### Direct Messaging on Nostr This project includes a complete direct messaging system supporting both NIP-04 (legacy) and NIP-17 (modern, - more - private) encrypted messages with real-time subscriptions, optimistic updates, and a persistent - cache first - local storage. ## Quick Start ### 1. Enable Direct Messaging The `DMProvider` is already added to your app, but **disabled by default**. To enable messaging, pass `enabled: true` in the config: ```tsx import { DMProvider } from '@/components/DMProvider'; import { PROTOCOL_MODE } from '@/lib/dmConstants'; function App() { return ( {/* Your app components */} ); } ``` **Config Options:** - `enabled` (boolean, default: `false`) - Enable/disable entire DM system. When false, no messages are loaded, stored, or processed. - `protocolMode` (ProtocolMode, default: `PROTOCOL_MODE.NIP17_ONLY`) - Which protocols to support: - `PROTOCOL_MODE.NIP04_ONLY` - Legacy encryption only - `PROTOCOL_MODE.NIP17_ONLY` - Modern private messages (recommended) - `PROTOCOL_MODE.BOTH` - Support both protocols (for backwards compatibility) **Note**: The DM system uses domain-based IndexedDB naming (`nostr-dm-store-${hostname}`) to prevent conflicts between multiple apps on the same domain. ### 2. Send Messages ```tsx import { useDMContext } from '@/hooks/useDMContext'; import { MESSAGE_PROTOCOL } from '@/lib/dmConstants'; function ComposeMessage({ recipientPubkey }: { recipientPubkey: string }) { const { sendMessage } = useDMContext(); const [content, setContent] = useState(''); const handleSend = async () => { await sendMessage({ recipientPubkey, content, protocol: MESSAGE_PROTOCOL.NIP17, // Uses NIP-44 encryption + gift wrapping }); setContent(''); }; return (
{ e.preventDefault(); handleSend(); }}>