mirror of
https://github.com/PR0M3TH3AN/bitlogin.git
synced 2026-10-27 08:31:21 +00:00
The element was the only way to sign, so a host that renders its own UI, a background job, or a headless test couldn't sign without mounting <bitlogin-auth>. Add @bitlogin/widget/headless: createHeadlessSigner() → a DOM-free wrapper over the crypto worker exposing restore, getPublicKey, signEvent, nip44Encrypt/Decrypt, isUnlocked, logout, destroy. It restores the cached session and signs with no element and no window.nostr. It deliberately cannot interactively log in (that needs the password UI): restore() returns null when nothing is cached, at which point the host mounts <bitlogin-auth> once; after that the headless signer works across reloads. New bitlogin-headless.js build entry + @bitlogin/widget/headless export (also re-exported from @bitlogin/widget). Covered by headless.test.ts with a scripted worker; README gains "Signing without the widget (headless)". Addresses the "headless session-restore API" 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
38 lines
1.5 KiB
TypeScript
38 lines
1.5 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"),
|
|
// Headless signer (restore + sign, no element/DOM). Loads cryptoWorker.js
|
|
// at runtime like bitlogin.js, so deploy them together.
|
|
"bitlogin-headless": resolve(__dirname, "src/headless.ts")
|
|
},
|
|
formats: ["es"],
|
|
fileName: (_format, entryName) => `${entryName}.js`
|
|
},
|
|
rollupOptions: {
|
|
output: {
|
|
chunkFileNames: "bitlogin-shared-[hash].js"
|
|
}
|
|
}
|
|
}
|
|
});
|