From adad8d0a567b34c43796e9d06082423a04277e35 Mon Sep 17 00:00:00 2001 From: woodser Date: Tue, 2 Jul 2019 12:29:14 -0400 Subject: [PATCH] implement sign() and verify() --- src/wallet/MoneroWallet.cpp | 29 +++++++++++++++++++++++++++++ src/wallet/MoneroWallet.h | 36 ++++++++++++++++++------------------ 2 files changed, 47 insertions(+), 18 deletions(-) diff --git a/src/wallet/MoneroWallet.cpp b/src/wallet/MoneroWallet.cpp index 17e446b..e4a9c86 100644 --- a/src/wallet/MoneroWallet.cpp +++ b/src/wallet/MoneroWallet.cpp @@ -1322,6 +1322,35 @@ namespace monero { } } + string MoneroWallet::sign(const string& msg) const { + return wallet2->sign(msg); + } + + bool MoneroWallet::verify(const string& msg, const string& address, const string& signature) const { + + // validate and parse address or url + cryptonote::address_parse_info info; + string err; + if (!get_account_address_from_str_or_url(info, wallet2->nettype(), address, + [&err](const std::string &url, const std::vector &addresses, bool dnssec_valid)->std::string { + if (!dnssec_valid) { + err = std::string("Invalid DNSSEC for ") + url; + return {}; + } + if (addresses.empty()) { + err = std::string("No Monero address found at ") + url; + return {}; + } + return addresses[0]; + })) + { + throw runtime_error(err); + } + + // verify and return result + return wallet2->verify(msg, info.address, signature); + } + string MoneroWallet::createPaymentUri(const MoneroSendRequest& request) const { cout << "createPaymentUri()" << endl; diff --git a/src/wallet/MoneroWallet.h b/src/wallet/MoneroWallet.h index f6a5324..5b3c87b 100644 --- a/src/wallet/MoneroWallet.h +++ b/src/wallet/MoneroWallet.h @@ -791,24 +791,24 @@ namespace monero { */ void setTxNotes(const vector& txIds, const vector& notes); -// /** -// * Sign a message. -// * -// * @param msg is the message to sign -// * @return the signature -// */ -// public string sign(string msg); -// -// /** -// * Verify a signature on a message. -// * -// * @param msg is the signed message -// * @param address is the signing address -// * @param signature is the signature -// * @return true if the signature is good, false otherwise -// */ -// public boolean verify(string msg, string address, string signature); -// + /** + * Sign a message. + * + * @param msg is the message to sign + * @return the signature + */ + string sign(const string& msg) const; + + /** + * Verify a signature on a message. + * + * @param msg is the signed message + * @param address is the signing address + * @param signature is the signature + * @return true if the signature is good, false otherwise + */ + bool verify(const string& msg, const string& address, const string& signature) const; + // /** // * Get a transaction's secret key from its id. // *