export type JsonRpcId = string | number; export type JsonRpcPayload = { id: JsonRpcId; jsonrpc: "2.0"; method: string; params: unknown[] | Record; }; export type JsonRpcErrorLike = { code: number; message: string; data?: Data; }; export class JsonRpcError extends Error { readonly code: number; readonly data?: Data; constructor(error: JsonRpcErrorLike) { super(error.message); this.name = "JsonRpcError"; this.code = error.code; this.data = error.data; } } export type JsonRpcResponse = { id: JsonRpcId; jsonrpc: "2.0"; } & ( | { result: Result; error?: never } | { result?: never; error: JsonRpcErrorLike } ); export type JsonRpcTransportRequestOptions = { /** Cancels this individual request without disposing the transport. */ signal?: AbortSignal; /** Overrides the transport's default timeout for this request. */ timeout?: number; }; export interface JsonRpcTransport { /** * Sends a JSON-RPC request to the server. * * @param payload - The JSON-RPC payload to send. * @returns The JSON-RPC response. */ request( payload: JsonRpcPayload, options?: JsonRpcTransportRequestOptions, ): Promise; }