@toruslabs/ethereum-controllers 4.2.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),
@@ -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);
@@ -4264,7 +4265,6 @@ class TokensController extends base_controllers_namespaceObject.BaseController {
4264
4265
  config,
4265
4266
  state,
4266
4267
  provider,
4267
- getNetworkIdentifier,
4268
4268
  getCustomTokens,
4269
4269
  getEtherScanTokens,
4270
4270
  getProviderConfig,
@@ -4279,13 +4279,11 @@ class TokensController extends base_controllers_namespaceObject.BaseController {
4279
4279
  defineProperty_default()(this, "provider", void 0);
4280
4280
  defineProperty_default()(this, "ethersProvider", void 0);
4281
4281
  defineProperty_default()(this, "_timer", void 0);
4282
- defineProperty_default()(this, "getNetworkIdentifier", void 0);
4283
4282
  defineProperty_default()(this, "getProviderConfig", void 0);
4284
4283
  defineProperty_default()(this, "getCustomTokens", void 0);
4285
4284
  defineProperty_default()(this, "getEtherScanTokens", void 0);
4286
4285
  this.provider = provider;
4287
4286
  this.ethersProvider = new external_ethers_namespaceObject.BrowserProvider(this.provider, "any");
4288
- this.getNetworkIdentifier = getNetworkIdentifier;
4289
4287
  this.getCustomTokens = getCustomTokens;
4290
4288
  this.getEtherScanTokens = getEtherScanTokens;
4291
4289
  this.getProviderConfig = getProviderConfig;
@@ -4364,7 +4362,7 @@ class TokensController extends base_controllers_namespaceObject.BaseController {
4364
4362
  detectNewTokens() {
4365
4363
  const userAddress = this.userSelectedAddress;
4366
4364
  if (!userAddress) return;
4367
- const currentChainId = this.getNetworkIdentifier();
4365
+ const currentChainId = this.config.chainId;
4368
4366
  const tokens = []; // object[]
4369
4367
  if (!currentChainId) {
4370
4368
  this.update({
@@ -4416,7 +4414,7 @@ class TokensController extends base_controllers_namespaceObject.BaseController {
4416
4414
  const tokenAddresses = oldTokens.map(x => x.tokenAddress);
4417
4415
  const nonZeroTokens = [];
4418
4416
  try {
4419
- const currentChainId = this.getNetworkIdentifier();
4417
+ const currentChainId = this.config.chainId;
4420
4418
  if (ETHERSCAN_SUPPORTED_CHAINS.includes(currentChainId)) {
4421
4419
  const etherscanBalances = await this.getEtherScanTokens(userAddress, currentChainId);
4422
4420
  nonZeroTokens.push(...etherscanBalances);
@@ -5360,7 +5358,7 @@ class TransactionStateManager extends base_controllers_namespaceObject.BaseTrans
5360
5358
  }
5361
5359
  }
5362
5360
  return objectSpread2_default()({
5363
- id: (0,base_controllers_namespaceObject.randomId)(),
5361
+ id: opts.transaction.id || (0,base_controllers_namespaceObject.randomId)(),
5364
5362
  time: Date.now(),
5365
5363
  status: base_controllers_namespaceObject.TransactionStatus.unapproved,
5366
5364
  loadingDefaults: true,