Add proof-of-work challenge, session hub support, and status metrics across backend and frontend apps.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b841c2d1f6
commit
9647ac8c50
29 files changed
+1492
-292
No files matched your search
@@ -0,0 +1,22 @@
|
||||
export type Solver = (challenge: string, difficulty: number) => Promise<number>;
|
||||
|
||||
/** Solves the proof of work in a worker, so the page stays responsive meanwhile. */
|
||||
export const solveInWorker: Solver = (challenge, difficulty) => new Promise((resolve, reject) =>
|
||||
{
|
||||
const worker = new Worker(new URL('./proof.worker.ts', import.meta.url), { type: 'module' });
|
||||
|
||||
worker.onmessage = ({ data }: MessageEvent<number | undefined>) =>
|
||||
{
|
||||
worker.terminate();
|
||||
if (data === undefined) reject(new Error('no solution found'));
|
||||
else resolve(data);
|
||||
};
|
||||
|
||||
worker.onerror = (event) =>
|
||||
{
|
||||
worker.terminate();
|
||||
reject(new Error(event.message));
|
||||
};
|
||||
|
||||
worker.postMessage({ challenge, difficulty });
|
||||
});
|
||||
Reference in new issue
Block a user