fix(bdk): Remove extra taproot fields when finalizing Psbt
We currently allow removing `partial_sigs` from a finalized Psbt, which is relevant to non-taproot inputs, however taproot related Psbt fields were left in place despite the recommendation of BIP371 to remove them once the `final_script_witness` is constructed. This can cause confusion for parsers that encounter extra taproot metadata in an already satisfied input. Fix this by introducing a new member to SignOptions `remove_taproot_extras`, which when true will remove extra taproot related data from a Psbt upon successful finalization. This change makes removal of all taproot extras the default but configurable. test(wallet): Add test `test_taproot_remove_tapfields_after_finalize_sign_option` that checks various fields have been cleared for taproot Psbt `Input`s and `Output`s according to BIP371.
This commit is contained in:
@@ -1972,6 +1972,15 @@ impl<D> Wallet<D> {
|
||||
if sign_options.remove_partial_sigs {
|
||||
psbt_input.partial_sigs.clear();
|
||||
}
|
||||
if sign_options.remove_taproot_extras {
|
||||
// We just constructed the final witness, clear these fields.
|
||||
psbt_input.tap_key_sig = None;
|
||||
psbt_input.tap_script_sigs.clear();
|
||||
psbt_input.tap_scripts.clear();
|
||||
psbt_input.tap_key_origins.clear();
|
||||
psbt_input.tap_internal_key = None;
|
||||
psbt_input.tap_merkle_root = None;
|
||||
}
|
||||
}
|
||||
Err(_) => finished = false,
|
||||
}
|
||||
@@ -1980,6 +1989,12 @@ impl<D> Wallet<D> {
|
||||
}
|
||||
}
|
||||
|
||||
if finished && sign_options.remove_taproot_extras {
|
||||
for output in &mut psbt.outputs {
|
||||
output.tap_key_origins.clear();
|
||||
}
|
||||
}
|
||||
|
||||
Ok(finished)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user