@assistant-ui/better-auth-dbsc 0.0.0-stage → 0.1.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.
@@ -0,0 +1,784 @@
1
+ import { D as DbscSessionConfig, E as DbscScopeRule, d as DbscAlgorithm, p as DbscPublicKey, r as DbscHeaderNames } from "./headers-KXqmHcXY.js";
2
+ import { InferOptionSchema } from "better-auth";
3
+ import { createAuthMiddleware } from "better-auth/api";
4
+ /** A session bound to a device key. */
5
+ interface DbscBinding {
6
+ sessionId: string;
7
+ userId: string;
8
+ publicKey: DbscPublicKey;
9
+ /** RFC 7638 thumbprint of `publicKey`. Two registrations agree when thumbprints match. */
10
+ thumbprint: string;
11
+ }
12
+ /** A proof that answers a challenge: a DBSC refresh, or a fresh proof for one action. */
13
+ type DbscProofKind = "refresh" | "fresh-proof";
14
+ /**
15
+ * Where bindings live. The default keeps them in a `dbscSession` table through Better
16
+ * Auth's adapter. Bring your own to keep them in Redis, a KV store, or an existing table.
17
+ */
18
+ interface DbscStore {
19
+ /** The binding for this session, or `null` for a plain session. */
20
+ find(sessionId: string): Promise<DbscBinding | null>;
21
+ /**
22
+ * Stores the binding unless the session already has one, and says whether it was
23
+ * stored. Must be atomic: two racing registrations bind at most one key.
24
+ */
25
+ bind(binding: DbscBinding): Promise<boolean>;
26
+ /**
27
+ * Spends a proof over a challenge issued at `issuedAtMs`. Answers `false` when that
28
+ * challenge, or a later one of the same kind, was spent already. Must be atomic: of
29
+ * two requests carrying the same proof, at most one gets `true`.
30
+ */
31
+ spend(sessionId: string, kind: DbscProofKind, issuedAtMs: number): Promise<boolean>;
32
+ /**
33
+ * Removes the binding and anything spent for it. Called whenever Better Auth deletes the
34
+ * session: sign-out, revocation, a deleted user, or an expired session it comes across.
35
+ * Better Auth leaves sessions that expire unseen in place, so prune bindings whose
36
+ * session is gone the same way you prune sessions.
37
+ */
38
+ delete(sessionId: string): Promise<void>;
39
+ }
40
+ declare const DBSC_MODEL = "dbscSession";
41
+ declare const dbscSchema: {
42
+ readonly dbscSession: {
43
+ readonly fields: {
44
+ readonly sessionId: {
45
+ readonly type: "string";
46
+ readonly required: true;
47
+ readonly unique: true;
48
+ readonly input: false;
49
+ readonly references: {
50
+ readonly model: "session";
51
+ readonly field: "id";
52
+ readonly onDelete: "cascade";
53
+ };
54
+ };
55
+ readonly userId: {
56
+ readonly type: "string";
57
+ readonly required: true;
58
+ readonly input: false;
59
+ readonly index: true;
60
+ readonly references: {
61
+ readonly model: "user";
62
+ readonly field: "id";
63
+ readonly onDelete: "cascade";
64
+ };
65
+ };
66
+ /** The device's public JWK, JSON-encoded, with `alg`. */
67
+ readonly publicKey: {
68
+ readonly type: "string";
69
+ readonly required: true;
70
+ readonly input: false;
71
+ };
72
+ readonly thumbprint: {
73
+ readonly type: "string";
74
+ readonly required: true;
75
+ readonly input: false;
76
+ };
77
+ /** Issue time of the newest refresh challenge spent. Older ones are refused. */
78
+ readonly lastRefreshAt: {
79
+ readonly type: "date";
80
+ readonly required: true;
81
+ readonly input: false;
82
+ };
83
+ /** Issue time of the newest fresh-proof challenge spent. */
84
+ readonly lastFreshProofAt: {
85
+ readonly type: "date";
86
+ readonly required: true;
87
+ readonly input: false;
88
+ };
89
+ /** How many proofs this binding has spent. */
90
+ readonly proofCount: {
91
+ readonly type: "number";
92
+ readonly required: true;
93
+ readonly defaultValue: 0;
94
+ readonly input: false;
95
+ };
96
+ readonly createdAt: {
97
+ readonly type: "date";
98
+ readonly required: true;
99
+ readonly input: false;
100
+ };
101
+ };
102
+ };
103
+ };
104
+ /** The slice of Better Auth's adapter the default store uses. */
105
+ interface DbscStoreAdapter {
106
+ findOne<T>(data: {
107
+ model: string;
108
+ where: {
109
+ field: string;
110
+ value: unknown;
111
+ }[];
112
+ }): Promise<T | null>;
113
+ create<T>(data: {
114
+ model: string;
115
+ data: Record<string, unknown>;
116
+ }): Promise<T>;
117
+ delete(data: {
118
+ model: string;
119
+ where: {
120
+ field: string;
121
+ value: unknown;
122
+ }[];
123
+ }): Promise<void>;
124
+ incrementOne<T>(data: {
125
+ model: string;
126
+ where: {
127
+ field: string;
128
+ value: unknown;
129
+ operator?: "lt" | "eq";
130
+ }[];
131
+ increment: Record<string, number>;
132
+ set?: Record<string, unknown>;
133
+ }): Promise<T | null>;
134
+ }
135
+ /**
136
+ * The default store: one `dbscSession` row per bound session, deleted with its session.
137
+ * `spend` is a guarded `incrementOne`, so a proof is spent once across every instance.
138
+ */
139
+ declare function createAdapterDbscStore(adapter: DbscStoreAdapter): DbscStore;
140
+ /** A store in process memory, for tests and single-instance development. */
141
+ declare function createMemoryDbscStore(): DbscStore & {
142
+ bindings: Map<string, DbscBinding>;
143
+ };
144
+ /** Error codes the plugin answers with. Also on `$ERROR_CODES` for the client. */
145
+ declare const DBSC_ERROR_CODES: {
146
+ DBSC_BINDING_REQUIRED: import("better-auth").RawError<"DBSC_BINDING_REQUIRED">;
147
+ DBSC_BOUND_TO_OTHER_KEY: import("better-auth").RawError<"DBSC_BOUND_TO_OTHER_KEY">;
148
+ DBSC_CHALLENGE_REQUIRED: import("better-auth").RawError<"DBSC_CHALLENGE_REQUIRED">;
149
+ DBSC_CREDENTIAL_REQUIRED: import("better-auth").RawError<"DBSC_CREDENTIAL_REQUIRED">;
150
+ DBSC_DISABLED: import("better-auth").RawError<"DBSC_DISABLED">;
151
+ DBSC_FRESH_PROOF_REQUIRED: import("better-auth").RawError<"DBSC_FRESH_PROOF_REQUIRED">;
152
+ DBSC_INVALID_CHALLENGE: import("better-auth").RawError<"DBSC_INVALID_CHALLENGE">;
153
+ DBSC_INVALID_PROOF: import("better-auth").RawError<"DBSC_INVALID_PROOF">;
154
+ DBSC_PROOF_REQUIRED: import("better-auth").RawError<"DBSC_PROOF_REQUIRED">;
155
+ DBSC_SESSION_ID_REQUIRED: import("better-auth").RawError<"DBSC_SESSION_ID_REQUIRED">;
156
+ DBSC_SESSION_REQUIRED: import("better-auth").RawError<"DBSC_SESSION_REQUIRED">;
157
+ };
158
+ declare const DBSC_REGISTER_PATH = "/dbsc/register";
159
+ declare const DBSC_REFRESH_PATH = "/dbsc/refresh";
160
+ /** Cookie keys passed to Better Auth's cookie factory, so `advanced.cookies.<key>` applies. */
161
+ declare const DBSC_COOKIE_KEYS: {
162
+ readonly bound: "dbsc_token";
163
+ readonly freshProof: "dbsc_fresh_proof";
164
+ };
165
+ /**
166
+ * What a session that is not bound to a device gets on a `freshProof` path.
167
+ *
168
+ * - `"allow"`: passes; the endpoint's own checks stand. Browsers without DBSC keep working.
169
+ * - `"fresh-session"`: passes only while the session is younger than Better Auth's
170
+ * `session.freshAge`, else `403 SESSION_NOT_FRESH`.
171
+ * - `"deny"`: `403 DBSC_BINDING_REQUIRED`. Only DBSC browsers get through: use it for
172
+ * the few routes that must resist malware reading the browser profile.
173
+ */
174
+ type DbscUnboundPolicy = "allow" | "fresh-session" | "deny";
175
+ interface DbscFreshProofRule {
176
+ /** Overrides `freshProof.unbound` for this path. */
177
+ unbound?: DbscUnboundPolicy;
178
+ }
179
+ type DbscRefusalReason = "invalid_challenge" | "invalid_proof" | "bound_to_other_key" | "disabled";
180
+ /**
181
+ * One DBSC event, for `onEvent`. Events carry session and user ids and reason codes,
182
+ * never keys, challenges, cookies, or tokens.
183
+ */
184
+ type DbscEvent = {
185
+ type: "registered";
186
+ sessionId: string;
187
+ userId: string;
188
+ } | {
189
+ type: "registration_refused";
190
+ sessionId: string;
191
+ userId: string;
192
+ reason: DbscRefusalReason;
193
+ } | {
194
+ type: "refreshed";
195
+ sessionId: string;
196
+ userId: string;
197
+ } | {
198
+ type: "refresh_challenged";
199
+ sessionId: string;
200
+ userId: string;
201
+ reason: "missing_proof" | "stale_challenge" | "replayed";
202
+ } |
203
+ /**
204
+ * A refresh for a bound session carried a proof the bound key did not sign: the
205
+ * strongest theft signal. The binding is untouched; revoke the session here if you
206
+ * would rather sign the owner out than let a thief keep trying.
207
+ */
208
+ {
209
+ type: "proof_rejected";
210
+ sessionId: string;
211
+ userId: string;
212
+ reason: string;
213
+ } |
214
+ /**
215
+ * A bound session arrived without a live bound cookie and was treated as signed out.
216
+ * Expected now and then from a real browser; a burst of them is a copied cookie.
217
+ */
218
+ {
219
+ type: "credential_missing";
220
+ sessionId: string;
221
+ userId: string;
222
+ via: DbscCarrier;
223
+ } | {
224
+ type: "fresh_proof_challenged";
225
+ sessionId: string;
226
+ userId: string;
227
+ action: string;
228
+ } | {
229
+ type: "fresh_proof_answered";
230
+ sessionId: string;
231
+ userId: string;
232
+ action: string;
233
+ } | {
234
+ type: "unbound_refused";
235
+ sessionId: string;
236
+ userId: string;
237
+ action: string;
238
+ policy: DbscUnboundPolicy;
239
+ } | {
240
+ type: "terminated";
241
+ reason: "disabled" | "no_session" | "not_bound" | "other_identifier";
242
+ };
243
+ /** Where a request carries a session token: see `dbsc()`'s gate. */
244
+ type DbscCarrier = "cookie" | "bearer" | "multi-session" | "admin-session";
245
+ type HookContext = Parameters<Parameters<typeof createAuthMiddleware>[0]>[0];
246
+ type AuthContext = HookContext["context"];
247
+ type Awaitable<T> = T | Promise<T>;
248
+ interface DbscOptions {
249
+ /**
250
+ * Turns DBSC on or off, read on every request. Off means nothing is read, written,
251
+ * advertised, or refused: bound sessions fall back to the plain session cookie at once,
252
+ * and browsers are told to end their DBSC sessions at the next refresh. Turning it back
253
+ * on restores every binding.
254
+ * @default true
255
+ */
256
+ enabled?: boolean | (() => Awaitable<boolean>);
257
+ /**
258
+ * Signing algorithms offered to the browser, in preference order.
259
+ * @default ["ES256", "RS256"]
260
+ */
261
+ algorithms?: DbscAlgorithm[];
262
+ /**
263
+ * Lifetime of the bound cookie, in seconds. When it lapses, the browser holds the next
264
+ * request and renews the cookie by signing a challenge with the device key.
265
+ * @default 300
266
+ */
267
+ boundCookieMaxAge?: number;
268
+ /**
269
+ * How long a registration or refresh challenge is accepted after it is issued, in seconds.
270
+ * @default 300
271
+ */
272
+ challengeExpiresIn?: number;
273
+ /** The DBSC session scope sent to the browser. */
274
+ scope?: {
275
+ /** Defaults to the origin of Better Auth's `baseURL`. */
276
+ origin?: string;
277
+ /**
278
+ * Cover every subdomain of the site, not only the origin. On a subdomain the browser
279
+ * first checks `/.well-known/device-bound-sessions` on the site.
280
+ * @default false
281
+ */
282
+ includeSite?: boolean;
283
+ /**
284
+ * Path prefixes the browser never holds a request for, such as static assets. The
285
+ * DBSC endpoints themselves are always excluded.
286
+ */
287
+ exclude?: string[];
288
+ /** Raw `scope_specification` rules, sent after `exclude`. */
289
+ rules?: DbscScopeRule[];
290
+ };
291
+ /**
292
+ * What happens to a bound session that arrives without a live bound cookie: its session
293
+ * cookie (and any `multiSession()` or `admin_session` cookie naming it) is dropped from
294
+ * the request, as if absent. Every endpoint then behaves as signed out, `getSession`
295
+ * answers `null`, and the session itself is untouched, so a copied cookie can never sign
296
+ * the owner out. A request with `Authorization: Bearer` that carries a bound session is
297
+ * refused with 401 unless the bound cookie proves it and the bearer token names that same
298
+ * session.
299
+ */
300
+ enforcement?: {
301
+ /**
302
+ * `false` binds sessions but never drops or refuses anything. For rollouts.
303
+ * @default true
304
+ */
305
+ enabled?: boolean;
306
+ /** Paths left alone. A trailing `/` matches child paths. */
307
+ exclude?: string[];
308
+ };
309
+ /**
310
+ * Endpoints whose effects outlast a copied cookie (adding a passkey, changing the
311
+ * email) and so need a proof made after the request arrived. On a bound session the
312
+ * first attempt is refused with `403 DBSC_FRESH_PROOF_REQUIRED` and the bound cookie
313
+ * removed; the browser refreshes with its key and the retry passes once. Use
314
+ * `auth.api.requireFreshProof` for your own routes.
315
+ */
316
+ freshProof?: {
317
+ /**
318
+ * Better Auth endpoint paths, such as `/change-email`, or a map of path to rule
319
+ * when some paths need a different `unbound` policy.
320
+ */
321
+ paths: string[] | Record<string, DbscFreshProofRule>;
322
+ /**
323
+ * What sessions that are not bound get on these paths.
324
+ * @default "allow"
325
+ */
326
+ unbound?: DbscUnboundPolicy;
327
+ /**
328
+ * How long a fresh-proof challenge waits for its retry, in seconds.
329
+ * @default 60
330
+ */
331
+ expiresIn?: number;
332
+ };
333
+ /**
334
+ * Rate limit for the register and refresh endpoints, per client address, through
335
+ * Better Auth's own limiter. Generous by default: an office shares one address.
336
+ */
337
+ rateLimit?: {
338
+ /** @default true */
339
+ enabled?: boolean;
340
+ /** In seconds. @default 60 */
341
+ window?: number;
342
+ /** @default 600 */
343
+ max?: number;
344
+ };
345
+ /**
346
+ * Called for registrations, refreshes, refusals, and theft signals, like the Stripe
347
+ * plugin's `onEvent`. Runs through Better Auth's background task handler when one is
348
+ * configured; a throw is logged and never changes the response.
349
+ */
350
+ onEvent?: (event: DbscEvent) => Awaitable<void>;
351
+ /**
352
+ * Decide whether a new session is offered DBSC. Runs only when a response issues a
353
+ * session token the request did not carry; session refreshes never re-register.
354
+ */
355
+ shouldRegister?: (ctx: HookContext) => Awaitable<boolean>;
356
+ /** The clock, in milliseconds. For tests. */
357
+ now?: () => number;
358
+ /**
359
+ * Where bindings live. Defaults to a `dbscSession` table through Better Auth's adapter.
360
+ * Pass a store, or a function that builds one from Better Auth's context.
361
+ */
362
+ store?: DbscStore | ((context: AuthContext) => DbscStore);
363
+ /** Rename the `dbscSession` model or its fields. */
364
+ schema?: InferOptionSchema<typeof dbscSchema>;
365
+ /** Protocol details. The defaults suit almost every app. */
366
+ advanced?: {
367
+ /**
368
+ * The browser keys DBSC sessions by site and this identifier, so one value per app
369
+ * means a new sign-in replaces the old DBSC session instead of piling up. Give apps
370
+ * that share a site different identifiers.
371
+ * @default "better-auth"
372
+ */
373
+ sessionIdentifier?: string;
374
+ /**
375
+ * Origins whose requests may make the browser refresh. `["*"]` lets a link or
376
+ * redirect from any site (an OAuth provider, another app) arrive with a fresh bound
377
+ * cookie instead of reading as signed out. Pass `[]` for same-site only.
378
+ * @default ["*"]
379
+ */
380
+ allowedRefreshInitiators?: string[];
381
+ /**
382
+ * Response header names to send: `Secure-Session-*` (`"standard"`), the origin
383
+ * trial's `Sec-Session-*` (`"legacy"`), or both. Request headers are always read
384
+ * under both names.
385
+ * @default "both"
386
+ */
387
+ headers?: DbscHeaderNames;
388
+ };
389
+ }
390
+ interface ResolvedDbscOptions {
391
+ enabled: () => Awaitable<boolean>;
392
+ algorithms: DbscAlgorithm[];
393
+ boundCookieMaxAge: number;
394
+ challengeExpiresIn: number;
395
+ scope: {
396
+ origin: string | undefined;
397
+ includeSite: boolean;
398
+ exclude: string[];
399
+ rules: DbscScopeRule[];
400
+ };
401
+ enforcement: {
402
+ enabled: boolean;
403
+ exclude: string[];
404
+ };
405
+ freshProof: {
406
+ paths: Map<string, DbscUnboundPolicy>;
407
+ expiresIn: number;
408
+ };
409
+ rateLimit: {
410
+ enabled: boolean;
411
+ window: number;
412
+ max: number;
413
+ };
414
+ onEvent: DbscOptions["onEvent"];
415
+ shouldRegister: DbscOptions["shouldRegister"];
416
+ now: () => number;
417
+ store: ((context: AuthContext) => DbscStore) | undefined;
418
+ advanced: {
419
+ sessionIdentifier: string;
420
+ allowedRefreshInitiators: string[];
421
+ headers: DbscHeaderNames;
422
+ };
423
+ }
424
+ /** Validates options and fills defaults. Every problem is reported at once. */
425
+ declare function resolveDbscOptions(options?: DbscOptions): ResolvedDbscOptions;
426
+ type FreshProofState = "off" | "no-session" | "unbound" | "answered" | "challenge";
427
+ type DbscStatusState = "off" | "no-session" | "unbound" | "bound";
428
+ /**
429
+ * Device Bound Session Credentials for Better Auth.
430
+ *
431
+ * Browsers that support DBSC bind the session to a hardware-backed key and keep a
432
+ * short-lived cookie fresh by signing server challenges. Browsers that do not ignore the
433
+ * registration header and keep using the plain session cookie.
434
+ */
435
+ declare const dbsc: <O extends DbscOptions>(options?: O) => {
436
+ id: "dbsc";
437
+ version: string;
438
+ schema: {
439
+ readonly dbscSession: {
440
+ readonly fields: {
441
+ readonly sessionId: {
442
+ readonly type: "string";
443
+ readonly required: true;
444
+ readonly unique: true;
445
+ readonly input: false;
446
+ readonly references: {
447
+ readonly model: "session";
448
+ readonly field: "id";
449
+ readonly onDelete: "cascade";
450
+ };
451
+ };
452
+ readonly userId: {
453
+ readonly type: "string";
454
+ readonly required: true;
455
+ readonly input: false;
456
+ readonly index: true;
457
+ readonly references: {
458
+ readonly model: "user";
459
+ readonly field: "id";
460
+ readonly onDelete: "cascade";
461
+ };
462
+ };
463
+ readonly publicKey: {
464
+ readonly type: "string";
465
+ readonly required: true;
466
+ readonly input: false;
467
+ };
468
+ readonly thumbprint: {
469
+ readonly type: "string";
470
+ readonly required: true;
471
+ readonly input: false;
472
+ };
473
+ readonly lastRefreshAt: {
474
+ readonly type: "date";
475
+ readonly required: true;
476
+ readonly input: false;
477
+ };
478
+ readonly lastFreshProofAt: {
479
+ readonly type: "date";
480
+ readonly required: true;
481
+ readonly input: false;
482
+ };
483
+ readonly proofCount: {
484
+ readonly type: "number";
485
+ readonly required: true;
486
+ readonly defaultValue: 0;
487
+ readonly input: false;
488
+ };
489
+ readonly createdAt: {
490
+ readonly type: "date";
491
+ readonly required: true;
492
+ readonly input: false;
493
+ };
494
+ };
495
+ };
496
+ };
497
+ init(ctx: import("better-auth").AuthContext): {
498
+ options: {
499
+ databaseHooks: {
500
+ session: {
501
+ delete: {
502
+ after(session: {
503
+ id: string;
504
+ }): Promise<void>;
505
+ };
506
+ };
507
+ };
508
+ };
509
+ context?: {
510
+ skipOriginCheck: string[];
511
+ } | undefined;
512
+ };
513
+ endpoints: {
514
+ /**
515
+ * ### Endpoint
516
+ *
517
+ * POST `/dbsc/register`
518
+ *
519
+ * ### API Methods
520
+ *
521
+ * **server:**
522
+ * `auth.api.registerDbscSession`
523
+ *
524
+ * The browser calls this itself: it posts a proof signed by its new key over the
525
+ * challenge from the sign-in response. Your code never needs to.
526
+ */
527
+ registerDbscSession: import("better-auth").StrictEndpoint<"/dbsc/register", {
528
+ method: "POST";
529
+ disableBody: true;
530
+ requireHeaders: true;
531
+ metadata: {
532
+ openapi: {
533
+ summary: string;
534
+ description: string;
535
+ responses: {
536
+ 200: {
537
+ readonly description: "The DBSC session config, as the browser expects it";
538
+ readonly content: {
539
+ readonly "application/json": {
540
+ readonly schema: {
541
+ readonly type: "object";
542
+ readonly properties: {
543
+ readonly session_identifier: {
544
+ readonly type: "string";
545
+ };
546
+ readonly refresh_url: {
547
+ readonly type: "string";
548
+ };
549
+ readonly scope: {
550
+ readonly type: "object";
551
+ };
552
+ readonly allowed_refresh_initiators: {
553
+ readonly type: "array";
554
+ readonly items: {
555
+ readonly type: "string";
556
+ };
557
+ };
558
+ readonly credentials: {
559
+ readonly type: "array";
560
+ readonly items: {
561
+ readonly type: "object";
562
+ };
563
+ };
564
+ readonly continue: {
565
+ readonly type: "boolean";
566
+ };
567
+ };
568
+ };
569
+ };
570
+ };
571
+ };
572
+ };
573
+ };
574
+ };
575
+ }, DbscSessionConfig>;
576
+ /**
577
+ * ### Endpoint
578
+ *
579
+ * POST `/dbsc/refresh`
580
+ *
581
+ * ### API Methods
582
+ *
583
+ * **server:**
584
+ * `auth.api.refreshDbscSession`
585
+ *
586
+ * The browser calls this itself when the bound cookie lapses. No proof, or a stale
587
+ * one: 403 with a new challenge. The bound key's proof: a new cookie. A session that
588
+ * is over or not bound ends the browser's DBSC session.
589
+ */
590
+ refreshDbscSession: import("better-auth").StrictEndpoint<"/dbsc/refresh", {
591
+ method: "POST";
592
+ disableBody: true;
593
+ requireHeaders: true;
594
+ metadata: {
595
+ openapi: {
596
+ summary: string;
597
+ description: string;
598
+ responses: {
599
+ 200: {
600
+ readonly description: "The DBSC session config, as the browser expects it";
601
+ readonly content: {
602
+ readonly "application/json": {
603
+ readonly schema: {
604
+ readonly type: "object";
605
+ readonly properties: {
606
+ readonly session_identifier: {
607
+ readonly type: "string";
608
+ };
609
+ readonly refresh_url: {
610
+ readonly type: "string";
611
+ };
612
+ readonly scope: {
613
+ readonly type: "object";
614
+ };
615
+ readonly allowed_refresh_initiators: {
616
+ readonly type: "array";
617
+ readonly items: {
618
+ readonly type: "string";
619
+ };
620
+ };
621
+ readonly credentials: {
622
+ readonly type: "array";
623
+ readonly items: {
624
+ readonly type: "object";
625
+ };
626
+ };
627
+ readonly continue: {
628
+ readonly type: "boolean";
629
+ };
630
+ };
631
+ };
632
+ };
633
+ };
634
+ };
635
+ 403: {
636
+ description: string;
637
+ };
638
+ };
639
+ };
640
+ };
641
+ }, DbscSessionConfig | {
642
+ readonly continue: false;
643
+ }>;
644
+ /**
645
+ * ### Endpoint
646
+ *
647
+ * GET `/dbsc/get-status`
648
+ *
649
+ * ### API Methods
650
+ *
651
+ * **server:**
652
+ * `auth.api.getDbscStatus`
653
+ *
654
+ * **client:**
655
+ * `authClient.dbsc.getStatus`
656
+ *
657
+ * Whether the current session is bound to this device:
658
+ * `{ state: "bound" | "unbound" | "no-session" | "off" }`. For a "this device is
659
+ * protected" line in account settings.
660
+ */
661
+ getDbscStatus: import("better-auth").StrictEndpoint<"/dbsc/get-status", {
662
+ method: "GET";
663
+ requireHeaders: true;
664
+ metadata: {
665
+ openapi: {
666
+ summary: string;
667
+ description: string;
668
+ responses: {
669
+ 200: {
670
+ description: string;
671
+ content: {
672
+ "application/json": {
673
+ schema: {
674
+ type: "object";
675
+ properties: {
676
+ state: {
677
+ type: string;
678
+ enum: string[];
679
+ };
680
+ };
681
+ required: string[];
682
+ };
683
+ };
684
+ };
685
+ };
686
+ };
687
+ };
688
+ };
689
+ }, {
690
+ state: DbscStatusState;
691
+ }>;
692
+ /**
693
+ * ### Endpoint
694
+ *
695
+ * Server only. No HTTP route.
696
+ *
697
+ * ### API Methods
698
+ *
699
+ * **server:**
700
+ * `auth.api.requireFreshProof`
701
+ *
702
+ * A fresh proof for one of your own routes or server actions:
703
+ * `await auth.api.requireFreshProof({ headers, body: { action: "delete-account" } })`.
704
+ *
705
+ * - `answered`: a bound session proved itself after this action's challenge. Go on.
706
+ * - `challenge`: refuse the request and forward the `Set-Cookie` headers (call with
707
+ * `returnHeaders: true`, or use the `nextCookies()` plugin). The client retries once.
708
+ * - `unbound`: a plain session; apply whatever fresh-proof you use without DBSC.
709
+ * - `no-session` and `off`: nothing was checked.
710
+ */
711
+ requireFreshProof: import("better-auth").StrictEndpoint<"/dbsc/require-fresh-proof", {
712
+ method: "POST";
713
+ body: {
714
+ readonly "~standard": {
715
+ readonly version: 1;
716
+ readonly vendor: "@assistant-ui/better-auth-dbsc";
717
+ readonly validate: (value: unknown) => {
718
+ value: {
719
+ action: string;
720
+ };
721
+ issues?: undefined;
722
+ } | {
723
+ value?: undefined;
724
+ issues: {
725
+ message: string;
726
+ path: string[];
727
+ }[];
728
+ };
729
+ readonly types: {
730
+ input: {
731
+ action: string;
732
+ };
733
+ output: {
734
+ action: string;
735
+ };
736
+ };
737
+ };
738
+ };
739
+ requireHeaders: true;
740
+ metadata: {
741
+ SERVER_ONLY: true;
742
+ };
743
+ }, {
744
+ state: FreshProofState;
745
+ }>;
746
+ };
747
+ hooks: {
748
+ before: {
749
+ matcher: (ctx: import("better-auth").HookEndpointContext) => boolean;
750
+ handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<{
751
+ context: {
752
+ headers?: Headers | undefined;
753
+ query?: {
754
+ disableCookieCache: boolean;
755
+ } | undefined;
756
+ };
757
+ } | undefined>>;
758
+ }[];
759
+ after: {
760
+ matcher: () => true;
761
+ handler: import("better-auth").Middleware<import("better-auth").MiddlewareOptions, (inputContext: import("better-auth").MiddlewareInputContext<import("better-auth").MiddlewareOptions>) => Promise<void>>;
762
+ }[];
763
+ };
764
+ rateLimit: {
765
+ pathMatcher: (path: string) => path is "/dbsc/refresh" | "/dbsc/register";
766
+ window: number;
767
+ max: number;
768
+ }[] | undefined;
769
+ $ERROR_CODES: {
770
+ DBSC_BINDING_REQUIRED: import("better-auth").RawError<"DBSC_BINDING_REQUIRED">;
771
+ DBSC_BOUND_TO_OTHER_KEY: import("better-auth").RawError<"DBSC_BOUND_TO_OTHER_KEY">;
772
+ DBSC_CHALLENGE_REQUIRED: import("better-auth").RawError<"DBSC_CHALLENGE_REQUIRED">;
773
+ DBSC_CREDENTIAL_REQUIRED: import("better-auth").RawError<"DBSC_CREDENTIAL_REQUIRED">;
774
+ DBSC_DISABLED: import("better-auth").RawError<"DBSC_DISABLED">;
775
+ DBSC_FRESH_PROOF_REQUIRED: import("better-auth").RawError<"DBSC_FRESH_PROOF_REQUIRED">;
776
+ DBSC_INVALID_CHALLENGE: import("better-auth").RawError<"DBSC_INVALID_CHALLENGE">;
777
+ DBSC_INVALID_PROOF: import("better-auth").RawError<"DBSC_INVALID_PROOF">;
778
+ DBSC_PROOF_REQUIRED: import("better-auth").RawError<"DBSC_PROOF_REQUIRED">;
779
+ DBSC_SESSION_ID_REQUIRED: import("better-auth").RawError<"DBSC_SESSION_ID_REQUIRED">;
780
+ DBSC_SESSION_REQUIRED: import("better-auth").RawError<"DBSC_SESSION_REQUIRED">;
781
+ };
782
+ options: NoInfer<O>;
783
+ };
784
+ export { dbscSchema as C, createMemoryDbscStore as S, DbscBinding as _, DbscEvent as a, DbscStoreAdapter as b, DbscRefusalReason as c, FreshProofState as d, ResolvedDbscOptions as f, DBSC_MODEL as g, DBSC_ERROR_CODES as h, DbscCarrier as i, DbscStatusState as l, resolveDbscOptions as m, DBSC_REFRESH_PATH as n, DbscFreshProofRule as o, dbsc as p, DBSC_REGISTER_PATH as r, DbscOptions as s, DBSC_COOKIE_KEYS as t, DbscUnboundPolicy as u, DbscProofKind as v, createAdapterDbscStore as x, DbscStore as y };