PrivKey.Equals

This commit is contained in:
Jae Kwon
2016-04-19 01:26:40 -07:00
parent 8b34fd2e51
commit d57d5ff3c9
2 changed files with 21 additions and 2 deletions

View File

@@ -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{*****}")
}

View File

@@ -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
}