Skip to content

Return error from at_derivation_index when descriptor has no wildcard#911

Open
febyeji wants to merge 3 commits intorust-bitcoin:masterfrom
febyeji:at-derivation-index-no-wildcard
Open

Return error from at_derivation_index when descriptor has no wildcard#911
febyeji wants to merge 3 commits intorust-bitcoin:masterfrom
febyeji:at-derivation-index-no-wildcard

Conversation

@febyeji
Copy link
Copy Markdown

@febyeji febyeji commented Mar 27, 2026

Closes #829.

  • Previously, calling at_derivation_index() on a descriptor without wildcards would silently ignore the index and return the descriptor unchanged. This was error-prone because callers would expect different indices to produce different addresses.
  • Callers that need to convert a non-wildcard descriptor to a definite one should use DefiniteDescriptorKey::new() on individual keys, or check has_wildcard() before calling at_derivation_index().
  • Add edge case tests for at_derivation_index wildcard check

Copy link
Copy Markdown
Contributor

@trevarj trevarj left a comment

Choose a reason for hiding this comment

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

But what should the workflow be if you just want to convert a DescriptorPublicKey descriptor to a DefiniteDescriptorKey one, not touching wildcards if they don't exist?

I'm ok with this as long as we address what Andrew said in the linked issue. I also would like a way to convert from Descriptor<DescriptorPublicKey> into Descriptor<DefiniteDescriptorKey> since I am currently using at_derivation_index as an agnostic translation.

Maybe it can be solved with just adding a helper function into_definite() or something.

@febyeji
Copy link
Copy Markdown
Author

febyeji commented Mar 28, 2026

Thanks for the review! Extracted a public into_definite() method which resolves the duplication and also addresses Andrew's question in the issue. find_derivation_index_for_spk now just calls self.into_definite()?.derived_descriptor(secp).

Address review feedback: unify the duplicated `Definitor` and
`Derivator` translator structs into a single `enum Definitor { FromPk, AtIndex(u32) }`
shared by both `into_definite()` and `at_derivation_index()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

at_derivation_index should fail when the descriptor has no wildcard

2 participants