@@ -20,6 +20,7 @@ use crate::{hash256, MiniscriptKey, ToPublicKey};
20
20
21
21
type DescriptorSinglePublicKey = SinglePub ;
22
22
type DescriptorExtendedPublicKey = DescriptorXKey < bip32:: ExtendedPubKey > ;
23
+ type DescriptorMultiExtendedPublicKey = DescriptorMultiXKey < bip32:: ExtendedPubKey > ;
23
24
24
25
/// The descriptor pubkey, either a single pubkey or an xpub.
25
26
#[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash ) ]
@@ -29,7 +30,7 @@ pub enum DescriptorPublicKey {
29
30
/// Extended public key (xpub).
30
31
XPub ( DescriptorExtendedPublicKey ) ,
31
32
/// Multiple extended public keys.
32
- MultiXPub ( DescriptorMultiXKey < bip32 :: ExtendedPubKey > ) ,
33
+ MultiXPub ( DescriptorMultiExtendedPublicKey ) ,
33
34
}
34
35
35
36
/// The descriptor secret key, either a single private key or an xprv.
@@ -310,22 +311,26 @@ impl fmt::Display for DescriptorExtendedPublicKey {
310
311
}
311
312
}
312
313
314
+ impl fmt:: Display for DescriptorMultiExtendedPublicKey {
315
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
316
+ maybe_fmt_master_id ( f, & self . origin ) ?;
317
+ self . xkey . fmt ( f) ?;
318
+ fmt_derivation_paths ( f, self . derivation_paths . paths ( ) ) ?;
319
+ match self . wildcard {
320
+ Wildcard :: None => { }
321
+ Wildcard :: Unhardened => write ! ( f, "/*" ) ?,
322
+ Wildcard :: Hardened => write ! ( f, "/*h" ) ?,
323
+ }
324
+ Ok ( ( ) )
325
+ }
326
+ }
327
+
313
328
impl fmt:: Display for DescriptorPublicKey {
314
329
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
315
330
match * self {
316
331
DescriptorPublicKey :: Single ( ref pk) => pk. fmt ( f) ,
317
332
DescriptorPublicKey :: XPub ( ref xpub) => xpub. fmt ( f) ,
318
- DescriptorPublicKey :: MultiXPub ( ref xpub) => {
319
- maybe_fmt_master_id ( f, & xpub. origin ) ?;
320
- xpub. xkey . fmt ( f) ?;
321
- fmt_derivation_paths ( f, xpub. derivation_paths . paths ( ) ) ?;
322
- match xpub. wildcard {
323
- Wildcard :: None => { }
324
- Wildcard :: Unhardened => write ! ( f, "/*" ) ?,
325
- Wildcard :: Hardened => write ! ( f, "/*h" ) ?,
326
- }
327
- Ok ( ( ) )
328
- }
333
+ DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. fmt ( f) ,
329
334
}
330
335
}
331
336
}
@@ -687,18 +692,38 @@ impl DescriptorInnerKey for DescriptorExtendedPublicKey {
687
692
}
688
693
}
689
694
695
+ impl DescriptorInnerKey for DescriptorMultiExtendedPublicKey {
696
+ fn master_fingerprint ( & self ) -> bip32:: Fingerprint {
697
+ if let Some ( ( fingerprint, _) ) = self . origin {
698
+ fingerprint
699
+ } else {
700
+ self . xkey . fingerprint ( )
701
+ }
702
+ }
703
+
704
+ fn full_derivation_path ( & self ) -> Option < bip32:: DerivationPath > {
705
+ None
706
+ }
707
+
708
+ fn has_wildcard ( & self ) -> bool {
709
+ self . wildcard != Wildcard :: None
710
+ }
711
+
712
+ fn at_derivation_index ( self , _index : u32 ) -> Result < DefiniteDescriptorKey , ConversionError > {
713
+ Err ( ConversionError :: MultiKey )
714
+ }
715
+
716
+ fn is_multipath ( & self ) -> bool {
717
+ true
718
+ }
719
+ }
720
+
690
721
impl DescriptorPublicKey {
691
722
/// The fingerprint of the master key associated with this key, `0x00000000` if none.
692
723
pub fn master_fingerprint ( & self ) -> bip32:: Fingerprint {
693
724
match * self {
694
725
DescriptorPublicKey :: XPub ( ref xpub) => xpub. master_fingerprint ( ) ,
695
- DescriptorPublicKey :: MultiXPub ( ref xpub) => {
696
- if let Some ( ( fingerprint, _) ) = xpub. origin {
697
- fingerprint
698
- } else {
699
- xpub. xkey . fingerprint ( )
700
- }
701
- }
726
+ DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. master_fingerprint ( ) ,
702
727
DescriptorPublicKey :: Single ( ref single) => single. master_fingerprint ( ) ,
703
728
}
704
729
}
@@ -714,7 +739,7 @@ impl DescriptorPublicKey {
714
739
match * self {
715
740
DescriptorPublicKey :: XPub ( ref xpub) => xpub. full_derivation_path ( ) ,
716
741
DescriptorPublicKey :: Single ( ref single) => single. full_derivation_path ( ) ,
717
- DescriptorPublicKey :: MultiXPub ( _ ) => None ,
742
+ DescriptorPublicKey :: MultiXPub ( ref xpub ) => xpub . full_derivation_path ( ) ,
718
743
}
719
744
}
720
745
@@ -729,7 +754,7 @@ impl DescriptorPublicKey {
729
754
match * self {
730
755
DescriptorPublicKey :: Single ( ref single) => single. has_wildcard ( ) ,
731
756
DescriptorPublicKey :: XPub ( ref xpub) => xpub. has_wildcard ( ) ,
732
- DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. wildcard != Wildcard :: None ,
757
+ DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. has_wildcard ( ) ,
733
758
}
734
759
}
735
760
@@ -755,7 +780,7 @@ impl DescriptorPublicKey {
755
780
match self {
756
781
DescriptorPublicKey :: Single ( single) => single. at_derivation_index ( index) ,
757
782
DescriptorPublicKey :: XPub ( xpub) => xpub. at_derivation_index ( index) ,
758
- DescriptorPublicKey :: MultiXPub ( _ ) => Err ( ConversionError :: MultiKey ) ,
783
+ DescriptorPublicKey :: MultiXPub ( xpub ) => xpub . at_derivation_index ( index ) ,
759
784
}
760
785
}
761
786
@@ -764,7 +789,7 @@ impl DescriptorPublicKey {
764
789
match self {
765
790
DescriptorPublicKey :: Single ( single) => single. is_multipath ( ) ,
766
791
DescriptorPublicKey :: XPub ( xpub) => xpub. is_multipath ( ) ,
767
- DescriptorPublicKey :: MultiXPub ( _ ) => true ,
792
+ DescriptorPublicKey :: MultiXPub ( xpub ) => xpub . is_multipath ( ) ,
768
793
}
769
794
}
770
795
0 commit comments