@toruslabs/ethereum-controllers 9.0.0 → 9.2.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 +22 -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 +23 -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
@@ -1,29 +1,33 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import { createFetchMiddleware, createInflightCacheMiddleware } from '@toruslabs/base-controllers';
3
- import { providerFromMiddleware, mergeMiddleware } from '@web3auth/auth';
3
+ import { providerFromMiddlewareV2, JRPCEngineV2 } from '@web3auth/auth';
4
4
  import { PollingBlockTracker } from '../Block/PollingBlockTracker.js';
5
5
  import { transactionDecoder } from '../utils/transaction.js';
6
6
  import { cacheIdentifierForRequest } from './cacheIdentifier.js';
7
7
 
8
8
  function createChainIdMiddleware(chainId) {
9
- return (req, res, next, end) => {
10
- if (req.method === "eth_chainId") {
11
- res.result = chainId;
12
- return end();
9
+ return async ({
10
+ request,
11
+ next
12
+ }) => {
13
+ if (request.method === "eth_chainId") {
14
+ return chainId;
13
15
  }
14
- if (req.method === "net_version") {
16
+ if (request.method === "net_version") {
15
17
  // convert to decimal
16
- res.result = Number.parseInt(chainId, 16).toString(10);
17
- return end();
18
+ return Number.parseInt(chainId, 16).toString(10);
18
19
  }
19
20
  return next();
20
21
  };
21
22
  }
22
23
  function createProviderConfigMiddleware(providerConfig) {
23
- return (req, res, next, end) => {
24
- if (req.method === "eth_provider_config") {
25
- res.result = providerConfig;
26
- return end();
24
+ return async ({
25
+ request,
26
+ next
27
+ }) => {
28
+ if (request.method === "eth_provider_config") {
29
+ // can't do the direct cast because `interface ProviderConfig` doesn't satisfy the `Json` type
30
+ return providerConfig;
27
31
  }
28
32
  return next();
29
33
  };
@@ -39,7 +43,7 @@ function createJsonRpcClient(providerConfig, networkConfig, idleTimeTracker, ana
39
43
  analytics,
40
44
  transactionDecoder
41
45
  });
42
- const blockProvider = providerFromMiddleware(fetchMiddleware);
46
+ const blockProvider = providerFromMiddlewareV2(fetchMiddleware);
43
47
  const blockTracker = new PollingBlockTracker({
44
48
  config: _objectSpread(_objectSpread({}, networkConfig), {}, {
45
49
  provider: blockProvider
@@ -47,15 +51,12 @@ function createJsonRpcClient(providerConfig, networkConfig, idleTimeTracker, ana
47
51
  state: {},
48
52
  idleTimeTracker
49
53
  });
50
- const networkMiddleware = mergeMiddleware([createChainIdMiddleware(chainId), createProviderConfigMiddleware(providerConfig),
51
- // 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
52
- // createBlockRefRewriteMiddleware({ blockTracker }),
53
- // createBlockCacheMiddleware({ blockTracker }),
54
- createInflightCacheMiddleware({
55
- cacheIdentifierForRequest
56
- }),
57
- // createBlockTrackerInspectorMiddleware({ blockTracker }),
58
- fetchMiddleware]);
54
+ const jrpcEngineV2 = JRPCEngineV2.create({
55
+ middleware: [createChainIdMiddleware(chainId), createProviderConfigMiddleware(providerConfig), createInflightCacheMiddleware({
56
+ cacheIdentifierForRequest
57
+ }), fetchMiddleware]
58
+ });
59
+ const networkMiddleware = jrpcEngineV2.asMiddleware();
59
60
  return {
60
61
  networkMiddleware,
61
62
  blockTracker
@@ -1,10 +1,10 @@
1
1
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
2
2
  import { BasePreferencesController, CHAIN_NAMESPACES, isUnauthorizedError, TransactionStatus } from '@toruslabs/base-controllers';
3
+ import { remove0x } from '@toruslabs/metadata-helpers';
3
4
  import { Mutex } from 'async-mutex';
4
5
  import log from 'loglevel';
5
6
  import { MM_TOKEN_API_SUPPORTED_CHAINS, SUPPORTED_NETWORKS } from '../utils/constants.js';
6
7
  import { formatPastTx, addEtherscanTransactions, getEthTxStatus, formatTime, formatDate } from '../utils/helpers.js';
7
- import { stripHexPrefix } from '../utils/hex.js';
8
8
 
9
9
  class PreferencesController extends BasePreferencesController {
10
10
  constructor({
@@ -302,7 +302,7 @@ class PreferencesController extends BasePreferencesController {
302
302
  }
303
303
  isChainIdSupported(address, chainId) {
304
304
  const approveChainOptions = this.getChainOptions(address);
305
- const providerConfig = approveChainOptions.find(x => stripHexPrefix(x.chainId) === chainId);
305
+ const providerConfig = approveChainOptions.find(x => remove0x(x.chainId) === chainId);
306
306
  return !!providerConfig;
307
307
  }
308
308
  async addChain(network) {
@@ -1,6 +1,7 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
3
  import { TRANSACTION_TYPES, TX_EVENTS, TransactionStatus } from '@toruslabs/base-controllers';
4
+ import { add0x, remove0x } from '@toruslabs/metadata-helpers';
4
5
  import { rpcErrors, providerErrors } from '@web3auth/auth';
5
6
  import { BigNumber } from 'bignumber.js';
6
7
  import log from 'loglevel';
@@ -9,7 +10,6 @@ import { generateEIP7702BatchTransaction } from '../Eip7702/eip7702Utils.js';
9
10
  import { METHOD_TYPES, TRANSACTION_ENVELOPE_TYPES, CONTRACT_TYPE_ERC7821, GAS_ESTIMATE_TYPES, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP } from '../utils/constants.js';
10
11
  import { decGWEIToHexWEI } from '../utils/conversionUtils.js';
11
12
  import { bnLessThan, getChainType, GAS_LIMITS } from '../utils/helpers.js';
12
- import { addHexPrefix, stripHexPrefix } from '../utils/hex.js';
13
13
  import { TRANSACTION_CATEGORY_EIP7702 } from '../utils/interfaces.js';
14
14
  import { NonceTracker } from './NonceTracker.js';
15
15
  import { PendingTransactionTracker } from './PendingTransactionTracker.js';
@@ -128,7 +128,7 @@ class TransactionController extends TransactionStateManager {
128
128
  }
129
129
  txParams.authorizationList = [{
130
130
  address: delegationAddress,
131
- chainId: addHexPrefix(chainId)
131
+ chainId: add0x(chainId)
132
132
  }];
133
133
  txParams.type = TRANSACTION_ENVELOPE_TYPES.SET_CODE;
134
134
  }
@@ -179,7 +179,7 @@ class TransactionController extends TransactionStateManager {
179
179
  // higher gas settings and therefor the nonce should not be recalculated
180
180
  const nonce = nonceLock.nextNonce;
181
181
  const customOrNonce = customNonceValueNumber === 0 ? customNonceValue : customNonceValue || nonce;
182
- txMeta.transaction.nonce = addHexPrefix(customOrNonce.toString(16));
182
+ txMeta.transaction.nonce = add0x(customOrNonce.toString(16));
183
183
  // add nonce debugging information to txMeta
184
184
  txMeta.nonceDetails = nonceLock.nonceDetails;
185
185
  this.updateTransactionInState(txMeta, "transactions#approveTransaction");
@@ -273,7 +273,7 @@ class TransactionController extends TransactionStateManager {
273
273
  });
274
274
  } catch (error) {
275
275
  if (error.message.toLowerCase().includes("known transaction")) {
276
- txHash = keccak256(addHexPrefix(rawTx));
276
+ txHash = keccak256(add0x(rawTx));
277
277
  } else {
278
278
  throw error;
279
279
  }
@@ -351,7 +351,7 @@ class TransactionController extends TransactionStateManager {
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
353
 
354
- txMeta.transaction.maxPriorityFeePerGas = bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ? stripHexPrefix(defaultMaxPriorityFeePerGas) : defaultMaxPriorityFeePerGas, typeof txMeta.transaction.gasPrice === "string" ? stripHexPrefix(txMeta.transaction.gasPrice) : txMeta.transaction.gasPrice) ? defaultMaxPriorityFeePerGas : txMeta.transaction.gasPrice;
354
+ txMeta.transaction.maxPriorityFeePerGas = bnLessThan(typeof defaultMaxPriorityFeePerGas === "string" ? remove0x(defaultMaxPriorityFeePerGas) : defaultMaxPriorityFeePerGas, typeof txMeta.transaction.gasPrice === "string" ? remove0x(txMeta.transaction.gasPrice) : txMeta.transaction.gasPrice) ? defaultMaxPriorityFeePerGas : txMeta.transaction.gasPrice;
355
355
  } else {
356
356
  if (defaultMaxFeePerGas && !txMeta.transaction.maxFeePerGas) {
357
357
  // If the dapp has not set the gasPrice or the maxFeePerGas, then we set maxFeePerGas
@@ -427,8 +427,8 @@ class TransactionController extends TransactionStateManager {
427
427
  if (suggestedMaxPriorityFeePerGas && suggestedMaxFeePerGas) {
428
428
  return {
429
429
  // send to controller in hex wei
430
- maxFeePerGas: addHexPrefix(decGWEIToHexWEI(new BigNumber(suggestedMaxFeePerGas)).toString(16)),
431
- maxPriorityFeePerGas: addHexPrefix(decGWEIToHexWEI(new BigNumber(suggestedMaxPriorityFeePerGas)).toString(16))
430
+ maxFeePerGas: add0x(decGWEIToHexWEI(new BigNumber(suggestedMaxFeePerGas)).toString(16)),
431
+ maxPriorityFeePerGas: add0x(decGWEIToHexWEI(new BigNumber(suggestedMaxPriorityFeePerGas)).toString(16))
432
432
  };
433
433
  }
434
434
  } else if (gasEstimateType === GAS_ESTIMATE_TYPES.LEGACY) {
@@ -438,7 +438,7 @@ class TransactionController extends TransactionStateManager {
438
438
  // The LEGACY type includes low, medium and high estimates of
439
439
  // gas price values.
440
440
  return {
441
- gasPrice: addHexPrefix(decGWEIToHexWEI(new BigNumber(medium)).toString(16))
441
+ gasPrice: add0x(decGWEIToHexWEI(new BigNumber(medium)).toString(16))
442
442
  };
443
443
  } else if (gasEstimateType === GAS_ESTIMATE_TYPES.ETH_GASPRICE) {
444
444
  const {
@@ -447,7 +447,7 @@ class TransactionController extends TransactionStateManager {
447
447
  // The ETH_GASPRICE type just includes a single gas price property,
448
448
  // which we can assume was retrieved from eth_gasPrice
449
449
  return {
450
- gasPrice: addHexPrefix(decGWEIToHexWEI(new BigNumber(gasPrice)).toString(16))
450
+ gasPrice: add0x(decGWEIToHexWEI(new BigNumber(gasPrice)).toString(16))
451
451
  };
452
452
  }
453
453
  } catch (error) {
@@ -457,7 +457,7 @@ class TransactionController extends TransactionStateManager {
457
457
  method: METHOD_TYPES.ETH_GET_GAS_PRICE
458
458
  });
459
459
  return {
460
- gasPrice: gasPrice && addHexPrefix(gasPrice)
460
+ gasPrice: gasPrice && add0x(gasPrice)
461
461
  };
462
462
  }
463
463
  async getDefaultGasLimit(txMeta) {
@@ -493,9 +493,9 @@ class TransactionController extends TransactionStateManager {
493
493
  const baseMultiplier = 1.5;
494
494
  const perCallBuffer = 0.1;
495
495
  const eip7702UpgradeWithDataToSelfGasBufferMultiplier = baseMultiplier + perCallBuffer * batchCallsCount;
496
- gasLimit = this.txGasUtil.addGasBuffer(addHexPrefix(estimatedGasHex), blockGasLimit, eip7702UpgradeWithDataToSelfGasBufferMultiplier);
496
+ gasLimit = this.txGasUtil.addGasBuffer(add0x(estimatedGasHex), blockGasLimit, eip7702UpgradeWithDataToSelfGasBufferMultiplier);
497
497
  } else {
498
- gasLimit = this.txGasUtil.addGasBuffer(addHexPrefix(estimatedGasHex), blockGasLimit, customNetworkGasBuffer);
498
+ gasLimit = this.txGasUtil.addGasBuffer(add0x(estimatedGasHex), blockGasLimit, customNetworkGasBuffer);
499
499
  }
500
500
  return {
501
501
  gasLimit,
@@ -520,7 +520,7 @@ class TransactionController extends TransactionStateManager {
520
520
  txMeta.methodParams = methodParams;
521
521
  txMeta.isUserOperation = req.isUserOperation;
522
522
  txMeta.isSignOnly = req.isSignOnly;
523
- txMeta.transaction.value = txMeta.transaction.value ? addHexPrefix(txMeta.transaction.value) : "0x0";
523
+ txMeta.transaction.value = txMeta.transaction.value ? add0x(txMeta.transaction.value) : "0x0";
524
524
  txMeta.batchId = overrideTxMeta === null || overrideTxMeta === void 0 ? void 0 : overrideTxMeta.batchId;
525
525
  txMeta.nestedTransactions = overrideTxMeta === null || overrideTxMeta === void 0 ? void 0 : overrideTxMeta.nestedTransactions;
526
526
  this.emit(`${txMeta.id}:unapproved`, txMeta);
@@ -1,9 +1,9 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
3
  import { cloneDeep } from '@toruslabs/base-controllers';
4
+ import { hexToBigInt, add0x, bigIntToHexPrefixedString } from '@toruslabs/metadata-helpers';
4
5
  import log from 'loglevel';
5
6
  import { DUMMY_AUTHORIZATION_SIGNATURE } from '../utils/eip7702Types.js';
6
- import { addHexPrefix } from '../utils/hex.js';
7
7
  import { isEip7702SetCodeTx } from './TransactionUtils.js';
8
8
 
9
9
  class TransactionGasUtil {
@@ -16,9 +16,9 @@ class TransactionGasUtil {
16
16
  async analyzeGasUsage(txMeta) {
17
17
  const block = await this.blockTracker.getLatestBlock();
18
18
  // fallback to block gasLimit
19
- const blockGasLimit = BigInt(addHexPrefix(block.gasLimit));
19
+ const blockGasLimit = hexToBigInt(block.gasLimit);
20
20
  const saferGasLimit = blockGasLimit * 19n / 20n;
21
- let estimatedGasHex = addHexPrefix(saferGasLimit.toString(16));
21
+ let estimatedGasHex = add0x(saferGasLimit.toString(16));
22
22
  let simulationFails;
23
23
  try {
24
24
  estimatedGasHex = await this.estimateTxGas(txMeta);
@@ -44,17 +44,17 @@ class TransactionGasUtil {
44
44
  Adds a gas buffer with out exceeding the block gas limit
45
45
  */
46
46
  addGasBuffer(initialGasLimitHex, blockGasLimitHex, multiplier = 1.5) {
47
- const initialGasLimit = BigInt(addHexPrefix(initialGasLimitHex));
48
- const blockGasLimit = BigInt(addHexPrefix(blockGasLimitHex));
47
+ const initialGasLimit = hexToBigInt(initialGasLimitHex);
48
+ const blockGasLimit = hexToBigInt(blockGasLimitHex);
49
49
  const upperGasLimit = blockGasLimit * 9n / 10n;
50
50
  const bufferedGasLimit = initialGasLimit * BigInt(Math.round(multiplier * 10)) / 10n;
51
51
 
52
52
  // if initialGasLimit is above blockGasLimit, dont modify it
53
- if (initialGasLimit > upperGasLimit) return addHexPrefix(initialGasLimit.toString(16));
53
+ if (initialGasLimit > upperGasLimit) return bigIntToHexPrefixedString(initialGasLimit);
54
54
  // if bufferedGasLimit is below blockGasLimit, use bufferedGasLimit
55
- if (bufferedGasLimit < upperGasLimit) return addHexPrefix(bufferedGasLimit.toString(16));
55
+ if (bufferedGasLimit < upperGasLimit) return bigIntToHexPrefixedString(bufferedGasLimit);
56
56
  // otherwise use blockGasLimit
57
- return addHexPrefix(upperGasLimit.toString(16));
57
+ return bigIntToHexPrefixedString(upperGasLimit);
58
58
  }
59
59
 
60
60
  /**
@@ -1,31 +1,31 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import { TRANSACTION_TYPES, TransactionStatus, randomId } from '@toruslabs/base-controllers';
3
+ import { add0x } from '@toruslabs/metadata-helpers';
3
4
  import { rpcErrors } from '@web3auth/auth';
4
5
  import log from 'loglevel';
5
6
  import { isHex, decodeFunctionData, isAddress } from 'viem';
6
7
  import { erc20Abi, erc721Abi, erc1155Abi } from '../utils/abis.js';
7
8
  import { CONTRACT_TYPE_ETH, TRANSACTION_ENVELOPE_TYPES, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC1155, METHOD_TYPES } from '../utils/constants.js';
8
- import { addHexPrefix } from '../utils/hex.js';
9
9
 
10
10
  // functions that handle normalizing of that key in txParams
11
11
 
12
12
  const normalizers = {
13
- from: (from, LowerCase = true) => LowerCase ? addHexPrefix(from).toLowerCase() : addHexPrefix(from),
14
- to: (to, LowerCase = true) => LowerCase ? addHexPrefix(to).toLowerCase() : addHexPrefix(to),
15
- nonce: nonce => addHexPrefix(nonce),
16
- customNonceValue: nonce => addHexPrefix(nonce),
17
- value: value => addHexPrefix(value),
18
- data: data => addHexPrefix(data),
19
- gas: gas => addHexPrefix(gas),
20
- gasPrice: gasPrice => addHexPrefix(gasPrice),
21
- type: addHexPrefix,
22
- maxFeePerGas: addHexPrefix,
23
- maxPriorityFeePerGas: addHexPrefix,
24
- callGasLimit: addHexPrefix,
25
- preVerificationGas: addHexPrefix,
26
- verificationGasLimit: addHexPrefix,
27
- paymasterVerificationGasLimit: addHexPrefix,
28
- paymasterPostOpGasLimit: addHexPrefix,
13
+ from: (from, LowerCase = true) => LowerCase ? add0x(from).toLowerCase() : add0x(from),
14
+ to: (to, LowerCase = true) => LowerCase ? add0x(to).toLowerCase() : add0x(to),
15
+ nonce: nonce => add0x(nonce),
16
+ customNonceValue: nonce => add0x(nonce),
17
+ value: value => add0x(value),
18
+ data: data => add0x(data),
19
+ gas: gas => add0x(gas),
20
+ gasPrice: gasPrice => add0x(gasPrice),
21
+ type: add0x,
22
+ maxFeePerGas: add0x,
23
+ maxPriorityFeePerGas: add0x,
24
+ callGasLimit: add0x,
25
+ preVerificationGas: add0x,
26
+ verificationGasLimit: add0x,
27
+ paymasterVerificationGasLimit: add0x,
28
+ paymasterPostOpGasLimit: add0x,
29
29
  authorizationList: authorizationList => authorizationList
30
30
  };
31
31
 
@@ -63,7 +63,7 @@ function isEIP1559Transaction(transaction) {
63
63
  var _transaction$transact, _transaction$transact2;
64
64
  const maxFeePerGas = transaction === null || transaction === void 0 || (_transaction$transact = transaction.transaction) === null || _transaction$transact === void 0 ? void 0 : _transaction$transact.maxFeePerGas;
65
65
  const maxPriorityFeePerGas = transaction === null || transaction === void 0 || (_transaction$transact2 = transaction.transaction) === null || _transaction$transact2 === void 0 ? void 0 : _transaction$transact2.maxPriorityFeePerGas;
66
- return typeof maxFeePerGas === "string" && typeof maxPriorityFeePerGas === "string" && isHex(addHexPrefix(maxFeePerGas)) && isHex(addHexPrefix(maxPriorityFeePerGas));
66
+ return typeof maxFeePerGas === "string" && typeof maxPriorityFeePerGas === "string" && isHex(add0x(maxFeePerGas)) && isHex(add0x(maxPriorityFeePerGas));
67
67
  }
68
68
 
69
69
  /**
@@ -76,7 +76,7 @@ function isEIP1559Transaction(transaction) {
76
76
  * EIP1559 fields
77
77
  */
78
78
  function isLegacyTransaction(transaction) {
79
- return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" || isHex(addHexPrefix(transaction.transaction.gasPrice)));
79
+ return typeof transaction.transaction.maxFeePerGas === "undefined" && typeof transaction.transaction.maxPriorityFeePerGas === "undefined" && (typeof transaction.transaction.gasPrice === "undefined" || isHex(add0x(transaction.transaction.gasPrice)));
80
80
  }
81
81
 
82
82
  /**
@@ -214,7 +214,7 @@ function validateTxParameters(txParams, eip1559Compatibility = true) {
214
214
  if (typeof authorization.address !== "string" || !isAddress(authorization.address)) {
215
215
  throw rpcErrors.invalidParams(`Invalid transaction params: authorization.address is not a valid address. got: (${authorization.address})`);
216
216
  }
217
- if (typeof authorization.chainId !== "string" || !isHex(addHexPrefix(authorization.chainId))) {
217
+ if (typeof authorization.chainId !== "string" || !isHex(add0x(authorization.chainId))) {
218
218
  throw rpcErrors.invalidParams(`Invalid transaction params: authorization.chainId is not a valid hex string. got: (${authorization.chainId})`);
219
219
  }
220
220
  });
@@ -11,9 +11,6 @@ export { PersonalMessageController } from './Message/PersonalMessageController.j
11
11
  export { SwitchChainController } from './Message/SwitchChainController.js';
12
12
  export { TypedMessageController } from './Message/TypedMessageController.js';
13
13
  export { normalizeMessageData, validateAddChainData, validateAddress, validateSignMessageData, validateSwitchChainData, validateTypedSignMessageDataV4 } from './Message/utils.js';
14
- export { createAAMiddleware, createEip5792Middleware, createEip7702Middleware, createEthereumMiddleware, createGetAccountsMiddleware, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessEstimateUserOperationGasMiddleware, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSignTransactionMiddleware, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessageV4, createProcessWalletSwitchChain, createRequestAccountsMiddleware, formatTxMetaForRpcResult } from './Network/createEthereumMiddleware.js';
15
- export { createChainIdMiddleware, createJsonRpcClient, createProviderConfigMiddleware } from './Network/createJsonRpcClient.js';
16
- export { NetworkController } from './Network/NetworkController.js';
17
14
  export { NftHandler } from './Nfts/NftHandler.js';
18
15
  export { NftsController } from './Nfts/NftsController.js';
19
16
  export { PreferencesController } from './Preferences/PreferencesController.js';
@@ -35,11 +32,15 @@ export { DUMMY_AUTHORIZATION_SIGNATURE, EIP_7702_METHODS, EIP_7702_PREFIX, EIP_7
35
32
  export { BNToHex, GAS_LIMITS, addEtherscanTransactions, bnLessThan, formatDate, formatPastTx, formatTime, getChainType, getEthTxStatus, getEtherScanHashLink, getIpfsEndpoint, hexToBn, isAddressByChainId, sanitizeNftMetdataUrl, toChecksumAddressByChainId } from './utils/helpers.js';
36
33
  export { TRANSACTION_CATEGORY_EIP7702 } from './utils/interfaces.js';
37
34
  export { BiconomySmartAccount } from './AccountAbstraction/smartAccounts/BiconomySmartAccount.js';
35
+ export { CacheStrategy, blockTagParamIndex, cacheIdentifierForRequest, cacheTypeForMethod } from './Network/cacheIdentifier.js';
38
36
  export { KernelSmartAccount } from './AccountAbstraction/smartAccounts/KernelSmartAccount.js';
39
37
  export { MetamaskSmartAccount } from './AccountAbstraction/smartAccounts/MetamaskSmartAccount.js';
38
+ export { NetworkController } from './Network/NetworkController.js';
40
39
  export { NexusSmartAccount } from './AccountAbstraction/smartAccounts/NexusSmartAccount.js';
41
40
  export { SafeSmartAccount } from './AccountAbstraction/smartAccounts/SafeSmartAccount.js';
42
41
  export { TrustSmartAccount } from './AccountAbstraction/smartAccounts/TrustSmartAccount.js';
42
+ export { createAAMiddleware, createEip5792Middleware, createEip7702Middleware, createEthereumMiddleware, createGetAccountsMiddleware, createGetProviderStateMiddleware, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessEstimateUserOperationGasMiddleware, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSignTransactionMiddleware, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessageV4, createProcessWalletSwitchChain, createRequestAccountsMiddleware, formatTxMetaForRpcResult } from './Network/createEthereumMiddleware.js';
43
+ export { createChainIdMiddleware, createJsonRpcClient, createProviderConfigMiddleware } from './Network/createJsonRpcClient.js';
43
44
  export { generateBatchId, processMultipleTransactions, processSingleTransaction, validateSendCallsParams, walletSendCalls } from './Eip5792/walletSendCalls.js';
44
45
  export { mapTransactionStatusToEip5792Status, walletGetCallsStatus } from './Eip5792/walletGetCallsStatus.js';
45
46
  export { walletGetCapabilities } from './Eip5792/walletGetCapabilities.js';
@@ -1,8 +1,8 @@
1
1
  import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructuringEmpty';
2
2
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
3
3
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
4
+ import { remove0x } from '@toruslabs/metadata-helpers';
4
5
  import { BigNumber } from 'bignumber.js';
5
- import { stripHexPrefix } from './hex.js';
6
6
 
7
7
  const _excluded = ["aBase", "bBase"],
8
8
  _excluded2 = ["aBase", "bBase"],
@@ -14,7 +14,7 @@ const BIG_NUMBER_GWEI_MULTIPLIER = new BigNumber("1000000000");
14
14
  const BIG_NUMBER_ETH_MULTIPLIER = new BigNumber("1");
15
15
  // Setter Maps
16
16
  const toBigNumber = {
17
- hex: n => new BigNumber(stripHexPrefix(n), 16),
17
+ hex: n => new BigNumber(remove0x(n), 16),
18
18
  dec: n => new BigNumber(String(n), 10),
19
19
  BN: n => new BigNumber(n.toString(16), 16)
20
20
  };
@@ -1,17 +1,17 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import { TransactionStatus, formatSmallNumbers, significantDigits, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, addressSlicer } from '@toruslabs/base-controllers';
3
+ import { add0x, remove0x } from '@toruslabs/metadata-helpers';
3
4
  import { BigNumber } from 'bignumber.js';
4
5
  import log from 'loglevel';
5
6
  import { toHex, isAddress, getAddress } from 'viem';
6
7
  import { determineTransactionType } from '../Transaction/TransactionUtils.js';
7
8
  import { SUPPORTED_NETWORKS, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ERC20, MAINNET_CHAIN_ID, TEST_CHAINS, METHOD_TYPES, CONTRACT_TYPE_ETH } from './constants.js';
8
- import { addHexPrefix, stripHexPrefix } from './hex.js';
9
9
 
10
10
  function hexToBn(hex) {
11
- return new BigNumber(stripHexPrefix(hex), 16);
11
+ return new BigNumber(remove0x(hex), 16);
12
12
  }
13
13
  function BNToHex(bn) {
14
- return addHexPrefix(bn.toString(16));
14
+ return add0x(bn.toString(16));
15
15
  }
16
16
  function getEtherScanHashLink(txHash, chainId) {
17
17
  if (!SUPPORTED_NETWORKS[chainId]) return "";
@@ -1,7 +1,7 @@
1
+ import { add0x } from '@toruslabs/metadata-helpers';
1
2
  import log from 'loglevel';
2
3
  import { recoverTransactionAddress, keccak256 } from 'viem';
3
4
  import { METHOD_TYPES } from './constants.js';
4
- import { addHexPrefix } from './hex.js';
5
5
 
6
6
  /**
7
7
  * Transaction decoder for analytics.
@@ -13,7 +13,7 @@ const transactionDecoder = async (req, chainId) => {
13
13
  try {
14
14
  if (req.method === METHOD_TYPES.ETH_SEND_RAW_TRANSACTION) {
15
15
  const rawTx = req.params[0];
16
- const normalizedRawTx = addHexPrefix(rawTx);
16
+ const normalizedRawTx = add0x(rawTx);
17
17
  sender = await recoverTransactionAddress({
18
18
  serializedTransaction: normalizedRawTx
19
19
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@toruslabs/ethereum-controllers",
3
- "version": "9.0.0",
3
+ "version": "9.2.0",
4
4
  "homepage": "https://github.com/torusresearch/controllers#readme",
5
5
  "license": "ISC",
6
6
  "sideEffects": false,
@@ -21,10 +21,10 @@
21
21
  },
22
22
  "dependencies": {
23
23
  "@metamask/smart-accounts-kit": "~0.4.0-beta.1",
24
- "@toruslabs/base-controllers": "^9.0.0",
24
+ "@toruslabs/base-controllers": "^9.2.0",
25
25
  "@toruslabs/http-helpers": "^9.0.0",
26
- "@toruslabs/metadata-helpers": "^8.1.0",
27
- "@web3auth/auth": "^10.8.0",
26
+ "@toruslabs/metadata-helpers": "^8.2.0",
27
+ "@web3auth/auth": "^11.3.0",
28
28
  "async-mutex": "^0.5.0",
29
29
  "bignumber.js": "^9.3.1",
30
30
  "deepmerge": "^4.3.1",
@@ -64,7 +64,7 @@
64
64
  "publishConfig": {
65
65
  "access": "public"
66
66
  },
67
- "gitHead": "85e8f530c68dc0916a30421454b99bba01711d0a",
67
+ "gitHead": "22ee9ad111b222c956e2fbc525fa2ced6f54ba57",
68
68
  "devDependencies": {
69
69
  "@types/uuid": "^10.0.0",
70
70
  "typechain": "^8.3.2"
@@ -1,9 +0,0 @@
1
- import { Hex } from "viem";
2
- /**
3
- * Removes '0x' from a given `String` if present
4
- */
5
- export declare const stripHexPrefix: (str: string) => string;
6
- /**
7
- * Adds "0x" to a given `string` if it does not already start with "0x".
8
- */
9
- export declare const addHexPrefix: (str: string) => Hex;
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- var viem = require('viem');
4
-
5
- /**
6
- * Removes '0x' from a given `String` if present
7
- */
8
- const stripHexPrefix = str => {
9
- if (typeof str !== "string") throw new Error(`[stripHexPrefix] input must be type 'string', received ${typeof str}`);
10
- return viem.isHex(str) ? str.slice(2) : str;
11
- };
12
- /**
13
- * Adds "0x" to a given `string` if it does not already start with "0x".
14
- */
15
- const addHexPrefix = str => {
16
- if (typeof str !== "string") {
17
- return str;
18
- }
19
- return viem.isHex(str) ? str : `0x${str}`;
20
- };
21
-
22
- exports.addHexPrefix = addHexPrefix;
23
- exports.stripHexPrefix = stripHexPrefix;
@@ -1,21 +0,0 @@
1
- import { isHex } from 'viem';
2
-
3
- /**
4
- * Removes '0x' from a given `String` if present
5
- */
6
- const stripHexPrefix = str => {
7
- if (typeof str !== "string") throw new Error(`[stripHexPrefix] input must be type 'string', received ${typeof str}`);
8
- return isHex(str) ? str.slice(2) : str;
9
- };
10
-
11
- /**
12
- * Adds "0x" to a given `string` if it does not already start with "0x".
13
- */
14
- const addHexPrefix = str => {
15
- if (typeof str !== "string") {
16
- return str;
17
- }
18
- return isHex(str) ? str : `0x${str}`;
19
- };
20
-
21
- export { addHexPrefix, stripHexPrefix };