Skip to content

feat: wire ClaimsService and ClaimsController initialization#9588

Open
tuna1207 wants to merge 11 commits into
mainfrom
feat/claim-controller-mm-wallet
Open

feat: wire ClaimsService and ClaimsController initialization#9588
tuna1207 wants to merge 11 commits into
mainfrom
feat/claim-controller-mm-wallet

Conversation

@tuna1207

Copy link
Copy Markdown
Member

Explanation

Adds ClaimsService and ClaimsController as default initialized units in the @metamask/wallet package, following the existing InitializationConfiguration pattern used by TransactionController, StorageService, and other wallet instances.

@metamask/wallet is the shared controller-integration layer for extension, mobile, and other clients, so build-specific and runtime values are injected via instanceOptions rather than hardcoded.

ClaimsService — selects the Claims API environment and platform fetch implementation. instanceOptions.claimsService.env and instanceOptions.claimsService.fetchFunction are required. The wallet init delegates AuthenticationController:getBearerToken to the service messenger; hosts must register AuthenticationController on the supplied root messenger before authenticated Claims API calls succeed.

ClaimsController — stateful controller with no additional constructor options beyond optional persisted state. The wallet init delegates only the ClaimsService actions the controller calls (fetchClaimsConfigurations, getRequestHeaders, getClaimsApiUrl, generateMessageForClaimSignature, getClaims) plus KeyringController:signPersonalMessage.

Wallet release work is intentionally deferred; this PR lands the integration and documents consumer options only.

References

Per-environment options

Option Extension Mobile Default (Node / tests / wallet-cli)
claimsService.env Build flavor (Env.DEV / Env.UAT / Env.PRD) Build flavor (Env.DEV / Env.UAT / Env.PRD) Env.PRD in wallet-cli; Env.DEV in wallet unit tests
claimsService.fetchFunction Platform fetch Platform fetch globalThis.fetch
claimsController state Persisted via wallet state blob when supplied Persisted via wallet state blob when supplied Optional; defaults apply when omitted
AuthenticationController:getBearerToken Host must register AuthenticationController on the wallet root messenger (not an instanceOptions slot) Host must register AuthenticationController on the wallet root messenger (not an instanceOptions slot) Not wired in wallet-cli; authenticated Claims calls require host auth wiring

Verification

  • yarn workspace @metamask/wallet run test
  • yarn workspace @metamask/wallet run jest --no-coverage src/initialization/instances/claims-service/claims-service.test.ts src/initialization/instances/claims-controller/claims-controller.test.ts
  • yarn workspace @metamask/wallet run messenger-action-types:check
  • yarn workspace @metamask/wallet run lint:tsconfigs
  • yarn workspace @metamask/wallet-cli run lint:tsconfigs
  • yarn readme-content:check
  • yarn codeowners:check
  • yarn lint:teams

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed
  • I've introduced breaking changes in this PR and documented required consumer options in the table above
  • Wallet release deferred to a follow-up request

Made with Cursor

tuna1207 and others added 10 commits July 22, 2026 15:09
Add default wallet initialization units for ClaimsService and
ClaimsController with tight messenger delegation, required
claimsService instance options, wallet-cli defaults, ownership, and
dependency graph updates.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Colocate ClaimsService with ClaimsController so a single CODEOWNERS
initializationPath covers both units, and revert multi-path ownership.

Co-authored-by: Cursor <cursoragent@cursor.com>
Match the SubscriptionEnv naming pattern so wallet consumers can set
claimsService.env without colliding with other Env enums.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@tuna1207
tuna1207 marked this pull request as ready for review July 23, 2026 00:58
@tuna1207
tuna1207 requested review from a team as code owners July 23, 2026 00:58
@tuna1207
tuna1207 temporarily deployed to default-branch July 23, 2026 00:58 — with GitHub Actions Inactive
@tuna1207 tuna1207 changed the title feat(wallet): wire ClaimsService and ClaimsController initialization feat: wire ClaimsService and ClaimsController initialization Jul 23, 2026
@@ -0,0 +1,16 @@
import type { Env } from '@metamask/claims-controller';

export type ClaimsControllerInstanceOptions = Record<string, never>;

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.

Please use strict types.

Suggested change
export type ClaimsControllerInstanceOptions = Record<string, never>;
export type ClaimsControllerInstanceOptions =
ConstructorParameters<typeof ClaimsController>[0];

Comment on lines +5 to +16
export type ClaimsServiceInstanceOptions = {
/**
* Claims API environment. Supplied by the consumer per build flavor
* (dev, uat, production).
*/
env: Env;

/**
* Platform fetch implementation used for Claims API requests.
*/
fetchFunction: typeof fetch;
};

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.

Same here. We can re-use the construct args type.

Suggested change
export type ClaimsServiceInstanceOptions = {
/**
* Claims API environment. Supplied by the consumer per build flavor
* (dev, uat, production).
*/
env: Env;
/**
* Platform fetch implementation used for Claims API requests.
*/
fetchFunction: typeof fetch;
};
export type ClaimsServiceInstanceOptions =
ConstructorParameters<typeof ClaimsService>[0];

storage: new InMemoryStorageAdapter(),
},
remoteFeatureFlagController: REMOTE_FEATURE_FLAG_OPTIONS,
claimsService: {

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.

Why? TransactionController doesn't interact with claims though.

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 InstanceSpecificOptions = {
approvalController?: ApprovalControllerInstanceOptions;
claimsService: ClaimsServiceInstanceOptions;
claimsController?: ClaimsControllerInstanceOptions;

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.

May I know why is claimsController optional but claimsService is required?

### 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.

@lwin-kyaw

Copy link
Copy Markdown
Contributor

One more thing I noticed is that shield/subscriptions/claims controllers have the different constructor interfaces.

Some accept ENV and some accept URL. I think they should be consistent.
And what's your thought on replacing ClaimsEnv SubscriptionsEnv with ENV from the AuthenticationController?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants