Skip to content

fix: return descriptor template key type errors - #1072

Open
j-kon wants to merge 2 commits into
bitcoindevkit:masterfrom
j-kon:agent/issue-1071-descriptor-template-errors
Open

j-kon wants to merge 2 commits into
bitcoindevkit:masterfrom
j-kon:agent/issue-1071-descriptor-template-errors

Conversation

@j-kon

@j-kon j-kon commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Description

Closes #1071.

The BIP44, BIP49, BIP84, and BIP86 descriptor constructors accepted descriptor key objects whose underlying single or multipath variants were handled with unreachable!(). This allowed generated binding callers to trigger a Rust panic after successfully parsing a WIF or other valid descriptor key.

This change makes every BIP template constructor return DescriptorError::InvalidKeyType for unsupported variants. The secret-key constructors now return Result, and their template build errors are propagated instead of unwrapped.

Breaking change

The four secret BIP template constructors are now throwable in generated bindings.

Validation

  • cargo fmt --all -- --config format_code_in_doc_comments=true --check
  • cargo clippy --all-targets --features "uniffi/bindgen-tests"
  • CLASSPATH=./tests/jna/jna-5.14.0.jar cargo test --features uniffi/bindgen-tests

@j-kon
j-kon force-pushed the agent/issue-1071-descriptor-template-errors branch from aac9665 to 8a293f3 Compare August 11, 2026 22:23
@j-kon
j-kon marked this pull request as ready for review August 11, 2026 22:51
@j-kon
j-kon requested a review from reez as a code owner August 11, 2026 22:51
@reez

reez commented Aug 12, 2026

Copy link
Copy Markdown
Collaborator

Looking good thanks for taking this on. Please add the changelog: breaking label. Since the four secret constructors now throw/return a result I dont think this can merge into a near term non-breaking release, so could we also track or link it from the existing 4.0 changes issue #1036 so it’s queued up for the next breaking release? Otherwise the implementation and tests looking good to me.

@j-kon

j-kon commented Aug 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I linked #1072 from the 4.0 tracking issue #1036. I also attempted to add changelog: breaking, but GitHub rejected it because I do not have label permissions on this repository, so a maintainer will need to apply that label.

@Johnosezele Johnosezele left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looking at the scope of things, wouldn't it be beneficial if we extract the shared require_xprv, require_xpub and from_template helpers so the validation lives in one place, I think there's already an existing debt that would keep compounding if someone later decides MultiXPrv should map to a different error than Single, or adds a fourth variant, they'd need to update eight sites... mssing one is how unreachable!() survived in the first place.

@j-kon
j-kon force-pushed the agent/issue-1071-descriptor-template-errors branch from 8a293f3 to b47a869 Compare August 20, 2026 04:12
@j-kon

j-kon commented Aug 20, 2026

Copy link
Copy Markdown
Contributor Author

@Johnosezele Addressed in b47a869: key-type validation now lives in shared require_xprv and require_xpub helpers, and template construction/error mapping lives in generic from_template. The eight exported constructors remain explicit for their UniFFI APIs. I also rebased onto current master and reran format, bindgen-feature clippy, and the full test suite.

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

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

BIP descriptor constructors panic for valid single descriptor keys

4 participants