recovery-pending.ts

1.4 KB · raw

1// Background-owned state set while the user has just created or rotated a2// vault identity and is confirming their recovery words. It intentionally3// never lives in chrome.storage.local: content scripts can read/write local4// storage unless the browser supports and has applied a trusted-context gate.5// Chrome's session storage is in-memory and trusted-context-only by default;6// Firefox falls back to this background module's memory for the same process.78const KEY = "peach_recovery_pending";9let inMemoryPending = false;1011function sessionStorage(): chrome.storage.StorageArea | undefined {12  return chrome.storage?.session;13}1415export async function isRecoveryConfirmPending(): Promise<boolean> {16  try {17    const session = sessionStorage();18    if (!session) return inMemoryPending;19    const out = await session.get(KEY);20    return (out as Record<string, unknown>)[KEY] === "1";21  } catch {22    return inMemoryPending;23  }24}2526export async function setRecoveryConfirmPending(): Promise<void> {27  try {28    const session = sessionStorage();29    if (session) {30      await session.set({ [KEY]: "1" });31      return;32    }33  } catch { /* use the in-memory fallback */ }34  inMemoryPending = true;35}3637export async function clearRecoveryConfirmPending(): Promise<void> {38  try {39    const session = sessionStorage();40    if (session) {41      await session.remove(KEY);42    }43  } catch { /* best-effort */ }44  inMemoryPending = false;45}