Skip to content

Commit 4ab7a7c

Browse files
committed
Add preimage32 type alias
1 parent 48c0ff8 commit 4ab7a7c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ pub use descriptor::{Descriptor, DescriptorPublicKey, DescriptorTrait};
127127
pub use interpreter::Interpreter;
128128
pub use miniscript::context::{BareCtx, Legacy, ScriptContext, Segwitv0};
129129
pub use miniscript::decode::Terminal;
130-
pub use miniscript::satisfy::{BitcoinSig, Satisfier};
130+
pub use miniscript::satisfy::{BitcoinSig, Preimage32, Satisfier};
131131
pub use miniscript::Miniscript;
132132

133133
///Public key trait which can be converted to Hash type

src/miniscript/satisfy.rs

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ use Terminal;
3737

3838
/// Type alias for a signature/hashtype pair
3939
pub type BitcoinSig = (secp256k1::Signature, bitcoin::SigHashType);
40+
/// Type alias for 32 byte Preimage.
41+
pub type Preimage32 = [u8; 32];
4042

4143
/// Helper function to create BitcoinSig from Rawsig
4244
/// Useful for downstream when implementing Satisfier.
@@ -71,22 +73,22 @@ pub trait Satisfier<Pk: MiniscriptKey + ToPublicKey> {
7173
}
7274

7375
/// Given a SHA256 hash, look up its preimage
74-
fn lookup_sha256(&self, _: sha256::Hash) -> Option<[u8; 32]> {
76+
fn lookup_sha256(&self, _: sha256::Hash) -> Option<Preimage32> {
7577
None
7678
}
7779

7880
/// Given a HASH256 hash, look up its preimage
79-
fn lookup_hash256(&self, _: sha256d::Hash) -> Option<[u8; 32]> {
81+
fn lookup_hash256(&self, _: sha256d::Hash) -> Option<Preimage32> {
8082
None
8183
}
8284

8385
/// Given a RIPEMD160 hash, look up its preimage
84-
fn lookup_ripemd160(&self, _: ripemd160::Hash) -> Option<[u8; 32]> {
86+
fn lookup_ripemd160(&self, _: ripemd160::Hash) -> Option<Preimage32> {
8587
None
8688
}
8789

8890
/// Given a HASH160 hash, look up its preimage
89-
fn lookup_hash160(&self, _: hash160::Hash) -> Option<[u8; 32]> {
91+
fn lookup_hash160(&self, _: hash160::Hash) -> Option<Preimage32> {
9092
None
9193
}
9294

@@ -181,19 +183,19 @@ impl<'a, Pk: MiniscriptKey + ToPublicKey, S: Satisfier<Pk>> Satisfier<Pk> for &'
181183
(**self).lookup_pkh_sig(pkh)
182184
}
183185

184-
fn lookup_sha256(&self, h: sha256::Hash) -> Option<[u8; 32]> {
186+
fn lookup_sha256(&self, h: sha256::Hash) -> Option<Preimage32> {
185187
(**self).lookup_sha256(h)
186188
}
187189

188-
fn lookup_hash256(&self, h: sha256d::Hash) -> Option<[u8; 32]> {
190+
fn lookup_hash256(&self, h: sha256d::Hash) -> Option<Preimage32> {
189191
(**self).lookup_hash256(h)
190192
}
191193

192-
fn lookup_ripemd160(&self, h: ripemd160::Hash) -> Option<[u8; 32]> {
194+
fn lookup_ripemd160(&self, h: ripemd160::Hash) -> Option<Preimage32> {
193195
(**self).lookup_ripemd160(h)
194196
}
195197

196-
fn lookup_hash160(&self, h: hash160::Hash) -> Option<[u8; 32]> {
198+
fn lookup_hash160(&self, h: hash160::Hash) -> Option<Preimage32> {
197199
(**self).lookup_hash160(h)
198200
}
199201

@@ -219,19 +221,19 @@ impl<'a, Pk: MiniscriptKey + ToPublicKey, S: Satisfier<Pk>> Satisfier<Pk> for &'
219221
(**self).lookup_pkh_sig(pkh)
220222
}
221223

222-
fn lookup_sha256(&self, h: sha256::Hash) -> Option<[u8; 32]> {
224+
fn lookup_sha256(&self, h: sha256::Hash) -> Option<Preimage32> {
223225
(**self).lookup_sha256(h)
224226
}
225227

226-
fn lookup_hash256(&self, h: sha256d::Hash) -> Option<[u8; 32]> {
228+
fn lookup_hash256(&self, h: sha256d::Hash) -> Option<Preimage32> {
227229
(**self).lookup_hash256(h)
228230
}
229231

230-
fn lookup_ripemd160(&self, h: ripemd160::Hash) -> Option<[u8; 32]> {
232+
fn lookup_ripemd160(&self, h: ripemd160::Hash) -> Option<Preimage32> {
231233
(**self).lookup_ripemd160(h)
232234
}
233235

234-
fn lookup_hash160(&self, h: hash160::Hash) -> Option<[u8; 32]> {
236+
fn lookup_hash160(&self, h: hash160::Hash) -> Option<Preimage32> {
235237
(**self).lookup_hash160(h)
236238
}
237239

@@ -288,7 +290,7 @@ macro_rules! impl_tuple_satisfier {
288290
None
289291
}
290292

291-
fn lookup_sha256(&self, h: sha256::Hash) -> Option<[u8; 32]> {
293+
fn lookup_sha256(&self, h: sha256::Hash) -> Option<Preimage32> {
292294
let &($(ref $ty,)*) = self;
293295
$(
294296
if let Some(result) = $ty.lookup_sha256(h) {
@@ -298,7 +300,7 @@ macro_rules! impl_tuple_satisfier {
298300
None
299301
}
300302

301-
fn lookup_hash256(&self, h: sha256d::Hash) -> Option<[u8; 32]> {
303+
fn lookup_hash256(&self, h: sha256d::Hash) -> Option<Preimage32> {
302304
let &($(ref $ty,)*) = self;
303305
$(
304306
if let Some(result) = $ty.lookup_hash256(h) {
@@ -308,7 +310,7 @@ macro_rules! impl_tuple_satisfier {
308310
None
309311
}
310312

311-
fn lookup_ripemd160(&self, h: ripemd160::Hash) -> Option<[u8; 32]> {
313+
fn lookup_ripemd160(&self, h: ripemd160::Hash) -> Option<Preimage32> {
312314
let &($(ref $ty,)*) = self;
313315
$(
314316
if let Some(result) = $ty.lookup_ripemd160(h) {
@@ -318,7 +320,7 @@ macro_rules! impl_tuple_satisfier {
318320
None
319321
}
320322

321-
fn lookup_hash160(&self, h: hash160::Hash) -> Option<[u8; 32]> {
323+
fn lookup_hash160(&self, h: hash160::Hash) -> Option<Preimage32> {
322324
let &($(ref $ty,)*) = self;
323325
$(
324326
if let Some(result) = $ty.lookup_hash160(h) {

0 commit comments

Comments
 (0)