@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,8 +1,31 @@
1
- import {
2
- sortParamKeys
3
- } from "../chunk-BTEAZZKP.mjs";
4
- import "../chunk-YRZVIDCF.mjs";
5
- export {
6
- sortParamKeys
1
+ // original source sortParamKeys from: https://github.com/etclabscore/sig.tools/blob/master/src/postMessageServer/postMessageServer.ts#L75-L77
2
+ /**
3
+ * Deterministically sort JSON-RPC parameter keys. This makes it possible to
4
+ * support both arrays and objects as parameters. Objects are sorted and turned
5
+ * into arrays, for easier consumption by the snap.
6
+ *
7
+ * The order is defined by the `method` parameter.
8
+ *
9
+ * @param methodParams - The parameters of the JSON-RPC method, which
10
+ * determines the ordering for the parameters.
11
+ * @param params - JSON-RPC parameters as object or array.
12
+ * @returns The values for the sorted keys. If `params` is not provided, this
13
+ * returns an empty array. If `params` is an array, this returns the same
14
+ * `params`.
15
+ */
16
+ export const sortParamKeys = (methodParams, params) => {
17
+ if (!params) {
18
+ return [];
19
+ }
20
+ if (params instanceof Array) {
21
+ return params;
22
+ }
23
+ const methodParamsOrder = methodParams.reduce((paramsOrderObj, paramsName, i) => ({
24
+ ...paramsOrderObj,
25
+ [paramsName]: i,
26
+ }), {});
27
+ return Object.entries(params)
28
+ .sort(([name1, _1], [name2, _2]) => methodParamsOrder[name1] - methodParamsOrder[name2])
29
+ .map(([_, val]) => val);
7
30
  };
8
31
  //# sourceMappingURL=sortParams.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"sortParams.mjs","sourceRoot":"","sources":["../../src/common/sortParams.ts"],"names":[],"mappings":"AAAA,8IAA8I;AAI9I;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,CAC3B,YAAsB,EACtB,MAAsB,EACtB,EAAE;IACF,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,IAAI,MAAM,YAAY,KAAK,EAAE,CAAC;QAC5B,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,MAAM,iBAAiB,GAA4B,YAAY,CAAC,MAAM,CACpE,CAAC,cAAc,EAAE,UAAU,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAClC,GAAG,cAAc;QACjB,CAAC,UAAU,CAAC,EAAE,CAAC;KAChB,CAAC,EACF,EAAE,CACH,CAAC;IAEF,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC;SAC1B,IAAI,CACH,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,CAC3B,iBAAiB,CAAC,KAAK,CAAC,GAAG,iBAAiB,CAAC,KAAK,CAAC,CACtD;SACA,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC,CAAC","sourcesContent":["// original source sortParamKeys from: https://github.com/etclabscore/sig.tools/blob/master/src/postMessageServer/postMessageServer.ts#L75-L77\n\nimport type { JsonRpcParams } from '@metamask/utils';\n\n/**\n * Deterministically sort JSON-RPC parameter keys. This makes it possible to\n * support both arrays and objects as parameters. Objects are sorted and turned\n * into arrays, for easier consumption by the snap.\n *\n * The order is defined by the `method` parameter.\n *\n * @param methodParams - The parameters of the JSON-RPC method, which\n * determines the ordering for the parameters.\n * @param params - JSON-RPC parameters as object or array.\n * @returns The values for the sorted keys. If `params` is not provided, this\n * returns an empty array. If `params` is an array, this returns the same\n * `params`.\n */\nexport const sortParamKeys = (\n methodParams: string[],\n params?: JsonRpcParams,\n) => {\n if (!params) {\n return [];\n }\n\n if (params instanceof Array) {\n return params;\n }\n\n const methodParamsOrder: { [k: string]: number } = methodParams.reduce(\n (paramsOrderObj, paramsName, i) => ({\n ...paramsOrderObj,\n [paramsName]: i,\n }),\n {},\n );\n\n return Object.entries(params)\n .sort(\n ([name1, _1], [name2, _2]) =>\n methodParamsOrder[name1] - methodParamsOrder[name2],\n )\n .map(([_, val]) => val);\n};\n"]}
@@ -0,0 +1,156 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidResponse = exports.sanitizeRequestArguments = exports.assertEthereumOutboundRequest = exports.assertSnapOutboundRequest = exports.BLOCKED_RPC_METHODS = exports.proxyStreamProvider = exports.withTeardown = void 0;
4
+ const rpc_errors_1 = require("@metamask/rpc-errors");
5
+ const utils_1 = require("@metamask/utils");
6
+ const logging_1 = require("../logging.cjs");
7
+ // 64 MB - we chose this number because it is the size limit for postMessage
8
+ // between the extension and the dapp enforced by Chrome.
9
+ const MAX_RESPONSE_JSON_SIZE = 64000000;
10
+ /**
11
+ * Make proxy for Promise and handle the teardown process properly.
12
+ * If the teardown is called in the meanwhile, Promise result will not be
13
+ * exposed to the snap anymore and warning will be logged to the console.
14
+ *
15
+ * @param originalPromise - Original promise.
16
+ * @param teardownRef - Reference containing teardown count.
17
+ * @param teardownRef.lastTeardown - Number of the last teardown.
18
+ * @returns New proxy promise.
19
+ */
20
+ async function withTeardown(originalPromise, teardownRef) {
21
+ const myTeardown = teardownRef.lastTeardown;
22
+ return new Promise((resolve, reject) => {
23
+ originalPromise
24
+ .then((value) => {
25
+ if (teardownRef.lastTeardown === myTeardown) {
26
+ resolve(value);
27
+ }
28
+ else {
29
+ (0, logging_1.log)('Late promise received after Snap finished execution. Promise will be dropped.');
30
+ }
31
+ })
32
+ .catch((reason) => {
33
+ if (teardownRef.lastTeardown === myTeardown) {
34
+ reject(reason);
35
+ }
36
+ else {
37
+ (0, logging_1.log)('Late promise received after Snap finished execution. Promise will be dropped.');
38
+ }
39
+ });
40
+ });
41
+ }
42
+ exports.withTeardown = withTeardown;
43
+ /**
44
+ * Returns a Proxy that only allows access to a `request` function.
45
+ * This is useful for replacing StreamProvider with an attenuated version.
46
+ *
47
+ * @param request - Custom attenuated request function.
48
+ * @returns Proxy that mimics a StreamProvider instance.
49
+ */
50
+ function proxyStreamProvider(request) {
51
+ // Proxy target is intentionally set to be an empty object, to ensure
52
+ // that access to the prototype chain is not possible.
53
+ const proxy = new Proxy({}, {
54
+ has(_target, prop) {
55
+ return typeof prop === 'string' && ['request'].includes(prop);
56
+ },
57
+ get(_target, prop) {
58
+ if (prop === 'request') {
59
+ return request;
60
+ }
61
+ return undefined;
62
+ },
63
+ });
64
+ return proxy;
65
+ }
66
+ exports.proxyStreamProvider = proxyStreamProvider;
67
+ // We're blocking these RPC methods for v1, will revisit later.
68
+ exports.BLOCKED_RPC_METHODS = Object.freeze([
69
+ 'wallet_requestPermissions',
70
+ 'wallet_revokePermissions',
71
+ // We disallow all of these confirmations for now, since the screens are not ready for Snaps.
72
+ 'eth_sendTransaction',
73
+ 'eth_sign',
74
+ 'eth_signTypedData',
75
+ 'eth_signTypedData_v1',
76
+ 'eth_signTypedData_v3',
77
+ 'eth_signTypedData_v4',
78
+ 'eth_decrypt',
79
+ 'eth_getEncryptionPublicKey',
80
+ 'wallet_addEthereumChain',
81
+ 'wallet_switchEthereumChain',
82
+ 'wallet_watchAsset',
83
+ 'wallet_registerOnboarding',
84
+ 'wallet_scanQRCode',
85
+ ]);
86
+ /**
87
+ * Asserts the validity of request arguments for a snap outbound request using the `snap.request` API.
88
+ *
89
+ * @param args - The arguments to validate.
90
+ */
91
+ function assertSnapOutboundRequest(args) {
92
+ // Disallow any non `wallet_` or `snap_` methods for separation of concerns.
93
+ (0, utils_1.assert)(String.prototype.startsWith.call(args.method, 'wallet_') ||
94
+ String.prototype.startsWith.call(args.method, 'snap_'), 'The global Snap API only allows RPC methods starting with `wallet_*` and `snap_*`.', rpc_errors_1.rpcErrors.methodNotSupported);
95
+ (0, utils_1.assert)(!exports.BLOCKED_RPC_METHODS.includes(args.method), rpc_errors_1.rpcErrors.methodNotFound({
96
+ data: {
97
+ method: args.method,
98
+ },
99
+ }));
100
+ (0, utils_1.assertStruct)(args, utils_1.JsonStruct, 'Provided value is not JSON-RPC compatible', rpc_errors_1.rpcErrors.invalidParams);
101
+ }
102
+ exports.assertSnapOutboundRequest = assertSnapOutboundRequest;
103
+ /**
104
+ * Asserts the validity of request arguments for an ethereum outbound request using the `ethereum.request` API.
105
+ *
106
+ * @param args - The arguments to validate.
107
+ */
108
+ function assertEthereumOutboundRequest(args) {
109
+ // Disallow snaps methods for separation of concerns.
110
+ (0, utils_1.assert)(!String.prototype.startsWith.call(args.method, 'snap_'), rpc_errors_1.rpcErrors.methodNotFound({
111
+ data: {
112
+ method: args.method,
113
+ },
114
+ }));
115
+ (0, utils_1.assert)(!exports.BLOCKED_RPC_METHODS.includes(args.method), rpc_errors_1.rpcErrors.methodNotFound({
116
+ data: {
117
+ method: args.method,
118
+ },
119
+ }));
120
+ (0, utils_1.assertStruct)(args, utils_1.JsonStruct, 'Provided value is not JSON-RPC compatible', rpc_errors_1.rpcErrors.invalidParams);
121
+ }
122
+ exports.assertEthereumOutboundRequest = assertEthereumOutboundRequest;
123
+ /**
124
+ * Gets a sanitized value to be used for passing to the underlying MetaMask provider.
125
+ *
126
+ * @param value - An unsanitized value from a snap.
127
+ * @returns A sanitized value ready to be passed to a MetaMask provider.
128
+ */
129
+ function sanitizeRequestArguments(value) {
130
+ // Before passing to getSafeJson we run the value through JSON serialization.
131
+ // This lets request arguments contain undefined which is normally disallowed.
132
+ const json = JSON.parse(JSON.stringify(value));
133
+ return (0, utils_1.getSafeJson)(json);
134
+ }
135
+ exports.sanitizeRequestArguments = sanitizeRequestArguments;
136
+ /**
137
+ * Check if the input is a valid response.
138
+ *
139
+ * @param response - The response.
140
+ * @returns True if the response is valid, otherwise false.
141
+ */
142
+ function isValidResponse(response) {
143
+ if (!(0, utils_1.isObject)(response)) {
144
+ return false;
145
+ }
146
+ try {
147
+ // If the JSON is invalid this will throw and we should return false.
148
+ const size = (0, utils_1.getJsonSize)(response);
149
+ return size < MAX_RESPONSE_JSON_SIZE;
150
+ }
151
+ catch {
152
+ return false;
153
+ }
154
+ }
155
+ exports.isValidResponse = isValidResponse;
156
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":";;;AACA,qDAAiD;AACjD,2CAOyB;AAEzB,4CAAiC;AAEjC,4EAA4E;AAC5E,yDAAyD;AACzD,MAAM,sBAAsB,GAAG,QAAU,CAAC;AAE1C;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,eAA8B,EAC9B,WAAqC;IAErC,MAAM,UAAU,GAAG,WAAW,CAAC,YAAY,CAAC;IAC5C,OAAO,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,eAAe;aACZ,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE;YACd,IAAI,WAAW,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;gBAC5C,OAAO,CAAC,KAAK,CAAC,CAAC;YACjB,CAAC;iBAAM,CAAC;gBACN,IAAA,aAAG,EACD,+EAA+E,CAChF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,MAAM,EAAE,EAAE;YAChB,IAAI,WAAW,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;gBAC5C,MAAM,CAAC,MAAM,CAAC,CAAC;YACjB,CAAC;iBAAM,CAAC;gBACN,IAAA,aAAG,EACD,+EAA+E,CAChF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACL,CAAC;AA1BD,oCA0BC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,OAAgB;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BAAW,EAAC,QAAQ,CAAC,CAAC;QACnC,OAAO,IAAI,GAAG,sBAAsB,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAZD,0CAYC","sourcesContent":["import type { StreamProvider, RequestArguments } from '@metamask/providers';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n assert,\n assertStruct,\n getJsonSize,\n getSafeJson,\n isObject,\n JsonStruct,\n} from '@metamask/utils';\n\nimport { log } from '../logging';\n\n// 64 MB - we chose this number because it is the size limit for postMessage\n// between the extension and the dapp enforced by Chrome.\nconst MAX_RESPONSE_JSON_SIZE = 64_000_000;\n\n/**\n * Make proxy for Promise and handle the teardown process properly.\n * If the teardown is called in the meanwhile, Promise result will not be\n * exposed to the snap anymore and warning will be logged to the console.\n *\n * @param originalPromise - Original promise.\n * @param teardownRef - Reference containing teardown count.\n * @param teardownRef.lastTeardown - Number of the last teardown.\n * @returns New proxy promise.\n */\nexport async function withTeardown<Type>(\n originalPromise: Promise<Type>,\n teardownRef: { lastTeardown: number },\n): Promise<Type> {\n const myTeardown = teardownRef.lastTeardown;\n return new Promise<Type>((resolve, reject) => {\n originalPromise\n .then((value) => {\n if (teardownRef.lastTeardown === myTeardown) {\n resolve(value);\n } else {\n log(\n 'Late promise received after Snap finished execution. Promise will be dropped.',\n );\n }\n })\n .catch((reason) => {\n if (teardownRef.lastTeardown === myTeardown) {\n reject(reason);\n } else {\n log(\n 'Late promise received after Snap finished execution. Promise will be dropped.',\n );\n }\n });\n });\n}\n\n/**\n * Returns a Proxy that only allows access to a `request` function.\n * This is useful for replacing StreamProvider with an attenuated version.\n *\n * @param request - Custom attenuated request function.\n * @returns Proxy that mimics a StreamProvider instance.\n */\nexport function proxyStreamProvider(request: unknown): StreamProvider {\n // Proxy target is intentionally set to be an empty object, to ensure\n // that access to the prototype chain is not possible.\n const proxy = new Proxy(\n {},\n {\n has(_target: object, prop: string | symbol) {\n return typeof prop === 'string' && ['request'].includes(prop);\n },\n get(_target, prop: keyof StreamProvider) {\n if (prop === 'request') {\n return request;\n }\n\n return undefined;\n },\n },\n );\n\n return proxy as StreamProvider;\n}\n\n// We're blocking these RPC methods for v1, will revisit later.\nexport const BLOCKED_RPC_METHODS = Object.freeze([\n 'wallet_requestPermissions',\n 'wallet_revokePermissions',\n // We disallow all of these confirmations for now, since the screens are not ready for Snaps.\n 'eth_sendTransaction',\n 'eth_sign',\n 'eth_signTypedData',\n 'eth_signTypedData_v1',\n 'eth_signTypedData_v3',\n 'eth_signTypedData_v4',\n 'eth_decrypt',\n 'eth_getEncryptionPublicKey',\n 'wallet_addEthereumChain',\n 'wallet_switchEthereumChain',\n 'wallet_watchAsset',\n 'wallet_registerOnboarding',\n 'wallet_scanQRCode',\n]);\n\n/**\n * Asserts the validity of request arguments for a snap outbound request using the `snap.request` API.\n *\n * @param args - The arguments to validate.\n */\nexport function assertSnapOutboundRequest(args: RequestArguments) {\n // Disallow any non `wallet_` or `snap_` methods for separation of concerns.\n assert(\n String.prototype.startsWith.call(args.method, 'wallet_') ||\n String.prototype.startsWith.call(args.method, 'snap_'),\n 'The global Snap API only allows RPC methods starting with `wallet_*` and `snap_*`.',\n rpcErrors.methodNotSupported,\n );\n assert(\n !BLOCKED_RPC_METHODS.includes(args.method),\n rpcErrors.methodNotFound({\n data: {\n method: args.method,\n },\n }),\n );\n assertStruct(\n args,\n JsonStruct,\n 'Provided value is not JSON-RPC compatible',\n rpcErrors.invalidParams,\n );\n}\n\n/**\n * Asserts the validity of request arguments for an ethereum outbound request using the `ethereum.request` API.\n *\n * @param args - The arguments to validate.\n */\nexport function assertEthereumOutboundRequest(args: RequestArguments) {\n // Disallow snaps methods for separation of concerns.\n assert(\n !String.prototype.startsWith.call(args.method, 'snap_'),\n rpcErrors.methodNotFound({\n data: {\n method: args.method,\n },\n }),\n );\n assert(\n !BLOCKED_RPC_METHODS.includes(args.method),\n rpcErrors.methodNotFound({\n data: {\n method: args.method,\n },\n }),\n );\n assertStruct(\n args,\n JsonStruct,\n 'Provided value is not JSON-RPC compatible',\n rpcErrors.invalidParams,\n );\n}\n\n/**\n * Gets a sanitized value to be used for passing to the underlying MetaMask provider.\n *\n * @param value - An unsanitized value from a snap.\n * @returns A sanitized value ready to be passed to a MetaMask provider.\n */\nexport function sanitizeRequestArguments(value: unknown): RequestArguments {\n // Before passing to getSafeJson we run the value through JSON serialization.\n // This lets request arguments contain undefined which is normally disallowed.\n const json = JSON.parse(JSON.stringify(value));\n return getSafeJson(json) as RequestArguments;\n}\n\n/**\n * Check if the input is a valid response.\n *\n * @param response - The response.\n * @returns True if the response is valid, otherwise false.\n */\nexport function isValidResponse(response: Record<string, unknown>) {\n if (!isObject(response)) {\n return false;\n }\n\n try {\n // If the JSON is invalid this will throw and we should return false.\n const size = getJsonSize(response);\n return size < MAX_RESPONSE_JSON_SIZE;\n } catch {\n return false;\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { StreamProvider, RequestArguments } from '@metamask/providers';
1
+ import type { StreamProvider, RequestArguments } from "@metamask/providers";
2
2
  /**
3
3
  * Make proxy for Promise and handle the teardown process properly.
4
4
  * If the teardown is called in the meanwhile, Promise result will not be
@@ -47,3 +47,4 @@ export declare function sanitizeRequestArguments(value: unknown): RequestArgumen
47
47
  * @returns True if the response is valid, otherwise false.
48
48
  */
