feat: wire ClaimsService and ClaimsController initialization#9588
feat: wire ClaimsService and ClaimsController initialization#9588tuna1207 wants to merge 11 commits into
Conversation
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>
| @@ -0,0 +1,16 @@ | |||
| import type { Env } from '@metamask/claims-controller'; | |||
|
|
|||
| export type ClaimsControllerInstanceOptions = Record<string, never>; | |||
There was a problem hiding this comment.
Please use strict types.
| export type ClaimsControllerInstanceOptions = Record<string, never>; | |
| export type ClaimsControllerInstanceOptions = | |
| ConstructorParameters<typeof ClaimsController>[0]; |
| 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; | ||
| }; |
There was a problem hiding this comment.
Same here. We can re-use the construct args type.
| 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: { |
There was a problem hiding this comment.
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'; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
I think just one entry (above BREAKING) is sufficient enough, to keep the CHANGELOG clean. These are not really necessary.
|
One more thing I noticed is that shield/subscriptions/claims controllers have the different constructor interfaces. Some accept |
Explanation
Adds
ClaimsServiceandClaimsControlleras default initialized units in the@metamask/walletpackage, following the existingInitializationConfigurationpattern used byTransactionController,StorageService, and other wallet instances.@metamask/walletis the shared controller-integration layer for extension, mobile, and other clients, so build-specific and runtime values are injected viainstanceOptionsrather than hardcoded.ClaimsService — selects the Claims API environment and platform
fetchimplementation.instanceOptions.claimsService.envandinstanceOptions.claimsService.fetchFunctionare required. The wallet init delegatesAuthenticationController:getBearerTokento the service messenger; hosts must registerAuthenticationControlleron 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) plusKeyringController:signPersonalMessage.Wallet release work is intentionally deferred; this PR lands the integration and documents consumer options only.
References
Per-environment options
claimsService.envEnv.DEV/Env.UAT/Env.PRD)Env.DEV/Env.UAT/Env.PRD)Env.PRDin wallet-cli;Env.DEVin wallet unit testsclaimsService.fetchFunctionfetchfetchglobalThis.fetchclaimsControllerstatestateblob when suppliedstateblob when suppliedAuthenticationController:getBearerTokenAuthenticationControlleron the wallet root messenger (not aninstanceOptionsslot)AuthenticationControlleron the wallet root messenger (not aninstanceOptionsslot)Verification
yarn workspace @metamask/wallet run testyarn workspace @metamask/wallet run jest --no-coverage src/initialization/instances/claims-service/claims-service.test.ts src/initialization/instances/claims-controller/claims-controller.test.tsyarn workspace @metamask/wallet run messenger-action-types:checkyarn workspace @metamask/wallet run lint:tsconfigsyarn workspace @metamask/wallet-cli run lint:tsconfigsyarn readme-content:checkyarn codeowners:checkyarn lint:teamsChecklist
Made with Cursor