For the complete documentation index, see llms.txt. This page is also available as Markdown.

Quickstart

This page is a five-minute primer for developers who have already read the Overview and want to see what wiring up the DeRec library looks like in code.

What you are actually integrating

The derec-library crate gives you an orchestrator — DeRecProtocol — that drives every protocol flow (pairing, sharing, verification, discovery, recovery, unpairing, update-channel-info, and the replica flows ReplicaDiscovery and UnpairReplica) on top of storage and transport callbacks you supply. You implement five small storage traits and one transport callback; the library handles wire framing, encryption, replay protection, and per-flow state — persisted through a state store you supply, so the orchestrator itself stays stateless — plus, when the application uses the replica feature, automatic Secret synchronization across every device under the same Owner identity. Your application reacts to typed events.

The library also exposes a lower altitude — the primitives layer — but the orchestrator is the recommended default. See Primitives and Orchestrator for when you would reach for the lower tier.

Six moving pieces

  1. DeRecProtocolBuilder — typestate builder that returns a configured DeRecProtocol once every required slot is filled. Setters can be called in any order; build() is only callable once the type system is satisfied. with_stores(DeRecStores { .. }) sets all five stores in one call, and with_config(DeRecProtocolConfig) applies a whole configuration loaded from a file or user record (every field optional; later setters override it field by field).

  2. The five store traits — DeRecChannelStore, DeRecShareStore, DeRecSecretStore, DeRecUserSecretStore, and DeRecStateStore. Application-supplied storage; the last one holds the orchestrator's in-flight protocol state (outstanding verification challenges, in-progress recovery, pending unpairs, the active sharing round) so a stateless deployment survives process restarts and load-balancer churn. All five are async-shaped (they return type-erased Futures) so they fit any executor — sync backends just return Box::pin(std::future::ready(...)).

  3. The DeRecTransport trait — a single async send(endpoints, bytes) callback the library calls whenever it needs to deliver bytes to a peer. endpoints is every endpoint that peer advertised, in its order, never empty; deliver to the first one that works and stop. Endpoints are https://, http://, grpcs:// or grpc:// URIs, and the library opens no socket: you implement delivery with whatever client you use (HTTPS, gRPC, an in-memory queue for tests). The usual shape is to implement SendOne (deliver to one endpoint) and wrap it in SequentialFailover, which handles the try-in-order bookkeeping. Delivery is push-only: replies leave through send too, so every participant needs a reachable endpoint — see Transports for the model and the recommended HTTP conventions.

  4. The event loop — when bytes arrive on your transport, call protocol.process(&envelope_bytes).await. You get back a Vec<DeRecEvent> describing what happened (PairingCompleted, ShareStored, SecretRecovered, ActionRequired { action }, etc.). React accordingly, and accept or reject any ActionRequired to complete the round-trip. A request that arrived on an authenticated channel and failed is not an error: it is a RequestFailed event. With auto_respond_on_failure off (the default) nothing was sent, and the event carries a token you pass to reject — once — or the sender is never answered and eventually times out. When process itself fails, the returned ProcessError still carries events in events; handle them like a successful call's, then handle the error.

  5. DeRecFlow for outbound actions — initiate any protocol flow with protocol.start(DeRecFlow::Pairing { ... }), protocol.start(DeRecFlow::ProtectSecret { ... }) (which takes the secrets, a weights map giving each Helper its number of subshares, and an optional threshold), protocol.start(DeRecFlow::RecoverSecret { ... }), and so on. The orchestrator sends the outbound envelopes through your DeRecTransport.

  6. tick() for time — the library runs no clock of its own. Timeouts (a sharing round whose Helpers went silent, an unacknowledged unpair, a pairing that never completed) advance only inside process and tick. Call protocol.tick().await on a timer and handle the events it returns. See Timeouts and tick().

The store and transport traits are async by design — even sync backends return a Future. This is how the same library targets native async runtimes (Tokio), C-ABI hosts (.NET, Go, React Native), and WASM (Node.js / Web) without forking the API surface.

Wiring it up

The example below shows the smallest meaningful DeRecProtocol instantiation: your stores and dialer (in their own modules), one process() call against an inbound envelope, and a tick(). Real stores live in smoke-tests/rust/src/protocol.rs — see Minimal integration example for the runnable end-to-end version, stores included.

Six of the seven with_* calls above are required for build() to type-check: every store and the transport (with_stores counts for all five stores). with_own_transports is checked at run time instead — build() is reachable without it, but it then fails with invalid_input for a missing or empty endpoint list, exactly as a threshold below 2 does. build() can also fail with a transport error for a malformed, plaintext, or duplicate-protocol endpoint. See Transport endpoints and plaintext connections.

That's the loop. Every flow — pairing, sharing, verification, recovery, the replica flows — drives through this same start / process / accept triangle, with tick keeping time.

Where to next

Last updated