Browse Source

PrivKey.Equals

pull/1782/head
Jae Kwon 9 years ago
parent
commit
d57d5ff3c9
2 changed files with 21 additions and 2 deletions
  1. +19
    -0
      priv_key.go
  2. +2
    -2
      pub_key.go

+ 19
- 0
priv_key.go 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{*****}")
}


+ 2
- 2
pub_key.go 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
}


Loading…
Cancel
Save