Dev environment setup
This page covers the practical bits of getting derec-library building locally and running its end-to-end smoke test. If you've already done this once, the Quickstart and Minimal integration example are probably more useful.
Rust toolchain
derec-library builds on stable Rust. The minimum supported Rust version (MSRV) is 1.88 — it is pinned in the crate's Cargo.toml via rust-version = "1.88".
rustup toolchain install stable
rustup default stable
rustc --version # should print 1.88 or newerAdding the crate
Add both crates to your Cargo.toml. derec-proto carries the wire types (TransportProtocol, ContactMode, SenderKind, StatusEnum, …) that appear in the library's API; derec-library does not re-export them, so any code that names one needs the dependency directly.
[dependencies]
derec-library = "0.0.10"
derec-proto = "0.0.10"Or via cargo:
cargo add derec-library derec-protoCargo features
Every feature is off by default, so a default build compiles no serde, no FFI layer, and no logging.
derec-library
serde
Serialize / Deserialize on the public store and channel types (SecretValue, PairingKeyMaterial, ChannelRecord, HelperChannel, ReplicaMember, ChannelStatus, TransportProtocol), so a store can persist them with any serde format. Pulls in derec-proto/serde. The serde format is not part of the public API.
derec-library
logging
tracing spans and events across the protocol and primitives layers. No overhead when no subscriber is installed.
derec-library
ffi
The C-ABI bridge used by the .NET, Go and React Native bindings. Implies serde. Pure-Rust consumers do not need it.
derec-proto
serde
Serialize / Deserialize on the generated wire types.
derec-proto
descriptor
The compiled schema as a FileDescriptorSet, for generating your own code (for example a gRPC transport). See Schema distribution.
The library never installs a tracing subscriber. With logging on, wire one up yourself:
DEREC_LOG=info shows protocol milestones; debug and trace add sizes, versions and channel ids. Key material is never logged.
The five store traits are required
DeRecProtocolBuilder::build() is only callable once every required slot is filled: the five stores (one by one, or all at once with with_stores(DeRecStores { .. })) and the transport. The own-transport list (with_own_transports) is required too, but checked at run time: build() returns invalid_input when it is missing or empty. The stores are implementations of:
DeRecChannelStore— helper channels (HelperChannel) keyed bychannel_id, replica group members (ReplicaMember) keyed byreplica_id, and the helper-side channel-link graph.DeRecShareStore— secret shares keyed by(secret_id, channel_id, version), plus the Owner'skeep_versiondecision, the Helper'sremove_versions, and the Helper'srecord_verificationhook (Rust has a default body that accepts every verification).DeRecSecretStore— per-channel key material (SharedKey,PairingSecret,PairingContact).DeRecUserSecretStore— user-facing Secret snapshot keyed bysecret_id.DeRecStateStore— the orchestrator's in-flight protocol state (outstanding verification challenges, in-progress recovery, pending unpairs, open sharing rounds, a pending replica catch-up), keyed bysecret_id. Persisting it here is what lets the orchestrator run stateless — see Failure Modes.
There are working in-memory implementations of all five in the repository — copy them as a starting point:
smoke-tests/rust/src/protocol.rs—InMemoryChannelStore,InMemoryShareStore,InMemorySecretStore,InMemoryUserSecretStore,InMemoryStateStore.smoke-tests/sqlite/andsmoke-tests/postgres/— reference persistent implementations of all five stores,DeRecStateStoreincluded. Either can be copied wholesale as the starting point for a new backend; see Implementing a persistent store.
Transport endpoints and plaintext connections
An endpoint is a URI with one of four schemes:
Scheme
Protocol
Transport security
https://
HTTPS (0)
TLS
http://
HTTPS (0)
plaintext
grpcs://
GRPC (1)
TLS
grpc://
GRPC (1)
plaintext
Every endpoint the protocol touches — your own, and every one a peer supplies — is checked in two stages. The distinction is worth learning, because only the second one is configurable.
Structure. Non-empty, at most 2048 bytes, no control characters, and a scheme from the table above that matches the declared Protocol. Always applied, everywhere. ws://, file:// and every other scheme are refused outright.
Scheme policy. Whether plaintext (http:// or grpc://) may be used at all. This depends on how the application is deployed, so it is configuration rather than a fixed rule:
Endpoint
https / grpcs
plaintext loopback
plaintext, any other host
Your own — what you pass to with_own_transports / set_own_transports, and the replyToTransports you stamp on your own requests
always
always, with a warning
needs the flag
A peer's — a contact's or pairing message's supportedTransports, an UpdateChannelInfo announcement, a request's replyToTransports
always
needs the flag
needs the flag
The flag defaults to false in every SDK and gates http:// and grpc:// identically. When it is true, plaintext is accepted for any host, your own endpoints and peer-supplied ones alike:
Rust
builder.with_unsafe_connection(true)
.NET
builder.WithUnsafeConnection(true)
Go
protocol.Config{ DeRecProtocolConfig: protocol.DeRecProtocolConfig{ UnsafeConnection: &allow } } — a *bool; nil keeps the default false. The field is promoted, so cfg.UnsafeConnection = &allow also works
Node.js / Web / React Native
builder.withUnsafeConnection(true)
One endpoint per protocol
A device serves at most one address per protocol, so an endpoint list is a preference order over distinct protocols — https then grpcs, say — not a pool of interchangeable addresses. The rule is enforced at two strengths:
Your own list is refused if it names a protocol twice:
build()(orset_own_transports) fails with aDuplicateProtocoltransport error. An empty list fails withinvalid_input.A peer's list is filtered: entries that fail structure or policy are dropped, and for a repeated protocol the first entry wins. The survivors are recorded in the peer's order, and your transport receives all of them on every
send. If nothing survives, pairing fails withNoUsableEndpoint.
A local dev server needs no configuration
http://localhost:8080 or grpc://localhost:50051 as your own endpoint works out of the box. Only the LAN case needs the flag — a phone talking to a laptop, where neither side is loopback — and it needs it on both sides.
Why loopback is free for your own endpoint but not for a peer's
The asymmetry is not arbitrary. Your own loopback names a service on your machine, so the bytes never reach a network and there is nothing for TLS to protect. A peer's loopback is an address somebody else chose that points at your machine — a peer should not be able to nominate your localhost as a reply address while you have plaintext switched off.
Loopback recognition is deliberately literal: the host must be localhost, 127.0.0.1 or ::1 exactly. No DNS resolution, no private-range classification. Both would need full URI parsing, and getting that wrong in a security check is how http://127.0.0.1@evil.com/ slips through — so any userinfo in the authority is refused outright. RFC1918 was considered and rejected as an always-allowed range precisely because corporate networks are overwhelmingly 10.0.0.0/8, which would have silently qualified a real production deployment.
For how endpoints travel during pairing and how replies are routed, see Flows → Transport endpoints and Messages → TransportProtocol.
Other languages
The Rust crate is the source of truth; the other SDKs wrap it over the C ABI (.NET via P/Invoke, Go via purego, React Native via a C++/JSI native module) or a WASM boundary (TypeScript).
.NET — the
DeRec.LibraryNuGet package. See the .Net SDK reference.TypeScript (Node.js) —
@derec-alliance/nodejs. See the TypeScript SDK reference.TypeScript (Web) —
@derec-alliance/web, a wasm-bindgen build targeting browsers. Same API surface as the Node.js package. See the TypeScript SDK reference.React Native —
@derec-alliance/react-native, a compiled JSI native module for iOS and Android. Same API surface as the Node.js package, minus the WASM boundary. Requires a native build step (pod install/ Gradle sync) and does not run inside Expo Go. See the React Native SDK reference.Go — the
github.com/derecalliance/lib-derec/packages/gomodule, a pure-Go (purego, no cgo) binding. See the Go SDK reference.
Clone and run the smoke test
The fastest way to verify "the whole thing works end-to-end" is to clone the monorepo and run the Rust binding's smoke test. It drives every flow — pairing, sharing, verification, discovery, recovery, restore, unpairing, update-channel-info, and the replica flows (Secret sync, ReplicaDiscovery, group-key handover) — through multiple in-process DeRecProtocol instances (an Owner, its Helpers, and paired Replicas).
Building from source needs the Protocol Buffers compiler, protoc, on your PATH (or pointed to by PROTOC): the derec-proto build script generates the Rust types from the .proto files. DEVELOPMENT.md in the repository lists the install commands per platform.
Expected tail output:
If you see All smoke tests passed., your local toolchain is wired up correctly.
smoke-tests/grpc/ is a second runnable reference: three nodes on loopback (an Owner and two Helpers) pair, share and verify over real gRPC, using the transport service in protobufs/grpc/derectransport.proto. Run it with cargo run -p derec-grpc-transport-smoke-test.
From here, jump into Choose your integration path or the Minimal integration example.
Last updated