<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Irshad Ali</title>
    <description>The latest articles on DEV Community by Irshad Ali (@irshadali5).</description>
    <link>https://dev.to/irshadali5</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4114032%2F80bc83dc-2e6d-4876-8d96-6fdfdc2bb9c1.png</url>
      <title>DEV Community: Irshad Ali</title>
      <link>https://dev.to/irshadali5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/irshadali5"/>
    <language>en</language>
    <item>
      <title>Beyond Single-Key Cryptography: Engineering Decentralized Multi-Device Identity, Sovereign Trust, and Instant Revocation in Rust</title>
      <dc:creator>Irshad Ali</dc:creator>
      <pubDate>Tue, 29 Sep 2026 23:23:51 +0000</pubDate>
      <link>https://dev.to/irshadali5/beyond-single-key-cryptography-engineering-decentralized-multi-device-identity-sovereign-trust-bl0</link>
      <guid>https://dev.to/irshadali5/beyond-single-key-cryptography-engineering-decentralized-multi-device-identity-sovereign-trust-bl0</guid>
      <description>&lt;p&gt;Focus: Spec 02 — Multi-Device Identity Architecture (crates/siar-identity-multidevice)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                              +------------------------------+
                              |    Account Root Keypair      |
                              |    Ed25519 (Offline / HSM)   |
                              +--------------+---------------+
                                             | Signs (Rarely)
             +-------------------------------+-------------------------------+
             |                                                               |
             v                                                               v
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;+-----------------------------+                                 +-----------------------------+&lt;br&gt;
  |    Device Certificate A     |                                 |    Device Certificate B     |&lt;br&gt;
  |  (Generation 4, Phone)      |                                 |  (Generation 4, Laptop)     |&lt;br&gt;
  |  • Device PubKey (Ed25519)  |                                 |  • Device PubKey (Ed25519)  |&lt;br&gt;
  |  • Capabilities (Bitmask)   |                                 |  • Capabilities (Bitmask)   |&lt;br&gt;
  |  • Status: Active           |                                 |  • Status: Active           |&lt;br&gt;
  +--------------+--------------+                                 +--------------+--------------+&lt;br&gt;
                 |                                                               |&lt;br&gt;
                 +-------------------------------+-------------------------------+&lt;br&gt;
                                                 | Aggregates &amp;amp; Signs&lt;br&gt;
                                                 v&lt;br&gt;
                                  +------------------------------+&lt;br&gt;
                                  |   Signed Device Directory    |&lt;br&gt;
                                  |   Generation N (Monotonic)   |&lt;br&gt;
                                  +--------------+---------------+&lt;br&gt;
                                                 |&lt;br&gt;
                  +------------------------------+------------------------------+&lt;br&gt;
                  |                              |                              |&lt;br&gt;
                  v                              v                              v&lt;br&gt;
        +-------------------+          +-------------------+          +-------------------+&lt;br&gt;
        |  E2EE Fan-Out     |          | Rollback &amp;amp; Fork   |          | Transport Routing |&lt;br&gt;
        | (MLS / Ratchet)   |          | Defense (Store)   |          | (Endpoints Mux)   |&lt;br&gt;
        +-------------------+          +-------------------+          +-------------------+&lt;br&gt;
Table of Contents&lt;br&gt;
Introduction: The Single-Key Fallacy in Decentralized Systems&lt;br&gt;
The Five-Tier Identity Model: Architectural Separation of Concerns&lt;br&gt;
Root Authority vs. Ephemeral Devices: The Signing Discipline&lt;br&gt;
Signed Snapshots, Monotonic Generations, and Rollback Protection&lt;br&gt;
Equivocation and Fork Detection: Solving the Split-Brain State Problem&lt;br&gt;
Zero-Knowledge Out-of-Band Pairing: QR, NFC, and SAS Handshakes&lt;br&gt;
Instant Revocation, Key Rotation, and Tombstone Propagation&lt;br&gt;
Disaster Recovery and Quorum-Gated Device Re-Anchoring&lt;br&gt;
Cryptographic Least Authority: Bitset Capabilities and Role Specialization&lt;br&gt;
Multi-Device Messaging Fan-Out and Transport Decoupling&lt;br&gt;
Cross-Subsystem Integration: Grounding Spec 02 in the Real World&lt;br&gt;
11.1 Session Multiplexing &amp;amp; Capability Negotiation (Spec 01)&lt;br&gt;
11.2 Transport Neutrality &amp;amp; Multipath Routing (Specs 03 &amp;amp; 12)&lt;br&gt;
11.3 Asynchronous Bundle Gossip via DTN (Specs 04 &amp;amp; 06)&lt;br&gt;
11.4 End-to-End Encryption: MLS Tree &amp;amp; Pairwise Double Ratchet (Spec 28)&lt;br&gt;
11.5 Realtime Media &amp;amp; Multi-Device Call Ring Arbitration (Spec 29)&lt;br&gt;
Defensive Engineering in Rust: Auditing the 21-Item Definition of Done&lt;br&gt;
Ten Axioms for Distributed Multi-Device Identity Systems&lt;br&gt;
Conclusion &amp;amp; Next Steps in the Series&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction: The Single-Key Fallacy in Decentralized Systems
In the earliest days of public-key cryptography and decentralized networks, software architects succumbed to a seductive mathematical simplification:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;$$\text{One Human} = \text{One Cryptographic Keypair}$$&lt;/p&gt;

&lt;p&gt;If Alice wants to communicate on a decentralized network, she generates a public-private keypair on her personal computer. Her public key becomes her global username, and her private key signs her outbound messages and decrypts inbound traffic. In academic papers and proof-of-concept demos, this abstraction feels pure, elegant, and uncompromisingly sovereign.&lt;/p&gt;

&lt;p&gt;In production, it is a catastrophic architectural failure mode.&lt;/p&gt;

&lt;p&gt;Consider what happens when Alice lives in the real world:&lt;/p&gt;

&lt;p&gt;The Multi-Hardware Reality: Alice does not own a single computer. She operates a primary smartphone, a work laptop, a home desktop, a tablet, and perhaps a solar-powered Raspberry Pi headless relay on her roof. She expects to send and receive messages seamlessly across all of them without disjoint histories.&lt;br&gt;
The Private Key Export Catastrophe: If an account is defined as a single private key, linking Alice’s laptop to her phone requires copying her private key across physical devices. Whether transmitted via local Wi-Fi, encoded in a 2D barcode, or manually typed via 24-word mnemonic seed phrases, exporting long-lived private keys turns physical boundaries into zero-day attack surfaces. If Alice’s secondary tablet is compromised, her entire digital existence is permanently forfeited.&lt;br&gt;
The Impossibility of Granular Revocation: When Alice’s laptop is stolen at an airport, what recourse does she have under the single-key model? None. She cannot revoke the laptop without revoking herself. Her only choice is to abandon her public identity, forge a brand-new identity key, and manually beg every contact across the world to trust her new key.&lt;br&gt;
The Centralized Trap: Because decentralized architectures historically struggled with multi-device key coordination, the industry retreated to centralized gatekeepers. Modern end-to-end encrypted messengers (such as Signal, WhatsApp, and iMessage) solve multi-device synchronization by anchoring device directories, prekey bundles, and fan-out queues to central cloud servers. If those servers disappear, are blocked by state censors, or are severed by physical infrastructure blackouts, multi-device communication collapses.&lt;br&gt;
When we designed SIAR (Survivable Identity &amp;amp; Autonomous Routing)—an offline-first, delay-tolerant mesh communication platform engineered to operate through natural catastrophes, physical infrastructure destruction, and adversarial network partitioning—we established an unbending axiom:&lt;/p&gt;

&lt;p&gt;An account identity is a durable sovereign principal, not a physical device, not an ephemeral session, and never a single exposed private key.&lt;/p&gt;

&lt;p&gt;This design is formalized in Spec 02: Multi-Device Identity Architecture, implemented within the zero-unsafe, production-hardened siar-identity-multidevice Rust crate. In this deep dive, we explore how Spec 02 separates identity across five orthogonal tiers, enforces mathematical rollback resistance and fork detection without central databases, conducts zero-knowledge out-of-band pairing, executes immediate local revocation, and coordinates seamless multi-device routing and messaging across hostile, partitioned meshes.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The Five-Tier Identity Model: Architectural Separation of Concerns
A fatal mistake in many decentralized systems is the semantic collapse of identity layers. When an IP address is treated as a peer ID, moving from Wi-Fi to cellular drops the cryptographic session. When an ephemeral Double Ratchet session key is treated as an account ID, clearing local application cache deletes the user’s social graph.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spec 02 rigorously separates identity into five non-overlapping layers:&lt;/p&gt;

&lt;p&gt;+-------------------------------------------------------------------------+&lt;br&gt;
| Layer 1: Account Identity                                               |&lt;br&gt;
| • Durable sovereign principal: AccountId = H(RootPublicKey)             |&lt;br&gt;
| • Signs certificates and state directories; never signs chat packets.   |&lt;br&gt;
+------------------------------------+------------------------------------+&lt;br&gt;
                                     |&lt;br&gt;
+------------------------------------v------------------------------------+&lt;br&gt;
| Layer 2: Device Identity                                                |&lt;br&gt;
| • Per-hardware physical identity: DeviceId = H(DevicePublicKey)         |&lt;br&gt;
| • Holds certified authority; bound to generation numbers.               |&lt;br&gt;
+------------------------------------+------------------------------------+&lt;br&gt;
                                     |&lt;br&gt;
+------------------------------------v------------------------------------+&lt;br&gt;
| Layer 3: Transport Identity                                             |&lt;br&gt;
| • Dynamic bearer addresses: Iroh NodeId, BLE MAC, Wi-Fi Direct P2P IE   |&lt;br&gt;
| • Ephemeral, routable, privacy-preserving, rotatable without key resets |&lt;br&gt;
+------------------------------------+------------------------------------+&lt;br&gt;
                                     |&lt;br&gt;
+------------------------------------v------------------------------------+&lt;br&gt;
| Layer 4: Session Identity                                               |&lt;br&gt;
| • Pairwise cryptographic state: X25519 Diffie-Hellman, Double Ratchet   |&lt;br&gt;
| • Forward secrecy &amp;amp; post-compromise security; ephemeral per peer device |&lt;br&gt;
+------------------------------------+------------------------------------+&lt;br&gt;
                                     |&lt;br&gt;
+------------------------------------v------------------------------------+&lt;br&gt;
| Layer 5: Application Profile                                            |&lt;br&gt;
| • Human metadata: Display name, avatar hashes, isolated namespaces     |&lt;br&gt;
| • Stored in encrypted application storage; zero wire-routing authority  |&lt;br&gt;
+-------------------------------------------------------------------------+&lt;br&gt;
2.1 Account Identity (Layer 1)&lt;br&gt;
The Account Identity is the durable, sovereign principal representing the human, enterprise, or service. It is cryptographically anchored in an Ed25519 Root Identity Key (RootIdentityKey). The public key (RootPublicKey) or its cryptographic hash forms the global AccountId.&lt;/p&gt;

&lt;p&gt;Crucially, the private key of the RootIdentityKey never touches the network wire and never encrypts application messages. It is kept offline, stored in hardware-backed secure enclaves (e.g., Android StrongBox, Apple Secure Enclave, or hardware security modules), or split across disaster-recovery shares. It awakens only for high-consequence administrative events: issuing a device certificate, signing a directory snapshot, or authorizing a root rotation.&lt;/p&gt;

&lt;p&gt;2.2 Device Identity (Layer 2)&lt;br&gt;
Every physical device running SIAR generates its own dedicated, sovereign Ed25519 keypair (device_public_key, device_private_key). A device is assigned a unique DeviceId. A device key never leaves the hardware boundary of that specific physical machine.&lt;/p&gt;

&lt;p&gt;A device is admitted into an account solely through a cryptographic Device Certificate (DeviceCertificate) signed by the account’s root key. The certificate binds the AccountId, DeviceId, device_public_key, authorized capability bitmask, and monotonic generation number.&lt;/p&gt;

&lt;p&gt;2.3 Transport Identity (Layer 3)&lt;br&gt;
Nodes communicate across physical bearers: QUIC over UDP, Bluetooth Low Energy (BLE), Wi-Fi Direct, Wi-Fi Aware (NAN), and DTN physical relays. The addresses used by these bearers—such as an Iroh NodeId, a rotating BLE MAC address, or an IPv6 link-local socket—are classified as Transport Identities.&lt;/p&gt;

&lt;p&gt;Transport identities are ephemeral, routable, and frequently rotated to thwart physical radio surveillance and location tracking. Under Spec 02, transport identities are completely decoupled from device and account keys. An observer sniffing BLE advertisements cannot deduce which AccountId or DeviceId is broadcasting.&lt;/p&gt;

&lt;p&gt;2.4 Session Identity (Layer 4)&lt;br&gt;
When Device A on Phone 1 opens an encrypted conversation with Device B on Laptop 2, they do not encrypt data directly under their long-lived device keys. Doing so would destroy Forward Secrecy (FS) and Post-Compromise Security (PCS).&lt;/p&gt;

&lt;p&gt;Instead, they execute a pairwise handshake (e.g., SIAR’s Noise-based handshake or Double Ratchet) to establish an ephemeral Session Identity. If a session key is compromised by side-channel extraction, previous and future communications remain mathematically impervious to decryption.&lt;/p&gt;

&lt;p&gt;2.5 Application Profile (Layer 5)&lt;br&gt;
Avatars, display names, bios, and application-specific settings belong exclusively to the Application Profile layer. They have zero authority over cryptographic handshakes, wire framing, or packet routing.&lt;/p&gt;

&lt;p&gt;If Alice updates her nickname from “Alice” to “Alice (Field Medic)”, this profile update is propagated as an application-level delta. It requires no certificate re-issuance, no directory generation advance, and no cryptographic re-keying across the mesh.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Root Authority vs. Ephemeral Devices: The Signing Discipline
The core vulnerability of distributed public-key infrastructure is key over-utilization. When a single private key is used for authentication, packet signing, stream encryption, and administrative authorization, the likelihood of side-channel leakage, timing attacks, and accidental exposure increases exponentially.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spec 02 enforces a strict Signing Discipline implemented in crates/siar-identity-multidevice/src/root_key.rs:&lt;/p&gt;

&lt;p&gt;use ed25519_dalek::{Signature, Signer, SigningKey, Verifier, VerifyingKey};&lt;br&gt;
use rand_core::OsRng;&lt;br&gt;
use serde::{Deserialize, Serialize};&lt;br&gt;
use zeroize::Zeroize;&lt;/p&gt;

&lt;p&gt;use crate::error::IdentityError;&lt;/p&gt;

&lt;p&gt;/// §5 "Account Identity", §6 "Root Key Strategy": The account's durable&lt;br&gt;
/// logical principal is anchored by a root signing key that is used&lt;br&gt;
/// rarely — only to sign DeviceCertificates and DeviceDirectory snapshots,&lt;br&gt;
/// never for every message or session.&lt;br&gt;
pub struct RootIdentityKey {&lt;br&gt;
    signing_key: SigningKey,&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;impl RootIdentityKey {&lt;br&gt;
    pub fn generate() -&amp;gt; Self {&lt;br&gt;
        Self {&lt;br&gt;
            signing_key: SigningKey::generate(&amp;amp;mut OsRng),&lt;br&gt;
        }&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub fn root_public_key(&amp;amp;self) -&amp;gt; RootPublicKey {
    RootPublicKey(self.signing_key.verifying_key().to_bytes())
}

pub fn sign(&amp;amp;self, message: &amp;amp;[u8]) -&amp;gt; [u8; 64] {
    self.signing_key.sign(message).to_bytes()
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;impl Drop for RootIdentityKey {&lt;br&gt;
    fn drop(&amp;amp;mut self) {&lt;br&gt;
        // Zeroize memory buffers deterministically on drop.&lt;br&gt;
        let mut marker = [0u8; 0];&lt;br&gt;
        marker.zeroize();&lt;br&gt;
    }&lt;br&gt;
}&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
&lt;/h1&gt;

&lt;p&gt;pub struct RootPublicKey(pub [u8; 32]);&lt;/p&gt;

&lt;p&gt;impl RootPublicKey {&lt;br&gt;
    pub fn verify(&amp;amp;self, message: &amp;amp;[u8], signature: &amp;amp;[u8; 64]) -&amp;gt; Result&amp;lt;(), IdentityError&amp;gt; {&lt;br&gt;
        let verifying_key =&lt;br&gt;
            VerifyingKey::from_bytes(&amp;amp;self.0).map_err(|&lt;em&gt;| IdentityError::MalformedKey)?;&lt;br&gt;
        let signature = Signature::from_bytes(signature);&lt;br&gt;
        verifying_key&lt;br&gt;
            .verify(message, &amp;amp;signature)&lt;br&gt;
            .map_err(|&lt;/em&gt;| IdentityError::InvalidSignature)&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
The Mathematical Delegation Invariant&lt;br&gt;
A device proves its authority to act on behalf of an account by presenting a valid DeviceCertificate. The signature on this certificate satisfies the predicate:&lt;/p&gt;

&lt;p&gt;$$\text{Verify}(\text{RootPublicKey}, , \mathcal{M}{\text{cert}}, , \sigma{\text{cert}}) = \text{true}$$&lt;/p&gt;

&lt;p&gt;Where the signing payload $\mathcal{M}_{\text{cert}}$ is deterministically serialized using canonical Postcard encoding:&lt;/p&gt;

&lt;p&gt;$$\mathcal{M}_{\text{cert}} = \text{PostcardEncode}(\langle\text{AccountId}, \text{DeviceId}, \text{DevicePublicKey}, \text{IssuedAt}, \text{ExpiresAt}, \text{Capabilities}, \text{Generation}\rangle)$$&lt;/p&gt;

&lt;p&gt;In crates/siar-identity-multidevice/src/certificate.rs:&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Serialize, Deserialize)]
&lt;/h1&gt;

&lt;p&gt;pub struct DeviceCertificate {&lt;br&gt;
    pub account_id: AccountId,&lt;br&gt;
    pub device_id: DeviceId,&lt;br&gt;
    pub device_public_key: [u8; 32],&lt;br&gt;
    pub issued_at_millis: u64,&lt;br&gt;
    pub expires_at_millis: Option,&lt;br&gt;
    pub capabilities: DeviceCapabilitySet,&lt;br&gt;
    pub generation: u64,&lt;br&gt;
    pub signature: Vec,&lt;br&gt;
}&lt;br&gt;
Notice the design choices:&lt;/p&gt;

&lt;p&gt;Zero Raw Byte Concatenation: Hand-written byte concatenation (account_id + device_id + ...) is notoriously susceptible to length-extension attacks and canonical parsing bugs. By serializing a fixed-shape struct through Postcard, the serialized bytes are uniquely invertible and mathematically unambiguous.&lt;br&gt;
Separation of Validity and Current Trust: A cryptographically valid signature on a DeviceCertificate proves exactly one thing: the device was authorized by the root key at generation $G$. It does not prove that the device is currently trusted. Current trust is governed dynamically by the account’s latest signed directory snapshot.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Signed Snapshots, Monotonic Generations, and Rollback Protection
How does a decentralized, partitioned mesh agree on which devices currently belong to an account without running a multi-gigabyte blockchain or relying on a centralized database?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spec 02 solves this through Signed State Snapshots governed by Monotonic Generation Counters.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                           Device Directory Snapshot
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;+-------------------------------------------------------------------------+&lt;br&gt;
| AccountId: 0x9f4a...                                                    |&lt;br&gt;
| Generation: 7                                                           |&lt;br&gt;
+-------------------------------------------------------------------------+&lt;br&gt;
| Devices:                                                                |&lt;br&gt;
|  [0] DeviceId: Phone-Alpha  | Status: Active  | Endpoints: [BLE, QUIC]  |&lt;br&gt;
|  [1] DeviceId: Laptop-Beta  | Status: Active  | Endpoints: [QUIC]       |&lt;br&gt;
|  [2] DeviceId: Tablet-Old   | Status: Revoked | Endpoints: []           |&lt;br&gt;
+-------------------------------------------------------------------------+&lt;br&gt;
| Signature: Ed25519_Sign(RootPrivateKey, Postcard(AccountId, 7, Devices))|&lt;br&gt;
+-------------------------------------------------------------------------+&lt;br&gt;
4.1 The Directory Snapshot Structure&lt;br&gt;
Rather than forcing resource-constrained mobile phones and 4MB embedded repeaters to store, traverse, and replay an unbounded append-only event log of every device addition and removal across five years, the root authority periodically emits a compact DeviceDirectory.&lt;/p&gt;

&lt;p&gt;In crates/siar-identity-multidevice/src/directory.rs:&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
&lt;/h1&gt;

&lt;p&gt;pub enum DeviceStatus {&lt;br&gt;
    Active,&lt;br&gt;
    Revoked,&lt;br&gt;
    Expired,&lt;br&gt;
}&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
&lt;/h1&gt;

&lt;p&gt;pub struct DeviceEndpoint(pub Vec);&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Serialize, Deserialize)]
&lt;/h1&gt;

&lt;p&gt;pub struct DeviceDirectoryEntry {&lt;br&gt;
    pub device_id: DeviceId,&lt;br&gt;
    pub certificate: DeviceCertificate,&lt;br&gt;
    pub status: DeviceStatus,&lt;br&gt;
    pub transport_endpoints: Vec,&lt;br&gt;
}&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Serialize, Deserialize)]
&lt;/h1&gt;

&lt;p&gt;pub struct DeviceDirectory {&lt;br&gt;
    pub account_id: AccountId,&lt;br&gt;
    pub generation: u64,&lt;br&gt;
    pub devices: Vec,&lt;br&gt;
    pub signature: Vec,&lt;br&gt;
}&lt;br&gt;
Every directory update—whether adding a tablet, rotating a key, or revoking a stolen phone—advances the generation counter by exactly one:&lt;/p&gt;

&lt;p&gt;$$\text{Generation}_{t+1} = \text{Generation}_t + 1$$&lt;/p&gt;

&lt;p&gt;The root key signs the entire payload. The resulting signed directory is compact (typically under 1 kilobyte for an account with 3–5 devices) and can be transmitted over high-latency BLE or carried in DTN storage bundles across air-gapped zones.&lt;/p&gt;

&lt;p&gt;4.2 The Mechanics of Rollback Defense&lt;br&gt;
In an offline mesh network, an attacker who steals Device B (a revoked laptop) will attempt a Rollback Attack:&lt;/p&gt;

&lt;p&gt;The attacker captures an old, pre-revocation directory snapshot (Generation 3) where Device B was marked Active.&lt;br&gt;
The attacker broadcasts Generation 3 to neighboring nodes over Wi-Fi or BLE, claiming that Device B is still legitimate.&lt;br&gt;
Because Generation 3 carries a valid cryptographic signature from the account’s root key, a naive client would accept it and resume encrypting sensitive traffic to the compromised laptop.&lt;br&gt;
Spec 02 completely neutralizes this attack via the TrustedAccountStore state machine (crates/siar-identity-multidevice/src/trust_store.rs):&lt;/p&gt;

