import { type XMTPMessage, type XMTPConfig, type XMTPConversation, type MessageHandler } from '@azeth/common'; import type { MessageRouter } from './message-router.js'; export type { XMTPConfig, XMTPConversation }; /** Parameters for sending a message via XMTP */ export interface SendMessageParams { /** Recipient Ethereum address */ to: `0x${string}`; /** Message content (text) */ content: string; /** Content type hint (default: 'text/plain') */ contentType?: string; } /** Interface for the XMTP messaging client */ export interface MessagingClient { /** Initialize the client with a private key and optional config */ initialize(privateKey: `0x${string}`, config?: XMTPConfig): Promise; /** Send a message to an Ethereum address. Returns the conversation ID. */ sendMessage(params: SendMessageParams): Promise; /** Register a handler for incoming messages. Returns an unsubscribe function. */ onMessage(handler: MessageHandler): () => void; /** Check if an address is reachable on the XMTP network */ canReach(address: `0x${string}`): Promise; /** List active conversations */ getConversations(): Promise; /** Whether the client has been successfully initialized */ isReady(): boolean; /** Tear down the client, stopping the agent and clearing state */ destroy(): Promise; } /** XMTP messaging client backed by @xmtp/agent-sdk. * * Provides E2E encrypted agent-to-agent messaging via the XMTP network. * Messages are rate-limited per sender and reachability results are cached. */ export declare class XMTPClient implements MessagingClient { private _agent; /** Static Client class from @xmtp/agent-sdk, used for fetchInboxStates. * The Agent's client instance doesn't expose this method, so we use the static version. */ private _ClientClass; private _xmtpEnv; private _handlers; private _rateLimiter; private _reachabilityCache; private _reachabilityCacheTtlMs; private _maxMessageLength; private _ready; private _listening; private _messageStreamAbort; private _convStreamAbort; private _messageRouter; private _autoReply; /** Initialize the XMTP client with a private key. * * Creates an XMTP Agent using the provided private key and config. * Must be called before any messaging operations. * * @param privateKey - Owner's private key (0x-prefixed hex) * @param config - Optional XMTP configuration * @throws AzethError if initialization fails */ initialize(privateKey: `0x${string}`, config?: XMTPConfig): Promise; /** Send a text message to an Ethereum address. * * Checks reachability, creates or finds a DM conversation, then sends. * * @param params - Message parameters (to, content, contentType) * @returns The conversation ID * @throws AzethError if the recipient is unreachable, content exceeds limits, or sending fails */ sendMessage(params: SendMessageParams): Promise; /** Register a handler for incoming messages. * * Starts the agent's message listener on first handler registration. * Returns an unsubscribe function that removes the handler. * * @param handler - Async function called for each incoming message * @returns Unsubscribe function */ onMessage(handler: MessageHandler): () => void; /** Check if an Ethereum address is reachable on the XMTP network. * * Results are cached with a configurable TTL (default 5 minutes). * Returns `false` on errors rather than throwing. * * @param address - Ethereum address to check * @returns Whether the address can receive XMTP messages */ canReach(address: `0x${string}`): Promise; /** List active XMTP conversations. * * @returns Array of conversation summaries */ getConversations(): Promise; /** Read recent messages from a specific conversation. * * Syncs conversations first, then fetches messages from the conversation * matching the given ID. Returns messages sorted by timestamp (newest first). * * @param conversationId - The XMTP conversation ID to read from * @param limit - Maximum number of messages to return (default 20, max 100) * @returns Array of messages with sender, content, and timestamp */ getMessages(conversationId: string, limit?: number): Promise; /** Read recent messages from a conversation with a specific peer address. * * Convenience method that finds the conversation by peer address * and reads messages from it. * * @param peerAddress - The Ethereum address of the conversation peer * @param limit - Maximum number of messages to return (default 20, max 100) * @returns Array of messages, or empty array if no conversation found */ getMessagesByPeer(peerAddress: `0x${string}`, limit?: number): Promise; /** Whether the client has been successfully initialized and is ready */ isReady(): boolean; /** Attach a MessageRouter for structured message dispatch. * * When a router is set and autoReply is enabled (via XMTPConfig or by * setting autoReply=true here), incoming messages are automatically * routed through the router and responses sent back to the sender. * * @param router - The MessageRouter instance to use for dispatch * @param autoReply - Enable auto-reply (default: uses config value) */ setRouter(router: MessageRouter, autoReply?: boolean): void; /** Tear down the XMTP client. * * Stops the agent, clears all handlers, caches, and timers. */ destroy(): Promise; private _requireReady; /** Start streaming incoming messages and new conversations */ private _startListening; /** Process a single incoming message from the stream */ private _handleIncoming; /** Extract peer address from a conversation object. * * Uses `peerInboxId` + `client.fetchInboxStates()` to resolve the peer's * wallet address. This avoids `conv.members()` which throws an internal * error in XMTP SDK v5 due to private field access issues on listed conversations. */ private _extractPeerAddress; } //# sourceMappingURL=xmtp.d.ts.map