Skip to content

chore: update @trezor/connect-web to v9.2.2#23763

Merged
danjm merged 29 commits intodevelopfrom
update-trezor-connect-web-9.2.0
May 22, 2024
Merged

chore: update @trezor/connect-web to v9.2.2#23763
danjm merged 29 commits intodevelopfrom
update-trezor-connect-web-9.2.0

Conversation

@danjm
Copy link
Copy Markdown
Contributor

@danjm danjm commented Mar 27, 2024

Description

The user experience for trezor connection on mv2 is this:

  1. Click through the hardware wallet connect screen for trezor
  2. Trezor popup tab opens
  3. User can connect the trezor device without having to install other software

Before this PR, on mv3, the flow was:

  1. Click through the hardware wallet connect screen for trezor
  2. Trezor popup tab opens
  3. User has to install the trezor bridge
  4. Once installed, the user can connect their trezor device to MetaMask

The solution to the problem required two parts.

First, we needed the connect-web module (called TrezorConnectSDK in the offscreen trezor file) to specify the env variable communicated to the trezor connect iframe and popup to be "webextension" and not just "web". This is because the iframe/popup code assumes that if the iframe origin does not match the origin of popup (e.g. metamask vs connect.trezor.io), and if environment is not "webextension", then webusb cannot be available: https://github.com/trezor/trezor-suite/blob/bb2e075024c8d8316fa016b7b20a0421b1a1f7d0/packages/connect-iframe/src/connectSettings.ts#L74-L84.

In theory, this could be set when the trezor module is initialized, but if the env is set to "webextension" in the connect-web code, then it attempts to open the popup via chrome apis that are not available in the offscreen document. So the solution is a patch which just tells the iframe and the popup that the environment is "webextension", while leave the environment setting within the trezor code that runs in the offscreen context as "web".

With that fix in place, there was another problem of metamask being able to connect to the webusb device and the popup being able to read that connection (or vice-versa). If the requestDevice call happens from the popup, then the webusb permission will be granted to the trezor.io origin, and metamask is unable to communicate with those devices. However, if the requestDevice call happens from metamask, then the devices can be communicated from metamask to the popup, and metamask (in particular the offscreen document) can communicate directly with the devices. Specifically, this code https://github.com/trezor/trezor-suite/blob/bb2e075024c8d8316fa016b7b20a0421b1a1f7d0/packages/transport/src/api/usb.ts#L98, when run within the offscreen document, returns null when requestDevice was called from the trezor popup, but returns a correctly populated array if requestDevice was called from MetaMask. To fix this, we can call requestDevice explicitly within the MetaMask ui flow, instead of having the trezor popup call it for us

Finally, and independent of the above two fixes, this PR updates trezor connect packages, which was necessary to get trezor working properly with Snow.

Open in GitHub Codespaces

Related issues

Fixes:

Manual testing steps

  1. Build this branch with yarn start:mv3
  2. Go through the regular trezor connect flow
  3. Trezor should connect and sign as normal

Screenshots/Recordings

trezorworking.mp4

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • 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 format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). 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.

@github-actions
Copy link
Copy Markdown
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
Copy Markdown

socket-security bot commented Mar 27, 2024

👍 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: npm/@babel/code-frame@7.10.4, npm/@expo/config-plugins@7.9.2, npm/@expo/config-types@50.0.1, npm/@expo/config@8.5.6, npm/@expo/fingerprint@0.6.1, npm/@expo/json-file@8.3.3, npm/@expo/plist@0.1.3, npm/@expo/sdk-runtime-versions@1.0.0, npm/@expo/spawn-async@1.7.2, npm/@react-native/normalize-color@2.1.0, npm/@trezor/analytics@1.0.16, npm/@trezor/blockchain-link-types@1.0.15, npm/@trezor/blockchain-link-utils@1.0.16, npm/@trezor/blockchain-link@2.1.28, npm/@trezor/connect-analytics@1.0.14, npm/@trezor/connect-common@0.0.31, npm/@trezor/connect-web@9.2.2, npm/@trezor/connect@9.2.2, npm/@trezor/env-utils@1.0.15, npm/@trezor/protobuf@1.0.11, npm/@trezor/protocol@1.0.7, npm/@trezor/schema-utils@1.0.3, npm/@trezor/transport@1.1.27, npm/@trezor/type-utils@1.0.5, npm/@trezor/utils@9.0.23, npm/@trezor/utxo-lib@2.0.8, npm/@types/lodash@4.14.184, npm/@types/node@20.12.7, npm/@types/web@0.0.138, npm/@xmldom/xmldom@0.7.13, npm/@xmldom/xmldom@0.8.10, npm/bplist-creator@0.1.1, npm/bplist-parser@0.3.2, npm/buffer@5.6.0, npm/commander@4.1.1, npm/expo-constants@15.4.5, npm/getenv@1.0.0, npm/glob@7.1.6, npm/lines-and-columns@1.1.6, npm/mz@2.7.0, npm/nan@2.15.0, npm/plist@3.1.0, npm/protobufjs@7.2.6, npm/ripple-address-codec@4.2.3, npm/ripple-binary-codec@1.3.0, npm/ripple-keypairs@1.1.3, npm/semver@7.5.3, npm/simple-plist@1.4.0, npm/slugify@1.6.6, npm/socks@2.8.1, npm/stream-buffers@2.2.0, npm/sucrase@3.34.0, npm/thenify-all@1.6.0, npm/thenify@3.3.1, npm/ts-interface-checker@0.1.13, npm/usb@2.12.0, npm/uuid@7.0.3, npm/ws@8.16.0, npm/xcode@3.0.1, npm/xml2js@0.6.0, npm/xmlbuilder@11.0.1, npm/xmlbuilder@14.0.0, npm/xmlbuilder@15.1.1

