| 564 | } |
| 565 | |
| 566 | UniValue verifymessage(const UniValue& params, bool fHelp) |
| 567 | { |
| 568 | if (fHelp || params.size() != 3) |
| 569 | throw runtime_error( |
| 570 | "verifymessage \"luxaddress\" \"signature\" \"message\"\n" |
| 571 | "\nVerify a signed message\n" |
| 572 | "\nArguments:\n" |
| 573 | "1. \"luxaddress\" (string, required) The lux address to use for the signature.\n" |
| 574 | "2. \"signature\" (string, required) The signature provided by the signer in base 64 encoding (see signmessage).\n" |
| 575 | "3. \"message\" (string, required) The message that was signed.\n" |
| 576 | "\nResult:\n" |
| 577 | "true|false (boolean) If the signature is verified or not.\n" |
| 578 | "\nExamples:\n" |
| 579 | "\nUnlock the wallet for 30 seconds\n" + |
| 580 | HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + |
| 581 | "\nCreate the signature\n" + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"my message\"") + |
| 582 | "\nVerify the signature\n" + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\" \"signature\" \"my message\"") + |
| 583 | "\nAs json rpc\n" + HelpExampleRpc("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XZ\", \"signature\", \"my message\"")); |
| 584 | |
| 585 | LOCK(cs_main); |
| 586 | string strAddress = params[0].get_str(); |
| 587 | string strSign = params[1].get_str(); |
| 588 | string strMessage = params[2].get_str(); |
| 589 | |
| 590 | CTxDestination destination = DecodeDestination(strAddress); |
| 591 | if (!IsValidDestination(destination)) |
| 592 | throw JSONRPCError(RPC_TYPE_ERROR, "Invalid address"); |
| 593 | |
| 594 | const CKeyID *keyID = boost::get<CKeyID>(&destination); |
| 595 | if (!keyID) |
| 596 | throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); |
| 597 | |
| 598 | bool fInvalid = false; |
| 599 | vector<unsigned char> vchSig = DecodeBase64(strSign.c_str(), &fInvalid); |
| 600 | |
| 601 | if (fInvalid) |
| 602 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Malformed base64 encoding"); |
| 603 | |
| 604 | CHashWriter ss(SER_GETHASH, 0); |
| 605 | ss << strMessageMagic; |
| 606 | ss << strMessage; |
| 607 | |
| 608 | CPubKey pubkey; |
| 609 | if (!pubkey.RecoverCompact(ss.GetHash(), vchSig)) |
| 610 | return false; |
| 611 | |
| 612 | return (pubkey.GetID() == *keyID); |
| 613 | } |
| 614 | |
| 615 | UniValue setmocktime(const UniValue& params, bool fHelp) |
| 616 | { |
nothing calls this directly
no test coverage detected