@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
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../src/common/commands.ts"],"sourcesContent":["import { HandlerType } from '@metamask/snaps-utils';\nimport { assertExhaustive } from '@metamask/utils';\n\nimport type { InvokeSnap, InvokeSnapArgs } from './BaseSnapExecutor';\nimport type {\n ExecuteSnap,\n JsonRpcRequestWithoutId,\n Ping,\n PossibleLookupRequestArgs,\n SnapRpc,\n Terminate,\n} from './validation';\nimport {\n assertIsOnTransactionRequestArguments,\n assertIsOnSignatureRequestArguments,\n assertIsOnNameLookupRequestArguments,\n assertIsOnUserInputRequestArguments,\n} from './validation';\n\nexport type CommandMethodsMapping = {\n ping: Ping;\n terminate: Terminate;\n executeSnap: ExecuteSnap;\n snapRpc: SnapRpc;\n};\n\n/**\n * Formats the arguments for the given handler.\n *\n * @param origin - The origin of the request.\n * @param handler - The handler to pass the request to.\n * @param request - The request object.\n * @returns The formatted arguments.\n */\nexport function getHandlerArguments(\n origin: string,\n handler: HandlerType,\n request: JsonRpcRequestWithoutId,\n): InvokeSnapArgs {\n // `request` is already validated by the time this function is called.\n\n switch (handler) {\n case HandlerType.OnTransaction: {\n assertIsOnTransactionRequestArguments(request.params);\n\n const { transaction, chainId, transactionOrigin } = request.params;\n return {\n transaction,\n chainId,\n transactionOrigin,\n };\n }\n case HandlerType.OnSignature: {\n assertIsOnSignatureRequestArguments(request.params);\n\n const { signature, signatureOrigin } = request.params;\n return { signature, signatureOrigin };\n }\n case HandlerType.OnNameLookup: {\n assertIsOnNameLookupRequestArguments(request.params);\n\n // TS complains that domain/address are not part of the type\n // casting here as we've already validated the request args in the above step.\n const { chainId, domain, address } =\n request.params as unknown as PossibleLookupRequestArgs;\n\n return domain\n ? {\n chainId,\n domain,\n }\n : {\n chainId,\n address,\n };\n }\n case HandlerType.OnRpcRequest:\n case HandlerType.OnKeyringRequest:\n return { origin, request };\n\n case HandlerType.OnCronjob:\n case HandlerType.OnInstall:\n case HandlerType.OnUpdate:\n return { request };\n\n case HandlerType.OnHomePage:\n return {};\n case HandlerType.OnUserInput: {\n assertIsOnUserInputRequestArguments(request.params);\n\n const { id, event } = request.params;\n return { id, event };\n }\n\n default:\n return assertExhaustive(handler);\n }\n}\n\n/**\n * Gets an object mapping internal, \"command\" JSON-RPC method names to their\n * implementations.\n *\n * @param startSnap - A function that starts a snap.\n * @param invokeSnap - A function that invokes the RPC method handler of a\n * snap.\n * @param onTerminate - A function that will be called when this executor is\n * terminated in order to handle cleanup tasks.\n * @returns An object containing the \"command\" method implementations.\n */\nexport function getCommandMethodImplementations(\n startSnap: (...args: Parameters<ExecuteSnap>) => Promise<void>,\n invokeSnap: InvokeSnap,\n onTerminate: () => void,\n): CommandMethodsMapping {\n return {\n ping: async () => Promise.resolve('OK'),\n terminate: async () => {\n onTerminate();\n return Promise.resolve('OK');\n },\n\n executeSnap: async (snapId, sourceCode, endowments) => {\n await startSnap(snapId, sourceCode, endowments);\n return 'OK';\n },\n\n snapRpc: async (target, handler, origin, request) => {\n return (\n (await invokeSnap(\n target,\n handler,\n getHandlerArguments(origin, handler, request),\n )) ?? null\n );\n },\n };\n}\n"],"names":["HandlerType","assertExhaustive","assertIsOnTransactionRequestArguments","assertIsOnSignatureRequestArguments","assertIsOnNameLookupRequestArguments","assertIsOnUserInputRequestArguments","getHandlerArguments","origin","handler","request","OnTransaction","params","transaction","chainId","transactionOrigin","OnSignature","signature","signatureOrigin","OnNameLookup","domain","address","OnRpcRequest","OnKeyringRequest","OnCronjob","OnInstall","OnUpdate","OnHomePage","OnUserInput","id","event","getCommandMethodImplementations","startSnap","invokeSnap","onTerminate","ping","Promise","resolve","terminate","executeSnap","snapId","sourceCode","endowments","snapRpc","target"],"mappings":"AAAA,SAASA,WAAW,QAAQ,wBAAwB;AACpD,SAASC,gBAAgB,QAAQ,kBAAkB;AAWnD,SACEC,qCAAqC,EACrCC,mCAAmC,EACnCC,oCAAoC,EACpCC,mCAAmC,QAC9B,eAAe;AAStB;;;;;;;CAOC,GACD,OAAO,SAASC,oBACdC,MAAc,EACdC,OAAoB,EACpBC,OAAgC;IAEhC,sEAAsE;IAEtE,OAAQD;QACN,KAAKR,YAAYU,aAAa;YAAE;gBAC9BR,sCAAsCO,QAAQE,MAAM;gBAEpD,MAAM,EAAEC,WAAW,EAAEC,OAAO,EAAEC,iBAAiB,EAAE,GAAGL,QAAQE,MAAM;gBAClE,OAAO;oBACLC;oBACAC;oBACAC;gBACF;YACF;QACA,KAAKd,YAAYe,WAAW;YAAE;gBAC5BZ,oCAAoCM,QAAQE,MAAM;gBAElD,MAAM,EAAEK,SAAS,EAAEC,eAAe,EAAE,GAAGR,QAAQE,MAAM;gBACrD,OAAO;oBAAEK;oBAAWC;gBAAgB;YACtC;QACA,KAAKjB,YAAYkB,YAAY;YAAE;gBAC7Bd,qCAAqCK,QAAQE,MAAM;gBAEnD,4DAA4D;gBAC5D,8EAA8E;gBAC9E,MAAM,EAAEE,OAAO,EAAEM,MAAM,EAAEC,OAAO,EAAE,GAChCX,QAAQE,MAAM;gBAEhB,OAAOQ,SACH;oBACEN;oBACAM;gBACF,IACA;oBACEN;oBACAO;gBACF;YACN;QACA,KAAKpB,YAAYqB,YAAY;QAC7B,KAAKrB,YAAYsB,gBAAgB;YAC/B,OAAO;gBAAEf;gBAAQE;YAAQ;QAE3B,KAAKT,YAAYuB,SAAS;QAC1B,KAAKvB,YAAYwB,SAAS;QAC1B,KAAKxB,YAAYyB,QAAQ;YACvB,OAAO;gBAAEhB;YAAQ;QAEnB,KAAKT,YAAY0B,UAAU;YACzB,OAAO,CAAC;QACV,KAAK1B,YAAY2B,WAAW;YAAE;gBAC5BtB,oCAAoCI,QAAQE,MAAM;gBAElD,MAAM,EAAEiB,EAAE,EAAEC,KAAK,EAAE,GAAGpB,QAAQE,MAAM;gBACpC,OAAO;oBAAEiB;oBAAIC;gBAAM;YACrB;QAEA;YACE,OAAO5B,iBAAiBO;IAC5B;AACF;AAEA;;;;;;;;;;CAUC,GACD,OAAO,SAASsB,gCACdC,SAA8D,EAC9DC,UAAsB,EACtBC,WAAuB;IAEvB,OAAO;QACLC,MAAM,UAAYC,QAAQC,OAAO,CAAC;QAClCC,WAAW;YACTJ;YACA,OAAOE,QAAQC,OAAO,CAAC;QACzB;QAEAE,aAAa,OAAOC,QAAQC,YAAYC;YACtC,MAAMV,UAAUQ,QAAQC,YAAYC;YACpC,OAAO;QACT;QAEAC,SAAS,OAAOC,QAAQnC,SAASD,QAAQE;YACvC,OACE,AAAC,MAAMuB,WACLW,QACAnC,SACAF,oBAAoBC,QAAQC,SAASC,aACjC;QAEV;IACF;AACF"}
@@ -1,132 +0,0 @@
1
- import { rootRealmGlobal } from '../globalObject';
2
- import consoleEndowment from './console';
3
- import crypto from './crypto';
4
- import date from './date';
5
- import interval from './interval';
6
- import math from './math';
7
- import network from './network';
8
- import textDecoder from './textDecoder';
9
- import textEncoder from './textEncoder';
10
- import timeout from './timeout';
11
- // Array of common endowments
12
- const commonEndowments = [
13
- {
14
- endowment: AbortController,
15
- name: 'AbortController'
16
- },
17
- {
18
- endowment: AbortSignal,
19
- name: 'AbortSignal'
20
- },
21
- {
22
- endowment: ArrayBuffer,
23
- name: 'ArrayBuffer'
24
- },
25
- {
26
- endowment: atob,
27
- name: 'atob',
28
- bind: true
29
- },
30
- {
31
- endowment: BigInt,
32
- name: 'BigInt'
33
- },
34
- {
35
- endowment: BigInt64Array,
36
- name: 'BigInt64Array'
37
- },
38
- {
39
- endowment: BigUint64Array,
40
- name: 'BigUint64Array'
41
- },
42
- {
43
- endowment: btoa,
44
- name: 'btoa',
45
- bind: true
46
- },
47
- {
48
- endowment: DataView,
49
- name: 'DataView'
50
- },
51
- {
52
- endowment: Float32Array,
53
- name: 'Float32Array'
54
- },
55
- {
56
- endowment: Float64Array,
57
- name: 'Float64Array'
58
- },
59
- {
60
- endowment: Int8Array,
61
- name: 'Int8Array'
62
- },
63
- {
64
- endowment: Int16Array,
65
- name: 'Int16Array'
66
- },
67
- {
68
- endowment: Int32Array,
69
- name: 'Int32Array'
70
- },
71
- {
72
- endowment: Uint8Array,
73
- name: 'Uint8Array'
74
- },
75
- {
76
- endowment: Uint8ClampedArray,
77
- name: 'Uint8ClampedArray'
78
- },
79
- {
80
- endowment: Uint16Array,
81
- name: 'Uint16Array'
82
- },
83
- {
84
- endowment: Uint32Array,
85
- name: 'Uint32Array'
86
- },
87
- {
88
- endowment: URL,
89
- name: 'URL'
90
- },
91
- {
92
- endowment: WebAssembly,
93
- name: 'WebAssembly'
94
- }
95
- ];
96
- /**
97
- * Creates a consolidated collection of common endowments.
98
- * This function will return factories for all common endowments including
99
- * the additionally attenuated. All hardened with SES.
100
- *
101
- * @returns An object with common endowments.
102
- */ const buildCommonEndowments = ()=>{
103
- const endowmentFactories = [
104
- crypto,
105
- interval,
106
- math,
107
- network,
108
- timeout,
109
- textDecoder,
110
- textEncoder,
111
- date,
112
- consoleEndowment
113
- ];
114
- commonEndowments.forEach((endowmentSpecification)=>{
115
- const endowment = {
116
- names: [
117
- endowmentSpecification.name
118
- ],
119
- factory: ()=>{
120
- const boundEndowment = typeof endowmentSpecification.endowment === 'function' && endowmentSpecification.bind ? endowmentSpecification.endowment.bind(rootRealmGlobal) : endowmentSpecification.endowment;
121
- return {
122
- [endowmentSpecification.name]: harden(boundEndowment)
123
- };
124
- }
125
- };
126
- endowmentFactories.push(endowment);
127
- });
128
- return endowmentFactories;
129
- };
130
- export default buildCommonEndowments;
131
-
132
- //# sourceMappingURL=commonEndowmentFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/commonEndowmentFactory.ts"],"sourcesContent":["import type { NotifyFunction } from '../BaseSnapExecutor';\nimport { rootRealmGlobal } from '../globalObject';\nimport consoleEndowment from './console';\nimport crypto from './crypto';\nimport date from './date';\nimport interval from './interval';\nimport math from './math';\nimport network from './network';\nimport textDecoder from './textDecoder';\nimport textEncoder from './textEncoder';\nimport timeout from './timeout';\n\nexport type EndowmentFactoryOptions = {\n snapId?: string;\n notify?: NotifyFunction;\n};\n\nexport type EndowmentFactory = {\n names: readonly string[];\n factory: (options?: EndowmentFactoryOptions) => { [key: string]: unknown };\n};\n\nexport type CommonEndowmentSpecification = {\n endowment: unknown;\n name: string;\n bind?: boolean;\n};\n\n// Array of common endowments\nconst commonEndowments: CommonEndowmentSpecification[] = [\n { endowment: AbortController, name: 'AbortController' },\n { endowment: AbortSignal, name: 'AbortSignal' },\n { endowment: ArrayBuffer, name: 'ArrayBuffer' },\n { endowment: atob, name: 'atob', bind: true },\n { endowment: BigInt, name: 'BigInt' },\n { endowment: BigInt64Array, name: 'BigInt64Array' },\n { endowment: BigUint64Array, name: 'BigUint64Array' },\n { endowment: btoa, name: 'btoa', bind: true },\n { endowment: DataView, name: 'DataView' },\n { endowment: Float32Array, name: 'Float32Array' },\n { endowment: Float64Array, name: 'Float64Array' },\n { endowment: Int8Array, name: 'Int8Array' },\n { endowment: Int16Array, name: 'Int16Array' },\n { endowment: Int32Array, name: 'Int32Array' },\n { endowment: Uint8Array, name: 'Uint8Array' },\n { endowment: Uint8ClampedArray, name: 'Uint8ClampedArray' },\n { endowment: Uint16Array, name: 'Uint16Array' },\n { endowment: Uint32Array, name: 'Uint32Array' },\n { endowment: URL, name: 'URL' },\n { endowment: WebAssembly, name: 'WebAssembly' },\n];\n\n/**\n * Creates a consolidated collection of common endowments.\n * This function will return factories for all common endowments including\n * the additionally attenuated. All hardened with SES.\n *\n * @returns An object with common endowments.\n */\nconst buildCommonEndowments = (): EndowmentFactory[] => {\n const endowmentFactories: EndowmentFactory[] = [\n crypto,\n interval,\n math,\n network,\n timeout,\n textDecoder,\n textEncoder,\n date,\n consoleEndowment,\n ];\n\n commonEndowments.forEach((endowmentSpecification) => {\n const endowment = {\n names: [endowmentSpecification.name] as const,\n factory: () => {\n const boundEndowment =\n typeof endowmentSpecification.endowment === 'function' &&\n endowmentSpecification.bind\n ? endowmentSpecification.endowment.bind(rootRealmGlobal)\n : endowmentSpecification.endowment;\n return {\n [endowmentSpecification.name]: harden(boundEndowment),\n } as const;\n },\n };\n endowmentFactories.push(endowment);\n });\n\n return endowmentFactories;\n};\n\nexport default buildCommonEndowments;\n"],"names":["rootRealmGlobal","consoleEndowment","crypto","date","interval","math","network","textDecoder","textEncoder","timeout","commonEndowments","endowment","AbortController","name","AbortSignal","ArrayBuffer","atob","bind","BigInt","BigInt64Array","BigUint64Array","btoa","DataView","Float32Array","Float64Array","Int8Array","Int16Array","Int32Array","Uint8Array","Uint8ClampedArray","Uint16Array","Uint32Array","URL","WebAssembly","buildCommonEndowments","endowmentFactories","forEach","endowmentSpecification","names","factory","boundEndowment","harden","push"],"mappings":"AACA,SAASA,eAAe,QAAQ,kBAAkB;AAClD,OAAOC,sBAAsB,YAAY;AACzC,OAAOC,YAAY,WAAW;AAC9B,OAAOC,UAAU,SAAS;AAC1B,OAAOC,cAAc,aAAa;AAClC,OAAOC,UAAU,SAAS;AAC1B,OAAOC,aAAa,YAAY;AAChC,OAAOC,iBAAiB,gBAAgB;AACxC,OAAOC,iBAAiB,gBAAgB;AACxC,OAAOC,aAAa,YAAY;AAkBhC,6BAA6B;AAC7B,MAAMC,mBAAmD;IACvD;QAAEC,WAAWC;QAAiBC,MAAM;IAAkB;IACtD;QAAEF,WAAWG;QAAaD,MAAM;IAAc;IAC9C;QAAEF,WAAWI;QAAaF,MAAM;IAAc;IAC9C;QAAEF,WAAWK;QAAMH,MAAM;QAAQI,MAAM;IAAK;IAC5C;QAAEN,WAAWO;QAAQL,MAAM;IAAS;IACpC;QAAEF,WAAWQ;QAAeN,MAAM;IAAgB;IAClD;QAAEF,WAAWS;QAAgBP,MAAM;IAAiB;IACpD;QAAEF,WAAWU;QAAMR,MAAM;QAAQI,MAAM;IAAK;IAC5C;QAAEN,WAAWW;QAAUT,MAAM;IAAW;IACxC;QAAEF,WAAWY;QAAcV,MAAM;IAAe;IAChD;QAAEF,WAAWa;QAAcX,MAAM;IAAe;IAChD;QAAEF,WAAWc;QAAWZ,MAAM;IAAY;IAC1C;QAAEF,WAAWe;QAAYb,MAAM;IAAa;IAC5C;QAAEF,WAAWgB;QAAYd,MAAM;IAAa;IAC5C;QAAEF,WAAWiB;QAAYf,MAAM;IAAa;IAC5C;QAAEF,WAAWkB;QAAmBhB,MAAM;IAAoB;IAC1D;QAAEF,WAAWmB;QAAajB,MAAM;IAAc;IAC9C;QAAEF,WAAWoB;QAAalB,MAAM;IAAc;IAC9C;QAAEF,WAAWqB;QAAKnB,MAAM;IAAM;IAC9B;QAAEF,WAAWsB;QAAapB,MAAM;IAAc;CAC/C;AAED;;;;;;CAMC,GACD,MAAMqB,wBAAwB;IAC5B,MAAMC,qBAAyC;QAC7CjC;QACAE;QACAC;QACAC;QACAG;QACAF;QACAC;QACAL;QACAF;KACD;IAEDS,iBAAiB0B,OAAO,CAAC,CAACC;QACxB,MAAM1B,YAAY;YAChB2B,OAAO;gBAACD,uBAAuBxB,IAAI;aAAC;YACpC0B,SAAS;gBACP,MAAMC,iBACJ,OAAOH,uBAAuB1B,SAAS,KAAK,cAC5C0B,uBAAuBpB,IAAI,GACvBoB,uBAAuB1B,SAAS,CAACM,IAAI,CAACjB,mBACtCqC,uBAAuB1B,SAAS;gBACtC,OAAO;oBACL,CAAC0B,uBAAuBxB,IAAI,CAAC,EAAE4B,OAAOD;gBACxC;YACF;QACF;QACAL,mBAAmBO,IAAI,CAAC/B;IAC1B;IAEA,OAAOwB;AACT;AAEA,eAAeD,sBAAsB"}
@@ -1,116 +0,0 @@
1
- import { assert } from '@metamask/utils';
2
- import { rootRealmGlobal } from '../globalObject';
3
- export const consoleAttenuatedMethods = new Set([
4
- 'log',
5
- 'assert',
6
- 'error',
7
- 'debug',
8
- 'info',
9
- 'warn'
10
- ]);
11
- /**
12
- * A set of all the `console` values that will be passed to the snap. This has
13
- * all the values that are available in both the browser and Node.js.
14
- */ export const consoleMethods = new Set([
15
- 'debug',
16
- 'error',
17
- 'info',
18
- 'log',
19
- 'warn',
20
- 'dir',
21
- 'dirxml',
22
- 'table',
23
- 'trace',
24
- 'group',
25
- 'groupCollapsed',
26
- 'groupEnd',
27
- 'clear',
28
- 'count',
29
- 'countReset',
30
- 'assert',
31
- 'profile',
32
- 'profileEnd',
33
- 'time',
34
- 'timeLog',
35
- 'timeEnd',
36
- 'timeStamp',
37
- 'context'
38
- ]);
39
- const consoleFunctions = [
40
- 'log',
41
- 'error',
42
- 'debug',
43
- 'info',
44
- 'warn'
45
- ];
46
- /**
47
- * Gets the appropriate (prepended) message to pass to one of the attenuated
48
- * method calls.
49
- *
50
- * @param snapId - Id of the snap that we're getting a message for.
51
- * @param message - The id of the snap that will interact with the endowment.
52
- * @param args - The array of additional arguments.
53
- * @returns An array of arguments to be passed into an attenuated console method call.
54
- */ function getMessage(snapId, message, ...args) {
55
- const prefix = `[Snap: ${snapId}]`;
56
- // If the first argument is a string, prepend the prefix to the message, and keep the
57
- // rest of the arguments as-is.
58
- if (typeof message === 'string') {
59
- return [
60
- `${prefix} ${message}`,
61
- ...args
62
- ];
63
- }
64
- // Otherwise, the `message` is an object, array, etc., so add the prefix as a separate
65
- // message to the arguments.
66
- return [
67
- prefix,
68
- message,
69
- ...args
70
- ];
71
- }
72
- /**
73
- * Create a a {@link console} object, with the same properties as the global
74
- * {@link console} object, but with some methods replaced.
75
- *
76
- * @param options - Factory options used in construction of the endowment.
77
- * @param options.snapId - The id of the snap that will interact with the endowment.
78
- * @returns The {@link console} object with the replaced methods.
79
- */ function createConsole({ snapId } = {}) {
80
- assert(snapId !== undefined);
81
- const keys = Object.getOwnPropertyNames(rootRealmGlobal.console);
82
- const attenuatedConsole = keys.reduce((target, key)=>{
83
- if (consoleMethods.has(key) && !consoleAttenuatedMethods.has(key)) {
84
- return {
85
- ...target,
86
- [key]: rootRealmGlobal.console[key]
87
- };
88
- }
89
- return target;
90
- }, {});
91
- return harden({
92
- console: {
93
- ...attenuatedConsole,
94
- assert: (value, message, ...optionalParams)=>{
95
- rootRealmGlobal.console.assert(value, ...getMessage(snapId, message, ...optionalParams));
96
- },
97
- ...consoleFunctions.reduce((target, key)=>{
98
- return {
99
- ...target,
100
- [key]: (message, ...optionalParams)=>{
101
- rootRealmGlobal.console[key](...getMessage(snapId, message, ...optionalParams));
102
- }
103
- };
104
- }, {})
105
- }
106
- });
107
- }
108
- const endowmentModule = {
109
- names: [
110
- 'console'
111
- ],
112
- factory: createConsole
113
- };
114
- export default endowmentModule;
115
-
116
- //# sourceMappingURL=console.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/console.ts"],"sourcesContent":["import { assert } from '@metamask/utils';\n\nimport { rootRealmGlobal } from '../globalObject';\nimport type { EndowmentFactoryOptions } from './commonEndowmentFactory';\n\nexport const consoleAttenuatedMethods = new Set([\n 'log',\n 'assert',\n 'error',\n 'debug',\n 'info',\n 'warn',\n]);\n\n/**\n * A set of all the `console` values that will be passed to the snap. This has\n * all the values that are available in both the browser and Node.js.\n */\nexport const consoleMethods = new Set([\n 'debug',\n 'error',\n 'info',\n 'log',\n 'warn',\n 'dir',\n 'dirxml',\n 'table',\n 'trace',\n 'group',\n 'groupCollapsed',\n 'groupEnd',\n 'clear',\n 'count',\n 'countReset',\n 'assert',\n 'profile',\n 'profileEnd',\n 'time',\n 'timeLog',\n 'timeEnd',\n 'timeStamp',\n 'context',\n]);\n\nconst consoleFunctions = ['log', 'error', 'debug', 'info', 'warn'] as const;\n\ntype ConsoleFunctions = {\n [Key in (typeof consoleFunctions)[number]]: (typeof rootRealmGlobal.console)[Key];\n};\n\n/**\n * Gets the appropriate (prepended) message to pass to one of the attenuated\n * method calls.\n *\n * @param snapId - Id of the snap that we're getting a message for.\n * @param message - The id of the snap that will interact with the endowment.\n * @param args - The array of additional arguments.\n * @returns An array of arguments to be passed into an attenuated console method call.\n */\nfunction getMessage(snapId: string, message: unknown, ...args: unknown[]) {\n const prefix = `[Snap: ${snapId}]`;\n\n // If the first argument is a string, prepend the prefix to the message, and keep the\n // rest of the arguments as-is.\n if (typeof message === 'string') {\n return [`${prefix} ${message}`, ...args];\n }\n\n // Otherwise, the `message` is an object, array, etc., so add the prefix as a separate\n // message to the arguments.\n return [prefix, message, ...args];\n}\n\n/**\n * Create a a {@link console} object, with the same properties as the global\n * {@link console} object, but with some methods replaced.\n *\n * @param options - Factory options used in construction of the endowment.\n * @param options.snapId - The id of the snap that will interact with the endowment.\n * @returns The {@link console} object with the replaced methods.\n */\nfunction createConsole({ snapId }: EndowmentFactoryOptions = {}) {\n assert(snapId !== undefined);\n const keys = Object.getOwnPropertyNames(\n rootRealmGlobal.console,\n ) as (keyof typeof console)[];\n\n const attenuatedConsole = keys.reduce((target, key) => {\n if (consoleMethods.has(key) && !consoleAttenuatedMethods.has(key)) {\n return { ...target, [key]: rootRealmGlobal.console[key] };\n }\n\n return target;\n }, {});\n\n return harden({\n console: {\n ...attenuatedConsole,\n assert: (\n value: any,\n message?: string | undefined,\n ...optionalParams: any[]\n ) => {\n rootRealmGlobal.console.assert(\n value,\n ...getMessage(snapId, message, ...optionalParams),\n );\n },\n ...consoleFunctions.reduce<ConsoleFunctions>((target, key) => {\n return {\n ...target,\n [key]: (message?: unknown, ...optionalParams: any[]) => {\n rootRealmGlobal.console[key](\n ...getMessage(snapId, message, ...optionalParams),\n );\n },\n };\n }, {} as ConsoleFunctions),\n },\n });\n}\n\nconst endowmentModule = {\n names: ['console'] as const,\n factory: createConsole,\n};\n\nexport default endowmentModule;\n"],"names":["assert","rootRealmGlobal","consoleAttenuatedMethods","Set","consoleMethods","consoleFunctions","getMessage","snapId","message","args","prefix","createConsole","undefined","keys","Object","getOwnPropertyNames","console","attenuatedConsole","reduce","target","key","has","harden","value","optionalParams","endowmentModule","names","factory"],"mappings":"AAAA,SAASA,MAAM,QAAQ,kBAAkB;AAEzC,SAASC,eAAe,QAAQ,kBAAkB;AAGlD,OAAO,MAAMC,2BAA2B,IAAIC,IAAI;IAC9C;IACA;IACA;IACA;IACA;IACA;CACD,EAAE;AAEH;;;CAGC,GACD,OAAO,MAAMC,iBAAiB,IAAID,IAAI;IACpC;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,EAAE;AAEH,MAAME,mBAAmB;IAAC;IAAO;IAAS;IAAS;IAAQ;CAAO;AAMlE;;;;;;;;CAQC,GACD,SAASC,WAAWC,MAAc,EAAEC,OAAgB,EAAE,GAAGC,IAAe;IACtE,MAAMC,SAAS,CAAC,OAAO,EAAEH,OAAO,CAAC,CAAC;IAElC,qFAAqF;IACrF,+BAA+B;IAC/B,IAAI,OAAOC,YAAY,UAAU;QAC/B,OAAO;YAAC,CAAC,EAAEE,OAAO,CAAC,EAAEF,QAAQ,CAAC;eAAKC;SAAK;IAC1C;IAEA,sFAAsF;IACtF,4BAA4B;IAC5B,OAAO;QAACC;QAAQF;WAAYC;KAAK;AACnC;AAEA;;;;;;;CAOC,GACD,SAASE,cAAc,EAAEJ,MAAM,EAA2B,GAAG,CAAC,CAAC;IAC7DP,OAAOO,WAAWK;IAClB,MAAMC,OAAOC,OAAOC,mBAAmB,CACrCd,gBAAgBe,OAAO;IAGzB,MAAMC,oBAAoBJ,KAAKK,MAAM,CAAC,CAACC,QAAQC;QAC7C,IAAIhB,eAAeiB,GAAG,CAACD,QAAQ,CAAClB,yBAAyBmB,GAAG,CAACD,MAAM;YACjE,OAAO;gBAAE,GAAGD,MAAM;gBAAE,CAACC,IAAI,EAAEnB,gBAAgBe,OAAO,CAACI,IAAI;YAAC;QAC1D;QAEA,OAAOD;IACT,GAAG,CAAC;IAEJ,OAAOG,OAAO;QACZN,SAAS;YACP,GAAGC,iBAAiB;YACpBjB,QAAQ,CACNuB,OACAf,SACA,GAAGgB;gBAEHvB,gBAAgBe,OAAO,CAAChB,MAAM,CAC5BuB,UACGjB,WAAWC,QAAQC,YAAYgB;YAEtC;YACA,GAAGnB,iBAAiBa,MAAM,CAAmB,CAACC,QAAQC;gBACpD,OAAO;oBACL,GAAGD,MAAM;oBACT,CAACC,IAAI,EAAE,CAACZ,SAAmB,GAAGgB;wBAC5BvB,gBAAgBe,OAAO,CAACI,IAAI,IACvBd,WAAWC,QAAQC,YAAYgB;oBAEtC;gBACF;YACF,GAAG,CAAC,EAAsB;QAC5B;IACF;AACF;AAEA,MAAMC,kBAAkB;IACtBC,OAAO;QAAC;KAAU;IAClBC,SAAShB;AACX;AAEA,eAAec,gBAAgB"}
@@ -1,26 +0,0 @@
1
- import { rootRealmGlobal } from '../globalObject';
2
- export const createCrypto = ()=>{
3
- if ('crypto' in rootRealmGlobal && typeof rootRealmGlobal.crypto === 'object' && 'SubtleCrypto' in rootRealmGlobal && typeof rootRealmGlobal.SubtleCrypto === 'function') {
4
- return {
5
- crypto: harden(rootRealmGlobal.crypto),
6
- SubtleCrypto: harden(rootRealmGlobal.SubtleCrypto)
7
- };
8
- }
9
- // For now, we expose the experimental webcrypto API for Node.js execution environments
10
- // TODO: Figure out if this is enough long-term or if we should use a polyfill.
11
- /* eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */ const crypto = require('crypto').webcrypto;
12
- return {
13
- crypto: harden(crypto),
14
- SubtleCrypto: harden(crypto.subtle.constructor)
15
- };
16
- };
17
- const endowmentModule = {
18
- names: [
19
- 'crypto',
20
- 'SubtleCrypto'
21
- ],
22
- factory: createCrypto
23
- };
24
- export default endowmentModule;
25
-
26
- //# sourceMappingURL=crypto.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/crypto.ts"],"sourcesContent":["import { rootRealmGlobal } from '../globalObject';\n\nexport const createCrypto = () => {\n if (\n 'crypto' in rootRealmGlobal &&\n typeof rootRealmGlobal.crypto === 'object' &&\n 'SubtleCrypto' in rootRealmGlobal &&\n typeof rootRealmGlobal.SubtleCrypto === 'function'\n ) {\n return {\n crypto: harden(rootRealmGlobal.crypto),\n SubtleCrypto: harden(rootRealmGlobal.SubtleCrypto),\n };\n }\n // For now, we expose the experimental webcrypto API for Node.js execution environments\n // TODO: Figure out if this is enough long-term or if we should use a polyfill.\n /* eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires, n/global-require */\n const crypto = require('crypto').webcrypto;\n return {\n crypto: harden(crypto),\n SubtleCrypto: harden(crypto.subtle.constructor),\n } as const;\n};\n\nconst endowmentModule = {\n names: ['crypto', 'SubtleCrypto'] as const,\n factory: createCrypto,\n};\nexport default endowmentModule;\n"],"names":["rootRealmGlobal","createCrypto","crypto","SubtleCrypto","harden","require","webcrypto","subtle","constructor","endowmentModule","names","factory"],"mappings":"AAAA,SAASA,eAAe,QAAQ,kBAAkB;AAElD,OAAO,MAAMC,eAAe;IAC1B,IACE,YAAYD,mBACZ,OAAOA,gBAAgBE,MAAM,KAAK,YAClC,kBAAkBF,mBAClB,OAAOA,gBAAgBG,YAAY,KAAK,YACxC;QACA,OAAO;YACLD,QAAQE,OAAOJ,gBAAgBE,MAAM;YACrCC,cAAcC,OAAOJ,gBAAgBG,YAAY;QACnD;IACF;IACA,uFAAuF;IACvF,+EAA+E;IAC/E,wHAAwH,GACxH,MAAMD,SAASG,QAAQ,UAAUC,SAAS;IAC1C,OAAO;QACLJ,QAAQE,OAAOF;QACfC,cAAcC,OAAOF,OAAOK,MAAM,CAACC,WAAW;IAChD;AACF,EAAE;AAEF,MAAMC,kBAAkB;IACtBC,OAAO;QAAC;QAAU;KAAe;IACjCC,SAASV;AACX;AACA,eAAeQ,gBAAgB"}
@@ -1,43 +0,0 @@
1
- import { rootRealmGlobal } from '../globalObject';
2
- /**
3
- * Creates a {@link Date} constructor, with most of the same properties as the global object.
4
- * The Date.now() function has added noise as to limit its precision and prevent potential timing attacks.
5
- * The Date constructor uses this now() function to seed itself if no arguments are given to the constructor.
6
- *
7
- * @returns A modified {@link Date} constructor with limited precision.
8
- */ function createDate() {
9
- const keys = Object.getOwnPropertyNames(rootRealmGlobal.Date);
10
- let currentTime = 0;
11
- const now = ()=>{
12
- const actual = rootRealmGlobal.Date.now();
13
- const newTime = Math.round(actual + Math.random());
14
- if (newTime > currentTime) {
15
- currentTime = newTime;
16
- }
17
- return currentTime;
18
- };
19
- const NewDate = function(...args) {
20
- return Reflect.construct(rootRealmGlobal.Date, args.length === 0 ? [
21
- now()
22
- ] : args, new.target);
23
- };
24
- keys.forEach((key)=>{
25
- Reflect.defineProperty(NewDate, key, {
26
- configurable: false,
27
- writable: false,
28
- value: key === 'now' ? now : rootRealmGlobal.Date[key]
29
- });
30
- });
31
- return {
32
- Date: harden(NewDate)
33
- };
34
- }
35
- const endowmentModule = {
36
- names: [
37
- 'Date'
38
- ],
39
- factory: createDate
40
- };
41
- export default endowmentModule;
42
-
43
- //# sourceMappingURL=date.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/date.ts"],"sourcesContent":["import { rootRealmGlobal } from '../globalObject';\n\n/**\n * Creates a {@link Date} constructor, with most of the same properties as the global object.\n * The Date.now() function has added noise as to limit its precision and prevent potential timing attacks.\n * The Date constructor uses this now() function to seed itself if no arguments are given to the constructor.\n *\n * @returns A modified {@link Date} constructor with limited precision.\n */\nfunction createDate() {\n const keys = Object.getOwnPropertyNames(\n rootRealmGlobal.Date,\n ) as (keyof typeof Date)[];\n\n let currentTime = 0;\n const now = () => {\n const actual = rootRealmGlobal.Date.now();\n const newTime = Math.round(actual + Math.random());\n if (newTime > currentTime) {\n currentTime = newTime;\n }\n return currentTime;\n };\n\n const NewDate = function (...args: unknown[]) {\n return Reflect.construct(\n rootRealmGlobal.Date,\n args.length === 0 ? [now()] : args,\n new.target,\n );\n } as DateConstructor;\n\n keys.forEach((key) => {\n Reflect.defineProperty(NewDate, key, {\n configurable: false,\n writable: false,\n value: key === 'now' ? now : rootRealmGlobal.Date[key],\n });\n });\n\n return { Date: harden(NewDate) };\n}\n\nconst endowmentModule = {\n names: ['Date'] as const,\n factory: createDate,\n};\n\nexport default endowmentModule;\n"],"names":["rootRealmGlobal","createDate","keys","Object","getOwnPropertyNames","Date","currentTime","now","actual","newTime","Math","round","random","NewDate","args","Reflect","construct","length","forEach","key","defineProperty","configurable","writable","value","harden","endowmentModule","names","factory"],"mappings":"AAAA,SAASA,eAAe,QAAQ,kBAAkB;AAElD;;;;;;CAMC,GACD,SAASC;IACP,MAAMC,OAAOC,OAAOC,mBAAmB,CACrCJ,gBAAgBK,IAAI;IAGtB,IAAIC,cAAc;IAClB,MAAMC,MAAM;QACV,MAAMC,SAASR,gBAAgBK,IAAI,CAACE,GAAG;QACvC,MAAME,UAAUC,KAAKC,KAAK,CAACH,SAASE,KAAKE,MAAM;QAC/C,IAAIH,UAAUH,aAAa;YACzBA,cAAcG;QAChB;QACA,OAAOH;IACT;IAEA,MAAMO,UAAU,SAAU,GAAGC,IAAe;QAC1C,OAAOC,QAAQC,SAAS,CACtBhB,gBAAgBK,IAAI,EACpBS,KAAKG,MAAM,KAAK,IAAI;YAACV;SAAM,GAAGO,MAC9B;IAEJ;IAEAZ,KAAKgB,OAAO,CAAC,CAACC;QACZJ,QAAQK,cAAc,CAACP,SAASM,KAAK;YACnCE,cAAc;YACdC,UAAU;YACVC,OAAOJ,QAAQ,QAAQZ,MAAMP,gBAAgBK,IAAI,CAACc,IAAI;QACxD;IACF;IAEA,OAAO;QAAEd,MAAMmB,OAAOX;IAAS;AACjC;AAEA,MAAMY,kBAAkB;IACtBC,OAAO;QAAC;KAAO;IACfC,SAAS1B;AACX;AAEA,eAAewB,gBAAgB"}
@@ -1,92 +0,0 @@
1
- import { rpcErrors } from '@metamask/rpc-errors';
2
- import { logWarning } from '@metamask/snaps-utils';
3
- import { hasProperty } from '@metamask/utils';
4
- import { rootRealmGlobal } from '../globalObject';
5
- import buildCommonEndowments from './commonEndowmentFactory';
6
- /**
7
- * Retrieve consolidated endowment factories for common endowments.
8
- */ const registeredEndowments = buildCommonEndowments();
9
- /**
10
- * A map of endowment names to their factory functions. Some endowments share
11
- * the same factory function, but we only call each factory once for each snap.
12
- * See {@link createEndowments} for details.
13
- */ const endowmentFactories = registeredEndowments.reduce((factories, builder)=>{
14
- builder.names.forEach((name)=>{
15
- factories.set(name, builder.factory);
16
- });
17
- return factories;
18
- }, new Map());
19
- /**
20
- * Gets the endowments for a particular Snap. Some endowments, like `setTimeout`
21
- * and `clearTimeout`, must be attenuated so that they can only affect behavior
22
- * within the Snap's own realm. Therefore, we use factory functions to create
23
- * such attenuated / modified endowments. Otherwise, the value that's on the
24
- * root realm global will be used.
25
- *
26
- * @param options - An options bag.
27
- * @param options.snap - The Snaps global API object.
28
- * @param options.ethereum - The Snap's EIP-1193 provider object.
29
- * @param options.snapId - The id of the snap that will use the created endowments.
30
- * @param options.endowments - The list of endowments to provide to the snap.
31
- * @param options.notify - A reference to the notify function of the snap executor.
32
- * @returns An object containing the Snap's endowments.
33
- */ export function createEndowments({ snap, ethereum, snapId, endowments, notify }) {
34
- const attenuatedEndowments = {};
35
- // TODO: All endowments should be hardened to prevent covert communication
36
- // channels. Hardening the returned objects breaks tests elsewhere in the
37
- // monorepo, so further research is needed.
38
- const result = endowments.reduce(({ allEndowments, teardowns }, endowmentName)=>{
39
- // First, check if the endowment has a factory, and default to that.
40
- if (endowmentFactories.has(endowmentName)) {
41
- if (!hasProperty(attenuatedEndowments, endowmentName)) {
42
- // Call the endowment factory for the current endowment. If the factory
43
- // creates multiple endowments, they will all be assigned to the
44
- // `attenuatedEndowments` object, but will only be passed on to the snap
45
- // if explicitly listed among its endowment.
46
- // This may not have an actual use case, but, safety first.
47
- // We just confirmed that endowmentFactories has the specified key.
48
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
49
- const { teardownFunction, ...endowment } = endowmentFactories.get(endowmentName)({
50
- snapId,
51
- notify
52
- });
53
- Object.assign(attenuatedEndowments, endowment);
54
- if (teardownFunction) {
55
- teardowns.push(teardownFunction);
56
- }
57
- }
58
- allEndowments[endowmentName] = attenuatedEndowments[endowmentName];
59
- } else if (endowmentName === 'ethereum') {
60
- // Special case for adding the EIP-1193 provider.
61
- allEndowments[endowmentName] = ethereum;
62
- } else if (endowmentName in rootRealmGlobal) {
63
- logWarning(`Access to unhardened global ${endowmentName}.`);
64
- // If the endowment doesn't have a factory, just use whatever is on the
65
- // global object.
66
- const globalValue = rootRealmGlobal[endowmentName];
67
- allEndowments[endowmentName] = globalValue;
68
- } else {
69
- // If we get to this point, we've been passed an endowment that doesn't
70
- // exist in our current environment.
71
- throw rpcErrors.internal(`Unknown endowment: "${endowmentName}".`);
72
- }
73
- return {
74
- allEndowments,
75
- teardowns
76
- };
77
- }, {
78
- allEndowments: {
79
- snap
80
- },
81
- teardowns: []
82
- });
83
- const teardown = async ()=>{
84
- await Promise.all(result.teardowns.map((teardownFunction)=>teardownFunction()));
85
- };
86
- return {
87
- endowments: result.allEndowments,
88
- teardown
89
- };
90
- }
91
-
92
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/index.ts"],"sourcesContent":["import type { StreamProvider } from '@metamask/providers';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { SnapsProvider } from '@metamask/snaps-sdk';\nimport { logWarning } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\n\nimport type { NotifyFunction } from '../BaseSnapExecutor';\nimport { rootRealmGlobal } from '../globalObject';\nimport type { EndowmentFactoryOptions } from './commonEndowmentFactory';\nimport buildCommonEndowments from './commonEndowmentFactory';\n\ntype EndowmentFactoryResult = {\n /**\n * A function that performs any necessary teardown when the snap becomes idle.\n *\n * NOTE:** The endowments are not reconstructed if the snap is re-invoked\n * before being terminated, so the teardown operation must not render the\n * endowments unusable; it should simply restore the endowments to their\n * original state.\n */\n teardownFunction?: () => Promise<void> | void;\n [key: string]: unknown;\n};\n\n/**\n * Retrieve consolidated endowment factories for common endowments.\n */\nconst registeredEndowments = buildCommonEndowments();\n\n/**\n * A map of endowment names to their factory functions. Some endowments share\n * the same factory function, but we only call each factory once for each snap.\n * See {@link createEndowments} for details.\n */\nconst endowmentFactories = registeredEndowments.reduce((factories, builder) => {\n builder.names.forEach((name) => {\n factories.set(name, builder.factory);\n });\n return factories;\n}, new Map<string, (options?: EndowmentFactoryOptions) => EndowmentFactoryResult>());\n\n/**\n * Gets the endowments for a particular Snap. Some endowments, like `setTimeout`\n * and `clearTimeout`, must be attenuated so that they can only affect behavior\n * within the Snap's own realm. Therefore, we use factory functions to create\n * such attenuated / modified endowments. Otherwise, the value that's on the\n * root realm global will be used.\n *\n * @param options - An options bag.\n * @param options.snap - The Snaps global API object.\n * @param options.ethereum - The Snap's EIP-1193 provider object.\n * @param options.snapId - The id of the snap that will use the created endowments.\n * @param options.endowments - The list of endowments to provide to the snap.\n * @param options.notify - A reference to the notify function of the snap executor.\n * @returns An object containing the Snap's endowments.\n */\nexport function createEndowments({\n snap,\n ethereum,\n snapId,\n endowments,\n notify,\n}: {\n snap: SnapsProvider;\n ethereum: StreamProvider;\n snapId: string;\n endowments: string[];\n notify: NotifyFunction;\n}): { endowments: Record<string, unknown>; teardown: () => Promise<void> } {\n const attenuatedEndowments: Record<string, unknown> = {};\n\n // TODO: All endowments should be hardened to prevent covert communication\n // channels. Hardening the returned objects breaks tests elsewhere in the\n // monorepo, so further research is needed.\n const result = endowments.reduce<{\n allEndowments: Record<string, unknown>;\n teardowns: (() => Promise<void> | void)[];\n }>(\n ({ allEndowments, teardowns }, endowmentName) => {\n // First, check if the endowment has a factory, and default to that.\n if (endowmentFactories.has(endowmentName)) {\n if (!hasProperty(attenuatedEndowments, endowmentName)) {\n // Call the endowment factory for the current endowment. If the factory\n // creates multiple endowments, they will all be assigned to the\n // `attenuatedEndowments` object, but will only be passed on to the snap\n // if explicitly listed among its endowment.\n // This may not have an actual use case, but, safety first.\n\n // We just confirmed that endowmentFactories has the specified key.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { teardownFunction, ...endowment } = endowmentFactories.get(\n endowmentName,\n )!({ snapId, notify });\n Object.assign(attenuatedEndowments, endowment);\n if (teardownFunction) {\n teardowns.push(teardownFunction);\n }\n }\n allEndowments[endowmentName] = attenuatedEndowments[endowmentName];\n } else if (endowmentName === 'ethereum') {\n // Special case for adding the EIP-1193 provider.\n allEndowments[endowmentName] = ethereum;\n } else if (endowmentName in rootRealmGlobal) {\n logWarning(`Access to unhardened global ${endowmentName}.`);\n // If the endowment doesn't have a factory, just use whatever is on the\n // global object.\n const globalValue = (rootRealmGlobal as Record<string, unknown>)[\n endowmentName\n ];\n allEndowments[endowmentName] = globalValue;\n } else {\n // If we get to this point, we've been passed an endowment that doesn't\n // exist in our current environment.\n throw rpcErrors.internal(`Unknown endowment: \"${endowmentName}\".`);\n }\n return { allEndowments, teardowns };\n },\n {\n allEndowments: { snap },\n teardowns: [],\n },\n );\n\n const teardown = async () => {\n await Promise.all(\n result.teardowns.map((teardownFunction) => teardownFunction()),\n );\n };\n return { endowments: result.allEndowments, teardown };\n}\n"],"names":["rpcErrors","logWarning","hasProperty","rootRealmGlobal","buildCommonEndowments","registeredEndowments","endowmentFactories","reduce","factories","builder","names","forEach","name","set","factory","Map","createEndowments","snap","ethereum","snapId","endowments","notify","attenuatedEndowments","result","allEndowments","teardowns","endowmentName","has","teardownFunction","endowment","get","Object","assign","push","globalValue","internal","teardown","Promise","all","map"],"mappings":"AACA,SAASA,SAAS,QAAQ,uBAAuB;AAEjD,SAASC,UAAU,QAAQ,wBAAwB;AACnD,SAASC,WAAW,QAAQ,kBAAkB;AAG9C,SAASC,eAAe,QAAQ,kBAAkB;AAElD,OAAOC,2BAA2B,2BAA2B;AAe7D;;CAEC,GACD,MAAMC,uBAAuBD;AAE7B;;;;CAIC,GACD,MAAME,qBAAqBD,qBAAqBE,MAAM,CAAC,CAACC,WAAWC;IACjEA,QAAQC,KAAK,CAACC,OAAO,CAAC,CAACC;QACrBJ,UAAUK,GAAG,CAACD,MAAMH,QAAQK,OAAO;IACrC;IACA,OAAON;AACT,GAAG,IAAIO;AAEP;;;;;;;;;;;;;;CAcC,GACD,OAAO,SAASC,iBAAiB,EAC/BC,IAAI,EACJC,QAAQ,EACRC,MAAM,EACNC,UAAU,EACVC,MAAM,EAOP;IACC,MAAMC,uBAAgD,CAAC;IAEvD,0EAA0E;IAC1E,yEAAyE;IACzE,2CAA2C;IAC3C,MAAMC,SAASH,WAAWb,MAAM,CAI9B,CAAC,EAAEiB,aAAa,EAAEC,SAAS,EAAE,EAAEC;QAC7B,oEAAoE;QACpE,IAAIpB,mBAAmBqB,GAAG,CAACD,gBAAgB;YACzC,IAAI,CAACxB,YAAYoB,sBAAsBI,gBAAgB;gBACrD,uEAAuE;gBACvE,gEAAgE;gBAChE,wEAAwE;gBACxE,4CAA4C;gBAC5C,2DAA2D;gBAE3D,mEAAmE;gBACnE,oEAAoE;gBACpE,MAAM,EAAEE,gBAAgB,EAAE,GAAGC,WAAW,GAAGvB,mBAAmBwB,GAAG,CAC/DJ,eACC;oBAAEP;oBAAQE;gBAAO;gBACpBU,OAAOC,MAAM,CAACV,sBAAsBO;gBACpC,IAAID,kBAAkB;oBACpBH,UAAUQ,IAAI,CAACL;gBACjB;YACF;YACAJ,aAAa,CAACE,cAAc,GAAGJ,oBAAoB,CAACI,cAAc;QACpE,OAAO,IAAIA,kBAAkB,YAAY;YACvC,iDAAiD;YACjDF,aAAa,CAACE,cAAc,GAAGR;QACjC,OAAO,IAAIQ,iBAAiBvB,iBAAiB;YAC3CF,WAAW,CAAC,4BAA4B,EAAEyB,cAAc,CAAC,CAAC;YAC1D,uEAAuE;YACvE,iBAAiB;YACjB,MAAMQ,cAAc,AAAC/B,eAA2C,CAC9DuB,cACD;YACDF,aAAa,CAACE,cAAc,GAAGQ;QACjC,OAAO;YACL,uEAAuE;YACvE,oCAAoC;YACpC,MAAMlC,UAAUmC,QAAQ,CAAC,CAAC,oBAAoB,EAAET,cAAc,EAAE,CAAC;QACnE;QACA,OAAO;YAAEF;YAAeC;QAAU;IACpC,GACA;QACED,eAAe;YAAEP;QAAK;QACtBQ,WAAW,EAAE;IACf;IAGF,MAAMW,WAAW;QACf,MAAMC,QAAQC,GAAG,CACff,OAAOE,SAAS,CAACc,GAAG,CAAC,CAACX,mBAAqBA;IAE/C;IACA,OAAO;QAAER,YAAYG,OAAOC,aAAa;QAAEY;IAAS;AACtD"}
@@ -1,52 +0,0 @@
1
- import { rpcErrors } from '@metamask/rpc-errors';
2
- const MINIMUM_INTERVAL = 10;
3
- /**
4
- * Creates a pair of `setInterval` and `clearInterval` functions attenuated such
5
- * that:
6
- * - `setInterval` throws if its "handler" parameter is not a function.
7
- * - `clearInterval` only clears timeouts created by its sibling `setInterval`,
8
- * or else no-ops.
9
- *
10
- * @returns An object with the attenuated `setInterval` and `clearInterval`
11
- * functions.
12
- */ const createInterval = ()=>{
13
- const registeredHandles = new Map();
14
- const _setInterval = (handler, timeout)=>{
15
- if (typeof handler !== 'function') {
16
- throw rpcErrors.invalidInput(`The interval handler must be a function. Received: ${typeof handler}.`);
17
- }
18
- harden(handler);
19
- const handle = Object.freeze(Object.create(null));
20
- const platformHandle = setInterval(handler, Math.max(MINIMUM_INTERVAL, timeout ?? 0));
21
- registeredHandles.set(handle, platformHandle);
22
- return handle;
23
- };
24
- const _clearInterval = (handle)=>{
25
- harden(handle);
26
- const platformHandle = registeredHandles.get(handle);
27
- if (platformHandle !== undefined) {
28
- clearInterval(platformHandle);
29
- registeredHandles.delete(handle);
30
- }
31
- };
32
- const teardownFunction = ()=>{
33
- for (const handle of registeredHandles.keys()){
34
- _clearInterval(handle);
35
- }
36
- };
37
- return {
38
- setInterval: harden(_setInterval),
39
- clearInterval: harden(_clearInterval),
40
- teardownFunction
41
- };
42
- };
43
- const endowmentModule = {
44
- names: [
45
- 'setInterval',
46
- 'clearInterval'
47
- ],
48
- factory: createInterval
49
- };
50
- export default endowmentModule;
51
-
52
- //# sourceMappingURL=interval.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/interval.ts"],"sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\n\nconst MINIMUM_INTERVAL = 10;\n\n/**\n * Creates a pair of `setInterval` and `clearInterval` functions attenuated such\n * that:\n * - `setInterval` throws if its \"handler\" parameter is not a function.\n * - `clearInterval` only clears timeouts created by its sibling `setInterval`,\n * or else no-ops.\n *\n * @returns An object with the attenuated `setInterval` and `clearInterval`\n * functions.\n */\nconst createInterval = () => {\n const registeredHandles = new Map<unknown, unknown>();\n\n const _setInterval = (handler: TimerHandler, timeout?: number): unknown => {\n if (typeof handler !== 'function') {\n throw rpcErrors.invalidInput(\n `The interval handler must be a function. Received: ${typeof handler}.`,\n );\n }\n harden(handler);\n const handle = Object.freeze(Object.create(null));\n const platformHandle = setInterval(\n handler,\n Math.max(MINIMUM_INTERVAL, timeout ?? 0),\n );\n registeredHandles.set(handle, platformHandle);\n return handle;\n };\n\n const _clearInterval = (handle: unknown): void => {\n harden(handle);\n const platformHandle = registeredHandles.get(handle);\n if (platformHandle !== undefined) {\n clearInterval(platformHandle as any);\n registeredHandles.delete(handle);\n }\n };\n\n const teardownFunction = (): void => {\n for (const handle of registeredHandles.keys()) {\n _clearInterval(handle);\n }\n };\n\n return {\n setInterval: harden(_setInterval),\n clearInterval: harden(_clearInterval),\n teardownFunction,\n } as const;\n};\n\nconst endowmentModule = {\n names: ['setInterval', 'clearInterval'] as const,\n factory: createInterval,\n};\nexport default endowmentModule;\n"],"names":["rpcErrors","MINIMUM_INTERVAL","createInterval","registeredHandles","Map","_setInterval","handler","timeout","invalidInput","harden","handle","Object","freeze","create","platformHandle","setInterval","Math","max","set","_clearInterval","get","undefined","clearInterval","delete","teardownFunction","keys","endowmentModule","names","factory"],"mappings":"AAAA,SAASA,SAAS,QAAQ,uBAAuB;AAEjD,MAAMC,mBAAmB;AAEzB;;;;;;;;;CASC,GACD,MAAMC,iBAAiB;IACrB,MAAMC,oBAAoB,IAAIC;IAE9B,MAAMC,eAAe,CAACC,SAAuBC;QAC3C,IAAI,OAAOD,YAAY,YAAY;YACjC,MAAMN,UAAUQ,YAAY,CAC1B,CAAC,mDAAmD,EAAE,OAAOF,QAAQ,CAAC,CAAC;QAE3E;QACAG,OAAOH;QACP,MAAMI,SAASC,OAAOC,MAAM,CAACD,OAAOE,MAAM,CAAC;QAC3C,MAAMC,iBAAiBC,YACrBT,SACAU,KAAKC,GAAG,CAAChB,kBAAkBM,WAAW;QAExCJ,kBAAkBe,GAAG,CAACR,QAAQI;QAC9B,OAAOJ;IACT;IAEA,MAAMS,iBAAiB,CAACT;QACtBD,OAAOC;QACP,MAAMI,iBAAiBX,kBAAkBiB,GAAG,CAACV;QAC7C,IAAII,mBAAmBO,WAAW;YAChCC,cAAcR;YACdX,kBAAkBoB,MAAM,CAACb;QAC3B;IACF;IAEA,MAAMc,mBAAmB;QACvB,KAAK,MAAMd,UAAUP,kBAAkBsB,IAAI,GAAI;YAC7CN,eAAeT;QACjB;IACF;IAEA,OAAO;QACLK,aAAaN,OAAOJ;QACpBiB,eAAeb,OAAOU;QACtBK;IACF;AACF;AAEA,MAAME,kBAAkB;IACtBC,OAAO;QAAC;QAAe;KAAgB;IACvCC,SAAS1B;AACX;AACA,eAAewB,gBAAgB"}
@@ -1,57 +0,0 @@
1
- import { rootRealmGlobal } from '../globalObject';
2
- import { createCrypto } from './crypto';
3
- /**
4
- * Create a {@link Math} object, with the same properties as the global
5
- * {@link Math} object, but with the {@link Math.random} method replaced.
6
- *
7
- * @returns The {@link Math} object with the {@link Math.random} method
8
- * replaced.
9
- */ function createMath() {
10
- // `Math` does not work with `Object.keys`, `Object.entries`, etc., so we
11
- // need to create a new object with the same properties.
12
- const keys = Object.getOwnPropertyNames(rootRealmGlobal.Math);
13
- const math = keys.reduce((target, key)=>{
14
- if (key === 'random') {
15
- return target;
16
- }
17
- return {
18
- ...target,
19
- [key]: rootRealmGlobal.Math[key]
20
- };
21
- }, {});
22
- // Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto
23
- const { crypto: hardenedCrypto } = createCrypto();
24
- return harden({
25
- Math: {
26
- ...math,
27
- random: ()=>{
28
- // NOTE: This is not intended to be a secure replacement for the weak
29
- // random number generator used by `Math.random`. It is only intended to
30
- // prevent side channel attacks of `Math.random` by replacing it with an
31
- // alternative implementation that is not vulnerable to the same
32
- // attacks.
33
- //
34
- // This does not mean that this implementation is secure. It is not
35
- // intended to be used in a security context, and this implementation
36
- // may change at any time.
37
- //
38
- // To securely generate random numbers, use a cryptographically secure
39
- // random number generator, such as the one provided by the Web Crypto
40
- // API:
41
- //
42
- // - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
43
- // - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
44
- return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;
45
- }
46
- }
47
- });
48
- }
49
- const endowmentModule = {
50
- names: [
51
- 'Math'
52
- ],
53
- factory: createMath
54
- };
55
- export default endowmentModule;
56
-
57
- //# sourceMappingURL=math.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../../../src/common/endowments/math.ts"],"sourcesContent":["import { rootRealmGlobal } from '../globalObject';\nimport { createCrypto } from './crypto';\n\n/**\n * Create a {@link Math} object, with the same properties as the global\n * {@link Math} object, but with the {@link Math.random} method replaced.\n *\n * @returns The {@link Math} object with the {@link Math.random} method\n * replaced.\n */\nfunction createMath() {\n // `Math` does not work with `Object.keys`, `Object.entries`, etc., so we\n // need to create a new object with the same properties.\n const keys = Object.getOwnPropertyNames(\n rootRealmGlobal.Math,\n ) as (keyof typeof Math)[];\n\n const math = keys.reduce<Partial<Math>>((target, key) => {\n if (key === 'random') {\n return target;\n }\n\n return { ...target, [key]: rootRealmGlobal.Math[key] };\n }, {});\n\n // Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto\n const { crypto: hardenedCrypto } = createCrypto();\n\n return harden({\n Math: {\n ...math,\n random: () => {\n // NOTE: This is not intended to be a secure replacement for the weak\n // random number generator used by `Math.random`. It is only intended to\n // prevent side channel attacks of `Math.random` by replacing it with an\n // alternative implementation that is not vulnerable to the same\n // attacks.\n //\n // This does not mean that this implementation is secure. It is not\n // intended to be used in a security context, and this implementation\n // may change at any time.\n //\n // To securely generate random numbers, use a cryptographically secure\n // random number generator, such as the one provided by the Web Crypto\n // API:\n //\n // - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey\n // - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues\n return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;\n },\n },\n });\n}\n\nconst endowmentModule = {\n names: ['Math'] as const,\n factory: createMath,\n};\n\nexport default endowmentModule;\n"],"names":["rootRealmGlobal","createCrypto","createMath","keys","Object","getOwnPropertyNames","Math","math","reduce","target","key","crypto","hardenedCrypto","harden","random","getRandomValues","Uint32Array","endowmentModule","names","factory"],"mappings":"AAAA,SAASA,eAAe,QAAQ,kBAAkB;AAClD,SAASC,YAAY,QAAQ,WAAW;AAExC;;;;;;CAMC,GACD,SAASC;IACP,yEAAyE;IACzE,wDAAwD;IACxD,MAAMC,OAAOC,OAAOC,mBAAmB,CACrCL,gBAAgBM,IAAI;IAGtB,MAAMC,OAAOJ,KAAKK,MAAM,CAAgB,CAACC,QAAQC;QAC/C,IAAIA,QAAQ,UAAU;YACpB,OAAOD;QACT;QAEA,OAAO;YAAE,GAAGA,MAAM;YAAE,CAACC,IAAI,EAAEV,gBAAgBM,IAAI,CAACI,IAAI;QAAC;IACvD,GAAG,CAAC;IAEJ,uJAAuJ;IACvJ,MAAM,EAAEC,QAAQC,cAAc,EAAE,GAAGX;IAEnC,OAAOY,OAAO;QACZP,MAAM;YACJ,GAAGC,IAAI;YACPO,QAAQ;gBACN,qEAAqE;gBACrE,wEAAwE;gBACxE,wEAAwE;gBACxE,gEAAgE;gBAChE,WAAW;gBACX,EAAE;gBACF,mEAAmE;gBACnE,qEAAqE;gBACrE,0BAA0B;gBAC1B,EAAE;gBACF,sEAAsE;gBACtE,sEAAsE;gBACtE,OAAO;gBACP,EAAE;gBACF,8EAA8E;gBAC9E,4EAA4E;gBAC5E,OAAOF,eAAeG,eAAe,CAAC,IAAIC,YAAY,GAAG,CAAC,EAAE,GAAG,KAAK;YACtE;QACF;IACF;AACF;AAEA,MAAMC,kBAAkB;IACtBC,OAAO;QAAC;KAAO;IACfC,SAASjB;AACX;AAEA,eAAee,gBAAgB"}