A Go package for encoding and decoding Bech32, Bech32m, and CashAddr addresses.
- Bech32 encoding/decoding (BIP-173, segwit v0)
- Bech32m encoding/decoding (BIP-350, segwit v1+)
- CashAddr encoding/decoding (Bitcoin Cash)
- Segwit address encode/decode helpers
- Zero-allocation polymod checksum using lookup tables
go get github.com/KarpelesLab/bech32m// Decode a segwit address
witver, witprog, err := bech32m.SegwitAddrDecode("bc", "bc1qw508d6qejxtdg4y5r3zarvary0c5xw7kv8f3t4")
// Encode a segwit address
addr, err := bech32m.SegwitAddrEncode("bc", witver, witprog)// Decode a CashAddr address
vers, payload, err := bech32m.CashAddrDecode("bitcoincash:", "bitcoincash:qr6m7j9njldwwzlg9v7v53unlr4jkmx6eylep8ekg2")
// Encode a CashAddr address
addr, err := bech32m.CashAddrEncode("bitcoincash:", vers, payload)// Encode raw data with Bech32m
encoded := bech32m.Encode("hrp", data, bech32m.Bech32m)
// Decode any Bech32/Bech32m/CashAddr string
hrp, data, spec, err := bech32m.Decode(encoded)