How zaygal/zaycomm works
Purpose and Entry Surface
Zaycomm is a TypeScript reference implementation of a secure, decentralized, delay-tolerant mesh messaging protocol. It is protocol infrastructure rather than a web application: messages remain end-to-end encrypted while moving across untrusted relays and intermittent transports. No executable entry point is visible in the tree; the public integration surface is likely the exported modules under src/, with package behavior defined by package.json.
Identity and Cryptographic Sessions
Long-lived identity material, device identity operations, and verification live in src/identity/identity.ts and src/crypto/keys.ts. Session establishment and ongoing forward-secret messaging are separated into src/crypto/handshake.ts and src/crypto/ratchet.ts. This boundary is security-critical: endpoints own private keys and ratchet state; relays should only handle opaque envelopes.
Message Construction and Content Types
Application payloads are represented by src/message/message.ts, with file-oriented payload/chunk handling in src/message/file.ts. These feed encrypted session payloads and can support extensible types such as broadcast. src/broadcast/broadcast.ts is the distinct broadcast path, likely applying different dissemination semantics from ordinary destination-directed messages.
Envelope and Fragmentation Boundary
src/envelope/envelope.ts defines the transportable protocol unit: relay-visible routing/control metadata plus a sealed payload for the recipient. src/envelope/fragment.ts splits and reassembles envelopes for constrained links. This is the key boundary between routing/transport behavior and cryptographic confidentiality: relays validate, deduplicate, forward, or queue envelopes without decrypting content.
Routing and Store-Carry-Forward
src/routing/routing.ts selects forwarding behavior across direct, multi-hop, and disconnected contacts. It should use message identifiers, TTL/freshness, relay knowledge, and bounded replication to avoid loops and uncontrolled flooding. When no suitable next hop exists, control passes to src/storage/store.ts, which persists local state and encrypted relay queues until contact, expiry, acknowledgment, or eviction.
Transport Abstraction
src/transport/transport.ts is the pluggable link boundary. Transports discover reachable peers and exchange bounded opaque frames; higher layers should not depend on BLE, Wi-Fi, Internet, radio, or physical-carry specifics. This permits gateway/synchronization behavior without requiring central infrastructure and makes a new transport adapter an additive change rather than a protocol rewrite.
Primary Control Flow and Trust Boundaries
Outbound flow is: construct message (src/message/message.ts) → establish/use crypto session (src/crypto/handshake.ts, src/crypto/ratchet.ts) → seal into envelope (src/envelope/envelope.ts) → fragment if required (src/envelope/fragment.ts) → choose next hop (src/routing/routing.ts) → transmit (src/transport/transport.ts) or queue (src/storage/store.ts). At relay nodes, only envelope, routing, transport, and queued ciphertext are processed. At the destination, fragments are reassembled, the envelope is decrypted/authenticated through session state, and the payload is delivered to message or broadcast handling.
Runtime and External Dependencies
The codebase is Node/TypeScript-oriented, indicated by package.json and package-lock.json; no deployed service, database, browser runtime, or mandatory external infrastructure is present in the repository tree. Internet-connected peers are conceptually optional gateways, not protocol authorities. Shared low-level behavior is centralized in src/util.ts.
Main entry points: envelope.ts Sealed envelope · routing.ts Forwarding policy · ratchet.ts Forward-secret ratchet · fragment.ts Fragmentation
Components 15
Endpoint security
Private identity and session state stay at endpoints.
- Device identity
src/identity/identity.ts - Key operations
src/crypto/keys.ts - Session handshake
src/crypto/handshake.ts - Forward-secret ratchet · Encrypts and authenticates ongoing session payloads.
src/crypto/ratchet.ts - Destination endpoint · Reassembles, authenticates, decrypts, and delivers payloads.
Payloads
- Application message
src/message/message.ts - File payloads
src/message/file.ts - Broadcast handling · Uses semantics distinct from destination-directed delivery.
src/broadcast/broadcast.ts
Opaque relay pipeline
Relays route and store sealed envelopes without decrypting them.
- Sealed envelope · Combines relay-visible metadata with recipient-only sealed content.
src/envelope/envelope.ts - Fragmentation · Splits and reassembles envelopes for constrained links.
src/envelope/fragment.ts - Forwarding policy · Selects direct, multi-hop, or deferred forwarding.
src/routing/routing.ts - Transport abstraction · Exchanges bounded opaque frames over pluggable transports.
src/transport/transport.ts - Store-carry-forward · Persists local state and queued ciphertext until delivery or eviction.
src/storage/store.ts
Other components
- Package surface · Defines package behavior and exported integration surface.
package.json - Shared utilities
src/util.ts
Connections 22
- Package surface → Device identity: exports
- Device identity → Key operations: uses
- Key operations → Session handshake: establishes identity-backed session
- Session handshake → Forward-secret ratchet: initializes
- Application message → File payloads: supports
- Application message → Forward-secret ratchet: payload to encrypt
- File payloads → Forward-secret ratchet: payload to encrypt
- Forward-secret ratchet → Sealed envelope: sealed payload
- Broadcast handling → Sealed envelope: dissemination envelope
- Sealed envelope → Fragmentation: split when needed
- Fragmentation → Forwarding policy: bounded frames
- Forwarding policy → Transport abstraction: next-hop transmit
- Forwarding policy → Store-carry-forward: defer without contact
- Store-carry-forward → Forwarding policy: retry on contact
- Transport abstraction → Fragmentation: received frames
- Fragmentation → Sealed envelope: reassembled envelope
- Sealed envelope → Destination endpoint: authenticated sealed content
- Destination endpoint → Forward-secret ratchet: decrypts via session state
- Destination endpoint → Application message: delivers directed payload
- Destination endpoint → Broadcast handling: delivers broadcast payload
- Shared utilities → Sealed envelope: shared low-level support
- Shared utilities → Forwarding policy: shared low-level support