Skip to content

Commit c267633

Browse files
Add psbt preimage satisfaction logic
Improving PSBT preimage satisfation Co-authored-by: Dr Maxim Orlovsky <orlovsky@pandoracore.com>
1 parent 4ab7a7c commit c267633

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

src/psbt/mod.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,16 @@
2222
use std::{error, fmt};
2323

2424
use bitcoin;
25+
use bitcoin::hashes::{hash160, ripemd160, sha256, sha256d};
2526
use bitcoin::secp256k1::{self, Secp256k1};
2627
use bitcoin::util::psbt::PartiallySignedTransaction as Psbt;
2728
use bitcoin::Script;
2829

2930
use interpreter;
3031
use miniscript::limits::SEQUENCE_LOCKTIME_DISABLE_FLAG;
3132
use miniscript::satisfy::{bitcoinsig_from_rawsig, After, Older};
32-
use BitcoinSig;
3333
use Satisfier;
34+
use {BitcoinSig, Preimage32};
3435
use {MiniscriptKey, ToPublicKey};
3536

3637
mod finalizer;
@@ -279,6 +280,44 @@ impl<'psbt, Pk: MiniscriptKey + ToPublicKey> Satisfier<Pk> for PsbtInputSatisfie
279280
<Satisfier<Pk>>::check_older(&Older(seq), n)
280281
}
281282
}
283+
284+
fn lookup_hash160(&self, h: hash160::Hash) -> Option<Preimage32> {
285+
self.psbt.inputs[self.index]
286+
.hash160_preimages
287+
.get(&h)
288+
.and_then(try_vec_as_preimage32)
289+
}
290+
291+
fn lookup_sha256(&self, h: sha256::Hash) -> Option<Preimage32> {
292+
self.psbt.inputs[self.index]
293+
.sha256_preimages
294+
.get(&h)
295+
.and_then(try_vec_as_preimage32)
296+
}
297+
298+
fn lookup_hash256(&self, h: sha256d::Hash) -> Option<Preimage32> {
299+
self.psbt.inputs[self.index]
300+
.hash256_preimages
301+
.get(&h)
302+
.and_then(try_vec_as_preimage32)
303+
}
304+
305+
fn lookup_ripemd160(&self, h: ripemd160::Hash) -> Option<Preimage32> {
306+
self.psbt.inputs[self.index]
307+
.ripemd160_preimages
308+
.get(&h)
309+
.and_then(try_vec_as_preimage32)
310+
}
311+
}
312+
313+
fn try_vec_as_preimage32(vec: &Vec<u8>) -> Option<Preimage32> {
314+
if vec.len() == 32 {
315+
let mut arr = [0u8; 32];
316+
arr.copy_from_slice(&vec);
317+
Some(arr)
318+
} else {
319+
None
320+
}
282321
}
283322

284323
fn sanity_check(psbt: &Psbt) -> Result<(), Error> {

0 commit comments

Comments
 (0)