keys

package
v0.2.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 26, 2019 License: Apache-2.0 Imports: 19 Imported by: 2

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var BcryptSecurityParameter = 12

Functions

func ArmorInfoBytes

func ArmorInfoBytes(bz []byte) string

Armor the InfoBytes

func ArmorPubKeyBytes

func ArmorPubKeyBytes(bz []byte) string

Armor the PubKeyBytes

func EncryptArmorPrivKey

func EncryptArmorPrivKey(privKey crypto.PrivKey, passphrase string) string

Encrypt and armor the private key.

func RegisterCodec

func RegisterCodec(cdc *go_amino.Codec)

func UnarmorDecryptPrivKey

func UnarmorDecryptPrivKey(armorStr string, passphrase string) (crypto.PrivKey, error)

Unarmor and decrypt the private key.

func UnarmorInfoBytes

func UnarmorInfoBytes(armorStr string) (bz []byte, err error)

Unarmor the InfoBytes

func UnarmorPubKeyBytes

func UnarmorPubKeyBytes(armorStr string) (bz []byte, err error)

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.

const (
	TypeLocal   KeyType = 0 //从命令行生成或从助记符中恢复
	TypeOffline KeyType = 1
	TypeImport  KeyType = 2 //以私钥的方式导入

)

Info KeyTypes

func (KeyType) String

func (kt KeyType) String() string

String implements the stringer interface for KeyType.

type Keybase

type Keybase struct {
	// contains filtered or unexported fields
}

func New

func New(db dbm.DB, cdc *go_amino.Codec) Keybase

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 (kb Keybase) CreateEnMnemonic(name, passwd string) (info Info, mnemonic string, err error)

func (Keybase) CreateImportInfo

func (kb Keybase) CreateImportInfo(name, passwd string, priv crypto.PrivKey) (Info, error)

func (Keybase) CreateOffline

func (kb Keybase) CreateOffline(name string, pub crypto.PubKey) (Info, error)

CreateOffline creates a new reference to an offline keypair It returns the created key info

func (Keybase) Delete

func (kb Keybase) Delete(name, passphrase string) error

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) Derive

func (kb Keybase) Derive(name, mnemonic, passwd, hdPath string) (info Info, err error)

func (Keybase) Export

func (kb Keybase) Export(name string) (armor string, err error)

func (Keybase) ExportPrivateKeyObject

func (kb Keybase) ExportPrivateKeyObject(name string, passphrase string) (crypto.PrivKey, error)

func (Keybase) ExportPubKey

func (kb Keybase) ExportPubKey(name string) (armor string, err error)

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) Get

func (kb Keybase) Get(name string) (Info, error)

Get returns the public information about one key.

func (Keybase) GetByAddress

func (kb Keybase) GetByAddress(address types.Address) (Info, error)

func (Keybase) Import

func (kb Keybase) Import(name string, armor string) (err error)

func (Keybase) ImportPubKey

func (kb Keybase) ImportPubKey(name string, armor string) (err error)

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) IsNil

func (kb Keybase) IsNil() bool

func (Keybase) List

func (kb Keybase) List() ([]Info, error)

List returns the keys from storage in alphabetical order.

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.

func (Keybase) Update

func (kb Keybase) Update(name, oldpass string, getNewpass func() (string, error)) error

Update changes the passphrase with which an already stored key is encrypted.

oldpass must be the current passphrase used for encryption, getNewpass is a function to get the passphrase to permanently replace the current passphrase

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL