.Net
This document provides the recommended structure and content for the .NET SDK section of the DeRec documentation.
It is designed to guide .NET developers through installing, understanding, and integrating the DeRec protocol using the official DeRec.Library NuGet package.
.NET SDK Overview
The DeRec .NET SDK provides a managed surface over the same DeRecProtocol orchestrator the Rust SDK exposes.
The SDK allows applications to:
Distribute Secret shares across trusted Helpers using a threshold secret-sharing scheme
Verify Helpers still hold shares
Recover the Secret from a threshold of Helpers
Optionally extend the Owner identity across multiple devices via the replica feature, with automatic Secret synchronization between them
The SDK is published as a single NuGet package:
DeRec.LibraryInternally the package is built on top of the C ABI exposed by the Rust derec-library crate. The FFI bridge, the pinned managed delegates, and the native handle lifecycle are all internal — the .NET consumer sees a managed DeRec.Library.Orchestrator.DeRecProtocol class, async methods, typed exceptions, and IDisposable lifetime management.
Installation
Add the SDK to your project:
The SDK is pre-1.0. Breaking changes between alpha versions are expected — pin an exact version in your project file and treat upgrades as a deliberate review step.
The package ships pre-built native binaries (libderec_library.dylib / .so / .dll) for the supported runtime identifiers (osx-arm64, osx-x64, linux-x64, linux-arm64). NuGet's RID-resolution picks the correct one at build time.
Quick Start
Implement the four store interfaces, a transport callback, and drive the orchestrator. The example below is the minimum scaffold; the four flow chapters show how each protocol round-trip flows through process(...).
DeRecProtocol is IDisposable — the instance owns the native handle plus a set of pinned delegates, and Dispose() releases both. Wrap it in a using block (or hold it on a long-lived service and dispose at shutdown).
Protocol Flows
The SDK exposes every DeRec flow through a single protocol.StartAsync(FlowKind, ...) entry point plus the inbound ProcessAsync / AcceptAsync loop. The four chapters below cover the core integration areas; the full flow catalog (Discovery, Unpair, UpdateChannelInfo) lives in Protocol Specification / Flows.
Establish secure communication between two participants — Owner ↔ Helper, or Replica pairings
Split the Secret and distribute shares to Helpers; sync the full Secret to every paired Replica
Verify Helpers still hold shares
Recover shares and reconstruct the Secret
Each flow follows the same shape: the initiator calls StartAsync(FlowKind.X, params); the library produces outbound envelopes through your ITransport; the responder feeds inbound envelopes to ProcessAsync and consents to any ActionRequiredEvent via AcceptAsync.
Message Model
The SDK operates on serialized protocol envelopes rather than exposing protobuf types directly.
Inbound and outbound envelopes are plain
byte[]arrays on both sides of the orchestratorThese bytes represent:
A serialized
DeRecMessageenvelope, orA plain serialized
ContactMessage(the out-of-band bootstrap, see Pairing)
For encrypted protocol exchanges, the
DeRecMessageenvelope contains an encrypted inner protobuf message — the library performs the encryption, decryption, and framing for you
This design ensures:
Transport-agnostic usage (HTTP, WebSocket, mailbox relay, etc.)
Language-agnostic interoperability with the Rust, TypeScript, and other SDKs
Clear separation between protocol and transport layers
Applications are responsible for:
Delivering outbound
byte[]envelopes — the library passes them toITransport.Send(uri, protocol, message)— to the counterpartyReceiving inbound
byte[]envelopes and passing them back throughDeRecProtocol.ProcessAsync(...)
Error Handling
All library-side errors surface as the typed DeRec.Library.DeRecException:
DeRecException.Category mirrors the FFI's DEREC_CATEGORY_* constants and identifies which protocol phase produced the error (Pairing, Sharing, Recovery, Verification, Discovery, Unpairing, SecretStore, ChannelStore, ShareStore, Invariant, InvalidInput, ...). DeRecException.Code mirrors the DEREC_CODE_* constants and identifies the specific reason — for example DeRecCode.ReplicaIdNotConfigured when a replica-mode flow is started without WithReplicaId(...).
The same (Category, Code) pair carries the same meaning across every language binding.
API Reference
The package surfaces XML doc comments on every public type. Full API documentation lives in the GitHub repository under packages/dotnet/DeRec.Library/src/.
Recommended documentation structure:
README.mdpairing.mdshare-distribution.mdverification.mdrecovery.md
SDK Architecture
DeRec.Library provides the managed DeRecProtocol orchestrator surface and the bridging delegates that satisfy the Rust-side store and transport traits. The native derec-library crate is the source of truth for protocol logic — every binding is a thin translation over the same core.
Last updated