Reference

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

Functions

The following functions are exported at the top-level package module.

deriveKeyPair(root, path, curveType)

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 Curve-suitable path of the derived Keyapair
curveType string Curve tech to use when deriving the KeyPair, e.g. ed25519
deriveNode(root, path, curveType)

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 Curve-suitable path of the derived Node
curveType string Curve tech to use when deriving the Node, e.g. ed25519
generateKeyPair(curveType)

Generates a randomized KeyPair for use with the provided curve.

Returns:a randomized KeyPair instance.
Arguments
Argument Type Description
curveType string Curve tech to use when generating the KeyPair
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, curveType)

Creates a detached signature generated by the signing key for the specified curve type.

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
curveType string Curve tech to compute the signature with
verifySignature(publicKey, message, signature, curveType)

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
curveType string Curve tech to verify the signature with

Class: KeyPair

Represents keys dervied for a particular curve.

Members

Members
Member Type Description
privateKey Buffer(32) Derived or generated signing key
publicKey Buffer(32) Verifying key corresponding to the privateKey
curveType string Curve tech used when deriving the KeyPair, e.g ed25519

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
curveType string Curve tech used when deriving the Node, e.g ed25519
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