@prosopo/procaptcha-bundle 2.0.3 → 2.1.1

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