@metamask/snaps-simulation 4.1.0 → 4.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/controllers.cjs.map +1 -1
  3. package/dist/controllers.d.cts +4 -5
  4. package/dist/controllers.d.cts.map +1 -1
  5. package/dist/controllers.d.mts +4 -5
  6. package/dist/controllers.d.mts.map +1 -1
  7. package/dist/controllers.mjs.map +1 -1
  8. package/dist/methods/hooks/interface.cjs +11 -1
  9. package/dist/methods/hooks/interface.cjs.map +1 -1
  10. package/dist/methods/hooks/interface.d.cts +7 -0
  11. package/dist/methods/hooks/interface.d.cts.map +1 -1
  12. package/dist/methods/hooks/interface.d.mts +7 -0
  13. package/dist/methods/hooks/interface.d.mts.map +1 -1
  14. package/dist/methods/hooks/interface.mjs +9 -0
  15. package/dist/methods/hooks/interface.mjs.map +1 -1
  16. package/dist/methods/specifications.cjs +1 -0
  17. package/dist/methods/specifications.cjs.map +1 -1
  18. package/dist/methods/specifications.d.cts.map +1 -1
  19. package/dist/methods/specifications.d.mts.map +1 -1
  20. package/dist/methods/specifications.mjs +2 -1
  21. package/dist/methods/specifications.mjs.map +1 -1
  22. package/dist/request.cjs +7 -0
  23. package/dist/request.cjs.map +1 -1
  24. package/dist/request.d.cts +2 -2
  25. package/dist/request.d.cts.map +1 -1
  26. package/dist/request.d.mts +2 -2
  27. package/dist/request.d.mts.map +1 -1
  28. package/dist/request.mjs +7 -0
  29. package/dist/request.mjs.map +1 -1
  30. package/dist/simulation.cjs +4 -5
  31. package/dist/simulation.cjs.map +1 -1
  32. package/dist/simulation.d.cts +5 -5
  33. package/dist/simulation.d.cts.map +1 -1
  34. package/dist/simulation.d.mts +5 -5
  35. package/dist/simulation.d.mts.map +1 -1
  36. package/dist/simulation.mjs +4 -5
  37. package/dist/simulation.mjs.map +1 -1
  38. package/package.json +12 -13
