Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: upgrade from ethereumjs-util to @ethereumjs/util #28169

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .storybook/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ module.exports = {
config.resolve.alias['@ethereumjs/util'] = require.resolve(
'../ui/__mocks__/ethereumjs-util.js',
);
config.resolve.alias['ethereumjs-util'] = require.resolve(
'../ui/__mocks__/ethereumjs-util.js',
);
config.resolve.alias['./useNftCollectionsMetadata'] = require.resolve(
'../ui/__mocks__/useNftCollectionsMetadata.js',
);
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/controllers/bridge/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { zeroAddress } from 'ethereumjs-util';
import { zeroAddress } from '@ethereumjs/util';
import { Hex } from '@metamask/utils';
import {
BRIDGE_DEFAULT_SLIPPAGE,
Expand Down
17 changes: 10 additions & 7 deletions app/scripts/controllers/metametrics-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {
size,
sum,
} from 'lodash';
import { bufferToHex, keccak } from 'ethereumjs-util';
import { keccak256 } from 'ethereum-cryptography/keccak';
import { v4 as uuidv4 } from 'uuid';
import { NameControllerState, NameType } from '@metamask/name-controller';
import { AccountsControllerState } from '@metamask/accounts-controller';
import {
add0x,
getErrorMessage,
Hex,
isErrorWithMessage,
Expand Down Expand Up @@ -523,13 +524,15 @@ export default class MetaMetricsController extends BaseController<
}

generateMetaMetricsId(): string {
return bufferToHex(
keccak(
Buffer.from(
String(Date.now()) +
String(Math.round(Math.random() * Number.MAX_SAFE_INTEGER)),
return add0x(
Buffer.from(
keccak256(
Buffer.from(
String(Date.now()) +
String(Math.round(Math.random() * Number.MAX_SAFE_INTEGER)),
),
),
),
).toString('hex'),
);
}

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/createRPCMethodTrackingMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApprovalType, detectSIWE } from '@metamask/controller-utils';
import { errorCodes } from '@metamask/rpc-errors';
import { isValidAddress } from 'ethereumjs-util';
import { isValidAddress } from '@ethereumjs/util';
import { MESSAGE_TYPE, ORIGIN_METAMASK } from '../../../shared/constants/app';
import {
MetaMetricsEventCategory,
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/transaction/decode/four-byte.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */

import { addHexPrefix } from 'ethereumjs-util';
import { addHexPrefix } from '@ethereumjs/util';
import { Interface, ParamType } from '@ethersproject/abi';
import { Hex, createProjectLogger } from '@metamask/utils';
import {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/transaction/decode/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { query } from '@metamask/controller-utils';
import EthQuery from '@metamask/eth-query';
import { Hex } from '@metamask/utils';
import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';
import { addHexPrefix, stripHexPrefix } from '@ethereumjs/util';

const IMPLEMENTATION_STORAGE_SLOTS = [
// org.zeppelinos.proxy.implementation
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/transaction/decode/uniswap.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Interface, TransactionDescription } from '@ethersproject/abi';
import { Hex } from '@metamask/utils';
import { addHexPrefix, stripHexPrefix } from 'ethereumjs-util';
import { addHexPrefix, stripHexPrefix } from '@ethereumjs/util';
import { CHAIN_IDS } from '../../../../../shared/constants/network';
import { UNISWAP_ROUTER_COMMANDS } from './uniswap-commands';

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/transaction/metrics.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import EthQuery, { Provider } from '@metamask/eth-query';
import { FetchGasFeeEstimateOptions } from '@metamask/gas-fee-controller';
import { BigNumber } from 'bignumber.js';
import { isHexString } from 'ethereumjs-util';
import { isHexString } from '@ethereumjs/util';

import { SmartTransaction } from '@metamask/smart-transactions-controller/dist/types';
import {
Expand Down
2 changes: 1 addition & 1 deletion app/scripts/lib/transaction/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
UserOperationController,
} from '@metamask/user-operation-controller';
import type { Hex } from '@metamask/utils';
import { addHexPrefix } from 'ethereumjs-util';
import { addHexPrefix } from '@ethereumjs/util';
import { PPOMController } from '@metamask/ppom-validator';

import {
Expand Down
5 changes: 3 additions & 2 deletions app/scripts/migrations/105.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { v4 as uuid } from 'uuid';
import { sha256FromString } from 'ethereumjs-util';
import { sha256 } from '@noble/hashes/sha256';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { hexToBytes } from '@noble/hashes/utils';
import { ETH_EOA_METHODS } from '../../../shared/constants/eth-methods';
import { migrate } from './105';

Expand All @@ -18,7 +19,7 @@ global.sentry = {

function addressToUUID(address: string): string {
return uuid({
random: sha256FromString(address).slice(0, 16),
random: sha256(hexToBytes(address)).slice(0, 16),
});
}

Expand Down
5 changes: 3 additions & 2 deletions app/scripts/migrations/105.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EthAccountType } from '@metamask/keyring-api';
import { InternalAccount } from '@metamask/keyring-internal-api';
import { sha256FromString } from 'ethereumjs-util';
import { sha256 } from '@noble/hashes/sha256';
import { hexToBytes } from '@noble/hashes/utils';
import { v4 as uuid } from 'uuid';
import { cloneDeep } from 'lodash';
import { ETH_EOA_METHODS } from '../../../shared/constants/eth-methods';
Expand Down Expand Up @@ -88,7 +89,7 @@ function createInternalAccountsForAccountsController(

Object.values(identities).forEach((identity) => {
const expectedId = uuid({
random: sha256FromString(identity.address).slice(0, 16),
random: sha256(hexToBytes(identity.address)).slice(0, 16),
});

accounts[expectedId] = {
Expand Down
Loading
Loading