You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.2 KiB

  1. package account
  2. import (
  3. "errors"
  4. "io"
  5. "reflect"
  6. "github.com/tendermint/go-ed25519"
  7. . "github.com/tendermint/tendermint/binary"
  8. . "github.com/tendermint/tendermint/common"
  9. )
  10. // Signature is a part of Txs and consensus Votes.
  11. type Signature interface {
  12. }
  13. // Types of Signature implementations
  14. const (
  15. SignatureTypeEd25519 = byte(0x01)
  16. )
  17. //-------------------------------------
  18. // for binary.readReflect
  19. func SignatureDecoder(r io.Reader, n *int64, err *error) interface{} {
  20. switch t := ReadByte(r, n, err); t {
  21. case SignatureTypeEd25519:
  22. return ReadBinary(&SignatureEd25519{}, r, n, err)
  23. default:
  24. *err = Errorf("Unknown Signature type %X", t)
  25. return nil
  26. }
  27. }
  28. var _ = RegisterType(&TypeInfo{
  29. Type: reflect.TypeOf((*Signature)(nil)).Elem(),
  30. Decoder: SignatureDecoder,
  31. })
  32. //-------------------------------------
  33. // Implements Signature
  34. type SignatureEd25519 struct {
  35. Bytes []byte
  36. }
  37. func (sig SignatureEd25519) TypeByte() byte { return SignatureTypeEd25519 }
  38. func (sig SignatureEd25519) ValidateBasic() error {
  39. if len(sig.Bytes) != ed25519.SignatureSize {
  40. return errors.New("Invalid SignatureEd25519 signature size")
  41. }
  42. return nil
  43. }
  44. func (sig SignatureEd25519) IsZero() bool {
  45. return len(sig.Bytes) == 0
  46. }