@toruslabs/ethereum-controllers 5.5.0 → 5.5.2

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.
@@ -2,9 +2,9 @@ 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, BaseKeyringController, PROVIDER_JRPC_METHODS, createFetchMiddleware, createSwappableProxy, createEventEmitterProxy, BasePreferencesController, TX_EVENTS, BaseTransactionStateManager, transactionMatchesNetwork as transactionMatchesNetwork$1 } from '@toruslabs/base-controllers';
4
4
  import { Mutex } from 'async-mutex';
5
- import { BrowserProvider, toQuantity, Contract, Interface, formatEther, SigningKey, Wallet, isHexString as isHexString$1, JsonRpcProvider, keccak256 } from 'ethers';
5
+ import { BrowserProvider, toQuantity, Contract, Interface, formatEther, isHexString as isHexString$1, JsonRpcProvider, keccak256 } from 'ethers';
6
6
  import log from 'loglevel';
7
- import { isHexString, addHexPrefix, isValidAddress, toChecksumAddress, stripHexPrefix, ecsign, bigIntToBytes, bytesToHex } from '@ethereumjs/util';
7
+ import { isHexString, addHexPrefix, isValidAddress, toChecksumAddress, stripHexPrefix, bytesToHex, privateToPublic, privateToAddress, ecsign, bigIntToBytes } from '@ethereumjs/util';
8
8
  import BigNumber from 'bignumber.js';
9
9
  import { rpcErrors, providerErrors } from '@metamask/rpc-errors';
10
10
  import { get, post, remove, patch } from '@toruslabs/http-helpers';
@@ -2293,17 +2293,15 @@ class KeyringController extends BaseKeyringController {
2293
2293
  return this.state.wallets.map(w => w.publicKey);
2294
2294
  }
2295
2295
  importAccount(accountPrivateKey) {
2296
- const hexPrivateKey = addHexPrefix(accountPrivateKey);
2297
- const signingKey = new SigningKey(hexPrivateKey);
2298
- const wallet = new Wallet(signingKey.privateKey);
2299
- const {
2300
- address
2301
- } = wallet;
2296
+ const hexPrivateKey = accountPrivateKey.padStart(64, "0");
2297
+ const bufferPrivKey = Buffer.from(hexPrivateKey, "hex");
2298
+ const publicKey = bytesToHex(privateToPublic(bufferPrivKey));
2299
+ const address = bytesToHex(privateToAddress(bufferPrivKey));
2302
2300
  const existingWallet = this.state.wallets.find(w => w.address === address);
2303
2301
  if (existingWallet) return existingWallet.address;
2304
2302
  this.update({
2305
2303
  wallets: [...this.state.wallets, {
2306
- publicKey: signingKey.publicKey,
2304
+ publicKey,
2307
2305
  privateKey: accountPrivateKey,
2308
2306
  address
2309
2307
  }]
@@ -2630,7 +2628,7 @@ class AddChainController extends AbstractMessageController {
2630
2628
  try {
2631
2629
  const msgObject = this.getMessage(messageId);
2632
2630
  await this.approveMessage(messageId, msgObject.messageParams);
2633
- this.addChain(msgObject.messageParams);
2631
+ await this.addChain(msgObject.messageParams);
2634
2632
  this.updateMessage(_objectSpread(_objectSpread({}, msgObject), {}, {
2635
2633
  rawSig: JSON.stringify(msgObject.messageParams)
2636
2634
  }));