-
Notifications
You must be signed in to change notification settings - Fork 5k
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
Conversation
1daedb7
to
eb0766e
Compare
--- 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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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
eb0766e
to
11d653e
Compare
Quality Gate passedIssues Measures |
Codecov ReportAll modified and coverable lines are covered by tests ✅
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. |
Builds ready [11d653e]
Page Load Metrics (1634 ± 84 ms)
Bundle size diffs [🚨 Warning! Bundle size has increased!]
|
There was a problem hiding this 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
There was a problem hiding this 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!
There was a problem hiding this 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:
There was a problem hiding this comment.
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();
}
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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 usedthis.settings
rather thanthis._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.
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