@appliedblockchain/silentdatarollup-ethers-provider
Version:
Ethers.js provider for Silent Data [Rollup]
106 lines (100 loc) • 4.52 kB
TypeScript
import { Signer, JsonRpcApiProviderOptions, Filter, JsonRpcProvider, JsonRpcPayload, JsonRpcResult, FetchRequest, Log, FilterByBlockHash, LogDescription, Interface } from 'ethers';
import { BaseConfig, NetworkName } from '@appliedblockchain/silentdatarollup-core';
declare const DEBUG_NAMESPACE = "silentdata:ethers-provider";
interface SilentDataRollupProviderConfig extends BaseConfig {
rpcUrl: string;
network?: NetworkName;
chainId?: number;
privateKey?: string;
signer?: Signer;
options?: JsonRpcApiProviderOptions;
}
/**
* Extended filter type that includes a special flag for private events
* This flag is used to identify when a call to eth_getLogs originated from
* the getAllLogs method, so we can add authentication headers
*/
interface PrivateEventsFilter extends Filter {
/**
* Internal flag to identify requests that should include auth headers
* Set automatically by getAllLogs method
*/
_isPrivateEvent?: boolean;
/**
* Optional event signature for filtering private events by type
* Example: "Transfer(address,address,uint256)"
* Will be converted to a hash and used for topic filtering
*/
eventSignature?: string;
}
declare class SilentDataRollupProvider extends JsonRpcProvider {
private config;
signer: Signer;
private baseProvider;
constructor(config: SilentDataRollupProviderConfig);
_send(payload: JsonRpcPayload | Array<JsonRpcPayload>): Promise<Array<JsonRpcResult>>;
static getRequest({ rpcUrl }: {
rpcUrl: string;
}): FetchRequest;
clone(): SilentDataRollupProvider;
/**
* Helper method to configure a filter for private events
* @param filter - The original filter
* @param forcePrivateOnly - Whether to force filtering for only PrivateEvents
* @returns The configured filter with proper topics
*/
private configurePrivateEventsFilter;
/**
* Gets logs for private events, including authentication headers
* @param filter - The filter parameters for logs
* @returns Array of logs matching the filter
*/
getAllLogs(filter?: PrivateEventsFilter): Promise<Array<Log>>;
/**
* Gets only private events (PrivateEvent logs), including authentication headers
* @param filter - The filter parameters for logs
* @returns Array of logs matching the filter, containing only PrivateEvent logs
*/
getPrivateLogs(filter?: PrivateEventsFilter): Promise<Log[]>;
/**
* Override of ethers' getLogs method that preserves our custom _isPrivateEvent property
*
* IMPORTANT: This method mimics the behavior of ethers' original getLogs implementation
* but adds a crucial step to preserve the _isPrivateEvent flag. We need this because:
*
* 1. Ethers' _getFilter method sanitizes filter objects, removing any non-standard properties
* 2. Our _isPrivateEvent flag would be stripped by this sanitization
* 3. We need the flag to reach the _send method to trigger the addition of auth headers
*
* The approach here is to run the normal filter processing, then re-attach our flag as a
* non-enumerable property to avoid JSON serialization issues. This allows the flag to
* survive until _send where we check for it to determine if auth headers are needed.
*
* @param _filter - The filter with our potential _isPrivateEvent property
* @returns Array of logs matching the filter
*/
getLogs(_filter: PrivateEventsFilter | FilterByBlockHash): Promise<Log[]>;
}
/**
* Extended LogDescription type that includes private event details
*/
interface SDLogDescription extends LogDescription {
/**
* Only present for PrivateEvents - contains the decoded inner log
* If decoding failed, this will be null
*/
innerLog?: LogDescription | null;
}
/**
* Extends ethers Interface to provide support for decoding PrivateEvent logs
* Make sure to include the PrivateEvent signature in your ABI when using this class
*/
declare class SDInterface extends Interface {
/**
* Extends the parseLog method to handle PrivateEvent logs
* @param log - The log to parse
* @returns The parsed log description with additional private event details if applicable
*/
parseLog(log: Parameters<Interface['parseLog']>[0]): SDLogDescription | null;
}
export { DEBUG_NAMESPACE, type PrivateEventsFilter, SDInterface, type SDLogDescription, SilentDataRollupProvider, type SilentDataRollupProviderConfig };