@toruslabs/ethereum-controllers 8.17.1 → 9.1.0

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 (76) hide show
  1. package/dist/lib.cjs/Account/AccountTrackerController.js +15 -7
  2. package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +22 -26
  3. package/dist/lib.cjs/Eip5792/walletGetCallsStatus.js +2 -2
  4. package/dist/lib.cjs/Eip5792/walletSendCalls.js +6 -7
  5. package/dist/lib.cjs/Eip7702/eip7702Utils.js +3 -3
  6. package/dist/lib.cjs/Gas/GasFeeController.js +2 -2
  7. package/dist/lib.cjs/Keyring/KeyringController.js +68 -41
  8. package/dist/lib.cjs/Message/utils.js +14 -16
  9. package/dist/lib.cjs/Network/NetworkController.js +7 -9
  10. package/dist/lib.cjs/Network/createEthereumMiddleware.js +373 -285
  11. package/dist/lib.cjs/Network/createJsonRpcClient.js +21 -21
  12. package/dist/lib.cjs/Nfts/NftHandler.js +54 -12
  13. package/dist/lib.cjs/Nfts/NftsController.js +1 -4
  14. package/dist/lib.cjs/Preferences/PreferencesController.js +2 -2
  15. package/dist/lib.cjs/Tokens/TokenHandler.js +39 -7
  16. package/dist/lib.cjs/Tokens/TokensController.js +15 -7
  17. package/dist/lib.cjs/Transaction/TransactionController.js +17 -20
  18. package/dist/lib.cjs/Transaction/TransactionGasUtil.js +11 -12
  19. package/dist/lib.cjs/Transaction/TransactionUtils.js +44 -39
  20. package/dist/lib.cjs/index.js +9 -0
  21. package/dist/lib.cjs/types/Account/AccountTrackerController.d.ts +1 -1
  22. package/dist/lib.cjs/types/AccountAbstraction/AccountAbstractionController.d.ts +4 -6
  23. package/dist/lib.cjs/types/Eip5792/walletSendCalls.d.ts +1 -1
  24. package/dist/lib.cjs/types/Eip7702/walletUpgradeAccount.d.ts +1 -1
  25. package/dist/lib.cjs/types/Keyring/KeyringController.d.ts +4 -4
  26. package/dist/lib.cjs/types/Network/NetworkController.d.ts +1 -1
  27. package/dist/lib.cjs/types/Network/createEthereumMiddleware.d.ts +28 -90
  28. package/dist/lib.cjs/types/Network/createJsonRpcClient.d.ts +4 -4
  29. package/dist/lib.cjs/types/Network/index.d.ts +5 -0
  30. package/dist/lib.cjs/types/Network/interfaces.d.ts +58 -0
  31. package/dist/lib.cjs/types/Nfts/NftHandler.d.ts +4 -3
  32. package/dist/lib.cjs/types/Nfts/NftsController.d.ts +0 -1
  33. package/dist/lib.cjs/types/Tokens/TokenHandler.d.ts +4 -3
  34. package/dist/lib.cjs/types/Tokens/TokensController.d.ts +1 -1
  35. package/dist/lib.cjs/types/Transaction/TransactionUtils.d.ts +11 -3
  36. package/dist/lib.cjs/types/index.d.ts +1 -3
  37. package/dist/lib.cjs/types/utils/abis.d.ts +544 -99
  38. package/dist/lib.cjs/types/utils/eip5792Types.d.ts +1 -1
  39. package/dist/lib.cjs/types/utils/eip7702Types.d.ts +1 -1
  40. package/dist/lib.cjs/types/utils/interfaces.d.ts +207 -4
  41. package/dist/lib.cjs/types/utils/transaction.d.ts +1 -1
  42. package/dist/lib.cjs/types/utils/viem.d.ts +8 -0
  43. package/dist/lib.cjs/utils/abis.js +12 -0
  44. package/dist/lib.cjs/utils/conversionUtils.js +3 -4
  45. package/dist/lib.cjs/utils/helpers.js +8 -7
  46. package/dist/lib.cjs/utils/transaction.js +7 -11
  47. package/dist/lib.cjs/utils/viem.js +214 -0
  48. package/dist/lib.esm/Account/AccountTrackerController.js +15 -7
  49. package/dist/lib.esm/AccountAbstraction/AccountAbstractionController.js +24 -28
  50. package/dist/lib.esm/Eip5792/walletGetCallsStatus.js +2 -2
  51. package/dist/lib.esm/Eip5792/walletSendCalls.js +6 -7
  52. package/dist/lib.esm/Eip7702/eip7702Utils.js +3 -3
  53. package/dist/lib.esm/Gas/GasFeeController.js +2 -2
  54. package/dist/lib.esm/Keyring/KeyringController.js +68 -42
  55. package/dist/lib.esm/Message/utils.js +14 -16
  56. package/dist/lib.esm/Network/NetworkController.js +8 -10
  57. package/dist/lib.esm/Network/createEthereumMiddleware.js +387 -290
  58. package/dist/lib.esm/Network/createJsonRpcClient.js +22 -22
  59. package/dist/lib.esm/Nfts/NftHandler.js +54 -12
  60. package/dist/lib.esm/Nfts/NftsController.js +1 -4
  61. package/dist/lib.esm/Preferences/PreferencesController.js +2 -2
  62. package/dist/lib.esm/Tokens/TokenHandler.js +39 -7
  63. package/dist/lib.esm/Tokens/TokensController.js +15 -7
  64. package/dist/lib.esm/Transaction/TransactionController.js +18 -21
  65. package/dist/lib.esm/Transaction/TransactionGasUtil.js +11 -12
  66. package/dist/lib.esm/Transaction/TransactionUtils.js +44 -40
  67. package/dist/lib.esm/index.js +4 -3
  68. package/dist/lib.esm/utils/abis.js +12 -0
  69. package/dist/lib.esm/utils/conversionUtils.js +3 -4
  70. package/dist/lib.esm/utils/helpers.js +8 -7
  71. package/dist/lib.esm/utils/interfaces.js +64 -0
  72. package/dist/lib.esm/utils/transaction.js +7 -11
  73. package/dist/lib.esm/utils/viem.js +214 -0
  74. package/package.json +14 -19
  75. package/dist/ethereumControllers.umd.min.js +0 -2
  76. package/dist/ethereumControllers.umd.min.js.LICENSE.txt +0 -50
