23db973afa
In this commit, we add two new package level functions: `EncodeM`, and `DecodeGeneric`. The new encode method is intended to allow callers to specify that they want to use the new bech32m checksum. This should be used when encoding segwit addresses with version 1 and beyond. The new `DecodeGeneric` function allows a caller to decode a bech32 and bech32m string with a single function. A new return value is added which is the version of the returned bech32 string, which allows callers to perform additional segwit addr validation (v1+ should use bech32m etc). We opted to add new functions rather than modifying the existing functions to not cause a breaking API change, as most uses in the wild can just use the existing functions, and only taproot related logic/code needs to worry about the new methods. A series of tests have been added to ensure that `DecodeGeneric` extracts the proper bech version, and we've also adopted the bech32m tests from BIP 350. |
||
---|---|---|
.. | ||
bech32.go | ||
bech32_test.go | ||
doc.go | ||
error.go | ||
example_test.go | ||
README.md | ||
version.go |
bech32
Package bech32 provides a Go implementation of the bech32 format specified in BIP 173.
Test vectors from BIP 173 are added to ensure compatibility with the BIP.
Installation and Updating
$ go get -u github.com/btcsuite/btcutil/bech32
Examples
- Bech32 decode Example Demonstrates how to decode a bech32 encoded string.
- Bech32 encode Example Demonstrates how to encode data into a bech32 string.
License
Package bech32 is licensed under the copyfree ISC License.