diff --git a/src/mnemonics/electrum-words.cpp b/src/mnemonics/electrum-words.cpp index b53f3acd3..86c0f86f1 100644 --- a/src/mnemonics/electrum-words.cpp +++ b/src/mnemonics/electrum-words.cpp @@ -91,29 +91,17 @@ namespace bool find_seed_language(const std::vector &seed, bool has_checksum, std::vector &matched_indices, Language::Base **language) { - // If there's a new language added, add an instance of it here. - std::vector language_instances({ - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance(), - Language::Singleton::instance() - }); + std::vector language_instances = crypto::ElectrumWords::get_language_list(); Language::Base *fallback = NULL; + // Add the deprecated OldEnglish language to ensure backwards compatibility + language_instances.push_back(Language::Singleton::instance()); + std::vector::const_iterator it2; matched_indices.reserve(seed.size()); // Iterate through all the languages and find a match - for (std::vector::iterator it1 = language_instances.begin(); + for (std::vector::iterator it1 = language_instances.begin(); it1 != language_instances.end(); it1++) { const std::unordered_map &word_map = (*it1)->get_word_map(); @@ -153,13 +141,13 @@ namespace if (has_checksum) if (!checksum_test(seed, *it1)) { - fallback = *it1; + fallback = const_cast(*it1); full_match = false; } } if (full_match) { - *language = *it1; + *language = const_cast(*it1); MINFO("Full match for language " << (*language)->get_english_language_name()); return true; } @@ -436,6 +424,7 @@ namespace crypto std::vector get_language_list() { + // If there's a new language added, add an instance of it here. static const std::vector language_instances({ Language::Singleton::instance(), Language::Singleton::instance(), diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 014aed0e7..dc31a2d76 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp @@ -484,8 +484,15 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co setStatusCritical(error); return false; } - // TODO: validate language - m_wallet->set_seed_language(language); + + // validate language + if (!crypto::ElectrumWords::is_valid_language(language)) { + std::string error = "failed to validate language."; + LOG_ERROR(error); + setStatusError(error); + return false; + } + crypto::secret_key recovery_val, secret_key; try { recovery_val = m_wallet->generate(path, password, secret_key, false, false); @@ -522,8 +529,14 @@ bool WalletImpl::createWatchOnly(const std::string &path, const std::string &pas setStatusError(error); return false; } - // TODO: validate language - view_wallet->set_seed_language(language); + + // validate language + if (!crypto::ElectrumWords::is_valid_language(language)) { + std::string error = "failed to validate language."; + LOG_ERROR(error); + setStatusError(error); + return false; + } const crypto::secret_key viewkey = m_wallet->get_account().get_keys().m_view_secret_key; const cryptonote::account_public_address address = m_wallet->get_account().get_keys().m_account_address;