@metamask/money-account-upgrade-controller 1.0.0 → 1.2.0
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.
- package/CHANGELOG.md +19 -1
- package/dist/MoneyAccountUpgradeController.cjs +18 -11
- package/dist/MoneyAccountUpgradeController.cjs.map +1 -1
- package/dist/MoneyAccountUpgradeController.d.cts +6 -5
- package/dist/MoneyAccountUpgradeController.d.cts.map +1 -1
- package/dist/MoneyAccountUpgradeController.d.mts +6 -5
- package/dist/MoneyAccountUpgradeController.d.mts.map +1 -1
- package/dist/MoneyAccountUpgradeController.mjs +18 -11
- package/dist/MoneyAccountUpgradeController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +0 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +0 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/{associate-address.cjs → steps/associate-address.cjs} +1 -1
- package/dist/steps/associate-address.cjs.map +1 -0
- package/dist/steps/associate-address.d.cts.map +1 -0
- package/dist/steps/associate-address.d.mts.map +1 -0
- package/dist/{associate-address.mjs → steps/associate-address.mjs} +1 -1
- package/dist/steps/associate-address.mjs.map +1 -0
- package/dist/steps/eip-7702-authorization.cjs +154 -0
- package/dist/steps/eip-7702-authorization.cjs.map +1 -0
- package/dist/steps/eip-7702-authorization.d.cts +21 -0
- package/dist/steps/eip-7702-authorization.d.cts.map +1 -0
- package/dist/steps/eip-7702-authorization.d.mts +21 -0
- package/dist/steps/eip-7702-authorization.d.mts.map +1 -0
- package/dist/steps/eip-7702-authorization.mjs +151 -0
- package/dist/steps/eip-7702-authorization.mjs.map +1 -0
- package/dist/steps/step.cjs.map +1 -0
- package/dist/{step.d.cts → steps/step.d.cts} +3 -1
- package/dist/steps/step.d.cts.map +1 -0
- package/dist/{step.d.mts → steps/step.d.mts} +3 -1
- package/dist/steps/step.d.mts.map +1 -0
- package/dist/steps/step.mjs.map +1 -0
- package/package.json +5 -4
- package/dist/associate-address.cjs.map +0 -1
- package/dist/associate-address.d.cts.map +0 -1
- package/dist/associate-address.d.mts.map +0 -1
- package/dist/associate-address.mjs.map +0 -1
- package/dist/step.cjs.map +0 -1
- package/dist/step.d.cts.map +0 -1
- package/dist/step.d.mts.map +0 -1
- package/dist/step.mjs.map +0 -1
- /package/dist/{associate-address.d.cts → steps/associate-address.d.cts} +0 -0
- /package/dist/{associate-address.d.mts → steps/associate-address.d.mts} +0 -0
- /package/dist/{step.cjs → steps/step.cjs} +0 -0
- /package/dist/{step.mjs → steps/step.mjs} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -7,11 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- Bump `@metamask/chomp-api-service` from `^1.0.0` to `^2.0.0` ([#8618](https://github.com/MetaMask/core/pull/8618))
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
|
|
18
|
+
- Send the CHOMP authentication timestamp as a number instead of a string in the associate-address step. ([#8610](https://github.com/MetaMask/core/pull/8610))
|
|
19
|
+
|
|
20
|
+
## [1.1.0]
|
|
21
|
+
|
|
22
|
+
### Added
|
|
23
|
+
|
|
24
|
+
- Add EIP-7702 authorization step to the upgrade sequence. ([#8565](https://github.com/MetaMask/core/pull/8565))
|
|
25
|
+
|
|
10
26
|
## [1.0.0]
|
|
11
27
|
|
|
12
28
|
### Added
|
|
13
29
|
|
|
14
30
|
- Add `MoneyAccountUpgradeController` with `upgradeAccount` method ([#8426](https://github.com/MetaMask/core/pull/8426))
|
|
15
31
|
|
|
16
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@1.
|
|
32
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@1.2.0...HEAD
|
|
33
|
+
[1.2.0]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@1.1.0...@metamask/money-account-upgrade-controller@1.2.0
|
|
34
|
+
[1.1.0]: https://github.com/MetaMask/core/compare/@metamask/money-account-upgrade-controller@1.0.0...@metamask/money-account-upgrade-controller@1.1.0
|
|
17
35
|
[1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/money-account-upgrade-controller@1.0.0
|
|
@@ -10,11 +10,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var
|
|
13
|
+
var _MoneyAccountUpgradeController_config, _MoneyAccountUpgradeController_steps;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MoneyAccountUpgradeController = exports.controllerName = void 0;
|
|
16
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
17
|
-
const associate_address_1 = require("./associate-address.cjs");
|
|
17
|
+
const associate_address_1 = require("./steps/associate-address.cjs");
|
|
18
|
+
const eip_7702_authorization_1 = require("./steps/eip-7702-authorization.cjs");
|
|
18
19
|
exports.controllerName = 'MoneyAccountUpgradeController';
|
|
19
20
|
const moneyAccountUpgradeControllerMetadata = {};
|
|
20
21
|
const MESSENGER_EXPOSED_METHODS = ['upgradeAccount'];
|
|
@@ -35,9 +36,8 @@ class MoneyAccountUpgradeController extends base_controller_1.BaseController {
|
|
|
35
36
|
name: exports.controllerName,
|
|
36
37
|
state: {},
|
|
37
38
|
});
|
|
38
|
-
|
|
39
|
-
_MoneyAccountUpgradeController_steps.set(this, [associate_address_1.associateAddressStep]);
|
|
40
|
-
__classPrivateFieldSet(this, _MoneyAccountUpgradeController_initialized, false, "f");
|
|
39
|
+
_MoneyAccountUpgradeController_config.set(this, void 0);
|
|
40
|
+
_MoneyAccountUpgradeController_steps.set(this, [associate_address_1.associateAddressStep, eip_7702_authorization_1.eip7702AuthorizationStep]);
|
|
41
41
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
42
42
|
}
|
|
43
43
|
/**
|
|
@@ -45,9 +45,9 @@ class MoneyAccountUpgradeController extends base_controller_1.BaseController {
|
|
|
45
45
|
* given chain.
|
|
46
46
|
*
|
|
47
47
|
* @param chainId - The chain to initialize for.
|
|
48
|
-
* @param
|
|
48
|
+
* @param initConfig - Contract addresses not available from the service details API.
|
|
49
49
|
*/
|
|
50
|
-
async init(chainId,
|
|
50
|
+
async init(chainId, initConfig) {
|
|
51
51
|
const response = await this.messenger.call('ChompApiService:getServiceDetails', [chainId]);
|
|
52
52
|
const chain = response.chains[chainId];
|
|
53
53
|
if (!chain) {
|
|
@@ -60,7 +60,10 @@ class MoneyAccountUpgradeController extends base_controller_1.BaseController {
|
|
|
60
60
|
if (vedaProtocol.supportedTokens.length === 0) {
|
|
61
61
|
throw new Error(`No supported tokens found for vedaProtocol on chain ${chainId}`);
|
|
62
62
|
}
|
|
63
|
-
__classPrivateFieldSet(this,
|
|
63
|
+
__classPrivateFieldSet(this, _MoneyAccountUpgradeController_config, {
|
|
64
|
+
chainId,
|
|
65
|
+
delegatorImplAddress: initConfig.delegatorImplAddress,
|
|
66
|
+
}, "f");
|
|
64
67
|
}
|
|
65
68
|
/**
|
|
66
69
|
* Runs each step in the upgrade sequence in order. A step that reports
|
|
@@ -71,14 +74,18 @@ class MoneyAccountUpgradeController extends base_controller_1.BaseController {
|
|
|
71
74
|
* @param address - The Money Account address to upgrade.
|
|
72
75
|
*/
|
|
73
76
|
async upgradeAccount(address) {
|
|
74
|
-
if (!__classPrivateFieldGet(this,
|
|
77
|
+
if (!__classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f")) {
|
|
75
78
|
throw new Error('MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called');
|
|
76
79
|
}
|
|
77
80
|
for (const step of __classPrivateFieldGet(this, _MoneyAccountUpgradeController_steps, "f")) {
|
|
78
|
-
await step.run({
|
|
81
|
+
await step.run({
|
|
82
|
+
messenger: this.messenger,
|
|
83
|
+
address,
|
|
84
|
+
...__classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f"),
|
|
85
|
+
});
|
|
79
86
|
}
|
|
80
87
|
}
|
|
81
88
|
}
|
|
82
89
|
exports.MoneyAccountUpgradeController = MoneyAccountUpgradeController;
|
|
83
|
-
|
|
90
|
+
_MoneyAccountUpgradeController_config = new WeakMap(), _MoneyAccountUpgradeController_steps = new WeakMap();
|
|
84
91
|
//# sourceMappingURL=MoneyAccountUpgradeController.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyAccountUpgradeController.cjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;
|
|
1
|
+
{"version":3,"file":"MoneyAccountUpgradeController.cjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAkB3D,qEAAiE;AACjE,+EAA0E;AAI7D,QAAA,cAAc,GAAG,+BAA+B,CAAC;AAI9D,MAAM,qCAAqC,GACzC,EAA8D,CAAC;AAEjE,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AAsC9D;;GAEG;AACH,MAAa,6BAA8B,SAAQ,gCAIlD;IAKC;;;;;OAKG;IACH,YAAY,EACV,SAAS,GAGV;QACC,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,qCAAqC;YAC/C,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE,EAAE;SACV,CAAC,CAAC;QApBL,wDAAsD;QAE7C,+CAAiB,CAAC,wCAAoB,EAAE,iDAAw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ChB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AA7FD,sEA6FC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ChompApiServiceAssociateAddressAction,\n ChompApiServiceCreateUpgradeAction,\n ChompApiServiceGetServiceDetailsAction,\n} from '@metamask/chomp-api-service';\nimport type {\n KeyringControllerSignEip7702AuthorizationAction,\n KeyringControllerSignPersonalMessageAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMethodActions } from './MoneyAccountUpgradeController-method-action-types';\nimport { associateAddressStep } from './steps/associate-address';\nimport { eip7702AuthorizationStep } from './steps/eip-7702-authorization';\nimport type { Step } from './steps/step';\nimport type { InitConfig } from './types';\n\nexport const controllerName = 'MoneyAccountUpgradeController';\n\nexport type MoneyAccountUpgradeControllerState = Record<string, never>;\n\nconst moneyAccountUpgradeControllerMetadata =\n {} satisfies StateMetadata<MoneyAccountUpgradeControllerState>;\n\nconst MESSENGER_EXPOSED_METHODS = ['upgradeAccount'] as const;\n\nexport type MoneyAccountUpgradeControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerActions =\n | MoneyAccountUpgradeControllerGetStateAction\n | MoneyAccountUpgradeControllerMethodActions;\n\ntype AllowedActions =\n | ChompApiServiceAssociateAddressAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetServiceDetailsAction\n | KeyringControllerSignEip7702AuthorizationAction\n | KeyringControllerSignPersonalMessageAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction;\n\nexport type MoneyAccountUpgradeControllerStateChangedEvent =\n ControllerStateChangedEvent<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerEvents =\n MoneyAccountUpgradeControllerStateChangedEvent;\n\ntype AllowedEvents = never;\n\nexport type MoneyAccountUpgradeControllerMessenger = Messenger<\n typeof controllerName,\n MoneyAccountUpgradeControllerActions | AllowedActions,\n MoneyAccountUpgradeControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that orchestrates the Money Account upgrade sequence.\n */\nexport class MoneyAccountUpgradeController extends BaseController<\n typeof controllerName,\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerMessenger\n> {\n #config?: { chainId: Hex; delegatorImplAddress: Hex };\n\n readonly #steps: Step[] = [associateAddressStep, eip7702AuthorizationStep];\n\n /**\n * Constructor for the MoneyAccountUpgradeController.\n *\n * @param options - The options for constructing the controller.\n * @param options.messenger - The messenger to use for inter-controller communication.\n */\n constructor({\n messenger,\n }: {\n messenger: MoneyAccountUpgradeControllerMessenger;\n }) {\n super({\n messenger,\n metadata: moneyAccountUpgradeControllerMetadata,\n name: controllerName,\n state: {},\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches service details and validates the controller can operate on the\n * given chain.\n *\n * @param chainId - The chain to initialize for.\n * @param initConfig - Contract addresses not available from the service details API.\n */\n async init(chainId: Hex, initConfig: InitConfig): Promise<void> {\n const response = await this.messenger.call(\n 'ChompApiService:getServiceDetails',\n [chainId],\n );\n\n const chain = response.chains[chainId];\n if (!chain) {\n throw new Error(`Chain ${chainId} not found in service details response`);\n }\n\n const { vedaProtocol } = chain.protocol;\n if (!vedaProtocol) {\n throw new Error(\n `vedaProtocol not found for chain ${chainId} in service details response`,\n );\n }\n\n if (vedaProtocol.supportedTokens.length === 0) {\n throw new Error(\n `No supported tokens found for vedaProtocol on chain ${chainId}`,\n );\n }\n\n this.#config = {\n chainId,\n delegatorImplAddress: initConfig.delegatorImplAddress,\n };\n }\n\n /**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step propagates and halts the sequence.\n *\n * @param address - The Money Account address to upgrade.\n */\n async upgradeAccount(address: Hex): Promise<void> {\n if (!this.#config) {\n throw new Error(\n 'MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called',\n );\n }\n\n for (const step of this.#steps) {\n await step.run({\n messenger: this.messenger,\n address,\n ...this.#config,\n });\n }\n }\n}\n"]}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
|
-
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceGetServiceDetailsAction } from "@metamask/chomp-api-service";
|
|
4
|
-
import type { KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
|
|
3
|
+
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetServiceDetailsAction } from "@metamask/chomp-api-service";
|
|
4
|
+
import type { KeyringControllerSignEip7702AuthorizationAction, KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
|
|
5
5
|
import type { Messenger } from "@metamask/messenger";
|
|
6
|
+
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
6
7
|
import type { Hex } from "@metamask/utils";
|
|
7
8
|
import type { MoneyAccountUpgradeControllerMethodActions } from "./MoneyAccountUpgradeController-method-action-types.cjs";
|
|
8
9
|
import type { InitConfig } from "./types.cjs";
|
|
@@ -10,7 +11,7 @@ export declare const controllerName = "MoneyAccountUpgradeController";
|
|
|
10
11
|
export type MoneyAccountUpgradeControllerState = Record<string, never>;
|
|
11
12
|
export type MoneyAccountUpgradeControllerGetStateAction = ControllerGetStateAction<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
12
13
|
export type MoneyAccountUpgradeControllerActions = MoneyAccountUpgradeControllerGetStateAction | MoneyAccountUpgradeControllerMethodActions;
|
|
13
|
-
type AllowedActions = ChompApiServiceAssociateAddressAction | ChompApiServiceGetServiceDetailsAction | KeyringControllerSignPersonalMessageAction;
|
|
14
|
+
type AllowedActions = ChompApiServiceAssociateAddressAction | ChompApiServiceCreateUpgradeAction | ChompApiServiceGetServiceDetailsAction | KeyringControllerSignEip7702AuthorizationAction | KeyringControllerSignPersonalMessageAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction;
|
|
14
15
|
export type MoneyAccountUpgradeControllerStateChangedEvent = ControllerStateChangedEvent<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
15
16
|
export type MoneyAccountUpgradeControllerEvents = MoneyAccountUpgradeControllerStateChangedEvent;
|
|
16
17
|
type AllowedEvents = never;
|
|
@@ -34,9 +35,9 @@ export declare class MoneyAccountUpgradeController extends BaseController<typeof
|
|
|
34
35
|
* given chain.
|
|
35
36
|
*
|
|
36
37
|
* @param chainId - The chain to initialize for.
|
|
37
|
-
* @param
|
|
38
|
+
* @param initConfig - Contract addresses not available from the service details API.
|
|
38
39
|
*/
|
|
39
|
-
init(chainId: Hex,
|
|
40
|
+
init(chainId: Hex, initConfig: InitConfig): Promise<void>;
|
|
40
41
|
/**
|
|
41
42
|
* Runs each step in the upgrade sequence in order. A step that reports
|
|
42
43
|
* `'already-done'` is skipped without performing any action; a step that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyAccountUpgradeController.d.cts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,sCAAsC,EACvC,oCAAoC;AACrC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"MoneyAccountUpgradeController.d.cts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,kCAAkC,EAClC,sCAAsC,EACvC,oCAAoC;AACrC,OAAO,KAAK,EACV,+CAA+C,EAC/C,0CAA0C,EAC3C,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,mDAAmD,EACnD,2CAA2C,EAC5C,qCAAqC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,0CAA0C,EAAE,gEAA4D;AAItH,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAgB;AAE1C,eAAO,MAAM,cAAc,kCAAkC,CAAC;AAE9D,MAAM,MAAM,kCAAkC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAOvE,MAAM,MAAM,2CAA2C,GACrD,wBAAwB,CACtB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,oCAAoC,GAC5C,2CAA2C,GAC3C,0CAA0C,CAAC;AAE/C,KAAK,cAAc,GACf,qCAAqC,GACrC,kCAAkC,GAClC,sCAAsC,GACtC,+CAA+C,GAC/C,0CAA0C,GAC1C,mDAAmD,GACnD,2CAA2C,CAAC;AAEhD,MAAM,MAAM,8CAA8C,GACxD,2BAA2B,CACzB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,mCAAmC,GAC7C,8CAA8C,CAAC;AAEjD,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,sCAAsC,GAAG,SAAS,CAC5D,OAAO,cAAc,EACrB,oCAAoC,GAAG,cAAc,EACrD,mCAAmC,GAAG,aAAa,CACpD,CAAC;AAEF;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,cAAc,CAC/D,OAAO,cAAc,EACrB,kCAAkC,EAClC,sCAAsC,CACvC;;IAKC;;;;;OAKG;gBACS,EACV,SAAS,GACV,EAAE;QACD,SAAS,EAAE,sCAAsC,CAAC;KACnD;IAcD;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B/D;;;;;;;OAOG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAelD"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { ControllerGetStateAction, ControllerStateChangedEvent } from "@metamask/base-controller";
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
|
-
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceGetServiceDetailsAction } from "@metamask/chomp-api-service";
|
|
4
|
-
import type { KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
|
|
3
|
+
import type { ChompApiServiceAssociateAddressAction, ChompApiServiceCreateUpgradeAction, ChompApiServiceGetServiceDetailsAction } from "@metamask/chomp-api-service";
|
|
4
|
+
import type { KeyringControllerSignEip7702AuthorizationAction, KeyringControllerSignPersonalMessageAction } from "@metamask/keyring-controller";
|
|
5
5
|
import type { Messenger } from "@metamask/messenger";
|
|
6
|
+
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
|
|
6
7
|
import type { Hex } from "@metamask/utils";
|
|
7
8
|
import type { MoneyAccountUpgradeControllerMethodActions } from "./MoneyAccountUpgradeController-method-action-types.mjs";
|
|
8
9
|
import type { InitConfig } from "./types.mjs";
|
|
@@ -10,7 +11,7 @@ export declare const controllerName = "MoneyAccountUpgradeController";
|
|
|
10
11
|
export type MoneyAccountUpgradeControllerState = Record<string, never>;
|
|
11
12
|
export type MoneyAccountUpgradeControllerGetStateAction = ControllerGetStateAction<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
12
13
|
export type MoneyAccountUpgradeControllerActions = MoneyAccountUpgradeControllerGetStateAction | MoneyAccountUpgradeControllerMethodActions;
|
|
13
|
-
type AllowedActions = ChompApiServiceAssociateAddressAction | ChompApiServiceGetServiceDetailsAction | KeyringControllerSignPersonalMessageAction;
|
|
14
|
+
type AllowedActions = ChompApiServiceAssociateAddressAction | ChompApiServiceCreateUpgradeAction | ChompApiServiceGetServiceDetailsAction | KeyringControllerSignEip7702AuthorizationAction | KeyringControllerSignPersonalMessageAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction;
|
|
14
15
|
export type MoneyAccountUpgradeControllerStateChangedEvent = ControllerStateChangedEvent<typeof controllerName, MoneyAccountUpgradeControllerState>;
|
|
15
16
|
export type MoneyAccountUpgradeControllerEvents = MoneyAccountUpgradeControllerStateChangedEvent;
|
|
16
17
|
type AllowedEvents = never;
|
|
@@ -34,9 +35,9 @@ export declare class MoneyAccountUpgradeController extends BaseController<typeof
|
|
|
34
35
|
* given chain.
|
|
35
36
|
*
|
|
36
37
|
* @param chainId - The chain to initialize for.
|
|
37
|
-
* @param
|
|
38
|
+
* @param initConfig - Contract addresses not available from the service details API.
|
|
38
39
|
*/
|
|
39
|
-
init(chainId: Hex,
|
|
40
|
+
init(chainId: Hex, initConfig: InitConfig): Promise<void>;
|
|
40
41
|
/**
|
|
41
42
|
* Runs each step in the upgrade sequence in order. A step that reports
|
|
42
43
|
* `'already-done'` is skipped without performing any action; a step that
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyAccountUpgradeController.d.mts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,sCAAsC,EACvC,oCAAoC;AACrC,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"MoneyAccountUpgradeController.d.mts","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAE5B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,qCAAqC,EACrC,kCAAkC,EAClC,sCAAsC,EACvC,oCAAoC;AACrC,OAAO,KAAK,EACV,+CAA+C,EAC/C,0CAA0C,EAC3C,qCAAqC;AACtC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,mDAAmD,EACnD,2CAA2C,EAC5C,qCAAqC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,0CAA0C,EAAE,gEAA4D;AAItH,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAgB;AAE1C,eAAO,MAAM,cAAc,kCAAkC,CAAC;AAE9D,MAAM,MAAM,kCAAkC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAOvE,MAAM,MAAM,2CAA2C,GACrD,wBAAwB,CACtB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,oCAAoC,GAC5C,2CAA2C,GAC3C,0CAA0C,CAAC;AAE/C,KAAK,cAAc,GACf,qCAAqC,GACrC,kCAAkC,GAClC,sCAAsC,GACtC,+CAA+C,GAC/C,0CAA0C,GAC1C,mDAAmD,GACnD,2CAA2C,CAAC;AAEhD,MAAM,MAAM,8CAA8C,GACxD,2BAA2B,CACzB,OAAO,cAAc,EACrB,kCAAkC,CACnC,CAAC;AAEJ,MAAM,MAAM,mCAAmC,GAC7C,8CAA8C,CAAC;AAEjD,KAAK,aAAa,GAAG,KAAK,CAAC;AAE3B,MAAM,MAAM,sCAAsC,GAAG,SAAS,CAC5D,OAAO,cAAc,EACrB,oCAAoC,GAAG,cAAc,EACrD,mCAAmC,GAAG,aAAa,CACpD,CAAC;AAEF;;GAEG;AACH,qBAAa,6BAA8B,SAAQ,cAAc,CAC/D,OAAO,cAAc,EACrB,kCAAkC,EAClC,sCAAsC,CACvC;;IAKC;;;;;OAKG;gBACS,EACV,SAAS,GACV,EAAE;QACD,SAAS,EAAE,sCAAsC,CAAC;KACnD;IAcD;;;;;;OAMG;IACG,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA8B/D;;;;;;;OAOG;IACG,cAAc,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC;CAelD"}
|
|
@@ -9,9 +9,10 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
12
|
+
var _MoneyAccountUpgradeController_config, _MoneyAccountUpgradeController_steps;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
|
-
import { associateAddressStep } from "./associate-address.mjs";
|
|
14
|
+
import { associateAddressStep } from "./steps/associate-address.mjs";
|
|
15
|
+
import { eip7702AuthorizationStep } from "./steps/eip-7702-authorization.mjs";
|
|
15
16
|
export const controllerName = 'MoneyAccountUpgradeController';
|
|
16
17
|
const moneyAccountUpgradeControllerMetadata = {};
|
|
17
18
|
const MESSENGER_EXPOSED_METHODS = ['upgradeAccount'];
|
|
@@ -32,9 +33,8 @@ export class MoneyAccountUpgradeController extends BaseController {
|
|
|
32
33
|
name: controllerName,
|
|
33
34
|
state: {},
|
|
34
35
|
});
|
|
35
|
-
|
|
36
|
-
_MoneyAccountUpgradeController_steps.set(this, [associateAddressStep]);
|
|
37
|
-
__classPrivateFieldSet(this, _MoneyAccountUpgradeController_initialized, false, "f");
|
|
36
|
+
_MoneyAccountUpgradeController_config.set(this, void 0);
|
|
37
|
+
_MoneyAccountUpgradeController_steps.set(this, [associateAddressStep, eip7702AuthorizationStep]);
|
|
38
38
|
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
39
39
|
}
|
|
40
40
|
/**
|
|
@@ -42,9 +42,9 @@ export class MoneyAccountUpgradeController extends BaseController {
|
|
|
42
42
|
* given chain.
|
|
43
43
|
*
|
|
44
44
|
* @param chainId - The chain to initialize for.
|
|
45
|
-
* @param
|
|
45
|
+
* @param initConfig - Contract addresses not available from the service details API.
|
|
46
46
|
*/
|
|
47
|
-
async init(chainId,
|
|
47
|
+
async init(chainId, initConfig) {
|
|
48
48
|
const response = await this.messenger.call('ChompApiService:getServiceDetails', [chainId]);
|
|
49
49
|
const chain = response.chains[chainId];
|
|
50
50
|
if (!chain) {
|
|
@@ -57,7 +57,10 @@ export class MoneyAccountUpgradeController extends BaseController {
|
|
|
57
57
|
if (vedaProtocol.supportedTokens.length === 0) {
|
|
58
58
|
throw new Error(`No supported tokens found for vedaProtocol on chain ${chainId}`);
|
|
59
59
|
}
|
|
60
|
-
__classPrivateFieldSet(this,
|
|
60
|
+
__classPrivateFieldSet(this, _MoneyAccountUpgradeController_config, {
|
|
61
|
+
chainId,
|
|
62
|
+
delegatorImplAddress: initConfig.delegatorImplAddress,
|
|
63
|
+
}, "f");
|
|
61
64
|
}
|
|
62
65
|
/**
|
|
63
66
|
* Runs each step in the upgrade sequence in order. A step that reports
|
|
@@ -68,13 +71,17 @@ export class MoneyAccountUpgradeController extends BaseController {
|
|
|
68
71
|
* @param address - The Money Account address to upgrade.
|
|
69
72
|
*/
|
|
70
73
|
async upgradeAccount(address) {
|
|
71
|
-
if (!__classPrivateFieldGet(this,
|
|
74
|
+
if (!__classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f")) {
|
|
72
75
|
throw new Error('MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called');
|
|
73
76
|
}
|
|
74
77
|
for (const step of __classPrivateFieldGet(this, _MoneyAccountUpgradeController_steps, "f")) {
|
|
75
|
-
await step.run({
|
|
78
|
+
await step.run({
|
|
79
|
+
messenger: this.messenger,
|
|
80
|
+
address,
|
|
81
|
+
...__classPrivateFieldGet(this, _MoneyAccountUpgradeController_config, "f"),
|
|
82
|
+
});
|
|
76
83
|
}
|
|
77
84
|
}
|
|
78
85
|
}
|
|
79
|
-
|
|
86
|
+
_MoneyAccountUpgradeController_config = new WeakMap(), _MoneyAccountUpgradeController_steps = new WeakMap();
|
|
80
87
|
//# sourceMappingURL=MoneyAccountUpgradeController.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MoneyAccountUpgradeController.mjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;
|
|
1
|
+
{"version":3,"file":"MoneyAccountUpgradeController.mjs","sourceRoot":"","sources":["../src/MoneyAccountUpgradeController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAkB3D,OAAO,EAAE,oBAAoB,EAAE,sCAAkC;AACjE,OAAO,EAAE,wBAAwB,EAAE,2CAAuC;AAI1E,MAAM,CAAC,MAAM,cAAc,GAAG,+BAA+B,CAAC;AAI9D,MAAM,qCAAqC,GACzC,EAA8D,CAAC;AAEjE,MAAM,yBAAyB,GAAG,CAAC,gBAAgB,CAAU,CAAC;AAsC9D;;GAEG;AACH,MAAM,OAAO,6BAA8B,SAAQ,cAIlD;IAKC;;;;;OAKG;IACH,YAAY,EACV,SAAS,GAGV;QACC,K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AAM,IAAI,IAAI,uBAAA,IAAI,4CAAO,EAAE,CAAC;YAC/B,MAAM,IAAI,CAAC,GAAG,CAAC;gBACb,SAAS,EAAE,IAAI,CAAC,SAAS;gBACzB,OAAO;gBACP,GAAG,uBAAA,IAAI,6CAAQ;aAChB,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangedEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n ChompApiServiceAssociateAddressAction,\n ChompApiServiceCreateUpgradeAction,\n ChompApiServiceGetServiceDetailsAction,\n} from '@metamask/chomp-api-service';\nimport type {\n KeyringControllerSignEip7702AuthorizationAction,\n KeyringControllerSignPersonalMessageAction,\n} from '@metamask/keyring-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n} from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMethodActions } from './MoneyAccountUpgradeController-method-action-types';\nimport { associateAddressStep } from './steps/associate-address';\nimport { eip7702AuthorizationStep } from './steps/eip-7702-authorization';\nimport type { Step } from './steps/step';\nimport type { InitConfig } from './types';\n\nexport const controllerName = 'MoneyAccountUpgradeController';\n\nexport type MoneyAccountUpgradeControllerState = Record<string, never>;\n\nconst moneyAccountUpgradeControllerMetadata =\n {} satisfies StateMetadata<MoneyAccountUpgradeControllerState>;\n\nconst MESSENGER_EXPOSED_METHODS = ['upgradeAccount'] as const;\n\nexport type MoneyAccountUpgradeControllerGetStateAction =\n ControllerGetStateAction<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerActions =\n | MoneyAccountUpgradeControllerGetStateAction\n | MoneyAccountUpgradeControllerMethodActions;\n\ntype AllowedActions =\n | ChompApiServiceAssociateAddressAction\n | ChompApiServiceCreateUpgradeAction\n | ChompApiServiceGetServiceDetailsAction\n | KeyringControllerSignEip7702AuthorizationAction\n | KeyringControllerSignPersonalMessageAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction;\n\nexport type MoneyAccountUpgradeControllerStateChangedEvent =\n ControllerStateChangedEvent<\n typeof controllerName,\n MoneyAccountUpgradeControllerState\n >;\n\nexport type MoneyAccountUpgradeControllerEvents =\n MoneyAccountUpgradeControllerStateChangedEvent;\n\ntype AllowedEvents = never;\n\nexport type MoneyAccountUpgradeControllerMessenger = Messenger<\n typeof controllerName,\n MoneyAccountUpgradeControllerActions | AllowedActions,\n MoneyAccountUpgradeControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that orchestrates the Money Account upgrade sequence.\n */\nexport class MoneyAccountUpgradeController extends BaseController<\n typeof controllerName,\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerMessenger\n> {\n #config?: { chainId: Hex; delegatorImplAddress: Hex };\n\n readonly #steps: Step[] = [associateAddressStep, eip7702AuthorizationStep];\n\n /**\n * Constructor for the MoneyAccountUpgradeController.\n *\n * @param options - The options for constructing the controller.\n * @param options.messenger - The messenger to use for inter-controller communication.\n */\n constructor({\n messenger,\n }: {\n messenger: MoneyAccountUpgradeControllerMessenger;\n }) {\n super({\n messenger,\n metadata: moneyAccountUpgradeControllerMetadata,\n name: controllerName,\n state: {},\n });\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Fetches service details and validates the controller can operate on the\n * given chain.\n *\n * @param chainId - The chain to initialize for.\n * @param initConfig - Contract addresses not available from the service details API.\n */\n async init(chainId: Hex, initConfig: InitConfig): Promise<void> {\n const response = await this.messenger.call(\n 'ChompApiService:getServiceDetails',\n [chainId],\n );\n\n const chain = response.chains[chainId];\n if (!chain) {\n throw new Error(`Chain ${chainId} not found in service details response`);\n }\n\n const { vedaProtocol } = chain.protocol;\n if (!vedaProtocol) {\n throw new Error(\n `vedaProtocol not found for chain ${chainId} in service details response`,\n );\n }\n\n if (vedaProtocol.supportedTokens.length === 0) {\n throw new Error(\n `No supported tokens found for vedaProtocol on chain ${chainId}`,\n );\n }\n\n this.#config = {\n chainId,\n delegatorImplAddress: initConfig.delegatorImplAddress,\n };\n }\n\n /**\n * Runs each step in the upgrade sequence in order. A step that reports\n * `'already-done'` is skipped without performing any action; a step that\n * reports `'completed'` has performed its action. An error thrown by any\n * step propagates and halts the sequence.\n *\n * @param address - The Money Account address to upgrade.\n */\n async upgradeAccount(address: Hex): Promise<void> {\n if (!this.#config) {\n throw new Error(\n 'MoneyAccountUpgradeController must be initialized via init() before upgradeAccount() can be called',\n );\n }\n\n for (const step of this.#steps) {\n await step.run({\n messenger: this.messenger,\n address,\n ...this.#config,\n });\n }\n }\n}\n"]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AACA,qFAAgF;AAAvE,8IAAA,6BAA6B,OAAA","sourcesContent":["export type { InitConfig, UpgradeConfig } from './types';\nexport { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\nexport type {\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerGetStateAction,\n MoneyAccountUpgradeControllerActions,\n MoneyAccountUpgradeControllerStateChangedEvent,\n MoneyAccountUpgradeControllerEvents,\n MoneyAccountUpgradeControllerMessenger,\n} from './MoneyAccountUpgradeController';\nexport type { MoneyAccountUpgradeControllerUpgradeAccountAction } from './MoneyAccountUpgradeController-method-action-types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type { Step, StepResult } from "./step.cjs";
|
|
2
1
|
export type { InitConfig, UpgradeConfig } from "./types.cjs";
|
|
3
2
|
export { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeController.cjs";
|
|
4
3
|
export type { MoneyAccountUpgradeControllerState, MoneyAccountUpgradeControllerGetStateAction, MoneyAccountUpgradeControllerActions, MoneyAccountUpgradeControllerStateChangedEvent, MoneyAccountUpgradeControllerEvents, MoneyAccountUpgradeControllerMessenger, } from "./MoneyAccountUpgradeController.cjs";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,oBAAgB;AACzD,OAAO,EAAE,6BAA6B,EAAE,4CAAwC;AAChF,YAAY,EACV,kCAAkC,EAClC,2CAA2C,EAC3C,oCAAoC,EACpC,8CAA8C,EAC9C,mCAAmC,EACnC,sCAAsC,GACvC,4CAAwC;AACzC,YAAY,EAAE,iDAAiD,EAAE,gEAA4D"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export type { Step, StepResult } from "./step.mjs";
|
|
2
1
|
export type { InitConfig, UpgradeConfig } from "./types.mjs";
|
|
3
2
|
export { MoneyAccountUpgradeController } from "./MoneyAccountUpgradeController.mjs";
|
|
4
3
|
export type { MoneyAccountUpgradeControllerState, MoneyAccountUpgradeControllerGetStateAction, MoneyAccountUpgradeControllerActions, MoneyAccountUpgradeControllerStateChangedEvent, MoneyAccountUpgradeControllerEvents, MoneyAccountUpgradeControllerMessenger, } from "./MoneyAccountUpgradeController.mjs";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,oBAAgB;AACzD,OAAO,EAAE,6BAA6B,EAAE,4CAAwC;AAChF,YAAY,EACV,kCAAkC,EAClC,2CAA2C,EAC3C,oCAAoC,EACpC,8CAA8C,EAC9C,mCAAmC,EACnC,sCAAsC,GACvC,4CAAwC;AACzC,YAAY,EAAE,iDAAiD,EAAE,gEAA4D"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,6BAA6B,EAAE,4CAAwC","sourcesContent":["export type { InitConfig, UpgradeConfig } from './types';\nexport { MoneyAccountUpgradeController } from './MoneyAccountUpgradeController';\nexport type {\n MoneyAccountUpgradeControllerState,\n MoneyAccountUpgradeControllerGetStateAction,\n MoneyAccountUpgradeControllerActions,\n MoneyAccountUpgradeControllerStateChangedEvent,\n MoneyAccountUpgradeControllerEvents,\n MoneyAccountUpgradeControllerMessenger,\n} from './MoneyAccountUpgradeController';\nexport type { MoneyAccountUpgradeControllerUpgradeAccountAction } from './MoneyAccountUpgradeController-method-action-types';\n"]}
|
|
@@ -17,7 +17,7 @@ const ALREADY_ASSOCIATED_STATUS = 'already_associated';
|
|
|
17
17
|
exports.associateAddressStep = {
|
|
18
18
|
name: 'associate-address',
|
|
19
19
|
async run({ messenger, address }) {
|
|
20
|
-
const timestamp = Date.now()
|
|
20
|
+
const timestamp = Date.now();
|
|
21
21
|
const message = `CHOMP Authentication ${timestamp}`;
|
|
22
22
|
const signature = (await messenger.call('KeyringController:signPersonalMessage', { data: message, from: address }));
|
|
23
23
|
const response = await messenger.call('ChompApiService:associateAddress', {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"associate-address.cjs","sourceRoot":"","sources":["../../src/steps/associate-address.ts"],"names":[],"mappings":";;;AAIA,MAAM,yBAAyB,GAAG,oBAAoB,CAAC;AAEvD;;;;;;;;;;;GAWG;AACU,QAAA,oBAAoB,GAAS;IACxC,IAAI,EAAE,mBAAmB;IACzB,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE;QAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,wBAAwB,SAAS,EAAE,CAAC;QAEpD,MAAM,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,IAAI,CACrC,uCAAuC,EACvC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CACjC,CAAQ,CAAC;QAEV,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,kCAAkC,EAAE;YACxE,SAAS;YACT,SAAS;YACT,OAAO;SACR,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,yBAAyB,EAAE,CAAC;YAClD,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { Step } from './step';\n\nconst ALREADY_ASSOCIATED_STATUS = 'already_associated';\n\n/**\n * Associates the Money Account address with the user's CHOMP profile.\n *\n * Signs `CHOMP Authentication {timestamp}` (EIP-191) with the account's key\n * and submits the signature to CHOMP, which verifies the timestamp is fresh,\n * recovers the signer, and records the profile–address mapping.\n *\n * CHOMP responds with 201 and `status: 'created'` when the association is\n * made, and 409 with `status: 'already_associated'` when the address is\n * already linked to a profile. The service surfaces both responses, so this\n * step reports `'already-done'` for the 409 case and `'completed'` otherwise.\n */\nexport const associateAddressStep: Step = {\n name: 'associate-address',\n async run({ messenger, address }) {\n const timestamp = Date.now();\n const message = `CHOMP Authentication ${timestamp}`;\n\n const signature = (await messenger.call(\n 'KeyringController:signPersonalMessage',\n { data: message, from: address },\n )) as Hex;\n\n const response = await messenger.call('ChompApiService:associateAddress', {\n signature,\n timestamp,\n address,\n });\n\n if (response.status === ALREADY_ASSOCIATED_STATUS) {\n return 'already-done';\n }\n\n return 'completed';\n },\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"associate-address.d.cts","sourceRoot":"","sources":["../../src/steps/associate-address.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAInC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,EAAE,IAuBlC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"associate-address.d.mts","sourceRoot":"","sources":["../../src/steps/associate-address.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAInC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,EAAE,IAuBlC,CAAC"}
|
|
@@ -14,7 +14,7 @@ const ALREADY_ASSOCIATED_STATUS = 'already_associated';
|
|
|
14
14
|
export const associateAddressStep = {
|
|
15
15
|
name: 'associate-address',
|
|
16
16
|
async run({ messenger, address }) {
|
|
17
|
-
const timestamp = Date.now()
|
|
17
|
+
const timestamp = Date.now();
|
|
18
18
|
const message = `CHOMP Authentication ${timestamp}`;
|
|
19
19
|
const signature = (await messenger.call('KeyringController:signPersonalMessage', { data: message, from: address }));
|
|
20
20
|
const response = await messenger.call('ChompApiService:associateAddress', {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"associate-address.mjs","sourceRoot":"","sources":["../../src/steps/associate-address.ts"],"names":[],"mappings":"AAIA,MAAM,yBAAyB,GAAG,oBAAoB,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAS;IACxC,IAAI,EAAE,mBAAmB;IACzB,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE;QAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC7B,MAAM,OAAO,GAAG,wBAAwB,SAAS,EAAE,CAAC;QAEpD,MAAM,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,IAAI,CACrC,uCAAuC,EACvC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CACjC,CAAQ,CAAC;QAEV,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,kCAAkC,EAAE;YACxE,SAAS;YACT,SAAS;YACT,OAAO;SACR,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,yBAAyB,EAAE,CAAC;YAClD,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { Step } from './step';\n\nconst ALREADY_ASSOCIATED_STATUS = 'already_associated';\n\n/**\n * Associates the Money Account address with the user's CHOMP profile.\n *\n * Signs `CHOMP Authentication {timestamp}` (EIP-191) with the account's key\n * and submits the signature to CHOMP, which verifies the timestamp is fresh,\n * recovers the signer, and records the profile–address mapping.\n *\n * CHOMP responds with 201 and `status: 'created'` when the association is\n * made, and 409 with `status: 'already_associated'` when the address is\n * already linked to a profile. The service surfaces both responses, so this\n * step reports `'already-done'` for the 409 case and `'completed'` otherwise.\n */\nexport const associateAddressStep: Step = {\n name: 'associate-address',\n async run({ messenger, address }) {\n const timestamp = Date.now();\n const message = `CHOMP Authentication ${timestamp}`;\n\n const signature = (await messenger.call(\n 'KeyringController:signPersonalMessage',\n { data: message, from: address },\n )) as Hex;\n\n const response = await messenger.call('ChompApiService:associateAddress', {\n signature,\n timestamp,\n address,\n });\n\n if (response.status === ALREADY_ASSOCIATED_STATUS) {\n return 'already-done';\n }\n\n return 'completed';\n },\n};\n"]}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.eip7702AuthorizationStep = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const EIP_7702_DELEGATION_PREFIX = '0xef0100';
|
|
6
|
+
// '0x' (2) + 'ef0100' (6) + 20-byte address (40) = 48 characters.
|
|
7
|
+
const EIP_7702_DELEGATED_CODE_LENGTH = 48;
|
|
8
|
+
// 65-byte signature: 32-byte r + 32-byte s + 1-byte v.
|
|
9
|
+
// '0x' (2) + 32 bytes (64) + 32 bytes (64) + 1 byte (2) = 132 characters.
|
|
10
|
+
const SIGNATURE_HEX_LENGTH = 132;
|
|
11
|
+
// '0x' + 32-byte r = 66 characters.
|
|
12
|
+
const R_END_INDEX = 66;
|
|
13
|
+
// r (66 chars) + 32-byte s (64 chars) = 130 characters.
|
|
14
|
+
const S_END_INDEX = 130;
|
|
15
|
+
const V_END_INDEX = SIGNATURE_HEX_LENGTH;
|
|
16
|
+
// v = 27 means yParity = 0; v = 28 means yParity = 1.
|
|
17
|
+
const V_BASE = 27;
|
|
18
|
+
/**
|
|
19
|
+
* Submits the EIP-7702 delegation-slot authorization to CHOMP so the Money
|
|
20
|
+
* Account can be upgraded to a smart account pointed at the configured
|
|
21
|
+
* delegator impl.
|
|
22
|
+
*
|
|
23
|
+
* The step:
|
|
24
|
+
*
|
|
25
|
+
* 1. Reads the account's on-chain code. If it is already delegated to the
|
|
26
|
+
* configured `delegatorImplAddress`, reports `'already-done'`. If it is
|
|
27
|
+
* delegated to a different address, throws rather than silently
|
|
28
|
+
* overwriting an existing delegation.
|
|
29
|
+
* 2. Fetches the account's current on-chain transaction count — CHOMP
|
|
30
|
+
* validates the nonce matches when it applies the authorization.
|
|
31
|
+
* 3. Signs the EIP-7702 authorization `{ chainId, delegatorImpl, nonce }`
|
|
32
|
+
* with the Money Account's key via the keyring.
|
|
33
|
+
* 4. Splits the 65-byte signature into `r`, `s`, `v`, `yParity` and submits
|
|
34
|
+
* it to `POST /v1/account-upgrade`.
|
|
35
|
+
*/
|
|
36
|
+
exports.eip7702AuthorizationStep = {
|
|
37
|
+
name: 'eip-7702-authorization',
|
|
38
|
+
async run({ messenger, address, chainId, delegatorImplAddress }) {
|
|
39
|
+
const provider = getProvider(messenger, chainId);
|
|
40
|
+
const existingDelegation = await fetchDelegationAddress(provider, address);
|
|
41
|
+
if (existingDelegation !== undefined) {
|
|
42
|
+
if (existingDelegation === delegatorImplAddress.toLowerCase()) {
|
|
43
|
+
return 'already-done';
|
|
44
|
+
}
|
|
45
|
+
throw new Error(`Account ${address} is already upgraded to another smart account: ${existingDelegation}.`);
|
|
46
|
+
}
|
|
47
|
+
const chainIdDecimal = parseInt(chainId, 16);
|
|
48
|
+
const nonce = await fetchNonce(provider, address);
|
|
49
|
+
const signature = await messenger.call('KeyringController:signEip7702Authorization', {
|
|
50
|
+
chainId: chainIdDecimal,
|
|
51
|
+
contractAddress: delegatorImplAddress,
|
|
52
|
+
nonce,
|
|
53
|
+
from: address,
|
|
54
|
+
});
|
|
55
|
+
const { r, s, v, yParity } = splitEip7702Signature(signature);
|
|
56
|
+
await messenger.call('ChompApiService:createUpgrade', {
|
|
57
|
+
r,
|
|
58
|
+
s,
|
|
59
|
+
v,
|
|
60
|
+
yParity,
|
|
61
|
+
address,
|
|
62
|
+
chainId: chainIdDecimal.toString(),
|
|
63
|
+
nonce: nonce.toString(),
|
|
64
|
+
});
|
|
65
|
+
return 'completed';
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
/**
|
|
69
|
+
* Splits a 65-byte ECDSA signature produced by
|
|
70
|
+
* `KeyringController:signEip7702Authorization` into its `r`, `s`, `v`
|
|
71
|
+
* components and derives `yParity` (`0` for `v = 27`, `1` for `v = 28`).
|
|
72
|
+
*
|
|
73
|
+
* @param signature - A 0x-prefixed 132-character hex string. Accepted in any
|
|
74
|
+
* case; normalized to lowercase before validation.
|
|
75
|
+
* @returns The signature components.
|
|
76
|
+
*/
|
|
77
|
+
function splitEip7702Signature(signature) {
|
|
78
|
+
const normalized = typeof signature === 'string' ? signature.toLowerCase() : signature;
|
|
79
|
+
if (!(0, utils_1.isStrictHexString)(normalized) ||
|
|
80
|
+
normalized.length !== SIGNATURE_HEX_LENGTH) {
|
|
81
|
+
throw new Error(`Expected a 0x-prefixed 65-byte signature from signEip7702Authorization, got ${JSON.stringify(signature)}`);
|
|
82
|
+
}
|
|
83
|
+
// eslint-disable-next-line id-length
|
|
84
|
+
const v = parseInt(normalized.slice(S_END_INDEX, V_END_INDEX), 16);
|
|
85
|
+
if (v !== 27 && v !== 28) {
|
|
86
|
+
throw new Error(`Expected v to be 27 or 28 in signEip7702Authorization signature, got ${v}`);
|
|
87
|
+
}
|
|
88
|
+
return {
|
|
89
|
+
r: normalized.slice(0, R_END_INDEX),
|
|
90
|
+
s: (0, utils_1.add0x)(normalized.slice(R_END_INDEX, S_END_INDEX)),
|
|
91
|
+
v,
|
|
92
|
+
yParity: v === V_BASE ? 0 : 1,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Reads the account's on-chain code and, if the account is currently
|
|
97
|
+
* delegated via EIP-7702, returns the implementation address the delegation
|
|
98
|
+
* points at. Returns `undefined` if the account has no code (a plain EOA).
|
|
99
|
+
* Throws if the code is present but not a valid EIP-7702 delegation, since
|
|
100
|
+
* that means the address is a regular contract and is not eligible for
|
|
101
|
+
* upgrade.
|
|
102
|
+
*
|
|
103
|
+
* @param provider - JSON-RPC provider for the target chain.
|
|
104
|
+
* @param address - The Money Account address.
|
|
105
|
+
* @returns The current delegation address, or `undefined` if none.
|
|
106
|
+
*/
|
|
107
|
+
async function fetchDelegationAddress(provider, address) {
|
|
108
|
+
const code = await provider.request({
|
|
109
|
+
method: 'eth_getCode',
|
|
110
|
+
params: [address, 'latest'],
|
|
111
|
+
});
|
|
112
|
+
if (typeof code !== 'string' || !code.startsWith('0x')) {
|
|
113
|
+
throw new Error(`Expected 0x-prefixed hex string from eth_getCode, got ${JSON.stringify(code)}`);
|
|
114
|
+
}
|
|
115
|
+
const normalized = code.toLowerCase();
|
|
116
|
+
if (normalized === '0x') {
|
|
117
|
+
return undefined;
|
|
118
|
+
}
|
|
119
|
+
if (normalized.length === EIP_7702_DELEGATED_CODE_LENGTH &&
|
|
120
|
+
normalized.startsWith(EIP_7702_DELEGATION_PREFIX)) {
|
|
121
|
+
return (0, utils_1.add0x)(normalized.slice(EIP_7702_DELEGATION_PREFIX.length));
|
|
122
|
+
}
|
|
123
|
+
throw new Error(`Account ${address} has unexpected on-chain code; expected either no code or an EIP-7702 delegation.`);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Fetches the current on-chain transaction count for the given address by
|
|
127
|
+
* issuing an `eth_getTransactionCount` RPC request.
|
|
128
|
+
*
|
|
129
|
+
* @param provider - JSON-RPC provider for the target chain.
|
|
130
|
+
* @param address - The Money Account address.
|
|
131
|
+
* @returns The current nonce as a decimal number.
|
|
132
|
+
*/
|
|
133
|
+
async function fetchNonce(provider, address) {
|
|
134
|
+
const nonceHex = await provider.request({
|
|
135
|
+
method: 'eth_getTransactionCount',
|
|
136
|
+
params: [address, 'latest'],
|
|
137
|
+
});
|
|
138
|
+
if (!(0, utils_1.isStrictHexString)(nonceHex)) {
|
|
139
|
+
throw new Error(`Expected hex string from eth_getTransactionCount, got ${JSON.stringify(nonceHex)}`);
|
|
140
|
+
}
|
|
141
|
+
return parseInt(nonceHex, 16);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Resolves the JSON-RPC provider for the given chain via NetworkController.
|
|
145
|
+
*
|
|
146
|
+
* @param messenger - The upgrade controller messenger.
|
|
147
|
+
* @param chainId - The chain to query.
|
|
148
|
+
* @returns The provider for that chain.
|
|
149
|
+
*/
|
|
150
|
+
function getProvider(messenger, chainId) {
|
|
151
|
+
const networkClientId = messenger.call('NetworkController:findNetworkClientIdByChainId', chainId);
|
|
152
|
+
return messenger.call('NetworkController:getNetworkClientById', networkClientId).provider;
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=eip-7702-authorization.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip-7702-authorization.cjs","sourceRoot":"","sources":["../../src/steps/eip-7702-authorization.ts"],"names":[],"mappings":";;;AACA,2CAA2D;AAK3D,MAAM,0BAA0B,GAAG,UAAU,CAAC;AAC9C,kEAAkE;AAClE,MAAM,8BAA8B,GAAG,EAAE,CAAC;AAE1C,uDAAuD;AACvD,0EAA0E;AAC1E,MAAM,oBAAoB,GAAG,GAAG,CAAC;AACjC,oCAAoC;AACpC,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,wDAAwD;AACxD,MAAM,WAAW,GAAG,GAAG,CAAC;AACxB,MAAM,WAAW,GAAG,oBAAoB,CAAC;AACzC,sDAAsD;AACtD,MAAM,MAAM,GAAG,EAAE,CAAC;AAElB;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,wBAAwB,GAAS;IAC5C,IAAI,EAAE,wBAAwB;IAC9B,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,EAAE,oBAAoB,EAAE;QAC7D,MAAM,QAAQ,GAAG,WAAW,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC;QAEjD,MAAM,kBAAkB,GAAG,MAAM,sBAAsB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC3E,IAAI,kBAAkB,KAAK,SAAS,EAAE,CAAC;YACrC,IAAI,kBAAkB,KAAK,oBAAoB,CAAC,WAAW,EAAE,EAAE,CAAC;gBAC9D,OAAO,cAAc,CAAC;YACxB,CAAC;YACD,MAAM,IAAI,KAAK,CACb,WAAW,OAAO,kDAAkD,kBAAkB,GAAG,CAC1F,CAAC;QACJ,CAAC;QAED,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;Q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M,QAAQ,CAAC,OAAO,CAAC;QACtC,MAAM,EAAE,yBAAyB;QACjC,MAAM,EAAE,CAAC,OAAO,EAAE,QAAQ,CAAC;KAC5B,CAAC,CAAC;IAEH,IAAI,CAAC,IAAA,yBAAiB,EAAC,QAAQ,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,yDAAyD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CACpF,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAClB,SAAmC,EACnC,OAAY;IAEZ,MAAM,eAAe,GAAG,SAAS,CAAC,IAAI,CACpC,gDAAgD,EAChD,OAAO,CACR,CAAC;IACF,OAAO,SAAS,CAAC,IAAI,CACnB,wCAAwC,EACxC,eAAe,CAChB,CAAC,QAAQ,CAAC;AACb,CAAC","sourcesContent":["import type { Provider } from '@metamask/network-controller';\nimport { add0x, isStrictHexString } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { Step, StepContext } from './step';\n\nconst EIP_7702_DELEGATION_PREFIX = '0xef0100';\n// '0x' (2) + 'ef0100' (6) + 20-byte address (40) = 48 characters.\nconst EIP_7702_DELEGATED_CODE_LENGTH = 48;\n\n// 65-byte signature: 32-byte r + 32-byte s + 1-byte v.\n// '0x' (2) + 32 bytes (64) + 32 bytes (64) + 1 byte (2) = 132 characters.\nconst SIGNATURE_HEX_LENGTH = 132;\n// '0x' + 32-byte r = 66 characters.\nconst R_END_INDEX = 66;\n// r (66 chars) + 32-byte s (64 chars) = 130 characters.\nconst S_END_INDEX = 130;\nconst V_END_INDEX = SIGNATURE_HEX_LENGTH;\n// v = 27 means yParity = 0; v = 28 means yParity = 1.\nconst V_BASE = 27;\n\n/**\n * Submits the EIP-7702 delegation-slot authorization to CHOMP so the Money\n * Account can be upgraded to a smart account pointed at the configured\n * delegator impl.\n *\n * The step:\n *\n * 1. Reads the account's on-chain code. If it is already delegated to the\n * configured `delegatorImplAddress`, reports `'already-done'`. If it is\n * delegated to a different address, throws rather than silently\n * overwriting an existing delegation.\n * 2. Fetches the account's current on-chain transaction count — CHOMP\n * validates the nonce matches when it applies the authorization.\n * 3. Signs the EIP-7702 authorization `{ chainId, delegatorImpl, nonce }`\n * with the Money Account's key via the keyring.\n * 4. Splits the 65-byte signature into `r`, `s`, `v`, `yParity` and submits\n * it to `POST /v1/account-upgrade`.\n */\nexport const eip7702AuthorizationStep: Step = {\n name: 'eip-7702-authorization',\n async run({ messenger, address, chainId, delegatorImplAddress }) {\n const provider = getProvider(messenger, chainId);\n\n const existingDelegation = await fetchDelegationAddress(provider, address);\n if (existingDelegation !== undefined) {\n if (existingDelegation === delegatorImplAddress.toLowerCase()) {\n return 'already-done';\n }\n throw new Error(\n `Account ${address} is already upgraded to another smart account: ${existingDelegation}.`,\n );\n }\n\n const chainIdDecimal = parseInt(chainId, 16);\n const nonce = await fetchNonce(provider, address);\n\n const signature = await messenger.call(\n 'KeyringController:signEip7702Authorization',\n {\n chainId: chainIdDecimal,\n contractAddress: delegatorImplAddress,\n nonce,\n from: address,\n },\n );\n\n const { r, s, v, yParity } = splitEip7702Signature(signature);\n\n await messenger.call('ChompApiService:createUpgrade', {\n r,\n s,\n v,\n yParity,\n address,\n chainId: chainIdDecimal.toString(),\n nonce: nonce.toString(),\n });\n\n return 'completed';\n },\n};\n\n/**\n * Splits a 65-byte ECDSA signature produced by\n * `KeyringController:signEip7702Authorization` into its `r`, `s`, `v`\n * components and derives `yParity` (`0` for `v = 27`, `1` for `v = 28`).\n *\n * @param signature - A 0x-prefixed 132-character hex string. Accepted in any\n * case; normalized to lowercase before validation.\n * @returns The signature components.\n */\nfunction splitEip7702Signature(signature: unknown): {\n r: Hex;\n s: Hex;\n v: number;\n yParity: 0 | 1;\n} {\n const normalized =\n typeof signature === 'string' ? signature.toLowerCase() : signature;\n\n if (\n !isStrictHexString(normalized) ||\n normalized.length !== SIGNATURE_HEX_LENGTH\n ) {\n throw new Error(\n `Expected a 0x-prefixed 65-byte signature from signEip7702Authorization, got ${JSON.stringify(signature)}`,\n );\n }\n\n // eslint-disable-next-line id-length\n const v = parseInt(normalized.slice(S_END_INDEX, V_END_INDEX), 16);\n if (v !== 27 && v !== 28) {\n throw new Error(\n `Expected v to be 27 or 28 in signEip7702Authorization signature, got ${v}`,\n );\n }\n\n return {\n r: normalized.slice(0, R_END_INDEX) as Hex,\n s: add0x(normalized.slice(R_END_INDEX, S_END_INDEX)),\n v,\n yParity: v === V_BASE ? 0 : 1,\n };\n}\n\n/**\n * Reads the account's on-chain code and, if the account is currently\n * delegated via EIP-7702, returns the implementation address the delegation\n * points at. Returns `undefined` if the account has no code (a plain EOA).\n * Throws if the code is present but not a valid EIP-7702 delegation, since\n * that means the address is a regular contract and is not eligible for\n * upgrade.\n *\n * @param provider - JSON-RPC provider for the target chain.\n * @param address - The Money Account address.\n * @returns The current delegation address, or `undefined` if none.\n */\nasync function fetchDelegationAddress(\n provider: Provider,\n address: Hex,\n): Promise<Hex | undefined> {\n const code = await provider.request({\n method: 'eth_getCode',\n params: [address, 'latest'],\n });\n\n if (typeof code !== 'string' || !code.startsWith('0x')) {\n throw new Error(\n `Expected 0x-prefixed hex string from eth_getCode, got ${JSON.stringify(code)}`,\n );\n }\n\n const normalized = code.toLowerCase();\n\n if (normalized === '0x') {\n return undefined;\n }\n\n if (\n normalized.length === EIP_7702_DELEGATED_CODE_LENGTH &&\n normalized.startsWith(EIP_7702_DELEGATION_PREFIX)\n ) {\n return add0x(normalized.slice(EIP_7702_DELEGATION_PREFIX.length));\n }\n\n throw new Error(\n `Account ${address} has unexpected on-chain code; expected either no code or an EIP-7702 delegation.`,\n );\n}\n\n/**\n * Fetches the current on-chain transaction count for the given address by\n * issuing an `eth_getTransactionCount` RPC request.\n *\n * @param provider - JSON-RPC provider for the target chain.\n * @param address - The Money Account address.\n * @returns The current nonce as a decimal number.\n */\nasync function fetchNonce(provider: Provider, address: Hex): Promise<number> {\n const nonceHex = await provider.request({\n method: 'eth_getTransactionCount',\n params: [address, 'latest'],\n });\n\n if (!isStrictHexString(nonceHex)) {\n throw new Error(\n `Expected hex string from eth_getTransactionCount, got ${JSON.stringify(nonceHex)}`,\n );\n }\n\n return parseInt(nonceHex, 16);\n}\n\n/**\n * Resolves the JSON-RPC provider for the given chain via NetworkController.\n *\n * @param messenger - The upgrade controller messenger.\n * @param chainId - The chain to query.\n * @returns The provider for that chain.\n */\nfunction getProvider(\n messenger: StepContext['messenger'],\n chainId: Hex,\n): Provider {\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n return messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).provider;\n}\n"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Step } from "./step.cjs";
|
|
2
|
+
/**
|
|
3
|
+
* Submits the EIP-7702 delegation-slot authorization to CHOMP so the Money
|
|
4
|
+
* Account can be upgraded to a smart account pointed at the configured
|
|
5
|
+
* delegator impl.
|
|
6
|
+
*
|
|
7
|
+
* The step:
|
|
8
|
+
*
|
|
9
|
+
* 1. Reads the account's on-chain code. If it is already delegated to the
|
|
10
|
+
* configured `delegatorImplAddress`, reports `'already-done'`. If it is
|
|
11
|
+
* delegated to a different address, throws rather than silently
|
|
12
|
+
* overwriting an existing delegation.
|
|
13
|
+
* 2. Fetches the account's current on-chain transaction count — CHOMP
|
|
14
|
+
* validates the nonce matches when it applies the authorization.
|
|
15
|
+
* 3. Signs the EIP-7702 authorization `{ chainId, delegatorImpl, nonce }`
|
|
16
|
+
* with the Money Account's key via the keyring.
|
|
17
|
+
* 4. Splits the 65-byte signature into `r`, `s`, `v`, `yParity` and submits
|
|
18
|
+
* it to `POST /v1/account-upgrade`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const eip7702AuthorizationStep: Step;
|
|
21
|
+
//# sourceMappingURL=eip-7702-authorization.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip-7702-authorization.d.cts","sourceRoot":"","sources":["../../src/steps/eip-7702-authorization.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAe,mBAAe;AAiBhD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,wBAAwB,EAAE,IA0CtC,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { Step } from "./step.mjs";
|
|
2
|
+
/**
|
|
3
|
+
* Submits the EIP-7702 delegation-slot authorization to CHOMP so the Money
|
|
4
|
+
* Account can be upgraded to a smart account pointed at the configured
|
|
5
|
+
* delegator impl.
|
|
6
|
+
*
|
|
7
|
+
* The step:
|
|
8
|
+
*
|
|
9
|
+
* 1. Reads the account's on-chain code. If it is already delegated to the
|
|
10
|
+
* configured `delegatorImplAddress`, reports `'already-done'`. If it is
|
|
11
|
+
* delegated to a different address, throws rather than silently
|
|
12
|
+
* overwriting an existing delegation.
|
|
13
|
+
* 2. Fetches the account's current on-chain transaction count — CHOMP
|
|
14
|
+
* validates the nonce matches when it applies the authorization.
|
|
15
|
+
* 3. Signs the EIP-7702 authorization `{ chainId, delegatorImpl, nonce }`
|
|
16
|
+
* with the Money Account's key via the keyring.
|
|
17
|
+
* 4. Splits the 65-byte signature into `r`, `s`, `v`, `yParity` and submits
|
|
18
|
+
* it to `POST /v1/account-upgrade`.
|
|
19
|
+
*/
|
|
20
|
+
export declare const eip7702AuthorizationStep: Step;
|
|
21
|
+
//# sourceMappingURL=eip-7702-authorization.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eip-7702-authorization.d.mts","sourceRoot":"","sources":["../../src/steps/eip-7702-authorization.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,IAAI,EAAe,mBAAe;AAiBhD;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,wBAAwB,EAAE,IA0CtC,CAAC"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { add0x, isStrictHexString } from "@metamask/utils";
|
|
2
|
+
const EIP_7702_DELEGATION_PREFIX = '0xef0100';
|
|
3
|
+
// '0x' (2) + 'ef0100' (6) + 20-byte address (40) = 48 characters.
|
|
4
|
+
const EIP_7702_DELEGATED_CODE_LENGTH = 48;
|
|
5
|
+
// 65-byte signature: 32-byte r + 32-byte s + 1-byte v.
|
|
6
|
+
// '0x' (2) + 32 bytes (64) + 32 bytes (64) + 1 byte (2) = 132 characters.
|
|
7
|
+
const SIGNATURE_HEX_LENGTH = 132;
|
|
8
|
+
// '0x' + 32-byte r = 66 characters.
|
|
9
|
+
const R_END_INDEX = 66;
|
|
10
|
+
// r (66 chars) + 32-byte s (64 chars) = 130 characters.
|
|
11
|
+
const S_END_INDEX = 130;
|
|
12
|
+
const V_END_INDEX = SIGNATURE_HEX_LENGTH;
|
|
13
|
+
// v = 27 means yParity = 0; v = 28 means yParity = 1.
|
|
14
|
+
const V_BASE = 27;
|
|
15
|
+
/**
|
|
16
|
+
* Submits the EIP-7702 delegation-slot authorization to CHOMP so the Money
|
|
17
|
+
* Account can be upgraded to a smart account pointed at the configured
|
|
18
|
+
* delegator impl.
|
|
19
|
+
*
|
|
20
|
+
* The step:
|
|
21
|
+
*
|
|
22
|
+
* 1. Reads the account's on-chain code. If it is already delegated to the
|
|
23
|
+
* configured `delegatorImplAddress`, reports `'already-done'`. If it is
|
|
24
|
+
* delegated to a different address, throws rather than silently
|
|
25
|
+
* overwriting an existing delegation.
|
|
26
|
+
* 2. Fetches the account's current on-chain transaction count — CHOMP
|
|
27
|
+
* validates the nonce matches when it applies the authorization.
|
|
28
|
+
* 3. Signs the EIP-7702 authorization `{ chainId, delegatorImpl, nonce }`
|
|
29
|
+
* with the Money Account's key via the keyring.
|
|
30
|
+
* 4. Splits the 65-byte signature into `r`, `s`, `v`, `yParity` and submits
|
|
31
|
+
* it to `POST /v1/account-upgrade`.
|
|
32
|
+
*/
|
|
33
|
+
export const eip7702AuthorizationStep = {
|
|
34
|
+
name: 'eip-7702-authorization',
|
|
35
|
+
async run({ messenger, address, chainId, delegatorImplAddress }) {
|
|
36
|
+
const provider = getProvider(messenger, chainId);
|
|
37
|
+
const existingDelegation = await fetchDelegationAddress(provider, address);
|
|
38
|
+
if (existingDelegation !== undefined) {
|
|
39
|
+
if (existingDelegation === delegatorImplAddress.toLowerCase()) {
|
|
40
|
+
return 'already-done';
|
|
41
|
+
}
|
|
42
|
+
throw new Error(`Account ${address} is already upgraded to another smart account: ${existingDelegation}.`);
|
|
43
|
+
}
|
|
44
|
+
const chainIdDecimal = parseInt(chainId, 16);
|
|
45
|
+
const nonce = await fetchNonce(provider, address);
|
|
46
|
+
const signature = await messenger.call('KeyringController:signEip7702Authorization', {
|
|
47
|
+
chainId: chainIdDecimal,
|
|
48
|
+
contractAddress: delegatorImplAddress,
|
|
49
|
+
nonce,
|
|
50
|
+
from: address,
|
|
51
|
+
});
|
|
52
|
+
const { r, s, v, yParity } = splitEip7702Signature(signature);
|
|
53
|
+
await messenger.call('ChompApiService:createUpgrade', {
|
|
54
|
+
r,
|
|
55
|
+
s,
|
|
56
|
+
v,
|
|
57
|
+
yParity,
|
|
58
|
+
address,
|
|
59
|
+
chainId: chainIdDecimal.toString(),
|
|
60
|
+
nonce: nonce.toString(),
|
|
61
|
+
});
|
|
62
|
+
return 'completed';
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* Splits a 65-byte ECDSA signature produced by
|
|
67
|
+
* `KeyringController:signEip7702Authorization` into its `r`, `s`, `v`
|
|
68
|
+
* components and derives `yParity` (`0` for `v = 27`, `1` for `v = 28`).
|
|
69
|
+
*
|
|
70
|
+
* @param signature - A 0x-prefixed 132-character hex string. Accepted in any
|
|
71
|
+
* case; normalized to lowercase before validation.
|
|
72
|
+
* @returns The signature components.
|
|
73
|
+
*/
|
|
74
|
+
function splitEip7702Signature(signature) {
|
|
75
|
+
const normalized = typeof signature === 'string' ? signature.toLowerCase() : signature;
|
|
76
|
+
if (!isStrictHexString(normalized) ||
|
|
77
|
+
normalized.length !== SIGNATURE_HEX_LENGTH) {
|
|
78
|
+
throw new Error(`Expected a 0x-prefixed 65-byte signature from signEip7702Authorization, got ${JSON.stringify(signature)}`);
|
|
79
|
+
}
|
|
80
|
+
// eslint-disable-next-line id-length
|
|
81
|
+
const v = parseInt(normalized.slice(S_END_INDEX, V_END_INDEX), 16);
|
|
82
|
+
if (v !== 27 && v !== 28) {
|
|
83
|
+
throw new Error(`Expected v to be 27 or 28 in signEip7702Authorization signature, got ${v}`);
|
|
84
|
+
}
|
|
85
|
+
return {
|
|
86
|
+
r: normalized.slice(0, R_END_INDEX),
|
|
87
|
+
s: add0x(normalized.slice(R_END_INDEX, S_END_INDEX)),
|
|
88
|
+
v,
|
|
89
|
+
yParity: v === V_BASE ? 0 : 1,
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Reads the account's on-chain code and, if the account is currently
|
|
94
|
+
* delegated via EIP-7702, returns the implementation address the delegation
|
|
95
|
+
* points at. Returns `undefined` if the account has no code (a plain EOA).
|
|
96
|
+
* Throws if the code is present but not a valid EIP-7702 delegation, since
|
|
97
|
+
* that means the address is a regular contract and is not eligible for
|
|
98
|
+
* upgrade.
|
|
99
|
+
*
|
|
100
|
+
* @param provider - JSON-RPC provider for the target chain.
|
|
101
|
+
* @param address - The Money Account address.
|
|
102
|
+
* @returns The current delegation address, or `undefined` if none.
|
|
103
|
+
*/
|
|
104
|
+
async function fetchDelegationAddress(provider, address) {
|
|
105
|
+
const code = await provider.request({
|
|
106
|
+
method: 'eth_getCode',
|
|
107
|
+
params: [address, 'latest'],
|
|
108
|
+
});
|
|
109
|
+
if (typeof code !== 'string' || !code.startsWith('0x')) {
|
|
110
|
+
throw new Error(`Expected 0x-prefixed hex string from eth_getCode, got ${JSON.stringify(code)}`);
|
|
111
|
+
}
|
|
112
|
+
const normalized = code.toLowerCase();
|
|
113
|
+
if (normalized === '0x') {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
if (normalized.length === EIP_7702_DELEGATED_CODE_LENGTH &&
|
|
117
|
+
normalized.startsWith(EIP_7702_DELEGATION_PREFIX)) {
|
|
118
|
+
return add0x(normalized.slice(EIP_7702_DELEGATION_PREFIX.length));
|
|
119
|
+
}
|
|
120
|
+
throw new Error(`Account ${address} has unexpected on-chain code; expected either no code or an EIP-7702 delegation.`);
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Fetches the current on-chain transaction count for the given address by
|
|
124
|
+
* issuing an `eth_getTransactionCount` RPC request.
|
|
125
|
+
*
|
|
126
|
+
* @param provider - JSON-RPC provider for the target chain.
|
|
127
|
+
* @param address - The Money Account address.
|
|
128
|
+
* @returns The current nonce as a decimal number.
|
|
129
|
+
*/
|
|
130
|
+
async function fetchNonce(provider, address) {
|
|
131
|
+
const nonceHex = await provider.request({
|
|
132
|
+
method: 'eth_getTransactionCount',
|
|
133
|
+
params: [address, 'latest'],
|
|
134
|
+
});
|
|
135
|
+
if (!isStrictHexString(nonceHex)) {
|
|
136
|
+
throw new Error(`Expected hex string from eth_getTransactionCount, got ${JSON.stringify(nonceHex)}`);
|
|
137
|
+
}
|
|
138
|
+
return parseInt(nonceHex, 16);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Resolves the JSON-RPC provider for the given chain via NetworkController.
|
|
142
|
+
*
|
|
143
|
+
* @param messenger - The upgrade controller messenger.
|
|
144
|
+
* @param chainId - The chain to query.
|
|
145
|
+
* @returns The provider for that chain.
|
|
146
|
+
*/
|
|
147
|
+
function getProvider(messenger, chainId) {
|
|
148
|
+
const networkClientId = messenger.call('NetworkController:findNetworkClientIdByChainId', chainId);
|
|
149
|
+
return messenger.call('NetworkController:getNetworkClientById', networkClientId).provider;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=eip-7702-authorization.mjs.map
|
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QAAQ,CAAC;KAC5B,CAAC,CAAC;IAEH,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CACb,yDAAyD,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,CACpF,CAAC;IACJ,CAAC;IAED,OAAO,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;AAChC,CAAC;AAED;;;;;;GAMG;AACH,SAAS,WAAW,CAClB,SAAmC,EACnC,OAAY;IAEZ,MAAM,eAAe,GAAG,SAAS,CAAC,IAAI,CACpC,gDAAgD,EAChD,OAAO,CACR,CAAC;IACF,OAAO,SAAS,CAAC,IAAI,CACnB,wCAAwC,EACxC,eAAe,CAChB,CAAC,QAAQ,CAAC;AACb,CAAC","sourcesContent":["import type { Provider } from '@metamask/network-controller';\nimport { add0x, isStrictHexString } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type { Step, StepContext } from './step';\n\nconst EIP_7702_DELEGATION_PREFIX = '0xef0100';\n// '0x' (2) + 'ef0100' (6) + 20-byte address (40) = 48 characters.\nconst EIP_7702_DELEGATED_CODE_LENGTH = 48;\n\n// 65-byte signature: 32-byte r + 32-byte s + 1-byte v.\n// '0x' (2) + 32 bytes (64) + 32 bytes (64) + 1 byte (2) = 132 characters.\nconst SIGNATURE_HEX_LENGTH = 132;\n// '0x' + 32-byte r = 66 characters.\nconst R_END_INDEX = 66;\n// r (66 chars) + 32-byte s (64 chars) = 130 characters.\nconst S_END_INDEX = 130;\nconst V_END_INDEX = SIGNATURE_HEX_LENGTH;\n// v = 27 means yParity = 0; v = 28 means yParity = 1.\nconst V_BASE = 27;\n\n/**\n * Submits the EIP-7702 delegation-slot authorization to CHOMP so the Money\n * Account can be upgraded to a smart account pointed at the configured\n * delegator impl.\n *\n * The step:\n *\n * 1. Reads the account's on-chain code. If it is already delegated to the\n * configured `delegatorImplAddress`, reports `'already-done'`. If it is\n * delegated to a different address, throws rather than silently\n * overwriting an existing delegation.\n * 2. Fetches the account's current on-chain transaction count — CHOMP\n * validates the nonce matches when it applies the authorization.\n * 3. Signs the EIP-7702 authorization `{ chainId, delegatorImpl, nonce }`\n * with the Money Account's key via the keyring.\n * 4. Splits the 65-byte signature into `r`, `s`, `v`, `yParity` and submits\n * it to `POST /v1/account-upgrade`.\n */\nexport const eip7702AuthorizationStep: Step = {\n name: 'eip-7702-authorization',\n async run({ messenger, address, chainId, delegatorImplAddress }) {\n const provider = getProvider(messenger, chainId);\n\n const existingDelegation = await fetchDelegationAddress(provider, address);\n if (existingDelegation !== undefined) {\n if (existingDelegation === delegatorImplAddress.toLowerCase()) {\n return 'already-done';\n }\n throw new Error(\n `Account ${address} is already upgraded to another smart account: ${existingDelegation}.`,\n );\n }\n\n const chainIdDecimal = parseInt(chainId, 16);\n const nonce = await fetchNonce(provider, address);\n\n const signature = await messenger.call(\n 'KeyringController:signEip7702Authorization',\n {\n chainId: chainIdDecimal,\n contractAddress: delegatorImplAddress,\n nonce,\n from: address,\n },\n );\n\n const { r, s, v, yParity } = splitEip7702Signature(signature);\n\n await messenger.call('ChompApiService:createUpgrade', {\n r,\n s,\n v,\n yParity,\n address,\n chainId: chainIdDecimal.toString(),\n nonce: nonce.toString(),\n });\n\n return 'completed';\n },\n};\n\n/**\n * Splits a 65-byte ECDSA signature produced by\n * `KeyringController:signEip7702Authorization` into its `r`, `s`, `v`\n * components and derives `yParity` (`0` for `v = 27`, `1` for `v = 28`).\n *\n * @param signature - A 0x-prefixed 132-character hex string. Accepted in any\n * case; normalized to lowercase before validation.\n * @returns The signature components.\n */\nfunction splitEip7702Signature(signature: unknown): {\n r: Hex;\n s: Hex;\n v: number;\n yParity: 0 | 1;\n} {\n const normalized =\n typeof signature === 'string' ? signature.toLowerCase() : signature;\n\n if (\n !isStrictHexString(normalized) ||\n normalized.length !== SIGNATURE_HEX_LENGTH\n ) {\n throw new Error(\n `Expected a 0x-prefixed 65-byte signature from signEip7702Authorization, got ${JSON.stringify(signature)}`,\n );\n }\n\n // eslint-disable-next-line id-length\n const v = parseInt(normalized.slice(S_END_INDEX, V_END_INDEX), 16);\n if (v !== 27 && v !== 28) {\n throw new Error(\n `Expected v to be 27 or 28 in signEip7702Authorization signature, got ${v}`,\n );\n }\n\n return {\n r: normalized.slice(0, R_END_INDEX) as Hex,\n s: add0x(normalized.slice(R_END_INDEX, S_END_INDEX)),\n v,\n yParity: v === V_BASE ? 0 : 1,\n };\n}\n\n/**\n * Reads the account's on-chain code and, if the account is currently\n * delegated via EIP-7702, returns the implementation address the delegation\n * points at. Returns `undefined` if the account has no code (a plain EOA).\n * Throws if the code is present but not a valid EIP-7702 delegation, since\n * that means the address is a regular contract and is not eligible for\n * upgrade.\n *\n * @param provider - JSON-RPC provider for the target chain.\n * @param address - The Money Account address.\n * @returns The current delegation address, or `undefined` if none.\n */\nasync function fetchDelegationAddress(\n provider: Provider,\n address: Hex,\n): Promise<Hex | undefined> {\n const code = await provider.request({\n method: 'eth_getCode',\n params: [address, 'latest'],\n });\n\n if (typeof code !== 'string' || !code.startsWith('0x')) {\n throw new Error(\n `Expected 0x-prefixed hex string from eth_getCode, got ${JSON.stringify(code)}`,\n );\n }\n\n const normalized = code.toLowerCase();\n\n if (normalized === '0x') {\n return undefined;\n }\n\n if (\n normalized.length === EIP_7702_DELEGATED_CODE_LENGTH &&\n normalized.startsWith(EIP_7702_DELEGATION_PREFIX)\n ) {\n return add0x(normalized.slice(EIP_7702_DELEGATION_PREFIX.length));\n }\n\n throw new Error(\n `Account ${address} has unexpected on-chain code; expected either no code or an EIP-7702 delegation.`,\n );\n}\n\n/**\n * Fetches the current on-chain transaction count for the given address by\n * issuing an `eth_getTransactionCount` RPC request.\n *\n * @param provider - JSON-RPC provider for the target chain.\n * @param address - The Money Account address.\n * @returns The current nonce as a decimal number.\n */\nasync function fetchNonce(provider: Provider, address: Hex): Promise<number> {\n const nonceHex = await provider.request({\n method: 'eth_getTransactionCount',\n params: [address, 'latest'],\n });\n\n if (!isStrictHexString(nonceHex)) {\n throw new Error(\n `Expected hex string from eth_getTransactionCount, got ${JSON.stringify(nonceHex)}`,\n );\n }\n\n return parseInt(nonceHex, 16);\n}\n\n/**\n * Resolves the JSON-RPC provider for the given chain via NetworkController.\n *\n * @param messenger - The upgrade controller messenger.\n * @param chainId - The chain to query.\n * @returns The provider for that chain.\n */\nfunction getProvider(\n messenger: StepContext['messenger'],\n chainId: Hex,\n): Provider {\n const networkClientId = messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n return messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).provider;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step.cjs","sourceRoot":"","sources":["../../src/steps/step.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMessenger } from '../MoneyAccountUpgradeController';\n\n/**\n * Context supplied to each step when it is run.\n */\nexport type StepContext = {\n messenger: MoneyAccountUpgradeControllerMessenger;\n address: Hex;\n chainId: Hex;\n delegatorImplAddress: Hex;\n};\n\n/**\n * The outcome of running a single step in the Money Account upgrade sequence.\n *\n * - `'already-done'` — the step's remote check determined that no work was\n * required; no action was taken.\n * - `'completed'` — the step performed its action and is now done.\n */\nexport type StepResult = 'already-done' | 'completed';\n\n/**\n * A single step in the Money Account upgrade sequence.\n *\n * Each step is responsible for checking whether its action has already been\n * applied (returning `'already-done'` if so) and otherwise performing the\n * action and returning `'completed'`.\n */\nexport type Step = {\n name: string;\n run: (context: StepContext) => Promise<StepResult>;\n};\n"]}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Hex } from "@metamask/utils";
|
|
2
|
-
import type { MoneyAccountUpgradeControllerMessenger } from "
|
|
2
|
+
import type { MoneyAccountUpgradeControllerMessenger } from "../MoneyAccountUpgradeController.cjs";
|
|
3
3
|
/**
|
|
4
4
|
* Context supplied to each step when it is run.
|
|
5
5
|
*/
|
|
6
6
|
export type StepContext = {
|
|
7
7
|
messenger: MoneyAccountUpgradeControllerMessenger;
|
|
8
8
|
address: Hex;
|
|
9
|
+
chainId: Hex;
|
|
10
|
+
delegatorImplAddress: Hex;
|
|
9
11
|
};
|
|
10
12
|
/**
|
|
11
13
|
* The outcome of running a single step in the Money Account upgrade sequence.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step.d.cts","sourceRoot":"","sources":["../../src/steps/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,sCAAsC,EAAE,6CAAyC;AAE/F;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,sCAAsC,CAAC;IAClD,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,GAAG,CAAC;IACb,oBAAoB,EAAE,GAAG,CAAC;CAC3B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,WAAW,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CACpD,CAAC"}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import type { Hex } from "@metamask/utils";
|
|
2
|
-
import type { MoneyAccountUpgradeControllerMessenger } from "
|
|
2
|
+
import type { MoneyAccountUpgradeControllerMessenger } from "../MoneyAccountUpgradeController.mjs";
|
|
3
3
|
/**
|
|
4
4
|
* Context supplied to each step when it is run.
|
|
5
5
|
*/
|
|
6
6
|
export type StepContext = {
|
|
7
7
|
messenger: MoneyAccountUpgradeControllerMessenger;
|
|
8
8
|
address: Hex;
|
|
9
|
+
chainId: Hex;
|
|
10
|
+
delegatorImplAddress: Hex;
|
|
9
11
|
};
|
|
10
12
|
/**
|
|
11
13
|
* The outcome of running a single step in the Money Account upgrade sequence.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step.d.mts","sourceRoot":"","sources":["../../src/steps/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,sCAAsC,EAAE,6CAAyC;AAE/F;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,sCAAsC,CAAC;IAClD,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,GAAG,CAAC;IACb,oBAAoB,EAAE,GAAG,CAAC;CAC3B,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,WAAW,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CACpD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"step.mjs","sourceRoot":"","sources":["../../src/steps/step.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMessenger } from '../MoneyAccountUpgradeController';\n\n/**\n * Context supplied to each step when it is run.\n */\nexport type StepContext = {\n messenger: MoneyAccountUpgradeControllerMessenger;\n address: Hex;\n chainId: Hex;\n delegatorImplAddress: Hex;\n};\n\n/**\n * The outcome of running a single step in the Money Account upgrade sequence.\n *\n * - `'already-done'` — the step's remote check determined that no work was\n * required; no action was taken.\n * - `'completed'` — the step performed its action and is now done.\n */\nexport type StepResult = 'already-done' | 'completed';\n\n/**\n * A single step in the Money Account upgrade sequence.\n *\n * Each step is responsible for checking whether its action has already been\n * applied (returning `'already-done'` if so) and otherwise performing the\n * action and returning `'completed'`.\n */\nexport type Step = {\n name: string;\n run: (context: StepContext) => Promise<StepResult>;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/money-account-upgrade-controller",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "MetaMask Money account upgrade controller",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|
|
@@ -54,13 +54,14 @@
|
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
56
|
"@metamask/base-controller": "^9.1.0",
|
|
57
|
-
"@metamask/chomp-api-service": "^
|
|
57
|
+
"@metamask/chomp-api-service": "^2.0.0",
|
|
58
58
|
"@metamask/keyring-controller": "^25.2.0",
|
|
59
|
-
"@metamask/messenger": "^1.1.1"
|
|
59
|
+
"@metamask/messenger": "^1.1.1",
|
|
60
|
+
"@metamask/network-controller": "^30.0.1",
|
|
61
|
+
"@metamask/utils": "^11.9.0"
|
|
60
62
|
},
|
|
61
63
|
"devDependencies": {
|
|
62
64
|
"@metamask/auto-changelog": "^6.1.0",
|
|
63
|
-
"@metamask/utils": "^11.9.0",
|
|
64
65
|
"@ts-bridge/cli": "^0.6.4",
|
|
65
66
|
"@types/jest": "^29.5.14",
|
|
66
67
|
"deepmerge": "^4.2.2",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"associate-address.cjs","sourceRoot":"","sources":["../src/associate-address.ts"],"names":[],"mappings":";;;AAIA,MAAM,yBAAyB,GAAG,oBAAoB,CAAC;AAEvD;;;;;;;;;;;GAWG;AACU,QAAA,oBAAoB,GAAS;IACxC,IAAI,EAAE,mBAAmB;IACzB,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE;QAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QACxC,MAAM,OAAO,GAAG,wBAAwB,SAAS,EAAE,CAAC;QAEpD,MAAM,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,IAAI,CACrC,uCAAuC,EACvC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CACjC,CAAQ,CAAC;QAEV,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,kCAAkC,EAAE;YACxE,SAAS;YACT,SAAS;YACT,OAAO;SACR,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,yBAAyB,EAAE,CAAC;YAClD,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { Step } from './step';\n\nconst ALREADY_ASSOCIATED_STATUS = 'already_associated';\n\n/**\n * Associates the Money Account address with the user's CHOMP profile.\n *\n * Signs `CHOMP Authentication {timestamp}` (EIP-191) with the account's key\n * and submits the signature to CHOMP, which verifies the timestamp is fresh,\n * recovers the signer, and records the profile–address mapping.\n *\n * CHOMP responds with 201 and `status: 'created'` when the association is\n * made, and 409 with `status: 'already_associated'` when the address is\n * already linked to a profile. The service surfaces both responses, so this\n * step reports `'already-done'` for the 409 case and `'completed'` otherwise.\n */\nexport const associateAddressStep: Step = {\n name: 'associate-address',\n async run({ messenger, address }) {\n const timestamp = Date.now().toString();\n const message = `CHOMP Authentication ${timestamp}`;\n\n const signature = (await messenger.call(\n 'KeyringController:signPersonalMessage',\n { data: message, from: address },\n )) as Hex;\n\n const response = await messenger.call('ChompApiService:associateAddress', {\n signature,\n timestamp,\n address,\n });\n\n if (response.status === ALREADY_ASSOCIATED_STATUS) {\n return 'already-done';\n }\n\n return 'completed';\n },\n};\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"associate-address.d.cts","sourceRoot":"","sources":["../src/associate-address.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAInC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,EAAE,IAuBlC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"associate-address.d.mts","sourceRoot":"","sources":["../src/associate-address.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,IAAI,EAAE,mBAAe;AAInC;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,oBAAoB,EAAE,IAuBlC,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"associate-address.mjs","sourceRoot":"","sources":["../src/associate-address.ts"],"names":[],"mappings":"AAIA,MAAM,yBAAyB,GAAG,oBAAoB,CAAC;AAEvD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAS;IACxC,IAAI,EAAE,mBAAmB;IACzB,KAAK,CAAC,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE;QAC9B,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;QACxC,MAAM,OAAO,GAAG,wBAAwB,SAAS,EAAE,CAAC;QAEpD,MAAM,SAAS,GAAG,CAAC,MAAM,SAAS,CAAC,IAAI,CACrC,uCAAuC,EACvC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CACjC,CAAQ,CAAC;QAEV,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,IAAI,CAAC,kCAAkC,EAAE;YACxE,SAAS;YACT,SAAS;YACT,OAAO;SACR,CAAC,CAAC;QAEH,IAAI,QAAQ,CAAC,MAAM,KAAK,yBAAyB,EAAE,CAAC;YAClD,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;CACF,CAAC","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { Step } from './step';\n\nconst ALREADY_ASSOCIATED_STATUS = 'already_associated';\n\n/**\n * Associates the Money Account address with the user's CHOMP profile.\n *\n * Signs `CHOMP Authentication {timestamp}` (EIP-191) with the account's key\n * and submits the signature to CHOMP, which verifies the timestamp is fresh,\n * recovers the signer, and records the profile–address mapping.\n *\n * CHOMP responds with 201 and `status: 'created'` when the association is\n * made, and 409 with `status: 'already_associated'` when the address is\n * already linked to a profile. The service surfaces both responses, so this\n * step reports `'already-done'` for the 409 case and `'completed'` otherwise.\n */\nexport const associateAddressStep: Step = {\n name: 'associate-address',\n async run({ messenger, address }) {\n const timestamp = Date.now().toString();\n const message = `CHOMP Authentication ${timestamp}`;\n\n const signature = (await messenger.call(\n 'KeyringController:signPersonalMessage',\n { data: message, from: address },\n )) as Hex;\n\n const response = await messenger.call('ChompApiService:associateAddress', {\n signature,\n timestamp,\n address,\n });\n\n if (response.status === ALREADY_ASSOCIATED_STATUS) {\n return 'already-done';\n }\n\n return 'completed';\n },\n};\n"]}
|
package/dist/step.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"step.cjs","sourceRoot":"","sources":["../src/step.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMessenger } from './MoneyAccountUpgradeController';\n\n/**\n * Context supplied to each step when it is run.\n */\nexport type StepContext = {\n messenger: MoneyAccountUpgradeControllerMessenger;\n address: Hex;\n};\n\n/**\n * The outcome of running a single step in the Money Account upgrade sequence.\n *\n * - `'already-done'` — the step's remote check determined that no work was\n * required; no action was taken.\n * - `'completed'` — the step performed its action and is now done.\n */\nexport type StepResult = 'already-done' | 'completed';\n\n/**\n * A single step in the Money Account upgrade sequence.\n *\n * Each step is responsible for checking whether its action has already been\n * applied (returning `'already-done'` if so) and otherwise performing the\n * action and returning `'completed'`.\n */\nexport type Step = {\n name: string;\n run: (context: StepContext) => Promise<StepResult>;\n};\n"]}
|
package/dist/step.d.cts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"step.d.cts","sourceRoot":"","sources":["../src/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,sCAAsC,EAAE,4CAAwC;AAE9F;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,sCAAsC,CAAC;IAClD,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,WAAW,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CACpD,CAAC"}
|
package/dist/step.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"step.d.mts","sourceRoot":"","sources":["../src/step.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,sCAAsC,EAAE,4CAAwC;AAE9F;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG;IACxB,SAAS,EAAE,sCAAsC,CAAC;IAClD,OAAO,EAAE,GAAG,CAAC;CACd,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,GAAG,cAAc,GAAG,WAAW,CAAC;AAEtD;;;;;;GAMG;AACH,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;CACpD,CAAC"}
|
package/dist/step.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"step.mjs","sourceRoot":"","sources":["../src/step.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type { MoneyAccountUpgradeControllerMessenger } from './MoneyAccountUpgradeController';\n\n/**\n * Context supplied to each step when it is run.\n */\nexport type StepContext = {\n messenger: MoneyAccountUpgradeControllerMessenger;\n address: Hex;\n};\n\n/**\n * The outcome of running a single step in the Money Account upgrade sequence.\n *\n * - `'already-done'` — the step's remote check determined that no work was\n * required; no action was taken.\n * - `'completed'` — the step performed its action and is now done.\n */\nexport type StepResult = 'already-done' | 'completed';\n\n/**\n * A single step in the Money Account upgrade sequence.\n *\n * Each step is responsible for checking whether its action has already been\n * applied (returning `'already-done'` if so) and otherwise performing the\n * action and returning `'completed'`.\n */\nexport type Step = {\n name: string;\n run: (context: StepContext) => Promise<StepResult>;\n};\n"]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|