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

Update @metamask/eth-keyring-controller #1441

Merged
merged 19 commits into from
Jul 18, 2023

Conversation

mikesposito
Copy link
Member

@mikesposito mikesposito commented Jun 21, 2023

Explanation

This PR updates @metamask/eth-keyring-controller in KeyringController to ^13.
As after v11.0.0 the library has been migrated to TS there is a number of changes needed to support it.

  • Type guards have been added to mitigate some issues with the Keyring type used by @metamask/eth-keyring-controller, which is still not supported by the latest released versions of the HD and simple keyrings.
  • Keyring type from @metamask/utils has been added, superseding local type declarations

References

Changelog

@metamask/keyring-controller

  • BREAKING: Removed keyringTypes property from the KeyringController state
  • BREAKING: Constructor KeyringControllerOptions type changed
    • The KeyringControllerOptions.state accepted type is now { vault?: string }
    • The KeyringControllerOptions.keyringBuilders type is now { (): Keyring<Json>; type: string }[]
  • BREAKING: The address type accepted by the removeAccount method is now Hex
  • BREAKING: The signTypedMessage method now returns a Promise<string>
  • BREAKING: The signTransaction method now requires a TypedTransaction from @ethereumjs/tx@^4 for the transaction argument, and returns a Promise<TxData>
  • BREAKING: Rename Keyring type to KeyringObject
  • BREAKING: addNewAccount now throws if address of new account is not a hex string
  • BREAKING: exportSeedPhrase now throws if first keyring does not have a mnemonic
  • BREAKING: verifySeedPhrase now throws if HD keyring does not have a mnemonic
  • CHANGED: Update return type of getAccountKeyringType to Promise<string>
  • CHANGED: The private method addQRKeyring has been renamed to #addQRKeyring
  • CHANGED: Updated @metamask/eth-keyring-controller to ^13.0.0

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate

@socket-security
Copy link

socket-security bot commented Jun 21, 2023

Updated and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Packages Version New capabilities Transitives Size Publisher
@metamask/eth-json-rpc-middleware 11.0.0...11.0.1 None +0/-0 149 kB metamaskbot
jsonschema 1.2.4...1.4.1 None +0/-0 81.8 kB acubed
@types/node 16.18.24...20.4.2 None +0/-0 3.81 MB types
@types/jest-when 2.7.3...2.7.4 None +0/-0 5.87 kB types
nanoid 3.1.31...3.3.6 None +0/-0 21.7 kB ai
immer 9.0.6...9.0.21 None +0/-0 872 kB mweststrate
jest-when 3.4.2...3.5.2 None +27/-45 14 MB timkindberg
multiformats 9.5.2...9.9.0 None +0/-0 529 kB npm-service-account-multiformats

