Encoders¶
Riemann offers 3 encoders: base58, bech32, and cashaddr (also bech32). Each exposes an encode and decode function.
Base58¶
Implementation of Base58 encoding with checksum
-
riemann.encoding.base58.decode(s: str, checksum: bool = True) → bytes¶ Convert base58 to binary using BASE58_ALPHABET.
-
riemann.encoding.base58.decode_with_checksum(s: str) → bytes¶ If the passed string is base58check, return the binary data.
Otherwise raises a ValueError.
-
riemann.encoding.base58.encode(data: bytes, checksum: bool = True) → str¶ Convert binary to base58 using BASE58_ALPHABET.
-
riemann.encoding.base58.encode_with_checksum(data: bytes) → str¶ A “hashed_base58” structure is a base58 integer (which looks like a string) with four bytes of hash data at the end.
This function turns data into its hashed_base58 equivalent.
-
riemann.encoding.base58.from_long(v: int, prefix: int, base: int, charset: Callable[..., int]) → bytes¶ The inverse of to_long. Convert an integer to an arbitrary base.
- Parameters
v – the integer value to convert
prefix – the number of prefixed 0s to include
base – the new radix
charset – an array indicating printable characters to use for each value
-
riemann.encoding.base58.has_checksum(base58: str) → bool¶ Return True if and only if base58 is valid hashed_base58.
-
riemann.encoding.base58.to_long(base: int, lookup_f: Callable[..., int], s: bytes) → Tuple[int, int]¶ Convert an array to a (possibly bignum) integer, along with a prefix value of how many prefixed zeros there are.
- Parameters
base – the source radix
lookup_f – a function to convert an element of s to a value between 0 and base-1.
s – the value to convert
Bech32¶
Reference implementation for Bech32 and segwit addresses.
-
riemann.encoding.bech32.bech32_create_checksum(hrp, data)¶ Compute the checksum values given HRP and data.
-
riemann.encoding.bech32.bech32_decode(bech)¶ Validate a Bech32 string, and determine HRP and data.
-
riemann.encoding.bech32.bech32_encode(hrp, data)¶ Compute a Bech32 string given HRP and data values.
-
riemann.encoding.bech32.bech32_hrp_expand(hrp)¶ Expand the HRP into values for checksum computation.
-
riemann.encoding.bech32.bech32_polymod(values)¶ Internal function that computes the Bech32 checksum.
-
riemann.encoding.bech32.bech32_verify_checksum(hrp, data)¶ Verify a checksum given HRP and converted data characters.
-
riemann.encoding.bech32.convertbits(data, frombits, tobits, pad=True)¶ General power-of-2 base conversion.
-
riemann.encoding.bech32.decode(bech: str) → bytes¶ Convert bech32 to bytes
-
riemann.encoding.bech32.encode(data: bytes) → str¶ Convert bytes to bech32
-
riemann.encoding.bech32.segwit_decode(hrp, addr)¶ Decode a segwit address.
-
riemann.encoding.bech32.segwit_encode(hrp, witver, witprog)¶ Encode a segwit address.
Cashaddr¶
-
riemann.encoding.cashaddr.b32decode(inputs)¶
-
riemann.encoding.cashaddr.b32encode(inputs)¶
-
riemann.encoding.cashaddr.calculate_checksum(prefix, payload)¶
-
riemann.encoding.cashaddr.convertbits(data, frombits, tobits, pad=True)¶
-
riemann.encoding.cashaddr.decode(data: str) → bytes¶ Convert cashaddr-bech32 to bytes
-
riemann.encoding.cashaddr.encode(data: bytes) → str¶ Convert bytes to cashaddr-bech32
-
riemann.encoding.cashaddr.polymod(values)¶
-
riemann.encoding.cashaddr.prefix_expand(prefix)¶
-
riemann.encoding.cashaddr.verify_checksum(prefix, payload)¶