@metamask/snaps-utils 6.0.0 → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (562) hide show
  1. package/CHANGELOG.md +23 -1
  2. package/dist/array.js +8 -0
  3. package/dist/array.js.map +1 -0
  4. package/dist/array.mjs +8 -0
  5. package/dist/array.mjs.map +1 -0
  6. package/dist/auxiliary-files.js +12 -0
  7. package/dist/auxiliary-files.js.map +1 -0
  8. package/dist/auxiliary-files.mjs +12 -0
  9. package/dist/auxiliary-files.mjs.map +1 -0
  10. package/dist/base64.js +13 -0
  11. package/dist/base64.js.map +1 -0
  12. package/dist/base64.mjs +13 -0
  13. package/dist/base64.mjs.map +1 -0
  14. package/dist/bytes.js +10 -0
  15. package/dist/bytes.js.map +1 -0
  16. package/dist/bytes.mjs +10 -0
  17. package/dist/bytes.mjs.map +1 -0
  18. package/dist/caveats.js +8 -0
  19. package/dist/caveats.js.map +1 -0
  20. package/dist/caveats.mjs +8 -0
  21. package/dist/caveats.mjs.map +1 -0
  22. package/dist/checksum.js +13 -0
  23. package/dist/checksum.js.map +1 -0
  24. package/dist/checksum.mjs +13 -0
  25. package/dist/checksum.mjs.map +1 -0
  26. package/dist/chunk-224S5XKL.js +32 -0
  27. package/dist/chunk-224S5XKL.js.map +1 -0
  28. package/dist/chunk-2G4HD42C.mjs +22 -0
  29. package/dist/chunk-2G4HD42C.mjs.map +1 -0
  30. package/dist/chunk-2IVFF3AA.mjs +211 -0
  31. package/dist/chunk-2IVFF3AA.mjs.map +1 -0
  32. package/dist/chunk-2QS3W66J.js +64 -0
  33. package/dist/chunk-2QS3W66J.js.map +1 -0
  34. package/dist/chunk-2XF32FCF.js +1 -0
  35. package/dist/chunk-2XF32FCF.js.map +1 -0
  36. package/dist/chunk-32B4YQM7.mjs +103 -0
  37. package/dist/chunk-32B4YQM7.mjs.map +1 -0
  38. package/dist/chunk-3SARO5TJ.mjs +18 -0
  39. package/dist/chunk-3SARO5TJ.mjs.map +1 -0
  40. package/dist/chunk-3TH3NLQL.js +169 -0
  41. package/dist/chunk-3TH3NLQL.js.map +1 -0
  42. package/dist/chunk-3ZSMMNQB.mjs +41 -0
  43. package/dist/chunk-3ZSMMNQB.mjs.map +1 -0
  44. package/dist/chunk-43EBXDVP.mjs +30 -0
  45. package/dist/chunk-43EBXDVP.mjs.map +1 -0
  46. package/dist/chunk-4GBOSMF7.mjs +33 -0
  47. package/dist/chunk-4GBOSMF7.mjs.map +1 -0
  48. package/dist/chunk-4IKNNAVC.mjs +30 -0
  49. package/dist/chunk-4IKNNAVC.mjs.map +1 -0
  50. package/dist/chunk-4UMDRHDR.js +95 -0
  51. package/dist/chunk-4UMDRHDR.js.map +1 -0
  52. package/dist/chunk-6CTV7VW5.mjs +20 -0
  53. package/dist/chunk-6CTV7VW5.mjs.map +1 -0
  54. package/dist/chunk-6H32HLTZ.js +10 -0
  55. package/dist/chunk-6H32HLTZ.js.map +1 -0
  56. package/dist/chunk-6WBLB5BX.js +9 -0
  57. package/dist/chunk-6WBLB5BX.js.map +1 -0
  58. package/dist/chunk-7H5TGXZ5.js +70 -0
  59. package/dist/chunk-7H5TGXZ5.js.map +1 -0
  60. package/dist/chunk-7KKLGQNE.js +38 -0
  61. package/dist/chunk-7KKLGQNE.js.map +1 -0
  62. package/dist/chunk-7PNGOFLU.js +22 -0
  63. package/dist/chunk-7PNGOFLU.js.map +1 -0
  64. package/dist/chunk-7T3N2ZGQ.mjs +107 -0
  65. package/dist/chunk-7T3N2ZGQ.mjs.map +1 -0
  66. package/dist/chunk-7XA5VYYV.mjs +9 -0
  67. package/dist/chunk-7XA5VYYV.mjs.map +1 -0
  68. package/dist/chunk-B2DMAQNK.mjs +8 -0
  69. package/dist/chunk-B2DMAQNK.mjs.map +1 -0
  70. package/dist/chunk-B3YQVRPE.js +107 -0
  71. package/dist/chunk-B3YQVRPE.js.map +1 -0
  72. package/dist/chunk-DK3IYVMP.mjs +1 -0
  73. package/dist/chunk-DK3IYVMP.mjs.map +1 -0
  74. package/dist/chunk-DKSB4FMW.mjs +74 -0
  75. package/dist/chunk-DKSB4FMW.mjs.map +1 -0
  76. package/dist/chunk-F33RMB76.js +69 -0
  77. package/dist/chunk-F33RMB76.js.map +1 -0
  78. package/dist/chunk-FJH6DDEL.mjs +193 -0
  79. package/dist/chunk-FJH6DDEL.mjs.map +1 -0
  80. package/dist/chunk-FTY3BOF7.js +9 -0
  81. package/dist/chunk-FTY3BOF7.js.map +1 -0
  82. package/dist/chunk-GK4IJQVW.js +409 -0
  83. package/dist/chunk-GK4IJQVW.js.map +1 -0
  84. package/dist/chunk-GMC2A3D7.js +211 -0
  85. package/dist/chunk-GMC2A3D7.js.map +1 -0
  86. package/dist/chunk-GW5NQXN4.mjs +151 -0
  87. package/dist/chunk-GW5NQXN4.mjs.map +1 -0
  88. package/dist/chunk-H34N3OWO.mjs +169 -0
  89. package/dist/chunk-H34N3OWO.mjs.map +1 -0
  90. package/dist/chunk-H636DAOG.js +193 -0
  91. package/dist/chunk-H636DAOG.js.map +1 -0
  92. package/dist/chunk-HOTDTMNP.mjs +21 -0
  93. package/dist/chunk-HOTDTMNP.mjs.map +1 -0
  94. package/dist/chunk-HWFLO7W5.mjs +281 -0
  95. package/dist/chunk-HWFLO7W5.mjs.map +1 -0
  96. package/dist/chunk-I3BUOULW.js +18 -0
  97. package/dist/chunk-I3BUOULW.js.map +1 -0
  98. package/dist/chunk-IIDK6BRC.mjs +1 -0
  99. package/dist/chunk-IIDK6BRC.mjs.map +1 -0
  100. package/dist/chunk-IUNNN6HN.mjs +29 -0
  101. package/dist/chunk-IUNNN6HN.mjs.map +1 -0
  102. package/dist/chunk-IWENO6LT.js +20 -0
  103. package/dist/chunk-IWENO6LT.js.map +1 -0
  104. package/dist/chunk-JGMGNLZW.mjs +38 -0
  105. package/dist/chunk-JGMGNLZW.mjs.map +1 -0
  106. package/dist/chunk-JV7OA3FD.js +1 -0
  107. package/dist/chunk-JV7OA3FD.js.map +1 -0
  108. package/dist/chunk-KEXZDQAN.js +50 -0
  109. package/dist/chunk-KEXZDQAN.js.map +1 -0
  110. package/dist/chunk-KWQKGJSV.js +152 -0
  111. package/dist/chunk-KWQKGJSV.js.map +1 -0
  112. package/dist/chunk-LEFOMYX3.mjs +1 -0
  113. package/dist/chunk-LEFOMYX3.mjs.map +1 -0
  114. package/dist/chunk-LHIPBIPS.mjs +32 -0
  115. package/dist/chunk-LHIPBIPS.mjs.map +1 -0
  116. package/dist/chunk-LOW2T4MV.mjs +50 -0
  117. package/dist/chunk-LOW2T4MV.mjs.map +1 -0
  118. package/dist/chunk-MJABESWH.js +20 -0
  119. package/dist/chunk-MJABESWH.js.map +1 -0
  120. package/dist/chunk-MSUZTHYT.js +9 -0
  121. package/dist/chunk-MSUZTHYT.js.map +1 -0
  122. package/dist/chunk-MYSBDK36.mjs +1 -0
  123. package/dist/chunk-MYSBDK36.mjs.map +1 -0
  124. package/dist/chunk-N52KMB25.mjs +109 -0
  125. package/dist/chunk-N52KMB25.mjs.map +1 -0
  126. package/dist/chunk-O3XKEEJV.mjs +249 -0
  127. package/dist/chunk-O3XKEEJV.mjs.map +1 -0
  128. package/dist/chunk-O4PW77JW.mjs +1 -0
  129. package/dist/chunk-O4PW77JW.mjs.map +1 -0
  130. package/dist/chunk-OQSLMZJN.js +281 -0
  131. package/dist/chunk-OQSLMZJN.js.map +1 -0
  132. package/dist/chunk-P5V6S2PA.mjs +69 -0
  133. package/dist/chunk-P5V6S2PA.mjs.map +1 -0
  134. package/dist/chunk-PHUTP7NB.js +25 -0
  135. package/dist/chunk-PHUTP7NB.js.map +1 -0
  136. package/dist/chunk-Q5T57UNN.js +1 -0
  137. package/dist/chunk-Q5T57UNN.js.map +1 -0
  138. package/dist/chunk-Q7FGULTV.js +8 -0
  139. package/dist/chunk-Q7FGULTV.js.map +1 -0
  140. package/dist/chunk-QF3LHIJ5.mjs +9 -0
  141. package/dist/chunk-QF3LHIJ5.mjs.map +1 -0
  142. package/dist/chunk-QJTAFTW7.js +30 -0
  143. package/dist/chunk-QJTAFTW7.js.map +1 -0
  144. package/dist/chunk-QWEXXUTO.mjs +10 -0
  145. package/dist/chunk-QWEXXUTO.mjs.map +1 -0
  146. package/dist/chunk-QYFDFOWT.js +41 -0
  147. package/dist/chunk-QYFDFOWT.js.map +1 -0
  148. package/dist/chunk-R4BBIGBN.js +18 -0
  149. package/dist/chunk-R4BBIGBN.js.map +1 -0
  150. package/dist/chunk-R7UAMO2U.js +21 -0
  151. package/dist/chunk-R7UAMO2U.js.map +1 -0
  152. package/dist/chunk-RRPU7M4Y.js +29 -0
  153. package/dist/chunk-RRPU7M4Y.js.map +1 -0
  154. package/dist/chunk-RS5HE55U.js +109 -0
  155. package/dist/chunk-RS5HE55U.js.map +1 -0
  156. package/dist/chunk-TUAHXE75.mjs +21 -0
  157. package/dist/chunk-TUAHXE75.mjs.map +1 -0
  158. package/dist/chunk-TURGGK5F.mjs +59 -0
  159. package/dist/chunk-TURGGK5F.mjs.map +1 -0
  160. package/dist/chunk-UGQQ5DJ4.mjs +50 -0
  161. package/dist/chunk-UGQQ5DJ4.mjs.map +1 -0
  162. package/dist/chunk-VGWELVCX.mjs +18 -0
  163. package/dist/chunk-VGWELVCX.mjs.map +1 -0
  164. package/dist/chunk-VMUXXXJC.js +103 -0
  165. package/dist/chunk-VMUXXXJC.js.map +1 -0
  166. package/dist/chunk-WDGBH5CP.js +249 -0
  167. package/dist/chunk-WDGBH5CP.js.map +1 -0
  168. package/dist/chunk-WJOAEPZ7.js +30 -0
  169. package/dist/chunk-WJOAEPZ7.js.map +1 -0
  170. package/dist/chunk-XC5E26VE.mjs +20 -0
  171. package/dist/chunk-XC5E26VE.mjs.map +1 -0
  172. package/dist/chunk-XDEHYKW2.js +1 -0
  173. package/dist/chunk-XDEHYKW2.js.map +1 -0
  174. package/dist/chunk-XEY3KVEH.js +21 -0
  175. package/dist/chunk-XEY3KVEH.js.map +1 -0
  176. package/dist/chunk-XKXHM3PC.mjs +9 -0
  177. package/dist/chunk-XKXHM3PC.mjs.map +1 -0
  178. package/dist/chunk-XRGYWWT7.js +151 -0
  179. package/dist/chunk-XRGYWWT7.js.map +1 -0
  180. package/dist/chunk-XWFKTDB3.js +50 -0
  181. package/dist/chunk-XWFKTDB3.js.map +1 -0
  182. package/dist/chunk-Y3F7VUZB.mjs +409 -0
  183. package/dist/chunk-Y3F7VUZB.mjs.map +1 -0
  184. package/dist/chunk-YF4PGFCO.js +1 -0
  185. package/dist/chunk-YF4PGFCO.js.map +1 -0
  186. package/dist/chunk-YLT6CNSL.mjs +64 -0
  187. package/dist/chunk-YLT6CNSL.mjs.map +1 -0
  188. package/dist/chunk-Z4J4GUGG.mjs +152 -0
  189. package/dist/chunk-Z4J4GUGG.mjs.map +1 -0
  190. package/dist/chunk-ZLFA4R5X.js +56 -0
  191. package/dist/chunk-ZLFA4R5X.js.map +1 -0
  192. package/dist/chunk-ZRVOIW3H.js +74 -0
  193. package/dist/chunk-ZRVOIW3H.js.map +1 -0
  194. package/dist/chunk-ZVXX2CTH.mjs +95 -0
  195. package/dist/chunk-ZVXX2CTH.mjs.map +1 -0
  196. package/dist/chunk-ZXCNX3ZB.mjs +70 -0
  197. package/dist/chunk-ZXCNX3ZB.mjs.map +1 -0
  198. package/dist/cronjob.js +20 -0
  199. package/dist/cronjob.js.map +1 -0
  200. package/dist/cronjob.mjs +20 -0
  201. package/dist/cronjob.mjs.map +1 -0
  202. package/dist/deep-clone.js +8 -0
  203. package/dist/deep-clone.js.map +1 -0
  204. package/dist/deep-clone.mjs +8 -0
  205. package/dist/deep-clone.mjs.map +1 -0
  206. package/dist/default-endowments.js +8 -0
  207. package/dist/default-endowments.js.map +1 -0
  208. package/dist/default-endowments.mjs +8 -0
  209. package/dist/default-endowments.mjs.map +1 -0
  210. package/dist/derivation-paths.js +13 -0
  211. package/dist/derivation-paths.js.map +1 -0
  212. package/dist/derivation-paths.mjs +13 -0
  213. package/dist/derivation-paths.mjs.map +1 -0
  214. package/dist/entropy.js +10 -0
  215. package/dist/entropy.js.map +1 -0
  216. package/dist/entropy.mjs +10 -0
  217. package/dist/entropy.mjs.map +1 -0
  218. package/dist/errors.js +20 -0
  219. package/dist/errors.js.map +1 -0
  220. package/dist/errors.mjs +20 -0
  221. package/dist/errors.mjs.map +1 -0
  222. package/dist/eval-worker.js +43 -0
  223. package/dist/eval-worker.js.map +1 -0
  224. package/dist/eval-worker.mjs +43 -0
  225. package/dist/eval-worker.mjs.map +1 -0
  226. package/dist/eval.js +17 -0
  227. package/dist/eval.js.map +1 -0
  228. package/dist/eval.mjs +17 -0
  229. package/dist/eval.mjs.map +1 -0
  230. package/dist/fs.js +28 -0
  231. package/dist/fs.js.map +1 -0
  232. package/dist/fs.mjs +28 -0
  233. package/dist/fs.mjs.map +1 -0
  234. package/dist/handler-types.js +10 -0
  235. package/dist/handler-types.js.map +1 -0
  236. package/dist/handler-types.mjs +10 -0
  237. package/dist/handler-types.mjs.map +1 -0
  238. package/dist/handlers.js +35 -0
  239. package/dist/handlers.js.map +1 -0
  240. package/dist/handlers.mjs +35 -0
  241. package/dist/handlers.mjs.map +1 -0
  242. package/dist/icon.js +14 -0
  243. package/dist/icon.js.map +1 -0
  244. package/dist/icon.mjs +14 -0
  245. package/dist/icon.mjs.map +1 -0
  246. package/dist/iframe.js +8 -0
  247. package/dist/iframe.js.map +1 -0
  248. package/dist/iframe.mjs +8 -0
  249. package/dist/iframe.mjs.map +1 -0
  250. package/dist/index.executionenv.js +134 -0
  251. package/dist/index.executionenv.js.map +1 -0
  252. package/dist/index.executionenv.mjs +134 -0
  253. package/dist/index.executionenv.mjs.map +1 -0
  254. package/dist/index.js +378 -0
  255. package/dist/index.js.map +1 -0
  256. package/dist/index.mjs +378 -0
  257. package/dist/index.mjs.map +1 -0
  258. package/dist/json-rpc.js +18 -0
  259. package/dist/json-rpc.js.map +1 -0
  260. package/dist/json-rpc.mjs +18 -0
  261. package/dist/json-rpc.mjs.map +1 -0
  262. package/dist/json.js +8 -0
  263. package/dist/json.js.map +1 -0
  264. package/dist/json.mjs +8 -0
  265. package/dist/json.mjs.map +1 -0
  266. package/dist/localization.js +23 -0
  267. package/dist/localization.js.map +1 -0
  268. package/dist/localization.mjs +23 -0
  269. package/dist/localization.mjs.map +1 -0
  270. package/dist/logging.js +14 -0
  271. package/dist/logging.js.map +1 -0
  272. package/dist/logging.mjs +14 -0
  273. package/dist/logging.mjs.map +1 -0
  274. package/dist/manifest/index.js +59 -0
  275. package/dist/manifest/index.js.map +1 -0
  276. package/dist/manifest/index.mjs +59 -0
  277. package/dist/manifest/index.mjs.map +1 -0
  278. package/dist/manifest/manifest.js +42 -0
  279. package/dist/manifest/manifest.js.map +1 -0
  280. package/dist/manifest/manifest.mjs +42 -0
  281. package/dist/manifest/manifest.mjs.map +1 -0
  282. package/dist/manifest/node.js +85 -0
  283. package/dist/manifest/node.js.map +1 -0
  284. package/dist/manifest/node.mjs +85 -0
  285. package/dist/manifest/node.mjs.map +1 -0
  286. package/dist/manifest/validation.js +58 -0
  287. package/dist/manifest/validation.js.map +1 -0
  288. package/dist/manifest/validation.mjs +58 -0
  289. package/dist/manifest/validation.mjs.map +1 -0
  290. package/dist/mock.js +13 -0
  291. package/dist/mock.js.map +1 -0
  292. package/dist/mock.mjs +13 -0
  293. package/dist/mock.mjs.map +1 -0
  294. package/dist/namespace.js +44 -0
  295. package/dist/namespace.js.map +1 -0
  296. package/dist/namespace.mjs +44 -0
  297. package/dist/namespace.mjs.map +1 -0
  298. package/dist/node.js +448 -0
  299. package/dist/node.js.map +1 -0
  300. package/dist/node.mjs +448 -0
  301. package/dist/node.mjs.map +1 -0
  302. package/dist/npm.js +32 -0
  303. package/dist/npm.js.map +1 -0
  304. package/dist/npm.mjs +32 -0
  305. package/dist/npm.mjs.map +1 -0
  306. package/dist/path.js +8 -0
  307. package/dist/path.js.map +1 -0
  308. package/dist/path.mjs +8 -0
  309. package/dist/path.mjs.map +1 -0
  310. package/dist/post-process.js +10 -0
  311. package/dist/post-process.js.map +1 -0
  312. package/dist/post-process.mjs +10 -0
  313. package/dist/post-process.mjs.map +1 -0
  314. package/dist/snaps.js +48 -0
  315. package/dist/snaps.js.map +1 -0
  316. package/dist/snaps.mjs +48 -0
  317. package/dist/snaps.mjs.map +1 -0
  318. package/dist/strings.js +8 -0
  319. package/dist/strings.js.map +1 -0
  320. package/dist/strings.mjs +8 -0
  321. package/dist/strings.mjs.map +1 -0
  322. package/dist/structs.js +31 -0
  323. package/dist/structs.js.map +1 -0
  324. package/dist/structs.mjs +31 -0
  325. package/dist/structs.mjs.map +1 -0
  326. package/dist/tsconfig.build.tsbuildinfo +1 -0
  327. package/dist/types/bytes.d.ts +1 -1
  328. package/dist/types/checksum.d.ts +1 -1
  329. package/dist/types/icon.d.ts +16 -1
  330. package/dist/types/index.d.ts +1 -6
  331. package/dist/types/json-rpc.d.ts +1 -1
  332. package/dist/types/localization.d.ts +1 -1
  333. package/dist/types/manifest/index.d.ts +0 -1
  334. package/dist/types/manifest/manifest.d.ts +1 -1
  335. package/dist/types/manifest/node.d.ts +2 -0
  336. package/dist/types/manifest/validation.d.ts +5 -5
  337. package/dist/types/node.d.ts +8 -0
  338. package/dist/types/post-process.d.ts +1 -1
  339. package/dist/types/structs.d.ts +0 -20
  340. package/dist/types/ui.d.ts +7 -0
  341. package/dist/types/virtual-file/index.d.ts +0 -1
  342. package/dist/types/virtual-file/node.d.ts +2 -0
  343. package/dist/types.js +28 -0
  344. package/dist/types.js.map +1 -0
  345. package/dist/types.mjs +28 -0
  346. package/dist/types.mjs.map +1 -0
  347. package/dist/ui.js +12 -0
  348. package/dist/ui.js.map +1 -0
  349. package/dist/ui.mjs +12 -0
  350. package/dist/ui.mjs.map +1 -0
  351. package/dist/validation.js +24 -0
  352. package/dist/validation.js.map +1 -0
  353. package/dist/validation.mjs +24 -0
  354. package/dist/validation.mjs.map +1 -0
  355. package/dist/versions.js +12 -0
  356. package/dist/versions.js.map +1 -0
  357. package/dist/versions.mjs +12 -0
  358. package/dist/versions.mjs.map +1 -0
  359. package/dist/virtual-file/VirtualFile.js +9 -0
  360. package/dist/virtual-file/VirtualFile.js.map +1 -0
  361. package/dist/virtual-file/VirtualFile.mjs +9 -0
  362. package/dist/virtual-file/VirtualFile.mjs.map +1 -0
  363. package/dist/virtual-file/index.js +10 -0
  364. package/dist/virtual-file/index.js.map +1 -0
  365. package/dist/virtual-file/index.mjs +10 -0
  366. package/dist/virtual-file/index.mjs.map +1 -0
  367. package/dist/virtual-file/node.js +17 -0
  368. package/dist/virtual-file/node.js.map +1 -0
  369. package/dist/virtual-file/node.mjs +17 -0
  370. package/dist/virtual-file/node.mjs.map +1 -0
  371. package/dist/virtual-file/toVirtualFile.js +12 -0
  372. package/dist/virtual-file/toVirtualFile.js.map +1 -0
  373. package/dist/virtual-file/toVirtualFile.mjs +12 -0
  374. package/dist/virtual-file/toVirtualFile.mjs.map +1 -0
  375. package/package.json +24 -40
  376. package/dist/cjs/array.js +0 -23
  377. package/dist/cjs/array.js.map +0 -1
  378. package/dist/cjs/auxiliary-files.js +0 -27
  379. package/dist/cjs/auxiliary-files.js.map +0 -1
  380. package/dist/cjs/base64.js +0 -44
  381. package/dist/cjs/base64.js.map +0 -1
  382. package/dist/cjs/bytes.js +0 -23
  383. package/dist/cjs/bytes.js.map +0 -1
  384. package/dist/cjs/caveats.js +0 -48
  385. package/dist/cjs/caveats.js.map +0 -1
  386. package/dist/cjs/checksum.js +0 -43
  387. package/dist/cjs/checksum.js.map +0 -1
  388. package/dist/cjs/cronjob.js +0 -77
  389. package/dist/cjs/cronjob.js.map +0 -1
  390. package/dist/cjs/deep-clone.js +0 -22
  391. package/dist/cjs/deep-clone.js.map +0 -1
  392. package/dist/cjs/default-endowments.js +0 -49
  393. package/dist/cjs/default-endowments.js.map +0 -1
  394. package/dist/cjs/derivation-paths.js +0 -300
  395. package/dist/cjs/derivation-paths.js.map +0 -1
  396. package/dist/cjs/entropy.js +0 -23
  397. package/dist/cjs/entropy.js.map +0 -1
  398. package/dist/cjs/errors.js +0 -221
  399. package/dist/cjs/errors.js.map +0 -1
  400. package/dist/cjs/eval-worker.js +0 -44
  401. package/dist/cjs/eval-worker.js.map +0 -1
  402. package/dist/cjs/eval.js +0 -77
  403. package/dist/cjs/eval.js.map +0 -1
  404. package/dist/cjs/fs.js +0 -126
  405. package/dist/cjs/fs.js.map +0 -1
  406. package/dist/cjs/handler-types.js +0 -34
  407. package/dist/cjs/handler-types.js.map +0 -1
  408. package/dist/cjs/handlers.js +0 -173
  409. package/dist/cjs/handlers.js.map +0 -1
  410. package/dist/cjs/icon.js +0 -37
  411. package/dist/cjs/icon.js.map +0 -1
  412. package/dist/cjs/iframe.js +0 -59
  413. package/dist/cjs/iframe.js.map +0 -1
  414. package/dist/cjs/index.browser.js +0 -49
  415. package/dist/cjs/index.browser.js.map +0 -1
  416. package/dist/cjs/index.executionenv.js +0 -27
  417. package/dist/cjs/index.executionenv.js.map +0 -1
  418. package/dist/cjs/index.js +0 -54
  419. package/dist/cjs/index.js.map +0 -1
  420. package/dist/cjs/json-rpc.js +0 -81
  421. package/dist/cjs/json-rpc.js.map +0 -1
  422. package/dist/cjs/json.js +0 -16
  423. package/dist/cjs/json.js.map +0 -1
  424. package/dist/cjs/localization.js +0 -113
  425. package/dist/cjs/localization.js.map +0 -1
  426. package/dist/cjs/logging.js +0 -40
  427. package/dist/cjs/logging.js.map +0 -1
  428. package/dist/cjs/manifest/index.browser.js +0 -20
  429. package/dist/cjs/manifest/index.browser.js.map +0 -1
  430. package/dist/cjs/manifest/index.js +0 -21
  431. package/dist/cjs/manifest/index.js.map +0 -1
  432. package/dist/cjs/manifest/manifest.js +0 -275
  433. package/dist/cjs/manifest/manifest.js.map +0 -1
  434. package/dist/cjs/manifest/validation.js +0 -244
  435. package/dist/cjs/manifest/validation.js.map +0 -1
  436. package/dist/cjs/mock.js +0 -128
  437. package/dist/cjs/mock.js.map +0 -1
  438. package/dist/cjs/namespace.js +0 -136
  439. package/dist/cjs/namespace.js.map +0 -1
  440. package/dist/cjs/npm.js +0 -96
  441. package/dist/cjs/npm.js.map +0 -1
  442. package/dist/cjs/path.js +0 -21
  443. package/dist/cjs/path.js.map +0 -1
  444. package/dist/cjs/post-process.js +0 -328
  445. package/dist/cjs/post-process.js.map +0 -1
  446. package/dist/cjs/snaps.js +0 -232
  447. package/dist/cjs/snaps.js.map +0 -1
  448. package/dist/cjs/strings.js +0 -21
  449. package/dist/cjs/strings.js.map +0 -1
  450. package/dist/cjs/structs.js +0 -210
  451. package/dist/cjs/structs.js.map +0 -1
  452. package/dist/cjs/types.js +0 -104
  453. package/dist/cjs/types.js.map +0 -1
  454. package/dist/cjs/ui.js +0 -53
  455. package/dist/cjs/ui.js.map +0 -1
  456. package/dist/cjs/validation.js +0 -24
  457. package/dist/cjs/validation.js.map +0 -1
  458. package/dist/cjs/versions.js +0 -47
  459. package/dist/cjs/versions.js.map +0 -1
  460. package/dist/cjs/virtual-file/VirtualFile.js +0 -92
  461. package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
  462. package/dist/cjs/virtual-file/index.browser.js +0 -20
  463. package/dist/cjs/virtual-file/index.browser.js.map +0 -1
  464. package/dist/cjs/virtual-file/index.js +0 -21
  465. package/dist/cjs/virtual-file/index.js.map +0 -1
  466. package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
  467. package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
  468. package/dist/esm/array.js +0 -13
  469. package/dist/esm/array.js.map +0 -1
  470. package/dist/esm/auxiliary-files.js +0 -23
  471. package/dist/esm/auxiliary-files.js.map +0 -1
  472. package/dist/esm/base64.js +0 -36
  473. package/dist/esm/base64.js.map +0 -1
  474. package/dist/esm/bytes.js +0 -18
  475. package/dist/esm/bytes.js.map +0 -1
  476. package/dist/esm/caveats.js +0 -38
  477. package/dist/esm/caveats.js.map +0 -1
  478. package/dist/esm/checksum.js +0 -41
  479. package/dist/esm/checksum.js.map +0 -1
  480. package/dist/esm/cronjob.js +0 -59
  481. package/dist/esm/cronjob.js.map +0 -1
  482. package/dist/esm/deep-clone.js +0 -7
  483. package/dist/esm/deep-clone.js.map +0 -1
  484. package/dist/esm/default-endowments.js +0 -39
  485. package/dist/esm/default-endowments.js.map +0 -1
  486. package/dist/esm/derivation-paths.js +0 -287
  487. package/dist/esm/derivation-paths.js.map +0 -1
  488. package/dist/esm/entropy.js +0 -6
  489. package/dist/esm/entropy.js.map +0 -1
  490. package/dist/esm/errors.js +0 -211
  491. package/dist/esm/errors.js.map +0 -1
  492. package/dist/esm/eval-worker.js +0 -40
  493. package/dist/esm/eval-worker.js.map +0 -1
  494. package/dist/esm/eval.js +0 -65
  495. package/dist/esm/eval.js.map +0 -1
  496. package/dist/esm/fs.js +0 -136
  497. package/dist/esm/fs.js.map +0 -1
  498. package/dist/esm/handler-types.js +0 -16
  499. package/dist/esm/handler-types.js.map +0 -1
  500. package/dist/esm/handlers.js +0 -119
  501. package/dist/esm/handlers.js.map +0 -1
  502. package/dist/esm/icon.js +0 -11
  503. package/dist/esm/icon.js.map +0 -1
  504. package/dist/esm/iframe.js +0 -49
  505. package/dist/esm/iframe.js.map +0 -1
  506. package/dist/esm/index.browser.js +0 -32
  507. package/dist/esm/index.browser.js.map +0 -1
  508. package/dist/esm/index.executionenv.js +0 -10
  509. package/dist/esm/index.executionenv.js.map +0 -1
  510. package/dist/esm/index.js +0 -37
  511. package/dist/esm/index.js.map +0 -1
  512. package/dist/esm/json-rpc.js +0 -79
  513. package/dist/esm/json-rpc.js.map +0 -1
  514. package/dist/esm/json.js +0 -17
  515. package/dist/esm/json.js.map +0 -1
  516. package/dist/esm/localization.js +0 -115
  517. package/dist/esm/localization.js.map +0 -1
  518. package/dist/esm/logging.js +0 -59
  519. package/dist/esm/logging.js.map +0 -1
  520. package/dist/esm/manifest/index.browser.js +0 -3
  521. package/dist/esm/manifest/index.browser.js.map +0 -1
  522. package/dist/esm/manifest/index.js +0 -4
  523. package/dist/esm/manifest/index.js.map +0 -1
  524. package/dist/esm/manifest/manifest.js +0 -299
  525. package/dist/esm/manifest/manifest.js.map +0 -1
  526. package/dist/esm/manifest/validation.js +0 -190
  527. package/dist/esm/manifest/validation.js.map +0 -1
  528. package/dist/esm/mock.js +0 -111
  529. package/dist/esm/mock.js.map +0 -1
  530. package/dist/esm/namespace.js +0 -113
  531. package/dist/esm/namespace.js.map +0 -1
  532. package/dist/esm/npm.js +0 -85
  533. package/dist/esm/npm.js.map +0 -1
  534. package/dist/esm/path.js +0 -17
  535. package/dist/esm/path.js.map +0 -1
  536. package/dist/esm/post-process.js +0 -333
  537. package/dist/esm/post-process.js.map +0 -1
  538. package/dist/esm/snaps.js +0 -217
  539. package/dist/esm/snaps.js.map +0 -1
  540. package/dist/esm/strings.js +0 -11
  541. package/dist/esm/strings.js.map +0 -1
  542. package/dist/esm/structs.js +0 -295
  543. package/dist/esm/structs.js.map +0 -1
  544. package/dist/esm/types.js +0 -78
  545. package/dist/esm/types.js.map +0 -1
  546. package/dist/esm/ui.js +0 -50
  547. package/dist/esm/ui.js.map +0 -1
  548. package/dist/esm/validation.js +0 -19
  549. package/dist/esm/validation.js.map +0 -1
  550. package/dist/esm/versions.js +0 -41
  551. package/dist/esm/versions.js.map +0 -1
  552. package/dist/esm/virtual-file/VirtualFile.js +0 -82
  553. package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
  554. package/dist/esm/virtual-file/index.browser.js +0 -3
  555. package/dist/esm/virtual-file/index.browser.js.map +0 -1
  556. package/dist/esm/virtual-file/index.js +0 -4
  557. package/dist/esm/virtual-file/index.js.map +0 -1
  558. package/dist/esm/virtual-file/toVirtualFile.js +0 -26
  559. package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
  560. package/dist/types/index.browser.d.ts +0 -30
  561. package/dist/types/manifest/index.browser.d.ts +0 -1
  562. package/dist/types/virtual-file/index.browser.d.ts +0 -1
