@@ -8,7 +8,7 @@ use bdk_wallet::bitcoin::secp256k1::{PublicKey, Secp256k1, Signing};
88use bdk_wallet:: bitcoin:: { Address , CompressedPublicKey , Network , TxOut } ;
99use bdk_wallet:: descriptor:: { Descriptor , ExtendedDescriptor , Segwitv0 } ;
1010use bdk_wallet:: keys:: DescriptorPublicKey ;
11- use bdk_wallet:: miniscript:: descriptor:: { DerivPaths , DescriptorMultiXKey , Wildcard } ;
11+ use bdk_wallet:: miniscript:: descriptor:: { DescriptorXKey , Wildcard } ;
1212use bdk_wallet:: miniscript:: descriptor:: { Sh , Wpkh } ;
1313use bdk_wallet:: miniscript:: { ForEachKey , Miniscript } ;
1414use bdk_wallet:: template:: { Bip49Public , DescriptorTemplate } ;
@@ -187,7 +187,7 @@ pub fn wsh_multisig_descriptor(
187187 required_signers : u8 ,
188188 global_xpubs : & BTreeMap < Xpub , KeySource > ,
189189 bip32_derivations : & BTreeMap < PublicKey , KeySource > ,
190- ) -> Result < ExtendedDescriptor , Error > {
190+ ) -> Result < [ ExtendedDescriptor ; 2 ] , Error > {
191191 // Find the account Xpubs in the global Xpub map of the PSBT.
192192 let xpubs = bip32_derivations
193193 . iter ( )
@@ -201,26 +201,35 @@ pub fn wsh_multisig_descriptor(
201201 . ok_or_else ( || Error :: MissingGlobalXpub ( subpath. clone ( ) ) )
202202 } ) ;
203203
204- let mut descriptor_pubkeys = Vec :: new ( ) ;
204+ let mut external_keys = Vec :: new ( ) ;
205+ let mut internal_keys = Vec :: new ( ) ;
205206 for maybe_xpub in xpubs {
206207 let ( xpub, source) = maybe_xpub?;
207208
208- let descriptor_pubkey = DescriptorPublicKey :: MultiXPub ( DescriptorMultiXKey {
209+ let external_key = DescriptorPublicKey :: XPub ( DescriptorXKey {
209210 origin : Some ( source. clone ( ) ) ,
210211 xkey : * xpub,
211- derivation_paths : DerivPaths :: new ( vec ! [
212- DerivationPath :: from( vec![ ChildNumber :: Normal { index: 0 } ] ) ,
213- DerivationPath :: from( vec![ ChildNumber :: Normal { index: 1 } ] ) ,
214- ] )
215- . expect ( "the vector passed should not be empty" ) ,
212+ derivation_path : DerivationPath :: from ( vec ! [ ChildNumber :: Normal { index: 0 } ] ) ,
216213 wildcard : Wildcard :: Unhardened ,
217214 } ) ;
218- descriptor_pubkeys. push ( descriptor_pubkey) ;
215+
216+ let internal_key = DescriptorPublicKey :: XPub ( DescriptorXKey {
217+ origin : Some ( source. clone ( ) ) ,
218+ xkey : * xpub,
219+ derivation_path : DerivationPath :: from ( vec ! [ ChildNumber :: Normal { index: 1 } ] ) ,
220+ wildcard : Wildcard :: Unhardened ,
221+ } ) ;
222+
223+ external_keys. push ( external_key) ;
224+ internal_keys. push ( internal_key) ;
219225 }
220226
221- Ok ( ExtendedDescriptor :: new_sh_wsh_sortedmulti (
222- usize:: from ( required_signers) ,
223- descriptor_pubkeys,
224- )
225- . unwrap ( ) )
227+ let external_descriptor =
228+ ExtendedDescriptor :: new_sh_wsh_sortedmulti ( usize:: from ( required_signers) , external_keys)
229+ . unwrap ( ) ;
230+ let internal_descriptor =
231+ ExtendedDescriptor :: new_sh_wsh_sortedmulti ( usize:: from ( required_signers) , internal_keys)
232+ . unwrap ( ) ;
233+
234+ Ok ( [ external_descriptor, internal_descriptor] )
226235}
0 commit comments