Expand description
Human-friendly “prefixed” encoding for the public data types.
This module sits on top of the canonical byte / hex encoding in
crate::types. It does not change a single bit of what is hashed,
signed or verified — it is a pure presentation layer whose only job is
to make a copy-pasted value:
- self-describing — a short tag (
pk,sk,ki,blsag) up front says what kind of value it is, so a public key pasted where a key image was expected is caught immediately; - typo-resistant — a trailing checksum detects the overwhelming majority of single-character mistakes, transpositions and truncated pastes before the bytes ever reach the cryptographic core.
§Wire shape
pk_3f8a…e1c0_d4e9a1b7
│ │ │
│ │ └ checksum: 4 bytes, hex (8 chars)
│ └ body: the canonical hex encoding, exactly as `to_hex()` emits it
└ tag: pk | sk | ki | blsagThree _-separated parts. None of the parts can itself contain a _
(the tags are fixed, the other two are hexadecimal), so splitting on
_ is unambiguous.
§Checksum
checksum = BLAKE3(DOMAIN || tag || 0x00 || payload)[..4].
The tag is folded into the checksum pre-image (with a 0x00
separator so no tag can be confused with a prefix of another), which
is what makes relabelling detectable: take a valid pk_… string,
rewrite the tag to ki_, and the checksum no longer matches. So one
check covers both “is the prefix coherent?” and “was the value
mistyped?”.
This checksum is not a security primitive. An attacker can trivially compute a valid checksum for any bytes they like; its only purpose is to catch honest mistakes. Authenticity comes from the BLSAG proof, never from this.
Enums§
- Tag
- Which kind of value a prefixed string carries. The string form is the human-readable prefix; it is also folded into the checksum.
Functions§
- decode_
prefixed - Decode a
tag_<hexbody>_<hexchecksum>string, verifying both the tag and the checksum, and return the raw payload bytes. - encode_
prefixed - Encode
payloadastag_<hexbody>_<hexchecksum>.