function workerFunction(){self.onmessage=function(e){const{type:t,data:s}=e.data;if(t==="pow"){const{challenge:i,salt:a,startNonce:r,endNonce:c,target:l,batchId:o}=s;let e=0,t=null;n(r);function n(s){const r=String(i)+String(a)+s.toString(),d=(new TextEncoder).encode(r);crypto.subtle.digest("SHA-256",d).then(i=>{const a=Array.from(new Uint8Array(i)),r=a.map(e=>e.toString(16).padStart(2,"0")).join("");if(e++,r.startsWith(l)){t={nonce:s.toString(),found:!0},self.postMessage({type:"pow_result",solution:t,count:e,batchId:o});return}e%1e3===0&&self.postMessage({type:"progress",count:e,batchId:o}),sn(s+1),0):t||self.postMessage({type:"pow_result",solution:null,count:e,batchId:o})}).catch(e=>{self.postMessage({type:"error",error:"Crypto API error: "+e.message})})}}else self.postMessage({type:"error",error:"Unknown message type: "+t})}}const workerCode="("+workerFunction.toString()+")()";function posWorkerFunction(){self.onmessage=async function(t){const{type:s,seedHex:n,isDecoy:o}=t.data;if(s==="pos"){const s=48,a=160;let t=parseInt(n.slice(0,8),16);t!=t&&(t=Math.floor(Math.random()*(a-s+1)));const b=o?s+(t*3+17)%(a-s+1):s+t%(a-s+1),r=b*1024*1024,i=4+t%5,l=Math.floor(r/i),m=4096,f=1024,p=35*1024*1024,g=3,v=new ArrayBuffer(r),c=new Uint8Array(v),j=new ArrayBuffer(16*1024*1024),d=new Uint8Array(j),u=[],h=[];for(let s=0;st);for(let e=t.length-1;e>0;e--){const n=o()%(e+1);[t[e],t[n]]=[t[n],t[e]]}const a=performance.now();for(let e=0;ee.toString(16).padStart(2,"0")).join("")),h.push(Math.round(b-a));for(let e=0;e>>0;function n(e,t){return(e<>>32-t)>>>0}return function(){const s=t[1]<<9;let e=t[0]*5>>>0;e=n(e,7)*9>>>0;const o=t[0]^t[2];return t[2]^=t[1],t[1]^=t[3],t[0]^=t[1],t[3]^=o,t[2]^=s,t[3]=n(t[3],11),e>>>0}}}const posWorkerCode="("+posWorkerFunction.toString()+")()";document.addEventListener("DOMContentLoaded",function(){setTimeout(e,650);function e(){const t=document.getElementById("verification-data"),o=t.getAttribute("data-target"),n=t.getAttribute("data-request-id");i();async function i(){try{const t=await fetch("/api/pow/challenge?id="+encodeURIComponent(n),{method:"GET",headers:{Accept:"application/json"}});if(!t.ok)throw new Error("Failed to get challenge parameters");const e=await t.json(),r=e.d,s=e.e||Math.random().toString(16).slice(2,18),i=e.f||[],a=new c(e,o,n,s,i);a.start()}catch(t){e("Verification setup failed: "+t.message)}}function a(){const e=new Blob([workerCode],{type:"text/javascript"});return new Worker(URL.createObjectURL(e))}function s(){const e=new Blob([posWorkerCode],{type:"text/javascript"});return new Worker(URL.createObjectURL(e))}function e(){const s=document.querySelector(".container");s.classList.add("error"),s.classList.remove("success");const i=document.querySelector(".spinner"),n=document.getElementById("status");n.style.display="inline-block",n.textContent="",n.classList.add("error"),n.classList.remove("success");const o=document.querySelector(".spinner-container");let t=document.getElementById("error-details");t||(t=document.createElement("div"),t.id="error-details",t.className="error-details",o.appendChild(t)),t.style.display="none"}function r(){document.querySelector(".container").classList.add("success"),document.getElementById("status").textContent="Redirecting"}function c(t,n,o,i,c){const l=[],d={};let u=null,h=!1;const p=navigator.hardwareConcurrency||4,f=Math.max(1,Math.floor(p*.8)),g=1488;this.start=function(){setTimeout(v,100)};async function v(){try{h=!0;let e,n;try{e=atob(t.a),n=atob(t.b)}catch(e){throw new Error(`Failed to decode challenge/salt: ${e.message}`)}const i="0".repeat(t.c);for(let t=0;tb(e.data),e.onerror=e=>{},l.push(e)}const s=Number.MAX_SAFE_INTEGER,o=Math.floor(s/f);for(let t=0;t{const n=s();n.onmessage=t=>{t.data.type==="pos_result"&&(e(t.data),n.terminate())},n.postMessage({type:"pos",seedHex:t.d,isDecoy:!1})}),a=await new Promise(e=>{const t=s();t.onmessage=n=>{n.data.type==="pos_result"&&(e(n.data),t.terminate())},t.postMessage({type:"pos",seedHex:i,isDecoy:!0})});await y({requestID:o,g:n.nonce,h:e.hashes,i:e.times,j:a.hashes,k:a.times,l:c})}catch(t){e(t.message)}}function m(){l.forEach(e=>e.terminate())}async function y(t){try{const s=await fetch("/api/pow/verify",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({request_id:t.requestID,g:t.g,h:t.h,i:t.i,j:t.j,k:t.k,l:t.l})});if(!s.ok){let t=`Verification failed: ${s.statusText}`;try{const e=await s.json();if(e&&e.error)t+=` - ${e.error}`;else{const e=await s.text();t+=` - Response: ${e}`}}catch{}e(t);return}r(),setTimeout(()=>{window.location.href=n},g)}catch{e("Verification failed. Please refresh the page.")}}}}})