Skip to content
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: Eth snap keyring #10829

Merged
merged 8 commits into from
Sep 20, 2024
Merged

feat: Eth snap keyring #10829

merged 8 commits into from
Sep 20, 2024

Conversation

owencraston
Copy link
Contributor

@owencraston owencraston commented Aug 27, 2024

Description

  1. What is the reason for the change?
  • This change adds lays the foundation for third party snap accounts by implementing/integrating the eth-snap-keyring into mobile flask
  • this is flask only feature
  • this change is needed to unlock the future of account management beyond native EOA accounts. This will enable third party MPC accounts such as Capsule. This also paves the way for multi chain accounts such as bitcoin.
  • This work has already been implemented and launched on the extension in production. We are finally going to bring these feature to mobile.
  1. What is the improvement/solution?
  • implement the SnapKeyring builder. This implementation mirrors the one on extension.
  • Implement and wire up the necessary snaps methods (getAllowedKeyringMethods, handleSnapRpcRequest, getSnapKeyring, hasPermission). The methods need to be implemented in the Engine as well as the snapMethodMiddlewareBuilder
  • add 'endowment:keyring': 'endowment:keyring' to the set of available snap permissions
  • implement keyringSnapPermissionsBuilder which derives the permissions for a specific origin.
  • include the new SnapKeyring in the additionalKeyring section of the keyring controller. This is where we add non "native" keyrings such as ledger and qr hardware wallets. The snapkeyring will now be included in this list IF THE BUILD TYPE IS FLASK.
  • I had to make some controllers properties on the Engine class for easier access across the file. This matches more closely what the extension is doing in the metamask-controllers.js file.

This PR DOES NOT

  • Allow users to confirm or deny snap account addition/removal. For now we will accept all incoming snap account additions/removals. Those confirmations will be handled in these following changes. https://github.com/MetaMask/accounts-planning/issues/152 and https://github.com/MetaMask/accounts-planning/issues/151
  • This PR does not support custom for account snaps
  • This PR does not support asynchronous approvals
  • This PR does not implement the improved account list U.I for snap accounts. For now the snap accounts in the account list will look exactly like the rest of the accounts.
  • This PR does not support granular permissions required in production since there seems to be come issues with the mobile snaps permissions in general. see Use the URL origin instead of hostname to identify subject websites #11029. For now we will eagerly grant keyring permissions to dapps since this is just a flask feature and is not doing into production.
  • Restrict wallet usage based on account permissions. Even if an account does not have signing permissions these flows will be available in the U.I and likely break.

Related issues

Fixes: https://github.com/MetaMask/accounts-planning/issues/149

Manual testing steps

  1. run yarn setup on this branch
  2. navigate to .js.env and set export METAMASK_BUILD_TYPE=flask
  3. source .js.env
  4. yarn watch:clean
  5. create/import a wallet
  6. navigate to settings/snaps
  7. there should be only one pre installed snap
  8. open the browser
  9. navigate to https://metamask.github.io/snap-simple-keyring/latest/
  10. click connect and accept all of the permissions
  11. you should now see this snap in the settings/snaps list
  12. click create account on the snap simple keyring
  13. the call should succeed and return the account info as a json obkect
  14. navigate to the home page and open the account list, the selected account should be a new account named Snap Account 1
  15. repeat step 15 as many times as you want, each time the new account should be added
  16. clicking list accounts on the SSK dapp should give you the entire list of accounts
  17. extract an id value from the listed accounts and paste it into the Remove accounts field and click.
  18. the call should succeed and return null
  19. navigate back to the home page and open the account list, that account should no longer be there and another account should be the selected account

Screenshots/Recordings

Before

N/A

After

Screen.Recording.2024-09-13.at.3.41.02.PM.1080.mov

Pre-merge author checklist

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.

Copy link
Contributor

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.

@owencraston owencraston force-pushed the feat/eth-snap-keyring branch 4 times, most recently from e1e227a to 3072451 Compare August 28, 2024 20:18
@codecov-commenter
Copy link

