Class Verifier

Class that handles BIP-322 signature verification. Reference: https://github.com/LegReq/bip0322-signatures/blob/master/BIP0322_verification.ipynb

Constructors

Methods

  • Wraps the Bitcoin message verification process to avoid throwing exceptions. This method attempts to verify a BIP-137 message using the provided address and signature. It encapsulates the verification process within a try-catch block, catching any errors that occur during verification and returning false instead of allowing the exception to propagate.

    The process is as follows:

    1. The bitcoinjs-message.verify function is called with the message, address, and signature provided in Base64 encoding.
    2. If the verification is successful, the method returns true.
    3. If any error occurs during the verification, the method catches the error and returns false, signaling an unsuccessful verification.

    Parameters

    • message: string

      The Bitcoin message to be verified.

    • address: string

      The Bitcoin address to which the message is allegedly signed.

    • signatureBase64: string

      The Base64 encoded signature corresponding to the message.

    Returns boolean

    boolean Returns true if the message is successfully verified, otherwise false.

  • Compute the hash to be signed for a given P2SH-P2WPKH BIP-322 toSign transaction.

    Parameters

    • toSignTx: Psbt

      PSBT instance of the toSign transaction

    • hashedPubkey: Buffer

      Hashed public key of the signing address

    Returns Buffer

    Computed transaction hash that requires signing

  • Compute the hash to be signed for a given P2TR BIP-322 toSign transaction.

    Parameters

    • toSignTx: Psbt

      PSBT instance of the toSign transaction

    • hashType: number

      Hash type used to sign the toSign transaction, must be either 0x00 or 0x01

    Returns Buffer

    Computed transaction hash that requires signing

    Throws

    Error if hashType is anything other than 0x00 or 0x01

  • Compute the hash to be signed for a given P2WPKH BIP-322 toSign transaction.

    Parameters

    • toSignTx: Psbt

      PSBT instance of the toSign transaction

    Returns Buffer

    Computed transaction hash that requires signing

  • Verify a legacy BIP-137 signature. Note that a signature is considered valid for all types of addresses that can be derived from the recovered public key.

    Parameters

    • signerAddress: string

      Address of the signing address

    • message: string

      message_challenge signed by the address

    • signatureBase64: string

      Signature produced by the signing address

    • useStrictVerification: boolean

      If true, apply strict BIP-137 verification and enforce address flag verification; otherwise, address flag is ignored during verification

    Returns boolean

    True if the provided signature is a valid BIP-137 signature for the given message and address, false if otherwise

    Throws

    If the provided signature fails basic validation, or if unsupported address and signature are provided

  • Verify a BIP-322 signature from P2WPKH, P2SH-P2WPKH, and single-key-spend P2TR address.

    Parameters

    • signerAddress: string

      Address of the signing address

    • message: string

      message_challenge signed by the address

    • signatureBase64: string

      Signature produced by the signing address

    • useStrictVerification: boolean = false

      If true, apply strict BIP-137 verification and enforce address flag verification; otherwise, address flag is ignored during verification

    Returns boolean

    True if the provided signature is a valid BIP-322 signature for the given message and address, false if otherwise

    Throws

    If the provided signature fails basic validation, or if unsupported address and signature are provided