From 618a84ab96f1865f6112d696077390ba184dd9b3 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Thu, 3 Sep 2026 22:55:03 -0700 Subject: Nostr signature verification moves off the main thread: the pool's synchronous verifyEvent (a schnorr check per event, ~560ms on a relay backlog — the profiled carousel-stutter cause) is switched off, and every event is now gated through a Web Worker before any caller sees it. Nothing unverified is ever trusted — the worker runs the same nostr-tools verifyEvent, just on another thread, with a synchronous fallback if the worker is unavailable (standalone file://) or stalls. Bundled to dist/verify-worker.js, precached in the SW MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_01MrkLsNScXe9b6BviUSdmMr --- src/verify-worker.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 src/verify-worker.js (limited to 'src/verify-worker.js') diff --git a/src/verify-worker.js b/src/verify-worker.js new file mode 100644 index 0000000..679c1a8 --- /dev/null +++ b/src/verify-worker.js @@ -0,0 +1,19 @@ +// Off-main-thread nostr event verification. Schnorr signature checks (real +// secp256k1) on a relay backlog blocked the UI on boot / when a community +// opens — the carousel-stutter cause a CPU profile pinned to verifyEvent. This +// worker does that work on another thread; the main thread posts events and +// gets back a boolean per event, so the page never freezes on a burst. +// +// Bundled to dist/verify-worker.js (see build.js) and loaded as a classic +// Worker. Same verifyEvent nostr-tools uses on the main thread, so semantics +// are identical — this only moves WHERE it runs. +import { verifyEvent } from 'nostr-tools/pure'; + +self.onmessage = (e) => { + const { reqId, events } = e.data || {}; + if (reqId == null || !Array.isArray(events)) return; + const results = events.map((ev) => { + try { return verifyEvent(ev); } catch { return false; } + }); + self.postMessage({ reqId, results }); +}; -- cgit v1.2.3