Skip to content

wallet: track multipath original - #125

Closed
Sjors wants to merge 16 commits into
masterfrom
2026/08/multipath-tag
Closed

Sjors wants to merge 16 commits into
masterfrom
2026/08/multipath-tag

Conversation

@Sjors

@Sjors Sjors commented Aug 25, 2026

Copy link
Copy Markdown
Owner

Implements approach 5 from bitcoin#36075

@Sjors
Sjors force-pushed the 2026/08/multipath-tag branch 5 times, most recently from bd291e0 to d4db937 Compare August 27, 2026 18:47
@Sjors

Sjors commented Aug 27, 2026

Copy link
Copy Markdown
Owner Author

Still need to study and polish this more before upstreaming, in particular:

  • descriptor: let Parse return the multipath descriptor string
  • descriptor: normalize keys in the multipath descriptor string

@Sjors
Sjors force-pushed the 2026/08/multipath-tag branch 4 times, most recently from 50faa46 to b53ebd3 Compare August 31, 2026 16:52
Sjors added 16 commits August 31, 2026 19:32
This lets the next commit record key positions in the descriptor string
while its miniscript expression is parsed in place.
Use it to check whether parsing expands a descriptor into multiple descriptor.
Use util::Expected for ParsePubkeyInner, ParsePubkey, and ParseScript, so errors are returned directly instead of passed through an output argument.

The only behavior change is that a preexisting error string is cleared when nested descriptor parsing fails without producing an error message. Previously, the stale error was left intact.
Group the key expression index and signing provider shared by ParsePubkeyInner, ParsePubkey, and ParseScript in ParseState.

A later commit extends this state with key replacement collection.
Add an optional Parse() output for the unexpanded multipath descriptor. This is always a public descriptor, so ParseState optionally collects KeyReplacement entries tracking key locations in the input for private-to-public conversion.

The replacement sink is null unless the caller requests this output.
Split finding the last hardened derivation step out of
BIP32PubkeyProvider::ToNormalizedString. No behavior change. A later
commit reuses it when normalizing the keys of a multipath descriptor
string.
Split formatting the normalized public form of a derived key, i.e. its
origin followed by the extended public key at the last hardened step,
out of BIP32PubkeyProvider::ToNormalizedString. No behavior change. A
later commit reuses it when normalizing the keys of a multipath
descriptor string.
Split merging an outer key origin into an already normalized key
expression out of OriginPubkeyProvider::ToNormalizedString. No behavior
change. A later commit reuses it when normalizing the keys of a
multipath descriptor string.
Private extended keys followed by a fixed hardened prefix are now replaced by their key origin and the extended public key at the last hardened step, merging any explicit origin. This matches Descriptor::ToNormalizedString and produces BIP 388 wallet policy key expressions suitable for registering the multipath descriptor on a signing device.

A hardened multipath element or wildcard cannot be represented by a single publicly derivable multipath descriptor. Leave the Parse multipath output unset in those cases.

ParsePubkeyInner now returns an optional replacement alongside parsed providers so ParsePubkey can merge explicit key origin information before collecting it.
When importdescriptors expands a BIP 389 multipath descriptor into
separate receive and change descriptors, additionally store a record
containing the multipath descriptor string, as reported by the parser
in public form, along with the IDs of the wallet descriptors it
expanded to.

Older wallet software ignores the new record.
Add an optional multipath field to getaddressinfo, containing the
multipath descriptor that this address' parent descriptor was expanded
from, in public form.
Add an optional multipath field to each listdescriptors entry that was
expanded from a multipath descriptor, containing the stored multipath
descriptor record. Every descriptor from the same multipath descriptor
returns the same value, always in public form.
The descriptor IDs in the record are translated to those of the
watchonly wallet.
Add SetupDescriptorScriptPubKeyManPair, used by default wallet creation
and createwalletdescriptor, which derives the receive and change
descriptors of an output type from a single multipath descriptor
string, built by a new GenerateMultipathDescriptorString.

This commit does not change behavior.
When SetupDescriptorScriptPubKeyManPair creates a descriptor pair, store
a record with the normalized multipath descriptor they derive from.

When createwalletdescriptor is used with the internal option, the record
is stored by whichever call completes the pair.
@Sjors
Sjors force-pushed the 2026/08/multipath-tag branch from b53ebd3 to 0948b92 Compare August 31, 2026 17:33
@Sjors

Sjors commented Aug 31, 2026

Copy link
Copy Markdown
Owner Author

Upstreamed as 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