Documentation ¶
Overview ¶
Package accounts 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
- Variables
- func Web3PrivateKey(web3JSON []byte, secret string) (*ecdsa.PrivateKey, error)
- type Account
- type AccountJSON
- type AmbiguousAddrError
- type Manager
- func (am *Manager) AccountByIndex(i int) (Account, error)
- func (am *Manager) Accounts() []Account
- func (am *Manager) BuildIndexDB() []error
- func (am *Manager) DeleteAccount(a Account, passphrase string) error
- func (am *Manager) Export(a Account, passphrase, newPassphrase string) (keyJSON []byte, err error)
- func (am *Manager) HasAddress(addr common.Address) bool
- func (am *Manager) Import(keyJSON []byte, passphrase, newPassphrase string) (Account, error)
- func (am *Manager) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (Account, error)
- func (am *Manager) ImportPreSaleKey(keyJSON []byte, passphrase string) (Account, error)
- func (am *Manager) Lock(addr common.Address) error
- func (am *Manager) NewAccount(passphrase string) (Account, error)
- func (am *Manager) Sign(addr common.Address, hash []byte) (signature []byte, err error)
- func (am *Manager) SignWithPassphrase(addr common.Address, passphrase string, hash []byte) (signature []byte, err error)
- func (am *Manager) TimedUnlock(a Account, passphrase string, timeout time.Duration) error
- func (am *Manager) Unlock(a Account, passphrase string) error
- func (am *Manager) Update(a Account, passphrase, newPassphrase string) error
- Bugs
Constants ¶
const ( // n,r,p = 2^18, 8, 1 uses 256MB memory and approx 1s CPU time on a modern CPU. StandardScryptN = 1 << 18 StandardScryptP = 1 // n,r,p = 2^12, 8, 6 uses 4MB memory and approx 100ms CPU time on a modern CPU. LightScryptN = 1 << 12 LightScryptP = 6 )
Variables ¶
var ( ErrLocked = errors.New("account is locked") ErrNoMatch = errors.New("no key for given address or file") ErrDecrypt = errors.New("could not decrypt key with given passphrase") )
var ErrCacheDBNoUpdateStamp = errors.New("cachedb has no updated timestamp; expected for newborn dbs.")
Functions ¶
func Web3PrivateKey ¶
func Web3PrivateKey(web3JSON []byte, secret string) (*ecdsa.PrivateKey, error)
Web3PrivateKey decrypts the record with secret and returns the private key.
Types ¶
type Account ¶
type Account struct { Address common.Address // Ethereum account address derived from the key EncryptedKey string // web3JSON format // File contains the key file name. // When Acccount is used as an argument to select a key, File can be left blank to // select just by address or set to the basename or absolute path of a file in the key // directory. Accounts returned by Manager will always contain an absolute path. File string }
Account represents a stored key. When used as an argument, it selects a unique key file to act on.
func (*Account) MarshalJSON ¶ added in v1.4.0
func (*Account) UnmarshalJSON ¶ added in v1.4.0
type AccountJSON ¶
type AccountJSON struct { Address string `json:"address"` EncryptedKey string `json:"key"` File string `json:"file"` }
AccountJSON is an auxiliary between Account and EasyMarshal'd structs.
func (AccountJSON) MarshalEasyJSON ¶
func (v AccountJSON) MarshalEasyJSON(w *jwriter.Writer)
MarshalEasyJSON supports easyjson.Marshaler interface
func (AccountJSON) MarshalJSON ¶
func (v AccountJSON) MarshalJSON() ([]byte, error)
MarshalJSON supports json.Marshaler interface
func (*AccountJSON) UnmarshalEasyJSON ¶
func (v *AccountJSON) UnmarshalEasyJSON(l *jlexer.Lexer)
UnmarshalEasyJSON supports easyjson.Unmarshaler interface
func (*AccountJSON) UnmarshalJSON ¶
func (v *AccountJSON) UnmarshalJSON(data []byte) error
UnmarshalJSON supports json.Unmarshaler interface
type AmbiguousAddrError ¶ added in v1.4.0
AmbiguousAddrError is returned when attempting to unlock an address for which more than one file exists.
func (*AmbiguousAddrError) Error ¶ added in v1.4.0
func (err *AmbiguousAddrError) Error() string
type Manager ¶ added in v0.9.17
type Manager struct {
// contains filtered or unexported fields
}
Manager manages a key storage directory on disk.
func NewManager ¶ added in v0.9.17
NewManager creates a manager for the given directory. keydir is by default /Users/ia/Library/EthereumClassic/mainnet/keystore
func (*Manager) AccountByIndex ¶ added in v1.4.0
AccountByIndex returns the ith account.
func (*Manager) Accounts ¶ added in v0.9.17
Accounts returns all key files present in the directory.
func (*Manager) BuildIndexDB ¶
func (*Manager) DeleteAccount ¶ added in v0.9.17
DeleteAccount deletes the key matched by account if the passphrase is correct. If a contains no filename, the address must match a unique key.
func (*Manager) Export ¶ added in v0.9.17
Export exports as a JSON key, encrypted with newPassphrase.
func (*Manager) HasAddress ¶ added in v1.4.0
HasAddress reports whether a key with the given address is present.
func (*Manager) Import ¶ added in v0.9.17
Import stores the given encrypted JSON key into the key directory.
func (*Manager) ImportECDSA ¶ added in v1.4.0
ImportECDSA stores the given key into the key directory, encrypting it with the passphrase.
func (*Manager) ImportPreSaleKey ¶ added in v0.9.17
ImportPreSaleKey decrypts the given Ethereum presale wallet and stores a key file in the key directory. The key file is encrypted with the same passphrase.
func (*Manager) Lock ¶ added in v1.4.0
Lock removes the private key with the given address from memory.
func (*Manager) NewAccount ¶ added in v0.9.17
NewAccount generates a new key and stores it into the key directory, encrypting it with the passphrase.
func (*Manager) Sign ¶ added in v0.9.17
Sign signs hash with an unlocked private key matching the given address.
func (*Manager) SignWithPassphrase ¶ added in v1.4.5
func (am *Manager) SignWithPassphrase(addr common.Address, passphrase string, hash []byte) (signature []byte, err error)
SignWithPassphrase signs hash if the private key matching the given address can be decrypted with the given passphrase.
func (*Manager) TimedUnlock ¶ added in v0.9.17
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.
Notes ¶
Bugs ¶
Windows won't allow updates to a keyfile when it is being read.