diff --git a/packages/accounts-controller/package.json b/packages/accounts-controller/package.json index 8bf77eddbda..5e09e43d8ab 100644 --- a/packages/accounts-controller/package.json +++ b/packages/accounts-controller/package.json @@ -50,8 +50,8 @@ "@ethereumjs/util": "^8.1.0", "@metamask/base-controller": "^7.1.0", "@metamask/eth-snap-keyring": "^7.0.0", - "@metamask/keyring-api": "^12.0.0", - "@metamask/keyring-internal-api": "^1.0.0", + "@metamask/keyring-api": "^13.0.0", + "@metamask/keyring-internal-api": "^1.1.0", "@metamask/snaps-sdk": "^6.7.0", "@metamask/snaps-utils": "^8.3.0", "@metamask/utils": "^11.0.1", diff --git a/packages/accounts-controller/src/AccountsController.test.ts b/packages/accounts-controller/src/AccountsController.test.ts index e082ea1c38c..b28666d1523 100644 --- a/packages/accounts-controller/src/AccountsController.test.ts +++ b/packages/accounts-controller/src/AccountsController.test.ts @@ -4,6 +4,8 @@ import { EthAccountType, BtcMethod, EthMethod, + EthScopes, + BtcScopes, } from '@metamask/keyring-api'; import { KeyringTypes } from '@metamask/keyring-controller'; import type { @@ -66,6 +68,7 @@ const mockAccount: InternalAccount = { options: {}, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, + scopes: [EthScopes.Namespace], metadata: { name: 'Account 1', keyring: { type: KeyringTypes.hd }, @@ -81,6 +84,7 @@ const mockAccount2: InternalAccount = { options: {}, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, + scopes: [EthScopes.Namespace], metadata: { name: 'Account 2', keyring: { type: KeyringTypes.hd }, @@ -95,6 +99,7 @@ const mockAccount3: InternalAccount = { options: {}, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, + scopes: [EthScopes.Namespace], metadata: { name: '', keyring: { type: KeyringTypes.snap }, @@ -114,6 +119,7 @@ const mockAccount4: InternalAccount = { options: {}, methods: [...ETH_EOA_METHODS], type: EthAccountType.Eoa, + scopes: [EthScopes.Namespace], metadata: { name: 'Custom Name', keyring: { type: KeyringTypes.snap }, @@ -191,24 +197,32 @@ function createExpectedInternalAccount({ lastSelected?: number; nameLastUpdatedAt?: number; }): InternalAccount { - const accountTypeToMethods = { - [`${EthAccountType.Eoa}`]: [...Object.values(ETH_EOA_METHODS)], - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - [`${EthAccountType.Erc4337}`]: [...Object.values(ETH_ERC_4337_METHODS)], - // TODO: Either fix this lint violation or explain why it's necessary to ignore. - // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - [`${BtcAccountType.P2wpkh}`]: [...Object.values(BtcMethod)], + const accountTypeToInfo: Record< + string, + { methods: string[]; scopes: string[] } + > = { + [`${EthAccountType.Eoa}`]: { + methods: [...Object.values(ETH_EOA_METHODS)], + scopes: [EthScopes.Namespace], + }, + [`${EthAccountType.Erc4337}`]: { + methods: [...Object.values(ETH_ERC_4337_METHODS)], + scopes: [EthScopes.Mainnet], // Assuming we are using mainnet for those Smart Accounts + }, + [`${BtcAccountType.P2wpkh}`]: { + methods: [...Object.values(BtcMethod)], + scopes: [BtcScopes.Mainnet], + }, }; - const methods = - accountTypeToMethods[type as keyof typeof accountTypeToMethods]; + const { methods, scopes } = accountTypeToInfo[type]; - const account = { + const account: InternalAccount = { id, address, options: {}, methods, + scopes, type, metadata: { name, @@ -217,7 +231,7 @@ function createExpectedInternalAccount({ lastSelected: lastSelected || expect.any(Number), ...(nameLastUpdatedAt && { nameLastUpdatedAt }), }, - } as InternalAccount; + }; if (snapId) { account.metadata.snap = { diff --git a/packages/accounts-controller/src/AccountsController.ts b/packages/accounts-controller/src/AccountsController.ts index 234d454472d..f2feed0e074 100644 --- a/packages/accounts-controller/src/AccountsController.ts +++ b/packages/accounts-controller/src/AccountsController.ts @@ -8,6 +8,7 @@ import { SnapKeyring } from '@metamask/eth-snap-keyring'; import { EthAccountType, EthMethod, + EthScopes, isEvmAccountType, } from '@metamask/keyring-api'; import { KeyringTypes } from '@metamask/keyring-controller'; @@ -203,6 +204,7 @@ export const EMPTY_ACCOUNT = { options: {}, methods: [], type: EthAccountType.Eoa, + scopes: [EthScopes.Namespace], metadata: { name: '', keyring: { @@ -456,7 +458,7 @@ export class AccountsController extends BaseController< }; // Do not remove this comment - This error is flaky: Comment out or restore the `ts-expect-error` directive below as needed. // See: https://github.com/MetaMask/utils/issues/168 - // @ts-expect-error Known issue - `Json` causes recursive error in immer `Draft`/`WritableDraft` types + // // @ts-expect-error Known issue - `Json` causes recursive error in immer `Draft`/`WritableDraft` types currentState.internalAccounts.accounts[accountId] = internalAccount; if (metadata.name) { @@ -582,6 +584,7 @@ export class AccountsController extends BaseController< EthMethod.SignTypedDataV3, EthMethod.SignTypedDataV4, ], + scopes: [EthScopes.Namespace], type: EthAccountType.Eoa, metadata: { name: '', @@ -656,6 +659,7 @@ export class AccountsController extends BaseController< EthMethod.SignTypedDataV3, EthMethod.SignTypedDataV4, ], + scopes: [EthScopes.Namespace], type: EthAccountType.Eoa, metadata: { name: this.#populateExistingMetadata(id, 'name') ?? '', diff --git a/packages/assets-controllers/package.json b/packages/assets-controllers/package.json index 2b16bdafd38..68ff0ac490e 100644 --- a/packages/assets-controllers/package.json +++ b/packages/assets-controllers/package.json @@ -80,7 +80,7 @@ "@metamask/auto-changelog": "^3.4.4", "@metamask/ethjs-provider-http": "^0.3.0", "@metamask/keyring-controller": "^19.0.2", - "@metamask/keyring-internal-api": "^1.0.0", + "@metamask/keyring-internal-api": "^1.1.0", "@metamask/network-controller": "^22.1.1", "@metamask/preferences-controller": "^15.0.1", "@metamask/providers": "^18.1.1", diff --git a/packages/chain-controller/package.json b/packages/chain-controller/package.json index cae7e2c7c70..1224c7f6772 100644 --- a/packages/chain-controller/package.json +++ b/packages/chain-controller/package.json @@ -49,7 +49,7 @@ "dependencies": { "@metamask/base-controller": "^7.1.0", "@metamask/chain-api": "^0.1.0", - "@metamask/keyring-internal-api": "^1.0.0", + "@metamask/keyring-internal-api": "^1.1.0", "@metamask/keyring-utils": "^1.0.0", "@metamask/snaps-controllers": "^9.10.0", "@metamask/snaps-sdk": "^6.7.0", diff --git a/packages/keyring-controller/package.json b/packages/keyring-controller/package.json index 1826f067bcb..99b6e1d32b2 100644 --- a/packages/keyring-controller/package.json +++ b/packages/keyring-controller/package.json @@ -54,8 +54,8 @@ "@metamask/eth-hd-keyring": "^7.0.4", "@metamask/eth-sig-util": "^8.0.0", "@metamask/eth-simple-keyring": "^6.0.5", - "@metamask/keyring-api": "^12.0.0", - "@metamask/keyring-internal-api": "^1.0.0", + "@metamask/keyring-api": "^13.0.0", + "@metamask/keyring-internal-api": "^1.1.0", "@metamask/message-manager": "^11.0.3", "@metamask/utils": "^11.0.1", "async-mutex": "^0.5.0", diff --git a/packages/keyring-controller/src/KeyringController.ts b/packages/keyring-controller/src/KeyringController.ts index b55d5b98c62..d0a13a5d4f7 100644 --- a/packages/keyring-controller/src/KeyringController.ts +++ b/packages/keyring-controller/src/KeyringController.ts @@ -2238,7 +2238,13 @@ export class KeyringController extends BaseController< ); } - keyring.generateRandomMnemonic(); + // NOTE: Not all keyrings implement this method in a asynchronous-way. Using `await` for + // non-thenable will still be valid (despite not being really useful). It allows us to cover both + // cases and allow retro-compatibility too. + // FIXME: For some reason, it seems that eslint is complaining about this call being non-thenable + // even though it is... For now, we just disable it: + // eslint-disable-next-line @typescript-eslint/await-thenable + await keyring.generateRandomMnemonic(); await keyring.addAccounts(1); } diff --git a/packages/profile-sync-controller/package.json b/packages/profile-sync-controller/package.json index 232bc119a3d..b1ab48f856e 100644 --- a/packages/profile-sync-controller/package.json +++ b/packages/profile-sync-controller/package.json @@ -101,7 +101,7 @@ }, "dependencies": { "@metamask/base-controller": "^7.1.0", - "@metamask/keyring-api": "^12.0.0", + "@metamask/keyring-api": "^13.0.0", "@metamask/keyring-controller": "^19.0.2", "@metamask/network-controller": "^22.1.1", "@metamask/snaps-sdk": "^6.7.0", @@ -117,7 +117,7 @@ "@lavamoat/preinstall-always-fail": "^2.1.0", "@metamask/accounts-controller": "^20.0.2", "@metamask/auto-changelog": "^3.4.4", - "@metamask/keyring-internal-api": "^1.0.0", + "@metamask/keyring-internal-api": "^1.1.0", "@metamask/providers": "^18.1.1", "@metamask/snaps-controllers": "^9.10.0", "@types/jest": "^27.4.1", diff --git a/packages/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index 4f2a7f4495f..44434e31e5e 100644 --- a/packages/transaction-controller/src/TransactionController.test.ts +++ b/packages/transaction-controller/src/TransactionController.test.ts @@ -388,6 +388,7 @@ const INTERNAL_ACCOUNT_MOCK: InternalAccount = { id: '58def058-d35f-49a1-a7ab-e2580565f6f5', address: ACCOUNT_MOCK, type: 'eip155:eoa', + scopes: ['eip155'], options: {}, methods: [], metadata: { diff --git a/packages/transaction-controller/src/TransactionControllerIntegration.test.ts b/packages/transaction-controller/src/TransactionControllerIntegration.test.ts index 65c05f904d3..4bc2d89f4b7 100644 --- a/packages/transaction-controller/src/TransactionControllerIntegration.test.ts +++ b/packages/transaction-controller/src/TransactionControllerIntegration.test.ts @@ -95,6 +95,7 @@ const createMockInternalAccount = ({ options: {}, methods: [], type: 'eip155:eoa', + scopes: ['eip155'], metadata: { name, keyring: { type: 'HD Key Tree' }, diff --git a/packages/transaction-controller/src/helpers/IncomingTransactionHelper.test.ts b/packages/transaction-controller/src/helpers/IncomingTransactionHelper.test.ts index 36fee65661d..7edf55c4eae 100644 --- a/packages/transaction-controller/src/helpers/IncomingTransactionHelper.test.ts +++ b/packages/transaction-controller/src/helpers/IncomingTransactionHelper.test.ts @@ -28,6 +28,7 @@ const CONTROLLER_ARGS_MOCK: ConstructorParameters< type: 'eip155:eoa' as const, options: {}, methods: [], + scopes: ['eip155'], metadata: { name: 'Account 1', keyring: { type: 'HD Key Tree' }, diff --git a/yarn.lock b/yarn.lock index 34df0b3571f..67d4997da00 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2194,6 +2194,16 @@ __metadata: languageName: node linkType: hard +"@metamask/abi-utils@npm:^3.0.0": + version: 3.0.0 + resolution: "@metamask/abi-utils@npm:3.0.0" + dependencies: + "@metamask/superstruct": "npm:^3.1.0" + "@metamask/utils": "npm:^11.0.1" + checksum: 10/068b98185148b9e185b4af4392c6a6f82f1d4b1ff60013c57679c618f37afe9030e3ccc940e1a8b690be6f62ea91115ab18b73f3c3c09f4eff1794e31ababb9b + languageName: node + linkType: hard + "@metamask/accounts-controller@npm:^20.0.2, @metamask/accounts-controller@workspace:packages/accounts-controller": version: 0.0.0-use.local resolution: "@metamask/accounts-controller@workspace:packages/accounts-controller" @@ -2202,9 +2212,9 @@ __metadata: "@metamask/auto-changelog": "npm:^3.4.4" "@metamask/base-controller": "npm:^7.1.0" "@metamask/eth-snap-keyring": "npm:^7.0.0" - "@metamask/keyring-api": "npm:^12.0.0" + "@metamask/keyring-api": "npm:^13.0.0" "@metamask/keyring-controller": "npm:^19.0.2" - "@metamask/keyring-internal-api": "npm:^1.0.0" + "@metamask/keyring-internal-api": "npm:^1.1.0" "@metamask/providers": "npm:^18.1.1" "@metamask/snaps-controllers": "npm:^9.10.0" "@metamask/snaps-sdk": "npm:^6.7.0" @@ -2323,7 +2333,7 @@ __metadata: "@metamask/eth-query": "npm:^4.0.0" "@metamask/ethjs-provider-http": "npm:^0.3.0" "@metamask/keyring-controller": "npm:^19.0.2" - "@metamask/keyring-internal-api": "npm:^1.0.0" + "@metamask/keyring-internal-api": "npm:^1.1.0" "@metamask/metamask-eth-abis": "npm:^3.1.1" "@metamask/network-controller": "npm:^22.1.1" "@metamask/polling-controller": "npm:^12.0.2" @@ -2459,7 +2469,7 @@ __metadata: "@metamask/auto-changelog": "npm:^3.4.4" "@metamask/base-controller": "npm:^7.1.0" "@metamask/chain-api": "npm:^0.1.0" - "@metamask/keyring-internal-api": "npm:^1.0.0" + "@metamask/keyring-internal-api": "npm:^1.1.0" "@metamask/keyring-utils": "npm:^1.0.0" "@metamask/providers": "npm:^18.1.1" "@metamask/snaps-controllers": "npm:^9.10.0" @@ -2809,17 +2819,17 @@ __metadata: languageName: node linkType: hard -"@metamask/eth-sig-util@npm:^8.0.0": - version: 8.1.0 - resolution: "@metamask/eth-sig-util@npm:8.1.0" +"@metamask/eth-sig-util@npm:^8.0.0, @metamask/eth-sig-util@npm:^8.1.2": + version: 8.1.2 + resolution: "@metamask/eth-sig-util@npm:8.1.2" dependencies: "@ethereumjs/util": "npm:^8.1.0" - "@metamask/abi-utils": "npm:^2.0.4" - "@metamask/utils": "npm:^9.0.0" + "@metamask/abi-utils": "npm:^3.0.0" + "@metamask/utils": "npm:^11.0.1" "@scure/base": "npm:~1.1.3" ethereum-cryptography: "npm:^2.1.2" tweetnacl: "npm:^1.0.3" - checksum: 10/6e8abca5c0431ca8e0a3b6c3654cf864bf54a484c2888ebc639e6a44767564c45e25da77664e55ffc65b3abbec55902813d4a57d85ffc097706cffd1c9d37dde + checksum: 10/32b284fc8c3229e3741b1c21f44ca3f55c2215ef8ad700775cd9501bbaab56a4e861827bef24ed263734d28c899eb3b34a9646e9d21ec3fce12204b7eb58bfed languageName: node linkType: hard @@ -2837,26 +2847,27 @@ __metadata: linkType: hard "@metamask/eth-snap-keyring@npm:^7.0.0": - version: 7.0.0 - resolution: "@metamask/eth-snap-keyring@npm:7.0.0" + version: 7.1.0 + resolution: "@metamask/eth-snap-keyring@npm:7.1.0" dependencies: "@ethereumjs/tx": "npm:^4.2.0" - "@metamask/eth-sig-util": "npm:^8.0.0" - "@metamask/keyring-api": "npm:^12.0.0" - "@metamask/keyring-internal-api": "npm:^1.0.0" - "@metamask/keyring-internal-snap-client": "npm:^1.0.0" + "@metamask/eth-sig-util": "npm:^8.1.2" + "@metamask/keyring-api": "npm:^13.0.0" + "@metamask/keyring-internal-api": "npm:^1.1.0" + "@metamask/keyring-internal-snap-client": "npm:^1.1.0" + "@metamask/keyring-utils": "npm:^1.0.0" "@metamask/snaps-controllers": "npm:^9.10.0" "@metamask/snaps-sdk": "npm:^6.7.0" "@metamask/snaps-utils": "npm:^8.3.0" "@metamask/superstruct": "npm:^3.1.0" - "@metamask/utils": "npm:^9.3.0" + "@metamask/utils": "npm:^11.0.1" "@types/uuid": "npm:^9.0.8" uuid: "npm:^9.0.1" webextension-polyfill: "npm:^0.12.0" peerDependencies: - "@metamask/keyring-api": ^12.0.0 - "@metamask/providers": ^18.1.0 - checksum: 10/7a82cd2c19204776d31e29716844ac6f304ce4b136b36728be8e7b19ac2be6b46d0c72cc9707c48669a7a342994ce401aafbfe3f0b47769748ab86ae2169cbbd + "@metamask/keyring-api": ^13.0.0 + "@metamask/providers": ^18.3.1 + checksum: 10/0cfa24d5ad2f0ec83d096de906c48994994b2af999cdd7ab6a472aa9c96c1ceab1f800588f4cdc6f9a2c6821417772321c1a031fead53a5c61c792a6adea839f languageName: node linkType: hard @@ -3113,15 +3124,15 @@ __metadata: languageName: node linkType: hard -"@metamask/keyring-api@npm:^12.0.0": - version: 12.0.0 - resolution: "@metamask/keyring-api@npm:12.0.0" +"@metamask/keyring-api@npm:^13.0.0": + version: 13.0.0 + resolution: "@metamask/keyring-api@npm:13.0.0" dependencies: "@metamask/keyring-utils": "npm:^1.0.0" "@metamask/superstruct": "npm:^3.1.0" - "@metamask/utils": "npm:^9.3.0" + "@metamask/utils": "npm:^11.0.1" bech32: "npm:^2.0.0" - checksum: 10/ba8b75c55d3fcb9f8b52c58ff141cba81f7c416c3fa684e089965717ea129d50e8df7a73e7ab1c96eaf59d70b6e2dd8a618434939b75ef0d3402b547b5196877 + checksum: 10/f7e8982112a2813790354267af8f79cbf241d7ca9d733fe5e8de1a13993203b154ac6d358a92bd4340cbd4d25f4bac48681d17a25e3dc6f2336c95c00c371686 languageName: node linkType: hard @@ -3142,8 +3153,8 @@ __metadata: "@metamask/eth-hd-keyring": "npm:^7.0.4" "@metamask/eth-sig-util": "npm:^8.0.0" "@metamask/eth-simple-keyring": "npm:^6.0.5" - "@metamask/keyring-api": "npm:^12.0.0" - "@metamask/keyring-internal-api": "npm:^1.0.0" + "@metamask/keyring-api": "npm:^13.0.0" + "@metamask/keyring-internal-api": "npm:^1.1.0" "@metamask/message-manager": "npm:^11.0.3" "@metamask/scure-bip39": "npm:^2.1.1" "@metamask/utils": "npm:^11.0.1" @@ -3163,48 +3174,48 @@ __metadata: languageName: unknown linkType: soft -"@metamask/keyring-internal-api@npm:^1.0.0": - version: 1.0.0 - resolution: "@metamask/keyring-internal-api@npm:1.0.0" +"@metamask/keyring-internal-api@npm:^1.1.0": + version: 1.1.0 + resolution: "@metamask/keyring-internal-api@npm:1.1.0" dependencies: - "@metamask/keyring-api": "npm:^12.0.0" + "@metamask/keyring-api": "npm:^13.0.0" "@metamask/keyring-utils": "npm:^1.0.0" "@metamask/superstruct": "npm:^3.1.0" - "@metamask/utils": "npm:^9.3.0" - checksum: 10/dd0fff93ddfdce008f1db82d404bd040d09840413723c831819d3a7f4c2819a4303657e4acd7578cfd22bd05ad9c7aa563fc88f13f2f06999e2325ada71b824c + "@metamask/utils": "npm:^11.0.1" + checksum: 10/5db127cfe319c289b95d55d08b6737820f00761564e219d756a55e030b83043fb43d18bac3b63fcc69cd2e03129f831410ce960ba954d8183d976d87a6781b8c languageName: node linkType: hard -"@metamask/keyring-internal-snap-client@npm:^1.0.0": - version: 1.0.0 - resolution: "@metamask/keyring-internal-snap-client@npm:1.0.0" +"@metamask/keyring-internal-snap-client@npm:^1.1.0": + version: 1.1.0 + resolution: "@metamask/keyring-internal-snap-client@npm:1.1.0" dependencies: - "@metamask/keyring-api": "npm:^12.0.0" - "@metamask/keyring-snap-client": "npm:^1.0.0" + "@metamask/keyring-api": "npm:^13.0.0" + "@metamask/keyring-snap-client": "npm:^1.1.0" "@metamask/keyring-utils": "npm:^1.0.0" "@metamask/snaps-controllers": "npm:^9.10.0" "@metamask/snaps-sdk": "npm:^6.7.0" "@metamask/snaps-utils": "npm:^8.3.0" webextension-polyfill: "npm:^0.12.0" peerDependencies: - "@metamask/providers": ^18.1.0 - checksum: 10/4c02429235bf5b3609fe2d728f0f976fc87cc276483c092d155b181eeb1f167953a96226c4f6b64f6700084f8a66e5b02944ba0accf201e3514e83df205389e1 + "@metamask/providers": ^18.3.1 + checksum: 10/58e0f00cc3798b156b7e2b3766216a8b355970391a33c9fb4b31cffc7c06d77cf63be275e5e217e0e05c517ed01dd8745b202882d6b7dd14891115d1dd022b7a languageName: node linkType: hard -"@metamask/keyring-snap-client@npm:^1.0.0": - version: 1.0.0 - resolution: "@metamask/keyring-snap-client@npm:1.0.0" +"@metamask/keyring-snap-client@npm:^1.1.0": + version: 1.1.0 + resolution: "@metamask/keyring-snap-client@npm:1.1.0" dependencies: - "@metamask/keyring-api": "npm:^12.0.0" + "@metamask/keyring-api": "npm:^13.0.0" "@metamask/keyring-utils": "npm:^1.0.0" "@metamask/superstruct": "npm:^3.1.0" "@types/uuid": "npm:^9.0.8" uuid: "npm:^9.0.1" webextension-polyfill: "npm:^0.12.0" peerDependencies: - "@metamask/providers": ^18.1.0 - checksum: 10/7b3ee4ab6b39f8e06d55dee2c29f778eeb2eeb8bb311eccaab07d1f8a855fa920bf52e78bd2be0f3ddcb66dc475282d740de0cc7337ccd99e956302a706d76a0 + "@metamask/providers": ^18.3.1 + checksum: 10/f6e72d94d2fefd24619eca8c6fe838e448adbc42553656a4ffac44c32266836eb8223b30881c70434ce88e433c6fce12dbdaf9920dca7542b54334802cff72b7 languageName: node linkType: hard @@ -3563,9 +3574,9 @@ __metadata: "@metamask/accounts-controller": "npm:^20.0.2" "@metamask/auto-changelog": "npm:^3.4.4" "@metamask/base-controller": "npm:^7.1.0" - "@metamask/keyring-api": "npm:^12.0.0" + "@metamask/keyring-api": "npm:^13.0.0" "@metamask/keyring-controller": "npm:^19.0.2" - "@metamask/keyring-internal-api": "npm:^1.0.0" + "@metamask/keyring-internal-api": "npm:^1.1.0" "@metamask/network-controller": "npm:^22.1.1" "@metamask/providers": "npm:^18.1.1" "@metamask/snaps-controllers": "npm:^9.10.0"