/** AuditReceiptService — persistent, chained, tamper-evident audit receipts. */
import type { OpOutcome, TickReceipt } from '../../types/TickReceipt.ts';
import type CryptoPort from '../../../ports/CryptoPort.ts';
import type CodecPort from '../../../ports/CodecPort.ts';
import type LoggerPort from '../../../ports/LoggerPort.ts';
import type RefPort from '../../../ports/RefPort.ts';
import type BlobPort from '../../../ports/BlobPort.ts';
import type TreePort from '../../../ports/TreePort.ts';
import type CommitPort from '../../../ports/CommitPort.ts';
/**
 * Domain-separated prefix for opsDigest computation.
 * The trailing \0 is a literal null byte (U+0000) acting as an
 * unambiguous delimiter between the prefix and the JSON payload.
 */
export declare const OPS_DIGEST_PREFIX = "git-warp:opsDigest:v1\0";
/** JSON.stringify replacer sorting object keys lexicographically (spec Section 5.2). */
export declare function sortedReplacer(_key: string, value: unknown): unknown;
/** Canonical JSON string of an ops array (spec Section 5.2). */
export declare function canonicalOpsJson(ops: ReadonlyArray<Readonly<OpOutcome>>): string;
/** Computes domain-separated SHA-256 opsDigest (spec Section 5.3). */
export declare function computeOpsDigest(ops: ReadonlyArray<Readonly<OpOutcome>>, crypto: CryptoPort): Promise<string>;
export interface AuditReceiptFields {
    version: number;
    graphName: string;
    writerId: string;
    dataCommit: string;
    tickStart: number;
    tickEnd: number;
    opsDigest: string;
    prevAuditCommit: string;
    timestamp: number;
}
/** Immutable audit receipt value object. Frozen, keys in sorted order for deterministic CBOR. */
export declare class AuditReceipt {
    readonly dataCommit: string;
    readonly graphName: string;
    readonly opsDigest: string;
    readonly prevAuditCommit: string;
    readonly tickEnd: number;
    readonly tickStart: number;
    readonly timestamp: number;
    readonly version: number;
    readonly writerId: string;
    /** Creates an immutable audit receipt from validated fields. */
    constructor({ version, graphName, writerId, dataCommit, tickStart, tickEnd, opsDigest, prevAuditCommit, timestamp }: AuditReceiptFields);
}
/**
 * Validates and builds a frozen receipt record with keys in sorted order.
 *
 * @throws {AuditError} If any field is invalid (code: E_AUDIT_INVALID)
 */
export declare function buildReceiptRecord(fields: AuditReceiptFields): AuditReceipt;
/** Combined persistence interface required by AuditReceiptService. */
export type AuditPersistence = RefPort & BlobPort & TreePort & CommitPort;
export interface AuditReceiptServiceOptions {
    persistence: AuditPersistence;
    graphName: string;
    writerId: string;
    codec: CodecPort;
    crypto: CryptoPort;
    logger?: LoggerPort;
}
export interface AuditStats {
    committed: number;
    skipped: number;
    failed: number;
    degraded: boolean;
}
/**
 * AuditReceiptService manages the audit receipt chain for a single writer.
 *
 * ## Lifecycle
 * 1. Construct with dependencies
 * 2. Call `init()` to read the current audit ref tip
 * 3. Call `commit(tickReceipt)` after each data commit succeeds
 *
 * ## Error handling
 * All errors are caught, logged with structured codes, and never propagated.
 * The data commit has already succeeded — audit failures create gaps that
 * are detectable by M4 verification.
 */
export declare class AuditReceiptService {
    private readonly _persistence;
    private readonly _graphName;
    private readonly _writerId;
    private readonly _codec;
    private readonly _crypto;
    private readonly _logger;
    private readonly _auditRef;
    /** Previous audit commit SHA (null = genesis) */
    private _prevAuditCommit;
    /** Expected old ref value for CAS (null = ref doesn't exist) */
    private _expectedOldRef;
    /** If true, service is degraded — skip all commits */
    private _degraded;
    /** If true, currently retrying — prevents recursive retry */
    private _retrying;
    private _committed;
    private _skipped;
    private _failed;
    /** Constructs an AuditReceiptService for the given writer audit chain. */
    constructor({ persistence, graphName, writerId, codec, crypto, logger }: AuditReceiptServiceOptions);
    /**
     * Initializes the service by reading the current audit ref tip.
     * Must be called before `commit()`.
     */
    init(): Promise<void>;
    /**
     * Creates an audit commit for the given tick receipt.
     *
     * DESIGN NOTE: Data commit has already succeeded at this point.
     * If audit commit fails, the data is persisted but the audit chain
     * has a gap. This is acceptable by design in M3 — gaps are detected
     * by M4 verification coverage rules (receipt count vs data commit count).
     *
     * @returns The audit commit SHA, or null on failure
     */
    commit(tickReceipt: TickReceipt): Promise<string | null>;
    /** Returns audit stats for coverage probing. */
    getStats(): AuditStats;
    /**
     * Inner commit logic. Throws on failure (caught by `commit()`).
     * @private
     */
    private _commitInner;
    /**
     * Retry-once after CAS conflict. Reads fresh tip, rebuilds receipt, retries.
     * @private
     */
    private _retryAfterCasConflict;
}
