Derive a child HD node from a master node given an absolute derivation path.
The resulting node is the same type as the parent node – private nodes return
private nodes, public nodes return public nodes. (To prevent implementation
errors, this function will not internally derive a public node from any
private node; for public derivation, use deriveHdPublicNode at the
desired BIP32 account level and provide the HD public key to this function.)
The derivation path uses the notation specified in BIP32: the first character
must be either m for private derivation or M 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:
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
to deriveHdPublicNode or deriveHdPathRelative.
By default, this function throws an Error rather than returning the error
as string when the provided path is invalid or cannot be derived from the
provided HD node (e.g. the path requests an excessive child index, a hardened
path is requested from a public node, or an astronomically rare HMAC-SHA512
result produces and invalid node).
While the throwing behavior is reasonable for the common case of deriving
known, fixed paths (e.g. the BCH account as standardized by SLIP44 at
m/44'/145'/0'), it is recommended that throwErrors be set to false
for use cases where dynamic or user-specified paths might be derived. In
these cases, deliberate error handling is recommended, e.g. saving any data
and safely shutting down, displaying troubleshooting information to the
user, etc.
If true, this function will throw an Error rather than returning the
error as a string when the provided path is invalid or cannot be derived
from the provided HD node (defaults to true).
Derive a child HD node from a master node given an absolute derivation path. The resulting node is the same type as the parent node – private nodes return private nodes, public nodes return public nodes. (To prevent implementation errors, this function will not internally derive a public node from any private node; for public derivation, use deriveHdPublicNode at the desired BIP32 account level and provide the HD public key to this function.)
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 to deriveHdPublicNode or deriveHdPathRelative.By default, this function throws an
Error
rather than returning the error as string when the provided path is invalid or cannot be derived from the provided HD node (e.g. the path requests an excessive child index, a hardened path is requested from a public node, or an astronomically rare HMAC-SHA512 result produces and invalid node).While the throwing behavior is reasonable for the common case of deriving known, fixed paths (e.g. the BCH account as standardized by SLIP44 at
m/44'/145'/0'
), it is recommended thatthrowErrors
be set tofalse
for use cases where dynamic or user-specified paths might be derived. In these cases, deliberate error handling is recommended, e.g. saving any data and safely shutting down, displaying troubleshooting information to the user, etc.