49
49
  export declare function isValidResponse(response: Record<string, unknown>): boolean;
50
+ //# sourceMappingURL=utils.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.cts","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,4BAA4B;AAiB5E;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,IAAI,EACrC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,EAC9B,WAAW,EAAE;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GACpC,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAoBpE;AAGD,eAAO,MAAM,mBAAmB,mBAiB9B,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,gBAAgB,QAsB/D;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,gBAAgB,QAwBnE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAKzE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAYhE"}
@@ -0,0 +1,50 @@
1
+ import type { StreamProvider, RequestArguments } from "@metamask/providers";
2
+ /**
3
+ * Make proxy for Promise and handle the teardown process properly.
4
+ * If the teardown is called in the meanwhile, Promise result will not be
5
+ * exposed to the snap anymore and warning will be logged to the console.
6
+ *
7
+ * @param originalPromise - Original promise.
8
+ * @param teardownRef - Reference containing teardown count.
9
+ * @param teardownRef.lastTeardown - Number of the last teardown.
10
+ * @returns New proxy promise.
11
+ */
12
+ export declare function withTeardown<Type>(originalPromise: Promise<Type>, teardownRef: {
13
+ lastTeardown: number;
14
+ }): Promise<Type>;
15
+ /**
16
+ * Returns a Proxy that only allows access to a `request` function.
17
+ * This is useful for replacing StreamProvider with an attenuated version.
18
+ *
19
+ * @param request - Custom attenuated request function.
20
+ * @returns Proxy that mimics a StreamProvider instance.
21
+ */
22
+ export declare function proxyStreamProvider(request: unknown): StreamProvider;
23
+ export declare const BLOCKED_RPC_METHODS: readonly string[];
24
+ /**
25
+ * Asserts the validity of request arguments for a snap outbound request using the `snap.request` API.
26
+ *
27
+ * @param args - The arguments to validate.
28
+ */
29
+ export declare function assertSnapOutboundRequest(args: RequestArguments): void;
30
+ /**
31
+ * Asserts the validity of request arguments for an ethereum outbound request using the `ethereum.request` API.
32
+ *
33
+ * @param args - The arguments to validate.
34
+ */
35
+ export declare function assertEthereumOutboundRequest(args: RequestArguments): void;
36
+ /**
37
+ * Gets a sanitized value to be used for passing to the underlying MetaMask provider.
38
+ *
39
+ * @param value - An unsanitized value from a snap.
40
+ * @returns A sanitized value ready to be passed to a MetaMask provider.
41
+ */
42
+ export declare function sanitizeRequestArguments(value: unknown): RequestArguments;
43
+ /**
44
+ * Check if the input is a valid response.
45
+ *
46
+ * @param response - The response.
47
+ * @returns True if the response is valid, otherwise false.
48
+ */
49
+ export declare function isValidResponse(response: Record<string, unknown>): boolean;
50
+ //# sourceMappingURL=utils.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.mts","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,4BAA4B;AAiB5E;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,IAAI,EACrC,eAAe,EAAE,OAAO,CAAC,IAAI,CAAC,EAC9B,WAAW,EAAE;IAAE,YAAY,EAAE,MAAM,CAAA;CAAE,GACpC,OAAO,CAAC,IAAI,CAAC,CAuBf;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,cAAc,CAoBpE;AAGD,eAAO,MAAM,mBAAmB,mBAiB9B,CAAC;AAEH;;;;GAIG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,gBAAgB,QAsB/D;AAED;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE,gBAAgB,QAwBnE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAKzE;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,WAYhE"}
@@ -1,21 +1,147 @@
1
- import {
2
- BLOCKED_RPC_METHODS,
3
- assertEthereumOutboundRequest,
4
- assertSnapOutboundRequest,
5
- isValidResponse,
6
- proxyStreamProvider,
7
- sanitizeRequestArguments,
8
- withTeardown
9
- } from "../chunk-HL2TTKF3.mjs";
10
- import "../chunk-5DEV3QQU.mjs";
11
- import "../chunk-YRZVIDCF.mjs";
12
- export {
13
- BLOCKED_RPC_METHODS,
14
- assertEthereumOutboundRequest,
15
- assertSnapOutboundRequest,
16
- isValidResponse,
17
- proxyStreamProvider,
18
- sanitizeRequestArguments,
19
- withTeardown
20
- };
1
+ import { rpcErrors } from "@metamask/rpc-errors";
2
+ import { assert, assertStruct, getJsonSize, getSafeJson, isObject, JsonStruct } from "@metamask/utils";
3
+ import { log } from "../logging.mjs";
4
+ // 64 MB - we chose this number because it is the size limit for postMessage
5
+ // between the extension and the dapp enforced by Chrome.
6
+ const MAX_RESPONSE_JSON_SIZE = 64000000;
7
+ /**
8
+ * Make proxy for Promise and handle the teardown process properly.
9
+ * If the teardown is called in the meanwhile, Promise result will not be
10
+ * exposed to the snap anymore and warning will be logged to the console.
11
+ *
12
+ * @param originalPromise - Original promise.
13
+ * @param teardownRef - Reference containing teardown count.
14
+ * @param teardownRef.lastTeardown - Number of the last teardown.
15
+ * @returns New proxy promise.
16
+ */
17
+ export async function withTeardown(originalPromise, teardownRef) {
18
+ const myTeardown = teardownRef.lastTeardown;
19
+ return new Promise((resolve, reject) => {
20
+ originalPromise
21
+ .then((value) => {
22
+ if (teardownRef.lastTeardown === myTeardown) {
23
+ resolve(value);
24
+ }
25
+ else {
26
+ log('Late promise received after Snap finished execution. Promise will be dropped.');
27
+ }
28
+ })
29
+ .catch((reason) => {
30
+ if (teardownRef.lastTeardown === myTeardown) {
31
+ reject(reason);
32
+ }
33
+ else {
34
+ log('Late promise received after Snap finished execution. Promise will be dropped.');
35
+ }
36
+ });
37
+ });
38
+ }
39
+ /**
40
+ * Returns a Proxy that only allows access to a `request` function.
41
+ * This is useful for replacing StreamProvider with an attenuated version.
42
+ *
43
+ * @param request - Custom attenuated request function.
44
+ * @returns Proxy that mimics a StreamProvider instance.
45
+ */
46
+ export function proxyStreamProvider(request) {
47
+ // Proxy target is intentionally set to be an empty object, to ensure
48
+ // that access to the prototype chain is not possible.
49
+ const proxy = new Proxy({}, {
50
+ has(_target, prop) {
51
+ return typeof prop === 'string' && ['request'].includes(prop);
52
+ },
53
+ get(_target, prop) {
54
+ if (prop === 'request') {
55
+ return request;
56
+ }
57
+ return undefined;
58
+ },
59
+ });
60
+ return proxy;
61
+ }
62
+ // We're blocking these RPC methods for v1, will revisit later.
63
+ export const BLOCKED_RPC_METHODS = Object.freeze([
64
+ 'wallet_requestPermissions',
65
+ 'wallet_revokePermissions',
66
+ // We disallow all of these confirmations for now, since the screens are not ready for Snaps.
67
+ 'eth_sendTransaction',
68
+ 'eth_sign',
69
+ 'eth_signTypedData',
70
+ 'eth_signTypedData_v1',
71
+ 'eth_signTypedData_v3',
72
+ 'eth_signTypedData_v4',
73
+ 'eth_decrypt',
74
+ 'eth_getEncryptionPublicKey',
75
+ 'wallet_addEthereumChain',
76
+ 'wallet_switchEthereumChain',
77
+ 'wallet_watchAsset',
78
+ 'wallet_registerOnboarding',
79
+ 'wallet_scanQRCode',
80
+ ]);
81
+ /**
82
+ * Asserts the validity of request arguments for a snap outbound request using the `snap.request` API.
83
+ *
84
+ * @param args - The arguments to validate.
85
+ */
86
+ export function assertSnapOutboundRequest(args) {
87
+ // Disallow any non `wallet_` or `snap_` methods for separation of concerns.
88
+ assert(String.prototype.startsWith.call(args.method, 'wallet_') ||
89
+ String.prototype.startsWith.call(args.method, 'snap_'), 'The global Snap API only allows RPC methods starting with `wallet_*` and `snap_*`.', rpcErrors.methodNotSupported);
90
+ assert(!BLOCKED_RPC_METHODS.includes(args.method), rpcErrors.methodNotFound({
91
+ data: {
92
+ method: args.method,
93
+ },
94
+ }));
95
+ assertStruct(args, JsonStruct, 'Provided value is not JSON-RPC compatible', rpcErrors.invalidParams);
96
+ }
97
+ /**
98
+ * Asserts the validity of request arguments for an ethereum outbound request using the `ethereum.request` API.
99
+ *
100
+ * @param args - The arguments to validate.
101
+ */
102
+ export function assertEthereumOutboundRequest(args) {
103
+ // Disallow snaps methods for separation of concerns.
104
+ assert(!String.prototype.startsWith.call(args.method, 'snap_'), rpcErrors.methodNotFound({
105
+ data: {
106
+ method: args.method,
107
+ },
108
+ }));
109
+ assert(!BLOCKED_RPC_METHODS.includes(args.method), rpcErrors.methodNotFound({
110
+ data: {
111
+ method: args.method,
112
+ },
113
+ }));
114
+ assertStruct(args, JsonStruct, 'Provided value is not JSON-RPC compatible', rpcErrors.invalidParams);
115
+ }
116
+ /**
117
+ * Gets a sanitized value to be used for passing to the underlying MetaMask provider.
118
+ *
119
+ * @param value - An unsanitized value from a snap.
120
+ * @returns A sanitized value ready to be passed to a MetaMask provider.
121
+ */
122
+ export function sanitizeRequestArguments(value) {
123
+ // Before passing to getSafeJson we run the value through JSON serialization.
124
+ // This lets request arguments contain undefined which is normally disallowed.
125
+ const json = JSON.parse(JSON.stringify(value));
126
+ return getSafeJson(json);
127
+ }
128
+ /**
129
+ * Check if the input is a valid response.
130
+ *
131
+ * @param response - The response.
132
+ * @returns True if the response is valid, otherwise false.
133
+ */
134
+ export function isValidResponse(response) {
135
+ if (!isObject(response)) {
136
+ return false;
137
+ }
138
+ try {
139
+ // If the JSON is invalid this will throw and we should return false.
140
+ const size = getJsonSize(response);
141
+ return size < MAX_RESPONSE_JSON_SIZE;
142
+ }
143
+ catch {
144
+ return false;
145
+ }
146
+ }
21
147
  //# sourceMappingURL=utils.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
