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.

70 lines
2.0 KiB

  1. package keys
  2. import (
  3. "sort"
  4. crypto "github.com/tendermint/go-crypto"
  5. data "github.com/tendermint/go-wire/data"
  6. )
  7. // Info is the public information about a key
  8. type Info struct {
  9. Name string `json:"name"`
  10. Address data.Bytes `json:"address"`
  11. PubKey crypto.PubKey `json:"pubkey"`
  12. }
  13. func (i *Info) Format() Info {
  14. if !i.PubKey.Empty() {
  15. i.Address = i.PubKey.Address()
  16. }
  17. return *i
  18. }
  19. // Infos is a wrapper to allows alphabetical sorting of the keys
  20. type Infos []Info
  21. func (k Infos) Len() int { return len(k) }
  22. func (k Infos) Less(i, j int) bool { return k[i].Name < k[j].Name }
  23. func (k Infos) Swap(i, j int) { k[i], k[j] = k[j], k[i] }
  24. func (k Infos) Sort() {
  25. if k != nil {
  26. sort.Sort(k)
  27. }
  28. }
  29. // Signable represents any transaction we wish to send to tendermint core
  30. // These methods allow us to sign arbitrary Tx with the KeyStore
  31. type Signable interface {
  32. // SignBytes is the immutable data, which needs to be signed
  33. SignBytes() []byte
  34. // Sign will add a signature and pubkey.
  35. //
  36. // Depending on the Signable, one may be able to call this multiple times for multisig
  37. // Returns error if called with invalid data or too many times
  38. Sign(pubkey crypto.PubKey, sig crypto.Signature) error
  39. // Signers will return the public key(s) that signed if the signature
  40. // is valid, or an error if there is any issue with the signature,
  41. // including if there are no signatures
  42. Signers() ([]crypto.PubKey, error)
  43. // TxBytes returns the transaction data as well as all signatures
  44. // It should return an error if Sign was never called
  45. TxBytes() ([]byte, error)
  46. }
  47. // Signer allows one to use a keystore to sign transactions
  48. type Signer interface {
  49. Sign(name, passphrase string, tx Signable) error
  50. }
  51. // Manager allows simple CRUD on a keystore, as an aid to signing
  52. type Manager interface {
  53. Create(name, passphrase, algo string) (Info, error)
  54. List() (Infos, error)
  55. Get(name string) (Info, error)
  56. Update(name, oldpass, newpass string) error
  57. Delete(name, passphrase string) error
  58. }