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.

55 lines
1.4 KiB

7 years ago
  1. package keys
  2. import (
  3. crypto "github.com/tendermint/go-crypto"
  4. )
  5. // Keybase allows simple CRUD on a keystore, as an aid to signing
  6. type Keybase interface {
  7. // Sign some bytes
  8. Sign(name, passphrase string, msg []byte) (crypto.Signature, crypto.PubKey, error)
  9. // Create a new keypair
  10. Create(name, passphrase string, algo CryptoAlgo) (info Info, seed string, err error)
  11. // Recover takes a seedphrase and loads in the key
  12. Recover(name, passphrase, seedphrase string) (info Info, erro error)
  13. List() ([]Info, error)
  14. Get(name string) (Info, error)
  15. Update(name, oldpass, newpass string) error
  16. Delete(name, passphrase string) error
  17. Import(name string, armor string) (err error)
  18. Export(name string) (armor string, err error)
  19. }
  20. // Info is the public information about a key
  21. type Info struct {
  22. Name string `json:"name"`
  23. PubKey crypto.PubKey `json:"pubkey"`
  24. PrivKeyArmor string `json:"privkey.armor"`
  25. }
  26. func newInfo(name string, pub crypto.PubKey, privArmor string) Info {
  27. return Info{
  28. Name: name,
  29. PubKey: pub,
  30. PrivKeyArmor: privArmor,
  31. }
  32. }
  33. // Address is a helper function to calculate the address from the pubkey
  34. func (i Info) Address() []byte {
  35. return i.PubKey.Address()
  36. }
  37. func (i Info) bytes() []byte {
  38. bz, err := cdc.MarshalBinaryBare(i)
  39. if err != nil {
  40. panic(err)
  41. }
  42. return bz
  43. }
  44. func readInfo(bz []byte) (info Info, err error) {
  45. err = cdc.UnmarshalBinaryBare(bz, &info)
  46. return
  47. }