Skip to content

Commit 8781a1b

Browse files
committed
psbt: Include output pubkey in additional pubkeys to sign
In addition to the pubkeys in hd_keypaths and tap_bip32_keypaths, also see if the descriptor can produce a SigningProvider for the output pubkey. Also slightly refactors this area to reduce code duplication.
1 parent 323890d commit 8781a1b

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2502,25 +2502,38 @@ TransactionError DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction&
25022502
keys->Merge(std::move(*script_keys));
25032503
} else {
25042504
// Maybe there are pubkeys listed that we can sign for
2505-
script_keys = std::make_unique<FlatSigningProvider>();
2506-
for (const auto& pk_pair : input.hd_keypaths) {
2507-
const CPubKey& pubkey = pk_pair.first;
2508-
std::unique_ptr<FlatSigningProvider> pk_keys = GetSigningProvider(pubkey);
2509-
if (pk_keys) {
2510-
keys->Merge(std::move(*pk_keys));
2511-
}
2505+
std::vector<CPubKey> pubkeys;
2506+
2507+
// ECDSA Pubkeys
2508+
for (const auto& [pk, _] : input.hd_keypaths) {
2509+
pubkeys.push_back(pk);
2510+
}
2511+
2512+
// Taproot output pubkey
2513+
std::vector<std::vector<unsigned char>> sols;
2514+
if (Solver(script, sols) == TxoutType::WITNESS_V1_TAPROOT) {
2515+
sols[0].insert(sols[0].begin(), 0x02);
2516+
pubkeys.emplace_back(sols[0]);
2517+
sols[0][0] = 0x03;
2518+
pubkeys.emplace_back(sols[0]);
25122519
}
2520+
2521+
// Taproot pubkeys
25132522
for (const auto& pk_pair : input.m_tap_bip32_paths) {
25142523
const XOnlyPubKey& pubkey = pk_pair.first;
25152524
for (unsigned char prefix : {0x02, 0x03}) {
25162525
unsigned char b[33] = {prefix};
25172526
std::copy(pubkey.begin(), pubkey.end(), b + 1);
25182527
CPubKey fullpubkey;
25192528
fullpubkey.Set(b, b + 33);
2520-
std::unique_ptr<FlatSigningProvider> pk_keys = GetSigningProvider(fullpubkey);
2521-
if (pk_keys) {
2522-
keys->Merge(std::move(*pk_keys));
2523-
}
2529+
pubkeys.push_back(fullpubkey);
2530+
}
2531+
}
2532+
2533+
for (const auto& pubkey : pubkeys) {
2534+
std::unique_ptr<FlatSigningProvider> pk_keys = GetSigningProvider(pubkey);
2535+
if (pk_keys) {
2536+
keys->Merge(std::move(*pk_keys));
25242537
}
25252538
}
25262539
}

0 commit comments

Comments
 (0)