Function deriveHdPath

  • 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).

    Type Parameters

    Parameters

    • node: NodeType

      the HD node from which to begin the derivation (for paths beginning with m, an HdPrivateNodeValid; for paths beginning with M, an HdPublicNode)

    • path: string

      the BIP32 derivation path, e.g. m/0/1'/2 or M/3/4/5

    • crypto: {
          ripemd160: {
              hash: ((input) => Uint8Array) & ((input) => Uint8Array);
          };
          secp256k1: {
              addTweakPrivateKey: ((privateKey, tweakValue) => string | Uint8Array);
              addTweakPublicKeyCompressed: ((publicKey, tweakValue) => string | Uint8Array);
              derivePublicKeyCompressed: ((privateKey) => string | Uint8Array);
          };
          sha256: {
              hash: ((input) => Uint8Array) & ((input) => Uint8Array);
          };
          sha512: {
              hash: ((input) => Uint8Array) & ((input) => Uint8Array);
          };
      } = ...

      an optional object containing implementations of sha256, sha512, ripemd160, and secp256k1 derivation functions

      • ripemd160: {
            hash: ((input) => Uint8Array) & ((input) => Uint8Array);
        }
        • hash: ((input) => Uint8Array) & ((input) => Uint8Array)
      • secp256k1: {
            addTweakPrivateKey: ((privateKey, tweakValue) => string | Uint8Array);
            addTweakPublicKeyCompressed: ((publicKey, tweakValue) => string | Uint8Array);
            derivePublicKeyCompressed: ((privateKey) => string | Uint8Array);
        }
        • addTweakPrivateKey: ((privateKey, tweakValue) => string | Uint8Array)
            • (privateKey, tweakValue): string | Uint8Array
            • Parameters

              • privateKey: Uint8Array
              • tweakValue: Uint8Array

              Returns string | Uint8Array

        • addTweakPublicKeyCompressed: ((publicKey, tweakValue) => string | Uint8Array)
            • (publicKey, tweakValue): string | Uint8Array
            • Parameters

              • publicKey: Uint8Array
              • tweakValue: Uint8Array

              Returns string | Uint8Array

        • derivePublicKeyCompressed: ((privateKey) => string | Uint8Array)
            • (privateKey): string | Uint8Array
            • Parameters

              • privateKey: Uint8Array

              Returns string | Uint8Array

      • sha256: {
            hash: ((input) => Uint8Array) & ((input) => Uint8Array);
        }
        • hash: ((input) => Uint8Array) & ((input) => Uint8Array)
      • sha512: {
            hash: ((input) => Uint8Array) & ((input) => Uint8Array);
        }
        • hash: ((input) => Uint8Array) & ((input) => Uint8Array)

    Returns invalidDerivationPath | invalidPrivateDerivationPrefix | invalidPublicDerivationPrefix | ReductionResults<NodeType>

    Remarks

    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:

    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.

Generated using TypeDoc