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