KeyManager

KeyManager

new KeyManager(seed) → {KeyManager}

Create and manage 25519 keys for use with 'hcs0' Holochain encoding

Parameters:
Name Type Description
seed Buffer

Buffer to be used as seed for creating keys (optional)

Properties:
Name Type Description
signing KeyPair

Signing keypair

encryption KeyPair

Encryption keypair

Source:

Methods

(static) deriveSeed(email, password) → {Uint8Array}

Derive seed from email and password

Parameters:
Name Type Description
email string

User email

password string

User password

Source:
Example
const seed = KeyManager.deriveSeed( "somebody@example.com", "Pa55w0rd!" );
const keys = new KeyManager( seed );

(static) digest(text) → {Uint8Array}

Produce a SHA-256 digest

Parameters:
Name Type Description
text string

Serialized message

Source:
Example
const bytes = KeyManager.digest( "bla bla bla" );

(static) encodeDigest(byte_array) → {string}

Encode bytes with SHA2-256 multicodec

Parameters:
Name Type Description
byte_array Uint8Array

Hash bytes

Source:
Example
const bytes = KeyManager.digest( "bla bla bla" );
const hash = KeyManager.encodeDigest( bytes );

(static) encodeSignature(byte_array) → {string}

Encode bytes with base64

Parameters:
Name Type Description
byte_array Uint8Array

Hash bytes

Source:
Example
const keys = new KeyManager();
const bytes = keys.sign( "bla bla bla" );
const signature = KeyManager.encodeSignature( bytes );

agentId() → {string}

Get HCID (hcs0) encoded public key

Source:
Example
const keys = new KeyManager();
let agent_id = keys.agentId();

digestAndSign(message) → {object}

Digest the message and then sign the hash. Returns unencoded digest and signature.

Parameters:
Name Type Description
message string

Message that will be digested and signed

Source:
Example
const keys = new KeyManager();
let pair = keys.digestAndSign( message );
console.log( pair.digest );
console.log( pair.signature );

digestAndSignEncoded(message) → {object}

Digest the message and then sign the hash. Returns encoded digest and signature.

Parameters:
Name Type Description
message string

Message that will be digested and signed

Source:
Example
const keys = new KeyManager();
let pair = keys.digestAndSignEncoded( message );
console.log( pair.digest );
console.log( pair.signature );

sign(message) → {Uint8Array}

Sign a message using private signing key

Parameters:
Name Type Description
message string

Message to be signed

Source:
Example
const keys = new KeyManager();
let signature = keys.sign( message );

verify(message, signature, public_key) → {boolean}

Verify a signed message against a given public key

Parameters:
Name Type Description
message string

Message that was signed

signature Uint8Array

Signature byte array

public_key Uint8Array

Public key (defaults to self public key)

Source:
Example
const keys = new KeyManager();
let genuine = keys.verify( message, signature );