implement sign() and verify()

This commit is contained in:
woodser
2019-07-02 12:29:14 -04:00
parent 0bc38afa99
commit adad8d0a56
2 changed files with 47 additions and 18 deletions
+29
View File
@@ -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<std::string> &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;
+18 -18
View File
@@ -791,24 +791,24 @@ namespace monero {
*/
void setTxNotes(const vector<string>& txIds, const vector<string>& 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.
// *