@toruslabs/ethereum-controllers 5.11.0 → 6.0.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 (111) hide show
  1. package/dist/ethereumControllers.cjs.js +80 -431
  2. package/dist/ethereumControllers.esm.js +30 -349
  3. package/dist/ethereumControllers.umd.min.js +1 -1
  4. package/dist/ethereumControllers.umd.min.js.LICENSE.txt +7 -2
  5. package/dist/lib.cjs/Account/AccountTrackerController.js +160 -0
  6. package/dist/lib.cjs/Block/PollingBlockTracker.js +85 -0
  7. package/dist/lib.cjs/Currency/CurrencyController.js +111 -0
  8. package/dist/lib.cjs/Gas/GasFeeController.js +214 -0
  9. package/dist/lib.cjs/Gas/gasUtil.js +148 -0
  10. package/dist/lib.cjs/Keyring/KeyringController.js +93 -0
  11. package/dist/lib.cjs/Message/AbstractMessageController.js +107 -0
  12. package/dist/lib.cjs/Message/AddChainController.js +78 -0
  13. package/dist/lib.cjs/Message/MessageController.js +77 -0
  14. package/dist/lib.cjs/Message/PersonalMessageController.js +77 -0
  15. package/dist/lib.cjs/Message/SwitchChainController.js +78 -0
  16. package/dist/lib.cjs/Message/TypedMessageController.js +81 -0
  17. package/dist/lib.cjs/Message/utils.js +112 -0
  18. package/dist/lib.cjs/Network/NetworkController.js +201 -0
  19. package/dist/lib.cjs/Network/cacheIdentifier.js +112 -0
  20. package/dist/lib.cjs/Network/createEthereumMiddleware.js +302 -0
  21. package/dist/lib.cjs/Network/createJsonRpcClient.js +64 -0
  22. package/dist/lib.cjs/Nfts/NftHandler.js +180 -0
  23. package/dist/lib.cjs/Nfts/NftsController.js +213 -0
  24. package/dist/lib.cjs/Preferences/PreferencesController.js +476 -0
  25. package/dist/lib.cjs/Tokens/TokenHandler.js +51 -0
  26. package/dist/lib.cjs/Tokens/TokenRatesController.js +112 -0
  27. package/dist/lib.cjs/Tokens/TokensController.js +259 -0
  28. package/dist/lib.cjs/Transaction/NonceTracker.js +150 -0
  29. package/dist/lib.cjs/Transaction/PendingTransactionTracker.js +222 -0
  30. package/dist/lib.cjs/Transaction/TransactionController.js +515 -0
  31. package/dist/lib.cjs/Transaction/TransactionGasUtil.js +81 -0
  32. package/dist/lib.cjs/Transaction/TransactionStateHistoryHelper.js +42 -0
  33. package/dist/lib.cjs/Transaction/TransactionStateManager.js +296 -0
  34. package/dist/lib.cjs/Transaction/TransactionUtils.js +341 -0
  35. package/dist/lib.cjs/index.js +171 -0
  36. package/dist/lib.cjs/utils/abis.js +510 -0
  37. package/dist/lib.cjs/utils/constants.js +362 -0
  38. package/dist/lib.cjs/utils/contractAddresses.js +16 -0
  39. package/dist/lib.cjs/utils/conversionUtils.js +232 -0
  40. package/dist/lib.cjs/utils/helpers.js +244 -0
  41. package/dist/lib.cjs/utils/lodashUtils.js +25 -0
  42. package/dist/lib.esm/Account/AccountTrackerController.js +158 -0
  43. package/dist/lib.esm/Block/PollingBlockTracker.js +83 -0
  44. package/dist/lib.esm/Currency/CurrencyController.js +109 -0
  45. package/dist/lib.esm/Gas/GasFeeController.js +212 -0
  46. package/dist/lib.esm/Gas/gasUtil.js +141 -0
  47. package/dist/lib.esm/Keyring/KeyringController.js +91 -0
  48. package/dist/lib.esm/Message/AbstractMessageController.js +105 -0
  49. package/dist/lib.esm/Message/AddChainController.js +76 -0
  50. package/dist/lib.esm/Message/MessageController.js +75 -0
  51. package/dist/lib.esm/Message/PersonalMessageController.js +75 -0
  52. package/dist/lib.esm/Message/SwitchChainController.js +76 -0
  53. package/dist/lib.esm/Message/TypedMessageController.js +79 -0
  54. package/dist/lib.esm/Message/utils.js +105 -0
  55. package/dist/lib.esm/Network/NetworkController.js +199 -0
  56. package/dist/lib.esm/Network/cacheIdentifier.js +107 -0
  57. package/dist/lib.esm/Network/createEthereumMiddleware.js +289 -0
  58. package/dist/lib.esm/Network/createJsonRpcClient.js +60 -0
  59. package/dist/lib.esm/Nfts/NftHandler.js +178 -0
  60. package/dist/lib.esm/Nfts/NftsController.js +211 -0
  61. package/dist/lib.esm/Preferences/PreferencesController.js +474 -0
  62. package/dist/lib.esm/Tokens/TokenHandler.js +49 -0
  63. package/dist/lib.esm/Tokens/TokenRatesController.js +109 -0
  64. package/dist/lib.esm/Tokens/TokensController.js +257 -0
  65. package/dist/lib.esm/Transaction/NonceTracker.js +148 -0
  66. package/dist/lib.esm/Transaction/PendingTransactionTracker.js +220 -0
  67. package/dist/lib.esm/Transaction/TransactionController.js +513 -0
  68. package/dist/lib.esm/Transaction/TransactionGasUtil.js +79 -0
  69. package/dist/lib.esm/Transaction/TransactionStateHistoryHelper.js +38 -0
  70. package/dist/lib.esm/Transaction/TransactionStateManager.js +294 -0
  71. package/dist/lib.esm/Transaction/TransactionUtils.js +326 -0
  72. package/dist/lib.esm/index.js +33 -0
  73. package/dist/lib.esm/utils/abis.js +505 -0
  74. package/dist/lib.esm/utils/constants.js +323 -0
  75. package/dist/lib.esm/utils/contractAddresses.js +14 -0
  76. package/dist/lib.esm/utils/conversionUtils.js +218 -0
  77. package/dist/lib.esm/utils/helpers.js +227 -0
  78. package/dist/lib.esm/utils/lodashUtils.js +21 -0
  79. package/dist/types/Account/AccountTrackerController.d.ts +5 -5
  80. package/dist/types/Block/PollingBlockTracker.d.ts +1 -2
  81. package/dist/types/Currency/CurrencyController.d.ts +1 -1
  82. package/dist/types/Gas/GasFeeController.d.ts +3 -3
  83. package/dist/types/Gas/gasUtil.d.ts +1 -1
  84. package/dist/types/Keyring/KeyringController.d.ts +3 -5
  85. package/dist/types/Message/AbstractMessageController.d.ts +5 -6
  86. package/dist/types/Message/AddChainController.d.ts +4 -4
  87. package/dist/types/Message/MessageController.d.ts +4 -4
  88. package/dist/types/Message/PersonalMessageController.d.ts +4 -4
  89. package/dist/types/Message/SwitchChainController.d.ts +4 -4
  90. package/dist/types/Message/TypedMessageController.d.ts +6 -7
  91. package/dist/types/Message/utils.d.ts +2 -7
  92. package/dist/types/Network/NetworkController.d.ts +4 -4
  93. package/dist/types/Network/cacheIdentifier.d.ts +1 -1
  94. package/dist/types/Network/createEthereumMiddleware.d.ts +2 -18
  95. package/dist/types/Network/createJsonRpcClient.d.ts +2 -2
  96. package/dist/types/Nfts/NftsController.d.ts +2 -2
  97. package/dist/types/Preferences/PreferencesController.d.ts +4 -4
  98. package/dist/types/Tokens/TokensController.d.ts +3 -3
  99. package/dist/types/Transaction/NonceTracker.d.ts +5 -5
  100. package/dist/types/Transaction/PendingTransactionTracker.d.ts +5 -5
  101. package/dist/types/Transaction/TransactionController.d.ts +12 -12
  102. package/dist/types/Transaction/TransactionGasUtil.d.ts +4 -4
  103. package/dist/types/Transaction/TransactionStateManager.d.ts +3 -3
  104. package/dist/types/Transaction/TransactionUtils.d.ts +1 -1
  105. package/dist/types/index.d.ts +12 -14
  106. package/dist/types/utils/constants.d.ts +1 -5
  107. package/dist/types/utils/helpers.d.ts +4 -4
  108. package/dist/types/utils/interfaces.d.ts +43 -23
  109. package/package.json +7 -7
  110. package/dist/types/Message/DecryptMessageController.d.ts +0 -20
  111. package/dist/types/Message/EncryptionPublicKeyController.d.ts +0 -20
@@ -1,17 +1,16 @@
1
1
  import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
- import { CHAIN_NAMESPACES, BaseController, randomId, TransactionStatus, TRANSACTION_TYPES, formatSmallNumbers, addressSlicer, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, significantDigits, BaseBlockTracker, timeout, BaseCurrencyController, cloneDeep, BaseKeyringController, PROVIDER_JRPC_METHODS, createFetchMiddleware, createInflightCacheMiddleware, createSwappableProxy, createEventEmitterProxy, BasePreferencesController, isUnauthorizedError, TX_EVENTS, BaseTransactionStateManager, omitBy, transactionMatchesNetwork as transactionMatchesNetwork$1, pickBy } from '@toruslabs/base-controllers';
3
+ import { CHAIN_NAMESPACES, BaseController, randomId, TransactionStatus, TRANSACTION_TYPES, formatSmallNumbers, addressSlicer, ACTIVITY_ACTION_RECEIVE, ACTIVITY_ACTION_SEND, significantDigits, BaseBlockTracker, timeout, BaseCurrencyController, cloneDeep, BaseKeyringController, concatSig, PROVIDER_JRPC_METHODS, createFetchMiddleware, createInflightCacheMiddleware, createSwappableProxy, createEventEmitterProxy, BasePreferencesController, isUnauthorizedError, TX_EVENTS, BaseTransactionStateManager, omitBy, transactionMatchesNetwork as transactionMatchesNetwork$1, pickBy } from '@toruslabs/base-controllers';
4
4
  import { Mutex } from 'async-mutex';
5
- import { BrowserProvider, toQuantity, Contract, Interface, isHexString as isHexString$1, JsonRpcProvider, keccak256 } from 'ethers';
5
+ import { BrowserProvider, toQuantity, Contract, Interface, SigningKey, hashMessage, TypedDataEncoder, isHexString as isHexString$1, JsonRpcProvider, keccak256 } from 'ethers';
6
6
  import log from 'loglevel';
7
7
  import { isHexString, addHexPrefix, isValidAddress, stripHexPrefix, toChecksumAddress, bytesToHex, privateToPublic, privateToAddress, ecsign, bigIntToBytes } from '@ethereumjs/util';
8
8
  import BigNumber from 'bignumber.js';
9
- import { rpcErrors, providerErrors, createAsyncMiddleware, mergeMiddleware, createScaffoldMiddleware, providerFromMiddleware, JRPCEngine, providerFromEngine, SafeEventEmitter } from '@toruslabs/openlogin-jrpc';
9
+ import { rpcErrors, providerErrors, createAsyncMiddleware, mergeMiddleware, createScaffoldMiddleware, providerFromMiddleware, JRPCEngine, providerFromEngine, SafeEventEmitter } from '@web3auth/auth';
10
10
  import { get } from '@toruslabs/http-helpers';
11
11
  import _objectDestructuringEmpty from '@babel/runtime/helpers/objectDestructuringEmpty';
12
12
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
13
13
  import BN, { BN as BN$1 } from 'bn.js';
14
- import { concatSig, personalSign, signTypedData, getEncryptionPublicKey, decrypt, typedSignatureHash, TYPED_MESSAGE_SCHEMA, SignTypedDataVersion } from '@metamask/eth-sig-util';
15
14
  import stringify from 'fast-safe-stringify';
16
15
  import deepmerge from 'deepmerge';
17
16
  import jsonDiffer from 'fast-json-patch';
@@ -737,14 +736,10 @@ const METHOD_TYPES = {
737
736
  ETH_REQUEST_ACCOUNTS: "eth_requestAccounts",
738
737
  ETH_SEND_RAW_TRANSACTION: "eth_sendRawTransaction",
739
738
  ETH_SIGN: "eth_sign",
740
- ETH_SIGN_TYPED_DATA: "eth_signTypedData",
741
- ETH_SIGN_TYPED_DATA_V3: "eth_signTypedData_v3",
742
739
  ETH_SIGN_TYPED_DATA_V4: "eth_signTypedData_v4",
743
740
  PERSONAL_SIGN: "personal_sign",
744
741
  ETH_GET_TRANSACTION_COUNT: "eth_getTransactionCount",
745
742
  ETH_GET_TRANSACTION_BY_HASH: "eth_getTransactionByHash",
746
- ETH_GET_ENCRYPTION_PUBLIC_KEY: "eth_getEncryptionPublicKey",
747
- ETH_DECRYPT: "eth_decrypt",
748
743
  ETH_GET_TRANSACTION_RECEIPT: "eth_getTransactionReceipt",
749
744
  WATCH_ASSET: "wallet_watchAsset",
750
745
  ETH_GET_BLOCK_BY_HASH: "eth_getBlockByHash",
@@ -2328,38 +2323,19 @@ class KeyringController extends BaseKeyringController {
2328
2323
  const sig = concatSig(Buffer.from(bigIntToBytes(messageSig.v)), Buffer.from(messageSig.r), Buffer.from(messageSig.s));
2329
2324
  return sig;
2330
2325
  }
2331
-
2332
- // For personal_sign, we need to prefix the message: ensure input is hashed and not buffer of utf-8
2333
2326
  async signPersonalMessage(data, address) {
2334
2327
  const wallet = this._getWalletForAccount(address);
2335
- const privKey = this.getBufferPrivateKey(wallet.privateKey);
2336
- const sig = personalSign({
2337
- privateKey: privKey,
2338
- data
2339
- });
2340
- return sig;
2328
+ const privKey = new SigningKey(addHexPrefix(wallet.privateKey));
2329
+ const signature = privKey.sign(hashMessage(data)).serialized;
2330
+ return signature;
2341
2331
  }
2342
2332
 
2343
2333
  // personal_signTypedData, signs data along with the schema
2344
- async signTypedData(typedData, address, version) {
2345
- const wallet = this._getWalletForAccount(address);
2346
- const privKey = this.getBufferPrivateKey(wallet.privateKey);
2347
- return signTypedData({
2348
- privateKey: privKey,
2349
- data: typedData,
2350
- version
2351
- });
2352
- }
2353
- signEncryptionPublicKey(address) {
2334
+ async signTypedData(typedData, address) {
2354
2335
  const wallet = this._getWalletForAccount(address);
2355
- return getEncryptionPublicKey(stripHexPrefix(wallet.privateKey));
2356
- }
2357
- decryptMessage(data, address) {
2358
- const wallet = this._getWalletForAccount(address);
2359
- return decrypt({
2360
- encryptedData: data,
2361
- privateKey: stripHexPrefix(wallet.privateKey)
2362
- });
2336
+ const privKey = new SigningKey(addHexPrefix(wallet.privateKey));
2337
+ const signature = privKey.sign(TypedDataEncoder.hash(typedData.domain, typedData.types, typedData.message)).serialized;
2338
+ return signature;
2363
2339
  }
2364
2340
  _getWalletForAccount(account) {
2365
2341
  const address = account.toLowerCase();
@@ -2493,19 +2469,7 @@ function normalizeMessageData(data) {
2493
2469
  } catch (e) {}
2494
2470
  return bytesToHex(Buffer.from(data, "utf8"));
2495
2471
  }
2496
- function validateTypedSignMessageDataV1(messageData) {
2497
- validateAddress(messageData.from, "from");
2498
- if (!messageData.data || !Array.isArray(messageData.data)) {
2499
- throw new Error(`Invalid message "data": ${messageData.data} must be a valid array.`);
2500
- }
2501
- try {
2502
- // typedSignatureHash will throw if the data is invalid.
2503
- typedSignatureHash(messageData.data);
2504
- } catch (e) {
2505
- throw new Error(`Expected EIP712 typed data.`);
2506
- }
2507
- }
2508
- async function validateTypedSignMessageDataV3V4(messageData, currentChainId) {
2472
+ async function validateTypedSignMessageDataV4(messageData, currentChainId) {
2509
2473
  validateAddress(messageData.from, "from");
2510
2474
  if (!messageData.data || Array.isArray(messageData.data) || typeof messageData.data !== "object" && typeof messageData.data !== "string") {
2511
2475
  throw new Error(`Invalid message "data": Must be a valid string or object.`);
@@ -2520,13 +2484,6 @@ async function validateTypedSignMessageDataV3V4(messageData, currentChainId) {
2520
2484
  throw new Error("Data must be passed as a valid JSON string.");
2521
2485
  }
2522
2486
  }
2523
- const {
2524
- validate
2525
- } = await import('jsonschema');
2526
- const validation = validate(data, TYPED_MESSAGE_SCHEMA);
2527
- if (validation.errors.length > 0) {
2528
- throw new Error("Data must conform to EIP-712 schema. See https://git.io/fNtcx.");
2529
- }
2530
2487
  if (!currentChainId) {
2531
2488
  throw new Error("Current chainId cannot be null or undefined.");
2532
2489
  }
@@ -2546,23 +2503,6 @@ async function validateTypedSignMessageDataV3V4(messageData, currentChainId) {
2546
2503
  }
2547
2504
  }
2548
2505
  }
2549
- function validateEncryptionPublicKeyMessageData(messageData) {
2550
- const {
2551
- from
2552
- } = messageData;
2553
- validateAddress(from, "from");
2554
- }
2555
- function validateDecryptedMessageData(messageData) {
2556
- const {
2557
- from
2558
- } = messageData;
2559
- validateAddress(from, "from");
2560
- }
2561
- function parseDecryptMessageData(data) {
2562
- const stripped = stripHexPrefix(data);
2563
- const buffer = Buffer.from(stripped, "hex");
2564
- return JSON.parse(buffer.toString("utf8"));
2565
- }
2566
2506
  async function validateAddChainData(data) {
2567
2507
  const {
2568
2508
  chainId,
@@ -2672,141 +2612,6 @@ class AddChainController extends AbstractMessageController {
2672
2612
  }
2673
2613
  }
2674
2614
 
2675
- class DecryptMessageController extends AbstractMessageController {
2676
- constructor({
2677
- config,
2678
- state,
2679
- decryptMessage,
2680
- getNetworkIdentifier
2681
- }) {
2682
- super({
2683
- config,
2684
- state,
2685
- getNetworkIdentifier
2686
- });
2687
- _defineProperty(this, "name", "DecryptMessageController");
2688
- _defineProperty(this, "decryptMessage", void 0);
2689
- this.decryptMessage = decryptMessage;
2690
- this.initialize();
2691
- }
2692
- async processDecryptMessage(messageId) {
2693
- const msgObject = this.getMessage(messageId);
2694
- if (!msgObject) {
2695
- throw new Error("Message not found");
2696
- }
2697
- try {
2698
- const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2699
- const parsedData = parseDecryptMessageData(cleanMsgParams.data);
2700
- const rawSig = this.decryptMessage(parsedData, cleanMsgParams.from);
2701
- this.updateMessage(_objectSpread(_objectSpread({}, msgObject), {}, {
2702
- rawSig
2703
- }));
2704
- this.setMessageStatus(messageId, MessageStatus.SIGNED);
2705
- return rawSig;
2706
- } catch (error) {
2707
- log.error(error);
2708
- msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
2709
- this.setMessageStatus(messageId, MessageStatus.FAILED);
2710
- }
2711
- }
2712
- async addNewUnapprovedMessage(messageParams, req) {
2713
- await this.addUnapprovedMessage(messageParams, req);
2714
- return this.waitForFinishStatus(messageParams, this.name);
2715
- }
2716
- async addUnapprovedMessage(messageParams, req) {
2717
- validateDecryptedMessageData(messageParams);
2718
- if (req) {
2719
- messageParams.origin = req.origin;
2720
- }
2721
- messageParams.data = normalizeMessageData(messageParams.data);
2722
- const messageId = messageParams.id || randomId();
2723
- const messageData = {
2724
- id: messageId,
2725
- messageParams,
2726
- status: MessageStatus.UNAPPROVED,
2727
- time: Date.now(),
2728
- type: METHOD_TYPES.ETH_DECRYPT
2729
- };
2730
- await this.addMessage(messageData);
2731
- this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, {
2732
- messageData,
2733
- req
2734
- });
2735
- return messageId;
2736
- }
2737
- prepMessageForSigning(messageParams) {
2738
- return Promise.resolve(_objectSpread({}, messageParams));
2739
- }
2740
- }
2741
-
2742
- class EncryptionPublicKeyController extends AbstractMessageController {
2743
- constructor({
2744
- config,
2745
- state,
2746
- signEncryptionPublicKey,
2747
- getNetworkIdentifier
2748
- }) {
2749
- super({
2750
- config,
2751
- state,
2752
- getNetworkIdentifier
2753
- });
2754
- _defineProperty(this, "name", "EncryptionPublicKeyController");
2755
- _defineProperty(this, "signEncryptionPublicKey", void 0);
2756
- this.signEncryptionPublicKey = signEncryptionPublicKey;
2757
- this.initialize();
2758
- }
2759
- async processGetEncryptionPublicKey(messageId) {
2760
- const msgObject = this.getMessage(messageId);
2761
- if (!msgObject) {
2762
- throw new Error(`Message not found`);
2763
- }
2764
- try {
2765
- const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2766
- const publicKey = this.signEncryptionPublicKey(cleanMsgParams.from);
2767
- this.updateMessage(_objectSpread(_objectSpread({}, msgObject), {}, {
2768
- rawSig: publicKey
2769
- }));
2770
- this.setMessageStatus(messageId, MessageStatus.SIGNED);
2771
- return publicKey;
2772
- } catch (error) {
2773
- log.error(error);
2774
- msgObject.error = (error === null || error === void 0 ? void 0 : error.message) || (error === null || error === void 0 ? void 0 : error.toString());
2775
- this.setMessageStatus(messageId, MessageStatus.FAILED);
2776
- }
2777
- }
2778
- async addNewUnapprovedMessage(messageParams, req) {
2779
- await this.addUnapprovedMessage(messageParams, req);
2780
- return this.waitForFinishStatus(messageParams, this.name);
2781
- }
2782
- async addUnapprovedMessage(messageParams, req) {
2783
- validateEncryptionPublicKeyMessageData(messageParams);
2784
- if (req) {
2785
- messageParams.origin = req.origin;
2786
- }
2787
- const messageId = messageParams.id || randomId();
2788
- const messageData = {
2789
- id: messageId,
2790
- messageParams,
2791
- status: MessageStatus.UNAPPROVED,
2792
- time: Date.now(),
2793
- type: METHOD_TYPES.ETH_GET_ENCRYPTION_PUBLIC_KEY
2794
- };
2795
- await this.addMessage(messageData);
2796
- this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, {
2797
- messageData,
2798
- req
2799
- });
2800
- return messageId;
2801
- }
2802
- prepMessageForSigning(messageParams) {
2803
- // From should be the public key for the encryption
2804
- return Promise.resolve(_objectSpread(_objectSpread({}, messageParams), {}, {
2805
- from: messageParams.data
2806
- }));
2807
- }
2808
- }
2809
-
2810
2615
  class MessageController extends AbstractMessageController {
2811
2616
  constructor({
2812
2617
  config,
@@ -3006,18 +2811,6 @@ class SwitchChainController extends AbstractMessageController {
3006
2811
  }
3007
2812
  }
3008
2813
 
3009
- function getMessageType(version) {
3010
- switch (version) {
3011
- case SignTypedDataVersion.V1:
3012
- return METHOD_TYPES.ETH_SIGN_TYPED_DATA;
3013
- case SignTypedDataVersion.V3:
3014
- return METHOD_TYPES.ETH_SIGN_TYPED_DATA_V3;
3015
- case SignTypedDataVersion.V4:
3016
- return METHOD_TYPES.ETH_SIGN_TYPED_DATA_V4;
3017
- default:
3018
- return METHOD_TYPES.ETH_SIGN_TYPED_DATA;
3019
- }
3020
- }
3021
2814
  class TypedMessageController extends AbstractMessageController {
3022
2815
  constructor({
3023
2816
  config,
@@ -3042,8 +2835,8 @@ class TypedMessageController extends AbstractMessageController {
3042
2835
  }
3043
2836
  try {
3044
2837
  const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
3045
- const msgData = cleanMsgParams.version === SignTypedDataVersion.V1 ? cleanMsgParams.data : JSON.parse(cleanMsgParams.data);
3046
- const rawSig = await this.signTypedData(msgData, cleanMsgParams.from, cleanMsgParams.version);
2838
+ const msgData = JSON.parse(cleanMsgParams.data);
2839
+ const rawSig = await this.signTypedData(msgData, cleanMsgParams.from);
3047
2840
  this.updateMessage(_objectSpread(_objectSpread({}, msgObject), {}, {
3048
2841
  rawSig
3049
2842
  }));
@@ -3055,32 +2848,26 @@ class TypedMessageController extends AbstractMessageController {
3055
2848
  this.setMessageStatus(messageId, MessageStatus.FAILED);
3056
2849
  }
3057
2850
  }
3058
- async addNewUnapprovedMessage(messageParams, req, version) {
3059
- await this.addUnapprovedMessage(messageParams, req, version);
2851
+ async addNewUnapprovedMessage(messageParams, req) {
2852
+ await this.addUnapprovedMessage(messageParams, req);
3060
2853
  return this.waitForFinishStatus(messageParams, this.name);
3061
2854
  }
3062
- async addUnapprovedMessage(messageParams, req, version) {
3063
- if (version === SignTypedDataVersion.V1) {
3064
- validateTypedSignMessageDataV1(messageParams);
3065
- }
3066
- if (version === SignTypedDataVersion.V3 || version === SignTypedDataVersion.V4) {
3067
- const currentChainId = this.getNetworkIdentifier();
3068
- await validateTypedSignMessageDataV3V4(messageParams, currentChainId);
3069
- }
3070
- if (typeof messageParams.data !== "string" && (version === SignTypedDataVersion.V3 || version === SignTypedDataVersion.V4)) {
2855
+ async addUnapprovedMessage(messageParams, req) {
2856
+ const currentChainId = this.getNetworkIdentifier();
2857
+ await validateTypedSignMessageDataV4(messageParams, currentChainId);
2858
+ if (typeof messageParams.data !== "string") {
3071
2859
  messageParams.data = JSON.stringify(messageParams.data);
3072
2860
  }
3073
2861
  if (req) {
3074
2862
  messageParams.origin = req.origin;
3075
2863
  }
3076
- messageParams.version = version;
3077
2864
  const messageId = messageParams.id || randomId();
3078
2865
  const messageData = {
3079
2866
  id: messageId,
3080
2867
  messageParams,
3081
2868
  status: MessageStatus.UNAPPROVED,
3082
2869
  time: Date.now(),
3083
- type: getMessageType(version)
2870
+ type: METHOD_TYPES.ETH_SIGN_TYPED_DATA_V4
3084
2871
  };
3085
2872
  await this.addMessage(messageData);
3086
2873
  this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, {
@@ -3143,56 +2930,6 @@ function createProcessEthSignMessage({
3143
2930
  response.result = await processEthSignMessage(msgParams, request);
3144
2931
  });
3145
2932
  }
3146
- function createProcessTypedMessage({
3147
- processTypedMessage
3148
- }) {
3149
- return createAsyncMiddleware(async (request, response, next) => {
3150
- const {
3151
- method
3152
- } = request;
3153
- if (method !== METHOD_TYPES.ETH_SIGN_TYPED_DATA) return next();
3154
- if (!processTypedMessage) throw new Error("WalletMiddleware - opts.processTypedMessage not provided");
3155
- if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
3156
- let msgParams = request.params;
3157
- if (Array.isArray(request.params)) {
3158
- if (!(request.params.length === 2)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [typedData, address]`);
3159
- const params = request.params;
3160
- const message = typeof params[0] === "string" ? JSON.parse(params[0]) : params[0];
3161
- const address = params[1];
3162
- msgParams = {
3163
- from: address,
3164
- data: message,
3165
- version: SignTypedDataVersion.V1
3166
- };
3167
- }
3168
- response.result = await processTypedMessage(msgParams, request);
3169
- });
3170
- }
3171
- function createProcessTypedMessageV3({
3172
- processTypedMessageV3
3173
- }) {
3174
- return createAsyncMiddleware(async (request, response, next) => {
3175
- const {
3176
- method
3177
- } = request;
3178
- if (method !== METHOD_TYPES.ETH_SIGN_TYPED_DATA_V3) return next();
3179
- if (!processTypedMessageV3) throw new Error("WalletMiddleware - opts.processTypedMessageV3 is not provided");
3180
- if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
3181
- let msgParams = request.params;
3182
- if (Array.isArray(request.params)) {
3183
- if (!(request.params.length === 2)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [address, typedData]`);
3184
- const params = request.params;
3185
- const address = params[0];
3186
- const message = params[1];
3187
- msgParams = {
3188
- from: address,
3189
- data: message,
3190
- version: SignTypedDataVersion.V3
3191
- };
3192
- }
3193
- response.result = await processTypedMessageV3(msgParams, request);
3194
- });
3195
- }
3196
2933
  function createProcessTypedMessageV4({
3197
2934
  processTypedMessageV4
3198
2935
  }) {
@@ -3211,8 +2948,7 @@ function createProcessTypedMessageV4({
3211
2948
  const message = params[1];
3212
2949
  msgParams = {
3213
2950
  from: address,
3214
- data: message,
3215
- version: SignTypedDataVersion.V4
2951
+ data: message
3216
2952
  };
3217
2953
  }
3218
2954
  response.result = await processTypedMessageV4(msgParams, request);
@@ -3335,50 +3071,6 @@ function createPendingTxMiddleware({
3335
3071
  return undefined;
3336
3072
  });
3337
3073
  }
3338
- function createProcessEncryptionPublicKeyMiddleware({
3339
- processEncryptionPublicKey
3340
- }) {
3341
- return createAsyncMiddleware(async (request, response, next) => {
3342
- const {
3343
- method
3344
- } = request;
3345
- if (method !== METHOD_TYPES.ETH_GET_ENCRYPTION_PUBLIC_KEY) return next();
3346
- if (!processEncryptionPublicKey) throw new Error("WalletMiddleware - opts.processEncryptionPublicKey not provided");
3347
- if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
3348
- let msgParams = request.params;
3349
- if (Array.isArray(request.params)) {
3350
- if (!(request.params.length === 1)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [address]`);
3351
- const [address] = request.params;
3352
- msgParams = {
3353
- data: address,
3354
- from: address
3355
- };
3356
- }
3357
- response.result = await processEncryptionPublicKey(msgParams, request);
3358
- });
3359
- }
3360
- function createProcessDecryptMessageMiddleware({
3361
- processDecryptMessage
3362
- }) {
3363
- return createAsyncMiddleware(async (request, response, next) => {
3364
- const {
3365
- method
3366
- } = request;
3367
- if (method !== METHOD_TYPES.ETH_DECRYPT) return next();
3368
- if (!processDecryptMessage) throw new Error("WalletMiddleware - opts.processDecryptMessage not provided");
3369
- if (!(request !== null && request !== void 0 && request.params)) throw new Error("WalletMiddleware - missing params");
3370
- let msgParams = request.params;
3371
- if (Array.isArray(request.params)) {
3372
- if (!(request.params.length === 2)) throw new Error(`WalletMiddleware - incorrect params for ${method} method. expected [message, address]`);
3373
- const [message, address] = request.params;
3374
- msgParams = {
3375
- data: message,
3376
- from: address
3377
- };
3378
- }
3379
- response.result = await processDecryptMessage(msgParams, request);
3380
- });
3381
- }
3382
3074
  function createProcessSwitchEthereumChain({
3383
3075
  processSwitchEthereumChain
3384
3076
  }) {
@@ -3438,14 +3130,10 @@ function createEthereumMiddleware(providerHandlers) {
3438
3130
  getAccounts,
3439
3131
  processTransaction,
3440
3132
  processEthSignMessage,
3441
- processTypedMessage,
3442
- processTypedMessageV3,
3443
3133
  processTypedMessageV4,
3444
3134
  processPersonalMessage,
3445
3135
  getPendingNonce,
3446
3136
  getPendingTransactionByHash,
3447
- processEncryptionPublicKey,
3448
- processDecryptMessage,
3449
3137
  processSwitchEthereumChain,
3450
3138
  processAddEthereumChain,
3451
3139
  getProviderState,
@@ -3462,10 +3150,6 @@ function createEthereumMiddleware(providerHandlers) {
3462
3150
  processTransaction
3463
3151
  }), createProcessEthSignMessage({
3464
3152
  processEthSignMessage
3465
- }), createProcessTypedMessage({
3466
- processTypedMessage
3467
- }), createProcessTypedMessageV3({
3468
- processTypedMessageV3
3469
3153
  }), createProcessTypedMessageV4({
3470
3154
  processTypedMessageV4
3471
3155
  }), createProcessPersonalMessage({
@@ -3474,10 +3158,6 @@ function createEthereumMiddleware(providerHandlers) {
3474
3158
  getPendingNonce
3475
3159
  }), createPendingTxMiddleware({
3476
3160
  getPendingTransactionByHash
3477
- }), createProcessEncryptionPublicKeyMiddleware({
3478
- processEncryptionPublicKey
3479
- }), createProcessDecryptMessageMiddleware({
3480
- processDecryptMessage
3481
3161
  }), createProcessSwitchEthereumChain({
3482
3162
  processSwitchEthereumChain
3483
3163
  }), createProcessAddEthereumChain({
@@ -5269,7 +4949,6 @@ class PendingTransactionTracker extends SafeEventEmitter {
5269
4949
  };
5270
4950
  this.emit(TX_EVENTS.TX_WARNING, {
5271
4951
  txMeta,
5272
- error,
5273
4952
  txId: txMeta.id
5274
4953
  });
5275
4954
  }
@@ -5359,7 +5038,8 @@ class PendingTransactionTracker extends SafeEventEmitter {
5359
5038
  message: "There was a problem loading this transaction."
5360
5039
  };
5361
5040
  this.emit(TX_EVENTS.TX_WARNING, {
5362
- txMeta
5041
+ txMeta,
5042
+ txId
5363
5043
  });
5364
5044
  }
5365
5045
  if (await this._checkIfTxWasDropped(txMeta)) {
@@ -5963,6 +5643,7 @@ class TransactionController extends TransactionStateManager {
5963
5643
  const {
5964
5644
  TransactionFactory
5965
5645
  } = await import('@ethereumjs/tx');
5646
+ // TODO: fix this when @ethereumjs/tx is updated.
5966
5647
  const unsignedEthTx = TransactionFactory.fromTxData(txParams, {
5967
5648
  common
5968
5649
  });
@@ -6235,12 +5916,12 @@ class TransactionController extends TransactionStateManager {
6235
5916
  this.updateTransactionInState(txMeta);
6236
5917
  }
6237
5918
  });
6238
- this.pendingTxTracker.on(TX_EVENTS.TX_RETRY, txMeta => {
6239
- if (!("retryCount" in txMeta)) {
6240
- txMeta.retryCount = 0;
5919
+ this.pendingTxTracker.on(TX_EVENTS.TX_RETRY, data => {
5920
+ if (!("retryCount" in data.txMeta)) {
5921
+ data.txMeta.retryCount = 0;
6241
5922
  }
6242
- txMeta.retryCount += 1;
6243
- this.updateTransactionInState(txMeta);
5923
+ data.txMeta.retryCount += 1;
5924
+ this.updateTransactionInState(data.txMeta);
6244
5925
  });
6245
5926
  this.pendingTxTracker.on(TX_EVENTS.TX_FAILED, data => {
6246
5927
  this.setTxStatusFailed(data.txId, data.error);
@@ -6312,4 +5993,4 @@ class TransactionController extends TransactionStateManager {
6312
5993
  }
6313
5994
  }
6314
5995
 
6315
- export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, AccountTrackerController, AddChainController, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BNToHex, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ETH, CurrencyController, DEFAULT_CURRENCY, DecryptMessageController, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, ETHERSCAN_SUPPORTED_CHAINS, EncryptionPublicKeyController, GAS_ESTIMATE_TYPES, GAS_LIMITS, GasFeeController, KeyringController, LOCALHOST, MAINNET_CHAIN_ID, MESSAGE_EVENTS, METHOD_TYPES, MessageController, MessageStatus, NetworkController, NftHandler, NftsController, NonceTracker, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, PendingTransactionTracker, PersonalMessageController, PollingBlockTracker, PreferencesController, SEPOLIA_CHAIN_ID, SIMPLEHASH_SUPPORTED_CHAINS, SUPPORTED_NETWORKS, SwitchChainController, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, TokenHandler, TokenRatesController, TokensController, TransactionController, TransactionGasUtil, TransactionStateManager, TypedMessageController, XDAI_CHAIN_ID, addCurrencies, addEtherscanTransactions, bnLessThan, conversionGTE, conversionGreaterThan, conversionLTE, conversionLessThan, conversionMax, conversionUtil, createChainIdMiddleware, createEthereumMiddleware, createGetAccountsMiddleware, createJsonRpcClient, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessDecryptMessageMiddleware, createProcessEncryptionPublicKeyMiddleware, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessage, createProcessTypedMessageV3, createProcessTypedMessageV4, createProviderConfigMiddleware, createRequestAccountsMiddleware, decGWEIToHexWEI, determineTransactionType, ensureFieldIsString, ensureMutuallyExclusiveFieldsNotProvided, erc1155Abi, erc20Abi, erc721Abi, formatDate, formatPastTx, formatTime, formatTxMetaForRpcResult, generateHistoryEntry, getBigNumber, getChainType, getEthTxStatus, getEtherScanHashLink, getFinalStates, getIpfsEndpoint, hexToBn, hexWEIToDecGWEI, idleTimeTracker, isAddressByChainId, isEIP1559Transaction, isLegacyTransaction, multiplyCurrencies, normalizeAndValidateTxParams, normalizeMessageData, normalizeTxParameters, parseDecryptMessageData, parseStandardTokenTransactionData, readAddressAsContract, replayHistory, sanitizeNftMetdataUrl, singleBalanceCheckerAbi, snapshotFromTxMeta, subtractCurrencies, toChecksumAddressByChainId, toNegative, transactionMatchesNetwork, validateAddChainData, validateAddress, validateDecryptedMessageData, validateEncryptionPublicKeyMessageData, validateFrom, validateRecipient, validateSignMessageData, validateSwitchChainData, validateTxParameters, validateTypedSignMessageDataV1, validateTypedSignMessageDataV3V4 };
5996
+ export { ARBITRUM_MAINNET_CHAIN_ID, ARBITRUM_TESTNET_CHAIN_ID, AVALANCHE_MAINNET_CHAIN_ID, AVALANCHE_TESTNET_CHAIN_ID, AbstractMessageController, AccountTrackerController, AddChainController, BASE_CHAIN_ID, BASE_TESTNET_CHAIN_ID, BNToHex, BSC_MAINNET_CHAIN_ID, BSC_TESTNET_CHAIN_ID, CELO_MAINNET_CHAIN_ID, CHAIN_ID_TO_GAS_LIMIT_BUFFER_MAP, COINGECKO_PLATFORMS_CHAIN_CODE_MAP, COINGECKO_SUPPORTED_CURRENCIES, CONTRACT_TYPE_ERC1155, CONTRACT_TYPE_ERC20, CONTRACT_TYPE_ERC721, CONTRACT_TYPE_ETH, CurrencyController, DEFAULT_CURRENCY, ERC1155_INTERFACE_ID, ERC721_ENUMERABLE_INTERFACE_ID, ERC721_INTERFACE_ID, ERC721_METADATA_INTERFACE_ID, ETHERSCAN_SUPPORTED_CHAINS, GAS_ESTIMATE_TYPES, GAS_LIMITS, GasFeeController, KeyringController, LOCALHOST, MAINNET_CHAIN_ID, MESSAGE_EVENTS, METHOD_TYPES, MessageController, MessageStatus, NetworkController, NftHandler, NftsController, NonceTracker, OLD_ERC721_LIST, OPTIMISM_MAINNET_CHAIN_ID, OPTIMISM_TESTNET_CHAIN_ID, POLYGON_AMOY_CHAIN_ID, POLYGON_CHAIN_ID, PendingTransactionTracker, PersonalMessageController, PollingBlockTracker, PreferencesController, SEPOLIA_CHAIN_ID, SIMPLEHASH_SUPPORTED_CHAINS, SUPPORTED_NETWORKS, SwitchChainController, TEST_CHAINS, TRANSACTION_ENVELOPE_TYPES, TokenHandler, TokenRatesController, TokensController, TransactionController, TransactionGasUtil, TransactionStateManager, TypedMessageController, XDAI_CHAIN_ID, addCurrencies, addEtherscanTransactions, bnLessThan, conversionGTE, conversionGreaterThan, conversionLTE, conversionLessThan, conversionMax, conversionUtil, createChainIdMiddleware, createEthereumMiddleware, createGetAccountsMiddleware, createJsonRpcClient, createPendingNonceMiddleware, createPendingTxMiddleware, createProcessAddEthereumChain, createProcessEthSignMessage, createProcessPersonalMessage, createProcessSwitchEthereumChain, createProcessTransactionMiddleware, createProcessTypedMessageV4, createProviderConfigMiddleware, createRequestAccountsMiddleware, decGWEIToHexWEI, determineTransactionType, ensureFieldIsString, ensureMutuallyExclusiveFieldsNotProvided, erc1155Abi, erc20Abi, erc721Abi, formatDate, formatPastTx, formatTime, formatTxMetaForRpcResult, generateHistoryEntry, getBigNumber, getChainType, getEthTxStatus, getEtherScanHashLink, getFinalStates, getIpfsEndpoint, hexToBn, hexWEIToDecGWEI, idleTimeTracker, isAddressByChainId, isEIP1559Transaction, isLegacyTransaction, multiplyCurrencies, normalizeAndValidateTxParams, normalizeMessageData, normalizeTxParameters, parseStandardTokenTransactionData, readAddressAsContract, replayHistory, sanitizeNftMetdataUrl, singleBalanceCheckerAbi, snapshotFromTxMeta, subtractCurrencies, toChecksumAddressByChainId, toNegative, transactionMatchesNetwork, validateAddChainData, validateAddress, validateFrom, validateRecipient, validateSignMessageData, validateSwitchChainData, validateTxParameters, validateTypedSignMessageDataV4 };