6 "github.com/tendermint/ed25519"
7 data "github.com/tendermint/go-wire/data"
8 . "github.com/tendermint/tmlibs/common"
11 //----------------------------------------
13 // DO NOT USE THIS INTERFACE.
14 // You probably want to use PubKey
15 // +gen wrapper:"PubKey,Impl[PubKeyEd25519,PubKeySecp256k1],ed25519,secp256k1"
16 type PubKeyInner interface {
18 VerifyBytes(msg []byte, sig Signature) bool
23 //-------------------------------------
25 var _ PubKeyInner = PubKeyEd25519{}
27 // Implements PubKeyInner
28 type PubKeyEd25519 [32]byte
30 func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool {
31 // make sure we use the same algorithm to sign
32 sig, ok := sig_.Unwrap().(SignatureEd25519)
36 pubKeyBytes := [32]byte(pubKey)
37 sigBytes := [64]byte(sig)
38 return ed25519.Verify(&pubKeyBytes, msg, &sigBytes)
41 func (p PubKeyEd25519) MarshalJSON() ([]byte, error) {
42 return data.Encoder.Marshal(p[:])
45 func (p *PubKeyEd25519) UnmarshalJSON(enc []byte) error {
47 err := data.Encoder.Unmarshal(&ref, enc)
52 func (pubKey PubKeyEd25519) String() string {
53 return Fmt("PubKeyEd25519{%X}", pubKey[:])
56 // Must return the full bytes in hex.
57 // Used for map keying, etc.
58 func (pubKey PubKeyEd25519) KeyString() string {
59 return Fmt("%X", pubKey[:])
62 func (pubKey PubKeyEd25519) Equals(other PubKey) bool {
63 if otherEd, ok := other.Unwrap().(PubKeyEd25519); ok {
64 return bytes.Equal(pubKey[:], otherEd[:])