@prosopo/procaptcha-bundle 0.3.39 → 0.3.41
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 +91 -41
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +1 -1
- package/dist/bundle/Captcha-DV7UgvdK.js +118 -0
- package/dist/bundle/{ProcaptchaWidget-C92A5r1i.js → ProcaptchaWidget-Df9IA3Z1.js} +346 -350
- package/dist/bundle/{index-BMVIqKta.js → index-q4wiV8mV.js} +3586 -3381
- package/dist/bundle/index.d.ts +8 -8
- package/dist/bundle/index.d.ts.map +1 -1
- package/dist/bundle/procaptcha.bundle.js +1 -1
- package/dist/bundle/{utils-e8yx6vsa.js → utils-DvyeJwNo.js} +4144 -4160
- package/dist/cjs/index.cjs +77 -47
- package/dist/index.d.ts +8 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +91 -41
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/stats.html +1 -1
- package/vite.config.ts +3 -1
- package/dist/bundle/Captcha-9w2F3Wjq.js +0 -113
- package/dist/cjs/account/dist/extension/Extension.cjs +0 -5
- package/dist/cjs/account/dist/extension/ExtensionWeb2.cjs +0 -100
- package/dist/cjs/account/dist/extension/ExtensionWeb3.cjs +0 -28
- package/dist/cjs/account/dist/index.cjs +0 -8
- package/dist/cjs/procaptcha-frictionless/dist/ProcaptchaFrictionless.cjs +0 -27
- package/dist/cjs/procaptcha-frictionless/dist/index.cjs +0 -4
- package/dist/cjs/procaptcha-pow/dist/Services/Manager.cjs +0 -136
- package/dist/cjs/procaptcha-pow/dist/Services/SolverService.cjs +0 -17
- package/dist/cjs/procaptcha-pow/dist/components/Captcha.cjs +0 -48
- package/dist/cjs/procaptcha-pow/dist/components/ProcaptchaPoW.cjs +0 -10
- package/dist/cjs/procaptcha-pow/dist/index.cjs +0 -5
- package/dist/cjs/web-components/dist/CaptchaPlaceholder.cjs +0 -37
- package/dist/cjs/web-components/dist/Checkbox.cjs +0 -59
- package/dist/cjs/web-components/dist/Containers.cjs +0 -42
- package/dist/cjs/web-components/dist/LoadingSpinner.cjs +0 -34
- package/dist/cjs/web-components/dist/Logo.cjs +0 -16
- package/dist/cjs/web-components/dist/LogoWithText.cjs +0 -10
- package/dist/cjs/web-components/dist/LogoWithoutText.cjs +0 -10
- package/dist/cjs/web-components/dist/WidgetConstants.cjs +0 -18
- package/dist/cjs/web-components/dist/index.cjs +0 -25
- package/dist/cjs/web-components/dist/theme.cjs +0 -44
package/vite.config.ts
CHANGED
|
@@ -35,6 +35,7 @@ const copyOptions = copyTo
|
|
|
35
35
|
: undefined
|
|
36
36
|
const tsConfigPaths = [path.resolve('./tsconfig.json')]
|
|
37
37
|
const packagesDir = path.resolve('..')
|
|
38
|
+
const workspaceRoot = path.resolve('../../')
|
|
38
39
|
// Get all folders in packagesDir
|
|
39
40
|
const packages = fs.readdirSync(packagesDir).filter((f) => fs.statSync(path.join(packagesDir, f)).isDirectory())
|
|
40
41
|
for (const packageName of packages) {
|
|
@@ -51,7 +52,8 @@ export default defineConfig(async ({ command, mode }) => {
|
|
|
51
52
|
command,
|
|
52
53
|
mode,
|
|
53
54
|
copyOptions,
|
|
54
|
-
tsConfigPaths
|
|
55
|
+
tsConfigPaths,
|
|
56
|
+
workspaceRoot
|
|
55
57
|
)
|
|
56
58
|
return {
|
|
57
59
|
...frontendConfig,
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { A as p, P as I, j as n, C as W, W as _, a as C, c as k, e as P, f as R, g as O, i as G, L as H, k as U, m as L, n as j, l as F, d as B, r as b } from "./index-BMVIqKta.js";
|
|
2
|
-
import { B as K, u as M, p as q, h as w, m as X, w as $, t as z, q as J, A as Q, W as V, K as Y, x as Z, C as ee, n as D, y as te, z as ne } from "./utils-e8yx6vsa.js";
|
|
3
|
-
const oe = (a, e) => {
|
|
4
|
-
let o = 0;
|
|
5
|
-
const c = "0".repeat(e);
|
|
6
|
-
for (; ; ) {
|
|
7
|
-
const l = new TextEncoder().encode(o + a);
|
|
8
|
-
if (ae(K(l)).startsWith(c))
|
|
9
|
-
return o;
|
|
10
|
-
o += 1;
|
|
11
|
-
}
|
|
12
|
-
}, ae = (a) => Array.from(a).map((e) => e.toString(16).padStart(2, "0")).join(""), re = (a, e, o, c) => {
|
|
13
|
-
const l = () => ({
|
|
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
|
-
}), r = () => {
|
|
23
|
-
window.clearTimeout(e.timeout), d({ timeout: void 0 });
|
|
24
|
-
}, i = () => {
|
|
25
|
-
const t = {
|
|
26
|
-
userAccountAddress: "",
|
|
27
|
-
...a
|
|
28
|
-
};
|
|
29
|
-
return I.parse(t);
|
|
30
|
-
}, f = (t) => {
|
|
31
|
-
const s = t.networks[t.defaultNetwork];
|
|
32
|
-
if (!s)
|
|
33
|
-
throw new w("DEVELOPER.NETWORK_NOT_FOUND", {
|
|
34
|
-
context: { error: `No network found for environment ${t.defaultEnvironment}` }
|
|
35
|
-
});
|
|
36
|
-
return s;
|
|
37
|
-
}, A = async () => {
|
|
38
|
-
const t = f(i()), s = await Q.create({
|
|
39
|
-
provider: new V(t.endpoint),
|
|
40
|
-
initWasm: !1,
|
|
41
|
-
noInitWarn: !0
|
|
42
|
-
}), h = "sr25519", m = new Y({ type: h, ss58Format: s.registry.chainSS58 });
|
|
43
|
-
return new Z(s, JSON.parse(ee), t.contract.address, "prosopo", 0, m.addFromAddress(i().account.address || ""));
|
|
44
|
-
}, x = () => {
|
|
45
|
-
if (!e.account)
|
|
46
|
-
throw new w("GENERAL.ACCOUNT_NOT_FOUND", { context: { error: "Account not loaded" } });
|
|
47
|
-
return e.account;
|
|
48
|
-
}, u = () => {
|
|
49
|
-
if (!e.dappAccount)
|
|
50
|
-
throw new w("GENERAL.SITE_KEY_MISSING");
|
|
51
|
-
return e.dappAccount;
|
|
52
|
-
}, d = D(e, o), N = () => {
|
|
53
|
-
r(), d(l());
|
|
54
|
-
};
|
|
55
|
-
return {
|
|
56
|
-
start: async () => {
|
|
57
|
-
if (e.loading || e.isHuman)
|
|
58
|
-
return;
|
|
59
|
-
N(), d({
|
|
60
|
-
loading: !0
|
|
61
|
-
});
|
|
62
|
-
const t = i(), s = new M(), h = t.userAccountAddress || (await s.getAccount(t)).account.address;
|
|
63
|
-
if (d({
|
|
64
|
-
account: { account: { address: h } }
|
|
65
|
-
}), d({ dappAccount: t.account.address }), await q(100), !t.web2 && !t.userAccountAddress)
|
|
66
|
-
throw new w("GENERAL.ACCOUNT_NOT_FOUND", {
|
|
67
|
-
context: { error: "Account address has not been set for web3 mode" }
|
|
68
|
-
});
|
|
69
|
-
const m = await A(), S = X(o, e, c), v = await $(m.query.getRandomActiveProvider, m.query)(h, u()), y = z(v.provider.url.toString()), E = new J(f(i()), y, u()), g = await E.getPowCaptchaChallenge(h, u()), T = oe(g.challenge, g.difficulty);
|
|
70
|
-
(await E.submitPowCaptchaSolution(g, x().account.address, u(), v, T))[p.verified] && (d({
|
|
71
|
-
isHuman: !0,
|
|
72
|
-
loading: !1
|
|
73
|
-
}), S.onHuman({
|
|
74
|
-
providerUrl: y,
|
|
75
|
-
[p.user]: x().account.address,
|
|
76
|
-
[p.dapp]: u(),
|
|
77
|
-
[p.challenge]: g.challenge,
|
|
78
|
-
[p.blockNumber]: v.blockNumber
|
|
79
|
-
}));
|
|
80
|
-
}
|
|
81
|
-
};
|
|
82
|
-
}, le = (a) => {
|
|
83
|
-
const e = a.config, o = e.theme === "light" ? "light" : "dark", c = a.config.theme === "light" ? F : B, l = a.callbacks || {}, [r, i] = te(b.useState, b.useRef), f = D(r, i), A = re(e, r, f, l);
|
|
84
|
-
return n("div", { children: n("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: n(W, { children: n(_, { children: C("div", { style: k, "data-cy": "button-human", children: [" ", C("div", { style: {
|
|
85
|
-
padding: P,
|
|
86
|
-
border: R,
|
|
87
|
-
backgroundColor: c.palette.background.default,
|
|
88
|
-
borderColor: c.palette.grey[300],
|
|
89
|
-
borderRadius: O,
|
|
90
|
-
display: "flex",
|
|
91
|
-
alignItems: "center",
|
|
92
|
-
flexWrap: "wrap",
|
|
93
|
-
justifyContent: "space-between",
|
|
94
|
-
minHeight: `${G}px`,
|
|
95
|
-
overflow: "hidden"
|
|
96
|
-
}, children: [n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("div", { style: {
|
|
97
|
-
display: "flex",
|
|
98
|
-
justifyContent: "flex-start",
|
|
99
|
-
alignItems: "center",
|
|
100
|
-
flexWrap: "wrap"
|
|
101
|
-
}, children: n("div", { style: {
|
|
102
|
-
display: "flex",
|
|
103
|
-
alignItems: "center",
|
|
104
|
-
justifyContent: "center",
|
|
105
|
-
flexDirection: "column",
|
|
106
|
-
verticalAlign: "middle"
|
|
107
|
-
}, children: n("div", { style: {
|
|
108
|
-
display: "flex"
|
|
109
|
-
}, children: n("div", { style: { flex: 1 }, children: r.loading ? n(H, { themeColor: o }) : n(ne, { checked: r.isHuman, onChange: A.start, themeColor: o, labelText: "I am human" }) }) }) }) }) }), n("div", { style: { display: "inline-flex", flexDirection: "column" }, children: n("a", { href: U, target: "_blank", "aria-label": L, children: n("div", { style: { flex: 1 }, children: n(j, { themeColor: o }) }) }) })] })] }) }) }) }) });
|
|
110
|
-
};
|
|
111
|
-
export {
|
|
112
|
-
le as default
|
|
113
|
-
};
|
|
@@ -1,100 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const Api = require("@polkadot/api/promise/Api");
|
|
4
|
-
const Extension = require("./Extension.cjs");
|
|
5
|
-
const keyring = require("@polkadot/keyring");
|
|
6
|
-
const common = require("@prosopo/common");
|
|
7
|
-
const ws = require("@polkadot/rpc-provider/ws");
|
|
8
|
-
const address = require("@polkadot/util-crypto/address");
|
|
9
|
-
const bip39 = require("@polkadot/util-crypto/mnemonic/bip39");
|
|
10
|
-
const fingerprintjs = require("@fingerprintjs/fingerprintjs");
|
|
11
|
-
const util = require("@prosopo/util");
|
|
12
|
-
const string = require("@polkadot/util/string");
|
|
13
|
-
const u8a = require("@polkadot/util/u8a");
|
|
14
|
-
const Signer = require("@polkadot/extension-base/page/Signer");
|
|
15
|
-
class ExtensionWeb2 extends Extension.Extension {
|
|
16
|
-
constructor() {
|
|
17
|
-
super(...arguments);
|
|
18
|
-
this.getNetwork = (config) => {
|
|
19
|
-
const network = config.networks[config.defaultNetwork];
|
|
20
|
-
if (!network) {
|
|
21
|
-
throw new common.ProsopoEnvError("DEVELOPER.NETWORK_NOT_FOUND", {
|
|
22
|
-
context: { error: `No network found for environment ${config.defaultEnvironment}` }
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
return network;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
async getAccount(config) {
|
|
29
|
-
const network = this.getNetwork(config);
|
|
30
|
-
const wsProvider = new ws.WsProvider(network.endpoint);
|
|
31
|
-
const account = await this.createAccount(wsProvider);
|
|
32
|
-
const extension = await this.createExtension(account);
|
|
33
|
-
return {
|
|
34
|
-
account,
|
|
35
|
-
extension
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
async createExtension(account) {
|
|
39
|
-
const signer = new Signer(async () => {
|
|
40
|
-
return;
|
|
41
|
-
});
|
|
42
|
-
signer.signRaw = async (payload) => {
|
|
43
|
-
const signature = account.keypair.sign(payload.data);
|
|
44
|
-
return {
|
|
45
|
-
id: 1,
|
|
46
|
-
signature: u8a.u8aToHex(signature)
|
|
47
|
-
};
|
|
48
|
-
};
|
|
49
|
-
return {
|
|
50
|
-
accounts: {
|
|
51
|
-
get: async () => {
|
|
52
|
-
return [account];
|
|
53
|
-
},
|
|
54
|
-
subscribe: () => {
|
|
55
|
-
return () => {
|
|
56
|
-
return;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
name: "procaptcha-web2",
|
|
61
|
-
version: util.version,
|
|
62
|
-
signer
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
async createAccount(wsProvider) {
|
|
66
|
-
const params = {
|
|
67
|
-
area: { width: 300, height: 300 },
|
|
68
|
-
offsetParameter: 2001000001,
|
|
69
|
-
multiplier: 15e3,
|
|
70
|
-
fontSizeFactor: 1.5,
|
|
71
|
-
maxShadowBlur: 50,
|
|
72
|
-
numberOfRounds: 5,
|
|
73
|
-
seed: 42
|
|
74
|
-
};
|
|
75
|
-
const browserEntropy = await this.getFingerprint();
|
|
76
|
-
const canvasEntropy = util.picassoCanvas(params.numberOfRounds, params.seed, params);
|
|
77
|
-
const entropy = common.hexHash([canvasEntropy, browserEntropy].join(""), 128).slice(2);
|
|
78
|
-
const u8Entropy = string.stringToU8a(entropy);
|
|
79
|
-
const mnemonic = bip39.entropyToMnemonic(u8Entropy);
|
|
80
|
-
const api = await Api.ApiPromise.create({ provider: wsProvider, initWasm: false, noInitWarn: true });
|
|
81
|
-
const type = "ed25519";
|
|
82
|
-
const keyring$1 = new keyring.Keyring({ type, ss58Format: api.registry.chainSS58 });
|
|
83
|
-
const keypair = keyring$1.addFromMnemonic(mnemonic);
|
|
84
|
-
const address$1 = keypair.address.length === 42 ? keypair.address : address.encodeAddress(address.decodeAddress(keypair.address), api.registry.chainSS58);
|
|
85
|
-
return {
|
|
86
|
-
address: address$1,
|
|
87
|
-
type,
|
|
88
|
-
name: address$1,
|
|
89
|
-
keypair
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
async getFingerprint() {
|
|
93
|
-
const fpPromise = fingerprintjs.load();
|
|
94
|
-
const fp = await fpPromise;
|
|
95
|
-
const result = await fp.get();
|
|
96
|
-
const { screenFrame, ...componentsReduced } = result.components;
|
|
97
|
-
return fingerprintjs.hashComponents(componentsReduced);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
exports.ExtensionWeb2 = ExtensionWeb2;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const Extension = require("./Extension.cjs");
|
|
4
|
-
const common = require("@prosopo/common");
|
|
5
|
-
const extensionDapp = require("@polkadot/extension-dapp");
|
|
6
|
-
class ExtensionWeb3 extends Extension.Extension {
|
|
7
|
-
async getAccount(config) {
|
|
8
|
-
const { dappName, userAccountAddress: address } = config;
|
|
9
|
-
if (!address) {
|
|
10
|
-
throw new common.ProsopoError("WIDGET.NO_ACCOUNTS_FOUND", { context: { error: "No account address provided" } });
|
|
11
|
-
}
|
|
12
|
-
const extensions = await extensionDapp.web3Enable(dappName);
|
|
13
|
-
if (extensions.length === 0) {
|
|
14
|
-
throw new common.ProsopoError("WIDGET.NO_EXTENSION_FOUND");
|
|
15
|
-
}
|
|
16
|
-
for (const extension of extensions) {
|
|
17
|
-
const accounts = await extension.accounts.get();
|
|
18
|
-
const account = accounts.find((account2) => account2.address === address);
|
|
19
|
-
if (account) {
|
|
20
|
-
return { account, extension };
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
throw new common.ProsopoError("WIDGET.ACCOUNT_NOT_FOUND", {
|
|
24
|
-
context: { error: `No account found matching ${address}` }
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
exports.ExtensionWeb3 = ExtensionWeb3;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const Extension = require("./extension/Extension.cjs");
|
|
4
|
-
const ExtensionWeb2 = require("./extension/ExtensionWeb2.cjs");
|
|
5
|
-
const ExtensionWeb3 = require("./extension/ExtensionWeb3.cjs");
|
|
6
|
-
exports.Extension = Extension.Extension;
|
|
7
|
-
exports.ExtensionWeb2 = ExtensionWeb2.ExtensionWeb2;
|
|
8
|
-
exports.ExtensionWeb3 = ExtensionWeb3.ExtensionWeb3;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("react/jsx-runtime");
|
|
4
|
-
const procaptchaReact = require("@prosopo/procaptcha-react");
|
|
5
|
-
require("../../web-components/dist/index.cjs");
|
|
6
|
-
require("../../procaptcha-pow/dist/index.cjs");
|
|
7
|
-
const botd = require("@fingerprintjs/botd");
|
|
8
|
-
const react = require("react");
|
|
9
|
-
const CaptchaPlaceholder = require("../../web-components/dist/CaptchaPlaceholder.cjs");
|
|
10
|
-
const ProcaptchaPoW = require("../../procaptcha-pow/dist/components/ProcaptchaPoW.cjs");
|
|
11
|
-
const ProcaptchaFrictionless = ({ config, callbacks }) => {
|
|
12
|
-
const [componentToRender, setComponentToRender] = react.useState(jsxRuntime.jsx(CaptchaPlaceholder.ProcaptchaPlaceholder, { darkMode: config.theme }));
|
|
13
|
-
react.useEffect(() => {
|
|
14
|
-
const detectBot = async () => {
|
|
15
|
-
const botd$1 = await botd.load();
|
|
16
|
-
const result = botd$1.detect();
|
|
17
|
-
if (result.bot) {
|
|
18
|
-
setComponentToRender(jsxRuntime.jsx(procaptchaReact.Procaptcha, { config, callbacks }));
|
|
19
|
-
} else {
|
|
20
|
-
setComponentToRender(jsxRuntime.jsx(ProcaptchaPoW.ProcaptchaPow, { config, callbacks }));
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
detectBot();
|
|
24
|
-
}, [config, callbacks]);
|
|
25
|
-
return componentToRender;
|
|
26
|
-
};
|
|
27
|
-
exports.ProcaptchaFrictionless = ProcaptchaFrictionless;
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const types = require("@prosopo/types");
|
|
4
|
-
const Api = require("@polkadot/api/promise/Api");
|
|
5
|
-
require("../../../account/dist/index.cjs");
|
|
6
|
-
const keyring = require("@polkadot/keyring");
|
|
7
|
-
const contract = require("@prosopo/contract");
|
|
8
|
-
const common = require("@prosopo/common");
|
|
9
|
-
const api = require("@prosopo/api");
|
|
10
|
-
const ws = require("@polkadot/rpc-provider/ws");
|
|
11
|
-
const contractInfo = require("@prosopo/captcha-contract/contract-info");
|
|
12
|
-
const procaptchaCommon = require("@prosopo/procaptcha-common");
|
|
13
|
-
const procaptcha = require("@prosopo/procaptcha");
|
|
14
|
-
const SolverService = require("./SolverService.cjs");
|
|
15
|
-
const ExtensionWeb2 = require("../../../account/dist/extension/ExtensionWeb2.cjs");
|
|
16
|
-
const Manager = (configInput, state, onStateUpdate, callbacks) => {
|
|
17
|
-
const defaultState = () => {
|
|
18
|
-
return {
|
|
19
|
-
showModal: false,
|
|
20
|
-
loading: false,
|
|
21
|
-
index: 0,
|
|
22
|
-
challenge: void 0,
|
|
23
|
-
solutions: void 0,
|
|
24
|
-
isHuman: false,
|
|
25
|
-
captchaApi: void 0,
|
|
26
|
-
account: void 0
|
|
27
|
-
};
|
|
28
|
-
};
|
|
29
|
-
const clearTimeout = () => {
|
|
30
|
-
window.clearTimeout(state.timeout);
|
|
31
|
-
updateState({ timeout: void 0 });
|
|
32
|
-
};
|
|
33
|
-
const getConfig = () => {
|
|
34
|
-
const config = {
|
|
35
|
-
userAccountAddress: "",
|
|
36
|
-
...configInput
|
|
37
|
-
};
|
|
38
|
-
return types.ProcaptchaConfigSchema.parse(config);
|
|
39
|
-
};
|
|
40
|
-
const getNetwork = (config) => {
|
|
41
|
-
const network = config.networks[config.defaultNetwork];
|
|
42
|
-
if (!network) {
|
|
43
|
-
throw new common.ProsopoEnvError("DEVELOPER.NETWORK_NOT_FOUND", {
|
|
44
|
-
context: { error: `No network found for environment ${config.defaultEnvironment}` }
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
return network;
|
|
48
|
-
};
|
|
49
|
-
const loadContract = async () => {
|
|
50
|
-
const network = getNetwork(getConfig());
|
|
51
|
-
const api2 = await Api.ApiPromise.create({
|
|
52
|
-
provider: new ws.WsProvider(network.endpoint),
|
|
53
|
-
initWasm: false,
|
|
54
|
-
noInitWarn: true
|
|
55
|
-
});
|
|
56
|
-
const type = "sr25519";
|
|
57
|
-
const keyring$1 = new keyring.Keyring({ type, ss58Format: api2.registry.chainSS58 });
|
|
58
|
-
return new contract.ProsopoCaptchaContract(api2, JSON.parse(contractInfo.ContractAbi), network.contract.address, "prosopo", 0, keyring$1.addFromAddress(getConfig().account.address || ""));
|
|
59
|
-
};
|
|
60
|
-
const getAccount = () => {
|
|
61
|
-
if (!state.account) {
|
|
62
|
-
throw new common.ProsopoEnvError("GENERAL.ACCOUNT_NOT_FOUND", { context: { error: "Account not loaded" } });
|
|
63
|
-
}
|
|
64
|
-
const account = state.account;
|
|
65
|
-
return account;
|
|
66
|
-
};
|
|
67
|
-
const getDappAccount = () => {
|
|
68
|
-
if (!state.dappAccount) {
|
|
69
|
-
throw new common.ProsopoEnvError("GENERAL.SITE_KEY_MISSING");
|
|
70
|
-
}
|
|
71
|
-
const dappAccount = state.dappAccount;
|
|
72
|
-
return dappAccount;
|
|
73
|
-
};
|
|
74
|
-
const getBlockNumber = () => {
|
|
75
|
-
if (!state.blockNumber) {
|
|
76
|
-
throw new common.ProsopoContractError("CAPTCHA.INVALID_BLOCK_NO", { context: { error: "Block number not found" } });
|
|
77
|
-
}
|
|
78
|
-
const blockNumber = state.blockNumber;
|
|
79
|
-
return blockNumber;
|
|
80
|
-
};
|
|
81
|
-
const updateState = procaptchaCommon.buildUpdateState(state, onStateUpdate);
|
|
82
|
-
const resetState = () => {
|
|
83
|
-
clearTimeout();
|
|
84
|
-
updateState(defaultState());
|
|
85
|
-
};
|
|
86
|
-
const start = async () => {
|
|
87
|
-
if (state.loading) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
if (state.isHuman) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
resetState();
|
|
94
|
-
updateState({
|
|
95
|
-
loading: true
|
|
96
|
-
});
|
|
97
|
-
const config = getConfig();
|
|
98
|
-
const ext = new ExtensionWeb2.ExtensionWeb2();
|
|
99
|
-
const userAccount = config.userAccountAddress || (await ext.getAccount(config)).account.address;
|
|
100
|
-
updateState({
|
|
101
|
-
account: { account: { address: userAccount } }
|
|
102
|
-
});
|
|
103
|
-
updateState({ dappAccount: config.account.address });
|
|
104
|
-
await procaptcha.sleep(100);
|
|
105
|
-
if (!config.web2 && !config.userAccountAddress) {
|
|
106
|
-
throw new common.ProsopoEnvError("GENERAL.ACCOUNT_NOT_FOUND", {
|
|
107
|
-
context: { error: "Account address has not been set for web3 mode" }
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
const contract$1 = await loadContract();
|
|
111
|
-
const events = procaptchaCommon.getDefaultEvents(onStateUpdate, state, callbacks);
|
|
112
|
-
const getRandomProviderResponse = await contract.wrapQuery(contract$1.query.getRandomActiveProvider, contract$1.query)(userAccount, getDappAccount());
|
|
113
|
-
const providerUrl = common.trimProviderUrl(getRandomProviderResponse.provider.url.toString());
|
|
114
|
-
const providerApi = new api.ProviderApi(getNetwork(getConfig()), providerUrl, getDappAccount());
|
|
115
|
-
const challenge = await providerApi.getPowCaptchaChallenge(userAccount, getDappAccount());
|
|
116
|
-
const solution = SolverService.solvePoW(challenge.challenge, challenge.difficulty);
|
|
117
|
-
const verifiedSolution = await providerApi.submitPowCaptchaSolution(challenge, getAccount().account.address, getDappAccount(), getRandomProviderResponse, solution);
|
|
118
|
-
if (verifiedSolution[types.ApiParams.verified]) {
|
|
119
|
-
updateState({
|
|
120
|
-
isHuman: true,
|
|
121
|
-
loading: false
|
|
122
|
-
});
|
|
123
|
-
events.onHuman({
|
|
124
|
-
providerUrl,
|
|
125
|
-
[types.ApiParams.user]: getAccount().account.address,
|
|
126
|
-
[types.ApiParams.dapp]: getDappAccount(),
|
|
127
|
-
[types.ApiParams.challenge]: challenge.challenge,
|
|
128
|
-
[types.ApiParams.blockNumber]: getRandomProviderResponse.blockNumber
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
};
|
|
132
|
-
return {
|
|
133
|
-
start
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
exports.Manager = Manager;
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const sha256 = require("@noble/hashes/sha256");
|
|
4
|
-
const solvePoW = (data, difficulty) => {
|
|
5
|
-
let nonce = 0;
|
|
6
|
-
const prefix = "0".repeat(difficulty);
|
|
7
|
-
while (true) {
|
|
8
|
-
const message = new TextEncoder().encode(nonce + data);
|
|
9
|
-
const hashHex = bufferToHex(sha256.sha256(message));
|
|
10
|
-
if (hashHex.startsWith(prefix)) {
|
|
11
|
-
return nonce;
|
|
12
|
-
}
|
|
13
|
-
nonce += 1;
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const bufferToHex = (buffer) => Array.from(buffer).map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
17
|
-
exports.solvePoW = solvePoW;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
3
|
-
require("../../../web-components/dist/index.cjs");
|
|
4
|
-
const Manager = require("../Services/Manager.cjs");
|
|
5
|
-
const procaptchaCommon = require("@prosopo/procaptcha-common");
|
|
6
|
-
const react = require("react");
|
|
7
|
-
const theme = require("../../../web-components/dist/theme.cjs");
|
|
8
|
-
const Containers = require("../../../web-components/dist/Containers.cjs");
|
|
9
|
-
const WidgetConstants = require("../../../web-components/dist/WidgetConstants.cjs");
|
|
10
|
-
const LoadingSpinner = require("../../../web-components/dist/LoadingSpinner.cjs");
|
|
11
|
-
const Checkbox = require("../../../web-components/dist/Checkbox.cjs");
|
|
12
|
-
const Logo = require("../../../web-components/dist/Logo.cjs");
|
|
13
|
-
const Procaptcha = (props) => {
|
|
14
|
-
const config = props.config;
|
|
15
|
-
const themeColor = config.theme === "light" ? "light" : "dark";
|
|
16
|
-
const theme$1 = props.config.theme === "light" ? theme.lightTheme : theme.darkTheme;
|
|
17
|
-
const callbacks = props.callbacks || {};
|
|
18
|
-
const [state, _updateState] = procaptchaCommon.useProcaptcha(react.useState, react.useRef);
|
|
19
|
-
const updateState = procaptchaCommon.buildUpdateState(state, _updateState);
|
|
20
|
-
const manager = Manager.Manager(config, state, updateState, callbacks);
|
|
21
|
-
return jsxRuntime.jsx("div", { children: jsxRuntime.jsx("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: jsxRuntime.jsx(Containers.ContainerDiv, { children: jsxRuntime.jsx(Containers.WidthBasedStylesDiv, { children: jsxRuntime.jsxs("div", { style: WidgetConstants.WIDGET_DIMENSIONS, "data-cy": "button-human", children: [" ", jsxRuntime.jsxs("div", { style: {
|
|
22
|
-
padding: WidgetConstants.WIDGET_PADDING,
|
|
23
|
-
border: WidgetConstants.WIDGET_BORDER,
|
|
24
|
-
backgroundColor: theme$1.palette.background.default,
|
|
25
|
-
borderColor: theme$1.palette.grey[300],
|
|
26
|
-
borderRadius: WidgetConstants.WIDGET_BORDER_RADIUS,
|
|
27
|
-
display: "flex",
|
|
28
|
-
alignItems: "center",
|
|
29
|
-
flexWrap: "wrap",
|
|
30
|
-
justifyContent: "space-between",
|
|
31
|
-
minHeight: `${WidgetConstants.WIDGET_INNER_HEIGHT}px`,
|
|
32
|
-
overflow: "hidden"
|
|
33
|
-
}, children: [jsxRuntime.jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: jsxRuntime.jsx("div", { style: {
|
|
34
|
-
display: "flex",
|
|
35
|
-
justifyContent: "flex-start",
|
|
36
|
-
alignItems: "center",
|
|
37
|
-
flexWrap: "wrap"
|
|
38
|
-
}, children: jsxRuntime.jsx("div", { style: {
|
|
39
|
-
display: "flex",
|
|
40
|
-
alignItems: "center",
|
|
41
|
-
justifyContent: "center",
|
|
42
|
-
flexDirection: "column",
|
|
43
|
-
verticalAlign: "middle"
|
|
44
|
-
}, children: jsxRuntime.jsx("div", { style: {
|
|
45
|
-
display: "flex"
|
|
46
|
-
}, children: jsxRuntime.jsx("div", { style: { flex: 1 }, children: state.loading ? jsxRuntime.jsx(LoadingSpinner.LoadingSpinner, { themeColor }) : jsxRuntime.jsx(Checkbox.Checkbox, { checked: state.isHuman, onChange: manager.start, themeColor, labelText: "I am human" }) }) }) }) }) }), jsxRuntime.jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: jsxRuntime.jsx("a", { href: WidgetConstants.WIDGET_URL, target: "_blank", "aria-label": WidgetConstants.WIDGET_URL_TEXT, children: jsxRuntime.jsx("div", { style: { flex: 1 }, children: jsxRuntime.jsx(Logo, { themeColor }) }) }) })] })] }) }) }) }) });
|
|
47
|
-
};
|
|
48
|
-
module.exports = Procaptcha;
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
-
const react = require("react");
|
|
5
|
-
require("../../../web-components/dist/index.cjs");
|
|
6
|
-
const CaptchaPlaceholder = require("../../../web-components/dist/CaptchaPlaceholder.cjs");
|
|
7
|
-
const _interopNamespaceDefaultOnly = (e) => Object.freeze(Object.defineProperty({ __proto__: null, default: e }, Symbol.toStringTag, { value: "Module" }));
|
|
8
|
-
const ProcaptchaWidget = react.lazy(async () => Promise.resolve().then(() => /* @__PURE__ */ _interopNamespaceDefaultOnly(require("./Captcha.cjs"))));
|
|
9
|
-
const ProcaptchaPow = (props) => jsxRuntime.jsx(react.Suspense, { fallback: jsxRuntime.jsx(CaptchaPlaceholder.ProcaptchaPlaceholder, { darkMode: props.config.theme }), children: jsxRuntime.jsx(ProcaptchaWidget, { config: props.config, callbacks: props.callbacks }) });
|
|
10
|
-
exports.ProcaptchaPow = ProcaptchaPow;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
-
const Containers = require("./Containers.cjs");
|
|
5
|
-
const LoadingSpinner = require("./LoadingSpinner.cjs");
|
|
6
|
-
const WidgetConstants = require("./WidgetConstants.cjs");
|
|
7
|
-
const theme = require("./theme.cjs");
|
|
8
|
-
const Logo = require("./Logo.cjs");
|
|
9
|
-
const ProcaptchaPlaceholder = (props) => {
|
|
10
|
-
const themeColor = props.darkMode === "light" ? "light" : "dark";
|
|
11
|
-
const theme$1 = props.darkMode === "light" ? theme.lightTheme : theme.darkTheme;
|
|
12
|
-
return jsxRuntime.jsx("div", { children: jsxRuntime.jsx("div", { style: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: jsxRuntime.jsx(Containers.ContainerDiv, { children: jsxRuntime.jsx(Containers.WidthBasedStylesDiv, { children: jsxRuntime.jsxs("div", { style: WidgetConstants.WIDGET_DIMENSIONS, "data-cy": "button-human", children: [" ", jsxRuntime.jsxs("div", { style: {
|
|
13
|
-
padding: WidgetConstants.WIDGET_PADDING,
|
|
14
|
-
border: WidgetConstants.WIDGET_BORDER,
|
|
15
|
-
backgroundColor: theme$1.palette.background.default,
|
|
16
|
-
borderColor: theme$1.palette.grey[300],
|
|
17
|
-
borderRadius: WidgetConstants.WIDGET_BORDER_RADIUS,
|
|
18
|
-
display: "flex",
|
|
19
|
-
alignItems: "center",
|
|
20
|
-
flexWrap: "wrap",
|
|
21
|
-
justifyContent: "space-between",
|
|
22
|
-
minHeight: `${WidgetConstants.WIDGET_INNER_HEIGHT}px`,
|
|
23
|
-
overflow: "hidden"
|
|
24
|
-
}, children: [jsxRuntime.jsx("div", { style: { display: "flex", flexDirection: "column" }, children: jsxRuntime.jsx("div", { style: {
|
|
25
|
-
alignItems: "center",
|
|
26
|
-
flex: 1
|
|
27
|
-
}, children: jsxRuntime.jsx("div", { style: {
|
|
28
|
-
display: "flex",
|
|
29
|
-
alignItems: "center",
|
|
30
|
-
justifyContent: "center",
|
|
31
|
-
flexDirection: "column",
|
|
32
|
-
verticalAlign: "middle"
|
|
33
|
-
}, children: jsxRuntime.jsx("div", { style: {
|
|
34
|
-
display: "flex"
|
|
35
|
-
}, children: jsxRuntime.jsx("div", { style: { display: "inline-flex" }, children: jsxRuntime.jsx(LoadingSpinner.LoadingSpinner, { themeColor }) }) }) }) }) }), jsxRuntime.jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: jsxRuntime.jsx("a", { href: WidgetConstants.WIDGET_URL, target: "_blank", "aria-label": WidgetConstants.WIDGET_URL_TEXT, children: jsxRuntime.jsx("div", { style: { flex: 1 }, children: jsxRuntime.jsx(Logo, { themeColor }) }) }) })] })] }) }) }) }) });
|
|
36
|
-
};
|
|
37
|
-
exports.ProcaptchaPlaceholder = ProcaptchaPlaceholder;
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
-
const react = require("@emotion/react");
|
|
5
|
-
const theme = require("./theme.cjs");
|
|
6
|
-
const react$1 = require("react");
|
|
7
|
-
const checkboxBefore = react.css`{
|
|
8
|
-
&:before {
|
|
9
|
-
content: '""';
|
|
10
|
-
position: absolute;
|
|
11
|
-
height: 100%;
|
|
12
|
-
width: 100%;
|
|
13
|
-
}
|
|
14
|
-
}`;
|
|
15
|
-
const baseStyle = {
|
|
16
|
-
width: "28px",
|
|
17
|
-
height: "28px",
|
|
18
|
-
top: "auto",
|
|
19
|
-
left: "auto",
|
|
20
|
-
opacity: "1",
|
|
21
|
-
borderRadius: "12.5%",
|
|
22
|
-
appearance: "none",
|
|
23
|
-
cursor: "pointer",
|
|
24
|
-
margin: "0",
|
|
25
|
-
borderStyle: "solid",
|
|
26
|
-
borderWidth: "1px"
|
|
27
|
-
};
|
|
28
|
-
const ID_LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
29
|
-
const generateRandomId = () => {
|
|
30
|
-
return Array.from({ length: 8 }, () => ID_LETTERS[Math.floor(Math.random() * ID_LETTERS.length)]).join("");
|
|
31
|
-
};
|
|
32
|
-
const Checkbox = ({ themeColor, onChange, checked, labelText }) => {
|
|
33
|
-
const theme$1 = react$1.useMemo(() => themeColor === "light" ? theme.lightTheme : theme.darkTheme, [themeColor]);
|
|
34
|
-
const checkboxStyleBase = {
|
|
35
|
-
...baseStyle,
|
|
36
|
-
border: `1px solid ${theme$1.palette.background.contrastText}`
|
|
37
|
-
};
|
|
38
|
-
const [hover, setHover] = react$1.useState(false);
|
|
39
|
-
const checkboxStyle = react$1.useMemo(() => {
|
|
40
|
-
return {
|
|
41
|
-
...checkboxStyleBase,
|
|
42
|
-
borderColor: hover ? theme$1.palette.background.contrastText : theme$1.palette.grey[400],
|
|
43
|
-
appearance: checked ? "auto" : "none",
|
|
44
|
-
flex: 1,
|
|
45
|
-
margin: "15px"
|
|
46
|
-
};
|
|
47
|
-
}, [hover, theme$1, checked]);
|
|
48
|
-
const id = generateRandomId();
|
|
49
|
-
return jsxRuntime.jsxs("span", { style: { display: "inline-flex" }, children: [jsxRuntime.jsx("input", { name: id, id, onMouseEnter: () => setHover(true), onMouseLeave: () => setHover(false), css: checkboxBefore, type: "checkbox", "aria-live": "assertive", "aria-haspopup": "true", onChange, checked, style: checkboxStyle }), jsxRuntime.jsx("label", { css: {
|
|
50
|
-
color: theme$1.palette.background.contrastText,
|
|
51
|
-
position: "relative",
|
|
52
|
-
display: "flex",
|
|
53
|
-
cursor: "pointer",
|
|
54
|
-
userSelect: "none",
|
|
55
|
-
top: "18px"
|
|
56
|
-
}, htmlFor: id, children: labelText })] });
|
|
57
|
-
};
|
|
58
|
-
exports.Checkbox = Checkbox;
|
|
59
|
-
exports.default = Checkbox;
|