@@ -12,56 +12,68 @@ use bitcoin::{
1212
1313use { MiniscriptKey , ToPublicKey } ;
1414
15- /// Single public key without any origin or range information
16- #[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash ) ]
17- pub enum SinglePubKey {
18- /// FullKey (compressed or uncompressed)
19- FullKey ( bitcoin:: PublicKey ) ,
20- /// XOnlyPublicKey
21- XOnly ( XOnlyPublicKey ) ,
22- }
23-
24- /// The MiniscriptKey corresponding to Descriptors. This can
25- /// either be Single public key or a Xpub
15+ /// The descriptor pubkey, either a single pubkey or an xpub.
2616#[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash ) ]
2717pub enum DescriptorPublicKey {
28- /// Single Public Key
29- SinglePub ( DescriptorSinglePub ) ,
30- /// Xpub
18+ /// Single public key.
19+ Single ( SinglePub ) ,
20+ /// Extended public key (xpub).
3121 XPub ( DescriptorXKey < bip32:: ExtendedPubKey > ) ,
3222}
3323
34- /// A Single Descriptor Key with optional origin information
24+ /// The descriptor secret key, either a single private key or an xprv.
25+ #[ derive( Debug ) ]
26+ pub enum DescriptorSecretKey {
27+ /// Single private key.
28+ Single ( SinglePriv ) ,
29+ /// Extended private key (xpriv).
30+ XPrv ( DescriptorXKey < bip32:: ExtendedPrivKey > ) ,
31+ }
32+
33+ /// A descriptor [`SinglePubKey`] with optional origin information.
3534#[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash ) ]
36- pub struct DescriptorSinglePub {
37- /// Origin information
35+ pub struct SinglePub {
36+ /// Origin information (fingerprint and derivation path).
3837 pub origin : Option < ( bip32:: Fingerprint , bip32:: DerivationPath ) > ,
39- /// The key
38+ /// The public key.
4039 pub key : SinglePubKey ,
4140}
4241
43- /// A Single Descriptor Secret Key with optional origin information
42+ /// A descriptor [`bitcoin::PrivateKey`] with optional origin information.
4443#[ derive( Debug ) ]
45- pub struct DescriptorSinglePriv {
46- /// Origin information
47- pub origin : Option < bip32:: KeySource > ,
48- /// The key
44+ pub struct SinglePriv {
45+ /// Origin information (fingerprint and derivation path).
46+ pub origin : Option < ( bip32:: Fingerprint , bip32 :: DerivationPath ) > ,
47+ /// The private key.
4948 pub key : bitcoin:: PrivateKey ,
5049}
5150
52- /// A Secret Key that can be either a single key or an Xprv
53- #[ derive( Debug ) ]
54- pub enum DescriptorSecretKey {
55- /// Single Secret Key
56- SinglePriv ( DescriptorSinglePriv ) ,
57- /// Xprv
58- XPrv ( DescriptorXKey < bip32:: ExtendedPrivKey > ) ,
51+ /// An extended key with origin, derivation path, and wildcard.
52+ #[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash ) ]
53+ pub struct DescriptorXKey < K : InnerXKey > {
54+ /// Origin information
55+ pub origin : Option < ( bip32:: Fingerprint , bip32:: DerivationPath ) > ,
56+ /// The extended key
57+ pub xkey : K ,
58+ /// The derivation path
59+ pub derivation_path : bip32:: DerivationPath ,
60+ /// Whether the descriptor is wildcard
61+ pub wildcard : Wildcard ,
62+ }
63+
64+ /// Single public key without any origin or range information.
65+ #[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash ) ]
66+ pub enum SinglePubKey {
67+ /// A bitcoin public key (compressed or uncompressed).
68+ FullKey ( bitcoin:: PublicKey ) ,
69+ /// An xonly public key.
70+ XOnly ( XOnlyPublicKey ) ,
5971}
6072
6173impl fmt:: Display for DescriptorSecretKey {
6274 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6375 match self {
64- & DescriptorSecretKey :: SinglePriv ( ref sk) => {
76+ & DescriptorSecretKey :: Single ( ref sk) => {
6577 maybe_fmt_master_id ( f, & sk. origin ) ?;
6678 sk. key . fmt ( f) ?;
6779 Ok ( ( ) )
@@ -124,28 +136,15 @@ pub enum Wildcard {
124136 Hardened ,
125137}
126138
127- /// Instance of an extended key with origin and derivation path
128- #[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash ) ]
129- pub struct DescriptorXKey < K : InnerXKey > {
130- /// Origin information
131- pub origin : Option < ( bip32:: Fingerprint , bip32:: DerivationPath ) > ,
132- /// The extended key
133- pub xkey : K ,
134- /// The derivation path
135- pub derivation_path : bip32:: DerivationPath ,
136- /// Whether the descriptor is wildcard
137- pub wildcard : Wildcard ,
138- }
139-
140- impl DescriptorSinglePriv {
139+ impl SinglePriv {
141140 /// Returns the public key of this key
142141 fn as_public < C : Signing > (
143142 & self ,
144143 secp : & Secp256k1 < C > ,
145- ) -> Result < DescriptorSinglePub , DescriptorKeyParseError > {
144+ ) -> Result < SinglePub , DescriptorKeyParseError > {
146145 let pub_key = self . key . public_key ( secp) ;
147146
148- Ok ( DescriptorSinglePub {
147+ Ok ( SinglePub {
149148 origin : self . origin . clone ( ) ,
150149 key : SinglePubKey :: FullKey ( pub_key) ,
151150 } )
@@ -219,7 +218,7 @@ impl error::Error for DescriptorKeyParseError {}
219218impl fmt:: Display for DescriptorPublicKey {
220219 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
221220 match * self {
222- DescriptorPublicKey :: SinglePub ( ref pk) => {
221+ DescriptorPublicKey :: Single ( ref pk) => {
223222 maybe_fmt_master_id ( f, & pk. origin ) ?;
224223 match pk. key {
225224 SinglePubKey :: FullKey ( full_key) => full_key. fmt ( f) ,
@@ -244,7 +243,7 @@ impl fmt::Display for DescriptorPublicKey {
244243
245244impl DescriptorSecretKey {
246245 /// Return the public version of this key, by applying either
247- /// [`DescriptorSinglePriv ::as_public`] or [`DescriptorXKey<bip32::ExtendedPrivKey>::as_public`]
246+ /// [`SinglePriv ::as_public`] or [`DescriptorXKey<bip32::ExtendedPrivKey>::as_public`]
248247 /// depending on the type of key.
249248 ///
250249 /// If the key is an "XPrv", the hardened derivation steps will be applied before converting it
@@ -255,8 +254,8 @@ impl DescriptorSecretKey {
255254 secp : & Secp256k1 < C > ,
256255 ) -> Result < DescriptorPublicKey , DescriptorKeyParseError > {
257256 Ok ( match self {
258- & DescriptorSecretKey :: SinglePriv ( ref sk) => {
259- DescriptorPublicKey :: SinglePub ( sk. as_public ( secp) ?)
257+ & DescriptorSecretKey :: Single ( ref sk) => {
258+ DescriptorPublicKey :: Single ( sk. as_public ( secp) ?)
260259 }
261260 & DescriptorSecretKey :: XPrv ( ref xprv) => {
262261 DescriptorPublicKey :: XPub ( xprv. as_public ( secp) ?)
@@ -341,10 +340,7 @@ impl FromStr for DescriptorPublicKey {
341340 ) )
342341 }
343342 } ;
344- Ok ( DescriptorPublicKey :: SinglePub ( DescriptorSinglePub {
345- key,
346- origin,
347- } ) )
343+ Ok ( DescriptorPublicKey :: Single ( SinglePub { key, origin } ) )
348344 }
349345 }
350346}
@@ -385,7 +381,7 @@ impl DescriptorPublicKey {
385381 xpub. xkey . fingerprint ( )
386382 }
387383 }
388- DescriptorPublicKey :: SinglePub ( ref single) => {
384+ DescriptorPublicKey :: Single ( ref single) => {
389385 if let Some ( ( fingerprint, _) ) = single. origin {
390386 fingerprint
391387 } else {
@@ -417,7 +413,7 @@ impl DescriptorPublicKey {
417413 } ;
418414 origin_path. extend ( & xpub. derivation_path )
419415 }
420- DescriptorPublicKey :: SinglePub ( ref single) => {
416+ DescriptorPublicKey :: Single ( ref single) => {
421417 if let Some ( ( _, ref path) ) = single. origin {
422418 path. clone ( )
423419 } else {
@@ -430,7 +426,7 @@ impl DescriptorPublicKey {
430426 /// Whether or not the key has a wildcards
431427 pub fn is_deriveable ( & self ) -> bool {
432428 match * self {
433- DescriptorPublicKey :: SinglePub ( ..) => false ,
429+ DescriptorPublicKey :: Single ( ..) => false ,
434430 DescriptorPublicKey :: XPub ( ref xpub) => xpub. wildcard != Wildcard :: None ,
435431 }
436432 }
@@ -476,7 +472,7 @@ impl DescriptorPublicKey {
476472 secp : & Secp256k1 < C > ,
477473 ) -> Result < bitcoin:: PublicKey , ConversionError > {
478474 match * self {
479- DescriptorPublicKey :: SinglePub ( ref pk) => match pk. key {
475+ DescriptorPublicKey :: Single ( ref pk) => match pk. key {
480476 SinglePubKey :: FullKey ( pk) => Ok ( pk) ,
481477 SinglePubKey :: XOnly ( xpk) => Ok ( xpk. to_public_key ( ) ) ,
482478 } ,
@@ -504,7 +500,7 @@ impl FromStr for DescriptorSecretKey {
504500 if key_part. len ( ) <= 52 {
505501 let sk = bitcoin:: PrivateKey :: from_str ( key_part)
506502 . map_err ( |_| DescriptorKeyParseError ( "Error while parsing a WIF private key" ) ) ?;
507- Ok ( DescriptorSecretKey :: SinglePriv ( DescriptorSinglePriv {
503+ Ok ( DescriptorSecretKey :: Single ( SinglePriv {
508504 key : sk,
509505 origin : None ,
510506 } ) )
@@ -694,7 +690,7 @@ impl MiniscriptKey for DescriptorPublicKey {
694690
695691 fn is_uncompressed ( & self ) -> bool {
696692 match self {
697- DescriptorPublicKey :: SinglePub ( DescriptorSinglePub {
693+ DescriptorPublicKey :: Single ( SinglePub {
698694 key : SinglePubKey :: FullKey ( ref key) ,
699695 ..
700696 } ) => key. is_uncompressed ( ) ,
@@ -704,7 +700,7 @@ impl MiniscriptKey for DescriptorPublicKey {
704700
705701 fn is_x_only_key ( & self ) -> bool {
706702 match self {
707- DescriptorPublicKey :: SinglePub ( DescriptorSinglePub {
703+ DescriptorPublicKey :: Single ( SinglePub {
708704 key : SinglePubKey :: XOnly ( ref _key) ,
709705 ..
710706 } ) => true ,
0 commit comments