From 935adfe4a28cedd17f97ea3a6be7ccbafe6c7cec Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Sun, 28 Jun 2026 03:21:07 -0700 Subject: Run silent-payment scanning in a Web Worker The EC crypto (candidate derivation + full scan) now runs in a worker, off the main thread, so even a large mainnet scan can't jank the UI at all. The worker is bundled separately and embedded as base64 (single-file app), spawned from a Blob URL; it holds the keys + per-tweak cache. If workers are unavailable or the bundle is missing, scanning falls back to the main thread (still cached + yielding). scanSilentPayments / _scanSpItems / _scanSpMempool now go through _spHitBlocks and _spScanItems, which dispatch to the worker (or the fallback). +27KB to index.html for the worker's crypto bundle. Verified via CDP: worker runs keys/candidates/scan correctly in-browser; a real reload + mainnet scan threw 0 exceptions and the SP address renders. Co-Authored-By: Claude Opus 4.8 (1M context) --- build.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'build.js') diff --git a/build.js b/build.js index 59c399b..97744b1 100644 --- a/build.js +++ b/build.js @@ -121,6 +121,21 @@ export async function buildJsQr({ minify = true } = {}) { return result.outputs[0].text(); } +// The silent-payment scanning worker, bundled separately (its own global scope) +// and embedded as base64 so the single-file app can spawn it from a Blob URL. +export async function buildSpWorker({ minify = true } = {}) { + const result = await Bun.build({ + entrypoints: ['./src/sp-worker.js'], + target: 'browser', + minify, + }); + if (!result.success) { + for (const log of result.logs) console.error(log); + throw new Error('sp-worker bundle failed'); + } + return result.outputs[0].text(); +} + export async function buildHtml({ minify = true, pwa = minify } = {}) { const result = await Bun.build({ entrypoints: ['./src/app.js'], @@ -134,6 +149,7 @@ export async function buildHtml({ minify = true, pwa = minify } = {}) { let js = await result.outputs[0].text(); // Guard against a literal inside the bundle closing our tag early. js = js.replaceAll(' @@ -149,6 +165,7 @@ ${pwa ? PWA_HEAD : ''}
+ ${pwa ? SW_REGISTER + '\n' : ''} `; -- cgit v1.2.3