Skip to main content

Overview

The xmtp_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 from lib.rs:
struct
The main client interface for XMTP MLS operations. Parameterized by context type to allow different API/DB combinations.
enum
Represents the network the client connects to:
  • Local(&'static str) - Local development network
  • Dev - Development network (default)
  • Prod - Production network
struct
A manager for group-specific semaphores to prevent concurrent modifications to the same group.
struct
A guard that releases the group semaphore when dropped, ensuring proper lock cleanup.

Core Modules

builder

Provides ClientBuilder for fluent construction of clients with identity, API, and storage configuration.

client

Contains the main Client<Context> type with methods for:
  • Creating and managing groups
  • Sending and receiving messages
  • Identity management
  • Device synchronization

context

Defines XmtpMlsLocalContext 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

struct
Generic client parameterized by context type. Provides all MLS operations.Key Methods:
  • create_group() - Create a new group conversation
  • create_dm() - Create a direct message conversation
  • group() - Get an existing group
  • conversations() - List all conversations
  • sync() - Synchronize with network
struct
Represents a group conversation.Key Methods:
  • send_message() - Send a message to the group
  • add_members() - Add members to the group
  • remove_members() - Remove members from the group
  • messages() - Retrieve messages
  • sync() - Sync group state
struct
Builder pattern for constructing clients.Methods:
  • api_client() - Set API client
  • identity() - Set identity
  • store() - Set storage
  • build() - Construct the client

Usage Examples

Creating a Client

Creating a Group

Sending Messages

Receiving Messages

Subscribing to Events

Features

feature
Utilities for testing, including mock implementations and test helpers.
feature
Benchmarking utilities and performance testing tools.
feature
Decentralized API support.
feature
Version 3 protocol support.
feature
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 implementation
  • xmtp_db - Storage layer
  • xmtp_id - Identity management
  • xmtp_proto - Protocol definitions
  • xmtp_cryptography - Cryptographic primitives