aboutsummaryrefslogtreecommitdiffstats
path: root/src/verify-worker.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-09-03 22:55:03 -0700
committerAdam Soltys <[email protected]>2026-09-03 22:55:03 -0700
commit618a84ab96f1865f6112d696077390ba184dd9b3 (patch)
tree37d81fa5945dcc1395ac70479193207143140ac1 /src/verify-worker.js
parentc0c6f017324a07fc7850cc2a6b705415b8a9e85c (diff)
downloadcoinosv3-618a84ab96f1865f6112d696077390ba184dd9b3.tar.gz
coinosv3-618a84ab96f1865f6112d696077390ba184dd9b3.zip
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
Co-Authored-By: Claude Fable 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01MrkLsNScXe9b6BviUSdmMr
Diffstat (limited to 'src/verify-worker.js')
-rw-r--r--src/verify-worker.js19
1 files changed, 19 insertions, 0 deletions
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 });
+};