diff options
Diffstat (limited to 'static/main.js')
-rw-r--r-- | static/main.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/static/main.js b/static/main.js new file mode 100644 index 0000000..73d98df --- /dev/null +++ b/static/main.js @@ -0,0 +1,25 @@ +document.addEventListener("DOMContentLoaded", async function() { + let challenge_b64 = document.body.dataset.identifier; + let difficulty = parseInt(document.body.dataset.difficulty); + let form = document.querySelector("form"); + let field = form.querySelector("input[name='powxy']"); + let status_el = document.getElementById("solver_status"); + + let identifier_bytes = Uint8Array.from( + atob(challenge_b64), + ch => ch.charCodeAt(0) + ); + + status_el.textContent = "Starting WebAssembly solver as a worker..."; + + let worker = new Worker("/.powxy/static/solver.js"); + + worker.onmessage = function(e) { + let { nonce, nonce_bytes } = e.data; + let nonce_str = String.fromCharCode(...nonce_bytes); + field.value = btoa(nonce_str); + status_el.textContent = "Challenge solved automatically in " + nonce + " iterations"; + }; + + worker.postMessage({ identifier_bytes, difficulty }); +}); |