addr_dec_utils
Module with utility functions for address decoding.
- class ChecksumPositions(value)
Bases:
Enum
Enumerative for checksum positions.
- BEGINNING = 1
- END = 2
- class AddrDecUtils
Bases:
object
Class container for address decoding utility functions.
- static ValidateAndRemovePrefix(addr: BytesOrStr, prefix: BytesOrStr) BytesOrStr
Validate and remove prefix from an address.
- Parameters:
addr (bytes or str) – Address string or bytes
prefix (bytes or str) – Address prefix
- Returns:
Address string or bytes with prefix removed
- Return type:
bytes or str
- Raises:
ValueError – If the prefix is not valid
- static ValidateLength(addr: Union[bytes, str], len_exp: int) None
Validate address length.
- Parameters:
addr (bytes or str) – Address string or bytes
len_exp (int) – Expected address length
- Raises:
ValueError – If the length is not valid
- static ValidatePubKey(pub_key_bytes: bytes, pub_key_cls: Type[IPublicKey]) None
Validate address length.
- Parameters:
pub_key_bytes (bytes) – Public key bytes
pub_key_cls (IPublicKey) – Public key class type
- Raises:
ValueError – If the public key is not valid
- static ValidateChecksum(payload: BytesOrStr, checksum_exp: BytesOrStr, checksum_fct: Callable[[BytesOrStr], BytesOrStr]) None
Validate address checksum.
- Parameters:
payload (bytes or str) – Payload string or bytes
checksum_exp (bytes or str) – Expected checksum string or bytes
checksum_fct (function) – Function for computing checksum
- Raises:
ValueError – If the computed checksum is not equal to the specified one
- static SplitPartsByChecksum(addr: BytesOrStr, checksum_len: int, checksum_pos: ChecksumPositions = ChecksumPositions.END) Tuple[BytesOrStr, BytesOrStr]
Split address in two parts, payload and checksum.
- Parameters:
addr (bytes or str) – Address string or bytes
checksum_len (int) – Checksum length
checksum_pos (bool) – True if checksum is at the end of the address, false if it is at the beginning
- Returns:
Payload (index 0) and checksum (index 1)
- Return type:
tuple[bytes or str, bytes or str]