@@ -1,34 +1,31 @@
1
1
  'use strict';
2
2
 
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
- var util = require('@ethereumjs/util');
5
4
  var baseControllers = require('@toruslabs/base-controllers');
5
+ var metadataHelpers = require('@toruslabs/metadata-helpers');
6
6
  var auth = require('@web3auth/auth');
7
- var ethers = require('ethers');
8
7
  var log = require('loglevel');
8
+ var viem = require('viem');
9
9
  var abis = require('../utils/abis.js');
10
10
  var constants = require('../utils/constants.js');
11
11
 
12
- const erc20Interface = new ethers.Interface(abis.erc20Abi);
13
- const erc721Interface = new ethers.Interface(abis.erc721Abi);
14
- const erc1155Interface = new ethers.Interface(abis.erc1155Abi);
15
12
  const normalizers = {
16
- from: (from, LowerCase = true) => LowerCase ? util.addHexPrefix(from).toLowerCase() : util.addHexPrefix(from),
17
- to: (to, LowerCase = true) => LowerCase ? util.addHexPrefix(to).toLowerCase() : util.addHexPrefix(to),
18
- nonce: nonce => util.addHexPrefix(nonce),
19
- customNonceValue: nonce => util.addHexPrefix(nonce),
20
- value: value => util.addHexPrefix(value),
21
- data: data => util.addHexPrefix(data),
22
- gas: gas => util.addHexPrefix(gas),
23
- gasPrice: gasPrice => util.addHexPrefix(gasPrice),
24
- type: util.addHexPrefix,
25
- maxFeePerGas: util.addHexPrefix,
26
- maxPriorityFeePerGas: util.addHexPrefix,
27
- callGasLimit: util.addHexPrefix,
28
- preVerificationGas: util.addHexPrefix,
29
- verificationGasLimit: util.addHexPrefix,
30
- paymasterVerificationGasLimit: util.addHexPrefix,
31
- paymasterPostOpGasLimit: util.addHexPrefix,
13
+ from: (from, LowerCase = true) => LowerCase ? metadataHelpers.add0x(from).toLowerCase() : metadataHelpers.add0x(from),
14
+ to: (to, LowerCase = true) => LowerCase ? metadataHelpers.add0x(to).toLowerCase() : metadataHelpers.add0x(to),
15
+ nonce: nonce => metadataHelpers.add0x(nonce),
16
+ customNonceValue: nonce => metadataHelpers.add0x(nonce),
17
+ value: value => metadataHelpers.add0x(value),
18
+ data: data => metadataHelpers.add0x(data),
19
+ gas: gas => metadataHelpers.add0x(gas),
20
+ gasPrice: gasPrice => metadataHelpers.add0x(gasPrice),
21
+ type: metadataHelpers.add0x,
22
+ maxFeePerGas: metadataHelpers.add0x,
23
+ maxPriorityFeePerGas: metadataHelpers.add0x,
24
+ callGasLimit: metadataHelpers.add0x,
25
+ preVerificationGas: metadataHelpers.add0x,
26
+ verificationGasLimit: metadataHelpers.add0x,
27
+ paymasterVerificationGasLimit: metadataHelpers.add0x,
28
+ paymasterPostOpGasLimit: metadataHelpers.add0x,
32
29
  authorizationList: authorizationList => authorizationList
33
30
  };
34
31
  /**
@@ -62,7 +59,9 @@ function transactionMatchesNetwork(transaction, chainId) {
62
59
  */
63
60
  function isEIP1559Transaction(transaction) {
64
61
  var _transaction$transact, _transaction$transact2;
65
- return util.isHexString(util.addHexPrefix(transaction === null || transaction === void 0 || (_transaction$transact = transaction.transaction) === null || _transaction$transact === void 0 ? void 0 : _transaction$transact.maxFeePerGas)) && util.isHexString(util.addHexPrefix(transaction === null || transaction === void 0 || (_transaction$transact2 = transaction.transaction) === null || _transaction$transact2 === void 0 ? void 0 : _transaction$transact2.maxPriorityFeePerGas));
62
+ const maxFeePerGas = transaction === null || transaction === void 0 || (_transaction$transact = transaction.transaction) === null || _transaction$transact === void 0 ? void 0 : _transaction$transact.maxFeePerGas;
63
+ const maxPriorityFeePerGas = transaction === null || transaction === void 0 || (_transaction$transact2 = transaction.transaction) === null || _transaction$transact2 === void 0 ? void 0 : _transaction$transact2.maxPriorityFeePerGas;
64
+ return typeof maxFeePerGas === "string" && typeof maxPriorityFeePerGas === "string" && viem.isHex(metadataHelpers.add0x(maxFeePerGas)) && viem.isHex(metadataHelpers.add0x(maxPriorityFeePerGas));
66
65
  }
67
66
  /**
68
67
  * Determine if the maxFeePerGas and maxPriorityFeePerGas fields are not
@@ -74,7 +73,7 @@ function isEIP1559Transaction(transaction) {
74
73
  * EIP1559 fields
75
74
  */
76
75
  function isLegacyTransaction(transaction) {
77
- return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" || util.isHexString(util.addHexPrefix(transaction.transaction.gasPrice)));
76
+ return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" || viem.isHex(metadataHelpers.add0x(transaction.transaction.gasPrice)));
78
77
  }
79
78
  /**
80
79
  * Given two fields, ensure that the second field is not included in txParams,
@@ -121,7 +120,7 @@ function validateFrom(txParams) {
121
120
  if (!(typeof txParams.from === "string")) {
122
121
  throw auth.rpcErrors.invalidParams(`Invalid "from" address "${txParams.from}": not a string.`);
123
122
  }
124
- if (!util.isValidAddress(txParams.from)) {
123
+ if (!viem.isAddress(txParams.from)) {
125
124
  throw auth.rpcErrors.invalidParams('Invalid "from" address.');
126
125
  }
127
126
  }
@@ -135,7 +134,7 @@ function validateRecipient(txParameters) {
135
134
  } else {
136
135
  throw auth.rpcErrors.invalidParams('Invalid "to" address.');
137
136
  }
138
- } else if (txParameters.to !== undefined && !util.isValidAddress(txParameters.to)) {
137
+ } else if (txParameters.to !== undefined && !viem.isAddress(txParameters.to)) {
139
138
  throw auth.rpcErrors.invalidParams('Invalid "to" address.');
140
139
  }
141
140
  return txParameters;
@@ -203,10 +202,10 @@ function validateTxParameters(txParams, eip1559Compatibility = true) {
203
202
  if (typeof authorization !== "object" || authorization === null) {
204
203
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: ${key} is not an object. got: (${authorization})`);
205
204
  }
206
- if (typeof authorization.address !== "string" || !util.isValidAddress(authorization.address)) {
205
+ if (typeof authorization.address !== "string" || !viem.isAddress(authorization.address)) {
207
206
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: authorization.address is not a valid address. got: (${authorization.address})`);
208
207
  }
209
- if (typeof authorization.chainId !== "string" || !util.isHexString(util.addHexPrefix(authorization.chainId))) {
208
+ if (typeof authorization.chainId !== "string" || !viem.isHex(metadataHelpers.add0x(authorization.chainId))) {
210
209
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: authorization.chainId is not a valid hex string. got: (${authorization.chainId})`);
211
210
  }
212
211
  });
@@ -236,36 +235,42 @@ function getFinalStates() {
236
235
  }
237
236
  function parseStandardTokenTransactionData(data) {
238
237
  try {
239
- const txDesc = erc20Interface.parseTransaction({
240
- data
238
+ var _txDesc$args;
239
+ const txDesc = viem.decodeFunctionData({
240
+ abi: abis.erc20Abi,
241
+ data: data
241
242
  });
242
243
  if (txDesc) return {
243
- name: txDesc.name,
244
- methodParams: txDesc.args.toArray(),
244
+ name: txDesc.functionName,
245
+ methodParams: [...((_txDesc$args = txDesc.args) !== null && _txDesc$args !== void 0 ? _txDesc$args : [])],
245
246
  type: constants.CONTRACT_TYPE_ERC20
246
247
  };
247
248
  } catch {
248
249
  // ignore and next try to parse with erc721 ABI
249
250
  }
250
251
  try {
251
- const txDesc = erc721Interface.parseTransaction({
252
- data
252
+ var _txDesc$args2;
253
+ const txDesc = viem.decodeFunctionData({
254
+ abi: abis.erc721Abi,
255
+ data: data
253
256
  });
254
257
  if (txDesc) return {
255
- name: txDesc.name,
256
- methodParams: txDesc.args.toArray(),
258
+ name: txDesc.functionName,
259
+ methodParams: [...((_txDesc$args2 = txDesc.args) !== null && _txDesc$args2 !== void 0 ? _txDesc$args2 : [])],
257
260
  type: constants.CONTRACT_TYPE_ERC721
258
261
  };
259
262
  } catch {
260
263
  // ignore and next try to parse with erc1155 ABI
261
264
  }
262
265
  try {
263
- const txDesc = erc1155Interface.parseTransaction({
264
- data
266
+ var _txDesc$args3;
267
+ const txDesc = viem.decodeFunctionData({
268
+ abi: abis.erc1155Abi,
269
+ data: data
265
270
  });
266
271
  if (txDesc) return {
267
- name: txDesc.name,
268
- methodParams: txDesc.args.toArray(),
272
+ name: txDesc.functionName,
273
+ methodParams: [...((_txDesc$args3 = txDesc.args) !== null && _txDesc$args3 !== void 0 ? _txDesc$args3 : [])],
269
274
  type: constants.CONTRACT_TYPE_ERC1155
270
275
  };
271
276
  } catch {
@@ -22,6 +22,7 @@ var PersonalMessageController = require('./Message/PersonalMessageController.js'
22
22
  var SwitchChainController = require('./Message/SwitchChainController.js');
23
23
  var TypedMessageController = require('./Message/TypedMessageController.js');
24
24
  var utils = require('./Message/utils.js');
25
+ var cacheIdentifier = require('./Network/cacheIdentifier.js');
25
26
  var createEthereumMiddleware = require('./Network/createEthereumMiddleware.js');
26
27
  var createJsonRpcClient = require('./Network/createJsonRpcClient.js');
27
28
  var NetworkController = require('./Network/NetworkController.js');
@@ -85,11 +86,19 @@ exports.validateAddress = utils.validateAddress;
85
86
  exports.validateSignMessageData = utils.validateSignMessageData;
86
87
  exports.validateSwitchChainData = utils.validateSwitchChainData;
87
88
  exports.validateTypedSignMessageDataV4 = utils.validateTypedSignMessageDataV4;
89
+ Object.defineProperty(exports, "CacheStrategy", {
90
+ enumerable: true,
91
+ get: function () { return cacheIdentifier.CacheStrategy; }
92
+ });
93
+ exports.blockTagParamIndex = cacheIdentifier.blockTagParamIndex;
94
+ exports.cacheIdentifierForRequest = cacheIdentifier.cacheIdentifierForRequest;
95
+ exports.cacheTypeForMethod = cacheIdentifier.cacheTypeForMethod;
88
96
  exports.createAAMiddleware = createEthereumMiddleware.createAAMiddleware;
89
97
  exports.createEip5792Middleware = createEthereumMiddleware.createEip5792Middleware;
90
98
  exports.createEip7702Middleware = createEthereumMiddleware.createEip7702Middleware;
91
99
  exports.createEthereumMiddleware = createEthereumMiddleware.createEthereumMiddleware;
92
100
  exports.createGetAccountsMiddleware = createEthereumMiddleware.createGetAccountsMiddleware;
101
+ exports.createGetProviderStateMiddleware = createEthereumMiddleware.createGetProviderStateMiddleware;
93
102
  exports.createPendingNonceMiddleware = createEthereumMiddleware.createPendingNonceMiddleware;
94
103
  exports.createPendingTxMiddleware = createEthereumMiddleware.createPendingTxMiddleware;
95
104
  exports.createProcessAddEthereumChain = createEthereumMiddleware.createProcessAddEthereumChain;
@@ -23,7 +23,7 @@ export declare class AccountTrackerController extends BaseController<AccountTrac
23
23
  private provider;
24
24
  private blockTracker;
25
25
  private mutex;
26
- private ethersProvider;
26
+ private publicClient;
27
27
  private getIdentities;
28
28
  private getCurrentChainId;
29
29
  constructor({ config, state, provider, blockTracker, getIdentities, onPreferencesStateChange, getCurrentChainId, }: AccountTrackerControllerOptions);
@@ -1,5 +1,5 @@
1
1
  import { type BaseConfig, BaseController, type BaseState, TransactionStatus } from "@toruslabs/base-controllers";
2
- import { JRPCMiddleware, type JRPCRequest, type JRPCResponse, type SafeEventEmitterProvider } from "@web3auth/auth";
2
+ import { type JRPCMiddlewareV2, type JRPCRequest, type Json, type SafeEventEmitterProvider } from "@web3auth/auth";
3
3
  import { type BundlerClient, type SmartAccount } from "viem/account-abstraction";
4
4
  import { type NetworkController } from "../Network/NetworkController";
5
5
  import type { BundlerConfig, EthereumNetworkState, ISmartAccount, PaymasterConfig, SignTypedDataMessageV4, SmartAccountType, TransactionParams, UserOperationGas } from "../utils/interfaces";
@@ -30,8 +30,8 @@ export interface AccountAbstractionControllerConfig extends BaseConfig {
30
30
  smartAccountInit?: ISmartAccount;
31
31
  chainId?: string;
32
32
  }
33
- export declare const eoaInterceptorMiddleware: (eoaAddress: string) => (req: JRPCRequest<unknown>, res: JRPCResponse<unknown>, next: () => void, end: () => void) => void;
34
- export declare function eoaProviderAsMiddleware(provider: SafeEventEmitterProvider): JRPCMiddleware<unknown, unknown>;
33
+ export declare const eoaInterceptorMiddleware: (eoaAddress: string) => JRPCMiddlewareV2<JRPCRequest, Json>;
34
+ export declare function eoaProviderAsMiddleware(provider: SafeEventEmitterProvider): JRPCMiddlewareV2<JRPCRequest, Json>;
35
35
  export declare class AccountAbstractionController extends BaseController<AccountAbstractionControllerConfig, AccountAbstractionControllerState> {
36
36
  private _smartAccount;
37
37
  private _publicClient;
@@ -52,8 +52,6 @@ export declare class AccountAbstractionController extends BaseController<Account
52
52
  estimateGas(txParams: TransactionParams, address: string): Promise<UserOperationGas>;
53
53
  signMessage(message: string, address: string): Promise<string>;
54
54
  signPersonalMessage(message: string, address: string): Promise<string>;
55
- signTypedData(data: SignTypedDataMessageV4 & {
56
- primaryType: string;
57
- }, address: string): Promise<string>;
55
+ signTypedData(data: SignTypedDataMessageV4, address: string): Promise<string>;
58
56
  private updateUserOpMeta;
59
57
  }
@@ -1,5 +1,5 @@
1
1
  import { JRPCRequest } from "@web3auth/auth";
2
- import { IProviderHandlers } from "../Network/createEthereumMiddleware";
2
+ import { IProviderHandlers } from "../Network/interfaces";
3
3
  import { BatchTransactionParams, Eip5792SendCallsParams } from "../utils/eip5792Types";
4
4
  import { GetEthCodeFn } from "../utils/interfaces";
5
5
  export interface WalletSendCallsContext {
@@ -1,5 +1,5 @@
1
1
  import { JRPCRequest } from "@web3auth/auth";
2
- import { IProviderHandlers } from "../Network/createEthereumMiddleware";
2
+ import { IProviderHandlers } from "../Network/interfaces";
3
3
  import { Eip7702Params } from "../utils/eip7702Types";
4
4
  import { GetEthCodeFn } from "../utils/interfaces";
5
5
  /**
@@ -9,11 +9,11 @@ export declare class KeyringController extends BaseKeyringController<Partial<Bas
9
9
  signTransaction<T, U>(tx: T, address: string): Promise<U>;
10
10
  signEip7702Authorization(authorization: UnsignedAuthorization, address: string): Promise<Required<Authorization>>;
11
11
  getAccounts(): string[];
12
- importAccount(accountPrivateKey: string): string;
12
+ importAccount(accountPrivateKey: string): Promise<string>;
13
13
  removeAccount(address: string): void;
14
- getBufferPrivateKey(privateKey: string): Buffer<ArrayBuffer>;
14
+ getPrivateKeyBytes(privateKey: string): Uint8Array;
15
15
  signMessage(data: string, address: string): Promise<string>;
16
- signPersonalMessage(data: string, address: string): Promise<string>;
17
- signTypedData(typedData: SignTypedDataMessageV4, address: string): Promise<string>;
16
+ signPersonalMessage(data: string, address: string): Promise<`0x${string}`>;
17
+ signTypedData(typedData: SignTypedDataMessageV4, address: string): Promise<`0x${string}`>;
18
18
  private _getWalletForAccount;
19
19
  }
@@ -2,7 +2,7 @@ import { type Analytics, BaseController, IdleTimeTracker, INetworkController } f
2
2
  import { SafeEventEmitterProvider } from "@web3auth/auth";
3
3
  import { PollingBlockTracker } from "../Block/PollingBlockTracker";
4
4
  import { EthereumNetworkConfig, EthereumNetworkState, EthereumProviderConfig, NetworkControllerEvents } from "../utils/interfaces";
5
- import { IProviderHandlers } from "./createEthereumMiddleware";
5
+ import { IProviderHandlers } from "./interfaces";
6
6
  export declare class NetworkController extends BaseController<EthereumNetworkConfig, EthereumNetworkState, NetworkControllerEvents<EthereumNetworkState>> implements INetworkController<EthereumNetworkConfig, EthereumNetworkState> {
7
7
  name: string;
8
8
  providerProxy: SafeEventEmitterProvider;
@@ -1,131 +1,69 @@
1
- import { type Analytics, InPageWalletProviderState, MessageParams, type ProviderConfig, SwitchChainMessageParams, UserRequestApprovalParams } from "@toruslabs/base-controllers";
2
- import { JRPCEngineEndCallback, JRPCEngineNextCallback, JRPCMiddleware, JRPCRequest, JRPCResponse } from "@web3auth/auth";
1
+ import { type Analytics, InPageWalletProviderState, type ProviderConfig } from "@toruslabs/base-controllers";
2
+ import { type JRPCMiddlewareV2, type JRPCRequest } from "@web3auth/auth";
3
3
  import { TransactionStateManager } from "../Transaction/TransactionStateManager";
4
- import { Eip5792SendCallsParams, TransactionBatchRequest } from "../utils/eip5792Types";
5
- import { AddChainMessageParams, BlockParams, EthereumTransactionMeta, GetEthCodeFn, TransactionParams, TransactionRPCMeta, TypedMessageParams, UserOperationGas } from "../utils/interfaces";
6
- export interface IProviderHandlers {
7
- version: string;
8
- aaConfig?: {
9
- bundlerUrl: string;
10
- paymasterUrl?: string;
11
- };
12
- requestAccounts?: (req: JRPCRequest<string[]>) => Promise<string[]>;
13
- getAccounts: (req: JRPCRequest<string[]>) => Promise<string[]>;
14
- getPrivateKey?: (req: JRPCRequest<unknown>) => Promise<string>;
15
- getPublicKey?: (req: JRPCRequest<unknown>) => Promise<string>;
16
- processTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
17
- processTransactionBatch?: (batchRequest: TransactionBatchRequest, req: JRPCRequest<Eip5792SendCallsParams>) => Promise<string>;
18
- processSignTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
19
- processEthSignMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
20
- processTypedMessageV4?: (msgParams: TypedMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
21
- processPersonalMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
22
- processSwitchEthereumChain?: (msgParams: SwitchChainMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
23
- processWalletSwitchChain?: (msgParams: SwitchChainMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
24
- processAddEthereumChain?: (msgParams: AddChainMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
25
- processEstimateUserOperationGas?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams>) => Promise<UserOperationGas>;
26
- getPendingNonce?: (nonceParams: {
27
- address: string;
28
- blockReference: string;
29
- }, req: JRPCRequest<{
30
- address: string;
31
- blockReference: string;
32
- }>) => Promise<string>;
33
- getPendingTransactionByHash?: (hash: string, req: JRPCRequest<string>) => Promise<EthereumTransactionMeta>;
34
- getTransactionByBatchId: TransactionStateManager["getTransactionByBatchId"];
35
- getProviderState: (req: JRPCRequest<[]>, res: JRPCResponse<InPageWalletProviderState>, next: JRPCEngineNextCallback, end: JRPCEngineEndCallback) => void;
36
- /**
37
- * Query the deployment bytecode of an address. (eth_getCode)
38
- */
39
- getEthCode?: GetEthCodeFn;
40
- /**
41
- * EIP-5792 configuration for wallet capabilities and batch calls.
42
- */
43
- eip5792Config?: {
44
- /**
45
- * Get the list of supported chain IDs for EIP-5792/EIP-7702.
46
- */
47
- getSupportedChains: () => `0x${string}`[];
48
- /**
49
- * Get cached delegation addresses.
50
- * Key format: `${walletAddress}-${chainId}`
51
- */
52
- getCachedDelegations?: () => Record<string, `0x${string}` | null>;
53
- /**
54
- * Update the delegation cache.
55
- */
56
- updateDelegationCache?: (walletAddress: `0x${string}`, chainId: `0x${string}`, delegation: `0x${string}` | null) => void;
57
- };
58
- }
59
- export declare function createGetAccountsMiddleware({ getAccounts }: {
4
+ import { EthereumTransactionMeta, GetEthCodeFn, TransactionRPCMeta, UserOperationGas } from "../utils/interfaces";
5
+ import { IProviderHandlers } from "./interfaces";
6
+ export declare function formatTxMetaForRpcResult(txMeta: EthereumTransactionMeta): TransactionRPCMeta;
7
+ export declare function createGetProviderStateMiddleware({ getProviderState, }: {
8
+ getProviderState: IProviderHandlers["getProviderState"];
9
+ }): JRPCMiddlewareV2<JRPCRequest, InPageWalletProviderState>;
10
+ export declare function createGetAccountsMiddleware({ getAccounts, }: {
60
11
  getAccounts: IProviderHandlers["getAccounts"];
61
- }): JRPCMiddleware<never, string[]>;
12
+ }): JRPCMiddlewareV2<JRPCRequest, string[]>;
62
13
  export declare function createProcessTransactionMiddleware({ processTransaction, }: {
63
14
  processTransaction: IProviderHandlers["processTransaction"];
64
- }): JRPCMiddleware<TransactionParams, string>;
15
+ }): JRPCMiddlewareV2<JRPCRequest, string>;
65
16
  export declare function createProcessSignTransactionMiddleware({ processSignTransaction, }: {
66
- processSignTransaction: IProviderHandlers["processTransaction"];
67
- }): JRPCMiddleware<TransactionParams, string>;
17
+ processSignTransaction: IProviderHandlers["processSignTransaction"];
18
+ }): JRPCMiddlewareV2<JRPCRequest, string>;
68
19
  export declare function createProcessEstimateUserOperationGasMiddleware({ processEstimateUserOperationGas, }: {
69
20
  processEstimateUserOperationGas: IProviderHandlers["processEstimateUserOperationGas"];
70
- }): JRPCMiddleware<TransactionParams, string | UserOperationGas>;
21
+ }): JRPCMiddlewareV2<JRPCRequest, UserOperationGas>;
71
22
  export declare function createProcessEthSignMessage({ processEthSignMessage, }: {
72
23
  processEthSignMessage: IProviderHandlers["processEthSignMessage"];
73
- }): JRPCMiddleware<unknown, string>;
24
+ }): JRPCMiddlewareV2<JRPCRequest, string>;
74
25
  export declare function createProcessTypedMessageV4({ processTypedMessageV4, }: {
75
26
  processTypedMessageV4: IProviderHandlers["processTypedMessageV4"];
76
- }): JRPCMiddleware<unknown, string>;
27
+ }): JRPCMiddlewareV2<JRPCRequest, string>;
77
28
  export declare function createProcessPersonalMessage({ processPersonalMessage, }: {
78
29
  processPersonalMessage: IProviderHandlers["processPersonalMessage"];
79
- }): JRPCMiddleware<unknown, string>;
30
+ }): JRPCMiddlewareV2<JRPCRequest, string>;
80
31
  export declare function createPendingNonceMiddleware({ getPendingNonce, }: {
81
32
  getPendingNonce: IProviderHandlers["getPendingNonce"];
82
- }): JRPCMiddleware<{
83
- address: string;
84
- blockReference: BlockParams;
85
- }, string>;
86
- export declare function formatTxMetaForRpcResult(txMeta: EthereumTransactionMeta): TransactionRPCMeta;
33
+ }): JRPCMiddlewareV2<JRPCRequest, string>;
87
34
  export declare function createPendingTxMiddleware({ getPendingTransactionByHash, }: {
88
35
  getPendingTransactionByHash: IProviderHandlers["getPendingTransactionByHash"];
89
- }): JRPCMiddleware<string, TransactionRPCMeta>;
36
+ }): JRPCMiddlewareV2<JRPCRequest>;
90
37
  export declare function createProcessSwitchEthereumChain({ processSwitchEthereumChain, }: {
91
38
  processSwitchEthereumChain: IProviderHandlers["processSwitchEthereumChain"];
92
- }): JRPCMiddleware<unknown, string>;
39
+ }): JRPCMiddlewareV2<JRPCRequest, string>;
93
40
  export declare function createProcessWalletSwitchChain({ processWalletSwitchChain, }: {
94
41
  processWalletSwitchChain: IProviderHandlers["processWalletSwitchChain"];
95
- }): JRPCMiddleware<unknown, string>;
42
+ }): JRPCMiddlewareV2<JRPCRequest, string>;
96
43
  export declare function createProcessAddEthereumChain({ processAddEthereumChain, }: {
97
44
  processAddEthereumChain: IProviderHandlers["processAddEthereumChain"];
98
- }): JRPCMiddleware<unknown, string>;
45
+ }): JRPCMiddlewareV2<JRPCRequest, string>;
99
46
  export declare function createRequestAccountsMiddleware({ requestAccounts, }: {
100
47
  requestAccounts: IProviderHandlers["requestAccounts"];
101
- }): JRPCMiddleware<string[], unknown>;
48
+ }): JRPCMiddlewareV2<JRPCRequest, string[]>;
102
49
  /**
103
- * Middleware to handle bundler/paymaster rpc method
50
+ * Middleware to handle bundler/paymaster rpc methods.
104
51
  */
105
52
  export declare function createAAMiddleware({ bundlerUrl, paymasterUrl, providerConfig, analytics, }: {
106
53
  bundlerUrl: string;
107
54
  paymasterUrl?: string;
108
55
  providerConfig: ProviderConfig;
109
56
  analytics?: Analytics;
110
- }): JRPCMiddleware<unknown, unknown>;
57
+ }): JRPCMiddlewareV2<JRPCRequest>;
111
58
  /**
112
59
  * Middleware to handle EIP-7702 methods.
113
- *
114
- * @param getEthCode - Function to get the deployment bytecode of an address. (eth_getCode)
115
- * @param processTransaction - Function to process a transaction.
116
- * @returns JRPCMiddleware to handle EIP-7702 methods
117
60
  */
118
61
  export declare function createEip7702Middleware({ getEthCode, processTransaction, }: {
119
62
  getEthCode: GetEthCodeFn;
120
63
  processTransaction: IProviderHandlers["processTransaction"];
121
- }): JRPCMiddleware<unknown, unknown>;
64
+ }): JRPCMiddlewareV2<JRPCRequest>;
122
65
  /**
123
66
  * Middleware to handle EIP-5792 methods.
124
- * Supports wallet capabilities and batch call operations for EIP-7702 upgraded accounts.
125
- *
126
- * @param eip5792Config - Configuration for EIP-5792 handlers.
127
- * @param processTransaction - Function to process a transaction.
128
- * @returns JRPCMiddleware to handle EIP-5792 methods
129
67
  */
130
68
  export declare function createEip5792Middleware({ eip5792Config, processTransaction, processTransactionBatch, getTransactionByBatchId, getEthCode, }: {
131
69
  eip5792Config: IProviderHandlers["eip5792Config"];
@@ -133,5 +71,5 @@ export declare function createEip5792Middleware({ eip5792Config, processTransact
133
71
  processTransactionBatch: IProviderHandlers["processTransactionBatch"];
134
72
  getTransactionByBatchId: TransactionStateManager["getTransactionByBatchId"];
135
73
  getEthCode: GetEthCodeFn;
136
- }): JRPCMiddleware<unknown, unknown>;
137
- export declare function createEthereumMiddleware(providerHandlers: IProviderHandlers, providerConfig?: ProviderConfig, analytics?: Analytics): JRPCMiddleware<unknown, unknown>;
74
+ }): JRPCMiddlewareV2<JRPCRequest>;
75
+ export declare function createEthereumMiddleware(providerHandlers: IProviderHandlers, providerConfig?: ProviderConfig, analytics?: Analytics): JRPCMiddlewareV2<JRPCRequest>;
@@ -1,10 +1,10 @@
1
1
  import { type Analytics, IdleTimeTracker, ProviderConfig } from "@toruslabs/base-controllers";
2
- import { JRPCMiddleware } from "@web3auth/auth";
2
+ import { JRPCMiddlewareV2, JRPCRequest } from "@web3auth/auth";
3
3
  import { PollingBlockTracker } from "../Block/PollingBlockTracker";
4
4
  import { EthereumNetworkConfig } from "../utils/interfaces";
5
- export declare function createChainIdMiddleware(chainId: string): JRPCMiddleware<unknown, string>;
6
- export declare function createProviderConfigMiddleware(providerConfig: ProviderConfig): JRPCMiddleware<unknown, ProviderConfig>;
5
+ export declare function createChainIdMiddleware(chainId: string): JRPCMiddlewareV2<JRPCRequest>;
6
+ export declare function createProviderConfigMiddleware(providerConfig: ProviderConfig): JRPCMiddlewareV2<JRPCRequest>;
7
7
  export declare function createJsonRpcClient(providerConfig: ProviderConfig, networkConfig: EthereumNetworkConfig, idleTimeTracker?: IdleTimeTracker, analytics?: Analytics): {
8
- networkMiddleware: JRPCMiddleware<unknown, unknown>;
8
+ networkMiddleware: JRPCMiddlewareV2<JRPCRequest>;
9
9
  blockTracker: PollingBlockTracker;
10
10
  };
@@ -0,0 +1,5 @@
1
+ export * from "./cacheIdentifier";
2
+ export * from "./createEthereumMiddleware";
3
+ export * from "./createJsonRpcClient";
4
+ export { type IProviderHandlers } from "./interfaces";
5
+ export { NetworkController } from "./NetworkController";
@@ -0,0 +1,58 @@
1
+ import { InPageWalletProviderState, SwitchChainMessageParams } from "@toruslabs/base-controllers";
2
+ import { JRPCRequest } from "@web3auth/auth";
3
+ import { TransactionStateManager } from "../Transaction/TransactionStateManager";
4
+ import { Eip5792SendCallsParams, TransactionBatchRequest } from "../utils/eip5792Types";
5
+ import { AddChainMessageParams, EthereumTransactionMeta, GetEthCodeFn, MessageParams, TransactionParams, TypedMessageParams, UserOperationGas, UserRequestApprovalParams } from "../utils/interfaces";
6
+ export interface IProviderHandlers {
7
+ version: string;
8
+ aaConfig?: {
9
+ bundlerUrl: string;
10
+ paymasterUrl?: string;
11
+ };
12
+ requestAccounts?: (req: JRPCRequest<string[]>) => Promise<string[]>;
13
+ getAccounts: (req: JRPCRequest<string[]>) => Promise<string[]>;
14
+ getPrivateKey?: (req: JRPCRequest<unknown>) => Promise<string>;
15
+ getPublicKey?: (req: JRPCRequest<unknown>) => Promise<string>;
16
+ processTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
17
+ processTransactionBatch?: (batchRequest: TransactionBatchRequest, req: JRPCRequest<Eip5792SendCallsParams>) => Promise<string>;
18
+ processSignTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
19
+ processEthSignMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
20
+ processTypedMessageV4?: (msgParams: TypedMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
21
+ processPersonalMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
22
+ processSwitchEthereumChain?: (msgParams: SwitchChainMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
23
+ processWalletSwitchChain?: (msgParams: SwitchChainMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
24
+ processAddEthereumChain?: (msgParams: AddChainMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
25
+ processEstimateUserOperationGas?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams>) => Promise<UserOperationGas>;
26
+ getPendingNonce?: (nonceParams: {
27
+ address: string;
28
+ blockReference: string;
29
+ }, req: JRPCRequest<{
30
+ address: string;
31
+ blockReference: string;
32
+ }>) => Promise<string>;
33
+ getPendingTransactionByHash?: (hash: string, req: JRPCRequest<string>) => Promise<EthereumTransactionMeta>;
34
+ getTransactionByBatchId: TransactionStateManager["getTransactionByBatchId"];
35
+ getProviderState: () => Promise<InPageWalletProviderState>;
36
+ /**
37
+ * Query the deployment bytecode of an address. (eth_getCode)
38
+ */
39
+ getEthCode?: GetEthCodeFn;
40
+ /**
41
+ * EIP-5792 configuration for wallet capabilities and batch calls.
42
+ */
43
+ eip5792Config?: {
44
+ /**
45
+ * Get the list of supported chain IDs for EIP-5792/EIP-7702.
46
+ */
47
+ getSupportedChains: () => `0x${string}`[];
48
+ /**
49
+ * Get cached delegation addresses.
50
+ * Key format: `${walletAddress}-${chainId}`
51
+ */
52
+ getCachedDelegations?: () => Record<string, `0x${string}` | null>;
53
+ /**
54
+ * Update the delegation cache.
55
+ */
56
+ updateDelegationCache?: (walletAddress: `0x${string}`, chainId: `0x${string}`, delegation: `0x${string}` | null) => void;
57
+ };
58
+ }
@@ -1,5 +1,5 @@
1
1
  import { CustomNftItemInfo } from "@toruslabs/base-controllers";
2
- import { Provider } from "ethers";
2
+ import { SafeEventEmitterProvider } from "@web3auth/auth";
3
3
  import { EthereumNftInfo as CustomNftInfo } from "../Nfts/INftsController";
4
4
  export interface INftOptions {
5
5
  contractAddress: string;
@@ -11,7 +11,7 @@ export interface INftOptions {
11
11
  nftStandard?: "erc721" | "erc1155";
12
12
  contractDescription?: string;
13
13
  chainId: string;
14
- provider: Provider;
14
+ provider: SafeEventEmitterProvider;
15
15
  }
16
16
  export declare class NftHandler {
17
17
  contractAddress: string;
@@ -23,8 +23,9 @@ export declare class NftHandler {
23
23
  nftStandard: "erc721" | "erc1155";
24
24
  contractDescription?: string;
25
25
  chainId: string;
26
- provider: Provider;
26
+ provider: SafeEventEmitterProvider;
27
27
  isSpecial?: boolean;
28
+ private publicClient;
28
29
  constructor({ chainId, contractAddress, contractImage, contractName, contractSymbol, nftStandard, provider, contractDescription, contractFallbackLogo, contractSupply, }: INftOptions);
29
30
  getNftMetadata(userAddress: string, tokenInfo: Partial<CustomNftItemInfo>): Promise<CustomNftItemInfo>;
30
31
  getContractMetadata(): Promise<Omit<CustomNftInfo, "assets">>;
@@ -17,7 +17,6 @@ export interface INftsControllerOptions {
17
17
  export declare class NftsController extends BaseController<EthereumNftsControllerConfig, EthereumNftsControllerState> implements INftsController<EthereumNftsControllerConfig, EthereumNftsControllerState> {
18
18
  name: string;
19
19
  private provider;
20
- private ethersProvider;
21
20
  private getCustomNfts;
22
21
  private getSimpleHashNfts;
23
22
  private pollingManager;
@@ -1,17 +1,18 @@
1
- import { BrowserProvider, Contract } from "ethers";
1
+ import { SafeEventEmitterProvider } from "@web3auth/auth";
2
2
  export interface ITokenOptions {
3
3
  address: string;
4
4
  symbol: string;
5
5
  decimals: number;
6
6
  name: string;
7
- provider: BrowserProvider;
7
+ provider: SafeEventEmitterProvider;
8
8
  }
9
9
  export declare class TokenHandler {
10
10
  address: string;
11
11
  symbol: string;
12
12
  decimals: number;
13
13
  name: string;
14
- contract: Contract;
14
+ provider: SafeEventEmitterProvider;
15
+ private publicClient;
15
16
  constructor({ address, symbol, decimals, name, provider }: ITokenOptions);
16
17
  getSymbol(): Promise<string>;
17
18
  getDecimals(): Promise<number>;
@@ -19,7 +19,7 @@ export interface ITokensControllerOptions {
19
19
  export declare class TokensController extends BaseController<EthereumTokensControllerConfig, EthereumTokensControllerState> implements ITokensController<EthereumTokensControllerConfig, EthereumTokensControllerState, CustomTokenInfo> {
20
20
  name: string;
21
21
  private provider;
22
- private ethersProvider;
22
+ private publicClient;
23
23
  private pollingManager;
24
24
  private getProviderConfig;
25
25
  private getCustomTokens;
@@ -54,8 +54,16 @@ export declare function normalizeAndValidateTxParams(txParams: TransactionParams
54
54
  */
55
55
  export declare function getFinalStates(): TransactionStatus[];
56
56
  export declare function parseStandardTokenTransactionData(data: string): {
57
- name: string;
58
- methodParams: any[];
57
+ name: "symbol" | "decimals" | "transfer" | "transferFrom" | "approve" | "name" | "totalSupply" | "balanceOf" | "approveAndCall" | "allowance";
58
+ methodParams: (bigint | `0x${string}`)[];
59
+ type: string;
60
+ } | {
61
+ name: "symbol" | "transferFrom" | "approve" | "safeTransferFrom" | "name" | "totalSupply" | "balanceOf" | "supportsInterface" | "getApproved" | "tokenOfOwnerByIndex" | "tokenByIndex" | "ownerOf" | "tokenURI";
62
+ methodParams: (bigint | `0x${string}`)[];
63
+ type: string;
64
+ } | {
65
+ name: "safeTransferFrom" | "setApprovalForAll" | "balanceOf" | "supportsInterface" | "balanceOfBatch" | "isApprovedForAll" | "uri";
66
+ methodParams: (bigint | boolean | `0x${string}` | readonly `0x${string}`[] | readonly bigint[])[];
59
67
  type: string;
60
68
  };
61
69
  export declare const readAddressAsContract: (provider: SafeEventEmitterProvider, address: string) => Promise<{
@@ -65,7 +73,7 @@ export declare const readAddressAsContract: (provider: SafeEventEmitterProvider,
65
73
  export declare function determineTransactionType(txParams: TransactionParams, provider: SafeEventEmitterProvider, overrideTxMeta?: Partial<EthereumTransactionMeta>): Promise<{
66
74
  type: string;
67
75
  category: string;
68
- methodParams: any[];
76
+ methodParams: unknown[];
69
77
  getCodeResponse: string;
70
78
  }>;
71
79
  /**
@@ -15,9 +15,7 @@ export * from "./Message/SwitchChainController";
15
15
  export * from "./Message/TypedMessageController";
16
16
  export * from "./Message/types";
17
17
  export * from "./Message/utils";
18
- export * from "./Network/createEthereumMiddleware";
19
- export * from "./Network/createJsonRpcClient";
20
- export { NetworkController } from "./Network/NetworkController";
18
+ export * from "./Network";
21
19
  export * from "./Nfts/INftsController";
22
20
  export * from "./Nfts/NftHandler";
23
21
  export * from "./Nfts/NftsController";