-
Notifications
You must be signed in to change notification settings - Fork 9
/
vote_signer.go
34 lines (30 loc) · 994 Bytes
/
vote_signer.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
package vote
import (
"github.com/bnb-chain/greenfield-challenger/logging"
"github.com/cometbft/cometbft/votepool"
"github.com/prysmaticlabs/prysm/crypto/bls/blst"
blscmn "github.com/prysmaticlabs/prysm/crypto/bls/common"
)
type VoteSigner struct {
privKey blscmn.SecretKey
pubKey blscmn.PublicKey
}
func NewVoteSigner(pk []byte) *VoteSigner {
privKey, err := blst.SecretKeyFromBytes(pk)
if err != nil {
logging.Logger.Errorf("vote signer failed to generate key from bytes, err=%+v", err.Error())
panic(err)
}
pubKey := privKey.PublicKey()
return &VoteSigner{
privKey: privKey,
pubKey: pubKey,
}
}
// SignVote sign a vote, data is used to sign and generate the signature
func (signer *VoteSigner) SignVote(vote *votepool.Vote, data []byte) {
signature := signer.privKey.Sign(data[:])
vote.EventHash = append(vote.EventHash, data[:]...)
vote.PubKey = append(vote.PubKey, signer.pubKey.Marshal()...)
vote.Signature = append(vote.Signature, signature.Marshal()...)
}