dbsc-toolkit 2.9.8 → 2.9.9

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.
Files changed (2) hide show
  1. package/README.md +54 -3
  2. package/package.json +4 -2
package/README.md CHANGED
@@ -116,11 +116,32 @@ Without the script those browsers stay on `tier: "none"`. Chromium 146+ doesn't
116
116
 
117
117
  Walk-through: [docs/getting-started.md](./docs/getting-started.md).
118
118
 
119
- ## Live demo
119
+ ### Not on Express?
120
120
 
121
- <https://dbsc-toolkit.onrender.com/>
121
+ `createDbsc()` is the Express convenience layer. The protocol itself — native DBSC, the polyfill, per-request proof verification — lives in a framework-agnostic core that takes plain data and a `StorageAdapter`, nothing else. The Express, Fastify, Hono, and Next.js adapters are thin wrappers over it. If you're on a different runtime (or wiring DBSC into your own framework's session layer), import the core handlers directly:
122
122
 
123
- Sign up, log in, click **Check session**. Chromium 146+ lands on `tier: "dbsc"` within a second; Firefox/Safari land on `tier: "bound"` within ~3 seconds. The demo uses a 60-second bound-cookie TTL so refresh fires fast — open DevTools Network and watch. Source: [examples/express/](./examples/express/).
123
+ ```ts
124
+ import {
125
+ handleRegistration, // POST /dbsc/registration
126
+ handleRefresh, // POST /dbsc/refresh
127
+ handleBoundRegistration, handleBoundRefresh, // the polyfill routes
128
+ verifyBoundProof, // your requireProof() equivalent
129
+ issueChallenge,
130
+ buildRegistrationHeader,
131
+ type StorageAdapter, // the only interface you implement
132
+ } from "dbsc-toolkit";
133
+ ```
134
+
135
+ These are the same functions every shipped adapter calls. A complete raw-`http` integration built on them — both protocol surfaces, every header and cookie detail — is in [docs/adapters.md](./docs/adapters.md#writing-your-own-adapter).
136
+
137
+ ## Live demos
138
+
139
+ | URL | Stack | Source |
140
+ |---|---|---|
141
+ | <https://dbsc-toolkit.onrender.com/> | Express + raw `dbsc-toolkit` | [examples/express/](./examples/express/) |
142
+ | <https://dbsc-better-auth-demo.onrender.com/> | Hono + Better Auth + `@dbsc-toolkit/better-auth` | [examples/better-auth/](./examples/better-auth/) |
143
+
144
+ Sign up, log in, click **Check session**. Chromium 145+ lands on `tier: "dbsc"` within a second; Firefox/Safari land on `tier: "bound"` within ~3 seconds. Open DevTools Network and watch the binding flow.
124
145
 
125
146
  ## Comparison
126
147
 
@@ -212,6 +233,36 @@ app.post("/logout", async (req, res) => {
212
233
 
213
234
  Full walk-through with `autoBind`, per-route policy, and the migration timeline: [docs/integrating-existing-auth.md](./docs/integrating-existing-auth.md).
214
235
 
236
+ ### Using Better Auth?
237
+
238
+ Install [@dbsc-toolkit/better-auth](./packages/better-auth/) — sessions from every sign-in method (email, OAuth, magic link, passkey) get bound automatically:
239
+
240
+ ```ts
241
+ // auth.ts
242
+ import { betterAuth } from "better-auth"
243
+ import { dbsc } from "@dbsc-toolkit/better-auth"
244
+
245
+ export const auth = betterAuth({
246
+ plugins: [dbsc()],
247
+ })
248
+ ```
249
+
250
+ ```ts
251
+ // server.ts
252
+ import { dbscExpress } from "@dbsc-toolkit/better-auth/express"
253
+
254
+ const dbsc = dbscExpress(auth)
255
+ dbsc.install(app) // mounts /dbsc/*, /dbsc-bound/*, /dbsc-client/*
256
+ app.all("/api/auth/*splat", toNodeHandler(auth))
257
+ app.get("/profile", dbsc.requireProof(), profileHandler)
258
+ ```
259
+
260
+ ```html
261
+ <script src="/dbsc-client/init.js" type="module"></script>
262
+ ```
263
+
264
+ Live demo: <https://dbsc-better-auth-demo.onrender.com/>. Full docs in the [package README](./packages/better-auth/README.md).
265
+
215
266
  ## Protect your routes
216
267
 
217
268
  After `createDbsc().install()`, every request through the middleware has a `tier` field on the request context. The library does not auto-protect anything — you add `requireProof()` to each route that matters.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dbsc-toolkit",
3
- "version": "2.9.8",
3
+ "version": "2.9.9",
4
4
  "description": "Server-side Device Bound Session Credentials (DBSC) for Node.js plus a Web Crypto polyfill for Firefox, Safari, and older Chromium. Cookie-theft protection on every modern browser.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -93,6 +93,7 @@
93
93
  },
94
94
  "devDependencies": {
95
95
  "@fastify/cookie": "^11.0.2",
96
+ "fastify-plugin": "^5.0.1",
96
97
  "@types/express": "^5.0.6",
97
98
  "@types/node": "^20.0.0",
98
99
  "@types/pg": "^8.0.0",
@@ -136,5 +137,6 @@
136
137
  },
137
138
  "engines": {
138
139
  "node": ">=20.0.0"
139
- }
140
+ },
141
+ "packageManager": "pnpm@9.0.0"
140
142
  }