@prosopo/procaptcha-bundle 0.3.2 → 0.3.3

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.
@@ -1,940 +0,0 @@
1
- import { r as f, l as ee, d as te, j as u, a as I, b as m, A as V, P as Ne, R as Te, C as Pe, W as Se, c as Oe, e as De, L as He, f as ke, g as Le, h as _e } from "./index-D_tmH38V.js";
2
- import { _ as Re, a as Me, b as Ue, I as je, R as We, g as Ge, c as Fe, d as ze, i as $e, P as $, o as Be, E as Ve, e as k, f as re, h as N, j as q, k as le, s as Ke, w as de, t as ne, l as Ye, r as qe, m as Xe, n as Je, p as Qe, A as Ze, W as et, K as tt, q as nt, C as ot, u as rt } from "./interface-B2_ap_kR.js";
3
- function at() {
4
- if (console && console.warn) {
5
- for (var t, e = arguments.length, n = new Array(e), o = 0; o < e; o++)
6
- n[o] = arguments[o];
7
- typeof n[0] == "string" && (n[0] = "react-i18next:: ".concat(n[0])), (t = console).warn.apply(t, n);
8
- }
9
- }
10
- var ue = {};
11
- function ae() {
12
- for (var t = arguments.length, e = new Array(t), n = 0; n < t; n++)
13
- e[n] = arguments[n];
14
- typeof e[0] == "string" && ue[e[0]] || (typeof e[0] == "string" && (ue[e[0]] = /* @__PURE__ */ new Date()), at.apply(void 0, e));
15
- }
16
- function pe(t, e, n) {
17
- t.loadNamespaces(e, function() {
18
- if (t.isInitialized)
19
- n();
20
- else {
21
- var o = function s() {
22
- setTimeout(function() {
23
- t.off("initialized", s);
24
- }, 0), n();
25
- };
26
- t.on("initialized", o);
27
- }
28
- });
29
- }
30
- function st(t, e) {
31
- var n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {}, o = e.languages[0], s = e.options ? e.options.fallbackLng : !1, r = e.languages[e.languages.length - 1];
32
- if (o.toLowerCase() === "cimode")
33
- return !0;
34
- var a = function(d, p) {
35
- var w = e.services.backendConnector.state["".concat(d, "|").concat(p)];
36
- return w === -1 || w === 2;
37
- };
38
- return n.bindI18n && n.bindI18n.indexOf("languageChanging") > -1 && e.services.backendConnector.backend && e.isLanguageChangingTo && !a(e.isLanguageChangingTo, t) ? !1 : !!(e.hasResourceBundle(o, t) || !e.services.backendConnector.backend || e.options.resources && !e.options.partialBundledLanguages || a(o, t) && (!s || a(r, t)));
39
- }
40
- function ct(t, e) {
41
- var n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
42
- if (!e.languages || !e.languages.length)
43
- return ae("i18n.languages were undefined or empty", e.languages), !0;
44
- var o = e.options.ignoreJSONStructure !== void 0;
45
- return o ? e.hasLoadedNamespace(t, {
46
- precheck: function(r, a) {
47
- if (n.bindI18n && n.bindI18n.indexOf("languageChanging") > -1 && r.services.backendConnector.backend && r.isLanguageChangingTo && !a(r.isLanguageChangingTo, t))
48
- return !1;
49
- }
50
- }) : st(t, e, n);
51
- }
52
- function it(t, e) {
53
- var n = t == null ? null : typeof Symbol < "u" && t[Symbol.iterator] || t["@@iterator"];
54
- if (n != null) {
55
- var o, s, r, a, i = [], d = !0, p = !1;
56
- try {
57
- if (r = (n = n.call(t)).next, e === 0) {
58
- if (Object(n) !== n)
59
- return;
60
- d = !1;
61
- } else
62
- for (; !(d = (o = r.call(n)).done) && (i.push(o.value), i.length !== e); d = !0)
63
- ;
64
- } catch (w) {
65
- p = !0, s = w;
66
- } finally {
67
- try {
68
- if (!d && n.return != null && (a = n.return(), Object(a) !== a))
69
- return;
70
- } finally {
71
- if (p)
72
- throw s;
73
- }
74
- }
75
- return i;
76
- }
77
- }
78
- function lt(t, e) {
79
- return Re(t) || it(t, e) || Me(t, e) || Ue();
80
- }
81
- function fe(t, e) {
82
- var n = Object.keys(t);
83
- if (Object.getOwnPropertySymbols) {
84
- var o = Object.getOwnPropertySymbols(t);
85
- e && (o = o.filter(function(s) {
86
- return Object.getOwnPropertyDescriptor(t, s).enumerable;
87
- })), n.push.apply(n, o);
88
- }
89
- return n;
90
- }
91
- function oe(t) {
92
- for (var e = 1; e < arguments.length; e++) {
93
- var n = arguments[e] != null ? arguments[e] : {};
94
- e % 2 ? fe(Object(n), !0).forEach(function(o) {
95
- Fe(t, o, n[o]);
96
- }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(n)) : fe(Object(n)).forEach(function(o) {
97
- Object.defineProperty(t, o, Object.getOwnPropertyDescriptor(n, o));
98
- });
99
- }
100
- return t;
101
- }
102
- var dt = function(e, n) {
103
- var o = f.useRef();
104
- return f.useEffect(function() {
105
- o.current = n ? o.current : e;
106
- }, [e, n]), o.current;
107
- };
108
- function ut(t) {
109
- var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, n = e.i18n, o = f.useContext(je) || {}, s = o.i18n, r = o.defaultNS, a = n || s || ze();
110
- if (a && !a.reportNamespaces && (a.reportNamespaces = new We()), !a) {
111
- ae("You will need to pass in an i18next instance by using initReactI18next");
112
- var i = function(y) {
113
- return Array.isArray(y) ? y[y.length - 1] : y;
114
- }, d = [i, {}, !1];
115
- return d.t = i, d.i18n = {}, d.ready = !1, d;
116
- }
117
- a.options.react && a.options.react.wait !== void 0 && ae("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
118
- var p = oe(oe(oe({}, Ge()), a.options.react), e), w = p.useSuspense, x = p.keyPrefix, g = t || r || a.options && a.options.defaultNS;
119
- g = typeof g == "string" ? [g] : g || ["translation"], a.reportNamespaces.addUsedNamespaces && a.reportNamespaces.addUsedNamespaces(g);
120
- var T = (a.isInitialized || a.initializedStoreOnce) && g.every(function(v) {
121
- return ct(v, a, p);
122
- });
123
- function L() {
124
- return a.getFixedT(null, p.nsMode === "fallback" ? g : g[0], x);
125
- }
126
- var B = f.useState(L), _ = lt(B, 2), M = _[0], P = _[1], U = g.join(), j = dt(U), S = f.useRef(!0);
127
- f.useEffect(function() {
128
- var v = p.bindI18n, y = p.bindI18nStore;
129
- S.current = !0, !T && !w && pe(a, g, function() {
130
- S.current && P(L);
131
- }), T && j && j !== U && S.current && P(L);
132
- function W() {
133
- S.current && P(L);
134
- }
135
- return v && a && a.on(v, W), y && a && a.store.on(y, W), function() {
136
- S.current = !1, v && a && v.split(" ").forEach(function(l) {
137
- return a.off(l, W);
138
- }), y && a && y.split(" ").forEach(function(l) {
139
- return a.store.off(l, W);
140
- });
141
- };
142
- }, [a, U]);
143
- var E = f.useRef(!0);
144
- f.useEffect(function() {
145
- S.current && !E.current && P(L), E.current = !1;
146
- }, [a, x]);
147
- var b = [M, a, T];
148
- if (b.t = M, b.i18n = a, b.ready = T, T || !T && !w)
149
- return b;
150
- throw new Promise(function(v) {
151
- pe(a, g, function() {
152
- v();
153
- });
154
- });
155
- }
156
- function pt(t) {
157
- return ut("translation", { i18n: $e, ...t });
158
- }
159
- const ft = (t) => {
160
- if (!t.hash)
161
- throw new $("CAPTCHA.MISSING_ITEM_HASH", { context: { item: t } });
162
- return t.hash;
163
- }, ht = ({ challenge: t, solution: e, onClick: n, themeColor: o }) => {
164
- const s = t.captcha.items, r = f.useMemo(() => o === "light" ? ee : te, [o]), a = "ontouchstart" in window;
165
- return u("div", { style: {
166
- paddingRight: 0.5,
167
- paddingBottom: 0.5,
168
- width: "100%",
169
- height: "100%",
170
- display: "flex",
171
- flexDirection: "row",
172
- flexWrap: "wrap"
173
- }, children: s.map((i, d) => {
174
- const p = ft(i);
175
- return u("div", { style: {
176
- paddingTop: "4px",
177
- paddingLeft: "4px",
178
- flexGrow: 1,
179
- flexBasis: "33.3333%",
180
- boxSizing: "border-box"
181
- }, children: I("div", { style: { cursor: "pointer", height: "100%", width: "100%" }, onClick: a ? void 0 : () => n(p), onTouchStart: a ? () => n(p) : void 0, children: [u("div", { style: { border: 1, borderColor: r.palette.grey[300] }, children: u("img", { style: {
182
- width: "100%",
183
- backgroundColor: r.palette.grey[300],
184
- opacity: e.includes(p) && a ? "50%" : "100%",
185
- display: "block",
186
- objectFit: "contain",
187
- aspectRatio: "1/1",
188
- height: "auto"
189
- }, src: i.data, alt: `Captcha image ${d + 1}` }) }), u("div", { style: {
190
- position: "relative",
191
- width: "100%",
192
- height: "100%",
193
- top: "-100%",
194
- visibility: e.includes(p) ? "visible" : "hidden",
195
- transition: "opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
196
- opacity: 1
197
- }, children: u("div", { style: {
198
- position: "absolute",
199
- top: 0,
200
- left: 0,
201
- bottom: 0,
202
- right: 0,
203
- height: "100%",
204
- width: "100%",
205
- display: "flex",
206
- alignItems: "center",
207
- justifyContent: "center",
208
- backgroundColor: "rgba(0,0,0,0.5)"
209
- }, children: u("svg", { style: {
210
- backgroundColor: "transparent",
211
- display: "block",
212
- width: "35%",
213
- height: "35%",
214
- transition: "fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
215
- userSelect: "none",
216
- fill: "currentcolor"
217
- }, focusable: "false", color: "#fff", "aria-hidden": "true", viewBox: "0 0 24 24", "data-testid": "CheckIcon", children: u("path", { d: "M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" }) }) }) })] }) }, d);
218
- }) });
219
- };
220
- function gt(t = {}) {
221
- return Object.keys(t).reduce((e, n) => ({ ...e, [`data-${n}`]: t[n] }), {});
222
- }
223
- function se({ general: t, dev: e }) {
224
- return {
225
- ...gt(t)
226
- };
227
- }
228
- const mt = {
229
- display: "inline-flex",
230
- alignItems: "center",
231
- justifyContent: "center",
232
- position: "relative",
233
- boxSizing: "border-box",
234
- outline: "0px",
235
- border: "0px",
236
- margin: "0px",
237
- cursor: "pointer",
238
- userSelect: "none",
239
- verticalAlign: "middle",
240
- appearance: void 0,
241
- textDecoration: "none",
242
- fontWeight: "500",
243
- fontSize: "0.875rem",
244
- lineHeight: "1.75",
245
- letterSpacing: "0.02857em",
246
- textTransform: "uppercase",
247
- minWidth: "64px",
248
- padding: "6px 16px",
249
- borderRadius: "4px",
250
- transition: "background-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, box-shadow 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, border-color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms, color 250ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
251
- color: "rgb(0, 0, 0)",
252
- backgroundColor: "#ffffff",
253
- boxShadow: "rgba(0, 0, 0, 0.2) 0px 3px 1px -2px, rgba(0, 0, 0, 0.14) 0px 2px 2px 0px, rgba(0, 0, 0, 0.12) 0px 1px 5px 0px"
254
- }, wt = ({ themeColor: t, buttonType: e, text: n, onClick: o }) => {
255
- const s = f.useMemo(() => t === "light" ? ee : te, [t]), [r, a] = f.useState(!1), i = f.useMemo(() => {
256
- const d = {
257
- ...mt,
258
- color: r ? s.palette.primary.contrastText : s.palette.background.contrastText
259
- };
260
- return e === "cancel" ? {
261
- ...d,
262
- backgroundColor: r ? s.palette.grey[600] : "transparent"
263
- } : {
264
- ...d,
265
- backgroundColor: r ? s.palette.primary.main : s.palette.background.default
266
- };
267
- }, [e, r, s]);
268
- return u("button", { ...se({ dev: { cy: `button-${e}` } }), onMouseEnter: () => a(!0), onMouseLeave: () => a(!1), style: i, onClick: (d) => {
269
- d.preventDefault(), o();
270
- }, children: n });
271
- }, he = wt, bt = ({ challenge: t, index: e, solutions: n, onSubmit: o, onCancel: s, onClick: r, onNext: a, themeColor: i }) => {
272
- const { t: d } = pt(), p = t.captchas ? m(t.captchas, e) : null, w = n ? m(n, e) : [], x = f.useMemo(() => i === "light" ? ee : te, [i]);
273
- return u(f.Suspense, { fallback: u("div", { children: "Loading..." }), children: u("div", { style: {
274
- overflowX: "auto",
275
- overflowY: "auto",
276
- width: "100%",
277
- maxWidth: "500px",
278
- maxHeight: "100%",
279
- display: "flex",
280
- flexDirection: "column"
281
- }, children: I("div", { style: {
282
- backgroundColor: x.palette.background.default,
283
- display: "flex",
284
- flexDirection: "column",
285
- minWidth: "300px"
286
- }, children: [I("div", { style: {
287
- display: "flex",
288
- alignItems: "center",
289
- width: "100%",
290
- backgroundColor: x.palette.primary.main,
291
- padding: "24px 16px"
292
- }, children: [I("p", { style: {
293
- color: "#ffffff",
294
- fontWeight: 700,
295
- lineHeight: 1.5
296
- }, children: [d("WIDGET.SELECT_ALL"), ": "] }), u("p", { style: {
297
- color: "#ffffff",
298
- fontWeight: 700,
299
- textTransform: "capitalize",
300
- lineHeight: 1.5
301
- }, children: `${m(t.captchas, e).captcha.target}` })] }), u("div", { ...se({ dev: { cy: "captcha-" + e } }), children: p && u(ht, { challenge: p, solution: w, onClick: r, themeColor: i }) }), u("div", { style: {
302
- display: "flex",
303
- alignItems: "center",
304
- justifyContent: "center",
305
- width: "100%"
306
- }, ...se({ dev: { cy: "dots-captcha" } }) }), u("div", { style: {
307
- padding: "8px 16px",
308
- display: "flex",
309
- width: "100%"
310
- } }), I("div", { style: {
311
- padding: "0 16px 16px",
312
- display: "flex",
313
- alignItems: "center",
314
- justifyContent: "space-between",
315
- lineHeight: 1.75
316
- }, children: [u(he, { themeColor: i, buttonType: "cancel", onClick: s, text: d("WIDGET.CANCEL") }), u(he, { themeColor: i, buttonType: "next", text: e < t.captchas.length - 1 ? d("WIDGET.NEXT") : d("WIDGET.SUBMIT"), onClick: e < t.captchas.length - 1 ? a : o })] })] }) }) });
317
- }, Ct = bt;
318
- function yt(t) {
319
- return new Promise((e) => {
320
- document.readyState === "complete" ? e(t()) : window.addEventListener("load", () => e(t()));
321
- });
322
- }
323
- const Z = window;
324
- Z.injectedWeb3 = Z.injectedWeb3 || {};
325
- Ce();
326
- let ge = null;
327
- function Ce() {
328
- return Object.values(Z.injectedWeb3).filter(({ connect: t, enable: e }) => !!(t || e)).length !== 0;
329
- }
330
- function vt(t) {
331
- return Promise.all(Object.entries(Z.injectedWeb3).map(([e, { connect: n, enable: o, version: s }]) => Promise.resolve().then(() => n ? n(t) : o ? o(t).then((r) => Be({ name: e, version: s || "unknown" }, r)) : Promise.reject(new Error("No connect(..) or enable(...) hook found"))).catch(({ message: r }) => {
332
- console.error(`Error initializing ${e}: ${r}`);
333
- }))).then((e) => e.filter((n) => !!n));
334
- }
335
- function At(t, e = []) {
336
- if (!t)
337
- throw new Error("You must pass a name for your app to the web3Enable function");
338
- const n = e.length ? Promise.all(e.map((o) => o().catch(() => !1))) : Promise.resolve([!0]);
339
- return ge = yt(() => n.then(() => vt(t).then((o) => o.map((s) => (s.accounts.subscribe || (s.accounts.subscribe = (r) => (s.accounts.get().then(r).catch(console.error), () => {
340
- })), s))).catch(() => []).then((o) => {
341
- const s = o.map(({ name: r, version: a }) => `${r}/${a}`);
342
- return Ce(), console.info(`web3Enable: Enabled ${o.length} extension${o.length !== 1 ? "s" : ""}: ${s.join(", ")}`), o;
343
- }))), ge;
344
- }
345
- class xt extends Ve {
346
- async getAccount(e) {
347
- const { dappName: n, userAccountAddress: o } = e;
348
- if (!o)
349
- throw new k("WIDGET.NO_ACCOUNTS_FOUND", { context: { error: "No account address provided" } });
350
- const s = await At(n);
351
- if (s.length === 0)
352
- throw new k("WIDGET.NO_EXTENSION_FOUND");
353
- for (const r of s) {
354
- const i = (await r.accounts.get()).find((d) => d.address === o);
355
- if (i)
356
- return { account: i, extension: r };
357
- }
358
- throw new k("WIDGET.ACCOUNT_NOT_FOUND", {
359
- context: { error: `No account found matching ${o}` }
360
- });
361
- }
362
- }
363
- const Et = (t) => new Promise((e) => setTimeout(e, t));
364
- async function It(t) {
365
- try {
366
- const e = await fetch(t);
367
- if (!e.ok)
368
- throw new re("API.BAD_REQUEST", {
369
- context: { error: `Network response was not ok, status: ${e.status}`, url: t }
370
- });
371
- const n = await e.arrayBuffer();
372
- return new Uint8Array(n);
373
- } catch (e) {
374
- throw new N("DATABASE.IMAGE_GET_FAILED", { context: { error: e } });
375
- }
376
- }
377
- const Nt = "NO_SOLUTION";
378
- function ye(t, e = !1, n = !1, o) {
379
- try {
380
- const s = t.items.map((r, a) => {
381
- if (r.hash)
382
- return r.hash;
383
- throw new $("CAPTCHA.MISSING_ITEM_HASH", {
384
- context: {
385
- computeCaptchaHashName: ye.name,
386
- index: a
387
- }
388
- });
389
- });
390
- return q([
391
- t.target,
392
- ...e ? Tt(t.solution) : [],
393
- n ? t.salt : "",
394
- o ? s.sort() : s
395
- ]);
396
- } catch (s) {
397
- throw new $("DATASET.HASH_ERROR", { context: { error: s } });
398
- }
399
- }
400
- function Tt(t) {
401
- return t !== void 0 ? t.sort() : [Nt];
402
- }
403
- async function Pt(t) {
404
- if (t.type === "text")
405
- return { ...t, hash: le(t.data) };
406
- if (t.type === "image")
407
- return { ...t, hash: le(await It(t.data)) };
408
- throw new $("CAPTCHA.INVALID_ITEM_FORMAT");
409
- }
410
- function St(t) {
411
- return q([t.captchaId, t.captchaContentId, [...t.solution].sort(), t.salt]);
412
- }
413
- class me {
414
- constructor(e) {
415
- this.hash = e, this.parent = null;
416
- }
417
- }
418
- class Ot {
419
- constructor() {
420
- this.leaves = [], this.layers = [];
421
- }
422
- build(e) {
423
- this.layers.length && (this.layers = []);
424
- const n = [];
425
- for (const o of e) {
426
- const s = new me(o);
427
- this.leaves.push(s), n.push(s.hash);
428
- }
429
- this.layers.push(n), this.root = this.buildMerkleTree(this.leaves)[0];
430
- }
431
- buildMerkleTree(e) {
432
- const n = e.length;
433
- if (n === 1)
434
- return e;
435
- const o = [];
436
- let s = 0;
437
- const r = [];
438
- for (; s < n; ) {
439
- const a = e[s];
440
- if (a === void 0)
441
- throw new k("DEVELOPER.GENERAL", { context: { error: "leftChild undefined" } });
442
- const i = s + 1 < n ? m(e, s + 1) : a, d = this.createParent(a, i);
443
- r.push(d.hash), o.push(d), s += 2;
444
- }
445
- return this.layers.push(r), this.buildMerkleTree(o);
446
- }
447
- createParent(e, n) {
448
- const o = new me(q([e.hash, n.hash]));
449
- return e.parent = o.hash, n.parent = o.hash, o;
450
- }
451
- proof(e) {
452
- const n = [];
453
- let o = 0;
454
- for (; o < this.layers.length - 1; ) {
455
- const r = this.layers[o];
456
- if (r === void 0)
457
- throw new k("DATASET.MERKLE_ERROR", {
458
- context: { error: "layer undefined", failedFuncName: this.proof.name, layerNum: o }
459
- });
460
- const a = r.indexOf(e);
461
- let i = a % 2 && a > 0 ? a - 1 : a + 1;
462
- i > r.length - 1 && (i = a);
463
- const d = [e], p = m(r, i);
464
- i > a ? d.push(p) : d.unshift(p), n.push([m(d, 0), m(d, 1)]), o += 1, e = q(d);
465
- }
466
- const s = m(this.layers, this.layers.length - 1);
467
- return [...n, [m(s, 0)]];
468
- }
469
- }
470
- function Dt(t, e) {
471
- try {
472
- if (m(e, 0).indexOf(t) === -1)
473
- return !1;
474
- for (const [n, o] of e.entries()) {
475
- if (t = q(o), m(e, n + 1).indexOf(t) === -1)
476
- return !1;
477
- const s = m(e, e.length - 1);
478
- if (t === m(s, 0))
479
- return !0;
480
- }
481
- return !1;
482
- } catch {
483
- return !1;
484
- }
485
- }
486
- class Ht {
487
- constructor(e, n, o, s, r, a) {
488
- this.userAccount = e, this.contract = n, this.provider = o, this.providerApi = s, this.web2 = r, this.dappAccount = a;
489
- }
490
- async getCaptchaChallenge() {
491
- try {
492
- const e = await this.providerApi.getCaptchaChallenge(this.userAccount, this.provider);
493
- return this.verifyCaptchaChallengeContent(this.provider, e), e.captchas.forEach((n) => {
494
- n.captcha.items.forEach((o) => {
495
- o.data && (o.data = o.data.replace(/^http(s)*:\/\//, "//"));
496
- });
497
- }), e;
498
- } catch (e) {
499
- throw new N("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", { context: { error: e } });
500
- }
501
- }
502
- verifyCaptchaChallengeContent(e, n) {
503
- const o = m(n.captchas, 0), s = o.proof.length;
504
- e.provider;
505
- const r = m(o.proof, s - 1);
506
- if (e.provider.datasetIdContent.toString() !== m(r, 0))
507
- throw new N("CAPTCHA.INVALID_DATASET_CONTENT_ID");
508
- for (const a of n.captchas) {
509
- if (!kt(a))
510
- throw new N("CAPTCHA.INVALID_CAPTCHA_CHALLENGE");
511
- if (!Dt(a.captcha.captchaContentId, a.proof))
512
- throw new N("CAPTCHA.INVALID_CAPTCHA_CHALLENGE");
513
- }
514
- }
515
- async submitCaptchaSolution(e, n, o, s, r) {
516
- const a = new Ot(), i = s.map((g) => St(g));
517
- a.build(i);
518
- const d = a.root.hash, p = void 0;
519
- let w;
520
- if (this.web2) {
521
- if (!e || !e.signRaw)
522
- throw new N("GENERAL.CANT_FIND_KEYRINGPAIR", {
523
- context: { error: "Signer is not defined, cannot sign message to prove account ownership" }
524
- });
525
- w = (await e.signRaw({
526
- address: this.userAccount,
527
- data: Ke(n),
528
- type: "bytes"
529
- })).signature;
530
- }
531
- let x;
532
- try {
533
- x = await this.providerApi.submitCaptchaSolution(s, n, this.contract.pair.address, r, w);
534
- } catch (g) {
535
- throw new $("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", { context: { error: g } });
536
- }
537
- return [x, d, p];
538
- }
539
- }
540
- async function kt(t) {
541
- const e = t.captcha, n = t.proof;
542
- if (!(await Promise.all(e.items.map(async (s) => (await Pt(s)).hash === s.hash))).every((s) => s === !0))
543
- return !1;
544
- const o = ye(e, !1, !1, !1);
545
- return o !== e.captchaContentId ? !1 : m(n, 0).indexOf(o) !== -1;
546
- }
547
- const Lt = Ht, ve = "@prosopo/current_account", Ae = "@prosopo/provider";
548
- function _t(t) {
549
- localStorage.setItem(ve, t);
550
- }
551
- function Rt() {
552
- return localStorage.getItem(ve);
553
- }
554
- function Mt(t) {
555
- localStorage.setItem(Ae, t);
556
- }
557
- function Ut() {
558
- return localStorage.getItem(Ae);
559
- }
560
- const K = {
561
- setAccount: _t,
562
- getAccount: Rt,
563
- setProviderUrl: Mt,
564
- getProviderUrl: Ut
565
- }, jt = () => ({
566
- showModal: !1,
567
- loading: !1,
568
- index: 0,
569
- challenge: void 0,
570
- solutions: void 0,
571
- isHuman: !1,
572
- captchaApi: void 0,
573
- account: void 0
574
- }), Wt = (t, e) => (o) => {
575
- Object.assign(t, o), e(o);
576
- }, we = (t) => {
577
- const e = t.networks[t.defaultNetwork];
578
- if (!e)
579
- throw new N("DEVELOPER.NETWORK_NOT_FOUND", {
580
- context: { error: `No network found for environment ${t.defaultEnvironment}` }
581
- });
582
- return e;
583
- };
584
- function Gt(t, e, n, o) {
585
- const r = Object.assign({
586
- onError: (l) => {
587
- alert(l.message);
588
- },
589
- onHuman: (l) => {
590
- i({ sendData: !e.sendData });
591
- },
592
- onExtensionNotFound: () => {
593
- alert("No extension found");
594
- },
595
- onFailed: () => {
596
- alert("Captcha challenge failed. Please try again"), i({ sendData: !e.sendData });
597
- },
598
- onExpired: () => {
599
- alert("Completed challenge has expired, please try again");
600
- },
601
- onChallengeExpired: () => {
602
- alert("Uncompleted challenge has expired, please try again");
603
- },
604
- onOpen: () => {
605
- },
606
- onClose: () => {
607
- }
608
- }, o), a = (l) => {
609
- const c = l instanceof Error ? l : new Error(String(l));
610
- r.onError(c);
611
- }, i = Wt(e, n), d = () => {
612
- const l = {
613
- userAccountAddress: "",
614
- ...t
615
- };
616
- return e.account && (l.userAccountAddress = e.account.account.address), Ne.parse(l);
617
- }, p = async (l) => {
618
- try {
619
- await l();
620
- } catch (c) {
621
- console.error(c), a(c), i({ isHuman: !1, showModal: !1, loading: !1 });
622
- }
623
- }, w = async () => {
624
- r.onOpen(), await p(async () => {
625
- if (e.loading || e.isHuman)
626
- return;
627
- U(), i({ loading: !0 });
628
- const l = d();
629
- i({ dappAccount: l.account.address }), await Et(100);
630
- const c = await S(), h = await y();
631
- let C = !1;
632
- try {
633
- C = (await h.query.dappOperatorIsHumanUser(c.account.address, l.solutionThreshold)).value.unwrap().unwrap();
634
- } catch (H) {
635
- }
636
- if (C) {
637
- i({ isHuman: !0, loading: !1 }), r.onHuman({
638
- user: c.account.address,
639
- dapp: b()
640
- }), P();
641
- return;
642
- }
643
- const A = K.getProviderUrl();
644
- let O;
645
- if (A) {
646
- O = await _(A);
647
- try {
648
- const H = await O.verifyDappUser(b(), c.account.address, void 0, t.challengeValidLength);
649
- if (H.solutionApproved) {
650
- i({ isHuman: !0, loading: !1 }), r.onHuman({
651
- [V.providerUrl]: A,
652
- [V.user]: c.account.address,
653
- [V.dapp]: b(),
654
- [V.commitmentId]: H.commitmentId,
655
- [V.blockNumber]: H.blockNumber
656
- }), P();
657
- return;
658
- }
659
- } catch {
660
- console.error("Error contacting provider from storage", A);
661
- }
662
- }
663
- const R = {
664
- address: c.account.address,
665
- data: Ye("message"),
666
- type: "bytes"
667
- }, z = await c.extension.signer.signRaw(R), D = await de(h.query.getRandomActiveProvider, h.query)(c.account.address, b()), X = parseInt(D.blockNumber.toString()), G = ne(D.provider.url.toString());
668
- O = await _(G);
669
- const J = await B(h, D, O), F = await J.getCaptchaChallenge();
670
- if (F.captchas.length <= 0)
671
- throw new re("DEVELOPER.PROVIDER_NO_CAPTCHA");
672
- const ie = F.captchas.map((H) => H.captcha.timeLimitMs || 30 * 1e3).reduce((H, Ie) => H + Ie), Ee = setTimeout(() => {
673
- "" + ie, r.onChallengeExpired(), i({ isHuman: !1, showModal: !1, loading: !1 });
674
- }, ie);
675
- i({
676
- index: 0,
677
- solutions: F.captchas.map(() => []),
678
- challenge: F,
679
- showModal: !0,
680
- timeout: Ee,
681
- blockNumber: X
682
- });
683
- });
684
- }, x = async () => {
685
- await p(async () => {
686
- if (M(), !e.challenge)
687
- throw new k("CAPTCHA.NO_CAPTCHA", {
688
- context: { error: "Cannot submit, no Captcha found in state" }
689
- });
690
- i({ showModal: !1 });
691
- const l = e.challenge, c = qe(), h = e.challenge.captchas.map((G, J) => {
692
- const F = m(e.solutions, J);
693
- return {
694
- captchaId: G.captcha.captchaId,
695
- captchaContentId: G.captcha.captchaContentId,
696
- salt: c,
697
- solution: F
698
- };
699
- }), C = E(), A = v(), O = C.extension.signer, R = m(l.captchas, 0);
700
- if (!R.captcha.datasetId)
701
- throw new $("CAPTCHA.INVALID_CAPTCHA_ID", {
702
- context: { error: "No datasetId set for challenge" }
703
- });
704
- const z = j(), D = await z.submitCaptchaSolution(O, l.requestHash, R.captcha.datasetId, h, c), X = D[0].solutionApproved;
705
- if (X || r.onFailed(), i({
706
- submission: D,
707
- isHuman: X,
708
- loading: !1
709
- }), e.isHuman) {
710
- const G = ne(z.provider.provider.url.toString());
711
- K.setProviderUrl(G), r.onHuman({
712
- providerUrl: G,
713
- user: C.account.address,
714
- dapp: b(),
715
- commitmentId: D[1],
716
- blockNumber: A
717
- }), P();
718
- }
719
- });
720
- }, g = async () => {
721
- M(), U(), r.onClose();
722
- }, T = (l) => {
723
- if (!e.challenge)
724
- throw new k("CAPTCHA.NO_CAPTCHA", {
725
- context: { error: "Cannot select, no Captcha found in state" }
726
- });
727
- if (e.index >= e.challenge.captchas.length || e.index < 0)
728
- throw new k("CAPTCHA.NO_CAPTCHA", {
729
- context: { error: "Cannot select, index is out of range for this Captcha" }
730
- });
731
- const c = e.index, h = e.solutions, C = m(h, c);
732
- C.includes(l) ? C.splice(C.indexOf(l), 1) : C.push(l), i({ solutions: h });
733
- }, L = () => {
734
- if (!e.challenge)
735
- throw new k("CAPTCHA.NO_CAPTCHA", {
736
- context: { error: "Cannot select, no Captcha found in state" }
737
- });
738
- if (e.index + 1 >= e.challenge.captchas.length)
739
- throw new k("CAPTCHA.NO_CAPTCHA", {
740
- context: { error: "Cannot select, index is out of range for this Captcha" }
741
- });
742
- i({ index: e.index + 1 });
743
- }, B = async (l, c, h) => {
744
- const C = d(), A = new Lt(E().account.address, l, c, h, C.web2, b());
745
- return i({ captchaApi: A }), j();
746
- }, _ = async (l) => {
747
- const c = d(), h = we(c);
748
- if (!c.account.address)
749
- throw new N("GENERAL.SITE_KEY_MISSING");
750
- return new Xe(h, l, c.account.address);
751
- }, M = () => {
752
- window.clearTimeout(e.timeout), i({ timeout: void 0 });
753
- }, P = () => {
754
- const l = t.challengeValidLength || 120 * 1e3, c = setTimeout(() => {
755
- "" + l, i({ isHuman: !1 }), r.onExpired();
756
- }, l);
757
- i({ successfullChallengeTimeout: c });
758
- }, U = () => {
759
- M(), i(jt());
760
- }, j = () => {
761
- if (!e.captchaApi)
762
- throw new re("API.UNKNOWN", { context: { error: "Captcha api not set", state: e } });
763
- return e.captchaApi;
764
- }, S = async () => {
765
- const l = d();
766
- if (!l.web2 && !l.userAccountAddress)
767
- throw new N("GENERAL.ACCOUNT_NOT_FOUND", {
768
- context: { error: "Account address has not been set for web3 mode" }
769
- });
770
- const h = await (l.web2 ? new Je() : new xt()).getAccount(l);
771
- return K.setAccount(h.account.address), i({ account: h }), E();
772
- }, E = () => {
773
- if (!e.account)
774
- throw new N("GENERAL.ACCOUNT_NOT_FOUND", { context: { error: "Account not loaded" } });
775
- return e.account;
776
- }, b = () => {
777
- if (!e.dappAccount)
778
- throw new N("GENERAL.SITE_KEY_MISSING");
779
- return e.dappAccount;
780
- }, v = () => {
781
- if (!e.blockNumber)
782
- throw new Qe("CAPTCHA.INVALID_BLOCK_NO", { context: { error: "Block number not found" } });
783
- return e.blockNumber;
784
- }, y = async () => {
785
- const l = d(), c = we(l), h = await Ze.create({ provider: new et(c.endpoint), initWasm: !1 }), C = "sr25519", A = new tt({ type: C, ss58Format: h.registry.chainSS58 });
786
- return new nt(h, JSON.parse(ot), c.contract.address, "prosopo", 0, A.addFromAddress(E().account.address));
787
- };
788
- return {
789
- start: w,
790
- cancel: g,
791
- submit: x,
792
- select: T,
793
- nextRound: L,
794
- exportData: async (l) => {
795
- var O;
796
- const c = K.getProviderUrl();
797
- let h;
798
- if (c)
799
- h = await _(c);
800
- else {
801
- const R = await y(), z = await de(R.query.getRandomActiveProvider, R.query)(E().account.address, b()), D = ne(z.provider.url.toString());
802
- h = await _(D);
803
- }
804
- if (!(K.getProviderUrl() || ((O = e.captchaApi) == null ? void 0 : O.provider.provider.url.toString())))
805
- return;
806
- let A = "";
807
- try {
808
- A = E().account.address;
809
- } catch (R) {
810
- console.error(R);
811
- }
812
- await h.submitUserEvents(l, A);
813
- }
814
- };
815
- }
816
- const Ft = 1e4, ce = (t, e) => {
817
- e((n) => {
818
- let o = [...n, t];
819
- return o.length > Ft && (o = o.slice(1)), o;
820
- });
821
- }, zt = (t, e) => {
822
- const n = {
823
- x: t.x,
824
- y: t.y,
825
- timestamp: t.timeStamp
826
- };
827
- ce(n, e);
828
- }, be = (t, e) => {
829
- const n = {
830
- key: t.key,
831
- timestamp: t.timeStamp,
832
- isShiftKey: t.shiftKey,
833
- isCtrlKey: t.ctrlKey
834
- };
835
- ce(n, e);
836
- }, Q = (t, e) => {
837
- for (const n of Array.from(t.touches))
838
- ce({ x: n.clientX, y: n.clientY, timestamp: t.timeStamp }, e);
839
- }, $t = (t, e, n, o) => {
840
- const s = xe(o);
841
- s && (s.addEventListener("mousemove", (r) => zt(r, t)), s.addEventListener("keydown", (r) => be(r, n)), s.addEventListener("keyup", (r) => be(r, n)), s.addEventListener("touchstart", (r) => Q(r, e)), s.addEventListener("touchend", (r) => Q(r, e)), s.addEventListener("touchcancel", (r) => Q(r, e)), s.addEventListener("touchmove", (r) => Q(r, e)));
842
- }, xe = (t) => t.tagName === "FORM" ? t : t.parentElement ? xe(t.parentElement) : null, Bt = ({ onProcessData: t, sendData: e, account: n }) => {
843
- const [o, s] = f.useState([]), [r, a] = f.useState([]), [i, d] = f.useState([]), p = f.useRef(null);
844
- return f.useEffect(() => {
845
- p && p.current && $t(s, a, d, p.current);
846
- }, []), f.useEffect(() => {
847
- n && t({
848
- mouseEvents: o,
849
- touchEvents: r,
850
- keyboardEvents: i
851
- });
852
- }, [e, n]), u("div", { ref: p });
853
- }, Vt = Bt, Kt = Te.memo((t, e) => {
854
- const { show: n, children: o } = t, r = {
855
- position: "fixed",
856
- zIndex: 2147483646,
857
- inset: 0,
858
- display: n ? "block" : "none"
859
- }, a = {
860
- position: "fixed",
861
- display: "flex",
862
- alignItems: "center",
863
- justifyContent: "center",
864
- right: 0,
865
- bottom: 0,
866
- top: 0,
867
- left: 0,
868
- backgroundColor: "rgba(0, 0, 0, 0.5)",
869
- zIndex: -1
870
- }, i = {
871
- position: "absolute",
872
- top: "50%",
873
- left: "50%",
874
- transform: "translate(-50%, -50%)",
875
- width: "400px",
876
- backgroundColor: "rgb(255, 255, 255)",
877
- border: "none",
878
- boxShadow: "rgba(0, 0, 0, 0.2) 0px 11px 15px -7px, rgba(0, 0, 0, 0.14) 0px 24px 38px 3px, rgba(0, 0, 0, 0.12) 0px 9px 46px 8px,"
879
- };
880
- return I("div", { className: "modalOuter", style: r, children: [u("div", { className: "modalBackground", style: a }), u("div", { className: "modalInner", style: i, children: o })] });
881
- }), Yt = Kt, Y = (t) => {
882
- const e = f.useRef(t), n = (s) => {
883
- e.current = s;
884
- };
885
- return [e.current, n];
886
- }, qt = () => {
887
- const [t, e] = f.useState(!1), [n, o] = f.useState(0), [s, r] = f.useState([]), [a, i] = Y(void 0), [d, p] = f.useState(!1), [w, x] = f.useState(void 0), [g, T] = f.useState(!1), [L, B] = f.useState(void 0), [_, M] = f.useState(void 0), [P, U] = Y(void 0), [j, S] = Y(void 0), [E, b] = Y(void 0), [v, y] = Y(void 0), [W, l] = f.useState(!1);
888
- return [
889
- {
890
- isHuman: t,
891
- index: n,
892
- solutions: s,
893
- captchaApi: a,
894
- showModal: d,
895
- challenge: w,
896
- loading: g,
897
- account: L,
898
- dappAccount: _,
899
- submission: P,
900
- timeout: j,
901
- blockNumber: E,
902
- successfullChallengeTimeout: v,
903
- sendData: W
904
- },
905
- (c) => {
906
- c.account !== void 0 && B(c.account), c.isHuman !== void 0 && e(c.isHuman), c.index !== void 0 && o(c.index), c.solutions !== void 0 && r(c.solutions.slice()), c.captchaApi !== void 0 && i(c.captchaApi), c.showModal !== void 0 && p(c.showModal), c.challenge !== void 0 && x(c.challenge), c.loading !== void 0 && T(c.loading), c.showModal !== void 0 && p(c.showModal), c.dappAccount !== void 0 && M(c.dappAccount), c.submission !== void 0 && U(c.submission), c.timeout !== void 0 && S(c.timeout), c.successfullChallengeTimeout !== void 0 && y(c.timeout), c.blockNumber !== void 0 && b(c.blockNumber), c.sendData !== void 0 && l(c.sendData);
907
- }
908
- ];
909
- }, Qt = (t) => {
910
- const e = t.config, n = t.callbacks || {}, [o, s] = qt(), r = Gt(e, o, s, n), a = t.config.theme === "light" ? "light" : "dark", i = f.useMemo(() => t.config.theme === "light" ? ee : te, [t.config.theme]);
911
- return u("div", { children: I("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: [u(Yt, { show: o.showModal, children: o.challenge ? u(Ct, { challenge: o.challenge, index: o.index, solutions: o.solutions, onSubmit: r.submit, onCancel: r.cancel, onClick: r.select, onNext: r.nextRound, themeColor: e.theme ?? "light" }) : u("div", { children: "No challenge set." }) }), I(Pe, { children: [u(Se, { children: I("div", { style: Oe, "data-cy": "button-human", children: [" ", I("div", { style: {
912
- padding: "2px",
913
- border: "1px solid",
914
- backgroundColor: i.palette.background.default,
915
- borderColor: i.palette.grey[300],
916
- borderRadius: "8px",
917
- display: "flex",
918
- alignItems: "center",
919
- flexWrap: "wrap",
920
- justifyContent: "space-between",
921
- minHeight: `${De}px`,
922
- overflow: "hidden"
923
- }, children: [u("div", { style: { display: "inline-flex", flexDirection: "column" }, children: u("div", { style: {
924
- alignItems: "center",
925
- flex: 1
926
- }, children: I("div", { style: {
927
- display: "flex",
928
- alignItems: "center",
929
- justifyContent: "center",
930
- flexDirection: "column",
931
- verticalAlign: "middle"
932
- }, children: [u("div", { style: {
933
- display: o.loading ? "none" : "flex"
934
- }, children: u(rt, { themeColor: a, onChange: r.start, checked: o.isHuman, labelText: "I am human" }) }), u("div", { style: {
935
- display: o.loading ? "flex" : "none"
936
- }, children: u("div", { style: { display: "inline-flex" }, children: u(He, { themeColor: a }) }) })] }) }) }), u("div", { style: { display: "inline-flex", flexDirection: "column" }, children: u("a", { href: ke, target: "_blank", "aria-label": Le, children: u("div", { style: { flex: 1 }, children: u(_e, { themeColor: a }) }) }) })] })] }) }), e.devOnlyWatchEvents && u(Vt, { onProcessData: r.exportData, sendData: o.sendData, account: o.account })] })] }) });
937
- };
938
- export {
939
- Qt as default
940
- };