P2TR_addr

Module for P2TR address encoding/decoding.

References

https://github.com/bitcoin/bips/blob/master/bip-0340.mediawiki https://github.com/bitcoin/bips/blob/master/bip-0341.mediawiki

class P2TRConst

Bases: object

Class container for P2TR constants.

FIELD_SIZE: int = 115792089237316195423570985008687907853269984665640564039457584007908834671663
TAP_TWEAK_SHA256: bytes = b'\xe8\x0f\xe1c\x9c\x9c\xa0P\xe3\xaf\x1b9\xc1C\xc6>B\x9c\xbc\xeb\x15\xd9@\xfb\xb5\xc5\xa1\xf4\xafW\xc5\xe9'
WITNESS_VER: int = 1
class P2TRAddrDecoder

Bases: IAddrDecoder

P2WPKH address decoder class. It allows the Pay-to-Witness-Public-Key-Hash address decoding.

static DecodeAddr(addr: str, **kwargs: Any) bytes

Decode a P2TR address to bytes.

Parameters:
  • addr (str) – Address string

  • hrp (str) – Expected HRP

Returns:

X coordinate of the tweaked public key

Return type:

bytes

Raises:

ValueError – If the address encoding is not valid

class P2TRAddrEncoder

Bases: IAddrEncoder

P2TR address encoder class. It allows the Pay-to-Taproot address encoding.

static EncodeKey(pub_key: Union[bytes, IPublicKey], **kwargs: Any) str

Encode a public key to P2TR address.

Parameters:
  • pub_key (bytes or IPublicKey) – Public key bytes or object

  • hrp (str) – HRP

Returns:

Address string

Return type:

str

Raises:
  • ValueError – If the public key is not valid or cannot be tweaked

  • TypeError – If the public key is not secp256k1

P2TRAddr

alias of P2TRAddrEncoder