mirror of
https://github.com/PR0M3TH3AN/bitlogin.git
synced 2026-10-27 08:31:21 +00:00
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
35 lines
1.3 KiB
TypeScript
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"
|
|
}
|
|
}
|
|
}
|
|
});
|