Skip to content

Commit 353005c

Browse files
committed
Merge #66: elip150: handle x-only pubkeys
e6d6028 elip150: handle x-only pubkeys (Leonardo Comandini) Pull request description: In ELIP150, descriptor blinding keys cannot be x-only pubkeys. Thus if we have a 64 hex char descriptor blinding key, we need to interpret is as a single view descriptor blinding key. ACKs for top commit: RCasatta: utACK e6d6028 apoelstra: ACK e6d6028 Tree-SHA512: dd95fdfcefa2e1739f54edc4f4bd10459f40bf50e25465219cf17b6ef44803aca34a6c6cf0cbe732f67bc9cdf2b8cfc6c95a03b2e843ad13bc99379e33305526
2 parents 9dcc34a + e6d6028 commit 353005c

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/confidential/mod.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@ impl_from_str!(
220220
("slip77", _) => return Err(Error::BadDescriptor(
221221
"slip77() must have exactly one argument".to_owned()
222222
)),
223-
_ => expression::terminal(keyexpr, DescriptorPublicKey::from_str).map(Key::Bare)
224-
.or_else(|_| expression::terminal(keyexpr, |s: &str| DescriptorSecretKey::from_str_inner(s, true)).map(Key::View))?,
223+
_ => expression::terminal(keyexpr, |s: &str| DescriptorSecretKey::from_str_inner(s, true)).map(Key::View)
224+
.or_else(|_| expression::terminal(keyexpr, DescriptorPublicKey::from_str).map(Key::Bare))?,
225225
},
226226
descriptor: crate::Descriptor::from_tree(&top.args[1])?,
227227
})
@@ -432,7 +432,7 @@ mod tests {
432432
),
433433
(
434434
"ct(L3jXxwef3fpB7hcrFozcWgHeJCPSAFiZ1Ji2YJMPxceaGvy3PC1q,elwpkh(03774eec7a3d550d18e9f89414152025b3b0ad6a342b19481f702d843cff06dfc4))#gcy6hcfz",
435-
"unexpected «Error while parsing xkey.»",
435+
"unexpected «Key too short (<66 char), doesn't match any format»",
436436
),
437437
];
438438

@@ -504,6 +504,19 @@ mod tests {
504504
}
505505
}
506506

507+
#[test]
508+
fn view_xonly_pubkey_descriptor() {
509+
// View keys are 64 hex chars, but also x-only public keys are 64 hex chars
510+
let view_key = "ab16855a17319477d4283fe5c29cc7d047f81e8ffb199e20d9be1bc31a751c4c";
511+
// This view key can also be interpreted as a public key
512+
let _public_key = DescriptorPublicKey::from_str(view_key).unwrap();
513+
// But since compressed public keys are disallowed, it must be interpreted as a view key
514+
let pk = "021a8fb6bd5a653b021b98a2a785725b8ddacfe3687bc043aa7f4d25d3a48d40b5";
515+
let desc_str = format!("ct({view_key},elwpkh({pk}))#n9uc7tzt");
516+
let desc = Descriptor::<DefiniteDescriptorKey>::from_str(&desc_str).unwrap();
517+
assert!(matches!(desc.key, Key::View(_)));
518+
}
519+
507520
#[test]
508521
fn descriptor_wildcard() {
509522
let secp = secp256k1_zkp::Secp256k1::new();

0 commit comments

Comments
 (0)