Files
bitlogin/packages/widget/vite.config.ts
T
thePR0M3TH3ANandClaude Opus 4.8 c9791b9840 widget: lightweight, widget-free session reader
Reading "who is signed in" on a page required mounting the whole widget
(bitlogin.js + crypto worker + wasm, ~1.6MB) because that was the only
thing that restored the per-origin session. Multi-page sites paid the
full load on every page just to render a "Signed in as …" header.

Write a cleartext, public-only record ({ pubkey, npub, name? } — never
key material) beside the encrypted session in IndexedDB, in lockstep with
it: the worker writes it at the single persistSession() choke point,
self-heals it on restoreSession (so sessions cached before this feature
upgrade with no re-login), and clears it on logout, so a reported session
can never outlive the real one.

Add @bitlogin/widget/session -> bitlogin-session.js: a self-contained
~1KB gzip reader (zero imports, no worker/wasm) exposing
readCachedSession(): Promise<{ pubkey, npub, name? } | null>. Mirror the
same call on window.bitlogin.readCachedSession() for pages that already
load the full widget.

The private key stays in the AES-GCM record in sessionCache.ts, exactly
as protected as before. Reader falls through to null for every failure
mode (DB/store absent, IndexedDB blocked), which reads as "not signed in".

Addresses the top item of the Tessera integration feedback (docs/TODO.md).

Co-Authored-By: Claude Opus 4.8 <[email protected]>
Claude-Session: https://claude.ai/code/session_01BXQCvJPA6sVSQ5j8uBd9bB
2026-08-11 19:22:06 -04:00

35 lines
1.3 KiB
TypeScript

import { defineConfig } from "vite";
import { resolve } from "node:path";
export default defineConfig({
build: {
outDir: "dist",
emptyOutDir: true,
target: "es2022",
lib: {
// Independent entry points, each a self-contained ES module with a fixed,
// non-hashed filename: bitlogin.js (main thread) and cryptoWorker.js (worker).
// workerClient.ts resolves the worker's URL at runtime relative to its own
// import.meta.url, so both files just need to be deployed side by side --
// at any path, not necessarily the site root (see workerClient.ts comment).
//
// bitlogin-session.js is the lightweight, read-only identity reader
// (session.ts): a few KB with no worker/wasm, for pages that only need to
// show who is signed in. It is dependency-free by design so it does not
// share a chunk with the widget.
entry: {
bitlogin: resolve(__dirname, "src/index.ts"),
cryptoWorker: resolve(__dirname, "src/worker/cryptoWorker.ts"),
"bitlogin-session": resolve(__dirname, "src/session.ts")
},
formats: ["es"],
fileName: (_format, entryName) => `${entryName}.js`
},
rollupOptions: {
output: {
chunkFileNames: "bitlogin-shared-[hash].js"
}
}
}
});