@prosopo/procaptcha-bundle 2.1.0 → 2.1.2

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.
Files changed (115) hide show
  1. package/package.json +9 -8
  2. package/stats.html +1 -1
  3. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts +0 -12
  4. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts.map +0 -1
  5. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js +0 -71
  6. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +0 -1
  7. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/captchaType.test.d.ts +0 -2
  8. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/captchaType.test.d.ts.map +0 -1
  9. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/captchaType.test.js +0 -36
  10. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/captchaType.test.js.map +0 -1
  11. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/config.test.d.ts +0 -2
  12. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/config.test.d.ts.map +0 -1
  13. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/config.test.js +0 -69
  14. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/tests/config.test.js.map +0 -1
  15. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captchaType.d.ts +0 -2
  16. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captchaType.d.ts.map +0 -1
  17. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captchaType.js +0 -8
  18. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/captchaType.js.map +0 -1
  19. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/config.d.ts +0 -8
  20. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/config.d.ts.map +0 -1
  21. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/config.js +0 -31
  22. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/config.js.map +0 -1
  23. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/defaultCallbacks.d.ts +0 -19
  24. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/defaultCallbacks.d.ts.map +0 -1
  25. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/defaultCallbacks.js +0 -147
  26. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/defaultCallbacks.js.map +0 -1
  27. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/form.d.ts +0 -2
  28. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/form.d.ts.map +0 -1
  29. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/form.js +0 -2
  30. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/form.js.map +0 -1
  31. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/language.d.ts +0 -3
  32. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/language.d.ts.map +0 -1
  33. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/language.js +0 -17
  34. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/language.js.map +0 -1
  35. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/theme.d.ts +0 -3
  36. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/theme.d.ts.map +0 -1
  37. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/theme.js +0 -9
  38. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/theme.js.map +0 -1
  39. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.d.ts +0 -3
  40. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.d.ts.map +0 -1
  41. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.js +0 -9
  42. package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/util/timeout.js.map +0 -1
  43. package/dist/bundle/ProcaptchaWidget-BZq2OhjK.js +0 -615
  44. package/dist/bundle/ProcaptchaWidget-b_oUhvT9.js +0 -149
  45. package/dist/bundle/index-Ck7UqzKB.js +0 -19822
  46. package/dist/bundle/index.d.ts +0 -12
  47. package/dist/bundle/index.d.ts.map +0 -1
  48. package/dist/bundle/procaptcha.bundle.js +0 -5
  49. package/dist/bundle/tests/captchaType.test.d.ts +0 -2
  50. package/dist/bundle/tests/captchaType.test.d.ts.map +0 -1
  51. package/dist/bundle/tests/config.test.d.ts +0 -2
  52. package/dist/bundle/tests/config.test.d.ts.map +0 -1
  53. package/dist/bundle/util/captchaType.d.ts +0 -2
  54. package/dist/bundle/util/captchaType.d.ts.map +0 -1
  55. package/dist/bundle/util/config.d.ts +0 -8
  56. package/dist/bundle/util/config.d.ts.map +0 -1
  57. package/dist/bundle/util/defaultCallbacks.d.ts +0 -19
  58. package/dist/bundle/util/defaultCallbacks.d.ts.map +0 -1
  59. package/dist/bundle/util/form.d.ts +0 -2
  60. package/dist/bundle/util/form.d.ts.map +0 -1
  61. package/dist/bundle/util/language.d.ts +0 -3
  62. package/dist/bundle/util/language.d.ts.map +0 -1
  63. package/dist/bundle/util/theme.d.ts +0 -3
  64. package/dist/bundle/util/theme.d.ts.map +0 -1
  65. package/dist/bundle/util/timeout.d.ts +0 -3
  66. package/dist/bundle/util/timeout.d.ts.map +0 -1
  67. package/dist/bundle/utils-9IQXYrRR.js +0 -8672
  68. package/dist/cjs/index.cjs +0 -81
  69. package/dist/cjs/util/captchaType.cjs +0 -12
  70. package/dist/cjs/util/config.cjs +0 -33
  71. package/dist/cjs/util/defaultCallbacks.cjs +0 -134
  72. package/dist/cjs/util/form.cjs +0 -4
  73. package/dist/cjs/util/language.cjs +0 -18
  74. package/dist/cjs/util/theme.cjs +0 -9
  75. package/dist/cjs/util/timeout.cjs +0 -14
  76. package/dist/index.d.ts +0 -12
  77. package/dist/index.d.ts.map +0 -1
  78. package/dist/index.js +0 -71
  79. package/dist/index.js.map +0 -1
  80. package/dist/tests/captchaType.test.d.ts +0 -2
  81. package/dist/tests/captchaType.test.d.ts.map +0 -1
  82. package/dist/tests/captchaType.test.js +0 -36
  83. package/dist/tests/captchaType.test.js.map +0 -1
  84. package/dist/tests/config.test.d.ts +0 -2
  85. package/dist/tests/config.test.d.ts.map +0 -1
  86. package/dist/tests/config.test.js +0 -69
  87. package/dist/tests/config.test.js.map +0 -1
  88. package/dist/util/captchaType.d.ts +0 -3
  89. package/dist/util/captchaType.d.ts.map +0 -1
  90. package/dist/util/captchaType.js +0 -8
  91. package/dist/util/captchaType.js.map +0 -1
  92. package/dist/util/config.d.ts +0 -8
  93. package/dist/util/config.d.ts.map +0 -1
  94. package/dist/util/config.js +0 -31
  95. package/dist/util/config.js.map +0 -1
  96. package/dist/util/defaultCallbacks.d.ts +0 -19
  97. package/dist/util/defaultCallbacks.d.ts.map +0 -1
  98. package/dist/util/defaultCallbacks.js +0 -147
  99. package/dist/util/defaultCallbacks.js.map +0 -1
  100. package/dist/util/form.d.ts +0 -2
  101. package/dist/util/form.d.ts.map +0 -1
  102. package/dist/util/form.js +0 -2
  103. package/dist/util/form.js.map +0 -1
  104. package/dist/util/language.d.ts +0 -3
  105. package/dist/util/language.d.ts.map +0 -1
  106. package/dist/util/language.js +0 -17
  107. package/dist/util/language.js.map +0 -1
  108. package/dist/util/theme.d.ts +0 -3
  109. package/dist/util/theme.d.ts.map +0 -1
  110. package/dist/util/theme.js +0 -9
  111. package/dist/util/theme.js.map +0 -1
  112. package/dist/util/timeout.d.ts +0 -3
  113. package/dist/util/timeout.d.ts.map +0 -1
  114. package/dist/util/timeout.js +0 -9
  115. package/dist/util/timeout.js.map +0 -1
