Function deriveHdPublicKey

  • Derive the HD public key of an HD private key.

    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.

    To derive the HD public node of an already-decoded HD private node, use deriveHdPublicNode.

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

    Type Parameters

    • ThrowErrors extends boolean = true

    Parameters

    • privateKey: string
    • __namedParameters: {
          crypto?: {
              secp256k1: {
                  derivePublicKeyCompressed: ((privateKey) => string | Uint8Array);
                  validatePublicKey: ((publicKey) => boolean);
              };
              sha256: {
                  hash: ((input) => Uint8Array) & ((input) => Uint8Array);
              };
          };
          throwErrors?: ThrowErrors;
      } = {}
      • Optional crypto?: {
            secp256k1: {
                derivePublicKeyCompressed: ((privateKey) => string | Uint8Array);
                validatePublicKey: ((publicKey) => boolean);
            };
            sha256: {
                hash: ((input) => Uint8Array) & ((input) => Uint8Array);
            };
        }

        An optional object containing an implementation of sha256 and a Secp256k1 derivePublicKeyCompressed and validatePublicKey to use.

        • secp256k1: {
              derivePublicKeyCompressed: ((privateKey) => string | Uint8Array);
              validatePublicKey: ((publicKey) => boolean);
          }
          • derivePublicKeyCompressed: ((privateKey) => string | Uint8Array)
              • (privateKey): string | Uint8Array
              • Parameters

                • privateKey: Uint8Array

                Returns string | Uint8Array

          • validatePublicKey: ((publicKey) => boolean)
              • (publicKey): boolean
              • Parameters

                • publicKey: Uint8Array

                Returns boolean

        • sha256: {
              hash: ((input) => Uint8Array) & ((input) => Uint8Array);
          }
          • hash: ((input) => Uint8Array) & ((input) => Uint8Array)
      • Optional throwErrors?: ThrowErrors

        If true, this function will throw an Error when the provided HD private key is invalid rather than returning the error as a string (defaults to true).

    Returns ThrowErrors extends true
        ? HdPublicKeyEncodeResult
        : string | HdPublicKeyEncodeResult

Generated using TypeDoc