diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index 8e7cced..a656447 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -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(new tools::wallet2(static_cast(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 ptx; // TODO wallet_rpc_server: unused variable - try - { + try { // gather info for each tx vector> txs; diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index e64d6f6..77682d7 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -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); /** diff --git a/src/wallet/monero_wallet_keys.cpp b/src/wallet/monero_wallet_keys.cpp index 2d87ba4..75dd5f4 100644 --- a/src/wallet/monero_wallet_keys.cpp +++ b/src/wallet/monero_wallet_keys.cpp @@ -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{}; diff --git a/src/wallet/monero_wallet_keys.h b/src/wallet/monero_wallet_keys.h index 1a44e03..c9ab185 100644 --- a/src/wallet/monero_wallet_keys.h +++ b/src/wallet/monero_wallet_keys.h @@ -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.