Function hdPrivateKeyToP2pkhLockingBytecode

  • Derive the P2PKH locking bytecode at the provided path and address index of the provided HD private key.

    Note that this function defaults to throwing an error if provided with an invalid HD private key or derivation path. To handle errors in a type-safe way, set throwErrors to false.

    To derive the resulting CashAddress, use hdPrivateKeyToP2pkhCashAddress. For non-HD private keys, use privateKeyToP2pkhLockingBytecode. For the HD public key equivalent, see hdPublicKeyToP2pkhLockingBytecode.

    Type Parameters

    • ThrowErrors extends boolean = true

    Parameters

    • __namedParameters: {
          addressIndex: number;
          hdPrivateKey: string;
          privateDerivationPath?: string;
          throwErrors?: ThrowErrors;
      }
      • addressIndex: number

        The address index within the BIP32 account specified by privateDerivationPath at which to derive the P2PKH locking bytecode.

        Address indexes must be positive integers between 0 and 4294967295 (0xffffffff), inclusive. An error will be thrown or returned (in accordance with throwErrors) for address indexes outside of this range.

        As standardized by BIP32, address indexes less than 2147483648 (0x80000000) use standard derivation, while indexes equal to or greater than 2147483648 use the "hardened" derivation algorithm. Note that this prevents the HD public key derived from the provided HD private key (deriveHdPublicKey) from deriving any address indexes beyond 2147483647. (In these cases, hdPublicKeyToP2pkhLockingBytecode and hdPublicKeyToP2pkhCashAddress will produce an error.)

      • hdPrivateKey: string

        An encoded HD private key, e.g. xprv9s21ZrQH143K3GJpoapnV8SFfukcVBSfeCficPSGfubmSFDxo1kuHnLisriDvSnRRuL2Qrg5ggqHKNVpxR86QEC8w35uxmGoggxtQTPvfUu.

        HD private keys may be encoded for either mainnet or testnet (the network information is ignored).

      • Optional privateDerivationPath?: string

        The private derivation path for the BIP32 account to use in deriving the P2PKH address. By default, i.

        This path uses the notation specified in BIP32 and the i character to represent the addressIndex.

        For example, for the first external P2PKH address of the first BCH account as standardized by SLIP44, privateDerivationPath should be m/44'/145'/0'/0/i, while addressIndex is set to 0. (For "change" addresses, privateDerivationPath should be m/44'/145'/0'/1/i.)

        This path may be relative or absolute, see WalletTemplateHdKey.privateDerivationPath for details.

      • Optional throwErrors?: ThrowErrors

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

    Returns ThrowErrors extends true
        ? Uint8Array
        : string | Uint8Array

Generated using TypeDoc