/** * Quantum Time Window Utilities for LIT Actions * * PRIMARY WORKFLOW FOR LIT ACTIONS: * * ```typescript * // 1. Wait for safe quantum moment (waits if in dead zone) * await waitForSafeQuantumMoment(); * * // 2. Validate signature timestamp (throws if invalid) * validateQuantumTimestamp(timestampOnSignature); * ``` * * The macro validateQuantumTimestamp() combines waiting + validation: * - Ensures LIT Action only validates when NOT in dead zone * - Ensures signature is from current quantum (prevents replay attacks) * - Throws error if validation fails * * Dead Zone Protection (16 seconds: 8+8): * - Protects against clock desynchronization * - Protects against Ethereum miner timestamp manipulation (±15s) * - Ensures deterministic validation across all validators * * See QUANTUM_TIME_WINDOW.md for full documentation. */ import { DEAD_ZONE_SECONDS, QUANTUM_WINDOW_SECONDS, SAFE_EXECUTION_WINDOW_SECONDS } from "../constants"; export { QUANTUM_WINDOW_SECONDS, DEAD_ZONE_SECONDS, SAFE_EXECUTION_WINDOW_SECONDS }; /** Maximum observed execution time for a LIT Action (seconds) */ export declare const LIT_ACTION_MAX_EXECUTION_SECONDS = 30; /** * Calculate quantum window start for given timestamp * * @param timestamp - Unix timestamp in seconds * @returns Quantum window start timestamp */ export declare function getQuantumStart(timestamp: number): number; /** * Calculate quantum window end for given timestamp * * @param timestamp - Unix timestamp in seconds * @returns Quantum window end timestamp */ export declare function getQuantumEnd(timestamp: number): number; /** * Get current quantum timestamp (start of current quantum) * * Use this for signing operations. * * @returns Current quantum start timestamp */ export declare function getCurrentQuantumTimestamp(): number; /** * Check if currently in dead zone (first 8s or last 8s of quantum) * * Dead zone = seconds 0-7 OR 52-59 of each 60-second quantum * * @param now - Current Unix timestamp (defaults to Date.now()/1000) * @returns True if in dead zone */ export declare function isInDeadZone(now?: number): boolean; /** * Get seconds remaining in current quantum * * @param now - Current Unix timestamp (defaults to Date.now()/1000) * @returns Seconds until quantum expires */ export declare function getSecondsRemainingInQuantum(now?: number): number; /** * Wait for safe quantum moment (LIT Actions use) * * LIT Actions must wait during dead zone to ensure deterministic validation. * Waits until second 8 of next quantum (first safe second). * * Decision logic: * - If in dead zone: Wait until second 8 of next quantum * - Otherwise: Proceed immediately * * @returns Promise that resolves when safe to operate */ export declare function waitForSafeQuantumMoment(): Promise; /** * Validate timestamp is within 3-quantum window (throws on invalid) * * This is the PRIMARY macro for LIT Actions validation. * * Accepts signatures from: * - PAST quantum (currentQuantum - 60) * - CURRENT quantum * - NEXT quantum (currentQuantum + 60) * * Boundary protection is NOT here: callers run `waitForSafeQuantumMoment()` first, so * validation happens at seconds 8–51 of a quantum, where this rule and the contract's * `_validateQuantum` accept exactly the same signatures * (`formal/lean/DH/Quantum.lean` `lit_eq_contract_after_wait`). The dead-zone branches that * used to follow the window check were unreachable (`lit_eq_three_windows`) and were removed * (plan A15). * * @param timestampOnSignature - Timestamp from signed message * @param now - Current Unix timestamp (defaults to Date.now()/1000) * @throws Error if timestamp is outside the 3-quantum window */ export declare function validateQuantumTimestamp(timestampOnSignature: number, now?: number, options?: { strictCurrentQuantum?: boolean; }): void; /** * Check if timestamp is valid (boolean version - does not throw) * * Rules: * 1. Must be within 3-quantum window (past, current, or next) * 2. Must not be in dead zones * * @param signatureTimestamp - Timestamp from signed message * @param now - Current Unix timestamp (defaults to Date.now()/1000) * @returns True if valid */ export declare function isTimestampValid(signatureTimestamp: number, now?: number): boolean; /** * Get next quantum timestamp * * @param now - Current Unix timestamp (defaults to Date.now()/1000) * @returns Next quantum timestamp */ export declare function getNextQuantumTimestamp(now?: number): number; /** * Get quantum info for debugging * * @param now - Current Unix timestamp (defaults to Date.now()/1000) * @returns Quantum information object */ export declare function getQuantumInfo(now?: number): { currentTime: number; currentQuantum: number; timeInQuantum: number; secondsRemaining: number; isInDeadZone: boolean; nextQuantum: number; }; /** * Get safe quantum info (async - waits if needed) * * This is useful for debugging but not typically needed in LIT Actions. * LIT Actions should use waitForSafeQuantumMoment() + validateQuantumTimestamp(). * * @returns Promise resolving to quantum information for safe operation */ export declare function getSafeQuantumInfo(): Promise<{ currentTime: number; currentQuantum: number; timeInQuantum: number; secondsRemaining: number; isInDeadZone: boolean; nextQuantum: number; }>; //# sourceMappingURL=quantum-time.module.d.ts.map