Skip to content

Commit 73e41b4

Browse files
committed
Expose psbt malleable API
1 parent 8aec456 commit 73e41b4

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/psbt/finalizer.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,27 @@ pub fn interpreter_check<C: secp256k1::Verification>(
242242
/// For satisfaction of individual inputs, use the satisfy API.
243243
/// This function also performs a sanity interpreter check on the
244244
/// finalized psbt which involves checking the signatures/ preimages/timelocks.
245+
/// The functions fails it is not possible to satisfy any of the inputs non-malleably
246+
/// See [finalize_mall] if you want to allow malleable satisfactions
245247
pub fn finalize<C: secp256k1::Verification>(
246248
psbt: &mut Psbt,
247249
secp: &Secp256k1<C>,
250+
) -> Result<(), super::Error> {
251+
finalize_helper(psbt, secp, false)
252+
}
253+
254+
/// Same as [finalize], but allows for malleable satisfactions
255+
pub fn finalize_mall<C: secp256k1::Verification>(
256+
psbt: &mut Psbt,
257+
secp: &Secp256k1<C>,
258+
) -> Result<(), super::Error> {
259+
finalize_helper(psbt, secp, true)
260+
}
261+
262+
pub fn finalize_helper<C: secp256k1::Verification>(
263+
psbt: &mut Psbt,
264+
secp: &Secp256k1<C>,
265+
allow_mall: bool,
248266
) -> Result<(), super::Error> {
249267
sanity_check(psbt)?;
250268

@@ -303,9 +321,12 @@ pub fn finalize<C: secp256k1::Verification>(
303321
let desc = get_descriptor(&psbt, index).map_err(|e| Error::InputError(e, index))?;
304322

305323
//generate the satisfaction witness and scriptsig
306-
let (witness, script_sig) = desc
307-
.get_satisfaction(PsbtInputSatisfier::new(&psbt, index))
308-
.map_err(|e| Error::InputError(InputError::MiniscriptError(e), index))?;
324+
let (witness, script_sig) = if !allow_mall {
325+
desc.get_satisfaction(PsbtInputSatisfier::new(&psbt, index))
326+
} else {
327+
desc.get_satisfaction_mall(PsbtInputSatisfier::new(&psbt, index))
328+
}
329+
.map_err(|e| Error::InputError(InputError::MiniscriptError(e), index))?;
309330

310331
let input = &mut psbt.inputs[index];
311332
//Fill in the satisfactions

src/psbt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use {BitcoinSig, Preimage32};
3535
use {MiniscriptKey, ToPublicKey};
3636

3737
mod finalizer;
38-
pub use self::finalizer::{finalize, interpreter_check};
38+
pub use self::finalizer::{finalize, finalize_mall, interpreter_check};
3939

4040
/// Error type for Pbst Input
4141
#[derive(Debug)]

0 commit comments

Comments
 (0)