feat(market): migrate order DMs to NIP-17 (NIP-44 + NIP-59) #39

Merged
padreug merged 2 commits from feat/market-nip17-messaging into demo 2026-05-03 14:35:27 +00:00

2 commits

Author SHA1 Message Date
a0187a6604 fix(vite): rewrite to <app>.html when query has dots (JWT tokens)
The dev SPA-fallback plugin used `!req.url.includes('.')` to skip asset
requests, which also matched JWT-shaped `?token=hdr.body.sig` query
strings — so `localhost:5185/?token=...` fell through to the hub
`index.html` instead of `market.html`, breaking the hub→standalone
auth-relay link. Strip the query before the extension check.

Applied to all 7 standalone vite configs.
2026-05-03 16:02:06 +02:00
121f5cc342 feat(market): migrate order DMs to NIP-17 (NIP-44 + NIP-59 gift wrap)
The nostrmarket LNbits extension was refactored to NIP-17 messaging
(refactor/nip17-messaging branch, PR #2). Customers must send orders
as kind 1059 gift wraps so the merchant's _handle_gift_wrap() handler
can process them; kind 4 NIP-04 events are now ignored by the backend.

Changes:
- nostrmarketService.publishOrder(): replace nip04.encrypt + finalizeEvent
  (kind 4) with nip59.wrapEvent producing kind 1059. The order JSON sits
  in an unsigned kind 14 rumor, sealed (kind 13) with the customer's key,
  wrapped (kind 1059) with an ephemeral key.
- useMarket.handleOrderDM(): unwrap incoming kind 1059 via nip59.unwrapEvent
  instead of nip04.decrypt. Read sender pubkey from rumor.pubkey (the gift
  wrap's pubkey is ephemeral).
- useMarket.registerMarketMessageHandler(): bypass chat-service and
  subscribe directly to {kinds: [1059], '#p': [userPubkey]}. The chat
  service still uses NIP-04 - when it migrates to NIP-17 it can take
  over routing again via setMarketMessageHandler.

nostr-tools v2.10.4 (already a dep) provides the NIP-44/NIP-59 APIs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-05-03 12:28:45 +02:00