Skip to content

Commit 3dffa08

Browse files
committed
Use Key instead of MiniscriptKey
One of the main traits in this lib is `MiniscriptKey`, we can shorten this to `Key` with no loss of meaning. This makes the whole codebase more terse. Terse code, if clear, is easier to read because there is less clutter. Also terseness assists the formatter and can reduce lines of code. This patch is the result of running `s/MiniscriptKey/Key/g` on all source files.
1 parent dcc9d0f commit 3dffa08

31 files changed

+410
-443
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
- Fixed miniscript type system bug. This is a security vulnerability and users are strongly encouraged to upgrade.
44
See this (link)[https://github.com/rust-bitcoin/rust-miniscript/pull/349/commits/db97c39afa4053c2c3917f04392f6e24964b3972] for details.
55
- Support for `tr` descriptors with miniscript leaves and multi_a fragment
6-
- Changes to MiniscriptKey and ToPublicKey traits for x-only keys support
6+
- Changes to Key and ToPublicKey traits for x-only keys support
77
- Add `PsbtExt` trait for psbt operations
88
- `Psbt::update_desc` adds information from a descriptor to a psbt. This figures
99
out the type of the descriptor and adds corresponding redeem script/witness script
@@ -33,7 +33,7 @@ See this (link)[https://github.com/rust-bitcoin/rust-miniscript/pull/349/commits
3333
- Remove `PkCtx` from the API
3434
- Move descriptors into their own types, with an enum containing all of them
3535
- Move descriptor functionality into a trait
36-
- Remove `FromStr` bound from `MiniscriptKey`and `MiniscriptKey::Hash`
36+
- Remove `FromStr` bound from `Key`and `Key::Hash`
3737
- Various `DescriptorPublicKey` improvements
3838
- Allow hardened paths in `DescriptorPublicKey`, remove direct `ToPublicKey` implementation
3939
- Change `Option` to `Result` in all APIs

examples/sign_multisig.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ fn main() {
9090
assert_eq!(my_descriptor.max_satisfaction_weight().unwrap(), 258);
9191

9292
// Sometimes it is necessary to have additional information to get the bitcoin::PublicKey
93-
// from the MiniscriptKey which can supplied by `to_pk_ctx` parameter. For example,
93+
// from the Key which can supplied by `to_pk_ctx` parameter. For example,
9494
// when calculating the script pubkey of a descriptor with xpubs, the secp context and
9595
// child information maybe required.
9696

examples/verify_tx.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ fn main() {
125125
// signatures are not treated as having participated in the script
126126
let secp = secp256k1::Secp256k1::new();
127127
// Sometimes it is necessary to have additional information to get the bitcoin::PublicKey
128-
// from the MiniscriptKey which can supplied by `to_pk_ctx` parameter. For example,
128+
// from the Key which can supplied by `to_pk_ctx` parameter. For example,
129129
// when calculating the script pubkey of a descriptor with xpubs, the secp context and
130130
// child information maybe required.
131131
let interpreter = miniscript::Interpreter::from_txdata(

integration_test/src/test_cpp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use bitcoin::{self, Amount, OutPoint, Transaction, TxIn, TxOut, Txid};
1111
use bitcoincore_rpc::{json, Client, RpcApi};
1212
use miniscript::miniscript::iter;
1313
use miniscript::psbt::PsbtExt;
14-
use miniscript::MiniscriptKey;
14+
use miniscript::Key;
1515
use miniscript::Segwitv0;
1616
use miniscript::{Descriptor, DescriptorTrait, Miniscript};
1717
use std::collections::BTreeMap;

integration_test/src/test_desc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use bitcoincore_rpc::{json, Client, RpcApi};
1515
use miniscript::miniscript::iter;
1616
use miniscript::psbt::PsbtExt;
1717
use miniscript::{Descriptor, DescriptorTrait, Miniscript, ToPublicKey};
18-
use miniscript::{MiniscriptKey, ScriptContext};
18+
use miniscript::{Key, ScriptContext};
1919
use std::collections::BTreeMap;
2020

2121
use crate::test_util::{self, TestData};

src/descriptor/bare.rs

+29-32
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ use expression::{self, FromTree};
2626
use miniscript::context::ScriptContext;
2727
use policy::{semantic, Liftable};
2828
use util::{varint_len, witness_to_scriptsig};
29-
use {
30-
BareCtx, Error, ForEach, ForEachKey, Miniscript, MiniscriptKey, Satisfier, ToPublicKey,
31-
TranslatePk,
32-
};
29+
use {BareCtx, Error, ForEach, ForEachKey, Key, Miniscript, Satisfier, ToPublicKey, TranslatePk};
3330

3431
use super::{
3532
checksum::{desc_checksum, verify_checksum},
@@ -39,12 +36,12 @@ use super::{
3936
/// Create a Bare Descriptor. That is descriptor that is
4037
/// not wrapped in sh or wsh. This covers the Pk descriptor
4138
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
42-
pub struct Bare<Pk: MiniscriptKey> {
39+
pub struct Bare<Pk: Key> {
4340
/// underlying miniscript
4441
ms: Miniscript<Pk, BareCtx>,
4542
}
4643

47-
impl<Pk: MiniscriptKey> Bare<Pk> {
44+
impl<Pk: Key> Bare<Pk> {
4845
/// Create a new raw descriptor
4946
pub fn new(ms: Miniscript<Pk, BareCtx>) -> Result<Self, Error> {
5047
// do the top-level checks
@@ -63,7 +60,7 @@ impl<Pk: MiniscriptKey> Bare<Pk> {
6360
}
6461
}
6562

66-
impl<Pk: MiniscriptKey + ToPublicKey> Bare<Pk> {
63+
impl<Pk: Key + ToPublicKey> Bare<Pk> {
6764
/// Obtain the corresponding script pubkey for this descriptor
6865
/// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
6966
pub fn spk(&self) -> Script {
@@ -83,32 +80,32 @@ impl<Pk: MiniscriptKey + ToPublicKey> Bare<Pk> {
8380
}
8481
}
8582

86-
impl<Pk: MiniscriptKey> fmt::Debug for Bare<Pk> {
83+
impl<Pk: Key> fmt::Debug for Bare<Pk> {
8784
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8885
write!(f, "{:?}", self.ms)
8986
}
9087
}
9188

92-
impl<Pk: MiniscriptKey> fmt::Display for Bare<Pk> {
89+
impl<Pk: Key> fmt::Display for Bare<Pk> {
9390
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9491
let desc = format!("{}", self.ms);
9592
let checksum = desc_checksum(&desc).map_err(|_| fmt::Error)?;
9693
write!(f, "{}#{}", &desc, &checksum)
9794
}
9895
}
9996

100-
impl<Pk: MiniscriptKey> Liftable<Pk> for Bare<Pk> {
97+
impl<Pk: Key> Liftable<Pk> for Bare<Pk> {
10198
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
10299
self.ms.lift()
103100
}
104101
}
105102

106103
impl<Pk> FromTree for Bare<Pk>
107104
where
108-
Pk: MiniscriptKey + FromStr,
105+
Pk: Key + FromStr,
109106
Pk::Hash: FromStr,
110107
<Pk as FromStr>::Err: ToString,
111-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
108+
<<Pk as Key>::Hash as FromStr>::Err: ToString,
112109
{
113110
fn from_tree(top: &expression::Tree) -> Result<Self, Error> {
114111
let sub = Miniscript::<Pk, BareCtx>::from_tree(&top)?;
@@ -119,10 +116,10 @@ where
119116

120117
impl<Pk> FromStr for Bare<Pk>
121118
where
122-
Pk: MiniscriptKey + FromStr,
119+
Pk: Key + FromStr,
123120
Pk::Hash: FromStr,
124121
<Pk as FromStr>::Err: ToString,
125-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
122+
<<Pk as Key>::Hash as FromStr>::Err: ToString,
126123
{
127124
type Err = Error;
128125

@@ -133,7 +130,7 @@ where
133130
}
134131
}
135132

136-
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
133+
impl<Pk: Key> DescriptorTrait<Pk> for Bare<Pk> {
137134
fn sanity_check(&self) -> Result<(), Error> {
138135
self.ms.sanity_check()?;
139136
Ok(())
@@ -202,7 +199,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
202199
}
203200
}
204201

205-
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Bare<Pk> {
202+
impl<Pk: Key> ForEachKey<Pk> for Bare<Pk> {
206203
fn for_each_key<'a, F: FnMut(ForEach<'a, Pk>) -> bool>(&'a self, pred: F) -> bool
207204
where
208205
Pk: 'a,
@@ -212,7 +209,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Bare<Pk> {
212209
}
213210
}
214211

215-
impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Bare<P> {
212+
impl<P: Key, Q: Key> TranslatePk<P, Q> for Bare<P> {
216213
type Output = Bare<Q>;
217214

218215
fn translate_pk<Fpk, Fpkh, E>(
@@ -223,7 +220,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Bare<P> {
223220
where
224221
Fpk: FnMut(&P) -> Result<Q, E>,
225222
Fpkh: FnMut(&P::Hash) -> Result<Q::Hash, E>,
226-
Q: MiniscriptKey,
223+
Q: Key,
227224
{
228225
Ok(Bare::new(
229226
self.ms
@@ -235,12 +232,12 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Bare<P> {
235232

236233
/// A bare PkH descriptor at top level
237234
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash)]
238-
pub struct Pkh<Pk: MiniscriptKey> {
235+
pub struct Pkh<Pk: Key> {
239236
/// underlying publickey
240237
pk: Pk,
241238
}
242239

243-
impl<Pk: MiniscriptKey> Pkh<Pk> {
240+
impl<Pk: Key> Pkh<Pk> {
244241
/// Create a new Pkh descriptor
245242
pub fn new(pk: Pk) -> Self {
246243
// do the top-level checks
@@ -258,7 +255,7 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
258255
}
259256
}
260257

261-
impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
258+
impl<Pk: Key + ToPublicKey> Pkh<Pk> {
262259
/// Obtain the corresponding script pubkey for this descriptor
263260
/// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
264261
pub fn spk(&self) -> Script {
@@ -285,32 +282,32 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
285282
}
286283
}
287284

288-
impl<Pk: MiniscriptKey> fmt::Debug for Pkh<Pk> {
285+
impl<Pk: Key> fmt::Debug for Pkh<Pk> {
289286
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
290287
write!(f, "pkh({:?})", self.pk)
291288
}
292289
}
293290

294-
impl<Pk: MiniscriptKey> fmt::Display for Pkh<Pk> {
291+
impl<Pk: Key> fmt::Display for Pkh<Pk> {
295292
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
296293
let desc = format!("pkh({})", self.pk);
297294
let checksum = desc_checksum(&desc).map_err(|_| fmt::Error)?;
298295
write!(f, "{}#{}", &desc, &checksum)
299296
}
300297
}
301298

302-
impl<Pk: MiniscriptKey> Liftable<Pk> for Pkh<Pk> {
299+
impl<Pk: Key> Liftable<Pk> for Pkh<Pk> {
303300
fn lift(&self) -> Result<semantic::Policy<Pk>, Error> {
304301
Ok(semantic::Policy::KeyHash(self.pk.to_pubkeyhash()))
305302
}
306303
}
307304

308305
impl<Pk> FromTree for Pkh<Pk>
309306
where
310-
Pk: MiniscriptKey + FromStr,
307+
Pk: Key + FromStr,
311308
Pk::Hash: FromStr,
312309
<Pk as FromStr>::Err: ToString,
313-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
310+
<<Pk as Key>::Hash as FromStr>::Err: ToString,
314311
{
315312
fn from_tree(top: &expression::Tree) -> Result<Self, Error> {
316313
if top.name == "pkh" && top.args.len() == 1 {
@@ -329,10 +326,10 @@ where
329326

330327
impl<Pk> FromStr for Pkh<Pk>
331328
where
332-
Pk: MiniscriptKey + FromStr,
329+
Pk: Key + FromStr,
333330
Pk::Hash: FromStr,
334331
<Pk as FromStr>::Err: ToString,
335-
<<Pk as MiniscriptKey>::Hash as FromStr>::Err: ToString,
332+
<<Pk as Key>::Hash as FromStr>::Err: ToString,
336333
{
337334
type Err = Error;
338335

@@ -343,7 +340,7 @@ where
343340
}
344341
}
345342

346-
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
343+
impl<Pk: Key> DescriptorTrait<Pk> for Pkh<Pk> {
347344
fn sanity_check(&self) -> Result<(), Error> {
348345
Ok(())
349346
}
@@ -414,7 +411,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
414411
}
415412
}
416413

417-
impl<Pk: MiniscriptKey> ForEachKey<Pk> for Pkh<Pk> {
414+
impl<Pk: Key> ForEachKey<Pk> for Pkh<Pk> {
418415
fn for_each_key<'a, F: FnMut(ForEach<'a, Pk>) -> bool>(&'a self, mut pred: F) -> bool
419416
where
420417
Pk: 'a,
@@ -424,7 +421,7 @@ impl<Pk: MiniscriptKey> ForEachKey<Pk> for Pkh<Pk> {
424421
}
425422
}
426423

427-
impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Pkh<P> {
424+
impl<P: Key, Q: Key> TranslatePk<P, Q> for Pkh<P> {
428425
type Output = Pkh<Q>;
429426

430427
fn translate_pk<Fpk, Fpkh, E>(
@@ -435,7 +432,7 @@ impl<P: MiniscriptKey, Q: MiniscriptKey> TranslatePk<P, Q> for Pkh<P> {
435432
where
436433
Fpk: FnMut(&P) -> Result<Q, E>,
437434
Fpkh: FnMut(&P::Hash) -> Result<Q::Hash, E>,
438-
Q: MiniscriptKey,
435+
Q: Key,
439436
{
440437
Ok(Pkh::new(translatefpk(&self.pk)?))
441438
}

src/descriptor/key.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use bitcoin::{
1010
XOnlyPublicKey, XpubIdentifier,
1111
};
1212

13-
use {MiniscriptKey, ToPublicKey};
13+
use {Key, ToPublicKey};
1414

1515
/// Single public key without any origin or range information
1616
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
@@ -21,7 +21,7 @@ pub enum SinglePubKey {
2121
XOnly(XOnlyPublicKey),
2222
}
2323

24-
/// The MiniscriptKey corresponding to Descriptors. This can
24+
/// The Key corresponding to Descriptors. This can
2525
/// either be Single public key or a Xpub
2626
#[derive(Debug, Eq, PartialEq, Clone, Ord, PartialOrd, Hash)]
2727
pub enum DescriptorPublicKey {
@@ -688,7 +688,7 @@ impl<K: InnerXKey> DescriptorXKey<K> {
688688
}
689689
}
690690

691-
impl MiniscriptKey for DescriptorPublicKey {
691+
impl Key for DescriptorPublicKey {
692692
// This allows us to be able to derive public keys even for PkH s
693693
type Hash = Self;
694694

0 commit comments

Comments
 (0)