Skip to content

Conversation

@himanshuchawla009
Copy link
Contributor

@himanshuchawla009 himanshuchawla009 commented Jul 24, 2025

Explanation

  • This PR moves revoke token call in background. Revoking refresh token is not a must after submit password so can be done in background and even when it fails it should affect user wallet unlock.

References

Changelog

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@himanshuchawla009 himanshuchawla009 changed the title call revoke token in background chore: call revoke token in background Jul 24, 2025
@himanshuchawla009
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link
Contributor

Preview builds have been published. See these instructions for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-tree-controller": "0.6.0-preview-fed19434",
  "@metamask-previews/accounts-controller": "32.0.0-preview-fed19434",
  "@metamask-previews/address-book-controller": "6.1.1-preview-fed19434",
  "@metamask-previews/announcement-controller": "7.0.3-preview-fed19434",
  "@metamask-previews/app-metadata-controller": "1.0.0-preview-fed19434",
  "@metamask-previews/approval-controller": "7.1.3-preview-fed19434",
  "@metamask-previews/assets-controllers": "73.0.0-preview-fed19434",
  "@metamask-previews/base-controller": "8.0.1-preview-fed19434",
  "@metamask-previews/bridge-controller": "37.0.0-preview-fed19434",
  "@metamask-previews/bridge-status-controller": "37.0.0-preview-fed19434",
  "@metamask-previews/build-utils": "3.0.3-preview-fed19434",
  "@metamask-previews/chain-agnostic-permission": "1.0.0-preview-fed19434",
  "@metamask-previews/composable-controller": "11.0.0-preview-fed19434",
  "@metamask-previews/controller-utils": "11.11.0-preview-fed19434",
  "@metamask-previews/delegation-controller": "0.6.0-preview-fed19434",
  "@metamask-previews/earn-controller": "4.0.0-preview-fed19434",
  "@metamask-previews/eip1193-permission-middleware": "1.0.0-preview-fed19434",
  "@metamask-previews/ens-controller": "17.0.1-preview-fed19434",
  "@metamask-previews/error-reporting-service": "2.0.0-preview-fed19434",
  "@metamask-previews/eth-json-rpc-provider": "4.1.8-preview-fed19434",
  "@metamask-previews/foundryup": "1.0.0-preview-fed19434",
  "@metamask-previews/gas-fee-controller": "24.0.0-preview-fed19434",
  "@metamask-previews/json-rpc-engine": "10.0.3-preview-fed19434",
  "@metamask-previews/json-rpc-middleware-stream": "8.0.7-preview-fed19434",
  "@metamask-previews/keyring-controller": "22.1.0-preview-fed19434",
  "@metamask-previews/logging-controller": "6.0.4-preview-fed19434",
  "@metamask-previews/message-manager": "12.0.2-preview-fed19434",
  "@metamask-previews/messenger": "0.0.0-preview-fed19434",
  "@metamask-previews/multichain-account-service": "0.2.1-preview-fed19434",
  "@metamask-previews/multichain-api-middleware": "1.0.0-preview-fed19434",
  "@metamask-previews/multichain-network-controller": "0.11.0-preview-fed19434",
  "@metamask-previews/multichain-transactions-controller": "4.0.0-preview-fed19434",
  "@metamask-previews/name-controller": "8.0.3-preview-fed19434",
  "@metamask-previews/network-controller": "24.0.1-preview-fed19434",
  "@metamask-previews/notification-services-controller": "15.0.0-preview-fed19434",
  "@metamask-previews/permission-controller": "11.0.6-preview-fed19434",
  "@metamask-previews/permission-log-controller": "4.0.0-preview-fed19434",
  "@metamask-previews/phishing-controller": "13.1.0-preview-fed19434",
  "@metamask-previews/polling-controller": "14.0.0-preview-fed19434",
  "@metamask-previews/preferences-controller": "18.4.1-preview-fed19434",
  "@metamask-previews/profile-sync-controller": "22.0.0-preview-fed19434",
  "@metamask-previews/rate-limit-controller": "6.0.3-preview-fed19434",
  "@metamask-previews/remote-feature-flag-controller": "1.6.0-preview-fed19434",
  "@metamask-previews/sample-controllers": "1.0.0-preview-fed19434",
  "@metamask-previews/seedless-onboarding-controller": "2.4.0-preview-fed19434",
  "@metamask-previews/selected-network-controller": "23.0.0-preview-fed19434",
  "@metamask-previews/signature-controller": "32.0.0-preview-fed19434",
  "@metamask-previews/token-search-discovery-controller": "3.3.0-preview-fed19434",
  "@metamask-previews/transaction-controller": "59.0.0-preview-fed19434",
  "@metamask-previews/user-operation-controller": "38.0.0-preview-fed19434"
}

Comment on lines +657 to +662
await this.#createNewVaultWithAuthData({
password,
rawToprfEncryptionKey: toprfEncryptionKey,
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
rawToprfAuthKeyPair: toprfAuthKeyPair,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

note that #createNewVaultWithAuthData is potentially an expensive operation.
it runs encryptWithDetail(pw, vaultData), which involves the intentionally slow pbkdf2 key derivation step.

as you are increasing the usage of vault encryption, you are driving up cpu usage.

Comment on lines +665 to +677
this.#revokeRefreshTokenAndUpdateState(revokeToken)
.then(() => {
// re-creating vault to persist the new revoke token
return this.#createNewVaultWithAuthData({
password,
rawToprfEncryptionKey: toprfEncryptionKey,
rawToprfPwEncryptionKey: toprfPwEncryptionKey,
rawToprfAuthKeyPair: toprfAuthKeyPair,
});
})
.catch((error) => {
log('Error revoking refresh token', error);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

writing the vault asynchronously like this is dangerous as it can lead to vault corruption.
imagine another piece of code updates the vault in the meantime. when this code here is executed after that, the vault will be overwritten with some old data.

Comment on lines +782 to +795
this.#revokeRefreshTokenAndUpdateState(revokeToken)
.then(() => {
// re-creating vault to persist the new revoke token.
// TODO: Optimize this function such that updates to vault wont require re-creating the vault.
return this.#createNewVaultWithAuthData({
password: globalPassword,
rawToprfEncryptionKey: latestEncKey,
rawToprfPwEncryptionKey: latestPwEncKey,
rawToprfAuthKeyPair: latestAuthKeyPair,
});
})
.catch((error) => {
log('Error revoking refresh token', error);
});
Copy link
Contributor

Choose a reason for hiding this comment

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

see comment above, we can't do this

matthewwalsh0 added a commit that referenced this pull request Nov 10, 2025
## Explanation

Support Relay quotes requiring multiple transactions, such as a token
approval and deposit.

Use fallback gas limit if missing in transaction data.

## References

Related to
[#6184](MetaMask/MetaMask-planning#6184)

## Checklist

- [x] I've updated the test suite for new or updated code as appropriate
- [x] I've updated documentation (JSDoc, Markdown, etc.) for new or
updated code as appropriate
- [x] I've communicated my changes to consumers by [updating changelogs
for packages I've
changed](https://github.com/MetaMask/core/tree/main/docs/contributing.md#updating-changelogs),
highlighting breaking changes as necessary
- [x] I've prepared draft pull requests for clients and consumer
packages to resolve any breaking changes

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Adds multi-transaction support for Relay quotes with batch submission,
fallback gas handling, and shared transaction ID collection utility.
> 
> - **Relay strategy**:
> - Support multiple transactions per quote: submit via
`TransactionController:addTransactionBatch`, collect required IDs with
`collectTransactionIds`, wait for all confirmations, and return last tx
`hash`.
> - Poll Relay status from the last step; set `isIntentComplete` when
`skipTransaction`.
> - Normalize params with fallback `gas` using
`RELAY_FALLBACK_GAS_LIMIT`.
> - Quote fees: compute source network fee using total gas across items
or fallback when missing.
> - **Utils**:
> - Add `utils/transaction#collectTransactionIds` and use it in
Bridge/Relay; remove in-file implementation from Bridge.
> - **Types/Mocks**:
> - Make `RelayQuote.steps[].items[].data.gas` optional; extend
messenger to handle `TransactionController:addTransactionBatch`.
> - **Changelog**:
>   - Note support for Relay quotes with multiple transactions.
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
7c30789. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants