import { type DataRef, type DaSink, type DaSource } from "./da.js";
import { type ToplocActivationCommitment } from "./toploc.js";
import { type Hash } from "./transcript.js";
/** Which turns get TOPLOC DA publication. */
export type ToplocSamplePolicy = {
    mode: "all";
} | {
    mode: "every_n";
    n: number;
} | {
    mode: "none";
};
/** Default: publish every turn that captured lanes (when TOPLOC is configured). */
export declare const DEFAULT_TOPLOC_SAMPLE_POLICY: ToplocSamplePolicy;
/** Publish strategy for cost control. */
export type ToplocPublishMode = 
/** One ephemeral blob per selected turn. */
"per_turn"
/** Single batch blob (root + ordered commitments) for all selected turns. */
 | "batch";
export declare const TOPLOC_BATCH_MAGIC: Uint8Array<ArrayBuffer>;
/** Per-turn binding inside session evidence. */
export interface ToplocActivationBinding {
    channelId: Hash;
    turnIndex: number;
    /** Running transcript root after this turn (checkpoint bind). */
    checkpointRoot: Hash;
    modelHash: Hash;
    /** Model precision committed at open_channel. */
    precision: number;
    layerIndex: number;
    seed: Hash;
    /** SHA-256 of canonical TOPLOC2 bytes (`activation_hash` for attestations). */
    activationHash: Hash;
    /** Neutral-validator DA reference (Ephemeral). */
    dataRef: DataRef;
    /**
     * When published as a batch, index of this commitment inside the batch blob.
     * Absent for per-turn publishes.
     */
    batchIndex?: number;
}
/** Full session evidence package for TOPLOC (off-chain; DA-retrievable). */
export interface ToplocSessionEvidence {
    channelId: Hash;
    modelHash: Hash;
    precision: number;
    samplePolicy: ToplocSamplePolicy;
    publishMode: ToplocPublishMode;
    /** Transcript DA ref when known (session bind). */
    transcriptRef: DataRef | null;
    /** Last co-signed / host checkpoint root covering published turns. */
    checkpointRoot: Hash;
    activations: ToplocActivationBinding[];
    /**
     * When `publishMode === "batch"`, the single batch DataRef (also on each binding).
     */
    batchRef: DataRef | null;
    /** blake2_256 over ordered activation hashes (batch root / manifest commit). */
    activationsRoot: Hash;
}
/** Host-side counters for publish path observability. */
export interface ToplocPublishMetricsSnapshot {
    published: number;
    retries: number;
    failures: number;
    idempotentHits: number;
    pruned: number;
    batches: number;
}
/** Host-side counters for publish path observability. */
export declare class ToplocPublishMetrics {
    published: number;
    retries: number;
    failures: number;
    idempotentHits: number;
    pruned: number;
    batches: number;
    snapshot(): ToplocPublishMetricsSnapshot;
}
/** Fail-closed settlement outcomes for required TOPLOC evidence (D-0430-shaped). */
export declare enum ToplocEvidenceSettlementAction {
    /** Required evidence present and retrievable — settlement may proceed. */
    Accept = "Accept",
    /** Temporary DA unavailability — extend challenge/response window once/capped. */
    ExtendWindow = "ExtendWindow",
    /**
     * Required evidence missing, withheld, expired, or unrecoverable.
     * Refund agent escrow; do **not** pay miner; do **not** fraud-slash
     * (cannot prove fraud without the bytes).
     */
    RefundNoSlash = "RefundNoSlash",
    /**
     * Temporary unavailability after max extensions — freeze payout until
     * operator/governance recovery (never silent accept).
     */
    Freeze = "Freeze"
}
export type ToplocDaAvailability = "available" | "unavailable" | "unrecoverable" | "missing";
/**
 * Decide settlement action for TOPLOC evidence. Fail closed: never Accept when
 * required evidence is incomplete or unrecoverable.
 */
export declare function evaluateToplocEvidenceSettlement(args: {
    /** Session configured TOPLOC / Soft-tier path requiring sampled commits. */
    required: boolean;
    /** Turn indices the sample policy selected. */
    selectedTurns: readonly number[];
    /** Turn indices with a published DataRef. */
    publishedTurns: readonly number[];
    /** Neutral-DA status for the evidence blob(s). */
    daStatus: ToplocDaAvailability;
    extensionsUsed?: number;
    maxExtensions?: number;
}): ToplocEvidenceSettlementAction;
/** Whether `turnIndex` is selected by the sample policy. */
export declare function isToplocTurnSelected(turnIndex: number, policy: ToplocSamplePolicy): boolean;
/** Ordered activation-hash root for batch/manifest commitment. */
export declare function activationsRoot(activationHashes: readonly Hash[]): Hash;
/**
 * Encode a batch of canonical TOPLOC2 commitments for a single ephemeral DA
 * publish. Layout: `TOPBAT1\0 || channelId || count || (turn_index || len || bytes)*`.
 */
export declare function encodeToplocActivationBatch(channelId: Hash, items: ReadonlyArray<{
    turnIndex: number;
    commitmentBytes: Uint8Array;
}>): Uint8Array;
export interface DecodedToplocBatchItem {
    turnIndex: number;
    commitmentBytes: Uint8Array;
}
/** Parse a TOPLOC batch blob; null on malformed input. */
export declare function decodeToplocActivationBatch(bytes: Uint8Array): {
    channelId: Hash;
    items: DecodedToplocBatchItem[];
} | null;
/**
 * Validator path: fetch canonical bytes from neutral DA and recompute the
 * activation hash. Independent of miner HTTP.
 */
export declare function fetchAndVerifyToplocActivation(da: DaSource, dataRef: DataRef, expected?: {
    activationHash?: Hash;
    commitment?: ToplocActivationCommitment;
}): Promise<{
    bytes: Uint8Array;
    activationHash: Hash;
}>;
/**
 * Fetch a batch blob and verify one turn's commitment hash against evidence.
 */
export declare function fetchAndVerifyToplocBatchTurn(da: DaSource, batchRef: DataRef, turnIndex: number, expectedActivationHash: Hash): Promise<{
    bytes: Uint8Array;
    activationHash: Hash;
}>;
/**
 * Best-effort DA availability probe. A validator DA sink also implements the
 * retrieval side ({@link DaSource}); use it (cheap `has` first, else `fetch`) to
 * confirm a blob is still present. When availability cannot be confirmed, return
 * false so callers re-publish rather than trust a possibly-stale ref.
 */
export declare function daBlobAvailable(da: DaSink, commitment: Hash): Promise<boolean>;
/**
 * Whether an existing DataRef may be reused instead of re-publishing. Content
 * addressing is necessary but NOT sufficient: the blob may have expired or been
 * dropped from DA while the host still holds the binding, so hash equality alone
 * would return a stale ref validators cannot fetch. Reuse only when the
 * commitment matches AND the blob is confirmed still retrievable; otherwise
 * re-publish (fail safe toward availability of required evidence).
 */
export declare function daRefReusable(da: DaSink, ref: DataRef, bytes: Uint8Array): Promise<boolean>;
/**
 * Publish with retries. Idempotent when `existing` already matches the bytes'
 * content commitment in the sink's address space (caller tracks turn→ref).
 */
export declare function publishEphemeralWithRetry(da: DaSink, bytes: Uint8Array, opts?: {
    maxRetries?: number;
    metrics?: ToplocPublishMetrics;
    existing?: DataRef | null;
    /** Return true when `existing` still covers these bytes (caller-defined). */
    sameAsExisting?: (ref: DataRef, bytes: Uint8Array) => boolean | Promise<boolean>;
}): Promise<DataRef>;
/** Hex key for Maps keyed by turn or commitment. */
export declare function turnKey(turnIndex: number): string;
export declare function commitmentKey(c: Hash): string;
//# sourceMappingURL=toploc-evidence.d.ts.map