-
Notifications
You must be signed in to change notification settings - Fork 2
/
lcp.go
52 lines (46 loc) · 1.71 KB
/
lcp.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package types
import (
"fmt"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto/secp256k1"
)
const (
QuoteOK = "OK"
QuoteSignatureInvalid = "SIGNATURE_INVALID"
QuoteGroupRevoked = "GROUP_REVOKED"
QuoteSignatureRevoked = "SIGNATURE_REVOKED"
QuoteKeyRevoked = "KEY_REVOKED"
QuoteSigRLVersionMismatch = "SIGRL_VERSION_MISMATCH"
QuoteGroupOutOfDate = "GROUP_OUT_OF_DATE"
QuoteConfigurationNeeded = "CONFIGURATION_NEEDED"
QuoteSwHardeningNeeded = "SW_HARDENING_NEEDED"
QuoteConfigurationAndSwHardeningNeeded = "CONFIGURATION_AND_SW_HARDENING_NEEDED"
)
// Note: currently, LCP supports only secp256k1
func VerifySignature(msg []byte, signature []byte, signer common.Address) error {
pubKey, err := secp256k1.RecoverPubkey(msg, signature)
if err != nil {
return err
}
pub, err := crypto.UnmarshalPubkey(pubKey)
if err != nil {
return err
}
addr := crypto.PubkeyToAddress(*pub)
if signer == addr {
return nil
} else {
return fmt.Errorf("unexpected signer: expected=%v actual=%v", signer.Hex(), addr.Hex())
}
}
func VerifySignatureWithSignBytes(signBytes []byte, signature []byte, expectedSigner common.Address) error {
if l := len(signature); l != 65 {
return fmt.Errorf("invalid signature length: expected=%v actual=%v", 65, l)
}
if l := len(expectedSigner); l != common.AddressLength {
return fmt.Errorf("invalid signer length: expected=%v actual=%v", common.AddressLength, l)
}
msg := crypto.Keccak256(signBytes)
return VerifySignature(msg, signature, expectedSigner)
}