eip-1193 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.d.ts +506 -0
  2. package/package.json +12 -0
package/index.d.ts ADDED
@@ -0,0 +1,506 @@
1
+ // ------------------------------------------------------------------------------------------------
2
+ // TYPES
3
+ // ------------------------------------------------------------------------------------------------
4
+ export type EIP1193Transaction = {
5
+ blockHash: DATA;
6
+ blockNumber: QUANTITY | null;
7
+ from: EIP1193Account;
8
+ gas: QUANTITY;
9
+ gasPrice: QUANTITY;
10
+ hash: DATA;
11
+ input: DATA;
12
+ nonce: QUANTITY;
13
+ to: EIP1193Account;
14
+ transactionIndex: QUANTITY | null;
15
+ value: QUANTITY;
16
+ v: QUANTITY;
17
+ r: QUANTITY;
18
+ s: QUANTITY;
19
+ };
20
+
21
+ export type EIP1193SyncingStatus = {
22
+ startingBlock: QUANTITY;
23
+ currentBlock: QUANTITY;
24
+ highestBlock: QUANTITY;
25
+ };
26
+
27
+ export type EIP1193Block = {
28
+ number: QUANTITY;
29
+ hash: DATA;
30
+ parentHash: DATA;
31
+ nonce: DATA;
32
+ sha3Uncles: DATA;
33
+ logsBloom: DATA;
34
+ transactionsRoot: DATA;
35
+ stateRoot: DATA;
36
+ receiptsRoot: DATA;
37
+ miner: EIP1193Account;
38
+ difficulty: QUANTITY;
39
+ totalDifficulty: QUANTITY;
40
+ extraData: DATA;
41
+ size: QUANTITY;
42
+ gasLimit: QUANTITY;
43
+ gasUsed: QUANTITY;
44
+ timestamp: QUANTITY;
45
+ uncles: DATA[];
46
+ };
47
+
48
+ export type EIP1193Log = {
49
+ removed: boolean;
50
+ logIndex: QUANTITY | null;
51
+ transactionIndex: QUANTITY | null;
52
+ transactionHash: DATA | null;
53
+ blockHash: DATA | null;
54
+ blockNumber: QUANTITY | null;
55
+ address: EIP1193Account;
56
+ data: DATA;
57
+ topics: DATA[];
58
+ };
59
+
60
+ export type EIP1193TransactionReceipt = {
61
+ transactionHash: DATA;
62
+ transactionIndex: QUANTITY;
63
+ blockHash: DATA;
64
+ blockNumber: QUANTITY;
65
+ from: EIP1193Account;
66
+ to: EIP1193Account;
67
+ cumulativeGasUsed: QUANTITY;
68
+ effectiveGasPrice: QUANTITY;
69
+ gasUsed: QUANTITY;
70
+ contractAddress: EIP1193Account;
71
+ logs: EIP1193Log[];
72
+ logsBloom: DATA;
73
+ type: DATA;
74
+ root: DATA;
75
+ status: QUANTITY;
76
+ };
77
+
78
+ export type EIP1193PendingBlock = EIP1193Block & {
79
+ number: null;
80
+ hash: null;
81
+ nonce: null;
82
+ logsBloom: null;
83
+ };
84
+
85
+ export type EIP1193BlockWithTransactions = EIP1193Block & {
86
+ transactions: EIP1193Transaction[];
87
+ };
88
+
89
+ export type EIP1193PendingBlockWithTransactions = EIP1193PendingBlock & {
90
+ transactions: EIP1193Transaction[];
91
+ };
92
+
93
+ type EIP1193BaseTransactionData = {
94
+ gas?: QUANTITY;
95
+ gasPrice?: QUANTITY;
96
+ value?: QUANTITY;
97
+ data?: DATA;
98
+ nonce?: QUANTITY;
99
+ };
100
+ export type EIP1193NormalTransactionData = EIP1193BaseTransactionData & {
101
+ from: EIP1193Account;
102
+ to: EIP1193Account;
103
+ };
104
+
105
+ export type EIP1193TransactionContractCreationData =
106
+ EIP1193BaseTransactionData & {
107
+ from: EIP1193Account;
108
+ data: DATA;
109
+ };
110
+
111
+ export type EIP1193TransactionData =
112
+ | EIP1193NormalTransactionData
113
+ | EIP1193TransactionContractCreationData;
114
+
115
+ export type EIP1193CallParam = {
116
+ from?: EIP1193Account;
117
+ to: EIP1193Account;
118
+ gas?: QUANTITY;
119
+ gasPrice?: QUANTITY;
120
+ value?: QUANTITY;
121
+ data?: `0x${string}`;
122
+ };
123
+
124
+ export type EIP1193AddChainParam = {
125
+ chainId: ChainId;
126
+ rpcUrls?: string[];
127
+ blockExplorerUrls?: string[];
128
+ chainName?: string;
129
+ iconUrls?: string[];
130
+ nativeCurrency?: {
131
+ name: string;
132
+ symbol: string;
133
+ decimals: number;
134
+ };
135
+ };
136
+
137
+ export type EIP1193LogsParam = {
138
+ fromBlock?: BlockTag;
139
+ toBlock?: BlockTag;
140
+ address?: EIP1193Account | EIP1193Accounts;
141
+ topics?: DATA[];
142
+ blockhash?: DATA;
143
+ };
144
+
145
+ export type EIP1193TypedSignatureParam = { [field: string]: any }; // TODO
146
+ // ------------------------------------------------------------------------------------------------
147
+ // REQUEST TYPES
148
+ // ------------------------------------------------------------------------------------------------
149
+
150
+ export type EIP1193Web3ClientVersionRequest = {
151
+ readonly method: "web3_clientVersion";
152
+ };
153
+
154
+ export type EIP1193Web3SHARequest = {
155
+ readonly method: "web3_sha";
156
+ readonly params: [DATA];
157
+ };
158
+
159
+ export type EIP1193NetVersionRequest = {
160
+ readonly method: "net_version";
161
+ };
162
+
163
+ export type EIP1193NetListeningRequest = {
164
+ readonly method: "net_listening";
165
+ };
166
+
167
+ export type EIP1193NetPeerCountRequest = {
168
+ readonly method: "net_peerCount";
169
+ };
170
+
171
+ export type EIP1193ProtocolVersionRequest = {
172
+ readonly method: "eth_protocolVersion";
173
+ };
174
+
175
+ export type EIP1193SyncingRequest = {
176
+ readonly method: "eth_syncing";
177
+ };
178
+
179
+ export type EIP1193CoinbaseRequest = {
180
+ readonly method: "eth_coinbase";
181
+ };
182
+
183
+ export type EIP1193MiningRequest = {
184
+ readonly method: "eth_mining";
185
+ };
186
+
187
+ export type EIP1193HashrateRequest = {
188
+ readonly method: "eth_hashrate";
189
+ };
190
+
191
+ export type EIP1193GasPriceRequest = {
192
+ readonly method: "eth_gasPrice";
193
+ };
194
+
195
+ export type EIP1193AccountsRequest = {
196
+ readonly method: "eth_accounts";
197
+ };
198
+
199
+ export type EIP1193BlockNumberRequest = {
200
+ readonly method: "eth_blockNumber";
201
+ };
202
+
203
+ export type EIP1193GetBalanceRequest = {
204
+ readonly method: "eth_getBalance";
205
+ readonly params: [EIP1193Account] | [EIP1193Account, BlockTag];
206
+ };
207
+
208
+ export type EIP1193GetStorageAtRequest = {
209
+ readonly method: "eth_getStorageAt";
210
+ readonly params:
211
+ | [EIP1193Account, QUANTITY]
212
+ | [EIP1193Account, QUANTITY, BlockTag];
213
+ };
214
+
215
+ export type EIP1193GetTransactionCountRequest = {
216
+ readonly method: "eth_getTransactionCount";
217
+ readonly params: [EIP1193Account] | [EIP1193Account, BlockTag];
218
+ };
219
+
220
+ export type EIP1193GetTransactionCountByHashRequest = {
221
+ readonly method: "eth_getBlockTransactionCountByHash";
222
+ readonly params: [DATA];
223
+ };
224
+
225
+ export type EIP1193GetTransactionCountByNumberRequest = {
226
+ readonly method: "eth_getBlockTransactionCountByNumber";
227
+ readonly params: [BlockTag];
228
+ };
229
+
230
+ export type EIP1193GetUncleCountByBlockHashRequest = {
231
+ readonly method: "eth_getUncleCountByBlockHash";
232
+ readonly params: [DATA];
233
+ };
234
+
235
+ export type EIP1193GetUncleCountByBlockNumberRequest = {
236
+ readonly method: "eth_getUncleCountByBlockNumber";
237
+ readonly params: [BlockTag];
238
+ };
239
+
240
+ export type EIP1193GetCodeRequest = {
241
+ readonly method: "eth_getCode";
242
+ readonly params: [EIP1193Account] | [EIP1193Account, BlockTag];
243
+ };
244
+
245
+ export type EIP1193LegacySignRequest = {
246
+ readonly method: "eth_sign";
247
+ readonly params: [EIP1193Account, DATA];
248
+ };
249
+
250
+ export type EIP1193SignTransactionRequest = {
251
+ readonly method: "eth_signTransaction";
252
+ readonly params: [EIP1193TransactionData];
253
+ };
254
+
255
+ export type EIP1193SendTransactionRequest = {
256
+ readonly method: "eth_sendTransaction";
257
+ readonly params: [EIP1193TransactionData];
258
+ };
259
+
260
+ export type EIP1193SendRawTransactionRequest = {
261
+ readonly method: "eth_sendRawTransaction";
262
+ readonly params: [DATA];
263
+ };
264
+
265
+ export type EIP119CallRequest = {
266
+ readonly method: "eth_call";
267
+ readonly params: [EIP1193CallParam] | [EIP1193CallParam, BlockTag];
268
+ };
269
+
270
+ export type EIP119EstimateGasRequest = {
271
+ readonly method: "eth_estimateGas";
272
+ readonly params: [EIP1193CallParam] | [EIP1193CallParam, BlockTag];
273
+ };
274
+
275
+ export type EIP119GetBlockByHashRequest<T = false> = {
276
+ readonly method: "eth_getBlockByHash";
277
+ readonly params: [DATA, T];
278
+ };
279
+
280
+ export type EIP119GetBlockByNumberRequest<T = false> = {
281
+ readonly method: "eth_getBlockByNumber";
282
+ readonly params: [BlockTag, T];
283
+ };
284
+
285
+ export type EIP119GetTransactionByHashRequest = {
286
+ readonly method: "eth_getTransactionByHash";
287
+ readonly params: [DATA];
288
+ };
289
+
290
+ export type EIP119GetTransactionByBlockHashAndIndexRequest = {
291
+ readonly method: "eth_getTransactionByBlockHashAndIndex";
292
+ readonly params: [DATA, QUANTITY];
293
+ };
294
+
295
+ export type EIP119GetTransactionByBlockNumberAndIndexRequest = {
296
+ readonly method: "eth_getTransactionByBlockNumberAndIndex";
297
+ readonly params: [BlockTag, QUANTITY];
298
+ };
299
+
300
+ export type EIP119GetTransactionReceiptRequest = {
301
+ readonly method: "eth_getTransactionReceipt";
302
+ readonly params: [DATA];
303
+ };
304
+
305
+ export type EIP119GetUncleByBlockHashAndIndexRequest = {
306
+ readonly method: "eth_getUncleByBlockHashAndIndex";
307
+ readonly params: [DATA, QUANTITY];
308
+ };
309
+
310
+ export type EIP119GetUncleByBlockNumberAndIndexRequest = {
311
+ readonly method: "eth_getUncleByBlockNumberAndIndex";
312
+ readonly params: [BlockTag, QUANTITY];
313
+ };
314
+
315
+ export type EIP119GetLogsRequest = {
316
+ readonly method: "eth_getLogs";
317
+ readonly params: [EIP1193LogsParam];
318
+ };
319
+
320
+ // ------------------------------------------------------------------------------------------------
321
+ // MORE REQUEST TYPES
322
+ // ------------------------------------------------------------------------------------------------
323
+
324
+ export type EIP1193PersonalSignRequest = {
325
+ readonly method: "personal_sign";
326
+ readonly params: [DATA, EIP1193Account];
327
+ };
328
+
329
+ export type EIP1193PTypedSignv4Request = {
330
+ readonly method: "eth_signTypedData_v4";
331
+ readonly params: [EIP1193Account, EIP1193TypedSignatureParam];
332
+ };
333
+
334
+ export type EIP1193PTypedSignRequest = {
335
+ readonly method: "eth_signTypedData";
336
+ readonly params: [EIP1193Account, EIP1193TypedSignatureParam];
337
+ };
338
+
339
+ export type EIP1193ChainIdRequest = {
340
+ readonly method: "eth_chainId";
341
+ };
342
+
343
+ export type EIP1193RequestAccountsRequest = {
344
+ readonly method: "eth_requestAccounts";
345
+ };
346
+
347
+ export type ERIP1193SwitchChainRequest = {
348
+ readonly method: "wallet_switchEthereumChain";
349
+ readonly params: [
350
+ {
351
+ chainId: string; // TODO `0x${string}`
352
+ }
353
+ ];
354
+ };
355
+ export type ERIP1193AddChainRequest = {
356
+ readonly method: "wallet_addEthereumChain";
357
+ readonly params: [EIP1193AddChainParam];
358
+ };
359
+
360
+ // ------------------------------------------------------------------------------------------------
361
+
362
+ export type EIP1193GenericRequest = {
363
+ readonly method: string;
364
+ readonly params?: readonly unknown[];
365
+ };
366
+
367
+ export interface EIP1193ProviderRpcError extends Error {
368
+ message: string;
369
+ code: number;
370
+ data?: unknown;
371
+ }
372
+
373
+ export interface EIP1193ProviderMessage {
374
+ readonly type: string;
375
+ readonly data: unknown;
376
+ }
377
+
378
+ export interface EIP1193EthSubscription extends EIP1193ProviderMessage {
379
+ readonly type: "eth_subscription";
380
+ readonly data: {
381
+ readonly subscription: string;
382
+ readonly result: unknown;
383
+ };
384
+ }
385
+
386
+ export interface EIP1193ProviderConnectInfo {
387
+ readonly chainId: string;
388
+ }
389
+
390
+ export type EIP1193AddChainError = {
391
+ // TODO
392
+ };
393
+
394
+ export type EIP1193SwitchChainError = {
395
+ // TODO
396
+ };
397
+
398
+ /*
399
+ // TODO
400
+ 4001 User Rejected Request The user rejected the request.
401
+ 4100 Unauthorized The requested method and/or account has not been authorized by the user.
402
+ 4200 Unsupported Method The Provider does not support the requested method.
403
+ 4900 Disconnected The Provider is disconnected from all chains.
404
+ 4901 Chain Disconnected The Provider is not connected to the requested chain.
405
+ */
406
+
407
+ type Listener<Message> = (message: Message) => unknown | Promise<unknown>;
408
+
409
+ export interface EIP1193Provider {
410
+ on(
411
+ eventName: "message" | "disconnect",
412
+ listener: Listener<EIP1193ProviderMessage | EIP1193EthSubscription>
413
+ ): EIP1193Provider;
414
+ on(
415
+ eventName: "accountsChanged",
416
+ listener: Listener<string[]>
417
+ ): EIP1193Provider;
418
+ on(eventName: "chainChanged", listener: Listener<string>): EIP1193Provider;
419
+ on(
420
+ eventName: "connect",
421
+ listener: Listener<EIP1193ProviderConnectInfo>
422
+ ): EIP1193Provider;
423
+ removeListener(
424
+ eventName: string | symbol,
425
+ listener:
426
+ | Listener<string>
427
+ | Listener<string[]>
428
+ | Listener<
429
+ | EIP1193ProviderMessage
430
+ | EIP1193EthSubscription
431
+ | EIP1193ProviderConnectInfo
432
+ >
433
+ ): EIP1193Provider;
434
+
435
+ request(args: EIP1193Web3ClientVersionRequest): Promise<string>;
436
+ request(args: EIP1193Web3SHARequest): Promise<DATA>;
437
+ request(args: EIP1193NetVersionRequest): Promise<ChainId>;
438
+ request(args: EIP1193NetListeningRequest): Promise<boolean>;
439
+ request(args: EIP1193NetPeerCountRequest): Promise<QUANTITY>;
440
+ request(args: EIP1193ProtocolVersionRequest): Promise<string>;
441
+ request(args: EIP1193SyncingRequest): Promise<EIP1193SyncingStatus | false>;
442
+ request(args: EIP1193CoinbaseRequest): Promise<EIP1193Account>;
443
+ request(args: EIP1193MiningRequest): Promise<boolean>;
444
+ request(args: EIP1193HashrateRequest): Promise<QUANTITY>;
445
+ request(args: EIP1193GasPriceRequest): Promise<QUANTITY>;
446
+ request(args: EIP1193AccountsRequest): Promise<EIP1193Accounts>;
447
+ request(args: EIP1193BlockNumberRequest): Promise<QUANTITY>;
448
+ request(args: EIP1193GetBalanceRequest): Promise<QUANTITY>;
449
+ request(args: EIP1193GetStorageAtRequest): Promise<DATA>;
450
+ request(args: EIP1193GetTransactionCountRequest): Promise<QUANTITY>;
451
+ request(args: EIP1193GetTransactionCountByHashRequest): Promise<QUANTITY>;
452
+ request(args: EIP1193GetTransactionCountByNumberRequest): Promise<QUANTITY>;
453
+
454
+ request(args: EIP1193GetUncleCountByBlockHashRequest): Promise<QUANTITY>;
455
+ request(args: EIP1193GetUncleCountByBlockNumberRequest): Promise<QUANTITY>;
456
+ request(args: EIP1193GetCodeRequest): Promise<DATA>;
457
+ request(args: EIP1193LegacySignRequest): Promise<DATA>;
458
+ request(args: EIP1193SignTransactionRequest): Promise<DATA>;
459
+ request(args: EIP1193SendTransactionRequest): Promise<DATA>;
460
+ request(args: EIP1193SendRawTransactionRequest): Promise<DATA>;
461
+ request(args: EIP119CallRequest): Promise<DATA>;
462
+ request(args: EIP119EstimateGasRequest): Promise<QUANTITY>;
463
+ request(args: EIP119GetBlockByHashRequest): Promise<EIP1193Block>;
464
+ request(args: EIP119GetBlockByNumberRequest): Promise<EIP1193Block>;
465
+ request(
466
+ args: EIP119GetBlockByHashRequest<true>
467
+ ): Promise<EIP1193BlockWithTransactions>;
468
+ request(
469
+ args: EIP119GetBlockByNumberRequest<true>
470
+ ): Promise<EIP1193BlockWithTransactions>;
471
+ request(args: EIP119GetTransactionByHashRequest): Promise<EIP1193Transaction>;
472
+ request(
473
+ args: EIP119GetTransactionByBlockHashAndIndexRequest
474
+ ): Promise<EIP1193Transaction>;
475
+ request(
476
+ args: EIP119GetTransactionByBlockNumberAndIndexRequest
477
+ ): Promise<EIP1193Transaction>;
478
+ request(
479
+ args: EIP119GetTransactionReceiptRequest
480
+ ): Promise<EIP1193TransactionReceipt>;
481
+ request(
482
+ args: EIP119GetUncleByBlockHashAndIndexRequest
483
+ ): Promise<EIP1193Block>;
484
+ request(
485
+ args: EIP119GetUncleByBlockNumberAndIndexRequest
486
+ ): Promise<EIP1193Block>;
487
+ request(args: EIP119GetLogsRequest): Promise<EIP1193Log[]>;
488
+ request(args: EIP1193PersonalSignRequest): Promise<DATA>;
489
+ request(args: EIP1193PTypedSignv4Request): Promise<DATA>;
490
+ request(args: EIP1193PTypedSignRequest): Promise<DATA>;
491
+ request(args: EIP1193ChainIdRequest): Promise<ChainId>;
492
+ request(args: EIP1193RequestAccountsRequest): Promise<EIP1193Accounts>;
493
+ request(
494
+ args: ERIP1193SwitchChainRequest
495
+ ): Promise<EIP1193SwitchChainError | null>;
496
+ request(args: ERIP1193AddChainRequest): Promise<EIP1193AddChainError | null>;
497
+
498
+ // request(args: EIP1193GenericRequest): Promise<unknown>;
499
+ }
500
+
501
+ type BlockTag = QUANTITY | "latest" | "earliest" | "pending";
502
+ type QUANTITY = `0x${string}`;
503
+ type DATA = `0x${string}`;
504
+ type ChainId = `0x${string}`;
505
+ export type EIP1193Account = `0x${string}`;
506
+ export type EIP1193Accounts = EIP1193Account[];
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "eip-1193",
3
+ "version": "0.0.1",
4
+ "description": "Types for EIP-1193",
5
+ "keywords": [],
6
+ "author": "",
7
+ "license": "ISC",
8
+ "types": "index.d.ts",
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ }
12
+ }