Overview
Thexmtp_mls crate is the core implementation of XMTP’s Messaging Layer Security (MLS) protocol. It provides the primary client interface for creating and managing encrypted group conversations, handling identity management, and syncing messages across devices.
Installation
Key Exports
The crate exports the following modules and types fromlib.rs:
The main client interface for XMTP MLS operations. Parameterized by context type to allow different API/DB combinations.
Represents the network the client connects to:
Local(&'static str)- Local development networkDev- Development network (default)Prod- Production network
A manager for group-specific semaphores to prevent concurrent modifications to the same group.
A guard that releases the group semaphore when dropped, ensuring proper lock cleanup.
Core Modules
builder
ProvidesClientBuilder for fluent construction of clients with identity, API, and storage configuration.
client
Contains the mainClient<Context> type with methods for:
- Creating and managing groups
- Sending and receiving messages
- Identity management
- Device synchronization
context
DefinesXmtpMlsLocalContext which centralizes dependencies:
- API client
- Storage/database
- Identity manager
- Group locks
- Event streams
groups
Group conversation management including:- Creating groups
- Adding/removing members
- Sending messages
- Group permissions and metadata
- DM (direct message) support
identity
Identity and authentication:- Installation identities
- Key package management
- Credential verification
messages
Message handling:- Encoding/decoding messages
- Content types
- Message delivery status
- Message enrichment
subscriptions
Real-time event subscriptions:- New messages
- Group updates
- Identity changes
Main Types and Traits
Generic client parameterized by context type. Provides all MLS operations.Key Methods:
create_group()- Create a new group conversationcreate_dm()- Create a direct message conversationgroup()- Get an existing groupconversations()- List all conversationssync()- Synchronize with network
Represents a group conversation.Key Methods:
send_message()- Send a message to the groupadd_members()- Add members to the groupremove_members()- Remove members from the groupmessages()- Retrieve messagessync()- Sync group state
Builder pattern for constructing clients.Methods:
api_client()- Set API clientidentity()- Set identitystore()- Set storagebuild()- Construct the client
Usage Examples
Creating a Client
Creating a Group
Sending Messages
Receiving Messages
Subscribing to Events
Features
Utilities for testing, including mock implementations and test helpers.
Benchmarking utilities and performance testing tools.
Decentralized API support.
Version 3 protocol support.
Development configuration and utilities.
Error Handling
The crate uses structured error types:Platform Support
- Native (Linux, macOS, Windows)
- WebAssembly (WASM)
- iOS (via FFI bindings)
- Android (via FFI bindings)
Dependencies
Key dependencies include:openmls- MLS protocol implementationxmtp_db- Storage layerxmtp_id- Identity managementxmtp_proto- Protocol definitionsxmtp_cryptography- Cryptographic primitives
