swh.alter.bech32 module#

Reference implementation for Bech32/Bech32m and segwit addresses.

class swh.alter.bech32.Encoding(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#

Bases: Enum

Enumeration type to list the various supported encodings.

BECH32 = 1#
BECH32M = 2#
swh.alter.bech32.convert_bits(data: List[int], from_bits: int, to_bits: int, pad: bool = False) List[int][source]#
swh.alter.bech32.bech32_polymod(values: List[int]) int[source]#

Internal function that computes the Bech32 checksum.

swh.alter.bech32.bech32_hrp_expand(hrp: str) List[int][source]#

Expand the HRP into values for checksum computation.

swh.alter.bech32.bech32_verify_checksum(hrp: str, data: List[int]) Encoding | None[source]#

Verify a checksum given HRP and converted data characters.

swh.alter.bech32.bech32_create_checksum(hrp: str, data: List[int], spec: Encoding) List[int][source]#

Compute the checksum values given HRP and data.

swh.alter.bech32.bech32_encode(hrp: str, data: List[int], spec: Encoding) str[source]#

Compute a Bech32 string given HRP and data values.

swh.alter.bech32.bech32_decode(bech: str) Tuple[str, List[int], Encoding][source]#

Validate a Bech32/Bech32m string, and determine HRP and data.