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.
A quadlet is a fundamental encoding unit in CESR consisting of a group of 4 Base64 characters in the Text domain (T), equivalently represented as 3 bytes (a triplet) in the Binary domain (B), used to define variable-size primitives while maintaining 24-bit boundary alignment for composability.
A quadlet is a foundational encoding unit in CESR (Composable Event Streaming Representation) that enables the protocol's signature property of text-binary concatenation composability. The quadlet serves as the basic building block for variable-length primitives, ensuring that cryptographic material can be seamlessly converted between human-readable text representations and compact binary formats without loss of information or primitive boundaries.
The quadlet's design directly addresses the fundamental constraint of CESR: all primitives must align on 24-bit boundaries. This alignment requirement emerges from the mathematical relationship between Base64 encoding (6 bits per character) and binary byte encoding (8 bits per byte). Since 24 is the least common multiple of 6 and 8, a quadlet of 4 Base64 characters (4 × 6 = 24 bits) maps perfectly to a triplet of 3 bytes (3 × 8 = 24 bits).
A quadlet exists in two equivalent representations across CESR's dual-domain architecture:
Text Domain (T) Representation:
[A-Z, a-z, 0-9, -, _]MAAB represents a quadlet in text formBinary Domain (B) Representation:
All CESR implementations MUST enforce strict 24-bit alignment:
Implementations MUST correctly calculate and apply lead padding:
ps = (3 - (rs % 3)) % 3
Where:
ps = pad size (number of lead bytes to prepend)rs = raw size (length of value in bytes)Critical: Lead bytes are prepended BEFORE Base64 conversion, not after. The Base64 characters resulting from lead bytes can be replaced with derivation codes.
Implementations should maintain multiple code tables:
Batch Processing: Convert multiple quadlets simultaneously:
Lookup Tables: Pre-compute encoding/decoding tables:
Zero-Copy Parsing: When possible, parse quadlets in-place:
Implementations MUST handle common error conditions:
Alignment Errors:
0x300001 represents the same information as text MAABThe critical property is that these representations are mathematically equivalent and bidirectionally convertible without information loss. This equivalence enables CESR's composability property, where concatenated primitives can be converted en masse between domains while maintaining individual primitive separability.
A quadlet typically contains two logical components when used in variable-length encoding:
Length Information: Encoded in Base64 characters (represented abstractly as # in specifications), indicating the size of the associated variable-length value in quadlets (text domain) or triplets (binary domain)
Value Portion: The actual data being encoded, which may span multiple quadlets depending on the primitive's size
For example, in the CESR variable-length byte string codes:
4B## uses a 4-character code where the first 2 characters (4B) identify the code type and lead size, and the next 2 characters (##) encode the lengthQuadlets do not have traditional "fields" in the sense of structured data formats. Instead, they represent atomic encoding units whose interpretation depends on context within a CESR stream. The meaning of a quadlet is determined by:
Position in Stream: The first quadlet(s) of a primitive typically contain framing codes that specify the primitive type and size
Code Table Context: CESR uses multiple code tables, and the active table determines how quadlet contents are interpreted
Primitive Type: Different primitive types (digests, signatures, keys, etc.) use quadlets differently based on their encoding requirements
The encoding format for quadlets follows strict rules to maintain composability:
Base64 URL-Safe Encoding (Text Domain):
Binary Encoding (Binary Domain):
Lead Padding Algorithm:
For variable-length values, CESR applies lead padding to ensure 24-bit alignment. The number of lead pad bytes (ps) is calculated as:
ps = (3 - (rs % 3)) % 3
Where rs is the raw size in bytes. This formula ensures:
rs % 3 = 0: No padding needed (ps = 0)rs % 3 = 1: Two lead bytes added (ps = 2)rs % 3 = 2: One lead byte added (ps = 1)The lead bytes are prepended to the raw value before Base64 conversion, and the resulting Base64 characters corresponding to these lead bytes can be replaced with derivation codes without affecting the value encoding.
Fixed Size Constraint:
Variable-Length Primitive Support:
Quadlets enable variable-length primitives through length encoding. CESR defines two size ranges:
Small Codes (supporting up to 4,095 quadlets/triplets):
4B##, 5B##, 6B## for different lead sizesBig Codes (supporting up to 16,777,215 quadlets/triplets):
7AAB####, 8AAB####, 9AAB#### for different lead sizesMaximum Primitive Sizes:
These size limits accommodate virtually all cryptographic primitives used in practice, from small digests and signatures to large data structures like ACDCs.
Encoding Process (Raw to Text Domain):
ps = (3 - (rs % 3)) % 3ps zero bytes to the beginning of the raw valueExample Encoding:
For a 2-byte value 0x0001:
rs = 2ps = (3 - (2 % 3)) % 3 = 10x000001 (1 lead byte + 2 value bytes)AAAB (4 characters = 1 quadlet)A (from lead byte) can be replaced with a type codeDecoding Process (Text to Raw Domain):
ps leading bytes based on the derivation codeQuadlets themselves are immutable once created, as they represent atomic encoding units. However, primitives composed of multiple quadlets can be modified by:
Concatenation: Multiple quadlets can be concatenated to form longer primitives
Stream Assembly: Quadlets from different primitives can be concatenated in CESR streams, maintaining separability due to self-framing properties
Domain Conversion: Quadlets can be converted between text and binary domains:
T2B transformation converts 4 Base64 characters to 3 bytesB2T transformation converts 3 bytes to 4 Base64 charactersGroup Conversion: The composability property enables en masse conversion of concatenated quadlets:
T(cat(b[k])) = cat(T(b[k])) for all k
B(cat(t[k])) = cat(B(t[k])) for all k
This means converting a stream of concatenated primitives produces the same result as converting each primitive individually and then concatenating.
Alignment Verification:
All CESR primitives must verify 24-bit alignment:
Code Table Validation:
The first quadlet(s) of a primitive contain derivation codes that must be validated against the active code table:
Composability Verification:
Round-trip conversion tests verify composability:
Original Text -> T2B -> Binary -> B2T -> Recovered Text
The recovered text must exactly match the original, confirming no information loss.
Stream Parsing Validation:
CESR parsers use quadlet boundaries to validate stream integrity:
Any failure in this process indicates stream corruption or protocol violation.
Quadlets are fundamental to the entire KERI protocol suite:
KERI (Key Event Receipt Infrastructure):
ACDC (Authentic Chained Data Containers):
CESR-Proof Signatures:
TSP (Trust Spanning Protocol):
4B##, 5B##, 6B## that specify length in quadletsOOBI (Out-Of-Band Introduction):
Stream Processing Lifecycle:
Cold Start: Parser begins processing a CESR stream by reading the first quadlet(s) to determine the code table selector
Primitive Extraction: For each primitive:
Domain Conversion: Convert between text and binary domains as needed:
Validation: Verify cryptographic properties:
Stream Continuation: Process subsequent primitives until stream end or error
Error Handling:
Quadlet-based parsing enables robust error detection:
Triplets (Binary Domain Equivalent):
A triplet is the binary domain equivalent of a quadlet, consisting of exactly 3 bytes (24 bits). The relationship is:
Primitives:
Cryptographic primitives are composed of one or more quadlets:
Count Codes:
Count codes use quadlets to specify the number of subsequent primitives in a group:
Framing Codes:
Framing codes occupy the first quadlet(s) of a primitive:
Self-Framing Primitives:
Self-framing primitives use quadlets to encode all necessary parsing information:
This self-framing property, enabled by quadlet-based encoding, is essential for CESR's cold start stream parsing capability, where parsers can begin processing at any point in a stream without prior context.
Performance Optimization:
Implementations should optimize quadlet operations:
Memory Alignment:
Quadlet-based encoding naturally aligns with modern CPU architectures:
Streaming Protocols:
Quadlet encoding is optimized for streaming:
Interoperability:
Quadlet-based CESR ensures interoperability:
Code Table Errors:
Composability Errors:
Composability Tests: Verify round-trip conversion:
assert T(B(T(original))) == original
assert B(T(B(original))) == original
Alignment Tests: Verify all primitives maintain alignment:
assert len(text_primitive) % 4 == 0
assert len(binary_primitive) % 3 == 0
Interoperability Tests: Verify cross-implementation compatibility:
Input Validation: Always validate quadlet alignment before processing:
Constant-Time Operations: For cryptographic primitives:
Python: Use bytes and bytearray for binary domain, str for text domain
Rust: Leverage zero-copy parsing with slices and &[u8] references
JavaScript: Use Uint8Array for binary domain, handle Base64 with btoa/atob or Buffer
Go: Use []byte slices and encoding/base64 package
When implementing quadlet support for KERI/ACDC: