import initWasm, { solve } from './pow-solver/pow_solver' import wasmUrl from './pow-solver/pow_solver_bg.wasm?url' let ready: Promise | null = null function ensureReady() { ready ??= initWasm({ module_or_path: wasmUrl }).then(() => {}) return ready } /** * Solve a SHA-256 leading-zero-bits proof-of-work challenge. * Returns the decimal answer string expected by the backend * (pow-solver: sha256(`${nonce}:${answer}`) with >= difficulty leading zero bits). */ export async function solvePow( nonce: string, difficulty: number, maxAttempts = 20_000_000, ): Promise { await ensureReady() return solve(nonce, difficulty, maxAttempts) }