Skip to content

Commit c3a7f51

Browse files
committed
Move verifymessage from rpcwallet to rpcmisc
Enables it in --disable-wallet compiles.
1 parent 723a03d commit c3a7f51

File tree

3 files changed

+52
-54
lines changed

3 files changed

+52
-54
lines changed

src/rpcmisc.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,55 @@ Value createmultisig(const Array& params, bool fHelp)
272272
return result;
273273
}
274274

275+
Value verifymessage(const Array& params, bool fHelp)
276+
{
277+
if (fHelp || params.size() != 3)
278+
throw runtime_error(
279+
"verifymessage \"bitcoinaddress\" \"signature\" \"message\"\n"
280+
"\nVerify a signed message\n"
281+
"\nArguments:\n"
282+
"1. \"bitcoinaddress\" (string, required) The bitcoin address to use for the signature.\n"
283+
"2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n"
284+
"3. \"message\" (string, required) The message that was signed.\n"
285+
"\nResult:\n"
286+
"true|false (boolean) If the signature is verified or not.\n"
287+
"\nExamples:\n"
288+
"\nUnlock the wallet for 30 seconds\n"
289+
+ HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
290+
"\nCreate the signature\n"
291+
+ HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") +
292+
"\nVerify the signature\n"
293+
+ HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") +
294+
"\nAs json rpc\n"
295+
+ HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"signature\", \"my message\"")
296+
);
297+
298+
string strAddress = params[0].get_str();
299+
string strSign = params[1].get_str();
300+
string strMessage = params[2].get_str();
301+
302+
CBitcoinAddress addr(strAddress);
303+
if (!addr.IsValid())
304+
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
305+
306+
CKeyID keyID;
307+
if (!addr.GetKeyID(keyID))
308+
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
309+
310+
bool fInvalid = false;
311+
vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid);
312+
313+
if (fInvalid)
314+
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
315+
316+
CHashWriter ss(SER_GETHASH, 0);
317+
ss << strMessageMagic;
318+
ss << strMessage;
319+
320+
CPubKey pubkey;
321+
if (!pubkey.RecoverCompact(ss.GetHash(), vchSig))
322+
return false;
323+
324+
return (pubkey.GetID() == keyID);
325+
}
275326

src/rpcserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ static const CRPCCommand vRPCCommands[] =
254254
{ "submitblock", &submitblock, false, false, false },
255255
{ "validateaddress", &validateaddress, true, false, false },
256256
{ "createmultisig", &createmultisig, true, true , false },
257+
{ "verifymessage", &verifymessage, false, false, false },
257258

258259
#ifdef ENABLE_WALLET
259260
/* Wallet */
@@ -283,7 +284,6 @@ static const CRPCCommand vRPCCommands[] =
283284
{ "listtransactions", &listtransactions, false, false, true },
284285
{ "listaddressgroupings", &listaddressgroupings, false, false, true },
285286
{ "signmessage", &signmessage, false, false, true },
286-
{ "verifymessage", &verifymessage, false, false, false },
287287
{ "listaccounts", &listaccounts, false, false, true },
288288
{ "listsinceblock", &listsinceblock, false, false, true },
289289
{ "dumpprivkey", &dumpprivkey, true, false, true },

src/rpcwallet.cpp

Lines changed: 0 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -441,59 +441,6 @@ Value signmessage(const Array& params, bool fHelp)
441441
return EncodeBase64(&vchSig[0], vchSig.size());
442442
}
443443

444-
Value verifymessage(const Array& params, bool fHelp)
445-
{
446-
if (fHelp || params.size() != 3)
447-
throw runtime_error(
448-
"verifymessage \"bitcoinaddress\" \"signature\" \"message\"\n"
449-
"\nVerify a signed message\n"
450-
"\nArguments:\n"
451-
"1. \"bitcoinaddress\" (string, required) The bitcoin address to use for the signature.\n"
452-
"2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n"
453-
"3. \"message\" (string, required) The message that was signed.\n"
454-
"\nResult:\n"
455-
"true|false (boolean) If the signature is verified or not.\n"
456-
"\nExamples:\n"
457-
"\nUnlock the wallet for 30 seconds\n"
458-
+ HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
459-
"\nCreate the signature\n"
460-
+ HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") +
461-
"\nVerify the signature\n"
462-
+ HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") +
463-
"\nAs json rpc\n"
464-
+ HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"signature\", \"my message\"")
465-
);
466-
467-
string strAddress = params[0].get_str();
468-
string strSign = params[1].get_str();
469-
string strMessage = params[2].get_str();
470-
471-
CBitcoinAddress addr(strAddress);
472-
if (!addr.IsValid())
473-
throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
474-
475-
CKeyID keyID;
476-
if (!addr.GetKeyID(keyID))
477-
throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
478-
479-
bool fInvalid = false;
480-
vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid);
481-
482-
if (fInvalid)
483-
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
484-
485-
CHashWriter ss(SER_GETHASH, 0);
486-
ss << strMessageMagic;
487-
ss << strMessage;
488-
489-
CPubKey pubkey;
490-
if (!pubkey.RecoverCompact(ss.GetHash(), vchSig))
491-
return false;
492-
493-
return (pubkey.GetID() == keyID);
494-
}
495-
496-
497444
Value getreceivedbyaddress(const Array& params, bool fHelp)
498445
{
499446
if (fHelp || params.size() < 1 || params.size() > 2)

0 commit comments

Comments
 (0)