Ethereum  PoC-8
The C++ Implementation of Ethereum
dev::eth::KeyManager Class Reference

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

#include <KeyManager.h>

Public Types

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

Public Member Functions

 KeyManager (boost::filesystem::path const &_keysFile=defaultPath(), boost::filesystem::path const &_secretsPath=SecretStore::defaultPath())
 
 ~KeyManager ()
 
void setKeysFile (boost::filesystem::path const &_keysFile)
 
boost::filesystem::path 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
 
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)
 
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, 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, 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 boost::filesystem::path 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 KeyPair newKeyPair (NewKeyType _type)
 

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 74 of file KeyManager.h.

Member Enumeration Documentation

◆ NewKeyType

Enumerator
DirectICAP 
NoVanity 
FirstTwo 
FirstTwoNextTwo 
FirstThree 
FirstFour 

Definition at line 77 of file KeyManager.h.

Constructor & Destructor Documentation

◆ KeyManager()

KeyManager::KeyManager ( boost::filesystem::path const &  _keysFile = defaultPath(),
boost::filesystem::path const &  _secretsPath = SecretStore::defaultPath() 
)

Definition at line 37 of file KeyManager.cpp.

◆ ~KeyManager()

KeyManager::~KeyManager ( )

Definition at line 48 of file KeyManager.cpp.

Member Function Documentation

◆ accountName()

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 293 of file KeyManager.cpp.

◆ accounts()

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

Definition at line 270 of file KeyManager.cpp.

◆ accountsHash()

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

Definition at line 97 of file KeyManager.h.

◆ address()

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 185 of file KeyManager.cpp.

◆ create()

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

Definition at line 56 of file KeyManager.cpp.

◆ defaultPath()

static boost::filesystem::path dev::eth::KeyManager::defaultPath ( )
inlinestatic

Definition at line 128 of file KeyManager.h.

◆ exists()

bool KeyManager::exists ( ) const

Definition at line 51 of file KeyManager.cpp.

◆ hasAccount()

bool KeyManager::hasAccount ( Address const &  _address) const

Definition at line 281 of file KeyManager.cpp.

◆ haveHint()

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

Definition at line 92 of file KeyManager.h.

◆ import() [1/2]

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

Definition at line 110 of file KeyManager.h.

◆ import() [2/2]

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

◆ importExisting() [1/2]

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() 
)

◆ importExisting() [2/2]

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

◆ keysFile()

boost::filesystem::path const& dev::eth::KeyManager::keysFile ( ) const
inline

Definition at line 83 of file KeyManager.h.

◆ kill() [1/2]

void KeyManager::kill ( Address const &  _a)

Definition at line 230 of file KeyManager.cpp.

◆ kill() [2/2]

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

Definition at line 125 of file KeyManager.h.

◆ load()

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

Definition at line 74 of file KeyManager.cpp.

◆ newKeyPair()

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

Definition at line 373 of file KeyManager.cpp.

◆ noteHint()

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

Definition at line 91 of file KeyManager.h.

◆ notePassword()

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

Definition at line 90 of file KeyManager.h.

◆ passwordHint()

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

Definition at line 305 of file KeyManager.cpp.

◆ presaleSecret()

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 240 of file KeyManager.cpp.

◆ recode()

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

Definition at line 62 of file KeyManager.cpp.

◆ save()

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

Definition at line 88 of file KeyManager.h.

◆ secret() [1/2]

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.

◆ secret() [2/2]

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.

◆ setKeysFile()

void dev::eth::KeyManager::setKeysFile ( boost::filesystem::path const &  _keysFile)
inline

Definition at line 82 of file KeyManager.h.

◆ store()

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

Definition at line 112 of file KeyManager.h.

◆ uuid()

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 177 of file KeyManager.cpp.


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