accounts

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2021 License: LGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnknownAccount = errors.New("unknown account")
	ErrLocked         = errors.New("password or unlock")
	ErrNoMatch        = errors.New("no key for given address or file")
	ErrNotValKey      = errors.New("not a validator key")
)

Functions

This section is empty.

Types

type Account

type Account struct {
	Address common.Address `json:"address"`
	Path    string         `json:"path"`
}

type AccountManager

type AccountManager interface {
	Accounts() []*Account
	NewAccount(passphrase []byte) (*Account, error)
	Delete(address common.Address, passphrase string) error
	Update(account *Account, passphrase, newPassphrase string) error
	Contains(address common.Address) bool
	Find(address common.Address) (*Account, bool)

	Lock(address common.Address) error
	Unlock(account *Account, passphrase string) error
	TimedUnlock(account *Account, passphrase string, timeout time.Duration) error
	Status(account Account) (string, error)

	ImportECDSA(priv *ecdsa.PrivateKey, passphrase string) (*Account, error)
	ExportECDSA(a *Account, passphrase string) (string, error)
	Import(keyJSON []byte, passphrase, newPassphrase string) (*Account, error)
	Export(a *Account, passphrase, newPassphrase string) (keyJSON []byte, err error)

	SignHash(account Account, hash []byte) (signature []byte, err error)
	SignTx(account Account, tx *types.Transaction) (*types.Transaction, error)
	SignHashWithPassphrase(account Account, passphrase string, hash []byte) (signature []byte, err error)
	SignTxWithPassphrase(account Account, passphrase string, tx *types.Transaction) (*types.Transaction, error)
	SignTxWithKey(key string, tx *types.Transaction, networkId *big.Int) (*types.Transaction, error)

	//NewValKey generates a new validator key that includes an ecdsa key and a bls key.
	NewValKey(pwd string) (*ValAccount, error)
	//UseValKey will unlock and return the required validator key.
	//If keep is true, then will store that validator key with plaintext, BE CAUTIOUS!
	//Will only keep at most one validator key.
	UseValKey(addr common.Address, pwd string, keep bool) (*keystore.Key, error)
	//GetUnlockedValKey gets the unlocked validator key
	GetUnlockedValKey() *keystore.Key
	//ExportValKey is like as Export, just do more check about validator key
	ExportValKey(addr common.Address, pwd, newPwd string) (keyJSON []byte, err error)
	ImportValKey(keyJSON []byte, pwd, newPwd string) (*ValAccount, error)
	//DelValKey will both try removing all unlocked validator keys and delete the specific key.
	DelValKey(addr common.Address, pwd string) error
	//LockValKey will remove all unlocked validator keys
	LockValKey() error
}

type Manager

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

func NewManager

func NewManager(ks Storage, blockNumber *big.Int) (*Manager, error)

func (*Manager) Accounts

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

func (*Manager) Contains

func (manager *Manager) Contains(address common.Address) bool

func (*Manager) DelValKey

func (manager *Manager) DelValKey(addr common.Address, pwd string) error

DelValKey will both try removing all unlocked validator keys and delete the specific key.

func (*Manager) Delete

func (manager *Manager) Delete(address common.Address, 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 (manager *Manager) Export(a *Account, passphrase, newPassphrase string) (keyJSON []byte, err error)

Export exports as a JSON key, encrypted with newPassphrase.

func (*Manager) ExportECDSA

func (manager *Manager) ExportECDSA(a *Account, passphrase string) (string, error)

ExportECDSA export a private key

func (*Manager) ExportValKey

func (manager *Manager) ExportValKey(addr common.Address, pwd, newPwd string) (keyJSON []byte, err error)

func (*Manager) Find

func (manager *Manager) Find(address common.Address) (*Account, bool)

func (*Manager) GetUnlockedValKey

func (manager *Manager) GetUnlockedValKey() *keystore.Key

func (*Manager) Import

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

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

func (*Manager) ImportECDSA

func (manager *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) ImportValKey

func (manager *Manager) ImportValKey(keyJSON []byte, pwd, newPwd string) (*ValAccount, error)

func (*Manager) Lock

func (manager *Manager) Lock(address common.Address) error

func (*Manager) LockValKey

func (manager *Manager) LockValKey() error

func (*Manager) NewAccount

func (manager *Manager) NewAccount(passphrase []byte) (*Account, error)

func (*Manager) NewValKey

func (manager *Manager) NewValKey(pwd string) (*ValAccount, error)

NewValKey generates a new validator key that includes an ecdsa key and a bls key.

func (*Manager) SignHash

func (manager *Manager) SignHash(account Account, hash []byte) (signature []byte, err error)

SignHash 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) SignHashWithPassphrase

func (manager *Manager) SignHashWithPassphrase(account Account, passphrase string, hash []byte) (signature []byte, err error)

SignHashWithPassphrase 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) SignTx

func (manager *Manager) SignTx(account Account, tx *types.Transaction) (*types.Transaction, error)

SignTx signs the given transaction with the requested account.

func (*Manager) SignTxWithKey

func (manager *Manager) SignTxWithKey(key string, tx *types.Transaction, networkId *big.Int) (*types.Transaction, error)

func (*Manager) SignTxWithPassphrase

func (manager *Manager) SignTxWithPassphrase(account Account, passphrase string, tx *types.Transaction) (*types.Transaction, error)

SignTxWithPassphrase signs the transaction if the private key matching the given address can be decrypted with the given passphrase.

func (*Manager) Status

func (manager *Manager) Status(account Account) (string, error)

func (*Manager) TimedUnlock

func (manager *Manager) TimedUnlock(account *Account, passphrase string, timeout time.Duration) error

func (*Manager) Unlock

func (manager *Manager) Unlock(account *Account, passphrase string) error

func (*Manager) Unlocked

func (manager *Manager) Unlocked() map[common.Address]*unlocked

func (*Manager) Update

func (manager *Manager) Update(account *Account, passphrase, newPassphrase string) error

Update passphrase of account

func (*Manager) UseValKey

func (manager *Manager) UseValKey(addr common.Address, pwd string, keep bool) (*keystore.Key, error)

UseValKey will unlock and return the required validator key. If keep is true, then will store that validator key with plaintext, BE CAUTIOUS! Will only keep at most one validator key.

type Storage

type Storage interface {
	GetKey(addr common.Address, filename string, passphrase string) (*keystore.Key, error)
	StoreKey(filename string, key *keystore.Key, passphrase string) error
	ImportKey(key *keystore.Key, passphrase string) (string, error)
	JoinPath(filename string) string
	GetPath(addr common.Address) string
}

type ValAccount

type ValAccount struct {
	Account
	MainPubKey []byte //consensus compressed public key
	BlsPubKey  []byte //compressed bls public key
}

ValAccount is a validator account, for convenient

type Wallet

type Wallet interface {
	// Contains returns whether an account is part of this particular wallet or not.
	Contains(account Account) bool

	// SignTx requests the wallet to sign the given transaction.
	//
	// It looks up the account specified either solely via its address contained within,
	// or optionally with the aid of any location metadata from the embedded URL field.
	//
	// If the wallet requires additional authentication to sign the request (e.g.
	// a password to decrypt the account, or a PIN code to verify the transaction),
	// an AuthNeededError instance will be returned, containing infos for the user
	// about which fields or actions are needed. The user may retry by providing
	// the needed details via SignTxWithPassphrase, or by other means (e.g. unlock
	// the account in a keystore).
	SignTx(account Account, tx *types.Transaction, networkId *big.Int) (*types.Transaction, error)
}

Wallet represents a software or hardware wallet that might contain one or more accounts (derived from the same seed).

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