Encryption

@human-protocol/sdk


@human-protocol/sdk / encryption / Encryption

Class: Encryption

Introduction

Class for signing and decrypting messages.

The algorithm includes the implementation of the PGP encryption algorithm multi-public key encryption on typescript, and uses the vanilla ed25519 implementation Schnorr signature for signatures and curve25519 for encryption. Learn more.

To get an instance of this class, initialization is recommended 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

Constructors

new Encryption()

new Encryption(privateKey): Encryption

Constructor for the Encryption class.

Parameters

privateKey

PrivateKey

The private key.

Returns

Encryption

Defined in

encryption.ts:66

Methods

decrypt()

decrypt(message, publicKey?): Promise<Uint8Array<ArrayBufferLike>>

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

Parameters

message

string

Message to decrypt.

publicKey?

string

Public key used to verify signature if needed. This is optional.

Returns

Promise<Uint8Array<ArrayBufferLike>>

Message decrypted.

Code example

Defined in

encryption.ts:194


sign()

sign(message): Promise<string>

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

Parameters

message

string

Message to sign.

Returns

Promise<string>

Message signed.

Code example

Defined in

encryption.ts:251


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

message

MessageDataType

Message to sign and encrypt.

publicKeys

string[]

Array of public keys to use for encryption.

Returns

Promise<string>

Message signed and encrypted.

Code example

Defined in

encryption.ts:142


build()

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

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

Parameters

privateKeyArmored

string

The encrypted private key in armored format.

passphrase?

string

Optional: The passphrase for the private key.

Returns

Promise<Encryption>

  • The Encryption instance.

Defined in

encryption.ts:77

Last updated