// Background-owned state set while the user has just created or rotated a // vault identity and is confirming their recovery words. It intentionally // never lives in chrome.storage.local: content scripts can read/write local // storage unless the browser supports and has applied a trusted-context gate. // Chrome's session storage is in-memory and trusted-context-only by default; // Firefox falls back to this background module's memory for the same process. const KEY = "peach_recovery_pending"; let inMemoryPending = false; function sessionStorage(): chrome.storage.StorageArea | undefined { return chrome.storage?.session; } export async function isRecoveryConfirmPending(): Promise { try { const session = sessionStorage(); if (!session) return inMemoryPending; const out = await session.get(KEY); return (out as Record)[KEY] === "1"; } catch { return inMemoryPending; } } export async function setRecoveryConfirmPending(): Promise { try { const session = sessionStorage(); if (session) { await session.set({ [KEY]: "1" }); return; } } catch { /* use the in-memory fallback */ } inMemoryPending = true; } export async function clearRecoveryConfirmPending(): Promise { try { const session = sessionStorage(); if (session) { await session.remove(KEY); } } catch { /* best-effort */ } inMemoryPending = false; }