@prosopo/procaptcha-react 0.2.2 → 0.2.4
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/README.md +95 -49
- package/dist/cjs/components/CaptchaComponent.cjs +108 -130
- package/dist/cjs/components/CaptchaWidget.cjs +6 -7
- package/dist/cjs/components/Procaptcha.cjs +48 -14
- package/dist/cjs/components/theme.cjs +20 -2
- package/dist/components/CaptchaComponent.d.ts +2 -1
- package/dist/components/CaptchaComponent.d.ts.map +1 -1
- package/dist/components/CaptchaComponent.js +36 -52
- package/dist/components/CaptchaComponent.js.map +1 -1
- package/dist/components/CaptchaWidget.d.ts +1 -1
- package/dist/components/CaptchaWidget.d.ts.map +1 -1
- package/dist/components/CaptchaWidget.js +61 -63
- package/dist/components/CaptchaWidget.js.map +1 -1
- package/dist/components/ExtensionAccountSelect.d.ts.map +1 -1
- package/dist/components/ExtensionAccountSelect.js.map +1 -1
- package/dist/components/Procaptcha.d.ts.map +1 -1
- package/dist/components/Procaptcha.js +54 -38
- package/dist/components/Procaptcha.js.map +1 -1
- package/dist/components/theme.d.ts +2 -2
- package/dist/components/theme.d.ts.map +1 -1
- package/dist/components/theme.js +17 -1
- package/dist/components/theme.js.map +1 -1
- package/package.json +9 -5
package/README.md
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Prosopo Procaptcha React Component Library
|
|
2
2
|
|
|
3
3
|
React components for integrating the Prosopo [procaptcha](https://github.com/prosopo/procaptcha) into a React app.
|
|
4
4
|
|
|
5
|
-
Prosopo is a distributed human verification service that can be used to stop bots from interacting with
|
|
5
|
+
Prosopo is a distributed human verification service that can be used to stop bots from interacting with your apps.
|
|
6
|
+
Sign up to be a network [beta tester](https://prosopo.io/#signup).
|
|
6
7
|
|
|
7
8
|
## Installation
|
|
8
9
|
|
|
@@ -14,73 +15,118 @@ npm install @prosopo/procaptcha-react --save
|
|
|
14
15
|
|
|
15
16
|
## Basic Usage
|
|
16
17
|
|
|
17
|
-
See the [client example](https://github.com/prosopo/client-example) for a minimal example of these components being used
|
|
18
|
+
See the [client example](https://github.com/prosopo/client-example) for a minimal example of these components being used
|
|
19
|
+
in a frontend app.
|
|
18
20
|
|
|
19
|
-
```
|
|
20
|
-
<
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
<CaptchaContextManager.Provider value={manager}>
|
|
24
|
-
{showCaptchas &&
|
|
25
|
-
<CaptchaComponent {...{ clientInterface }} />}
|
|
26
|
-
</CaptchaContextManager.Provider>
|
|
27
|
-
|
|
28
|
-
{!showCaptchas &&
|
|
29
|
-
<Button onClick={showCaptchaClick} className={"iAmHumanButton"}>
|
|
30
|
-
<Typography className={"iAmHumanButtonLabel"}>
|
|
31
|
-
I am human
|
|
32
|
-
</Typography>
|
|
33
|
-
</Button>}
|
|
34
|
-
|
|
35
|
-
</Box>
|
|
21
|
+
```jsx
|
|
22
|
+
<Procaptcha config={config} callbacks={{ onAccountNotFound, onError, onHuman, onExpired }}/>
|
|
36
23
|
```
|
|
37
24
|
|
|
38
25
|
### Callbacks
|
|
39
|
-
`CaptchaEventCallbacks` are passed to the captcha component at creation.
|
|
40
26
|
|
|
41
|
-
|
|
42
|
-
const clientInterface = useCaptcha({ config }, { onAccountChange, onChange, onSubmit, onSolved, onCancel });
|
|
43
|
-
```
|
|
27
|
+
`ProcaptchaEvents` are passed to the captcha component at creation.
|
|
44
28
|
|
|
45
29
|
The captcha event callbacks are defined as follows:
|
|
46
30
|
|
|
47
31
|
```typescript
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
onChange?: (captchaSolution: number[][], index: number) => void;
|
|
59
|
-
onCancel?: () => void;
|
|
60
|
-
onSolved?: (result: TCaptchaSubmitResult, isHuman?: boolean) => void;
|
|
32
|
+
/**
|
|
33
|
+
* A list of all events which can occur during the Procaptcha process.
|
|
34
|
+
*/
|
|
35
|
+
export interface ProcaptchaEvents {
|
|
36
|
+
onError: (error: Error) => void
|
|
37
|
+
onAccountNotFound: (address: string) => void
|
|
38
|
+
onHuman: (output: ProcaptchaOutput) => void
|
|
39
|
+
onExtensionNotFound: () => void
|
|
40
|
+
onExpired: () => void
|
|
41
|
+
onFailed: () => void
|
|
61
42
|
}
|
|
62
43
|
```
|
|
63
44
|
|
|
64
|
-
|
|
45
|
+
### onHuman
|
|
46
|
+
|
|
47
|
+
The `onHuman` callback is called when the user has successfully completed the captcha challenge. The `ProcaptchaOutput`
|
|
48
|
+
object contains the following fields:
|
|
49
|
+
|
|
50
|
+
| Key | Type | Description |
|
|
51
|
+
|--------------|--------|-------------------------------------------------------------------------------------------------------------------------------|
|
|
52
|
+
| commitmentId | string | The commitment ID of the captcha challenge. This is used to verify the user's response on-chain. |
|
|
53
|
+
| providerUrl | string | The URL of the provider that the user used to solve the captcha challenge. |
|
|
54
|
+
| dapp | string | The SITE_KEY of your application / website |
|
|
55
|
+
| user | string | The user's account address |
|
|
56
|
+
| blockNumber | number | The block number of the captcha challenge. This is used to verify that the contacted provider was randomly selected on-chain. |
|
|
57
|
+
|
|
58
|
+
### onError
|
|
59
|
+
|
|
60
|
+
The `onError` callback is called when an error occurs during the captcha process. The `Error` object is a standard
|
|
61
|
+
JavaScript error.
|
|
65
62
|
|
|
66
|
-
|
|
63
|
+
### onAccountNotFound
|
|
67
64
|
|
|
68
|
-
|
|
65
|
+
The `onAccountNotFound` callback is called when the user's account is not found in the Procaptcha config in
|
|
66
|
+
the [`userAccountAddress`](https://github.com/prosopo/captcha/blob/0bb4850adfe2b995dc16f7dd18e6ea844a0b6997/packages/types/src/config/config.ts#L116) field.
|
|
69
67
|
|
|
70
|
-
|
|
68
|
+
### onExpired
|
|
71
69
|
|
|
72
|
-
|
|
70
|
+
The `onExpired` callback is called when the captcha challenge has expired. This can occur if the user takes too long to
|
|
71
|
+
complete the challenge.
|
|
73
72
|
|
|
74
|
-
|
|
73
|
+
### onFailed
|
|
75
74
|
|
|
76
|
-
|
|
75
|
+
The `onFailed` callback is called when the user has failed the captcha challenge. This can occur if the user answers the
|
|
76
|
+
challenge incorrectly.
|
|
77
77
|
|
|
78
|
-
|
|
78
|
+
## Add the Procaptcha Widget to your Web page using a React Component
|
|
79
|
+
|
|
80
|
+
You can see Procaptcha being used as a React component in
|
|
81
|
+
our [React Demo](https://github.com/prosopo/captcha/blob/main/demos/client-example/src/App.tsx).
|
|
82
|
+
|
|
83
|
+
The Procaptcha component is called as follows:
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
<Procaptcha
|
|
89
|
+
config={config}
|
|
90
|
+
callbacks={{onAccountNotFound, onError, onHuman, onExpired}}
|
|
91
|
+
/>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
A config object is required and must contain your SITE_KEY. The callbacks are optional and can be used to handle the
|
|
95
|
+
various Procaptcha events. The following config demonstrates the `REACT_APP_DAPP_SITE_KEY` variable being pulled from
|
|
96
|
+
environment variables.
|
|
97
|
+
|
|
98
|
+
```tsx
|
|
99
|
+
const config: ProcaptchaConfigOptional = {
|
|
100
|
+
account: {
|
|
101
|
+
address: process.env.REACT_APP_DAPP_SITE_KEY || undefined,
|
|
102
|
+
},
|
|
103
|
+
web2: 'true',
|
|
104
|
+
dappName: 'client-example',
|
|
105
|
+
defaultEnvironment: 'rococo',
|
|
106
|
+
networks: {
|
|
107
|
+
rococo: {
|
|
108
|
+
endpoint: 'wss://rococo-contracts-rpc.polkadot.io:443',
|
|
109
|
+
contract: {
|
|
110
|
+
address: '5HiVWQhJrysNcFNEWf2crArKht16zrhro3FcekVWocyQjx5u',
|
|
111
|
+
name: 'prosopo',
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
solutionThreshold: 80,
|
|
116
|
+
}
|
|
117
|
+
```
|
|
79
118
|
|
|
80
|
-
|
|
119
|
+
### Config Options
|
|
81
120
|
|
|
82
|
-
|
|
121
|
+
| Key | Type | Description |
|
|
122
|
+
|--------------------|--------|-----------------------------------------------------------------------------------------|
|
|
123
|
+
| account | string | The SITE_KEY you received when you signed up |
|
|
124
|
+
| web2 | string | Set to `true` to enable web2 support |
|
|
125
|
+
| dappName | string | The name of your application / website |
|
|
126
|
+
| defaultEnvironment | string | The default environment to use - set to `rococo` |
|
|
127
|
+
| networks | object | The networks your application supports - copy paste this from the config above |
|
|
128
|
+
| solutionThreshold | number | The percentage of captcha that a user must have answered correctly to identify as human |
|
|
83
129
|
|
|
84
|
-
|
|
130
|
+
## Verify the User Response Server Side
|
|
85
131
|
|
|
86
|
-
|
|
132
|
+
Please see the main [README](https://github.com/prosopo/captcha/blob/main/README.md) for instructions on how to implement the server side of Procaptcha.
|
|
@@ -3,153 +3,131 @@ const jsxRuntime = require("react/jsx-runtime");
|
|
|
3
3
|
const material = require("@mui/material");
|
|
4
4
|
const CaptchaWidget = require("./CaptchaWidget.cjs");
|
|
5
5
|
const util = require("@prosopo/util");
|
|
6
|
+
const theme = require("./theme.cjs");
|
|
7
|
+
const react = require("react");
|
|
6
8
|
const common = require("@prosopo/common");
|
|
7
9
|
const index = require("../util/index.cjs");
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
+
const CaptchaComponent = ({
|
|
11
|
+
challenge,
|
|
12
|
+
index: index$1,
|
|
13
|
+
solutions,
|
|
14
|
+
onSubmit,
|
|
15
|
+
onCancel,
|
|
16
|
+
onClick,
|
|
17
|
+
onNext,
|
|
18
|
+
themeColor
|
|
19
|
+
}) => {
|
|
10
20
|
const { t } = common.useTranslation();
|
|
11
|
-
const { challenge, index: index$1, solutions, onSubmit, onCancel, onClick, onNext } = props;
|
|
12
21
|
const captcha = util.at(challenge.captchas, index$1);
|
|
13
22
|
const solution = util.at(solutions, index$1);
|
|
14
|
-
|
|
23
|
+
const theme$1 = react.useMemo(() => themeColor === "light" ? theme.lightTheme : theme.darkTheme, [themeColor]);
|
|
24
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
15
25
|
material.Box,
|
|
16
26
|
{
|
|
17
27
|
sx: {
|
|
18
|
-
//
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
justifyContent: "center",
|
|
22
|
-
// fill entire screen
|
|
28
|
+
// introduce scroll bars when screen < minWidth of children
|
|
29
|
+
overflowX: "auto",
|
|
30
|
+
overflowY: "auto",
|
|
23
31
|
width: "100%",
|
|
24
|
-
|
|
32
|
+
maxWidth: "500px",
|
|
33
|
+
maxHeight: "100%"
|
|
25
34
|
},
|
|
26
|
-
children: /* @__PURE__ */ jsxRuntime.
|
|
35
|
+
children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
27
36
|
material.Box,
|
|
28
37
|
{
|
|
38
|
+
bgcolor: theme$1.palette.background.default,
|
|
29
39
|
sx: {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
width: "100%",
|
|
34
|
-
// limit the popup width
|
|
35
|
-
maxWidth: "450px",
|
|
36
|
-
// maxHeight introduces vertical scroll bars if children content longer than window
|
|
37
|
-
maxHeight: "100%"
|
|
40
|
+
display: "flex",
|
|
41
|
+
flexDirection: "column",
|
|
42
|
+
minWidth: "300px"
|
|
38
43
|
},
|
|
39
|
-
children:
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
),
|
|
76
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
77
|
-
material.Typography,
|
|
78
|
-
{
|
|
79
|
-
px: 1,
|
|
80
|
-
sx: {
|
|
81
|
-
color: "#ffffff",
|
|
82
|
-
fontWeight: 700,
|
|
83
|
-
textTransform: "uppercase",
|
|
84
|
-
fontSize: theme.typography.h6.fontSize
|
|
85
|
-
},
|
|
86
|
-
children: `${util.at(props.challenge.captchas, props.index).captcha.target}`
|
|
87
|
-
}
|
|
88
|
-
)
|
|
89
|
-
]
|
|
90
|
-
}
|
|
91
|
-
),
|
|
92
|
-
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { ...index({ dev: { cy: "captcha-" + props.index } }), children: /* @__PURE__ */ jsxRuntime.jsx(CaptchaWidget.CaptchaWidget, { challenge: captcha, solution, onClick }) }),
|
|
93
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
94
|
-
material.Box,
|
|
95
|
-
{
|
|
96
|
-
px: 2,
|
|
97
|
-
py: 1,
|
|
98
|
-
sx: {
|
|
99
|
-
display: "flex",
|
|
100
|
-
alignItems: "center",
|
|
101
|
-
justifyContent: "center",
|
|
102
|
-
width: "100%"
|
|
103
|
-
},
|
|
104
|
-
...index({ dev: { cy: "dots-captcha" } }),
|
|
105
|
-
children: challenge.captchas.map((_, i) => /* @__PURE__ */ jsxRuntime.jsx(
|
|
106
|
-
material.Box,
|
|
107
|
-
{
|
|
108
|
-
sx: {
|
|
109
|
-
width: 7,
|
|
110
|
-
height: 7,
|
|
111
|
-
borderRadius: "50%",
|
|
112
|
-
border: "1px solid #CFCFCF"
|
|
113
|
-
},
|
|
114
|
-
mx: 0.5,
|
|
115
|
-
bgcolor: index$1 === i ? theme.palette.background.default : "#CFCFCF"
|
|
44
|
+
children: [
|
|
45
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
46
|
+
material.Box,
|
|
47
|
+
{
|
|
48
|
+
px: 2,
|
|
49
|
+
py: 3,
|
|
50
|
+
sx: {
|
|
51
|
+
display: "flex",
|
|
52
|
+
alignItems: "center",
|
|
53
|
+
width: "100%"
|
|
54
|
+
},
|
|
55
|
+
bgcolor: theme$1.palette.primary.main,
|
|
56
|
+
children: [
|
|
57
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
58
|
+
material.Typography,
|
|
59
|
+
{
|
|
60
|
+
sx: {
|
|
61
|
+
color: "#ffffff",
|
|
62
|
+
fontWeight: 700
|
|
63
|
+
},
|
|
64
|
+
children: [
|
|
65
|
+
t("WIDGET.SELECT_ALL"),
|
|
66
|
+
": "
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
),
|
|
70
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
71
|
+
material.Typography,
|
|
72
|
+
{
|
|
73
|
+
px: 1,
|
|
74
|
+
sx: {
|
|
75
|
+
color: "#ffffff",
|
|
76
|
+
fontWeight: 700,
|
|
77
|
+
textTransform: "capitalize",
|
|
78
|
+
fontSize: theme$1.typography.h6.fontSize
|
|
116
79
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
80
|
+
children: `${util.at(challenge.captchas, index$1).captcha.target}`
|
|
81
|
+
}
|
|
82
|
+
)
|
|
83
|
+
]
|
|
84
|
+
}
|
|
85
|
+
),
|
|
86
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { ...index({ dev: { cy: "captcha-" + index$1 } }), children: /* @__PURE__ */ jsxRuntime.jsx(CaptchaWidget.CaptchaWidget, { challenge: captcha, solution, onClick }) }),
|
|
87
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
88
|
+
material.Box,
|
|
89
|
+
{
|
|
90
|
+
px: 2,
|
|
91
|
+
py: 1,
|
|
92
|
+
sx: {
|
|
93
|
+
display: "flex",
|
|
94
|
+
alignItems: "center",
|
|
95
|
+
justifyContent: "center",
|
|
96
|
+
width: "100%"
|
|
97
|
+
},
|
|
98
|
+
...index({ dev: { cy: "dots-captcha" } })
|
|
99
|
+
}
|
|
100
|
+
),
|
|
101
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
102
|
+
material.Box,
|
|
103
|
+
{
|
|
104
|
+
px: 2,
|
|
105
|
+
pt: 0,
|
|
106
|
+
pb: 2,
|
|
107
|
+
sx: {
|
|
108
|
+
display: "flex",
|
|
109
|
+
alignItems: "center",
|
|
110
|
+
justifyContent: "space-between"
|
|
111
|
+
},
|
|
112
|
+
children: [
|
|
113
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Button, { onClick: onCancel, variant: "text", children: t("WIDGET.CANCEL") }),
|
|
114
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
115
|
+
material.Button,
|
|
116
|
+
{
|
|
117
|
+
color: "primary",
|
|
118
|
+
onClick: index$1 < challenge.captchas.length - 1 ? onNext : onSubmit,
|
|
119
|
+
variant: "contained",
|
|
120
|
+
...index({ dev: { cy: "button-next" } }),
|
|
121
|
+
children: index$1 < challenge.captchas.length - 1 ? t("WIDGET.NEXT") : t("WIDGET.SUBMIT")
|
|
122
|
+
}
|
|
123
|
+
)
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
)
|
|
127
|
+
]
|
|
150
128
|
}
|
|
151
129
|
)
|
|
152
130
|
}
|
|
153
|
-
)
|
|
131
|
+
);
|
|
154
132
|
};
|
|
155
133
|
module.exports = CaptchaComponent;
|
|
@@ -13,12 +13,11 @@ const getHash = (item) => {
|
|
|
13
13
|
}
|
|
14
14
|
return item.hash;
|
|
15
15
|
};
|
|
16
|
-
|
|
17
|
-
const { challenge, solution, onClick } = props;
|
|
16
|
+
const CaptchaWidget = ({ challenge, solution, onClick }) => {
|
|
18
17
|
const items = challenge.captcha.items;
|
|
19
18
|
const theme = material.useTheme();
|
|
20
19
|
const isTouchDevice = "ontouchstart" in window;
|
|
21
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
20
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
22
21
|
material.Box,
|
|
23
22
|
{
|
|
24
23
|
component: "div",
|
|
@@ -55,13 +54,13 @@ function CaptchaWidget(props) {
|
|
|
55
54
|
onClick: isTouchDevice ? void 0 : () => onClick(hash),
|
|
56
55
|
onTouchStart: isTouchDevice ? () => onClick(hash) : void 0,
|
|
57
56
|
children: [
|
|
58
|
-
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { border: 1, borderColor:
|
|
57
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { border: 1, borderColor: theme.palette.grey[300] }, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
59
58
|
"img",
|
|
60
59
|
{
|
|
61
60
|
style: {
|
|
62
61
|
width: "100%",
|
|
63
62
|
// image should be full width / height of the item
|
|
64
|
-
backgroundColor:
|
|
63
|
+
backgroundColor: theme.palette.grey[300],
|
|
65
64
|
// colour of the bands when letterboxing and image
|
|
66
65
|
opacity: solution.includes(hash) && isTouchDevice ? "50%" : "100%",
|
|
67
66
|
// iphone workaround
|
|
@@ -136,6 +135,6 @@ function CaptchaWidget(props) {
|
|
|
136
135
|
);
|
|
137
136
|
})
|
|
138
137
|
}
|
|
139
|
-
)
|
|
140
|
-
}
|
|
138
|
+
);
|
|
139
|
+
};
|
|
141
140
|
exports.CaptchaWidget = CaptchaWidget;
|
|
@@ -4,6 +4,7 @@ const jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
|
4
4
|
const procaptcha = require("@prosopo/procaptcha");
|
|
5
5
|
const material = require("@mui/material");
|
|
6
6
|
const react = require("@emotion/react");
|
|
7
|
+
const theme = require("./theme.cjs");
|
|
7
8
|
const react$1 = require("react");
|
|
8
9
|
const CaptchaComponent = require("./CaptchaComponent.cjs");
|
|
9
10
|
const logoStyle = react.css`
|
|
@@ -112,9 +113,10 @@ const Procaptcha = (props) => {
|
|
|
112
113
|
const [state, updateState] = useProcaptcha();
|
|
113
114
|
console.log("state", state);
|
|
114
115
|
const manager = procaptcha.Manager(config, state, updateState, callbacks);
|
|
115
|
-
const configSx =
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
const configSx = { maxWidth: "400px", minWidth: "200px" };
|
|
117
|
+
const theme$1 = react$1.useMemo(() => props.config.theme === "light" ? theme.lightTheme : theme.darkTheme, [props.config.theme]);
|
|
118
|
+
return /* @__PURE__ */ jsxRuntime.jsx(material.ThemeProvider, { theme: theme$1, children: /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx: { maxWidth: "100%", maxHeight: "100%", overflowX: "auto" }, children: [
|
|
119
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Backdrop, { open: state.showModal, sx: { zIndex: (theme2) => theme2.zIndex.drawer + 1 }, children: state.challenge ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
118
120
|
CaptchaComponent,
|
|
119
121
|
{
|
|
120
122
|
challenge: state.challenge,
|
|
@@ -123,7 +125,8 @@ const Procaptcha = (props) => {
|
|
|
123
125
|
onSubmit: manager.submit,
|
|
124
126
|
onCancel: manager.cancel,
|
|
125
127
|
onClick: manager.select,
|
|
126
|
-
onNext: manager.nextRound
|
|
128
|
+
onNext: manager.nextRound,
|
|
129
|
+
themeColor: config.theme ?? "light"
|
|
127
130
|
}
|
|
128
131
|
) : /* @__PURE__ */ jsxRuntime.jsx(material.Alert, { children: "No challenge set." }) }),
|
|
129
132
|
/* @__PURE__ */ jsxRuntime.jsxs(material.Box, { p: 0, sx: [...Array.isArray(configSx) ? configSx : [configSx]], "data-cy": "button-human", children: [
|
|
@@ -133,14 +136,14 @@ const Procaptcha = (props) => {
|
|
|
133
136
|
{
|
|
134
137
|
p: 1,
|
|
135
138
|
border: 1,
|
|
136
|
-
|
|
139
|
+
bgcolor: theme$1.palette.background.default,
|
|
140
|
+
borderColor: theme$1.palette.grey[300],
|
|
137
141
|
borderRadius: 2,
|
|
138
142
|
sx: {
|
|
139
143
|
display: "flex",
|
|
140
144
|
justifyContent: "space-between",
|
|
141
145
|
alignItems: "center",
|
|
142
|
-
flexWrap: "wrap"
|
|
143
|
-
backgroundColor: "white"
|
|
146
|
+
flexWrap: "wrap"
|
|
144
147
|
},
|
|
145
148
|
children: [
|
|
146
149
|
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx: { display: "flex", flexDirection: "column" }, children: /* @__PURE__ */ jsxRuntime.jsxs(
|
|
@@ -178,7 +181,20 @@ const Procaptcha = (props) => {
|
|
|
178
181
|
checked: state.isHuman,
|
|
179
182
|
inputProps: { "aria-label": "controlled" },
|
|
180
183
|
sx: {
|
|
181
|
-
"& .MuiSvgIcon-root": { fontSize: 32 }
|
|
184
|
+
"& .MuiSvgIcon-root": { fontSize: 32, position: "relative" },
|
|
185
|
+
"& .PrivateSwitchBase-input": {
|
|
186
|
+
width: "1.4em",
|
|
187
|
+
height: "1.4em",
|
|
188
|
+
top: "auto",
|
|
189
|
+
left: "auto",
|
|
190
|
+
opacity: "1",
|
|
191
|
+
"&::before": {
|
|
192
|
+
content: '""',
|
|
193
|
+
position: "absolute",
|
|
194
|
+
height: "100%",
|
|
195
|
+
width: "100%"
|
|
196
|
+
}
|
|
197
|
+
}
|
|
182
198
|
}
|
|
183
199
|
}
|
|
184
200
|
)
|
|
@@ -196,20 +212,38 @@ const Procaptcha = (props) => {
|
|
|
196
212
|
]
|
|
197
213
|
}
|
|
198
214
|
),
|
|
199
|
-
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { p: 1, children: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { color:
|
|
215
|
+
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { p: 1, children: /* @__PURE__ */ jsxRuntime.jsx(material.Typography, { color: theme$1.palette.primary.contrastText, children: "I am a human" }) })
|
|
200
216
|
]
|
|
201
217
|
}
|
|
202
218
|
) }),
|
|
203
219
|
/* @__PURE__ */ jsxRuntime.jsx(material.Box, { children: /* @__PURE__ */ jsxRuntime.jsx(material.Link, { href: "https://prosopo.io", target: "_blank", children: /* @__PURE__ */ jsxRuntime.jsx(material.Box, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
|
|
204
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
205
|
-
|
|
220
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
221
|
+
"div",
|
|
222
|
+
{
|
|
223
|
+
css: logoStyle,
|
|
224
|
+
dangerouslySetInnerHTML: {
|
|
225
|
+
__html: props.config.theme === "light" ? logoWithoutTextBlack : logoWithoutTextWhite
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
),
|
|
229
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
230
|
+
"div",
|
|
231
|
+
{
|
|
232
|
+
css: logoStyle,
|
|
233
|
+
dangerouslySetInnerHTML: {
|
|
234
|
+
__html: props.config.theme === "light" ? logoWithTextBlack : logoWithTextWhite
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
)
|
|
206
238
|
] }) }) }) })
|
|
207
239
|
]
|
|
208
240
|
}
|
|
209
241
|
)
|
|
210
242
|
] })
|
|
211
|
-
] });
|
|
243
|
+
] }) });
|
|
212
244
|
};
|
|
213
|
-
const
|
|
214
|
-
const
|
|
245
|
+
const logoWithTextBlack = '<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2062.63 468.67" height="35px" width="140px"><defs><style>.cls-1{fill:#1d1d1b;}</style></defs><title>Prosopo Logo Black</title><path class="cls-1" d="M335.55,1825.19A147.75,147.75,0,0,1,483.3,1972.94h50.5c0-109.49-88.76-198.25-198.25-198.25v50.5Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M269.36,1891.39A147.74,147.74,0,0,1,417.1,2039.13h50.5c0-109.49-88.75-198.24-198.24-198.24v50.5Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M414,2157.17a147.75,147.75,0,0,1-147.74-147.74h-50.5c0,109.49,88.75,198.24,198.24,198.24v-50.5Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M480.17,2091a147.74,147.74,0,0,1-147.74-147.75H281.92c0,109.49,88.76,198.25,198.25,198.25V2091Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M862.8,2017.5q-27.39,22.86-78.25,22.86h-65v112.19H654.82v-312h134q46.32,0,73.86,24.13t27.55,74.72Q890.2,1994.64,862.8,2017.5ZM813,1905.1q-12.37-10.36-34.7-10.38H719.59v91.87h58.75q22.32,0,34.7-11.22t12.39-35.56Q825.43,1915.48,813,1905.1Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1045.69,1916.42c.78.08,2.51.19,5.19.32v61.81c-3.81-.42-7.2-.71-10.16-.85s-5.36-.21-7.2-.21q-36.4,0-48.89,23.71-7,13.33-7,41.06v110.29H916.89V1921.82h57.58V1962q14-23.07,24.34-31.54,16.94-14.18,44-14.18C1044,1916.32,1044.92,1916.35,1045.69,1916.42Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1265.64,2124.32q-29.21,36.06-88.69,36.06t-88.69-36.06Q1059,2088.26,1059,2037.5q0-49.9,29.22-86.5t88.69-36.59q59.47,0,88.69,36.59t29.21,86.5Q1294.85,2088.26,1265.64,2124.32ZM1217.38,2091q14.17-18.81,14.18-53.48t-14.18-53.37q-14.19-18.7-40.64-18.71T1136,1984.13q-14.29,18.72-14.29,53.37T1136,2091q14.28,18.81,40.75,18.81T1217.38,2091Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1371.81,2078.88q1.92,16.1,8.29,22.87,11.28,12.06,41.7,12.06,17.85,0,28.39-5.29t10.53-15.88a17.12,17.12,0,0,0-8.48-15.45q-8.49-5.28-63.12-18.2-39.33-9.73-55.41-24.35-16.08-14.39-16.09-41.49,0-32,25.14-54.93t70.75-23q43.26,0,70.53,17.25t31.29,59.59H1455q-1.27-11.64-6.58-18.42-10-12.27-34-12.28-19.74,0-28.13,6.14t-8.38,14.4c0,6.91,3,11.93,8.92,15q8.89,4.89,63,16.73,36,8.46,54.05,25.61,17.77,17.35,17.78,43.39,0,34.3-25.56,56t-79,21.7q-54.51,0-80.49-23t-26-58.53Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1745.54,2124.32q-29.22,36.06-88.7,36.06t-88.69-36.06q-29.2-36.06-29.21-86.82,0-49.9,29.21-86.5t88.69-36.59q59.49,0,88.7,36.59t29.21,86.5Q1774.75,2088.26,1745.54,2124.32ZM1697.27,2091q14.19-18.81,14.19-53.48t-14.19-53.37q-14.18-18.7-40.64-18.71t-40.75,18.71q-14.28,18.72-14.28,53.37t14.28,53.48q14.3,18.81,40.75,18.81T1697.27,2091Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1992.75,1946.59q28.24,29.84,28.23,87.63,0,61-27.58,92.93t-71.06,32q-27.69,0-46-13.76-10-7.62-19.6-22.23v120.24H1797V1921.82h57.79v34.08q9.79-15,20.88-23.71,20.23-15.43,48.15-15.45Q1964.53,1916.74,1992.75,1946.59Zm-46.3,43.39q-12.3-20.52-39.88-20.53-33.15,0-45.54,31.11-6.43,16.51-6.42,41.92,0,40.21,21.58,56.51,12.82,9.53,30.37,9.53,25.45,0,38.83-19.48t13.36-51.86Q1958.75,2010.51,1946.45,1990Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M2249.14,2124.32q-29.2,36.06-88.69,36.06t-88.69-36.06q-29.22-36.06-29.21-86.82,0-49.9,29.21-86.5t88.69-36.59q59.49,0,88.69,36.59t29.22,86.5Q2278.36,2088.26,2249.14,2124.32ZM2200.88,2091q14.19-18.81,14.18-53.48t-14.18-53.37q-14.18-18.7-40.64-18.71t-40.75,18.71q-14.28,18.72-14.29,53.37t14.29,53.48q14.3,18.81,40.75,18.81T2200.88,2091Z" transform="translate(-215.73 -1774.69)"/></svg>';
|
|
246
|
+
const logoWithTextWhite = '<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 2062.63 468.67" height="35px" width="140px"><defs><style>.cls-1{fill:#fff;}</style></defs><title>Prosopo Logo Black</title><path class="cls-1" d="M335.55,1825.19A147.75,147.75,0,0,1,483.3,1972.94h50.5c0-109.49-88.76-198.25-198.25-198.25v50.5Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M269.36,1891.39A147.74,147.74,0,0,1,417.1,2039.13h50.5c0-109.49-88.75-198.24-198.24-198.24v50.5Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M414,2157.17a147.75,147.75,0,0,1-147.74-147.74h-50.5c0,109.49,88.75,198.24,198.24,198.24v-50.5Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M480.17,2091a147.74,147.74,0,0,1-147.74-147.75H281.92c0,109.49,88.76,198.25,198.25,198.25V2091Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M862.8,2017.5q-27.39,22.86-78.25,22.86h-65v112.19H654.82v-312h134q46.32,0,73.86,24.13t27.55,74.72Q890.2,1994.64,862.8,2017.5ZM813,1905.1q-12.37-10.36-34.7-10.38H719.59v91.87h58.75q22.32,0,34.7-11.22t12.39-35.56Q825.43,1915.48,813,1905.1Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1045.69,1916.42c.78.08,2.51.19,5.19.32v61.81c-3.81-.42-7.2-.71-10.16-.85s-5.36-.21-7.2-.21q-36.4,0-48.89,23.71-7,13.33-7,41.06v110.29H916.89V1921.82h57.58V1962q14-23.07,24.34-31.54,16.94-14.18,44-14.18C1044,1916.32,1044.92,1916.35,1045.69,1916.42Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1265.64,2124.32q-29.21,36.06-88.69,36.06t-88.69-36.06Q1059,2088.26,1059,2037.5q0-49.9,29.22-86.5t88.69-36.59q59.47,0,88.69,36.59t29.21,86.5Q1294.85,2088.26,1265.64,2124.32ZM1217.38,2091q14.17-18.81,14.18-53.48t-14.18-53.37q-14.19-18.7-40.64-18.71T1136,1984.13q-14.29,18.72-14.29,53.37T1136,2091q14.28,18.81,40.75,18.81T1217.38,2091Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1371.81,2078.88q1.92,16.1,8.29,22.87,11.28,12.06,41.7,12.06,17.85,0,28.39-5.29t10.53-15.88a17.12,17.12,0,0,0-8.48-15.45q-8.49-5.28-63.12-18.2-39.33-9.73-55.41-24.35-16.08-14.39-16.09-41.49,0-32,25.14-54.93t70.75-23q43.26,0,70.53,17.25t31.29,59.59H1455q-1.27-11.64-6.58-18.42-10-12.27-34-12.28-19.74,0-28.13,6.14t-8.38,14.4c0,6.91,3,11.93,8.92,15q8.89,4.89,63,16.73,36,8.46,54.05,25.61,17.77,17.35,17.78,43.39,0,34.3-25.56,56t-79,21.7q-54.51,0-80.49-23t-26-58.53Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1745.54,2124.32q-29.22,36.06-88.7,36.06t-88.69-36.06q-29.2-36.06-29.21-86.82,0-49.9,29.21-86.5t88.69-36.59q59.49,0,88.7,36.59t29.21,86.5Q1774.75,2088.26,1745.54,2124.32ZM1697.27,2091q14.19-18.81,14.19-53.48t-14.19-53.37q-14.18-18.7-40.64-18.71t-40.75,18.71q-14.28,18.72-14.28,53.37t14.28,53.48q14.3,18.81,40.75,18.81T1697.27,2091Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M1992.75,1946.59q28.24,29.84,28.23,87.63,0,61-27.58,92.93t-71.06,32q-27.69,0-46-13.76-10-7.62-19.6-22.23v120.24H1797V1921.82h57.79v34.08q9.79-15,20.88-23.71,20.23-15.43,48.15-15.45Q1964.53,1916.74,1992.75,1946.59Zm-46.3,43.39q-12.3-20.52-39.88-20.53-33.15,0-45.54,31.11-6.43,16.51-6.42,41.92,0,40.21,21.58,56.51,12.82,9.53,30.37,9.53,25.45,0,38.83-19.48t13.36-51.86Q1958.75,2010.51,1946.45,1990Z" transform="translate(-215.73 -1774.69)"/><path class="cls-1" d="M2249.14,2124.32q-29.2,36.06-88.69,36.06t-88.69-36.06q-29.22-36.06-29.21-86.82,0-49.9,29.21-86.5t88.69-36.59q59.49,0,88.69,36.59t29.22,86.5Q2278.36,2088.26,2249.14,2124.32ZM2200.88,2091q14.19-18.81,14.18-53.48t-14.18-53.37q-14.18-18.7-40.64-18.71t-40.75,18.71q-14.28,18.72-14.29,53.37t14.29,53.48q14.3,18.81,40.75,18.81T2200.88,2091Z" transform="translate(-215.73 -1774.69)"/></svg>';
|
|
247
|
+
const logoWithoutTextWhite = '<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 260 348" height="35px"><path id="Vector" d="M95.7053 40.2707C127.005 40.2707 157.022 52.6841 179.154 74.78C201.286 96.8759 213.719 126.844 213.719 158.093H254.056C254.056 70.7808 183.16 -4.57764e-05 95.7053 -4.57764e-05V40.2707Z" fill="#fff"/><path id="Vector_2" d="M42.8365 93.0614C58.3333 93.0614 73.6784 96.1087 87.9955 102.029C102.313 107.95 115.322 116.628 126.279 127.568C137.237 138.508 145.93 151.496 151.86 165.79C157.79 180.084 160.843 195.404 160.843 210.875H201.179C201.179 123.564 130.291 52.7906 42.8365 52.7906V93.0614Z" fill="#fff"/><path id="Vector_3" d="M158.367 305.005C127.07 305.003 97.056 292.59 74.926 270.496C52.796 248.402 40.3626 218.437 40.3604 187.191H0.0239563C0.0239563 274.503 70.9123 345.276 158.367 345.276V305.005Z" fill="#fff"/><path id="Vector_4" d="M211.219 252.239C195.722 252.239 180.376 249.191 166.059 243.27C151.741 237.349 138.732 228.67 127.774 217.729C116.816 206.788 108.123 193.799 102.194 179.505C96.2637 165.21 93.2121 149.889 93.2132 134.417H52.8687C52.8687 221.729 123.765 292.509 211.219 292.509V252.239Z" fill="#fff"/></g><defs><clipPath id="clip0_1_2"><rect width="254" height="345" fill="white"/></clipPath></defs></svg>';
|
|
248
|
+
const logoWithoutTextBlack = '<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 260 348" height="35px"><path id="Vector" d="M95.7053 40.2707C127.005 40.2707 157.022 52.6841 179.154 74.78C201.286 96.8759 213.719 126.844 213.719 158.093H254.056C254.056 70.7808 183.16 -4.57764e-05 95.7053 -4.57764e-05V40.2707Z" fill="#000000"/><path id="Vector_2" d="M42.8365 93.0614C58.3333 93.0614 73.6784 96.1087 87.9955 102.029C102.313 107.95 115.322 116.628 126.279 127.568C137.237 138.508 145.93 151.496 151.86 165.79C157.79 180.084 160.843 195.404 160.843 210.875H201.179C201.179 123.564 130.291 52.7906 42.8365 52.7906V93.0614Z" fill="#000000"/><path id="Vector_3" d="M158.367 305.005C127.07 305.003 97.056 292.59 74.926 270.496C52.796 248.402 40.3626 218.437 40.3604 187.191H0.0239563C0.0239563 274.503 70.9123 345.276 158.367 345.276V305.005Z" fill="#000000"/><path id="Vector_4" d="M211.219 252.239C195.722 252.239 180.376 249.191 166.059 243.27C151.741 237.349 138.732 228.67 127.774 217.729C116.816 206.788 108.123 193.799 102.194 179.505C96.2637 165.21 93.2121 149.889 93.2132 134.417H52.8687C52.8687 221.729 123.765 292.509 211.219 292.509V252.239Z" fill="#000000"/></g><defs><clipPath id="clip0_1_2"><rect width="254" height="345" fill="white"/></clipPath></defs></svg>';
|
|
215
249
|
exports.Procaptcha = Procaptcha;
|