@prosopo/procaptcha-bundle 0.3.1 → 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.
- 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 +14 -7
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +1 -1
- package/dist/bundle/Captcha-O2tGirAv.js +106 -0
- package/dist/bundle/ProcaptchaWidget-f7S-UgEx.js +891 -0
- package/dist/bundle/{index-DUjgpJkc.js → index-BoRQHVyP.js} +4649 -3729
- package/dist/bundle/index.d.ts.map +1 -1
- package/dist/bundle/procaptcha.bundle.js +1 -1
- package/dist/bundle/{interface-CyIrD5th.js → utils-CIX8CwBe.js} +5092 -5181
- package/dist/cjs/account/dist/extension/ExtensionWeb3.cjs +28 -0
- package/dist/cjs/account/dist/index.cjs +2 -0
- package/dist/cjs/index.cjs +15 -6
- package/dist/cjs/procaptcha-frictionless/dist/ProcaptchaFrictionless.cjs +27 -0
- package/dist/cjs/procaptcha-frictionless/dist/index.cjs +4 -0
- package/dist/cjs/procaptcha-pow/dist/Services/Manager.cjs +91 -27
- package/dist/cjs/procaptcha-pow/dist/components/Captcha.cjs +22 -67
- package/dist/cjs/procaptcha-pow/dist/components/ProcaptchaPoW.cjs +1 -1
- package/dist/cjs/web-components/dist/CaptchaPlaceholder.cjs +13 -55
- package/dist/cjs/web-components/dist/Checkbox.cjs +21 -11
- package/dist/cjs/web-components/dist/Containers.cjs +42 -0
- package/dist/cjs/web-components/dist/LoadingSpinner.cjs +4 -0
- package/dist/cjs/web-components/dist/Logo.cjs +16 -0
- package/dist/cjs/web-components/dist/LogoWithText.cjs +10 -0
- package/dist/cjs/web-components/dist/LogoWithoutText.cjs +10 -0
- package/dist/cjs/web-components/dist/WidgetConstants.cjs +12 -0
- package/dist/cjs/web-components/dist/index.cjs +11 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +14 -7
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
- package/stats.html +1 -1
- package/typedoc.config.js +13 -0
- package/vite.cjs.config.ts +13 -0
- package/vite.config.ts +14 -1
- package/dist/bundle/Captcha-wrP5sDne.js +0 -169
- package/dist/bundle/ProcaptchaWidget-CggtG-1W.js +0 -1037
|
@@ -0,0 +1,891 @@
|
|
|
1
|
+
import { r as f, l as J, d as Q, j as d, a as v, b as g, A as $, h as ce, P as Ee, R as Ie, C as Ne, W as Te, c as Se, e as Pe, L as Oe, f as ke, g as Le, i as He } from "./index-BoRQHVyP.js";
|
|
2
|
+
import { _ as De, a as _e, b as Re, I as Me, R as Ue, g as We, c as je, d as Ge, i as Fe, P as z, o as ze, E as $e, e as S, f as re, h as A, j as K, k as ie, s as Be, l as Ke, w as le, t as te, m as Ve, n as Ye, p as qe, r as Xe, q as Je, u as Qe, v as Ze, A as et, W as tt, K as nt, x as rt, C as ot, y as at, z as st } from "./utils-CIX8CwBe.js";
|
|
3
|
+
function ct() {
|
|
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 de = {};
|
|
11
|
+
function oe() {
|
|
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" && de[e[0]] || (typeof e[0] == "string" && (de[e[0]] = /* @__PURE__ */ new Date()), ct.apply(void 0, e));
|
|
15
|
+
}
|
|
16
|
+
function ue(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 it(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(i, p) {
|
|
35
|
+
var w = e.services.backendConnector.state["".concat(i, "|").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 lt(t, e) {
|
|
41
|
+
var n = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : {};
|
|
42
|
+
if (!e.languages || !e.languages.length)
|
|
43
|
+
return oe("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
|
+
}) : it(t, e, n);
|
|
51
|
+
}
|
|
52
|
+
function dt(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 = [], i = !0, p = !1;
|
|
56
|
+
try {
|
|
57
|
+
if (s = (n = n.call(t)).next, e === 0) {
|
|
58
|
+
if (Object(n) !== n)
|
|
59
|
+
return;
|
|
60
|
+
i = !1;
|
|
61
|
+
} else
|
|
62
|
+
for (; !(i = (r = s.call(n)).done) && (c.push(r.value), c.length !== e); i = !0)
|
|
63
|
+
;
|
|
64
|
+
} catch (w) {
|
|
65
|
+
p = !0, a = w;
|
|
66
|
+
} finally {
|
|
67
|
+
try {
|
|
68
|
+
if (!i && 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 ut(t, e) {
|
|
79
|
+
return De(t) || dt(t, e) || _e(t, e) || Re();
|
|
80
|
+
}
|
|
81
|
+
function pe(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 ne(t) {
|
|
92
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
93
|
+
var n = arguments[e] != null ? arguments[e] : {};
|
|
94
|
+
e % 2 ? pe(Object(n), !0).forEach(function(r) {
|
|
95
|
+
je(t, r, n[r]);
|
|
96
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(t, Object.getOwnPropertyDescriptors(n)) : pe(Object(n)).forEach(function(r) {
|
|
97
|
+
Object.defineProperty(t, r, Object.getOwnPropertyDescriptor(n, r));
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
return t;
|
|
101
|
+
}
|
|
102
|
+
var pt = 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 ht(t) {
|
|
109
|
+
var e = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}, n = e.i18n, r = f.useContext(Me) || {}, a = r.i18n, s = r.defaultNS, o = n || a || Ge();
|
|
110
|
+
if (o && !o.reportNamespaces && (o.reportNamespaces = new Ue()), !o) {
|
|
111
|
+
oe("You will need to pass in an i18next instance by using initReactI18next");
|
|
112
|
+
var c = function(N) {
|
|
113
|
+
return Array.isArray(N) ? N[N.length - 1] : N;
|
|
114
|
+
}, i = [c, {}, !1];
|
|
115
|
+
return i.t = c, i.i18n = {}, i.ready = !1, i;
|
|
116
|
+
}
|
|
117
|
+
o.options.react && o.options.react.wait !== void 0 && oe("It seems you are still using the old wait option, you may migrate to the new useSuspense behaviour.");
|
|
118
|
+
var p = ne(ne(ne({}, We()), o.options.react), e), w = p.useSuspense, E = 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 k = (o.isInitialized || o.initializedStoreOnce) && m.every(function(x) {
|
|
121
|
+
return lt(x, o, p);
|
|
122
|
+
});
|
|
123
|
+
function H() {
|
|
124
|
+
return o.getFixedT(null, p.nsMode === "fallback" ? m : m[0], E);
|
|
125
|
+
}
|
|
126
|
+
var M = f.useState(H), U = ut(M, 2), W = U[0], D = U[1], j = m.join(), V = pt(j), b = f.useRef(!0);
|
|
127
|
+
f.useEffect(function() {
|
|
128
|
+
var x = p.bindI18n, N = p.bindI18nStore;
|
|
129
|
+
b.current = !0, !k && !w && ue(o, m, function() {
|
|
130
|
+
b.current && D(H);
|
|
131
|
+
}), k && V && V !== j && b.current && D(H);
|
|
132
|
+
function l() {
|
|
133
|
+
b.current && D(H);
|
|
134
|
+
}
|
|
135
|
+
return x && o && o.on(x, l), N && o && o.store.on(N, l), function() {
|
|
136
|
+
b.current = !1, x && o && x.split(" ").forEach(function(u) {
|
|
137
|
+
return o.off(u, l);
|
|
138
|
+
}), N && o && N.split(" ").forEach(function(u) {
|
|
139
|
+
return o.store.off(u, l);
|
|
140
|
+
});
|
|
141
|
+
};
|
|
142
|
+
}, [o, j]);
|
|
143
|
+
var I = f.useRef(!0);
|
|
144
|
+
f.useEffect(function() {
|
|
145
|
+
b.current && !I.current && D(H), I.current = !1;
|
|
146
|
+
}, [o, E]);
|
|
147
|
+
var _ = [W, o, k];
|
|
148
|
+
if (_.t = W, _.i18n = o, _.ready = k, k || !k && !w)
|
|
149
|
+
return _;
|
|
150
|
+
throw new Promise(function(x) {
|
|
151
|
+
ue(o, m, function() {
|
|
152
|
+
x();
|
|
153
|
+
});
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function ft(t) {
|
|
157
|
+
return ht("translation", { i18n: Fe, ...t });
|
|
158
|
+
}
|
|
159
|
+
const gt = (t) => {
|
|
160
|
+
if (!t.hash)
|
|
161
|
+
throw new z("CAPTCHA.MISSING_ITEM_HASH", { context: { item: t } });
|
|
162
|
+
return t.hash;
|
|
163
|
+
}, mt = ({ challenge: t, solution: e, onClick: n, themeColor: r }) => {
|
|
164
|
+
const a = t.captcha.items, s = f.useMemo(() => r === "light" ? J : Q, [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, i) => {
|
|
174
|
+
const p = gt(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: v("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 ${i + 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" }) }) }) })] }) }, i);
|
|
218
|
+
}) });
|
|
219
|
+
};
|
|
220
|
+
function wt(t = {}) {
|
|
221
|
+
return Object.keys(t).reduce((e, n) => ({ ...e, [`data-${n}`]: t[n] }), {});
|
|
222
|
+
}
|
|
223
|
+
function ae({ general: t, dev: e }) {
|
|
224
|
+
return {
|
|
225
|
+
...wt(t)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
const yt = {
|
|
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
|
+
}, bt = ({ themeColor: t, buttonType: e, text: n, onClick: r }) => {
|
|
255
|
+
const a = f.useMemo(() => t === "light" ? J : Q, [t]), [s, o] = f.useState(!1), c = f.useMemo(() => {
|
|
256
|
+
const i = {
|
|
257
|
+
...yt,
|
|
258
|
+
color: s ? a.palette.primary.contrastText : a.palette.background.contrastText
|
|
259
|
+
};
|
|
260
|
+
return e === "cancel" ? {
|
|
261
|
+
...i,
|
|
262
|
+
backgroundColor: s ? a.palette.grey[600] : "transparent"
|
|
263
|
+
} : {
|
|
264
|
+
...i,
|
|
265
|
+
backgroundColor: s ? a.palette.primary.main : a.palette.background.default
|
|
266
|
+
};
|
|
267
|
+
}, [e, s, a]);
|
|
268
|
+
return d("button", { ...ae({ dev: { cy: `button-${e}` } }), onMouseEnter: () => o(!0), onMouseLeave: () => o(!1), style: c, onClick: (i) => {
|
|
269
|
+
i.preventDefault(), r();
|
|
270
|
+
}, children: n });
|
|
271
|
+
}, he = bt, Ct = ({ challenge: t, index: e, solutions: n, onSubmit: r, onCancel: a, onClick: s, onNext: o, themeColor: c }) => {
|
|
272
|
+
const { t: i } = ft(), p = t.captchas ? g(t.captchas, e) : null, w = n ? g(n, e) : [], E = f.useMemo(() => c === "light" ? J : Q, [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: v("div", { style: {
|
|
282
|
+
backgroundColor: E.palette.background.default,
|
|
283
|
+
display: "flex",
|
|
284
|
+
flexDirection: "column",
|
|
285
|
+
minWidth: "300px"
|
|
286
|
+
}, children: [v("div", { style: {
|
|
287
|
+
display: "flex",
|
|
288
|
+
alignItems: "center",
|
|
289
|
+
width: "100%",
|
|
290
|
+
backgroundColor: E.palette.primary.main,
|
|
291
|
+
padding: "24px 16px"
|
|
292
|
+
}, children: [v("p", { style: {
|
|
293
|
+
color: "#ffffff",
|
|
294
|
+
fontWeight: 700,
|
|
295
|
+
lineHeight: 1.5
|
|
296
|
+
}, children: [i("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", { ...ae({ dev: { cy: "captcha-" + e } }), children: p && d(mt, { challenge: p, solution: w, onClick: s, themeColor: c }) }), d("div", { style: {
|
|
302
|
+
display: "flex",
|
|
303
|
+
alignItems: "center",
|
|
304
|
+
justifyContent: "center",
|
|
305
|
+
width: "100%"
|
|
306
|
+
}, ...ae({ dev: { cy: "dots-captcha" } }) }), d("div", { style: {
|
|
307
|
+
padding: "8px 16px",
|
|
308
|
+
display: "flex",
|
|
309
|
+
width: "100%"
|
|
310
|
+
} }), v("div", { style: {
|
|
311
|
+
padding: "0 16px 16px",
|
|
312
|
+
display: "flex",
|
|
313
|
+
alignItems: "center",
|
|
314
|
+
justifyContent: "space-between",
|
|
315
|
+
lineHeight: 1.75
|
|
316
|
+
}, children: [d(he, { themeColor: c, buttonType: "cancel", onClick: a, text: i("WIDGET.CANCEL") }), d(he, { themeColor: c, buttonType: "next", text: e < t.captchas.length - 1 ? i("WIDGET.NEXT") : i("WIDGET.SUBMIT"), onClick: e < t.captchas.length - 1 ? o : r })] })] }) }) });
|
|
317
|
+
}, xt = Ct;
|
|
318
|
+
function vt(t) {
|
|
319
|
+
return new Promise((e) => {
|
|
320
|
+
document.readyState === "complete" ? e(t()) : window.addEventListener("load", () => e(t()));
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
const X = window;
|
|
324
|
+
X.injectedWeb3 = X.injectedWeb3 || {};
|
|
325
|
+
ye();
|
|
326
|
+
let fe = null;
|
|
327
|
+
function ye() {
|
|
328
|
+
return Object.values(X.injectedWeb3).filter(({ connect: t, enable: e }) => !!(t || e)).length !== 0;
|
|
329
|
+
}
|
|
330
|
+
function At(t) {
|
|
331
|
+
return Promise.all(Object.entries(X.injectedWeb3).map(([e, { connect: n, enable: r, version: a }]) => Promise.resolve().then(() => n ? n(t) : r ? r(t).then((s) => ze({ 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 Et(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 fe = vt(() => n.then(() => At(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 ye(), console.info(`web3Enable: Enabled ${r.length} extension${r.length !== 1 ? "s" : ""}: ${a.join(", ")}`), r;
|
|
343
|
+
}))), fe;
|
|
344
|
+
}
|
|
345
|
+
class It extends $e {
|
|
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 Et(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((i) => i.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 Nt(t) {
|
|
364
|
+
try {
|
|
365
|
+
const e = await fetch(t);
|
|
366
|
+
if (!e.ok)
|
|
367
|
+
throw new re("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 A("DATABASE.IMAGE_GET_FAILED", { context: { error: e } });
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const Tt = "NO_SOLUTION";
|
|
377
|
+
function be(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: be.name,
|
|
385
|
+
index: o
|
|
386
|
+
}
|
|
387
|
+
});
|
|
388
|
+
});
|
|
389
|
+
return K([
|
|
390
|
+
t.target,
|
|
391
|
+
...e ? St(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 St(t) {
|
|
400
|
+
return t !== void 0 ? t.sort() : [Tt];
|
|
401
|
+
}
|
|
402
|
+
async function Pt(t) {
|
|
403
|
+
if (t.type === "text")
|
|
404
|
+
return { ...t, hash: ie(t.data) };
|
|
405
|
+
if (t.type === "image")
|
|
406
|
+
return { ...t, hash: ie(await Nt(t.data)) };
|
|
407
|
+
throw new z("CAPTCHA.INVALID_ITEM_FORMAT");
|
|
408
|
+
}
|
|
409
|
+
function Ot(t) {
|
|
410
|
+
return K([t.captchaId, t.captchaContentId, [...t.solution].sort(), t.salt]);
|
|
411
|
+
}
|
|
412
|
+
class ge {
|
|
413
|
+
constructor(e) {
|
|
414
|
+
this.hash = e, this.parent = null;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
class kt {
|
|
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 ge(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, i = this.createParent(o, c);
|
|
442
|
+
s.push(i.hash), r.push(i), a += 2;
|
|
443
|
+
}
|
|
444
|
+
return this.layers.push(s), this.buildMerkleTree(r);
|
|
445
|
+
}
|
|
446
|
+
createParent(e, n) {
|
|
447
|
+
const r = new ge(K([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 i = [e], p = g(s, c);
|
|
463
|
+
c > o ? i.push(p) : i.unshift(p), n.push([g(i, 0), g(i, 1)]), r += 1, e = K(i);
|
|
464
|
+
}
|
|
465
|
+
const a = g(this.layers, this.layers.length - 1);
|
|
466
|
+
return [...n, [g(a, 0)]];
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
function Lt(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 = K(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 Ht {
|
|
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 A("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 A("CAPTCHA.INVALID_DATASET_CONTENT_ID");
|
|
508
|
+
for (const o of n.captchas) {
|
|
509
|
+
if (!Dt(o))
|
|
510
|
+
throw new A("CAPTCHA.INVALID_CAPTCHA_CHALLENGE");
|
|
511
|
+
if (!Lt(o.captcha.captchaContentId, o.proof))
|
|
512
|
+
throw new A("CAPTCHA.INVALID_CAPTCHA_CHALLENGE");
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
async submitCaptchaSolution(e, n, r, a, s) {
|
|
516
|
+
const o = new kt(), c = a.map((m) => Ot(m));
|
|
517
|
+
o.build(c);
|
|
518
|
+
const i = o.root.hash, p = void 0;
|
|
519
|
+
let w;
|
|
520
|
+
if (this.web2) {
|
|
521
|
+
if (!e || !e.signRaw)
|
|
522
|
+
throw new A("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: Be(n),
|
|
528
|
+
type: "bytes"
|
|
529
|
+
})).signature;
|
|
530
|
+
}
|
|
531
|
+
let E;
|
|
532
|
+
try {
|
|
533
|
+
E = 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 [E, i, p];
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
async function Dt(t) {
|
|
541
|
+
const e = t.captcha, n = t.proof;
|
|
542
|
+
if (!(await Promise.all(e.items.map(async (a) => (await Pt(a)).hash === a.hash))).every((a) => a === !0))
|
|
543
|
+
return !1;
|
|
544
|
+
const r = be(e, !1, !1, !1);
|
|
545
|
+
return r !== e.captchaContentId ? !1 : g(n, 0).indexOf(r) !== -1;
|
|
546
|
+
}
|
|
547
|
+
const _t = Ht, Ce = "@prosopo/current_account", xe = "@prosopo/provider";
|
|
548
|
+
function Rt(t) {
|
|
549
|
+
localStorage.setItem(Ce, t);
|
|
550
|
+
}
|
|
551
|
+
function Mt() {
|
|
552
|
+
return localStorage.getItem(Ce);
|
|
553
|
+
}
|
|
554
|
+
function Ut(t) {
|
|
555
|
+
localStorage.setItem(xe, t);
|
|
556
|
+
}
|
|
557
|
+
function Wt() {
|
|
558
|
+
return localStorage.getItem(xe);
|
|
559
|
+
}
|
|
560
|
+
const B = {
|
|
561
|
+
setAccount: Rt,
|
|
562
|
+
getAccount: Mt,
|
|
563
|
+
setProviderUrl: Ut,
|
|
564
|
+
getProviderUrl: Wt
|
|
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
|
+
}), me = (t) => {
|
|
575
|
+
const e = t.networks[t.defaultNetwork];
|
|
576
|
+
if (!e)
|
|
577
|
+
throw new A("DEVELOPER.NETWORK_NOT_FOUND", {
|
|
578
|
+
context: { error: `No network found for environment ${t.defaultEnvironment}` }
|
|
579
|
+
});
|
|
580
|
+
return e;
|
|
581
|
+
};
|
|
582
|
+
function Gt(t, e, n, r) {
|
|
583
|
+
const a = Ke(n, e, r), s = (l) => {
|
|
584
|
+
const u = l instanceof Error ? l : new Error(String(l));
|
|
585
|
+
a.onError(u);
|
|
586
|
+
}, o = Ve(e, n), c = () => {
|
|
587
|
+
const l = {
|
|
588
|
+
userAccountAddress: "",
|
|
589
|
+
...t
|
|
590
|
+
};
|
|
591
|
+
return e.account && (l.userAccountAddress = e.account.account.address), Ee.parse(l);
|
|
592
|
+
}, i = async (l) => {
|
|
593
|
+
try {
|
|
594
|
+
await l();
|
|
595
|
+
} catch (u) {
|
|
596
|
+
console.error(u), s(u), o({ isHuman: !1, showModal: !1, loading: !1 });
|
|
597
|
+
}
|
|
598
|
+
}, p = async () => {
|
|
599
|
+
a.onOpen(), await i(async () => {
|
|
600
|
+
if (e.loading || e.isHuman)
|
|
601
|
+
return;
|
|
602
|
+
D(), o({ loading: !0 });
|
|
603
|
+
const l = c();
|
|
604
|
+
o({ dappAccount: l.account.address }), await Ye(100);
|
|
605
|
+
const u = await V(), h = await x();
|
|
606
|
+
let y = !1;
|
|
607
|
+
try {
|
|
608
|
+
y = (await h.query.dappOperatorIsHumanUser(u.account.address, l.solutionThreshold)).value.unwrap().unwrap();
|
|
609
|
+
} catch (T) {
|
|
610
|
+
}
|
|
611
|
+
if (y) {
|
|
612
|
+
o({ isHuman: !0, loading: !1 }), a.onHuman({
|
|
613
|
+
user: u.account.address,
|
|
614
|
+
dapp: I()
|
|
615
|
+
}), W();
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const C = B.getProviderUrl();
|
|
619
|
+
let P;
|
|
620
|
+
if (C) {
|
|
621
|
+
P = await M(C);
|
|
622
|
+
try {
|
|
623
|
+
const T = await P.verifyDappUser(I(), u.account.address, void 0, t.challengeValidLength);
|
|
624
|
+
if (T.verified) {
|
|
625
|
+
o({ isHuman: !0, loading: !1 });
|
|
626
|
+
const ee = {
|
|
627
|
+
[$.providerUrl]: C,
|
|
628
|
+
[$.user]: u.account.address,
|
|
629
|
+
[$.dapp]: I(),
|
|
630
|
+
[$.commitmentId]: ce(T.commitmentId),
|
|
631
|
+
[$.blockNumber]: T.blockNumber
|
|
632
|
+
};
|
|
633
|
+
a.onHuman(ee), 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: qe("message"),
|
|
643
|
+
type: "bytes"
|
|
644
|
+
};
|
|
645
|
+
await u.extension.signer.signRaw(O);
|
|
646
|
+
const L = await le(h.query.getRandomActiveProvider, h.query)(u.account.address, I()), R = parseInt(L.blockNumber.toString()), Y = te(L.provider.url.toString());
|
|
647
|
+
P = await M(Y);
|
|
648
|
+
const F = await (await H(h, L, P)).getCaptchaChallenge();
|
|
649
|
+
if (F.captchas.length <= 0)
|
|
650
|
+
throw new re("DEVELOPER.PROVIDER_NO_CAPTCHA");
|
|
651
|
+
const Z = F.captchas.map((T) => T.captcha.timeLimitMs || 30 * 1e3).reduce((T, ee) => T + ee), Ae = setTimeout(() => {
|
|
652
|
+
a.onChallengeExpired(), o({ isHuman: !1, showModal: !1, loading: !1 });
|
|
653
|
+
}, Z);
|
|
654
|
+
o({
|
|
655
|
+
index: 0,
|
|
656
|
+
solutions: F.captchas.map(() => []),
|
|
657
|
+
challenge: F,
|
|
658
|
+
showModal: !0,
|
|
659
|
+
timeout: Ae,
|
|
660
|
+
blockNumber: R
|
|
661
|
+
});
|
|
662
|
+
});
|
|
663
|
+
}, w = async () => {
|
|
664
|
+
await i(async () => {
|
|
665
|
+
if (U(), !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 l = e.challenge, u = Xe(), h = e.challenge.captchas.map((G, F) => {
|
|
671
|
+
const Z = g(e.solutions, F);
|
|
672
|
+
return {
|
|
673
|
+
captchaId: G.captcha.captchaId,
|
|
674
|
+
captchaContentId: G.captcha.captchaContentId,
|
|
675
|
+
salt: u,
|
|
676
|
+
solution: Z
|
|
677
|
+
};
|
|
678
|
+
}), y = b(), C = _(), P = y.extension.signer, O = g(l.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 L = j(), R = await L.submitCaptchaSolution(P, l.requestHash, O.captcha.datasetId, h, u), Y = R[0].verified;
|
|
684
|
+
if (Y || a.onFailed(), o({
|
|
685
|
+
submission: R,
|
|
686
|
+
isHuman: Y,
|
|
687
|
+
loading: !1
|
|
688
|
+
}), e.isHuman) {
|
|
689
|
+
const G = te(L.provider.provider.url.toString());
|
|
690
|
+
B.setProviderUrl(G), a.onHuman({
|
|
691
|
+
providerUrl: G,
|
|
692
|
+
user: y.account.address,
|
|
693
|
+
dapp: I(),
|
|
694
|
+
commitmentId: ce(R[1]),
|
|
695
|
+
blockNumber: C
|
|
696
|
+
}), W();
|
|
697
|
+
}
|
|
698
|
+
});
|
|
699
|
+
}, E = async () => {
|
|
700
|
+
U(), D(), a.onClose();
|
|
701
|
+
}, m = (l) => {
|
|
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(l) ? y.splice(y.indexOf(l), 1) : y.push(l), o({ solutions: h });
|
|
712
|
+
}, k = () => {
|
|
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
|
+
}, H = async (l, u, h) => {
|
|
723
|
+
const y = c(), C = new _t(b().account.address, l, u, h, y.web2, I());
|
|
724
|
+
return o({ captchaApi: C }), j();
|
|
725
|
+
}, M = async (l) => {
|
|
726
|
+
const u = c(), h = me(u);
|
|
727
|
+
if (!u.account.address)
|
|
728
|
+
throw new A("GENERAL.SITE_KEY_MISSING");
|
|
729
|
+
return new Je(h, l, u.account.address);
|
|
730
|
+
}, U = () => {
|
|
731
|
+
window.clearTimeout(e.timeout), o({ timeout: void 0 });
|
|
732
|
+
}, W = () => {
|
|
733
|
+
const l = t.challengeValidLength || 12e4, u = setTimeout(() => {
|
|
734
|
+
o({ isHuman: !1 }), a.onExpired();
|
|
735
|
+
}, l);
|
|
736
|
+
o({ successfullChallengeTimeout: u });
|
|
737
|
+
}, D = () => {
|
|
738
|
+
U(), o(jt());
|
|
739
|
+
}, j = () => {
|
|
740
|
+
if (!e.captchaApi)
|
|
741
|
+
throw new re("API.UNKNOWN", { context: { error: "Captcha api not set", state: e } });
|
|
742
|
+
return e.captchaApi;
|
|
743
|
+
}, V = async () => {
|
|
744
|
+
const l = c();
|
|
745
|
+
if (!l.web2 && !l.userAccountAddress)
|
|
746
|
+
throw new A("GENERAL.ACCOUNT_NOT_FOUND", {
|
|
747
|
+
context: { error: "Account address has not been set for web3 mode" }
|
|
748
|
+
});
|
|
749
|
+
const h = await (l.web2 ? new Qe() : new It()).getAccount(l);
|
|
750
|
+
return B.setAccount(h.account.address), o({ account: h }), b();
|
|
751
|
+
}, b = () => {
|
|
752
|
+
if (!e.account)
|
|
753
|
+
throw new A("GENERAL.ACCOUNT_NOT_FOUND", { context: { error: "Account not loaded" } });
|
|
754
|
+
return e.account;
|
|
755
|
+
}, I = () => {
|
|
756
|
+
if (!e.dappAccount)
|
|
757
|
+
throw new A("GENERAL.SITE_KEY_MISSING");
|
|
758
|
+
return e.dappAccount;
|
|
759
|
+
}, _ = () => {
|
|
760
|
+
if (!e.blockNumber)
|
|
761
|
+
throw new Ze("CAPTCHA.INVALID_BLOCK_NO", { context: { error: "Block number not found" } });
|
|
762
|
+
return e.blockNumber;
|
|
763
|
+
}, x = async () => {
|
|
764
|
+
const l = c(), u = me(l), h = await et.create({ provider: new tt(u.endpoint), initWasm: !1 }), y = "sr25519", C = new nt({ type: y, ss58Format: h.registry.chainSS58 });
|
|
765
|
+
return new rt(h, JSON.parse(ot), u.contract.address, "prosopo", 0, C.addFromAddress(b().account.address));
|
|
766
|
+
};
|
|
767
|
+
return {
|
|
768
|
+
start: p,
|
|
769
|
+
cancel: E,
|
|
770
|
+
submit: w,
|
|
771
|
+
select: m,
|
|
772
|
+
nextRound: k,
|
|
773
|
+
exportData: async (l) => {
|
|
774
|
+
var P;
|
|
775
|
+
const u = B.getProviderUrl();
|
|
776
|
+
let h;
|
|
777
|
+
if (u)
|
|
778
|
+
h = await M(u);
|
|
779
|
+
else {
|
|
780
|
+
const O = await x(), L = await le(O.query.getRandomActiveProvider, O.query)(b().account.address, I()), R = te(L.provider.url.toString());
|
|
781
|
+
h = await M(R);
|
|
782
|
+
}
|
|
783
|
+
if (!(B.getProviderUrl() || ((P = e.captchaApi) == null ? void 0 : P.provider.provider.url.toString())))
|
|
784
|
+
return;
|
|
785
|
+
let C = "";
|
|
786
|
+
try {
|
|
787
|
+
C = b().account.address;
|
|
788
|
+
} catch (O) {
|
|
789
|
+
console.error(O);
|
|
790
|
+
}
|
|
791
|
+
await h.submitUserEvents(l, C);
|
|
792
|
+
}
|
|
793
|
+
};
|
|
794
|
+
}
|
|
795
|
+
const Ft = 1e4, se = (t, e) => {
|
|
796
|
+
e((n) => {
|
|
797
|
+
let r = [...n, t];
|
|
798
|
+
return r.length > Ft && (r = r.slice(1)), r;
|
|
799
|
+
});
|
|
800
|
+
}, zt = (t, e) => {
|
|
801
|
+
const n = {
|
|
802
|
+
x: t.x,
|
|
803
|
+
y: t.y,
|
|
804
|
+
timestamp: t.timeStamp
|
|
805
|
+
};
|
|
806
|
+
se(n, e);
|
|
807
|
+
}, we = (t, e) => {
|
|
808
|
+
const n = {
|
|
809
|
+
key: t.key,
|
|
810
|
+
timestamp: t.timeStamp,
|
|
811
|
+
isShiftKey: t.shiftKey,
|
|
812
|
+
isCtrlKey: t.ctrlKey
|
|
813
|
+
};
|
|
814
|
+
se(n, e);
|
|
815
|
+
}, q = (t, e) => {
|
|
816
|
+
for (const n of Array.from(t.touches))
|
|
817
|
+
se({ x: n.clientX, y: n.clientY, timestamp: t.timeStamp }, e);
|
|
818
|
+
}, $t = (t, e, n, r) => {
|
|
819
|
+
const a = ve(r);
|
|
820
|
+
a && (a.addEventListener("mousemove", (s) => zt(s, t)), a.addEventListener("keydown", (s) => we(s, n)), a.addEventListener("keyup", (s) => we(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)));
|
|
821
|
+
}, ve = (t) => t.tagName === "FORM" ? t : t.parentElement ? ve(t.parentElement) : null, Bt = ({ onProcessData: t, sendData: e, account: n }) => {
|
|
822
|
+
const [r, a] = f.useState([]), [s, o] = f.useState([]), [c, i] = f.useState([]), p = f.useRef(null);
|
|
823
|
+
return f.useEffect(() => {
|
|
824
|
+
p && p.current && $t(a, o, i, p.current);
|
|
825
|
+
}, []), f.useEffect(() => {
|
|
826
|
+
n && t({
|
|
827
|
+
mouseEvents: r,
|
|
828
|
+
touchEvents: s,
|
|
829
|
+
keyboardEvents: c
|
|
830
|
+
});
|
|
831
|
+
}, [e, n]), d("div", { ref: p });
|
|
832
|
+
}, Kt = Bt, Vt = Ie.memo((t, e) => {
|
|
833
|
+
const { show: n, children: r } = t, s = {
|
|
834
|
+
position: "fixed",
|
|
835
|
+
zIndex: 2147483646,
|
|
836
|
+
inset: 0,
|
|
837
|
+
display: n ? "block" : "none"
|
|
838
|
+
}, o = {
|
|
839
|
+
position: "fixed",
|
|
840
|
+
display: "flex",
|
|
841
|
+
alignItems: "center",
|
|
842
|
+
justifyContent: "center",
|
|
843
|
+
right: 0,
|
|
844
|
+
bottom: 0,
|
|
845
|
+
top: 0,
|
|
846
|
+
left: 0,
|
|
847
|
+
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
|
848
|
+
zIndex: -1
|
|
849
|
+
}, c = {
|
|
850
|
+
position: "absolute",
|
|
851
|
+
top: "50%",
|
|
852
|
+
left: "50%",
|
|
853
|
+
transform: "translate(-50%, -50%)",
|
|
854
|
+
width: "400px",
|
|
855
|
+
backgroundColor: "rgb(255, 255, 255)",
|
|
856
|
+
border: "none",
|
|
857
|
+
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,"
|
|
858
|
+
};
|
|
859
|
+
return v("div", { className: "modalOuter", style: s, children: [d("div", { className: "modalBackground", style: o }), d("div", { className: "modalInner", style: c, children: r })] });
|
|
860
|
+
}), Yt = Vt, Jt = (t) => {
|
|
861
|
+
const e = t.config, n = t.callbacks || {}, [r, a] = at(f.useState, f.useRef), s = Gt(e, r, a, n), o = t.config.theme === "light" ? "light" : "dark", c = t.config.theme === "light" ? J : Q;
|
|
862
|
+
return d("div", { children: v("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: [d(Yt, { show: r.showModal, children: r.challenge ? d(xt, { 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." }) }), v(Ne, { children: [d(Te, { children: v("div", { style: Se, "data-cy": "button-human", children: [" ", v("div", { style: {
|
|
863
|
+
padding: "2px",
|
|
864
|
+
border: "1px solid",
|
|
865
|
+
backgroundColor: c.palette.background.default,
|
|
866
|
+
borderColor: c.palette.grey[300],
|
|
867
|
+
borderRadius: "8px",
|
|
868
|
+
display: "flex",
|
|
869
|
+
alignItems: "center",
|
|
870
|
+
flexWrap: "wrap",
|
|
871
|
+
justifyContent: "space-between",
|
|
872
|
+
minHeight: `${Pe}px`,
|
|
873
|
+
overflow: "hidden"
|
|
874
|
+
}, children: [d("div", { style: { display: "inline-flex", flexDirection: "column" }, children: d("div", { style: {
|
|
875
|
+
alignItems: "center",
|
|
876
|
+
flex: 1
|
|
877
|
+
}, children: v("div", { style: {
|
|
878
|
+
display: "flex",
|
|
879
|
+
alignItems: "center",
|
|
880
|
+
justifyContent: "center",
|
|
881
|
+
flexDirection: "column",
|
|
882
|
+
verticalAlign: "middle"
|
|
883
|
+
}, children: [d("div", { style: {
|
|
884
|
+
display: r.loading ? "none" : "flex"
|
|
885
|
+
}, children: d(st, { themeColor: o, onChange: s.start, checked: r.isHuman, labelText: "I am human" }) }), d("div", { style: {
|
|
886
|
+
display: r.loading ? "flex" : "none"
|
|
887
|
+
}, children: d("div", { style: { display: "inline-flex" }, children: d(Oe, { themeColor: o }) }) })] }) }) }), d("div", { style: { display: "inline-flex", flexDirection: "column" }, children: d("a", { href: ke, target: "_blank", "aria-label": Le, children: d("div", { style: { flex: 1 }, children: d(He, { themeColor: o }) }) }) })] })] }) }), e.devOnlyWatchEvents && d(Kt, { onProcessData: s.exportData, sendData: r.sendData, account: r.account })] })] }) });
|
|
888
|
+
};
|
|
889
|
+
export {
|
|
890
|
+
Jt as default
|
|
891
|
+
};
|