Skip to main content

Module descriptor

Module descriptor 

Source
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 guard bytes[i - 1] != b'/' only rejects a doubled slash //{digit}/*; nested paths like xpub.../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 as rewrite_trailing_zero_star so 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.