the HD node from which to begin the derivation (for paths
beginning with m
, an HdPrivateNodeValid; for paths beginning with
M
, an HdPublicNode)
the BIP32 derivation path, e.g. m/0/1'/2
or M/3/4/5
an optional object containing implementations of sha256, sha512, ripemd160, and secp256k1 derivation functions
Returns the ripemd160 hash of the provided input.
To incrementally construct a ripemd160 hash (e.g. for streaming), use
init
, update
, and final
.
a Uint8Array to be hashed using ripemd160
Tweak a privateKey by adding tweakValue
to it.
Returns an error message if the private key is invalid or if the addition fails.
a valid secp256k1 private key
256 bit value to tweak by (BE)
Tweak a publicKey
by adding tweakValue
times the generator to it.
Returns an error message if the provided public key could not be parsed or is not valid, or if the addition failed.
The returned public key will be in compressed format.
a public key.
256 bit value to tweak by (BE)
Derive a compressed public key from a valid secp256k1 private key.
Returns an error message if the provided private key is too large (see
validatePrivateKey
).
a valid secp256k1, 32-byte private key
Returns the sha256 hash of the provided input.
To incrementally construct a sha256 hash (e.g. for streaming), use init
,
update
, and final
.
a Uint8Array to be hashed using sha256
Returns the sha512 hash of the provided input.
To incrementally construct a sha512 hash (e.g. for streaming), use init
,
update
, and final
.
a Uint8Array to be hashed using sha512
Generated using TypeDoc
Derive a child HD node from a parent node given a derivation path. The resulting node is the same type as the parent node (private nodes return private nodes, public nodes return public nodes).
Remarks
The derivation path uses the notation specified in BIP32:
The first character must be either
m
for private derivation orM
for public derivation, followed by sets of/
and a number representing the child index used in the derivation at that depth. Hardened derivation is represented by a trailing'
, and may only appear in private derivation paths (hardened derivation requires knowledge of the private key). Hardened child indexes are represented with the hardened index offset (2147483648
) subtracted.For example,
m/0/1'/2
uses private derivation (m
), with child indexes in the following order:derivePrivate(derivePrivate(derivePrivate(node, 0), 2147483648 + 1), 2)
Likewise,
M/3/4/5
uses public derivation (M
), with child indexes in the following order:derivePublic(derivePublic(derivePublic(node, 3), 4), 5)
Because hardened derivation requires a private node, paths that specify public derivation (
M
) using hardened derivation ('
) will return an error. To derive the public node associated with a child private node that requires hardened derivation, begin with private derivation, then provide the result toderiveHdPublicNode
.