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) on top of storage and transport callbacks you supply. You implement four small storage traits and one transport callback; the library handles wire framing, encryption, replay protection, per-flow state, and — 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.
Five 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.The four store traits —
DeRecChannelStore,DeRecShareStore,DeRecSecretStore, andDeRecUserSecretStore. Application-supplied storage. All four 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(endpoint, bytes)callback the library calls whenever it needs to deliver bytes to a peer. You implement it over whatever transport you use (HTTP, WebSocket, message bus, in-memory queue for tests).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.DeRecFlowfor outbound actions — initiate any protocol flow withprotocol.start(DeRecFlow::Pairing { ... }),protocol.start(DeRecFlow::ProtectSecret { ... }),protocol.start(DeRecFlow::RecoverSecret { ... }), and so on. The orchestrator queues the outbound envelopes through yourDeRecTransport.
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), FFI hosts (.NET), and WASM (Node.js / Web) without forking the API surface.
Wiring it up
The example below shows the smallest meaningful DeRecProtocol instantiation: no-op stores (just enough to satisfy the type bounds), an in-memory transport, and a single process() call against a junk envelope to demonstrate the event-loop shape. Real stores live in bindings/rust/src/protocol.rs — see Minimal integration example for the runnable end-to-end version.
[dependencies]
derec-library = "0.0.1-alpha.7"
tokio = { version = "1", features = ["macros", "rt"] }That's the loop. Every flow — pairing, sharing, verification, recovery — drives through this same start / process / accept triangle.
Where to next
Dev environment setup — toolchain, dependency, local build.
Repository Map — where each piece lives in
lib-derec.Choose your integration path — orchestrator vs primitives, language, role.
Minimal integration example — runnable two-actor pairing + 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