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

chore: update Trezor Connect to v9.4.0, remove workarounds #26749

Closed
wants to merge 4 commits into from

Conversation

martykan
Copy link
Contributor

@martykan martykan commented Aug 29, 2024

Description

With MV3, MetaMask started to use Trezor Connect inside an offscreen environment, in a way that was previously unsupported and required a workaround by patching the Trezor Connect library.

In recent versions of Trezor Connect, the library can handle working in an offscreen environment correctly, without the need for the workaround, which could cause issues with compatibility.

This PR removes the patch and updates the Trezor Connect library to the latest version (v9.4.0).
The change in manifest.json is due to new URL parameters, Firefox needs the asterisk at the end to match the URL with them.
I haven't removed the WebUSB device request which was added on MetaMask's side in relation to the workaround, since it can improve UX of the pairing process, but it could be removed if desired.

The dependency update affects Lavamoat, I am including the policy changes in my commit, however let me know if you would like me to remove them and handle them using your own process.

Open in GitHub Codespaces

Related issues

NA

Manual testing steps

  1. Open accounts dropdown, "Add hardware wallet"
  2. Select Trezor
  3. Follow prompts to connect the device
  4. See a list of accounts from the Trezor

Screenshots/Recordings

NA

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.

Copy link

socket-security bot commented Aug 29, 2024

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

