Replace NIP-04 messaging with NIP-17 (NIP-44 + NIP-59 gift wrapping)
Modernize the entire customer-merchant communication layer from deprecated NIP-04 (kind 4, AES-256-CBC) to NIP-17 private direct messages using NIP-44 v2 encryption (ChaCha20 + HMAC-SHA256) and NIP-59 gift wrapping (rumor/seal/gift-wrap protocol). No backwards compatibility retained. New modules: - nostr/nip44.py: NIP-44 v2 encryption verified against official spec vectors - nostr/nip59.py: NIP-59 gift wrap with wrap/unwrap convenience functions - tests/: 44 unit tests for NIP-44 and NIP-59 Key changes: - Subscription filters: kind 4 → kind 1059 gift wraps - Message handler: _handle_nip04_message → _handle_gift_wrap (unwrap + route) - send_dm/reply_to_structured_dm: NIP-59 gift wrap to recipient + self-archive - Merchant model: removed NIP-04 crypto methods (decrypt/encrypt/build_dm_event) - helpers.py: removed NIP-04 functions, kept Schnorr signing + key normalization - views_api.py: consolidated DM sending through send_dm() service function Reliability improvements: - Event deduplication via bounded LRU set in NostrClient - Subscription health monitor (resubscribes after 120s of silence) - Preserved 5-minute lenient time window from prior work Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
319d5eeb04
commit
725944ae9c
13 changed files with 869 additions and 165 deletions
17
__init__.py
17
__init__.py
|
|
@ -27,7 +27,11 @@ def nostrmarket_renderer():
|
|||
nostr_client: NostrClient = NostrClient()
|
||||
|
||||
|
||||
from .tasks import wait_for_nostr_events, wait_for_paid_invoices # noqa
|
||||
from .tasks import ( # noqa
|
||||
subscription_health_monitor,
|
||||
wait_for_nostr_events,
|
||||
wait_for_paid_invoices,
|
||||
)
|
||||
from .views import * # noqa
|
||||
from .views_api import * # noqa
|
||||
|
||||
|
|
@ -65,4 +69,13 @@ def nostrmarket_start():
|
|||
task3 = create_permanent_unique_task(
|
||||
"ext_nostrmarket_wait_for_events", _wait_for_nostr_events
|
||||
)
|
||||
scheduled_tasks.extend([task1, task2, task3])
|
||||
|
||||
async def _health_monitor():
|
||||
# start after the subscription is active
|
||||
await asyncio.sleep(20)
|
||||
await subscription_health_monitor(nostr_client)
|
||||
|
||||
task4 = create_permanent_unique_task(
|
||||
"ext_nostrmarket_health_monitor", _health_monitor
|
||||
)
|
||||
scheduled_tasks.extend([task1, task2, task3, task4])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue