mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-06 11:13:02 +02:00
Merge #15368: Descriptor checksums
fd637be8d2Add checksums to descriptors.md (Pieter Wuille)be62903c41Make descriptor checksums mandatory in deriveaddresses and importmulti (Pieter Wuille)b52cb63688Add getdescriptorinfo to compute checksum (Pieter Wuille)3b40bff988Descriptor checksum (Pieter Wuille) Pull request description: This adds support for a descriptor-specific 8-character checksum. Descriptors may optionally be suffixed with a `#` plus these 8 checksum characters. Any descriptor that contains a `#` at the end must be followed by a valid checksum. If the `#` is missing entirely, it is valid without checksum. All RPCs are updated to report descriptors that include the checksum. On input, they are optional except in `deriveaddress` and `importmulti`, which require descriptors which include a checksum. A new RPC is also added to analyse descriptors (`getdescriptorinfo`), which can be used to compute the checksum for a descriptor without. Tree-SHA512: a8294b09155eb6c67fbc178b5e2d3fbc0e9bec8b6de57a13f8835550d51c2cb32a428b3c9a188ded42b454d594e9305edbd4797906b755de77a8f33c79165f6b
This commit is contained in:
@@ -143,6 +143,46 @@ static UniValue createmultisig(const JSONRPCRequest& request)
|
||||
return result;
|
||||
}
|
||||
|
||||
UniValue getdescriptorinfo(const JSONRPCRequest& request)
|
||||
{
|
||||
if (request.fHelp || request.params.size() != 1) {
|
||||
throw std::runtime_error(
|
||||
RPCHelpMan{"getdescriptorinfo",
|
||||
{"\nAnalyses a descriptor.\n"},
|
||||
{
|
||||
{"descriptor", RPCArg::Type::STR, RPCArg::Optional::NO, "The descriptor."},
|
||||
},
|
||||
RPCResult{
|
||||
"{\n"
|
||||
" \"descriptor\" : \"desc\", (string) The descriptor in canonical form, without private keys\n"
|
||||
" \"isrange\" : true|false, (boolean) Whether the descriptor is ranged\n"
|
||||
" \"issolvable\" : true|false, (boolean) Whether the descriptor is solvable\n"
|
||||
" \"hasprivatekeys\" : true|false, (boolean) Whether the input descriptor contained at least one private key\n"
|
||||
"}\n"
|
||||
},
|
||||
RPCExamples{
|
||||
"Analyse a descriptor\n" +
|
||||
HelpExampleCli("getdescriptorinfo", "\"wpkh([d34db33f/84h/0h/0h]0279be667ef9dcbbac55a06295Ce870b07029Bfcdb2dce28d959f2815b16f81798)\"")
|
||||
}}.ToString()
|
||||
);
|
||||
}
|
||||
|
||||
RPCTypeCheck(request.params, {UniValue::VSTR});
|
||||
|
||||
FlatSigningProvider provider;
|
||||
auto desc = Parse(request.params[0].get_str(), provider);
|
||||
if (!desc) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Invalid descriptor"));
|
||||
}
|
||||
|
||||
UniValue result(UniValue::VOBJ);
|
||||
result.pushKV("descriptor", desc->ToString());
|
||||
result.pushKV("isrange", desc->IsRange());
|
||||
result.pushKV("issolvable", desc->IsSolvable());
|
||||
result.pushKV("hasprivatekeys", provider.keys.size() > 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
UniValue deriveaddresses(const JSONRPCRequest& request)
|
||||
{
|
||||
if (request.fHelp || request.params.empty() || request.params.size() > 3) {
|
||||
@@ -167,7 +207,7 @@ UniValue deriveaddresses(const JSONRPCRequest& request)
|
||||
},
|
||||
RPCExamples{
|
||||
"First three native segwit receive addresses\n" +
|
||||
HelpExampleCli("deriveaddresses", "\"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)\" 0 2")
|
||||
HelpExampleCli("deriveaddresses", "\"wpkh([d34db33f/84h/0h/0h]xpub6DJ2dNUysrn5Vt36jH2KLBT2i1auw1tTSSomg8PhqNiUtx8QX2SvC9nrHu81fT41fvDUnhMjEzQgXnQjKEu3oaqMSzhSrHMxyyoEAmUHQbY/0/*)#trd0mf0l\" 0 2")
|
||||
}}.ToString()
|
||||
);
|
||||
}
|
||||
@@ -193,7 +233,7 @@ UniValue deriveaddresses(const JSONRPCRequest& request)
|
||||
}
|
||||
|
||||
FlatSigningProvider provider;
|
||||
auto desc = Parse(desc_str, provider);
|
||||
auto desc = Parse(desc_str, provider, /* require_checksum = */ true);
|
||||
if (!desc) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, strprintf("Invalid descriptor"));
|
||||
}
|
||||
@@ -564,6 +604,7 @@ static const CRPCCommand commands[] =
|
||||
{ "util", "validateaddress", &validateaddress, {"address"} },
|
||||
{ "util", "createmultisig", &createmultisig, {"nrequired","keys","address_type"} },
|
||||
{ "util", "deriveaddresses", &deriveaddresses, {"descriptor", "begin", "end"} },
|
||||
{ "util", "getdescriptorinfo", &getdescriptorinfo, {"descriptor"} },
|
||||
{ "util", "verifymessage", &verifymessage, {"address","signature","message"} },
|
||||
{ "util", "signmessagewithprivkey", &signmessagewithprivkey, {"privkey","message"} },
|
||||
|
||||
|
||||
Reference in New Issue
Block a user