7 "github.com/tendermint/go-wire"
8 data "github.com/tendermint/go-wire/data"
9 . "github.com/tendermint/tmlibs/common"
12 func SignatureFromBytes(sigBytes []byte) (sig Signature, err error) {
13 err = wire.ReadBinaryBytes(sigBytes, &sig)
17 //----------------------------------------
19 // DO NOT USE THIS INTERFACE.
20 // You probably want to use Signature.
21 // +gen wrapper:"Signature,Impl[SignatureEd25519,SignatureSecp256k1],ed25519,secp256k1"
22 type SignatureInner interface {
23 AssertIsSignatureInner()
26 Equals(Signature) bool
30 //-------------------------------------
32 var _ SignatureInner = SignatureEd25519{}
34 // Implements Signature
35 type SignatureEd25519 [64]byte
37 func (sig SignatureEd25519) AssertIsSignatureInner() {}
39 func (sig SignatureEd25519) Bytes() []byte {
40 return wire.BinaryBytes(Signature{sig})
43 func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
45 func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
47 func (sig SignatureEd25519) Equals(other Signature) bool {
48 if otherEd, ok := other.Unwrap().(SignatureEd25519); ok {
49 return bytes.Equal(sig[:], otherEd[:])
55 func (sig SignatureEd25519) MarshalJSON() ([]byte, error) {
56 return data.Encoder.Marshal(sig[:])
59 func (sig *SignatureEd25519) UnmarshalJSON(enc []byte) error {
61 err := data.Encoder.Unmarshal(&ref, enc)
66 func SignatureEd25519FromBytes(data []byte) Signature {
67 var sig SignatureEd25519
72 //-------------------------------------
74 var _ SignatureInner = SignatureSecp256k1{}
76 // Implements Signature
77 type SignatureSecp256k1 []byte
79 func (sig SignatureSecp256k1) AssertIsSignatureInner() {}
81 func (sig SignatureSecp256k1) Bytes() []byte {
82 return wire.BinaryBytes(Signature{sig})
85 func (sig SignatureSecp256k1) IsZero() bool { return len(sig) == 0 }
87 func (sig SignatureSecp256k1) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
89 func (sig SignatureSecp256k1) Equals(other Signature) bool {
90 if otherEd, ok := other.Unwrap().(SignatureSecp256k1); ok {
91 return bytes.Equal(sig[:], otherEd[:])
97 func (sig SignatureSecp256k1) MarshalJSON() ([]byte, error) {
98 return data.Encoder.Marshal(sig)
101 func (sig *SignatureSecp256k1) UnmarshalJSON(enc []byte) error {
102 return data.Encoder.Unmarshal((*[]byte)(sig), enc)