Fabcoin Core  0.16.2
P2P Digital Currency
Public Types | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
dev::eth::KeyManager Class Reference

High-level manager of password-encrypted keys for Ethereum. More...

#include <KeyManager.h>

Collaboration diagram for dev::eth::KeyManager:
[legend]

Public Types

enum  NewKeyType {
  NewKeyType::DirectICAP = 0, NewKeyType::NoVanity, NewKeyType::FirstTwo, NewKeyType::FirstTwoNextTwo,
  NewKeyType::FirstThree, NewKeyType::FirstFour
}
 

Public Member Functions

 KeyManager (std::string const &_keysFile=defaultPath(), std::string const &_secretsPath=SecretStore::defaultPath())
 
 ~KeyManager ()
 
void setSecretsPath (std::string const &_secretsPath)
 
void setKeysFile (std::string const &_keysFile)
 
std::string const & keysFile () const
 
bool exists () const
 
void create (std::string const &_pass)
 
bool load (std::string const &_pass)
 
void save (std::string const &_pass) const
 
void notePassword (std::string const &_pass)
 
void noteHint (std::string const &_pass, std::string const &_hint)
 
bool haveHint (std::string const &_pass) const
 
Addresses accounts () const
 
AddressHash accountsHash () const
 
bool hasAccount (Address const &_address) const
 
std::string const & accountName (Address const &_address) const
 
std::string const & passwordHint (Address const &_address) const
 
void changeName (Address const &_address, std::string const &_name)
 Should be called to change password. More...
 
bool haveKey (Address const &_a) const
 
h128 uuid (Address const &_a) const
 
Address address (h128 const &_uuid) const
 
h128 import (Secret const &_s, std::string const &_accountName, std::string const &_pass, std::string const &_passwordHint)
 
h128 import (Secret const &_s, std::string const &_accountName)
 
Address importBrain (std::string const &_seed, std::string const &_accountName, std::string const &_seedHint)
 
void importExistingBrain (Address const &_a, std::string const &_accountName, std::string const &_seedHint)
 
SecretStorestore ()
 
void importExisting (h128 const &_uuid, std::string const &_accountName, std::string const &_pass, std::string const &_passwordHint)
 
void importExisting (h128 const &_uuid, std::string const &_accountName)
 
void importExisting (h128 const &_uuid, std::string const &_accountName, Address const &_addr, h256 const &_passHash=h256(), std::string const &_passwordHint=std::string())
 
Secret secret (Address const &_address, std::function< std::string()> const &_pass=DontKnowThrow, bool _usePasswordCache=true) const
 
Secret secret (h128 const &_uuid, std::function< std::string()> const &_pass=DontKnowThrow, bool _usePasswordCache=true) const
 
bool recode (Address const &_address, SemanticPassword _newPass, std::function< std::string()> const &_pass=DontKnowThrow, KDF _kdf=KDF::Scrypt)
 
bool recode (Address const &_address, std::string const &_newPass, std::string const &_hint, std::function< std::string()> const &_pass=DontKnowThrow, KDF _kdf=KDF::Scrypt)
 
void kill (h128 const &_id)
 
void kill (Address const &_a)
 

Static Public Member Functions

static std::string defaultPath ()
 
static KeyPair presaleSecret (std::string const &_json, std::function< std::string(bool)> const &_password)
 Extracts the secret key from the presale wallet. More...
 
static Secret brain (std::string const &_seed)
 
static Secret subkey (Secret const &_s, unsigned _index)
 
static KeyPair newKeyPair (NewKeyType _type)
 

Private Member Functions

std::string getPassword (h128 const &_uuid, std::function< std::string()> const &_pass=DontKnowThrow) const
 
std::string getPassword (h256 const &_passHash, std::function< std::string()> const &_pass=DontKnowThrow) const
 
std::string defaultPassword (std::function< std::string()> const &_pass=DontKnowThrow) const
 
h256 hashPassword (std::string const &_pass) const
 
