@prosopo/procaptcha-bundle 2.5.3 → 2.5.5

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 (60) hide show
  1. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts.map +1 -1
  2. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/index.js +15 -17
  3. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +1 -1
  4. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.js +23 -27
  5. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/tests/util/renderLogic.test.js.map +1 -1
  6. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.d.ts +2 -2
  7. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.d.ts.map +1 -1
  8. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.js +4 -7
  9. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/captcha/captchaRenderer.js.map +1 -1
  10. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.d.ts +2 -2
  11. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.d.ts.map +1 -1
  12. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.js +9 -4
  13. package/.rollup.cache/home/runner/work/captcha-private/captcha-private/captcha/packages/procaptcha-bundle/dist/bundle/util/widgetFactory.js.map +1 -1
  14. package/dist/bundle/ProcaptchaWidget-CCSN3Dxj.js +636 -0
  15. package/dist/bundle/{ProcaptchaWidget-Dnwno-4N.js → ProcaptchaWidget-Dfex8hc8.js} +4 -4
  16. package/dist/bundle/{asU8a-JliaME7-.js → asU8a-CAsEnbuP.js} +1 -1
  17. package/dist/bundle/{bip39-CFjno8fK.js → bip39-DCaMcFzo.js} +2 -2
  18. package/dist/bundle/{captchaComponentProvider-dcMua0p9.js → captchaComponentProvider-Dm44AMrY.js} +23 -18
  19. package/dist/bundle/captchaRenderer-BBodRhQu.js +70 -0
  20. package/dist/bundle/{emotion-element-5486c51c.browser.esm-Bywq83R5.js → emotion-element-5486c51c.browser.esm-CQHFV-dS.js} +711 -746
  21. package/dist/bundle/{fp.esm-C0kLYOiJ.js → fp.esm-DYWeNGcH.js} +17 -0
  22. package/dist/bundle/{hash-CtL1HOjf.js → hash-D-64Vz5z.js} +1 -1
  23. package/dist/bundle/{captchaRenderer-D-du50M4.js → index-9I1Aae33.js} +1293 -1355
  24. package/dist/bundle/index-DCHEbWAs.js +1242 -0
  25. package/dist/bundle/{index-DcG_c-Na.js → index-DkQ4njKa.js} +12 -12
  26. package/dist/bundle/{index-BTlHNFX8.js → index-DxswvPTy.js} +285 -183
  27. package/dist/bundle/{index-BMjJnq60.js → index-nNwZuute.js} +252 -252
  28. package/dist/bundle/index.d.ts.map +1 -1
  29. package/dist/bundle/locales/de/translation.json +55 -405
  30. package/dist/bundle/locales/en/translation.json +55 -405
  31. package/dist/bundle/locales/es/translation.json +55 -405
  32. package/dist/bundle/locales/fr/translation.json +55 -405
  33. package/dist/bundle/locales/it/translation.json +55 -405
  34. package/dist/bundle/locales/pt/translation.json +55 -405
  35. package/dist/bundle/locales/pt-BR/translation.json +55 -405
  36. package/dist/bundle/procaptcha.bundle.js +1 -1
  37. package/dist/bundle/{useTranslation-7b6JJ18N.js → useTranslation-CEt2t9kE.js} +1 -1
  38. package/dist/bundle/util/captcha/captchaRenderer.d.ts +2 -2
  39. package/dist/bundle/util/captcha/captchaRenderer.d.ts.map +1 -1
  40. package/dist/bundle/util/widgetFactory.d.ts +2 -2
  41. package/dist/bundle/util/widgetFactory.d.ts.map +1 -1
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +15 -17
  44. package/dist/index.js.map +1 -1
  45. package/dist/tests/util/renderLogic.test.js +23 -27
  46. package/dist/tests/util/renderLogic.test.js.map +1 -1
  47. package/dist/util/captcha/captchaRenderer.d.ts +2 -2
  48. package/dist/util/captcha/captchaRenderer.d.ts.map +1 -1
  49. package/dist/util/captcha/captchaRenderer.js +4 -7
  50. package/dist/util/captcha/captchaRenderer.js.map +1 -1
  51. package/dist/util/widgetFactory.d.ts +2 -2
  52. package/dist/util/widgetFactory.d.ts.map +1 -1
  53. package/dist/util/widgetFactory.js +9 -4
  54. package/dist/util/widgetFactory.js.map +1 -1
  55. package/package.json +20 -14
  56. package/stats.html +1 -1
  57. package/vite.config.ts +18 -3
  58. package/vite.serve.config.ts +24 -0
  59. package/dist/bundle/ProcaptchaWidget-BlWWnPeB.js +0 -615
  60. package/dist/bundle/index-B8oMghZ3.js +0 -1120
package/vite.config.ts CHANGED
@@ -14,14 +14,21 @@
14
14
 
15
15
  import * as fs from "node:fs";
16
16
  import * as path from "node:path";
17
- import { ViteFrontendConfig } from "@prosopo/config";
17
+ import { getLoggerDefault } from "@prosopo/common";
18
+ import {
19
+ ViteFrontendConfig,
20
+ VitePluginRemoveUnusedTranslations,
21
+ } from "@prosopo/config";
18
22
  import { loadEnv } from "@prosopo/dotenv";
23
+ import { at, flatten } from "@prosopo/util";
19
24
  import fg from "fast-glob";
20
25
  import { defineConfig } from "vite";
21
26
 
22
27
  // load env using our util because vite loadEnv is not working for .env.development
23
28
  loadEnv();
24
29
 
30
+ const logger = getLoggerDefault();
31
+
25
32
  // Vite doesn't find the tsconfig for some reason
26
33
  process.env.TS_NODE_PROJECT = path.resolve("./tsconfig.json");
27
34
 
@@ -53,11 +60,13 @@ const copyDir = {
53
60
  destDir: `${workspaceRoot}/packages/procaptcha-bundle/dist/bundle/locales`,
54
61
  };
55
62
 
56
- const localFiles = await fg.glob(
63
+ const localeFiles = await fg.glob(
57
64
  `${workspaceRoot}/packages/locale/src/locales/**/*.json`,
58
65
  );
59
66
 
60
- console.log(localFiles);
67
+ const translationKeys = Object.keys(
68
+ flatten(JSON.parse(fs.readFileSync(at(localeFiles, 0), "utf-8"))),
69
+ );
61
70
 
62
71
  // Merge with generic frontend config
63
72
  export default defineConfig(async ({ command, mode }) => {
@@ -84,12 +93,18 @@ export default defineConfig(async ({ command, mode }) => {
84
93
  if (!fs.existsSync(containingFolder)) {
85
94
  fs.mkdirSync(containingFolder, { recursive: true });
86
95
  }
96
+ logger.info(`Copying ${copyDir.srcDir} to ${copyDir.destDir}`);
87
97
  fs.cpSync(copyDir.srcDir, copyDir.destDir, {
88
98
  recursive: true,
89
99
  });
90
100
  }
91
101
  },
92
102
  },
103
+ VitePluginRemoveUnusedTranslations(
104
+ translationKeys,
105
+ `${copyDir.destDir}/**/*.json`,
106
+ ),
107
+
93
108
  ...(frontendConfig.plugins ? frontendConfig.plugins : []),
94
109
  ],
95
110
  };
