Class Address

Class that implement address-related utility functions.

Constructors

Methods

  • Convert a given public key into a corresponding Bitcoin address.

    Parameters

    • publicKey: Buffer

      Public key for deriving the address, or internal public key for deriving taproot address

    • addressType: "p2pkh" | "p2sh-p2wpkh" | "p2wpkh" | "p2tr"

      Bitcoin address type to be derived, must be either 'p2pkh', 'p2sh-p2wpkh', 'p2wpkh', or 'p2tr'

    Returns {
        mainnet: string;
        regtest: string;
        testnet: string;
    }

    Bitcoin address that correspond to the given public key in both mainnet and testnet

    • mainnet: string
    • regtest: string
    • testnet: string
  • Check if a given Bitcoin address is a pay-to-public-key-hash (p2pkh) address.

    Parameters

    • address: string

      Bitcoin address to be checked

    Returns boolean

    True if the provided address correspond to a valid P2PKH address, false if otherwise

  • Check if a given Bitcoin address is a pay-to-script-hash (P2SH) address.

    Parameters

    • address: string

      Bitcoin address to be checked

    Returns boolean

    True if the provided address correspond to a valid P2SH address, false if otherwise

  • Check if a given Bitcoin address is a taproot address.

    Parameters

    • address: string

      Bitcoin address to be checked

    Returns boolean

    True if the provided address is a taproot address, false if otherwise

  • Check if a given Bitcoin address is a pay-to-witness-public-key-hash (P2WPKH) address.

    Parameters

    • address: string

      Bitcoin address to be checked

    Returns boolean

    True if the provided address correspond to a valid P2WPKH address, false if otherwise

  • Check if a given witness stack corresponds to a P2WPKH address.

    Parameters

    • witness: Buffer[]

      Witness data associated with the toSign BIP-322 transaction

    Returns boolean

    True if the provided witness stack correspond to a valid P2WPKH address, false if otherwise

  • Check if a given witness stack corresponds to a single-key-spend P2TR address.

    Parameters

    • witness: Buffer[]

      Witness data associated with the toSign BIP-322 transaction

    Returns boolean

    True if the provided address and witness stack correspond to a valid single-key-spend P2TR address, false if otherwise

  • Validates a given Bitcoin address. This method checks if the provided Bitcoin address is valid by attempting to decode it for different Bitcoin networks: mainnet, testnet, and regtest. The method uses the bitcoinjs-lib's address module for decoding.

    The process is as follows:

    1. Attempt to decode the address for the Bitcoin mainnet. If decoding succeeds, the method returns true, indicating the address is valid for mainnet.
    2. If the first step fails, catch the resulting error and attempt to decode the address for the Bitcoin testnet. If decoding succeeds, the method returns true, indicating the address is valid for testnet.
    3. If the second step fails, catch the resulting error and attempt to decode the address for the Bitcoin regtest network. If decoding succeeds, the method returns true, indicating the address is valid for regtest.
    4. If all attempts fail, the method returns false, indicating the address is not valid for any of the checked networks.

    Parameters

    • address: string

      The Bitcoin address to validate.

    Returns boolean

    boolean Returns true if the address is valid for any of the Bitcoin networks, otherwise returns false.