Skip to content

fix: add dynamic nft and erc20 check#506

Merged
montelaidev merged 9 commits intomainfrom
fix/mul-1593
Apr 10, 2026
Merged

fix: add dynamic nft and erc20 check#506
montelaidev merged 9 commits intomainfrom
fix/mul-1593

Conversation

@montelaidev
Copy link
Copy Markdown
Contributor

@montelaidev montelaidev commented Apr 10, 2026

This PR replaces hardcoded erc20: true / nft: true flags in the Ledger mobile bridge's clearSignTransaction call with dynamic detection based on the transaction's 4-byte calldata selector. A new getTransactionSelector utility parses serialized transaction hex (both legacy RLP and EIP-2718 typed transactions) to extract the selector, which is then checked against NFT_ONLY_SELECTORS (ERC-721/ERC-1155) and ERC20_WRITE_SELECTORS (EIP-20 transfer, transferFrom, approve) constant sets to set the appropriate flags.

  • Dynamic NFT and ERC20 clear-signing flags for Ledger mobile bridge — instead of unconditionally passing erc20: true and nft: true to clearSignTransaction, the bridge now inspects the 4-byte
    calldata selector and sets these flags only when the transaction matches the corresponding contract standard.
  • Adds getTransactionSelector utility to extract the function selector from serialized transaction hex (supports legacy RLP and EIP-2718 typed transactions).
  • Adds NFT_ONLY_SELECTORS (ERC-721/ERC-1155) and ERC20_WRITE_SELECTORS (EIP-20 transfer, transferFrom, approve) constant sets.

Note

Medium Risk
Changes how Ledger mobile transaction signing sets erc20/nft clear-signing flags based on parsed calldata selectors, which can affect which Ledger signing flows are enabled. Includes new selector parsing and updated dependencies/tests, but is scoped and well-covered.

Overview
Derives Ledger mobile clearSignTransaction options dynamically by parsing the serialized transaction to extract the 4-byte calldata selector and enabling erc20/nft clear-signing only when it matches known ERC-20 write selectors or NFT-only selectors.

Adds getTransactionSelector plus exported selector sets (NFT_ONLY_SELECTORS, ERC20_WRITE_SELECTORS) with new unit coverage, updates the mobile bridge tests to assert the new behavior, and bumps ethereum-cryptography (and lockfile) to ^2.2.1.

Reviewed by Cursor Bugbot for commit 51e56bb. Bugbot is set up for automated code reviews on this repo. Configure here.

@montelaidev montelaidev requested a review from a team as a code owner April 10, 2026 08:22
@montelaidev
Copy link
Copy Markdown
Contributor Author

montelaidev commented Apr 10, 2026

@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.1-c26e419",
  "@metamask-previews/hw-wallet-sdk": "0.8.0-c26e419",
  "@metamask-previews/keyring-api": "22.0.0-c26e419",
  "@metamask-previews/eth-hd-keyring": "13.1.0-c26e419",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.3.0-c26e419",
  "@metamask-previews/eth-money-keyring": "2.0.0-c26e419",
  "@metamask-previews/eth-qr-keyring": "1.1.0-c26e419",
  "@metamask-previews/eth-simple-keyring": "11.1.1-c26e419",
  "@metamask-previews/eth-trezor-keyring": "9.1.0-c26e419",
  "@metamask-previews/keyring-internal-api": "10.0.1-c26e419",
  "@metamask-previews/keyring-internal-snap-client": "9.0.1-c26e419",
  "@metamask-previews/keyring-sdk": "1.1.0-c26e419",
  "@metamask-previews/eth-snap-keyring": "20.0.0-c26e419",
  "@metamask-previews/keyring-snap-client": "8.2.1-c26e419",
  "@metamask-previews/keyring-snap-sdk": "8.0.0-c26e419",
  "@metamask-previews/keyring-utils": "3.2.0-c26e419"
}

Copy link
Copy Markdown

@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.

Reviewed by Cursor Bugbot for commit 1fa71bd. Configure here.

