Skip to content

Commit 8ff4482

Browse files
committed
Fixed missing err cases, comments
1 parent 101324f commit 8ff4482

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

verify.go

+24-10
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,31 @@ import (
99
"github.com/bitcoinsv/bsvd/bsvec"
1010
"github.com/bitcoinsv/bsvd/chaincfg/chainhash"
1111
"github.com/bitcoinsv/bsvd/wire"
12+
"github.com/bitcoinsv/bsvutil"
1213
)
1314

1415
const (
15-
// H_BSV is the magic header string required fore Bitcoin Signed Messages
16+
// hBSV is the magic header string required fore Bitcoin Signed Messages
1617
hBSV string = "Bitcoin Signed Message:\n"
1718
)
1819

19-
// PublicKeyFromSignature gets a publickey for a signature and tells you whether is was compressed
20+
// PubKeyFromSignature gets a publickey for a signature and tells you whether is was compressed
2021
func PubKeyFromSignature(sig, data string) (pubKey *bsvec.PublicKey, wasCompressed bool, err error) {
21-
decodedSig, err := base64.StdEncoding.DecodeString(sig)
22-
if err != nil {
22+
23+
var decodedSig []byte
24+
if decodedSig, err = base64.StdEncoding.DecodeString(sig); err != nil {
2325
return nil, false, err
2426
}
2527

26-
// Validate the signature - this just shows that it was valid at all.
27-
// we will compare it with the key next.
28+
// Validate the signature - this just shows that it was valid at all
29+
// we will compare it with the key next
2830
var buf bytes.Buffer
29-
wire.WriteVarString(&buf, 0, hBSV)
30-
wire.WriteVarString(&buf, 0, data)
31+
if err = wire.WriteVarString(&buf, 0, hBSV); err != nil {
32+
return nil, false, err
33+
}
34+
if err = wire.WriteVarString(&buf, 0, data); err != nil {
35+
return nil, false, err
36+
}
3137

3238
// Create the hash
3339
expectedMessageHash := chainhash.DoubleHashB(buf.Bytes())
@@ -48,13 +54,21 @@ func VerifyMessage(address, sig, data string) error {
4854
}
4955

5056
// Get the address
51-
bsvecAddress, err := GetAddressFromPubKey(publicKey, wasCompressed)
57+
var bsvecAddress *bsvutil.LegacyAddressPubKeyHash
58+
if bsvecAddress, err = GetAddressFromPubKey(publicKey, wasCompressed); err != nil {
59+
return err
60+
}
5261

5362
// Return nil if addresses match.
5463
if bsvecAddress.String() == address {
5564
return nil
5665
}
57-
return fmt.Errorf("Address (%s) not found. Was compressed: %t\n%s was found instead", address, wasCompressed, bsvecAddress.EncodeAddress())
66+
return fmt.Errorf(
67+
"address (%s) not found - compressed: %t\n%s was found instead",
68+
address,
69+
wasCompressed,
70+
bsvecAddress.EncodeAddress(),
71+
)
5872
}
5973

6074
// VerifyMessageDER will take a message string, a public key string and a signature string

0 commit comments

Comments
 (0)