{"id":1945,"library":"base58","title":"Base58","description":"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.","status":"active","version":"2.1.1","language":"en","source_language":"en","source_url":"https://github.com/keis/base58","tags":["encoding","base58","cryptography","bitcoin","blockchain"],"install":[{"cmd":"pip install base58","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python 3.5 or higher for versions 2.x.","package":"Python","optional":false}],"imports":[{"note":"Input must be a bytes-like object, not a string.","wrong":"base58.b58encode('string_data')","symbol":"b58encode","correct":"import base58\nbase58.b58encode(...)"},{"note":"Input must be a bytes-like object (or a string that decodes to bytes), not a plain string, for consistent behavior.","wrong":"base58.b58decode('string_data')","symbol":"b58decode","correct":"import base58\nbase58.b58decode(...)"},{"note":"Encodes with a built-in checksum. Input must be bytes.","symbol":"b58encode_check","correct":"import base58\nbase58.b58encode_check(...)"},{"note":"Decodes with a built-in checksum verification. Input must be bytes.","symbol":"b58decode_check","correct":"import base58\nbase58.b58decode_check(...)"},{"note":"`XRP_ALPHABET` is the recommended alias for the Ripple alphabet, though `RIPPLE_ALPHABET` is also provided for compatibility.","wrong":"base58.RIPPLE_ALPHABET","symbol":"XRP_ALPHABET","correct":"import base58\nbase58.XRP_ALPHABET"}],"quickstart":{"code":"import base58\n\n# Encode binary data\ndata_bytes = b'hello world'\nencoded_data = base58.b58encode(data_bytes)\nprint(f\"Encoded: {encoded_data.decode('ascii')}\")\n\n# Decode Base58 string back to bytes\ndecoded_bytes = base58.b58decode(encoded_data)\nprint(f\"Decoded: {decoded_bytes.decode('utf-8')}\")\n\n# Encode with Base58Check (includes a checksum)\ndata_for_check = b'my secret data'\nencoded_check = base58.b58encode_check(data_for_check)\nprint(f\"Encoded (with check): {encoded_check.decode('ascii')}\")\n\n# Decode Base58Check (verifies checksum)\ndecoded_check = base58.b58decode_check(encoded_check)\nprint(f\"Decoded (with check): {decoded_check.decode('utf-8')}\")\n\n# Using a custom alphabet (e.g., XRP/Ripple)\nxrp_data = b'xrp address seed'\nencoded_xrp = base58.b58encode(xrp_data, alphabet=base58.XRP_ALPHABET)\nprint(f\"Encoded (XRP alphabet): {encoded_xrp.decode('ascii')}\")","lang":"python","description":"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."},"warnings":[{"fix":"Upgrade to Python 3.5+ to use base58 >= 2.0.0. If unable to upgrade Python, pin to base58<2.0.0.","message":"Python 2 support was dropped in version 2.0.0. Projects still on Python 2 must use the 1.x series, which will not receive new features.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Always convert string inputs to bytes (e.g., `my_string.encode('utf-8')`) before passing them to `base58` functions. Similarly, if you need a string output, decode the resulting bytes (e.g., `encoded_bytes.decode('ascii')`).","message":"Encoding and decoding functions (`b58encode`, `b58decode`, etc.) strictly expect bytes-like objects as input. Passing a plain Python string will result in errors or incorrect encoding.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure input strings for decoding are valid Base58. Implement robust error handling (e.g., `try-except ValueError`) when processing external or untrusted Base58 strings.","message":"When decoding, the input string must strictly adhere to the Base58 character set. The library's decoding functions will raise a `ValueError` if invalid characters (e.g., '0', 'O', 'I', 'l' which are excluded from Base58) are present.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Explicitly pass the `alphabet` parameter to both `b58encode` and `b58decode` functions to guarantee consistency, especially when dealing with data from different systems.","message":"If using custom alphabets (e.g., `base58.XRP_ALPHABET`), ensure that the *exact same alphabet* is used for both encoding and subsequent decoding. Mismatched alphabets will lead to `ValueError` or corrupted data.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always use `base58.b58encode_check()` and `base58.b58decode_check()` for Base58Check operations to leverage the library's correct handling of checksums. Avoid manual checksum computations where possible with this library.","message":"When dealing with Base58Check, the checksum calculation (typically a double SHA-256 hash) and its inclusion are crucial. Manually implementing this can be prone to errors in hashing or byte extraction.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}