From d64e5aa71936d86f91d3f45a9da0468f97078409 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Thu, 31 Oct 2019 14:09:19 +0000 Subject: wallet: allow message sign/verify for subaddresses --- src/simplewallet/simplewallet.cpp | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/simplewallet/simplewallet.cpp') diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 03693a57c..23452b0ca 100644 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -214,7 +214,7 @@ namespace const char* USAGE_GET_TX_NOTE("get_tx_note "); const char* USAGE_GET_DESCRIPTION("get_description"); const char* USAGE_SET_DESCRIPTION("set_description [free text note]"); - const char* USAGE_SIGN("sign "); + const char* USAGE_SIGN("sign [,] "); const char* USAGE_VERIFY("verify
"); const char* USAGE_EXPORT_KEY_IMAGES("export_key_images [all] "); const char* USAGE_IMPORT_KEY_IMAGES("import_key_images "); @@ -3356,7 +3356,7 @@ simple_wallet::simple_wallet() m_cmd_binder.set_handler("sign", boost::bind(&simple_wallet::on_command, this, &simple_wallet::sign, _1), tr(USAGE_SIGN), - tr("Sign the contents of a file.")); + tr("Sign the contents of a file with the given subaddress (or the main address if not specified)")); m_cmd_binder.set_handler("verify", boost::bind(&simple_wallet::on_command, this, &simple_wallet::verify, _1), tr(USAGE_VERIFY), @@ -9593,7 +9593,7 @@ bool simple_wallet::sign(const std::vector &args) fail_msg_writer() << tr("command not supported by HW wallet"); return true; } - if (args.size() != 1) + if (args.size() != 1 && args.size() != 2) { PRINT_USAGE(USAGE_SIGN); return true; @@ -9609,7 +9609,20 @@ bool simple_wallet::sign(const std::vector &args) return true; } - std::string filename = args[0]; + subaddress_index index{0, 0}; + if (args.size() == 2) + { + unsigned int a, b; + if (sscanf(args[0].c_str(), "%u,%u", &a, &b) != 2) + { + fail_msg_writer() << tr("Invalid subaddress index format"); + return true; + } + index.major = a; + index.minor = b; + } + + const std::string &filename = args.back(); std::string data; bool r = m_wallet->load_from_file(filename, data); if (!r) @@ -9620,7 +9633,7 @@ bool simple_wallet::sign(const std::vector &args) SCOPED_WALLET_UNLOCK(); - std::string signature = m_wallet->sign(data); + std::string signature = m_wallet->sign(data, index); success_msg_writer() << signature; return true; } -- cgit v1.2.3