-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsigner_ocr.go
43 lines (36 loc) · 877 Bytes
/
signer_ocr.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
package don
import (
cryptorand "crypto/rand"
"fmt"
)
type Signer interface {
OracleID() OracleID
Sign(reportCtx ReportContext, report []byte) ([]byte, error)
Verify(pubKey OnchainPublicKey, reportCtx ReportContext, report, signed []byte) error
}
type OcrSigner struct {
k *EvmKeyring
oid OracleID
}
func NewSigner(oid OracleID) *OcrSigner {
k, err := NewEVMKeyring(cryptorand.Reader)
if err != nil {
panic(err)
}
return &OcrSigner{
k: k,
oid: oid,
}
}
func (s *OcrSigner) OracleID() OracleID {
return s.oid
}
func (s *OcrSigner) Sign(reportCtx ReportContext, report []byte) ([]byte, error) {
return s.k.Sign(reportCtx, report)
}
func (s *OcrSigner) Verify(pubKey OnchainPublicKey, reportCtx ReportContext, report, signed []byte) error {
if !s.k.Verify(pubKey, reportCtx, report, signed) {
return fmt.Errorf("invalid report")
}
return nil
}