|
1 | 1 | import type { RpcMethod } from '.'; |
2 | 2 |
|
| 3 | +// Base types |
| 4 | +type HexString = `0x${string}`; |
| 5 | +type Address = `0x${string}`; |
| 6 | +type Hash32 = `0x${string}`; |
| 7 | +type BlockTag = 'earliest' | 'finalized' | 'safe' | 'latest' | 'pending'; |
| 8 | +type BlockNumberOrTag = HexString | BlockTag; |
| 9 | +type BlockNumberOrTagOrHash = HexString | BlockTag | Hash32; |
| 10 | + |
| 11 | +// Complex types for method parameters and responses |
| 12 | +interface AddEthereumChainParameter { |
| 13 | + chainId: HexString; |
| 14 | + chainName: string; |
| 15 | + nativeCurrency: { |
| 16 | + name?: string; |
| 17 | + symbol: string; |
| 18 | + decimals: number; |
| 19 | + }; |
| 20 | + rpcUrls: string[]; |
| 21 | + blockExplorerUrls?: string[]; |
| 22 | + iconUrls?: string[]; |
| 23 | +} |
| 24 | + |
| 25 | +interface TypedData { |
| 26 | + types: { |
| 27 | + EIP712Domain: Array<{ |
| 28 | + name: string; |
| 29 | + type: string; |
| 30 | + }>; |
| 31 | + [key: string]: Array<{ |
| 32 | + name: string; |
| 33 | + type: string; |
| 34 | + }>; |
| 35 | + }; |
| 36 | + primaryType: string; |
| 37 | + domain: Record<string, any>; |
| 38 | + message: Record<string, any>; |
| 39 | +} |
| 40 | + |
| 41 | +interface WatchAssetOptions { |
| 42 | + address: string; |
| 43 | + symbol?: string; |
| 44 | + decimals?: number; |
| 45 | + image?: string; |
| 46 | + tokenId?: string; |
| 47 | +} |
| 48 | + |
| 49 | +interface Call { |
| 50 | + to?: Address; |
| 51 | + data?: HexString; |
| 52 | + value?: HexString; |
| 53 | + capabilities?: Record<string, any>; |
| 54 | +} |
| 55 | + |
| 56 | +interface SendCallsParameter { |
| 57 | + version: string; |
| 58 | + id?: string; |
| 59 | + from: Address; |
| 60 | + chainId: HexString; |
| 61 | + atomicRequired: boolean; |
| 62 | + calls: Call[]; |
| 63 | + capabilities?: Record<string, any>; |
| 64 | +} |
| 65 | + |
| 66 | +interface BatchResult { |
| 67 | + id: string; |
| 68 | + capabilities?: Record<string, any>; |
| 69 | +} |
| 70 | + |
| 71 | +interface BatchStatus { |
| 72 | + version: string; |
| 73 | + id: string; |
| 74 | + chainId: HexString; |
| 75 | + status: number; |
| 76 | + atomic: boolean; |
| 77 | + receipts?: Array<{ |
| 78 | + logs: Array<{ |
| 79 | + address: Address; |
| 80 | + data: HexString; |
| 81 | + topics: HexString[]; |
| 82 | + }>; |
| 83 | + status: HexString; |
| 84 | + blockHash: Hash32; |
| 85 | + blockNumber: HexString; |
| 86 | + gasUsed: HexString; |
| 87 | + transactionHash: Hash32; |
| 88 | + [key: string]: any; |
| 89 | + }>; |
| 90 | + capabilities?: Record<string, any>; |
| 91 | +} |
| 92 | + |
| 93 | +interface Transaction { |
| 94 | + from: Address; |
| 95 | + to?: Address; |
| 96 | + gas?: HexString; |
| 97 | + gasPrice?: HexString; |
| 98 | + maxFeePerGas?: HexString; |
| 99 | + maxPriorityFeePerGas?: HexString; |
| 100 | + value?: HexString; |
| 101 | + data?: HexString; |
| 102 | + nonce?: HexString; |
| 103 | + accessList?: Array<{ |
| 104 | + address: Address; |
| 105 | + storageKeys: Hash32[]; |
| 106 | + }>; |
| 107 | + type?: HexString; |
| 108 | + chainId?: HexString; |
| 109 | +} |
| 110 | + |
| 111 | +interface Filter { |
| 112 | + fromBlock?: HexString; |
| 113 | + toBlock?: HexString; |
| 114 | + address?: Address | Address[]; |
| 115 | + topics?: Array<HexString | HexString[] | null>; |
| 116 | +} |
| 117 | + |
| 118 | +interface Log { |
| 119 | + removed?: boolean; |
| 120 | + logIndex?: HexString; |
| 121 | + transactionIndex?: HexString; |
| 122 | + transactionHash: Hash32; |
| 123 | + blockHash?: Hash32; |
| 124 | + blockNumber?: HexString; |
| 125 | + address: Address; |
| 126 | + data: HexString; |
| 127 | + topics: HexString[]; |
| 128 | +} |
| 129 | + |
| 130 | +interface Block { |
| 131 | + number: HexString; |
| 132 | + hash: Hash32; |
| 133 | + parentHash: Hash32; |
| 134 | + nonce: HexString; |
| 135 | + sha3Uncles: Hash32; |
| 136 | + logsBloom: HexString; |
| 137 | + transactionsRoot: Hash32; |
| 138 | + stateRoot: Hash32; |
| 139 | + receiptsRoot: Hash32; |
| 140 | + miner: Address; |
| 141 | + difficulty?: HexString; |
| 142 | + totalDifficulty?: HexString; |
| 143 | + extraData: HexString; |
| 144 | + size: HexString; |
| 145 | + gasLimit: HexString; |
| 146 | + gasUsed: HexString; |
| 147 | + timestamp: HexString; |
| 148 | + transactions: Hash32[] | TransactionInfo[]; |
| 149 | + uncles: Hash32[]; |
| 150 | + baseFeePerGas?: HexString; |
| 151 | + withdrawalsRoot?: Hash32; |
| 152 | + withdrawals?: Array<{ |
| 153 | + index: HexString; |
| 154 | + validatorIndex: HexString; |
| 155 | + address: Address; |
| 156 | + amount: HexString; |
| 157 | + }>; |
| 158 | + blobGasUsed?: HexString; |
| 159 | + excessBlobGas?: HexString; |
| 160 | + parentBeaconBlockRoot?: Hash32; |
| 161 | + mixHash?: Hash32; |
| 162 | +} |
| 163 | + |
| 164 | +interface TransactionInfo { |
| 165 | + blockHash: Hash32; |
| 166 | + blockNumber: HexString; |
| 167 | + from: Address; |
| 168 | + gas: HexString; |
| 169 | + gasPrice?: HexString; |
| 170 | + maxFeePerGas?: HexString; |
| 171 | + maxPriorityFeePerGas?: HexString; |
| 172 | + hash: Hash32; |
| 173 | + input: HexString; |
| 174 | + nonce: HexString; |
| 175 | + to?: Address; |
| 176 | + transactionIndex: HexString; |
| 177 | + value: HexString; |
| 178 | + type?: HexString; |
| 179 | + accessList?: Array<{ |
| 180 | + address: Address; |
| 181 | + storageKeys: Hash32[]; |
| 182 | + }>; |
| 183 | + chainId?: number; |
| 184 | + v?: HexString; |
| 185 | + r?: HexString; |
| 186 | + s?: HexString; |
| 187 | + yParity?: HexString; |
| 188 | +} |
| 189 | + |
| 190 | +interface TransactionReceipt { |
| 191 | + transactionHash: Hash32; |
| 192 | + transactionIndex: HexString; |
| 193 | + blockHash: Hash32; |
| 194 | + blockNumber: HexString; |
| 195 | + from: Address; |
| 196 | + to?: Address; |
| 197 | + cumulativeGasUsed: HexString; |
| 198 | + gasUsed: HexString; |
| 199 | + contractAddress?: Address; |
| 200 | + logs: Log[]; |
| 201 | + logsBloom: HexString; |
| 202 | + status?: HexString; |
| 203 | + effectiveGasPrice: HexString; |
| 204 | + type?: HexString; |
| 205 | + blobGasUsed?: HexString; |
| 206 | + blobGasPrice?: HexString; |
| 207 | +} |
| 208 | + |
| 209 | +interface FeeHistory { |
| 210 | + oldestBlock: HexString; |
| 211 | + baseFeePerGas: HexString[]; |
| 212 | + baseFeePerBlobGas?: HexString[]; |
| 213 | + gasUsedRatio: number[]; |
| 214 | + blobGasUsedRatio?: number[]; |
| 215 | + reward?: HexString[][]; |
| 216 | +} |
| 217 | + |
| 218 | +interface AccountProof { |
| 219 | + address: Address; |
| 220 | + accountProof: HexString[]; |
| 221 | + balance: HexString; |
| 222 | + codeHash: Hash32; |
| 223 | + nonce: HexString; |
| 224 | + storageHash: Hash32; |
| 225 | + storageProof: Array<{ |
| 226 | + key: HexString; |
| 227 | + value: HexString; |
| 228 | + proof: HexString[]; |
| 229 | + }>; |
| 230 | +} |
| 231 | + |
| 232 | +type SyncingStatus = |
| 233 | + | boolean |
| 234 | + | { |
| 235 | + startingBlock: HexString; |
| 236 | + currentBlock: HexString; |
| 237 | + highestBlock: HexString; |
| 238 | + }; |
| 239 | + |
3 | 240 | export type Eip155Rpc = { |
4 | 241 | methods: { |
5 | | - eth_sendTransaction: RpcMethod<{ to: string; value?: string; data?: string }, string>; |
6 | | - eth_call: RpcMethod<{ to: string; data?: string }, string>; |
7 | | - eth_getBalance: RpcMethod<{ address: string; blockNumber: string }, string>; |
| 242 | + // Wallet methods |
| 243 | + wallet_addEthereumChain: RpcMethod<[AddEthereumChainParameter], null>; |
| 244 | + wallet_watchAsset: RpcMethod<{ type: string; options: WatchAssetOptions }, boolean>; |
| 245 | + wallet_scanQRCode: RpcMethod<[string?], string>; |
| 246 | + wallet_sendCalls: RpcMethod<[SendCallsParameter], BatchResult>; |
| 247 | + wallet_getCallsStatus: RpcMethod<[string], BatchStatus>; |
| 248 | + wallet_getCapabilities: RpcMethod<[Address, HexString[]?], Record<string, any>>; |
| 249 | + |
| 250 | + // Signing methods |
| 251 | + personal_sign: RpcMethod<[HexString, Address], HexString>; |
| 252 | + eth_signTypedData_v4: RpcMethod<[Address, TypedData], HexString>; |
| 253 | + eth_decrypt: RpcMethod<[string, Address], string>; |
| 254 | + eth_getEncryptionPublicKey: RpcMethod<[Address], string>; |
| 255 | + |
| 256 | + // Account methods |
| 257 | + eth_accounts: RpcMethod<[], Address[]>; |
| 258 | + |
| 259 | + // Transaction methods |
| 260 | + eth_sendTransaction: RpcMethod<[Transaction], Hash32>; |
| 261 | + eth_sendRawTransaction: RpcMethod<[HexString], Hash32>; |
| 262 | + eth_estimateGas: RpcMethod<[Transaction, BlockNumberOrTagOrHash?], HexString>; |
| 263 | + |
| 264 | + // Block methods |
| 265 | + eth_blockNumber: RpcMethod<[], HexString>; |
| 266 | + eth_getBlockByHash: RpcMethod<[Hash32, boolean], Block | null>; |
| 267 | + eth_getBlockByNumber: RpcMethod<[BlockNumberOrTag, boolean], Block | null>; |
| 268 | + eth_getBlockTransactionCountByHash: RpcMethod<[Hash32], HexString | null>; |
| 269 | + eth_getBlockTransactionCountByNumber: RpcMethod<[BlockNumberOrTag], HexString | null>; |
| 270 | + eth_getUncleCountByBlockHash: RpcMethod<[Hash32], HexString | null>; |
| 271 | + eth_getUncleCountByBlockNumber: RpcMethod<[BlockNumberOrTag], HexString | null>; |
| 272 | + |
| 273 | + // Transaction info methods |
| 274 | + eth_getTransactionByHash: RpcMethod<[Hash32], TransactionInfo | null>; |
| 275 | + eth_getTransactionByBlockHashAndIndex: RpcMethod<[Hash32, HexString], TransactionInfo | null>; |
| 276 | + eth_getTransactionByBlockNumberAndIndex: RpcMethod<[BlockNumberOrTag, HexString], TransactionInfo | null>; |
| 277 | + eth_getTransactionCount: RpcMethod<[Address, BlockNumberOrTagOrHash], HexString>; |
| 278 | + eth_getTransactionReceipt: RpcMethod<[Hash32], TransactionReceipt | null>; |
| 279 | + |
| 280 | + // State methods |
| 281 | + eth_getBalance: RpcMethod<[Address, BlockNumberOrTagOrHash], HexString>; |
| 282 | + eth_getCode: RpcMethod<[Address, BlockNumberOrTagOrHash], HexString>; |
| 283 | + eth_getStorageAt: RpcMethod<[Address, HexString, BlockNumberOrTagOrHash], HexString>; |
| 284 | + eth_call: RpcMethod<[Transaction, BlockNumberOrTagOrHash?], HexString>; |
| 285 | + eth_getProof: RpcMethod<[Address, HexString[], BlockNumberOrTagOrHash], AccountProof>; |
| 286 | + |
| 287 | + // Gas and fee methods |
| 288 | + eth_gasPrice: RpcMethod<[], HexString>; |
| 289 | + eth_feeHistory: RpcMethod<[HexString, BlockNumberOrTag, number[]], FeeHistory>; |
| 290 | + |
| 291 | + // Filter and log methods |
| 292 | + eth_newFilter: RpcMethod<[Filter], HexString>; |
| 293 | + eth_newBlockFilter: RpcMethod<[], HexString>; |
| 294 | + eth_newPendingTransactionFilter: RpcMethod<[], HexString>; |
| 295 | + eth_uninstallFilter: RpcMethod<[HexString], boolean>; |
| 296 | + eth_getFilterChanges: RpcMethod<[HexString], (Log | Hash32)[]>; |
| 297 | + eth_getFilterLogs: RpcMethod<[HexString], Log[]>; |
| 298 | + eth_getLogs: RpcMethod<[Filter], Log[]>; |
| 299 | + |
| 300 | + // Subscription methods |
| 301 | + eth_subscribe: RpcMethod<[string, object?], HexString>; |
| 302 | + eth_unsubscribe: RpcMethod<[HexString], boolean>; |
| 303 | + |
| 304 | + // Network info methods |
| 305 | + eth_chainId: RpcMethod<[], HexString>; |
| 306 | + eth_syncing: RpcMethod<[], SyncingStatus>; |
| 307 | + web3_clientVersion: RpcMethod<[], string>; |
8 | 308 | }; |
9 | | - events: ['eth_subscription']; |
| 309 | + events: ['eth_subscription', 'accountsChanged', 'chainChanged', 'connect', 'disconnect']; |
10 | 310 | }; |
0 commit comments