Skip to content

fix: 29044 Add keyring error mappings for typed v3 signing#575

Merged
dawnseeker8 merged 4 commits into
mainfrom
fix/29044-ledger-v3-typed-data-error
Jul 2, 2026
Merged

fix: 29044 Add keyring error mappings for typed v3 signing#575
dawnseeker8 merged 4 commits into
mainfrom
fix/29044-ledger-v3-typed-data-error

Conversation

@dawnseeker8

@dawnseeker8 dawnseeker8 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Keyring-level typed data version validation and error handling:

  • Added KEYRING_ERROR_MAPPINGS in @metamask/hw-wallet-sdk, mapping DeviceStateOnlyV4Supported to a clear error message and user message for unsupported typed data versions. [1] [2]
  • Implemented createKeyringStateError factory in errors.ts to generate a HardwareWalletError using the new mapping, with a fallback for unknown errors.
  • Updated LedgerKeyring.signTypedData to throw a HardwareWalletError with DeviceStateOnlyV4Supported when a non-V4 typed data version is requested.
  • Added and enhanced tests for the new error handling in both errors.test.ts and ledger-keyring.test.ts, ensuring correct error types and messages are thrown and mapped. [1] [2]
  • Updated changelogs in both hw-wallet-sdk and keyring-eth-ledger-bridge packages 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 by ErrorCode.

@metamask/hw-wallet-sdk adds KEYRING_ERROR_MAPPINGS for keyring-level validation, starting with DeviceStateOnlyV4Supported (message + user-facing copy). @metamask/eth-ledger-bridge-keyring adds createKeyringStateError, which builds a HardwareWalletError from those mappings (with a fallback for unknown codes), and LedgerKeyring.signTypedData throws that when the version is not V4 or is omitted. Tests now assert code / message on 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.

- 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.
@dawnseeker8 dawnseeker8 marked this pull request as ready for review June 24, 2026 08:41
@dawnseeker8 dawnseeker8 requested a review from a team as a code owner June 24, 2026 08:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread packages/keyring-eth-ledger-bridge/src/errors.ts
- 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.
@dawnseeker8

Copy link
Copy Markdown
Contributor Author

@metamaskbot publish-preview

@github-actions

Copy link
Copy Markdown

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.4-6bf9188",
  "@metamask-previews/hw-wallet-sdk": "0.8.0-6bf9188",
  "@metamask-previews/keyring-api": "23.3.0-6bf9188",
  "@metamask-previews/eth-hd-keyring": "14.1.1-6bf9188",
  "@metamask-previews/eth-ledger-bridge-keyring": "12.2.0-6bf9188",
  "@metamask-previews/eth-money-keyring": "3.0.0-6bf9188",
  "@metamask-previews/eth-qr-keyring": "2.1.0-6bf9188",
  "@metamask-previews/eth-simple-keyring": "12.0.2-6bf9188",
  "@metamask-previews/eth-trezor-keyring": "10.1.0-6bf9188",
  "@metamask-previews/keyring-internal-api": "11.0.1-6bf9188",
  "@metamask-previews/keyring-internal-snap-client": "10.0.3-6bf9188",
  "@metamask-previews/keyring-sdk": "2.2.0-6bf9188",
  "@metamask-previews/eth-snap-keyring": "22.3.0-6bf9188",
  "@metamask-previews/keyring-snap-client": "9.0.2-6bf9188",
  "@metamask-previews/keyring-snap-sdk": "9.0.2-6bf9188",
  "@metamask-previews/keyring-utils": "3.3.1-6bf9188"
}

Comment thread packages/keyring-eth-ledger-bridge/src/ledger-keyring.test.ts Outdated
Comment thread packages/keyring-eth-ledger-bridge/src/ledger-keyring.test.ts Outdated
Comment thread packages/hw-wallet-sdk/src/hardware-error-mappings.ts
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>
@dawnseeker8 dawnseeker8 requested a review from montelaidev June 26, 2026 10:18
montelaidev
montelaidev previously approved these changes Jul 2, 2026
@dawnseeker8 dawnseeker8 enabled auto-merge July 2, 2026 10:55
@dawnseeker8

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

auto-merge was automatically disabled July 2, 2026 10:57

Head branch was pushed to by a user without write access

Copilot AI commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Resolved. The only conflict was in packages/keyring-eth-ledger-bridge/CHANGELOG.md — merged both the Changed (keyring-api bump from #583) and our Fixed entries under [Unreleased].

@dawnseeker8 dawnseeker8 added this pull request to the merge queue Jul 2, 2026
Merged via the queue into main with commit 6d2e7d2 Jul 2, 2026
40 checks passed
@dawnseeker8 dawnseeker8 deleted the fix/29044-ledger-v3-typed-data-error branch July 2, 2026 11:29
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.

[Bug]: [Ledger] Uninformative error message appears when signing V3 typed data with ledger

3 participants