aboutsummaryrefslogtreecommitdiffstats
path: root/build.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2026-06-28 03:21:07 -0700
committerAdam Soltys <[email protected]>2026-06-28 03:21:07 -0700
commit935adfe4a28cedd17f97ea3a6be7ccbafe6c7cec (patch)
treeb4618b068e379e7feedd80b2a623433ed240018e /build.js
parente8edfd88b14ad07f5f97f5cb1d5d603d825a413d (diff)
downloadcoinosv3-935adfe4a28cedd17f97ea3a6be7ccbafe6c7cec.tar.gz
coinosv3-935adfe4a28cedd17f97ea3a6be7ccbafe6c7cec.zip
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) <[email protected]>
Diffstat (limited to 'build.js')
-rw-r--r--build.js17
1 files changed, 17 insertions, 0 deletions
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 </script> inside the bundle closing our tag early.
js = js.replaceAll('</script', '<\\/script');
+ const workerB64 = Buffer.from(await buildSpWorker({ minify })).toString('base64');
const css = await Bun.file('./src/style.css').text();
return `<!doctype html>
@@ -149,6 +165,7 @@ ${pwa ? PWA_HEAD : ''}<style>${css}</style>
</head>
<body>
<div id="app"></div>
+<script>globalThis.__SP_WORKER__=${JSON.stringify(workerB64)}</script>
<script>${js}</script>
${pwa ? SW_REGISTER + '\n' : ''}</body>
</html>`;