This PR brings a host of improvements to the bech32 package, back porting from the following commits:
decred/dcrd@9b88dd0
decred/dcrd@3a0dce1
decred/dcrd@3cfb088
The public interface of the package remains unchanged, of course not including new public methods.
Summary of changes
Improved error handling using dedicated error types. Programmatically detect if the errors produced are the expected ones.
Improve test coverage to test more corner cases. Added test vectors from Bitcoin Core.
Add a benchmark for a full encode/decode cycle of a bech32 string.
Add a new function DecodeNoLimit, for decoding large bech32 encoded strings. It does NOT validate against the BIP-173 maximum length allowed for bech32 strings.
Automatically convert the HRP to lowercase in Encode function.
Improve performance of Encode/Decode functions by using strings.Builder.
Improve memory allocation in ConvertBits function.
Oops, Travis CI was testing against really old versions of Go. Additionally, gometalinter seems dead, and I don't really want to fix all the CI stuff in this PR. Let's have #167 merged first.
What is this about?
This PR brings a host of improvements to the bech32 package, back porting from the following commits:
The public interface of the package remains unchanged, of course not including new public methods.
Summary of changes
DecodeNoLimit
, for decoding large bech32 encoded strings. It does NOT validate against the BIP-173 maximum length allowed for bech32 strings.Encode
function.Encode
/Decode
functions by usingstrings.Builder
.ConvertBits
function.Credits: @matheusd
Closes #152 and #168.