@metamask/snaps-simulation 3.5.0 → 3.5.1

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 CHANGED
@@ -7,6 +7,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [3.5.1]
11
+
12
+ ### Changed
13
+
14
+ - Bump `@metamask/permission-controller` from `^11.0.6` to `^12.0.0`(([#3611](https://github.com/MetaMask/snaps/pull/3611))
15
+
16
+ ### Removed
17
+
18
+ - Remove `@metamask/base-controller` dependency ([#3611](https://github.com/MetaMask/snaps/pull/3611))
19
+
10
20
  ## [3.5.0]
11
21
 
12
22
  ### Added
@@ -223,7 +233,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
223
233
 
224
234
  - Initial release of `@metamask/snaps-simulation` package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
225
235
 
226
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.5.0...HEAD
236
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.5.1...HEAD
237
+ [3.5.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.5.0...@metamask/snaps-simulation@3.5.1
227
238
  [3.5.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.4.2...@metamask/snaps-simulation@3.5.0
228
239
  [3.4.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.4.1...@metamask/snaps-simulation@3.4.2
229
240
  [3.4.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.4.0...@metamask/snaps-simulation@3.4.1
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerSnap = exports.getControllers = void 0;
4
+ const messenger_1 = require("@metamask/messenger");
4
5
  const permission_controller_1 = require("@metamask/permission-controller");
5
6
  const snaps_controllers_1 = require("@metamask/snaps-controllers");
6
7
  const snaps_rpc_methods_1 = require("@metamask/snaps-rpc-methods");
@@ -16,29 +17,31 @@ const constants_1 = require("./methods/constants.cjs");
16
17
  function getControllers(options) {
17
18
  const { controllerMessenger } = options;
18
19
  const subjectMetadataController = new permission_controller_1.SubjectMetadataController({
19
- messenger: controllerMessenger.getRestricted({
20
- name: 'SubjectMetadataController',
21
- allowedActions: [],
22
- allowedEvents: [],
20
+ messenger: new messenger_1.Messenger({
21
+ namespace: 'SubjectMetadataController',
22
+ parent: controllerMessenger,
23
23
  }),
24
24
  subjectCacheLimit: 100,
25
25
  });
26
+ const interfaceControllerMessenger = new messenger_1.Messenger({
27
+ namespace: 'SnapInterfaceController',
28
+ parent: controllerMessenger,
29
+ });
30
+ controllerMessenger.delegate({
31
+ messenger: interfaceControllerMessenger,
32
+ actions: [
33
+ 'PhishingController:testOrigin',
34
+ 'ApprovalController:hasRequest',
35
+ 'ApprovalController:acceptRequest',
36
+ 'AccountsController:getAccountByAddress',
37
+ 'AccountsController:getSelectedMultichainAccount',
38
+ 'AccountsController:listMultichainAccounts',
39
+ 'MultichainAssetsController:getState',
40
+ ],
41
+ events: ['NotificationServicesController:notificationsListUpdated'],
42
+ });
26
43
  const interfaceController = new snaps_controllers_1.SnapInterfaceController({
27
- messenger: controllerMessenger.getRestricted({
28
- name: 'SnapInterfaceController',
29
- allowedActions: [
30
- 'PhishingController:testOrigin',
31
- 'ApprovalController:hasRequest',
32
- 'ApprovalController:acceptRequest',
33
- 'AccountsController:getAccountByAddress',
34
- 'AccountsController:getSelectedMultichainAccount',
35
- 'AccountsController:listMultichainAccounts',
36
- 'MultichainAssetsController:getState',
37
- ],
38
- allowedEvents: [
39
- 'NotificationServicesController:notificationsListUpdated',
40
- ],
41
- }),
44
+ messenger: interfaceControllerMessenger,
42
45
  });
43
46
  const permissionController = getPermissionController(options);
44
47
  return {
@@ -59,20 +62,24 @@ exports.getControllers = getControllers;
59
62
  function getPermissionController(options) {
60
63
  const { controllerMessenger } = options;
61
64
  const permissionSpecifications = (0, methods_1.getPermissionSpecifications)(options);
65
+ const messenger = new messenger_1.Messenger({
66
+ namespace: 'PermissionController',
67
+ parent: controllerMessenger,
68
+ });
69
+ controllerMessenger.delegate({
70
+ messenger,
71
+ actions: [
72
+ `ApprovalController:addRequest`,
73
+ `ApprovalController:hasRequest`,
74
+ `ApprovalController:acceptRequest`,
75
+ `ApprovalController:rejectRequest`,
76
+ `SnapController:getPermitted`,
77
+ `SnapController:install`,
78
+ `SubjectMetadataController:getSubjectMetadata`,
79
+ ],
80
+ });
62
81
  return new permission_controller_1.PermissionController({
63
- messenger: controllerMessenger.getRestricted({
64
- name: 'PermissionController',
65
- allowedActions: [
66
- `ApprovalController:addRequest`,
67
- `ApprovalController:hasRequest`,
68
- `ApprovalController:acceptRequest`,
69
- `ApprovalController:rejectRequest`,
70
- `SnapController:getPermitted`,
71
- `SnapController:install`,
72
- `SubjectMetadataController:getSubjectMetadata`,
73
- ],
74
- allowedEvents: [],
75
- }),
82
+ messenger,
76
83
  caveatSpecifications: {
77
84
  ...snaps_rpc_methods_1.caveatSpecifications,
78
85
  ...snaps_rpc_methods_1.endowmentCaveatSpecifications,
@@ -1 +1 @@
1
- {"version":3,"file":"controllers.cjs","sourceRoot":"","sources":["../src/controllers.ts"],"names":[],"mappings":";;;AAOA,2EAIyC;AACzC,mEAAsE;AAOtE,mEAIqC;AAGrC,2CAA8C;AAE9C,iDAAwD;AACxD,uDAA2D;AAoC3D;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,OAA8B;IAC3D,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IACxC,MAAM,yBAAyB,GAAG,IAAI,iDAAyB,CAAC;QAC9D,SAAS,EAAE,mBAAmB,CAAC,aAAa,CAAC;YAC3C,IAAI,EAAE,2BAA2B;YACjC,cAAc,EAAE,EAAE;YAClB,aAAa,EAAE,EAAE;SAClB,CAAC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,kBAAkB,CAAC;QAC3C,MAAM,EAAE,MAAM;QACd,WAAW,EAAE,mCAAW,CAAC,IAAI;KAC9B,CAAC,CAAC;IAEH,MAAM,mBAAmB,GAAG,IAAA,0CAAsB,EAChD,IAAA,mBAAW,EAAC,QAAQ,CAAC,kBAAkB,CAAC,CACzC,CAAC;IAEF,oBAAoB,CAAC,gBAAgB,CAAC;QACpC,mBAAmB;QACnB,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;QAC3B,2BAA2B,EAAE,KAAK;KACnC,CAAC,CAAC;AACL,CAAC;AAtBD,oCAsBC","sourcesContent":["import type { Messenger } from '@metamask/base-controller';\nimport type {\n CaveatSpecificationConstraint,\n PermissionSpecificationConstraint,\n PermissionControllerActions,\n SubjectMetadataControllerActions,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport { SnapInterfaceController } from '@metamask/snaps-controllers';\nimport type {\n ExecutionServiceActions,\n SnapInterfaceControllerActions,\n SnapInterfaceControllerAllowedActions,\n SnapInterfaceControllerStateChangeEvent,\n} from '@metamask/snaps-controllers';\nimport {\n caveatSpecifications as snapsCaveatsSpecifications,\n endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications,\n processSnapPermissions,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { SnapManifest } from '@metamask/snaps-utils';\nimport { getSafeJson } from '@metamask/utils';\n\nimport { getPermissionSpecifications } from './methods';\nimport { UNRESTRICTED_METHODS } from './methods/constants';\nimport type { SimulationOptions } from './options';\nimport type { RestrictedMiddlewareHooks } from './simulation';\nimport type { RunSagaFunction } from './store';\n\nexport type RootControllerAllowedActions =\n | SnapInterfaceControllerActions\n | SnapInterfaceControllerAllowedActions\n | PermissionControllerActions\n | ExecutionServiceActions\n | SubjectMetadataControllerActions;\n\nexport type RootControllerAllowedEvents =\n SnapInterfaceControllerStateChangeEvent;\n\nexport type RootControllerMessenger = Messenger<\n RootControllerAllowedActions,\n RootControllerAllowedEvents\n>;\n\nexport type GetControllersOptions = {\n controllerMessenger: Messenger<any, any>;\n hooks: RestrictedMiddlewareHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\nexport type Controllers = {\n permissionController: PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n >;\n subjectMetadataController: SubjectMetadataController;\n interfaceController: SnapInterfaceController;\n};\n\n/**\n * Get the controllers for the Snap.\n *\n * @param options - The options.\n * @returns The controllers for the Snap.\n */\nexport function getControllers(options: GetControllersOptions): Controllers {\n const { controllerMessenger } = options;\n const subjectMetadataController = new SubjectMetadataController({\n messenger: controllerMessenger.getRestricted({\n name: 'SubjectMetadataController',\n allowedActions: [],\n allowedEvents: [],\n }),\n subjectCacheLimit: 100,\n });\n\n const interfaceController = new SnapInterfaceController({\n messenger: controllerMessenger.getRestricted({\n name: 'SnapInterfaceController',\n allowedActions: [\n 'PhishingController:testOrigin',\n 'ApprovalController:hasRequest',\n 'ApprovalController:acceptRequest',\n 'AccountsController:getAccountByAddress',\n 'AccountsController:getSelectedMultichainAccount',\n 'AccountsController:listMultichainAccounts',\n 'MultichainAssetsController:getState',\n ],\n allowedEvents: [\n 'NotificationServicesController:notificationsListUpdated',\n ],\n }),\n });\n\n const permissionController = getPermissionController(options);\n\n return {\n permissionController,\n subjectMetadataController,\n interfaceController,\n };\n}\n\n/**\n * Get the permission controller for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.options - Miscellaneous options.\n * @returns The permission controller for the Snap.\n */\nfunction getPermissionController(options: GetControllersOptions) {\n const { controllerMessenger } = options;\n const permissionSpecifications = getPermissionSpecifications(options);\n return new PermissionController({\n messenger: controllerMessenger.getRestricted({\n name: 'PermissionController',\n allowedActions: [\n `ApprovalController:addRequest`,\n `ApprovalController:hasRequest`,\n `ApprovalController:acceptRequest`,\n `ApprovalController:rejectRequest`,\n `SnapController:getPermitted`,\n `SnapController:install`,\n `SubjectMetadataController:getSubjectMetadata`,\n ],\n allowedEvents: [],\n }),\n caveatSpecifications: {\n ...snapsCaveatsSpecifications,\n ...snapsEndowmentCaveatSpecifications,\n },\n permissionSpecifications,\n unrestrictedMethods: UNRESTRICTED_METHODS,\n });\n}\n\n/**\n * Register the Snap. This sets up the Snap's permissions and subject metadata.\n *\n * @param snapId - The ID of the Snap to install.\n * @param manifest - The parsed manifest.\n * @param controllers - The controllers for the Snap.\n * @param controllers.permissionController - The permission controller.\n * @param controllers.subjectMetadataController - The subject metadata controller.\n */\nexport async function registerSnap(\n snapId: SnapId,\n manifest: SnapManifest,\n {\n permissionController,\n subjectMetadataController,\n }: Omit<Controllers, 'interfaceController'>,\n) {\n subjectMetadataController.addSubjectMetadata({\n origin: snapId,\n subjectType: SubjectType.Snap,\n });\n\n const approvedPermissions = processSnapPermissions(\n getSafeJson(manifest.initialPermissions),\n );\n\n permissionController.grantPermissions({\n approvedPermissions,\n subject: { origin: snapId },\n preserveExistingPermissions: false,\n });\n}\n"]}
1
+ {"version":3,"file":"controllers.cjs","sourceRoot":"","sources":["../src/controllers.ts"],"names":[],"mappings":";;;AAAA,mDAAgD;AAOhD,2EAIyC;AACzC,mEAAsE;AAOtE,mEAIqC;AAGrC,2CAA8C;AAE9C,iDAAwD;AACxD,uDAA2D;AAqC3D;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,OAA8B;IAC3D,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IACxC,MAAM,yBAAyB,GAAG,IAAI,iDAAyB,CAAC;QAC9D,SAAS,EAAE,IAAI,qBAAS,CAAC;YACvB,SAAS,EAAE,2BAA2B;YACtC,MAAM,EAAE,mBAAmB;SAC5B,CAAC;QACF,iBAAiB,EAAE,GAAG;KACvB,CAAC,CAAC;IAEH,MAAM,4BAA4B,GAAG,IAAI,qBAAS,CAAC;QACjD,SAAS,EAAE,yBAAyB;QACpC,MAAM,EAAE,mBAAm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AAsB,EACtB,EACE,oBAAoB,EACpB,yBAAyB,GACgB;IAE3C,yBAAyB,CAAC,kBAAkB,CAAC;QAC3C,MAAM,EAAE,MAAM;QACd,WAAW,EAAE,mCAAW,CAAC,IAAI;KAC9B,CAAC,CAAC;IAEH,MAAM,mBAAmB,GAAG,IAAA,0CAAsB,EAChD,IAAA,mBAAW,EAAC,QAAQ,CAAC,kBAAkB,CAAC,CACzC,CAAC;IAEF,oBAAoB,CAAC,gBAAgB,CAAC;QACpC,mBAAmB;QACnB,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;QAC3B,2BAA2B,EAAE,KAAK;KACnC,CAAC,CAAC;AACL,CAAC;AAtBD,oCAsBC","sourcesContent":["import { Messenger } from '@metamask/messenger';\nimport type {\n CaveatSpecificationConstraint,\n PermissionSpecificationConstraint,\n PermissionControllerActions,\n SubjectMetadataControllerActions,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport { SnapInterfaceController } from '@metamask/snaps-controllers';\nimport type {\n ExecutionServiceActions,\n SnapInterfaceControllerActions,\n SnapInterfaceControllerAllowedActions,\n SnapInterfaceControllerStateChangeEvent,\n} from '@metamask/snaps-controllers';\nimport {\n caveatSpecifications as snapsCaveatsSpecifications,\n endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications,\n processSnapPermissions,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { SnapManifest } from '@metamask/snaps-utils';\nimport { getSafeJson } from '@metamask/utils';\n\nimport { getPermissionSpecifications } from './methods';\nimport { UNRESTRICTED_METHODS } from './methods/constants';\nimport type { SimulationOptions } from './options';\nimport type { RestrictedMiddlewareHooks } from './simulation';\nimport type { RunSagaFunction } from './store';\n\nexport type RootControllerAllowedActions =\n | SnapInterfaceControllerActions\n | SnapInterfaceControllerAllowedActions\n | PermissionControllerActions\n | ExecutionServiceActions\n | SubjectMetadataControllerActions;\n\nexport type RootControllerAllowedEvents =\n SnapInterfaceControllerStateChangeEvent;\n\nexport type RootControllerMessenger = Messenger<\n any,\n RootControllerAllowedActions,\n RootControllerAllowedEvents\n>;\n\nexport type GetControllersOptions = {\n controllerMessenger: Messenger<any, any, any>;\n hooks: RestrictedMiddlewareHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\nexport type Controllers = {\n permissionController: PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n >;\n subjectMetadataController: SubjectMetadataController;\n interfaceController: SnapInterfaceController;\n};\n\n/**\n * Get the controllers for the Snap.\n *\n * @param options - The options.\n * @returns The controllers for the Snap.\n */\nexport function getControllers(options: GetControllersOptions): Controllers {\n const { controllerMessenger } = options;\n const subjectMetadataController = new SubjectMetadataController({\n messenger: new Messenger({\n namespace: 'SubjectMetadataController',\n parent: controllerMessenger,\n }),\n subjectCacheLimit: 100,\n });\n\n const interfaceControllerMessenger = new Messenger({\n namespace: 'SnapInterfaceController',\n parent: controllerMessenger,\n });\n\n controllerMessenger.delegate({\n messenger: interfaceControllerMessenger,\n actions: [\n 'PhishingController:testOrigin',\n 'ApprovalController:hasRequest',\n 'ApprovalController:acceptRequest',\n 'AccountsController:getAccountByAddress',\n 'AccountsController:getSelectedMultichainAccount',\n 'AccountsController:listMultichainAccounts',\n 'MultichainAssetsController:getState',\n ],\n events: ['NotificationServicesController:notificationsListUpdated'],\n });\n\n const interfaceController = new SnapInterfaceController({\n messenger: interfaceControllerMessenger,\n });\n\n const permissionController = getPermissionController(options);\n\n return {\n permissionController,\n subjectMetadataController,\n interfaceController,\n };\n}\n\n/**\n * Get the permission controller for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.options - Miscellaneous options.\n * @returns The permission controller for the Snap.\n */\nfunction getPermissionController(options: GetControllersOptions) {\n const { controllerMessenger } = options;\n const permissionSpecifications = getPermissionSpecifications(options);\n const messenger = new Messenger({\n namespace: 'PermissionController',\n parent: controllerMessenger,\n });\n\n controllerMessenger.delegate({\n messenger,\n actions: [\n `ApprovalController:addRequest`,\n `ApprovalController:hasRequest`,\n `ApprovalController:acceptRequest`,\n `ApprovalController:rejectRequest`,\n `SnapController:getPermitted`,\n `SnapController:install`,\n `SubjectMetadataController:getSubjectMetadata`,\n ],\n });\n\n return new PermissionController({\n messenger,\n caveatSpecifications: {\n ...snapsCaveatsSpecifications,\n ...snapsEndowmentCaveatSpecifications,\n },\n permissionSpecifications,\n unrestrictedMethods: UNRESTRICTED_METHODS,\n });\n}\n\n/**\n * Register the Snap. This sets up the Snap's permissions and subject metadata.\n *\n * @param snapId - The ID of the Snap to install.\n * @param manifest - The parsed manifest.\n * @param controllers - The controllers for the Snap.\n * @param controllers.permissionController - The permission controller.\n * @param controllers.subjectMetadataController - The subject metadata controller.\n */\nexport async function registerSnap(\n snapId: SnapId,\n manifest: SnapManifest,\n {\n permissionController,\n subjectMetadataController,\n }: Omit<Controllers, 'interfaceController'>,\n) {\n subjectMetadataController.addSubjectMetadata({\n origin: snapId,\n subjectType: SubjectType.Snap,\n });\n\n const approvedPermissions = processSnapPermissions(\n getSafeJson(manifest.initialPermissions),\n );\n\n permissionController.grantPermissions({\n approvedPermissions,\n subject: { origin: snapId },\n preserveExistingPermissions: false,\n });\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { Messenger } from "@metamask/base-controller";
1
+ import { Messenger } from "@metamask/messenger";
2
2
  import type { CaveatSpecificationConstraint, PermissionSpecificationConstraint, PermissionControllerActions, SubjectMetadataControllerActions } from "@metamask/permission-controller";
3
3
  import { PermissionController, SubjectMetadataController } from "@metamask/permission-controller";
4
4
  import { SnapInterfaceController } from "@metamask/snaps-controllers";
@@ -10,9 +10,9 @@ import type { RestrictedMiddlewareHooks } from "./simulation.cjs";
10
10
  import type { RunSagaFunction } from "./store/index.cjs";
11
11
  export type RootControllerAllowedActions = SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions | PermissionControllerActions | ExecutionServiceActions | SubjectMetadataControllerActions;
12
12
  export type RootControllerAllowedEvents = SnapInterfaceControllerStateChangeEvent;
13
- export type RootControllerMessenger = Messenger<RootControllerAllowedActions, RootControllerAllowedEvents>;
13
+ export type RootControllerMessenger = Messenger<any, RootControllerAllowedActions, RootControllerAllowedEvents>;
14
14
  export type GetControllersOptions = {
15
- controllerMessenger: Messenger<any, any>;
15
+ controllerMessenger: Messenger<any, any, any>;
16
16
  hooks: RestrictedMiddlewareHooks;
17
17
  runSaga: RunSagaFunction;
18
18
  options: SimulationOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"controllers.d.cts","sourceRoot":"","sources":["../src/controllers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,6BAA6B,EAC7B,iCAAiC,EACjC,2BAA2B,EAC3B,gCAAgC,EACjC,wCAAwC;AACzC,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EAE1B,wCAAwC;AACzC,OAAO,EAAE,uBAAuB,EAAE,oCAAoC;AACtE,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAC9B,qCAAqC,EACrC,uCAAuC,EACxC,oCAAoC;AAMrC,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAK1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAkB;AACnD,OAAO,KAAK,EAAE,yBAAyB,EAAE,yBAAqB;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,0BAAgB;AAE/C,MAAM,MAAM,4BAA4B,GACpC,8BAA8B,GAC9B,qCAAqC,GACrC,2BAA2B,GAC3B,uBAAuB,GACvB,gCAAgC,CAAC;AAErC,MAAM,MAAM,2BAA2B,GACrC,uCAAuC,CAAC;AAE1C,MAAM,MAAM,uBAAuB,GAAG,SAAS,CAC7C,4BAA4B,EAC5B,2BAA2B,CAC5B,CAAC;AAEF,MA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KAAK,EAAE,eAAe,EAAE,0BAAgB;AAE/C,MAAM,MAAM,4BAA4B,GACpC,8BAA8B,GAC9B,qCAAqC,GACrC,2BAA2B,GAC3B,uBAAuB,GACvB,gCAAgC,CAAC;AAErC,MAAM,MAAM,2BAA2B,GACrC,uCAAuC,CAAC;AAE1C,MAAM,MAAM,uBAAuB,GAAG,SAAS,CAC7C,GAAG,EACH,4BAA4B,EAC5B,2BAA2B,CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,mBAAmB,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9C,KAAK,EAAE,yBAAyB,CAAC;IACjC,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,oBAAoB,EAAE,oBAAoB,CACxC,iCAAiC,EACjC,6BAA6B,CAC9B,CAAC;IACF,yBAAyB,EAAE,yBAAyB,CAAC;IACrD,mBAAmB,EAAE,uBAAuB,CAAC;CAC9C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,WAAW,CAwC1E;AA0CD;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,YAAY,EACtB,EACE,oBAAoB,EACpB,yBAAyB,GAC1B,EAAE,IAAI,CAAC,WAAW,EAAE,qBAAqB,CAAC,iBAgB5C"}
@@ -1,4 +1,4 @@
1
- import type { Messenger } from "@metamask/base-controller";
1
+ import { Messenger } from "@metamask/messenger";
2
2
  import type { CaveatSpecificationConstraint, PermissionSpecificationConstraint, PermissionControllerActions, SubjectMetadataControllerActions } from "@metamask/permission-controller";
3
3
  import { PermissionController, SubjectMetadataController } from "@metamask/permission-controller";
4
4
  import { SnapInterfaceController } from "@metamask/snaps-controllers";
@@ -10,9 +10,9 @@ import type { RestrictedMiddlewareHooks } from "./simulation.mjs";
10
10
  import type { RunSagaFunction } from "./store/index.mjs";
11
11
  export type RootControllerAllowedActions = SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions | PermissionControllerActions | ExecutionServiceActions | SubjectMetadataControllerActions;
12
12
  export type RootControllerAllowedEvents = SnapInterfaceControllerStateChangeEvent;
13
- export type RootControllerMessenger = Messenger<RootControllerAllowedActions, RootControllerAllowedEvents>;
13
+ export type RootControllerMessenger = Messenger<any, RootControllerAllowedActions, RootControllerAllowedEvents>;
14
14
  export type GetControllersOptions = {
15
- controllerMessenger: Messenger<any, any>;
15
+ controllerMessenger: Messenger<any, any, any>;
16
16
  hooks: RestrictedMiddlewareHooks;
17
17
  runSaga: RunSagaFunction;
18
18
  options: SimulationOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"controllers.d.mts","sourceRoot":"","sources":["../src/controllers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,6BAA6B,EAC7B,iCAAiC,EACjC,2BAA2B,EAC3B,gCAAgC,EACjC,wCAAwC;AACzC,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EAE1B,wCAAwC;AACzC,OAAO,EAAE,uBAAuB,EAAE,oCAAoC;AACtE,OAAO,KAAK,EACV,uBAAuB,EACvB,8BAA8B,EAC9B,qCAAqC,EACrC,uCAAuC,EACxC,oCAAoC;AAMrC,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,YAAY,EAAE,8BAA8B;AAK1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAkB;AACnD,OAAO,KAAK,EAAE,yBAAyB,EAAE,yBAAqB;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,0BAAgB;AAE/C,MAAM,MAAM,4BAA4B,GACpC,8BAA8B,GAC9B,qCAAqC,GACrC,2BAA2B,GAC3B,uBAAuB,GACvB,gCAAgC,CAAC;AAErC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EAAE,YAAY,EAAE,8BAA8B;AAK1D,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAkB;AACnD,OAAO,KAAK,EAAE,yBAAyB,EAAE,yBAAqB;AAC9D,OAAO,KAAK,EAAE,eAAe,EAAE,0BAAgB;AAE/C,MAAM,MAAM,4BAA4B,GACpC,8BAA8B,GAC9B,qCAAqC,GACrC,2BAA2B,GAC3B,uBAAuB,GACvB,gCAAgC,CAAC;AAErC,MAAM,MAAM,2BAA2B,GACrC,uCAAuC,CAAC;AAE1C,MAAM,MAAM,uBAAuB,GAAG,SAAS,CAC7C,GAAG,EACH,4BAA4B,EAC5B,2BAA2B,CAC5B,CAAC;AAEF,MAAM,MAAM,qBAAqB,GAAG;IAClC,mBAAmB,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;IAC9C,KAAK,EAAE,yBAAyB,CAAC;IACjC,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,iBAAiB,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,oBAAoB,EAAE,oBAAoB,CACxC,iCAAiC,EACjC,6BAA6B,CAC9B,CAAC;IACF,yBAAyB,EAAE,yBAAyB,CAAC;IACrD,mBAAmB,EAAE,uBAAuB,CAAC;CAC9C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,WAAW,CAwC1E;AA0CD;;;;;;;;GAQG;AACH,wBAAsB,YAAY,CAChC,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,YAAY,EACtB,EACE,oBAAoB,EACpB,yBAAyB,GAC1B,EAAE,IAAI,CAAC,WAAW,EAAE,qBAAqB,CAAC,iBAgB5C"}
@@ -1,3 +1,4 @@
1
+ import { Messenger } from "@metamask/messenger";
1
2
  import { PermissionController, SubjectMetadataController, SubjectType } from "@metamask/permission-controller";
2
3
  import { SnapInterfaceController } from "@metamask/snaps-controllers";
3
4
  import { caveatSpecifications as snapsCaveatsSpecifications, endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications, processSnapPermissions } from "@metamask/snaps-rpc-methods";
@@ -13,29 +14,31 @@ import { UNRESTRICTED_METHODS } from "./methods/constants.mjs";
13
14
  export function getControllers(options) {
14
15
  const { controllerMessenger } = options;
15
16
  const subjectMetadataController = new SubjectMetadataController({
16
- messenger: controllerMessenger.getRestricted({
17
- name: 'SubjectMetadataController',
18
- allowedActions: [],
19
- allowedEvents: [],
17
+ messenger: new Messenger({
18
+ namespace: 'SubjectMetadataController',
19
+ parent: controllerMessenger,
20
20
  }),
21
21
  subjectCacheLimit: 100,
22
22
  });
23
+ const interfaceControllerMessenger = new Messenger({
24
+ namespace: 'SnapInterfaceController',
25
+ parent: controllerMessenger,
26
+ });
27
+ controllerMessenger.delegate({
28
+ messenger: interfaceControllerMessenger,
29
+ actions: [
30
+ 'PhishingController:testOrigin',
31
+ 'ApprovalController:hasRequest',
32
+ 'ApprovalController:acceptRequest',
33
+ 'AccountsController:getAccountByAddress',
34
+ 'AccountsController:getSelectedMultichainAccount',
35
+ 'AccountsController:listMultichainAccounts',
36
+ 'MultichainAssetsController:getState',
37
+ ],
38
+ events: ['NotificationServicesController:notificationsListUpdated'],
39
+ });
23
40
  const interfaceController = new SnapInterfaceController({
24
- messenger: controllerMessenger.getRestricted({
25
- name: 'SnapInterfaceController',
26
- allowedActions: [
27
- 'PhishingController:testOrigin',
28
- 'ApprovalController:hasRequest',
29
- 'ApprovalController:acceptRequest',
30
- 'AccountsController:getAccountByAddress',
31
- 'AccountsController:getSelectedMultichainAccount',
32
- 'AccountsController:listMultichainAccounts',
33
- 'MultichainAssetsController:getState',
34
- ],
35
- allowedEvents: [
36
- 'NotificationServicesController:notificationsListUpdated',
37
- ],
38
- }),
41
+ messenger: interfaceControllerMessenger,
39
42
  });
40
43
  const permissionController = getPermissionController(options);
41
44
  return {
@@ -55,20 +58,24 @@ export function getControllers(options) {
55
58
  function getPermissionController(options) {
56
59
  const { controllerMessenger } = options;
57
60
  const permissionSpecifications = getPermissionSpecifications(options);
61
+ const messenger = new Messenger({
62
+ namespace: 'PermissionController',
63
+ parent: controllerMessenger,
64
+ });
65
+ controllerMessenger.delegate({
66
+ messenger,
67
+ actions: [
68
+ `ApprovalController:addRequest`,
69
+ `ApprovalController:hasRequest`,
70
+ `ApprovalController:acceptRequest`,
71
+ `ApprovalController:rejectRequest`,
72
+ `SnapController:getPermitted`,
73
+ `SnapController:install`,
74
+ `SubjectMetadataController:getSubjectMetadata`,
75
+ ],
76
+ });
58
77
  return new PermissionController({
59
- messenger: controllerMessenger.getRestricted({
60
- name: 'PermissionController',
61
- allowedActions: [
62
- `ApprovalController:addRequest`,
63
- `ApprovalController:hasRequest`,
64
- `ApprovalController:acceptRequest`,
65
- `ApprovalController:rejectRequest`,
66
- `SnapController:getPermitted`,
67
- `SnapController:install`,
68
- `SubjectMetadataController:getSubjectMetadata`,
69
- ],
70
- allowedEvents: [],
71
- }),
78
+ messenger,
72
79
  caveatSpecifications: {
73
80
  ...snapsCaveatsSpecifications,
74
81
  ...snapsEndowmentCaveatSpecifications,
@@ -1 +1 @@
1
- {"version":3,"file":"controllers.mjs","sourceRoot":"","sources":["../src/controllers.ts"],"names":[],"mappings":"AAOA,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,WAAW,EACZ,wCAAwC;AACzC,OAAO,EAAE,uBAAuB,EAAE,oCAAoC;AAOtE,OAAO,EACL,oBAAoB,IAAI,0BAA0B,EAClD,6BAA6B,IAAI,kCAAkC,EACnE,sBAAsB,EACvB,oCAAoC;AAGrC,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,OAAO,EAAE,2BAA2B,EAAE,4BAAkB;AACxD,OAAO,EAAE,oBAAoB,EAAE,gCAA4B;AAoC3D;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,OAA8B;IAC3D,MAAM,EAAE,mBAAmB,EAAE,GAAG,OAAO,CAAC;IACxC,MAAM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AAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAc,EACd,QAAsB,EACtB,EACE,oBAAoB,EACpB,yBAAyB,GACgB;IAE3C,yBAAyB,CAAC,kBAAkB,CAAC;QAC3C,MAAM,EAAE,MAAM;QACd,WAAW,EAAE,WAAW,CAAC,IAAI;KAC9B,CAAC,CAAC;IAEH,MAAM,mBAAmB,GAAG,sBAAsB,CAChD,WAAW,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CACzC,CAAC;IAEF,oBAAoB,CAAC,gBAAgB,CAAC;QACpC,mBAAmB;QACnB,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;QAC3B,2BAA2B,EAAE,KAAK;KACnC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type { Messenger } from '@metamask/base-controller';\nimport type {\n CaveatSpecificationConstraint,\n PermissionSpecificationConstraint,\n PermissionControllerActions,\n SubjectMetadataControllerActions,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport { SnapInterfaceController } from '@metamask/snaps-controllers';\nimport type {\n ExecutionServiceActions,\n SnapInterfaceControllerActions,\n SnapInterfaceControllerAllowedActions,\n SnapInterfaceControllerStateChangeEvent,\n} from '@metamask/snaps-controllers';\nimport {\n caveatSpecifications as snapsCaveatsSpecifications,\n endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications,\n processSnapPermissions,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { SnapManifest } from '@metamask/snaps-utils';\nimport { getSafeJson } from '@metamask/utils';\n\nimport { getPermissionSpecifications } from './methods';\nimport { UNRESTRICTED_METHODS } from './methods/constants';\nimport type { SimulationOptions } from './options';\nimport type { RestrictedMiddlewareHooks } from './simulation';\nimport type { RunSagaFunction } from './store';\n\nexport type RootControllerAllowedActions =\n | SnapInterfaceControllerActions\n | SnapInterfaceControllerAllowedActions\n | PermissionControllerActions\n | ExecutionServiceActions\n | SubjectMetadataControllerActions;\n\nexport type RootControllerAllowedEvents =\n SnapInterfaceControllerStateChangeEvent;\n\nexport type RootControllerMessenger = Messenger<\n RootControllerAllowedActions,\n RootControllerAllowedEvents\n>;\n\nexport type GetControllersOptions = {\n controllerMessenger: Messenger<any, any>;\n hooks: RestrictedMiddlewareHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\nexport type Controllers = {\n permissionController: PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n >;\n subjectMetadataController: SubjectMetadataController;\n interfaceController: SnapInterfaceController;\n};\n\n/**\n * Get the controllers for the Snap.\n *\n * @param options - The options.\n * @returns The controllers for the Snap.\n */\nexport function getControllers(options: GetControllersOptions): Controllers {\n const { controllerMessenger } = options;\n const subjectMetadataController = new SubjectMetadataController({\n messenger: controllerMessenger.getRestricted({\n name: 'SubjectMetadataController',\n allowedActions: [],\n allowedEvents: [],\n }),\n subjectCacheLimit: 100,\n });\n\n const interfaceController = new SnapInterfaceController({\n messenger: controllerMessenger.getRestricted({\n name: 'SnapInterfaceController',\n allowedActions: [\n 'PhishingController:testOrigin',\n 'ApprovalController:hasRequest',\n 'ApprovalController:acceptRequest',\n 'AccountsController:getAccountByAddress',\n 'AccountsController:getSelectedMultichainAccount',\n 'AccountsController:listMultichainAccounts',\n 'MultichainAssetsController:getState',\n ],\n allowedEvents: [\n 'NotificationServicesController:notificationsListUpdated',\n ],\n }),\n });\n\n const permissionController = getPermissionController(options);\n\n return {\n permissionController,\n subjectMetadataController,\n interfaceController,\n };\n}\n\n/**\n * Get the permission controller for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.options - Miscellaneous options.\n * @returns The permission controller for the Snap.\n */\nfunction getPermissionController(options: GetControllersOptions) {\n const { controllerMessenger } = options;\n const permissionSpecifications = getPermissionSpecifications(options);\n return new PermissionController({\n messenger: controllerMessenger.getRestricted({\n name: 'PermissionController',\n allowedActions: [\n `ApprovalController:addRequest`,\n `ApprovalController:hasRequest`,\n `ApprovalController:acceptRequest`,\n `ApprovalController:rejectRequest`,\n `SnapController:getPermitted`,\n `SnapController:install`,\n `SubjectMetadataController:getSubjectMetadata`,\n ],\n allowedEvents: [],\n }),\n caveatSpecifications: {\n ...snapsCaveatsSpecifications,\n ...snapsEndowmentCaveatSpecifications,\n },\n permissionSpecifications,\n unrestrictedMethods: UNRESTRICTED_METHODS,\n });\n}\n\n/**\n * Register the Snap. This sets up the Snap's permissions and subject metadata.\n *\n * @param snapId - The ID of the Snap to install.\n * @param manifest - The parsed manifest.\n * @param controllers - The controllers for the Snap.\n * @param controllers.permissionController - The permission controller.\n * @param controllers.subjectMetadataController - The subject metadata controller.\n */\nexport async function registerSnap(\n snapId: SnapId,\n manifest: SnapManifest,\n {\n permissionController,\n subjectMetadataController,\n }: Omit<Controllers, 'interfaceController'>,\n) {\n subjectMetadataController.addSubjectMetadata({\n origin: snapId,\n subjectType: SubjectType.Snap,\n });\n\n const approvedPermissions = processSnapPermissions(\n getSafeJson(manifest.initialPermissions),\n );\n\n permissionController.grantPermissions({\n approvedPermissions,\n subject: { origin: snapId },\n preserveExistingPermissions: false,\n });\n}\n"]}
1
+ {"version":3,"file":"controllers.mjs","sourceRoot":"","sources":["../src/controllers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,4BAA4B;AAOhD,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,WAAW,EACZ,wCAAwC;AACzC,OAAO,EAAE,uBAAuB,EAAE,oCAAoC;AAOtE,OAAO,EACL,oBAAoB,IAAI,0BAA0B,EAClD,6BAA6B,IAAI,kCAAkC,EACnE,sBAAsB,EACvB,oCAAoC;AAGrC,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAE9C,OAAO,EAAE,2BAA2B,EAAE,4BAAkB;AACxD,OAAO,EAAE,oBAAoB,EAAE,gCAA4B;AAq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,+BAA+B;YAC/B,+BAA+B;YAC/B,kCAAkC;YAClC,kCAAkC;YAClC,6BAA6B;YAC7B,wBAAwB;YACxB,8CAA8C;SAC/C;KACF,CAAC,CAAC;IAEH,OAAO,IAAI,oBAAoB,CAAC;QAC9B,SAAS;QACT,oBAAoB,EAAE;YACpB,GAAG,0BAA0B;YAC7B,GAAG,kCAAkC;SACtC;QACD,wBAAwB;QACxB,mBAAmB,EAAE,oBAAoB;KAC1C,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,MAAc,EACd,QAAsB,EACtB,EACE,oBAAoB,EACpB,yBAAyB,GACgB;IAE3C,yBAAyB,CAAC,kBAAkB,CAAC;QAC3C,MAAM,EAAE,MAAM;QACd,WAAW,EAAE,WAAW,CAAC,IAAI;KAC9B,CAAC,CAAC;IAEH,MAAM,mBAAmB,GAAG,sBAAsB,CAChD,WAAW,CAAC,QAAQ,CAAC,kBAAkB,CAAC,CACzC,CAAC;IAEF,oBAAoB,CAAC,gBAAgB,CAAC;QACpC,mBAAmB;QACnB,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;QAC3B,2BAA2B,EAAE,KAAK;KACnC,CAAC,CAAC;AACL,CAAC","sourcesContent":["import { Messenger } from '@metamask/messenger';\nimport type {\n CaveatSpecificationConstraint,\n PermissionSpecificationConstraint,\n PermissionControllerActions,\n SubjectMetadataControllerActions,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport { SnapInterfaceController } from '@metamask/snaps-controllers';\nimport type {\n ExecutionServiceActions,\n SnapInterfaceControllerActions,\n SnapInterfaceControllerAllowedActions,\n SnapInterfaceControllerStateChangeEvent,\n} from '@metamask/snaps-controllers';\nimport {\n caveatSpecifications as snapsCaveatsSpecifications,\n endowmentCaveatSpecifications as snapsEndowmentCaveatSpecifications,\n processSnapPermissions,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport type { SnapManifest } from '@metamask/snaps-utils';\nimport { getSafeJson } from '@metamask/utils';\n\nimport { getPermissionSpecifications } from './methods';\nimport { UNRESTRICTED_METHODS } from './methods/constants';\nimport type { SimulationOptions } from './options';\nimport type { RestrictedMiddlewareHooks } from './simulation';\nimport type { RunSagaFunction } from './store';\n\nexport type RootControllerAllowedActions =\n | SnapInterfaceControllerActions\n | SnapInterfaceControllerAllowedActions\n | PermissionControllerActions\n | ExecutionServiceActions\n | SubjectMetadataControllerActions;\n\nexport type RootControllerAllowedEvents =\n SnapInterfaceControllerStateChangeEvent;\n\nexport type RootControllerMessenger = Messenger<\n any,\n RootControllerAllowedActions,\n RootControllerAllowedEvents\n>;\n\nexport type GetControllersOptions = {\n controllerMessenger: Messenger<any, any, any>;\n hooks: RestrictedMiddlewareHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\nexport type Controllers = {\n permissionController: PermissionController<\n PermissionSpecificationConstraint,\n CaveatSpecificationConstraint\n >;\n subjectMetadataController: SubjectMetadataController;\n interfaceController: SnapInterfaceController;\n};\n\n/**\n * Get the controllers for the Snap.\n *\n * @param options - The options.\n * @returns The controllers for the Snap.\n */\nexport function getControllers(options: GetControllersOptions): Controllers {\n const { controllerMessenger } = options;\n const subjectMetadataController = new SubjectMetadataController({\n messenger: new Messenger({\n namespace: 'SubjectMetadataController',\n parent: controllerMessenger,\n }),\n subjectCacheLimit: 100,\n });\n\n const interfaceControllerMessenger = new Messenger({\n namespace: 'SnapInterfaceController',\n parent: controllerMessenger,\n });\n\n controllerMessenger.delegate({\n messenger: interfaceControllerMessenger,\n actions: [\n 'PhishingController:testOrigin',\n 'ApprovalController:hasRequest',\n 'ApprovalController:acceptRequest',\n 'AccountsController:getAccountByAddress',\n 'AccountsController:getSelectedMultichainAccount',\n 'AccountsController:listMultichainAccounts',\n 'MultichainAssetsController:getState',\n ],\n events: ['NotificationServicesController:notificationsListUpdated'],\n });\n\n const interfaceController = new SnapInterfaceController({\n messenger: interfaceControllerMessenger,\n });\n\n const permissionController = getPermissionController(options);\n\n return {\n permissionController,\n subjectMetadataController,\n interfaceController,\n };\n}\n\n/**\n * Get the permission controller for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.options - Miscellaneous options.\n * @returns The permission controller for the Snap.\n */\nfunction getPermissionController(options: GetControllersOptions) {\n const { controllerMessenger } = options;\n const permissionSpecifications = getPermissionSpecifications(options);\n const messenger = new Messenger({\n namespace: 'PermissionController',\n parent: controllerMessenger,\n });\n\n controllerMessenger.delegate({\n messenger,\n actions: [\n `ApprovalController:addRequest`,\n `ApprovalController:hasRequest`,\n `ApprovalController:acceptRequest`,\n `ApprovalController:rejectRequest`,\n `SnapController:getPermitted`,\n `SnapController:install`,\n `SubjectMetadataController:getSubjectMetadata`,\n ],\n });\n\n return new PermissionController({\n messenger,\n caveatSpecifications: {\n ...snapsCaveatsSpecifications,\n ...snapsEndowmentCaveatSpecifications,\n },\n permissionSpecifications,\n unrestrictedMethods: UNRESTRICTED_METHODS,\n });\n}\n\n/**\n * Register the Snap. This sets up the Snap's permissions and subject metadata.\n *\n * @param snapId - The ID of the Snap to install.\n * @param manifest - The parsed manifest.\n * @param controllers - The controllers for the Snap.\n * @param controllers.permissionController - The permission controller.\n * @param controllers.subjectMetadataController - The subject metadata controller.\n */\nexport async function registerSnap(\n snapId: SnapId,\n manifest: SnapManifest,\n {\n permissionController,\n subjectMetadataController,\n }: Omit<Controllers, 'interfaceController'>,\n) {\n subjectMetadataController.addSubjectMetadata({\n origin: snapId,\n subjectType: SubjectType.Snap,\n });\n\n const approvedPermissions = processSnapPermissions(\n getSafeJson(manifest.initialPermissions),\n );\n\n permissionController.grantPermissions({\n approvedPermissions,\n subject: { origin: snapId },\n preserveExistingPermissions: false,\n });\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.registerActions = exports.getPermittedHooks = exports.getRestrictedHooks = exports.installSnap = void 0;
4
- const base_controller_1 = require("@metamask/base-controller");
5
4
  const json_rpc_middleware_stream_1 = require("@metamask/json-rpc-middleware-stream");
5
+ const messenger_1 = require("@metamask/messenger");
6
6
  const phishing_controller_1 = require("@metamask/phishing-controller");
7
7
  const node_1 = require("@metamask/snaps-controllers/node");
8
8
  const snaps_rpc_methods_1 = require("@metamask/snaps-rpc-methods");
@@ -44,7 +44,9 @@ async function installSnap(snapId, { executionService, executionServiceOptions,
44
44
  const snapFiles = await (0, node_1.fetchSnap)(snapId, location);
45
45
  // Create Redux store.
46
46
  const { store, runSaga } = (0, store_1.createStore)(options);
47
- const controllerMessenger = new base_controller_1.Messenger();
47
+ const controllerMessenger = new messenger_1.Messenger({
48
+ namespace: messenger_1.MOCK_ANY_NAMESPACE,
49
+ });
48
50
  registerActions(controllerMessenger, runSaga, options, snapId);
49
51
  // Set up controllers and JSON-RPC stack.
50
52
  const restrictedHooks = getRestrictedHooks(options);
@@ -67,10 +69,9 @@ async function installSnap(snapId, { executionService, executionServiceOptions,
67
69
  const ExecutionService = executionService ?? node_1.NodeThreadExecutionService;
68
70
  const service = new ExecutionService({
69
71
  ...executionServiceOptions,
70
- messenger: controllerMessenger.getRestricted({
71
- name: 'ExecutionService',
72
- allowedActions: [],
73
- allowedEvents: [],
72
+ messenger: new messenger_1.Messenger({
73
+ namespace: 'ExecutionService',
74
+ parent: controllerMessenger,
74
75
  }),
75
76
  setupSnapProvider: (_snapId, rpcStream) => {
76
77
  const mux = (0, node_1.setupMultiplex)(rpcStream, 'snapStream');
@@ -1 +1 @@
1
- {"version":3,"file":"simulation.cjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":";;;AAIA,+DAAsD;AACtD,qFAA0E;AAE1E,uEAA2E;AAE3E,2DAK0C;AAC1C,mEAAoE;AAcpE,uDAAiD;AAGjD,qDAA2C;AAE3C,gDAA4C;AAG5C,mDAA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AAE,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;YACf,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;YACvC,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAAE,CACH;KACF,CAAC,CACH,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,+BAA+B,EAC/B,CAAC,IAAI,EAAE,EAAE;QACP;;;;;WAKG;QACH,QAAQ,CAAC,CAAC,uBAAuB;YAC/B,MAAM,gBAAgB,GAAc,MAAM,IAAA,gBAAM,EAAC,2BAAmB,CAAC,CAAC;YACtE,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,gBAAgB,GAA0B,OAAO,CACrD,uBAAuB,CACxB,CAAC,MAAM,EAAE,CAAC;QACX,OAAO,CACL,gBAAgB,EAAE,IAAI,KAAK,yCAAqB,CAAC,OAAO;YACxD,gBAAgB,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,CAClC,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,kCAAkC,EAClC,KAAK,EAAE,GAAW,EAAE,KAAc,EAAE,EAAE;QACpC,MAAM,OAAO,CAAC,2BAAe,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAElD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;AACJ,CAAC;AAxGD,0CAwGC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { Messenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { PhishingDetectorResultType } from '@metamask/phishing-controller';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n TrackEventParams,\n AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n InterfaceContext,\n SnapId,\n EntropySource,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles, Snap } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { CaipAssetType, Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport type { SnapHelpers } from './helpers';\nimport { getHelpers } from './helpers';\nimport { resolveWithSaga } from './interface';\nimport { asyncResolve, getEndowments } from './methods';\nimport {\n getPermittedClearSnapStateMethodImplementation,\n getPermittedGetSnapStateMethodImplementation,\n getPermittedUpdateSnapStateMethodImplementation,\n getGetEntropySourcesImplementation,\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n} from './methods/hooks';\nimport { getGetMnemonicSeedImplementation } from './methods/hooks/get-mnemonic-seed';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { Interface, RunSagaFunction, Store } from './store';\nimport { createStore, getCurrentInterface } from './store';\nimport { addSnapMetadataToAccount } from './utils/account';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService<unknown>>,\n> =\n ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof AbstractExecutionService>;\n controllerMessenger: Messenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the mnemonic from.\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns the seed derived from the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the seed from.\n * @returns The seed.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n\n /**\n * A hook that returns metadata about a given Snap.\n *\n * @param snapId - The ID of a Snap.\n * @returns The metadata for the given Snap.\n */\n getSnap: (snapId: string) => Snap;\n};\n\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that gets whether the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * A hook that returns the entropy sources available to the Snap.\n *\n * @returns The entropy sources available to the Snap.\n */\n getEntropySources: () => EntropySource[];\n\n /**\n * A hook that returns a promise that resolves once the extension is unlocked.\n *\n * @param shouldShowUnlockRequest - Whether to show the unlock request.\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * A hook that returns whether the client is active or not.\n *\n * @returns A boolean flag signaling whether the client is opened.\n */\n getIsActive: () => boolean;\n\n /**\n * A hook that returns the Snap's auxiliary file for the given path. This hook\n * is bound to the Snap ID.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that gets the state of the Snap. This hook is bound to the Snap ID.\n *\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * A hook that updates the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n */\n updateSnapState: (\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n\n /**\n * A hook that clears the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n */\n clearSnapState: (encrypted: boolean) => Promise<void>;\n\n /**\n * A hook that creates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param content - The content of the interface.\n * @param context - The context of the interface.\n * @returns The ID of the created interface.\n */\n createInterface: (content: Component, context?: InterfaceContext) => string;\n\n /**\n * A hook that updates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to update.\n * @param content - The content of the interface.\n */\n updateInterface: (id: string, content: Component) => void;\n\n /**\n * A hook that gets the state of an interface for the Snap. This hook is bound\n * to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The state of the interface.\n */\n getInterfaceState: (id: string) => InterfaceState;\n\n /**\n * A hook that gets the context of an interface for the Snap. This hook is\n * bound to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The context of the interface.\n */\n getInterfaceContext: (id: string) => InterfaceContext | null;\n\n /**\n * A hook that resolves an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to resolve.\n * @param value - The value to resolve the interface with.\n */\n resolveInterface: (id: string, value: Json) => Promise<void>;\n\n /**\n * A hook that gets the Snap's metadata.\n *\n * @param snapId - The ID of the Snap to get.\n * @returns The Snap's metadata.\n */\n getSnap(snapId: string): Snap;\n\n /**\n * A hook that tracks an error.\n *\n * @param error - The error object containing error details and properties.\n */\n trackError(error: Error): void;\n\n /**\n * A hook that tracks an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent(event: TrackEventParams['event']): void;\n\n /**\n * A hook that starts a performance trace.\n *\n * @param request - The trace request object containing trace details.\n */\n startTrace(request: TraceRequest): TraceContext;\n\n /**\n * A hook that ends a performance trace.\n *\n * @param request - The trace request object containing trace details.\n * @returns The trace data.\n */\n endTrace(request: EndTraceRequest): void;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The installed Snap object.\n * @template Service - The type of the execution service.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap & SnapHelpers> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new Messenger<any, any>();\n\n registerActions(controllerMessenger, runSaga, options, snapId);\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options);\n const permittedHooks = getPermittedHooks(\n snapId,\n snapFiles,\n controllerMessenger,\n runSaga,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n restrictedHooks,\n permittedHooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: controllerMessenger.getRestricted({\n name: 'ExecutionService',\n allowedActions: [],\n allowedEvents: [],\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n });\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n const helpers = getHelpers({\n snapId,\n store,\n controllerMessenger,\n runSaga,\n executionService: service,\n options,\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n ...helpers,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getMnemonicSeed: getGetMnemonicSeedImplementation(\n options.secretRecoveryPhrase,\n ),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n getSnap: getGetSnapImplementation(true),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param snapId - The ID of the Snap.\n * @param snapFiles - The fetched Snap files.\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n snapId: SnapId,\n snapFiles: FetchedSnapFiles,\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n hasPermission: () => true,\n getUnlockPromise: asyncResolve(),\n getIsLocked: () => false,\n getIsActive: () => true,\n\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n\n createInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n getInterfaceContext: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).context,\n resolveInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:resolveInterface',\n snapId,\n ...args,\n ),\n\n getEntropySources: getGetEntropySourcesImplementation(),\n getSnapState: getPermittedGetSnapStateMethodImplementation(runSaga),\n updateSnapState: getPermittedUpdateSnapStateMethodImplementation(runSaga),\n clearSnapState: getPermittedClearSnapStateMethodImplementation(runSaga),\n\n getSnap: getGetSnapImplementation(true),\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @param options - The simulation options.\n * @param snapId - The ID of the Snap.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: PhishingDetectorResultType.All }),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getAccountByAddress',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n (address) => {\n const matchingAccount = options.accounts.find(\n (account) => address === account.address,\n );\n\n if (!matchingAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(matchingAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getSelectedMultichainAccount',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n () => {\n const selectedAccount = options.accounts.find(\n (account) => account.selected,\n );\n\n if (!selectedAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(selectedAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:listMultichainAccounts',\n\n () =>\n // @ts-expect-error - These are partial accounts with only the necessary\n // data used by the interface controller.\n options.accounts.map((account) =>\n addSnapMetadataToAccount(account, snapId),\n ),\n );\n\n controllerMessenger.registerActionHandler(\n 'MultichainAssetsController:getState',\n () => ({\n // @ts-expect-error - These are partial assets with only the\n // necessary data used by the interface controller.\n assetsMetadata: options.assets,\n accountsAssets: options.accounts.reduce<Record<string, CaipAssetType[]>>(\n (acc, account) => {\n acc[account.id] = account.assets ?? [];\n return acc;\n },\n {},\n ),\n }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n}\n"]}
1
+ {"version":3,"file":"simulation.cjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":";;;AAAA,qFAA0E;AAQ1E,mDAAoE;AACpE,uEAA2E;AAE3E,2DAK0C;AAC1C,mEAAoE;AAcpE,uDAAiD;AAGjD,qDAA2C;AAE3C,gDAA4C;AAG5C,mDAA6D;AAC7D,uCAAsC;AAEtC,2CAAuC;AACvC,+CAA8C;AAC9C,iDAAwD;AACxD,qDAWyB;AACzB,6EAAqF;AACrF,uDAAmD;AAEnD,2CAAuC;AAEvC,6CAA2D;AAC3D,iDAA2D;AAmQ3D;;;;;;;;;;;;;;GAcG;AACI,KAAK,UAAU,WAAW,CAK/B,MAAc,EACd,EACE,gBAAgB,EAChB,uBAAuB,EACvB,OAAO,EAAE,UAAU,GAAG,EAAE,MACgB,EAAE;IAE5C,MAAM,OAAO,GAAG,IAAA,oBAAU,EAAC,UAAU,CAAC,CAAC;IAEvC,oBAAoB;IACpB,MAAM,QAAQ,GAAG,IAAA,yBAAkB,EAAC,MAAM,EAAE;QAC1C,UAAU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AO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,gBAAgB,GAA0B,OAAO,CACrD,uBAAuB,CACxB,CAAC,MAAM,EAAE,CAAC;QACX,OAAO,CACL,gBAAgB,EAAE,IAAI,KAAK,yCAAqB,CAAC,OAAO;YACxD,gBAAgB,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,CAClC,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,kCAAkC,EAClC,KAAK,EAAE,GAAW,EAAE,KAAc,EAAE,EAAE;QACpC,MAAM,OAAO,CAAC,2BAAe,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAElD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;AACJ,CAAC;AAxGD,0CAwGC","sourcesContent":["import { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n ActionConstraint,\n EventConstraint,\n MockAnyNamespace,\n NamespacedName,\n} from '@metamask/messenger';\nimport { MOCK_ANY_NAMESPACE, Messenger } from '@metamask/messenger';\nimport { PhishingDetectorResultType } from '@metamask/phishing-controller';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n TrackEventParams,\n AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n InterfaceContext,\n SnapId,\n EntropySource,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles, Snap } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { CaipAssetType, Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport type { SnapHelpers } from './helpers';\nimport { getHelpers } from './helpers';\nimport { resolveWithSaga } from './interface';\nimport { asyncResolve, getEndowments } from './methods';\nimport {\n getPermittedClearSnapStateMethodImplementation,\n getPermittedGetSnapStateMethodImplementation,\n getPermittedUpdateSnapStateMethodImplementation,\n getGetEntropySourcesImplementation,\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n} from './methods/hooks';\nimport { getGetMnemonicSeedImplementation } from './methods/hooks/get-mnemonic-seed';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { Interface, RunSagaFunction, Store } from './store';\nimport { createStore, getCurrentInterface } from './store';\nimport { addSnapMetadataToAccount } from './utils/account';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService<unknown>>,\n> =\n ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof AbstractExecutionService>;\n controllerMessenger: Messenger<\n NamespacedName,\n ActionConstraint,\n EventConstraint\n >;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the mnemonic from.\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns the seed derived from the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the seed from.\n * @returns The seed.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n\n /**\n * A hook that returns metadata about a given Snap.\n *\n * @param snapId - The ID of a Snap.\n * @returns The metadata for the given Snap.\n */\n getSnap: (snapId: string) => Snap;\n};\n\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that gets whether the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * A hook that returns the entropy sources available to the Snap.\n *\n * @returns The entropy sources available to the Snap.\n */\n getEntropySources: () => EntropySource[];\n\n /**\n * A hook that returns a promise that resolves once the extension is unlocked.\n *\n * @param shouldShowUnlockRequest - Whether to show the unlock request.\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * A hook that returns whether the client is active or not.\n *\n * @returns A boolean flag signaling whether the client is opened.\n */\n getIsActive: () => boolean;\n\n /**\n * A hook that returns the Snap's auxiliary file for the given path. This hook\n * is bound to the Snap ID.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that gets the state of the Snap. This hook is bound to the Snap ID.\n *\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * A hook that updates the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n */\n updateSnapState: (\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n\n /**\n * A hook that clears the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n */\n clearSnapState: (encrypted: boolean) => Promise<void>;\n\n /**\n * A hook that creates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param content - The content of the interface.\n * @param context - The context of the interface.\n * @returns The ID of the created interface.\n */\n createInterface: (content: Component, context?: InterfaceContext) => string;\n\n /**\n * A hook that updates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to update.\n * @param content - The content of the interface.\n */\n updateInterface: (id: string, content: Component) => void;\n\n /**\n * A hook that gets the state of an interface for the Snap. This hook is bound\n * to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The state of the interface.\n */\n getInterfaceState: (id: string) => InterfaceState;\n\n /**\n * A hook that gets the context of an interface for the Snap. This hook is\n * bound to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The context of the interface.\n */\n getInterfaceContext: (id: string) => InterfaceContext | null;\n\n /**\n * A hook that resolves an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to resolve.\n * @param value - The value to resolve the interface with.\n */\n resolveInterface: (id: string, value: Json) => Promise<void>;\n\n /**\n * A hook that gets the Snap's metadata.\n *\n * @param snapId - The ID of the Snap to get.\n * @returns The Snap's metadata.\n */\n getSnap(snapId: string): Snap;\n\n /**\n * A hook that tracks an error.\n *\n * @param error - The error object containing error details and properties.\n */\n trackError(error: Error): void;\n\n /**\n * A hook that tracks an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent(event: TrackEventParams['event']): void;\n\n /**\n * A hook that starts a performance trace.\n *\n * @param request - The trace request object containing trace details.\n */\n startTrace(request: TraceRequest): TraceContext;\n\n /**\n * A hook that ends a performance trace.\n *\n * @param request - The trace request object containing trace details.\n * @returns The trace data.\n */\n endTrace(request: EndTraceRequest): void;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The installed Snap object.\n * @template Service - The type of the execution service.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap & SnapHelpers> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new Messenger<MockAnyNamespace, any, any>({\n namespace: MOCK_ANY_NAMESPACE,\n });\n\n registerActions(controllerMessenger, runSaga, options, snapId);\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options);\n const permittedHooks = getPermittedHooks(\n snapId,\n snapFiles,\n controllerMessenger,\n runSaga,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n restrictedHooks,\n permittedHooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: new Messenger({\n namespace: 'ExecutionService',\n parent: controllerMessenger,\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n });\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n const helpers = getHelpers({\n snapId,\n store,\n controllerMessenger,\n runSaga,\n executionService: service,\n options,\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n ...helpers,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getMnemonicSeed: getGetMnemonicSeedImplementation(\n options.secretRecoveryPhrase,\n ),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n getSnap: getGetSnapImplementation(true),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param snapId - The ID of the Snap.\n * @param snapFiles - The fetched Snap files.\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n snapId: SnapId,\n snapFiles: FetchedSnapFiles,\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n hasPermission: () => true,\n getUnlockPromise: asyncResolve(),\n getIsLocked: () => false,\n getIsActive: () => true,\n\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n\n createInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n getInterfaceContext: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).context,\n resolveInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:resolveInterface',\n snapId,\n ...args,\n ),\n\n getEntropySources: getGetEntropySourcesImplementation(),\n getSnapState: getPermittedGetSnapStateMethodImplementation(runSaga),\n updateSnapState: getPermittedUpdateSnapStateMethodImplementation(runSaga),\n clearSnapState: getPermittedClearSnapStateMethodImplementation(runSaga),\n\n getSnap: getGetSnapImplementation(true),\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @param options - The simulation options.\n * @param snapId - The ID of the Snap.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: PhishingDetectorResultType.All }),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getAccountByAddress',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n (address) => {\n const matchingAccount = options.accounts.find(\n (account) => address === account.address,\n );\n\n if (!matchingAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(matchingAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getSelectedMultichainAccount',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n () => {\n const selectedAccount = options.accounts.find(\n (account) => account.selected,\n );\n\n if (!selectedAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(selectedAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:listMultichainAccounts',\n\n () =>\n // @ts-expect-error - These are partial accounts with only the necessary\n // data used by the interface controller.\n options.accounts.map((account) =>\n addSnapMetadataToAccount(account, snapId),\n ),\n );\n\n controllerMessenger.registerActionHandler(\n 'MultichainAssetsController:getState',\n () => ({\n // @ts-expect-error - These are partial assets with only the\n // necessary data used by the interface controller.\n assetsMetadata: options.assets,\n accountsAssets: options.accounts.reduce<Record<string, CaipAssetType[]>>(\n (acc, account) => {\n acc[account.id] = account.assets ?? [];\n return acc;\n },\n {},\n ),\n }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n}\n"]}
@@ -1,6 +1,6 @@
1
- import type { ActionConstraint, EventConstraint } from "@metamask/base-controller";
2
- import { Messenger } from "@metamask/base-controller";
3
1
  import type { CryptographicFunctions } from "@metamask/key-tree";
2
+ import type { ActionConstraint, EventConstraint, NamespacedName } from "@metamask/messenger";
3
+ import { Messenger } from "@metamask/messenger";
4
4
  import type { AbstractExecutionService } from "@metamask/snaps-controllers";
5
5
  import type { TrackEventParams, AuxiliaryFileEncoding, Component, InterfaceState, InterfaceContext, SnapId, EntropySource, TraceRequest, EndTraceRequest, TraceContext } from "@metamask/snaps-sdk";
6
6
  import type { FetchedSnapFiles, Snap } from "@metamask/snaps-utils";
@@ -40,7 +40,7 @@ export type InstalledSnap = {
40
40
  snapId: SnapId;
41
41
  store: Store;
42
42
  executionService: InstanceType<typeof AbstractExecutionService>;
43
- controllerMessenger: Messenger<ActionConstraint, EventConstraint>;
43
+ controllerMessenger: Messenger<NamespacedName, ActionConstraint, EventConstraint>;
44
44
  runSaga: RunSagaFunction;
45
45
  };
46
46
  export type RestrictedMiddlewareHooks = {
@@ -1 +1 @@
1
- {"version":3,"file":"simulation.d.cts","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAChB,eAAe,EAChB,kCAAkC;AACnC,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAEtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B;AAEjE,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAQ5E,OAAO,KAAK,EACV,gBAAgB,EAChB,qBAAqB,EACrB,SAAS,EACT,cAAc,EACd,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B,uBAAuB,EACvB,OAAO,EAAE,UAAe,GACzB,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM,GAC3C,OAAO,CAAC,aAAa,GAAG,WAAW,CAAC,CAkGtC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,iBAAiB,GACzB,yBAAyB,CAU3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,gBAAgB,EAC3B,mBAAmB,EAAE,uBAAuB,EAC5C,OAAO,EAAE,eAAe,GACvB,wBAAwB,CAoD1B;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,mBAAmB,EAAE,uBAAuB,EAC5C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,MAAM,QAoGf"}
@@ -1,6 +1,6 @@
1
- import type { ActionConstraint, EventConstraint } from "@metamask/base-controller";
2
- import { Messenger } from "@metamask/base-controller";
3
1
  import type { CryptographicFunctions } from "@metamask/key-tree";
2
+ import type { ActionConstraint, EventConstraint, NamespacedName } from "@metamask/messenger";
3
+ import { Messenger } from "@metamask/messenger";
4
4
  import type { AbstractExecutionService } from "@metamask/snaps-controllers";
5
5
  import type { TrackEventParams, AuxiliaryFileEncoding, Component, InterfaceState, InterfaceContext, SnapId, EntropySource, TraceRequest, EndTraceRequest, TraceContext } from "@metamask/snaps-sdk";
6
6
  import type { FetchedSnapFiles, Snap } from "@metamask/snaps-utils";
@@ -40,7 +40,7 @@ export type InstalledSnap = {
40
40
  snapId: SnapId;
41
41
  store: Store;
42
42
  executionService: InstanceType<typeof AbstractExecutionService>;
43
- controllerMessenger: Messenger<ActionConstraint, EventConstraint>;
43
+ controllerMessenger: Messenger<NamespacedName, ActionConstraint, EventConstraint>;
44
44
  runSaga: RunSagaFunction;
45
45
  };
46
46
  export type RestrictedMiddlewareHooks = {
@@ -1 +1 @@
1
- {"version":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OAIG;IACH,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,YAAY,CAAC;IAEhD;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,WAAW,CAC/B,OAAO,SAAS,KACd,GAAG,IAAI,EAAE,GAAG,EAAE,KACX,YAAY,CAAC,OAAO,wBAAwB,CAAC,EAElD,MAAM,EAAE,MAAM,EACd,EACE,gBAAgB,EAChB,uBAAuB,EACvB,OAAO,EAAE,UAAe,GACzB,GAAE,OAAO,CAAC,kBAAkB,CAAC,OAAO,CAAC,CAAM,GAC3C,OAAO,CAAC,aAAa,GAAG,WAAW,CAAC,CAkGtC;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,iBAAiB,GACzB,yBAAyB,CAU3B;AAED;;;;;;;;GAQG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,gBAAgB,EAC3B,mBAAmB,EAAE,uBAAuB,EAC5C,OAAO,EAAE,eAAe,GACvB,wBAAwB,CAoD1B;AAED;;;;;;;GAOG;AACH,wBAAgB,eAAe,CAC7B,mBAAmB,EAAE,uBAAuB,EAC5C,OAAO,EAAE,eAAe,EACxB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,MAAM,QAoGf"}
@@ -1,5 +1,5 @@
1
- import { Messenger } from "@metamask/base-controller";
2
1
  import { createEngineStream } from "@metamask/json-rpc-middleware-stream";
2
+ import { MOCK_ANY_NAMESPACE, Messenger } from "@metamask/messenger";
3
3
  import { PhishingDetectorResultType } from "@metamask/phishing-controller";
4
4
  import { detectSnapLocation, fetchSnap, NodeThreadExecutionService, setupMultiplex } from "@metamask/snaps-controllers/node";
5
5
  import { DIALOG_APPROVAL_TYPES } from "@metamask/snaps-rpc-methods";
@@ -41,7 +41,9 @@ export async function installSnap(snapId, { executionService, executionServiceOp
41
41
  const snapFiles = await fetchSnap(snapId, location);
42
42
  // Create Redux store.
43
43
  const { store, runSaga } = createStore(options);
44
- const controllerMessenger = new Messenger();
44
+ const controllerMessenger = new Messenger({
45
+ namespace: MOCK_ANY_NAMESPACE,
46
+ });
45
47
  registerActions(controllerMessenger, runSaga, options, snapId);
46
48
  // Set up controllers and JSON-RPC stack.
47
49
  const restrictedHooks = getRestrictedHooks(options);
@@ -64,10 +66,9 @@ export async function installSnap(snapId, { executionService, executionServiceOp
64
66
  const ExecutionService = executionService ?? NodeThreadExecutionService;
65
67
  const service = new ExecutionService({
66
68
  ...executionServiceOptions,
67
- messenger: controllerMessenger.getRestricted({
68
- name: 'ExecutionService',
69
- allowedActions: [],
70
- allowedEvents: [],
69
+ messenger: new Messenger({
70
+ namespace: 'ExecutionService',
71
+ parent: controllerMessenger,
71
72
  }),
72
73
  setupSnapProvider: (_snapId, rpcStream) => {
73
74
  const mux = setupMultiplex(rpcStream, 'snapStream');
@@ -1 +1 @@
1
- {"version":3,"file":"simulation.mjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,kCAAkC;AACtD,OAAO,EAAE,kBAAkB,EAAE,6CAA6C;AAE1E,OAAO,EAAE,0BAA0B,EAAE,sCAAsC;AAE3E,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,0BAA0B,EAC1B,cAAc,EACf,yCAAyC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,oCAAoC;AAcpE,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAE3C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAG5C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,0BAAsB;AAC7D,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,OAAO,EAAE,UAAU,EAAE,sBAAkB;AACvC,OAAO,EAAE,eAAe,EAAE,wBAAoB;AAC9C,OAAO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QAC5D,mDAAmD;QACnD,cAAc,EAAE,OAAO,CAAC,MAAM;QAC9B,cAAc,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;YACf,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;YACvC,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAAE,CACH;KACF,CAAC,CACH,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,+BAA+B,EAC/B,CAAC,IAAI,EAAE,EAAE;QACP;;;;;WAKG;QACH,QAAQ,CAAC,CAAC,uBAAuB;YAC/B,MAAM,gBAAgB,GAAc,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;YACtE,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,gBAAgB,GAA0B,OAAO,CACrD,uBAAuB,CACxB,CAAC,MAAM,EAAE,CAAC;QACX,OAAO,CACL,gBAAgB,EAAE,IAAI,KAAK,qBAAqB,CAAC,OAAO;YACxD,gBAAgB,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,CAClC,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,kCAAkC,EAClC,KAAK,EAAE,GAAW,EAAE,KAAc,EAAE,EAAE;QACpC,MAAM,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAElD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { Messenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport { PhishingDetectorResultType } from '@metamask/phishing-controller';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n TrackEventParams,\n AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n InterfaceContext,\n SnapId,\n EntropySource,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles, Snap } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { CaipAssetType, Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport type { SnapHelpers } from './helpers';\nimport { getHelpers } from './helpers';\nimport { resolveWithSaga } from './interface';\nimport { asyncResolve, getEndowments } from './methods';\nimport {\n getPermittedClearSnapStateMethodImplementation,\n getPermittedGetSnapStateMethodImplementation,\n getPermittedUpdateSnapStateMethodImplementation,\n getGetEntropySourcesImplementation,\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n} from './methods/hooks';\nimport { getGetMnemonicSeedImplementation } from './methods/hooks/get-mnemonic-seed';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { Interface, RunSagaFunction, Store } from './store';\nimport { createStore, getCurrentInterface } from './store';\nimport { addSnapMetadataToAccount } from './utils/account';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService<unknown>>,\n> =\n ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof AbstractExecutionService>;\n controllerMessenger: Messenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the mnemonic from.\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns the seed derived from the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the seed from.\n * @returns The seed.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n\n /**\n * A hook that returns metadata about a given Snap.\n *\n * @param snapId - The ID of a Snap.\n * @returns The metadata for the given Snap.\n */\n getSnap: (snapId: string) => Snap;\n};\n\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that gets whether the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * A hook that returns the entropy sources available to the Snap.\n *\n * @returns The entropy sources available to the Snap.\n */\n getEntropySources: () => EntropySource[];\n\n /**\n * A hook that returns a promise that resolves once the extension is unlocked.\n *\n * @param shouldShowUnlockRequest - Whether to show the unlock request.\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * A hook that returns whether the client is active or not.\n *\n * @returns A boolean flag signaling whether the client is opened.\n */\n getIsActive: () => boolean;\n\n /**\n * A hook that returns the Snap's auxiliary file for the given path. This hook\n * is bound to the Snap ID.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that gets the state of the Snap. This hook is bound to the Snap ID.\n *\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * A hook that updates the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n */\n updateSnapState: (\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n\n /**\n * A hook that clears the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n */\n clearSnapState: (encrypted: boolean) => Promise<void>;\n\n /**\n * A hook that creates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param content - The content of the interface.\n * @param context - The context of the interface.\n * @returns The ID of the created interface.\n */\n createInterface: (content: Component, context?: InterfaceContext) => string;\n\n /**\n * A hook that updates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to update.\n * @param content - The content of the interface.\n */\n updateInterface: (id: string, content: Component) => void;\n\n /**\n * A hook that gets the state of an interface for the Snap. This hook is bound\n * to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The state of the interface.\n */\n getInterfaceState: (id: string) => InterfaceState;\n\n /**\n * A hook that gets the context of an interface for the Snap. This hook is\n * bound to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The context of the interface.\n */\n getInterfaceContext: (id: string) => InterfaceContext | null;\n\n /**\n * A hook that resolves an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to resolve.\n * @param value - The value to resolve the interface with.\n */\n resolveInterface: (id: string, value: Json) => Promise<void>;\n\n /**\n * A hook that gets the Snap's metadata.\n *\n * @param snapId - The ID of the Snap to get.\n * @returns The Snap's metadata.\n */\n getSnap(snapId: string): Snap;\n\n /**\n * A hook that tracks an error.\n *\n * @param error - The error object containing error details and properties.\n */\n trackError(error: Error): void;\n\n /**\n * A hook that tracks an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent(event: TrackEventParams['event']): void;\n\n /**\n * A hook that starts a performance trace.\n *\n * @param request - The trace request object containing trace details.\n */\n startTrace(request: TraceRequest): TraceContext;\n\n /**\n * A hook that ends a performance trace.\n *\n * @param request - The trace request object containing trace details.\n * @returns The trace data.\n */\n endTrace(request: EndTraceRequest): void;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The installed Snap object.\n * @template Service - The type of the execution service.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap & SnapHelpers> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new Messenger<any, any>();\n\n registerActions(controllerMessenger, runSaga, options, snapId);\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options);\n const permittedHooks = getPermittedHooks(\n snapId,\n snapFiles,\n controllerMessenger,\n runSaga,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n restrictedHooks,\n permittedHooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: controllerMessenger.getRestricted({\n name: 'ExecutionService',\n allowedActions: [],\n allowedEvents: [],\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n });\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n const helpers = getHelpers({\n snapId,\n store,\n controllerMessenger,\n runSaga,\n executionService: service,\n options,\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n ...helpers,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getMnemonicSeed: getGetMnemonicSeedImplementation(\n options.secretRecoveryPhrase,\n ),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n getSnap: getGetSnapImplementation(true),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param snapId - The ID of the Snap.\n * @param snapFiles - The fetched Snap files.\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n snapId: SnapId,\n snapFiles: FetchedSnapFiles,\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n hasPermission: () => true,\n getUnlockPromise: asyncResolve(),\n getIsLocked: () => false,\n getIsActive: () => true,\n\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n\n createInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n getInterfaceContext: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).context,\n resolveInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:resolveInterface',\n snapId,\n ...args,\n ),\n\n getEntropySources: getGetEntropySourcesImplementation(),\n getSnapState: getPermittedGetSnapStateMethodImplementation(runSaga),\n updateSnapState: getPermittedUpdateSnapStateMethodImplementation(runSaga),\n clearSnapState: getPermittedClearSnapStateMethodImplementation(runSaga),\n\n getSnap: getGetSnapImplementation(true),\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @param options - The simulation options.\n * @param snapId - The ID of the Snap.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: PhishingDetectorResultType.All }),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getAccountByAddress',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n (address) => {\n const matchingAccount = options.accounts.find(\n (account) => address === account.address,\n );\n\n if (!matchingAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(matchingAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getSelectedMultichainAccount',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n () => {\n const selectedAccount = options.accounts.find(\n (account) => account.selected,\n );\n\n if (!selectedAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(selectedAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:listMultichainAccounts',\n\n () =>\n // @ts-expect-error - These are partial accounts with only the necessary\n // data used by the interface controller.\n options.accounts.map((account) =>\n addSnapMetadataToAccount(account, snapId),\n ),\n );\n\n controllerMessenger.registerActionHandler(\n 'MultichainAssetsController:getState',\n () => ({\n // @ts-expect-error - These are partial assets with only the\n // necessary data used by the interface controller.\n assetsMetadata: options.assets,\n accountsAssets: options.accounts.reduce<Record<string, CaipAssetType[]>>(\n (acc, account) => {\n acc[account.id] = account.assets ?? [];\n return acc;\n },\n {},\n ),\n }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n}\n"]}
1
+ {"version":3,"file":"simulation.mjs","sourceRoot":"","sources":["../src/simulation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,6CAA6C;AAQ1E,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,4BAA4B;AACpE,OAAO,EAAE,0BAA0B,EAAE,sCAAsC;AAE3E,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,0BAA0B,EAC1B,cAAc,EACf,yCAAyC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,oCAAoC;AAcpE,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,OAAO,EAAE,QAAQ,EAAE,wBAAwB;AAE3C,OAAO,EAAE,MAAM,EAAE,2BAA2B;AAG5C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,0BAAsB;AAC7D,OAAO,EAAE,WAAW,EAAE,oBAAgB;AAEtC,OAAO,EAAE,UAAU,EAAE,sBAAkB;AACvC,OAAO,EAAE,eAAe,EAAE,wBAAoB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CAAC,CAAC;QACL,4DAA4D;QAC5D,mDAAmD;QACnD,cAAc,EAAE,OAAO,CAAC,MAAM;QAC9B,cAAc,EAAE,OAAO,CAAC,QAAQ,CAAC,MAAM,CACrC,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;YACf,GAAG,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC;YACvC,OAAO,GAAG,CAAC;QACb,CAAC,EACD,EAAE,CACH;KACF,CAAC,CACH,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,+BAA+B,EAC/B,CAAC,IAAI,EAAE,EAAE;QACP;;;;;WAKG;QACH,QAAQ,CAAC,CAAC,uBAAuB;YAC/B,MAAM,gBAAgB,GAAc,MAAM,MAAM,CAAC,mBAAmB,CAAC,CAAC;YACtE,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAED,MAAM,gBAAgB,GAA0B,OAAO,CACrD,uBAAuB,CACxB,CAAC,MAAM,EAAE,CAAC;QACX,OAAO,CACL,gBAAgB,EAAE,IAAI,KAAK,qBAAqB,CAAC,OAAO;YACxD,gBAAgB,EAAE,EAAE,KAAK,IAAI,EAAE,EAAE,CAClC,CAAC;IACJ,CAAC,CACF,CAAC;IAEF,mBAAmB,CAAC,qBAAqB,CACvC,kCAAkC,EAClC,KAAK,EAAE,GAAW,EAAE,KAAc,EAAE,EAAE;QACpC,MAAM,OAAO,CAAC,eAAe,EAAE,KAAK,CAAC,CAAC,SAAS,EAAE,CAAC;QAElD,OAAO,EAAE,KAAK,EAAE,CAAC;IACnB,CAAC,CACF,CAAC;AACJ,CAAC","sourcesContent":["import { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport type { CryptographicFunctions } from '@metamask/key-tree';\nimport type {\n ActionConstraint,\n EventConstraint,\n MockAnyNamespace,\n NamespacedName,\n} from '@metamask/messenger';\nimport { MOCK_ANY_NAMESPACE, Messenger } from '@metamask/messenger';\nimport { PhishingDetectorResultType } from '@metamask/phishing-controller';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n detectSnapLocation,\n fetchSnap,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n TrackEventParams,\n AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n InterfaceContext,\n SnapId,\n EntropySource,\n TraceRequest,\n EndTraceRequest,\n TraceContext,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles, Snap } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { CaipAssetType, Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport type { SnapHelpers } from './helpers';\nimport { getHelpers } from './helpers';\nimport { resolveWithSaga } from './interface';\nimport { asyncResolve, getEndowments } from './methods';\nimport {\n getPermittedClearSnapStateMethodImplementation,\n getPermittedGetSnapStateMethodImplementation,\n getPermittedUpdateSnapStateMethodImplementation,\n getGetEntropySourcesImplementation,\n getGetMnemonicImplementation,\n getGetSnapImplementation,\n getTrackEventImplementation,\n getTrackErrorImplementation,\n getEndTraceImplementation,\n getStartTraceImplementation,\n} from './methods/hooks';\nimport { getGetMnemonicSeedImplementation } from './methods/hooks/get-mnemonic-seed';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { Interface, RunSagaFunction, Store } from './store';\nimport { createStore, getCurrentInterface } from './store';\nimport { addSnapMetadataToAccount } from './utils/account';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService<unknown>>,\n> =\n ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof AbstractExecutionService>;\n controllerMessenger: Messenger<\n NamespacedName,\n ActionConstraint,\n EventConstraint\n >;\n runSaga: RunSagaFunction;\n};\n\nexport type RestrictedMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the mnemonic from.\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns the seed derived from the user's secret recovery phrase.\n *\n * @param source - The entropy source to get the seed from.\n * @returns The seed.\n */\n getMnemonicSeed: (source?: string | undefined) => Promise<Uint8Array>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * Get the cryptographic functions to use for the client. This may return an\n * empty object to fall back to the default cryptographic functions.\n *\n * @returns The cryptographic functions to use for the client.\n */\n getClientCryptography: () => CryptographicFunctions;\n\n /**\n * A hook that returns metadata about a given Snap.\n *\n * @param snapId - The ID of a Snap.\n * @returns The metadata for the given Snap.\n */\n getSnap: (snapId: string) => Snap;\n};\n\nexport type PermittedMiddlewareHooks = {\n /**\n * A hook that gets whether the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * A hook that returns the entropy sources available to the Snap.\n *\n * @returns The entropy sources available to the Snap.\n */\n getEntropySources: () => EntropySource[];\n\n /**\n * A hook that returns a promise that resolves once the extension is unlocked.\n *\n * @param shouldShowUnlockRequest - Whether to show the unlock request.\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n\n /**\n * A hook that returns whether the client is active or not.\n *\n * @returns A boolean flag signaling whether the client is opened.\n */\n getIsActive: () => boolean;\n\n /**\n * A hook that returns the Snap's auxiliary file for the given path. This hook\n * is bound to the Snap ID.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that gets the state of the Snap. This hook is bound to the Snap ID.\n *\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * A hook that updates the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n */\n updateSnapState: (\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n\n /**\n * A hook that clears the state of the Snap. This hook is bound to the Snap\n * ID.\n *\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n */\n clearSnapState: (encrypted: boolean) => Promise<void>;\n\n /**\n * A hook that creates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param content - The content of the interface.\n * @param context - The context of the interface.\n * @returns The ID of the created interface.\n */\n createInterface: (content: Component, context?: InterfaceContext) => string;\n\n /**\n * A hook that updates an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to update.\n * @param content - The content of the interface.\n */\n updateInterface: (id: string, content: Component) => void;\n\n /**\n * A hook that gets the state of an interface for the Snap. This hook is bound\n * to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The state of the interface.\n */\n getInterfaceState: (id: string) => InterfaceState;\n\n /**\n * A hook that gets the context of an interface for the Snap. This hook is\n * bound to the Snap ID.\n *\n * @param id - The ID of the interface to get.\n * @returns The context of the interface.\n */\n getInterfaceContext: (id: string) => InterfaceContext | null;\n\n /**\n * A hook that resolves an interface for the Snap. This hook is bound to the\n * Snap ID.\n *\n * @param id - The ID of the interface to resolve.\n * @param value - The value to resolve the interface with.\n */\n resolveInterface: (id: string, value: Json) => Promise<void>;\n\n /**\n * A hook that gets the Snap's metadata.\n *\n * @param snapId - The ID of the Snap to get.\n * @returns The Snap's metadata.\n */\n getSnap(snapId: string): Snap;\n\n /**\n * A hook that tracks an error.\n *\n * @param error - The error object containing error details and properties.\n */\n trackError(error: Error): void;\n\n /**\n * A hook that tracks an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent(event: TrackEventParams['event']): void;\n\n /**\n * A hook that starts a performance trace.\n *\n * @param request - The trace request object containing trace details.\n */\n startTrace(request: TraceRequest): TraceContext;\n\n /**\n * A hook that ends a performance trace.\n *\n * @param request - The trace request object containing trace details.\n * @returns The trace data.\n */\n endTrace(request: EndTraceRequest): void;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @returns The installed Snap object.\n * @template Service - The type of the execution service.\n */\nexport async function installSnap<\n Service extends new (\n ...args: any[]\n ) => InstanceType<typeof AbstractExecutionService>,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap & SnapHelpers> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new Messenger<MockAnyNamespace, any, any>({\n namespace: MOCK_ANY_NAMESPACE,\n });\n\n registerActions(controllerMessenger, runSaga, options, snapId);\n\n // Set up controllers and JSON-RPC stack.\n const restrictedHooks = getRestrictedHooks(options);\n const permittedHooks = getPermittedHooks(\n snapId,\n snapFiles,\n controllerMessenger,\n runSaga,\n );\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks: restrictedHooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n restrictedHooks,\n permittedHooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: new Messenger({\n namespace: 'ExecutionService',\n parent: controllerMessenger,\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Provider stream failure.`, error);\n }\n });\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n const helpers = getHelpers({\n snapId,\n store,\n controllerMessenger,\n runSaga,\n executionService: service,\n options,\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n ...helpers,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @returns The hooks for the simulation.\n */\nexport function getRestrictedHooks(\n options: SimulationOptions,\n): RestrictedMiddlewareHooks {\n return {\n getMnemonic: getGetMnemonicImplementation(options.secretRecoveryPhrase),\n getMnemonicSeed: getGetMnemonicSeedImplementation(\n options.secretRecoveryPhrase,\n ),\n getIsLocked: () => false,\n getClientCryptography: () => ({}),\n getSnap: getGetSnapImplementation(true),\n };\n}\n\n/**\n * Get the permitted hooks for the simulation.\n *\n * @param snapId - The ID of the Snap.\n * @param snapFiles - The fetched Snap files.\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @returns The permitted hooks for the simulation.\n */\nexport function getPermittedHooks(\n snapId: SnapId,\n snapFiles: FetchedSnapFiles,\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n): PermittedMiddlewareHooks {\n return {\n hasPermission: () => true,\n getUnlockPromise: asyncResolve(),\n getIsLocked: () => false,\n getIsActive: () => true,\n\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n\n createInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n getInterfaceContext: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).context,\n resolveInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:resolveInterface',\n snapId,\n ...args,\n ),\n\n getEntropySources: getGetEntropySourcesImplementation(),\n getSnapState: getPermittedGetSnapStateMethodImplementation(runSaga),\n updateSnapState: getPermittedUpdateSnapStateMethodImplementation(runSaga),\n clearSnapState: getPermittedClearSnapStateMethodImplementation(runSaga),\n\n getSnap: getGetSnapImplementation(true),\n trackError: getTrackErrorImplementation(runSaga),\n trackEvent: getTrackEventImplementation(runSaga),\n startTrace: getStartTraceImplementation(runSaga),\n endTrace: getEndTraceImplementation(runSaga),\n };\n}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n * @param options - The simulation options.\n * @param snapId - The ID of the Snap.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n options: SimulationOptions,\n snapId: SnapId,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: PhishingDetectorResultType.All }),\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getAccountByAddress',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n (address) => {\n const matchingAccount = options.accounts.find(\n (account) => address === account.address,\n );\n\n if (!matchingAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(matchingAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:getSelectedMultichainAccount',\n // @ts-expect-error - This is a partial account with only the necessary\n // data used by the interface controller.\n () => {\n const selectedAccount = options.accounts.find(\n (account) => account.selected,\n );\n\n if (!selectedAccount) {\n return undefined;\n }\n\n return addSnapMetadataToAccount(selectedAccount, snapId);\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'AccountsController:listMultichainAccounts',\n\n () =>\n // @ts-expect-error - These are partial accounts with only the necessary\n // data used by the interface controller.\n options.accounts.map((account) =>\n addSnapMetadataToAccount(account, snapId),\n ),\n );\n\n controllerMessenger.registerActionHandler(\n 'MultichainAssetsController:getState',\n () => ({\n // @ts-expect-error - These are partial assets with only the\n // necessary data used by the interface controller.\n assetsMetadata: options.assets,\n accountsAssets: options.accounts.reduce<Record<string, CaipAssetType[]>>(\n (acc, account) => {\n acc[account.id] = account.assets ?? [];\n return acc;\n },\n {},\n ),\n }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-simulation",
3
- "version": "3.5.0",
3
+ "version": "3.5.1",
4
4
  "description": "A simulation framework for MetaMask Snaps, enabling headless testing of Snaps in a controlled environment",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -55,18 +55,18 @@
55
55
  "test:watch": "jest --watch"
56
56
  },
57
57
  "dependencies": {
58
- "@metamask/base-controller": "^8.4.1",
59
58
  "@metamask/eth-json-rpc-middleware": "^17.0.1",
60
59
  "@metamask/json-rpc-engine": "^10.1.0",
61
60
  "@metamask/json-rpc-middleware-stream": "^8.0.8",
62
61
  "@metamask/key-tree": "^10.1.1",
63
- "@metamask/permission-controller": "^11.0.6",
62
+ "@metamask/messenger": "^0.3.0",
63
+ "@metamask/permission-controller": "^12.0.0",
64
64
  "@metamask/phishing-controller": "^13.1.0",
65
- "@metamask/snaps-controllers": "^15.0.2",
65
+ "@metamask/snaps-controllers": "^16.0.0",
66
66
  "@metamask/snaps-execution-environments": "^10.2.2",
67
- "@metamask/snaps-rpc-methods": "^13.5.3",
67
+ "@metamask/snaps-rpc-methods": "^14.0.0",
68
68
  "@metamask/snaps-sdk": "^10.0.0",
69
- "@metamask/snaps-utils": "^11.6.0",
69
+ "@metamask/snaps-utils": "^11.6.1",
70
70
  "@metamask/superstruct": "^3.2.1",
71
71
  "@metamask/utils": "^11.8.1",
72
72
  "@reduxjs/toolkit": "^1.9.5",