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
DeRecProtocolBuilder— typestate builder that returns a configuredDeRecProtocolonce 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, andwith_config(DeRecProtocolConfig)applies a whole configuration loaded from a file or user record (every field optional; later setters override it field by field).The five store traits —
DeRecChannelStore,DeRecShareStore,DeRecSecretStore,DeRecUserSecretStore, andDeRecStateStore. 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-erasedFutures) so they fit any executor — sync backends just returnBox::pin(std::future::ready(...)).The
DeRecTransporttrait — a single asyncsend(endpoints, bytes)callback the library calls whenever it needs to deliver bytes to a peer.endpointsis every endpoint that peer advertised, in its order, never empty; deliver to the first one that works and stop. Endpoints arehttps://,http://,grpcs://orgrpc://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 implementSendOne(deliver to one endpoint) and wrap it inSequentialFailover, which handles the try-in-order bookkeeping. Delivery is push-only: replies leave throughsendtoo, so every participant needs a reachable endpoint — see Transports for the model and the recommended HTTP conventions.The event loop — when bytes arrive on your transport, call
protocol.process(&envelope_bytes).await. You get back aVec<DeRecEvent>describing what happened (PairingCompleted,ShareStored,SecretRecovered,ActionRequired { action }, etc.). React accordingly, andacceptorrejectanyActionRequiredto complete the round-trip. A request that arrived on an authenticated channel and failed is not an error: it is aRequestFailedevent. Withauto_respond_on_failureoff (the default) nothing was sent, and the event carries a token you pass toreject— once — or the sender is never answered and eventually times out. Whenprocessitself fails, the returnedProcessErrorstill carries events inevents; handle them like a successful call's, then handle the error.DeRecFlowfor outbound actions — initiate any protocol flow withprotocol.start(DeRecFlow::Pairing { ... }),protocol.start(DeRecFlow::ProtectSecret { ... })(which takes the secrets, aweightsmap giving each Helper its number of subshares, and an optionalthreshold),protocol.start(DeRecFlow::RecoverSecret { ... }), and so on. The orchestrator sends the outbound envelopes through yourDeRecTransport.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 insideprocessandtick. Callprotocol.tick().awaiton a timer and handle the events it returns. See Timeouts andtick().
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
Dev environment setup — toolchain, dependency, transport endpoints, local build.
Repository Map — where each piece lives in
lib-derec.Choose your integration path — orchestrator vs primitives, language, role.
Minimal integration example — runnable Owner-plus-two-Helpers pairing and protect-secret round.
Concepts / Replicas — how the Owner identity extends across multiple devices, and what changes at the integration level when replicas are in play.
Rust SDK reference — flow-by-flow API documentation.
Last updated