-
Notifications
You must be signed in to change notification settings - Fork 458
/
signature.go
31 lines (25 loc) · 882 Bytes
/
signature.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package types
import (
logging "github.com/ipfs/go-log"
"github.com/filecoin-project/go-filecoin/address"
wutil "github.com/filecoin-project/go-filecoin/wallet/util"
)
var log = logging.Logger("types")
// Signature is the result of a cryptographic sign operation.
type Signature []byte
// IsValidSignature cryptographically verifies that 'sig' is the signed hash of 'data' with
// the public key belonging to `addr`.
func IsValidSignature(data []byte, addr address.Address, sig Signature) bool {
maybePk, err := wutil.Ecrecover(data, sig)
if err != nil {
// Any error returned from Ecrecover means this signature is not valid.
log.Infof("error in signature validation: %s", err)
return false
}
maybeAddr, err := address.NewSecp256k1Address(maybePk)
if err != nil {
log.Infof("error in recovered address: %s", err)
return false
}
return maybeAddr == addr
}