@toruslabs/ethereum-controllers 6.0.4 → 6.1.1

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.
@@ -1,46 +1,7 @@
1
1
  /******/ (() => { // webpackBootstrap
2
2
  /******/ "use strict";
3
- /******/ var __webpack_modules__ = ({
4
-
5
- /***/ 652:
6
- /***/ ((module) => {
7
-
8
- module.exports = require("@ethereumjs/common");
9
-
10
- /***/ }),
11
-
12
- /***/ 81:
13
- /***/ ((module) => {
14
-
15
- module.exports = require("@ethereumjs/tx");
16
-
17
- /***/ })
18
-
19
- /******/ });
20
- /************************************************************************/
21
- /******/ // The module cache
22
- /******/ var __webpack_module_cache__ = {};
23
- /******/
24
- /******/ // The require function
25
- /******/ function __webpack_require__(moduleId) {
26
- /******/ // Check if module is in cache
27
- /******/ var cachedModule = __webpack_module_cache__[moduleId];
28
- /******/ if (cachedModule !== undefined) {
29
- /******/ return cachedModule.exports;
30
- /******/ }
31
- /******/ // Create a new module (and put it into the cache)
32
- /******/ var module = __webpack_module_cache__[moduleId] = {
33
- /******/ // no module.id needed
34
- /******/ // no module.loaded needed
35
- /******/ exports: {}
36
- /******/ };
37
- /******/
38
- /******/ // Execute the module function
39
- /******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
40
- /******/
41
- /******/ // Return the exports of the module
42
- /******/ return module.exports;
43
- /******/ }
3
+ /******/ // The require scope
4
+ /******/ var __webpack_require__ = {};
44
5
  /******/
45
6
  /************************************************************************/
46
7
  /******/ /* webpack/runtime/compat get default export */
@@ -55,36 +16,6 @@ module.exports = require("@ethereumjs/tx");
55
16
  /******/ };
56
17
  /******/ })();
57
18
  /******/
58
- /******/ /* webpack/runtime/create fake namespace object */
59
- /******/ (() => {
60
- /******/ var getProto = Object.getPrototypeOf ? (obj) => (Object.getPrototypeOf(obj)) : (obj) => (obj.__proto__);
61
- /******/ var leafPrototypes;
62
- /******/ // create a fake namespace object
63
- /******/ // mode & 1: value is a module id, require it
64
- /******/ // mode & 2: merge all properties of value into the ns
65
- /******/ // mode & 4: return value when already ns object
66
- /******/ // mode & 16: return value when it's Promise-like
67
- /******/ // mode & 8|1: behave like require
68
- /******/ __webpack_require__.t = function(value, mode) {
69
- /******/ if(mode & 1) value = this(value);
70
- /******/ if(mode & 8) return value;
71
- /******/ if(typeof value === 'object' && value) {
72
- /******/ if((mode & 4) && value.__esModule) return value;
73
- /******/ if((mode & 16) && typeof value.then === 'function') return value;
74
- /******/ }
75
- /******/ var ns = Object.create(null);
76
- /******/ __webpack_require__.r(ns);
77
- /******/ var def = {};
78
- /******/ leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];
79
- /******/ for(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {
80
- /******/ Object.getOwnPropertyNames(current).forEach((key) => (def[key] = () => (value[key])));
81
- /******/ }
82
- /******/ def['default'] = () => (value);
83
- /******/ __webpack_require__.d(ns, def);
84
- /******/ return ns;
85
- /******/ };
86
- /******/ })();
87
- /******/
88
19
  /******/ /* webpack/runtime/define property getters */
