Skip to Content
Hydra@exodus/bip322-js

@exodus/bip322-js

Version: 0.0.0

Address

class
Class that implement address-related utility functions.

Constructor

constructor
Address(): Address

Returns:

Address

Methods

convertAdressToScriptPubkey
convertAdressToScriptPubkey(address: string): Buffer
Convert a given Bitcoin address into its corresponding script public key. Reference: https://github.com/buidl-bitcoin/buidl-python/blob/d79e9808e8ca60975d315be41293cb40d968626d/buidl/script.py#L607

Parameters:

address: string
Bitcoin address

Returns:

Buffer
Script public key of the given Bitcoin address
convertPubKeyIntoAddress
convertPubKeyIntoAddress(publicKey: Buffer, addressType: "p2pkh" | "p2sh-p2wpkh" | "p2wpkh" | "p2tr"): any
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:

any
Bitcoin address that correspond to the given public key in both mainnet and testnet
isP2PKH
isP2PKH(address: string): boolean
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
isP2SH
isP2SH(address: string): boolean
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
isP2TR
isP2TR(address: string): boolean
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
isP2WPKH
isP2WPKH(address: string): boolean
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
isP2WPKHWitness
isP2WPKHWitness(witness: Buffer[]): boolean
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
isSingleKeyP2TRWitness
isSingleKeyP2TRWitness(witness: Buffer[]): boolean
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

BIP322

class
Class that handles BIP-322 related operations. Reference: https://github.com/LegReq/bip0322-signatures/blob/master/BIP0322_signing.ipynb

Constructor

constructor
BIP322(): BIP322

Returns:

BIP322

Properties

TAG
Buffer

Methods

buildToSignTx
buildToSignTx(toSpendTxId: string, witnessScript: Buffer, isRedeemScript: boolean, tapInternalKey?: Buffer): Psbt
Build a to_sign transaction using simple signature in accordance to the BIP-322.

Parameters:

toSpendTxId: string
Transaction ID of the to_spend transaction as constructed by buildToSpendTx
witnessScript: Buffer
The script public key for the signing wallet, or the redeemScript for P2SH-P2WPKH address
isRedeemScript: boolean
Set to true if the provided witnessScript is a redeemScript for P2SH-P2WPKH address, default to false
tapInternalKey (optional): Buffer
Used to set the taproot internal public key of a taproot signing address when provided, default to undefined

Returns:

Psbt
Ready-to-be-signed bitcoinjs.Psbt transaction
buildToSpendTx
buildToSpendTx(message: string, scriptPublicKey: Buffer): Transaction
Build a to_spend transaction using simple signature in accordance to the BIP-322.

Parameters:

message: string
Message to be signed using BIP-322
scriptPublicKey: Buffer
The script public key for the signing wallet

Returns:

Transaction
Bitcoin transaction that correspond to the to_spend transaction
encodeWitness
encodeWitness(signedPsbt: Psbt): string
Encode witness stack in a signed BIP-322 PSBT into its base-64 encoded format.

Parameters:

signedPsbt: Psbt
Signed PSBT

Returns:

string
Base-64 encoded witness data
hashMessage
hashMessage(message: string): any
Compute the message hash as specified in the BIP-322. The standard is specified in BIP-340 as: The function hashtag(x) where tag is a UTF-8 encoded tag name and x is a byte array returns the 32-byte hash SHA256(SHA256(tag) || SHA256(tag) || x).

Parameters:

message: string
Message to be hashed

Returns:

any
Hashed message

Signer

class
Class that signs BIP-322 signature using a private key. Reference: https://github.com/LegReq/bip0322-signatures/blob/master/BIP0322_signing.ipynb

Constructor

constructor
Signer(): Signer

Returns:

Signer

Methods

signAsync
signAsync(signerOrKey: string | Buffer | Signer, address: string, message: string, network: Network): Promise
Sign a BIP-322 signature from P2WPKH, P2SH-P2WPKH, and single-key-spend P2TR address and its corresponding private key.

Parameters:

signerOrKey: string | Buffer | Signer
address: string
Address to be signing the message
message: string
message_challenge to be signed by the address
network: Network
Network that the address is located, defaults to the Bitcoin mainnet

Returns:

Promise
BIP-322 simple signature, encoded in base-64

Verifier

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

Constructor

constructor
Verifier(): Verifier

Returns:

Verifier

Methods

verifySignature
verifySignature(signerAddress: string, message: string, signature: Buffer): Promise
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
signature: Buffer
Signature buffer produced by the signing address

Returns:

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

Start building

XO

Request Demo

Schedule a call with our team

Select a product
Arrow right

Start building
Grateful

Contact Us

We're here to help