@naughtbot/sdk 0.0.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/dist/widget.js ADDED
@@ -0,0 +1,398 @@
1
+ /**
2
+ * QR code widget for NaughtBot captcha.
3
+ * Renders a QR code, shows SAS words/emojis, handles lifecycle.
4
+ *
5
+ * Uses safe DOM APIs (createElement, textContent) instead of innerHTML.
6
+ */
7
+ import { createSession } from "./captcha.js";
8
+ import { createBLESession, isBLESupported } from "./ble.js";
9
+ // Widget CSS class prefix
10
+ const CLS = "naughtbot";
11
+ /**
12
+ * Create a captcha widget in the specified container.
13
+ *
14
+ * @param container - CSS selector or DOM element
15
+ * @param options - Widget options
16
+ * @returns Widget instance
17
+ */
18
+ export async function createWidget(container, options) {
19
+ const maybeEl = typeof container === "string" ? document.querySelector(container) : container;
20
+ if (!maybeEl) {
21
+ throw new Error(`Container not found: ${container}`);
22
+ }
23
+ const el = maybeEl;
24
+ let session = null;
25
+ let destroyed = false;
26
+ const mode = options.mode ?? "qr";
27
+ const useBLE = mode === "ble" || (mode === "auto" && isBLESupported());
28
+ injectStyles();
29
+ if (useBLE) {
30
+ // BLE mode: show a connect button (Web Bluetooth requires user gesture)
31
+ renderInto(el, buildBLEPrompt(() => startBLESession()));
32
+ }
33
+ else {
34
+ // QR mode: create relay session immediately
35
+ renderInto(el, buildState("initializing", null, null));
36
+ startQRSession();
37
+ }
38
+ function startBLESession() {
39
+ renderInto(el, buildState("initializing", null, null));
40
+ createBLESession(options)
41
+ .then((bleSession) => {
42
+ if (destroyed)
43
+ return;
44
+ session = bleSession;
45
+ wireSession(bleSession);
46
+ })
47
+ .catch((error) => {
48
+ if (destroyed)
49
+ return;
50
+ // In auto mode, fall back to QR if BLE fails (user cancelled picker, etc.)
51
+ if (mode === "auto") {
52
+ startQRSession();
53
+ return;
54
+ }
55
+ renderInto(el, buildState("error", null, null));
56
+ options.onError?.(error instanceof Error ? error : new Error(String(error)));
57
+ });
58
+ }
59
+ function startQRSession() {
60
+ createSession(options)
61
+ .then((qrSession) => {
62
+ if (destroyed)
63
+ return;
64
+ session = qrSession;
65
+ wireSession(qrSession);
66
+ renderInto(el, buildState("waiting_for_scan", qrSession.qrCodeUrl, null));
67
+ })
68
+ .catch((error) => {
69
+ if (!destroyed) {
70
+ renderInto(el, buildState("error", null, null));
71
+ options.onError?.(error instanceof Error ? error : new Error(String(error)));
72
+ }
73
+ });
74
+ }
75
+ function wireSession(s) {
76
+ s.onStateChange((state, sas) => {
77
+ if (destroyed)
78
+ return;
79
+ renderInto(el, buildState(state, s.qrCodeUrl, sas, useBLE ? () => s.confirmSAS() : null));
80
+ options.onStateChange?.(state);
81
+ });
82
+ s.waitForResult()
83
+ .then((result) => {
84
+ if (!destroyed) {
85
+ renderInto(el, buildState("verified", null, null));
86
+ options.onVerified(result);
87
+ }
88
+ })
89
+ .catch((error) => {
90
+ if (!destroyed) {
91
+ const err = error instanceof Error ? error : new Error(String(error));
92
+ if (err.message.includes("expired")) {
93
+ renderInto(el, buildState("expired", null, null));
94
+ options.onExpired?.();
95
+ }
96
+ else {
97
+ renderInto(el, buildState("error", null, null));
98
+ options.onError?.(err);
99
+ }
100
+ }
101
+ });
102
+ }
103
+ return {
104
+ destroy() {
105
+ destroyed = true;
106
+ session?.cancel();
107
+ while (el.firstChild)
108
+ el.removeChild(el.firstChild);
109
+ },
110
+ get session() {
111
+ return session;
112
+ },
113
+ };
114
+ }
115
+ // --- Safe DOM rendering helpers ---
116
+ /** Build a BLE connect prompt (button requires user gesture for Web Bluetooth) */
117
+ function buildBLEPrompt(onClick) {
118
+ const wrapper = document.createElement("div");
119
+ wrapper.className = `${CLS}-widget ${CLS}-ble-prompt`;
120
+ wrapper.appendChild(buildBrand());
121
+ const btn = document.createElement("button");
122
+ btn.className = `${CLS}-ble-btn`;
123
+ btn.textContent = "Connect via Bluetooth";
124
+ btn.addEventListener("click", onClick);
125
+ wrapper.appendChild(btn);
126
+ const hint = document.createElement("p");
127
+ hint.className = `${CLS}-hint`;
128
+ hint.textContent = "Connects to nearby NaughtBot device";
129
+ wrapper.appendChild(hint);
130
+ return wrapper;
131
+ }
132
+ /** Replace all children of a container with the given element */
133
+ function renderInto(container, child) {
134
+ while (container.firstChild)
135
+ container.removeChild(container.firstChild);
136
+ container.appendChild(child);
137
+ }
138
+ /** Build the widget DOM for a given state */
139
+ function buildState(state, qrCodeUrl, sas, onConfirmSAS) {
140
+ const wrapper = document.createElement("div");
141
+ wrapper.className = `${CLS}-widget ${CLS}-${state}`;
142
+ switch (state) {
143
+ case "initializing":
144
+ case "verifying": {
145
+ wrapper.appendChild(buildSpinner());
146
+ const label = document.createElement("p");
147
+ label.className = `${CLS}-label`;
148
+ label.textContent = state === "initializing" ? "Initializing..." : "Verifying...";
149
+ wrapper.appendChild(label);
150
+ break;
151
+ }
152
+ case "waiting_for_scan": {
153
+ wrapper.appendChild(buildBrand());
154
+ if (qrCodeUrl) {
155
+ wrapper.appendChild(buildQR(qrCodeUrl));
156
+ }
157
+ const hint = document.createElement("p");
158
+ hint.className = `${CLS}-hint`;
159
+ hint.textContent = "Scan with NaughtBot app";
160
+ wrapper.appendChild(hint);
161
+ break;
162
+ }
163
+ case "phone_connected":
164
+ case "sas_verification": {
165
+ wrapper.appendChild(buildBrand());
166
+ const instruction = document.createElement("p");
167
+ instruction.className = `${CLS}-hint`;
168
+ instruction.textContent = "Verify this code matches your phone:";
169
+ wrapper.appendChild(instruction);
170
+ if (sas) {
171
+ wrapper.appendChild(buildSASDisplay(sas));
172
+ // In BLE mode, show a "Confirm Match" button for user to confirm SAS
173
+ if (onConfirmSAS) {
174
+ const confirmBtn = document.createElement("button");
175
+ confirmBtn.className = `${CLS}-ble-btn`;
176
+ confirmBtn.textContent = "Confirm Match";
177
+ confirmBtn.addEventListener("click", onConfirmSAS);
178
+ wrapper.appendChild(confirmBtn);
179
+ }
180
+ }
181
+ else {
182
+ const connecting = document.createElement("p");
183
+ connecting.className = `${CLS}-label`;
184
+ connecting.textContent = "Connecting...";
185
+ wrapper.appendChild(connecting);
186
+ }
187
+ break;
188
+ }
189
+ case "verified": {
190
+ const checkmark = document.createElement("div");
191
+ checkmark.className = `${CLS}-checkmark`;
192
+ // Use a Unicode checkmark rendered in a styled circle (no innerHTML)
193
+ const icon = document.createElement("span");
194
+ icon.textContent = "\u2713";
195
+ icon.className = `${CLS}-checkmark-icon`;
196
+ checkmark.appendChild(icon);
197
+ wrapper.appendChild(checkmark);
198
+ const label = document.createElement("p");
199
+ label.className = `${CLS}-verified-label`;
200
+ label.textContent = "Verified";
201
+ wrapper.appendChild(label);
202
+ break;
203
+ }
204
+ case "expired": {
205
+ const label = document.createElement("p");
206
+ label.className = `${CLS}-expired-label`;
207
+ label.textContent = "Session expired";
208
+ wrapper.appendChild(label);
209
+ break;
210
+ }
211
+ case "error": {
212
+ const label = document.createElement("p");
213
+ label.className = `${CLS}-error-label`;
214
+ label.textContent = "Verification failed";
215
+ wrapper.appendChild(label);
216
+ break;
217
+ }
218
+ }
219
+ return wrapper;
220
+ }
221
+ function buildBrand() {
222
+ const brand = document.createElement("div");
223
+ brand.className = `${CLS}-brand`;
224
+ const naught = document.createElement("span");
225
+ naught.className = `${CLS}-brand-naught`;
226
+ naught.textContent = "Naught";
227
+ const bot = document.createElement("span");
228
+ bot.textContent = "Bot";
229
+ brand.appendChild(naught);
230
+ brand.appendChild(bot);
231
+ return brand;
232
+ }
233
+ function buildSpinner() {
234
+ const spinner = document.createElement("div");
235
+ spinner.className = `${CLS}-spinner`;
236
+ return spinner;
237
+ }
238
+ function buildQR(url) {
239
+ const container = document.createElement("div");
240
+ container.className = `${CLS}-qr`;
241
+ // Consumers should use this attribute with a real QR library (e.g., qrcode.js)
242
+ // to render a scannable QR code over or in place of the placeholder
243
+ container.dataset.naughtbotQrUrl = url;
244
+ const canvas = document.createElement("canvas");
245
+ canvas.width = 180;
246
+ canvas.height = 180;
247
+ canvas.className = `${CLS}-qr-canvas`;
248
+ const ctx = canvas.getContext("2d");
249
+ if (ctx) {
250
+ drawQRPlaceholder(ctx, 180);
251
+ }
252
+ container.appendChild(canvas);
253
+ // Dispatch a custom event so integrators can render a real QR code
254
+ setTimeout(() => {
255
+ container.dispatchEvent(new CustomEvent("naughtbot:qr-ready", { detail: { url }, bubbles: true }));
256
+ }, 0);
257
+ return container;
258
+ }
259
+ /** Draw a simple QR-like finder pattern placeholder */
260
+ function drawQRPlaceholder(ctx, size) {
261
+ const dark = "#172031";
262
+ const accent = "#dd4541";
263
+ const m = 10; // margin
264
+ const fp = 40; // finder pattern size
265
+ ctx.fillStyle = "white";
266
+ ctx.fillRect(0, 0, size, size);
267
+ // Three finder patterns (top-left, top-right, bottom-left)
268
+ for (const [x, y] of [
269
+ [m, m],
270
+ [size - m - fp, m],
271
+ [m, size - m - fp],
272
+ ]) {
273
+ ctx.fillStyle = dark;
274
+ roundRect(ctx, x, y, fp, fp, 4);
275
+ ctx.fill();
276
+ ctx.fillStyle = "white";
277
+ roundRect(ctx, x + 7, y + 7, fp - 14, fp - 14, 2);
278
+ ctx.fill();
279
+ ctx.fillStyle = dark;
280
+ roundRect(ctx, x + 13, y + 13, fp - 26, fp - 26, 1);
281
+ ctx.fill();
282
+ }
283
+ // Accent center dot
284
+ ctx.fillStyle = accent;
285
+ roundRect(ctx, size / 2 - 10, size / 2 - 10, 20, 20, 3);
286
+ ctx.fill();
287
+ // Some timing pattern dots
288
+ ctx.fillStyle = dark;
289
+ for (let i = 0; i < 5; i++) {
290
+ const dotX = 58 + i * 8;
291
+ if (i % 2 === 0) {
292
+ ctx.fillRect(dotX, 22, 6, 6);
293
+ ctx.fillRect(22, dotX, 6, 6);
294
+ }
295
+ }
296
+ // Label so it's clear this is a placeholder, not a scannable QR code
297
+ ctx.fillStyle = "#94a3b8";
298
+ ctx.font = "bold 10px sans-serif";
299
+ ctx.textAlign = "center";
300
+ ctx.fillText("QR PLACEHOLDER", size / 2, size - 6);
301
+ }
302
+ function roundRect(ctx, x, y, w, h, r) {
303
+ ctx.beginPath();
304
+ ctx.moveTo(x + r, y);
305
+ ctx.lineTo(x + w - r, y);
306
+ ctx.quadraticCurveTo(x + w, y, x + w, y + r);
307
+ ctx.lineTo(x + w, y + h - r);
308
+ ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
309
+ ctx.lineTo(x + r, y + h);
310
+ ctx.quadraticCurveTo(x, y + h, x, y + h - r);
311
+ ctx.lineTo(x, y + r);
312
+ ctx.quadraticCurveTo(x, y, x + r, y);
313
+ ctx.closePath();
314
+ }
315
+ function buildSASDisplay(sas) {
316
+ const container = document.createElement("div");
317
+ container.className = `${CLS}-sas`;
318
+ const emojis = document.createElement("div");
319
+ emojis.className = `${CLS}-sas-emojis`;
320
+ emojis.textContent = sas.emojis.join(" ");
321
+ container.appendChild(emojis);
322
+ const words = document.createElement("div");
323
+ words.className = `${CLS}-sas-words`;
324
+ words.textContent = sas.wordString;
325
+ container.appendChild(words);
326
+ return container;
327
+ }
328
+ // --- Stylesheet injection (once per page) ---
329
+ let stylesInjected = false;
330
+ function injectStyles() {
331
+ if (stylesInjected || typeof document === "undefined")
332
+ return;
333
+ const existingStyle = document.getElementById("naughtbot-widget-styles");
334
+ if (existingStyle) {
335
+ stylesInjected = true;
336
+ return;
337
+ }
338
+ stylesInjected = true;
339
+ const style = document.createElement("style");
340
+ style.id = "naughtbot-widget-styles";
341
+ style.textContent = `
342
+ .${CLS}-widget {
343
+ display: flex;
344
+ flex-direction: column;
345
+ align-items: center;
346
+ justify-content: center;
347
+ padding: 16px;
348
+ font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
349
+ min-height: 200px;
350
+ border: 1px solid #e0e0e0;
351
+ border-radius: 12px;
352
+ background: #fafafa;
353
+ }
354
+ .${CLS}-spinner {
355
+ width: 24px;
356
+ height: 24px;
357
+ border: 3px solid #ddd;
358
+ border-top-color: #dd4541;
359
+ border-radius: 50%;
360
+ animation: ${CLS}-spin 0.8s linear infinite;
361
+ }
362
+ @keyframes ${CLS}-spin { to { transform: rotate(360deg); } }
363
+ .${CLS}-label { margin: 12px 0 0; color: #666; font-size: 14px; }
364
+ .${CLS}-hint { margin: 0 0 12px; color: #666; font-size: 13px; }
365
+ .${CLS}-brand { font-weight: 600; font-size: 16px; color: #172031; margin-bottom: 12px; }
366
+ .${CLS}-brand-naught { color: #dd4541; }
367
+ .${CLS}-qr {
368
+ width: 180px;
369
+ height: 180px;
370
+ background: white;
371
+ border: 2px solid #e0e0e0;
372
+ border-radius: 8px;
373
+ display: flex;
374
+ align-items: center;
375
+ justify-content: center;
376
+ }
377
+ .${CLS}-qr-canvas { display: block; }
378
+ .${CLS}-sas { text-align: center; }
379
+ .${CLS}-sas-emojis { font-size: 28px; letter-spacing: 4px; margin-bottom: 8px; }
380
+ .${CLS}-sas-words { font-size: 14px; font-weight: 600; color: #172031; letter-spacing: 1px; font-family: monospace; }
381
+ .${CLS}-checkmark {
382
+ width: 48px; height: 48px; border-radius: 50%; background: #22c55e;
383
+ display: flex; align-items: center; justify-content: center;
384
+ }
385
+ .${CLS}-checkmark-icon { color: white; font-size: 24px; font-weight: bold; }
386
+ .${CLS}-verified-label { margin: 12px 0 0; color: #22c55e; font-size: 14px; font-weight: 600; }
387
+ .${CLS}-expired-label { color: #94a3b8; font-size: 14px; }
388
+ .${CLS}-error-label { color: #dd4541; font-size: 14px; }
389
+ .${CLS}-ble-btn {
390
+ padding: 10px 24px; border: none; border-radius: 8px;
391
+ background: #dd4541; color: white; font-size: 14px; font-weight: 600;
392
+ cursor: pointer; margin-bottom: 8px;
393
+ }
394
+ .${CLS}-ble-btn:hover { background: #c33b38; }
395
+ `;
396
+ document.head.appendChild(style);
397
+ }
398
+ //# sourceMappingURL=widget.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"widget.js","sourceRoot":"","sources":["../src/widget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,aAAa,EAAuB,MAAM,cAAc,CAAC;AACl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H,GAAG;;;;;OAKH,GAAG;GACP,CAAC;IACF,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "author": "NaughtBot",
3
+ "dependencies": {
4
+ "@naughtbot/api": "^0.1.0"
5
+ },
6
+ "peerDependencies": {
7
+ "@ackagent/web-sdk": "^0.1.0"
8
+ },
9
+ "description": "NaughtBot captcha SDK — cryptographic proof of human interaction via biometric verification",
10
+ "devDependencies": {
11
+ "@ackagent/web-sdk": "^0.1.0",
12
+ "@biomejs/biome": "2.3.14",
13
+ "@types/node": "^25.0.3",
14
+ "@vitest/coverage-v8": "^4.0.16",
15
+ "typescript": "^5.3.0",
16
+ "vitest": "^4.0.16"
17
+ },
18
+ "engines": {
19
+ "node": ">=20.0.0"
20
+ },
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.js",
24
+ "types": "./dist/index.d.ts"
25
+ }
26
+ },
27
+ "files": [
28
+ "dist",
29
+ "README.md"
30
+ ],
31
+ "keywords": [
32
+ "naughtbot",
33
+ "captcha",
34
+ "biometric",
35
+ "bbs-plus",
36
+ "anonymous-attestation",
37
+ "e2e-encryption"
38
+ ],
39
+ "license": "MIT",
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "git+https://github.com/naughtbot/sdk.git"
43
+ },
44
+ "main": "./dist/index.js",
45
+ "name": "@naughtbot/sdk",
46
+ "publishConfig": {
47
+ "access": "public"
48
+ },
49
+ "type": "module",
50
+ "types": "./dist/index.d.ts",
51
+ "version": "0.0.1",
52
+ "scripts": {
53
+ "build": "tsc",
54
+ "clean": "rm -rf dist",
55
+ "format": "biome format --write src/",
56
+ "format:check": "biome format src/",
57
+ "lint": "biome lint src/",
58
+ "test": "vitest run",
59
+ "test:coverage": "vitest run --coverage",
60
+ "test:watch": "vitest"
61
+ }
62
+ }