Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
ca4657a
eip-7702-internal-rpc-middleware package
MoMannn Oct 7, 2025
4b7744f
update build config
MoMannn Oct 7, 2025
91ccfda
Return the address to which an account is upgraded to
MoMannn Oct 7, 2025
d616665
linter fixes
MoMannn Oct 7, 2025
dd9fe07
add codeowners and update package.json
MoMannn Oct 7, 2025
da14086
add package to teams
MoMannn Oct 7, 2025
f669058
Merge branch 'main' into feat/eip-7702-internal-rpc-middleware
MoMannn Oct 7, 2025
0b7411a
update yarn lock
MoMannn Oct 7, 2025
f869165
update changelog
MoMannn Oct 7, 2025
df99911
Merge branch 'feat/eip-7702-internal-rpc-middleware' of https://githu…
MoMannn Oct 7, 2025
fa41730
update changelog
MoMannn Oct 7, 2025
d3a7fd3
update changelog
MoMannn Oct 7, 2025
4979e92
rename isAtomicBatchSupported and update descriptions
MoMannn Oct 8, 2025
d8d1b32
Merge branch 'main' into feat/eip-7702-internal-rpc-middleware
MoMannn Oct 8, 2025
3a2fc00
Update packages/eip-7702-internal-rpc-middleware/src/hooks/getAccount…
MoMannn Oct 9, 2025
00348b7
Update packages/eip-7702-internal-rpc-middleware/src/hooks/getAccount…
MoMannn Oct 9, 2025
73dbe5a
Update packages/eip-7702-internal-rpc-middleware/src/utils.test.ts
MoMannn Oct 9, 2025
48a1213
Update packages/eip-7702-internal-rpc-middleware/src/hooks/upgradeAcc…
MoMannn Oct 9, 2025
c4c3c37
Update packages/eip-7702-internal-rpc-middleware/src/hooks/upgradeAcc…
MoMannn Oct 9, 2025
528b188
flat structure and PR fixes
MoMannn Oct 9, 2025
766d595
flat structure and pr fixes
MoMannn Oct 9, 2025
5765723
Merge branch 'feat/eip-7702-internal-rpc-middleware' of https://githu…
MoMannn Oct 9, 2025
efe2661
merge fix
MoMannn Oct 9, 2025
16d1288
100% codecoverage
MoMannn Oct 9, 2025
c388025
Renaming and linter fixes
MoMannn Oct 9, 2025
a529924
Merge branch 'main' into feat/eip-7702-internal-rpc-middleware
MoMannn Oct 9, 2025
3287605
fix index exports
MoMannn Oct 9, 2025
932983d
fix typings
MoMannn Oct 9, 2025
0d9fd52
change getNetworkConfigurationByChainId hook to getSelectedNetworkCli…
MoMannn Oct 9, 2025
2db27fb
clean up utils
MoMannn Oct 9, 2025
a018789
type fixes
MoMannn Oct 9, 2025
5e2b3a0
fix exports
MoMannn Oct 9, 2025
a92cc6f
fix: format index.ts exports
MoMannn Oct 9, 2025
23462e7
update isEip7702Supported logic
MoMannn Oct 10, 2025
d381d00
Merge branch 'main' into feat/eip-7702-internal-rpc-middleware
MoMannn Oct 10, 2025
35e37ea
update yarn.lock
MoMannn Oct 10, 2025
f6fcabd
update dependencies
MoMannn Oct 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

## Delegation Team
/packages/gator-permissions-controller @MetaMask/delegation
/packages/eip-7702-internal-rpc-middleware @MetaMask/delegation @MetaMask/core-platform

## Earn Team
/packages/earn-controller @MetaMask/earn
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Each package in this repository has its own README where you can find installati
- [`@metamask/delegation-controller`](packages/delegation-controller)
- [`@metamask/earn-controller`](packages/earn-controller)
- [`@metamask/eip-5792-middleware`](packages/eip-5792-middleware)
- [`@metamask/eip-7702-internal-rpc-middleware`](packages/eip-7702-internal-rpc-middleware)
- [`@metamask/eip1193-permission-middleware`](packages/eip1193-permission-middleware)
- [`@metamask/ens-controller`](packages/ens-controller)
- [`@metamask/error-reporting-service`](packages/error-reporting-service)
Expand Down Expand Up @@ -101,6 +102,7 @@ linkStyle default opacity:0.5
delegation_controller(["@metamask/delegation-controller"]);
earn_controller(["@metamask/earn-controller"]);
eip_5792_middleware(["@metamask/eip-5792-middleware"]);
eip_7702_internal_rpc_middleware(["@metamask/eip-7702-internal-rpc-middleware"]);
eip1193_permission_middleware(["@metamask/eip1193-permission-middleware"]);
ens_controller(["@metamask/ens-controller"]);
error_reporting_service(["@metamask/error-reporting-service"]);
Expand Down Expand Up @@ -264,6 +266,7 @@ linkStyle default opacity:0.5
permission_log_controller --> json_rpc_engine;
phishing_controller --> base_controller;
phishing_controller --> controller_utils;
phishing_controller --> transaction_controller;
polling_controller --> base_controller;
polling_controller --> controller_utils;
polling_controller --> network_controller;
Expand Down Expand Up @@ -292,6 +295,7 @@ linkStyle default opacity:0.5
signature_controller --> controller_utils;
signature_controller --> accounts_controller;
signature_controller --> approval_controller;
signature_controller --> gator_permissions_controller;
signature_controller --> keyring_controller;
signature_controller --> logging_controller;
signature_controller --> network_controller;
Expand Down
20 changes: 20 additions & 0 deletions packages/eip-7702-internal-rpc-middleware/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

