Skip to content

Commit

Permalink
Print out invalid seed words on fail
Browse files Browse the repository at this point in the history
If the private keys can't be generated, we will print out
every word that isn't present in the english dictionary that
was present in the users input. Thanks to @MoonMoonDogo again
for some style fixes.
  • Loading branch information
zpalmtree committed Feb 6, 2018
1 parent b728fe8 commit be3157c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
19 changes: 16 additions & 3 deletions src/SimpleWallet/SimpleWallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,13 +693,15 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) {

if (!crypto::ElectrumWords::words_to_bytes(mnemonic_phrase, private_spend_key, language)) {
logger(ERROR, BRIGHT_RED) << "Invalid mnemonic phrase";
std::vector<std::string> words;
logIncorrectWords(boost::split(words, mnemonic_phrase, ::isspace));
return false;
}

/* This is not used, but is needed to be passed to the function, not sure how we can avoid this */
Crypto::PublicKey public_view_key;
Crypto::PublicKey unused_dummy_variable;

AccountBase::generateViewFromSpend(private_spend_key, private_view_key, public_view_key);
AccountBase::generateViewFromSpend(private_spend_key, private_view_key, unused_dummy_variable);
}

} else {
Expand Down Expand Up @@ -771,7 +773,7 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) {
return true;
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::generate_mnemonic(Logging::LoggerRef logger) {
bool simple_wallet::generate_mnemonic() {
std::string private_spend_key_string;

do {
Expand Down Expand Up @@ -802,6 +804,17 @@ bool simple_wallet::generate_mnemonic(Logging::LoggerRef logger) {
return true;
}
//----------------------------------------------------------------------------------------------------
void simple_wallet::logIncorrectWords(std::vector<std::string> words) {
Language::Base *language = Language::Singleton<Language::English>::instance();
const std::vector<std::string> &dictionary = language->get_word_list();

for (auto i : words) {
if (std::find(dictionary.begin(), dictionary.end(), i) == dictionary.end()) {
logger(ERROR, BRIGHT_RED) << i << " is not in the english word list!";
}
}
}
//----------------------------------------------------------------------------------------------------
bool simple_wallet::deinit() {
m_wallet->removeObserver(this);
m_node->removeObserver(static_cast<INodeObserver*>(this));
Expand Down
3 changes: 2 additions & 1 deletion src/SimpleWallet/SimpleWallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ namespace CryptoNote
simple_wallet(System::Dispatcher& dispatcher, const CryptoNote::Currency& currency, Logging::LoggerManager& log);

bool init(const boost::program_options::variables_map& vm);
bool generate_mnemonic(Logging::LoggerRef);
bool generate_mnemonic();
void logIncorrectWords(std::vector<std::string>);
bool deinit();
bool run();
void stop();
Expand Down

0 comments on commit be3157c

Please sign in to comment.