A fast, zero-dependency Base58 encoding library for Go with support for both standard and chunked encoding.
- Standard Base58 — variable-length encoding commonly used for Bitcoin addresses
- Chunked Base58 — fixed-block encoding that splits input into 8-byte chunks, providing O(n) performance instead of O(n²) for large payloads
- Buffer reuse —
EncodeToallows encoding into a caller-provided buffer with zero allocations - Custom alphabets — includes Bitcoin and Flickr alphabets, or create your own with
NewEncoding
go get github.com/KarpelesLab/base58
// Encode
encoded := base58.Bitcoin.Encode(data)
// Decode
decoded, err := base58.Bitcoin.Decode(encoded)
// Encode with buffer reuse (zero allocations)
buf := make([]byte, base58.EncodedMaxLen(len(data)))
result := base58.Bitcoin.EncodeTo(buf[:0], data)Chunked encoding processes data in independent 8-byte blocks, making it significantly faster for larger payloads at the cost of a slightly longer output.
// Encode
encoded := base58.Bitcoin.EncodeChunked(data)
// Decode
decoded, err := base58.Bitcoin.DecodeChunked(encoded)enc := base58.NewEncoding("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
encoded := enc.Encode(data)| Name | Alphabet |
|---|---|
Bitcoin |
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz |
Flickr |
123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ |
Standard base58 is O(n²) due to full-buffer carry propagation. Chunked encoding is O(n) since each 8-byte block is encoded independently. Benchmarks on an Intel i9-14900K:
Run benchmarks yourself:
go test -bench=. -benchmem
