|
20 | 20 | #include <script/sign.h> |
21 | 21 | #include <util/bip32.h> |
22 | 22 | #include <util/fees.h> |
23 | | -#include <util/message.h> // For MessageSign() |
24 | 23 | #include <util/moneystr.h> |
25 | 24 | #include <util/string.h> |
26 | 25 | #include <util/system.h> |
|
48 | 47 | using interfaces::FoundBlock; |
49 | 48 |
|
50 | 49 | static const std::string WALLET_ENDPOINT_BASE = "/wallet/"; |
51 | | -static const std::string HELP_REQUIRING_PASSPHRASE{"\nRequires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.\n"}; |
| 50 | +const std::string HELP_REQUIRING_PASSPHRASE{"\nRequires wallet passphrase to be set with walletpassphrase call if wallet is encrypted.\n"}; |
52 | 51 |
|
53 | 52 | static inline bool GetAvoidReuseFlag(const CWallet& wallet, const UniValue& param) { |
54 | 53 | bool can_avoid_reuse = wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE); |
@@ -612,63 +611,6 @@ static RPCHelpMan listaddressgroupings() |
612 | 611 | }; |
613 | 612 | } |
614 | 613 |
|
615 | | -static RPCHelpMan signmessage() |
616 | | -{ |
617 | | - return RPCHelpMan{"signmessage", |
618 | | - "\nSign a message with the private key of an address" + |
619 | | - HELP_REQUIRING_PASSPHRASE, |
620 | | - { |
621 | | - {"address", RPCArg::Type::STR, RPCArg::Optional::NO, "The bitcoin address to use for the private key."}, |
622 | | - {"message", RPCArg::Type::STR, RPCArg::Optional::NO, "The message to create a signature of."}, |
623 | | - }, |
624 | | - RPCResult{ |
625 | | - RPCResult::Type::STR, "signature", "The signature of the message encoded in base 64" |
626 | | - }, |
627 | | - RPCExamples{ |
628 | | - "\nUnlock the wallet for 30 seconds\n" |
629 | | - + HelpExampleCli("walletpassphrase", "\"mypassphrase\" 30") + |
630 | | - "\nCreate the signature\n" |
631 | | - + HelpExampleCli("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"my message\"") + |
632 | | - "\nVerify the signature\n" |
633 | | - + HelpExampleCli("verifymessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\" \"signature\" \"my message\"") + |
634 | | - "\nAs a JSON-RPC call\n" |
635 | | - + HelpExampleRpc("signmessage", "\"1D1ZrZNe3JUo7ZycKEYQQiQAWd9y54F4XX\", \"my message\"") |
636 | | - }, |
637 | | - [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue |
638 | | -{ |
639 | | - const std::shared_ptr<const CWallet> pwallet = GetWalletForJSONRPCRequest(request); |
640 | | - if (!pwallet) return NullUniValue; |
641 | | - |
642 | | - LOCK(pwallet->cs_wallet); |
643 | | - |
644 | | - EnsureWalletIsUnlocked(*pwallet); |
645 | | - |
646 | | - std::string strAddress = request.params[0].get_str(); |
647 | | - std::string strMessage = request.params[1].get_str(); |
648 | | - |
649 | | - CTxDestination dest = DecodeDestination(strAddress); |
650 | | - if (!IsValidDestination(dest)) { |
651 | | - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid address"); |
652 | | - } |
653 | | - |
654 | | - const PKHash* pkhash = std::get_if<PKHash>(&dest); |
655 | | - if (!pkhash) { |
656 | | - throw JSONRPCError(RPC_TYPE_ERROR, "Address does not refer to key"); |
657 | | - } |
658 | | - |
659 | | - std::string signature; |
660 | | - SigningResult err = pwallet->SignMessage(strMessage, *pkhash, signature); |
661 | | - if (err == SigningResult::SIGNING_FAILED) { |
662 | | - throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, SigningResultString(err)); |
663 | | - } else if (err != SigningResult::OK){ |
664 | | - throw JSONRPCError(RPC_WALLET_ERROR, SigningResultString(err)); |
665 | | - } |
666 | | - |
667 | | - return signature; |
668 | | -}, |
669 | | - }; |
670 | | -} |
671 | | - |
672 | 614 | static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet) |
673 | 615 | { |
674 | 616 | std::set<CTxDestination> address_set; |
@@ -4860,6 +4802,7 @@ RPCHelpMan removeprunedfunds(); |
4860 | 4802 | RPCHelpMan importmulti(); |
4861 | 4803 | RPCHelpMan importdescriptors(); |
4862 | 4804 | RPCHelpMan listdescriptors(); |
| 4805 | +RPCHelpMan signmessage(); |
4863 | 4806 |
|
4864 | 4807 | Span<const CRPCCommand> GetWalletRPCCommands() |
4865 | 4808 | { |
|
0 commit comments