@metamask/snaps-controllers 18.0.4 → 19.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (288) hide show
  1. package/CHANGELOG.md +96 -1
  2. package/dist/cronjob/CronjobController-method-action-types.cjs +7 -0
  3. package/dist/cronjob/CronjobController-method-action-types.cjs.map +1 -0
  4. package/dist/cronjob/CronjobController-method-action-types.d.cts +51 -0
  5. package/dist/cronjob/CronjobController-method-action-types.d.cts.map +1 -0
  6. package/dist/cronjob/CronjobController-method-action-types.d.mts +51 -0
  7. package/dist/cronjob/CronjobController-method-action-types.d.mts.map +1 -0
  8. package/dist/cronjob/CronjobController-method-action-types.mjs +6 -0
  9. package/dist/cronjob/CronjobController-method-action-types.mjs.map +1 -0
  10. package/dist/cronjob/CronjobController.cjs +7 -4
  11. package/dist/cronjob/CronjobController.cjs.map +1 -1
  12. package/dist/cronjob/CronjobController.d.cts +7 -24
  13. package/dist/cronjob/CronjobController.d.cts.map +1 -1
  14. package/dist/cronjob/CronjobController.d.mts +7 -24
  15. package/dist/cronjob/CronjobController.d.mts.map +1 -1
  16. package/dist/cronjob/CronjobController.mjs +7 -4
  17. package/dist/cronjob/CronjobController.mjs.map +1 -1
  18. package/dist/cronjob/index.cjs +3 -15
  19. package/dist/cronjob/index.cjs.map +1 -1
  20. package/dist/cronjob/index.d.cts +3 -1
  21. package/dist/cronjob/index.d.cts.map +1 -1
  22. package/dist/cronjob/index.d.mts +3 -1
  23. package/dist/cronjob/index.d.mts.map +1 -1
  24. package/dist/cronjob/index.mjs +1 -1
  25. package/dist/cronjob/index.mjs.map +1 -1
  26. package/dist/insights/SnapInsightsController.cjs +1 -3
  27. package/dist/insights/SnapInsightsController.cjs.map +1 -1
  28. package/dist/insights/SnapInsightsController.d.cts +8 -8
  29. package/dist/insights/SnapInsightsController.d.cts.map +1 -1
  30. package/dist/insights/SnapInsightsController.d.mts +8 -8
  31. package/dist/insights/SnapInsightsController.d.mts.map +1 -1
  32. package/dist/insights/SnapInsightsController.mjs +1 -3
  33. package/dist/insights/SnapInsightsController.mjs.map +1 -1
  34. package/dist/insights/index.cjs +3 -15
  35. package/dist/insights/index.cjs.map +1 -1
  36. package/dist/insights/index.d.cts +2 -1
  37. package/dist/insights/index.d.cts.map +1 -1
  38. package/dist/insights/index.d.mts +2 -1
  39. package/dist/insights/index.d.mts.map +1 -1
  40. package/dist/insights/index.mjs +1 -1
  41. package/dist/insights/index.mjs.map +1 -1
  42. package/dist/interface/SnapInterfaceController-method-action-types.cjs +7 -0
  43. package/dist/interface/SnapInterfaceController-method-action-types.cjs.map +1 -0
  44. package/dist/interface/SnapInterfaceController-method-action-types.d.cts +99 -0
  45. package/dist/interface/SnapInterfaceController-method-action-types.d.cts.map +1 -0
  46. package/dist/interface/SnapInterfaceController-method-action-types.d.mts +99 -0
  47. package/dist/interface/SnapInterfaceController-method-action-types.d.mts.map +1 -0
  48. package/dist/interface/SnapInterfaceController-method-action-types.mjs +6 -0
  49. package/dist/interface/SnapInterfaceController-method-action-types.mjs.map +1 -0
  50. package/dist/interface/SnapInterfaceController.cjs +12 -16
  51. package/dist/interface/SnapInterfaceController.cjs.map +1 -1
  52. package/dist/interface/SnapInterfaceController.d.cts +9 -39
  53. package/dist/interface/SnapInterfaceController.d.cts.map +1 -1
  54. package/dist/interface/SnapInterfaceController.d.mts +9 -39
  55. package/dist/interface/SnapInterfaceController.d.mts.map +1 -1
  56. package/dist/interface/SnapInterfaceController.mjs +12 -16
  57. package/dist/interface/SnapInterfaceController.mjs.map +1 -1
  58. package/dist/interface/index.cjs +3 -15
  59. package/dist/interface/index.cjs.map +1 -1
  60. package/dist/interface/index.d.cts +3 -1
  61. package/dist/interface/index.d.cts.map +1 -1
  62. package/dist/interface/index.d.mts +3 -1
  63. package/dist/interface/index.d.mts.map +1 -1
  64. package/dist/interface/index.mjs +1 -1
  65. package/dist/interface/index.mjs.map +1 -1
  66. package/dist/multichain/MultichainRoutingService-method-action-types.cjs +7 -0
  67. package/dist/multichain/MultichainRoutingService-method-action-types.cjs.map +1 -0
  68. package/dist/multichain/MultichainRoutingService-method-action-types.d.cts +61 -0
  69. package/dist/multichain/MultichainRoutingService-method-action-types.d.cts.map +1 -0
  70. package/dist/multichain/MultichainRoutingService-method-action-types.d.mts +61 -0
  71. package/dist/multichain/MultichainRoutingService-method-action-types.d.mts.map +1 -0
  72. package/dist/multichain/MultichainRoutingService-method-action-types.mjs +6 -0
  73. package/dist/multichain/MultichainRoutingService-method-action-types.mjs.map +1 -0
  74. package/dist/multichain/{MultichainRouter.cjs → MultichainRoutingService.cjs} +14 -13
  75. package/dist/multichain/MultichainRoutingService.cjs.map +1 -0
  76. package/dist/multichain/{MultichainRouter.d.mts → MultichainRoutingService.d.cts} +13 -28
  77. package/dist/multichain/MultichainRoutingService.d.cts.map +1 -0
  78. package/dist/multichain/{MultichainRouter.d.cts → MultichainRoutingService.d.mts} +13 -28
  79. package/dist/multichain/MultichainRoutingService.d.mts.map +1 -0
  80. package/dist/multichain/{MultichainRouter.mjs → MultichainRoutingService.mjs} +12 -11
  81. package/dist/multichain/MultichainRoutingService.mjs.map +1 -0
  82. package/dist/multichain/index.cjs +3 -15
  83. package/dist/multichain/index.cjs.map +1 -1
  84. package/dist/multichain/index.d.cts +3 -1
  85. package/dist/multichain/index.d.cts.map +1 -1
  86. package/dist/multichain/index.d.mts +3 -1
  87. package/dist/multichain/index.d.mts.map +1 -1
  88. package/dist/multichain/index.mjs +1 -1
  89. package/dist/multichain/index.mjs.map +1 -1
  90. package/dist/services/ExecutionService-method-action-types.cjs +7 -0
  91. package/dist/services/ExecutionService-method-action-types.cjs.map +1 -0
  92. package/dist/services/ExecutionService-method-action-types.d.cts +50 -0
  93. package/dist/services/ExecutionService-method-action-types.d.cts.map +1 -0
  94. package/dist/services/ExecutionService-method-action-types.d.mts +50 -0
  95. package/dist/services/ExecutionService-method-action-types.d.mts.map +1 -0
  96. package/dist/services/ExecutionService-method-action-types.mjs +6 -0
  97. package/dist/services/ExecutionService-method-action-types.mjs.map +1 -0
  98. package/dist/services/ExecutionService.cjs +287 -0
  99. package/dist/services/ExecutionService.cjs.map +1 -1
  100. package/dist/services/ExecutionService.d.cts +100 -46
  101. package/dist/services/ExecutionService.d.cts.map +1 -1
  102. package/dist/services/ExecutionService.d.mts +100 -46
  103. package/dist/services/ExecutionService.d.mts.map +1 -1
  104. package/dist/services/ExecutionService.mjs +285 -1
  105. package/dist/services/ExecutionService.mjs.map +1 -1
  106. package/dist/services/browser.cjs +5 -2
  107. package/dist/services/browser.cjs.map +1 -1
  108. package/dist/services/browser.d.cts +4 -2
  109. package/dist/services/browser.d.cts.map +1 -1
  110. package/dist/services/browser.d.mts +4 -2
  111. package/dist/services/browser.d.mts.map +1 -1
  112. package/dist/services/browser.mjs +2 -2
  113. package/dist/services/browser.mjs.map +1 -1
  114. package/dist/services/iframe/IframeExecutionService.cjs +2 -2
  115. package/dist/services/iframe/IframeExecutionService.cjs.map +1 -1
  116. package/dist/services/iframe/IframeExecutionService.d.cts +3 -3
  117. package/dist/services/iframe/IframeExecutionService.d.cts.map +1 -1
  118. package/dist/services/iframe/IframeExecutionService.d.mts +3 -3
  119. package/dist/services/iframe/IframeExecutionService.d.mts.map +1 -1
  120. package/dist/services/iframe/IframeExecutionService.mjs +2 -2
  121. package/dist/services/iframe/IframeExecutionService.mjs.map +1 -1
  122. package/dist/services/index.cjs +5 -1
  123. package/dist/services/index.cjs.map +1 -1
  124. package/dist/services/index.d.cts +4 -2
  125. package/dist/services/index.d.cts.map +1 -1
  126. package/dist/services/index.d.mts +4 -2
  127. package/dist/services/index.d.mts.map +1 -1
  128. package/dist/services/index.mjs +2 -1
  129. package/dist/services/index.mjs.map +1 -1
  130. package/dist/services/multiplex.cjs +27 -0
  131. package/dist/services/multiplex.cjs.map +1 -0
  132. package/dist/services/multiplex.d.cts +11 -0
  133. package/dist/services/multiplex.d.cts.map +1 -0
  134. package/dist/services/multiplex.d.mts +11 -0
  135. package/dist/services/multiplex.d.mts.map +1 -0
  136. package/dist/services/multiplex.mjs +27 -0
  137. package/dist/services/multiplex.mjs.map +1 -0
  138. package/dist/services/node-js/NodeProcessExecutionService.cjs +2 -2
  139. package/dist/services/node-js/NodeProcessExecutionService.cjs.map +1 -1
  140. package/dist/services/node-js/NodeProcessExecutionService.d.cts +3 -3
  141. package/dist/services/node-js/NodeProcessExecutionService.d.cts.map +1 -1
  142. package/dist/services/node-js/NodeProcessExecutionService.d.mts +3 -3
  143. package/dist/services/node-js/NodeProcessExecutionService.d.mts.map +1 -1
  144. package/dist/services/node-js/NodeProcessExecutionService.mjs +2 -2
  145. package/dist/services/node-js/NodeProcessExecutionService.mjs.map +1 -1
  146. package/dist/services/node-js/NodeThreadExecutionService.cjs +2 -5
  147. package/dist/services/node-js/NodeThreadExecutionService.cjs.map +1 -1
  148. package/dist/services/node-js/NodeThreadExecutionService.d.cts +3 -3
  149. package/dist/services/node-js/NodeThreadExecutionService.d.cts.map +1 -1
  150. package/dist/services/node-js/NodeThreadExecutionService.d.mts +3 -3
  151. package/dist/services/node-js/NodeThreadExecutionService.d.mts.map +1 -1
  152. package/dist/services/node-js/NodeThreadExecutionService.mjs +2 -5
  153. package/dist/services/node-js/NodeThreadExecutionService.mjs.map +1 -1
  154. package/dist/services/offscreen/OffscreenExecutionService.cjs.map +1 -1
  155. package/dist/services/offscreen/OffscreenExecutionService.d.cts +1 -1
  156. package/dist/services/offscreen/OffscreenExecutionService.d.cts.map +1 -1
  157. package/dist/services/offscreen/OffscreenExecutionService.d.mts +1 -1
  158. package/dist/services/offscreen/OffscreenExecutionService.d.mts.map +1 -1
  159. package/dist/services/offscreen/OffscreenExecutionService.mjs.map +1 -1
  160. package/dist/services/proxy/ProxyExecutionService.cjs +2 -5
  161. package/dist/services/proxy/ProxyExecutionService.cjs.map +1 -1
  162. package/dist/services/proxy/ProxyExecutionService.d.cts +3 -3
  163. package/dist/services/proxy/ProxyExecutionService.d.cts.map +1 -1
  164. package/dist/services/proxy/ProxyExecutionService.d.mts +3 -3
  165. package/dist/services/proxy/ProxyExecutionService.d.mts.map +1 -1
  166. package/dist/services/proxy/ProxyExecutionService.mjs +2 -5
  167. package/dist/services/proxy/ProxyExecutionService.mjs.map +1 -1
  168. package/dist/services/webview/WebViewExecutionService.cjs +2 -2
  169. package/dist/services/webview/WebViewExecutionService.cjs.map +1 -1
  170. package/dist/services/webview/WebViewExecutionService.d.cts +3 -3
  171. package/dist/services/webview/WebViewExecutionService.d.cts.map +1 -1
  172. package/dist/services/webview/WebViewExecutionService.d.mts +3 -3
  173. package/dist/services/webview/WebViewExecutionService.d.mts.map +1 -1
  174. package/dist/services/webview/WebViewExecutionService.mjs +2 -2
  175. package/dist/services/webview/WebViewExecutionService.mjs.map +1 -1
  176. package/dist/snaps/SnapController-method-action-types.cjs +7 -0
  177. package/dist/snaps/SnapController-method-action-types.cjs.map +1 -0
  178. package/dist/snaps/SnapController-method-action-types.d.cts +284 -0
  179. package/dist/snaps/SnapController-method-action-types.d.cts.map +1 -0
  180. package/dist/snaps/SnapController-method-action-types.d.mts +284 -0
  181. package/dist/snaps/SnapController-method-action-types.d.mts.map +1 -0
  182. package/dist/snaps/SnapController-method-action-types.mjs +6 -0
  183. package/dist/snaps/SnapController-method-action-types.mjs.map +1 -0
  184. package/dist/snaps/SnapController.cjs +118 -113
  185. package/dist/snaps/SnapController.cjs.map +1 -1
  186. package/dist/snaps/SnapController.d.cts +32 -189
  187. package/dist/snaps/SnapController.d.cts.map +1 -1
  188. package/dist/snaps/SnapController.d.mts +32 -189
  189. package/dist/snaps/SnapController.d.mts.map +1 -1
  190. package/dist/snaps/SnapController.mjs +119 -114
  191. package/dist/snaps/SnapController.mjs.map +1 -1
  192. package/dist/snaps/index.cjs +3 -1
  193. package/dist/snaps/index.cjs.map +1 -1
  194. package/dist/snaps/index.d.cts +3 -1
  195. package/dist/snaps/index.d.cts.map +1 -1
  196. package/dist/snaps/index.d.mts +3 -1
  197. package/dist/snaps/index.d.mts.map +1 -1
  198. package/dist/snaps/index.mjs +1 -1
  199. package/dist/snaps/index.mjs.map +1 -1
  200. package/dist/snaps/registry/SnapRegistryController-method-action-types.cjs +7 -0
  201. package/dist/snaps/registry/SnapRegistryController-method-action-types.cjs.map +1 -0
  202. package/dist/snaps/registry/SnapRegistryController-method-action-types.d.cts +46 -0
  203. package/dist/snaps/registry/SnapRegistryController-method-action-types.d.cts.map +1 -0
  204. package/dist/snaps/registry/SnapRegistryController-method-action-types.d.mts +46 -0
  205. package/dist/snaps/registry/SnapRegistryController-method-action-types.d.mts.map +1 -0
  206. package/dist/snaps/registry/SnapRegistryController-method-action-types.mjs +6 -0
  207. package/dist/snaps/registry/SnapRegistryController-method-action-types.mjs.map +1 -0
  208. package/dist/snaps/registry/{json.cjs → SnapRegistryController.cjs} +27 -24
  209. package/dist/snaps/registry/SnapRegistryController.cjs.map +1 -0
  210. package/dist/snaps/registry/SnapRegistryController.d.cts +67 -0
  211. package/dist/snaps/registry/SnapRegistryController.d.cts.map +1 -0
  212. package/dist/snaps/registry/SnapRegistryController.d.mts +67 -0
  213. package/dist/snaps/registry/SnapRegistryController.d.mts.map +1 -0
  214. package/dist/snaps/registry/{json.mjs → SnapRegistryController.mjs} +25 -22
  215. package/dist/snaps/registry/SnapRegistryController.mjs.map +1 -0
  216. package/dist/snaps/registry/index.cjs +5 -16
  217. package/dist/snaps/registry/index.cjs.map +1 -1
  218. package/dist/snaps/registry/index.d.cts +5 -2
  219. package/dist/snaps/registry/index.d.cts.map +1 -1
  220. package/dist/snaps/registry/index.d.mts +5 -2
  221. package/dist/snaps/registry/index.d.mts.map +1 -1
  222. package/dist/snaps/registry/index.mjs +2 -2
  223. package/dist/snaps/registry/index.mjs.map +1 -1
  224. package/dist/snaps/registry/types.cjs +11 -0
  225. package/dist/snaps/registry/types.cjs.map +1 -0
  226. package/dist/snaps/registry/types.d.cts +20 -0
  227. package/dist/snaps/registry/types.d.cts.map +1 -0
  228. package/dist/snaps/registry/types.d.mts +20 -0
  229. package/dist/snaps/registry/types.d.mts.map +1 -0
  230. package/dist/snaps/registry/types.mjs +8 -0
  231. package/dist/snaps/registry/types.mjs.map +1 -0
  232. package/dist/types/controllers.cjs.map +1 -1
  233. package/dist/types/controllers.d.cts +1 -1
  234. package/dist/types/controllers.d.cts.map +1 -1
  235. package/dist/types/controllers.d.mts +1 -1
  236. package/dist/types/controllers.d.mts.map +1 -1
  237. package/dist/types/controllers.mjs.map +1 -1
  238. package/dist/websocket/WebSocketService-method-action-types.cjs +7 -0
  239. package/dist/websocket/WebSocketService-method-action-types.cjs.map +1 -0
  240. package/dist/websocket/WebSocketService-method-action-types.d.cts +54 -0
  241. package/dist/websocket/WebSocketService-method-action-types.d.cts.map +1 -0
  242. package/dist/websocket/WebSocketService-method-action-types.d.mts +54 -0
  243. package/dist/websocket/WebSocketService-method-action-types.d.mts.map +1 -0
  244. package/dist/websocket/WebSocketService-method-action-types.mjs +6 -0
  245. package/dist/websocket/WebSocketService-method-action-types.mjs.map +1 -0
  246. package/dist/websocket/WebSocketService.cjs +14 -11
  247. package/dist/websocket/WebSocketService.cjs.map +1 -1
  248. package/dist/websocket/WebSocketService.d.cts +43 -22
  249. package/dist/websocket/WebSocketService.d.cts.map +1 -1
  250. package/dist/websocket/WebSocketService.d.mts +43 -22
  251. package/dist/websocket/WebSocketService.d.mts.map +1 -1
  252. package/dist/websocket/WebSocketService.mjs +14 -11
  253. package/dist/websocket/WebSocketService.mjs.map +1 -1
  254. package/dist/websocket/index.cjs +3 -15
  255. package/dist/websocket/index.cjs.map +1 -1
  256. package/dist/websocket/index.d.cts +3 -1
  257. package/dist/websocket/index.d.cts.map +1 -1
  258. package/dist/websocket/index.d.mts +3 -1
  259. package/dist/websocket/index.d.mts.map +1 -1
  260. package/dist/websocket/index.mjs +1 -1
  261. package/dist/websocket/index.mjs.map +1 -1
  262. package/package.json +8 -7
  263. package/dist/multichain/MultichainRouter.cjs.map +0 -1
  264. package/dist/multichain/MultichainRouter.d.cts.map +0 -1
  265. package/dist/multichain/MultichainRouter.d.mts.map +0 -1
  266. package/dist/multichain/MultichainRouter.mjs.map +0 -1
  267. package/dist/services/AbstractExecutionService.cjs +0 -314
  268. package/dist/services/AbstractExecutionService.cjs.map +0 -1
  269. package/dist/services/AbstractExecutionService.d.cts +0 -107
  270. package/dist/services/AbstractExecutionService.d.cts.map +0 -1
  271. package/dist/services/AbstractExecutionService.d.mts +0 -107
  272. package/dist/services/AbstractExecutionService.d.mts.map +0 -1
  273. package/dist/services/AbstractExecutionService.mjs +0 -313
  274. package/dist/services/AbstractExecutionService.mjs.map +0 -1
  275. package/dist/snaps/registry/json.cjs.map +0 -1
  276. package/dist/snaps/registry/json.d.cts +0 -58
  277. package/dist/snaps/registry/json.d.cts.map +0 -1
  278. package/dist/snaps/registry/json.d.mts +0 -58
  279. package/dist/snaps/registry/json.d.mts.map +0 -1
  280. package/dist/snaps/registry/json.mjs.map +0 -1
  281. package/dist/snaps/registry/registry.cjs +0 -11
  282. package/dist/snaps/registry/registry.cjs.map +0 -1
  283. package/dist/snaps/registry/registry.d.cts +0 -41
  284. package/dist/snaps/registry/registry.d.cts.map +0 -1
  285. package/dist/snaps/registry/registry.d.mts +0 -41
  286. package/dist/snaps/registry/registry.d.mts.map +0 -1
  287. package/dist/snaps/registry/registry.mjs +0 -8
  288. package/dist/snaps/registry/registry.mjs.map +0 -1
