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

States

This page describes the conceptual protocol states involved in the DeRec flows.

The protocol is organized around these flows:

  • Pairing

  • Sharing

  • Verification

  • Discovery

  • Recovery

  • ReplicaDiscovery (replica-only)

  • UnpairReplica (replica-only)

  • Unpair

  • UpdateChannelInfo

These flows are message-driven interactions between an Owner identity (the Owner device and any paired Replicas) and the participants it interacts with — Helpers and sibling Replicas.

The state machines below describe the expected progression of these interactions.

This section is descriptive and intended to clarify protocol behavior.

Exact message structures are defined in the Messages section, and interaction sequences are defined in Flows.

Global State Variables

Protocol interactions reference the following identifiers:

  • secret_id — Identifier for the protected Secret. Fixed for the lifetime of the Owner identity.

  • version — Monotonic version of the Secret. Increments by one on every publish round.

  • replica_id — Per-device stable identifier of a replica-group member. Application-assigned, stamped on replica-bound writes and their responses so a member can be attributed on a channel every member shares. Helpers neither receive nor send it. 0 is reserved as the "absent" sentinel and is not a valid identity.

  • channel_id — Communication channel between two participants. One per Owner ↔ Helper pair; one per replica group, shared by every member.

The value that bootstraps pairing (carried in the ContactMessage) is transient: the moment the handshake completes, both sides rotate to a long-term channel_id derived from the channel key (SHA-384(originalChannelId || channelKey)). All post-pairing traffic uses the rotated id; see Messages for the derivation and the validation each side performs.

The combination of (secret_id, channel_id, version) identifies a specific share on a Helper. Exactly one share exists per key: a version has exactly one writer, and a second write at an existing version carrying different content is refused with VERSION_CONFLICT rather than stored alongside.

The protocol does not mandate how versions are generated beyond the monotonic rule. The reference library derives each round's version as latest_version + 1; see Versioning.

Owner State Machine

The Owner (or any Replica acting on its behalf) coordinates protocol flows with Helpers. Once a Replica has received the first Secret sync from the Owner identity, its Helper-facing state machine is identical to the Owner's: every member publishes to a Helper as the Owner. Within the group, each member keeps a persisted ReplicaRole (exactly one Source); that role does not change how it talks to Helpers.

  • Unpaired — No protocol relationship has been established yet on this channel.

  • PairingInProgress — Pairing messages are exchanged to establish a trusted communication relationship with each peer (Helper or Replica).

  • Paired — The two sides have completed pairing and may participate in protocol flows.

  • Sharing — Shares are distributed for a particular secret_id and version — committed shares to Helpers and the full Secret to paired Replicas.

  • Active — Normal operating state in which verification, discovery, and recovery flows may occur.

  • Verification — The Owner identity challenges Helpers to confirm possession of share content.

  • RecoveryMode — A recovery operation is initiated.

  • Recovering — Shares are requested from Helpers and reconstruction is attempted once enough valid shares are obtained.

Channel lifecycle status

Every stored channel record carries a ChannelStatus. There are three values:

Status
Meaning

Pending

Awaiting out-of-band fingerprint confirmation. Not a publish target, not a recovery source, and an inbound message on it is dropped and reported as MessageIgnored with reason PendingVerification. A dropped message is not replayed after confirmation.

Paired

Fully paired and ready for protocol messages.

Unpairing

Replica member only. Told to leave, awaiting the roster version that completes its removal. Never set on a Helper channel.

The Pending gate

Two kinds of channel enter Pending after the cryptographic handshake and stay there until fingerprint cross-confirmation succeeds:

  • Every replica channel (ReplicaSource ↔ ReplicaDestination), whatever the contact mode.

  • Every NoKeys channel, Owner ↔ Helper included — that mode commits to nothing, so the fingerprint replaces the missing commitment.

An InlineKeys or HashedKeys Owner ↔ Helper channel is Paired at handshake completion and skips the gate.

A channel left in Pending is swept by the expired-channel policy — see Timeouts. A fingerprint mismatch revokes the pairing: verify_fingerprint fails with FingerprintMismatch, and the channel's Pending records, its channel key and its pairing material are deleted, so a second comparison fails and the devices must pair again. The sweep removes the channel key with the record. A Paired channel is never touched by a comparison.

The Unpairing flag

Unpairing exists because replica removal is a member-row edit, not a channel deletion — every member shares one group channel, so deleting it would sever the whole group.

The flag is persisted, because the unpair request and the completing roster are separate rounds that may straddle a restart. Both halves must hold before anything is torn down: told to leave, and subsequently absent from a newer roster. Absence alone never destroys a copy of the Secret. See UnpairReplica and Replica removal.

Helper State Machine

Helpers store shares and respond to protocol requests from the Owner identity.

  • Unpaired — No protocol relationship has been established yet.

  • PairingInProgress — Pairing messages are exchanged.

  • Paired — The Helper can participate in protocol flows.

  • HoldingShare — The Helper stores share data indexed by (secret_id, channel_id, version). Exactly one share exists per key. A byte-identical re-send at an existing version is an idempotent retry answered OK; a write carrying different bytes at an existing version is refused with VERSION_CONFLICT and never reaches storage. A Helper holds no replica identity and cannot tell which device wrote a version. A share outside the Helper's size range, one that does not decode, or one that does not verify against its commitment is refused before ActionRequired and reported as ShareRefused; nothing is stored and no version is removed.

  • VerifyResponding — The Helper responds to a verification request.

  • RecoveryServing — The Helper returns share data when requested during recovery.

  • Discovery — The Helper returns the catalogue of (secret_id, version) pairs it currently holds.

Helpers do not communicate with other Helpers and do not know the size of the Helper Set.

Recovery Share Collection

A recovery targets exactly one (secret_id, version): the Owner requests that version from every paired Helper. Each response is judged on arrival.

  • A share that is undecodable, bound to another secret or version, or names a different version than the one requested is Malformed. A share whose Merkle proof does not open to its own commitment root is InvalidProof. Both are reported as RecoveryShareCorrupted and set aside.

  • A Helper that answers with a non-Ok status — for example UNKNOWN_SHARE_VERSION because it no longer holds that version — is reported as RecoveryShareRefused. The share is not collected and recovery stays open.

  • Valid shares are grouped by (commitment root, ciphertext) and tried largest group first; ties go to the earliest arrival, and a group of one is never tried. The first group that decrypts wins. Shares outside it are reported as RecoveryShareCorrupted { reason: Inconsistent } alongside SecretRecovered.

Concurrent writes never accumulate as divergent shares at one version on a Helper: they are refused at store time with VERSION_CONFLICT. See Conflict resolution.

Restoring operational state after recovery

Reconstructing the Secret produces the Recovered state — the user-facing data is in hand, surfaced as the SecretRecovered event. SecretRecovered writes nothing: the application shows the Secret, or asks the user, before committing it. A device that was recovering from loss is not yet operational at this point: it drove recovery over throwaway recovery-mode channels and holds no committed snapshot.

The restore(secret, version) step advances it to Restored:

  • It validates every roster entry — keys, ids, roles, including entries it will skip — before writing anything.

  • It re-establishes the canonical channels to every Helper and Replica named in the recovered Secret, with each Helper's roster weight. An entry with no endpoint gets no channel and is reported as PeerNotRestored { reason: NoTransports }; the rest of the roster is restored.

  • It commits the Secret snapshot at the recovered version, with the roster's threshold. That write is the commit point.

  • It unpairs the recovery-mode channels, emitting Unpaired, or UnpairFailed for a teardown it could not complete.

restore returns events the application must handle. It does not adopt a replica identity: when the roster has a replica group, the next publish needs a configured replica_id the roster names, or it fails with ReplicaIdNotConfigured. restore writes no owner-side tracking shares, so start(VerifyShares) at the recovered version sends no challenge and reports every channel as VerifySharesFailed { reason: NoProof, .. }, until one ProtectSecret has run; that publish goes out at recovered_version + 1 and writes the tracking shares verification needs. The Recovering --> Active transition in the Owner state machine, for a device recovering from loss, passes through this restore step.

In-flight orchestrator state

Separate from channel status, the orchestrator persists the state of rounds that are still open in the DeRecStateStore. Each row is tagged with a StateKind (crate::protocol::types::StateKind). The discriminants are stable and safe to persist; new kinds are appended.

StateKind

Value

Keyed by

Holds

PendingVerification

0

channel_id

The outstanding VerifyShareRequestMessage for that channel, used to bind the response to the challenge.

PendingRecovery

1

recovered (secret_id, version)

Every GetShareResponseMessage received so far for that reconstruction target.

PendingUnpair

2

channel_id

An outstanding unpair acknowledgement and its started_at timestamp.

SharingRound

3

version

One open publish round: per-channel and per-member tallies, started_at, the keep_version every Helper was sent (used to prune the Owner's proofs when a Helper confirms; a row written by 0.0.9 carries keep_list instead, which is ignored, so that round prunes nothing) and the threshold the round split at (what SharingComplete.threshold_met is judged against). Several can be open at once, because the pair-completion hook and verify_fingerprint also publish. A row written before 0.0.9 decodes with an empty keep list, so it prunes nothing, and no threshold, so it is judged against the builder's.

PendingReplicaDiscovery

4

— (one per secret_id)

The versions members have reported so far in a ReplicaDiscovery. A new start(ReplicaDiscovery) overwrites it.

Open rounds are timed out by Timeouts (sharing round and unpair acknowledgement default to 60 seconds) and settled by tick() or at the start of the next process(); see Timeouts and tick(). A sharing round that settles a Helper channel as failed, by rejection or timeout, deletes the Owner's proof for that channel at the round's version. Pending channels are removed by the expired-channel sweep, Enabled { timeout_in_secs: 300 } by default, together with their channel key and pairing material.

Pending actions are not orchestrator state. An ActionRequired token, and the PendingAction::RespondToFailure token a RequestFailed carries when auto_respond_on_failure is off, are handed to the application, which keeps them until it calls accept or reject. The library never expires one; a token nobody answers leaves its sender to time out, and resolving each token once is the application's part.

Last updated