@@ -20,6 +20,7 @@ use crate::{hash256, MiniscriptKey, ToPublicKey};
2020
2121type DescriptorSinglePublicKey = SinglePub ;
2222type DescriptorExtendedPublicKey = DescriptorXKey < bip32:: ExtendedPubKey > ;
23+ type DescriptorMultiExtendedPublicKey = DescriptorMultiXKey < bip32:: ExtendedPubKey > ;
2324
2425/// The descriptor pubkey, either a single pubkey or an xpub.
2526#[ derive( Debug , Eq , PartialEq , Clone , Ord , PartialOrd , Hash ) ]
@@ -29,7 +30,7 @@ pub enum DescriptorPublicKey {
2930 /// Extended public key (xpub).
3031 XPub ( DescriptorExtendedPublicKey ) ,
3132 /// Multiple extended public keys.
32- MultiXPub ( DescriptorMultiXKey < bip32 :: ExtendedPubKey > ) ,
33+ MultiXPub ( DescriptorMultiExtendedPublicKey ) ,
3334}
3435
3536/// The descriptor secret key, either a single private key or an xprv.
@@ -311,22 +312,26 @@ impl fmt::Display for DescriptorExtendedPublicKey {
311312 }
312313}
313314
315+ impl fmt:: Display for DescriptorMultiExtendedPublicKey {
316+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
317+ maybe_fmt_master_id ( f, & self . origin ) ?;
318+ self . xkey . fmt ( f) ?;
319+ fmt_derivation_paths ( f, self . derivation_paths . paths ( ) ) ?;
320+ match self . wildcard {
321+ Wildcard :: None => { }
322+ Wildcard :: Unhardened => write ! ( f, "/*" ) ?,
323+ Wildcard :: Hardened => write ! ( f, "/*h" ) ?,
324+ }
325+ Ok ( ( ) )
326+ }
327+ }
328+
314329impl fmt:: Display for DescriptorPublicKey {
315330 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
316331 match * self {
317332 DescriptorPublicKey :: Single ( ref pk) => pk. fmt ( f) ,
318333 DescriptorPublicKey :: XPub ( ref xpub) => xpub. fmt ( f) ,
319- DescriptorPublicKey :: MultiXPub ( ref xpub) => {
320- maybe_fmt_master_id ( f, & xpub. origin ) ?;
321- xpub. xkey . fmt ( f) ?;
322- fmt_derivation_paths ( f, xpub. derivation_paths . paths ( ) ) ?;
323- match xpub. wildcard {
324- Wildcard :: None => { }
325- Wildcard :: Unhardened => write ! ( f, "/*" ) ?,
326- Wildcard :: Hardened => write ! ( f, "/*h" ) ?,
327- }
328- Ok ( ( ) )
329- }
334+ DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. fmt ( f) ,
330335 }
331336 }
332337}
@@ -664,18 +669,38 @@ impl DescriptorInnerKey for DescriptorExtendedPublicKey {
664669 }
665670}
666671
672+ impl DescriptorInnerKey for DescriptorMultiExtendedPublicKey {
673+ fn master_fingerprint ( & self ) -> bip32:: Fingerprint {
674+ if let Some ( ( fingerprint, _) ) = self . origin {
675+ fingerprint
676+ } else {
677+ self . xkey . fingerprint ( )
678+ }
679+ }
680+
681+ fn full_derivation_path ( & self ) -> Option < bip32:: DerivationPath > {
682+ None
683+ }
684+
685+ fn has_wildcard ( & self ) -> bool {
686+ self . wildcard != Wildcard :: None
687+ }
688+
689+ fn at_derivation_index ( self , _index : u32 ) -> Result < DefiniteDescriptorKey , ConversionError > {
690+ Err ( ConversionError :: MultiKey )
691+ }
692+
693+ fn is_multipath ( & self ) -> bool {
694+ true
695+ }
696+ }
697+
667698impl DescriptorPublicKey {
668699 /// The fingerprint of the master key associated with this key, `0x00000000` if none.
669700 pub fn master_fingerprint ( & self ) -> bip32:: Fingerprint {
670701 match * self {
671702 DescriptorPublicKey :: XPub ( ref xpub) => xpub. master_fingerprint ( ) ,
672- DescriptorPublicKey :: MultiXPub ( ref xpub) => {
673- if let Some ( ( fingerprint, _) ) = xpub. origin {
674- fingerprint
675- } else {
676- xpub. xkey . fingerprint ( )
677- }
678- }
703+ DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. master_fingerprint ( ) ,
679704 DescriptorPublicKey :: Single ( ref single) => single. master_fingerprint ( ) ,
680705 }
681706 }
@@ -691,7 +716,7 @@ impl DescriptorPublicKey {
691716 match * self {
692717 DescriptorPublicKey :: XPub ( ref xpub) => xpub. full_derivation_path ( ) ,
693718 DescriptorPublicKey :: Single ( ref single) => single. full_derivation_path ( ) ,
694- DescriptorPublicKey :: MultiXPub ( _) => None ,
719+ DescriptorPublicKey :: MultiXPub ( _) => self . full_derivation_path ( ) ,
695720 }
696721 }
697722
@@ -706,7 +731,7 @@ impl DescriptorPublicKey {
706731 match * self {
707732 DescriptorPublicKey :: Single ( ref single) => single. has_wildcard ( ) ,
708733 DescriptorPublicKey :: XPub ( ref xpub) => xpub. has_wildcard ( ) ,
709- DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. wildcard != Wildcard :: None ,
734+ DescriptorPublicKey :: MultiXPub ( ref xpub) => xpub. has_wildcard ( ) ,
710735 }
711736 }
712737
@@ -732,15 +757,15 @@ impl DescriptorPublicKey {
732757 match self {
733758 DescriptorPublicKey :: Single ( single) => single. at_derivation_index ( index) ,
734759 DescriptorPublicKey :: XPub ( xpub) => xpub. at_derivation_index ( index) ,
735- DescriptorPublicKey :: MultiXPub ( _ ) => Err ( ConversionError :: MultiKey ) ,
760+ DescriptorPublicKey :: MultiXPub ( xpub ) => xpub . at_derivation_index ( index ) ,
736761 }
737762 }
738763
739764 /// Whether or not this key has multiple derivation paths.
740765 pub fn is_multipath ( & self ) -> bool {
741766 match * self {
742767 DescriptorPublicKey :: Single ( ..) | DescriptorPublicKey :: XPub ( ..) => self . is_multipath ( ) ,
743- DescriptorPublicKey :: MultiXPub ( _) => true ,
768+ DescriptorPublicKey :: MultiXPub ( _) => self . is_multipath ( ) ,
744769 }
745770 }
746771
@@ -1458,7 +1483,7 @@ mod test {
14581483 fn get_multipath_xpub (
14591484 key_str : & str ,
14601485 num_paths : usize ,
1461- ) -> DescriptorMultiXKey < bip32 :: ExtendedPubKey > {
1486+ ) -> DescriptorMultiExtendedPublicKey {
14621487 let desc_key = DescriptorPublicKey :: from_str ( key_str) . unwrap ( ) ;
14631488 assert_eq ! ( desc_key. num_der_paths( ) , num_paths) ;
14641489 match desc_key {
0 commit comments