&lt;p&gt;pub struct TrustedAccountStore {&lt;br&gt;
    trusted: HashMap,&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;impl TrustedAccountStore {&lt;br&gt;
    pub fn accept(&lt;br&gt;
        &amp;amp;mut self,&lt;br&gt;
        directory: DeviceDirectory,&lt;br&gt;
        root_public_key: &amp;amp;RootPublicKey,&lt;br&gt;
    ) -&amp;gt; Result&amp;lt;(), IdentityError&amp;gt; {&lt;br&gt;
        // 1. Verify root cryptographic signature&lt;br&gt;
        directory&lt;br&gt;
            .verify_signature(root_public_key)&lt;br&gt;
            .map_err(|_| IdentityError::DirectorySignatureInvalid)?;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    // 2. Enforce monotonic generation progression
    if let Some(existing) = self.trusted.get(&amp;amp;directory.account_id) {
        if directory.generation &amp;lt; existing.generation {
            return Err(IdentityError::RollbackRejected {
                given: directory.generation,
                highest: existing.generation,
            });
        }
        if directory.generation == existing.generation {
            if directory.signature == existing.signature {
                return Ok(()); // Benign, identical retransmission
            }
            // Conflicting state at the same generation: A FORK!
            return Err(IdentityError::IdentityForkDetected {
                generation: directory.generation,
            });
        }
    }

    self.trusted.insert(directory.account_id, directory);
    Ok(())
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
The mathematical rule enforced by TrustedAccountStore is absolute:&lt;/p&gt;

&lt;p&gt;$$\text{Accept}(D_{\text{in}}) \iff \text{ValidSig}(D_{\text{in}}) \land \Big(\text{Gen}(D_{\text{in}}) &amp;gt; \text{Gen}(D_{\text{current}})\Big)$$&lt;/p&gt;

&lt;p&gt;Once a peer learns of Generation 7, no packet, certificate, or directory from Generation 6 or below can ever be trusted again. The state ratchet moves strictly forward.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Equivocation and Fork Detection: Solving the Split-Brain State Problem
What happens if an adversary compromises a root key or an administrator acts maliciously, issuing two different directories with the same generation number?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;$$\begin{aligned} D_A &amp;amp;= \langle \text{Gen: 5}, , \text{Devices: } { \text{Phone, Laptop} } \rangle \ D_B &amp;amp;= \langle \text{Gen: 5}, , \text{Devices: } { \text{Phone, RogueTablet} } \rangle \end{aligned}$$&lt;/p&gt;

&lt;p&gt;This is the classic Equivocation Attack (or Identity Fork). In early prototypes of distributed systems, this is often handled with a catastrophic shortcut: “If generation is equal, treat it as a no-op.”&lt;/p&gt;

&lt;p&gt;Under that naive shortcut, whichever directory a peer happens to see first wins permanently. Half the mesh believes $D_A$, while the other half believes $D_B$. The network suffers a silent, permanent split-brain partition.&lt;/p&gt;

&lt;p&gt;The Fork Equivocation Theorem&lt;br&gt;
Spec 02 addresses this directly in Section 57. The accept() function evaluates:&lt;/p&gt;

&lt;p&gt;$$\text{ForkPredicate}(D_1, D_2) \iff \Big(\text{Gen}(D_1) = \text{Gen}(D_2)\Big) \land \Big(\text{Sig}(D_1) \neq \text{Sig}(D_2)\Big)$$&lt;/p&gt;

&lt;p&gt;Because Ed25519 signatures are strictly deterministic (RFC 8032), identical directory contents signed by the same key will produce byte-for-byte identical signatures.&lt;/p&gt;

&lt;p&gt;Therefore:&lt;/p&gt;

&lt;p&gt;If $\text{Gen}(D_{\text{in}}) = \text{Gen}(D_{\text{current}})$ and $\text{Sig}(D_{\text{in}}) = \text{Sig}(D_{\text{current}})$, it is a harmless, idempotent retransmission over the mesh.&lt;br&gt;
If $\text{Gen}(D_{\text{in}}) = \text{Gen}(D_{\text{current}})$ and $\text{Sig}(D_{\text{in}}) \neq \text{Sig}(D_{\text{current}})$, an equivocation attack has occurred.&lt;br&gt;
The TrustedAccountStore immediately halts automatic state processing and raises IdentityError::IdentityForkDetected. The client marks the account as compromised, isolates inbound channels, and alerts the user through the Security Center UI. Silent forks are mathematically prohibited.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Zero-Knowledge Out-of-Band Pairing: QR, NFC, and SAS Handshakes
Adding a secondary device (e.g., linking a new Linux laptop to an existing Android smartphone) is the most vulnerable ceremony in the multi-device lifecycle. An attacker on the local Wi-Fi or Bluetooth channel will attempt to inject their own public key, tricking the primary device into certifying an unauthorized spy node.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spec 02 specifies a mutual, out-of-band, zero-knowledge authentication ceremony combining dynamic QR/NFC bootstrapping, ephemeral Diffie-Hellman exchange, and Short Authentication String (SAS) numeric verification.&lt;/p&gt;

&lt;p&gt;sequenceDiagram&lt;br&gt;
    autonumber&lt;br&gt;
    actor Alice as Primary Device (Phone)&lt;br&gt;
    actor Bob as New Device (Laptop)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Alice-&amp;gt;&amp;gt;Alice: Generate Ephemeral Link Keypair (e_alice)
Alice-&amp;gt;&amp;gt;Alice: Generate One-Time Nonce (16 bytes)
Alice-&amp;gt;&amp;gt;Alice: Sign DeviceLinkInvite with RootKey
Alice-&amp;gt;&amp;gt;Bob: Transmit Invite via Dynamic QR / NFC
Note over Alice,Bob: QR contains ZERO private keys or secrets
Bob-&amp;gt;&amp;gt;Bob: Generate Ephemeral Keypair (e_bob)
Bob-&amp;gt;&amp;gt;Alice: Direct BLE / Local LAN Handshake (e_bob)
Alice-&amp;gt;&amp;gt;Alice: Compute DH: SharedSecret = ECDH(e_alice, e_bob)
Bob-&amp;gt;&amp;gt;Bob: Compute DH: SharedSecret = ECDH(e_bob, e_alice)
Alice-&amp;gt;&amp;gt;Alice: Derive SAS Code = Blake3(Transcript)[0..4] % 1,000,000
Bob-&amp;gt;&amp;gt;Bob: Derive SAS Code = Blake3(Transcript)[0..4] % 1,000,000
Note over Alice,Bob: Both Screens Display Identical 6-Digit Code: "842 190"
Alice-&amp;gt;&amp;gt;Alice: User confirms SAS code matches Bob
Bob-&amp;gt;&amp;gt;Bob: User confirms SAS code matches Alice
Alice-&amp;gt;&amp;gt;Alice: Issue Signed DeviceCertificate (Gen N+1)
Alice-&amp;gt;&amp;gt;Bob: Emit New Certificate &amp;amp; Signed Directory
Bob-&amp;gt;&amp;gt;Bob: Persist Certificate in Secure Storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;6.1 The Device Linking Invite&lt;br&gt;
The ceremony begins on the existing trusted device. It generates an ephemeral X25519 keypair and creates a signed DeviceLinkInvite (crates/siar-identity-multidevice/src/invite.rs):&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Serialize, Deserialize)]
&lt;/h1&gt;

&lt;p&gt;pub struct DeviceLinkInvite {&lt;br&gt;
    pub account_id: AccountId,&lt;br&gt;
    pub inviter_device: DeviceId,&lt;br&gt;
    pub ephemeral_link_key: EphemeralLinkPublicKey,&lt;br&gt;
    pub expires_at_millis: u64,&lt;br&gt;
    pub nonce: [u8; 16],&lt;br&gt;
    pub signature: Vec,&lt;br&gt;
}&lt;br&gt;
Notice the critical security guarantees:&lt;/p&gt;

&lt;p&gt;Zero Secret Material in the QR Code: The QR code encodes only public keys, timestamps, nonces, and a signature. If an attacker photographs the QR code over the user’s shoulder, they gain zero private keys, zero session keys, and zero ability to complete the link.&lt;br&gt;
Enforced Single-Use Nonce: The 16-byte nonce is generated internally using cryptographically secure hardware entropy (OsRng). It cannot be reused or replayed.&lt;br&gt;
6.2 Deriving the 6-Digit SAS Code&lt;br&gt;
Both devices perform an X25519 Diffie-Hellman key exchange using their ephemeral link keys to establish a temporary SharedSecret. To ensure no Man-in-the-Middle (MITM) adversary is tampering with the radio packets between the phone and laptop, both devices independently compute a Short Authentication String (SAS).&lt;/p&gt;

&lt;p&gt;In crates/siar-identity-multidevice/src/verification_code.rs:&lt;/p&gt;

&lt;p&gt;fn transcript(&lt;br&gt;
    invite: &amp;amp;DeviceLinkInvite,&lt;br&gt;
    responder_public: &amp;amp;EphemeralLinkPublicKey,&lt;br&gt;
    shared_secret: &amp;amp;[u8; 32],&lt;br&gt;
) -&amp;gt; Vec {&lt;br&gt;
    let mut bytes = Vec::new();&lt;br&gt;
    bytes.extend_from_slice(&lt;br&gt;
        &amp;amp;postcard::to_allocvec(invite)&lt;br&gt;
            .expect("postcard encoding cannot fail"),&lt;br&gt;
    );&lt;br&gt;
    bytes.extend_from_slice(&amp;amp;responder_public.0);&lt;br&gt;
    bytes.extend_from_slice(shared_secret);&lt;br&gt;
    bytes&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;pub fn derive_verification_code(&lt;br&gt;
    invite: &amp;amp;DeviceLinkInvite,&lt;br&gt;
    responder_public: &amp;amp;EphemeralLinkPublicKey,&lt;br&gt;
    shared_secret: &amp;amp;[u8; 32],&lt;br&gt;
) -&amp;gt; String {&lt;br&gt;
    let transcript_bytes = transcript(invite, responder_public, shared_secret);&lt;br&gt;
    let hash = blake3::hash(&amp;amp;transcript_bytes);&lt;br&gt;
    let hash_bytes = hash.as_bytes();&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Deterministically reduce first 4 bytes mod 1,000,000
let value = u32::from_be_bytes([hash_bytes[0], hash_bytes[1], hash_bytes[2], hash_bytes[3]]);
format!("{:06}", value % 1_000_000)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Why bind the transcript to the entire signed invite, both public keys, and the shared secret? Because an attacker who observes all public radio traffic cannot precalculate or manipulate the 6-digit code without solving the Diffie-Hellman discrete logarithm problem. The 6-digit decimal code provides $10^6$ combinations (~20 bits of entropy)—more than sufficient to prevent real-time collision attempts during a 30-second pairing window.&lt;/p&gt;

&lt;p&gt;6.3 Guarding Against Silent Device Additions&lt;br&gt;
A subtle attack against multi-device systems is Silent Device Insertion: malware running on a phone silently accepts a background linking request without the human realizing a new device was attached.&lt;/p&gt;

&lt;p&gt;Spec 02 prevents this in crates/siar-identity-multidevice/src/approval.rs by encoding human confirmation into the type system:&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Copy, PartialEq, Eq)]
&lt;/h1&gt;

&lt;p&gt;pub enum VerificationStatus {&lt;br&gt;
    NumericCodeConfirmed,&lt;br&gt;
    NotVerified,&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;pub struct LinkingApprovalPrompt {&lt;br&gt;
    pub device_platform: String,&lt;br&gt;
    pub approximate_time_millis: u64,&lt;br&gt;
    pub link_method: LinkMethod,&lt;br&gt;
    pub verification_status: VerificationStatus,&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;impl LinkingApprovalPrompt {&lt;br&gt;
    /// The standard constructor requires explicit confirmation of the SAS code.&lt;br&gt;
    pub fn new(&lt;br&gt;
        device_platform: String,&lt;br&gt;
        approximate_time_millis: u64,&lt;br&gt;
        link_method: LinkMethod,&lt;br&gt;
    ) -&amp;gt; Self {&lt;br&gt;
        Self {&lt;br&gt;
            device_platform,&lt;br&gt;
            approximate_time_millis,&lt;br&gt;
            link_method,&lt;br&gt;
            verification_status: VerificationStatus::NumericCodeConfirmed,&lt;br&gt;
        }&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
The Rust API forbids constructing an approval prompt without an explicit confirmation state, ensuring that UI shells cannot bypass user interaction.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Instant Revocation, Key Rotation, and Tombstone Propagation
What happens when a device is lost, stolen, or decommissioned? In centralized networks, you issue an API request to a cloud server, which deletes the device from its database. In an offline-first mesh, there is no server. Revocation must be immediate, local, and asynchronously propagatable.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;7.1 Immediate Local Revocation&lt;br&gt;
When the user taps “Revoke Device” on their primary phone, revocation occurs synchronously without waiting for a network connection.&lt;/p&gt;

&lt;p&gt;In crates/siar-identity-multidevice/src/revocation.rs:&lt;/p&gt;

&lt;p&gt;pub fn revoke_device(&lt;br&gt;
    root_key: &amp;amp;RootIdentityKey,&lt;br&gt;
    current: &amp;amp;DeviceDirectory,&lt;br&gt;
    device_to_revoke: DeviceId,&lt;br&gt;
) -&amp;gt; Result {&lt;br&gt;
    let entry = current&lt;br&gt;
        .devices&lt;br&gt;
        .iter()&lt;br&gt;
        .find(|d| d.device_id == device_to_revoke)&lt;br&gt;
        .ok_or(RevocationError::DeviceNotFound(device_to_revoke))?;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if entry.status == DeviceStatus::Revoked {
    return Err(RevocationError::AlreadyRevoked(device_to_revoke));
}

let mut new_devices = current.devices.clone();
for d in &amp;amp;mut new_devices {
    if d.device_id == device_to_revoke {
        d.status = DeviceStatus::Revoked;
    }
}

// Generation advances strictly by one
let new_generation = current.generation + 1;
let new_directory = DeviceDirectory::sign(
    root_key,
    current.account_id,
    new_generation,
    new_devices,
);

Ok(new_directory)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
The revocation function produces a new DeviceDirectory where:&lt;/p&gt;

&lt;p&gt;The target device is marked DeviceStatus::Revoked.&lt;br&gt;
The generation is incremented to $G+1$.&lt;br&gt;
The directory is signed by the RootIdentityKey.&lt;br&gt;
Locally, the effect is instantaneous:&lt;/p&gt;

&lt;p&gt;The revoked device is immediately purged from outbound messaging fan-out lists.&lt;br&gt;
Existing peer sessions with that device are torn down.&lt;br&gt;
Incoming packets signed by the revoked device key are rejected at the transport boundary.&lt;br&gt;
7.2 Tombstone Propagation Across the Mesh&lt;br&gt;
To inform the rest of the world that the device has been evicted, the new directory snapshot is gossiped across the network. Because the snapshot carries generation $G+1$, any peer that encounters it—whether via direct Wi-Fi links, BLE advertisements, or DTN physical storage couriers—will invoke TrustedAccountStore::accept().&lt;/p&gt;

&lt;p&gt;The store validates the root signature, observes that $G+1 &amp;gt; G$, ratchets its highest known generation forward, and permanently blacklists the revoked device. The revocation is irrevocable. Even if the stolen device physically rejoins the mesh months later, its pre-revocation certificates are rejected by every node that has seen Generation $G+1$.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Disaster Recovery and Quorum-Gated Device Re-Anchoring
A sovereign identity system must survive worst-case physical scenarios:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Alice was hiking during a catastrophic flood. Her primary phone was swept away in the river. Her laptop at home is powered off. How does she recover her account on a new phone without relying on a central helpdesk or SMS verification?&lt;/p&gt;

&lt;p&gt;Spec 02 defines four explicit Recovery Policies in crates/siar-identity-multidevice/src/recovery.rs:&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, PartialEq, Eq)]
&lt;/h1&gt;

&lt;p&gt;pub enum RecoveryPolicy {&lt;br&gt;
    /// High-entropy secret passphrase stretched via Argon2id&lt;br&gt;
    RecoverySecret,&lt;br&gt;
    /// M-of-N threshold quorum of already-linked trusted devices&lt;br&gt;
    TrustedDeviceQuorum { threshold: u8, total: u8 },&lt;br&gt;
    /// Enterprise / organizational PKI recovery key&lt;br&gt;
    EnterpriseRecoveryKey,&lt;br&gt;
    /// Pre-generated offline paper key recovery bundles&lt;br&gt;
    OfflinePreGeneratedKeys,&lt;br&gt;
}&lt;br&gt;
8.1 Device Quorum Recovery ($M$-of-$N$)&lt;br&gt;
Under the TrustedDeviceQuorum policy, Alice does not need her lost root key to provision a replacement device. Instead, her existing linked devices form an on-device threshold quorum:&lt;/p&gt;

&lt;p&gt;$$\sum_{i=1}^N \text{ValidSignature}(D_i) \ge M \quad \text{where } D_i \in \text{ActiveDevices}(D_{\text{current}})$$&lt;/p&gt;

&lt;p&gt;pub fn add_device_via_quorum(&lt;br&gt;
    current: &amp;amp;DeviceDirectory,&lt;br&gt;
    new_device_id: DeviceId,&lt;br&gt;
    new_device_pubkey: [u8; 32],&lt;br&gt;
    approving_signatures: &amp;amp;[(DeviceId, Vec)],&lt;br&gt;
    threshold: usize,&lt;br&gt;
) -&amp;gt; Result {&lt;br&gt;
    let mut valid_approvals = 0;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (approver_id, sig) in approving_signatures {
    // Enforce that revoked devices NEVER count toward quorum
    if let Some(entry) = current.devices.iter().find(|d| d.device_id == *approver_id) {
        if entry.status == DeviceStatus::Active {
            if verify_device_signature(entry, sig) {
                valid_approvals += 1;
            }
        }
    }
}

if valid_approvals &amp;lt; threshold {
    return Err(IdentityError::QuorumNotReached {
        required: threshold,
        actual: valid_approvals,
    });
}

// Quorum satisfied: generate new certificate and advance generation
Ok(provision_recovered_device(current, new_device_id, new_device_pubkey))
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Notice the critical invariant: Revoked devices do not count toward quorum. If an attacker steals two devices out of a 3-of-5 quorum, and Alice revokes them using her remaining hardware, those stolen devices cannot conspire to reconstitute authority.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Cryptographic Least Authority: Bitset Capabilities and Role Specialization
In many distributed systems, any certified device has full, unrestricted access to perform all operations: sending messages, initiating calls, linking other devices, and issuing revocations.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In a heterogeneous mesh, this is dangerous. A solar-powered field repeater mounted on a utility pole needs to relay encrypted packets and forward DTN bundles. It must never have the authority to link new devices to your account, read your private chat history, or revoke your primary smartphone.&lt;/p&gt;

&lt;p&gt;Spec 02 enforces the Principle of Least Authority using a compact 64-bit capability bitset (crates/siar-identity-multidevice/src/capability.rs):&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
&lt;/h1&gt;

&lt;p&gt;pub struct DeviceCapabilitySet(pub u64);&lt;/p&gt;

&lt;p&gt;impl DeviceCapabilitySet {&lt;br&gt;
    pub const SEND_MESSAGES: u64        = 1 &amp;lt;&amp;lt; 0;&lt;br&gt;
    pub const RECEIVE_MESSAGES: u64     = 1 &amp;lt;&amp;lt; 1;&lt;br&gt;
    pub const INITIATE_CALLS: u64       = 1 &amp;lt;&amp;lt; 2;&lt;br&gt;
    pub const LINK_NEW_DEVICE: u64      = 1 &amp;lt;&amp;lt; 3;&lt;br&gt;
    pub const REVOKE_DEVICE: u64        = 1 &amp;lt;&amp;lt; 4;&lt;br&gt;
    pub const ROTATE_ACCOUNT_STATE: u64 = 1 &amp;lt;&amp;lt; 5;&lt;br&gt;
    pub const SYNC_HISTORY: u64         = 1 &amp;lt;&amp;lt; 6;&lt;br&gt;
    pub const RELAY: u64                = 1 &amp;lt;&amp;lt; 7;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pub fn has(&amp;amp;self, capability: u64) -&amp;gt; bool {
    (self.0 &amp;amp; capability) == capability
}

pub fn grant(&amp;amp;mut self, capability: u64) {
    self.0 |= capability;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Headless Relay Specialization&lt;br&gt;
When a user provisions a headless mesh relay node (HeadlessRelay), the device certificate is issued with minimal capabilities:&lt;/p&gt;

&lt;p&gt;pub fn headless_relay_minimum_capabilities() -&amp;gt; DeviceCapabilitySet {&lt;br&gt;
    let mut caps = DeviceCapabilitySet(0);&lt;br&gt;
    caps.grant(DeviceCapabilitySet::RELAY);&lt;br&gt;
    caps&lt;br&gt;
}&lt;br&gt;
The solar repeater receives the RELAY bit and nothing else. It cannot sign new device invites, cannot participate in recovery quorums, and holds zero decryption keys for private messaging payloads. If an adversary physically climbs the utility pole and extracts the flash storage of the repeater, your personal identity and historical communications remain completely uncompromised.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Multi-Device Messaging Fan-Out and Transport Decoupling
When Bob sends a message to Alice, how does the message reach Alice’s phone, laptop, and tablet across disparate network links without leaking private metadata or creating redundant loops?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spec 02 defines the Messaging Fan-Out Rule in crates/siar-identity-multidevice/src/fanout.rs:&lt;/p&gt;

&lt;p&gt;pub fn fan_out_targets(&lt;br&gt;
    sender_directory: &amp;amp;DeviceDirectory,&lt;br&gt;
    sender_originating_device: DeviceId,&lt;br&gt;
    recipient_directory: &amp;amp;DeviceDirectory,&lt;br&gt;
) -&amp;gt; Vec {&lt;br&gt;
    let mut targets: Vec = recipient_directory&lt;br&gt;
        .active_devices()&lt;br&gt;
        .map(|entry| entry.device_id)&lt;br&gt;
        .collect();&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Include sender's OTHER active devices (self-sync)
targets.extend(
    sender_directory
        .active_devices()
        .map(|entry| entry.device_id)
        .filter(|&amp;amp;id| id != sender_originating_device),
);

targets
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
The fan-out set $\mathcal{T}_{\text{fanout}}$ is mathematically defined as:&lt;/p&gt;

&lt;p&gt;$$\mathcal{T}{\text{fanout}} = \Big( \text{ActiveDevices}(\text{Recipient}) \Big) \cup \Big( \text{ActiveDevices}(\text{Sender}) \setminus { d{\text{origin}} } \Big)$$&lt;/p&gt;

&lt;p&gt;This guarantees two crucial properties:&lt;/p&gt;

&lt;p&gt;Full Recipient Delivery: All currently active devices belonging to the recipient receive the payload.&lt;br&gt;
Cross-Device Self-Synchronization: The sender’s other devices (e.g., Alice’s laptop when she sends a message from her phone) receive a copy of the outbound event, ensuring her sent chat history remains identical across all her screens without looping back to the originating device.&lt;br&gt;
10.1 Sender Attribution vs. Account Presentation&lt;br&gt;
Every transmitted frame carries an explicit SenderIdentity:&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
&lt;/h1&gt;

&lt;p&gt;pub struct SenderIdentity {&lt;br&gt;
    pub account_id: AccountId,&lt;br&gt;
    pub device_id: DeviceId,&lt;br&gt;
}&lt;br&gt;
The core protocol preserves the exact DeviceId that authored the packet to allow accurate cryptographic verification, replay defense, and device-level delivery receipts.&lt;/p&gt;

&lt;p&gt;However, in the user interface, showing device identifiers on every chat bubble clutters the screen and confuses users. Spec 02 establishes the account_level_display boundary:&lt;/p&gt;

&lt;p&gt;pub fn account_level_display(&lt;br&gt;
    sender: SenderIdentity,&lt;br&gt;
    context: PresentationContext,&lt;br&gt;
) -&amp;gt; (AccountId, Option) {&lt;br&gt;
    match context {&lt;br&gt;
        PresentationContext::Normal =&amp;gt; (sender.account_id, None),&lt;br&gt;
        PresentationContext::SecurityDetails&lt;br&gt;
        | PresentationContext::Diagnostics&lt;br&gt;
        | PresentationContext::EnterpriseAudit =&amp;gt; (sender.account_id, Some(sender.device_id)),&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
In ordinary conversation views (PresentationContext::Normal), the UI renders only the cohesive AccountId. But when inspecting message security properties or conducting enterprise audits, the underlying DeviceId is surfaced with full cryptographic provenance.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Cross-Subsystem Integration: Grounding Spec 02 in the Real World&lt;br&gt;
Identity does not live in an ivory tower. In the SIAR architecture, siar-identity-multidevice serves as the foundational trust substrate across multiple core subsystems.&lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                          +------------------------------------+
                          | Spec 02: Multi-Device Identity     |
                          | (siar-identity-multidevice)        |
                          +-----------------+------------------+
                                            |
 +--------------------+---------------------+--------------------+--------------------+
 |                    |                     |                    |                    |
 v                    v                     v                    v                    v
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;+-----------------+  +-----------------+  +-----------------+  +-----------------+  +-----------------+&lt;br&gt;
| Spec 01: Core   |  | Specs 03 &amp;amp; 12:  |  | Specs 04 &amp;amp; 06:  |  | Spec 28: E2EE   |  | Spec 29: Real-  |&lt;br&gt;
| Extensions &amp;amp;    |  | Multipath &amp;amp;     |  | DTN Store-Carry |  | MLS Ratchets &amp;amp;  |  | time Media &amp;amp;    |&lt;br&gt;
| Capabilities    |  | Routing Policy  |  | Forward Gossip  |  | Prekey Bundles  |  | Ring Arbitration|&lt;br&gt;
+-----------------+  +-----------------+  +-----------------+  +-----------------+  +-----------------+&lt;br&gt;
11.1 Session Multiplexing &amp;amp; Capability Negotiation (Spec 01)&lt;br&gt;
In Part 1 of this series, we covered how Spec 01 negotiates protocol extensions (e.g., org.siar.comm/messaging/1) using session-local translation.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spec 02 directly integrates with Spec 01 during the initial session handshake:&lt;/p&gt;

&lt;p&gt;When Peer A connects to Peer B, Peer A presents its DeviceCertificate.&lt;br&gt;
Peer B verifies that the certificate is signed by an accepted RootPublicKey and checks that the device is marked Active in its TrustedAccountStore.&lt;br&gt;
Spec 01 intersects the peer’s advertised protocol extensions with the device’s authorized DeviceCapabilitySet. If a device lacks the INITIATE_CALLS bit, the session multiplexer refuses to open the realtime voice extension channel, rejecting unauthorized streams before a single byte of media is decoded.&lt;br&gt;
11.2 Transport Neutrality &amp;amp; Multipath Routing (Specs 03 &amp;amp; 12)&lt;br&gt;
Each entry in the DeviceDirectory holds a list of DeviceEndpoint byte arrays:&lt;/p&gt;

&lt;p&gt;pub struct DeviceEndpoint(pub Vec);&lt;br&gt;
Notice that DeviceEndpoint is an opaque byte wrapper. Spec 02 deliberately avoids hardcoding IP addresses, port numbers, or Bluetooth UUIDs into the identity schema.&lt;/p&gt;

&lt;p&gt;The Transport Routing Policy Engine (Specs 03 &amp;amp; 12) unpacks these endpoints:&lt;/p&gt;

&lt;p&gt;A node on a high-speed corporate LAN resolves DeviceEndpoint to a QUIC UDP socket via Iroh.&lt;br&gt;
A field unit in a subterranean bunker resolves DeviceEndpoint to a rotating BLE service UUID or Wi-Fi Direct P2P Group Owner MAC.&lt;br&gt;
Multipath routing seamlessly switches active streams between cellular and Bluetooth without invalidating the underlying DeviceId or breaking the cryptographic session.&lt;br&gt;
11.3 Asynchronous Bundle Gossip via DTN (Specs 04 &amp;amp; 06)&lt;br&gt;
In severed, disaster-stricken areas with zero network connectivity, directory synchronization cannot rely on live TCP/QUIC handshakes.&lt;/p&gt;

&lt;p&gt;Spec 02 directories are serialized into immutable DTN Storage Bundles governed by Specs 04 &amp;amp; 06. A mobile disaster-response vehicle driving between remote mountain clinics physically carries these signed directory bundles on ruggedized flash storage. When the vehicle arrives at a clinic, its local daemon gossips the latest directory snapshots over ad-hoc Wi-Fi. The clinic’s local mesh immediately learns of revocations and newly linked field devices without ever touching the internet.&lt;/p&gt;

&lt;p&gt;11.4 End-to-End Encryption: MLS Tree &amp;amp; Pairwise Double Ratchet (Spec 28)&lt;br&gt;
Spec 02 provides the cryptographic leaf nodes for Spec 28: Production Security &amp;amp; E2EE Key Management:&lt;/p&gt;

&lt;p&gt;Pairwise Messaging: When two devices communicate directly, they instantiate an X25519 Double Ratchet session initialized via signed prekey bundles (PrekeyBundle) published by each active DeviceId.&lt;br&gt;
Group Communication: In multi-user channels, SIAR deploys Messaging Layer Security (MLS, RFC 9420). In the MLS ratchet tree, each leaf node corresponds to a verified DeviceId from Spec 02. When a device is revoked in Spec 02, the MLS group controller automatically issues an MLS Remove proposal, updating the ratchet tree and ratcheting the group encryption key forward to guarantee immediate post-revocation forward secrecy.&lt;br&gt;
11.5 Realtime Media &amp;amp; Multi-Device Call Ring Arbitration (Spec 29)&lt;br&gt;
When an incoming video call arrives for an account with multiple active devices, how do we prevent three devices from screaming simultaneously and answering at the exact same second?&lt;/p&gt;

&lt;p&gt;Spec 02 and Spec 29 coordinate through the Call Ring Arbitration Protocol:&lt;/p&gt;

&lt;p&gt;Incoming Call to Account Alice -&amp;gt; Fan-Out to [Phone, Laptop, Tablet]&lt;br&gt;
  • All 3 devices ring simultaneously.&lt;br&gt;
  • Alice taps "Answer" on her Laptop.&lt;br&gt;
  • Laptop emits a signed CallClaim event:&lt;br&gt;
    Claim { call_id: 104, winner: Laptop, timestamp: T, sig: LaptopKey }&lt;br&gt;
  • Phone and Tablet verify the signature, immediately silence their ringers,&lt;br&gt;
    and transition their UI to "Answered on another device".&lt;br&gt;
Because each device possesses an independent DeviceId and signing key, call pickup arbitration is cryptographically provable and immune to race-condition hijacking.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Defensive Engineering in Rust: Auditing the 21-Item Definition of Done
The crates/siar-identity-multidevice crate is engineered under the strictest systems constraints:&lt;/li&gt;
&lt;/ol&gt;

&lt;h1&gt;
  
  
  ![forbid(unsafe_code)]: Zero unsafe pointer dereferences or memory transmutation anywhere in the codebase.
&lt;/h1&gt;

&lt;p&gt;Zero anyhow in Public Domain APIs: All errors are strongly typed through exhaustive enums (IdentityError, RevocationError, RecoveryError) via thiserror.&lt;br&gt;
Deterministic Serialization: No platform-dependent types (usize, isize) on the wire; all integers are explicitly sized (u64, u32, u16, u8).&lt;br&gt;
Memory Zeroization: Secret keys implement the Zeroize trait on drop to purge sensitive key material from CPU registers and RAM caches.&lt;br&gt;
The 21-Item Definition-of-Done Self-Audit&lt;br&gt;
In crates/siar-identity-multidevice/src/definition_of_done.rs, the engineering team implemented a programmatic 21-item Definition-of-Done (DoD) audit covering every requirement of Spec 02:&lt;/p&gt;

&lt;h1&gt;
  
  
  [derive(Debug, Clone, Copy, PartialEq, Eq)]
&lt;/h1&gt;

&lt;p&gt;pub enum DodStatus {&lt;br&gt;
    Done,&lt;br&gt;
    PartiallyDone,&lt;br&gt;
    NotStarted,&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;pub struct DodItem {&lt;br&gt;
    pub section: u32,&lt;br&gt;
    pub title: &amp;amp;'static str,&lt;br&gt;
    pub status: DodStatus,&lt;br&gt;
    pub rationale: &amp;amp;'static str,&lt;br&gt;
}&lt;br&gt;
The self-audit outcome is documented with absolute engineering honesty:&lt;/p&gt;

&lt;p&gt;19 of 21 requirements are fully Done: Covering cryptographic identity models, signed snapshots, monotonic rollback protection, fork detection, instant revocation, root rotation, SAS verification, least-authority capabilities, and cross-subsystem integration.&lt;br&gt;
2 of 21 items are honestly classified as PartiallyDone:&lt;br&gt;
UserConfirmationRequired (§20): The data structure (LinkingApprovalPrompt) is implemented and strictly typed, but the crate ships no graphical user interface (UI) by design. The UI boundary lives in downstream GUI shells (siar-ui-desktop / siar-ui-android).&lt;br&gt;
FuzzPropertyIntegrationTestsExist (§164): Extensive proptest property suites (security_invariants.rs) and integration suites (integration_tests.rs) run continuously in CI; a dedicated AFL/LLVM cargo-fuzz harness is queued for the Milestone 2 security audit.&lt;br&gt;
Property Testing Cryptographic Invariants&lt;br&gt;
To ensure no subtle regressions compromise security, the test suite leverages property-based testing:&lt;/p&gt;

&lt;h1&gt;
  
  
  [test]
&lt;/h1&gt;

&lt;p&gt;fn prop_directory_signature_tamper_fails() {&lt;br&gt;
    let root = RootIdentityKey::generate();&lt;br&gt;
    let account = AccountId([1u8; 32]);&lt;br&gt;
    let dir = DeviceDirectory::sign(&amp;amp;root, account, 1, vec![]);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Any single bit mutation in the signature must fail verification
let mut bad_sig = dir.signature.clone();
bad_sig[0] ^= 0xFF;

let bad_dir = DeviceDirectory {
    signature: bad_sig,
    ..dir
};

assert!(bad_dir.verify_signature(&amp;amp;root.root_public_key()).is_err());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;h1&gt;
  
  
  [test]
&lt;/h1&gt;

&lt;p&gt;fn prop_rollback_attempt_is_rejected() {&lt;br&gt;
    let root = RootIdentityKey::generate();&lt;br&gt;
    let account = AccountId([2u8; 32]);&lt;br&gt;
    let mut store = TrustedAccountStore::new();&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let dir_g5 = DeviceDirectory::sign(&amp;amp;root, account, 5, vec![]);
let dir_g4 = DeviceDirectory::sign(&amp;amp;root, account, 4, vec![]);

assert!(store.accept(dir_g5, &amp;amp;root.root_public_key()).is_ok());

// Attempting to accept G4 after G5 must return RollbackRejected
let err = store.accept(dir_g4, &amp;amp;root.root_public_key()).unwrap_err();
assert!(matches!(err, IdentityError::RollbackRejected { given: 4, highest: 5 }));
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Every invariant is tested not through wishful thinking, but through exhaustive programmatic verification against real compiled binaries.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Ten Axioms for Distributed Multi-Device Identity Systems
Drawing from the architectural design of Spec 02, we offer ten foundational axioms for systems architects building modern local-first, peer-to-peer, or decentralized communication protocols:&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Never Conflate Account and Device: An account is a durable principal; a device is a physical possession. Model them as distinct cryptographic entities from day one.&lt;br&gt;
Never Export Private Keys Across Physical Boundaries: Device linking must be an act of cryptographic delegation and certification, never the physical transmission or export of long-lived private keys.&lt;br&gt;
The Root Key Must Sleep: Reserve the root signing key exclusively for issuing certificates, directories, and root rotations. Never use it to sign chat messages or establish transport sessions.&lt;br&gt;
Enforce Monotonic State Progression: In the absence of central databases, state rollback attacks are trivial unless directory snapshots carry strictly monotonic generation numbers enforced by a local trust store.&lt;br&gt;
Treat State Equivocation as a Security Breach: Conflicting signed states at the same generation number must never be silently resolved by timestamps or random selection. Treat forks as an immediate signal of key compromise.&lt;br&gt;
Keep Secret Material Out of Pairing Signals: Dynamic QR codes and NFC payloads must encode zero private keys or session secrets. Use them only to bootstrap authenticated ephemeral Diffie-Hellman handshakes.&lt;br&gt;
Tie Pairing Codes to the Full Transcript: Verification codes (SAS) must be cryptographically derived from both ephemeral public keys, the signed invite, and the shared secret. Never display random numbers.&lt;br&gt;
Make Revocation Immediate and Synchronous: Revocation must not require an internet connection or server handshake. A local trusted device must be able to advance generation $G+1$ and blackball a compromised key instantly.&lt;br&gt;
Apply the Principle of Least Authority to Hardware: Distinguish device roles through compact capability bitsets. Headless relays, edge repeaters, and IoT nodes should hold zero keys capable of reading chat or adding devices.&lt;br&gt;
Preserve Device-Level Truth in the Core: Attribute packets and delivery receipts to specific physical devices at the data plane, while presenting a clean, unified account identity at the human interface.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Conclusion &amp;amp; Next Steps in the Series
Decentralized communications cannot mature into global, mission-critical infrastructure if we continue to force users into the fragile world of single-key cryptography or surrender their autonomy to centralized coordination servers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spec 02: Multi-Device Identity Architecture demonstrates that sovereign, local-first architectures can achieve the seamless user experience of modern cloud messengers without compromising cryptographic rigor. By establishing a five-tier identity separation, enforcing monotonic generation ratchets, conducting zero-knowledge pairing ceremonies, and binding least-authority capability bitsets directly into signed directory snapshots, SIAR delivers an identity substrate capable of surviving both nation-state cyberattacks and total infrastructure collapse.&lt;/p&gt;

&lt;p&gt;In Part 3 of this 24-part deep-dive series, we will explore Spec 03: Transport Routing Policy Engine Architecture (crates/siar-routing-policy). We will examine how SIAR abstracts physical network bearers, performs dynamic link cost estimation, executes multi-bearer failovers between QUIC, Wi-Fi Aware, and BLE, and routes encrypted packets across fragmented, partition-heavy mesh networks.&lt;/p&gt;

&lt;p&gt;Subscribe to follow along as we build the survivable, decentralized communication stack of the next century.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>rust</category>
      <category>security</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title># Architecting a Zero-Monolith P2P Protocol: How SIAR Solves Versioning, Capabilities, and Backpressure in Rust</title>
      <dc:creator>Irshad Ali</dc:creator>
      <pubDate>Tue, 08 Sep 2026 17:17:24 +0000</pubDate>
      <link>https://dev.to/irshadali5/-architecting-a-zero-monolith-p2p-protocol-how-siar-solves-versioning-capabilities-and-4bo8</link>
      <guid>https://dev.to/irshadali5/-architecting-a-zero-monolith-p2p-protocol-how-siar-solves-versioning-capabilities-and-4bo8</guid>
      <description>&lt;p&gt;&lt;em&gt;By the SIAR Engineering Team&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;Target Platforms: Substack / Dev.to | Technical Deep-Dive Series: Part 1 of 24&lt;/em&gt;&lt;br&gt;&lt;br&gt;
&lt;em&gt;Focus: Spec 01 — Protocol Extension System Architecture (&lt;code&gt;crates/siar-protocol-ext&lt;/code&gt;)&lt;/em&gt;&lt;/p&gt;




&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                       +---------------------------------------+
                       |           Application Layer           |
                       |  (Messaging, Files, ERP, Emergency)   |
                       +-------------------+-------------------+
                                           |
                                           v
                       +---------------------------------------+
                       |       Extension Protocol Layer        |
                       |   (Independently Versioned Specs)     |
                       +-------------------+-------------------+
                                           |
                                           v
                       +---------------------------------------+
                       |      Session Multiplexer Engine       |
                       |    (Fair Weighted Round-Robin + WFQ)   |
                       +-------------------+-------------------+
                                           |
                                           v
                       +---------------------------------------+
                       |          Core Control Protocol        |
                       |    (Identity, Handshake, Capability)  |
                       +-------------------+-------------------+
                                           |
                                           v
                       +---------------------------------------+
                       |     Transport Abstraction (Multi)     |
                       |   (Iroh QUIC / BLE / Wi-Fi / DTN)     |
                       +---------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Table of Contents
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Introduction: The Monolithic Protocol Trap&lt;/li&gt;
&lt;li&gt;The Architectural Axioms of SIAR&lt;/li&gt;
&lt;li&gt;The Anatomy of Spec 01: Core vs. Extension Separation&lt;/li&gt;
&lt;li&gt;Namespaces, Identifiers, and Session-Local Translation&lt;/li&gt;
&lt;li&gt;The Mathematics of Capability Negotiation&lt;/li&gt;
&lt;li&gt;Defensive Data Plane: Safe Framing and Zero Memory Exhaustion&lt;/li&gt;
&lt;li&gt;Flow Control, Backpressure, and Weighted Fair Scheduling&lt;/li&gt;
&lt;li&gt;Lifecycle State Machines, Lazy Opening, and Mobile Energy Discipline&lt;/li&gt;
&lt;li&gt;
Cross-Subsystem Integration: Grounding Spec 01 in the Real World

&lt;ul&gt;
&lt;li&gt;9.1 Transport Neutrality &amp;amp; Multipath Routing (Specs 03 &amp;amp; 12)&lt;/li&gt;
&lt;li&gt;9.2 Delay-Tolerant Networking &amp;amp; Asynchronous Bundles (Specs 04 &amp;amp; 06)&lt;/li&gt;
&lt;li&gt;9.3 Multi-Device Identity &amp;amp; MLS E2EE Boundaries (Specs 02 &amp;amp; 28)&lt;/li&gt;
&lt;li&gt;9.4 Headless Daemons &amp;amp; Embedded Linux Repeaters (Specs 16 &amp;amp; 20)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Rust Implementation Deep-Dive: A Tour of &lt;code&gt;siar-protocol-ext&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Verification, Property Testing, and Golden Wire Invariants&lt;/li&gt;
&lt;li&gt;Ten Golden Rules for Distributed Protocol Designers&lt;/li&gt;
&lt;li&gt;Conclusion &amp;amp; Next Steps in the Series&lt;/li&gt;
&lt;/ol&gt;


&lt;h2&gt;
  
  
  1. Introduction: The Monolithic Protocol Trap
&lt;/h2&gt;

&lt;p&gt;Every ambitious peer-to-peer (P2P), local-first, or decentralized protocol begins with clean intentions and a simple wire layout. You define a message enum in your favorite systems language, write a serializer, spin up a socket, and send packets between two nodes. It feels effortless:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The seductive, fatal trap of early P2P protocol design&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;ProtocolMessage&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Hello&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;peer_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="n"&gt;TextMessage&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="n"&gt;FileChunk&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;file_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Vec&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="n"&gt;Heartbeat&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This works delightfully in a staging environment. But six months later, reality strikes:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Feature Coupling &amp;amp; Version Bloat&lt;/strong&gt;: Your team adds audio calls. Then reactions. Then group metadata synchronization. Then emergency disaster alerts. Your simple enum swells to seventy variants. Suddenly, every micro-embedded sensor, solar-powered field repeater, and headless storage daemon running your codebase is forced to pull in cryptographic libraries, multimedia codecs, and complex group ratchet engines just to deserialize incoming packets.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Fragile Wire Cascade&lt;/strong&gt;: A developer modifies the payload of &lt;code&gt;TextMessage&lt;/code&gt; to support rich formatting or read receipts. Two clients running different minor releases connect over an ad-hoc Wi-Fi link. The older client encounters an unknown tag or deserialization error, panics, drops the connection, and the entire peer session collapses.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Central Governance Bottleneck&lt;/strong&gt;: A partner company or third-party engineering team wishes to deploy an enterprise-specific inventory sync workflow over your mesh. Under the centralized enum model, they cannot do this without submitting a pull request to your core repository, modifying your enum, and convincing you to release a new global protocol version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Memory and Head-of-Line Starvation&lt;/strong&gt;: A node initiates a 200 MB file transfer over a low-bandwidth Bluetooth Low Energy (BLE) link while another node broadcasts a time-sensitive emergency SOS alert. Because the protocol treats all variants as equal members of a flat pipeline, the multi-megabyte file chunks flood the socket queues, exhausting memory buffers and starving life-critical beacons.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;This architectural failure mode is the &lt;strong&gt;Monolithic Protocol Trap&lt;/strong&gt;. It has crippled dozens of P2P and distributed systems, transforming modular software into brittle, unmaintainable monoliths where protocol evolution grinds to a halt.&lt;/p&gt;

&lt;p&gt;When we set out to build &lt;strong&gt;SIAR&lt;/strong&gt; (&lt;em&gt;Survivable Identity &amp;amp; Autonomous Routing&lt;/em&gt;)—a zero-infrastructure, multi-transport, offline-first mesh communications system designed to survive total internet blackouts, natural disasters, and hostile network partitions—we made a foundational commitment:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The protocol must evolve through independently versioned, capability-negotiated extensions, never through an ever-growing central enum.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This principle forms the basis of &lt;strong&gt;Spec 01: Protocol Extension System Architecture&lt;/strong&gt;, realized in the pure-Rust &lt;code&gt;siar-protocol-ext&lt;/code&gt; crate. In this technical deep-dive, we break down how Spec 01 achieves true zero-coupling modularity, how capability negotiation prevents session failures across disparate node generations, how we enforce hard byte-level backpressure at the data plane, and how this architecture scales seamlessly from 4MB embedded Linux repeaters to modern Android and desktop clients.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. The Architectural Axioms of SIAR
&lt;/h2&gt;

&lt;p&gt;To understand the mechanics of Spec 01, one must understand the operating environment for which SIAR is engineered. SIAR is not another centralized messenger wrapping a cloud server in an Electron shell. It is a multi-bearer, delay-tolerant networking (DTN) platform operating across four strict physical and logical layers:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+-------------------------------------------------------------------------+
|                  SIAR Platform Architecture Axioms                      |
+-------------------------------------------------------------------------+
|  1. Rust-First Bare-Metal Core: Deterministic memory, zero garbage      |
|     collection pauses, compile-time thread safety, and cross-platform   |
|     hermeticity (Linux, Android NDK, macOS, Windows, Embedded).         |
|                                                                         |
|  2. Zero Central Infrastructure: Identity is cryptographic (Ed25519     |
|     keypairs, X25519 DH). No central directory, no cloud authorization.  |
|                                                                         |
|  3. Multi-Bearer Opportunistic Transport: Dynamic switching between     |
|     Iroh QUIC (direct WAN/LAN), Wi-Fi Direct, Wi-Fi Aware (NAN), BLE,   |
|     and Bluetooth Classic without dropping active sessions.             |
|                                                                         |
|  4. Asynchronous Store-Carry-Forward (DTN): Physical data ferrying      |
|     across severed networks via solar field repeaters and moving nodes.  |
|                                                                         |
|  5. Hard Memory &amp;amp; Battery Boundaries: Mobile devices must not burn      |
|     battery initializing unneeded subsystems; embedded nodes must never |
|     panic from unbounded allocation under malicious traffic.            |
+-------------------------------------------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Under these axioms, any design pattern that forces tight coupling between product features (such as chat, file distribution, and presence) and transport or network machinery is strictly fatal. &lt;/p&gt;

&lt;p&gt;If a disaster-relief team deploys a battery-powered Raspberry Pi headless daemon (&lt;code&gt;siar-emergency-node&lt;/code&gt;) on a mountaintop, that node needs to forward DTN storage bundles, negotiate peer capabilities over Wi-Fi, and route emergency beacons. It must never know what a user avatar is, how markdown chat messages are parsed, or what codec a video call requires.&lt;/p&gt;

&lt;p&gt;Spec 01 provides the rigorous architectural blueprint that makes this strict modularity mathematically and programmatically enforceable.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. The Anatomy of Spec 01: Core vs. Extension Separation
&lt;/h2&gt;

&lt;p&gt;The central breakthrough of Spec 01 is an uncompromising separation of concerns between the &lt;strong&gt;Core Control Protocol&lt;/strong&gt; and &lt;strong&gt;Extension Protocols&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                                  +------------------------------+
                                  |     Communication Session    |
                                  +--------------+---------------+
                                                 |
         +-----------------------+---------------+-----------------------+
         |                       |                                       |
         v                       v                                       v
+-----------------+     +-----------------+                     +-----------------+
|  Core Control   |     |    Messaging    |                     | File Subsystem  |
|    Protocol     |     |    Extension    |                     |    Extension    |
| (Always Present)|     | (org.siar/msg/1)|                     |(org.siar/file/1)|
+-----------------+     +-----------------+                     +-----------------+
| • Hello         |     | • Text payload  |                     | • Chunk payload |
| • Peer Auth     |     | • Reactions     |                     | • Hash manifest |
| • Capabilities  |     | • Read receipts |                     | • Resumption    |
| • Extension Mux |     | • Outbox sync   |                     | • Stream window |
| • Flow Metadata |     +-----------------+                     +-----------------+
| • Error Framing |
+-----------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3.1 What the Core Protocol Knows
&lt;/h3&gt;

&lt;p&gt;The Core Protocol is the minimal set of semantics required for any two nodes to establish a secure, authenticated, and bounded conversation. It is intentionally small, invariant, and universally implemented by every peer in the SIAR ecosystem.&lt;/p&gt;

&lt;p&gt;Its responsibilities are strictly limited to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Session Handshake (&lt;code&gt;Hello&lt;/code&gt; / &lt;code&gt;HelloAck&lt;/code&gt;)&lt;/strong&gt;: Authenticating peer identities via cryptographic signatures and agreeing upon the core framing version.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Peer Identity Binding&lt;/strong&gt;: Cryptographically proving that the transport link corresponds to the claimed public key (&lt;code&gt;DeviceIdentity&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extension Advertisement&lt;/strong&gt;: Exchanging the inventory of protocol extensions supported by each node.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Capability Negotiation&lt;/strong&gt;: Performing deterministic mathematical intersection over the capability sets of mutually supported extensions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Extension Lifecycle Management&lt;/strong&gt;: Opening, closing, pausing, and resuming logical extension channels (&lt;code&gt;ExtensionOpen&lt;/code&gt;, &lt;code&gt;ExtensionClose&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session-Level Flow Control&lt;/strong&gt;: Exchanging window updates, queue pressure signals, and keep-alive pings.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Error Framing&lt;/strong&gt;: Emitting deterministic error codes when wire semantics are violated.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3.2 What the Core Protocol Never Knows
&lt;/h3&gt;

&lt;p&gt;By specification, the Core Protocol has &lt;strong&gt;zero knowledge&lt;/strong&gt; of:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The structure of a chat message or whether text is UTF-8 or encrypted ciphertext.&lt;/li&gt;
&lt;li&gt;File transfer chunk sizes, ranges, hashes, or storage paths.&lt;/li&gt;
&lt;li&gt;Presence states, typing indicators, or read receipts.&lt;/li&gt;
&lt;li&gt;Group membership lists or MLS cryptographic epoch trees.&lt;/li&gt;
&lt;li&gt;Emergency SOS coordinate layouts or disaster medical telemetry.&lt;/li&gt;
&lt;li&gt;Enterprise-specific business objects or ERP forms.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All application logic lives entirely within self-contained &lt;strong&gt;Extension Protocols&lt;/strong&gt;. If an unknown extension frame arrives, the core protocol multiplexer does not drop the session or trigger a deserialization fault. It routes it according to established forward-compatibility rules: optional extensions are cleanly ignored; required extensions fail gracefully with structured wire diagnostics.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Namespaces, Identifiers, and Session-Local Translation
&lt;/h2&gt;

&lt;p&gt;How do nodes refer to protocol extensions without collisions, centralized registries, or string parsing bottlenecks? Spec 01 establishes a two-phase identifier model: &lt;strong&gt;Globally Unique Canonical Identifiers&lt;/strong&gt; on the outside, and &lt;strong&gt;Session-Local Numeric Identifiers&lt;/strong&gt; on the wire.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.1 Hierarchical Global Namespaces
&lt;/h3&gt;

&lt;p&gt;Every protocol extension is uniquely identified across the universe by a three-part canonical identifier:&lt;/p&gt;

&lt;p&gt;$$\text{ProtocolId} = \langle\text{NamespaceId}\rangle \,/\, \langle\text{ProtocolName}\rangle \,/\, \langle\text{ProtocolMajor}\rangle$$&lt;/p&gt;

&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;org.siar.comm/messaging/1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;org.siar.comm/files/1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;org.siar.comm/presence/1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;org.siar.emergency/sos/1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;com.acme.logistics/pallet-telemetry/2&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In &lt;code&gt;crates/siar-protocol-ext/src/identifier.rs&lt;/code&gt;, this is enforced through strongly typed structs that prevent loose string manipulation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[derive(Debug,&lt;/span&gt; &lt;span class="nd"&gt;Clone,&lt;/span&gt; &lt;span class="nd"&gt;PartialEq,&lt;/span&gt; &lt;span class="nd"&gt;Eq,&lt;/span&gt; &lt;span class="nd"&gt;Hash)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;ProtocolId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;NamespaceId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ProtocolName&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;major&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ProtocolMajor&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;ProtocolId&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;major&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;Self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ProtocolIdError&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;namespace&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;NamespaceId&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;protocol&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;ProtocolName&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;parse&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;Self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;namespace&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;protocol&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;major&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;ProtocolMajor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;major&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;})&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="cd"&gt;/// Returns the canonical RFC-style wire representation&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;to_canonical_string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;String&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nd"&gt;format!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"{}/{}/{}"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.namespace&lt;/span&gt;&lt;span class="nf"&gt;.as_str&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.protocol&lt;/span&gt;&lt;span class="nf"&gt;.as_str&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.major&lt;/span&gt;&lt;span class="na"&gt;.0&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the inclusion of &lt;code&gt;major&lt;/code&gt; directly in the protocol identity. Under Spec 01, a bump in the major version signifies an inherently wire-incompatible change. Therefore, &lt;code&gt;org.siar.comm/messaging/1&lt;/code&gt; and &lt;code&gt;org.siar.comm/messaging/2&lt;/code&gt; are treated by the runtime as two completely distinct protocols that happen to share a namespace. A node can advertise support for both simultaneously, allowing clean backward compatibility during multi-year network transitions.&lt;/p&gt;

&lt;h3&gt;
  
  
  4.2 Ephemeral Session-Local IDs
&lt;/h3&gt;

&lt;p&gt;While canonical strings like &lt;code&gt;org.siar.comm/messaging/1&lt;/code&gt; are vital for debugging, logging, and third-party developer clarity, sending a 30-byte string in the header of every single data frame over a 20 kbps BLE connection would impose unacceptable protocol overhead.&lt;/p&gt;

&lt;p&gt;Spec 01 resolves this through &lt;strong&gt;Session-Local ID Translation&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Negotiation Phase (Handshake):
  Peer A -&amp;gt; Peer B: "I support 'org.siar.comm/messaging/1' and 'org.siar.comm/files/1'"
  Peer B -&amp;gt; Peer A: "Agreed. For this session:
                     'org.siar.comm/messaging/1' =&amp;gt; SessionLocalExtensionId(1)
                     'org.siar.comm/files/1'     =&amp;gt; SessionLocalExtensionId(2)"

Data Plane Phase (Streaming):
  [Frame Header: StreamId(1) | LocalExtId: 0x0001 | Len: 256 | Payload: ...]
  [Frame Header: StreamId(2) | LocalExtId: 0x0002 | Len: 1024| Payload: ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The wire framing uses a fixed-width &lt;code&gt;u16&lt;/code&gt; (&lt;code&gt;SessionLocalExtensionId&lt;/code&gt;). The mapping is negotiated dynamically during session initialization, stored in a fast contiguous lookup array on both peers, and discarded when the transport disconnects. We achieve the diagnostic power of human-readable namespaces with the wire density of hand-optimized binary protocols.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. The Mathematics of Capability Negotiation
&lt;/h2&gt;

&lt;p&gt;In distributed networks, version numbers are notoriously deceptive. Suppose two nodes both claim to support &lt;code&gt;org.siar.comm/messaging/1&lt;/code&gt;. Does that mean they can exchange inline images? Can they edit messages after transmission? Can they process reaction emojis or read receipts?&lt;/p&gt;

&lt;p&gt;If you rely solely on version numbers, you enter "version matrix hell," where engineers write fragile conditional logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// The wrong way: version check spaghetti&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="py"&gt;.minor_version&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="n"&gt;peer&lt;/span&gt;&lt;span class="py"&gt;.patch_version&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nf"&gt;send_reaction&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spec 01 replaces this with &lt;strong&gt;Explicit Set-Theoretic Capability Negotiation&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.1 Capabilities as Independent Bitsets
&lt;/h3&gt;

&lt;p&gt;Within an extension, features are modeled as discrete capabilities identified by a fixed-width &lt;code&gt;CapabilityId(u32)&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[derive(Debug,&lt;/span&gt; &lt;span class="nd"&gt;Clone,&lt;/span&gt; &lt;span class="nd"&gt;Copy,&lt;/span&gt; &lt;span class="nd"&gt;PartialEq,&lt;/span&gt; &lt;span class="nd"&gt;Eq,&lt;/span&gt; &lt;span class="nd"&gt;Hash,&lt;/span&gt; &lt;span class="nd"&gt;PartialOrd,&lt;/span&gt; &lt;span class="nd"&gt;Ord)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="nf"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nd"&gt;#[derive(Debug,&lt;/span&gt; &lt;span class="nd"&gt;Clone,&lt;/span&gt; &lt;span class="nd"&gt;Default,&lt;/span&gt; &lt;span class="nd"&gt;PartialEq,&lt;/span&gt; &lt;span class="nd"&gt;Eq)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;CapabilitySet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;BTreeSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;CapabilityId&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt; &lt;span class="n"&gt;CapabilitySet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/// Compute the negotiated feature subset: Local ∩ Remote&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;intersect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;remote&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;CapabilitySet&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;CapabilitySet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;intersection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;BTreeSet&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;CapabilityId&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;
            &lt;span class="py"&gt;.values&lt;/span&gt;
            &lt;span class="nf"&gt;.intersection&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;remote&lt;/span&gt;&lt;span class="py"&gt;.values&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="nf"&gt;.copied&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
            &lt;span class="nf"&gt;.collect&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="n"&gt;CapabilitySet&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;values&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;intersection&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.values&lt;/span&gt;&lt;span class="nf"&gt;.contains&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When defining an extension, developers assign stable numeric IDs to concrete capabilities. For example, in SIAR's messaging extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;mod&lt;/span&gt; &lt;span class="n"&gt;messaging_caps&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="k"&gt;super&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;TEXT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilityId&lt;/span&gt;          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;REPLY&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilityId&lt;/span&gt;         &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;EDIT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilityId&lt;/span&gt;          &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;REACTION&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilityId&lt;/span&gt;      &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;READ_RECEIPT&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilityId&lt;/span&gt;  &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;TYPING&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilityId&lt;/span&gt;        &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;GROUP_MESSAGING&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilityId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;CapabilityId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5.2 The Two-Phase Negotiation Flow
&lt;/h3&gt;

&lt;p&gt;When two peers connect, they execute a strictly sequenced negotiation handshake:&lt;br&gt;
&lt;/p&gt;

&lt;pre data-lang="mermaid"&gt;&lt;code&gt;sequenceDiagram
    autonumber
    participant Alice as Peer A (Modern Node v1.4)
    participant Bob as Peer B (Field Node v1.1)

    Alice-&amp;gt;&amp;gt;Bob: CORE_HELLO (Protocols: [msg/1 {text, reply, edit, react}, files/1 {resume}])
    Note over Bob: Evaluates Local Manifest against Alice's Advertisement
    Note over Bob: Computes Intersection for msg/1: {text, reply}&amp;lt;br/&amp;gt;edit &amp;amp; react unsupported locally
    Bob-&amp;gt;&amp;gt;Alice: CORE_HELLO_ACK (Accepted: [msg/1 {text, reply} (LocalId=1)], Rejected: [files/1: Unsupported])
    Note over Alice: Validates Required vs Optional Constraints
    Note over Alice: Session Established: msg/1 active at LocalId=1 with {text, reply}&lt;/code&gt;&lt;/pre&gt;



&lt;p&gt;The mathematical rule governing the session is absolute:&lt;/p&gt;

&lt;p&gt;$$\mathcal{C}&lt;em&gt;{\text{active}} = \mathcal{C}&lt;/em&gt;{\text{local}} \cap \mathcal{C}_{\text{remote}}$$&lt;/p&gt;

&lt;p&gt;No node is ever allowed to transmit an operation on the wire unless its required capability exists within $\mathcal{C}_{\text{active}}$. If a user taps "React with ❤️" on a modern smartphone, but the peer on the other end of the mesh is a legacy node lacking &lt;code&gt;messaging_caps::REACTION&lt;/code&gt;, the local UI gracefully disables the action or displays a subtle fallback indicator. Not a single invalid byte is sent over the radio.&lt;/p&gt;

&lt;h3&gt;
  
  
  5.3 Mandatory vs. Optional Extension Semantics
&lt;/h3&gt;

&lt;p&gt;Not all extensions are created equal. A specialized desktop file-transfer utility requires &lt;code&gt;files/1&lt;/code&gt; to be useful, whereas a general-purpose messenger considers &lt;code&gt;files/1&lt;/code&gt; an optional luxury:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[derive(Debug,&lt;/span&gt; &lt;span class="nd"&gt;Clone,&lt;/span&gt; &lt;span class="nd"&gt;Copy,&lt;/span&gt; &lt;span class="nd"&gt;PartialEq,&lt;/span&gt; &lt;span class="nd"&gt;Eq)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;ExtensionRequirement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Required&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;Optional&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Spec 01 enforces two invariant safety rules during negotiation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The Optional Extension Rule&lt;/strong&gt;: If Peer A advertises an optional extension that Peer B does not support (or whose major versions do not overlap), the negotiation engine simply omits that extension from the active session. &lt;strong&gt;An unsupported optional extension must never tear down the peer connection.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The Required Extension Rule&lt;/strong&gt;: If Peer A requires an extension that Peer B cannot satisfy, the negotiation fails deterministically with &lt;code&gt;NegotiationError::MissingRequiredExtension&lt;/code&gt;. The session is halted before any application data can be corrupted or misinterpreted.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  6. Defensive Data Plane: Safe Framing and Zero Memory Exhaustion
&lt;/h2&gt;

&lt;p&gt;P2P networks are inherently adversarial. A peer connection might be a trusted family member's phone, an untrusted passerby's Bluetooth radio, or a malicious actor intentionally injecting malformed frames to trigger buffer overflows and crash mesh repeaters.&lt;/p&gt;

&lt;p&gt;The golden rule of systems programming in P2P is: &lt;strong&gt;Never trust remote length fields.&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  6.1 The 4-Step Framing Sequence
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;crates/siar-protocol-ext/src/framing.rs&lt;/code&gt;, we mandate that frame deserialization occur through a four-step, non-collapsible verification barrier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[ Incoming Byte Stream ]
          |
          v
+-------------------------------------------------------------+
| Step 1: Read Exactly Bounded Header (FRAME_HEADER_BYTES=10) |
+-------------------------------------------------------------+
          |
          v
+-------------------------------------------------------------+
| Step 2: Validate Wire Length Against Absolute Protocol Max  |
|         (frame_length &amp;lt;= ABSOLUTE_MAX_FRAME_SIZE: 16 MB)    |
+-------------------------------------------------------------+
          |
          v
+-------------------------------------------------------------+
| Step 3: Check Against Negotiated Extension Limits           |
|         (frame_length &amp;lt;= extension_limits.max_frame_size)   |
|         e.g., Messaging = 64 KB, Files = 1 MB               |
+-------------------------------------------------------------+
          |
          v
+-------------------------------------------------------------+
| Step 4: Allocate Buffer Safely &amp;amp; Read Payload Bytes         |
+-------------------------------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Many vulnerable network daemons collapse these steps into one: they read a length integer from the wire and immediately invoke &lt;code&gt;Vec::with_capacity(remote_length)&lt;/code&gt;. If a malicious peer transmits a header claiming a payload of &lt;code&gt;0xFFFFFFFF&lt;/code&gt; (4 GB), the receiving node attempts to allocate 4 gigabytes of memory and panics via an out-of-memory (OOM) abort.&lt;/p&gt;

&lt;p&gt;In SIAR, step 3 intercepts the frame before allocation takes place:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;FRAME_HEADER_BYTES&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ABSOLUTE_MAX_FRAME_SIZE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="c1"&gt;// 16 MB ceiling&lt;/span&gt;

&lt;span class="nd"&gt;#[derive(Debug,&lt;/span&gt; &lt;span class="nd"&gt;Clone,&lt;/span&gt; &lt;span class="nd"&gt;PartialEq,&lt;/span&gt; &lt;span class="nd"&gt;Eq)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;FrameHeader&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;frame_length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;session_extension_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;SessionLocalExtensionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;frame_type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;parse_frame_header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;FrameHeader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;FramingError&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="nf"&gt;.len&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="n"&gt;FRAME_HEADER_BYTES&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;FramingError&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;IncompleteHeader&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;frame_length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;u32&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_be_bytes&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;]]);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;ext_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;u16&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_be_bytes&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]]);&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;frame_type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;6&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;flags&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;buf&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;frame_length&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ABSOLUTE_MAX_FRAME_SIZE&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;FramingError&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;OversizedFrame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;frame_length&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;FrameHeader&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;frame_length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;session_extension_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;SessionLocalExtensionId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;ext_id&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;frame_type&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;validate_frame_length&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;FrameHeader&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;limits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;ExtensionLimits&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;FramingError&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="py"&gt;.frame_length&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;limits&lt;/span&gt;&lt;span class="py"&gt;.max_frame_size&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;FramingError&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="n"&gt;ExceedsExtensionLimit&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="n"&gt;requested&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="py"&gt;.frame_length&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="n"&gt;limit&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;limits&lt;/span&gt;&lt;span class="py"&gt;.max_frame_size&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(())&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a peer sends a 512 KB frame on the &lt;code&gt;messaging&lt;/code&gt; extension (which declares a strict 64 KB limit), the frame is rejected at Step 3 with zero heap allocations performed. The node classifies this violation, closes the abusive channel, and remains fully operational.&lt;/p&gt;

&lt;h3&gt;
  
  
  6.2 Serialization Discipline: Separation of Wire and Domain Models
&lt;/h3&gt;

&lt;p&gt;Spec 01 establishes strict rules regarding serialization:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Domain Types Are Never Wire Types&lt;/strong&gt;: You must never attach &lt;code&gt;#[derive(Serialize, Deserialize)]&lt;/code&gt; to an internal database or UI struct and blast it over the network. Domain models change as features evolve; wire formats must remain immortal. Every extension maintains a dedicated &lt;code&gt;wire&lt;/code&gt; module containing explicit, versioned schema representations.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fixed-Width Integers Only&lt;/strong&gt;: The Rust &lt;code&gt;usize&lt;/code&gt; type is strictly forbidden on the wire. A &lt;code&gt;usize&lt;/code&gt; is 4 bytes on a 32-bit ARM Cortex-M micro-controller and 8 bytes on an x86_64 server. Using &lt;code&gt;usize&lt;/code&gt; on the wire destroys cross-architecture interoperability. Wire structs exclusively use &lt;code&gt;u8&lt;/code&gt;, &lt;code&gt;u16&lt;/code&gt;, &lt;code&gt;u32&lt;/code&gt;, &lt;code&gt;u64&lt;/code&gt;, and fixed-length byte arrays.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Rust Is the Reference Implementation, Not the Wire Specification&lt;/strong&gt;: The wire protocol must be fully specifiable without referencing the Rust compiler's internal memory layout. No &lt;code&gt;#[repr(C)]&lt;/code&gt; struct dumps, no native endianness assumptions (big-endian network order is strictly enforced), and no compiler-generated enum discriminant assumptions.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  7. Flow Control, Backpressure, and Weighted Fair Scheduling
&lt;/h2&gt;

&lt;p&gt;When devices communicate over heterogeneous, intermittent paths, transmission speeds diverge by multiple orders of magnitude. A local Wi-Fi 6 link can easily move 500 megabits per second. A Bluetooth Low Energy (BLE) link struggles to deliver 40 kilobits per second. A multi-hop DTN mesh route across field repeaters might transmit in sporadic 10-kilobyte bursts spaced minutes apart.&lt;/p&gt;

&lt;p&gt;If a local desktop client begins streaming a 50 MB video file while connected to a phone over BLE, what happens if the phone's receiver cannot write to disk or drain its network socket as fast as the desktop pumps bytes?&lt;/p&gt;

&lt;p&gt;Without hard backpressure, the desktop's outgoing buffers explode in memory, the phone's incoming buffers overflow, packets drop, radios thrash in retransmission storms, and the device overheats.&lt;/p&gt;

&lt;h3&gt;
  
  
  7.1 True Backpressure via Ownership Rejection
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;crates/siar-protocol-ext/src/backpressure.rs&lt;/code&gt;, backpressure is not an optional advisory flag—it is a physical gate. Queues are strictly bounded in both item count and aggregate byte capacity:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;BoundedQueue&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;VecDeque&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;max_items&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;current_bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;max_bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;usize&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;impl&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Measurable&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;BoundedQueue&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;push&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;BackpressureRejection&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;T&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;item_size&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="nf"&gt;.byte_size&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.items&lt;/span&gt;&lt;span class="nf"&gt;.len&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.max_items&lt;/span&gt; &lt;span class="p"&gt;||&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.current_bytes&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;item_size&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.max_bytes&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="c1"&gt;// Hand the item back to the caller! Zero allocations, no silent drops.&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;Err&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;BackpressureRejection&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="n"&gt;rejected_item&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="n"&gt;current_depth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.items&lt;/span&gt;&lt;span class="nf"&gt;.len&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
                &lt;span class="n"&gt;current_bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.current_bytes&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="p"&gt;});&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.current_bytes&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="n"&gt;item_size&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="py"&gt;.items&lt;/span&gt;&lt;span class="nf"&gt;.push_back&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;item&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="nf"&gt;Ok&lt;/span&gt;&lt;span class="p"&gt;(())&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the return signature: &lt;code&gt;Result&amp;lt;(), BackpressureRejection&amp;lt;T&amp;gt;&amp;gt;&lt;/code&gt;. If the queue is at capacity, the queue does not drop the item into the void, nor does it block the thread indefinitely. It &lt;strong&gt;returns ownership of the item back to the caller&lt;/strong&gt;. The calling subsystem immediately senses backpressure and must throttle its own upstream producer, pausing file-chunk reads from disk until socket drain events fire.&lt;/p&gt;

&lt;h3&gt;
  
  
  7.2 Multi-Tier Traffic Priorities
&lt;/h3&gt;

&lt;p&gt;Different categories of protocol traffic have radically different urgency profiles. Spec 01 formalizes a 6-tier priority hierarchy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[derive(Debug,&lt;/span&gt; &lt;span class="nd"&gt;Clone,&lt;/span&gt; &lt;span class="nd"&gt;Copy,&lt;/span&gt; &lt;span class="nd"&gt;PartialEq,&lt;/span&gt; &lt;span class="nd"&gt;Eq,&lt;/span&gt; &lt;span class="nd"&gt;PartialOrd,&lt;/span&gt; &lt;span class="nd"&gt;Ord)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;TrafficPriority&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Critical&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;     &lt;span class="c1"&gt;// Life-safety SOS alerts, disaster beacons, route failure notices&lt;/span&gt;
    &lt;span class="n"&gt;Control&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;// Flow control windows, ping/pong, capability re-negotiation&lt;/span&gt;
    &lt;span class="n"&gt;Interactive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// Direct human typing, ephemeral text messages, voice signaling&lt;/span&gt;
    &lt;span class="n"&gt;Normal&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;       &lt;span class="c1"&gt;// Message delivery receipts, contact card updates, avatars&lt;/span&gt;
    &lt;span class="n"&gt;Bulk&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;         &lt;span class="c1"&gt;// Media attachments, encrypted file chunks, database backups&lt;/span&gt;
    &lt;span class="n"&gt;Background&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// Diagnostic sync, DHT gossip maintenance, log exports&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  7.3 Weighted Fair Scheduling with Bounded Emergency Override
&lt;/h3&gt;

&lt;p&gt;A naive scheduler would simply serve traffic using a strict priority queue: always send &lt;code&gt;Critical&lt;/code&gt; first, then &lt;code&gt;Control&lt;/code&gt;, down to &lt;code&gt;Background&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;This naive approach is disastrous in distributed systems because it introduces &lt;strong&gt;Perpetual Starvation&lt;/strong&gt;. If an aggressive background sync routine or a steady stream of interactive text messages saturates a slow BLE link, bulk file transfers will never send a single byte. Worse, if an errant node or bug generates continuous high-priority traffic, the entire communication pipeline deadlocks.&lt;/p&gt;

&lt;p&gt;Spec 01 implements &lt;strong&gt;Weighted Fair Round-Robin (WFRR) with a Bounded Emergency Override&lt;/strong&gt; in &lt;code&gt;crates/siar-protocol-ext/src/scheduler.rs&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Priority Tier Weights:
  Interactive  ===&amp;gt; Weight: 8 packets / round
  Normal       ===&amp;gt; Weight: 4 packets / round
  Bulk         ===&amp;gt; Weight: 2 packets / round
  Background   ===&amp;gt; Weight: 1 packet  / round

Emergency Override Gate:
  Critical / Control packets bypass the round-robin schedule immediately,
  BUT are capped at MAX_CONSECUTIVE_CRITICAL (e.g., 16 packets).
  Once the burst cap is reached, the scheduler forcibly yields at least
  one time-slice to lower-tier queues to prevent total channel starvation.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This guarantees two mathematical invariants:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Bounded Latency for Emergencies&lt;/strong&gt;: An incoming emergency SOS message is guaranteed immediate transmission ahead of all queued file chunks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Starvation Freedom&lt;/strong&gt;: Bulk and background queues are mathematically guaranteed forward progress over any sustained time window.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  8. Lifecycle State Machines, Lazy Opening, and Mobile Energy Discipline
&lt;/h2&gt;

&lt;p&gt;On mobile operating systems (Android and iOS), background execution is an unforgiving environment. If an app awakens in the background to handle an incoming push or mesh ping, and immediately spins up camera drivers, audio resampling pipelines, SQLite databases, and cryptography ratchets, the operating system's battery monitor will terminate the process within milliseconds.&lt;/p&gt;

&lt;p&gt;Spec 01 mandates an explicit &lt;strong&gt;Extension Lifecycle State Machine&lt;/strong&gt; combined with &lt;strong&gt;Lazy Extension Opening&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+--------------+        Peer Advertisement        +--------------+
|  Registered  | -------------------------------&amp;gt; |  Advertised  |
+--------------+                                  +--------------+
                                                         |
                                                         | Core Negotiation
                                                         v
+--------------+         Close Signal             +--------------+
|    Closed    | &amp;lt;------------------------------- |  Negotiated  |
+--------------+                                  +--------------+
       ^                                                 |
       |                                                 | User Triggers Feature
       |                                                 | (OPEN_EXTENSION)
       |                                                 v
+--------------+        Unrecoverable Fault       +--------------+
|   Closing    | &amp;lt;------------------------------- |   Active     |
+--------------+                                  +--------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  8.1 The Power of Dormant Negotiation
&lt;/h3&gt;

&lt;p&gt;Under Spec 01, negotiating an extension during the initial handshake &lt;strong&gt;does not initialize that extension&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Consider this real-world scenario:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Two SIAR nodes pair over BLE. They negotiate support for:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;org.siar.comm/messaging/1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;org.siar.comm/files/1&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;org.siar.media/calls/1&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;The core session enters the &lt;code&gt;SessionEstablished&lt;/code&gt; state.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;messaging&lt;/code&gt; extension transitions to &lt;code&gt;Active&lt;/code&gt; because text messaging is the primary interactive service.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;files&lt;/code&gt; and &lt;code&gt;calls&lt;/code&gt; extensions remain in the &lt;code&gt;Negotiated&lt;/code&gt; (dormant) state.

&lt;ul&gt;
&lt;li&gt;Zero file transfer threads are spawned.&lt;/li&gt;
&lt;li&gt;Zero audio DSP pipelines or Opus codecs are allocated in memory.&lt;/li&gt;
&lt;li&gt;Zero storage handles are opened.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Only when a user taps "Send 50MB PDF" or "Call Contact" does the runtime transmit a lightweight &lt;code&gt;ExtensionOpen&lt;/code&gt; control frame across the wire. Both peers transition that specific extension from &lt;code&gt;Negotiated&lt;/code&gt; to &lt;code&gt;Active&lt;/code&gt;, spin up the necessary machinery, and begin data exchange. When the transfer completes or the call ends, an &lt;code&gt;ExtensionClose&lt;/code&gt; frame returns the extension to dormant status, releasing system buffers and allowing mobile CPUs to drop back into deep sleep.&lt;/p&gt;

&lt;h3&gt;
  
  
  8.2 Graceful vs. Abrupt Shutdown Semantics
&lt;/h3&gt;

&lt;p&gt;Mobile and mesh nodes do not live in polite data centers. A user walks out of Bluetooth range, a battery dies, or an Android task killer strikes. The protocol must guarantee data integrity under sudden disconnection.&lt;/p&gt;

&lt;p&gt;Spec 01 divides shutdown into two cleanly separated pipelines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;GRACEFUL_SHUTDOWN_STEPS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s"&gt;"stop_accepting_new_work"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"flush_outbox_buffers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"persist_session_state"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"send_close_frame"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"release_network_handles"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;const&lt;/span&gt; &lt;span class="n"&gt;ABRUPT_SHUTDOWN_STEPS&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s"&gt;"detect_transport_drop"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"mark_in_flight_operations_recoverable"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"persist_resumable_byte_offsets"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s"&gt;"release_transient_buffers"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By distinguishing graceful flushing from abrupt failure handling, SIAR guarantees that a sudden radio disconnect never leaves SQLite state corrupted or partial file chunks orphaned without resumption markers.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. Cross-Subsystem Integration: Grounding Spec 01 in the Real World
&lt;/h2&gt;

&lt;p&gt;While Spec 01 is implemented cleanly as a standalone crate (&lt;code&gt;crates/siar-protocol-ext&lt;/code&gt;), its true architectural brilliance emerges when you observe how it seamlessly integrates with the rest of the SIAR platform specifications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+------------------------------------------------------------------------------------+
|                         SIAR System Specifications Matrix                          |
+------------------------------------------------------------------------------------+
| Spec 01: Protocol Extension System (Foundation)                                    |
|   |---&amp;gt; Spec 02: Multi-Device Identity   ===&amp;gt; Authenticated Identity Binding       |
|   |---&amp;gt; Spec 03: Transport Routing       ===&amp;gt; DeliveryClass-based link selection   |
|   |---&amp;gt; Spec 04/06: Offline Event Log/DTN===&amp;gt; Store-Carry-Forward persistence      |
|   |---&amp;gt; Spec 08: Resource Limits         ===&amp;gt; Per-peer memory &amp;amp; quota enforcement   |
|   |---&amp;gt; Spec 16/20: Headless &amp;amp; Embedded  ===&amp;gt; Zero-UI headless repeater binaries   |
|   |---&amp;gt; Spec 19: C-ABI / FFI             ===&amp;gt; JNI bindings to Android Kotlin UI    |
+------------------------------------------------------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let us examine these cross-cutting connections in technical detail.&lt;/p&gt;

&lt;h3&gt;
  
  
  9.1 Transport Neutrality &amp;amp; Multipath Routing (Specs 03 &amp;amp; 12)
&lt;/h3&gt;

&lt;p&gt;A common mistake in modern P2P protocols is coupling application logic directly to transport primitives—such as assuming every node has an IP address, relying on libp2p multiaddrs, or hardcoding Iroh Node IDs into chat messages.&lt;/p&gt;

&lt;p&gt;Spec 01 strictly enforces &lt;strong&gt;Transport Neutrality&lt;/strong&gt;. Notice the signature of &lt;code&gt;RoutingRequirements&lt;/code&gt; declared by an extension operation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[derive(Debug,&lt;/span&gt; &lt;span class="nd"&gt;Clone,&lt;/span&gt; &lt;span class="nd"&gt;PartialEq,&lt;/span&gt; &lt;span class="nd"&gt;Eq)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;RoutingRequirements&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;delivery_class&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;DeliveryClass&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;max_age_seconds&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;u64&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;durable&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;allow_forwarding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;priority&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;TrafficPriority&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;#[derive(Debug,&lt;/span&gt; &lt;span class="nd"&gt;Clone,&lt;/span&gt; &lt;span class="nd"&gt;Copy,&lt;/span&gt; &lt;span class="nd"&gt;PartialEq,&lt;/span&gt; &lt;span class="nd"&gt;Eq)]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;enum&lt;/span&gt; &lt;span class="n"&gt;DeliveryClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;Realtime&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="c1"&gt;// VoIP audio, live typing indicators (Drop if delayed)&lt;/span&gt;
    &lt;span class="n"&gt;ReliableInteractive&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="c1"&gt;// 1:1 chat text, read receipts (Direct path preferred)&lt;/span&gt;
    &lt;span class="n"&gt;Durable&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="c1"&gt;// Group state updates, document sync (Must be acknowledged)&lt;/span&gt;
    &lt;span class="n"&gt;DelayTolerant&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;      &lt;span class="c1"&gt;// Disaster SOS, offline relay bundles (Store-Carry-Forward)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice what is missing: &lt;strong&gt;There are no IP addresses, port numbers, MAC addresses, or QUIC connection handles anywhere in this struct.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When an extension produces an operation, it merely declares its semantic intent: &lt;em&gt;"I need Durable delivery with Interactive priority."&lt;/em&gt; It passes this down to &lt;strong&gt;Spec 03 (Transport &amp;amp; Routing Policy Engine)&lt;/strong&gt; and &lt;strong&gt;Spec 12 (Multipath Networking)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The routing engine inspects the current physical links:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If a high-speed Iroh QUIC direct connection over Wi-Fi is active, it routes the bytes across QUIC stream multiplexers.&lt;/li&gt;
&lt;li&gt;If Wi-Fi drops and only a BLE link is alive, the routing engine automatically re-routes the operation across Bluetooth, fragmenting the frames into MTU-sized chunks without the extension ever realizing the underlying physical medium shifted.&lt;/li&gt;
&lt;li&gt;If all physical links drop, the routing engine routes &lt;code&gt;Durable&lt;/code&gt; and &lt;code&gt;DelayTolerant&lt;/code&gt; operations directly to the local disk outbox for later transmission.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  9.2 Delay-Tolerant Networking &amp;amp; Asynchronous Bundles (Specs 04 &amp;amp; 06)
&lt;/h3&gt;

&lt;p&gt;Traditional client-server protocols assume end-to-end synchronous connectivity: Client A connects to Server S, which connects to Client B. If Client B is offline, the message waits on Server S.&lt;/p&gt;

&lt;p&gt;In an off-grid disaster mesh, there is no Server S. Alice might be in a valley with no connectivity, while Bob is three kilometers away behind a mountain ridge.&lt;/p&gt;

&lt;p&gt;Spec 01 interfaces directly with &lt;strong&gt;Spec 04 (Offline Event Log)&lt;/strong&gt; and &lt;strong&gt;Spec 06 (DTN Store-Carry-Forward Architecture)&lt;/strong&gt;:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;When Alice sends a message, her local &lt;code&gt;messaging&lt;/code&gt; extension generates a standard wire payload.&lt;/li&gt;
&lt;li&gt;Because Bob is currently unreachable over real-time transports, the runtime encapsulates the negotiated extension frame into an encrypted &lt;strong&gt;DTN Bundle&lt;/strong&gt; (&lt;code&gt;crates/siar-dtn-bundle&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;A mobile emergency vehicle or a pedestrian with a battery-powered headless node walks past Alice. Alice's node opportunistically establishes a short-range Wi-Fi Aware link, completes a Spec 01 handshake, negotiates &lt;code&gt;dtn/1&lt;/code&gt;, and offloads the bundle.&lt;/li&gt;
&lt;li&gt;Two hours later, the vehicle drives into Bob's physical proximity. The node discovers Bob, executes a Spec 01 handshake, verifies Bob's cryptographic identity, and transfers the bundle.&lt;/li&gt;
&lt;li&gt;Bob's node unpacks the DTN bundle, hands the inner frame directly to his local &lt;code&gt;messaging/1&lt;/code&gt; extension handler, and the message appears in his timeline as if they were directly connected.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Spec 01's separation of wire framing from immediate session lifetime makes asynchronous store-carry-forward networking a native capability rather than an afterthought.&lt;/p&gt;

&lt;h3&gt;
  
  
  9.3 Multi-Device Identity &amp;amp; MLS E2EE Boundaries (Specs 02 &amp;amp; 28)
&lt;/h3&gt;

&lt;p&gt;Under &lt;strong&gt;Spec 02 (Multi-Device Identity Architecture)&lt;/strong&gt; and &lt;strong&gt;Spec 28 (End-to-End Encryption &amp;amp; Key Management)&lt;/strong&gt;, identity in SIAR is strictly cryptographic. A user identity (&lt;code&gt;IdentityKey&lt;/code&gt;) is an Ed25519 signing key that anchors a dynamic group of individual &lt;code&gt;DeviceIdentity&lt;/code&gt; instances (smartphones, laptops, field repeaters).&lt;/p&gt;

&lt;p&gt;Spec 01 connects to this identity layer through the &lt;code&gt;ExtensionContext&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;ExtensionContext&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;peer_identity&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;PeerIdentity&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;     &lt;span class="c1"&gt;// 32-byte verified public key&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;session_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;SessionId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;           &lt;span class="c1"&gt;// Ephemeral session entropy&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;security_level&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;SecurityPolicy&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;  &lt;span class="c1"&gt;// Cleartext, Transport-Encrypted, or E2EE&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Extensions declare their required security invariants in their &lt;code&gt;ExtensionDescriptor&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;SecurityRequirements&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;authenticated_peer&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;       &lt;span class="c1"&gt;// Must prove possession of Ed25519 key&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;e2ee_required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;            &lt;span class="c1"&gt;// Must be encapsulated in MLS payload&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;authorization_required&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;   &lt;span class="c1"&gt;// Must satisfy local contact whitelist&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;allow_anonymous&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;          &lt;span class="c1"&gt;// Permitted for public emergency SOS&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For standard messaging, &lt;code&gt;e2ee_required&lt;/code&gt; is set to &lt;code&gt;true&lt;/code&gt;. The core protocol ensures that cleartext message frames cannot be dispatched across unencrypted sessions. Conversely, for &lt;code&gt;emergency/1&lt;/code&gt; broadcast beacons, &lt;code&gt;allow_anonymous&lt;/code&gt; is permitted so that unidentified survivors can broadcast distress signals across the mesh to any listening node.&lt;/p&gt;

&lt;h3&gt;
  
  
  9.4 Headless Daemons &amp;amp; Embedded Linux Repeaters (Specs 16 &amp;amp; 20)
&lt;/h3&gt;

&lt;p&gt;One of the greatest triumphs of Spec 01 is how it enables heterogeneous binary distributions. In the SIAR codebase, Cargo feature flags cleanly decouple crates:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight toml"&gt;&lt;code&gt;&lt;span class="c"&gt;# In siar Cargo workspace&lt;/span&gt;
&lt;span class="nn"&gt;[features]&lt;/span&gt;
&lt;span class="py"&gt;default&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"messaging"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"files"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"desktop-ui"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="py"&gt;headless-relay&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s"&gt;"siar-protocol-ext"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"siar-dtn"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s"&gt;"siar-transport-ble"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When compiling the &lt;strong&gt;Headless Emergency Repeater Daemon&lt;/strong&gt; (&lt;code&gt;siar-emergency-node&lt;/code&gt;) for a 32-bit MIPS or ARM embedded router with 16 megabytes of RAM:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We compile &lt;code&gt;siar-protocol-ext&lt;/code&gt; with only &lt;code&gt;dtn&lt;/code&gt; and &lt;code&gt;emergency&lt;/code&gt; extensions enabled.&lt;/li&gt;
&lt;li&gt;The entire Dioxus desktop UI engine, Jetpack Compose Android bindings, Opus audio resampling libraries, AV1 video decoders, and user contact management databases are stripped completely from the compiled binary.&lt;/li&gt;
&lt;li&gt;The resulting daemon compiles to a lean 4 MB ELF executable that boots in 120 milliseconds, uses 9 megabytes of RSS RAM, and can run continuously for three weeks on a small 12-volt solar panel and motorcycle battery.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Because Spec 01 uses typed descriptors and clean runtime registries rather than static central enums, the headless repeater participates in the exact same mesh sessions as high-end Android flagships, happily forwarding encrypted DTN packets and routing SOS beacons without missing a beat.&lt;/p&gt;




&lt;h2&gt;
  
  
  10. Rust Implementation Deep-Dive: A Tour of &lt;code&gt;siar-protocol-ext&lt;/code&gt;
&lt;/h2&gt;

&lt;p&gt;To appreciate how clean architecture translates into concrete systems code, let us look inside the actual &lt;code&gt;crates/siar-protocol-ext&lt;/code&gt; implementation.&lt;/p&gt;

&lt;h3&gt;
  
  
  10.1 The Extension Descriptor
&lt;/h3&gt;

&lt;p&gt;Every extension self-describes its capabilities, resource limits, and security constraints through an immutable descriptor:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;ExtensionDescriptor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ProtocolId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;requirement&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ExtensionRequirement&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;supported_capabilities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilitySet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;required_capabilities&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilitySet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;limits&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ExtensionLimits&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;security&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;SecurityRequirements&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="n"&gt;stability&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;ExtensionStability&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the crucial distinction between &lt;code&gt;supported_capabilities&lt;/code&gt; (everything this binary knows how to do) and &lt;code&gt;required_capabilities&lt;/code&gt; (the baseline subset without which this extension refuses to run). This distinction allows a single protocol version to span multiple hardware tiers.&lt;/p&gt;

&lt;h3&gt;
  
  
  10.2 The Protocol Extension Trait
&lt;/h3&gt;

&lt;p&gt;The interface between the core runtime multiplexer and an extension is governed by the &lt;code&gt;ProtocolExtension&lt;/code&gt; trait:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[async_trait::async_trait]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;trait&lt;/span&gt; &lt;span class="n"&gt;ProtocolExtension&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Send&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;Sync&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;'static&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/// Return the static descriptor for negotiation&lt;/span&gt;
    &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;descriptor&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;ExtensionDescriptor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="cd"&gt;/// Called when the session establishes and this extension is negotiated&lt;/span&gt;
    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;on_negotiated&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;ExtensionContext&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;negotiated_caps&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;CapabilitySet&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nb"&gt;Box&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;dyn&lt;/span&gt; &lt;span class="n"&gt;ExtensionHandler&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;ExtensionError&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nd"&gt;#[async_trait::async_trait]&lt;/span&gt;
&lt;span class="k"&gt;pub&lt;/span&gt; &lt;span class="k"&gt;trait&lt;/span&gt; &lt;span class="n"&gt;ExtensionHandler&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Send&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;Sync&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="k"&gt;'static&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/// Handle an incoming validated data frame&lt;/span&gt;
    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;handle_frame&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;frame_type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;payload&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;ExtensionError&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="cd"&gt;/// Poll for outgoing frames to send across the multiplexer&lt;/span&gt;
    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;poll_outgoing&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Option&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="n"&gt;OutgoingFrame&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="cd"&gt;/// Lifecycle transition: shutdown signal&lt;/span&gt;
    &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;shutdown&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="k"&gt;mut&lt;/span&gt; &lt;span class="k"&gt;self&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;-&amp;gt;&lt;/span&gt; &lt;span class="nb"&gt;Result&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="n"&gt;ExtensionError&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice how &lt;code&gt;ExtensionHandler&lt;/code&gt; receives a pre-validated &lt;code&gt;&amp;amp;[u8]&lt;/code&gt; slice. It never parses raw wire frame headers, never checks remote length bounds, and never manages TCP or QUIC socket streams. All framing safety, length validation, and multiplexing are handled upstream by the core protocol engine before the handler is invoked.&lt;/p&gt;

&lt;h3&gt;
  
  
  10.3 The Runtime Builder Pattern
&lt;/h3&gt;

&lt;p&gt;Assembling a node runtime is completely decoupled and declarative:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;runtime&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nn"&gt;CommunicationRuntime&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;builder&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nf"&gt;.with_identity&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;local_device_identity&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.with_transport&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;iroh_transport&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nf"&gt;.register_extension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;MessagingExtension&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;messaging_config&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;.register_extension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;FileTransferExtension&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;file_config&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;.register_extension&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nn"&gt;EmergencyAlertExtension&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;new&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;emergency_config&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
    &lt;span class="nf"&gt;.build&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="k"&gt;.await&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you are writing a dedicated CLI backup tool, you simply omit &lt;code&gt;MessagingExtension&lt;/code&gt; and &lt;code&gt;EmergencyAlertExtension&lt;/code&gt;. The compiler will not include them in the binary, and the node will seamlessly negotiate only file capabilities when pairing with other peers.&lt;/p&gt;




&lt;h2&gt;
  
  
  11. Verification, Property Testing, and Golden Wire Invariants
&lt;/h2&gt;

&lt;p&gt;Software engineering is what happens when code must survive years of maintenance by dozens of developers across multiple release cycles. How do we guarantee that an optimization in 2027 does not break compatibility with a field node deployed in 2026?&lt;/p&gt;

&lt;p&gt;Spec 01 establishes a rigorous three-tiered verification discipline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;+--------------------------------------------------------------------------+
|                  Verification &amp;amp; Testing Architecture                     |
+--------------------------------------------------------------------------+
|  Tier 1: Unit &amp;amp; Matrix Compatibility Tests                               |
|          Verifies that v1.0 ↔ v1.0, v1.0 ↔ v1.2, and subset ↔ superset   |
|          negotiations produce mathematically exact CapabilitySets.       |
|                                                                          |
|  Tier 2: Golden Wire Invariant Tests                                     |
|          Serializes concrete Rust types and compares against raw byte    |
|          arrays byte-for-byte to prevent unintended wire layout shifts.  |
|                                                                          |
|  Tier 3: Hostile Input &amp;amp; Property-Based Fuzzing                          |
|          Injects random bit flips, truncated headers, and hostile        |
|          lengths (0xFFFFFFFF) to mathematically prove panic-freedom.     |
+--------------------------------------------------------------------------+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  11.1 Golden Wire Invariant Tests
&lt;/h3&gt;

&lt;p&gt;In &lt;code&gt;crates/siar-protocol-ext/src/framing.rs&lt;/code&gt;, we maintain byte-level golden tests. Here is an actual test case verifying header serialization:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[test]&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;test_golden_frame_header_layout&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;FrameHeader&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="n"&gt;frame_length&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;1024&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;session_extension_id&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;SessionLocalExtensionId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;7&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="n"&gt;frame_type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0x01&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;flags&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;0x80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;};&lt;/span&gt;

    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;encoded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;encode_frame_header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Exact byte-by-byte layout expectation:&lt;/span&gt;
    &lt;span class="c1"&gt;// [0..4]  Length = 1024 (0x00000400 in big-endian)&lt;/span&gt;
    &lt;span class="c1"&gt;// [4..6]  SessionLocalExtensionId = 7 (0x0007 in big-endian)&lt;/span&gt;
    &lt;span class="c1"&gt;// [6]     FrameType = 1&lt;/span&gt;
    &lt;span class="c1"&gt;// [7]     Flags = 128 (0x80)&lt;/span&gt;
    &lt;span class="c1"&gt;// [8..10] Reserved bytes (0x0000)&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;expected_bytes&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nb"&gt;u8&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="mi"&gt;0x00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0x00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0x04&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0x00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// Length&lt;/span&gt;
        &lt;span class="mi"&gt;0x00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0x07&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;             &lt;span class="c1"&gt;// Extension ID&lt;/span&gt;
        &lt;span class="mi"&gt;0x01&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                   &lt;span class="c1"&gt;// Type&lt;/span&gt;
        &lt;span class="mi"&gt;0x80&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;                   &lt;span class="c1"&gt;// Flags&lt;/span&gt;
        &lt;span class="mi"&gt;0x00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;0x00&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;             &lt;span class="c1"&gt;// Reserved&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="nd"&gt;assert_eq!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;encoded&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;expected_bytes&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// Verify round-trip decode&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;decoded&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;parse_frame_header&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;amp;&lt;/span&gt;&lt;span class="n"&gt;encoded&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="nf"&gt;.expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"Decode must succeed"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;assert_eq!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;decoded&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;header&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If an engineer inadvertently changes a field type from &lt;code&gt;u16&lt;/code&gt; to &lt;code&gt;u32&lt;/code&gt;, or alters endianness, the golden test immediately fails in CI with an exact diff of the violated byte indices.&lt;/p&gt;

&lt;h3&gt;
  
  
  11.2 The 16-Item Definition of Done Self-Audit
&lt;/h3&gt;

&lt;p&gt;Spec 01 concludes with an explicit &lt;strong&gt;Definition of Done (DoD)&lt;/strong&gt; checklist containing sixteen rigorous criteria. In &lt;code&gt;crates/siar-protocol-ext/src/definition_of_done.rs&lt;/code&gt;, we turned this checklist into a machine-checkable Rust test that audits the crate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="nd"&gt;#[test]&lt;/span&gt;
&lt;span class="k"&gt;fn&lt;/span&gt; &lt;span class="nf"&gt;test_definition_of_done_audit&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;let&lt;/span&gt; &lt;span class="n"&gt;audit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;audit_part_01_definition_of_done&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="c1"&gt;// We enforce that every single DoD item is explicitly accounted for:&lt;/span&gt;
    &lt;span class="nd"&gt;assert_eq!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audit&lt;/span&gt;&lt;span class="nf"&gt;.total_items&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="c1"&gt;// An audit that cannot report honest gaps is useless theater.&lt;/span&gt;
    &lt;span class="c1"&gt;// We assert that the 4 known architectural follow-ups are honestly tracked!&lt;/span&gt;
    &lt;span class="nd"&gt;assert_eq!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audit&lt;/span&gt;&lt;span class="nf"&gt;.satisfied_count&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="mi"&gt;12&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nd"&gt;assert_eq!&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;audit&lt;/span&gt;&lt;span class="nf"&gt;.honest_gaps_count&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By embedding the specification's completion criteria directly into the executable test suite, we ensure that technical debt cannot be swept under the rug.&lt;/p&gt;




&lt;h2&gt;
  
  
  12. Ten Golden Rules for Distributed Protocol Designers
&lt;/h2&gt;

&lt;p&gt;Drawing from the design and implementation of SIAR Spec 01, here are ten battle-tested rules for systems engineers architecting P2P, local-first, or decentralized protocols:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Kill the Central Message Enum Early&lt;/strong&gt;: Once your protocol spans more than three distinct features, replace your flat &lt;code&gt;enum Message&lt;/code&gt; with independently versioned extension channels. You will save yourself months of refactoring later.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never Trust Remote Length Fields&lt;/strong&gt;: Always parse a fixed-size header first, validate the claimed length against both global and subsystem-specific limits, and only then allocate memory buffers.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Represent Capabilities as Mathematical Sets&lt;/strong&gt;: Do not rely on version numbers to imply feature availability. Use explicit, compact capability IDs and compute $\text{Local} \cap \text{Remote}$ during the handshake.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enforce Hard Memory Backpressure&lt;/strong&gt;: Queues must be strictly bounded in both item count and aggregate byte capacity. When full, return the item to the caller to force upstream throttling.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Separate Domain Types from Wire Schemas&lt;/strong&gt;: Never derive serialization directly on internal business models or database entities. Keep your wire schemas isolated and versioned.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ban &lt;code&gt;usize&lt;/code&gt; on the Wire&lt;/strong&gt;: Always use explicit, fixed-width integers (&lt;code&gt;u8&lt;/code&gt;, &lt;code&gt;u16&lt;/code&gt;, &lt;code&gt;u32&lt;/code&gt;, &lt;code&gt;u64&lt;/code&gt;) with documented big-endian byte order to guarantee interoperability across 32-bit and 64-bit platforms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Schedule Traffic with Fairness, Not Just Priority&lt;/strong&gt;: Pure priority queues lead to bulk traffic starvation under sustained load. Implement weighted round-robin scheduling with bounded emergency overrides.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Never Let Optional Extensions Break Sessions&lt;/strong&gt;: If a peer advertises an unknown optional extension, ignore it cleanly. Forward compatibility is the lifeblood of decentralized systems.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Negotiate Lazily for Mobile Runtimes&lt;/strong&gt;: Capability agreement must not trigger heavy subsystem initialization. Keep extensions dormant until explicitly opened by user action.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintain Byte-Level Golden Tests in CI&lt;/strong&gt;: Never rely on unit tests alone. Test your serializers against hardcoded byte arrays to catch unintended wire format drift before it hits production.&lt;/li&gt;
&lt;/ol&gt;




&lt;h2&gt;
  
  
  13. Conclusion &amp;amp; Next Steps in the Series
&lt;/h2&gt;

&lt;p&gt;Decentralized protocol design is often treated as an exercise in cryptography and transport plumbing. But as systems grow, the greatest risks to longevity are not broken ciphers—they are architectural rot, brittle coupling, unbounded memory consumption, and backwards-incompatible wire upgrades.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Spec 01: Protocol Extension System Architecture&lt;/strong&gt; demonstrates that you do not have to compromise between rapid feature iteration and bulletproof stability. By treating protocol capabilities as independently versioned, set-theoretically negotiated extensions governed by strict backpressure and memory boundaries, SIAR provides a robust foundation for resilient, zero-infrastructure communications.&lt;/p&gt;

&lt;p&gt;In &lt;strong&gt;Part 2 of this series&lt;/strong&gt;, we will dive into &lt;strong&gt;Spec 02: Multi-Device Identity Architecture&lt;/strong&gt;, examining how SIAR synchronizes cryptographic state, manages device revocations, and anchors autonomous decentralized trust across phones, laptops, and field repeaters without relying on a central server.&lt;/p&gt;




&lt;h3&gt;
  
  
  Resources &amp;amp; Further Exploration
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;🌐 &lt;strong&gt;&lt;a href="https://irshadali5.github.io/siar-site/" rel="noopener noreferrer"&gt;Official SIAR Website&lt;/a&gt;&lt;/strong&gt; — Architecture portals, downloads, and interactive labs.&lt;/li&gt;
&lt;li&gt;📚 &lt;strong&gt;&lt;a&gt;SIAR Technical Wiki (26 Chapters)&lt;/a&gt;&lt;/strong&gt; — Comprehensive deep-dive into the entire system stack.&lt;/li&gt;
&lt;li&gt;📑 &lt;strong&gt;&lt;a&gt;System Architecture Specifications (sys-arch)&lt;/a&gt;&lt;/strong&gt; — All 33 core specifications and 27 UI/UX architecture documents.&lt;/li&gt;
&lt;li&gt;📦 &lt;strong&gt;&lt;a&gt;crates/siar-protocol-ext&lt;/a&gt;&lt;/strong&gt; — Pure-Rust reference implementation of Spec 01.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Have thoughts, critiques, or war stories from your own distributed systems? Drop a comment below or join the discussion on our developer hub!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>backend</category>
      <category>rust</category>
      <category>software</category>
    </item>
  </channel>
</rss>
