@private-captcha/private-captcha-js-core 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/index.js +1063 -0
  2. package/index.js.map +7 -0
  3. package/package.json +19 -0
package/index.js ADDED
@@ -0,0 +1,1063 @@
1
+ "use strict";
2
+ (() => {
3
+ // node_modules/base64-arraybuffer/dist/base64-arraybuffer.es5.js
4
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
5
+ var lookup = typeof Uint8Array === "undefined" ? [] : new Uint8Array(256);
6
+ for (i = 0; i < chars.length; i++) {
7
+ lookup[chars.charCodeAt(i)] = i;
8
+ }
9
+ var i;
10
+ var encode = function(arraybuffer) {
11
+ var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = "";
12
+ for (i = 0; i < len; i += 3) {
13
+ base64 += chars[bytes[i] >> 2];
14
+ base64 += chars[(bytes[i] & 3) << 4 | bytes[i + 1] >> 4];
15
+ base64 += chars[(bytes[i + 1] & 15) << 2 | bytes[i + 2] >> 6];
16
+ base64 += chars[bytes[i + 2] & 63];
17
+ }
18
+ if (len % 3 === 2) {
19
+ base64 = base64.substring(0, base64.length - 1) + "=";
20
+ } else if (len % 3 === 1) {
21
+ base64 = base64.substring(0, base64.length - 2) + "==";
22
+ }
23
+ return base64;
24
+ };
25
+ var decode = function(base64) {
26
+ var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
27
+ if (base64[base64.length - 1] === "=") {
28
+ bufferLength--;
29
+ if (base64[base64.length - 2] === "=") {
30
+ bufferLength--;
31
+ }
32
+ }
33
+ var arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
34
+ for (i = 0; i < len; i += 4) {
35
+ encoded1 = lookup[base64.charCodeAt(i)];
36
+ encoded2 = lookup[base64.charCodeAt(i + 1)];
37
+ encoded3 = lookup[base64.charCodeAt(i + 2)];
38
+ encoded4 = lookup[base64.charCodeAt(i + 3)];
39
+ bytes[p++] = encoded1 << 2 | encoded2 >> 4;
40
+ bytes[p++] = (encoded2 & 15) << 4 | encoded3 >> 2;
41
+ bytes[p++] = (encoded3 & 3) << 6 | encoded4 & 63;
42
+ }
43
+ return arraybuffer;
44
+ };
45
+
46
+ // js/puzzle.js
47
+ var PUZZLE_BUFFER_LENGTH = 128;
48
+ var ACCEPTABLE_CLIENT_ERRORS = [408, 409, 429];
49
+ async function getPuzzle(endpoint, sitekey) {
50
+ try {
51
+ const response = await fetchWithBackoff(
52
+ `${endpoint}?sitekey=${sitekey}`,
53
+ { headers: [["x-pc-captcha-version", "1"]], mode: "cors" },
54
+ 3
55
+ /*max attempts*/
56
+ );
57
+ if (response.ok) {
58
+ const data = await response.text();
59
+ return data;
60
+ } else {
61
+ let json = await response.json();
62
+ if (json && json.error) {
63
+ throw Error(json.error);
64
+ }
65
+ }
66
+ } catch (err) {
67
+ console.error("[privatecaptcha]", err);
68
+ throw err;
69
+ }
70
+ throw Error("Internal error");
71
+ }
72
+ function wait(delay) {
73
+ return new Promise((resolve) => setTimeout(resolve, delay));
74
+ }
75
+ async function fetchWithBackoff(url, options, maxAttempts, initialDelay = 800, maxDelay = 6e3) {
76
+ for (let attempt = 0; attempt < maxAttempts; attempt++) {
77
+ if (attempt > 0) {
78
+ const delay = Math.min(initialDelay * Math.pow(2, attempt), maxDelay);
79
+ await wait(delay);
80
+ }
81
+ try {
82
+ const response = await fetch(url, options);
83
+ if (response.ok) {
84
+ return response;
85
+ } else {
86
+ console.warn("[privatecaptcha]", `HTTP request failed. status=${response.status}`);
87
+ }
88
+ if (response.status >= 400 && response.status < 500 && !ACCEPTABLE_CLIENT_ERRORS.includes(response.status)) {
89
+ break;
90
+ } else {
91
+ continue;
92
+ }
93
+ } catch (err) {
94
+ console.error("[privatecaptcha]", err);
95
+ }
96
+ }
97
+ throw new Error("Maximum number of attempts exceeded");
98
+ }
99
+ function readUInt32LE(binaryData, offset) {
100
+ return (binaryData[offset] | binaryData[offset + 1] << 8 | binaryData[offset + 2] << 16 | binaryData[offset + 3] << 24) >>> 0;
101
+ }
102
+ function readUInt64LE(binaryData, offset) {
103
+ return BigInt(readUInt32LE(binaryData, offset)) + (BigInt(readUInt32LE(binaryData, offset + 4)) << 32n);
104
+ }
105
+ var Puzzle = class {
106
+ constructor(rawData) {
107
+ this.puzzleBuffer = null;
108
+ this.ID = null;
109
+ this.difficulty = null;
110
+ this.solutionsCount = null;
111
+ this.expirationTimestamp = null;
112
+ this.userData = null;
113
+ this.signature = null;
114
+ this.parse(rawData);
115
+ this.rawData = rawData;
116
+ }
117
+ parse(rawData) {
118
+ const parts = rawData.split(".");
119
+ if (parts.length !== 2) {
120
+ throw Error(`Invalid amount of parts: ${parts.length}`);
121
+ }
122
+ const buffer = parts[0];
123
+ this.signature = parts[1];
124
+ const data = new Uint8Array(decode(buffer));
125
+ let offset = 0;
126
+ offset += 1;
127
+ offset += 16;
128
+ this.ID = readUInt64LE(data, offset);
129
+ offset += 8;
130
+ this.difficulty = data[offset];
131
+ offset += 1;
132
+ this.solutionsCount = data[offset];
133
+ offset += 1;
134
+ this.expirationTimestamp = readUInt32LE(data, offset);
135
+ offset += 4;
136
+ offset += 4;
137
+ const userDataSize = 16;
138
+ this.userData = data.slice(offset, offset + userDataSize);
139
+ offset += userDataSize;
140
+ let puzzleBuffer = data;
141
+ if (puzzleBuffer.length < PUZZLE_BUFFER_LENGTH) {
142
+ const enlargedBuffer = new Uint8Array(PUZZLE_BUFFER_LENGTH);
143
+ enlargedBuffer.set(puzzleBuffer);
144
+ this.puzzleBuffer = enlargedBuffer;
145
+ } else {
146
+ this.puzzleBuffer = puzzleBuffer;
147
+ }
148
+ }
149
+ isZero() {
150
+ return this.ID === 0n && this.difficulty === 0 && this.expirationTimestamp === 0;
151
+ }
152
+ expirationMillis() {
153
+ if (!this.expirationTimestamp) {
154
+ return 0;
155
+ }
156
+ const expiration = new Date(this.expirationTimestamp * 1e3);
157
+ const currentDate = /* @__PURE__ */ new Date();
158
+ const diff = expiration - currentDate;
159
+ return diff;
160
+ }
161
+ };
162
+
163
+ // inline-worker:__inline-worker
164
+ function inlineWorker(scriptText) {
165
+ let blob = new Blob([scriptText], { type: "text/javascript" });
166
+ let url = URL.createObjectURL(blob);
167
+ let worker = new Worker(url);
168
+ URL.revokeObjectURL(url);
169
+ return worker;
170
+ }
171
+
172
+ // js/puzzle.worker.js
173
+ function Worker2() {
174
+ return inlineWorker('var __create = Object.create;\nvar __defProp = Object.defineProperty;\nvar __getOwnPropDesc = Object.getOwnPropertyDescriptor;\nvar __getOwnPropNames = Object.getOwnPropertyNames;\nvar __getProtoOf = Object.getPrototypeOf;\nvar __hasOwnProp = Object.prototype.hasOwnProperty;\nvar __commonJS = (cb, mod) => function __require() {\n return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;\n};\nvar __copyProps = (to, from, except, desc) => {\n if (from && typeof from === "object" || typeof from === "function") {\n for (let key of __getOwnPropNames(from))\n if (!__hasOwnProp.call(to, key) && key !== except)\n __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });\n }\n return to;\n};\nvar __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(\n // If the importer is in node compatibility mode or this is not an ESM\n // file that has been converted to a CommonJS file using a Babel-\n // compatible transform (i.e. "__esModule" has not been set), then set\n // "default" to the CommonJS "module.exports" for node compatibility.\n isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,\n mod\n));\n\n// node_modules/nanoassert/index.js\nvar require_nanoassert = __commonJS({\n "node_modules/nanoassert/index.js"(exports, module) {\n module.exports = assert;\n var AssertionError = class extends Error {\n };\n AssertionError.prototype.name = "AssertionError";\n function assert(t, m) {\n if (!t) {\n var err = new AssertionError(m);\n if (Error.captureStackTrace) Error.captureStackTrace(err, assert);\n throw err;\n }\n }\n }\n});\n\n// node_modules/b4a/lib/ascii.js\nvar require_ascii = __commonJS({\n "node_modules/b4a/lib/ascii.js"(exports, module) {\n function byteLength(string) {\n return string.length;\n }\n function toString(buffer) {\n const len = buffer.byteLength;\n let result = "";\n for (let i = 0; i < len; i++) {\n result += String.fromCharCode(buffer[i]);\n }\n return result;\n }\n function write(buffer, string, offset = 0, length = byteLength(string)) {\n const len = Math.min(length, buffer.byteLength - offset);\n for (let i = 0; i < len; i++) {\n buffer[offset + i] = string.charCodeAt(i);\n }\n return len;\n }\n module.exports = {\n byteLength,\n toString,\n write\n };\n }\n});\n\n// node_modules/b4a/lib/base64.js\nvar require_base64 = __commonJS({\n "node_modules/b4a/lib/base64.js"(exports, module) {\n var alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";\n var codes = new Uint8Array(256);\n for (let i = 0; i < alphabet.length; i++) {\n codes[alphabet.charCodeAt(i)] = i;\n }\n codes[\n /* - */\n 45\n ] = 62;\n codes[\n /* _ */\n 95\n ] = 63;\n function byteLength(string) {\n let len = string.length;\n if (string.charCodeAt(len - 1) === 61) len--;\n if (len > 1 && string.charCodeAt(len - 1) === 61) len--;\n return len * 3 >>> 2;\n }\n function toString(buffer) {\n const len = buffer.byteLength;\n let result = "";\n for (let i = 0; i < len; i += 3) {\n result += alphabet[buffer[i] >> 2] + alphabet[(buffer[i] & 3) << 4 | buffer[i + 1] >> 4] + alphabet[(buffer[i + 1] & 15) << 2 | buffer[i + 2] >> 6] + alphabet[buffer[i + 2] & 63];\n }\n if (len % 3 === 2) {\n result = result.substring(0, result.length - 1) + "=";\n } else if (len % 3 === 1) {\n result = result.substring(0, result.length - 2) + "==";\n }\n return result;\n }\n function write(buffer, string, offset = 0, length = byteLength(string)) {\n const len = Math.min(length, buffer.byteLength - offset);\n for (let i = 0, j = 0; j < len; i += 4) {\n const a = codes[string.charCodeAt(i)];\n const b = codes[string.charCodeAt(i + 1)];\n const c = codes[string.charCodeAt(i + 2)];\n const d = codes[string.charCodeAt(i + 3)];\n buffer[j++] = a << 2 | b >> 4;\n buffer[j++] = (b & 15) << 4 | c >> 2;\n buffer[j++] = (c & 3) << 6 | d & 63;\n }\n return len;\n }\n module.exports = {\n byteLength,\n toString,\n write\n };\n }\n});\n\n// node_modules/b4a/lib/hex.js\nvar require_hex = __commonJS({\n "node_modules/b4a/lib/hex.js"(exports, module) {\n function byteLength(string) {\n return string.length >>> 1;\n }\n function toString(buffer) {\n const len = buffer.byteLength;\n buffer = new DataView(buffer.buffer, buffer.byteOffset, len);\n let result = "";\n let i = 0;\n for (let n = len - len % 4; i < n; i += 4) {\n result += buffer.getUint32(i).toString(16).padStart(8, "0");\n }\n for (; i < len; i++) {\n result += buffer.getUint8(i).toString(16).padStart(2, "0");\n }\n return result;\n }\n function write(buffer, string, offset = 0, length = byteLength(string)) {\n const len = Math.min(length, buffer.byteLength - offset);\n for (let i = 0; i < len; i++) {\n const a = hexValue(string.charCodeAt(i * 2));\n const b = hexValue(string.charCodeAt(i * 2 + 1));\n if (a === void 0 || b === void 0) {\n return buffer.subarray(0, i);\n }\n buffer[offset + i] = a << 4 | b;\n }\n return len;\n }\n module.exports = {\n byteLength,\n toString,\n write\n };\n function hexValue(char) {\n if (char >= 48 && char <= 57) return char - 48;\n if (char >= 65 && char <= 70) return char - 65 + 10;\n if (char >= 97 && char <= 102) return char - 97 + 10;\n }\n }\n});\n\n// node_modules/b4a/lib/utf8.js\nvar require_utf8 = __commonJS({\n "node_modules/b4a/lib/utf8.js"(exports, module) {\n function byteLength(string) {\n let length = 0;\n for (let i = 0, n = string.length; i < n; i++) {\n const code = string.charCodeAt(i);\n if (code >= 55296 && code <= 56319 && i + 1 < n) {\n const code2 = string.charCodeAt(i + 1);\n if (code2 >= 56320 && code2 <= 57343) {\n length += 4;\n i++;\n continue;\n }\n }\n if (code <= 127) length += 1;\n else if (code <= 2047) length += 2;\n else length += 3;\n }\n return length;\n }\n var toString;\n if (typeof TextDecoder !== "undefined") {\n const decoder = new TextDecoder();\n toString = function toString2(buffer) {\n return decoder.decode(buffer);\n };\n } else {\n toString = function toString2(buffer) {\n const len = buffer.byteLength;\n let output = "";\n let i = 0;\n while (i < len) {\n let byte = buffer[i];\n if (byte <= 127) {\n output += String.fromCharCode(byte);\n i++;\n continue;\n }\n let bytesNeeded = 0;\n let codePoint = 0;\n if (byte <= 223) {\n bytesNeeded = 1;\n codePoint = byte & 31;\n } else if (byte <= 239) {\n bytesNeeded = 2;\n codePoint = byte & 15;\n } else if (byte <= 244) {\n bytesNeeded = 3;\n codePoint = byte & 7;\n }\n if (len - i - bytesNeeded > 0) {\n let k = 0;\n while (k < bytesNeeded) {\n byte = buffer[i + k + 1];\n codePoint = codePoint << 6 | byte & 63;\n k += 1;\n }\n } else {\n codePoint = 65533;\n bytesNeeded = len - i;\n }\n output += String.fromCodePoint(codePoint);\n i += bytesNeeded + 1;\n }\n return output;\n };\n }\n var write;\n if (typeof TextEncoder !== "undefined") {\n const encoder = new TextEncoder();\n write = function write2(buffer, string, offset = 0, length = byteLength(string)) {\n const len = Math.min(length, buffer.byteLength - offset);\n encoder.encodeInto(string, buffer.subarray(offset, offset + len));\n return len;\n };\n } else {\n write = function write2(buffer, string, offset = 0, length = byteLength(string)) {\n const len = Math.min(length, buffer.byteLength - offset);\n buffer = buffer.subarray(offset, offset + len);\n let i = 0;\n let j = 0;\n while (i < string.length) {\n const code = string.codePointAt(i);\n if (code <= 127) {\n buffer[j++] = code;\n i++;\n continue;\n }\n let count = 0;\n let bits = 0;\n if (code <= 2047) {\n count = 6;\n bits = 192;\n } else if (code <= 65535) {\n count = 12;\n bits = 224;\n } else if (code <= 2097151) {\n count = 18;\n bits = 240;\n }\n buffer[j++] = bits | code >> count;\n count -= 6;\n while (count >= 0) {\n buffer[j++] = 128 | code >> count & 63;\n count -= 6;\n }\n i += code >= 65536 ? 2 : 1;\n }\n return len;\n };\n }\n module.exports = {\n byteLength,\n toString,\n write\n };\n }\n});\n\n// node_modules/b4a/lib/utf16le.js\nvar require_utf16le = __commonJS({\n "node_modules/b4a/lib/utf16le.js"(exports, module) {\n function byteLength(string) {\n return string.length * 2;\n }\n function toString(buffer) {\n const len = buffer.byteLength;\n let result = "";\n for (let i = 0; i < len - 1; i += 2) {\n result += String.fromCharCode(buffer[i] + buffer[i + 1] * 256);\n }\n return result;\n }\n function write(buffer, string, offset = 0, length = byteLength(string)) {\n const len = Math.min(length, buffer.byteLength - offset);\n let units = len;\n for (let i = 0; i < string.length; ++i) {\n if ((units -= 2) < 0) break;\n const c = string.charCodeAt(i);\n const hi = c >> 8;\n const lo = c % 256;\n buffer[offset + i * 2] = lo;\n buffer[offset + i * 2 + 1] = hi;\n }\n return len;\n }\n module.exports = {\n byteLength,\n toString,\n write\n };\n }\n});\n\n// node_modules/b4a/browser.js\nvar require_browser = __commonJS({\n "node_modules/b4a/browser.js"(exports, module) {\n var ascii = require_ascii();\n var base64 = require_base64();\n var hex = require_hex();\n var utf8 = require_utf8();\n var utf16le = require_utf16le();\n var LE = new Uint8Array(Uint16Array.of(255).buffer)[0] === 255;\n function codecFor(encoding) {\n switch (encoding) {\n case "ascii":\n return ascii;\n case "base64":\n return base64;\n case "hex":\n return hex;\n case "utf8":\n case "utf-8":\n case void 0:\n return utf8;\n case "ucs2":\n case "ucs-2":\n case "utf16le":\n case "utf-16le":\n return utf16le;\n default:\n throw new Error(`Unknown encoding: ${encoding}`);\n }\n }\n function isBuffer(value) {\n return value instanceof Uint8Array;\n }\n function isEncoding(encoding) {\n try {\n codecFor(encoding);\n return true;\n } catch (e) {\n return false;\n }\n }\n function alloc(size, fill2, encoding) {\n const buffer = new Uint8Array(size);\n if (fill2 !== void 0) exports.fill(buffer, fill2, 0, buffer.byteLength, encoding);\n return buffer;\n }\n function allocUnsafe(size) {\n return new Uint8Array(size);\n }\n function allocUnsafeSlow(size) {\n return new Uint8Array(size);\n }\n function byteLength(string, encoding) {\n return codecFor(encoding).byteLength(string);\n }\n function compare(a, b) {\n if (a === b) return 0;\n const len = Math.min(a.byteLength, b.byteLength);\n a = new DataView(a.buffer, a.byteOffset, a.byteLength);\n b = new DataView(b.buffer, b.byteOffset, b.byteLength);\n let i = 0;\n for (let n = len - len % 4; i < n; i += 4) {\n const x = a.getUint32(i, LE);\n const y = b.getUint32(i, LE);\n if (x !== y) break;\n }\n for (; i < len; i++) {\n const x = a.getUint8(i);\n const y = b.getUint8(i);\n if (x < y) return -1;\n if (x > y) return 1;\n }\n return a.byteLength > b.byteLength ? 1 : a.byteLength < b.byteLength ? -1 : 0;\n }\n function concat(buffers, totalLength) {\n if (totalLength === void 0) {\n totalLength = buffers.reduce((len, buffer) => len + buffer.byteLength, 0);\n }\n const result = new Uint8Array(totalLength);\n let offset = 0;\n for (const buffer of buffers) {\n if (offset + buffer.byteLength > result.byteLength) {\n const sub = buffer.subarray(0, result.byteLength - offset);\n result.set(sub, offset);\n return result;\n }\n result.set(buffer, offset);\n offset += buffer.byteLength;\n }\n return result;\n }\n function copy(source, target, targetStart = 0, start = 0, end = source.byteLength) {\n if (end > 0 && end < start) return 0;\n if (end === start) return 0;\n if (source.byteLength === 0 || target.byteLength === 0) return 0;\n if (targetStart < 0) throw new RangeError("targetStart is out of range");\n if (start < 0 || start >= source.byteLength) throw new RangeError("sourceStart is out of range");\n if (end < 0) throw new RangeError("sourceEnd is out of range");\n if (targetStart >= target.byteLength) targetStart = target.byteLength;\n if (end > source.byteLength) end = source.byteLength;\n if (target.byteLength - targetStart < end - start) {\n end = target.length - targetStart + start;\n }\n const len = end - start;\n if (source === target) {\n target.copyWithin(targetStart, start, end);\n } else {\n target.set(source.subarray(start, end), targetStart);\n }\n return len;\n }\n function equals(a, b) {\n if (a === b) return true;\n if (a.byteLength !== b.byteLength) return false;\n const len = a.byteLength;\n a = new DataView(a.buffer, a.byteOffset, a.byteLength);\n b = new DataView(b.buffer, b.byteOffset, b.byteLength);\n let i = 0;\n for (let n = len - len % 4; i < n; i += 4) {\n if (a.getUint32(i, LE) !== b.getUint32(i, LE)) return false;\n }\n for (; i < len; i++) {\n if (a.getUint8(i) !== b.getUint8(i)) return false;\n }\n return true;\n }\n function fill(buffer, value, offset, end, encoding) {\n if (typeof value === "string") {\n if (typeof offset === "string") {\n encoding = offset;\n offset = 0;\n end = buffer.byteLength;\n } else if (typeof end === "string") {\n encoding = end;\n end = buffer.byteLength;\n }\n } else if (typeof value === "number") {\n value = value & 255;\n } else if (typeof value === "boolean") {\n value = +value;\n }\n if (offset < 0 || buffer.byteLength < offset || buffer.byteLength < end) {\n throw new RangeError("Out of range index");\n }\n if (offset === void 0) offset = 0;\n if (end === void 0) end = buffer.byteLength;\n if (end <= offset) return buffer;\n if (!value) value = 0;\n if (typeof value === "number") {\n for (let i = offset; i < end; ++i) {\n buffer[i] = value;\n }\n } else {\n value = isBuffer(value) ? value : from(value, encoding);\n const len = value.byteLength;\n for (let i = 0; i < end - offset; ++i) {\n buffer[i + offset] = value[i % len];\n }\n }\n return buffer;\n }\n function from(value, encodingOrOffset, length) {\n if (typeof value === "string") return fromString(value, encodingOrOffset);\n if (Array.isArray(value)) return fromArray(value);\n if (ArrayBuffer.isView(value)) return fromBuffer(value);\n return fromArrayBuffer(value, encodingOrOffset, length);\n }\n function fromString(string, encoding) {\n const codec = codecFor(encoding);\n const buffer = new Uint8Array(codec.byteLength(string));\n codec.write(buffer, string, 0, buffer.byteLength);\n return buffer;\n }\n function fromArray(array) {\n const buffer = new Uint8Array(array.length);\n buffer.set(array);\n return buffer;\n }\n function fromBuffer(buffer) {\n const copy2 = new Uint8Array(buffer.byteLength);\n copy2.set(buffer);\n return copy2;\n }\n function fromArrayBuffer(arrayBuffer, byteOffset, length) {\n return new Uint8Array(arrayBuffer, byteOffset, length);\n }\n function includes(buffer, value, byteOffset, encoding) {\n return indexOf(buffer, value, byteOffset, encoding) !== -1;\n }\n function bidirectionalIndexOf(buffer, value, byteOffset, encoding, first) {\n if (buffer.byteLength === 0) return -1;\n if (typeof byteOffset === "string") {\n encoding = byteOffset;\n byteOffset = 0;\n } else if (byteOffset === void 0) {\n byteOffset = first ? 0 : buffer.length - 1;\n } else if (byteOffset < 0) {\n byteOffset += buffer.byteLength;\n }\n if (byteOffset >= buffer.byteLength) {\n if (first) return -1;\n else byteOffset = buffer.byteLength - 1;\n } else if (byteOffset < 0) {\n if (first) byteOffset = 0;\n else return -1;\n }\n if (typeof value === "string") {\n value = from(value, encoding);\n } else if (typeof value === "number") {\n value = value & 255;\n if (first) {\n return buffer.indexOf(value, byteOffset);\n } else {\n return buffer.lastIndexOf(value, byteOffset);\n }\n }\n if (value.byteLength === 0) return -1;\n if (first) {\n let foundIndex = -1;\n for (let i = byteOffset; i < buffer.byteLength; i++) {\n if (buffer[i] === value[foundIndex === -1 ? 0 : i - foundIndex]) {\n if (foundIndex === -1) foundIndex = i;\n if (i - foundIndex + 1 === value.byteLength) return foundIndex;\n } else {\n if (foundIndex !== -1) i -= i - foundIndex;\n foundIndex = -1;\n }\n }\n } else {\n if (byteOffset + value.byteLength > buffer.byteLength) {\n byteOffset = buffer.byteLength - value.byteLength;\n }\n for (let i = byteOffset; i >= 0; i--) {\n let found = true;\n for (let j = 0; j < value.byteLength; j++) {\n if (buffer[i + j] !== value[j]) {\n found = false;\n break;\n }\n }\n if (found) return i;\n }\n }\n return -1;\n }\n function indexOf(buffer, value, byteOffset, encoding) {\n return bidirectionalIndexOf(\n buffer,\n value,\n byteOffset,\n encoding,\n true\n /* first */\n );\n }\n function lastIndexOf(buffer, value, byteOffset, encoding) {\n return bidirectionalIndexOf(\n buffer,\n value,\n byteOffset,\n encoding,\n false\n /* last */\n );\n }\n function swap(buffer, n, m) {\n const i = buffer[n];\n buffer[n] = buffer[m];\n buffer[m] = i;\n }\n function swap16(buffer) {\n const len = buffer.byteLength;\n if (len % 2 !== 0) throw new RangeError("Buffer size must be a multiple of 16-bits");\n for (let i = 0; i < len; i += 2) swap(buffer, i, i + 1);\n return buffer;\n }\n function swap32(buffer) {\n const len = buffer.byteLength;\n if (len % 4 !== 0) throw new RangeError("Buffer size must be a multiple of 32-bits");\n for (let i = 0; i < len; i += 4) {\n swap(buffer, i, i + 3);\n swap(buffer, i + 1, i + 2);\n }\n return buffer;\n }\n function swap64(buffer) {\n const len = buffer.byteLength;\n if (len % 8 !== 0) throw new RangeError("Buffer size must be a multiple of 64-bits");\n for (let i = 0; i < len; i += 8) {\n swap(buffer, i, i + 7);\n swap(buffer, i + 1, i + 6);\n swap(buffer, i + 2, i + 5);\n swap(buffer, i + 3, i + 4);\n }\n return buffer;\n }\n function toBuffer(buffer) {\n return buffer;\n }\n function toString(buffer, encoding, start = 0, end = buffer.byteLength) {\n const len = buffer.byteLength;\n if (start >= len) return "";\n if (end <= start) return "";\n if (start < 0) start = 0;\n if (end > len) end = len;\n if (start !== 0 || end < len) buffer = buffer.subarray(start, end);\n return codecFor(encoding).toString(buffer);\n }\n function write(buffer, string, offset, length, encoding) {\n if (offset === void 0) {\n encoding = "utf8";\n } else if (length === void 0 && typeof offset === "string") {\n encoding = offset;\n offset = void 0;\n } else if (encoding === void 0 && typeof length === "string") {\n encoding = length;\n length = void 0;\n }\n return codecFor(encoding).write(buffer, string, offset, length);\n }\n function writeDoubleLE(buffer, value, offset) {\n if (offset === void 0) offset = 0;\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n view.setFloat64(offset, value, true);\n return offset + 8;\n }\n function writeFloatLE(buffer, value, offset) {\n if (offset === void 0) offset = 0;\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n view.setFloat32(offset, value, true);\n return offset + 4;\n }\n function writeUInt32LE(buffer, value, offset) {\n if (offset === void 0) offset = 0;\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n view.setUint32(offset, value, true);\n return offset + 4;\n }\n function writeInt32LE(buffer, value, offset) {\n if (offset === void 0) offset = 0;\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n view.setInt32(offset, value, true);\n return offset + 4;\n }\n function readDoubleLE(buffer, offset) {\n if (offset === void 0) offset = 0;\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n return view.getFloat64(offset, true);\n }\n function readFloatLE(buffer, offset) {\n if (offset === void 0) offset = 0;\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n return view.getFloat32(offset, true);\n }\n function readUInt32LE2(buffer, offset) {\n if (offset === void 0) offset = 0;\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n return view.getUint32(offset, true);\n }\n function readInt32LE(buffer, offset) {\n if (offset === void 0) offset = 0;\n const view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);\n return view.getInt32(offset, true);\n }\n module.exports = exports = {\n isBuffer,\n isEncoding,\n alloc,\n allocUnsafe,\n allocUnsafeSlow,\n byteLength,\n compare,\n concat,\n copy,\n equals,\n fill,\n from,\n includes,\n indexOf,\n lastIndexOf,\n swap16,\n swap32,\n swap64,\n toBuffer,\n toString,\n write,\n writeDoubleLE,\n writeFloatLE,\n writeUInt32LE,\n writeInt32LE,\n readDoubleLE,\n readFloatLE,\n readUInt32LE: readUInt32LE2,\n readInt32LE\n };\n }\n});\n\n// node_modules/blake2b-wasm/blake2b.js\nvar require_blake2b = __commonJS({\n "node_modules/blake2b-wasm/blake2b.js"(exports, module) {\n var __commonJS2 = (cb, mod) => function __require() {\n return mod || (0, cb[Object.keys(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;\n };\n var __toBinary = /* @__PURE__ */ (() => {\n var table = new Uint8Array(128);\n for (var i = 0; i < 64; i++)\n table[i < 26 ? i + 65 : i < 52 ? i + 71 : i < 62 ? i - 4 : i * 4 - 205] = i;\n return (base64) => {\n var n = base64.length, bytes2 = new Uint8Array((n - (base64[n - 1] == "=") - (base64[n - 2] == "=")) * 3 / 4 | 0);\n for (var i2 = 0, j = 0; i2 < n; ) {\n var c0 = table[base64.charCodeAt(i2++)], c1 = table[base64.charCodeAt(i2++)];\n var c2 = table[base64.charCodeAt(i2++)], c3 = table[base64.charCodeAt(i2++)];\n bytes2[j++] = c0 << 2 | c1 >> 4;\n bytes2[j++] = c1 << 4 | c2 >> 2;\n bytes2[j++] = c2 << 6 | c3;\n }\n return bytes2;\n };\n })();\n var require_blake2b3 = __commonJS2({\n "wasm-binary:./blake2b.wat"(exports2, module2) {\n module2.exports = __toBinary("AGFzbQEAAAABEANgAn9/AGADf39/AGABfwADBQQAAQICBQUBAQroBwdNBQZtZW1vcnkCAAxibGFrZTJiX2luaXQAAA5ibGFrZTJiX3VwZGF0ZQABDWJsYWtlMmJfZmluYWwAAhBibGFrZTJiX2NvbXByZXNzAAMKvz8EwAIAIABCADcDACAAQgA3AwggAEIANwMQIABCADcDGCAAQgA3AyAgAEIANwMoIABCADcDMCAAQgA3AzggAEIANwNAIABCADcDSCAAQgA3A1AgAEIANwNYIABCADcDYCAAQgA3A2ggAEIANwNwIABCADcDeCAAQoiS853/zPmE6gBBACkDAIU3A4ABIABCu86qptjQ67O7f0EIKQMAhTcDiAEgAEKr8NP0r+68tzxBECkDAIU3A5ABIABC8e30+KWn/aelf0EYKQMAhTcDmAEgAELRhZrv+s+Uh9EAQSApAwCFNwOgASAAQp/Y+dnCkdqCm39BKCkDAIU3A6gBIABC6/qG2r+19sEfQTApAwCFNwOwASAAQvnC+JuRo7Pw2wBBOCkDAIU3A7gBIABCADcDwAEgAEIANwPIASAAQgA3A9ABC20BA38gAEHAAWohAyAAQcgBaiEEIAQpAwCnIQUCQANAIAEgAkYNASAFQYABRgRAIAMgAykDACAFrXw3AwBBACEFIAAQAwsgACAFaiABLQAAOgAAIAVBAWohBSABQQFqIQEMAAsLIAQgBa03AwALYQEDfyAAQcABaiEBIABByAFqIQIgASABKQMAIAIpAwB8NwMAIABCfzcD0AEgAikDAKchAwJAA0AgA0GAAUYNASAAIANqQQA6AAAgA0EBaiEDDAALCyACIAOtNwMAIAAQAwuqOwI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Bh8fCEDIA4gA4VCEIohDiAJIA58IQkgCCAJhUI/iiEIIAQgBSAWfHwhBCAPIASFQiCKIQ8gCiAPfCEKIAUgCoVCGIohBSAEIAUgFHx8IQQgDyAEhUIQiiEPIAogD3whCiAFIAqFQj+KIQUgISAhKQMAIAEgCYWFNwMAICIgIikDACACIAqFhTcDACAjICMpAwAgAyALhYU3AwAgJCAkKQMAIAQgDIWFNwMAICUgJSkDACAFIA2FhTcDACAmICYpAwAgBiAOhYU3AwAgJyAnKQMAIAcgD4WFNwMAICggKCkDACAIIBCFhTcDAAs=");\n }\n });\n var bytes = require_blake2b3();\n var compiled = WebAssembly.compile(bytes);\n module.exports = async (imports) => {\n const instance = await WebAssembly.instantiate(await compiled, imports);\n return instance.exports;\n };\n }\n});\n\n// node_modules/blake2b-wasm/index.js\nvar require_blake2b_wasm = __commonJS({\n "node_modules/blake2b-wasm/index.js"(exports, module) {\n var assert = require_nanoassert();\n var b4a = require_browser();\n var wasm = null;\n var wasmPromise = typeof WebAssembly !== "undefined" && require_blake2b()().then((mod) => {\n wasm = mod;\n });\n var head = 64;\n var freeList = [];\n module.exports = Blake2b2;\n var BYTES_MIN = module.exports.BYTES_MIN = 16;\n var BYTES_MAX = module.exports.BYTES_MAX = 64;\n var BYTES = module.exports.BYTES = 32;\n var KEYBYTES_MIN = module.exports.KEYBYTES_MIN = 16;\n var KEYBYTES_MAX = module.exports.KEYBYTES_MAX = 64;\n var KEYBYTES = module.exports.KEYBYTES = 32;\n var SALTBYTES = module.exports.SALTBYTES = 16;\n var PERSONALBYTES = module.exports.PERSONALBYTES = 16;\n function Blake2b2(digestLength, key, salt, personal, noAssert) {\n if (!(this instanceof Blake2b2)) return new Blake2b2(digestLength, key, salt, personal, noAssert);\n if (!wasm) throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");\n if (!digestLength) digestLength = 32;\n if (noAssert !== true) {\n assert(digestLength >= BYTES_MIN, "digestLength must be at least " + BYTES_MIN + ", was given " + digestLength);\n assert(digestLength <= BYTES_MAX, "digestLength must be at most " + BYTES_MAX + ", was given " + digestLength);\n if (key != null) {\n assert(key instanceof Uint8Array, "key must be Uint8Array or Buffer");\n assert(key.length >= KEYBYTES_MIN, "key must be at least " + KEYBYTES_MIN + ", was given " + key.length);\n assert(key.length <= KEYBYTES_MAX, "key must be at least " + KEYBYTES_MAX + ", was given " + key.length);\n }\n if (salt != null) {\n assert(salt instanceof Uint8Array, "salt must be Uint8Array or Buffer");\n assert(salt.length === SALTBYTES, "salt must be exactly " + SALTBYTES + ", was given " + salt.length);\n }\n if (personal != null) {\n assert(personal instanceof Uint8Array, "personal must be Uint8Array or Buffer");\n assert(personal.length === PERSONALBYTES, "personal must be exactly " + PERSONALBYTES + ", was given " + personal.length);\n }\n }\n if (!freeList.length) {\n freeList.push(head);\n head += 216;\n }\n this.digestLength = digestLength;\n this.finalized = false;\n this.pointer = freeList.pop();\n this._memory = new Uint8Array(wasm.memory.buffer);\n this._memory.fill(0, 0, 64);\n this._memory[0] = this.digestLength;\n this._memory[1] = key ? key.length : 0;\n this._memory[2] = 1;\n this._memory[3] = 1;\n if (salt) this._memory.set(salt, 32);\n if (personal) this._memory.set(personal, 48);\n if (this.pointer + 216 > this._memory.length) this._realloc(this.pointer + 216);\n wasm.blake2b_init(this.pointer, this.digestLength);\n if (key) {\n this.update(key);\n this._memory.fill(0, head, head + key.length);\n this._memory[this.pointer + 200] = 128;\n }\n }\n Blake2b2.prototype._realloc = function(size) {\n wasm.memory.grow(Math.max(0, Math.ceil(Math.abs(size - this._memory.length) / 65536)));\n this._memory = new Uint8Array(wasm.memory.buffer);\n };\n Blake2b2.prototype.update = function(input) {\n assert(this.finalized === false, "Hash instance finalized");\n assert(input instanceof Uint8Array, "input must be Uint8Array or Buffer");\n if (head + input.length > this._memory.length) this._realloc(head + input.length);\n this._memory.set(input, head);\n wasm.blake2b_update(this.pointer, head, head + input.length);\n return this;\n };\n Blake2b2.prototype.digest = function(enc) {\n assert(this.finalized === false, "Hash instance finalized");\n this.finalized = true;\n freeList.push(this.pointer);\n wasm.blake2b_final(this.pointer);\n if (!enc || enc === "binary") {\n return this._memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength);\n }\n if (typeof enc === "string") {\n return b4a.toString(this._memory, enc, this.pointer + 128, this.pointer + 128 + this.digestLength);\n }\n assert(enc instanceof Uint8Array && enc.length >= this.digestLength, "input must be Uint8Array or Buffer");\n for (var i = 0; i < this.digestLength; i++) {\n enc[i] = this._memory[this.pointer + 128 + i];\n }\n return enc;\n };\n Blake2b2.prototype.final = Blake2b2.prototype.digest;\n Blake2b2.WASM = wasm;\n Blake2b2.SUPPORTED = typeof WebAssembly !== "undefined";\n Blake2b2.ready = function(cb) {\n if (!cb) cb = noop;\n if (!wasmPromise) return cb(new Error("WebAssembly not supported"));\n return wasmPromise.then(() => cb(), cb);\n };\n Blake2b2.prototype.ready = Blake2b2.ready;\n Blake2b2.prototype.getPartialHash = function() {\n return this._memory.slice(this.pointer, this.pointer + 216);\n };\n Blake2b2.prototype.setPartialHash = function(ph) {\n this._memory.set(ph, this.pointer);\n };\n function noop() {\n }\n }\n});\n\n// node_modules/blakejs/util.js\nvar require_util = __commonJS({\n "node_modules/blakejs/util.js"(exports, module) {\n var ERROR_MSG_INPUT = "Input must be an string, Buffer or Uint8Array";\n function normalizeInput(input) {\n let ret;\n if (input instanceof Uint8Array) {\n ret = input;\n } else if (typeof input === "string") {\n const encoder = new TextEncoder();\n ret = encoder.encode(input);\n } else {\n throw new Error(ERROR_MSG_INPUT);\n }\n return ret;\n }\n function toHex(bytes) {\n return Array.prototype.map.call(bytes, function(n) {\n return (n < 16 ? "0" : "") + n.toString(16);\n }).join("");\n }\n function uint32ToHex(val) {\n return (4294967296 + val).toString(16).substring(1);\n }\n function debugPrint(label, arr, size) {\n let msg = "\\n" + label + " = ";\n for (let i = 0; i < arr.length; i += 2) {\n if (size === 32) {\n msg += uint32ToHex(arr[i]).toUpperCase();\n msg += " ";\n msg += uint32ToHex(arr[i + 1]).toUpperCase();\n } else if (size === 64) {\n msg += uint32ToHex(arr[i + 1]).toUpperCase();\n msg += uint32ToHex(arr[i]).toUpperCase();\n } else throw new Error("Invalid size " + size);\n if (i % 6 === 4) {\n msg += "\\n" + new Array(label.length + 4).join(" ");\n } else if (i < arr.length - 2) {\n msg += " ";\n }\n }\n console.log(msg);\n }\n function testSpeed(hashFn, N, M) {\n let startMs = (/* @__PURE__ */ new Date()).getTime();\n const input = new Uint8Array(N);\n for (let i = 0; i < N; i++) {\n input[i] = i % 256;\n }\n const genMs = (/* @__PURE__ */ new Date()).getTime();\n console.log("Generated random input in " + (genMs - startMs) + "ms");\n startMs = genMs;\n for (let i = 0; i < M; i++) {\n const hashHex = hashFn(input);\n const hashMs = (/* @__PURE__ */ new Date()).getTime();\n const ms = hashMs - startMs;\n startMs = hashMs;\n console.log("Hashed in " + ms + "ms: " + hashHex.substring(0, 20) + "...");\n console.log(\n Math.round(N / (1 << 20) / (ms / 1e3) * 100) / 100 + " MB PER SECOND"\n );\n }\n }\n module.exports = {\n normalizeInput,\n toHex,\n debugPrint,\n testSpeed\n };\n }\n});\n\n// node_modules/blakejs/blake2b.js\nvar require_blake2b2 = __commonJS({\n "node_modules/blakejs/blake2b.js"(exports, module) {\n var util = require_util();\n function ADD64AA(v2, a, b) {\n const o0 = v2[a] + v2[b];\n let o1 = v2[a + 1] + v2[b + 1];\n if (o0 >= 4294967296) {\n o1++;\n }\n v2[a] = o0;\n v2[a + 1] = o1;\n }\n function ADD64AC(v2, a, b0, b1) {\n let o0 = v2[a] + b0;\n if (b0 < 0) {\n o0 += 4294967296;\n }\n let o1 = v2[a + 1] + b1;\n if (o0 >= 4294967296) {\n o1++;\n }\n v2[a] = o0;\n v2[a + 1] = o1;\n }\n function B2B_GET32(arr, i) {\n return arr[i] ^ arr[i + 1] << 8 ^ arr[i + 2] << 16 ^ arr[i + 3] << 24;\n }\n function B2B_G(a, b, c, d, ix, iy) {\n const x0 = m[ix];\n const x1 = m[ix + 1];\n const y0 = m[iy];\n const y1 = m[iy + 1];\n ADD64AA(v, a, b);\n ADD64AC(v, a, x0, x1);\n let xor0 = v[d] ^ v[a];\n let xor1 = v[d + 1] ^ v[a + 1];\n v[d] = xor1;\n v[d + 1] = xor0;\n ADD64AA(v, c, d);\n xor0 = v[b] ^ v[c];\n xor1 = v[b + 1] ^ v[c + 1];\n v[b] = xor0 >>> 24 ^ xor1 << 8;\n v[b + 1] = xor1 >>> 24 ^ xor0 << 8;\n ADD64AA(v, a, b);\n ADD64AC(v, a, y0, y1);\n xor0 = v[d] ^ v[a];\n xor1 = v[d + 1] ^ v[a + 1];\n v[d] = xor0 >>> 16 ^ xor1 << 16;\n v[d + 1] = xor1 >>> 16 ^ xor0 << 16;\n ADD64AA(v, c, d);\n xor0 = v[b] ^ v[c];\n xor1 = v[b + 1] ^ v[c + 1];\n v[b] = xor1 >>> 31 ^ xor0 << 1;\n v[b + 1] = xor0 >>> 31 ^ xor1 << 1;\n }\n var BLAKE2B_IV32 = new Uint32Array([\n 4089235720,\n 1779033703,\n 2227873595,\n 3144134277,\n 4271175723,\n 1013904242,\n 1595750129,\n 2773480762,\n 2917565137,\n 1359893119,\n 725511199,\n 2600822924,\n 4215389547,\n 528734635,\n 327033209,\n 1541459225\n ]);\n var SIGMA8 = [\n 0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6,\n 7,\n 8,\n 9,\n 10,\n 11,\n 12,\n 13,\n 14,\n 15,\n 14,\n 10,\n 4,\n 8,\n 9,\n 15,\n 13,\n 6,\n 1,\n 12,\n 0,\n 2,\n 11,\n 7,\n 5,\n 3,\n 11,\n 8,\n 12,\n 0,\n 5,\n 2,\n 15,\n 13,\n 10,\n 14,\n 3,\n 6,\n 7,\n 1,\n 9,\n 4,\n 7,\n 9,\n 3,\n 1,\n 13,\n 12,\n 11,\n 14,\n 2,\n 6,\n 5,\n 10,\n 4,\n 0,\n 15,\n 8,\n 9,\n 0,\n 5,\n 7,\n 2,\n 4,\n 10,\n 15,\n 14,\n 1,\n 11,\n 12,\n 6,\n 8,\n 3,\n 13,\n 2,\n 12,\n 6,\n 10,\n 0,\n 11,\n 8,\n 3,\n 4,\n 13,\n 7,\n 5,\n 15,\n 14,\n 1,\n 9,\n 12,\n 5,\n 1,\n 15,\n 14,\n 13,\n 4,\n 10,\n 0,\n 7,\n 6,\n 3,\n 9,\n 2,\n 8,\n 11,\n 13,\n 11,\n 7,\n 14,\n 12,\n 1,\n 3,\n 9,\n 5,\n 0,\n 15,\n 4,\n 8,\n 6,\n 2,\n 10,\n 6,\n 15,\n 14,\n 9,\n 11,\n 3,\n 0,\n 8,\n 12,\n 2,\n 13,\n 7,\n 1,\n 4,\n 10,\n 5,\n 10,\n 2,\n 8,\n 4,\n 7,\n 6,\n 1,\n 5,\n 15,\n 11,\n 9,\n 14,\n 3,\n 12,\n 13,\n 0,\n 0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6,\n 7,\n 8,\n 9,\n 10,\n 11,\n 12,\n 13,\n 14,\n 15,\n 14,\n 10,\n 4,\n 8,\n 9,\n 15,\n 13,\n 6,\n 1,\n 12,\n 0,\n 2,\n 11,\n 7,\n 5,\n 3\n ];\n var SIGMA82 = new Uint8Array(\n SIGMA8.map(function(x) {\n return x * 2;\n })\n );\n var v = new Uint32Array(32);\n var m = new Uint32Array(32);\n function blake2bCompress(ctx, last) {\n let i = 0;\n for (i = 0; i < 16; i++) {\n v[i] = ctx.h[i];\n v[i + 16] = BLAKE2B_IV32[i];\n }\n v[24] = v[24] ^ ctx.t;\n v[25] = v[25] ^ ctx.t / 4294967296;\n if (last) {\n v[28] = ~v[28];\n v[29] = ~v[29];\n }\n for (i = 0; i < 32; i++) {\n m[i] = B2B_GET32(ctx.b, 4 * i);\n }\n for (i = 0; i < 12; i++) {\n B2B_G(0, 8, 16, 24, SIGMA82[i * 16 + 0], SIGMA82[i * 16 + 1]);\n B2B_G(2, 10, 18, 26, SIGMA82[i * 16 + 2], SIGMA82[i * 16 + 3]);\n B2B_G(4, 12, 20, 28, SIGMA82[i * 16 + 4], SIGMA82[i * 16 + 5]);\n B2B_G(6, 14, 22, 30, SIGMA82[i * 16 + 6], SIGMA82[i * 16 + 7]);\n B2B_G(0, 10, 20, 30, SIGMA82[i * 16 + 8], SIGMA82[i * 16 + 9]);\n B2B_G(2, 12, 22, 24, SIGMA82[i * 16 + 10], SIGMA82[i * 16 + 11]);\n B2B_G(4, 14, 16, 26, SIGMA82[i * 16 + 12], SIGMA82[i * 16 + 13]);\n B2B_G(6, 8, 18, 28, SIGMA82[i * 16 + 14], SIGMA82[i * 16 + 15]);\n }\n for (i = 0; i < 16; i++) {\n ctx.h[i] = ctx.h[i] ^ v[i] ^ v[i + 16];\n }\n }\n var parameterBlock = new Uint8Array([\n 0,\n 0,\n 0,\n 0,\n // 0: outlen, keylen, fanout, depth\n 0,\n 0,\n 0,\n 0,\n // 4: leaf length, sequential mode\n 0,\n 0,\n 0,\n 0,\n // 8: node offset\n 0,\n 0,\n 0,\n 0,\n // 12: node offset\n 0,\n 0,\n 0,\n 0,\n // 16: node depth, inner length, rfu\n 0,\n 0,\n 0,\n 0,\n // 20: rfu\n 0,\n 0,\n 0,\n 0,\n // 24: rfu\n 0,\n 0,\n 0,\n 0,\n // 28: rfu\n 0,\n 0,\n 0,\n 0,\n // 32: salt\n 0,\n 0,\n 0,\n 0,\n // 36: salt\n 0,\n 0,\n 0,\n 0,\n // 40: salt\n 0,\n 0,\n 0,\n 0,\n // 44: salt\n 0,\n 0,\n 0,\n 0,\n // 48: personal\n 0,\n 0,\n 0,\n 0,\n // 52: personal\n 0,\n 0,\n 0,\n 0,\n // 56: personal\n 0,\n 0,\n 0,\n 0\n // 60: personal\n ]);\n function blake2bInit2(outlen, key, salt, personal) {\n if (outlen === 0 || outlen > 64) {\n throw new Error("Illegal output length, expected 0 < length <= 64");\n }\n if (key && key.length > 64) {\n throw new Error("Illegal key, expected Uint8Array with 0 < length <= 64");\n }\n if (salt && salt.length !== 16) {\n throw new Error("Illegal salt, expected Uint8Array with length is 16");\n }\n if (personal && personal.length !== 16) {\n throw new Error("Illegal personal, expected Uint8Array with length is 16");\n }\n const ctx = {\n b: new Uint8Array(128),\n h: new Uint32Array(16),\n t: 0,\n // input count\n c: 0,\n // pointer within buffer\n outlen\n // output length in bytes\n };\n parameterBlock.fill(0);\n parameterBlock[0] = outlen;\n if (key) parameterBlock[1] = key.length;\n parameterBlock[2] = 1;\n parameterBlock[3] = 1;\n if (salt) parameterBlock.set(salt, 32);\n if (personal) parameterBlock.set(personal, 48);\n for (let i = 0; i < 16; i++) {\n ctx.h[i] = BLAKE2B_IV32[i] ^ B2B_GET32(parameterBlock, i * 4);\n }\n if (key) {\n blake2bUpdate2(ctx, key);\n ctx.c = 128;\n }\n return ctx;\n }\n function blake2bUpdate2(ctx, input) {\n for (let i = 0; i < input.length; i++) {\n if (ctx.c === 128) {\n ctx.t += ctx.c;\n blake2bCompress(ctx, false);\n ctx.c = 0;\n }\n ctx.b[ctx.c++] = input[i];\n }\n }\n function blake2bFinal2(ctx) {\n ctx.t += ctx.c;\n while (ctx.c < 128) {\n ctx.b[ctx.c++] = 0;\n }\n blake2bCompress(ctx, true);\n const out = new Uint8Array(ctx.outlen);\n for (let i = 0; i < ctx.outlen; i++) {\n out[i] = ctx.h[i >> 2] >> 8 * (i & 3);\n }\n return out;\n }\n function blake2b2(input, key, outlen, salt, personal) {\n outlen = outlen || 64;\n input = util.normalizeInput(input);\n if (salt) {\n salt = util.normalizeInput(salt);\n }\n if (personal) {\n personal = util.normalizeInput(personal);\n }\n const ctx = blake2bInit2(outlen, key, salt, personal);\n blake2bUpdate2(ctx, input);\n return blake2bFinal2(ctx);\n }\n function blake2bHex(input, key, outlen, salt, personal) {\n const output = blake2b2(input, key, outlen, salt, personal);\n return util.toHex(output);\n }\n module.exports = {\n blake2b: blake2b2,\n blake2bHex,\n blake2bInit: blake2bInit2,\n blake2bUpdate: blake2bUpdate2,\n blake2bFinal: blake2bFinal2\n };\n }\n});\n\n// node_modules/blakejs/blake2s.js\nvar require_blake2s = __commonJS({\n "node_modules/blakejs/blake2s.js"(exports, module) {\n var util = require_util();\n function B2S_GET32(v2, i) {\n return v2[i] ^ v2[i + 1] << 8 ^ v2[i + 2] << 16 ^ v2[i + 3] << 24;\n }\n function B2S_G(a, b, c, d, x, y) {\n v[a] = v[a] + v[b] + x;\n v[d] = ROTR32(v[d] ^ v[a], 16);\n v[c] = v[c] + v[d];\n v[b] = ROTR32(v[b] ^ v[c], 12);\n v[a] = v[a] + v[b] + y;\n v[d] = ROTR32(v[d] ^ v[a], 8);\n v[c] = v[c] + v[d];\n v[b] = ROTR32(v[b] ^ v[c], 7);\n }\n function ROTR32(x, y) {\n return x >>> y ^ x << 32 - y;\n }\n var BLAKE2S_IV = new Uint32Array([\n 1779033703,\n 3144134277,\n 1013904242,\n 2773480762,\n 1359893119,\n 2600822924,\n 528734635,\n 1541459225\n ]);\n var SIGMA = new Uint8Array([\n 0,\n 1,\n 2,\n 3,\n 4,\n 5,\n 6,\n 7,\n 8,\n 9,\n 10,\n 11,\n 12,\n 13,\n 14,\n 15,\n 14,\n 10,\n 4,\n 8,\n 9,\n 15,\n 13,\n 6,\n 1,\n 12,\n 0,\n 2,\n 11,\n 7,\n 5,\n 3,\n 11,\n 8,\n 12,\n 0,\n 5,\n 2,\n 15,\n 13,\n 10,\n 14,\n 3,\n 6,\n 7,\n 1,\n 9,\n 4,\n 7,\n 9,\n 3,\n 1,\n 13,\n 12,\n 11,\n 14,\n 2,\n 6,\n 5,\n 10,\n 4,\n 0,\n 15,\n 8,\n 9,\n 0,\n 5,\n 7,\n 2,\n 4,\n 10,\n 15,\n 14,\n 1,\n 11,\n 12,\n 6,\n 8,\n 3,\n 13,\n 2,\n 12,\n 6,\n 10,\n 0,\n 11,\n 8,\n 3,\n 4,\n 13,\n 7,\n 5,\n 15,\n 14,\n 1,\n 9,\n 12,\n 5,\n 1,\n 15,\n 14,\n 13,\n 4,\n 10,\n 0,\n 7,\n 6,\n 3,\n 9,\n 2,\n 8,\n 11,\n 13,\n 11,\n 7,\n 14,\n 12,\n 1,\n 3,\n 9,\n 5,\n 0,\n 15,\n 4,\n 8,\n 6,\n 2,\n 10,\n 6,\n 15,\n 14,\n 9,\n 11,\n 3,\n 0,\n 8,\n 12,\n 2,\n 13,\n 7,\n 1,\n 4,\n 10,\n 5,\n 10,\n 2,\n 8,\n 4,\n 7,\n 6,\n 1,\n 5,\n 15,\n 11,\n 9,\n 14,\n 3,\n 12,\n 13,\n 0\n ]);\n var v = new Uint32Array(16);\n var m = new Uint32Array(16);\n function blake2sCompress(ctx, last) {\n let i = 0;\n for (i = 0; i < 8; i++) {\n v[i] = ctx.h[i];\n v[i + 8] = BLAKE2S_IV[i];\n }\n v[12] ^= ctx.t;\n v[13] ^= ctx.t / 4294967296;\n if (last) {\n v[14] = ~v[14];\n }\n for (i = 0; i < 16; i++) {\n m[i] = B2S_GET32(ctx.b, 4 * i);\n }\n for (i = 0; i < 10; i++) {\n B2S_G(0, 4, 8, 12, m[SIGMA[i * 16 + 0]], m[SIGMA[i * 16 + 1]]);\n B2S_G(1, 5, 9, 13, m[SIGMA[i * 16 + 2]], m[SIGMA[i * 16 + 3]]);\n B2S_G(2, 6, 10, 14, m[SIGMA[i * 16 + 4]], m[SIGMA[i * 16 + 5]]);\n B2S_G(3, 7, 11, 15, m[SIGMA[i * 16 + 6]], m[SIGMA[i * 16 + 7]]);\n B2S_G(0, 5, 10, 15, m[SIGMA[i * 16 + 8]], m[SIGMA[i * 16 + 9]]);\n B2S_G(1, 6, 11, 12, m[SIGMA[i * 16 + 10]], m[SIGMA[i * 16 + 11]]);\n B2S_G(2, 7, 8, 13, m[SIGMA[i * 16 + 12]], m[SIGMA[i * 16 + 13]]);\n B2S_G(3, 4, 9, 14, m[SIGMA[i * 16 + 14]], m[SIGMA[i * 16 + 15]]);\n }\n for (i = 0; i < 8; i++) {\n ctx.h[i] ^= v[i] ^ v[i + 8];\n }\n }\n function blake2sInit(outlen, key) {\n if (!(outlen > 0 && outlen <= 32)) {\n throw new Error("Incorrect output length, should be in [1, 32]");\n }\n const keylen = key ? key.length : 0;\n if (key && !(keylen > 0 && keylen <= 32)) {\n throw new Error("Incorrect key length, should be in [1, 32]");\n }\n const ctx = {\n h: new Uint32Array(BLAKE2S_IV),\n // hash state\n b: new Uint8Array(64),\n // input block\n c: 0,\n // pointer within block\n t: 0,\n // input count\n outlen\n // output length in bytes\n };\n ctx.h[0] ^= 16842752 ^ keylen << 8 ^ outlen;\n if (keylen > 0) {\n blake2sUpdate(ctx, key);\n ctx.c = 64;\n }\n return ctx;\n }\n function blake2sUpdate(ctx, input) {\n for (let i = 0; i < input.length; i++) {\n if (ctx.c === 64) {\n ctx.t += ctx.c;\n blake2sCompress(ctx, false);\n ctx.c = 0;\n }\n ctx.b[ctx.c++] = input[i];\n }\n }\n function blake2sFinal(ctx) {\n ctx.t += ctx.c;\n while (ctx.c < 64) {\n ctx.b[ctx.c++] = 0;\n }\n blake2sCompress(ctx, true);\n const out = new Uint8Array(ctx.outlen);\n for (let i = 0; i < ctx.outlen; i++) {\n out[i] = ctx.h[i >> 2] >> 8 * (i & 3) & 255;\n }\n return out;\n }\n function blake2s(input, key, outlen) {\n outlen = outlen || 32;\n input = util.normalizeInput(input);\n const ctx = blake2sInit(outlen, key);\n blake2sUpdate(ctx, input);\n return blake2sFinal(ctx);\n }\n function blake2sHex(input, key, outlen) {\n const output = blake2s(input, key, outlen);\n return util.toHex(output);\n }\n module.exports = {\n blake2s,\n blake2sHex,\n blake2sInit,\n blake2sUpdate,\n blake2sFinal\n };\n }\n});\n\n// node_modules/blakejs/index.js\nvar require_blakejs = __commonJS({\n "node_modules/blakejs/index.js"(exports, module) {\n var b2b = require_blake2b2();\n var b2s = require_blake2s();\n module.exports = {\n blake2b: b2b.blake2b,\n blake2bHex: b2b.blake2bHex,\n blake2bInit: b2b.blake2bInit,\n blake2bUpdate: b2b.blake2bUpdate,\n blake2bFinal: b2b.blake2bFinal,\n blake2s: b2s.blake2s,\n blake2sHex: b2s.blake2sHex,\n blake2sInit: b2s.blake2sInit,\n blake2sUpdate: b2s.blake2sUpdate,\n blake2sFinal: b2s.blake2sFinal\n };\n }\n});\n\n// js/blake2-wrapper.js\nvar b2wasm = __toESM(require_blake2b_wasm(), 1);\nvar import_blakejs = __toESM(require_blakejs(), 1);\nfunction Blake2b(outlen, key, salt, personal) {\n return (0, import_blakejs.blake2bInit)(outlen, key);\n}\nBlake2b.prototype.update = function(input) {\n (0, import_blakejs.blake2bUpdate)(this, input);\n return this;\n};\nBlake2b.prototype.digest = function(out) {\n var buf = !out ? new Uint8Array(this.outlen) : out;\n (0, import_blakejs.blake2bFinal)(this, buf);\n return buf;\n};\nBlake2b.prototype.final = Blake2b.prototype.digest;\nBlake2b.ready = function(cb) {\n b2wasm.ready(function() {\n cb();\n });\n};\nfunction createHash(outlen, key, salt, personal) {\n return new Blake2b(outlen, key);\n}\nfunction ready2(cb) {\n b2wasm.ready(function() {\n cb();\n });\n}\nvar WASM_LOADED = false;\nvar impl = createHash;\nb2wasm.ready(function(err) {\n if (!err) {\n WASM_LOADED = true;\n impl = b2wasm.default;\n }\n});\n\n// js/puzzle.worker.js\nvar blake2b = impl;\nvar blake2bInitialized = false;\nvar puzzleBuffer = null;\nvar puzzleID = null;\nvar useWasm = false;\nif (ready2) {\n ready2(() => {\n useWasm = WASM_LOADED;\n console.debug("[privatecaptcha][worker] Hasher loaded. wasm=" + useWasm);\n blake2b = impl;\n blake2bInitialized = true;\n if (puzzleBuffer) {\n self.postMessage({ command: "init" });\n }\n });\n} else {\n console.warn("[privatecaptcha][worker] Blake2b ready() is not defined");\n}\nfunction readUInt32LE(buffer, offset) {\n return (buffer[offset] | buffer[offset + 1] << 8 | buffer[offset + 2] << 16 | buffer[offset + 3] << 24) >>> 0;\n}\nfunction thresholdFromDifficulty(d) {\n return Math.pow(2, Math.floor((255.999 - d) / 8)) >>> 0;\n}\nfunction findSolution(threshold, puzzleIndex, debug) {\n const length = puzzleBuffer.length;\n if (debug) {\n console.debug(`[privatecaptcha][worker] looking for a solution. threshold=${threshold} puzzleID=${puzzleIndex} length=${length}`);\n }\n puzzleBuffer[length - 8] = puzzleIndex;\n let hash = new Uint8Array(32);\n for (let i = 0; i < 256; i++) {\n puzzleBuffer[length - 1 - 3] = i;\n for (let j = 0; j < 256; j++) {\n puzzleBuffer[length - 1 - 2] = j;\n for (let k = 0; k < 256; k++) {\n puzzleBuffer[length - 1 - 1] = j;\n for (let l = 0; l < 256; l++) {\n puzzleBuffer[length - 1 - 0] = l;\n hash.fill(0);\n blake2b(hash.length).update(puzzleBuffer).digest(hash);\n const prefix = readUInt32LE(hash, 0);\n if (prefix <= threshold) {\n if (debug) {\n console.debug(`[privatecaptcha][worker] found solution. prefix=${prefix} threshold=${threshold}`);\n }\n return puzzleBuffer.subarray(length - 8);\n }\n }\n }\n }\n }\n return new Uint8Array(0);\n}\nself.onmessage = (event) => {\n const { command, argument } = event.data;\n switch (command) {\n case "init":\n const { id, buffer } = argument;\n puzzleID = id;\n puzzleBuffer = buffer;\n if (blake2bInitialized) {\n self.postMessage({ command: "init" });\n }\n break;\n case "solve":\n const { difficulty, puzzleIndex, debug } = argument;\n const threshold = thresholdFromDifficulty(difficulty);\n const solution = findSolution(threshold, puzzleIndex, debug);\n self.postMessage({ command, argument: { id: puzzleID, solution, wasm: useWasm } });\n break;\n default:\n break;\n }\n};\n');
175
+ }
176
+
177
+ // js/workerspool.js
178
+ var METADATA_VERSION = 1;
179
+ var WorkersPool = class {
180
+ constructor(callbacks = {}, debug = false) {
181
+ this._solutions = [];
182
+ this._solutionsCount = 0;
183
+ this._puzzleID = null;
184
+ this._workers = [];
185
+ this._debug = debug;
186
+ this._timeStarted = null;
187
+ this._timeFinished = null;
188
+ this._anyWasm = false;
189
+ this._callbacks = Object.assign({
190
+ workersReady: () => 0,
191
+ workerError: () => 0,
192
+ workStarted: () => 0,
193
+ workCompleted: () => 0,
194
+ progress: () => 0
195
+ }, callbacks);
196
+ }
197
+ init(puzzle, autoStart) {
198
+ if (!puzzle) {
199
+ return;
200
+ }
201
+ if (puzzle.isZero()) {
202
+ if (this._debug) {
203
+ console.debug("[privatecaptcha][pool] skipping initializing workers");
204
+ }
205
+ setTimeout(() => this._callbacks.workersReady(autoStart), 0);
206
+ return;
207
+ }
208
+ const workersCount = 4;
209
+ let readyWorkers = 0;
210
+ const workers = [];
211
+ const pool = this;
212
+ const puzzleID = puzzle.ID;
213
+ const puzzleData = puzzle.puzzleBuffer;
214
+ for (let i = 0; i < workersCount; i++) {
215
+ const worker = new Worker2();
216
+ worker.onerror = (e) => this._callbacks.workerError(e);
217
+ worker.onmessage = function(event) {
218
+ if (!event.data) {
219
+ return;
220
+ }
221
+ const command = event.data.command;
222
+ switch (command) {
223
+ case "init":
224
+ readyWorkers++;
225
+ if (readyWorkers === workersCount) {
226
+ pool._callbacks.workersReady(autoStart);
227
+ }
228
+ break;
229
+ case "solve":
230
+ const { id, solution, wasm } = event.data.argument;
231
+ pool.onSolutionFound(id, solution, wasm);
232
+ break;
233
+ case "error":
234
+ if (event.data.error) {
235
+ pool._callbacks.workerError(event.data.error);
236
+ }
237
+ break;
238
+ default:
239
+ break;
240
+ }
241
+ ;
242
+ };
243
+ workers.push(worker);
244
+ }
245
+ this._workers = workers;
246
+ if (this._debug) {
247
+ console.debug(`[privatecaptcha][pool] initializing workers. count=${this._workers.length}`);
248
+ }
249
+ for (let i = 0; i < this._workers.length; i++) {
250
+ this._workers[i].postMessage({
251
+ command: "init",
252
+ argument: {
253
+ id: puzzleID,
254
+ buffer: puzzleData
255
+ }
256
+ });
257
+ }
258
+ ;
259
+ }
260
+ solve(puzzle) {
261
+ if (!puzzle) {
262
+ return;
263
+ }
264
+ if (this._debug) {
265
+ console.debug("[privatecaptcha][pool] starting solving");
266
+ }
267
+ this._solutions = [];
268
+ this._solutionsCount = puzzle.solutionsCount;
269
+ this._puzzleID = puzzle.ID;
270
+ this._timeStarted = Date.now();
271
+ this._timeFinished = null;
272
+ const skipSolving = puzzle.isZero() || puzzle.solutionsCount === 0;
273
+ let stubSolution = null;
274
+ for (let i = 0; i < puzzle.solutionsCount; i++) {
275
+ if (!skipSolving) {
276
+ this._workers[i % this._workers.length].postMessage({
277
+ command: "solve",
278
+ argument: {
279
+ difficulty: puzzle.difficulty,
280
+ puzzleIndex: i,
281
+ debug: this._debug
282
+ }
283
+ });
284
+ } else {
285
+ if (!stubSolution) {
286
+ stubSolution = new Uint8Array(8);
287
+ }
288
+ this._solutions.push(stubSolution);
289
+ }
290
+ }
291
+ this._callbacks.workStarted();
292
+ if (skipSolving) {
293
+ setTimeout(() => this.onWorkCompleted(), 0);
294
+ }
295
+ }
296
+ stop() {
297
+ const count = this._workers.length;
298
+ for (let i = 0; i < count; i++) {
299
+ this._workers[i].terminate();
300
+ }
301
+ this._workers = [];
302
+ if (this._debug) {
303
+ console.debug("[privatecaptcha][pool] terminated the workers. count=" + count);
304
+ }
305
+ }
306
+ onSolutionFound(id, solution, wasm) {
307
+ if (this._debug) {
308
+ console.debug("[privatecaptcha][pool] solution found. length=" + solution.length);
309
+ }
310
+ if (id != this._puzzleID) {
311
+ console.warn(`[privatecaptcha][pool] Discarding solution with invalid ID. actual=${id} expected=${this._puzzleID}`);
312
+ return;
313
+ }
314
+ this._solutions.push(solution);
315
+ if (wasm) {
316
+ this._anyWasm = true;
317
+ }
318
+ const count = this._solutions.length;
319
+ this._callbacks.progress(count * 100 / this._solutionsCount);
320
+ if (count == this._solutionsCount) {
321
+ this.onWorkCompleted();
322
+ }
323
+ }
324
+ onWorkCompleted() {
325
+ this._timeFinished = Date.now();
326
+ this._callbacks.workCompleted();
327
+ }
328
+ serializeSolutions(errorCode) {
329
+ if (this._debug) {
330
+ console.debug("[privatecaptcha][pool] serializing solutions. count=" + this._solutions.length);
331
+ }
332
+ const solutionsLength = this._solutions.reduce((total, arr) => total + arr.length, 0);
333
+ const metadataArray = this.writeMetadata(errorCode);
334
+ const metadataSize = metadataArray.length;
335
+ const resultArray = new Uint8Array(metadataSize + solutionsLength);
336
+ let offset = 0;
337
+ resultArray.set(metadataArray, offset);
338
+ offset += metadataArray.length;
339
+ for (let i = 0; i < this._solutions.length; i++) {
340
+ resultArray.set(this._solutions[i], offset);
341
+ offset += this._solutions[i].length;
342
+ }
343
+ return encode(resultArray);
344
+ }
345
+ writeMetadata(errorCode) {
346
+ const metadataSize = 1 + 1 + 1 + 4;
347
+ const binaryData = new Uint8Array(metadataSize);
348
+ let currentIndex = 0;
349
+ binaryData[currentIndex++] = METADATA_VERSION & 255;
350
+ binaryData[currentIndex++] = errorCode & 255;
351
+ const wasmFlag = this._anyWasm ? 1 : 0;
352
+ binaryData[currentIndex++] = wasmFlag & 255;
353
+ const elapsedMillis = this.elapsedMillis();
354
+ binaryData[currentIndex++] = elapsedMillis & 255;
355
+ binaryData[currentIndex++] = elapsedMillis >> 8 & 255;
356
+ binaryData[currentIndex++] = elapsedMillis >> 16 & 255;
357
+ binaryData[currentIndex++] = elapsedMillis >> 24 & 255;
358
+ return binaryData;
359
+ }
360
+ elapsedMillis() {
361
+ if (this._timeStarted && this._timeFinished) {
362
+ return this._timeFinished - this._timeStarted;
363
+ }
364
+ return 0;
365
+ }
366
+ };
367
+
368
+ // js/progress.js
369
+ var ProgressRing = class extends HTMLElement {
370
+ constructor() {
371
+ super();
372
+ const stroke = this.getAttribute("stroke");
373
+ const size = 100;
374
+ const radius = size / 2;
375
+ const normalizedRadius = radius - stroke / 2;
376
+ this._circumference = normalizedRadius * 2 * Math.PI;
377
+ this._root = this.attachShadow({ mode: "open" });
378
+ this._root.innerHTML = `
379
+ <svg preserveAspectRatio="xMidYMid meet" viewBox="0 0 ${size} ${size}">
380
+ <circle
381
+ id="pie"
382
+ style="stroke-dasharray: 0 ${this._circumference}"
383
+ stroke-width="${normalizedRadius}"
384
+ fill="transparent"
385
+ r="${normalizedRadius / 2}"
386
+ cx="${radius}"
387
+ cy="${radius}"
388
+ />
389
+ <circle
390
+ id="track"
391
+ stroke-width="${stroke}"
392
+ fill="transparent"
393
+ r="${normalizedRadius}"
394
+ cx="${radius}"
395
+ cy="${radius}"
396
+ />
397
+ <circle
398
+ id="progress"
399
+ stroke-dasharray="${this._circumference} ${this._circumference}"
400
+ style="stroke-dashoffset: ${this._circumference}"
401
+ stroke-width="${stroke}"
402
+ fill="transparent"
403
+ r="${normalizedRadius}"
404
+ cx="${radius}"
405
+ cy="${radius}"
406
+ />
407
+ </svg>
408
+
409
+ <style>
410
+ svg {
411
+ width: 2.25em;
412
+ height: 2.25em;
413
+ }
414
+ #pie {
415
+ stroke: var(--pie-color);
416
+ transition: stroke-dasharray 0.35s;
417
+ transform: rotate(-90deg);
418
+ transform-origin: 50% 50%;
419
+ }
420
+ #progress {
421
+ stroke: var(--accent-color);
422
+ transition: stroke-dashoffset 0.35s;
423
+ transform: rotate(-90deg);
424
+ transform-origin: 50% 50%;
425
+ }
426
+ #track {
427
+ stroke: var(--gray-color);
428
+ }
429
+ </style>
430
+ `;
431
+ }
432
+ setProgress(percent) {
433
+ const progress = percent / 100 * this._circumference;
434
+ const offset = this._circumference - progress;
435
+ const circle = this._root.getElementById("progress");
436
+ circle.style.strokeDashoffset = offset;
437
+ const pie = this._root.getElementById("pie");
438
+ pie.style.strokeDasharray = progress / 2 + " " + this._circumference;
439
+ }
440
+ static get observedAttributes() {
441
+ return ["progress"];
442
+ }
443
+ attributeChangedCallback(name, oldValue, newValue) {
444
+ if (name === "progress") {
445
+ this.setProgress(newValue);
446
+ }
447
+ }
448
+ };
449
+
450
+ // js/styles.css
451
+ var styles_default = '@layer base,theme,custom;@layer base{:host,*,*:before,*:after{box-sizing:border-box;margin:0;padding:0;border:0 solid}:host{--extra-spacing: 0px;--label-spacing: .625rem;--border-radius: .125rem;--warn-color: #A70B0B;--accent-color: #009400;min-width:0;font-size:1rem;display:inline-block;max-width:100%;border-radius:var(--border-radius)}:host(.hidden){display:none}:host(.floating){display:block;position:absolute;left:0;top:0;transform:translateY(-100%);z-index:1000}@media (min-width: 30em){:host{min-width:20em}}}@layer theme{:host([theme="light"]){--dark-color: #070113;--gray-color: #E0E0E0;--pie-color: #D8E9E9;--background-color: #fff;--checkbox-background-color: #FFF;--checkbox-hover-color: #EBF4F4}:host([theme="dark"]){--dark-color: #EBF4F4;--gray-color: #656C7B;--pie-color: #376262;--background-color: #041616;--checkbox-background-color: #223C3C;--checkbox-hover-color: #1C3232}}.pc-captcha-widget{display:flex;align-items:center;flex-direction:row;padding:.75em 1em;border:1px solid var(--gray-color);border-radius:var(--border-radius);background-color:var(--background-color);box-sizing:border-box;width:100%;height:100%}.pc-interactive-area{display:flex;flex:0 1 auto;align-items:center;position:relative;min-width:0}.pc-interactive-area label{padding-left:var(--label-spacing);color:var(--dark-color);flex:0 1 auto;min-width:1em;white-space:normal}.pc-interactive-area input[type=checkbox]{font-size:1em;width:2em;height:2em;margin:0 0 0 calc(.125em + var(--extra-spacing));appearance:none;background-color:var(--checkbox-background-color);border:.125em solid var(--dark-color);border-radius:.25em;cursor:pointer;flex-shrink:0}.pc-interactive-area input[type=checkbox]+label{padding:0 0 0 calc(.125em + var(--extra-spacing) + var(--label-spacing))}@keyframes colorChange{0%,to{border-color:var(--dark-color)}50%{border-color:var(--gray-color)}}.pc-interactive-area input[type=checkbox].loading{animation:colorChange 2s infinite;animation-timing-function:ease-in-out;background-color:var(--checkbox-hover-color);cursor:default}.pc-interactive-area input[type=checkbox].ready{background-color:var(--checkbox-background-color);border-color:var(--dark-color);cursor:pointer}.pc-interactive-area input[type=checkbox].invalid{background-color:var(--checkbox-hover-color);border-color:var(--gray-color);cursor:not-allowed}.pc-interactive-area input[type=checkbox]:not(.invalid):hover{background-color:var(--checkbox-hover-color);border-color:var(--accent-color)}.pc-interactive-area input[type=checkbox].invalid:hover+label{cursor:not-allowed}.pc-interactive-area input[type=checkbox]:not(.invalid):hover+label{cursor:pointer}@keyframes dots-1{0%{opacity:0}25%{opacity:1}}@keyframes dots-2{0%{opacity:0}50%{opacity:1}}@keyframes dots-3{0%{opacity:0}75%{opacity:1}}@-webkit-keyframes dots-1{0%{opacity:0}25%{opacity:1}}@-webkit-keyframes dots-2{0%{opacity:0}50%{opacity:1}}@-webkit-keyframes dots-3{0%{opacity:0}75%{opacity:1}}.pc-interactive-area .dots span{animation:dots-1 2s infinite steps(1);-webkit-animation:dots-1 2s infinite steps(1)}.pc-interactive-area .dots span:first-child+span{animation-name:dots-2;-webkit-animation-name:dots-2}.pc-interactive-area .dots span:first-child+span+span{animation-name:dots-3;-webkit-animation-name:dots-3}#pc-progress{display:flex;justify-content:center;margin:0 0 0 var(--extra-spacing);flex-shrink:0}#pc-progress+label{padding:0 0 0 calc(var(--extra-spacing) + var(--label-spacing))}.pc-spacer{flex-basis:0;flex-shrink:1;flex-grow:1;width:4em;min-width:0}.pc-info{display:flex;flex:0 0 auto;flex-direction:column;align-items:center;justify-content:center;margin-right:calc(.125em + var(--extra-spacing));color:var(--dark-color)}.pc-info svg{width:auto;height:3.125em;max-width:100%;max-height:100%}a.pc-link{margin-top:5px;text-decoration:none;color:currentcolor;text-align:center;font-size:.55em;text-transform:uppercase;font-weight:700;line-height:1.1em}a.pc-link:hover{text-decoration:underline}@keyframes checkmark{0%{stroke-dashoffset:100px}to{stroke-dashoffset:0px}}svg.verified{margin:0 0 0 var(--extra-spacing);flex-shrink:0;width:2.25em;height:2.25em}svg.verified+label{padding:0 0 0 calc(var(--extra-spacing) + var(--label-spacing))}svg.verified polyline{animation:checkmark .35s ease-in-out .1s backwards;stroke:#f2f2f2}svg.verified circle{fill:var(--accent-color)}#pc-debug{font-size:.75em;color:var(--gray-color);position:absolute;top:100%;left:calc(2em + 1em + 2*.125em + 2*var(--extra-spacing) + var(--label-spacing));cursor:default}#pc-debug.warn{color:var(--warn-color)}\n';
452
+
453
+ // js/strings.js
454
+ var CLICK_TO_VERIFY = "click_to_verify";
455
+ var VERIFYING = "verifying";
456
+ var SUCCESS = "success";
457
+ var UNAVAILABLE = "unavailable";
458
+ var INCOMPLETE = "incomplete";
459
+ var ERROR = "error";
460
+ var TESTING = "testing";
461
+ var STRINGS = {
462
+ "en": {
463
+ [CLICK_TO_VERIFY]: "Click to verify",
464
+ [VERIFYING]: "Verifying",
465
+ [SUCCESS]: "Success",
466
+ [UNAVAILABLE]: "Not available",
467
+ [INCOMPLETE]: "incomplete",
468
+ [ERROR]: "error",
469
+ [TESTING]: "testing"
470
+ }
471
+ };
472
+
473
+ // js/errors.js
474
+ var ERROR_NO_ERROR = 0;
475
+ var ERROR_NOT_CONFIGURED = 1;
476
+ var ERROR_ZERO_PUZZLE = 2;
477
+ var ERROR_FETCH_PUZZLE = 3;
478
+ var ERROR_SOLVE_PUZZLE = 4;
479
+
480
+ // js/html.js
481
+ window.customElements.define("progress-ring", ProgressRing);
482
+ var STATE_EMPTY = "empty";
483
+ var STATE_ERROR = "error";
484
+ var STATE_LOADING = "loading";
485
+ var STATE_READY = "ready";
486
+ var STATE_IN_PROGRESS = "inprogress";
487
+ var STATE_VERIFIED = "verified";
488
+ var STATE_INVALID = "invalid";
489
+ var DISPLAY_POPUP = "popup";
490
+ var DISPLAY_HIDDEN = "hidden";
491
+ var DISPLAY_WIDGET = "widget";
492
+ var CHECKBOX_ID = "pc-checkbox";
493
+ var PROGRESS_ID = "pc-progress";
494
+ var DEBUG_ID = "pc-debug";
495
+ var DEBUG_ERROR_CLASS = "warn";
496
+ var privateCaptchaSVG = `<svg viewBox="0 0 39.4 41.99" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" class="pc-logo" preserveAspectRatio="xMidYMid meet">
497
+ <path d="M0 0v30.62l4.29 2.48V4.85h30.83v23.29l-15.41 8.9-6.83-3.94v-4.95l6.83 3.94 11.12-6.42V9.91H8.58v25.66l11.12 6.42 19.7-11.37V0Zm12.87 14.86h13.66v8.32l-6.83 3.94-6.83-3.94z" fill="currentColor"/>
498
+ </svg>`;
499
+ var verifiedSVG = `<svg class="verified" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 154 154">
500
+ <g fill="none"><circle cx="77" cy="77" r="76"></circle>
501
+ <polyline class="st0" stroke-width="12" points="43.5,77.8 63.7,97.9 112.2,49.4" style="stroke-dasharray:100px, 100px; stroke-dashoffset: 200px;"/></g>
502
+ </svg>
503
+ `;
504
+ function checkbox(cls) {
505
+ return `<input type="checkbox" id="${CHECKBOX_ID}" class="${cls}" required>`;
506
+ }
507
+ function label(text, forElement) {
508
+ return `<label for="${forElement}">${text}</label>`;
509
+ }
510
+ function errorDescription(code, strings) {
511
+ switch (code) {
512
+ case ERROR_NO_ERROR:
513
+ return "";
514
+ case ERROR_NOT_CONFIGURED:
515
+ return strings[INCOMPLETE];
516
+ case ERROR_ZERO_PUZZLE:
517
+ return strings[TESTING];
518
+ default:
519
+ return strings[ERROR];
520
+ }
521
+ ;
522
+ }
523
+ var CaptchaElement = class extends HTMLElement {
524
+ constructor() {
525
+ super();
526
+ this._state = "";
527
+ this._root = this.attachShadow({ mode: "open" });
528
+ this._debug = this.getAttribute("debug");
529
+ this._error = null;
530
+ this._displayMode = this.getAttribute("display-mode");
531
+ this._lang = this.getAttribute("lang");
532
+ if (!(this._lang in STRINGS)) {
533
+ console.warn(`[privatecaptcha][progress] Localization not found. lang=${this._lang}`);
534
+ this._lang = "en";
535
+ }
536
+ this.checkEvent = new CustomEvent("check", {
537
+ bubbles: true,
538
+ cancelable: false,
539
+ composed: true
540
+ });
541
+ const sheet = new CSSStyleSheet();
542
+ sheet.replace(styles_default);
543
+ this._root.adoptedStyleSheets.push(sheet);
544
+ const extraStyles = this.getAttribute("extra-styles");
545
+ if (extraStyles) {
546
+ const overridesSheet = new CSSStyleSheet();
547
+ const cssText = `@layer custom { :host { ${extraStyles} } }`;
548
+ overridesSheet.replace(cssText);
549
+ this._root.adoptedStyleSheets.push(overridesSheet);
550
+ }
551
+ const canShow = this._displayMode == DISPLAY_WIDGET;
552
+ this.setState(STATE_EMPTY, canShow);
553
+ }
554
+ setState(state, canShow) {
555
+ if (state == this._state) {
556
+ console.debug("[privatecaptcha][progress] already in this state: " + state);
557
+ return;
558
+ }
559
+ if (this._debug) {
560
+ console.debug(`[privatecaptcha][progress] change state. old=${this._state} new=${state}`);
561
+ }
562
+ let activeArea = "";
563
+ let bindCheckEvent = false;
564
+ let showPopupIfNeeded = false;
565
+ const strings = STRINGS[this._lang];
566
+ switch (state) {
567
+ case STATE_EMPTY:
568
+ bindCheckEvent = true;
569
+ activeArea = checkbox("") + label(strings[CLICK_TO_VERIFY], CHECKBOX_ID);
570
+ break;
571
+ case STATE_LOADING:
572
+ bindCheckEvent = true;
573
+ activeArea = checkbox("loading") + label(strings[CLICK_TO_VERIFY], CHECKBOX_ID);
574
+ break;
575
+ case STATE_READY:
576
+ bindCheckEvent = true;
577
+ activeArea = checkbox("ready") + label(strings[CLICK_TO_VERIFY], CHECKBOX_ID);
578
+ showPopupIfNeeded = canShow;
579
+ break;
580
+ case STATE_IN_PROGRESS:
581
+ const text = strings[VERIFYING];
582
+ activeArea = `<progress-ring id="${PROGRESS_ID}" stroke="12" progress="0"></progress-ring><label for="${PROGRESS_ID}">${text}<span class="dots"><span>.</span><span>.</span><span>.</span></span></label>`;
583
+ showPopupIfNeeded = canShow;
584
+ break;
585
+ case STATE_VERIFIED:
586
+ activeArea = verifiedSVG + label(strings[SUCCESS], PROGRESS_ID);
587
+ showPopupIfNeeded = canShow;
588
+ break;
589
+ case STATE_INVALID:
590
+ activeArea = checkbox("invalid") + label(strings[UNAVAILABLE], CHECKBOX_ID);
591
+ break;
592
+ default:
593
+ console.error(`[privatecaptcha][progress] unknown state: ${state}`);
594
+ break;
595
+ }
596
+ if (this._debug || this._error) {
597
+ const debugText = this._error ? errorDescription(this._error, strings) : `[${state}]`;
598
+ activeArea += `<span id="${DEBUG_ID}" class="${this._error ? DEBUG_ERROR_CLASS : ""}">${debugText}</span>`;
599
+ }
600
+ let hostClass = "";
601
+ switch (this._displayMode) {
602
+ case DISPLAY_HIDDEN:
603
+ hostClass = "hidden";
604
+ break;
605
+ case DISPLAY_POPUP:
606
+ hostClass = showPopupIfNeeded ? "floating" : "hidden";
607
+ break;
608
+ case DISPLAY_WIDGET:
609
+ break;
610
+ }
611
+ ;
612
+ this.classList.remove("hidden", "floating");
613
+ if (hostClass) {
614
+ this.classList.add(hostClass);
615
+ }
616
+ this._state = state;
617
+ this._root.innerHTML = `<div class="pc-captcha-widget">
618
+ <div class="pc-interactive-area">
619
+ ${activeArea}
620
+ </div>
621
+ <div class="pc-spacer"></div>
622
+ <div class="pc-info">
623
+ ${privateCaptchaSVG}
624
+ <a href="https://privatecaptcha.com" class="pc-link" rel="noopener nofollow" target="_blank">Private<br />Captcha</a>
625
+ </div>
626
+ </div>`;
627
+ if (bindCheckEvent) {
628
+ const checkbox2 = this._root.getElementById(CHECKBOX_ID);
629
+ if (checkbox2) {
630
+ checkbox2.addEventListener("change", this.onCheckboxClicked.bind(this));
631
+ } else {
632
+ console.warn("[privatecaptcha][progress] checkbox not found in the Shadow DOM");
633
+ }
634
+ }
635
+ }
636
+ onCheckboxClicked(event) {
637
+ event.preventDefault();
638
+ if (this._debug) {
639
+ console.debug("[privatecaptcha][progress] checkbox was clicked");
640
+ }
641
+ if (event.target.checked) {
642
+ this.dispatchEvent(this.checkEvent);
643
+ } else {
644
+ console.warn("[privatecaptcha][progress] checkbox was unchecked");
645
+ }
646
+ }
647
+ setProgress(percent) {
648
+ if (STATE_IN_PROGRESS == this._state) {
649
+ const progressBar = this._root.getElementById(PROGRESS_ID);
650
+ if (progressBar) {
651
+ progressBar.setProgress(percent);
652
+ } else {
653
+ console.warn("[privatecaptcha][progress] progress element not found");
654
+ }
655
+ } else {
656
+ if (this._debug) {
657
+ console.debug("[privatecaptcha][progress] skipping updating progress when not in progress");
658
+ }
659
+ }
660
+ }
661
+ setError(value) {
662
+ this._error = value;
663
+ }
664
+ setDebugText(text, error) {
665
+ const debugElement = this._root.getElementById(DEBUG_ID);
666
+ if (debugElement) {
667
+ let debugText = "";
668
+ if (this._error) {
669
+ const strings = STRINGS[this._lang];
670
+ debugText = errorDescription(this._error, strings);
671
+ } else {
672
+ debugText = `[${text}]`;
673
+ }
674
+ debugElement.innerHTML = debugText;
675
+ if (error || this._error) {
676
+ debugElement.classList.add(DEBUG_ERROR_CLASS);
677
+ } else {
678
+ debugElement.classList.remove(DEBUG_ERROR_CLASS);
679
+ }
680
+ }
681
+ }
682
+ static get observedAttributes() {
683
+ return ["state", "progress"];
684
+ }
685
+ attributeChangedCallback(name, oldValue, newValue) {
686
+ if ("progress" === name) {
687
+ this.setProgress(newValue);
688
+ }
689
+ }
690
+ };
691
+
692
+ // js/widget.js
693
+ window.customElements.define("private-captcha", CaptchaElement);
694
+ var PUZZLE_ENDPOINT_URL = "https://api.privatecaptcha.com/puzzle";
695
+ var PUZZLE_EU_ENDPOINT_URL = "https://api.eu.privatecaptcha.com/puzzle";
696
+ function findParentFormElement(element) {
697
+ while (element && element.tagName !== "FORM") {
698
+ element = element.parentElement;
699
+ }
700
+ return element;
701
+ }
702
+ var CaptchaWidget = class {
703
+ constructor(element, options = {}) {
704
+ this._element = element;
705
+ this._puzzle = null;
706
+ this._expiryTimeout = null;
707
+ this._state = STATE_EMPTY;
708
+ this._lastProgress = null;
709
+ this._solution = null;
710
+ this._userStarted = false;
711
+ this._options = {};
712
+ this._errorCode = ERROR_NO_ERROR;
713
+ this.setOptions(options);
714
+ this._workersPool = new WorkersPool({
715
+ workersReady: this.onWorkersReady.bind(this),
716
+ workerError: this.onWorkerError.bind(this),
717
+ workStarted: this.onWorkStarted.bind(this),
718
+ workCompleted: this.onWorkCompleted.bind(this),
719
+ progress: this.onWorkProgress.bind(this)
720
+ }, this._options.debug);
721
+ const form = findParentFormElement(this._element);
722
+ if (form) {
723
+ form.addEventListener("focusin", this.onFocusIn.bind(this), { once: true, passive: true });
724
+ this._element.innerHTML = `<private-captcha display-mode="${this._options.displayMode}" lang="${this._options.lang}" theme="${this._options.theme}" extra-styles="${this._options.styles}"${this._options.debug ? ' debug="true"' : ""}></private-captcha>`;
725
+ this._element.addEventListener("check", this.onChecked.bind(this));
726
+ if (this._options.storeVariable) {
727
+ this._element[this._options.storeVariable] = this;
728
+ }
729
+ if (DISPLAY_POPUP === this._options.displayMode) {
730
+ const anchor = form.querySelector(".private-captcha-anchor");
731
+ if (anchor) {
732
+ anchor.style.position = "relative";
733
+ } else {
734
+ console.warn("[privatecaptcha] cannot find anchor for popup");
735
+ }
736
+ }
737
+ this.checkConfigured();
738
+ } else {
739
+ console.warn("[privatecaptcha] cannot find form element");
740
+ }
741
+ }
742
+ setOptions(options) {
743
+ const euOnly = this._element.dataset["eu"] || null;
744
+ const defaultEndpoint = euOnly ? PUZZLE_EU_ENDPOINT_URL : PUZZLE_ENDPOINT_URL;
745
+ this._options = Object.assign({
746
+ startMode: this._element.dataset["startMode"] || "click",
747
+ debug: this._element.dataset["debug"],
748
+ fieldName: this._element.dataset["solutionField"] || "private-captcha-solution",
749
+ puzzleEndpoint: this._element.dataset["puzzleEndpoint"] || defaultEndpoint,
750
+ sitekey: this._element.dataset["sitekey"] || "",
751
+ displayMode: this._element.dataset["displayMode"] || "widget",
752
+ lang: this._element.dataset["lang"] || "en",
753
+ theme: this._element.dataset["theme"] || "light",
754
+ styles: this._element.dataset["styles"] || "",
755
+ storeVariable: this._element.dataset["storeVariable"] || null,
756
+ initCallback: () => this.trace("init callback"),
757
+ startedCallback: () => this.trace("started callback"),
758
+ finishedCallback: () => this.trace("finished callback"),
759
+ erroredCallback: () => this.trace("errored callback")
760
+ }, options);
761
+ }
762
+ // fetches puzzle from the server and setup workers
763
+ async init(autoStart) {
764
+ this.trace(`init() was called. state=${this._state}`);
765
+ this._puzzle = null;
766
+ this._solution = null;
767
+ this._errorCode = ERROR_NO_ERROR;
768
+ const sitekey = this.checkConfigured();
769
+ if (!sitekey) {
770
+ return;
771
+ }
772
+ if (this._state != STATE_EMPTY && this._state != STATE_ERROR) {
773
+ console.warn(`[privatecaptcha] captcha has already been initialized. state=${this._state}`);
774
+ return;
775
+ }
776
+ if (this._workersPool) {
777
+ this._workersPool.stop();
778
+ }
779
+ const startWorkers = this._options.startMode == "auto" || autoStart;
780
+ try {
781
+ this.setState(STATE_LOADING);
782
+ this.trace("fetching puzzle");
783
+ const puzzleData = await getPuzzle(this._options.puzzleEndpoint, sitekey);
784
+ this._puzzle = new Puzzle(puzzleData);
785
+ if (this._puzzle && this._puzzle.isZero()) {
786
+ this._errorCode = ERROR_ZERO_PUZZLE;
787
+ }
788
+ const expirationMillis = this._puzzle.expirationMillis();
789
+ this.trace(`parsed puzzle buffer. isZero=${this._puzzle.isZero()} ttl=${expirationMillis / 1e3}`);
790
+ if (this._expiryTimeout) {
791
+ clearTimeout(this._expiryTimeout);
792
+ }
793
+ if (expirationMillis) {
794
+ this._expiryTimeout = setTimeout(() => this.expire(), expirationMillis);
795
+ }
796
+ this._workersPool.init(this._puzzle, startWorkers);
797
+ this.signalInit();
798
+ } catch (e) {
799
+ console.error("[privatecaptcha]", e);
800
+ if (this._expiryTimeout) {
801
+ clearTimeout(this._expiryTimeout);
802
+ }
803
+ this._errorCode = ERROR_FETCH_PUZZLE;
804
+ this.setState(STATE_ERROR);
805
+ this.setProgressState(this._userStarted ? STATE_VERIFIED : STATE_EMPTY);
806
+ this.saveSolutions();
807
+ if (this._userStarted) {
808
+ this.signalErrored();
809
+ }
810
+ }
811
+ }
812
+ checkConfigured() {
813
+ const sitekey = this._options.sitekey || this._element.dataset["sitekey"];
814
+ if (!sitekey) {
815
+ console.error("[privatecaptcha] sitekey not set on captcha element");
816
+ this._errorCode = ERROR_NOT_CONFIGURED;
817
+ this.setState(STATE_INVALID);
818
+ this.setProgressState(STATE_INVALID);
819
+ return null;
820
+ }
821
+ return sitekey;
822
+ }
823
+ start() {
824
+ if (this._state !== STATE_READY) {
825
+ console.warn(`[privatecaptcha] solving has already been started. state=${this._state}`);
826
+ return;
827
+ }
828
+ this.trace("starting solving captcha");
829
+ try {
830
+ this.setState(STATE_IN_PROGRESS);
831
+ this._workersPool.solve(this._puzzle);
832
+ } catch (e) {
833
+ console.error("[privatecaptcha]", e);
834
+ }
835
+ }
836
+ signalInit() {
837
+ this._options.initCallback(this);
838
+ const callback = this._element.dataset["initCallback"];
839
+ if (callback) {
840
+ try {
841
+ window[callback](this);
842
+ } catch (e) {
843
+ console.error("[privatecaptcha] Error in init callback:", e);
844
+ }
845
+ }
846
+ }
847
+ signalStarted() {
848
+ this._options.startedCallback(this);
849
+ const callback = this._element.dataset["startedCallback"];
850
+ if (callback) {
851
+ try {
852
+ window[callback](this);
853
+ } catch (e) {
854
+ console.error("[privatecaptcha] Error in started callback:", e);
855
+ }
856
+ }
857
+ }
858
+ signalFinished() {
859
+ this._options.finishedCallback(this);
860
+ const callback = this._element.dataset["finishedCallback"];
861
+ if (callback) {
862
+ try {
863
+ window[callback](this);
864
+ } catch (e) {
865
+ console.error("[privatecaptcha] Error in finished callback:", e);
866
+ }
867
+ }
868
+ }
869
+ signalErrored() {
870
+ this._options.erroredCallback(this);
871
+ const callback = this._element.dataset["erroredCallback"];
872
+ if (callback) {
873
+ try {
874
+ window[callback](this);
875
+ } catch (e) {
876
+ console.error("[privatecaptcha] Error in errored callback:", e);
877
+ }
878
+ }
879
+ }
880
+ ensureNoSolutionField() {
881
+ const solutionField = this._element.querySelector(`input[name="${this._options.fieldName}"]`);
882
+ if (solutionField) {
883
+ try {
884
+ this._element.removeChild(solutionField);
885
+ } catch (e) {
886
+ console.warn("[privatecaptcha]", e);
887
+ }
888
+ }
889
+ }
890
+ reset(options = {}) {
891
+ this.trace("reset captcha");
892
+ if (this._expiryTimeout) {
893
+ clearTimeout(this._expiryTimeout);
894
+ }
895
+ if (this._workersPool) {
896
+ this._workersPool.stop();
897
+ }
898
+ this._errorCode = ERROR_NO_ERROR;
899
+ this.setState(STATE_EMPTY);
900
+ this.setProgressState(STATE_EMPTY);
901
+ this.ensureNoSolutionField();
902
+ this._userStarted = false;
903
+ this.setOptions(options);
904
+ this.init(
905
+ false
906
+ /*start*/
907
+ );
908
+ }
909
+ expire() {
910
+ this.trace("expire captcha");
911
+ if (this._workersPool) {
912
+ this._workersPool.stop();
913
+ }
914
+ this.setState(STATE_EMPTY);
915
+ this.setProgressState(STATE_EMPTY);
916
+ this.ensureNoSolutionField();
917
+ this.init(this._userStarted);
918
+ }
919
+ solution() {
920
+ return this._solution;
921
+ }
922
+ onFocusIn(event) {
923
+ this.trace("onFocusIn event handler");
924
+ const pcElement = this._element.querySelector("private-captcha");
925
+ if (pcElement && event.target == pcElement) {
926
+ this.trace("skipping focusin event on captcha element");
927
+ return;
928
+ }
929
+ this.init(
930
+ false
931
+ /*start*/
932
+ );
933
+ this.setProgressState(this._state);
934
+ }
935
+ execute() {
936
+ this.onChecked();
937
+ return new Promise(() => {
938
+ });
939
+ }
940
+ onChecked() {
941
+ this.trace(`onChecked event handler. state=${this._state}`);
942
+ this._userStarted = true;
943
+ let progressState = STATE_IN_PROGRESS;
944
+ let finished = false;
945
+ switch (this._state) {
946
+ case STATE_READY:
947
+ this.start();
948
+ break;
949
+ case STATE_EMPTY:
950
+ case STATE_ERROR:
951
+ this.init(
952
+ true
953
+ /*start*/
954
+ );
955
+ break;
956
+ case STATE_LOADING:
957
+ break;
958
+ case STATE_IN_PROGRESS:
959
+ setTimeout(() => this.setProgress(this._lastProgress), 500);
960
+ break;
961
+ case STATE_VERIFIED:
962
+ progressState = STATE_VERIFIED;
963
+ finished = true;
964
+ break;
965
+ default:
966
+ console.warn("[privatecaptcha] onChecked: unexpected state. state=" + this._state);
967
+ return;
968
+ }
969
+ ;
970
+ this.setProgressState(progressState);
971
+ if (finished) {
972
+ this.signalFinished();
973
+ }
974
+ }
975
+ onWorkersReady(autoStart) {
976
+ this.trace(`workers are ready. autostart=${autoStart}`);
977
+ this.setState(STATE_READY);
978
+ if (!this._userStarted) {
979
+ this.setProgressState(STATE_READY);
980
+ }
981
+ if (autoStart || this._userStarted) {
982
+ this.start();
983
+ }
984
+ }
985
+ onWorkerError(error) {
986
+ console.error("[privatecaptcha] error in worker:", error);
987
+ this._errorCode = ERROR_SOLVE_PUZZLE;
988
+ }
989
+ onWorkStarted() {
990
+ this.signalStarted();
991
+ }
992
+ onWorkCompleted() {
993
+ this.trace("[privatecaptcha] work completed");
994
+ if (this._state !== STATE_IN_PROGRESS) {
995
+ console.warn(`[privatecaptcha] solving has not been started. state=${this._state}`);
996
+ return;
997
+ }
998
+ this.setState(STATE_VERIFIED);
999
+ if (this._userStarted) {
1000
+ this.setProgressState(STATE_VERIFIED);
1001
+ }
1002
+ this.saveSolutions();
1003
+ if (this._userStarted) {
1004
+ this.signalFinished();
1005
+ }
1006
+ }
1007
+ onWorkProgress(percent) {
1008
+ if (this._state !== STATE_IN_PROGRESS) {
1009
+ console.warn(`[privatecaptcha] skipping progress update. state=${this._state}`);
1010
+ return;
1011
+ }
1012
+ this.trace(`progress changed. percent=${percent}`);
1013
+ this.setProgress(percent);
1014
+ }
1015
+ saveSolutions() {
1016
+ const solutions = this._workersPool.serializeSolutions(this._errorCode);
1017
+ const payload = `${solutions}.${this._puzzle.rawData}`;
1018
+ this.ensureNoSolutionField();
1019
+ this._element.insertAdjacentHTML("beforeend", `<input name="${this._options.fieldName}" type="hidden" value="${payload}">`);
1020
+ this._solution = payload;
1021
+ this.trace(`saved solutions. payload=${payload}`);
1022
+ }
1023
+ // this updates the "UI" state of the widget
1024
+ setProgressState(state) {
1025
+ const canShow = this._userStarted || DISPLAY_WIDGET === this._options.displayMode;
1026
+ const pcElement = this._element.querySelector("private-captcha");
1027
+ if (pcElement) {
1028
+ pcElement.setError(this._errorCode);
1029
+ pcElement.setState(state, canShow);
1030
+ } else {
1031
+ console.error("[privatecaptcha] component not found when changing state");
1032
+ }
1033
+ }
1034
+ // this updates the "internal" (actual) state
1035
+ setState(state) {
1036
+ this.trace(`change state. old=${this._state} new=${state}`);
1037
+ this._state = state;
1038
+ if (this._options.debug) {
1039
+ const pcElement = this._element.querySelector("private-captcha");
1040
+ if (pcElement) {
1041
+ pcElement.setDebugText(state, STATE_ERROR == state);
1042
+ }
1043
+ }
1044
+ }
1045
+ setProgress(progress) {
1046
+ this._lastProgress = progress;
1047
+ if (STATE_IN_PROGRESS == this._state || STATE_VERIFIED == this._state) {
1048
+ const pcElement = this._element.querySelector("private-captcha");
1049
+ if (pcElement) {
1050
+ pcElement.setProgress(progress);
1051
+ } else {
1052
+ console.error("[privatecaptcha] component not found when updating progress");
1053
+ }
1054
+ }
1055
+ }
1056
+ trace(str) {
1057
+ if (this._options.debug) {
1058
+ console.debug("[privatecaptcha]", str);
1059
+ }
1060
+ }
1061
+ };
1062
+ })();
1063
+ //# sourceMappingURL=index.js.map