/**
 * @file Dispute tooling (challenger + defender).
 * @module sdk/typescript/compute-channel/dispute
 *
 * Challenger fetches the transcript blob from validator DA, audits it against
 * the posted finalRoot, and pinpoints a fraudulent turn. Defender (miner)
 * rebuilds `respond_dispute` evidence and self-audits it before submitting.
 *
 * Multi-round bisection: open over n turns (power of two), miner opens midpoint
 * child roots, challenger picks the half with the fraud, until a single turn —
 * then the existing leaf check. Round bound = ⌈log₂ n⌉ (`DisputeBisection`).
 */
import { TranscriptBlob, type DaSource } from "./da.js";
import { type DisputeEvidence, type VerifiedTurn } from "./protocol.js";
import { type Hash } from "./transcript.js";
export declare enum FraudReason {
    BadEnclaveSignature = "BadEnclaveSignature",
    NotInCommittedRoot = "NotInCommittedRoot"
}
export interface Challenge {
    contestedTurn: number;
    reason: FraudReason;
}
/** Fetch + parse the transcript blob behind a settlement's DataRef. */
export declare function fetchTranscript(da: DaSource, commitment: Hash): Promise<TranscriptBlob>;
/**
 * Audit a transcript against the posted root + enclave key. Returns the first
 * fraudulent turn, or `null` if every turn is sound (honest settlement).
 */
export declare function audit(blob: TranscriptBlob, enclaveKey: Uint8Array, finalRoot: Hash): Challenge | null;
/** Build `respond_dispute` evidence for `contestedTurn`, or `null` if absent. */
export declare function buildEvidence(blob: TranscriptBlob, contestedTurn: number): DisputeEvidence | null;
/** Build the `verified_turns` proof bundle required by settle/force_settle. */
export declare function buildVerifiedTurns(blob: TranscriptBlob): VerifiedTurn[];
/**
 * Defender self-audit: build evidence and confirm it satisfies the on-chain
 * `respond_dispute` check before submitting. Honest miner ⇒ valid evidence;
 * fraudulent ⇒ `null` (and a slash on the response timeout).
 *
 * `posted` is the posted `force_settle` call: the settled `channelId`, read
 * from chain state, and its `verified_turns` bundle. An agent may post a root
 * for a prefix or sparse set that differs from the miner's current DA tree;
 * that call still carries the exact leaf and path needed to answer, so it is
 * the fallback when the local rebuild does not verify. The agent pins the DA
 * blob, so its channel ID is not trusted: a blob for another channel yields no
 * evidence, and the fallback leaf is rebuilt for `posted.channelId` (Rust
 * `prepare_response_with_fallback`).
 */
export declare function prepareResponse(blob: TranscriptBlob, enclaveKey: Uint8Array, finalRoot: Hash, contestedTurn: number, posted?: {
    channelId: Hash;
    turns: readonly VerifiedTurn[];
}): DisputeEvidence | null;
/** ⌈log₂ n⌉ — matches Lean `DisputeBisection.rounds` / on-chain `bisection_rounds`. */
export declare function bisectionRounds(n: number): number;
export declare function isPowerOfTwo(n: number): boolean;
/** Merkle root over a leaf slice (odd levels duplicate last). */
export declare function merklizeLeaves(leaves: Hash[]): Hash;
/** Leaf hashes of a transcript blob (same encoding as the chain accumulator). */
export declare function blobLeaves(blob: TranscriptBlob): Hash[];
/**
 * Midpoint child roots for interval `[lo, hi]`: left = merklize `[lo, mid]`,
 * right = merklize `[mid+1, hi]`. On-chain requires `hash(left‖right) === parent`
 * (power-of-two interval lengths).
 */
export declare function midpointChildren(leaves: Hash[], lo: number, hi: number): {
    left: Hash;
    right: Hash;
    mid: number;
};
/** Off-chain mirror of the multi-round dispute state machine. */
export interface BisectionState {
    lo: number;
    hi: number;
    parentRoot: Hash;
    rounds: number;
    /** Pending child roots after miner open; null while awaiting miner. */
    pendingLeft: Hash | null;
    pendingRight: Hash | null;
}
export declare function initBisection(nTurns: number, finalRoot: Hash): BisectionState;
/** Miner: build child roots for the active interval (self-check vs parent). */
export declare function prepareBisectionResponse(leaves: Hash[], state: BisectionState): {
    left: Hash;
    right: Hash;
} | null;
export declare function applyBisectionResponse(state: BisectionState, left: Hash, right: Hash): BisectionState;
/** Which half contains `target` (challenger strategy when the fraud turn is known). */
export declare function chooseHalfToward(target: number, lo: number, hi: number): boolean;
export declare function applyBisectionChallenge(state: BisectionState, chooseLeft: boolean, maxRounds: number): BisectionState;
/**
 * Honest multi-round client: walk midpoints toward `targetTurn`, then build leaf
 * evidence. Returns the number of midpoint rounds and the leaf evidence.
 * Honest miner always produces valid openings for every half. `posted` is the
 * settled turn set and trusted channel ID when the local DA blob has grown.
 */
export declare function playHonestBisection(blob: TranscriptBlob, enclaveKey: Uint8Array, finalRoot: Hash, targetTurn: number, maxRounds?: number, posted?: {
    channelId: Hash;
    turns: readonly VerifiedTurn[];
}): {
    rounds: number;
    evidence: DisputeEvidence;
};
//# sourceMappingURL=dispute.d.ts.map