mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-29 00:42:30 +00:00
Watch history is stored as up to ~150 separately NIP-44-encrypted chunk events. Each chunk built a fresh cipher suite whose conversation-key cache lived only in its own closure, so the ECDH conversation key (~12ms each in the bundle) was re-derived once per chunk — multiplied across actor-candidate and scheme-fallback retries this synchronously blocked the main thread for up to ~20s after login/profile open (the reported freeze + fan spin-up). Memoize the derived key by (scheme, privateKey, target) at module scope so it is computed once per load and reused. Cleared on logout/identity change next to clearDecryptionSchemeCache so a derived shared secret never outlives its session. On the 150-chunk path this drops decrypt time ~1955ms -> ~182ms. Adds tests/nostr/watchHistoryConversationKeyCache.test.js covering: 150 chunks => one derivation, distinct identities derive independently (no cross-identity reuse), and cache-clear forces re-derivation. Co-Authored-By: Claude Opus 4.8 <[email protected]>