@prosopo/procaptcha-bundle 1.0.2 → 2.0.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.
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts +8 -8
- 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 +128 -80
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +1 -1
- package/dist/bundle/ProcaptchaWidget-Bk0Iiawd.js +787 -0
- package/dist/bundle/ProcaptchaWidget-CtdNKhRb.js +166 -0
- package/dist/bundle/index-DvT5XLGE.js +15027 -0
- package/dist/bundle/index.d.ts +8 -8
- package/dist/bundle/index.d.ts.map +1 -1
- package/dist/bundle/procaptcha.bundle.js +2 -2
- package/dist/bundle/utils-nH-g73b2.js +12281 -0
- package/dist/cjs/index.cjs +81 -23
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +128 -80
- package/dist/index.js.map +1 -1
- package/package.json +59 -66
- package/stats.html +1 -1
- package/vite.cjs.config.ts +7 -3
- package/vite.config.ts +39 -37
- package/webpack.config.cjs +42 -0
- package/dist/bundle/Captcha-VFcjC-TM.js +0 -119
- package/dist/bundle/ProcaptchaWidget-YCG6trDR.js +0 -906
- package/dist/bundle/index-Bvarorfv.js +0 -11607
- package/dist/bundle/utils-o59wPRMZ.js +0 -35879
package/vite.cjs.config.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
// Copyright 2021-2024 Prosopo (UK) Ltd.
|
|
2
3
|
//
|
|
3
4
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
@@ -11,9 +12,12 @@
|
|
|
11
12
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
13
|
// See the License for the specific language governing permissions and
|
|
13
14
|
// limitations under the License.
|
|
14
|
-
import { ViteCommonJSConfig } from
|
|
15
|
-
import path from 'path'
|
|
15
|
+
import { ViteCommonJSConfig } from "@prosopo/config";
|
|
16
16
|
|
|
17
17
|
export default function () {
|
|
18
|
-
|
|
18
|
+
return ViteCommonJSConfig(
|
|
19
|
+
"procaptcha-bundle",
|
|
20
|
+
path.resolve("./tsconfig.cjs.json"),
|
|
21
|
+
"src/index.tsx",
|
|
22
|
+
);
|
|
19
23
|
}
|
package/vite.config.ts
CHANGED
|
@@ -11,51 +11,53 @@
|
|
|
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
|
-
import * as fs from
|
|
15
|
-
import * as path from
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
14
|
+
import * as fs from "node:fs";
|
|
15
|
+
import * as path from "node:path";
|
|
16
|
+
import { loadEnv } from "@prosopo/cli";
|
|
17
|
+
import { ViteFrontendConfig } from "@prosopo/config";
|
|
18
|
+
import { defineConfig } from "vite";
|
|
19
19
|
// load env using our util because vite loadEnv is not working for .env.development
|
|
20
|
-
loadEnv()
|
|
20
|
+
loadEnv();
|
|
21
21
|
|
|
22
22
|
// Vite doesn't find the tsconfig for some reason
|
|
23
|
-
process.env.TS_NODE_PROJECT = path.resolve(
|
|
23
|
+
process.env.TS_NODE_PROJECT = path.resolve("./tsconfig.json");
|
|
24
24
|
|
|
25
25
|
// Package specific config
|
|
26
|
-
const copyTo = [
|
|
27
|
-
const bundleName =
|
|
28
|
-
const packageName =
|
|
29
|
-
const entry =
|
|
26
|
+
const copyTo = ["../../demos/client-bundle-example/src/assets"];
|
|
27
|
+
const bundleName = "procaptcha";
|
|
28
|
+
const packageName = "@prosopo/procaptcha-bundle";
|
|
29
|
+
const entry = "./src/index.tsx";
|
|
30
30
|
const copyOptions = copyTo
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
const tsConfigPaths = [path.resolve(
|
|
37
|
-
const packagesDir = path.resolve(
|
|
38
|
-
const workspaceRoot = path.resolve(
|
|
31
|
+
? {
|
|
32
|
+
srcDir: "./dist/bundle",
|
|
33
|
+
destDir: copyTo,
|
|
34
|
+
}
|
|
35
|
+
: undefined;
|
|
36
|
+
const tsConfigPaths = [path.resolve("./tsconfig.json")];
|
|
37
|
+
const packagesDir = path.resolve("..");
|
|
38
|
+
const workspaceRoot = path.resolve("../../");
|
|
39
39
|
// Get all folders in packagesDir
|
|
40
|
-
const packages = fs
|
|
40
|
+
const packages = fs
|
|
41
|
+
.readdirSync(packagesDir)
|
|
42
|
+
.filter((f) => fs.statSync(path.join(packagesDir, f)).isDirectory());
|
|
41
43
|
for (const packageName of packages) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
+
// Add the tsconfig for each package to tsConfigPaths
|
|
45
|
+
tsConfigPaths.push(path.resolve(`../${packageName}/tsconfig.json`));
|
|
44
46
|
}
|
|
45
47
|
// Merge with generic frontend config
|
|
46
48
|
export default defineConfig(async ({ command, mode }) => {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
})
|
|
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
|
+
};
|
|
63
|
+
});
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// Copyright 2021-2024 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
|
+
const getWebpackConfig = require("@prosopo/config/webpack/webpack.config");
|
|
15
|
+
const path = require("node:path");
|
|
16
|
+
const args = process.argv.slice(2);
|
|
17
|
+
const mode =
|
|
18
|
+
args.indexOf("--mode") > -1
|
|
19
|
+
? args[args.indexOf("--mode") + 1]
|
|
20
|
+
: "development";
|
|
21
|
+
const webpackConfig = getWebpackConfig(mode);
|
|
22
|
+
const bundleWebpackConfig = {
|
|
23
|
+
...webpackConfig,
|
|
24
|
+
resolve: {
|
|
25
|
+
...webpackConfig.resolve,
|
|
26
|
+
modules: [
|
|
27
|
+
path.resolve("node_modules"),
|
|
28
|
+
path.resolve("../node_modules"),
|
|
29
|
+
path.resolve("../../node_modules"),
|
|
30
|
+
],
|
|
31
|
+
alias: {
|
|
32
|
+
"@polkadot/x-textdecoder": path.resolve(
|
|
33
|
+
"../../node_modules/@polkadot/x-textdecoder",
|
|
34
|
+
),
|
|
35
|
+
"@polkadot/x-textencoder": path.resolve(
|
|
36
|
+
"../../node_modules/@polkadot/x-textencoder",
|
|
37
|
+
),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
console.log(bundleWebpackConfig);
|
|
42
|
+
module.exports = bundleWebpackConfig;
|
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import { A as d, P as _, j as n, C as k, W as R, a as T, c as O, e as G, f as H, g as L, h as U, L as j, i as F, k as M, m as B, l as K, d as q, r as b } from "./index-Bvarorfv.js";
|
|
2
|
-
import { D as V, l as D, v as X, n as $, f as w, w as z, t as J, q as Q, p as Y, A as Z, W as ee, K as te, y as ne, C as oe, m as N, z as ae, B as re } from "./utils-o59wPRMZ.js";
|
|
3
|
-
const se = (a, t) => {
|
|
4
|
-
let o = 0;
|
|
5
|
-
const c = "0".repeat(t);
|
|
6
|
-
for (; ; ) {
|
|
7
|
-
const u = new TextEncoder().encode(o + a);
|
|
8
|
-
if (ce(V(u)).startsWith(c))
|
|
9
|
-
return o;
|
|
10
|
-
o += 1;
|
|
11
|
-
}
|
|
12
|
-
}, ce = (a) => Array.from(a).map((t) => t.toString(16).padStart(2, "0")).join(""), ie = (a, t, o, c) => {
|
|
13
|
-
const u = D(o, t, c), i = () => ({
|
|
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
|
-
}), v = () => {
|
|
23
|
-
window.clearTimeout(t.timeout), s({ timeout: void 0 });
|
|
24
|
-
}, l = () => {
|
|
25
|
-
const e = {
|
|
26
|
-
userAccountAddress: "",
|
|
27
|
-
...a
|
|
28
|
-
};
|
|
29
|
-
return _.parse(e);
|
|
30
|
-
}, f = (e) => {
|
|
31
|
-
const r = e.networks[e.defaultNetwork];
|
|
32
|
-
if (!r)
|
|
33
|
-
throw new w("DEVELOPER.NETWORK_NOT_FOUND", {
|
|
34
|
-
context: { error: `No network found for environment ${e.defaultEnvironment}` }
|
|
35
|
-
});
|
|
36
|
-
return r;
|
|
37
|
-
}, S = async () => {
|
|
38
|
-
const e = f(l()), r = await Z.create({
|
|
39
|
-
provider: new ee(e.endpoint),
|
|
40
|
-
initWasm: !1,
|
|
41
|
-
noInitWarn: !0
|
|
42
|
-
}), h = "sr25519", m = new te({ type: h, ss58Format: r.registry.chainSS58 });
|
|
43
|
-
return new ne(r, JSON.parse(oe), e.contract.address, "prosopo", 0, m.addFromAddress(l().account.address || ""));
|
|
44
|
-
}, A = () => {
|
|
45
|
-
if (!t.account)
|
|
46
|
-
throw new w("GENERAL.ACCOUNT_NOT_FOUND", { context: { error: "Account not loaded" } });
|
|
47
|
-
return t.account;
|
|
48
|
-
}, p = () => {
|
|
49
|
-
if (!t.dappAccount)
|
|
50
|
-
throw new w("GENERAL.SITE_KEY_MISSING");
|
|
51
|
-
return t.dappAccount;
|
|
52
|
-
}, s = N(t, o), I = () => {
|
|
53
|
-
v(), s(i());
|
|
54
|
-
}, P = () => {
|
|
55
|
-
const e = l().captchas.pow.solutionTimeout, r = setTimeout(() => {
|
|
56
|
-
s({ isHuman: !1 }), u.onExpired();
|
|
57
|
-
}, e);
|
|
58
|
-
s({ successfullChallengeTimeout: r });
|
|
59
|
-
};
|
|
60
|
-
return {
|
|
61
|
-
start: async () => {
|
|
62
|
-
if (t.loading || t.isHuman)
|
|
63
|
-
return;
|
|
64
|
-
I(), s({
|
|
65
|
-
loading: !0
|
|
66
|
-
});
|
|
67
|
-
const e = l(), r = new X(), h = e.userAccountAddress || (await r.getAccount(e)).account.address;
|
|
68
|
-
if (s({
|
|
69
|
-
account: { account: { address: h } }
|
|
70
|
-
}), s({ dappAccount: e.account.address }), await $(100), !e.web2 && !e.userAccountAddress)
|
|
71
|
-
throw new w("GENERAL.ACCOUNT_NOT_FOUND", {
|
|
72
|
-
context: { error: "Account address has not been set for web3 mode" }
|
|
73
|
-
});
|
|
74
|
-
const m = await S(), W = D(o, t, c), x = await z(m.query.getRandomActiveProvider, m.query)(h, p()), y = J(x.provider.url.toString()), E = new Q(f(l()), y, p()), g = await E.getPowCaptchaChallenge(h, p()), C = se(g.challenge, g.difficulty);
|
|
75
|
-
(await E.submitPowCaptchaSolution(g, A().account.address, p(), x, C, e.captchas.pow.verifiedTimeout))[d.verified] && (s({
|
|
76
|
-
isHuman: !0,
|
|
77
|
-
loading: !1
|
|
78
|
-
}), W.onHuman(Y({
|
|
79
|
-
[d.providerUrl]: y,
|
|
80
|
-
[d.user]: A().account.address,
|
|
81
|
-
[d.dapp]: p(),
|
|
82
|
-
[d.challenge]: g.challenge,
|
|
83
|
-
[d.blockNumber]: x.blockNumber,
|
|
84
|
-
[d.nonce]: C
|
|
85
|
-
})), P());
|
|
86
|
-
}
|
|
87
|
-
};
|
|
88
|
-
}, he = (a) => {
|
|
89
|
-
const t = a.config, o = t.theme === "light" ? "light" : "dark", c = a.config.theme === "light" ? K : q, u = a.callbacks || {}, [i, v] = ae(b.useState, b.useRef), l = N(i, v), f = ie(t, i, l, u);
|
|
90
|
-
return n("div", { children: n("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: n(k, { children: n(R, { children: T("div", { style: O, "data-cy": "button-human", children: [" ", T("div", { style: {
|
|
91
|
-
padding: G,
|
|
92
|
-
border: H,
|
|
93
|
-
backgroundColor: c.palette.background.default,
|
|
94
|
-
borderColor: c.palette.grey[300],
|
|
95
|
-
borderRadius: L,
|
|
96
|
-
display: "flex",
|
|
97
|
-
alignItems: "center",
|
|
98
|
-
flexWrap: "wrap",
|
|
99
|
-
justifyContent: "space-between",
|
|
100
|
-
minHeight: `${U}px`,
|
|
101
|
-
overflow: "hidden"
|
|
102
|
-
}, children: [n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("div", { style: {
|
|
103
|
-
display: "flex",
|
|
104
|
-
justifyContent: "flex-start",
|
|
105
|
-
alignItems: "center",
|
|
106
|
-
flexWrap: "wrap"
|
|
107
|
-
}, children: n("div", { style: {
|
|
108
|
-
display: "flex",
|
|
109
|
-
alignItems: "center",
|
|
110
|
-
justifyContent: "center",
|
|
111
|
-
flexDirection: "column",
|
|
112
|
-
verticalAlign: "middle"
|
|
113
|
-
}, children: n("div", { style: {
|
|
114
|
-
display: "flex"
|
|
115
|
-
}, children: n("div", { style: { flex: 1 }, children: i.loading ? n(j, { themeColor: o, "aria-label": "Loading spinner" }) : n(re, { checked: i.isHuman, onChange: f.start, themeColor: o, labelText: "I am human", "aria-label": "human checkbox" }) }) }) }) }) }), n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("a", { href: F, target: "_blank", "aria-label": M, children: n("div", { style: { flex: 1 }, children: n(B, { themeColor: o, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) }) }) });
|
|
116
|
-
};
|
|
117
|
-
export {
|
|
118
|
-
he as default
|
|
119
|
-
};
|