bch_bech32
Module for BitcoinCash bech32 decoding/encoding. Reference: https://github.com/bitcoincashorg/bitcoincash.org/blob/master/spec/cashaddr.md
- class BchBech32Const
Bases:
object
Class container for Bitcoin Cash Bech32 constants.
- SEPARATOR: str = ':'
- CHECKSUM_STR_LEN: int = 8
- class BchBech32Utils
Bases:
object
Class container for Bitcoin Cash utility functions.
- static PolyMod(values: List[int]) int
Computes the polynomial modulus.
- Parameters:
values (list[int]) – List of polynomial coefficients
- Returns:
Computed modulus
- Return type:
int
- static HrpExpand(hrp: str) List[int]
Expand the HRP into values for checksum computation.
- Parameters:
hrp (str) – HRP
- Returns:
Expanded HRP values
- Return type:
list[int]
- static ComputeChecksum(hrp: str, data: List[int]) List[int]
Compute the checksum from the specified HRP and data.
- Parameters:
hrp (str) – HRP
data (list[int]) – Data part
- Returns:
Computed checksum
- Return type:
list[int]
- static VerifyChecksum(hrp: str, data: List[int]) bool
Verify the checksum from the specified HRP and converted data characters.
- Parameters:
hrp (str) – HRP
data (list[int]) – Data part
- Returns:
True if valid, false otherwise
- Return type:
bool
- class BchBech32Encoder
Bases:
Bech32EncoderBase
Bitcoin Cash Bech32 encoder class. It provides methods for encoding to Bitcoin Cash Bech32 format.
- classmethod Encode(hrp: str, net_ver: bytes, data: bytes) str
Encode to Bitcoin Cash Bech32.
- Parameters:
hrp (str) – HRP
net_ver (bytes) – Net version
data (bytes) – Data
- Returns:
Encoded address
- Return type:
str
- Raises:
ValueError – If the data is not valid
- class BchBech32Decoder
Bases:
Bech32DecoderBase
Bitcoin Cash Bech32 decoder class. It provides methods for decoding Bitcoin Cash Bech32 format.
- classmethod Decode(hrp: str, addr: str) Tuple[bytes, bytes]
Decode from Bitcoin Cash Bech32.
- Parameters:
hrp (str) – Human readable part
addr (str) – Address
- Returns:
Net version (index 0) and data (index 1)
- Return type:
tuple[bytes, bytes]
- Raises:
ValueError – If the bech32 string is not valid
Bech32ChecksumError – If the checksum is not valid