Function deriveHdPublicNodeChild

  • Derive a non-hardened, child HD public node from an HD public node.

    Because hardened derivation also requires knowledge of the parent private node, it's not possible to use an HD public node to derive a hardened child HD public node. (See deriveHdPath or deriveHdPublicNode.)

    Though private keys cannot be derived from HD public keys, sharing HD public keys still carries risk. Along with allowing an attacker to associate wallet addresses together (breaking privacy), should an attacker gain knowledge of a single child private key, it's possible to derive all parent HD private keys. See crackHdPrivateNodeFromHdPublicNodeAndChildPrivateNode for details.

    This function has a less than 1 in 2^127 probability of producing an invalid result (where the resulting public key is not a valid Secp256k1 public key). 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: HdPublicNodeValid

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

    • index: number

      The index at which to derive the child node.

    • __namedParameters: {
          crypto?: {
              ripemd160: {
                  hash: ((input) => Uint8Array) & ((input) => Uint8Array);
              };
              secp256k1: {
                  addTweakPublicKeyCompressed: ((publicKey, tweakValue) => 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: {
                addTweakPublicKeyCompressed: ((publicKey, tweakValue) => 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 compressed public key "tweak addition" (application of the EC group operation).

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

                • publicKey: Uint8Array
                • tweakValue: 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 return an error rather than an HdPublicNodeInvalid (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
        ? HdPublicNodeKnownParent<HdPublicNodeValid>
        : ReturnInvalidNodes extends false
            ? string | HdPublicNodeKnownParent<HdPublicNodeValid>
            : string | HdPublicNodeKnownParent<HdPublicNode>

Generated using TypeDoc