-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathproof.go
40 lines (36 loc) · 949 Bytes
/
proof.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
package spec
import (
"bytes"
"fmt"
"github.com/ssvlabs/dkg-spec/crypto"
)
func ValidateCeremonyProof(
validatorPK []byte,
operator *Operator,
signedProof SignedProof,
) error {
// verify owner address is not zero address
if bytes.Equal(signedProof.Proof.Owner[:], make([]byte, 20)) {
return fmt.Errorf("invalid owner address")
}
// verify validator pk
if !bytes.Equal(validatorPK, signedProof.Proof.ValidatorPubKey) {
return fmt.Errorf("invalid proof validator pubkey")
}
if err := VerifyCeremonyProof(operator.PubKey, signedProof); err != nil {
return err
}
return nil
}
// VerifyCeremonyProof returns error if ceremony signed proof is invalid
func VerifyCeremonyProof(pkBytes []byte, proof SignedProof) error {
hash, err := proof.Proof.HashTreeRoot()
if err != nil {
return err
}
pk, err := crypto.ParseRSAPublicKey(pkBytes)
if err != nil {
return err
}
return crypto.VerifyRSA(pk, hash[:], proof.Signature)
}