Human Protocol SDK
v1.1.19
v1.1.19
  • Typescript SDK​
    • Encryption
      • Encryption
      • EncryptionUtils
    • Escrow
      • EscrowClient
      • EscrowUtils
    • KVStore
      • KVStoreClient
    • Staking
      • StakingClient
    • Storage
      • StorageClient
    • Statistics
      • StatisticsClient
  • Python SDK
    • agreement
      • bootstrap
      • measures
      • utils
    • encryption
      • encryption
      • legacy_encryption
      • encryption_utils
    • escrow
      • escrow_client
      • escrow_utils
    • kvstore
      • kvstore_client
    • staking
      • staking_client
      • staking_utils
    • statistics
      • statistics_client
    • storage
      • storage_client
      • storage_utils
    • constants
    • filter
    • utils
  • CHANGELOG
Powered by GitBook
On this page
  • Class: Encryption
  • Introduction
  • Installation
  • Input parameters
  • Code example
  • Table of contents
  • Constructors
  • Properties
  • Methods
  1. Typescript SDK​
  2. Encryption

Encryption

Last updated 1 year ago

/ / / Encryption

Class: Encryption

.Encryption

Introduction

Class for sign and decrypt messages.

The algorithm includes the implementation of the multi-public key encryption on typescript. Using the vanilla implementation Schnorr signatures for signature and for encryption. .

To get an instance of this class, is recommended to initialize it using the static build method.

static async build(privateKeyArmored: string, passphrase?: string): Promise<Encryption>

Installation

npm

npm install @human-protocol/sdk

yarn

yarn install @human-protocol/sdk

Input parameters

  • privateKeyArmored - The encrypted private key in armored format.

  • passphrase - The passphrase for the private key.

Code example

import { Encryption } from '@human-protocol/sdk';

const privateKey = 'Armored_priv_key';
const passphrase = 'example_passphrase';
const encription = await Encryption.build(privateKey, passphrase);

Table of contents

Constructors

Properties

Methods

Constructors

constructor

Constructor for the Encryption class.

Parameters

Name
Type
Description

privateKey

PrivateKey

The private key.

Returns

Defined in

Properties

privateKey

• Private privateKey: PrivateKey

Defined in

Methods

decrypt

▸ decrypt(message, publicKey?): Promise<string>

This function decrypt message message using the private key. In addition, the public key can be added for signature verification.

Parameters

Name
Type
Description

message

string

Message to decrypt.

publicKey?

string

Public key used to verify signature if needed. Optional.

Returns

Promise<string>

Message decrypted.

Code example

import { Encryption } from '@human-protocol/sdk';

const privateKey = 'Armored_priv_key';
const passphrase = 'example_passphrase';
const encription = await Encryption.build(privateKey, passphrase);

const publicKey = `-----BEGIN PGP PUBLIC KEY BLOCK-----
xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
-----END PGP PUBLIC KEY BLOCK-----`;

const resultMessage = await encription.decrypt('message');

Defined in


sign

▸ sign(message): Promise<string>

This function signs a message using the private key used to initialize the client.

Parameters

Name
Type
Description

message

string

Message to sign.

Returns

Promise<string>

Message signed.

Code example

import { Encryption } from '@human-protocol/sdk';

const privateKey = 'Armored_priv_key';
const passphrase = 'example_passphrase';
const encription = await Encryption.build(privateKey, passphrase);

const resultMessage = await encription.sign('message');

Defined in


signAndEncrypt

▸ signAndEncrypt(message, publicKeys): Promise<string>

This function signs and encrypts a message using the private key used to initialize the client and the specified public keys.

Parameters

Name
Type
Description

message

string

Message to sign and encrypt.

publicKeys

string[]

Array of public keys to use for encryption.

Returns

Promise<string>

Message signed and encrypted.

Code example

import { Encryption } from '@human-protocol/sdk';
import { EscrowClient } from '@human-protocol/sdk';

