From 2ba77629ad4f23e521fa1ff22d1970d3619c2fa0 Mon Sep 17 00:00:00 2001 From: Jakob Lind Date: Sun, 3 Aug 2014 16:58:21 +0200 Subject: [PATCH] refactoring. get seed code in wallet2 --- src/simplewallet/simplewallet.cpp | 15 +++------------ src/wallet/wallet2.cpp | 18 ++++++++++++++++++ src/wallet/wallet2.h | 2 ++ 3 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 45dc49bb..58706338 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -46,11 +46,7 @@ #include "version.h" #include "crypto/crypto.h" // for crypto::secret_key definition #include "crypto/electrum-words.h" -extern "C" -{ -#include "crypto/keccak.h" -#include "crypto/crypto-ops.h" -} + #if defined(WIN32) #include #endif @@ -195,14 +191,9 @@ std::string simple_wallet::get_commands_str() bool simple_wallet::seed(const std::vector &args/* = std::vector()*/) { std::string electrum_words; - crypto::ElectrumWords::bytes_to_words(m_wallet->get_account().get_keys().m_spend_secret_key, electrum_words); - - crypto::secret_key second; - keccak((uint8_t *)&m_wallet->get_account().get_keys().m_spend_secret_key, sizeof(crypto::secret_key), (uint8_t *)&second, sizeof(crypto::secret_key)); - - sc_reduce32((uint8_t *)&second); + bool success = m_wallet->get_seed(electrum_words); - if (memcmp(second.data,m_wallet->get_account().get_keys().m_view_secret_key.data, sizeof(crypto::secret_key))==0) + if (success) { success_msg_writer(true) << "\nPLEASE NOTE: the following 24 words can be used to recover access to your wallet. Please write them down and store them somewhere safe and secure. Please do not store them in your email or on file storage services outside of your immediate control.\n"; std::cout << electrum_words << std::endl; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 86f2dc0d..da45771a 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -45,7 +45,13 @@ using namespace epee; #include "crypto/crypto.h" #include "serialization/binary_utils.h" #include "cryptonote_protocol/blobdatatype.h" +#include "crypto/electrum-words.h" +extern "C" +{ +#include "crypto/keccak.h" +#include "crypto/crypto-ops.h" +} using namespace cryptonote; namespace @@ -78,6 +84,18 @@ void wallet2::init(const std::string& daemon_address, uint64_t upper_transaction m_daemon_address = daemon_address; } //---------------------------------------------------------------------------------------------------- +bool wallet2::get_seed(std::string& electrum_words) +{ + crypto::ElectrumWords::bytes_to_words(get_account().get_keys().m_spend_secret_key, electrum_words); + + crypto::secret_key second; + keccak((uint8_t *)&get_account().get_keys().m_spend_secret_key, sizeof(crypto::secret_key), (uint8_t *)&second, sizeof(crypto::secret_key)); + + sc_reduce32((uint8_t *)&second); + + return memcmp(second.data,get_account().get_keys().m_view_secret_key.data, sizeof(crypto::secret_key)) == 0; +} +//---------------------------------------------------------------------------------------------------- void wallet2::process_new_transaction(const cryptonote::transaction& tx, uint64_t height) { process_unconfirmed(tx); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 4323404d..a6f4c5c1 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -151,6 +151,8 @@ namespace tools i_wallet2_callback* callback() const { return m_callback; } void callback(i_wallet2_callback* callback) { m_callback = callback; } + bool get_seed(std::string& electrum_words); + void refresh(); void refresh(uint64_t start_height, size_t & blocks_fetched); void refresh(uint64_t start_height, size_t & blocks_fetched, bool& received_money);