Skip to content

feat(keyring-eth-cash): add cash account keyring based on hd-key-ring#472

Open
Jwhiles wants to merge 12 commits intomainfrom
create-cash-account-keyring
Open

feat(keyring-eth-cash): add cash account keyring based on hd-key-ring#472
Jwhiles wants to merge 12 commits intomainfrom
create-cash-account-keyring

Conversation

@Jwhiles
Copy link

@Jwhiles Jwhiles commented Mar 9, 2026

Implements a new keyring to support MUSD-386

Examples


Note

Medium Risk
Introduces a new public KeyringType.Cash enum value and a new keyring package that derives/signs accounts on a different path; downstream consumers with exhaustive handling of keyring types or assumptions about HD derivation may need updates.

Overview
Adds cash account support by introducing a new @metamask/eth-cash-keyring package that extends @metamask/eth-hd-keyring with a distinct type ("Cash Keyring"), fixed derivation path (m/44'/4392018'/0'/0), and single-account behavior.

Updates the public API to include KeyringType.Cash (with type-level coverage in keyring.test-d.ts), and wires the new package into repo tooling/docs (PR title validation scope, root README module list/dependency graph, TS project references, and yarn.lock).

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

@Jwhiles Jwhiles force-pushed the create-cash-account-keyring branch 5 times, most recently from 5f50434 to ca5f3e9 Compare March 9, 2026 19:10
@Jwhiles Jwhiles force-pushed the create-cash-account-keyring branch from ca5f3e9 to 01e9b64 Compare March 9, 2026 19:19
@danroc
Copy link
Contributor

danroc commented Mar 10, 2026

Should we remove the ability to add accounts directly? We could override addAccounts to only allow 1 account to be added.

Yes, if this is what the product expects, we should enforce it. Otherwise, we might mistakenly create more than one account and end up dealing with this kind of hard-to-solve bug.

@danroc
Copy link
Contributor

danroc commented Mar 10, 2026

Calling it Cash Account for a keyring is a bit confusing because it overlaps with the concept of account. Using just Cash might be clearer.

WDYT @gantunesr, @ccharly ?


- Install [Node.js](https://nodejs.org) version 18
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
- Install [Yarn v3](https://yarnpkg.com/getting-started/install)
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure this is up-to-date (to be checked @ccharly)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, we use v4 now. That does not change much anyway 😄 but if you could change that too, that'd be nice!

} from '@metamask/eth-hd-keyring';

const hdPathString = `m/44'/4392018'/0'/0`;
const type = 'Cash Account Keyring';
Copy link
Contributor

Choose a reason for hiding this comment

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

I would also export it just in case and maybe rename it to CASH_ACCOUNT_KEYRING_TYPE.

That could allow us to re-inject this constant value in some other enums (like the one in @metamask/keyring-controller (KeyringTypes).

@ccharly
Copy link
Contributor

ccharly commented Mar 10, 2026

Calling it Cash Account for a keyring is a bit confusing because it overlaps with the concept of account. Using just Cash might be clearer.

WDYT @gantunesr, @ccharly ?

I think you're right yep!

@Jwhiles Jwhiles force-pushed the create-cash-account-keyring branch from 81d726d to fe35f69 Compare March 10, 2026 10:25
@Jwhiles Jwhiles changed the title feat: add cash account keyring based on hd-key-ring feat(keyring-cash): add cash account keyring based on hd-key-ring Mar 10, 2026
@Jwhiles Jwhiles force-pushed the create-cash-account-keyring branch from 5395223 to b26b341 Compare March 10, 2026 10:52
@Jwhiles Jwhiles marked this pull request as ready for review March 10, 2026 11:35
@Jwhiles Jwhiles requested a review from a team as a code owner March 10, 2026 11:35
@Jwhiles Jwhiles requested review from ccharly and danroc March 10, 2026 11:35
account_api --> keyring_api;
account_api --> keyring_utils;
keyring_api --> keyring_utils;
eth_cash_keyring --> keyring_eth_hd;
Copy link

Choose a reason for hiding this comment

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

Mermaid diagram references wrong node variable name

Medium Severity

The new dependency edge eth_cash_keyring --> keyring_eth_hd references an undefined Mermaid node keyring_eth_hd. The correct variable name is eth_hd_keyring, as defined on line 45 and used consistently on lines 60–62. Mermaid will auto-create a separate orphan node instead of linking to the actual @metamask/eth-hd-keyring node, causing the dependency graph to render incorrectly.

Fix in Cursor Fix in Web

export const CASH_DERIVATION_PATH = `m/44'/4392018'/0'/0`;
const type = 'Cash Keyring';

export class CashKeyring extends HdKeyring {
Copy link
Member

Choose a reason for hiding this comment

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

Double checking if this keyring should support removeAccount

Copy link
Author

Choose a reason for hiding this comment

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

I don't know if we need it. But having it shouldn't cause an issue, right?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think so. Depending on designs, account is going to be largely hidden in the client anyway, so removing it wouldn't really serve any purpose

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 3 potential issues.

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

@Jwhiles Jwhiles changed the title feat(keyring-cash): add cash account keyring based on hd-key-ring feat(keyring-eth-cash): add cash account keyring based on hd-key-ring Mar 10, 2026
@Jwhiles Jwhiles requested a review from gantunesr March 10, 2026 15:20
@Jwhiles
Copy link
Author

Jwhiles commented Mar 10, 2026

@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-25e4b24",
  "@metamask-previews/hw-wallet-sdk": "0.5.0-25e4b24",
  "@metamask-previews/keyring-api": "21.5.0-25e4b24",
  "@metamask-previews/eth-cash-keyring": "0.0.0-25e4b24",
  "@metamask-previews/eth-hd-keyring": "13.1.0-25e4b24",
  "@metamask-previews/eth-ledger-bridge-keyring": "11.3.0-25e4b24",
  "@metamask-previews/eth-qr-keyring": "1.1.0-25e4b24",
  "@metamask-previews/eth-simple-keyring": "11.0.0-25e4b24",
  "@metamask-previews/eth-trezor-keyring": "9.0.0-25e4b24",
  "@metamask-previews/keyring-internal-api": "10.0.0-25e4b24",
  "@metamask-previews/keyring-internal-snap-client": "9.0.0-25e4b24",
  "@metamask-previews/eth-snap-keyring": "19.0.0-25e4b24",
  "@metamask-previews/keyring-snap-client": "8.2.0-25e4b24",
  "@metamask-previews/keyring-snap-sdk": "7.2.1-25e4b24",
  "@metamask-previews/keyring-utils": "3.2.0-25e4b24"
}

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.

5 participants