@toruslabs/ethereum-controllers 6.0.3 → 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);
@@ -2679,7 +2609,11 @@ class KeyringController extends base_controllers_namespaceObject.BaseKeyringCont
2679
2609
  async signPersonalMessage(data, address) {
2680
2610
  const wallet = this._getWalletForAccount(address);
2681
2611
  const privKey = new external_ethers_namespaceObject.SigningKey((0,util_namespaceObject.addHexPrefix)(wallet.privateKey));
2682
- const signature = privKey.sign((0,external_ethers_namespaceObject.hashMessage)(data)).serialized;
2612
+ // we need to check if the data is hex or not
2613
+ // For historical reasons, you must submit the message to sign in hex-encoded UTF-8.
2614
+ // https://docs.metamask.io/wallet/how-to/sign-data/#use-personal_sign
2615
+ const message = (0,util_namespaceObject.isHexString)(data) ? Buffer.from((0,util_namespaceObject.stripHexPrefix)(data), "hex") : Buffer.from(data);
2616
+ const signature = privKey.sign((0,external_ethers_namespaceObject.hashMessage)(message)).serialized;
2683
2617
  return signature;
2684
2618
  }
2685
2619
 
@@ -6014,7 +5948,6 @@ class TransactionController extends TransactionStateManager {
6014
5948
  signEthTx,
6015
5949
  getCurrentChainId,
6016
5950
  getCurrentNetworkEIP1559Compatibility,
6017
- getProviderConfig,
6018
5951
  getCurrentAccountEIP1559Compatibility,
6019
5952
  getSelectedAddress,
6020
5953
  getEIP1559GasFeeEstimates
@@ -6031,7 +5964,6 @@ class TransactionController extends TransactionStateManager {
6031
5964
  defineProperty_default()(this, "txGasUtil", void 0);
6032
5965
  defineProperty_default()(this, "_getCurrentNetworkEIP1559Compatibility", void 0);
6033
5966
  defineProperty_default()(this, "_getCurrentAccountEIP1559Compatibility", void 0);
6034
- defineProperty_default()(this, "getProviderConfig", void 0);
6035
5967
  defineProperty_default()(this, "signEthTx", void 0);
6036
5968
  defineProperty_default()(this, "provider", void 0);
6037
5969
  defineProperty_default()(this, "blockTracker", void 0);
@@ -6039,7 +5971,6 @@ class TransactionController extends TransactionStateManager {
6039
5971
  defineProperty_default()(this, "getUnapprovedTxCount", () => Object.keys(this.getUnapprovedTxList()).length);
6040
5972
  defineProperty_default()(this, "getPendingTxCount", account => this.getPendingTransactions(account).length);
6041
5973
  this.blockTracker = blockTracker;
6042
- this.getProviderConfig = getProviderConfig;
6043
5974
  this._getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
6044
5975
  this._getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility;
6045
5976
  this.getSelectedAddress = getSelectedAddress;
@@ -6140,27 +6071,27 @@ class TransactionController extends TransactionStateManager {
6140
6071
  const txMeta = this.getTransaction(txId);
6141
6072
  const chainId = this.getCurrentChainId();
6142
6073
  const type = isEIP1559Transaction(txMeta) ? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : TRANSACTION_ENVELOPE_TYPES.LEGACY;
6143
- const txParams = objectSpread2_default()(objectSpread2_default()({}, txMeta.transaction), {}, {
6144
- type,
6074
+ const txParams = {
6075
+ type: Number.parseInt(type, 16),
6145
6076
  chainId,
6146
- gasLimit: txMeta.transaction.gas
6147
- });
6148
- const fromAddress = txParams.from;
6149
- const common = await this.getCommonConfiguration(fromAddress);
6150
- const {
6151
- TransactionFactory
6152
- } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 81, 23));
6153
- // TODO: fix this when @ethereumjs/tx is updated.
6154
- const unsignedEthTx = TransactionFactory.fromTxData(txParams, {
6155
- common
6156
- });
6157
- const signedEthTx = await this.signEthTx(unsignedEthTx, fromAddress);
6158
- txMeta.r = (0,util_namespaceObject.addHexPrefix)(signedEthTx.r.toString(16));
6159
- txMeta.s = (0,util_namespaceObject.addHexPrefix)(signedEthTx.s.toString(16));
6160
- 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));
6161
6092
  this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values");
6162
6093
  this.setTxStatusSigned(txId);
6163
- const rawTx = (0,util_namespaceObject.addHexPrefix)(Buffer.from(signedEthTx.serialize()).toString("hex"));
6094
+ const rawTx = signedEthTx.serialized;
6164
6095
  return rawTx;
6165
6096
  }
6166
6097
  async publishTransaction(txId, rawTx) {
@@ -6461,24 +6392,6 @@ class TransactionController extends TransactionStateManager {
6461
6392
  external_loglevel_default().error(error);
6462
6393
  }
6463
6394
  }
6464
- async getCommonConfiguration(fromAddress) {
6465
- const {
6466
- chainId,
6467
- displayName
6468
- } = this.getProviderConfig();
6469
- const supportsEIP1559 = await this.getEIP1559Compatibility(fromAddress);
6470
- const {
6471
- Common,
6472
- Hardfork
6473
- } = await Promise.resolve(/* import() */).then(__webpack_require__.t.bind(__webpack_require__, 652, 23));
6474
- const hardfork = supportsEIP1559 ? Hardfork.Paris : Hardfork.Berlin;
6475
- return Common.custom({
6476
- chainId: chainId === "loading" ? 0 : Number.parseInt(chainId, 16),
6477
- defaultHardfork: hardfork,
6478
- name: displayName,
6479
- networkId: chainId === "loading" ? 0 : Number.parseInt(chainId, 16)
6480
- });
6481
- }
6482
6395
  markNonceDuplicatesDropped(txId) {
6483
6396
  const txMeta = this.getTransaction(txId);
6484
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);
@@ -2326,7 +2325,11 @@ class KeyringController extends BaseKeyringController {
2326
2325
  async signPersonalMessage(data, address) {
2327
2326
  const wallet = this._getWalletForAccount(address);
2328
2327
  const privKey = new SigningKey(addHexPrefix(wallet.privateKey));
2329
- const signature = privKey.sign(hashMessage(data)).serialized;
2328
+ // we need to check if the data is hex or not
2329
+ // For historical reasons, you must submit the message to sign in hex-encoded UTF-8.
2330
+ // https://docs.metamask.io/wallet/how-to/sign-data/#use-personal_sign
2331
+ const message = isHexString(data) ? Buffer.from(stripHexPrefix(data), "hex") : Buffer.from(data);
2332
+ const signature = privKey.sign(hashMessage(message)).serialized;
2330
2333
  return signature;
2331
2334
  }
2332
2335
 
@@ -5507,7 +5510,6 @@ class TransactionController extends TransactionStateManager {
5507
5510
  signEthTx,
5508
5511
  getCurrentChainId,
5509
5512
  getCurrentNetworkEIP1559Compatibility,
5510
- getProviderConfig,
5511
5513
  getCurrentAccountEIP1559Compatibility,
5512
5514
  getSelectedAddress,
5513
5515
  getEIP1559GasFeeEstimates
@@ -5524,7 +5526,6 @@ class TransactionController extends TransactionStateManager {
5524
5526
  _defineProperty(this, "txGasUtil", void 0);
5525
5527
  _defineProperty(this, "_getCurrentNetworkEIP1559Compatibility", void 0);
5526
5528
  _defineProperty(this, "_getCurrentAccountEIP1559Compatibility", void 0);
5527
- _defineProperty(this, "getProviderConfig", void 0);
5528
5529
  _defineProperty(this, "signEthTx", void 0);
5529
5530
  _defineProperty(this, "provider", void 0);
5530
5531
  _defineProperty(this, "blockTracker", void 0);
@@ -5532,7 +5533,6 @@ class TransactionController extends TransactionStateManager {
5532
5533
  _defineProperty(this, "getUnapprovedTxCount", () => Object.keys(this.getUnapprovedTxList()).length);
5533
5534
  _defineProperty(this, "getPendingTxCount", account => this.getPendingTransactions(account).length);
5534
5535
  this.blockTracker = blockTracker;
5535
- this.getProviderConfig = getProviderConfig;
5536
5536
  this._getCurrentNetworkEIP1559Compatibility = getCurrentNetworkEIP1559Compatibility;
5537
5537
  this._getCurrentAccountEIP1559Compatibility = getCurrentAccountEIP1559Compatibility;
5538
5538
  this.getSelectedAddress = getSelectedAddress;
@@ -5633,27 +5633,27 @@ class TransactionController extends TransactionStateManager {
5633
5633
  const txMeta = this.getTransaction(txId);
5634
5634
  const chainId = this.getCurrentChainId();
5635
5635
  const type = isEIP1559Transaction(txMeta) ? TRANSACTION_ENVELOPE_TYPES.FEE_MARKET : TRANSACTION_ENVELOPE_TYPES.LEGACY;
5636
- const txParams = _objectSpread(_objectSpread({}, txMeta.transaction), {}, {
5637
- type,
5636
+ const txParams = {
5637
+ type: Number.parseInt(type, 16),
5638
5638
  chainId,
5639
- gasLimit: txMeta.transaction.gas
5640
- });
5641
- const fromAddress = txParams.from;
5642
- const common = await this.getCommonConfiguration(fromAddress);
5643
- const {
5644
- TransactionFactory
5645
- } = await import('@ethereumjs/tx');
5646
- // TODO: fix this when @ethereumjs/tx is updated.
5647
- const unsignedEthTx = TransactionFactory.fromTxData(txParams, {
5648
- common
5649
- });
5650
- const signedEthTx = await this.signEthTx(unsignedEthTx, fromAddress);
5651
- txMeta.r = addHexPrefix(signedEthTx.r.toString(16));
5652
- txMeta.s = addHexPrefix(signedEthTx.s.toString(16));
5653
- 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));
5654
5654
  this.updateTransactionInState(txMeta, "transactions#signTransaction: add r, s, v values");
5655
5655
  this.setTxStatusSigned(txId);
5656
- const rawTx = addHexPrefix(Buffer.from(signedEthTx.serialize()).toString("hex"));
5656
+ const rawTx = signedEthTx.serialized;
5657
5657
  return rawTx;
5658
5658
  }
5659
5659
  async publishTransaction(txId, rawTx) {
@@ -5954,24 +5954,6 @@ class TransactionController extends TransactionStateManager {
5954
5954
  log.error(error);
5955
5955
  }
5956
5956
  }
5957
- async getCommonConfiguration(fromAddress) {
5958
- const {
5959
- chainId,
5960
- displayName
5961
- } = this.getProviderConfig();
5962
- const supportsEIP1559 = await this.getEIP1559Compatibility(fromAddress);
5963
- const {
5964
- Common,
5965
- Hardfork
5966
- } = await import('@ethereumjs/common');
5967
- const hardfork = supportsEIP1559 ? Hardfork.Paris : Hardfork.Berlin;
5968
- return Common.custom({
5969
- chainId: chainId === "loading" ? 0 : Number.parseInt(chainId, 16),
5970
- defaultHardfork: hardfork,
5971
- name: displayName,
5972
- networkId: chainId === "loading" ? 0 : Number.parseInt(chainId, 16)
5973
- });
5974
- }
5975
5957
  markNonceDuplicatesDropped(txId) {
5976
5958
  const txMeta = this.getTransaction(txId);
5977
5959
  const {