/**
 * Blockchain Anchoring Module
 *
 * Provides optional blockchain anchoring for proofs to create
 * tamper-evident timestamps on public ledgers.
 *
 * @packageDocumentation
 */
import type { ID } from '../../common/types.js';
import type { Database } from '../../common/db.js';
/**
 * Proof data prepared for blockchain anchoring
 */
export interface ProofToAnchor {
    /** Proof ID */
    id: ID;
    /** Proof hash to anchor */
    hash: string;
    /** Timestamp of proof creation */
    timestamp: Date;
    /** Tenant ID */
    tenantId?: string;
    /** Chain position in batch */
    chainPosition?: number;
    /** Optional metadata */
    metadata?: Record<string, unknown>;
}
/**
 * Result of anchoring a single proof
 */
export interface ProofAnchorResult {
    /** Proof ID that was anchored */
    proofId: ID;
    /** Whether anchoring succeeded */
    success: boolean;
    /** Transaction hash on the blockchain */
    txHash?: string;
    /** Block number where anchor was included */
    blockNumber?: number;
    /** Chain identifier (e.g., 'ethereum-mainnet', 'polygon') */
    chainId?: string;
    /** Error message if failed */
    error?: string;
    /** Timestamp of anchoring */
    anchoredAt?: Date;
}
/**
 * Result of anchoring a batch of proofs
 */
export interface BatchAnchorResult {
    /** Total proofs in batch */
    total: number;
    /** Successfully anchored count */
    succeeded: number;
    /** Failed count */
    failed: number;
    /** Individual results */
    results: ProofAnchorResult[];
    /** Merkle root of the batch (if batched) */
    batchRoot?: string;
    /** Transaction hash for batch anchor */
    batchTxHash?: string;
}
/**
 * Configuration for chain anchor service
 */
export interface ChainAnchorConfig {
    /** Default batch size for Merkle tree anchoring */
    defaultBatchSize?: number;
    /** Default batch timeout in ms */
    defaultBatchTimeoutMs?: number;
    /** Enable agent anchor (record agent in proofs) */
    enableAgentAnchor?: boolean;
    /** Enable anchoring */
    enabled?: boolean;
    /** Chain to use (e.g., 'ethereum', 'polygon', 'arbitrum') */
    chain?: string;
    /** RPC endpoint URL */
    rpcUrl?: string;
    /** Contract address for anchoring */
    contractAddress?: string;
}
/**
 * Chain anchor statistics
 */
export interface ChainAnchorStats {
    /** Total proofs anchored */
    totalAnchored: number;
    /** Total batches processed */
    totalBatches: number;
    /** Pending proofs */
    pendingCount: number;
    /** Last anchor timestamp */
    lastAnchorAt?: Date;
    /** Chain ID */
    chainId?: string;
}
/**
 * Service for anchoring proofs to blockchain
 *
 * Supports multiple chains and batching via Merkle trees for efficiency.
 *
 * Architecture layers:
 *  1. Local proof layer (current): In-memory Map + optional database persistence.
 *     All anchoring operations store proofs locally with deterministic anchor IDs,
 *     Merkle tree batching, and full verification capabilities.
 *  2. L2 blockchain layer (future): Polygon / Arbitrum on-chain anchoring.
 *     When rpcUrl and contractAddress are configured, Merkle roots will be
 *     submitted to an on-chain anchor contract for tamper-evident timestamping.
 *
 * // ---- Future Polygon L2 Integration Architecture ----
 * // When config.rpcUrl and config.contractAddress are set:
 * //   1. anchorProof / anchorBatch computes the Merkle root as it does today
 * //   2. A ProofAnchorContract adapter calls:
 * //        contract.anchorRoot(merkleRoot, leafCount, metadata)
 * //   3. The tx receipt provides txHash and blockNumber for ProofAnchorResult
 * //   4. Verification calls contract.verifyRoot(merkleRoot) to confirm on-chain
 * //   5. The in-memory store continues to hold Merkle paths for local verification
 * // ---------------------------------------------------
 */
export declare class ChainAnchorService {
    private config;
    private db?;
    private pendingProofs;
    private stats;
    /**
     * In-memory anchor store keyed by proofId.
     * Serves as the primary local proof layer. In production this would be
     * backed by the database; the in-memory Map provides zero-dependency
     * functionality for development and testing.
     */
    private anchorStore;
    /**
     * Auto-incrementing simulated block number for the local anchor layer.
     * Each anchorProof call increments this to simulate blockchain progression.
     */
    private simulatedBlockNumber;
    constructor(config: ChainAnchorConfig);
    /**
     * Initialize with database connection
     */
    initialize(db: Database): void;
    /**
     * Check if anchoring is enabled
     */
    isEnabled(): boolean;
    /**
     * Add proofs to the current batch
     */
    addProofsToBatch(proofs: ProofToAnchor[]): Promise<void>;
    /**
     * Process pending batches
     */
    processPendingBatches(): Promise<BatchAnchorResult[]>;
    /**
     * Anchor a single proof to blockchain
     *
     * Local proof layer implementation:
     *  - Generates a deterministic anchor ID (txHash) from the proof hash using SHA-256
     *  - Assigns an incrementing simulated block number
     *  - Stores the anchor record in the in-memory store for later lookup and verification
     *
     * When a real blockchain backend is configured (rpcUrl + contractAddress),
     * this method would submit the proof hash to the on-chain anchor contract
     * and use the actual txHash and blockNumber from the receipt.
     */
    anchorProof(proof: ProofToAnchor): Promise<ProofAnchorResult>;
    /**
     * Anchor a batch of proofs using Merkle tree
     *
     * Implementation:
     *  1. Convert each proof into a Merkle leaf hash (sha256 of proofId:proofHash)
     *  2. Build a binary Merkle tree from all leaf hashes
     *  3. Generate individual Merkle proofs (inclusion paths) for every leaf
     *  4. Compute a deterministic batch txHash from the Merkle root
     *  5. Store each proof's anchor record with its Merkle path for later verification
     *
     * The Merkle root is the single value that would be submitted on-chain in
     * a production L2 deployment, making batch anchoring O(1) on-chain cost
     * regardless of the number of proofs in the batch.
     */
    anchorBatch(proofs: ProofToAnchor[]): Promise<BatchAnchorResult>;
    /**
     * Get anchor status for a specific proof
     *
     * Looks up the proof anchor record from the in-memory store.
     * Returns the full ProofAnchorResult including txHash, blockNumber,
     * chainId, and anchoring timestamp, or null if the proof has not
     * been anchored.
     *
     * In a production deployment with database persistence, this would
     * query the anchor records table instead of the in-memory Map.
     */
    getProofAnchor(proofId: ID): Promise<ProofAnchorResult | null>;
    /**
     * Verify a proof is properly anchored
     *
     * Verification steps:
     *  1. Look up the anchor record from the in-memory store
     *  2. Verify the provided hash matches the stored proof hash
     *  3. If the proof was part of a Merkle batch, verify the Merkle inclusion path
     *     by recomputing the leaf hash and walking the path up to the stored root
     *  4. Return a verification result with details
     *
     * In a production L2 deployment, step 3 would additionally verify
     * that the Merkle root is anchored on-chain by querying the anchor contract.
     */
    verifyProofAnchored(proofId: ID, hash: string): Promise<{
        valid: boolean;
        error?: string;
        details?: Record<string, unknown>;
    }>;
    /**
     * Get statistics
     */
    getStats(): ChainAnchorStats;
    /**
     * Shutdown the service
     */
    shutdown(): Promise<void>;
}
/**
 * Scheduler for batching and periodically anchoring proofs
 */
export declare class ChainAnchorScheduler {
    private service;
    private db?;
    private intervalId?;
    private batchSize;
    private intervalMs;
    constructor(service: ChainAnchorService, options?: {
        batchSize?: number;
        intervalMs?: number;
    });
    /**
     * Initialize with database connection
     */
    initialize(db: Database): void;
    /**
     * Start the scheduler
     */
    start(): void;
    /**
     * Stop the scheduler
     */
    stop(): void;
    /**
     * Queue a proof for anchoring
     */
    queue(proof: ProofToAnchor): Promise<void>;
    /**
     * Flush pending proofs to blockchain
     */
    flush(): Promise<BatchAnchorResult[]>;
    /**
     * Get count of pending proofs
     */
    getPendingCount(): number;
}
/**
 * Create a chain anchor service
 */
export declare function createChainAnchorService(config: ChainAnchorConfig): ChainAnchorService;
/**
 * Create a chain anchor scheduler
 */
export declare function createChainAnchorScheduler(service: ChainAnchorService, options?: {
    batchSize?: number;
    intervalMs?: number;
}): ChainAnchorScheduler;
//# sourceMappingURL=index.d.ts.map