Encryption
@human-protocol/sdk / encryption / Encryption
Class: Encryption
Defined in: encryption.ts:58
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/sdkyarn
yarn install @human-protocol/sdkInput parameters
privateKeyArmored- The encrypted private key in armored format.passphrase- The passphrase for the private key.
Code example
Constructors
Constructor
new Encryption(
privateKey):Encryption
Defined in: encryption.ts:66
Constructor for the Encryption class.
Parameters
privateKey
PrivateKey
The private key.
Returns
Encryption
Methods
decrypt()
decrypt(
message,publicKey?):Promise<Uint8Array<ArrayBufferLike>>
Defined in: encryption.ts:194
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
sign()
sign(
message):Promise<string>
Defined in: encryption.ts:251
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
signAndEncrypt()
signAndEncrypt(
message,publicKeys):Promise<string>
Defined in: encryption.ts:142
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
build()
staticbuild(privateKeyArmored,passphrase?):Promise<Encryption>
Defined in: encryption.ts:77
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.
Last updated