Merge #829: initpegoutwallet: check for hardened derivation steps early

a7b41e1f7 initpegoutwallet: check for hardened derivation steps early (Gregory Sanders)

Pull request description:

  Before anything is written to wallet.

Tree-SHA512: 44d46740481aaf06a9ff774f5c0bfa750e522b19b5cf7beeae7c1e29652978f727dc04d7f95849595d6b5fbab6a743ed66ecc529e2f56b2e8c309b1100fc12a5
This commit is contained in:
Steven Roose 2020-03-04 15:54:58 +00:00
commit 29298ceeb6
No known key found for this signature in database
GPG key ID: 2F2A88D7F8D68E87

View file

@ -5136,6 +5136,19 @@ UniValue initpegoutwallet(const JSONRPCRequest& request)
throw JSONRPCError(RPC_INVALID_PARAMETER, "bitcoin_descriptor must be a ranged descriptor.");
}
// Check if we can actually generate addresses(catches hardened derivation steps etc) before
// writing to cache
UniValue address_list(UniValue::VARR);
for (int i = counter; i < counter+3; i++) {
std::vector<CScript> scripts;
if (!desc->Expand(i, provider, scripts, provider)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Could not generate lookahead addresses with descriptor. Are there hardened derivations after the xpub?");
}
CTxDestination destination;
ExtractDestination(scripts[0], destination);
address_list.push_back(EncodeParentDestination(destination));
}
// For our manual pattern matching, we don't want the checksum part.
auto checksum_char = bitcoin_desc.find('#');
if (checksum_char != std::string::npos) {
@ -5204,16 +5217,6 @@ UniValue initpegoutwallet(const JSONRPCRequest& request)
assert(len == 33);
assert(negatedpubkeybytes.size() == 33);
UniValue address_list(UniValue::VARR);
for (int i = counter; i < counter+3; i++) {
std::vector<CScript> scripts;
if (!desc->Expand(i, provider, scripts, provider)) {
throw JSONRPCError(RPC_WALLET_ERROR, "Could not generate lookahead addresses with descriptor. This is a bug.");
}
CTxDestination destination;
ExtractDestination(scripts[0], destination);
address_list.push_back(EncodeParentDestination(destination));
}
UniValue pak(UniValue::VOBJ);
pak.pushKV("pakentry", "pak=" + HexStr(negatedpubkeybytes) + ":" + HexStr(online_pubkey));
pak.pushKV("liquid_pak", HexStr(online_pubkey));