wire-mesh-wire 0.1.0

Wire types and canonical CBOR codec for the wire-mesh protocol (spec/*.cddl), hand-written against RFC 8949 4.2 core deterministic encoding
Documentation
  • Coverage
  • 41.77%
    246 out of 589 items documented0 out of 178 items with examples
  • Size
  • Source code size: 378.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 7.2 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 3s Average build duration of successful builds.
  • all releases: 3s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • ExaDev/wire-mesh
    0 1 45
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • Mearman

rust/

The Rust implementation of wire-mesh: a Cargo workspace whose core crate mirrors the TypeScript core's generated/ports/adapters/domain split.

crates/
  wire-mesh-wire/              The CDDL model + CDE codec. One hand-written module per CDDL rule family
                               (identity, handshake, tokens, transport, management, streaming, exec,
                               data, discovery, frame, bulk, room, secure-channel, threshold, webrtc)
                               plus the CborValue/CanonicalMap DOM for every `any` and open-map
                               position. No async, crypto or serde dependencies.
  wire-mesh-core/              Ports (Transport, KeyValueStorage, Identity, Clock), full domain parity
                               (handshake negotiation, capability-token minting/verification/predicates,
                               RevocationView and persistent RevocationStore, capability.request and
                               capability.grant, RelayHub with AdvertExtensionPolicy and HubMailbox,
                               RelayClient and end-to-end secure channel, core/bulk resumable transfers,
                               core/data sync, coordinator election, peer-advert and GossipDirectory,
                               rooms/paths/rekeying, erasure coding and shard manifests, Session runtime
                               with reconnect), and adapters (MemoryStorage, atomic durable FsStorage,
                               Tokio TCP, mutual-TLS TlsTransport, WebSocket WsTransport, UDP multicast
                               LanDiscovery, clocks, Ed25519/ES256 NodeIdentity).
  wire-mesh-threshold/         FROST(Ed25519, SHA-512) threshold signing (RFC 9591) among a
                               person's own devices, wrapping the audited frost-ed25519 and
                               frost-core crates: distributed key generation, proactive resharing,
                               two-round signing, share envelopes, a nonce-store port, and
                               wire-driven coordinator and participant roles over manage-requests.
  wire-mesh-threshold-wasm/    WebAssembly bindings for wire-mesh-threshold, so the TypeScript core
                               holds a real FROST key share without reimplementing the
                               cryptography. Byte-oriented wrappers only; no domain logic.
  wire-mesh-conformance/       The conformance-check binary gating the frozen vectors in
                               ../../conformance/*.v1.json.

Codec guarantees

Every wire type implements minicbor Encode/Decode by hand (minicbor is pinned to an exact version because its 2.x trait shapes differ from the widely documented 0.2x series) with two invariants:

  • CDE by construction (RFC 8949 4.2 core deterministic encoding, the rules DAG-CBOR builds on): map keys are written in encoded-length-first-then-bytewise order, integer heads are minimal-length, lengths are always definite. Closed-key structs hard-code the order (pinned by the conformance vectors); open maps go through CanonicalMap; mixed typed-plus-tail maps through CdeMapBuilder, because an extension key can sort anywhere among the typed fields.
  • Strict decode: unknown keys, wrong arity, indefinite lengths, floats, tags, duplicate keys, unsorted keys, non-minimal integer/string/array/map heads, non-32-byte device-ids, bad enum literals, and trailing bytes are all rejected — matching what cbor2's cdeDecodeOptions enforces on the TypeScript side, so both implementations accept exactly the same byte strings and any input that decodes also re-encodes to identical bytes.

Running

cargo build --all-features
cargo test --all-features --locked
cargo clippy --all-targets --all-features -- -D warnings
cargo fmt --check
cargo run --bin conformance-check

The root justfile already dispatches the workspace checks (just build, just test, just lint, just conformance); just conformance runs this binary alongside the vector-generation gate in conformance/.

Publishing

Three workspace crates are publishable to crates.io in dependency order (wire-mesh-wire, wire-mesh-core, wire-mesh-threshold), while wire-mesh-threshold-wasm and wire-mesh-conformance stay workspace-private with publish = false. All publishable crates share [workspace.package].version and declare matching sibling path+version constraints so multi-crate packaging and cargo-deny (wildcards = "deny") succeed cleanly.

CI verifies packaging on every run in the crates job of .github/workflows/ci.yml using cargo metadata --locked --no-deps --format-version 1 and jq (checking that all publishable crates share [workspace.package].version and matching sibling path dependency constraints, and ordering them topologically), followed by cargo package --locked --list and cargo publish --locked --dry-run. Actual uploads run in publish-crates on refs/tags/v* pushes and manual workflow_dispatch runs using OIDC trusted publishing (rust-lang/crates-io-auth-action), querying https://index.crates.io with curl and jq so only versions not yet on crates.io are published in dependency order with cargo publish --locked. Because crates.io trusted publishing configures crates that already exist (or pending publishers), perform a one-time initial crates.io registration and first publish with an API token (or register a pending publisher) and configure each crate's trusted publisher for ExaDev/wire-mesh and ci.yml before publish-crates can upload releases automatically.

conformance-check proves every frozen vector in all 14 conformance/*.v1.json files two ways per vector: a typed decode, validate, re-encode and byte-compare loop (with a first-divergence hex diff on mismatch), and a reverse message-JSON to CborValue DOM to CDE encode to byte-compare loop that pins the {"hex": ...} byte-string convention and rejects non-integral JSON numbers rather than truncating them. For the three COSE vectors it additionally round-trips the nested protected headers and claims through the on-demand accessors, proving those re-encode identically too. Section checkers verify bulk, secure_channel (recomputing key schedules, sealing, hello verdicts, establish verdicts and open sequences) and handshake_scenarios, mint, coordinator_election, data_sync, file_storage (against FsStorage), room_params, gossip_directory and introspection, failing on any unread field or unaccounted vector file.

Known upstream quirk (flagged, worked around)

The frozen tokens.v1.json protected headers encode the RFC 9052 alg/kid labels as text keys "1"/"4" (bytes 0x61 0x31/0x61 0x34), not the CDDL's integer labels 1/4 (0x01/0x04) — a JS-object-key quirk from the vector generator. The wire crate accepts both forms on decode (HeaderLabel::Int vs HeaderLabel::Text), but only the integer form is canonical for emitted tokens: CoseTokenHeaders's typed alg/kid fields populate from integer labels and re-emit as integer labels, while a text form decodes into extra verbatim so byte-exact round-tripping still holds. The vector generator should eventually be fixed to emit true integer labels and re-frozen; worth doing before more implementations hard-code the quirk.

Scope and deferrals

wire-mesh-core now has full protocol and adapter parity with the TypeScript core across transport adapters (Tokio TcpTransport, mutual-TLS TlsTransport with pure-Rust P-256 X.509/PKCS#8 identities and DeviceId pinning, WsTransport for RFC 6455 ws:// and wss://, and feature-gated UDP IPv4 multicast LanDiscovery), storage (in-memory MemoryStorage and atomic durable FsStorage with temp-file staging, sync_all, rename and parent directory sync), handshake negotiation (version min plus order-independent domain intersection, retired core/federation rejected distinctly), capability tokens (COSE_Sign1 per RFC 9052 Sig_structure, self-certifying sha256(device-id) check, minting with narrowing/expiry-clamping, predicates evaluation, RevocationView and KeyValueStorage-backed RevocationStore persistence, plus capability.request and capability.grant primitives), gossiped peer-advert verification and GossipDirectory, RelayHub (with AdvertExtensionPolicy filtering, HubMailbox store-and-forward, uplink chaining and connection state export/restore), RelayClient and end-to-end secure_channel, core/bulk resumable SHA-256-verified transfers (BulkSender/BulkReceiver/SliceBulkSource/FileBulkSource/StoredTransferSource/SessionBulkLink), core/data sync, CoordinatorElection (term and lowest-device-id tiebreak), rooms (room_path, room_token_verification, room notices, group_key rekeying), erasure coding and shard manifests byte-identical with TypeScript, threshold signing (wire-mesh-threshold and wire-mesh-threshold-wasm), and the Session runtime (HandlerRegistry, semaphore-bounded manage dispatch, path.trace, topology.get, version.get, ReconnectPolicy and dial_with_reconnect). What remains schema-only or deferred:

  • Exec and streaming engines: core/exec (process spawning and PTY handling) and core/streaming (ack-seq + window credit-window enforcement) decode, encode and validate in wire-mesh-wire, with no runtime engine in either Rust or TypeScript.
  • DNS handle fetching and NAT hole-punching: handle-record verification and wire shapes exist (HandleClaims, HandleRecord), while live HTTPS fetching of /.well-known/wire-mesh/<local-part> and direct-path UDP/ICE hole-punching remain unimplemented (connections traverse RelayHub when not direct or discovered locally via LanDiscovery).
  • CDDL-to-Rust drift mitigation: there is no CDDL-to-Rust generator (cddl.js emits TypeScript/Zod only), so beyond the frozen vectors, drift is caught by the per-family unit tests derived from the CDDL text (key order, regex tiers over the registry's examples, arity, and unknown-key rejection). Vectors should be regenerated and this gate re-run whenever spec/*.cddl changes.