void cachePassword (std::string const &_password) const
 Stores the password by its hash in the password cache. More...
 
bool write () const
 
bool write (std::string const &_keysFile) const
 
void write (std::string const &_pass, std::string const &_keysFile) const
 
void write (SecureFixedHash< 16 > const &_key, std::string const &_keysFile) const
 

Private Attributes

std::unordered_map< h128, Addressm_uuidLookup
 Mapping key uuid -> address. More...
 
std::unordered_map< Address, h128m_addrLookup
 Mapping address -> key uuid. More...
 
std::unordered_map< Address, KeyInfom_keyInfo
 Mapping address -> key info. More...
 
std::unordered_map< h256, std::string > m_passwordHint
 Mapping password hash -> password hint. More...
 
std::unordered_map< h256, std::string > m_cachedPasswords
 
std::string m_defaultPasswordDeprecated
 
std::string m_keysFile
 
SecureFixedHash< 16 > m_keysFileKey
 
h256 m_master
 
SecretStore m_store
 

Detailed Description

High-level manager of password-encrypted keys for Ethereum.

Usage:

Call exists() to check whether there is already a database. If so, get the master password from the user and call load() with it. If not, get a new master password from the user (get them to type it twice and keep some hint around!) and call create() with it.

Uses a "key file" (and a corresponding .salt file) that contains encrypted information about the keys and a directory called "secrets path" that contains a file for each key.

Definition at line 72 of file KeyManager.h.

Member Enumeration Documentation

Enumerator
DirectICAP 
NoVanity 
FirstTwo 
FirstTwoNextTwo 
FirstThree 
FirstFour 

Definition at line 75 of file KeyManager.h.

Constructor & Destructor Documentation

KeyManager::KeyManager ( std::string const &  _keysFile = defaultPath(),
std::string const &  _secretsPath = SecretStore::defaultPath() 
)

Definition at line 37 of file KeyManager.cpp.

Here is the call graph for this function:

KeyManager::~KeyManager ( )

Definition at line 48 of file KeyManager.cpp.

Member Function Documentation

string const & KeyManager::accountName ( Address const &  _address) const
Returns
the human-readable name or json-encoded info of the account for the given address.

Definition at line 351 of file KeyManager.cpp.

Here is the caller graph for this function:

Addresses KeyManager::accounts ( ) const
Returns
the list of account addresses.

Definition at line 328 of file KeyManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

AddressHash dev::eth::KeyManager::accountsHash ( ) const
inline
Returns
a hashset of all account addresses.

Definition at line 96 of file KeyManager.h.

Address KeyManager::address ( h128 const &  _uuid) const
Returns
the address corresponding to the key with uuid _uuid or the zero address on error.

Definition at line 205 of file KeyManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Secret KeyManager::brain ( std::string const &  _seed)
static
Returns
the brainwallet secret for the given seed.

Definition at line 227 of file KeyManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void KeyManager::cachePassword ( std::string const &  _password) const
private

Stores the password by its hash in the password cache.

Definition at line 394 of file KeyManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void KeyManager::changeName ( Address const &  _address,
std::string const &  _name 
)

Should be called to change password.

Definition at line 363 of file KeyManager.cpp.

Here is the call graph for this function:

void KeyManager::create ( std::string const &  _pass)

Definition at line 56 of file KeyManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

std::string dev::eth::KeyManager::defaultPassword ( std::function< std::string()> const &  _pass = DontKnowThrow) const
inlineprivate

Definition at line 152 of file KeyManager.h.

Here is the call graph for this function:

Here is the caller graph for this function:

static std::string dev::eth::KeyManager::defaultPath ( )
inlinestatic

Definition at line 136 of file KeyManager.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool KeyManager::exists ( ) const

Definition at line 51 of file KeyManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

std::string dev::eth::KeyManager::getPassword ( h128 const &  _uuid,
std::function< std::string()> const &  _pass = DontKnowThrow 
) const
private

Here is the caller graph for this function:

std::string dev::eth::KeyManager::getPassword ( h256 const &  _passHash,
std::function< std::string()> const &  _pass = DontKnowThrow 
) const
private
bool KeyManager::hasAccount ( Address const &  _address) const

Definition at line 339 of file KeyManager.cpp.

Here is the call graph for this function:

h256 KeyManager::hashPassword ( std::string const &  _pass) const
private

Definition at line 388 of file KeyManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool dev::eth::KeyManager::haveHint ( std::string const &  _pass) const
inline

Definition at line 91 of file KeyManager.h.

Here is the caller graph for this function:

bool dev::eth::KeyManager::haveKey ( Address const &  _a) const
inline
Returns
true if the given address has a key (UUID) associated with it. Equivalent to !!uuid(_a) If the address has no key, it could be a brain wallet.

Definition at line 107 of file KeyManager.h.

Here is the call graph for this function:

h128 dev::eth::KeyManager::import ( Secret const &  _s,
std::string const &  _accountName,
std::string const &  _pass,
std::string const &  _passwordHint 
)

Here is the caller graph for this function:

h128 dev::eth::KeyManager::import ( Secret const &  _s,
std::string const &  _accountName 
)
inline

Definition at line 114 of file KeyManager.h.

Address KeyManager::importBrain ( std::string const &  _seed,
std::string const &  _accountName,
std::string const &  _seedHint 
)

Definition at line 249 of file KeyManager.cpp.

Here is the call graph for this function:

void dev::eth::KeyManager::importExisting ( h128 const &  _uuid,
std::string const &  _accountName,
std::string const &  _pass,
std::string const &  _passwordHint 
)

Here is the caller graph for this function:

void dev::eth::KeyManager::importExisting ( h128 const &  _uuid,
std::string const &  _accountName 
)
inline

Definition at line 120 of file KeyManager.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void dev::eth::KeyManager::importExisting ( h128 const &  _uuid,
std::string const &  _accountName,
Address const &  _addr,
h256 const &  _passHash = h256(),
std::string const &  _passwordHint = std::string() 
)
void KeyManager::importExistingBrain ( Address const &  _a,
std::string const &  _accountName,
std::string const &  _seedHint 
)

Definition at line 258 of file KeyManager.cpp.

Here is the call graph for this function:

std::string const& dev::eth::KeyManager::keysFile ( ) const
inline

Definition at line 82 of file KeyManager.h.

Here is the caller graph for this function:

void dev::eth::KeyManager::kill ( h128 const &  _id)
inline

Definition at line 133 of file KeyManager.h.

Here is the call graph for this function:

Here is the caller graph for this function:

void KeyManager::kill ( Address const &  _a)

Definition at line 288 of file KeyManager.cpp.

Here is the call graph for this function:

bool KeyManager::load ( std::string const &  _pass)

Definition at line 88 of file KeyManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

KeyPair KeyManager::newKeyPair ( KeyManager::NewKeyType  _type)
static
Returns
new random keypair with given vanity

Definition at line 441 of file KeyManager.cpp.

Here is the call graph for this function:

void dev::eth::KeyManager::noteHint ( std::string const &  _pass,
std::string const &  _hint 
)
inline

Definition at line 90 of file KeyManager.h.

Here is the caller graph for this function:

void dev::eth::KeyManager::notePassword ( std::string const &  _pass)
inline

Definition at line 89 of file KeyManager.h.

Here is the caller graph for this function:

string const & KeyManager::passwordHint ( Address const &  _address) const
Returns
the password hint for the account for the given address;

Definition at line 373 of file KeyManager.cpp.

Here is the caller graph for this function:

KeyPair KeyManager::presaleSecret ( std::string const &  _json,
std::function< std::string(bool)> const &  _password 
)
static

Extracts the secret key from the presale wallet.

Definition at line 298 of file KeyManager.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool dev::eth::KeyManager::recode ( Address const &  _address,
SemanticPassword  _newPass,
std::function< std::string()> const &  _pass = DontKnowThrow,
KDF  _kdf = KDF::Scrypt 
)

