@@ -25,23 +25,23 @@ use std::fmt;
25
25
use elements:: secp256k1_zkp;
26
26
27
27
use crate :: descriptor:: checksum:: { desc_checksum, verify_checksum} ;
28
- use crate :: descriptor:: DescriptorSecretKey ;
28
+ use crate :: descriptor:: { DescriptorSecretKey , DescriptorPublicKey } ;
29
29
use crate :: expression:: FromTree ;
30
30
use crate :: extensions:: { CovExtArgs , CovenantExt , Extension , ParseableExt } ;
31
31
use crate :: { expression, Error , MiniscriptKey , ToPublicKey } ;
32
32
33
33
/// A description of a blinding key
34
34
#[ derive( Clone , PartialEq , Eq , Debug ) ]
35
- pub enum Key < Pk : MiniscriptKey > {
35
+ pub enum Key {
36
36
/// Blinding key is computed using SLIP77 with the given master key
37
37
Slip77 ( slip77:: MasterBlindingKey ) ,
38
38
/// Blinding key is given directly
39
- Bare ( Pk ) ,
39
+ Bare ( DescriptorPublicKey ) ,
40
40
/// Blinding key is given directly, as a secret key
41
41
View ( DescriptorSecretKey ) ,
42
42
}
43
43
44
- impl < Pk : MiniscriptKey > fmt:: Display for Key < Pk > {
44
+ impl fmt:: Display for Key {
45
45
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
46
46
match self {
47
47
Key :: Slip77 ( data) => write ! ( f, "slip77({})" , data) ,
@@ -51,15 +51,15 @@ impl<Pk: MiniscriptKey> fmt::Display for Key<Pk> {
51
51
}
52
52
}
53
53
54
- impl < Pk : MiniscriptKey + ToPublicKey > Key < Pk > {
54
+ impl Key {
55
55
fn to_public_key < C : secp256k1_zkp:: Signing + secp256k1_zkp:: Verification > (
56
56
& self ,
57
57
secp : & secp256k1_zkp:: Secp256k1 < C > ,
58
58
spk : & elements:: Script ,
59
59
) -> secp256k1_zkp:: PublicKey {
60
60
match * self {
61
61
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" ) ) ,
63
63
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" ) ) ,
64
64
}
65
65
}
@@ -69,7 +69,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Key<Pk> {
69
69
#[ derive( Clone , PartialEq , Eq , Debug ) ]
70
70
pub struct Descriptor < Pk : MiniscriptKey , T : Extension = CovenantExt < CovExtArgs > > {
71
71
/// The blinding key
72
- pub key : Key < Pk > ,
72
+ pub key : Key ,
73
73
/// The script descriptor
74
74
pub descriptor : crate :: Descriptor < Pk , T > ,
75
75
}
@@ -137,7 +137,7 @@ impl_from_str!(
137
137
( "slip77" , _) => return Err ( Error :: BadDescriptor (
138
138
"slip77() must have exactly one argument" . to_owned( )
139
139
) ) ,
140
- _ => expression:: terminal( keyexpr, Pk :: from_str) . map( Key :: Bare )
140
+ _ => expression:: terminal( keyexpr, DescriptorPublicKey :: from_str) . map( Key :: Bare )
141
141
. or_else( |_| expression:: terminal( keyexpr, DescriptorSecretKey :: from_str) . map( Key :: View ) ) ?,
142
142
} ,
143
143
descriptor: crate :: Descriptor :: from_tree( & top. args[ 1 ] ) ?,
@@ -161,7 +161,7 @@ mod tests {
161
161
// taken from libwally src/test/test_confidential_addr.py
162
162
let mut addr = Address :: from_str ( "Q7qcjTLsYGoMA7TjUp97R6E6AM5VKqBik6" ) . unwrap ( ) ;
163
163
let key = Key :: Bare (
164
- bitcoin :: PublicKey :: from_str (
164
+ DescriptorPublicKey :: from_str (
165
165
"02dce16018bbbb8e36de7b394df5b5166e9adb7498be7d881a85a09aeecf76b623" ,
166
166
)
167
167
. unwrap ( ) ,
@@ -174,7 +174,7 @@ mod tests {
174
174
}
175
175
176
176
struct ConfidentialTest {
177
- key : Key < DefiniteDescriptorKey > ,
177
+ key : Key ,
178
178
descriptor : crate :: Descriptor < DefiniteDescriptorKey , NoExt > ,
179
179
descriptor_str : String ,
180
180
conf_addr : & ' static str ,
@@ -231,7 +231,7 @@ mod tests {
231
231
let secp = secp256k1_zkp:: Secp256k1 :: new ( ) ;
232
232
233
233
// CT key used for bare keys
234
- let ct_key = DefiniteDescriptorKey :: from_str (
234
+ let ct_key = DescriptorPublicKey :: from_str (
235
235
"xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL" ,
236
236
)
237
237
. unwrap ( ) ;
@@ -370,7 +370,7 @@ mod tests {
370
370
let view_key = DescriptorSecretKey :: from_str (
371
371
"xprv9s21ZrQH143K28NgQ7bHCF61hy9VzwquBZvpzTwXLsbmQLRJ6iV9k2hUBRt5qzmBaSpeMj5LdcsHaXJvM7iFEivPryRcL8irN7Na9p65UUb" ,
372
372
) . 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 ( ) ;
374
374
let spk_key = DefiniteDescriptorKey :: from_str (
375
375
"xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH" ,
376
376
)
0 commit comments