Function deriveHdPathRelative

  • Derive a child HD node from a parent node given a relative 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.)

    Where possible, consider instead using deriveHdPath to reduce the likelihood of implementation errors.

    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.

    The derivation path uses the notation specified in BIP32; see deriveHdPath for details.

    Type Parameters

    Parameters

    • node: NodeType

      The HD node from which to begin the derivation – for private derivation, an HdPrivateNodeValid; for public derivation, an HdPublicNodeValid.

    • path: Path

      The relative BIP32 derivation path, e.g. 1'/2 or 3/4/5.

    • __namedParameters: {
          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);
              };
          };
          throwErrors?: ThrowErrors;
      } = {}
      • Optional 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 hashing, sha512 hashing, ripemd160 hashing, 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)
      • Optional throwErrors?: ThrowErrors

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

    Returns ThrowErrors extends true
        ? RelativeDerivation<NodeType, Path>
        : string | RelativeDerivation<NodeType, Path>

Generated using TypeDoc