Function crackHdPrivateNodeFromHdPublicNodeAndChildPrivateNode

  • Derive the HD private node from a HD public node, given any non-hardened child private node.


    This exploits the "non-hardened" BIP32 derivation algorithm. Because non-hardened derivation only requires knowledge of the "chain code" (rather than requiring knowledge of the parent private key) it's possible to calculate the value by which the parent private key is "tweaked" to arrive at the child private key. Since we have the child private key, we simply subtract this "tweaked" amount to get back to the parent private key.

    The BIP32 "hardened" derivation algorithm is designed to address this weakness. Using hardened derivation, child private nodes can be shared without risk of leaking the parent private node, but this comes at the cost of public node derivation. Given only a parent public node, it is not possible to derive hardened child public keys, so applications must choose between support for HD public node derivation or support for sharing child private nodes.

    Type Parameters


    • parentPublicNode: PublicNode

      the parent HD public node for which to derive a private node

    • childPrivateNode: {
          childIndex: number;
          privateKey: Uint8Array;

      any non-hardened child private node of the parent node (only the privateKey and the childIndex are required) *

      • childIndex: number
      • privateKey: Uint8Array
    • crypto: {
          sha512: {
              hash: ((input: Uint8Array) => Uint8Array);
      } = ...

      an optional object containing an implementation of sha512

      • sha512: {
            hash: ((input: Uint8Array) => Uint8Array);
        • hash: ((input: Uint8Array) => Uint8Array)
            • (input: Uint8Array): Uint8Array
            • Returns the sha512 hash of the provided input.

              To incrementally construct a sha512 hash (e.g. for streaming), use init, update, and final.


              • input: Uint8Array

                a Uint8Array to be hashed using sha512

              Returns Uint8Array

    Returns cannotCrackHardenedDerivation | (PublicNode extends HdPublicNodeKnownParent ? HdPrivateNodeKnownParent : HdPrivateNodeValid)

Generated using TypeDoc