MCPcopy Create free account
hub / github.com/bitcoinxt/bitcoinxt / verifymessage

Function verifymessage

src/rpcmisc.cpp:324–376  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

322}
323
324UniValue verifymessage(const UniValue& params, bool fHelp)
325{
326 if (fHelp || params.size() != 3)
327 throw runtime_error(
328 "verifymessage \"bitcoinaddress\" \"signature\" \"message\"\n"
329 "\nVerify a signed message\n"
330 "\nArguments:\n"
331 "1. \"bitcoinaddress\" (string, required) The bitcoin address to use for the signature.\n"
332 "2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n"
333 "3. \"message\" (string, required) The message that was signed.\n"
334 "\nResult:\n"
335 "true|false (boolean) If the signature is verified or not.\n"
336 "\nExamples:\n"
337 "\nUnlock the wallet for 30 seconds\n"
338 + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
339 "\nCreate the signature\n"
340 + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") +
341 "\nVerify the signature\n"
342 + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") +
343 "\nAs json rpc\n"
344 + HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"signature\", \"my message\"")
345 );
346
347 LOCK(cs_main);
348
349 string strAddress = params[0].get_str();
350 string strSign = params[1].get_str();
351 string strMessage = params[2].get_str();
352
353 CBitcoinAddress addr(strAddress);
354 if (!addr.IsValid())
355 throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address");
356
357 CKeyID keyID;
358 if (!addr.GetKeyID(keyID))
359 throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
360
361 bool fInvalid = false;
362 vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid);
363
364 if (fInvalid)
365 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding");
366
367 CHashWriter ss(SER_GETHASH, 0);
368 ss << strMessageMagic;
369 ss << strMessage;
370
371 CPubKey pubkey;
372 if (!pubkey.RecoverCompact(ss.GetHash(), vchSig))
373 return false;
374
375 return (pubkey.GetID() == keyID);
376}
377
378UniValue setmocktime(const UniValue& params, bool fHelp)
379{

Callers

nothing calls this directly

Calls 11

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
JSONRPCErrorFunction · 0.85
DecodeBase64Function · 0.85
get_strMethod · 0.80
GetKeyIDMethod · 0.80
RecoverCompactMethod · 0.80
GetIDMethod · 0.80
sizeMethod · 0.45
IsValidMethod · 0.45
GetHashMethod · 0.45

Tested by

no test coverage detected