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

    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
    • __namedParameters: {
          crypto?: {
              sha512: {
                  hash: ((input) => Uint8Array) & ((input) => Uint8Array);
              };
          };
      } = {}
      • Optional crypto?: {
            sha512: {
                hash: ((input) => Uint8Array) & ((input) => Uint8Array);
            };
        }

        An optional object containing an implementation of sha512.

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

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

Generated using TypeDoc