1+ use crate :: bitcoin:: Address ;
12use crate :: bitcoin:: DescriptorId ;
23use crate :: bitcoin:: DescriptorType ;
34use crate :: error:: DescriptorError ;
@@ -12,6 +13,7 @@ use bdk_wallet::chain::DescriptorExt;
1213use bdk_wallet:: descriptor:: { ExtendedDescriptor , IntoWalletDescriptor } ;
1314use bdk_wallet:: keys:: DescriptorPublicKey as BdkDescriptorPublicKey ;
1415use bdk_wallet:: keys:: { DescriptorSecretKey as BdkDescriptorSecretKey , KeyMap } ;
16+ use bdk_wallet:: miniscript:: descriptor:: ConversionError ;
1517use bdk_wallet:: template:: {
1618 Bip44 , Bip44Public , Bip49 , Bip49Public , Bip84 , Bip84Public , Bip86 , Bip86Public ,
1719 DescriptorTemplate ,
@@ -355,6 +357,30 @@ impl Descriptor {
355357 pub fn desc_type ( & self ) -> DescriptorType {
356358 self . extended_descriptor . desc_type ( )
357359 }
360+
361+ pub fn derived_address (
362+ & self ,
363+ index : u32 ,
364+ network : Network ,
365+ ) -> Result < Arc < Address > , DescriptorError > {
366+ let secp = Secp256k1 :: verification_only ( ) ;
367+ let derived_descriptor = self
368+ . extended_descriptor
369+ . at_derivation_index ( index)
370+ . and_then ( |desc| desc. derived_descriptor ( & secp) )
371+ . map_err ( |error| match error {
372+ ConversionError :: HardenedChild => DescriptorError :: HardenedDerivationXpub ,
373+ ConversionError :: MultiKey => DescriptorError :: MultiPath ,
374+ } ) ?;
375+ let script_pubkey = derived_descriptor. script_pubkey ( ) ;
376+ let address = bdk_wallet:: bitcoin:: Address :: from_script ( & script_pubkey, network) . map_err (
377+ |error| DescriptorError :: Miniscript {
378+ error_message : error. to_string ( ) ,
379+ } ,
380+ ) ?;
381+
382+ Ok ( Arc :: new ( address. into ( ) ) )
383+ }
358384}
359385
360386impl Display for Descriptor {
0 commit comments