@toruslabs/ethereum-controllers 6.0.4 → 6.1.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.
@@ -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);
@@ -6018,7 +5948,6 @@ class TransactionController extends TransactionStateManager {
6018
5948
  signEthTx,
6019
5949
  getCurrentChainId,
6020
5950
  getCurrentNetworkEIP1559Compatibility,
6021
- getProviderConfig,
6022
5951
  getCurrentAccountEIP1559Compatibility,
6023
5952
  getSelectedAddress,
6024
5953
  getEIP1559GasFeeEstimates
@@ -6035,7 +5964,6 @@ class TransactionController extends TransactionStateManager {
6035
5964
  defineProperty_default()(this, "txGasUtil", void 0);
6036
5965
  defineProperty_default()(this, "_getCurrentNetworkEIP1559Compatibility", void 0);
6037
5966
  defineProperty_default()(this, "_getCurrentAccountEIP1559Compatibility", void 0);
6038
- defineProperty_default()(this, "getProviderConfig", void 0);
6039
5967
  defineProperty_default()(this, "signEthTx", void 0);
6040
5968
  defineProperty_default()(this, "provider", void 0);
6041
5969
  defineProperty_default()(this, "blockTracker", void 0);
@@ -6043,7 +5971,6 @@ class TransactionController extends TransactionStateManager {
6043
5971
  defineProperty_default()(this, "getUnapprovedTxCount", () => Object.keys(this.getUnapprovedTxList()).length);
6044
5972
  defineProperty_default()(this, "getPendingTxCount", account => this.getPendingTransactions(account).length);
6045
5973
  this.blockTracker = blockTracker;
6046
- this.getProviderConfig = getProviderConfig;
6047
5974
  this._getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
6048
5975
  this._getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility;
6049
5976
  this.getSelectedAddress = getSelectedAddress;
@@ -6144,27 +6071,27 @@ class TransactionController extends TransactionStateManager {
6144
6071
  const txMeta = this.getTransaction(txId);
6145
6072
  const chainId = this.getCurrentChainId();
6146
6073
  const type = isEIP1559Transaction(txMeta) ? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : TRANSACTION_ENVELOPE_TYPES.LEGACY;
6147
- const txParams = objectSpread2_default()(objectSpread2_default()({}, txMeta.transaction), {}, {
6148
- type,
6074
+ const txParams = {
6075
+ type: Number.parseInt(type, 16),
6149
6076
  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));
6077
+ gasLimit: txMeta.transaction.gas,
6078
+ accessList: txMeta.transaction.accessList,
6079
+ data: txMeta.transaction.data,
6080
+ gasPrice: txMeta.transaction.gasPrice,
6081
+ maxFeePerGas: txMeta.transaction.maxFeePerGas,
6082
+ maxPriorityFeePerGas: txMeta.transaction.maxPriorityFeePerGas,
6083
+ nonce: Number.parseInt(txMeta.transaction.nonce, 16),
6084
+ to: txMeta.transaction.to
6085
+ };
6086
+ const fromAddress = txMeta.transaction.from;
6087
+ const tx = external_ethers_namespaceObject.Transaction.from(txParams);
6088
+ const signedEthTx = await this.signEthTx(tx, fromAddress);
6089
+ txMeta.r = signedEthTx.signature.r;
6090
+ txMeta.s = signedEthTx.signature.s;
6091
+ txMeta.v = (0,util_namespaceObject.addHexPrefix)(signedEthTx.signature.v.toString(16));
6165
6092
  this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values");
6166
6093
  this.setTxStatusSigned(txId);
6167
- const rawTx = (0,util_namespaceObject.addHexPrefix)(Buffer.from(signedEthTx.serialize()).toString("hex"));
6094
+ const rawTx = signedEthTx.serialized;
6168
6095
  return rawTx;
6169
6096
  }
6170
6097
  async publishTransaction(txId, rawTx) {
@@ -6465,24 +6392,6 @@ class TransactionController extends TransactionStateManager {
6465
6392
  external_loglevel_default().error(error);
6466
6393
  }
6467
6394
  }
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
6395
  markNonceDuplicatesDropped(txId) {
6487
6396
  const txMeta = this.getTransaction(txId);
6488
6397
  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);
@@ -5511,7 +5510,6 @@ class TransactionController extends TransactionStateManager {
5511
5510
  signEthTx,
5512
5511
  getCurrentChainId,
5513
5512
  getCurrentNetworkEIP1559Compatibility,
5514
- getProviderConfig,
5515
5513
  getCurrentAccountEIP1559Compatibility,
5516
5514
  getSelectedAddress,
5517
5515
  getEIP1559GasFeeEstimates
@@ -5528,7 +5526,6 @@ class TransactionController extends TransactionStateManager {
5528
5526
  _defineProperty(this, "txGasUtil", void 0);
5529
5527
  _defineProperty(this, "_getCurrentNetworkEIP1559Compatibility", void 0);
5530
5528
  _defineProperty(this, "_getCurrentAccountEIP1559Compatibility", void 0);
5531
- _defineProperty(this, "getProviderConfig", void 0);
5532
5529
  _defineProperty(this, "signEthTx", void 0);
5533
5530
  _defineProperty(this, "provider", void 0);
5534
5531
  _defineProperty(this, "blockTracker", void 0);
@@ -5536,7 +5533,6 @@ class TransactionController extends TransactionStateManager {
5536
5533
  _defineProperty(this, "getUnapprovedTxCount", () => Object.keys(this.getUnapprovedTxList()).length);
5537
5534
  _defineProperty(this, "getPendingTxCount", account => this.getPendingTransactions(account).length);
5538
5535
  this.blockTracker = blockTracker;
5539
- this.getProviderConfig = getProviderConfig;
5540
5536
  this._getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
5541
5537
  this._getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility;
5542
5538
  this.getSelectedAddress = getSelectedAddress;
@@ -5637,27 +5633,27 @@ class TransactionController extends TransactionStateManager {
5637
5633
  const txMeta = this.getTransaction(txId);
5638
5634
  const chainId = this.getCurrentChainId();
5639
5635
  const type = isEIP1559Transaction(txMeta) ? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : TRANSACTION_ENVELOPE_TYPES.LEGACY;
5640
- const txParams = _objectSpread(_objectSpread({}, txMeta.transaction), {}, {
5641
- type,
5636
+ const txParams = {
5637
+ type: Number.parseInt(type, 16),
5642
5638
  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));
5639
+ gasLimit: txMeta.transaction.gas,
5640
+ accessList: txMeta.transaction.accessList,
5641
+ data: txMeta.transaction.data,
5642
+ gasPrice: txMeta.transaction.gasPrice,
5643
+ maxFeePerGas: txMeta.transaction.maxFeePerGas,
5644
+ maxPriorityFeePerGas: txMeta.transaction.maxPriorityFeePerGas,
5645
+ nonce: Number.parseInt(txMeta.transaction.nonce, 16),
5646
+ to: txMeta.transaction.to
5647
+ };
5648
+ const fromAddress = txMeta.transaction.from;
5649
+ const tx = Transaction.from(txParams);
5650
+ const signedEthTx = await this.signEthTx(tx, fromAddress);
5651
+ txMeta.r = signedEthTx.signature.r;
5652
+ txMeta.s = signedEthTx.signature.s;
5653
+ txMeta.v = addHexPrefix(signedEthTx.signature.v.toString(16));
5658
5654
  this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values");
5659
5655
  this.setTxStatusSigned(txId);
5660
- const rawTx = addHexPrefix(Buffer.from(signedEthTx.serialize()).toString("hex"));
5656
+ const rawTx = signedEthTx.serialized;
5661
5657
  return rawTx;
5662
5658
  }
5663
5659
  async publishTransaction(txId, rawTx) {
@@ -5958,24 +5954,6 @@ class TransactionController extends TransactionStateManager {
5958
5954
  log.error(error);
5959
5955
  }
5960
5956
  }
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
5957
  markNonceDuplicatesDropped(txId) {
5980
5958
  const txMeta = this.getTransaction(txId);
5981
5959
  const {