Skip to content

Commit 609ebc2

Browse files
committed
add remove_partial_sigs to SignOptions
1 parent 17d0ae0 commit 609ebc2

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222
- Signing Taproot PSBTs (key spend and script spend)
2323
- Support for `tr()` descriptors in the `descriptor!()` macro
2424
- Add support for Bitcoin Core 23.0 when using the `rpc` blockchain
25+
- Added `remove_partial_sigs` to `SignOptions`
2526

2627
## [v0.18.0] - [v0.17.0]
2728

src/wallet/mod.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,9 @@ where
11611161
let psbt_input = &mut psbt.inputs[n];
11621162
psbt_input.final_script_sig = Some(tmp_input.script_sig);
11631163
psbt_input.final_script_witness = Some(tmp_input.witness);
1164+
if sign_options.remove_partial_sigs {
1165+
psbt_input.partial_sigs.clear();
1166+
}
11641167
}
11651168
Err(e) => {
11661169
debug!("satisfy error {:?} for input {}", e, n);
@@ -3878,6 +3881,36 @@ pub(crate) mod test {
38783881
)
38793882
}
38803883

3884+
#[test]
3885+
fn test_remove_partial_sigs_after_finalize_sign_option() {
3886+
let (wallet, _, _) = get_funded_wallet("wpkh(tprv8ZgxMBicQKsPd3EupYiPRhaMooHKUHJxNsTfYuScep13go8QFfHdtkG9nRkFGb7busX4isf6X9dURGCoKgitaApQ6MupRhZMcELAxTBRJgS/*)");
3887+
3888+
for remove_partial_sigs in &[true, false] {
3889+
let addr = wallet.get_address(New).unwrap();
3890+
let mut builder = wallet.build_tx();
3891+
builder.drain_to(addr.script_pubkey()).drain_wallet();
3892+
let mut psbt = builder.finish().unwrap().0;
3893+
3894+
assert!(wallet
3895+
.sign(
3896+
&mut psbt,
3897+
SignOptions {
3898+
remove_partial_sigs: *remove_partial_sigs,
3899+
..Default::default()
3900+
},
3901+
)
3902+
.unwrap());
3903+
3904+
psbt.inputs.iter().for_each(|input| {
3905+
if *remove_partial_sigs {
3906+
assert!(input.partial_sigs.is_empty())
3907+
} else {
3908+
assert!(!input.partial_sigs.is_empty())
3909+
}
3910+
});
3911+
}
3912+
}
3913+
38813914
#[test]
38823915
fn test_sign_nonstandard_sighash() {
38833916
let sighash = EcdsaSighashType::NonePlusAnyoneCanPay;

src/wallet/signer.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,10 @@ pub struct SignOptions {
667667
///
668668
/// Defaults to `false` which will only allow signing using `SIGHASH_ALL`.
669669
pub allow_all_sighashes: bool,
670+
/// Whether to remove partial_sigs from psbt inputs while finalizing psbt.
671+
///
672+
/// Defaults to `true` which will remove partial_sigs after finalizing.
673+
pub remove_partial_sigs: bool,
670674
}
671675

672676
#[allow(clippy::derivable_impls)]
@@ -676,6 +680,7 @@ impl Default for SignOptions {
676680
trust_witness_utxo: false,
677681
assume_height: None,
678682
allow_all_sighashes: false,
683+
remove_partial_sigs: true,
679684
}
680685
}
681686
}

0 commit comments

Comments
 (0)