39 KeyInfo(
h256 const& _passHash, std::string
const& _accountName, std::string
const& _passwordHint = std::string()): passHash(_passHash), accountName(_accountName), passwordHint(_passwordHint) {}
49 static h256 const UnknownPassword;
51 static auto const DontKnowThrow = [](){
throw PasswordUnknown();
return std::string(); };
75 enum class NewKeyType { DirectICAP = 0, NoVanity, FirstTwo, FirstTwoNextTwo, FirstThree, FirstFour };
80 void setSecretsPath(std::string
const& _secretsPath) { m_store.setPath(_secretsPath); }
81 void setKeysFile(std::string
const& _keysFile) { m_keysFile = _keysFile; }
82 std::string
const&
keysFile()
const {
return m_keysFile; }
85 void create(std::string
const& _pass);
86 bool load(std::string
const& _pass);
87 void save(std::string
const& _pass)
const { write(_pass, m_keysFile); }
89 void notePassword(std::string
const& _pass) { m_cachedPasswords[hashPassword(_pass)] = _pass; }
90 void noteHint(std::string
const& _pass, std::string
const& _hint) {
if (!_hint.empty()) m_passwordHint[hashPassword(_pass)] = _hint; }
91 bool haveHint(std::string
const& _pass)
const {
auto h = hashPassword(_pass);
return m_cachedPasswords.count(
h) && !m_cachedPasswords.at(
h).empty(); }
97 bool hasAccount(
Address const& _address)
const;
99 std::string
const& accountName(
Address const& _address)
const;
101 std::string
const& passwordHint(
Address const& _address)
const;
103 void changeName(
Address const& _address, std::string
const& _name);
113 h128 import(
Secret const& _s, std::string
const& _accountName, std::string
const& _pass, std::string
const& _passwordHint);
114 h128 import(
Secret const& _s, std::string
const& _accountName) {
return import(_s, _accountName, defaultPassword(), std::string()); }
115 Address importBrain(std::string
const& _seed, std::string
const& _accountName, std::string
const& _seedHint);
116 void importExistingBrain(
Address const& _a, std::string
const& _accountName, std::string
const& _seedHint);
119 void importExisting(
h128 const& _uuid, std::string
const& _accountName, std::string
const& _pass, std::string
const& _passwordHint);
121 void importExisting(
h128 const& _uuid, std::string
const& _accountName,
Address const& _addr,
h256 const& _passHash =
h256(), std::string
const& _passwordHint = std::string());
125 Secret secret(
Address const& _address,
std::function<std::string()>
const& _pass = DontKnowThrow,
bool _usePasswordCache =
true)
const;
128 Secret secret(
h128 const& _uuid,
std::function<std::string()>
const& _pass = DontKnowThrow,
bool _usePasswordCache =
true)
const;
131 bool recode(
Address const& _address, std::string
const& _newPass, std::string
const& _hint,
std::function<std::string()>
const& _pass = DontKnowThrow,
KDF _kdf =
KDF::Scrypt);
139 static KeyPair presaleSecret(std::string
const& _json,
std::function<std::string(
bool)>
const& _password);
142 static Secret brain(std::string
const& _seed);
145 static Secret subkey(
Secret const& _s,
unsigned _index);
153 h256 hashPassword(std::string
const& _pass)
const;
156 void cachePassword(std::string
const& _password)
const;
161 bool write(std::string
const& _keysFile)
const;
162 void write(std::string
const& _pass, std::string
const& _keysFile)
const;
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
AddressHash accountsHash() const
#define function(a, b, c, d, k, s)
void notePassword(std::string const &_pass)
void noteHint(std::string const &_pass, std::string const &_hint)
Simple class that represents a "key pair".
std::string const & keysFile() const
std::string getDataDir(std::string _prefix="ethereum")
void setSecretsPath(std::string const &_secretsPath)
std::string accountName
Name of the key, or JSON key info if begins with '{'.
void setKeysFile(std::string const &_keysFile)
Base class for all exceptions.
High-level manager of password-encrypted keys for Ethereum.
std::string passwordHint
Hint of the password. Alternative place for storage than the hash-based lookup.
void kill(h128 const &_id)
static std::string defaultPath()
void importExisting(h128 const &_uuid, std::string const &_accountName)
bool haveKey(Address const &_a) const
std::string m_defaultPasswordDeprecated
h160s Addresses
A vector of Ethereum addresses.
void save(std::string const &_pass) const
h256 passHash
Hash of the password or h256() / UnknownPassword if unknown.
std::unordered_map< h256, std::string > m_passwordHint
Mapping password hash -> password hint.
SecureFixedHash< 16 > m_keysFileKey
Manages encrypted keys stored in a certain directory on disk.
std::unordered_map< Address, KeyInfo > m_keyInfo
Mapping address -> key info.
bool haveHint(std::string const &_pass) const
std::unordered_map< h256, std::string > m_cachedPasswords
std::string getPassword(std::string const &_prompt)
Requests the user to enter a password on the console.
struct evm_uint160be address(struct evm_env *env)
KeyInfo(h256 const &_passHash, std::string const &_accountName, std::string const &_passwordHint=std::string())
std::unordered_map< Address, h128 > m_addrLookup
Mapping address -> key uuid.
static std::string defaultPath()
std::string defaultPassword(std::function< std::string()> const &_pass=DontKnowThrow) const
std::unordered_map< h128, Address > m_uuidLookup
Mapping key uuid -> address.
std::unordered_set< h160 > AddressHash
A hash set of Ethereum addresses.