segwit_bech32

Module for segwit bech32/bech32m decoding/encoding.

References

https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki https://github.com/bitcoin/bips/blob/master/bip-0350.mediawiki

class SegwitBech32Const

Bases: object

Class container for Segwit Bech32 constants.

SEPARATOR: str = '1'
CHECKSUM_STR_LEN: int = 6
WITNESS_PROG_MIN_BYTE_LEN: int = 2
WITNESS_PROG_MAX_BYTE_LEN: int = 40
WITNESS_VER_BECH32: int = 0
WITNESS_VER_MAX_VAL: int = 16
WITNESS_VER_ZERO_DATA_BYTE_LEN: Tuple[int, int] = (20, 32)
class SegwitBech32Encoder

Bases: Bech32EncoderBase

Segwit Bech32 encoder class. It provides methods for encoding to Segwit Bech32 format.

classmethod Encode(hrp: str, wit_ver: int, wit_prog: bytes) str

Encode to Segwit Bech32.

Parameters:
  • hrp (str) – HRP

  • wit_ver (int) – Witness version

  • wit_prog (bytes) – Witness program

Returns:

Encoded address

Return type:

str

Raises:

ValueError – If the data is not valid

class SegwitBech32Decoder

Bases: Bech32DecoderBase

Segwit Bech32 decoder class. It provides methods for decoding Segwit Bech32 format.

classmethod Decode(hrp: str, addr: str) Tuple[int, bytes]

Decode from Segwit Bech32.

Parameters:
  • hrp (str) – Human readable part

  • addr (str) – Address

Returns:

Witness version (index 0) and witness program (index 1)

Return type:

tuple[int, bytes]

Raises:
  • Bech32ChecksumError – If the checksum is not valid

  • ValueError – If the bech32 string is not valid