Expand description
BIP 388 placeholder-ordering canonicalization per spec v0.13 §6.1, plus
per-@N canonical-fill expansion per §5.3 / §6.3.
BIP 388 wallet policies require placeholder indices @0..@{N-1} to be
introduced in the descriptor template in canonical first-occurrence order:
the first new placeholder encountered in document-order pre-order
traversal must be @0, the next new one @1, etc.
canonicalize_placeholder_indices reshapes a Descriptor in place
so this invariant holds, atomically permuting:
- the tree’s
KeyArg.indexandTr.key_indexfields; - the
PathDecl’sDivergentpaths vector (one path per@N); - per-
@NTLV maps:use_site_path_overrides,fingerprints,pubkeys,origin_path_overrides.
After canonicalization, the post-conditions are:
- Each TLV map’s
(idx, _)keys are strictly ascending and< n. - The tree’s first-occurrence sequence is exactly
[0, 1, ..., n-1](verified viacrate::validate::validate_placeholder_usage).
Idempotent: calling on an already-canonical descriptor is a no-op (identity-permutation fast path).
The decoder side does not call this routine: v0.11’s
crate::validate::validate_placeholder_usage rejects non-canonical
wires up-front via
Error::PlaceholderFirstOccurrenceOutOfOrder.
expand_per_at_n resolves each @N to a fully-populated
ExpandedKey (origin, use-site, optional fp/xpub) by composing the
per-@N TLV overrides with the descriptor-level baselines. Used by
Phase 4’s WalletPolicyId construction and Phase 5’s decoder validation.
Structs§
- Expanded
Key - Fully-resolved per-
@Nkey record produced byexpand_per_at_n.
Functions§
- canonicalize_
placeholder_ indices - Canonicalize placeholder indices in
dso the first-occurrence sequence ind.treeis exactly[0, 1, ..., d.n - 1]. - expand_
per_ at_ n - Expand a
Descriptorinto a vector ofExpandedKeyrecords — one per@Nin0..d.n— by composing per-@NTLV overrides with the descriptor-level baselines (spec v0.13 §5.3 / §6.3, “Option A”).