mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-20 15:04:22 +00:00
crypto: API modifications (#5236)
## Description This PR aims to make the crypto.PubKey interface more intuitive. Changes: - `VerfiyBytes` -> `VerifySignature` Before `Bytes()` was amino encoded, now since it is the byte representation should we get rid of it entirely? EDIT: decided to keep `Bytes()` as it is useful if you are using the interface instead of the concrete key Closes: #XXX
This commit is contained in:
+6
-6
@@ -290,10 +290,10 @@ func (dve *DuplicateVoteEvidence) Verify(chainID string, pubKey crypto.PubKey) e
|
||||
va := dve.VoteA.ToProto()
|
||||
vb := dve.VoteB.ToProto()
|
||||
// Signatures must be valid
|
||||
if !pubKey.VerifyBytes(VoteSignBytes(chainID, va), dve.VoteA.Signature) {
|
||||
if !pubKey.VerifySignature(VoteSignBytes(chainID, va), dve.VoteA.Signature) {
|
||||
return fmt.Errorf("verifying VoteA: %w", ErrVoteInvalidSignature)
|
||||
}
|
||||
if !pubKey.VerifyBytes(VoteSignBytes(chainID, vb), dve.VoteB.Signature) {
|
||||
if !pubKey.VerifySignature(VoteSignBytes(chainID, vb), dve.VoteB.Signature) {
|
||||
return fmt.Errorf("verifying VoteB: %w", ErrVoteInvalidSignature)
|
||||
}
|
||||
|
||||
@@ -724,7 +724,7 @@ func (e *LunaticValidatorEvidence) Verify(chainID string, pubKey crypto.PubKey)
|
||||
}
|
||||
|
||||
v := e.Vote.ToProto()
|
||||
if !pubKey.VerifyBytes(VoteSignBytes(chainID, v), e.Vote.Signature) {
|
||||
if !pubKey.VerifySignature(VoteSignBytes(chainID, v), e.Vote.Signature) {
|
||||
return errors.New("invalid signature")
|
||||
}
|
||||
|
||||
@@ -948,10 +948,10 @@ func (e *PotentialAmnesiaEvidence) Verify(chainID string, pubKey crypto.PubKey)
|
||||
vb := e.VoteB.ToProto()
|
||||
|
||||
// Signatures must be valid
|
||||
if !pubKey.VerifyBytes(VoteSignBytes(chainID, va), e.VoteA.Signature) {
|
||||
if !pubKey.VerifySignature(VoteSignBytes(chainID, va), e.VoteA.Signature) {
|
||||
return fmt.Errorf("verifying VoteA: %w", ErrVoteInvalidSignature)
|
||||
}
|
||||
if !pubKey.VerifyBytes(VoteSignBytes(chainID, vb), e.VoteB.Signature) {
|
||||
if !pubKey.VerifySignature(VoteSignBytes(chainID, vb), e.VoteB.Signature) {
|
||||
return fmt.Errorf("verifying VoteB: %w", ErrVoteInvalidSignature)
|
||||
}
|
||||
|
||||
@@ -1145,7 +1145,7 @@ func (e *ProofOfLockChange) ValidateVotes(valSet *ValidatorSet, chainID string)
|
||||
if bytes.Equal(validator.Address, vote.ValidatorAddress) {
|
||||
exists = true
|
||||
v := vote.ToProto()
|
||||
if !validator.PubKey.VerifyBytes(VoteSignBytes(chainID, v), vote.Signature) {
|
||||
if !validator.PubKey.VerifySignature(VoteSignBytes(chainID, v), vote.Signature) {
|
||||
return fmt.Errorf("cannot verify vote (from validator: %d) against signature: %v",
|
||||
vote.ValidatorIndex, vote.Signature)
|
||||
}
|
||||
|
||||
@@ -71,7 +71,7 @@ func TestProposalVerifySignature(t *testing.T) {
|
||||
prop.Signature = p.Signature
|
||||
|
||||
// verify the same proposal
|
||||
valid := pubKey.VerifyBytes(signBytes, prop.Signature)
|
||||
valid := pubKey.VerifySignature(signBytes, prop.Signature)
|
||||
require.True(t, valid)
|
||||
|
||||
// serialize, deserialize and verify again....
|
||||
@@ -90,7 +90,7 @@ func TestProposalVerifySignature(t *testing.T) {
|
||||
// verify the transmitted proposal
|
||||
newSignBytes := ProposalSignBytes("test_chain_id", pb)
|
||||
require.Equal(t, string(signBytes), string(newSignBytes))
|
||||
valid = pubKey.VerifyBytes(newSignBytes, np.Signature)
|
||||
valid = pubKey.VerifySignature(newSignBytes, np.Signature)
|
||||
require.True(t, valid)
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ func BenchmarkProposalVerifySignature(b *testing.B) {
|
||||
require.NoError(b, err)
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
pubKey.VerifyBytes(ProposalSignBytes("test_chain_id", pbp), testProposal.Signature)
|
||||
pubKey.VerifySignature(ProposalSignBytes("test_chain_id", pbp), testProposal.Signature)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -84,12 +84,12 @@ func TestABCIEvidence(t *testing.T) {
|
||||
|
||||
type pubKeyEddie struct{}
|
||||
|
||||
func (pubKeyEddie) Address() Address { return []byte{} }
|
||||
func (pubKeyEddie) Bytes() []byte { return []byte{} }
|
||||
func (pubKeyEddie) VerifyBytes(msg []byte, sig []byte) bool { return false }
|
||||
func (pubKeyEddie) Equals(crypto.PubKey) bool { return false }
|
||||
func (pubKeyEddie) String() string { return "" }
|
||||
func (pubKeyEddie) Type() string { return "pubKeyEddie" }
|
||||
func (pubKeyEddie) Address() Address { return []byte{} }
|
||||
func (pubKeyEddie) Bytes() []byte { return []byte{} }
|
||||
func (pubKeyEddie) VerifySignature(msg []byte, sig []byte) bool { return false }
|
||||
func (pubKeyEddie) Equals(crypto.PubKey) bool { return false }
|
||||
func (pubKeyEddie) String() string { return "" }
|
||||
func (pubKeyEddie) Type() string { return "pubKeyEddie" }
|
||||
|
||||
func TestABCIValidatorFromPubKeyAndPower(t *testing.T) {
|
||||
pubkey := ed25519.GenPrivKey().PubKey()
|
||||
|
||||
@@ -688,7 +688,7 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,
|
||||
|
||||
// Validate signature.
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, int32(idx))
|
||||
if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) {
|
||||
if !val.PubKey.VerifySignature(voteSignBytes, commitSig.Signature) {
|
||||
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
}
|
||||
// Good!
|
||||
@@ -746,7 +746,7 @@ func (vals *ValidatorSet) VerifyCommitLight(chainID string, blockID BlockID,
|
||||
|
||||
// Validate signature.
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, int32(idx))
|
||||
if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) {
|
||||
if !val.PubKey.VerifySignature(voteSignBytes, commitSig.Signature) {
|
||||
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
}
|
||||
|
||||
@@ -807,7 +807,7 @@ func (vals *ValidatorSet) VerifyCommitLightTrusting(chainID string, commit *Comm
|
||||
|
||||
// Validate signature.
|
||||
voteSignBytes := commit.VoteSignBytes(chainID, int32(idx))
|
||||
if !val.PubKey.VerifyBytes(voteSignBytes, commitSig.Signature) {
|
||||
if !val.PubKey.VerifySignature(voteSignBytes, commitSig.Signature) {
|
||||
return fmt.Errorf("wrong signature (#%d): %X", idx, commitSig.Signature)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -149,7 +149,7 @@ func (vote *Vote) Verify(chainID string, pubKey crypto.PubKey) error {
|
||||
return ErrVoteInvalidValidatorAddress
|
||||
}
|
||||
v := vote.ToProto()
|
||||
if !pubKey.VerifyBytes(VoteSignBytes(chainID, v), vote.Signature) {
|
||||
if !pubKey.VerifySignature(VoteSignBytes(chainID, v), vote.Signature) {
|
||||
return ErrVoteInvalidSignature
|
||||
}
|
||||
return nil
|
||||
|
||||
+2
-2
@@ -161,7 +161,7 @@ func TestVoteVerifySignature(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
// verify the same vote
|
||||
valid := pubkey.VerifyBytes(VoteSignBytes("test_chain_id", v), v.Signature)
|
||||
valid := pubkey.VerifySignature(VoteSignBytes("test_chain_id", v), v.Signature)
|
||||
require.True(t, valid)
|
||||
|
||||
// serialize, deserialize and verify again....
|
||||
@@ -174,7 +174,7 @@ func TestVoteVerifySignature(t *testing.T) {
|
||||
// verify the transmitted vote
|
||||
newSignBytes := VoteSignBytes("test_chain_id", precommit)
|
||||
require.Equal(t, string(signBytes), string(newSignBytes))
|
||||
valid = pubkey.VerifyBytes(newSignBytes, precommit.Signature)
|
||||
valid = pubkey.VerifySignature(newSignBytes, precommit.Signature)
|
||||
require.True(t, valid)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user