fix: 29044 Add keyring error mappings for typed v3 signing#575
Conversation
- Introduced `KEYRING_ERROR_MAPPINGS` for handling `DeviceStateOnlyV4Supported` errors in the keyring. - Updated tests to validate the new error mappings and ensure proper error handling in `signTypedData` method. - Changelog entries added for both `hw-wallet-sdk` and `keyring-eth-ledger-bridge` to reflect these changes.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9249cab6d5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- Updated `CHANGELOG.md` for `hw-wallet-sdk` and `keyring-eth-ledger-bridge` to reflect the addition of `KEYRING_ERROR_MAPPINGS` and the corresponding error handling for `DeviceStateOnlyV4Supported`. - Linked the changes to pull request #575 for reference.
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions (from the Expand for full list of packages and versions. |
Use expect().rejects.toMatchObject() instead of try/catch, and add a TODO to extend DeviceStateOnlyV4Supported to Trezor and QR keyrings. Co-authored-by: Cursor <cursoragent@cursor.com>
|
@copilot resolve the merge conflicts in this pull request |
Head branch was pushed to by a user without write access
Resolved. The only conflict was in |
Keyring-level typed data version validation and error handling:
KEYRING_ERROR_MAPPINGSin@metamask/hw-wallet-sdk, mappingDeviceStateOnlyV4Supportedto a clear error message and user message for unsupported typed data versions. [1] [2]createKeyringStateErrorfactory inerrors.tsto generate aHardwareWalletErrorusing the new mapping, with a fallback for unknown errors.LedgerKeyring.signTypedDatato throw aHardwareWalletErrorwithDeviceStateOnlyV4Supportedwhen a non-V4 typed data version is requested.errors.test.tsandledger-keyring.test.ts, ensuring correct error types and messages are thrown and mapped. [1] [2]hw-wallet-sdkandkeyring-eth-ledger-bridgepackages to reflect the new error and validation behavior. [1] [2]Fixes MetaMask/metamask-mobile#29044
Examples
Note
Low Risk
Localized error-type change on an existing validation path; no signing logic or transport behavior changes beyond error shape.
Overview
Ledger typed data version errors now use the shared hardware wallet error model instead of a generic
Error, so clients (e.g. mobile) can detect unsupported EIP-712 versions byErrorCode.@metamask/hw-wallet-sdkaddsKEYRING_ERROR_MAPPINGSfor keyring-level validation, starting withDeviceStateOnlyV4Supported(message + user-facing copy).@metamask/eth-ledger-bridge-keyringaddscreateKeyringStateError, which builds aHardwareWalletErrorfrom those mappings (with a fallback for unknown codes), andLedgerKeyring.signTypedDatathrows that when the version is not V4 or is omitted. Tests now assertcode/messageon the thrown error; changelogs note the behavior in both packages.A TODO in the SDK still calls out wiring the same pattern into Trezor and QR keyrings later.
Reviewed by Cursor Bugbot for commit 272c0ec. Bugbot is set up for automated code reviews on this repo. Configure here.