@@ -0,0 +1,69 @@
1
+ import {
2
+ DEFAULT_ENDOWMENTS
3
+ } from "./chunk-3ZSMMNQB.mjs";
4
+
5
+ // src/mock.ts
6
+ import crypto from "crypto";
7
+ import EventEmitter from "events";
8
+ var NETWORK_APIS = ["fetch", "Request", "Headers", "Response"];
9
+ var ALL_APIS = [
10
+ ...DEFAULT_ENDOWMENTS,
11
+ ...NETWORK_APIS,
12
+ "WebAssembly"
13
+ ];
14
+ function getMockSnapGlobal() {
15
+ return { request: async () => true };
16
+ }
17
+ function getMockEthereumProvider() {
18
+ const mockProvider = new EventEmitter();
19
+ mockProvider.request = async () => true;
20
+ return mockProvider;
21
+ }
22
+ var isConstructor = (value) => Boolean(typeof value?.prototype?.constructor?.name === "string");
23
+ var mockFunction = () => true;
24
+ var MockClass = class {
25
+ };
26
+ var handler = {
27
+ // eslint-disable-next-line @typescript-eslint/naming-convention
28
+ construct(Target, args) {
29
+ return new Proxy(new Target(...args), handler);
30
+ },
31
+ get(_target, _prop) {
32
+ return mockFunction;
33
+ }
34
+ };
35
+ var generateMockClass = (value) => {
36
+ return new Proxy(value, handler);
37
+ };
38
+ var mockWindow = {
39
+ crypto,
40
+ SubtleCrypto: MockClass
41
+ };
42
+ var generateMockEndowment = (key) => {
43
+ const globalValue = globalThis[key];
44
+ if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {
45
+ return globalValue;
46
+ }
47
+ const globalOrMocked = globalValue ?? mockWindow[key];
48
+ const type = typeof globalOrMocked;
49
+ const isFunction = type === "function";
50
+ if (isFunction && isConstructor(globalOrMocked)) {
51
+ return generateMockClass(globalOrMocked);
52
+ } else if (isFunction || !globalOrMocked) {
53
+ return mockFunction;
54
+ }
55
+ return globalOrMocked;
56
+ };
57
+ var generateMockEndowments = () => {
58
+ return ALL_APIS.reduce(
59
+ (acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),
60
+ { snap: getMockSnapGlobal(), ethereum: getMockEthereumProvider() }
61
+ );
62
+ };
63
+
64
+ export {
65
+ ALL_APIS,
66
+ isConstructor,
67
+ generateMockEndowments
68
+ };
69
+ //# sourceMappingURL=chunk-P5V6S2PA.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/mock.ts"],"sourcesContent":["import crypto from 'crypto';\nimport EventEmitter from 'events';\n\nimport { DEFAULT_ENDOWMENTS } from './default-endowments';\n\nconst NETWORK_APIS = ['fetch', 'Request', 'Headers', 'Response'];\n\nexport const ALL_APIS: string[] = [\n ...DEFAULT_ENDOWMENTS,\n ...NETWORK_APIS,\n 'WebAssembly',\n];\n\ntype MockSnapGlobal = {\n request: () => Promise<any>;\n};\n\ntype MockEthereumProvider = EventEmitter & {\n request: () => Promise<any>;\n};\n\n/**\n * Get a mock snap API, that always returns `true` for requests.\n *\n * @returns A mocked snap provider.\n */\nfunction getMockSnapGlobal(): MockSnapGlobal {\n // eslint-disable-next-line @typescript-eslint/require-await\n return { request: async () => true };\n}\n\n/**\n * Get a mock Ethereum provider, that always returns `true` for requests.\n *\n * @returns A mocked ethereum provider.\n */\nfunction getMockEthereumProvider(): MockEthereumProvider {\n const mockProvider = new EventEmitter() as Partial<MockEthereumProvider>;\n // eslint-disable-next-line @typescript-eslint/require-await\n mockProvider.request = async () => true;\n return mockProvider as MockEthereumProvider;\n}\n\n/**\n * Check if a value is a constructor.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nexport const isConstructor = (value: any) =>\n Boolean(typeof value?.prototype?.constructor?.name === 'string');\n\n/**\n * A function that always returns `true`.\n *\n * @returns `true`.\n */\nconst mockFunction = () => true;\nclass MockClass {}\n\nconst handler = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n construct(Target: any, args: any[]): any {\n return new Proxy(new Target(...args), handler);\n },\n get(_target: any, _prop: any) {\n return mockFunction;\n },\n};\n\n/**\n * Generate a mock class for a given value. The value is wrapped in a Proxy, and\n * all methods are replaced with a mock function.\n *\n * @param value - The value to mock.\n * @returns A mock class.\n */\nconst generateMockClass = (value: any) => {\n return new Proxy(value, handler);\n};\n\n// Things not currently auto-mocked because of NodeJS, by adding them here we\n// have types for them and can use that to generate mocks if needed.\nconst mockWindow: Record<string, unknown> = {\n crypto,\n SubtleCrypto: MockClass,\n};\n\n/**\n * Generate a mock endowment for a certain class or function on the `globalThis`\n * object.\n *\n * @param key - The key to generate the mock endowment for.\n * @returns A mocked class or function. If the key is part of the default\n * endowments, the original value is returned.\n */\nconst generateMockEndowment = (key: string) => {\n const globalValue = (globalThis as any)[key];\n\n // Default exposed APIs don't need to be mocked\n if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {\n return globalValue;\n }\n\n // Fall back to mockWindow for certain APIs not exposed in global in Node.JS\n const globalOrMocked = globalValue ?? mockWindow[key];\n\n const type = typeof globalOrMocked;\n const isFunction = type === 'function';\n if (isFunction && isConstructor(globalOrMocked)) {\n return generateMockClass(globalOrMocked);\n } else if (isFunction || !globalOrMocked) {\n // Fall back to function mock for now\n return mockFunction;\n }\n return globalOrMocked;\n};\n\n/**\n * Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.\n *\n * @returns A map of endowments.\n */\nexport const generateMockEndowments = () => {\n return ALL_APIS.reduce<Record<string, any>>(\n (acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),\n { snap: getMockSnapGlobal(), ethereum: getMockEthereumProvider() },\n );\n};\n"],"mappings":";;;;;AAAA,OAAO,YAAY;AACnB,OAAO,kBAAkB;AAIzB,IAAM,eAAe,CAAC,SAAS,WAAW,WAAW,UAAU;AAExD,IAAM,WAAqB;AAAA,EAChC,GAAG;AAAA,EACH,GAAG;AAAA,EACH;AACF;AAeA,SAAS,oBAAoC;AAE3C,SAAO,EAAE,SAAS,YAAY,KAAK;AACrC;AAOA,SAAS,0BAAgD;AACvD,QAAM,eAAe,IAAI,aAAa;AAEtC,eAAa,UAAU,YAAY;AACnC,SAAO;AACT;AAQO,IAAM,gBAAgB,CAAC,UAC5B,QAAQ,OAAO,OAAO,WAAW,aAAa,SAAS,QAAQ;AAOjE,IAAM,eAAe,MAAM;AAC3B,IAAM,YAAN,MAAgB;AAAC;AAEjB,IAAM,UAAU;AAAA;AAAA,EAEd,UAAU,QAAa,MAAkB;AACvC,WAAO,IAAI,MAAM,IAAI,OAAO,GAAG,IAAI,GAAG,OAAO;AAAA,EAC/C;AAAA,EACA,IAAI,SAAc,OAAY;AAC5B,WAAO;AAAA,EACT;AACF;AASA,IAAM,oBAAoB,CAAC,UAAe;AACxC,SAAO,IAAI,MAAM,OAAO,OAAO;AACjC;AAIA,IAAM,aAAsC;AAAA,EAC1C;AAAA,EACA,cAAc;AAChB;AAUA,IAAM,wBAAwB,CAAC,QAAgB;AAC7C,QAAM,cAAe,WAAmB,GAAG;AAG3C,MAAI,eAAe,mBAAmB,SAAS,GAAG,GAAG;AACnD,WAAO;AAAA,EACT;AAGA,QAAM,iBAAiB,eAAe,WAAW,GAAG;AAEpD,QAAM,OAAO,OAAO;AACpB,QAAM,aAAa,SAAS;AAC5B,MAAI,cAAc,cAAc,cAAc,GAAG;AAC/C,WAAO,kBAAkB,cAAc;AAAA,EACzC,WAAW,cAAc,CAAC,gBAAgB;AAExC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAOO,IAAM,yBAAyB,MAAM;AAC1C,SAAO,SAAS;AAAA,IACd,CAAC,KAAK,SAAS,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,sBAAsB,GAAG,EAAE;AAAA,IAC3D,EAAE,MAAM,kBAAkB,GAAG,UAAU,wBAAwB,EAAE;AAAA,EACnE;AACF;","names":[]}
@@ -0,0 +1,25 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __accessCheck = (obj, member, msg) => {
2
+ if (!member.has(obj))
3
+ throw TypeError("Cannot " + msg);
4
+ };
5
+ var __privateGet = (obj, member, getter) => {
6
+ __accessCheck(obj, member, "read from private field");
7
+ return getter ? getter.call(obj) : member.get(obj);
8
+ };
9
+ var __privateAdd = (obj, member, value) => {
10
+ if (member.has(obj))
11
+ throw TypeError("Cannot add the same private member more than once");
12
+ member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
13
+ };
14
+ var __privateSet = (obj, member, value, setter) => {
15
+ __accessCheck(obj, member, "write to private field");
16
+ setter ? setter.call(obj, value) : member.set(obj, value);
17
+ return value;
18
+ };
19
+
20
+
21
+
22
+
23
+
24
+ exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet;
25
+ //# sourceMappingURL=chunk-PHUTP7NB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1 @@
1
+ "use strict";//# sourceMappingURL=chunk-Q5T57UNN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,8 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }// src/deep-clone.ts
2
+ var _rfdc = require('rfdc'); var _rfdc2 = _interopRequireDefault(_rfdc);
3
+ var deepClone = _rfdc2.default.call(void 0, { proto: false, circles: false });
4
+
5
+
6
+
7
+ exports.deepClone = deepClone;
8
+ //# sourceMappingURL=chunk-Q7FGULTV.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/deep-clone.ts"],"names":[],"mappings":";AAAA,OAAO,UAAU;AAEV,IAAM,YAAY,KAAK,EAAE,OAAO,OAAO,SAAS,MAAM,CAAC","sourcesContent":["import rfdc from 'rfdc';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n"]}
@@ -0,0 +1,9 @@
1
+ // src/entropy.ts
2
+ var SIP_6_MAGIC_VALUE = `1399742832'`;
3
+ var STATE_ENCRYPTION_MAGIC_VALUE = `572232532'`;
4
+
5
+ export {
6
+ SIP_6_MAGIC_VALUE,
7
+ STATE_ENCRYPTION_MAGIC_VALUE
8
+ };
9
+ //# sourceMappingURL=chunk-QF3LHIJ5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/entropy.ts"],"sourcesContent":["// 0xd36e6170 - 0x80000000\nexport const SIP_6_MAGIC_VALUE = `1399742832'` as `${number}'`;\n\n// `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`\nexport const STATE_ENCRYPTION_MAGIC_VALUE = `572232532'` as `${number}'`;\n\nexport type MagicValue =\n | typeof SIP_6_MAGIC_VALUE\n | typeof STATE_ENCRYPTION_MAGIC_VALUE;\n"],"mappings":";AACO,IAAM,oBAAoB;AAG1B,IAAM,+BAA+B;","names":[]}
@@ -0,0 +1,30 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkOQSLMZJNjs = require('./chunk-OQSLMZJN.js');
4
+
5
+
6
+ var _chunkH636DAOGjs = require('./chunk-H636DAOG.js');
7
+
8
+
9
+ var _chunkKEXZDQANjs = require('./chunk-KEXZDQAN.js');
10
+
11
+
12
+ var _chunkRS5HE55Ujs = require('./chunk-RS5HE55U.js');
13
+
14
+ // src/validation.ts
15
+ async function validateFetchedSnap(files) {
16
+ _chunkOQSLMZJNjs.assertIsSnapManifest.call(void 0, files.manifest.result);
17
+ await _chunkH636DAOGjs.validateSnapShasum.call(void 0, files);
18
+ _chunkRS5HE55Ujs.validateSnapManifestLocalizations.call(void 0,
19
+ files.manifest.result,
20
+ files.localizationFiles.map((file) => file.result)
21
+ );
22
+ if (files.svgIcon) {
23
+ _chunkKEXZDQANjs.assertIsSnapIcon.call(void 0, files.svgIcon);
24
+ }
25
+ }
26
+
27
+
28
+
29
+ exports.validateFetchedSnap = validateFetchedSnap;
30
+ //# sourceMappingURL=chunk-QJTAFTW7.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/validation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAYA,eAAsB,oBACpB,OACe;AACf,uBAAqB,MAAM,SAAS,MAAM;AAC1C,QAAM,mBAAmB,KAAK;AAC9B;AAAA,IACE,MAAM,SAAS;AAAA,IACf,MAAM,kBAAkB,IAAI,CAAC,SAAS,KAAK,MAAM;AAAA,EACnD;AAEA,MAAI,MAAM,SAAS;AACjB,qBAAiB,MAAM,OAAO;AAAA,EAChC;AACF","sourcesContent":["import { assertIsSnapIcon } from './icon';\nimport { validateSnapManifestLocalizations } from './localization';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport { validateSnapShasum } from './snaps';\nimport type { FetchedSnapFiles } from './types';\n\n/**\n * Validates the files contained in a fetched snap.\n *\n * @param files - All potentially included files in a fetched snap.\n * @throws If any of the files are considered invalid.\n */\nexport async function validateFetchedSnap(\n files: FetchedSnapFiles,\n): Promise<void> {\n assertIsSnapManifest(files.manifest.result);\n await validateSnapShasum(files);\n validateSnapManifestLocalizations(\n files.manifest.result,\n files.localizationFiles.map((file) => file.result),\n );\n\n if (files.svgIcon) {\n assertIsSnapIcon(files.svgIcon);\n }\n}\n"]}
@@ -0,0 +1,10 @@
1
+ // src/json.ts
2
+ import { getSafeJson } from "@metamask/utils";
3
+ function parseJson(json) {
4
+ return getSafeJson(JSON.parse(json));
5
+ }
6
+
7
+ export {
8
+ parseJson
9
+ };
10
+ //# sourceMappingURL=chunk-QWEXXUTO.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/json.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n"],"mappings":";AACA,SAAS,mBAAmB;AAerB,SAAS,UAAoC,MAAc;AAChE,SAAO,YAAkB,KAAK,MAAM,IAAI,CAAC;AAC3C;","names":[]}
@@ -0,0 +1,41 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/default-endowments.ts
2
+ var DEFAULT_ENDOWMENTS = Object.freeze([
3
+ "atob",
4
+ "btoa",
5
+ "BigInt",
6
+ "console",
7
+ "crypto",
8
+ "Date",
9
+ "Math",
10
+ "setTimeout",
11
+ "clearTimeout",
12
+ "SubtleCrypto",
13
+ "TextDecoder",
14
+ "TextEncoder",
15
+ "URL",
16
+ "setInterval",
17
+ "clearInterval",
18
+ "Int8Array",
19
+ "Uint8Array",
20
+ "Uint8ClampedArray",
21
+ "Int16Array",
22
+ "Uint16Array",
23
+ "Int32Array",
24
+ "Uint32Array",
25
+ "Float32Array",
26
+ "Float64Array",
27
+ "BigInt64Array",
28
+ "BigUint64Array",
29
+ "DataView",
30
+ "ArrayBuffer",
31
+ // Used by fetch, but also as API for some packages that don't do network connections
32
+ // https://github.com/MetaMask/snaps-monorepo/issues/662
33
+ // https://github.com/MetaMask/snaps-monorepo/discussions/678
34
+ "AbortController",
35
+ "AbortSignal"
36
+ ]);
37
+
38
+
39
+
40
+ exports.DEFAULT_ENDOWMENTS = DEFAULT_ENDOWMENTS;
41
+ //# sourceMappingURL=chunk-QYFDFOWT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/default-endowments.ts"],"names":[],"mappings":";AAGO,IAAM,qBAAwC,OAAO,OAAO;AAAA,EACjE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA,EACA;AACF,CAAC","sourcesContent":["/**\n * Global JavaScript APIs exposed by default to all snaps.\n */\nexport const DEFAULT_ENDOWMENTS: readonly string[] = Object.freeze([\n 'atob',\n 'btoa',\n 'BigInt',\n 'console',\n 'crypto',\n 'Date',\n 'Math',\n 'setTimeout',\n 'clearTimeout',\n 'SubtleCrypto',\n 'TextDecoder',\n 'TextEncoder',\n 'URL',\n 'setInterval',\n 'clearInterval',\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n 'ArrayBuffer',\n // Used by fetch, but also as API for some packages that don't do network connections\n // https://github.com/MetaMask/snaps-monorepo/issues/662\n // https://github.com/MetaMask/snaps-monorepo/discussions/678\n 'AbortController',\n 'AbortSignal',\n]);\n"]}
@@ -0,0 +1,18 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkXWFKTDB3js = require('./chunk-XWFKTDB3.js');
4
+
5
+ // src/bytes.ts
6
+ var _utils = require('@metamask/utils');
7
+ function getBytes(bytes) {
8
+ const unwrapped = bytes instanceof _chunkXWFKTDB3js.VirtualFile ? bytes.value : bytes;
9
+ if (typeof unwrapped === "string") {
10
+ return _utils.stringToBytes.call(void 0, unwrapped);
11
+ }
12
+ return unwrapped;
13
+ }
14
+
15
+
16
+
17
+ exports.getBytes = getBytes;
18
+ //# sourceMappingURL=chunk-R4BBIGBN.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bytes.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,qBAAqB;AAUvB,SAAS,SAAS,OAAsD;AAG7E,QAAM,YAAY,iBAAiB,cAAc,MAAM,QAAQ;AAE/D,MAAI,OAAO,cAAc,UAAU;AACjC,WAAO,cAAc,SAAS;AAAA,EAChC;AAEA,SAAO;AACT","sourcesContent":["import { stringToBytes } from '@metamask/utils';\n\nimport { VirtualFile } from './virtual-file/VirtualFile';\n\n/**\n * Convert a bytes-like input value to a Uint8Array.\n *\n * @param bytes - A bytes-like value.\n * @returns The input value converted to a Uint8Array if necessary.\n */\nexport function getBytes(bytes: VirtualFile | Uint8Array | string): Uint8Array {\n // Unwrap VirtualFiles to extract the content\n // The content is then either a string or Uint8Array\n const unwrapped = bytes instanceof VirtualFile ? bytes.value : bytes;\n\n if (typeof unwrapped === 'string') {\n return stringToBytes(unwrapped);\n }\n\n return unwrapped;\n}\n"]}
@@ -0,0 +1,21 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkXWFKTDB3js = require('./chunk-XWFKTDB3.js');
4
+
5
+ // src/virtual-file/toVirtualFile.ts
6
+ var _fs = require('fs');
7
+ async function readVirtualFile(path, encoding = null) {
8
+ return new (0, _chunkXWFKTDB3js.VirtualFile)({
9
+ path,
10
+ value: await _fs.promises.readFile(path, { encoding })
11
+ });
12
+ }
13
+ async function writeVirtualFile(vfile, options) {
14
+ return _fs.promises.writeFile(vfile.path, vfile.value, options);
15
+ }
16
+
17
+
18
+
19
+
20
+ exports.readVirtualFile = readVirtualFile; exports.writeVirtualFile = writeVirtualFile;
21
+ //# sourceMappingURL=chunk-R7UAMO2U.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/virtual-file/toVirtualFile.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,YAAY,kBAAkB;AAWvC,eAAsB,gBACpB,MACA,WAAkC,MAClC;AACA,SAAO,IAAI,YAAY;AAAA,IACrB;AAAA,IACA,OAAO,MAAM,WAAW,SAAS,MAAM,EAAE,SAAS,CAAC;AAAA,EACrD,CAAC;AACH;AAaA,eAAsB,iBACpB,OACA,SACA;AACA,SAAO,WAAW,UAAU,MAAM,MAAM,MAAM,OAAO,OAAO;AAC9D","sourcesContent":["import { promises as fsPromises } from 'fs';\n\nimport { VirtualFile } from './VirtualFile';\n\n/**\n * Reads a file from filesystem and creates a vfile.\n *\n * @param path - Filesystem path to load the contents from.\n * @param encoding - Optional encoding to pass down to fs.readFile.\n * @returns Promise returning VFile with loaded file contents.\n */\nexport async function readVirtualFile(\n path: string,\n encoding: BufferEncoding | null = null,\n) {\n return new VirtualFile({\n path,\n value: await fsPromises.readFile(path, { encoding }),\n });\n}\n\ntype WriteVFileOptions = Exclude<\n Parameters<(typeof fsPromises)['writeFile']>[2],\n undefined\n>;\n\n/**\n * Writes vfile to filesystem.\n *\n * @param vfile - The vfile to write.\n * @param options - Options to pass down to fs.writeFile.\n */\nexport async function writeVirtualFile(\n vfile: VirtualFile,\n options?: WriteVFileOptions,\n) {\n return fsPromises.writeFile(vfile.path, vfile.value, options);\n}\n"]}
@@ -0,0 +1,29 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/iframe.ts
2
+ async function createWindow(uri, id, sandbox = true) {
3
+ return await new Promise((resolve, reject) => {
4
+ const iframe = document.createElement("iframe");
5
+ iframe.setAttribute("id", id);
6
+ iframe.setAttribute("data-testid", "snaps-iframe");
7
+ if (sandbox) {
8
+ iframe.setAttribute("sandbox", "allow-scripts");
9
+ }
10
+ iframe.setAttribute("src", uri);
11
+ document.body.appendChild(iframe);
12
+ iframe.addEventListener("load", () => {
13
+ if (iframe.contentWindow) {
14
+ resolve(iframe.contentWindow);
15
+ } else {
16
+ reject(
17
+ new Error(
18
+ `iframe.contentWindow not present on load for job "${id}".`
19
+ )
20
+ );
21
+ }
22
+ });
23
+ });
24
+ }
25
+
26
+
27
+
28
+ exports.createWindow = createWindow;
29
+ //# sourceMappingURL=chunk-RRPU7M4Y.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/iframe.ts"],"names":[],"mappings":";AAUA,eAAsB,aACpB,KACA,IACA,UAAU,MACO;AACjB,SAAO,MAAM,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC5C,UAAM,SAAS,SAAS,cAAc,QAAQ;AAG9C,WAAO,aAAa,MAAM,EAAE;AAC5B,WAAO,aAAa,eAAe,cAAc;AAEjD,QAAI,SAAS;AAKX,aAAO,aAAa,WAAW,eAAe;AAAA,IAChD;AAaA,WAAO,aAAa,OAAO,GAAG;AAC9B,aAAS,KAAK,YAAY,MAAM;AAEhC,WAAO,iBAAiB,QAAQ,MAAM;AACpC,UAAI,OAAO,eAAe;AACxB,gBAAQ,OAAO,aAAa;AAAA,MAC9B,OAAO;AAGL;AAAA,UACE,IAAI;AAAA,YACF,qDAAqD,EAAE;AAAA,UACzD;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n * @param uri - The iframe URI.\n * @param id - The ID to assign to the iframe.\n * @param sandbox - Whether to enable the sandbox attribute.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow(\n uri: string,\n id: string,\n sandbox = true,\n): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', 'snaps-iframe');\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n });\n });\n}\n"]}
@@ -0,0 +1,109 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk6H32HLTZjs = require('./chunk-6H32HLTZ.js');
4
+
5
+ // src/localization.ts
6
+ var _snapssdk = require('@metamask/snaps-sdk');
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+ var _superstruct = require('superstruct');
15
+ var LOCALIZABLE_FIELDS = ["description", "proposedName"];
16
+ var LocalizationFileStruct = _superstruct.object.call(void 0, {
17
+ locale: _superstruct.string.call(void 0, ),
18
+ messages: _superstruct.record.call(void 0,
19
+ _superstruct.string.call(void 0, ),
20
+ _superstruct.object.call(void 0, {
21
+ message: _superstruct.string.call(void 0, ),
22
+ description: _superstruct.optional.call(void 0, _superstruct.string.call(void 0, ))
23
+ })
24
+ )
25
+ });
26
+ function getValidatedLocalizationFiles(localizationFiles) {
27
+ for (const file of localizationFiles) {
28
+ try {
29
+ file.result = _superstruct.create.call(void 0, _chunk6H32HLTZjs.parseJson.call(void 0, file.toString()), LocalizationFileStruct);
30
+ } catch (error) {
31
+ if (error instanceof _superstruct.StructError) {
32
+ throw new Error(
33
+ `Failed to validate localization file "${file.path}": ${error.message}.`
34
+ );
35
+ }
36
+ if (error instanceof SyntaxError) {
37
+ throw new Error(
38
+ `Failed to parse localization file "${file.path}" as JSON.`
39
+ );
40
+ }
41
+ throw error;
42
+ }
43
+ }
44
+ return localizationFiles;
45
+ }
46
+ function getLocalizationFile(locale, localizationFiles) {
47
+ const file = localizationFiles.find(
48
+ (localizationFile) => localizationFile.locale === locale
49
+ );
50
+ if (!file) {
51
+ return localizationFiles.find(
52
+ (localizationFile) => localizationFile.locale === "en"
53
+ );
54
+ }
55
+ return file;
56
+ }
57
+ var TRANSLATION_REGEX = /\{\{\s?([a-zA-Z0-9-_\s]+)\s?\}\}/gu;
58
+ function translate(value, file) {
59
+ const matches = value.matchAll(TRANSLATION_REGEX);
60
+ const array = Array.from(matches);
61
+ return array.reduce((result, [match, key]) => {
62
+ if (!file) {
63
+ throw new Error(
64
+ `Failed to translate "${value}": No localization file found.`
65
+ );
66
+ }
67
+ const translation = file.messages[key.trim()];
68
+ if (!translation) {
69
+ throw new Error(
70
+ `Failed to translate "${value}": No translation found for "${key.trim()}" in "${file.locale}" file.`
71
+ );
72
+ }
73
+ return result.replace(match, translation.message);
74
+ }, value);
75
+ }
76
+ function getLocalizedSnapManifest(snapManifest, locale, localizationFiles) {
77
+ const file = getLocalizationFile(locale, localizationFiles);
78
+ return LOCALIZABLE_FIELDS.reduce((manifest, field) => {
79
+ const translation = translate(manifest[field], file);
80
+ return {
81
+ ...manifest,
82
+ [field]: translation
83
+ };
84
+ }, snapManifest);
85
+ }
86
+ function validateSnapManifestLocalizations(snapManifest, localizationFiles) {
87
+ try {
88
+ localizationFiles.filter((file) => file.locale !== "en").forEach((file) => {
89
+ getLocalizedSnapManifest(snapManifest, file.locale, localizationFiles);
90
+ });
91
+ getLocalizedSnapManifest(snapManifest, "en", localizationFiles);
92
+ } catch (error) {
93
+ throw new Error(
94
+ `Failed to localize Snap manifest: ${_snapssdk.getErrorMessage.call(void 0, error)}`
95
+ );
96
+ }
97
+ }
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+
108
+ exports.LOCALIZABLE_FIELDS = LOCALIZABLE_FIELDS; exports.LocalizationFileStruct = LocalizationFileStruct; exports.getValidatedLocalizationFiles = getValidatedLocalizationFiles; exports.getLocalizationFile = getLocalizationFile; exports.TRANSLATION_REGEX = TRANSLATION_REGEX; exports.translate = translate; exports.getLocalizedSnapManifest = getLocalizedSnapManifest; exports.validateSnapManifestLocalizations = validateSnapManifestLocalizations;
109
+ //# sourceMappingURL=chunk-RS5HE55U.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/localization.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,uBAAuB;AAEhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMA,IAAM,qBAAqB,CAAC,eAAe,cAAc;AAEzD,IAAM,yBAAyB,OAAO;AAAA,EAC3C,QAAQ,OAAO;AAAA,EACf,UAAU;AAAA,IACR,OAAO;AAAA,IACP,OAAO;AAAA,MACL,SAAS,OAAO;AAAA,MAChB,aAAa,SAAS,OAAO,CAAC;AAAA,IAChC,CAAC;AAAA,EACH;AACF,CAAC;AAWM,SAAS,8BACd,mBACiC;AACjC,aAAW,QAAQ,mBAAmB;AACpC,QAAI;AACF,WAAK,SAAS,OAAO,UAAU,KAAK,SAAS,CAAC,GAAG,sBAAsB;AAAA,IACzE,SAAS,OAAO;AACd,UAAI,iBAAiB,aAAa;AAChC,cAAM,IAAI;AAAA,UACR,yCAAyC,KAAK,IAAI,MAAM,MAAM,OAAO;AAAA,QACvE;AAAA,MACF;AAEA,UAAI,iBAAiB,aAAa;AAChC,cAAM,IAAI;AAAA,UACR,sCAAsC,KAAK,IAAI;AAAA,QACjD;AAAA,MACF;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AAEA,SAAO;AACT;AAWO,SAAS,oBACd,QACA,mBACA;AACA,QAAM,OAAO,kBAAkB;AAAA,IAC7B,CAAC,qBAAqB,iBAAiB,WAAW;AAAA,EACpD;AAEA,MAAI,CAAC,MAAM;AACT,WAAO,kBAAkB;AAAA,MACvB,CAAC,qBAAqB,iBAAiB,WAAW;AAAA,IACpD;AAAA,EACF;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB;AAa1B,SAAS,UAAU,OAAe,MAAoC;AAC3E,QAAM,UAAU,MAAM,SAAS,iBAAiB;AAChD,QAAM,QAAQ,MAAM,KAAK,OAAO;AAEhC,SAAO,MAAM,OAAe,CAAC,QAAQ,CAAC,OAAO,GAAG,MAAM;AACpD,QAAI,CAAC,MAAM;AACT,YAAM,IAAI;AAAA,QACR,wBAAwB,KAAK;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,cAAc,KAAK,SAAS,IAAI,KAAK,CAAC;AAC5C,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI;AAAA,QACR,wBAAwB,KAAK,gCAAgC,IAAI,KAAK,CAAC,SACrE,KAAK,MACP;AAAA,MACF;AAAA,IACF;AAEA,WAAO,OAAO,QAAQ,OAAO,YAAY,OAAO;AAAA,EAClD,GAAG,KAAK;AACV;AAWO,SAAS,yBACd,cACA,QACA,mBACA;AACA,QAAM,OAAO,oBAAoB,QAAQ,iBAAiB;AAE1D,SAAO,mBAAmB,OAAO,CAAC,UAAU,UAAU;AACpD,UAAM,cAAc,UAAU,SAAS,KAAK,GAAG,IAAI;AACnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,KAAK,GAAG;AAAA,IACX;AAAA,EACF,GAAG,YAAY;AACjB;AASO,SAAS,kCACd,cACA,mBACA;AACA,MAAI;AAGF,sBACG,OAAO,CAAC,SAAS,KAAK,WAAW,IAAI,EACrC,QAAQ,CAAC,SAAS;AACjB,+BAAyB,cAAc,KAAK,QAAQ,iBAAiB;AAAA,IACvE,CAAC;AAGH,6BAAyB,cAAc,MAAM,iBAAiB;AAAA,EAChE,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,qCAAqC,gBAAgB,KAAK,CAAC;AAAA,IAC7D;AAAA,EACF;AACF","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Infer } from 'superstruct';\nimport {\n create,\n object,\n optional,\n record,\n string,\n StructError,\n} from 'superstruct';\n\nimport { parseJson } from './json';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport const LOCALIZABLE_FIELDS = ['description', 'proposedName'] as const;\n\nexport const LocalizationFileStruct = object({\n locale: string(),\n messages: record(\n string(),\n object({\n message: string(),\n description: optional(string()),\n }),\n ),\n});\n\nexport type LocalizationFile = Infer<typeof LocalizationFileStruct>;\n\n/**\n * Validate a list of localization files.\n *\n * @param localizationFiles - The localization files to validate.\n * @returns The validated localization files.\n * @throws If any of the files are considered invalid.\n */\nexport function getValidatedLocalizationFiles(\n localizationFiles: VirtualFile[],\n): VirtualFile<LocalizationFile>[] {\n for (const file of localizationFiles) {\n try {\n file.result = create(parseJson(file.toString()), LocalizationFileStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Failed to validate localization file \"${file.path}\": ${error.message}.`,\n );\n }\n\n if (error instanceof SyntaxError) {\n throw new Error(\n `Failed to parse localization file \"${file.path}\" as JSON.`,\n );\n }\n\n throw error;\n }\n }\n\n return localizationFiles as VirtualFile<LocalizationFile>[];\n}\n\n/**\n * Get the localization file for a given locale. If the locale is not found,\n * the English localization file will be returned.\n *\n * @param locale - The locale to use.\n * @param localizationFiles - The localization files to use.\n * @returns The localization file, or `undefined` if no localization file was\n * found.\n */\nexport function getLocalizationFile(\n locale: string,\n localizationFiles: LocalizationFile[],\n) {\n const file = localizationFiles.find(\n (localizationFile) => localizationFile.locale === locale,\n );\n\n if (!file) {\n return localizationFiles.find(\n (localizationFile) => localizationFile.locale === 'en',\n );\n }\n\n return file;\n}\n\nexport const TRANSLATION_REGEX = /\\{\\{\\s?([a-zA-Z0-9-_\\s]+)\\s?\\}\\}/gu;\n\n/**\n * Translate a string using a localization file. This will replace all instances\n * of `{{key}}` with the localized version of `key`.\n *\n * @param value - The string to translate.\n * @param file - The localization file to use, or `undefined` if no localization\n * file was found.\n * @returns The translated string.\n * @throws If the string contains a key that is not present in the localization\n * file, or if no localization file was found.\n */\nexport function translate(value: string, file: LocalizationFile | undefined) {\n const matches = value.matchAll(TRANSLATION_REGEX);\n const array = Array.from(matches);\n\n return array.reduce<string>((result, [match, key]) => {\n if (!file) {\n throw new Error(\n `Failed to translate \"${value}\": No localization file found.`,\n );\n }\n\n const translation = file.messages[key.trim()];\n if (!translation) {\n throw new Error(\n `Failed to translate \"${value}\": No translation found for \"${key.trim()}\" in \"${\n file.locale\n }\" file.`,\n );\n }\n\n return result.replace(match, translation.message);\n }, value);\n}\n\n/**\n * Get the localized Snap manifest for a given locale. This will replace all\n * localized strings in the manifest with the localized version.\n *\n * @param snapManifest - The Snap manifest to localize.\n * @param locale - The locale to use.\n * @param localizationFiles - The localization files to use.\n * @returns The localized Snap manifest.\n */\nexport function getLocalizedSnapManifest(\n snapManifest: SnapManifest,\n locale: string,\n localizationFiles: LocalizationFile[],\n) {\n const file = getLocalizationFile(locale, localizationFiles);\n\n return LOCALIZABLE_FIELDS.reduce((manifest, field) => {\n const translation = translate(manifest[field], file);\n return {\n ...manifest,\n [field]: translation,\n };\n }, snapManifest);\n}\n\n/**\n * Validate the localization files for a Snap manifest.\n *\n * @param snapManifest - The Snap manifest to validate.\n * @param localizationFiles - The localization files to validate.\n * @throws If the manifest cannot be localized.\n */\nexport function validateSnapManifestLocalizations(\n snapManifest: SnapManifest,\n localizationFiles: LocalizationFile[],\n) {\n try {\n // `translate` throws if the manifest cannot be localized, so we just attempt\n // to translate the manifest using all localization files.\n localizationFiles\n .filter((file) => file.locale !== 'en')\n .forEach((file) => {\n getLocalizedSnapManifest(snapManifest, file.locale, localizationFiles);\n });\n\n // The manifest must be localizable in English.\n getLocalizedSnapManifest(snapManifest, 'en', localizationFiles);\n } catch (error) {\n throw new Error(\n `Failed to localize Snap manifest: ${getErrorMessage(error)}`,\n );\n }\n}\n"]}
@@ -0,0 +1,21 @@
1
+ // src/handler-types.ts
2
+ var HandlerType = /* @__PURE__ */ ((HandlerType2) => {
3
+ HandlerType2["OnRpcRequest"] = "onRpcRequest";
4
+ HandlerType2["OnSignature"] = "onSignature";
5
+ HandlerType2["OnTransaction"] = "onTransaction";
6
+ HandlerType2["OnCronjob"] = "onCronjob";
7
+ HandlerType2["OnInstall"] = "onInstall";
8
+ HandlerType2["OnUpdate"] = "onUpdate";
9
+ HandlerType2["OnNameLookup"] = "onNameLookup";
10
+ HandlerType2["OnKeyringRequest"] = "onKeyringRequest";
11
+ HandlerType2["OnHomePage"] = "onHomePage";
12
+ HandlerType2["OnUserInput"] = "onUserInput";
13
+ return HandlerType2;
14
+ })(HandlerType || {});
15
+ var SNAP_EXPORT_NAMES = Object.values(HandlerType);
16
+
17
+ export {
18
+ HandlerType,
19
+ SNAP_EXPORT_NAMES
20
+ };
21
+ //# sourceMappingURL=chunk-TUAHXE75.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/handler-types.ts"],"sourcesContent":["export enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnSignature = 'onSignature',\n OnTransaction = 'onTransaction',\n OnCronjob = 'onCronjob',\n OnInstall = 'onInstall',\n OnUpdate = 'onUpdate',\n OnNameLookup = 'onNameLookup',\n OnKeyringRequest = 'onKeyringRequest',\n OnHomePage = 'onHomePage',\n OnUserInput = 'onUserInput',\n}\n\nexport type SnapHandler = {\n /**\n * The type of handler.\n */\n type: HandlerType;\n\n /**\n * Whether the handler is required, i.e., whether the request will fail if the\n * handler is called, but the snap does not export it.\n *\n * This is primarily used for the lifecycle handlers, which are optional.\n */\n required: boolean;\n\n /**\n * Validate the given snap export. This should return a type guard for the\n * handler type.\n *\n * @param snapExport - The export to validate.\n * @returns Whether the export is valid.\n */\n validator: (snapExport: unknown) => boolean;\n};\n\nexport const SNAP_EXPORT_NAMES = Object.values(HandlerType);\n"],"mappings":";AAAO,IAAK,cAAL,kBAAKA,iBAAL;AACL,EAAAA,aAAA,kBAAe;AACf,EAAAA,aAAA,iBAAc;AACd,EAAAA,aAAA,mBAAgB;AAChB,EAAAA,aAAA,eAAY;AACZ,EAAAA,aAAA,eAAY;AACZ,EAAAA,aAAA,cAAW;AACX,EAAAA,aAAA,kBAAe;AACf,EAAAA,aAAA,sBAAmB;AACnB,EAAAA,aAAA,gBAAa;AACb,EAAAA,aAAA,iBAAc;AAVJ,SAAAA;AAAA,GAAA;AAqCL,IAAM,oBAAoB,OAAO,OAAO,WAAW;","names":["HandlerType"]}
@@ -0,0 +1,59 @@
1
+ import {
2
+ validateFilePath
3
+ } from "./chunk-32B4YQM7.mjs";
4
+ import {
5
+ __dirname
6
+ } from "./chunk-4GBOSMF7.mjs";
7
+
8
+ // src/eval.ts
9
+ import { assert } from "@metamask/utils";
10
+ import { fork } from "child_process";
11
+ import { join } from "path";
12
+ var SnapEvalError = class extends Error {
13
+ constructor(message, output) {
14
+ super(message);
15
+ this.name = "SnapEvalError";
16
+ this.output = output;
17
+ }
18
+ };
19
+ async function evalBundle(bundlePath) {
20
+ await validateFilePath(bundlePath);
21
+ return new Promise((resolve, reject) => {
22
+ const worker = fork(join(__dirname, "eval-worker.js"), [bundlePath], {
23
+ // To avoid printing the output of the worker to the console, we set
24
+ // `stdio` to `pipe` and handle the output ourselves.
25
+ stdio: "pipe"
26
+ });
27
+ let stdout = "";
28
+ let stderr = "";
29
+ assert(worker.stdout, "`stdout` should be defined.");
30
+ assert(worker.stderr, "`stderr` should be defined.");
31
+ worker.stdout.on("data", (data) => {
32
+ stdout += data.toString();
33
+ });
34
+ worker.stderr.on("data", (data) => {
35
+ stderr += data.toString();
36
+ });
37
+ worker.on("exit", (exitCode) => {
38
+ const output = {
39
+ stdout,
40
+ stderr
41
+ };
42
+ if (exitCode === 0) {
43
+ return resolve(output);
44
+ }
45
+ return reject(
46
+ new SnapEvalError(
47
+ `Process exited with non-zero exit code: ${exitCode}.`,
48
+ output
49
+ )
50
+ );
51
+ });
52
+ });
53
+ }
54
+
55
+ export {
56
+ SnapEvalError,
57
+ evalBundle
58
+ };
59
+ //# sourceMappingURL=chunk-TURGGK5F.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/eval.ts"],"sourcesContent":["import { assert } from '@metamask/utils';\nimport { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\nexport type EvalOutput = {\n stdout: string;\n stderr: string;\n};\n\nexport class SnapEvalError extends Error {\n readonly output: EvalOutput;\n\n constructor(message: string, output: EvalOutput) {\n super(message);\n\n this.name = 'SnapEvalError';\n this.output = output;\n }\n}\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<EvalOutput> {\n await validateFilePath(bundlePath);\n\n return new Promise((resolve, reject) => {\n const worker = fork(join(__dirname, 'eval-worker.js'), [bundlePath], {\n // To avoid printing the output of the worker to the console, we set\n // `stdio` to `pipe` and handle the output ourselves.\n stdio: 'pipe',\n });\n\n let stdout = '';\n let stderr = '';\n\n assert(worker.stdout, '`stdout` should be defined.');\n assert(worker.stderr, '`stderr` should be defined.');\n\n worker.stdout.on('data', (data: Buffer) => {\n stdout += data.toString();\n });\n\n worker.stderr.on('data', (data: Buffer) => {\n stderr += data.toString();\n });\n\n worker.on('exit', (exitCode: number) => {\n const output = {\n stdout,\n stderr,\n };\n\n if (exitCode === 0) {\n return resolve(output);\n }\n\n return reject(\n new SnapEvalError(\n `Process exited with non-zero exit code: ${exitCode}.`,\n output,\n ),\n );\n });\n });\n}\n"],"mappings":";;;;;;;;AAAA,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,YAAY;AASd,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAGvC,YAAY,SAAiB,QAAoB;AAC/C,UAAM,OAAO;AAEb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AASA,eAAsB,WAAW,YAAyC;AACxE,QAAM,iBAAiB,UAAU;AAEjC,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAS,KAAK,KAAK,WAAW,gBAAgB,GAAG,CAAC,UAAU,GAAG;AAAA;AAAA;AAAA,MAGnE,OAAO;AAAA,IACT,CAAC;AAED,QAAI,SAAS;AACb,QAAI,SAAS;AAEb,WAAO,OAAO,QAAQ,6BAA6B;AACnD,WAAO,OAAO,QAAQ,6BAA6B;AAEnD,WAAO,OAAO,GAAG,QAAQ,CAAC,SAAiB;AACzC,gBAAU,KAAK,SAAS;AAAA,IAC1B,CAAC;AAED,WAAO,OAAO,GAAG,QAAQ,CAAC,SAAiB;AACzC,gBAAU,KAAK,SAAS;AAAA,IAC1B,CAAC;AAED,WAAO,GAAG,QAAQ,CAAC,aAAqB;AACtC,YAAM,SAAS;AAAA,QACb;AAAA,QACA;AAAA,MACF;AAEA,UAAI,aAAa,GAAG;AAClB,eAAO,QAAQ,MAAM;AAAA,MACvB;AAEA,aAAO;AAAA,QACL,IAAI;AAAA,UACF,2CAA2C,QAAQ;AAAA,UACnD;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
@@ -0,0 +1,50 @@
1
+ // src/icon.ts
2
+ import { isSvg, parseSvg } from "@metamask/snaps-sdk";
3
+ import { assert } from "@metamask/utils";
4
+ var SVG_MAX_BYTE_SIZE = 1e5;
5
+ var SVG_MAX_BYTE_SIZE_TEXT = `${Math.floor(
6
+ SVG_MAX_BYTE_SIZE / 1e3
7
+ )}kb`;
8
+ function assertIsSnapIcon(icon) {
9
+ assert(icon.path.endsWith(".svg"), 'Expected snap icon to end in ".svg".');
10
+ assert(
11
+ Buffer.byteLength(icon.value, "utf8") <= SVG_MAX_BYTE_SIZE,
12
+ `The specified SVG icon exceeds the maximum size of ${SVG_MAX_BYTE_SIZE_TEXT}.`
13
+ );
14
+ assert(isSvg(icon.toString()), "Snap icon must be a valid SVG.");
15
+ }
16
+ function getSvgDimensions(svg) {
17
+ try {
18
+ const parsed = parseSvg(svg);
19
+ const height = parsed["@_height"];
20
+ const width = parsed["@_width"];
21
+ if (height && width) {
22
+ return { height, width };
23
+ }
24
+ const viewBox = parsed["@_viewBox"];
25
+ if (viewBox) {
26
+ const [_minX, _minY, viewBoxWidth, viewBoxHeight] = viewBox.split(" ");
27
+ if (viewBoxWidth && viewBoxHeight) {
28
+ const parsedWidth = parseInt(viewBoxWidth, 10);
29
+ const parsedHeight = parseInt(viewBoxHeight, 10);
30
+ assert(Number.isInteger(parsedWidth) && parsedWidth > 0);
31
+ assert(Number.isInteger(parsedHeight) && parsedHeight > 0);
32
+ return {
33
+ width: parsedWidth,
34
+ height: parsedHeight
35
+ };
36
+ }
37
+ }
38
+ } catch {
39
+ throw new Error("Snap icon must be a valid SVG.");
40
+ }
41
+ return null;
42
+ }
43
+
44
+ export {
45
+ SVG_MAX_BYTE_SIZE,
46
+ SVG_MAX_BYTE_SIZE_TEXT,
47
+ assertIsSnapIcon,
48
+ getSvgDimensions
49
+ };
50
+ //# sourceMappingURL=chunk-UGQQ5DJ4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/icon.ts"],"sourcesContent":["import { isSvg, parseSvg } from '@metamask/snaps-sdk';\nimport { assert } from '@metamask/utils';\n\nimport type { VirtualFile } from './virtual-file';\n\nexport const SVG_MAX_BYTE_SIZE = 100_000;\nexport const SVG_MAX_BYTE_SIZE_TEXT = `${Math.floor(\n SVG_MAX_BYTE_SIZE / 1000,\n)}kb`;\n\n/**\n * Assert that a virtual file containing a Snap icon is valid.\n *\n * @param icon - A virtual file containing a Snap icon.\n */\nexport function assertIsSnapIcon(icon: VirtualFile) {\n assert(icon.path.endsWith('.svg'), 'Expected snap icon to end in \".svg\".');\n\n assert(\n Buffer.byteLength(icon.value, 'utf8') <= SVG_MAX_BYTE_SIZE,\n `The specified SVG icon exceeds the maximum size of ${SVG_MAX_BYTE_SIZE_TEXT}.`,\n );\n\n assert(isSvg(icon.toString()), 'Snap icon must be a valid SVG.');\n}\n\n/**\n * Extract the dimensions of an image from an SVG string if possible.\n *\n * @param svg - An SVG string.\n * @returns The height and width of the SVG or null.\n */\nexport function getSvgDimensions(svg: string): {\n height: number;\n width: number;\n} | null {\n try {\n const parsed = parseSvg(svg);\n\n const height = parsed['@_height'];\n const width = parsed['@_width'];\n\n if (height && width) {\n return { height, width };\n }\n\n const viewBox = parsed['@_viewBox'];\n if (viewBox) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [_minX, _minY, viewBoxWidth, viewBoxHeight] = viewBox.split(' ');\n\n if (viewBoxWidth && viewBoxHeight) {\n const parsedWidth = parseInt(viewBoxWidth, 10);\n const parsedHeight = parseInt(viewBoxHeight, 10);\n\n assert(Number.isInteger(parsedWidth) && parsedWidth > 0);\n assert(Number.isInteger(parsedHeight) && parsedHeight > 0);\n\n return {\n width: parsedWidth,\n height: parsedHeight,\n };\n }\n }\n } catch {\n throw new Error('Snap icon must be a valid SVG.');\n }\n\n return null;\n}\n"],"mappings":";AAAA,SAAS,OAAO,gBAAgB;AAChC,SAAS,cAAc;AAIhB,IAAM,oBAAoB;AAC1B,IAAM,yBAAyB,GAAG,KAAK;AAAA,EAC5C,oBAAoB;AACtB,CAAC;AAOM,SAAS,iBAAiB,MAAmB;AAClD,SAAO,KAAK,KAAK,SAAS,MAAM,GAAG,sCAAsC;AAEzE;AAAA,IACE,OAAO,WAAW,KAAK,OAAO,MAAM,KAAK;AAAA,IACzC,sDAAsD,sBAAsB;AAAA,EAC9E;AAEA,SAAO,MAAM,KAAK,SAAS,CAAC,GAAG,gCAAgC;AACjE;AAQO,SAAS,iBAAiB,KAGxB;AACP,MAAI;AACF,UAAM,SAAS,SAAS,GAAG;AAE3B,UAAM,SAAS,OAAO,UAAU;AAChC,UAAM,QAAQ,OAAO,SAAS;AAE9B,QAAI,UAAU,OAAO;AACnB,aAAO,EAAE,QAAQ,MAAM;AAAA,IACzB;AAEA,UAAM,UAAU,OAAO,WAAW;AAClC,QAAI,SAAS;AAEX,YAAM,CAAC,OAAO,OAAO,cAAc,aAAa,IAAI,QAAQ,MAAM,GAAG;AAErE,UAAI,gBAAgB,eAAe;AACjC,cAAM,cAAc,SAAS,cAAc,EAAE;AAC7C,cAAM,eAAe,SAAS,eAAe,EAAE;AAE/C,eAAO,OAAO,UAAU,WAAW,KAAK,cAAc,CAAC;AACvD,eAAO,OAAO,UAAU,YAAY,KAAK,eAAe,CAAC;AAEzD,eAAO;AAAA,UACL,OAAO;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA,EACF,QAAQ;AACN,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}
@@ -0,0 +1,18 @@
1
+ import {
2
+ VirtualFile
3
+ } from "./chunk-LOW2T4MV.mjs";
4
+
5
+ // src/bytes.ts
6
+ import { stringToBytes } from "@metamask/utils";
7
+ function getBytes(bytes) {
8
+ const unwrapped = bytes instanceof VirtualFile ? bytes.value : bytes;
9
+ if (typeof unwrapped === "string") {
10
+ return stringToBytes(unwrapped);
11
+ }
12
+ return unwrapped;
13
+ }
14
+
15
+ export {
16
+ getBytes
17
+ };
18
+ //# sourceMappingURL=chunk-VGWELVCX.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/bytes.ts"],"sourcesContent":["import { stringToBytes } from '@metamask/utils';\n\nimport { VirtualFile } from './virtual-file/VirtualFile';\n\n/**\n * Convert a bytes-like input value to a Uint8Array.\n *\n * @param bytes - A bytes-like value.\n * @returns The input value converted to a Uint8Array if necessary.\n */\nexport function getBytes(bytes: VirtualFile | Uint8Array | string): Uint8Array {\n // Unwrap VirtualFiles to extract the content\n // The content is then either a string or Uint8Array\n const unwrapped = bytes instanceof VirtualFile ? bytes.value : bytes;\n\n if (typeof unwrapped === 'string') {\n return stringToBytes(unwrapped);\n }\n\n return unwrapped;\n}\n"],"mappings":";;;;;AAAA,SAAS,qBAAqB;AAUvB,SAAS,SAAS,OAAsD;AAG7E,QAAM,YAAY,iBAAiB,cAAc,MAAM,QAAQ;AAE/D,MAAI,OAAO,cAAc,UAAU;AACjC,WAAO,cAAc,SAAS;AAAA,EAChC;AAEA,SAAO;AACT;","names":[]}