Skip to content

Commit 8ee27ec

Browse files
committed
Merge remote-tracking branch 'origin/main' into feat/onekey-keyring
2 parents 8b4abfc + 4f87ecc commit 8ee27ec

File tree

123 files changed

+8849
-695
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

123 files changed

+8849
-695
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
style
4040
test
4141
scopes: |
42+
deps
4243
keyring-api
4344
keyring-eth-hd
4445
keyring-eth-ledger-bridge

.syncpackrc

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,35 @@
1212
"semverGroups": [
1313
{
1414
"label": "use tilde range for some dependencies",
15-
"dependencies": ["eslint-plugin-import", "typescript"],
15+
"dependencies": [
16+
"eslint-plugin-import",
17+
"typescript"
18+
],
1619
"range": "~"
1720
},
1821
{
1922
"label": "use exact versions for some dependencies",
20-
"dependencies": ["yarn"],
23+
"dependencies": [
24+
"yarn"
25+
],
2126
"range": ""
2227
},
2328
{
2429
"label": "use caret ranges everywhere else",
25-
"dependencies": ["**"],
30+
"dependencies": [
31+
"**"
32+
],
2633
"range": "^"
2734
}
2835
],
2936
"versionGroups": [
3037
{
3138
"label": "use workspace version of packages in the monorepo",
32-
"dependencyTypes": ["!local"],
39+
"dependencyTypes": [
40+
"!local"
41+
],
3342
"dependencies": [
43+
"@metamask/account-**",
3444
"@metamask/keyring-**",
3545
"@metamask/eth-**-keyring"
3646
],

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,15 @@ linkStyle default opacity:0.5
5454
account_api --> keyring_api;
5555
account_api --> keyring_utils;
5656
keyring_api --> keyring_utils;
57+
eth_hd_keyring --> keyring_api;
5758
eth_hd_keyring --> keyring_utils;
59+
eth_hd_keyring --> account_api;
60+
eth_ledger_bridge_keyring --> keyring_api;
5861
eth_ledger_bridge_keyring --> keyring_utils;
5962
eth_onekey_keyring --> keyring_utils;
63+
eth_ledger_bridge_keyring --> account_api;
6064
eth_qr_keyring --> keyring_utils;
65+
eth_simple_keyring --> keyring_api;
6166
eth_simple_keyring --> keyring_utils;
6267
eth_trezor_keyring --> keyring_utils;
6368
keyring_internal_api --> keyring_api;
@@ -69,6 +74,7 @@ linkStyle default opacity:0.5
6974
eth_snap_keyring --> keyring_api;
7075
eth_snap_keyring --> keyring_internal_api;
7176
eth_snap_keyring --> keyring_internal_snap_client;
77+
eth_snap_keyring --> keyring_snap_sdk;
7278
eth_snap_keyring --> keyring_utils;
7379
keyring_snap_client --> keyring_api;
7480
keyring_snap_client --> keyring_utils;

jest.config.packages.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ module.exports = {
8888
moduleNameMapper: {
8989
'^@metamask/(.+)$': [
9090
'<rootDir>/../$1/src',
91+
// While still unclear why, adding the line below seems to fix the @typescript-eslint/no-redundant-type-constituents errors throughout the monorepo
92+
'<rootDir>/packages/$1/src',
9193
// Some @metamask/* packages we are referencing aren't in this monorepo,
9294
// so in that case use their published versions
9395
'<rootDir>/../../node_modules/@metamask/$1',

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/accounts-monorepo",
3-
"version": "65.0.0",
3+
"version": "81.0.0",
44
"private": true,
55
"description": "Monorepo for MetaMask accounts related packages",
66
"repository": {

packages/account-api/CHANGELOG.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,36 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.12.0]
11+
12+
### Changed
13+
14+
- **BREAKING:** Rename `AccountsProvider.discoverAndCreateAccounts` to `AccountsProvider.discoverAccounts` ([#371](https://github.com/MetaMask/accounts/pull/371))
15+
- This aligns the method name with `MultichainAccountWallet.discoverAccounts`.
16+
17+
## [0.11.0]
18+
19+
### Added
20+
21+
- **BREAKING:** Add `MultichainAccountWallet.{align,discover}Accounts` methods ([#368](https://github.com/MetaMask/accounts/pull/368))
22+
- **BREAKING:** Add `{Multichain,}AccountWallet.status` getter ([#367](https://github.com/MetaMask/accounts/pull/367))
23+
24+
### Changed
25+
26+
- Make `isBip44Account` faster ([#369](https://github.com/MetaMask/accounts/pull/369))
27+
- We mainly rely on the `options.entropy.type` now and no longer use `superstruct` for this function.
28+
29+
## [0.10.0]
30+
31+
### Added
32+
33+
- Add group/wallet ID parsing/validation support ([#360](https://github.com/MetaMask/accounts/pull/360))
34+
- Add `Bip44AccountProvider` type alias ([#361](https://github.com/MetaMask/accounts/pull/361))
35+
36+
### Changed
37+
38+
- **BREAKING:** Bump `@metamask/keyring-api` to `^21.0.0` ([#362](https://github.com/MetaMask/accounts/pull/362))
39+
1040
## [0.9.0]
1141

1242
### Changed
@@ -100,7 +130,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
100130

101131
- Add `AccountGroup` and `AccountWallet` ([#307](https://github.com/MetaMask/accounts/pull/307))
102132

103-
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.9.0...HEAD
133+
[Unreleased]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.12.0...HEAD
134+
[0.12.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.11.0...@metamask/account-api@0.12.0
135+
[0.11.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.10.0...@metamask/account-api@0.11.0
136+
[0.10.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.9.0...@metamask/account-api@0.10.0
104137
[0.9.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.8.0...@metamask/account-api@0.9.0
105138
[0.8.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.7.0...@metamask/account-api@0.8.0
106139
[0.7.0]: https://github.com/MetaMask/accounts/compare/@metamask/account-api@0.6.0...@metamask/account-api@0.7.0

packages/account-api/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@metamask/account-api",
3-
"version": "0.9.0",
3+
"version": "0.12.0",
44
"description": "MetaMask Account API",
55
"keywords": [
66
"metamask",
@@ -58,7 +58,6 @@
5858
"dependencies": {
5959
"@metamask/keyring-api": "workspace:^",
6060
"@metamask/keyring-utils": "workspace:^",
61-
"@metamask/superstruct": "^3.1.0",
6261
"uuid": "^9.0.1"
6362
},
6463
"devDependencies": {

packages/account-api/src/api/bip44.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ import type {
22
KeyringAccount,
33
KeyringAccountEntropyMnemonicOptions,
44
} from '@metamask/keyring-api';
5-
import { KeyringAccountEntropyMnemonicOptionsStruct } from '@metamask/keyring-api';
6-
import { is } from '@metamask/superstruct';
75

86
/**
97
* BIP-44 compatible account type.
@@ -25,11 +23,9 @@ export type Bip44Account<Account extends KeyringAccount> = Account & {
2523
export function isBip44Account<Account extends KeyringAccount>(
2624
account: Account,
2725
): account is Bip44Account<Account> {
28-
// To be BIP-44 compatible, you just need to use this set of options:
29-
return is(
30-
account.options.entropy,
31-
KeyringAccountEntropyMnemonicOptionsStruct,
32-
);
26+
// To be BIP-44 compatible, we just check for the entropy type (the
27+
// the `entropy` shape will be inferred automatically).
28+
return account.options.entropy?.type === 'mnemonic';
3329
}
3430

3531
/**

packages/account-api/src/api/group.test.ts

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
import {
22
DEFAULT_ACCOUNT_GROUP_UNIQUE_ID,
3+
isAccountGroupId,
4+
parseAccountGroupId,
5+
stripAccountWalletId,
36
toAccountGroupId,
47
toDefaultAccountGroupId,
58
} from './group';
69
import { AccountWalletType, toAccountWalletId } from './wallet';
10+
import {
11+
MOCK_ENTROPY_GROUP_ID,
12+
MOCK_ENTROPY_SOURCE_1,
13+
MOCK_KEYRING_GROUP_ID,
14+
MOCK_PRIVATE_KEY_KEYRING_TYPE,
15+
MOCK_SNAP_1,
16+
MOCK_SNAP_2,
17+
MOCK_SNAP_LOCAL_GROUP_ID,
18+
MOCK_SNAP_NPM_GROUP_ID,
19+
} from '../mocks';
20+
21+
const MOCK_INVALID_GROUP_IDS = [
22+
'invalid-id',
23+
'entropy/01K3KE7FE52Z62S76VMNYNZH3J:0',
24+
'keyring:Simple Key Pair@0x456',
25+
];
726

827
describe('group', () => {
928
describe('toAccountGroupId', () => {
@@ -27,4 +46,120 @@ describe('group', () => {
2746
);
2847
});
2948
});
49+
50+
describe('isAccountGroupId', () => {
51+
it.each([
52+
MOCK_ENTROPY_GROUP_ID,
53+
MOCK_SNAP_LOCAL_GROUP_ID,
54+
MOCK_SNAP_NPM_GROUP_ID,
55+
MOCK_KEYRING_GROUP_ID,
56+
])('returns true if ID is valid: %s', (id) => {
57+
expect(isAccountGroupId(id)).toBe(true);
58+
});
59+
60+
it.each(MOCK_INVALID_GROUP_IDS)(
61+
'returns false if ID is invalid: %s',
62+
(id) => {
63+
expect(isAccountGroupId(id)).toBe(false);
64+
},
65+
);
66+
});
67+
68+
describe('parseAccountGroupId', () => {
69+
it.each([
70+
{
71+
id: MOCK_ENTROPY_GROUP_ID,
72+
parsed: {
73+
wallet: {
74+
id: toAccountWalletId(
75+
AccountWalletType.Entropy,
76+
MOCK_ENTROPY_SOURCE_1,
77+
),
78+
type: AccountWalletType.Entropy,
79+
subId: MOCK_ENTROPY_SOURCE_1,
80+
},
81+
subId: '0',
82+
},
83+
},
84+
{
85+
id: MOCK_SNAP_LOCAL_GROUP_ID,
86+
parsed: {
87+
wallet: {
88+
id: toAccountWalletId(AccountWalletType.Snap, MOCK_SNAP_1.id),
89+
type: AccountWalletType.Snap,
90+
subId: MOCK_SNAP_1.id,
91+
},
92+
subId: '0x123',
93+
},
94+
},
95+
{
96+
id: MOCK_SNAP_NPM_GROUP_ID,
97+
parsed: {
98+
wallet: {
99+
id: toAccountWalletId(AccountWalletType.Snap, MOCK_SNAP_2.id),
100+
type: AccountWalletType.Snap,
101+
subId: MOCK_SNAP_2.id,
102+
},
103+
subId: '0x456',
104+
},
105+
},
106+
{
107+
id: MOCK_KEYRING_GROUP_ID,
108+
parsed: {
109+
wallet: {
110+
id: toAccountWalletId(
111+
AccountWalletType.Keyring,
112+
MOCK_PRIVATE_KEY_KEYRING_TYPE,
113+
),
114+
type: AccountWalletType.Keyring,
115+
subId: MOCK_PRIVATE_KEY_KEYRING_TYPE,
116+
},
117+
subId: '0x789',
118+
},
119+
},
120+
])('parses account group id for: %s', ({ id, parsed }) => {
121+
expect(parseAccountGroupId(id)).toStrictEqual(parsed);
122+
});
123+
124+
it.each(MOCK_INVALID_GROUP_IDS)(
125+
'fails to parse invalid account group ID',
126+
(id) => {
127+
expect(() => parseAccountGroupId(id)).toThrow(
128+
`Invalid account group ID: "${id}"`,
129+
);
130+
},
131+
);
132+
});
133+
134+
describe('stripAccountWalletId', () => {
135+
it.each([
136+
{
137+
id: MOCK_ENTROPY_GROUP_ID,
138+
stripped: '0',
139+
},
140+
{
141+
id: MOCK_SNAP_LOCAL_GROUP_ID,
142+
stripped: '0x123',
143+
},
144+
{
145+
id: MOCK_SNAP_NPM_GROUP_ID,
146+
stripped: '0x456',
147+
},
148+
{
149+
id: MOCK_KEYRING_GROUP_ID,
150+
stripped: '0x789',
151+
},
152+
])('get account group sub-ID for: %s', ({ id, stripped }) => {
153+
expect(stripAccountWalletId(id)).toStrictEqual(stripped);
154+
});
155+
156+
it.each(MOCK_INVALID_GROUP_IDS)(
157+
'fails to parse invalid account group ID',
158+
(id) => {
159+
expect(() => stripAccountWalletId(id)).toThrow(
160+
`Invalid account group ID: "${id}"`,
161+
);
162+
},
163+
);
164+
});
30165
});

0 commit comments

Comments
 (0)