-
-
Notifications
You must be signed in to change notification settings - Fork 256
feat: Add optional JWT token authentication to multi-chain accounts API #7165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bug: Test timeout value doesn't match updated constant
The test comment and advanceTime call use 30000ms to simulate the timeout, but ACCOUNTS_API_TIMEOUT_MS was changed from 30000 to 10000 in TokenDetectionController.ts. The test advances time by 30000ms when it should advance by 10000ms to properly test the timeout behavior. This causes the test to wait 3x longer than necessary and doesn't accurately test the actual timeout threshold.
packages/assets-controllers/src/TokenDetectionController.test.ts#L2833-L2836
core/packages/assets-controllers/src/TokenDetectionController.test.ts
Lines 2833 to 2836 in 71af222
| // Fast-forward time by 30 seconds to trigger the timeout | |
| // This simulates the API call taking longer than the ACCOUNTS_API_TIMEOUT_MS (30000ms) | |
| await advanceTime({ clock, duration: 30000 }); |
Explanation
What is the current state and why does it need to change?
Currently, the multi-chain accounts API calls in
TokenDetectionControllerandTokenBalancesControllerare made without authentication. This limits the ability to provide user-specific data and secure API endpoints that require authenticated requests.What is the solution and how does it work?
This PR adds optional JWT token authentication and timeout protection to the accounts API calls:
API Layer Changes (
multi-chain-accounts.ts):jwtTokenparameter tofetchMultiChainBalancesandfetchMultiChainBalancesV4Authorization: Bearer <token>headerController Integration:
AuthenticationController:getBearerTokenand passes it tofetchMultiChainBalanceswhen detecting tokens via Accounts APIfetchMultiChainBalancesV4Balance Fetcher Updates (
api-balance-fetcher.ts):AccountsApiBalanceFetcherto accept and pass JWT token through the fetch chainupdateBalances→fetch→#fetchBalances→ API callsKey Design Decisions
References
Checklist
TokenDetectionController.test.tsto verify JWT token is passed correctlyTokenDetectionController.test.tsto verify 30-second timeout triggers RPC fallbackTokenBalancesController.test.tsto verify JWT token flows through balance fetchermulti-chain-accounts.test.tsto verify Authorization header is set correctlyadvanceTimehelperfetchMultiChainBalancesandfetchMultiChainBalancesV4Note
Adds optional JWT bearer authentication to multi‑chain Accounts API calls and wires token retrieval through controllers, while lowering timeouts to 10s and reducing API batch size to 20.
jwtTokentofetchMultiChainBalances/fetchMultiChainBalancesV4; includeAuthorization: Bearer <token>header when provided.10s; reduce V4 batch size from50to20.TokenDetectionControllerandTokenBalancesControllerfetch JWT viaAuthenticationController:getBearerTokenand pass it through balance/token detection flows.TokenDetectionControllerAccounts API timeout lowered to10s.AccountsApiBalanceFetcheraccepts/forwardsjwtToken; applies 10s timeout and 20-size batching.AuthenticationController:getBearerTokenand token list state injection.@metamask/profile-sync-controlleras dev/peer dep.CHANGELOG.mdto document the new optional auth.Written by Cursor Bugbot for commit d645dcf. This will update automatically on new commits. Configure here.