Package New capabilities Transitives Size Publisher
npm/@babel/generator@7.25.5 None 0 489 kB nicolo-ribaudo
npm/@babel/helper-annotate-as-pure@7.24.7 None 0 52.4 kB nicolo-ribaudo
npm/@babel/helper-create-class-features-plugin@7.25.4 None 0 506 kB nicolo-ribaudo
npm/@babel/helper-plugin-utils@7.24.8 None 0 114 kB nicolo-ribaudo
npm/@babel/helper-replace-supers@7.25.0 None 0 106 kB nicolo-ribaudo
npm/@babel/helper-skip-transparent-expression-wrappers@7.24.7 None 0 58.5 kB nicolo-ribaudo
npm/@babel/parser@7.25.4 None 0 1.89 MB nicolo-ribaudo
npm/@babel/plugin-syntax-jsx@7.24.7 None 0 70 kB nicolo-ribaudo
npm/@babel/plugin-syntax-typescript@7.25.4 None 0 69.7 kB existentialism, hzoo, jlhwung, ...1 more
npm/@babel/plugin-transform-modules-commonjs@7.24.8 None 0 107 kB nicolo-ribaudo
npm/@babel/plugin-transform-typescript@7.25.2 None 0 200 kB nicolo-ribaudo
npm/@babel/preset-typescript@7.24.7 None 0 90.8 kB nicolo-ribaudo
npm/@babel/runtime@7.25.4 None 0 248 kB nicolo-ribaudo
npm/@babel/traverse@7.25.4 None 0 728 kB nicolo-ribaudo
npm/@babel/types@7.25.4 environment 0 2.48 MB nicolo-ribaudo
npm/@emurgo/cardano-serialization-lib-browser@11.5.0 eval 0 3.35 MB lisicky_emurgo
npm/@emurgo/cardano-serialization-lib-nodejs@11.5.0 eval, filesystem 0 3.35 MB lisicky_emurgo
npm/@fivebinaries/coin-selection@2.2.1 None 0 149 kB slowbackspace
npm/@mobily/ts-belt@3.13.1 None 0 381 kB mobily
npm/@sinclair/typebox@0.31.28 None 0 536 kB sinclair
npm/@solana/buffer-layout@4.0.1 None 0 197 kB steveluscher
npm/@solana/web3.js@1.95.3 network 0 10.9 MB lorisleiva
npm/@trezor/analytics@1.2.0 network 0 14 kB trezor-ci
npm/@trezor/blockchain-link-types@1.2.0 None 0 56.3 kB trezor-ci
npm/@trezor/blockchain-link-utils@1.2.0 network 0 58.4 kB trezor-ci
npm/@trezor/blockchain-link@2.3.0 None 0 213 kB trezor-ci
npm/@trezor/connect-analytics@1.2.0 environment 0 5.41 kB trezor-ci
npm/@trezor/connect-common@0.2.0 None 0 180 kB trezor-ci
npm/@trezor/connect-web@9.4.0 None 0 93.8 kB trezor-ci
npm/@trezor/connect@9.4.0 filesystem 0 1.41 MB trezor-ci
npm/@trezor/env-utils@1.2.0 environment 0 17.7 kB trezor-ci
npm/@trezor/protobuf@1.2.0 None 0 1.09 MB trezor-ci
npm/@trezor/protocol@1.2.0 None 0 11.8 kB trezor-ci
npm/@trezor/schema-utils@1.2.0 None 0 38.7 kB trezor-ci
npm/@trezor/transport@1.3.0 network 0 165 kB trezor-ci
npm/@trezor/type-utils@1.1.0 None 0 2.89 kB trezor-ci
npm/@trezor/utils@9.2.0 None 0 64.2 kB trezor-ci
npm/@trezor/utxo-lib@2.2.0 None 0 234 kB trezor-ci
npm/@types/w3c-web-usb@1.0.10 None 0 8.92 kB types
npm/@types/web@0.0.138 None 0 1.36 MB types
npm/agentkeepalive@4.5.0 network 0 43.7 kB fengmk2
npm/bchaddrjs@0.5.2 None 0 1.56 MB ealmansi
npm/big-integer@1.6.36 None 0 164 kB peterolson
npm/bigint-buffer@1.1.5 None 0 55.7 kB no2chem
npm/bip66@1.1.5 None 0 7.79 kB dcousens
npm/bitcoin-ops@1.4.1 None 0 4.38 kB dcousens
npm/blake-hash@2.0.0 None 0 410 kB fanatid
npm/borsh@0.7.0 None 0 34.6 kB volovyk-s
npm/cashaddrjs@0.4.4 None 0 110 kB ealmansi
npm/commander@2.20.3 filesystem, shell 0 62.4 kB abetomo
npm/delay@5.0.0 None 0 11.2 kB sindresorhus
npm/es6-promise@4.2.8 None 0 315 kB stefanpenner
npm/es6-promisify@5.0.0 None 0 7.76 kB digitaldesignlabs
npm/eyes@0.1.8 None 0 14 kB indexzero
npm/fast-stable-stringify@1.0.0 None 0 125 kB nickyout
npm/humanize-ms@1.2.1 None 0 3.66 kB dead_horse
npm/int64-buffer@1.0.1 None 0 22.2 kB kawanet
npm/jayson@4.1.1 network 0 162 kB tedeh
npm/jsonschema@1.2.2 None 0 75.6 kB tdegrunt
npm/nan@2.15.0 None 0 422 kB kkoopa
npm/pushdata-bitcoin@1.0.1 None 0 4.28 kB dcousens
npm/ripple-address-codec@4.2.3 None 0 47.4 kB jst5000
npm/ripple-binary-codec@1.3.0 None 0 1.1 MB jst5000
npm/ripple-keypairs@1.1.3 None 0 24.4 kB jst5000
npm/ripple-lib-transactionparser@0.8.2 None 0 147 kB intelliot
npm/ripple-lib@1.10.1 network 0 4.9 MB intelliot
npm/text-encoding-utf-8@1.0.2 None 0 79.4 kB arv
npm/tiny-secp256k1@1.1.6 None 0 1.1 MB junderw
npm/typeforce@1.18.0 None 0 19.1 kB dcousens
npm/ua-parser-js@1.0.37 None 0 112 kB faisalman
npm/usb@2.12.0 None 0 6.9 MB thegecko
npm/varuint-bitcoin@1.1.2 None 0 5.49 kB junderw
npm/wif@4.0.0 None 0 4.67 kB junderw
npm/ws@8.18.0 environment, network 0 147 kB lpinca

🚮 Removed packages: npm/@babel/generator@7.24.10, npm/@babel/helper-annotate-as-pure@7.22.5, npm/@babel/helper-create-class-features-plugin@7.24.5, npm/@babel/helper-module-imports@7.24.3, npm/@babel/helper-module-transforms@7.24.5, npm/@babel/helper-plugin-utils@7.24.5, npm/@babel/helper-replace-supers@7.24.1, npm/@babel/helper-simple-access@7.24.5, npm/@babel/helper-skip-transparent-expression-wrappers@7.22.5, npm/@babel/helper-validator-option@7.23.5, npm/@babel/parser@7.24.8, npm/@babel/plugin-syntax-jsx@7.24.1, npm/@babel/plugin-syntax-typescript@7.24.1, npm/@babel/plugin-transform-modules-commonjs@7.24.1, npm/@babel/plugin-transform-typescript@7.24.5, npm/@babel/preset-typescript@7.24.1, npm/@babel/runtime@7.24.8, npm/@babel/template@7.24.7, npm/@babel/traverse@7.24.8, npm/@babel/types@7.24.9, npm/@sinclair/typebox@0.27.8, npm/big-integer@1.6.52, npm/commander@7.2.0, npm/globals@13.24.0, npm/jsesc@0.5.0, npm/jsonschema@1.2.4, npm/ws@8.17.1