codecov-commenter commented Aug 28, 2024

Codecov Report

Attention: Patch coverage is 56.94444% with 31 lines in your changes missing coverage. Please review.

Project coverage is 55.92%. Comparing base (20df5be) to head (abb62cd).
Report is 7 commits behind head on main.

Files with missing lines Patch % Lines
app/core/Engine.ts 42.85% 16 Missing ⚠️
app/core/SnapKeyring/SnapKeyring.ts 66.66% 7 Missing ⚠️
app/core/Snaps/SnapsMethodMiddleware.ts 0.00% 6 Missing ⚠️
app/core/Snaps/SnapBridge.ts 0.00% 1 Missing ⚠️
app/core/Snaps/utils.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10829      +/-   ##
==========================================
+ Coverage   55.87%   55.92%   +0.04%     
==========================================
  Files        1587     1593       +6     
  Lines       37651    37860     +209     
  Branches     4505     4540      +35     
==========================================
+ Hits        21039    21174     +135     
- Misses      16116    16187      +71     
- Partials      496      499       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@owencraston owencraston force-pushed the feat/eth-snap-keyring branch 2 times, most recently from 68e5af1 to 5ba2375 Compare August 29, 2024 23:20
@owencraston owencraston force-pushed the feat/eth-snap-keyring branch 2 times, most recently from 6e17748 to dfe6473 Compare September 3, 2024 20:24
@owencraston owencraston force-pushed the feat/eth-snap-keyring branch 5 times, most recently from f6b7013 to 28aff50 Compare September 13, 2024 19:31
app/core/Engine.ts Outdated Show resolved Hide resolved
ios/Podfile.lock Outdated Show resolved Hide resolved
@owencraston owencraston marked this pull request as ready for review September 13, 2024 23:40
@owencraston owencraston requested review from a team as code owners September 13, 2024 23:40
@owencraston owencraston added the needs-qa Any New Features that needs a full manual QA prior to being added to a release. label Sep 13, 2024
@owencraston owencraston added Run Smoke E2E Triggers smoke e2e on Bitrise No QA Needed Apply this label when your PR does not need any QA effort. and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Sep 20, 2024
Copy link
Contributor

github-actions bot commented Sep 20, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: a501525
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/6604d957-cb0a-441e-8e83-99dcdad1852b

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

k-g-j
k-g-j previously approved these changes Sep 20, 2024
- This change adds lays the foundation for third party snap accounts by implementing/integrating the eth-snap-keyring into mobile flask
- this change is needed to unlock the future of account management beyond native EOA accounts
- In this change we implement the snapKeyringBuilder method
which returns an instance of the snap keyring and allows
third party snaps to add accounts to metamask
- This change also sets up the appropriate permissions for
these snaps.
@owencraston owencraston force-pushed the feat/eth-snap-keyring branch 2 times, most recently from 4539f7a to 6bcddfe Compare September 20, 2024 18:21
@owencraston owencraston added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Sep 20, 2024
Copy link
Contributor

github-actions bot commented Sep 20, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 8763e21
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/017b8c6d-954f-48d1-a580-6184ac8479fd

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Copy link

Copy link
Contributor

@Jonathansoufer Jonathansoufer left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Contributor

@Cal-L Cal-L left a comment

Choose a reason for hiding this comment

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

LGTM

@owencraston owencraston added this pull request to the merge queue Sep 20, 2024
Merged via the queue into main with commit e6a5b2b Sep 20, 2024
42 checks passed
@owencraston owencraston deleted the feat/eth-snap-keyring branch September 20, 2024 19:43
@github-actions github-actions bot locked and limited conversation to collaborators Sep 20, 2024
@metamaskbot metamaskbot added the release-7.33.0 Issue or pull request that will be included in release 7.33.0 label Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
No QA Needed Apply this label when your PR does not need any QA effort. release-7.33.0 Issue or pull request that will be included in release 7.33.0 Run Smoke E2E Triggers smoke e2e on Bitrise team-accounts
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

9 participants