Skip to content

Commit da8d16c

Browse files
committed
CT descriptor: remove generic from blinding key
The generic was only used by the `Bare` variant, which was inconsistent with its corresponding "secret" variant, `View`. The generic could be used to handle the conversion from `ConfidentialDescriptor<DescriptorPublicKey>` to `Descriptor<DefiniteDescriptorKey>`, specifically making sure that the descriptor blinding key does not have wildcards. For the `Bare` variant this could be done, but this cannot happen for the `View` variant, since we don't have the definite version of `DescriptorSecretKey`.
1 parent 571e467 commit da8d16c

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/confidential/mod.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ use std::fmt;
2525
use elements::secp256k1_zkp;
2626

2727
use crate::descriptor::checksum::{desc_checksum, verify_checksum};
28-
use crate::descriptor::DescriptorSecretKey;
28+
use crate::descriptor::{DescriptorSecretKey, DescriptorPublicKey};
2929
use crate::expression::FromTree;
3030
use crate::extensions::{CovExtArgs, CovenantExt, Extension, ParseableExt};
3131
use crate::{expression, Error, MiniscriptKey, ToPublicKey};
3232

3333
/// A description of a blinding key
3434
#[derive(Clone, PartialEq, Eq, Debug)]
35-
pub enum Key<Pk: MiniscriptKey> {
35+
pub enum Key {
3636
/// Blinding key is computed using SLIP77 with the given master key
3737
Slip77(slip77::MasterBlindingKey),
3838
/// Blinding key is given directly
39-
Bare(Pk),
39+
Bare(DescriptorPublicKey),
4040
/// Blinding key is given directly, as a secret key
4141
View(DescriptorSecretKey),
4242
}
4343

44-
impl<Pk: MiniscriptKey> fmt::Display for Key<Pk> {
44+
impl fmt::Display for Key {
4545
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
4646
match self {
4747
Key::Slip77(data) => write!(f, "slip77({})", data),
@@ -51,15 +51,15 @@ impl<Pk: MiniscriptKey> fmt::Display for Key<Pk> {
5151
}
5252
}
5353

54-
impl<Pk: MiniscriptKey + ToPublicKey> Key<Pk> {
54+
impl Key {
5555
fn to_public_key<C: secp256k1_zkp::Signing + secp256k1_zkp::Verification>(
5656
&self,
5757
secp: &secp256k1_zkp::Secp256k1<C>,
5858
spk: &elements::Script,
5959
) -> secp256k1_zkp::PublicKey {
6060
match *self {
6161
Key::Slip77(ref mbk) => mbk.blinding_key(secp, spk),
62-
Key::Bare(ref pk) => bare::tweak_key(secp, spk, pk),
62+
Key::Bare(ref pk) => bare::tweak_key(secp, spk, &pk.clone().at_derivation_index(0).expect("FIXME deal with derivation paths properly")),
6363
Key::View(ref sk) => bare::tweak_key(secp, spk, &sk.to_public(secp).expect("view keys cannot be multipath keys").at_derivation_index(0).expect("FIXME deal with derivation paths properly")),
6464
}
6565
}
@@ -69,7 +69,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Key<Pk> {
6969
#[derive(Clone, PartialEq, Eq, Debug)]
7070
pub struct Descriptor<Pk: MiniscriptKey, T: Extension = CovenantExt<CovExtArgs>> {
7171
/// The blinding key
72-
pub key: Key<Pk>,
72+
pub key: Key,
7373
/// The script descriptor
7474
pub descriptor: crate::Descriptor<Pk, T>,
7575
}
@@ -137,7 +137,7 @@ impl_from_str!(
137137
("slip77", _) => return Err(Error::BadDescriptor(
138138
"slip77() must have exactly one argument".to_owned()
139139
)),
140-
_ => expression::terminal(keyexpr, Pk::from_str).map(Key::Bare)
140+
_ => expression::terminal(keyexpr, DescriptorPublicKey::from_str).map(Key::Bare)
141141
.or_else(|_| expression::terminal(keyexpr, DescriptorSecretKey::from_str).map(Key::View))?,
142142
},
143143
descriptor: crate::Descriptor::from_tree(&top.args[1])?,
@@ -161,7 +161,7 @@ mod tests {
161161
// taken from libwally src/test/test_confidential_addr.py
162162
let mut addr = Address::from_str("Q7qcjTLsYGoMA7TjUp97R6E6AM5VKqBik6").unwrap();
163163
let key = Key::Bare(
164-
bitcoin::PublicKey::from_str(
164+
DescriptorPublicKey::from_str(
165165
"02dce16018bbbb8e36de7b394df5b5166e9adb7498be7d881a85a09aeecf76b623",
166166
)
167167
.unwrap(),
@@ -174,7 +174,7 @@ mod tests {
174174
}
175175

176176
struct ConfidentialTest {
177-
key: Key<DefiniteDescriptorKey>,
177+
key: Key,
178178
descriptor: crate::Descriptor<DefiniteDescriptorKey, NoExt>,
179179
descriptor_str: String,
180180
conf_addr: &'static str,
@@ -231,7 +231,7 @@ mod tests {
231231
let secp = secp256k1_zkp::Secp256k1::new();
232232

233233
// CT key used for bare keys
234-
let ct_key = DefiniteDescriptorKey::from_str(
234+
let ct_key = DescriptorPublicKey::from_str(
235235
"xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL",
236236
)
237237
.unwrap();
@@ -370,7 +370,7 @@ mod tests {
370370
let view_key = DescriptorSecretKey::from_str(
371371
"xprv9s21ZrQH143K28NgQ7bHCF61hy9VzwquBZvpzTwXLsbmQLRJ6iV9k2hUBRt5qzmBaSpeMj5LdcsHaXJvM7iFEivPryRcL8irN7Na9p65UUb",
372372
).unwrap();
373-
let ct_key = view_key.to_public(&secp).unwrap().at_derivation_index(0).unwrap(); // FIXME figure out derivation
373+
let ct_key = view_key.to_public(&secp).unwrap();
374374
let spk_key = DefiniteDescriptorKey::from_str(
375375
"xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH",
376376
)

0 commit comments

Comments
 (0)