@metamask/snaps-controllers 9.2.0 → 9.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (153) hide show
  1. package/CHANGELOG.md +37 -1
  2. package/dist/{chunk-WP3DAIFM.mjs → chunk-23PVLQFV.mjs} +62 -2
  3. package/dist/chunk-23PVLQFV.mjs.map +1 -0
  4. package/dist/chunk-272IFIK7.mjs +1 -0
  5. package/dist/chunk-272IFIK7.mjs.map +1 -0
  6. package/dist/{chunk-42ODFZSH.mjs → chunk-2AEM5R2M.mjs} +4 -4
  7. package/dist/{chunk-NZKBY2N7.mjs → chunk-2MH7QYBP.mjs} +47 -11
  8. package/dist/chunk-2MH7QYBP.mjs.map +1 -0
  9. package/dist/chunk-2XQD4P2S.mjs +1 -0
  10. package/dist/chunk-2XQD4P2S.mjs.map +1 -0
  11. package/dist/{chunk-XSFI32LB.mjs → chunk-33RRV7F4.mjs} +1 -1
  12. package/dist/{chunk-SAAURQ5A.mjs → chunk-6WGCLJGC.mjs} +2 -2
  13. package/dist/{chunk-FPGAQ6MT.js → chunk-7BUNUNUC.js} +3 -3
  14. package/dist/{chunk-CDTGUNSA.js → chunk-B6KTRDBK.js} +9 -9
  15. package/dist/chunk-B6KTRDBK.js.map +1 -0
  16. package/dist/{chunk-3AANDIXT.js → chunk-D66YLO7T.js} +3 -3
  17. package/dist/{chunk-E52MHHG4.js → chunk-FKQTV3LO.js} +55 -19
  18. package/dist/chunk-FKQTV3LO.js.map +1 -0
  19. package/dist/{chunk-KH72WRHR.js → chunk-FZOI4WPB.js} +3 -3
  20. package/dist/chunk-G245VWEY.mjs +275 -0
  21. package/dist/chunk-G245VWEY.mjs.map +1 -0
  22. package/dist/{chunk-7IJQGFT5.mjs → chunk-HLQQTAMM.mjs} +2 -2
  23. package/dist/chunk-IDCWJJCQ.js +1 -0
  24. package/dist/chunk-IDCWJJCQ.js.map +1 -0
  25. package/dist/{chunk-BUHS4M6F.js → chunk-JLIW4CNS.js} +62 -2
  26. package/dist/chunk-JLIW4CNS.js.map +1 -0
  27. package/dist/{chunk-RW7AYHRG.js → chunk-KELDSV7H.js} +3 -3
  28. package/dist/{chunk-567BFPSL.mjs → chunk-KRI4OKC3.mjs} +10 -10
  29. package/dist/chunk-KRI4OKC3.mjs.map +1 -0
  30. package/dist/{chunk-PMZXFAQI.mjs → chunk-KYRKZ3RH.mjs} +2 -2
  31. package/dist/{chunk-LRVK45HN.mjs → chunk-LDL6LJ3P.mjs} +2 -2
  32. package/dist/chunk-M7DWHPVM.js +1 -0
  33. package/dist/chunk-M7DWHPVM.js.map +1 -0
  34. package/dist/{chunk-6ERB63FH.js → chunk-OVATPF5I.js} +3 -3
  35. package/dist/{chunk-HQ6HMINL.js → chunk-P66VIDFG.js} +3 -3
  36. package/dist/{chunk-PT22IXNS.js → chunk-POQSARDG.js} +3 -3
  37. package/dist/{chunk-ZRC46TUF.js → chunk-PYSDWIVK.js} +3 -3
  38. package/dist/{chunk-S775IABY.js → chunk-QRISQRFI.js} +13 -14
  39. package/dist/{chunk-S775IABY.js.map → chunk-QRISQRFI.js.map} +1 -1
  40. package/dist/chunk-QYQLJCPR.js +275 -0
  41. package/dist/chunk-QYQLJCPR.js.map +1 -0
  42. package/dist/{chunk-QLFH3MC6.mjs → chunk-TSDUJNOP.mjs} +5 -6
  43. package/dist/chunk-TSDUJNOP.mjs.map +1 -0
  44. package/dist/{chunk-YUWYMNIX.mjs → chunk-VKMY6CKT.mjs} +2 -2
  45. package/dist/{chunk-CIFVYFJW.mjs → chunk-WR7CVDEY.mjs} +2 -2
  46. package/dist/{chunk-GRBWVPLF.js → chunk-XFUP7RFI.js} +1 -1
  47. package/dist/{chunk-3A72M4GC.mjs → chunk-XOSHP4J3.mjs} +2 -2
  48. package/dist/cronjob/CronjobController.js +19 -17
  49. package/dist/cronjob/CronjobController.mjs +18 -16
  50. package/dist/cronjob/index.js +19 -17
  51. package/dist/cronjob/index.mjs +18 -16
  52. package/dist/index.js +31 -28
  53. package/dist/index.mjs +31 -28
  54. package/dist/insights/SnapInsightsController.js +25 -0
  55. package/dist/insights/SnapInsightsController.js.map +1 -0
  56. package/dist/insights/SnapInsightsController.mjs +25 -0
  57. package/dist/insights/SnapInsightsController.mjs.map +1 -0
  58. package/dist/insights/index.js +26 -0
  59. package/dist/insights/index.js.map +1 -0
  60. package/dist/insights/index.mjs +26 -0
  61. package/dist/insights/index.mjs.map +1 -0
  62. package/dist/interface/SnapInterfaceController.js +2 -2
  63. package/dist/interface/SnapInterfaceController.mjs +1 -1
  64. package/dist/interface/index.js +2 -2
  65. package/dist/interface/index.mjs +1 -1
  66. package/dist/node.js +33 -30
  67. package/dist/node.mjs +35 -32
  68. package/dist/react-native.js +32 -29
  69. package/dist/react-native.mjs +32 -29
  70. package/dist/services/AbstractExecutionService.js +3 -3
  71. package/dist/services/AbstractExecutionService.mjs +2 -2
  72. package/dist/services/browser.js +10 -10
  73. package/dist/services/browser.mjs +10 -10
  74. package/dist/services/iframe/IframeExecutionService.js +4 -4
  75. package/dist/services/iframe/IframeExecutionService.mjs +3 -3
  76. package/dist/services/iframe/index.js +4 -4
  77. package/dist/services/iframe/index.mjs +3 -3
  78. package/dist/services/index.js +9 -9
  79. package/dist/services/index.mjs +9 -9
  80. package/dist/services/node-js/NodeProcessExecutionService.js +9 -9
  81. package/dist/services/node-js/NodeProcessExecutionService.mjs +8 -8
  82. package/dist/services/node-js/NodeThreadExecutionService.js +9 -9
  83. package/dist/services/node-js/NodeThreadExecutionService.mjs +8 -8
  84. package/dist/services/node-js/index.js +10 -10
  85. package/dist/services/node-js/index.mjs +11 -11
  86. package/dist/services/node.js +11 -11
  87. package/dist/services/node.mjs +13 -13
  88. package/dist/services/offscreen/OffscreenExecutionService.js +5 -5
  89. package/dist/services/offscreen/OffscreenExecutionService.mjs +4 -4
  90. package/dist/services/offscreen/index.js +5 -5
  91. package/dist/services/offscreen/index.mjs +4 -4
  92. package/dist/services/proxy/ProxyExecutionService.js +4 -4
  93. package/dist/services/proxy/ProxyExecutionService.mjs +3 -3
  94. package/dist/services/react-native.js +10 -10
  95. package/dist/services/react-native.mjs +10 -10
  96. package/dist/services/webview/WebViewExecutionService.js +5 -5
  97. package/dist/services/webview/WebViewExecutionService.mjs +4 -4
  98. package/dist/services/webview/index.js +5 -5
  99. package/dist/services/webview/index.mjs +4 -4
  100. package/dist/services/webworker/WebWorkerExecutionService.js +4 -4
  101. package/dist/services/webworker/WebWorkerExecutionService.mjs +3 -3
  102. package/dist/services/webworker/index.js +4 -4
  103. package/dist/services/webworker/index.mjs +3 -3
  104. package/dist/snaps/SnapController.js +5 -5
  105. package/dist/snaps/SnapController.mjs +4 -4
  106. package/dist/snaps/index.js +10 -10
  107. package/dist/snaps/index.mjs +9 -9
  108. package/dist/snaps/location/index.js +4 -4
  109. package/dist/snaps/location/index.mjs +4 -4
  110. package/dist/snaps/location/location.js +3 -3
  111. package/dist/snaps/location/location.mjs +2 -2
  112. package/dist/tsconfig.build.tsbuildinfo +1 -1
  113. package/dist/types/controllers.js +2 -0
  114. package/dist/types/controllers.js.map +1 -0
  115. package/dist/types/controllers.mjs +2 -0
  116. package/dist/types/controllers.mjs.map +1 -0
  117. package/dist/types/index.d.ts +1 -0
  118. package/dist/types/index.js +2 -1
  119. package/dist/types/index.mjs +1 -0
  120. package/dist/types/insights/SnapInsightsController.d.ts +33 -0
  121. package/dist/types/insights/index.d.ts +1 -0
  122. package/dist/types/interface/SnapInterfaceController.d.ts +17 -2
  123. package/dist/types/types/controllers.d.ts +131 -0
  124. package/dist/types/types/index.d.ts +1 -0
  125. package/dist/types/utils.d.ts +0 -13
  126. package/dist/utils.js +2 -4
  127. package/dist/utils.mjs +1 -3
  128. package/package.json +14 -14
  129. package/dist/chunk-567BFPSL.mjs.map +0 -1
  130. package/dist/chunk-BUHS4M6F.js.map +0 -1
  131. package/dist/chunk-CDTGUNSA.js.map +0 -1
  132. package/dist/chunk-E52MHHG4.js.map +0 -1
  133. package/dist/chunk-NZKBY2N7.mjs.map +0 -1
  134. package/dist/chunk-QLFH3MC6.mjs.map +0 -1
  135. package/dist/chunk-WP3DAIFM.mjs.map +0 -1
  136. /package/dist/{chunk-42ODFZSH.mjs.map → chunk-2AEM5R2M.mjs.map} +0 -0
  137. /package/dist/{chunk-XSFI32LB.mjs.map → chunk-33RRV7F4.mjs.map} +0 -0
  138. /package/dist/{chunk-SAAURQ5A.mjs.map → chunk-6WGCLJGC.mjs.map} +0 -0
  139. /package/dist/{chunk-FPGAQ6MT.js.map → chunk-7BUNUNUC.js.map} +0 -0
  140. /package/dist/{chunk-3AANDIXT.js.map → chunk-D66YLO7T.js.map} +0 -0
  141. /package/dist/{chunk-KH72WRHR.js.map → chunk-FZOI4WPB.js.map} +0 -0
  142. /package/dist/{chunk-7IJQGFT5.mjs.map → chunk-HLQQTAMM.mjs.map} +0 -0
  143. /package/dist/{chunk-RW7AYHRG.js.map → chunk-KELDSV7H.js.map} +0 -0
  144. /package/dist/{chunk-PMZXFAQI.mjs.map → chunk-KYRKZ3RH.mjs.map} +0 -0
  145. /package/dist/{chunk-LRVK45HN.mjs.map → chunk-LDL6LJ3P.mjs.map} +0 -0
  146. /package/dist/{chunk-6ERB63FH.js.map → chunk-OVATPF5I.js.map} +0 -0
  147. /package/dist/{chunk-HQ6HMINL.js.map → chunk-P66VIDFG.js.map} +0 -0
  148. /package/dist/{chunk-PT22IXNS.js.map → chunk-POQSARDG.js.map} +0 -0
  149. /package/dist/{chunk-ZRC46TUF.js.map → chunk-PYSDWIVK.js.map} +0 -0
  150. /package/dist/{chunk-YUWYMNIX.mjs.map → chunk-VKMY6CKT.mjs.map} +0 -0
  151. /package/dist/{chunk-CIFVYFJW.mjs.map → chunk-WR7CVDEY.mjs.map} +0 -0
  152. /package/dist/{chunk-GRBWVPLF.js.map → chunk-XFUP7RFI.js.map} +0 -0
  153. /package/dist/{chunk-3A72M4GC.mjs.map → chunk-XOSHP4J3.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,40 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [9.3.1]
10
+ ### Changed
11
+ - Bump `@metamask/approval-controller` from `^7.0.0` to `^7.0.2` ([#2593](https://github.com/metamask/snaps/pull/2593))
12
+ - Bump `@metamask/base-controller` from `^6.0.1` to `^6.0.2` ([#2593](https://github.com/metamask/snaps/pull/2593))
13
+ - Bump `@metamask/json-rpc-engine` from `^9.0.0` to `^9.0.2` ([#2593](https://github.com/metamask/snaps/pull/2593))
14
+ - Bump `@metamask/json-rpc-middleware-stream` from `^8.0.0` to `^8.0.2` ([#2593](https://github.com/metamask/snaps/pull/2593))
15
+ - Bump `@metamask/permission-controller` from `^10.0.1` to `^11.0.0` ([#2593](https://github.com/metamask/snaps/pull/2593))
16
+ - Bump `@metamask/phishing-controller` from `^10.0.0` to `^10.1.1` ([#2593](https://github.com/metamask/snaps/pull/2593))
17
+ - Bump `@metamask/snaps-utils` from `^7.8.0` to `^7.8.1` ([#2595](https://github.com/MetaMask/snaps/pull/2595))
18
+
19
+ ## [9.3.0]
20
+ ### Added
21
+ - Add `snap_resolveInterface` RPC method to the `SnapInterfaceController` ([#2509](https://github.com/metamask/snaps/pull/2509))
22
+ - Add `SnapInsightsController` ([#2555](https://github.com/metamask/snaps/pull/2555))
23
+
24
+ ### Changed
25
+ - Bump `@metamask/base-controller` from `^6.0.0` to `^6.0.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
26
+ - Bump `@metamask/permission-controller` from `^10.0.0` to `^10.0.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
27
+ - Bump `@metamask/rpc-errors` from `^6.2.1` to `^6.3.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
28
+ - Bump `@metamask/snaps-registry` from `^3.1.0` to `^3.2.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
29
+ - Bump `@metamask/snaps-rpc-methods` to `^10.0.0` ([#2589](https://github.com/MetaMask/snaps/pull/2589))
30
+ - Bump `@metamask/snaps-sdk` to `^6.1.0` ([#2589](https://github.com/MetaMask/snaps/pull/2589))
31
+ - Bump `@metamask/snaps-utils` to `^7.8.0` ([#2589](https://github.com/MetaMask/snaps/pull/2589))
32
+ - Bump `@metamask/utils` from `^8.3.0` to `^9.1.0` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
33
+ - Bump peer dependency `@metamask/snaps-execution-environments` to `^6.6.1` ([#2589](https://github.com/MetaMask/snaps/pull/2589))
34
+
35
+ ### Fixed
36
+ - Handle initial connections for preinstalled Snaps ([#2591](https://github.com/MetaMask/snaps/pull/2591))
37
+ - Account for revoked origins when calculating the difference in `initialConnections` ([#2535](https://github.com/metamask/snaps/pull/2535))
38
+ - Fixes issue of revoking permissions that are already revoked.
39
+ - Enables revoked connections to be highlighted as being re-added in the UI.
40
+ - Enforce stricter size limits for source code, static auxiliary files, and `snap_getFile` return values ([#2527](https://github.com/metamask/snaps/pull/2527))
41
+ - Prevent communication failures by enabling compliance with JSON-RPC extension message requirements.
42
+
9
43
  ## [9.2.0]
10
44
  ### Added
11
45
  - Add feature flag to disable Snap installation ([#2521](https://github.com/MetaMask/snaps/pull/2521))
@@ -307,7 +341,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
307
341
  - The version of the package no longer needs to match the version of all other
308
342
  MetaMask Snaps packages.
309
343
 
310
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.2.0...HEAD
344
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.3.1...HEAD
345
+ [9.3.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.3.0...@metamask/snaps-controllers@9.3.1
346
+ [9.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.2.0...@metamask/snaps-controllers@9.3.0
311
347
  [9.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.1.0...@metamask/snaps-controllers@9.2.0
312
348
  [9.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.0.0...@metamask/snaps-controllers@9.1.0
313
349
  [9.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.4.0...@metamask/snaps-controllers@9.0.0
@@ -15,7 +15,7 @@ import { assert } from "@metamask/utils";
15
15
  import { nanoid } from "nanoid";
16
16
  var MAX_UI_CONTENT_SIZE = 1e7;
17
17
  var controllerName = "SnapInterfaceController";
18
- var _registerMessageHandlers, registerMessageHandlers_fn, _validateArgs, validateArgs_fn, _triggerPhishingListUpdate, triggerPhishingListUpdate_fn, _checkPhishingList, checkPhishingList_fn, _validateContent, validateContent_fn;
18
+ var _registerMessageHandlers, registerMessageHandlers_fn, _validateArgs, validateArgs_fn, _validateApproval, validateApproval_fn, _triggerPhishingListUpdate, triggerPhishingListUpdate_fn, _checkPhishingList, checkPhishingList_fn, _hasApprovalRequest, hasApprovalRequest_fn, _acceptApprovalRequest, acceptApprovalRequest_fn, _validateContent, validateContent_fn;
19
19
  var SnapInterfaceController = class extends BaseController {
20
20
  constructor({ messenger, state }) {
21
21
  super({
@@ -38,6 +38,12 @@ var SnapInterfaceController = class extends BaseController {
38
38
  * @param id - The interface id.
39
39
  */
40
40
  __privateAdd(this, _validateArgs);
41
+ /**
42
+ * Utility function to validate that the approval request exists.
43
+ *
44
+ * @param id - The interface id.
45
+ */
46
+ __privateAdd(this, _validateApproval);
41
47
  /**
42
48
  * Trigger a Phishing list update if needed.
43
49
  */
@@ -49,6 +55,21 @@ var SnapInterfaceController = class extends BaseController {
49
55
  * @returns True if the origin is on the phishing list, otherwise false.
50
56
  */
51
57
  __privateAdd(this, _checkPhishingList);
58
+ /**
59
+ * Check if an approval request exists for a given interface by looking up
60
+ * if the ApprovalController has a request with the given interface ID.
61
+ *
62
+ * @param id - The interface id.
63
+ * @returns True if an approval request exists, otherwise false.
64
+ */
65
+ __privateAdd(this, _hasApprovalRequest);
66
+ /**
67
+ * Accept an approval request for a given interface.
68
+ *
69
+ * @param id - The interface id.
70
+ * @param value - The value to resolve the promise with.
71
+ */
72
+ __privateAdd(this, _acceptApprovalRequest);
52
73
  /**
53
74
  * Utility function to validate the components of an interface.
54
75
  * Throws if something is invalid.
@@ -132,6 +153,20 @@ var SnapInterfaceController = class extends BaseController {
132
153
  draftState.interfaces[id].state = state;
133
154
  });
134
155
  }
156
+ /**
157
+ * Resolve the promise of a given interface approval request.
158
+ * The approval needs to have the same ID as the interface.
159
+ *
160
+ * @param snapId - The snap id.
161
+ * @param id - The interface id.
162
+ * @param value - The value to resolve the promise with.
163
+ */
164
+ async resolveInterface(snapId, id, value) {
165
+ __privateMethod(this, _validateArgs, validateArgs_fn).call(this, snapId, id);
166
+ __privateMethod(this, _validateApproval, validateApproval_fn).call(this, id);
167
+ await __privateMethod(this, _acceptApprovalRequest, acceptApprovalRequest_fn).call(this, id, value);
168
+ this.deleteInterface(id);
169
+ }
135
170
  };
136
171
  _registerMessageHandlers = new WeakSet();
137
172
  registerMessageHandlers_fn = function() {
@@ -155,6 +190,10 @@ registerMessageHandlers_fn = function() {
155
190
  `${controllerName}:updateInterfaceState`,
156
191
  this.updateInterfaceState.bind(this)
157
192
  );
193
+ this.messagingSystem.registerActionHandler(
194
+ `${controllerName}:resolveInterface`,
195
+ this.resolveInterface.bind(this)
196
+ );
158
197
  };
159
198
  _validateArgs = new WeakSet();
160
199
  validateArgs_fn = function(snapId, id) {
@@ -168,6 +207,13 @@ validateArgs_fn = function(snapId, id) {
168
207
  `Interface not created by ${snapId}.`
169
208
  );
170
209
  };
210
+ _validateApproval = new WeakSet();
211
+ validateApproval_fn = function(id) {
212
+ assert(
213
+ __privateMethod(this, _hasApprovalRequest, hasApprovalRequest_fn).call(this, id),
214
+ `Approval request with id '${id}' not found.`
215
+ );
216
+ };
171
217
  _triggerPhishingListUpdate = new WeakSet();
172
218
  triggerPhishingListUpdate_fn = async function() {
173
219
  await this.messagingSystem.call("PhishingController:maybeUpdateState");
@@ -176,6 +222,20 @@ _checkPhishingList = new WeakSet();
176
222
  checkPhishingList_fn = function(origin) {
177
223
  return this.messagingSystem.call("PhishingController:testOrigin", origin).result;
178
224
  };
225
+ _hasApprovalRequest = new WeakSet();
226
+ hasApprovalRequest_fn = function(id) {
227
+ return this.messagingSystem.call("ApprovalController:hasRequest", {
228
+ id
229
+ });
230
+ };
231
+ _acceptApprovalRequest = new WeakSet();
232
+ acceptApprovalRequest_fn = async function(id, value) {
233
+ await this.messagingSystem.call(
234
+ "ApprovalController:acceptRequest",
235
+ id,
236
+ value
237
+ );
238
+ };
179
239
  _validateContent = new WeakSet();
180
240
  validateContent_fn = async function(element) {
181
241
  const size = getJsonSizeUnsafe(element);
@@ -190,4 +250,4 @@ validateContent_fn = async function(element) {
190
250
  export {
191
251
  SnapInterfaceController
192
252
  };
193
- //# sourceMappingURL=chunk-WP3DAIFM.mjs.map
253
+ //# sourceMappingURL=chunk-23PVLQFV.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/interface/SnapInterfaceController.ts"],"sourcesContent":["import type {\n AcceptRequest,\n HasApprovalRequest,\n} from '@metamask/approval-controller';\nimport type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n MaybeUpdateState,\n TestOrigin,\n} from '@metamask/phishing-controller';\nimport type {\n InterfaceState,\n SnapId,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { getJsonSizeUnsafe, validateJsxLinks } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { assert } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport {\n constructState,\n getJsxInterface,\n validateInterfaceContext,\n} from './utils';\n\nconst MAX_UI_CONTENT_SIZE = 10_000_000; // 10 mb\n\nconst controllerName = 'SnapInterfaceController';\n\nexport type CreateInterface = {\n type: `${typeof controllerName}:createInterface`;\n handler: SnapInterfaceController['createInterface'];\n};\n\nexport type GetInterface = {\n type: `${typeof controllerName}:getInterface`;\n handler: SnapInterfaceController['getInterface'];\n};\n\nexport type UpdateInterface = {\n type: `${typeof controllerName}:updateInterface`;\n handler: SnapInterfaceController['updateInterface'];\n};\n\nexport type DeleteInterface = {\n type: `${typeof controllerName}:deleteInterface`;\n handler: SnapInterfaceController['deleteInterface'];\n};\n\nexport type UpdateInterfaceState = {\n type: `${typeof controllerName}:updateInterfaceState`;\n handler: SnapInterfaceController['updateInterfaceState'];\n};\n\nexport type ResolveInterface = {\n type: `${typeof controllerName}:resolveInterface`;\n handler: SnapInterfaceController['resolveInterface'];\n};\n\nexport type SnapInterfaceControllerAllowedActions =\n | TestOrigin\n | MaybeUpdateState\n | HasApprovalRequest\n | AcceptRequest;\n\nexport type SnapInterfaceControllerActions =\n | CreateInterface\n | GetInterface\n | UpdateInterface\n | DeleteInterface\n | UpdateInterfaceState\n | ResolveInterface;\n\nexport type SnapInterfaceControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions,\n never,\n SnapInterfaceControllerAllowedActions['type'],\n never\n>;\n\nexport type StoredInterface = {\n snapId: SnapId;\n content: JSXElement;\n state: InterfaceState;\n context: InterfaceContext | null;\n};\n\nexport type SnapInterfaceControllerState = {\n interfaces: Record<string, StoredInterface>;\n};\n\nexport type SnapInterfaceControllerArgs = {\n messenger: SnapInterfaceControllerMessenger;\n state?: SnapInterfaceControllerState;\n};\n\n/**\n * Use this controller to manage snaps UI interfaces using RPC method hooks.\n */\nexport class SnapInterfaceController extends BaseController<\n typeof controllerName,\n SnapInterfaceControllerState,\n SnapInterfaceControllerMessenger\n> {\n constructor({ messenger, state }: SnapInterfaceControllerArgs) {\n super({\n messenger,\n metadata: {\n interfaces: { persist: false, anonymous: false },\n },\n name: controllerName,\n state: { interfaces: {}, ...state },\n });\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:createInterface`,\n this.createInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getInterface`,\n this.getInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateInterface`,\n this.updateInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:deleteInterface`,\n this.deleteInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateInterfaceState`,\n this.updateInterfaceState.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:resolveInterface`,\n this.resolveInterface.bind(this),\n );\n }\n\n /**\n * Create an interface in the controller state with the associated data.\n *\n * @param snapId - The snap id that created the interface.\n * @param content - The interface content.\n * @param context - An optional interface context object.\n * @returns The newly interface id.\n */\n async createInterface(\n snapId: SnapId,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) {\n const element = getJsxInterface(content);\n await this.#validateContent(element);\n validateInterfaceContext(context);\n\n const id = nanoid();\n const componentState = constructState({}, element);\n\n this.update((draftState) => {\n // @ts-expect-error - TS2589: Type instantiation is excessively deep and\n // possibly infinite.\n draftState.interfaces[id] = {\n snapId,\n content: element,\n state: componentState,\n context: context ?? null,\n };\n });\n\n return id;\n }\n\n /**\n * Get the data of a given interface id.\n *\n * @param snapId - The snap id requesting the interface data.\n * @param id - The interface id.\n * @returns The interface state.\n */\n getInterface(snapId: SnapId, id: string) {\n this.#validateArgs(snapId, id);\n\n return this.state.interfaces[id];\n }\n\n /**\n * Update the interface with the given content.\n *\n * @param snapId - The snap id requesting the update.\n * @param id - The interface id.\n * @param content - The new content.\n */\n async updateInterface(\n snapId: SnapId,\n id: string,\n content: ComponentOrElement,\n ) {\n this.#validateArgs(snapId, id);\n const element = getJsxInterface(content);\n await this.#validateContent(element);\n\n const oldState = this.state.interfaces[id].state;\n const newState = constructState(oldState, element);\n\n this.update((draftState) => {\n draftState.interfaces[id].state = newState;\n draftState.interfaces[id].content = element;\n });\n }\n\n /**\n * Delete an interface from state.\n *\n * @param id - The interface id.\n */\n deleteInterface(id: string) {\n this.update((draftState) => {\n delete draftState.interfaces[id];\n });\n }\n\n /**\n * Update the interface state.\n *\n * @param id - The interface id.\n * @param state - The new state.\n */\n updateInterfaceState(id: string, state: InterfaceState) {\n this.update((draftState) => {\n draftState.interfaces[id].state = state;\n });\n }\n\n /**\n * Resolve the promise of a given interface approval request.\n * The approval needs to have the same ID as the interface.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async resolveInterface(snapId: SnapId, id: string, value: Json) {\n this.#validateArgs(snapId, id);\n this.#validateApproval(id);\n\n await this.#acceptApprovalRequest(id, value);\n\n this.deleteInterface(id);\n }\n\n /**\n * Utility function to validate the args passed to the other methods.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n */\n #validateArgs(snapId: SnapId, id: string) {\n const existingInterface = this.state.interfaces[id];\n\n assert(\n existingInterface !== undefined,\n `Interface with id '${id}' not found.`,\n );\n assert(\n existingInterface.snapId === snapId,\n `Interface not created by ${snapId}.`,\n );\n }\n\n /**\n * Utility function to validate that the approval request exists.\n *\n * @param id - The interface id.\n */\n #validateApproval(id: string) {\n assert(\n this.#hasApprovalRequest(id),\n `Approval request with id '${id}' not found.`,\n );\n }\n\n /**\n * Trigger a Phishing list update if needed.\n */\n async #triggerPhishingListUpdate() {\n await this.messagingSystem.call('PhishingController:maybeUpdateState');\n }\n\n /**\n * Check an origin against the phishing list.\n *\n * @param origin - The origin to check.\n * @returns True if the origin is on the phishing list, otherwise false.\n */\n #checkPhishingList(origin: string) {\n return this.messagingSystem.call('PhishingController:testOrigin', origin)\n .result;\n }\n\n /**\n * Check if an approval request exists for a given interface by looking up\n * if the ApprovalController has a request with the given interface ID.\n *\n * @param id - The interface id.\n * @returns True if an approval request exists, otherwise false.\n */\n #hasApprovalRequest(id: string) {\n return this.messagingSystem.call('ApprovalController:hasRequest', {\n id,\n });\n }\n\n /**\n * Accept an approval request for a given interface.\n *\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async #acceptApprovalRequest(id: string, value: Json) {\n await this.messagingSystem.call(\n 'ApprovalController:acceptRequest',\n id,\n value,\n );\n }\n\n /**\n * Utility function to validate the components of an interface.\n * Throws if something is invalid.\n *\n * @param element - The JSX element to verify.\n */\n async #validateContent(element: JSXElement) {\n // We assume the validity of this JSON to be validated by the caller.\n // E.g., in the RPC method implementation.\n const size = getJsonSizeUnsafe(element);\n assert(\n size <= MAX_UI_CONTENT_SIZE,\n `A Snap UI may not be larger than ${MAX_UI_CONTENT_SIZE / 1000000} MB.`,\n );\n\n await this.#triggerPhishingListUpdate();\n validateJsxLinks(element, this.#checkPhishingList.bind(this));\n }\n}\n"],"mappings":"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","names":[]}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=chunk-272IFIK7.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
@@ -1,12 +1,12 @@
1
1
  import {
2
2
  LocalLocation
3
3
  } from "./chunk-B3UTLNYS.mjs";
4
- import {
5
- NpmLocation
6
- } from "./chunk-WKQRCGUW.mjs";
7
4
  import {
8
5
  HttpLocation
9
6
  } from "./chunk-6GMWL4JR.mjs";
7
+ import {
8
+ NpmLocation
9
+ } from "./chunk-WKQRCGUW.mjs";
10
10
 
11
11
  // src/snaps/location/location.ts
12
12
  import { assert } from "@metamask/utils";
@@ -37,4 +37,4 @@ function detectSnapLocation(location, opts) {
37
37
  export {
38
38
  detectSnapLocation
39
39
  };
40
- //# sourceMappingURL=chunk-42ODFZSH.mjs.map
40
+ //# sourceMappingURL=chunk-2AEM5R2M.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  detectSnapLocation
3
- } from "./chunk-42ODFZSH.mjs";
3
+ } from "./chunk-2AEM5R2M.mjs";
4
4
  import {
5
5
  RequestQueue
6
6
  } from "./chunk-NC5PBDKD.mjs";
@@ -16,13 +16,12 @@ import {
16
16
  log
17
17
  } from "./chunk-4HVWEABQ.mjs";
18
18
  import {
19
- calculateConnectionsChange,
20
19
  fetchSnap,
21
20
  hasTimedOut,
22
21
  permissionsDiff,
23
22
  setDiff,
24
23
  withTimeout
25
- } from "./chunk-567BFPSL.mjs";
24
+ } from "./chunk-KRI4OKC3.mjs";
26
25
  import {
27
26
  Timer
28
27
  } from "./chunk-XO7KDFBY.mjs";
@@ -71,7 +70,8 @@ import {
71
70
  NpmSnapFileNames,
72
71
  OnNameLookupResponseStruct,
73
72
  getLocalizedSnapManifest,
74
- parseJson
73
+ parseJson,
74
+ MAX_FILE_SIZE
75
75
  } from "@metamask/snaps-utils";
76
76
  import {
77
77
  assert,
@@ -119,7 +119,7 @@ function truncateSnap(snap) {
119
119
  return truncatedSnap;
120
120
  }
121
121
  var name = "SnapController";
122
- var _closeAllConnections, _dynamicPermissions, _environmentEndowmentPermissions, _excludedPermissions, _featureFlags, _fetchFunction, _idleTimeCheckInterval, _maxIdleTime, _encryptor, _getMnemonic, _getFeatureFlags, _detectSnapLocation, _snapsRuntimeData, _rollbackSnapshots, _timeoutForLastRequestStatus, _statusMachine, _preinstalledSnaps, _initializeStateMachine, initializeStateMachine_fn, _registerMessageHandlers, registerMessageHandlers_fn, _handlePreinstalledSnaps, handlePreinstalledSnaps_fn, _pollForLastRequestStatus, pollForLastRequestStatus_fn, _blockSnap, blockSnap_fn, _unblockSnap, unblockSnap_fn, _assertIsInstallAllowed, assertIsInstallAllowed_fn, _assertCanInstallSnaps, assertCanInstallSnaps_fn, _assertCanUsePlatform, assertCanUsePlatform_fn, _stopSnapsLastRequestPastMax, stopSnapsLastRequestPastMax_fn, _transition, transition_fn, _terminateSnap, terminateSnap_fn, _getSnapEncryptionKey, getSnapEncryptionKey_fn, _decryptSnapState, decryptSnapState_fn, _encryptSnapState, encryptSnapState_fn, _handleInitialConnections, handleInitialConnections_fn, _addSnapToSubject, addSnapToSubject_fn, _removeSnapFromSubjects, removeSnapFromSubjects_fn, _revokeAllSnapPermissions, revokeAllSnapPermissions_fn, _createApproval, createApproval_fn, _updateApproval, updateApproval_fn, _resolveAllowlistVersion, resolveAllowlistVersion_fn, _add, add_fn, _startSnap, startSnap_fn, _getEndowments, getEndowments_fn, _set, set_fn, _validateSnapPermissions, validateSnapPermissions_fn, _getExecutionTimeout, getExecutionTimeout_fn, _getRpcRequestHandler, getRpcRequestHandler_fn, _createInterface, createInterface_fn, _assertInterfaceExists, assertInterfaceExists_fn, _transformSnapRpcRequestResult, transformSnapRpcRequestResult_fn, _assertSnapRpcRequestResult, assertSnapRpcRequestResult_fn, _recordSnapRpcRequestStart, recordSnapRpcRequestStart_fn, _recordSnapRpcRequestFinish, recordSnapRpcRequestFinish_fn, _getRollbackSnapshot, getRollbackSnapshot_fn, _createRollbackSnapshot, createRollbackSnapshot_fn, _rollbackSnap, rollbackSnap_fn, _rollbackSnaps, rollbackSnaps_fn, _getRuntime, getRuntime_fn, _getRuntimeExpect, getRuntimeExpect_fn, _setupRuntime, setupRuntime_fn, _calculatePermissionsChange, calculatePermissionsChange_fn, _updatePermissions, updatePermissions_fn, _isValidUpdate, isValidUpdate_fn, _callLifecycleHook, callLifecycleHook_fn;
122
+ var _closeAllConnections, _dynamicPermissions, _environmentEndowmentPermissions, _excludedPermissions, _featureFlags, _fetchFunction, _idleTimeCheckInterval, _maxIdleTime, _encryptor, _getMnemonic, _getFeatureFlags, _detectSnapLocation, _snapsRuntimeData, _rollbackSnapshots, _timeoutForLastRequestStatus, _statusMachine, _preinstalledSnaps, _initializeStateMachine, initializeStateMachine_fn, _registerMessageHandlers, registerMessageHandlers_fn, _handlePreinstalledSnaps, handlePreinstalledSnaps_fn, _pollForLastRequestStatus, pollForLastRequestStatus_fn, _blockSnap, blockSnap_fn, _unblockSnap, unblockSnap_fn, _assertIsInstallAllowed, assertIsInstallAllowed_fn, _assertCanInstallSnaps, assertCanInstallSnaps_fn, _assertCanUsePlatform, assertCanUsePlatform_fn, _stopSnapsLastRequestPastMax, stopSnapsLastRequestPastMax_fn, _transition, transition_fn, _terminateSnap, terminateSnap_fn, _getSnapEncryptionKey, getSnapEncryptionKey_fn, _decryptSnapState, decryptSnapState_fn, _encryptSnapState, encryptSnapState_fn, _handleInitialConnections, handleInitialConnections_fn, _addSnapToSubject, addSnapToSubject_fn, _removeSnapFromSubjects, removeSnapFromSubjects_fn, _revokeAllSnapPermissions, revokeAllSnapPermissions_fn, _createApproval, createApproval_fn, _updateApproval, updateApproval_fn, _resolveAllowlistVersion, resolveAllowlistVersion_fn, _add, add_fn, _startSnap, startSnap_fn, _getEndowments, getEndowments_fn, _set, set_fn, _validateSnapPermissions, validateSnapPermissions_fn, _getExecutionTimeout, getExecutionTimeout_fn, _getRpcRequestHandler, getRpcRequestHandler_fn, _createInterface, createInterface_fn, _assertInterfaceExists, assertInterfaceExists_fn, _transformSnapRpcRequestResult, transformSnapRpcRequestResult_fn, _assertSnapRpcRequestResult, assertSnapRpcRequestResult_fn, _recordSnapRpcRequestStart, recordSnapRpcRequestStart_fn, _recordSnapRpcRequestFinish, recordSnapRpcRequestFinish_fn, _getRollbackSnapshot, getRollbackSnapshot_fn, _createRollbackSnapshot, createRollbackSnapshot_fn, _rollbackSnap, rollbackSnap_fn, _rollbackSnaps, rollbackSnaps_fn, _getRuntime, getRuntime_fn, _getRuntimeExpect, getRuntimeExpect_fn, _setupRuntime, setupRuntime_fn, _calculatePermissionsChange, calculatePermissionsChange_fn, _isSubjectConnectedToSnap, isSubjectConnectedToSnap_fn, _calculateConnectionsChange, calculateConnectionsChange_fn, _updatePermissions, updatePermissions_fn, _isValidUpdate, isValidUpdate_fn, _callLifecycleHook, callLifecycleHook_fn;
123
123
  var SnapController = class extends BaseController {
124
124
  constructor({
125
125
  closeAllConnections,
@@ -405,6 +405,8 @@ var SnapController = class extends BaseController {
405
405
  __privateAdd(this, _getRuntimeExpect);
406
406
  __privateAdd(this, _setupRuntime);
407
407
  __privateAdd(this, _calculatePermissionsChange);
408
+ __privateAdd(this, _isSubjectConnectedToSnap);
409
+ __privateAdd(this, _calculateConnectionsChange);
408
410
  /**
409
411
  * Updates the permissions for a snap following an install, update or rollback.
410
412
  *
@@ -809,7 +811,12 @@ var SnapController = class extends BaseController {
809
811
  if (!value) {
810
812
  return null;
811
813
  }
812
- return encodeAuxiliaryFile(value, encoding);
814
+ const encoded = await encodeAuxiliaryFile(value, encoding);
815
+ assert(
816
+ encoded.length < MAX_FILE_SIZE,
817
+ `Failed to encode static file to "${encoding}": Static files must be less than 64 MB when encoded.`
818
+ );
819
+ return encoded;
813
820
  }
814
821
  /**
815
822
  * Completely clear the controller's state: delete all associated data,
@@ -1228,10 +1235,7 @@ var SnapController = class extends BaseController {
1228
1235
  );
1229
1236
  __privateMethod(this, _validateSnapPermissions, validateSnapPermissions_fn).call(this, processedPermissions);
1230
1237
  const { newPermissions, unusedPermissions, approvedPermissions } = __privateMethod(this, _calculatePermissionsChange, calculatePermissionsChange_fn).call(this, snapId, processedPermissions);
1231
- const { newConnections, unusedConnections, approvedConnections } = calculateConnectionsChange(
1232
- oldManifest.initialConnections ?? {},
1233
- manifest.initialConnections ?? {}
1234
- );
1238
+ const { newConnections, unusedConnections, approvedConnections } = __privateMethod(this, _calculateConnectionsChange, calculateConnectionsChange_fn).call(this, snapId, oldManifest.initialConnections ?? {}, manifest.initialConnections ?? {});
1235
1239
  __privateMethod(this, _updateApproval, updateApproval_fn).call(this, pendingApproval.id, {
1236
1240
  permissions: newPermissions,
1237
1241
  newVersion: manifest.version,
@@ -1668,6 +1672,9 @@ handlePreinstalledSnaps_fn = function(preinstalledSnaps) {
1668
1672
  __privateMethod(this, _validateSnapPermissions, validateSnapPermissions_fn).call(this, processedPermissions);
1669
1673
  const { newPermissions, unusedPermissions } = __privateMethod(this, _calculatePermissionsChange, calculatePermissionsChange_fn).call(this, snapId, processedPermissions);
1670
1674
  __privateMethod(this, _updatePermissions, updatePermissions_fn).call(this, { snapId, newPermissions, unusedPermissions });
1675
+ if (manifest.initialConnections) {
1676
+ __privateMethod(this, _handleInitialConnections, handleInitialConnections_fn).call(this, snapId, existingSnap?.initialConnections ?? null, manifest.initialConnections);
1677
+ }
1671
1678
  this.update((state) => {
1672
1679
  state.snaps[snapId].status = SnapStatus.Stopped;
1673
1680
  });
@@ -2447,6 +2454,35 @@ calculatePermissionsChange_fn = function(snapId, desiredPermissionsSet) {
2447
2454
  );
2448
2455
  return { newPermissions, unusedPermissions, approvedPermissions };
2449
2456
  };
2457
+ _isSubjectConnectedToSnap = new WeakSet();
2458
+ isSubjectConnectedToSnap_fn = function(snapId, origin) {
2459
+ const subjectPermissions = this.messagingSystem.call(
2460
+ "PermissionController:getPermissions",
2461
+ origin
2462
+ );
2463
+ const existingCaveat = subjectPermissions?.[WALLET_SNAP_PERMISSION_KEY]?.caveats?.find((caveat) => caveat.type === SnapCaveatType.SnapIds);
2464
+ return Boolean(existingCaveat?.value?.[snapId]);
2465
+ };
2466
+ _calculateConnectionsChange = new WeakSet();
2467
+ calculateConnectionsChange_fn = function(snapId, oldConnectionsSet, desiredConnectionsSet) {
2468
+ const filteredOldConnections = Object.keys(oldConnectionsSet).filter((origin) => __privateMethod(this, _isSubjectConnectedToSnap, isSubjectConnectedToSnap_fn).call(this, snapId, origin)).reduce((accumulator, origin) => {
2469
+ accumulator[origin] = oldConnectionsSet[origin];
2470
+ return accumulator;
2471
+ }, {});
2472
+ const newConnections = setDiff(
2473
+ desiredConnectionsSet,
2474
+ filteredOldConnections
2475
+ );
2476
+ const unusedConnections = setDiff(
2477
+ filteredOldConnections,
2478
+ desiredConnectionsSet
2479
+ );
2480
+ const approvedConnections = setDiff(
2481
+ filteredOldConnections,
2482
+ unusedConnections
2483
+ );
2484
+ return { newConnections, unusedConnections, approvedConnections };
2485
+ };
2450
2486
  _updatePermissions = new WeakSet();
2451
2487
  updatePermissions_fn = function({
2452
2488
  snapId,
@@ -2509,4 +2545,4 @@ export {
2509
2545
  SNAP_APPROVAL_RESULT,
2510
2546
  SnapController
2511
2547
  };
2512
- //# sourceMappingURL=chunk-NZKBY2N7.mjs.map
2548
+ //# sourceMappingURL=chunk-2MH7QYBP.mjs.map