Status: Draft specification (Phase P0, 2026-11-22; revised 2026-11-24
and 2026-11-25 after review) · Conformance vectors:
docs/vectors/cp2-vectors.json · Reference checker:
tools/cp2_vectors.py
This document defines Courier Protocol v2 (CP2): a bearer-independent wire protocol for reliable, authenticated, per-recipient tracked small-group messaging across heterogeneous links (LoRa/MeshCore, IP, Matrix, amateur VHF/HF radio, email, and bridges). It is self-contained: an implementation can be built from this specification and its conformance vectors without reading any other repository document.
CP2 is a strict superset of Courier v1 on MeshCore. Every valid v1 MeshCore envelope remains byte-for-byte valid under CP2 compact encoding.
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in RFC 2119.
F)
are unsigned big-endian (network byte order) unless stated
otherwise._B64): unpadded
64-character URL-safe alphabet in exact index order 0..63:
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_
An n-character base64url integer encodes an unsigned
6n-bit integer big-endian (most significant 6-bit group
first)._B32): unpadded RFC 4648
uppercase alphabet in exact index order 0..31:
ABCDEFGHIJKLMNOPQRSTUVWXYZ234567 Used only by the
case-folding compact rendering (C32, §4.4).conv): a
single ASCII character from the set 0, A..Z,
a..z.
'0' (0x30) is reserved for one-to-one
direct conversations.'A'..'Z' (0x41..0x5A) and 'a'..'z'
(0x61..0x7A) identify group conversations configured by
the admin. (Groups intended to traverse case-folding bearers MUST use
'A'..'Z'.)(author_id, conv) for group conversations and
(author_id, recipient_id, '0') for direct conversations. A
sequence number (seq64) is allocated once when a message is
authored and MUST NEVER be allocated per bearer.C or C32 MUST NOT
contain U+0000 (0x00), because MeshCore
companion DMs are NUL-terminated C strings.F is self-describing binary. Compact encoding
C omits fields already known to both endpoints from the
signed admin config and stream state (analogous to SCHC, RFC 8724). Both
encodings authenticate over the same canonical signing input, so compact
and full copies of one message carry the same tag.C without CP2 extension blocks is
byte-for-byte identical to Courier v1. All new compact fields ride
inside the existing has-extension (flag bit 5, value 32)
block list.auth = 1 or 2) from
encryption (auth = 3).Every CP2 node MUST generate and persist a 32-byte random seed defining an Ed25519 key pair (RFC 8032 pure Ed25519, no context, no pre-hash).
author_id, recipient,
relayed_by): the 32-byte raw Ed25519 public key
(64 lowercase hex characters in JSON/text representations).h = SHA-512(ed25519_seed)[0..31], clamped per RFC
8032/7748: h[0] &= 248, h[31] &= 127,
h[31] |= 64.u): birational map from
the Edwards25519 public key y (32-byte little-endian
integer with sign bit 255 cleared:
y = int_le(ed_pub) & ((1 << 255) - 1)), over
prime p = 2^255 - 19:
u = (1 + y) * (1 - y)^(-1) mod p, encoded as 32 bytes
little-endian. Implementations MUST reject y >= p or
y == 1.Group membership, roster identities, bearer addresses, codebook, and policy are distributed out of band in a single signed JSON file:
{
"payload": "<exact UTF-8 JSON payload text>",
"sig": "<128 lowercase hex chars: RFC 8032 Ed25519 signature over UTF-8 bytes of payload>",
"admin_key": "<64 lowercase hex chars: 32-byte Ed25519 admin public key>"
}payload string (no JSON canonicalisation).admin_key out of band (by
local configuration or by out-of-band confirmation of the 80-bit
fingerprint below); a node MUST NEVER silently trust an unknown
admin_key.version; nodes MUST refuse any config with
version <= current_version.pub[0]), and every member's MeshCore radio key (if
present) MUST also have a distinct first byte. This guarantees
collision-free 12-bit member tags across the roster.
docs/identity-foundation.md §3, §5, open question 5)
relaxes this rule. The code no longer enforces the node-key first-byte
MUST, for v10 or v11 configs. For a v11 group config, tags are assigned
(principal slot, device slot) instead of derived from keys; a
principal's own active radios must differ in first byte and a clash
across principals is only a warning. The radio-key rule above still
applies to a v10 config. Decision still under "Proposed" in
docs/decisions.md.P claim from the member's radio
key agreeing with a Matrix room com.chee3e.courier.claim
event from that account) REMAINS valid where the admin config does not
set an explicit admin binding. An admin binding ALWAYS overrides
self-announced claims.encryption_forbidden,
cost classes 2 and 3). Default is off (only short codes
and receipts permitted).admin_fp): the
first 10 bytes (80 bits) of SHA-256(admin_pub_raw).
Displayed to humans as five 4-hex-digit groups separated by hyphens
(xxxx-xxxx-xxxx-xxxx-xxxx).admin_fp (10 B) || conv (1 B ASCII). Including
admin_fp prevents cross-group replay or collision between
independent Courier deployments sharing a group letter (such as
'G').A member tag is 2 base64url characters representing the top 12 bits of a 32-byte public key:
top12 = (pub[0] << 4) | (pub[1] >> 4)
tag = _B64[top12 >> 6] + _B64[top12 & 63]
O relay blocks
and v1 group K replies
1W <tag><seq>), the tag is derived from the
member's MeshCore radio public key for backward wire
compatibility.D recipient tags and CP2
O blocks on non-v1 bearers), the tag is derived from the
member's node key (choice: non-MeshCore nodes may lack
a MeshCore radio key; listed in §9).Given nodes A (with Ed25519 seed seed_A,
public key pub_A) and B (public key
pub_B):
shared = X25519(ed25519_seed_to_x25519_priv(seed_A), ed25519_pub_to_x25519_pub(pub_B))
(32 bytes). Implementations MUST reject the derivation if
shared == 0x00 * 32 (RFC 7748 §6.1 low-order point
check).salt_pair = (pub_A || pub_B) if pub_A <= pub_B else (pub_B || pub_A)
(64 bytes). (Choice: binding sorted Ed25519 public keys in the HKDF
salt prevents unknown-key-share ambiguity while keeping
pair_key(A, B) == pair_key(B, A); listed in §9.)pair_key = HKDF-SHA256(ikm=shared, salt=salt_pair, info="courier pair", L=32)2^32 random-nonce budget under §5.5;
listed in §9):
auth = 1):
mac_key = HKDF-SHA256(ikm=pair_key, salt=b"", info="courier mac", L=32)auth = 3,
keyed to sender author_id and admin_fp):
aead_key = HKDF-SHA256(ikm=pair_key, salt=author_id || admin_fp, info="courier aead", L=32)(Optional broadcast group MAC key, pending group decision Q6 in
§9: if enabled by admin config,
group_mac_key = HKDF-SHA256(ikm=group_secret, salt=admin_fp || conv, info="courier group mac", L=32).)
F)A Full encoding (F) frame consists of a fixed
64-byte big-endian header, followed by
options_len bytes of TLV options, body_len
bytes of body, and tag_len bytes of auth tag.
| Offset | Size | Field | Description |
|---|---|---|---|
| 0 | 2 | magic |
ASCII 0x43 0x32 ("C2"). Receivers MUST
reject any other value. |
| 2 | 1 | ver_flags |
High nibble (b >> 4): protocol version, MUST be
2. Low nibble (b & 0x0F): header flags —
bit 0 (0x01) relayed, bit 1
(0x02) lossy, bit 2 (0x04)
encrypted, bit 3 (0x08) reserved (MUST be
0). |
| 3 | 1 | type |
ASCII message type: M (0x4D), K (0x4B),
R (0x52), Q (0x51), P (0x50),
G (0x47). |
| 4 | 1 | msg_flags |
Message flags — bit 0 (0x01)
reply_required, bit 1 (0x02)
urgent, bit 2 (0x04) more_parts,
bits 3..7 (0xF8) reserved (MUST be 0). |
| 5 | 1 | auth |
Auth algorithm: 0 = none (0 B tag), 1 =
HMAC-SHA256-48 (6 B tag), 2 = Ed25519 (64 B tag),
3 = ChaCha20-Poly1305 (16 B tag). Values
4..255 MUST be rejected. |
| 6 | 2 | body_len |
uint16 big-endian byte length of body
(0..65535). |
| 8 | 32 | author_id |
Author's 32-byte raw Ed25519 node public key. |
| 40 | 10 | admin_fp |
Active admin config's 10-byte fingerprint
(SHA-256(admin_pub)[:10]). |
| 50 | 1 | conv |
ASCII conversation character ('0',
'A'..'Z', 'a'..'z'). |
| 51 | 1 | options_len |
uint8 total byte length of the options TLV block
(0..255). |
| 52 | 8 | seq64 |
uint64 big-endian stream sequence number,
epoch·2^32 + n (§6.3), always below 2^53. Low
12 bits equal the compact 12-bit seq. Data streams
(M, K) start at n = 1; control
types use 0. |
| 60 | 4 | ts |
uint32 big-endian Unix timestamp (seconds) on the
author's clock; 0 if unknown. |
| 64 | options_len |
options |
Zero or more TLV entries (§3.2). |
64+options_len |
body_len |
body |
Message body (§6); encrypted in place when
auth == 3. |
64+options_len+body_len |
0, 6, 64, 16 |
auth_tag |
Authentication tag or signature per auth (§5). |
Header invariants (MUST be enforced on decode and encode):
64 + options_len + body_len + tag_len(auth). Trailing or
missing bytes MUST be rejected.encrypted (byte 2, bit 2) MUST equal 1 if
and only if auth == 3.0.Each option in the options section is encoded as:
opt_type (1 byte uint8) || opt_len (1 byte uint8) || opt_val (opt_len bytes)
Options are partitioned by the high bit of opt_type:
0x00..0x7F): authenticated by the auth tag / AAD.
MUST appear before all unsigned options, MUST be ordered by strictly
ascending opt_type (no duplicates), and unknown signed
option types MUST be rejected.0x80..0xFF): mutable per hop, NOT covered by the
auth tag / AAD, so anyone who can put a frame on the bearer can add or
change them. Receivers MUST apply §3.5 before using any of them.
Duplicate option types MUST be rejected. Encoders SHOULD emit them in
ascending opt_type order. Decoders MUST validate known
types and MAY ignore unknown types in 0x80..0xFF.| Type | Scope | Name | Length | Layout and Rules |
|---|---|---|---|---|
0x01 |
Signed | recipient |
32 | Final recipient's raw Ed25519 node public key. MUST NOT appear when
conv != '0'. REQUIRED on direct messages
(conv == '0') when authenticated (auth != 0)
or relayed. |
0x02 |
Signed | answers |
41 | orig_author_id (32 B) || orig_conv (1 B ASCII) || orig_seq64 (8 B u64 BE).
For Full-native replies. MUST be omitted when targeting C↔︎F tag equality
for compact K replies (whose body already encodes the
target; choice noted in §9). |
0x03 |
Signed | attachment |
2 | kind (1 B ASCII in P/F/V/D/U) || size_class (1 B u8 in 0..15 or 63).
Maps 1-to-1 with compact block A. |
0x04 |
Signed | nonce |
12 | ChaCha20-Poly1305 nonce, random per encryption (§5.5). REQUIRED when
auth == 3; MUST NOT appear otherwise. |
0x05 |
Signed | stream_author |
32 | Node key of the author of the stream an R or
Q is about. REQUIRED on R and Q
in Full encoding; MUST NOT appear on other types. |
0x06 |
Signed | receipt64 |
16 | rwm64 (u64 BE) || base64 (u64 BE). R only;
REQUIRED on every Full R. Claim: the R's
author holds every seq of the stream in [base64, rwm64].
rwm64 = base64 = 0 means "no 64-bit claim". Otherwise
1 <= base64 <= rwm64 + 1, both in one epoch (§6.3),
and the body's rwm MUST equal
rwm64 & 0xFFF. A decoder MUST reject any other
combination. |
0x80 |
Unsigned | piggyback |
4 | received_wm (u16 BE, 0..4095) || read_wm (u16 BE, 0..4095).
12-bit watermarks matching R receipts so C↔︎F is stateless
(choice noted in §9). Hop claim (§3.5). |
0x81 |
Unsigned | position |
8 | lat24 (3 B u24 BE) || lon24 (3 B u24 BE) || time_src12 (2 B u16 BE, top 4 bits = 0).
Exact binary form of the 60-bit v1 position block (§4.2). Hop claim
(§3.5). |
0x82 |
Unsigned | relayed_by |
32 | Relaying node's raw Ed25519 public key. Informational (§3.5). |
0x83 |
Unsigned | age |
2 | age_code (u16 BE, 0..511, top 7 bits = 0). Uses the v1
9-bit piecewise age table (§4.2). Places ts only (§3.5,
§6.2). |
To compute or verify auth = 1 (HMAC-SHA256-48),
auth = 2 (Ed25519), or the AAD for auth = 3
(ChaCha20-Poly1305), construct header' as a copy of header
bytes 0..63 with three transport/hop-dependent fields
zeroed:
header'[2] = header[2] & 0xFE — clears bit 0
(relayed), so a relay can pass the author's auth tag
untouched while setting relayed = 1 on its relayed
frame.header'[51] = 0x00 — zeroes options_len,
because unsigned hop options vary in length.header'[60:64] = 0x00 0x00 0x00 0x00 — zeroes
ts, because compact frames on bearers without frame
timestamps carry only a quantized T age without a shared
clock, and relayed O frames carry only a quantized 9-bit
age. (Deviation from proposal §3.3, proposed in
decisions.md and §9: without zeroing ts and
relayed, C↔︎F and relayed O+S tag equality
would fail on any 1-second clock skew or age quantization.)Let signed_options be the exact concatenation of all TLV
entries with opt_type < 0x80 in strictly ascending
opt_type order. Then:
auth in {1, 2}:
signing_input = header' (64 B) || signed_options || body (plaintext)auth == 3:
aead_aad = header' (64 B) || signed_optionsBecause body_len is committed inside
header'[6:8] and each TLV is self-delimiting, the boundary
between signed_options and body is unambiguous
even with header'[51] == 0.
On JSON bearers (Matrix com.chee3e.courier room event
field, email between nodes), v REMAINS 1 and
four CP2 fields (node, seq64,
sig, bsig) are added to the existing object
(all hex strings are lowercase):
"com.chee3e.courier": {
"v": 1,
"from": "<64 lowercase hex MeshCore radio key (optional if radio-less)>",
"node": "<64 lowercase hex Ed25519 node public key>",
"conv": "G",
"seqs": [200, 201],
"seq64": 200,
"ts": 1795034500,
"kind": "M",
"flags": ["urgent"],
"parts": ["Part one text. ", "Part two text."],
"attachment": {"kind": "photo", "size_class": 11},
"msg": "vec-m8",
"sig": "<128 lowercase hex Ed25519 signature>",
"bsig": "<128 lowercase hex Ed25519 binding signature>"
}seq64 is the first part's 64-bit sequence number, the
one the sender's engine allocated for the message in its stream (§1). It
is the same value every other bearer carries for that message; a JSON
bearer MUST NOT keep a separate counter. Integers MUST remain within
0..2^53-1 for Matrix canonical JSON.sig is the RFC 8032 Ed25519 signature
(auth = 2) over canonical_signing_input(F) of
the corresponding Full message with author_id = node,
admin_fp = active config fingerprint, conv,
type = kind, seq64,
more_parts = 0,
urgent/reply_required from flags,
optional 0x03 attachment if attachment is
present, and body = k (for K) or
"".join(parts) (for M) encoded as UTF-8.
(Choice: one signature over the assembled body matches the singular
sig field in the proposal; listed in §9.)bsig is a second Ed25519 signature by the same
node key, binding what the Full signing input does not
cover:
bsig = Ed25519(node_key, "courier matrix bind v1" || 0x00 || sig_bytes || M),
where sig_bytes is the 64 raw bytes of sig and
M is the UTF-8 encoding of Matrix Canonical
JSON (Matrix Specification, "Canonical JSON": object keys
sorted recursively by Unicode code point, no insignificant whitespace
with separators , and :, UTF-8 without BOM,
integers only in -(2^53)+1..2^53-1, no floats, shortest
string escapes — \", \\, \b,
\f, \n, \r, \t, and
\uXXXX in lowercase hex for all other control characters
U+0000..U+001F; / and non-ASCII characters,
including U+2028 and U+2029, MUST NOT be
escaped). Any lone surrogate (U+D800..U+DFFF) in the event
makes it invalid (treated as provisional). The signed object
M has exactly these six keys:
answers: null, or the reply-target object
{"conv": <conv string>, "from": <null or 64 lowercase hex radio key>, "seq": <int 0..4095>}
(matching com.chee3e.courier's answers object
in courier/matrix/mapping.py; keys sorted
conv, from, seq in canonical
JSON, no extra keys).from: null (radio-less node) or 64
lowercase hex characters (the sender's 32-byte MeshCore radio key).kind: one of the CP2 type letters ("M" or
"K" on Matrix).msg: null or string (the message id from
field msg).part_bytes: array of non-negative integers giving the
UTF-8 byte length of each entry of parts in order (for
K, a single-element array
[len(utf8(k))]).seqs: array of integers (0..4095, matching
field seqs). With sig, this fixes the part
count, the exact split, the reply target, the sender's radio key, the
message id and every seq of the message. sig stays
identical to the signature of the equivalent bare Full frame.node equals that key, sig and
bsig both verify, and seq64 is not stale under
§6.3. Every Matrix ingress path — room timeline, re-feed after start-up
or rebinding, and to-device resend and
relay_request items — MUST apply the same checks before
feeding the engine; rows quarantined by verification are never re-fed.
An event without valid sig and bsig from such
a member is provisional (shown unverified, never fed to the engine), and
so is a copy relayed on the member's behalf that lacks a valid
sig and bsig; a provisional event never
occupies the author's seq.m.relates_to: {"m.in_reply_to": {"event_id": <answered room event>}}
beside the Courier field (Matrix's own relation, not inside
com.chee3e.courier, so not covered by sig or
bsig: a homeserver can change which message it points at,
never the text). A W/N/S reply also carries answers in the
field, a text reply does not. Receivers MUST ignore the relation on a
mirror (relayed_by present).sig and
bsig, is author-direct; a copy relayed on the member's
behalf is signed but relayed. seq64 < 2^53 always holds
(§3.1).sig and
bsig cover the attachment stub
(kind and size_class), not the uploaded media
file bytes. A relaying member or homeserver could substitute the file
while preserving valid signatures; this is an accepted limitation for
now.Vectors: category matrix_bsig.
com.chee3e.courier.dm)Direct conversations (conv = '0') are NEVER posted to
any Matrix room. Over Matrix, direct messages (M,
K) and their receipts (R) travel as end-to-end
encrypted Matrix to-device events of type
com.chee3e.courier.dm, addressed to the recipient's bound
Matrix account (its fresh Courier device ID, or *
otherwise).
Wire JSON:
{
"v": 1,
"node": "<64 lowercase hex Ed25519 sender node key>",
"frame": "<unpadded base64url of sealed_bytes>"
}{"v", "node", "frame"}; v
MUST be integer 1; node MUST be 64 lowercase
hex characters; frame MUST be canonical unpadded base64url
([A-Za-z0-9_-]+) decoding to 28..48000
bytes.F) frame (§3.1) with auth = 2 (Ed25519),
conv = '0', relayed = 0, admin_fp
equal to the active admin fingerprint, author_id equal to
the sender's 32-byte node key, and signed option
0x01 recipient equal to the recipient's 32-byte node key.
M and K: seq64 is the
stream's 64-bit sequence number (one counter shared across all bearers);
0x03 attachment is optional on M.R (receipt and read watermark):
seq64 = 0, ts = 0, signed options
0x01 recipient, 0x05 stream_author (equal to
the recipient's node key), and 0x06 receipt64
(rwm64 || base64), with ASCII receipt body
(encode_receipt).seq64, ts, and receipt watermarks from
the homeserver):
pair_key = derive_pair_key(sender_priv, recipient_pub)
(§2.5; static pair key, no per-message ephemeral key).dm_seal_key = HKDF-SHA256(ikm = pair_key, salt = sender_pub || admin_fp, info = "courier matrix dm", L = 32)
(directional via sender_pub in salt, domain-separated from
aead_key and Direct IP link keys).aad = "courier matrix dm v1\x00" || sender_pub || recipient_pub || admin_fp
(95 bytes).nonce: 12 random bytes per message from an injected RNG
(CLAUDE.md rule 6).sealed_bytes = nonce (12 B) || ChaCha20-Poly1305(dm_seal_key, nonce, aad, inner_full_frame) || tag (16 B).sender MXID is the confirmed (or admin) binding of a roster
member sender_rf and node equals
sender_rf's pinned node key in the signed admin config (and
is not this node's own key).sealed_bytes with
open_matrix_dm(sealed, recipient_priv, sender_pub, admin_fp).verify_full(inner) and require
auth == 2, admin_fp matches,
author_id == sender_pub, conv == '0',
0x01 recipient == recipient_pub, not relayed;
strip hop claims (§3.5); require UTF-8 body.M/K,
check §6.3 staleness (epoch / >2048 behind anchored
mark) and feed BearerInbound (updating peer liveness when
not stale); for R, require
0x05 stream_author == recipient_pub, valid
0x06 receipt64, and valid receipt body, then feed
BearerReceipt (§6.2 exact seq64 crediting,
claims_beyond_head enforced).node_keys in the signed
admin config to use Matrix for DMs; without them Matrix is skipped for
DMs. No Matrix Q/resend is used for DM gaps in this version
(DM gaps recover via Direct IP catch-up or radio Q).Vectors: category matrix_dm (and
neg-matrix-dm-* in negative).
0x80 piggyback and 0x81 position (compact
wwww and pppppppppp, §4.1) are hop
claims: statements by the node that transmitted the frame,
about itself. The piggyback is that node's watermarks for the reverse
stream with the frame's recipient; the position is that node's location.
Neither is part of the message. The frame sender sets them at each
transmission, so they differ between retries and between bearers of one
message, and on a relayed frame they are the relay's, not the
author's.
For that reason they are not in the author's signing input: a relay could no longer pass the author's tag on untouched, and copies of one message would stop carrying the same tag (§5.4). A second tag per hop would cost 9 more characters of a 67-character APRS frame. The rule is instead on who is believed:
authenticates_sender == "yes" (§8.1), and
MUST attribute it to the sender that bearer authenticated: never to the
author_id of a relayed message, and never to the node named
in 0x82."by_binding" or
"no") a receiver MUST ignore hop claims: they change no
watermark, delivery status, bearer health or position. The rest of the
frame is processed as if they were absent. A valid auth tag does not
change this, because the tag does not cover them.authenticates_sender == "yes". On those bearers watermarks
travel only in R frames, whose body is inside the signing
input, and position is not carried.Cost: on APRS or JS8 a receipt is its own R frame (23
characters with T and S, plus the compact form
of 0x06 once defined, §9.2 item 16) instead of 4 piggyback
characters. Position stays on MeshCore, where it is today.
The other unsigned options decide nothing:
0x82 relayed_by is informational and MUST NOT feed any
status or trust decision, and 0x83 age only places
ts (§6.2).
Vectors: category hop_claims.
C)Compact encoding C is a printable UTF-8 text string with
no NUL bytes:
^ T C SS F [wwww] [pppppppppp] [n blocks...] body
| Field | Chars | Encoding |
|---|---|---|
^ |
1 | Literal marker 0x5E. |
T |
1 | Message type: M, K, R,
Q, P, G. |
C |
1 | Conversation: 0 (direct) or A..Z,
a..z (group). |
SS |
2 | 12-bit seq (0..4095), big-endian
_B64. |
F |
1 | 6-bit flags in _B64: bit 0 (1)
reply_required, bit 1 (2) urgent, bit 2 (4)
more_parts, bit 3 (8) has_piggyback, bit 4
(16) has_position, bit 5 (32)
has_extension. |
wwww |
4 | Present iff has_piggyback (bit 3):
received_wm (2 _B64) + read_wm (2 _B64) for
the reverse stream. Hop claim: outside the S tag, used only
per §3.5. |
pppppppppp |
10 | Present iff has_position (bit 4): 60-bit position block
in _B64 (§4.2). Hop claim: outside the S tag,
used only per §3.5. |
n blocks... |
1 + ... | Present iff has_extension (bit 5): 1-char
_B64 block count n, followed by n
extension blocks (§4.3). |
body |
variable | Remaining UTF-8 bytes (§6). |
MeshCore size budget: hard cap 158 UTF-8
bytes total (including header, piggyback, position, and
extension blocks), because MeshCore companion firmware caps DMs at 160
bytes for attempts 0..3 and 158 bytes for attempts
>= 4. Usable body without extensions: 152 B (header
only), 148 B (with piggyback), 142 B (with position), 138 B (with
both).
When has_position is set, 10 _B64
characters pack 60 bits big-endian:
la = clamp(round((lat + 90) / 180 * 2^24), 0, 2^24 - 1).
Decodes to la * 180 / 2^24 - 90 (~1.19 m steps).lo = round((lon + 180) / 360 * 2^24) mod 2^24. Decodes to
lo * 360 / 2^24 - 180 (~2.39 m × cos(lat); wrapped if
>= 180.0).(source_class << 10) | (newer << 9) | age_code:
source_class (2 bits): 0 =
radio, 1 = host, 2 =
phone, 3 = manual.newer (1 bit): 0 = fix is older than or
equal to frame timestamp; 1 = fix is newer than frame
timestamp (cleared to 0 if quantized
age_code == 0).age_code (9 bits, 0..511): piecewise table
where rounding ALWAYS moves the decoded fix time older
(never makes a fix appear fresher than reality):| Code range | Count | Seconds covered | Step |
|---|---|---|---|
0..119 |
120 | 0..119 s |
1 s |
120..239 |
120 | 120..1905 s |
15 s |
240..359 |
120 | 1920..16200 s |
120 s (2 min) |
360..510 |
151 | 16320..151320 s |
900 s (15 min, ~42 h) |
511 |
1 | > 151320 s ("older than table") |
900 s (value 151320 s) |
For age_s >= 0 (used by O,
E, T), age_code(age_s) selects
the smallest index i in 0..510 with
value(i) >= age_s, or 511 if
age_s > 151320.
has_extension, Flag Bit 5)The byte immediately after header / piggyback / position is a 1-char
_B64 count n:
EXT_MAX_BLOCKS = 3 (n in
0..3, chars A..D) and unknown block types fail
decoding.EXT_MAX_BLOCKS rises to
6 (n in 0..6,
chars A..G) (choice: accommodates
O + D + A + N + T + S; listed in §9). All nodes on a
link MUST upgrade to CP2 before new block types (S,
T, D, N) or n > 3
are transmitted.n = 0 ('A') is valid and marks
continuation parts (part >= 1) of a relayed message on
the relayer's direct stream (conv = '0').| Block | Length | Status | Wire Layout |
|---|---|---|---|
O |
8 chars | v1 (extended in CP2) | 'O' + original conv (1) + author member
tag (2 _B64) + author first seq (2
_B64) + age_flags (2 _B64: bit 11
urgent, bit 10 reply_required, bit 9 =
0, bits 8..0 age_code). In v1 MeshCore
conv != '0'; CP2 permits conv == '0' when
paired with D for relayed direct messages. |
E |
9 + nb bytes |
v1 | 'E' + group conv (1, != '0')
+ event digest (4 _B64 = top 24 bits of
SHA-256(event_id)) + age_flags (2
_B64: bit 11 guest, bits 10..9 =
0, bits 8..0 age_code) + nb (1
_B64, 0..16) + UTF-8 display name
(nb bytes). Bridge/Matrix-origin only; no CP2 Full
equivalent. |
A |
3 chars | v1 | 'A' + kind (1: P photo, F
file, V voice, D video, U audio)
+ size_class (1 _B64: 0..15
meaning <= 2^c KiB, or 63 unknown). |
S |
9 chars | CP2 new | 'S' + 8 _B64 chars encoding the 48-bit
(6-byte) big-endian HMAC-SHA256-48 tag. REQUIRED on bearers that do not
natively authenticate the sender. |
T |
3 chars | CP2 new | 'T' + 2 _B64 chars encoding
(0 << 9) | age_code (bits 11..9 MUST be
0; bits 8..0 = 9-bit age_code). REQUIRED on
bearers without a frame timestamp. |
D |
3 chars | CP2 new | 'D' + 2 _B64 chars encoding the final
recipient's member tag (top 12 bits of recipient's node key). Allowed
ONLY alongside an O block with
conv == '0'. |
X |
1 char | v1 (reserved in CP2) | 'X' alone: the author's no-mirror marker on part 0 of a
v1 MeshCore group message (docs/radio-mirror-design.md,
decisions 2026-11-26). The letter is reserved: no CP2 block may use it.
A CP2 encoder never emits it (a mirror_ok=false message
never goes on a CP2 bearer), so a CP2 decoder still rejects it as an
unknown block. |
N |
5 chars | CP2 new | 'N' + 4 _B64 chars: the sender's stream
epoch (§6.3; 24 bits, top 3 bits 0, value
>= 1). Allowed on P, M,
K. Used only from an unrelayed frame on a bearer with
authenticates_sender == "yes"; ignored elsewhere. Not part
of the signing input and dropped in C → F. A node sends it
on its return hello and heartbeat P, and on every
M/K until the recipient has receipted a
message of the current epoch. |
Note (2026-11-27): v1 adds block Y, the reply
reference: 5 chars, 'Y' + author member tag (2
_B64, the radio-key tag as in v1 O) + the
answered message's first seq (2 _B64), on part
0 of a v1 MeshCore group M only
(docs/functional-spec.md 5). The letter is reserved: no CP2
block may use it; a CP2 decoder rejects it as an unknown block, and a
CP2 encoder never emits it (a text reply's reference on CP2 bearers
travels on Matrix only, §3.4). A v1 decoder before 2026-11-27 rejects it
too, so every member updates before replies are used.
Validation rules: CP2 encoders SHOULD emit blocks in
canonical order (O/E, D,
A, N, T, S).
Decoders MUST accept blocks in any order, MUST reject duplicate block
types within one frame, MUST reject unknown block types, MUST reject
reserved non-zero bits in O, E,
T, N, MUST reject N with value
0 or on a type other than P, M,
K, and MUST reject D unless paired with
O(conv='0'). Vectors for N: category
epoch_block.
C32)Bearers that fold character case (e.g., JS8, (unverified, needs
bench)) cannot distinguish mixed-case _B64. CP2
defines an uppercase Base32 (_B32) rendering
C32:
^ + T
(1) + C (1, MUST be '0' or
'A'..'Z') + seq (3 _B32, top 3
bits = 0) + flags (2 _B32, top 4
bits = 0).rwm (3
_B32) + dwm (3 _B32).(la << 36) | (lo << 12) | time_src12 in 12
_B32 chars. Both are hop claims (§3.5). No reference
case-folding bearer authenticates the sender (§8.3), so neither is sent
on them._B32 char
(0..6). Blocks: O (11 chars:
'O' + conv(1) + tag(3) + seq(3) + age_flags(3)),
A (4 chars: 'A' + kind(1) + size_class(2)),
S (11 chars:
'S' + tag48(10 _B32, top 2 bits = 0)), T (4
chars: 'T' + age_code(3 _B32, top 6 bits = 0)),
D (4 chars: 'D' + tag(3 _B32)), N
(6 chars: 'N' + epoch(5 _B32, top 4 bits = 0)).R, Q, P (nonce),
G: each 12-bit sequence field uses 3 _B32
chars (top 3 bits = 0). When mapping C32 → F,
these control bodies are normalized back to standard _B64
bodies so auth tags match F and C.K: macro codes and uppercase parameters are natively
uppercase; lossy flag in F is 0,
so K tags are identical across F,
C, and C32.M: free text is uppercased; the sender MUST set
lossy = 1 (header byte 2 bit 1) when computing the
S tag, and receivers MUST treat the decoded message as a
lossy copy (shown until a faithful copy arrives).C ↔︎ F Mapping, seq64 Expansion, and
Authenticationseq64
Expansion from 12-Bit seqLet ref_seq64 be the stream's mark (§6.3): the highest
accepted seq64 on stream (author_id, conv)
(0 if no message has yet been accepted on that stream), and
let seq12 be the 12-bit sequence number
(0..4095) from a compact frame:
d = (seq12 - (ref_seq64 & 0xFFF)) mod 4096
if d >= 2048:
d -= 4096 # signed difference in [-2048, +2047]
candidate = ref_seq64 + d
Bounds and rejection rules:
candidate < 0 or
candidate >= 2^64, the receiver MUST reject the
frame.type in {'M', 'K'}),
streams start at n = 1 of their epoch (§6.3) and increment
monotonically (4095 -> 4096, where
4096 & 0xFFF == 0). Therefore
candidate == 0 MUST be rejected for M and
K.R, Q, P,
G), seq64 = seq12 (normally 0, no
window expansion).candidate
(never brute-force past epochs). A compact frame originally signed at
seq64 = 5 and replayed once ref_seq64 = 4100
expands to 4101, which fails authentication.candidate MUST have the same epoch as
ref_seq64 and n >= 1 (§6.3); otherwise
reject. On a stream that is not anchored the result is an estimate and
MUST NOT be used for 0x06.C → F)A compact R or Q has no Full form in this
version: a Full R needs 0x05 and
0x06 and a Full Q needs 0x05
(§3.2), which compact encoding does not carry yet (§9.2 item 16).
Given a decoded compact frame C (or C32),
active config admin_fp, roster map, transport
sender_node_id, optional transport
recipient_node_id, stream ref_seq64, optional
frame_ts (on MeshCore, after subtracting the P17
per-recipient offset), arrival_ts, and
hop_authenticated (true iff the bearer declares
authenticates_sender == "yes"):
O block is present: relayed = 1;
resolve author_id uniquely from O.tag against
the roster; conv = O.conv; seq12 = O.seq;
urgent = O.urgent;
reply_required = O.reply_required; include unsigned option
0x82 relayed_by = sender_node_id and
0x83 age = O.age_code;
ts = max(0, (frame_ts or arrival_ts) - age_value(O.age_code)).relayed = 0;
author_id = sender_node_id; conv = C.conv;
seq12 = C.seq; urgent = C.urgent;
reply_required = C.reply_required; if frame_ts
is present, ts = frame_ts; else if T block is
present, ts = max(0, arrival_ts - age_value(T.age_code));
else ts = 0. If T block is present, include
unsigned option 0x83 age = T.age_code.seq12 to
seq64 per §5.1.< 0x80):
conv == '0': resolve recipient (D.tag
if D present, else recipient_node_id) and
include 0x01 recipient (32 B) if known.A block is present: include
0x03 attachment = (kind_char, size_class).N block is not mapped to any option; it is consumed
per §6.3 and dropped.>= 0x80):
hop_authenticated: C.piggyback →
0x80 piggyback (4 B) and C.position →
0x81 position (8 B binary). Otherwise both are dropped
(§3.5).relayed → 0x82 relayed_by (32 B).T or O → 0x83 age (2 B).body = C.body.encode("utf-8"),
encrypted = 0, lossy per bearer
(1 for C32 case-folded text, else
0).S block is present: auth = 1,
auth_tag = S.tag (6 B). Else auth = 0,
auth_tag = b"".F → C)F.auth not in {0, 1}, or
F.encrypted == 1, or any signed option other than
0x01 (recipient) and 0x03
(attachment) is present, or F.body is not
valid NUL-free UTF-8. A Full R carries 0x05
and 0x06 and therefore has no compact form in this version;
see §6.2.authenticates_sender == "yes" and
F.relayed == 0, map 0x80 → piggyback and
0x81 → position; otherwise omit both hop claims (on a
relayed copy, F's 0x80 and 0x81
belong to an earlier hop and MUST NOT be forwarded; any piggyback or
position a relay sends on an authenticating bearer is set fresh by the
relay at transmission, §3.5). Map 0x03 → A
block, 0x83 → T block (when not relayed and
bearer needs age), F.auth == 1 → S block.F.relayed == 1: outer conv = '0', outer
seq = relay_seq & 0xFFF, outer
urgent = reply_required = 0; emit O block with
F.conv, key_tag(F.author_id),
F.seq64 & 0xFFF, age from 0x83, and
F.urgent/F.reply_required; if
F.conv == '0', also emit D block with
key_tag(0x01 recipient).C.conv = F.conv,
C.seq = F.seq64 & 0xFFF,
C.urgent = F.urgent,
C.reply_required = F.reply_required.auth |
Algorithm | Tag Size | Computation & Verification |
|---|---|---|---|
0 |
None | 0 B | Permitted ONLY on bearers declaring
authenticates_sender == "yes" (MeshCore pairwise encrypted
DM) or legacy unverified v1 frames. |
1 |
HMAC-SHA256-48 | 6 B | tag = HMAC-SHA256(mac_key, signing_input)[:6]. MUST
verify in constant time. Online guessing is bounded by §5.6. |
2 |
Ed25519 | 64 B | Pure RFC 8032 Ed25519.Sign(author_seed, signing_input).
Verify against author_id, which MUST belong to the active
signed admin config roster. |
3 |
ChaCha20-Poly1305 | 16 B | RFC 8439 AEAD with
key = aead_key(pair_key, author_id, admin_fp),
aad = canonical_signing_input(F) (without body),
nonce = the 12 bytes of option 0x04 (§5.5).
MUST NOT be transmitted on any bearer declaring
confidentiality == "encryption_forbidden". |
Tag equality invariant: for any message with
auth = 1, canonical_signing_input(F) and
canonical_signing_input(compact_to_full(C)) MUST be
byte-for-byte identical, yielding the exact same 48-bit tag regardless
of clock skew, quantized T/O age,
piggyback/position options, or relayed status. The same
property means the tag says nothing about piggyback or position; §3.5
governs those.
auth = 3)Every auth = 3 frame MUST carry signed option
0x04, and its 12 bytes are the nonce. A decoder MUST reject
an auth = 3 frame without it. The sender MUST draw the 12
bytes from a cryptographically secure random source for each encryption.
A nonce is never derived from type, conv,
seq64 or any stored counter.
Reason: a derived nonce repeats when a node loses stream state
(restore from backup, reset, reinstall with the same node key) and
allocates a seq64 again for different text. With
ChaCha20-Poly1305 one repeat under one key reveals the XOR of the two
plaintexts and lets an attacker forge frames. A random nonce depends on
no state that can be lost, so restore and reset need no special
handling.
2^32 frames under
one aead_key (collision probability stays below
2^-32). aead_key is per direction, per pair
and per admin key (§2.5).seq64, which is in the AAD.On a bearer that does not declare
authenticates_sender == "yes", the source address of a
frame is only a claim. On APRS-IS anyone can send under any callsign. A
rule that mutes a source after bad tags would let anyone silence a
member with a handful of forged frames, so:
Q, the
next bearer on the ladder).This is enough against guessing: at 10 tries per second a 48-bit tag takes about 450,000 years on average. A flood can still crowd out genuine frames on that one bearer while it lasts, which is true of any open bearer; it cannot be aimed at one member and it leaves no state behind.
M K R Q P G)| Type | Sequenced | Body Format | Semantics |
|---|---|---|---|
M |
Yes (seq64 >= 1) |
UTF-8 text (no NUL in compact) | User text message (or caption when paired with A /
0x03 attachment stub). Long texts split across
1..4 consecutive seqs with more_parts = 1 on
all but the last part. |
K |
Yes (seq64 >= 1) |
<ver 1><code 1..8>[ <param>...] |
Codebook macro or built-in reply (W WILCO,
N NEG, S STBY). Version mismatches or unknown
codes MUST show raw with a warning (never guessed). Direct reply param
(3 chars): <conv><seq2>. Group reply param (4
chars): <orig_tag2><seq2>. |
R |
No (seq = 0) |
<rwm 2><dwm 2>[<bitmap 2>] |
Cumulative, idempotent app receipt for reverse stream: received
watermark, read watermark, optional 12-bit bitmap (bit i =
rwm + 1 + i held). Never itself receipted. In Full encoding
the claim is option 0x06; the bitmap is relative to
rwm64. The read watermark is
dwm64 = rwm64 - ((rwm - dwm) mod 4096) when
dwm != 0; a receiver whose read position is 4096 or more
below rwm64, or below base64, sends
dwm = 0. |
Q |
No (seq = 0) |
0..8 × <seq 2> |
Re-request missing seqs (empty body = "send me your receipt").
Mandatory after Unconfirmed grace period. |
P |
No (seq = 0) |
2-char nonce, 1-char tracking time left
(2 min units), or
<nonce2>M<mxid|-> |
Link probe / return hello / heartbeat / live tracking update / Matrix binding claim (max 139 B mxid on MeshCore). Never receipted; counts as peer heard. |
G |
No (seq = 0) |
<role 1> + 1..37 ×
<first 2><last 2> |
Gap closure: role 'S' (skip from sender) or
'L' (lost from receiver). Each inclusive range MUST span
< 2048 seqs. |
(author_id, admin_fp, conv, seq64) across ALL bearers.R body or piggyback accepted on a bearer
with authenticates_sender == "yes", unrelayed (v1
behaviour, 12-bit), or (b) from a signed 0x06 claim. On any
other bearer, and for every relayed R, an R
without a valid 0x06 MUST NOT change any delivery status. A
sender credits delivery d to the R's author
only if base64 <= d.seq64 <= rwm64, or
d.seq64 - rwm64 is a set bitmap bit; Read only if also
d.seq64 <= dwm64. No 12-bit value is ever widened to
decide a credit. An R whose rwm64 plus highest
bitmap bit exceeds the highest seq64 the sender allocated
on that stream is dropped whole and counted. Because the claim names
absolute seqs, a replayed, late or relayed R credits only
what its author really held; it needs no freshness. Compact carriage of
0x06 for APRS and JS8 is not defined yet (§9.2 item 16);
until it is, receipts on those bearers credit nothing.seq64 order with immediate gap display (nothing held back).
Across authors in a thread, by ts then arrival order; a
full copy whose ts is far from arrival time without an age
is placed at arrival and marked.ts is not authenticated.
ts and the T/O/0x83
age are outside the signing input (§3.3), so on a bearer that does not
authenticate the sender anyone who can inject a copy can choose where a
message sorts among other authors' messages. Order within one stream is
unaffected, because seq64 is signed. ts MUST
be used for display order only, never for dedup, receipts, replay
protection or status.Queued → Sent (bearer accepted) →
At bearer / At radio (bearer's native ACK;
NEVER shown as delivered) → Received (recipient node's app
receipt via any bearer) → Read → Acknowledged
(W/N/S reply). Terminal/auxiliary states: Paused,
Unconfirmed, Cancelled, Expired,
and Handed off (ceiling for guests reached
through a bridge; foreign replies/reactions appear as information only
and NEVER become Received).(author_id, admin_fp, conv, seq64) carry different
bodies): display the copy with the strongest author proof and attach a
warning:
auth = 2)auth = 1) / AEAD
(auth = 3)O without
S)lossy = 1, e.g., case-folded
C32)epoch(s) = s >> 32,
n(s) = s & 0xFFFFFFFF.
Sender.
1..2^21-1. It
is stored outside the stream-state database, beside the node key, and
written durably before it is first used. It is never derived from a
clock.e + 1 when the node verifies a frame
signed by its own key with epoch e above its own, or when
the operator sets it.M or K until its epoch is set;
it still receives.n = 1 (compact
seq 1). Messages of the earlier epoch that are not yet Received are
closed as Expired; a seq is never reissued or renumbered.Evidence. Signed: the author's tag or
signature verified (§5.4; on Matrix sig and
bsig), relayed or not. Author-direct: signed, not
relayed, and received from the author itself: on the author's own Direct
IP link, as the author's own post from its bound Matrix account, or
unrelayed on a bearer with
authenticates_sender == "yes".
Receiver state. Per author node key:
epoch_A (0 = unknown). Per stream: the 12-bit window, and
one mark: the highest accepted seq64. The
mark is the ref_seq64 of §5.1; there is no second
high-water value. A stream is anchored when its mark is
a real seq64 tied to the window; base is the
lowest seq of its 64-bit claim.
A signed 64-bit arrival a, in this
order:
epoch(a) < epoch_A: stale. Dropped (provisional on
Matrix), counted, shown in bearer status.epoch_A == 0: set epoch_A = epoch(a).
Nothing is reset.epoch(a) > epoch_A: set
epoch_A = epoch(a) and reset every stream of that author to
its initial state (empty window, mark epoch·2^32, anchored,
base = mark + 1). Any signed frame may do this: a replay
cannot carry an epoch above the author's current one.a + 2048 < mark, stale as in 1.
If a >= wm64 + 2048 (2048 or more past the 64-bit window
watermark wm64, keeping mark - wm64 < 2048
invariant), the window is rebuilt at a (mark
= a, base = a, wm64 = a); the
seqs skipped are shown as a gap and are not claimed. Otherwise
a goes through the window and the mark becomes
max(mark, a).a goes through the 12-bit window. If
a is author-direct and the window accepts it as new, the
stream becomes anchored with mark = a,
wm64 = a - seq_diff(a & 0xFFF, wm_before) (advancing
with the window), and base = wm64_before + 1; the window is
not reset. If a is author-direct and cannot fit in the
existing 12-bit window because it is 2048 or more ahead of the
unanchored window (including a fresh/unused stream receiving
(a & 0xFFF) in {0, 2048..4095}), the window is rebuilt
and anchored at a (mark = a,
base = a, wm64 = a). If a is
author-direct and the window takes it for a duplicate (at or below its
watermark, or held), it is the author's restarted stream (sender 5) when
its signed content (body and more_parts) differs from every
copy the window keeps for that 12-bit seq, or, when the window keeps
none and is not empty, when epoch_A was learned from
a itself under rule 2 and a is not a catch-up
or resend copy: that stream alone is reset as in rule 3 (mark
epoch(a)·2^32, anchored, base = mark + 1) and
a then goes through rule 4, so it is new and the epoch's
seqs below it are a gap. ts is not evidence (§6.2). A seq
whose gap was closed keeps the late-arrival path. A relayed
a never anchors, never resets and never sets the mark.A 12-bit arrival expands per §5.1 against the mark when the stream is anchored, and moves the mark once accepted by the window. On a stream that is not anchored it uses the window alone.
The author's epoch from a hello (epoch,
§8.4) counts as signed evidence for rules 2 and 3. So does compact block
N (§4.3) on an unrelayed frame on an authenticating
bearer.
Receipts sent. Anchored: rwm64 is the
64-bit window watermark wm64, not below
base - 1; base64 = base. Not anchored: after
accepting a signed frame a as new,
rwm64 = base64 = a; otherwise
rwm64 = base64 = 0.
Node key change. A new node key has no state on receivers and starts at rule 2.
Limitations. (i) A receiver with no state for a stream accepts the first signed frame it is given, which may be an old one; the next newer frame corrects the mark. (ii) Until a stream is anchored, a relaying member or the homeserver can present an old signed message once per 12-bit position; it is shown as new and can shadow one later message at that position. Nothing is falsely credited, and the first author-direct frame ends the exposure. (iii) Restoring an older copy of the whole data directory reissues seqs in the same epoch; see §9.2 item 13.
Vectors: categories stream_epoch (receiver rules) and
receipt64 (§6.2 credit).
CP2 uses two distinct layers so the reliability engine only tracks application-level envelopes:
Long M text is split on UTF-8 character boundaries into
1..4 consecutive seq64 values with
more_parts = 1 on parts 0..k-2 and
more_parts = 0 on part k-1. On MeshCore, part
budgets follow §4.1 (152 B base, 148 B with piggyback on part 0, minus
any extension prefix). Bearers with large MTUs (Direct IP, Matrix,
Winlink) send all parts in a single message.
For bearers whose mtu_bytes is smaller than a single
serialized envelope (e.g., APRS at 67 chars for a 158-byte compact
envelope), the bearer plugin MUST fragment on transmit and reassemble on
receive transparently before handing whole envelopes to the engine.
len(envelope_bytes) <= mtu_bytes, the plugin
sends the envelope verbatim without % framing.% <tag 2 _B64> <idx_cnt 1 _B64> <piece>
'%' (0x25, distinct from envelope
marker '^' and allowed in APRS).frag_tag): top 12 bits of
SHA-256(complete_envelope_bytes) encoded as 2
_B64 chars
(seq_encode((h[0] << 4) | (h[1] >> 4))).
(Choice: deterministic per rule 6 and serves as a 12-bit reassembly
integrity check; listed in §9.)idx_cnt): 1 _B64 char (6 bits)
encoding (index << 3) | (count - 1), where
1 <= count <= 8 and
0 <= index < count. (Choice: storing
count - 1 supports up to 8 fragments instead of 7; listed
in §9.)mtu_bytes - 4 bytes. For
UTF-8 text envelopes, splitting MUST fall on UTF-8 character boundaries;
for binary Full frames, on byte boundaries. Envelopes needing more than
8 fragments for mtu_bytes MUST be rejected
(mtu_bytes MUST be >= 5).mtu_bytes = 67, payload 63 B/frag) produces
exactly 3 frames (63 + 63 + 32 = 158
payload bytes; 67, 67, 36 chars
on air).(sender_addr, frag_tag, count) with an expiration timer
(RECOMMENDED: 10 minutes on APRS)._B64,
or index >= count.index are idempotent; conflicting payload bytes for the
same index MUST reject and discard the buffer.0..count-1 pieces arrive (in any order),
concatenate pieces 0..count-1, verify
frag_tag_for(reassembled) == frag_tag (reject on mismatch),
and deliver the complete envelope upward.C32): use a
6-char uppercase Base32 header
% <tag 3 _B32> <idx_cnt 2 _B32> with the same
semantics.Every bearer and bridge plugin lives behind a uniform contract (in-process Python asyncio class, or out-of-process JSON-lines over stdio/WebSocket). CLAUDE.md Rule 2 extends to all plugins: nothing reaches a bearer except through its plugin, and the plugin ALWAYS enforces that bearer's airtime/rate budget.
Every plugin MUST return a static capability object from
capabilities() before opening traffic:
| Field | Type / Allowed Values | Meaning and Protocol Consequence |
|---|---|---|
name |
str |
Unique plugin identifier (e.g., meshcore,
matrix, direct_ip, aprs,
js8, winlink, email,
discord, irc, imessage). |
kind |
"bearer" | "bridge" |
"bearer" carries CP2 between Courier nodes.
"bridge" reaches non-Courier users as guests; status
ceiling is Handed off and messages MUST NEVER loop back to
their origin service. |
mtu_bytes |
int >= 5 |
Maximum payload bytes in a single bearer frame. |
alphabet |
"binary" | "utf8" | "ascii" |
"aprs_ascii" | "upper_base32" |
Allowed wire character set. "aprs_ascii" = printable
ASCII 0x20..0x7E excluding |, ~,
{. Plugins MUST refuse frames violating their alphabet
rather than corrupting signed bytes. |
encoding |
"full" | "compact" |
"compact32" | "json" |
Wire encoding carried by the plugin. |
link_fragmentation |
bool |
Whether the plugin implements Layer 2 %
fragmentation/reassembly (§7.2). |
native_ack |
"none" | "next_hop" |
"end_to_end" |
Whether the bearer emits a transport ACK. Only
"next_hop" or "end_to_end" may advance status
to At bearer (At radio); NEVER
Received. |
authenticates_sender |
"yes" | "by_binding" |
"no" |
If "no", the engine MUST attach auth = 1
(S tag), auth = 2 (Ed25519) or
auth = 3 on every frame and reject unauthenticated inbound
frames. Unless "yes", hop claims are neither sent nor used
(§3.5) and bad tags are handled per §5.6. |
confidentiality |
"end_to_end" | "hop" | "none"
| "encryption_forbidden" |
If "encryption_forbidden" (amateur radio), the plugin
MUST refuse any encrypted frame (auth = 3), and the engine
MUST transmit clear text ONLY if the conversation's signed admin config
explicitly opts in (default: codes and receipts only). |
has_frame_timestamp |
bool |
If false, compact frames MUST include the
T (age) extension block. |
addressing |
"unicast" | "broadcast" |
"room" |
Delivery topology (determines fan-out and whether pairwise or group auth tags apply). |
cost_class |
0 | 1 | 2 |
3 |
Delivery ladder rung: 0 free/IP, 1
unlicensed shared RF, 2 amateur VHF, 3 amateur
HF. |
latency_class |
"seconds" | "minutes" |
"hours" |
Expected one-way delivery timescale. |
hold_before_next_rung_s |
float | null |
Default hold waiting for an app receipt before escalating to the
next cost class (null = manual/urgent only). |
airtime_rules |
object | Mandatory budget rules: budget_kind
("rate_limit" | "duty_cycle" |
"frames_per_hour" | "tx_seconds_per_hour"),
window_s, ceiling value (max_duty_fraction /
max_frames / max_tx_s), optional
max_single_tx_s, optional flood_multiplier,
and requires_licence (bool: amateur bearers
MUST refuse TX unless the local node declares a valid licence for the
band and mode). |
open(),
capabilities(),
send(address, frame) -> Sent | Held(reason) | Rejected(reason) | Unsure,
cancel(send_id).
Unsure (preserving v1 BearerUnsure):
unknown transmit outcome; MUST NEVER be counted as
Sent.Held(reason): bearer budget or link policy held the
frame without transmitting.inbound(address, frame, meta),
ack(send_id, meta), peer_heard(address, meta),
link(up, reason), budget(snapshot).Values for APRS and JS8 are provisional (unverified, needs
bench); see docs/protocol-findings.md §17.
| Capability | MeshCore | Direct IP | Matrix | APRS (unverified) | JS8 (unverified) |
|---|---|---|---|---|---|
kind |
bearer |
bearer |
bearer (+ bridge) |
bearer |
bearer |
mtu_bytes |
158 |
65535 |
65536 |
67 |
~12–18 chars/frame |
alphabet |
utf8 (no NUL) |
binary |
utf8 |
aprs_ascii |
upper_base32 |
encoding |
compact |
full |
json |
compact |
compact32 |
link_fragmentation |
false |
false |
false |
true |
true (or codes/R only) |
native_ack |
end_to_end (DM) |
none |
none |
end_to_end (ack) |
end_to_end (ACK) |
authenticates_sender |
yes |
no (uses auth=2) |
by_binding (+ sig, bsig) |
no (S required) |
no (S required) |
confidentiality |
end_to_end |
hop (link sealed per §8.4) |
none (rooms) / end_to_end (DM
to-device) |
encryption_forbidden |
encryption_forbidden |
has_frame_timestamp |
true |
true (F.ts) |
true |
false (T required) |
false (T required) |
cost_class |
1 |
0 |
0 |
2 |
3 |
airtime_rules.budget_kind |
duty_cycle (10%/10m, 6 floods) |
rate_limit |
rate_limit |
frames_per_hour |
tx_seconds_per_hour |
airtime_rules.requires_licence |
false |
false |
false |
true |
true |
A Direct IP link is a WebSocket between two nodes. One node dials
(role = "initiator"), the other accepts
(role = "responder"). Both frames of the handshake and the
key-confirmation frames are WebSocket text frames carrying JSON; after
key confirmation every frame is a binary sealed frame. Node identities
are the Ed25519 keys of §2.1; pair_key is §2.5. Direct IP
declares authenticates_sender: "no" (so hop claims, §3.5,
are neither sent nor used even though the link is mutually
authenticated) and confidentiality: "hop", and carries
auth = 2 (Ed25519) Full frames only (never
auth = 3). All hex values in §8.4 are
lowercase; senders MUST emit lowercase hex, and
receivers MUST reject non-hex or wrong-length strings.
admin_fp (20 hex), config_version (int),
eph (64 hex, fresh X25519 public key), epoch
(int), mac (64 hex), node_id (64 hex initiator
node key), nonce (32 hex, 16 random bytes),
role ("initiator"), seen (int),
to (64 hex responder node key). epoch is the
sender's own stream epoch (§6.3); seen is the highest epoch
for which the sender holds signed evidence from the peer (0 if none).
There is no timestamp, and no step of the handshake reads a wall clock.
hk = HKDF-SHA256(ikm = pair_key, length 32, salt = 0x00 * 32, info = "courier link hello" || I || R),
where I and R are the raw 32-byte Ed25519 node
keys of initiator and responder (ASCII label, no trailing space).mac = HMAC-SHA256(hk, "courier link hello" || 0x00 || C),
where C is the frame with the mac member
removed, which is the canonical JSON of the object without
mac., and :, no whitespace,
exactly the key set above, no duplicate key, string values without
escapes, integers as plain decimal in 0..2^53-1 with no
sign, leading zero, fraction or exponent. Hex is lowercase; a receiver
MUST reject uppercase hex and MUST NOT change case. A receiver parses,
re-serialises and compares bytes; any difference is a failure.admin_fp;
node_id is a roster member's node key and not its own;
role == "initiator"; to is its own node key;
mac in constant time; and (node_id, nonce) not
seen in the last 120 s on its monotonic timer. On any failure it closes
the socket and sends nothing. A hello replayed after 120 s is answered
with a responder hello and fails at key confirmation; it creates no link
state.admin_fp,
config_version, eph, epoch,
node_id, nonce, role
("responder"), seen, in the same canonical
form; key confirmation in item 4 authenticates it. The initiator drops
the link if the responder's hello is not canonical, has a different
admin_fp, has a node_id that is not the
expected roster peer or equals its own key, or has
role != "responder".config_version mismatch does NOT fail the handshake
(members update at different times); both values are bound into
H, and the node logs the mismatch and shows it in bearer
status.H = SHA-256("courier link transcript" || u32be(len(h1)) || u32be(len(h2)) || h1 || h2),
where h1 and h2 are the exact UTF-8 bytes of
the two hello text frames as sent (the initiator's includes
to, epoch, seen and
mac; the responder's includes epoch and
seen), h1 from the node with the lower
node_id (byte-wise) and h2 from the other.
Both nonces, both roles, both ephemeral keys, admin_fp,
config_version, both epoch and
seen values, and the initiator's to and
mac are therefore bound into everything below.eph_shared = X25519(eph_priv, peer_eph); implementations
MUST reject the handshake if eph_shared == 0x00 * 32 (same
RFC 7748 §6.1 low-order point check as §2.5).
ikm = pair_key || eph_shared. For a label L
and a node key P (raw 32 bytes, not hex):
key(L, P) = HKDF-SHA256(ikm, length 32, salt = H, info = L || P).
The sealing key for frames we send is
key("courier link ", own_node_key), for frames we receive
key("courier link ", peer_node_key). Confirm keys are
key("courier link confirm ", sender_node_key). Both HKDF
labels end with a trailing ASCII space (0x20). The
ephemeral private key is discarded after the handshake (forward secrecy
against a later compromise of node keys).{"confirm": hex(HMAC-SHA256(confirm_key_of_sender, "courier link confirm" || H))}
(lowercase hex; note no trailing space in the HMAC label) and verifies
the peer's in constant time with the peer's confirm key. Either side
that does not receive a valid confirm in time closes the socket. A link
exists only after both confirmations verify and the responder has
accepted it (item 6).counter (u64 BE) || ChaCha20-Poly1305(key, nonce = 0x00000000 || counter, plaintext) || tag (16 B).
The counter starts at 0 per direction and increases by one; a receiver
rejects any counter below the next one it expects. A frame that fails
authentication or is replayed is dropped without moving any counter; 20
of them within 60 s close the link. Plaintexts shorter than a Full frame
(under 64 bytes) are link control frames, never delivered: empty =
accepted, 0x01 || id (8 B) = ping,
0x02 || id (8 B) = pong echoing that id (so
overlapping probes cannot answer each other), and 0x03 =
refused.0x03
(refused) on the newcomer and closing its socket; if no
pong arrives, close the old link and accept the newcomer;node_id (byte-wise) and close
the other; when both have the same initiator (a redial after a lost
accepted), the newest wins and the older is closed. The
responder applies this rule after key confirmation and before sending
accepted. The initiator applies it when it receives the
responder's accepted and before sending its own. Fast redial
after a dead link therefore hits the probe, never the tiebreak. Dead
sockets are also found by WebSocket heartbeats (15 s). An initiator that
is refused or whose link drops backs off exponentially: base 1 s,
multiplier 2, cap 30 s, resetting after a link has stayed up for 60
s.auth = 2 (Ed25519) whose
author_id is a node key of its signed admin config, whose
admin_fp matches, and which are not relayed
unless authored by a third member; an unrelayed frame MUST be authored
by the link's peer. Hop claims (0x80, 0x81)
are ignored (§3.5). A direct message (conv = 0) MUST carry
0x01 recipient equal to the receiver and is never relayed.
An R is accepted, direct or relayed, when its
auth = 2 signature verifies, its author is a member of
conv, and 0x05 stream_author is present. It
feeds delivery status only per §6.2. Only an R received
directly from the link's peer triggers serving (§8.5). A DM
R is never relayed. A DM is served from a store-and-forward
cache only to its recipient, a group frame only to members of that
group.unreachable (no connection),
no answer to hello (closed before a responder hello: wrong
key, wrong admin_fp, or not in the peer's roster),
confirmation failed, refused
(0x03), or linked. A node also shows
epoch behind when a peer's seen exceeds its
own epoch. No status depends on a clock.Vectors: category direct_ip_handshake.
A holder serves cached frames of stream S to requester
P only on an R received directly from
P on a live link. With a 64-bit claim, it serves frames
with seq64 > rwm64 in the same epoch that the bitmap
does not cover, oldest first; if the cache holds frames from a higher
epoch than epoch(rwm64), it serves the newest cached
epoch's frames above cursor, oldest first (ignoring the
lower-epoch bitmap). With rwm64 = 0 and
rwm = 0 (a fresh or wiped peer with no state), it serves
the newest cached epoch's frames above cursor, oldest
first; otherwise with rwm64 = 0, it serves only frames
within 2048 of its newest cached seq that are ahead of the body's 12-bit
rwm. It keeps a cursor per link and stream, and serves only
above max(cursor, rwm64) (or cursor when
serving a higher epoch); the cursor is forgotten when the link drops or
is replaced. Served frames use at most half the link's rate limit and
wait while live frames are pending. A frame the limiter holds is
retried, not dropped. Frames of an epoch below the author's current one
are discarded from the cache.
docs/protocol-v2-proposal.md §9These questions remain open for group decision and are NOT silently decided by this specification:
| # | Question | Proposal Recommendation |
|---|---|---|
| Q1 | Which git remote is primary: one of the two hosted copies? | Pick one; mirror the other. |
| Q2 | What do we publish publicly so amateur radio use is permitted (47 CFR §97.309(a)(4)): the whole repo, or only this protocol document? | At least docs/protocol-v2.md, before Phase P3. |
| Q3 | Are node keys required from one admin config version, with all nodes upgrading together? | Yes. |
| Q4 | The N-bearer seam touches the engine while user testing is live. Which branch, and when does it merge? | Its own branch; merge after the Phase 5 gate. |
| Q5 | Keep today's envelope bytes on MeshCore (12-bit seq, 4 parts), or redesign them? | Keep (this spec assumes Keep). |
| Q6 | Auth tag on a broadcast bearer (APRS/JS8): pairwise tags (1 frame per recipient) or a group tag (1 frame, but any member can forge another)? | Pairwise default; group tag as an admin opt-in. |
| Q7 | Which conversations may send free text in clear on amateur bands? | None by default; codes and receipts only. |
| Q8 | A member with several nodes: does any one of them holding a message
make it Received? |
Yes. |
| Q9 | Must a phone ever be a standalone node with a BLE radio and no Raspberry Pi? | Decides whether to build a Rust core. |
| Q10 | Who sends APNs pushes (shared key per node vs small relay), and how is the iOS app distributed? | Open. |
| Q11 | CarPlay: widget and Live Activity only, or apply for Apple's communication entitlement? | Widget first. |
Where the proposal left wire-level mechanics unspecified, this
document chose concrete defaults (and vectored them in
docs/vectors/cp2-vectors.json) so implementers have an
unambiguous spec. None of them is decided: they are listed under
"Proposed" in docs/decisions.md and bind nobody until the
group moves them up.
ts (bytes
60..63) and relayed (byte 2 bit 0) alongside
options_len (byte 51), so compact T (age)
without a shared clock and relayed O+S copies produce the
exact same tag as Full F.salt = min(pub_a, pub_b) || max(pub_a, pub_b) for
pair_key, plus HKDF subkeys "courier mac"
(auth = 1) and directional "courier aead" with
salt = author_id || admin_fp (auth = 3).auth = 3) nonce: random 12 bytes
per encryption, always carried in signed option 0x04; no
derived nonce (§5.5).O blocks and v1 group replies; node key on CP2-native
blocks (D and non-v1 O), with first-byte
uniqueness enforced on node keys too.EXT_MAX_BLOCKS raised from 3 to
6 in CP2, and O relaxed to permit
conv = '0' when paired with D for relayed
direct messages.frag_tag = top
12 bits of SHA-256(envelope_bytes) (deterministic integrity
check), and 3-bit count - 1 supporting 1..8
fragments.C32 uppercase Base32 layout for
case-folding bearers, normalizing control bodies back to
_B64 for cross-bearer tag equality and setting
lossy = 1 on uppercased M text.0x02 answers omitted when targeting C↔︎F
tag equality on K replies (whose body already
encodes the target).0x80 piggyback uses 12-bit watermarks (4
B) so C↔︎F stays stateless for per-hop piggybacks.sig and bsig
(§3.4): sig signs the single assembled Full message
(more_parts = 0, seq64 = seqs[0] expanded) for
multi-part posts; bsig signs
"courier matrix bind v1" || 0x00 || sig_bytes || M where
M is Matrix canonical JSON of
{answers, from, kind, msg, part_bytes, seqs}, binding part
splits, reply target, radio key, message id, and every seq across all
Matrix ingress paths (room timeline, re-feed, to-device
resend/relay_request). Media file bytes are
not covered by sig/bsig (accepted
limitation).authenticates_sender == "yes" (§3.5). Still open: whether
position should also travel on other bearers, which would need a signed
carrier (a signed option and a compact block of about 11
characters).seq64 = epoch·2^32 + n below 2^53; the epoch
is stored beside the node key and never taken from a clock; a wipe, or
stream state from an earlier epoch, starts a new epoch with every stream
at n = 1; one mark per stream (the §5.1 reference); any
signed frame may raise an author's epoch, which resets that author's
12-bit windows; only an author-direct frame anchors a window built from
radio seqs; a jump of 2048 or more past an anchored mark rebuilds the
window and is never claimed in a receipt. Open: restoring an older copy
of the whole data directory is not detected locally (the node reissues
seqs in the same epoch; an old receipt can then credit a reissued seq,
and peers drop the new message as a duplicate). The node shows a warning
when a peer's R claims a seq above anything it allocated,
and the operator sets a new epoch. Open: a radio-only receiver learns a
new epoch only from block N, which no bearer transmits
before the MeshCore plugin moves to CP2 compact.authenticates_sender: "no" (hop claims ignored),
confidentiality: "hop", auth = 2 Full frames
only; initiator-MAC'd hello (hk, C,
mac, to, 120 s (node_id, nonce)
replay set, ASCII-only, lowercase hex; no timestamp in the hello; exact
key sets and byte-exact canonical form; epoch and
seen) verified before allocating state or replying; 2 s
hello deadline and 64 unconfirmed sockets with no per-address limits or
/64 keying; config_version mismatch allowed and bound into
H; ephemeral X25519 all-zero check, raw 32-byte
P in HKDF info, ChaCha20-Poly1305 link sealing
and control frames (accepted, ping,
pong, 0x03 refused); local-state
one-link-per-peer rule (probe accepted link / tiebreak unaccepted
simultaneous dial / same-initiator newest wins) and 1 s–30 s backoff
(reset after 60 s); dial outcomes distinguishable in status.0x05,
0x06; §6.2): an R claims the absolute range
[base64, rwm64]; credit is by exact seq64;
relayed and late receipts are accepted. Catch-up serving uses
rwm64 (§8.5).0x06 (and of
0x05 on R and Q) for bearers that
do not authenticate the sender (APRS, JS8) is not defined. Until it is,
an R on those bearers credits nothing. Needed before
P3.com.chee3e.courier.dm to-device event
{"v": 1, "node": "<64 lowercase hex>", "frame": "<unpadded base64url>"}
outer-sealing a complete auth = 2 Ed25519 Full frame
(conv = '0', 0x01 recipient;
0x05/0x06 on R) with
ChaCha20-Poly1305 under static
pair_key-derived
dm_seal_key = HKDF-SHA256(pair_key, salt = sender_pub || admin_fp, info = "courier matrix dm", L = 32),
aad = "courier matrix dm v1\x00" || sender_pub || recipient_pub || admin_fp,
and a random 12-byte nonce from an injected RNG. Direct messages cascade
direct_ip (15 s DM hold) -> matrix
(matrix_confirm_wait_s, 60 s) -> radio,
with no Matrix Q/resend for DM gaps in this version.