Skip to content

Commit 1385aa7

Browse files
committed
Merge #842: backport #839 (DefiniteDescriptorKey fixes) to 10.x
d61103f bump version to 10.2.3 (Andrew Poelstra) ac76ce0 key: fix DefiniteDescriptorKey construction from key with hardened step (Andrew Poelstra) Pull request description: ACKs for top commit: sanket1729: utACK d61103f Tree-SHA512: 364519c25c47ebc439ee927321bf058fce9047ca790c180e4df4c73b306c1b480ff7cb14f223bb031c31751c2f42d3b5ad79a2149b952dd608b98ea87440e063
2 parents b9dea66 + d61103f commit 1385aa7

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Cargo-recent.lock

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

262262
[[package]]
263263
name = "miniscript"
264-
version = "10.2.2"
264+
version = "10.2.3"
265265
dependencies = [
266266
"base64",
267267
"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 = "10.2.2"
3+
version = "10.2.3"
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
@@ -607,6 +607,23 @@ impl DescriptorPublicKey {
607607
}
608608
}
609609

610+
/// Whether or not the key has a wildcard
611+
pub fn has_hardened_step(&self) -> bool {
612+
let paths = match self {
613+
DescriptorPublicKey::Single(..) => &[],
614+
DescriptorPublicKey::XPub(xpub) => core::slice::from_ref(&xpub.derivation_path),
615+
DescriptorPublicKey::MultiXPub(xpub) => &xpub.derivation_paths.paths()[..],
616+
};
617+
for p in paths {
618+
for step in p.into_iter() {
619+
if step.is_hardened() {
620+
return true;
621+
}
622+
}
623+
}
624+
false
625+
}
626+
610627
#[deprecated(note = "use at_derivation_index instead")]
611628
/// Deprecated name for [`Self::at_derivation_index`].
612629
pub fn derive(self, index: u32) -> Result<DefiniteDescriptorKey, ConversionError> {
@@ -1055,7 +1072,7 @@ impl DefiniteDescriptorKey {
10551072
///
10561073
/// Returns `None` if the key contains a wildcard
10571074
fn new(key: DescriptorPublicKey) -> Option<Self> {
1058-
if key.has_wildcard() || key.is_multipath() {
1075+
if key.has_wildcard() || key.is_multipath() || key.has_hardened_step() {
10591076
None
10601077
} else {
10611078
Some(Self(key))
@@ -1089,7 +1106,7 @@ impl FromStr for DefiniteDescriptorKey {
10891106
fn from_str(s: &str) -> Result<Self, Self::Err> {
10901107
let inner = DescriptorPublicKey::from_str(s)?;
10911108
DefiniteDescriptorKey::new(inner).ok_or(DescriptorKeyParseError(
1092-
"cannot parse multi-path keys or keys with a wilcard as a DerivedDescriptorKey",
1109+
"cannot parse multi-path keys, keys with a wildcard or keys with hardened derivation steps as a DerivedDescriptorKey",
10931110
))
10941111
}
10951112
}
@@ -1587,5 +1604,10 @@ mod test {
15871604
.parse::<DescriptorPublicKey>()
15881605
.unwrap();
15891606
assert!(DefiniteDescriptorKey::new(desc).is_none());
1607+
// xpub with hardened path
1608+
let desc = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8/1'/2"
1609+
.parse::<DescriptorPublicKey>()
1610+
.unwrap();
1611+
assert!(DefiniteDescriptorKey::new(desc).is_none());
15901612
}
15911613
}

0 commit comments

Comments
 (0)