Overview
Thexmtp_api_d14n crate provides the decentralized (d14n) API implementation for XMTP, supporting both v3 (centralized MLS) and v4 (decentralized) protocol endpoints. This implementation follows the XIP-49 Decentralized Backend specification.
Source Location
crates/xmtp_api_d14n/
Architecture
The crate is organized into three main components:File Hierarchy
endpoints/- gRPC endpoints for v3 and decentralization protobuf interface
- Divided into
v3/(centralized) andd14n/(decentralized) modules
- Query implementations according to the XMTP Protocol Interface
- XMTP d14n implementation according to the d14n XIP
- Backend configuration for decentralized network
Decentralized (D14n) Endpoints
The d14n endpoints implement the v4 decentralized protocol:PublishClientEnvelopes
Publishes client envelopes to the decentralized network./xmtp.xmtpv4.payer_api.PayerApi/PublishClientEnvelopes
Builder Example:
QueryEnvelopes
Queries envelopes from the network with filtering options./xmtp.xmtpv4.message_api.ReplicationApi/QueryEnvelopes
Builder Example:
QueryEnvelope (Single)
Queries a single envelope topic.SubscribeEnvelopes
Subscribes to envelope updates in real-time./xmtp.xmtpv4.message_api.ReplicationApi/SubscribeEnvelopes
Builder Example:
GetInboxIds
Retrieves inbox IDs for given addresses. Endpoint: Defined inendpoints/d14n/get_inbox_ids.rs
GetNewestEnvelopes
Fetches the newest envelopes from the network. Endpoint: Defined inendpoints/d14n/get_newest_envelopes.rs
HealthCheck
Checks the health status of the decentralized network nodes. Endpoint: Defined inendpoints/d14n/health_check.rs
GetNodes
Retrieves information about available network nodes. Endpoint: Defined inendpoints/d14n/get_nodes.rs
FetchD14nCutover
Fetches the cutover information for transitioning to the decentralized network. Endpoint: Defined inendpoints/d14n/fetch_d14n_cutover.rs
V3 Endpoints
The v3 endpoints provide compatibility with the centralized MLS Group Chat implementation:Identity Endpoints (v3/identity/)
GetIdentityUpdatesV2- Retrieves identity updates for inboxes
- Source:
endpoints/v3/identity/get_identity_updates_v2.rs
- Maps addresses to inbox IDs
- Source:
endpoints/v3/identity/get_inbox_ids.rs
- Publishes identity updates to the network
- Source:
endpoints/v3/identity/publish_identity_update.rs
- Verifies signatures from smart contract wallets
- Source:
endpoints/v3/identity/verify_smart_contract_wallet_signatures.rs
MLS Endpoints (v3/mls/)
FetchKeyPackages- Fetches key packages for installations
- Source:
endpoints/v3/mls/fetch_key_packages.rs
- Retrieves the newest message for a group
- Source:
endpoints/v3/mls/get_newest_group_message.rs
endpoints/v3/mls/ directory.
Endpoint Trait
All endpoints implement theEndpoint trait from xmtp_proto:
Usage with API Client
Unary Request:Protocol Interface
The d14n protocol implements the client-to-node protocol as specified in XIP-49 Section 3.3. Key Components:- Client envelope authentication
- Topic-based message routing
- Global cursor-based pagination
- Originator node filtering
- Real-time envelope subscriptions
Configuration
Theconfig module provides backend configuration for connecting to the decentralized network:
- Node discovery
- Network topology
- Connection parameters
Type Definitions
Common types used throughout the d14n API: Topics:Builder Pattern
All endpoints use thederive_builder crate for ergonomic construction:
- Type-safe construction
- Optional field handling
- Validation before building
- Fluent API interface
Testing
The crate includes test utilities and clients: XmtpdClient - Test client for d14n endpoints GatewayClient - Test client for gateway endpointsMigration from V3 to D14n
TheFetchD14nCutover endpoint helps coordinate the migration from v3 (centralized) to v4 (decentralized) infrastructure:
- Query cutover status
- Determine migration timeline
- Switch to decentralized endpoints
- Maintain backward compatibility during transition
Related XIPs
Related Crates
xmtp_api- Core trait definitionsxmtp_api_grpc- gRPC client implementationxmtp_proto- Protocol buffer definitions