89
20
  /******/ (() => {
90
21
  /******/ // define getter functions for harmony exports
@@ -2627,12 +2558,11 @@ class KeyringController extends base_controllers_namespaceObject.BaseKeyringCont
2627
2558
  this.initialize();
2628
2559
  }
2629
2560
  async signTransaction(tx, address) {
2630
- const txPayload = tx;
2631
2561
  const wallet = this._getWalletForAccount(address);
2632
- const privKey = this.getBufferPrivateKey(wallet.privateKey);
2633
- const signedTx = txPayload.sign(privKey);
2634
- // Newer versions of Ethereumjs-tx are immutable and return a new tx object
2635
- return signedTx === undefined ? tx : signedTx;
2562
+ const privKey = new external_ethers_namespaceObject.SigningKey((0,util_namespaceObject.addHexPrefix)(wallet.privateKey));
2563
+ const localTx = tx;
2564
+ localTx.signature = privKey.sign(localTx.unsignedHash);
2565
+ return localTx;
2636
2566
  }
2637
2567
  getAccounts() {
2638
2568
  return this.state.wallets.map(w => w.publicKey);
@@ -5185,11 +5115,14 @@ class TokensController extends base_controllers_namespaceObject.BaseController {
5185
5115
  chainId: x.chainId
5186
5116
  };
5187
5117
  } catch (error) {
5188
- external_loglevel_default().warn("Invalid contract address while fetching", error);
5118
+ external_loglevel_default().warn("could not fetch user token balance", error);
5189
5119
  return undefined;
5190
5120
  }
5191
5121
  }));
5192
- const nonZeroTokens = promiseSettledResult.filter(x => x.status === "fulfilled").map(x => x.value);
5122
+ const nonZeroTokens = promiseSettledResult.reduce((acc, x) => {
5123
+ if (x.status === "fulfilled" && x.value) acc.push(x.value);
5124
+ return acc;
5125
+ }, []);
5193
5126
  this.update({
5194
5127
  tokens: {
5195
5128
  [this.userSelectedAddress]: mergeTokenArrays(this.userTokens, nonZeroTokens)
@@ -6018,7 +5951,6 @@ class TransactionController extends TransactionStateManager {
6018
5951
  signEthTx,
6019
5952
  getCurrentChainId,
6020
5953
  getCurrentNetworkEIP1559Compatibility,
6021
- getProviderConfig,
6022
5954
  getCurrentAccountEIP1559Compatibility,
6023
5955
  getSelectedAddress,
6024
5956
  getEIP1559GasFeeEstimates
@@ -6035,7 +5967,6 @@ class TransactionController extends TransactionStateManager {
6035
5967
  defineProperty_default()(this, "txGasUtil", void 0);
6036
5968
  defineProperty_default()(this, "_getCurrentNetworkEIP1559Compatibility", void 0);
6037
5969
  defineProperty_default()(this, "_getCurrentAccountEIP1559Compatibility", void 0);
6038
- defineProperty_default()(this, "getProviderConfig", void 0);
6039
5970
  defineProperty_default()(this, "signEthTx", void 0);
6040
5971
  defineProperty_default()(this, "provider", void 0);
6041
5972
  defineProperty_default()(this, "blockTracker", void 0);
@@ -6043,7 +5974,6 @@ class TransactionController extends TransactionStateManager {
6043
5974
  defineProperty_default()(this, "getUnapprovedTxCount", () => Object.keys(this.getUnapprovedTxList()).length);
6044
5975
  defineProperty_default()(this, "getPendingTxCount", account => this.getPendingTransactions(account).length);
6045
5976
  this.blockTracker = blockTracker;
6046
- this.getProviderConfig = getProviderConfig;
6047
5977
  this._getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
6048
5978
  this._getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility;
6049
5979
  this.getSelectedAddress = getSelectedAddress;
@@ -6144,27 +6074,27 @@ class TransactionController extends TransactionStateManager {
6144
6074
  const txMeta = this.getTransaction(txId);
6145
6075
  const chainId = this.getCurrentChainId();
6146
6076
  const type = isEIP1559Transaction(txMeta) ? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : TRANSACTION_ENVELOPE_TYPES.LEGACY;
6147
- const txParams = objectSpread2_default()(objectSpread2_default()({}, txMeta.transaction), {}, {
6148
- type,
6077
+ const txParams = {
6078
+ type: Number.parseInt(type, 16),
6149
6079
  chainId,
6150
- gasLimit: txMeta.transaction.gas
6151
- });
6152
- const fromAddress = txParams.from;
6153
- const common = await this.getCommonConfiguration(fromAddress);
6154
- const {
6155
- TransactionFactory
6156
- } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 81, 23));
6157
- // TODO: fix this when @ethereumjs/tx is updated.
6158
- const unsignedEthTx = TransactionFactory.fromTxData(txParams, {
6159
- common
6160
- });
6161
- const signedEthTx = await this.signEthTx(unsignedEthTx, fromAddress);
6162
- txMeta.r = (0,util_namespaceObject.addHexPrefix)(signedEthTx.r.toString(16));
6163
- txMeta.s = (0,util_namespaceObject.addHexPrefix)(signedEthTx.s.toString(16));
6164
- txMeta.v = (0,util_namespaceObject.addHexPrefix)(signedEthTx.v.toString(16));
6080
+ gasLimit: txMeta.transaction.gas,
6081
+ accessList: txMeta.transaction.accessList,
6082
+ data: txMeta.transaction.data,
6083
+ gasPrice: txMeta.transaction.gasPrice,
6084
+ maxFeePerGas: txMeta.transaction.maxFeePerGas,
6085
+ maxPriorityFeePerGas: txMeta.transaction.maxPriorityFeePerGas,
6086
+ nonce: Number.parseInt(txMeta.transaction.nonce, 16),
6087
+ to: txMeta.transaction.to
6088
+ };
6089
+ const fromAddress = txMeta.transaction.from;
6090
+ const tx = external_ethers_namespaceObject.Transaction.from(txParams);
6091
+ const signedEthTx = await this.signEthTx(tx, fromAddress);
6092
+ txMeta.r = signedEthTx.signature.r;
6093
+ txMeta.s = signedEthTx.signature.s;
6094
+ txMeta.v = (0,util_namespaceObject.addHexPrefix)(signedEthTx.signature.v.toString(16));
6165
6095
  this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values");
6166
6096
  this.setTxStatusSigned(txId);
6167
- const rawTx = (0,util_namespaceObject.addHexPrefix)(Buffer.from(signedEthTx.serialize()).toString("hex"));
6097
+ const rawTx = signedEthTx.serialized;
6168
6098
  return rawTx;
6169
6099
  }
6170
6100
  async publishTransaction(txId, rawTx) {
@@ -6465,24 +6395,6 @@ class TransactionController extends TransactionStateManager {
6465
6395
  external_loglevel_default().error(error);
6466
6396
  }
6467
6397
  }
6468
- async getCommonConfiguration(fromAddress) {
6469
- const {
6470
- chainId,
6471
- displayName
6472
- } = this.getProviderConfig();
6473
- const supportsEIP1559 = await this.getEIP1559Compatibility(fromAddress);
6474
- const {
6475
- Common,
6476
- Hardfork
6477
- } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 652, 23));
6478
- const hardfork = supportsEIP1559 ? Hardfork.Paris : Hardfork.Berlin;
6479
- return Common.custom({
6480
- chainId: chainId === "loading" ? 0 : Number.parseInt(chainId, 16),
6481
- defaultHardfork: hardfork,
6482
- name: displayName,
6483
- networkId: chainId === "loading" ? 0 : Number.parseInt(chainId, 16)
6484
- });
6485
- }
6486
6398
  markNonceDuplicatesDropped(txId) {
6487
6399
  const txMeta = this.getTransaction(txId);
6488
6400
  const {
@@ -2,7 +2,7 @@ import _objectSpread from '@babel/runtime/helpers/objectSpread2';
2
2
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
3
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, SigningKey, hashMessage, TypedDataEncoder, isHexString as isHexString$1, JsonRpcProvider, keccak256 } from 'ethers';
5
+ import { BrowserProvider, toQuantity, Contract, Interface, SigningKey, hashMessage, TypedDataEncoder, isHexString as isHexString$1, JsonRpcProvider, Transaction, 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';
@@ -2274,12 +2274,11 @@ class KeyringController extends BaseKeyringController {
2274
2274
  this.initialize();
2275
2275
  }
2276
2276
  async signTransaction(tx, address) {
2277
- const txPayload = tx;
2278
2277
  const wallet = this._getWalletForAccount(address);
2279
- const privKey = this.getBufferPrivateKey(wallet.privateKey);
2280
- const signedTx = txPayload.sign(privKey);
2281
- // Newer versions of Ethereumjs-tx are immutable and return a new tx object
2282
- return signedTx === undefined ? tx : signedTx;
2278
+ const privKey = new SigningKey(addHexPrefix(wallet.privateKey));
2279
+ const localTx = tx;
2280
+ localTx.signature = privKey.sign(localTx.unsignedHash);
2281
+ return localTx;
2283
2282
  }
2284
2283
  getAccounts() {
2285
2284
  return this.state.wallets.map(w => w.publicKey);
@@ -4721,11 +4720,14 @@ class TokensController extends BaseController {
4721
4720
  chainId: x.chainId
4722
4721
  };
4723
4722
  } catch (error) {
4724
- log.warn("Invalid contract address while fetching", error);
4723
+ log.warn("could not fetch user token balance", error);
4725
4724
  return undefined;
4726
4725
  }
4727
4726
  }));
4728
- const nonZeroTokens = promiseSettledResult.filter(x => x.status === "fulfilled").map(x => x.value);
4727
+ const nonZeroTokens = promiseSettledResult.reduce((acc, x) => {
4728
+ if (x.status === "fulfilled" && x.value) acc.push(x.value);
4729
+ return acc;
4730
+ }, []);
4729
4731
  this.update({
4730
4732
  tokens: {
4731
4733
  [this.userSelectedAddress]: mergeTokenArrays(this.userTokens, nonZeroTokens)
@@ -5511,7 +5513,6 @@ class TransactionController extends TransactionStateManager {
5511
5513
  signEthTx,
5512
5514
  getCurrentChainId,
5513
5515
  getCurrentNetworkEIP1559Compatibility,
5514
- getProviderConfig,
5515
5516
  getCurrentAccountEIP1559Compatibility,
5516
5517
  getSelectedAddress,
5517
5518
  getEIP1559GasFeeEstimates
@@ -5528,7 +5529,6 @@ class TransactionController extends TransactionStateManager {
5528
5529
  _defineProperty(this, "txGasUtil", void 0);
5529
5530
  _defineProperty(this, "_getCurrentNetworkEIP1559Compatibility", void 0);
5530
5531
  _defineProperty(this, "_getCurrentAccountEIP1559Compatibility", void 0);
5531
- _defineProperty(this, "getProviderConfig", void 0);
5532
5532
  _defineProperty(this, "signEthTx", void 0);
5533
5533
  _defineProperty(this, "provider", void 0);
5534
5534
  _defineProperty(this, "blockTracker", void 0);
@@ -5536,7 +5536,6 @@ class TransactionController extends TransactionStateManager {
5536
5536
  _defineProperty(this, "getUnapprovedTxCount", () => Object.keys(this.getUnapprovedTxList()).length);
5537
5537
  _defineProperty(this, "getPendingTxCount", account => this.getPendingTransactions(account).length);
5538
5538
  this.blockTracker = blockTracker;
5539
- this.getProviderConfig = getProviderConfig;
5540
5539
  this._getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
5541
5540
  this._getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility;
5542
5541
  this.getSelectedAddress = getSelectedAddress;
@@ -5637,27 +5636,27 @@ class TransactionController extends TransactionStateManager {
5637
5636
  const txMeta = this.getTransaction(txId);
5638
5637
  const chainId = this.getCurrentChainId();
5639
5638
  const type = isEIP1559Transaction(txMeta) ? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : TRANSACTION_ENVELOPE_TYPES.LEGACY;
5640
- const txParams = _objectSpread(_objectSpread({}, txMeta.transaction), {}, {
5641
- type,
5639
+ const txParams = {
5640
+ type: Number.parseInt(type, 16),
5642
5641
  chainId,
5643
- gasLimit: txMeta.transaction.gas
5644
- });
5645
- const fromAddress = txParams.from;
5646
- const common = await this.getCommonConfiguration(fromAddress);
5647
- const {
5648
- TransactionFactory
5649
- } = await import('@ethereumjs/tx');
5650
- // TODO: fix this when @ethereumjs/tx is updated.
5651
- const unsignedEthTx = TransactionFactory.fromTxData(txParams, {
5652
- common
5653
- });
5654
- const signedEthTx = await this.signEthTx(unsignedEthTx, fromAddress);
5655
- txMeta.r = addHexPrefix(signedEthTx.r.toString(16));
5656
- txMeta.s = addHexPrefix(signedEthTx.s.toString(16));
5657
- txMeta.v = addHexPrefix(signedEthTx.v.toString(16));
5642
+ gasLimit: txMeta.transaction.gas,
5643
+ accessList: txMeta.transaction.accessList,
5644
+ data: txMeta.transaction.data,
5645
+ gasPrice: txMeta.transaction.gasPrice,
5646
+ maxFeePerGas: txMeta.transaction.maxFeePerGas,
5647
+ maxPriorityFeePerGas: txMeta.transaction.maxPriorityFeePerGas,
5648
+ nonce: Number.parseInt(txMeta.transaction.nonce, 16),
5649
+ to: txMeta.transaction.to
5650
+ };
5651
+ const fromAddress = txMeta.transaction.from;
5652
+ const tx = Transaction.from(txParams);
5653
+ const signedEthTx = await this.signEthTx(tx, fromAddress);
5654
+ txMeta.r = signedEthTx.signature.r;
5655
+ txMeta.s = signedEthTx.signature.s;
5656
+ txMeta.v = addHexPrefix(signedEthTx.signature.v.toString(16));
5658
5657
  this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values");
5659
5658
  this.setTxStatusSigned(txId);
5660
- const rawTx = addHexPrefix(Buffer.from(signedEthTx.serialize()).toString("hex"));
5659
+ const rawTx = signedEthTx.serialized;
5661
5660
  return rawTx;
5662
5661
  }
5663
5662
  async publishTransaction(txId, rawTx) {
@@ -5958,24 +5957,6 @@ class TransactionController extends TransactionStateManager {
5958
5957
  log.error(error);
5959
5958
  }
5960
5959
  }
5961
- async getCommonConfiguration(fromAddress) {
5962
- const {
5963
- chainId,
5964
- displayName
5965
- } = this.getProviderConfig();
5966
- const supportsEIP1559 = await this.getEIP1559Compatibility(fromAddress);
5967
- const {
5968
- Common,
5969
- Hardfork
5970
- } = await import('@ethereumjs/common');
5971
- const hardfork = supportsEIP1559 ? Hardfork.Paris : Hardfork.Berlin;
5972
- return Common.custom({
5973
- chainId: chainId === "loading" ? 0 : Number.parseInt(chainId, 16),
5974
- defaultHardfork: hardfork,
5975
- name: displayName,
5976
- networkId: chainId === "loading" ? 0 : Number.parseInt(chainId, 16)
5977
- });
5978
- }
5979
5960
  markNonceDuplicatesDropped(txId) {
5980
5961
  const txMeta = this.getTransaction(txId);
5981
5962
  const {