diff --git a/priv_key.go b/priv_key.go index 2806e24f7..42f932ba1 100644 --- a/priv_key.go +++ b/priv_key.go @@ -1,6 +1,8 @@ package crypto import ( + "bytes" + secp256k1 "github.com/btcsuite/btcd/btcec" "github.com/tendermint/ed25519" "github.com/tendermint/ed25519/extra25519" @@ -13,6 +15,7 @@ type PrivKey interface { Bytes() []byte Sign(msg []byte) Signature PubKey() PubKey + Equals(PrivKey) bool } // Types of PrivKey implementations @@ -53,6 +56,14 @@ func (privKey PrivKeyEd25519) PubKey() PubKey { return PubKeyEd25519(*ed25519.MakePublicKey(&privKeyBytes)) } +func (privKey PrivKeyEd25519) Equals(other PrivKey) bool { + if otherEd, ok := other.(PrivKeyEd25519); ok { + return bytes.Equal(privKey[:], otherEd[:]) + } else { + return false + } +} + func (privKey PrivKeyEd25519) ToCurve25519() *[32]byte { keyCurve25519 := new([32]byte) privKeyBytes := [64]byte(privKey) @@ -117,6 +128,14 @@ func (privKey PrivKeySecp256k1) PubKey() PubKey { return PubKeySecp256k1(pub) } +func (privKey PrivKeySecp256k1) Equals(other PrivKey) bool { + if otherSecp, ok := other.(PrivKeySecp256k1); ok { + return bytes.Equal(privKey[:], otherSecp[:]) + } else { + return false + } +} + func (privKey PrivKeySecp256k1) String() string { return Fmt("PrivKeySecp256k1{*****}") } diff --git a/pub_key.go b/pub_key.go index 1162a1ef3..de56c8122 100644 --- a/pub_key.go +++ b/pub_key.go @@ -148,8 +148,8 @@ func (pubKey PubKeySecp256k1) KeyString() string { } func (pubKey PubKeySecp256k1) Equals(other PubKey) bool { - if otherEd, ok := other.(PubKeySecp256k1); ok { - return bytes.Equal(pubKey[:], otherEd[:]) + if otherSecp, ok := other.(PubKeySecp256k1); ok { + return bytes.Equal(pubKey[:], otherSecp[:]) } else { return false }