Skip to content

backport #830 to rust-miniscript 10.x #833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: release-10.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "miniscript"
version = "10.2.1"
version = "10.2.2"
authors = ["Andrew Poelstra <[email protected]>, Sanket Kanjalkar <[email protected]>"]
license = "CC0-1.0"
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"
Expand Down
25 changes: 22 additions & 3 deletions src/descriptor/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1058,7 +1058,7 @@ impl DefiniteDescriptorKey {
///
/// Returns `None` if the key contains a wildcard
fn new(key: DescriptorPublicKey) -> Option<Self> {
if key.has_wildcard() {
if key.has_wildcard() || key.is_multipath() {
None
} else {
Some(Self(key))
Expand Down Expand Up @@ -1092,7 +1092,7 @@ impl FromStr for DefiniteDescriptorKey {
fn from_str(s: &str) -> Result<Self, Self::Err> {
let inner = DescriptorPublicKey::from_str(s)?;
DefiniteDescriptorKey::new(inner).ok_or(DescriptorKeyParseError(
"cannot parse key with a wilcard as a DerivedDescriptorKey",
"cannot parse multi-path keys or keys with a wilcard as a DerivedDescriptorKey",
))
}
}
Expand Down Expand Up @@ -1190,7 +1190,7 @@ mod test {
DescriptorKeyParseError, DescriptorMultiXKey, DescriptorPublicKey, DescriptorSecretKey,
MiniscriptKey, Wildcard,
};
use crate::prelude::*;
use crate::{prelude::*, DefiniteDescriptorKey};

#[test]
fn parse_descriptor_key_errors() {
Expand Down Expand Up @@ -1571,4 +1571,23 @@ mod test {
let public_key = DescriptorPublicKey::from_str(desc).unwrap();
assert_tokens(&public_key, &[Token::String(desc)]);
}

#[test]
fn definite_keys() {
// basic xpub
let desc = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8"
.parse::<DescriptorPublicKey>()
.unwrap();
assert!(DefiniteDescriptorKey::new(desc).is_some());
// xpub with wildcard
let desc = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8/*"
.parse::<DescriptorPublicKey>()
.unwrap();
assert!(DefiniteDescriptorKey::new(desc).is_none());
// multipath xpub
let desc = "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8/<0;1>"
.parse::<DescriptorPublicKey>()
.unwrap();
assert!(DefiniteDescriptorKey::new(desc).is_none());
}
}
Loading