From 14f90e5946920a5034ed728a88de0553e984240c Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Fri, 16 Jul 2021 17:41:55 -0700 Subject: [PATCH] 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. --- bech32/error.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bech32/error.go b/bech32/error.go index c987b6e..e8b1fe8 100644 --- a/bech32/error.go +++ b/bech32/error.go @@ -65,15 +65,17 @@ func (e ErrNonCharsetChar) Error() 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 { - Expected string - Actual string + Expected string + ExpectedM string + Actual string } func (e ErrInvalidChecksum) Error() string { - return fmt.Sprintf("invalid checksum (expected %v got %v)", - e.Expected, e.Actual) + return fmt.Sprintf("invalid checksum (expected (bech32=%v, "+ + "bech32m=%v), got %v)", e.Expected, e.ExpectedM, e.Actual) } // ErrInvalidDataByte is returned when a byte outside the range required for