Skip to content

Commit 2ffa5ea

Browse files
committed
Rename Sha256Hash type to Sha256
1 parent 2e95dc0 commit 2ffa5ea

File tree

11 files changed

+39
-42
lines changed

11 files changed

+39
-42
lines changed

src/descriptor/key.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ impl<K: InnerXKey> DescriptorXKey<K> {
737737
impl MiniscriptKey for DescriptorPublicKey {
738738
// This allows us to be able to derive public keys even for PkH s
739739
type Hash = Self;
740-
type Sha256Hash = bitcoin::hashes::sha256::Hash;
740+
type Sha256 = bitcoin::hashes::sha256::Hash;
741741

742742
fn is_uncompressed(&self) -> bool {
743743
match self {
@@ -803,7 +803,7 @@ impl fmt::Display for DerivedDescriptorKey {
803803
impl MiniscriptKey for DerivedDescriptorKey {
804804
// This allows us to be able to derive public keys even for PkH s
805805
type Hash = Self;
806-
type Sha256Hash = bitcoin::hashes::sha256::Hash;
806+
type Sha256 = bitcoin::hashes::sha256::Hash;
807807

808808
fn is_uncompressed(&self) -> bool {
809809
self.key.is_uncompressed()

src/interpreter/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl TypedHash160 {
149149

150150
impl MiniscriptKey for BitcoinKey {
151151
type Hash = TypedHash160;
152-
type Sha256Hash = bitcoin::hashes::sha256::Hash;
152+
type Sha256 = bitcoin::hashes::sha256::Hash;
153153

154154
fn to_pubkeyhash(&self) -> Self::Hash {
155155
match self {

src/lib.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -157,15 +157,15 @@ pub trait MiniscriptKey: Clone + Eq + Ord + fmt::Debug + fmt::Display + hash::Ha
157157

158158
/// The associated [`sha256::Hash`] type for this [`MiniscriptKey`] type.
159159
/// Used in the sha256 fragment
160-
type Sha256Hash: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
160+
type Sha256: Clone + Eq + Ord + fmt::Display + fmt::Debug + hash::Hash;
161161

162162
/// Converts this key to the associated pubkey hash.
163163
fn to_pubkeyhash(&self) -> Self::Hash;
164164
}
165165

166166
impl MiniscriptKey for bitcoin::secp256k1::PublicKey {
167167
type Hash = hash160::Hash;
168-
type Sha256Hash = sha256::Hash;
168+
type Sha256 = sha256::Hash;
169169

170170
fn to_pubkeyhash(&self) -> Self::Hash {
171171
hash160::Hash::hash(&self.serialize())
@@ -179,7 +179,7 @@ impl MiniscriptKey for bitcoin::PublicKey {
179179
}
180180

181181
type Hash = hash160::Hash;
182-
type Sha256Hash = sha256::Hash;
182+
type Sha256 = sha256::Hash;
183183

184184
fn to_pubkeyhash(&self) -> Self::Hash {
185185
hash160::Hash::hash(&self.to_bytes())
@@ -188,7 +188,7 @@ impl MiniscriptKey for bitcoin::PublicKey {
188188

189189
impl MiniscriptKey for bitcoin::secp256k1::XOnlyPublicKey {
190190
type Hash = hash160::Hash;
191-
type Sha256Hash = sha256::Hash;
191+
type Sha256 = sha256::Hash;
192192

193193
fn to_pubkeyhash(&self) -> Self::Hash {
194194
hash160::Hash::hash(&self.serialize())
@@ -201,7 +201,7 @@ impl MiniscriptKey for bitcoin::secp256k1::XOnlyPublicKey {
201201

202202
impl MiniscriptKey for String {
203203
type Hash = String;
204-
type Sha256Hash = String; // specify hashes as string
204+
type Sha256 = String; // specify hashes as string
205205

206206
fn to_pubkeyhash(&self) -> Self::Hash {
207207
(&self).to_string()
@@ -227,8 +227,8 @@ pub trait ToPublicKey: MiniscriptKey {
227227
/// the result directly.
228228
fn hash_to_hash160(hash: &<Self as MiniscriptKey>::Hash) -> hash160::Hash;
229229

230-
/// Converts the generic associated [`MiniscriptKey::Sha256Hash`] to [`sha256::Hash`]
231-
fn to_sha256(hash: &<Self as MiniscriptKey>::Sha256Hash) -> sha256::Hash;
230+
/// Converts the generic associated [`MiniscriptKey::Sha256`] to [`sha256::Hash`]
231+
fn to_sha256(hash: &<Self as MiniscriptKey>::Sha256) -> sha256::Hash;
232232
}
233233

234234
impl ToPublicKey for bitcoin::PublicKey {
@@ -299,7 +299,7 @@ impl str::FromStr for DummyKey {
299299

300300
impl MiniscriptKey for DummyKey {
301301
type Hash = DummyKeyHash;
302-
type Sha256Hash = DummySha256Hash;
302+
type Sha256 = DummySha256Hash;
303303

304304
fn to_pubkeyhash(&self) -> Self::Hash {
305305
DummyKeyHash
@@ -402,8 +402,8 @@ where
402402
/// Provides the translation public keys hashes P::Hash -> Q::Hash
403403
fn f_pkh(&mut self, pkh: &P::Hash) -> Result<Q::Hash, E>;
404404

405-
/// Provides the translation from P::Sha256Hash -> Q::Sha256Hash
406-
fn f_sha256(&mut self, sha256: &P::Sha256Hash) -> Result<Q::Sha256Hash, E>;
405+
/// Provides the translation from P::Sha256 -> Q::Sha256
406+
fn f_sha256(&mut self, sha256: &P::Sha256) -> Result<Q::Sha256, E>;
407407
}
408408

409409
/// Provides the conversion information required in [`TranslatePk`].
@@ -412,7 +412,7 @@ where
412412
pub trait PkTranslator<P, Q, E>
413413
where
414414
P: MiniscriptKey,
415-
Q: MiniscriptKey<Sha256Hash = P::Sha256Hash>,
415+
Q: MiniscriptKey<Sha256 = P::Sha256>,
416416
{
417417
/// Provides the translation public keys P -> Q
418418
fn f_pk(&mut self, pk: &P) -> Result<Q, E>;
@@ -425,7 +425,7 @@ impl<P, Q, E, T> Translator<P, Q, E> for T
425425
where
426426
T: PkTranslator<P, Q, E>,
427427
P: MiniscriptKey,
428-
Q: MiniscriptKey<Sha256Hash = P::Sha256Hash>,
428+
Q: MiniscriptKey<Sha256 = P::Sha256>,
429429
{
430430
fn f_pk(&mut self, pk: &P) -> Result<Q, E> {
431431
<Self as PkTranslator<P, Q, E>>::f_pk(self, pk)
@@ -435,10 +435,7 @@ where
435435
<Self as PkTranslator<P, Q, E>>::f_pkh(self, pkh)
436436
}
437437

438-
fn f_sha256(
439-
&mut self,
440-
sha256: &<P as MiniscriptKey>::Sha256Hash,
441-
) -> Result<<Q>::Sha256Hash, E> {
438+
fn f_sha256(&mut self, sha256: &<P as MiniscriptKey>::Sha256) -> Result<<Q>::Sha256, E> {
442439
Ok(sha256.clone())
443440
}
444441
}

src/macros.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ macro_rules! impl_from_tree {
2828
where
2929
Pk: MiniscriptKey + core::str::FromStr,
3030
Pk::Hash: core::str::FromStr,
31-
Pk::Sha256Hash: core::str::FromStr,
31+
Pk::Sha256: core::str::FromStr,
3232
<Pk as core::str::FromStr>::Err: $crate::prelude::ToString,
3333
<<Pk as MiniscriptKey>::Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
34-
<<Pk as MiniscriptKey>::Sha256Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
34+
<<Pk as MiniscriptKey>::Sha256 as core::str::FromStr>::Err: $crate::prelude::ToString,
3535
$($gen : $gen_con,)*
3636
{
3737

@@ -56,10 +56,10 @@ macro_rules! impl_from_str {
5656
where
5757
Pk: MiniscriptKey + core::str::FromStr,
5858
Pk::Hash: core::str::FromStr,
59-
Pk::Sha256Hash: core::str::FromStr,
59+
Pk::Sha256: core::str::FromStr,
6060
<Pk as core::str::FromStr>::Err: $crate::prelude::ToString,
6161
<<Pk as MiniscriptKey>::Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
62-
<<Pk as MiniscriptKey>::Sha256Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
62+
<<Pk as MiniscriptKey>::Sha256 as core::str::FromStr>::Err: $crate::prelude::ToString,
6363
$($gen : $gen_con,)*
6464
{
6565
type Err = $err_ty;
@@ -84,10 +84,10 @@ macro_rules! impl_block_str {
8484
where
8585
Pk: MiniscriptKey + core::str::FromStr,
8686
Pk::Hash: core::str::FromStr,
87-
Pk::Sha256Hash: core::str::FromStr,
87+
Pk::Sha256: core::str::FromStr,
8888
<Pk as core::str::FromStr>::Err: $crate::prelude::ToString,
8989
<<Pk as MiniscriptKey>::Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
90-
<<Pk as MiniscriptKey>::Sha256Hash as core::str::FromStr>::Err: $crate::prelude::ToString,
90+
<<Pk as MiniscriptKey>::Sha256 as core::str::FromStr>::Err: $crate::prelude::ToString,
9191
$($gen : $gen_con,)*
9292
{
9393
$(#[$meta])*
@@ -107,11 +107,11 @@ macro_rules! serde_string_impl_pk {
107107
where
108108
Pk: $crate::MiniscriptKey + core::str::FromStr,
109109
Pk::Hash: core::str::FromStr,
110-
Pk::Sha256Hash: core::str::FromStr,
110+
Pk::Sha256: core::str::FromStr,
111111
<Pk as core::str::FromStr>::Err: core::fmt::Display,
112112
<<Pk as $crate::MiniscriptKey>::Hash as core::str::FromStr>::Err:
113113
core::fmt::Display,
114-
<<Pk as $crate::MiniscriptKey>::Sha256Hash as core::str::FromStr>::Err:
114+
<<Pk as $crate::MiniscriptKey>::Sha256 as core::str::FromStr>::Err:
115115
core::fmt::Display,
116116
$($gen : $gen_con,)*
117117
{
@@ -129,11 +129,11 @@ macro_rules! serde_string_impl_pk {
129129
where
130130
Pk: $crate::MiniscriptKey + core::str::FromStr,
131131
Pk::Hash: core::str::FromStr,
132-
Pk::Sha256Hash: core::str::FromStr,
132+
Pk::Sha256: core::str::FromStr,
133133
<Pk as core::str::FromStr>::Err: core::fmt::Display,
134134
<<Pk as $crate::MiniscriptKey>::Hash as core::str::FromStr>::Err:
135135
core::fmt::Display,
136-
<<Pk as $crate::MiniscriptKey>::Sha256Hash as core::str::FromStr>::Err:
136+
<<Pk as $crate::MiniscriptKey>::Sha256 as core::str::FromStr>::Err:
137137
core::fmt::Display,
138138
$($gen: $gen_con,)*
139139
{

src/miniscript/astelem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl_from_tree!(
470470
expression::parse_num(x).map(Terminal::Older)
471471
}),
472472
("sha256", 1) => expression::terminal(&top.args[0], |x| {
473-
Pk::Sha256Hash::from_str(x).map(Terminal::Sha256)
473+
Pk::Sha256::from_str(x).map(Terminal::Sha256)
474474
}),
475475
("hash256", 1) => expression::terminal(&top.args[0], |x| {
476476
sha256d::Hash::from_hex(x)

src/miniscript/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ pub trait ScriptContext:
191191
fmt::Debug + Clone + Ord + PartialOrd + Eq + PartialEq + hash::Hash + private::Sealed
192192
where
193193
Self::Key: MiniscriptKey<Hash = bitcoin::hashes::hash160::Hash>,
194-
Self::Key: MiniscriptKey<Sha256Hash = bitcoin::hashes::sha256::Hash>,
194+
Self::Key: MiniscriptKey<Sha256 = bitcoin::hashes::sha256::Hash>,
195195
{
196196
/// The consensus key associated with the type. Must be a parseable key
197197
type Key: ParseableKey;

src/miniscript/decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub enum Terminal<Pk: MiniscriptKey, Ctx: ScriptContext> {
142142
Older(u32),
143143
// hashlocks
144144
/// `SIZE 32 EQUALVERIFY SHA256 <hash> EQUAL`
145-
Sha256(Pk::Sha256Hash),
145+
Sha256(Pk::Sha256),
146146
/// `SIZE 32 EQUALVERIFY HASH256 <hash> EQUAL`
147147
Hash256(sha256d::Hash),
148148
/// `SIZE 32 EQUALVERIFY RIPEMD160 <hash> EQUAL`

src/miniscript/satisfy.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pub trait Satisfier<Pk: MiniscriptKey + ToPublicKey> {
9090
}
9191

9292
/// Given a SHA256 hash, look up its preimage
93-
fn lookup_sha256(&self, _: &Pk::Sha256Hash) -> Option<Preimage32> {
93+
fn lookup_sha256(&self, _: &Pk::Sha256) -> Option<Preimage32> {
9494
None
9595
}
9696

@@ -257,7 +257,7 @@ impl<'a, Pk: MiniscriptKey + ToPublicKey, S: Satisfier<Pk>> Satisfier<Pk> for &'
257257
(**self).lookup_tap_control_block_map()
258258
}
259259

260-
fn lookup_sha256(&self, h: &Pk::Sha256Hash) -> Option<Preimage32> {
260+
fn lookup_sha256(&self, h: &Pk::Sha256) -> Option<Preimage32> {
261261
(**self).lookup_sha256(h)
262262
}
263263

@@ -319,7 +319,7 @@ impl<'a, Pk: MiniscriptKey + ToPublicKey, S: Satisfier<Pk>> Satisfier<Pk> for &'
319319
(**self).lookup_tap_control_block_map()
320320
}
321321

322-
fn lookup_sha256(&self, h: &Pk::Sha256Hash) -> Option<Preimage32> {
322+
fn lookup_sha256(&self, h: &Pk::Sha256) -> Option<Preimage32> {
323323
(**self).lookup_sha256(h)
324324
}
325325

@@ -433,7 +433,7 @@ macro_rules! impl_tuple_satisfier {
433433
None
434434
}
435435

436-
fn lookup_sha256(&self, h: &Pk::Sha256Hash) -> Option<Preimage32> {
436+
fn lookup_sha256(&self, h: &Pk::Sha256) -> Option<Preimage32> {
437437
let &($(ref $ty,)*) = self;
438438
$(
439439
if let Some(result) = $ty.lookup_sha256(h) {
@@ -601,7 +601,7 @@ impl Witness {
601601
}
602602

603603
/// Turn a hash preimage into (part of) a satisfaction
604-
fn sha256_preimage<Pk: ToPublicKey, S: Satisfier<Pk>>(sat: S, h: &Pk::Sha256Hash) -> Self {
604+
fn sha256_preimage<Pk: ToPublicKey, S: Satisfier<Pk>>(sat: S, h: &Pk::Sha256) -> Self {
605605
match sat.lookup_sha256(h) {
606606
Some(pre) => Witness::Stack(vec![pre.to_vec()]),
607607
// Note hash preimages are unavailable instead of impossible

src/policy/concrete.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub enum Policy<Pk: MiniscriptKey> {
5858
/// A relative locktime restriction
5959
Older(u32),
6060
/// A SHA256 whose preimage must be provided to satisfy the descriptor
61-
Sha256(Pk::Sha256Hash),
61+
Sha256(Pk::Sha256),
6262
/// A SHA256d whose preimage must be provided to satisfy the descriptor
6363
Hash256(sha256d::Hash),
6464
/// A RIPEMD160 whose preimage must be provided to satisfy the descriptor
@@ -780,7 +780,7 @@ impl_block_str!(
780780
Ok(Policy::Older(num))
781781
}
782782
("sha256", 1) => expression::terminal(&top.args[0], |x| {
783-
<Pk::Sha256Hash as core::str::FromStr>::from_str(x).map(Policy::Sha256)
783+
<Pk::Sha256 as core::str::FromStr>::from_str(x).map(Policy::Sha256)
784784
}),
785785
("hash256", 1) => expression::terminal(&top.args[0], |x| {
786786
sha256d::Hash::from_hex(x).map(Policy::Hash256)

src/policy/semantic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub enum Policy<Pk: MiniscriptKey> {
4444
/// A relative locktime restriction
4545
Older(u32),
4646
/// A SHA256 whose preimage must be provided to satisfy the descriptor
47-
Sha256(Pk::Sha256Hash),
47+
Sha256(Pk::Sha256),
4848
/// A SHA256d whose preimage must be provided to satisfy the descriptor
4949
Hash256(sha256d::Hash),
5050
/// A RIPEMD160 whose preimage must be provided to satisfy the descriptor
@@ -340,7 +340,7 @@ impl_from_tree!(
340340
expression::parse_num(x).map(Policy::Older)
341341
}),
342342
("sha256", 1) => expression::terminal(&top.args[0], |x| {
343-
Pk::Sha256Hash::from_str(x).map(Policy::Sha256)
343+
Pk::Sha256::from_str(x).map(Policy::Sha256)
344344
}),
345345
("hash256", 1) => expression::terminal(&top.args[0], |x| {
346346
sha256d::Hash::from_hex(x).map(Policy::Hash256)

0 commit comments

Comments
 (0)