@metamask/snaps-controllers 18.0.4 → 19.0.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 +96 -1
- package/dist/cronjob/CronjobController-method-action-types.cjs +7 -0
- package/dist/cronjob/CronjobController-method-action-types.cjs.map +1 -0
- package/dist/cronjob/CronjobController-method-action-types.d.cts +51 -0
- package/dist/cronjob/CronjobController-method-action-types.d.cts.map +1 -0
- package/dist/cronjob/CronjobController-method-action-types.d.mts +51 -0
- package/dist/cronjob/CronjobController-method-action-types.d.mts.map +1 -0
- package/dist/cronjob/CronjobController-method-action-types.mjs +6 -0
- package/dist/cronjob/CronjobController-method-action-types.mjs.map +1 -0
- package/dist/cronjob/CronjobController.cjs +7 -4
- package/dist/cronjob/CronjobController.cjs.map +1 -1
- package/dist/cronjob/CronjobController.d.cts +7 -24
- package/dist/cronjob/CronjobController.d.cts.map +1 -1
- package/dist/cronjob/CronjobController.d.mts +7 -24
- package/dist/cronjob/CronjobController.d.mts.map +1 -1
- package/dist/cronjob/CronjobController.mjs +7 -4
- package/dist/cronjob/CronjobController.mjs.map +1 -1
- package/dist/cronjob/index.cjs +3 -15
- package/dist/cronjob/index.cjs.map +1 -1
- package/dist/cronjob/index.d.cts +3 -1
- package/dist/cronjob/index.d.cts.map +1 -1
- package/dist/cronjob/index.d.mts +3 -1
- package/dist/cronjob/index.d.mts.map +1 -1
- package/dist/cronjob/index.mjs +1 -1
- package/dist/cronjob/index.mjs.map +1 -1
- package/dist/insights/SnapInsightsController.cjs +1 -3
- package/dist/insights/SnapInsightsController.cjs.map +1 -1
- package/dist/insights/SnapInsightsController.d.cts +8 -8
- package/dist/insights/SnapInsightsController.d.cts.map +1 -1
- package/dist/insights/SnapInsightsController.d.mts +8 -8
- package/dist/insights/SnapInsightsController.d.mts.map +1 -1
- package/dist/insights/SnapInsightsController.mjs +1 -3
- package/dist/insights/SnapInsightsController.mjs.map +1 -1
- package/dist/insights/index.cjs +3 -15
- package/dist/insights/index.cjs.map +1 -1
- package/dist/insights/index.d.cts +2 -1
- package/dist/insights/index.d.cts.map +1 -1
- package/dist/insights/index.d.mts +2 -1
- package/dist/insights/index.d.mts.map +1 -1
- package/dist/insights/index.mjs +1 -1
- package/dist/insights/index.mjs.map +1 -1
- package/dist/interface/SnapInterfaceController-method-action-types.cjs +7 -0
- package/dist/interface/SnapInterfaceController-method-action-types.cjs.map +1 -0
- package/dist/interface/SnapInterfaceController-method-action-types.d.cts +99 -0
- package/dist/interface/SnapInterfaceController-method-action-types.d.cts.map +1 -0
- package/dist/interface/SnapInterfaceController-method-action-types.d.mts +99 -0
- package/dist/interface/SnapInterfaceController-method-action-types.d.mts.map +1 -0
- package/dist/interface/SnapInterfaceController-method-action-types.mjs +6 -0
- package/dist/interface/SnapInterfaceController-method-action-types.mjs.map +1 -0
- package/dist/interface/SnapInterfaceController.cjs +12 -16
- package/dist/interface/SnapInterfaceController.cjs.map +1 -1
- package/dist/interface/SnapInterfaceController.d.cts +9 -39
- package/dist/interface/SnapInterfaceController.d.cts.map +1 -1
- package/dist/interface/SnapInterfaceController.d.mts +9 -39
- package/dist/interface/SnapInterfaceController.d.mts.map +1 -1
- package/dist/interface/SnapInterfaceController.mjs +12 -16
- package/dist/interface/SnapInterfaceController.mjs.map +1 -1
- package/dist/interface/index.cjs +3 -15
- package/dist/interface/index.cjs.map +1 -1
- package/dist/interface/index.d.cts +3 -1
- package/dist/interface/index.d.cts.map +1 -1
- package/dist/interface/index.d.mts +3 -1
- package/dist/interface/index.d.mts.map +1 -1
- package/dist/interface/index.mjs +1 -1
- package/dist/interface/index.mjs.map +1 -1
- package/dist/multichain/MultichainRoutingService-method-action-types.cjs +7 -0
- package/dist/multichain/MultichainRoutingService-method-action-types.cjs.map +1 -0
- package/dist/multichain/MultichainRoutingService-method-action-types.d.cts +61 -0
- package/dist/multichain/MultichainRoutingService-method-action-types.d.cts.map +1 -0
- package/dist/multichain/MultichainRoutingService-method-action-types.d.mts +61 -0
- package/dist/multichain/MultichainRoutingService-method-action-types.d.mts.map +1 -0
- package/dist/multichain/MultichainRoutingService-method-action-types.mjs +6 -0
- package/dist/multichain/MultichainRoutingService-method-action-types.mjs.map +1 -0
- package/dist/multichain/{MultichainRouter.cjs → MultichainRoutingService.cjs} +14 -13
- package/dist/multichain/MultichainRoutingService.cjs.map +1 -0
- package/dist/multichain/{MultichainRouter.d.mts → MultichainRoutingService.d.cts} +13 -28
- package/dist/multichain/MultichainRoutingService.d.cts.map +1 -0
- package/dist/multichain/{MultichainRouter.d.cts → MultichainRoutingService.d.mts} +13 -28
- package/dist/multichain/MultichainRoutingService.d.mts.map +1 -0
- package/dist/multichain/{MultichainRouter.mjs → MultichainRoutingService.mjs} +12 -11
- package/dist/multichain/MultichainRoutingService.mjs.map +1 -0
- package/dist/multichain/index.cjs +3 -15
- package/dist/multichain/index.cjs.map +1 -1
- package/dist/multichain/index.d.cts +3 -1
- package/dist/multichain/index.d.cts.map +1 -1
- package/dist/multichain/index.d.mts +3 -1
- package/dist/multichain/index.d.mts.map +1 -1
- package/dist/multichain/index.mjs +1 -1
- package/dist/multichain/index.mjs.map +1 -1
- package/dist/services/ExecutionService-method-action-types.cjs +7 -0
- package/dist/services/ExecutionService-method-action-types.cjs.map +1 -0
- package/dist/services/ExecutionService-method-action-types.d.cts +50 -0
- package/dist/services/ExecutionService-method-action-types.d.cts.map +1 -0
- package/dist/services/ExecutionService-method-action-types.d.mts +50 -0
- package/dist/services/ExecutionService-method-action-types.d.mts.map +1 -0
- package/dist/services/ExecutionService-method-action-types.mjs +6 -0
- package/dist/services/ExecutionService-method-action-types.mjs.map +1 -0
- package/dist/services/ExecutionService.cjs +287 -0
- package/dist/services/ExecutionService.cjs.map +1 -1
- package/dist/services/ExecutionService.d.cts +100 -46
- package/dist/services/ExecutionService.d.cts.map +1 -1
- package/dist/services/ExecutionService.d.mts +100 -46
- package/dist/services/ExecutionService.d.mts.map +1 -1
- package/dist/services/ExecutionService.mjs +285 -1
- package/dist/services/ExecutionService.mjs.map +1 -1
- package/dist/services/browser.cjs +5 -2
- package/dist/services/browser.cjs.map +1 -1
- package/dist/services/browser.d.cts +4 -2
- package/dist/services/browser.d.cts.map +1 -1
- package/dist/services/browser.d.mts +4 -2
- package/dist/services/browser.d.mts.map +1 -1
- package/dist/services/browser.mjs +2 -2
- package/dist/services/browser.mjs.map +1 -1
- package/dist/services/iframe/IframeExecutionService.cjs +2 -2
- package/dist/services/iframe/IframeExecutionService.cjs.map +1 -1
- package/dist/services/iframe/IframeExecutionService.d.cts +3 -3
- package/dist/services/iframe/IframeExecutionService.d.cts.map +1 -1
- package/dist/services/iframe/IframeExecutionService.d.mts +3 -3
- package/dist/services/iframe/IframeExecutionService.d.mts.map +1 -1
- package/dist/services/iframe/IframeExecutionService.mjs +2 -2
- package/dist/services/iframe/IframeExecutionService.mjs.map +1 -1
- package/dist/services/index.cjs +5 -1
- package/dist/services/index.cjs.map +1 -1
- package/dist/services/index.d.cts +4 -2
- package/dist/services/index.d.cts.map +1 -1
- package/dist/services/index.d.mts +4 -2
- package/dist/services/index.d.mts.map +1 -1
- package/dist/services/index.mjs +2 -1
- package/dist/services/index.mjs.map +1 -1
- package/dist/services/multiplex.cjs +27 -0
- package/dist/services/multiplex.cjs.map +1 -0
- package/dist/services/multiplex.d.cts +11 -0
- package/dist/services/multiplex.d.cts.map +1 -0
- package/dist/services/multiplex.d.mts +11 -0
- package/dist/services/multiplex.d.mts.map +1 -0
- package/dist/services/multiplex.mjs +27 -0
- package/dist/services/multiplex.mjs.map +1 -0
- package/dist/services/node-js/NodeProcessExecutionService.cjs +2 -2
- package/dist/services/node-js/NodeProcessExecutionService.cjs.map +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.d.cts +3 -3
- package/dist/services/node-js/NodeProcessExecutionService.d.cts.map +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.d.mts +3 -3
- package/dist/services/node-js/NodeProcessExecutionService.d.mts.map +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.mjs +2 -2
- package/dist/services/node-js/NodeProcessExecutionService.mjs.map +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.cjs +2 -5
- package/dist/services/node-js/NodeThreadExecutionService.cjs.map +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.d.cts +3 -3
- package/dist/services/node-js/NodeThreadExecutionService.d.cts.map +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.d.mts +3 -3
- package/dist/services/node-js/NodeThreadExecutionService.d.mts.map +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.mjs +2 -5
- package/dist/services/node-js/NodeThreadExecutionService.mjs.map +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.cjs.map +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.d.cts +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.d.cts.map +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.d.mts +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.d.mts.map +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.mjs.map +1 -1
- package/dist/services/proxy/ProxyExecutionService.cjs +2 -5
- package/dist/services/proxy/ProxyExecutionService.cjs.map +1 -1
- package/dist/services/proxy/ProxyExecutionService.d.cts +3 -3
- package/dist/services/proxy/ProxyExecutionService.d.cts.map +1 -1
- package/dist/services/proxy/ProxyExecutionService.d.mts +3 -3
- package/dist/services/proxy/ProxyExecutionService.d.mts.map +1 -1
- package/dist/services/proxy/ProxyExecutionService.mjs +2 -5
- package/dist/services/proxy/ProxyExecutionService.mjs.map +1 -1
- package/dist/services/webview/WebViewExecutionService.cjs +2 -2
- package/dist/services/webview/WebViewExecutionService.cjs.map +1 -1
- package/dist/services/webview/WebViewExecutionService.d.cts +3 -3
- package/dist/services/webview/WebViewExecutionService.d.cts.map +1 -1
- package/dist/services/webview/WebViewExecutionService.d.mts +3 -3
- package/dist/services/webview/WebViewExecutionService.d.mts.map +1 -1
- package/dist/services/webview/WebViewExecutionService.mjs +2 -2
- package/dist/services/webview/WebViewExecutionService.mjs.map +1 -1
- package/dist/snaps/SnapController-method-action-types.cjs +7 -0
- package/dist/snaps/SnapController-method-action-types.cjs.map +1 -0
- package/dist/snaps/SnapController-method-action-types.d.cts +284 -0
- package/dist/snaps/SnapController-method-action-types.d.cts.map +1 -0
- package/dist/snaps/SnapController-method-action-types.d.mts +284 -0
- package/dist/snaps/SnapController-method-action-types.d.mts.map +1 -0
- package/dist/snaps/SnapController-method-action-types.mjs +6 -0
- package/dist/snaps/SnapController-method-action-types.mjs.map +1 -0
- package/dist/snaps/SnapController.cjs +118 -113
- package/dist/snaps/SnapController.cjs.map +1 -1
- package/dist/snaps/SnapController.d.cts +32 -189
- package/dist/snaps/SnapController.d.cts.map +1 -1
- package/dist/snaps/SnapController.d.mts +32 -189
- package/dist/snaps/SnapController.d.mts.map +1 -1
- package/dist/snaps/SnapController.mjs +119 -114
- package/dist/snaps/SnapController.mjs.map +1 -1
- package/dist/snaps/index.cjs +3 -1
- package/dist/snaps/index.cjs.map +1 -1
- package/dist/snaps/index.d.cts +3 -1
- package/dist/snaps/index.d.cts.map +1 -1
- package/dist/snaps/index.d.mts +3 -1
- package/dist/snaps/index.d.mts.map +1 -1
- package/dist/snaps/index.mjs +1 -1
- package/dist/snaps/index.mjs.map +1 -1
- package/dist/snaps/registry/SnapRegistryController-method-action-types.cjs +7 -0
- package/dist/snaps/registry/SnapRegistryController-method-action-types.cjs.map +1 -0
- package/dist/snaps/registry/SnapRegistryController-method-action-types.d.cts +46 -0
- package/dist/snaps/registry/SnapRegistryController-method-action-types.d.cts.map +1 -0
- package/dist/snaps/registry/SnapRegistryController-method-action-types.d.mts +46 -0
- package/dist/snaps/registry/SnapRegistryController-method-action-types.d.mts.map +1 -0
- package/dist/snaps/registry/SnapRegistryController-method-action-types.mjs +6 -0
- package/dist/snaps/registry/SnapRegistryController-method-action-types.mjs.map +1 -0
- package/dist/snaps/registry/{json.cjs → SnapRegistryController.cjs} +27 -24
- package/dist/snaps/registry/SnapRegistryController.cjs.map +1 -0
- package/dist/snaps/registry/SnapRegistryController.d.cts +67 -0
- package/dist/snaps/registry/SnapRegistryController.d.cts.map +1 -0
- package/dist/snaps/registry/SnapRegistryController.d.mts +67 -0
- package/dist/snaps/registry/SnapRegistryController.d.mts.map +1 -0
- package/dist/snaps/registry/{json.mjs → SnapRegistryController.mjs} +25 -22
- package/dist/snaps/registry/SnapRegistryController.mjs.map +1 -0
- package/dist/snaps/registry/index.cjs +5 -16
- package/dist/snaps/registry/index.cjs.map +1 -1
- package/dist/snaps/registry/index.d.cts +5 -2
- package/dist/snaps/registry/index.d.cts.map +1 -1
- package/dist/snaps/registry/index.d.mts +5 -2
- package/dist/snaps/registry/index.d.mts.map +1 -1
- package/dist/snaps/registry/index.mjs +2 -2
- package/dist/snaps/registry/index.mjs.map +1 -1
- package/dist/snaps/registry/types.cjs +11 -0
- package/dist/snaps/registry/types.cjs.map +1 -0
- package/dist/snaps/registry/types.d.cts +20 -0
- package/dist/snaps/registry/types.d.cts.map +1 -0
- package/dist/snaps/registry/types.d.mts +20 -0
- package/dist/snaps/registry/types.d.mts.map +1 -0
- package/dist/snaps/registry/types.mjs +8 -0
- package/dist/snaps/registry/types.mjs.map +1 -0
- package/dist/types/controllers.cjs.map +1 -1
- package/dist/types/controllers.d.cts +1 -1
- package/dist/types/controllers.d.cts.map +1 -1
- package/dist/types/controllers.d.mts +1 -1
- package/dist/types/controllers.d.mts.map +1 -1
- package/dist/types/controllers.mjs.map +1 -1
- package/dist/websocket/WebSocketService-method-action-types.cjs +7 -0
- package/dist/websocket/WebSocketService-method-action-types.cjs.map +1 -0
- package/dist/websocket/WebSocketService-method-action-types.d.cts +54 -0
- package/dist/websocket/WebSocketService-method-action-types.d.cts.map +1 -0
- package/dist/websocket/WebSocketService-method-action-types.d.mts +54 -0
- package/dist/websocket/WebSocketService-method-action-types.d.mts.map +1 -0
- package/dist/websocket/WebSocketService-method-action-types.mjs +6 -0
- package/dist/websocket/WebSocketService-method-action-types.mjs.map +1 -0
- package/dist/websocket/WebSocketService.cjs +14 -11
- package/dist/websocket/WebSocketService.cjs.map +1 -1
- package/dist/websocket/WebSocketService.d.cts +43 -22
- package/dist/websocket/WebSocketService.d.cts.map +1 -1
- package/dist/websocket/WebSocketService.d.mts +43 -22
- package/dist/websocket/WebSocketService.d.mts.map +1 -1
- package/dist/websocket/WebSocketService.mjs +14 -11
- package/dist/websocket/WebSocketService.mjs.map +1 -1
- package/dist/websocket/index.cjs +3 -15
- package/dist/websocket/index.cjs.map +1 -1
- package/dist/websocket/index.d.cts +3 -1
- package/dist/websocket/index.d.cts.map +1 -1
- package/dist/websocket/index.d.mts +3 -1
- package/dist/websocket/index.d.mts.map +1 -1
- package/dist/websocket/index.mjs +1 -1
- package/dist/websocket/index.mjs.map +1 -1
- package/package.json +8 -7
- package/dist/multichain/MultichainRouter.cjs.map +0 -1
- package/dist/multichain/MultichainRouter.d.cts.map +0 -1
- package/dist/multichain/MultichainRouter.d.mts.map +0 -1
- package/dist/multichain/MultichainRouter.mjs.map +0 -1
- package/dist/services/AbstractExecutionService.cjs +0 -314
- package/dist/services/AbstractExecutionService.cjs.map +0 -1
- package/dist/services/AbstractExecutionService.d.cts +0 -107
- package/dist/services/AbstractExecutionService.d.cts.map +0 -1
- package/dist/services/AbstractExecutionService.d.mts +0 -107
- package/dist/services/AbstractExecutionService.d.mts.map +0 -1
- package/dist/services/AbstractExecutionService.mjs +0 -313
- package/dist/services/AbstractExecutionService.mjs.map +0 -1
- package/dist/snaps/registry/json.cjs.map +0 -1
- package/dist/snaps/registry/json.d.cts +0 -58
- package/dist/snaps/registry/json.d.cts.map +0 -1
- package/dist/snaps/registry/json.d.mts +0 -58
- package/dist/snaps/registry/json.d.mts.map +0 -1
- package/dist/snaps/registry/json.mjs.map +0 -1
- package/dist/snaps/registry/registry.cjs +0 -11
- package/dist/snaps/registry/registry.cjs.map +0 -1
- package/dist/snaps/registry/registry.d.cts +0 -41
- package/dist/snaps/registry/registry.d.cts.map +0 -1
- package/dist/snaps/registry/registry.d.mts +0 -41
- package/dist/snaps/registry/registry.d.mts.map +0 -1
- package/dist/snaps/registry/registry.mjs +0 -8
- package/dist/snaps/registry/registry.mjs.map +0 -1
|
@@ -7,6 +7,16 @@ import { nanoid } from "nanoid";
|
|
|
7
7
|
import { constructState, getJsxInterface, isMatchingChainId, validateInterfaceContext } from "./utils.mjs";
|
|
8
8
|
const MAX_UI_CONTENT_SIZE = 10000000; // 10 mb
|
|
9
9
|
const controllerName = 'SnapInterfaceController';
|
|
10
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
11
|
+
'createInterface',
|
|
12
|
+
'getInterface',
|
|
13
|
+
'getInterfaceState',
|
|
14
|
+
'updateInterface',
|
|
15
|
+
'deleteInterface',
|
|
16
|
+
'updateInterfaceState',
|
|
17
|
+
'resolveInterface',
|
|
18
|
+
'setInterfaceDisplayed',
|
|
19
|
+
];
|
|
10
20
|
/**
|
|
11
21
|
* Use this controller to manage snaps UI interfaces using RPC method hooks.
|
|
12
22
|
*/
|
|
@@ -36,21 +46,7 @@ export class SnapInterfaceController extends BaseController {
|
|
|
36
46
|
state: { interfaces: {}, ...state },
|
|
37
47
|
});
|
|
38
48
|
this.messenger.subscribe('NotificationServicesController:notificationsListUpdated', this.#onNotificationsListUpdated.bind(this));
|
|
39
|
-
this
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Constructor helper for registering this controller's messaging system
|
|
43
|
-
* actions.
|
|
44
|
-
*/
|
|
45
|
-
#registerMessageHandlers() {
|
|
46
|
-
this.messenger.registerActionHandler(`${controllerName}:createInterface`, this.createInterface.bind(this));
|
|
47
|
-
this.messenger.registerActionHandler(`${controllerName}:getInterface`, this.getInterface.bind(this));
|
|
48
|
-
this.messenger.registerActionHandler(`${controllerName}:getInterfaceState`, this.getInterfaceState.bind(this));
|
|
49
|
-
this.messenger.registerActionHandler(`${controllerName}:updateInterface`, this.updateInterface.bind(this));
|
|
50
|
-
this.messenger.registerActionHandler(`${controllerName}:deleteInterface`, this.deleteInterface.bind(this));
|
|
51
|
-
this.messenger.registerActionHandler(`${controllerName}:updateInterfaceState`, this.updateInterfaceState.bind(this));
|
|
52
|
-
this.messenger.registerActionHandler(`${controllerName}:resolveInterface`, this.resolveInterface.bind(this));
|
|
53
|
-
this.messenger.registerActionHandler(`${controllerName}:setInterfaceDisplayed`, this.setInterfaceDisplayed.bind(this));
|
|
49
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
54
50
|
}
|
|
55
51
|
/**
|
|
56
52
|
* Create an interface in the controller state with the associated data.
|
|
@@ -287,7 +283,7 @@ export class SnapInterfaceController extends BaseController {
|
|
|
287
283
|
* @returns The snap.
|
|
288
284
|
*/
|
|
289
285
|
#getSnap(id) {
|
|
290
|
-
return this.messenger.call('SnapController:
|
|
286
|
+
return this.messenger.call('SnapController:getSnap', id);
|
|
291
287
|
}
|
|
292
288
|
#hasPermission(snapId, permission) {
|
|
293
289
|
return this.messenger.call('PermissionController:hasPermission', snapId, permission);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnapInterfaceController.mjs","sourceRoot":"","sources":["../../src/interface/SnapInterfaceController.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAU3D,OAAO,EAAE,WAAW,EAAE,4BAA4B;AAGlD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACpB,8BAA8B;AAO/B,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,wBAAwB;AAC1E,OAAO,EAAE,SAAS,EAAE,cAAc;AAClC,OAAO,EAAE,MAAM,EAAE,eAAe;AAEhC,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,wBAAwB,EACzB,oBAAgB;AAGjB,MAAM,mBAAmB,GAAG,QAAU,CAAC,CAAC,QAAQ;AAEhD,MAAM,cAAc,GAAG,y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;IACL,CAAC;IAED,2BAA2B,CAAC,iBAAiC;QAC3D,MAAM,8BAA8B,GAAG,iBAAiB,CAAC,MAAM,CAC7D,CAAC,YAAY,EAAE,EAAE;YACf,OAAO,CACL,YAAY,CAAC,IAAI,KAAK,MAAM;gBAC5B,WAAW,CAAE,YAAiC,CAAC,IAAI,EAAE,cAAc,CAAC,CACrE,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,MAAM,cAAc,GAAG,IAAI,GAAG,CAC5B,8BAA8B,CAAC,GAAG,CAChC,CAAC,YAAY,EAAE,EAAE,CAEZ,YAAiC;aAC/B,IACJ,CAAC,YAAY,CAAC,WAAW,CAC7B,CACF,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,EAAE,EAAE;gBAC/D,IACE,aAAa,CAAC,WAAW,KAAK,WAAW,CAAC,YAAY;oBACtD,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,EACvB,CAAC;oBACD,OAAO,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n AcceptRequest,\n HasApprovalRequest,\n} from '@metamask/approval-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HasPermission } from '@metamask/permission-controller';\nimport type {\n InterfaceState,\n SnapId,\n ComponentOrElement,\n InterfaceContext,\n FungibleAssetMetadata,\n} from '@metamask/snaps-sdk';\nimport { ContentType } from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type { InternalAccount } from '@metamask/snaps-utils';\nimport {\n getJsonSizeUnsafe,\n snapOwnsAccount,\n validateJsxElements,\n} from '@metamask/snaps-utils';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n Json,\n} from '@metamask/utils';\nimport { assert, hasProperty, parseCaipAccountId } from '@metamask/utils';\nimport { castDraft } from 'immer';\nimport { nanoid } from 'nanoid';\n\nimport {\n constructState,\n getJsxInterface,\n isMatchingChainId,\n validateInterfaceContext,\n} from './utils';\nimport type { GetSnap } from '../snaps';\n\nconst MAX_UI_CONTENT_SIZE = 10_000_000; // 10 mb\n\nconst controllerName = 'SnapInterfaceController';\n\nexport type CreateInterface = {\n type: `${typeof controllerName}:createInterface`;\n handler: SnapInterfaceController['createInterface'];\n};\n\nexport type GetInterface = {\n type: `${typeof controllerName}:getInterface`;\n handler: SnapInterfaceController['getInterface'];\n};\n\nexport type UpdateInterface = {\n type: `${typeof controllerName}:updateInterface`;\n handler: SnapInterfaceController['updateInterface'];\n};\n\nexport type DeleteInterface = {\n type: `${typeof controllerName}:deleteInterface`;\n handler: SnapInterfaceController['deleteInterface'];\n};\n\nexport type UpdateInterfaceState = {\n type: `${typeof controllerName}:updateInterfaceState`;\n handler: SnapInterfaceController['updateInterfaceState'];\n};\n\nexport type ResolveInterface = {\n type: `${typeof controllerName}:resolveInterface`;\n handler: SnapInterfaceController['resolveInterface'];\n};\n\nexport type SnapInterfaceControllerGetInterfaceStateAction = {\n type: `${typeof controllerName}:getInterfaceState`;\n handler: SnapInterfaceController['getInterfaceState'];\n};\n\nexport type SnapInterfaceControllerSetInterfaceDisplayedAction = {\n type: `${typeof controllerName}:setInterfaceDisplayed`;\n handler: SnapInterfaceController['setInterfaceDisplayed'];\n};\n\ntype AccountsControllerGetAccountByAddressAction = {\n type: `AccountsController:getAccountByAddress`;\n handler: (address: string) => InternalAccount | undefined;\n};\n\ntype AccountsControllerGetSelectedMultichainAccountAction = {\n type: `AccountsController:getSelectedMultichainAccount`;\n handler: () => InternalAccount;\n};\n\ntype AccountsControllerListMultichainAccountsAction = {\n type: `AccountsController:listMultichainAccounts`;\n handler: (chainId?: CaipChainId) => InternalAccount[];\n};\n\nexport type SnapInterfaceControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SnapInterfaceControllerState\n>;\n\ntype MultichainAssetsControllerGetStateAction = ControllerGetStateAction<\n 'MultichainAssetsController',\n {\n assetsMetadata: {\n [asset: CaipAssetType]: FungibleAssetMetadata;\n };\n accountsAssets: { [account: string]: CaipAssetType[] };\n }\n>;\n\ntype PhishingControllerTestOrigin = {\n type: 'PhishingController:testOrigin';\n handler: (origin: string) => { result: boolean; type: string };\n};\n\nexport type SnapInterfaceControllerAllowedActions =\n | PhishingControllerTestOrigin\n | HasApprovalRequest\n | AcceptRequest\n | GetSnap\n | MultichainAssetsControllerGetStateAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | AccountsControllerGetAccountByAddressAction\n | AccountsControllerListMultichainAccountsAction\n | HasPermission;\n\nexport type SnapInterfaceControllerActions =\n | CreateInterface\n | GetInterface\n | UpdateInterface\n | DeleteInterface\n | UpdateInterfaceState\n | ResolveInterface\n | SnapInterfaceControllerGetInterfaceStateAction\n | SnapInterfaceControllerSetInterfaceDisplayedAction\n | SnapInterfaceControllerGetStateAction;\n\nexport type SnapInterfaceControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SnapInterfaceControllerState\n >;\n\ntype OtherNotification = { type: string; [key: string]: unknown };\n\nexport type ExpandedView = {\n title: string;\n interfaceId: string;\n footerLink?: { href: string; text: string };\n};\n\ntype NormalSnapNotificationData = { message: string; origin: string };\n\ntype ExpandedSnapNotificationData = {\n message: string;\n origin: string;\n detailedView: ExpandedView;\n};\n\ntype SnapNotification = {\n type: 'snap';\n data: NormalSnapNotificationData | ExpandedSnapNotificationData;\n readDate: string | null;\n};\n\ntype Notification = OtherNotification | SnapNotification;\n\ntype NotificationListUpdatedEvent = {\n type: 'NotificationServicesController:notificationsListUpdated';\n payload: [Notification[]];\n};\n\nexport type SnapInterfaceControllerEvents =\n | SnapInterfaceControllerStateChangeEvent\n | NotificationListUpdatedEvent;\n\nexport type SnapInterfaceControllerMessenger = Messenger<\n typeof controllerName,\n SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions,\n SnapInterfaceControllerEvents\n>;\n\nexport type StoredInterface = {\n snapId: SnapId;\n content: JSXElement;\n state: InterfaceState;\n context: InterfaceContext | null;\n contentType: ContentType | null;\n\n /**\n * Whether the interface has been displayed in the UI at least once.\n */\n displayed: boolean;\n};\n\nexport type SnapInterfaceControllerState = {\n interfaces: Record<string, StoredInterface>;\n};\n\nexport type SnapInterfaceControllerArgs = {\n messenger: SnapInterfaceControllerMessenger;\n state?: SnapInterfaceControllerState;\n};\n\n/**\n * Use this controller to manage snaps UI interfaces using RPC method hooks.\n */\nexport class SnapInterfaceController extends BaseController<\n typeof controllerName,\n SnapInterfaceControllerState,\n SnapInterfaceControllerMessenger\n> {\n constructor({ messenger, state }: SnapInterfaceControllerArgs) {\n super({\n messenger,\n metadata: {\n interfaces: {\n includeInStateLogs: true,\n persist: (interfaces: Record<string, StoredInterface>) => {\n return Object.entries(interfaces).reduce<\n Record<string, StoredInterface>\n >((persistedInterfaces, [id, snapInterface]) => {\n switch (snapInterface.contentType) {\n case ContentType.Notification:\n persistedInterfaces[id] = snapInterface;\n return persistedInterfaces;\n default:\n return persistedInterfaces;\n }\n }, {});\n },\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n },\n name: controllerName,\n state: { interfaces: {}, ...state },\n });\n\n this.messenger.subscribe(\n 'NotificationServicesController:notificationsListUpdated',\n this.#onNotificationsListUpdated.bind(this),\n );\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers() {\n this.messenger.registerActionHandler(\n `${controllerName}:createInterface`,\n this.createInterface.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:getInterface`,\n this.getInterface.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:getInterfaceState`,\n this.getInterfaceState.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:updateInterface`,\n this.updateInterface.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:deleteInterface`,\n this.deleteInterface.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:updateInterfaceState`,\n this.updateInterfaceState.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:resolveInterface`,\n this.resolveInterface.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:setInterfaceDisplayed`,\n this.setInterfaceDisplayed.bind(this),\n );\n }\n\n /**\n * Create an interface in the controller state with the associated data.\n *\n * @param snapId - The snap id that created the interface.\n * @param content - The interface content.\n * @param context - An optional interface context object.\n * @param contentType - The type of content.\n * @returns The newly interface id.\n */\n createInterface(\n snapId: SnapId,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) {\n const element = getJsxInterface(content);\n this.#validateContent(snapId, element);\n validateInterfaceContext(context);\n\n const id = nanoid();\n const componentState = constructState({}, element, {\n getAssetsState: this.#getAssetsState.bind(this),\n getAccountByAddress: this.#getAccountByAddress.bind(this),\n getSelectedAccount: this.#getSelectedAccount.bind(this),\n listAccounts: this.#listAccounts.bind(this),\n snapOwnsAccount: (account: InternalAccount) =>\n snapOwnsAccount(snapId, account),\n });\n\n this.update((draftState) => {\n // @ts-expect-error - TS2589: Type instantiation is excessively deep and\n // possibly infinite.\n draftState.interfaces[id] = {\n snapId,\n content: castDraft(element),\n state: componentState,\n context: context ?? null,\n contentType: contentType ?? null,\n displayed: false,\n };\n });\n\n return id;\n }\n\n /**\n * Get the data of a given interface id.\n *\n * @param snapId - The snap id requesting the interface data.\n * @param id - The interface id.\n * @returns The interface state.\n */\n getInterface(snapId: SnapId, id: string) {\n this.#validateArgs(snapId, id);\n\n return this.state.interfaces[id];\n }\n\n /**\n * Get the state of a given interface ID, if the interface has been displayed\n * at least once.\n *\n * @param snapId - The snap ID requesting the interface state.\n * @param id - The interface ID.\n * @returns The interface state.\n */\n getInterfaceState(snapId: SnapId, id: string) {\n const storedInterface = this.getInterface(snapId, id);\n if (!storedInterface.displayed) {\n throw new Error(\n `Interface with ID '${id}' has not been displayed yet. Interface state is not available until the interface has been displayed at least once.`,\n );\n }\n\n return storedInterface.state;\n }\n\n /**\n * Update the interface with the given content.\n *\n * @param snapId - The snap id requesting the update.\n * @param id - The interface id.\n * @param content - The new content.\n * @param context - An optional interface context object.\n */\n updateInterface(\n snapId: SnapId,\n id: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) {\n this.#validateArgs(snapId, id);\n const element = getJsxInterface(content);\n this.#validateContent(snapId, element);\n validateInterfaceContext(context);\n\n const oldState = this.state.interfaces[id].state;\n const newState = constructState(oldState, element, {\n getAssetsState: this.#getAssetsState.bind(this),\n getAccountByAddress: this.#getAccountByAddress.bind(this),\n getSelectedAccount: this.#getSelectedAccount.bind(this),\n listAccounts: this.#listAccounts.bind(this),\n snapOwnsAccount: (account: InternalAccount) =>\n snapOwnsAccount(snapId, account),\n });\n\n this.update((draftState) => {\n draftState.interfaces[id].state = newState;\n draftState.interfaces[id].content = castDraft(element);\n if (context) {\n draftState.interfaces[id].context = context;\n }\n });\n }\n\n /**\n * Delete an interface from state.\n *\n * @param id - The interface id.\n */\n deleteInterface(id: string) {\n this.update((draftState) => {\n delete draftState.interfaces[id];\n });\n }\n\n /**\n * Update the interface state.\n *\n * @param id - The interface id.\n * @param state - The new state.\n */\n updateInterfaceState(id: string, state: InterfaceState) {\n this.update((draftState) => {\n draftState.interfaces[id].state = state;\n });\n }\n\n /**\n * Resolve the promise of a given interface approval request.\n * The approval needs to have the same ID as the interface.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async resolveInterface(snapId: SnapId, id: string, value: Json) {\n this.#validateArgs(snapId, id);\n this.#validateApproval(id);\n\n await this.#acceptApprovalRequest(id, value);\n\n this.deleteInterface(id);\n }\n\n /**\n * Set the interface as displayed.\n *\n * @param snapId - The snap ID requesting the update.\n * @param id - The interface ID.\n */\n setInterfaceDisplayed(snapId: SnapId, id: string) {\n this.#validateArgs(snapId, id);\n\n if (this.state.interfaces[id].displayed) {\n return;\n }\n\n this.update((draftState) => {\n draftState.interfaces[id].displayed = true;\n });\n }\n\n /**\n * Utility function to validate the args passed to the other methods.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n */\n #validateArgs(snapId: SnapId, id: string) {\n const existingInterface = this.state.interfaces[id];\n\n assert(\n existingInterface !== undefined,\n `Interface with id '${id}' not found.`,\n );\n assert(\n existingInterface.snapId === snapId,\n `Interface not created by ${snapId}.`,\n );\n }\n\n /**\n * Utility function to validate that the approval request exists.\n *\n * @param id - The interface id.\n */\n #validateApproval(id: string) {\n assert(\n this.#hasApprovalRequest(id),\n `Approval request with id '${id}' not found.`,\n );\n }\n\n /**\n * Check an origin against the phishing list.\n *\n * @param origin - The origin to check.\n * @returns True if the origin is on the phishing list, otherwise false.\n */\n #checkPhishingList(origin: string) {\n return this.messenger.call('PhishingController:testOrigin', origin).result;\n }\n\n /**\n * Check if an approval request exists for a given interface by looking up\n * if the ApprovalController has a request with the given interface ID.\n *\n * @param id - The interface id.\n * @returns True if an approval request exists, otherwise false.\n */\n #hasApprovalRequest(id: string) {\n return this.messenger.call('ApprovalController:hasRequest', {\n id,\n });\n }\n\n /**\n * Accept an approval request for a given interface.\n *\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async #acceptApprovalRequest(id: string, value: Json) {\n await this.messenger.call('ApprovalController:acceptRequest', id, value);\n }\n\n /**\n * Get the selected account in the client.\n *\n * @returns The selected account.\n */\n #getSelectedAccount() {\n return this.messenger.call(\n 'AccountsController:getSelectedMultichainAccount',\n );\n }\n\n /**\n * Get a list of accounts for the given chain IDs.\n *\n * @param chainIds - The chain IDs to get the accounts for.\n * @returns The list of accounts.\n */\n #listAccounts(chainIds?: CaipChainId[]) {\n const accounts = this.messenger.call(\n 'AccountsController:listMultichainAccounts',\n );\n\n if (!chainIds || chainIds.length === 0) {\n return accounts;\n }\n\n return accounts.filter((account) =>\n account.scopes.some((scope) => isMatchingChainId(scope, chainIds)),\n );\n }\n\n /**\n * Get an account by its address.\n *\n * @param address - The account address.\n * @returns The account or undefined if not found.\n */\n #getAccountByAddress(address: CaipAccountId) {\n const { address: parsedAddress } = parseCaipAccountId(address);\n\n return this.messenger.call(\n 'AccountsController:getAccountByAddress',\n parsedAddress,\n );\n }\n\n /**\n * Get the MultichainAssetsController state.\n *\n * @returns The MultichainAssetsController state.\n */\n #getAssetsState() {\n return this.messenger.call('MultichainAssetsController:getState');\n }\n\n /**\n * Get a snap by its id.\n *\n * @param id - The snap id.\n * @returns The snap.\n */\n #getSnap(id: string) {\n return this.messenger.call('SnapController:get', id);\n }\n\n #hasPermission(snapId: SnapId, permission: string) {\n return this.messenger.call(\n 'PermissionController:hasPermission',\n snapId,\n permission,\n );\n }\n\n /**\n * Utility function to validate the components of an interface.\n * Throws if something is invalid.\n *\n * @param snapId - The Snap ID.\n * @param element - The JSX element to verify.\n */\n #validateContent(snapId: SnapId, element: JSXElement) {\n // We assume the validity of this JSON to be validated by the caller.\n // E.g., in the RPC method implementation.\n const size = getJsonSizeUnsafe(element);\n assert(\n size <= MAX_UI_CONTENT_SIZE,\n `A Snap UI may not be larger than ${MAX_UI_CONTENT_SIZE / 1000000} MB.`,\n );\n\n validateJsxElements(element, {\n isOnPhishingList: this.#checkPhishingList.bind(this),\n getSnap: this.#getSnap.bind(this),\n getAccountByAddress: this.#getAccountByAddress.bind(this),\n hasPermission: this.#hasPermission.bind(this, snapId),\n });\n }\n\n #onNotificationsListUpdated(notificationsList: Notification[]) {\n const snapNotificationsWithInterface = notificationsList.filter(\n (notification) => {\n return (\n notification.type === 'snap' &&\n hasProperty((notification as SnapNotification).data, 'detailedView')\n );\n },\n );\n\n const interfaceIdSet = new Set(\n snapNotificationsWithInterface.map(\n (notification) =>\n (\n (notification as SnapNotification)\n .data as ExpandedSnapNotificationData\n ).detailedView.interfaceId,\n ),\n );\n\n this.update((state) => {\n Object.entries(state.interfaces).forEach(([id, snapInterface]) => {\n if (\n snapInterface.contentType === ContentType.Notification &&\n !interfaceIdSet.has(id)\n ) {\n delete state.interfaces[id];\n }\n });\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"SnapInterfaceController.mjs","sourceRoot":"","sources":["../../src/interface/SnapInterfaceController.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAU3D,OAAO,EAAE,WAAW,EAAE,4BAA4B;AAGlD,OAAO,EACL,iBAAiB,EACjB,eAAe,EACf,mBAAmB,EACpB,8BAA8B;AAO/B,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,kBAAkB,EAAE,wBAAwB;AAC1E,OAAO,EAAE,SAAS,EAAE,cAAc;AAClC,OAAO,EAAE,MAAM,EAAE,eAAe;AAGhC,OAAO,EACL,cAAc,EACd,eAAe,EACf,iBAAiB,EACjB,wBAAwB,EACzB,oBAAgB;AAGjB,MAAM,mBAAmB,GAAG,QAAU,CAAC,CAAC,QAAQ;AAEhD,MAAM,cAAc,GAAG,yBAAyB,CAAC;AAEjD,MAAM,yBAAyB,GAAG;IAChC,iBAAiB;IACjB,cAAc;IACd,mBAAmB;IACnB,iBAAiB;IACjB,iBAAiB;IACjB,sBAAsB;IACtB,kBAAkB;IAClB,uBAAuB;CACf,CAAC;AAwHX;;GAEG;AACH,MAAM,OAAO,uBAAwB,SAAQ,cAI5C;IACC,YAAY,EAAE,SAAS,EAAE,KAAK,EAA+B;QAC3D,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE;gBACR,UAAU,EAAE;oBACV,kBAAkB,EAAE,IAAI;oBACxB,OAAO,EAAE,CAAC,UAA2C,EAAE,EAAE;wBACvD,OAAO,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC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AO,CACL,YAAY,CAAC,IAAI,KAAK,MAAM;gBAC5B,WAAW,CAAE,YAAiC,CAAC,IAAI,EAAE,cAAc,CAAC,CACrE,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,MAAM,cAAc,GAAG,IAAI,GAAG,CAC5B,8BAA8B,CAAC,GAAG,CAChC,CAAC,YAAY,EAAE,EAAE,CAEZ,YAAiC;aAC/B,IACJ,CAAC,YAAY,CAAC,WAAW,CAC7B,CACF,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,aAAa,CAAC,EAAE,EAAE;gBAC/D,IACE,aAAa,CAAC,WAAW,KAAK,WAAW,CAAC,YAAY;oBACtD,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC,EACvB,CAAC;oBACD,OAAO,KAAK,CAAC,UAAU,CAAC,EAAE,CAAC,CAAC;gBAC9B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import type {\n ApprovalControllerAcceptRequestAction,\n ApprovalControllerHasRequestAction,\n} from '@metamask/approval-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HasPermission } from '@metamask/permission-controller';\nimport type {\n InterfaceState,\n SnapId,\n ComponentOrElement,\n InterfaceContext,\n FungibleAssetMetadata,\n} from '@metamask/snaps-sdk';\nimport { ContentType } from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type { InternalAccount } from '@metamask/snaps-utils';\nimport {\n getJsonSizeUnsafe,\n snapOwnsAccount,\n validateJsxElements,\n} from '@metamask/snaps-utils';\nimport type {\n CaipAccountId,\n CaipAssetType,\n CaipChainId,\n Json,\n} from '@metamask/utils';\nimport { assert, hasProperty, parseCaipAccountId } from '@metamask/utils';\nimport { castDraft } from 'immer';\nimport { nanoid } from 'nanoid';\n\nimport type { SnapInterfaceControllerMethodActions } from './SnapInterfaceController-method-action-types';\nimport {\n constructState,\n getJsxInterface,\n isMatchingChainId,\n validateInterfaceContext,\n} from './utils';\nimport type { SnapControllerGetSnapAction } from '../snaps';\n\nconst MAX_UI_CONTENT_SIZE = 10_000_000; // 10 mb\n\nconst controllerName = 'SnapInterfaceController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'createInterface',\n 'getInterface',\n 'getInterfaceState',\n 'updateInterface',\n 'deleteInterface',\n 'updateInterfaceState',\n 'resolveInterface',\n 'setInterfaceDisplayed',\n] as const;\n\ntype AccountsControllerGetAccountByAddressAction = {\n type: `AccountsController:getAccountByAddress`;\n handler: (address: string) => InternalAccount | undefined;\n};\n\ntype AccountsControllerGetSelectedMultichainAccountAction = {\n type: `AccountsController:getSelectedMultichainAccount`;\n handler: () => InternalAccount;\n};\n\ntype AccountsControllerListMultichainAccountsAction = {\n type: `AccountsController:listMultichainAccounts`;\n handler: (chainId?: CaipChainId) => InternalAccount[];\n};\n\nexport type SnapInterfaceControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n SnapInterfaceControllerState\n>;\n\ntype MultichainAssetsControllerGetStateAction = ControllerGetStateAction<\n 'MultichainAssetsController',\n {\n assetsMetadata: {\n [asset: CaipAssetType]: FungibleAssetMetadata;\n };\n accountsAssets: { [account: string]: CaipAssetType[] };\n }\n>;\n\ntype PhishingControllerTestOrigin = {\n type: 'PhishingController:testOrigin';\n handler: (origin: string) => { result: boolean; type: string };\n};\n\ntype AllowedActions =\n | PhishingControllerTestOrigin\n | ApprovalControllerHasRequestAction\n | ApprovalControllerAcceptRequestAction\n | SnapControllerGetSnapAction\n | MultichainAssetsControllerGetStateAction\n | AccountsControllerGetSelectedMultichainAccountAction\n | AccountsControllerGetAccountByAddressAction\n | AccountsControllerListMultichainAccountsAction\n | HasPermission;\n\nexport type SnapInterfaceControllerActions =\n | SnapInterfaceControllerGetStateAction\n | SnapInterfaceControllerMethodActions;\n\nexport type SnapInterfaceControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n SnapInterfaceControllerState\n >;\n\ntype OtherNotification = { type: string; [key: string]: unknown };\n\ntype ExpandedView = {\n title: string;\n interfaceId: string;\n footerLink?: { href: string; text: string };\n};\n\ntype NormalSnapNotificationData = { message: string; origin: string };\n\ntype ExpandedSnapNotificationData = {\n message: string;\n origin: string;\n detailedView: ExpandedView;\n};\n\ntype SnapNotification = {\n type: 'snap';\n data: NormalSnapNotificationData | ExpandedSnapNotificationData;\n readDate: string | null;\n};\n\ntype Notification = OtherNotification | SnapNotification;\n\ntype NotificationListUpdatedEvent = {\n type: 'NotificationServicesController:notificationsListUpdated';\n payload: [Notification[]];\n};\n\ntype AllowedEvents = NotificationListUpdatedEvent;\n\nexport type SnapInterfaceControllerEvents =\n SnapInterfaceControllerStateChangeEvent;\n\nexport type SnapInterfaceControllerMessenger = Messenger<\n typeof controllerName,\n SnapInterfaceControllerActions | AllowedActions,\n SnapInterfaceControllerEvents | AllowedEvents\n>;\n\nexport type StoredInterface = {\n snapId: SnapId;\n content: JSXElement;\n state: InterfaceState;\n context: InterfaceContext | null;\n contentType: ContentType | null;\n\n /**\n * Whether the interface has been displayed in the UI at least once.\n */\n displayed: boolean;\n};\n\nexport type SnapInterfaceControllerState = {\n interfaces: Record<string, StoredInterface>;\n};\n\nexport type SnapInterfaceControllerArgs = {\n messenger: SnapInterfaceControllerMessenger;\n state?: SnapInterfaceControllerState;\n};\n\n/**\n * Use this controller to manage snaps UI interfaces using RPC method hooks.\n */\nexport class SnapInterfaceController extends BaseController<\n typeof controllerName,\n SnapInterfaceControllerState,\n SnapInterfaceControllerMessenger\n> {\n constructor({ messenger, state }: SnapInterfaceControllerArgs) {\n super({\n messenger,\n metadata: {\n interfaces: {\n includeInStateLogs: true,\n persist: (interfaces: Record<string, StoredInterface>) => {\n return Object.entries(interfaces).reduce<\n Record<string, StoredInterface>\n >((persistedInterfaces, [id, snapInterface]) => {\n switch (snapInterface.contentType) {\n case ContentType.Notification:\n persistedInterfaces[id] = snapInterface;\n return persistedInterfaces;\n default:\n return persistedInterfaces;\n }\n }, {});\n },\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n },\n name: controllerName,\n state: { interfaces: {}, ...state },\n });\n\n this.messenger.subscribe(\n 'NotificationServicesController:notificationsListUpdated',\n this.#onNotificationsListUpdated.bind(this),\n );\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Create an interface in the controller state with the associated data.\n *\n * @param snapId - The snap id that created the interface.\n * @param content - The interface content.\n * @param context - An optional interface context object.\n * @param contentType - The type of content.\n * @returns The newly interface id.\n */\n createInterface(\n snapId: SnapId,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) {\n const element = getJsxInterface(content);\n this.#validateContent(snapId, element);\n validateInterfaceContext(context);\n\n const id = nanoid();\n const componentState = constructState({}, element, {\n getAssetsState: this.#getAssetsState.bind(this),\n getAccountByAddress: this.#getAccountByAddress.bind(this),\n getSelectedAccount: this.#getSelectedAccount.bind(this),\n listAccounts: this.#listAccounts.bind(this),\n snapOwnsAccount: (account: InternalAccount) =>\n snapOwnsAccount(snapId, account),\n });\n\n this.update((draftState) => {\n // @ts-expect-error - TS2589: Type instantiation is excessively deep and\n // possibly infinite.\n draftState.interfaces[id] = {\n snapId,\n content: castDraft(element),\n state: componentState,\n context: context ?? null,\n contentType: contentType ?? null,\n displayed: false,\n };\n });\n\n return id;\n }\n\n /**\n * Get the data of a given interface id.\n *\n * @param snapId - The snap id requesting the interface data.\n * @param id - The interface id.\n * @returns The interface state.\n */\n getInterface(snapId: SnapId, id: string) {\n this.#validateArgs(snapId, id);\n\n return this.state.interfaces[id];\n }\n\n /**\n * Get the state of a given interface ID, if the interface has been displayed\n * at least once.\n *\n * @param snapId - The snap ID requesting the interface state.\n * @param id - The interface ID.\n * @returns The interface state.\n */\n getInterfaceState(snapId: SnapId, id: string) {\n const storedInterface = this.getInterface(snapId, id);\n if (!storedInterface.displayed) {\n throw new Error(\n `Interface with ID '${id}' has not been displayed yet. Interface state is not available until the interface has been displayed at least once.`,\n );\n }\n\n return storedInterface.state;\n }\n\n /**\n * Update the interface with the given content.\n *\n * @param snapId - The snap id requesting the update.\n * @param id - The interface id.\n * @param content - The new content.\n * @param context - An optional interface context object.\n */\n updateInterface(\n snapId: SnapId,\n id: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) {\n this.#validateArgs(snapId, id);\n const element = getJsxInterface(content);\n this.#validateContent(snapId, element);\n validateInterfaceContext(context);\n\n const oldState = this.state.interfaces[id].state;\n const newState = constructState(oldState, element, {\n getAssetsState: this.#getAssetsState.bind(this),\n getAccountByAddress: this.#getAccountByAddress.bind(this),\n getSelectedAccount: this.#getSelectedAccount.bind(this),\n listAccounts: this.#listAccounts.bind(this),\n snapOwnsAccount: (account: InternalAccount) =>\n snapOwnsAccount(snapId, account),\n });\n\n this.update((draftState) => {\n draftState.interfaces[id].state = newState;\n draftState.interfaces[id].content = castDraft(element);\n if (context) {\n draftState.interfaces[id].context = context;\n }\n });\n }\n\n /**\n * Delete an interface from state.\n *\n * @param id - The interface id.\n */\n deleteInterface(id: string) {\n this.update((draftState) => {\n delete draftState.interfaces[id];\n });\n }\n\n /**\n * Update the interface state.\n *\n * @param id - The interface id.\n * @param state - The new state.\n */\n updateInterfaceState(id: string, state: InterfaceState) {\n this.update((draftState) => {\n draftState.interfaces[id].state = state;\n });\n }\n\n /**\n * Resolve the promise of a given interface approval request.\n * The approval needs to have the same ID as the interface.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async resolveInterface(snapId: SnapId, id: string, value: Json) {\n this.#validateArgs(snapId, id);\n this.#validateApproval(id);\n\n await this.#acceptApprovalRequest(id, value);\n\n this.deleteInterface(id);\n }\n\n /**\n * Set the interface as displayed.\n *\n * @param snapId - The snap ID requesting the update.\n * @param id - The interface ID.\n */\n setInterfaceDisplayed(snapId: SnapId, id: string) {\n this.#validateArgs(snapId, id);\n\n if (this.state.interfaces[id].displayed) {\n return;\n }\n\n this.update((draftState) => {\n draftState.interfaces[id].displayed = true;\n });\n }\n\n /**\n * Utility function to validate the args passed to the other methods.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n */\n #validateArgs(snapId: SnapId, id: string) {\n const existingInterface = this.state.interfaces[id];\n\n assert(\n existingInterface !== undefined,\n `Interface with id '${id}' not found.`,\n );\n assert(\n existingInterface.snapId === snapId,\n `Interface not created by ${snapId}.`,\n );\n }\n\n /**\n * Utility function to validate that the approval request exists.\n *\n * @param id - The interface id.\n */\n #validateApproval(id: string) {\n assert(\n this.#hasApprovalRequest(id),\n `Approval request with id '${id}' not found.`,\n );\n }\n\n /**\n * Check an origin against the phishing list.\n *\n * @param origin - The origin to check.\n * @returns True if the origin is on the phishing list, otherwise false.\n */\n #checkPhishingList(origin: string) {\n return this.messenger.call('PhishingController:testOrigin', origin).result;\n }\n\n /**\n * Check if an approval request exists for a given interface by looking up\n * if the ApprovalController has a request with the given interface ID.\n *\n * @param id - The interface id.\n * @returns True if an approval request exists, otherwise false.\n */\n #hasApprovalRequest(id: string) {\n return this.messenger.call('ApprovalController:hasRequest', {\n id,\n });\n }\n\n /**\n * Accept an approval request for a given interface.\n *\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async #acceptApprovalRequest(id: string, value: Json) {\n await this.messenger.call('ApprovalController:acceptRequest', id, value);\n }\n\n /**\n * Get the selected account in the client.\n *\n * @returns The selected account.\n */\n #getSelectedAccount() {\n return this.messenger.call(\n 'AccountsController:getSelectedMultichainAccount',\n );\n }\n\n /**\n * Get a list of accounts for the given chain IDs.\n *\n * @param chainIds - The chain IDs to get the accounts for.\n * @returns The list of accounts.\n */\n #listAccounts(chainIds?: CaipChainId[]) {\n const accounts = this.messenger.call(\n 'AccountsController:listMultichainAccounts',\n );\n\n if (!chainIds || chainIds.length === 0) {\n return accounts;\n }\n\n return accounts.filter((account) =>\n account.scopes.some((scope) => isMatchingChainId(scope, chainIds)),\n );\n }\n\n /**\n * Get an account by its address.\n *\n * @param address - The account address.\n * @returns The account or undefined if not found.\n */\n #getAccountByAddress(address: CaipAccountId) {\n const { address: parsedAddress } = parseCaipAccountId(address);\n\n return this.messenger.call(\n 'AccountsController:getAccountByAddress',\n parsedAddress,\n );\n }\n\n /**\n * Get the MultichainAssetsController state.\n *\n * @returns The MultichainAssetsController state.\n */\n #getAssetsState() {\n return this.messenger.call('MultichainAssetsController:getState');\n }\n\n /**\n * Get a snap by its id.\n *\n * @param id - The snap id.\n * @returns The snap.\n */\n #getSnap(id: string) {\n return this.messenger.call('SnapController:getSnap', id);\n }\n\n #hasPermission(snapId: SnapId, permission: string) {\n return this.messenger.call(\n 'PermissionController:hasPermission',\n snapId,\n permission,\n );\n }\n\n /**\n * Utility function to validate the components of an interface.\n * Throws if something is invalid.\n *\n * @param snapId - The Snap ID.\n * @param element - The JSX element to verify.\n */\n #validateContent(snapId: SnapId, element: JSXElement) {\n // We assume the validity of this JSON to be validated by the caller.\n // E.g., in the RPC method implementation.\n const size = getJsonSizeUnsafe(element);\n assert(\n size <= MAX_UI_CONTENT_SIZE,\n `A Snap UI may not be larger than ${MAX_UI_CONTENT_SIZE / 1000000} MB.`,\n );\n\n validateJsxElements(element, {\n isOnPhishingList: this.#checkPhishingList.bind(this),\n getSnap: this.#getSnap.bind(this),\n getAccountByAddress: this.#getAccountByAddress.bind(this),\n hasPermission: this.#hasPermission.bind(this, snapId),\n });\n }\n\n #onNotificationsListUpdated(notificationsList: Notification[]) {\n const snapNotificationsWithInterface = notificationsList.filter(\n (notification) => {\n return (\n notification.type === 'snap' &&\n hasProperty((notification as SnapNotification).data, 'detailedView')\n );\n },\n );\n\n const interfaceIdSet = new Set(\n snapNotificationsWithInterface.map(\n (notification) =>\n (\n (notification as SnapNotification)\n .data as ExpandedSnapNotificationData\n ).detailedView.interfaceId,\n ),\n );\n\n this.update((state) => {\n Object.entries(state.interfaces).forEach(([id, snapInterface]) => {\n if (\n snapInterface.contentType === ContentType.Notification &&\n !interfaceIdSet.has(id)\n ) {\n delete state.interfaces[id];\n }\n });\n });\n }\n}\n"]}
|
package/dist/interface/index.cjs
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
3
|
+
exports.SnapInterfaceController = void 0;
|
|
4
|
+
var SnapInterfaceController_1 = require("./SnapInterfaceController.cjs");
|
|
5
|
+
Object.defineProperty(exports, "SnapInterfaceController", { enumerable: true, get: function () { return SnapInterfaceController_1.SnapInterfaceController; } });
|
|
18
6
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":";;;AAUA,yEAAoE;AAA3D,kIAAA,uBAAuB,OAAA","sourcesContent":["export type {\n SnapInterfaceControllerActions,\n SnapInterfaceControllerArgs,\n SnapInterfaceControllerEvents,\n SnapInterfaceControllerGetStateAction,\n SnapInterfaceControllerMessenger,\n SnapInterfaceControllerState,\n SnapInterfaceControllerStateChangeEvent,\n StoredInterface,\n} from './SnapInterfaceController';\nexport { SnapInterfaceController } from './SnapInterfaceController';\nexport type {\n SnapInterfaceControllerCreateInterfaceAction,\n SnapInterfaceControllerDeleteInterfaceAction,\n SnapInterfaceControllerGetInterfaceAction,\n SnapInterfaceControllerGetInterfaceStateAction,\n SnapInterfaceControllerMethodActions,\n SnapInterfaceControllerResolveInterfaceAction,\n SnapInterfaceControllerSetInterfaceDisplayedAction,\n SnapInterfaceControllerUpdateInterfaceAction,\n SnapInterfaceControllerUpdateInterfaceStateAction,\n} from './SnapInterfaceController-method-action-types';\n"]}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type { SnapInterfaceControllerActions, SnapInterfaceControllerArgs, SnapInterfaceControllerEvents, SnapInterfaceControllerGetStateAction, SnapInterfaceControllerMessenger, SnapInterfaceControllerState, SnapInterfaceControllerStateChangeEvent, StoredInterface, } from "./SnapInterfaceController.cjs";
|
|
2
|
+
export { SnapInterfaceController } from "./SnapInterfaceController.cjs";
|
|
3
|
+
export type { SnapInterfaceControllerCreateInterfaceAction, SnapInterfaceControllerDeleteInterfaceAction, SnapInterfaceControllerGetInterfaceAction, SnapInterfaceControllerGetInterfaceStateAction, SnapInterfaceControllerMethodActions, SnapInterfaceControllerResolveInterfaceAction, SnapInterfaceControllerSetInterfaceDisplayedAction, SnapInterfaceControllerUpdateInterfaceAction, SnapInterfaceControllerUpdateInterfaceStateAction, } from "./SnapInterfaceController-method-action-types.cjs";
|
|
2
4
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,8BAA8B,EAC9B,2BAA2B,EAC3B,6BAA6B,EAC7B,qCAAqC,EACrC,gCAAgC,EAChC,4BAA4B,EAC5B,uCAAuC,EACvC,eAAe,GAChB,sCAAkC;AACnC,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,YAAY,EACV,4CAA4C,EAC5C,4CAA4C,EAC5C,yCAAyC,EACzC,8CAA8C,EAC9C,oCAAoC,EACpC,6CAA6C,EAC7C,kDAAkD,EAClD,4CAA4C,EAC5C,iDAAiD,GAClD,0DAAsD"}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type { SnapInterfaceControllerActions, SnapInterfaceControllerArgs, SnapInterfaceControllerEvents, SnapInterfaceControllerGetStateAction, SnapInterfaceControllerMessenger, SnapInterfaceControllerState, SnapInterfaceControllerStateChangeEvent, StoredInterface, } from "./SnapInterfaceController.mjs";
|
|
2
|
+
export { SnapInterfaceController } from "./SnapInterfaceController.mjs";
|
|
3
|
+
export type { SnapInterfaceControllerCreateInterfaceAction, SnapInterfaceControllerDeleteInterfaceAction, SnapInterfaceControllerGetInterfaceAction, SnapInterfaceControllerGetInterfaceStateAction, SnapInterfaceControllerMethodActions, SnapInterfaceControllerResolveInterfaceAction, SnapInterfaceControllerSetInterfaceDisplayedAction, SnapInterfaceControllerUpdateInterfaceAction, SnapInterfaceControllerUpdateInterfaceStateAction, } from "./SnapInterfaceController-method-action-types.mjs";
|
|
2
4
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,8BAA8B,EAC9B,2BAA2B,EAC3B,6BAA6B,EAC7B,qCAAqC,EACrC,gCAAgC,EAChC,4BAA4B,EAC5B,uCAAuC,EACvC,eAAe,GAChB,sCAAkC;AACnC,OAAO,EAAE,uBAAuB,EAAE,sCAAkC;AACpE,YAAY,EACV,4CAA4C,EAC5C,4CAA4C,EAC5C,yCAAyC,EACzC,8CAA8C,EAC9C,oCAAoC,EACpC,6CAA6C,EAC7C,kDAAkD,EAClD,4CAA4C,EAC5C,iDAAiD,GAClD,0DAAsD"}
|
package/dist/interface/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export
|
|
1
|
+
export { SnapInterfaceController } from "./SnapInterfaceController.mjs";
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/interface/index.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,uBAAuB,EAAE,sCAAkC","sourcesContent":["export type {\n SnapInterfaceControllerActions,\n SnapInterfaceControllerArgs,\n SnapInterfaceControllerEvents,\n SnapInterfaceControllerGetStateAction,\n SnapInterfaceControllerMessenger,\n SnapInterfaceControllerState,\n SnapInterfaceControllerStateChangeEvent,\n StoredInterface,\n} from './SnapInterfaceController';\nexport { SnapInterfaceController } from './SnapInterfaceController';\nexport type {\n SnapInterfaceControllerCreateInterfaceAction,\n SnapInterfaceControllerDeleteInterfaceAction,\n SnapInterfaceControllerGetInterfaceAction,\n SnapInterfaceControllerGetInterfaceStateAction,\n SnapInterfaceControllerMethodActions,\n SnapInterfaceControllerResolveInterfaceAction,\n SnapInterfaceControllerSetInterfaceDisplayedAction,\n SnapInterfaceControllerUpdateInterfaceAction,\n SnapInterfaceControllerUpdateInterfaceStateAction,\n} from './SnapInterfaceController-method-action-types';\n"]}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
4
|
+
* Do not edit manually.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
//# sourceMappingURL=MultichainRoutingService-method-action-types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainRoutingService-method-action-types.cjs","sourceRoot":"","sources":["../../src/multichain/MultichainRoutingService-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { MultichainRoutingService } from './MultichainRoutingService';\n\n/**\n * Handle an incoming JSON-RPC request tied to a specific scope by routing\n * to either a protocol Snap or an account Snap.\n *\n * Note: Addresses are considered case-sensitive by the MultichainRoutingService as\n * not all non-EVM chains are case-insensitive.\n *\n * @param options - An options bag.\n * @param options.connectedAddresses - Addresses currently connected to the\n * origin for the requested scope.\n * @param options.origin - The origin of the RPC request.\n * @param options.request - The JSON-RPC request.\n * @param options.scope - The CAIP-2 scope for the request.\n * @returns The response from the chosen Snap.\n * @throws If no handler was found.\n */\nexport type MultichainRoutingServiceHandleRequestAction = {\n type: `MultichainRoutingService:handleRequest`;\n handler: MultichainRoutingService['handleRequest'];\n};\n\n/**\n * Get a list of supported methods for a given scope.\n * This combines both protocol and account Snaps supported methods.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of supported methods.\n */\nexport type MultichainRoutingServiceGetSupportedMethodsAction = {\n type: `MultichainRoutingService:getSupportedMethods`;\n handler: MultichainRoutingService['getSupportedMethods'];\n};\n\n/**\n * Get a list of supported accounts for a given scope.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of CAIP-10 addresses.\n */\nexport type MultichainRoutingServiceGetSupportedAccountsAction = {\n type: `MultichainRoutingService:getSupportedAccounts`;\n handler: MultichainRoutingService['getSupportedAccounts'];\n};\n\n/**\n * Determine whether a given CAIP-2 scope is supported by the router.\n *\n * @param scope - The CAIP-2 scope.\n * @returns True if the router can service the scope, otherwise false.\n */\nexport type MultichainRoutingServiceIsSupportedScopeAction = {\n type: `MultichainRoutingService:isSupportedScope`;\n handler: MultichainRoutingService['isSupportedScope'];\n};\n\n/**\n * Union of all MultichainRoutingService action types.\n */\nexport type MultichainRoutingServiceMethodActions =\n | MultichainRoutingServiceHandleRequestAction\n | MultichainRoutingServiceGetSupportedMethodsAction\n | MultichainRoutingServiceGetSupportedAccountsAction\n | MultichainRoutingServiceIsSupportedScopeAction;\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { MultichainRoutingService } from "./MultichainRoutingService.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* Handle an incoming JSON-RPC request tied to a specific scope by routing
|
|
8
|
+
* to either a protocol Snap or an account Snap.
|
|
9
|
+
*
|
|
10
|
+
* Note: Addresses are considered case-sensitive by the MultichainRoutingService as
|
|
11
|
+
* not all non-EVM chains are case-insensitive.
|
|
12
|
+
*
|
|
13
|
+
* @param options - An options bag.
|
|
14
|
+
* @param options.connectedAddresses - Addresses currently connected to the
|
|
15
|
+
* origin for the requested scope.
|
|
16
|
+
* @param options.origin - The origin of the RPC request.
|
|
17
|
+
* @param options.request - The JSON-RPC request.
|
|
18
|
+
* @param options.scope - The CAIP-2 scope for the request.
|
|
19
|
+
* @returns The response from the chosen Snap.
|
|
20
|
+
* @throws If no handler was found.
|
|
21
|
+
*/
|
|
22
|
+
export type MultichainRoutingServiceHandleRequestAction = {
|
|
23
|
+
type: `MultichainRoutingService:handleRequest`;
|
|
24
|
+
handler: MultichainRoutingService['handleRequest'];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Get a list of supported methods for a given scope.
|
|
28
|
+
* This combines both protocol and account Snaps supported methods.
|
|
29
|
+
*
|
|
30
|
+
* @param scope - The CAIP-2 scope.
|
|
31
|
+
* @returns A list of supported methods.
|
|
32
|
+
*/
|
|
33
|
+
export type MultichainRoutingServiceGetSupportedMethodsAction = {
|
|
34
|
+
type: `MultichainRoutingService:getSupportedMethods`;
|
|
35
|
+
handler: MultichainRoutingService['getSupportedMethods'];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Get a list of supported accounts for a given scope.
|
|
39
|
+
*
|
|
40
|
+
* @param scope - The CAIP-2 scope.
|
|
41
|
+
* @returns A list of CAIP-10 addresses.
|
|
42
|
+
*/
|
|
43
|
+
export type MultichainRoutingServiceGetSupportedAccountsAction = {
|
|
44
|
+
type: `MultichainRoutingService:getSupportedAccounts`;
|
|
45
|
+
handler: MultichainRoutingService['getSupportedAccounts'];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Determine whether a given CAIP-2 scope is supported by the router.
|
|
49
|
+
*
|
|
50
|
+
* @param scope - The CAIP-2 scope.
|
|
51
|
+
* @returns True if the router can service the scope, otherwise false.
|
|
52
|
+
*/
|
|
53
|
+
export type MultichainRoutingServiceIsSupportedScopeAction = {
|
|
54
|
+
type: `MultichainRoutingService:isSupportedScope`;
|
|
55
|
+
handler: MultichainRoutingService['isSupportedScope'];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Union of all MultichainRoutingService action types.
|
|
59
|
+
*/
|
|
60
|
+
export type MultichainRoutingServiceMethodActions = MultichainRoutingServiceHandleRequestAction | MultichainRoutingServiceGetSupportedMethodsAction | MultichainRoutingServiceGetSupportedAccountsAction | MultichainRoutingServiceIsSupportedScopeAction;
|
|
61
|
+
//# sourceMappingURL=MultichainRoutingService-method-action-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainRoutingService-method-action-types.d.cts","sourceRoot":"","sources":["../../src/multichain/MultichainRoutingService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAmC;AAE3E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,wBAAwB,CAAC,eAAe,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,wBAAwB,CAAC,qBAAqB,CAAC,CAAC;CAC1D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC/D,IAAI,EAAE,+CAA+C,CAAC;IACtD,OAAO,EAAE,wBAAwB,CAAC,sBAAsB,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC7C,2CAA2C,GAC3C,iDAAiD,GACjD,kDAAkD,GAClD,8CAA8C,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { MultichainRoutingService } from "./MultichainRoutingService.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Handle an incoming JSON-RPC request tied to a specific scope by routing
|
|
8
|
+
* to either a protocol Snap or an account Snap.
|
|
9
|
+
*
|
|
10
|
+
* Note: Addresses are considered case-sensitive by the MultichainRoutingService as
|
|
11
|
+
* not all non-EVM chains are case-insensitive.
|
|
12
|
+
*
|
|
13
|
+
* @param options - An options bag.
|
|
14
|
+
* @param options.connectedAddresses - Addresses currently connected to the
|
|
15
|
+
* origin for the requested scope.
|
|
16
|
+
* @param options.origin - The origin of the RPC request.
|
|
17
|
+
* @param options.request - The JSON-RPC request.
|
|
18
|
+
* @param options.scope - The CAIP-2 scope for the request.
|
|
19
|
+
* @returns The response from the chosen Snap.
|
|
20
|
+
* @throws If no handler was found.
|
|
21
|
+
*/
|
|
22
|
+
export type MultichainRoutingServiceHandleRequestAction = {
|
|
23
|
+
type: `MultichainRoutingService:handleRequest`;
|
|
24
|
+
handler: MultichainRoutingService['handleRequest'];
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Get a list of supported methods for a given scope.
|
|
28
|
+
* This combines both protocol and account Snaps supported methods.
|
|
29
|
+
*
|
|
30
|
+
* @param scope - The CAIP-2 scope.
|
|
31
|
+
* @returns A list of supported methods.
|
|
32
|
+
*/
|
|
33
|
+
export type MultichainRoutingServiceGetSupportedMethodsAction = {
|
|
34
|
+
type: `MultichainRoutingService:getSupportedMethods`;
|
|
35
|
+
handler: MultichainRoutingService['getSupportedMethods'];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Get a list of supported accounts for a given scope.
|
|
39
|
+
*
|
|
40
|
+
* @param scope - The CAIP-2 scope.
|
|
41
|
+
* @returns A list of CAIP-10 addresses.
|
|
42
|
+
*/
|
|
43
|
+
export type MultichainRoutingServiceGetSupportedAccountsAction = {
|
|
44
|
+
type: `MultichainRoutingService:getSupportedAccounts`;
|
|
45
|
+
handler: MultichainRoutingService['getSupportedAccounts'];
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Determine whether a given CAIP-2 scope is supported by the router.
|
|
49
|
+
*
|
|
50
|
+
* @param scope - The CAIP-2 scope.
|
|
51
|
+
* @returns True if the router can service the scope, otherwise false.
|
|
52
|
+
*/
|
|
53
|
+
export type MultichainRoutingServiceIsSupportedScopeAction = {
|
|
54
|
+
type: `MultichainRoutingService:isSupportedScope`;
|
|
55
|
+
handler: MultichainRoutingService['isSupportedScope'];
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* Union of all MultichainRoutingService action types.
|
|
59
|
+
*/
|
|
60
|
+
export type MultichainRoutingServiceMethodActions = MultichainRoutingServiceHandleRequestAction | MultichainRoutingServiceGetSupportedMethodsAction | MultichainRoutingServiceGetSupportedAccountsAction | MultichainRoutingServiceIsSupportedScopeAction;
|
|
61
|
+
//# sourceMappingURL=MultichainRoutingService-method-action-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainRoutingService-method-action-types.d.mts","sourceRoot":"","sources":["../../src/multichain/MultichainRoutingService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,wBAAwB,EAAE,uCAAmC;AAE3E;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,2CAA2C,GAAG;IACxD,IAAI,EAAE,wCAAwC,CAAC;IAC/C,OAAO,EAAE,wBAAwB,CAAC,eAAe,CAAC,CAAC;CACpD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,iDAAiD,GAAG;IAC9D,IAAI,EAAE,8CAA8C,CAAC;IACrD,OAAO,EAAE,wBAAwB,CAAC,qBAAqB,CAAC,CAAC;CAC1D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kDAAkD,GAAG;IAC/D,IAAI,EAAE,+CAA+C,CAAC;IACtD,OAAO,EAAE,wBAAwB,CAAC,sBAAsB,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C,CAAC;IAClD,OAAO,EAAE,wBAAwB,CAAC,kBAAkB,CAAC,CAAC;CACvD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qCAAqC,GAC7C,2CAA2C,GAC3C,iDAAiD,GACjD,kDAAkD,GAClD,8CAA8C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainRoutingService-method-action-types.mjs","sourceRoot":"","sources":["../../src/multichain/MultichainRoutingService-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { MultichainRoutingService } from './MultichainRoutingService';\n\n/**\n * Handle an incoming JSON-RPC request tied to a specific scope by routing\n * to either a protocol Snap or an account Snap.\n *\n * Note: Addresses are considered case-sensitive by the MultichainRoutingService as\n * not all non-EVM chains are case-insensitive.\n *\n * @param options - An options bag.\n * @param options.connectedAddresses - Addresses currently connected to the\n * origin for the requested scope.\n * @param options.origin - The origin of the RPC request.\n * @param options.request - The JSON-RPC request.\n * @param options.scope - The CAIP-2 scope for the request.\n * @returns The response from the chosen Snap.\n * @throws If no handler was found.\n */\nexport type MultichainRoutingServiceHandleRequestAction = {\n type: `MultichainRoutingService:handleRequest`;\n handler: MultichainRoutingService['handleRequest'];\n};\n\n/**\n * Get a list of supported methods for a given scope.\n * This combines both protocol and account Snaps supported methods.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of supported methods.\n */\nexport type MultichainRoutingServiceGetSupportedMethodsAction = {\n type: `MultichainRoutingService:getSupportedMethods`;\n handler: MultichainRoutingService['getSupportedMethods'];\n};\n\n/**\n * Get a list of supported accounts for a given scope.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of CAIP-10 addresses.\n */\nexport type MultichainRoutingServiceGetSupportedAccountsAction = {\n type: `MultichainRoutingService:getSupportedAccounts`;\n handler: MultichainRoutingService['getSupportedAccounts'];\n};\n\n/**\n * Determine whether a given CAIP-2 scope is supported by the router.\n *\n * @param scope - The CAIP-2 scope.\n * @returns True if the router can service the scope, otherwise false.\n */\nexport type MultichainRoutingServiceIsSupportedScopeAction = {\n type: `MultichainRoutingService:isSupportedScope`;\n handler: MultichainRoutingService['isSupportedScope'];\n};\n\n/**\n * Union of all MultichainRoutingService action types.\n */\nexport type MultichainRoutingServiceMethodActions =\n | MultichainRoutingServiceHandleRequestAction\n | MultichainRoutingServiceGetSupportedMethodsAction\n | MultichainRoutingServiceGetSupportedAccountsAction\n | MultichainRoutingServiceIsSupportedScopeAction;\n"]}
|
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.MultichainRoutingService = void 0;
|
|
4
4
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
5
|
const snaps_rpc_methods_1 = require("@metamask/snaps-rpc-methods");
|
|
6
6
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
7
7
|
const utils_1 = require("@metamask/utils");
|
|
8
8
|
const nanoid_1 = require("nanoid");
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
|
|
9
|
+
const name = 'MultichainRoutingService';
|
|
10
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
11
|
+
'handleRequest',
|
|
12
|
+
'getSupportedMethods',
|
|
13
|
+
'getSupportedAccounts',
|
|
14
|
+
'isSupportedScope',
|
|
15
|
+
];
|
|
16
|
+
class MultichainRoutingService {
|
|
12
17
|
name = name;
|
|
13
18
|
state = null;
|
|
14
19
|
#messenger;
|
|
@@ -16,10 +21,7 @@ class MultichainRouter {
|
|
|
16
21
|
constructor({ messenger, withSnapKeyring }) {
|
|
17
22
|
this.#messenger = messenger;
|
|
18
23
|
this.#withSnapKeyring = withSnapKeyring;
|
|
19
|
-
this.#messenger.
|
|
20
|
-
this.#messenger.registerActionHandler(`${name}:getSupportedMethods`, (...args) => this.getSupportedMethods(...args));
|
|
21
|
-
this.#messenger.registerActionHandler(`${name}:getSupportedAccounts`, (...args) => this.getSupportedAccounts(...args));
|
|
22
|
-
this.#messenger.registerActionHandler(`${name}:isSupportedScope`, (...args) => this.isSupportedScope(...args));
|
|
24
|
+
this.#messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
23
25
|
}
|
|
24
26
|
/**
|
|
25
27
|
* Attempts to resolve the account address to use for a given request by inspecting the request itself.
|
|
@@ -113,8 +115,7 @@ class MultichainRouter {
|
|
|
113
115
|
* @returns A list of all the protocol Snaps available and their RPC methods.
|
|
114
116
|
*/
|
|
115
117
|
#getProtocolSnaps(scope) {
|
|
116
|
-
const
|
|
117
|
-
const filteredSnaps = (0, snaps_1.getRunnableSnaps)(allSnaps);
|
|
118
|
+
const filteredSnaps = this.#messenger.call('SnapController:getRunnableSnaps');
|
|
118
119
|
return filteredSnaps.reduce((accumulator, snap) => {
|
|
119
120
|
const permissions = this.#messenger.call('PermissionController:getPermissions', snap.id);
|
|
120
121
|
if (permissions && (0, utils_1.hasProperty)(permissions, snaps_rpc_methods_1.SnapEndowments.Protocol)) {
|
|
@@ -134,7 +135,7 @@ class MultichainRouter {
|
|
|
134
135
|
* Handle an incoming JSON-RPC request tied to a specific scope by routing
|
|
135
136
|
* to either a protocol Snap or an account Snap.
|
|
136
137
|
*
|
|
137
|
-
* Note: Addresses are considered case-sensitive by the
|
|
138
|
+
* Note: Addresses are considered case-sensitive by the MultichainRoutingService as
|
|
138
139
|
* not all non-EVM chains are case-insensitive.
|
|
139
140
|
*
|
|
140
141
|
* @param options - An options bag.
|
|
@@ -236,5 +237,5 @@ class MultichainRouter {
|
|
|
236
237
|
return hasAccountSnap || this.#getProtocolSnaps(scope).length > 0;
|
|
237
238
|
}
|
|
238
239
|
}
|
|
239
|
-
exports.
|
|
240
|
-
//# sourceMappingURL=
|
|
240
|
+
exports.MultichainRoutingService = MultichainRoutingService;
|
|
241
|
+
//# sourceMappingURL=MultichainRoutingService.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainRoutingService.cjs","sourceRoot":"","sources":["../../src/multichain/Multichain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,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,CAC3C,CAAC;IACJ,CAAC;IAED;;;;;OAKG;IACH,gBAAgB,CAAC,KAAkB;QACjC,MAAM,cAAc,GAAG,IAAI,CAAC,UAAU;aACnC,IAAI,CAAC,2CAA2C,EAAE,KAAK,CAAC;aACxD,IAAI,CAAC,CAAC,OAAwB,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACtE,+GAA+G;QAC/G,OAAO,cAAc,IAAI,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;IACpE,CAAC;CACF;AA9TD,4DA8TC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { GetPermissions } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n getProtocolCaveatScopes,\n SnapEndowments,\n} from '@metamask/snaps-rpc-methods';\nimport type { Json, JsonRpcRequest, SnapId } from '@metamask/snaps-sdk';\nimport type { InternalAccount } from '@metamask/snaps-utils';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n JsonRpcParams,\n} from '@metamask/utils';\nimport {\n assert,\n hasProperty,\n isObject,\n KnownCaipNamespace,\n parseCaipAccountId,\n} from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport type { MultichainRoutingServiceMethodActions } from './MultichainRoutingService-method-action-types';\nimport type {\n SnapControllerGetRunnableSnapsAction,\n SnapControllerHandleRequestAction,\n} from '../snaps';\n\ntype SnapKeyring = {\n submitRequest: (request: {\n origin: string;\n account: string;\n method: string;\n params?: Json[] | Record<string, Json>;\n scope: CaipChainId;\n }) => Promise<Json>;\n};\n\n// Expecting a bound function that calls KeyringController.withKeyring selecting the Snap keyring\nexport type WithSnapKeyringFunction = <ReturnType>(\n operation: ({ keyring }: { keyring: SnapKeyring }) => Promise<ReturnType>,\n) => Promise<ReturnType>;\n\nexport type AccountsControllerListMultichainAccountsAction = {\n type: `AccountsController:listMultichainAccounts`;\n handler: (chainId?: CaipChainId) => InternalAccount[];\n};\n\nexport type MultichainRoutingServiceActions =\n MultichainRoutingServiceMethodActions;\n\ntype AllowedActions =\n | SnapControllerGetRunnableSnapsAction\n | SnapControllerHandleRequestAction\n | GetPermissions\n | AccountsControllerListMultichainAccountsAction;\n\nexport type MultichainRoutingServiceEvents = never;\n\nexport type MultichainRoutingServiceMessenger = Messenger<\n typeof name,\n MultichainRoutingServiceActions | AllowedActions\n>;\n\nexport type MultichainRoutingServiceArgs = {\n messenger: MultichainRoutingServiceMessenger;\n withSnapKeyring: WithSnapKeyringFunction;\n};\n\ntype ProtocolSnap = {\n snapId: SnapId;\n methods: string[];\n};\n\nconst name = 'MultichainRoutingService';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'handleRequest',\n 'getSupportedMethods',\n 'getSupportedAccounts',\n 'isSupportedScope',\n] as const;\n\nexport class MultichainRoutingService {\n name: typeof name = name;\n\n state = null;\n\n readonly #messenger: MultichainRoutingServiceMessenger;\n\n readonly #withSnapKeyring: WithSnapKeyringFunction;\n\n constructor({ messenger, withSnapKeyring }: MultichainRoutingServiceArgs) {\n this.#messenger = messenger;\n this.#withSnapKeyring = withSnapKeyring;\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Attempts to resolve the account address to use for a given request by inspecting the request itself.\n *\n * The request is sent to an account Snap that will attempt this resolution.\n *\n * We manually construct the request instead of using the SnapKeyring, as the keyring may not be available.\n *\n * @param snapId - The ID of the Snap to send the request to.\n * @param scope - The CAIP-2 scope for the request.\n * @param request - The JSON-RPC request.\n * @returns The resolved address if found, otherwise null.\n * @throws If the invocation of the SnapKeyring fails.\n */\n async #resolveRequestAddress(\n snapId: SnapId,\n scope: CaipChainId,\n request: JsonRpcRequest,\n ) {\n try {\n const result = await this.#messenger.call(\n 'SnapController:handleRequest',\n {\n snapId,\n origin: 'metamask',\n request: {\n method: 'keyring_resolveAccountAddress',\n params: {\n request,\n scope,\n },\n },\n handler: HandlerType.OnKeyringRequest,\n },\n );\n\n assert(result === null || isObject(result));\n\n const address = result?.address as CaipAccountId;\n return address ? parseCaipAccountId(address).address : null;\n } catch {\n throw rpcErrors.internal();\n }\n }\n\n /**\n * Get the account ID of the account that should service the RPC request via an account Snap.\n *\n * This function checks whether any accounts exist that can service a given request by\n * using a combination of the resolveAccountAddress functionality and the connected accounts.\n *\n * If an account is expected to service this request but none is found, the function will throw.\n *\n * @param connectedAddresses - The CAIP-10 addresses connected to the\n * requesting origin for the requested scope.\n * @param scope - The CAIP-2 scope for the request.\n * @param request - The JSON-RPC request.\n * @returns An account ID if found, otherwise null.\n * @throws If no account is found, but the accounts exist that could service the request.\n */\n async #getSnapAccountId(\n connectedAddresses: CaipAccountId[],\n scope: CaipChainId,\n request: JsonRpcRequest,\n ) {\n const accounts = this.#messenger\n .call('AccountsController:listMultichainAccounts', scope)\n .filter(\n (\n account: InternalAccount,\n ): account is InternalAccount & {\n metadata: Required<InternalAccount['metadata']>;\n } =>\n Boolean(account.metadata.snap?.enabled) &&\n account.methods.includes(request.method),\n );\n\n // If no accounts can service the request, return null.\n if (accounts.length === 0) {\n return null;\n }\n\n const parsedConnectedAddresses = connectedAddresses.map(\n (connectedAddress) => parseCaipAccountId(connectedAddress).address,\n );\n\n const connectedAccounts = accounts.filter((account) =>\n parsedConnectedAddresses.includes(account.address),\n );\n\n if (connectedAccounts.length === 0) {\n throw rpcErrors.invalidParams({\n message: 'No available account found for request.',\n });\n }\n\n const resolutionSnapId = connectedAccounts[0].metadata.snap.id;\n\n // Attempt to resolve the address that should be used for signing.\n const address = await this.#resolveRequestAddress(\n resolutionSnapId,\n scope,\n request,\n );\n\n // If we have a resolved address, try to find the selected account based on that\n // otherwise, default to one of the connected accounts.\n // TODO: Eventually let the user choose if we have more than one option for the account.\n const selectedAccount = address\n ? connectedAccounts.find((account) => account.address === address)\n : connectedAccounts[0];\n\n if (!selectedAccount) {\n throw rpcErrors.invalidParams({\n message: 'No available account found for request.',\n });\n }\n\n return selectedAccount.id;\n }\n\n /**\n * Get all protocol Snaps that can service a given CAIP-2 scope.\n *\n * Protocol Snaps are deemed fit to service a scope if they are runnable\n * and have the proper permissions set for the scope.\n *\n * @param scope - A CAIP-2 scope.\n * @returns A list of all the protocol Snaps available and their RPC methods.\n */\n #getProtocolSnaps(scope: CaipChainId) {\n const filteredSnaps = this.#messenger.call(\n 'SnapController:getRunnableSnaps',\n );\n\n return filteredSnaps.reduce<ProtocolSnap[]>((accumulator, snap) => {\n const permissions = this.#messenger.call(\n 'PermissionController:getPermissions',\n snap.id,\n );\n\n if (permissions && hasProperty(permissions, SnapEndowments.Protocol)) {\n const permission = permissions[SnapEndowments.Protocol];\n const scopes = getProtocolCaveatScopes(permission);\n if (scopes && hasProperty(scopes, scope)) {\n accumulator.push({\n snapId: snap.id,\n methods: scopes[scope].methods,\n });\n }\n }\n\n return accumulator;\n }, []);\n }\n\n /**\n * Handle an incoming JSON-RPC request tied to a specific scope by routing\n * to either a protocol Snap or an account Snap.\n *\n * Note: Addresses are considered case-sensitive by the MultichainRoutingService as\n * not all non-EVM chains are case-insensitive.\n *\n * @param options - An options bag.\n * @param options.connectedAddresses - Addresses currently connected to the\n * origin for the requested scope.\n * @param options.origin - The origin of the RPC request.\n * @param options.request - The JSON-RPC request.\n * @param options.scope - The CAIP-2 scope for the request.\n * @returns The response from the chosen Snap.\n * @throws If no handler was found.\n */\n async handleRequest({\n connectedAddresses,\n origin,\n scope,\n request: rawRequest,\n }: {\n connectedAddresses: CaipAccountId[];\n origin: string;\n scope: CaipChainId;\n request: JsonRpcRequest;\n }): Promise<Json> {\n // Explicitly block EVM scopes, just in case.\n assert(\n !scope.startsWith(KnownCaipNamespace.Eip155) &&\n !scope.startsWith('wallet:eip155'),\n );\n\n // Re-create the request to simplify and remove additional properties that may be present in MM middleware.\n const request = {\n jsonrpc: '2.0' as const,\n id: rawRequest.id ?? nanoid(),\n method: rawRequest.method,\n ...(rawRequest.params ? { params: rawRequest.params } : {}),\n };\n\n const { method, params } = request;\n\n // If the RPC request can be serviced by an account Snap, route it there.\n const accountId = await this.#getSnapAccountId(\n connectedAddresses,\n scope,\n request,\n );\n\n if (accountId) {\n return this.#withSnapKeyring(async ({ keyring }) =>\n keyring.submitRequest({\n origin,\n account: accountId,\n scope,\n method,\n params: params as JsonRpcParams,\n }),\n );\n }\n\n // If the RPC request cannot be serviced by an account Snap,\n // but has a protocol Snap available, route it there.\n const protocolSnaps = this.#getProtocolSnaps(scope);\n const protocolSnap = protocolSnaps.find((snap) =>\n snap.methods.includes(method),\n );\n\n if (protocolSnap) {\n return this.#messenger.call('SnapController:handleRequest', {\n snapId: protocolSnap.snapId,\n origin,\n request: {\n method: '',\n params: {\n request,\n scope,\n },\n },\n handler: HandlerType.OnProtocolRequest,\n }) as Promise<Json>;\n }\n\n // If no compatible account or protocol Snaps were found, throw.\n throw rpcErrors.methodNotFound();\n }\n\n /**\n * Get a list of metadata for supported accounts for a given scope from the client.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of metadata for the supported accounts.\n */\n #getSupportedAccountsMetadata(scope: CaipChainId): InternalAccount[] {\n return this.#messenger\n .call('AccountsController:listMultichainAccounts', scope)\n .filter((account: InternalAccount) => account.metadata.snap?.enabled);\n }\n\n /**\n * Get a list of supported methods for a given scope.\n * This combines both protocol and account Snaps supported methods.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of supported methods.\n */\n getSupportedMethods(scope: CaipChainId): string[] {\n const accountMethods = this.#getSupportedAccountsMetadata(scope).flatMap(\n (account) => account.methods,\n );\n\n const protocolMethods = this.#getProtocolSnaps(scope).flatMap(\n (snap) => snap.methods,\n );\n\n return Array.from(new Set([...accountMethods, ...protocolMethods]));\n }\n\n /**\n * Get a list of supported accounts for a given scope.\n *\n * @param scope - The CAIP-2 scope.\n * @returns A list of CAIP-10 addresses.\n */\n getSupportedAccounts(scope: CaipChainId): string[] {\n return this.#getSupportedAccountsMetadata(scope).map(\n (account) => `${scope}:${account.address}`,\n );\n }\n\n /**\n * Determine whether a given CAIP-2 scope is supported by the router.\n *\n * @param scope - The CAIP-2 scope.\n * @returns True if the router can service the scope, otherwise false.\n */\n isSupportedScope(scope: CaipChainId): boolean {\n const hasAccountSnap = this.#messenger\n .call('AccountsController:listMultichainAccounts', scope)\n .some((account: InternalAccount) => account.metadata.snap?.enabled);\n // We currently assume here that if one Snap exists that service the scope, we can service the scope generally.\n return hasAccountSnap || this.#getProtocolSnaps(scope).length > 0;\n }\n}\n"]}
|
|
@@ -3,23 +3,8 @@ import type { GetPermissions } from "@metamask/permission-controller";
|
|
|
3
3
|
import type { Json, JsonRpcRequest } from "@metamask/snaps-sdk";
|
|
4
4
|
import type { InternalAccount } from "@metamask/snaps-utils";
|
|
5
5
|
import type { CaipAccountId, CaipChainId } from "@metamask/utils";
|
|
6
|
-
import type {
|
|
7
|
-
|
|
8
|
-
type: `${typeof name}:handleRequest`;
|
|
9
|
-
handler: MultichainRouter['handleRequest'];
|
|
10
|
-
};
|
|
11
|
-
export type MultichainRouterGetSupportedMethodsAction = {
|
|
12
|
-
type: `${typeof name}:getSupportedMethods`;
|
|
13
|
-
handler: MultichainRouter['getSupportedMethods'];
|
|
14
|
-
};
|
|
15
|
-
export type MultichainRouterGetSupportedAccountsAction = {
|
|
16
|
-
type: `${typeof name}:getSupportedAccounts`;
|
|
17
|
-
handler: MultichainRouter['getSupportedAccounts'];
|
|
18
|
-
};
|
|
19
|
-
export type MultichainRouterIsSupportedScopeAction = {
|
|
20
|
-
type: `${typeof name}:isSupportedScope`;
|
|
21
|
-
handler: MultichainRouter['isSupportedScope'];
|
|
22
|
-
};
|
|
6
|
+
import type { MultichainRoutingServiceMethodActions } from "./MultichainRoutingService-method-action-types.cjs";
|
|
7
|
+
import type { SnapControllerGetRunnableSnapsAction, SnapControllerHandleRequestAction } from "../snaps/index.cjs";
|
|
23
8
|
type SnapKeyring = {
|
|
24
9
|
submitRequest: (request: {
|
|
25
10
|
origin: string;
|
|
@@ -36,25 +21,25 @@ export type AccountsControllerListMultichainAccountsAction = {
|
|
|
36
21
|
type: `AccountsController:listMultichainAccounts`;
|
|
37
22
|
handler: (chainId?: CaipChainId) => InternalAccount[];
|
|
38
23
|
};
|
|
39
|
-
export type
|
|
40
|
-
|
|
41
|
-
export type
|
|
42
|
-
export type
|
|
43
|
-
export type
|
|
44
|
-
messenger:
|
|
24
|
+
export type MultichainRoutingServiceActions = MultichainRoutingServiceMethodActions;
|
|
25
|
+
type AllowedActions = SnapControllerGetRunnableSnapsAction | SnapControllerHandleRequestAction | GetPermissions | AccountsControllerListMultichainAccountsAction;
|
|
26
|
+
export type MultichainRoutingServiceEvents = never;
|
|
27
|
+
export type MultichainRoutingServiceMessenger = Messenger<typeof name, MultichainRoutingServiceActions | AllowedActions>;
|
|
28
|
+
export type MultichainRoutingServiceArgs = {
|
|
29
|
+
messenger: MultichainRoutingServiceMessenger;
|
|
45
30
|
withSnapKeyring: WithSnapKeyringFunction;
|
|
46
31
|
};
|
|
47
|
-
declare const name = "
|
|
48
|
-
export declare class
|
|
32
|
+
declare const name = "MultichainRoutingService";
|
|
33
|
+
export declare class MultichainRoutingService {
|
|
49
34
|
#private;
|
|
50
35
|
name: typeof name;
|
|
51
36
|
state: null;
|
|
52
|
-
constructor({ messenger, withSnapKeyring }:
|
|
37
|
+
constructor({ messenger, withSnapKeyring }: MultichainRoutingServiceArgs);
|
|
53
38
|
/**
|
|
54
39
|
* Handle an incoming JSON-RPC request tied to a specific scope by routing
|
|
55
40
|
* to either a protocol Snap or an account Snap.
|
|
56
41
|
*
|
|
57
|
-
* Note: Addresses are considered case-sensitive by the
|
|
42
|
+
* Note: Addresses are considered case-sensitive by the MultichainRoutingService as
|
|
58
43
|
* not all non-EVM chains are case-insensitive.
|
|
59
44
|
*
|
|
60
45
|
* @param options - An options bag.
|
|
@@ -96,4 +81,4 @@ export declare class MultichainRouter {
|
|
|
96
81
|
isSupportedScope(scope: CaipChainId): boolean;
|
|
97
82
|
}
|
|
98
83
|
export {};
|
|
99
|
-
//# sourceMappingURL=
|
|
84
|
+
//# sourceMappingURL=MultichainRoutingService.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MultichainRoutingService.d.cts","sourceRoot":"","sources":["../../src/multichain/MultichainRoutingService.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,cAAc,EAAE,wCAAwC;AAMtE,OAAO,KAAK,EAAE,IAAI,EAAE,cAAc,EAAU,4BAA4B;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,8BAA8B;AAE7D,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EAEZ,wBAAwB;AAUzB,OAAO,KAAK,EAAE,qCAAqC,EAAE,2DAAuD;AAC5G,OAAO,KAAK,EACV,oCAAoC,EACpC,iCAAiC,EAClC,2BAAiB;AAElB,KAAK,WAAW,GAAG;IACjB,aAAa,EAAE,CAAC,OAAO,EAAE;QACvB,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,MAAM,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACvC,KAAK,EAAE,WAAW,CAAC;KACpB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrB,CAAC;AAGF,MAAM,MAAM,uBAAuB,GAAG,CAAC,UAAU,EAC/C,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE;IAAE,OAAO,EAAE,WAAW,CAAA;CAAE,KAAK,OAAO,CAAC,UAAU,CAAC,KACtE,OAAO,CAAC,UAAU,CAAC,CAAC;AAEzB,MAAM,MAAM,8CAA8C,GAAG;IAC3D,IAAI,EAAE,2CAA2C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