5. @fleetmesh/dm#

@fleetmesh/dm implements browser-side direct messaging for FleetMesh: bilateral conversations, message storage and unread counters, consolidated inbox and outbox views, NIP-44 message body sealing, and synchronization with mediated leaf deliveries and host mailboxes. Its host-side counterpart is Direct-Message Host Stores (fleetmesh_protocols.dm).

5.1. Installation#

npm install @fleetmesh/dm@next @fleetmesh/circles@next @fleetmesh/textile@next @fleetmesh/leaf@next

Runtime dependencies are @fleetmesh/circles and @fleetmesh/textile.

Conversation state is persisted locally in the browser (loadDmState, saveDmState). Outbound transmission is delegated to the host adapter: sendDirectMessage persists the message with status sending and passes it to the host adapter, which delivers it either as a mediated DIDComm envelope via a leaf session or through the host’s HTTP API.

5.2. Modules#

Module

Description

dmConversations

Bilateral conversation management (one conversation per pair of identities): ensureDmConversationForPeer, getDmConversations, getDmMessages, getUnreadDmSummary, and markDmConversationRead.

dmMessaging

Outbound and inbound message handling: sendDirectMessage (supporting plain text and structured attachments such as circle invitations) and deliverInboundDirectMessage.

dmSealing

sealDmBody(senderDid, recipientDid, body) encrypts message bodies with NIP-44 to the recipient using the browser’s NIP-07 signer (window.nostr), returning null when no signer is present or the active signer does not match the sender. openSealedDms() decrypts all sealed records accessible to the active signer and returns the count opened; unopened records render SEALED_DM_PLACEHOLDER.

dmSync

State synchronization: syncLeafInboxToDmStore (ingesting deliveries retrieved by a leaf) and syncServerDmSummaryToStore / refreshDmConversationsFromServer (synchronizing with the host mailbox).

dmConsolidatedBox, dmMeshPeersAndBox

Unified inbox/outbox view (getConsolidatedDmBox) and mesh peer discovery helpers (collectMeshPeerIdentities, formatPeerDidFingerprint).

dmTypesAndState

Type definitions for conversations, messages, attachments, and serialized client state.

hostAdapter

configureDmHost registration for outbound delivery (sendServerDirectMessage, sendMediatedDidcommEnvelope, pickupFromMediator), server read-state synchronization, conversation retrieval, notifications, and typing indicators.

5.3. Host Adapter#

DmHostAdapter defines the complete interface between @fleetmesh/dm and its host environment. Transport delivery is provided by sendMediatedDidcommEnvelope (via the user’s mediator) and sendServerDirectMessage (via the host API). fetchDmConversations and markServerDmRead synchronize state with the host mailbox, while notification and typing callbacks integrate with host UI layers. Any unconfigured adapter member follows the failure semantics specified in Browser Packages (@fleetmesh/*), returning an explicit failure rather than reporting synthetic delivery success.