1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
//! Reference application layer for DE-MLS.
//!
//! This module provides a complete reference implementation showing how to build
//! on top of [`crate::core`]. You can use it directly or as a template for custom
//! implementations.
//!
//! # Overview
//!
//! The app layer adds:
//! - **`User`** - Multi-group manager with consensus integration
//! - **`GroupStateMachine`** - State transitions (PendingJoin → Working ⇄ Waiting → Leaving)
//! - **`StateChangeHandler`** - Callbacks for UI state updates
//! - **Epoch scheduling** - Configurable steward epoch timing
//!
//! # When to Use This Layer
//!
//! **Use directly** if you want:
//! - Standard chat functionality out of the box
//! - Epoch-based steward consensus model
//! - Built-in join timeout and leave handling
//!
//! **Build your own** if you need:
//! - Different consensus model (e.g., leader election)
//! - Custom state machine transitions
//! - Non-standard epoch timing
//!
//! # Architecture
//!
//! ```text
//! ┌─────────────────────────────────────────────────────────┐
//! │ de_mls::app │
//! │ │
//! │ User<P, H, S> │
//! │ ├── groups: HashMap<String, GroupEntry> │
//! │ │ └── GroupEntry │
//! │ │ ├── handle: GroupHandle (from core) │
//! │ │ └── state_machine: GroupStateMachine │
//! │ ├── consensus_service │
//! │ ├── handler: H (GroupEventHandler) │
//! │ └── state_handler: S (StateChangeHandler) │
//! │ │
//! │ GroupStateMachine │
//! │ ├── state: PendingJoin | Working | Waiting | Leaving │
//! │ ├── epoch timing (last_boundary, epoch_duration) │
//! │ └── timeout tracking (pending_join, commit) │
//! └─────────────────────────────────────────────────────────┘
//! │
//! ▼
//! ┌─────────────────────────────────────────────────────────┐
//! │ de_mls::core │
//! │ GroupHandle, process_inbound, dispatch_result, ... │
//! └─────────────────────────────────────────────────────────┘
//! ```
//!
//! # State Machine
//!
//! ```text
//! ┌──────────────┐
//! join_group │ PendingJoin │ timeout (2 epochs)
//! ──────────► │ │ ──────────────────► cleanup
//! └──────┬───────┘
//! │ welcome received
//! ▼
//! ┌──────────────┐
//! │ Working │◄─────────────────┐
//! │ │ │
//! └──────┬───────┘ │
//! │ epoch boundary │ commit received
//! │ (has proposals) │
//! ▼ │
//! ┌──────────────┐ │
//! │ Waiting │──────────────────┘
//! │ │
//! └──────┬───────┘
//! │ leave_group()
//! ▼
//! ┌──────────────┐
//! │ Leaving │ ─────────────────► cleanup
//! │ │ (commit received)
//! └──────────────┘
//! ```
//!
//! # Quick Start
//!
//! ```ignore
//! use de_mls::app::{User, GroupState, StateChangeHandler};
//! use de_mls::core::{GroupEventHandler, DefaultProvider};
//!
//! // Your handlers
//! struct MyHandler { /* ... */ }
//! impl GroupEventHandler for MyHandler { /* ... */ }
//! impl StateChangeHandler for MyHandler { /* ... */ }
//!
//! // Create user
//! let user = User::<DefaultProvider, _, _>::with_private_key(
//! "0xprivate_key",
//! consensus_service,
//! event_handler,
//! state_handler,
//! )?;
//!
//! // Create a group (as steward)
//! user.create_group("my-chat", true).await?;
//!
//! // Or join an existing group
//! user.create_group("other-chat", false).await?;
//! user.send_kp_message("other-chat").await?; // Send key package
//!
//! // Send messages
//! user.send_app_message("my-chat", b"Hello!".to_vec()).await?;
//!
//! // Process inbound (call from your transport receive loop)
//! user.process_inbound_packet(inbound_packet).await?;
//!
//! // Steward epoch (call periodically for steward groups)
//! user.start_steward_epoch("my-chat").await?;
//!
//! // Member epoch (call at epoch boundaries for non-steward groups)
//! let entered_waiting = user.start_member_epoch("other-chat").await?;
//! ```
//!
//! # Configuration
//!
//! Epoch duration can be configured per-user (default) or per-group:
//!
//! ```ignore
//! use de_mls::app::GroupConfig;
//! use std::time::Duration;
//!
//! // Custom default for all groups
//! let config = GroupConfig::with_epoch_duration(Duration::from_secs(60));
//! let user = User::with_private_key_and_config(key, consensus, handler, state_handler, config)?;
//!
//! // Or per-group
//! user.create_group_with_config("fast-chat", true, GroupConfig::with_epoch_duration(Duration::from_secs(10))).await?;
//! ```
pub use ;
pub use ;
pub use ;