View full report↗︎

Copy link

socket-security bot commented Aug 29, 2024

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Native code npm/tiny-secp256k1@1.1.6 🚫
Install scripts npm/tiny-secp256k1@1.1.6
  • Install script: install
  • Source: npm run build || echo "secp256k1 bindings compilation fail. Pure JS implementation will be used."
⚠︎
New author npm/varuint-bitcoin@1.1.2 🚫
New author npm/@solana/buffer-layout@4.0.1 🚫
Network access npm/agentkeepalive@4.5.0 🚫
Network access npm/agentkeepalive@4.5.0 🚫
Native code npm/bigint-buffer@1.1.5 🚫
Install scripts npm/bigint-buffer@1.1.5
  • Install script: install
  • Source: npm run rebuild || echo "Couldn't build bindings. Non-native version used."
⚠︎
Deprecated npm/ripple-lib@1.10.1
  • Reason: ripple-lib is deprecated. Please migrate to xrpl.js using this migration guide: https://xrpl.org/xrpljs2-migration-guide.html
⚠︎
Network access npm/ripple-lib@1.10.1 🚫
Network access npm/ripple-lib@1.10.1 🚫
Native code npm/blake-hash@2.0.0 🚫
New author npm/wif@4.0.0 🚫
Native code npm/usb@2.12.0 🚫
Network access npm/jayson@4.1.1 🚫
Network access npm/jayson@4.1.1 🚫
Network access npm/jayson@4.1.1 🚫
Network access npm/jayson@4.1.1 🚫
Network access npm/@solana/web3.js@1.95.3 🚫
Network access npm/@solana/web3.js@1.95.3 🚫
Network access npm/@solana/web3.js@1.95.3 🚫
Network access npm/@trezor/transport@1.3.0 🚫
Network access npm/@trezor/blockchain-link-utils@1.2.0 🚫
Network access npm/@trezor/analytics@1.2.0 🚫

View full report↗︎

Next steps

What's wrong with native code?

Contains native code which could be a vector to obscure malicious code, and generally decrease the likelihood of reproducible or reliable installs.

Ensure that native code bindings are expected. Consumers may consider pure JS and functionally similar alternatives to avoid the challenges and risks associated with native code bindings.

What is an install script?

Install scripts are run when the package is installed. The majority of malware in npm is hidden in install scripts.

Packages should not be running non-essential scripts during install and there are often solutions to problems people solve with install scripts that can be run at publish time instead.

What is new author?

A new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.

Scrutinize new collaborator additions to packages because they now have the ability to publish code into your dependency tree. Packages should avoid frequent or unnecessary additions or changes to publishing rights.

What is network access?

This module accesses the network.

Packages should remove all network access that is functionally unnecessary. Consumers should audit network access to ensure legitimate use.

What is a deprecated package?

The maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.

Research the state of the package and determine if there are non-deprecated versions that can be used, or if it should be replaced with a new, supported solution.

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

  • @SocketSecurity ignore npm/tiny-secp256k1@1.1.6
  • @SocketSecurity ignore npm/varuint-bitcoin@1.1.2
  • @SocketSecurity ignore npm/@solana/buffer-layout@4.0.1
  • @SocketSecurity ignore npm/agentkeepalive@4.5.0
  • @SocketSecurity ignore npm/bigint-buffer@1.1.5
  • @SocketSecurity ignore npm/ripple-lib@1.10.1
  • @SocketSecurity ignore npm/blake-hash@2.0.0
  • @SocketSecurity ignore npm/wif@4.0.0
  • @SocketSecurity ignore npm/usb@2.12.0
  • @SocketSecurity ignore npm/jayson@4.1.1
  • @SocketSecurity ignore npm/@solana/web3.js@1.95.3
  • @SocketSecurity ignore npm/@trezor/transport@1.3.0
  • @SocketSecurity ignore npm/@trezor/blockchain-link-utils@1.2.0
  • @SocketSecurity ignore npm/@trezor/analytics@1.2.0

