import type { Delegation, RevocationRecord, ActionReceipt, SignedPassport, FloorAttestation } from '../types/passport.js';
import type { ScopedReputation, DemotionEvent } from '../types/reputation-authority.js';
import type { KeyRotationEntry } from '../types/identity.js';
export interface CursorPage<T> {
    items: T[];
    nextCursor?: string;
    hasMore: boolean;
}
export interface ReceiptFilter {
    agentId?: string;
    delegationId?: string;
    scope?: string;
    after?: string;
    before?: string;
}
export interface SpendReservation {
    reservationId: string;
    delegationId: string;
    amount: number;
    currency: string;
    reservedAt: string;
    expiresAt: string;
    status: 'reserved' | 'committed' | 'released';
}
export interface SpendReservationResult {
    success: boolean;
    reservationId?: string;
    currentSpent?: number;
    limit?: number;
    reason?: string;
}
export interface StoredAgentRecord {
    agentId: string;
    passport: SignedPassport;
    attestation: FloorAttestation;
    registeredAt: string;
    metadata?: Record<string, unknown>;
}
export interface GatewayCheckpoint {
    checkpointId: string;
    gatewayId: string;
    sequence: number;
    receiptHeadHash: string;
    stateRootHash: string;
    delegationCount: number;
    revocationCount: number;
    receiptCount: number;
    protocolVersion: string;
    createdAt: string;
    previousCheckpointHash: string;
    signature: string;
}
export interface IntegrityReport {
    schemaVersion: number;
    receiptChainValid: boolean;
    receiptCount: number;
    brokenLinks: string[];
    delegationCount: number;
    revocationCount: number;
    checkpointSequence: number;
    checkpointValid: boolean;
    errors: string[];
}
export type CheckpointCallback = (hash: string, sequence: number) => void | Promise<void>;
export interface StorageOperations {
    putAgent(agent: StoredAgentRecord): Promise<void>;
    getAgent(agentId: string): Promise<StoredAgentRecord | null>;
    listAgents(): Promise<StoredAgentRecord[]>;
    putDelegation(delegation: Delegation): Promise<void>;
    getDelegation(delegationId: string): Promise<Delegation | null>;
    getDelegationsForAgent(agentPublicKey: string): Promise<Delegation[]>;
    reserveSpend(delegationId: string, amount: number, currency: string, ttlSeconds?: number): Promise<SpendReservationResult>;
    commitSpend(reservationId: string): Promise<boolean>;
    releaseSpend(reservationId: string): Promise<boolean>;
    getSpentAmount(delegationId: string): Promise<number>;
    appendRevocation(revocation: RevocationRecord): Promise<void>;
    isRevoked(delegationId: string): Promise<boolean>;
    getRevocationsBy(revokedBy: string): Promise<RevocationRecord[]>;
    appendReceipt(receipt: ActionReceipt): Promise<void>;
    getReceipt(receiptId: string): Promise<ActionReceipt | null>;
    queryReceipts(filter: ReceiptFilter, limit?: number, cursor?: string): Promise<CursorPage<ActionReceipt>>;
    getReceiptCount(agentId?: string, scope?: string): Promise<number>;
    /** GDPR tombstone: redacts payload but preserves hash chain + signature */
    tombstoneReceipt(receiptId: string, reason: string): Promise<boolean>;
    getReputation(agentId: string, scope: string): Promise<ScopedReputation | null>;
    putReputation(rep: ScopedReputation): Promise<void>;
    appendDemotion(demotion: DemotionEvent): Promise<void>;
    getDemotionCount(agentId: string): Promise<number>;
    getDemotions(agentId: string): Promise<DemotionEvent[]>;
    appendKeyRotation(entry: KeyRotationEntry): Promise<void>;
    getKeyRotations(publicKey: string): Promise<KeyRotationEntry[]>;
    checkAndStoreNonce(requestId: string, ttlSeconds: number): Promise<boolean>;
}
export interface StorageBackend extends StorageOperations {
    /** Initialize the backend (create tables, run migrations, etc) */
    initialize(): Promise<void>;
    /** Clean shutdown */
    close(): Promise<void>;
    /**
     * Run multiple operations in an atomic ACID transaction.
     * If any operation throws, ALL operations roll back.
     * The callback receives a transactional StorageOperations object.
     * CRITICAL: Use tx methods inside the callback, not the outer backend.
     */
    transaction<T>(fn: (tx: StorageOperations) => Promise<T>): Promise<T>;
    /**
     * Verify integrity of persisted state on startup.
     * Checks: receipt chain hashes, checkpoint sequence monotonicity,
     * delegation/revocation consistency, schema version.
     * Gateway should enter read-only mode if this returns errors.
     */
    verifyIntegrity(): Promise<IntegrityReport>;
    /**
     * Rebuild derived state (reputation, spend totals) from event log.
     * Called when cache and events disagree, or after recovery.
     */
    rebuildDerivedState(): Promise<void>;
    /** Prune expired replay nonces and spend reservations */
    pruneExpired(): Promise<{
        nonces: number;
        reservations: number;
    }>;
    /** Generate and store a new checkpoint. Returns the checkpoint. */
    createCheckpoint(gatewayId: string, gatewayPrivateKey: string): Promise<GatewayCheckpoint>;
    /** Get the latest checkpoint (for rollback detection on startup) */
    getLatestCheckpoint(): Promise<GatewayCheckpoint | null>;
    /** Register a callback for external checkpoint anchoring.
     *  Called after every createCheckpoint with (hash, sequence).
     *  Default: noop. In production: log, webhook, email, etc.
     *  The system cannot prove its own temporal integrity from within. */
    onCheckpoint(callback: CheckpointCallback): void;
    /** Export receipts as a signed, self-contained verifiable bundle */
    exportReceipts(filter: ReceiptFilter): Promise<{
        receipts: ActionReceipt[];
        chainValid: boolean;
    }>;
}
//# sourceMappingURL=types.d.ts.map