diff --git a/package.json b/package.json index e1b7daf616..7a8293cd29 100644 --- a/package.json +++ b/package.json @@ -42,6 +42,12 @@ "pre-push": "yarn lint" }, "resolutions": { + "@metamask/eth-snap-keyring@7.0.0": "npm:@metamask-previews/eth-snap-keyring@7.0.0-ac29af4", + "@metamask/eth-snap-keyring@^7.0.0": "npm:@metamask-previews/eth-snap-keyring@7.0.0-ac29af4", + "@metamask/keyring-api@12.0.0": "npm:@metamask-previews/keyring-api@12.0.0-ac29af4", + "@metamask/keyring-api@^12.0.0": "npm:@metamask-previews/keyring-api@12.0.0-ac29af4", + "@metamask/keyring-internal-api@1.0.0": "npm:@metamask-previews/keyring-internal-api@1.0.0-ac29af4", + "@metamask/keyring-internal-api@^1.0.0": "npm:@metamask-previews/keyring-internal-api@1.0.0-ac29af4", "elliptic@6.5.4": "^6.5.7", "fast-xml-parser@^4.3.4": "^4.4.1", "ws@7.4.6": "^7.5.10" diff --git a/packages/accounts-controller/src/AccountsController.test.ts b/packages/accounts-controller/src/AccountsController.test.ts index e082ea1c38..c1c94ca83d 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,36 @@ function createExpectedInternalAccount({ lastSelected?: number; nameLastUpdatedAt?: number; }): InternalAccount { - const accountTypeToMethods = { - [`${EthAccountType.Eoa}`]: [...Object.values(ETH_EOA_METHODS)], + const accountTypeToInfo: Record< + string, + { methods: string[]; scopes: string[] } + > = { + [`${EthAccountType.Eoa}`]: { + methods: [...Object.values(ETH_EOA_METHODS)], + scopes: [EthScopes.Namespace], + }, // 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)], + [`${EthAccountType.Erc4337}`]: { + methods: [...Object.values(ETH_ERC_4337_METHODS)], + scopes: [EthScopes.Mainnet], // Assuming we are using mainnet for those Smart Accounts + }, // 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)], + [`${BtcAccountType.P2wpkh}`]: { + methods: [...Object.values(BtcMethod)], + scopes: [BtcScopes.Mainnet], // Assuming we are using mainnet for those Smart Accounts + }, }; - 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 +235,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 234d454472..4280a09eb5 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: { @@ -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/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index 4f2a7f4495..44434e31e5 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 65c05f904d..4bc2d89f4b 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 36fee65661..7edf55c4ea 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 60e7d188b7..91b7f6810b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2673,15 +2673,16 @@ __metadata: languageName: node linkType: hard -"@metamask/eth-snap-keyring@npm:^7.0.0": - version: 7.0.0 - resolution: "@metamask/eth-snap-keyring@npm:7.0.0" +"@metamask/eth-snap-keyring@npm:@metamask-previews/eth-snap-keyring@7.0.0-ac29af4": + version: 7.0.0-ac29af4 + resolution: "@metamask-previews/eth-snap-keyring@npm:7.0.0-ac29af4" 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/keyring-api": "npm:12.0.0" + "@metamask/keyring-internal-api": "npm:1.0.0" + "@metamask/keyring-internal-snap-client": "npm:1.0.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" @@ -2691,9 +2692,8 @@ __metadata: 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 + checksum: 10/4c565f9a7d4ab5dc0771c3f8c1167360056dffc21c03c5c8ecdbc42de727c377a36d8f9544eded9addc8b01c855bda6634085a74c20511cbb4561bd8d9962d2b languageName: node linkType: hard @@ -2950,15 +2950,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:@metamask-previews/keyring-api@12.0.0-ac29af4": + version: 12.0.0-ac29af4 + resolution: "@metamask-previews/keyring-api@npm:12.0.0-ac29af4" dependencies: - "@metamask/keyring-utils": "npm:^1.0.0" + "@metamask/keyring-utils": "npm:1.0.0" "@metamask/superstruct": "npm:^3.1.0" "@metamask/utils": "npm:^9.3.0" bech32: "npm:^2.0.0" - checksum: 10/ba8b75c55d3fcb9f8b52c58ff141cba81f7c416c3fa684e089965717ea129d50e8df7a73e7ab1c96eaf59d70b6e2dd8a618434939b75ef0d3402b547b5196877 + checksum: 10/770d556ef2832dc32a73fa1c349b6c5ab112e3d26c928fa7a24058655307a360bcc5c94f475a010a83ba5903642f8a366c65015726ceb9de209eb657f0617776 languageName: node linkType: hard @@ -3000,19 +3000,19 @@ __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:@metamask-previews/keyring-internal-api@1.0.0-ac29af4": + version: 1.0.0-ac29af4 + resolution: "@metamask-previews/keyring-internal-api@npm:1.0.0-ac29af4" dependencies: - "@metamask/keyring-api": "npm:^12.0.0" - "@metamask/keyring-utils": "npm:^1.0.0" + "@metamask/keyring-api": "npm:12.0.0" + "@metamask/keyring-utils": "npm:1.0.0" "@metamask/superstruct": "npm:^3.1.0" "@metamask/utils": "npm:^9.3.0" - checksum: 10/dd0fff93ddfdce008f1db82d404bd040d09840413723c831819d3a7f4c2819a4303657e4acd7578cfd22bd05ad9c7aa563fc88f13f2f06999e2325ada71b824c + checksum: 10/87c19bcc147488b40bb6c063e465bc262bb439edf499466c22a5939a1a3248d615852a3358e8345a4885c977f933e8cebd276bed3abfedee31f0d9dfbaeeda8e languageName: node linkType: hard -"@metamask/keyring-internal-snap-client@npm:^1.0.0": +"@metamask/keyring-internal-snap-client@npm:1.0.0": version: 1.0.0 resolution: "@metamask/keyring-internal-snap-client@npm:1.0.0" dependencies: @@ -3045,7 +3045,7 @@ __metadata: languageName: node linkType: hard -"@metamask/keyring-utils@npm:^1.0.0": +"@metamask/keyring-utils@npm:1.0.0, @metamask/keyring-utils@npm:^1.0.0": version: 1.0.0 resolution: "@metamask/keyring-utils@npm:1.0.0" dependencies: