/** * Merkle Batch Signing — 1000x TPS Multiplier * * Build Merkle trees from transaction hashes, generate proofs, and verify * inclusion locally before submitting on-chain via BatchVerifier.sol. * * Uses OpenZeppelin-compatible commutative keccak256 with sorted pairs, * ensuring proofs generated here are directly verifiable by the on-chain * MerkleProof.verify() function. * * @example * ```typescript * import { buildMerkleTree, verifyMerkleProof } from '@sequence0/sdk'; * * const txHashes = ['0xabc...', '0xdef...', ...]; // up to 4096 tx hashes * const { root, proofs } = buildMerkleTree(txHashes); * * // Verify a single leaf locally * const proof = proofs.get(0)!; * const valid = verifyMerkleProof(root, txHashes[0], proof); * ``` */ export interface MerkleBatchConfig { /** Maximum transactions per batch (default: 1024) */ maxBatchSize: number; /** Auto-flush interval in ms when using MerkleBatchCollector (default: 500) */ flushIntervalMs: number; } export interface MerkleTreeResult { /** Merkle root hash (0x-prefixed, 32 bytes) */ root: string; /** Leaf index => array of sibling hashes forming the proof */ proofs: Map; /** Number of original (non-padded) leaves */ leafCount: number; } export interface BatchResult { /** Unique batch identifier */ batchId: string; /** Merkle root of the transaction tree */ merkleRoot: string; /** ECDSA signature over (batchId, merkleRoot, batchSize, chainId) */ signature: string; /** Number of transactions in the batch */ batchSize: number; /** Map from transaction hash to its proof and leaf index */ proofs: Map; } /** Default configuration */ export declare const DEFAULT_BATCH_CONFIG: MerkleBatchConfig; /** * Build a Merkle tree from transaction hashes. * * Uses OpenZeppelin-compatible commutative keccak256: each parent node is * computed by sorting the two children lexicographically then hashing them * concatenated. This matches the on-chain MerkleProof.verify() behavior. * * @param leaves Array of 0x-prefixed 32-byte hex hashes * @returns Root hash and proofs for each original leaf * @throws If leaves array is empty */ export declare function buildMerkleTree(leaves: string[]): MerkleTreeResult; /** * Verify a Merkle proof locally (before submitting on-chain). * * Replicates the exact logic of OpenZeppelin's MerkleProof.verify(): * at each level, sort the pair lexicographically then hash. * * @param root Expected Merkle root (0x-prefixed, 32 bytes) * @param leaf The leaf hash to verify (0x-prefixed, 32 bytes) * @param proof Array of sibling hashes from leaf to root * @returns true if the proof is valid */ export declare function verifyMerkleProof(root: string, leaf: string, proof: string[]): boolean; /** * Compute the message hash that must be signed for batch registration. * * This matches the on-chain reconstruction in BatchVerifier.registerBatch(): * keccak256(abi.encodePacked(batchId, merkleRoot, batchSize, chainId)) * * @param batchId Unique batch identifier (bytes32) * @param merkleRoot Merkle root hash (bytes32) * @param batchSize Number of transactions in the batch * @param chainId Target chain ID * @returns The raw message hash (0x-prefixed, 32 bytes) */ export declare function computeBatchMessage(batchId: string, merkleRoot: string, batchSize: number, chainId: number): string; /** * Generate a unique batch ID from a set of transaction hashes and a nonce. * * @param txHashes Array of transaction hashes in the batch * @param nonce Unique nonce to prevent collisions (e.g., timestamp or counter) * @returns Deterministic batch ID (0x-prefixed, 32 bytes) */ export declare function generateBatchId(txHashes: string[], nonce: number): string; //# sourceMappingURL=merkle-batch.d.ts.map