@toruslabs/ethereum-controllers 9.0.0 → 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 (50) hide show
  1. package/dist/lib.cjs/AccountAbstraction/AccountAbstractionController.js +18 -20
  2. package/dist/lib.cjs/Eip5792/walletGetCallsStatus.js +2 -2
  3. package/dist/lib.cjs/Eip7702/eip7702Utils.js +3 -3
  4. package/dist/lib.cjs/Gas/GasFeeController.js +2 -3
  5. package/dist/lib.cjs/Keyring/KeyringController.js +8 -10
  6. package/dist/lib.cjs/Message/utils.js +3 -6
  7. package/dist/lib.cjs/Network/NetworkController.js +7 -9
  8. package/dist/lib.cjs/Network/createEthereumMiddleware.js +373 -285
  9. package/dist/lib.cjs/Network/createJsonRpcClient.js +21 -21
  10. package/dist/lib.cjs/Preferences/PreferencesController.js +2 -2
  11. package/dist/lib.cjs/Transaction/TransactionController.js +13 -13
  12. package/dist/lib.cjs/Transaction/TransactionGasUtil.js +8 -8
  13. package/dist/lib.cjs/Transaction/TransactionUtils.js +20 -20
  14. package/dist/lib.cjs/index.js +9 -0
  15. package/dist/lib.cjs/types/AccountAbstraction/AccountAbstractionController.d.ts +3 -3
  16. package/dist/lib.cjs/types/Eip5792/walletSendCalls.d.ts +1 -1
  17. package/dist/lib.cjs/types/Eip7702/walletUpgradeAccount.d.ts +1 -1
  18. package/dist/lib.cjs/types/Network/NetworkController.d.ts +1 -1
  19. package/dist/lib.cjs/types/Network/createEthereumMiddleware.d.ts +28 -90
  20. package/dist/lib.cjs/types/Network/createJsonRpcClient.d.ts +4 -4
  21. package/dist/lib.cjs/types/Network/index.d.ts +5 -0
  22. package/dist/lib.cjs/types/Network/interfaces.d.ts +58 -0
  23. package/dist/lib.cjs/types/index.d.ts +1 -3
  24. package/dist/lib.cjs/types/utils/eip5792Types.d.ts +1 -1
  25. package/dist/lib.cjs/types/utils/eip7702Types.d.ts +1 -1
  26. package/dist/lib.cjs/types/utils/interfaces.d.ts +2 -2
  27. package/dist/lib.cjs/utils/conversionUtils.js +2 -2
  28. package/dist/lib.cjs/utils/helpers.js +4 -4
  29. package/dist/lib.cjs/utils/transaction.js +2 -2
  30. package/dist/lib.esm/AccountAbstraction/AccountAbstractionController.js +19 -21
  31. package/dist/lib.esm/Eip5792/walletGetCallsStatus.js +2 -2
  32. package/dist/lib.esm/Eip7702/eip7702Utils.js +3 -3
  33. package/dist/lib.esm/Gas/GasFeeController.js +2 -3
  34. package/dist/lib.esm/Keyring/KeyringController.js +9 -11
  35. package/dist/lib.esm/Message/utils.js +4 -7
  36. package/dist/lib.esm/Network/NetworkController.js +8 -10
  37. package/dist/lib.esm/Network/createEthereumMiddleware.js +387 -290
  38. package/dist/lib.esm/Network/createJsonRpcClient.js +22 -22
  39. package/dist/lib.esm/Preferences/PreferencesController.js +2 -2
  40. package/dist/lib.esm/Transaction/TransactionController.js +13 -13
  41. package/dist/lib.esm/Transaction/TransactionGasUtil.js +8 -8
  42. package/dist/lib.esm/Transaction/TransactionUtils.js +20 -20
  43. package/dist/lib.esm/index.js +4 -3
  44. package/dist/lib.esm/utils/conversionUtils.js +2 -2
  45. package/dist/lib.esm/utils/helpers.js +3 -3
  46. package/dist/lib.esm/utils/transaction.js +2 -2
  47. package/package.json +5 -5
  48. package/dist/lib.cjs/types/utils/hex.d.ts +0 -9
  49. package/dist/lib.cjs/utils/hex.js +0 -23
  50. package/dist/lib.esm/utils/hex.js +0 -21
@@ -8,24 +8,27 @@ var transaction = require('../utils/transaction.js');
8
8
  var cacheIdentifier = require('./cacheIdentifier.js');
9
9
 
10
10
  function createChainIdMiddleware(chainId) {
11
- return (req, res, next, end) => {
12
- if (req.method === "eth_chainId") {
13
- res.result = chainId;
14
- return end();
11
+ return async ({
12
+ request,
13
+ next
14
+ }) => {
15
+ if (request.method === "eth_chainId") {
16
+ return chainId;
15
17
  }
16
- if (req.method === "net_version") {
18
+ if (request.method === "net_version") {
17
19
  // convert to decimal
18
- res.result = Number.parseInt(chainId, 16).toString(10);
19
- return end();
20
+ return Number.parseInt(chainId, 16).toString(10);
20
21
  }
21
22
  return next();
22
23
  };
23
24
  }
24
25
  function createProviderConfigMiddleware(providerConfig) {
25
- return (req, res, next, end) => {
26
- if (req.method === "eth_provider_config") {
27
- res.result = providerConfig;
28
- return end();
26
+ return async ({
27
+ request,
28
+ next
29
+ }) => {
30
+ if (request.method === "eth_provider_config") {
31
+ return providerConfig;
29
32
  }
30
33
  return next();
31
34
  };
@@ -41,7 +44,7 @@ function createJsonRpcClient(providerConfig, networkConfig, idleTimeTracker, ana
41
44
  analytics,
42
45
  transactionDecoder: transaction.transactionDecoder
43
46
  });
44
- const blockProvider = auth.providerFromMiddleware(fetchMiddleware);
47
+ const blockProvider = auth.providerFromMiddlewareV2(fetchMiddleware);
45
48
  const blockTracker = new PollingBlockTracker.PollingBlockTracker({
46
49
  config: _objectSpread(_objectSpread({}, networkConfig), {}, {
47
50
  provider: blockProvider
@@ -49,15 +52,12 @@ function createJsonRpcClient(providerConfig, networkConfig, idleTimeTracker, ana
49
52
  state: {},
50
53
  idleTimeTracker
51
54
  });
52
- const networkMiddleware = auth.mergeMiddleware([createChainIdMiddleware(chainId), createProviderConfigMiddleware(providerConfig),
53
- // No need for the following middlewares for web because all browser sessions are quite short lived and each session is limited to scope of a window/tab
54
- // createBlockRefRewriteMiddleware({ blockTracker }),
55
- // createBlockCacheMiddleware({ blockTracker }),
56
- baseControllers.createInflightCacheMiddleware({
57
- cacheIdentifierForRequest: cacheIdentifier.cacheIdentifierForRequest
58
- }),
59
- // createBlockTrackerInspectorMiddleware({ blockTracker }),
60
- fetchMiddleware]);
55
+ const jrpcEngineV2 = auth.JRPCEngineV2.create({
56
+ middleware: [createChainIdMiddleware(chainId), createProviderConfigMiddleware(providerConfig), baseControllers.createInflightCacheMiddleware({
57
+ cacheIdentifierForRequest: cacheIdentifier.cacheIdentifierForRequest
58
+ }), fetchMiddleware]
59
+ });
60
+ const networkMiddleware = jrpcEngineV2.asMiddleware();
61
61
  return {
62
62
  networkMiddleware,
63
63
  blockTracker
@@ -2,11 +2,11 @@
2
2
 
3
3
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
4
4
  var baseControllers = require('@toruslabs/base-controllers');
5
+ var metadataHelpers = require('@toruslabs/metadata-helpers');
5
6
  var asyncMutex = require('async-mutex');
6
7
  var log = require('loglevel');
7
8
  var constants = require('../utils/constants.js');
8
9
  var helpers = require('../utils/helpers.js');
9
- var hex = require('../utils/hex.js');
10
10
 
11
11
  class PreferencesController extends baseControllers.BasePreferencesController {
12
12
  constructor({
@@ -302,7 +302,7 @@ class PreferencesController extends baseControllers.BasePreferencesController {
302
302
  }
303
303
  isChainIdSupported(address, chainId) {
304
304
  const approveChainOptions = this.getChainOptions(address);
305
- const providerConfig = approveChainOptions.find(x => hex.stripHexPrefix(x.chainId) === chainId);
305
+ const providerConfig = approveChainOptions.find(x => metadataHelpers.remove0x(x.chainId) === chainId);
306
306
  return !!providerConfig;
307
307
  }
308
308
  async addChain(network) {
@@ -3,11 +3,11 @@
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
5
  var baseControllers = require('@toruslabs/base-controllers');
6
+ var metadataHelpers = require('@toruslabs/metadata-helpers');
6
7
  var auth = require('@web3auth/auth');
7
8
  var bignumber_js = require('bignumber.js');
8
9
  var log = require('loglevel');
9
10
  var viem = require('viem');
10
- var hex = require('../utils/hex.js');
11
11
  var eip7702Utils = require('../Eip7702/eip7702Utils.js');
12
12
  var walletSendCalls = require('../Eip5792/walletSendCalls.js');
13
13
  var constants = require('../utils/constants.js');
@@ -130,7 +130,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
130
130
  }
131
131
  txParams.authorizationList = [{
132
132
  address: delegationAddress,
133
- chainId: hex.addHexPrefix(chainId)
133
+ chainId: metadataHelpers.add0x(chainId)
134
134
  }];
135
135
  txParams.type = constants.TRANSACTION_ENVELOPE_TYPES.SET_CODE;
136
136
  }
@@ -181,7 +181,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
181
181
  // higher gas settings and therefor the nonce should not be recalculated
182
182
  const nonce = nonceLock.nextNonce;
183
183
  const customOrNonce = customNonceValueNumber === 0 ? customNonceValue : customNonceValue || nonce;
184
- txMeta.transaction.nonce = hex.addHexPrefix(customOrNonce.toString(16));
184
+ txMeta.transaction.nonce = metadataHelpers.add0x(customOrNonce.toString(16));
185
185
  // add nonce debugging information to txMeta
186
186
  txMeta.nonceDetails = nonceLock.nonceDetails;
187
187
  this.updateTransactionInState(txMeta, "transactions#approveTransaction");
@@ -274,7 +274,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
274
274
  });
275
275
  } catch (error) {
276
276
  if (error.message.toLowerCase().includes("known transaction")) {
277
- txHash = viem.keccak256(hex.addHexPrefix(rawTx));
277
+ txHash = viem.keccak256(metadataHelpers.add0x(rawTx));
278
278
  } else {
279
279
  throw error;
280
280
  }
@@ -350,7 +350,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
350
350
  txMeta.transaction.maxFeePerGas = txMeta.transaction.gasPrice;
351
351
  // If the dapp has suggested a gas price, but no maxFeePerGas or maxPriorityFeePerGas
352
352
  // then we set maxFeePerGas to the suggested gasPrice.
353
- txMeta.transaction.maxPriorityFeePerGas = helpers.bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ? hex.stripHexPrefix(defaultMaxPriorityFeePerGas) : defaultMaxPriorityFeePerGas, typeof txMeta.transaction.gasPrice === "string" ? hex.stripHexPrefix(txMeta.transaction.gasPrice) : txMeta.transaction.gasPrice) ? defaultMaxPriorityFeePerGas : txMeta.transaction.gasPrice;
353
+ txMeta.transaction.maxPriorityFeePerGas = helpers.bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ? metadataHelpers.remove0x(defaultMaxPriorityFeePerGas) : defaultMaxPriorityFeePerGas, typeof txMeta.transaction.gasPrice === "string" ? metadataHelpers.remove0x(txMeta.transaction.gasPrice) : txMeta.transaction.gasPrice) ? defaultMaxPriorityFeePerGas : txMeta.transaction.gasPrice;
354
354
  } else {
355
355
  if (defaultMaxFeePerGas && !txMeta.transaction.maxFeePerGas) {
356
356
  // If the dapp has not set the gasPrice or the maxFeePerGas, then we set maxFeePerGas
@@ -422,8 +422,8 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
422
422
  if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {
423
423
  return {
424
424
  // send to controller in hex wei
425
- maxFeePerGas: hex.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(suggestedMaxFeePerGas)).toString(16)),
426
- maxPriorityFeePerGas: hex.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(suggestedMaxPriorityFeePerGas)).toString(16))
425
+ maxFeePerGas: metadataHelpers.add0x(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(suggestedMaxFeePerGas)).toString(16)),
426
+ maxPriorityFeePerGas: metadataHelpers.add0x(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(suggestedMaxPriorityFeePerGas)).toString(16))
427
427
  };
428
428
  }
429
429
  } else if (gasEstimateType === constants.GAS_ESTIMATE_TYPES.LEGACY) {
@@ -433,7 +433,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
433
433
  // The LEGACY type includes low, medium and high estimates of
434
434
  // gas price values.
435
435
  return {
436
- gasPrice: hex.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(medium)).toString(16))
436
+ gasPrice: metadataHelpers.add0x(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(medium)).toString(16))
437
437
  };
438
438
  } else if (gasEstimateType === constants.GAS_ESTIMATE_TYPES.ETH_GASPRICE) {
439
439
  const {
@@ -442,7 +442,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
442
442
  // The ETH_GASPRICE type just includes a single gas price property,
443
443
  // which we can assume was retrieved from eth_gasPrice
444
444
  return {
445
- gasPrice: hex.addHexPrefix(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(gasPrice)).toString(16))
445
+ gasPrice: metadataHelpers.add0x(conversionUtils.decGWEIToHexWEI(new bignumber_js.BigNumber(gasPrice)).toString(16))
446
446
  };
447
447
  }
448
448
  } catch (error) {
@@ -452,7 +452,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
452
452
  method: constants.METHOD_TYPES.ETH_GET_GAS_PRICE
453
453
  });
454
454
  return {
455
- gasPrice: gasPrice && hex.addHexPrefix(gasPrice)
455
+ gasPrice: gasPrice && metadataHelpers.add0x(gasPrice)
456
456
  };
457
457
  }
458
458
  async getDefaultGasLimit(txMeta) {
@@ -486,9 +486,9 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
486
486
  const baseMultiplier = 1.5;
487
487
  const perCallBuffer = 0.1;
488
488
  const eip7702UpgradeWithDataToSelfGasBufferMultiplier = baseMultiplier + perCallBuffer * batchCallsCount;
489
- gasLimit = this.txGasUtil.addGasBuffer(hex.addHexPrefix(estimatedGasHex), blockGasLimit, eip7702UpgradeWithDataToSelfGasBufferMultiplier);
489
+ gasLimit = this.txGasUtil.addGasBuffer(metadataHelpers.add0x(estimatedGasHex), blockGasLimit, eip7702UpgradeWithDataToSelfGasBufferMultiplier);
490
490
  } else {
491
- gasLimit = this.txGasUtil.addGasBuffer(hex.addHexPrefix(estimatedGasHex), blockGasLimit, customNetworkGasBuffer);
491
+ gasLimit = this.txGasUtil.addGasBuffer(metadataHelpers.add0x(estimatedGasHex), blockGasLimit, customNetworkGasBuffer);
492
492
  }
493
493
  return {
494
494
  gasLimit,
@@ -513,7 +513,7 @@ class TransactionController extends TransactionStateManager.TransactionStateMana
513
513
  txMeta.methodParams = methodParams;
514
514
  txMeta.isUserOperation = req.isUserOperation;
515
515
  txMeta.isSignOnly = req.isSignOnly;
516
- txMeta.transaction.value = txMeta.transaction.value ? hex.addHexPrefix(txMeta.transaction.value) : "0x0";
516
+ txMeta.transaction.value = txMeta.transaction.value ? metadataHelpers.add0x(txMeta.transaction.value) : "0x0";
517
517
  txMeta.batchId = overrideTxMeta === null || overrideTxMeta === void 0 ? void 0 : overrideTxMeta.batchId;
518
518
  txMeta.nestedTransactions = overrideTxMeta === null || overrideTxMeta === void 0 ? void 0 : overrideTxMeta.nestedTransactions;
519
519
  this.emit(`${txMeta.id}:unapproved`, txMeta);
@@ -3,9 +3,9 @@
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var _defineProperty = require('@babel/runtime/helpers/defineProperty');
5
5
  var baseControllers = require('@toruslabs/base-controllers');
6
+ var metadataHelpers = require('@toruslabs/metadata-helpers');
6
7
  var log = require('loglevel');
7
8
  var eip7702Types = require('../utils/eip7702Types.js');
8
- var hex = require('../utils/hex.js');
9
9
  var TransactionUtils = require('./TransactionUtils.js');
10
10
 
11
11
  class TransactionGasUtil {
@@ -18,9 +18,9 @@ class TransactionGasUtil {
18
18
  async analyzeGasUsage(txMeta) {
19
19
  const block = await this.blockTracker.getLatestBlock();
20
20
  // fallback to block gasLimit
21
- const blockGasLimit = BigInt(hex.addHexPrefix(block.gasLimit));
21
+ const blockGasLimit = metadataHelpers.hexToBigInt(block.gasLimit);
22
22
  const saferGasLimit = blockGasLimit * 19n / 20n;
23
- let estimatedGasHex = hex.addHexPrefix(saferGasLimit.toString(16));
23
+ let estimatedGasHex = metadataHelpers.add0x(saferGasLimit.toString(16));
24
24
  let simulationFails;
25
25
  try {
26
26
  estimatedGasHex = await this.estimateTxGas(txMeta);
@@ -45,16 +45,16 @@ class TransactionGasUtil {
45
45
  Adds a gas buffer with out exceeding the block gas limit
46
46
  */
47
47
  addGasBuffer(initialGasLimitHex, blockGasLimitHex, multiplier = 1.5) {
48
- const initialGasLimit = BigInt(hex.addHexPrefix(initialGasLimitHex));
49
- const blockGasLimit = BigInt(hex.addHexPrefix(blockGasLimitHex));
48
+ const initialGasLimit = metadataHelpers.hexToBigInt(initialGasLimitHex);
49
+ const blockGasLimit = metadataHelpers.hexToBigInt(blockGasLimitHex);
50
50
  const upperGasLimit = blockGasLimit * 9n / 10n;
51
51
  const bufferedGasLimit = initialGasLimit * BigInt(Math.round(multiplier * 10)) / 10n;
52
52
  // if initialGasLimit is above blockGasLimit, dont modify it
53
- if (initialGasLimit > upperGasLimit) return hex.addHexPrefix(initialGasLimit.toString(16));
53
+ if (initialGasLimit > upperGasLimit) return metadataHelpers.bigIntToHexPrefixedString(initialGasLimit);
54
54
  // if bufferedGasLimit is below blockGasLimit, use bufferedGasLimit
55
- if (bufferedGasLimit < upperGasLimit) return hex.addHexPrefix(bufferedGasLimit.toString(16));
55
+ if (bufferedGasLimit < upperGasLimit) return metadataHelpers.bigIntToHexPrefixedString(bufferedGasLimit);
56
56
  // otherwise use blockGasLimit
57
- return hex.addHexPrefix(upperGasLimit.toString(16));
57
+ return metadataHelpers.bigIntToHexPrefixedString(upperGasLimit);
58
58
  }
59
59
  /**
60
60
  Estimates the tx's gas usage
@@ -2,30 +2,30 @@
2
2
 
3
3
  var _objectSpread = require('@babel/runtime/helpers/objectSpread2');
4
4
  var baseControllers = require('@toruslabs/base-controllers');
5
+ var metadataHelpers = require('@toruslabs/metadata-helpers');
5
6
  var auth = require('@web3auth/auth');
6
7
  var log = require('loglevel');
7
8
  var viem = require('viem');
8
9
  var abis = require('../utils/abis.js');
9
10
  var constants = require('../utils/constants.js');
10
- var hex = require('../utils/hex.js');
11
11
 
12
12
  const normalizers = {
13
- from: (from, LowerCase = true) => LowerCase ? hex.addHexPrefix(from).toLowerCase() : hex.addHexPrefix(from),
14
- to: (to, LowerCase = true) => LowerCase ? hex.addHexPrefix(to).toLowerCase() : hex.addHexPrefix(to),
15
- nonce: nonce => hex.addHexPrefix(nonce),
16
- customNonceValue: nonce => hex.addHexPrefix(nonce),
17
- value: value => hex.addHexPrefix(value),
18
- data: data => hex.addHexPrefix(data),
19
- gas: gas => hex.addHexPrefix(gas),
20
- gasPrice: gasPrice => hex.addHexPrefix(gasPrice),
21
- type: hex.addHexPrefix,
22
- maxFeePerGas: hex.addHexPrefix,
23
- maxPriorityFeePerGas: hex.addHexPrefix,
24
- callGasLimit: hex.addHexPrefix,
25
- preVerificationGas: hex.addHexPrefix,
26
- verificationGasLimit: hex.addHexPrefix,
27
- paymasterVerificationGasLimit: hex.addHexPrefix,
28
- paymasterPostOpGasLimit: hex.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,
29
29
  authorizationList: authorizationList => authorizationList
30
30
  };
31
31
  /**
@@ -61,7 +61,7 @@ function isEIP1559Transaction(transaction) {
61
61
  var _transaction$transact, _transaction$transact2;
62
62
  const maxFeePerGas = transaction === null || transaction === void 0 || (_transaction$transact = transaction.transaction) === null || _transaction$transact === void 0 ? void 0 : _transaction$transact.maxFeePerGas;
63
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(hex.addHexPrefix(maxFeePerGas)) && viem.isHex(hex.addHexPrefix(maxPriorityFeePerGas));
64
+ return typeof maxFeePerGas === "string" && typeof maxPriorityFeePerGas === "string" && viem.isHex(metadataHelpers.add0x(maxFeePerGas)) && viem.isHex(metadataHelpers.add0x(maxPriorityFeePerGas));
65
65
  }
66
66
  /**
67
67
  * Determine if the maxFeePerGas and maxPriorityFeePerGas fields are not
@@ -73,7 +73,7 @@ function isEIP1559Transaction(transaction) {
73
73
  * EIP1559 fields
74
74
  */
75
75
  function isLegacyTransaction(transaction) {
76
- return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" || viem.isHex(hex.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)));
77
77
  }
78
78
  /**
79
79
  * Given two fields, ensure that the second field is not included in txParams,
@@ -205,7 +205,7 @@ function validateTxParameters(txParams, eip1559Compatibility = true) {
205
205
  if (typeof authorization.address !== "string" || !viem.isAddress(authorization.address)) {
206
206
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: authorization.address is not a valid address. got: (${authorization.address})`);
207
207
  }
208
- if (typeof authorization.chainId !== "string" || !viem.isHex(hex.addHexPrefix(authorization.chainId))) {
208
+ if (typeof authorization.chainId !== "string" || !viem.isHex(metadataHelpers.add0x(authorization.chainId))) {
209
209
  throw auth.rpcErrors.invalidParams(`Invalid transaction params: authorization.chainId is not a valid hex string. got: (${authorization.chainId})`);
210
210
  }
211
211
  });
@@ -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;
@@ -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;
@@ -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
  /**
@@ -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";