-
Notifications
You must be signed in to change notification settings - Fork 5k
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
feat: Migrate eth_accounts and permittedChains to CAIP-25 endowment #27847
base: main
Are you sure you want to change the base?
Conversation
CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes. |
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
🚮 Removed packages: npm/@json-schema-spec/[email protected], npm/@json-schema-tools/[email protected], npm/@metamask/[email protected], npm/@open-rpc/[email protected] |
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
@metamask-bot update-policies |
.yarn/patches/@json-schema-tools-reference-resolver-npm-1.2.6-4e1497c16d.patch
Show resolved
Hide resolved
@metamaskbot update-policies |
Policies updated. 🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff |
app/scripts/lib/rpc-method-middleware/handlers/ethereum-chain-utils.js
Outdated
Show resolved
Hide resolved
app/scripts/lib/rpc-method-middleware/handlers/wallet-requestPermissions.ts
Outdated
Show resolved
Hide resolved
app/scripts/lib/rpc-method-middleware/handlers/wallet-revokePermissions.ts
Outdated
Show resolved
Hide resolved
@metamaskbot update-policies |
Policies updated. 🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff |
@SocketSecurity ignore npm/@metamask/[email protected] i know that mcmire guy |
@SocketSecurity ignore npm/@metamask/[email protected] i still know that mcmire fellow |
@SocketSecurity ignore npm/@metamask/[email protected] the fetch isn't new, but even then it's fine because it fetches caller supplied url |
@metamaskbot update-policies |
Policies updated. 🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff |
# Conflicts: # ui/pages/permissions-connect/connect-page/connect-page.tsx
}, | ||
) { | ||
let validParams; | ||
try { | ||
validParams = validateAddEthereumChainParams(req.params[0], end); |
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.
Nit: Looks like we could remove the superfluous end
parameter in a separate PR, it appears to be unused on main
as well
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.
PR against main here #29619
app/scripts/lib/rpc-method-middleware/handlers/add-ethereum-chain.test.js
Outdated
Show resolved
Hide resolved
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.
Great to see this converted to TypeScript, though perhaps we could do this in a separate PR as well, to reduce the impact of this one.
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.
sure! 30b1773
app/scripts/metamask-controller.js
Outdated
* | ||
* @param {string} origin - The origin whose exposed accounts to retrieve. | ||
* @param {boolean} [suppressUnauthorizedError] - Suppresses the unauthorized error. | ||
* @param {boolean} ignoreLock - If accounts should be returned even if the wallet is locked. |
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.
Perhaps we can use an options object here instead, so that this is a named parameter. When reading the request-accounts
method middleware, I was unsure what getAccounts(true)
meant.
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.
app/scripts/lib/rpc-method-middleware/handlers/request-accounts.ts
Outdated
Show resolved
Hide resolved
app/scripts/lib/rpc-method-middleware/handlers/wallet-requestPermissions.ts
Show resolved
Hide resolved
app/scripts/lib/rpc-method-middleware/handlers/wallet-requestPermissions.ts
Outdated
Show resolved
Hide resolved
res.result = Object.values(grantedPermissions).filter( | ||
(value) => value !== undefined, | ||
) as Json; |
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.
Nit: We can avoid type casting like this:
res.result = Object.values(grantedPermissions).filter( | |
(value) => value !== undefined, | |
) as Json; | |
res.result = Object.values(grantedPermissions).filter( | |
( | |
permission: ValidPermission<string, Caveat<string, Json>> | undefined, | |
): permission is ValidPermission<string, Caveat<string, Json>> => | |
permission !== undefined, | |
); |
A bit verbose, and still doesn't really validate that the return type matches the operation, but it does make a lot more clear what type transformation we're making here. And it preserves more type information.
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.
Where do these undefined values come from anyway 🤔 I'm guessing it's because the controller considers it a valid possibility that the user would approve a set of zero permissions? But our UI doesn't allow that. Curious. Maybe we can find a way to update the type later to better reflect what it does.
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.
I've never actually seen undefined at runtime. Types seem to suggest this is possible though, but the types might just be incorrect.
I took this change from Elliot's suggestion
app/scripts/lib/rpc-method-middleware/handlers/wallet-revokePermissions.ts
Outdated
Show resolved
Hide resolved
({ type }) => type === Caip25CaveatType, | ||
)?.value as Caip25CaveatValue | undefined; | ||
|
||
if (caip25CaveatValue?.isMultichainOrigin) { |
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.
Do we still need this? I'm not sure why we'd want to throw an error in this case. This is what I thought we were trying to avoid - introducing obstacles to simultaneous use of both APIs.
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.
- wallet_requestPermissions leave as is, that being the CAIP-25 permission is always replaced in it's entirety
- wallet_add/switchEthereumChain switching, remove the isMultichainOrigin check
- wallet_revokePermissions, remove the isMultichainOrigin check
Done here
…rant (#29613) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Restores wallet_requestPermissions atomicity by delaying CAIP-25 grant until after other grants if they are requested [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29613?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
Builds ready [368fccb]
Page Load Metrics (1753 ± 69 ms)
|
…o caip25-permission-migration
…rmissions.ts Co-authored-by: Mark Stacey <[email protected]>
…o caip25-permission-migration
Builds ready [30b1773]
Page Load Metrics (1694 ± 109 ms)
|
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Removes tests that are no longer applicable pertaining to permitted chains. [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29618?quickstart=1) ## **Related issues** See: #27847 (comment) ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
app/scripts/migrations/137.ts
Outdated
`Migration ${version}: Invalid subject for origin "${origin}" of type ${typeof subject}`, | ||
), | ||
); | ||
return state; |
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.
Perhaps @Gudahtt can chime in here, but seems dangerous to bail out of the migration with a potentially partially modified state.
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.
yeah hmmm should these be continue
instead?
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.
pushing a PR with suggested change
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.
) <!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** Removes unused `end` param in the ethereum-chain-util helpers * validateChainId * validateAddEthereumChainParams * validateSwitchEthereumChainParams [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29619?quickstart=1) Extending E2E timeout to get past "no timings found" error: ``` flags = { "circleci": { "timeoutMinutes": 30 } } ``` ## **Related issues** See: #27847 (comment) ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
<!-- Please submit this PR as a draft initially. Do not mark it as "Ready for review" until the template has been completely filled out, and PR status checks have passed at least once. --> ## **Description** <!-- Write a short description of the changes included in this pull request, also include relevant motivation and context. Have in mind the following questions: 1. What is the reason for the change? 2. What is the improvement/solution? --> [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/29634?quickstart=1) ## **Related issues** Fixes: ## **Manual testing steps** 1. Go to this page... 2. 3. ## **Screenshots/Recordings** <!-- If applicable, add screenshots and/or recordings to visualize the before and after of your change. --> ### **Before** <!-- [screenshots/recordings] --> ### **After** <!-- [screenshots/recordings] --> ## **Pre-merge author checklist** - [ ] I've followed [MetaMask Contributor Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask Extension Coding Standards](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/CODING_GUIDELINES.md). - [ ] I've completed the PR template to the best of my ability - [ ] I’ve included tests if applicable - [ ] I’ve documented my code using [JSDoc](https://jsdoc.app/) format if applicable - [ ] I’ve applied the right labels on the PR (see [labeling guidelines](https://github.com/MetaMask/metamask-extension/blob/main/.github/guidelines/LABELING_GUIDELINES.md)). Not required for external contributors. ## **Pre-merge reviewer checklist** - [ ] I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed). - [ ] I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.
…o caip25-permission-migration
Builds ready [c1cbb26]
Page Load Metrics (1669 ± 56 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Builds ready [70b9f05]
Page Load Metrics (1567 ± 38 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
Description
This PR replaces the replaces the internal
eth_accounts
andendowment:permittedChains
permission structure with a CAIP-25 endowment. It adds adapter logic to translate to and from the new internal CAIP-25 permissions. This change should be transparent to wallet users and to dapps except foronetwo cases, see below. This change is required in order to support CAIP-25 and CAIP-27 requests in a follow-up PR that enables the Multichain API.Related issues
Related: MetaMask/core#4784
Manual testing steps
There should be no user or dapp facing difference in behavior except:
wallet_revokePermissions
and specifying eithereth_accounts
orendowment:permitted-chains
, the entire CAIP-25 permission will be revoked. It will appear to the dapp as if botheth_accounts
andendowment:permitted-chains
were revoked.wallet_getPermissions
for a permitted dapp when the wallet is locked,eth_accounts
should be returned in addition toendowment:permitted-chains
. Currently there is a regression onmain
where onlyendowment:permitted-chains
gets returned when the wallet is locked.Locked Wallet Behavior with dapp connected
Other than the one noted item below, this behavior matches that in
main
eth_accounts
returns []wallet_getPermissions
returns permissions incl eth_accountswallet_revokePermissions
works as usual and revokes eth_accounts and revoke permitted-chains togethermain
where eth_accounts and permitted-chains aren't revoked as a pair if either is revokedeth_requestAccounts
prompts for unlock, after unlock returns accounts if any are permitted, otherwise shows connection promptwallet_requestPermissions
prompts for unlockaccountsChanged
empty array on lock. no event after revokePermissions which makes sense since the dapp was told empty array on lock and now it's actually empty array so no changes have occurred as far as the dapp should be concerned.Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist