mirror of
https://github.com/tendermint/tendermint.git
synced 2026-06-01 11:56:21 +00:00
PrivKey.Equals
This commit is contained in:
19
priv_key.go
19
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{*****}")
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user