Skip to content

Commit 74d4186

Browse files
chore: bump @metamask/{keyring, profile-sync}-controller (#30637)
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> These packages are being bumped to their latest version: ### `@metamask/keyring-controller` - **BREAKING:** `addNewKeyring` method now returns `Promise<KeyringMetadata>` instead of `Promise<unknown>` ([#5372](MetaMask/core#5372)) - Consumers can use the returned `KeyringMetadata.id` to access the created keyring instance via `withKeyring`. - **BREAKING:** `withKeyring` method now requires a callback argument of type `({ keyring: SelectedKeyring; metadata: KeyringMetadata }) => Promise<CallbackResult>` ([#5372](MetaMask/core#5372)) - Bump `@metamask/keyring-internal-api` from `^4.0.3` to `^5.0.0` ([#5405](MetaMask/core#5405)) - Bump `@metamask/eth-hd-keyring` from `^10.0.0` to `^11.0.0` ([#5405](MetaMask/core#5405)) - Bump `@metamask/eth-simple-keyring` from `^8.1.0` to `^9.0.0` ([#5405](MetaMask/core#5405)) ### `@metamask/profile-sync-controller` - Bump `@metamask/keyring-internal-api` from `^4.0.3` to `^5.0.0` ([#5405](MetaMask/core#5405)) ### `@metamask/eth-ledger-bridge-keyring` - **BREAKING:** `LedgerKeyring` now implements the `Keyring` type ([#194](MetaMask/accounts#194)) - The class does not extend `EventEmitter` anymore. - The `LedgerKeyring.accounts` class variable is now a `readonly Hex[]` array. - The `addAccounts` method signature has been changed: - An `amount` number parameter is now required to specify the number of accounts to add. - The method now returns a promise resolving to an array of `Hex` addresses. - The `unlock` method now returns `Promise<Hex>`. - The `getAccounts` method now returns `Promise<Hex[]>`. - The `deserialize` method now requires a `LedgerKeyringSerializedState` typed parameter. - The `signTransaction` method now accepts an `Hex` typed value as the `address` parameter. - The `signMessage` method now accepts an `Hex` typed value as the `withAccount` parameter. - The `signPersonalMessage` method now accepts an `Hex` typed value as the `withAccount` parameter. - The `signTypedData` method now accepts an `Hex` typed value as the `withAccount` parameter. - The `unlockAccountByAddress` method now accepts an `Hex` typed value as the `address` parameter. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/30637?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots. --------- Co-authored-by: MetaMask Bot <metamaskbot@users.noreply.github.com>
1 parent 9811f62 commit 74d4186

File tree

12 files changed

+112
-231
lines changed

12 files changed

+112
-231
lines changed

app/scripts/controllers/mmi-controller.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -313,10 +313,11 @@ describe('MMIController', function () {
313313
const type = 'mock-keyring-type';
314314
mmiController.keyringController.getKeyringsByType = jest
315315
.fn()
316-
.mockReturnValue([]);
316+
.mockReturnValueOnce([])
317+
.mockReturnValueOnce(['new-keyring']);
317318
mmiController.keyringController.addNewKeyring = jest
318319
.fn()
319-
.mockResolvedValue('new-keyring');
320+
.mockResolvedValue('new-keyring-metadata');
320321

321322
const result = await mmiController.addKeyringIfNotExists(type);
322323

app/scripts/controllers/mmi-controller.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,8 @@ export class MMIController {
226226
async addKeyringIfNotExists(type: KeyringTypes) {
227227
let keyring = await this.keyringController.getKeyringsByType(type)[0];
228228
if (!keyring) {
229-
keyring = await this.keyringController.addNewKeyring(type);
229+
await this.keyringController.addNewKeyring(type);
230+
[keyring] = await this.keyringController.getKeyringsByType(type);
230231
}
231232
return keyring;
232233
}

app/scripts/metamask-controller.js

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,6 @@ import {
189189
LedgerTransportTypes,
190190
} from '../../shared/constants/hardware-wallets';
191191
import { KeyringType } from '../../shared/constants/keyring';
192-
///: BEGIN:ONLY_INCLUDE_IF(multi-srp)
193-
import { findKeyringId } from '../../shared/lib/keyring';
194-
///: END:ONLY_INCLUDE_IF
195192
import {
196193
RestrictedMethods,
197194
ExcludedSnapPermissions,
@@ -2455,11 +2452,14 @@ export default class MetamaskController extends EventEmitter {
24552452
* @returns {SnapKeyring}
24562453
*/
24572454
async getSnapKeyring() {
2455+
// TODO: Use `withKeyring` instead
24582456
let [snapKeyring] = this.keyringController.getKeyringsByType(
24592457
KeyringType.snap,
24602458
);
24612459
if (!snapKeyring) {
2462-
snapKeyring = await this.keyringController.addNewKeyring(
2460+
await this.keyringController.addNewKeyring(KeyringType.snap);
2461+
// TODO: Use `withKeyring` instead
2462+
[snapKeyring] = this.keyringController.getKeyringsByType(
24632463
KeyringType.snap,
24642464
);
24652465
}
@@ -2633,7 +2633,7 @@ export default class MetamaskController extends EventEmitter {
26332633
{
26342634
id: source,
26352635
},
2636-
async (keyring) => ({
2636+
async ({ keyring }) => ({
26372637
type: keyring.type,
26382638
mnemonic: keyring.mnemonic,
26392639
}),
@@ -4316,7 +4316,7 @@ export default class MetamaskController extends EventEmitter {
43164316
try {
43174317
// TODO: `getKeyringsByType` is deprecated, this logic should probably be moved to the `KeyringController`.
43184318
// FIXME: The `KeyringController` does not check yet for duplicated accounts with HD keyrings, see: https://github.com/MetaMask/core/issues/5411
4319-
const alreadyImportedSrp = await this.keyringController
4319+
const alreadyImportedSrp = this.keyringController
43204320
.getKeyringsByType(KeyringTypes.hd)
43214321
.some((keyring) => {
43224322
return (
@@ -4332,26 +4332,22 @@ export default class MetamaskController extends EventEmitter {
43324332
);
43334333
}
43344334

4335-
const newKeyring = await this.keyringController.addNewKeyring(
4335+
const { id } = await this.keyringController.addNewKeyring(
43364336
KeyringTypes.hd,
43374337
{
43384338
mnemonic,
43394339
numberOfAccounts: 1,
43404340
},
43414341
);
4342-
const [newAccountAddress] = await newKeyring.getAccounts();
4342+
const [newAccountAddress] = await this.keyringController.withKeyring(
4343+
{ id },
4344+
async ({ keyring }) => keyring.getAccounts(),
4345+
);
43434346
const account =
43444347
this.accountsController.getAccountByAddress(newAccountAddress);
43454348
this.accountsController.setSelectedAccount(account.id);
43464349

4347-
// TODO: Find a way to encapsulate this logic in the KeyringController itself.
4348-
const { keyrings, keyringsMetadata } = this.keyringController.state;
4349-
const keyringId = findKeyringId(keyrings, keyringsMetadata, {
4350-
address: newAccountAddress,
4351-
type: KeyringTypes.hd,
4352-
});
4353-
4354-
await this._addAccountsWithBalance(keyringId);
4350+
await this._addAccountsWithBalance(id);
43554351

43564352
return newAccountAddress;
43574353
} finally {
@@ -4372,10 +4368,13 @@ export default class MetamaskController extends EventEmitter {
43724368
const releaseLock = await this.createVaultMutex.acquire();
43734369
try {
43744370
// addNewKeyring auto creates 1 account.
4375-
const newHdkeyring = await this.keyringController.addNewKeyring(
4371+
const { id } = await this.keyringController.addNewKeyring(
43764372
KeyringTypes.hd,
43774373
);
4378-
const [newAccount] = await newHdkeyring.getAccounts();
4374+
const [newAccount] = await this.keyringController.withKeyring(
4375+
{ id },
4376+
async ({ keyring }) => keyring.getAccounts(),
4377+
);
43794378
const account = this.accountsController.getAccountByAddress(newAccount);
43804379
this.accountsController.setSelectedAccount(account.id);
43814380

@@ -4451,7 +4450,7 @@ export default class MetamaskController extends EventEmitter {
44514450

44524451
const accounts = await this.keyringController.withKeyring(
44534452
keyringSelector,
4454-
async (keyring) => {
4453+
async ({ keyring }) => {
44554454
return await keyring.getAccounts();
44564455
},
44574456
);
@@ -4487,7 +4486,7 @@ export default class MetamaskController extends EventEmitter {
44874486
// This account has assets, so check the next one
44884487
address = await this.keyringController.withKeyring(
44894488
keyringSelector,
4490-
async (keyring) => {
4489+
async ({ keyring }) => {
44914490
const [newAddress] = await keyring.addAccounts(1);
44924491
return newAddress;
44934492
},
@@ -4770,11 +4769,13 @@ export default class MetamaskController extends EventEmitter {
47704769
// The `getKeyringForAccount` is now deprecated, so we just use `withKeyring` instead to access our keyring.
47714770
return await this.keyringController.withKeyring(
47724771
{ address },
4773-
({ type: keyringType, bridge: keyringBridge }) =>
4772+
({ keyring }) => {
4773+
const { type: keyringType, bridge: keyringBridge } = keyring;
47744774
// Specific case for OneKey devices, see `ONE_KEY_VIA_TREZOR_MINOR_VERSION` for further details.
4775-
keyringBridge?.minorVersion === ONE_KEY_VIA_TREZOR_MINOR_VERSION
4775+
return keyringBridge?.minorVersion === ONE_KEY_VIA_TREZOR_MINOR_VERSION
47764776
? HardwareKeyringType.oneKey
4777-
: HardwareKeyringType[keyringType],
4777+
: HardwareKeyringType[keyringType];
4778+
},
47784779
);
47794780
}
47804781

@@ -4832,23 +4833,26 @@ export default class MetamaskController extends EventEmitter {
48324833
* @returns {'ledger' | 'lattice' | string | undefined}
48334834
*/
48344835
async getDeviceModel(address) {
4835-
return this.keyringController.withKeyring({ address }, async (keyring) => {
4836-
switch (keyring.type) {
4837-
case KeyringType.trezor:
4838-
case KeyringType.oneKey:
4839-
return keyring.getModel();
4840-
case KeyringType.qr:
4841-
return keyring.getName();
4842-
case KeyringType.ledger:
4843-
// TODO: get model after ledger keyring exposes method
4844-
return HardwareDeviceNames.ledger;
4845-
case KeyringType.lattice:
4846-
// TODO: get model after lattice keyring exposes method
4847-
return HardwareDeviceNames.lattice;
4848-
default:
4849-
return undefined;
4850-
}
4851-
});
4836+
return this.keyringController.withKeyring(
4837+
{ address },
4838+
async ({ keyring }) => {
4839+
switch (keyring.type) {
4840+
case KeyringType.trezor:
4841+
case KeyringType.oneKey:
4842+
return keyring.getModel();
4843+
case KeyringType.qr:
4844+
return keyring.getName();
4845+
case KeyringType.ledger:
4846+
// TODO: get model after ledger keyring exposes method
4847+
return HardwareDeviceNames.ledger;
4848+
case KeyringType.lattice:
4849+
// TODO: get model after lattice keyring exposes method
4850+
return HardwareDeviceNames.lattice;
4851+
default:
4852+
return undefined;
4853+
}
4854+
},
4855+
);
48524856
}
48534857

48544858
/**
@@ -4936,7 +4940,7 @@ export default class MetamaskController extends EventEmitter {
49364940

49374941
const addedAccountAddress = await this.keyringController.withKeyring(
49384942
keyringSelector,
4939-
async (keyring) => {
4943+
async ({ keyring }) => {
49404944
if (keyring.type !== KeyringTypes.hd) {
49414945
throw new Error('Cannot add account to non-HD keyring');
49424946
}
@@ -7573,7 +7577,7 @@ export default class MetamaskController extends EventEmitter {
75737577

75747578
return this.keyringController.withKeyring(
75757579
{ type: keyringType },
7576-
async (keyring) => {
7580+
async ({ keyring }) => {
75777581
if (options.hdPath && keyring.setHdPath) {
75787582
keyring.setHdPath(options.hdPath);
75797583
}

app/scripts/metamask-controller.test.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ const buildMockKeyringBridge = (publicKeyPayload) =>
195195
jest.fn(() => ({
196196
init: jest.fn(),
197197
dispose: jest.fn(),
198+
destroy: jest.fn(),
198199
updateTransportMethod: jest.fn(),
199200
getPublicKey: jest.fn(async () => publicKeyPayload),
200201
}));
@@ -214,6 +215,7 @@ jest.mock('@metamask/eth-ledger-bridge-keyring', () => ({
214215
...jest.requireActual('@metamask/eth-ledger-bridge-keyring'),
215216
LedgerIframeBridge: buildMockKeyringBridge({
216217
publicKey: KNOWN_PUBLIC_KEY,
218+
address: KNOWN_PUBLIC_KEY_ADDRESSES[0].address,
217219
chainCode: '0x1',
218220
}),
219221
}));
@@ -1859,7 +1861,7 @@ describe('MetaMaskController', () => {
18591861
async (type) => {
18601862
jest
18611863
.spyOn(metamaskController.keyringController, 'withKeyring')
1862-
.mockImplementation((_, fn) => fn({ type }));
1864+
.mockImplementation((_, fn) => fn({ keyring: { type } }));
18631865

18641866
const result = await metamaskController.getHardwareTypeForMetric(
18651867
'0x123',
@@ -1877,7 +1879,7 @@ describe('MetaMaskController', () => {
18771879
type: 'trezor',
18781880
bridge: { minorVersion: ONE_KEY_VIA_TREZOR_MINOR_VERSION },
18791881
};
1880-
return fn(keyring);
1882+
return fn({ keyring });
18811883
});
18821884

18831885
const result = await metamaskController.getHardwareTypeForMetric(

lavamoat/browserify/beta/policy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@
11471147
"@ethereumjs/tx>@ethereumjs/util": true,
11481148
"@metamask/eth-ledger-bridge-keyring>@ledgerhq/hw-app-eth": true,
11491149
"@metamask/eth-ledger-bridge-keyring>@metamask/eth-sig-util": true,
1150+
"@metamask/utils": true,
11501151
"browserify>buffer": true,
1151-
"webpack>events": true,
11521152
"@metamask/eth-trezor-keyring>hdkey": true
11531153
}
11541154
},

lavamoat/browserify/flask/policy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@
11471147
"@ethereumjs/tx>@ethereumjs/util": true,
11481148
"@metamask/eth-ledger-bridge-keyring>@ledgerhq/hw-app-eth": true,
11491149
"@metamask/eth-ledger-bridge-keyring>@metamask/eth-sig-util": true,
1150+
"@metamask/utils": true,
11501151
"browserify>buffer": true,
1151-
"webpack>events": true,
11521152
"@metamask/eth-trezor-keyring>hdkey": true
11531153
}
11541154
},

lavamoat/browserify/main/policy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@
11471147
"@ethereumjs/tx>@ethereumjs/util": true,
11481148
"@metamask/eth-ledger-bridge-keyring>@ledgerhq/hw-app-eth": true,
11491149
"@metamask/eth-ledger-bridge-keyring>@metamask/eth-sig-util": true,
1150+
"@metamask/utils": true,
11501151
"browserify>buffer": true,
1151-
"webpack>events": true,
11521152
"@metamask/eth-trezor-keyring>hdkey": true
11531153
}
11541154
},

lavamoat/browserify/mmi/policy.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1239,8 +1239,8 @@
12391239
"@ethereumjs/tx>@ethereumjs/util": true,
12401240
"@metamask/eth-ledger-bridge-keyring>@ledgerhq/hw-app-eth": true,
12411241
"@metamask/eth-ledger-bridge-keyring>@metamask/eth-sig-util": true,
1242+
"@metamask/utils": true,
12421243
"browserify>buffer": true,
1243-
"webpack>events": true,
12441244
"@metamask/eth-trezor-keyring>hdkey": true
12451245
}
12461246
},

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,19 @@
271271
"@metamask/ens-resolver-snap": "^0.1.2",
272272
"@metamask/eth-json-rpc-filters": "^9.0.0",
273273
"@metamask/eth-json-rpc-middleware": "^15.1.2",
274-
"@metamask/eth-ledger-bridge-keyring": "^8.0.3",
274+
"@metamask/eth-ledger-bridge-keyring": "^9.0.0",
275275
"@metamask/eth-sig-util": "^7.0.1",
276276
"@metamask/eth-snap-keyring": "^11.1.0",
277277
"@metamask/eth-token-tracker": "^10.0.2",
278-
"@metamask/eth-trezor-keyring": "^6.0.0",
278+
"@metamask/eth-trezor-keyring": "^6.1.1",
279279
"@metamask/etherscan-link": "^3.0.0",
280280
"@metamask/gas-fee-controller": "^22.0.3",
281281
"@metamask/jazzicon": "^2.0.0",
282282
"@metamask/json-rpc-engine": "^10.0.0",
283283
"@metamask/json-rpc-middleware-stream": "^8.0.4",
284284
"@metamask/keyring-api": "^17.2.1",
285-
"@metamask/keyring-controller": "^19.2.0",
286-
"@metamask/keyring-internal-api": "^4.0.3",
285+
"@metamask/keyring-controller": "^20.0.0",
286+
"@metamask/keyring-internal-api": "^5.0.0",
287287
"@metamask/keyring-snap-client": "^4.0.1",
288288
"@metamask/logging-controller": "^6.0.4",
289289
"@metamask/logo": "^4.0.0",
@@ -305,7 +305,7 @@
305305
"@metamask/post-message-stream": "^9.0.0",
306306
"@metamask/ppom-validator": "0.36.0",
307307
"@metamask/preinstalled-example-snap": "^0.3.0",
308-
"@metamask/profile-sync-controller": "^8.1.1",
308+
"@metamask/profile-sync-controller": "^9.0.0",
309309
"@metamask/providers": "^20.0.0",
310310
"@metamask/queued-request-controller": "^7.0.1",
311311
"@metamask/rate-limit-controller": "^6.0.3",

0 commit comments

Comments
 (0)