@prosopo/procaptcha-bundle 2.0.0 → 2.0.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.
package/vite.config.ts CHANGED
@@ -11,11 +11,13 @@
11
11
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  // See the License for the specific language governing permissions and
13
13
  // limitations under the License.
14
+
14
15
  import * as fs from "node:fs";
15
16
  import * as path from "node:path";
16
- import { loadEnv } from "@prosopo/cli";
17
+ import { loadEnv } from "@prosopo/dotenv";
17
18
  import { ViteFrontendConfig } from "@prosopo/config";
18
19
  import { defineConfig } from "vite";
20
+
19
21
  // load env using our util because vite loadEnv is not working for .env.development
20
22
  loadEnv();
21
23
 
@@ -28,36 +30,36 @@ const bundleName = "procaptcha";
28
30
  const packageName = "@prosopo/procaptcha-bundle";
29
31
  const entry = "./src/index.tsx";
30
32
  const copyOptions = copyTo
31
- ? {
32
- srcDir: "./dist/bundle",
33
- destDir: copyTo,
34
- }
35
- : undefined;
33
+ ? {
34
+ srcDir: "./dist/bundle",
35
+ destDir: copyTo,
36
+ }
37
+ : undefined;
36
38
  const tsConfigPaths = [path.resolve("./tsconfig.json")];
37
39
  const packagesDir = path.resolve("..");
38
40
  const workspaceRoot = path.resolve("../../");
39
41
  // Get all folders in packagesDir
40
42
  const packages = fs
41
- .readdirSync(packagesDir)
42
- .filter((f) => fs.statSync(path.join(packagesDir, f)).isDirectory());
43
+ .readdirSync(packagesDir)
44
+ .filter((f) => fs.statSync(path.join(packagesDir, f)).isDirectory());
43
45
  for (const packageName of packages) {
44
- // Add the tsconfig for each package to tsConfigPaths
45
- tsConfigPaths.push(path.resolve(`../${packageName}/tsconfig.json`));
46
+ // Add the tsconfig for each package to tsConfigPaths
47
+ tsConfigPaths.push(path.resolve(`../${packageName}/tsconfig.json`));
46
48
  }
47
49
  // Merge with generic frontend config
48
50
  export default defineConfig(async ({ command, mode }) => {
49
- const frontendConfig = await ViteFrontendConfig(
50
- packageName,
51
- bundleName,
52
- path.resolve(),
53
- entry,
54
- command,
55
- mode,
56
- copyOptions,
57
- tsConfigPaths,
58
- workspaceRoot,
59
- );
60
- return {
61
- ...frontendConfig,
62
- };
51
+ const frontendConfig = await ViteFrontendConfig(
52
+ packageName,
53
+ bundleName,
54
+ path.resolve(),
55
+ entry,
56
+ command,
57
+ mode,
58
+ copyOptions,
59
+ tsConfigPaths,
60
+ workspaceRoot,
61
+ );
62
+ return {
63
+ ...frontendConfig,
64
+ };
63
65
  });