Comment thread packages/keyring-eth-ledger-bridge/src/constants.ts
Comment thread packages/keyring-eth-ledger-bridge/src/utils.ts Outdated
Comment thread packages/keyring-eth-ledger-bridge/src/utils.ts Outdated
Comment thread packages/keyring-eth-ledger-bridge/CHANGELOG.md Outdated
Co-authored-by: Charly Chevalier <charlyy.chevalier@gmail.com>
@montelaidev montelaidev enabled auto-merge April 10, 2026 10:45
ccharly and others added 5 commits April 10, 2026 21:35
Similar implementation than `KeyringClient` but using the new unified
keyring API (keyring v2) methods.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Introduces a parallel v2 JSON-RPC surface (including `exportAccount`)
across API, clients, and snap dispatch logic; mistakes could break RPC
compatibility or unintentionally affect account export/request routing.
> 
> **Overview**
> **Adds keyring v2 RPC support end-to-end.** `@metamask/keyring-api`
now exports `KeyringRpcV2Method` plus superstruct-validated v2
request/response types and `isKeyringRpcV2Method`, and refines
`isKeyringRpcMethod` to be a type predicate.
> 
> **Introduces v2 client and dispatcher.**
`@metamask/keyring-snap-client` adds `KeyringClientV2` (UUID ids, strict
response masking) and `@metamask/keyring-internal-snap-client` adds
`KeyringInternalSnapClientV2` (Messenger-backed).
`@metamask/keyring-snap-sdk` adds `handleKeyringRequestV2` to validate
and route v2 JSON-RPC calls, including guarding optional
`exportAccount`. Tests and package exports/changelogs are updated
accordingly.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
cc83c17. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->

---------

Co-authored-by: Mathieu Artu <mathieu.artu@gmail.com>
This is the release candidate for version 99.0.0. See the changelogs for
more details.

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Medium Risk**
> Primarily a release/version bump, but it upgrades
`@metamask/keyring-sdk` to `1.2.0` across multiple keyrings, which may
change generated account IDs (now deterministic for EVM addresses) for
downstream consumers.
>
> **Overview**
> **Release 99.0.0**: bumps the monorepo version and publishes patch
releases for several keyring packages (HD, Ledger Bridge, Trezor,
Simple), updating their changelogs accordingly.
>
> Updates keyring dependencies to `@metamask/keyring-sdk@^1.2.0` (and
bumps `@metamask/eth-hd-keyring` in `@metamask/eth-money-keyring`), with
`yarn.lock` refreshed to match.
>
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
2a58933. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@montelaidev montelaidev added this pull request to the merge queue Apr 10, 2026
Merged via the queue into main with commit edde744 Apr 10, 2026
39 checks passed
@montelaidev montelaidev deleted the fix/mul-1593 branch April 10, 2026 14:48
@montelaidev montelaidev mentioned this pull request Apr 13, 2026
github-merge-queue Bot pushed a commit that referenced this pull request Apr 13, 2026
<!--
Thanks for your contribution! Take a moment to answer these questions so
that reviewers have the information they need to properly understand
your changes:

* What is the current state of things and why does it need to change?
* What is the solution your changes offer and how does it work?

Are there any issues or other links reviewers should consult to
understand this pull request better? For instance:

* Fixes #12345
* See: #67890
-->

This PR releases a new minor verson for
`@metamask/eth-ledger-bridge-keyring`

### Added

- Add `getTransactionSelector` to read the 4-byte calldata selector from
serialized transaction hex (legacy and typed txs)
([#506](#506))
- Ledger mobile bridge passes `nft: true` to `clearSignTransaction` when
that selector is NFT-only (ERC-721 / ERC-1155).
- Add `ERC20_WRITE_SELECTORS` for the three EIP-20 write functions
(`transfer`, `transferFrom`, `approve`)
([#506](#506))

## Examples

<!--
Are there any examples of this change being used in another repository?

When considering changes to the MetaMask module template, it's strongly
preferred that the change be experimented with in another repository
first. This gives reviewers a better sense of how the change works,
making it less likely the change will need to be reverted or adjusted
later.
-->

<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> **Low Risk**
> Low risk: this PR only updates package versions and publishes
changelog entries/compare links; no runtime code changes are included in
the diff.
> 
> **Overview**
> Bumps the monorepo version to `100.0.0` and releases
`@metamask/eth-ledger-bridge-keyring` as `11.4.0`.
> 
> Updates `keyring-eth-ledger-bridge`’s `CHANGELOG.md` with the `11.4.0`
release notes and adjusts the *Unreleased* compare links accordingly.
> 
> <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit
408cee7. Bugbot is set up for automated
code reviews on this repo. Configure
[here](https://www.cursor.com/dashboard/bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants