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 @@ -156,6 +156,7 @@
/packages/wallet/src/initialization/instances/remote-feature-flag-controller/ @MetaMask/extension-platform @MetaMask/mobile-platform @MetaMask/core-platform
/packages/wallet/src/initialization/instances/seedless-onboarding-controller/ @MetaMask/web3auth
/packages/wallet/src/initialization/instances/storage-service/ @MetaMask/extension-platform @MetaMask/mobile-platform @MetaMask/core-platform
/packages/wallet/src/initialization/instances/subscription-controller/ @MetaMask/web3auth
/packages/wallet/src/initialization/instances/transaction-controller/ @MetaMask/confirmations

## Package Release related
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ linkStyle default opacity:0.5
wallet --> remote_feature_flag_controller;
wallet --> seedless_onboarding_controller;
wallet --> storage_service;
wallet --> subscription_controller;
wallet --> transaction_controller;
wallet_cli --> base_controller;
wallet_cli --> remote_feature_flag_controller;
Expand Down
1 change: 1 addition & 0 deletions codeowners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,7 @@ const PACKAGES: Record<string, PackageInfo> = {
},
'subscription-controller': {
teams: ['@MetaMask/web3auth'],
initializationPath: 'subscription-controller',
},
'transaction-controller': {
teams: ['@MetaMask/confirmations'],
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 `subscriptionController` slot in the daemon wallet's instance options (`SubscriptionEnv.PRD` and `globalThis.fetch`), so the daemon initializes `SubscriptionController` with the wallet's required configuration ([#9598](https://github.com/MetaMask/core/pull/9598))
- 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 @@ -3,6 +3,7 @@ import { InMemoryStorageAdapter } from '@metamask/storage-service';
import {
AlwaysOnlineAdapter,
importSecretRecoveryPhrase,
SubscriptionEnv,
Wallet,
} from '@metamask/wallet';
import { rmSync } from 'node:fs';
Expand Down Expand Up @@ -119,6 +120,10 @@ describe('createWallet', () => {
expect(instanceOptions.storageService.storage).toBeInstanceOf(
InMemoryStorageAdapter,
);
expect(instanceOptions.subscriptionController).toStrictEqual({
env: SubscriptionEnv.PRD,
fetchFunction: globalThis.fetch,
});
expect(instanceOptions.transactionController?.disableSwaps).toBe(true);
expect(instanceOptions.transactionController?.hooks).toStrictEqual({});
expect(ClientConfigApiService).toHaveBeenCalled();
Expand Down
8 changes: 8 additions & 0 deletions packages/wallet-cli/src/daemon/wallet-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type { Json } from '@metamask/utils';
import {
AlwaysOnlineAdapter,
importSecretRecoveryPhrase,
SubscriptionEnv,
Wallet,
} from '@metamask/wallet';
import type { WalletOptions } from '@metamask/wallet';
Expand Down Expand Up @@ -65,6 +66,9 @@ 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.
* - `subscriptionController` — production subscription API environment and
* platform `fetch`; authenticated calls require host `AuthenticationController`
* wiring on the wallet root messenger (not configured in the CLI).
*
* The optional `keyringController` slot is intentionally omitted so the
* controller's built-in defaults (e.g. the PBKDF2 encryptor) apply.
Expand Down Expand Up @@ -108,6 +112,10 @@ function buildInstanceOptions(
storageService: {
storage: new InMemoryStorageAdapter(),
},
subscriptionController: {
env: SubscriptionEnv.PRD,
fetchFunction: globalThis.fetch,
},
transactionController: {
// The CLI exposes no swaps surface, so skip the swaps-specific
// post-processing a full wallet client runs (mobile makes the same
Expand Down
7 changes: 7 additions & 0 deletions packages/wallet/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- **BREAKING** Wire `SubscriptionController` into the default wallet initialization ([#9598](https://github.com/MetaMask/core/pull/9598))
- Adds a required `subscriptionController` slot to `instanceOptions` (`env`, `fetchFunction`; optional `subscriptionService`, `getAccessToken`, `captureException`, `pollingInterval`).
- Hosts must register `AuthenticationController` on the wallet root messenger for authenticated subscription API calls.
- Re-exports `Env` from `@metamask/subscription-controller` as `SubscriptionEnv` for `instanceOptions.subscriptionController.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 @@ -71,6 +71,7 @@
"@metamask/scure-bip39": "^2.1.1",
"@metamask/seedless-onboarding-controller": "^10.1.0",
"@metamask/storage-service": "^1.0.2",
"@metamask/subscription-controller": "^6.2.1",
"@metamask/transaction-controller": "^69.2.1",
"@metamask/utils": "^11.11.0"
},
Expand Down
28 changes: 28 additions & 0 deletions packages/wallet/src/Wallet.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { getDefaultAddressBookControllerState } from '@metamask/address-book-con
import { CONNECTIVITY_STATUSES } from '@metamask/connectivity-controller';
import { Messenger } from '@metamask/messenger';
import { InMemoryStorageAdapter } from '@metamask/storage-service';
import {
Env,
getDefaultSubscriptionControllerState,
} from '@metamask/subscription-controller';
import { Json } from '@metamask/utils';
import { webcrypto } from 'crypto';

Expand All @@ -23,6 +27,11 @@ const REMOTE_FEATURE_FLAG_OPTIONS = {
},
};

const SUBSCRIPTION_CONTROLLER_OPTIONS = {
env: Env.DEV,
fetchFunction: globalThis.fetch,
};

async function setupWallet(): Promise<Wallet> {
const wallet = new Wallet({
instanceOptions: {
Expand All @@ -39,6 +48,7 @@ async function setupWallet(): Promise<Wallet> {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
subscriptionController: SUBSCRIPTION_CONTROLLER_OPTIONS,
},
});

Expand Down Expand Up @@ -105,6 +115,7 @@ describe('Wallet', () => {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
subscriptionController: SUBSCRIPTION_CONTROLLER_OPTIONS,
},
});

Expand Down Expand Up @@ -157,6 +168,7 @@ describe('Wallet', () => {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
subscriptionController: SUBSCRIPTION_CONTROLLER_OPTIONS,
},
});
const { state } = wallet;
Expand Down Expand Up @@ -203,6 +215,7 @@ describe('Wallet', () => {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
subscriptionController: SUBSCRIPTION_CONTROLLER_OPTIONS,
},
});

Expand Down Expand Up @@ -316,6 +329,7 @@ describe('Wallet', () => {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
subscriptionController: SUBSCRIPTION_CONTROLLER_OPTIONS,
},
});

Expand Down Expand Up @@ -351,6 +365,7 @@ describe('Wallet', () => {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
subscriptionController: SUBSCRIPTION_CONTROLLER_OPTIONS,
},
});

Expand Down Expand Up @@ -394,6 +409,7 @@ describe('Wallet', () => {
storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
subscriptionController: SUBSCRIPTION_CONTROLLER_OPTIONS,
},
});

Expand Down Expand Up @@ -454,6 +470,17 @@ describe('Wallet', () => {
});
});

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

expect(
wallet.messenger.call('SubscriptionController:getState'),
).toStrictEqual(getDefaultSubscriptionControllerState());
expect(wallet.getInstance('SubscriptionController')).toBeDefined();
});
});

describe('RemoteFeatureFlagController', () => {
it('is wired and exposes its state on the wallet messenger', async () => {
const wallet = await setupWallet();
Expand Down Expand Up @@ -494,6 +521,7 @@ describe('Wallet', () => {
}),
},
},
subscriptionController: SUBSCRIPTION_CONTROLLER_OPTIONS,
},
});
const { messenger } = wallet;
Expand Down
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 SubscriptionEnv } from '@metamask/subscription-controller';
export type { WalletOptions } from './types.js';
export type {
DefaultActions,
Expand Down
1 change: 1 addition & 0 deletions packages/wallet/src/initialization/instances/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ export { passkeyController } from './passkey-controller/passkey-controller.js';
export { remoteFeatureFlagController } from './remote-feature-flag-controller/remote-feature-flag-controller.js';
export { seedlessOnboardingController } from './seedless-onboarding-controller/seedless-onboarding-controller.js';
export { storageService } from './storage-service/storage-service.js';
export { subscriptionController } from './subscription-controller/subscription-controller.js';
export { transactionController } from './transaction-controller/transaction-controller.js';
Loading