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: add scopes field to KeyringAccount #29195

Open
wants to merge 74 commits into
base: main
Choose a base branch
from

Conversation

ccharly
Copy link
Contributor

@ccharly ccharly commented Dec 13, 2024

Description

Testing the new scopes added on the KeyringAccount.

Open in GitHub Codespaces

Related issues

Requires this PR to be merged first:

Related to:

Manual testing steps

  • Use a previous stable version
git checkout Version-v12.10.0 # Or use a release build
  • Run it:
yarn
yarn start:flask
  • Create a bunch of accounts (EVM, non-EVM (Solana/Bitcoin), hardware-wallet, Snap EVM accounts like the SSK)

Screenshot 2025-01-16 at 17 11 55

  • Save your extension logs (Settings > Advanced)
  • Now disable your extension (chrome://extensions)
  • Stops your yarn start:flask
  • Now, update your extension by going back to this PR (or by using the latest RC if you're validating an RC version)
git checkout feat/keyring-account-scopes
  • Re-run it:
yarn
yarn start:flask
  • Re-enable your extension (chrome://extensions)
  • Open up your console logs (looking at the service worker)
  • You should now see some migrations running like:

Screenshot 2025-01-16 at 17 14 03

  • You should also see some other migrations from the Snap keyring this like so:

Screenshot 2025-01-16 at 18 52 48

  • Save your extension logs again (Settings > Advanced, and use a different filename)
  • Now, compare your 2 .json files

Screenshots/Recordings

Before

After

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.

@ccharly ccharly force-pushed the feat/keyring-account-scopes branch from d1cc825 to 81c5c8f Compare December 13, 2024 11:36
@ccharly ccharly changed the title Feat/keyring account scopes feat(keyring-api)!: add scopes field to KeyringAccount Dec 13, 2024
@ccharly ccharly force-pushed the feat/keyring-account-scopes branch from ecb5bc1 to 3a72085 Compare December 13, 2024 17:12
@ccharly ccharly requested review from a team as code owners January 14, 2025 16:39
@ccharly ccharly marked this pull request as draft January 14, 2025 16:39
@metamaskbot
Copy link
Collaborator

Builds ready [3da5933]
Page Load Metrics (1794 ± 102 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint38121821660470226
domContentLoaded141521731760210101
load142521811794213102
domInteractive24216454120
backgroundConnect868332110
firstReactRender18100513014
getState598212512
initialActions01000
loadScripts10511664131817584
setupStore75213116
uiStartup178529502158321154
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -38.04 KiB (-0.65%)
  • ui: 0 Bytes (0.00%)
  • common: -74.95 KiB (-0.89%)

@metamaskbot
Copy link
Collaborator

Builds ready [c512ad5]
Page Load Metrics (1914 ± 78 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint24621621669581279
domContentLoaded15042144189116077
load15132166191416378
domInteractive27153623316
backgroundConnect775232211
firstReactRender16104462713
getState572232110
initialActions01000
loadScripts10491625142613967
setupStore66518199
uiStartup175230932246269129
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -38.04 KiB (-0.65%)
  • ui: 0 Bytes (0.00%)
  • common: -74.95 KiB (-0.89%)

import { ETH_EOA_METHODS } from '../../../shared/constants/eth-methods';
import { migrate } from './105';
import type { Identity, InternalAccount } from './105';
Copy link
Contributor

@danroc danroc Jan 15, 2025

Choose a reason for hiding this comment

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

Why is it imported from the migration? Shouldn't it be defined somewhere else?

Got it from the next file, but I wouldn't expect InternalAccount to be defined there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well.. given that the migration was done for a previous "state version", I thought that keeping the "old InternalAccount representation" for that migration was better than relying on the new one.

I honestly don't know what's the best strategy here.

So yes, the test import locally-defined type of the InternalAccount and Identity was duplicated in both the test and the migration files, so I just refactored slightly (I can revert this).

@@ -59,6 +59,7 @@ describe('Accounts Selectors', () => {
'eth_signTypedData_v4',
],
type: 'eip155:eoa',
scopes: ['eip155'],
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
scopes: ['eip155'],
scopes: [EthScopes.Mainnet],

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -48,6 +54,7 @@ describe('useMultichainWalletSnapClient', () => {
id: '22b44d7c-1e57-4b5b-8502-02698e686fd1',
options: {},
methods: ['someMethod'],
scopes: [SolScopes.Devnet],
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: It would be nice to update this account type back to SolanaAccountType.DataAccount

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch! The scopes is not really correct either (compared to what we do on the migration and on the Solana Snap, I'll update that now)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

github-merge-queue bot pushed a commit to MetaMask/metamask-mobile that referenced this pull request Jan 16, 2025
# **Description**

The primary purpose of this PR is to update the accounts controller and
the assets-controller to the latest version. In doing that, there were
several other package updates that were needed. Here is a summary of the
updates...


# 🔴  Major updates 🔴 

### "@metamask/accounts-controller": "^20.0.1" -> ^21.0.0
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/accounts-controller/CHANGELOG.md#2100)
- Breaking changes
- BREAKING: Add scopes field to KeyringAccount
(MetaMask/core#5066),
(MetaMask/core#5136)
This field is now required and will be used to identify the supported
chains (using CAIP-2 chain IDs) for every accounts.
- Changes
- Bump @metamask/base-controller from ^7.0.0 to ^7.1.1
(MetaMask/core#5079),
(MetaMask/core#5135)
- Bump @metamask/utils to ^11.0.1
(MetaMask/core#5080)
- Bump @metamask/rpc-errors to ^7.0.2
(MetaMask/core#5080)
- Use new @metamask/keyring-internal-api@^1.0.0
(MetaMask/core#4695)
This package has been split out from the Keyring API.
- Bump @metamask/keyring-api from ^10.1.0 to ^12.0.0
(MetaMask/core#4695)
- Bump @metamask/eth-snap-keyring from ^5.0.1 to ^7.0.0
(MetaMask/core#4695)
ESM/CommonJS support.

### "@metamask/assets-controllers": "^45.1.1", ->  ^46.0.0",
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/assets-controllers/CHANGELOG.md#4600)
- Breaking changes
- BREAKING: Bump @metamask/accounts-controller peer dependency from
^20.0.0 to ^21.0.0 (MetaMask/core#5140)
- Changes
- Remove use of @metamask/keyring-api
(MetaMask/core#4695)
@metamask/providers and webextension-polyfill peer dependencies are no
longer required.
- Use new @metamask/keyring-internal-api@^1.0.0
(MetaMask/core#4695)
This package has been split out from the Keyring API. Its types are
compatible with the @metamask/keyring-api package used previously.
- Bump @metamask/base-controller from ^7.0.0 to ^7.1.1
(MetaMask/core#5079),
(MetaMask/core#5135)
- Bump @metamask/keyring-api from ^12.0.0 to ^13.0.0
(MetaMask/core#5066)
- Bump @metamask/utils to ^11.0.1
(MetaMask/core#5080)
- Bump @metamask/rpc-errors to ^7.0.2
(MetaMask/core#5080)
- Added
- Add new MultichainBalancesController
(MetaMask/core#4965)
This controller has been migrated from the MetaMask extension codebase.

### "@metamask/utils": "^10.0.1" -> ^11.0.1"
-
[changelog](https://github.com/MetaMask/utils/blob/main/CHANGELOG.md#1101)
- breaking changes
- BREAKING: generateRandomMnemonic now returns Promise<void> instead of
void (MetaMask/utils#222)

### Added "@metamask/keyring-internal-api": "^2.0.0",
-
[changelog](https://github.com/MetaMask/accounts/blob/main/packages/keyring-internal-api/CHANGELOG.md#200)
- This package was a peer dep on the latest accounts controller and
assets controller. Given this I figured we should add it now anyway.
- Changes needed
- update imports from `@metamask/keyring-api` to
`@metamask/keyring-internal-api`
   - add support for scopes in the InternalAccount object
- added migration (066.ts) to backfill the scopes to existing accounts.
- This change is based off a [similar change made in the
extension](MetaMask/metamask-extension#29195)
made by @ccharly

### Added @metamask/keyring-snap-client: "^2.0.0"
-
[changelog](https://github.com/MetaMask/accounts/blob/main/packages/keyring-snap-client/CHANGELOG.md#200)
- Added because KeyringClient is now exported from
`@metamask/keyring-snap-client` instead of `@metamask/keyring-api'`. See
`app/components/Views/AddAccountActions/AddAccountActions.tsx` for
changes.

### "@metamask/keyring-api": "^10.1.0", -> ^13.0.0"
-
[changelog](https://github.com/MetaMask/accounts/blob/main/packages/keyring-api/CHANGELOG.md#1300)
- Breaking changes
- BREAKING: Add scopes field to KeyringAccount
(MetaMask/accounts#101)
- BREAKING: Split into several smaller packages
(MetaMask/accounts#24)
        - This should improve dependencies management.
- Internal related types (internal to both clients) have been moved to
keyring-internal-* packages.
- Keyring API clients (mainly used by dapps) have been moved to
keyring-snap-client package.
        - Common utils have been moevd to keyring-utils package.

### "@metamask/eth-snap-keyring": "^5.0.1" -> ^7.0.0"
-
[changelog](https://github.com/MetaMask/accounts/blob/main/packages/keyring-eth-simple/CHANGELOG.md#700)
- breaking changes
- BREAKING: Increase minimum Node.js version to 16
(MetaMask/eth-simple-keyring#152)
- BREAKING: Bump @metamask/eth-sig-util from ^6.0.1 to ^7.0.0
(MetaMask/eth-simple-keyring#156)
- Bump @metamask/utils from ^5.0.0 to ^8.1.0
(MetaMask/eth-simple-keyring#153)
- Bump ethereum-cryptography from ^1.2.0 to ^2.1.2
(MetaMask/eth-simple-keyring#153)
- BREAKING: Bump @metamask/eth-sig-util dependency from ^7.0.3 to ^8.0.0
(MetaMask/accounts#79)
- signTypedData no longer support number for addresses, see
[here](https://github.com/MetaMask/eth-sig-util/blob/main/CHANGELOG.md#800).

## 🟡 Minor updates 🟡 

### "@metamask/base-controller": "^7.0.1", -> ^7.1.1
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/base-controller/CHANGELOG.md#711)
- Changes
    -  Bump @metamask/utils from ^10.0.0 to ^11.0.1
- Rename ControllerMessenger to Messenger
(MetaMask/core#5050)
        - ControllerMessenger has been renamed to Messenger
- RestrictedControllerMessengerConstraint has been renamed to
RestrictedMessengerConstraint
- RestrictedControllerMessenger has been renamed to RestrictedMessenger
- The RestrictedMessenger constructor parameter controllerMessenger has
been renamed to messenger, though the old name is still accepted
- The old names remain exported as deprecated aliases of the new names,
so this is not a breaking change.

### "@metamask/providers": "^18.1.0" -> ^18.3.1"
-
[changelog](https://github.com/MetaMask/providers/blob/main/CHANGELOG.md#1831)
- Changes
- Bump @metamask/json-rpc-engine from ^10.0.1 to ^10.0.2
(MetaMask/providers#397)
- Bump @metamask/json-rpc-middleware-stream from ^8.0.5 to ^8.0.6
(MetaMask/providers#397)
- Bump @metamask/rpc-errors from ^7.0.1 to ^7.0.2
(MetaMask/providers#397)
- Bump @metamask/utils from ^10.0.0 to ^11.0.1
(MetaMask/providers#397)


## 🟢  Patch updates 🟢 

### "@metamask/json-rpc-engine": "^10.0.0" -> ^10.0.2",
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/json-rpc-engine/CHANGELOG.md#1002)

### "@metamask/json-rpc-middleware-stream": "^8.0.2" -> 8.0.6"
-
[changelog](https://github.com/MetaMask/core/blob/main/packages/json-rpc-middleware-stream/CHANGELOG.md#806)
- changed
- Bump @metamask/json-rpc-engine from ^10.0.1 to ^10.0.2
(MetaMask/core#5082)
- Bump @metamask/utils from ^10.0.0 to ^11.0.1
(MetaMask/core#5080)

### "@metamask/rpc-errors": "^7.0.1" -> ^7.0.2"
-
[changelog](https://github.com/MetaMask/rpc-errors/blob/main/CHANGELOG.md#702)
- changes
- Bump @metamask/utils from ^10.0.0 to ^11.0.1
(MetaMask/rpc-errors#166)


## **Related issues**

Fixes: #12967
Fixes: #12966

Fixes: MetaMask/accounts-planning#758

Unblocks: #12599

## **Manual testing steps**

#### Basic import account flow with tokens


https://github.com/user-attachments/assets/1a8d3e59-34e4-413e-a3e8-7dbdc5f7424a



## **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 Mobile
Coding
Standards](https://github.com/MetaMask/metamask-mobile/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-mobile/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.
@ccharly ccharly force-pushed the feat/keyring-account-scopes branch from f8e088a to c70c99a Compare January 17, 2025 11:42
@ccharly ccharly marked this pull request as ready for review January 17, 2025 12:58
@metamaskbot
Copy link
Collaborator

Builds ready [9e94e59]
Page Load Metrics (1782 ± 107 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint154424461781228110
domContentLoaded153323731752219105
load154524471782224107
domInteractive21204554521
backgroundConnect798292512
firstReactRender1698412713
getState593202412
initialActions00000
loadScripts11211787130817684
setupStore66613157
uiStartup175327202032263126
Bundle size diffs [🚀 Bundle size reduced!]
  • background: -38.65 KiB (-0.65%)
  • ui: 0 Bytes (0.00%)
  • common: -73.09 KiB (-0.84%)

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.

Update metamask/accounts-controller to version 21.0.0
6 participants