package/CHANGELOG.md CHANGED
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [4.1.2]
11
+
12
+ ### Changed
13
+
14
+ - Bump `@metamask/snaps-controllers` from `18.0.4` to `19.0.0` and handle breaking changes ([#3922](https://github.com/MetaMask/snaps/pull/3922))
15
+
16
+ ## [4.1.1]
17
+
18
+ ### Changed
19
+
20
+ - Track whether interface has been displayed before allowing `snap_getInterfaceState` ([#3888](https://github.com/MetaMask/snaps/pull/3888))
21
+
10
22
  ## [4.1.0]
11
23
 
12
24
  ### Changed
@@ -281,7 +293,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
281
293
 
282
294
  - Initial release of `@metamask/snaps-simulation` package ([#2727](https://github.com/MetaMask/snaps/pull/2727))
283
295
 
284
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.0...HEAD
296
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.2...HEAD
297
+ [4.1.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.1...@metamask/snaps-simulation@4.1.2
298
+ [4.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.1.0...@metamask/snaps-simulation@4.1.1
285
299
  [4.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@4.0.0...@metamask/snaps-simulation@4.1.0
286
300
  [4.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.8.0...@metamask/snaps-simulation@4.0.0
287
301
  [3.8.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-simulation@3.7.0...@metamask/snaps-simulation@3.8.0
@@ -1 +1 @@
1
- {"version":3,"file":"controllers.cjs","sourceRoot":"","sources":["../src/controllers.ts"],"names":[],"mappings":";;;AAAA,mFAG6C;AAC7C,mDAAgD;AAOhD,2EAIyC;AACzC,mEAAsE;AAOtE,mEAIqC;AA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,EAAE,gCAAoB;KAC1C,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACI,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,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 {\n caip25CaveatBuilder,\n Caip25CaveatType,\n} from '@metamask/chain-agnostic-permission';\nimport { 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 type { Hex } from '@metamask/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 'PermissionController:hasPermission',\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 const simulatedAccounts = options.options.accounts;\n const ethereumAccounts = simulatedAccounts\n .filter((account) =>\n account.scopes.some((scope) => scope.startsWith('eip155')),\n )\n .map((account) => ({\n type: 'eip155:eoa',\n address: account.address as Hex,\n }));\n\n return new PermissionController({\n messenger,\n caveatSpecifications: {\n [Caip25CaveatType]: caip25CaveatBuilder({\n findNetworkClientIdByChainId: (chainId) => chainId,\n isNonEvmScopeSupported: (_scope) => true,\n getNonEvmAccountAddresses: (scope) =>\n simulatedAccounts\n .filter((account) => account.scopes.includes(scope))\n .map((account) => `${scope}:${account.address}`),\n listAccounts: () => ethereumAccounts,\n }),\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,mFAG6C;AAM7C,mDAAgD;AAMhD,2EAIyC;AAOzC,mEAAsE;AACtE,mEAIqC;AAIrC,2CAA8C;AAE9C,iDAAwD;AACxD,uDAA2D;AAuC3D;;;;;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,GAChC,IAAI,qBAAS,CAAC;QACZ,SAAS,EAAE,yBAAyB;QACpC,MAAM,EAAE,mBAAmB;KAC5B,CAAC,CAAC;IAEL,mBAAmB,CAAC,QAAQ,CAAC;QAC3B,SAAS,EAAE,4BAA4B;QACvC,OAAO,EAAE;YACP,+BAA+B;YAC/B,+BAA+B;YAC/B,kCAAkC;YAClC,wCAAwC;YACxC,iDAAiD;YACjD,2CAA2C;YAC3C,qCAAqC;YACrC,oCAAoC;SACrC;QACD,MAAM,EAAE,CAAC,yDAAyD,CAAC;KACpE,CAAC,CAAC;IAEH,MAAM,mBAAmB,GAAG,IAAI,2CAAuB,CAAC;QACtD,SAAS,EAAE,4BAA4B;KACxC,CAAC,CAAC;IAEH,MAAM,oBAAoB,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAC;IAE9D,OAAO;QACL,oBAAoB;QACpB,yBAAyB;QACzB,mBAAmB;KACpB,CAA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AE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;qBACnD,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBACpD,YAAY,EAAE,GAAG,EAAE,CAAC,gBAAgB;aACrC,CAAC;YACF,GAAG,wCAA0B;YAC7B,GAAG,iDAAkC;SACtC;QACD,wBAAwB;QACxB,mBAAmB,EAAE,gCAAoB;KAC1C,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;GAQG;AACI,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,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 {\n caip25CaveatBuilder,\n Caip25CaveatType,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n MessengerActions,\n MessengerEvents,\n MockAnyNamespace,\n} from '@metamask/messenger';\nimport { Messenger } from '@metamask/messenger';\nimport type {\n CaveatSpecificationConstraint,\n PermissionControllerMessenger,\n PermissionSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport type {\n ExecutionServiceMessenger,\n SnapControllerMessenger,\n SnapInterfaceControllerMessenger,\n SnapRegistryControllerMessenger,\n} from '@metamask/snaps-controllers';\nimport { SnapInterfaceController } 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 type { Hex } from '@metamask/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 RootControllerMessenger = Messenger<\n MockAnyNamespace,\n MessengerActions<\n | ExecutionServiceMessenger\n | PermissionControllerMessenger\n | SnapControllerMessenger\n | SnapInterfaceControllerMessenger\n | SnapRegistryControllerMessenger\n >,\n MessengerEvents<\n | ExecutionServiceMessenger\n | PermissionControllerMessenger\n | SnapControllerMessenger\n | SnapInterfaceControllerMessenger\n | SnapRegistryControllerMessenger\n >\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: SnapInterfaceControllerMessenger =\n 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 'PermissionController:hasPermission',\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 const simulatedAccounts = options.options.accounts;\n const ethereumAccounts = simulatedAccounts\n .filter((account) =>\n account.scopes.some((scope) => scope.startsWith('eip155')),\n )\n .map((account) => ({\n type: 'eip155:eoa',\n address: account.address as Hex,\n }));\n\n return new PermissionController({\n messenger,\n caveatSpecifications: {\n [Caip25CaveatType]: caip25CaveatBuilder({\n findNetworkClientIdByChainId: (chainId) => chainId,\n isNonEvmScopeSupported: (_scope) => true,\n getNonEvmAccountAddresses: (scope) =>\n simulatedAccounts\n .filter((account) => account.scopes.includes(scope))\n .map((account) => `${scope}:${account.address}`),\n listAccounts: () => ethereumAccounts,\n }),\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,16 +1,15 @@
1
+ import type { MessengerActions, MessengerEvents, MockAnyNamespace } from "@metamask/messenger";
1
2
  import { Messenger } from "@metamask/messenger";
2
- import type { CaveatSpecificationConstraint, PermissionSpecificationConstraint, PermissionControllerActions, SubjectMetadataControllerActions } from "@metamask/permission-controller";
3
+ import type { CaveatSpecificationConstraint, PermissionControllerMessenger, PermissionSpecificationConstraint } from "@metamask/permission-controller";
3
4
  import { PermissionController, SubjectMetadataController } from "@metamask/permission-controller";
5
+ import type { ExecutionServiceMessenger, SnapControllerMessenger, SnapInterfaceControllerMessenger, SnapRegistryControllerMessenger } from "@metamask/snaps-controllers";
4
6
  import { SnapInterfaceController } from "@metamask/snaps-controllers";
5
- import type { ExecutionServiceActions, SnapInterfaceControllerActions, SnapInterfaceControllerAllowedActions, SnapInterfaceControllerStateChangeEvent } from "@metamask/snaps-controllers";
6
7
  import type { SnapId } from "@metamask/snaps-sdk";
7
8
  import type { SnapManifest } from "@metamask/snaps-utils";
8
9
  import type { SimulationOptions } from "./options.cjs";
9
10
  import type { RestrictedMiddlewareHooks } from "./simulation.cjs";
10
11
  import type { RunSagaFunction } from "./store/index.cjs";
11
- export type RootControllerAllowedActions = SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions | PermissionControllerActions | ExecutionServiceActions | SubjectMetadataControllerActions;
12
- export type RootControllerAllowedEvents = SnapInterfaceControllerStateChangeEvent;
13
- export type RootControllerMessenger = Messenger<any, RootControllerAllowedActions, RootControllerAllowedEvents>;
12
+ export type RootControllerMessenger = Messenger<MockAnyNamespace, MessengerActions<ExecutionServiceMessenger | PermissionControllerMessenger | SnapControllerMessenger | SnapInterfaceControllerMessenger | SnapRegistryControllerMessenger>, MessengerEvents<ExecutionServiceMessenger | PermissionControllerMessenger | SnapControllerMessenger | SnapInterfaceControllerMessenger | SnapRegistryControllerMessenger>>;
14
13
  export type GetControllersOptions = {
15
14
  controllerMessenger: Messenger<any, any, any>;
16
15
  hooks: RestrictedMiddlewareHooks;
@@ -1 +1 @@
1
- {"version":3,"file":"controllers.d.cts","sourceRoot":"","sources":["../src/controllers.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,4BAA4B;AAChD,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;AAM1D,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,2BAA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+ import type { MessengerActions, MessengerEvents, MockAnyNamespace } from "@metamask/messenger";
1
2
  import { Messenger } from "@metamask/messenger";
2
- import type { CaveatSpecificationConstraint, PermissionSpecificationConstraint, PermissionControllerActions, SubjectMetadataControllerActions } from "@metamask/permission-controller";
3
+ import type { CaveatSpecificationConstraint, PermissionControllerMessenger, PermissionSpecificationConstraint } from "@metamask/permission-controller";
3
4
  import { PermissionController, SubjectMetadataController } from "@metamask/permission-controller";
5
+ import type { ExecutionServiceMessenger, SnapControllerMessenger, SnapInterfaceControllerMessenger, SnapRegistryControllerMessenger } from "@metamask/snaps-controllers";
4
6
  import { SnapInterfaceController } from "@metamask/snaps-controllers";
5
- import type { ExecutionServiceActions, SnapInterfaceControllerActions, SnapInterfaceControllerAllowedActions, SnapInterfaceControllerStateChangeEvent } from "@metamask/snaps-controllers";
6
7
  import type { SnapId } from "@metamask/snaps-sdk";
7
8
  import type { SnapManifest } from "@metamask/snaps-utils";
8
9
  import type { SimulationOptions } from "./options.mjs";
9
10
  import type { RestrictedMiddlewareHooks } from "./simulation.mjs";
10
11
  import type { RunSagaFunction } from "./store/index.mjs";
11
- export type RootControllerAllowedActions = SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions | PermissionControllerActions | ExecutionServiceActions | SubjectMetadataControllerActions;
12
- export type RootControllerAllowedEvents = SnapInterfaceControllerStateChangeEvent;
13
- export type RootControllerMessenger = Messenger<any, RootControllerAllowedActions, RootControllerAllowedEvents>;
12
+ export type RootControllerMessenger = Messenger<MockAnyNamespace, MessengerActions<ExecutionServiceMessenger | PermissionControllerMessenger | SnapControllerMessenger | SnapInterfaceControllerMessenger | SnapRegistryControllerMessenger>, MessengerEvents<ExecutionServiceMessenger | PermissionControllerMessenger | SnapControllerMessenger | SnapInterfaceControllerMessenger | SnapRegistryControllerMessenger>>;
14
13
  export type GetControllersOptions = {
15
14
  controllerMessenger: Messenger<any, any, any>;
16
15
  hooks: RestrictedMiddlewareHooks;
@@ -1 +1 @@
1
- {"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oB,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 {\n caip25CaveatBuilder,\n Caip25CaveatType,\n} from '@metamask/chain-agnostic-permission';\nimport { 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 type { Hex } from '@metamask/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 'PermissionController:hasPermission',\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 const simulatedAccounts = options.options.accounts;\n const ethereumAccounts = simulatedAccounts\n .filter((account) =>\n account.scopes.some((scope) => scope.startsWith('eip155')),\n )\n .map((account) => ({\n type: 'eip155:eoa',\n address: account.address as Hex,\n }));\n\n return new PermissionController({\n messenger,\n caveatSpecifications: {\n [Caip25CaveatType]: caip25CaveatBuilder({\n findNetworkClientIdByChainId: (chainId) => chainId,\n isNonEvmScopeSupported: (_scope) => true,\n getNonEvmAccountAddresses: (scope) =>\n simulatedAccounts\n .filter((account) => account.scopes.includes(scope))\n .map((account) => `${scope}:${account.address}`),\n listAccounts: () => ethereumAccounts,\n }),\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
+ {"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AAE,EAAE,CAAC,IAAI;gBACxC,yBAAyB,EAAE,CAAC,KAAK,EAAE,EAAE,CACnC,iBAAiB;qBACd,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;qBACnD,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;gBACpD,YAAY,EAAE,GAAG,EAAE,CAAC,gBAAgB;aACrC,CAAC;YACF,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 {\n caip25CaveatBuilder,\n Caip25CaveatType,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n MessengerActions,\n MessengerEvents,\n MockAnyNamespace,\n} from '@metamask/messenger';\nimport { Messenger } from '@metamask/messenger';\nimport type {\n CaveatSpecificationConstraint,\n PermissionControllerMessenger,\n PermissionSpecificationConstraint,\n} from '@metamask/permission-controller';\nimport {\n PermissionController,\n SubjectMetadataController,\n SubjectType,\n} from '@metamask/permission-controller';\nimport type {\n ExecutionServiceMessenger,\n SnapControllerMessenger,\n SnapInterfaceControllerMessenger,\n SnapRegistryControllerMessenger,\n} from '@metamask/snaps-controllers';\nimport { SnapInterfaceController } 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 type { Hex } from '@metamask/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 RootControllerMessenger = Messenger<\n MockAnyNamespace,\n MessengerActions<\n | ExecutionServiceMessenger\n | PermissionControllerMessenger\n | SnapControllerMessenger\n | SnapInterfaceControllerMessenger\n | SnapRegistryControllerMessenger\n >,\n MessengerEvents<\n | ExecutionServiceMessenger\n | PermissionControllerMessenger\n | SnapControllerMessenger\n | SnapInterfaceControllerMessenger\n | SnapRegistryControllerMessenger\n >\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: SnapInterfaceControllerMessenger =\n 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 'PermissionController:hasPermission',\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 const simulatedAccounts = options.options.accounts;\n const ethereumAccounts = simulatedAccounts\n .filter((account) =>\n account.scopes.some((scope) => scope.startsWith('eip155')),\n )\n .map((account) => ({\n type: 'eip155:eoa',\n address: account.address as Hex,\n }));\n\n return new PermissionController({\n messenger,\n caveatSpecifications: {\n [Caip25CaveatType]: caip25CaveatBuilder({\n findNetworkClientIdByChainId: (chainId) => chainId,\n isNonEvmScopeSupported: (_scope) => true,\n getNonEvmAccountAddresses: (scope) =>\n simulatedAccounts\n .filter((account) => account.scopes.includes(scope))\n .map((account) => `${scope}:${account.address}`),\n listAccounts: () => ethereumAccounts,\n }),\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,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getGetInterfaceImplementation = exports.getCreateInterfaceImplementation = void 0;
3
+ exports.getSetInterfaceDisplayedImplementation = exports.getGetInterfaceImplementation = exports.getCreateInterfaceImplementation = void 0;
4
4
  /**
5
5
  * Get the implementation of the `createInterface` hook.
6
6
  *
@@ -21,4 +21,14 @@ function getGetInterfaceImplementation(controllerMessenger) {
21
21
  return (snapId, id) => controllerMessenger.call('SnapInterfaceController:getInterface', snapId, id);
22
22
  }
23
23
  exports.getGetInterfaceImplementation = getGetInterfaceImplementation;
24
+ /**
25
+ * Get the implementation of the `setInterfaceDisplayed` hook.
26
+ *
27
+ * @param controllerMessenger - The controller messenger used to call actions.
28
+ * @returns The implementation of the `setInterfaceDisplayed` hook.
29
+ */
30
+ function getSetInterfaceDisplayedImplementation(controllerMessenger) {
31
+ return (snapId, id) => controllerMessenger.call('SnapInterfaceController:setInterfaceDisplayed', snapId, id);
32
+ }
33
+ exports.getSetInterfaceDisplayedImplementation = getSetInterfaceDisplayedImplementation;
24
34
  //# sourceMappingURL=interface.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.cjs","sourceRoot":"","sources":["../../../src/methods/hooks/interface.ts"],"names":[],"mappings":";;;AASA;;;;;GAKG;AACH,SAAgB,gCAAgC,CAC9C,mBAA4C;IAE5C,OAAO,KAAK,EACV,MAAc,EACd,OAAkB,EAClB,OAA0B,EAC1B,WAAyB,EACzB,EAAE,CACF,mBAAmB,CAAC,IAAI,CACtB,yCAAyC,EACzC,MAAM,EACN,OAAO,EACP,OAAO,EACP,WAAW,CACZ,CAAC;AACN,CAAC;AAhBD,4EAgBC;AAED;;;;;GAKG;AACH,SAAgB,6BAA6B,CAC3C,mBAA4C;IAE5C,OAAO,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CACpC,mBAAmB,CAAC,IAAI,CACtB,sCAAsC,EACtC,MAAM,EACN,EAAE,CACH,CAAC;AACN,CAAC;AATD,sEASC","sourcesContent":["import type {\n Component,\n ContentType,\n InterfaceContext,\n SnapId,\n} from '@metamask/snaps-sdk';\n\nimport type { RootControllerMessenger } from '../../controllers';\n\n/**\n * Get the implementation of the `createInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `createInterface` hook.\n */\nexport function getCreateInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return async (\n snapId: SnapId,\n content: Component,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n content,\n context,\n contentType,\n );\n}\n\n/**\n * Get the implementation of the `getInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `getInterface` hook.\n */\nexport function getGetInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return (snapId: SnapId, id: string) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n}\n"]}
1
+ {"version":3,"file":"interface.cjs","sourceRoot":"","sources":["../../../src/methods/hooks/interface.ts"],"names":[],"mappings":";;;AASA;;;;;GAKG;AACH,SAAgB,gCAAgC,CAC9C,mBAA4C;IAE5C,OAAO,KAAK,EACV,MAAc,EACd,OAAkB,EAClB,OAA0B,EAC1B,WAAyB,EACzB,EAAE,CACF,mBAAmB,CAAC,IAAI,CACtB,yCAAyC,EACzC,MAAM,EACN,OAAO,EACP,OAAO,EACP,WAAW,CACZ,CAAC;AACN,CAAC;AAhBD,4EAgBC;AAED;;;;;GAKG;AACH,SAAgB,6BAA6B,CAC3C,mBAA4C;IAE5C,OAAO,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CACpC,mBAAmB,CAAC,IAAI,CACtB,sCAAsC,EACtC,MAAM,EACN,EAAE,CACH,CAAC;AACN,CAAC;AATD,sEASC;AAED;;;;;GAKG;AACH,SAAgB,sCAAsC,CACpD,mBAA4C;IAE5C,OAAO,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CACpC,mBAAmB,CAAC,IAAI,CACtB,+CAA+C,EAC/C,MAAM,EACN,EAAE,CACH,CAAC;AACN,CAAC;AATD,wFASC","sourcesContent":["import type {\n Component,\n ContentType,\n InterfaceContext,\n SnapId,\n} from '@metamask/snaps-sdk';\n\nimport type { RootControllerMessenger } from '../../controllers';\n\n/**\n * Get the implementation of the `createInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `createInterface` hook.\n */\nexport function getCreateInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return async (\n snapId: SnapId,\n content: Component,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n content,\n context,\n contentType,\n );\n}\n\n/**\n * Get the implementation of the `getInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `getInterface` hook.\n */\nexport function getGetInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return (snapId: SnapId, id: string) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n}\n\n/**\n * Get the implementation of the `setInterfaceDisplayed` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `setInterfaceDisplayed` hook.\n */\nexport function getSetInterfaceDisplayedImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return (snapId: SnapId, id: string) =>\n controllerMessenger.call(\n 'SnapInterfaceController:setInterfaceDisplayed',\n snapId,\n id,\n );\n}\n"]}
@@ -14,4 +14,11 @@ export declare function getCreateInterfaceImplementation(controllerMessenger: Ro
14
14
  * @returns The implementation of the `getInterface` hook.
15
15
  */
16
16
  export declare function getGetInterfaceImplementation(controllerMessenger: RootControllerMessenger): (snapId: SnapId, id: string) => import("@metamask/snaps-controllers").StoredInterface;
17
+ /**
18
+ * Get the implementation of the `setInterfaceDisplayed` hook.
19
+ *
20
+ * @param controllerMessenger - The controller messenger used to call actions.
21
+ * @returns The implementation of the `setInterfaceDisplayed` hook.
22
+ */
23
+ export declare function getSetInterfaceDisplayedImplementation(controllerMessenger: RootControllerMessenger): (snapId: SnapId, id: string) => void;
17
24
  //# sourceMappingURL=interface.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.cts","sourceRoot":"","sources":["../../../src/methods/hooks/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,MAAM,EACP,4BAA4B;AAE7B,OAAO,KAAK,EAAE,uBAAuB,EAAE,8BAA0B;AAEjE;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,mBAAmB,EAAE,uBAAuB,YAGlC,MAAM,WACL,SAAS,YACR,gBAAgB,gBACZ,WAAW,qBAS5B;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,mBAAmB,EAAE,uBAAuB,YAE5B,MAAM,MAAM,MAAM,2DAMnC"}
1
+ {"version":3,"file":"interface.d.cts","sourceRoot":"","sources":["../../../src/methods/hooks/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,MAAM,EACP,4BAA4B;AAE7B,OAAO,KAAK,EAAE,uBAAuB,EAAE,8BAA0B;AAEjE;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,mBAAmB,EAAE,uBAAuB,YAGlC,MAAM,WACL,SAAS,YACR,gBAAgB,gBACZ,WAAW,qBAS5B;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,mBAAmB,EAAE,uBAAuB,YAE5B,MAAM,MAAM,MAAM,2DAMnC;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,mBAAmB,EAAE,uBAAuB,YAE5B,MAAM,MAAM,MAAM,UAMnC"}
@@ -14,4 +14,11 @@ export declare function getCreateInterfaceImplementation(controllerMessenger: Ro
14
14
  * @returns The implementation of the `getInterface` hook.
15
15
  */
16
16
  export declare function getGetInterfaceImplementation(controllerMessenger: RootControllerMessenger): (snapId: SnapId, id: string) => import("@metamask/snaps-controllers").StoredInterface;
17
+ /**
18
+ * Get the implementation of the `setInterfaceDisplayed` hook.
19
+ *
20
+ * @param controllerMessenger - The controller messenger used to call actions.
21
+ * @returns The implementation of the `setInterfaceDisplayed` hook.
22
+ */
23
+ export declare function getSetInterfaceDisplayedImplementation(controllerMessenger: RootControllerMessenger): (snapId: SnapId, id: string) => void;
17
24
  //# sourceMappingURL=interface.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.d.mts","sourceRoot":"","sources":["../../../src/methods/hooks/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,MAAM,EACP,4BAA4B;AAE7B,OAAO,KAAK,EAAE,uBAAuB,EAAE,8BAA0B;AAEjE;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,mBAAmB,EAAE,uBAAuB,YAGlC,MAAM,WACL,SAAS,YACR,gBAAgB,gBACZ,WAAW,qBAS5B;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,mBAAmB,EAAE,uBAAuB,YAE5B,MAAM,MAAM,MAAM,2DAMnC"}
1
+ {"version":3,"file":"interface.d.mts","sourceRoot":"","sources":["../../../src/methods/hooks/interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,WAAW,EACX,gBAAgB,EAChB,MAAM,EACP,4BAA4B;AAE7B,OAAO,KAAK,EAAE,uBAAuB,EAAE,8BAA0B;AAEjE;;;;;GAKG;AACH,wBAAgB,gCAAgC,CAC9C,mBAAmB,EAAE,uBAAuB,YAGlC,MAAM,WACL,SAAS,YACR,gBAAgB,gBACZ,WAAW,qBAS5B;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAC3C,mBAAmB,EAAE,uBAAuB,YAE5B,MAAM,MAAM,MAAM,2DAMnC;AAED;;;;;GAKG;AACH,wBAAgB,sCAAsC,CACpD,mBAAmB,EAAE,uBAAuB,YAE5B,MAAM,MAAM,MAAM,UAMnC"}
@@ -16,4 +16,13 @@ export function getCreateInterfaceImplementation(controllerMessenger) {
16
16
  export function getGetInterfaceImplementation(controllerMessenger) {
17
17
  return (snapId, id) => controllerMessenger.call('SnapInterfaceController:getInterface', snapId, id);
18
18
  }
19
+ /**
20
+ * Get the implementation of the `setInterfaceDisplayed` hook.
21
+ *
22
+ * @param controllerMessenger - The controller messenger used to call actions.
23
+ * @returns The implementation of the `setInterfaceDisplayed` hook.
24
+ */
25
+ export function getSetInterfaceDisplayedImplementation(controllerMessenger) {
26
+ return (snapId, id) => controllerMessenger.call('SnapInterfaceController:setInterfaceDisplayed', snapId, id);
27
+ }
19
28
  //# sourceMappingURL=interface.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"interface.mjs","sourceRoot":"","sources":["../../../src/methods/hooks/interface.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC9C,mBAA4C;IAE5C,OAAO,KAAK,EACV,MAAc,EACd,OAAkB,EAClB,OAA0B,EAC1B,WAAyB,EACzB,EAAE,CACF,mBAAmB,CAAC,IAAI,CACtB,yCAAyC,EACzC,MAAM,EACN,OAAO,EACP,OAAO,EACP,WAAW,CACZ,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC3C,mBAA4C;IAE5C,OAAO,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CACpC,mBAAmB,CAAC,IAAI,CACtB,sCAAsC,EACtC,MAAM,EACN,EAAE,CACH,CAAC;AACN,CAAC","sourcesContent":["import type {\n Component,\n ContentType,\n InterfaceContext,\n SnapId,\n} from '@metamask/snaps-sdk';\n\nimport type { RootControllerMessenger } from '../../controllers';\n\n/**\n * Get the implementation of the `createInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `createInterface` hook.\n */\nexport function getCreateInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return async (\n snapId: SnapId,\n content: Component,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n content,\n context,\n contentType,\n );\n}\n\n/**\n * Get the implementation of the `getInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `getInterface` hook.\n */\nexport function getGetInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return (snapId: SnapId, id: string) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n}\n"]}
1
+ {"version":3,"file":"interface.mjs","sourceRoot":"","sources":["../../../src/methods/hooks/interface.ts"],"names":[],"mappings":"AASA;;;;;GAKG;AACH,MAAM,UAAU,gCAAgC,CAC9C,mBAA4C;IAE5C,OAAO,KAAK,EACV,MAAc,EACd,OAAkB,EAClB,OAA0B,EAC1B,WAAyB,EACzB,EAAE,CACF,mBAAmB,CAAC,IAAI,CACtB,yCAAyC,EACzC,MAAM,EACN,OAAO,EACP,OAAO,EACP,WAAW,CACZ,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,6BAA6B,CAC3C,mBAA4C;IAE5C,OAAO,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CACpC,mBAAmB,CAAC,IAAI,CACtB,sCAAsC,EACtC,MAAM,EACN,EAAE,CACH,CAAC;AACN,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,sCAAsC,CACpD,mBAA4C;IAE5C,OAAO,CAAC,MAAc,EAAE,EAAU,EAAE,EAAE,CACpC,mBAAmB,CAAC,IAAI,CACtB,+CAA+C,EAC/C,MAAM,EACN,EAAE,CACH,CAAC;AACN,CAAC","sourcesContent":["import type {\n Component,\n ContentType,\n InterfaceContext,\n SnapId,\n} from '@metamask/snaps-sdk';\n\nimport type { RootControllerMessenger } from '../../controllers';\n\n/**\n * Get the implementation of the `createInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `createInterface` hook.\n */\nexport function getCreateInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return async (\n snapId: SnapId,\n content: Component,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n content,\n context,\n contentType,\n );\n}\n\n/**\n * Get the implementation of the `getInterface` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `getInterface` hook.\n */\nexport function getGetInterfaceImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return (snapId: SnapId, id: string) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n}\n\n/**\n * Get the implementation of the `setInterfaceDisplayed` hook.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @returns The implementation of the `setInterfaceDisplayed` hook.\n */\nexport function getSetInterfaceDisplayedImplementation(\n controllerMessenger: RootControllerMessenger,\n) {\n return (snapId: SnapId, id: string) =>\n controllerMessenger.call(\n 'SnapInterfaceController:setInterfaceDisplayed',\n snapId,\n id,\n );\n}\n"]}
@@ -59,6 +59,7 @@ function getPermissionSpecifications({ controllerMessenger, hooks, runSaga, opti
59
59
  updateSnapState: (0, hooks_1.getUpdateSnapStateMethodImplementation)(runSaga),
60
60
  createInterface: (0, hooks_1.getCreateInterfaceImplementation)(controllerMessenger),
61
61
  getInterface: (0, hooks_1.getGetInterfaceImplementation)(controllerMessenger),
62
+ setInterfaceDisplayed: (0, hooks_1.getSetInterfaceDisplayedImplementation)(controllerMessenger),
62
63
  }),
63
64
  };
64
65
  }
@@ -1 +1 @@
1
- {"version":3,"file":"specifications.cjs","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":";;;AAAA,mFAA6E;AAE7E,mEAIqC;AAErC,uDAA2D;AAE3D,+CAGqB;AACrB,6CAUiB;AAqBjB;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,MAAe;IACrC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;AACtB,CAAC;AAFD,0BAEC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAAO,MAAa;IAC9C,OAAO,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC;AAC5B,CAAC;AAFD,oCAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,2BAA2B,CAAC,EAC1C,mBAAmB,EACnB,KAAK,EACL,OAAO,EACP,OAAO,GAC4B;IACnC,OAAO;QACL,CAAC,kDAAsB,CAAC,UAAU,CAAC,EACjC,kDAAsB,CAAC,oBAAoB,CAAC,EAAE,CAAC;QACjD,GAAG,IAAA,oDAAgC,EAAC,oCAAwB,CAAC;QAC7D,GAAG,IAAA,2DAAuC,EAAC,qCAAyB,EAAE;YACpE,gBAAgB;YAChB,GAAG,KAAK;YA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AAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,gCAAkB,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC;AAvBD,sCAuBC","sourcesContent":["import { caip25EndowmentBuilder } from '@metamask/chain-agnostic-permission';\nimport type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetPreferencesMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n getRequestUserApprovalImplementation,\n} from './hooks';\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\n\nexport type PermissionSpecificationsHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve<Type>(result?: Type) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.runSaga - The function to run a saga outside the usual Redux\n * flow.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n}: GetPermissionSpecificationsOptions) {\n return {\n [caip25EndowmentBuilder.targetName]:\n caip25EndowmentBuilder.specificationBuilder({}),\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {\n // Shared hooks.\n ...hooks,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getPreferences: getGetPreferencesMethodImplementation(options),\n getSnapState: getGetSnapStateMethodImplementation(runSaga),\n getUnlockPromise: asyncResolve(true),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n requestUserApproval: getRequestUserApprovalImplementation(runSaga),\n showInAppNotification: getShowInAppNotificationImplementation(runSaga),\n showNativeNotification: getShowNativeNotificationImplementation(runSaga),\n updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),\n createInterface: getCreateInterfaceImplementation(controllerMessenger),\n getInterface: getGetInterfaceImplementation(controllerMessenger),\n }),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"]}
1
+ {"version":3,"file":"specifications.cjs","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":";;;AAAA,mFAA6E;AAE7E,mEAIqC;AAErC,uDAA2D;AAE3D,+CAGqB;AACrB,6CAWiB;AAqBjB;;;;;GAKG;AACH,SAAgB,OAAO,CAAC,MAAe;IACrC,OAAO,GAAG,EAAE,CAAC,MAAM,CAAC;AACtB,CAAC;AAFD,0BAEC;AAED;;;;;;GAMG;AACH,SAAgB,YAAY,CAAO,MAAa;IAC9C,OAAO,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC;AAC5B,CAAC;AAFD,oCAEC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,2BAA2B,CAAC,EAC1C,mBAAmB,EACnB,KAAK,EACL,OAAO,EACP,OAAO,GAC4B;IACnC,OAAO;QACL,CAAC,kDAAsB,CAAC,UAAU,CAAC,EACjC,kDAAsB,CAAC,oBAAoB,CAAC,EAAE,CAAC;QACjD,GAAG,IAAA,oDAAgC,EAAC,oCAAwB,CAAC;QAC7D,GAAG,IAAA,2DAAuC,EAAC,qCAAyB,EAAE;YACpE,gBAAgB;YAChB,GAAG,KAAK;YAER,wBAAwB;YACxB,cAAc,EAAE,IAAA,6CAAqC,EAAC,OAAO,CAAC;YAC9D,cAAc,EAAE,IAAA,6CAAqC,EAAC,OAAO,CAAC;YAC9D,YAAY,EAAE,IAAA,2CAAmC,EAAC,OAAO,CAAC;YAC1D,gBAAgB,EAAE,YAAY,CAAC,IAAI,CAAC;YAEpC,+DAA+D;YAC/D,gBAAgB,EAAE,OAAO,CAAC,KAAK,CAAC;YAEhC,uBAAuB,EAAE,YAAY,EAAE;YACvC,mBAAmB,EAAE,IAAA,4CAAoC,EAAC,OAAO,CAAC;YAClE,qBAAqB,EAAE,IAAA,8CAAsC,EAAC,OAAO,CAAC;YACtE,sBAAsB,EAAE,IAAA,+CAAuC,EAAC,OAAO,CAAC;YACxE,eAAe,EAAE,IAAA,8CAAsC,EAAC,OAAO,CAAC;YAChE,eAAe,EAAE,IAAA,wCAAgC,EAAC,mBAAmB,CAAC;YACtE,YAAY,EAAE,IAAA,qCAA6B,EAAC,mBAAmB,CAAC;YAChE,qBAAqB,EACnB,IAAA,8CAAsC,EAAC,mBAAmB,CAAC;SAC9D,CAAC;KACH,CAAC;AACJ,CAAC;AAlCD,kEAkCC;AAED;;;;;;GAMG;AACI,KAAK,UAAU,aAAa,CACjC,oBAAiD,EACjD,MAAc;IAEd,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,+CAA2B,CAAC,CAAC,MAAM,CAEzE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE;QAClC,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC;QAClC,IAAI,oBAAoB,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;YAC/D,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,aAAa,CACzD,MAAM,EACN,cAAc,CACf,CAAC;YAEF,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,WAAW,CAAC,MAAM,CAAC,UAAsB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,gCAAkB,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC;AAvBD,sCAuBC","sourcesContent":["import { caip25EndowmentBuilder } from '@metamask/chain-agnostic-permission';\nimport type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetPreferencesMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n getRequestUserApprovalImplementation,\n getSetInterfaceDisplayedImplementation,\n} from './hooks';\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\n\nexport type PermissionSpecificationsHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve<Type>(result?: Type) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.runSaga - The function to run a saga outside the usual Redux\n * flow.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n}: GetPermissionSpecificationsOptions) {\n return {\n [caip25EndowmentBuilder.targetName]:\n caip25EndowmentBuilder.specificationBuilder({}),\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {\n // Shared hooks.\n ...hooks,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getPreferences: getGetPreferencesMethodImplementation(options),\n getSnapState: getGetSnapStateMethodImplementation(runSaga),\n getUnlockPromise: asyncResolve(true),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n requestUserApproval: getRequestUserApprovalImplementation(runSaga),\n showInAppNotification: getShowInAppNotificationImplementation(runSaga),\n showNativeNotification: getShowNativeNotificationImplementation(runSaga),\n updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),\n createInterface: getCreateInterfaceImplementation(controllerMessenger),\n getInterface: getGetInterfaceImplementation(controllerMessenger),\n setInterfaceDisplayed:\n getSetInterfaceDisplayedImplementation(controllerMessenger),\n }),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"specifications.d.cts","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,2BAA2B,EAAE,wCAAwC;AAMnF,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAkBlD,OAAO,KAAK,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;;;;;;GAMG;AACH,wBAAsB,aAAa,CACjC,oBAAoB,EAAE,2BAA2B,EACjD,MAAM,EAAE,MAAM,qBAqBf"}
@@ -2,7 +2,7 @@ import { caip25EndowmentBuilder } from "@metamask/chain-agnostic-permission";
2
2
  import { endowmentPermissionBuilders, buildSnapEndowmentSpecifications, buildSnapRestrictedMethodSpecifications } from "@metamask/snaps-rpc-methods";
3
3
  import { DEFAULT_ENDOWMENTS } from "@metamask/snaps-utils";
4
4
  import { EXCLUDED_SNAP_ENDOWMENTS, EXCLUDED_SNAP_PERMISSIONS } from "./constants.mjs";
5
- import { getGetPreferencesMethodImplementation, getClearSnapStateMethodImplementation, getGetSnapStateMethodImplementation, getUpdateSnapStateMethodImplementation, getShowInAppNotificationImplementation, getShowNativeNotificationImplementation, getCreateInterfaceImplementation, getGetInterfaceImplementation, getRequestUserApprovalImplementation } from "./hooks/index.mjs";
5
+ import { getGetPreferencesMethodImplementation, getClearSnapStateMethodImplementation, getGetSnapStateMethodImplementation, getUpdateSnapStateMethodImplementation, getShowInAppNotificationImplementation, getShowNativeNotificationImplementation, getCreateInterfaceImplementation, getGetInterfaceImplementation, getRequestUserApprovalImplementation, getSetInterfaceDisplayedImplementation } from "./hooks/index.mjs";
6
6
  /**
7
7
  * Get a function which resolves with the specified result.
8
8
  *
@@ -54,6 +54,7 @@ export function getPermissionSpecifications({ controllerMessenger, hooks, runSag
54
54
  updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),
55
55
  createInterface: getCreateInterfaceImplementation(controllerMessenger),
56
56
  getInterface: getGetInterfaceImplementation(controllerMessenger),
57
+ setInterfaceDisplayed: getSetInterfaceDisplayedImplementation(controllerMessenger),
57
58
  }),
58
59
  };
59
60
  }
@@ -1 +1 @@
1
- {"version":3,"file":"specifications.mjs","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,4CAA4C;AAE7E,OAAO,EACL,2BAA2B,EAC3B,gCA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AE,uCAAuC,CAAC,OAAO,CAAC;YACxE,eAAe,EAAE,sCAAsC,CAAC,OAAO,CAAC;YAChE,eAAe,EAAE,gCAAgC,CAAC,mBAAmB,CAAC;YACtE,YAAY,EAAE,6BAA6B,CAAC,mBAAmB,CAAC;SACjE,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,oBAAiD,EACjD,MAAc;IAEd,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,MAAM,CAEzE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE;QAClC,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC;QAClC,IAAI,oBAAoB,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;YAC/D,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,aAAa,CACzD,MAAM,EACN,cAAc,CACf,CAAC;YAEF,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,WAAW,CAAC,MAAM,CAAC,UAAsB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,kBAAkB,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { caip25EndowmentBuilder } from '@metamask/chain-agnostic-permission';\nimport type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetPreferencesMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n getRequestUserApprovalImplementation,\n} from './hooks';\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\n\nexport type PermissionSpecificationsHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve<Type>(result?: Type) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.runSaga - The function to run a saga outside the usual Redux\n * flow.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n}: GetPermissionSpecificationsOptions) {\n return {\n [caip25EndowmentBuilder.targetName]:\n caip25EndowmentBuilder.specificationBuilder({}),\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {\n // Shared hooks.\n ...hooks,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getPreferences: getGetPreferencesMethodImplementation(options),\n getSnapState: getGetSnapStateMethodImplementation(runSaga),\n getUnlockPromise: asyncResolve(true),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n requestUserApproval: getRequestUserApprovalImplementation(runSaga),\n showInAppNotification: getShowInAppNotificationImplementation(runSaga),\n showNativeNotification: getShowNativeNotificationImplementation(runSaga),\n updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),\n createInterface: getCreateInterfaceImplementation(controllerMessenger),\n getInterface: getGetInterfaceImplementation(controllerMessenger),\n }),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"]}
1
+ {"version":3,"file":"specifications.mjs","sourceRoot":"","sources":["../../src/methods/specifications.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,4CAA4C;AAE7E,OAAO,EACL,2BAA2B,EAC3B,gCAAgC,EAChC,uCAAuC,EACxC,oCAAoC;AAErC,OAAO,EAAE,kBAAkB,EAAE,8BAA8B;AAE3D,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EAC1B,wBAAoB;AACrB,OAAO,EACL,qCAAqC,EACrC,qCAAqC,EACrC,mCAAmC,EACnC,sCAAsC,EACtC,sCAAsC,EACtC,uCAAuC,E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C;SAC9D,CAAC;KACH,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,oBAAiD,EACjD,MAAc;IAEd,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAC,MAAM,CAEzE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,EAAE;QAClC,MAAM,WAAW,GAAG,MAAM,OAAO,CAAC;QAClC,IAAI,oBAAoB,CAAC,aAAa,CAAC,MAAM,EAAE,cAAc,CAAC,EAAE,CAAC;YAC/D,MAAM,UAAU,GAAG,MAAM,oBAAoB,CAAC,aAAa,CACzD,MAAM,EACN,cAAc,CACf,CAAC;YAEF,IAAI,UAAU,EAAE,CAAC;gBACf,OAAO,WAAW,CAAC,MAAM,CAAC,UAAsB,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC;IACrB,CAAC,EAAE,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC;IAExB,OAAO,CAAC,GAAG,IAAI,GAAG,CAAC,CAAC,GAAG,kBAAkB,EAAE,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { caip25EndowmentBuilder } from '@metamask/chain-agnostic-permission';\nimport type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetPreferencesMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n getRequestUserApprovalImplementation,\n getSetInterfaceDisplayedImplementation,\n} from './hooks';\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\n\nexport type PermissionSpecificationsHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve<Type>(result?: Type) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.runSaga - The function to run a saga outside the usual Redux\n * flow.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n}: GetPermissionSpecificationsOptions) {\n return {\n [caip25EndowmentBuilder.targetName]:\n caip25EndowmentBuilder.specificationBuilder({}),\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {\n // Shared hooks.\n ...hooks,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getPreferences: getGetPreferencesMethodImplementation(options),\n getSnapState: getGetSnapStateMethodImplementation(runSaga),\n getUnlockPromise: asyncResolve(true),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n requestUserApproval: getRequestUserApprovalImplementation(runSaga),\n showInAppNotification: getShowInAppNotificationImplementation(runSaga),\n showNativeNotification: getShowNativeNotificationImplementation(runSaga),\n updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),\n createInterface: getCreateInterfaceImplementation(controllerMessenger),\n getInterface: getGetInterfaceImplementation(controllerMessenger),\n setInterfaceDisplayed:\n getSetInterfaceDisplayedImplementation(controllerMessenger),\n }),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"]}
package/dist/request.cjs CHANGED
@@ -151,6 +151,13 @@ async function getInterfaceApi(result, snapId, controllerMessenger, options, con
151
151
  const interfaceId = await getInterfaceFromResult(result, snapId, controllerMessenger);
152
152
  const id = interfaceId ?? contentId;
153
153
  if (id) {
154
+ try {
155
+ controllerMessenger.call('SnapInterfaceController:setInterfaceDisplayed', snapId, id);
156
+ }
157
+ catch {
158
+ // The call will fail for invalid interfaces, but we can just ignore that
159
+ // here.
160
+ }
154
161
  return () => {
155
162
  const { content } = controllerMessenger.call('SnapInterfaceController:getInterface', snapId, id);
156
163
  const actions = (0, interface_1.getInterfaceActions)(snapId, controllerMessenger, options, {
@@ -1 +1 @@
1
- {"version":3,"file":"request.cjs","sourceRoot":"","sources":["../src/request.ts"],"names":[],"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AA6B,CACrC,CAAC;QAEF,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAzBD,wDAyBC;AAED;;;;;;;;;;GAUG;AACI,KAAK,UAAU,eAAe,CACnC,MAAe,EACf,MAAc,EACd,mBAA4C,EAC5C,OAA0B,EAC1B,SAAkB;IAElB,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAC9C,MAAM,EACN,MAAM,EACN,mBAAmB,CACpB,CAAC;IAEF,MAAM,EAAE,GAAG,WAAW,IAAI,SAAS,CAAC;IAEpC,IAAI,EAAE,EAAE,CAAC;QACP,OAAO,GAAG,EAAE;YACV,MAAM,EAAE,OAAO,EAAE,GAAG,mBAAmB,CAAC,IAAI,CAC1C,sCAAsC,EACtC,MAAM,EACN,EAAE,CACH,CAAC;YAEF,MAAM,OAAO,GAAG,IAAA,+BAAmB,EACjC,MAAM,EACN,mBAAmB,EACnB,OAAO,EACP;gBACE,EAAE;gBACF,OAAO;aACR,CACF,CAAC;YAEF,OAAO;gBACL,OAAO;gBACP,GAAG,OAAO;aACX,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAzCD,0CAyCC","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n type ComponentOrElement,\n ComponentOrElementStruct,\n type JsonRpcError,\n type SnapId,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getInterface, getInterfaceActions } from './interface';\nimport type { SimulationOptions } from './options';\nimport type { RunSagaFunction, Store } from './store';\nimport {\n getTraces,\n getErrors,\n clearNotifications,\n getNotifications,\n getEvents,\n clearTrackables,\n} from './store';\nimport { SnapResponseStruct } from './structs';\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from './types';\n\nexport type HandleRequestOptions = {\n snapId: SnapId;\n store: Store;\n executionService: AbstractExecutionService<unknown>;\n handler: HandlerType;\n controllerMessenger: RootControllerMessenger;\n simulationOptions: SimulationOptions;\n runSaga: RunSagaFunction;\n request: RequestOptions;\n};\n\n/**\n * Send a JSON-RPC request to the Snap, and wrap the response in a\n * {@link SnapResponse} object.\n *\n * @param options - The request options.\n * @param options.snapId - The ID of the Snap to send the request to.\n * @param options.store - The Redux store.\n * @param options.executionService - The execution service to use to send the\n * request.\n * @param options.handler - The handler to use to send the request.\n * @param options.controllerMessenger - The controller messenger used to call actions.\n * @param options.simulationOptions - The simulation options.\n * @param options.runSaga - A function to run a saga outside the usual Redux\n * flow.\n * @param options.request - The request to send.\n * @param options.request.id - The ID of the request. If not provided, a random\n * ID will be generated.\n * @param options.request.origin - The origin of the request. Defaults to\n * `https://metamask.io`.\n * @returns The response, wrapped in a {@link SnapResponse} object.\n */\nexport function handleRequest({\n snapId,\n store,\n executionService,\n handler,\n controllerMessenger,\n simulationOptions,\n runSaga,\n request: { id = nanoid(), origin = 'https://metamask.io', ...options },\n}: HandleRequestOptions): SnapRequest {\n const getInterfaceError = () => {\n throw new Error(\n 'Unable to get the interface from the Snap: The request to the Snap failed.',\n );\n };\n\n const promise = executionService\n .handleRpcRequest(snapId, {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n })\n .then(async (result) => {\n const state = store.getState();\n const notifications = getNotifications(state);\n const errors = getErrors(state);\n const events = getEvents(state);\n const traces = getTraces(state);\n const interfaceId = notifications[0]?.content;\n\n store.dispatch(clearNotifications());\n store.dispatch(clearTrackables());\n\n try {\n const getInterfaceFn = await getInterfaceApi(\n result,\n snapId,\n controllerMessenger,\n simulationOptions,\n interfaceId,\n );\n\n return {\n id: String(id),\n response: {\n result: getSafeJson(result),\n },\n notifications,\n tracked: {\n errors,\n events,\n traces,\n },\n ...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),\n };\n } catch (error) {\n const [unwrappedError] = unwrapError(error);\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n tracked: {\n errors: [],\n events: [],\n traces: [],\n },\n getInterface: getInterfaceError,\n };\n }\n })\n .catch((error) => {\n const [unwrappedError] = unwrapError(error);\n\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n tracked: {\n errors: [],\n events: [],\n traces: [],\n },\n getInterface: getInterfaceError,\n };\n }) as unknown as SnapRequest;\n\n promise.getInterface = async () => {\n const sagaPromise = runSaga(\n getInterface,\n runSaga,\n snapId,\n controllerMessenger,\n simulationOptions,\n ).toPromise();\n const result = await Promise.race([promise, sagaPromise]);\n\n // If the request promise has resolved to an error, we should throw\n // instead of waiting for an interface that likely will never be displayed\n if (\n is(result, SnapResponseStruct) &&\n hasProperty(result.response, 'error')\n ) {\n throw new Error(\n `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${\n (result.response.error as JsonRpcError).message\n }`,\n );\n }\n\n return await sagaPromise;\n };\n\n return promise;\n}\n\n/**\n * Get the interface ID from the result if it's available or create a new interface if the result contains static components.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The interface ID or undefined if the result doesn't include content.\n */\nexport async function getInterfaceFromResult(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n) {\n if (isPlainObject(result) && hasProperty(result, 'id')) {\n return result.id as string;\n }\n\n if (isPlainObject(result) && hasProperty(result, 'content')) {\n assert(\n is(result.content, ComponentOrElementStruct),\n 'The Snap returned an invalid interface.',\n );\n\n const id = controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n result.content as ComponentOrElement,\n );\n\n return id;\n }\n\n return undefined;\n}\n\n/**\n * Get the response content from the `SnapInterfaceController` and include the\n * interaction methods.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @param options - The simulation options.\n * @param contentId - The id of the interface if it exists outside of the result.\n * @returns The content components if any.\n */\nexport async function getInterfaceApi(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n options: SimulationOptions,\n contentId?: string,\n): Promise<(() => SnapHandlerInterface) | undefined> {\n const interfaceId = await getInterfaceFromResult(\n result,\n snapId,\n controllerMessenger,\n );\n\n const id = interfaceId ?? contentId;\n\n if (id) {\n return () => {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const actions = getInterfaceActions(\n snapId,\n controllerMessenger,\n options,\n {\n id,\n content,\n },\n );\n\n return {\n content,\n ...actions,\n };\n };\n }\n\n return undefined;\n}\n"]}
1
+ {"version":3,"file":"request.cjs","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":";;;AACA,mDAK6B;AAE7B,uDAAoD;AACpD,uDAA2C;AAC3C,2CAKyB;AACzB,8CAA0C;AAG1C,+CAAgE;AAGhE,6CAOiB;AACjB,2CAA+C;AAkB/C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,SAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,EACP,OAAO,EAAE,EAAE,EAAE,GAAG,IAAA,gBAAM,GAAE,EAAE,MAAM,GAAG,qBAAqB,EAAE,GAAG,OAAO,EAAE,GACjD;IACrB,MAAM,iBAAiB,GAAG,GAAG,EAAE;QAC7B,MAAM,IAAI,KAAK,CACb,4EAA4E,CAC7E,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,OAAO,GAAG,gBAAgB;SAC7B,gBAAgB,CAAC,MAAM,EAAE;QACxB,MAAM;QACN,OAAO;QACP,OAAO,EAAE;YACP,OAAO,EAAE,KAAK;YACd,EAAE,EAAE,C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,EACN,EAAE,CACH,CAAC;YAEF,MAAM,OAAO,GAAG,IAAA,+BAAmB,EACjC,MAAM,EACN,mBAAmB,EACnB,OAAO,EACP;gBACE,EAAE;gBACF,OAAO;aACR,CACF,CAAC;YAEF,OAAO;gBACL,OAAO;gBACP,GAAG,OAAO;aACX,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AApDD,0CAoDC","sourcesContent":["import type { ExecutionService } from '@metamask/snaps-controllers';\nimport {\n type ComponentOrElement,\n ComponentOrElementStruct,\n type JsonRpcError,\n type SnapId,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getInterface, getInterfaceActions } from './interface';\nimport type { SimulationOptions } from './options';\nimport type { RunSagaFunction, Store } from './store';\nimport {\n getTraces,\n getErrors,\n clearNotifications,\n getNotifications,\n getEvents,\n clearTrackables,\n} from './store';\nimport { SnapResponseStruct } from './structs';\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from './types';\n\nexport type HandleRequestOptions = {\n snapId: SnapId;\n store: Store;\n executionService: ExecutionService;\n handler: HandlerType;\n controllerMessenger: RootControllerMessenger;\n simulationOptions: SimulationOptions;\n runSaga: RunSagaFunction;\n request: RequestOptions;\n};\n\n/**\n * Send a JSON-RPC request to the Snap, and wrap the response in a\n * {@link SnapResponse} object.\n *\n * @param options - The request options.\n * @param options.snapId - The ID of the Snap to send the request to.\n * @param options.store - The Redux store.\n * @param options.executionService - The execution service to use to send the\n * request.\n * @param options.handler - The handler to use to send the request.\n * @param options.controllerMessenger - The controller messenger used to call actions.\n * @param options.simulationOptions - The simulation options.\n * @param options.runSaga - A function to run a saga outside the usual Redux\n * flow.\n * @param options.request - The request to send.\n * @param options.request.id - The ID of the request. If not provided, a random\n * ID will be generated.\n * @param options.request.origin - The origin of the request. Defaults to\n * `https://metamask.io`.\n * @returns The response, wrapped in a {@link SnapResponse} object.\n */\nexport function handleRequest({\n snapId,\n store,\n executionService,\n handler,\n controllerMessenger,\n simulationOptions,\n runSaga,\n request: { id = nanoid(), origin = 'https://metamask.io', ...options },\n}: HandleRequestOptions): SnapRequest {\n const getInterfaceError = () => {\n throw new Error(\n 'Unable to get the interface from the Snap: The request to the Snap failed.',\n );\n };\n\n const promise = executionService\n .handleRpcRequest(snapId, {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n })\n .then(async (result) => {\n const state = store.getState();\n const notifications = getNotifications(state);\n const errors = getErrors(state);\n const events = getEvents(state);\n const traces = getTraces(state);\n const interfaceId = notifications[0]?.content;\n\n store.dispatch(clearNotifications());\n store.dispatch(clearTrackables());\n\n try {\n const getInterfaceFn = await getInterfaceApi(\n result,\n snapId,\n controllerMessenger,\n simulationOptions,\n interfaceId,\n );\n\n return {\n id: String(id),\n response: {\n result: getSafeJson(result),\n },\n notifications,\n tracked: {\n errors,\n events,\n traces,\n },\n ...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),\n };\n } catch (error) {\n const [unwrappedError] = unwrapError(error);\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n tracked: {\n errors: [],\n events: [],\n traces: [],\n },\n getInterface: getInterfaceError,\n };\n }\n })\n .catch((error) => {\n const [unwrappedError] = unwrapError(error);\n\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n tracked: {\n errors: [],\n events: [],\n traces: [],\n },\n getInterface: getInterfaceError,\n };\n }) as unknown as SnapRequest;\n\n promise.getInterface = async () => {\n const sagaPromise = runSaga(\n getInterface,\n runSaga,\n snapId,\n controllerMessenger,\n simulationOptions,\n ).toPromise();\n const result = await Promise.race([promise, sagaPromise]);\n\n // If the request promise has resolved to an error, we should throw\n // instead of waiting for an interface that likely will never be displayed\n if (\n is(result, SnapResponseStruct) &&\n hasProperty(result.response, 'error')\n ) {\n throw new Error(\n `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${\n (result.response.error as JsonRpcError).message\n }`,\n );\n }\n\n return await sagaPromise;\n };\n\n return promise;\n}\n\n/**\n * Get the interface ID from the result if it's available or create a new interface if the result contains static components.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The interface ID or undefined if the result doesn't include content.\n */\nexport async function getInterfaceFromResult(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n) {\n if (isPlainObject(result) && hasProperty(result, 'id')) {\n return result.id as string;\n }\n\n if (isPlainObject(result) && hasProperty(result, 'content')) {\n assert(\n is(result.content, ComponentOrElementStruct),\n 'The Snap returned an invalid interface.',\n );\n\n const id = controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n result.content as ComponentOrElement,\n );\n\n return id;\n }\n\n return undefined;\n}\n\n/**\n * Get the response content from the `SnapInterfaceController` and include the\n * interaction methods.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @param options - The simulation options.\n * @param contentId - The id of the interface if it exists outside of the result.\n * @returns The content components if any.\n */\nexport async function getInterfaceApi(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n options: SimulationOptions,\n contentId?: string,\n): Promise<(() => SnapHandlerInterface) | undefined> {\n const interfaceId = await getInterfaceFromResult(\n result,\n snapId,\n controllerMessenger,\n );\n\n const id = interfaceId ?? contentId;\n\n if (id) {\n try {\n controllerMessenger.call(\n 'SnapInterfaceController:setInterfaceDisplayed',\n snapId,\n id,\n );\n } catch {\n // The call will fail for invalid interfaces, but we can just ignore that\n // here.\n }\n\n return () => {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const actions = getInterfaceActions(\n snapId,\n controllerMessenger,\n options,\n {\n id,\n content,\n },\n );\n\n return {\n content,\n ...actions,\n };\n };\n }\n\n return undefined;\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { AbstractExecutionService } from "@metamask/snaps-controllers";
1
+ import type { ExecutionService } from "@metamask/snaps-controllers";
2
2
  import { type SnapId } from "@metamask/snaps-sdk";
3
3
  import type { HandlerType } from "@metamask/snaps-utils";
4
4
  import type { RootControllerMessenger } from "./controllers.cjs";
@@ -8,7 +8,7 @@ import type { RequestOptions, SnapHandlerInterface, SnapRequest } from "./types.
8
8
  export type HandleRequestOptions = {
9
9
  snapId: SnapId;
10
10
  store: Store;
11
- executionService: AbstractExecutionService<unknown>;
11
+ executionService: ExecutionService;
12
12
  handler: HandlerType;
13
13
  controllerMessenger: RootControllerMessenger;
14
14
  simulationOptions: SimulationOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.cts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,EAIL,KAAK,MAAM,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAWzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,0BAAsB;AAE7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAkB;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,0BAAgB;AAUtD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACZ,oBAAgB;AAEjB,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,gBAAgB,EAAE,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,EAAE,WAAW,CAAC;IACrB,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C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EAAE,KAAK,CAAC;IACb,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,OAAO,EAAE,WAAW,CAAC;IACrB,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,EACP,OAAO,EAAE,EAAE,EAAa,EAAE,MAA8B,EAAE,GAAG,OAAO,EAAE,GACvE,EAAE,oBAAoB,GAAG,WAAW,CAgHpC;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,+BAsB7C;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,EAC5C,OAAO,EAAE,iBAAiB,EAC1B,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,CAAC,MAAM,oBAAoB,CAAC,GAAG,SAAS,CAAC,CA8CnD"}
@@ -1,4 +1,4 @@
1
- import type { AbstractExecutionService } from "@metamask/snaps-controllers";
1
+ import type { ExecutionService } from "@metamask/snaps-controllers";
2
2
  import { type SnapId } from "@metamask/snaps-sdk";
3
3
  import type { HandlerType } from "@metamask/snaps-utils";
4
4
  import type { RootControllerMessenger } from "./controllers.mjs";
@@ -8,7 +8,7 @@ import type { RequestOptions, SnapHandlerInterface, SnapRequest } from "./types.
8
8
  export type HandleRequestOptions = {
9
9
  snapId: SnapId;
10
10
  store: Store;
11
- executionService: AbstractExecutionService<unknown>;
11
+ executionService: ExecutionService;
12
12
  handler: HandlerType;
13
13
  controllerMessenger: RootControllerMessenger;
14
14
  simulationOptions: SimulationOptions;
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.mts","sourceRoot":"","sources":["../src/request.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,wBAAwB,EAAE,oCAAoC;AAC5E,OAAO,EAIL,KAAK,MAAM,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,8BAA8B;AAWzD,OAAO,KAAK,EAAE,uBAAuB,EAAE,0BAAsB;AAE7D,OAAO,KAAK,EAAE,iBAAiB,EAAE,sBAAkB;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,KAAK,EAAE,0BAAgB;AAUtD,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACpB,WAAW,EACZ,oBAAgB;AAEjB,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,gBAAgB,EAAE,wBAAwB,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,EAAE,WAAW,CAAC;IACrB,mBAAmB,EAAE,uBAAuB,CAAC;IAC7C,iBAAiB,EAAE,iBAAiB,CAAC;IACrC,OAAO,EAAE,eAAe,CAAC;IACzB,OAAO,EAAE,cAAc,CAAC;CACzB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,aAAa,CAAC,EAC5B,MAAM,EACN,KAAK,EACL,gBAAgB,EAChB,OAAO,EACP,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,EACP,OAAO,EAAE,EAAE,EAAa,EAAE,MAA8B,EAAE,GAAG,OAAO,EAAE,GACvE,EAAE,oBAAoB,GAAG,WAAW,CAgHpC;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,+BAsB7C;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,e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,CAC1C,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,+BAsB7C;AAED;;;;;;;;;;GAUG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,OAAO,EACf,MAAM,EAAE,MAAM,EACd,mBAAmB,EAAE,uBAAuB,EAC5C,OAAO,EAAE,iBAAiB,EAC1B,SAAS,CAAC,EAAE,MAAM,GACjB,OAAO,CAAC,CAAC,MAAM,oBAAoB,CAAC,GAAG,SAAS,CAAC,CA8CnD"}
package/dist/request.mjs CHANGED
@@ -147,6 +147,13 @@ export async function getInterfaceApi(result, snapId, controllerMessenger, optio
147
147
  const interfaceId = await getInterfaceFromResult(result, snapId, controllerMessenger);
148
148
  const id = interfaceId ?? contentId;
149
149
  if (id) {
150
+ try {
151
+ controllerMessenger.call('SnapInterfaceController:setInterfaceDisplayed', snapId, id);
152
+ }
153
+ catch {
154
+ // The call will fail for invalid interfaces, but we can just ignore that
155
+ // here.
156
+ }
150
157
  return () => {
151
158
  const { content } = controllerMessenger.call('SnapInterfaceController:getInterface', snapId, id);
152
159
  const actions = getInterfaceActions(snapId, controllerMessenger, options, {