@metamask/snaps-execution-environments 6.6.1 → 6.7.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 (526) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/common/BaseSnapExecutor.cjs +436 -0
  3. package/dist/common/BaseSnapExecutor.cjs.map +1 -0
  4. package/dist/{types/common/BaseSnapExecutor.d.ts → common/BaseSnapExecutor.d.cts} +8 -6
  5. package/dist/common/BaseSnapExecutor.d.cts.map +1 -0
  6. package/dist/common/BaseSnapExecutor.d.mts +70 -0
  7. package/dist/common/BaseSnapExecutor.d.mts.map +1 -0
  8. package/dist/common/BaseSnapExecutor.mjs +430 -24
  9. package/dist/common/BaseSnapExecutor.mjs.map +1 -1
  10. package/dist/common/commands.cjs +95 -0
  11. package/dist/common/commands.cjs.map +1 -0
  12. package/dist/{types/common/commands.d.ts → common/commands.d.cts} +5 -4
  13. package/dist/common/commands.d.cts.map +1 -0
  14. package/dist/common/commands.d.mts +31 -0
  15. package/dist/common/commands.d.mts.map +1 -0
  16. package/dist/common/commands.mjs +89 -10
  17. package/dist/common/commands.mjs.map +1 -1
  18. package/dist/common/endowments/commonEndowmentFactory.cjs +76 -0
  19. package/dist/common/endowments/commonEndowmentFactory.cjs.map +1 -0
  20. package/dist/{types/common/endowments/commonEndowmentFactory.d.ts → common/endowments/commonEndowmentFactory.d.cts} +5 -4
  21. package/dist/common/endowments/commonEndowmentFactory.d.cts.map +1 -0
  22. package/dist/common/endowments/commonEndowmentFactory.d.mts +26 -0
  23. package/dist/common/endowments/commonEndowmentFactory.d.mts.map +1 -0
  24. package/dist/common/endowments/commonEndowmentFactory.mjs +69 -18
  25. package/dist/common/endowments/commonEndowmentFactory.mjs.map +1 -1
  26. package/dist/common/endowments/console.cjs +103 -0
  27. package/dist/common/endowments/console.cjs.map +1 -0
  28. package/dist/{types/common/endowments/console.d.ts → common/endowments/console.d.cts} +2 -1
  29. package/dist/common/endowments/console.d.cts.map +1 -0
  30. package/dist/common/endowments/console.d.mts +46 -0
  31. package/dist/common/endowments/console.d.mts.map +1 -0
  32. package/dist/common/endowments/console.mjs +98 -11
  33. package/dist/common/endowments/console.mjs.map +1 -1
  34. package/dist/common/endowments/crypto.cjs +30 -0
  35. package/dist/common/endowments/crypto.cjs.map +1 -0
  36. package/dist/{types/common/endowments/crypto.d.ts → common/endowments/crypto.d.cts} +1 -0
  37. package/dist/common/endowments/crypto.d.cts.map +1 -0
  38. package/dist/common/endowments/crypto.d.mts +13 -0
  39. package/dist/common/endowments/crypto.d.mts.map +1 -0
  40. package/dist/common/endowments/crypto.mjs +24 -9
  41. package/dist/common/endowments/crypto.mjs.map +1 -1
  42. package/dist/common/endowments/date.cjs +39 -0
  43. package/dist/common/endowments/date.cjs.map +1 -0
  44. package/dist/{types/common/endowments/date.d.ts → common/endowments/date.d.cts} +1 -0
  45. package/dist/common/endowments/date.d.cts.map +1 -0
  46. package/dist/common/endowments/date.d.mts +16 -0
  47. package/dist/common/endowments/date.d.mts.map +1 -0
  48. package/dist/common/endowments/date.mjs +35 -7
  49. package/dist/common/endowments/date.mjs.map +1 -1
  50. package/dist/common/endowments/index.cjs +93 -0
  51. package/dist/common/endowments/index.cjs.map +1 -0
  52. package/dist/{types/common/endowments/index.d.ts → common/endowments/index.d.cts} +4 -3
  53. package/dist/common/endowments/index.d.cts.map +1 -0
  54. package/dist/common/endowments/index.d.mts +29 -0
  55. package/dist/common/endowments/index.d.mts.map +1 -0
  56. package/dist/common/endowments/index.mjs +85 -20
  57. package/dist/common/endowments/index.mjs.map +1 -1
  58. package/dist/common/endowments/interval.cjs +51 -0
  59. package/dist/common/endowments/interval.cjs.map +1 -0
  60. package/dist/{types/common/endowments/interval.d.ts → common/endowments/interval.d.cts} +1 -0
  61. package/dist/common/endowments/interval.d.cts.map +1 -0
  62. package/dist/common/endowments/interval.d.mts +10 -0
  63. package/dist/common/endowments/interval.d.mts.map +1 -0
  64. package/dist/common/endowments/interval.mjs +47 -6
  65. package/dist/common/endowments/interval.mjs.map +1 -1
  66. package/dist/common/endowments/math.cjs +54 -0
  67. package/dist/common/endowments/math.cjs.map +1 -0
  68. package/dist/{types/common/endowments/math.d.ts → common/endowments/math.d.cts} +1 -0
  69. package/dist/common/endowments/math.d.cts.map +1 -0
  70. package/dist/common/endowments/math.d.mts +61 -0
  71. package/dist/common/endowments/math.d.mts.map +1 -0
  72. package/dist/common/endowments/math.mjs +50 -8
  73. package/dist/common/endowments/math.mjs.map +1 -1
  74. package/dist/common/endowments/network.cjs +255 -0
  75. package/dist/common/endowments/network.cjs.map +1 -0
  76. package/dist/{types/common/endowments/network.d.ts → common/endowments/network.d.cts} +4 -2
  77. package/dist/common/endowments/network.d.cts.map +1 -0
  78. package/dist/common/endowments/network.d.mts +25 -0
  79. package/dist/common/endowments/network.d.mts.map +1 -0
  80. package/dist/common/endowments/network.mjs +251 -8
  81. package/dist/common/endowments/network.mjs.map +1 -1
  82. package/dist/common/endowments/textDecoder.cjs +18 -0
  83. package/dist/common/endowments/textDecoder.cjs.map +1 -0
  84. package/dist/{types/common/endowments/textDecoder.d.ts → common/endowments/textDecoder.d.cts} +1 -0
  85. package/dist/common/endowments/textDecoder.d.cts.map +1 -0
  86. package/dist/common/endowments/textDecoder.d.mts +11 -0
  87. package/dist/common/endowments/textDecoder.d.mts.map +1 -0
  88. package/dist/common/endowments/textDecoder.mjs +14 -6
  89. package/dist/common/endowments/textDecoder.mjs.map +1 -1
  90. package/dist/common/endowments/textEncoder.cjs +18 -0
  91. package/dist/common/endowments/textEncoder.cjs.map +1 -0
  92. package/dist/{types/common/endowments/textEncoder.d.ts → common/endowments/textEncoder.d.cts} +1 -0
  93. package/dist/common/endowments/textEncoder.d.cts.map +1 -0
  94. package/dist/common/endowments/textEncoder.d.mts +11 -0
  95. package/dist/common/endowments/textEncoder.d.mts.map +1 -0
  96. package/dist/common/endowments/textEncoder.mjs +14 -6
  97. package/dist/common/endowments/textEncoder.mjs.map +1 -1
  98. package/dist/common/endowments/timeout.cjs +53 -0
  99. package/dist/common/endowments/timeout.cjs.map +1 -0
  100. package/dist/{types/common/endowments/timeout.d.ts → common/endowments/timeout.d.cts} +1 -0
  101. package/dist/common/endowments/timeout.d.cts.map +1 -0
  102. package/dist/common/endowments/timeout.d.mts +10 -0
  103. package/dist/common/endowments/timeout.d.mts.map +1 -0
  104. package/dist/common/endowments/timeout.mjs +49 -6
  105. package/dist/common/endowments/timeout.mjs.map +1 -1
  106. package/dist/common/globalEvents.cjs +48 -0
  107. package/dist/common/globalEvents.cjs.map +1 -0
  108. package/dist/{types/common/globalEvents.d.ts → common/globalEvents.d.cts} +1 -0
  109. package/dist/common/globalEvents.d.cts.map +1 -0
  110. package/dist/common/globalEvents.d.mts +21 -0
  111. package/dist/common/globalEvents.d.mts.map +1 -0
  112. package/dist/common/globalEvents.mjs +42 -10
  113. package/dist/common/globalEvents.mjs.map +1 -1
  114. package/dist/common/globalObject.cjs +50 -0
  115. package/dist/common/globalObject.cjs.map +1 -0
  116. package/dist/{types/common/globalObject.d.ts → common/globalObject.d.cts} +1 -0
  117. package/dist/common/globalObject.d.cts.map +1 -0
  118. package/dist/common/globalObject.d.mts +10 -0
  119. package/dist/common/globalObject.d.mts.map +1 -0
  120. package/dist/common/globalObject.mjs +45 -9
  121. package/dist/common/globalObject.mjs.map +1 -1
  122. package/dist/common/lockdown/lockdown-events.cjs +60 -0
  123. package/dist/common/lockdown/lockdown-events.cjs.map +1 -0
  124. package/dist/{types/common/lockdown/lockdown-events.d.ts → common/lockdown/lockdown-events.d.cts} +1 -0
  125. package/dist/common/lockdown/lockdown-events.d.cts.map +1 -0
  126. package/dist/common/lockdown/lockdown-events.d.mts +5 -0
  127. package/dist/common/lockdown/lockdown-events.d.mts.map +1 -0
  128. package/dist/common/lockdown/lockdown-events.mjs +55 -7
  129. package/dist/common/lockdown/lockdown-events.mjs.map +1 -1
  130. package/dist/common/lockdown/lockdown-more.cjs +89 -0
  131. package/dist/common/lockdown/lockdown-more.cjs.map +1 -0
  132. package/dist/{types/common/lockdown/lockdown-more.d.ts → common/lockdown/lockdown-more.d.cts} +1 -0
  133. package/dist/common/lockdown/lockdown-more.d.cts.map +1 -0
  134. package/dist/common/lockdown/lockdown-more.d.mts +23 -0
  135. package/dist/common/lockdown/lockdown-more.d.mts.map +1 -0
  136. package/dist/common/lockdown/lockdown-more.mjs +84 -7
  137. package/dist/common/lockdown/lockdown-more.mjs.map +1 -1
  138. package/dist/common/lockdown/lockdown.cjs +29 -0
  139. package/dist/common/lockdown/lockdown.cjs.map +1 -0
  140. package/dist/{types/common/lockdown/lockdown.d.ts → common/lockdown/lockdown.d.cts} +1 -0
  141. package/dist/common/lockdown/lockdown.d.cts.map +1 -0
  142. package/dist/common/lockdown/lockdown.d.mts +8 -0
  143. package/dist/common/lockdown/lockdown.d.mts.map +1 -0
  144. package/dist/common/lockdown/lockdown.mjs +22 -19
  145. package/dist/common/lockdown/lockdown.mjs.map +1 -1
  146. package/dist/common/sortParams.cjs +35 -0
  147. package/dist/common/sortParams.cjs.map +1 -0
  148. package/dist/{types/common/sortParams.d.ts → common/sortParams.d.cts} +2 -1
  149. package/dist/common/sortParams.d.cts.map +1 -0
  150. package/dist/common/sortParams.d.mts +17 -0
  151. package/dist/common/sortParams.d.mts.map +1 -0
  152. package/dist/common/sortParams.mjs +29 -6
  153. package/dist/common/sortParams.mjs.map +1 -1
  154. package/dist/common/utils.cjs +156 -0
  155. package/dist/common/utils.cjs.map +1 -0
  156. package/dist/{types/common/utils.d.ts → common/utils.d.cts} +2 -1
  157. package/dist/common/utils.d.cts.map +1 -0
  158. package/dist/common/utils.d.mts +50 -0
  159. package/dist/common/utils.d.mts.map +1 -0
  160. package/dist/common/utils.mjs +146 -20
  161. package/dist/common/utils.mjs.map +1 -1
  162. package/dist/common/validation.cjs +137 -0
  163. package/dist/common/validation.cjs.map +1 -0
  164. package/dist/{types/common/validation.d.ts → common/validation.d.cts} +37 -36
  165. package/dist/common/validation.d.cts.map +1 -0
  166. package/dist/common/validation.d.mts +199 -0
  167. package/dist/common/validation.d.mts.map +1 -0
  168. package/dist/common/validation.mjs +127 -37
  169. package/dist/common/validation.mjs.map +1 -1
  170. package/dist/iframe/IFrameSnapExecutor.cjs +42 -0
  171. package/dist/iframe/IFrameSnapExecutor.cjs.map +1 -0
  172. package/dist/{types/iframe/IFrameSnapExecutor.d.ts → iframe/IFrameSnapExecutor.d.cts} +3 -2
  173. package/dist/iframe/IFrameSnapExecutor.d.cts.map +1 -0
  174. package/dist/iframe/IFrameSnapExecutor.d.mts +14 -0
  175. package/dist/iframe/IFrameSnapExecutor.d.mts.map +1 -0
  176. package/dist/iframe/IFrameSnapExecutor.mjs +42 -26
  177. package/dist/iframe/IFrameSnapExecutor.mjs.map +1 -1
  178. package/dist/iframe/index.cjs +10 -0
  179. package/dist/iframe/index.cjs.map +1 -0
  180. package/dist/iframe/index.d.cts +2 -0
  181. package/dist/iframe/index.d.cts.map +1 -0
  182. package/dist/iframe/index.d.mts +2 -0
  183. package/dist/iframe/index.d.mts.map +1 -0
  184. package/dist/iframe/index.mjs +4 -31
  185. package/dist/iframe/index.mjs.map +1 -1
  186. package/dist/index.cjs +18 -0
  187. package/dist/index.cjs.map +1 -0
  188. package/dist/index.d.cts +2 -0
  189. package/dist/index.d.cts.map +1 -0
  190. package/dist/index.d.mts +2 -0
  191. package/dist/index.d.mts.map +1 -0
  192. package/dist/index.mjs +1 -8
  193. package/dist/index.mjs.map +1 -1
  194. package/dist/logging.cjs +13 -0
  195. package/dist/logging.cjs.map +1 -0
  196. package/dist/{types/logging.d.ts → logging.d.cts} +1 -0
  197. package/dist/logging.d.cts.map +1 -0
  198. package/dist/logging.d.mts +9 -0
  199. package/dist/logging.d.mts.map +1 -0
  200. package/dist/logging.mjs +9 -7
  201. package/dist/logging.mjs.map +1 -1
  202. package/dist/node-process/ChildProcessSnapExecutor.cjs +30 -0
  203. package/dist/node-process/ChildProcessSnapExecutor.cjs.map +1 -0
  204. package/dist/{types/node-process/ChildProcessSnapExecutor.d.ts → node-process/ChildProcessSnapExecutor.d.cts} +2 -1
  205. package/dist/node-process/ChildProcessSnapExecutor.d.cts.map +1 -0
  206. package/dist/node-process/ChildProcessSnapExecutor.d.mts +5 -0
  207. package/dist/node-process/ChildProcessSnapExecutor.d.mts.map +1 -0
  208. package/dist/node-process/ChildProcessSnapExecutor.mjs +30 -26
  209. package/dist/node-process/ChildProcessSnapExecutor.mjs.map +1 -1
  210. package/dist/node-process/index.cjs +8 -0
  211. package/dist/node-process/index.cjs.map +1 -0
  212. package/dist/node-process/index.d.cts +2 -0
  213. package/dist/node-process/index.d.cts.map +1 -0
  214. package/dist/node-process/index.d.mts +2 -0
  215. package/dist/node-process/index.d.mts.map +1 -0
  216. package/dist/node-process/index.mjs +3 -28
  217. package/dist/node-process/index.mjs.map +1 -1
  218. package/dist/node-thread/ThreadSnapExecutor.cjs +30 -0
  219. package/dist/node-thread/ThreadSnapExecutor.cjs.map +1 -0
  220. package/dist/node-thread/ThreadSnapExecutor.d.cts +5 -0
  221. package/dist/node-thread/ThreadSnapExecutor.d.cts.map +1 -0
  222. package/dist/node-thread/ThreadSnapExecutor.d.mts +5 -0
  223. package/dist/node-thread/ThreadSnapExecutor.d.mts.map +1 -0
  224. package/dist/node-thread/ThreadSnapExecutor.mjs +30 -26
  225. package/dist/node-thread/ThreadSnapExecutor.mjs.map +1 -1
  226. package/dist/node-thread/index.cjs +8 -0
  227. package/dist/node-thread/index.cjs.map +1 -0
  228. package/dist/node-thread/index.d.cts +2 -0
  229. package/dist/node-thread/index.d.cts.map +1 -0
  230. package/dist/node-thread/index.d.mts +2 -0
  231. package/dist/node-thread/index.d.mts.map +1 -0
  232. package/dist/node-thread/index.mjs +3 -28
  233. package/dist/node-thread/index.mjs.map +1 -1
  234. package/dist/proxy/ProxySnapExecutor.cjs +112 -0
  235. package/dist/proxy/ProxySnapExecutor.cjs.map +1 -0
  236. package/dist/{types/proxy/ProxySnapExecutor.d.ts → proxy/ProxySnapExecutor.d.cts} +4 -3
  237. package/dist/proxy/ProxySnapExecutor.d.cts.map +1 -0
  238. package/dist/proxy/ProxySnapExecutor.d.mts +36 -0
  239. package/dist/proxy/ProxySnapExecutor.d.mts.map +1 -0
  240. package/dist/proxy/ProxySnapExecutor.mjs +104 -6
  241. package/dist/proxy/ProxySnapExecutor.mjs.map +1 -1
  242. package/dist/proxy/index.cjs +18 -0
  243. package/dist/proxy/index.cjs.map +1 -0
  244. package/dist/proxy/index.d.cts +2 -0
  245. package/dist/proxy/index.d.cts.map +1 -0
  246. package/dist/proxy/index.d.mts +2 -0
  247. package/dist/proxy/index.d.mts.map +1 -0
  248. package/dist/proxy/index.mjs +1 -8
  249. package/dist/proxy/index.mjs.map +1 -1
  250. package/dist/webview/WebViewExecutorStream.cjs +79 -0
  251. package/dist/webview/WebViewExecutorStream.cjs.map +1 -0
  252. package/dist/{types/webview/WebViewExecutorStream.d.ts → webview/WebViewExecutorStream.d.cts} +3 -2
  253. package/dist/webview/WebViewExecutorStream.d.cts.map +1 -0
  254. package/dist/webview/WebViewExecutorStream.d.mts +33 -0
  255. package/dist/webview/WebViewExecutorStream.d.mts.map +1 -0
  256. package/dist/webview/WebViewExecutorStream.mjs +74 -6
  257. package/dist/webview/WebViewExecutorStream.mjs.map +1 -1
  258. package/dist/webview/index.cjs +16 -0
  259. package/dist/webview/index.cjs.map +1 -0
  260. package/dist/webview/index.d.cts +2 -0
  261. package/dist/webview/index.d.cts.map +1 -0
  262. package/dist/webview/index.d.mts +2 -0
  263. package/dist/webview/index.d.mts.map +1 -0
  264. package/dist/webview/index.mjs +9 -21
  265. package/dist/webview/index.mjs.map +1 -1
  266. package/dist/webworker/executor/WebWorkerSnapExecutor.cjs +37 -0
  267. package/dist/webworker/executor/WebWorkerSnapExecutor.cjs.map +1 -0
  268. package/dist/{types/webworker/executor/WebWorkerSnapExecutor.d.ts → webworker/executor/WebWorkerSnapExecutor.d.cts} +3 -2
  269. package/dist/webworker/executor/WebWorkerSnapExecutor.d.cts.map +1 -0
  270. package/dist/webworker/executor/WebWorkerSnapExecutor.d.mts +14 -0
  271. package/dist/webworker/executor/WebWorkerSnapExecutor.d.mts.map +1 -0
  272. package/dist/webworker/executor/WebWorkerSnapExecutor.mjs +37 -26
  273. package/dist/webworker/executor/WebWorkerSnapExecutor.mjs.map +1 -1
  274. package/dist/webworker/executor/index.cjs +10 -0
  275. package/dist/webworker/executor/index.cjs.map +1 -0
  276. package/dist/webworker/executor/index.d.cts +2 -0
  277. package/dist/webworker/executor/index.d.cts.map +1 -0
  278. package/dist/webworker/executor/index.d.mts +2 -0
  279. package/dist/webworker/executor/index.d.mts.map +1 -0
  280. package/dist/webworker/executor/index.mjs +4 -31
  281. package/dist/webworker/executor/index.mjs.map +1 -1
  282. package/dist/webworker/pool/WebWorkerPool.cjs +168 -0
  283. package/dist/webworker/pool/WebWorkerPool.cjs.map +1 -0
  284. package/dist/{types/webworker/pool/WebWorkerPool.d.ts → webworker/pool/WebWorkerPool.d.cts} +4 -3
  285. package/dist/webworker/pool/WebWorkerPool.d.cts.map +1 -0
  286. package/dist/webworker/pool/WebWorkerPool.d.mts +24 -0
  287. package/dist/webworker/pool/WebWorkerPool.d.mts.map +1 -0
  288. package/dist/webworker/pool/WebWorkerPool.mjs +163 -6
  289. package/dist/webworker/pool/WebWorkerPool.mjs.map +1 -1
  290. package/dist/webworker/pool/index.cjs +10 -0
  291. package/dist/webworker/pool/index.cjs.map +1 -0
  292. package/dist/webworker/pool/index.d.cts +2 -0
  293. package/dist/webworker/pool/index.d.cts.map +1 -0
  294. package/dist/webworker/pool/index.d.mts +2 -0
  295. package/dist/webworker/pool/index.d.mts.map +1 -0
  296. package/dist/webworker/pool/index.mjs +4 -12
  297. package/dist/webworker/pool/index.mjs.map +1 -1
  298. package/package.json +23 -20
  299. package/dist/browserify/iframe/bundle.js +0 -9
  300. package/dist/browserify/iframe/index.html +0 -13394
  301. package/dist/browserify/node-process/bundle.js +0 -13390
  302. package/dist/browserify/node-thread/bundle.js +0 -13390
  303. package/dist/browserify/webview/index.html +0 -13402
  304. package/dist/browserify/worker-executor/bundle.js +0 -13392
  305. package/dist/browserify/worker-pool/bundle.js +0 -9
  306. package/dist/browserify/worker-pool/index.html +0 -13394
  307. package/dist/chunk-2VA6RAEE.js +0 -30
  308. package/dist/chunk-2VA6RAEE.js.map +0 -1
  309. package/dist/chunk-3JCT4MWT.js +0 -108
  310. package/dist/chunk-3JCT4MWT.js.map +0 -1
  311. package/dist/chunk-46LW37FK.js +0 -144
  312. package/dist/chunk-46LW37FK.js.map +0 -1
  313. package/dist/chunk-4COIRXF5.js +0 -86
  314. package/dist/chunk-4COIRXF5.js.map +0 -1
  315. package/dist/chunk-4XRZLEKU.js +0 -49
  316. package/dist/chunk-4XRZLEKU.js.map +0 -1
  317. package/dist/chunk-53ZULHPK.mjs +0 -16
  318. package/dist/chunk-53ZULHPK.mjs.map +0 -1
  319. package/dist/chunk-5DEV3QQU.mjs +0 -12
  320. package/dist/chunk-5DEV3QQU.mjs.map +0 -1
  321. package/dist/chunk-5STN3QCA.js +0 -183
  322. package/dist/chunk-5STN3QCA.js.map +0 -1
  323. package/dist/chunk-72KFTWQZ.mjs +0 -45
  324. package/dist/chunk-72KFTWQZ.mjs.map +0 -1
  325. package/dist/chunk-75RCH4ZX.mjs +0 -151
  326. package/dist/chunk-75RCH4ZX.mjs.map +0 -1
  327. package/dist/chunk-7AJWXSDQ.mjs +0 -73
  328. package/dist/chunk-7AJWXSDQ.mjs.map +0 -1
  329. package/dist/chunk-7MMUJJQ2.js +0 -151
  330. package/dist/chunk-7MMUJJQ2.js.map +0 -1
  331. package/dist/chunk-BCBKEUCG.mjs +0 -38
  332. package/dist/chunk-BCBKEUCG.mjs.map +0 -1
  333. package/dist/chunk-BEJDC4XI.mjs +0 -40
  334. package/dist/chunk-BEJDC4XI.mjs.map +0 -1
  335. package/dist/chunk-BLHIYDO5.js +0 -40
  336. package/dist/chunk-BLHIYDO5.js.map +0 -1
  337. package/dist/chunk-BTEAZZKP.mjs +0 -24
  338. package/dist/chunk-BTEAZZKP.mjs.map +0 -1
  339. package/dist/chunk-BVRVUIJB.mjs +0 -67
  340. package/dist/chunk-BVRVUIJB.mjs.map +0 -1
  341. package/dist/chunk-CV5LC4PP.js +0 -24
  342. package/dist/chunk-CV5LC4PP.js.map +0 -1
  343. package/dist/chunk-DKDTGAFK.js +0 -67
  344. package/dist/chunk-DKDTGAFK.js.map +0 -1
  345. package/dist/chunk-DLLLH5HN.js +0 -26
  346. package/dist/chunk-DLLLH5HN.js.map +0 -1
  347. package/dist/chunk-EXN2TFDJ.js +0 -38
  348. package/dist/chunk-EXN2TFDJ.js.map +0 -1
  349. package/dist/chunk-FOEAIF5U.js +0 -16
  350. package/dist/chunk-FOEAIF5U.js.map +0 -1
  351. package/dist/chunk-FUPEJT7B.js +0 -82
  352. package/dist/chunk-FUPEJT7B.js.map +0 -1
  353. package/dist/chunk-HCXTK3PR.js +0 -472
  354. package/dist/chunk-HCXTK3PR.js.map +0 -1
  355. package/dist/chunk-HGLRZZ56.js +0 -32
  356. package/dist/chunk-HGLRZZ56.js.map +0 -1
  357. package/dist/chunk-HL2TTKF3.mjs +0 -144
  358. package/dist/chunk-HL2TTKF3.mjs.map +0 -1
  359. package/dist/chunk-HWS4QSOC.mjs +0 -16
  360. package/dist/chunk-HWS4QSOC.mjs.map +0 -1
  361. package/dist/chunk-HXKBUIYS.js +0 -262
  362. package/dist/chunk-HXKBUIYS.js.map +0 -1
  363. package/dist/chunk-HXUJHX3E.mjs +0 -33
  364. package/dist/chunk-HXUJHX3E.mjs.map +0 -1
  365. package/dist/chunk-I5G4YFHM.js +0 -73
  366. package/dist/chunk-I5G4YFHM.js.map +0 -1
  367. package/dist/chunk-IX5S3V47.mjs +0 -26
  368. package/dist/chunk-IX5S3V47.mjs.map +0 -1
  369. package/dist/chunk-JDWYJ5UI.mjs +0 -33
  370. package/dist/chunk-JDWYJ5UI.mjs.map +0 -1
  371. package/dist/chunk-JOT5JH42.js +0 -52
  372. package/dist/chunk-JOT5JH42.js.map +0 -1
  373. package/dist/chunk-KEAB7ZVV.js +0 -50
  374. package/dist/chunk-KEAB7ZVV.js.map +0 -1
  375. package/dist/chunk-LO5ORVRC.js +0 -16
  376. package/dist/chunk-LO5ORVRC.js.map +0 -1
  377. package/dist/chunk-M3OBSGHF.mjs +0 -472
  378. package/dist/chunk-M3OBSGHF.mjs.map +0 -1
  379. package/dist/chunk-MCXWFCGV.js +0 -1
  380. package/dist/chunk-MCXWFCGV.js.map +0 -1
  381. package/dist/chunk-MIWGLICQ.mjs +0 -108
  382. package/dist/chunk-MIWGLICQ.mjs.map +0 -1
  383. package/dist/chunk-MMYM63NH.mjs +0 -82
  384. package/dist/chunk-MMYM63NH.mjs.map +0 -1
  385. package/dist/chunk-MS2LQQYH.js +0 -38
  386. package/dist/chunk-MS2LQQYH.js.map +0 -1
  387. package/dist/chunk-MXNMMTJW.mjs +0 -51
  388. package/dist/chunk-MXNMMTJW.mjs.map +0 -1
  389. package/dist/chunk-OBT45IWW.js +0 -92
  390. package/dist/chunk-OBT45IWW.js.map +0 -1
  391. package/dist/chunk-OCNPLHS2.js +0 -51
  392. package/dist/chunk-OCNPLHS2.js.map +0 -1
  393. package/dist/chunk-ODICKSGZ.mjs +0 -86
  394. package/dist/chunk-ODICKSGZ.mjs.map +0 -1
  395. package/dist/chunk-Q42NNJFY.mjs +0 -32
  396. package/dist/chunk-Q42NNJFY.mjs.map +0 -1
  397. package/dist/chunk-QZC2X6NG.js +0 -44
  398. package/dist/chunk-QZC2X6NG.js.map +0 -1
  399. package/dist/chunk-RACRYFWM.js +0 -45
  400. package/dist/chunk-RACRYFWM.js.map +0 -1
  401. package/dist/chunk-RD2APLK5.js +0 -33
  402. package/dist/chunk-RD2APLK5.js.map +0 -1
  403. package/dist/chunk-S5NWI5Z7.mjs +0 -50
  404. package/dist/chunk-S5NWI5Z7.mjs.map +0 -1
  405. package/dist/chunk-S7257EN3.mjs +0 -49
  406. package/dist/chunk-S7257EN3.mjs.map +0 -1
  407. package/dist/chunk-TSEAPB7L.mjs +0 -1
  408. package/dist/chunk-TSEAPB7L.mjs.map +0 -1
  409. package/dist/chunk-UOPIRTJX.mjs +0 -44
  410. package/dist/chunk-UOPIRTJX.mjs.map +0 -1
  411. package/dist/chunk-V76DI2XM.mjs +0 -183
  412. package/dist/chunk-V76DI2XM.mjs.map +0 -1
  413. package/dist/chunk-W7EDURT5.mjs +0 -92
  414. package/dist/chunk-W7EDURT5.mjs.map +0 -1
  415. package/dist/chunk-XPCW7TKM.mjs +0 -262
  416. package/dist/chunk-XPCW7TKM.mjs.map +0 -1
  417. package/dist/chunk-Y7AK2VVC.mjs +0 -52
  418. package/dist/chunk-Y7AK2VVC.mjs.map +0 -1
  419. package/dist/chunk-YRZVIDCF.mjs +0 -38
  420. package/dist/chunk-YRZVIDCF.mjs.map +0 -1
  421. package/dist/chunk-Z7BOREC4.js +0 -12
  422. package/dist/chunk-Z7BOREC4.js.map +0 -1
  423. package/dist/chunk-ZAYDLP42.js +0 -33
  424. package/dist/chunk-ZAYDLP42.js.map +0 -1
  425. package/dist/chunk-ZNTCZK7J.mjs +0 -30
  426. package/dist/chunk-ZNTCZK7J.mjs.map +0 -1
  427. package/dist/common/BaseSnapExecutor.js +0 -26
  428. package/dist/common/BaseSnapExecutor.js.map +0 -1
  429. package/dist/common/commands.js +0 -11
  430. package/dist/common/commands.js.map +0 -1
  431. package/dist/common/endowments/commonEndowmentFactory.js +0 -20
  432. package/dist/common/endowments/commonEndowmentFactory.js.map +0 -1
  433. package/dist/common/endowments/console.js +0 -13
  434. package/dist/common/endowments/console.js.map +0 -1
  435. package/dist/common/endowments/crypto.js +0 -11
  436. package/dist/common/endowments/crypto.js.map +0 -1
  437. package/dist/common/endowments/date.js +0 -9
  438. package/dist/common/endowments/date.js.map +0 -1
  439. package/dist/common/endowments/index.js +0 -21
  440. package/dist/common/endowments/index.js.map +0 -1
  441. package/dist/common/endowments/interval.js +0 -8
  442. package/dist/common/endowments/interval.js.map +0 -1
  443. package/dist/common/endowments/math.js +0 -10
  444. package/dist/common/endowments/math.js.map +0 -1
  445. package/dist/common/endowments/network.js +0 -10
  446. package/dist/common/endowments/network.js.map +0 -1
  447. package/dist/common/endowments/textDecoder.js +0 -8
  448. package/dist/common/endowments/textDecoder.js.map +0 -1
  449. package/dist/common/endowments/textEncoder.js +0 -8
  450. package/dist/common/endowments/textEncoder.js.map +0 -1
  451. package/dist/common/endowments/timeout.js +0 -8
  452. package/dist/common/endowments/timeout.js.map +0 -1
  453. package/dist/common/globalEvents.js +0 -11
  454. package/dist/common/globalEvents.js.map +0 -1
  455. package/dist/common/globalObject.js +0 -10
  456. package/dist/common/globalObject.js.map +0 -1
  457. package/dist/common/lockdown/lockdown-events.js +0 -8
  458. package/dist/common/lockdown/lockdown-events.js.map +0 -1
  459. package/dist/common/lockdown/lockdown-more.js +0 -8
  460. package/dist/common/lockdown/lockdown-more.js.map +0 -1
  461. package/dist/common/lockdown/lockdown.js +0 -22
  462. package/dist/common/lockdown/lockdown.js.map +0 -1
  463. package/dist/common/sortParams.js +0 -8
  464. package/dist/common/sortParams.js.map +0 -1
  465. package/dist/common/utils.js +0 -21
  466. package/dist/common/utils.js.map +0 -1
  467. package/dist/common/validation.js +0 -38
  468. package/dist/common/validation.js.map +0 -1
  469. package/dist/globals.d.js +0 -1
  470. package/dist/globals.d.js.map +0 -1
  471. package/dist/globals.d.mjs +0 -1
  472. package/dist/globals.d.mjs.map +0 -1
  473. package/dist/iframe/IFrameSnapExecutor.js +0 -27
  474. package/dist/iframe/IFrameSnapExecutor.js.map +0 -1
  475. package/dist/iframe/index.js +0 -35
  476. package/dist/iframe/index.js.map +0 -1
  477. package/dist/index.js +0 -9
  478. package/dist/index.js.map +0 -1
  479. package/dist/logging.js +0 -8
  480. package/dist/logging.js.map +0 -1
  481. package/dist/node-process/ChildProcessSnapExecutor.js +0 -27
  482. package/dist/node-process/ChildProcessSnapExecutor.js.map +0 -1
  483. package/dist/node-process/index.js +0 -31
  484. package/dist/node-process/index.js.map +0 -1
  485. package/dist/node-thread/ThreadSnapExecutor.js +0 -27
  486. package/dist/node-thread/ThreadSnapExecutor.js.map +0 -1
  487. package/dist/node-thread/index.js +0 -31
  488. package/dist/node-thread/index.js.map +0 -1
  489. package/dist/proxy/ProxySnapExecutor.js +0 -8
  490. package/dist/proxy/ProxySnapExecutor.js.map +0 -1
  491. package/dist/proxy/index.js +0 -9
  492. package/dist/proxy/index.js.map +0 -1
  493. package/dist/tsconfig.build.tsbuildinfo +0 -1
  494. package/dist/types/iframe/index.d.ts +0 -1
  495. package/dist/types/index.d.ts +0 -1
  496. package/dist/types/node-process/index.d.ts +0 -1
  497. package/dist/types/node-thread/ThreadSnapExecutor.d.ts +0 -4
  498. package/dist/types/node-thread/index.d.ts +0 -1
  499. package/dist/types/proxy/index.d.ts +0 -1
  500. package/dist/types/vendor/global.d.js +0 -1
  501. package/dist/types/vendor/global.d.js.map +0 -1
  502. package/dist/types/vendor/global.d.mjs +0 -1
  503. package/dist/types/vendor/global.d.mjs.map +0 -1
  504. package/dist/types/vendor/providers.d.js +0 -1
  505. package/dist/types/vendor/providers.d.js.map +0 -1
  506. package/dist/types/vendor/providers.d.mjs +0 -1
  507. package/dist/types/vendor/providers.d.mjs.map +0 -1
  508. package/dist/types/vendor/readable-stream.d.js +0 -1
  509. package/dist/types/vendor/readable-stream.d.js.map +0 -1
  510. package/dist/types/vendor/readable-stream.d.mjs +0 -1
  511. package/dist/types/vendor/readable-stream.d.mjs.map +0 -1
  512. package/dist/types/webview/index.d.ts +0 -1
  513. package/dist/types/webworker/executor/index.d.ts +0 -1
  514. package/dist/types/webworker/pool/index.d.ts +0 -1
  515. package/dist/webview/WebViewExecutorStream.js +0 -8
  516. package/dist/webview/WebViewExecutorStream.js.map +0 -1
  517. package/dist/webview/index.js +0 -26
  518. package/dist/webview/index.js.map +0 -1
  519. package/dist/webworker/executor/WebWorkerSnapExecutor.js +0 -27
  520. package/dist/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
  521. package/dist/webworker/executor/index.js +0 -35
  522. package/dist/webworker/executor/index.js.map +0 -1
  523. package/dist/webworker/pool/WebWorkerPool.js +0 -8
  524. package/dist/webworker/pool/WebWorkerPool.js.map +0 -1
  525. package/dist/webworker/pool/index.js +0 -16
  526. package/dist/webworker/pool/index.js.map +0 -1
