-
Notifications
You must be signed in to change notification settings - Fork 2
/
privval.go
53 lines (44 loc) · 1.32 KB
/
privval.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
53
package mock
import (
"github.com/fibonacci-chain/fbc/libs/tendermint/crypto"
tmtypes "github.com/fibonacci-chain/fbc/libs/tendermint/types"
"github.com/fibonacci-chain/fbc/libs/tendermint/crypto/ed25519"
)
var _ tmtypes.PrivValidator = PV{}
// MockPV implements PrivValidator without any safety or persistence.
// Only use it for testing.
type PV struct {
PrivKey ed25519.PrivKeyEd25519
}
func NewPV() PV {
return PV{ed25519.GenPrivKey()}
}
// GetPubKey implements PrivValidator interface
func (pv PV) GetPubKey() (crypto.PubKey, error) {
//return cryptocodec.ToTmPubKeyInterface(pv.PrivKey.PubKey())
return pv.PrivKey.PubKey(), nil
}
// SignVote implements PrivValidator interface
func (pv PV) SignVote(chainID string, vote *tmtypes.Vote) error {
signBytes := tmtypes.VoteSignBytes(chainID, vote)
sig, err := pv.PrivKey.Sign(signBytes)
if err != nil {
return err
}
vote.Signature = sig
return nil
}
// SignProposal implements PrivValidator interface
func (pv PV) SignProposal(chainID string, proposal *tmtypes.Proposal) error {
signBytes := tmtypes.ProposalSignBytes(chainID, proposal)
sig, err := pv.PrivKey.Sign(signBytes)
if err != nil {
return err
}
proposal.Signature = sig
return nil
}
// SignBytes implements PrivValidator interface
func (pv PV) SignBytes(bz []byte) ([]byte, error) {
return pv.PrivKey.Sign(bz)
}