Skip to content

Conversation

@reez
Copy link
Collaborator

@reez reez commented Nov 25, 2025

Description

exposing a helper to derive an address from a descriptor without building a wallet

follows miniscript’s recommended at_derivation_index → derived_descriptor flow to avoid panicy edge cases with unsupported descriptor https://docs.rs/miniscript/12.3.5/src/miniscript/descriptor/mod.rs.html#886

Notes to the reviewers

tests covering both the happy path and multipath error mapping

Documentation

The helper includes these

Checklists

All Submissions:

  • I've signed all my commits
  • I followed the contribution guidelines
  • I ran cargo fmt and cargo clippy before committing
  • I've added a changelog in the next release tracking issue (see example)
  • I've linked the relevant upstream docs or specs above

New Features:

  • I've added tests for the new feature
  • I've added docs for the new feature

Bugfixes:

  • This pull request breaks the existing API
  • I've added tests to reproduce the issue which are now passing
  • I'm linking the issue being fixed by this PR

@reez
Copy link
Collaborator Author

reez commented Nov 25, 2025

Need to add changelog once this comes out of Draft

@reez
Copy link
Collaborator Author

reez commented Nov 25, 2025

CI passes except for Android but I think that's a known thing atm

@reez reez changed the title (draft)feat: expose derived_address helper on Descriptor feat: expose derived_address helper on Descriptor Nov 26, 2025
@reez reez marked this pull request as ready for review November 26, 2025 15:02
@reez reez linked an issue Nov 26, 2025 that may be closed by this pull request
@reez reez requested a review from thunderbiscuit November 26, 2025 15:02
Copy link
Member

@thunderbiscuit thunderbiscuit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure of the exact difference between the two approaches (also the bdk_wallet type is a wrapper around the rust-bitcoin type and so has new methods I wasn't aware of initially), so let me know if this is wrong somehow but I was able to do away with the use of dervied_descriptor entirely and simplify quite a bit (mind you with handling the errors it will get bigger):

Currently:

let secp = Secp256k1::verification_only();
let derived_descriptor = self
    .extended_descriptor
    .at_derivation_index(index)
    .and_then(|desc| desc.derived_descriptor(&secp))
    .map_err(|error| match error {
        ConversionError::HardenedChild => DescriptorError::HardenedDerivationXpub,
        ConversionError::MultiKey => DescriptorError::MultiPath,
    })?;

let script_pubkey = derived_descriptor.script_pubkey();
let address =
    Address::from_script(Arc::new(Script(script_pubkey)), network).map_err(|error| {
        DescriptorError::Miniscript {
            error_message: error.to_string(),
        }
    })?;

Ok(Arc::new(address)

Can be rewritten as:

let definite_descriptor = self.extended_descriptor.at_derivation_index(index).unwrap();
let address = definite_descriptor.address(network).unwrap();
        
Ok(Arc::new(address.into()))

Let me know if I'm missing something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Derive address directly from Descriptor in swift-bdk

2 participants