### 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. Wrap Your App with DMProvider ```tsx import { DMProvider } from '@/contexts/DMContext'; import { PROTOCOL_MODE } from '@/lib/dmConstants'; function App() { return ( {/* Your app components */} ); } ``` **Protocol Modes:** - `PROTOCOL_MODE.NIP04_ONLY` - Legacy encryption only - `PROTOCOL_MODE.NIP17_ONLY` - Modern private messages (recommended) - `PROTOCOL_MODE.BOTH` - Support both protocols ### 2. Send Messages ```tsx import { useDMContext } from '@/contexts/DMContext'; 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(); }}>