import { z } from "zod"; import { HashChain, type ChainHead } from "../audit/HashChain.js"; import type { LineWriter } from "../audit/LineAuditSink.js"; /** * What the security stream may say. Every field is an identifier, a code, an * origin, or a count; no value, parameter, header, path, or body has a place * in this schema, so an event cannot carry one by mistake. */ export declare const SecurityEventSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ event: z.ZodLiteral<"POSTURE_VERIFIED">; checks: z.ZodNumber; waived: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"POSTURE_WAIVED">; check: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"POSTURE_DRIFT">; check: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"POSTURE_RESTORED">; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"SECRET_ROTATED">; name: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"SECRET_RELOAD_REFUSED">; name: z.ZodString; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"AUTHORITY_CLIENTS_REBUILT">; name: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"LEAK_SUSPECTED">; patterns: z.ZodArray; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EGRESS_REFUSED">; origin: z.ZodNullable; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"UPSTREAM_TLS_REFUSED">; origin: z.ZodString; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"UPSTREAM_PROOF_MISSING">; origin: z.ZodString; stops_at: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"UPSTREAM_UNVERIFIED">; origin: z.ZodString; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"UPSTREAM_PROOF_RESTORED">; origin: z.ZodString; method: z.ZodEnum<{ file: "file"; dns: "dns"; }>; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"AUTH_FAILED">; method: z.ZodEnum<{ bearer: "bearer"; jwt: "jwt"; mtls: "mtls"; tenant_key: "tenant_key"; none: "none"; }>; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"AUTH_FAILED_SUPPRESSED">; method: z.ZodEnum<{ bearer: "bearer"; jwt: "jwt"; mtls: "mtls"; tenant_key: "tenant_key"; none: "none"; }>; code: z.ZodString; count: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"PRINCIPAL_LOCKED">; principal: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"PRINCIPALS_LOADED">; principals: z.ZodNumber; proposers: z.ZodNumber; operators: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"LEGACY_PRINCIPAL_MODE">; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"BEARER_PRINCIPAL_CONFIGURED">; principal: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"JWKS_REFRESHED">; keys: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"JWKS_REFRESH_FAILED">; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"OPERATOR_ACTION">; principal: z.ZodString; action: z.ZodEnum<{ status: "status"; "secrets.reload": "secrets.reload"; metrics: "metrics"; halt: "halt"; resume: "resume"; }>; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"TLS_CONTEXT_ROTATED">; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CHAIN_RESUMED">; chain: z.ZodString; head: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CHAIN_CHECKPOINT">; chain: z.ZodString; head: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"HALTED">; trigger: z.ZodString; reason: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"RESUMED">; trigger: z.ZodString; reason: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"UNKNOWN_ATTEMPTS_OVERRIDDEN">; unknown: z.ZodNumber; reason: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"HARD_LIMIT_REFUSED">; code: z.ZodString; currency: z.ZodNullable; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CLOCK_SKEW_EXCEEDED">; skew_ms: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"JOURNAL_WRITE_FAILED">; record: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"OPEN_ATTEMPT_FOUND_AT_STARTUP">; intent_id: z.ZodString; state: z.ZodEnum<{ OPENED: "OPENED"; CLAIMED: "CLAIMED"; }>; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"OPEN_ATTEMPT_RESOLVED">; intent_id: z.ZodString; resolution: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EFFECT_OBSERVED">; intent_id: z.ZodString; comparison: z.ZodEnum<{ MATCH: "MATCH"; MISMATCH: "MISMATCH"; PENDING: "PENDING"; }>; confirmation: z.ZodString; receipt: z.ZodEnum<{ MATCH: "MATCH"; MISMATCH: "MISMATCH"; SILENT: "SILENT"; ABSENT: "ABSENT"; }>; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EFFECT_MISMATCH">; intent_id: z.ZodString; fields: z.ZodArray; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EFFECT_RECEIPT_MISMATCH">; intent_id: z.ZodString; receipt_status: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EFFECT_PENDING_CONFIRMATION">; intent_id: z.ZodString; method: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"PROVIDER_REFUSED">; intent_id: z.ZodString; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"FINALIZATION_PENDING">; intent_id: z.ZodString; outcome: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"SEPARATION_OF_DUTIES_VIOLATED">; principal: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_GRANT_HELD">; intent_id: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_AUTHORIZATION_MATCHED">; intent_id: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_AUTHORIZATION_INCREMENTED">; intent_id: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_CLAIM_RECORD_FAILED">; intent_id: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_AUTHORIZATION_PENDING">; intent_id: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_AUTHORIZATION_NO_MATCH">; intent_id: z.ZodNullable; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_AUTHORIZATION_SETTLED">; intent_id: z.ZodString; outcome: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_OUTCOMES_DROPPED">; count: z.ZodNumber; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_OUTCOMES_PUBLISHED">; submitted: z.ZodNumber; accepted: z.ZodNumber; duplicates: z.ZodNumber; conflicts: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"CARD_OUTCOMES_REFUSED">; code: z.ZodString; retry: z.ZodBoolean; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_BUNDLE_LOADED">; bundle_id: z.ZodString; policy_version: z.ZodString; kid: z.ZodString; expires_at: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_BUNDLE_REFRESH_FAILED">; code: z.ZodString; failures: z.ZodNumber; retry_ms: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_BUNDLE_EXPIRED">; bundle_id: z.ZodString; policy_version: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_USAGE_KEY_LOADED">; kid: z.ZodString; installation_id: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_USAGE_REPORTED">; period: z.ZodString; destination: z.ZodEnum<{ file: "file"; url: "url"; }>; total: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_USAGE_REPORT_FAILED">; period: z.ZodString; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_USAGE_TALLY_RESET">; head: z.ZodNumber; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_USAGE_PERSIST_FAILED">; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_REPLAY_CLEANUP_FAILED">; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_LICENCE_WARNING">; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EDGE_LICENCE_CLEARED">; code: z.ZodString; }, z.core.$strict>, z.ZodObject<{ event: z.ZodLiteral<"EVIDENCE_EXPORTED">; principal: z.ZodString; files: z.ZodNumber; signed: z.ZodBoolean; }, z.core.$strict>], "event">; export type SecurityEvent = z.infer; export declare const SECURITY_STREAM = "agent-safe.security/1"; export interface SecurityEventsOptions { readonly clock?: () => Date; /** The chain to link lines on; a fresh one from genesis when the process has no checkpoint. */ readonly chain?: HashChain; } /** * The security stream: one JSON line per event on stderr, validated against * the schema before it is written and linked on its own hash chain. An * event that does not fit is dropped and counted rather than thrown, * because a request path must never fail on its own evidence. Subscribers * (the metrics) see each event after it is written. */ export declare class SecurityEvents { private readonly write; private droppedCount; private readonly clock; readonly chain: HashChain; private readonly listeners; private readonly taps; constructor(write: LineWriter, options?: SecurityEventsOptions); get dropped(): number; get head(): ChainHead; /** * Every line this stream writes, as written. The evidence export keeps a * bounded window of them; a subscriber that wants the event rather than * the line uses `subscribe`. */ tap(listener: (line: string) => void): () => void; subscribe(listener: (event: SecurityEvent) => void): () => void; emit(event: SecurityEvent): void; } //# sourceMappingURL=SecurityEvents.d.ts.map