🚮 Removed packages: @metamask/[email protected], @metamask/[email protected], [email protected]

) {
const messageParamsClone = { ...messageParams };

if ((await this.getAccountKeyringType(address)) === KeyringTypes.qr) {
Copy link
Member Author

Choose a reason for hiding this comment

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

Starting from @metamask/[email protected] any attempt to add a Keyring of a type with a missing keyring builder throws an error instead of returning undefined.

@mikesposito
Copy link
Member Author

signPersonalMessageshould sign personal message even if empty data is passed
This test is currently failing with this error: Missing data parameter.

Seems like this behavior is changed in @metamask/eth-keyring-controller due to this line added. The data is being normalized too, using normalize function from @metamask/eth-sig-util, which returns undefined with an empty string,

@mikesposito
Copy link
Member Author

Update of @ethereumjs/tx, @ethereumjs/common, @keystonehq/metamask-airgapped-keyring and @metamask/utils has been moved to #1514

@mikesposito mikesposito force-pushed the chore/update-eth-keyring-controller branch 2 times, most recently from 95242fc to 13a2ec7 Compare July 17, 2023 14:43
@socket-security
Copy link

socket-security bot commented Jul 17, 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.

Ignoring: @sinonjs/[email protected], [email protected]

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of package-name@version specifiers. e.g. @SocketSecurity ignore [email protected] bar@* or ignore all packages with @SocketSecurity ignore-all

@mikesposito mikesposito marked this pull request as ready for review July 17, 2023 15:24
@mikesposito mikesposito requested a review from a team as a code owner July 17, 2023 15:24
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! Just spotted some typecasting and had some questions.

packages/keyring-controller/src/KeyringController.test.ts Outdated Show resolved Hide resolved
packages/keyring-controller/src/KeyringController.ts Outdated Show resolved Hide resolved
packages/keyring-controller/src/KeyringController.test.ts Outdated Show resolved Hide resolved
packages/keyring-controller/src/KeyringController.test.ts Outdated Show resolved Hide resolved
types/obs-store.d.ts Outdated Show resolved Hide resolved
@legobeat
Copy link
Contributor

@SocketSecurity ignore @sinonjs/[email protected]
@SocketSecurity ignore [email protected]

types/obs-store.d.ts Outdated Show resolved Hide resolved
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.

Looked over these changes and they make sense to me.

@mcmire
Copy link
Contributor

mcmire commented Jul 18, 2023

Would it be worth it to list these in the changelog as well?

  • BREAKING: Rename Keyring type to KeyringObject
  • BREAKING: addNewAccount now throws if address of new account is not a hex string
  • BREAKING: exportSeedPhrase now throws if first keyring does not have a mnemonic
  • BREAKING: verifySeedPhrase now throws if HD keyring does not have a mnemonic
  • CHANGED: Update return type of getAccountKeyringType to Promise<string>

Also you had listed that the setLocked method is now async, but it seems like that was already the case before, no?

@mikesposito mikesposito force-pushed the chore/update-eth-keyring-controller branch from 4ac5946 to 62e1617 Compare July 18, 2023 18:38
@mikesposito mikesposito merged commit 4eb66e5 into main Jul 18, 2023
@mikesposito mikesposito deleted the chore/update-eth-keyring-controller branch July 18, 2023 18:45
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* chore: update eth-keyring-controller

* fix: update airgapped keyring and fix deserialize issue

* refactor: leave better comment

* chore: use eth-keyring-controller v12

* refactor: use latest @metamask/utils

* chore: fix lint

* chore: yarn dedupe

* chore: add obs-store module declaration

* refactor: remove cacheEncryptionKey from default test parameters

* refactor: apply @mcmire suggestions

* refactor remove unnecessary typecast

* refactor: simplify keyring builders type

* refactor: remove qr assertion

* refactor: use @metamask/eth-keyring-controller v13

* refactor: remove obs-store module declaration

* refactor: remove unnecessary code

* refactor: addQRKeyring as hash function

* refactor: #addQRKeyring reorder with other prv methods

* refactor: apply @Gudahtt suggestions
MajorLift pushed a commit that referenced this pull request Oct 11, 2023
* chore: update eth-keyring-controller

* fix: update airgapped keyring and fix deserialize issue

* refactor: leave better comment

* chore: use eth-keyring-controller v12

* refactor: use latest @metamask/utils

* chore: fix lint

* chore: yarn dedupe

* chore: add obs-store module declaration

* refactor: remove cacheEncryptionKey from default test parameters

* refactor: apply @mcmire suggestions

* refactor remove unnecessary typecast

* refactor: simplify keyring builders type

* refactor: remove qr assertion

* refactor: use @metamask/eth-keyring-controller v13

* refactor: remove obs-store module declaration

* refactor: remove unnecessary code

* refactor: addQRKeyring as hash function

* refactor: #addQRKeyring reorder with other prv methods

* refactor: apply @Gudahtt suggestions
plasmacorral pushed a commit to MetaMask/metamask-mobile that referenced this pull request Jan 6, 2024
## **Description**


This PR bumps the `@metamask/keyring-controller` version from `6.0.0` to
`7.5.0`. These are the relevant changes to take into consideration
during review,

- **BREAKING**: Remove `keyringTypes` property from the
KeyringController state
([#1441](MetaMask/core#1441))
- **BREAKING**: Constructor `KeyringControllerOptions` type changed
([#1441](MetaMask/core#1441))
- The `KeyringControllerOptions.state` accepted type is now `{ vault?:
string }`
- The `KeyringControllerOptions.keyringBuilders` type is now `{ ():
Keyring<Json>; type: string }[]`
- **BREAKING**: The `address` type accepted by the `removeAccount`
method is now `Hex`
([#1441](MetaMask/core#1441))
- **BREAKING**: The `signTypedMessage` method now returns a
`Promise<string>` ([#1441](MetaMask/core#1441))
- **BREAKING**: The `signTransaction` method now requires a
`TypedTransaction` from `@ethereumjs/tx@^4` for the `transaction`
argument, and returns a `Promise<TxData>`
([#1441](MetaMask/core#1441))
- **BREAKING:** Rename `Keyring` type to `KeyringObject`
([#1441](MetaMask/core#1441))
- **BREAKING:** `addNewAccount` now throws if address of new account is
not a hex string ([#1441](MetaMask/core#1441))
- **BREAKING:** `exportSeedPhrase` now throws if first keyring does not
have a mnemonic ([#1441](MetaMask/core#1441))
- **BREAKING:** `verifySeedPhrase` now throws if HD keyring does not
have a mnemonic ([#1441](MetaMask/core#1441))
 

## **Related issues**

Fixes: #8180

## **Manual testing steps**

Use cases or flows to verify,

1. Onboarding
2. Import SRP
3. Import private key
4. Reveal SRP
5. Reveal private key
6. Add new account
7. Connect QR wallet
8. Signed type messages
9. Remove imported account
10. Lock and unlock wallet

## **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 Coding
Standards](https://github.com/MetaMask/metamask-mobile/blob/main/.github/guidelines/CODING_GUIDELINES.md).
- [ ] I've clearly explained what problem this PR is solving and how it
is solved.
- [ ] I've linked related issues
- [ ] I've included manual testing steps
- [ ] I've included screenshots/recordings if applicable
- [ ] 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.
- [ ] I’ve properly set the pull request status:
  - [ ] In case it's not yet "ready for review", I've set it to "draft".
- [ ] In case it's "ready for review", I've changed it from "draft" to
"non-draft".

## **Pre-merge reviewer checklist**

- [X ] I've manually tested the PR (e.g. pull and build branch, run the
app, test code being changed).
- [X ] 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants