MCPcopy Create free account
hub / github.com/ElementsProject/elements / verifymessage

Function verifymessage

src/rpc/misc.cpp:350–397  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

348}
349
350static RPCHelpMan verifymessage()
351{
352 return RPCHelpMan{"verifymessage",
353 "Verify a signed message.",
354 {
355 {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to use for the signature."},
356 {"signature", RPCArg::Type::STR, RPCArg::Optional::NO, "The signature provided by the signer in base 64 encoding (see signmessage)."},
357 {"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message that was signed."},
358 },
359 RPCResult{
360 RPCResult::Type::BOOL, "", "If the signature is verified or not."
361 },
362 RPCExamples{
363 "\nUnlock the wallet for 30 seconds\n"
364 + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") +
365 "\nCreate the signature\n"
366 + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") +
367 "\nVerify the signature\n"
368 + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
369 "\nAs a JSON-RPC call\n"
370 + HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"signature\", \"my message\"")
371 },
372 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
373{
374 LOCK(cs_main);
375
376 std::string strAddress = request.params[0].get_str();
377 std::string strSign = request.params[1].get_str();
378 std::string strMessage = request.params[2].get_str();
379
380 switch (MessageVerify(strAddress, strSign, strMessage)) {
381 case MessageVerificationResult::ERR_INVALID_ADDRESS:
382 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address");
383 case MessageVerificationResult::ERR_ADDRESS_NO_KEY:
384 throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key");
385 case MessageVerificationResult::ERR_MALFORMED_SIGNATURE:
386 throw JSONRPCError(RPC_TYPE_ERROR, "Malformed base64 encoding");
387 case MessageVerificationResult::ERR_PUBKEY_NOT_RECOVERED:
388 case MessageVerificationResult::ERR_NOT_SIGNED:
389 return false;
390 case MessageVerificationResult::OK:
391 return true;
392 }
393
394 return false;
395},
396 };
397}
398
399static RPCHelpMan signmessagewithprivkey()
400{

Callers

nothing calls this directly

Calls 4

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
MessageVerifyFunction · 0.85
JSONRPCErrorFunction · 0.85

Tested by

no test coverage detected