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 createNewVaultAndRestore from core KeyringController #19816

Merged
merged 4 commits into from
Aug 14, 2023

Conversation

mikesposito
Copy link
Member

Explanation

With this PR the extension starts using createNewVaultAndRestore from core KeyringController, instead of calling EthKeyringController directly.

Screenshots/Screencaps

Before

After

Manual Testing Steps

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.

@metamaskbot
Copy link
Collaborator

Builds ready [8314b41]
Page Load Metrics (1654 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1011831302010
domContentLoaded1508181616327235
load1508184216547737
domInteractive1508181616327235
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 157356 bytes
  • ui: -6356 bytes
  • common: 6356 bytes

@codecov
Copy link

codecov bot commented Jun 30, 2023

Codecov Report

Merging #19816 (28be6d0) into develop (e02f597) will decrease coverage by 0.15%.
The diff coverage is 66.67%.

❗ Current head 28be6d0 differs from pull request most recent head ae61eeb. Consider uploading reports for the commit ae61eeb to get more accurate results

@@             Coverage Diff             @@
##           develop   #19816      +/-   ##
===========================================
- Coverage    68.84%   68.69%   -0.15%     
===========================================
  Files          993      990       -3     
  Lines        38258    38083     -175     
  Branches     10248    10201      -47     
===========================================
- Hits         26338    26160     -178     
- Misses       11920    11923       +3     
Files Changed Coverage Δ
app/scripts/metamask-controller.js 65.58% <66.67%> (+0.09%) ⬆️

... and 76 files with indirect coverage changes

@mikesposito mikesposito force-pushed the refactor/use-core-keyring-controller branch 5 times, most recently from c65c6b9 to 2d584d7 Compare July 19, 2023 09:37
@mikesposito
Copy link
Member Author

Depends on #19659

@mikesposito mikesposito force-pushed the refactor/use-core-keyring-controller branch 2 times, most recently from 95313e3 to 1567ae0 Compare July 24, 2023 10:32
Base automatically changed from refactor/use-core-keyring-controller to develop July 24, 2023 18:44
@mikesposito mikesposito force-pushed the refactor/use-create-valut-and-restore-from-core branch from 8314b41 to e23ac8a Compare July 25, 2023 08:57
@metamaskbot
Copy link
Collaborator

Builds ready [e23ac8a]
Page Load Metrics (1758 ± 70 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1102331502412
domContentLoaded14981952175714469
load14981952175814570
domInteractive14981952175714469
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 295 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@mikesposito mikesposito marked this pull request as ready for review July 25, 2023 12:43
@mikesposito mikesposito requested a review from a team as a code owner July 25, 2023 12:43
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 a suggestion, but it's non-blocking.

Just checking but it seems there are no changes needed to tests, is this true?

Comment on lines 2951 to 2988
/**
* Get a Uint8Array mnemonic from Buffer.
*
* @param {Buffer} mnemonic - The mnemonic phrase as a Buffer
* @returns {Uint8Array} The mnemonic phrase as a Uint8Array
*/
_bufferToUint8Array(mnemonic) {
const indices = mnemonic
.toString()
.split(' ')
.map((word) => wordlist.indexOf(word));
return new Uint8Array(new Uint16Array(indices).buffer);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like almost the reverse of: #19817 (comment)

What do you think about:

Suggested change
/**
* Get a Uint8Array mnemonic from Buffer.
*
* @param {Buffer} mnemonic - The mnemonic phrase as a Buffer
* @returns {Uint8Array} The mnemonic phrase as a Uint8Array
*/
_bufferToUint8Array(mnemonic) {
const indices = mnemonic
.toString()
.split(' ')
.map((word) => wordlist.indexOf(word));
return new Uint8Array(new Uint16Array(indices).buffer);
}
/**
* Encodes a BIP-39 mnemonic as the indices of words in the English BIP-39 wordlist.
*
* @param {Buffer} mnenonic - The BIP-39 mnemonic.
* @returns {Buffer} The Unicode code points for the seed phrase formed from the words in the wordlist.
*/
_convertMnemonicToWordlistIndices(mnemonic) {
const indices = mnemonic
.toString()
.split(' ')
.map((word) => wordlist.indexOf(word));
return new Uint8Array(indices);
}

It might be good to relocate this and the other function to some kind of utility file as they're related operations, but this seems fine for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense! I just applied your suggestion.
Do you think that makes sense to merge the two PRs and then move the two methods to another file in a later PR?

Copy link
Member Author

Choose a reason for hiding this comment

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

Uhm, it looks like this doesn't work. I noticed that also in @metamask/eth-hd-keyring we convert indices to Uint16Array before converting them finally to Uint8Array.

I'm not exactly sure why this is needed though

@mikesposito mikesposito force-pushed the refactor/use-create-valut-and-restore-from-core branch from 4e5b9a9 to fc64a7b Compare August 1, 2023 11:21
@mikesposito
Copy link
Member Author

mikesposito commented Aug 1, 2023

Just checking but it seems there are no changes needed to tests, is this true?

@mcmire We already have test coverage for this method, but I've just refactored the tests to mock KeyringController instead of EthKeyringController, which I think makes more sense

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.

Looks good!

@mikesposito mikesposito force-pushed the refactor/use-create-valut-and-restore-from-core branch from b672917 to 28be6d0 Compare August 2, 2023 11:58
@metamaskbot
Copy link
Collaborator

Builds ready [28be6d0]
Page Load Metrics (1689 ± 63 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1273751705627
domContentLoaded14811999168813163
load14811999168913163
domInteractive14811999168813163
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 298 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@mikesposito mikesposito force-pushed the refactor/use-create-valut-and-restore-from-core branch from 28be6d0 to ae61eeb Compare August 14, 2023 08:09
@metamaskbot
Copy link
Collaborator

Builds ready [ae61eeb]
Page Load Metrics (1484 ± 37 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint1093311374622
domContentLoaded1349163214847737
load1349163214847737
domInteractive1349163214837737
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 298 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

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

LGTM!

@mikesposito mikesposito force-pushed the refactor/use-create-valut-and-restore-from-core branch from ae61eeb to e8db201 Compare August 14, 2023 14:43
@metamaskbot
Copy link
Collaborator

Builds ready [e8db201]
Page Load Metrics (1466 ± 35 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint109164125157
domContentLoaded1312158714667435
load1312158714667435
domInteractive1312158714667435
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 298 Bytes (0.01%)
  • ui: 0 Bytes (0.00%)
  • common: 0 Bytes (0.00%)

@mikesposito mikesposito merged commit d6eecf8 into develop Aug 14, 2023
@mikesposito mikesposito deleted the refactor/use-create-valut-and-restore-from-core branch August 14, 2023 15:23
@github-actions github-actions bot locked and limited conversation to collaborators Aug 14, 2023
@metamaskbot metamaskbot added the release-10.36.0 Issue or pull request that will be included in release 10.36.0 label Aug 14, 2023
@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 team-wallet-framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Keyring consolidation: use createNewVaultAndRestore from core KeyringController
5 participants