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.

57 lines
1.5 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. ImportPubKey(name string, armor string) (err error)
  19. Export(name string) (armor string, err error)
  20. ExportPubKey(name string) (armor string, err error)
  21. }
  22. // Info is the public information about a key
  23. type Info struct {
  24. Name string `json:"name"`
  25. PubKey crypto.PubKey `json:"pubkey"`
  26. PrivKeyArmor string `json:"privkey.armor"`
  27. }
  28. func newInfo(name string, pub crypto.PubKey, privArmor string) Info {
  29. return Info{
  30. Name: name,
  31. PubKey: pub,
  32. PrivKeyArmor: privArmor,
  33. }
  34. }
  35. // Address is a helper function to calculate the address from the pubkey
  36. func (i Info) Address() []byte {
  37. return i.PubKey.Address()
  38. }
  39. func (i Info) bytes() []byte {
  40. bz, err := cdc.MarshalBinaryBare(i)
  41. if err != nil {
  42. panic(err)
  43. }
  44. return bz
  45. }
  46. func readInfo(bz []byte) (info Info, err error) {
  47. err = cdc.UnmarshalBinaryBare(bz, &info)
  48. return
  49. }