API Reference

b58decode(val, alphabet)

Decode a base-58 value.

Parameters
  • val (bytes) – The bytes to decode.

  • alphabet (Alphabet, optional) – The encoding alphabet. Defaults to Alphabet.BITCOIN.

Returns

The decoded value.

Return type

bytes

Example

>>> from based58 import b58decode, Alphabet
>>> b58decode(b"he11owor1d")
b'\x040^+$s\xf0X'
>>> b58decode(b"he11owor1d", Alphabet.RIPPLE)
b'`e\xe7\x9b\xba/x'
b58encode(val, alphabet)

Encode bytes into base-58.

Parameters
  • val (bytes) – The bytes to encode.

  • alphabet (Alphabet, optional) – The encoding alphabet. Defaults to Alphabet.BITCOIN.

Returns

The encoded value.

Return type

bytes

Example

>>> from based58 import b58encode, Alphabet
>>> b58encode(b"\x040^+$s\xf0X")
b'he11owor1d'
>>> b58encode(b'`e\xe7\x9b\xba/x', Alphabet.RIPPLE)
b'he11owor1d'
b58decode_check(val, alphabet, expected_ver=None)

Decode and check checksum using the Base58Check algorithm.

Parameters
  • val (bytes) – The bytes to decode.

  • alphabet (Alphabet, optional) – The encoding alphabet. Defaults to Alphabet.BITCOIN.

  • expected_ver (int, optional) – If provided, the version byte will be used in verification. Defaults to None.

Returns

The decoded value.

Return type

bytes

Example

>>> from based58 import b58decode_check
>>> b58decode_check(b"PWEu9GGN")
b'-1'
b58encode_check(val, alphabet, expected_ver=None)

Encode and check checksum using the Base58Check algorithm.

Parameters
  • val (bytes) – The bytes to encode.

  • alphabet (Alphabet, optional) – The encoding alphabet. Defaults to Alphabet.BITCOIN.

  • expected_ver (int, optional) – If provided, the version byte will be used in verification. Defaults to None.

Returns

The encoded value.

Return type

bytes

Example

>>> from based58 import b58encode_check
>>> b58encode_check(b"`e\xe7\x9b\xba/x")
b'QuT57JNzzWTu7mW'
class Alphabet

A collection of 58 ASCII characters used to encode data.

Parameters

base (bytes) – The 58 ASCII characters with which to create the alphabet.

Example

>>> from based58 import Alphabet, b58decode, b58encode
>>> alpha = Alphabet(b" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXY")
>>> decoded = b58decode(b"he11owor1d", alphabet=Alphabet.RIPPLE)
>>> decoded
b'`e\xe7\x9b\xba/x'
>>> b58encode(decoded, alphabet=alpha)
b'#ERRN)N RD'
BITCOIN = Alphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
DEFAULT = Alphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
FLICKR = Alphabet("123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ")
MONERO = Alphabet("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
RIPPLE = Alphabet("rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz")