diff --git a/app/scripts/account-import-strategies/account-import-strategies.test.js b/app/scripts/account-import-strategies/account-import-strategies.test.js
index bc2f53ae7..e29561639 100644
--- a/app/scripts/account-import-strategies/account-import-strategies.test.js
+++ b/app/scripts/account-import-strategies/account-import-strategies.test.js
@@ -1,5 +1,5 @@
import assert from 'assert';
-import ethUtil from 'ethereumjs-util';
+import { stripHexPrefix } from 'ethereumjs-util';
import accountImporter from '.';
describe('Account Import Strategies', function () {
@@ -13,7 +13,7 @@ describe('Account Import Strategies', function () {
const importPrivKey = await accountImporter.importAccount('Private Key', [
privkey,
]);
- assert.equal(importPrivKey, ethUtil.stripHexPrefix(privkey));
+ assert.equal(importPrivKey, stripHexPrefix(privkey));
});
it('throws an error for empty string private key', async function () {
diff --git a/app/scripts/account-import-strategies/index.js b/app/scripts/account-import-strategies/index.js
index 89fd0b8c1..ce52132aa 100644
--- a/app/scripts/account-import-strategies/index.js
+++ b/app/scripts/account-import-strategies/index.js
@@ -1,7 +1,12 @@
import log from 'loglevel';
import Wallet from 'ethereumjs-wallet';
import importers from 'ethereumjs-wallet/thirdparty';
-import ethUtil from 'ethereumjs-util';
+import {
+ toBuffer,
+ isValidPrivate,
+ bufferToHex,
+ stripHexPrefix,
+} from 'ethereumjs-util';
import { addHexPrefix } from '../lib/util';
const accountImporter = {
@@ -22,13 +27,13 @@ const accountImporter = {
}
const prefixed = addHexPrefix(privateKey);
- const buffer = ethUtil.toBuffer(prefixed);
+ const buffer = toBuffer(prefixed);
- if (!ethUtil.isValidPrivate(buffer)) {
+ if (!isValidPrivate(buffer)) {
throw new Error('Cannot import invalid private key.');
}
- const stripped = ethUtil.stripHexPrefix(prefixed);
+ const stripped = stripHexPrefix(prefixed);
return stripped;
},
'JSON File': (input, password) => {
@@ -47,7 +52,7 @@ const accountImporter = {
function walletToPrivateKey(wallet) {
const privateKeyBuffer = wallet.getPrivateKey();
- return ethUtil.bufferToHex(privateKeyBuffer);
+ return bufferToHex(privateKeyBuffer);
}
export default accountImporter;
diff --git a/app/scripts/controllers/ens/index.js b/app/scripts/controllers/ens/index.js
index 015c3ee0a..a7d4c696b 100644
--- a/app/scripts/controllers/ens/index.js
+++ b/app/scripts/controllers/ens/index.js
@@ -1,5 +1,5 @@
import punycode from 'punycode/punycode';
-import ethUtil from 'ethereumjs-util';
+import { toChecksumAddress } from 'ethereumjs-util';
import { ObservableStore } from '@metamask/obs-store';
import log from 'loglevel';
import { CHAIN_ID_TO_NETWORK_ID_MAP } from '../../../../shared/constants/network';
@@ -43,7 +43,7 @@ export default class EnsController {
}
reverseResolveAddress(address) {
- return this._reverseResolveAddress(ethUtil.toChecksumAddress(address));
+ return this._reverseResolveAddress(toChecksumAddress(address));
}
async _reverseResolveAddress(address) {
@@ -79,7 +79,7 @@ export default class EnsController {
return undefined;
}
- if (ethUtil.toChecksumAddress(registeredAddress) !== address) {
+ if (toChecksumAddress(registeredAddress) !== address) {
return undefined;
}
diff --git a/app/scripts/controllers/ens/index.test.js b/app/scripts/controllers/ens/index.test.js
index 6e1a4c047..24197dbd7 100644
--- a/app/scripts/controllers/ens/index.test.js
+++ b/app/scripts/controllers/ens/index.test.js
@@ -79,7 +79,7 @@ describe('EnsController', function () {
const ens = new EnsController({
ens: {
reverse: sinon.stub().withArgs(address).returns('peaksignal.eth'),
- lookup: sinon.stub().withArgs('peaksignal.eth').returns('0xfoo'),
+ lookup: sinon.stub().withArgs('peaksignal.eth').returns('0x00'),
},
onNetworkDidChange,
getCurrentChainId,
diff --git a/app/scripts/controllers/metametrics.js b/app/scripts/controllers/metametrics.js
index 00e07009f..6e8fc62a2 100644
--- a/app/scripts/controllers/metametrics.js
+++ b/app/scripts/controllers/metametrics.js
@@ -1,6 +1,6 @@
import { merge, omit } from 'lodash';
import { ObservableStore } from '@metamask/obs-store';
-import { bufferToHex, sha3 } from 'ethereumjs-util';
+import { bufferToHex, keccak } from 'ethereumjs-util';
import { ENVIRONMENT_TYPE_BACKGROUND } from '../../../shared/constants/app';
import {
METAMETRICS_ANONYMOUS_ID,
@@ -110,9 +110,11 @@ export default class MetaMetricsController {
generateMetaMetricsId() {
return bufferToHex(
- sha3(
- String(Date.now()) +
- String(Math.round(Math.random() * Number.MAX_SAFE_INTEGER)),
+ keccak(
+ Buffer.from(
+ String(Date.now()) +
+ String(Math.round(Math.random() * Number.MAX_SAFE_INTEGER)),
+ ),
),
);
}
diff --git a/app/scripts/controllers/token-rates.js b/app/scripts/controllers/token-rates.js
index 9d597ce1b..b725b04c9 100644
--- a/app/scripts/controllers/token-rates.js
+++ b/app/scripts/controllers/token-rates.js
@@ -1,7 +1,7 @@
import { ObservableStore } from '@metamask/obs-store';
import log from 'loglevel';
import { normalize as normalizeAddress } from 'eth-sig-util';
-import ethUtil from 'ethereumjs-util';
+import { toChecksumAddress } from 'ethereumjs-util';
import getFetchWithTimeout from '../../../shared/modules/fetch-with-timeout';
const fetchWithTimeout = getFetchWithTimeout(30000);
@@ -45,7 +45,7 @@ export default class TokenRatesController {
this._tokens.forEach((token) => {
const price =
prices[token.address.toLowerCase()] ||
- prices[ethUtil.toChecksumAddress(token.address)];
+ prices[toChecksumAddress(token.address)];
contractExchangeRates[normalizeAddress(token.address)] = price
? price[nativeCurrency]
: 0;
diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js
index 3b0b9465d..3067b3e4f 100644
--- a/app/scripts/controllers/transactions/index.js
+++ b/app/scripts/controllers/transactions/index.js
@@ -1,6 +1,6 @@
import EventEmitter from 'safe-event-emitter';
import { ObservableStore } from '@metamask/obs-store';
-import ethUtil from 'ethereumjs-util';
+import { bufferToHex, keccak, toBuffer } from 'ethereumjs-util';
import Transaction from 'ethereumjs-tx';
import EthQuery from 'ethjs-query';
import { ethErrors } from 'eth-rpc-errors';
@@ -569,9 +569,9 @@ export default class TransactionController extends EventEmitter {
// add r,s,v values for provider request purposes see createMetamaskMiddleware
// and JSON rpc standard for further explanation
- txMeta.r = ethUtil.bufferToHex(ethTx.r);
- txMeta.s = ethUtil.bufferToHex(ethTx.s);
- txMeta.v = ethUtil.bufferToHex(ethTx.v);
+ txMeta.r = bufferToHex(ethTx.r);
+ txMeta.s = bufferToHex(ethTx.s);
+ txMeta.v = bufferToHex(ethTx.v);
this.txStateManager.updateTransaction(
txMeta,
@@ -580,7 +580,7 @@ export default class TransactionController extends EventEmitter {
// set state to signed
this.txStateManager.setTxStatusSigned(txMeta.id);
- const rawTx = ethUtil.bufferToHex(ethTx.serialize());
+ const rawTx = bufferToHex(ethTx.serialize());
return rawTx;
}
@@ -606,7 +606,7 @@ export default class TransactionController extends EventEmitter {
txHash = await this.query.sendRawTransaction(rawTx);
} catch (error) {
if (error.message.toLowerCase().includes('known transaction')) {
- txHash = ethUtil.sha3(addHexPrefix(rawTx)).toString('hex');
+ txHash = keccak(toBuffer(addHexPrefix(rawTx), 'hex')).toString('hex');
txHash = addHexPrefix(txHash);
} else {
throw error;
diff --git a/app/scripts/controllers/transactions/index.test.js b/app/scripts/controllers/transactions/index.test.js
index 2d1709cdf..a249c17fc 100644
--- a/app/scripts/controllers/transactions/index.test.js
+++ b/app/scripts/controllers/transactions/index.test.js
@@ -1,6 +1,6 @@
import { strict as assert } from 'assert';
import EventEmitter from 'events';
-import ethUtil from 'ethereumjs-util';
+import { toBuffer } from 'ethereumjs-util';
import EthTx from 'ethereumjs-tx';
import { ObservableStore } from '@metamask/obs-store';
import sinon from 'sinon';
@@ -518,7 +518,7 @@ describe('Transaction Controller', function () {
noop,
);
const rawTx = await txController.signTransaction('1');
- const ethTx = new EthTx(ethUtil.toBuffer(rawTx));
+ const ethTx = new EthTx(toBuffer(rawTx));
assert.equal(ethTx.getChainId(), 42);
});
});
diff --git a/app/scripts/controllers/transactions/tx-gas-utils.js b/app/scripts/controllers/transactions/tx-gas-utils.js
index 75eb60d83..1b84577b1 100644
--- a/app/scripts/controllers/transactions/tx-gas-utils.js
+++ b/app/scripts/controllers/transactions/tx-gas-utils.js
@@ -1,6 +1,6 @@
import EthQuery from 'ethjs-query';
import log from 'loglevel';
-import ethUtil from 'ethereumjs-util';
+import { addHexPrefix } from 'ethereumjs-util';
import { cloneDeep } from 'lodash';
import { hexToBn, BnMultiplyByFraction, bnToHex } from '../../lib/util';
@@ -103,7 +103,7 @@ export default class TxGasUtil {
// add additional gas buffer to our estimation for safety
const gasLimit = this.addGasBuffer(
- ethUtil.addHexPrefix(estimatedGasHex),
+ addHexPrefix(estimatedGasHex),
blockGasLimit,
multiplier,
);
diff --git a/app/scripts/lib/decrypt-message-manager.js b/app/scripts/lib/decrypt-message-manager.js
index 674c73572..56eabf552 100644
--- a/app/scripts/lib/decrypt-message-manager.js
+++ b/app/scripts/lib/decrypt-message-manager.js
@@ -1,6 +1,6 @@
import EventEmitter from 'events';
import { ObservableStore } from '@metamask/obs-store';
-import ethUtil from 'ethereumjs-util';
+import { bufferToHex, stripHexPrefix } from 'ethereumjs-util';
import { ethErrors } from 'eth-rpc-errors';
import log from 'loglevel';
import { MESSAGE_TYPE } from '../../../shared/constants/app';
@@ -337,7 +337,7 @@ export default class DecryptMessageManager extends EventEmitter {
*/
normalizeMsgData(data) {
try {
- const stripped = ethUtil.stripHexPrefix(data);
+ const stripped = stripHexPrefix(data);
if (stripped.match(hexRe)) {
return addHexPrefix(stripped);
}
@@ -345,6 +345,6 @@ export default class DecryptMessageManager extends EventEmitter {
log.debug(`Message was not hex encoded, interpreting as utf8.`);
}
- return ethUtil.bufferToHex(Buffer.from(data, 'utf8'));
+ return bufferToHex(Buffer.from(data, 'utf8'));
}
}
diff --git a/app/scripts/lib/message-manager.js b/app/scripts/lib/message-manager.js
index ce48327f3..bb7756b33 100644
--- a/app/scripts/lib/message-manager.js
+++ b/app/scripts/lib/message-manager.js
@@ -1,6 +1,6 @@
import EventEmitter from 'events';
import { ObservableStore } from '@metamask/obs-store';
-import ethUtil from 'ethereumjs-util';
+import { bufferToHex } from 'ethereumjs-util';
import { ethErrors } from 'eth-rpc-errors';
import { MESSAGE_TYPE } from '../../../shared/constants/app';
import { METAMASK_CONTROLLER_EVENTS } from '../metamask-controller';
@@ -298,5 +298,5 @@ function normalizeMsgData(data) {
return data;
}
// data is unicode, convert to hex
- return ethUtil.bufferToHex(Buffer.from(data, 'utf8'));
+ return bufferToHex(Buffer.from(data, 'utf8'));
}
diff --git a/app/scripts/lib/personal-message-manager.js b/app/scripts/lib/personal-message-manager.js
index 0149e4802..6002b0709 100644
--- a/app/scripts/lib/personal-message-manager.js
+++ b/app/scripts/lib/personal-message-manager.js
@@ -1,6 +1,6 @@
import EventEmitter from 'events';
import { ObservableStore } from '@metamask/obs-store';
-import ethUtil from 'ethereumjs-util';
+import { bufferToHex, stripHexPrefix } from 'ethereumjs-util';
import { ethErrors } from 'eth-rpc-errors';
import log from 'loglevel';
import { MESSAGE_TYPE } from '../../../shared/constants/app';
@@ -322,7 +322,7 @@ export default class PersonalMessageManager extends EventEmitter {
*/
normalizeMsgData(data) {
try {
- const stripped = ethUtil.stripHexPrefix(data);
+ const stripped = stripHexPrefix(data);
if (stripped.match(hexRe)) {
return addHexPrefix(stripped);
}
@@ -330,6 +330,6 @@ export default class PersonalMessageManager extends EventEmitter {
log.debug(`Message was not hex encoded, interpreting as utf8.`);
}
- return ethUtil.bufferToHex(Buffer.from(data, 'utf8'));
+ return bufferToHex(Buffer.from(data, 'utf8'));
}
}
diff --git a/app/scripts/lib/util.js b/app/scripts/lib/util.js
index ccf8d1193..46e5b8641 100644
--- a/app/scripts/lib/util.js
+++ b/app/scripts/lib/util.js
@@ -1,6 +1,6 @@
import assert from 'assert';
import extension from 'extensionizer';
-import ethUtil from 'ethereumjs-util';
+import { stripHexPrefix } from 'ethereumjs-util';
import BN from 'bn.js';
import { memoize } from 'lodash';
@@ -111,7 +111,7 @@ function sufficientBalance(txParams, hexBalance) {
*
*/
function hexToBn(inputHex) {
- return new BN(ethUtil.stripHexPrefix(inputHex), 16);
+ return new BN(stripHexPrefix(inputHex), 16);
}
/**
diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js
index 7e3ec936d..6d4c45ea0 100644
--- a/app/scripts/metamask-controller.js
+++ b/app/scripts/metamask-controller.js
@@ -10,7 +10,7 @@ import createSubscriptionManager from 'eth-json-rpc-filters/subscriptionManager'
import providerAsMiddleware from 'eth-json-rpc-middleware/providerAsMiddleware';
import KeyringController from 'eth-keyring-controller';
import { Mutex } from 'await-semaphore';
-import ethUtil from 'ethereumjs-util';
+import { toChecksumAddress, stripHexPrefix } from 'ethereumjs-util';
import log from 'loglevel';
import TrezorKeyring from 'eth-trezor-keyring';
import LedgerBridgeKeyring from '@metamask/eth-ledger-bridge-keyring';
@@ -1096,16 +1096,14 @@ export default class MetamaskController extends EventEmitter {
// Filter ERC20 tokens
const filteredAccountTokens = {};
Object.keys(accountTokens).forEach((address) => {
- const checksummedAddress = ethUtil.toChecksumAddress(address);
+ const checksummedAddress = toChecksumAddress(address);
filteredAccountTokens[checksummedAddress] = {};
Object.keys(accountTokens[address]).forEach((chainId) => {
filteredAccountTokens[checksummedAddress][chainId] =
chainId === MAINNET_CHAIN_ID
? accountTokens[address][chainId].filter(
({ address: tokenAddress }) => {
- const checksumAddress = ethUtil.toChecksumAddress(
- tokenAddress,
- );
+ const checksumAddress = toChecksumAddress(tokenAddress);
return contractMap[checksumAddress]
? contractMap[checksumAddress].erc20
: true;
@@ -1142,10 +1140,10 @@ export default class MetamaskController extends EventEmitter {
const accounts = {
hd: hdAccounts
.filter((item, pos) => hdAccounts.indexOf(item) === pos)
- .map((address) => ethUtil.toChecksumAddress(address)),
+ .map((address) => toChecksumAddress(address)),
simpleKeyPair: simpleKeyPairAccounts
.filter((item, pos) => simpleKeyPairAccounts.indexOf(item) === pos)
- .map((address) => ethUtil.toChecksumAddress(address)),
+ .map((address) => toChecksumAddress(address)),
ledger: [],
trezor: [],
};
@@ -1155,7 +1153,7 @@ export default class MetamaskController extends EventEmitter {
let { transactions } = this.txController.store.getState();
// delete tx for other accounts that we're not importing
transactions = transactions.filter((tx) => {
- const checksummedTxFrom = ethUtil.toChecksumAddress(tx.txParams.from);
+ const checksummedTxFrom = toChecksumAddress(tx.txParams.from);
return accounts.hd.includes(checksummedTxFrom);
});
@@ -1640,7 +1638,7 @@ export default class MetamaskController extends EventEmitter {
const msgId = msgParams.metamaskId;
const msg = this.decryptMessageManager.getMsg(msgId);
try {
- const stripped = ethUtil.stripHexPrefix(msgParams.data);
+ const stripped = stripHexPrefix(msgParams.data);
const buff = Buffer.from(stripped, 'hex');
msgParams.data = JSON.parse(buff.toString('utf8'));
@@ -1670,7 +1668,7 @@ export default class MetamaskController extends EventEmitter {
msgParams,
);
- const stripped = ethUtil.stripHexPrefix(cleanMsgParams.data);
+ const stripped = stripHexPrefix(cleanMsgParams.data);
const buff = Buffer.from(stripped, 'hex');
cleanMsgParams.data = JSON.parse(buff.toString('utf8'));
diff --git a/app/scripts/metamask-controller.test.js b/app/scripts/metamask-controller.test.js
index 6756025ad..55eb1f083 100644
--- a/app/scripts/metamask-controller.test.js
+++ b/app/scripts/metamask-controller.test.js
@@ -2,7 +2,7 @@ import assert from 'assert';
import sinon from 'sinon';
import { cloneDeep } from 'lodash';
import nock from 'nock';
-import ethUtil from 'ethereumjs-util';
+import { pubToAddress, bufferToHex } from 'ethereumjs-util';
import { obj as createThoughStream } from 'through2';
import EthQuery from 'eth-query';
import proxyquire from 'proxyquire';
@@ -186,9 +186,9 @@ describe('MetaMaskController', function () {
);
const privKeyBuffer = simpleKeyrings[0].wallets[0]._privKey;
const pubKeyBuffer = simpleKeyrings[0].wallets[0]._pubKey;
- const addressBuffer = ethUtil.pubToAddress(pubKeyBuffer);
- const privKey = ethUtil.bufferToHex(privKeyBuffer);
- const pubKey = ethUtil.bufferToHex(addressBuffer);
+ const addressBuffer = pubToAddress(pubKeyBuffer);
+ const privKey = bufferToHex(privKeyBuffer);
+ const pubKey = bufferToHex(addressBuffer);
assert.equal(privKey, addHexPrefix(importPrivkey));
assert.equal(pubKey, '0xe18035bf8712672935fdb4e5e431b1a0183d2dfc');
});
diff --git a/app/scripts/migrations/039.js b/app/scripts/migrations/039.js
index adc8390db..7dcf904de 100644
--- a/app/scripts/migrations/039.js
+++ b/app/scripts/migrations/039.js
@@ -1,5 +1,5 @@
import { cloneDeep } from 'lodash';
-import ethUtil from 'ethereumjs-util';
+import { toChecksumAddress } from 'ethereumjs-util';
const version = 39;
@@ -12,7 +12,7 @@ function isOldDai(token = {}) {
token &&
typeof token === 'object' &&
token.symbol === DAI_V1_TOKEN_SYMBOL &&
- ethUtil.toChecksumAddress(token.address) === DAI_V1_CONTRACT_ADDRESS
+ toChecksumAddress(token.address) === DAI_V1_CONTRACT_ADDRESS
);
}
diff --git a/package.json b/package.json
index d3871f8a4..f6ead484d 100644
--- a/package.json
+++ b/package.json
@@ -129,7 +129,7 @@
"ethereum-ens-network-map": "^1.0.2",
"ethereumjs-abi": "^0.6.4",
"ethereumjs-tx": "1.3.7",
- "ethereumjs-util": "5.1.0",
+ "ethereumjs-util": "^7.0.9",
"ethereumjs-wallet": "^0.6.4",
"ethers": "^5.0.8",
"ethjs": "^0.4.0",
diff --git a/ui/app/components/app/account-menu/account-menu.test.js b/ui/app/components/app/account-menu/account-menu.test.js
index ece1cb1b6..7862de005 100644
--- a/ui/app/components/app/account-menu/account-menu.test.js
+++ b/ui/app/components/app/account-menu/account-menu.test.js
@@ -26,12 +26,12 @@ describe('Account Menu', () => {
addressConnectedDomainMap: {},
accounts: [
{
- address: '0xAddress',
+ address: '0x00',
name: 'Account 1',
balance: '0x0',
},
{
- address: '0xImportedAddress',
+ address: '0x1',
name: 'Imported Account 1',
balance: '0x0',
},
@@ -43,7 +43,7 @@ describe('Account Menu', () => {
},
{
type: 'Simple Key Pair',
- accounts: ['0xImportedAddress'],
+ accounts: ['0x1'],
},
],
prevIsAccountMenuOpen: false,
@@ -90,9 +90,7 @@ describe('Account Menu', () => {
click.first().simulate('click');
expect(props.showAccountDetail.calledOnce).toStrictEqual(true);
- expect(props.showAccountDetail.getCall(0).args[0]).toStrictEqual(
- '0xAddress',
- );
+ expect(props.showAccountDetail.getCall(0).args[0]).toStrictEqual('0x00');
});
it('render imported account label', () => {
diff --git a/ui/app/components/app/modals/confirm-remove-account/confirm-remove-account.test.js b/ui/app/components/app/modals/confirm-remove-account/confirm-remove-account.test.js
index b1646b43e..fd89e96f8 100644
--- a/ui/app/components/app/modals/confirm-remove-account/confirm-remove-account.test.js
+++ b/ui/app/components/app/modals/confirm-remove-account/confirm-remove-account.test.js
@@ -18,7 +18,7 @@ describe('Confirm Remove Account', () => {
removeAccount: sinon.stub().resolves(),
network: '101',
identity: {
- address: '0xAddress',
+ address: '0x0',
name: 'Account 1',
},
};
diff --git a/ui/app/components/app/signature-request-original/signature-request-original.component.js b/ui/app/components/app/signature-request-original/signature-request-original.component.js
index 5dbcf9eb7..ae62fcad9 100644
--- a/ui/app/components/app/signature-request-original/signature-request-original.component.js
+++ b/ui/app/components/app/signature-request-original/signature-request-original.component.js
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
-import ethUtil from 'ethereumjs-util';
+import { stripHexPrefix } from 'ethereumjs-util';
import classnames from 'classnames';
import { ObjectInspector } from 'react-inspector';
@@ -179,7 +179,7 @@ export default class SignatureRequestOriginal extends Component {
msgHexToText = (hex) => {
try {
- const stripped = ethUtil.stripHexPrefix(hex);
+ const stripped = stripHexPrefix(hex);
const buff = Buffer.from(stripped, 'hex');
return buff.length === 32 ? hex : buff.toString('utf8');
} catch (e) {
diff --git a/ui/app/components/ui/identicon/identicon.component.test.js b/ui/app/components/ui/identicon/identicon.component.test.js
index 031da5f36..f78a47b6d 100644
--- a/ui/app/components/ui/identicon/identicon.component.test.js
+++ b/ui/app/components/ui/identicon/identicon.component.test.js
@@ -38,7 +38,7 @@ describe('Identicon', () => {
it('renders div with address prop', () => {
const wrapper = mount(
-