Skip to content

Commit

Permalink
Merge pull request #214 from cartoon-face/development
Browse files Browse the repository at this point in the history
`save_keys` command in concealwallet
  • Loading branch information
krypt0x committed Oct 30, 2021
2 parents 2a21c68 + 6ffd331 commit 6643aa2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/SimpleWallet/SimpleWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,7 @@ simple_wallet::simple_wallet(System::Dispatcher& dispatcher, const CryptoNote::C
m_consoleHandler.setHandler("help", boost::bind(&simple_wallet::help, this, boost::arg<1>()), "Show this help");
m_consoleHandler.setHandler("exit", boost::bind(&simple_wallet::exit, this, boost::arg<1>()), "Close wallet");
m_consoleHandler.setHandler("get_reserve_proof", boost::bind(&simple_wallet::get_reserve_proof, this, boost::arg<1>()), "all|<amount> [<message>] - Generate a signature proving that you own at least <amount>, optionally with a challenge string <message>. ");
m_consoleHandler.setHandler("save_keys", boost::bind(&simple_wallet::save_keys_to_file, this, boost::arg<1>()), "Save wallet private keys to \"conceal_keys_backup.txt\"");
}

/* This function shows the number of outputs in the wallet
Expand Down Expand Up @@ -1927,6 +1928,33 @@ void simple_wallet::printConnectionError() const {
fail_msg_writer() << "wallet failed to connect to daemon (" << m_daemon_address << ").";
}

bool simple_wallet::save_keys_to_file(const std::vector<std::string>& args)
{
std::ofstream backup_file("conceal_keys_backup.txt");
AccountKeys keys;
m_wallet->getAccountKeys(keys);

std::string priv_key = "\t\tConceal Keys Backup\n\n";
priv_key += "Wallet file name: " + m_wallet_file + "\n";
priv_key += "Private spend key: " + Common::podToHex(keys.spendSecretKey) + "\n";
priv_key += "Private view key: " + Common::podToHex(keys.viewSecretKey) + "\n";

Crypto::PublicKey unused_dummy_variable;
Crypto::SecretKey deterministic_private_view_key;

AccountBase::generateViewFromSpend(keys.spendSecretKey, deterministic_private_view_key, unused_dummy_variable);
bool deterministic_private_keys = deterministic_private_view_key == keys.viewSecretKey;

/* dont show a mnemonic seed if it is an old non-deterministic wallet */
if (deterministic_private_keys)
priv_key += "Mnemonic seed: " + generate_mnemonic(keys.spendSecretKey) + "\n";

backup_file << priv_key;

logger(INFO, BRIGHT_GREEN) << "Wallet keys have been saved to the current folder where \"concealwallet\" is located.";

return true;
}

int main(int argc, char* argv[]) {
#ifdef _WIN32
Expand Down
2 changes: 1 addition & 1 deletion src/SimpleWallet/SimpleWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ namespace CryptoNote
bool save(const std::vector<std::string> &args);
bool reset(const std::vector<std::string> &args);
bool set_log(const std::vector<std::string> &args);
bool save_keys_to_file(const std::vector<std::string> &args);

bool ask_wallet_create_if_needed();
std::string resolveAlias(const std::string& aliasUrl);
void printConnectionError() const;

Expand Down

0 comments on commit 6643aa2

Please sign in to comment.