Skip to content

Commit

Permalink
refactor: use new @metamask/keyring-api layout (split packages) (#4695
Browse files Browse the repository at this point in the history
)

## Explanation

The `keyring-api` has been split out into multiple smaller packages,
this introduce some breaking changes since some exports have been moved
elsewhere.

This was done to reduce the number of required dependencies for the
`keyring-api`. The `InternalAccount` type (widely used internally by
some controllers) has been moved to a new package:
`@metamask/keyring-internal-api`.

## References

Relates to:
- MetaMask/accounts#24

Basic testing done through the CI + preview builds:
- MetaMask/metamask-extension#28861

## Changelog

### `@metamask/keyring-controller`

- **CHANGED**: Remove use of peer dependency `@metamask/providers`
- **CHANGED**: Bump `@metamask/keyring-api` to `^12.0.0`
- **CHANGED**: Use `@metamask/keyring-internal-api@^1.0.0`

> Even if we are bumping the major of the `keyring-api`, this is not
breaking since all
> types from the split are compatible. The only difference now here is
the `Keyring`
> interface which has a new optional method `listAccountTransactions`,
optional, thus
> non-breaking (and this type is not used there anyway)

### `@metamask/accounts-controller`

- **CHANGED**: Bump `@metamask/keyring-api` to `^12.0.0`
- **CHANGED**: Bump `@metamask/eth-snap-keyring` to `^7.0.0`
- **CHANGED**: Use `@metamask/keyring-internal-api@^1.0.0`

> `eth-snap-keyring` has been bumped to `7.0.0` but this was a mistake
since no breaking changes has been introduced there either.
> The version `6.0.0` also introduces `ts-bridge` builds, but this is
already compatible with this repo, so not breaking here either.

### `@metamask/assets-controllers`

- **CHANGED**: Remove use of `@metamask/keyring-api`
- **CHANGED**: Use `@metamask/keyring-internal-api@^1.0.0`

### `@metamask/chain-controller`

- **CHANGED**: Remove use of `@metamask/keyring-api`
- **CHANGED**: Use `@metamask/keyring-internal-api@^1.0.0`
- **CHANGED**: Use `@metamask/keyring-utils@^1.0.0`

### `@metamask/profile-sync-controller`

- **CHANGED**: Remove use of `@metamask/keyring-api`
- **CHANGED**: Use `@metamask/keyring-internal-api@^1.0.0`

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've highlighted breaking changes using the "BREAKING" category
above as appropriate
  • Loading branch information
ccharly authored Dec 11, 2024
1 parent 22516ea commit 058534e
Show file tree
Hide file tree
Showing 28 changed files with 127 additions and 77 deletions.
5 changes: 3 additions & 2 deletions packages/accounts-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@
"dependencies": {
"@ethereumjs/util": "^8.1.0",
"@metamask/base-controller": "^7.0.2",
"@metamask/eth-snap-keyring": "^5.0.1",
"@metamask/keyring-api": "^10.1.0",
"@metamask/eth-snap-keyring": "^7.0.0",
"@metamask/keyring-api": "^12.0.0",
"@metamask/keyring-internal-api": "^1.0.0",
"@metamask/snaps-sdk": "^6.7.0",
"@metamask/snaps-utils": "^8.3.0",
"@metamask/utils": "^10.0.0",
Expand Down
10 changes: 5 additions & 5 deletions packages/accounts-controller/src/AccountsController.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { ControllerMessenger } from '@metamask/base-controller';
import type {
InternalAccount,
InternalAccountType,
} from '@metamask/keyring-api';
import {
BtcAccountType,
BtcMethod,
EthAccountType,
BtcMethod,
EthMethod,
} from '@metamask/keyring-api';
import { KeyringTypes } from '@metamask/keyring-controller';
import type {
InternalAccount,
InternalAccountType,
} from '@metamask/keyring-internal-api';
import type { SnapControllerState } from '@metamask/snaps-controllers';
import { SnapStatus } from '@metamask/snaps-utils';
import type { CaipChainId } from '@metamask/utils';
Expand Down
2 changes: 1 addition & 1 deletion packages/accounts-controller/src/AccountsController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import type {
} from '@metamask/base-controller';
import { BaseController } from '@metamask/base-controller';
import { SnapKeyring } from '@metamask/eth-snap-keyring';
import type { InternalAccount } from '@metamask/keyring-api';
import {
EthAccountType,
EthMethod,
Expand All @@ -19,6 +18,7 @@ import type {
KeyringControllerGetAccountsAction,
KeyringControllerStateChangeEvent,
} from '@metamask/keyring-controller';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type {
SnapControllerState,
SnapStateChange,
Expand Down
10 changes: 5 additions & 5 deletions packages/accounts-controller/src/tests/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type {
InternalAccount,
InternalAccountType,
} from '@metamask/keyring-api';
import {
BtcAccountType,
BtcMethod,
EthAccountType,
BtcMethod,
EthMethod,
} from '@metamask/keyring-api';
import { KeyringTypes } from '@metamask/keyring-controller';
import type {
InternalAccount,
InternalAccountType,
} from '@metamask/keyring-internal-api';
import { v4 } from 'uuid';

export const createMockInternalAccount = ({
Expand Down
4 changes: 1 addition & 3 deletions packages/assets-controllers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,10 @@
"@metamask/approval-controller": "^7.1.1",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/ethjs-provider-http": "^0.3.0",
"@metamask/keyring-api": "^10.1.0",
"@metamask/keyring-controller": "^19.0.1",
"@metamask/keyring-internal-api": "^1.0.0",
"@metamask/network-controller": "^22.1.1",
"@metamask/preferences-controller": "^15.0.1",
"@metamask/providers": "^18.1.1",
"@types/jest": "^27.4.1",
"@types/lodash": "^4.14.191",
"@types/node": "^16.18.54",
Expand All @@ -104,7 +103,6 @@
"@metamask/keyring-controller": "^19.0.0",
"@metamask/network-controller": "^22.0.0",
"@metamask/preferences-controller": "^15.0.0",
"@metamask/providers": "^18.1.0",
"webextension-polyfill": "^0.10.0 || ^0.11.0 || ^0.12.0"
},
"engines": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ControllerMessenger } from '@metamask/base-controller';
import { query, toChecksumHexAddress } from '@metamask/controller-utils';
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import {
type NetworkClientId,
type NetworkClientConfiguration,
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/NftController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
NFT_API_BASE_URL,
InfuraNetworkType,
} from '@metamask/controller-utils';
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type {
NetworkClientConfiguration,
NetworkClientId,
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/NftController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
NFT_API_BASE_URL,
NFT_API_VERSION,
} from '@metamask/controller-utils';
import { type InternalAccount } from '@metamask/keyring-api';
import { type InternalAccount } from '@metamask/keyring-internal-api';
import type {
NetworkClientId,
NetworkControllerGetNetworkClientByIdAction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import {
convertHexToDecimal,
InfuraNetworkType,
} from '@metamask/controller-utils';
import type { InternalAccount } from '@metamask/keyring-api';
import type { KeyringControllerState } from '@metamask/keyring-controller';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import {
getDefaultNetworkControllerState,
RpcEndpointType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
toChecksumHexAddress,
toHex,
} from '@metamask/controller-utils';
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type {
NetworkClientConfiguration,
NetworkClientId,
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/TokenRatesController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
FALL_BACK_VS_CURRENCY,
toHex,
} from '@metamask/controller-utils';
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type {
NetworkControllerGetNetworkClientByIdAction,
NetworkControllerGetStateAction,
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/TokensController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
convertHexToDecimal,
InfuraNetworkType,
} from '@metamask/controller-utils';
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type {
NetworkClientConfiguration,
NetworkClientId,
Expand Down
2 changes: 1 addition & 1 deletion packages/assets-controllers/src/TokensController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
isValidHexAddress,
safelyExecute,
} from '@metamask/controller-utils';
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import { abiERC721 } from '@metamask/metamask-eth-abis';
import type {
NetworkClientId,
Expand Down
3 changes: 2 additions & 1 deletion packages/chain-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
"dependencies": {
"@metamask/base-controller": "^7.0.2",
"@metamask/chain-api": "^0.1.0",
"@metamask/keyring-api": "^10.1.0",
"@metamask/keyring-internal-api": "^1.0.0",
"@metamask/keyring-utils": "^1.0.0",
"@metamask/snaps-controllers": "^9.10.0",
"@metamask/snaps-sdk": "^6.7.0",
"@metamask/snaps-utils": "^8.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/chain-controller/src/ChainController.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ControllerMessenger } from '@metamask/base-controller';
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type { SnapId } from '@metamask/snaps-sdk';

import type { AllowedActions, ChainControllerActions } from './ChainController';
Expand Down
2 changes: 1 addition & 1 deletion packages/chain-controller/src/ChainController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
} from '@metamask/base-controller';
import { BaseController } from '@metamask/base-controller';
import type { CaipAssetType, BalancesResult, Chain } from '@metamask/chain-api';
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type { HandleSnapRequest as SnapControllerHandleSnapRequestAction } from '@metamask/snaps-controllers';
import type { SnapId } from '@metamask/snaps-sdk';
import type { CaipChainId } from '@metamask/utils';
Expand Down
4 changes: 2 additions & 2 deletions packages/chain-controller/src/SnapHandlerClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { JsonRpcRequest } from '@metamask/keyring-api/dist/JsonRpcRequest';
import type { JsonRpcRequest } from '@metamask/keyring-utils';
import type { SnapController } from '@metamask/snaps-controllers';
import type { SnapId } from '@metamask/snaps-sdk';
import { HandlerType } from '@metamask/snaps-utils';
Expand Down Expand Up @@ -78,7 +78,7 @@ export class SnapHandlerClient {
*/
constructor({
handler,
// Follow same pattern than for @metamask/keyring-api
// Follow same pattern than for @metamask/keyring-snap-client
snapId,
origin = 'metamask',
}: {
Expand Down
11 changes: 3 additions & 8 deletions packages/keyring-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +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": "^10.1.0",
"@metamask/keyring-api": "^12.0.0",
"@metamask/keyring-internal-api": "^1.0.0",
"@metamask/message-manager": "^11.0.3",
"@metamask/utils": "^10.0.0",
"async-mutex": "^0.5.0",
Expand All @@ -68,7 +69,6 @@
"@lavamoat/allow-scripts": "^3.0.4",
"@lavamoat/preinstall-always-fail": "^2.1.0",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/providers": "^18.1.1",
"@metamask/scure-bip39": "^2.1.1",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
Expand All @@ -79,12 +79,7 @@
"typedoc": "^0.24.8",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.2.2",
"uuid": "^8.3.2",
"webextension-polyfill": "^0.12.0"
},
"peerDependencies": {
"@metamask/providers": "^18.1.0",
"webextension-polyfill": "^0.10.0 || ^0.11.0 || ^0.12.0"
"uuid": "^8.3.2"
},
"engines": {
"node": "^18.18 || >=20"
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-controller/src/KeyringController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
encrypt,
} from '@metamask/eth-sig-util';
import SimpleKeyring from '@metamask/eth-simple-keyring/dist/simple-keyring';
import type { EthKeyring } from '@metamask/keyring-api';
import type { EthKeyring } from '@metamask/keyring-internal-api';
import { wordlist } from '@metamask/scure-bip39/dist/wordlists/english';
import type { KeyringClass } from '@metamask/utils';
import {
Expand Down
4 changes: 2 additions & 2 deletions packages/keyring-controller/src/KeyringController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import HDKeyring from '@metamask/eth-hd-keyring';
import { normalize as ethNormalize } from '@metamask/eth-sig-util';
import SimpleKeyring from '@metamask/eth-simple-keyring';
import type {
KeyringExecutionContext,
EthBaseTransaction,
EthBaseUserOperation,
EthKeyring,
EthUserOperation,
EthUserOperationPatch,
KeyringExecutionContext,
} from '@metamask/keyring-api';
import type { EthKeyring } from '@metamask/keyring-internal-api';
import type {
PersonalMessageParams,
TypedMessageParams,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EthKeyring } from '@metamask/keyring-api';
import type { EthKeyring } from '@metamask/keyring-internal-api';
import type { Hex, Json } from '@metamask/utils';

export class MockErc4337Keyring implements EthKeyring<Json> {
Expand Down
2 changes: 1 addition & 1 deletion packages/keyring-controller/tests/mocks/mockKeyring.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { EthKeyring } from '@metamask/keyring-api';
import type { EthKeyring } from '@metamask/keyring-internal-api';
import type { Json, Hex } from '@metamask/utils';

export class MockKeyring implements EthKeyring<Json> {
Expand Down
3 changes: 2 additions & 1 deletion packages/profile-sync-controller/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
},
"dependencies": {
"@metamask/base-controller": "^7.0.2",
"@metamask/keyring-api": "^10.1.0",
"@metamask/keyring-api": "^12.0.0",
"@metamask/keyring-controller": "^19.0.1",
"@metamask/network-controller": "^22.1.1",
"@metamask/snaps-sdk": "^6.7.0",
Expand All @@ -117,6 +117,7 @@
"@lavamoat/preinstall-always-fail": "^2.1.0",
"@metamask/accounts-controller": "^20.0.1",
"@metamask/auto-changelog": "^3.4.4",
"@metamask/keyring-internal-api": "^1.0.0",
"@metamask/providers": "^18.1.1",
"@metamask/snaps-controllers": "^9.10.0",
"@types/jest": "^27.4.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type nock from 'nock';

import encryption, { createSHA256Hash } from '../../shared/encryption';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import type {
StateMetadata,
} from '@metamask/base-controller';
import { BaseController } from '@metamask/base-controller';
import { type InternalAccount, isEvmAccountType } from '@metamask/keyring-api';
import { isEvmAccountType } from '@metamask/keyring-api';
import {
type KeyringControllerGetStateAction,
type KeyringControllerLockEvent,
type KeyringControllerUnlockEvent,
type KeyringControllerAddNewAccountAction,
KeyringTypes,
} from '@metamask/keyring-controller';
import type { InternalAccount } from '@metamask/keyring-internal-api';
import type {
NetworkControllerAddNetworkAction,
NetworkControllerGetStateAction,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { EthAccountType, type InternalAccount } from '@metamask/keyring-api';
import { EthAccountType } from '@metamask/keyring-api';
import { KeyringTypes } from '@metamask/keyring-controller';
import type { InternalAccount } from '@metamask/keyring-internal-api';

import { LOCALIZED_DEFAULT_ACCOUNT_NAMES } from '../accounts/constants';
import { mapInternalAccountToUserStorageAccount } from '../accounts/user-storage';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { InternalAccount } from '@metamask/keyring-api';
import type { InternalAccount } from '@metamask/keyring-internal-api';

import {
USER_STORAGE_VERSION_KEY,
Expand Down
Loading

0 comments on commit 058534e

Please sign in to comment.