| 15 | #include <string> |
| 16 | |
| 17 | static RPCMethod verifymessage() |
| 18 | { |
| 19 | return RPCMethod{"verifymessage", |
| 20 | "Verify a signed message.", |
| 21 | { |
| 22 | {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to use for the signature."}, |
| 23 | {"signature", RPCArg::Type::STR, RPCArg::Optional::NO, "The signature provided by the signer in base 64 encoding (see signmessage)."}, |
| 24 | {"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message that was signed."}, |
| 25 | }, |
| 26 | RPCResult{ |
| 27 | RPCResult::Type::BOOL, "", "If the signature is verified or not." |
| 28 | }, |
| 29 | RPCExamples{ |
| 30 | "\nUnlock the wallet for 30 seconds\n" |
| 31 | + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + |
| 32 | "\nCreate the signature\n" |
| 33 | + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") + |
| 34 | "\nVerify the signature\n" |
| 35 | + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") + |
| 36 | "\nAs a JSON-RPC call\n" |
| 37 | + HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"signature\", \"my message\"") |
| 38 | }, |
| 39 | [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue |
| 40 | { |
| 41 | switch (MessageVerify(std::string{self.Arg<std::string_view>("address")}, |
| 42 | std::string{self.Arg<std::string_view>("signature")}, |
| 43 | std::string{self.Arg<std::string_view>("message")})) { |
| 44 | case MessageVerificationResult::ERR_INVALID_ADDRESS: |
| 45 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); |
| 46 | case MessageVerificationResult::ERR_ADDRESS_NO_KEY: |
| 47 | throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); |
| 48 | case MessageVerificationResult::ERR_MALFORMED_SIGNATURE: |
| 49 | throw JSONRPCError(RPC_TYPE_ERROR, "Malformed base64 encoding"); |
| 50 | case MessageVerificationResult::ERR_PUBKEY_NOT_RECOVERED: |
| 51 | case MessageVerificationResult::ERR_NOT_SIGNED: |
| 52 | return false; |
| 53 | case MessageVerificationResult::OK: |
| 54 | return true; |
| 55 | } |
| 56 | |
| 57 | return false; |
| 58 | }, |
| 59 | }; |
| 60 | } |
| 61 | |
| 62 | static RPCMethod signmessagewithprivkey() |
| 63 | { |
nothing calls this directly
no test coverage detected