Reference

The package is comprised of the following static functions and classes. See the example page for further information on usage.

Functions

The following static functions are exported at the top-level module and provide the core package functionality.

addressFromPublicKey(publicKey)

Computes the base-58 encoded address digest from the provided public key.

Returns:the base-58 encoded string
Arguments
Argument Type Description
path Buffer(32) The verifying key to digest
deriveKeyPair(root, path)

Uses a child-key-derivation function to derive a KeyPair instance from at the provided path relative to the provided root.

Returns:the derived KeyPair instance
Arguments
Argument Type Description
root Node, string, or Buffer(64) Relative root Node or seed key (string or Buffer(64))
path string Hardened path of the derived Keyapair
deriveNode(root, path)

Uses a child-key-derivation (CKD) function to derive an HD Node at the provided path relative to the provided root.

Returns:the derived Node instance.
Arguments
Argument Type Description
root Node, string, or Buffer(64) Relative root Node or seed key (string or Buffer(64)) from which to derive the node
path string Hardened path of the derived Node
generateKeyPair()

Generates a randomized KeyPair for use with the Plug platform.

Returns:a randomized KeyPair instance.
generateMnemonic(entropyLength?)

Generates a BIP39 compatable mnemonic phrase seed using random entropy.

Returns:a string containing the random phrase.
Arguments
Argument Type Description
entropyLength number Optional entropy length in bits to generate - defaults to 128 (12 words)
mnemonicToSeed(phrase, password?)

Derives a BIP32 compatable seed from the provided phrase.

Returns:a hexadecimal string containing the derived seed.
Arguments
Argument Type Description
phrase string Entropy as a mnemonic phrase
password string Optional password to use when deriving the seed - defaults to empty string
validateMnemonic(phrase)

Validates a mnemonic phrase.

Returns:a boolean specifying whether the phrase is valid.
Arguments
Argument Type Description
phrase string The mnemonic phrase to validate
sign(privateKey, message)

Creates a detached signature generated by the signing key.

Note

The KeyPair.sign helper for signing using a KeyPair context.

Returns:a Buffer(32) containing the detached signature.
Arguments
Argument Type Description
privateKey Buffer(32) Signing key to create the signature
message Buffer Message over which to create the signature
verifySignature(publicKey, message, signature)

Verifies a detached signature against a public key and message.

Note

The KeyPair.verifySignature helper for verifying signatures using a KeyPair context.

Returns:a boolean indicating whether the signature is valid.
Arguments
Argument Type Description
publicKey Buffer(32) Verifying key to validate the signature
Message Buffer Message to verify the signature against
signature Buffer(32) The signature to verify

Class: KeyPair

Represents a Plug key pair. Instances are obtained through the deriveKeyPair and generateKeyPair functions.

Members

Members
Member Type Description
address string Base-58 encoded address digest corresponding to the public key
privateKey Buffer(32) Derived or generated signing key
publicKey Buffer(32) Verifying key corresponding to the privateKey

Methods

KeyPair.sign(message)

Uses the KeyPair instance configuration to create a detached signature over the provided message.

Returns:a Buffer(32) containing the detached signature.
Arguments
Argument Type Description
message Buffer The message over which to create the detached signature
KeyPair.verifySignature(message, signature)

Uses the KeyPair instance configuration to verify a signature over the provided message.

Returns:a boolean indicating whether the signature is valid.
Arguments
Argument Type Description
message Buffer Message to verify the signature against
signature Buffer(32) The signature to verify

Class: Node

Represents a BIP32-like HD node. Instances are created by the deriveNode function.

Members

Members
Member Type Description
chainCode Buffer(32) Buffer containing the derived chain code used for further derivation
keyPair object KeyPair instance containing the derived keys
path string The relative path of the derived node from the origin root

Methods

Node.deriveNode(path)

Derives a new Node instance using the calling instance as a relative root

Returns:the derived Node instance.
Arguments
Argument Type Description
path string The path relative to this instance from which to derive a new Node instance