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

Use @metamask/keyring-controller #19659

Merged
merged 8 commits into from
Jul 24, 2023

Conversation

mikesposito
Copy link
Member

@mikesposito mikesposito commented Jun 19, 2023

Explanation

This PR enables a smooth transition from @metamask/eth-keyring-controller to @metamask/keyring-controller.

In order to replace all interactions between the extension client and the EthKeyringController with KeyringController in separate PRs we need to be able to start using KeyringController, while being able to keep direct interactions with EthKeyringController possible.

As the instance of EthKeyringController managed by KeyringController is inaccessible, we need a temporary patch to add a getEthKeyringController method on KeyringController so that we can keep using EthKeyringController in MetamaskController.

Manual Testing Steps

Nothing should be changed in terms of functionality.

Pre-merge author checklist

  • I've clearly explained:
    • What problem this PR is solving
    • How this problem was solved
    • How reviewers can test my changes
  • Sufficient automated test coverage has been added

Pre-merge reviewer checklist

  • Manual testing (e.g. pull and build branch, run in browser, test code being changed)
  • PR is linked to the appropriate GitHub issue
  • IF this PR fixes a bug in the release milestone, add this PR to the release milestone

If further QA is required (e.g. new feature, complex testing steps, large refactor), add the Extension QA Board label.

In this case, a QA Engineer approval will be be required.

@github-actions
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.

@socket-security
Copy link

socket-security bot commented Jun 19, 2023

👍 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.

@socket-security
Copy link

socket-security bot commented Jun 19, 2023

No top level dependency changes detected. Learn more about Socket for GitHub ↗︎

@codecov
Copy link

codecov bot commented Jun 19, 2023

Codecov Report

Merging #19659 (16e373d) into develop (937fcdc) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

❗ Current head 16e373d differs from pull request most recent head 9530eed. Consider uploading reports for the commit 9530eed to get more accurate results

@@             Coverage Diff             @@
##           develop   #19659      +/-   ##
===========================================
- Coverage    69.36%   69.36%   -0.00%     
===========================================
  Files          987      987              
  Lines        37289    37292       +3     
  Branches     10011    10011              
===========================================
+ Hits         25865    25867       +2     
- Misses       11424    11425       +1     
Impacted Files Coverage Δ
app/scripts/metamask-controller.js 65.95% <100.00%> (+0.09%) ⬆️

... and 1 file with indirect coverage changes

@metamaskbot
Copy link
Collaborator

