Skip to content

Commit 2126c85

Browse files
committed
Merge branch 'main' into bump-all-packages-to-node-18
2 parents 9933f8e + 17c52d9 commit 2126c85

File tree

136 files changed

+10733
-3789
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+10733
-3789
lines changed

.eslintrc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ module.exports = {
55
'!.eslintrc.js',
66
'!jest.config.js',
77
'node_modules',
8-
'dist',
9-
'docs',
10-
'coverage',
8+
'**/dist',
9+
'**/docs',
10+
'**/coverage',
1111
'merged-packages',
12-
'package-template',
12+
'scripts/create-package/package-template',
1313
],
1414
overrides: [
1515
{
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: 'Check for PR labels that block merging'
2+
on:
3+
pull_request:
4+
types:
5+
- opened
6+
- labeled
7+
- unlabeled
8+
9+
jobs:
10+
ensure-blocking-pr-labels-absent:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
pull-requests: read
14+
steps:
15+
- uses: actions/checkout@v3
16+
- name: Set up Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
cache: yarn
20+
- name: Install dependencies
21+
run: yarn --immutable
22+
- name: Run command
23+
uses: actions/github-script@v7
24+
with:
25+
script: |
26+
if (context.payload.pull_request.labels.some((label) => label.name === 'DO-NOT-MERGE')) {
27+
core.setFailed(
28+
"PR cannot be merged because it contains the label 'DO-NOT-MERGE'."
29+
);
30+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: 'MetaMask Security Code Scanner'
2+
3+
on:
4+
push:
5+
branches: ['main']
6+
pull_request:
7+
branches: ['main']
8+
9+
jobs:
10+
run-security-scan:
11+
runs-on: ubuntu-latest
12+
permissions:
13+
actions: read
14+
contents: read
15+
security-events: write
16+
steps:
17+
- name: MetaMask Security Code Scanner
18+
uses: MetaMask/Security-Code-Scanner@main
19+
with:
20+
repo: ${{ github.repository }}
21+
paths_ignored: |
22+
'**/test*/'
23+
docs/
24+
'**/*.test.js'
25+
'**/*.test.ts'
26+
node_modules
27+
merged-packages/
28+
'**/jest.environment.js'
29+
mixpanel_project_token: ${{secrets.SECURITY_CODE_SCANNER_MIXPANEL_TOKEN}}
30+
slack_webhook: ${{ secrets.APPSEC_BOT_SLACK_WEBHOOK }}

package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/core-monorepo",
3-
"version": "115.0.0",
3+
"version": "120.0.0",
44
"private": true,
55
"description": "Monorepo for packages shared between MetaMask clients",
66
"repository": {
@@ -44,7 +44,7 @@
4444
"@babel/core": "^7.23.5",
4545
"@babel/plugin-transform-modules-commonjs": "^7.23.3",
4646
"@babel/preset-typescript": "^7.23.3",
47-
"@lavamoat/allow-scripts": "^2.3.1",
47+
"@lavamoat/allow-scripts": "^3.0.2",
4848
"@metamask/create-release-branch": "^3.0.0",
4949
"@metamask/eslint-config": "^12.2.0",
5050
"@metamask/eslint-config-jest": "^12.1.0",
@@ -92,11 +92,6 @@
9292
"@lavamoat/preinstall-always-fail": false,
9393
"@keystonehq/bc-ur-registry-eth>hdkey>secp256k1": true,
9494
"babel-runtime>core-js": false,
95-
"eth-sig-util>ethereumjs-abi>ethereumjs-util>keccakjs>sha3": true,
96-
"eth-sig-util>ethereumjs-util>keccak": true,
97-
"eth-sig-util>ethereumjs-util>secp256k1": true,
98-
"ethereumjs-util>ethereum-cryptography>keccak": true,
99-
"ethereumjs-util>ethereum-cryptography>secp256k1": true,
10095
"simple-git-hooks": false
10196
}
10297
}

packages/accounts-controller/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,15 @@
3131
"test:watch": "jest --watch"
3232
},
3333
"dependencies": {
34+
"@ethereumjs/util": "^8.1.0",
3435
"@metamask/base-controller": "^4.1.1",
3536
"@metamask/eth-snap-keyring": "^2.1.1",
3637
"@metamask/keyring-api": "^3.0.0",
3738
"@metamask/snaps-sdk": "^1.3.2",
3839
"@metamask/snaps-utils": "^5.1.2",
3940
"@metamask/utils": "^8.3.0",
4041
"deepmerge": "^4.2.2",
41-
"ethereumjs-util": "^7.0.10",
42+
"ethereum-cryptography": "^2.1.2",
4243
"immer": "^9.0.6",
4344
"uuid": "^8.3.2"
4445
},

packages/accounts-controller/src/AccountsController.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1401,7 +1401,7 @@ describe('AccountsController', () => {
14011401
KeyringTypes.ledger,
14021402
KeyringTypes.lattice,
14031403
KeyringTypes.qr,
1404-
KeyringTypes.custody,
1404+
'Custody - JSON - RPC',
14051405
])('should add accounts for %s type', async (keyringType) => {
14061406
mockUUID.mockReturnValue('mock-id');
14071407

packages/accounts-controller/src/AccountsController.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { toBuffer } from '@ethereumjs/util';
12
import type {
23
ControllerGetStateAction,
34
ControllerStateChangeEvent,
@@ -22,7 +23,7 @@ import type {
2223
import type { SnapId } from '@metamask/snaps-sdk';
2324
import type { Snap } from '@metamask/snaps-utils';
2425
import type { Keyring, Json } from '@metamask/utils';
25-
import { sha256FromString } from 'ethereumjs-util';
26+
import { sha256 } from 'ethereum-cryptography/sha256';
2627
import type { Draft } from 'immer';
2728
import { v4 as uuid } from 'uuid';
2829

@@ -455,7 +456,7 @@ export class AccountsController extends BaseController<
455456
address,
456457
);
457458
const v4options = {
458-
random: sha256FromString(address).slice(0, 16),
459+
random: sha256(toBuffer(address)).slice(0, 16),
459460
};
460461

461462
internalAccounts.push({

packages/accounts-controller/src/utils.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { KeyringTypes } from '@metamask/keyring-controller';
2-
import { sha256FromString } from 'ethereumjs-util';
1+
import { toBuffer } from '@ethereumjs/util';
2+
import { isCustodyKeyring, KeyringTypes } from '@metamask/keyring-controller';
3+
import { sha256 } from 'ethereum-cryptography/sha256';
34
import { v4 as uuid } from 'uuid';
45

56
/**
@@ -9,6 +10,12 @@ import { v4 as uuid } from 'uuid';
910
* @returns The name of the keyring type.
1011
*/
1112
export function keyringTypeToName(keyringType: string): string {
13+
// Custody keyrings are a special case, as they are not a single type
14+
// they just start with the prefix `Custody`
15+
if (isCustodyKeyring(keyringType)) {
16+
return 'Custody';
17+
}
18+
1219
switch (keyringType) {
1320
case KeyringTypes.simple: {
1421
return 'Account';
@@ -31,9 +38,6 @@ export function keyringTypeToName(keyringType: string): string {
3138
case KeyringTypes.snap: {
3239
return 'Snap Account';
3340
}
34-
case KeyringTypes.custody: {
35-
return 'Custody';
36-
}
3741
default: {
3842
throw new Error(`Unknown keyring ${keyringType}`);
3943
}
@@ -47,7 +51,7 @@ export function keyringTypeToName(keyringType: string): string {
4751
*/
4852
export function getUUIDFromAddressOfNormalAccount(address: string): string {
4953
const v4options = {
50-
random: sha256FromString(address).slice(0, 16),
54+
random: sha256(toBuffer(address)).slice(0, 16),
5155
};
5256

5357
return uuid(v4options);

packages/address-book-controller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"dependencies": {
3434
"@metamask/base-controller": "^4.1.1",
35-
"@metamask/controller-utils": "^8.0.2",
35+
"@metamask/controller-utils": "^8.0.3",
3636
"@metamask/utils": "^8.3.0"
3737
},
3838
"devDependencies": {

packages/approval-controller/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
},
3333
"dependencies": {
3434
"@metamask/base-controller": "^4.1.1",
35-
"@metamask/rpc-errors": "^6.1.0",
35+
"@metamask/rpc-errors": "^6.2.1",
3636
"@metamask/utils": "^8.3.0",
3737
"nanoid": "^3.1.31"
3838
},

packages/assets-controllers/CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Added
1111

1212
- **BREAKING:** Adds `@metamask/accounts-controller` ^8.0.0 and `@metamask/keyring-controller` ^12.0.0 as dependencies and peer dependencies. ([#3775](https://github.com/MetaMask/core/pull/3775/)).
13-
- **BREAKING:** `TokenDetectionController` newly subscribes to the `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`, `KeyringController:lock`, `KeyringController:unlock` events, and allows the `PreferencesController:getState` messenger action. ([#3775](https://github.com/MetaMask/core/pull/3775/))
13+
- **BREAKING:** `TokenDetectionController` newly subscribes to the `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`, `KeyringController:lock`, `KeyringController:unlock` events, and allows messenger actions `AccountsController:getSelectedAccount`, `NetworkController:findNetworkClientIdByChainId`, `NetworkController:getNetworkConfigurationByNetworkClientId`, `NetworkController:getProviderConfig`, `KeyringController:getState`, `PreferencesController:getState`, `TokenListController:getState`, `TokensController:getState`, `TokensController:addDetectedTokens`. ([#3775](https://github.com/MetaMask/core/pull/3775/)), ([#3923](https://github.com/MetaMask/core/pull/3923/))
1414
- `TokensController` now exports `TokensControllerActions`, `TokensControllerGetStateAction`, `TokensControllerAddDetectedTokensAction`, `TokensControllerEvents`, `TokensControllerStateChangeEvent`. ([#3690](https://github.com/MetaMask/core/pull/3690/))
1515

1616
### Changed
1717

18-
- **BREAKING:** `TokenDetectionController` is merged with `DetectTokensController` from the `metamask-extension` repo. ([#3775](https://github.com/MetaMask/core/pull/3775/))
18+
- **BREAKING:** `TokenDetectionController` is merged with `DetectTokensController` from the `metamask-extension` repo. ([#3775](https://github.com/MetaMask/core/pull/3775/), [#3923](https://github.com/MetaMask/core/pull/3923)), ([#3938](https://github.com/MetaMask/core/pull/3938))
1919
- **BREAKING:** `TokenDetectionController` now resets its polling interval to the default value of 3 minutes when token detection is triggered by external controller events `KeyringController:unlock`, `TokenListController:stateChange`, `PreferencesController:stateChange`, `AccountsController:selectedAccountChange`.
2020
- **BREAKING:** `TokenDetectionController` now refetches tokens on `NetworkController:networkDidChange` if the `networkClientId` is changed instead of `chainId`.
2121
- **BREAKING:** `TokenDetectionController` cannot initiate polling or token detection if `KeyringController` state is locked.
22+
- **BREAKING:** The `detectTokens` method input option `accountAddress` has been renamed to `selectedAddress`.
2223
- **BREAKING:** The `detectTokens` method now excludes tokens that are already included in the `TokensController`'s `detectedTokens` list from the batch of incoming tokens it sends to the `TokensController` `addDetectedTokens` method.
2324
- **BREAKING:** The constructor for `TokenDetectionController` expects a new required proprerty `trackMetaMetricsEvent`, which defines the callback that is called in the `detectTokens` method.
25+
- The constructor option `selectedAddress` no longer defaults to `''` if omitted. Instead, the correct address is assigned using the `AccountsController:getSelectedAccount` messenger action.
2426
- **BREAKING:** In Mainnet, even if the `PreferenceController`'s `useTokenDetection` option is set to false, automatic token detection is performed on the legacy token list (token data from the contract-metadata repo).
2527
- **BREAKING:** The `TokensState` type is now defined as a type alias rather than an interface. ([#3690](https://github.com/MetaMask/core/pull/3690/))
2628
- This is breaking because it could affect how this type is used with other types, such as `Json`, which does not support TypeScript interfaces.

packages/assets-controllers/jest.config.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ module.exports = merge(baseConfig, {
1717
// An object that configures minimum threshold enforcement for coverage results
1818
coverageThreshold: {
1919
global: {
20-
branches: 88.47,
21-
functions: 95.89,
22-
lines: 96.87,
23-
statements: 96.87,
20+
branches: 88.58,
21+
functions: 96.98,
22+
lines: 97.35,
23+
statements: 97.4,
2424
},
2525
},
2626

packages/assets-controllers/package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"test:watch": "jest --watch"
3232
},
3333
"dependencies": {
34+
"@ethereumjs/util": "^8.1.0",
3435
"@ethersproject/address": "^5.7.0",
3536
"@ethersproject/bignumber": "^5.7.0",
3637
"@ethersproject/contracts": "^5.7.0",
@@ -40,19 +41,20 @@
4041
"@metamask/approval-controller": "^5.1.2",
4142
"@metamask/base-controller": "^4.1.1",
4243
"@metamask/contract-metadata": "^2.4.0",
43-
"@metamask/controller-utils": "^8.0.2",
44+
"@metamask/controller-utils": "^8.0.3",
4445
"@metamask/eth-query": "^4.0.0",
4546
"@metamask/keyring-controller": "^12.2.0",
4647
"@metamask/metamask-eth-abis": "3.0.0",
4748
"@metamask/network-controller": "^17.2.0",
4849
"@metamask/polling-controller": "^5.0.0",
4950
"@metamask/preferences-controller": "^7.0.0",
50-
"@metamask/rpc-errors": "^6.1.0",
51+
"@metamask/rpc-errors": "^6.2.1",
5152
"@metamask/utils": "^8.3.0",
53+
"@types/bn.js": "^5.1.5",
5254
"@types/uuid": "^8.3.0",
5355
"async-mutex": "^0.2.6",
56+
"bn.js": "^5.2.1",
5457
"cockatiel": "^3.1.2",
55-
"ethereumjs-util": "^7.0.10",
5658
"lodash": "^4.17.21",
5759
"multiformats": "^9.5.2",
5860
"single-call-balance-checker-abi": "^1.0.0",

packages/assets-controllers/src/AssetsContractController.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import type {
1111
} from '@metamask/network-controller';
1212
import type { PreferencesState } from '@metamask/preferences-controller';
1313
import type { Hex } from '@metamask/utils';
14-
import type { BN } from 'ethereumjs-util';
14+
import type BN from 'bn.js';
1515
import abiSingleCallBalancesContract from 'single-call-balance-checker-abi';
1616

1717
import { SupportedTokenDetectionNetworks } from './assetsUtil';

packages/assets-controllers/src/NftController.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
getDefaultPreferencesState,
2727
type PreferencesState,
2828
} from '@metamask/preferences-controller';
29-
import { BN } from 'ethereumjs-util';
29+
import BN from 'bn.js';
3030
import nock from 'nock';
3131
import * as sinon from 'sinon';
3232
import { v4 } from 'uuid';

packages/assets-controllers/src/NftController.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ import type {
2626
import type { PreferencesState } from '@metamask/preferences-controller';
2727
import { rpcErrors } from '@metamask/rpc-errors';
2828
import type { Hex } from '@metamask/utils';
29+
import { remove0x } from '@metamask/utils';
2930
import { Mutex } from 'async-mutex';
30-
import { BN, stripHexPrefix } from 'ethereumjs-util';
31+
import BN from 'bn.js';
3132
import { EventEmitter } from 'events';
3233
import { v4 as random } from 'uuid';
3334

@@ -568,7 +569,7 @@ export class NftController extends BaseControllerV1<NftConfig, NftState> {
568569
return [tokenURI, ERC1155];
569570
}
570571

571-
const hexTokenId = stripHexPrefix(BNToHex(new BN(tokenId)))
572+
const hexTokenId = remove0x(BNToHex(new BN(tokenId)))
572573
.padStart(64, '0')
573574
.toLowerCase();
574575
return [tokenURI.replace('{id}', hexTokenId), ERC1155];

packages/assets-controllers/src/NftDetectionController.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,34 @@ describe('NftDetectionController', () => {
570570
},
571571
);
572572
});
573+
574+
it('should only re-detect when relevant settings change', async () => {
575+
await withController(
576+
{},
577+
async ({ controller, triggerPreferencesStateChange }) => {
578+
const detectNfts = sinon.stub(controller, 'detectNfts');
579+
580+
// Repeated preference changes should only trigger 1 detection
581+
for (let i = 0; i < 5; i++) {
582+
triggerPreferencesStateChange({
583+
...getDefaultPreferencesState(),
584+
useNftDetection: true,
585+
});
586+
}
587+
await advanceTime({ clock, duration: 1 });
588+
expect(detectNfts.callCount).toBe(1);
589+
590+
// Irrelevant preference changes shouldn't trigger a detection
591+
triggerPreferencesStateChange({
592+
...getDefaultPreferencesState(),
593+
useNftDetection: true,
594+
securityAlertsEnabled: true,
595+
});
596+
await advanceTime({ clock, duration: 1 });
597+
expect(detectNfts.callCount).toBe(1);
598+
},
599+
);
600+
});
573601
});
574602

575603
type WithControllerCallback<ReturnValue> = ({

packages/assets-controllers/src/NftDetectionController.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,6 @@ export class NftDetectionController extends StaticIntervalPollingControllerV1<
299299
!useNftDetection !== disabled
300300
) {
301301
this.configure({ selectedAddress, disabled: !useNftDetection });
302-
}
303-
304-
if (useNftDetection !== undefined) {
305302
if (useNftDetection) {
306303
this.start();
307304
} else {

packages/assets-controllers/src/Standards/ERC20Standard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1+
import { toUtf8 } from '@ethereumjs/util';
12
import { Contract } from '@ethersproject/contracts';
23
import type { Web3Provider } from '@ethersproject/providers';
34
import { decodeSingle } from '@metamask/abi-utils';
45
import { ERC20 } from '@metamask/controller-utils';
56
import { abiERC20 } from '@metamask/metamask-eth-abis';
67
import { assertIsStrictHexString } from '@metamask/utils';
7-
import { toUtf8 } from 'ethereumjs-util';
8-
import type { BN } from 'ethereumjs-util';
8+
import type BN from 'bn.js';
99

1010
import { ethersBigNumberToBN } from '../assetsUtil';
1111

packages/assets-controllers/src/Standards/NftStandards/ERC1155/ERC1155Standard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
timeoutFetch,
1010
} from '@metamask/controller-utils';
1111
import { abiERC1155 } from '@metamask/metamask-eth-abis';
12-
import type { BN } from 'ethereumjs-util';
12+
import type * as BN from 'bn.js';
1313

1414
import { getFormattedIpfsUrl, ethersBigNumberToBN } from '../../../assetsUtil';
1515

packages/assets-controllers/src/TokenBalancesController.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ControllerMessenger } from '@metamask/base-controller';
22
import { toHex } from '@metamask/controller-utils';
3-
import { BN } from 'ethereumjs-util';
3+
import BN from 'bn.js';
44

55
import { flushPromises } from '../../../tests/helpers';
66
import type {

0 commit comments

Comments
 (0)