@prosopo/procaptcha-frictionless 2.17.0 → 2.18.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.turbo/turbo-build$colon$cjs.log +8 -8
- package/.turbo/turbo-build$colon$tsc.log +25 -25
- package/.turbo/turbo-build.log +15 -15
- package/CHANGELOG.md +66 -0
- package/dist/{AuthenticatedBadge.d.ts → authenticatedBadge.d.ts} +3 -3
- package/dist/authenticatedBadge.d.ts.map +1 -0
- package/dist/authenticatedBadge.js +79 -0
- package/dist/authenticatedBadge.js.map +1 -0
- package/dist/cjs/authenticatedBadge.cjs +79 -0
- package/dist/cjs/detectorPrefetch.cjs +2 -2
- package/dist/cjs/index.cjs +2 -2
- package/dist/cjs/procaptchaFrictionless.cjs +269 -0
- package/dist/detectorPrefetch.js +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/procaptchaFrictionless.d.ts +6 -0
- package/dist/procaptchaFrictionless.d.ts.map +1 -0
- package/dist/procaptchaFrictionless.js +269 -0
- package/dist/procaptchaFrictionless.js.map +1 -0
- package/dist/tests/escalationClientSession.test.d.ts +0 -3
- package/dist/tests/escalationClientSession.test.d.ts.map +1 -1
- package/dist/tests/escalationClientSession.test.js +52 -61
- package/dist/tests/escalationClientSession.test.js.map +1 -1
- package/dist/tests/escalationHandoff.integration.test.d.ts +0 -3
- package/dist/tests/escalationHandoff.integration.test.d.ts.map +1 -1
- package/dist/tests/escalationHandoff.integration.test.js +62 -61
- package/dist/tests/escalationHandoff.integration.test.js.map +1 -1
- package/dist/tests/executeBeforeMount.test.d.ts +0 -3
- package/dist/tests/executeBeforeMount.test.d.ts.map +1 -1
- package/dist/tests/executeBeforeMount.test.js +53 -49
- package/dist/tests/executeBeforeMount.test.js.map +1 -1
- package/dist/tests/manualStart.test.d.ts +0 -3
- package/dist/tests/manualStart.test.d.ts.map +1 -1
- package/dist/tests/manualStart.test.js +55 -52
- package/dist/tests/manualStart.test.js.map +1 -1
- package/dist/tests/procaptchaFrictionless.test.d.ts +2 -0
- package/dist/tests/procaptchaFrictionless.test.d.ts.map +1 -0
- package/dist/tests/procaptchaFrictionless.test.js +244 -0
- package/dist/tests/procaptchaFrictionless.test.js.map +1 -0
- package/dist/tests/sessionInvalidatedRemint.test.d.ts +0 -3
- package/dist/tests/sessionInvalidatedRemint.test.d.ts.map +1 -1
- package/dist/tests/sessionInvalidatedRemint.test.js +49 -43
- package/dist/tests/sessionInvalidatedRemint.test.js.map +1 -1
- package/package.json +12 -14
- package/src/authenticatedBadge.ts +151 -0
- package/src/customDetectBot.ts +2 -2
- package/src/detectorPrefetch.ts +2 -2
- package/src/index.ts +1 -1
- package/src/{ProcaptchaFrictionless.tsx → procaptchaFrictionless.ts} +285 -314
- package/src/tests/{escalationClientSession.test.tsx → escalationClientSession.test.ts} +83 -92
- package/src/tests/{escalationHandoff.integration.test.tsx → escalationHandoff.integration.test.ts} +110 -108
- package/src/tests/{executeBeforeMount.test.tsx → executeBeforeMount.test.ts} +79 -77
- package/src/tests/{manualStart.test.tsx → manualStart.test.ts} +87 -83
- package/src/tests/procaptchaFrictionless.test.ts +408 -0
- package/src/tests/{sessionInvalidatedRemint.test.tsx → sessionInvalidatedRemint.test.ts} +67 -64
- package/tsconfig.cjs.json +1 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/AuthenticatedBadge.d.ts.map +0 -1
- package/dist/AuthenticatedBadge.js +0 -75
- package/dist/AuthenticatedBadge.js.map +0 -1
- package/dist/ProcaptchaFrictionless.d.ts +0 -3
- package/dist/ProcaptchaFrictionless.d.ts.map +0 -1
- package/dist/ProcaptchaFrictionless.js +0 -287
- package/dist/ProcaptchaFrictionless.js.map +0 -1
- package/dist/cjs/AuthenticatedBadge.cjs +0 -75
- package/dist/cjs/ProcaptchaFrictionless.cjs +0 -287
- package/src/AuthenticatedBadge.tsx +0 -141
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
const require_AuthenticatedBadge = require("./AuthenticatedBadge.cjs");
|
|
2
|
-
const require_customDetectBot = require("./customDetectBot.cjs");
|
|
3
|
-
const require_frictionlessResultGuard = require("./frictionlessResultGuard.cjs");
|
|
4
|
-
const require_sessionInvalidatedRecovery = require("./sessionInvalidatedRecovery.cjs");
|
|
5
|
-
let _prosopo_locale = require("@prosopo/locale");
|
|
6
|
-
let _prosopo_procaptcha_common = require("@prosopo/procaptcha-common");
|
|
7
|
-
let _prosopo_types = require("@prosopo/types");
|
|
8
|
-
let _prosopo_widget_skeleton = require("@prosopo/widget-skeleton");
|
|
9
|
-
let react = require("react");
|
|
10
|
-
let react_jsx_runtime = require("react/jsx-runtime");
|
|
11
|
-
//#region src/ProcaptchaFrictionless.tsx
|
|
12
|
-
var NO_SESSION_FOUND_KEY = "CAPTCHA.NO_SESSION_FOUND";
|
|
13
|
-
var ProcaptchaLoader = async () => (await import("@prosopo/procaptcha-react")).Procaptcha;
|
|
14
|
-
var ProcaptchaPuzzleLoader = async () => (await import("@prosopo/procaptcha-puzzle")).ProcaptchaPuzzle;
|
|
15
|
-
var ProcaptchaPowLoader = async () => (await import("@prosopo/procaptcha-pow")).ProcaptchaPow;
|
|
16
|
-
var PROCAPTCHA_EXECUTE_EVENT = "procaptcha:execute";
|
|
17
|
-
var noopCheckboxHandler = async (_event) => {};
|
|
18
|
-
var renderPlaceholder = (theme, mode, errorMessage, isTranslationLoaded, translationFn, loading, onChange = noopCheckboxHandler) => {
|
|
19
|
-
const checkboxTheme = "light" === theme ? _prosopo_widget_skeleton.lightTheme : _prosopo_widget_skeleton.darkTheme;
|
|
20
|
-
if (mode === "invisible") return null;
|
|
21
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_prosopo_procaptcha_common.Checkbox, {
|
|
22
|
-
theme: checkboxTheme,
|
|
23
|
-
onChange,
|
|
24
|
-
checked: false,
|
|
25
|
-
labelText: isTranslationLoaded ? translationFn("WIDGET.I_AM_HUMAN") : "",
|
|
26
|
-
error: errorMessage,
|
|
27
|
-
"aria-label": "human checkbox",
|
|
28
|
-
loading,
|
|
29
|
-
loadingText: isTranslationLoaded ? translationFn("WIDGET.CHECKING") : void 0
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
var defaultLoadingState = (attemptCount) => ({
|
|
33
|
-
loading: false,
|
|
34
|
-
attemptCount
|
|
35
|
-
});
|
|
36
|
-
var ProcaptchaFrictionless = ({ config, callbacks, restart, i18n, detectBot = require_customDetectBot.default, container }) => {
|
|
37
|
-
const stateRef = (0, react.useRef)(defaultLoadingState(0));
|
|
38
|
-
const events = (0, _prosopo_procaptcha_common.getDefaultEvents)(callbacks);
|
|
39
|
-
const pendingRetryCoordsRef = (0, react.useRef)(null);
|
|
40
|
-
const sessionInvalidatedAttemptsRef = (0, react.useRef)(0);
|
|
41
|
-
const escalatedSessionIdsRef = (0, react.useRef)(/* @__PURE__ */ new Set());
|
|
42
|
-
const mountCountRef = (0, react.useRef)(0);
|
|
43
|
-
const nextMountAutoStartRef = (0, react.useRef)(false);
|
|
44
|
-
const manualStart = config.startMode === _prosopo_types.StartModeEnum.manual;
|
|
45
|
-
const manualStartedRef = (0, react.useRef)(false);
|
|
46
|
-
const manualCheckboxHandlerRef = (0, react.useRef)(noopCheckboxHandler);
|
|
47
|
-
const innerWidgetRenderedRef = (0, react.useRef)(false);
|
|
48
|
-
const innerWidgetListeningRef = (0, react.useRef)(false);
|
|
49
|
-
const pendingExecuteRef = (0, react.useRef)(false);
|
|
50
|
-
(0, react.useEffect)(() => {
|
|
51
|
-
if (!config.language) return;
|
|
52
|
-
if (i18n) {
|
|
53
|
-
if (i18n.language !== config.language) i18n.changeLanguage(config.language);
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
(0, _prosopo_locale.loadI18next)(false, config.language);
|
|
57
|
-
}, [i18n, config.language]);
|
|
58
|
-
const [componentToRender, setComponentToRender] = (0, react.useState)(renderPlaceholder(config.theme, config.mode, stateRef.current.errorMessage, i18n.isInitialized, i18n.t, !manualStart, manualStart ? (event) => manualCheckboxHandlerRef.current(event) : void 0));
|
|
59
|
-
const resetState = (attemptCount) => {
|
|
60
|
-
stateRef.current = defaultLoadingState(attemptCount ?? stateRef.current.attemptCount);
|
|
61
|
-
};
|
|
62
|
-
const fallOverWithStyle = (errorMessage, errorKey) => {
|
|
63
|
-
if (errorKey === "CAPTCHA.NO_SESSION_FOUND") setTimeout(() => {
|
|
64
|
-
restartComponentTimeout();
|
|
65
|
-
}, 0);
|
|
66
|
-
innerWidgetRenderedRef.current = false;
|
|
67
|
-
setComponentToRender(renderPlaceholder(config.theme, config.mode, errorMessage || "Cannot load CAPTCHA", i18n.isInitialized, i18n.t, false));
|
|
68
|
-
};
|
|
69
|
-
const restartComponentTimeout = () => {
|
|
70
|
-
setTimeout(() => {
|
|
71
|
-
resetState(0);
|
|
72
|
-
events.onReset();
|
|
73
|
-
restart();
|
|
74
|
-
}, 1e4);
|
|
75
|
-
};
|
|
76
|
-
const renderForCaptchaType = async (captchaType, frictionlessState, autoStart = false, escalationCoords) => {
|
|
77
|
-
const onEscalate = (next, newSessionId, coords) => {
|
|
78
|
-
if (escalatedSessionIdsRef.current.has(newSessionId)) return;
|
|
79
|
-
escalatedSessionIdsRef.current.add(newSessionId);
|
|
80
|
-
renderForCaptchaType(next, {
|
|
81
|
-
...frictionlessState,
|
|
82
|
-
sessionId: newSessionId
|
|
83
|
-
}, true, coords);
|
|
84
|
-
};
|
|
85
|
-
const onSessionInvalidated = (x, y) => {
|
|
86
|
-
const { shouldRestart } = require_sessionInvalidatedRecovery.handleSessionInvalidated(x, y, sessionInvalidatedAttemptsRef, pendingRetryCoordsRef);
|
|
87
|
-
if (shouldRestart) {
|
|
88
|
-
resetState(0);
|
|
89
|
-
start();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
const message = i18n.isInitialized ? i18n.t(NO_SESSION_FOUND_KEY) : "No session found";
|
|
93
|
-
events.onError(new Error(message));
|
|
94
|
-
fallOverWithStyle(message, NO_SESSION_FOUND_KEY);
|
|
95
|
-
};
|
|
96
|
-
const onReload = (x, y) => {
|
|
97
|
-
pendingRetryCoordsRef.current = require_sessionInvalidatedRecovery.normaliseRetryCoords(x, y);
|
|
98
|
-
nextMountAutoStartRef.current = true;
|
|
99
|
-
sessionInvalidatedAttemptsRef.current = 0;
|
|
100
|
-
resetState(0);
|
|
101
|
-
start();
|
|
102
|
-
};
|
|
103
|
-
const forcedAutoStart = nextMountAutoStartRef.current;
|
|
104
|
-
nextMountAutoStartRef.current = false;
|
|
105
|
-
const { autoStart: resumedAutoStart, startCoords: retryStartCoords } = require_sessionInvalidatedRecovery.consumeRetryMountProps(pendingRetryCoordsRef, autoStart || forcedAutoStart);
|
|
106
|
-
const startCoords = escalationCoords ?? retryStartCoords;
|
|
107
|
-
mountCountRef.current += 1;
|
|
108
|
-
const mountKey = mountCountRef.current;
|
|
109
|
-
innerWidgetRenderedRef.current = true;
|
|
110
|
-
if (captchaType === _prosopo_types.CaptchaType.authenticated) {
|
|
111
|
-
if (!frictionlessState.sessionId) {
|
|
112
|
-
events.onError(/* @__PURE__ */ new Error("authenticated captcha response missing sessionId — provider is misbehaving"));
|
|
113
|
-
fallOverWithStyle();
|
|
114
|
-
return;
|
|
115
|
-
}
|
|
116
|
-
setComponentToRender(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(require_AuthenticatedBadge.AuthenticatedBadge, {
|
|
117
|
-
sessionId: frictionlessState.sessionId,
|
|
118
|
-
agent: frictionlessState.agent,
|
|
119
|
-
dapp: config.account.address ?? "",
|
|
120
|
-
userAccount: frictionlessState.userAccount,
|
|
121
|
-
provider: frictionlessState.provider,
|
|
122
|
-
callbacks
|
|
123
|
-
}));
|
|
124
|
-
} else if (captchaType === _prosopo_types.CaptchaType.image) {
|
|
125
|
-
const Procaptcha = await ProcaptchaLoader();
|
|
126
|
-
setComponentToRender(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(Procaptcha, {
|
|
127
|
-
config,
|
|
128
|
-
callbacks,
|
|
129
|
-
frictionlessState,
|
|
130
|
-
i18n,
|
|
131
|
-
autoStart: resumedAutoStart,
|
|
132
|
-
startCoords,
|
|
133
|
-
onSessionInvalidated,
|
|
134
|
-
container,
|
|
135
|
-
onReload
|
|
136
|
-
}, mountKey));
|
|
137
|
-
} else if (captchaType === _prosopo_types.CaptchaType.puzzle) {
|
|
138
|
-
const ProcaptchaPuzzle = await ProcaptchaPuzzleLoader();
|
|
139
|
-
setComponentToRender(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProcaptchaPuzzle, {
|
|
140
|
-
config,
|
|
141
|
-
callbacks,
|
|
142
|
-
frictionlessState,
|
|
143
|
-
i18n,
|
|
144
|
-
autoStart: resumedAutoStart,
|
|
145
|
-
startCoords,
|
|
146
|
-
onSessionInvalidated,
|
|
147
|
-
container
|
|
148
|
-
}, mountKey));
|
|
149
|
-
} else {
|
|
150
|
-
const ProcaptchaPow = await ProcaptchaPowLoader();
|
|
151
|
-
setComponentToRender(/* @__PURE__ */ (0, react_jsx_runtime.jsx)(ProcaptchaPow, {
|
|
152
|
-
config,
|
|
153
|
-
callbacks,
|
|
154
|
-
frictionlessState,
|
|
155
|
-
i18n,
|
|
156
|
-
onEscalate,
|
|
157
|
-
autoStart: resumedAutoStart,
|
|
158
|
-
startCoords,
|
|
159
|
-
onSessionInvalidated,
|
|
160
|
-
container
|
|
161
|
-
}, mountKey));
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
const start = async () => {
|
|
165
|
-
if (!(0, _prosopo_procaptcha_common.isSecureBrowserContext)()) {
|
|
166
|
-
const errorMessage = i18n.isInitialized ? i18n.t("WIDGET.INSECURE_CONTEXT") : "Procaptcha requires a secure (HTTPS) connection";
|
|
167
|
-
events.onError(new Error(errorMessage));
|
|
168
|
-
fallOverWithStyle(errorMessage, "WIDGET.INSECURE_CONTEXT");
|
|
169
|
-
return;
|
|
170
|
-
}
|
|
171
|
-
await (0, _prosopo_procaptcha_common.providerRetry)(async () => {
|
|
172
|
-
stateRef.current.attemptCount += 1;
|
|
173
|
-
const result = await detectBot(_prosopo_types.ProcaptchaConfigSchema.parse(config), container, restart, { attempt: stateRef.current.attemptCount });
|
|
174
|
-
const guard = require_frictionlessResultGuard.evaluateFrictionlessResult(result);
|
|
175
|
-
if (guard.kind === "error") {
|
|
176
|
-
if (guard.retryable) throw new Error(guard.message);
|
|
177
|
-
stateRef.current = {
|
|
178
|
-
...stateRef.current,
|
|
179
|
-
loading: false,
|
|
180
|
-
errorMessage: guard.message
|
|
181
|
-
};
|
|
182
|
-
events.onError(new Error(guard.message));
|
|
183
|
-
fallOverWithStyle(guard.message, guard.key);
|
|
184
|
-
return;
|
|
185
|
-
}
|
|
186
|
-
const frictionlessState = {
|
|
187
|
-
provider: result.provider,
|
|
188
|
-
sessionId: result.sessionId,
|
|
189
|
-
userAccount: result.userAccount,
|
|
190
|
-
restart,
|
|
191
|
-
behaviorCollector1: result.behaviorCollector1,
|
|
192
|
-
behaviorCollector2: result.behaviorCollector2,
|
|
193
|
-
behaviorCollector3: result.behaviorCollector3,
|
|
194
|
-
deviceCapability: result.deviceCapability,
|
|
195
|
-
encryptBehavioralData: result.encryptBehavioralData,
|
|
196
|
-
getSimdReadings: result.getSimdReadings,
|
|
197
|
-
hp: result.hp,
|
|
198
|
-
agent: result.agent
|
|
199
|
-
};
|
|
200
|
-
await renderForCaptchaType(result.captchaType, frictionlessState);
|
|
201
|
-
stateRef.current = {
|
|
202
|
-
...stateRef.current,
|
|
203
|
-
loading: false
|
|
204
|
-
};
|
|
205
|
-
}, start, resetState, stateRef.current.attemptCount, 5).finally(() => {
|
|
206
|
-
if (stateRef.current.attemptCount >= 5) {
|
|
207
|
-
events.onError(/* @__PURE__ */ new Error("Cannot load CAPTCHA"));
|
|
208
|
-
fallOverWithStyle();
|
|
209
|
-
restartComponentTimeout();
|
|
210
|
-
}
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
const startManually = async (autoStart, coords) => {
|
|
214
|
-
if (manualStartedRef.current) return;
|
|
215
|
-
manualStartedRef.current = true;
|
|
216
|
-
pendingRetryCoordsRef.current = coords ?? null;
|
|
217
|
-
nextMountAutoStartRef.current = autoStart;
|
|
218
|
-
innerWidgetRenderedRef.current = false;
|
|
219
|
-
setComponentToRender(renderPlaceholder(config.theme, config.mode, stateRef.current.errorMessage, i18n.isInitialized, i18n.t, true));
|
|
220
|
-
await start();
|
|
221
|
-
};
|
|
222
|
-
manualCheckboxHandlerRef.current = async (event) => {
|
|
223
|
-
let x = 0;
|
|
224
|
-
let y = 0;
|
|
225
|
-
const nativeEvent = event.nativeEvent;
|
|
226
|
-
if ("clientX" in nativeEvent && "clientY" in nativeEvent) {
|
|
227
|
-
x = nativeEvent.clientX;
|
|
228
|
-
y = nativeEvent.clientY;
|
|
229
|
-
}
|
|
230
|
-
await startManually(true, require_sessionInvalidatedRecovery.normaliseRetryCoords(x, y) ?? void 0);
|
|
231
|
-
};
|
|
232
|
-
(0, react.useEffect)(() => {
|
|
233
|
-
if (!manualStart) return;
|
|
234
|
-
const onStartEvent = (event) => {
|
|
235
|
-
const detail = event.detail;
|
|
236
|
-
if (detail?.element && container && !detail.element.contains(container)) return;
|
|
237
|
-
startManually(false);
|
|
238
|
-
};
|
|
239
|
-
const onExecuteEvent = () => {
|
|
240
|
-
startManually(true);
|
|
241
|
-
};
|
|
242
|
-
document.addEventListener(_prosopo_types.PROCAPTCHA_START_EVENT, onStartEvent);
|
|
243
|
-
document.addEventListener(PROCAPTCHA_EXECUTE_EVENT, onExecuteEvent);
|
|
244
|
-
return () => {
|
|
245
|
-
document.removeEventListener(_prosopo_types.PROCAPTCHA_START_EVENT, onStartEvent);
|
|
246
|
-
document.removeEventListener(PROCAPTCHA_EXECUTE_EVENT, onExecuteEvent);
|
|
247
|
-
};
|
|
248
|
-
}, [manualStart, container]);
|
|
249
|
-
(0, react.useEffect)(() => {
|
|
250
|
-
if (manualStart) return;
|
|
251
|
-
const invisible = config.mode === _prosopo_types.ModeEnum.invisible;
|
|
252
|
-
const onExecuteEvent = () => {
|
|
253
|
-
if (!innerWidgetListeningRef.current) pendingExecuteRef.current = true;
|
|
254
|
-
};
|
|
255
|
-
container?.addEventListener(PROCAPTCHA_EXECUTE_EVENT, onExecuteEvent);
|
|
256
|
-
if (invisible) document.addEventListener(PROCAPTCHA_EXECUTE_EVENT, onExecuteEvent);
|
|
257
|
-
return () => {
|
|
258
|
-
container?.removeEventListener(PROCAPTCHA_EXECUTE_EVENT, onExecuteEvent);
|
|
259
|
-
if (invisible) document.removeEventListener(PROCAPTCHA_EXECUTE_EVENT, onExecuteEvent);
|
|
260
|
-
};
|
|
261
|
-
}, [
|
|
262
|
-
manualStart,
|
|
263
|
-
config.mode,
|
|
264
|
-
container
|
|
265
|
-
]);
|
|
266
|
-
(0, react.useEffect)(() => {
|
|
267
|
-
innerWidgetListeningRef.current = innerWidgetRenderedRef.current;
|
|
268
|
-
if (!innerWidgetListeningRef.current || !pendingExecuteRef.current) return;
|
|
269
|
-
pendingExecuteRef.current = false;
|
|
270
|
-
(container ?? document).dispatchEvent(new CustomEvent(PROCAPTCHA_EXECUTE_EVENT));
|
|
271
|
-
}, [componentToRender, container]);
|
|
272
|
-
const startedForKeyRef = (0, react.useRef)(null);
|
|
273
|
-
(0, react.useEffect)(() => {
|
|
274
|
-
const key = `${config.account?.address ?? ""}|${config.language ?? ""}|${config.mode ?? ""}`;
|
|
275
|
-
if (startedForKeyRef.current === key) return;
|
|
276
|
-
startedForKeyRef.current = key;
|
|
277
|
-
if (manualStart) return;
|
|
278
|
-
start();
|
|
279
|
-
}, [
|
|
280
|
-
config.account?.address,
|
|
281
|
-
config.language,
|
|
282
|
-
config.mode
|
|
283
|
-
]);
|
|
284
|
-
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)(_prosopo_procaptcha_common.TestModeBanner, { siteKey: config.account?.address ?? "" }), componentToRender] });
|
|
285
|
-
};
|
|
286
|
-
//#endregion
|
|
287
|
-
exports.ProcaptchaFrictionless = ProcaptchaFrictionless;
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
// Copyright 2021-2026 Prosopo (UK) Ltd.
|
|
2
|
-
//
|
|
3
|
-
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
// you may not use this file except in compliance with the License.
|
|
5
|
-
// You may obtain a copy of the License at
|
|
6
|
-
//
|
|
7
|
-
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
-
//
|
|
9
|
-
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
-
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
-
// See the License for the specific language governing permissions and
|
|
13
|
-
// limitations under the License.
|
|
14
|
-
|
|
15
|
-
// Widget for the `authenticated` captcha outcome — no user-facing challenge,
|
|
16
|
-
// just a visible acknowledgement that Web Bot Auth verification succeeded.
|
|
17
|
-
// Mounts once, immediately encodes a ProcaptchaToken with the sessionId as
|
|
18
|
-
// its commitmentId (matching what /client/authenticated/verify decodes) and
|
|
19
|
-
// fires `onHuman`. The badge itself is purely presentational; the token
|
|
20
|
-
// submission happens in the mount effect.
|
|
21
|
-
//
|
|
22
|
-
// The token carries empty signature bags (`{provider: {}, user: {}}`) — the
|
|
23
|
-
// authenticated verify endpoint does not check the token's user or provider
|
|
24
|
-
// signatures because there was no captcha challenge to sign. Only the dApp
|
|
25
|
-
// server's signature on the timestamp is checked at verify time, and that
|
|
26
|
-
// is applied by the dApp on the way to /verify (not by the widget here).
|
|
27
|
-
|
|
28
|
-
import { getDefaultEvents } from "@prosopo/procaptcha-common";
|
|
29
|
-
import {
|
|
30
|
-
type Account,
|
|
31
|
-
ApiParams,
|
|
32
|
-
CaptchaType,
|
|
33
|
-
type ProcaptchaCallbacks,
|
|
34
|
-
type RandomProvider,
|
|
35
|
-
encodeProcaptchaOutput,
|
|
36
|
-
} from "@prosopo/types";
|
|
37
|
-
import { type FC, useEffect, useRef } from "react";
|
|
38
|
-
|
|
39
|
-
export type AuthenticatedBadgeProps = {
|
|
40
|
-
sessionId: string;
|
|
41
|
-
agent?: string;
|
|
42
|
-
dapp: string;
|
|
43
|
-
userAccount: Account;
|
|
44
|
-
provider: RandomProvider;
|
|
45
|
-
callbacks: ProcaptchaCallbacks;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const displayHost = (agent?: string): string => {
|
|
49
|
-
if (!agent) return "unknown";
|
|
50
|
-
try {
|
|
51
|
-
return new URL(agent).hostname;
|
|
52
|
-
} catch {
|
|
53
|
-
return agent;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
export const AuthenticatedBadge: FC<AuthenticatedBadgeProps> = ({
|
|
58
|
-
sessionId,
|
|
59
|
-
agent,
|
|
60
|
-
dapp,
|
|
61
|
-
userAccount,
|
|
62
|
-
provider,
|
|
63
|
-
callbacks,
|
|
64
|
-
}) => {
|
|
65
|
-
// One-shot: React 18 StrictMode double-invokes effects in development;
|
|
66
|
-
// this guard makes sure the token is emitted exactly once even under
|
|
67
|
-
// double-mount. Production doesn't double-invoke, so this is a
|
|
68
|
-
// belt-and-braces against local-dev confusion.
|
|
69
|
-
const emittedRef = useRef(false);
|
|
70
|
-
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (emittedRef.current) return;
|
|
73
|
-
emittedRef.current = true;
|
|
74
|
-
const events = getDefaultEvents(callbacks);
|
|
75
|
-
const token = encodeProcaptchaOutput({
|
|
76
|
-
[ApiParams.providerUrl]: provider.provider.url,
|
|
77
|
-
[ApiParams.user]: userAccount.account.address,
|
|
78
|
-
[ApiParams.dapp]: dapp,
|
|
79
|
-
// Verify endpoint reads commitmentId as the sessionId — reusing
|
|
80
|
-
// the existing slot avoids a token codec bump for this one flow.
|
|
81
|
-
[ApiParams.commitmentId]: sessionId,
|
|
82
|
-
[ApiParams.timestamp]: Date.now().toString(),
|
|
83
|
-
[ApiParams.signature]: {
|
|
84
|
-
[ApiParams.provider]: {},
|
|
85
|
-
[ApiParams.user]: {},
|
|
86
|
-
},
|
|
87
|
-
[ApiParams.captchaType]: CaptchaType.authenticated,
|
|
88
|
-
});
|
|
89
|
-
events.onHuman(token);
|
|
90
|
-
}, [sessionId, dapp, userAccount, provider, callbacks]);
|
|
91
|
-
|
|
92
|
-
return (
|
|
93
|
-
<div
|
|
94
|
-
style={{
|
|
95
|
-
display: "inline-flex",
|
|
96
|
-
alignItems: "center",
|
|
97
|
-
gap: 8,
|
|
98
|
-
padding: "8px 12px",
|
|
99
|
-
borderRadius: 6,
|
|
100
|
-
background: "#eef2ff",
|
|
101
|
-
border: "1px solid #c7d2fe",
|
|
102
|
-
color: "#3730a3",
|
|
103
|
-
fontFamily:
|
|
104
|
-
"-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
|
|
105
|
-
fontSize: 13,
|
|
106
|
-
lineHeight: 1.4,
|
|
107
|
-
}}
|
|
108
|
-
// biome-ignore lint/a11y/useSemanticElements: doesn't make sense
|
|
109
|
-
role="status"
|
|
110
|
-
aria-label="Verified agent"
|
|
111
|
-
>
|
|
112
|
-
<svg
|
|
113
|
-
width="16"
|
|
114
|
-
height="16"
|
|
115
|
-
viewBox="0 0 24 24"
|
|
116
|
-
fill="none"
|
|
117
|
-
stroke="currentColor"
|
|
118
|
-
strokeWidth="2.5"
|
|
119
|
-
strokeLinecap="round"
|
|
120
|
-
strokeLinejoin="round"
|
|
121
|
-
aria-hidden="true"
|
|
122
|
-
>
|
|
123
|
-
<title>Verified</title>
|
|
124
|
-
<path d="M20 6L9 17l-5-5" />
|
|
125
|
-
</svg>
|
|
126
|
-
<span>
|
|
127
|
-
{agent ? (
|
|
128
|
-
<>
|
|
129
|
-
<strong>Verified agent</strong>: {displayHost(agent)}
|
|
130
|
-
</>
|
|
131
|
-
) : (
|
|
132
|
-
// No Signature-Agent URL on the response — the operator's Allow
|
|
133
|
-
// rule matched on a non-Web-Bot-Auth condition (IP CIDR, JA4,
|
|
134
|
-
// UA substring, ASN, country). Fall back to generic copy so
|
|
135
|
-
// the operator isn't misled about which qualifier fired.
|
|
136
|
-
<strong>Trusted request</strong>
|
|
137
|
-
)}
|
|
138
|
-
</span>
|
|
139
|
-
</div>
|
|
140
|
-
);
|
|
141
|
-
};
|