diff --git a/.gitignore b/.gitignore index 6ab35fc..b350e1c 100644 --- a/.gitignore +++ b/.gitignore @@ -7,11 +7,13 @@ yarn-error.log* pnpm-debug.log* lerna-debug.log* + node_modules dist dist-ssr *.local .ai/ +yarn.lock # Editor directories and files .idea diff --git a/AGENTS.md b/AGENTS.md index 548e869..2f70f6a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -19,6 +19,7 @@ This project is a Nostr client application built with React 18.x, TailwindCSS 3. - `/src/components/`: UI components including NostrProvider for Nostr integration - `/src/components/ui/`: shadcn/ui components (48+ components available) - `/src/components/auth/`: Authentication-related components (LoginArea, LoginDialog, etc.) + - `/src/components/dm/`: Direct messaging UI components (DMMessagingInterface, DMConversationList, DMChatArea) - Zap components: `ZapButton`, `ZapDialog`, `WalletModal` for Lightning payments - `/src/hooks/`: Custom hooks including: - `useNostr`: Core Nostr protocol integration @@ -40,7 +41,9 @@ This project is a Nostr client application built with React 18.x, TailwindCSS 3. - `useShakespeare`: AI chat completions with Shakespeare AI API - `/src/pages/`: Page components used by React Router (Index, NotFound) - `/src/lib/`: Utility functions and shared logic -- `/src/contexts/`: React context providers (AppContext, NWCContext) +- `/src/contexts/`: React context providers (AppContext, NWCContext, DMContext) + - `useDMContext`: Hook exported from DMContext for direct messaging (NIP-04 & NIP-17) + - `useConversationMessages`: Hook exported from DMContext for paginated messages - `/src/test/`: Testing utilities including TestApp component - `/public/`: Static assets - `App.tsx`: Main app component with provider setup @@ -109,6 +112,8 @@ The project includes a **`docs/`** directory containing specialized documentatio - **`docs/NOSTR_INFINITE_SCROLL.md`**: Read when building feed interfaces, implementing pagination for Nostr events, or creating social media-style infinite scroll experiences. +- **`docs/NOSTR_DIRECT_MESSAGES.md`**: Read when implementing direct messaging features, building chat interfaces, or working with encrypted peer-to-peer communication (NIP-04 and NIP-17). + ## System Prompt Management The AI assistant's behavior and knowledge is defined by the AGENTS.md file, which serves as the system prompt. To modify the assistant's instructions or add new project-specific guidelines: @@ -744,6 +749,20 @@ function EditProfilePage() { The `EditProfileForm` component displays just the form. It requires no props, and will "just work" automatically. +### Direct Messaging (NIP-04 & NIP-17) + +The project includes a complete direct messaging system with real-time updates, encrypted storage, and support for both NIP-04 (legacy) and NIP-17 (modern private messaging) protocols. **The system is disabled by default** - enable it by passing `enabled: true` in the `DMProvider` config. + +For complete implementation guide including: +- Setup and configuration +- Sending messages and file attachments +- Using the `DMMessagingInterface` component +- Building custom messaging UIs +- Protocol comparison (NIP-04 vs NIP-17) +- Advanced features and architecture + +See **`docs/NOSTR_DIRECT_MESSAGES.md`** + ### Uploading Files on Nostr Use the `useUploadFile` hook to upload files. This hook uses Blossom servers for file storage and returns NIP-94 compatible tags. diff --git a/docs/NOSTR_DIRECT_MESSAGES.md b/docs/NOSTR_DIRECT_MESSAGES.md new file mode 100644 index 0000000..2d692c3 --- /dev/null +++ b/docs/NOSTR_DIRECT_MESSAGES.md @@ -0,0 +1,438 @@ +### 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 '@/contexts/DMContext'; +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 '@/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(); }}> +