@metamask-previews/eip-7702-internal-rpc-middleware 0.0.0-preview-8504447

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/LICENSE +21 -0
  3. package/README.md +98 -0
  4. package/dist/constants.cjs +10 -0
  5. package/dist/constants.cjs.map +1 -0
  6. package/dist/constants.d.cts +6 -0
  7. package/dist/constants.d.cts.map +1 -0
  8. package/dist/constants.d.mts +6 -0
  9. package/dist/constants.d.mts.map +1 -0
  10. package/dist/constants.mjs +7 -0
  11. package/dist/constants.mjs.map +1 -0
  12. package/dist/index.cjs +16 -0
  13. package/dist/index.cjs.map +1 -0
  14. package/dist/index.d.cts +6 -0
  15. package/dist/index.d.cts.map +1 -0
  16. package/dist/index.d.mts +6 -0
  17. package/dist/index.d.mts.map +1 -0
  18. package/dist/index.mjs +8 -0
  19. package/dist/index.mjs.map +1 -0
  20. package/dist/types.cjs +15 -0
  21. package/dist/types.cjs.map +1 -0
  22. package/dist/types.d.cts +31 -0
  23. package/dist/types.d.cts.map +1 -0
  24. package/dist/types.d.mts +31 -0
  25. package/dist/types.d.mts.map +1 -0
  26. package/dist/types.mjs +12 -0
  27. package/dist/types.mjs.map +1 -0
  28. package/dist/utils.cjs +63 -0
  29. package/dist/utils.cjs.map +1 -0
  30. package/dist/utils.d.cts +22 -0
  31. package/dist/utils.d.cts.map +1 -0
  32. package/dist/utils.d.mts +22 -0
  33. package/dist/utils.d.mts.map +1 -0
  34. package/dist/utils.mjs +58 -0
  35. package/dist/utils.mjs.map +1 -0
  36. package/dist/wallet_getAccountUpgradeStatus.cjs +97 -0
  37. package/dist/wallet_getAccountUpgradeStatus.cjs.map +1 -0
  38. package/dist/wallet_getAccountUpgradeStatus.d.cts +26 -0
  39. package/dist/wallet_getAccountUpgradeStatus.d.cts.map +1 -0
  40. package/dist/wallet_getAccountUpgradeStatus.d.mts +26 -0
  41. package/dist/wallet_getAccountUpgradeStatus.d.mts.map +1 -0
  42. package/dist/wallet_getAccountUpgradeStatus.mjs +93 -0
  43. package/dist/wallet_getAccountUpgradeStatus.mjs.map +1 -0
  44. package/dist/wallet_upgradeAccount.cjs +71 -0
  45. package/dist/wallet_upgradeAccount.cjs.map +1 -0
  46. package/dist/wallet_upgradeAccount.d.cts +28 -0
  47. package/dist/wallet_upgradeAccount.d.cts.map +1 -0
  48. package/dist/wallet_upgradeAccount.d.mts +28 -0
  49. package/dist/wallet_upgradeAccount.d.mts.map +1 -0
  50. package/dist/wallet_upgradeAccount.mjs +67 -0
  51. package/dist/wallet_upgradeAccount.mjs.map +1 -0
  52. package/package.json +72 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,20 @@
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
+ - Initial release of @metamask/eip-7702-internal-rpc-middleware ([#6789](https://github.com/MetaMask/core/pull/6789))
13
+ - `wallet_upgradeAccount` JSON-RPC method for upgrading EOA accounts to smart accounts using EIP-7702 ([#6789](https://github.com/MetaMask/core/pull/6789))
14
+ - `wallet_getAccountUpgradeStatus` JSON-RPC method for checking account upgrade status ([#6789](https://github.com/MetaMask/core/pull/6789))
15
+ - Hook-based architecture with `upgradeAccount` and `getAccountUpgradeStatus` hooks ([#6789](https://github.com/MetaMask/core/pull/6789))
16
+ - Comprehensive TypeScript type definitions ([#6789](https://github.com/MetaMask/core/pull/6789))
17
+ - Full test coverage with Jest ([#6789](https://github.com/MetaMask/core/pull/6789))
18
+ - Documentation and examples ([#6789](https://github.com/MetaMask/core/pull/6789))
19
+
20
+ [Unreleased]: https://github.com/MetaMask/core/
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 MetaMask
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # `@metamask/eip-7702-internal-rpc-middleware`
2
+
3
+ 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.
4
+
5
+ ## Installation
6
+
7
+ `yarn add @metamask/eip-7702-internal-rpc-middleware`
8
+
9
+ or
10
+
11
+ `npm install @metamask/eip-7702-internal-rpc-middleware`
12
+
13
+ ## JSON-RPC Methods
14
+
15
+ ### wallet_upgradeAccount
16
+
17
+ Upgrades an EOA account to a smart account using EIP-7702.
18
+
19
+ **Parameters:**
20
+
21
+ - `account` (string): Address of the EOA to upgrade
22
+ - `chainId` (string, optional): Chain ID for the upgrade (defaults to current)
23
+
24
+ **Returns:**
25
+
26
+ - `transactionHash` (string): Hash of the EIP-7702 authorization transaction
27
+ - `upgradedAccount` (string): Address of the upgraded account (same as input)
28
+ - `delegatedTo` (string): Address of the contract delegated to
29
+
30
+ **Example:**
31
+
32
+ ```json
33
+ {
34
+ "method": "wallet_upgradeAccount",
35
+ "params": [
36
+ {
37
+ "account": "0x1234567890123456789012345678901234567890",
38
+ "chainId": "0x1"
39
+ }
40
+ ]
41
+ }
42
+ ```
43
+
44
+ ### wallet_getAccountUpgradeStatus
45
+
46
+ Checks if an account has been upgraded using EIP-7702.
47
+
48
+ **Parameters:**
49
+
50
+ - `account` (string): Address of the account to check
51
+ - `chainId` (string, optional): Chain ID for the check (defaults to current)
52
+
53
+ **Returns:**
54
+
55
+ - `account` (string): Address of the checked account
56
+ - `isUpgraded` (boolean): Whether the account is upgraded
57
+ - `upgradedAddress` (string | null): Address to which the account is upgraded (null if not upgraded)
58
+ - `chainId` (string): Chain ID where the check was performed
59
+
60
+ **Example:**
61
+
62
+ ```json
63
+ {
64
+ "method": "wallet_getAccountUpgradeStatus",
65
+ "params": [
66
+ {
67
+ "account": "0x1234567890123456789012345678901234567890",
68
+ "chainId": "0x1"
69
+ }
70
+ ]
71
+ }
72
+ ```
73
+
74
+ **Example Response (Upgraded Account):**
75
+
76
+ ```json
77
+ {
78
+ "account": "0x1234567890123456789012345678901234567890",
79
+ "isUpgraded": true,
80
+ "upgradedAddress": "0xabcdef1234567890abcdef1234567890abcdef12",
81
+ "chainId": "0x1"
82
+ }
83
+ ```
84
+
85
+ **Example Response (Non-Upgraded Account):**
86
+
87
+ ```json
88
+ {
89
+ "account": "0x1234567890123456789012345678901234567890",
90
+ "isUpgraded": false,
91
+ "upgradedAddress": null,
92
+ "chainId": "0x1"
93
+ }
94
+ ```
95
+
96
+ ## Contributing
97
+
98
+ This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DELEGATION_INDICATOR_PREFIX = exports.METHOD_NAMES = void 0;
4
+ // Method names
5
+ exports.METHOD_NAMES = {
6
+ UPGRADE_ACCOUNT: 'wallet_upgradeAccount',
7
+ GET_ACCOUNT_UPGRADE_STATUS: 'wallet_getAccountUpgradeStatus',
8
+ };
9
+ exports.DELEGATION_INDICATOR_PREFIX = '0xef0100';
10
+ //# sourceMappingURL=constants.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.cjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAAA,eAAe;AACF,QAAA,YAAY,GAAG;IAC1B,eAAe,EAAE,uBAAuB;IACxC,0BAA0B,EAAE,gCAAgC;CACpD,CAAC;AAEE,QAAA,2BAA2B,GAAG,UAAU,CAAC","sourcesContent":["// Method names\nexport const METHOD_NAMES = {\n UPGRADE_ACCOUNT: 'wallet_upgradeAccount',\n GET_ACCOUNT_UPGRADE_STATUS: 'wallet_getAccountUpgradeStatus',\n} as const;\n\nexport const DELEGATION_INDICATOR_PREFIX = '0xef0100';\n"]}
@@ -0,0 +1,6 @@
1
+ export declare const METHOD_NAMES: {
2
+ readonly UPGRADE_ACCOUNT: "wallet_upgradeAccount";
3
+ readonly GET_ACCOUNT_UPGRADE_STATUS: "wallet_getAccountUpgradeStatus";
4
+ };
5
+ export declare const DELEGATION_INDICATOR_PREFIX = "0xef0100";
6
+ //# sourceMappingURL=constants.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.cts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY;;;CAGf,CAAC;AAEX,eAAO,MAAM,2BAA2B,aAAa,CAAC"}
@@ -0,0 +1,6 @@
1
+ export declare const METHOD_NAMES: {
2
+ readonly UPGRADE_ACCOUNT: "wallet_upgradeAccount";
3
+ readonly GET_ACCOUNT_UPGRADE_STATUS: "wallet_getAccountUpgradeStatus";
4
+ };
5
+ export declare const DELEGATION_INDICATOR_PREFIX = "0xef0100";
6
+ //# sourceMappingURL=constants.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.mts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,YAAY;;;CAGf,CAAC;AAEX,eAAO,MAAM,2BAA2B,aAAa,CAAC"}
@@ -0,0 +1,7 @@
1
+ // Method names
2
+ export const METHOD_NAMES = {
3
+ UPGRADE_ACCOUNT: 'wallet_upgradeAccount',
4
+ GET_ACCOUNT_UPGRADE_STATUS: 'wallet_getAccountUpgradeStatus',
5
+ };
6
+ export const DELEGATION_INDICATOR_PREFIX = '0xef0100';
7
+ //# sourceMappingURL=constants.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.mjs","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,MAAM,CAAC,MAAM,YAAY,GAAG;IAC1B,eAAe,EAAE,uBAAuB;IACxC,0BAA0B,EAAE,gCAAgC;CACpD,CAAC;AAEX,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CAAC","sourcesContent":["// Method names\nexport const METHOD_NAMES = {\n UPGRADE_ACCOUNT: 'wallet_upgradeAccount',\n GET_ACCOUNT_UPGRADE_STATUS: 'wallet_getAccountUpgradeStatus',\n} as const;\n\nexport const DELEGATION_INDICATOR_PREFIX = '0xef0100';\n"]}
package/dist/index.cjs ADDED
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.METHOD_NAMES = exports.validateAndNormalizeAddress = exports.validateParams = exports.walletGetAccountUpgradeStatus = exports.walletUpgradeAccount = void 0;
4
+ // Method handlers
5
+ var wallet_upgradeAccount_1 = require("./wallet_upgradeAccount.cjs");
6
+ Object.defineProperty(exports, "walletUpgradeAccount", { enumerable: true, get: function () { return wallet_upgradeAccount_1.walletUpgradeAccount; } });
7
+ var wallet_getAccountUpgradeStatus_1 = require("./wallet_getAccountUpgradeStatus.cjs");
8
+ Object.defineProperty(exports, "walletGetAccountUpgradeStatus", { enumerable: true, get: function () { return wallet_getAccountUpgradeStatus_1.walletGetAccountUpgradeStatus; } });
9
+ // Utilities
10
+ var utils_1 = require("./utils.cjs");
11
+ Object.defineProperty(exports, "validateParams", { enumerable: true, get: function () { return utils_1.validateParams; } });
12
+ Object.defineProperty(exports, "validateAndNormalizeAddress", { enumerable: true, get: function () { return utils_1.validateAndNormalizeAddress; } });
13
+ // Constants
14
+ var constants_1 = require("./constants.cjs");
15
+ Object.defineProperty(exports, "METHOD_NAMES", { enumerable: true, get: function () { return constants_1.METHOD_NAMES; } });
16
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,kBAAkB;AAClB,qEAA+D;AAAtD,6HAAA,oBAAoB,OAAA;AAC7B,uFAAiF;AAAxE,+IAAA,6BAA6B,OAAA;AAEtC,YAAY;AACZ,qCAAsE;AAA7D,uGAAA,cAAc,OAAA;AAAE,oHAAA,2BAA2B,OAAA;AAEpD,YAAY;AACZ,6CAA2C;AAAlC,yGAAA,YAAY,OAAA","sourcesContent":["// Method handlers\nexport { walletUpgradeAccount } from './wallet_upgradeAccount';\nexport { walletGetAccountUpgradeStatus } from './wallet_getAccountUpgradeStatus';\n\n// Utilities\nexport { validateParams, validateAndNormalizeAddress } from './utils';\n\n// Constants\nexport { METHOD_NAMES } from './constants';\n\n// Types\nexport type {\n UpgradeAccountParams,\n UpgradeAccountResult,\n GetAccountUpgradeStatusParams,\n GetAccountUpgradeStatusResult,\n} from './types';\n"]}
@@ -0,0 +1,6 @@
1
+ export { walletUpgradeAccount } from "./wallet_upgradeAccount.cjs";
2
+ export { walletGetAccountUpgradeStatus } from "./wallet_getAccountUpgradeStatus.cjs";
3
+ export { validateParams, validateAndNormalizeAddress } from "./utils.cjs";
4
+ export { METHOD_NAMES } from "./constants.cjs";
5
+ export type { UpgradeAccountParams, UpgradeAccountResult, GetAccountUpgradeStatusParams, GetAccountUpgradeStatusResult, } from "./types.cjs";
6
+ //# sourceMappingURL=index.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,oCAAgC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,6CAAyC;AAGjF,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,oBAAgB;AAGtE,OAAO,EAAE,YAAY,EAAE,wBAAoB;AAG3C,YAAY,EACV,oBAAoB,EACpB,oBAAoB,EACpB,6BAA6B,EAC7B,6BAA6B,GAC9B,oBAAgB"}
@@ -0,0 +1,6 @@
1
+ export { walletUpgradeAccount } from "./wallet_upgradeAccount.mjs";
2
+ export { walletGetAccountUpgradeStatus } from "./wallet_getAccountUpgradeStatus.mjs";
3
+ export { validateParams, validateAndNormalizeAddress } from "./utils.mjs";
4
+ export { METHOD_NAMES } from "./constants.mjs";
5
+ export type { UpgradeAccountParams, UpgradeAccountResult, GetAccountUpgradeStatusParams, GetAccountUpgradeStatusResult, } from "./types.mjs";
6
+ //# sourceMappingURL=index.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,oCAAgC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,6CAAyC;AAGjF,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,oBAAgB;AAGtE,OAAO,EAAE,YAAY,EAAE,wBAAoB;AAG3C,YAAY,EACV,oBAAoB,EACpB,oBAAoB,EACpB,6BAA6B,EAC7B,6BAA6B,GAC9B,oBAAgB"}
package/dist/index.mjs ADDED
@@ -0,0 +1,8 @@
1
+ // Method handlers
2
+ export { walletUpgradeAccount } from "./wallet_upgradeAccount.mjs";
3
+ export { walletGetAccountUpgradeStatus } from "./wallet_getAccountUpgradeStatus.mjs";
4
+ // Utilities
5
+ export { validateParams, validateAndNormalizeAddress } from "./utils.mjs";
6
+ // Constants
7
+ export { METHOD_NAMES } from "./constants.mjs";
8
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kBAAkB;AAClB,OAAO,EAAE,oBAAoB,EAAE,oCAAgC;AAC/D,OAAO,EAAE,6BAA6B,EAAE,6CAAyC;AAEjF,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,2BAA2B,EAAE,oBAAgB;AAEtE,YAAY;AACZ,OAAO,EAAE,YAAY,EAAE,wBAAoB","sourcesContent":["// Method handlers\nexport { walletUpgradeAccount } from './wallet_upgradeAccount';\nexport { walletGetAccountUpgradeStatus } from './wallet_getAccountUpgradeStatus';\n\n// Utilities\nexport { validateParams, validateAndNormalizeAddress } from './utils';\n\n// Constants\nexport { METHOD_NAMES } from './constants';\n\n// Types\nexport type {\n UpgradeAccountParams,\n UpgradeAccountResult,\n GetAccountUpgradeStatusParams,\n GetAccountUpgradeStatusResult,\n} from './types';\n"]}
package/dist/types.cjs ADDED
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GetAccountUpgradeStatusParamsStruct = exports.UpgradeAccountParamsStruct = void 0;
4
+ const superstruct_1 = require("@metamask/superstruct");
5
+ const utils_1 = require("@metamask/utils");
6
+ // Superstruct validation schemas
7
+ exports.UpgradeAccountParamsStruct = (0, superstruct_1.object)({
8
+ account: utils_1.HexChecksumAddressStruct,
9
+ chainId: (0, superstruct_1.optional)(utils_1.StrictHexStruct),
10
+ });
11
+ exports.GetAccountUpgradeStatusParamsStruct = (0, superstruct_1.object)({
12
+ account: utils_1.HexChecksumAddressStruct,
13
+ chainId: (0, superstruct_1.optional)(utils_1.StrictHexStruct),
14
+ });
15
+ //# sourceMappingURL=types.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AACA,uDAAyD;AAEzD,2CAA4E;AAE5E,iCAAiC;AACpB,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,OAAO,EAAE,gCAAwB;IACjC,OAAO,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;CACnC,CAAC,CAAC;AAEU,QAAA,mCAAmC,GAAG,IAAA,oBAAM,EAAC;IACxD,OAAO,EAAE,gCAAwB;IACjC,OAAO,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;CACnC,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { object, optional } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport { HexChecksumAddressStruct, StrictHexStruct } from '@metamask/utils';\n\n// Superstruct validation schemas\nexport const UpgradeAccountParamsStruct = object({\n account: HexChecksumAddressStruct,\n chainId: optional(StrictHexStruct),\n});\n\nexport const GetAccountUpgradeStatusParamsStruct = object({\n account: HexChecksumAddressStruct,\n chainId: optional(StrictHexStruct),\n});\n\n// Type definitions derived from schemas\nexport type UpgradeAccountParams = Infer<typeof UpgradeAccountParamsStruct>;\n\nexport type UpgradeAccountResult = {\n transactionHash: Hex; // Hash of the EIP-7702 authorization transaction\n upgradedAccount: Hex; // Address of the upgraded account (same as input)\n delegatedTo: Hex; // Address of the contract delegated to (determined by wallet)\n};\n\nexport type GetAccountUpgradeStatusParams = Infer<\n typeof GetAccountUpgradeStatusParamsStruct\n>;\n\nexport type GetAccountUpgradeStatusResult = {\n account: Hex; // Address of the checked account\n chainId: Hex; // Chain ID where the check was performed\n isSupported: boolean; // Whether upgrade to smart account is supported on the chain\n isUpgraded: boolean; // Whether the account is upgraded\n upgradedAddress: Hex | null; // Address to which the account is upgraded\n};\n"]}
@@ -0,0 +1,31 @@
1
+ import type { Infer } from "@metamask/superstruct";
2
+ import type { Hex } from "@metamask/utils";
3
+ export declare const UpgradeAccountParamsStruct: import("@metamask/superstruct").Struct<{
4
+ account: `0x${string}`;
5
+ chainId?: `0x${string}` | undefined;
6
+ }, {
7
+ account: import("@metamask/superstruct").Struct<`0x${string}`, null>;
8
+ chainId: import("@metamask/superstruct").Struct<`0x${string}` | undefined, null>;
9
+ }>;
10
+ export declare const GetAccountUpgradeStatusParamsStruct: import("@metamask/superstruct").Struct<{
11
+ account: `0x${string}`;
12
+ chainId?: `0x${string}` | undefined;
13
+ }, {
14
+ account: import("@metamask/superstruct").Struct<`0x${string}`, null>;
15
+ chainId: import("@metamask/superstruct").Struct<`0x${string}` | undefined, null>;
16
+ }>;
17
+ export type UpgradeAccountParams = Infer<typeof UpgradeAccountParamsStruct>;
18
+ export type UpgradeAccountResult = {
19
+ transactionHash: Hex;
20
+ upgradedAccount: Hex;
21
+ delegatedTo: Hex;
22
+ };
23
+ export type GetAccountUpgradeStatusParams = Infer<typeof GetAccountUpgradeStatusParamsStruct>;
24
+ export type GetAccountUpgradeStatusResult = {
25
+ account: Hex;
26
+ chainId: Hex;
27
+ isSupported: boolean;
28
+ isUpgraded: boolean;
29
+ upgradedAddress: Hex | null;
30
+ };
31
+ //# sourceMappingURL=types.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,eAAO,MAAM,0BAA0B;;;;;;EAGrC,CAAC;AAEH,eAAO,MAAM,mCAAmC;;;;;;EAG9C,CAAC;AAGH,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE5E,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,GAAG,CAAC;IACrB,eAAe,EAAE,GAAG,CAAC;IACrB,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,KAAK,CAC/C,OAAO,mCAAmC,CAC3C,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,eAAe,EAAE,GAAG,GAAG,IAAI,CAAC;CAC7B,CAAC"}
@@ -0,0 +1,31 @@
1
+ import type { Infer } from "@metamask/superstruct";
2
+ import type { Hex } from "@metamask/utils";
3
+ export declare const UpgradeAccountParamsStruct: import("@metamask/superstruct").Struct<{
4
+ account: `0x${string}`;
5
+ chainId?: `0x${string}` | undefined;
6
+ }, {
7
+ account: import("@metamask/superstruct").Struct<`0x${string}`, null>;
8
+ chainId: import("@metamask/superstruct").Struct<`0x${string}` | undefined, null>;
9
+ }>;
10
+ export declare const GetAccountUpgradeStatusParamsStruct: import("@metamask/superstruct").Struct<{
11
+ account: `0x${string}`;
12
+ chainId?: `0x${string}` | undefined;
13
+ }, {
14
+ account: import("@metamask/superstruct").Struct<`0x${string}`, null>;
15
+ chainId: import("@metamask/superstruct").Struct<`0x${string}` | undefined, null>;
16
+ }>;
17
+ export type UpgradeAccountParams = Infer<typeof UpgradeAccountParamsStruct>;
18
+ export type UpgradeAccountResult = {
19
+ transactionHash: Hex;
20
+ upgradedAccount: Hex;
21
+ delegatedTo: Hex;
22
+ };
23
+ export type GetAccountUpgradeStatusParams = Infer<typeof GetAccountUpgradeStatusParamsStruct>;
24
+ export type GetAccountUpgradeStatusResult = {
25
+ account: Hex;
26
+ chainId: Hex;
27
+ isSupported: boolean;
28
+ isUpgraded: boolean;
29
+ upgradedAddress: Hex | null;
30
+ };
31
+ //# sourceMappingURL=types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAI3C,eAAO,MAAM,0BAA0B;;;;;;EAGrC,CAAC;AAEH,eAAO,MAAM,mCAAmC;;;;;;EAG9C,CAAC;AAGH,MAAM,MAAM,oBAAoB,GAAG,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE5E,MAAM,MAAM,oBAAoB,GAAG;IACjC,eAAe,EAAE,GAAG,CAAC;IACrB,eAAe,EAAE,GAAG,CAAC;IACrB,WAAW,EAAE,GAAG,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,KAAK,CAC/C,OAAO,mCAAmC,CAC3C,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG;IAC1C,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,GAAG,CAAC;IACb,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,OAAO,CAAC;IACpB,eAAe,EAAE,GAAG,GAAG,IAAI,CAAC;CAC7B,CAAC"}
package/dist/types.mjs ADDED
@@ -0,0 +1,12 @@
1
+ import { object, optional } from "@metamask/superstruct";
2
+ import { HexChecksumAddressStruct, StrictHexStruct } from "@metamask/utils";
3
+ // Superstruct validation schemas
4
+ export const UpgradeAccountParamsStruct = object({
5
+ account: HexChecksumAddressStruct,
6
+ chainId: optional(StrictHexStruct),
7
+ });
8
+ export const GetAccountUpgradeStatusParamsStruct = object({
9
+ account: HexChecksumAddressStruct,
10
+ chainId: optional(StrictHexStruct),
11
+ });
12
+ //# sourceMappingURL=types.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.mjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,8BAA8B;AAEzD,OAAO,EAAE,wBAAwB,EAAE,eAAe,EAAE,wBAAwB;AAE5E,iCAAiC;AACjC,MAAM,CAAC,MAAM,0BAA0B,GAAG,MAAM,CAAC;IAC/C,OAAO,EAAE,wBAAwB;IACjC,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC;CACnC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,mCAAmC,GAAG,MAAM,CAAC;IACxD,OAAO,EAAE,wBAAwB;IACjC,OAAO,EAAE,QAAQ,CAAC,eAAe,CAAC;CACnC,CAAC,CAAC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport { object, optional } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport { HexChecksumAddressStruct, StrictHexStruct } from '@metamask/utils';\n\n// Superstruct validation schemas\nexport const UpgradeAccountParamsStruct = object({\n account: HexChecksumAddressStruct,\n chainId: optional(StrictHexStruct),\n});\n\nexport const GetAccountUpgradeStatusParamsStruct = object({\n account: HexChecksumAddressStruct,\n chainId: optional(StrictHexStruct),\n});\n\n// Type definitions derived from schemas\nexport type UpgradeAccountParams = Infer<typeof UpgradeAccountParamsStruct>;\n\nexport type UpgradeAccountResult = {\n transactionHash: Hex; // Hash of the EIP-7702 authorization transaction\n upgradedAccount: Hex; // Address of the upgraded account (same as input)\n delegatedTo: Hex; // Address of the contract delegated to (determined by wallet)\n};\n\nexport type GetAccountUpgradeStatusParams = Infer<\n typeof GetAccountUpgradeStatusParamsStruct\n>;\n\nexport type GetAccountUpgradeStatusResult = {\n account: Hex; // Address of the checked account\n chainId: Hex; // Chain ID where the check was performed\n isSupported: boolean; // Whether upgrade to smart account is supported on the chain\n isUpgraded: boolean; // Whether the account is upgraded\n upgradedAddress: Hex | null; // Address to which the account is upgraded\n};\n"]}
package/dist/utils.cjs ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateParams = exports.validateAndNormalizeAddress = void 0;
4
+ const rpc_errors_1 = require("@metamask/rpc-errors");
5
+ const superstruct_1 = require("@metamask/superstruct");
6
+ const utils_1 = require("@metamask/utils");
7
+ /**
8
+ * Validates address format, checks user eth_accounts permissions.
9
+ *
10
+ * @param address - The Ethereum address to validate and normalize.
11
+ * @param origin - The origin string for permission checking.
12
+ * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.
13
+ * @returns A normalized (lowercase) hex address if valid and authorized.
14
+ * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.
15
+ * @throws JsonRpcError with invalid params if the address format is invalid.
16
+ */
17
+ async function validateAndNormalizeAddress(address, origin, getPermittedAccountsForOrigin) {
18
+ if (typeof address !== 'string' ||
19
+ address.length === 0 ||
20
+ !(0, utils_1.isHexAddress)(address)) {
21
+ throw rpc_errors_1.rpcErrors.invalidParams({
22
+ message: `Invalid parameters: must provide an EVM address.`,
23
+ });
24
+ }
25
+ // Ensure that an "unauthorized" error is thrown if the requester
26
+ // does not have the `eth_accounts` permission.
27
+ const accounts = await getPermittedAccountsForOrigin(origin);
28
+ // Validate and convert each account address to normalized Hex
29
+ const normalizedAccounts = accounts.map((accountAddress) => accountAddress.toLowerCase());
30
+ if (!normalizedAccounts.includes(address.toLowerCase())) {
31
+ throw rpc_errors_1.providerErrors.unauthorized();
32
+ }
33
+ return address;
34
+ }
35
+ exports.validateAndNormalizeAddress = validateAndNormalizeAddress;
36
+ /**
37
+ * Validates parameters against a Superstruct schema and throws an error if validation fails.
38
+ *
39
+ * @param value - The value to validate against the struct schema.
40
+ * @param struct - The Superstruct schema to validate against.
41
+ * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.
42
+ */
43
+ function validateParams(value, struct) {
44
+ const [error] = (0, superstruct_1.validate)(value, struct);
45
+ if (error) {
46
+ throw rpc_errors_1.rpcErrors.invalidParams(formatValidationError(error, 'Invalid parameters'));
47
+ }
48
+ }
49
+ exports.validateParams = validateParams;
50
+ /**
51
+ * Formats a Superstruct validation error into a human-readable string.
52
+ *
53
+ * @param error - The Superstruct validation error to format.
54
+ * @param message - The base error message to prepend to the formatted details.
55
+ * @returns A formatted error message string with validation failure details.
56
+ */
57
+ function formatValidationError(error, message) {
58
+ return `${message}\n\n${error
59
+ .failures()
60
+ .map((f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`)
61
+ .join('\n')}`;
62
+ }
63
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AAAA,qDAAiE;AAEjE,uDAAiD;AAEjD,2CAA+C;AAE/C;;;;;;;;;GASG;AACI,KAAK,UAAU,2BAA2B,CAC/C,OAAY,EACZ,MAAc,EACd,6BAAoE;IAEpE,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,CAAC,MAAM,KAAK,CAAC;QACpB,CAAC,IAAA,oBAAY,EAAC,OAAO,CAAC,EACtB;QACA,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,kDAAkD;SAC5D,CAAC,CAAC;KACJ;IAED,iEAAiE;IACjE,+CAA+C;IAC/C,MAAM,QAAQ,GAAG,MAAM,6BAA6B,CAAC,MAAM,CAAC,CAAC;IAE7D,8DAA8D;IAC9D,MAAM,kBAAkB,GAAa,QAAQ,CAAC,GAAG,CAAC,CAAC,cAAc,EAAE,EAAE,CACnE,cAAc,CAAC,WAAW,EAAE,CAC7B,CAAC;IAEF,IAAI,CAAC,kBAAkB,CAAC,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,EAAE;QACvD,MAAM,2BAAc,CAAC,YAAY,EAAE,CAAC;KACrC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC;AA7BD,kEA6BC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,KAA2B,EAC3B,MAA0B;IAE1B,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAQ,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAExC,IAAI,KAAK,EAAE;QACT,MAAM,sBAAS,CAAC,aAAa,CAC3B,qBAAqB,CAAC,KAAK,EAAE,oBAAoB,CAAC,CACnD,CAAC;KACH;AACH,CAAC;AAXD,wCAWC;AAED;;;;;;GAMG;AACH,SAAS,qBAAqB,CAAC,KAAkB,EAAE,OAAe;IAChE,OAAO,GAAG,OAAO,OAAO,KAAK;SAC1B,QAAQ,EAAE;SACV,GAAG,CACF,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CACxE;SACA,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport { isHexAddress } from '@metamask/utils';\n\n/**\n * Validates address format, checks user eth_accounts permissions.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param origin - The origin string for permission checking.\n * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.\n * @returns A normalized (lowercase) hex address if valid and authorized.\n * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.\n * @throws JsonRpcError with invalid params if the address format is invalid.\n */\nexport async function validateAndNormalizeAddress(\n address: Hex,\n origin: string,\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>,\n): Promise<Hex> {\n if (\n typeof address !== 'string' ||\n address.length === 0 ||\n !isHexAddress(address)\n ) {\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an EVM address.`,\n });\n }\n\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getPermittedAccountsForOrigin(origin);\n\n // Validate and convert each account address to normalized Hex\n const normalizedAccounts: string[] = accounts.map((accountAddress) =>\n accountAddress.toLowerCase(),\n );\n\n if (!normalizedAccounts.includes(address.toLowerCase())) {\n throw providerErrors.unauthorized();\n }\n\n return address;\n}\n\n/**\n * Validates parameters against a Superstruct schema and throws an error if validation fails.\n *\n * @param value - The value to validate against the struct schema.\n * @param struct - The Superstruct schema to validate against.\n * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.\n */\nexport function validateParams<ParamsType>(\n value: unknown | ParamsType,\n struct: Struct<ParamsType>,\n): asserts value is ParamsType {\n const [error] = validate(value, struct);\n\n if (error) {\n throw rpcErrors.invalidParams(\n formatValidationError(error, 'Invalid parameters'),\n );\n }\n}\n\n/**\n * Formats a Superstruct validation error into a human-readable string.\n *\n * @param error - The Superstruct validation error to format.\n * @param message - The base error message to prepend to the formatted details.\n * @returns A formatted error message string with validation failure details.\n */\nfunction formatValidationError(error: StructError, message: string): string {\n return `${message}\\n\\n${error\n .failures()\n .map(\n (f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`,\n )\n .join('\\n')}`;\n}\n"]}
@@ -0,0 +1,22 @@
1
+ import type { Struct } from "@metamask/superstruct";
2
+ import type { Hex } from "@metamask/utils";
3
+ /**
4
+ * Validates address format, checks user eth_accounts permissions.
5
+ *
6
+ * @param address - The Ethereum address to validate and normalize.
7
+ * @param origin - The origin string for permission checking.
8
+ * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.
9
+ * @returns A normalized (lowercase) hex address if valid and authorized.
10
+ * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.
11
+ * @throws JsonRpcError with invalid params if the address format is invalid.
12
+ */
13
+ export declare function validateAndNormalizeAddress(address: Hex, origin: string, getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>): Promise<Hex>;
14
+ /**
15
+ * Validates parameters against a Superstruct schema and throws an error if validation fails.
16
+ *
17
+ * @param value - The value to validate against the struct schema.
18
+ * @param struct - The Superstruct schema to validate against.
19
+ * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.
20
+ */
21
+ export declare function validateParams<ParamsType>(value: unknown | ParamsType, struct: Struct<ParamsType>): asserts value is ParamsType;
22
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAe,8BAA8B;AAEjE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,MAAM,EACd,6BAA6B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,GACnE,OAAO,CAAC,GAAG,CAAC,CAyBd;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EACvC,KAAK,EAAE,OAAO,GAAG,UAAU,EAC3B,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,GACzB,OAAO,CAAC,KAAK,IAAI,UAAU,CAQ7B"}
@@ -0,0 +1,22 @@
1
+ import type { Struct } from "@metamask/superstruct";
2
+ import type { Hex } from "@metamask/utils";
3
+ /**
4
+ * Validates address format, checks user eth_accounts permissions.
5
+ *
6
+ * @param address - The Ethereum address to validate and normalize.
7
+ * @param origin - The origin string for permission checking.
8
+ * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.
9
+ * @returns A normalized (lowercase) hex address if valid and authorized.
10
+ * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.
11
+ * @throws JsonRpcError with invalid params if the address format is invalid.
12
+ */
13
+ export declare function validateAndNormalizeAddress(address: Hex, origin: string, getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>): Promise<Hex>;
14
+ /**
15
+ * Validates parameters against a Superstruct schema and throws an error if validation fails.
16
+ *
17
+ * @param value - The value to validate against the struct schema.
18
+ * @param struct - The Superstruct schema to validate against.
19
+ * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.
20
+ */
21
+ export declare function validateParams<ParamsType>(value: unknown | ParamsType, struct: Struct<ParamsType>): asserts value is ParamsType;
22
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAe,8BAA8B;AAEjE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C;;;;;;;;;GASG;AACH,wBAAsB,2BAA2B,CAC/C,OAAO,EAAE,GAAG,EACZ,MAAM,EAAE,MAAM,EACd,6BAA6B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,GACnE,OAAO,CAAC,GAAG,CAAC,CAyBd;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,UAAU,EACvC,KAAK,EAAE,OAAO,GAAG,UAAU,EAC3B,MAAM,EAAE,MAAM,CAAC,UAAU,CAAC,GACzB,OAAO,CAAC,KAAK,IAAI,UAAU,CAQ7B"}
package/dist/utils.mjs ADDED
@@ -0,0 +1,58 @@
1
+ import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
2
+ import { validate } from "@metamask/superstruct";
3
+ import { isHexAddress } from "@metamask/utils";
4
+ /**
5
+ * Validates address format, checks user eth_accounts permissions.
6
+ *
7
+ * @param address - The Ethereum address to validate and normalize.
8
+ * @param origin - The origin string for permission checking.
9
+ * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.
10
+ * @returns A normalized (lowercase) hex address if valid and authorized.
11
+ * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.
12
+ * @throws JsonRpcError with invalid params if the address format is invalid.
13
+ */
14
+ export async function validateAndNormalizeAddress(address, origin, getPermittedAccountsForOrigin) {
15
+ if (typeof address !== 'string' ||
16
+ address.length === 0 ||
17
+ !isHexAddress(address)) {
18
+ throw rpcErrors.invalidParams({
19
+ message: `Invalid parameters: must provide an EVM address.`,
20
+ });
21
+ }
22
+ // Ensure that an "unauthorized" error is thrown if the requester
23
+ // does not have the `eth_accounts` permission.
24
+ const accounts = await getPermittedAccountsForOrigin(origin);
25
+ // Validate and convert each account address to normalized Hex
26
+ const normalizedAccounts = accounts.map((accountAddress) => accountAddress.toLowerCase());
27
+ if (!normalizedAccounts.includes(address.toLowerCase())) {
28
+ throw providerErrors.unauthorized();
29
+ }
30
+ return address;
31
+ }
32
+ /**
33
+ * Validates parameters against a Superstruct schema and throws an error if validation fails.
34
+ *
35
+ * @param value - The value to validate against the struct schema.
36
+ * @param struct - The Superstruct schema to validate against.
37
+ * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.
38
+ */
39
+ export function validateParams(value, struct) {
40
+ const [error] = validate(value, struct);
41
+ if (error) {
42
+ throw rpcErrors.invalidParams(formatValidationError(error, 'Invalid parameters'));
43
+ }
44
+ }
45
+ /**
46
+ * Formats a Superstruct validation error into a human-readable string.
47
+ *
48
+ * @param error - The Superstruct validation error to format.
49
+ * @param message - The base error message to prepend to the formatted details.
50
+ * @returns A formatted error message string with validation failure details.
51
+ */
52
+ function formatValidationError(error, message) {
53
+ return `${message}\n\n${error
54
+ .failures()
55
+ .map((f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`)
56
+ .join('\n')}`;
57
+ }
58
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAEjE,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAEjD,OAAO,EAAE,YAAY,EAAE,wBAAwB;AAE/C;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,2BAA2B,CAC/C,OAAY,EACZ,MAAc,EACd,6BAAoE;IAEpE,IACE,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,CAAC,MAAM,KAAK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amask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex } from '@metamask/utils';\nimport { isHexAddress } from '@metamask/utils';\n\n/**\n * Validates address format, checks user eth_accounts permissions.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param origin - The origin string for permission checking.\n * @param getPermittedAccountsForOrigin - Function to retrieve permitted accounts for the origin.\n * @returns A normalized (lowercase) hex address if valid and authorized.\n * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.\n * @throws JsonRpcError with invalid params if the address format is invalid.\n */\nexport async function validateAndNormalizeAddress(\n address: Hex,\n origin: string,\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>,\n): Promise<Hex> {\n if (\n typeof address !== 'string' ||\n address.length === 0 ||\n !isHexAddress(address)\n ) {\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an EVM address.`,\n });\n }\n\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getPermittedAccountsForOrigin(origin);\n\n // Validate and convert each account address to normalized Hex\n const normalizedAccounts: string[] = accounts.map((accountAddress) =>\n accountAddress.toLowerCase(),\n );\n\n if (!normalizedAccounts.includes(address.toLowerCase())) {\n throw providerErrors.unauthorized();\n }\n\n return address;\n}\n\n/**\n * Validates parameters against a Superstruct schema and throws an error if validation fails.\n *\n * @param value - The value to validate against the struct schema.\n * @param struct - The Superstruct schema to validate against.\n * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.\n */\nexport function validateParams<ParamsType>(\n value: unknown | ParamsType,\n struct: Struct<ParamsType>,\n): asserts value is ParamsType {\n const [error] = validate(value, struct);\n\n if (error) {\n throw rpcErrors.invalidParams(\n formatValidationError(error, 'Invalid parameters'),\n );\n }\n}\n\n/**\n * Formats a Superstruct validation error into a human-readable string.\n *\n * @param error - The Superstruct validation error to format.\n * @param message - The base error message to prepend to the formatted details.\n * @returns A formatted error message string with validation failure details.\n */\nfunction formatValidationError(error: StructError, message: string): string {\n return `${message}\\n\\n${error\n .failures()\n .map(\n (f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`,\n )\n .join('\\n')}`;\n}\n"]}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.walletGetAccountUpgradeStatus = void 0;
4
+ const rpc_errors_1 = require("@metamask/rpc-errors");
5
+ const utils_1 = require("@metamask/utils");
6
+ const constants_1 = require("./constants.cjs");
7
+ const types_1 = require("./types.cjs");
8
+ const utils_2 = require("./utils.cjs");
9
+ const isAccountUpgraded = async (address, networkClientId, getCode) => {
10
+ const code = await getCode(address, networkClientId);
11
+ if (!code || code === '0x' || code.length <= 2) {
12
+ return { isUpgraded: false, upgradedAddress: null };
13
+ }
14
+ if (!code.startsWith(constants_1.DELEGATION_INDICATOR_PREFIX)) {
15
+ return { isUpgraded: false, upgradedAddress: null };
16
+ }
17
+ const expectedLength = constants_1.DELEGATION_INDICATOR_PREFIX.length + 40; // 0xef0100 + 40 hex chars
18
+ if (code.length !== expectedLength) {
19
+ return { isUpgraded: false, upgradedAddress: null };
20
+ }
21
+ // Extract the 20-byte address (40 hex characters after the prefix)
22
+ const upgradedAddress = `0x${code.slice(8, 48)}`;
23
+ return { isUpgraded: true, upgradedAddress };
24
+ };
25
+ /**
26
+ * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`
27
+ *
28
+ * @param req - The JSON RPC request's end callback.
29
+ * @param res - The JSON RPC request's pending response object.
30
+ * @param hooks - The hooks required for account upgrade status checking.
31
+ */
32
+ async function walletGetAccountUpgradeStatus(req, res, hooks) {
33
+ const { params, origin } = req;
34
+ // Validate parameters using Superstruct
35
+ (0, utils_2.validateParams)(params, types_1.GetAccountUpgradeStatusParamsStruct);
36
+ const { account, chainId } = params;
37
+ // Validate and normalize the account address with authorization check
38
+ const normalizedAccount = await (0, utils_2.validateAndNormalizeAddress)(account, origin, hooks.getPermittedAccountsForOrigin);
39
+ // Use current chain ID if not provided
40
+ let targetChainId;
41
+ if (chainId !== undefined) {
42
+ targetChainId = chainId;
43
+ }
44
+ else {
45
+ const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);
46
+ if (!currentChainIdForDomain) {
47
+ throw rpc_errors_1.rpcErrors.invalidParams({
48
+ message: `Could not determine current chain ID for origin: ${origin}`,
49
+ });
50
+ }
51
+ targetChainId = currentChainIdForDomain;
52
+ }
53
+ const { isSupported } = await hooks.isEip7702Supported({
54
+ address: normalizedAccount,
55
+ chainId: targetChainId,
56
+ });
57
+ if (!isSupported) {
58
+ res.result = {
59
+ isSupported,
60
+ account: normalizedAccount,
61
+ isUpgraded: false,
62
+ upgradedAddress: null,
63
+ chainId: targetChainId,
64
+ };
65
+ return;
66
+ }
67
+ try {
68
+ // Get the network configuration for the target chain
69
+ const hexChainId = targetChainId;
70
+ const networkClientId = hooks.getSelectedNetworkClientIdForChain(hexChainId);
71
+ if (!networkClientId) {
72
+ throw rpc_errors_1.rpcErrors.invalidParams({
73
+ message: `Network client ID not found for chain ID ${targetChainId}`,
74
+ });
75
+ }
76
+ // Check if the account is upgraded using the EIP7702 utils
77
+ const { isUpgraded, upgradedAddress } = await isAccountUpgraded(normalizedAccount, networkClientId, hooks.getCode);
78
+ res.result = {
79
+ isSupported,
80
+ account: normalizedAccount,
81
+ isUpgraded,
82
+ upgradedAddress,
83
+ chainId: targetChainId,
84
+ };
85
+ }
86
+ catch (error) {
87
+ // Re-throw RPC errors as-is
88
+ if (error instanceof rpc_errors_1.JsonRpcError) {
89
+ throw error;
90
+ }
91
+ throw rpc_errors_1.rpcErrors.internal({
92
+ message: `Failed to get account upgrade status: ${(0, utils_1.getErrorMessage)(error)}`,
93
+ });
94
+ }
95
+ }
96
+ exports.walletGetAccountUpgradeStatus = walletGetAccountUpgradeStatus;
97
+ //# sourceMappingURL=wallet_getAccountUpgradeStatus.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet_getAccountUp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,EACf,KAAK,CAAC,OAAO,CACd,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG;YACX,WAAW;YACX,OAAO,EAAE,iBAAiB;YAC1B,UAAU;YACV,eAAe;YACf,OAAO,EAAE,aAAa;SACvB,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,4BAA4B;QAC5B,IAAI,KAAK,YAAY,yBAAY,EAAE;YACjC,MAAM,KAAK,CAAC;SACb;QACD,MAAM,sBAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,yCAAyC,IAAA,uBAAe,EAAC,KAAK,CAAC,EAAE;SAC3E,CAAC,CAAC;KACJ;AACH,CAAC;AApFD,sEAoFC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport {\n type JsonRpcRequest,\n type PendingJsonRpcResponse,\n type Hex,\n getErrorMessage,\n} from '@metamask/utils';\n\nimport { DELEGATION_INDICATOR_PREFIX } from './constants';\nimport type { GetAccountUpgradeStatusParams } from './types';\nimport { GetAccountUpgradeStatusParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletGetAccountUpgradeStatusHooks = {\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n getCode: (address: string, networkClientId: string) => Promise<string | null>;\n getSelectedNetworkClientIdForChain: (chainId: string) => string | null;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n};\n\nconst isAccountUpgraded = async (\n address: string,\n networkClientId: string,\n getCode: (address: string, networkClientId: string) => Promise<string | null>,\n): Promise<{ isUpgraded: boolean; upgradedAddress: Hex | null }> => {\n const code = await getCode(address, networkClientId);\n if (!code || code === '0x' || code.length <= 2) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n if (!code.startsWith(DELEGATION_INDICATOR_PREFIX)) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n const expectedLength = DELEGATION_INDICATOR_PREFIX.length + 40; // 0xef0100 + 40 hex chars\n if (code.length !== expectedLength) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n // Extract the 20-byte address (40 hex characters after the prefix)\n const upgradedAddress = `0x${code.slice(8, 48)}` as Hex;\n\n return { isUpgraded: true, upgradedAddress };\n};\n\n/**\n * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade status checking.\n */\nexport async function walletGetAccountUpgradeStatus(\n req: JsonRpcRequest<GetAccountUpgradeStatusParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletGetAccountUpgradeStatusHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, GetAccountUpgradeStatusParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current chain ID if not provided\n let targetChainId: Hex;\n if (chainId !== undefined) {\n targetChainId = chainId;\n } else {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `Could not determine current chain ID for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n }\n\n const { isSupported } = await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: targetChainId,\n });\n\n if (!isSupported) {\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded: false,\n upgradedAddress: null,\n chainId: targetChainId,\n };\n return;\n }\n\n try {\n // Get the network configuration for the target chain\n const hexChainId = targetChainId;\n const networkClientId =\n hooks.getSelectedNetworkClientIdForChain(hexChainId);\n\n if (!networkClientId) {\n throw rpcErrors.invalidParams({\n message: `Network client ID not found for chain ID ${targetChainId}`,\n });\n }\n\n // Check if the account is upgraded using the EIP7702 utils\n const { isUpgraded, upgradedAddress } = await isAccountUpgraded(\n normalizedAccount,\n networkClientId,\n hooks.getCode,\n );\n\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded,\n upgradedAddress,\n chainId: targetChainId,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to get account upgrade status: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ import { type JsonRpcRequest, type PendingJsonRpcResponse, type Hex } from "@metamask/utils";
2
+ import type { GetAccountUpgradeStatusParams } from "./types.cjs";
3
+ export type WalletGetAccountUpgradeStatusHooks = {
4
+ getCurrentChainIdForDomain: (origin: string) => Hex | null;
5
+ getCode: (address: string, networkClientId: string) => Promise<string | null>;
6
+ getSelectedNetworkClientIdForChain: (chainId: string) => string | null;
7
+ getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;
8
+ isEip7702Supported: (request: {
9
+ address: string;
10
+ chainId: Hex;
11
+ }) => Promise<{
12
+ isSupported: boolean;
13
+ upgradeContractAddress?: string;
14
+ }>;
15
+ };
16
+ /**
17
+ * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`
18
+ *
19
+ * @param req - The JSON RPC request's end callback.
20
+ * @param res - The JSON RPC request's pending response object.
21
+ * @param hooks - The hooks required for account upgrade status checking.
22
+ */
23
+ export declare function walletGetAccountUpgradeStatus(req: JsonRpcRequest<GetAccountUpgradeStatusParams> & {
24
+ origin: string;
25
+ }, res: PendingJsonRpcResponse, hooks: WalletGetAccountUpgradeStatusHooks): Promise<void>;
26
+ //# sourceMappingURL=wallet_getAccountUpgradeStatus.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet_getAccountUpgradeStatus.d.cts","sourceRoot":"","sources":["../src/wallet_getAccountUpgradeStatus.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,GAAG,EAET,wBAAwB;AAGzB,OAAO,KAAK,EAAE,6BAA6B,EAAE,oBAAgB;AAI7D,MAAM,MAAM,kCAAkC,GAAG;IAC/C,0BAA0B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC;IAC3D,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9E,kCAAkC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACvE,6BAA6B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACrE,kBAAkB,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC;QAC1E,WAAW,EAAE,OAAO,CAAC;QACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,CAAC,CAAC;CACJ,CAAC;AA2BF;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,cAAc,CAAC,6BAA6B,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EACvE,GAAG,EAAE,sBAAsB,EAC3B,KAAK,EAAE,kCAAkC,GACxC,OAAO,CAAC,IAAI,CAAC,CAgFf"}
@@ -0,0 +1,26 @@
1
+ import { type JsonRpcRequest, type PendingJsonRpcResponse, type Hex } from "@metamask/utils";
2
+ import type { GetAccountUpgradeStatusParams } from "./types.mjs";
3
+ export type WalletGetAccountUpgradeStatusHooks = {
4
+ getCurrentChainIdForDomain: (origin: string) => Hex | null;
5
+ getCode: (address: string, networkClientId: string) => Promise<string | null>;
6
+ getSelectedNetworkClientIdForChain: (chainId: string) => string | null;
7
+ getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;
8
+ isEip7702Supported: (request: {
9
+ address: string;
10
+ chainId: Hex;
11
+ }) => Promise<{
12
+ isSupported: boolean;
13
+ upgradeContractAddress?: string;
14
+ }>;
15
+ };
16
+ /**
17
+ * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`
18
+ *
19
+ * @param req - The JSON RPC request's end callback.
20
+ * @param res - The JSON RPC request's pending response object.
21
+ * @param hooks - The hooks required for account upgrade status checking.
22
+ */
23
+ export declare function walletGetAccountUpgradeStatus(req: JsonRpcRequest<GetAccountUpgradeStatusParams> & {
24
+ origin: string;
25
+ }, res: PendingJsonRpcResponse, hooks: WalletGetAccountUpgradeStatusHooks): Promise<void>;
26
+ //# sourceMappingURL=wallet_getAccountUpgradeStatus.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet_getAccountUpgradeStatus.d.mts","sourceRoot":"","sources":["../src/wallet_getAccountUpgradeStatus.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,sBAAsB,EAC3B,KAAK,GAAG,EAET,wBAAwB;AAGzB,OAAO,KAAK,EAAE,6BAA6B,EAAE,oBAAgB;AAI7D,MAAM,MAAM,kCAAkC,GAAG;IAC/C,0BAA0B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC;IAC3D,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC9E,kCAAkC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,MAAM,GAAG,IAAI,CAAC;IACvE,6BAA6B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACrE,kBAAkB,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC;QAC1E,WAAW,EAAE,OAAO,CAAC;QACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,CAAC,CAAC;CACJ,CAAC;AA2BF;;;;;;GAMG;AACH,wBAAsB,6BAA6B,CACjD,GAAG,EAAE,cAAc,CAAC,6BAA6B,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EACvE,GAAG,EAAE,sBAAsB,EAC3B,KAAK,EAAE,kCAAkC,GACxC,OAAO,CAAC,IAAI,CAAC,CAgFf"}
@@ -0,0 +1,93 @@
1
+ import { JsonRpcError, rpcErrors } from "@metamask/rpc-errors";
2
+ import { getErrorMessage } from "@metamask/utils";
3
+ import { DELEGATION_INDICATOR_PREFIX } from "./constants.mjs";
4
+ import { GetAccountUpgradeStatusParamsStruct } from "./types.mjs";
5
+ import { validateParams, validateAndNormalizeAddress } from "./utils.mjs";
6
+ const isAccountUpgraded = async (address, networkClientId, getCode) => {
7
+ const code = await getCode(address, networkClientId);
8
+ if (!code || code === '0x' || code.length <= 2) {
9
+ return { isUpgraded: false, upgradedAddress: null };
10
+ }
11
+ if (!code.startsWith(DELEGATION_INDICATOR_PREFIX)) {
12
+ return { isUpgraded: false, upgradedAddress: null };
13
+ }
14
+ const expectedLength = DELEGATION_INDICATOR_PREFIX.length + 40; // 0xef0100 + 40 hex chars
15
+ if (code.length !== expectedLength) {
16
+ return { isUpgraded: false, upgradedAddress: null };
17
+ }
18
+ // Extract the 20-byte address (40 hex characters after the prefix)
19
+ const upgradedAddress = `0x${code.slice(8, 48)}`;
20
+ return { isUpgraded: true, upgradedAddress };
21
+ };
22
+ /**
23
+ * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`
24
+ *
25
+ * @param req - The JSON RPC request's end callback.
26
+ * @param res - The JSON RPC request's pending response object.
27
+ * @param hooks - The hooks required for account upgrade status checking.
28
+ */
29
+ export async function walletGetAccountUpgradeStatus(req, res, hooks) {
30
+ const { params, origin } = req;
31
+ // Validate parameters using Superstruct
32
+ validateParams(params, GetAccountUpgradeStatusParamsStruct);
33
+ const { account, chainId } = params;
34
+ // Validate and normalize the account address with authorization check
35
+ const normalizedAccount = await validateAndNormalizeAddress(account, origin, hooks.getPermittedAccountsForOrigin);
36
+ // Use current chain ID if not provided
37
+ let targetChainId;
38
+ if (chainId !== undefined) {
39
+ targetChainId = chainId;
40
+ }
41
+ else {
42
+ const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);
43
+ if (!currentChainIdForDomain) {
44
+ throw rpcErrors.invalidParams({
45
+ message: `Could not determine current chain ID for origin: ${origin}`,
46
+ });
47
+ }
48
+ targetChainId = currentChainIdForDomain;
49
+ }
50
+ const { isSupported } = await hooks.isEip7702Supported({
51
+ address: normalizedAccount,
52
+ chainId: targetChainId,
53
+ });
54
+ if (!isSupported) {
55
+ res.result = {
56
+ isSupported,
57
+ account: normalizedAccount,
58
+ isUpgraded: false,
59
+ upgradedAddress: null,
60
+ chainId: targetChainId,
61
+ };
62
+ return;
63
+ }
64
+ try {
65
+ // Get the network configuration for the target chain
66
+ const hexChainId = targetChainId;
67
+ const networkClientId = hooks.getSelectedNetworkClientIdForChain(hexChainId);
68
+ if (!networkClientId) {
69
+ throw rpcErrors.invalidParams({
70
+ message: `Network client ID not found for chain ID ${targetChainId}`,
71
+ });
72
+ }
73
+ // Check if the account is upgraded using the EIP7702 utils
74
+ const { isUpgraded, upgradedAddress } = await isAccountUpgraded(normalizedAccount, networkClientId, hooks.getCode);
75
+ res.result = {
76
+ isSupported,
77
+ account: normalizedAccount,
78
+ isUpgraded,
79
+ upgradedAddress,
80
+ chainId: targetChainId,
81
+ };
82
+ }
83
+ catch (error) {
84
+ // Re-throw RPC errors as-is
85
+ if (error instanceof JsonRpcError) {
86
+ throw error;
87
+ }
88
+ throw rpcErrors.internal({
89
+ message: `Failed to get account upgrade status: ${getErrorMessage(error)}`,
90
+ });
91
+ }
92
+ }
93
+ //# sourceMappingURL=wallet_getAccountUpgradeStatus.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet_get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AE,4CAA4C,aAAa,EAAE;aACrE,CAAC,CAAC;SACJ;QAED,2DAA2D;QAC3D,MAAM,EAAE,UAAU,EAAE,eAAe,EAAE,GAAG,MAAM,iBAAiB,CAC7D,iBAAiB,EACjB,eAAe,EACf,KAAK,CAAC,OAAO,CACd,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG;YACX,WAAW;YACX,OAAO,EAAE,iBAAiB;YAC1B,UAAU;YACV,eAAe;YACf,OAAO,EAAE,aAAa;SACvB,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,4BAA4B;QAC5B,IAAI,KAAK,YAAY,YAAY,EAAE;YACjC,MAAM,KAAK,CAAC;SACb;QACD,MAAM,SAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,yCAAyC,eAAe,CAAC,KAAK,CAAC,EAAE;SAC3E,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport {\n type JsonRpcRequest,\n type PendingJsonRpcResponse,\n type Hex,\n getErrorMessage,\n} from '@metamask/utils';\n\nimport { DELEGATION_INDICATOR_PREFIX } from './constants';\nimport type { GetAccountUpgradeStatusParams } from './types';\nimport { GetAccountUpgradeStatusParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletGetAccountUpgradeStatusHooks = {\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n getCode: (address: string, networkClientId: string) => Promise<string | null>;\n getSelectedNetworkClientIdForChain: (chainId: string) => string | null;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n};\n\nconst isAccountUpgraded = async (\n address: string,\n networkClientId: string,\n getCode: (address: string, networkClientId: string) => Promise<string | null>,\n): Promise<{ isUpgraded: boolean; upgradedAddress: Hex | null }> => {\n const code = await getCode(address, networkClientId);\n if (!code || code === '0x' || code.length <= 2) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n if (!code.startsWith(DELEGATION_INDICATOR_PREFIX)) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n const expectedLength = DELEGATION_INDICATOR_PREFIX.length + 40; // 0xef0100 + 40 hex chars\n if (code.length !== expectedLength) {\n return { isUpgraded: false, upgradedAddress: null };\n }\n\n // Extract the 20-byte address (40 hex characters after the prefix)\n const upgradedAddress = `0x${code.slice(8, 48)}` as Hex;\n\n return { isUpgraded: true, upgradedAddress };\n};\n\n/**\n * The RPC method handler middleware for `wallet_getAccountUpgradeStatus`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade status checking.\n */\nexport async function walletGetAccountUpgradeStatus(\n req: JsonRpcRequest<GetAccountUpgradeStatusParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletGetAccountUpgradeStatusHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, GetAccountUpgradeStatusParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current chain ID if not provided\n let targetChainId: Hex;\n if (chainId !== undefined) {\n targetChainId = chainId;\n } else {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `Could not determine current chain ID for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n }\n\n const { isSupported } = await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: targetChainId,\n });\n\n if (!isSupported) {\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded: false,\n upgradedAddress: null,\n chainId: targetChainId,\n };\n return;\n }\n\n try {\n // Get the network configuration for the target chain\n const hexChainId = targetChainId;\n const networkClientId =\n hooks.getSelectedNetworkClientIdForChain(hexChainId);\n\n if (!networkClientId) {\n throw rpcErrors.invalidParams({\n message: `Network client ID not found for chain ID ${targetChainId}`,\n });\n }\n\n // Check if the account is upgraded using the EIP7702 utils\n const { isUpgraded, upgradedAddress } = await isAccountUpgraded(\n normalizedAccount,\n networkClientId,\n hooks.getCode,\n );\n\n res.result = {\n isSupported,\n account: normalizedAccount,\n isUpgraded,\n upgradedAddress,\n chainId: targetChainId,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to get account upgrade status: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.walletUpgradeAccount = void 0;
4
+ const rpc_errors_1 = require("@metamask/rpc-errors");
5
+ const types_1 = require("./types.cjs");
6
+ const utils_1 = require("./utils.cjs");
7
+ /**
8
+ * The RPC method handler middleware for `wallet_upgradeAccount`
9
+ *
10
+ * @param req - The JSON RPC request's end callback.
11
+ * @param res - The JSON RPC request's pending response object.
12
+ * @param hooks - The hooks required for account upgrade functionality.
13
+ */
14
+ async function walletUpgradeAccount(req, res, hooks) {
15
+ const { params, origin } = req;
16
+ // Validate parameters using Superstruct
17
+ (0, utils_1.validateParams)(params, types_1.UpgradeAccountParamsStruct);
18
+ const { account, chainId } = params;
19
+ // Validate and normalize the account address with authorization check
20
+ const normalizedAccount = await (0, utils_1.validateAndNormalizeAddress)(account, origin, hooks.getPermittedAccountsForOrigin);
21
+ // Use current app selected chain ID if not passed as a param
22
+ let targetChainId;
23
+ if (chainId !== undefined) {
24
+ targetChainId = chainId;
25
+ }
26
+ else {
27
+ const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);
28
+ if (!currentChainIdForDomain) {
29
+ throw rpc_errors_1.rpcErrors.invalidParams({
30
+ message: `No network configuration found for origin: ${origin}`,
31
+ });
32
+ }
33
+ targetChainId = currentChainIdForDomain;
34
+ }
35
+ try {
36
+ // Get the EIP7702 network configuration for the target chain
37
+ const hexChainId = targetChainId;
38
+ const { isSupported, upgradeContractAddress } = await hooks.isEip7702Supported({
39
+ address: normalizedAccount,
40
+ chainId: hexChainId,
41
+ });
42
+ if (!isSupported) {
43
+ throw rpc_errors_1.rpcErrors.invalidParams({
44
+ message: `Account upgrade not supported on chain ID ${targetChainId}`,
45
+ });
46
+ }
47
+ if (!upgradeContractAddress) {
48
+ throw rpc_errors_1.rpcErrors.invalidParams({
49
+ message: `No upgrade contract address available for chain ID ${targetChainId}`,
50
+ });
51
+ }
52
+ // Perform the upgrade using existing EIP-7702 functionality
53
+ const result = await hooks.upgradeAccount(normalizedAccount, upgradeContractAddress, targetChainId);
54
+ res.result = {
55
+ transactionHash: result.transactionHash,
56
+ upgradedAccount: normalizedAccount,
57
+ delegatedTo: result.delegatedTo,
58
+ };
59
+ }
60
+ catch (error) {
61
+ // Re-throw RPC errors as-is
62
+ if (error instanceof rpc_errors_1.JsonRpcError) {
63
+ throw error;
64
+ }
65
+ throw rpc_errors_1.rpcErrors.internal({
66
+ message: `Failed to upgrade account: ${error instanceof Error ? error.message : String(error)}`,
67
+ });
68
+ }
69
+ }
70
+ exports.walletUpgradeAccount = walletUpgradeAccount;
71
+ //# sourceMappingURL=wallet_upgradeAccount.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet_upgradeAccount.cjs","sourceRoot":"","sources":["../src/wallet_upgradeAccount.ts"],"names":[],"mappings":";;;AAAA,qDAA+D;AAQ/D,uCAAqD;AACrD,uCAAsE;AAgBtE;;;;;;GAMG;AACI,KAAK,UAAU,oBAAoB,CACxC,GAA8D,EAC9D,GAA2B,EAC3B,KAAgC;IAEhC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,wCAAwC;IACxC,IAAA,sBAAc,EAAC,MAAM,EAAE,kCAA0B,CAAC,CAAC;IAEnD,MAAM,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AW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,4BAA4B;QAC5B,IAAI,KAAK,YAAY,yBAAY,EAAE;YACjC,MAAM,KAAK,CAAC;SACb;QACD,MAAM,sBAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;SAChG,CAAC,CAAC;KACJ;AACH,CAAC;AA3ED,oDA2EC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport type { UpgradeAccountParams } from './types';\nimport { UpgradeAccountParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletUpgradeAccountHooks = {\n upgradeAccount: (\n address: string,\n upgradeContractAddress: string,\n chainId?: Hex,\n ) => Promise<{ transactionHash: string; delegatedTo: string }>;\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n};\n\n/**\n * The RPC method handler middleware for `wallet_upgradeAccount`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade functionality.\n */\nexport async function walletUpgradeAccount(\n req: JsonRpcRequest<UpgradeAccountParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletUpgradeAccountHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, UpgradeAccountParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current app selected chain ID if not passed as a param\n let targetChainId: Hex;\n if (chainId !== undefined) {\n targetChainId = chainId;\n } else {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `No network configuration found for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n }\n\n try {\n // Get the EIP7702 network configuration for the target chain\n const hexChainId = targetChainId;\n const { isSupported, upgradeContractAddress } =\n await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: hexChainId,\n });\n\n if (!isSupported) {\n throw rpcErrors.invalidParams({\n message: `Account upgrade not supported on chain ID ${targetChainId}`,\n });\n }\n\n if (!upgradeContractAddress) {\n throw rpcErrors.invalidParams({\n message: `No upgrade contract address available for chain ID ${targetChainId}`,\n });\n }\n\n // Perform the upgrade using existing EIP-7702 functionality\n const result = await hooks.upgradeAccount(\n normalizedAccount,\n upgradeContractAddress,\n targetChainId,\n );\n\n res.result = {\n transactionHash: result.transactionHash,\n upgradedAccount: normalizedAccount,\n delegatedTo: result.delegatedTo,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to upgrade account: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n"]}
@@ -0,0 +1,28 @@
1
+ import type { JsonRpcRequest, PendingJsonRpcResponse, Hex } from "@metamask/utils";
2
+ import type { UpgradeAccountParams } from "./types.cjs";
3
+ export type WalletUpgradeAccountHooks = {
4
+ upgradeAccount: (address: string, upgradeContractAddress: string, chainId?: Hex) => Promise<{
5
+ transactionHash: string;
6
+ delegatedTo: string;
7
+ }>;
8
+ getCurrentChainIdForDomain: (origin: string) => Hex | null;
9
+ isEip7702Supported: (request: {
10
+ address: string;
11
+ chainId: Hex;
12
+ }) => Promise<{
13
+ isSupported: boolean;
14
+ upgradeContractAddress?: string;
15
+ }>;
16
+ getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;
17
+ };
18
+ /**
19
+ * The RPC method handler middleware for `wallet_upgradeAccount`
20
+ *
21
+ * @param req - The JSON RPC request's end callback.
22
+ * @param res - The JSON RPC request's pending response object.
23
+ * @param hooks - The hooks required for account upgrade functionality.
24
+ */
25
+ export declare function walletUpgradeAccount(req: JsonRpcRequest<UpgradeAccountParams> & {
26
+ origin: string;
27
+ }, res: PendingJsonRpcResponse, hooks: WalletUpgradeAccountHooks): Promise<void>;
28
+ //# sourceMappingURL=wallet_upgradeAccount.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet_upgradeAccount.d.cts","sourceRoot":"","sources":["../src/wallet_upgradeAccount.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,GAAG,EACJ,wBAAwB;AAEzB,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAgB;AAIpD,MAAM,MAAM,yBAAyB,GAAG;IACtC,cAAc,EAAE,CACd,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,OAAO,CAAC,EAAE,GAAG,KACV,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/D,0BAA0B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC;IAC3D,kBAAkB,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC;QAC1E,WAAW,EAAE,OAAO,CAAC;QACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,CAAC,CAAC;IACH,6BAA6B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACtE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,cAAc,CAAC,oBAAoB,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAC9D,GAAG,EAAE,sBAAsB,EAC3B,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAuEf"}
@@ -0,0 +1,28 @@
1
+ import type { JsonRpcRequest, PendingJsonRpcResponse, Hex } from "@metamask/utils";
2
+ import type { UpgradeAccountParams } from "./types.mjs";
3
+ export type WalletUpgradeAccountHooks = {
4
+ upgradeAccount: (address: string, upgradeContractAddress: string, chainId?: Hex) => Promise<{
5
+ transactionHash: string;
6
+ delegatedTo: string;
7
+ }>;
8
+ getCurrentChainIdForDomain: (origin: string) => Hex | null;
9
+ isEip7702Supported: (request: {
10
+ address: string;
11
+ chainId: Hex;
12
+ }) => Promise<{
13
+ isSupported: boolean;
14
+ upgradeContractAddress?: string;
15
+ }>;
16
+ getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;
17
+ };
18
+ /**
19
+ * The RPC method handler middleware for `wallet_upgradeAccount`
20
+ *
21
+ * @param req - The JSON RPC request's end callback.
22
+ * @param res - The JSON RPC request's pending response object.
23
+ * @param hooks - The hooks required for account upgrade functionality.
24
+ */
25
+ export declare function walletUpgradeAccount(req: JsonRpcRequest<UpgradeAccountParams> & {
26
+ origin: string;
27
+ }, res: PendingJsonRpcResponse, hooks: WalletUpgradeAccountHooks): Promise<void>;
28
+ //# sourceMappingURL=wallet_upgradeAccount.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet_upgradeAccount.d.mts","sourceRoot":"","sources":["../src/wallet_upgradeAccount.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,sBAAsB,EACtB,GAAG,EACJ,wBAAwB;AAEzB,OAAO,KAAK,EAAE,oBAAoB,EAAE,oBAAgB;AAIpD,MAAM,MAAM,yBAAyB,GAAG;IACtC,cAAc,EAAE,CACd,OAAO,EAAE,MAAM,EACf,sBAAsB,EAAE,MAAM,EAC9B,OAAO,CAAC,EAAE,GAAG,KACV,OAAO,CAAC;QAAE,eAAe,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IAC/D,0BAA0B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,GAAG,GAAG,IAAI,CAAC;IAC3D,kBAAkB,EAAE,CAAC,OAAO,EAAE;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,KAAK,OAAO,CAAC;QAC1E,WAAW,EAAE,OAAO,CAAC;QACrB,sBAAsB,CAAC,EAAE,MAAM,CAAC;KACjC,CAAC,CAAC;IACH,6BAA6B,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;CACtE,CAAC;AAEF;;;;;;GAMG;AACH,wBAAsB,oBAAoB,CACxC,GAAG,EAAE,cAAc,CAAC,oBAAoB,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EAC9D,GAAG,EAAE,sBAAsB,EAC3B,KAAK,EAAE,yBAAyB,GAC/B,OAAO,CAAC,IAAI,CAAC,CAuEf"}
@@ -0,0 +1,67 @@
1
+ import { JsonRpcError, rpcErrors } from "@metamask/rpc-errors";
2
+ import { UpgradeAccountParamsStruct } from "./types.mjs";
3
+ import { validateParams, validateAndNormalizeAddress } from "./utils.mjs";
4
+ /**
5
+ * The RPC method handler middleware for `wallet_upgradeAccount`
6
+ *
7
+ * @param req - The JSON RPC request's end callback.
8
+ * @param res - The JSON RPC request's pending response object.
9
+ * @param hooks - The hooks required for account upgrade functionality.
10
+ */
11
+ export async function walletUpgradeAccount(req, res, hooks) {
12
+ const { params, origin } = req;
13
+ // Validate parameters using Superstruct
14
+ validateParams(params, UpgradeAccountParamsStruct);
15
+ const { account, chainId } = params;
16
+ // Validate and normalize the account address with authorization check
17
+ const normalizedAccount = await validateAndNormalizeAddress(account, origin, hooks.getPermittedAccountsForOrigin);
18
+ // Use current app selected chain ID if not passed as a param
19
+ let targetChainId;
20
+ if (chainId !== undefined) {
21
+ targetChainId = chainId;
22
+ }
23
+ else {
24
+ const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);
25
+ if (!currentChainIdForDomain) {
26
+ throw rpcErrors.invalidParams({
27
+ message: `No network configuration found for origin: ${origin}`,
28
+ });
29
+ }
30
+ targetChainId = currentChainIdForDomain;
31
+ }
32
+ try {
33
+ // Get the EIP7702 network configuration for the target chain
34
+ const hexChainId = targetChainId;
35
+ const { isSupported, upgradeContractAddress } = await hooks.isEip7702Supported({
36
+ address: normalizedAccount,
37
+ chainId: hexChainId,
38
+ });
39
+ if (!isSupported) {
40
+ throw rpcErrors.invalidParams({
41
+ message: `Account upgrade not supported on chain ID ${targetChainId}`,
42
+ });
43
+ }
44
+ if (!upgradeContractAddress) {
45
+ throw rpcErrors.invalidParams({
46
+ message: `No upgrade contract address available for chain ID ${targetChainId}`,
47
+ });
48
+ }
49
+ // Perform the upgrade using existing EIP-7702 functionality
50
+ const result = await hooks.upgradeAccount(normalizedAccount, upgradeContractAddress, targetChainId);
51
+ res.result = {
52
+ transactionHash: result.transactionHash,
53
+ upgradedAccount: normalizedAccount,
54
+ delegatedTo: result.delegatedTo,
55
+ };
56
+ }
57
+ catch (error) {
58
+ // Re-throw RPC errors as-is
59
+ if (error instanceof JsonRpcError) {
60
+ throw error;
61
+ }
62
+ throw rpcErrors.internal({
63
+ message: `Failed to upgrade account: ${error instanceof Error ? error.message : String(error)}`,
64
+ });
65
+ }
66
+ }
67
+ //# sourceMappingURL=wallet_upgradeAccount.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet_upgradeAccount.mjs","sourceRoot":"","sources":["../src/wallet_upgradeAccount.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B;AAQ/D,OAAO,EAAE,0BAA0B,EAAE,oBAAgB;AACrD,OAA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B,OAAO,EAAE,sDAAsD,aAAa,EAAE;aAC/E,CAAC,CAAC;SACJ;QAED,4DAA4D;QAC5D,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,cAAc,CACvC,iBAAiB,EACjB,sBAAsB,EACtB,aAAa,CACd,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG;YACX,eAAe,EAAE,MAAM,CAAC,eAAe;YACvC,eAAe,EAAE,iBAAiB;YAClC,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAC;KACH;IAAC,OAAO,KAAK,EAAE;QACd,4BAA4B;QAC5B,IAAI,KAAK,YAAY,YAAY,EAAE;YACjC,MAAM,KAAK,CAAC;SACb;QACD,MAAM,SAAS,CAAC,QAAQ,CAAC;YACvB,OAAO,EAAE,8BAA8B,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE;SAChG,CAAC,CAAC;KACJ;AACH,CAAC","sourcesContent":["import { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n JsonRpcRequest,\n PendingJsonRpcResponse,\n Hex,\n} from '@metamask/utils';\n\nimport type { UpgradeAccountParams } from './types';\nimport { UpgradeAccountParamsStruct } from './types';\nimport { validateParams, validateAndNormalizeAddress } from './utils';\n\nexport type WalletUpgradeAccountHooks = {\n upgradeAccount: (\n address: string,\n upgradeContractAddress: string,\n chainId?: Hex,\n ) => Promise<{ transactionHash: string; delegatedTo: string }>;\n getCurrentChainIdForDomain: (origin: string) => Hex | null;\n isEip7702Supported: (request: { address: string; chainId: Hex }) => Promise<{\n isSupported: boolean;\n upgradeContractAddress?: string;\n }>;\n getPermittedAccountsForOrigin: (origin: string) => Promise<string[]>;\n};\n\n/**\n * The RPC method handler middleware for `wallet_upgradeAccount`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks required for account upgrade functionality.\n */\nexport async function walletUpgradeAccount(\n req: JsonRpcRequest<UpgradeAccountParams> & { origin: string },\n res: PendingJsonRpcResponse,\n hooks: WalletUpgradeAccountHooks,\n): Promise<void> {\n const { params, origin } = req;\n\n // Validate parameters using Superstruct\n validateParams(params, UpgradeAccountParamsStruct);\n\n const { account, chainId } = params;\n\n // Validate and normalize the account address with authorization check\n const normalizedAccount = await validateAndNormalizeAddress(\n account,\n origin,\n hooks.getPermittedAccountsForOrigin,\n );\n\n // Use current app selected chain ID if not passed as a param\n let targetChainId: Hex;\n if (chainId !== undefined) {\n targetChainId = chainId;\n } else {\n const currentChainIdForDomain = hooks.getCurrentChainIdForDomain(origin);\n if (!currentChainIdForDomain) {\n throw rpcErrors.invalidParams({\n message: `No network configuration found for origin: ${origin}`,\n });\n }\n targetChainId = currentChainIdForDomain;\n }\n\n try {\n // Get the EIP7702 network configuration for the target chain\n const hexChainId = targetChainId;\n const { isSupported, upgradeContractAddress } =\n await hooks.isEip7702Supported({\n address: normalizedAccount,\n chainId: hexChainId,\n });\n\n if (!isSupported) {\n throw rpcErrors.invalidParams({\n message: `Account upgrade not supported on chain ID ${targetChainId}`,\n });\n }\n\n if (!upgradeContractAddress) {\n throw rpcErrors.invalidParams({\n message: `No upgrade contract address available for chain ID ${targetChainId}`,\n });\n }\n\n // Perform the upgrade using existing EIP-7702 functionality\n const result = await hooks.upgradeAccount(\n normalizedAccount,\n upgradeContractAddress,\n targetChainId,\n );\n\n res.result = {\n transactionHash: result.transactionHash,\n upgradedAccount: normalizedAccount,\n delegatedTo: result.delegatedTo,\n };\n } catch (error) {\n // Re-throw RPC errors as-is\n if (error instanceof JsonRpcError) {\n throw error;\n }\n throw rpcErrors.internal({\n message: `Failed to upgrade account: ${error instanceof Error ? error.message : String(error)}`,\n });\n }\n}\n"]}
package/package.json ADDED
@@ -0,0 +1,72 @@
1
+ {
2
+ "name": "@metamask-previews/eip-7702-internal-rpc-middleware",
3
+ "version": "0.0.0-preview-8504447",
4
+ "description": "Implements internal JSON-RPC methods for EIP-7702 account upgrade functionality",
5
+ "keywords": [
6
+ "MetaMask",
7
+ "Ethereum"
8
+ ],
9
+ "homepage": "https://github.com/MetaMask/core/tree/main/packages/eip-7702-internal-rpc-middleware#readme",
10
+ "bugs": {
11
+ "url": "https://github.com/MetaMask/core/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/MetaMask/core.git"
16
+ },
17
+ "license": "MIT",
18
+ "sideEffects": false,
19
+ "exports": {
20
+ ".": {
21
+ "import": {
22
+ "types": "./dist/index.d.mts",
23
+ "default": "./dist/index.mjs"
24
+ },
25
+ "require": {
26
+ "types": "./dist/index.d.cts",
27
+ "default": "./dist/index.cjs"
28
+ }
29
+ },
30
+ "./package.json": "./package.json"
31
+ },
32
+ "main": "./dist/index.cjs",
33
+ "types": "./dist/index.d.cts",
34
+ "files": [
35
+ "dist/"
36
+ ],
37
+ "scripts": {
38
+ "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
39
+ "build:docs": "typedoc",
40
+ "changelog:update": "../../scripts/update-changelog.sh @metamask/eip-7702-internal-rpc-middleware",
41
+ "changelog:validate": "../../scripts/validate-changelog.sh @metamask/eip-7702-internal-rpc-middleware",
42
+ "publish:preview": "yarn npm publish --tag preview",
43
+ "since-latest-release": "../../scripts/since-latest-release.sh",
44
+ "test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
45
+ "test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
46
+ "test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
47
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
48
+ },
49
+ "dependencies": {
50
+ "@metamask/controller-utils": "^11.14.1",
51
+ "@metamask/rpc-errors": "^7.0.2",
52
+ "@metamask/superstruct": "^3.1.0",
53
+ "@metamask/utils": "^11.8.1"
54
+ },
55
+ "devDependencies": {
56
+ "@metamask/auto-changelog": "^3.4.4",
57
+ "@types/jest": "^27.4.1",
58
+ "deepmerge": "^4.2.2",
59
+ "jest": "^27.5.1",
60
+ "ts-jest": "^27.1.4",
61
+ "typedoc": "^0.24.8",
62
+ "typedoc-plugin-missing-exports": "^2.0.0",
63
+ "typescript": "~5.2.2"
64
+ },
65
+ "engines": {
66
+ "node": "^18.18 || >=20"
67
+ },
68
+ "publishConfig": {
69
+ "access": "public",
70
+ "registry": "https://registry.npmjs.org/"
71
+ }
72
+ }