id=prowseir-vaultguard-passwords name=VaultGuard — Encrypted Passwords + Google Auth 2FA version=1.0.0 author=roman_arco description=Zero-knowledge AES-256-GCM + PBKDF2-SHA256 (250k iterations) password vault isolated inside a closed Shadow DOM that demands a live 6-digit Google Authenticator (RFC 6238 TOTP) code (plus optional Google Account Sign-In binding) to unlock, reveal, copy, or autofill credentials. Includes 1-click login autofill, 20-char CSPRNG password generator, 120s auto-lock, and portable encrypted .pvault export/import. site_pattern=* global=1 enabled=1 ---CODE--- // VaultGuard — Guarded AES-256-GCM Password Manager + Mandatory Google Auth (TOTP + Optional Google Sign-In) // Runs inside a closed Shadow DOM so host page scripts cannot inspect inputs, secrets, or unlocked entries. // Creator: by roman a. s. arco (function () { if (location.protocol === "prowseir:" || location.protocol === "about:") return; if (window.__prowseirVaultGuardMounted) return; window.__prowseirVaultGuardMounted = true; const STORAGE_KEY = "__prowseir_vaultguard_v1__"; const PBKDF2_ITERATIONS = 250000; const AUTO_LOCK_MS = 120000; // 2 minutes inactivity auto-lock const B32_ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"; const enc = new TextEncoder(); const dec = new TextDecoder(); // Ephemeral closure-only state (never attached to window or host DOM) let sessionMaster = ""; let sessionSecretB32 = ""; let sessionMeta = null; let unlockedEntries = null; let lastVerifiedTotpStep = -1; let googleVerifiedEmail = ""; let autoLockTimer = null; let modalOpen = false; let revealedIds = new Set(); function esc(s) { return String(s || "").replace(/[&<>"']/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c])); } function toB64(bytes) { let bin = ""; const u8 = bytes instanceof Uint8Array ? bytes : new Uint8Array(bytes); for (let i = 0; i < u8.length; i++) bin += String.fromCharCode(u8[i]); return btoa(bin); } function fromB64(b64) { const bin = atob(String(b64 || "").trim()); const out = new Uint8Array(bin.length); for (let i = 0; i < bin.length; i++) out[i] = bin.charCodeAt(i); return out; } function generateBase32Secret(byteLen = 20) { const raw = new Uint8Array(byteLen); crypto.getRandomValues(raw); let bits = 0; let val = 0; let out = ""; for (let i = 0; i < raw.length; i++) { val = (val << 8) | raw[i]; bits += 8; while (bits >= 5) { out += B32_ALPHABET[(val >>> (bits - 5)) & 31]; bits -= 5; } } if (bits > 0) out += B32_ALPHABET[(val << (5 - bits)) & 31]; return out; } function formatBase32Groups(b32) { return String(b32 || "").replace(/\s+/g, "").replace(/(.{4})/g, "$1 ").trim(); } function base32ToBytes(b32) { const clean = String(b32 || "").toUpperCase().replace(/[^A-Z2-7]/g, ""); let bits = 0; let val = 0; const out = []; for (let i = 0; i < clean.length; i++) { const idx = B32_ALPHABET.indexOf(clean[i]); if (idx < 0) continue; val = (val << 5) | idx; bits += 5; if (bits >= 8) { out.push((val >>> (bits - 8)) & 0xff); bits -= 8; } } return new Uint8Array(out); } // RFC 6238 Google Authenticator 6-Digit TOTP (HMAC-SHA1, 30s step) async function computeTotpAtStep(secretB32, step) { const keyBytes = base32ToBytes(secretB32); if (!keyBytes.length) return ""; const buf = new ArrayBuffer(8); const view = new DataView(buf); view.setUint32(0, Math.floor(step / 0x100000000), false); view.setUint32(4, step >>> 0, false); const key = await crypto.subtle.importKey( "raw", keyBytes, { name: "HMAC", hash: "SHA-1" }, false, ["sign"] ); const hmac = new Uint8Array(await crypto.subtle.sign("HMAC", key, buf)); const offset = hmac[hmac.length - 1] & 0x0f; const code = (((hmac[offset] & 0x7f) << 24) | ((hmac[offset + 1] & 0xff) << 16) | ((hmac[offset + 2] & 0xff) << 8) | (hmac[offset + 3] & 0xff)) % 1000000; return String(code).padStart(6, "0"); } function timingSafeEq(a, b) { const sa = String(a || ""); const sb = String(b || ""); if (sa.length !== sb.length) return false; let diff = 0; for (let i = 0; i < sa.length; i++) diff |= sa.charCodeAt(i) ^ sb.charCodeAt(i); return diff === 0; } async function verifyGoogleAuthTotp(secretB32, rawCode, allowSameWindow = false) { const code = String(rawCode || "").replace(/\s+/g, ""); if (!/^\d{6}$/.test(code)) return { ok: false, step: -1 }; const nowStep = Math.floor(Date.now() / 1000 / 30); for (const drift of [0, -1, 1]) { const candidateStep = nowStep + drift; const expected = await computeTotpAtStep(secretB32, candidateStep); if (timingSafeEq(code, expected)) { if (!allowSameWindow && candidateStep <= lastVerifiedTotpStep) { return { ok: false, replay: true, step: candidateStep }; } return { ok: true, step: candidateStep }; } } return { ok: false, step: -1 }; } async function deriveAesKey(secretMaterial, saltBytes, domainTag) { const baseKey = await crypto.subtle.importKey( "raw", enc.encode(domainTag + ":" + secretMaterial), "PBKDF2", false, ["deriveKey"] ); return crypto.subtle.deriveKey( { name: "PBKDF2", salt: saltBytes, iterations: PBKDF2_ITERATIONS, hash: "SHA-256" }, baseKey, { name: "AES-GCM", length: 256 }, false, ["encrypt", "decrypt"] ); } async function encryptJson(obj, secretMaterial, domainTag) { const salt = new Uint8Array(16); const iv = new Uint8Array(12); crypto.getRandomValues(salt); crypto.getRandomValues(iv); const key = await deriveAesKey(secretMaterial, salt, domainTag); const ct = await crypto.subtle.encrypt( { name: "AES-GCM", iv }, key, enc.encode(JSON.stringify(obj)) ); return { s: toB64(salt), iv: toB64(iv), ct: toB64(ct) }; } async function decryptJson(box, secretMaterial, domainTag) { if (!box || !box.s || !box.iv || !box.ct) throw new Error("Invalid encrypted envelope."); const key = await deriveAesKey(secretMaterial, fromB64(box.s), domainTag); const pt = await crypto.subtle.decrypt( { name: "AES-GCM", iv: fromB64(box.iv) }, key, fromB64(box.ct) ); return JSON.parse(dec.decode(pt)); } function loadStoredBlob() { try { const raw = localStorage.getItem(STORAGE_KEY); return raw ? JSON.parse(raw) : null; } catch (_) { return null; } } function saveStoredBlob(blob) { localStorage.setItem(STORAGE_KEY, JSON.stringify(blob)); } async function persistVault(masterPass, secretB32, meta, entries) { const authBox = await encryptJson( { secretB32, meta }, masterPass, "prowseir-vaultguard-auth-v1" ); const dataBox = await encryptJson( { v: 1, updatedAt: new Date().toISOString(), entries }, masterPass + "::" + secretB32, "prowseir-vaultguard-data-v1" ); const full = { format: "prowseir-pvault-v1", kdf: "PBKDF2-SHA256-250000", cipher: "AES-256-GCM", authBox, dataBox }; saveStoredBlob(full); return full; } function generateStrongPassword(len = 20) { const chars = "ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789!@#$%^&*()-_=+"; const rnd = new Uint32Array(len); crypto.getRandomValues(rnd); let out = ""; for (let i = 0; i < len; i++) out += chars[rnd[i] % chars.length]; return out; } function touchActivity() { if (autoLockTimer) clearTimeout(autoLockTimer); if (unlockedEntries) { autoLockTimer = setTimeout(() => { lockVault("Vault auto-locked after 2 minutes of inactivity."); }, AUTO_LOCK_MS); } } function lockVault(msg = "Vault locked. Master password + Google Auth required.") { sessionMaster = ""; sessionSecretB32 = ""; sessionMeta = null; unlockedEntries = null; googleVerifiedEmail = ""; revealedIds.clear(); if (autoLockTimer) { clearTimeout(autoLockTimer); autoLockTimer = null; } updatePill(); if (modalOpen) renderModal(msg, false); } // Optional Google Identity Services (OAuth ID Token verification) when user binds a Google Client ID async function verifyGoogleIdToken(idToken, expectedClientId) { const resp = await fetch("https://oauth2.googleapis.com/tokeninfo?id_token=" + encodeURIComponent(idToken)); if (!resp.ok) throw new Error("Google ID token rejected by Google tokeninfo endpoint."); const info = await resp.json(); if (expectedClientId && info.aud !== expectedClientId) { throw new Error("Google Client ID mismatch (aud check failed)."); } if (info.email_verified !== "true" && info.email_verified !== true) { throw new Error("Google account email is not verified."); } return String(info.email || info.sub || "verified-google-user"); } // Closed Shadow DOM UI Host const hostEl = document.createElement("div"); hostEl.setAttribute("data-prowseir-ext", (typeof prowseirExt !== "undefined" && prowseirExt.id) ? prowseirExt.id : "prowseir-vaultguard-passwords"); const shadow = hostEl.attachShadow({ mode: "closed" }); (document.documentElement || document.body).appendChild(hostEl); const styleEl = document.createElement("style"); styleEl.textContent = ` :host { all: initial; } * { box-sizing: border-box; font-family: 'JetBrains Mono', Consolas, monospace; } .vg-pill { position: fixed; left: 14px; bottom: 14px; z-index: 2147483644; background: #090B10; color: #FFD400; border: 2px solid #FFD400; padding: 6px 11px; font-size: 11px; font-weight: 800; cursor: pointer; letter-spacing: 0.8px; opacity: 0.86; box-shadow: 0 4px 14px rgba(0,0,0,0.65); } .vg-pill.unlocked { border-color: #00E5A8; color: #00E5A8; } .vg-pill:hover { opacity: 1; background: #141924; } .vg-backdrop { position: fixed; inset: 0; z-index: 2147483645; background: rgba(5,7,12,0.84); display: none; align-items: center; justify-content: center; padding: 16px; } .vg-backdrop.open { display: flex; } .vg-box { width: 100%; max-width: 620px; max-height: 88vh; overflow-y: auto; background: #0E121B; color: #FFFFFF; border: 2px solid #FFD400; padding: 18px; box-shadow: 0 12px 38px rgba(0,0,0,0.85); font-size: 12px; line-height: 1.5; } .vg-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; border-bottom: 2px solid #FFFFFF; padding-bottom: 10px; margin-bottom: 12px; } .vg-title { margin: 0; font-size: 15px; color: #FFD400; letter-spacing: 1px; } .vg-sub { color: #B6BFCC; font-size: 11px; margin-bottom: 10px; } .vg-card { background: #090B10; border: 1px solid #30384A; padding: 12px; margin-bottom: 10px; } .vg-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; } label { display: block; font-size: 10.5px; color: #B6BFCC; text-transform: uppercase; font-weight: 700; margin-bottom: 3px; } input, textarea { width: 100%; background: #141925; color: #FFFFFF; border: 1px solid #3A455C; padding: 7px 9px; font-size: 12px; font-family: inherit; } input:focus, textarea:focus { outline: none; border-color: #FFD400; } .vg-btn { background: #141925; color: #FFFFFF; border: 1px solid #FFFFFF; padding: 6px 10px; font-size: 11px; font-weight: 700; cursor: pointer; } .vg-btn:hover { background: #FFFFFF; color: #090B10; } .vg-btn.acc { background: #FFD400; color: #000000; border-color: #FFD400; } .vg-btn.ok { border-color: #00E5A8; color: #00E5A8; } .vg-btn.ok:hover { background: #00E5A8; color: #000000; } .vg-btn.warn { border-color: #FF5555; color: #FF5555; } .vg-btn.warn:hover { background: #FF5555; color: #FFFFFF; } .vg-msg { padding: 7px 10px; margin-bottom: 10px; font-size: 11.5px; font-weight: 700; border: 1px solid #00E5A8; color: #00E5A8; background: #091512; } .vg-msg.err { border-color: #FF5555; color: #FF5555; background: #190B0E; } .vg-secret { font-size: 13px; letter-spacing: 1.5px; color: #00E5A8; font-weight: 800; word-break: break-all; padding: 8px; background: #06080C; border: 1px dashed #00E5A8; margin: 6px 0; } .vg-entry { border: 1px solid #30384A; border-left: 3px solid #FFD400; padding: 10px; margin-bottom: 8px; background: #0B0E16; } .vg-entry.match { border-left-color: #00E5A8; } `; const pillBtn = document.createElement("button"); pillBtn.type = "button"; pillBtn.className = "vg-pill"; pillBtn.title = "Open VaultGuard Encrypted Password Manager (Alt+Shift+V)"; pillBtn.textContent = "VAULT [LOCKED · 2FA]"; const backdrop = document.createElement("div"); backdrop.className = "vg-backdrop"; const box = document.createElement("div"); box.className = "vg-box"; backdrop.appendChild(box); shadow.appendChild(styleEl); shadow.appendChild(pillBtn); shadow.appendChild(backdrop); function updatePill() { if (unlockedEntries) { pillBtn.className = "vg-pill unlocked"; pillBtn.textContent = `VAULT [UNLOCKED: ${unlockedEntries.length}]`; } else { pillBtn.className = "vg-pill"; pillBtn.textContent = "VAULT [LOCKED · 2FA]"; } } function autofillOnPage(username, password) { const passInputs = Array.from(document.querySelectorAll('input[type="password"]')).filter( (el) => el.offsetParent !== null || el.getClientRects().length > 0 ); if (!passInputs.length) return false; const pEl = passInputs[0]; const form = pEl.closest("form") || document.body; const candidates = Array.from( form.querySelectorAll('input[type="email"], input[type="text"], input:not([type])') ).filter((el) => el !== pEl && !el.readOnly && !el.disabled); const setVal = (el, val) => { const setter = Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set; if (setter) setter.call(el, val); else el.value = val; el.dispatchEvent(new Event("input", { bubbles: true })); el.dispatchEvent(new Event("change", { bubbles: true })); }; if (candidates.length && username) setVal(candidates[candidates.length - 1], username); setVal(pEl, password); return true; } let pendingSetupSecret = ""; function renderModal(statusText = "", isError = false) { touchActivity(); const stored = loadStoredBlob(); const banner = statusText ? `
${esc(statusText)}
` : ""; // STATE 1: INITIAL VAULT + GOOGLE AUTH ENROLLMENT if (!stored) { if (!pendingSetupSecret) pendingSetupSecret = generateBase32Secret(20); const otpUri = `otpauth://totp/Prowseir%20VaultGuard:${encodeURIComponent(location.hostname || "vault")}?secret=${pendingSetupSecret}&issuer=ProwseirVault&algorithm=SHA1&digits=6&period=30`; box.innerHTML = `

VAULTGUARD // SETUP ENCRYPTED VAULT + GOOGLE AUTH

${banner}
Passwords are encrypted locally with AES-256-GCM + PBKDF2-SHA256 (250,000 iterations) and locked behind your Google Authenticator 6-digit code.
${esc(formatBase32Groups(pendingSetupSecret))}
`; bindEvents(); return; } // STATE 2: LOCKED VAULT (DEMANDS MASTER PASSWORD + GOOGLE AUTH 6-DIGIT CODE) if (!unlockedEntries) { box.innerHTML = `

VAULTGUARD // GUARDED UNLOCK (GOOGLE AUTH REQUIRED)

${banner}
Vault ciphertext detected on ${esc(location.hostname || "local")}. Both your Master Passphrase and a live Google Authenticator 6-digit code are required to decrypt.
`; bindEvents(); return; } // STATE 3: UNLOCKED GUARDED VAULT (STEP-UP GOOGLE AUTH ON REVEAL/COPY/AUTOFILL) const host = (location.hostname || "").toLowerCase(); const sorted = [...unlockedEntries].sort((a, b) => { const am = host && a.domain && host.includes(a.domain.toLowerCase()) ? 0 : 1; const bm = host && b.domain && host.includes(b.domain.toLowerCase()) ? 0 : 1; return am - bm || String(a.domain || "").localeCompare(String(b.domain || "")); }); const listHtml = sorted.length ? sorted.map((item) => { const isMatch = host && item.domain && host.includes(item.domain.toLowerCase()); const shown = revealedIds.has(item.id); return `
${esc(item.domain || "*")} · ${esc(item.username)}
Password: ${shown ? esc(item.password) : "••••••••••••••••"} ${item.notes ? ` · ${esc(item.notes)}` : ""}
`; }).join("") : `
No credentials saved yet. Add your first AES-256-GCM encrypted login below.
`; box.innerHTML = `

VAULTGUARD // UNLOCKED (${unlockedEntries.length} ENCRYPTED LOGINS)

${banner}
+ SAVE ENCRYPTED PASSWORD
GUARDED CREDENTIALS (${unlockedEntries.length}) ${listHtml}
`; bindEvents(); } async function requireStepUpTotp() { const el = shadow.getElementById("vg-stepup-totp"); const code = el ? el.value.trim() : ""; const check = await verifyGoogleAuthTotp(sessionSecretB32, code, true); if (!check.ok) { renderModal("Enter a valid live 6-digit Google Authenticator code in the Step-Up box first!", true); return false; } return true; } function downloadPvaultFile(blob) { const file = new Blob([JSON.stringify(blob, null, 2)], { type: "application/json;charset=utf-8" }); const a = document.createElement("a"); a.href = URL.createObjectURL(file); a.download = "prowseir-vaultguard-backup.pvault"; a.click(); setTimeout(() => URL.revokeObjectURL(a.href), 1500); } function bindEvents() { const fileIn = shadow.getElementById("vg-file-in"); if (fileIn) { fileIn.addEventListener("change", (ev) => { const f = ev.target.files && ev.target.files[0]; if (!f) return; const reader = new FileReader(); reader.onload = () => { try { const parsed = JSON.parse(String(reader.result || "")); if (!parsed || parsed.format !== "prowseir-pvault-v1" || !parsed.authBox || !parsed.dataBox) { throw new Error("Not a valid prowseir-pvault-v1 encrypted file."); } saveStoredBlob(parsed); lockVault("Imported .pvault file! Enter Master Passphrase + Google Auth code to decrypt."); } catch (e) { renderModal("File import error: " + e.message, true); } }; reader.readAsText(f); }); } box.querySelectorAll("[data-act]").forEach((btn) => { btn.addEventListener("click", async () => { touchActivity(); const act = btn.getAttribute("data-act"); if (act === "close") { modalOpen = false; backdrop.classList.remove("open"); return; } if (act === "lock") { lockVault("Vault locked."); return; } if (act === "copy-secret") { await navigator.clipboard?.writeText(pendingSetupSecret).catch(() => {}); renderModal("Copied Base32 Google Authenticator setup key to clipboard."); return; } if (act === "copy-uri") { await navigator.clipboard?.writeText(btn.getAttribute("data-uri") || "").catch(() => {}); renderModal("Copied otpauth:// URI for Google Authenticator."); return; } if (act === "regen-secret") { pendingSetupSecret = generateBase32Secret(20); renderModal("Generated a fresh 160-bit Google Authenticator secret."); return; } if (act === "finish-setup") { const pass = shadow.getElementById("vg-setup-pass")?.value || ""; const gid = (shadow.getElementById("vg-setup-gid")?.value || "").trim(); const totp = shadow.getElementById("vg-setup-totp")?.value || ""; if (pass.length < 8) { renderModal("Master Passphrase must be at least 8 characters.", true); return; } const v = await verifyGoogleAuthTotp(pendingSetupSecret, totp, true); if (!v.ok) { renderModal("Invalid 6-digit Google Authenticator code. Scan/add the key in Google Authenticator first.", true); return; } sessionMaster = pass; sessionSecretB32 = pendingSetupSecret; sessionMeta = { googleClientId: gid || "", createdAt: new Date().toISOString() }; unlockedEntries = []; lastVerifiedTotpStep = v.step; pendingSetupSecret = ""; await persistVault(sessionMaster, sessionSecretB32, sessionMeta, unlockedEntries); updatePill(); renderModal("Encrypted Vault created & bound to Google Authenticator!"); return; } if (act === "import-blob") { const raw = (shadow.getElementById("vg-import-raw")?.value || "").trim(); try { const parsed = JSON.parse(raw); if (!parsed || parsed.format !== "prowseir-pvault-v1" || !parsed.authBox || !parsed.dataBox) { throw new Error("Not a valid prowseir-pvault-v1 encrypted backup."); } saveStoredBlob(parsed); lockVault("Encrypted .pvault loaded! Enter Master Passphrase + Google Auth code to decrypt."); } catch (e) { renderModal("Import error: " + e.message, true); } return; } if (act === "export-blob") { const stored = loadStoredBlob(); if (stored) { downloadPvaultFile(stored); renderModal("Exported encrypted .pvault file (importable via IMPORT .PVAULT FILE)."); } return; } if (act === "export-text") { const stored = loadStoredBlob(); if (stored) { const jsonStr = JSON.stringify(stored); await navigator.clipboard?.writeText(jsonStr).catch(() => {}); renderModal("Exported & copied encrypted .pvault JSON text to clipboard!"); const ta = shadow.getElementById("vg-import-raw"); if (ta) ta.value = jsonStr; } return; } if (act === "unlock") { const pass = shadow.getElementById("vg-unlock-pass")?.value || ""; const totp = shadow.getElementById("vg-unlock-totp")?.value || ""; const gtok = (shadow.getElementById("vg-unlock-gtoken")?.value || "").trim(); const stored = loadStoredBlob(); try { const authData = await decryptJson(stored.authBox, pass, "prowseir-vaultguard-auth-v1"); const check = await verifyGoogleAuthTotp(authData.secretB32, totp, false); if (!check.ok) { throw new Error(check.replay ? "Wait for the next 30-second Google Authenticator code (anti-replay active)." : "Invalid 6-digit Google Authenticator code."); } if (authData.meta && authData.meta.googleClientId) { if (!gtok) throw new Error("This vault also demands a verified Google OAuth ID token."); googleVerifiedEmail = await verifyGoogleIdToken(gtok, authData.meta.googleClientId); } const vaultData = await decryptJson( stored.dataBox, pass + "::" + authData.secretB32, "prowseir-vaultguard-data-v1" ); sessionMaster = pass; sessionSecretB32 = authData.secretB32; sessionMeta = authData.meta || {}; unlockedEntries = Array.isArray(vaultData.entries) ? vaultData.entries : []; lastVerifiedTotpStep = check.step; revealedIds.clear(); updatePill(); renderModal("Google Auth verified! Decrypted " + unlockedEntries.length + " login(s)." + (googleVerifiedEmail ? " (" + googleVerifiedEmail + ")" : "")); } catch (e) { renderModal("Unlock denied: " + (e.message || "Wrong Master Passphrase or Google Auth code."), true); } return; } if (act === "gen-pw") { const pwIn = shadow.getElementById("vg-new-pass"); if (pwIn) pwIn.value = generateStrongPassword(20); return; } if (act === "add-entry") { const domain = (shadow.getElementById("vg-new-domain")?.value || "").trim(); const username = (shadow.getElementById("vg-new-user")?.value || "").trim(); const password = shadow.getElementById("vg-new-pass")?.value || ""; const notes = (shadow.getElementById("vg-new-note")?.value || "").trim(); if (!username || !password) { renderModal("Enter both a username/email and password to encrypt.", true); return; } unlockedEntries.unshift({ id: "pw-" + Date.now().toString(36) + Math.random().toString(36).slice(2, 6), domain: domain || location.hostname || "*", username, password, notes, updatedAt: new Date().toISOString(), }); await persistVault(sessionMaster, sessionSecretB32, sessionMeta, unlockedEntries); updatePill(); renderModal("Encrypted & saved login for " + (domain || location.hostname) + "."); return; } const itemId = btn.getAttribute("data-id"); const entry = (unlockedEntries || []).find((x) => x.id === itemId); if (!entry) return; if (act === "del-pw") { unlockedEntries = unlockedEntries.filter((x) => x.id !== itemId); revealedIds.delete(itemId); await persistVault(sessionMaster, sessionSecretB32, sessionMeta, unlockedEntries); updatePill(); renderModal("Deleted credential and re-encrypted vault."); return; } // Guarded actions demand live 6-digit Google Auth step-up check if (!(await requireStepUpTotp())) return; if (act === "reveal") { if (revealedIds.has(itemId)) revealedIds.delete(itemId); else revealedIds.add(itemId); renderModal(revealedIds.has(itemId) ? "Password revealed (Google Auth verified)." : "Password masked."); } else if (act === "copy-pw") { await navigator.clipboard?.writeText(entry.password).catch(() => {}); renderModal("Copied password for " + entry.username + " (Google Auth verified)."); } else if (act === "autofill") { const filled = autofillOnPage(entry.username, entry.password); if (filled) { modalOpen = false; backdrop.classList.remove("open"); } else { renderModal("No visible password input found on this page.", true); } } }); }); } function openModal() { modalOpen = true; backdrop.classList.add("open"); renderModal(); } pillBtn.addEventListener("click", () => { if (modalOpen) { modalOpen = false; backdrop.classList.remove("open"); } else { openModal(); } }); const onKeyDown = (e) => { if (e.altKey && e.shiftKey && (e.key === "V" || e.key === "v")) { e.preventDefault(); if (modalOpen) { modalOpen = false; backdrop.classList.remove("open"); } else { openModal(); } } else if (e.key === "Escape" && modalOpen) { modalOpen = false; backdrop.classList.remove("open"); } }; window.addEventListener("keydown", onKeyDown, true); if (typeof prowseirExt !== "undefined" && typeof prowseirExt.onCleanup === "function") { prowseirExt.onCleanup(() => { lockVault(); window.removeEventListener("keydown", onKeyDown, true); hostEl.remove(); delete window.__prowseirVaultGuardMounted; }); } })(); ---CSS--- /* Host page remains untouched: all VaultGuard UI styles are encapsulated inside a closed ShadowRoot */