e671bff1201f

filter mesh relay storage triggers by dependency key (v5.3.33)

time
2026-11-23 00:46 UTC · 5 days ago
machine
Junes-MacBook-Pro.local
agent
gpt-5.6-sol
session
remediate interim audit findings
parent
c929195a66da
12 files manifest.firefox.json+1 −1manifest.json+1 −1package.json+1 −1src/background/device-identity.ts+8 −8src/background/entry.lock-port.test.ts+24 −0src/background/entry.ts+4 −1src/background/locked-sync-spool.ts+6 −6src/background/mesh-relay-listener.test.ts+189 −1src/background/mesh-relay-listener.ts+75 −5src/background/sync-settings.ts+2 −2src/background/vault.session-escrow.test.ts+16 −0src/background/vault.ts+13 −2
manifest.firefox.json+1 −1
@@ -1,7 +1,7 @@11 {22   "manifest_version": 3,33   "name": "Peach Password Manager",4-  "version": "5.3.32",4+  "version": "5.3.33",55   "description": "Zero-knowledge password manager",66   "browser_specific_settings": {77     "gecko": {

view file

manifest.json+1 −1
@@ -2,7 +2,7 @@22   "manifest_version": 3,33   "minimum_chrome_version": "116",44   "name": "Peach Password Manager",5-  "version": "5.3.32",5+  "version": "5.3.33",66   "description": "Zero-knowledge password manager",77   "action": {88     "default_popup": "src/popup/index.html",

view file

package.json+1 −1
@@ -1,6 +1,6 @@11 {22   "name": "peach",3-  "version": "5.3.32",3+  "version": "5.3.33",44   "description": "Zero-knowledge password manager",55   "license": "GPL-3.0-only",66   "type": "module",

view file

src/background/device-identity.ts+8 −8
@@ -40,12 +40,12 @@4040 } from "./sync-generation";4141 4242 const DEVICE_NAME_KEY = "peach_device_name";43-const IDENTITY_RECORD_KEY = "peach_local_identity_v4";44-const IDENTITY_MARKER_KEY = "peach_local_identity_initialized";45-const LEGACY_IDENTITY_KEY = "peach_local_identity_v2";43+export const IDENTITY_RECORD_KEY = "peach_local_identity_v4";44+export const IDENTITY_MARKER_KEY = "peach_local_identity_initialized";45+export const LEGACY_IDENTITY_KEY = "peach_local_identity_v2";4646 const LEGACY_INFO = "peach-local-identity-v2";4747 const BLOB_INFO = "peach-local-identity-blob-v1";48-const SESSION_CACHE_KEY = "peach_local_identity_session";48+export const IDENTITY_SESSION_CACHE_KEY = "peach_local_identity_session";4949 const HEX_64 = /^[0-9a-f]{64}$/i;5050 5151 /** Frozen local-identity schema (campaign task 2.1). */@@ -202,13 +202,13 @@202202   if (!isUnlocked() || isDecoyMode()) return null;203203   const session = chrome.storage.session;204204   if (!session) return null;205-  const stored = await session.get(SESSION_CACHE_KEY);206-  return (stored[SESSION_CACHE_KEY] as IdentityRecord | undefined) ?? null;205+  const stored = await session.get(IDENTITY_SESSION_CACHE_KEY);206+  return (stored[IDENTITY_SESSION_CACHE_KEY] as IdentityRecord | undefined) ?? null;207207 }208208 209209 async function cacheSet(record: IdentityRecord): Promise<void> {210210   try {211-    await chrome.storage.session?.set({ [SESSION_CACHE_KEY]: record });211+    await chrome.storage.session?.set({ [IDENTITY_SESSION_CACHE_KEY]: record });212212   } catch {213213     // The durable local envelope is authoritative; session cache is only a214214     // restart optimization and must not block identity creation or rotation.@@ -216,7 +216,7 @@216216 }217217 218218 async function clearCache(): Promise<void> {219-  await chrome.storage.session?.remove(SESSION_CACHE_KEY);219+  await chrome.storage.session?.remove(IDENTITY_SESSION_CACHE_KEY);220220 }221221 222222 setIdentityHooks({

view file

src/background/entry.lock-port.test.ts+24 −0
@@ -2,6 +2,16 @@22 // "popup-<uuid>" port from the extension page and ignores anything else.33 import { beforeEach, describe, expect, it, vi } from "vitest";44 5+// The mesh relay listener opens sockets; these tests only need to observe the6+// reconcile requests the entry wiring makes.7+const meshRelay = vi.hoisted(() => ({8+  requestMeshRelayReconcile: vi.fn(),9+  setupMeshRelayListener: vi.fn(),10+  abortMeshRelaySessions: vi.fn(),11+  selectProductionDialTargets: vi.fn(async (devices: unknown[]) => devices),12+}));13+vi.mock("./mesh-relay-listener", () => meshRelay);14+515 type StorageShape = Record<string, unknown>;616 717 interface FakePort {@@ -35,6 +45,7 @@3545     vi.resetModules();3646     storage = {};3747     connectListeners = [];48+    meshRelay.requestMeshRelayReconcile.mockClear();3849 3950     const chromeMock = {4051       runtime: {@@ -162,4 +173,17 @@162173     expect(await pending.consumeRecoveryReveal()).toBe(false);163174   });164175 176+  describe("mesh relay reconcile wiring", () => {177+    it("requests a reconcile on lock and again after unlock", async () => {178+      await import("./entry");179+      const vault = await setupUnlockedVaultWithLockOnClose();180+      meshRelay.requestMeshRelayReconcile.mockClear();181+182+      await vault.lock();183+      expect(meshRelay.requestMeshRelayReconcile.mock.calls.length, "lock").toBe(1);184+185+      expect(await vault.unlock("correct horse battery staple")).toBe(true);186+      expect(meshRelay.requestMeshRelayReconcile.mock.calls.length, "unlock").toBe(2);187+    });188+  });165189 });

view file

src/background/entry.ts+4 −1
@@ -68,7 +68,10 @@6868   const hardening = hardenExtensionStorage();6969   setLockedSyncHooks({7070     refresh: refreshLockedSyncSpool,71-    afterUnlock: drainAndRefreshLockedSyncSpool,71+    // The mesh relay dependency list covers storage reads only; lock and unlock72+    // change in-memory vault state, so they reconcile through these hooks.73+    afterUnlock: () => drainAndRefreshLockedSyncSpool().finally(requestMeshRelayReconcile),74+    onLock: () => requestMeshRelayReconcile(),7275     onDecoy: () => {7376       void clearLockedSyncPrivateKey();7477       abortMeshRelaySessions();

view file

src/background/locked-sync-spool.ts+6 −6
@@ -3,14 +3,14 @@33 import { SYNC_LIMITS, clampSyncTimestamp } from "../shared/sync-limits";44 import type { DeviceType } from "../shared/sync-types";55 import { ensureSettingsLoaded, isDecoyMode, lockedSyncRequiresUnlock } from "./vault";6-const STORAGE_KEY = "peach_locked_sync_spool_v1";6+export const SPOOL_STORAGE_KEY = "peach_locked_sync_spool_v1";77 88 /**99  * Locked sync metadata lives in session storage. The private key is retained1010  * there by default so a cold worker can resume locked sync; hardened custody1111  * omits it and therefore requires unlock after a restart.1212  */13-const PRIVATE_KEY_STORAGE_KEY = "peach_locked_sync_private_key_v1";13+export const PRIVATE_KEY_STORAGE_KEY = "peach_locked_sync_private_key_v1";1414 1515 interface CachedEntry {1616   modifiedAt: number;@@ -209,14 +209,14 @@209209 async function loadSpool(): Promise<LockedSyncSpool | null> {210210   await removeLegacyDiskSpool();211211   if (!chrome.storage.session) return null;212-  const result = await chrome.storage.session.get(STORAGE_KEY);213-  const value = (result as Record<string, unknown>)[STORAGE_KEY];212+  const result = await chrome.storage.session.get(SPOOL_STORAGE_KEY);213+  const value = (result as Record<string, unknown>)[SPOOL_STORAGE_KEY];214214   return isLockedSyncSpool(value) ? value : null;215215 }216216 217217 async function saveSpool(spool: LockedSyncSpool): Promise<void> {218218   if (!chrome.storage.session) return;219-  await chrome.storage.session.set({ [STORAGE_KEY]: spool });219+  await chrome.storage.session.set({ [SPOOL_STORAGE_KEY]: spool });220220 }221221 222222 /**@@ -228,7 +228,7 @@228228 229229 function removeLegacyDiskSpool(): Promise<void> {230230   if (!legacyDiskSpoolRemoval) {231-    legacyDiskSpoolRemoval = Promise.resolve(chrome.storage.local.remove(STORAGE_KEY))231+    legacyDiskSpoolRemoval = Promise.resolve(chrome.storage.local.remove(SPOOL_STORAGE_KEY))232232       .catch(() => undefined);233233   }234234   return legacyDiskSpoolRemoval;

view file

src/background/mesh-relay-listener.test.ts+189 −1
@@ -1,4 +1,4 @@1-import { describe, expect, it } from "vitest";1+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";22 import type { PairedDevice } from "../shared/sync-types";33 import {44   isRouteCapableMeshPeer,@@ -68,5 +68,193 @@6868     expect(nextMeshWaiterRetryDelay(2_000, false)).toBe(4_000);6969     expect(nextMeshWaiterRetryDelay(20_000, false)).toBe(30_000);7070     expect(nextMeshWaiterRetryDelay(30_000, true)).toBe(2_000);71+  });72+});73+74+// Every key reconcile() reads, with the accessor that reads it, in the area75+// that accessor uses. The literal list is the assertion: dropping a key from76+// the listener filter fails these tests.77+const RECONCILE_DEPENDENCIES: Record<string, readonly string[]> = {78+  local: [79+    "peach_settings", // vault.loadSettings via locked-sync-spool.getLockedSyncIdentity80+    "peach_local_identity_v4", // device-identity.readEnvelope81+    "peach_local_identity_v2", // device-identity.migrateLegacyIdentity82+    "peach_local_identity_initialized", // device-identity.ensureRecord83+    "peach_sync_mode_v1", // sync-settings.getSyncSettings84+    "peach_relay_url_v1", // sync-settings.getSyncSettings85+    "peach_paired_devices_v3", // paired-devices.listPairedDevices86+    "peach_pair_secrets_v1", // pair-secrets.getPairSecret87+  ],88+  session: [89+    "peach_local_identity_session", // device-identity.cacheGet90+    "peach_locked_sync_spool_v1", // locked-sync-spool.loadSpool91+    "peach_locked_sync_private_key_v1", // locked-sync-spool.getLockedSyncIdentity92+    "peach_pair_secrets_session", // pair-secrets.readSessionCache93+  ],94+};95+96+type StorageShape = Record<string, unknown>;97+type StorageListener = (98+  changes: Record<string, chrome.storage.StorageChange>,99+  areaName: string,100+) => void;101+102+function makeChrome(areas: Record<string, StorageShape>) {103+  const listeners: StorageListener[] = [];104+  const local = areas.local ?? {};105+  const sync = areas.sync ?? {};106+  const session = areas.session ?? {};107+  const area = (store: StorageShape) => ({108+    get: vi.fn(async (key?: string | string[]) => {109+      if (!key) return store;110+      if (typeof key === "string") return { [key]: store[key] };111+      return key.reduce<Record<string, unknown>>((out, item) => {112+        out[item] = store[item];113+        return out;114+      }, {});115+    }),116+    set: vi.fn(async (next: Record<string, unknown>) => { Object.assign(store, next); }),117+    remove: vi.fn(async () => undefined),118+  });119+  const chromeMock = {120+    storage: {121+      local: area(local),122+      sync: area(sync),123+      session: area(session),124+      onChanged: {125+        addListener: vi.fn((listener: StorageListener) => { listeners.push(listener); }),126+        removeListener: vi.fn(),127+      },128+    },129+  } as unknown as typeof chrome;130+  return {131+    chromeMock,132+    emit: (changes: Record<string, chrome.storage.StorageChange>, areaName: string) => {133+      for (const listener of listeners) listener(changes, areaName);134+    },135+    reads: () =>136+      (chromeMock.storage.local.get as ReturnType<typeof vi.fn>).mock.calls.length +137+      (chromeMock.storage.session.get as ReturnType<typeof vi.fn>).mock.calls.length,138+    resetReads: () => {139+      (chromeMock.storage.local.get as ReturnType<typeof vi.fn>).mockClear();140+      (chromeMock.storage.session.get as ReturnType<typeof vi.fn>).mockClear();141+    },142+  };143+}144+145+describe("mesh relay storage trigger filter", () => {146+  beforeEach(() => {147+    vi.resetModules();148+    // Listener installation is memoized on globalThis so a restarted worker149+    // installs it once; each test starts from an uninstalled worker.150+    delete (globalThis as { __peachMeshListenerState?: unknown }).__peachMeshListenerState;151+    vi.useFakeTimers({ toFake: ["setTimeout", "clearTimeout"] });152+  });153+154+  afterEach(() => {155+    vi.useRealTimers();156+    vi.unstubAllGlobals();157+  });158+159+  // Reconcile runs on a microtask; a zero-length timer advance drains it.160+  const flush = () => vi.advanceTimersByTimeAsync(0);161+162+  async function install(mock: ReturnType<typeof makeChrome>): Promise<void> {163+    vi.stubGlobal("chrome", mock.chromeMock);164+    const { setupMeshRelayListener } = await import("./mesh-relay-listener");165+    setupMeshRelayListener();166+    await flush();167+    mock.resetReads();168+  }169+170+  it("ignores ten unrelated local writes and unrelated removals", async () => {171+    const mock = makeChrome({});172+    await install(mock);173+    expect(mock.reads()).toBe(0);174+175+    const unrelated: Array<Record<string, chrome.storage.StorageChange>> = [176+      { peach_pro_nudge_next_at: { newValue: 1 } },177+      { peach_last_sync_at: { newValue: 2 } },178+      { peach_last_sync_result: { newValue: "sync_ok" } },179+      { peach_pending_sync_alerts_v1: { newValue: [] } },180+      { peach_device_name: { newValue: "laptop" } },181+      { peach_codex_verify_code: { newValue: "123456" } },182+      { peach_license_revocations_v1: { newValue: [] } },183+      { peach_manual_summon_recall_v1: { newValue: {} } },184+      { peach_vault_a: { oldValue: {} } },185+      { peach_pending_vouched_devices_v1: { oldValue: [] } },186+    ];187+    // One flush per write: these are separate events, not one coalesced burst.188+    for (const changes of unrelated) {189+      mock.emit(changes, "local");190+      await flush();191+    }192+193+    expect(mock.reads()).toBe(0);194+  });195+196+  it("ignores a dependency-named key written in another area", async () => {197+    const mock = makeChrome({});198+    await install(mock);199+200+    mock.emit({ peach_locked_sync_spool_v1: { newValue: {} } }, "local");201+    mock.emit({ peach_settings: { newValue: {} } }, "sync");202+    mock.emit({ peach_pair_secrets_session: { newValue: {} } }, "local");203+    await flush();204+205+    expect(mock.reads()).toBe(0);206+  });207+208+  it("reconciles when any dependency key changes or is removed", async () => {209+    const mock = makeChrome({});210+    await install(mock);211+212+    for (const [areaName, keys] of Object.entries(RECONCILE_DEPENDENCIES)) {213+      for (const key of keys) {214+        mock.emit({ [key]: { newValue: "changed" } }, areaName);215+        await flush();216+        expect(mock.reads(), `${areaName}/${key} write`).toBe(1);217+        mock.resetReads();218+219+        mock.emit({ [key]: { oldValue: "changed" } }, areaName);220+        await flush();221+        expect(mock.reads(), `${areaName}/${key} removal`).toBe(1);222+        mock.resetReads();223+      }224+    }225+  });226+227+  it("reconciles once for an event that mixes an unrelated and a dependency key", async () => {228+    const mock = makeChrome({});229+    await install(mock);230+231+    mock.emit(232+      {233+        peach_last_sync_at: { newValue: 2 },234+        peach_paired_devices_v3: { newValue: [] },235+      },236+      "local",237+    );238+    await flush();239+240+    expect(mock.reads()).toBe(1);241+  });242+243+  it("coalesces a burst of dependency writes into one reconciliation", async () => {244+    const mock = makeChrome({});245+    await install(mock);246+247+    mock.emit(248+      {249+        peach_sync_mode_v1: { newValue: "off" },250+        peach_relay_url_v1: { newValue: "wss://relay.example" },251+        peach_paired_devices_v3: { newValue: [] },252+      },253+      "local",254+    );255+    mock.emit({ peach_pair_secrets_session: { newValue: {} } }, "session");256+    await flush();257+258+    expect(mock.reads()).toBe(1);71259   });72260 });

view file

src/background/mesh-relay-listener.ts+75 −5
@@ -19,20 +19,88 @@1919 import {2020   createLockedSyncVaultAdapter,2121   getLockedSyncIdentity,22+  PRIVATE_KEY_STORAGE_KEY,23+  SPOOL_STORAGE_KEY,2224 } from "./locked-sync-spool";23-import { getLocalPairingIdentity } from "./device-identity";2425 import {26+  getLocalPairingIdentity,27+  IDENTITY_MARKER_KEY,28+  IDENTITY_RECORD_KEY,29+  IDENTITY_SESSION_CACHE_KEY,30+  LEGACY_IDENTITY_KEY,31+} from "./device-identity";32+import {2533   findPairedDeviceById,2634   listPairedDevices,2735   markLastSyncedAt,36+  REGISTRY_KEY,2837 } from "./paired-devices";29-import { getSyncSettings, relayInForce } from "./sync-settings";30-import { isUnlocked, isDecoyMode, getRootKeyHex } from "./vault";31-import { getPairSecret } from "./pair-secrets";38+import { getSyncSettings, RELAY_URL_KEY, relayInForce, SYNC_MODE_KEY } from "./sync-settings";39+import { isUnlocked, isDecoyMode, getRootKeyHex, SETTINGS_STORAGE_KEY } from "./vault";40+import { getPairSecret, PAIR_SECRETS_KEY, SESSION_PAIR_SECRETS_KEY } from "./pair-secrets";3241 import { recordInboundSyncCompletion } from "./sync-trigger";3342 3443 const RECONCILE_INTERVAL_MS = 60_000;3544 45+/**46+ * Storage keys whose value reconcile() reads, per area, with the accessor that47+ * reads each one. A change or removal here can change which waiters reconcile48+ * keeps, so it requests a reconcile; every other write is ignored.49+ *50+ * This table covers storage reads only. Lock and unlock also change the51+ * in-memory vault state reconcile() reads (isUnlocked, isDecoyMode,52+ * getRootKeyHex), which no storage key reports; they request their reconcile53+ * through the onLock and afterUnlock hooks wired in entry.ts.54+ *55+ * local:56+ *   SETTINGS_STORAGE_KEY       vault.loadSettings (via locked-sync-spool)57+ *   IDENTITY_RECORD_KEY        device-identity.readEnvelope58+ *   IDENTITY_MARKER_KEY        device-identity.ensureRecord59+ *   LEGACY_IDENTITY_KEY        device-identity.migrateLegacyIdentity60+ *   SYNC_MODE_KEY              sync-settings.getSyncSettings61+ *   RELAY_URL_KEY              sync-settings.getSyncSettings62+ *   REGISTRY_KEY               paired-devices.listPairedDevices63+ *   PAIR_SECRETS_KEY           pair-secrets.getPairSecret64+ * session:65+ *   IDENTITY_SESSION_CACHE_KEY device-identity.cacheGet66+ *   SPOOL_STORAGE_KEY          locked-sync-spool.loadSpool67+ *   PRIVATE_KEY_STORAGE_KEY    locked-sync-spool.getLockedSyncIdentity68+ *   SESSION_PAIR_SECRETS_KEY   pair-secrets.readSessionCache69+ *70+ * Not listed: chrome.storage.sync device name (metadata only, never part of71+ * the reconcile decision), the revocation issuer archive (read by72+ * listRevocationIssuerKeyMap, not by reconcile or selectProductionDialTargets),73+ * and the keys probed by hasLegacyTrustState on an identity-less start, which74+ * throws before the abort loop and so leaves the existing waiters as they were.75+ */76+const RECONCILE_STORAGE_KEYS: Record<string, readonly string[]> = {77+  local: [78+    SETTINGS_STORAGE_KEY,79+    IDENTITY_RECORD_KEY,80+    IDENTITY_MARKER_KEY,81+    LEGACY_IDENTITY_KEY,82+    SYNC_MODE_KEY,83+    RELAY_URL_KEY,84+    REGISTRY_KEY,85+    PAIR_SECRETS_KEY,86+  ],87+  session: [88+    IDENTITY_SESSION_CACHE_KEY,89+    SPOOL_STORAGE_KEY,90+    PRIVATE_KEY_STORAGE_KEY,91+    SESSION_PAIR_SECRETS_KEY,92+  ],93+};94+95+function affectsReconcile(96+  changes: Record<string, chrome.storage.StorageChange>,97+  areaName: string,98+): boolean {99+  const keys = RECONCILE_STORAGE_KEYS[areaName];100+  if (!keys) return false;101+  return Object.keys(changes).some((key) => keys.includes(key));102+}103+36104 interface MeshIdentity {37105   identity: Omit<SyncPeerIdentity, "longTermPrivateKey">;38106   privateKey: Uint8Array;@@ -88,7 +156,9 @@88156   const listener = state();89157   if (listener.installed) return;90158   listener.installed = true;91-  chrome.storage?.onChanged?.addListener(() => requestMeshRelayReconcile());159+  chrome.storage?.onChanged?.addListener((changes, areaName) => {160+    if (affectsReconcile(changes, areaName)) requestMeshRelayReconcile();161+  });92162   requestMeshRelayReconcile();93163 }94164 

view file

src/background/sync-settings.ts+2 −2
@@ -24,8 +24,8 @@2424   relayUrl: string;2525 }2626 27-const RELAY_URL_KEY = "peach_relay_url_v1";28-const SYNC_MODE_KEY = "peach_sync_mode_v1";27+export const RELAY_URL_KEY = "peach_relay_url_v1";28+export const SYNC_MODE_KEY = "peach_sync_mode_v1";2929 3030 export async function getSyncSettings(): Promise<SyncSettings> {3131   try {

view file

src/background/vault.session-escrow.test.ts+16 −0
@@ -89,6 +89,22 @@8989     expect(v2.getEntries().some((e) => e.title === "Recovered")).toBe(true);9090   });9191 92+  it("unlockWithKey runs the post-unlock hook like the password path", async () => {93+    const v1 = await import("./vault");94+    await v1.createVault("pin-hook-pass-abc123");95+    // The PIN path unwraps the pre-derived vault key; pin the hook wiring only.96+    const derivedHex = v1.getDerivedKeyHex();97+    await v1.lock();98+99+    const afterUnlock = vi.fn(async () => undefined);100+    v1.setLockedSyncHooks({ refresh: async () => undefined, afterUnlock });101+    // The PIN path unwraps the vault key from the PIN wrap; this test pins the102+    // hook wiring, so it drives the key directly.103+    const result = await v1.unlockWithKey(derivedHex);104+    expect(result.ok).toBe(true);105+    expect(afterUnlock).toHaveBeenCalledTimes(1);106+  });107+92108   it("restoreFromSession rehydrates rootKey so background sync survives a SW restart", async () => {93109     // Background sync bug: entry.ts calls restoreFromSession() on every SW wake-up,94110     // then triggerSyncIfReachable. The runner needs getRootKeyHex() to be non-null

view file

src/background/vault.ts+13 −2
@@ -56,6 +56,7 @@5656 // configuration is recorded only inside the encrypted payload of slot A.5757 const SLOT_A = "peach_vault_a";5858 const SLOT_B = "peach_vault_b";59+export const SETTINGS_STORAGE_KEY = "peach_settings";5960 6061 // Plaintext is padded to the next multiple of this size before encryption.6162 // This coarsens ciphertext-length leakage into 1 KiB buckets.@@ -393,7 +394,7 @@393394 async function persistSettings(): Promise<void> {394395   try {395396     await chrome.storage.local.set({396-      peach_settings: {397+      [SETTINGS_STORAGE_KEY]: {397398         // Legacy plaintext recall is carried through every settings write until398399         // adoption commits the encrypted copy and clears it explicitly.399400         ...settings,@@ -416,7 +417,7 @@416417 }417418 418419 async function loadSettings(): Promise<void> {419-  const result = await chrome.storage.local.get("peach_settings");420+  const result = await chrome.storage.local.get(SETTINGS_STORAGE_KEY);420421   settings = (result as { peach_settings?: VaultSettings }).peach_settings ?? {};421422 }422423 @@ -805,6 +806,7 @@805806 806807 let lockedSyncRefreshHook: (() => Promise<void>) | null = null;807808 let lockedSyncUnlockHook: (() => Promise<void>) | null = null;809+let vaultLockHook: (() => void) | null = null;808810 let decoySyncTeardownHook: (() => void) | null = null;809811 export type IdentityHooks = {810812   /** Drop the cached identity: the session is no longer a real unlocked one. */@@ -844,10 +846,12 @@844846 export function setLockedSyncHooks(hooks: {845847   refresh: () => Promise<void>;846848   afterUnlock: () => Promise<void>;849+  onLock?: () => void;847850   onDecoy?: () => void;848851 }): void {849852   lockedSyncRefreshHook = hooks.refresh;850853   lockedSyncUnlockHook = hooks.afterUnlock;854+  vaultLockHook = hooks.onLock ?? null;851855   decoySyncTeardownHook = hooks.onDecoy ?? null;852856 }853857 @@ -2593,6 +2597,7 @@25932597   // The decrypted identity is session state as well, so a locked vault must not25942598   // leave one behind; clear it after the in-memory state is gone.25952599   await notifyIdentitySessionEnded();2600+  vaultLockHook?.();25962601 }25972602 25982603 /// Identifies the current unlock session for authorization across awaited work.@@ -2656,6 +2661,12 @@26562661     await saveSessionKey(masterKeyBytes, "real", epoch);26572662     if (stale()) return { ok: false, error: "invalid_key" };26582663     await restoreManualSummonRecall();2664+    if (stale()) return { ok: false, error: "invalid_key" };2665+    // The PIN/adoption unlock path publishes the same in-memory state as the2666+    // password path, and the mesh relay reconcile depends on it.2667+    await lockedSyncUnlockHook?.().catch((error) => {2668+      console.warn("[Peach sync] locked inbox drain failed:", error);2669+    });26592670     if (stale()) return { ok: false, error: "invalid_key" };26602671     return { ok: true, entries };26612672   } catch {

view file