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.

52 lines
1.4 KiB

  1. package crypto
  2. import (
  3. "github.com/tendermint/tendermint/crypto/tmhash"
  4. "github.com/tendermint/tendermint/libs/bytes"
  5. )
  6. const (
  7. // AddressSize is the size of a pubkey address.
  8. AddressSize = tmhash.TruncatedSize
  9. )
  10. // An address is a []byte, but hex-encoded even in JSON.
  11. // []byte leaves us the option to change the address length.
  12. // Use an alias so Unmarshal methods (with ptr receivers) are available too.
  13. type Address = bytes.HexBytes
  14. func AddressHash(bz []byte) Address {
  15. return Address(tmhash.SumTruncated(bz))
  16. }
  17. type PubKey interface {
  18. Address() Address
  19. Bytes() []byte
  20. VerifySignature(msg []byte, sig []byte) bool
  21. Equals(PubKey) bool
  22. Type() string
  23. }
  24. type PrivKey interface {
  25. Bytes() []byte
  26. Sign(msg []byte) ([]byte, error)
  27. PubKey() PubKey
  28. Equals(PrivKey) bool
  29. Type() string
  30. }
  31. type Symmetric interface {
  32. Keygen() []byte
  33. Encrypt(plaintext []byte, secret []byte) (ciphertext []byte)
  34. Decrypt(ciphertext []byte, secret []byte) (plaintext []byte, err error)
  35. }
  36. // If a new key type implements batch verification,
  37. // the key type must be registered in github.com/tendermint/tendermint/crypto/batch
  38. type BatchVerifier interface {
  39. // Add appends an entry into the BatchVerifier.
  40. Add(key PubKey, message, signature []byte) error
  41. // Verify verifies all the entries in the BatchVerifier.
  42. // If the verification fails it is unknown which entry failed and each entry will need to be verified individually.
  43. Verify() bool
  44. }