Skip to content

wallet: reconstruct multipath descriptors - #123

Closed
Sjors wants to merge 4 commits into
masterfrom
2026/08/multipath-reconstruct
Closed

Sjors wants to merge 4 commits into
masterfrom
2026/08/multipath-reconstruct

Conversation

@Sjors

@Sjors Sjors commented Aug 24, 2026 •

Copy link
Copy Markdown
Owner

Still a bit too vibe coded to upstream.

@Sjors Sjors mentioned this pull request Aug 24, 2026
7 tasks
Sjors added 4 commits August 25, 2026 09:24
Combine a receive descriptor with its change counterpart back into
the multipath descriptor (BIP 389) both were derived from, e.g.
combine wpkh(XPUB/0/*) with wpkh(XPUB/1/*) into wpkh(XPUB/<0;1>/*).

Each PubkeyProvider merges itself with its counterpart: the providers
must be identical apart from at most one derivation path element,
whose hardened flag must match and whose change index must be greater
than the receive index. This supports index pairs other than <0;1>,
multipath elements at any depth and hardened elements. The
DescriptorImpl printing machinery walks both descriptors in lockstep
via a new StringType::MULTIPATH, requiring identical structure and
non-key arguments, including miniscript and taproot script trees.

This is groundwork for reconstructing the imported multipath
descriptor from the expanded receive and change descriptor pair
stored in a wallet.
Importing a multipath descriptor, conventionally with a /<0;1>/*
derivation path, expands it into a separate receive (/0/*) and change
(/1/*) descriptor, and generated single key wallets consist of such
pairs to begin with. Add DeriveMultipathDescriptor to combine a pair
of descriptor SPKMs back into the original multipath descriptor,
delegating to Descriptor::ToStringMultipath on the normalized public
descriptor pair.

This is groundwork for external signer support of descriptors that
must be registered on the device, such as multisig and MuSig2: the
reconstructed multipath descriptor is what gets registered on (and
verified by) the device.

The unit test roundtrips a multisig, MuSig2 and non-<0;1> multipath
descriptor through pairs of SPKMs, and covers the failure modes:
pairs from different multipath descriptors and a swapped
receive/change pair. Coverage of the various descriptor shapes lives
in descriptor_tests.
Add an optional multipath field to each listdescriptors entry that
has a receive or change counterpart in the wallet, containing the
multipath descriptor the pair was derived from. Both halves of a
pair return the same value, always in public form.

This makes the original form of an imported multipath descriptor,
which is stored expanded into separate receive and change
descriptors, visible again, e.g. for comparison against the other
participants' wallets or a signing device.
Add an optional parent_multipath field next to parent_desc,
containing the multipath descriptor that the address's parent
descriptor and its receive or change counterpart were derived from.
This lets a caller see the original imported form of the descriptor
an address belongs to, e.g. for comparison against the other
participants' wallets or a signing device.
@Sjors

Sjors commented Aug 31, 2026

Copy link
Copy Markdown
Owner Author

Closing in favor of bitcoin#36133.

@Sjors Sjors closed this Aug 31, 2026
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.

1 participant