Skip to content

Commit 19f4e06

Browse files
committed
Merge #344: Enforce that x-only keys cannot be used in non-tr descriptors
8212b9c Add breaking test testing x-only keys in non-tr descriptors (sanket1729) 7ef4fdc Enforce that x-only keys cannot be used in non-tr descriptors (sanket1729) Pull request description: Reported by: @afilini . This was a copy-paste error on my side :( ACKs for top commit: afilini: ACK 8212b9c apoelstra: ACK 8212b9c Tree-SHA512: 22b71b72eb2ba5207d4581fa358c8146fb103cf0b2b80c6235d1cde8066acad6ed1aaab9cf997f11882981967fc8a869c4b35501f2e203ae1950079f73619439
2 parents 8426519 + 8212b9c commit 19f4e06

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

src/descriptor/key.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -705,9 +705,9 @@ impl MiniscriptKey for DescriptorPublicKey {
705705
fn is_x_only_key(&self) -> bool {
706706
match self {
707707
DescriptorPublicKey::SinglePub(DescriptorSinglePub {
708-
key: SinglePubKey::FullKey(ref key),
708+
key: SinglePubKey::XOnly(ref _key),
709709
..
710-
}) => key.is_x_only_key(),
710+
}) => true,
711711
_ => false,
712712
}
713713
}

src/descriptor/mod.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1721,4 +1721,19 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
17211721
let descriptor: Descriptor<DescriptorPublicKey> = descriptor_str.parse().unwrap();
17221722
assert_eq!(descriptor.to_string(), "sh(wsh(pk(xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL)))#6c6hwr22");
17231723
}
1724+
1725+
#[test]
1726+
fn test_xonly_keys() {
1727+
let comp_key = "0308c0fcf8895f4361b4fc77afe2ad53b0bd27dcebfd863421b2b246dc283d4103";
1728+
let x_only_key = "08c0fcf8895f4361b4fc77afe2ad53b0bd27dcebfd863421b2b246dc283d4103";
1729+
1730+
// Both x-only keys and comp keys allowed in tr
1731+
Descriptor::<DescriptorPublicKey>::from_str(&format!("tr({})", comp_key)).unwrap();
1732+
Descriptor::<DescriptorPublicKey>::from_str(&format!("tr({})", x_only_key)).unwrap();
1733+
1734+
// Only compressed keys allowed in wsh
1735+
Descriptor::<DescriptorPublicKey>::from_str(&format!("wsh(pk({}))", comp_key)).unwrap();
1736+
Descriptor::<DescriptorPublicKey>::from_str(&format!("wsh(pk({}))", x_only_key))
1737+
.unwrap_err();
1738+
}
17241739
}

0 commit comments

Comments
 (0)