@@ -1,21 +1,86 @@
1
- import {
2
- createEndowments
3
- } from "../../chunk-BVRVUIJB.mjs";
4
- import "../../chunk-ODICKSGZ.mjs";
5
- import "../../chunk-S5NWI5Z7.mjs";
6
- import "../../chunk-BCBKEUCG.mjs";
7
- import "../../chunk-XPCW7TKM.mjs";
8
- import "../../chunk-53ZULHPK.mjs";
9
- import "../../chunk-HWS4QSOC.mjs";
10
- import "../../chunk-Y7AK2VVC.mjs";
11
- import "../../chunk-W7EDURT5.mjs";
12
- import "../../chunk-Q42NNJFY.mjs";
13
- import "../../chunk-UOPIRTJX.mjs";
14
- import "../../chunk-HL2TTKF3.mjs";
15
- import "../../chunk-5DEV3QQU.mjs";
16
- import "../../chunk-IX5S3V47.mjs";
17
- import "../../chunk-YRZVIDCF.mjs";
18
- export {
19
- createEndowments
20
- };
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.mjs";
5
+ import buildCommonEndowments from "./commonEndowmentFactory.mjs";
6
+ /**
7
+ * Retrieve consolidated endowment factories for common endowments.
8
+ */
9
+ const registeredEndowments = buildCommonEndowments();
10
+ /**
11
+ * A map of endowment names to their factory functions. Some endowments share
12
+ * the same factory function, but we only call each factory once for each snap.
13
+ * See {@link createEndowments} for details.
14
+ */
15
+ const endowmentFactories = registeredEndowments.reduce((factories, builder) => {
16
+ builder.names.forEach((name) => {
17
+ factories.set(name, builder.factory);
18
+ });
19
+ return factories;
20
+ }, new Map());
21
+ /**
22
+ * Gets the endowments for a particular Snap. Some endowments, like `setTimeout`
23
+ * and `clearTimeout`, must be attenuated so that they can only affect behavior
24
+ * within the Snap's own realm. Therefore, we use factory functions to create
25
+ * such attenuated / modified endowments. Otherwise, the value that's on the
26
+ * root realm global will be used.
27
+ *
28
+ * @param options - An options bag.
29
+ * @param options.snap - The Snaps global API object.
30
+ * @param options.ethereum - The Snap's EIP-1193 provider object.
31
+ * @param options.snapId - The id of the snap that will use the created endowments.
32
+ * @param options.endowments - The list of endowments to provide to the snap.
33
+ * @param options.notify - A reference to the notify function of the snap executor.
34
+ * @returns An object containing the Snap's endowments.
35
+ */
36
+ export function createEndowments({ snap, ethereum, snapId, endowments, notify, }) {
37
+ const attenuatedEndowments = {};
38
+ // TODO: All endowments should be hardened to prevent covert communication
39
+ // channels. Hardening the returned objects breaks tests elsewhere in the
40
+ // monorepo, so further research is needed.
41
+ const result = endowments.reduce(({ allEndowments, teardowns }, endowmentName) => {
42
+ // First, check if the endowment has a factory, and default to that.
43
+ if (endowmentFactories.has(endowmentName)) {
44
+ if (!hasProperty(attenuatedEndowments, endowmentName)) {
45
+ // Call the endowment factory for the current endowment. If the factory
46
+ // creates multiple endowments, they will all be assigned to the
47
+ // `attenuatedEndowments` object, but will only be passed on to the snap
48
+ // if explicitly listed among its endowment.
49
+ // This may not have an actual use case, but, safety first.
50
+ // We just confirmed that endowmentFactories has the specified key.
51
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
52
+ const { teardownFunction, ...endowment } = endowmentFactories.get(endowmentName)({ snapId, notify });
53
+ Object.assign(attenuatedEndowments, endowment);
54
+ if (teardownFunction) {
55
+ teardowns.push(teardownFunction);
56
+ }
57
+ }
58
+ allEndowments[endowmentName] = attenuatedEndowments[endowmentName];
59
+ }
60
+ else if (endowmentName === 'ethereum') {
61
+ // Special case for adding the EIP-1193 provider.
62
+ allEndowments[endowmentName] = ethereum;
63
+ }
64
+ else if (endowmentName in rootRealmGlobal) {
65
+ logWarning(`Access to unhardened global ${endowmentName}.`);
66
+ // If the endowment doesn't have a factory, just use whatever is on the
67
+ // global object.
68
+ const globalValue = rootRealmGlobal[endowmentName];
69
+ allEndowments[endowmentName] = globalValue;
70
+ }
71
+ else {
72
+ // If we get to this point, we've been passed an endowment that doesn't
73
+ // exist in our current environment.
74
+ throw rpcErrors.internal(`Unknown endowment: "${endowmentName}".`);
75
+ }
76
+ return { allEndowments, teardowns };
77
+ }, {
78
+ allEndowments: { snap },
79
+ teardowns: [],
80
+ });
81
+ const teardown = async () => {
82
+ await Promise.all(result.teardowns.map((teardownFunction) => teardownFunction()));
83
+ };
84
+ return { endowments: result.allEndowments, teardown };
85
+ }
21
86
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/common/endowments/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,UAAU,EAAE,8BAA8B;AACnD,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAG9C,OAAO,EAAE,eAAe,EAAE,4BAAwB;AAElD,OAAO,qBAAqB,qCAAiC;AAe7D;;GAEG;AACH,MAAM,oBAAoB,GAAG,qBAAqB,EAAE,CAAC;AAErD;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;IAC5E,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC7B,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC,EAAE,IAAI,GAAG,EAAyE,CAAC,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,GAOP;IACC,MAAM,oBAAoB,GAA4B,EAAE,CAAC;IAEzD,0EAA0E;IAC1E,yEAAyE;IACzE,2CAA2C;IAC3C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAI9B,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,aAAa,EAAE,EAAE;QAC9C,oEAAoE;QACpE,IAAI,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,aAAa,CAAC,EAAE,CAAC;gBACtD,uEAAuE;gBACvE,gEAAgE;gBAChE,wEAAwE;gBACxE,4CAA4C;gBAC5C,2DAA2D;gBAE3D,mEAAmE;gBACnE,oEAAoE;gBACpE,MAAM,EAAE,gBAAgB,EAAE,GAAG,SAAS,EAAE,GAAG,kBAAkB,CAAC,GAAG,CAC/D,aAAa,CACb,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;gBACvB,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;gBAC/C,IAAI,gBAAgB,EAAE,CAAC;oBACrB,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;YACD,aAAa,CAAC,aAAa,CAAC,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC;QACrE,CAAC;aAAM,IAAI,aAAa,KAAK,UAAU,EAAE,CAAC;YACxC,iDAAiD;YACjD,aAAa,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;QAC1C,CAAC;aAAM,IAAI,aAAa,IAAI,eAAe,EAAE,CAAC;YAC5C,UAAU,CAAC,+BAA+B,aAAa,GAAG,CAAC,CAAC;YAC5D,uEAAuE;YACvE,iBAAiB;YACjB,MAAM,WAAW,GAAI,eAA2C,CAC9D,aAAa,CACd,CAAC;YACF,aAAa,CAAC,aAAa,CAAC,GAAG,WAAW,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,uEAAuE;YACvE,oCAAoC;YACpC,MAAM,SAAS,CAAC,QAAQ,CAAC,uBAAuB,aAAa,IAAI,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC,EACD;QACE,aAAa,EAAE,EAAE,IAAI,EAAE;QACvB,SAAS,EAAE,EAAE;KACd,CACF,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC,CAC/D,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,QAAQ,EAAE,CAAC;AACxD,CAAC","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"]}
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const rpc_errors_1 = require("@metamask/rpc-errors");
4
+ const MINIMUM_INTERVAL = 10;
5
+ /**
6
+ * Creates a pair of `setInterval` and `clearInterval` functions attenuated such
7
+ * that:
8
+ * - `setInterval` throws if its "handler" parameter is not a function.
9
+ * - `clearInterval` only clears timeouts created by its sibling `setInterval`,
10
+ * or else no-ops.
11
+ *
12
+ * @returns An object with the attenuated `setInterval` and `clearInterval`
13
+ * functions.
14
+ */
15
+ const createInterval = () => {
16
+ const registeredHandles = new Map();
17
+ const _setInterval = (handler, timeout, ...args) => {
18
+ if (typeof handler !== 'function') {
19
+ throw rpc_errors_1.rpcErrors.invalidInput(`The interval handler must be a function. Received: ${typeof handler}.`);
20
+ }
21
+ harden(handler);
22
+ const handle = Object.freeze(Object.create(null));
23
+ const platformHandle = setInterval(handler, Math.max(MINIMUM_INTERVAL, timeout ?? 0), ...args);
24
+ registeredHandles.set(handle, platformHandle);
25
+ return handle;
26
+ };
27
+ const _clearInterval = (handle) => {
28
+ harden(handle);
29
+ const platformHandle = registeredHandles.get(handle);
30
+ if (platformHandle !== undefined) {
31
+ clearInterval(platformHandle);
32
+ registeredHandles.delete(handle);
33
+ }
34
+ };
35
+ const teardownFunction = () => {
36
+ for (const handle of registeredHandles.keys()) {
37
+ _clearInterval(handle);
38
+ }
39
+ };
40
+ return {
41
+ setInterval: harden(_setInterval),
42
+ clearInterval: harden(_clearInterval),
43
+ teardownFunction,
44
+ };
45
+ };
46
+ const endowmentModule = {
47
+ names: ['setInterval', 'clearInterval'],
48
+ factory: createInterval,
49
+ };
50
+ exports.default = endowmentModule;
51
+ //# sourceMappingURL=interval.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.cjs","sourceRoot":"","sources":["../../../src/common/endowments/interval.ts"],"names":[],"mappings":";;AAAA,qDAAiD;AAEjD,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;;;;;;;GASG;AACH,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEtD,MAAM,YAAY,GAAG,CACnB,OAAqB,EACrB,OAAgB,EAChB,GAAG,IAAW,EACL,EAAE;QACX,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,sBAAS,CAAC,YAAY,CAC1B,sDAAsD,OAAO,OAAO,GAAG,CACxE,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,CAAC;QAChB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAClD,MAAM,cAAc,GAAG,WAAW,CAChC,OAAO,EACP,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,OAAO,IAAI,CAAC,CAAC,EACxC,GAAG,IAAI,CACR,CAAC;QACF,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,CAAC,MAAe,EAAQ,EAAE;QAC/C,MAAM,CAAC,MAAM,CAAC,CAAC;QACf,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,aAAa,CAAC,cAAqB,CAAC,CAAC;YACrC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,GAAS,EAAE;QAClC,KAAK,MAAM,MAAM,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9C,cAAc,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC;QACjC,aAAa,EAAE,MAAM,CAAC,cAAc,CAAC;QACrC,gBAAgB;KACR,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,aAAa,EAAE,eAAe,CAAU;IAChD,OAAO,EAAE,cAAc;CACxB,CAAC;AACF,kBAAe,eAAe,CAAC","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 = (\n handler: TimerHandler,\n timeout?: number,\n ...args: any[]\n ): 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 ...args,\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"]}
@@ -7,3 +7,4 @@ declare const endowmentModule: {
7
7
  };
