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)) 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..3fd0725fd9e 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, @@ -2303,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;