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

Function signmessagewithprivkey

src/rpc/misc.cpp:399–437  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397}
398
399static RPCHelpMan signmessagewithprivkey()
400{
401 return RPCHelpMan{"signmessagewithprivkey",
402 "\nSign a message with the private key of an address\n",
403 {
404 {"privkey", RPCArg::Type::STR, RPCArg::Optional::NO, "The private key to sign the message with."},
405 {"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message to create a signature of."},
406 },
407 RPCResult{
408 RPCResult::Type::STR, "signature", "The signature of the message encoded in base 64"
409 },
410 RPCExamples{
411 "\nCreate the signature\n"
412 + HelpExampleCli("signmessagewithprivkey", "\"privkey\" \"my message\"") +
413 "\nVerify the signature\n"
414 + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") +
415 "\nAs a JSON-RPC call\n"
416 + HelpExampleRpc("signmessagewithprivkey", "\"privkey\", \"my message\"")
417 },
418 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
419{
420 std::string strPrivkey = request.params[0].get_str();
421 std::string strMessage = request.params[1].get_str();
422
423 CKey key = DecodeSecret(strPrivkey);
424 if (!key.IsValid()) {
425 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid private key");
426 }
427
428 std::string signature;
429
430 if (!MessageSign(key, strMessage, signature)) {
431 throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Sign failed");
432 }
433
434 return signature;
435},
436 };
437}
438
439static RPCHelpMan setmocktime()
440{

Callers

nothing calls this directly

Calls 6

HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
DecodeSecretFunction · 0.85
JSONRPCErrorFunction · 0.85
MessageSignFunction · 0.85
IsValidMethod · 0.45

Tested by

no test coverage detected