Skip to content

Commit a806bb5

Browse files
authored
feat(keyring-eth-money): add money account keyring based on hd-key-ring (#472)
<!-- 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 --> Implements a new keyring to support [MUSD-386](https://consensyssoftware.atlassian.net/browse/MUSD-386) ## 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] > **Medium Risk** > Introduces a new keyring package and extends the public `KeyringType` enum, which may affect downstream consumers and account derivation behavior if integrated incorrectly. > > **Overview** > Adds a new `@metamask/eth-money-keyring` package that extends `@metamask/eth-hd-keyring` with a dedicated type (`"Money Keyring"`), a fixed derivation path (`m/44'/4392018'/0'/0`), and enforced single-account behavior (overridden `deserialize`/`addAccounts`). > > Updates `@metamask/keyring-api` to include `KeyringType.Money` (plus type-level tests and changelog), and wires the new package into repo tooling/docs (README module list/graph, root `tsconfig.build.json`, PR-title scope allowlist, and `yarn.lock`). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 62f41a9. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 3c3001b commit a806bb5

File tree

17 files changed

+468
-1
lines changed

17 files changed

+468
-1
lines changed

.github/workflows/validate-pr-title.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jobs:
4343
deps-dev
4444
keyring-api
4545
keyring-eth-hd
46+
keyring-eth-money
4647
keyring-eth-ledger-bridge
4748
keyring-eth-simple
4849
keyring-eth-trezor

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ This repository contains the following packages [^fn1]:
1515
- [`@metamask/account-api`](packages/account-api)
1616
- [`@metamask/eth-hd-keyring`](packages/keyring-eth-hd)
1717
- [`@metamask/eth-ledger-bridge-keyring`](packages/keyring-eth-ledger-bridge)
18+
- [`@metamask/eth-money-keyring`](packages/keyring-eth-money)
1819
- [`@metamask/eth-qr-keyring`](packages/keyring-eth-qr)
1920
- [`@metamask/eth-simple-keyring`](packages/keyring-eth-simple)
2021
- [`@metamask/eth-snap-keyring`](packages/keyring-snap-bridge)
@@ -42,6 +43,7 @@ linkStyle default opacity:0.5
4243
keyring_api(["@metamask/keyring-api"]);
4344
eth_hd_keyring(["@metamask/eth-hd-keyring"]);
4445
eth_ledger_bridge_keyring(["@metamask/eth-ledger-bridge-keyring"]);
46+
eth_money_keyring(["@metamask/eth-money-keyring"]);
4547
eth_qr_keyring(["@metamask/eth-qr-keyring"]);
4648
eth_simple_keyring(["@metamask/eth-simple-keyring"]);
4749
eth_trezor_keyring(["@metamask/eth-trezor-keyring"]);
@@ -61,6 +63,7 @@ linkStyle default opacity:0.5
6163
eth_ledger_bridge_keyring --> keyring_api;
6264
eth_ledger_bridge_keyring --> keyring_utils;
6365
eth_ledger_bridge_keyring --> account_api;
66+
eth_money_keyring --> keyring_eth_hd;
6467
eth_qr_keyring --> keyring_api;
6568
eth_qr_keyring --> keyring_utils;
6669
eth_qr_keyring --> account_api;

packages/keyring-api/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
- Add `KeyringType.Money` variant ([#472](https://github.com/MetaMask/accounts/pull/472))
1213
- Add optional `details` field to `Transaction` type ([#445](https://github.com/MetaMask/accounts/pull/445))
1314
- Add `SecurityAlertResponse` enum with values: `benign`, `warning`, `malicious`
1415
- Add optional `origin` field (string) to track transaction request source

packages/keyring-api/src/api/v2/keyring-type.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ export enum KeyringType {
4343
* Represents keyring backed by a OneKey hardware wallet.
4444
*/
4545
OneKey = 'onekey',
46+
47+
/**
48+
* Represents keyring for money accounts.
49+
*/
50+
Money = 'money',
4651
}

packages/keyring-api/src/api/v2/keyring.test-d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import type { ImportPrivateKeyFormat } from './private-key';
2222

2323
// Test KeyringType enum
2424
expectAssignable<KeyringType>(KeyringType.Hd);
25+
expectAssignable<KeyringType>(KeyringType.Money);
2526
expectAssignable<KeyringType>(KeyringType.PrivateKey);
2627
expectAssignable<KeyringType>(KeyringType.Qr);
2728
expectAssignable<KeyringType>(KeyringType.Snap);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7+
8+
## [Unreleased]
9+
10+
### Added
11+
12+
- Add initial implementation of `MoneyKeyring` ([#472](https://github.com/MetaMask/accounts/pull/472))
13+
- Extends `HdKeyring` from `@metamask/eth-hd-keyring`.
14+
- Uses keyring type `"Money Keyring"`.
15+
- Uses derivation path `"m/44'/4392018'/0'/0"`.
16+
17+
[Unreleased]: https://github.com/MetaMask/accounts/

packages/keyring-eth-money/LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
ISC License
2+
3+
Copyright (c) 2020 MetaMask
4+
5+
Permission to use, copy, modify, and/or distribute this software for any
6+
purpose with or without fee is hereby granted, provided that the above
7+
copyright notice and this permission notice appear in all copies.
8+
9+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Money Keyring
2+
3+
An Ethereum keyring that extends [`@metamask/eth-hd-keyring`](../keyring-eth-hd) with a distinct keyring type and derivation path for money accounts.
4+
5+
Money accounts use a separate HD derivation path to keep funds isolated from the primary HD keyring, while reusing the same seed phrase and signing infrastructure.
6+
7+
## Installation
8+
9+
`yarn add @metamask/eth-money-keyring`
10+
11+
or
12+
13+
`npm install @metamask/eth-money-keyring`
14+
15+
## Usage
16+
17+
```ts
18+
import { MoneyKeyring } from '@metamask/eth-money-keyring';
19+
20+
const keyring = new MoneyKeyring();
21+
```
22+
23+
The `MoneyKeyring` class implements the same `Keyring` interface as `HdKeyring` — see the [HD Keyring README](../keyring-eth-hd/README.md) for full API documentation.
24+
25+
## Contributing
26+
27+
### Setup
28+
29+
- Install [Node.js](https://nodejs.org) version 18
30+
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
31+
- Install [Yarn v4](https://yarnpkg.com/getting-started/install)
32+
- Run `yarn install` to install dependencies and run any required post-install scripts
33+
34+
### Testing and Linting
35+
36+
Run `yarn test` to run the tests once.
37+
38+
Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* For a detailed explanation regarding each configuration property and type check, visit:
3+
* https://jestjs.io/docs/configuration
4+
*/
5+
6+
const merge = require('deepmerge');
7+
const path = require('path');
8+
9+
const baseConfig = require('../../jest.config.packages');
10+
11+
const displayName = path.basename(__dirname);
12+
13+
module.exports = merge(baseConfig, {
14+
// The display name when running multiple projects
15+
displayName,
16+
17+
// The glob patterns Jest uses to detect test files
18+
testMatch: ['**/*.test.[jt]s?(x)'],
19+
});
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"name": "@metamask/eth-money-keyring",
3+
"version": "0.0.0",
4+
"description": "A money account keyring that extends the HD keyring with a different keyring type and derivation path.",
5+
"keywords": [
6+
"ethereum",
7+
"keyring"
8+
],
9+
"homepage": "https://github.com/MetaMask/accounts#readme",
10+
"bugs": {
11+
"url": "https://github.com/MetaMask/accounts/issues"
12+
},
13+
"repository": {
14+
"type": "git",
15+
"url": "https://github.com/MetaMask/accounts.git"
16+
},
17+
"license": "ISC",
18+
"exports": {
19+
".": {
20+
"import": {
21+
"types": "./dist/index.d.mts",
22+
"default": "./dist/index.mjs"
23+
},
24+
"require": {
25+
"types": "./dist/index.d.cts",
26+
"default": "./dist/index.cjs"
27+
}
28+
}
29+
},
30+
"main": "./dist/index.cjs",
31+
"types": "./dist/index.d.cts",
32+
"files": [
33+
"dist/"
34+
],
35+
"scripts": {
36+
"build": "ts-bridge --project tsconfig.build.json --no-references",
37+
"build:clean": "yarn build --clean",
38+
"build:docs": "typedoc",
39+
"changelog:update": "../../scripts/update-changelog.sh @metamask/eth-money-keyring",
40+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-money-keyring",
41+
"publish:preview": "yarn npm publish --tag preview",
42+
"test": "jest",
43+
"test:clean": "jest --clearCache"
44+
},
45+
"dependencies": {
46+
"@metamask/eth-hd-keyring": "workspace:^"
47+
},
48+
"devDependencies": {
49+
"@lavamoat/allow-scripts": "^3.2.1",
50+
"@lavamoat/preinstall-always-fail": "^2.1.0",
51+
"@metamask/auto-changelog": "^3.4.4",
52+
"@metamask/eth-sig-util": "^8.2.0",
53+
"@metamask/utils": "^11.1.0",
54+
"@ts-bridge/cli": "^0.6.3",
55+
"@types/jest": "^29.5.12",
56+
"deepmerge": "^4.2.2",
57+
"jest": "^29.5.0"
58+
},
59+
"engines": {
60+
"node": "^18.18 || >=20"
61+
},
62+
"publishConfig": {
63+
"access": "public",
64+
"registry": "https://registry.npmjs.org/"
65+
},
66+
"lavamoat": {
67+
"allowScripts": {
68+
"@lavamoat/preinstall-always-fail": false
69+
}
70+
}
71+
}

0 commit comments

Comments
 (0)