View full report↗︎

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 ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

@danjm danjm force-pushed the update-trezor-connect-web-9.2.0 branch from 75f4066 to a4523b6 Compare April 19, 2024 19:30
@davidmurdoch davidmurdoch changed the title Update trezor connect-web to 9.2.0 chore: update @trezor/connect-web to v9.2.2 Apr 22, 2024
@danjm danjm force-pushed the update-trezor-connect-web-9.2.0 branch from 01fb099 to 50fcea0 Compare April 25, 2024 17:15
@danjm
Copy link
Copy Markdown
Contributor Author

danjm commented Apr 25, 2024

@metamaskbot update-policies

@danjm danjm marked this pull request as ready for review April 25, 2024 17:15
@danjm danjm requested review from a team and kumavis as code owners April 25, 2024 17:15
@metamaskbot
Copy link
Copy Markdown
Collaborator

Policies updated

brad-decker
brad-decker previously approved these changes Apr 25, 2024
@davidmurdoch davidmurdoch added the team-extension-platform Extension Platform team label Apr 26, 2024
@DDDDDanica DDDDDanica force-pushed the update-trezor-connect-web-9.2.0 branch from cbff18b to 88abc4b Compare May 3, 2024 16:56
@danjm danjm requested a review from a team as a code owner May 20, 2024 14:05

it('Connects to a Hardware wallet for trezor', async function () {
it('Connects to a Hardware wallet for lattice', async function () {
if (process.env.ENABLE_MV3) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like this replaces the existing test for Trezor with a test for GridPlus Lattice. Is there a reason to not keep testing for the Trezor-connect case?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The trezor connect case now requires the user to interact with a browser pop-up before going to the trezor connect screen, and we are unable to do that from the e2e test. However, this e2e test never tested any specific trezor functionality, and just the behaviour of the first steps of the hardware wallet connect flow, which were essentially the same for gridplus and trezor

Co-authored-by: legobeat <109787230+legobeat@users.noreply.github.com>
@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [abfcc55]
Page Load Metrics (1169 ± 590 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint721631002813
domContentLoaded9401684
load59277811691228590
domInteractive9401684
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 32.82 KiB (0.98%)
  • ui: 575 Bytes (0.01%)
  • common: 141.73 KiB (2.30%)

@codecov
Copy link
Copy Markdown

codecov bot commented May 21, 2024

Codecov Report

Attention: Patch coverage is 33.33333% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 67.42%. Comparing base (0d1dc5e) to head (e167e9a).
Report is 1 commits behind head on develop.

Files Patch % Lines
...create-account/connect-hardware/select-hardware.js 33.33% 6 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #23763      +/-   ##
===========================================
- Coverage    67.43%   67.42%   -0.01%     
===========================================
  Files         1290     1290              
  Lines        50308    50316       +8     
  Branches     13034    13037       +3     
===========================================
+ Hits         33922    33924       +2     
- Misses       16386    16392       +6     

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

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [1e820a7]
Page Load Metrics (633 ± 468 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint57205873115
domContentLoaded8129192612
load452443633974468
domInteractive8129192612
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 32.82 KiB (0.98%)
  • ui: 575 Bytes (0.01%)
  • common: 141.73 KiB (2.30%)

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [650dc3d]
Page Load Metrics (1390 ± 584 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint64143982512
domContentLoaded94915115
load51321313901216584
domInteractive94915115
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 32.82 KiB (0.97%)
  • ui: 575 Bytes (0.01%)
  • common: 141.73 KiB (2.30%)

DDDDDanica
DDDDDanica previously approved these changes May 22, 2024
@DDDDDanica
Copy link
Copy Markdown
Contributor

The implementation looks good to me. Approved ~

@metamaskbot
Copy link
Copy Markdown
Collaborator

Builds ready [e167e9a]
Page Load Metrics (506 ± 422 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint60178923216
domContentLoaded96216147
load492441506878422
domInteractive96216147
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 32.82 KiB (0.95%)
  • ui: 575 Bytes (0.01%)
  • common: 141.73 KiB (2.30%)

@danjm
Copy link
Copy Markdown
Contributor Author

danjm commented May 22, 2024

@SocketSecurity ignore-all

All of the dependencies that socket security is warning us about are dependencies of trezor, but not of them are used in our applications code

@danjm danjm merged commit 7fd377c into develop May 22, 2024
@danjm danjm deleted the update-trezor-connect-web-9.2.0 branch May 22, 2024 17:14
@github-actions github-actions bot locked and limited conversation to collaborators May 22, 2024
@metamaskbot metamaskbot added release-11.16.6 Issue or pull request that will be included in release 11.16.6 and removed release-11.18.0 labels Jun 4, 2024
@metamaskbot
Copy link
Copy Markdown
Collaborator

Missing release label release-11.16.6 on PR. Adding release label release-11.16.6 on PR and removing other release labels(release-11.18.0), as PR was cherry-picked in branch 11.16.6.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-11.16.6 Issue or pull request that will be included in release 11.16.6 team-extension-platform Extension Platform team

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

7 participants