/** * A cached operator session — the *human* (email) principal, distinct from the * agent's per-wallet SIWX identity. Minted in the browser via the device- * authorization flow (`run402 operator login`) and cached at the BASE config * dir (not per-wallet) because it is email-scoped: one login spans every local * named wallet that the email controls. * * Stored shape vs the gateway token payload: the gateway returns a relative * `expires_in` (seconds); we persist the absolute `expires_at` (epoch ms, * computed at write time) so a cached session can be checked for expiry without * knowing when it was written. `absolute_expires_at` (the gateway's ~12h hard * cap) is stored verbatim, for display and a defensive secondary expiry check. */ export interface OperatorSession { operator_session_token: string; token_type: string; email: string; wallets: string[]; /** Epoch ms when the access token expires (issued_at + expires_in). */ expires_at: number; /** ISO 8601 absolute cap from the gateway; the session cannot outlive it. */ absolute_expires_at: string; } /** * The token payload returned by the device/token poll (and the underlying * email/passkey mints). Relative `expires_in`; mapped to an absolute * `expires_at` by {@link operatorSessionFromTokenResponse} before caching. */ export interface OperatorSessionTokenResponse { operator_session_token: string; token_type?: string; expires_in?: number; absolute_expires_at?: string; email?: string; wallets?: string[]; } /** * Path to the cached operator session: `{base}/operator-session.json`, at the * BASE config dir — NOT the per-profile dir, because the session is email- * scoped and shared across all local named wallets. `RUN402_OPERATOR_SESSION_PATH` * overrides for testing, mirroring `RUN402_ALLOWANCE_PATH`. */ export declare function getOperatorSessionPath(): string; /** * Load the cached operator session from disk. * * Returns `null` for the "no session cached" cases (file absent, unreadable, or * unparseable JSON) — callers treat that as "not logged in" and point at * `run402 operator login`. Throws a structured `Error` when the file parses as * JSON but the shape is wrong, so a corrupted cache surfaces a clear fix-it * instead of a downstream `TypeError`. */ export declare function readOperatorSession(path?: string): OperatorSession | null; /** Persist an operator session atomically (temp-file + rename), mode 0600. */ export declare function saveOperatorSession(data: OperatorSession, path?: string): void; /** * Delete the cached operator session — the local half of `operator logout`. * Best-effort and idempotent: a missing file is a no-op. */ export declare function clearOperatorSession(path?: string): void; /** * Whether a cached session is past its usable life. The access token * (`expires_at`, ~30m) always expires before the absolute cap (~12h), so * checking it is sufficient; the absolute cap is honored defensively. A small * skew buffer treats a session expiring within `skewMs` as already expired, so * we never send a token that dies mid-flight. */ export declare function isOperatorSessionExpired(session: OperatorSession, nowMs?: number, skewMs?: number): boolean; /** * Read the cached session and return it only if still usable; `null` if absent * or expired. The bearer fetch path and `operator overview` use this so an * expired cache surfaces as "not logged in" instead of a server 401. */ export declare function loadLiveOperatorSession(path?: string, nowMs?: number): OperatorSession | null; /** * Map a gateway token payload (relative `expires_in`) into the cached shape * (absolute `expires_at`). `nowMs` is injectable for deterministic tests. */ export declare function operatorSessionFromTokenResponse(resp: OperatorSessionTokenResponse, nowMs?: number): OperatorSession; //# sourceMappingURL=operator-session.d.ts.map