altcha 0.1.0
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.
- package/README.md +76 -0
- package/dist/altcha.d.ts +1 -0
- package/dist/altcha.js +976 -0
- package/dist/altcha.umd.cjs +1 -0
- package/package.json +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# ALTCHA
|
|
2
|
+
|
|
3
|
+
ALTCHA uses a proof-of-work mechanism to protect your website, APIs, and online services from spam and abuse. Unlike other solutions, ALTCHA is self-hosted, does not use cookies nor fingerprinting, does not track users, and is fully compliant with GDPR.
|
|
4
|
+
|
|
5
|
+
## Benefits
|
|
6
|
+
|
|
7
|
+
- __Friction-less__ - Using PoW instead of visual puzzles.
|
|
8
|
+
- __Cookie-less__ - GDPR compliant by design.
|
|
9
|
+
- __Self-hosted__ - Without reliance on external providers.
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
ALTCHA widget is distributed as a "Web Component" and [supports all modern browsers](https://developer.mozilla.org/en-US/docs/Web/API/Web_components#browser_compatibility).
|
|
14
|
+
|
|
15
|
+
### 1. Add `<script>` tag to your website
|
|
16
|
+
|
|
17
|
+
```html
|
|
18
|
+
<script async defer src="/altcha.js" type="module"></script>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. Use `<altcha-box>` tag in your forms
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<form>
|
|
25
|
+
<altcha-box
|
|
26
|
+
challengeurl="https://..."
|
|
27
|
+
></altcha-box>
|
|
28
|
+
</form>
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
See the [configuration](#configuration) below or visit the [website integration documentation](https://altcha.org/docs/website-integration).
|
|
32
|
+
|
|
33
|
+
### 3. Integrate ALCTHA with your server
|
|
34
|
+
|
|
35
|
+
See [server documentation](https://altcha.org/docs/server-integration) for more details.
|
|
36
|
+
|
|
37
|
+
## Configuration
|
|
38
|
+
|
|
39
|
+
Main options:
|
|
40
|
+
|
|
41
|
+
- __challengeurl__ - The URL of your server, where to fetch the challenge from. See [server integration](/docs/server-integration).
|
|
42
|
+
- __challengejson__ - The JSON-encoded challenge. If you don't want to make an HTTP request to `challengeurl`, provide the data here instead.
|
|
43
|
+
|
|
44
|
+
Customization options:
|
|
45
|
+
|
|
46
|
+
- __hidefooter__ - Hide the footer (ALTCHA link).
|
|
47
|
+
- __hidelogo__ - Hide the ALTCHA logo.
|
|
48
|
+
- __maxnumber__ - Max. number to iterate to (defaults to 10,000,000).
|
|
49
|
+
- __name__ - The name of the hidden field containing payload (defaults to "altcha").
|
|
50
|
+
- __strings__ - JSON-encoded translation strings. See [customization](/docs/widget-customization).
|
|
51
|
+
|
|
52
|
+
Development / testing options:
|
|
53
|
+
|
|
54
|
+
- __debug__ - Print log messages into the console.
|
|
55
|
+
- __mockerror__ - Causes the verification to always fail with a "mock" error.
|
|
56
|
+
- __test__ - This option will make the widget generate its own "mock" challenge, thus __not__ making the request to the `challengeurl`.
|
|
57
|
+
|
|
58
|
+
Events:
|
|
59
|
+
|
|
60
|
+
- __statechange__ - triggers whenever an internal `state` changes.
|
|
61
|
+
- __verified__ - triggers when the challenge is verified.
|
|
62
|
+
|
|
63
|
+
Using events:
|
|
64
|
+
|
|
65
|
+
```js
|
|
66
|
+
document.querySelector('#altcha').addEventListener('statechange', (ev) => {
|
|
67
|
+
// state can be: unverified, verifying, verified, error
|
|
68
|
+
console.log('state:', ev.detail.state);
|
|
69
|
+
});
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
## License
|
|
74
|
+
|
|
75
|
+
MIT
|
|
76
|
+
|
package/dist/altcha.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
declare module 'altcha';
|
package/dist/altcha.js
ADDED
|
@@ -0,0 +1,976 @@
|
|
|
1
|
+
var Ce = Object.defineProperty;
|
|
2
|
+
var xe = (t, e, n) => e in t ? Ce(t, e, { enumerable: !0, configurable: !0, writable: !0, value: n }) : t[e] = n;
|
|
3
|
+
var x = (t, e, n) => (xe(t, typeof e != "symbol" ? e + "" : e, n), n);
|
|
4
|
+
function Z() {
|
|
5
|
+
}
|
|
6
|
+
function fe(t) {
|
|
7
|
+
return t();
|
|
8
|
+
}
|
|
9
|
+
function re() {
|
|
10
|
+
return /* @__PURE__ */ Object.create(null);
|
|
11
|
+
}
|
|
12
|
+
function K(t) {
|
|
13
|
+
t.forEach(fe);
|
|
14
|
+
}
|
|
15
|
+
function he(t) {
|
|
16
|
+
return typeof t == "function";
|
|
17
|
+
}
|
|
18
|
+
function Le(t, e) {
|
|
19
|
+
return t != t ? e == e : t !== e || t && typeof t == "object" || typeof t == "function";
|
|
20
|
+
}
|
|
21
|
+
function Re(t) {
|
|
22
|
+
return Object.keys(t).length === 0;
|
|
23
|
+
}
|
|
24
|
+
function m(t, e) {
|
|
25
|
+
t.appendChild(e);
|
|
26
|
+
}
|
|
27
|
+
function Ie(t, e, n) {
|
|
28
|
+
const l = Ne(t);
|
|
29
|
+
if (!l.getElementById(e)) {
|
|
30
|
+
const i = p("style");
|
|
31
|
+
i.id = e, i.textContent = n, Ae(l, i);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function Ne(t) {
|
|
35
|
+
if (!t)
|
|
36
|
+
return document;
|
|
37
|
+
const e = t.getRootNode ? t.getRootNode() : t.ownerDocument;
|
|
38
|
+
return e && /** @type {ShadowRoot} */
|
|
39
|
+
e.host ? (
|
|
40
|
+
/** @type {ShadowRoot} */
|
|
41
|
+
e
|
|
42
|
+
) : t.ownerDocument;
|
|
43
|
+
}
|
|
44
|
+
function Ae(t, e) {
|
|
45
|
+
return m(
|
|
46
|
+
/** @type {Document} */
|
|
47
|
+
t.head || t,
|
|
48
|
+
e
|
|
49
|
+
), e.sheet;
|
|
50
|
+
}
|
|
51
|
+
function M(t, e, n) {
|
|
52
|
+
t.insertBefore(e, n || null);
|
|
53
|
+
}
|
|
54
|
+
function A(t) {
|
|
55
|
+
t.parentNode && t.parentNode.removeChild(t);
|
|
56
|
+
}
|
|
57
|
+
function p(t) {
|
|
58
|
+
return document.createElement(t);
|
|
59
|
+
}
|
|
60
|
+
function V(t) {
|
|
61
|
+
return document.createElementNS("http://www.w3.org/2000/svg", t);
|
|
62
|
+
}
|
|
63
|
+
function Me(t) {
|
|
64
|
+
return document.createTextNode(t);
|
|
65
|
+
}
|
|
66
|
+
function S() {
|
|
67
|
+
return Me(" ");
|
|
68
|
+
}
|
|
69
|
+
function z(t, e, n, l) {
|
|
70
|
+
return t.addEventListener(e, n, l), () => t.removeEventListener(e, n, l);
|
|
71
|
+
}
|
|
72
|
+
function o(t, e, n) {
|
|
73
|
+
n == null ? t.removeAttribute(e) : t.getAttribute(e) !== n && t.setAttribute(e, n);
|
|
74
|
+
}
|
|
75
|
+
function Ve(t) {
|
|
76
|
+
return Array.from(t.childNodes);
|
|
77
|
+
}
|
|
78
|
+
function le(t, e, n) {
|
|
79
|
+
t.classList.toggle(e, !!n);
|
|
80
|
+
}
|
|
81
|
+
function Oe(t, e, { bubbles: n = !1, cancelable: l = !1 } = {}) {
|
|
82
|
+
return new CustomEvent(t, { detail: e, bubbles: n, cancelable: l });
|
|
83
|
+
}
|
|
84
|
+
function Fe(t) {
|
|
85
|
+
const e = {};
|
|
86
|
+
return t.childNodes.forEach(
|
|
87
|
+
/** @param {Element} node */
|
|
88
|
+
(n) => {
|
|
89
|
+
e[n.slot || "default"] = !0;
|
|
90
|
+
}
|
|
91
|
+
), e;
|
|
92
|
+
}
|
|
93
|
+
let U;
|
|
94
|
+
function Y(t) {
|
|
95
|
+
U = t;
|
|
96
|
+
}
|
|
97
|
+
function te() {
|
|
98
|
+
if (!U)
|
|
99
|
+
throw new Error("Function called outside component initialization");
|
|
100
|
+
return U;
|
|
101
|
+
}
|
|
102
|
+
function He(t) {
|
|
103
|
+
te().$$.on_mount.push(t);
|
|
104
|
+
}
|
|
105
|
+
function Se(t) {
|
|
106
|
+
te().$$.on_destroy.push(t);
|
|
107
|
+
}
|
|
108
|
+
function Ge() {
|
|
109
|
+
const t = te();
|
|
110
|
+
return (e, n, { cancelable: l = !1 } = {}) => {
|
|
111
|
+
const i = t.$$.callbacks[e];
|
|
112
|
+
if (i) {
|
|
113
|
+
const r = Oe(
|
|
114
|
+
/** @type {string} */
|
|
115
|
+
e,
|
|
116
|
+
n,
|
|
117
|
+
{ cancelable: l }
|
|
118
|
+
);
|
|
119
|
+
return i.slice().forEach((c) => {
|
|
120
|
+
c.call(t, r);
|
|
121
|
+
}), !r.defaultPrevented;
|
|
122
|
+
}
|
|
123
|
+
return !0;
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
const T = [], Q = [];
|
|
127
|
+
let W = [];
|
|
128
|
+
const ie = [], Te = /* @__PURE__ */ Promise.resolve();
|
|
129
|
+
let q = !1;
|
|
130
|
+
function We() {
|
|
131
|
+
q || (q = !0, Te.then(N));
|
|
132
|
+
}
|
|
133
|
+
function ee(t) {
|
|
134
|
+
W.push(t);
|
|
135
|
+
}
|
|
136
|
+
const J = /* @__PURE__ */ new Set();
|
|
137
|
+
let G = 0;
|
|
138
|
+
function N() {
|
|
139
|
+
if (G !== 0)
|
|
140
|
+
return;
|
|
141
|
+
const t = U;
|
|
142
|
+
do {
|
|
143
|
+
try {
|
|
144
|
+
for (; G < T.length; ) {
|
|
145
|
+
const e = T[G];
|
|
146
|
+
G++, Y(e), Be(e.$$);
|
|
147
|
+
}
|
|
148
|
+
} catch (e) {
|
|
149
|
+
throw T.length = 0, G = 0, e;
|
|
150
|
+
}
|
|
151
|
+
for (Y(null), T.length = 0, G = 0; Q.length; )
|
|
152
|
+
Q.pop()();
|
|
153
|
+
for (let e = 0; e < W.length; e += 1) {
|
|
154
|
+
const n = W[e];
|
|
155
|
+
J.has(n) || (J.add(n), n());
|
|
156
|
+
}
|
|
157
|
+
W.length = 0;
|
|
158
|
+
} while (T.length);
|
|
159
|
+
for (; ie.length; )
|
|
160
|
+
ie.pop()();
|
|
161
|
+
q = !1, J.clear(), Y(t);
|
|
162
|
+
}
|
|
163
|
+
function Be(t) {
|
|
164
|
+
if (t.fragment !== null) {
|
|
165
|
+
t.update(), K(t.before_update);
|
|
166
|
+
const e = t.dirty;
|
|
167
|
+
t.dirty = [-1], t.fragment && t.fragment.p(t.ctx, e), t.after_update.forEach(ee);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function Ye(t) {
|
|
171
|
+
const e = [], n = [];
|
|
172
|
+
W.forEach((l) => t.indexOf(l) === -1 ? e.push(l) : n.push(l)), n.forEach((l) => l()), W = e;
|
|
173
|
+
}
|
|
174
|
+
const Ze = /* @__PURE__ */ new Set();
|
|
175
|
+
function Ue(t, e) {
|
|
176
|
+
t && t.i && (Ze.delete(t), t.i(e));
|
|
177
|
+
}
|
|
178
|
+
function Ke(t, e, n) {
|
|
179
|
+
const { fragment: l, after_update: i } = t.$$;
|
|
180
|
+
l && l.m(e, n), ee(() => {
|
|
181
|
+
const r = t.$$.on_mount.map(fe).filter(he);
|
|
182
|
+
t.$$.on_destroy ? t.$$.on_destroy.push(...r) : K(r), t.$$.on_mount = [];
|
|
183
|
+
}), i.forEach(ee);
|
|
184
|
+
}
|
|
185
|
+
function Pe(t, e) {
|
|
186
|
+
const n = t.$$;
|
|
187
|
+
n.fragment !== null && (Ye(n.after_update), K(n.on_destroy), n.fragment && n.fragment.d(e), n.on_destroy = n.fragment = null, n.ctx = []);
|
|
188
|
+
}
|
|
189
|
+
function Xe(t, e) {
|
|
190
|
+
t.$$.dirty[0] === -1 && (T.push(t), We(), t.$$.dirty.fill(0)), t.$$.dirty[e / 31 | 0] |= 1 << e % 31;
|
|
191
|
+
}
|
|
192
|
+
function De(t, e, n, l, i, r, c = null, a = [-1]) {
|
|
193
|
+
const u = U;
|
|
194
|
+
Y(t);
|
|
195
|
+
const f = t.$$ = {
|
|
196
|
+
fragment: null,
|
|
197
|
+
ctx: [],
|
|
198
|
+
// state
|
|
199
|
+
props: r,
|
|
200
|
+
update: Z,
|
|
201
|
+
not_equal: i,
|
|
202
|
+
bound: re(),
|
|
203
|
+
// lifecycle
|
|
204
|
+
on_mount: [],
|
|
205
|
+
on_destroy: [],
|
|
206
|
+
on_disconnect: [],
|
|
207
|
+
before_update: [],
|
|
208
|
+
after_update: [],
|
|
209
|
+
context: new Map(e.context || (u ? u.$$.context : [])),
|
|
210
|
+
// everything else
|
|
211
|
+
callbacks: re(),
|
|
212
|
+
dirty: a,
|
|
213
|
+
skip_bound: !1,
|
|
214
|
+
root: e.target || u.$$.root
|
|
215
|
+
};
|
|
216
|
+
c && c(f.root);
|
|
217
|
+
let L = !1;
|
|
218
|
+
if (f.ctx = n ? n(t, e.props || {}, (g, $, ...k) => {
|
|
219
|
+
const y = k.length ? k[0] : $;
|
|
220
|
+
return f.ctx && i(f.ctx[g], f.ctx[g] = y) && (!f.skip_bound && f.bound[g] && f.bound[g](y), L && Xe(t, g)), $;
|
|
221
|
+
}) : [], f.update(), L = !0, K(f.before_update), f.fragment = l ? l(f.ctx) : !1, e.target) {
|
|
222
|
+
if (e.hydrate) {
|
|
223
|
+
const g = Ve(e.target);
|
|
224
|
+
f.fragment && f.fragment.l(g), g.forEach(A);
|
|
225
|
+
} else
|
|
226
|
+
f.fragment && f.fragment.c();
|
|
227
|
+
e.intro && Ue(t.$$.fragment), Ke(t, e.target, e.anchor), N();
|
|
228
|
+
}
|
|
229
|
+
Y(u);
|
|
230
|
+
}
|
|
231
|
+
let de;
|
|
232
|
+
typeof HTMLElement == "function" && (de = class extends HTMLElement {
|
|
233
|
+
constructor(e, n, l) {
|
|
234
|
+
super();
|
|
235
|
+
/** The Svelte component constructor */
|
|
236
|
+
x(this, "$$ctor");
|
|
237
|
+
/** Slots */
|
|
238
|
+
x(this, "$$s");
|
|
239
|
+
/** The Svelte component instance */
|
|
240
|
+
x(this, "$$c");
|
|
241
|
+
/** Whether or not the custom element is connected */
|
|
242
|
+
x(this, "$$cn", !1);
|
|
243
|
+
/** Component props data */
|
|
244
|
+
x(this, "$$d", {});
|
|
245
|
+
/** `true` if currently in the process of reflecting component props back to attributes */
|
|
246
|
+
x(this, "$$r", !1);
|
|
247
|
+
/** @type {Record<string, CustomElementPropDefinition>} Props definition (name, reflected, type etc) */
|
|
248
|
+
x(this, "$$p_d", {});
|
|
249
|
+
/** @type {Record<string, Function[]>} Event listeners */
|
|
250
|
+
x(this, "$$l", {});
|
|
251
|
+
/** @type {Map<Function, Function>} Event listener unsubscribe functions */
|
|
252
|
+
x(this, "$$l_u", /* @__PURE__ */ new Map());
|
|
253
|
+
this.$$ctor = e, this.$$s = n, l && this.attachShadow({ mode: "open" });
|
|
254
|
+
}
|
|
255
|
+
addEventListener(e, n, l) {
|
|
256
|
+
if (this.$$l[e] = this.$$l[e] || [], this.$$l[e].push(n), this.$$c) {
|
|
257
|
+
const i = this.$$c.$on(e, n);
|
|
258
|
+
this.$$l_u.set(n, i);
|
|
259
|
+
}
|
|
260
|
+
super.addEventListener(e, n, l);
|
|
261
|
+
}
|
|
262
|
+
removeEventListener(e, n, l) {
|
|
263
|
+
if (super.removeEventListener(e, n, l), this.$$c) {
|
|
264
|
+
const i = this.$$l_u.get(n);
|
|
265
|
+
i && (i(), this.$$l_u.delete(n));
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
async connectedCallback() {
|
|
269
|
+
if (this.$$cn = !0, !this.$$c) {
|
|
270
|
+
let e = function(r) {
|
|
271
|
+
return () => {
|
|
272
|
+
let c;
|
|
273
|
+
return {
|
|
274
|
+
c: function() {
|
|
275
|
+
c = p("slot"), r !== "default" && o(c, "name", r);
|
|
276
|
+
},
|
|
277
|
+
/**
|
|
278
|
+
* @param {HTMLElement} target
|
|
279
|
+
* @param {HTMLElement} [anchor]
|
|
280
|
+
*/
|
|
281
|
+
m: function(f, L) {
|
|
282
|
+
M(f, c, L);
|
|
283
|
+
},
|
|
284
|
+
d: function(f) {
|
|
285
|
+
f && A(c);
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
if (await Promise.resolve(), !this.$$cn)
|
|
291
|
+
return;
|
|
292
|
+
const n = {}, l = Fe(this);
|
|
293
|
+
for (const r of this.$$s)
|
|
294
|
+
r in l && (n[r] = [e(r)]);
|
|
295
|
+
for (const r of this.attributes) {
|
|
296
|
+
const c = this.$$g_p(r.name);
|
|
297
|
+
c in this.$$d || (this.$$d[c] = X(c, r.value, this.$$p_d, "toProp"));
|
|
298
|
+
}
|
|
299
|
+
this.$$c = new this.$$ctor({
|
|
300
|
+
target: this.shadowRoot || this,
|
|
301
|
+
props: {
|
|
302
|
+
...this.$$d,
|
|
303
|
+
$$slots: n,
|
|
304
|
+
$$scope: {
|
|
305
|
+
ctx: []
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
const i = () => {
|
|
310
|
+
this.$$r = !0;
|
|
311
|
+
for (const r in this.$$p_d)
|
|
312
|
+
if (this.$$d[r] = this.$$c.$$.ctx[this.$$c.$$.props[r]], this.$$p_d[r].reflect) {
|
|
313
|
+
const c = X(
|
|
314
|
+
r,
|
|
315
|
+
this.$$d[r],
|
|
316
|
+
this.$$p_d,
|
|
317
|
+
"toAttribute"
|
|
318
|
+
);
|
|
319
|
+
c == null ? this.removeAttribute(this.$$p_d[r].attribute || r) : this.setAttribute(this.$$p_d[r].attribute || r, c);
|
|
320
|
+
}
|
|
321
|
+
this.$$r = !1;
|
|
322
|
+
};
|
|
323
|
+
this.$$c.$$.after_update.push(i), i();
|
|
324
|
+
for (const r in this.$$l)
|
|
325
|
+
for (const c of this.$$l[r]) {
|
|
326
|
+
const a = this.$$c.$on(r, c);
|
|
327
|
+
this.$$l_u.set(c, a);
|
|
328
|
+
}
|
|
329
|
+
this.$$l = {};
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
// We don't need this when working within Svelte code, but for compatibility of people using this outside of Svelte
|
|
333
|
+
// and setting attributes through setAttribute etc, this is helpful
|
|
334
|
+
attributeChangedCallback(e, n, l) {
|
|
335
|
+
var i;
|
|
336
|
+
this.$$r || (e = this.$$g_p(e), this.$$d[e] = X(e, l, this.$$p_d, "toProp"), (i = this.$$c) == null || i.$set({ [e]: this.$$d[e] }));
|
|
337
|
+
}
|
|
338
|
+
disconnectedCallback() {
|
|
339
|
+
this.$$cn = !1, Promise.resolve().then(() => {
|
|
340
|
+
this.$$cn || (this.$$c.$destroy(), this.$$c = void 0);
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
$$g_p(e) {
|
|
344
|
+
return Object.keys(this.$$p_d).find(
|
|
345
|
+
(n) => this.$$p_d[n].attribute === e || !this.$$p_d[n].attribute && n.toLowerCase() === e
|
|
346
|
+
) || e;
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
function X(t, e, n, l) {
|
|
350
|
+
var r;
|
|
351
|
+
const i = (r = n[t]) == null ? void 0 : r.type;
|
|
352
|
+
if (e = i === "Boolean" && typeof e != "boolean" ? e != null : e, !l || !n[t])
|
|
353
|
+
return e;
|
|
354
|
+
if (l === "toAttribute")
|
|
355
|
+
switch (i) {
|
|
356
|
+
case "Object":
|
|
357
|
+
case "Array":
|
|
358
|
+
return e == null ? null : JSON.stringify(e);
|
|
359
|
+
case "Boolean":
|
|
360
|
+
return e ? "" : null;
|
|
361
|
+
case "Number":
|
|
362
|
+
return e ?? null;
|
|
363
|
+
default:
|
|
364
|
+
return e;
|
|
365
|
+
}
|
|
366
|
+
else
|
|
367
|
+
switch (i) {
|
|
368
|
+
case "Object":
|
|
369
|
+
case "Array":
|
|
370
|
+
return e && JSON.parse(e);
|
|
371
|
+
case "Boolean":
|
|
372
|
+
return e;
|
|
373
|
+
case "Number":
|
|
374
|
+
return e != null ? +e : e;
|
|
375
|
+
default:
|
|
376
|
+
return e;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
function ze(t, e, n, l, i, r) {
|
|
380
|
+
let c = class extends de {
|
|
381
|
+
constructor() {
|
|
382
|
+
super(t, n, i), this.$$p_d = e;
|
|
383
|
+
}
|
|
384
|
+
static get observedAttributes() {
|
|
385
|
+
return Object.keys(e).map(
|
|
386
|
+
(a) => (e[a].attribute || a).toLowerCase()
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
};
|
|
390
|
+
return Object.keys(e).forEach((a) => {
|
|
391
|
+
Object.defineProperty(c.prototype, a, {
|
|
392
|
+
get() {
|
|
393
|
+
return this.$$c && a in this.$$c ? this.$$c[a] : this.$$d[a];
|
|
394
|
+
},
|
|
395
|
+
set(u) {
|
|
396
|
+
var f;
|
|
397
|
+
u = X(a, u, e), this.$$d[a] = u, (f = this.$$c) == null || f.$set({ [a]: u });
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
}), l.forEach((a) => {
|
|
401
|
+
Object.defineProperty(c.prototype, a, {
|
|
402
|
+
get() {
|
|
403
|
+
var u;
|
|
404
|
+
return (u = this.$$c) == null ? void 0 : u[a];
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
}), r && (c = r(c)), t.element = /** @type {any} */
|
|
408
|
+
c, c;
|
|
409
|
+
}
|
|
410
|
+
class Je {
|
|
411
|
+
constructor() {
|
|
412
|
+
/**
|
|
413
|
+
* ### PRIVATE API
|
|
414
|
+
*
|
|
415
|
+
* Do not use, may change at any time
|
|
416
|
+
*
|
|
417
|
+
* @type {any}
|
|
418
|
+
*/
|
|
419
|
+
x(this, "$$");
|
|
420
|
+
/**
|
|
421
|
+
* ### PRIVATE API
|
|
422
|
+
*
|
|
423
|
+
* Do not use, may change at any time
|
|
424
|
+
*
|
|
425
|
+
* @type {any}
|
|
426
|
+
*/
|
|
427
|
+
x(this, "$$set");
|
|
428
|
+
}
|
|
429
|
+
/** @returns {void} */
|
|
430
|
+
$destroy() {
|
|
431
|
+
Pe(this, 1), this.$destroy = Z;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* @template {Extract<keyof Events, string>} K
|
|
435
|
+
* @param {K} type
|
|
436
|
+
* @param {((e: Events[K]) => void) | null | undefined} callback
|
|
437
|
+
* @returns {() => void}
|
|
438
|
+
*/
|
|
439
|
+
$on(e, n) {
|
|
440
|
+
if (!he(n))
|
|
441
|
+
return Z;
|
|
442
|
+
const l = this.$$.callbacks[e] || (this.$$.callbacks[e] = []);
|
|
443
|
+
return l.push(n), () => {
|
|
444
|
+
const i = l.indexOf(n);
|
|
445
|
+
i !== -1 && l.splice(i, 1);
|
|
446
|
+
};
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* @param {Partial<Props>} props
|
|
450
|
+
* @returns {void}
|
|
451
|
+
*/
|
|
452
|
+
$set(e) {
|
|
453
|
+
this.$$set && !Re(e) && (this.$$.skip_bound = !0, this.$$set(e), this.$$.skip_bound = !1);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
const Qe = "4";
|
|
457
|
+
typeof window < "u" && (window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(Qe);
|
|
458
|
+
const me = "KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLHIuZW5jb2RlKGUrbikpKX1hc3luYyBmdW5jdGlvbiBpKGUsbixhPSJTSEEtMjU2IixvPTFlNyl7Y29uc3Qgcz1EYXRlLm5vdygpO2ZvcihsZXQgdD0wO3Q8PW87dCsrKWlmKGF3YWl0IGwobix0LGEpPT09ZSlyZXR1cm57bnVtYmVyOnQsdG9vazpEYXRlLm5vdygpLXN9O3JldHVybiBudWxsfW9ubWVzc2FnZT1hc3luYyBlPT57Y29uc3R7YWxnOm4sY2hhbGxlbmdlOmEsbWF4Om8sc2FsdDpzfT1lLmRhdGF8fHt9O2lmKGEmJnMpe2NvbnN0IHQ9YXdhaXQgaShhLHMsbixvKTtzZWxmLnBvc3RNZXNzYWdlKHQmJnsuLi50LHdvcmtlcjohMH0pfWVsc2Ugc2VsZi5wb3N0TWVzc2FnZShudWxsKX19KSgpOwo=", se = typeof window < "u" && window.Blob && new Blob([atob(me)], { type: "text/javascript;charset=utf-8" });
|
|
459
|
+
function qe() {
|
|
460
|
+
let t;
|
|
461
|
+
try {
|
|
462
|
+
if (t = se && (window.URL || window.webkitURL).createObjectURL(se), !t)
|
|
463
|
+
throw "";
|
|
464
|
+
return new Worker(t);
|
|
465
|
+
} catch {
|
|
466
|
+
return new Worker("data:application/javascript;base64," + me);
|
|
467
|
+
} finally {
|
|
468
|
+
t && (window.URL || window.webkitURL).revokeObjectURL(t);
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
const et = 1e7, tt = new TextEncoder();
|
|
472
|
+
function nt(t) {
|
|
473
|
+
return [...new Uint8Array(t)].map((e) => e.toString(16).padStart(2, "0")).join("");
|
|
474
|
+
}
|
|
475
|
+
async function rt(t = 1e5, e = "SHA-256") {
|
|
476
|
+
const n = Date.now().toString(16), l = await ge(n, Math.round(Math.random() * t), e);
|
|
477
|
+
return {
|
|
478
|
+
algorithm: e,
|
|
479
|
+
challenge: l,
|
|
480
|
+
salt: n,
|
|
481
|
+
signature: ""
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
async function ge(t, e, n) {
|
|
485
|
+
return nt(await crypto.subtle.digest(n, tt.encode(t + e)));
|
|
486
|
+
}
|
|
487
|
+
async function lt(t, e, n = "SHA-256", l = et) {
|
|
488
|
+
const i = Date.now();
|
|
489
|
+
for (let r = 0; r <= l; r++)
|
|
490
|
+
if (await ge(e, r, n) === t)
|
|
491
|
+
return {
|
|
492
|
+
number: r,
|
|
493
|
+
took: Date.now() - i
|
|
494
|
+
};
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
var j = /* @__PURE__ */ ((t) => (t.ERROR = "error", t.VERIFIED = "verified", t.VERIFYING = "verifying", t.UNVERIFIED = "unverfied", t))(j || {});
|
|
498
|
+
function it(t) {
|
|
499
|
+
Ie(t, "svelte-mjm2j6", ".altcha.svelte-mjm2j6.svelte-mjm2j6{background:var(--altcha-color-base, #ffffff);border:1px solid var(--altcha-color-border, #a0a0a0);border-radius:3px;color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:260px;overflow:hidden;position:relative}.altcha.svelte-mjm2j6.svelte-mjm2j6:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-mjm2j6.svelte-mjm2j6{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-mjm2j6.svelte-mjm2j6{flex-grow:1}.altcha-label.svelte-mjm2j6 label.svelte-mjm2j6{cursor:pointer}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6{color:currentColor;opacity:0.3}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6:hover{opacity:1}.altcha-error.svelte-mjm2j6.svelte-mjm2j6{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-mjm2j6.svelte-mjm2j6{align-items:center;background-color:var(--altcha-color-footer-bg, #f4f4f4);display:flex;font-size:0.75rem;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-mjm2j6>.svelte-mjm2j6:first-child{flex-grow:1}.altcha-footer.svelte-mjm2j6 a{color:currentColor}.altcha-checkbox.svelte-mjm2j6.svelte-mjm2j6{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-mjm2j6 input.svelte-mjm2j6{width:18px;height:18px;margin:0}.altcha-hidden.svelte-mjm2j6.svelte-mjm2j6{display:none}.altcha-spinner.svelte-mjm2j6.svelte-mjm2j6{animation:svelte-mjm2j6-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-mjm2j6-altcha-spinner{100%{transform:rotate(360deg)}}");
|
|
500
|
+
}
|
|
501
|
+
function oe(t) {
|
|
502
|
+
let e, n, l;
|
|
503
|
+
return {
|
|
504
|
+
c() {
|
|
505
|
+
e = V("svg"), n = V("path"), l = V("path"), o(n, "d", "M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"), o(n, "fill", "currentColor"), o(n, "opacity", ".25"), o(l, "d", "M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"), o(l, "fill", "currentColor"), o(l, "class", "altcha-spinner svelte-mjm2j6"), o(e, "width", "24"), o(e, "height", "24"), o(e, "viewBox", "0 0 24 24"), o(e, "xmlns", "http://www.w3.org/2000/svg");
|
|
506
|
+
},
|
|
507
|
+
m(i, r) {
|
|
508
|
+
M(i, e, r), m(e, n), m(e, l);
|
|
509
|
+
},
|
|
510
|
+
d(i) {
|
|
511
|
+
i && A(e);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function st(t) {
|
|
516
|
+
let e, n = (
|
|
517
|
+
/*_strings*/
|
|
518
|
+
t[7].label + ""
|
|
519
|
+
), l;
|
|
520
|
+
return {
|
|
521
|
+
c() {
|
|
522
|
+
e = p("label"), o(e, "for", l = /*name*/
|
|
523
|
+
t[1] + "_checkbox"), o(e, "class", "svelte-mjm2j6");
|
|
524
|
+
},
|
|
525
|
+
m(i, r) {
|
|
526
|
+
M(i, e, r), e.innerHTML = n;
|
|
527
|
+
},
|
|
528
|
+
p(i, r) {
|
|
529
|
+
r[0] & /*_strings*/
|
|
530
|
+
128 && n !== (n = /*_strings*/
|
|
531
|
+
i[7].label + "") && (e.innerHTML = n), r[0] & /*name*/
|
|
532
|
+
2 && l !== (l = /*name*/
|
|
533
|
+
i[1] + "_checkbox") && o(e, "for", l);
|
|
534
|
+
},
|
|
535
|
+
d(i) {
|
|
536
|
+
i && A(e);
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
}
|
|
540
|
+
function ot(t) {
|
|
541
|
+
let e, n = (
|
|
542
|
+
/*_strings*/
|
|
543
|
+
t[7].verifying + ""
|
|
544
|
+
);
|
|
545
|
+
return {
|
|
546
|
+
c() {
|
|
547
|
+
e = p("span");
|
|
548
|
+
},
|
|
549
|
+
m(l, i) {
|
|
550
|
+
M(l, e, i), e.innerHTML = n;
|
|
551
|
+
},
|
|
552
|
+
p(l, i) {
|
|
553
|
+
i[0] & /*_strings*/
|
|
554
|
+
128 && n !== (n = /*_strings*/
|
|
555
|
+
l[7].verifying + "") && (e.innerHTML = n);
|
|
556
|
+
},
|
|
557
|
+
d(l) {
|
|
558
|
+
l && A(e);
|
|
559
|
+
}
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
function ct(t) {
|
|
563
|
+
let e, n = (
|
|
564
|
+
/*_strings*/
|
|
565
|
+
t[7].verified + ""
|
|
566
|
+
), l, i;
|
|
567
|
+
return {
|
|
568
|
+
c() {
|
|
569
|
+
e = p("span"), l = S(), i = p("input"), o(i, "type", "hidden"), o(
|
|
570
|
+
i,
|
|
571
|
+
"name",
|
|
572
|
+
/*name*/
|
|
573
|
+
t[1]
|
|
574
|
+
), i.value = /*payload*/
|
|
575
|
+
t[6];
|
|
576
|
+
},
|
|
577
|
+
m(r, c) {
|
|
578
|
+
M(r, e, c), e.innerHTML = n, M(r, l, c), M(r, i, c);
|
|
579
|
+
},
|
|
580
|
+
p(r, c) {
|
|
581
|
+
c[0] & /*_strings*/
|
|
582
|
+
128 && n !== (n = /*_strings*/
|
|
583
|
+
r[7].verified + "") && (e.innerHTML = n), c[0] & /*name*/
|
|
584
|
+
2 && o(
|
|
585
|
+
i,
|
|
586
|
+
"name",
|
|
587
|
+
/*name*/
|
|
588
|
+
r[1]
|
|
589
|
+
), c[0] & /*payload*/
|
|
590
|
+
64 && (i.value = /*payload*/
|
|
591
|
+
r[6]);
|
|
592
|
+
},
|
|
593
|
+
d(r) {
|
|
594
|
+
r && (A(e), A(l), A(i));
|
|
595
|
+
}
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
function ce(t) {
|
|
599
|
+
let e, n, l, i, r, c = (
|
|
600
|
+
/*_strings*/
|
|
601
|
+
t[7].error + ""
|
|
602
|
+
);
|
|
603
|
+
return {
|
|
604
|
+
c() {
|
|
605
|
+
e = p("div"), n = V("svg"), l = V("path"), i = S(), r = p("div"), o(l, "stroke-linecap", "round"), o(l, "stroke-linejoin", "round"), o(l, "d", "M6 18L18 6M6 6l12 12"), o(n, "width", "14"), o(n, "height", "14"), o(n, "xmlns", "http://www.w3.org/2000/svg"), o(n, "fill", "none"), o(n, "viewBox", "0 0 24 24"), o(n, "stroke-width", "1.5"), o(n, "stroke", "currentColor"), o(
|
|
606
|
+
r,
|
|
607
|
+
"title",
|
|
608
|
+
/*error*/
|
|
609
|
+
t[5]
|
|
610
|
+
), o(e, "class", "altcha-error svelte-mjm2j6");
|
|
611
|
+
},
|
|
612
|
+
m(a, u) {
|
|
613
|
+
M(a, e, u), m(e, n), m(n, l), m(e, i), m(e, r), r.innerHTML = c;
|
|
614
|
+
},
|
|
615
|
+
p(a, u) {
|
|
616
|
+
u[0] & /*_strings*/
|
|
617
|
+
128 && c !== (c = /*_strings*/
|
|
618
|
+
a[7].error + "") && (r.innerHTML = c), u[0] & /*error*/
|
|
619
|
+
32 && o(
|
|
620
|
+
r,
|
|
621
|
+
"title",
|
|
622
|
+
/*error*/
|
|
623
|
+
a[5]
|
|
624
|
+
);
|
|
625
|
+
},
|
|
626
|
+
d(a) {
|
|
627
|
+
a && A(e);
|
|
628
|
+
}
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
function ae(t) {
|
|
632
|
+
let e, n, l = (
|
|
633
|
+
/*_strings*/
|
|
634
|
+
t[7].footer + ""
|
|
635
|
+
);
|
|
636
|
+
return {
|
|
637
|
+
c() {
|
|
638
|
+
e = p("div"), n = p("div"), o(n, "class", "svelte-mjm2j6"), o(e, "class", "altcha-footer svelte-mjm2j6");
|
|
639
|
+
},
|
|
640
|
+
m(i, r) {
|
|
641
|
+
M(i, e, r), m(e, n), n.innerHTML = l;
|
|
642
|
+
},
|
|
643
|
+
p(i, r) {
|
|
644
|
+
r[0] & /*_strings*/
|
|
645
|
+
128 && l !== (l = /*_strings*/
|
|
646
|
+
i[7].footer + "") && (n.innerHTML = l);
|
|
647
|
+
},
|
|
648
|
+
d(i) {
|
|
649
|
+
i && A(e);
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
function at(t) {
|
|
654
|
+
let e, n, l, i, r, c, a, u, f, L, g, $, k, y, H, B, R, O, I, _ = (
|
|
655
|
+
/*state*/
|
|
656
|
+
t[2] === j.VERIFYING && oe()
|
|
657
|
+
);
|
|
658
|
+
function F(h, C) {
|
|
659
|
+
return (
|
|
660
|
+
/*state*/
|
|
661
|
+
h[2] === j.VERIFIED ? ct : (
|
|
662
|
+
/*state*/
|
|
663
|
+
h[2] === j.VERIFYING ? ot : st
|
|
664
|
+
)
|
|
665
|
+
);
|
|
666
|
+
}
|
|
667
|
+
let E = F(t), d = E(t), v = (
|
|
668
|
+
/*error*/
|
|
669
|
+
t[5] && ce(t)
|
|
670
|
+
), w = (
|
|
671
|
+
/*_strings*/
|
|
672
|
+
t[7].footer && /*hidefooter*/
|
|
673
|
+
t[0] !== !0 && ae(t)
|
|
674
|
+
);
|
|
675
|
+
return {
|
|
676
|
+
c() {
|
|
677
|
+
e = p("div"), n = p("div"), _ && _.c(), l = S(), i = p("div"), r = p("input"), a = S(), u = p("div"), d.c(), f = S(), L = p("div"), g = p("a"), $ = V("svg"), k = V("path"), y = V("path"), H = V("path"), B = S(), v && v.c(), R = S(), w && w.c(), o(r, "type", "checkbox"), o(r, "id", c = /*name*/
|
|
678
|
+
t[1] + "_checkbox"), r.required = !0, o(r, "class", "svelte-mjm2j6"), o(i, "class", "altcha-checkbox svelte-mjm2j6"), le(
|
|
679
|
+
i,
|
|
680
|
+
"altcha-hidden",
|
|
681
|
+
/*state*/
|
|
682
|
+
t[2] === j.VERIFYING
|
|
683
|
+
), o(u, "class", "altcha-label svelte-mjm2j6"), o(k, "d", "M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"), o(k, "fill", "currentColor"), o(y, "d", "M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"), o(y, "fill", "currentColor"), o(H, "d", "M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"), o(H, "fill", "currentColor"), o($, "width", "22"), o($, "height", "22"), o($, "viewBox", "0 0 20 20"), o($, "fill", "none"), o($, "xmlns", "http://www.w3.org/2000/svg"), o(g, "href", be), o(g, "target", "_blank"), o(g, "class", "altcha-logo svelte-mjm2j6"), o(n, "class", "altcha-main svelte-mjm2j6"), o(e, "class", "altcha svelte-mjm2j6"), o(
|
|
684
|
+
e,
|
|
685
|
+
"data-state",
|
|
686
|
+
/*state*/
|
|
687
|
+
t[2]
|
|
688
|
+
);
|
|
689
|
+
},
|
|
690
|
+
m(h, C) {
|
|
691
|
+
M(h, e, C), m(e, n), _ && _.m(n, null), m(n, l), m(n, i), m(i, r), r.checked = /*checked*/
|
|
692
|
+
t[3], m(n, a), m(n, u), d.m(u, null), m(n, f), m(n, L), m(L, g), m(g, $), m($, k), m($, y), m($, H), m(e, B), v && v.m(e, null), m(e, R), w && w.m(e, null), t[20](e), O || (I = [
|
|
693
|
+
z(
|
|
694
|
+
r,
|
|
695
|
+
"change",
|
|
696
|
+
/*input_change_handler*/
|
|
697
|
+
t[19]
|
|
698
|
+
),
|
|
699
|
+
z(
|
|
700
|
+
r,
|
|
701
|
+
"change",
|
|
702
|
+
/*onCheckedChange*/
|
|
703
|
+
t[8]
|
|
704
|
+
),
|
|
705
|
+
z(
|
|
706
|
+
r,
|
|
707
|
+
"invalid",
|
|
708
|
+
/*onInvalid*/
|
|
709
|
+
t[9]
|
|
710
|
+
)
|
|
711
|
+
], O = !0);
|
|
712
|
+
},
|
|
713
|
+
p(h, C) {
|
|
714
|
+
/*state*/
|
|
715
|
+
h[2] === j.VERIFYING ? _ || (_ = oe(), _.c(), _.m(n, l)) : _ && (_.d(1), _ = null), C[0] & /*name*/
|
|
716
|
+
2 && c !== (c = /*name*/
|
|
717
|
+
h[1] + "_checkbox") && o(r, "id", c), C[0] & /*checked*/
|
|
718
|
+
8 && (r.checked = /*checked*/
|
|
719
|
+
h[3]), C[0] & /*state*/
|
|
720
|
+
4 && le(
|
|
721
|
+
i,
|
|
722
|
+
"altcha-hidden",
|
|
723
|
+
/*state*/
|
|
724
|
+
h[2] === j.VERIFYING
|
|
725
|
+
), E === (E = F(h)) && d ? d.p(h, C) : (d.d(1), d = E(h), d && (d.c(), d.m(u, null))), /*error*/
|
|
726
|
+
h[5] ? v ? v.p(h, C) : (v = ce(h), v.c(), v.m(e, R)) : v && (v.d(1), v = null), /*_strings*/
|
|
727
|
+
h[7].footer && /*hidefooter*/
|
|
728
|
+
h[0] !== !0 ? w ? w.p(h, C) : (w = ae(h), w.c(), w.m(e, null)) : w && (w.d(1), w = null), C[0] & /*state*/
|
|
729
|
+
4 && o(
|
|
730
|
+
e,
|
|
731
|
+
"data-state",
|
|
732
|
+
/*state*/
|
|
733
|
+
h[2]
|
|
734
|
+
);
|
|
735
|
+
},
|
|
736
|
+
i: Z,
|
|
737
|
+
o: Z,
|
|
738
|
+
d(h) {
|
|
739
|
+
h && A(e), _ && _.d(), d.d(), v && v.d(), w && w.d(), t[20](null), O = !1, K(I);
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
const be = "https://altcha.org/";
|
|
744
|
+
function ue(t) {
|
|
745
|
+
return JSON.parse(t);
|
|
746
|
+
}
|
|
747
|
+
function ut(t, e, n) {
|
|
748
|
+
let l, i, r, { challengeurl: c = void 0 } = e, { challengejson: a = void 0 } = e, { debug: u = !1 } = e, { hidefooter: f = !1 } = e, { name: L = "altcha" } = e, { maxnumber: g = void 0 } = e, { mockerror: $ = !1 } = e, { strings: k = void 0 } = e, { test: y = !1 } = e;
|
|
749
|
+
const H = Ge(), B = ["SHA-256", "SHA-384", "SHA-512"];
|
|
750
|
+
let R = !1, O, I = null, _ = null, F = null, E = j.UNVERIFIED;
|
|
751
|
+
Se(() => {
|
|
752
|
+
I && (I.removeEventListener("submit", v), I.removeEventListener("reset", w), I = null);
|
|
753
|
+
}), He(() => {
|
|
754
|
+
d("mounted"), y && d("using test mode"), I = O.closest("form"), I && (I.addEventListener("submit", v), I.addEventListener("reset", w));
|
|
755
|
+
});
|
|
756
|
+
function d(...s) {
|
|
757
|
+
(u || s.some((b) => b instanceof Error)) && console[s[0] instanceof Error ? "error" : "log"]("ALTCHA", ...s);
|
|
758
|
+
}
|
|
759
|
+
function v() {
|
|
760
|
+
P();
|
|
761
|
+
}
|
|
762
|
+
function w() {
|
|
763
|
+
P();
|
|
764
|
+
}
|
|
765
|
+
function h(s, b) {
|
|
766
|
+
return btoa(JSON.stringify({
|
|
767
|
+
algorithm: s.algorithm,
|
|
768
|
+
challenge: s.challenge,
|
|
769
|
+
number: b.number,
|
|
770
|
+
salt: s.salt,
|
|
771
|
+
signature: s.signature,
|
|
772
|
+
test: y ? !0 : void 0,
|
|
773
|
+
took: b.took
|
|
774
|
+
}));
|
|
775
|
+
}
|
|
776
|
+
function C(s) {
|
|
777
|
+
if (!s.algorithm || !B.includes(s.algorithm))
|
|
778
|
+
throw new Error(`Unknown algorithm value. Allowed values: ${B.join(", ")}`);
|
|
779
|
+
if (!s.challenge || s.challenge.length < 40)
|
|
780
|
+
throw new Error("Challenge is too short. Min. 40 chars.");
|
|
781
|
+
if (!s.salt || s.salt.length < 10)
|
|
782
|
+
throw new Error("Salt is too short. Min. 10 chars.");
|
|
783
|
+
if (s.signature === void 0)
|
|
784
|
+
throw new Error("Signature is missing.");
|
|
785
|
+
}
|
|
786
|
+
async function $e() {
|
|
787
|
+
if ($)
|
|
788
|
+
throw d("mocking error"), new Error("Mocked error.");
|
|
789
|
+
if (l)
|
|
790
|
+
return d("using provided json data"), l;
|
|
791
|
+
if (y)
|
|
792
|
+
return d("generating test challenge"), rt();
|
|
793
|
+
{
|
|
794
|
+
if (!c)
|
|
795
|
+
throw new Error("Attribute challengeurl not set.");
|
|
796
|
+
d("fetching challenge from", c);
|
|
797
|
+
const s = await fetch(c);
|
|
798
|
+
if (s.status !== 200)
|
|
799
|
+
throw new Error(`Server responded with ${s.status}.`);
|
|
800
|
+
return s.json();
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
async function _e(s) {
|
|
804
|
+
let b = null;
|
|
805
|
+
if ("Worker" in window) {
|
|
806
|
+
try {
|
|
807
|
+
b = await ve(s.challenge, s.salt, s.algorithm);
|
|
808
|
+
} catch (D) {
|
|
809
|
+
d(D);
|
|
810
|
+
}
|
|
811
|
+
if ((b == null ? void 0 : b.number) !== void 0)
|
|
812
|
+
return { data: s, solution: b };
|
|
813
|
+
}
|
|
814
|
+
return {
|
|
815
|
+
data: s,
|
|
816
|
+
solution: await lt(s.challenge, s.salt, s.algorithm, g)
|
|
817
|
+
};
|
|
818
|
+
}
|
|
819
|
+
async function ve(s, b, D) {
|
|
820
|
+
const ne = new qe();
|
|
821
|
+
return new Promise((ke) => {
|
|
822
|
+
ne.addEventListener("message", (Ee) => {
|
|
823
|
+
ke(Ee.data);
|
|
824
|
+
}), ne.postMessage({ alg: D, challenge: s, max: g, salt: b });
|
|
825
|
+
});
|
|
826
|
+
}
|
|
827
|
+
function we() {
|
|
828
|
+
[j.UNVERIFIED, j.ERROR].includes(E) ? (P(j.VERIFYING), $e().then((s) => (C(s), d("challenge", s), _e(s))).then(({ data: s, solution: b }) => {
|
|
829
|
+
if (d("solution", b), (b == null ? void 0 : b.number) !== void 0)
|
|
830
|
+
d("verified"), n(2, E = j.VERIFIED), n(3, R = !0), n(6, F = h(s, b)), H("verified", { payload: F }), d("payload", F);
|
|
831
|
+
else
|
|
832
|
+
throw new Error("Unexpected result returned.");
|
|
833
|
+
}).catch((s) => {
|
|
834
|
+
d(s), n(2, E = j.ERROR), n(3, R = !1), n(5, _ = s);
|
|
835
|
+
})) : n(3, R = !0);
|
|
836
|
+
}
|
|
837
|
+
function pe() {
|
|
838
|
+
E === j.VERIFYING && alert(r.waitAlert);
|
|
839
|
+
}
|
|
840
|
+
function P(s = j.UNVERIFIED) {
|
|
841
|
+
n(3, R = !1), n(5, _ = null), n(6, F = null), n(2, E = s);
|
|
842
|
+
}
|
|
843
|
+
function je() {
|
|
844
|
+
R = this.checked, n(3, R);
|
|
845
|
+
}
|
|
846
|
+
function ye(s) {
|
|
847
|
+
Q[s ? "unshift" : "push"](() => {
|
|
848
|
+
O = s, n(4, O);
|
|
849
|
+
});
|
|
850
|
+
}
|
|
851
|
+
return t.$$set = (s) => {
|
|
852
|
+
"challengeurl" in s && n(10, c = s.challengeurl), "challengejson" in s && n(11, a = s.challengejson), "debug" in s && n(12, u = s.debug), "hidefooter" in s && n(0, f = s.hidefooter), "name" in s && n(1, L = s.name), "maxnumber" in s && n(13, g = s.maxnumber), "mockerror" in s && n(14, $ = s.mockerror), "strings" in s && n(15, k = s.strings), "test" in s && n(16, y = s.test);
|
|
853
|
+
}, t.$$.update = () => {
|
|
854
|
+
t.$$.dirty[0] & /*challengejson*/
|
|
855
|
+
2048 && (l = a ? ue(a) : void 0), t.$$.dirty[0] & /*strings*/
|
|
856
|
+
32768 && n(18, i = k ? ue(k) : {}), t.$$.dirty[0] & /*parsedStrings*/
|
|
857
|
+
262144 && n(7, r = {
|
|
858
|
+
error: "Verification failed. Try again later.",
|
|
859
|
+
footer: `Protected by <a href="${be}" target="_blank">ALTCHA</a>`,
|
|
860
|
+
label: "I'm not a robot",
|
|
861
|
+
verified: "Verified",
|
|
862
|
+
verifying: "Verifying...",
|
|
863
|
+
waitAlert: "Verifying... please wait.",
|
|
864
|
+
...i
|
|
865
|
+
}), t.$$.dirty[0] & /*state*/
|
|
866
|
+
4 && H("statechange", { state: E });
|
|
867
|
+
}, [
|
|
868
|
+
f,
|
|
869
|
+
L,
|
|
870
|
+
E,
|
|
871
|
+
R,
|
|
872
|
+
O,
|
|
873
|
+
_,
|
|
874
|
+
F,
|
|
875
|
+
r,
|
|
876
|
+
we,
|
|
877
|
+
pe,
|
|
878
|
+
c,
|
|
879
|
+
a,
|
|
880
|
+
u,
|
|
881
|
+
g,
|
|
882
|
+
$,
|
|
883
|
+
k,
|
|
884
|
+
y,
|
|
885
|
+
P,
|
|
886
|
+
i,
|
|
887
|
+
je,
|
|
888
|
+
ye
|
|
889
|
+
];
|
|
890
|
+
}
|
|
891
|
+
class ft extends Je {
|
|
892
|
+
constructor(e) {
|
|
893
|
+
super(), De(
|
|
894
|
+
this,
|
|
895
|
+
e,
|
|
896
|
+
ut,
|
|
897
|
+
at,
|
|
898
|
+
Le,
|
|
899
|
+
{
|
|
900
|
+
challengeurl: 10,
|
|
901
|
+
challengejson: 11,
|
|
902
|
+
debug: 12,
|
|
903
|
+
hidefooter: 0,
|
|
904
|
+
name: 1,
|
|
905
|
+
maxnumber: 13,
|
|
906
|
+
mockerror: 14,
|
|
907
|
+
strings: 15,
|
|
908
|
+
test: 16,
|
|
909
|
+
reset: 17
|
|
910
|
+
},
|
|
911
|
+
it,
|
|
912
|
+
[-1, -1]
|
|
913
|
+
);
|
|
914
|
+
}
|
|
915
|
+
get challengeurl() {
|
|
916
|
+
return this.$$.ctx[10];
|
|
917
|
+
}
|
|
918
|
+
set challengeurl(e) {
|
|
919
|
+
this.$$set({ challengeurl: e }), N();
|
|
920
|
+
}
|
|
921
|
+
get challengejson() {
|
|
922
|
+
return this.$$.ctx[11];
|
|
923
|
+
}
|
|
924
|
+
set challengejson(e) {
|
|
925
|
+
this.$$set({ challengejson: e }), N();
|
|
926
|
+
}
|
|
927
|
+
get debug() {
|
|
928
|
+
return this.$$.ctx[12];
|
|
929
|
+
}
|
|
930
|
+
set debug(e) {
|
|
931
|
+
this.$$set({ debug: e }), N();
|
|
932
|
+
}
|
|
933
|
+
get hidefooter() {
|
|
934
|
+
return this.$$.ctx[0];
|
|
935
|
+
}
|
|
936
|
+
set hidefooter(e) {
|
|
937
|
+
this.$$set({ hidefooter: e }), N();
|
|
938
|
+
}
|
|
939
|
+
get name() {
|
|
940
|
+
return this.$$.ctx[1];
|
|
941
|
+
}
|
|
942
|
+
set name(e) {
|
|
943
|
+
this.$$set({ name: e }), N();
|
|
944
|
+
}
|
|
945
|
+
get maxnumber() {
|
|
946
|
+
return this.$$.ctx[13];
|
|
947
|
+
}
|
|
948
|
+
set maxnumber(e) {
|
|
949
|
+
this.$$set({ maxnumber: e }), N();
|
|
950
|
+
}
|
|
951
|
+
get mockerror() {
|
|
952
|
+
return this.$$.ctx[14];
|
|
953
|
+
}
|
|
954
|
+
set mockerror(e) {
|
|
955
|
+
this.$$set({ mockerror: e }), N();
|
|
956
|
+
}
|
|
957
|
+
get strings() {
|
|
958
|
+
return this.$$.ctx[15];
|
|
959
|
+
}
|
|
960
|
+
set strings(e) {
|
|
961
|
+
this.$$set({ strings: e }), N();
|
|
962
|
+
}
|
|
963
|
+
get test() {
|
|
964
|
+
return this.$$.ctx[16];
|
|
965
|
+
}
|
|
966
|
+
set test(e) {
|
|
967
|
+
this.$$set({ test: e }), N();
|
|
968
|
+
}
|
|
969
|
+
get reset() {
|
|
970
|
+
return this.$$.ctx[17];
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
customElements.define("altcha-box", ze(ft, { challengeurl: {}, challengejson: {}, debug: { type: "Boolean" }, hidefooter: { type: "Boolean" }, name: {}, maxnumber: {}, mockerror: { type: "Boolean" }, strings: {}, test: { type: "Boolean" } }, [], ["reset"], !1));
|
|
974
|
+
export {
|
|
975
|
+
ft as Altcha
|
|
976
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
(function(E,$){typeof exports=="object"&&typeof module<"u"?$(exports):typeof define=="function"&&define.amd?define(["exports"],$):(E=typeof globalThis<"u"?globalThis:E||self,$(E["<<name>>"]={}))})(this,function(E){"use strict";var ft=Object.defineProperty;var ht=(E,$,F)=>$ in E?ft(E,$,{enumerable:!0,configurable:!0,writable:!0,value:F}):E[$]=F;var R=(E,$,F)=>(ht(E,typeof $!="symbol"?$+"":$,F),F);function $(){}function F(t){return t()}function le(){return Object.create(null)}function U(t){t.forEach(F)}function ie(t){return typeof t=="function"}function ve(t,e){return t!=t?e==e:t!==e||t&&typeof t=="object"||typeof t=="function"}function pe(t){return Object.keys(t).length===0}function d(t,e){t.appendChild(e)}function we(t,e,n){const l=je(t);if(!l.getElementById(e)){const i=_("style");i.id=e,i.textContent=n,ye(l,i)}}function je(t){if(!t)return document;const e=t.getRootNode?t.getRootNode():t.ownerDocument;return e&&e.host?e:t.ownerDocument}function ye(t,e){return d(t.head||t,e),e.sheet}function O(t,e,n){t.insertBefore(e,n||null)}function I(t){t.parentNode&&t.parentNode.removeChild(t)}function _(t){return document.createElement(t)}function S(t){return document.createElementNS("http://www.w3.org/2000/svg",t)}function ke(t){return document.createTextNode(t)}function G(){return ke(" ")}function J(t,e,n,l){return t.addEventListener(e,n,l),()=>t.removeEventListener(e,n,l)}function o(t,e,n){n==null?t.removeAttribute(e):t.getAttribute(e)!==n&&t.setAttribute(e,n)}function Ee(t){return Array.from(t.childNodes)}function se(t,e,n){t.classList.toggle(e,!!n)}function Ce(t,e,{bubbles:n=!1,cancelable:l=!1}={}){return new CustomEvent(t,{detail:e,bubbles:n,cancelable:l})}function xe(t){const e={};return t.childNodes.forEach(n=>{e[n.slot||"default"]=!0}),e}let K;function P(t){K=t}function Q(){if(!K)throw new Error("Function called outside component initialization");return K}function Le(t){Q().$$.on_mount.push(t)}function Re(t){Q().$$.on_destroy.push(t)}function Ie(){const t=Q();return(e,n,{cancelable:l=!1}={})=>{const i=t.$$.callbacks[e];if(i){const r=Ce(e,n,{cancelable:l});return i.slice().forEach(c=>{c.call(t,r)}),!r.defaultPrevented}return!0}}const B=[],q=[];let Y=[];const oe=[],Ne=Promise.resolve();let ee=!1;function Ae(){ee||(ee=!0,Ne.then(N))}function te(t){Y.push(t)}const ne=new Set;let Z=0;function N(){if(Z!==0)return;const t=K;do{try{for(;Z<B.length;){const e=B[Z];Z++,P(e),Me(e.$$)}}catch(e){throw B.length=0,Z=0,e}for(P(null),B.length=0,Z=0;q.length;)q.pop()();for(let e=0;e<Y.length;e+=1){const n=Y[e];ne.has(n)||(ne.add(n),n())}Y.length=0}while(B.length);for(;oe.length;)oe.pop()();ee=!1,ne.clear(),P(t)}function Me(t){if(t.fragment!==null){t.update(),U(t.before_update);const e=t.dirty;t.dirty=[-1],t.fragment&&t.fragment.p(t.ctx,e),t.after_update.forEach(te)}}function Ve(t){const e=[],n=[];Y.forEach(l=>t.indexOf(l)===-1?e.push(l):n.push(l)),n.forEach(l=>l()),Y=e}const Oe=new Set;function Se(t,e){t&&t.i&&(Oe.delete(t),t.i(e))}function Fe(t,e,n){const{fragment:l,after_update:i}=t.$$;l&&l.m(e,n),te(()=>{const r=t.$$.on_mount.map(F).filter(ie);t.$$.on_destroy?t.$$.on_destroy.push(...r):U(r),t.$$.on_mount=[]}),i.forEach(te)}function He(t,e){const n=t.$$;n.fragment!==null&&(Ve(n.after_update),U(n.on_destroy),n.fragment&&n.fragment.d(e),n.on_destroy=n.fragment=null,n.ctx=[])}function Te(t,e){t.$$.dirty[0]===-1&&(B.push(t),Ae(),t.$$.dirty.fill(0)),t.$$.dirty[e/31|0]|=1<<e%31}function Ge(t,e,n,l,i,r,c=null,a=[-1]){const u=K;P(t);const f=t.$$={fragment:null,ctx:[],props:r,update:$,not_equal:i,bound:le(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(e.context||(u?u.$$.context:[])),callbacks:le(),dirty:a,skip_bound:!1,root:e.target||u.$$.root};c&&c(f.root);let A=!1;if(f.ctx=n?n(t,e.props||{},(g,v,...C)=>{const k=C.length?C[0]:v;return f.ctx&&i(f.ctx[g],f.ctx[g]=k)&&(!f.skip_bound&&f.bound[g]&&f.bound[g](k),A&&Te(t,g)),v}):[],f.update(),A=!0,U(f.before_update),f.fragment=l?l(f.ctx):!1,e.target){if(e.hydrate){const g=Ee(e.target);f.fragment&&f.fragment.l(g),g.forEach(I)}else f.fragment&&f.fragment.c();e.intro&&Se(t.$$.fragment),Fe(t,e.target,e.anchor),N()}P(u)}let ce;typeof HTMLElement=="function"&&(ce=class extends HTMLElement{constructor(e,n,l){super();R(this,"$$ctor");R(this,"$$s");R(this,"$$c");R(this,"$$cn",!1);R(this,"$$d",{});R(this,"$$r",!1);R(this,"$$p_d",{});R(this,"$$l",{});R(this,"$$l_u",new Map);this.$$ctor=e,this.$$s=n,l&&this.attachShadow({mode:"open"})}addEventListener(e,n,l){if(this.$$l[e]=this.$$l[e]||[],this.$$l[e].push(n),this.$$c){const i=this.$$c.$on(e,n);this.$$l_u.set(n,i)}super.addEventListener(e,n,l)}removeEventListener(e,n,l){if(super.removeEventListener(e,n,l),this.$$c){const i=this.$$l_u.get(n);i&&(i(),this.$$l_u.delete(n))}}async connectedCallback(){if(this.$$cn=!0,!this.$$c){let e=function(r){return()=>{let c;return{c:function(){c=_("slot"),r!=="default"&&o(c,"name",r)},m:function(f,A){O(f,c,A)},d:function(f){f&&I(c)}}}};if(await Promise.resolve(),!this.$$cn)return;const n={},l=xe(this);for(const r of this.$$s)r in l&&(n[r]=[e(r)]);for(const r of this.attributes){const c=this.$$g_p(r.name);c in this.$$d||(this.$$d[c]=D(c,r.value,this.$$p_d,"toProp"))}this.$$c=new this.$$ctor({target:this.shadowRoot||this,props:{...this.$$d,$$slots:n,$$scope:{ctx:[]}}});const i=()=>{this.$$r=!0;for(const r in this.$$p_d)if(this.$$d[r]=this.$$c.$$.ctx[this.$$c.$$.props[r]],this.$$p_d[r].reflect){const c=D(r,this.$$d[r],this.$$p_d,"toAttribute");c==null?this.removeAttribute(this.$$p_d[r].attribute||r):this.setAttribute(this.$$p_d[r].attribute||r,c)}this.$$r=!1};this.$$c.$$.after_update.push(i),i();for(const r in this.$$l)for(const c of this.$$l[r]){const a=this.$$c.$on(r,c);this.$$l_u.set(c,a)}this.$$l={}}}attributeChangedCallback(e,n,l){var i;this.$$r||(e=this.$$g_p(e),this.$$d[e]=D(e,l,this.$$p_d,"toProp"),(i=this.$$c)==null||i.$set({[e]:this.$$d[e]}))}disconnectedCallback(){this.$$cn=!1,Promise.resolve().then(()=>{this.$$cn||(this.$$c.$destroy(),this.$$c=void 0)})}$$g_p(e){return Object.keys(this.$$p_d).find(n=>this.$$p_d[n].attribute===e||!this.$$p_d[n].attribute&&n.toLowerCase()===e)||e}});function D(t,e,n,l){var r;const i=(r=n[t])==null?void 0:r.type;if(e=i==="Boolean"&&typeof e!="boolean"?e!=null:e,!l||!n[t])return e;if(l==="toAttribute")switch(i){case"Object":case"Array":return e==null?null:JSON.stringify(e);case"Boolean":return e?"":null;case"Number":return e??null;default:return e}else switch(i){case"Object":case"Array":return e&&JSON.parse(e);case"Boolean":return e;case"Number":return e!=null?+e:e;default:return e}}function We(t,e,n,l,i,r){let c=class extends ce{constructor(){super(t,n,i),this.$$p_d=e}static get observedAttributes(){return Object.keys(e).map(a=>(e[a].attribute||a).toLowerCase())}};return Object.keys(e).forEach(a=>{Object.defineProperty(c.prototype,a,{get(){return this.$$c&&a in this.$$c?this.$$c[a]:this.$$d[a]},set(u){var f;u=D(a,u,e),this.$$d[a]=u,(f=this.$$c)==null||f.$set({[a]:u})}})}),l.forEach(a=>{Object.defineProperty(c.prototype,a,{get(){var u;return(u=this.$$c)==null?void 0:u[a]}})}),r&&(c=r(c)),t.element=c,c}class Be{constructor(){R(this,"$$");R(this,"$$set")}$destroy(){He(this,1),this.$destroy=$}$on(e,n){if(!ie(n))return $;const l=this.$$.callbacks[e]||(this.$$.callbacks[e]=[]);return l.push(n),()=>{const i=l.indexOf(n);i!==-1&&l.splice(i,1)}}$set(e){this.$$set&&!pe(e)&&(this.$$.skip_bound=!0,this.$$set(e),this.$$.skip_bound=!1)}}const Ye="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ye);const ae="KGZ1bmN0aW9uKCl7InVzZSBzdHJpY3QiO2NvbnN0IHI9bmV3IFRleHRFbmNvZGVyO2Z1bmN0aW9uIGMoZSl7cmV0dXJuWy4uLm5ldyBVaW50OEFycmF5KGUpXS5tYXAobj0+bi50b1N0cmluZygxNikucGFkU3RhcnQoMiwiMCIpKS5qb2luKCIiKX1hc3luYyBmdW5jdGlvbiBsKGUsbixhKXtyZXR1cm4gYyhhd2FpdCBjcnlwdG8uc3VidGxlLmRpZ2VzdChhLHIuZW5jb2RlKGUrbikpKX1hc3luYyBmdW5jdGlvbiBpKGUsbixhPSJTSEEtMjU2IixvPTFlNyl7Y29uc3Qgcz1EYXRlLm5vdygpO2ZvcihsZXQgdD0wO3Q8PW87dCsrKWlmKGF3YWl0IGwobix0LGEpPT09ZSlyZXR1cm57bnVtYmVyOnQsdG9vazpEYXRlLm5vdygpLXN9O3JldHVybiBudWxsfW9ubWVzc2FnZT1hc3luYyBlPT57Y29uc3R7YWxnOm4sY2hhbGxlbmdlOmEsbWF4Om8sc2FsdDpzfT1lLmRhdGF8fHt9O2lmKGEmJnMpe2NvbnN0IHQ9YXdhaXQgaShhLHMsbixvKTtzZWxmLnBvc3RNZXNzYWdlKHQmJnsuLi50LHdvcmtlcjohMH0pfWVsc2Ugc2VsZi5wb3N0TWVzc2FnZShudWxsKX19KSgpOwo=",ue=typeof window<"u"&&window.Blob&&new Blob([atob(ae)],{type:"text/javascript;charset=utf-8"});function Ze(){let t;try{if(t=ue&&(window.URL||window.webkitURL).createObjectURL(ue),!t)throw"";return new Worker(t)}catch{return new Worker("data:application/javascript;base64,"+ae)}finally{t&&(window.URL||window.webkitURL).revokeObjectURL(t)}}const Ue=1e7,Ke=new TextEncoder;function Pe(t){return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,"0")).join("")}async function Xe(t=1e5,e="SHA-256"){const n=Date.now().toString(16),l=await fe(n,Math.round(Math.random()*t),e);return{algorithm:e,challenge:l,salt:n,signature:""}}async function fe(t,e,n){return Pe(await crypto.subtle.digest(n,Ke.encode(t+e)))}async function De(t,e,n="SHA-256",l=Ue){const i=Date.now();for(let r=0;r<=l;r++)if(await fe(e,r,n)===t)return{number:r,took:Date.now()-i};return null}var y=(t=>(t.ERROR="error",t.VERIFIED="verified",t.VERIFYING="verifying",t.UNVERIFIED="unverfied",t))(y||{});function ze(t){we(t,"svelte-mjm2j6",".altcha.svelte-mjm2j6.svelte-mjm2j6{background:var(--altcha-color-base, #ffffff);border:1px solid var(--altcha-color-border, #a0a0a0);border-radius:3px;color:var(--altcha-color-text, currentColor);display:flex;flex-direction:column;max-width:260px;overflow:hidden;position:relative}.altcha.svelte-mjm2j6.svelte-mjm2j6:focus-within{border-color:var(--altcha-color-border-focus, currentColor)}.altcha-main.svelte-mjm2j6.svelte-mjm2j6{align-items:center;display:flex;gap:0.4rem;padding:0.7rem}.altcha-label.svelte-mjm2j6.svelte-mjm2j6{flex-grow:1}.altcha-label.svelte-mjm2j6 label.svelte-mjm2j6{cursor:pointer}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6{color:currentColor;opacity:0.3}.altcha-logo.svelte-mjm2j6.svelte-mjm2j6:hover{opacity:1}.altcha-error.svelte-mjm2j6.svelte-mjm2j6{color:var(--altcha-color-error-text, #f23939);display:flex;font-size:0.85rem;gap:0.3rem;padding:0 0.7rem 0.7rem}.altcha-footer.svelte-mjm2j6.svelte-mjm2j6{align-items:center;background-color:var(--altcha-color-footer-bg, #f4f4f4);display:flex;font-size:0.75rem;padding:0.2rem 0.7rem;text-align:right}.altcha-footer.svelte-mjm2j6>.svelte-mjm2j6:first-child{flex-grow:1}.altcha-footer.svelte-mjm2j6 a{color:currentColor}.altcha-checkbox.svelte-mjm2j6.svelte-mjm2j6{display:flex;align-items:center;height:24px;width:24px}.altcha-checkbox.svelte-mjm2j6 input.svelte-mjm2j6{width:18px;height:18px;margin:0}.altcha-hidden.svelte-mjm2j6.svelte-mjm2j6{display:none}.altcha-spinner.svelte-mjm2j6.svelte-mjm2j6{animation:svelte-mjm2j6-altcha-spinner 0.75s infinite linear;transform-origin:center}@keyframes svelte-mjm2j6-altcha-spinner{100%{transform:rotate(360deg)}}")}function he(t){let e,n,l;return{c(){e=S("svg"),n=S("path"),l=S("path"),o(n,"d","M12,1A11,11,0,1,0,23,12,11,11,0,0,0,12,1Zm0,19a8,8,0,1,1,8-8A8,8,0,0,1,12,20Z"),o(n,"fill","currentColor"),o(n,"opacity",".25"),o(l,"d","M12,4a8,8,0,0,1,7.89,6.7A1.53,1.53,0,0,0,21.38,12h0a1.5,1.5,0,0,0,1.48-1.75,11,11,0,0,0-21.72,0A1.5,1.5,0,0,0,2.62,12h0a1.53,1.53,0,0,0,1.49-1.3A8,8,0,0,1,12,4Z"),o(l,"fill","currentColor"),o(l,"class","altcha-spinner svelte-mjm2j6"),o(e,"width","24"),o(e,"height","24"),o(e,"viewBox","0 0 24 24"),o(e,"xmlns","http://www.w3.org/2000/svg")},m(i,r){O(i,e,r),d(e,n),d(e,l)},d(i){i&&I(e)}}}function Je(t){let e,n=t[7].label+"",l;return{c(){e=_("label"),o(e,"for",l=t[1]+"_checkbox"),o(e,"class","svelte-mjm2j6")},m(i,r){O(i,e,r),e.innerHTML=n},p(i,r){r[0]&128&&n!==(n=i[7].label+"")&&(e.innerHTML=n),r[0]&2&&l!==(l=i[1]+"_checkbox")&&o(e,"for",l)},d(i){i&&I(e)}}}function Qe(t){let e,n=t[7].verifying+"";return{c(){e=_("span")},m(l,i){O(l,e,i),e.innerHTML=n},p(l,i){i[0]&128&&n!==(n=l[7].verifying+"")&&(e.innerHTML=n)},d(l){l&&I(e)}}}function qe(t){let e,n=t[7].verified+"",l,i;return{c(){e=_("span"),l=G(),i=_("input"),o(i,"type","hidden"),o(i,"name",t[1]),i.value=t[6]},m(r,c){O(r,e,c),e.innerHTML=n,O(r,l,c),O(r,i,c)},p(r,c){c[0]&128&&n!==(n=r[7].verified+"")&&(e.innerHTML=n),c[0]&2&&o(i,"name",r[1]),c[0]&64&&(i.value=r[6])},d(r){r&&(I(e),I(l),I(i))}}}function de(t){let e,n,l,i,r,c=t[7].error+"";return{c(){e=_("div"),n=S("svg"),l=S("path"),i=G(),r=_("div"),o(l,"stroke-linecap","round"),o(l,"stroke-linejoin","round"),o(l,"d","M6 18L18 6M6 6l12 12"),o(n,"width","14"),o(n,"height","14"),o(n,"xmlns","http://www.w3.org/2000/svg"),o(n,"fill","none"),o(n,"viewBox","0 0 24 24"),o(n,"stroke-width","1.5"),o(n,"stroke","currentColor"),o(r,"title",t[5]),o(e,"class","altcha-error svelte-mjm2j6")},m(a,u){O(a,e,u),d(e,n),d(n,l),d(e,i),d(e,r),r.innerHTML=c},p(a,u){u[0]&128&&c!==(c=a[7].error+"")&&(r.innerHTML=c),u[0]&32&&o(r,"title",a[5])},d(a){a&&I(e)}}}function me(t){let e,n,l=t[7].footer+"";return{c(){e=_("div"),n=_("div"),o(n,"class","svelte-mjm2j6"),o(e,"class","altcha-footer svelte-mjm2j6")},m(i,r){O(i,e,r),d(e,n),n.innerHTML=l},p(i,r){r[0]&128&&l!==(l=i[7].footer+"")&&(n.innerHTML=l)},d(i){i&&I(e)}}}function et(t){let e,n,l,i,r,c,a,u,f,A,g,v,C,k,W,X,M,H,V,p=t[2]===y.VERIFYING&&he();function T(h,L){return h[2]===y.VERIFIED?qe:h[2]===y.VERIFYING?Qe:Je}let x=T(t),m=x(t),w=t[5]&&de(t),j=t[7].footer&&t[0]!==!0&&me(t);return{c(){e=_("div"),n=_("div"),p&&p.c(),l=G(),i=_("div"),r=_("input"),a=G(),u=_("div"),m.c(),f=G(),A=_("div"),g=_("a"),v=S("svg"),C=S("path"),k=S("path"),W=S("path"),X=G(),w&&w.c(),M=G(),j&&j.c(),o(r,"type","checkbox"),o(r,"id",c=t[1]+"_checkbox"),r.required=!0,o(r,"class","svelte-mjm2j6"),o(i,"class","altcha-checkbox svelte-mjm2j6"),se(i,"altcha-hidden",t[2]===y.VERIFYING),o(u,"class","altcha-label svelte-mjm2j6"),o(C,"d","M2.33955 16.4279C5.88954 20.6586 12.1971 21.2105 16.4279 17.6604C18.4699 15.947 19.6548 13.5911 19.9352 11.1365L17.9886 10.4279C17.8738 12.5624 16.909 14.6459 15.1423 16.1284C11.7577 18.9684 6.71167 18.5269 3.87164 15.1423C1.03163 11.7577 1.4731 6.71166 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577C16.9767 5.86872 17.5322 7.02798 17.804 8.2324L19.9522 9.01429C19.7622 7.07737 19.0059 5.17558 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956C-0.658625 5.88958 -1.21046 12.1971 2.33955 16.4279Z"),o(C,"fill","currentColor"),o(k,"d","M3.57212 2.33956C1.65755 3.94607 0.496389 6.11731 0.12782 8.40523L2.04639 9.13961C2.26047 7.15832 3.21057 5.25375 4.8577 3.87164C8.24231 1.03162 13.2883 1.4731 16.1284 4.8577L13.8302 6.78606L19.9633 9.13364C19.7929 7.15555 19.0335 5.20847 17.6604 3.57212C14.1104 -0.658624 7.80283 -1.21043 3.57212 2.33956Z"),o(k,"fill","currentColor"),o(W,"d","M7 10H5C5 12.7614 7.23858 15 10 15C12.7614 15 15 12.7614 15 10H13C13 11.6569 11.6569 13 10 13C8.3431 13 7 11.6569 7 10Z"),o(W,"fill","currentColor"),o(v,"width","22"),o(v,"height","22"),o(v,"viewBox","0 0 20 20"),o(v,"fill","none"),o(v,"xmlns","http://www.w3.org/2000/svg"),o(g,"href",ge),o(g,"target","_blank"),o(g,"class","altcha-logo svelte-mjm2j6"),o(n,"class","altcha-main svelte-mjm2j6"),o(e,"class","altcha svelte-mjm2j6"),o(e,"data-state",t[2])},m(h,L){O(h,e,L),d(e,n),p&&p.m(n,null),d(n,l),d(n,i),d(i,r),r.checked=t[3],d(n,a),d(n,u),m.m(u,null),d(n,f),d(n,A),d(A,g),d(g,v),d(v,C),d(v,k),d(v,W),d(e,X),w&&w.m(e,null),d(e,M),j&&j.m(e,null),t[20](e),H||(V=[J(r,"change",t[19]),J(r,"change",t[8]),J(r,"invalid",t[9])],H=!0)},p(h,L){h[2]===y.VERIFYING?p||(p=he(),p.c(),p.m(n,l)):p&&(p.d(1),p=null),L[0]&2&&c!==(c=h[1]+"_checkbox")&&o(r,"id",c),L[0]&8&&(r.checked=h[3]),L[0]&4&&se(i,"altcha-hidden",h[2]===y.VERIFYING),x===(x=T(h))&&m?m.p(h,L):(m.d(1),m=x(h),m&&(m.c(),m.m(u,null))),h[5]?w?w.p(h,L):(w=de(h),w.c(),w.m(e,M)):w&&(w.d(1),w=null),h[7].footer&&h[0]!==!0?j?j.p(h,L):(j=me(h),j.c(),j.m(e,null)):j&&(j.d(1),j=null),L[0]&4&&o(e,"data-state",h[2])},i:$,o:$,d(h){h&&I(e),p&&p.d(),m.d(),w&&w.d(),j&&j.d(),t[20](null),H=!1,U(V)}}}const ge="https://altcha.org/";function be(t){return JSON.parse(t)}function tt(t,e,n){let l,i,r,{challengeurl:c=void 0}=e,{challengejson:a=void 0}=e,{debug:u=!1}=e,{hidefooter:f=!1}=e,{name:A="altcha"}=e,{maxnumber:g=void 0}=e,{mockerror:v=!1}=e,{strings:C=void 0}=e,{test:k=!1}=e;const W=Ie(),X=["SHA-256","SHA-384","SHA-512"];let M=!1,H,V=null,p=null,T=null,x=y.UNVERIFIED;Re(()=>{V&&(V.removeEventListener("submit",w),V.removeEventListener("reset",j),V=null)}),Le(()=>{m("mounted"),k&&m("using test mode"),V=H.closest("form"),V&&(V.addEventListener("submit",w),V.addEventListener("reset",j))});function m(...s){(u||s.some(b=>b instanceof Error))&&console[s[0]instanceof Error?"error":"log"]("ALTCHA",...s)}function w(){z()}function j(){z()}function h(s,b){return btoa(JSON.stringify({algorithm:s.algorithm,challenge:s.challenge,number:b.number,salt:s.salt,signature:s.signature,test:k?!0:void 0,took:b.took}))}function L(s){if(!s.algorithm||!X.includes(s.algorithm))throw new Error(`Unknown algorithm value. Allowed values: ${X.join(", ")}`);if(!s.challenge||s.challenge.length<40)throw new Error("Challenge is too short. Min. 40 chars.");if(!s.salt||s.salt.length<10)throw new Error("Salt is too short. Min. 10 chars.");if(s.signature===void 0)throw new Error("Signature is missing.")}async function nt(){if(v)throw m("mocking error"),new Error("Mocked error.");if(l)return m("using provided json data"),l;if(k)return m("generating test challenge"),Xe();{if(!c)throw new Error("Attribute challengeurl not set.");m("fetching challenge from",c);const s=await fetch(c);if(s.status!==200)throw new Error(`Server responded with ${s.status}.`);return s.json()}}async function rt(s){let b=null;if("Worker"in window){try{b=await lt(s.challenge,s.salt,s.algorithm)}catch(re){m(re)}if((b==null?void 0:b.number)!==void 0)return{data:s,solution:b}}return{data:s,solution:await De(s.challenge,s.salt,s.algorithm,g)}}async function lt(s,b,re){const _e=new Ze;return new Promise(at=>{_e.addEventListener("message",ut=>{at(ut.data)}),_e.postMessage({alg:re,challenge:s,max:g,salt:b})})}function it(){[y.UNVERIFIED,y.ERROR].includes(x)?(z(y.VERIFYING),nt().then(s=>(L(s),m("challenge",s),rt(s))).then(({data:s,solution:b})=>{if(m("solution",b),(b==null?void 0:b.number)!==void 0)m("verified"),n(2,x=y.VERIFIED),n(3,M=!0),n(6,T=h(s,b)),W("verified",{payload:T}),m("payload",T);else throw new Error("Unexpected result returned.")}).catch(s=>{m(s),n(2,x=y.ERROR),n(3,M=!1),n(5,p=s)})):n(3,M=!0)}function st(){x===y.VERIFYING&&alert(r.waitAlert)}function z(s=y.UNVERIFIED){n(3,M=!1),n(5,p=null),n(6,T=null),n(2,x=s)}function ot(){M=this.checked,n(3,M)}function ct(s){q[s?"unshift":"push"](()=>{H=s,n(4,H)})}return t.$$set=s=>{"challengeurl"in s&&n(10,c=s.challengeurl),"challengejson"in s&&n(11,a=s.challengejson),"debug"in s&&n(12,u=s.debug),"hidefooter"in s&&n(0,f=s.hidefooter),"name"in s&&n(1,A=s.name),"maxnumber"in s&&n(13,g=s.maxnumber),"mockerror"in s&&n(14,v=s.mockerror),"strings"in s&&n(15,C=s.strings),"test"in s&&n(16,k=s.test)},t.$$.update=()=>{t.$$.dirty[0]&2048&&(l=a?be(a):void 0),t.$$.dirty[0]&32768&&n(18,i=C?be(C):{}),t.$$.dirty[0]&262144&&n(7,r={error:"Verification failed. Try again later.",footer:`Protected by <a href="${ge}" target="_blank">ALTCHA</a>`,label:"I'm not a robot",verified:"Verified",verifying:"Verifying...",waitAlert:"Verifying... please wait.",...i}),t.$$.dirty[0]&4&&W("statechange",{state:x})},[f,A,x,M,H,p,T,r,it,st,c,a,u,g,v,C,k,z,i,ot,ct]}class $e extends Be{constructor(e){super(),Ge(this,e,tt,et,ve,{challengeurl:10,challengejson:11,debug:12,hidefooter:0,name:1,maxnumber:13,mockerror:14,strings:15,test:16,reset:17},ze,[-1,-1])}get challengeurl(){return this.$$.ctx[10]}set challengeurl(e){this.$$set({challengeurl:e}),N()}get challengejson(){return this.$$.ctx[11]}set challengejson(e){this.$$set({challengejson:e}),N()}get debug(){return this.$$.ctx[12]}set debug(e){this.$$set({debug:e}),N()}get hidefooter(){return this.$$.ctx[0]}set hidefooter(e){this.$$set({hidefooter:e}),N()}get name(){return this.$$.ctx[1]}set name(e){this.$$set({name:e}),N()}get maxnumber(){return this.$$.ctx[13]}set maxnumber(e){this.$$set({maxnumber:e}),N()}get mockerror(){return this.$$.ctx[14]}set mockerror(e){this.$$set({mockerror:e}),N()}get strings(){return this.$$.ctx[15]}set strings(e){this.$$set({strings:e}),N()}get test(){return this.$$.ctx[16]}set test(e){this.$$set({test:e}),N()}get reset(){return this.$$.ctx[17]}}customElements.define("altcha-box",We($e,{challengeurl:{},challengejson:{},debug:{type:"Boolean"},hidefooter:{type:"Boolean"},name:{},maxnumber:{},mockerror:{type:"Boolean"},strings:{},test:{type:"Boolean"}},[],["reset"],!1)),E.Altcha=$e,Object.defineProperty(E,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "altcha",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"homepage": "https://github.com/altcha-org/altchajs",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/altcha-org/altchajs"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"files": [
|
|
12
|
+
"dist"
|
|
13
|
+
],
|
|
14
|
+
"main": "./dist/altcha.umd.cjs",
|
|
15
|
+
"module": "./dist/altcha.js",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"import": "./dist/altcha.js",
|
|
19
|
+
"require": "./dist/altcha.umd.cjs"
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
"scripts": {
|
|
23
|
+
"dev": "vite",
|
|
24
|
+
"build": "rimraf dist && vite build && echo \"declare module 'altcha';\" > dist/altcha.d.ts",
|
|
25
|
+
"preview": "vite preview",
|
|
26
|
+
"check": "svelte-check --tsconfig ./tsconfig.json",
|
|
27
|
+
"test": "vitest"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@sveltejs/vite-plugin-svelte": "^2.4.2",
|
|
31
|
+
"@tsconfig/svelte": "^5.0.0",
|
|
32
|
+
"body-parser": "^1.20.2",
|
|
33
|
+
"cors": "^2.8.5",
|
|
34
|
+
"express": "^4.18.2",
|
|
35
|
+
"svelte": "^4.0.5",
|
|
36
|
+
"svelte-check": "^3.4.6",
|
|
37
|
+
"tslib": "^2.6.0",
|
|
38
|
+
"typescript": "^5.0.2",
|
|
39
|
+
"vite": "^4.4.5",
|
|
40
|
+
"vitest": "^0.34.6"
|
|
41
|
+
}
|
|
42
|
+
}
|