@@ -1,18 +1,43 @@
1
+ import { JsonRpcEngineV2 as JsonRpcEngine } from "@metamask/json-rpc-engine/v2";
1
2
  import type { Messenger } from "@metamask/messenger";
3
+ import type ObjectMultiplex from "@metamask/object-multiplex";
4
+ import type { BasePostMessageStream } from "@metamask/post-message-stream";
2
5
  import type { SnapRpcHookArgs } from "@metamask/snaps-utils";
3
- import type { Json } from "@metamask/utils";
4
- type TerminateSnap = (snapId: string) => Promise<void>;
5
- type TerminateAll = () => Promise<void>;
6
- type ExecuteSnap = (snapData: SnapExecutionData) => Promise<unknown>;
7
- type HandleRpcRequest = (snapId: string, options: SnapRpcHookArgs) => Promise<unknown>;
8
- export type ExecutionService = {
9
- name: 'ExecutionService';
10
- state: null;
11
- terminateSnap: TerminateSnap;
12
- terminateAllSnaps: TerminateAll;
13
- executeSnap: ExecuteSnap;
14
- handleRpcRequest: HandleRpcRequest;
6
+ import type { Json, JsonRpcRequest } from "@metamask/utils";
7
+ import type { Duplex } from "readable-stream";
8
+ import type { ExecutionServiceMethodActions } from "./ExecutionService-method-action-types.mjs";
9
+ declare const serviceName = "ExecutionService";
10
+ export type SetupSnapProvider = (snapId: string, stream: Duplex) => void;
11
+ export type ExecutionServiceArgs = {
12
+ setupSnapProvider: SetupSnapProvider;
13
+ messenger: ExecutionServiceMessenger;
14
+ initTimeout?: number;
15
+ pingTimeout?: number;
16
+ terminationTimeout?: number;
17
+ usePing?: boolean;
18
+ };
19
+ type JobStreams = {
20
+ command: Duplex;
21
+ rpc: Duplex;
22
+ connection: BasePostMessageStream;
23
+ mux: ObjectMultiplex;
24
+ };
25
+ export type Job<WorkerType> = {
26
+ id: string;
27
+ streams: JobStreams;
28
+ rpcEngine: JsonRpcEngine<JsonRpcRequest>;
29
+ worker: WorkerType;
15
30
  };
31
+ export type TerminateJobArgs<WorkerType> = Partial<Job<WorkerType>> & Pick<Job<WorkerType>, 'id'>;
32
+ /**
33
+ Statuses used for diagnostic purposes
34
+ - created: The initial state, no initialization has started
35
+ - initializing: Snap execution environment is initializing
36
+ - initialized: Snap execution environment has initialized
37
+ - executing: Snap source code is being executed
38
+ - running: Snap executed and ready for RPC requests
39
+ */
40
+ type ExecutionStatus = 'created' | 'initializing' | 'initialized' | 'executing' | 'running';
16
41
  export type SnapExecutionData = {
17
42
  snapId: string;
18
43
  sourceCode: string;
@@ -23,49 +48,78 @@ export type SnapErrorJson = {
23
48
  code: number;
24
49
  data?: Json;
25
50
  };
26
- type ControllerName = 'ExecutionService';
27
- export type ErrorMessageEvent = {
51
+ export type ExecutionServiceUnhandledErrorEvent = {
28
52
  type: 'ExecutionService:unhandledError';
29
53
  payload: [string, SnapErrorJson];
30
54
  };
31
- export type OutboundRequest = {
55
+ export type ExecutionServiceOutboundRequestEvent = {
32
56
  type: 'ExecutionService:outboundRequest';
33
57
  payload: [string];
34
58
  };
35
- export type OutboundResponse = {
59
+ export type ExecutionServiceOutboundResponseEvent = {
36
60
  type: 'ExecutionService:outboundResponse';
37
61
  payload: [string];
38
62
  };
39
- export type ExecutionServiceEvents = ErrorMessageEvent | OutboundRequest | OutboundResponse;
40
- /**
41
- * Handles RPC request.
42
- */
43
- export type HandleRpcRequestAction = {
44
- type: `${ControllerName}:handleRpcRequest`;
45
- handler: ExecutionService['handleRpcRequest'];
46
- };
47
- /**
48
- * Executes a given snap.
49
- */
50
- export type ExecuteSnapAction = {
51
- type: `${ControllerName}:executeSnap`;
52
- handler: ExecutionService['executeSnap'];
53
- };
54
- /**
55
- * Terminates a given snap.
56
- */
57
- export type TerminateSnapAction = {
58
- type: `${ControllerName}:terminateSnap`;
59
- handler: ExecutionService['terminateSnap'];
60
- };
61
- /**
62
- * Terminates all snaps.
63
- */
64
- export type TerminateAllSnapsAction = {
65
- type: `${ControllerName}:terminateAllSnaps`;
66
- handler: ExecutionService['terminateAllSnaps'];
67
- };
68
- export type ExecutionServiceActions = HandleRpcRequestAction | ExecuteSnapAction | TerminateSnapAction | TerminateAllSnapsAction;
63
+ export type ExecutionServiceEvents = ExecutionServiceUnhandledErrorEvent | ExecutionServiceOutboundRequestEvent | ExecutionServiceOutboundResponseEvent;
64
+ export type ExecutionServiceActions = ExecutionServiceMethodActions;
69
65
  export type ExecutionServiceMessenger = Messenger<'ExecutionService', ExecutionServiceActions, ExecutionServiceEvents>;
66
+ export declare abstract class ExecutionService<WorkerType = unknown> {
67
+ #private;
68
+ name: typeof serviceName;
69
+ state: null;
70
+ constructor({ setupSnapProvider, messenger, initTimeout, pingTimeout, terminationTimeout, usePing, }: ExecutionServiceArgs);
71
+ /**
72
+ * Performs additional necessary work during job termination. **MUST** be
73
+ * implemented by concrete implementations. See
74
+ * {@link AbstractExecutionService.terminate} for details.
75
+ *
76
+ * @param job - The object corresponding to the job to be terminated.
77
+ */
78
+ protected abstract terminateJob(job: TerminateJobArgs<WorkerType>): Promise<void>;
79
+ /**
80
+ * Terminates the Snap with the specified ID and deletes all its associated
81
+ * data. Any subsequent messages targeting the Snap will fail with an error.
82
+ * Throws an error if termination fails unexpectedly.
83
+ *
84
+ * @param snapId - The id of the Snap to be terminated.
85
+ */
86
+ terminateSnap(snapId: string): Promise<void>;
87
+ /**
88
+ * Abstract function implemented by implementing class that spins up a new worker for a job.
89
+ *
90
+ * Depending on the execution environment, this may run forever if the Snap fails to start up properly, therefore any call to this function should be wrapped in a timeout.
91
+ */
92
+ protected abstract initEnvStream(snapId: string): Promise<{
93
+ worker: WorkerType;
94
+ stream: BasePostMessageStream;
95
+ }>;
96
+ /**
97
+ * Set the execution status of the Snap.
98
+ *
99
+ * @param snapId - The Snap ID.
100
+ * @param status - The current execution status.
101
+ */
102
+ protected setSnapStatus(snapId: string, status: ExecutionStatus): void;
103
+ terminateAllSnaps(): Promise<void>;
104
+ /**
105
+ * Initializes and executes a Snap, setting up the communication channels to the Snap etc.
106
+ *
107
+ * @param snapData - Data needed for Snap execution.
108
+ * @param snapData.snapId - The ID of the Snap to execute.
109
+ * @param snapData.sourceCode - The source code of the Snap to execute.
110
+ * @param snapData.endowments - The endowments available to the executing Snap.
111
+ * @returns A string `OK` if execution succeeded.
112
+ * @throws If the execution service returns an error or execution times out.
113
+ */
114
+ executeSnap({ snapId, sourceCode, endowments, }: SnapExecutionData): Promise<string>;
115
+ /**
116
+ * Handle RPC request.
117
+ *
118
+ * @param snapId - The ID of the recipient Snap.
119
+ * @param options - Bag of options to pass to the RPC handler.
120
+ * @returns Promise that can handle the request.
121
+ */
122
+ handleRpcRequest(snapId: string, options: SnapRpcHookArgs): Promise<unknown>;
123
+ }
70
124
  export {};
71
125
  //# sourceMappingURL=ExecutionService.d.mts.map
@@ -1 +1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QAAQ,CAAC,YAAY,CAC7B,GAAG,EAAE,gBAAgB,CAAC,UAAU,CAAC,GAChC,OAAO,CAAC,IAAI,CAAC;IAEhB;;;;;;OAMG;IACU,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAgMzD;;;;OAIG;IACH,SAAS,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;QACxD,MAAM,EAAE,UAAU,CAAC;QACnB,MAAM,EAAE,qBAAqB,CAAC;KAC/B,CAAC;IAEF;;;;;OAKG;IACH,SAAS,CAAC,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,eAAe;IAIzD,iBAAiB;IAMvB;;;;;;;;;OASG;IACG,WAAW,CAAC,EAChB,MAAM,EACN,UAAU,EACV,UAAU,GACX,EAAE,iBAAiB,GAAG,OAAO,CAAC,MAAM,CAAC;IAiFtC;;;;;;OAMG;IACU,gBAAgB,CAC3B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,OAAO,CAAC;CAepB"}
@@ -1,2 +1,286 @@
1
- export {};
1
+ import { asV2Middleware } from "@metamask/json-rpc-engine";
2
+ import { JsonRpcEngineV2 as JsonRpcEngine } from "@metamask/json-rpc-engine/v2";
3
+ import { createStreamMiddleware } from "@metamask/json-rpc-middleware-stream";
4
+ import { SNAP_STREAM_NAMES, logError, logWarning } from "@metamask/snaps-utils";
5
+ import { Duration, assertIsJsonRpcRequest, hasProperty, inMilliseconds } from "@metamask/utils";
6
+ import { nanoid } from "nanoid";
7
+ import { pipeline } from "readable-stream";
8
+ import { setupMultiplex } from "./multiplex.mjs";
9
+ import { log } from "../logging.mjs";
10
+ import { Timer } from "../snaps/Timer.mjs";
11
+ import { hasTimedOut, withTimeout } from "../utils.mjs";
12
+ const serviceName = 'ExecutionService';
13
+ const MESSENGER_EXPOSED_METHODS = [
14
+ 'terminateSnap',
15
+ 'terminateAllSnaps',
16
+ 'executeSnap',
17
+ 'handleRpcRequest',
18
+ ];
19
+ export class ExecutionService {
20
+ name = serviceName;
21
+ state = null;
22
+ #jobs;
23
+ #status;
24
+ #setupSnapProvider;
25
+ #messenger;
26
+ #initTimeout;
27
+ #pingTimeout;
28
+ #terminationTimeout;
29
+ #usePing;
30
+ constructor({ setupSnapProvider, messenger, initTimeout = inMilliseconds(60, Duration.Second), pingTimeout = inMilliseconds(10, Duration.Second), terminationTimeout = inMilliseconds(1, Duration.Second), usePing = true, }) {
31
+ this.#jobs = new Map();
32
+ this.#status = new Map();
33
+ this.#setupSnapProvider = setupSnapProvider;
34
+ this.#messenger = messenger;
35
+ this.#initTimeout = initTimeout;
36
+ this.#pingTimeout = pingTimeout;
37
+ this.#terminationTimeout = terminationTimeout;
38
+ this.#usePing = usePing;
39
+ this.#messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
40
+ }
41
+ /**
42
+ * Terminates the Snap with the specified ID and deletes all its associated
43
+ * data. Any subsequent messages targeting the Snap will fail with an error.
44
+ * Throws an error if termination fails unexpectedly.
45
+ *
46
+ * @param snapId - The id of the Snap to be terminated.
47
+ */
48
+ async terminateSnap(snapId) {
49
+ const job = this.#jobs.get(snapId);
50
+ if (!job) {
51
+ return;
52
+ }
53
+ try {
54
+ // Ping worker and tell it to run teardown, continue with termination if it takes too long
55
+ const result = await withTimeout(this.#command(snapId, {
56
+ jsonrpc: '2.0',
57
+ method: 'terminate',
58
+ id: nanoid(),
59
+ }), this.#terminationTimeout);
60
+ if (result === hasTimedOut || result !== 'OK') {
61
+ logWarning(`Snap "${snapId}" failed to terminate gracefully.`);
62
+ }
63
+ }
64
+ catch {
65
+ // Ignore
66
+ }
67
+ Object.values(job.streams).forEach((stream) => {
68
+ try {
69
+ if (!stream.destroyed) {
70
+ stream.destroy();
71
+ }
72
+ }
73
+ catch (error) {
74
+ logError('Error while destroying stream', error);
75
+ }
76
+ });
77
+ await this.terminateJob(job);
78
+ this.#jobs.delete(snapId);
79
+ this.#status.delete(snapId);
80
+ log(`Snap "${snapId}" terminated.`);
81
+ }
82
+ /**
83
+ * Initiates a job for a Snap.
84
+ *
85
+ * @param snapId - The ID of the Snap to initiate a job for.
86
+ * @param timer - The timer to use for timeouts.
87
+ * @returns Information regarding the created job.
88
+ * @throws If the execution service returns an error or execution times out.
89
+ */
90
+ async #initJob(snapId, timer) {
91
+ const { streams, worker } = await this.#initStreams(snapId, timer);
92
+ const jsonRpcConnection = createStreamMiddleware();
93
+ pipeline(jsonRpcConnection.stream, streams.command, jsonRpcConnection.stream, (error) => {
94
+ if (error && !error.message?.match('Premature close')) {
95
+ logError(`Command stream failure.`, error);
96
+ }
97
+ });
98
+ const rpcEngine = JsonRpcEngine.create({
99
+ middleware: [asV2Middleware(jsonRpcConnection.middleware)],
100
+ });
101
+ const envMetadata = {
102
+ id: snapId,
103
+ streams,
104
+ rpcEngine,
105
+ worker,
106
+ };
107
+ this.#jobs.set(snapId, envMetadata);
108
+ return envMetadata;
109
+ }
110
+ /**
111
+ * Sets up the streams for an initiated job.
112
+ *
113
+ * @param snapId - The Snap ID.
114
+ * @param timer - The timer to use for timeouts.
115
+ * @returns The streams to communicate with the worker and the worker itself.
116
+ * @throws If the execution service returns an error or execution times out.
117
+ */
118
+ async #initStreams(snapId, timer) {
119
+ const result = await withTimeout(this.initEnvStream(snapId), timer);
120
+ if (result === hasTimedOut) {
121
+ // For certain environments, such as the iframe we may have already created the worker and wish to terminate it.
122
+ await this.terminateJob({ id: snapId });
123
+ const status = this.#status.get(snapId);
124
+ if (status === 'created') {
125
+ // Currently this error can only be thrown by OffscreenExecutionService.
126
+ throw new Error(`The executor for "${snapId}" couldn't start initialization. The offscreen document may not exist.`);
127
+ }
128
+ throw new Error(`The executor for "${snapId}" failed to initialize. The iframe/webview/worker failed to load.`);
129
+ }
130
+ const { worker, stream: envStream } = result;
131
+ const mux = setupMultiplex(envStream, `Snap: "${snapId}"`);
132
+ const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);
133
+ // Handle out-of-band errors, i.e. errors thrown from the Snap outside of the req/res cycle.
134
+ // Also keep track of outbound request/responses
135
+ const notificationHandler = (message) => {
136
+ if (hasProperty(message, 'id')) {
137
+ return;
138
+ }
139
+ if (message.method === 'OutboundRequest') {
140
+ this.#messenger.publish('ExecutionService:outboundRequest', snapId);
141
+ }
142
+ else if (message.method === 'OutboundResponse') {
143
+ this.#messenger.publish('ExecutionService:outboundResponse', snapId);
144
+ }
145
+ else if (message.method === 'UnhandledError') {
146
+ this.#messenger.publish('ExecutionService:unhandledError', snapId, message.params.error);
147
+ commandStream.removeListener('data', notificationHandler);
148
+ }
149
+ else {
150
+ logError(new Error(`Received unexpected command stream notification "${message.method}".`));
151
+ }
152
+ };
153
+ commandStream.on('data', notificationHandler);
154
+ const rpcStream = mux
155
+ .createStream(SNAP_STREAM_NAMES.JSON_RPC)
156
+ .setMaxListeners(20);
157
+ rpcStream.on('data', (chunk) => {
158
+ if (chunk?.data && hasProperty(chunk?.data, 'id')) {
159
+ this.#messenger.publish('ExecutionService:outboundRequest', snapId);
160
+ }
161
+ });
162
+ // An error handler is not attached to the RPC stream until `setupSnapProvider` is called.
163
+ // We must set it up here to prevent errors from bubbling up if the stream is destroyed before then.
164
+ rpcStream.on('error', (error) => {
165
+ if (error && !error.message?.match('Premature close')) {
166
+ logError(`Snap: "${snapId}" - RPC stream failure:`, error);
167
+ }
168
+ });
169
+ const originalWrite = rpcStream.write.bind(rpcStream);
170
+ // @ts-expect-error Hack to inspect the messages being written to the stream.
171
+ rpcStream.write = (chunk, encoding, callback) => {
172
+ // Ignore chain switching notifications as it doesn't matter for the SnapProvider.
173
+ if (chunk?.data?.method === 'metamask_chainChanged') {
174
+ return true;
175
+ }
176
+ if (chunk?.data && hasProperty(chunk?.data, 'id')) {
177
+ this.#messenger.publish('ExecutionService:outboundResponse', snapId);
178
+ }
179
+ return originalWrite(chunk, encoding, callback);
180
+ };
181
+ return {
182
+ streams: {
183
+ command: commandStream,
184
+ rpc: rpcStream,
185
+ connection: envStream,
186
+ mux,
187
+ },
188
+ worker,
189
+ };
190
+ }
191
+ /**
192
+ * Set the execution status of the Snap.
193
+ *
194
+ * @param snapId - The Snap ID.
195
+ * @param status - The current execution status.
196
+ */
197
+ setSnapStatus(snapId, status) {
198
+ this.#status.set(snapId, status);
199
+ }
200
+ async terminateAllSnaps() {
201
+ await Promise.all([...this.#jobs.keys()].map(async (snapId) => this.terminateSnap(snapId)));
202
+ }
203
+ /**
204
+ * Initializes and executes a Snap, setting up the communication channels to the Snap etc.
205
+ *
206
+ * @param snapData - Data needed for Snap execution.
207
+ * @param snapData.snapId - The ID of the Snap to execute.
208
+ * @param snapData.sourceCode - The source code of the Snap to execute.
209
+ * @param snapData.endowments - The endowments available to the executing Snap.
210
+ * @returns A string `OK` if execution succeeded.
211
+ * @throws If the execution service returns an error or execution times out.
212
+ */
213
+ async executeSnap({ snapId, sourceCode, endowments, }) {
214
+ if (this.#jobs.has(snapId)) {
215
+ throw new Error(`"${snapId}" is already running.`);
216
+ }
217
+ this.setSnapStatus(snapId, 'created');
218
+ const timer = new Timer(this.#initTimeout);
219
+ // This may resolve even if the environment has failed to start up fully
220
+ const job = await this.#initJob(snapId, timer);
221
+ // Certain environments use ping as part of their initialization and thus can skip it here
222
+ if (this.#usePing) {
223
+ // Ping the worker to ensure that it started up
224
+ const pingResult = await withTimeout(this.#command(job.id, {
225
+ jsonrpc: '2.0',
226
+ method: 'ping',
227
+ id: nanoid(),
228
+ }), this.#pingTimeout);
229
+ if (pingResult === hasTimedOut) {
230
+ throw new Error(`The executor for "${snapId}" was unreachable. The executor did not respond in time.`);
231
+ }
232
+ }
233
+ const rpcStream = job.streams.rpc;
234
+ this.#setupSnapProvider(snapId, rpcStream);
235
+ // Use the remaining time as the timer, but ensure that the
236
+ // Snap gets at least half the init timeout.
237
+ const remainingTime = Math.max(timer.remaining, this.#initTimeout / 2);
238
+ this.setSnapStatus(snapId, 'initialized');
239
+ const request = {
240
+ jsonrpc: '2.0',
241
+ method: 'executeSnap',
242
+ params: { snapId, sourceCode, endowments },
243
+ id: nanoid(),
244
+ };
245
+ assertIsJsonRpcRequest(request);
246
+ this.setSnapStatus(snapId, 'executing');
247
+ const result = await withTimeout(this.#command(job.id, request), remainingTime);
248
+ if (result === hasTimedOut) {
249
+ throw new Error(`${snapId} failed to start.`);
250
+ }
251
+ if (result === 'OK') {
252
+ this.setSnapStatus(snapId, 'running');
253
+ }
254
+ return result;
255
+ }
256
+ async #command(snapId, message) {
257
+ const job = this.#jobs.get(snapId);
258
+ if (!job) {
259
+ throw new Error(`"${snapId}" is not currently running.`);
260
+ }
261
+ log('Parent: Sending Command', message);
262
+ return await job.rpcEngine.handle(message);
263
+ }
264
+ /**
265
+ * Handle RPC request.
266
+ *
267
+ * @param snapId - The ID of the recipient Snap.
268
+ * @param options - Bag of options to pass to the RPC handler.
269
+ * @returns Promise that can handle the request.
270
+ */
271
+ async handleRpcRequest(snapId, options) {
272
+ const { handler, request, origin } = options;
273
+ return await this.#command(snapId, {
274
+ id: nanoid(),
275
+ jsonrpc: '2.0',
276
+ method: 'snapRpc',
277
+ params: {
278
+ snapId,
279
+ origin,
280
+ handler,
281
+ request: request,
282
+ },
283
+ });
284
+ }
285
+ }
2
286
  //# sourceMappingURL=ExecutionService.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"ExecutionService.mjs","sourceRoot":"","sources":["../../src/services/ExecutionService.ts"],"names":[],"mappings":"","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\n\ntype TerminateSnap = (snapId: string) => Promise<void>;\ntype TerminateAll = () => Promise<void>;\ntype ExecuteSnap = (snapData: SnapExecutionData) => Promise<unknown>;\n\ntype HandleRpcRequest = (\n snapId: string,\n options: SnapRpcHookArgs,\n) => Promise<unknown>;\n\nexport type ExecutionService = {\n // These fields are required for modular initialisation of the execution\n // service in the MetaMask extension.\n name: 'ExecutionService';\n state: null;\n\n terminateSnap: TerminateSnap;\n terminateAllSnaps: TerminateAll;\n executeSnap: ExecuteSnap;\n handleRpcRequest: HandleRpcRequest;\n};\n\nexport type SnapExecutionData = {\n snapId: string;\n sourceCode: string;\n endowments: Json;\n};\n\nexport type SnapErrorJson = {\n message: string;\n code: number;\n data?: Json;\n};\n\ntype ControllerName = 'ExecutionService';\n\nexport type ErrorMessageEvent = {\n type: 'ExecutionService:unhandledError';\n payload: [string, SnapErrorJson];\n};\n\nexport type OutboundRequest = {\n type: 'ExecutionService:outboundRequest';\n payload: [string];\n};\n\nexport type OutboundResponse = {\n type: 'ExecutionService:outboundResponse';\n payload: [string];\n};\n\nexport type ExecutionServiceEvents =\n | ErrorMessageEvent\n | OutboundRequest\n | OutboundResponse;\n\n/**\n * Handles RPC request.\n */\nexport type HandleRpcRequestAction = {\n type: `${ControllerName}:handleRpcRequest`;\n handler: ExecutionService['handleRpcRequest'];\n};\n\n/**\n * Executes a given snap.\n */\nexport type ExecuteSnapAction = {\n type: `${ControllerName}:executeSnap`;\n handler: ExecutionService['executeSnap'];\n};\n\n/**\n * Terminates a given snap.\n */\nexport type TerminateSnapAction = {\n type: `${ControllerName}:terminateSnap`;\n handler: ExecutionService['terminateSnap'];\n};\n\n/**\n * Terminates all snaps.\n */\nexport type TerminateAllSnapsAction = {\n type: `${ControllerName}:terminateAllSnaps`;\n handler: ExecutionService['terminateAllSnaps'];\n};\n\nexport type ExecutionServiceActions =\n | HandleRpcRequestAction\n | ExecuteSnapAction\n | TerminateSnapAction\n | TerminateAllSnapsAction;\n\nexport type ExecutionServiceMessenger = Messenger<\n 'ExecutionService',\n ExecutionServiceActions,\n ExecutionServiceEvents\n>;\n"]}
1
+ {"version":3,"file":"ExecutionService.mjs","sourceRoot":"","sources":["../../src/services/ExecutionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,eAAe,I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engine/v2';\nimport { createStreamMiddleware } from '@metamask/json-rpc-middleware-stream';\nimport type { Messenger } from '@metamask/messenger';\nimport type ObjectMultiplex from '@metamask/object-multiplex';\nimport type { BasePostMessageStream } from '@metamask/post-message-stream';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { SNAP_STREAM_NAMES, logError, logWarning } from '@metamask/snaps-utils';\nimport type {\n Json,\n JsonRpcNotification,\n JsonRpcRequest,\n} from '@metamask/utils';\nimport {\n Duration,\n assertIsJsonRpcRequest,\n hasProperty,\n inMilliseconds,\n} from '@metamask/utils';\nimport { nanoid } from 'nanoid';\nimport { pipeline } from 'readable-stream';\nimport type { Duplex } from 'readable-stream';\n\nimport type { ExecutionServiceMethodActions } from './ExecutionService-method-action-types';\nimport { setupMultiplex } from './multiplex';\nimport { log } from '../logging';\nimport { Timer } from '../snaps/Timer';\nimport { hasTimedOut, withTimeout } from '../utils';\n\nconst serviceName = 'ExecutionService';\n\nexport type SetupSnapProvider = (snapId: string, stream: Duplex) => void;\n\nexport type ExecutionServiceArgs = {\n setupSnapProvider: SetupSnapProvider;\n messenger: ExecutionServiceMessenger;\n initTimeout?: number;\n pingTimeout?: number;\n terminationTimeout?: number;\n usePing?: boolean;\n};\n\ntype JobStreams = {\n command: Duplex;\n rpc: Duplex;\n connection: BasePostMessageStream;\n mux: ObjectMultiplex;\n};\n\nexport type Job<WorkerType> = {\n id: string;\n streams: JobStreams;\n rpcEngine: JsonRpcEngine<JsonRpcRequest>;\n worker: WorkerType;\n};\n\nexport type TerminateJobArgs<WorkerType> = Partial<Job<WorkerType>> &\n Pick<Job<WorkerType>, 'id'>;\n\n/**\n Statuses used for diagnostic purposes\n - created: The initial state, no initialization has started\n - initializing: Snap execution environment is initializing\n - initialized: Snap execution environment has initialized\n - executing: Snap source code is being executed\n - running: Snap executed and ready for RPC requests\n */\ntype ExecutionStatus =\n | 'created'\n | 'initializing'\n | 'initialized'\n | 'executing'\n | 'running';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'terminateSnap',\n 'terminateAllSnaps',\n 'executeSnap',\n 'handleRpcRequest',\n] as const;\n\nexport type SnapExecutionData = {\n snapId: string;\n sourceCode: string;\n endowments: Json;\n};\n\nexport type SnapErrorJson = {\n message: string;\n code: number;\n data?: Json;\n};\n\nexport type ExecutionServiceUnhandledErrorEvent = {\n type: 'ExecutionService:unhandledError';\n payload: [string, SnapErrorJson];\n};\n\nexport type ExecutionServiceOutboundRequestEvent = {\n type: 'ExecutionService:outboundRequest';\n payload: [string];\n};\n\nexport type ExecutionServiceOutboundResponseEvent = {\n type: 'ExecutionService:outboundResponse';\n payload: [string];\n};\n\nexport type ExecutionServiceEvents =\n | ExecutionServiceUnhandledErrorEvent\n | ExecutionServiceOutboundRequestEvent\n | ExecutionServiceOutboundResponseEvent;\n\nexport type ExecutionServiceActions = ExecutionServiceMethodActions;\n\nexport type ExecutionServiceMessenger = Messenger<\n 'ExecutionService',\n ExecutionServiceActions,\n ExecutionServiceEvents\n>;\n\nexport abstract class ExecutionService<WorkerType = unknown> {\n name: typeof serviceName = serviceName;\n\n state = null;\n\n readonly #jobs: Map<string, Job<WorkerType>>;\n\n readonly #status: Map<string, ExecutionStatus>;\n\n readonly #setupSnapProvider: SetupSnapProvider;\n\n readonly #messenger: ExecutionServiceMessenger;\n\n readonly #initTimeout: number;\n\n readonly #pingTimeout: number;\n\n readonly #terminationTimeout: number;\n\n readonly #usePing: boolean;\n\n constructor({\n setupSnapProvider,\n messenger,\n initTimeout = inMilliseconds(60, Duration.Second),\n pingTimeout = inMilliseconds(10, Duration.Second),\n terminationTimeout = inMilliseconds(1, Duration.Second),\n usePing = true,\n }: ExecutionServiceArgs) {\n this.#jobs = new Map();\n this.#status = new Map();\n this.#setupSnapProvider = setupSnapProvider;\n this.#messenger = messenger;\n this.#initTimeout = initTimeout;\n this.#pingTimeout = pingTimeout;\n this.#terminationTimeout = terminationTimeout;\n this.#usePing = usePing;\n\n this.#messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Performs additional necessary work during job termination. **MUST** be\n * implemented by concrete implementations. See\n * {@link AbstractExecutionService.terminate} for details.\n *\n * @param job - The object corresponding to the job to be terminated.\n */\n protected abstract terminateJob(\n job: TerminateJobArgs<WorkerType>,\n ): Promise<void>;\n\n /**\n * Terminates the Snap with the specified ID and deletes all its associated\n * data. Any subsequent messages targeting the Snap will fail with an error.\n * Throws an error if termination fails unexpectedly.\n *\n * @param snapId - The id of the Snap to be terminated.\n */\n public async terminateSnap(snapId: string): Promise<void> {\n const job = this.#jobs.get(snapId);\n if (!job) {\n return;\n }\n\n try {\n // Ping worker and tell it to run teardown, continue with termination if it takes too long\n const result = await withTimeout(\n this.#command(snapId, {\n jsonrpc: '2.0',\n method: 'terminate',\n id: nanoid(),\n }),\n this.#terminationTimeout,\n );\n\n if (result === hasTimedOut || result !== 'OK') {\n logWarning(`Snap \"${snapId}\" failed to terminate gracefully.`);\n }\n } catch {\n // Ignore\n }\n\n Object.values(job.streams).forEach((stream) => {\n try {\n if (!stream.destroyed) {\n stream.destroy();\n }\n } catch (error) {\n logError('Error while destroying stream', error);\n }\n });\n\n await this.terminateJob(job);\n\n this.#jobs.delete(snapId);\n this.#status.delete(snapId);\n log(`Snap \"${snapId}\" terminated.`);\n }\n\n /**\n * Initiates a job for a Snap.\n *\n * @param snapId - The ID of the Snap to initiate a job for.\n * @param timer - The timer to use for timeouts.\n * @returns Information regarding the created job.\n * @throws If the execution service returns an error or execution times out.\n */\n async #initJob(snapId: string, timer: Timer): Promise<Job<WorkerType>> {\n const { streams, worker } = await this.#initStreams(snapId, timer);\n\n const jsonRpcConnection = createStreamMiddleware();\n\n pipeline(\n jsonRpcConnection.stream,\n streams.command,\n jsonRpcConnection.stream,\n (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Command stream failure.`, error);\n }\n },\n );\n\n const rpcEngine = JsonRpcEngine.create({\n middleware: [asV2Middleware(jsonRpcConnection.middleware)],\n });\n\n const envMetadata = {\n id: snapId,\n streams,\n rpcEngine,\n worker,\n };\n this.#jobs.set(snapId, envMetadata);\n\n return envMetadata;\n }\n\n /**\n * Sets up the streams for an initiated job.\n *\n * @param snapId - The Snap ID.\n * @param timer - The timer to use for timeouts.\n * @returns The streams to communicate with the worker and the worker itself.\n * @throws If the execution service returns an error or execution times out.\n */\n async #initStreams(\n snapId: string,\n timer: Timer,\n ): Promise<{ streams: JobStreams; worker: WorkerType }> {\n const result = await withTimeout(this.initEnvStream(snapId), timer);\n\n if (result === hasTimedOut) {\n // For certain environments, such as the iframe we may have already created the worker and wish to terminate it.\n await this.terminateJob({ id: snapId });\n\n const status = this.#status.get(snapId);\n if (status === 'created') {\n // Currently this error can only be thrown by OffscreenExecutionService.\n throw new Error(\n `The executor for \"${snapId}\" couldn't start initialization. The offscreen document may not exist.`,\n );\n }\n throw new Error(\n `The executor for \"${snapId}\" failed to initialize. The iframe/webview/worker failed to load.`,\n );\n }\n\n const { worker, stream: envStream } = result;\n const mux = setupMultiplex(envStream, `Snap: \"${snapId}\"`);\n const commandStream = mux.createStream(SNAP_STREAM_NAMES.COMMAND);\n\n // Handle out-of-band errors, i.e. errors thrown from the Snap outside of the req/res cycle.\n // Also keep track of outbound request/responses\n const notificationHandler = (\n message:\n | JsonRpcRequest\n | JsonRpcNotification<Json[] | Record<string, Json>>,\n ) => {\n if (hasProperty(message, 'id')) {\n return;\n }\n\n if (message.method === 'OutboundRequest') {\n this.#messenger.publish('ExecutionService:outboundRequest', snapId);\n } else if (message.method === 'OutboundResponse') {\n this.#messenger.publish('ExecutionService:outboundResponse', snapId);\n } else if (message.method === 'UnhandledError') {\n this.#messenger.publish(\n 'ExecutionService:unhandledError',\n snapId,\n (message.params as { error: SnapErrorJson }).error,\n );\n commandStream.removeListener('data', notificationHandler);\n } else {\n logError(\n new Error(\n `Received unexpected command stream notification \"${message.method}\".`,\n ),\n );\n }\n };\n\n commandStream.on('data', notificationHandler);\n\n const rpcStream = mux\n .createStream(SNAP_STREAM_NAMES.JSON_RPC)\n .setMaxListeners(20);\n\n rpcStream.on('data', (chunk) => {\n if (chunk?.data && hasProperty(chunk?.data, 'id')) {\n this.#messenger.publish('ExecutionService:outboundRequest', snapId);\n }\n });\n\n // An error handler is not attached to the RPC stream until `setupSnapProvider` is called.\n // We must set it up here to prevent errors from bubbling up if the stream is destroyed before then.\n rpcStream.on('error', (error) => {\n if (error && !error.message?.match('Premature close')) {\n logError(`Snap: \"${snapId}\" - RPC stream failure:`, error);\n }\n });\n\n const originalWrite = rpcStream.write.bind(rpcStream);\n\n // @ts-expect-error Hack to inspect the messages being written to the stream.\n rpcStream.write = (chunk, encoding, callback) => {\n // Ignore chain switching notifications as it doesn't matter for the SnapProvider.\n if (chunk?.data?.method === 'metamask_chainChanged') {\n return true;\n }\n\n if (chunk?.data && hasProperty(chunk?.data, 'id')) {\n this.#messenger.publish('ExecutionService:outboundResponse', snapId);\n }\n\n return originalWrite(chunk, encoding, callback);\n };\n\n return {\n streams: {\n command: commandStream,\n rpc: rpcStream,\n connection: envStream,\n mux,\n },\n worker,\n };\n }\n\n /**\n * Abstract function implemented by implementing class that spins up a new worker for a job.\n *\n * Depending on the execution environment, this may run forever if the Snap fails to start up properly, therefore any call to this function should be wrapped in a timeout.\n */\n protected abstract initEnvStream(snapId: string): Promise<{\n worker: WorkerType;\n stream: BasePostMessageStream;\n }>;\n\n /**\n * Set the execution status of the Snap.\n *\n * @param snapId - The Snap ID.\n * @param status - The current execution status.\n */\n protected setSnapStatus(snapId: string, status: ExecutionStatus) {\n this.#status.set(snapId, status);\n }\n\n async terminateAllSnaps() {\n await Promise.all(\n [...this.#jobs.keys()].map(async (snapId) => this.terminateSnap(snapId)),\n );\n }\n\n /**\n * Initializes and executes a Snap, setting up the communication channels to the Snap etc.\n *\n * @param snapData - Data needed for Snap execution.\n * @param snapData.snapId - The ID of the Snap to execute.\n * @param snapData.sourceCode - The source code of the Snap to execute.\n * @param snapData.endowments - The endowments available to the executing Snap.\n * @returns A string `OK` if execution succeeded.\n * @throws If the execution service returns an error or execution times out.\n */\n async executeSnap({\n snapId,\n sourceCode,\n endowments,\n }: SnapExecutionData): Promise<string> {\n if (this.#jobs.has(snapId)) {\n throw new Error(`\"${snapId}\" is already running.`);\n }\n\n this.setSnapStatus(snapId, 'created');\n\n const timer = new Timer(this.#initTimeout);\n\n // This may resolve even if the environment has failed to start up fully\n const job = await this.#initJob(snapId, timer);\n\n // Certain environments use ping as part of their initialization and thus can skip it here\n if (this.#usePing) {\n // Ping the worker to ensure that it started up\n const pingResult = await withTimeout(\n this.#command(job.id, {\n jsonrpc: '2.0',\n method: 'ping',\n id: nanoid(),\n }),\n this.#pingTimeout,\n );\n\n if (pingResult === hasTimedOut) {\n throw new Error(\n `The executor for \"${snapId}\" was unreachable. The executor did not respond in time.`,\n );\n }\n }\n\n const rpcStream = job.streams.rpc;\n\n this.#setupSnapProvider(snapId, rpcStream);\n\n // Use the remaining time as the timer, but ensure that the\n // Snap gets at least half the init timeout.\n const remainingTime = Math.max(timer.remaining, this.#initTimeout / 2);\n\n this.setSnapStatus(snapId, 'initialized');\n\n const request = {\n jsonrpc: '2.0',\n method: 'executeSnap',\n params: { snapId, sourceCode, endowments },\n id: nanoid(),\n };\n\n assertIsJsonRpcRequest(request);\n\n this.setSnapStatus(snapId, 'executing');\n\n const result = await withTimeout(\n this.#command(job.id, request),\n remainingTime,\n );\n\n if (result === hasTimedOut) {\n throw new Error(`${snapId} failed to start.`);\n }\n\n if (result === 'OK') {\n this.setSnapStatus(snapId, 'running');\n }\n\n return result as string;\n }\n\n async #command(\n snapId: string,\n message: JsonRpcRequest,\n ): Promise<Json | undefined> {\n const job = this.#jobs.get(snapId);\n if (!job) {\n throw new Error(`\"${snapId}\" is not currently running.`);\n }\n\n log('Parent: Sending Command', message);\n return await job.rpcEngine.handle(message);\n }\n\n /**\n * Handle RPC request.\n *\n * @param snapId - The ID of the recipient Snap.\n * @param options - Bag of options to pass to the RPC handler.\n * @returns Promise that can handle the request.\n */\n public async handleRpcRequest(\n snapId: string,\n options: SnapRpcHookArgs,\n ): Promise<unknown> {\n const { handler, request, origin } = options;\n\n return await this.#command(snapId, {\n id: nanoid(),\n jsonrpc: '2.0',\n method: 'snapRpc',\n params: {\n snapId,\n origin,\n handler,\n request: request as JsonRpcRequest,\n },\n });\n }\n}\n"]}
@@ -14,8 +14,11 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- // Subset of exports meant for browser environments, omits Node.js services
18
- __exportStar(require("./AbstractExecutionService.cjs"), exports);
17
+ exports.setupMultiplex = exports.ExecutionService = void 0;
18
+ var ExecutionService_1 = require("./ExecutionService.cjs");
19
+ Object.defineProperty(exports, "ExecutionService", { enumerable: true, get: function () { return ExecutionService_1.ExecutionService; } });
20
+ var multiplex_1 = require("./multiplex.cjs");
21
+ Object.defineProperty(exports, "setupMultiplex", { enumerable: true, get: function () { return multiplex_1.setupMultiplex; } });
19
22
  __exportStar(require("./ProxyPostMessageStream.cjs"), exports);
20
23
  __exportStar(require("./iframe/index.cjs"), exports);
21
24
  __exportStar(require("./offscreen/index.cjs"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"browser.cjs","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2EAA2E;AAC3E,iEAA2C;AAE3C,+DAAyC;AACzC,qDAAyB;AACzB,wDAA4B;AAC5B,sDAA0B","sourcesContent":["// Subset of exports meant for browser environments, omits Node.js services\nexport * from './AbstractExecutionService';\nexport type * from './ExecutionService';\nexport * from './ProxyPostMessageStream';\nexport * from './iframe';\nexport * from './offscreen';\nexport * from './webview';\n"]}
1
+ {"version":3,"file":"browser.cjs","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAYA,2DAAsD;AAA7C,oHAAA,gBAAgB,OAAA;AAOzB,6CAA6C;AAApC,2GAAA,cAAc,OAAA;AACvB,+DAAyC;AACzC,qDAAyB;AACzB,wDAA4B;AAC5B,sDAA0B","sourcesContent":["// Subset of exports meant for browser environments, omits Node.js services\nexport type {\n ExecutionServiceActions,\n ExecutionServiceArgs,\n ExecutionServiceEvents,\n ExecutionServiceMessenger,\n ExecutionServiceOutboundRequestEvent,\n ExecutionServiceOutboundResponseEvent,\n ExecutionServiceUnhandledErrorEvent,\n SnapErrorJson,\n SnapExecutionData,\n} from './ExecutionService';\nexport { ExecutionService } from './ExecutionService';\nexport type {\n ExecutionServiceTerminateSnapAction,\n ExecutionServiceTerminateAllSnapsAction,\n ExecutionServiceExecuteSnapAction,\n ExecutionServiceHandleRpcRequestAction,\n} from './ExecutionService-method-action-types';\nexport { setupMultiplex } from './multiplex';\nexport * from './ProxyPostMessageStream';\nexport * from './iframe';\nexport * from './offscreen';\nexport * from './webview';\n"]}
@@ -1,5 +1,7 @@
1
- export * from "./AbstractExecutionService.cjs";
2
- export type * from "./ExecutionService.cjs";
1
+ export type { ExecutionServiceActions, ExecutionServiceArgs, ExecutionServiceEvents, ExecutionServiceMessenger, ExecutionServiceOutboundRequestEvent, ExecutionServiceOutboundResponseEvent, ExecutionServiceUnhandledErrorEvent, SnapErrorJson, SnapExecutionData, } from "./ExecutionService.cjs";
2
+ export { ExecutionService } from "./ExecutionService.cjs";
3
+ export type { ExecutionServiceTerminateSnapAction, ExecutionServiceTerminateAllSnapsAction, ExecutionServiceExecuteSnapAction, ExecutionServiceHandleRpcRequestAction, } from "./ExecutionService-method-action-types.cjs";
4
+ export { setupMultiplex } from "./multiplex.cjs";
3
5
  export * from "./ProxyPostMessageStream.cjs";
4
6
  export * from "./iframe/index.cjs";
5
7
  export * from "./offscreen/index.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.cts","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AACA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B"}
1
+ {"version":3,"file":"browser.d.cts","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AACA,YAAY,EACV,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,oCAAoC,EACpC,qCAAqC,EACrC,mCAAmC,EACnC,aAAa,EACb,iBAAiB,GAClB,+BAA2B;AAC5B,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AACtD,YAAY,EACV,mCAAmC,EACnC,uCAAuC,EACvC,iCAAiC,EACjC,sCAAsC,GACvC,mDAA+C;AAChD,OAAO,EAAE,cAAc,EAAE,wBAAoB;AAC7C,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B"}
@@ -1,5 +1,7 @@
1
- export * from "./AbstractExecutionService.mjs";
2
- export type * from "./ExecutionService.mjs";
1
+ export type { ExecutionServiceActions, ExecutionServiceArgs, ExecutionServiceEvents, ExecutionServiceMessenger, ExecutionServiceOutboundRequestEvent, ExecutionServiceOutboundResponseEvent, ExecutionServiceUnhandledErrorEvent, SnapErrorJson, SnapExecutionData, } from "./ExecutionService.mjs";
2
+ export { ExecutionService } from "./ExecutionService.mjs";
3
+ export type { ExecutionServiceTerminateSnapAction, ExecutionServiceTerminateAllSnapsAction, ExecutionServiceExecuteSnapAction, ExecutionServiceHandleRpcRequestAction, } from "./ExecutionService-method-action-types.mjs";
4
+ export { setupMultiplex } from "./multiplex.mjs";
3
5
  export * from "./ProxyPostMessageStream.mjs";
4
6
  export * from "./iframe/index.mjs";
5
7
  export * from "./offscreen/index.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"browser.d.mts","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AACA,+CAA2C;AAC3C,4CAAwC;AACxC,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B"}
1
+ {"version":3,"file":"browser.d.mts","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AACA,YAAY,EACV,uBAAuB,EACvB,oBAAoB,EACpB,sBAAsB,EACtB,yBAAyB,EACzB,oCAAoC,EACpC,qCAAqC,EACrC,mCAAmC,EACnC,aAAa,EACb,iBAAiB,GAClB,+BAA2B;AAC5B,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AACtD,YAAY,EACV,mCAAmC,EACnC,uCAAuC,EACvC,iCAAiC,EACjC,sCAAsC,GACvC,mDAA+C;AAChD,OAAO,EAAE,cAAc,EAAE,wBAAoB;AAC7C,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B"}
@@ -1,5 +1,5 @@
1
- // Subset of exports meant for browser environments, omits Node.js services
2
- export * from "./AbstractExecutionService.mjs";
1
+ export { ExecutionService } from "./ExecutionService.mjs";
2
+ export { setupMultiplex } from "./multiplex.mjs";
3
3
  export * from "./ProxyPostMessageStream.mjs";
4
4
  export * from "./iframe/index.mjs";
5
5
  export * from "./offscreen/index.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"browser.mjs","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,+CAA2C;AAE3C,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B","sourcesContent":["// Subset of exports meant for browser environments, omits Node.js services\nexport * from './AbstractExecutionService';\nexport type * from './ExecutionService';\nexport * from './ProxyPostMessageStream';\nexport * from './iframe';\nexport * from './offscreen';\nexport * from './webview';\n"]}
1
+ {"version":3,"file":"browser.mjs","sourceRoot":"","sources":["../../src/services/browser.ts"],"names":[],"mappings":"AAYA,OAAO,EAAE,gBAAgB,EAAE,+BAA2B;AAOtD,OAAO,EAAE,cAAc,EAAE,wBAAoB;AAC7C,6CAAyC;AACzC,mCAAyB;AACzB,sCAA4B;AAC5B,oCAA0B","sourcesContent":["// Subset of exports meant for browser environments, omits Node.js services\nexport type {\n ExecutionServiceActions,\n ExecutionServiceArgs,\n ExecutionServiceEvents,\n ExecutionServiceMessenger,\n ExecutionServiceOutboundRequestEvent,\n ExecutionServiceOutboundResponseEvent,\n ExecutionServiceUnhandledErrorEvent,\n SnapErrorJson,\n SnapExecutionData,\n} from './ExecutionService';\nexport { ExecutionService } from './ExecutionService';\nexport type {\n ExecutionServiceTerminateSnapAction,\n ExecutionServiceTerminateAllSnapsAction,\n ExecutionServiceExecuteSnapAction,\n ExecutionServiceHandleRpcRequestAction,\n} from './ExecutionService-method-action-types';\nexport { setupMultiplex } from './multiplex';\nexport * from './ProxyPostMessageStream';\nexport * from './iframe';\nexport * from './offscreen';\nexport * from './webview';\n"]}
@@ -4,8 +4,8 @@ exports.IframeExecutionService = void 0;
4
4
  const post_message_stream_1 = require("@metamask/post-message-stream");
5
5
  const snaps_utils_1 = require("@metamask/snaps-utils");
6
6
  const utils_1 = require("../../utils.cjs");
7
- const AbstractExecutionService_1 = require("../AbstractExecutionService.cjs");
8
- class IframeExecutionService extends AbstractExecutionService_1.AbstractExecutionService {
7
+ const ExecutionService_1 = require("../ExecutionService.cjs");
8
+ class IframeExecutionService extends ExecutionService_1.ExecutionService {
9
9
  iframeUrl;
10
10
  constructor({ iframeUrl, messenger, setupSnapProvider, ...args }) {
11
11
  super({