bech32: add additional field to ErrInvalidChecksum (bech32m version)

In this commit, we add an additional field to the ErrInvalidChecksum,
the bech32m version of a checksum. When decoding, we don't now what
version they actually _intended_ to use, so we'll opt to include both
checksums to aide in debugging and error reporting.
This commit is contained in:
Olaoluwa Osuntokun 2021-07-16 17:41:55 -07:00
parent 3ecfc35771
commit 14f90e5946
No known key found for this signature in database
GPG key ID: 3BBD59E99B280306

View file

@ -65,15 +65,17 @@ func (e ErrNonCharsetChar) Error() string {
} }
// ErrInvalidChecksum is returned when the extracted checksum of the string // ErrInvalidChecksum is returned when the extracted checksum of the string
// is different than what was expected. // is different than what was expected. Both the original version, as well as
// the new bech32m checksum may be specified.
type ErrInvalidChecksum struct { type ErrInvalidChecksum struct {
Expected string Expected string
Actual string ExpectedM string
Actual string
} }
func (e ErrInvalidChecksum) Error() string { func (e ErrInvalidChecksum) Error() string {
return fmt.Sprintf("invalid checksum (expected %v got %v)", return fmt.Sprintf("invalid checksum (expected (bech32=%v, "+
e.Expected, e.Actual) "bech32m=%v), got %v)", e.Expected, e.ExpectedM, e.Actual)
} }
// ErrInvalidDataByte is returned when a byte outside the range required for // ErrInvalidDataByte is returned when a byte outside the range required for