Skip to content

Commit 483677e

Browse files
authored
feat: add SimpleKeyringV2 (#409)
Related to: https://consensyssoftware.atlassian.net/browse/MUL-1319 ## 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] > Introduce `SimpleKeyringV2` wrapping legacy `SimpleKeyring` to expose the unified Keyring V2 API with EOA support, private-key import/export, request handling, and robust concurrency/rollback. > > - **@metamask/eth-simple-keyring**: > - **New Adapter**: Add `SimpleKeyringV2` extending `EthKeyringWrapper` to expose EOA accounts via `KeyringV2`. > - Supports private-key import (hex) and export; maintains `KeyringAccount` registry. > - Routes requests for `eth_signTransaction`, `eth_sign`, `personal_sign`, `eth_signTypedData_v1/v3/v4`, `eth_getEncryptionPublicKey`, `eth_decrypt`, `eth_getAppKeyAddress`, `eth_signEip7702Authorization`. > - Adds mutex-based concurrency control and transactional rollback for safe imports; implements account deletion. > - **Tests**: Add comprehensive tests for account CRUD, exports, request handling, concurrency, and registry syncing. > - **Build/Deps**: Add deps `@metamask/keyring-api`, `async-mutex`; update TS project references; update CHANGELOG. > - **@metamask/keyring-api**: > - Update `KeyringWrapper` docs to reference the account "registry" (not "resolver"). > - **README**: > - Update dependency graph to add `eth_simple_keyring --> keyring_api`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit a6aef0d. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 6133e50 commit 483677e

File tree

9 files changed

+1343
-3
lines changed

9 files changed

+1343
-3
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ linkStyle default opacity:0.5
5757
eth_hd_keyring --> account_api;
5858
eth_ledger_bridge_keyring --> keyring_utils;
5959
eth_qr_keyring --> keyring_utils;
60+
eth_simple_keyring --> keyring_api;
6061
eth_simple_keyring --> keyring_utils;
6162
eth_trezor_keyring --> keyring_utils;
6263
keyring_internal_api --> keyring_api;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export abstract class KeyringWrapper<
142142
* Implementations are responsible for interpreting the
143143
* {@link CreateAccountOptions} (for example BIP-44 derivation or
144144
* private-key import) and returning the resulting {@link KeyringAccount}
145-
* objects. Implementors should also ensure that the resolver is updated so
145+
* objects. Implementors should also ensure that the registry is updated so
146146
* that {@link getAccount} works for newly created accounts.
147147
*/
148148
abstract createAccounts(
@@ -154,7 +154,7 @@ export abstract class KeyringWrapper<
154154
* keyring.
155155
*
156156
* Implementations are expected to translate the ID to an underlying
157-
* address (typically via the resolver) and then invoke the appropriate
157+
* address (typically via the registry) and then invoke the appropriate
158158
* removal mechanism on the legacy keyring.
159159
*/
160160
abstract deleteAccount(accountId: AccountId): Promise<void>;

packages/keyring-eth-simple/CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `SimpleKeyringV2` class implementing `KeyringV2` interface ([#409](https://github.com/MetaMask/accounts/pull/409))
13+
- Wraps legacy `SimpleKeyring` to expose accounts via the unified `KeyringV2` API and the `KeyringAccount` type.
14+
- Extends `EthKeyringWrapper` for common Ethereum logic.
15+
1016
## [11.0.0]
1117

1218
### Changed

packages/keyring-eth-simple/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@
4646
"dependencies": {
4747
"@ethereumjs/util": "^9.1.0",
4848
"@metamask/eth-sig-util": "^8.2.0",
49+
"@metamask/keyring-api": "workspace:^",
4950
"@metamask/utils": "^11.1.0",
51+
"async-mutex": "^0.5.0",
5052
"ethereum-cryptography": "^2.1.2",
5153
"randombytes": "^2.1.0"
5254
},

0 commit comments

Comments
 (0)