/** * Bound on how long a single OS credential-store round trip may block * before this process gives up on it. Deliberately generous, not tuned: the * incident's own evidence (an interactive-session read of the SAME * credential returned in 7ms) shows any real answer — including a * plausibly slow one under disk/RPC contention — comes back in well under * 1s. 5s is headroom, not a budget. If this ever needs tightening or * loosening, this is the one constant to change — never disable the bound * entirely (see the file header for what "entirely" cost the last time). */ export declare const CREDENTIAL_STORE_TIMEOUT_MS = 5000; export type BoundedGetStatus = 'found' | 'not-found' | 'timeout' | 'error'; export interface BoundedGetResult { status: BoundedGetStatus; value: string | null; errorMessage?: string; } /** * Thrown by `BoundedEntry`/`boundedSetPassword` specifically for the TIMEOUT * case — never for a genuine "not found" or a fast credential-store error. * Load-bearing distinction, not just an ADR-015 nicety: a plain "the read * failed" is safe to treat as "no key exists yet" (the existing, pre-fix * tolerance — see keystore.ts's `getOrCreateCredentialStoreKey`), because a * fast failure genuinely means the store looked and found nothing. A TIMEOUT * means the OPPOSITE — we asked and got no answer in time, so we have NO * IDEA whether a key exists. Treating that as "no key exists" would let * `getOrCreateCredentialStoreKey` fall through to minting a brand-new * random key and OVERWRITING whatever the scoped identity actually holds — * destroying a real, already-in-use encryption key on nothing more than a * slow read, with no way to recover it afterward (the DB it encrypted * becomes permanently unreadable; see serve.ts's `rewrapWrongKeyError` for * how loud/fatal that failure is on the NEXT boot, by which point the * original key is already gone). Callers that must not risk this (the read * paths in keystore.ts) catch this specific type and re-throw it past their * own "swallow a fast failure as not-found" logic instead of proceeding. */ export declare class CredentialStoreTimeoutError extends Error { constructor(message: string); } export declare function __setChildScriptPathForTests(path: string | null): void; /** * Reads `service`/`account` from the OS credential store with a hard * wall-clock bound, by running the actual `Entry(...).getPassword()` call * inside a short-lived child process (keystore-child.ts) instead of this * thread. Never throws — every outcome (found / genuinely absent / errored * / timed out) is reported in the returned status; ADR-015 rule 4 requires * the timeout case specifically be distinguishable from "not found", so * callers that only care about "do we have a value" still get a WARN log * for the timeout case emitted here, once, regardless of how they treat the * returned status afterward. */ export declare function boundedGetPassword(service: string, account: string, timeoutMs?: number): BoundedGetResult; /** * Writes `secret` to the OS credential store under `service`/`account`, * with the same hard wall-clock bound and out-of-thread execution as * boundedGetPassword. Throws on ANY failure (timeout included) — this * mirrors `Entry.setPassword()`'s own throw-on-failure contract exactly, so * every existing caller's try/catch (keystore.ts's fallback-to-key-file / * fallback-to-secrets.env logic) needs no changes to pick up the bound; see * this file's header for why reusing the existing fallback path, not * inventing a new one, is the point. */ export declare function boundedSetPassword(service: string, account: string, secret: string, timeoutMs?: number): void; /** Structural subset of `@napi-rs/keyring`'s `Entry` actually used anywhere * in this repo — the interface `BoundedEntry` (and every test fake passed * to keystore.ts's `__setEntryCtorForTests`) needs to satisfy. */ export interface EntryLike { getPassword(): string | null; setPassword(password: string): void; } /** * Drop-in replacement for `@napi-rs/keyring`'s `Entry`, backed by the * bounded child-process calls above. keystore.ts wires this in as * `EntryCtor`'s DEFAULT (see that file) — every existing credential-store * call site (db-key, bearer, sync-device-token; scoped AND legacy * identities; every doctor check and CLI command built on top) already * funnels through `EntryCtor`, so swapping the default here closes the * hang hazard everywhere at once, with no per-call-site changes. * * getPassword() intentionally mirrors the real Entry's own tolerated * contract for a FAST failure (return `null` OR throw both mean "no key * yet" to every existing caller — see keystore.ts's * `getOrCreateCredentialStoreKey` doc comment): 'found' -> the value, * 'not-found' -> null, 'error' -> a plain Error (safe for a caller to * swallow and treat as "no key yet", exactly like today). * * 'timeout' is DELIBERATELY DIFFERENT: it throws a `CredentialStoreTimeoutError` * specifically (see that class's doc comment for the destructive-overwrite * hazard this distinction exists to prevent) rather than a plain `Error`, so * a caller that must not risk minting-over-an-unreadable-existing-key * (`getOrCreateCredentialStoreKey`'s read paths) can `instanceof`-check and * refuse to swallow it, instead of falling through to a write it has no * business making under genuine uncertainty. */ export declare class BoundedEntry implements EntryLike { private readonly service; private readonly account; constructor(service: string, account: string); getPassword(): string | null; setPassword(password: string): void; }