Skip to content

feat: trezor error management#471

Open
montelaidev wants to merge 16 commits intomainfrom
feat/mul-1444
Open

feat: trezor error management#471
montelaidev wants to merge 16 commits intomainfrom
feat/mul-1444

Conversation

@montelaidev
Copy link
Contributor

@montelaidev montelaidev commented Mar 9, 2026

This PR updates the trezor keyring to use the hardware error management

Examples


Note

Medium Risk
Medium risk because it refactors Trezor signing/unlock error paths to throw typed HardwareWalletErrors, which can change error types/messages surfaced to clients and affect hardware-wallet UX flows.

Overview
Standardizes Trezor error handling across the monorepo. The Trezor keyring now depends on @metamask/hw-wallet-sdk and converts bridge/transport failures in unlock, signTransaction, signPersonalMessage, and signTypedData into typed HardwareWalletErrors via a new handleTrezorTransportError helper, while preserving address-mismatch validation as plain Errors.

Adds reusable static TREZOR_ERROR_MAPPINGS to hw-wallet-sdk (with tests) and new Trezor error utilities/exports in eth-trezor-keyring, plus expanded test coverage and updated Jest coverage thresholds/build references to reflect the new modules.

Written by Cursor Bugbot for commit e069e4c. This will update automatically on new commits. Configure here.

@montelaidev
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link

github-actions bot commented Mar 9, 2026

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "1.0.0-543b4a0",
  "@metamask-previews/hw-wallet-sdk": "0.5.0-543b4a0",
  "@metamask-previews/keyring-api": "21.5.0-543b4a0",
  "@metamask-previews/eth-hd-keyring": "13.1.0-543b4a0",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.3.0-543b4a0",
  "@metamask-previews/eth-qr-keyring": "1.1.0-543b4a0",
  "@metamask-previews/eth-simple-keyring": "11.0.0-543b4a0",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-543b4a0",
  "@metamask-previews/keyring-internal-api": "10.0.0-543b4a0",
  "@metamask-previews/keyring-internal-snap-client": "9.0.0-543b4a0",
  "@metamask-previews/eth-snap-keyring": "19.0.0-543b4a0",
  "@metamask-previews/keyring-snap-client": "8.2.0-543b4a0",
  "@metamask-previews/keyring-snap-sdk": "7.2.1-543b4a0",
  "@metamask-previews/keyring-utils": "3.2.0-543b4a0"
}

@montelaidev montelaidev marked this pull request as ready for review March 11, 2026 15:02
@montelaidev montelaidev requested a review from a team as a code owner March 11, 2026 15:02
@montelaidev montelaidev requested a review from ccharly March 18, 2026 08:45
@montelaidev
Copy link
Contributor Author

@metamaskbot publish-preview

@github-actions
Copy link

Preview builds have been published. See these instructions (from the core monorepo) for more information about preview builds.

Expand for full list of packages and versions.
{
  "@metamask-previews/account-api": "1.0.0-6511fbf",
  "@metamask-previews/hw-wallet-sdk": "0.5.0-6511fbf",
  "@metamask-previews/keyring-api": "21.5.0-6511fbf",
  "@metamask-previews/eth-hd-keyring": "13.1.0-6511fbf",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.3.0-6511fbf",
  "@metamask-previews/eth-qr-keyring": "1.1.0-6511fbf",
  "@metamask-previews/eth-simple-keyring": "11.0.0-6511fbf",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-6511fbf",
  "@metamask-previews/keyring-internal-api": "10.0.0-6511fbf",
  "@metamask-previews/keyring-internal-snap-client": "9.0.0-6511fbf",
  "@metamask-previews/eth-snap-keyring": "19.0.0-6511fbf",
  "@metamask-previews/keyring-snap-client": "8.2.0-6511fbf",
  "@metamask-previews/keyring-snap-sdk": "7.2.1-6511fbf",
  "@metamask-previews/keyring-utils": "3.2.0-6511fbf"
}

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

return handleTrezorTransportError(
error,
'Failed to sign typed data with Trezor device',
);
Copy link

Choose a reason for hiding this comment

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

Broad try-catch wraps non-hardware errors as HardwareWalletError

Medium Severity

In signTypedData, the try-catch block wraps transformTypedData() which throws local validation errors (e.g., "Only version 4 of typed data signing is supported"). Previously this call was outside any try-catch, so validation errors propagated as plain Error instances. Now they're caught and converted to HardwareWalletError with ErrorCode.Unknown, incorrectly classifying software validation errors as hardware wallet errors. Consumers distinguishing error types may be affected.

Fix in Cursor Fix in Web

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.

2 participants