@toruslabs/ethereum-controllers 4.1.0 → 4.3.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.
@@ -82,6 +82,7 @@ __webpack_require__.d(__webpack_exports__, {
82
82
  KeyringController: () => (/* reexport */ KeyringController),
83
83
  LOCALHOST: () => (/* reexport */ LOCALHOST),
84
84
  MAINNET_CHAIN_ID: () => (/* reexport */ MAINNET_CHAIN_ID),
85
+ MESSAGE_EVENTS: () => (/* reexport */ MESSAGE_EVENTS),
85
86
  METHOD_TYPES: () => (/* reexport */ METHOD_TYPES),
86
87
  MessageController: () => (/* reexport */ MessageController),
87
88
  MessageStatus: () => (/* reexport */ MessageStatus),
@@ -792,7 +793,7 @@ const SUPPORTED_NETWORKS = {
792
793
  rpcTarget: `https://goerli.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
793
794
  ticker: "ETH",
794
795
  tickerName: "Ethereum",
795
- isTestNet: true
796
+ isTestnet: true
796
797
  },
797
798
  [SEPOLIA_CHAIN_ID]: {
798
799
  blockExplorerUrl: "https://sepolia.etherscan.io",
@@ -802,7 +803,7 @@ const SUPPORTED_NETWORKS = {
802
803
  rpcTarget: `https://sepolia.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
803
804
  ticker: "ETH",
804
805
  tickerName: "Ethereum",
805
- isTestNet: true
806
+ isTestnet: true
806
807
  },
807
808
  [POLYGON_MUMBAI_CHAIN_ID]: {
808
809
  blockExplorerUrl: "https://mumbai.polygonscan.com",
@@ -812,7 +813,7 @@ const SUPPORTED_NETWORKS = {
812
813
  rpcTarget: `https://polygon-mumbai.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
813
814
  ticker: "MATIC",
814
815
  tickerName: "Matic Network Token",
815
- isTestNet: true
816
+ isTestnet: true
816
817
  },
817
818
  [BSC_TESTNET_CHAIN_ID]: {
818
819
  blockExplorerUrl: "https://testnet.bscscan.com",
@@ -822,7 +823,7 @@ const SUPPORTED_NETWORKS = {
822
823
  rpcTarget: `https://data-seed-prebsc-1-s1.binance.org:8545`,
823
824
  ticker: "BNB",
824
825
  tickerName: "Binance Coin",
825
- isTestNet: true
826
+ isTestnet: true
826
827
  },
827
828
  [AVALANCHE_TESTNET_CHAIN_ID]: {
828
829
  blockExplorerUrl: "https://testnet.snowtrace.io",
@@ -832,7 +833,7 @@ const SUPPORTED_NETWORKS = {
832
833
  rpcTarget: `https://api.avax-test.network/ext/bc/C/rpc`,
833
834
  ticker: "AVAX",
834
835
  tickerName: "Avalanche",
835
- isTestNet: true
836
+ isTestnet: true
836
837
  },
837
838
  [ARBITRUM_TESTNET_CHAIN_ID]: {
838
839
  blockExplorerUrl: "https://testnet.arbiscan.io",
@@ -842,7 +843,7 @@ const SUPPORTED_NETWORKS = {
842
843
  rpcTarget: `https://arbitrum-rinkeby.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
843
844
  ticker: "ETH",
844
845
  tickerName: "Ethereum",
845
- isTestNet: true
846
+ isTestnet: true
846
847
  },
847
848
  [OPTIMISM_TESTNET_CHAIN_ID]: {
848
849
  blockExplorerUrl: "https://goerli-optimism.etherscan.io",
@@ -852,7 +853,7 @@ const SUPPORTED_NETWORKS = {
852
853
  rpcTarget: `https://optimism-goerli.infura.io/v3/${process.env.VITE_APP_INFURA_PROJECT_KEY}`,
853
854
  ticker: "ETH",
854
855
  tickerName: "Ethereum",
855
- isTestNet: true
856
+ isTestnet: true
856
857
  }
857
858
  };
858
859
  const METHOD_TYPES = {
@@ -958,6 +959,9 @@ const MessageStatus = {
958
959
  REJECTED: "rejected",
959
960
  FAILED: "failed"
960
961
  };
962
+ const MESSAGE_EVENTS = {
963
+ UNAPPROVED_MESSAGE: "unapprovedMessage"
964
+ };
961
965
  ;// CONCATENATED MODULE: ./src/utils/contractAddresses.ts
962
966
 
963
967
  const SINGLE_CALL_BALANCES_ADDRESSES = {
@@ -2240,8 +2244,8 @@ class AbstractMessageController extends base_controllers_namespaceObject.BaseCon
2240
2244
  this.messages.push(message);
2241
2245
  this.saveMessageList();
2242
2246
  }
2243
- approveMessage(messageParams) {
2244
- this.setMessageStatus(messageParams.id, MessageStatus.APPROVED);
2247
+ approveMessage(messageId, messageParams) {
2248
+ this.setMessageStatus(messageId, MessageStatus.APPROVED);
2245
2249
  return this.prepMessageForSigning(messageParams);
2246
2250
  }
2247
2251
  setMessageStatus(messageId, status) {
@@ -2417,7 +2421,7 @@ class DecryptMessageController extends AbstractMessageController {
2417
2421
  async processDecryptMessage(messageId) {
2418
2422
  try {
2419
2423
  const msgObject = this.getMessage(messageId);
2420
- const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
2424
+ const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2421
2425
  const parsedData = parseDecryptMessageData(cleanMsgParams.data);
2422
2426
  const rawSig = this.decryptMessage(parsedData, cleanMsgParams.from);
2423
2427
  this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
@@ -2449,7 +2453,7 @@ class DecryptMessageController extends AbstractMessageController {
2449
2453
  type: METHOD_TYPES.ETH_DECRYPT
2450
2454
  };
2451
2455
  await this.addMessage(messageData);
2452
- this.emit(`unapprovedMessage`, objectSpread2_default()({}, messageParams));
2456
+ this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
2453
2457
  return messageId;
2454
2458
  }
2455
2459
  prepMessageForSigning(messageParams) {
@@ -2486,7 +2490,7 @@ class EncryptionPublicKeyController extends AbstractMessageController {
2486
2490
  async processGetEncryptionPublicKey(messageId) {
2487
2491
  try {
2488
2492
  const msgObject = this.getMessage(messageId);
2489
- const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
2493
+ const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2490
2494
  const publicKey = this.signEncryptionPublicKey(cleanMsgParams.from);
2491
2495
  this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
2492
2496
  rawSig: publicKey
@@ -2516,7 +2520,7 @@ class EncryptionPublicKeyController extends AbstractMessageController {
2516
2520
  type: METHOD_TYPES.ETH_GET_ENCRYPTION_PUBLIC_KEY
2517
2521
  };
2518
2522
  await this.addMessage(messageData);
2519
- this.emit(`unapprovedMessage`, objectSpread2_default()({}, messageParams));
2523
+ this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
2520
2524
  return messageId;
2521
2525
  }
2522
2526
  prepMessageForSigning(messageParams) {
@@ -2555,7 +2559,7 @@ class MessageController extends AbstractMessageController {
2555
2559
  async processSignMessage(messageId) {
2556
2560
  try {
2557
2561
  const msgObject = this.getMessage(messageId);
2558
- const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
2562
+ const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2559
2563
  const rawSig = this.signMessage(cleanMsgParams.data, cleanMsgParams.from);
2560
2564
  this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
2561
2565
  rawSig
@@ -2586,7 +2590,7 @@ class MessageController extends AbstractMessageController {
2586
2590
  type: METHOD_TYPES.ETH_SIGN
2587
2591
  };
2588
2592
  await this.addMessage(messageData);
2589
- this.emit(`unapprovedMessage`, messageParams);
2593
+ this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
2590
2594
  return messageId;
2591
2595
  }
2592
2596
  prepMessageForSigning(messageParams) {
@@ -2622,7 +2626,7 @@ class PersonalMessageController extends AbstractMessageController {
2622
2626
  async processPersonalSignMessage(messageId) {
2623
2627
  try {
2624
2628
  const msgObject = this.getMessage(messageId);
2625
- const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
2629
+ const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2626
2630
  const rawSig = await this.signPersonalMessage(cleanMsgParams.data, cleanMsgParams.from);
2627
2631
  this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
2628
2632
  rawSig
@@ -2644,7 +2648,7 @@ class PersonalMessageController extends AbstractMessageController {
2644
2648
  messageParams.origin = req.origin;
2645
2649
  }
2646
2650
  messageParams.data = normalizeMessageData(messageParams.data);
2647
- const messageId = (0,base_controllers_namespaceObject.randomId)();
2651
+ const messageId = messageParams.id || (0,base_controllers_namespaceObject.randomId)();
2648
2652
  const messageData = {
2649
2653
  id: messageId,
2650
2654
  messageParams,
@@ -2653,7 +2657,7 @@ class PersonalMessageController extends AbstractMessageController {
2653
2657
  type: METHOD_TYPES.PERSONAL_SIGN
2654
2658
  };
2655
2659
  await this.addMessage(messageData);
2656
- this.emit(`unapprovedMessage`, messageParams);
2660
+ this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
2657
2661
  return messageId;
2658
2662
  }
2659
2663
  prepMessageForSigning(messageParams) {
@@ -2702,7 +2706,7 @@ class TypedMessageController extends AbstractMessageController {
2702
2706
  async processPersonalSignMessage(messageId) {
2703
2707
  try {
2704
2708
  const msgObject = this.getMessage(messageId);
2705
- const cleanMsgParams = await this.approveMessage(msgObject.messageParams);
2709
+ const cleanMsgParams = await this.approveMessage(messageId, msgObject.messageParams);
2706
2710
  const rawSig = await this.signTypedData(cleanMsgParams.data, cleanMsgParams.from, cleanMsgParams.version);
2707
2711
  this.updateMessage(objectSpread2_default()(objectSpread2_default()({}, msgObject), {}, {
2708
2712
  rawSig
@@ -2742,7 +2746,7 @@ class TypedMessageController extends AbstractMessageController {
2742
2746
  type: getMessageType(version)
2743
2747
  };
2744
2748
  await this.addMessage(messageData);
2745
- this.emit(`unapprovedMessage`, messageParams);
2749
+ this.emit(MESSAGE_EVENTS.UNAPPROVED_MESSAGE, messageData);
2746
2750
  return messageId;
2747
2751
  }
2748
2752
  prepMessageForSigning(messageParams) {
@@ -3470,7 +3474,6 @@ class NftsController extends base_controllers_namespaceObject.BaseController {
3470
3474
  config,
3471
3475
  state,
3472
3476
  provider,
3473
- getNetworkIdentifier,
3474
3477
  getCustomNfts,
3475
3478
  getSimpleHashNfts,
3476
3479
  onPreferencesStateChange,
@@ -3484,12 +3487,10 @@ class NftsController extends base_controllers_namespaceObject.BaseController {
3484
3487
  defineProperty_default()(this, "provider", void 0);
3485
3488
  defineProperty_default()(this, "ethersProvider", void 0);
3486
3489
  defineProperty_default()(this, "_timer", void 0);
3487
- defineProperty_default()(this, "getNetworkIdentifier", void 0);
3488
3490
  defineProperty_default()(this, "getCustomNfts", void 0);
3489
3491
  defineProperty_default()(this, "getSimpleHashNfts", void 0);
3490
3492
  this.provider = provider;
3491
3493
  this.ethersProvider = new external_ethers_namespaceObject.BrowserProvider(this.provider, "any");
3492
- this.getNetworkIdentifier = getNetworkIdentifier;
3493
3494
  this.getCustomNfts = getCustomNfts;
3494
3495
  this.getSimpleHashNfts = getSimpleHashNfts;
3495
3496
  this.defaultConfig = {
@@ -3567,7 +3568,7 @@ class NftsController extends base_controllers_namespaceObject.BaseController {
3567
3568
  detectNewNfts() {
3568
3569
  const userAddress = this.userSelectedAddress;
3569
3570
  if (!userAddress) return;
3570
- const currentChainId = this.getNetworkIdentifier();
3571
+ const currentChainId = this.config.chainId;
3571
3572
  const nftsToDetect = []; // object[]
3572
3573
  if (!currentChainId) {
3573
3574
  this.update({
@@ -3622,7 +3623,7 @@ class NftsController extends base_controllers_namespaceObject.BaseController {
3622
3623
  const oldNfts = [...this.userNfts];
3623
3624
  const nonZeroNfts = [];
3624
3625
  try {
3625
- const currentChainId = this.getNetworkIdentifier();
3626
+ const currentChainId = this.config.chainId;
3626
3627
  if (SIMPLEHASH_SUPPORTED_CHAINS.includes(currentChainId)) {
3627
3628
  const simpleHashBalances = await this.getSimpleHashNfts(userAddress, currentChainId);
3628
3629
  nonZeroNfts.push(...simpleHashBalances);
@@ -3729,9 +3730,13 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
3729
3730
  calledFromEmbed,
3730
3731
  userInfo,
3731
3732
  rehydrate,
3732
- locale = "en-US"
3733
+ locale = "en-US",
3734
+ type
3733
3735
  } = params;
3734
- await super.init(address, userInfo, jwtToken);
3736
+ await super.init(address, userInfo, jwtToken, {
3737
+ type,
3738
+ email: userInfo.email
3739
+ });
3735
3740
  const {
3736
3741
  aggregateVerifier,
3737
3742
  verifier,
@@ -3862,6 +3867,17 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
3862
3867
  // }
3863
3868
  }
3864
3869
  }
3870
+ async fetchEtherscanTx(parameters) {
3871
+ try {
3872
+ const url = new URL(`${this.config.api}/etherscan`);
3873
+ Object.keys(parameters).forEach(key => url.searchParams.append(key, parameters[key]));
3874
+ const response = await (0,http_helpers_namespaceObject.get)(url.href, this.headers(parameters.selectedAddress));
3875
+ return response.success ? response.data : [];
3876
+ } catch (error) {
3877
+ external_loglevel_default().error("unable to fetch etherscan tx", error);
3878
+ return [];
3879
+ }
3880
+ }
3865
3881
  async getEtherScanTokens(address, chainId) {
3866
3882
  const selectedAddress = address;
3867
3883
  const apiUrl = new URL(this.config.api);
@@ -3907,7 +3923,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
3907
3923
  chain_id: network.chainId,
3908
3924
  symbol: network.ticker,
3909
3925
  block_explorer_url: network.blockExplorerUrl || undefined,
3910
- is_test_net: network.isTestNet || false
3926
+ is_test_net: network.isTestnet || false
3911
3927
  };
3912
3928
  const res = await (0,http_helpers_namespaceObject.post)(apiUrl.href, payload, this.headers(selectedAddress), {
3913
3929
  useAPIKey: true
@@ -3953,7 +3969,7 @@ class PreferencesController extends base_controllers_namespaceObject.BasePrefere
3953
3969
  chain_id: network.chainId,
3954
3970
  symbol: network.ticker || undefined,
3955
3971
  block_explorer_url: network.blockExplorerUrl || undefined,
3956
- is_test_net: network.isTestNet || false
3972
+ is_test_net: network.isTestnet || false
3957
3973
  };
3958
3974
  await (0,http_helpers_namespaceObject.patch)(apiUrl.href, payload, this.headers(selectedAddress), {
3959
3975
  useAPIKey: true
@@ -4249,7 +4265,6 @@ class TokensController extends base_controllers_namespaceObject.BaseController {
4249
4265
  config,
4250
4266
  state,
4251
4267
  provider,
4252
- getNetworkIdentifier,
4253
4268
  getCustomTokens,
4254
4269
  getEtherScanTokens,
4255
4270
  getProviderConfig,
@@ -4264,13 +4279,11 @@ class TokensController extends base_controllers_namespaceObject.BaseController {
4264
4279
  defineProperty_default()(this, "provider", void 0);
4265
4280
  defineProperty_default()(this, "ethersProvider", void 0);
4266
4281
  defineProperty_default()(this, "_timer", void 0);
4267
- defineProperty_default()(this, "getNetworkIdentifier", void 0);
4268
4282
  defineProperty_default()(this, "getProviderConfig", void 0);
4269
4283
  defineProperty_default()(this, "getCustomTokens", void 0);
4270
4284
  defineProperty_default()(this, "getEtherScanTokens", void 0);
4271
4285
  this.provider = provider;
4272
4286
  this.ethersProvider = new external_ethers_namespaceObject.BrowserProvider(this.provider, "any");
4273
- this.getNetworkIdentifier = getNetworkIdentifier;
4274
4287
  this.getCustomTokens = getCustomTokens;
4275
4288
  this.getEtherScanTokens = getEtherScanTokens;
4276
4289
  this.getProviderConfig = getProviderConfig;
@@ -4349,7 +4362,7 @@ class TokensController extends base_controllers_namespaceObject.BaseController {
4349
4362
  detectNewTokens() {
4350
4363
  const userAddress = this.userSelectedAddress;
4351
4364
  if (!userAddress) return;
4352
- const currentChainId = this.getNetworkIdentifier();
4365
+ const currentChainId = this.config.chainId;
4353
4366
  const tokens = []; // object[]
4354
4367
  if (!currentChainId) {
4355
4368
  this.update({
@@ -4401,7 +4414,7 @@ class TokensController extends base_controllers_namespaceObject.BaseController {
4401
4414
  const tokenAddresses = oldTokens.map(x => x.tokenAddress);
4402
4415
  const nonZeroTokens = [];
4403
4416
  try {
4404
- const currentChainId = this.getNetworkIdentifier();
4417
+ const currentChainId = this.config.chainId;
4405
4418
  if (ETHERSCAN_SUPPORTED_CHAINS.includes(currentChainId)) {
4406
4419
  const etherscanBalances = await this.getEtherScanTokens(userAddress, currentChainId);
4407
4420
  nonZeroTokens.push(...etherscanBalances);
@@ -5345,7 +5358,7 @@ class TransactionStateManager extends base_controllers_namespaceObject.BaseTrans
5345
5358
  }
5346
5359
  }
5347
5360
  return objectSpread2_default()({
5348
- id: (0,base_controllers_namespaceObject.randomId)(),
5361
+ id: opts.transaction.id || (0,base_controllers_namespaceObject.randomId)(),
5349
5362
  time: Date.now(),
5350
5363
  status: base_controllers_namespaceObject.TransactionStatus.unapproved,
5351
5364
  loadingDefaults: true,