Skip to main content

Module encode

Module encode 

Source
Expand description

Top-level encoder per spec §13.3.

Structs§

Descriptor
Top-level descriptor parsed/built from a v0.30 wire payload.

Functions§

encode_md1_string
Encode a Descriptor into a complete codex32 md1 string (HRP + payload + BCH checksum). Returns the canonical single-string form.
encode_payload
Encode a Descriptor into the canonical payload bit stream and return (bytes, total_bit_count). The bytes are zero-padded; total_bit_count is the exact unpadded length needed for round-trip decoding (see §3.7’s “TLV section ends when codex32 total-length is exhausted” rule).
is_display_separator
True for any character treated as a display separator on intake: ALL Unicode whitespace plus - and ,. SPEC §3.2 (mstring display-grouping). None of these appear in the codex32 alphabet (qpzry9x8gf2tvdw0s3jn54khce6mua7l) or the ms/mk/md/1 structural chars (SPEC §4), so stripping is unambiguous.
render_codex32_grouped
Render a codex32 string with optional N-char HYPHEN grouping for transcription aid (spec §10.2). group_size = 0 returns the input unchanged. Back-compat wrapper over render_grouped (hyphen separator). Retained as public API (documented in the technical manual); new callers use render_grouped with an explicit separator.
render_grouped
Insert separator after every group_size characters (SPEC §3.1). group_size == 0 returns the input unchanged. Single line; ASCII-safe.
strip_display_separators
Strip every display separator (SPEC §3.2) — used on intake before decode. Idempotent; strips ONLY separators (other chars pass through, so a malformed card is never silently “cleaned” into validity).