Skip to main content

DeRecProtocolBuilder

Struct DeRecProtocolBuilder 

Source
pub struct DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> { /* private fields */ }
Expand description

Typestate builder for DeRecProtocol.

Call each store/transport setter, then build. The “every required slot is filled” constraint is enforced at compile time by the impl-block bounds — calling build() on an incomplete builder is a type error, not a runtime panic.

Setters may be called in any order.

§Example

let protocol = DeRecProtocolBuilder::new()
    .with_channel_store(my_channel_store)
    .with_share_store(my_share_store)
    .with_secret_store(my_secret_store)
    .with_transport(my_transport)
    .with_own_transport(TransportProtocol { uri: "https://me.example.com".into(), .. })
    // Plus any optional with_* setters to override defaults.
    .build();

Implementations§

Source§

impl DeRecProtocolBuilder<BuilderSlotMissingMarker, BuilderSlotMissingMarker, BuilderSlotMissingMarker, BuilderSlotMissingMarker, BuilderSlotMissingMarker, BuilderSlotMissingMarker, BuilderSlotMissingMarker>

Source

pub fn new(secret_id: u64) -> Self

Construct a new builder bound to a specific secret.

secret_id identifies the single secret this protocol instance manages. Apps that juggle multiple secrets instantiate one DeRecProtocol per secret_id.

Source§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>

Source

pub fn with_threshold(self, threshold: usize) -> Self

Minimum number of shares required to reconstruct the secret.

Default: 3. This setter is infallible — invariant checks run at build time and surface a structured crate::Error so callers can handle invalid configurations uniformly across SDKs (FFI / WASM bindings translate that error into their native shape rather than seeing a panic propagate across the language boundary).

Source

pub fn with_keep_versions_count(self, count: usize) -> Self

Number of recent versions each helper must retain.

Default: 3.

Source

pub fn with_timeout(self, timeout: Duration) -> Self

Protocol-wide staleness boundary.

Any inbound envelope whose timestamp is older than this is discarded on receipt, regardless of flow.

The same threshold is also used to age out local state that is waiting on a peer: incomplete pairings, in-flight sharing rounds, and outstanding unpair acknowledgements.

§Granularity

One second is the smallest effective unit. The protocol’s wire timestamps (protobuf Timestamp.seconds) carry only whole-second resolution, so message ages can only be measured to the nearest second. As a consequence:

Default: 5 minutes.

Source

pub fn with_communication_info(self, info: HashMap<String, String>) -> Self

Key-value pairs included in CommunicationInfo within pairing request and response messages (e.g. "name", "email", "phone").

Default: empty.

Source

pub fn with_auto_respond_on_failure(self, enabled: bool) -> Self

Whether the protocol replies to peers on inbound processing failures.

  • true: on a failed inbound request (e.g. format errors, decryption failures), the protocol automatically sends a failure response to the peer.
  • false: inbound processing errors are only surfaced as events and no response is sent — the application decides how to respond.

Default: false.

Source

pub fn with_unpair_ack(self, ack: UnpairAck) -> Self

Whether the unpair initiator waits for the peer’s acknowledgement before dropping local state.

Default: UnpairAck::Required.

Source

pub fn with_auto_reply_to(self, enabled: bool) -> Self

Whether outbound requests carry an ephemeral replyTo set to this node’s own transport endpoint.

  • true: every outbound request envelope stamps request.replyTo = own_transport. The responder routes its response to that endpoint, ignoring the channel’s stored peer endpoint. Useful when two peers share a channel record but reach out from different endpoints (e.g. replicas talking to a helper that was paired with a sibling replica) — without this, the responder would reply to the sibling.
  • false: outbound requests leave replyTo unset. The responder routes to the channel’s stored endpoint, which is correct for the single-device case.

Only affects outbound requests originated through DeRecProtocol::start. Responders always honour an inbound replyTo regardless of this flag (it is purely a per-request hint on the wire).

Default: false.

Source

pub fn with_auto_accept(self, policy: AutoAcceptPolicy) -> Self

Per-flow opt-in for auto-accepting inbound requests.

When a flow’s field on the policy is true, DeRecProtocol::process internally runs the equivalent of DeRecProtocol::accept for that flow and emits crate::protocol::DeRecEvent::AutoAccepted in place of crate::protocol::DeRecEvent::ActionRequired (followed in the same event vec by the flow’s completion events).

Default: crate::protocol::AutoAcceptPolicy::default() — every field false, behaviour identical to today’s ActionRequired flow. See the field-level docs on crate::protocol::AutoAcceptPolicy for the per-flow trade-offs.

Source

pub fn with_replica_id(self, id: u64) -> Self

Configure this node’s local replica identity.

Required to participate in any replica-mode pairing — when set, the orchestrator auto-injects the id (hex-encoded) under the reserved key derec.replica_id in outbound PairRequest / PairResponse envelopes whose sender_kind is ReplicaSource or ReplicaDestination, and accepts inbound replica pairings that advertise the peer’s id under the same key.

Apps that do not use replica flows simply do not call this setter. With no replica id configured, the orchestrator rejects every replica-mode entry point with Error::ReplicaIdNotConfigured; Owner and Helper pairings are unaffected.

The id must be stable across restarts — persist it on the device once and pass the same value on every protocol init. Use crate::generate_replica_id to mint a fresh one with the OS CSPRNG.

Default: unset (replica flows disabled).

Source

pub fn with_parameter_range(self, range: ParameterRange) -> Self

Declare the local node’s acceptable ParameterRange for pair negotiation.

Embedded in outbound PairRequest / PairResponse envelopes and checked against the peer’s range on inbound ones: if any field’s range fails to intersect (e.g. local minShareSize exceeds peer maxShareSize) the pairing is rejected with Error::Pairing(PairingError::IncompatibleParameterRange { .. }).

Default: unset — the local side advertises no constraints and accepts any peer range.

Source§

impl<ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> DeRecProtocolBuilder<BuilderSlotMissingMarker, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>

Source

pub fn with_channel_store<Cs: DeRecChannelStore>( self, store: Cs, ) -> DeRecProtocolBuilder<BuilderSlotSetMarker<Cs>, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>

Set the DeRecChannelStore implementation responsible for persisting channel records.

Source§

impl<ChannelStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> DeRecProtocolBuilder<ChannelStore, BuilderSlotMissingMarker, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>

Source

pub fn with_share_store<Sh: DeRecShareStore>( self, store: Sh, ) -> DeRecProtocolBuilder<ChannelStore, BuilderSlotSetMarker<Sh>, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>

Set the DeRecShareStore implementation responsible for persisting secret shares.

Source§

impl<ChannelStore, ShareStore, UserSecretStore, StateStore, Transport, OwnTransport> DeRecProtocolBuilder<ChannelStore, ShareStore, BuilderSlotMissingMarker, UserSecretStore, StateStore, Transport, OwnTransport>

Source

pub fn with_secret_store<Ss: DeRecSecretStore>( self, store: Ss, ) -> DeRecProtocolBuilder<ChannelStore, ShareStore, BuilderSlotSetMarker<Ss>, UserSecretStore, StateStore, Transport, OwnTransport>

Set the DeRecSecretStore implementation responsible for persisting per-channel key material (pairing secrets, shared keys, pairing contacts).

Source§

impl<ChannelStore, ShareStore, SecretStore, StateStore, Transport, OwnTransport> DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, BuilderSlotMissingMarker, StateStore, Transport, OwnTransport>

Source

pub fn with_user_secret_store<Us: DeRecUserSecretStore>( self, store: Us, ) -> DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, BuilderSlotSetMarker<Us>, StateStore, Transport, OwnTransport>

Set the DeRecUserSecretStore implementation responsible for persisting the user-facing secret contents keyed by secret_id. Written on every start(FlowKind::ProtectSecret); read by the pair-completion auto-publish hook so freshly-paired peers receive the current secret without an explicit re-publish.

Source§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, OwnTransport> DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, BuilderSlotMissingMarker, OwnTransport>

Source

pub fn with_transport<Tr: DeRecTransport>( self, transport: Tr, ) -> DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, BuilderSlotSetMarker<Tr>, OwnTransport>

Set the DeRecTransport implementation responsible for delivering outbound envelopes to peers.

Source§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport> DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, BuilderSlotMissingMarker>

Source

pub fn with_own_transport( self, own_transport: impl IntoOwnTransport, ) -> DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, BuilderSlotSetMarker<Result<TransportProtocol, TransportValidationError>>>

The local node’s transport endpoint that peers will use to reach it.

Embedded into outgoing contact and pairing messages so peers know where to send their replies. Accepts anything implementing IntoOwnTransport: a typed TransportProtocol, a &str, or a String. URI validation is deferred to build so the setter chain stays infallible — a malformed URI surfaces as crate::Error::Transport when build() runs.

Source§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, Transport, OwnTransport> DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, BuilderSlotMissingMarker, Transport, OwnTransport>

Source

pub fn with_state_store<St: DeRecStateStore>( self, store: St, ) -> DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, BuilderSlotSetMarker<St>, Transport, OwnTransport>

Set the DeRecStateStore implementation responsible for persisting in-flight orchestrator state (outstanding verification challenges, recovery accumulators, pending unpair acknowledgements). Required for stateless / load-balanced deployments where the process may be recycled between an outbound request and its inbound response; see the trait documentation for the concurrency contract.

Source§

impl<Cs: DeRecChannelStore, Sh: DeRecShareStore, Ss: DeRecSecretStore, Us: DeRecUserSecretStore, St: DeRecStateStore, Tr: DeRecTransport> DeRecProtocolBuilder<BuilderSlotSetMarker<Cs>, BuilderSlotSetMarker<Sh>, BuilderSlotSetMarker<Ss>, BuilderSlotSetMarker<Us>, BuilderSlotSetMarker<St>, BuilderSlotSetMarker<Tr>, BuilderSlotSetMarker<Result<TransportProtocol, TransportValidationError>>>

Source

pub fn build(self) -> Result<DeRecProtocol<Cs, Sh, Ss, Us, St, Tr>>

Consume the builder and return a fully-initialized DeRecProtocol.

The “all required slots set” constraint is enforced by this impl block’s type bounds — the call is only reachable once every slot has been filled. Runtime invariant checks (currently: threshold >= 2 and own-transport URI validity) are deferred to this point and surface as crate::Error.

§Errors

Auto Trait Implementations§

§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> Freeze for DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>
where ChannelStore: Freeze, ShareStore: Freeze, SecretStore: Freeze, UserSecretStore: Freeze, StateStore: Freeze, Transport: Freeze, OwnTransport: Freeze,

§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> RefUnwindSafe for DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>
where ChannelStore: RefUnwindSafe, ShareStore: RefUnwindSafe, SecretStore: RefUnwindSafe, UserSecretStore: RefUnwindSafe, StateStore: RefUnwindSafe, Transport: RefUnwindSafe, OwnTransport: RefUnwindSafe,

§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> Send for DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>
where ChannelStore: Send, ShareStore: Send, SecretStore: Send, UserSecretStore: Send, StateStore: Send, Transport: Send, OwnTransport: Send,

§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> Sync for DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>
where ChannelStore: Sync, ShareStore: Sync, SecretStore: Sync, UserSecretStore: Sync, StateStore: Sync, Transport: Sync, OwnTransport: Sync,

§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> Unpin for DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>
where ChannelStore: Unpin, ShareStore: Unpin, SecretStore: Unpin, UserSecretStore: Unpin, StateStore: Unpin, Transport: Unpin, OwnTransport: Unpin,

§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> UnsafeUnpin for DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>
where ChannelStore: UnsafeUnpin, ShareStore: UnsafeUnpin, SecretStore: UnsafeUnpin, UserSecretStore: UnsafeUnpin, StateStore: UnsafeUnpin, Transport: UnsafeUnpin, OwnTransport: UnsafeUnpin,

§

impl<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport> UnwindSafe for DeRecProtocolBuilder<ChannelStore, ShareStore, SecretStore, UserSecretStore, StateStore, Transport, OwnTransport>
where ChannelStore: UnwindSafe, ShareStore: UnwindSafe, SecretStore: UnwindSafe, UserSecretStore: UnwindSafe, StateStore: UnwindSafe, Transport: UnwindSafe, OwnTransport: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V