@@ -9,25 +9,31 @@ import (
9
9
"github.com/bitcoinsv/bsvd/bsvec"
10
10
"github.com/bitcoinsv/bsvd/chaincfg/chainhash"
11
11
"github.com/bitcoinsv/bsvd/wire"
12
+ "github.com/bitcoinsv/bsvutil"
12
13
)
13
14
14
15
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
16
17
hBSV string = "Bitcoin Signed Message:\n "
17
18
)
18
19
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
20
21
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 {
23
25
return nil , false , err
24
26
}
25
27
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
28
30
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
+ }
31
37
32
38
// Create the hash
33
39
expectedMessageHash := chainhash .DoubleHashB (buf .Bytes ())
@@ -48,13 +54,21 @@ func VerifyMessage(address, sig, data string) error {
48
54
}
49
55
50
56
// 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
+ }
52
61
53
62
// Return nil if addresses match.
54
63
if bsvecAddress .String () == address {
55
64
return nil
56
65
}
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
+ )
58
72
}
59
73
60
74
// VerifyMessageDER will take a message string, a public key string and a signature string
0 commit comments