addr_dec_utils

Module with utility functions for address decoding.

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 (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_bytes: bytes, checksum_bytes_exp: bytes, checksum_fct: Callable[[bytes], bytes]) None

Validate address checksum.

Parameters:
  • payload_bytes (bytes) – Payload bytes

  • checksum_bytes_exp (bytes) – Expected checksum bytes

  • checksum_fct (function) – Function for computing checksum

Raises:

ValueError – If the computed checksum is not equal tot he specified one

static SplitPartsByChecksum(addr_bytes: bytes, checksum_len: int) Tuple[bytes, bytes]

Split address in two parts, considering the checksum at the end of it.

Parameters:
  • addr_bytes (bytes) – Address bytes

  • checksum_len (int) – Checksum length

Returns:

Payload bytes (index 0) and checksum bytes (index 1)

Return type:

tuple[bytes, bytes]