@@ -1,162 +0,0 @@
1
- import { A as o, e as G, a as H, P as L, r as v, j as n, C as U, W as j, b as D, c as M, f as B, g as F, h as K, i as V, L as X, k as Y, m as $, n as q, l as z, d as J } from "./index-jr-ls0GZ.js";
2
- import { v as Q, k as _, E as Z, p as ee, n as te, f as w, o as ne, s as oe, q as ae, l as k, t as re, C as se } from "./utils-CHbJaqXT.js";
3
- const ce = (s, e) => {
4
- let r = 0;
5
- const d = "0".repeat(e);
6
- for (; ; ) {
7
- const p = new TextEncoder().encode(r + s);
8
- if (ie(Q(p)).startsWith(d))
9
- return r;
10
- r += 1;
11
- }
12
- }, ie = (s) => Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join(""), le = (s, e, r, d) => {
13
- const p = _(r, e, d), u = () => ({
14
- showModal: !1,
15
- loading: !1,
16
- index: 0,
17
- challenge: void 0,
18
- solutions: void 0,
19
- isHuman: !1,
20
- captchaApi: void 0,
21
- account: void 0
22
- }), b = () => {
23
- window.clearTimeout(e.timeout), a({ timeout: void 0 });
24
- }, T = () => {
25
- window.clearTimeout(e.successfullChallengeTimeout), a({ successfullChallengeTimeout: void 0 });
26
- }, i = () => {
27
- const t = {
28
- userAccountAddress: "",
29
- ...s
30
- };
31
- return e.account && (t.userAccountAddress = e.account.account.address), L.parse(t);
32
- }, E = (t) => {
33
- const c = t.networks[t.defaultNetwork];
34
- if (!c)
35
- throw new w("DEVELOPER.NETWORK_NOT_FOUND", {
36
- context: {
37
- error: `No network found for environment ${t.defaultEnvironment}`
38
- }
39
- });
40
- return c;
41
- }, g = () => {
42
- if (!e.account)
43
- throw new w("GENERAL.ACCOUNT_NOT_FOUND", {
44
- context: { error: "Account not loaded" }
45
- });
46
- return { account: e.account };
47
- }, l = () => {
48
- if (!e.dappAccount)
49
- throw new w("GENERAL.SITE_KEY_MISSING");
50
- return e.dappAccount;
51
- }, a = k(e, r), I = () => {
52
- b(), T(), a(u());
53
- }, P = () => {
54
- const t = i().captchas.pow.solutionTimeout, c = setTimeout(() => {
55
- a({ isHuman: !1 }), p.onExpired();
56
- }, t);
57
- a({ successfullChallengeTimeout: c });
58
- }, W = async () => {
59
- var y;
60
- if (e.loading || e.isHuman)
61
- return;
62
- I(), a({
63
- loading: !0
64
- });
65
- const t = i(), c = t.web2 ? new Z() : new ee(), h = t.userAccountAddress || (await c.getAccount(t)).account.address;
66
- if (a({
67
- account: { account: { address: h } }
68
- }), a({ dappAccount: t.account.address }), await te(100), !t.web2 && !t.userAccountAddress)
69
- throw new w("GENERAL.ACCOUNT_NOT_FOUND", {
70
- context: { error: "Account address has not been set for web3 mode" }
71
- });
72
- const f = O(), x = _(r, e, d), A = f.provider.url, N = new ne(E(i()), A, l()), m = await N.getPowCaptchaChallenge(h, l()), R = ce(m.challenge, m.difficulty), C = (y = (await c.getAccount(i())).extension) == null ? void 0 : y.signer;
73
- if (!C || !C.signRaw)
74
- throw new w("GENERAL.CANT_FIND_KEYRINGPAIR", {
75
- context: {
76
- error: "Signer is not defined, cannot sign message to prove account ownership"
77
- }
78
- });
79
- const S = await C.signRaw({
80
- address: h,
81
- data: oe(m[o.timestamp].toString()),
82
- type: "bytes"
83
- });
84
- (await N.submitPowCaptchaSolution(m, g().account.account.address, l(), R, S.signature.toString(), t.captchas.pow.verifiedTimeout))[o.verified] && (a({
85
- isHuman: !0,
86
- loading: !1
87
- }), x.onHuman(G({
88
- [o.providerUrl]: A,
89
- [o.user]: g().account.account.address,
90
- [o.dapp]: l(),
91
- [o.challenge]: m.challenge,
92
- [o.blockNumber]: f.blockNumber,
93
- [o.nonce]: R,
94
- [o.timestamp]: m.timestamp,
95
- [o.signature]: {
96
- [o.provider]: m.signature.provider,
97
- [o.user]: {
98
- [o.timestamp]: S.signature.toString()
99
- }
100
- }
101
- })), P());
102
- }, O = () => {
103
- const t = (x, A) => Math.floor(Math.random() * (A - x + 1) + x), c = i().defaultEnvironment, h = ae(c), f = H(h, t(0, h.length - 1));
104
- return {
105
- providerAccount: f.address,
106
- provider: {
107
- url: f.url,
108
- datasetId: f.datasetId,
109
- datasetIdContent: f.datasetIdContent
110
- },
111
- blockNumber: 0
112
- };
113
- };
114
- return {
115
- start: W,
116
- resetState: I
117
- };
118
- }, he = (s) => {
119
- const e = s.config, r = e.theme === "light" ? "light" : "dark", d = s.config.theme === "light" ? z : J, p = s.callbacks || {}, [u, b] = re(v.useState, v.useRef), T = k(u, b), i = v.useRef(le(e, u, T, p)), E = v.useRef(null);
120
- return v.useEffect(() => {
121
- const g = E.current;
122
- if (!g)
123
- return;
124
- const l = g.closest("form");
125
- if (!l)
126
- return;
127
- const a = () => {
128
- i.current.resetState();
129
- };
130
- return l.addEventListener("submit", a), () => {
131
- l.removeEventListener("submit", a);
132
- };
133
- }, []), n("div", { ref: E, children: n("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: n(U, { children: n(j, { children: D("div", { style: M, "data-cy": "button-human", children: [" ", D("div", { style: {
134
- padding: B,
135
- border: F,
136
- backgroundColor: d.palette.background.default,
137
- borderColor: d.palette.grey[300],
138
- borderRadius: K,
139
- display: "flex",
140
- alignItems: "center",
141
- flexWrap: "wrap",
142
- justifyContent: "space-between",
143
- minHeight: `${V}px`,
144
- overflow: "hidden"
145
- }, children: [n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("div", { style: {
146
- display: "flex",
147
- justifyContent: "flex-start",
148
- alignItems: "center",
149
- flexWrap: "wrap"
150
- }, children: n("div", { style: {
151
- display: "flex",
152
- alignItems: "center",
153
- justifyContent: "center",
154
- flexDirection: "column",
155
- verticalAlign: "middle"
156
- }, children: n("div", { style: {
157
- display: "flex"
158
- }, children: n("div", { style: { flex: 1 }, children: u.loading ? n(X, { themeColor: r, "aria-label": "Loading spinner" }) : n(se, { checked: u.isHuman, onChange: i.current.start, themeColor: r, labelText: "I am human", "aria-label": "human checkbox" }) }) }) }) }) }), n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("a", { href: Y, target: "_blank", "aria-label": $, rel: "noreferrer", children: n("div", { style: { flex: 1 }, children: n(q, { themeColor: r, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) }) }) });
159
- };
160
- export {
161
- he as default
162
- };