Encryption

@human-protocol/sdk / Modules / encryption / Encryption

Class: Encryption

encryption.Encryption

Introduction

Class for sign and decrypt messages.

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

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

Table of contents

Constructors

Properties

Methods

Constructors

constructor

new Encryption(privateKey): Encryption

Constructor for the Encryption class.

Parameters

Name
Type
Description

privateKey

PrivateKey

The private key.

Returns

Encryption

Defined in

encryption.ts:53

Properties

privateKey

Private privateKey: PrivateKey

Defined in

encryption.ts:46

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

Defined in

encryption.ts:180


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

Defined in

encryption.ts:217


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

Defined in

encryption.ts:129


build

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

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

Promise<Encryption>

  • The Encryption instance.

Defined in

encryption.ts:64

Last updated