keystore

package
v0.0.0-...-59892fd Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2022 License: GPL-3.0 Imports: 42 Imported by: 0

Documentation

Overview

Package keystore implements encrypted storage of secp256k1 private keys.

Keys are stored as encrypted JSON files according to the Web3 Secret Storage specification. See https://github.com/ethereum/wiki/wiki/Web3-Secret-Storage-Definition for more information.

Index

Constants

View Source
const (

	// StandardScryptN is the N parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptN = 1 << 18

	// StandardScryptP is the P parameter of Scrypt encryption algorithm, using 256MB
	// memory and taking approximately 1s CPU time on a modern processor.
	StandardScryptP = 1

	// LightScryptN is the N parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptN = 1 << 12

	// LightScryptP is the P parameter of Scrypt encryption algorithm, using 4MB
	// memory and taking approximately 100ms CPU time on a modern processor.
	LightScryptP = 6
)
View Source
const KeyStoreScheme = "keystore"

KeyStoreScheme is the protocol scheme prefixing account and wallet URLs.

Variables

View Source
var (
	ErrLocked      = accounts.NewAuthNeededError("password or unlock")
	ErrNoMatch     = errors.New("no key for given address or file")
	ErrDecrypt     = errors.New("could not decrypt key with given passphrase")
	ErrNoStoreType = errors.New("could not support kestore type")
)
View Source
var KeyStoreType = reflect.TypeOf(&KeyStore{})

KeyStoreType is the reflect type of a keystore backend.

Functions

func EncryptKey

func EncryptKey(key *Key, auth string, scryptN, scryptP int) ([]byte, error)

EncryptKey encrypts a key using the specified scrypt parameters into a json blob that can be decrypted later on.

func GetAddress

func GetAddress(keyjson []byte) (string, error)

func StoreKey

func StoreKey(dir, auth string, scryptN, scryptP int, at uint64) (accounts.Account, error)

StoreKey generates a key, encrypts with 'auth' and stores in the given directory

Types

type AmbiguousAddrError

type AmbiguousAddrError struct {
	Address address.PKAddress
	Matches []accounts.Account
}

AmbiguousAddrError is returned when attempting to unlock an address for which more than one file exists.

func (*AmbiguousAddrError) Error

func (err *AmbiguousAddrError) Error() string

type Key

type Key struct {
	Id uuid.UUID // Version 4 "random" for unique id not derived from key data
	// to simplify lookups we also store the address
	Address address.PKAddress

	Tk address.TKAddress
	// we only store privkey as pubkey/address can be derived from it
	// privkey in this struct is always in plaintext
	PrivateKey *ecdsa.PrivateKey

	At uint64

	Version int
}

func DecryptKey

func DecryptKey(keyjson []byte, auth string) (*Key, error)

DecryptKey decrypts a key from a json blob, returning the private key itself.

type KeyStore

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

KeyStore manages a key storage directory on disk.

func NewKeyStore

func NewKeyStore(keydir string, scryptN, scryptP int) *KeyStore

NewKeyStore creates a keystore for the given directory.

func (*KeyStore) Accounts

func (ks *KeyStore) Accounts() []accounts.Account

Accounts returns all key files present in the directory.

func (*KeyStore) Delete

func (ks *KeyStore) Delete(a accounts.Account, passphrase string) error

Delete deletes the key matched by account if the passphrase is correct. If the account contains no filename, the address must match a unique key.

func (*KeyStore) Export

func (ks *KeyStore) Export(a accounts.Account, passphrase, newPassphrase string) (keyJSON []byte, err error)

Export exports as a JSON key, encrypted with newPassphrase.

func (*KeyStore) ExportMnemonic

func (ks *KeyStore) ExportMnemonic(a accounts.Account, passphrase string) (string, error)

func (*KeyStore) ExportRewKey

func (ks *KeyStore) ExportRewKey(a accounts.Account, passphrase string) ([]byte, error)

func (*KeyStore) Find

func (ks *KeyStore) Find(a accounts.Account) (accounts.Account, error)

Find resolves the given account into a unique entry in the keystore.

func (*KeyStore) GetSeed

func (ks *KeyStore) GetSeed(a accounts.Account) (*address.Seed, error)

func (*KeyStore) GetSeedWithPassphrase

func (ks *KeyStore) GetSeedWithPassphrase(account accounts.Account, passphrase string) (*address.Seed, error)

func (*KeyStore) HasAddress

func (ks *KeyStore) HasAddress(address address.PKAddress) bool

HasAddress reports whether a key with the given address is present.

func (*KeyStore) Import

func (ks *KeyStore) Import(keyJSON []byte, passphrase, newPassphrase string) (accounts.Account, error)

Import stores the given encrypted JSON key into the key directory.

func (*KeyStore) ImportECDSA

func (ks *KeyStore) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string, at uint64, version int) (accounts.Account, error)

ImportECDSA stores the given key into the key directory, encrypting it with the passphrase.

func (*KeyStore) ImportTk

func (ks *KeyStore) ImportTk(tk c_type.Tk, at uint64) (accounts.Account, error)

func (*KeyStore) Lock

func (ks *KeyStore) Lock(address address.PKAddress) error

Lock removes the private key with the given address from memory.

func (*KeyStore) NewAccount

func (ks *KeyStore) NewAccount(passphrase string, at uint64, version int) (accounts.Account, error)

NewAccount generates a new key and stores it into the key directory, encrypting it with the passphrase.

func (*KeyStore) NewAccountWithMnemonic

func (ks *KeyStore) NewAccountWithMnemonic(passphrase string, at uint64, version int) (string, accounts.Account, error)

func (*KeyStore) Subscribe

func (ks *KeyStore) Subscribe(sink chan<- accounts.WalletEvent) event.Subscription

Subscribe implements accounts.Backend, creating an async subscription to receive notifications on the addition or removal of keystore wallets.

func (*KeyStore) TimedUnlock

func (ks *KeyStore) TimedUnlock(a accounts.Account, passphrase string, timeout time.Duration) error

TimedUnlock unlocks the given account with the passphrase. The account stays unlocked for the duration of timeout. A timeout of 0 unlocks the account until the program exits. The account must match a unique key file.

If the account address is already unlocked for a duration, TimedUnlock extends or shortens the active unlock timeout. If the address was previously unlocked indefinitely the timeout is not altered.

func (*KeyStore) Unlock

func (ks *KeyStore) Unlock(a accounts.Account, passphrase string) error

Unlock unlocks the given account indefinitely.

func (*KeyStore) Update

func (ks *KeyStore) Update(a accounts.Account, passphrase, newPassphrase string) error

Update changes the passphrase of an existing account.

func (*KeyStore) Wallets

func (ks *KeyStore) Wallets() []accounts.Wallet

Wallets implements accounts.Backend, returning all single-key wallets from the keystore directory.

Jump to

Keyboard shortcuts

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