@prosopo/procaptcha-frictionless 2.0.3 → 2.1.0
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/dist/ProcaptchaFrictionless.d.ts.map +1 -1
- package/dist/ProcaptchaFrictionless.js +6 -2
- package/dist/ProcaptchaFrictionless.js.map +1 -1
- package/dist/cjs/ProcaptchaFrictionless.cjs +10 -7
- package/package.json +58 -53
- package/dist/cjs/account/dist/extension/Extension.cjs +0 -5
- package/dist/cjs/account/dist/extension/ExtensionWeb2.cjs +0 -78
- package/dist/cjs/account/dist/extension/ExtensionWeb3.cjs +0 -30
- package/dist/cjs/account/dist/index.cjs +0 -8
- package/dist/cjs/detector/src/index.cjs +0 -4586
- package/dist/cjs/procaptcha-pow/dist/components/ProcaptchaPoW.cjs +0 -9
- package/dist/cjs/procaptcha-pow/dist/components/ProcaptchaWidget.cjs +0 -62
- package/dist/cjs/procaptcha-pow/dist/index.cjs +0 -5
- package/dist/cjs/procaptcha-pow/dist/services/Manager.cjs +0 -162
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
4
|
-
const webComponents = require("@prosopo/web-components");
|
|
5
|
-
const react = require("react");
|
|
6
|
-
const _interopNamespaceDefaultOnly = (e) => Object.freeze(Object.defineProperty({ __proto__: null, default: e }, Symbol.toStringTag, { value: "Module" }));
|
|
7
|
-
const ProcaptchaWidget = react.lazy(async () => Promise.resolve().then(() => /* @__PURE__ */ _interopNamespaceDefaultOnly(require("./ProcaptchaWidget.cjs"))));
|
|
8
|
-
const ProcaptchaPow = (props) => jsxRuntime.jsx(react.Suspense, { fallback: jsxRuntime.jsx(webComponents.ProcaptchaPlaceholder, { darkMode: props.config.theme }), children: jsxRuntime.jsx(ProcaptchaWidget, { config: props.config, callbacks: props.callbacks }) });
|
|
9
|
-
exports.ProcaptchaPow = ProcaptchaPow;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
3
|
-
const procaptchaCommon = require("@prosopo/procaptcha-common");
|
|
4
|
-
const webComponents = require("@prosopo/web-components");
|
|
5
|
-
const react = require("react");
|
|
6
|
-
const Manager = require("../services/Manager.cjs");
|
|
7
|
-
const Procaptcha = (props) => {
|
|
8
|
-
const config = props.config;
|
|
9
|
-
const themeColor = config.theme === "light" ? "light" : "dark";
|
|
10
|
-
const theme = props.config.theme === "light" ? webComponents.lightTheme : webComponents.darkTheme;
|
|
11
|
-
const callbacks = props.callbacks || {};
|
|
12
|
-
const [state, _updateState] = procaptchaCommon.useProcaptcha(react.useState, react.useRef);
|
|
13
|
-
const updateState = procaptchaCommon.buildUpdateState(state, _updateState);
|
|
14
|
-
const manager = react.useRef(Manager.Manager(config, state, updateState, callbacks));
|
|
15
|
-
const captchaRef = react.useRef(null);
|
|
16
|
-
react.useEffect(() => {
|
|
17
|
-
const element = captchaRef.current;
|
|
18
|
-
if (!element)
|
|
19
|
-
return;
|
|
20
|
-
const form = element.closest("form");
|
|
21
|
-
if (!form)
|
|
22
|
-
return;
|
|
23
|
-
const handleSubmit = () => {
|
|
24
|
-
manager.current.resetState();
|
|
25
|
-
};
|
|
26
|
-
form.addEventListener("submit", handleSubmit);
|
|
27
|
-
return () => {
|
|
28
|
-
form.removeEventListener("submit", handleSubmit);
|
|
29
|
-
};
|
|
30
|
-
}, []);
|
|
31
|
-
return jsxRuntime.jsx("div", { ref: captchaRef, children: jsxRuntime.jsx("div", { style: {
|
|
32
|
-
maxWidth: webComponents.WIDGET_MAX_WIDTH,
|
|
33
|
-
maxHeight: "100%",
|
|
34
|
-
overflowX: "auto"
|
|
35
|
-
}, children: jsxRuntime.jsx(webComponents.ContainerDiv, { children: jsxRuntime.jsx(webComponents.WidthBasedStylesDiv, { children: jsxRuntime.jsxs("div", { style: webComponents.WIDGET_DIMENSIONS, "data-cy": "button-human", children: [" ", jsxRuntime.jsxs("div", { style: {
|
|
36
|
-
padding: webComponents.WIDGET_PADDING,
|
|
37
|
-
border: webComponents.WIDGET_BORDER,
|
|
38
|
-
backgroundColor: theme.palette.background.default,
|
|
39
|
-
borderColor: theme.palette.grey[300],
|
|
40
|
-
borderRadius: webComponents.WIDGET_BORDER_RADIUS,
|
|
41
|
-
display: "flex",
|
|
42
|
-
alignItems: "center",
|
|
43
|
-
flexWrap: "wrap",
|
|
44
|
-
justifyContent: "space-between",
|
|
45
|
-
minHeight: `${webComponents.WIDGET_INNER_HEIGHT}px`,
|
|
46
|
-
overflow: "hidden"
|
|
47
|
-
}, children: [jsxRuntime.jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: jsxRuntime.jsx("div", { style: {
|
|
48
|
-
display: "flex",
|
|
49
|
-
justifyContent: "flex-start",
|
|
50
|
-
alignItems: "center",
|
|
51
|
-
flexWrap: "wrap"
|
|
52
|
-
}, children: jsxRuntime.jsx("div", { style: {
|
|
53
|
-
display: "flex",
|
|
54
|
-
alignItems: "center",
|
|
55
|
-
justifyContent: "center",
|
|
56
|
-
flexDirection: "column",
|
|
57
|
-
verticalAlign: "middle"
|
|
58
|
-
}, children: jsxRuntime.jsx("div", { style: {
|
|
59
|
-
display: "flex"
|
|
60
|
-
}, children: jsxRuntime.jsx("div", { style: { flex: 1 }, children: state.loading ? jsxRuntime.jsx(webComponents.LoadingSpinner, { themeColor, "aria-label": "Loading spinner" }) : jsxRuntime.jsx(webComponents.Checkbox, { checked: state.isHuman, onChange: manager.current.start, themeColor, labelText: "I am human", "aria-label": "human checkbox" }) }) }) }) }) }), jsxRuntime.jsx("div", { style: { display: "inline-flex", flexDirection: "column" }, children: jsxRuntime.jsx("a", { href: webComponents.WIDGET_URL, target: "_blank", "aria-label": webComponents.WIDGET_URL_TEXT, rel: "noreferrer", children: jsxRuntime.jsx("div", { style: { flex: 1 }, children: jsxRuntime.jsx(webComponents.Logo, { themeColor, "aria-label": "Prosopo logo" }) }) }) })] })] }) }) }) }) });
|
|
61
|
-
};
|
|
62
|
-
module.exports = Procaptcha;
|
|
@@ -1,162 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const string = require("@polkadot/util/string");
|
|
4
|
-
require("../../../account/dist/index.cjs");
|
|
5
|
-
const api = require("@prosopo/api");
|
|
6
|
-
const common = require("@prosopo/common");
|
|
7
|
-
const loadBalancer = require("@prosopo/load-balancer");
|
|
8
|
-
const procaptcha = require("@prosopo/procaptcha");
|
|
9
|
-
const procaptchaCommon = require("@prosopo/procaptcha-common");
|
|
10
|
-
const types = require("@prosopo/types");
|
|
11
|
-
const util = require("@prosopo/util");
|
|
12
|
-
const ExtensionWeb2 = require("../../../account/dist/extension/ExtensionWeb2.cjs");
|
|
13
|
-
const ExtensionWeb3 = require("../../../account/dist/extension/ExtensionWeb3.cjs");
|
|
14
|
-
const Manager = (configInput, state, onStateUpdate, callbacks) => {
|
|
15
|
-
const events = procaptchaCommon.getDefaultEvents(onStateUpdate, state, callbacks);
|
|
16
|
-
const defaultState = () => {
|
|
17
|
-
return {
|
|
18
|
-
showModal: false,
|
|
19
|
-
loading: false,
|
|
20
|
-
index: 0,
|
|
21
|
-
challenge: void 0,
|
|
22
|
-
solutions: void 0,
|
|
23
|
-
isHuman: false,
|
|
24
|
-
captchaApi: void 0,
|
|
25
|
-
account: void 0
|
|
26
|
-
};
|
|
27
|
-
};
|
|
28
|
-
const clearTimeout = () => {
|
|
29
|
-
window.clearTimeout(state.timeout);
|
|
30
|
-
updateState({ timeout: void 0 });
|
|
31
|
-
};
|
|
32
|
-
const clearSuccessfulChallengeTimeout = () => {
|
|
33
|
-
window.clearTimeout(state.successfullChallengeTimeout);
|
|
34
|
-
updateState({ successfullChallengeTimeout: void 0 });
|
|
35
|
-
};
|
|
36
|
-
const getConfig = () => {
|
|
37
|
-
const config = {
|
|
38
|
-
userAccountAddress: "",
|
|
39
|
-
...configInput
|
|
40
|
-
};
|
|
41
|
-
if (state.account) {
|
|
42
|
-
config.userAccountAddress = state.account.account.address;
|
|
43
|
-
}
|
|
44
|
-
return types.ProcaptchaConfigSchema.parse(config);
|
|
45
|
-
};
|
|
46
|
-
const getAccount = () => {
|
|
47
|
-
if (!state.account) {
|
|
48
|
-
throw new common.ProsopoEnvError("GENERAL.ACCOUNT_NOT_FOUND", {
|
|
49
|
-
context: { error: "Account not loaded" }
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
const account = state.account;
|
|
53
|
-
return { account };
|
|
54
|
-
};
|
|
55
|
-
const getDappAccount = () => {
|
|
56
|
-
if (!state.dappAccount) {
|
|
57
|
-
throw new common.ProsopoEnvError("GENERAL.SITE_KEY_MISSING");
|
|
58
|
-
}
|
|
59
|
-
const dappAccount = state.dappAccount;
|
|
60
|
-
return dappAccount;
|
|
61
|
-
};
|
|
62
|
-
const updateState = procaptchaCommon.buildUpdateState(state, onStateUpdate);
|
|
63
|
-
const resetState = () => {
|
|
64
|
-
clearTimeout();
|
|
65
|
-
clearSuccessfulChallengeTimeout();
|
|
66
|
-
updateState(defaultState());
|
|
67
|
-
};
|
|
68
|
-
const setValidChallengeTimeout = () => {
|
|
69
|
-
const timeMillis = getConfig().captchas.pow.solutionTimeout;
|
|
70
|
-
const successfullChallengeTimeout = setTimeout(() => {
|
|
71
|
-
updateState({ isHuman: false });
|
|
72
|
-
events.onExpired();
|
|
73
|
-
}, timeMillis);
|
|
74
|
-
updateState({ successfullChallengeTimeout });
|
|
75
|
-
};
|
|
76
|
-
const start = async () => {
|
|
77
|
-
if (state.loading) {
|
|
78
|
-
return;
|
|
79
|
-
}
|
|
80
|
-
if (state.isHuman) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
resetState();
|
|
84
|
-
updateState({
|
|
85
|
-
loading: true
|
|
86
|
-
});
|
|
87
|
-
const config = getConfig();
|
|
88
|
-
const ext = config.web2 ? new ExtensionWeb2.ExtensionWeb2() : new ExtensionWeb3.ExtensionWeb3();
|
|
89
|
-
const userAccount = config.userAccountAddress || (await ext.getAccount(config)).account.address;
|
|
90
|
-
updateState({
|
|
91
|
-
account: { account: { address: userAccount } }
|
|
92
|
-
});
|
|
93
|
-
updateState({ dappAccount: config.account.address });
|
|
94
|
-
await procaptcha.sleep(100);
|
|
95
|
-
if (!config.web2 && !config.userAccountAddress) {
|
|
96
|
-
throw new common.ProsopoEnvError("GENERAL.ACCOUNT_NOT_FOUND", {
|
|
97
|
-
context: { error: "Account address has not been set for web3 mode" }
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
const getRandomProviderResponse = getRandomActiveProvider();
|
|
101
|
-
const events2 = procaptchaCommon.getDefaultEvents(onStateUpdate, state, callbacks);
|
|
102
|
-
const providerUrl = getRandomProviderResponse.provider.url;
|
|
103
|
-
const providerApi = new api.ProviderApi(providerUrl, getDappAccount());
|
|
104
|
-
const challenge = await providerApi.getPowCaptchaChallenge(userAccount, getDappAccount());
|
|
105
|
-
const solution = util.solvePoW(challenge.challenge, challenge.difficulty);
|
|
106
|
-
const user = await ext.getAccount(getConfig());
|
|
107
|
-
const signer = user.extension?.signer;
|
|
108
|
-
if (!signer || !signer.signRaw) {
|
|
109
|
-
throw new common.ProsopoEnvError("GENERAL.CANT_FIND_KEYRINGPAIR", {
|
|
110
|
-
context: {
|
|
111
|
-
error: "Signer is not defined, cannot sign message to prove account ownership"
|
|
112
|
-
}
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
const userTimestampSignature = await signer.signRaw({
|
|
116
|
-
address: userAccount,
|
|
117
|
-
data: string.stringToHex(challenge[types.ApiParams.timestamp].toString()),
|
|
118
|
-
type: "bytes"
|
|
119
|
-
});
|
|
120
|
-
const verifiedSolution = await providerApi.submitPowCaptchaSolution(challenge, getAccount().account.account.address, getDappAccount(), solution, userTimestampSignature.signature.toString(), config.captchas.pow.verifiedTimeout);
|
|
121
|
-
if (verifiedSolution[types.ApiParams.verified]) {
|
|
122
|
-
updateState({
|
|
123
|
-
isHuman: true,
|
|
124
|
-
loading: false
|
|
125
|
-
});
|
|
126
|
-
events2.onHuman(types.encodeProcaptchaOutput({
|
|
127
|
-
[types.ApiParams.providerUrl]: providerUrl,
|
|
128
|
-
[types.ApiParams.user]: getAccount().account.account.address,
|
|
129
|
-
[types.ApiParams.dapp]: getDappAccount(),
|
|
130
|
-
[types.ApiParams.challenge]: challenge.challenge,
|
|
131
|
-
[types.ApiParams.nonce]: solution,
|
|
132
|
-
[types.ApiParams.timestamp]: challenge.timestamp,
|
|
133
|
-
[types.ApiParams.signature]: {
|
|
134
|
-
[types.ApiParams.provider]: challenge.signature.provider,
|
|
135
|
-
[types.ApiParams.user]: {
|
|
136
|
-
[types.ApiParams.timestamp]: userTimestampSignature.signature.toString()
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
}));
|
|
140
|
-
setValidChallengeTimeout();
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
const getRandomActiveProvider = () => {
|
|
144
|
-
const randomIntBetween = (min, max) => Math.floor(Math.random() * (max - min + 1) + min);
|
|
145
|
-
const environment = getConfig().defaultEnvironment;
|
|
146
|
-
const PROVIDERS = loadBalancer.loadBalancer(environment);
|
|
147
|
-
const randomProvderObj = util.at(PROVIDERS, randomIntBetween(0, PROVIDERS.length - 1));
|
|
148
|
-
return {
|
|
149
|
-
providerAccount: randomProvderObj.address,
|
|
150
|
-
provider: {
|
|
151
|
-
url: randomProvderObj.url,
|
|
152
|
-
datasetId: randomProvderObj.datasetId,
|
|
153
|
-
datasetIdContent: randomProvderObj.datasetIdContent
|
|
154
|
-
}
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
return {
|
|
158
|
-
start,
|
|
159
|
-
resetState
|
|
160
|
-
};
|
|
161
|
-
};
|
|
162
|
-
exports.Manager = Manager;
|