Skip to content

Commit 5e0fc81

Browse files
committed
Merge #840: backport #839 (DefiniteDescriptorKey fixes) to 12.x
1374ae4 bump version to 12.3.4 (Andrew Poelstra) de73db9 key: fix DefiniteDescriptorKey construction from key with hardened step (Andrew Poelstra) Pull request description: ACKs for top commit: sanket1729: ACK 1374ae4 Tree-SHA512: 4f4faac8df85e137eb901a2df42780c1b5cfda31746b8906d628942d038bb16e44be88d07255e8f952ebbc2e43f37207c72d02952c34a3a619aa68d536bd98cc
2 parents af2664d + 1374ae4 commit 5e0fc81

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

Cargo-minimal.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ dependencies = [
316316

317317
[[package]]
318318
name = "miniscript"
319-
version = "12.3.3"
319+
version = "12.3.4"
320320
dependencies = [
321321
"bech32",
322322
"bitcoin",

Cargo-recent.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ dependencies = [
294294

295295
[[package]]
296296
name = "miniscript"
297-
version = "12.3.3"
297+
version = "12.3.4"
298298
dependencies = [
299299
"bech32",
300300
"bitcoin",

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "12.3.3"
3+
version = "12.3.4"
44
authors = ["Andrew Poelstra <apoelstra@wpsoftware.net>, Sanket Kanjalkar <sanket1729@gmail.com>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"

src/descriptor/key.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,23 @@ impl DescriptorPublicKey {
609609
}
610610
}
611611

612+
/// Whether or not the key has a wildcard
613+
pub fn has_hardened_step(&self) -> bool {
614+
let paths = match self {
615+
DescriptorPublicKey::Single(..) => &[],
616+
DescriptorPublicKey::XPub(xpub) => core::slice::from_ref(&xpub.derivation_path),
617+
DescriptorPublicKey::MultiXPub(xpub) => &xpub.derivation_paths.paths()[..],
618+
};
619+
for p in paths {
620+
for step in p.into_iter() {
621+
if step.is_hardened() {
622+
return true;
623+
}
624+
}
625+
}
626+
false
627+
}
628+
612629
#[deprecated(note = "use at_derivation_index instead")]
613630
/// Deprecated name for [`Self::at_derivation_index`].
614631
pub fn derive(self, index: u32) -> Result<DefiniteDescriptorKey, ConversionError> {
@@ -1037,7 +1054,7 @@ impl DefiniteDescriptorKey {
10371054
///
10381055
/// Returns `None` if the key contains a wildcard
10391056
fn new(key: DescriptorPublicKey) -> Option<Self> {
1040-
if key.has_wildcard() || key.is_multipath() {
1057+
if key.has_wildcard() || key.is_multipath() || key.has_hardened_step() {
10411058
None
10421059
} else {
10431060
Some(Self(key))
@@ -1071,7 +1088,7 @@ impl FromStr for DefiniteDescriptorKey {
10711088
fn from_str(s: &str) -> Result<Self, Self::Err> {
10721089
let inner = DescriptorPublicKey::from_str(s)?;
10731090
DefiniteDescriptorKey::new(inner).ok_or(DescriptorKeyParseError(
1074-
"cannot parse multi-path keys or keys with a wilcard as a DerivedDescriptorKey",
1091+
"cannot parse multi-path keys, keys with a wildcard or keys with hardened derivation steps as a DerivedDescriptorKey",
10751092
))
10761093
}
10771094
}
@@ -1516,5 +1533,10 @@ mod test {
15161533
.parse::<DescriptorPublicKey>()
15171534
.unwrap();
15181535
assert!(DefiniteDescriptorKey::new(desc).is_none());
1536+
// xpub with hardened path
1537+
let desc = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8/1'/2"
1538+
.parse::<DescriptorPublicKey>()
1539+
.unwrap();
1540+
assert!(DefiniteDescriptorKey::new(desc).is_none());
15191541
}
15201542
}

0 commit comments

Comments
 (0)