eip-1193 0.7.2 → 0.7.4

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 +244 -18
  2. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -219,6 +219,14 @@ type BaseEIP1193TransactionData = {
219
219
 
220
220
  export type EIP1193LegacyTransactionData = BaseEIP1193TransactionData & {
221
221
  type?: '0x0';
222
+ /**
223
+ * Binds the transaction to a chain (EIP-155 replay protection). Optional on every type,
224
+ * legacy included: execution-apis `GenericTransaction` and `TransactionLegacyUnsigned` both
225
+ * carry an optional `chainId` (`src/schemas/transaction.yaml`), and go-ethereum rejects a
226
+ * `TransactionArgs` whose `chainId` does not match the node's, whatever its type, and fills
227
+ * it in when absent (`internal/ethapi/transaction_args.go`, `setDefaults`).
228
+ */
229
+ chainId?: EIP1193ChainId;
222
230
  gasPrice?: EIP1193QUANTITY;
223
231
  };
224
232
 
@@ -575,26 +583,13 @@ export type EIP1193TypedData = {
575
583
  };
576
584
 
577
585
  /**
578
- * The typed-data parameter of `eth_signTypedData_v3` / `eth_signTypedData_v4`.
586
+ * The typed-data parameter of `eth_signTypedData`, `eth_signTypedData_v3` and `eth_signTypedData_v4`.
579
587
  *
580
588
  * MetaMask's canonical form is a JSON STRING (`JSON.stringify(typedData)`); other wallets and
581
589
  * most libraries accept the object directly. Both are allowed here.
582
590
  */
583
591
  export type EIP1193TypedSignatureParam = EIP1193TypedData | string;
584
592
 
585
- /** A single field of the legacy V1 `eth_signTypedData` payload. */
586
- export type EIP1193TypedDataV1Field = {
587
- name: string;
588
- type: string;
589
- value: any;
590
- };
591
-
592
- /**
593
- * The legacy V1 `eth_signTypedData` payload: a flat ARRAY of fields, not an EIP-712 object.
594
- * Note that V1 also takes its parameters in the opposite order to v3/v4.
595
- */
596
- export type EIP1193TypedDataV1 = EIP1193TypedDataV1Field[];
597
-
598
593
  // ------------------------------------------------------------------------------------------------
599
594
  // WALLET METHOD PARAMS (EIP-3085 / 3326 / 747 / 2255 / 5792)
600
595
  // ------------------------------------------------------------------------------------------------
@@ -843,6 +838,12 @@ type Listener<Message> = (message: Message) => unknown;
843
838
  // LegacyNodeMethods - pre-merge leftovers, removed from execution-apis.
844
839
  // DebugOnlyMethods - the debug namespace.
845
840
  //
841
+ // Development nodes add their own groups, see DEV-NODE METHOD GROUPS below:
842
+ //
843
+ // DevNodeMethods - served by BOTH Hardhat and Anvil under the same name.
844
+ // HardhatMethods - served by Hardhat only.
845
+ // AnvilMethods - served by Anvil only (its `anvil_*` names and its extra aliases).
846
+ //
846
847
  // ------------------------------------------------------------------------------------------------
847
848
 
848
849
  /** Client and network identity. Served by browser wallets as well as nodes. */
@@ -999,12 +1000,13 @@ export type SignerMethods = {
999
1000
  personal_ecRecover: {params: [EIP1193DATA, EIP1193DATA]; result: EIP1193Account};
1000
1001
 
1001
1002
  /**
1002
- * The legacy V1 API. Takes `[typedData, address]` -- the REVERSE of v3/v4 -- and a flat array
1003
- * of `{name, type, value}` fields rather than an EIP-712 object.
1003
+ * Typed like v4: `[address, typedData]`. The legacy V1 payload (a flat field array, with the
1004
+ * parameters in the reverse order) is deliberately not modelled: nothing in use sends it, and
1005
+ * viem only ever sends `eth_signTypedData_v4`.
1004
1006
  *
1005
1007
  * @deprecated Use `eth_signTypedData_v4`.
1006
1008
  */
1007
- eth_signTypedData: {params: [EIP1193TypedDataV1 | string, EIP1193Account]; result: EIP1193DATA};
1009
+ eth_signTypedData: {params: [EIP1193Account, EIP1193TypedSignatureParam]; result: EIP1193DATA};
1008
1010
  /** @deprecated Does not handle arrays or nested structs correctly. Use `eth_signTypedData_v4`. */
1009
1011
  eth_signTypedData_v3: {params: [EIP1193Account, EIP1193TypedSignatureParam]; result: EIP1193DATA};
1010
1012
  eth_signTypedData_v4: {params: [EIP1193Account, EIP1193TypedSignatureParam]; result: EIP1193DATA};
@@ -1063,6 +1065,215 @@ export type DebugOnlyMethods = {
1063
1065
  };
1064
1066
  };
1065
1067
 
1068
+ // ------------------------------------------------------------------------------------------------
1069
+ // DEV-NODE METHOD GROUPS
1070
+ // ------------------------------------------------------------------------------------------------
1071
+ //
1072
+ // Methods only a local development node serves: time travel, mining control, state edits and
1073
+ // impersonation. No production endpoint answers them, so they are in none of the sets above and
1074
+ // are composed into dedicated provider types instead (EIP1193DevNodeProvider,
1075
+ // EIP1193HardhatProvider, EIP1193AnvilProvider).
1076
+ //
1077
+ // Every entry was checked against the client's own request parser and handler:
1078
+ //
1079
+ // Hardhat: NomicFoundation/edr @ b9bd49fcc746d11e510447448a7f97f9a359ddc5
1080
+ // crates/edr_provider/src/requests/methods.rs (params, results)
1081
+ // crates/edr_provider/src/requests/serde.rs (how each param is parsed)
1082
+ // Anvil: foundry-rs/foundry @ 85d83334d17a1e37c849d954711312480ef876d7
1083
+ // crates/anvil/core/src/eth/mod.rs (`EthRequest`: names, aliases, params)
1084
+ // crates/anvil/src/eth/api.rs (results; a handler returning `()` answers `null`)
1085
+ // crates/common/src/serde_helpers.rs (how each numeric param is parsed)
1086
+ //
1087
+ // DevNodeMethods is disjoint from each client group, so each provider type composes by plain
1088
+ // intersection. HardhatMethods and AnvilMethods are NOT disjoint from each other: both list
1089
+ // `evm_setIntervalMining`, in different units, so do not intersect them. A method both clients
1090
+ // serve under the same name and meaning lives in DevNodeMethods only, typed with the params BOTH
1091
+ // accept and a result covering what EITHER returns. Where they disagree is noted per entry:
1092
+ // Hardhat mostly answers `true` where Anvil answers `null`, which is why many results below are
1093
+ // `boolean | null`.
1094
+ //
1095
+ // Params: a timestamp, a duration or a block count is typed `EIP1193QUANTITY | number`, because
1096
+ // both clients accept a JSON number there as well as a hex string. Other quantities are
1097
+ // `EIP1193QUANTITY` only: Hardhat rejects a JSON number for balances, nonces and storage slots,
1098
+ // and the rest are kept hex for uniformity.
1099
+ //
1100
+ // Omitting `params` is allowed only where it was checked to work. `evm_mine` and `hardhat_mine`
1101
+ // need `params` (pass `[]` for the defaults): Anvil answers `invalid type: null` to an omitted
1102
+ // `params` on `anvil_mine` / `hardhat_mine`, and `evm_mine` requires it too because Hardhat's
1103
+ // handling of an omitted `params` there could not be verified (Anvil accepts it).
1104
+ //
1105
+ // Not covered: `hardhat_reset` is not served by EDR, the engine of Hardhat 3, which removed it
1106
+ // (Hardhat 2 answers it in its JavaScript layer); Anvil's is in AnvilMethods. Methods outside
1107
+ // these tables can still be called through EIP1193GenericRequestProvider.
1108
+ //
1109
+ // ------------------------------------------------------------------------------------------------
1110
+
1111
+ /** The fork the node runs on, as reported by `hardhat_metadata`. */
1112
+ export type EIP1193DevNodeForkedNetwork = {
1113
+ chainId: number;
1114
+ forkBlockNumber: number;
1115
+ forkBlockHash: EIP1193DATA;
1116
+ };
1117
+
1118
+ /**
1119
+ * `hardhat_metadata` result. Numbers are JSON numbers, not hex quantities. Hardhat omits
1120
+ * `forkedNetwork` when not forking; Anvil sends `null`.
1121
+ */
1122
+ export type EIP1193DevNodeMetadata = {
1123
+ clientVersion: string;
1124
+ chainId: number;
1125
+ /** Unique per run of the node; changes on reset. */
1126
+ instanceId: EIP1193DATA;
1127
+ latestBlockNumber: number;
1128
+ latestBlockHash: EIP1193DATA;
1129
+ forkedNetwork?: EIP1193DevNodeForkedNetwork | null;
1130
+ };
1131
+
1132
+ /** `anvil_metadata` result: the `hardhat_metadata` fields plus Anvil's own. */
1133
+ export type EIP1193AnvilMetadata = EIP1193DevNodeMetadata & {
1134
+ clientSemver: string | null;
1135
+ clientCommitSha: string | null;
1136
+ /** Keyed by snapshot id: `[blockNumber, blockHash]` at the time of the snapshot. */
1137
+ snapshots: {[snapshotId: string]: [number, EIP1193DATA]};
1138
+ };
1139
+
1140
+ /** The fork to reset onto, for `anvil_reset` / Anvil's `hardhat_reset`. */
1141
+ export type EIP1193AnvilForkingParam = {
1142
+ jsonRpcUrl?: string;
1143
+ blockNumber?: EIP1193QUANTITY | number;
1144
+ };
1145
+
1146
+ /** A timestamp, duration or block count: both dev nodes accept a JSON number or a hex string. */
1147
+ type DevNodeNumber = EIP1193QUANTITY | number;
1148
+
1149
+ /**
1150
+ * An entry whose params are all optional, so `params` itself may be omitted from the request.
1151
+ * Two entries, hence two overloads: a required `params` tuple alone would force `params: []`.
1152
+ */
1153
+ type ParamsMayBeOmitted<P extends any[], R> = {result: R} | {params: P; result: R};
1154
+
1155
+ /**
1156
+ * Served by BOTH Hardhat and Anvil under the same name: the `evm_*` methods both implement, and
1157
+ * the `hardhat_*` methods Anvil accepts as aliases of its `anvil_*` ones.
1158
+ */
1159
+ export type DevNodeMethods = {
1160
+ /**
1161
+ * Mines one block. The optional param is the block's timestamp. Anvil also accepts
1162
+ * `{timestamp, blocks}`, which Hardhat does not; for several blocks use `hardhat_mine`.
1163
+ * Pass `params: []` for no timestamp. The result is a placeholder: Hardhat answers `'0'`,
1164
+ * Anvil `'0x0'`.
1165
+ */
1166
+ evm_mine: {params: [timestamp?: DevNodeNumber]; result: string};
1167
+ /** Seconds to add. Returns the total offset: Hardhat as a DECIMAL string, Anvil as a number. */
1168
+ evm_increaseTime: {params: [seconds: DevNodeNumber]; result: string | number};
1169
+ /** Hardhat returns the timestamp as a DECIMAL string, Anvil returns `null`. */
1170
+ evm_setNextBlockTimestamp: {params: [timestamp: DevNodeNumber]; result: string | null};
1171
+ /** Returns the snapshot id, to pass to `evm_revert`. */
1172
+ evm_snapshot: {result: EIP1193QUANTITY};
1173
+ /** `false` if the id is unknown. Reverting consumes the snapshot and every later one. */
1174
+ evm_revert: {params: [snapshotId: EIP1193QUANTITY]; result: boolean};
1175
+ /** Hardhat returns `true`, Anvil `null`. */
1176
+ evm_setAutomine: {params: [enabled: boolean]; result: boolean | null};
1177
+ evm_setBlockGasLimit: {params: [gasLimit: EIP1193QUANTITY]; result: boolean};
1178
+
1179
+ /** Hardhat returns `true`, Anvil `null`. */
1180
+ hardhat_impersonateAccount: {params: [EIP1193Account]; result: boolean | null};
1181
+ /** Hardhat returns whether the account was impersonated, Anvil `null`. */
1182
+ hardhat_stopImpersonatingAccount: {params: [EIP1193Account]; result: boolean | null};
1183
+ hardhat_getAutomine: {result: boolean};
1184
+ /** Mines `blocks` blocks (default 1), `interval` seconds apart (default 1). */
1185
+ hardhat_mine: {params: [blocks?: DevNodeNumber, interval?: DevNodeNumber]; result: boolean | null};
1186
+ hardhat_setBalance: {params: [EIP1193Account, balance: EIP1193QUANTITY]; result: boolean | null};
1187
+ hardhat_setCode: {params: [EIP1193Account, code: EIP1193DATA]; result: boolean | null};
1188
+ hardhat_setNonce: {params: [EIP1193Account, nonce: EIP1193QUANTITY]; result: boolean | null};
1189
+ /** `value` must be exactly 32 bytes. Both clients return `true`. */
1190
+ hardhat_setStorageAt: {params: [EIP1193Account, slot: EIP1193QUANTITY, value: EIP1193DATA]; result: boolean};
1191
+ hardhat_setCoinbase: {params: [EIP1193Account]; result: boolean | null};
1192
+ /**
1193
+ * Removes a pending transaction. Hardhat returns whether it was removed; Anvil returns the
1194
+ * removed transaction's hash, or `null` if there was none.
1195
+ */
1196
+ hardhat_dropTransaction: {params: [txHash: EIP1193DATA]; result: boolean | EIP1193DATA | null};
1197
+ /** Post-London only (both clients). */
1198
+ hardhat_setNextBlockBaseFeePerGas: {params: [baseFee: EIP1193QUANTITY]; result: boolean | null};
1199
+ /** Pre-London only (both clients). */
1200
+ hardhat_setMinGasPrice: {params: [gasPrice: EIP1193QUANTITY]; result: boolean | null};
1201
+ hardhat_setLoggingEnabled: {params: [enabled: boolean]; result: boolean | null};
1202
+ hardhat_metadata: {result: EIP1193DevNodeMetadata};
1203
+ };
1204
+
1205
+ /** Served by Hardhat (EDR) only. */
1206
+ export type HardhatMethods = {
1207
+ /**
1208
+ * Interval in MILLISECONDS, or a `[min, max]` range for a random interval; `0` disables.
1209
+ * Anvil's `evm_setIntervalMining` takes SECONDS, hence one entry per client.
1210
+ */
1211
+ evm_setIntervalMining: {params: [interval: number | [min: number, max: number]]; result: boolean};
1212
+ /** Post-merge only. */
1213
+ hardhat_setPrevRandao: {params: [prevRandao: EIP1193DATA]; result: boolean};
1214
+ };
1215
+
1216
+ /**
1217
+ * Served by Anvil only: a selection of its `anvil_*` methods, and of the `evm_*` / `hardhat_*`
1218
+ * aliases Anvil accepts that Hardhat does not serve (or serves with a different meaning). Others
1219
+ * (`anvil_dealERC20`, `anvil_nodeInfo`, `evm_mine_detailed`, ...) are not typed yet.
1220
+ */
1221
+ export type AnvilMethods = {
1222
+ /** Interval in SECONDS; `0` disables. Hardhat's takes milliseconds. */
1223
+ evm_setIntervalMining: {params: [seconds: DevNodeNumber]; result: null};
1224
+ anvil_setIntervalMining: {params: [seconds: DevNodeNumber]; result: null};
1225
+ /** Sets the clock. Returns the offset to wall-clock time in seconds. */
1226
+ evm_setTime: {params: [timestamp: DevNodeNumber]; result: number};
1227
+ anvil_setTime: {params: [timestamp: DevNodeNumber]; result: number};
1228
+
1229
+ anvil_mine: {params: [blocks?: DevNodeNumber, interval?: DevNodeNumber]; result: null};
1230
+ anvil_increaseTime: {params: [seconds: DevNodeNumber]; result: number};
1231
+ anvil_setNextBlockTimestamp: {params: [timestamp: DevNodeNumber]; result: null};
1232
+ anvil_snapshot: {result: EIP1193QUANTITY};
1233
+ anvil_revert: {params: [snapshotId: EIP1193QUANTITY]; result: boolean};
1234
+ anvil_setAutomine: {params: [enabled: boolean]; result: null};
1235
+ anvil_getAutomine: {result: boolean};
1236
+ anvil_setBlockGasLimit: {params: [gasLimit: EIP1193QUANTITY]; result: boolean};
1237
+
1238
+ anvil_impersonateAccount: {params: [EIP1193Account]; result: null};
1239
+ anvil_stopImpersonatingAccount: {params: [EIP1193Account]; result: null};
1240
+ /** Makes every account impersonated. */
1241
+ anvil_autoImpersonateAccount: {params: [enabled: boolean]; result: null};
1242
+ hardhat_autoImpersonateAccount: {params: [enabled: boolean]; result: null};
1243
+
1244
+ anvil_setBalance: {params: [EIP1193Account, balance: EIP1193QUANTITY]; result: null};
1245
+ anvil_addBalance: {params: [EIP1193Account, amount: EIP1193QUANTITY]; result: null};
1246
+ hardhat_addBalance: {params: [EIP1193Account, amount: EIP1193QUANTITY]; result: null};
1247
+ anvil_setCode: {params: [EIP1193Account, code: EIP1193DATA]; result: null};
1248
+ anvil_setNonce: {params: [EIP1193Account, nonce: EIP1193QUANTITY]; result: null};
1249
+ /** `value` must be exactly 32 bytes. */
1250
+ anvil_setStorageAt: {params: [EIP1193Account, slot: EIP1193QUANTITY, value: EIP1193DATA]; result: boolean};
1251
+ anvil_setCoinbase: {params: [EIP1193Account]; result: null};
1252
+ anvil_setChainId: {params: [chainId: DevNodeNumber]; result: null};
1253
+
1254
+ /** Returns the removed transaction's hash, or `null` if there was none. */
1255
+ anvil_dropTransaction: {params: [txHash: EIP1193DATA]; result: EIP1193DATA | null};
1256
+ anvil_dropAllTransactions: {result: null};
1257
+ hardhat_dropAllTransactions: {result: null};
1258
+ anvil_setNextBlockBaseFeePerGas: {params: [baseFee: EIP1193QUANTITY]; result: null};
1259
+ anvil_setMinGasPrice: {params: [gasPrice: EIP1193QUANTITY]; result: null};
1260
+ anvil_setLoggingEnabled: {params: [enabled: boolean]; result: null};
1261
+
1262
+ /**
1263
+ * Resets the chain, optionally onto a new fork. The fork options may be passed bare or under
1264
+ * a `forking` key. Omit them to reset to the initial state.
1265
+ */
1266
+ anvil_reset: ParamsMayBeOmitted<[forking?: EIP1193AnvilForkingParam | {forking: EIP1193AnvilForkingParam}], null>;
1267
+ /** Anvil's alias of `anvil_reset`. Hardhat 3 does not serve `hardhat_reset`. */
1268
+ hardhat_reset: ParamsMayBeOmitted<[forking?: EIP1193AnvilForkingParam | {forking: EIP1193AnvilForkingParam}], null>;
1269
+ /** Returns the state as an opaque blob for `anvil_loadState`. */
1270
+ anvil_dumpState: ParamsMayBeOmitted<[preserveHistoricalStates?: boolean], EIP1193DATA>;
1271
+ hardhat_dumpState: ParamsMayBeOmitted<[preserveHistoricalStates?: boolean], EIP1193DATA>;
1272
+ anvil_loadState: {params: [state: EIP1193DATA]; result: boolean};
1273
+ hardhat_loadState: {params: [state: EIP1193DATA]; result: boolean};
1274
+ anvil_metadata: {result: EIP1193AnvilMetadata};
1275
+ };
1276
+
1066
1277
  // ------------------------------------------------------------------------------------------------
1067
1278
  // METHOD SETS
1068
1279
  // ------------------------------------------------------------------------------------------------
@@ -1127,7 +1338,10 @@ export type CoreMethods = ClientMethods &
1127
1338
  SignerMethods &
1128
1339
  ConnectedAccountMethods;
1129
1340
 
1130
- /** Every method in this file, node and wallet and debug. Permissive; prefer a narrower set. */
1341
+ /**
1342
+ * Every method in this file, node and wallet and debug, except the dev-node groups (Hardhat and
1343
+ * Anvil disagree on some of them). Permissive; prefer a narrower set.
1344
+ */
1131
1345
  export type AllMethods = NodeMethods & WalletMethods & DebugOnlyMethods;
1132
1346
 
1133
1347
  // ------------------------------------------------------------------------------------------------
@@ -1250,6 +1464,18 @@ export type EIP1193SignerProvider = RequestRPC<SignerMethods>;
1250
1464
  /** A node provider with the `debug` namespace enabled. */
1251
1465
  export type EIP1193DebugProvider = EIP1193NodeProvider & RequestRPC<DebugOnlyMethods>;
1252
1466
 
1467
+ /**
1468
+ * Any local development node, Hardhat or Anvil: the {@link CoreMethods} plus the dev-node
1469
+ * methods both serve ({@link DevNodeMethods}). Use it for code that runs against either.
1470
+ */
1471
+ export type EIP1193DevNodeProvider = EIP1193CoreProvider & RequestRPC<DevNodeMethods>;
1472
+
1473
+ /** A Hardhat node: a JSON-RPC node plus {@link DevNodeMethods} and {@link HardhatMethods}. */
1474
+ export type EIP1193HardhatProvider = EIP1193NodeProvider & RequestRPC<DevNodeMethods & HardhatMethods>;
1475
+
1476
+ /** An Anvil node: a JSON-RPC node plus {@link DevNodeMethods} and {@link AnvilMethods}. */
1477
+ export type EIP1193AnvilProvider = EIP1193NodeProvider & RequestRPC<DevNodeMethods & AnvilMethods>;
1478
+
1253
1479
  /** Every method in this file. Permissive; prefer a narrower provider type. */
1254
1480
  export type EIP1193AllMethodsProvider = RequestRPC<AllMethods>;
1255
1481
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eip-1193",
3
- "version": "0.7.2",
3
+ "version": "0.7.4",
4
4
  "description": "Types for EIP-1193 ethereum provider",
5
5
  "keywords": ["ethereum", "eip-1193"],
6
6
  "author": "Ronan Sandford",