Skip to content

fix: Add DescriptorKeyParseError for as_public - #1108

Open
ItoroD wants to merge 1 commit into
masterfrom
add-keyparse-error
Open

ItoroD wants to merge 1 commit into
masterfrom
add-keyparse-error

Conversation

@ItoroD

@ItoroD ItoroD commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Description

Addresses #1093

Notes to the reviewers

  • Error is expected for multipath in rust-miniscript. Now I return error rather than panic.
  • Also, it seems later version of mini-script now handles for multipath here (master)

Documentation

Changelog

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 exactly one changelog:* label
  • 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

Comment thread bdk-ffi/src/keys.rs
let secp = Secp256k1::new();
let descriptor_public_key = self.0.to_public(&secp).unwrap();
Arc::new(DescriptorPublicKey(descriptor_public_key))
let descriptor_public_key = self.0.to_public(&secp).map_err(DescriptorKeyError::from)?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could we map the MultiXPrv case to InvalidKeyType, or preferably a dedicated MultiPath variant? The key parsed successfully; it is the conversion that is unsupported. Returning Parse makes binding callers inspect the error message to distinguish this case.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The key parse error refers to what this function in particular is doing. So I won't say "the key parsed successfully" because it cannot parse the mutlixPriv to make it public. Hence, the parsing error. This is also consistent with rust-miniscript error as I shared in the PR description. So returning an invalidKeyType might be misleading.

I suspecting the parsing you are refering to is the one that happens before this function is used. i.e DescriptorSecretKey::from_string like in my test.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah, I see what you mean. I was referring to the earlier DescriptorSecretKey::from_string() parse, since at that point we already have a valid MultiXPrv.

But you're right that to_public() itself returns DescriptorKeyParseError upstream, so mapping that through the existing DescriptorKeyError::Parse conversion is consistent with the current FFI error mapping.

My concern was mainly about whether binding callers need a typed way to distinguish this particular conversion failure rather than inspecting the error message, not that the upstream error type itself was wrong.

I also noticed newer miniscript handles some MultiXPrv -> MultiXPub conversions directly and only errors for incompatible hardened derivation paths, so InvalidKeyType would probably be too broad here.

Given that, I'm fine with Parse for this PR if we're intentionally following the existing upstream/error mapping. Thanks for clarifying.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Alright, thanks. Maybe if we update mini-script in the future we can update as well.

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.

2 participants