8
8
  };
9
9
  export default endowmentModule;
10
+ //# sourceMappingURL=interval.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.d.cts","sourceRoot":"","sources":["../../../src/common/endowments/interval.ts"],"names":[],"mappings":"AA4DA,QAAA,MAAM,eAAe;;;wCA1CR,YAAY,YACX,MAAM,WACP,GAAG,EAAE,KACb,OAAO;yCAiBsB,OAAO,KAAG,IAAI;yCASjB,IAAI;;CAgBlC,CAAC;AACF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,10 @@
1
+ declare const endowmentModule: {
2
+ names: readonly ["setInterval", "clearInterval"];
3
+ factory: () => {
4
+ readonly setInterval: (handler: TimerHandler, timeout?: number, ...args: any[]) => unknown;
5
+ readonly clearInterval: (handle: unknown) => void;
6
+ readonly teardownFunction: () => void;
7
+ };
8
+ };
9
+ export default endowmentModule;
10
+ //# sourceMappingURL=interval.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"interval.d.mts","sourceRoot":"","sources":["../../../src/common/endowments/interval.ts"],"names":[],"mappings":"AA4DA,QAAA,MAAM,eAAe;;;wCA1CR,YAAY,YACX,MAAM,WACP,GAAG,EAAE,KACb,OAAO;yCAiBsB,OAAO,KAAG,IAAI;yCASjB,IAAI;;CAgBlC,CAAC;AACF,eAAe,eAAe,CAAC"}
@@ -1,8 +1,49 @@
1
- import {
2
- interval_default
3
- } from "../../chunk-S5NWI5Z7.mjs";
4
- import "../../chunk-YRZVIDCF.mjs";
5
- export {
6
- interval_default as default
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
+ */
13
+ const createInterval = () => {
14
+ const registeredHandles = new Map();
15
+ const _setInterval = (handler, timeout, ...args) => {
16
+ if (typeof handler !== 'function') {
17
+ throw rpcErrors.invalidInput(`The interval handler must be a function. Received: ${typeof handler}.`);
18
+ }
19
+ harden(handler);
20
+ const handle = Object.freeze(Object.create(null));
21
+ const platformHandle = setInterval(handler, Math.max(MINIMUM_INTERVAL, timeout ?? 0), ...args);
22
+ registeredHandles.set(handle, platformHandle);
23
+ return handle;
24
+ };
25
+ const _clearInterval = (handle) => {
26
+ harden(handle);
27
+ const platformHandle = registeredHandles.get(handle);
28
+ if (platformHandle !== undefined) {
29
+ clearInterval(platformHandle);
30
+ registeredHandles.delete(handle);
31
+ }
32
+ };
33
+ const teardownFunction = () => {
34
+ for (const handle of registeredHandles.keys()) {
35
+ _clearInterval(handle);
36
+ }
37
+ };
38
+ return {
39
+ setInterval: harden(_setInterval),
40
+ clearInterval: harden(_clearInterval),
41
+ teardownFunction,
42
+ };
7
43
  };
44
+ const endowmentModule = {
45
+ names: ['setInterval', 'clearInterval'],
46
+ factory: createInterval,
47
+ };
48
+ export default endowmentModule;
8
49
  //# sourceMappingURL=interval.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"interval.mjs","sourceRoot":"","sources":["../../../src/common/endowments/interval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;;;;;;;GASG;AACH,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEtD,MAAM,YAAY,GAAG,CACnB,OAAqB,EACrB,OAAgB,EAChB,GAAG,IAAW,EACL,EAAE;QACX,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,SAAS,CAAC,YAAY,CAC1B,sDAAsD,OAAO,OAAO,GAAG,CACxE,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,CAAC;QAChB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAClD,MAAM,cAAc,GAAG,WAAW,CAChC,OAAO,EACP,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,OAAO,IAAI,CAAC,CAAC,EACxC,GAAG,IAAI,CACR,CAAC;QACF,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,CAAC,MAAe,EAAQ,EAAE;QAC/C,MAAM,CAAC,MAAM,CAAC,CAAC;QACf,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,aAAa,CAAC,cAAqB,CAAC,CAAC;YACrC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,GAAS,EAAE;QAClC,KAAK,MAAM,MAAM,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9C,cAAc,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC;QACjC,aAAa,EAAE,MAAM,CAAC,cAAc,CAAC;QACrC,gBAAgB;KACR,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,aAAa,EAAE,eAAe,CAAU;IAChD,OAAO,EAAE,cAAc;CACxB,CAAC;AACF,eAAe,eAAe,CAAC","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 = (\n handler: TimerHandler,\n timeout?: number,\n ...args: any[]\n ): 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 ...args,\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"]}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const globalObject_1 = require("../globalObject.cjs");
4
+ const crypto_1 = require("./crypto.cjs");
5
+ /**
6
+ * Create a {@link Math} object, with the same properties as the global
7
+ * {@link Math} object, but with the {@link Math.random} method replaced.
8
+ *
9
+ * @returns The {@link Math} object with the {@link Math.random} method
10
+ * replaced.
11
+ */
12
+ function createMath() {
13
+ // `Math` does not work with `Object.keys`, `Object.entries`, etc., so we
14
+ // need to create a new object with the same properties.
15
+ const keys = Object.getOwnPropertyNames(globalObject_1.rootRealmGlobal.Math);
16
+ const math = keys.reduce((target, key) => {
17
+ if (key === 'random') {
18
+ return target;
19
+ }
20
+ return { ...target, [key]: globalObject_1.rootRealmGlobal.Math[key] };
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 } = (0, crypto_1.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: ['Math'],
51
+ factory: createMath,
52
+ };
53
+ exports.default = endowmentModule;
54
+ //# sourceMappingURL=math.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.cjs","sourceRoot":"","sources":["../../../src/common/endowments/math.ts"],"names":[],"mappings":";;AAAA,sDAAkD;AAClD,yCAAwC;AAExC;;;;;;GAMG;AACH,SAAS,UAAU;IACjB,yEAAyE;IACzE,wDAAwD;IACxD,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,CACrC,8BAAe,CAAC,IAAI,CACI,CAAC;IAE3B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACtD,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,8BAAe,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACzD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,uJAAuJ;IACvJ,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,qBAAY,GAAE,CAAC;IAElD,OAAO,MAAM,CAAC;QACZ,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,MAAM,EAAE,GAAG,EAAE;gBACX,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,OAAO,cAAc,CAAC,eAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACzE,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,MAAM,CAAU;IACxB,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,kBAAe,eAAe,CAAC","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"]}
@@ -58,3 +58,4 @@ declare const endowmentModule: {
58
58
  factory: typeof createMath;
59
59
  };
60
60
  export default endowmentModule;
61
+ //# sourceMappingURL=math.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.d.cts","sourceRoot":"","sources":["../../../src/common/endowments/math.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,iBAAS,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0ClB;AAED,QAAA,MAAM,eAAe;;;CAGpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Create a {@link Math} object, with the same properties as the global
3
+ * {@link Math} object, but with the {@link Math.random} method replaced.
4
+ *
5
+ * @returns The {@link Math} object with the {@link Math.random} method
6
+ * replaced.
7
+ */
8
+ declare function createMath(): {
9
+ Math: {
10
+ random: () => number;
11
+ E?: number | undefined;
12
+ LN10?: number | undefined;
13
+ LN2?: number | undefined;
14
+ LOG2E?: number | undefined;
15
+ LOG10E?: number | undefined;
16
+ PI?: number | undefined;
17
+ SQRT1_2?: number | undefined;
18
+ SQRT2?: number | undefined;
19
+ abs?: ((x: number) => number) | undefined;
20
+ acos?: ((x: number) => number) | undefined;
21
+ asin?: ((x: number) => number) | undefined;
22
+ atan?: ((x: number) => number) | undefined;
23
+ atan2?: ((y: number, x: number) => number) | undefined;
24
+ ceil?: ((x: number) => number) | undefined;
25
+ cos?: ((x: number) => number) | undefined;
26
+ exp?: ((x: number) => number) | undefined;
27
+ floor?: ((x: number) => number) | undefined;
28
+ log?: ((x: number) => number) | undefined;
29
+ max?: ((...values: number[]) => number) | undefined;
30
+ min?: ((...values: number[]) => number) | undefined;
31
+ pow?: ((x: number, y: number) => number) | undefined;
32
+ round?: ((x: number) => number) | undefined;
33
+ sin?: ((x: number) => number) | undefined;
34
+ sqrt?: ((x: number) => number) | undefined;
35
+ tan?: ((x: number) => number) | undefined;
36
+ clz32?: ((x: number) => number) | undefined;
37
+ imul?: ((x: number, y: number) => number) | undefined;
38
+ sign?: ((x: number) => number) | undefined;
39
+ log10?: ((x: number) => number) | undefined;
40
+ log2?: ((x: number) => number) | undefined;
41
+ log1p?: ((x: number) => number) | undefined;
42
+ expm1?: ((x: number) => number) | undefined;
43
+ cosh?: ((x: number) => number) | undefined;
44
+ sinh?: ((x: number) => number) | undefined;
45
+ tanh?: ((x: number) => number) | undefined;
46
+ acosh?: ((x: number) => number) | undefined;
47
+ asinh?: ((x: number) => number) | undefined;
48
+ atanh?: ((x: number) => number) | undefined;
49
+ hypot?: ((...values: number[]) => number) | undefined;
50
+ trunc?: ((x: number) => number) | undefined;
51
+ fround?: ((x: number) => number) | undefined;
52
+ cbrt?: ((x: number) => number) | undefined;
53
+ [Symbol.toStringTag]?: string | undefined;
54
+ };
55
+ };
56
+ declare const endowmentModule: {
57
+ names: readonly ["Math"];
58
+ factory: typeof createMath;
59
+ };
60
+ export default endowmentModule;
61
+ //# sourceMappingURL=math.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"math.d.mts","sourceRoot":"","sources":["../../../src/common/endowments/math.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,iBAAS,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0ClB;AAED,QAAA,MAAM,eAAe;;;CAGpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
@@ -1,10 +1,52 @@
1
- import {
2
- math_default
3
- } from "../../chunk-BCBKEUCG.mjs";
4
- import "../../chunk-Q42NNJFY.mjs";
5
- import "../../chunk-IX5S3V47.mjs";
6
- import "../../chunk-YRZVIDCF.mjs";
7
- export {
8
- math_default as default
1
+ import { rootRealmGlobal } from "../globalObject.mjs";
2
+ import { createCrypto } from "./crypto.mjs";
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
+ */
10
+ function createMath() {
11
+ // `Math` does not work with `Object.keys`, `Object.entries`, etc., so we
12
+ // need to create a new object with the same properties.
13
+ const keys = Object.getOwnPropertyNames(rootRealmGlobal.Math);
14
+ const math = keys.reduce((target, key) => {
15
+ if (key === 'random') {
16
+ return target;
17
+ }
18
+ return { ...target, [key]: rootRealmGlobal.Math[key] };
19
+ }, {});
20
+ // Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto
21
+ const { crypto: hardenedCrypto } = createCrypto();
22
+ return harden({
23
+ Math: {
24
+ ...math,
25
+ random: () => {
26
+ // NOTE: This is not intended to be a secure replacement for the weak
27
+ // random number generator used by `Math.random`. It is only intended to
28
+ // prevent side channel attacks of `Math.random` by replacing it with an
29
+ // alternative implementation that is not vulnerable to the same
30
+ // attacks.
31
+ //
32
+ // This does not mean that this implementation is secure. It is not
33
+ // intended to be used in a security context, and this implementation
34
+ // may change at any time.
35
+ //
36
+ // To securely generate random numbers, use a cryptographically secure
37
+ // random number generator, such as the one provided by the Web Crypto
38
+ // API:
39
+ //
40
+ // - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
41
+ // - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
42
+ return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;
43
+ },
44
+ },
45
+ });
46
+ }
47
+ const endowmentModule = {
48
+ names: ['Math'],
49
+ factory: createMath,
9
50
  };
51
+ export default endowmentModule;
10
52
  //# sourceMappingURL=math.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"math.mjs","sourceRoot":"","sources":["../../../src/common/endowments/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,4BAAwB;AAClD,OAAO,EAAE,YAAY,EAAE,qBAAiB;AAExC;;;;;;GAMG;AACH,SAAS,UAAU;IACjB,yEAAyE;IACzE,wDAAwD;IACxD,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,CACrC,eAAe,CAAC,IAAI,CACI,CAAC;IAE3B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACtD,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACzD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,uJAAuJ;IACvJ,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,YAAY,EAAE,CAAC;IAElD,OAAO,MAAM,CAAC;QACZ,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,MAAM,EAAE,GAAG,EAAE;gBACX,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,OAAO,cAAc,CAAC,eAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACzE,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,MAAM,CAAU;IACxB,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,eAAe,eAAe,CAAC","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"]}