add offset to keys/core wallet create_wallet_from_mnemonic()

This commit is contained in:
woodser
2019-12-10 15:49:21 -05:00
parent 0c65c33d7a
commit b7e1079e87
4 changed files with 14 additions and 27 deletions
+8 -21
View File
@@ -821,42 +821,30 @@ namespace monero {
return wallet;
}
monero_wallet_core* monero_wallet_core::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic) {
MTRACE("create_wallet_from_mnemonic(path, password, network_type, mnemonic)");
throw runtime_error("Not implemented");
}
monero_wallet_core* monero_wallet_core::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height) {
monero_wallet_core* monero_wallet_core::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& offset) {
MTRACE("create_wallet_from_mnemonic(path, password, mnemonic, network_type, daemon_connection, restore_height)");
monero_wallet_core* wallet = new monero_wallet_core();
// validate mnemonic and get recovery key and language
crypto::secret_key recoveryKey;
crypto::secret_key recovery_key;
string language;
bool is_valid = crypto::ElectrumWords::words_to_bytes(mnemonic, recoveryKey, language);
bool is_valid = crypto::ElectrumWords::words_to_bytes(mnemonic, recovery_key, language);
if (!is_valid) throw runtime_error("Invalid mnemonic");
if (language == crypto::ElectrumWords::old_language_name) language = Language::English().get_language_name();
// apply offset if given
if (!offset.empty()) recovery_key = cryptonote::decrypt_key(recovery_key, offset);
// initialize wallet
wallet->m_w2 = unique_ptr<tools::wallet2>(new tools::wallet2(static_cast<cryptonote::network_type>(network_type), 1, true));
wallet->set_daemon_connection(daemon_connection);
wallet->m_w2->set_seed_language(language);
wallet->m_w2->generate(path, password, recoveryKey, true, false);
wallet->m_w2->generate(path, password, recovery_key, true, false);
wallet->m_w2->set_refresh_from_block_height(restore_height);
wallet->init_common();
return wallet;
}
monero_wallet_core* monero_wallet_core::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key) {
MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type)");
throw runtime_error("Not implemented");
}
monero_wallet_core* monero_wallet_core::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height) {
MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type, daemon_connection, restore_height)");
throw runtime_error("Not implemented");
}
monero_wallet_core* monero_wallet_core::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language) {
MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type, daemon_connection, restore_height, language)");
monero_wallet_core* wallet = new monero_wallet_core();
@@ -2387,8 +2375,7 @@ namespace monero {
}
std::vector<tools::wallet2::pending_tx> ptx; // TODO wallet_rpc_server: unused variable
try
{
try {
// gather info for each tx
vector<shared_ptr<monero_tx_wallet>> txs;
+1 -4
View File
@@ -120,8 +120,7 @@ namespace monero {
* @param daemon_connection is connection information to a daemon (default = an unconnected wallet)
* @param restore_height is the block height to restore (i.e. scan the chain) from (default = 0)
*/
static monero_wallet_core* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic);
static monero_wallet_core* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height);
static monero_wallet_core* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& offset);
/**
* Create a wallet from an address, view key, and spend key.
@@ -136,8 +135,6 @@ namespace monero {
* @param restore_height is the block height to restore (i.e. scan the chain) from (default = 0)
* @param language is the wallet and mnemonic's language (default = "English")
*/
static monero_wallet_core* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key);
static monero_wallet_core* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height);
static monero_wallet_core* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language);
/**
+4 -1
View File
@@ -93,7 +93,7 @@ namespace monero {
return wallet;
}
monero_wallet_keys* monero_wallet_keys::create_wallet_from_mnemonic(const monero_network_type network_type, const string& mnemonic) {
monero_wallet_keys* monero_wallet_keys::create_wallet_from_mnemonic(const monero_network_type network_type, const string& mnemonic, const string& offset) {
// validate mnemonic and get recovery key and language
crypto::secret_key recovery_key;
@@ -102,6 +102,9 @@ namespace monero {
if (!is_valid) throw runtime_error("Invalid mnemonic");
if (language == crypto::ElectrumWords::old_language_name) language = Language::English().get_language_name();
// apply offset if given
if (!offset.empty()) recovery_key = cryptonote::decrypt_key(recovery_key, offset);
// initialize wallet account
monero_wallet_keys* wallet = new monero_wallet_keys();
wallet->m_account = cryptonote::account_base{};
+1 -1
View File
@@ -86,7 +86,7 @@ namespace monero {
* @param network_type is the wallet's network type
* @param mnemonic is the mnemonic of the wallet to construct
*/
static monero_wallet_keys* create_wallet_from_mnemonic(const monero_network_type network_type, const string& mnemonic);
static monero_wallet_keys* create_wallet_from_mnemonic(const monero_network_type network_type, const string& mnemonic, const string& offset);
/**
* Create a wallet from an address, view key, and spend key.