package crypto import ( "bytes" "github.com/tendermint/ed25519" data "github.com/tendermint/go-wire/data" . "github.com/tendermint/tmlibs/common" ) //---------------------------------------- // DO NOT USE THIS INTERFACE. // You probably want to use PubKey // +gen wrapper:"PubKey,Impl[PubKeyEd25519,PubKeySecp256k1],ed25519,secp256k1" type PubKeyInner interface { KeyString() string VerifyBytes(msg []byte, sig Signature) bool Equals(PubKey) bool Wrap() PubKey } //------------------------------------- var _ PubKeyInner = PubKeyEd25519{} // Implements PubKeyInner type PubKeyEd25519 [32]byte func (pubKey PubKeyEd25519) VerifyBytes(msg []byte, sig_ Signature) bool { // make sure we use the same algorithm to sign sig, ok := sig_.Unwrap().(SignatureEd25519) if !ok { return false } pubKeyBytes := [32]byte(pubKey) sigBytes := [64]byte(sig) return ed25519.Verify(&pubKeyBytes, msg, &sigBytes) } func (p PubKeyEd25519) MarshalJSON() ([]byte, error) { return data.Encoder.Marshal(p[:]) } func (p *PubKeyEd25519) UnmarshalJSON(enc []byte) error { var ref []byte err := data.Encoder.Unmarshal(&ref, enc) copy(p[:], ref) return err } func (pubKey PubKeyEd25519) String() string { return Fmt("PubKeyEd25519{%X}", pubKey[:]) } // Must return the full bytes in hex. // Used for map keying, etc. func (pubKey PubKeyEd25519) KeyString() string { return Fmt("%X", pubKey[:]) } func (pubKey PubKeyEd25519) Equals(other PubKey) bool { if otherEd, ok := other.Unwrap().(PubKeyEd25519); ok { return bytes.Equal(pubKey[:], otherEd[:]) } else { return false } }