From 839701663e2910e1d75c2ecd075a3df7b67ad9c4 Mon Sep 17 00:00:00 2001 From: Michele Esposito Date: Fri, 20 Feb 2026 18:01:43 +0100 Subject: [PATCH 1/3] feat!: add serialized keyring data to state --- .../src/KeyringController.test.ts | 22 +++++++++++++------ .../src/KeyringController.ts | 7 +++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/packages/keyring-controller/src/KeyringController.test.ts b/packages/keyring-controller/src/KeyringController.test.ts index 9498f4efe78..09e391d5dbc 100644 --- a/packages/keyring-controller/src/KeyringController.test.ts +++ b/packages/keyring-controller/src/KeyringController.test.ts @@ -1330,6 +1330,9 @@ describe('KeyringController', () => { const newKeyring = { accounts: [address], type: 'Simple Key Pair', + data: [ + '1e4e6a4c0c077f4ae8ddfbf372918e61dd0fb4a4cfa592cb16e7546d505e68fc', + ], }; const importedAccountAddress = await controller.importAccountWithStrategy( @@ -1422,6 +1425,9 @@ describe('KeyringController', () => { const newKeyring = { accounts: [address], type: 'Simple Key Pair', + data: [ + '62390c1fe2fe70071bf6dc7345a872de041dc9663b89b2e28e6ce920427169c7', + ], }; const modifiedState = { ...initialState, @@ -2868,16 +2874,14 @@ describe('KeyringController', () => { }); it('should unlock succesfully when the controller is instantiated with an existing `keyringsMetadata`', async () => { - stubKeyringClassWithAccount(HdKeyring, '0x123'); + stubKeyringClassWithAccount(MockKeyring, '0x123'); await withController( { state: { vault: createVault([ { - type: KeyringTypes.hd, - data: { - accounts: ['0x123'], - }, + type: MockKeyring.type, + data: {}, metadata: { id: '123', name: '', @@ -2885,6 +2889,7 @@ describe('KeyringController', () => { }, ]), }, + keyringBuilders: [keyringBuilderFactory(MockKeyring)], skipVaultCreation: true, }, async ({ controller }) => { @@ -2892,8 +2897,9 @@ describe('KeyringController', () => { expect(controller.state.keyrings).toStrictEqual([ { - type: KeyringTypes.hd, + type: MockKeyring.type, accounts: ['0x123'], + data: {}, metadata: { id: '123', name: '', @@ -2937,6 +2943,9 @@ describe('KeyringController', () => { { type: KeyringTypes.hd, accounts: expect.any(Array), + data: { + accounts: ['0x123'], + }, metadata: { id: expect.any(String), name: '', @@ -4406,7 +4415,6 @@ describe('KeyringController', () => { ).toMatchInlineSnapshot(` { "isUnlocked": false, - "keyrings": [], } `); }, diff --git a/packages/keyring-controller/src/KeyringController.ts b/packages/keyring-controller/src/KeyringController.ts index add11e8183b..29ef9ec9c1a 100644 --- a/packages/keyring-controller/src/KeyringController.ts +++ b/packages/keyring-controller/src/KeyringController.ts @@ -291,6 +291,10 @@ export type KeyringObject = { * Keyring type. */ type: string; + /** + * Keyring serialized data. + */ + data: Json; /** * Additional data associated with the keyring. */ @@ -662,6 +666,7 @@ async function displayForKeyring({ // Cast to `string[]` here is safe here because `accounts` has no nullish // values, and `normalize` returns `string` unless given a nullish value accounts: accounts.map(normalize) as string[], + data: cloneDeep(await keyring.serialize()), metadata, }; } @@ -770,7 +775,7 @@ export class KeyringController< usedInUi: true, }, keyrings: { - includeInStateLogs: true, + includeInStateLogs: false, persist: false, includeInDebugSnapshot: false, usedInUi: true, From 8b53fd5e4db285653499d129f83d5d3b75a13797 Mon Sep 17 00:00:00 2001 From: Michele Esposito Date: Fri, 20 Feb 2026 18:36:02 +0100 Subject: [PATCH 2/3] update changelog --- packages/keyring-controller/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/keyring-controller/CHANGELOG.md b/packages/keyring-controller/CHANGELOG.md index f918e01ef62..10822eb02b9 100644 --- a/packages/keyring-controller/CHANGELOG.md +++ b/packages/keyring-controller/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- **BREAKING:** The `data` property has been added to the `KeyringObject` type ([#8009](https://github.com/MetaMask/core/pull/8009)) + - This change is also reflected in the `KeyringControllerState` type, via the `keyrings` property - Bump `@metamask/keyring-api` from `^21.0.0` to `^21.5.0` ([#7857](https://github.com/MetaMask/core/pull/7857)) - Bump `@metamask/keyring-internal-api` from `^9.0.0` to `^10.0.0` ([#7857](https://github.com/MetaMask/core/pull/7857)) From 3d4d0d0ef009ec2e49d8f4d36a19062b412411d2 Mon Sep 17 00:00:00 2001 From: Michele Esposito Date: Fri, 20 Feb 2026 18:55:34 +0100 Subject: [PATCH 3/3] add `ts-expect-error` for excessively deep type instantiation --- packages/keyring-controller/src/KeyringController.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/keyring-controller/src/KeyringController.ts b/packages/keyring-controller/src/KeyringController.ts index 29ef9ec9c1a..3fd0725fd9e 100644 --- a/packages/keyring-controller/src/KeyringController.ts +++ b/packages/keyring-controller/src/KeyringController.ts @@ -2308,6 +2308,7 @@ export class KeyringController< const updatedKeyrings = await this.#getUpdatedKeyrings(); this.update((state) => { + // @ts-expect-error The `Json` type causes the error `Type instantiation is excessively deep and possibly infinite` state.keyrings = updatedKeyrings; state.encryptionKey = encryptionKey; state.encryptionSalt = this.#encryptionKey?.salt;