@prosopo/procaptcha-bundle 0.2.41 → 0.3.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/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.d.ts +2 -0
- 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 +26 -8
- package/.rollup.cache/home/runner/work/captcha/captcha/packages/procaptcha-bundle/dist/bundle/index.js.map +1 -1
- package/README.md +0 -0
- package/dist/bundle/Captcha-ymSK23DO.js +73 -0
- package/dist/bundle/ProcaptchaWidget-a74LJVtB.js +940 -0
- package/dist/bundle/index-D_tmH38V.js +11460 -0
- package/dist/bundle/index.d.ts +2 -0
- package/dist/bundle/index.d.ts.map +1 -1
- package/dist/bundle/{ProcaptchaWidget-6ed20c17.js → interface-B2_ap_kR.js} +12711 -13891
- package/dist/bundle/procaptcha.bundle.js +1 -1
- package/dist/cjs/account/dist/extension/Extension.cjs +5 -0
- package/dist/cjs/account/dist/extension/ExtensionWeb2.cjs +100 -0
- package/dist/cjs/account/dist/extension/ExtensionWeb3.cjs +28 -0
- package/dist/cjs/account/dist/index.cjs +8 -0
- package/dist/cjs/index.cjs +35 -17
- package/dist/cjs/procaptcha-frictionless/dist/ProcaptchaFrictionless.cjs +27 -0
- package/dist/cjs/procaptcha-frictionless/dist/index.cjs +4 -0
- package/dist/cjs/procaptcha-pow/dist/Services/Manager.cjs +59 -0
- package/dist/cjs/procaptcha-pow/dist/Services/SolverService.cjs +17 -0
- package/dist/cjs/procaptcha-pow/dist/components/Captcha.cjs +55 -0
- package/dist/cjs/procaptcha-pow/dist/components/ProcaptchaPoW.cjs +10 -0
- package/dist/cjs/procaptcha-pow/dist/index.cjs +5 -0
- package/dist/cjs/web-components/dist/CaptchaPlaceholder.cjs +39 -0
- package/dist/cjs/web-components/dist/Checkbox.cjs +55 -0
- package/dist/cjs/web-components/dist/Containers.cjs +42 -0
- package/dist/cjs/web-components/dist/LoadingSpinner.cjs +34 -0
- package/dist/cjs/web-components/dist/Logo.cjs +16 -0
- package/dist/cjs/web-components/dist/LogoWithText.cjs +10 -0
- package/dist/cjs/web-components/dist/LogoWithoutText.cjs +10 -0
- package/dist/cjs/web-components/dist/WidgetConstants.cjs +12 -0
- package/dist/cjs/web-components/dist/index.cjs +22 -0
- package/dist/cjs/web-components/dist/theme.cjs +44 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -8
- package/dist/index.js.map +1 -1
- package/package.json +8 -6
- package/stats.html +1 -1
- package/typedoc.config.js +19 -0
- package/vite.cjs.config.ts +13 -0
- package/vite.config.ts +14 -1
- package/dist/bundle/index-28b478c4.js +0 -10562
|
@@ -0,0 +1,100 @@
|
|
|
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: "0.1.11",
|
|
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 });
|
|
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;
|
|
@@ -0,0 +1,28 @@
|
|
|
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;
|
|
@@ -0,0 +1,8 @@
|
|
|
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;
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var _a;
|
|
3
2
|
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
4
3
|
const jsxRuntime = require("react/jsx-runtime");
|
|
5
4
|
const types = require("@prosopo/types");
|
|
6
5
|
const procaptchaReact = require("@prosopo/procaptcha-react");
|
|
6
|
+
require("./procaptcha-frictionless/dist/index.cjs");
|
|
7
|
+
require("./procaptcha-pow/dist/index.cjs");
|
|
7
8
|
const util = require("@prosopo/util");
|
|
8
9
|
const client = require("react-dom/client");
|
|
10
|
+
const ProcaptchaFrictionless = require("./procaptcha-frictionless/dist/ProcaptchaFrictionless.cjs");
|
|
11
|
+
const ProcaptchaPoW = require("./procaptcha-pow/dist/components/ProcaptchaPoW.cjs");
|
|
9
12
|
const BUNDLE_NAME = "procaptcha.bundle.js";
|
|
10
13
|
const getProcaptchaScript = () => document.querySelector(`script[src*="${BUNDLE_NAME}"]`);
|
|
11
14
|
const extractParams = (name) => {
|
|
@@ -31,7 +34,8 @@ const getConfig = (siteKey) => {
|
|
|
31
34
|
address: siteKey
|
|
32
35
|
},
|
|
33
36
|
serverUrl: process.env.PROSOPO_SERVER_URL || "",
|
|
34
|
-
mongoAtlasUri: process.env.
|
|
37
|
+
mongoAtlasUri: process.env.PROSOPO_MONGO_EVENTS_URI || "",
|
|
38
|
+
devOnlyWatchEvents: process.env._DEV_ONLY_WATCH_EVENTS === "true" || false
|
|
35
39
|
});
|
|
36
40
|
};
|
|
37
41
|
const getParentForm = (element) => element.closest("form");
|
|
@@ -58,12 +62,12 @@ const customThemeSet = /* @__PURE__ */ new Set(["light", "dark"]);
|
|
|
58
62
|
const validateTheme = (themeAttribute) => customThemeSet.has(themeAttribute) ? themeAttribute : "light";
|
|
59
63
|
const renderLogic = (elements, config, renderOptions) => {
|
|
60
64
|
elements.forEach((element) => {
|
|
61
|
-
const callbackName =
|
|
62
|
-
const chalExpiredCallbackName =
|
|
63
|
-
const errorCallback =
|
|
64
|
-
const onCloseCallbackName =
|
|
65
|
-
const onOpenCallbackName =
|
|
66
|
-
const onExpiredCallbackName =
|
|
65
|
+
const callbackName = renderOptions?.callback || element.getAttribute("data-callback");
|
|
66
|
+
const chalExpiredCallbackName = renderOptions?.["chalexpired-callback"] || element.getAttribute("data-chalexpired-callback");
|
|
67
|
+
const errorCallback = renderOptions?.["error-callback"] || element.getAttribute("data-error-callback");
|
|
68
|
+
const onCloseCallbackName = renderOptions?.["close-callback"] || element.getAttribute("data-close-callback");
|
|
69
|
+
const onOpenCallbackName = renderOptions?.["open-callback"] || element.getAttribute("data-open-callback");
|
|
70
|
+
const onExpiredCallbackName = renderOptions?.["expired-callback"] || element.getAttribute("data-expired-callback");
|
|
67
71
|
const callbacks = {
|
|
68
72
|
onHuman: (payload) => handleOnHuman(element, payload),
|
|
69
73
|
onChallengeExpired: () => {
|
|
@@ -94,32 +98,46 @@ const renderLogic = (elements, config, renderOptions) => {
|
|
|
94
98
|
callbacks.onClose = getWindowCallback(onCloseCallbackName);
|
|
95
99
|
if (onOpenCallbackName)
|
|
96
100
|
callbacks.onOpen = getWindowCallback(onOpenCallbackName);
|
|
97
|
-
const themeAttribute =
|
|
101
|
+
const themeAttribute = renderOptions?.theme || element.getAttribute("data-theme") || "light";
|
|
98
102
|
config.theme = validateTheme(themeAttribute);
|
|
99
|
-
const challengeValidLengthAttribute =
|
|
103
|
+
const challengeValidLengthAttribute = renderOptions?.["challenge-valid-length"] || element.getAttribute("data-challenge-valid-length");
|
|
100
104
|
if (challengeValidLengthAttribute) {
|
|
101
105
|
config.challengeValidLength = parseInt(challengeValidLengthAttribute);
|
|
102
106
|
}
|
|
103
|
-
|
|
107
|
+
switch (renderOptions?.captchaType) {
|
|
108
|
+
case "pow":
|
|
109
|
+
client.createRoot(element).render(/* @__PURE__ */ jsxRuntime.jsx(ProcaptchaPoW.ProcaptchaPow, { config, callbacks }));
|
|
110
|
+
break;
|
|
111
|
+
case "frictionless":
|
|
112
|
+
client.createRoot(element).render(/* @__PURE__ */ jsxRuntime.jsx(ProcaptchaFrictionless.ProcaptchaFrictionless, { config, callbacks }));
|
|
113
|
+
break;
|
|
114
|
+
default:
|
|
115
|
+
client.createRoot(element).render(/* @__PURE__ */ jsxRuntime.jsx(procaptchaReact.Procaptcha, { config, callbacks }));
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
104
118
|
});
|
|
105
119
|
};
|
|
106
120
|
const implicitRender = () => {
|
|
107
121
|
const elements = Array.from(document.getElementsByClassName("procaptcha"));
|
|
108
122
|
if (elements.length) {
|
|
109
|
-
const siteKey = util.at(elements, 0).getAttribute("data-sitekey")
|
|
110
|
-
|
|
111
|
-
|
|
123
|
+
const siteKey = util.at(elements, 0).getAttribute("data-sitekey");
|
|
124
|
+
if (!siteKey) {
|
|
125
|
+
console.error("No siteKey found");
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const features = Object.values(types.FeaturesEnum);
|
|
129
|
+
const captchaType = features.find((feature) => feature === util.at(elements, 0).getAttribute("data-captcha-type")) || "image";
|
|
130
|
+
renderLogic(elements, getConfig(siteKey), { captchaType, siteKey });
|
|
112
131
|
}
|
|
113
132
|
};
|
|
114
133
|
const render = (elementId, renderOptions) => {
|
|
115
134
|
const siteKey = renderOptions.siteKey;
|
|
116
|
-
const config = getConfig(siteKey);
|
|
117
135
|
const element = document.getElementById(elementId);
|
|
118
136
|
if (!element) {
|
|
119
137
|
console.error("Element not found:", elementId);
|
|
120
138
|
return;
|
|
121
139
|
}
|
|
122
|
-
renderLogic([element],
|
|
140
|
+
renderLogic([element], getConfig(siteKey), renderOptions);
|
|
123
141
|
};
|
|
124
142
|
function ready(fn) {
|
|
125
143
|
if (document && document.readyState !== "loading") {
|
|
@@ -137,7 +155,7 @@ if (renderExplicit !== "explicit") {
|
|
|
137
155
|
}
|
|
138
156
|
if (onloadUrlCallback) {
|
|
139
157
|
const onloadCallback = getWindowCallback(onloadUrlCallback);
|
|
140
|
-
|
|
158
|
+
getProcaptchaScript()?.addEventListener("load", () => {
|
|
141
159
|
ready(onloadCallback);
|
|
142
160
|
});
|
|
143
161
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
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;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const Api = require("@polkadot/api/promise/Api");
|
|
4
|
+
require("../../../account/dist/index.cjs");
|
|
5
|
+
const keyring = require("@polkadot/keyring");
|
|
6
|
+
const types = require("@prosopo/types");
|
|
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 SolverService = require("./SolverService.cjs");
|
|
13
|
+
const ExtensionWeb2 = require("../../../account/dist/extension/ExtensionWeb2.cjs");
|
|
14
|
+
const Manager = async (configInput) => {
|
|
15
|
+
const getConfig = () => {
|
|
16
|
+
const config2 = {
|
|
17
|
+
userAccountAddress: "",
|
|
18
|
+
...configInput
|
|
19
|
+
};
|
|
20
|
+
return types.ProcaptchaConfigSchema.parse(config2);
|
|
21
|
+
};
|
|
22
|
+
const getNetwork = (config2) => {
|
|
23
|
+
const network = config2.networks[config2.defaultNetwork];
|
|
24
|
+
if (!network) {
|
|
25
|
+
throw new common.ProsopoEnvError("DEVELOPER.NETWORK_NOT_FOUND", {
|
|
26
|
+
context: { error: `No network found for environment ${config2.defaultEnvironment}` }
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
return network;
|
|
30
|
+
};
|
|
31
|
+
const loadContract = async () => {
|
|
32
|
+
const network = getNetwork(getConfig());
|
|
33
|
+
const api2 = await Api.ApiPromise.create({ provider: new ws.WsProvider(network.endpoint), initWasm: false });
|
|
34
|
+
const type = "sr25519";
|
|
35
|
+
const keyring$1 = new keyring.Keyring({ type, ss58Format: api2.registry.chainSS58 });
|
|
36
|
+
return new contract.ProsopoCaptchaContract(api2, JSON.parse(contractInfo.ContractAbi), network.contract.address, "prosopo", 0, keyring$1.addFromAddress(getConfig().account.address || ""));
|
|
37
|
+
};
|
|
38
|
+
const config = getConfig();
|
|
39
|
+
if (!config.web2 && !config.userAccountAddress) {
|
|
40
|
+
throw new common.ProsopoEnvError("GENERAL.ACCOUNT_NOT_FOUND", {
|
|
41
|
+
context: { error: "Account address has not been set for web3 mode" }
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
const ext = new ExtensionWeb2.ExtensionWeb2();
|
|
45
|
+
const account = await ext.getAccount(config);
|
|
46
|
+
const contract$1 = await loadContract();
|
|
47
|
+
const getRandomProviderResponse = await contract.wrapQuery(contract$1.query.getRandomActiveProvider, contract$1.query)(account.account.address, configInput.account.address || "");
|
|
48
|
+
const providerUrl = common.trimProviderUrl(getRandomProviderResponse.provider.url.toString());
|
|
49
|
+
const providerApi = new api.ProviderApi(getNetwork(getConfig()), providerUrl, configInput.account.address || "");
|
|
50
|
+
const challenge = await providerApi.getPowCaptchaChallenge(account.account.address, configInput.account.address || "");
|
|
51
|
+
console.log("challenge", challenge);
|
|
52
|
+
console.log("challenge", challenge.challenge);
|
|
53
|
+
console.log("challenge", challenge.difficulty);
|
|
54
|
+
const solution = SolverService.solvePoW(challenge.challenge, challenge.difficulty);
|
|
55
|
+
console.log("solution", solution);
|
|
56
|
+
const verifiedSolution = await providerApi.submitPowCaptchaSolution(challenge, account.account.address, configInput.account.address || "", getRandomProviderResponse, solution);
|
|
57
|
+
return verifiedSolution;
|
|
58
|
+
};
|
|
59
|
+
exports.Manager = Manager;
|
|
@@ -0,0 +1,17 @@
|
|
|
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;
|
|
@@ -0,0 +1,55 @@
|
|
|
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 react = require("react");
|
|
6
|
+
const theme = require("../../../web-components/dist/theme.cjs");
|
|
7
|
+
const Containers = require("../../../web-components/dist/Containers.cjs");
|
|
8
|
+
const WidgetConstants = require("../../../web-components/dist/WidgetConstants.cjs");
|
|
9
|
+
const LoadingSpinner = require("../../../web-components/dist/LoadingSpinner.cjs");
|
|
10
|
+
const Checkbox = require("../../../web-components/dist/Checkbox.cjs");
|
|
11
|
+
const Logo = require("../../../web-components/dist/Logo.cjs");
|
|
12
|
+
const Procaptcha = (props) => {
|
|
13
|
+
const [checked, setChecked] = react.useState(false);
|
|
14
|
+
const [loading, setLoading] = react.useState(false);
|
|
15
|
+
const darkMode = props.config.theme;
|
|
16
|
+
const themeColor = darkMode ? "light" : "dark";
|
|
17
|
+
const theme$1 = react.useMemo(() => darkMode === "light" ? theme.lightTheme : theme.darkTheme, [darkMode]);
|
|
18
|
+
const handlePowCaptcha = async () => {
|
|
19
|
+
setLoading(true);
|
|
20
|
+
Manager.Manager(props.config).then((verified) => {
|
|
21
|
+
if (verified.verified) {
|
|
22
|
+
console.log("verified");
|
|
23
|
+
setChecked(true);
|
|
24
|
+
}
|
|
25
|
+
setLoading(false);
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
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: {
|
|
29
|
+
padding: "2px",
|
|
30
|
+
border: "1px solid",
|
|
31
|
+
backgroundColor: theme$1.palette.background.default,
|
|
32
|
+
borderColor: theme$1.palette.grey[300],
|
|
33
|
+
borderRadius: "4px",
|
|
34
|
+
display: "flex",
|
|
35
|
+
alignItems: "center",
|
|
36
|
+
flexWrap: "wrap",
|
|
37
|
+
justifyContent: "space-between",
|
|
38
|
+
minHeight: `${WidgetConstants.WIDGET_INNER_HEIGHT}px`,
|
|
39
|
+
overflow: "hidden"
|
|
40
|
+
}, children: [jsxRuntime.jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: jsxRuntime.jsx("div", { style: {
|
|
41
|
+
display: "flex",
|
|
42
|
+
justifyContent: "flex-start",
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
flexWrap: "wrap"
|
|
45
|
+
}, children: jsxRuntime.jsx("div", { style: {
|
|
46
|
+
display: "flex",
|
|
47
|
+
alignItems: "center",
|
|
48
|
+
justifyContent: "center",
|
|
49
|
+
flexDirection: "column",
|
|
50
|
+
verticalAlign: "middle"
|
|
51
|
+
}, children: jsxRuntime.jsx("div", { style: {
|
|
52
|
+
display: "flex"
|
|
53
|
+
}, children: jsxRuntime.jsx("div", { style: { flex: 1 }, children: loading ? jsxRuntime.jsx(LoadingSpinner.LoadingSpinner, { themeColor }) : jsxRuntime.jsx(Checkbox.Checkbox, { checked, onChange: handlePowCaptcha, 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 }) }) }) })] })] }) }) }) }) });
|
|
54
|
+
};
|
|
55
|
+
module.exports = Procaptcha;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
require("../../../web-components/dist/index.cjs");
|
|
5
|
+
const react = require("react");
|
|
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;
|
|
@@ -0,0 +1,39 @@
|
|
|
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 react = require("react");
|
|
9
|
+
const Logo = require("./Logo.cjs");
|
|
10
|
+
const ProcaptchaPlaceholder = (props) => {
|
|
11
|
+
const darkMode = props.darkMode;
|
|
12
|
+
const themeColor = props.darkMode === "light" ? "light" : "dark";
|
|
13
|
+
const theme$1 = react.useMemo(() => darkMode === "light" ? theme.lightTheme : theme.darkTheme, [darkMode]);
|
|
14
|
+
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: {
|
|
15
|
+
padding: "2px",
|
|
16
|
+
border: "1px solid",
|
|
17
|
+
backgroundColor: theme$1.palette.background.default,
|
|
18
|
+
borderColor: theme$1.palette.grey[300],
|
|
19
|
+
borderRadius: "8px",
|
|
20
|
+
display: "flex",
|
|
21
|
+
alignItems: "center",
|
|
22
|
+
flexWrap: "wrap",
|
|
23
|
+
justifyContent: "space-between",
|
|
24
|
+
minHeight: `${WidgetConstants.WIDGET_INNER_HEIGHT}px`,
|
|
25
|
+
overflow: "hidden"
|
|
26
|
+
}, children: [jsxRuntime.jsx("div", { style: { display: "flex", flexDirection: "column" }, children: jsxRuntime.jsx("div", { style: {
|
|
27
|
+
alignItems: "center",
|
|
28
|
+
flex: 1
|
|
29
|
+
}, children: jsxRuntime.jsx("div", { style: {
|
|
30
|
+
display: "flex",
|
|
31
|
+
alignItems: "center",
|
|
32
|
+
justifyContent: "center",
|
|
33
|
+
flexDirection: "column",
|
|
34
|
+
verticalAlign: "middle"
|
|
35
|
+
}, children: jsxRuntime.jsx("div", { style: {
|
|
36
|
+
display: "flex"
|
|
37
|
+
}, 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 }) }) }) })] })] }) }) }) }) });
|
|
38
|
+
};
|
|
39
|
+
exports.ProcaptchaPlaceholder = ProcaptchaPlaceholder;
|
|
@@ -0,0 +1,55 @@
|
|
|
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 Checkbox = ({ themeColor, onChange, checked, labelText }) => {
|
|
29
|
+
const theme$1 = react$1.useMemo(() => themeColor === "light" ? theme.lightTheme : theme.darkTheme, [themeColor]);
|
|
30
|
+
const checkboxStyleBase = {
|
|
31
|
+
...baseStyle,
|
|
32
|
+
border: `1px solid ${theme$1.palette.background.contrastText}`
|
|
33
|
+
};
|
|
34
|
+
const [hover, setHover] = react$1.useState(false);
|
|
35
|
+
const checkboxStyle = react$1.useMemo(() => {
|
|
36
|
+
return {
|
|
37
|
+
...checkboxStyleBase,
|
|
38
|
+
borderColor: hover ? theme$1.palette.background.contrastText : theme$1.palette.grey[400],
|
|
39
|
+
appearance: checked ? "auto" : "none",
|
|
40
|
+
flex: 1,
|
|
41
|
+
margin: "0 15px"
|
|
42
|
+
};
|
|
43
|
+
}, [hover, theme$1, checked]);
|
|
44
|
+
const id = react$1.useId();
|
|
45
|
+
return jsxRuntime.jsxs("span", { style: { display: "inline-flex" }, children: [jsxRuntime.jsx("input", { name: 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: {
|
|
46
|
+
color: theme$1.palette.background.contrastText,
|
|
47
|
+
position: "relative",
|
|
48
|
+
display: "flex",
|
|
49
|
+
cursor: "pointer",
|
|
50
|
+
userSelect: "none",
|
|
51
|
+
top: "4px"
|
|
52
|
+
}, htmlFor: id, children: labelText })] });
|
|
53
|
+
};
|
|
54
|
+
exports.Checkbox = Checkbox;
|
|
55
|
+
exports.default = Checkbox;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const WidgetConstants = require("./WidgetConstants.cjs");
|
|
4
|
+
const styled = require("@emotion/styled");
|
|
5
|
+
const ContainerDiv = styled.div`
|
|
6
|
+
container-type: inline-size;
|
|
7
|
+
`;
|
|
8
|
+
const WidthBasedStylesDiv = styled.div`
|
|
9
|
+
max-width: 100%;
|
|
10
|
+
max-height: 100%;
|
|
11
|
+
overflow: hidden;
|
|
12
|
+
height: ${WidgetConstants.WIDGET_OUTER_HEIGHT}px;
|
|
13
|
+
@container (max-width: 243px) {
|
|
14
|
+
#logo-without-text {
|
|
15
|
+
display: none;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
#logo-with-text {
|
|
19
|
+
display: none;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
@container (min-width: 244px) and (max-width: 339px) {
|
|
23
|
+
#logo-without-text {
|
|
24
|
+
display: inherit;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#logo-with-text {
|
|
28
|
+
display: none;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
@container (min-width: 340px) {
|
|
32
|
+
#logo-without-text {
|
|
33
|
+
display: none;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
#logo-with-text {
|
|
37
|
+
display: inherit;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
`;
|
|
41
|
+
exports.ContainerDiv = ContainerDiv;
|
|
42
|
+
exports.WidthBasedStylesDiv = WidthBasedStylesDiv;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
+
const theme = require("./theme.cjs");
|
|
5
|
+
const react = require("react");
|
|
6
|
+
const styled = require("@emotion/styled");
|
|
7
|
+
const LoadingSpinner = ({ themeColor }) => {
|
|
8
|
+
const theme$1 = react.useMemo(() => themeColor === "light" ? theme.lightTheme : theme.darkTheme, [themeColor]);
|
|
9
|
+
const StyledDiv = styled.div`
|
|
10
|
+
margin-top: 0;
|
|
11
|
+
margin-left: 15px;
|
|
12
|
+
margin-right: 15px;
|
|
13
|
+
width: 2em;
|
|
14
|
+
height: 2em;
|
|
15
|
+
border: 4px solid ${theme$1.palette.background.contrastText};
|
|
16
|
+
border-bottom-color: transparent;
|
|
17
|
+
border-radius: 50%;
|
|
18
|
+
display: inherit;
|
|
19
|
+
box-sizing: border-box;
|
|
20
|
+
animation: rotation 1s linear infinite;
|
|
21
|
+
|
|
22
|
+
@keyframes rotation {
|
|
23
|
+
0% {
|
|
24
|
+
transform: rotate(0deg);
|
|
25
|
+
}
|
|
26
|
+
100% {
|
|
27
|
+
transform: rotate(360deg);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
`;
|
|
31
|
+
return jsxRuntime.jsx(StyledDiv, {});
|
|
32
|
+
};
|
|
33
|
+
exports.LoadingSpinner = LoadingSpinner;
|
|
34
|
+
exports.default = LoadingSpinner;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
3
|
+
const LogoWithText = require("./LogoWithText.cjs");
|
|
4
|
+
const LogoWithoutText = require("./LogoWithoutText.cjs");
|
|
5
|
+
const styled = require("@emotion/styled");
|
|
6
|
+
const LogoContainer = styled.div`
|
|
7
|
+
padding: 8px;
|
|
8
|
+
flex: 1 1 0;
|
|
9
|
+
`;
|
|
10
|
+
const LogoInnerContainer = styled.div`
|
|
11
|
+
padding: 8px;
|
|
12
|
+
`;
|
|
13
|
+
const Logo = ({ themeColor }) => {
|
|
14
|
+
return jsxRuntime.jsx(LogoContainer, { children: jsxRuntime.jsxs(LogoInnerContainer, { children: [jsxRuntime.jsx(LogoWithoutText.LogoWithoutText, { themeColor }), jsxRuntime.jsx(LogoWithText.LogoWithText, { themeColor })] }) });
|
|
15
|
+
};
|
|
16
|
+
module.exports = Logo;
|