Base58

2.1.1 · active · verified Thu Apr 09

The `base58` library provides an implementation of Base58 and Base58Check encoding and decoding, compatible with schemes used by the Bitcoin network. It also supports custom alphabets, such as the XRP one. The current version is 2.1.1, and the library has a stable release history with periodic updates to address compatibility and features.

Warnings

Install

Imports

Quickstart

Demonstrates basic Base58 encoding and decoding, including the Base58Check functionality and using a custom alphabet like XRP's. It's crucial to work with byte strings for all encoding/decoding operations.

import base58

# Encode binary data
data_bytes = b'hello world'
encoded_data = base58.b58encode(data_bytes)
print(f"Encoded: {encoded_data.decode('ascii')}")

# Decode Base58 string back to bytes
decoded_bytes = base58.b58decode(encoded_data)
print(f"Decoded: {decoded_bytes.decode('utf-8')}")

# Encode with Base58Check (includes a checksum)
data_for_check = b'my secret data'
encoded_check = base58.b58encode_check(data_for_check)
print(f"Encoded (with check): {encoded_check.decode('ascii')}")

# Decode Base58Check (verifies checksum)
decoded_check = base58.b58decode_check(encoded_check)
print(f"Decoded (with check): {decoded_check.decode('utf-8')}")

# Using a custom alphabet (e.g., XRP/Ripple)
xrp_data = b'xrp address seed'
encoded_xrp = base58.b58encode(xrp_data, alphabet=base58.XRP_ALPHABET)
print(f"Encoded (XRP alphabet): {encoded_xrp.decode('ascii')}")

view raw JSON →