mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
The login modal now shows <bitlogin-auth> -- a portable Nostr identity behind a login name and password -- as the default sign-in path, styled with bitvid's own brand tokens (accent-strong, surfaces, radii). The existing NIP-07 extension, nsec, and NIP-46 remote-signer options still work exactly as before, just collapsed under a new "Other login options" fold instead of a flat "Available methods" grid; nip07 no longer carries the stale "Recommended" eyebrow now that BitLogin has that role. BitLogin isn't a single button-click-then-await-a-promise flow like the other providers -- it's a whole multi-screen sign-in/create/recover UI -- so it gets a permanent, statically-declared widget in components/login-modal.html (js/ui/bitloginModalIntegration.js relocates it, never destroys and recreates it, since removal tears down its crypto Web Worker) instead of a grid button. It still goes through the exact same session-establishment path as every other signer: a new "bitlogin" provider (js/services/authProviders/bitlogin.js) lets AuthService resolve and activate it via the normal requestLogin -> handleAuthLogin path, while providersForModal excludes it from the grid so it isn't rendered twice. Two things this needed beyond the wiring itself: - js/app.js is one line from its lint/file-size ceiling, so the only change there is renaming an import binding (providers -> providersForModal), a net-zero line change. The actual widget/event wiring lives in a new, unconstrained module instead. - The login modal's HTML (including the permanent widget element) loads asynchronously after bootstrap runs, so wireBitloginLogin() waits via MutationObserver rather than assuming a specific call order. Vendored via scripts/build-bitlogin-widget.mjs (mirrors the existing Bitcoin Connect/Blossom vendor steps): BitLogin isn't published to npm, so the widget build is copied verbatim from the sibling ../bitlogin checkout into committed vendor/bitlogin/, then lazy-imported (like Bitcoin Connect) so its ~350KB never weighs on visitors who never open the login modal. Gated behind FEATURE_BITLOGIN (config/instance-config.js), default on for this unstable-branch experiment per AGENTS.md §1 -- reset to false before this reaches main until verified end-to-end against production relays. Verified: npm run lint (clean), the full auth/login test suite (43/43, including new coverage for the provider + adapter), and a manual Chrome pass against the built dist/ -- widget renders themed correctly, "Other login options" still shows the original four methods unchanged.
69 lines
3.2 KiB
JavaScript
69 lines
3.2 KiB
JavaScript
// Vendor the sibling @bitlogin/widget build into a pinned, same-origin bundle.
|
|
//
|
|
// bitvid's CSP is script-src 'self' (plus a couple of pinned CDN fallbacks for
|
|
// nostr-tools) -- the same reasoning as the existing bitcoin-connect/blossom-sdk
|
|
// vendor steps. Unlike those, BitLogin ships its own Vite-built ESM output
|
|
// directly (bitlogin.js + cryptoWorker.js + a shared chunk they both import),
|
|
// so this script copies that output verbatim instead of re-bundling it with
|
|
// esbuild -- the worker's relative self-URL resolution depends on the three
|
|
// files staying exactly as built and sitting side by side (see BitRoad's and
|
|
// BitUnlock's identical vendor steps for this same reasoning).
|
|
//
|
|
// node scripts/build-bitlogin-widget.mjs
|
|
// BITLOGIN_ENTRY=/path/to/bitlogin node scripts/build-bitlogin-widget.mjs
|
|
|
|
import { createHash } from "node:crypto";
|
|
import { copyFile, mkdir, readdir, readFile, rm, writeFile } from "node:fs/promises";
|
|
import { existsSync } from "node:fs";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { execSync } from "node:child_process";
|
|
|
|
const repoRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "..");
|
|
const bitloginRoot = process.env.BITLOGIN_ENTRY
|
|
? path.resolve(process.env.BITLOGIN_ENTRY)
|
|
: path.resolve(repoRoot, "../bitlogin");
|
|
const widgetDir = path.join(bitloginRoot, "packages/widget");
|
|
const widgetDist = path.join(widgetDir, "dist");
|
|
const vendorDir = path.join(repoRoot, "vendor/bitlogin");
|
|
const integrityFile = path.join(repoRoot, "vendor/bitlogin.integrity.json");
|
|
|
|
const packageJson = JSON.parse(await readFile(path.join(widgetDir, "package.json"), "utf8"));
|
|
if (packageJson.name !== "@bitlogin/widget") {
|
|
throw new Error("BITLOGIN_ENTRY must point to a BitLogin checkout (packages/widget/package.json not found there).");
|
|
}
|
|
|
|
if (!existsSync(widgetDist)) {
|
|
console.log("[build-bitlogin-widget] dist missing, building @bitlogin/core then @bitlogin/widget first...");
|
|
execSync("npm run build -w @bitlogin/core", { cwd: bitloginRoot, stdio: "inherit" });
|
|
execSync("npm run build -w @bitlogin/widget", { cwd: bitloginRoot, stdio: "inherit" });
|
|
}
|
|
|
|
await rm(vendorDir, { recursive: true, force: true });
|
|
await mkdir(vendorDir, { recursive: true });
|
|
|
|
const distEntries = (await readdir(widgetDist)).filter((name) => name.endsWith(".js"));
|
|
if (!distEntries.includes("bitlogin.js") || !distEntries.includes("cryptoWorker.js")) {
|
|
throw new Error("Expected bitlogin.js and cryptoWorker.js in @bitlogin/widget dist -- did the build layout change?");
|
|
}
|
|
|
|
const files = {};
|
|
for (const name of distEntries) {
|
|
await copyFile(path.join(widgetDist, name), path.join(vendorDir, name));
|
|
const bytes = await readFile(path.join(widgetDist, name));
|
|
files[name] = { sha256: createHash("sha256").update(bytes).digest("hex"), bytes: bytes.byteLength };
|
|
}
|
|
|
|
await writeFile(
|
|
integrityFile,
|
|
`${JSON.stringify({ package: packageJson.name, version: packageJson.version, files }, null, 2)}\n`,
|
|
);
|
|
|
|
try {
|
|
await copyFile(path.join(bitloginRoot, "LICENSE"), path.join(repoRoot, "vendor/bitlogin.LICENSE"));
|
|
} catch (error) {
|
|
console.warn("[build-bitlogin-widget] could not copy LICENSE:", error.message);
|
|
}
|
|
|
|
console.log("[build-bitlogin-widget] wrote", path.relative(repoRoot, vendorDir), `(${distEntries.length} files)`);
|