This commit is contained in:
Tiago
2025-04-23 14:42:42 +01:00
parent 093b7882ed
commit 5f9dc1ddbd
4 changed files with 18 additions and 8 deletions
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@cap.js/widget",
"version": "0.1.1",
"version": "0.1.2",
"description": "Client-side widget for Cap. Cap is a lightweight, modern open-source CAPTCHA alternative designed using SHA-256 PoW.",
"keywords": [
"account security",
+15 -5
View File
@@ -90,7 +90,8 @@
? parseInt(workers, 10)
: navigator.hardwareConcurrency || 8
);
const fieldName = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
const fieldName =
this.getAttribute("data-cap-hidden-field-name") || "cap-token";
this.#host.innerHTML = `<input type="hidden" name="${fieldName}">`;
}
@@ -127,7 +128,8 @@
this.dispatchEvent("progress", { progress: 100 });
if (!resp.success) throw new Error("Invalid solution");
const fieldName = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
const fieldName =
this.getAttribute("data-cap-hidden-field-name") || "cap-token";
if (this.querySelector(`input[name='${fieldName}']`)) {
this.querySelector(`input[name='${fieldName}']`).value = resp.token;
}
@@ -324,7 +326,8 @@
}
this.dispatchEvent("reset");
this.token = null;
const fieldName = this.getAttribute("data-cap-hidden-field-name") || "cap-token";
const fieldName =
this.getAttribute("data-cap-hidden-field-name") || "cap-token";
if (this.querySelector(`input[name='${fieldName}']`)) {
this.querySelector(`input[name='${fieldName}']`).value = "";
}
@@ -407,8 +410,6 @@
document.adoptedStyleSheets.push(sheet);
const workerFunct = function () {
let initPromise, solve_pow_function;
if (
typeof WebAssembly !== "object" ||
typeof WebAssembly?.instantiate !== "function"
@@ -477,6 +478,8 @@
);
}
let initPromise, solve_pow_function;
initPromise = import(
"https://cdn.jsdelivr.net/npm/@cap.js/wasm@0.0.3/browser/cap_wasm.min.js"
)
@@ -493,8 +496,15 @@
});
self.onmessage = async ({ data: { salt, target } }) => {
const until = (predFn) => {
const poll = (done) =>
predFn() ? done() : setTimeout(() => poll(done), 500);
return new Promise(poll);
};
try {
await initPromise;
await until(() => !!solve_pow_function);
const startTime = performance.now();
const nonce = solve_pow_function(salt, target);