widget: updates to the latest wasm version

This commit is contained in:
Tiago
2025-05-24 09:08:17 +01:00
parent c4e94efcfa
commit e3fd58fcb7
5 changed files with 76 additions and 4 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.11",
"version": "0.1.12",
"description": "Client-side widget for Cap, a lightweight, modern open-source CAPTCHA alternative designed using SHA-256 PoW.",
"keywords": [
"account security",
+1 -1
View File
@@ -218,7 +218,7 @@
target,
wasmUrl:
window.CAP_CUSTOM_WASM_URL ||
"https://cdn.jsdelivr.net/npm/@cap.js/wasm@0.0.3/browser/cap_wasm.min.js",
"https://cdn.jsdelivr.net/npm/@cap.js/wasm@0.0.4/browser/cap_wasm.min.js",
});
} catch (error) {
clearTimeout(timeout);
+72
View File
@@ -0,0 +1,72 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<script>
window.CAP_CUSTOM_FETCH = async (url, options) => {
if (url === "/api/challenge") {
const browserCrypto = window.crypto;
return new Response(
JSON.stringify({
challenge: Array.from({ length: 5 }, () => [
Array.from(
browserCrypto.getRandomValues(
new Uint8Array(Math.ceil(32 / 2))
)
)
.map((byte) => byte.toString(16).padStart(2, "0"))
.join("")
.slice(0, 32),
Array.from(
browserCrypto.getRandomValues(
new Uint8Array(Math.ceil(2 / 2))
)
)
.map((byte) => byte.toString(16).padStart(2, "0"))
.join("")
.slice(0, 4),
]),
token: "",
expires: new Date().getTime() + 6000 * 100,
}),
{
status: 200,
headers: { "Content-Type": "application/json" },
}
);
}
if (url === "/api/redeem") {
return new Response(
JSON.stringify({
success: true,
token: "ok",
expires: new Date().getTime() + 1000 * 60,
}),
{
status: 200,
headers: { "Content-Type": "application/json" },
}
);
}
return await window.fetch(url, options);
};
</script>
</head>
<body>
<script src="/widget.js"></script>
<cap-widget data-cap-api-endpoint="/api/"></cap-widget>
<script>
const widget = document.querySelector("cap-widget");
widget.solve();
widget.addEventListener("solve", function (e) {
fetch(e.detail.token === "ok" ? "/solved" : "/failed");
});
</script>
</body>
</html>