{
  "version": 3,
  "sources": ["captcha-solver.js"],
  "sourcesContent": ["const MAX_WORKERS = 8;\nconst TIMEOUT = 60 * 1000;\n\n/**\n * Whether the browser has the Web Crypto ALTCHA's worker solves with. It does\n * on a secure origin only - so not on local development's plain HTTP hosts.\n */\nexport function hasWebCrypto() {\n    return Boolean(window.crypto?.subtle);\n}\n\n/**\n * Find the number a captcha challenge asks for, with a worker on every core:\n * each takes every n-th number, and the one that comes across it answers for\n * all. Resolves with the solution, and rejects when none was found.\n *\n * `workerUrls` names the two there are: `native`, ALTCHA's own (`js/vendor/`),\n * and `fallback`, ours (`captcha-fallback-worker.js`), which does the same\n * work in plain JavaScript, several times slower, for a page with no Web\n * Crypto.\n *\n * NOTE: Imports nothing, so that the admin's login page can use it too - it\n *       has neither the frontend config nor jQuery (`js/admin/`).\n */\nexport function solveChallenge(challenge, workerUrls) {\n    const workerUrl = hasWebCrypto() ? workerUrls.native : workerUrls.fallback;\n    const count = Math.min(\n        MAX_WORKERS,\n        Math.max(1, navigator.hardwareConcurrency || 1),\n    );\n    const workers = [];\n    return new Promise((resolve, reject) => {\n        for (let index = 0; index < count; index++) {\n            const worker = new Worker(workerUrl);\n            workers.push(worker);\n            worker.addEventListener(\"error\", () => {\n                reject(new Error(\"The captcha worker failed.\"));\n            });\n            worker.addEventListener(\"message\", ({ data }) => {\n                if (data?.derivedKey) {\n                    resolve(data);\n                } else {\n                    // An error, or nothing at all once it ran out of time.\n                    reject(new Error(\"The captcha challenge was not solved.\"));\n                }\n            });\n            worker.postMessage({\n                type: \"work\",\n                challenge,\n                counterStart: index,\n                counterStep: count,\n                timeout: TIMEOUT,\n            });\n        }\n    }).finally(() => {\n        workers.forEach((worker) => worker.terminate());\n    });\n}\n"],
  "mappings": "AAAA,MAAMA,EAAc,EACdC,EAAU,IAMT,gBAAS,cAAe,CAC3B,MAAO,EAAQ,OAAO,QAAQ,MAClC,CAeO,gBAAS,eAAeC,EAAWC,EAAY,CAClD,MAAMC,EAAY,aAAa,EAAID,EAAW,OAASA,EAAW,SAC5DE,EAAQ,KAAK,IACf,EACA,KAAK,IAAI,EAAG,UAAU,qBAAuB,CAAC,CAClD,EACMC,EAAU,CAAC,EACjB,OAAO,IAAI,QAAQ,CAACC,EAASC,IAAW,CACpC,QAASC,EAAQ,EAAGA,EAAQJ,EAAOI,IAAS,CACxC,MAAMC,EAAS,IAAI,OAAON,CAAS,EACnCE,EAAQ,KAAKI,CAAM,EACnBA,EAAO,iBAAiB,QAAS,IAAM,CACnCF,EAAO,IAAI,MAAM,4BAA4B,CAAC,CAClD,CAAC,EACDE,EAAO,iBAAiB,UAAW,CAAC,CAAE,KAAAC,CAAK,IAAM,CACzCA,GAAM,WACNJ,EAAQI,CAAI,EAGZH,EAAO,IAAI,MAAM,uCAAuC,CAAC,CAEjE,CAAC,EACDE,EAAO,YAAY,CACf,KAAM,OACN,UAAAR,EACA,aAAcO,EACd,YAAaJ,EACb,QAAS,GACb,CAAC,CACL,CACJ,CAAC,EAAE,QAAQ,IAAM,CACbC,EAAQ,QAASI,GAAWA,EAAO,UAAU,CAAC,CAClD,CAAC,CACL",
  "names": ["MAX_WORKERS", "TIMEOUT", "challenge", "workerUrls", "workerUrl", "count", "workers", "resolve", "reject", "index", "worker", "data"]
}
