Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@
/packages/wallet/src/initialization/instances/accounts-controller/ @MetaMask/accounts-engineers
/packages/wallet/src/initialization/instances/address-book-controller/ @MetaMask/confirmations
/packages/wallet/src/initialization/instances/approval-controller/ @MetaMask/confirmations
/packages/wallet/src/initialization/instances/claims-controller/ @MetaMask/web3auth
/packages/wallet/src/initialization/instances/connectivity-controller/ @MetaMask/core-platform
/packages/wallet/src/initialization/instances/gas-fee-controller/ @MetaMask/confirmations
/packages/wallet/src/initialization/instances/keyring-controller/ @MetaMask/accounts-engineers @MetaMask/core-platform
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ linkStyle default opacity:0.5
wallet --> address_book_controller;
wallet --> approval_controller;
wallet --> base_controller;
wallet --> claims_controller;
wallet --> connectivity_controller;
wallet --> controller_utils;
wallet --> gas_fee_controller;
Expand Down
1 change: 1 addition & 0 deletions codeowners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ const PACKAGES: Record<string, PackageInfo> = {
},
'claims-controller': {
teams: ['@MetaMask/web3auth'],
initializationPath: 'claims-controller',
},
'client-controller': {
teams: [
Expand Down
1 change: 1 addition & 0 deletions packages/wallet-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Wire the `claimsService` slot in the daemon wallet's instance options (`ClaimsEnv.PRD` and `globalThis.fetch`), so the daemon initializes `ClaimsService` with the wallet's required configuration ([#9588](https://github.com/MetaMask/core/pull/9588))
- Wire the `transactionController` slot in the daemon wallet's instance options, so the daemon runs the `TransactionController` with an explicit CLI-appropriate configuration (swaps processing disabled, no client hooks) rather than relying on the controller's implicit defaults ([#9509](https://github.com/MetaMask/core/pull/9509))
- Wire the `gasFeeController` slot in the daemon wallet's instance options, passing `clientId: 'cli'` so the CLI identifies itself to the gas estimation API, now that `@metamask/wallet` requires this option ([#9527](https://github.com/MetaMask/core/pull/9527))
- Add the `mm wallet unlock` command, which dispatches `KeyringController:submitPassword` over the daemon socket, allowing the keyring to be unlocked after a daemon start with no password or after a `mm daemon call KeyringController:setLocked` ([#8821](https://github.com/MetaMask/core/pull/8821))
Expand Down
5 changes: 5 additions & 0 deletions packages/wallet-cli/src/daemon/wallet-factory.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { ClientConfigApiService } from '@metamask/remote-feature-flag-controller
import { InMemoryStorageAdapter } from '@metamask/storage-service';
import {
AlwaysOnlineAdapter,
ClaimsEnv,
importSecretRecoveryPhrase,
Wallet,
} from '@metamask/wallet';
Expand Down Expand Up @@ -121,6 +122,10 @@ describe('createWallet', () => {
);
expect(instanceOptions.transactionController?.disableSwaps).toBe(true);
expect(instanceOptions.transactionController?.hooks).toStrictEqual({});
expect(instanceOptions.claimsService).toStrictEqual({
env: ClaimsEnv.PRD,
fetchFunction: globalThis.fetch,
});
expect(ClientConfigApiService).toHaveBeenCalled();

await dispose();
Expand Down
7 changes: 7 additions & 0 deletions packages/wallet-cli/src/daemon/wallet-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { InMemoryStorageAdapter } from '@metamask/storage-service';
import type { Json } from '@metamask/utils';
import {
AlwaysOnlineAdapter,
ClaimsEnv,
importSecretRecoveryPhrase,
Wallet,
} from '@metamask/wallet';
Expand Down Expand Up @@ -65,6 +66,8 @@ export type CreateWalletResult = {
* - `transactionController` — swaps processing disabled and no client hooks;
* see the slot's inline comment for why the daemon relies on the
* controller's defaults for everything else.
* - `claimsService` — production Claims API environment and the platform
* `fetch` implementation.
*
* The optional `keyringController` slot is intentionally omitted so the
* controller's built-in defaults (e.g. the PBKDF2 encryptor) apply.
Expand Down Expand Up @@ -121,6 +124,10 @@ function buildInstanceOptions(
// the controller's default.
hooks: {},
},
claimsService: {
env: ClaimsEnv.PRD,
fetchFunction: globalThis.fetch,
},
};
}

Expand Down
8 changes: 8 additions & 0 deletions packages/wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **BREAKING:** Wire `ClaimsService` and `ClaimsController` into the default wallet initialization ([#9588](https://github.com/MetaMask/core/pull/9588))
- Passing `instanceOptions.claimsService.env` is now required.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just one entry (above BREAKING) is sufficient enough, to keep the CHANGELOG clean. These are not really necessary.

- Passing `instanceOptions.claimsService.fetchFunction` is now required.
- `ClaimsService` delegates `AuthenticationController:getBearerToken`; hosts must register `AuthenticationController` on the supplied root messenger before authenticated Claims API calls succeed.
- Re-exports `Env` from `@metamask/claims-controller` as `ClaimsEnv` for `instanceOptions.claimsService.env`.

## [8.0.0]

### Added
Expand Down
1 change: 1 addition & 0 deletions packages/wallet/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"@metamask/approval-controller": "^9.0.2",
"@metamask/base-controller": "^9.1.0",
"@metamask/browser-passworder": "^6.0.0",
"@metamask/claims-controller": "^0.5.3",
"@metamask/connectivity-controller": "^0.3.0",
"@metamask/controller-utils": "^12.3.0",
"@metamask/gas-fee-controller": "^26.2.4",
Expand Down
157 changes: 44 additions & 113 deletions packages/wallet/src/Wallet.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { getDefaultAddressBookControllerState } from '@metamask/address-book-controller';
import { Env } from '@metamask/claims-controller';
import { getDefaultClaimsControllerState } from '@metamask/claims-controller';
import { CONNECTIVITY_STATUSES } from '@metamask/connectivity-controller';
import { Messenger } from '@metamask/messenger';
import { InMemoryStorageAdapter } from '@metamask/storage-service';
Expand All @@ -8,6 +10,7 @@ import { webcrypto } from 'crypto';
import MockEncryptor from '../../keyring-controller/tests/mocks/mockEncryptor.js';
import * as initializationModule from './initialization/initialization.js';
import { AlwaysOnlineAdapter } from './initialization/instances/connectivity-controller/always-online-adapter.js';
import type { WalletOptions } from './types.js';
import { importSecretRecoveryPhrase } from './utilities.js';
import { Wallet } from './Wallet.js';

Expand All @@ -23,23 +26,31 @@ const REMOTE_FEATURE_FLAG_OPTIONS = {
},
};

function getInstanceOptions(): WalletOptions['instanceOptions'] {
return {
connectivityController: {
connectivityAdapter: new AlwaysOnlineAdapter(),
},
gasFeeController: {
clientId: 'test',
},
networkController: {
infuraProjectId: 'fake-infura-project-id',
},
storageService: {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
claimsService: {
env: Env.DEV,
fetchFunction: globalThis.fetch,
},
};
}

async function setupWallet(): Promise<Wallet> {
const wallet = new Wallet({
instanceOptions: {
connectivityController: {
connectivityAdapter: new AlwaysOnlineAdapter(),
},
gasFeeController: {
clientId: 'test',
},
networkController: {
infuraProjectId: 'fake-infura-project-id',
},
storageService: {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
},
instanceOptions: getInstanceOptions(),
});

await importSecretRecoveryPhrase(wallet, TEST_PASSWORD, TEST_SRP);
Expand Down Expand Up @@ -89,22 +100,10 @@ describe('Wallet', () => {
it('supports passing instance options', async () => {
const wallet = new Wallet({
instanceOptions: {
connectivityController: {
connectivityAdapter: new AlwaysOnlineAdapter(),
},
gasFeeController: {
clientId: 'test',
},
...getInstanceOptions(),
keyringController: {
encryptor: new MockEncryptor(),
},
networkController: {
infuraProjectId: 'fake-infura-project-id',
},
storageService: {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
},
});

Expand Down Expand Up @@ -143,21 +142,7 @@ describe('Wallet', () => {
init: (): DummyService => new DummyService(),
},
],
instanceOptions: {
connectivityController: {
connectivityAdapter: new AlwaysOnlineAdapter(),
},
gasFeeController: {
clientId: 'test',
},
networkController: {
infuraProjectId: 'fake-infura-project-id',
},
storageService: {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
},
instanceOptions: getInstanceOptions(),
});
const { state } = wallet;

Expand Down Expand Up @@ -189,21 +174,7 @@ describe('Wallet', () => {
});

const wallet = new Wallet({
instanceOptions: {
connectivityController: {
connectivityAdapter: new AlwaysOnlineAdapter(),
},
gasFeeController: {
clientId: 'test',
},
networkController: {
infuraProjectId: 'fake-infura-project-id',
},
storageService: {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
},
instanceOptions: getInstanceOptions(),
});

expect(wallet.controllerMetadata).toStrictEqual({
Expand Down Expand Up @@ -302,21 +273,7 @@ describe('Wallet', () => {
addressBook: { '0x1': { [ADDRESS]: entry } },
},
},
instanceOptions: {
connectivityController: {
connectivityAdapter: new AlwaysOnlineAdapter(),
},
gasFeeController: {
clientId: 'test',
},
networkController: {
infuraProjectId: 'fake-infura-project-id',
},
storageService: {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
},
instanceOptions: getInstanceOptions(),
});

expect(
Expand All @@ -337,21 +294,7 @@ describe('Wallet', () => {
describe('ConnectivityController', () => {
it('reports online connectivity status', () => {
const wallet = new Wallet({
instanceOptions: {
connectivityController: {
connectivityAdapter: new AlwaysOnlineAdapter(),
},
gasFeeController: {
clientId: 'test',
},
networkController: {
infuraProjectId: 'fake-infura-project-id',
},
storageService: {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
},
instanceOptions: getInstanceOptions(),
});

expect(wallet.state.ConnectivityController.connectivityStatus).toBe(
Expand Down Expand Up @@ -380,21 +323,7 @@ describe('Wallet', () => {
vault,
},
},
instanceOptions: {
connectivityController: {
connectivityAdapter: new AlwaysOnlineAdapter(),
},
gasFeeController: {
clientId: 'test',
},
networkController: {
infuraProjectId: 'fake-infura-project-id',
},
storageService: {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
},
instanceOptions: getInstanceOptions(),
});

await wallet.messenger.call(
Expand Down Expand Up @@ -472,17 +401,8 @@ describe('Wallet', () => {
it('routes injected instanceOptions through to the controller', async () => {
const wallet = new Wallet({
instanceOptions: {
connectivityController: {
connectivityAdapter: new AlwaysOnlineAdapter(),
},
gasFeeController: {
clientId: 'test',
},
networkController: {
infuraProjectId: 'fake-infura-project-id',
},
...getInstanceOptions(),
keyringController: { encryptor: new MockEncryptor() },
storageService: { storage: new InMemoryStorageAdapter() },
remoteFeatureFlagController: {
clientConfigApiService: {
fetchRemoteFeatureFlags: async (): Promise<{
Expand All @@ -508,4 +428,15 @@ describe('Wallet', () => {
).toStrictEqual({ testFlag: true });
});
});

describe('ClaimsController', () => {
it('is wired and exposes its state on the wallet messenger', async () => {
const wallet = await setupWallet();
const { messenger } = wallet;

expect(messenger.call('ClaimsController:getState')).toStrictEqual(
getDefaultClaimsControllerState(),
);
});
});
});
1 change: 1 addition & 0 deletions packages/wallet/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export { Wallet } from './Wallet.js';
export { AlwaysOnlineAdapter } from './initialization/instances/connectivity-controller/always-online-adapter.js';
export { importSecretRecoveryPhrase } from './utilities.js';
export { Env as ClaimsEnv } from '@metamask/claims-controller';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to export this.
Clients can just import from @metamask/claims-controller.

export type { WalletOptions } from './types.js';
export type {
DefaultActions,
Expand Down
Loading