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

fix: Fix Trezor signing and connecting #26882

Merged
merged 1 commit into from
Sep 4, 2024
Merged

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Sep 4, 2024

Description

Trezor signing and connecting was broken in a recent change that included an update to the @trezor/connect-web library (in #26143). The patch had to be rewritten as part of that update, but in this rewrite an underscore was missed in referencing a variable (the patch used this.settings rather than this._settings).

Additionally, two more changes have been applied to ensure the modified settings are used everywhere. One was present in the original patch but missing from the patch in #26143. The other was not present in the original patch (#23763) because the affected line was added in the library update, but it seems equally necessary.

Open in GitHub Codespaces

Related issues

Fixes #26875

Manual testing steps

Follow reproduction steps in #26875

Screenshots/Recordings

Before

See https://www.loom.com/share/3e1f3d2cc57247a5b02e0ff8d61babb8?sid=1b17e423-16cf-4260-a1ed-674441e25b3a

After:

Screen.Recording.2024-09-03.at.21.55.10.mov

(I stopped partway through connecting, I was already past the point of it crashing by then).

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.

--- a/lib/impl/core-in-iframe.js
+++ b/lib/impl/core-in-iframe.js
@@ -116,7 +116,9 @@ class CoreInIframe {
this._log.enabled = !!this._settings.debug;
window.addEventListener('message', this.boundHandleMessage);
window.addEventListener('unload', this.boundDispose);
- await iframe.init(this._settings);
+ const modifiedSettings = Object.assign({}, this.settings);
Copy link
Member Author

Choose a reason for hiding this comment

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

This is where the underscore was missing

- await this.init(this._settings);
+ var modifiedSettings = Object.assign({}, this._settings);
+ modifiedSettings.env = 'webextension';
+ await this.init(modifiedSettings);
Copy link
Member Author

Choose a reason for hiding this comment

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

The same settings object is referenced here, so we'd want to use the same modifications. This was present in the original patch

+ var modifiedSettings = Object.assign({}, this.settings);
+ modifiedSettings.env = 'webextension';
this.channel.postMessage({
type: events_2.POPUP.INIT,
Copy link
Member Author

@Gudahtt Gudahtt Sep 4, 2024

Choose a reason for hiding this comment

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

This second call to events_2.POPUP.INIT was not present in v9.2.2, but it is present here in v9.3.0

See:
9.2.2: https://npmfs.com/package/@trezor/connect-web/9.2.2/lib/popup/index.js
9.3.0: https://npmfs.com/package/@trezor/connect-web/9.3.0/lib/popup/index.js

Trezor signing and connecting was broken in a recent change that
included an update to the `@trezor/connect-web` library (in #26143).
The patch had to be rewritten as part of that update, but in this
rewrite an underscore was missed in referencing a variable (the patch
used `this.settings` rather than `this._settings`).

Additionally, two more changes have been applied to ensure the modified
settings are used everywhere. One was present in the original patch but
missing from the patch in #26143. The other was not present in the
original patch (#23763) because the affected line was added in the
library update, but it seems equally necessary.

Fixes #26875
Copy link

sonarcloud bot commented Sep 4, 2024

@Gudahtt Gudahtt marked this pull request as ready for review September 4, 2024 00:29
@Gudahtt Gudahtt requested a review from a team as a code owner September 4, 2024 00:29
Copy link

codecov bot commented Sep 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 70.15%. Comparing base (1801174) to head (11d653e).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop   #26882   +/-   ##
========================================
  Coverage    70.15%   70.15%           
========================================
  Files         1425     1425           
  Lines        49600    49600           
  Branches     13877    13877           
========================================
  Hits         34795    34795           
  Misses       14805    14805           

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

@metamaskbot
Copy link
Collaborator

Builds ready [11d653e]
Page Load Metrics (1634 ± 84 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint20921861572354170
domContentLoaded14332061161115273
load14412201163417584
domInteractive147434178
Bundle size diffs [🚨 Warning! Bundle size has increased!]
  • background: 0 Bytes (0.00%)
  • ui: 0 Bytes (0.00%)
  • common: 84 Bytes (0.00%)

Copy link
Contributor

@danjm danjm left a comment

Choose a reason for hiding this comment

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

Approved. I have reviewed all code and manually tested both connecting trezor and signing+sending a transaction with trezor

Copy link
Member

@mikesposito mikesposito 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, and it works!

Copy link
Contributor

@MajorLift MajorLift left a comment

Choose a reason for hiding this comment

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

LGTM and successfully tested connecting trezor. Thanks for fixing this so quickly @Gudahtt! Just had one question:

Copy link
Contributor

Choose a reason for hiding this comment

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

Are we not using modifiedSettings in this branch both here and in the original patch because we want a longer request timeout for handshake events?

@@ -240,7 +241,7 @@ class PopupManager extends events_1.default {
         else if (message.type === events_2.POPUP.CORE_LOADED) {
+            var modifiedSettings = Object.assign({}, this.settings, { env: 'webextension' });
             this.channel.postMessage({
                 type: events_2.POPUP.HANDSHAKE,
-                payload: { settings: this.settings },
+                payload: { settings: modifiedSettings },
             });
             (_a = this.handshakePromise) === null || _a === void 0 ? void 0 : _a.resolve();
         }

Copy link
Member Author

Choose a reason for hiding this comment

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

Great question. Maybe we should be using it here as well

Copy link
Member Author

Choose a reason for hiding this comment

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

I'll merge this for now, but this is worth following up on

@Gudahtt Gudahtt merged commit 97e0030 into develop Sep 4, 2024
81 checks passed
@Gudahtt Gudahtt deleted the fix-trezor-connections branch September 4, 2024 11:15
@github-actions github-actions bot locked and limited conversation to collaborators Sep 4, 2024
@metamaskbot metamaskbot added the release-12.6.0 Issue or pull request that will be included in release 12.6.0 label Sep 4, 2024
@gauthierpetetin gauthierpetetin added release-12.5.0 Issue or pull request that will be included in release 12.5.0 and removed release-12.6.0 Issue or pull request that will be included in release 12.6.0 labels Sep 11, 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.

[Bug]: Unable to add or sign Trezor account in v12.1.1
6 participants