aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2014-08-05 09:43:39 +0200
committerRiccardo Spagni <ric@spagni.net>2014-08-05 09:43:39 +0200
commit43c013a57f3bd5e0c70695c93ca6a76b78043288 (patch)
tree0a859060427ffd9881385d7e27eff0547507ffb0
parentMerge pull request #81 from tewinget/restore-fix (diff)
parentadded view_key to wallet RPC command query_key (diff)
downloadmonero-43c013a57f3bd5e0c70695c93ca6a76b78043288.tar.xz
Merge pull request #86 from jakoblind/seed
Query view key and seed
-rw-r--r--src/simplewallet/simplewallet.cpp28
-rw-r--r--src/simplewallet/simplewallet.h2
-rw-r--r--src/wallet/wallet2.cpp18
-rw-r--r--src/wallet/wallet2.h2
-rw-r--r--src/wallet/wallet_rpc_server.cpp22
-rw-r--r--src/wallet/wallet_rpc_server.h4
-rw-r--r--src/wallet/wallet_rpc_server_commands_defs.h22
7 files changed, 97 insertions, 1 deletions
diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp
index 4bb5389e4..960b1be9d 100644
--- a/src/simplewallet/simplewallet.cpp
+++ b/src/simplewallet/simplewallet.cpp
@@ -188,6 +188,30 @@ std::string simple_wallet::get_commands_str()
return ss.str();
}
+bool simple_wallet::viewkey(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
+{
+ success_msg_writer() << string_tools::pod_to_hex(m_wallet->get_account().get_keys().m_view_secret_key) << std::endl;
+
+ return true;
+}
+
+bool simple_wallet::seed(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
+{
+ std::string electrum_words;
+ bool success = m_wallet->get_seed(electrum_words);
+
+ 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;
+ }
+ else
+ {
+ fail_msg_writer() << "The wallet is non-deterministic. Cannot display seed.";
+ }
+ return true;
+}
+
bool simple_wallet::help(const std::vector<std::string> &args/* = std::vector<std::string>()*/)
{
success_msg_writer() << get_commands_str();
@@ -210,6 +234,8 @@ simple_wallet::simple_wallet()
m_cmd_binder.set_handler("set_log", boost::bind(&simple_wallet::set_log, this, _1), "set_log <level> - Change current log detalization level, <level> is a number 0-4");
m_cmd_binder.set_handler("address", boost::bind(&simple_wallet::print_address, this, _1), "Show current wallet public address");
m_cmd_binder.set_handler("save", boost::bind(&simple_wallet::save, this, _1), "Save wallet synchronized data");
+ m_cmd_binder.set_handler("viewkey", boost::bind(&simple_wallet::viewkey, this, _1), "Get viewkey");
+ m_cmd_binder.set_handler("seed", boost::bind(&simple_wallet::seed, this, _1), "Get deterministic seed");
m_cmd_binder.set_handler("help", boost::bind(&simple_wallet::help, this, _1), "Show this help");
}
//----------------------------------------------------------------------------------------------------
@@ -437,7 +463,7 @@ bool simple_wallet::new_wallet(const string &wallet_file, const std::string& pas
if (!two_random)
{
- 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. You will not be able to view these words again, so it is imperative to make note of them now.\n";
+ 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;
}
success_msg_writer() << "**********************************************************************";
diff --git a/src/simplewallet/simplewallet.h b/src/simplewallet/simplewallet.h
index 6214f7a5c..41197b4bb 100644
--- a/src/simplewallet/simplewallet.h
+++ b/src/simplewallet/simplewallet.h
@@ -70,6 +70,8 @@ namespace cryptonote
bool open_wallet(const std::string &wallet_file, const std::string& password);
bool close_wallet();
+ bool viewkey(const std::vector<std::string> &args = std::vector<std::string>());
+ bool seed(const std::vector<std::string> &args = std::vector<std::string>());
bool help(const std::vector<std::string> &args = std::vector<std::string>());
bool start_mining(const std::vector<std::string> &args);
bool stop_mining(const std::vector<std::string> &args);
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 86f2dc0d5..da45771af 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 4323404d3..a6f4c5c17 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);
diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp
index 063716a9e..fa0a5445e 100644
--- a/src/wallet/wallet_rpc_server.cpp
+++ b/src/wallet/wallet_rpc_server.cpp
@@ -403,4 +403,26 @@ namespace tools
return true;
}
//------------------------------------------------------------------------------------------------------------------------------
+ bool wallet_rpc_server::on_query_key(const wallet_rpc::COMMAND_RPC_QUERY_KEY::request& req, wallet_rpc::COMMAND_RPC_QUERY_KEY::response& res, epee::json_rpc::error& er, connection_context& cntx)
+ {
+ if (req.key_type.compare("mnemonic") == 0)
+ {
+ if (!m_wallet.get_seed(res.key))
+ {
+ er.message = "The wallet is non-deterministic. Cannot display seed.";
+ return false;
+ }
+ }
+ else if(req.key_type.compare("view_key") == 0)
+ {
+ res.key = string_tools::pod_to_hex(m_wallet.get_account().get_keys().m_view_secret_key);
+ }
+ else
+ {
+ er.message = "key_type " + req.key_type + " not found";
+ return false;
+ }
+
+ return true;
+ }
}
diff --git a/src/wallet/wallet_rpc_server.h b/src/wallet/wallet_rpc_server.h
index 8fc6b092b..6f52e87ba 100644
--- a/src/wallet/wallet_rpc_server.h
+++ b/src/wallet/wallet_rpc_server.h
@@ -69,6 +69,7 @@ namespace tools
MAP_JON_RPC_WE("get_payments", on_get_payments, wallet_rpc::COMMAND_RPC_GET_PAYMENTS)
MAP_JON_RPC_WE("get_bulk_payments", on_get_bulk_payments, wallet_rpc::COMMAND_RPC_GET_BULK_PAYMENTS)
MAP_JON_RPC_WE("incoming_transfers", on_incoming_transfers, wallet_rpc::COMMAND_RPC_INCOMING_TRANSFERS)
+ MAP_JON_RPC_WE("query_key", on_query_key, wallet_rpc::COMMAND_RPC_QUERY_KEY)
END_JSON_RPC_MAP()
END_URI_MAP2()
@@ -85,6 +86,9 @@ namespace tools
bool handle_command_line(const boost::program_options::variables_map& vm);
+ //json rpc v2
+ bool on_query_key(const wallet_rpc::COMMAND_RPC_QUERY_KEY::request& req, wallet_rpc::COMMAND_RPC_QUERY_KEY::response& res, epee::json_rpc::error& er, connection_context& cntx);
+
wallet2& m_wallet;
std::string m_port;
std::string m_bind_ip;
diff --git a/src/wallet/wallet_rpc_server_commands_defs.h b/src/wallet/wallet_rpc_server_commands_defs.h
index 146e84cb2..48f8ec2a5 100644
--- a/src/wallet/wallet_rpc_server_commands_defs.h
+++ b/src/wallet/wallet_rpc_server_commands_defs.h
@@ -257,6 +257,28 @@ namespace wallet_rpc
END_KV_SERIALIZE_MAP()
};
};
+
+ //JSON RPC V2
+ struct COMMAND_RPC_QUERY_KEY
+ {
+ struct request
+ {
+ std::string key_type;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(key_type)
+ END_KV_SERIALIZE_MAP()
+ };
+
+ struct response
+ {
+ std::string key;
+
+ BEGIN_KV_SERIALIZE_MAP()
+ KV_SERIALIZE(key)
+ END_KV_SERIALIZE_MAP()
+ };
+ };
}
}