Here is the caller graph for this function:

bool dev::eth::KeyManager::recode ( Address const &  _address,
std::string const &  _newPass,
std::string const &  _hint,
std::function< std::string()> const &  _pass = DontKnowThrow,
KDF  _kdf = KDF::Scrypt 
)
void dev::eth::KeyManager::save ( std::string const &  _pass) const
inline

Definition at line 87 of file KeyManager.h.

Here is the caller graph for this function:

Secret dev::eth::KeyManager::secret ( Address const &  _address,
std::function< std::string()> const &  _pass = DontKnowThrow,
bool  _usePasswordCache = true 
) const
Returns
the secret key associated with an address provided the password query function _pass or the zero-secret key on error.

Here is the caller graph for this function:

Secret dev::eth::KeyManager::secret ( h128 const &  _uuid,
std::function< std::string()> const &  _pass = DontKnowThrow,
bool  _usePasswordCache = true 
) const
Returns
the secret key associated with the uuid of a key provided the password query function _pass or the zero-secret key on error.
void dev::eth::KeyManager::setKeysFile ( std::string const &  _keysFile)
inline

Definition at line 81 of file KeyManager.h.

Here is the caller graph for this function:

void dev::eth::KeyManager::setSecretsPath ( std::string const &  _secretsPath)
inline

Definition at line 80 of file KeyManager.h.

SecretStore& dev::eth::KeyManager::store ( )
inline

Definition at line 118 of file KeyManager.h.

Here is the caller graph for this function:

Secret KeyManager::subkey ( Secret const &  _s,
unsigned  _index 
)
static
Returns
the HD subkey for a given key.

Definition at line 239 of file KeyManager.cpp.

Here is the call graph for this function:

h128 KeyManager::uuid ( Address const &  _a) const
Returns
the uuid of the key for the address _a or the empty hash on error.

Definition at line 197 of file KeyManager.cpp.

Here is the caller graph for this function:

bool dev::eth::KeyManager::write ( ) const
inlineprivate

Definition at line 160 of file KeyManager.h.

Here is the call graph for this function:

Here is the caller graph for this function:

bool dev::eth::KeyManager::write ( std::string const &  _keysFile) const
private
void dev::eth::KeyManager::write ( std::string const &  _pass,
std::string const &  _keysFile 
) const
private
void dev::eth::KeyManager::write ( SecureFixedHash< 16 > const &  _key,
std::string const &  _keysFile 
) const
private

Member Data Documentation

std::unordered_map<Address, h128> dev::eth::KeyManager::m_addrLookup
private

Mapping address -> key uuid.

Definition at line 170 of file KeyManager.h.

std::unordered_map<h256, std::string> dev::eth::KeyManager::m_cachedPasswords
mutableprivate

Definition at line 177 of file KeyManager.h.

std::string dev::eth::KeyManager::m_defaultPasswordDeprecated
private

Definition at line 184 of file KeyManager.h.

std::unordered_map<Address, KeyInfo> dev::eth::KeyManager::m_keyInfo
private

Mapping address -> key info.

Definition at line 172 of file KeyManager.h.

std::string dev::eth::KeyManager::m_keysFile
mutableprivate

Definition at line 186 of file KeyManager.h.

SecureFixedHash<16> dev::eth::KeyManager::m_keysFileKey
mutableprivate

Definition at line 187 of file KeyManager.h.

h256 dev::eth::KeyManager::m_master
mutableprivate

Definition at line 188 of file KeyManager.h.

std::unordered_map<h256, std::string> dev::eth::KeyManager::m_passwordHint
private

Mapping password hash -> password hint.

Definition at line 174 of file KeyManager.h.

SecretStore dev::eth::KeyManager::m_store
private

Definition at line 189 of file KeyManager.h.

std::unordered_map<h128, Address> dev::eth::KeyManager::m_uuidLookup
private

Mapping key uuid -> address.

Definition at line 168 of file KeyManager.h.


The documentation for this class was generated from the following files: