From 2768732e234cb009367dc1db8f494f14e5a0ade4 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 15 Dec 2020 22:53:07 +0100 Subject: [PATCH] Fixed tracking seed restoring bug --- src/currency_core/account.cpp | 5 ++++ src/currency_core/account.h | 1 + src/wallet/wallet_helpers.h | 44 +++++++++++++++++++++------------- src/wallet/wallets_manager.cpp | 26 ++++++++++++-------- 4 files changed, 50 insertions(+), 26 deletions(-) diff --git a/src/currency_core/account.cpp b/src/currency_core/account.cpp index 85c5ba7f..4f8e9320 100644 --- a/src/currency_core/account.cpp +++ b/src/currency_core/account.cpp @@ -226,6 +226,11 @@ namespace currency return true; } //----------------------------------------------------------------- + bool account_base::is_seed_tracking(const std::string& seed_phrase) + { + return seed_phrase.find(':') != std::string::npos; + } + //----------------------------------------------------------------- bool account_base::is_seed_password_protected(const std::string& seed_phrase, bool& is_password_protected) { //cut the last timestamp word from restore_dats diff --git a/src/currency_core/account.h b/src/currency_core/account.h index ba723670..305b02e3 100644 --- a/src/currency_core/account.h +++ b/src/currency_core/account.h @@ -79,6 +79,7 @@ namespace currency static std::string vector_of_chars_to_string(const std::vector& v) { return std::string(v.begin(), v.end()); } static std::vector string_to_vector_of_chars(const std::string& v) { return std::vector(v.begin(), v.end()); } static bool is_seed_password_protected(const std::string& seed_phrase, bool& is_password_protected); + static bool is_seed_tracking(const std::string& seed_phrase); BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(m_keys) diff --git a/src/wallet/wallet_helpers.h b/src/wallet/wallet_helpers.h index 12355011..8e37d856 100644 --- a/src/wallet/wallet_helpers.h +++ b/src/wallet/wallet_helpers.h @@ -27,27 +27,39 @@ namespace tools inline std::string get_seed_phrase_info(const std::string& seed_phrase, const std::string& seed_password, view::seed_phrase_info& result) { //cut the last timestamp word from restore_dats - try{ - result.syntax_correct = currency::account_base::is_seed_password_protected(seed_phrase, result.require_password); + try + { + //restore_from_tracking_seed + bool is_tracking = currency::account_base::is_seed_tracking(seed_phrase); + if (is_tracking) + { + currency::account_base acc; + result.require_password = false; + result.hash_sum_matched = false; + result.syntax_correct = acc.restore_from_tracking_seed(seed_phrase); + } + else + { + result.syntax_correct = currency::account_base::is_seed_password_protected(seed_phrase, result.require_password); + if (result.syntax_correct && result.require_password) + { + if (seed_password.size()) + { + currency::account_base acc; + result.hash_sum_matched = acc.restore_from_seed_phrase(seed_phrase, seed_password); + } + else + { + result.hash_sum_matched = false; + } + } + } + return API_RETURN_CODE_OK; } catch (...) { result.syntax_correct = false; return API_RETURN_CODE_OK; } - - if (result.syntax_correct && result.require_password) - { - if (seed_password.size()) - { - currency::account_base acc; - result.hash_sum_matched = acc.restore_from_seed_phrase(seed_phrase, seed_password); - } - else - { - result.hash_sum_matched = false; - } - } - return API_RETURN_CODE_OK; } } \ No newline at end of file diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index ec07c3b2..eb101997 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1060,16 +1060,22 @@ std::string wallets_manager::is_pos_allowed() } std::string wallets_manager::is_valid_brain_restore_data(const std::string& seed_phrase, const std::string& seed_password) { + currency::account_base acc; - if (acc.restore_from_seed_phrase(seed_phrase, seed_password)) - return API_RETURN_CODE_TRUE; - - currency::account_public_address addr; - crypto::secret_key view_sec_key; - uint64_t ts; - if (currency::parse_tracking_seed(seed_phrase, addr, view_sec_key, ts)) - return API_RETURN_CODE_TRUE; + if (!currency::account_base::is_seed_tracking(seed_phrase)) + { + if (acc.restore_from_seed_phrase(seed_phrase, seed_password)) + return API_RETURN_CODE_TRUE; + } + else + { + currency::account_public_address addr = AUTO_VAL_INIT(addr); + crypto::secret_key view_sec_key = AUTO_VAL_INIT(view_sec_key); + uint64_t ts = 0; + if (currency::parse_tracking_seed(seed_phrase, addr, view_sec_key, ts)) + return API_RETURN_CODE_TRUE; + } return API_RETURN_CODE_FALSE; } #ifndef MOBILE_WALLET_BUILD @@ -1115,8 +1121,8 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: currency::account_base acc; try { - bool auditable_watch_only = seed_phrase.find(':') != std::string::npos; - w->restore(path, password, seed_phrase, auditable_watch_only, seed_password); + bool is_tracking = currency::account_base::is_seed_tracking(seed_phrase); + w->restore(path, password, seed_phrase, is_tracking, seed_password); //owr.seed = w->get_account().get_seed_phrase(); } catch (const tools::error::file_exists&)