@martykan martykan force-pushed the chore/update-trezor-9-4-0 branch 2 times, most recently from 7646897 to ffae4cf Compare August 29, 2024 13:57
@martykan martykan marked this pull request as ready for review August 29, 2024 14:31
@martykan martykan requested review from a team as code owners August 29, 2024 14:31
@chloeYue
Copy link
Contributor

chloeYue commented Sep 6, 2024

Test OK for Trezor connection on this PR branch:

Screen.Recording.2024-09-06.at.23.42.29.mov

vthomas13
vthomas13 previously approved these changes Sep 9, 2024
Copy link
Contributor

@vthomas13 vthomas13 left a comment

Choose a reason for hiding this comment

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

Tested on 12.0.6. Works great! Thanks a lot @martykan

Copy link

codecov bot commented Sep 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.08%. Comparing base (f354888) to head (ffae4cf).
Report is 171 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #26749   +/-   ##
========================================
  Coverage    70.08%   70.08%           
========================================
  Files         1414     1414           
  Lines        49328    49330    +2     
  Branches     13781    13781           
========================================
+ Hits         34568    34570    +2     
  Misses       14760    14760           

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

@vthomas13
Copy link
Contributor

Hey @martykan I noticed there are some merge conflicts. If any support is needed with updating, feel free to reach out here.

@martykan
Copy link
Contributor Author

Yeah, probably due to #26882.
I will rebase on latest develop.

@martykan martykan marked this pull request as ready for review September 10, 2024 13:21
@martykan
Copy link
Contributor Author

Ok, I've updated it. There seem to be some failing checks, I don't think I can affect those.

@vthomas13
Copy link
Contributor

vthomas13 commented Sep 16, 2024

Hey @martykan, we are working to get this reviewed internally as a workaround to a CI step that is failing for external contributors. Really appreciate your patience on this!

@gauthierpetetin gauthierpetetin requested a review from a team September 30, 2024 15:59
github-merge-queue bot pushed a commit that referenced this pull request Oct 11, 2024
This PR includes changes from PR #26749 by @martykan.
<!--
Please submit this PR as a draft initially.
Do not mark it as "Ready for review" until the template has been
completely filled out, and PR status checks have passed at least once.
-->

## **Description**

> With MV3, MetaMask started to use Trezor Connect inside an offscreen
environment, in a way that was previously unsupported and required a
workaround by patching the Trezor Connect library.
> 
> In recent versions of Trezor Connect, the library can handle working
in an offscreen environment correctly, without the need for the
workaround, which could cause issues with compatibility.
> 
> This PR removes the patch and updates the Trezor Connect library to
the latest version (v9.4.0).
> The change in manifest.json is due to new URL parameters, Firefox
needs the asterisk at the end to match the URL with them.
> I haven't removed the WebUSB device request which was added on
MetaMask's side in relation to the workaround, since it can improve UX
of the pairing process, but it could be removed if desired.
> 
> The dependency update affects Lavamoat, I am including the policy
changes in my commit, however let me know if you would like me to remove
them and handle them using your own process.

[![Open in GitHub
Codespaces](https://github.com/codespaces/badge.svg)](https://codespaces.new/MetaMask/metamask-extension/pull/27112?quickstart=1)

## **Related issues**

Fixes:

## **Manual testing steps**

> 1. Open accounts dropdown, "Add hardware wallet"
> 2. Select Trezor
> 3. Follow prompts to connect the device
> 4. See a list of accounts from the Trezor

## **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**

- [x ] I've followed [MetaMask Contributor
Docs](https://github.com/MetaMask/contributor-docs) and [MetaMask
Extension Coding
Standards](https://github.com/MetaMask/metamask-extension/blob/develop/.github/guidelines/CODING_GUIDELINES.md).
- [x ] 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-extension/blob/develop/.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.
@danjm
Copy link
Contributor

danjm commented Oct 15, 2024

Thanks again for the contribution! This PR was re-opened as #27112 to workaround some issues we are currently having with CI and forks, and that PR has been closed.

@danjm danjm closed this Oct 15, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Oct 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants