Function deriveHdPrivateNodeChild

  • Derive a child HD private node from an HD private node.

    To derive a child HD public node, use deriveHdPublicNode on the result of this method. If the child uses a non-hardened index, it's also possible to use deriveHdPublicNodeChild.

    Note that this function defaults to throwing errors. To handle errors in a type-safe way, set throwErrors to false.

    This function has a less than 1 in 2^127 probability of producing an invalid result (where the resulting private key is not a valid Secp256k1 private key, see validateSecp256k1PrivateKey). While this scenario is unlikely to ever occur without a weakness in HMAC-SHA512, the returnInvalidNodes parameter can be set to true to return the resulting HdPrivateNodeInvalid rather than an error (defaults to false).

    Type Parameters

    • ThrowErrors extends boolean = true

    • ReturnInvalidNodes extends boolean = false

    Parameters

    • node: HdPrivateNodeValid

      The valid HD private node from which to derive the child node.

    • index: number

      The index at which to derive the child node - indexes greater than or equal to the hardened index offset (0x80000000/2147483648) are derived using the "hardened" derivation algorithm.

    • __namedParameters: {
          crypto?: {
              ripemd160: {
                  hash: ((input) => Uint8Array) & ((input) => Uint8Array);
              };
              secp256k1: {
                  addTweakPrivateKey: ((privateKey, tweakValue) => string | Uint8Array);
                  derivePublicKeyCompressed: ((privateKey) => string | Uint8Array);
              };
              sha256: {
                  hash: ((input) => Uint8Array) & ((input) => Uint8Array);
              };
              sha512: {
                  hash: ((input) => Uint8Array) & ((input) => Uint8Array);
              };
          };
          returnInvalidNodes?: ReturnInvalidNodes;
          throwErrors?: ThrowErrors;
      } = {}
      • Optional crypto?: {
            ripemd160: {
                hash: ((input) => Uint8Array) & ((input) => Uint8Array);
            };
            secp256k1: {
                addTweakPrivateKey: ((privateKey, 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, ripemd160, secp256k1 compressed public key derivation, and secp256k1 private key "tweak addition" (application of the EC group operation).

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

                • privateKey: 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 returnInvalidNodes?: ReturnInvalidNodes

        If false, invalid derivations (probability less than 1 in 2^127) will produce an error rather than an HdPrivateNodeInvalid (defaults to false). To return the invalid node rather than throwing an error, throwErrors must also be set to false.

      • Optional throwErrors?: ThrowErrors

        If true, this function will throw an Error rather than returning derivation errors as a string (defaults to true).

    Returns ThrowErrors extends true
        ? HdPrivateNodeKnownParent<HdPrivateNodeValid>
        : ReturnInvalidNodes extends false
            ? string | HdPrivateNodeKnownParent<HdPrivateNodeValid>
            : string | HdPrivateNodeKnownParent<HdPrivateNode>

Generated using TypeDoc