Documentation ¶
Overview ¶
Package accountmgr provides account creation and management functionalities.
Index ¶
- Variables
- type AccountManager
- func (am *AccountManager) APIs() jsonrpc.APISet
- func (am *AccountManager) AccountExist(address string) (bool, error)
- func (am *AccountManager) AskForPassword() (string, error)
- func (am *AccountManager) AskForPasswordOnce() (string, error)
- func (am *AccountManager) CreateAccount(address *crypto.Key, passphrase string) error
- func (am *AccountManager) CreateCmd(seed int64, pwd string) (*crypto.Key, error)
- func (am *AccountManager) GetByAddress(addr string) (*StoredAccount, error)
- func (am *AccountManager) GetByIndex(i int) (*StoredAccount, error)
- func (am *AccountManager) GetDefault() (*StoredAccount, error)
- func (am *AccountManager) ImportCmd(keyfile, pwd string) error
- func (am *AccountManager) ListAccounts() (accounts []*StoredAccount, err error)
- func (am *AccountManager) ListCmd() error
- func (am *AccountManager) RevealCmd(address, pwd string) error
- func (am *AccountManager) UpdateCmd(address string) error
- type PasswordPrompt
- type StoredAccount
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAccountNotFound represents an error about a missing account ErrAccountNotFound = fmt.Errorf("account not found") )
Functions ¶
This section is empty.
Types ¶
type AccountManager ¶
type AccountManager struct {
// contains filtered or unexported fields
}
AccountManager defines functionalities to create, update, fetch and import accounts. An account encapsulates an address and private key and are stored in an encrypted format locally.
func New ¶
func New(accountDir string) *AccountManager
New creates an account manager. accountDir is where encrypted account files are stored. Caller is expected to have created the accountDir before calling New
func (*AccountManager) APIs ¶
func (am *AccountManager) APIs() jsonrpc.APISet
APIs returns all API handlers
func (*AccountManager) AccountExist ¶
func (am *AccountManager) AccountExist(address string) (bool, error)
AccountExist checks if an account with a matching address exists
func (*AccountManager) AskForPassword ¶
func (am *AccountManager) AskForPassword() (string, error)
AskForPassword starts an interactive prompt to collect password. Returns error if password and repeated passwords do not match
func (*AccountManager) AskForPasswordOnce ¶
func (am *AccountManager) AskForPasswordOnce() (string, error)
AskForPasswordOnce is like askForPassword but it does not ask to confirm password.
func (*AccountManager) CreateAccount ¶
func (am *AccountManager) CreateAccount(address *crypto.Key, passphrase string) error
CreateAccount creates a new account
func (*AccountManager) CreateCmd ¶
CreateCmd creates a new account and interactively obtains encryption passphrase. If seed is non-zero, it is used. Otherwise, one will be randomly generated. If pwd is provide and it is not a file path, it is used as the password. Otherwise, the file is read, trimmed of newline characters (left and right) and used as the password. When pwd is set, interactive password collection is not used.
func (*AccountManager) GetByAddress ¶
func (am *AccountManager) GetByAddress(addr string) (*StoredAccount, error)
GetByAddress gets an account by its address in the list of accounts which is ordered by the time of creation.
func (*AccountManager) GetByIndex ¶
func (am *AccountManager) GetByIndex(i int) (*StoredAccount, error)
GetByIndex returns an account by its current position in the list of accounts which is ordered by the time of creation.
func (*AccountManager) GetDefault ¶
func (am *AccountManager) GetDefault() (*StoredAccount, error)
GetDefault gets the oldest account. Usually the account with 0 index.
func (*AccountManager) ImportCmd ¶
func (am *AccountManager) ImportCmd(keyfile, pwd string) error
ImportCmd takes a keyfile containing unencrypted password to create a new account. Keyfile must be a path to a file that exists. If pwd is provide and it is not a file path, it is used as the password. Otherwise, the file is read, trimmed of newline characters (left and right) and used as the password. When pwd is set, interactive password collection is not used.
func (*AccountManager) ListAccounts ¶
func (am *AccountManager) ListAccounts() (accounts []*StoredAccount, err error)
ListAccounts returns the accounts stored on disk.
func (*AccountManager) ListCmd ¶
func (am *AccountManager) ListCmd() error
ListCmd fetches and lists all accounts
func (*AccountManager) RevealCmd ¶
func (am *AccountManager) RevealCmd(address, pwd string) error
RevealCmd decrypts and account and outputs the private key. If pwd is provide and it is not a file path, it is used as the password. Otherwise, the file is read, trimmed of newline characters (left and right) and used as the password. When pwd is set, interactive password collection is not used.
func (*AccountManager) UpdateCmd ¶
func (am *AccountManager) UpdateCmd(address string) error
UpdateCmd fetches and lists all accounts
type PasswordPrompt ¶
PasswordPrompt reprents a function that can collect user input
type StoredAccount ¶
type StoredAccount struct { Address string Cipher []byte CreatedAt time.Time // contains filtered or unexported fields }
StoredAccount represents an encrypted account stored on disk
func (*StoredAccount) Decrypt ¶
func (sa *StoredAccount) Decrypt(passphrase string) error
Decrypt decrypts the account cipher and initializes the address field
func (*StoredAccount) GetAddress ¶
func (sa *StoredAccount) GetAddress() *crypto.Key
GetAddress returns the address object which contains the private key and public key. Must call Decrypt() first.
func (*StoredAccount) GetKey ¶
func (sa *StoredAccount) GetKey() *crypto.Key
GetKey gets the decrypted key