-
Notifications
You must be signed in to change notification settings - Fork 202
/
messageSigVerifier.go
50 lines (41 loc) · 1.16 KB
/
messageSigVerifier.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
package process
import (
"github.com/multiversx/mx-chain-core-go/core/check"
"github.com/multiversx/mx-chain-crypto-go"
"github.com/multiversx/mx-chain-go/vm"
)
type messageSigVerifier struct {
kg crypto.KeyGenerator
singleSigner crypto.SingleSigner
}
// NewMessageSigVerifier creates a message signature verifier
func NewMessageSigVerifier(
kg crypto.KeyGenerator,
singleSigner crypto.SingleSigner,
) (*messageSigVerifier, error) {
if check.IfNil(kg) {
return nil, vm.ErrNilKeyGenerator
}
if check.IfNil(singleSigner) {
return nil, vm.ErrNilSingleSigner
}
return &messageSigVerifier{
kg: kg,
singleSigner: singleSigner,
}, nil
}
// Verify checks if message was signed by public key given as byte array
func (m *messageSigVerifier) Verify(message []byte, signedMessage []byte, pubKey []byte) error {
if len(pubKey) == 0 {
return vm.ErrNilPublicKey
}
actPubKey, err := m.kg.PublicKeyFromByteArray(pubKey)
if err != nil {
return err
}
return m.singleSigner.Verify(actPubKey, message, signedMessage)
}
// IsInterfaceNil returns if underlying object is nil
func (m *messageSigVerifier) IsInterfaceNil() bool {
return m == nil
}