const privateKey = 'Armored_priv_key';
const passphrase = 'example_passphrase';
const encription = await Encryption.build(privateKey, passphrase);
const publicKey1 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
xjMEZKQEMxYJKwYBBAHaRw8BAQdA5oZTq4UPlS0IXn4kEaSqQdAa9+Cq522v
WYxJQn3vo1/NFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
CwkHCAkQJBFPuuhtQo4DFQgKBBYAAgECGQECGwMCHgEWIQTQ5fbVPB9CWIdf
XdYkEU+66G1CjgAAKYYA/jMyDCtJtqu6hj22kq9SW6fuV1FCT2ySJ9vBhumF
X8wWAP433zVFl4VECOkgGk8qFr8BgkYxaz16GOFAqYbfO6oMBc44BGSkBDMS
CisGAQQBl1UBBQEBB0AKR+A48zVVYZWQvgu7Opn2IGvzI9jePB/J8pzqRhg2
YAMBCAfCeAQYFggAKgUCZKQEMwkQJBFPuuhtQo4CGwwWIQTQ5fbVPB9CWIdf
XdYkEU+66G1CjgAA0xgBAK4AIahFFnmWR2Mp6A3q021cZXpGklc0Xw1Hfswc
UYLqAQDfdym4kiUvKO1+REKASt0Gwykndl7hra9txqlUL5DXBQ===Vwgv
-----END PGP PUBLIC KEY BLOCK-----`;

const publicKey2 = `-----BEGIN PGP PUBLIC KEY BLOCK-----
xjMEZKQEMxYJKwYBBAHaRw8BAQdAG6h+E+6T/RV2tIHer3FP/jKThAyGcoVx
FzhnP0hncPzNFEh1bWFuIDxodW1hbkBobXQuYWk+wowEEBYKAD4FAmSkBDME
CwkHCAkQPIq5xLhlTYkDFQgKBBYAAgECGQECGwMCHgEWIQTcxtMgul/AeUvH
bio8irnEuGVNiQAA/HsBANpfFkxNYixpsBk8LlaaCaPy5f1/cWNPgODM9uzo
ciSTAQDtAYynu4dSJO9GbMuDuc0FaUHRWJK3mS6JkvedYL4oBM44BGSkBDMS
CisGAQQBl1UBBQEBB0DWbEG7DMhkeSc8ZPzrH8XNSCqS3t9y/oQidFR+xN3Z
bAMBCAfCeAQYFggAKgUCZKQEMwkQPIq5xLhlTYkCGwwWIQTcxtMgul/AeUvH
bio8irnEuGVNiQAAqt8BAM/4Lw0RVOb0L5Ki9CyxO/6AKvRg4ra3Q3WR+duP
s/88AQCDErzvn+SOX4s3gvZcM3Vr4wh4Q2syHV8Okgx8STYPDg===DsVk
-----END PGP PUBLIC KEY BLOCK-----`;

const publicKeys = [publicKey1, publicKey2];
const resultMessage = await encription.signAndEncrypt('message', publicKeys);

Defined in


build

Builds an Encryption instance by decrypting the private key from an encrypted private key and passphrase.

Parameters

Name
Type
Description

privateKeyArmored

string

The encrypted private key in armored format.

passphrase?

string

Optional: The passphrase for the private key.

Returns

  • The Encryption instance.

Defined in

• new Encryption(privateKey):

▸ build(privateKeyArmored, passphrase?): Promise<>

Promise<>

@human-protocol/sdk
Modules
encryption
encryption
PGP encryption algorithm
ed25519
curve25519
Learn more
Encryption
Encryption
encryption.ts:53
encryption.ts:46
encryption.ts:180
encryption.ts:217
encryption.ts:129
Encryption
Encryption
encryption.ts:64
constructor
privateKey
decrypt
sign
signAndEncrypt
build