Skip to content

Commit 01e9b64

Browse files
committed
feat: add cash account keyring based on hd-key-ring
1 parent 3c3001b commit 01e9b64

File tree

16 files changed

+483
-1
lines changed

16 files changed

+483
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ This repository contains the following packages [^fn1]:
1313
<!-- start package list -->
1414

1515
- [`@metamask/account-api`](packages/account-api)
16+
- [`@metamask/eth-cash-account-keyring`](packages/keyring-eth-cash-account)
1617
- [`@metamask/eth-hd-keyring`](packages/keyring-eth-hd)
1718
- [`@metamask/eth-ledger-bridge-keyring`](packages/keyring-eth-ledger-bridge)
1819
- [`@metamask/eth-qr-keyring`](packages/keyring-eth-qr)
@@ -40,6 +41,7 @@ linkStyle default opacity:0.5
4041
account_api(["@metamask/account-api"]);
4142
hw_wallet_sdk(["@metamask/hw-wallet-sdk"]);
4243
keyring_api(["@metamask/keyring-api"]);
44+
eth_cash_account_keyring(["@metamask/eth-cash-account-keyring"]);
4345
eth_hd_keyring(["@metamask/eth-hd-keyring"]);
4446
eth_ledger_bridge_keyring(["@metamask/eth-ledger-bridge-keyring"]);
4547
eth_qr_keyring(["@metamask/eth-qr-keyring"]);
@@ -54,6 +56,7 @@ linkStyle default opacity:0.5
5456
account_api --> keyring_api;
5557
account_api --> keyring_utils;
5658
keyring_api --> keyring_utils;
59+
eth_cash_account_keyring --> keyring_eth_hd;
5760
eth_hd_keyring --> keyring_api;
5861
eth_hd_keyring --> keyring_utils;
5962
eth_hd_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 `CashAccount` variant to `KeyringType` enum ([#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+
* A keyring for the cash account
49+
*/
50+
CashAccount = 'cash-account',
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.CashAccount);
2526
expectAssignable<KeyringType>(KeyringType.PrivateKey);
2627
expectAssignable<KeyringType>(KeyringType.Qr);
2728
expectAssignable<KeyringType>(KeyringType.Snap);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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 `CashAccountKeyring` class extending `HdKeyring` from `@metamask/eth-hd-keyring` ([#472](https://github.com/MetaMask/accounts/pull/472))
13+
- Uses keyring type `Cash Account Keyring`
14+
- Uses derivation path `m/44'/4392018'/0'/0`
15+
16+
[Unreleased]: https://github.com/MetaMask/accounts/
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+
# Cash Account Keyring
2+
3+
An Ethereum keyring that extends [`@metamask/eth-hd-keyring`](../keyring-eth-hd) with a distinct keyring type and derivation path for cash accounts.
4+
5+
Cash 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-cash-account-keyring`
10+
11+
or
12+
13+
`npm install @metamask/eth-cash-account-keyring`
14+
15+
## Usage
16+
17+
```ts
18+
import { CashAccountKeyring } from '@metamask/eth-cash-account-keyring';
19+
20+
const keyring = new CashAccountKeyring();
21+
```
22+
23+
The `CashAccountKeyring` 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 v3](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-cash-account-keyring",
3+
"version": "1.0.0",
4+
"description": "A cash 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-cash-account-keyring",
40+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/eth-cash-account-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)