@@ -0,0 +1,24 @@
1
+ // Copyright 2021-2025 Prosopo (UK) Ltd.
2
+ //
3
+ // Licensed under the Apache License, Version 2.0 (the "License");
4
+ // you may not use this file except in compliance with the License.
5
+ // You may obtain a copy of the License at
6
+ //
7
+ // http://www.apache.org/licenses/LICENSE-2.0
8
+ //
9
+ // Unless required by applicable law or agreed to in writing, software
10
+ // distributed under the License is distributed on an "AS IS" BASIS,
11
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ // See the License for the specific language governing permissions and
13
+ // limitations under the License.
14
+
15
+ // vite.config.js
16
+ import { defineConfig } from "vite";
17
+
18
+ export default defineConfig({
19
+ server: {
20
+ port: 9269,
21
+ },
22
+ // Change the default public directory if needed
23
+ publicDir: "dist/bundle", // assets in the "assets" folder at the project root will be served
24
+ });
@@ -1,615 +0,0 @@
1
- import { j as i, a as I, P as _, b as T, c as k, g as ae, p as B, d as se, e as ce, E as ie, C as le } from "./captchaComponentProvider-dcMua0p9.js";
2
- import { r as f, A as b, o as de, P as X, R as ue } from "./emotion-element-5486c51c.browser.esm-Bywq83R5.js";
3
- import { b as M, d as S, a as w, l as he } from "./index-BTlHNFX8.js";
4
- import { u as q, b as pe, s as ge, a as fe, c as me } from "./useTranslation-7b6JJ18N.js";
5
- import { h as W } from "./hash-CtL1HOjf.js";
6
- import { r as xe } from "./asU8a-JliaME7-.js";
7
- const Ce = (t) => Array.isArray(t) && t !== null, O = new Array(256), Y = new Array(256 * 256);
8
- for (let t = 0; t < 256; t++)
9
- O[t] = t.toString(16).padStart(2, "0");
10
- for (let t = 0; t < 256; t++) {
11
- const e = t << 8;
12
- for (let r = 0; r < 256; r++)
13
- Y[e | r] = O[t] + O[r];
14
- }
15
- function U(t, e) {
16
- const r = t.length % 2 | 0, a = t.length - r | 0;
17
- for (let n = 0; n < a; n += 2)
18
- e += Y[t[n] << 8 | t[n + 1]];
19
- return r && (e += O[t[a] | 0]), e;
20
- }
21
- function be(t, e = -1, r = !0) {
22
- const a = r ? "0x" : "";
23
- if (!(t != null && t.length))
24
- return a;
25
- if (e > 0) {
26
- const n = Math.ceil(e / 8);
27
- if (t.length > n)
28
- return `${U(t.subarray(0, n / 2), a)}…${U(t.subarray(t.length - n / 2), "")}`;
29
- }
30
- return U(t, a);
31
- }
32
- const we = (t) => Ce(t) ? be(new Uint8Array(t)) : t.toString(), Ae = {
33
- border: "none",
34
- paddingTop: "6px",
35
- paddingBottom: "6px",
36
- cursor: "pointer",
37
- height: "39px",
38
- width: "39px",
39
- borderRadius: "50%"
40
- }, ye = ({ themeColor: t, onReload: e }) => {
41
- const r = f.useMemo(() => t === "light" ? M : S, [t]), [a, n] = f.useState(!1), s = f.useMemo(() => ({
42
- ...{
43
- ...Ae,
44
- backgroundColor: r.palette.background.default,
45
- color: a ? r.palette.primary.contrastText : r.palette.background.contrastText
46
- },
47
- backgroundColor: a ? r.palette.grey[700] : r.palette.background.default
48
- }), [a, r]);
49
- return i("button", { className: "reload-button", "aria-label": "Reload", type: "button", style: s, onMouseEnter: () => n(!0), onMouseLeave: () => n(!1), onClick: (o) => {
50
- o.preventDefault(), e();
51
- }, children: I("svg", { width: "27px", height: "27px", viewBox: "0 0 27 27", version: "1.1", xmlns: "http://www.w3.org/2000/svg", xmlnsXlink: "http://www.w3.org/1999/xlink", children: [i("title", { children: "reload" }), i("path", { fill: s.color, transform: "scale(0.0703125)", d: "M234.666667,149.333333 L234.666667,106.666667 L314.564847,106.664112 C287.579138,67.9778918 242.745446,42.6666667 192,42.6666667 C109.525477,42.6666667 42.6666667,109.525477 42.6666667,192 C42.6666667,274.474523 109.525477,341.333333 192,341.333333 C268.201293,341.333333 331.072074,284.258623 340.195444,210.526102 L382.537159,215.817985 C370.807686,310.617565 289.973536,384 192,384 C85.961328,384 1.42108547e-14,298.038672 1.42108547e-14,192 C1.42108547e-14,85.961328 85.961328,1.42108547e-14 192,1.42108547e-14 C252.316171,1.42108547e-14 306.136355,27.8126321 341.335366,71.3127128 L341.333333,1.42108547e-14 L384,1.42108547e-14 L384,149.333333 L234.666667,149.333333 Z" })] }) });
52
- }, Ee = (t) => {
53
- if (!t.hash)
54
- throw new _("CAPTCHA.MISSING_ITEM_HASH", {
55
- context: { item: t }
56
- });
57
- return t.hash;
58
- }, Te = ({ challenge: t, solution: e, onClick: r, themeColor: a }) => {
59
- const n = t.items, s = f.useMemo(() => a === "light" ? M : S, [a]), o = `${s.spacing.half}px`;
60
- return i("div", { style: {
61
- width: "100%",
62
- height: "100%",
63
- display: "flex",
64
- flexDirection: "row",
65
- flexWrap: "wrap",
66
- justifyContent: "space-between",
67
- paddingBottom: o,
68
- paddingRight: o
69
- }, children: n.map((d, l) => {
70
- const u = Ee(d);
71
- return i("div", { style: {
72
- flexGrow: 1,
73
- flexBasis: "33.3333%",
74
- boxSizing: "border-box",
75
- paddingLeft: o,
76
- paddingTop: o
77
- }, children: I("div", { style: {
78
- position: "relative",
79
- cursor: "pointer",
80
- height: "100%",
81
- width: "100%",
82
- border: 1,
83
- padding: 0,
84
- margin: 0,
85
- borderStyle: "solid",
86
- borderColor: s.palette.grey[300]
87
- }, onClick: () => r(u), children: [i("img", { style: {
88
- width: "100%",
89
- backgroundColor: s.palette.grey[300],
90
- display: "block",
91
- objectFit: "contain",
92
- aspectRatio: "1/1",
93
- height: "auto"
94
- }, src: d.data, alt: `Captcha image ${l + 1}` }), i("div", { style: {
95
- position: "absolute",
96
- top: 0,
97
- left: 0,
98
- bottom: 0,
99
- right: 0,
100
- height: "100%",
101
- width: "100%",
102
- display: "flex",
103
- alignItems: "center",
104
- justifyContent: "center",
105
- backgroundColor: "rgba(0,0,0,0.5)",
106
- visibility: e.includes(u) ? "visible" : "hidden"
107
- }, children: i("svg", { style: {
108
- backgroundColor: "transparent",
109
- display: "block",
110
- width: "35%",
111
- height: "35%",
112
- transition: "fill 200ms cubic-bezier(0.4, 0, 0.2, 1) 0ms",
113
- userSelect: "none",
114
- fill: "currentcolor"
115
- }, focusable: "false", color: "#fff", "aria-hidden": "true", viewBox: "0 0 24 24", "data-testid": "CheckIcon", "aria-label": "Check icon", children: i("path", { d: "M9 16.17 4.83 12l-1.42 1.41L9 19 21 7l-1.41-1.41z" }) }) })] }) }, d.hash);
116
- }) });
117
- };
118
- function ve(t = {}) {
119
- return Object.keys(t).reduce((e, r) => ({ ...e, [`data-${r}`]: t[r] }), {});
120
- }
121
- function Z({ general: t, dev: e }) {
122
- return {
123
- ...ve(t)
124
- };
125
- }
126
- const Ie = {
127
- display: "inline-flex",
128
- alignItems: "center",
129
- justifyContent: "center",
130
- position: "relative",
131
- boxSizing: "border-box",
132
- outline: "0px",
133
- border: "0px",
134
- margin: "0px",
135
- cursor: "pointer",
136
- userSelect: "none",
137
- verticalAlign: "middle",
138
- appearance: void 0,
139
- textDecoration: "none",
140
- fontWeight: "500",
141
- fontSize: "0.875rem",
142
- lineHeight: "1.75",
143
- letterSpacing: "0.02857em",
144
- textTransform: "uppercase",
145
- minWidth: "64px",
146
- padding: "6px 16px",
147
- borderRadius: "4px",
148
- 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",
149
- color: "rgb(0, 0, 0)",
150
- backgroundColor: "#ffffff",
151
- 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"
152
- }, j = ({ themeColor: t, buttonType: e, text: r, onClick: a }) => {
153
- const n = f.useMemo(() => t === "light" ? M : S, [t]), [s, o] = f.useState(!1), d = f.useMemo(() => {
154
- const l = {
155
- ...Ie,
156
- color: s ? n.palette.primary.contrastText : n.palette.background.contrastText
157
- };
158
- return e === "cancel" ? {
159
- ...l,
160
- backgroundColor: s ? n.palette.grey[600] : "transparent"
161
- } : {
162
- ...l,
163
- backgroundColor: s ? n.palette.primary.main : n.palette.background.default
164
- };
165
- }, [e, s, n]);
166
- return i("button", { ...Z({ dev: {} }), onMouseEnter: () => o(!0), onMouseLeave: () => o(!1), style: d, onClick: (l) => {
167
- l.preventDefault(), a();
168
- }, "aria-label": r, children: r });
169
- }, z = ({ challenge: t, index: e, solutions: r, onSubmit: a, onCancel: n, onClick: s, onNext: o, onReload: d, themeColor: l }) => {
170
- const { t: u } = q(), h = t.captchas ? w(t.captchas, e) : null, y = r ? w(r, e) : [], C = f.useMemo(() => l === "light" ? M : S, [l]), m = `${C.spacing.unit}px`, A = `${C.spacing.half}px`;
171
- return i(f.Suspense, { fallback: i("div", { children: "Loading..." }), children: i("div", { style: {
172
- overflowX: "auto",
173
- overflowY: "auto",
174
- width: "100%",
175
- maxWidth: "500px",
176
- maxHeight: "100%",
177
- display: "flex",
178
- flexDirection: "column",
179
- border: "1px solid #dddddd",
180
- boxShadow: "rgba(255, 255, 255, 0.2) 0px 0px 4px",
181
- borderRadius: "4px",
182
- backgroundColor: C.palette.background.default,
183
- userSelect: "none",
184
- touchAction: "none",
185
- overscrollBehavior: "none"
186
- }, children: I("div", { style: {
187
- backgroundColor: C.palette.background.default,
188
- display: "flex",
189
- flexDirection: "column",
190
- minWidth: "300px"
191
- }, children: [i("div", { style: {
192
- display: "flex",
193
- alignItems: "center",
194
- width: "100%"
195
- }, children: i("div", { style: {
196
- backgroundColor: C.palette.primary.main,
197
- width: "100%",
198
- marginTop: m,
199
- marginLeft: m,
200
- marginRight: m
201
- }, children: I("div", { style: {
202
- paddingLeft: `${C.spacing.half}px`,
203
- paddingRight: `${C.spacing.half}px`
204
- }, children: [I("p", { style: {
205
- color: "#ffffff",
206
- fontWeight: 700,
207
- lineHeight: 1.5
208
- }, children: [u("WIDGET.SELECT_ALL"), ":", " ", i("span", { children: `${u(w(t.captchas, e).target)} ` })] }), i("p", { style: {
209
- color: "#ffffff",
210
- fontWeight: 500,
211
- lineHeight: 0.8,
212
- fontSize: "0.8rem"
213
- }, children: u("WIDGET.IF_NONE_CLICK_NEXT") })] }) }) }), i("div", { ...Z({ dev: {} }), style: {
214
- paddingRight: A,
215
- paddingLeft: A
216
- }, children: h && i(Te, { challenge: h, solution: y, onClick: s, themeColor: l }) }), i("div", { style: {
217
- display: "flex",
218
- alignItems: "center",
219
- justifyContent: "space-between",
220
- lineHeight: 1.75,
221
- padding: m,
222
- paddingBottom: A,
223
- paddingTop: A
224
- }, children: I("div", { style: {
225
- display: "grid",
226
- gridAutoFlow: "column",
227
- gridTemplateColumns: "repeat(3, minmax(0, 1fr)",
228
- width: "100%"
229
- }, children: [i("div", { style: { justifySelf: "left" }, children: i(j, { themeColor: l, buttonType: "cancel", onClick: n, text: u("WIDGET.CANCEL"), "aria-label": u("WIDGET.CANCEL") }) }), i("div", { style: { justifySelf: "center" }, children: i(ye, { themeColor: l, onReload: d }) }), i("div", { style: { justifySelf: "right" }, children: i(j, { themeColor: l, buttonType: "next", text: e < t.captchas.length - 1 ? u("WIDGET.NEXT") : u("WIDGET.SUBMIT"), onClick: e < t.captchas.length - 1 ? o : a, "aria-label": e < t.captchas.length - 1 ? u("WIDGET.NEXT") : u("WIDGET.SUBMIT"), "data-cy": "button-next" }) })] }) })] }) }) });
230
- };
231
- function Ne(t) {
232
- return W([
233
- t.captchaId,
234
- t.captchaContentId,
235
- [...t.solution].sort(),
236
- t.salt
237
- ]);
238
- }
239
- class $ {
240
- constructor(e) {
241
- this.hash = e, this.parent = null;
242
- }
243
- }
244
- class ke {
245
- constructor() {
246
- this.leaves = [], this.layers = [];
247
- }
248
- getRoot() {
249
- if (this.root === void 0)
250
- throw new T("DATASET.MERKLE_ERROR", {
251
- context: {
252
- error: "root undefined",
253
- failedFuncName: this.getRoot.name
254
- }
255
- });
256
- return this.root;
257
- }
258
- build(e) {
259
- this.layers.length && (this.layers = []);
260
- const r = [];
261
- for (const a of e) {
262
- const n = new $(a);
263
- this.leaves.push(n), r.push(n.hash);
264
- }
265
- this.layers.push(r), this.root = this.buildMerkleTree(this.leaves)[0];
266
- }
267
- buildMerkleTree(e) {
268
- const r = e.length;
269
- if (r === 1)
270
- return e;
271
- const a = [];
272
- let n = 0;
273
- const s = [];
274
- for (; n < r; ) {
275
- const o = e[n];
276
- if (o === void 0)
277
- throw new T("DEVELOPER.GENERAL", {
278
- context: { error: "leftChild undefined" }
279
- });
280
- const d = n + 1 < r ? w(e, n + 1) : o, l = this.createParent(o, d);
281
- s.push(l.hash), a.push(l), n += 2;
282
- }
283
- return this.layers.push(s), this.buildMerkleTree(a);
284
- }
285
- createParent(e, r) {
286
- const a = new $(W([e.hash, r.hash]));
287
- return e.parent = a.hash, r.parent = a.hash, a;
288
- }
289
- proof(e) {
290
- const r = [];
291
- let a = 0;
292
- for (; a < this.layers.length - 1; ) {
293
- const s = this.layers[a];
294
- if (s === void 0)
295
- throw new T("DATASET.MERKLE_ERROR", {
296
- context: {
297
- error: "layer undefined",
298
- failedFuncName: this.proof.name,
299
- layerNum: a
300
- }
301
- });
302
- const o = s.indexOf(e);
303
- let d = o % 2 && o > 0 ? o - 1 : o + 1;
304
- d > s.length - 1 && (d = o);
305
- const l = [e], u = w(s, d);
306
- d > o ? l.push(u) : l.unshift(u), r.push([w(l, 0), w(l, 1)]), a += 1, e = W(l);
307
- }
308
- const n = w(this.layers, this.layers.length - 1);
309
- return [...r, [w(n, 0)]];
310
- }
311
- }
312
- class F {
313
- constructor(e, r, a, n, s) {
314
- this.userAccount = e, this.provider = r, this.providerApi = a, this._web2 = n, this.dappAccount = s;
315
- }
316
- get web2() {
317
- return this._web2;
318
- }
319
- async getCaptchaChallenge(e) {
320
- try {
321
- const r = await this.providerApi.getCaptchaChallenge(this.userAccount, this.provider, e);
322
- if (r[b.error])
323
- return r;
324
- for (const a of r.captchas)
325
- for (const n of a.items)
326
- n.data && (n.data = `https://${n.data.replace(/^http(s)*:\/\//, "")}`);
327
- return r;
328
- } catch (r) {
329
- throw new k("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
330
- context: { error: r }
331
- });
332
- }
333
- }
334
- async submitCaptchaSolution(e, r, a, n, s) {
335
- const o = new ke(), d = a.map((y) => Ne(y));
336
- if (o.build(d), !o.root)
337
- throw new _("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
338
- context: { error: "Merkle tree root is undefined" }
339
- });
340
- const l = o.root.hash, u = void 0;
341
- let h;
342
- try {
343
- h = await this.providerApi.submitCaptchaSolution(a, r, this.userAccount, n, s, e);
344
- } catch (y) {
345
- throw new _("CAPTCHA.INVALID_CAPTCHA_CHALLENGE", {
346
- context: { error: y }
347
- });
348
- }
349
- return [h, l, u];
350
- }
351
- }
352
- const He = () => ({
353
- showModal: !1,
354
- loading: !1,
355
- index: 0,
356
- challenge: void 0,
357
- solutions: void 0,
358
- isHuman: !1,
359
- captchaApi: void 0,
360
- account: void 0
361
- });
362
- function Re(t, e, r, a, n) {
363
- const s = ae(a), o = pe(e, r), d = () => {
364
- const c = {
365
- userAccountAddress: "",
366
- ...t
367
- };
368
- return e.account && (c.userAccountAddress = e.account.account.address), X.parse(c);
369
- }, l = async () => {
370
- s.onOpen(), await B(async () => {
371
- var R;
372
- if (e.loading || e.isHuman)
373
- return;
374
- o({ loading: !0 }), o({
375
- attemptCount: e.attemptCount ? e.attemptCount + 1 : 1
376
- }), o({
377
- sessionId: n == null ? void 0 : n.sessionId
378
- });
379
- const c = d();
380
- o({ dappAccount: c.account.address }), await fe(100);
381
- const g = await Q();
382
- let x = e.captchaApi;
383
- if (n != null && n.provider) {
384
- const N = n.provider.provider.url, E = await A(N);
385
- x = new F(g.account.address, n.provider, E, c.web2, c.account.address || ""), o({ captchaApi: x });
386
- } else {
387
- const N = await se(d()), E = N.provider.url, v = await A(E);
388
- x = new F(g.account.address, N, v, c.web2, c.account.address || ""), o({ captchaApi: x });
389
- }
390
- const p = await (x == null ? void 0 : x.getCaptchaChallenge(e.sessionId));
391
- if (p.error)
392
- o({
393
- loading: !1,
394
- error: {
395
- message: p.error.message,
396
- key: p.error.key || "API.UNKNOWN_ERROR"
397
- }
398
- }), s.onError(new Error((R = p.error) == null ? void 0 : R.message));
399
- else {
400
- if (p.captchas.length <= 0)
401
- throw new _("DEVELOPER.PROVIDER_NO_CAPTCHA");
402
- const N = p.captchas.map((v) => v.timeLimitMs || c.captchas.image.challengeTimeout).reduce((v, P) => v + P), E = setTimeout(() => {
403
- s.onChallengeExpired(), o({ isHuman: !1, showModal: !1, loading: !1 });
404
- }, N);
405
- o({
406
- index: 0,
407
- solutions: p.captchas.map(() => []),
408
- challenge: p,
409
- showModal: !0,
410
- timeout: E,
411
- loading: !1
412
- });
413
- }
414
- }, l, L, e.attemptCount, 10);
415
- }, u = async () => {
416
- await B(async () => {
417
- if (H(), !e.challenge)
418
- throw new T("CAPTCHA.NO_CAPTCHA", {
419
- context: { error: "Cannot submit, no Captcha found in state" }
420
- });
421
- o({ showModal: !1 });
422
- const c = e.challenge, g = xe(), x = e.challenge.captchas.map((D, oe) => {
423
- const re = w(e.solutions, oe);
424
- return {
425
- captchaId: D.captchaId,
426
- captchaContentId: D.captchaContentId,
427
- salt: g,
428
- solution: re
429
- };
430
- }), p = G(), R = te(p).signer;
431
- if (!w(c.captchas, 0).datasetId)
432
- throw new _("CAPTCHA.INVALID_CAPTCHA_ID", {
433
- context: { error: "No datasetId set for challenge" }
434
- });
435
- const E = e.captchaApi;
436
- if (!E)
437
- throw new T("CAPTCHA.INVALID_TOKEN", {
438
- context: { error: "No Captcha API found in state" }
439
- });
440
- if (!R || !R.signRaw)
441
- throw new k("GENERAL.CANT_FIND_KEYRINGPAIR", {
442
- context: {
443
- error: "Signer is not defined, cannot sign message to prove account ownership"
444
- }
445
- });
446
- const v = await R.signRaw({
447
- address: p.account.address,
448
- data: ge(c[b.timestamp]),
449
- type: "bytes"
450
- }), P = await E.submitCaptchaSolution(v.signature, c.requestHash, x, c.timestamp, c.signature.provider.requestHash), ne = P[0].verified;
451
- if (o({
452
- submission: P,
453
- isHuman: ne,
454
- loading: !1
455
- }), e.isHuman) {
456
- const D = E.provider.provider.url;
457
- s.onHuman(de({
458
- [b.providerUrl]: D,
459
- [b.user]: p.account.address,
460
- [b.dapp]: ee(),
461
- [b.commitmentId]: we(P[1]),
462
- [b.timestamp]: c.timestamp,
463
- [b.signature]: {
464
- [b.provider]: {
465
- [b.requestHash]: c.signature.provider.requestHash
466
- },
467
- [b.user]: {
468
- [b.timestamp]: v.signature
469
- }
470
- }
471
- })), J();
472
- } else
473
- s.onFailed(), L(n == null ? void 0 : n.restart);
474
- }, l, L, e.attemptCount, 10);
475
- }, h = async () => {
476
- H(), L(n == null ? void 0 : n.restart), s.onClose();
477
- }, y = async () => {
478
- H(), s.onReload(), L(n == null ? void 0 : n.restart), n != null && n.restart || await l();
479
- }, C = (c) => {
480
- if (!e.challenge)
481
- throw new T("CAPTCHA.NO_CAPTCHA", {
482
- context: { error: "Cannot select, no Captcha found in state" }
483
- });
484
- if (e.index >= e.challenge.captchas.length || e.index < 0)
485
- throw new T("CAPTCHA.NO_CAPTCHA", {
486
- context: {
487
- error: "Cannot select, index is out of range for this Captcha"
488
- }
489
- });
490
- const g = e.index, x = e.solutions, p = w(x, g);
491
- p.includes(c) ? p.splice(p.indexOf(c), 1) : p.push(c), o({ solutions: x });
492
- }, m = () => {
493
- if (!e.challenge)
494
- throw new T("CAPTCHA.NO_CAPTCHA", {
495
- context: { error: "Cannot select, no Captcha found in state" }
496
- });
497
- if (e.index + 1 >= e.challenge.captchas.length)
498
- throw new T("CAPTCHA.NO_CAPTCHA", {
499
- context: {
500
- error: "Cannot select, index is out of range for this Captcha"
501
- }
502
- });
503
- o({ index: e.index + 1 });
504
- }, A = async (c) => {
505
- const g = d();
506
- if (!g.account.address)
507
- throw new k("GENERAL.SITE_KEY_MISSING");
508
- return new ce(c, g.account.address);
509
- }, H = () => {
510
- window.clearTimeout(Number(e.timeout)), o({ timeout: void 0 });
511
- }, J = () => {
512
- const c = t.captchas.image.solutionTimeout, g = setTimeout(() => {
513
- o({ isHuman: !1 }), s.onExpired();
514
- }, c);
515
- o({ successfullChallengeTimeout: g });
516
- }, L = (c) => {
517
- H(), o(He()), s.onReset(), c && c();
518
- }, Q = async () => {
519
- const c = d();
520
- if (!c.web2 && !c.userAccountAddress)
521
- throw new k("GENERAL.ACCOUNT_NOT_FOUND", {
522
- context: { error: "Account address has not been set for web3 mode" }
523
- });
524
- const x = await (async () => {
525
- const p = new (await ie(c.web2))();
526
- return n ? n.userAccount : await p.getAccount(c);
527
- })();
528
- return o({ account: x }), G();
529
- }, G = () => {
530
- if (!e.account)
531
- throw new k("GENERAL.ACCOUNT_NOT_FOUND", {
532
- context: { error: "Account not loaded" }
533
- });
534
- return e.account;
535
- }, ee = () => {
536
- if (!e.dappAccount)
537
- throw new k("GENERAL.SITE_KEY_MISSING");
538
- return e.dappAccount;
539
- }, te = (c) => {
540
- const g = c || G();
541
- if (!g.extension)
542
- throw new k("ACCOUNT.NO_POLKADOT_EXTENSION", {
543
- context: { error: "Extension not loaded" }
544
- });
545
- return g.extension;
546
- };
547
- return {
548
- start: l,
549
- cancel: h,
550
- submit: u,
551
- select: C,
552
- nextRound: m,
553
- reload: y
554
- };
555
- }
556
- const K = ue.memo((t, e) => {
557
- const { show: r, children: a } = t, s = {
558
- position: "fixed",
559
- zIndex: 2147483646,
560
- inset: 0,
561
- display: r ? "block" : "none"
562
- }, o = {
563
- position: "fixed",
564
- display: "flex",
565
- alignItems: "center",
566
- justifyContent: "center",
567
- right: 0,
568
- bottom: 0,
569
- top: 0,
570
- left: 0,
571
- backgroundColor: "rgba(0, 0, 0, 0.5)",
572
- zIndex: -1
573
- }, d = {
574
- position: "absolute",
575
- top: "50%",
576
- left: "50%",
577
- transform: "translate(-50%, -50%)",
578
- width: "inherit",
579
- backgroundColor: "transparent",
580
- border: "none",
581
- 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,"
582
- };
583
- return I("div", { className: "prosopo-modalOuter", style: s, children: [i("div", { className: "prosopo-modalBackground", style: o }), i("div", { className: "prosopo-modalInner", style: d, children: a })] });
584
- }), V = "procaptcha:execute", Oe = (t) => {
585
- var C;
586
- const { t: e } = q(), r = X.parse(t.config), a = t.frictionlessState, n = t.i18n, s = t.callbacks || {}, [o, d] = me(f.useState, f.useRef), [l, u] = f.useState(!1), h = Re(r, o, d, s, a), y = t.config.theme === "light" ? M : S;
587
- return f.useEffect(() => {
588
- r.language && (n ? n.language !== r.language && n.changeLanguage(r.language).then((m) => m) : he().then((m) => {
589
- m.language !== r.language && m.changeLanguage(r.language).then((A) => A);
590
- }));
591
- }, [n, r.language]), f.useEffect(() => {
592
- o.error && (u(!1), o.error.key === "CAPTCHA.NO_SESSION_FOUND" && a && setTimeout(() => {
593
- a.restart();
594
- }, 3e3));
595
- }, [o.error, a]), f.useEffect(() => {
596
- const m = (A) => {
597
- if (d({
598
- showModal: !0
599
- }), !o.challenge && h.start)
600
- try {
601
- h.start();
602
- } catch (H) {
603
- console.error("Error starting verification:", H);
604
- }
605
- };
606
- return document.addEventListener(V, m), () => {
607
- document.removeEventListener(V, m);
608
- };
609
- }, [h, o.challenge, d]), r.mode === "invisible" ? i(K, { show: o.showModal, children: o.challenge ? i(z, { challenge: o.challenge, index: o.index, solutions: o.solutions, onSubmit: h.submit, onCancel: h.cancel, onClick: h.select, onNext: h.nextRound, onReload: h.reload, themeColor: r.theme ?? "light" }) : null }) : I("div", { className: "image-captcha", children: [i(K, { show: o.showModal, children: o.challenge ? i(z, { challenge: o.challenge, index: o.index, solutions: o.solutions, onSubmit: h.submit, onCancel: h.cancel, onClick: h.select, onNext: h.nextRound, onReload: h.reload, themeColor: r.theme ?? "light" }) : i("div", { children: "No challenge set." }) }), i(le, { theme: y, onChange: async () => {
610
- l || (u(!0), await h.start(), u(!1));
611
- }, checked: o.isHuman, labelText: e("WIDGET.I_AM_HUMAN"), error: (C = o.error) == null ? void 0 : C.message, "aria-label": "human checkbox", loading: l })] });
612
- };
613
- export {
614
- Oe as default
615
- };