Skip to content

feat: Add new_wsh_sortedmulti and new_pk#949

Merged
reez merged 2 commits intobitcoindevkit:masterfrom
ItoroD:miniscript-descriptor-methods
Mar 17, 2026
Merged

feat: Add new_wsh_sortedmulti and new_pk#949
reez merged 2 commits intobitcoindevkit:masterfrom
ItoroD:miniscript-descriptor-methods

Conversation

@ItoroD
Copy link
Copy Markdown
Collaborator

@ItoroD ItoroD commented Feb 17, 2026

Description

This Pr is based on my comment from #687 here.

Notes to the reviewers

In bdk-wallet we can do the following to create a 1 of 2 multisig descriptor. Thanks so miniscript helper functions

let multisig_descriptor = Descriptor::new_wsh_sortedmulti(1, vec![key.clone(), key2.clone()]).unwrap();

In bindings: kotlin, we do:

val multisigDescriptor = Descriptor("wsh(multi(1,$key,$key2))", Network.REGTEST)

Current we have to concatenate a string with the keys and script type to parse the descriptor.

Much easier and safer to be able to do:

val multisigDescriptor = Descriptor.newWshSortedmulti(2u, pkList);

Documentation

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

@ItoroD ItoroD changed the title Miniscript descriptor methods feat: Add new_wsh_sortedmulti and new_pk Feb 17, 2026
@ItoroD ItoroD changed the title feat: Add new_wsh_sortedmulti and new_pk feat: Add new_wsh_sortedmulti and new_pk Feb 17, 2026
@reez
Copy link
Copy Markdown
Collaborator

reez commented Feb 17, 2026

this is really cool @ItoroD

@ItoroD ItoroD mentioned this pull request Feb 19, 2026
9 tasks
@ItoroD ItoroD force-pushed the miniscript-descriptor-methods branch from e5c8e2f to eb836c7 Compare February 19, 2026 09:19
@ItoroD
Copy link
Copy Markdown
Collaborator Author

ItoroD commented Feb 19, 2026

this is really cool @ItoroD

Thanks!

If this get approved, I am hoping to bring in the other similar miniscript methods that take either a list of PKs or single Pk. There are other ones that take more complex params that I can focus my attention on later once these simple ones are in.

I did just these 2 in this pr just as a sort of concept and starter for the rest.

@ItoroD ItoroD force-pushed the miniscript-descriptor-methods branch from eb836c7 to 777bc48 Compare February 19, 2026 17:15
Comment thread bdk-ffi/src/descriptor.rs Outdated
let bdk_pks: Vec<BdkDescriptorPublicKey> = pks
.iter()
.map(|pk| {
BdkDescriptorPublicKey::from_str(pk).map_err(|e| DescriptorError::Miniscript {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we avoid reparsing raw strings into BdkDescriptorPublicKey here? Right now malformed keys become DescriptorError::Miniscript while the rest of the API exposes key parsing through DescriptorPublicKey and key oriented error variants. Taking DescriptorPublicKey directly, or adding a dedicated conversion for key parse failures would keep this constructor consistent with the existing bindings surface I think

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.

Taking DescriptorPublicKey directly will mean the user will parse his string first before passing it to our new methods? Isn't it better if the method handles both?

With regards to the error, currently you will get a DescriptorKeyException if you pass a malformed key. Also, some of these constructors are not going to be taking pk alone, they will take actual miniscript like here

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.

I just ran the android test with a malformed key and indeed its a DescriptorException$Miniscript error that shows up. I should be able to change it to give a DescriptorKeyException like it does when you parse with DescriptorPublicKey.

About whether to take strings as param or DescriptorPublicKey, I was only thinking about the way we have been passing things into the descriptor type so far (with strings). Hoping it will not be too disruptive it use DescriptorPublicKey.fromString first before they they pass it to this constructor.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Yeah your right keeping String params here is good w me, that makes sense.

I’d be interested to hear what you find if you look into the error mapping. If it’s an easy fix, that would be great, but if it's not then I am def good with merging the pr as is.

Good work on this overall, its has some tricky bits for sure.

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.

I have looked at the Error variant we are using again and I come to the conclusion that DescriptorError::Key might be the best to use that case. It maps to KeyError in bdk-wallet and it seems to have a wide range of error variants.

"xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB"
)

Descriptor.newWshSortedmulti(2u, pkList);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Should we assert the resulting descriptor string or descType() here? I think this only checks that construction succeeds so it I dont know if it would catch a wrapper bug that returns the wrong descriptor variant

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.

Yes good call. Will update

@ItoroD ItoroD force-pushed the miniscript-descriptor-methods branch 2 times, most recently from a6c4e2b to cc6bbbf Compare March 17, 2026 11:03
@ItoroD ItoroD force-pushed the miniscript-descriptor-methods branch from cc6bbbf to ec37928 Compare March 17, 2026 11:22
@notmandatory notmandatory moved this to Ready to Review in BDK-Bindings Mar 17, 2026
Copy link
Copy Markdown
Collaborator

@reez reez left a comment

Choose a reason for hiding this comment

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

ACK ec37928

@reez reez merged commit a5918b0 into bitcoindevkit:master Mar 17, 2026
6 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to Review to Done in BDK-Bindings Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants