Skip to main content

User

Struct User 

Source
pub struct User<P: DeMlsProvider, H: GroupEventHandler, SCH: StateChangeHandler> { /* private fields */ }
Expand description

User manages multiple MLS groups.

This struct provides the main application-level interface for working with MLS groups, handling consensus, and processing messages.

The type parameter P determines which service implementations are used (storage, consensus). Use DefaultProvider for standard configuration.

The type parameter H is the handler that receives output events (outbound packets, app messages, leave/join notifications).

The type parameter SCH is the handler for state machine state changes (an app-layer concern, separate from the core GroupEventHandler).

Implementations§

Source§

impl<P: DeMlsProvider, H: GroupEventHandler + 'static, SCH: StateChangeHandler + 'static> User<P, H, SCH>

Source

pub fn identity_string(&self) -> String

Get the user’s identity string (wallet address as checksummed hex).

Source

pub async fn create_group( &mut self, group_name: &str, is_creation: bool, ) -> Result<(), UserError>

Create or join a group with the user’s default config.

§Arguments
  • group_name - The name of the group
  • is_creation - true to create a new group as steward, false to prepare to join
Source

pub async fn create_group_with_config( &mut self, group_name: &str, is_creation: bool, config: GroupConfig, ) -> Result<(), UserError>

Create or join a group with custom config.

§Arguments
  • group_name - The name of the group
  • is_creation - true to create a new group as steward, false to prepare to join
  • config - Group-specific configuration
Source

pub async fn leave_group(&mut self, group_name: &str) -> Result<(), UserError>

Leave a group.

For PendingJoin state: immediate cleanup (no MLS state exists). For Leaving state: error (already leaving). For Working/Waiting: transitions to Leaving and sends a self-removal ban request. Actual cleanup happens when the removal commit arrives via DispatchAction::LeaveGroup.

Source

pub async fn get_group_state( &self, group_name: &str, ) -> Result<GroupState, UserError>

Get the state of a group.

Source

pub async fn list_groups(&self) -> Vec<String>

List all group names.

Source

pub async fn is_steward_for_group( &self, group_name: &str, ) -> Result<bool, UserError>

Check if the user is steward for a group.

Source

pub async fn get_group_members( &self, group_name: &str, ) -> Result<Vec<String>, UserError>

Get the members of a group.

Source

pub async fn get_approved_proposal_for_current_epoch( &self, group_name: &str, ) -> Result<Vec<GroupUpdateRequest>, UserError>

Get current epoch proposals for a group.

Source

pub async fn get_epoch_history( &self, group_name: &str, ) -> Result<Vec<Vec<GroupUpdateRequest>>, UserError>

Get epoch history for a group (past batches of approved proposals, most recent last).

Returns up to the last 10 epoch batches for UI display.

Source

pub async fn send_kp_message(&self, group_name: &str) -> Result<(), UserError>

Build and send a key package message for a group via the handler.

Source

pub async fn send_app_message( &self, group_name: &str, message: Vec<u8>, ) -> Result<(), UserError>

Send a conversation message to a group.

Allowed in Working and Leaving states (user is still a group member). Blocked in PendingJoin (no MLS state) and Waiting (epoch freeze).

Source

pub async fn process_ban_request( &mut self, ban_request: BanRequest, group_name: &str, ) -> Result<(), UserError>

Process a ban request.

Returns an error if the group is blocked (PendingJoin, Waiting, or Leaving state).

Source

pub async fn check_pending_join(&self, group_name: &str) -> bool

Check if still in pending join state.

Called periodically while in PendingJoin state to:

  1. Detect when the member has joined (state changed to Working)
  2. Check for timeout (time-based fallback if group is quiet after rejection)

Returns true if still waiting (PendingJoin), false if no longer pending (either joined, timed out, or group not found).

Source

pub async fn time_until_next_epoch(&self, group_name: &str) -> Option<Duration>

Get the time until the next epoch boundary for a group.

Returns None if the group doesn’t exist or hasn’t synced yet. Returns Some(Duration::ZERO) if we’re already past the boundary.

Source

pub async fn check_commit_timeout( &self, group_name: &str, ) -> CommitTimeoutStatus

Check if the commit has timed out while in Waiting state.

Returns a CommitTimeoutStatus indicating:

  • NotWaiting — not in Waiting state (nothing to check)
  • StillWaiting — in Waiting but timeout not reached yet
  • TimedOut { has_proposals } — timeout reached, state reverted to Working

When timed out, checks if approved proposals still exist:

  • If proposals exist: steward failed to commit (steward fault)
  • If no proposals: false alarm (proposals cleared by other means)

In both cases the member is unblocked (reverted to Working) and the epoch boundary is re-synced to now.

Source

pub async fn start_member_epoch( &self, group_name: &str, ) -> Result<bool, UserError>

Start a member epoch check.

Non-steward members call this at the epoch boundary (not before). If they have approved proposals, they transition to Waiting state expecting a commit.

Returns true if entered Waiting state (caller should poll for commit timeout), false otherwise (no polling needed).

This method does nothing for stewards or members in PendingJoin/Leaving state.

Source

pub async fn start_steward_epoch( &mut self, group_name: &str, ) -> Result<(), UserError>

Start a steward epoch.

Source

pub async fn start_voting_on_request_background( &self, group_name: String, upd_request: GroupUpdateRequest, ) -> Result<(), UserError>

Source

pub async fn process_user_vote( &mut self, group_name: &str, proposal_id: u32, vote: bool, ) -> Result<(), UserError>

Process a user vote.

Allowed in Working, Leaving, and PendingJoin states. Blocked in Waiting state (epoch freeze — vote is sent as MLS message).

Source

pub async fn process_inbound_packet( &self, packet: InboundPacket, ) -> Result<(), UserError>

Process an inbound packet.

Source

pub async fn handle_consensus_event( &mut self, group_name: &str, event: ConsensusEvent, ) -> Result<(), UserError>

Handle a consensus event.

Source§

impl<H: GroupEventHandler + 'static, SCH: StateChangeHandler + 'static> User<DefaultProvider, H, SCH>

Source

pub fn with_private_key( private_key: &str, consensus_service: Arc<DefaultConsensusService>, handler: Arc<H>, state_handler: Arc<SCH>, ) -> Result<Self, UserError>

Convenience constructor for the default provider with default group config.

Creates a User with MLS service and the given consensus service.

§Arguments
  • private_key - Ethereum private key as hex string
  • consensus_service - The default consensus service
  • handler - Event handler for output events
  • state_handler - Handler for state machine state changes
Source

pub fn with_private_key_and_config( private_key: &str, consensus_service: Arc<DefaultConsensusService>, handler: Arc<H>, state_handler: Arc<SCH>, default_group_config: GroupConfig, ) -> Result<Self, UserError>

Convenience constructor for the default provider with custom group config.

Creates a User with MLS service and the given consensus service.

§Arguments
  • private_key - Ethereum private key as hex string
  • consensus_service - The default consensus service
  • handler - Event handler for output events
  • state_handler - Handler for state machine state changes
  • default_group_config - Default config applied to new groups

Auto Trait Implementations§

§

impl<P, H, SCH> !Freeze for User<P, H, SCH>

§

impl<P, H, SCH> !RefUnwindSafe for User<P, H, SCH>

§

impl<P, H, SCH> Send for User<P, H, SCH>

§

impl<P, H, SCH> Sync for User<P, H, SCH>

§

impl<P, H, SCH> Unpin for User<P, H, SCH>
where <P as DeMlsProvider>::Storage: Unpin,

§

impl<P, H, SCH> !UnwindSafe for User<P, H, SCH>

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<T> Classify for T

Source§

type Classified = T

Source§

fn classify(self) -> T

Source§

impl<T> Declassify for T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more