@metamask/snaps-execution-environments 4.0.0 → 5.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 (441) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/browserify/iframe/bundle.js +4 -4
  3. package/dist/browserify/iframe/index.html +201 -110
  4. package/dist/browserify/node-process/bundle.js +204 -113
  5. package/dist/browserify/node-thread/bundle.js +204 -113
  6. package/dist/browserify/webview/bundle.js +4 -4
  7. package/dist/browserify/webview/index.html +201 -110
  8. package/dist/browserify/worker-executor/bundle.js +205 -114
  9. package/dist/browserify/worker-pool/bundle.js +4 -4
  10. package/dist/browserify/worker-pool/index.html +201 -110
  11. package/dist/chunk-26EFJQDW.mjs +49 -0
  12. package/dist/chunk-26EFJQDW.mjs.map +1 -0
  13. package/dist/chunk-4NOF6TN6.js +51 -0
  14. package/dist/chunk-4NOF6TN6.js.map +1 -0
  15. package/dist/chunk-5DIRYAYO.js +30 -0
  16. package/dist/chunk-5DIRYAYO.js.map +1 -0
  17. package/dist/chunk-5RKYO2Y5.js +33 -0
  18. package/dist/chunk-5RKYO2Y5.js.map +1 -0
  19. package/dist/chunk-6GHFAQ54.mjs +44 -0
  20. package/dist/chunk-6GHFAQ54.mjs.map +1 -0
  21. package/dist/chunk-A7NJQLUA.mjs +32 -0
  22. package/dist/chunk-A7NJQLUA.mjs.map +1 -0
  23. package/dist/chunk-AJFPA6MI.js +81 -0
  24. package/dist/chunk-AJFPA6MI.js.map +1 -0
  25. package/dist/chunk-AQNACKO6.js +1 -0
  26. package/dist/chunk-AQNACKO6.js.map +1 -0
  27. package/dist/chunk-AZCRNZ5W.js +49 -0
  28. package/dist/chunk-AZCRNZ5W.js.map +1 -0
  29. package/dist/chunk-B3ASGNVQ.mjs +45 -0
  30. package/dist/chunk-B3ASGNVQ.mjs.map +1 -0
  31. package/dist/chunk-BE4YFFMX.js +49 -0
  32. package/dist/chunk-BE4YFFMX.js.map +1 -0
  33. package/dist/chunk-BOCIYCLE.mjs +30 -0
  34. package/dist/chunk-BOCIYCLE.mjs.map +1 -0
  35. package/dist/chunk-CCBKFCGG.js +147 -0
  36. package/dist/chunk-CCBKFCGG.js.map +1 -0
  37. package/dist/chunk-CINBMYIQ.mjs +183 -0
  38. package/dist/chunk-CINBMYIQ.mjs.map +1 -0
  39. package/dist/chunk-EBECHU6M.js +92 -0
  40. package/dist/chunk-EBECHU6M.js.map +1 -0
  41. package/dist/chunk-ETXAWW65.mjs +86 -0
  42. package/dist/chunk-ETXAWW65.mjs.map +1 -0
  43. package/dist/chunk-EXN2TFDJ.js +38 -0
  44. package/dist/chunk-EXN2TFDJ.js.map +1 -0
  45. package/dist/chunk-FNRATYYY.mjs +24 -0
  46. package/dist/chunk-FNRATYYY.mjs.map +1 -0
  47. package/dist/chunk-FQBU72MW.mjs +16 -0
  48. package/dist/chunk-FQBU72MW.mjs.map +1 -0
  49. package/dist/chunk-G3NCGVCC.mjs +33 -0
  50. package/dist/chunk-G3NCGVCC.mjs.map +1 -0
  51. package/dist/chunk-GH6FPDY5.mjs +147 -0
  52. package/dist/chunk-GH6FPDY5.mjs.map +1 -0
  53. package/dist/chunk-HSZIPZHO.js +183 -0
  54. package/dist/chunk-HSZIPZHO.js.map +1 -0
  55. package/dist/chunk-IU54VPNO.js +67 -0
  56. package/dist/chunk-IU54VPNO.js.map +1 -0
  57. package/dist/chunk-IXYNAYMQ.js +33 -0
  58. package/dist/chunk-IXYNAYMQ.js.map +1 -0
  59. package/dist/chunk-IY3CYGH7.js +44 -0
  60. package/dist/chunk-IY3CYGH7.js.map +1 -0
  61. package/dist/chunk-KQNKD7G5.mjs +40 -0
  62. package/dist/chunk-KQNKD7G5.mjs.map +1 -0
  63. package/dist/chunk-KWFB2KH2.mjs +73 -0
  64. package/dist/chunk-KWFB2KH2.mjs.map +1 -0
  65. package/dist/chunk-L4G6IIWG.js +484 -0
  66. package/dist/chunk-L4G6IIWG.js.map +1 -0
  67. package/dist/chunk-L5U2LMZR.js +26 -0
  68. package/dist/chunk-L5U2LMZR.js.map +1 -0
  69. package/dist/chunk-LGC7HQR4.js +32 -0
  70. package/dist/chunk-LGC7HQR4.js.map +1 -0
  71. package/dist/chunk-LX5LQXYU.js +16 -0
  72. package/dist/chunk-LX5LQXYU.js.map +1 -0
  73. package/dist/chunk-M2OYI2NS.js +108 -0
  74. package/dist/chunk-M2OYI2NS.js.map +1 -0
  75. package/dist/chunk-MOWPAP2K.mjs +92 -0
  76. package/dist/chunk-MOWPAP2K.mjs.map +1 -0
  77. package/dist/chunk-N7URTBJV.js +73 -0
  78. package/dist/chunk-N7URTBJV.js.map +1 -0
  79. package/dist/chunk-OW4IXJ5J.mjs +484 -0
  80. package/dist/chunk-OW4IXJ5J.mjs.map +1 -0
  81. package/dist/chunk-OWG545LQ.js +45 -0
  82. package/dist/chunk-OWG545LQ.js.map +1 -0
  83. package/dist/chunk-QYFJ2LLW.js +86 -0
  84. package/dist/chunk-QYFJ2LLW.js.map +1 -0
  85. package/dist/chunk-RCPCISJD.mjs +16 -0
  86. package/dist/chunk-RCPCISJD.mjs.map +1 -0
  87. package/dist/chunk-RDFGQYG6.mjs +147 -0
  88. package/dist/chunk-RDFGQYG6.mjs.map +1 -0
  89. package/dist/chunk-RO347OMD.js +16 -0
  90. package/dist/chunk-RO347OMD.js.map +1 -0
  91. package/dist/chunk-RWBJNNGH.js +24 -0
  92. package/dist/chunk-RWBJNNGH.js.map +1 -0
  93. package/dist/chunk-S7LRB72P.js +38 -0
  94. package/dist/chunk-S7LRB72P.js.map +1 -0
  95. package/dist/chunk-SWINKAMI.js +147 -0
  96. package/dist/chunk-SWINKAMI.js.map +1 -0
  97. package/dist/chunk-TVV27HGP.mjs +81 -0
  98. package/dist/chunk-TVV27HGP.mjs.map +1 -0
  99. package/dist/chunk-TWF4RAXL.mjs +49 -0
  100. package/dist/chunk-TWF4RAXL.mjs.map +1 -0
  101. package/dist/chunk-VL3VNUT4.mjs +12 -0
  102. package/dist/chunk-VL3VNUT4.mjs.map +1 -0
  103. package/dist/chunk-VZS2LXDP.mjs +108 -0
  104. package/dist/chunk-VZS2LXDP.mjs.map +1 -0
  105. package/dist/chunk-WA7K3P4D.js +40 -0
  106. package/dist/chunk-WA7K3P4D.js.map +1 -0
  107. package/dist/chunk-XBKAIK2K.mjs +67 -0
  108. package/dist/chunk-XBKAIK2K.mjs.map +1 -0
  109. package/dist/chunk-XGCWN6ZD.mjs +262 -0
  110. package/dist/chunk-XGCWN6ZD.mjs.map +1 -0
  111. package/dist/chunk-XKY46YTJ.js +12 -0
  112. package/dist/chunk-XKY46YTJ.js.map +1 -0
  113. package/dist/chunk-XL5BQOEI.mjs +33 -0
  114. package/dist/chunk-XL5BQOEI.mjs.map +1 -0
  115. package/dist/chunk-XMCETCVM.js +48 -0
  116. package/dist/chunk-XMCETCVM.js.map +1 -0
  117. package/dist/chunk-XYRWHY3K.mjs +51 -0
  118. package/dist/chunk-XYRWHY3K.mjs.map +1 -0
  119. package/dist/chunk-Y7IEFWZU.mjs +26 -0
  120. package/dist/chunk-Y7IEFWZU.mjs.map +1 -0
  121. package/dist/chunk-YC3HWHJV.mjs +48 -0
  122. package/dist/chunk-YC3HWHJV.mjs.map +1 -0
  123. package/dist/chunk-YMAK7TUO.mjs +1 -0
  124. package/dist/chunk-YMAK7TUO.mjs.map +1 -0
  125. package/dist/chunk-YRZVIDCF.mjs +38 -0
  126. package/dist/chunk-YRZVIDCF.mjs.map +1 -0
  127. package/dist/chunk-Z7FBBBME.mjs +38 -0
  128. package/dist/chunk-Z7FBBBME.mjs.map +1 -0
  129. package/dist/chunk-ZMDJRC2Z.js +262 -0
  130. package/dist/chunk-ZMDJRC2Z.js.map +1 -0
  131. package/dist/common/BaseSnapExecutor.js +26 -0
  132. package/dist/common/BaseSnapExecutor.js.map +1 -0
  133. package/dist/common/BaseSnapExecutor.mjs +26 -0
  134. package/dist/common/BaseSnapExecutor.mjs.map +1 -0
  135. package/dist/common/commands.js +11 -0
  136. package/dist/common/commands.js.map +1 -0
  137. package/dist/common/commands.mjs +11 -0
  138. package/dist/common/commands.mjs.map +1 -0
  139. package/dist/common/endowments/commonEndowmentFactory.js +20 -0
  140. package/dist/common/endowments/commonEndowmentFactory.js.map +1 -0
  141. package/dist/common/endowments/commonEndowmentFactory.mjs +20 -0
  142. package/dist/common/endowments/commonEndowmentFactory.mjs.map +1 -0
  143. package/dist/common/endowments/console.js +13 -0
  144. package/dist/common/endowments/console.js.map +1 -0
  145. package/dist/common/endowments/console.mjs +13 -0
  146. package/dist/common/endowments/console.mjs.map +1 -0
  147. package/dist/common/endowments/crypto.js +11 -0
  148. package/dist/common/endowments/crypto.js.map +1 -0
  149. package/dist/common/endowments/crypto.mjs +11 -0
  150. package/dist/common/endowments/crypto.mjs.map +1 -0
  151. package/dist/common/endowments/date.js +9 -0
  152. package/dist/common/endowments/date.js.map +1 -0
  153. package/dist/common/endowments/date.mjs +9 -0
  154. package/dist/common/endowments/date.mjs.map +1 -0
  155. package/dist/common/endowments/index.js +21 -0
  156. package/dist/common/endowments/index.js.map +1 -0
  157. package/dist/common/endowments/index.mjs +21 -0
  158. package/dist/common/endowments/index.mjs.map +1 -0
  159. package/dist/common/endowments/interval.js +8 -0
  160. package/dist/common/endowments/interval.js.map +1 -0
  161. package/dist/common/endowments/interval.mjs +8 -0
  162. package/dist/common/endowments/interval.mjs.map +1 -0
  163. package/dist/common/endowments/math.js +10 -0
  164. package/dist/common/endowments/math.js.map +1 -0
  165. package/dist/common/endowments/math.mjs +10 -0
  166. package/dist/common/endowments/math.mjs.map +1 -0
  167. package/dist/common/endowments/network.js +10 -0
  168. package/dist/common/endowments/network.js.map +1 -0
  169. package/dist/common/endowments/network.mjs +10 -0
  170. package/dist/common/endowments/network.mjs.map +1 -0
  171. package/dist/common/endowments/textDecoder.js +8 -0
  172. package/dist/common/endowments/textDecoder.js.map +1 -0
  173. package/dist/common/endowments/textDecoder.mjs +8 -0
  174. package/dist/common/endowments/textDecoder.mjs.map +1 -0
  175. package/dist/common/endowments/textEncoder.js +8 -0
  176. package/dist/common/endowments/textEncoder.js.map +1 -0
  177. package/dist/common/endowments/textEncoder.mjs +8 -0
  178. package/dist/common/endowments/textEncoder.mjs.map +1 -0
  179. package/dist/common/endowments/timeout.js +8 -0
  180. package/dist/common/endowments/timeout.js.map +1 -0
  181. package/dist/common/endowments/timeout.mjs +8 -0
  182. package/dist/common/endowments/timeout.mjs.map +1 -0
  183. package/dist/common/globalEvents.js +11 -0
  184. package/dist/common/globalEvents.js.map +1 -0
  185. package/dist/common/globalEvents.mjs +11 -0
  186. package/dist/common/globalEvents.mjs.map +1 -0
  187. package/dist/common/globalObject.js +10 -0
  188. package/dist/common/globalObject.js.map +1 -0
  189. package/dist/common/globalObject.mjs +10 -0
  190. package/dist/common/globalObject.mjs.map +1 -0
  191. package/dist/common/lockdown/lockdown-events.js +8 -0
  192. package/dist/common/lockdown/lockdown-events.js.map +1 -0
  193. package/dist/common/lockdown/lockdown-events.mjs +8 -0
  194. package/dist/common/lockdown/lockdown-events.mjs.map +1 -0
  195. package/dist/common/lockdown/lockdown-more.js +8 -0
  196. package/dist/common/lockdown/lockdown-more.js.map +1 -0
  197. package/dist/common/lockdown/lockdown-more.mjs +8 -0
  198. package/dist/common/lockdown/lockdown-more.mjs.map +1 -0
  199. package/dist/common/lockdown/lockdown.js +22 -0
  200. package/dist/common/lockdown/lockdown.js.map +1 -0
  201. package/dist/common/lockdown/lockdown.mjs +22 -0
  202. package/dist/common/lockdown/lockdown.mjs.map +1 -0
  203. package/dist/common/sortParams.js +8 -0
  204. package/dist/common/sortParams.js.map +1 -0
  205. package/dist/common/sortParams.mjs +8 -0
  206. package/dist/common/sortParams.mjs.map +1 -0
  207. package/dist/common/utils.js +21 -0
  208. package/dist/common/utils.js.map +1 -0
  209. package/dist/common/utils.mjs +21 -0
  210. package/dist/common/utils.mjs.map +1 -0
  211. package/dist/common/validation.js +38 -0
  212. package/dist/common/validation.js.map +1 -0
  213. package/dist/common/validation.mjs +38 -0
  214. package/dist/common/validation.mjs.map +1 -0
  215. package/dist/globals.d.js +1 -0
  216. package/dist/globals.d.js.map +1 -0
  217. package/dist/globals.d.mjs +1 -0
  218. package/dist/globals.d.mjs.map +1 -0
  219. package/dist/iframe/IFrameSnapExecutor.js +27 -0
  220. package/dist/iframe/IFrameSnapExecutor.js.map +1 -0
  221. package/dist/iframe/IFrameSnapExecutor.mjs +27 -0
  222. package/dist/iframe/IFrameSnapExecutor.mjs.map +1 -0
  223. package/dist/iframe/index.js +35 -0
  224. package/dist/iframe/index.js.map +1 -0
  225. package/dist/iframe/index.mjs +35 -0
  226. package/dist/iframe/index.mjs.map +1 -0
  227. package/dist/index.js +9 -0
  228. package/dist/index.js.map +1 -0
  229. package/dist/index.mjs +9 -0
  230. package/dist/index.mjs.map +1 -0
  231. package/dist/logging.js +8 -0
  232. package/dist/logging.js.map +1 -0
  233. package/dist/logging.mjs +8 -0
  234. package/dist/logging.mjs.map +1 -0
  235. package/dist/node-process/ChildProcessSnapExecutor.js +27 -0
  236. package/dist/node-process/ChildProcessSnapExecutor.js.map +1 -0
  237. package/dist/node-process/ChildProcessSnapExecutor.mjs +27 -0
  238. package/dist/node-process/ChildProcessSnapExecutor.mjs.map +1 -0
  239. package/dist/node-process/index.js +31 -0
  240. package/dist/node-process/index.js.map +1 -0
  241. package/dist/node-process/index.mjs +31 -0
  242. package/dist/node-process/index.mjs.map +1 -0
  243. package/dist/node-thread/ThreadSnapExecutor.js +27 -0
  244. package/dist/node-thread/ThreadSnapExecutor.js.map +1 -0
  245. package/dist/node-thread/ThreadSnapExecutor.mjs +27 -0
  246. package/dist/node-thread/ThreadSnapExecutor.mjs.map +1 -0
  247. package/dist/node-thread/index.js +31 -0
  248. package/dist/node-thread/index.js.map +1 -0
  249. package/dist/node-thread/index.mjs +31 -0
  250. package/dist/node-thread/index.mjs.map +1 -0
  251. package/dist/proxy/ProxySnapExecutor.js +8 -0
  252. package/dist/proxy/ProxySnapExecutor.js.map +1 -0
  253. package/dist/proxy/ProxySnapExecutor.mjs +8 -0
  254. package/dist/proxy/ProxySnapExecutor.mjs.map +1 -0
  255. package/dist/proxy/index.js +9 -0
  256. package/dist/proxy/index.js.map +1 -0
  257. package/dist/proxy/index.mjs +9 -0
  258. package/dist/proxy/index.mjs.map +1 -0
  259. package/dist/tsconfig.build.tsbuildinfo +1 -0
  260. package/dist/types/common/utils.d.ts +7 -0
  261. package/dist/types/vendor/global.d.js +1 -0
  262. package/dist/types/vendor/global.d.js.map +1 -0
  263. package/dist/types/vendor/global.d.mjs +1 -0
  264. package/dist/types/vendor/global.d.mjs.map +1 -0
  265. package/dist/types/vendor/readable-stream.d.js +1 -0
  266. package/dist/types/vendor/readable-stream.d.js.map +1 -0
  267. package/dist/types/vendor/readable-stream.d.mjs +1 -0
  268. package/dist/types/vendor/readable-stream.d.mjs.map +1 -0
  269. package/dist/webview/WebViewExecutorStream.js +8 -0
  270. package/dist/webview/WebViewExecutorStream.js.map +1 -0
  271. package/dist/webview/WebViewExecutorStream.mjs +8 -0
  272. package/dist/webview/WebViewExecutorStream.mjs.map +1 -0
  273. package/dist/webview/index.js +26 -0
  274. package/dist/webview/index.js.map +1 -0
  275. package/dist/webview/index.mjs +26 -0
  276. package/dist/webview/index.mjs.map +1 -0
  277. package/dist/webworker/executor/WebWorkerSnapExecutor.js +27 -0
  278. package/dist/webworker/executor/WebWorkerSnapExecutor.js.map +1 -0
  279. package/dist/webworker/executor/WebWorkerSnapExecutor.mjs +27 -0
  280. package/dist/webworker/executor/WebWorkerSnapExecutor.mjs.map +1 -0
  281. package/dist/webworker/executor/index.js +35 -0
  282. package/dist/webworker/executor/index.js.map +1 -0
  283. package/dist/webworker/executor/index.mjs +35 -0
  284. package/dist/webworker/executor/index.mjs.map +1 -0
  285. package/dist/webworker/pool/WebWorkerPool.js +8 -0
  286. package/dist/webworker/pool/WebWorkerPool.js.map +1 -0
  287. package/dist/webworker/pool/WebWorkerPool.mjs +8 -0
  288. package/dist/webworker/pool/WebWorkerPool.mjs.map +1 -0
  289. package/dist/webworker/pool/index.js +16 -0
  290. package/dist/webworker/pool/index.js.map +1 -0
  291. package/dist/webworker/pool/index.mjs +16 -0
  292. package/dist/webworker/pool/index.mjs.map +1 -0
  293. package/package.json +29 -22
  294. package/dist/cjs/common/BaseSnapExecutor.js +0 -496
  295. package/dist/cjs/common/BaseSnapExecutor.js.map +0 -1
  296. package/dist/cjs/common/commands.js +0 -102
  297. package/dist/cjs/common/commands.js.map +0 -1
  298. package/dist/cjs/common/endowments/commonEndowmentFactory.js +0 -147
  299. package/dist/cjs/common/endowments/commonEndowmentFactory.js.map +0 -1
  300. package/dist/cjs/common/endowments/console.js +0 -134
  301. package/dist/cjs/common/endowments/console.js.map +0 -1
  302. package/dist/cjs/common/endowments/crypto.js +0 -44
  303. package/dist/cjs/common/endowments/crypto.js.map +0 -1
  304. package/dist/cjs/common/endowments/date.js +0 -53
  305. package/dist/cjs/common/endowments/date.js.map +0 -1
  306. package/dist/cjs/common/endowments/index.js +0 -93
  307. package/dist/cjs/common/endowments/index.js.map +0 -1
  308. package/dist/cjs/common/endowments/interval.js +0 -62
  309. package/dist/cjs/common/endowments/interval.js.map +0 -1
  310. package/dist/cjs/common/endowments/math.js +0 -67
  311. package/dist/cjs/common/endowments/math.js.map +0 -1
  312. package/dist/cjs/common/endowments/network.js +0 -303
  313. package/dist/cjs/common/endowments/network.js.map +0 -1
  314. package/dist/cjs/common/endowments/textDecoder.js +0 -28
  315. package/dist/cjs/common/endowments/textDecoder.js.map +0 -1
  316. package/dist/cjs/common/endowments/textEncoder.js +0 -28
  317. package/dist/cjs/common/endowments/textEncoder.js.map +0 -1
  318. package/dist/cjs/common/endowments/timeout.js +0 -64
  319. package/dist/cjs/common/endowments/timeout.js.map +0 -1
  320. package/dist/cjs/common/globalEvents.js +0 -40
  321. package/dist/cjs/common/globalEvents.js.map +0 -1
  322. package/dist/cjs/common/globalObject.js +0 -53
  323. package/dist/cjs/common/globalObject.js.map +0 -1
  324. package/dist/cjs/common/lockdown/lockdown-events.js +0 -74
  325. package/dist/cjs/common/lockdown/lockdown-events.js.map +0 -1
  326. package/dist/cjs/common/lockdown/lockdown-more.js +0 -73
  327. package/dist/cjs/common/lockdown/lockdown-more.js.map +0 -1
  328. package/dist/cjs/common/lockdown/lockdown.js +0 -30
  329. package/dist/cjs/common/lockdown/lockdown.js.map +0 -1
  330. package/dist/cjs/common/sortParams.js +0 -26
  331. package/dist/cjs/common/sortParams.js.map +0 -1
  332. package/dist/cjs/common/utils.js +0 -128
  333. package/dist/cjs/common/utils.js.map +0 -1
  334. package/dist/cjs/common/validation.js +0 -149
  335. package/dist/cjs/common/validation.js.map +0 -1
  336. package/dist/cjs/iframe/IFrameSnapExecutor.js +0 -50
  337. package/dist/cjs/iframe/IFrameSnapExecutor.js.map +0 -1
  338. package/dist/cjs/iframe/index.js +0 -13
  339. package/dist/cjs/iframe/index.js.map +0 -1
  340. package/dist/cjs/index.js +0 -20
  341. package/dist/cjs/index.js.map +0 -1
  342. package/dist/cjs/logging.js +0 -15
  343. package/dist/cjs/logging.js.map +0 -1
  344. package/dist/cjs/node-process/ChildProcessSnapExecutor.js +0 -39
  345. package/dist/cjs/node-process/ChildProcessSnapExecutor.js.map +0 -1
  346. package/dist/cjs/node-process/index.js +0 -11
  347. package/dist/cjs/node-process/index.js.map +0 -1
  348. package/dist/cjs/node-thread/ThreadSnapExecutor.js +0 -39
  349. package/dist/cjs/node-thread/ThreadSnapExecutor.js.map +0 -1
  350. package/dist/cjs/node-thread/index.js +0 -11
  351. package/dist/cjs/node-thread/index.js.map +0 -1
  352. package/dist/cjs/proxy/ProxySnapExecutor.js +0 -183
  353. package/dist/cjs/proxy/ProxySnapExecutor.js.map +0 -1
  354. package/dist/cjs/proxy/index.js +0 -20
  355. package/dist/cjs/proxy/index.js.map +0 -1
  356. package/dist/cjs/webview/WebViewExecutorStream.js +0 -121
  357. package/dist/cjs/webview/WebViewExecutorStream.js.map +0 -1
  358. package/dist/cjs/webview/index.js +0 -19
  359. package/dist/cjs/webview/index.js.map +0 -1
  360. package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js +0 -45
  361. package/dist/cjs/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
  362. package/dist/cjs/webworker/executor/index.js +0 -13
  363. package/dist/cjs/webworker/executor/index.js.map +0 -1
  364. package/dist/cjs/webworker/pool/WebWorkerPool.js +0 -248
  365. package/dist/cjs/webworker/pool/WebWorkerPool.js.map +0 -1
  366. package/dist/cjs/webworker/pool/index.js +0 -13
  367. package/dist/cjs/webworker/pool/index.js.map +0 -1
  368. package/dist/esm/common/BaseSnapExecutor.js +0 -486
  369. package/dist/esm/common/BaseSnapExecutor.js.map +0 -1
  370. package/dist/esm/common/commands.js +0 -101
  371. package/dist/esm/common/commands.js.map +0 -1
  372. package/dist/esm/common/endowments/commonEndowmentFactory.js +0 -132
  373. package/dist/esm/common/endowments/commonEndowmentFactory.js.map +0 -1
  374. package/dist/esm/common/endowments/console.js +0 -116
  375. package/dist/esm/common/endowments/console.js.map +0 -1
  376. package/dist/esm/common/endowments/crypto.js +0 -26
  377. package/dist/esm/common/endowments/crypto.js.map +0 -1
  378. package/dist/esm/common/endowments/date.js +0 -43
  379. package/dist/esm/common/endowments/date.js.map +0 -1
  380. package/dist/esm/common/endowments/index.js +0 -92
  381. package/dist/esm/common/endowments/index.js.map +0 -1
  382. package/dist/esm/common/endowments/interval.js +0 -52
  383. package/dist/esm/common/endowments/interval.js.map +0 -1
  384. package/dist/esm/common/endowments/math.js +0 -57
  385. package/dist/esm/common/endowments/math.js.map +0 -1
  386. package/dist/esm/common/endowments/network.js +0 -293
  387. package/dist/esm/common/endowments/network.js.map +0 -1
  388. package/dist/esm/common/endowments/textDecoder.js +0 -18
  389. package/dist/esm/common/endowments/textDecoder.js.map +0 -1
  390. package/dist/esm/common/endowments/textEncoder.js +0 -18
  391. package/dist/esm/common/endowments/textEncoder.js.map +0 -1
  392. package/dist/esm/common/endowments/timeout.js +0 -54
  393. package/dist/esm/common/endowments/timeout.js.map +0 -1
  394. package/dist/esm/common/globalEvents.js +0 -36
  395. package/dist/esm/common/globalEvents.js.map +0 -1
  396. package/dist/esm/common/globalObject.js +0 -36
  397. package/dist/esm/common/globalObject.js.map +0 -1
  398. package/dist/esm/common/lockdown/lockdown-events.js +0 -66
  399. package/dist/esm/common/lockdown/lockdown-events.js.map +0 -1
  400. package/dist/esm/common/lockdown/lockdown-more.js +0 -82
  401. package/dist/esm/common/lockdown/lockdown-more.js.map +0 -1
  402. package/dist/esm/common/lockdown/lockdown.js +0 -24
  403. package/dist/esm/common/lockdown/lockdown.js.map +0 -1
  404. package/dist/esm/common/sortParams.js +0 -29
  405. package/dist/esm/common/sortParams.js.map +0 -1
  406. package/dist/esm/common/utils.js +0 -128
  407. package/dist/esm/common/utils.js.map +0 -1
  408. package/dist/esm/common/validation.js +0 -127
  409. package/dist/esm/common/validation.js.map +0 -1
  410. package/dist/esm/iframe/IFrameSnapExecutor.js +0 -35
  411. package/dist/esm/iframe/IFrameSnapExecutor.js.map +0 -1
  412. package/dist/esm/iframe/index.js +0 -9
  413. package/dist/esm/iframe/index.js.map +0 -1
  414. package/dist/esm/index.js +0 -3
  415. package/dist/esm/index.js.map +0 -1
  416. package/dist/esm/logging.js +0 -10
  417. package/dist/esm/logging.js.map +0 -1
  418. package/dist/esm/node-process/ChildProcessSnapExecutor.js +0 -24
  419. package/dist/esm/node-process/ChildProcessSnapExecutor.js.map +0 -1
  420. package/dist/esm/node-process/index.js +0 -7
  421. package/dist/esm/node-process/index.js.map +0 -1
  422. package/dist/esm/node-thread/ThreadSnapExecutor.js +0 -24
  423. package/dist/esm/node-thread/ThreadSnapExecutor.js.map +0 -1
  424. package/dist/esm/node-thread/index.js +0 -7
  425. package/dist/esm/node-thread/index.js.map +0 -1
  426. package/dist/esm/proxy/ProxySnapExecutor.js +0 -181
  427. package/dist/esm/proxy/ProxySnapExecutor.js.map +0 -1
  428. package/dist/esm/proxy/index.js +0 -3
  429. package/dist/esm/proxy/index.js.map +0 -1
  430. package/dist/esm/webview/WebViewExecutorStream.js +0 -111
  431. package/dist/esm/webview/WebViewExecutorStream.js.map +0 -1
  432. package/dist/esm/webview/index.js +0 -15
  433. package/dist/esm/webview/index.js.map +0 -1
  434. package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js +0 -30
  435. package/dist/esm/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
  436. package/dist/esm/webworker/executor/index.js +0 -9
  437. package/dist/esm/webworker/executor/index.js.map +0 -1
  438. package/dist/esm/webworker/pool/WebWorkerPool.js +0 -245
  439. package/dist/esm/webworker/pool/WebWorkerPool.js.map +0 -1
  440. package/dist/esm/webworker/pool/index.js +0 -9
  441. package/dist/esm/webworker/pool/index.js.map +0 -1
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+
3
+ var _chunkHSZIPZHOjs = require('../../chunk-HSZIPZHO.js');
4
+
5
+
6
+ var _chunkBE4YFFMXjs = require('../../chunk-BE4YFFMX.js');
7
+
8
+
9
+ var _chunk4NOF6TN6js = require('../../chunk-4NOF6TN6.js');
10
+ require('../../chunk-EXN2TFDJ.js');
11
+
12
+ // src/webworker/pool/index.ts
13
+ _chunk4NOF6TN6js.executeLockdownMore.call(void 0, );
14
+ _chunkBE4YFFMXjs.executeLockdownEvents.call(void 0, );
15
+ _chunkHSZIPZHOjs.WebWorkerPool.initialize();
16
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webworker/pool/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,oBAAoB;AACpB,sBAAsB;AAEtB,cAAc,WAAW","sourcesContent":["import { executeLockdownEvents } from '../../common/lockdown/lockdown-events';\nimport { executeLockdownMore } from '../../common/lockdown/lockdown-more';\nimport { WebWorkerPool } from './WebWorkerPool';\n\n// Lockdown is already applied in LavaMoat\nexecuteLockdownMore();\nexecuteLockdownEvents();\n\nWebWorkerPool.initialize();\n"]}
@@ -0,0 +1,16 @@
1
+ import {
2
+ WebWorkerPool
3
+ } from "../../chunk-CINBMYIQ.mjs";
4
+ import {
5
+ executeLockdownEvents
6
+ } from "../../chunk-TWF4RAXL.mjs";
7
+ import {
8
+ executeLockdownMore
9
+ } from "../../chunk-XYRWHY3K.mjs";
10
+ import "../../chunk-YRZVIDCF.mjs";
11
+
12
+ // src/webworker/pool/index.ts
13
+ executeLockdownMore();
14
+ executeLockdownEvents();
15
+ WebWorkerPool.initialize();
16
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/webworker/pool/index.ts"],"sourcesContent":["import { executeLockdownEvents } from '../../common/lockdown/lockdown-events';\nimport { executeLockdownMore } from '../../common/lockdown/lockdown-more';\nimport { WebWorkerPool } from './WebWorkerPool';\n\n// Lockdown is already applied in LavaMoat\nexecuteLockdownMore();\nexecuteLockdownEvents();\n\nWebWorkerPool.initialize();\n"],"mappings":";;;;;;;;;;;;AAKA,oBAAoB;AACpB,sBAAsB;AAEtB,cAAc,WAAW;","names":[]}
package/package.json CHANGED
@@ -1,20 +1,31 @@
1
1
  {
2
2
  "name": "@metamask/snaps-execution-environments",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "description": "Snap sandbox environments for executing SES javascript",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "https://github.com/MetaMask/snaps.git"
8
8
  },
9
9
  "sideEffects": false,
10
- "main": "./dist/cjs/index.js",
11
- "module": "./dist/esm/index.js",
10
+ "exports": {
11
+ ".": {
12
+ "import": "./dist/index.mjs",
13
+ "require": "./dist/index.js",
14
+ "types": "./dist/types/index.d.ts"
15
+ },
16
+ "./dist/browserify/node-process/bundle.js": {
17
+ "default": "./dist/browserify/node-process/bundle.js"
18
+ },
19
+ "./dist/browserify/node-thread/bundle.js": {
20
+ "default": "./dist/browserify/node-thread/bundle.js"
21
+ },
22
+ "./package.json": "./package.json"
23
+ },
24
+ "main": "./dist/index.js",
25
+ "module": "./dist/index.mjs",
12
26
  "types": "./dist/types/index.d.ts",
13
27
  "files": [
14
- "dist/cjs/**",
15
- "dist/esm/**",
16
- "dist/types/**",
17
- "dist/browserify/**"
28
+ "dist"
18
29
  ],
19
30
  "scripts": {
20
31
  "test": "rimraf coverage && jest && yarn test:browser && yarn posttest",
@@ -28,29 +39,25 @@
28
39
  "lint:changelog": "../../scripts/validate-changelog.sh @metamask/snaps-execution-environments",
29
40
  "lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog && yarn lint:dependencies",
30
41
  "clean": "rimraf '*.tsbuildinfo' 'dist' 'src/__GENERATED__/' 'coverage/*' '__test__/*'",
31
- "build": "yarn build:source && yarn build:types",
32
- "build:source": "yarn build:esm && yarn build:cjs",
42
+ "build": "tsup --clean && yarn build:types && yarn build:lavamoat",
33
43
  "build:types": "tsc --project tsconfig.build.json",
34
- "build:esm": "swc src --out-dir dist/esm --config-file ../../.swcrc.build.json --config module.type=es6",
35
- "build:cjs": "swc src --out-dir dist/cjs --config-file ../../.swcrc.build.json --config module.type=commonjs",
36
- "build:clean": "yarn clean && yarn build",
37
- "build:post-tsc": "yarn build:lavamoat",
38
44
  "build:lavamoat": "lavamoat scripts/build.js --policy lavamoat/build-system/policy.json --policyOverride lavamoat/build-system/policy-override.json",
39
45
  "build:lavamoat:policy": "yarn build:lavamoat --writeAutoPolicy && node scripts/build.js --writeAutoPolicy",
40
46
  "auto-changelog-init": "auto-changelog init",
41
47
  "publish:preview": "yarn npm publish --tag preview",
42
48
  "lint:ci": "yarn lint",
43
49
  "start": "node scripts/start.js",
44
- "lint:dependencies": "depcheck"
50
+ "lint:dependencies": "depcheck",
51
+ "build:ci": "tsup --clean"
45
52
  },
46
53
  "dependencies": {
47
54
  "@metamask/json-rpc-engine": "^7.3.2",
48
55
  "@metamask/object-multiplex": "^2.0.0",
49
56
  "@metamask/post-message-stream": "^8.0.0",
50
57
  "@metamask/providers": "^14.0.2",
51
- "@metamask/rpc-errors": "^6.1.0",
52
- "@metamask/snaps-sdk": "^2.0.0",
53
- "@metamask/snaps-utils": "^6.0.0",
58
+ "@metamask/rpc-errors": "^6.2.1",
59
+ "@metamask/snaps-sdk": "^3.0.0",
60
+ "@metamask/snaps-utils": "^7.0.0",
54
61
  "@metamask/utils": "^8.3.0",
55
62
  "nanoid": "^3.1.31",
56
63
  "readable-stream": "^3.6.2",
@@ -62,15 +69,14 @@
62
69
  "@babel/preset-typescript": "^7.23.2",
63
70
  "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
64
71
  "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
65
- "@lavamoat/allow-scripts": "^3.0.0",
66
- "@lavamoat/lavapack": "^6.0.2",
72
+ "@lavamoat/allow-scripts": "^3.0.2",
73
+ "@lavamoat/lavapack": "^6.1.0",
67
74
  "@lavamoat/lavatube": "^1.0.0",
68
75
  "@metamask/auto-changelog": "^3.4.4",
69
76
  "@metamask/eslint-config": "^12.1.0",
70
77
  "@metamask/eslint-config-jest": "^12.1.0",
71
78
  "@metamask/eslint-config-nodejs": "^12.1.0",
72
79
  "@metamask/eslint-config-typescript": "^12.1.0",
73
- "@swc/cli": "^0.1.62",
74
80
  "@swc/core": "1.3.78",
75
81
  "@swc/jest": "^0.2.26",
76
82
  "@types/express": "^4.17.17",
@@ -105,8 +111,8 @@
105
111
  "jest": "^29.0.2",
106
112
  "jest-environment-node": "^29.5.0",
107
113
  "jest-fetch-mock": "^3.0.3",
108
- "lavamoat": "^8.0.2",
109
- "lavamoat-browserify": "^17.0.2",
114
+ "lavamoat": "^8.0.3",
115
+ "lavamoat-browserify": "^17.0.4",
110
116
  "prettier": "^2.7.1",
111
117
  "prettier-plugin-packagejson": "^2.2.11",
112
118
  "rimraf": "^4.1.2",
@@ -114,6 +120,7 @@
114
120
  "ses": "^1.1.0",
115
121
  "terser": "^5.17.7",
116
122
  "ts-node": "^10.9.1",
123
+ "tsup": "^8.0.1",
117
124
  "typescript": "~4.8.4",
118
125
  "vite": "^4.3.9",
119
126
  "vite-tsconfig-paths": "^4.0.5",
@@ -1,496 +0,0 @@
1
- // eslint-disable-next-line @typescript-eslint/triple-slash-reference, spaced-comment
2
- /// <reference path="../../../../node_modules/ses/types.d.ts" />
3
- "use strict";
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- Object.defineProperty(exports, "BaseSnapExecutor", {
8
- enumerable: true,
9
- get: function() {
10
- return BaseSnapExecutor;
11
- }
12
- });
13
- const _jsonrpcengine = require("@metamask/json-rpc-engine");
14
- const _StreamProvider = require("@metamask/providers/dist/StreamProvider");
15
- const _rpcerrors = require("@metamask/rpc-errors");
16
- const _snapssdk = require("@metamask/snaps-sdk");
17
- const _snapsutils = require("@metamask/snaps-utils");
18
- const _utils = require("@metamask/utils");
19
- const _superstruct = require("superstruct");
20
- const _logging = require("../logging");
21
- const _commands = require("./commands");
22
- const _endowments = require("./endowments");
23
- const _globalEvents = require("./globalEvents");
24
- const _sortParams = require("./sortParams");
25
- const _utils1 = require("./utils");
26
- const _validation = require("./validation");
27
- function _check_private_redeclaration(obj, privateCollection) {
28
- if (privateCollection.has(obj)) {
29
- throw new TypeError("Cannot initialize the same private elements twice on an object");
30
- }
31
- }
32
- function _class_private_method_get(receiver, privateSet, fn) {
33
- if (!privateSet.has(receiver)) {
34
- throw new TypeError("attempted to get private field on non-instance");
35
- }
36
- return fn;
37
- }
38
- function _class_private_method_init(obj, privateSet) {
39
- _check_private_redeclaration(obj, privateSet);
40
- privateSet.add(obj);
41
- }
42
- function _define_property(obj, key, value) {
43
- if (key in obj) {
44
- Object.defineProperty(obj, key, {
45
- value: value,
46
- enumerable: true,
47
- configurable: true,
48
- writable: true
49
- });
50
- } else {
51
- obj[key] = value;
52
- }
53
- return obj;
54
- }
55
- const fallbackError = {
56
- code: _rpcerrors.errorCodes.rpc.internal,
57
- message: 'Execution Environment Error'
58
- };
59
- const unhandledError = _rpcerrors.rpcErrors.internal({
60
- message: 'Unhandled Snap Error'
61
- }).serialize();
62
- /**
63
- * The supported methods in the execution environment. The validator checks the
64
- * incoming JSON-RPC request, and the `params` property is used for sorting the
65
- * parameters, if they are an object.
66
- */ const EXECUTION_ENVIRONMENT_METHODS = {
67
- ping: {
68
- struct: _validation.PingRequestArgumentsStruct,
69
- params: []
70
- },
71
- executeSnap: {
72
- struct: _validation.ExecuteSnapRequestArgumentsStruct,
73
- params: [
74
- 'snapId',
75
- 'sourceCode',
76
- 'endowments'
77
- ]
78
- },
79
- terminate: {
80
- struct: _validation.TerminateRequestArgumentsStruct,
81
- params: []
82
- },
83
- snapRpc: {
84
- struct: _validation.SnapRpcRequestArgumentsStruct,
85
- params: [
86
- 'target',
87
- 'handler',
88
- 'origin',
89
- 'request'
90
- ]
91
- }
92
- };
93
- var _write = /*#__PURE__*/ new WeakSet(), _notify = /*#__PURE__*/ new WeakSet(), _respond = /*#__PURE__*/ new WeakSet();
94
- class BaseSnapExecutor {
95
- errorHandler(error, data) {
96
- const serializedError = (0, _rpcerrors.serializeError)(error, {
97
- fallbackError: unhandledError,
98
- shouldIncludeStack: false
99
- });
100
- const errorData = (0, _snapssdk.getErrorData)(serializedError);
101
- _class_private_method_get(this, _notify, notify).call(this, {
102
- method: 'UnhandledError',
103
- params: {
104
- error: {
105
- ...serializedError,
106
- data: {
107
- ...errorData,
108
- ...data
109
- }
110
- }
111
- }
112
- }).catch((notifyError)=>{
113
- (0, _snapsutils.logError)(notifyError);
114
- });
115
- }
116
- async onCommandRequest(message) {
117
- if (!(0, _utils.isJsonRpcRequest)(message)) {
118
- if ((0, _utils.hasProperty)(message, 'id') && (0, _superstruct.is)(message.id, _utils.JsonRpcIdStruct)) {
119
- // Instead of throwing, we directly respond with an error.
120
- // We can only do this if the message ID is still valid.
121
- await _class_private_method_get(this, _write, write).call(this, {
122
- error: (0, _rpcerrors.serializeError)(_rpcerrors.rpcErrors.internal('JSON-RPC requests must be JSON serializable objects.')),
123
- id: message.id,
124
- jsonrpc: '2.0'
125
- });
126
- } else {
127
- (0, _snapsutils.logInfo)('Command stream received a non-JSON-RPC request, and was unable to respond.');
128
- }
129
- return;
130
- }
131
- const { id, method, params } = message;
132
- if (!(0, _utils.hasProperty)(EXECUTION_ENVIRONMENT_METHODS, method)) {
133
- await _class_private_method_get(this, _respond, respond).call(this, id, {
134
- error: _rpcerrors.rpcErrors.methodNotFound({
135
- data: {
136
- method
137
- }
138
- }).serialize()
139
- });
140
- return;
141
- }
142
- const methodObject = EXECUTION_ENVIRONMENT_METHODS[method];
143
- // support params by-name and by-position
144
- const paramsAsArray = (0, _sortParams.sortParamKeys)(methodObject.params, params);
145
- const [error] = (0, _superstruct.validate)(paramsAsArray, methodObject.struct);
146
- if (error) {
147
- await _class_private_method_get(this, _respond, respond).call(this, id, {
148
- error: _rpcerrors.rpcErrors.invalidParams({
149
- message: `Invalid parameters for method "${method}": ${error.message}.`,
150
- data: {
151
- method,
152
- params: paramsAsArray
153
- }
154
- }).serialize()
155
- });
156
- return;
157
- }
158
- try {
159
- const result = await this.methods[method](...paramsAsArray);
160
- await _class_private_method_get(this, _respond, respond).call(this, id, {
161
- result
162
- });
163
- } catch (rpcError) {
164
- await _class_private_method_get(this, _respond, respond).call(this, id, {
165
- error: (0, _rpcerrors.serializeError)(rpcError, {
166
- fallbackError
167
- })
168
- });
169
- }
170
- }
171
- /**
172
- * Attempts to evaluate a snap in SES. Generates APIs for the snap. May throw
173
- * on errors.
174
- *
175
- * @param snapId - The id of the snap.
176
- * @param sourceCode - The source code of the snap, in IIFE format.
177
- * @param _endowments - An array of the names of the endowments.
178
- */ async startSnap(snapId, sourceCode, _endowments1) {
179
- (0, _logging.log)(`Starting snap '${snapId}' in worker.`);
180
- if (this.snapPromiseErrorHandler) {
181
- (0, _globalEvents.removeEventListener)('unhandledrejection', this.snapPromiseErrorHandler);
182
- }
183
- if (this.snapErrorHandler) {
184
- (0, _globalEvents.removeEventListener)('error', this.snapErrorHandler);
185
- }
186
- this.snapErrorHandler = (error)=>{
187
- this.errorHandler(error.error, {
188
- snapId
189
- });
190
- };
191
- this.snapPromiseErrorHandler = (error)=>{
192
- this.errorHandler(error instanceof Error ? error : error.reason, {
193
- snapId
194
- });
195
- };
196
- const provider = new _StreamProvider.StreamProvider(this.rpcStream, {
197
- jsonRpcStreamName: 'metamask-provider',
198
- rpcMiddleware: [
199
- (0, _jsonrpcengine.createIdRemapMiddleware)()
200
- ]
201
- });
202
- await provider.initialize();
203
- const snap = this.createSnapGlobal(provider);
204
- const ethereum = this.createEIP1193Provider(provider);
205
- // We specifically use any type because the Snap can modify the object any way they want
206
- const snapModule = {
207
- exports: {}
208
- };
209
- try {
210
- const { endowments, teardown: endowmentTeardown } = (0, _endowments.createEndowments)({
211
- snap,
212
- ethereum,
213
- snapId,
214
- endowments: _endowments1,
215
- notify: _class_private_method_get(this, _notify, notify).bind(this)
216
- });
217
- // !!! Ensure that this is the only place the data is being set.
218
- // Other methods access the object value and mutate its properties.
219
- this.snapData.set(snapId, {
220
- idleTeardown: endowmentTeardown,
221
- runningEvaluations: new Set(),
222
- exports: {}
223
- });
224
- (0, _globalEvents.addEventListener)('unhandledRejection', this.snapPromiseErrorHandler);
225
- (0, _globalEvents.addEventListener)('error', this.snapErrorHandler);
226
- const compartment = new Compartment({
227
- ...endowments,
228
- module: snapModule,
229
- exports: snapModule.exports
230
- });
231
- // All of those are JavaScript runtime specific and self referential,
232
- // but we add them for compatibility sake with external libraries.
233
- //
234
- // We can't do that in the injected globals object above
235
- // because SES creates its own globalThis
236
- compartment.globalThis.self = compartment.globalThis;
237
- compartment.globalThis.global = compartment.globalThis;
238
- compartment.globalThis.window = compartment.globalThis;
239
- await this.executeInSnapContext(snapId, ()=>{
240
- compartment.evaluate(sourceCode);
241
- this.registerSnapExports(snapId, snapModule);
242
- });
243
- } catch (error) {
244
- this.removeSnap(snapId);
245
- const [cause] = (0, _snapsutils.unwrapError)(error);
246
- throw _rpcerrors.rpcErrors.internal({
247
- message: `Error while running snap '${snapId}': ${cause.message}`,
248
- data: {
249
- cause: cause.serialize()
250
- }
251
- });
252
- }
253
- }
254
- /**
255
- * Cancels all running evaluations of all snaps and clears all snap data.
256
- * NOTE:** Should only be called in response to the `terminate` RPC command.
257
- */ onTerminate() {
258
- // `stop()` tears down snap endowments.
259
- // Teardown will also be run for each snap as soon as there are
260
- // no more running evaluations for that snap.
261
- this.snapData.forEach((data)=>data.runningEvaluations.forEach((evaluation)=>evaluation.stop()));
262
- this.snapData.clear();
263
- }
264
- registerSnapExports(snapId, snapModule) {
265
- const data = this.snapData.get(snapId);
266
- // Somebody deleted the snap before we could register.
267
- if (!data) {
268
- return;
269
- }
270
- data.exports = _snapsutils.SNAP_EXPORT_NAMES.reduce((acc, exportName)=>{
271
- const snapExport = snapModule.exports[exportName];
272
- const { validator } = _snapsutils.SNAP_EXPORTS[exportName];
273
- if (validator(snapExport)) {
274
- return {
275
- ...acc,
276
- [exportName]: snapExport
277
- };
278
- }
279
- return acc;
280
- }, {});
281
- }
282
- /**
283
- * Instantiates a snap API object (i.e. `globalThis.snap`).
284
- *
285
- * @param provider - A StreamProvider connected to MetaMask.
286
- * @returns The snap provider object.
287
- */ createSnapGlobal(provider) {
288
- const originalRequest = provider.request.bind(provider);
289
- const request = async (args)=>{
290
- const sanitizedArgs = (0, _utils1.sanitizeRequestArguments)(args);
291
- (0, _utils1.assertSnapOutboundRequest)(sanitizedArgs);
292
- return await (0, _utils1.withTeardown)((async ()=>{
293
- await _class_private_method_get(this, _notify, notify).call(this, {
294
- method: 'OutboundRequest',
295
- params: {
296
- source: 'snap.request'
297
- }
298
- });
299
- try {
300
- return await originalRequest(sanitizedArgs);
301
- } finally{
302
- await _class_private_method_get(this, _notify, notify).call(this, {
303
- method: 'OutboundResponse',
304
- params: {
305
- source: 'snap.request'
306
- }
307
- });
308
- }
309
- })(), this);
310
- };
311
- // Proxy target is intentionally set to be an empty object, to ensure
312
- // that access to the prototype chain is not possible.
313
- const snapGlobalProxy = new Proxy({}, {
314
- has (_target, prop) {
315
- return typeof prop === 'string' && [
316
- 'request'
317
- ].includes(prop);
318
- },
319
- get (_target, prop) {
320
- if (prop === 'request') {
321
- return request;
322
- }
323
- return undefined;
324
- }
325
- });
326
- return harden(snapGlobalProxy);
327
- }
328
- /**
329
- * Instantiates an EIP-1193 Ethereum provider object (i.e. `globalThis.ethereum`).
330
- *
331
- * @param provider - A StreamProvider connected to MetaMask.
332
- * @returns The EIP-1193 Ethereum provider object.
333
- */ createEIP1193Provider(provider) {
334
- const originalRequest = provider.request.bind(provider);
335
- const request = async (args)=>{
336
- const sanitizedArgs = (0, _utils1.sanitizeRequestArguments)(args);
337
- (0, _utils1.assertEthereumOutboundRequest)(sanitizedArgs);
338
- return await (0, _utils1.withTeardown)((async ()=>{
339
- await _class_private_method_get(this, _notify, notify).call(this, {
340
- method: 'OutboundRequest',
341
- params: {
342
- source: 'ethereum.request'
343
- }
344
- });
345
- try {
346
- return await originalRequest(sanitizedArgs);
347
- } finally{
348
- await _class_private_method_get(this, _notify, notify).call(this, {
349
- method: 'OutboundResponse',
350
- params: {
351
- source: 'ethereum.request'
352
- }
353
- });
354
- }
355
- })(), this);
356
- };
357
- const streamProviderProxy = (0, _utils1.proxyStreamProvider)(provider, request);
358
- return harden(streamProviderProxy);
359
- }
360
- /**
361
- * Removes the snap with the given name.
362
- *
363
- * @param snapId - The id of the snap to remove.
364
- */ removeSnap(snapId) {
365
- this.snapData.delete(snapId);
366
- }
367
- /**
368
- * Calls the specified executor function in the context of the specified snap.
369
- * Essentially, this means that the operation performed by the executor is
370
- * counted as an evaluation of the specified snap. When the count of running
371
- * evaluations of a snap reaches zero, its endowments are torn down.
372
- *
373
- * @param snapId - The id of the snap whose context to execute in.
374
- * @param executor - The function that will be executed in the snap's context.
375
- * @returns The executor's return value.
376
- * @template Result - The return value of the executor.
377
- */ async executeInSnapContext(snapId, executor) {
378
- const data = this.snapData.get(snapId);
379
- if (data === undefined) {
380
- throw _rpcerrors.rpcErrors.internal(`Tried to execute in context of unknown snap: "${snapId}".`);
381
- }
382
- let stop;
383
- const stopPromise = new Promise((_, reject)=>stop = ()=>reject(// TODO(rekmarks): Specify / standardize error code for this case.
384
- _rpcerrors.rpcErrors.internal(`The snap "${snapId}" has been terminated during execution.`)));
385
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
386
- const evaluationData = {
387
- stop: stop
388
- };
389
- try {
390
- data.runningEvaluations.add(evaluationData);
391
- // Notice that we have to await this executor.
392
- // If we didn't, we would decrease the amount of running evaluations
393
- // before the promise actually resolves
394
- return await Promise.race([
395
- executor(),
396
- stopPromise
397
- ]);
398
- } catch (error) {
399
- throw new _snapsutils.WrappedSnapError(error);
400
- } finally{
401
- data.runningEvaluations.delete(evaluationData);
402
- if (data.runningEvaluations.size === 0) {
403
- this.lastTeardown += 1;
404
- await data.idleTeardown();
405
- }
406
- }
407
- }
408
- constructor(commandStream, rpcStream){
409
- // Awaitable function that writes back to the command stream
410
- // To prevent snap execution from blocking writing we wrap in a promise
411
- // and await it before continuing execution
412
- _class_private_method_init(this, _write);
413
- _class_private_method_init(this, _notify);
414
- _class_private_method_init(this, _respond);
415
- _define_property(this, "snapData", void 0);
416
- _define_property(this, "commandStream", void 0);
417
- _define_property(this, "rpcStream", void 0);
418
- _define_property(this, "methods", void 0);
419
- _define_property(this, "snapErrorHandler", void 0);
420
- _define_property(this, "snapPromiseErrorHandler", void 0);
421
- _define_property(this, "lastTeardown", 0);
422
- this.snapData = new Map();
423
- this.commandStream = commandStream;
424
- this.commandStream.on('data', (data)=>{
425
- this.onCommandRequest(data).catch((error)=>{
426
- // TODO: Decide how to handle errors.
427
- (0, _snapsutils.logError)(error);
428
- });
429
- });
430
- this.rpcStream = rpcStream;
431
- this.methods = (0, _commands.getCommandMethodImplementations)(this.startSnap.bind(this), async (target, handlerType, args)=>{
432
- const data = this.snapData.get(target);
433
- // We're capturing the handler in case someone modifies the data object
434
- // before the call.
435
- const handler = data?.exports[handlerType];
436
- const { required } = _snapsutils.SNAP_EXPORTS[handlerType];
437
- (0, _utils.assert)(!required || handler !== undefined, `No ${handlerType} handler exported for snap "${target}`, _rpcerrors.rpcErrors.methodNotSupported);
438
- // Certain handlers are not required. If they are not exported, we
439
- // return null.
440
- if (!handler) {
441
- return null;
442
- }
443
- let result = await this.executeInSnapContext(target, ()=>// TODO: fix handler args type cast
444
- handler(args));
445
- // The handler might not return anything, but undefined is not valid JSON.
446
- if (result === undefined) {
447
- result = null;
448
- }
449
- // /!\ Always return only sanitized JSON to prevent security flaws. /!\
450
- try {
451
- return (0, _utils.getSafeJson)(result);
452
- } catch (error) {
453
- throw _rpcerrors.rpcErrors.internal(`Received non-JSON-serializable value: ${error.message.replace(/^Assertion failed: /u, '')}`);
454
- }
455
- }, this.onTerminate.bind(this));
456
- }
457
- }
458
- async function write(chunk) {
459
- return new Promise((resolve, reject)=>{
460
- this.commandStream.write(chunk, (error)=>{
461
- if (error) {
462
- reject(error);
463
- return;
464
- }
465
- resolve();
466
- });
467
- });
468
- }
469
- async function notify(requestObject) {
470
- if (!(0, _utils.isValidJson)(requestObject) || !(0, _utils.isObject)(requestObject)) {
471
- throw _rpcerrors.rpcErrors.internal('JSON-RPC notifications must be JSON serializable objects');
472
- }
473
- await _class_private_method_get(this, _write, write).call(this, {
474
- ...requestObject,
475
- jsonrpc: '2.0'
476
- });
477
- }
478
- async function respond(id, requestObject) {
479
- if (!(0, _utils.isValidJson)(requestObject) || !(0, _utils.isObject)(requestObject)) {
480
- // Instead of throwing, we directly respond with an error.
481
- // This prevents an issue where we wouldn't respond when errors were non-serializable
482
- await _class_private_method_get(this, _write, write).call(this, {
483
- error: (0, _rpcerrors.serializeError)(_rpcerrors.rpcErrors.internal('JSON-RPC responses must be JSON serializable objects.')),
484
- id,
485
- jsonrpc: '2.0'
486
- });
487
- return;
488
- }
489
- await _class_private_method_get(this, _write, write).call(this, {
490
- ...requestObject,
491
- id,
492
- jsonrpc: '2.0'
493
- });
494
- }
495
-
496
- //# sourceMappingURL=BaseSnapExecutor.js.map