Skip to content

Commit d6a0c20

Browse files
authored
feat: add EthKeyringWrapper for common Eth logic around KeyringV2 implementation (#404)
<!-- 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 --> Related to: https://consensyssoftware.atlassian.net/browse/MUL-1316 ## 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] > Introduces `EthKeyringWrapper` with shared Ethereum `submitRequest` logic and updates `HdKeyringV2` to extend it, adding RPC param structs, an `EthKeyring` alias, tests, and required deps. > > - **Keyring API**: > - **New**: `eth/v2/EthKeyringWrapper` abstract class with common Ethereum request routing (`submitRequest`) and `EthKeyringMethod` enum. > - **RPC**: Add `EthGetEncryptionPublicKeyOptionsStruct` and `EthGetEncryptionPublicKeyParamsStruct` (address, optional options). > - **Exports**: Re-export from `eth/v2` and include new wrapper in `eth/index`. > - **Deps**: Add `@ethereumjs/tx` and `@metamask/eth-sig-util`. > - **Tests**: Add comprehensive unit tests for wrapper routing and errors. > - **Keyring ETH HD**: > - **Refactor**: `HdKeyringV2` now extends `EthKeyringWrapper`; removes duplicate routing, uses shared methods list including encryption/app-key/EIP-7702. > - **Tests**: Adjust to pass address/options for `eth_getEncryptionPublicKey` and align with wrapper behavior. > - **Changelog**: Note extension of `EthKeyringWrapper`. > - **Keyring Utils**: > - **New**: Export `EthKeyring` type alias for legacy `Keyring`. > - **Changelog**: Document alias addition. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 22051b5. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 2fe2a8d commit d6a0c20

13 files changed

Lines changed: 833 additions & 162 deletions

File tree

packages/keyring-api/CHANGELOG.md

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

1010
### Added
1111

12+
- Add `EthKeyringWrapper` abstract class for Ethereum-based `KeyringV2` implementations ([#404](https://github.com/MetaMask/accounts/pull/404))
13+
- Provides common Ethereum signing method routing (`submitRequest`) for all Ethereum-based keyrings.
1214
- Add `KeyringWrapper` base class to adapt legacy keyrings to `KeyringV2` ([#398](https://github.com/MetaMask/accounts/pull/398))
1315

1416
### Changed

packages/keyring-api/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646
"test:watch": "jest --watch"
4747
},
4848
"dependencies": {
49+
"@ethereumjs/tx": "^5.4.0",
50+
"@metamask/eth-sig-util": "^8.2.0",
4951
"@metamask/keyring-utils": "workspace:^",
5052
"@metamask/superstruct": "^3.1.0",
5153
"@metamask/utils": "^11.1.0",

packages/keyring-api/src/eth/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@ export * from './erc4337';
33
export * from './rpc';
44
export * from './types';
55
export * from './utils';
6+
export * from './v2';

packages/keyring-api/src/eth/rpc/params.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ export type EthEip7702Authorization = Infer<
126126
typeof EthEip7702AuthorizationStruct
127127
>;
128128

129+
/**
130+
* A struct for getEncryptionPublicKey options.
131+
*/
132+
export const EthGetEncryptionPublicKeyOptionsStruct = record(
133+
string(),
134+
unknown(),
135+
);
136+
129137
// ============================================================================
130138
// RPC Method Parameter Structs
131139
// ============================================================================
@@ -214,3 +222,11 @@ export const EthSignEip7702AuthorizationParamsStruct = tuple([
214222
export type EthSignEip7702AuthorizationParams = Infer<
215223
typeof EthSignEip7702AuthorizationParamsStruct
216224
>;
225+
226+
/**
227+
* Parameters for `eth_getEncryptionPublicKey`.
228+
*/
229+
export const EthGetEncryptionPublicKeyParamsStruct = tuple([
230+
EthAddressStruct, // address
231+
optional(EthGetEncryptionPublicKeyOptionsStruct), // options
232+
]);

0 commit comments

Comments
 (0)