|
| 1 | +# @webdecoy/client |
| 2 | + |
| 3 | +Browser widget for [WebDecoy](https://github.com/WebDecoy/node-sdk) captcha — collects behavioral, environmental, and fingerprint signals, solves a SHA-256 proof-of-work, and submits to your WebDecoy-protected server. |
| 4 | + |
| 5 | +[](https://www.npmjs.com/package/@webdecoy/client) |
| 6 | +[](https://opensource.org/licenses/MIT) |
| 7 | + |
| 8 | +Pairs with the in-process detection engine in [`@webdecoy/node`](https://www.npmjs.com/package/@webdecoy/node). |
| 9 | + |
| 10 | +## Installation |
| 11 | + |
| 12 | +```bash |
| 13 | +npm install @webdecoy/client |
| 14 | +``` |
| 15 | + |
| 16 | +Or load the standalone bundle directly via `<script>`: |
| 17 | + |
| 18 | +```html |
| 19 | +<script src="https://unpkg.com/@webdecoy/client/dist/webdecoy.global.js"></script> |
| 20 | +``` |
| 21 | + |
| 22 | +## Usage |
| 23 | + |
| 24 | +### Checkbox widget |
| 25 | + |
| 26 | +```html |
| 27 | +<div id="captcha-box"></div> |
| 28 | +<script type="module"> |
| 29 | + import { WebDecoyCaptcha } from '@webdecoy/client'; |
| 30 | +
|
| 31 | + WebDecoyCaptcha.configure({ serverUrl: 'https://your-server.com' }); |
| 32 | + const id = WebDecoyCaptcha.render('captcha-box', { |
| 33 | + siteKey: 'pk_live_...', |
| 34 | + theme: 'light', |
| 35 | + callback: (token) => console.log('verified:', token), |
| 36 | + }); |
| 37 | +
|
| 38 | + // Later: WebDecoyCaptcha.getResponse(id) → token |
| 39 | +</script> |
| 40 | +``` |
| 41 | + |
| 42 | +### Auto-init (no JS) |
| 43 | + |
| 44 | +```html |
| 45 | +<div data-webdecoy="pk_live_..." data-endpoint="https://your-server.com"></div> |
| 46 | +<script src="https://unpkg.com/@webdecoy/client/dist/webdecoy.global.js"></script> |
| 47 | +``` |
| 48 | + |
| 49 | +### Invisible mode |
| 50 | + |
| 51 | +Passively scores the session and auto-protects form submissions (injects a |
| 52 | +hidden `webdecoy_token` field, scores on submit): |
| 53 | + |
| 54 | +```js |
| 55 | +import { WebDecoyCaptcha } from '@webdecoy/client'; |
| 56 | + |
| 57 | +WebDecoyCaptcha.configure({ serverUrl: 'https://your-server.com' }); |
| 58 | +WebDecoyCaptcha.invisible({ siteKey: 'pk_live_...' }); |
| 59 | +``` |
| 60 | + |
| 61 | +Or score on demand: |
| 62 | + |
| 63 | +```js |
| 64 | +const result = await WebDecoyCaptcha.execute('pk_live_...', { action: 'login' }); |
| 65 | +if (result.success) { /* result.token */ } |
| 66 | +``` |
| 67 | + |
| 68 | +## What it collects |
| 69 | + |
| 70 | +| Group | Signals | |
| 71 | +|-------|---------| |
| 72 | +| Behavioral | mouse trajectory/velocity/micro-tremor, click precision, touch kinematics, scroll, keystroke cadence | |
| 73 | +| Sensor | device motion/orientation entropy (mobile) | |
| 74 | +| Environmental | WebDriver/CDP/Playwright markers, canvas, WebGL, audio, fonts, WebRTC, speech, worker consistency, CSS media, permissions, DOMRect, RAF/JS timing | |
| 75 | +| Form | submit method, per-field textarea typing stats | |
| 76 | + |
| 77 | +Signals are hashed and bound into the proof-of-work so they can't be tampered |
| 78 | +with after solving. The server scores them with `@webdecoy/node`. |
| 79 | + |
| 80 | +## Server setup |
| 81 | + |
| 82 | +Mount the matching endpoints on your backend (default base path `/__webdecoy`): |
| 83 | + |
| 84 | +```js |
| 85 | +import express from 'express'; |
| 86 | +import { webdecoyCaptcha } from '@webdecoy/express'; |
| 87 | + |
| 88 | +const app = express(); |
| 89 | +app.use(express.json()); |
| 90 | +app.use(webdecoyCaptcha({ secret: process.env.WEBDECOY_SECRET })); |
| 91 | +``` |
| 92 | + |
| 93 | +See [`@webdecoy/node`](https://www.npmjs.com/package/@webdecoy/node) for Fastify |
| 94 | +and Next.js adapters and the full detection/scoring reference. |
| 95 | + |
| 96 | +## API |
| 97 | + |
| 98 | +- `WebDecoyCaptcha.configure({ serverUrl })` |
| 99 | +- `WebDecoyCaptcha.render(container, options) → widgetId` |
| 100 | +- `WebDecoyCaptcha.getResponse(widgetId) → token | null` |
| 101 | +- `WebDecoyCaptcha.reset(widgetId)` |
| 102 | +- `WebDecoyCaptcha.invisible(options) → InvisibleSession` |
| 103 | +- `WebDecoyCaptcha.execute(siteKey, { action, minTime, powDifficulty }) → Promise<result>` |
| 104 | +- `WebDecoyCaptcha.autoInit()` |
| 105 | + |
| 106 | +## License |
| 107 | + |
| 108 | +MIT |
0 commit comments