@prosopo/procaptcha-bundle 2.0.1 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js +1 -4
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +1 -1
- package/dist/bundle/{ProcaptchaWidget-Bk0Iiawd.js → ProcaptchaWidget-BzBkw8-_.js} +285 -297
- package/dist/bundle/ProcaptchaWidget-nO3NsM0R.js +155 -0
- package/dist/bundle/{index-DvT5XLGE.js → index-DsnIPyZG.js} +3222 -3273
- package/dist/bundle/index.d.ts.map +1 -1
- package/dist/bundle/procaptcha.bundle.js +1 -1
- package/dist/bundle/{utils-nH-g73b2.js → utils-Cpz4o_0n.js} +4290 -3878
- package/dist/cjs/index.cjs +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -4
- package/dist/index.js.map +1 -1
- package/package.json +59 -59
- package/stats.html +1 -1
- package/vite.config.ts +26 -24
- package/dist/bundle/ProcaptchaWidget-CtdNKhRb.js +0 -166
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/
|
|
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
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
+
.readdirSync(packagesDir)
|
|
44
|
+
.filter((f) => fs.statSync(path.join(packagesDir, f)).isDirectory());
|
|
43
45
|
for (const packageName of packages) {
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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,166 +0,0 @@
|
|
|
1
|
-
import { A as o, e as O, a as H, P as L, r as v, j as n, W as U, C as j, c as M, b as y, f as B, g as F, h as K, i as V, k as X, L as Y, m as $, n as q, o as z, l as J, d as Q } from "./index-DvT5XLGE.js";
|
|
2
|
-
import { v as Z, k as _, E as ee, p as te, n as ne, f as w, o as oe, s as ae, q as re, l as k, t as se, C as ce } from "./utils-nH-g73b2.js";
|
|
3
|
-
const ie = (s, e) => {
|
|
4
|
-
let r = 0;
|
|
5
|
-
const d = "0".repeat(e);
|
|
6
|
-
for (; ; ) {
|
|
7
|
-
const p = new TextEncoder().encode(r + s);
|
|
8
|
-
if (le(Z(p)).startsWith(d))
|
|
9
|
-
return r;
|
|
10
|
-
r += 1;
|
|
11
|
-
}
|
|
12
|
-
}, le = (s) => Array.from(s).map((e) => e.toString(16).padStart(2, "0")).join(""), de = (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
|
-
}), T = () => {
|
|
23
|
-
window.clearTimeout(e.timeout), a({ timeout: void 0 });
|
|
24
|
-
}, b = () => {
|
|
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
|
-
T(), b(), 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 S;
|
|
60
|
-
if (e.loading || e.isHuman)
|
|
61
|
-
return;
|
|
62
|
-
I(), a({
|
|
63
|
-
loading: !0
|
|
64
|
-
});
|
|
65
|
-
const t = i(), c = t.web2 ? new ee() : new te(), h = t.userAccountAddress || (await c.getAccount(t)).account.address;
|
|
66
|
-
if (a({
|
|
67
|
-
account: { account: { address: h } }
|
|
68
|
-
}), a({ dappAccount: t.account.address }), await ne(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 = G(), x = _(r, e, d), A = f.provider.url, D = new oe(E(i()), A, l()), m = await D.getPowCaptchaChallenge(h, l()), N = ie(m.challenge, m.difficulty), C = (S = (await c.getAccount(i())).extension) == null ? void 0 : S.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 R = await C.signRaw({
|
|
80
|
-
address: h,
|
|
81
|
-
data: ae(m[o.timestamp].toString()),
|
|
82
|
-
type: "bytes"
|
|
83
|
-
});
|
|
84
|
-
(await D.submitPowCaptchaSolution(m, g().account.account.address, l(), N, R.signature.toString(), t.captchas.pow.verifiedTimeout))[o.verified] && (a({
|
|
85
|
-
isHuman: !0,
|
|
86
|
-
loading: !1
|
|
87
|
-
}), x.onHuman(O({
|
|
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]: N,
|
|
94
|
-
[o.timestamp]: m.timestamp,
|
|
95
|
-
[o.signature]: {
|
|
96
|
-
[o.provider]: m.signature.provider,
|
|
97
|
-
[o.user]: {
|
|
98
|
-
[o.timestamp]: R.signature.toString()
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
})), P());
|
|
102
|
-
}, G = () => {
|
|
103
|
-
const t = (x, A) => Math.floor(Math.random() * (A - x + 1) + x), c = i().defaultEnvironment, h = re(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
|
-
}, pe = (s) => {
|
|
119
|
-
const e = s.config, r = e.theme === "light" ? "light" : "dark", d = s.config.theme === "light" ? J : Q, p = s.callbacks || {}, [u, T] = se(v.useState, v.useRef), b = k(u, T), i = v.useRef(de(e, u, b, 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: {
|
|
134
|
-
maxWidth: U,
|
|
135
|
-
maxHeight: "100%",
|
|
136
|
-
overflowX: "auto"
|
|
137
|
-
}, children: n(j, { children: n(M, { children: y("div", { style: B, "data-cy": "button-human", children: [" ", y("div", { style: {
|
|
138
|
-
padding: F,
|
|
139
|
-
border: K,
|
|
140
|
-
backgroundColor: d.palette.background.default,
|
|
141
|
-
borderColor: d.palette.grey[300],
|
|
142
|
-
borderRadius: V,
|
|
143
|
-
display: "flex",
|
|
144
|
-
alignItems: "center",
|
|
145
|
-
flexWrap: "wrap",
|
|
146
|
-
justifyContent: "space-between",
|
|
147
|
-
minHeight: `${X}px`,
|
|
148
|
-
overflow: "hidden"
|
|
149
|
-
}, children: [n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("div", { style: {
|
|
150
|
-
display: "flex",
|
|
151
|
-
justifyContent: "flex-start",
|
|
152
|
-
alignItems: "center",
|
|
153
|
-
flexWrap: "wrap"
|
|
154
|
-
}, children: n("div", { style: {
|
|
155
|
-
display: "flex",
|
|
156
|
-
alignItems: "center",
|
|
157
|
-
justifyContent: "center",
|
|
158
|
-
flexDirection: "column",
|
|
159
|
-
verticalAlign: "middle"
|
|
160
|
-
}, children: n("div", { style: {
|
|
161
|
-
display: "flex"
|
|
162
|
-
}, children: n("div", { style: { flex: 1 }, children: u.loading ? n(Y, { themeColor: r, "aria-label": "Loading spinner" }) : n(ce, { 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: $, target: "_blank", "aria-label": q, rel: "noreferrer", children: n("div", { style: { flex: 1 }, children: n(z, { themeColor: r, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) }) }) });
|
|
163
|
-
};
|
|
164
|
-
export {
|
|
165
|
-
pe as default
|
|
166
|
-
};
|