mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
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.
This commit is contained in:
parent
323890d0d7
commit
8781a1b6bb
1 changed files with 24 additions and 11 deletions
|
@ -2502,14 +2502,23 @@ TransactionError DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction&
|
||||||
keys->Merge(std::move(*script_keys));
|
keys->Merge(std::move(*script_keys));
|
||||||
} else {
|
} else {
|
||||||
// Maybe there are pubkeys listed that we can sign for
|
// Maybe there are pubkeys listed that we can sign for
|
||||||
script_keys = std::make_unique<FlatSigningProvider>();
|
std::vector<CPubKey> pubkeys;
|
||||||
for (const auto& pk_pair : input.hd_keypaths) {
|
|
||||||
const CPubKey& pubkey = pk_pair.first;
|
// ECDSA Pubkeys
|
||||||
std::unique_ptr<FlatSigningProvider> pk_keys = GetSigningProvider(pubkey);
|
for (const auto& [pk, _] : input.hd_keypaths) {
|
||||||
if (pk_keys) {
|
pubkeys.push_back(pk);
|
||||||
keys->Merge(std::move(*pk_keys));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Taproot output pubkey
|
||||||
|
std::vector<std::vector<unsigned char>> sols;
|
||||||
|
if (Solver(script, sols) == TxoutType::WITNESS_V1_TAPROOT) {
|
||||||
|
sols[0].insert(sols[0].begin(), 0x02);
|
||||||
|
pubkeys.emplace_back(sols[0]);
|
||||||
|
sols[0][0] = 0x03;
|
||||||
|
pubkeys.emplace_back(sols[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Taproot pubkeys
|
||||||
for (const auto& pk_pair : input.m_tap_bip32_paths) {
|
for (const auto& pk_pair : input.m_tap_bip32_paths) {
|
||||||
const XOnlyPubKey& pubkey = pk_pair.first;
|
const XOnlyPubKey& pubkey = pk_pair.first;
|
||||||
for (unsigned char prefix : {0x02, 0x03}) {
|
for (unsigned char prefix : {0x02, 0x03}) {
|
||||||
|
@ -2517,10 +2526,14 @@ TransactionError DescriptorScriptPubKeyMan::FillPSBT(PartiallySignedTransaction&
|
||||||
std::copy(pubkey.begin(), pubkey.end(), b + 1);
|
std::copy(pubkey.begin(), pubkey.end(), b + 1);
|
||||||
CPubKey fullpubkey;
|
CPubKey fullpubkey;
|
||||||
fullpubkey.Set(b, b + 33);
|
fullpubkey.Set(b, b + 33);
|
||||||
std::unique_ptr<FlatSigningProvider> pk_keys = GetSigningProvider(fullpubkey);
|
pubkeys.push_back(fullpubkey);
|
||||||
if (pk_keys) {
|
}
|
||||||
keys->Merge(std::move(*pk_keys));
|
}
|
||||||
}
|
|
||||||
|
for (const auto& pubkey : pubkeys) {
|
||||||
|
std::unique_ptr<FlatSigningProvider> pk_keys = GetSigningProvider(pubkey);
|
||||||
|
if (pk_keys) {
|
||||||
|
keys->Merge(std::move(*pk_keys));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue