Skip to content

fix: cp-12.18.0 discard duplicate accounts on unlock #32621

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

Merged
merged 28 commits into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
a12ebda
chore: bump `@metamask/keyring-controller`
mikesposito May 7, 2025
7a8160e
use preview build
mikesposito May 7, 2025
75fc785
update preview
mikesposito May 8, 2025
25d35f5
remove keyringsMetadata usage
mikesposito May 8, 2025
ca12a89
update accounts-controller
mikesposito May 8, 2025
0c1517c
test: fix create-snap-account mock
mikesposito May 13, 2025
201d68c
update `TemporaryBackgroundState` type
mikesposito May 13, 2025
56e04f9
update package previews
mikesposito May 13, 2025
f32a163
Merge branch 'main' into mikesposito/fix/unsupported-keyrings
mikesposito May 13, 2025
5f6ca3d
fix `send.test.js` mocks
mikesposito May 13, 2025
4cc86df
fix `getHDEntropyIndex`
mikesposito May 13, 2025
bcd7c06
fix `your-accounts.test.tsx` mocks
mikesposito May 13, 2025
14df23d
update fixture builder multi-srp vault
mikesposito May 13, 2025
43f2b9f
fix test lint
mikesposito May 13, 2025
5a74b5e
fix background type
mikesposito May 13, 2025
1735f93
fix `selectors.test.js`
mikesposito May 14, 2025
d8a98e2
fix `unconnected-account-alert.test.js`
mikesposito May 14, 2025
dec1e88
fix test lint
mikesposito May 14, 2025
2647750
fix test interdependence because of `createSelector`
mikesposito May 14, 2025
5ab8818
remove package previews
mikesposito May 14, 2025
6e2abf2
fix `.storybook/test-data.js`
mikesposito May 14, 2025
a25391f
Merge branch 'main' into mikesposito/fix/unsupported-keyrings
mikesposito May 14, 2025
6c65ea9
add migration to remove keyringsMetadata
mikesposito May 14, 2025
6304264
include migration
mikesposito May 14, 2025
cb22891
rename migration to 156.2
mikesposito May 15, 2025
3892b14
fix migration include
mikesposito May 15, 2025
29a8fd7
Merge branch 'main' into mikesposito/fix/unsupported-keyrings
Gudahtt May 15, 2025
1764055
rename migration 156.2 to 156.1
mikesposito May 15, 2025
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
18 changes: 8 additions & 10 deletions .storybook/test-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -1259,20 +1259,18 @@ const state = {
'0x64a845a5b02460acf8a3d84503b0d68d028b4bb4',
'0xb19ac54efa18cc3a14a5b821bfec73d284bf0c5e',
],
metadata: {
id: '01JN08SYECPZHFHB3K0J1NHJ4H',
name: '',
},
},
{
type: KeyringType.ledger,
accounts: ['0x9d0ba4ddac06032527b140912ec808ab9451b788'],
},
],
keyringsMetadata: [
{
id: '01JN08SYECPZHFHB3K0J1NHJ4H',
name: '',
},
{
id: '01JN08T38HEXPYQX2HKP1FCRMZ',
name: '',
metadata: {
id: '01JN08T38HEXPYQX2HKP1FCRMZ',
name: '',
},
},
],
...mockNetworkState(
Expand Down
1 change: 0 additions & 1 deletion app/scripts/controllers/mmi-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ describe('MMIController', function () {
state: {
keyrings: [],
isUnlocked: true,
keyringsMetadata: [],
},
encryptor: {
encrypt(_, object) {
Expand Down
50 changes: 20 additions & 30 deletions app/scripts/controllers/preferences-controller.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,10 @@ describe('preferences controller', () => {
{
type: 'HD Key Tree',
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
metadata: {
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
},
},
],
},
Expand Down Expand Up @@ -203,12 +201,10 @@ describe('preferences controller', () => {
{
type: 'HD Key Tree',
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
metadata: {
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
},
},
],
},
Expand Down Expand Up @@ -260,12 +256,10 @@ describe('preferences controller', () => {
{
type: 'HD Key Tree',
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
metadata: {
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
},
},
],
},
Expand Down Expand Up @@ -301,12 +295,10 @@ describe('preferences controller', () => {
{
type: 'HD Key Tree',
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
metadata: {
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
},
},
],
},
Expand Down Expand Up @@ -511,12 +503,10 @@ describe('preferences controller', () => {
{
type: 'HD Key Tree',
accounts: [firstAddress, secondAddress],
},
],
keyringsMetadata: [
{
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
metadata: {
id: '01JKDGGBRE3DGZA7N1PZJSQK4W',
name: '',
},
},
],
},
Expand Down
21 changes: 11 additions & 10 deletions app/scripts/metamask-controller.actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,19 @@ describe('MetaMaskController', function () {
const result2 = metamaskController.keyringController.state;

// On restore, a new keyring metadata is generated.
expect(result1.keyringsMetadata[0].id).toBe(mockULIDs[0]);
expect(result2).toStrictEqual(
expect.objectContaining({
...result1,
keyringsMetadata: [
{
expect(result1.keyrings[0].metadata.id).toBe(mockULIDs[0]);
expect(result2).toStrictEqual({
...result1,
keyrings: [
{
...result1.keyrings[0],
metadata: {
...result1.keyrings[0].metadata,
id: mockULIDs[1],
name: '',
},
],
}),
);
},
],
});
});
});

Expand Down
4 changes: 2 additions & 2 deletions app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -7129,8 +7129,8 @@ export default class MetamaskController extends EventEmitter {
.map((keyring, index) => {
if (keyring.type === KeyringTypes.hd) {
return {
id: state.keyringsMetadata[index].id,
name: state.keyringsMetadata[index].name,
id: keyring.metadata.id,
name: keyring.metadata.name,
type: 'mnemonic',
primary: index === 0,
};
Expand Down
7 changes: 3 additions & 4 deletions app/scripts/metamask-controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3992,10 +3992,9 @@ describe('MetaMaskController', () => {
metamaskController.keyringController.state.keyrings;

const newlyAddedKeyringId =
metamaskController.keyringController.state.keyringsMetadata[
metamaskController.keyringController.state.keyringsMetadata.length -
2 // -1 for the snap keyring, -1 for the newly added keyring
].id;
metamaskController.keyringController.state.keyrings[
metamaskController.keyringController.state.keyrings.length - 2 // -1 for the snap keyring, -1 for the newly added keyring
].metadata.id;

const newSRP = Buffer.from(
await metamaskController.getSeedPhrase(password, newlyAddedKeyringId),
Expand Down
101 changes: 101 additions & 0 deletions app/scripts/migrations/156.1.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
import { migrate } from './156.1';

const expectedVersion = 156.1;
const previousVersion = 156;

describe(`migration #${expectedVersion}`, () => {
it('does nothing if state has no KeyringController property', async () => {
const oldVersionedData = {
meta: { version: previousVersion },
data: {},
};
const expectedVersionedData = {
meta: { version: expectedVersion },
data: oldVersionedData.data,
};

const newVersionedData = await migrate(oldVersionedData);

expect(newVersionedData).toStrictEqual(expectedVersionedData);
});

it('does nothing if state.KeyringController is not an object', async () => {
const oldVersionedData = {
meta: { version: previousVersion },
data: {
KeyringController: 'not-an-object',
},
};
const expectedVersionedData = {
meta: { version: expectedVersion },
data: oldVersionedData.data,
};

const newVersionedData = await migrate(oldVersionedData);

expect(newVersionedData).toStrictEqual(expectedVersionedData);
});

it('does nothing if state.KeyringController has no keyringsMetadata property', async () => {
const oldVersionedData = {
meta: { version: previousVersion },
data: {
KeyringController: {
vault: 'vault',
keyrings: [
{
type: 'HD Key Tree',
accounts: ['0x1234567890abcdef'],
},
],
},
},
};
const expectedVersionedData = {
meta: { version: expectedVersion },
data: oldVersionedData.data,
};

const newVersionedData = await migrate(oldVersionedData);

expect(newVersionedData).toStrictEqual(expectedVersionedData);
});

it('removes keyringsMetadata from KeyringController state', async () => {
const oldVersionedData = {
meta: { version: previousVersion },
data: {
KeyringController: {
vault: 'vault',
keyrings: [
{
type: 'HD Key Tree',
accounts: ['0x1234567890abcdef'],
},
],
keyringsMetadata: {
someKey: 'someValue',
},
},
},
};
const expectedVersionedData = {
meta: { version: expectedVersion },
data: {
KeyringController: {
vault: 'vault',
keyrings: [
{
type: 'HD Key Tree',
accounts: ['0x1234567890abcdef'],
},
],
},
},
};

const newVersionedData = await migrate(oldVersionedData);

expect(newVersionedData).toStrictEqual(expectedVersionedData);
});
});
37 changes: 37 additions & 0 deletions app/scripts/migrations/156.1.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { hasProperty } from '@metamask/utils';
import { cloneDeep, isObject } from 'lodash';

export const version = 156.1;

/**
* Remove `keyringsMetadata` from `KeyringController` state.
*
* @param originalVersionedData - Versioned MetaMask extension state, exactly what we persist to dist.
* @param originalVersionedData.meta - State metadata.
* @param originalVersionedData.meta.version - The current state version.
* @param originalVersionedData.data - The persisted MetaMask state, keyed by controller.
* @returns Updated versioned MetaMask extension state.
*/
export async function migrate(originalVersionedData: {
meta: { version: number };
data: Record<string, unknown>;
}) {
const versionedData = cloneDeep(originalVersionedData);
versionedData.meta.version = version;
versionedData.data = transformState(versionedData.data);
return versionedData;
}

function transformState(state: Record<string, unknown>) {
const newState = state;

if (
hasProperty(newState, 'KeyringController') &&
isObject(newState.KeyringController) &&
hasProperty(newState.KeyringController, 'keyringsMetadata')
) {
delete newState.KeyringController.keyringsMetadata;
}

return newState;
}
1 change: 1 addition & 0 deletions app/scripts/migrations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ const migrations = [
require('./154'),
require('./155'),
require('./156'),
require('./156.1'),
require('./157'),
require('./158'),
];
Expand Down
4 changes: 2 additions & 2 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1678,8 +1678,7 @@
},
"@metamask/keyring-controller": {
"globals": {
"console.error": true,
"console.log": true
"console.error": true
},
"packages": {
"@ethereumjs/tx>@ethereumjs/util": true,
Expand All @@ -1691,6 +1690,7 @@
"@metamask/utils": true,
"@metamask/name-controller>async-mutex": true,
"@metamask/keyring-controller>ethereumjs-wallet": true,
"lodash": true,
"@metamask/keyring-controller>ulid": true
}
},
Expand Down
4 changes: 2 additions & 2 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1678,8 +1678,7 @@
},
"@metamask/keyring-controller": {
"globals": {
"console.error": true,
"console.log": true
"console.error": true
},
"packages": {
"@ethereumjs/tx>@ethereumjs/util": true,
Expand All @@ -1691,6 +1690,7 @@
"@metamask/utils": true,
"@metamask/name-controller>async-mutex": true,
"@metamask/keyring-controller>ethereumjs-wallet": true,
"lodash": true,
"@metamask/keyring-controller>ulid": true
}
},
Expand Down
4 changes: 2 additions & 2 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1678,8 +1678,7 @@
},
"@metamask/keyring-controller": {
"globals": {
"console.error": true,
"console.log": true
"console.error": true
},
"packages": {
"@ethereumjs/tx>@ethereumjs/util": true,
Expand All @@ -1691,6 +1690,7 @@
"@metamask/utils": true,
"@metamask/name-controller>async-mutex": true,
"@metamask/keyring-controller>ethereumjs-wallet": true,
"lodash": true,
"@metamask/keyring-controller>ulid": true
}
},
Expand Down
4 changes: 2 additions & 2 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1809,8 +1809,7 @@
},
"@metamask/keyring-controller": {
"globals": {
"console.error": true,
"console.log": true
"console.error": true
},
"packages": {
"@ethereumjs/tx>@ethereumjs/util": true,
Expand All @@ -1822,6 +1821,7 @@
"@metamask/utils": true,
"@metamask/name-controller>async-mutex": true,
"@metamask/keyring-controller>ethereumjs-wallet": true,
"lodash": true,
"@metamask/keyring-controller>ulid": true
}
},
Expand Down
Loading
Loading