Documentation ¶
Index ¶
Examples ¶
Constants ¶
View Source
const ( AlgoEd25519 = SignAlgo("ed25519") AlgoSecp256k1 = SignAlgo("secp256k1") )
Variables ¶
This section is empty.
Functions ¶
func New ¶ added in v0.5.0
Example ¶
package main import ( "fmt" dbm "github.com/tendermint/tmlibs/db" "github.com/tendermint/go-crypto/keys" "github.com/tendermint/go-crypto/keys/words" ) func main() { // Select the encryption and storage for your cryptostore cstore := keys.New( dbm.NewMemDB(), words.MustLoadCodec("english"), ) ed := keys.AlgoEd25519 sec := keys.AlgoSecp256k1 // Add keys and see they return in alphabetical order bob, _, err := cstore.CreateMnemonic("Bob", "friend", ed) if err != nil { // this should never happen fmt.Println(err) } else { // return info here just like in List fmt.Println(bob.GetName()) } cstore.CreateMnemonic("Alice", "secret", sec) cstore.CreateMnemonic("Carl", "mitm", ed) 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 publically 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
Types ¶
type Info ¶
type Info interface { // Human-readable type for key listing GetType() string // Name of the key GetName() string // Public key GetPubKey() crypto.PubKey }
Publically exposed information about a keypair
type Keybase ¶ added in v0.5.0
type Keybase interface { // CRUD on the keystore List() ([]Info, error) Get(name string) (Info, error) Delete(name, passphrase string) error // Sign some bytes, looking up the private key to use Sign(name, passphrase string, msg []byte) (crypto.Signature, crypto.PubKey, error) // Create a new locally-stored keypair, returning the mnemonic CreateMnemonic(name, passphrase string, algo SignAlgo) (info Info, seed string, err error) // Recover takes a seedphrase and loads in the key Recover(name, passphrase, seedphrase string) (info Info, erro error) // Create, store, and return a new Ledger key reference CreateLedger(name string, path crypto.DerivationPath, algo SignAlgo) (info Info, err error) // Create, store, and return a new offline key reference CreateOffline(name string, pubkey crypto.PubKey) (info Info, err error) // The following operations will *only* work on locally-stored keys Update(name, oldpass, newpass string) error Import(name string, armor string) (err error) ImportPubKey(name string, armor string) (err error) Export(name string) (armor string, err error) ExportPubKey(name string) (armor string, err error) }
Keybase exposes operations on a generic keystore
Click to show internal directories.
Click to hide internal directories.