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