- Initial release of @metamask/eip-7702-internal-rpc-middleware ([#6789](https://github.com/MetaMask/core/pull/6789))
- `wallet_upgradeAccount` JSON-RPC method for upgrading EOA accounts to smart accounts using EIP-7702 ([#6789](https://github.com/MetaMask/core/pull/6789))
- `wallet_getAccountUpgradeStatus` JSON-RPC method for checking account upgrade status ([#6789](https://github.com/MetaMask/core/pull/6789))
- Hook-based architecture with `upgradeAccount` and `getAccountUpgradeStatus` hooks ([#6789](https://github.com/MetaMask/core/pull/6789))
- Comprehensive TypeScript type definitions ([#6789](https://github.com/MetaMask/core/pull/6789))
- Full test coverage with Jest ([#6789](https://github.com/MetaMask/core/pull/6789))
- Documentation and examples ([#6789](https://github.com/MetaMask/core/pull/6789))

[Unreleased]: https://github.com/MetaMask/core/
21 changes: 21 additions & 0 deletions packages/eip-7702-internal-rpc-middleware/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 MetaMask

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
98 changes: 98 additions & 0 deletions packages/eip-7702-internal-rpc-middleware/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# `@metamask/eip-7702-internal-rpc-middleware`

Implements internal JSON-RPC methods that support EIP-7702 account upgrade functionality. These methods are internal to MetaMask and not defined in [EIP-7702](https://eips.ethereum.org/EIPS/eip-7702), but provide the necessary infrastructure for EIP-7702 account upgrades.

## Installation

`yarn add @metamask/eip-7702-internal-rpc-middleware`

or

`npm install @metamask/eip-7702-internal-rpc-middleware`

## JSON-RPC Methods

### wallet_upgradeAccount

Upgrades an EOA account to a smart account using EIP-7702.

**Parameters:**

- `account` (string): Address of the EOA to upgrade
- `chainId` (string, optional): Chain ID for the upgrade (defaults to current)

**Returns:**

- `transactionHash` (string): Hash of the EIP-7702 authorization transaction
- `upgradedAccount` (string): Address of the upgraded account (same as input)
- `delegatedTo` (string): Address of the contract delegated to

**Example:**

```json
{
"method": "wallet_upgradeAccount",
"params": [
{
"account": "0x1234567890123456789012345678901234567890",
"chainId": "0x1"
}
]
}
```

### wallet_getAccountUpgradeStatus

Checks if an account has been upgraded using EIP-7702.

**Parameters:**

- `account` (string): Address of the account to check
- `chainId` (string, optional): Chain ID for the check (defaults to current)

**Returns:**

- `account` (string): Address of the checked account
- `isUpgraded` (boolean): Whether the account is upgraded
- `upgradedAddress` (string | null): Address to which the account is upgraded (null if not upgraded)
- `chainId` (string): Chain ID where the check was performed

**Example:**

```json
{
"method": "wallet_getAccountUpgradeStatus",
"params": [
{
"account": "0x1234567890123456789012345678901234567890",
"chainId": "0x1"
}
]
}
```

**Example Response (Upgraded Account):**

```json
{
"account": "0x1234567890123456789012345678901234567890",
"isUpgraded": true,
"upgradedAddress": "0xabcdef1234567890abcdef1234567890abcdef12",
"chainId": "0x1"
}
```

**Example Response (Non-Upgraded Account):**

```json
{
"account": "0x1234567890123456789012345678901234567890",
"isUpgraded": false,
"upgradedAddress": null,
"chainId": "0x1"
}
```

## Contributing

This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
26 changes: 26 additions & 0 deletions packages/eip-7702-internal-rpc-middleware/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/configuration
*/

const merge = require('deepmerge');
const path = require('path');

const baseConfig = require('../../jest.config.packages');

const displayName = path.basename(__dirname);

module.exports = merge(baseConfig, {
// The display name when running multiple projects
displayName,

// An object that configures minimum threshold enforcement for coverage results
coverageThreshold: {
global: {
branches: 100,
functions: 100,
lines: 100,
statements: 100,
},
},
});
72 changes: 72 additions & 0 deletions packages/eip-7702-internal-rpc-middleware/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"name": "@metamask/eip-7702-internal-rpc-middleware",
"version": "1.0.0",
"description": "Implements internal JSON-RPC methods for EIP-7702 account upgrade functionality",
"keywords": [
"MetaMask",
"Ethereum"
],
"homepage": "https://github.com/MetaMask/core/tree/main/packages/eip-7702-internal-rpc-middleware#readme",
"bugs": {
"url": "https://github.com/MetaMask/core/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/MetaMask/core.git"
},
"license": "MIT",
"sideEffects": false,
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.cts",
"default": "./dist/index.cjs"
}
},
"./package.json": "./package.json"
},
"main": "./dist/index.cjs",
"types": "./dist/index.d.cts",
"files": [
"dist/"
],
"scripts": {
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
"build:docs": "typedoc",
"changelog:update": "../../scripts/update-changelog.sh @metamask/eip-7702-internal-rpc-middleware",
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/eip-7702-internal-rpc-middleware",
"publish:preview": "yarn npm publish --tag preview",
"since-latest-release": "../../scripts/since-latest-release.sh",
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
},
"dependencies": {
"@metamask/controller-utils": "^11.14.1",
"@metamask/rpc-errors": "^7.0.2",
"@metamask/superstruct": "^3.1.0",
"@metamask/utils": "^11.8.1"
},
"devDependencies": {
"@metamask/auto-changelog": "^3.4.4",
"@types/jest": "^27.4.1",
"deepmerge": "^4.2.2",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"typedoc": "^0.24.8",
"typedoc-plugin-missing-exports": "^2.0.0",
"typescript": "~5.2.2"
},
"engines": {
"node": "^18.18 || >=20"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org/"
}
}
7 changes: 7 additions & 0 deletions packages/eip-7702-internal-rpc-middleware/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Method names
export const METHOD_NAMES = {
UPGRADE_ACCOUNT: 'wallet_upgradeAccount',
GET_ACCOUNT_UPGRADE_STATUS: 'wallet_getAccountUpgradeStatus',
} as const;

export const DELEGATION_INDICATOR_PREFIX = '0xef0100';
17 changes: 17 additions & 0 deletions packages/eip-7702-internal-rpc-middleware/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Method handlers
export { walletUpgradeAccount } from './wallet_upgradeAccount';
export { walletGetAccountUpgradeStatus } from './wallet_getAccountUpgradeStatus';

// Utilities
export { validateParams, validateAndNormalizeAddress } from './utils';

// Constants
export { METHOD_NAMES } from './constants';

// Types
export type {
UpgradeAccountParams,
UpgradeAccountResult,
GetAccountUpgradeStatusParams,
GetAccountUpgradeStatusResult,
} from './types';
36 changes: 36 additions & 0 deletions packages/eip-7702-internal-rpc-middleware/src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import type { Infer } from '@metamask/superstruct';
import { object, optional } from '@metamask/superstruct';
import type { Hex } from '@metamask/utils';
import { HexChecksumAddressStruct, StrictHexStruct } from '@metamask/utils';

// Superstruct validation schemas
export const UpgradeAccountParamsStruct = object({
account: HexChecksumAddressStruct,
chainId: optional(StrictHexStruct),
});

export const GetAccountUpgradeStatusParamsStruct = object({
account: HexChecksumAddressStruct,
chainId: optional(StrictHexStruct),
});

// Type definitions derived from schemas
export type UpgradeAccountParams = Infer<typeof UpgradeAccountParamsStruct>;

export type UpgradeAccountResult = {
transactionHash: string; // Hash of the EIP-7702 authorization transaction
upgradedAccount: string; // Address of the upgraded account (same as input)
delegatedTo: string; // Address of the contract delegated to (determined by wallet)
};

export type GetAccountUpgradeStatusParams = Infer<
typeof GetAccountUpgradeStatusParamsStruct
>;

export type GetAccountUpgradeStatusResult = {
account: string; // Address of the checked account
chainId: Hex; // Chain ID where the check was performed
isSupported: boolean; // Whether upgrade to smart account is supported on the chain
isUpgraded: boolean; // Whether the account is upgraded
upgradedAddress: string | null; // Address to which the account is upgraded
};
Loading
Loading