accounts

package
v1.5.8-0...-fc52f2c Latest Latest
Warning

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

Go to latest
Published: Jan 23, 2017 License: GPL-3.0 Imports: 30 Imported by: 0

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

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
)

Variables

View Source
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")
)

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.

Types

type Account

type Account struct {
	Address common.Address // Ethereum account address derived from the key

	// 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

func (acc *Account) MarshalJSON() ([]byte, error)

func (*Account) UnmarshalJSON

func (acc *Account) UnmarshalJSON(raw []byte) error

type AmbiguousAddrError

type AmbiguousAddrError struct {
	Addr    common.Address
	Matches []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 common.Address
	// we only store privkey as pubkey/address can be derived from it
	// privkey in this struct is always in plaintext
	PrivateKey *ecdsa.PrivateKey
}

func DecryptKey

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

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

func NewKeyForDirectICAP

func NewKeyForDirectICAP(rand io.Reader) *Key

NewKeyForDirectICAP generates a key whose address fits into < 155 bits so it can fit into the Direct ICAP spec. for simplicity and easier compatibility with other libs, we retry until the first byte is 0.

func (*Key) MarshalJSON

func (k *Key) MarshalJSON() (j []byte, err error)

func (*Key) UnmarshalJSON

func (k *Key) UnmarshalJSON(j []byte) (err error)

type Manager

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

Manager manages a key storage directory on disk.

func NewManager

func NewManager(keydir string, scryptN, scryptP int) *Manager

NewManager creates a manager for the given directory.

func NewPlaintextManager

func NewPlaintextManager(keydir string) *Manager

NewPlaintextManager creates a manager for the given directory. Deprecated: Use NewManager.

func (*Manager) AccountByIndex

func (am *Manager) AccountByIndex(i int) (Account, error)

AccountByIndex returns the ith account.

func (*Manager) Accounts

func (am *Manager) Accounts() []Account

Accounts returns all key files present in the directory.

func (*Manager) Delete

func (am *Manager) Delete(a 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 (*Manager) Export

func (am *Manager) Export(a Account, passphrase, newPassphrase string) (keyJSON []byte, err error)

Export exports as a JSON key, encrypted with newPassphrase.

func (*Manager) Find

func (am *Manager) Find(a Account) (Account, error)

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

func (*Manager) HasAddress

func (am *Manager) HasAddress(addr common.Address) bool

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

func (*Manager) Import

func (am *Manager) Import(keyJSON []byte, passphrase, newPassphrase string) (Account, error)

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

func (*Manager) ImportECDSA

func (am *Manager) ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (Account, error)

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

func (*Manager) ImportPreSaleKey

func (am *Manager) ImportPreSaleKey(keyJSON []byte, passphrase string) (Account, error)

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

func (am *Manager) Lock(addr common.Address) error

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

func (*Manager) NewAccount

func (am *Manager) NewAccount(passphrase string) (Account, error)

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

func (*Manager) Sign

func (am *Manager) Sign(addr common.Address, hash []byte) ([]byte, error)

Sign calculates a ECDSA signature for the given hash. The produced signature is in the [R || S || V] format where V is 0 or 1.

func (*Manager) SignWithPassphrase

func (am *Manager) SignWithPassphrase(a Account, 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. The produced signature is in the [R || S || V] format where V is 0 or 1.

func (*Manager) TimedUnlock

func (am *Manager) TimedUnlock(a 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 (*Manager) Unlock

func (am *Manager) Unlock(a Account, passphrase string) error

Unlock unlocks the given account indefinitely.

func (*Manager) Update

func (am *Manager) Update(a Account, passphrase, newPassphrase string) error

Update changes the passphrase of an existing account.

Directories

Path Synopsis
abi
Package abi implements the Ethereum ABI (Application Binary Interface).
Package abi implements the Ethereum ABI (Application Binary Interface).
bind
Package bind generates Ethereum contract Go bindings.
Package bind generates Ethereum contract Go bindings.

Jump to

Keyboard shortcuts

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