34 <<
" account list List all keys available in wallet." << endl
35 <<
" account new Create a new key and add it to the wallet." << endl
36 <<
" account update [<uuid>|<address> , ... ] Decrypt and re-encrypt given keys." << endl
37 <<
" account import [<uuid>|<file>|<secret-hex>] Import keys from given source and place in wallet." << endl;
43 <<
" wallet import <file> Import a presale wallet." << endl;
48 if (
string(argv[1]) ==
"wallet")
50 if (3 < argc &&
string(argv[2]) ==
"import")
54 string file = argv[3];
55 string name =
"presale wallet";
59 KeyPair k = m_keyManager->presaleSecret(
61 [&](
bool){
return (pw =
getPassword(
"Enter the passphrase for the presale key: "));}
63 m_keyManager->import(k.
secret(),
name, pw,
"Same passphrase as used for presale key");
64 cout <<
" Address: {" << k.
address().
hex() <<
"}" << endl;
68 if (
auto err = boost::get_error_info<errinfo_comment>(_e))
69 cout <<
" Decryption failed: " << *err << endl;
71 cout <<
" Decryption failed: Unknown reason." << endl;
76 streamWalletHelp(cout);
79 else if (
string(argv[1]) ==
"account")
81 if (argc < 3 ||
string(argv[2]) ==
"list")
84 if (m_keyManager->store().keys().empty())
85 cout <<
"No keys found." << endl;
91 for (
auto const& u: m_keyManager->store().keys())
93 if (
Address a = m_keyManager->address(u))
96 cout <<
"Account #" << k <<
": {" <<
a.hex() <<
"}" << endl;
102 for (
auto const&
a: m_keyManager->accounts())
105 cout <<
"Account #" << k <<
": {" <<
a.hex() <<
"}" <<
" (Brain)" << endl;
108 for (
auto const& u: bare)
110 cout <<
"Account #" << k <<
": " <<
toUUID(u) <<
" (Bare)" << endl;
115 else if (2 < argc &&
string(argv[2]) ==
"new")
121 lock =
createPassword(
"Enter a passphrase with which to secure this account:");
123 h128 u = m_keyManager->import(k.secret(),
name, lock, lockHint);
124 cout <<
"Created key " <<
toUUID(u) << endl;
125 cout <<
" ICAP: " <<
ICAP(k.address()).encoded() << endl;
126 cout <<
" Address: {" << k.
address().hex() <<
"}" << endl;
128 else if (3 < argc &&
string(argv[2]) ==
"import")
131 h128 u = m_keyManager->store().importKey(argv[3]);
134 cerr <<
"Error: reading key file failed" << endl;
138 bytesSec s = m_keyManager->store().secret(u, [&](){
return (pw =
getPassword(
"Enter the passphrase for the key: ")); });
141 cerr <<
"Error: couldn't decode key or invalid secret size." << endl;
148 m_keyManager->importExisting(u, name, pw, lockHint);
149 auto a = m_keyManager->address(u);
150 cout <<
"Imported key " <<
toUUID(u) << endl;
152 cout <<
" Address: {" <<
a.hex() <<
"}" << endl;
155 else if (3 < argc &&
string(argv[2]) ==
"update")
158 for (
int k = 3; k < argc; k++)
164 string newP =
createPassword(
"Enter the new passphrase for the account " + i);
165 auto oldP = [&](){
return getPassword(
"Enter the current passphrase for the account " + i +
": "); };
166 bool recoded =
false;
169 recoded = m_keyManager->store().recode(
176 else if (u !=
h128())
178 recoded = m_keyManager->store().recode(
186 cerr <<
"Re-encoded " << i << endl;
188 cerr <<
"Couldn't re-encode " << i <<
"; key does not exist, corrupt or incorrect passphrase supplied." << endl;
191 cerr <<
"Couldn't re-encode " << i <<
"; does not represent an address or uuid." << endl;
195 streamAccountHelp(cout);
208 string confirm =
getPassword(
"Please confirm the passphrase by entering it again: ");
211 cout <<
"Passwords were different. Try again." << endl;
230 if (m_keyManager->exists())
232 if (m_keyManager->load(std::string()) || m_keyManager->load(
getPassword(
"Please enter your MASTER passphrase: ")))
236 cerr <<
"Couldn't open wallet. Please check passphrase." << endl;
242 cerr <<
"Couldn't open wallet. Does it exist?" << endl;
std::string encoded() const
h128 fromUUID(std::string const &_uuid)
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
std::pair< Address, bytes > address(std::function< bytes(Address, bytes)> const &_call, Address const &_reg) const
static void streamWalletHelp(std::ostream &_out)
stream wallet help section
Simple class that represents a "key pair".
h160 Address
An Ethereum address: 20 bytes.
SecureFixedHash< 32 > Secret
std::hash for asio::adress
std::string contentsString(std::string const &_file)
Retrieve and returns the contents of the given file as a std::string.
Secret const & secret() const
std::string createPassword(std::string const &_prompt) const
ask end user to create a password.
string createPassword(std::string const &_prompt)
dev::KeyPair makeKey() const
creates a ramdom secret/address pair. It uses ICAP.
bytesConstRef ref() const
Base class for all exceptions.
static void streamAccountHelp(std::ostream &_out)
stream account help section
High-level manager of password-encrypted keys for Ethereum.
bool isHex(std::string const &_s) noexcept
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
bool execute(int argc, char **argv)
uses argc, argv provided by the CLI and executes implemented options.
Address const & address() const
Retrieve the associated address of the public key.
Encapsulation of an ICAP address.
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
std::string getPassword(std::string const &_prompt)
Requests the user to enter a password on the console.
bool openWallet()
instanciate KeyManager and open the wallet.
std::string toUUID(h128 const &_uuid)
std::unordered_set< h160 > AddressHash
A hash set of Ethereum addresses.