Alejandro Gómez 119f737d3d fix: Complete NIP-17 gift wrap persistence for self-chat
This commit implements a production-ready solution for NIP-17 gift wrap
sending and persistence, fixing the issue where self-chat messages
would appear optimistically but disappear on page reload.

**Root Causes Identified:**

1. **publishEvent ignored relay hints from actions**
   - ActionRunner calls publishMethod(event, relays) with two parameters
   - Our publishEvent only accepted one parameter (event)
   - Gift wrap actions passed inbox relays as second parameter → ignored
   - Gift wraps published to wrong relays or failed with no relay list

2. **Encrypted content not persisted during send**
   - Gift wraps created with EncryptedContentSymbol (in-memory only)
   - When received back from relay, new instance had no symbol
   - isGiftWrapUnlocked() returned false → marked as "pending"
   - Messages didn't appear in UI until manually decrypted

3. **Optimistic updates created duplicate risk**
   - Synthetic rumor created with timestamp T1, ID calculated
   - Real rumor created with timestamp T2, different ID
   - Potential for duplicates in UI on relay echo

**Changes:**

- src/services/hub.ts:
  * Modified publishEvent signature to accept optional relayHints parameter
  * Use relay hints when provided, fallback to outbox relay lookup
  * Added encrypted content persistence to Dexie for kind 1059 events
  * Persists decrypted content using EncryptedContentSymbol during publish
  * Fixed TypeScript null handling for getOutboxRelays return type
  * Added detailed console logging for relay routing debugging

- src/lib/chat/adapters/nip-17-adapter.ts:
  * Removed optimistic update code (lines 651-725)
  * Removed synthetic rumor creation and ID calculation
  * Removed immediate decryptedRumors$ update on send
  * Simplified sendMessage flow to rely on natural relay echo (~200-500ms)
  * Kept relay alignment debug logging for self-chat diagnostics

- src/services/gift-wrap.ts:
  * Added refreshPersistedIds() method for debugging
  * Allows manual reload of persisted IDs from Dexie if needed

**Expected Behavior After Fix:**

1. User sends self-chat message
2. SendWrappedMessage queries own inbox relays (kind 10050)
3. publishEvent receives relay hints, uses them for publishing
4. Gift wrap encrypted content persisted to Dexie during publish
5. Gift wrap sent to inbox relays (same relays we're subscribed to)
6. Gift wrap received back from relay (~200ms)
7. persistedIds check recognizes it as already unlocked
8. Message appears in UI and persists across reloads

**Testing Required:**

Manual testing checklist (see plan in /claudedocs/):
- Self-chat: send message, verify appears and persists on reload
- 1-on-1 chat: verify messages persist across reloads
- Group chat: verify multi-recipient messages work
- Reply functionality: verify reply threads persist
- Error cases: verify clear error messages for missing inbox relays

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 13:38:34 +01:00
2025-12-18 15:46:02 +01:00
👶
2025-12-09 16:26:31 +01:00
2025-12-19 12:49:29 +01:00
2025-12-13 15:06:05 +01:00
2025-12-10 13:00:39 +01:00
2025-12-22 20:40:16 +00:00
2025-12-20 14:25:40 +01:00
2026-01-14 19:24:37 +01:00
👶
2025-12-09 16:26:31 +01:00
👶
2025-12-09 16:26:31 +01:00
👶
2025-12-09 16:26:31 +01:00
👶
2025-12-09 16:26:31 +01:00
2025-12-14 16:50:16 +01:00

Grimoire

A Nostr protocol explorer and developer tool with a tiling window manager interface.

Features

  • Tiling Windows - Each window is a Nostr "app" (profile viewer, event feed, NIP docs, etc.)
  • Command Palette - Unix-style commands via Cmd+K to open apps and navigate
  • Multi-workspace - Virtual desktops with independent layouts
  • Real-time - Reactive event subscriptions with automatic updates

Stack

React 19, TypeScript, Vite, TailwindCSS, Jotai, Dexie, Applesauce

Getting Started

npm install
npm run dev

Scripts

Command Description
npm run dev Start dev server
npm run build Build for production
npm test Run tests in watch mode
npm run lint Lint code
npm run format Format code

License

MIT

Description
No description provided
Readme MIT 14 MiB
Languages
TypeScript 98.9%
CSS 0.8%
JavaScript 0.3%