chat: migrate from NIP-04 to NIP-17 (NIP-44 + NIP-59 gift wrap) #40
Labels
No labels
app:activities
app:chat
app:events
app:forum
app:libra
app:market
app:restaurant
app:tasks
app:wallet
app:webapp
bug
enhancement
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
aiolabs/webapp#40
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Context
PR #39 migrated the market module order DMs from NIP-04 (kind 4, AES-256-CBC) to NIP-17 (kind 1059 gift wrap, NIP-44 v2 + NIP-59). The companion nostrmarket extension refactor (aiolabs/nostrmarket#2) refused to handle kind 4 anymore, so the market had to upgrade.
The chat module (
src/modules/chat/services/chat-service.ts) still uses NIP-04 for general user-to-user direct messages. NIP-04 is deprecated:Scope
Migrate
chat-serviceto NIP-17:Sending: replace
nip04.encrypt()+kind: 4finalizeEvent()(around chat-service.ts:364–367) withnip59.wrapEvent()producing kind 1059. The rumor useskind: 14per the NIP-17 spec.Receiving: replace the kind 4 subscription filters (chat-service.ts:528, 536, 634, 812, 819) with
{kinds: [1059], '#p': [userPubkey]}. Replacenip04.decrypt()(chat-service.ts:575, 741) withnip59.unwrapEvent().Re-attach market routing: once chat is on kind 1059, the market module can hand off its order gift-wrap subscription back to chat-service via
setMarketMessageHandler(handleOrderDM)— chat-service receives all 1059 events for the user and routes by content.useMarket.registerMarketMessageHandler()(composables/useMarket.ts:62–80) currently subscribes directly to kind 1059. There's a comment in that file noting this should revert once chat upgrades. Either:typefield (0/1/2) and forwards to the market handler.References
nostr-tools2.10.4 already exposesnip59.wrapEvent(),nip59.unwrapEvent(),nip44.encrypt(),nip44.decrypt()— no dep change needed.src/modules/market/services/nostrmarketService.tsandsrc/modules/market/composables/useMarket.ts).Notes
services.pysend_dm); see alsonip59.wrapManyEvents()in nostr-tools.