@@ -1,615 +0,0 @@
1
- import { z as P, P as b, a as u, b as I, c as D, e as ie, A as x, d as q, r as A, l as L, f as M, j as s, g as C, R as se, i as ce, W as le, C as de, h as he, k as pe, m as ue, n as ge, o as fe, p as me, L as xe, q as Ce, s as be, t as Ae } from "./index-Ck7UqzKB.js";
2
- import { u as ye, h as we, a as j, s as X, g as Te, p as F, b as Ee, c as Ie, d as Se, e as ve, r as Ne, P as He, E as De, f as Re, i as Y, j as _e, C as Pe } from "./utils-9IQXYrRR.js";
3
- function ke(t) {
4
- return ye(we(t));
5
- }
6
- const Le = (t) => Array.isArray(t) && t !== null, k = new Array(256), J = new Array(256 * 256);
7
- for (let t = 0; t < 256; t++)
8
- k[t] = t.toString(16).padStart(2, "0");
9
- for (let t = 0; t < 256; t++) {
10
- const e = t << 8;
11
- for (let o = 0; o < 256; o++)
12
- J[e | o] = k[t] + k[o];
13
- }
14
- function U(t, e) {
15
- const o = t.length % 2 | 0, r = t.length - o | 0;
16
- for (let n = 0; n < r; n += 2)
17
- e += J[t[n] << 8 | t[n + 1]];
18
- return o && (e += k[t[r] | 0]), e;
19
- }
20
- function Me(t, e = -1, o = !0) {
21
- const r = o ? "0x" : "";
22
- if (!(t != null && t.length))
23
- return r;
24
- if (e > 0) {
25
- const n = Math.ceil(e / 8);
26
- if (t.length > n)
27
- return `${U(t.subarray(0, n / 2), r)}…${U(t.subarray(t.length - n / 2), "")}`;
28
- }
29
- return U(t, r);
30
- }
31
- const Oe = (t) => Le(t) ? Me(new Uint8Array(t)) : t.toString(), Z = P.object({
32
- account: P.string().optional(),
33
- blockNumber: P.number().optional(),
34
- providerUrl: P.string().optional()
35
- });
36
- function Ge(t) {
37
- return j([
38
- t.captchaId,
39
- t.captchaContentId,
40
- [...t.solution].sort(),
41
- t.salt
42
- ]);
43
- }
44
- class K {
45
- constructor(e) {
46
- this.hash = e, this.parent = null;
47
- }
48
- }
49
- class We {
50
- constructor() {
51
- this.leaves = [], this.layers = [];
52
- }
53
- getRoot() {
54
- if (this.root === void 0)
55
- throw new b("DATASET.MERKLE_ERROR", {
56
- context: {
57
- error: "root undefined",
58
- failedFuncName: this.getRoot.name
59
- }
60
- });
61
- return this.root;
62
- }
63
- build(e) {
64
- this.layers.length && (this.layers = []);
65
- const o = [];
66
- for (const r of e) {
67
- const n = new K(r);
68
- this.leaves.push(n), o.push(n.hash);
69
- }
70
- this.layers.push(o), this.root = this.buildMerkleTree(this.leaves)[0];
71
- }
72
- buildMerkleTree(e) {
73
- const o = e.length;
74
- if (o === 1)
75
- return e;
76
- const r = [];
77
- let n = 0;
78
- const a = [];
79
- for (; n < o; ) {
80
- const c = e[n];
81
- if (c === void 0)
82
- throw new b("DEVELOPER.GENERAL", {
83
- context: { error: "leftChild undefined" }
84
- });
85
- const d = n + 1 < o ? u(e, n + 1) : c, i = this.createParent(c, d);
86
- a.push(i.hash), r.push(i), n += 2;
87
- }
88
- return this.layers.push(a), this.buildMerkleTree(r);
89
- }
90
- createParent(e, o) {
91
- const r = new K(j([e.hash, o.hash]));
92
- return e.parent = r.hash, o.parent = r.hash, r;
93
- }
94
- proof(e) {
95
- const o = [];
96
- let r = 0;
97
- for (; r < this.layers.length - 1; ) {
98
- const a = this.layers[r];
99
- if (a === void 0)
100
- throw new b("DATASET.MERKLE_ERROR", {
101
- context: {
102
- error: "layer undefined",
103
- failedFuncName: this.proof.name,
104
- layerNum: r
105
- }
106
- });
107
- const c = a.indexOf(e);
108
- let d = c % 2 && c > 0 ? c - 1 : c + 1;
109
- d > a.length - 1 && (d = c);
110
- const i = [e], g = u(a, d);
111
- d > c ? i.push(g) : i.unshift(g), o.push([u(i, 0), u(i, 1)]), r += 1, e = j(i);
112
- }
113
- const n = u(this.layers, this.layers.length - 1);
114
- return [...o, [u(n, 0)]];
115
- }
116
- }
117
- class Ue {
118
- constructor(e, o, r, n, a) {
119
- this.userAccount = e, this.provider = o, this.providerApi = r, this._web2 = n, this.dappAccount = a;
120
- }
121
- get web2() {
122
- return this._web2;
123
- }
124
- async getCaptchaChallenge() {
125
- try {
126
- const e = await this.providerApi.getCaptchaChallenge(this.userAccount, this.provider);
127
- for (const o of e.captchas)
128
- for (const r of o.items)
129
- r.data && (r.data = r.data.replace(/^http(s)*:\/\//, "//"));
130
- return e;
131
- } catch (e) {
132
- throw new I("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
133
- context: { error: e }
134
- });
135
- }
136
- }
137
- async submitCaptchaSolution(e, o, r, n, a) {
138
- const c = new We(), d = r.map((h) => Ge(h));
139
- if (c.build(d), !c.root)
140
- throw new D("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
141
- context: { error: "Merkle tree root is undefined" }
142
- });
143
- const i = c.root.hash, g = void 0;
144
- let y;
145
- try {
146
- y = await this.providerApi.submitCaptchaSolution(r, o, this.userAccount, n, a, e);
147
- } catch (h) {
148
- throw new D("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
149
- context: { error: h }
150
- });
151
- }
152
- return [y, i, g];
153
- }
154
- }
155
- const Q = "@prosopo/procaptcha";
156
- function z() {
157
- return Z.parse(JSON.parse(ke(localStorage.getItem(Q) || "0x7b7d")));
158
- }
159
- function ee(t) {
160
- localStorage.setItem(Q, X(JSON.stringify(Z.parse(t))));
161
- }
162
- function Be(t) {
163
- ee({ ...z(), account: t });
164
- }
165
- function je() {
166
- return z().account || null;
167
- }
168
- const B = {
169
- setAccount: Be,
170
- getAccount: je,
171
- setProcaptchaStorage: ee,
172
- getProcaptchaStorage: z
173
- }, $e = () => ({
174
- showModal: !1,
175
- loading: !1,
176
- index: 0,
177
- challenge: void 0,
178
- solutions: void 0,
179
- isHuman: !1,
180
- captchaApi: void 0,
181
- account: void 0
182
- });
183
- function ze(t, e, o, r) {
184
- const n = Te(o, e, r), a = Ee(e, o), c = () => {
185
- const l = {
186
- userAccountAddress: "",
187
- ...t
188
- };
189
- return e.account && (l.userAccountAddress = e.account.account.address), q.parse(l);
190
- }, d = async () => {
191
- n.onOpen(), await F(async () => {
192
- if (e.loading || e.isHuman)
193
- return;
194
- await Ie(), R(), a({ loading: !0 }), a({
195
- attemptCount: e.attemptCount ? e.attemptCount + 1 : 1
196
- });
197
- const l = c();
198
- a({ dappAccount: l.account.address }), await Se(100);
199
- const p = await te(), f = await ve(c()), m = f.provider.url, N = await v(m), W = new Ue(p.account.address, f, N, l.web2, l.account.address || "");
200
- a({ captchaApi: W });
201
- const T = await W.getCaptchaChallenge();
202
- if (T.captchas.length <= 0)
203
- throw new D("DEVELOPER.PROVIDER_NO_CAPTCHA");
204
- const _ = T.captchas.map((S) => S.timeLimitMs || l.captchas.image.challengeTimeout).reduce((S, E) => S + E), H = setTimeout(() => {
205
- n.onChallengeExpired(), a({ isHuman: !1, showModal: !1, loading: !1 });
206
- }, _);
207
- a({
208
- index: 0,
209
- solutions: T.captchas.map(() => []),
210
- challenge: T,
211
- showModal: !0,
212
- timeout: H
213
- });
214
- }, d, R, e.attemptCount, 10);
215
- }, i = async () => {
216
- await F(async () => {
217
- if (w(), !e.challenge)
218
- throw new b("CAPTCHA.NO_CAPTCHA", {
219
- context: { error: "Cannot submit, no Captcha found in state" }
220
- });
221
- a({ showModal: !1 });
222
- const l = e.challenge, p = Ne(), f = e.challenge.captchas.map((E, ae) => {
223
- const re = u(e.solutions, ae);
224
- return {
225
- captchaId: E.captchaId,
226
- captchaContentId: E.captchaContentId,
227
- salt: p,
228
- solution: re
229
- };
230
- }), m = G(), N = oe(m).signer;
231
- if (!u(l.captchas, 0).datasetId)
232
- throw new D("CAPTCHA.INVALID_CAPTCHA_ID", {
233
- context: { error: "No datasetId set for challenge" }
234
- });
235
- const T = e.captchaApi;
236
- if (!T)
237
- throw new b("CAPTCHA.INVALID_TOKEN", {
238
- context: { error: "No Captcha API found in state" }
239
- });
240
- if (!N || !N.signRaw)
241
- throw new I("GENERAL.CANT_FIND_KEYRINGPAIR", {
242
- context: {
243
- error: "Signer is not defined, cannot sign message to prove account ownership"
244
- }
245
- });
246
- const _ = await N.signRaw({
247
- address: m.account.address,
248
- data: X(l.requestHash),
249
- type: "bytes"
250
- }), H = await T.submitCaptchaSolution(_.signature, l.requestHash, f, l.timestamp, l.signature.provider.requestHash), S = H[0].verified;
251
- if (S || n.onFailed(), a({
252
- submission: H,
253
- isHuman: S,
254
- loading: !1
255
- }), e.isHuman) {
256
- const E = T.provider.provider.url;
257
- B.setProcaptchaStorage({
258
- ...B.getProcaptchaStorage(),
259
- providerUrl: E
260
- }), n.onHuman(ie({
261
- [x.providerUrl]: E,
262
- [x.user]: m.account.address,
263
- [x.dapp]: ne(),
264
- [x.commitmentId]: Oe(H[1]),
265
- [x.timestamp]: l.timestamp,
266
- [x.signature]: {
267
- [x.provider]: {
268
- [x.requestHash]: l.signature.provider.requestHash
269
- },
270
- [x.user]: {
271
- [x.requestHash]: _.signature
272
- }
273
- }
274
- })), O();
275
- }
276
- }, d, R, e.attemptCount, 10);
277
- }, g = async () => {
278
- w(), R(), n.onClose();
279
- }, y = (l) => {
280
- if (!e.challenge)
281
- throw new b("CAPTCHA.NO_CAPTCHA", {
282
- context: { error: "Cannot select, no Captcha found in state" }
283
- });
284
- if (e.index >= e.challenge.captchas.length || e.index < 0)
285
- throw new b("CAPTCHA.NO_CAPTCHA", {
286
- context: {
287
- error: "Cannot select, index is out of range for this Captcha"
288
- }
289
- });
290
- const p = e.index, f = e.solutions, m = u(f, p);
291
- m.includes(l) ? m.splice(m.indexOf(l), 1) : m.push(l), a({ solutions: f });
292
- }, h = () => {
293
- if (!e.challenge)
294
- throw new b("CAPTCHA.NO_CAPTCHA", {
295
- context: { error: "Cannot select, no Captcha found in state" }
296
- });
297
- if (e.index + 1 >= e.challenge.captchas.length)
298
- throw new b("CAPTCHA.NO_CAPTCHA", {
299
- context: {
300
- error: "Cannot select, index is out of range for this Captcha"
301
- }
302
- });
303
- a({ index: e.index + 1 });
304
- }, v = async (l) => {
305
- const p = c();
306
- if (!p.account.address)
307
- throw new I("GENERAL.SITE_KEY_MISSING");
308
- return new He(l, p.account.address);
309
- }, w = () => {
310
- window.clearTimeout(e.timeout), a({ timeout: void 0 });
311
- }, O = () => {
312
- const l = t.captchas.image.solutionTimeout, p = setTimeout(() => {
313
- a({ isHuman: !1 }), n.onExpired();
314
- }, l);
315
- a({ successfullChallengeTimeout: p });
316
- }, R = () => {
317
- w(), a($e());
318
- }, te = async () => {
319
- const l = c();
320
- if (!l.web2 && !l.userAccountAddress)
321
- throw new I("GENERAL.ACCOUNT_NOT_FOUND", {
322
- context: { error: "Account address has not been set for web3 mode" }
323
- });
324
- const f = await (l.web2 ? new De() : new Re()).getAccount(l);
325
- return B.setAccount(f.account.address), a({ account: f }), G();
326
- }, G = () => {
327
- if (!e.account)
328
- throw new I("GENERAL.ACCOUNT_NOT_FOUND", {
329
- context: { error: "Account not loaded" }
330
- });
331
- return e.account;
332
- }, ne = () => {
333
- if (!e.dappAccount)
334
- throw new I("GENERAL.SITE_KEY_MISSING");
335
- return e.dappAccount;
336
- }, oe = (l) => {
337
- const p = l || G();
338
- if (!p.extension)
339
- throw new I("ACCOUNT.NO_POLKADOT_EXTENSION", {
340
- context: { error: "Extension not loaded" }
341
- });
342
- return p.extension;
343
- };
344
- return {
345
- start: d,
346
- cancel: g,
347
- submit: i,
348
- select: y,
349
- nextRound: h
350
- };
351
- }
352
- const Fe = (t) => {
353
- if (!t.hash)
354
- throw new D("CAPTCHA.MISSING_ITEM_HASH", {
355
- context: { item: t }
356
- });
357
- return t.hash;
358
- }, Ke = ({ challenge: t, solution: e, onClick: o, themeColor: r }) => {
359
- const n = t.items, a = A.useMemo(() => r === "light" ? L : M, [r]), c = "ontouchstart" in window, d = `${a.spacing.unit}px`, i = `${a.spacing.half}px`, g = {
360
- 0: {
361
- paddingLeft: 0,
362
- paddingRight: i,
363
- paddingTop: i,
364
- paddingBottom: i
365
- },
366
- 1: {
367
- paddingLeft: i,
368
- paddingRight: i,
369
- paddingTop: i,
370
- paddingBottom: i
371
- },
372
- 2: {
373
- paddingLeft: i,
374
- paddingRight: 0,
375
- paddingTop: i,
376
- paddingBottom: i
377
- }
378
- }, y = {
379
- 0: { paddingTop: d },
380
- 2: { paddingBottom: d }
381
- };
382
- return s("div", { style: {
383
- paddingRight: 0.5,
384
- paddingBottom: 0.5,
385
- width: "100%",
386
- height: "100%",
387
- display: "flex",
388
- flexDirection: "row",
389
- flexWrap: "wrap"
390
- }, children: n.map((h, v) => {
391
- const w = Fe(h), O = {
392
- ...g[v % 3],
393
- ...y[Math.floor(v / 3)],
394
- flexGrow: 1,
395
- flexBasis: "33.3333%",
396
- boxSizing: "border-box"
397
- };
398
- return s("div", { style: O, children: C("div", { style: {
399
- cursor: "pointer",
400
- height: "100%",
401
- width: "100%",
402
- border: 1,
403
- borderStyle: "solid",
404
- borderColor: a.palette.grey[300]
405
- }, onClick: c ? void 0 : () => o(w), onTouchStart: c ? () => o(w) : void 0, children: [s("div", { children: s("img", { style: {
406
- width: "100%",
407
- backgroundColor: a.palette.grey[300],
408
- opacity: e.includes(w) && c ? "50%" : "100%",
409
- display: "block",
410
- objectFit: "contain",
411
- aspectRatio: "1/1",
412
- height: "auto"
413
- }, src: h.data, alt: `Captcha image ${v + 1}` }) }), s("div", { style: {
414
- position: "relative",
415
- width: "100%",
416
- height: "100%",
417
- top: "-100%",
418
- visibility: e.includes(w) ? "visible" : "hidden",
419
- transition: "opacity 225ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
420
- opacity: 1
421
- }, children: s("div", { style: {
422
- position: "absolute",
423
- top: 0,
424
- left: 0,
425
- bottom: 0,
426
- right: 0,
427
- height: "100%",
428
- width: "100%",
429
- display: "flex",
430
- alignItems: "center",
431
- justifyContent: "center",
432
- backgroundColor: "rgba(0,0,0,0.5)"
433
- }, children: s("svg", { style: {
434
- backgroundColor: "transparent",
435
- display: "block",
436
- width: "35%",
437
- height: "35%",
438
- transition: "fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
439
- userSelect: "none",
440
- fill: "currentcolor"
441
- }, focusable: "false", color: "#fff", "aria-hidden": "true", viewBox: "0 0 24 24", "data-testid": "CheckIcon", "aria-label": "Check icon", children: s("path", { d: "M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" }) }) }) })] }) }, h.hash);
442
- }) });
443
- };
444
- function Ve(t = {}) {
445
- return Object.keys(t).reduce((e, o) => ({ ...e, [`data-${o}`]: t[o] }), {});
446
- }
447
- function $({ general: t, dev: e }) {
448
- return {
449
- ...Ve(t)
450
- };
451
- }
452
- const qe = {
453
- display: "inline-flex",
454
- alignItems: "center",
455
- justifyContent: "center",
456
- position: "relative",
457
- boxSizing: "border-box",
458
- outline: "0px",
459
- border: "0px",
460
- margin: "0px",
461
- cursor: "pointer",
462
- userSelect: "none",
463
- verticalAlign: "middle",
464
- appearance: void 0,
465
- textDecoration: "none",
466
- fontWeight: "500",
467
- fontSize: "0.875rem",
468
- lineHeight: "1.75",
469
- letterSpacing: "0.02857em",
470
- textTransform: "uppercase",
471
- minWidth: "64px",
472
- padding: "6px 16px",
473
- borderRadius: "4px",
474
- 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",
475
- color: "rgb(0, 0, 0)",
476
- backgroundColor: "#ffffff",
477
- 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"
478
- }, V = ({ themeColor: t, buttonType: e, text: o, onClick: r }) => {
479
- const n = A.useMemo(() => t === "light" ? L : M, [t]), [a, c] = A.useState(!1), d = A.useMemo(() => {
480
- const i = {
481
- ...qe,
482
- color: a ? n.palette.primary.contrastText : n.palette.background.contrastText
483
- };
484
- return e === "cancel" ? {
485
- ...i,
486
- backgroundColor: a ? n.palette.grey[600] : "transparent"
487
- } : {
488
- ...i,
489
- backgroundColor: a ? n.palette.primary.main : n.palette.background.default
490
- };
491
- }, [e, a, n]);
492
- return s("button", { ...$({ dev: { cy: `button-${e}` } }), onMouseEnter: () => c(!0), onMouseLeave: () => c(!1), style: d, onClick: (i) => {
493
- i.preventDefault(), r();
494
- }, "aria-label": o, children: o });
495
- }, Xe = ({ challenge: t, index: e, solutions: o, onSubmit: r, onCancel: n, onClick: a, onNext: c, themeColor: d }) => {
496
- const { t: i } = Y(), g = t.captchas ? u(t.captchas, e) : null, y = o ? u(o, e) : [], h = A.useMemo(() => d === "light" ? L : M, [d]);
497
- return s(A.Suspense, { fallback: s("div", { children: "Loading..." }), children: s("div", { style: {
498
- overflowX: "auto",
499
- overflowY: "auto",
500
- width: "100%",
501
- maxWidth: "500px",
502
- maxHeight: "100%",
503
- display: "flex",
504
- flexDirection: "column",
505
- border: "1px solid #dddddd",
506
- boxShadow: "rgba(255, 255, 255, 0.2) 0px 0px 4px",
507
- borderRadius: "4px",
508
- padding: `${h.spacing.unit}px`,
509
- backgroundColor: h.palette.background.default
510
- }, children: C("div", { style: {
511
- backgroundColor: h.palette.background.default,
512
- display: "flex",
513
- flexDirection: "column",
514
- minWidth: "300px"
515
- }, children: [s("div", { style: {
516
- display: "flex",
517
- alignItems: "center",
518
- width: "100%"
519
- }, children: s("div", { style: {
520
- backgroundColor: h.palette.primary.main,
521
- width: "100%"
522
- }, children: C("div", { style: {
523
- paddingLeft: `${h.spacing.half}px`,
524
- paddingRight: `${h.spacing.half}px`
525
- }, children: [C("p", { style: {
526
- color: "#ffffff",
527
- fontWeight: 700,
528
- lineHeight: 1.5
529
- }, children: [i("WIDGET.SELECT_ALL"), ":", " ", s("span", { children: `${i(u(t.captchas, e).target)} ` })] }), s("p", { style: {
530
- color: "#ffffff",
531
- fontWeight: 500,
532
- lineHeight: 0.8,
533
- fontSize: "0.8rem"
534
- }, children: i("WIDGET.IF_NONE_CLICK_NEXT") })] }) }) }), s("div", { ...$({ dev: { cy: `captcha-${e}` } }), children: g && s(Ke, { challenge: g, solution: y, onClick: a, themeColor: d }) }), s("div", { style: {
535
- display: "flex",
536
- alignItems: "center",
537
- justifyContent: "center",
538
- width: "100%"
539
- }, ...$({ dev: { cy: "dots-captcha" } }) }), s("div", { style: {
540
- padding: `0 ${h.spacing}px`,
541
- display: "flex",
542
- width: "100%"
543
- } }), C("div", { style: {
544
- padding: `0 ${h.spacing}px`,
545
- display: "flex",
546
- alignItems: "center",
547
- justifyContent: "space-between",
548
- lineHeight: 1.75
549
- }, children: [s(V, { themeColor: d, buttonType: "cancel", onClick: n, text: i("WIDGET.CANCEL"), "aria-label": i("WIDGET.CANCEL") }), s(V, { themeColor: d, buttonType: "next", text: e < t.captchas.length - 1 ? i("WIDGET.NEXT") : i("WIDGET.SUBMIT"), onClick: e < t.captchas.length - 1 ? c : r, "aria-label": e < t.captchas.length - 1 ? i("WIDGET.NEXT") : i("WIDGET.SUBMIT"), "data-cy": "button-next" })] })] }) }) });
550
- }, Ye = se.memo((t, e) => {
551
- const { show: o, children: r } = t, a = {
552
- position: "fixed",
553
- zIndex: 2147483646,
554
- inset: 0,
555
- display: o ? "block" : "none"
556
- }, c = {
557
- position: "fixed",
558
- display: "flex",
559
- alignItems: "center",
560
- justifyContent: "center",
561
- right: 0,
562
- bottom: 0,
563
- top: 0,
564
- left: 0,
565
- backgroundColor: "rgba(0, 0, 0, 0.5)",
566
- zIndex: -1
567
- }, d = {
568
- position: "absolute",
569
- top: "50%",
570
- left: "50%",
571
- transform: "translate(-50%, -50%)",
572
- width: "400px",
573
- backgroundColor: "transparent",
574
- border: "none",
575
- 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,"
576
- };
577
- return C("div", { className: "prosopo-modalOuter", style: a, children: [s("div", { className: "prosopo-modalBackground", style: c }), s("div", { className: "prosopo-modalInner", style: d, children: r })] });
578
- }), Qe = (t) => {
579
- const { t: e } = Y(), o = q.parse(t.config), r = t.callbacks || {}, [n, a] = _e(A.useState, A.useRef), c = ze(o, n, a, r), d = t.config.theme === "light" ? "light" : "dark", i = t.config.theme === "light" ? L : M;
580
- return A.useEffect(() => {
581
- o.language && ce.changeLanguage(o.language);
582
- }, [o.language]), s("div", { children: C("div", { style: {
583
- maxWidth: le,
584
- maxHeight: "100%",
585
- overflowX: "auto"
586
- }, children: [s(Ye, { show: n.showModal, children: n.challenge ? s(Xe, { challenge: n.challenge, index: n.index, solutions: n.solutions, onSubmit: c.submit, onCancel: c.cancel, onClick: c.select, onNext: c.nextRound, themeColor: o.theme ?? "light" }) : s("div", { children: "No challenge set." }) }), s(de, { children: s(he, { children: C("div", { style: pe, "data-cy": "button-human", children: [" ", C("div", { style: {
587
- padding: ue,
588
- border: ge,
589
- backgroundColor: i.palette.background.default,
590
- borderColor: i.palette.grey[300],
591
- borderRadius: fe,
592
- display: "flex",
593
- alignItems: "center",
594
- flexWrap: "wrap",
595
- justifyContent: "space-between",
596
- minHeight: `${me}px`,
597
- overflow: "hidden"
598
- }, children: [s("div", { style: { display: "inline-flex", flexDirection: "column" }, children: s("div", { style: {
599
- alignItems: "center",
600
- flex: 1
601
- }, children: C("div", { style: {
602
- display: "flex",
603
- alignItems: "center",
604
- justifyContent: "center",
605
- flexDirection: "column",
606
- verticalAlign: "middle"
607
- }, children: [s("div", { style: {
608
- display: n.loading ? "none" : "flex"
609
- }, children: s(Pe, { themeColor: d, onChange: c.start, checked: n.isHuman, labelText: e("WIDGET.I_AM_HUMAN"), "aria-label": "human checkbox" }) }), s("div", { style: {
610
- display: n.loading ? "flex" : "none"
611
- }, children: s("div", { style: { display: "inline-flex" }, children: s(xe, { themeColor: d, "aria-label": "Loading spinner" }) }) })] }) }) }), s("div", { style: { display: "inline-flex", flexDirection: "column" }, children: s("a", { href: Ce, target: "_blank", "aria-label": be, rel: "noreferrer", children: s("div", { style: { flex: 1 }, children: s(Ae, { themeColor: d, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) })] }) });
612
- };
613
- export {
614
- Qe as default
615
- };