Documentation ¶
Index ¶
- Variables
- func ArmorInfoBytes(bz []byte) string
- func ArmorPubKeyBytes(bz []byte) string
- func EncryptArmorPrivKey(privKey crypto.PrivKey, passphrase string) string
- func RegisterCodec(cdc *go_amino.Codec)
- func UnarmorDecryptPrivKey(armorStr string, passphrase string) (crypto.PrivKey, error)
- func UnarmorInfoBytes(armorStr string) (bz []byte, err error)
- func UnarmorPubKeyBytes(armorStr string) (bz []byte, err error)
- type Info
- type KeyType
- type Keybase
- func (kb Keybase) CloseDB()
- func (kb Keybase) CreateEnMnemonic(name, passwd string) (info Info, mnemonic string, err error)
- func (kb Keybase) CreateImportInfo(name, passwd string, priv crypto.PrivKey) (Info, error)
- func (kb Keybase) CreateOffline(name string, pub crypto.PubKey) (Info, error)
- func (kb Keybase) Delete(name, passphrase string) error
- func (kb Keybase) Derive(name, mnemonic, passwd, hdPath string) (info Info, err error)
- func (kb Keybase) Export(name string) (armor string, err error)
- func (kb Keybase) ExportPrivateKeyObject(name string, passphrase string) (crypto.PrivKey, error)
- func (kb Keybase) ExportPubKey(name string) (armor string, err error)
- func (kb Keybase) Get(name string) (Info, error)
- func (kb Keybase) GetByAddress(address types.Address) (Info, error)
- func (kb Keybase) Import(name string, armor string) (err error)
- func (kb Keybase) ImportPubKey(name string, armor string) (err error)
- func (kb Keybase) IsNil() bool
- func (kb Keybase) List() ([]Info, error)
- func (kb Keybase) Sign(name, passphrase string, msg []byte) (sig []byte, pub crypto.PubKey, err error)
- func (kb Keybase) Update(name, oldpass string, getNewpass func() (string, error)) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var BcryptSecurityParameter = 12
Functions ¶
func EncryptArmorPrivKey ¶
Encrypt and armor the private key.
func RegisterCodec ¶
func UnarmorDecryptPrivKey ¶
Unarmor and decrypt the private key.
func UnarmorInfoBytes ¶
Unarmor the InfoBytes
func UnarmorPubKeyBytes ¶
Unarmor the PubKeyBytes
Types ¶
type Info ¶
type Info interface { // Human-readable type for key listing GetType() KeyType // Name of the key GetName() string // Public key GetPubKey() crypto.PubKey // Address GetAddress() types.Address }
Info is the publicly exposed information about a keypair
type KeyType ¶
type KeyType uint
KeyType reflects a human-readable type for key listing.
type Keybase ¶
type Keybase struct {
// contains filtered or unexported fields
}
func New ¶
New creates a new Keybase instance using the passed DB for reading and writing keys.
Example ¶
// Select the encryption and storage for your cryptostore db := dbm.NewMemDB() cstore := New(db, MakeCodec()) // Add keys and see they return in alphabetical order bob, _, err := cstore.CreateEnMnemonic("Bob", "friend") if err != nil { // this should never happen fmt.Println(err) } else { // return info here just like in List fmt.Println(bob.GetName()) } cstore.CreateEnMnemonic("Alice", "secret") cstore.CreateEnMnemonic("Carl", "mitm") info, _ := cstore.List() for _, i := range info { fmt.Println(i.GetName()) } // We need to use passphrase to generate a signature tx := []byte("deadbeef") sig, pub, err := cstore.Sign("Bob", "friend", tx) if err != nil { fmt.Println("don't accept real passphrase") } // and we can validate the signature with publicly available info binfo, _ := cstore.Get("Bob") if !binfo.GetPubKey().Equals(bob.GetPubKey()) { fmt.Println("Get and Create return different keys") } if pub.Equals(binfo.GetPubKey()) { fmt.Println("signed by Bob") } if !pub.VerifyBytes(tx, sig) { fmt.Println("invalid signature") }
Output: Bob Alice Bob Carl signed by Bob
func (Keybase) CloseDB ¶
func (kb Keybase) CloseDB()
CloseDB releases the lock and closes the storage backend.
func (Keybase) CreateEnMnemonic ¶
func (Keybase) CreateImportInfo ¶
func (Keybase) CreateOffline ¶
CreateOffline creates a new reference to an offline keypair It returns the created key info
func (Keybase) Delete ¶
Delete removes key forever, but we must present the proper passphrase before deleting it (for security). A passphrase of 'yes' is used to delete stored references to offline and Ledger / HW wallet keys
func (Keybase) ExportPrivateKeyObject ¶
func (Keybase) ExportPubKey ¶
ExportPubKey returns public keys in ASCII armored format. Retrieve a Info object by its name and return the public key in a portable format.
func (Keybase) ImportPubKey ¶
ImportPubKey imports ASCII-armored public keys. Store a new Info object holding a public key only, i.e. it will not be possible to sign with it as it lacks the secret key.
func (Keybase) Sign ¶
func (kb Keybase) Sign(name, passphrase string, msg []byte) (sig []byte, pub crypto.PubKey, err error)
Sign signs the msg with the named key. It returns an error if the key doesn't exist or the decryption fails.