mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-24 02:01:43 +00:00
Use new go-wire; PubKey etc are interfaces; Keybase refactor
This commit is contained in:
58
signature.go
58
signature.go
@ -4,40 +4,35 @@ import (
|
||||
"bytes"
|
||||
"fmt"
|
||||
|
||||
"github.com/tendermint/go-wire"
|
||||
data "github.com/tendermint/go-wire/data"
|
||||
. "github.com/tendermint/tmlibs/common"
|
||||
)
|
||||
|
||||
func SignatureFromBytes(sigBytes []byte) (sig Signature, err error) {
|
||||
err = wire.ReadBinaryBytes(sigBytes, &sig)
|
||||
func SignatureFromBytes(pubKeyBytes []byte) (pubKey Signature, err error) {
|
||||
err = cdc.UnmarshalBinary(pubKeyBytes, &pubKey)
|
||||
return
|
||||
}
|
||||
|
||||
//----------------------------------------
|
||||
|
||||
// DO NOT USE THIS INTERFACE.
|
||||
// You probably want to use Signature.
|
||||
// +gen wrapper:"Signature,Impl[SignatureEd25519,SignatureSecp256k1],ed25519,secp256k1"
|
||||
type SignatureInner interface {
|
||||
AssertIsSignatureInner()
|
||||
type Signature interface {
|
||||
Bytes() []byte
|
||||
IsZero() bool
|
||||
Equals(Signature) bool
|
||||
Wrap() Signature
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
var _ SignatureInner = SignatureEd25519{}
|
||||
var _ Signature = SignatureEd25519{}
|
||||
|
||||
// Implements Signature
|
||||
type SignatureEd25519 [64]byte
|
||||
|
||||
func (sig SignatureEd25519) AssertIsSignatureInner() {}
|
||||
|
||||
func (sig SignatureEd25519) Bytes() []byte {
|
||||
return wire.BinaryBytes(Signature{sig})
|
||||
bz, err := cdc.MarshalBinary(sig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return bz
|
||||
}
|
||||
|
||||
func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
|
||||
@ -45,41 +40,32 @@ func (sig SignatureEd25519) IsZero() bool { return len(sig) == 0 }
|
||||
func (sig SignatureEd25519) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
|
||||
|
||||
func (sig SignatureEd25519) Equals(other Signature) bool {
|
||||
if otherEd, ok := other.Unwrap().(SignatureEd25519); ok {
|
||||
if otherEd, ok := other.(SignatureEd25519); ok {
|
||||
return bytes.Equal(sig[:], otherEd[:])
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (sig SignatureEd25519) MarshalJSON() ([]byte, error) {
|
||||
return data.Encoder.Marshal(sig[:])
|
||||
}
|
||||
|
||||
func (sig *SignatureEd25519) UnmarshalJSON(enc []byte) error {
|
||||
var ref []byte
|
||||
err := data.Encoder.Unmarshal(&ref, enc)
|
||||
copy(sig[:], ref)
|
||||
return err
|
||||
}
|
||||
|
||||
func SignatureEd25519FromBytes(data []byte) Signature {
|
||||
var sig SignatureEd25519
|
||||
copy(sig[:], data)
|
||||
return sig.Wrap()
|
||||
return sig
|
||||
}
|
||||
|
||||
//-------------------------------------
|
||||
|
||||
var _ SignatureInner = SignatureSecp256k1{}
|
||||
var _ Signature = SignatureSecp256k1{}
|
||||
|
||||
// Implements Signature
|
||||
type SignatureSecp256k1 []byte
|
||||
|
||||
func (sig SignatureSecp256k1) AssertIsSignatureInner() {}
|
||||
|
||||
func (sig SignatureSecp256k1) Bytes() []byte {
|
||||
return wire.BinaryBytes(Signature{sig})
|
||||
bz, err := cdc.MarshalBinary(sig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return bz
|
||||
}
|
||||
|
||||
func (sig SignatureSecp256k1) IsZero() bool { return len(sig) == 0 }
|
||||
@ -87,17 +73,9 @@ func (sig SignatureSecp256k1) IsZero() bool { return len(sig) == 0 }
|
||||
func (sig SignatureSecp256k1) String() string { return fmt.Sprintf("/%X.../", Fingerprint(sig[:])) }
|
||||
|
||||
func (sig SignatureSecp256k1) Equals(other Signature) bool {
|
||||
if otherSecp, ok := other.Unwrap().(SignatureSecp256k1); ok {
|
||||
if otherSecp, ok := other.(SignatureSecp256k1); ok {
|
||||
return bytes.Equal(sig[:], otherSecp[:])
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func (sig SignatureSecp256k1) MarshalJSON() ([]byte, error) {
|
||||
return data.Encoder.Marshal(sig)
|
||||
}
|
||||
|
||||
func (sig *SignatureSecp256k1) UnmarshalJSON(enc []byte) error {
|
||||
return data.Encoder.Unmarshal((*[]byte)(sig), enc)
|
||||
}
|
||||
|
Reference in New Issue
Block a user