import { Transport } from '../core/transport'; export interface EthereumTransactionRequest { to?: string; from?: string; value?: string; data?: string; chainId?: string | number; gas?: string; gasPrice?: string; maxFeePerGas?: string; maxPriorityFeePerGas?: string; nonce?: string; } export interface ApnaEthereum { request(method: string, params?: unknown[]): Promise; getAddress(): Promise; signMessage(message: string): Promise; signTypedData(data: unknown): Promise; sendTransaction(tx: EthereumTransactionRequest): Promise; } export interface EthereumProtocolOptions { transport: () => Transport; isCapabilitySupported?: (capability: string) => boolean; } /** Create the low-level Ethereum protocol module. */ export function createEthereumProtocol( options: EthereumProtocolOptions ): ApnaEthereum { const call = (capability: string, args: unknown[]): Promise => options.isCapabilitySupported?.(capability) === false ? Promise.reject(new Error('ethereum not supported by this host')) : options.transport().call(capability, args); return { request: (method: string, params: unknown[] = []) => call('ethereum.request', [method, params]) as Promise, getAddress: () => call('ethereum.getAddress', []) as Promise, signMessage: (message: string) => call('ethereum.signMessage', [message]) as Promise, signTypedData: (data: unknown) => call('ethereum.signTypedData', [data]) as Promise, sendTransaction: (tx: EthereumTransactionRequest) => call('ethereum.sendTransaction', [tx]) as Promise, }; }