Expand description
Shared text-level helpers for output descriptor strings. Shared text-level helpers for output descriptor strings.
These helpers live in keep-core so that both keep-bitcoin (for
normalization) and keep-nip46 (for validation) can agree on how a
single-path /0/* or /1/* tail is detected.
Functionsยง
- contains_
tail - Returns true if the descriptor body contains a terminating
/{digit}/*derivation suffix, i.e. a/{digit}/*immediately followed by)or,. The guardbytes[i - 1] != b'/'only rejects a doubled slash//{digit}/*; nested paths likexpub.../0/0/*)also match at the trailing segment because that segment drives external/change derivation. - has_
multipath_ marker - Returns true if the descriptor body contains any BIP-389 multipath
placeholder (
<0;1>or<1;0>). - has_
single_ path_ tail - Returns true if the descriptor body contains a terminating single-path
/0/*or/1/*derivation suffix on any key expression. - rewrite_
trailing_ zero_ star - Rewrite every anchored
/0/*tail (a/0/*followed by)or,, whose leading/is not itself preceded by another/) to/<0;1>/*. Works on byte indices but copies unchanged regions as UTF-8 slices so the output stays well-formed even if the input contains non-ASCII bytes. - rewrite_
trailing_ zero_ to_ one - Rewrite every anchored
/0/*tail to/1/*, using the same anchoring rules asrewrite_trailing_zero_starso nested paths and origin info are left alone. Used to derive an internal (change) descriptor from an external (receive) descriptor without touching unrelated/0/*substrings.