Loading vLEI.wiki
Fetching knowledge base...
Fetching knowledge base...
This comprehensive explanation has been generated from 24 GitHub source documents. All source documents are searchable here.
Last updated: October 7, 2025
This content is meant to be consumed by AI agents via MCP. Click here to get the MCP configuration.
Note: In rare cases it may contain LLM hallucinations.
For authoritative documentation, please consult the official GLEIF vLEI trainings and the ToIP Glossary.
Pre-padding (pre-pad) is a fundamental encoding technique in CESR (Composable Event Streaming Representation) that involves prepending leading pad bytes—typically zeros—to raw binary data before Base64 conversion. This ensures the total size of the padded binary value becomes an integer multiple of 3 bytes, which guarantees the resulting Base64 text will be an integer multiple of 4 characters without requiring trailing = pad characters.
The number of lead pad bytes (ps) is calculated as:
ps = (3 - (rs % 3)) % 3
where rs is the raw binary size in bytes.
CESR requires all primitives to align on 24-bit boundaries to satisfy the composability property—the ability to convert concatenated primitives between text and binary domains without loss. Since Base64 encodes 6 bits per character (4 characters = 24 bits) and binary uses 8 bits per byte (3 bytes = 24 bits), 24 bits is the least common multiple enabling seamless domain conversion.
CESR distinguishes between two alignment strategies:
Pre-padding (CESR approach):
= charactersPost-padding (naive Base64):
= characters Base64 conversionAlways use the modulo formula ps = (3 - (rs % 3)) % 3 rather than conditional logic. This ensures:
Pre-padding MUST use zero bytes (0x00), not other values:
For variable-length primitives, code selection depends on pad size:
ps = 0: Use codes 4B or 7AABps = 1: Use codes 5B or 8AABps = 2: Use codes 6B or 9AABChoose small codes (4B/5B/6B) for lengths up to 4,095 quadlets, big codes (7AAB/8AAB/9AAB) for larger.
When parsing CESR streams:
Implementations should validate:
Pre-padding is critical for CESR's design goals:
In KERI's key event logs (KELs) and ACDCs, pre-padding ensures:
For variable-length primitives like VIDs (Verifiable Identifiers) in TSP (Trust Spanning Protocol), pre-padding uses specific CESR codes:
4B##, 5B##, 6B## for small strings (up to 4,095 quadlets)7AAB####, 8AAB####, 9AAB#### for large strings (up to 16,777,215 quadlets)The code selection depends on the calculated pad size (ps), ensuring proper alignment regardless of the original data length.