import { RequestItem } from '@lit-protocol/types'; /** * @fileOverview * This file provides utility functions to process a batch of asynchronous requests * to Lit Protocol nodes in a functional style. It aggregates results from multiple * promises and determines overall success based on a minimum number of successful outcomes. */ /** * Represents the structure of the 'authSig' object within a request's data. * This is typically a session signature for a specific node. */ export interface RequestAuthSig { sig: string; derivedVia: string; signedMessage: string; address: string; algo: string; } /** * Represents an item in the 'nodeSet' array within a request's data. */ export interface NodeSetEntry { socketAddress: string; value: number; } /** * Represents a successful outcome from processing the batch of requests. * @template T The type of the value returned by a successful individual request. */ export interface BatchSuccessResult { success: true; values: T[]; } /** * Represents a failed outcome from processing the batch of requests. * The 'error' property can be any type, but structured error objects are recommended. */ export interface BatchErrorResult { success: false; error: any; } /** * Union type for the result of processing the batch of requests. * @template T The type of the value returned by a successful individual request. */ export type ProcessedBatchResult = BatchSuccessResult | BatchErrorResult; /** * Placeholder type for the expected successful response from a node for a signing operation. * This should be refined based on the actual response structure of `LitNodeApi.sendNodeRequest` * for PKP signing. */ export interface NodeResponse { signatureShare?: string; signature?: string; dataSigned?: string; rawPubKey?: string; [key: string]: any; } /** * Processes a batch of request items asynchronously and aggregates their results. * It implements an "early success" mechanism: if `minSuccessCount` successful responses * are received, it resolves immediately without waiting for all other requests to complete. * * @template M The type of the data payload within each `RequestItem`. * @template T The expected type of a successful response from a single request (defaults to `NodeResponse`). * @param requests An array of `RequestItem` objects to be processed. * @param batchRequestId A unique identifier for this batch of requests. * @param minSuccessCount The minimum number of successful responses required for the batch to be considered successful. * @returns A Promise that resolves to a `ProcessedBatchResult`, indicating either overall success with the collected values or failure with an error. */ export declare function dispatchRequests(requests: RequestItem[], batchRequestId: string, minSuccessCount: number): Promise>;