Builds ready [ed4efdb]
Page Load Metrics (1663 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1021811292110
domContentLoaded14751955163812359
load14751981166313665
domInteractive14751955163812359
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 157067 bytes
  • ui: -6356 bytes
  • common: 6356 bytes

@mikesposito mikesposito force-pushed the refactor/use-core-keyring-controller branch from ed4efdb to 8d67d4e Compare June 20, 2023 09:15
@mikesposito mikesposito marked this pull request as ready for review June 20, 2023 09:16
@mikesposito mikesposito requested review from a team as code owners June 20, 2023 09:16
@mikesposito mikesposito requested a review from jpuri June 20, 2023 09:16
@mikesposito
Copy link
Member Author

Uhm, it looks like we are adding ~150kb to the background bundle, which isn't great.

From the bundle visualizer, looks like KeyringController introduces his own version of [email protected], [email protected](and [email protected] along with it).
Fixing these two packages should reduce it by ~80kb

Screenshot 2023-06-20 at 11 24 14

@metamaskbot
Copy link
Collaborator

Builds ready [8d67d4e]
Page Load Metrics (1950 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint128189151168
domContentLoaded1758201519137335
load1758210719507837
domInteractive1758201419137335
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 157067 bytes
  • ui: -6356 bytes
  • common: 6356 bytes

@mikesposito mikesposito force-pushed the refactor/use-core-keyring-controller branch 3 times, most recently from 40b1e8b to a73071d Compare July 18, 2023 21:58
@mikesposito
Copy link
Member Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated

@metamaskbot
Copy link
Collaborator

Builds ready [6d13c99]
Page Load Metrics (1605 ± 75 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1072101382512
domContentLoaded13971918160515775
load13981918160515775
domInteractive13971918160415775
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 85114 bytes
  • ui: -826 bytes
  • common: -126191 bytes

@mikesposito mikesposito requested review from Gudahtt and mcmire July 18, 2023 22:52
@mikesposito mikesposito force-pushed the refactor/use-core-keyring-controller branch 2 times, most recently from c65c6b9 to 2d584d7 Compare July 19, 2023 09:37
@mikesposito
Copy link
Member Author

mikesposito commented Jul 19, 2023

In the extension we still use ethereumjs-wallet@^0.6.4 for importing private keys, but this will be removed by #19815 and we'll end up using only the ethereumjs-wallet provided by @metamask/keyring-controller, removing the direct dependency and reducing the bundle size by another 40KB

@metamaskbot
Copy link
Collaborator

Builds ready [2d584d7]
Page Load Metrics (1561 ± 33 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint102181131209
domContentLoaded1425168515616833
load1425168515616833
domInteractive1425168515616833
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 80848 bytes
  • ui: -440 bytes
  • common: -126306 bytes

@mikesposito
Copy link
Member Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

No policy changes

@metamaskbot
Copy link
Collaborator

Builds ready [a052202]
Page Load Metrics (1705 ± 83 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1162331542814
domContentLoaded14152176170517483
load14152176170517483
domInteractive14152175170517483
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 80848 bytes
  • ui: -440 bytes
  • common: -126306 bytes

@mikesposito mikesposito force-pushed the refactor/use-core-keyring-controller branch from a052202 to 95313e3 Compare July 19, 2023 15:23
@metamaskbot
Copy link
Collaborator

Builds ready [95313e3]
Page Load Metrics (1588 ± 45 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint101173132199
domContentLoaded1450178215889545
load1450178215889545
domInteractive1450178215889545
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 78.95 KiB (1.87%)
  • ui: -826 Bytes (-0.01%)
  • common: -123.35 KiB (-3.02%)

@mikesposito mikesposito force-pushed the refactor/use-core-keyring-controller branch from 95313e3 to 1567ae0 Compare July 24, 2023 10:32
@mikesposito
Copy link
Member Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated

@metamaskbot
Copy link
Collaborator

Builds ready [608b911]
Page Load Metrics (1503 ± 42 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint109170127178
domContentLoaded1366170815038842
load1366170815038842
domInteractive1366170815038742
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 76.11 KiB (1.80%)
  • ui: -6.21 KiB (-0.08%)
  • common: -152.03 KiB (-3.69%)

@@ -1,10 +1,11 @@
import type { TxData, TypedTransaction } from '@ethereumjs/tx';
-import { type MetaMaskKeyring as QRKeyring, type IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
+import type { MetaMaskKeyring as QRKeyring, IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
Copy link
Member

Choose a reason for hiding this comment

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

Curious why these type imports were changed. Was this unintended? Or did the import { type ___ } syntax cause problems with the build system?

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ah I see. The TypeScript version used here is fairly old, that's probably why.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Should we add TypeScript ~4.6.3 as an optional peer dependency to all packages in the core repo?

Copy link
Member

Choose a reason for hiding this comment

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

Maybe >=4.6.3 instead? But yes that might be a good idea

Copy link
Member

@Gudahtt Gudahtt left a comment

Choose a reason for hiding this comment

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

LGTM!

syncIdentities: this.preferencesController.syncAddresses.bind(
this.preferencesController,
),
updateIdentities: this.preferencesController.setAddresses.bind(
Copy link
Member

Choose a reason for hiding this comment

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

I noticed that setAddresses isn't quite the equivalent of updateIdentities. updateIdentities will update selectedAddress if the referenced account is removed, but setAddresses will not do that.

Copy link
Member

Choose a reason for hiding this comment

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

We can handle this in a later PR, but it will come up once we start using the core keyring controller for creating accounts and keyrings

Copy link
Member Author

Choose a reason for hiding this comment

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

we can do this as part of #18772

@metamaskbot
Copy link
Collaborator

Builds ready [16e373d]
Page Load Metrics (1596 ± 48 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint115169135168
domContentLoaded1438183115969948
load1439183115969948
domInteractive1438183115969948
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 76.11 KiB (1.80%)
  • ui: -6.21 KiB (-0.08%)
  • common: -152.03 KiB (-3.69%)

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

Had one question, but this looks good to me.

@@ -1,10 +1,11 @@
import type { TxData, TypedTransaction } from '@ethereumjs/tx';
-import { type MetaMaskKeyring as QRKeyring, type IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
+import type { MetaMaskKeyring as QRKeyring, IKeyringState as IQRKeyringState } from '@keystonehq/metamask-airgapped-keyring';
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm. Should we add TypeScript ~4.6.3 as an optional peer dependency to all packages in the core repo?

@mikesposito mikesposito merged commit 11b2c42 into develop Jul 24, 2023
@mikesposito mikesposito deleted the refactor/use-core-keyring-controller branch July 24, 2023 18:44
@github-actions github-actions bot locked and limited conversation to collaborators Jul 24, 2023
@metamaskbot metamaskbot added the release-10.36.0 Issue or pull request that will be included in release 10.36.0 label Jul 24, 2023
@metamaskbot
Copy link
Collaborator

Builds ready [9530eed]
Page Load Metrics (1601 ± 41 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint110184131168
domContentLoaded1440176216018641
load1441176216018641
domInteractive1440176216018641
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 76.11 KiB (1.80%)
  • ui: -6.21 KiB (-0.08%)
  • common: -152.03 KiB (-3.69%)

@Gudahtt Gudahtt added release-11.1.0 Issue or pull request that will be included in release 11.1.0 and removed release-10.36.0 Issue or pull request that will be included in release 10.36.0 labels Sep 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-11.1.0 Issue or pull request that will be included in release 11.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keyring Consolidation: Patch core KeyringController on extension to expose inner EthKeyringController
4 participants