1
+ {"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../src/common/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EACL,MAAM,EACN,YAAY,EACZ,WAAW,EACX,WAAW,EACX,QAAQ,EACR,UAA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AE;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB;KACF,CAAC,CACH,CAAC;IACF,MAAM,CACJ,CAAC,mBAAmB,CAAC,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,EAC1C,SAAS,CAAC,cAAc,CAAC;QACvB,IAAI,EAAE;YACJ,MAAM,EAAE,IAAI,CAAC,MAAM;SACpB;KACF,CAAC,CACH,CAAC;IACF,YAAY,CACV,IAAI,EACJ,UAAU,EACV,2CAA2C,EAC3C,SAAS,CAAC,aAAa,CACxB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAAC,KAAc;IACrD,6EAA6E;IAC7E,8EAA8E;IAC9E,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;IAC/C,OAAO,WAAW,CAAC,IAAI,CAAqB,CAAC;AAC/C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,eAAe,CAAC,QAAiC;IAC/D,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxB,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,CAAC;QACH,qEAAqE;QACrE,MAAM,IAAI,GAAG,WAAW,CAAC,QAAQ,CAAC,CAAC;QACnC,OAAO,IAAI,GAAG,sBAAsB,CAAC;IACvC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["import type { StreamProvider, RequestArguments } from '@metamask/providers';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n assert,\n assertStruct,\n getJsonSize,\n getSafeJson,\n isObject,\n JsonStruct,\n} from '@metamask/utils';\n\nimport { log } from '../logging';\n\n// 64 MB - we chose this number because it is the size limit for postMessage\n// between the extension and the dapp enforced by Chrome.\nconst MAX_RESPONSE_JSON_SIZE = 64_000_000;\n\n/**\n * Make proxy for Promise and handle the teardown process properly.\n * If the teardown is called in the meanwhile, Promise result will not be\n * exposed to the snap anymore and warning will be logged to the console.\n *\n * @param originalPromise - Original promise.\n * @param teardownRef - Reference containing teardown count.\n * @param teardownRef.lastTeardown - Number of the last teardown.\n * @returns New proxy promise.\n */\nexport async function withTeardown<Type>(\n originalPromise: Promise<Type>,\n teardownRef: { lastTeardown: number },\n): Promise<Type> {\n const myTeardown = teardownRef.lastTeardown;\n return new Promise<Type>((resolve, reject) => {\n originalPromise\n .then((value) => {\n if (teardownRef.lastTeardown === myTeardown) {\n resolve(value);\n } else {\n log(\n 'Late promise received after Snap finished execution. Promise will be dropped.',\n );\n }\n })\n .catch((reason) => {\n if (teardownRef.lastTeardown === myTeardown) {\n reject(reason);\n } else {\n log(\n 'Late promise received after Snap finished execution. Promise will be dropped.',\n );\n }\n });\n });\n}\n\n/**\n * Returns a Proxy that only allows access to a `request` function.\n * This is useful for replacing StreamProvider with an attenuated version.\n *\n * @param request - Custom attenuated request function.\n * @returns Proxy that mimics a StreamProvider instance.\n */\nexport function proxyStreamProvider(request: unknown): StreamProvider {\n // Proxy target is intentionally set to be an empty object, to ensure\n // that access to the prototype chain is not possible.\n const proxy = new Proxy(\n {},\n {\n has(_target: object, prop: string | symbol) {\n return typeof prop === 'string' && ['request'].includes(prop);\n },\n get(_target, prop: keyof StreamProvider) {\n if (prop === 'request') {\n return request;\n }\n\n return undefined;\n },\n },\n );\n\n return proxy as StreamProvider;\n}\n\n// We're blocking these RPC methods for v1, will revisit later.\nexport const BLOCKED_RPC_METHODS = Object.freeze([\n 'wallet_requestPermissions',\n 'wallet_revokePermissions',\n // We disallow all of these confirmations for now, since the screens are not ready for Snaps.\n 'eth_sendTransaction',\n 'eth_sign',\n 'eth_signTypedData',\n 'eth_signTypedData_v1',\n 'eth_signTypedData_v3',\n 'eth_signTypedData_v4',\n 'eth_decrypt',\n 'eth_getEncryptionPublicKey',\n 'wallet_addEthereumChain',\n 'wallet_switchEthereumChain',\n 'wallet_watchAsset',\n 'wallet_registerOnboarding',\n 'wallet_scanQRCode',\n]);\n\n/**\n * Asserts the validity of request arguments for a snap outbound request using the `snap.request` API.\n *\n * @param args - The arguments to validate.\n */\nexport function assertSnapOutboundRequest(args: RequestArguments) {\n // Disallow any non `wallet_` or `snap_` methods for separation of concerns.\n assert(\n String.prototype.startsWith.call(args.method, 'wallet_') ||\n String.prototype.startsWith.call(args.method, 'snap_'),\n 'The global Snap API only allows RPC methods starting with `wallet_*` and `snap_*`.',\n rpcErrors.methodNotSupported,\n );\n assert(\n !BLOCKED_RPC_METHODS.includes(args.method),\n rpcErrors.methodNotFound({\n data: {\n method: args.method,\n },\n }),\n );\n assertStruct(\n args,\n JsonStruct,\n 'Provided value is not JSON-RPC compatible',\n rpcErrors.invalidParams,\n );\n}\n\n/**\n * Asserts the validity of request arguments for an ethereum outbound request using the `ethereum.request` API.\n *\n * @param args - The arguments to validate.\n */\nexport function assertEthereumOutboundRequest(args: RequestArguments) {\n // Disallow snaps methods for separation of concerns.\n assert(\n !String.prototype.startsWith.call(args.method, 'snap_'),\n rpcErrors.methodNotFound({\n data: {\n method: args.method,\n },\n }),\n );\n assert(\n !BLOCKED_RPC_METHODS.includes(args.method),\n rpcErrors.methodNotFound({\n data: {\n method: args.method,\n },\n }),\n );\n assertStruct(\n args,\n JsonStruct,\n 'Provided value is not JSON-RPC compatible',\n rpcErrors.invalidParams,\n );\n}\n\n/**\n * Gets a sanitized value to be used for passing to the underlying MetaMask provider.\n *\n * @param value - An unsanitized value from a snap.\n * @returns A sanitized value ready to be passed to a MetaMask provider.\n */\nexport function sanitizeRequestArguments(value: unknown): RequestArguments {\n // Before passing to getSafeJson we run the value through JSON serialization.\n // This lets request arguments contain undefined which is normally disallowed.\n const json = JSON.parse(JSON.stringify(value));\n return getSafeJson(json) as RequestArguments;\n}\n\n/**\n * Check if the input is a valid response.\n *\n * @param response - The response.\n * @returns True if the response is valid, otherwise false.\n */\nexport function isValidResponse(response: Record<string, unknown>) {\n if (!isObject(response)) {\n return false;\n }\n\n try {\n // If the JSON is invalid this will throw and we should return false.\n const size = getJsonSize(response);\n return size < MAX_RESPONSE_JSON_SIZE;\n } catch {\n return false;\n }\n}\n"]}
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.assertIsOnUserInputRequestArguments = exports.OnUserInputArgumentsStruct = exports.assertIsOnNameLookupRequestArguments = exports.OnNameLookupRequestArgumentsStruct = exports.assertIsOnSignatureRequestArguments = exports.OnSignatureRequestArgumentsStruct = exports.assertIsOnTransactionRequestArguments = exports.OnTransactionRequestArgumentsStruct = exports.SnapRpcRequestArgumentsStruct = exports.ExecuteSnapRequestArgumentsStruct = exports.TerminateRequestArgumentsStruct = exports.PingRequestArgumentsStruct = exports.isEndowmentsArray = exports.isEndowment = exports.EndowmentStruct = exports.JsonRpcRequestWithoutIdStruct = void 0;
4
+ const rpc_errors_1 = require("@metamask/rpc-errors");
5
+ const snaps_sdk_1 = require("@metamask/snaps-sdk");
6
+ const snaps_utils_1 = require("@metamask/snaps-utils");
7
+ const superstruct_1 = require("@metamask/superstruct");
8
+ const utils_1 = require("@metamask/utils");
9
+ exports.JsonRpcRequestWithoutIdStruct = (0, superstruct_1.object)({
10
+ jsonrpc: (0, superstruct_1.optional)(utils_1.JsonRpcVersionStruct),
11
+ id: (0, superstruct_1.optional)(utils_1.JsonRpcIdStruct),
12
+ method: (0, superstruct_1.string)(),
13
+ params: (0, superstruct_1.optional)(utils_1.JsonRpcParamsStruct),
14
+ });
15
+ exports.EndowmentStruct = (0, superstruct_1.string)();
16
+ /**
17
+ * Check if the given value is an endowment.
18
+ *
19
+ * @param value - The value to check.
20
+ * @returns Whether the value is an endowment.
21
+ */
22
+ function isEndowment(value) {
23
+ return (0, superstruct_1.is)(value, exports.EndowmentStruct);
24
+ }
25
+ exports.isEndowment = isEndowment;
26
+ /**
27
+ * Check if the given value is an array of endowments.
28
+ *
29
+ * @param value - The value to check.
30
+ * @returns Whether the value is an array of endowments.
31
+ */
32
+ function isEndowmentsArray(value) {
33
+ return Array.isArray(value) && value.every(isEndowment);
34
+ }
35
+ exports.isEndowmentsArray = isEndowmentsArray;
36
+ const OkStruct = (0, superstruct_1.literal)('OK');
37
+ exports.PingRequestArgumentsStruct = (0, superstruct_1.optional)((0, superstruct_1.union)([(0, superstruct_1.literal)(undefined), (0, superstruct_1.array)()]));
38
+ exports.TerminateRequestArgumentsStruct = (0, superstruct_1.union)([
39
+ (0, superstruct_1.literal)(undefined),
40
+ (0, superstruct_1.array)(),
41
+ ]);
42
+ exports.ExecuteSnapRequestArgumentsStruct = (0, superstruct_1.tuple)([
43
+ (0, superstruct_1.string)(),
44
+ (0, superstruct_1.string)(),
45
+ (0, superstruct_1.array)(exports.EndowmentStruct),
46
+ ]);
47
+ exports.SnapRpcRequestArgumentsStruct = (0, superstruct_1.tuple)([
48
+ (0, superstruct_1.string)(),
49
+ (0, superstruct_1.enums)(Object.values(snaps_utils_1.HandlerType)),
50
+ (0, superstruct_1.string)(),
51
+ (0, superstruct_1.assign)(exports.JsonRpcRequestWithoutIdStruct, (0, superstruct_1.object)({
52
+ params: (0, superstruct_1.optional)((0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct)),
53
+ })),
54
+ ]);
55
+ exports.OnTransactionRequestArgumentsStruct = (0, superstruct_1.object)({
56
+ // TODO: Improve `transaction` type.
57
+ transaction: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
58
+ chainId: snaps_utils_1.ChainIdStruct,
59
+ transactionOrigin: (0, superstruct_1.nullable)((0, superstruct_1.string)()),
60
+ });
61
+ /**
62
+ * Asserts that the given value is a valid {@link OnTransactionRequestArguments}
63
+ * object.
64
+ *
65
+ * @param value - The value to validate.
66
+ * @throws If the value is not a valid {@link OnTransactionRequestArguments}
67
+ * object.
68
+ */
69
+ function assertIsOnTransactionRequestArguments(value) {
70
+ (0, utils_1.assertStruct)(value, exports.OnTransactionRequestArgumentsStruct, 'Invalid request params', rpc_errors_1.rpcErrors.invalidParams);
71
+ }
72
+ exports.assertIsOnTransactionRequestArguments = assertIsOnTransactionRequestArguments;
73
+ exports.OnSignatureRequestArgumentsStruct = (0, superstruct_1.object)({
74
+ signature: (0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct),
75
+ signatureOrigin: (0, superstruct_1.nullable)((0, superstruct_1.string)()),
76
+ });
77
+ /**
78
+ * Asserts that the given value is a valid {@link OnSignatureRequestArguments}
79
+ * object.
80
+ *
81
+ * @param value - The value to validate.
82
+ * @throws If the value is not a valid {@link OnSignatureRequestArguments}
83
+ * object.
84
+ */
85
+ function assertIsOnSignatureRequestArguments(value) {
86
+ (0, utils_1.assertStruct)(value, exports.OnSignatureRequestArgumentsStruct, 'Invalid request params', rpc_errors_1.rpcErrors.invalidParams);
87
+ }
88
+ exports.assertIsOnSignatureRequestArguments = assertIsOnSignatureRequestArguments;
89
+ const baseNameLookupArgs = { chainId: snaps_utils_1.ChainIdStruct };
90
+ const domainRequestStruct = (0, superstruct_1.object)({
91
+ ...baseNameLookupArgs,
92
+ address: (0, superstruct_1.string)(),
93
+ });
94
+ const addressRequestStruct = (0, superstruct_1.object)({
95
+ ...baseNameLookupArgs,
96
+ domain: (0, superstruct_1.string)(),
97
+ });
98
+ exports.OnNameLookupRequestArgumentsStruct = (0, superstruct_1.union)([
99
+ domainRequestStruct,
100
+ addressRequestStruct,
101
+ ]);
102
+ /**
103
+ * Asserts that the given value is a valid {@link OnNameLookupRequestArguments}
104
+ * object.
105
+ *
106
+ * @param value - The value to validate.
107
+ * @throws If the value is not a valid {@link OnNameLookupRequestArguments}
108
+ * object.
109
+ */
110
+ function assertIsOnNameLookupRequestArguments(value) {
111
+ (0, utils_1.assertStruct)(value, exports.OnNameLookupRequestArgumentsStruct, 'Invalid request params', rpc_errors_1.rpcErrors.invalidParams);
112
+ }
113
+ exports.assertIsOnNameLookupRequestArguments = assertIsOnNameLookupRequestArguments;
114
+ exports.OnUserInputArgumentsStruct = (0, superstruct_1.object)({
115
+ id: (0, superstruct_1.string)(),
116
+ event: snaps_sdk_1.UserInputEventStruct,
117
+ context: (0, superstruct_1.optional)((0, superstruct_1.nullable)(snaps_sdk_1.InterfaceContextStruct)),
118
+ });
119
+ /**
120
+ * Asserts that the given value is a valid {@link OnUserInputArguments}
121
+ * object.
122
+ *
123
+ * @param value - The value to validate.
124
+ * @throws If the value is not a valid {@link OnUserInputArguments}
125
+ * object.
126
+ */
127
+ function assertIsOnUserInputRequestArguments(value) {
128
+ (0, utils_1.assertStruct)(value, exports.OnUserInputArgumentsStruct, 'Invalid request params', rpc_errors_1.rpcErrors.invalidParams);
129
+ }
130
+ exports.assertIsOnUserInputRequestArguments = assertIsOnUserInputRequestArguments;
131
+ const OkResponseStruct = (0, superstruct_1.object)({
132
+ id: utils_1.JsonRpcIdStruct,
133
+ jsonrpc: utils_1.JsonRpcVersionStruct,
134
+ result: OkStruct,
135
+ });
136
+ const SnapRpcResponse = utils_1.JsonRpcSuccessStruct;
137
+ //# sourceMappingURL=validation.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/common/validation.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AACjD,mDAG6B;AAC7B,uDAAmE;AAEnE,uDAa+B;AAE/B,2CAOyB;AAEZ,QAAA,6BAA6B,GAAG,IAAA,oBAAM,EAAC;IAClD,OAAO,EAAE,IAAA,sBAAQ,EAAC,4BAAoB,CAAC;IACvC,EAAE,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;IAC7B,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,MAAM,EAAE,IAAA,sBAAQ,EAAC,2BAAmB,CAAC;CACtC,CAAC,CAAC;AAMU,QAAA,eAAe,GAAG,IAAA,oBAAM,GAAE,CAAC;AAGxC;;;;;GAKG;AACH,SAAgB,WAAW,CAAC,KAAc;IACxC,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,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C;IAC/C,EAAE,EAAE,IAAA,oBAAM,GAAE;IACZ,KAAK,EAAE,gCAAoB;IAC3B,OAAO,EAAE,IAAA,sBAAQ,EAAC,IAAA,sBAAQ,EAAC,kCAAsB,CAAC,CAAC;CACpD,CAAC,CAAC;AAIH;;;;;;;GAOG;AACH,SAAgB,mCAAmC,CACjD,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,kCAA0B,EAC1B,wBAAwB,EACxB,sBAAS,CAAC,aAAa,CACxB,CAAC;AACJ,CAAC;AATD,kFASC;AAED,MAAM,gBAAgB,GAAG,IAAA,oBAAM,EAAC;IAC9B,EAAE,EAAE,uBAAe;IACnB,OAAO,EAAE,4BAAoB;IAC7B,MAAM,EAAE,QAAQ;CACjB,CAAC,CAAC;AAEH,MAAM,eAAe,GAAG,4BAAoB,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport {\n InterfaceContextStruct,\n UserInputEventStruct,\n} from '@metamask/snaps-sdk';\nimport { ChainIdStruct, HandlerType } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n assign,\n enums,\n is,\n literal,\n nullable,\n object,\n optional,\n record,\n string,\n tuple,\n union,\n} from '@metamask/superstruct';\nimport type { Json, JsonRpcSuccess } from '@metamask/utils';\nimport {\n assertStruct,\n JsonRpcIdStruct,\n JsonRpcParamsStruct,\n JsonRpcSuccessStruct,\n JsonRpcVersionStruct,\n JsonStruct,\n} from '@metamask/utils';\n\nexport const JsonRpcRequestWithoutIdStruct = object({\n jsonrpc: optional(JsonRpcVersionStruct),\n id: optional(JsonRpcIdStruct),\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type JsonRpcRequestWithoutId = Infer<\n typeof JsonRpcRequestWithoutIdStruct\n>;\n\nexport const EndowmentStruct = string();\nexport type Endowment = Infer<typeof EndowmentStruct>;\n\n/**\n * Check if the given value is an endowment.\n *\n * @param value - The value to check.\n * @returns Whether the value is an endowment.\n */\nexport function isEndowment(value: unknown): value is Endowment {\n return is(value, EndowmentStruct);\n}\n\n/**\n * Check if the given value is an array of endowments.\n *\n * @param value - The value to check.\n * @returns Whether the value is an array of endowments.\n */\nexport function isEndowmentsArray(value: unknown): value is Endowment[] {\n return Array.isArray(value) && value.every(isEndowment);\n}\n\nconst OkStruct = literal('OK');\n\nexport const PingRequestArgumentsStruct = optional(\n union([literal(undefined), array()]),\n);\n\nexport const TerminateRequestArgumentsStruct = union([\n literal(undefined),\n array(),\n]);\n\nexport const ExecuteSnapRequestArgumentsStruct = tuple([\n string(),\n string(),\n array(EndowmentStruct),\n]);\n\nexport const SnapRpcRequestArgumentsStruct = tuple([\n string(),\n enums(Object.values(HandlerType)),\n string(),\n assign(\n JsonRpcRequestWithoutIdStruct,\n object({\n params: optional(record(string(), JsonStruct)),\n }),\n ),\n]);\n\nexport type PingRequestArguments = Infer<typeof PingRequestArgumentsStruct>;\nexport type TerminateRequestArguments = Infer<\n typeof TerminateRequestArgumentsStruct\n>;\n\nexport type ExecuteSnapRequestArguments = Infer<\n typeof ExecuteSnapRequestArgumentsStruct\n>;\n\nexport type SnapRpcRequestArguments = Infer<\n typeof SnapRpcRequestArgumentsStruct\n>;\n\nexport type RequestArguments =\n | PingRequestArguments\n | TerminateRequestArguments\n | ExecuteSnapRequestArguments\n | SnapRpcRequestArguments;\n\nexport const OnTransactionRequestArgumentsStruct = object({\n // TODO: Improve `transaction` type.\n transaction: record(string(), JsonStruct),\n chainId: ChainIdStruct,\n transactionOrigin: nullable(string()),\n});\n\nexport type OnTransactionRequestArguments = Infer<\n typeof OnTransactionRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnTransactionRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnTransactionRequestArguments}\n * object.\n */\nexport function assertIsOnTransactionRequestArguments(\n value: unknown,\n): asserts value is OnTransactionRequestArguments {\n assertStruct(\n value,\n OnTransactionRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnSignatureRequestArgumentsStruct = object({\n signature: record(string(), JsonStruct),\n signatureOrigin: nullable(string()),\n});\n\nexport type OnSignatureRequestArguments = Infer<\n typeof OnSignatureRequestArgumentsStruct\n>;\n\n/**\n * Asserts that the given value is a valid {@link OnSignatureRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnSignatureRequestArguments}\n * object.\n */\nexport function assertIsOnSignatureRequestArguments(\n value: unknown,\n): asserts value is OnSignatureRequestArguments {\n assertStruct(\n value,\n OnSignatureRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst baseNameLookupArgs = { chainId: ChainIdStruct };\nconst domainRequestStruct = object({\n ...baseNameLookupArgs,\n address: string(),\n});\nconst addressRequestStruct = object({\n ...baseNameLookupArgs,\n domain: string(),\n});\n\nexport const OnNameLookupRequestArgumentsStruct = union([\n domainRequestStruct,\n addressRequestStruct,\n]);\n\nexport type OnNameLookupRequestArguments = Infer<\n typeof OnNameLookupRequestArgumentsStruct\n>;\n\nexport type PossibleLookupRequestArgs = typeof baseNameLookupArgs & {\n address?: string;\n domain?: string;\n};\n\n/**\n * Asserts that the given value is a valid {@link OnNameLookupRequestArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnNameLookupRequestArguments}\n * object.\n */\nexport function assertIsOnNameLookupRequestArguments(\n value: unknown,\n): asserts value is OnNameLookupRequestArguments {\n assertStruct(\n value,\n OnNameLookupRequestArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nexport const OnUserInputArgumentsStruct = object({\n id: string(),\n event: UserInputEventStruct,\n context: optional(nullable(InterfaceContextStruct)),\n});\n\nexport type OnUserInputArguments = Infer<typeof OnUserInputArgumentsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link OnUserInputArguments}\n * object.\n *\n * @param value - The value to validate.\n * @throws If the value is not a valid {@link OnUserInputArguments}\n * object.\n */\nexport function assertIsOnUserInputRequestArguments(\n value: unknown,\n): asserts value is OnUserInputArguments {\n assertStruct(\n value,\n OnUserInputArgumentsStruct,\n 'Invalid request params',\n rpcErrors.invalidParams,\n );\n}\n\nconst OkResponseStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: OkStruct,\n});\n\nconst SnapRpcResponse = JsonRpcSuccessStruct;\n\nexport type OkResponse = Infer<typeof OkResponseStruct>;\nexport type SnapRpcResponse = Infer<typeof SnapRpcResponse>;\n\nexport type Response = OkResponse | SnapRpcResponse;\n\ntype RequestParams<Params extends unknown[] | undefined> =\n Params extends undefined ? [] : Params;\n\ntype RequestFunction<\n Args extends RequestArguments,\n ResponseType extends JsonRpcSuccess<Json>,\n> = (...args: RequestParams<Args>) => Promise<ResponseType['result']>;\n\nexport type Ping = RequestFunction<PingRequestArguments, OkResponse>;\nexport type Terminate = RequestFunction<TerminateRequestArguments, OkResponse>;\nexport type ExecuteSnap = RequestFunction<\n ExecuteSnapRequestArguments,\n OkResponse\n>;\nexport type SnapRpc = RequestFunction<SnapRpcRequestArguments, SnapRpcResponse>;\n"]}