@metamask/snaps-utils 6.1.0 → 7.0.1

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 (560) hide show
  1. package/CHANGELOG.md +24 -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-224DMTNJ.mjs +409 -0
  27. package/dist/chunk-224DMTNJ.mjs.map +1 -0
  28. package/dist/chunk-2IWSQJKQ.mjs +193 -0
  29. package/dist/chunk-2IWSQJKQ.mjs.map +1 -0
  30. package/dist/chunk-2LBN5T56.js +64 -0
  31. package/dist/chunk-2LBN5T56.js.map +1 -0
  32. package/dist/chunk-2PCPD5XY.js +169 -0
  33. package/dist/chunk-2PCPD5XY.js.map +1 -0
  34. package/dist/chunk-3SOYDY4W.js +152 -0
  35. package/dist/chunk-3SOYDY4W.js.map +1 -0
  36. package/dist/chunk-44GPX66J.mjs +70 -0
  37. package/dist/chunk-44GPX66J.mjs.map +1 -0
  38. package/dist/chunk-44VFHYJO.js +249 -0
  39. package/dist/chunk-44VFHYJO.js.map +1 -0
  40. package/dist/chunk-473MIETW.js +18 -0
  41. package/dist/chunk-473MIETW.js.map +1 -0
  42. package/dist/chunk-4BDR6KRH.js +50 -0
  43. package/dist/chunk-4BDR6KRH.js.map +1 -0
  44. package/dist/chunk-4CMD46B2.js +1 -0
  45. package/dist/chunk-4CMD46B2.js.map +1 -0
  46. package/dist/chunk-5R7UF7KM.mjs +21 -0
  47. package/dist/chunk-5R7UF7KM.mjs.map +1 -0
  48. package/dist/chunk-63OXILAY.mjs +69 -0
  49. package/dist/chunk-63OXILAY.mjs.map +1 -0
  50. package/dist/chunk-6CHO3LOX.mjs +10 -0
  51. package/dist/chunk-6CHO3LOX.mjs.map +1 -0
  52. package/dist/chunk-6LOYTBS3.js +107 -0
  53. package/dist/chunk-6LOYTBS3.js.map +1 -0
  54. package/dist/chunk-6YRUDGNL.mjs +18 -0
  55. package/dist/chunk-6YRUDGNL.mjs.map +1 -0
  56. package/dist/chunk-772OPTGX.js +70 -0
  57. package/dist/chunk-772OPTGX.js.map +1 -0
  58. package/dist/chunk-7LG4D4XA.mjs +20 -0
  59. package/dist/chunk-7LG4D4XA.mjs.map +1 -0
  60. package/dist/chunk-7LOABHVW.js +1 -0
  61. package/dist/chunk-7LOABHVW.js.map +1 -0
  62. package/dist/chunk-7MTAHOWC.mjs +1 -0
  63. package/dist/chunk-7MTAHOWC.mjs.map +1 -0
  64. package/dist/chunk-7P62OIGX.js +69 -0
  65. package/dist/chunk-7P62OIGX.js.map +1 -0
  66. package/dist/chunk-7Y3WSN44.mjs +103 -0
  67. package/dist/chunk-7Y3WSN44.mjs.map +1 -0
  68. package/dist/chunk-A3RRMELT.mjs +1 -0
  69. package/dist/chunk-A3RRMELT.mjs.map +1 -0
  70. package/dist/chunk-A6E325SZ.js +211 -0
  71. package/dist/chunk-A6E325SZ.js.map +1 -0
  72. package/dist/chunk-AFQY2CNY.js +109 -0
  73. package/dist/chunk-AFQY2CNY.js.map +1 -0
  74. package/dist/chunk-AOGVLPQZ.js +18 -0
  75. package/dist/chunk-AOGVLPQZ.js.map +1 -0
  76. package/dist/chunk-AS5P6JRP.mjs +9 -0
  77. package/dist/chunk-AS5P6JRP.mjs.map +1 -0
  78. package/dist/chunk-ASZWZ7JT.js +20 -0
  79. package/dist/chunk-ASZWZ7JT.js.map +1 -0
  80. package/dist/chunk-BGSO2GQC.mjs +41 -0
  81. package/dist/chunk-BGSO2GQC.mjs.map +1 -0
  82. package/dist/chunk-CMOSYNZR.js +95 -0
  83. package/dist/chunk-CMOSYNZR.js.map +1 -0
  84. package/dist/chunk-CNNMLOQ6.js +409 -0
  85. package/dist/chunk-CNNMLOQ6.js.map +1 -0
  86. package/dist/chunk-CQRPSEH3.js +74 -0
  87. package/dist/chunk-CQRPSEH3.js.map +1 -0
  88. package/dist/chunk-DKDGMZFU.mjs +74 -0
  89. package/dist/chunk-DKDGMZFU.mjs.map +1 -0
  90. package/dist/chunk-E3BDBG6T.js +20 -0
  91. package/dist/chunk-E3BDBG6T.js.map +1 -0
  92. package/dist/chunk-EA2FOAEG.mjs +64 -0
  93. package/dist/chunk-EA2FOAEG.mjs.map +1 -0
  94. package/dist/chunk-EFRPCO3C.js +1 -0
  95. package/dist/chunk-EFRPCO3C.js.map +1 -0
  96. package/dist/chunk-ENKAY3PI.js +281 -0
  97. package/dist/chunk-ENKAY3PI.js.map +1 -0
  98. package/dist/chunk-EXUEHPZ4.mjs +107 -0
  99. package/dist/chunk-EXUEHPZ4.mjs.map +1 -0
  100. package/dist/chunk-FOWIC2SO.mjs +38 -0
  101. package/dist/chunk-FOWIC2SO.mjs.map +1 -0
  102. package/dist/chunk-GTAYOKI4.mjs +211 -0
  103. package/dist/chunk-GTAYOKI4.mjs.map +1 -0
  104. package/dist/chunk-HF7HUZ5Z.js +10 -0
  105. package/dist/chunk-HF7HUZ5Z.js.map +1 -0
  106. package/dist/chunk-HJRCBSNA.mjs +32 -0
  107. package/dist/chunk-HJRCBSNA.mjs.map +1 -0
  108. package/dist/chunk-HJYRGKCX.js +50 -0
  109. package/dist/chunk-HJYRGKCX.js.map +1 -0
  110. package/dist/chunk-HYF7Q6VY.mjs +1 -0
  111. package/dist/chunk-HYF7Q6VY.mjs.map +1 -0
  112. package/dist/chunk-I77AVJKV.mjs +152 -0
  113. package/dist/chunk-I77AVJKV.mjs.map +1 -0
  114. package/dist/chunk-IGMAXVPP.mjs +21 -0
  115. package/dist/chunk-IGMAXVPP.mjs.map +1 -0
  116. package/dist/chunk-IHQPAJ2B.js +38 -0
  117. package/dist/chunk-IHQPAJ2B.js.map +1 -0
  118. package/dist/chunk-IJX3CXOY.js +9 -0
  119. package/dist/chunk-IJX3CXOY.js.map +1 -0
  120. package/dist/chunk-IPOE62V4.js +30 -0
  121. package/dist/chunk-IPOE62V4.js.map +1 -0
  122. package/dist/chunk-IV3FSWZ7.mjs +9 -0
  123. package/dist/chunk-IV3FSWZ7.mjs.map +1 -0
  124. package/dist/chunk-IXBJNVHK.js +22 -0
  125. package/dist/chunk-IXBJNVHK.js.map +1 -0
  126. package/dist/chunk-JI5NQ2C3.mjs +1 -0
  127. package/dist/chunk-JI5NQ2C3.mjs.map +1 -0
  128. package/dist/chunk-JMDSN227.mjs +25 -0
  129. package/dist/chunk-JMDSN227.mjs.map +1 -0
  130. package/dist/chunk-K6BCBPXF.js +151 -0
  131. package/dist/chunk-K6BCBPXF.js.map +1 -0
  132. package/dist/chunk-KMLVVVK3.mjs +22 -0
  133. package/dist/chunk-KMLVVVK3.mjs.map +1 -0
  134. package/dist/chunk-LBRWAC27.js +56 -0
  135. package/dist/chunk-LBRWAC27.js.map +1 -0
  136. package/dist/chunk-LCWDLIK5.mjs +281 -0
  137. package/dist/chunk-LCWDLIK5.mjs.map +1 -0
  138. package/dist/chunk-LEKZPKS2.js +21 -0
  139. package/dist/chunk-LEKZPKS2.js.map +1 -0
  140. package/dist/chunk-LSPOXPJJ.mjs +63 -0
  141. package/dist/chunk-LSPOXPJJ.mjs.map +1 -0
  142. package/dist/chunk-MCEKOGEG.mjs +50 -0
  143. package/dist/chunk-MCEKOGEG.mjs.map +1 -0
  144. package/dist/chunk-MLOQHUOY.js +32 -0
  145. package/dist/chunk-MLOQHUOY.js.map +1 -0
  146. package/dist/chunk-N722KRZW.js +41 -0
  147. package/dist/chunk-N722KRZW.js.map +1 -0
  148. package/dist/chunk-NUCLSR2G.js +8 -0
  149. package/dist/chunk-NUCLSR2G.js.map +1 -0
  150. package/dist/chunk-P252LKUT.mjs +9 -0
  151. package/dist/chunk-P252LKUT.mjs.map +1 -0
  152. package/dist/chunk-PHUTP7NB.js +25 -0
  153. package/dist/chunk-PHUTP7NB.js.map +1 -0
  154. package/dist/chunk-PJMEJVOB.mjs +29 -0
  155. package/dist/chunk-PJMEJVOB.mjs.map +1 -0
  156. package/dist/chunk-PLBSSUVY.js +29 -0
  157. package/dist/chunk-PLBSSUVY.js.map +1 -0
  158. package/dist/chunk-Q7RCL5IE.js +30 -0
  159. package/dist/chunk-Q7RCL5IE.js.map +1 -0
  160. package/dist/chunk-QSCKTRRU.js +21 -0
  161. package/dist/chunk-QSCKTRRU.js.map +1 -0
  162. package/dist/chunk-QX6MAFJU.mjs +169 -0
  163. package/dist/chunk-QX6MAFJU.mjs.map +1 -0
  164. package/dist/chunk-QYPLUMB7.mjs +249 -0
  165. package/dist/chunk-QYPLUMB7.mjs.map +1 -0
  166. package/dist/chunk-RAZ7XG4Z.mjs +1 -0
  167. package/dist/chunk-RAZ7XG4Z.mjs.map +1 -0
  168. package/dist/chunk-SRMDDOVO.mjs +20 -0
  169. package/dist/chunk-SRMDDOVO.mjs.map +1 -0
  170. package/dist/chunk-T3VM5YXY.js +1 -0
  171. package/dist/chunk-T3VM5YXY.js.map +1 -0
  172. package/dist/chunk-T3YY4JIJ.js +9 -0
  173. package/dist/chunk-T3YY4JIJ.js.map +1 -0
  174. package/dist/chunk-T6FWIDA6.mjs +95 -0
  175. package/dist/chunk-T6FWIDA6.mjs.map +1 -0
  176. package/dist/chunk-TFP64TMV.js +1 -0
  177. package/dist/chunk-TFP64TMV.js.map +1 -0
  178. package/dist/chunk-TG4BDSYJ.js +193 -0
  179. package/dist/chunk-TG4BDSYJ.js.map +1 -0
  180. package/dist/chunk-UMZNVWEM.mjs +30 -0
  181. package/dist/chunk-UMZNVWEM.mjs.map +1 -0
  182. package/dist/chunk-UW74NLTC.mjs +18 -0
  183. package/dist/chunk-UW74NLTC.mjs.map +1 -0
  184. package/dist/chunk-VWGXNUMD.mjs +151 -0
  185. package/dist/chunk-VWGXNUMD.mjs.map +1 -0
  186. package/dist/chunk-WEOCOYES.mjs +109 -0
  187. package/dist/chunk-WEOCOYES.mjs.map +1 -0
  188. package/dist/chunk-WF56W2AR.mjs +30 -0
  189. package/dist/chunk-WF56W2AR.mjs.map +1 -0
  190. package/dist/chunk-X44Z53IG.js +103 -0
  191. package/dist/chunk-X44Z53IG.js.map +1 -0
  192. package/dist/chunk-Z2JQNSVL.mjs +8 -0
  193. package/dist/chunk-Z2JQNSVL.mjs.map +1 -0
  194. package/dist/chunk-ZJRWU4AJ.mjs +50 -0
  195. package/dist/chunk-ZJRWU4AJ.mjs.map +1 -0
  196. package/dist/chunk-ZT3KKTS2.js +9 -0
  197. package/dist/chunk-ZT3KKTS2.js.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/index.d.ts +1 -6
  330. package/dist/types/json-rpc.d.ts +1 -1
  331. package/dist/types/localization.d.ts +1 -1
  332. package/dist/types/manifest/index.d.ts +0 -1
  333. package/dist/types/manifest/manifest.d.ts +1 -1
  334. package/dist/types/manifest/node.d.ts +2 -0
  335. package/dist/types/manifest/validation.d.ts +5 -5
  336. package/dist/types/node.d.ts +8 -0
  337. package/dist/types/structs.d.ts +0 -20
  338. package/dist/types/ui.d.ts +7 -0
  339. package/dist/types/virtual-file/index.d.ts +0 -1
  340. package/dist/types/virtual-file/node.d.ts +2 -0
  341. package/dist/types.js +28 -0
  342. package/dist/types.js.map +1 -0
  343. package/dist/types.mjs +28 -0
  344. package/dist/types.mjs.map +1 -0
  345. package/dist/ui.js +12 -0
  346. package/dist/ui.js.map +1 -0
  347. package/dist/ui.mjs +12 -0
  348. package/dist/ui.mjs.map +1 -0
  349. package/dist/validation.js +24 -0
  350. package/dist/validation.js.map +1 -0
  351. package/dist/validation.mjs +24 -0
  352. package/dist/validation.mjs.map +1 -0
  353. package/dist/versions.js +12 -0
  354. package/dist/versions.js.map +1 -0
  355. package/dist/versions.mjs +12 -0
  356. package/dist/versions.mjs.map +1 -0
  357. package/dist/virtual-file/VirtualFile.js +9 -0
  358. package/dist/virtual-file/VirtualFile.js.map +1 -0
  359. package/dist/virtual-file/VirtualFile.mjs +9 -0
  360. package/dist/virtual-file/VirtualFile.mjs.map +1 -0
  361. package/dist/virtual-file/index.js +10 -0
  362. package/dist/virtual-file/index.js.map +1 -0
  363. package/dist/virtual-file/index.mjs +10 -0
  364. package/dist/virtual-file/index.mjs.map +1 -0
  365. package/dist/virtual-file/node.js +17 -0
  366. package/dist/virtual-file/node.js.map +1 -0
  367. package/dist/virtual-file/node.mjs +17 -0
  368. package/dist/virtual-file/node.mjs.map +1 -0
  369. package/dist/virtual-file/toVirtualFile.js +12 -0
  370. package/dist/virtual-file/toVirtualFile.js.map +1 -0
  371. package/dist/virtual-file/toVirtualFile.mjs +12 -0
  372. package/dist/virtual-file/toVirtualFile.mjs.map +1 -0
  373. package/package.json +23 -38
  374. package/dist/cjs/array.js +0 -23
  375. package/dist/cjs/array.js.map +0 -1
  376. package/dist/cjs/auxiliary-files.js +0 -27
  377. package/dist/cjs/auxiliary-files.js.map +0 -1
  378. package/dist/cjs/base64.js +0 -44
  379. package/dist/cjs/base64.js.map +0 -1
  380. package/dist/cjs/bytes.js +0 -23
  381. package/dist/cjs/bytes.js.map +0 -1
  382. package/dist/cjs/caveats.js +0 -48
  383. package/dist/cjs/caveats.js.map +0 -1
  384. package/dist/cjs/checksum.js +0 -43
  385. package/dist/cjs/checksum.js.map +0 -1
  386. package/dist/cjs/cronjob.js +0 -77
  387. package/dist/cjs/cronjob.js.map +0 -1
  388. package/dist/cjs/deep-clone.js +0 -22
  389. package/dist/cjs/deep-clone.js.map +0 -1
  390. package/dist/cjs/default-endowments.js +0 -49
  391. package/dist/cjs/default-endowments.js.map +0 -1
  392. package/dist/cjs/derivation-paths.js +0 -300
  393. package/dist/cjs/derivation-paths.js.map +0 -1
  394. package/dist/cjs/entropy.js +0 -23
  395. package/dist/cjs/entropy.js.map +0 -1
  396. package/dist/cjs/errors.js +0 -221
  397. package/dist/cjs/errors.js.map +0 -1
  398. package/dist/cjs/eval-worker.js +0 -44
  399. package/dist/cjs/eval-worker.js.map +0 -1
  400. package/dist/cjs/eval.js +0 -77
  401. package/dist/cjs/eval.js.map +0 -1
  402. package/dist/cjs/fs.js +0 -126
  403. package/dist/cjs/fs.js.map +0 -1
  404. package/dist/cjs/handler-types.js +0 -34
  405. package/dist/cjs/handler-types.js.map +0 -1
  406. package/dist/cjs/handlers.js +0 -173
  407. package/dist/cjs/handlers.js.map +0 -1
  408. package/dist/cjs/icon.js +0 -66
  409. package/dist/cjs/icon.js.map +0 -1
  410. package/dist/cjs/iframe.js +0 -59
  411. package/dist/cjs/iframe.js.map +0 -1
  412. package/dist/cjs/index.browser.js +0 -49
  413. package/dist/cjs/index.browser.js.map +0 -1
  414. package/dist/cjs/index.executionenv.js +0 -27
  415. package/dist/cjs/index.executionenv.js.map +0 -1
  416. package/dist/cjs/index.js +0 -54
  417. package/dist/cjs/index.js.map +0 -1
  418. package/dist/cjs/json-rpc.js +0 -81
  419. package/dist/cjs/json-rpc.js.map +0 -1
  420. package/dist/cjs/json.js +0 -16
  421. package/dist/cjs/json.js.map +0 -1
  422. package/dist/cjs/localization.js +0 -113
  423. package/dist/cjs/localization.js.map +0 -1
  424. package/dist/cjs/logging.js +0 -40
  425. package/dist/cjs/logging.js.map +0 -1
  426. package/dist/cjs/manifest/index.browser.js +0 -20
  427. package/dist/cjs/manifest/index.browser.js.map +0 -1
  428. package/dist/cjs/manifest/index.js +0 -21
  429. package/dist/cjs/manifest/index.js.map +0 -1
  430. package/dist/cjs/manifest/manifest.js +0 -283
  431. package/dist/cjs/manifest/manifest.js.map +0 -1
  432. package/dist/cjs/manifest/validation.js +0 -244
  433. package/dist/cjs/manifest/validation.js.map +0 -1
  434. package/dist/cjs/mock.js +0 -128
  435. package/dist/cjs/mock.js.map +0 -1
  436. package/dist/cjs/namespace.js +0 -136
  437. package/dist/cjs/namespace.js.map +0 -1
  438. package/dist/cjs/npm.js +0 -96
  439. package/dist/cjs/npm.js.map +0 -1
  440. package/dist/cjs/path.js +0 -21
  441. package/dist/cjs/path.js.map +0 -1
  442. package/dist/cjs/post-process.js +0 -328
  443. package/dist/cjs/post-process.js.map +0 -1
  444. package/dist/cjs/snaps.js +0 -232
  445. package/dist/cjs/snaps.js.map +0 -1
  446. package/dist/cjs/strings.js +0 -21
  447. package/dist/cjs/strings.js.map +0 -1
  448. package/dist/cjs/structs.js +0 -210
  449. package/dist/cjs/structs.js.map +0 -1
  450. package/dist/cjs/types.js +0 -104
  451. package/dist/cjs/types.js.map +0 -1
  452. package/dist/cjs/ui.js +0 -53
  453. package/dist/cjs/ui.js.map +0 -1
  454. package/dist/cjs/validation.js +0 -24
  455. package/dist/cjs/validation.js.map +0 -1
  456. package/dist/cjs/versions.js +0 -47
  457. package/dist/cjs/versions.js.map +0 -1
  458. package/dist/cjs/virtual-file/VirtualFile.js +0 -92
  459. package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
  460. package/dist/cjs/virtual-file/index.browser.js +0 -20
  461. package/dist/cjs/virtual-file/index.browser.js.map +0 -1
  462. package/dist/cjs/virtual-file/index.js +0 -21
  463. package/dist/cjs/virtual-file/index.js.map +0 -1
  464. package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
  465. package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
  466. package/dist/esm/array.js +0 -13
  467. package/dist/esm/array.js.map +0 -1
  468. package/dist/esm/auxiliary-files.js +0 -23
  469. package/dist/esm/auxiliary-files.js.map +0 -1
  470. package/dist/esm/base64.js +0 -36
  471. package/dist/esm/base64.js.map +0 -1
  472. package/dist/esm/bytes.js +0 -18
  473. package/dist/esm/bytes.js.map +0 -1
  474. package/dist/esm/caveats.js +0 -38
  475. package/dist/esm/caveats.js.map +0 -1
  476. package/dist/esm/checksum.js +0 -41
  477. package/dist/esm/checksum.js.map +0 -1
  478. package/dist/esm/cronjob.js +0 -59
  479. package/dist/esm/cronjob.js.map +0 -1
  480. package/dist/esm/deep-clone.js +0 -7
  481. package/dist/esm/deep-clone.js.map +0 -1
  482. package/dist/esm/default-endowments.js +0 -39
  483. package/dist/esm/default-endowments.js.map +0 -1
  484. package/dist/esm/derivation-paths.js +0 -287
  485. package/dist/esm/derivation-paths.js.map +0 -1
  486. package/dist/esm/entropy.js +0 -6
  487. package/dist/esm/entropy.js.map +0 -1
  488. package/dist/esm/errors.js +0 -211
  489. package/dist/esm/errors.js.map +0 -1
  490. package/dist/esm/eval-worker.js +0 -40
  491. package/dist/esm/eval-worker.js.map +0 -1
  492. package/dist/esm/eval.js +0 -65
  493. package/dist/esm/eval.js.map +0 -1
  494. package/dist/esm/fs.js +0 -136
  495. package/dist/esm/fs.js.map +0 -1
  496. package/dist/esm/handler-types.js +0 -16
  497. package/dist/esm/handler-types.js.map +0 -1
  498. package/dist/esm/handlers.js +0 -119
  499. package/dist/esm/handlers.js.map +0 -1
  500. package/dist/esm/icon.js +0 -51
  501. package/dist/esm/icon.js.map +0 -1
  502. package/dist/esm/iframe.js +0 -49
  503. package/dist/esm/iframe.js.map +0 -1
  504. package/dist/esm/index.browser.js +0 -32
  505. package/dist/esm/index.browser.js.map +0 -1
  506. package/dist/esm/index.executionenv.js +0 -10
  507. package/dist/esm/index.executionenv.js.map +0 -1
  508. package/dist/esm/index.js +0 -37
  509. package/dist/esm/index.js.map +0 -1
  510. package/dist/esm/json-rpc.js +0 -79
  511. package/dist/esm/json-rpc.js.map +0 -1
  512. package/dist/esm/json.js +0 -17
  513. package/dist/esm/json.js.map +0 -1
  514. package/dist/esm/localization.js +0 -115
  515. package/dist/esm/localization.js.map +0 -1
  516. package/dist/esm/logging.js +0 -59
  517. package/dist/esm/logging.js.map +0 -1
  518. package/dist/esm/manifest/index.browser.js +0 -3
  519. package/dist/esm/manifest/index.browser.js.map +0 -1
  520. package/dist/esm/manifest/index.js +0 -4
  521. package/dist/esm/manifest/index.js.map +0 -1
  522. package/dist/esm/manifest/manifest.js +0 -307
  523. package/dist/esm/manifest/manifest.js.map +0 -1
  524. package/dist/esm/manifest/validation.js +0 -190
  525. package/dist/esm/manifest/validation.js.map +0 -1
  526. package/dist/esm/mock.js +0 -111
  527. package/dist/esm/mock.js.map +0 -1
  528. package/dist/esm/namespace.js +0 -113
  529. package/dist/esm/namespace.js.map +0 -1
  530. package/dist/esm/npm.js +0 -85
  531. package/dist/esm/npm.js.map +0 -1
  532. package/dist/esm/path.js +0 -17
  533. package/dist/esm/path.js.map +0 -1
  534. package/dist/esm/post-process.js +0 -333
  535. package/dist/esm/post-process.js.map +0 -1
  536. package/dist/esm/snaps.js +0 -217
  537. package/dist/esm/snaps.js.map +0 -1
  538. package/dist/esm/strings.js +0 -11
  539. package/dist/esm/strings.js.map +0 -1
  540. package/dist/esm/structs.js +0 -295
  541. package/dist/esm/structs.js.map +0 -1
  542. package/dist/esm/types.js +0 -78
  543. package/dist/esm/types.js.map +0 -1
  544. package/dist/esm/ui.js +0 -50
  545. package/dist/esm/ui.js.map +0 -1
  546. package/dist/esm/validation.js +0 -19
  547. package/dist/esm/validation.js.map +0 -1
  548. package/dist/esm/versions.js +0 -41
  549. package/dist/esm/versions.js.map +0 -1
  550. package/dist/esm/virtual-file/VirtualFile.js +0 -82
  551. package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
  552. package/dist/esm/virtual-file/index.browser.js +0 -3
  553. package/dist/esm/virtual-file/index.browser.js.map +0 -1
  554. package/dist/esm/virtual-file/index.js +0 -4
  555. package/dist/esm/virtual-file/index.js.map +0 -1
  556. package/dist/esm/virtual-file/toVirtualFile.js +0 -26
  557. package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
  558. package/dist/types/index.browser.d.ts +0 -30
  559. package/dist/types/manifest/index.browser.d.ts +0 -1
  560. package/dist/types/virtual-file/index.browser.d.ts +0 -1
@@ -1,221 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- SNAP_ERROR_WRAPPER_CODE: function() {
13
- return SNAP_ERROR_WRAPPER_CODE;
14
- },
15
- SNAP_ERROR_WRAPPER_MESSAGE: function() {
16
- return SNAP_ERROR_WRAPPER_MESSAGE;
17
- },
18
- WrappedSnapError: function() {
19
- return WrappedSnapError;
20
- },
21
- isSnapError: function() {
22
- return isSnapError;
23
- },
24
- isSerializedSnapError: function() {
25
- return isSerializedSnapError;
26
- },
27
- isWrappedSnapError: function() {
28
- return isWrappedSnapError;
29
- },
30
- unwrapError: function() {
31
- return unwrapError;
32
- }
33
- });
34
- const _rpcerrors = require("@metamask/rpc-errors");
35
- const _snapssdk = require("@metamask/snaps-sdk");
36
- const _utils = require("@metamask/utils");
37
- function _check_private_redeclaration(obj, privateCollection) {
38
- if (privateCollection.has(obj)) {
39
- throw new TypeError("Cannot initialize the same private elements twice on an object");
40
- }
41
- }
42
- function _class_apply_descriptor_get(receiver, descriptor) {
43
- if (descriptor.get) {
44
- return descriptor.get.call(receiver);
45
- }
46
- return descriptor.value;
47
- }
48
- function _class_apply_descriptor_set(receiver, descriptor, value) {
49
- if (descriptor.set) {
50
- descriptor.set.call(receiver, value);
51
- } else {
52
- if (!descriptor.writable) {
53
- throw new TypeError("attempted to set read only private field");
54
- }
55
- descriptor.value = value;
56
- }
57
- }
58
- function _class_extract_field_descriptor(receiver, privateMap, action) {
59
- if (!privateMap.has(receiver)) {
60
- throw new TypeError("attempted to " + action + " private field on non-instance");
61
- }
62
- return privateMap.get(receiver);
63
- }
64
- function _class_private_field_get(receiver, privateMap) {
65
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "get");
66
- return _class_apply_descriptor_get(receiver, descriptor);
67
- }
68
- function _class_private_field_init(obj, privateMap, value) {
69
- _check_private_redeclaration(obj, privateMap);
70
- privateMap.set(obj, value);
71
- }
72
- function _class_private_field_set(receiver, privateMap, value) {
73
- var descriptor = _class_extract_field_descriptor(receiver, privateMap, "set");
74
- _class_apply_descriptor_set(receiver, descriptor, value);
75
- return value;
76
- }
77
- const SNAP_ERROR_WRAPPER_CODE = -31001;
78
- const SNAP_ERROR_WRAPPER_MESSAGE = 'Wrapped Snap Error';
79
- var _error = /*#__PURE__*/ new WeakMap(), _message = /*#__PURE__*/ new WeakMap(), _stack = /*#__PURE__*/ new WeakMap();
80
- class WrappedSnapError extends Error {
81
- /**
82
- * The error name.
83
- *
84
- * @returns The error name.
85
- */ get name() {
86
- return 'WrappedSnapError';
87
- }
88
- /**
89
- * The error message.
90
- *
91
- * @returns The error message.
92
- */ get message() {
93
- return _class_private_field_get(this, _message);
94
- }
95
- /**
96
- * The error stack.
97
- *
98
- * @returns The error stack.
99
- */ get stack() {
100
- return _class_private_field_get(this, _stack);
101
- }
102
- /**
103
- * Convert the error to a JSON object.
104
- *
105
- * @returns The JSON object.
106
- */ toJSON() {
107
- const cause = isSnapError(_class_private_field_get(this, _error)) ? _class_private_field_get(this, _error).serialize() : (0, _rpcerrors.serializeCause)(_class_private_field_get(this, _error));
108
- return {
109
- code: SNAP_ERROR_WRAPPER_CODE,
110
- message: SNAP_ERROR_WRAPPER_MESSAGE,
111
- data: {
112
- cause
113
- }
114
- };
115
- }
116
- /**
117
- * Serialize the error to a JSON object. This is called by
118
- * `@metamask/rpc-errors` when serializing the error.
119
- *
120
- * @returns The JSON object.
121
- */ serialize() {
122
- return this.toJSON();
123
- }
124
- /**
125
- * Create a new `WrappedSnapError`.
126
- *
127
- * @param error - The error to create the `WrappedSnapError` from.
128
- */ constructor(error){
129
- const message = (0, _snapssdk.getErrorMessage)(error);
130
- super(message);
131
- _class_private_field_init(this, _error, {
132
- writable: true,
133
- value: void 0
134
- });
135
- _class_private_field_init(this, _message, {
136
- writable: true,
137
- value: void 0
138
- });
139
- _class_private_field_init(this, _stack, {
140
- writable: true,
141
- value: void 0
142
- });
143
- _class_private_field_set(this, _error, error);
144
- _class_private_field_set(this, _message, message);
145
- _class_private_field_set(this, _stack, (0, _snapssdk.getErrorStack)(error));
146
- }
147
- }
148
- function isSnapError(error) {
149
- if ((0, _utils.isObject)(error) && 'serialize' in error && typeof error.serialize === 'function') {
150
- const serialized = error.serialize();
151
- return (0, _utils.isJsonRpcError)(serialized) && isSerializedSnapError(serialized);
152
- }
153
- return false;
154
- }
155
- function isSerializedSnapError(error) {
156
- return error.code === _snapssdk.SNAP_ERROR_CODE && error.message === _snapssdk.SNAP_ERROR_MESSAGE;
157
- }
158
- function isWrappedSnapError(error) {
159
- return (0, _utils.isJsonRpcError)(error) && error.code === SNAP_ERROR_WRAPPER_CODE && error.message === SNAP_ERROR_WRAPPER_MESSAGE;
160
- }
161
- /**
162
- * Get a JSON-RPC error with the given code, message, stack, and data.
163
- *
164
- * @param code - The error code.
165
- * @param message - The error message.
166
- * @param stack - The error stack.
167
- * @param data - Additional data for the error.
168
- * @returns The JSON-RPC error.
169
- */ function getJsonRpcError(code, message, stack, data) {
170
- const error = new _rpcerrors.JsonRpcError(code, message, data);
171
- error.stack = stack;
172
- return error;
173
- }
174
- function unwrapError(error) {
175
- // This logic is a bit complicated, but it's necessary to handle all the
176
- // different types of errors that can be thrown by a Snap.
177
- // If the error is a wrapped Snap error, unwrap it.
178
- if (isWrappedSnapError(error)) {
179
- // The wrapped error can be a JSON-RPC error, or an unknown error. If it's
180
- // a JSON-RPC error, we can unwrap it further.
181
- if ((0, _utils.isJsonRpcError)(error.data.cause)) {
182
- // If the JSON-RPC error is a wrapped Snap error, unwrap it further.
183
- if (isSerializedSnapError(error.data.cause)) {
184
- const { code, message, stack, data } = error.data.cause.data.cause;
185
- return [
186
- getJsonRpcError(code, message, stack, data),
187
- true
188
- ];
189
- }
190
- // Otherwise, we use the original JSON-RPC error.
191
- const { code, message, stack, data } = error.data.cause;
192
- return [
193
- getJsonRpcError(code, message, stack, data),
194
- false
195
- ];
196
- }
197
- // Otherwise, we throw an internal error with the wrapped error as the
198
- // message.
199
- return [
200
- getJsonRpcError(_rpcerrors.errorCodes.rpc.internal, (0, _snapssdk.getErrorMessage)(error.data.cause), (0, _snapssdk.getErrorStack)(error.data.cause)),
201
- false
202
- ];
203
- }
204
- // The error can be a non-wrapped JSON-RPC error, in which case we can just
205
- // re-throw it with the same code, message, and data.
206
- if ((0, _utils.isJsonRpcError)(error)) {
207
- const { code, message, stack, data } = error;
208
- return [
209
- getJsonRpcError(code, message, stack, data),
210
- false
211
- ];
212
- }
213
- // If the error is not a wrapped error, we don't know how to handle it, so we
214
- // throw an internal error with the error as the message.
215
- return [
216
- getJsonRpcError(_rpcerrors.errorCodes.rpc.internal, (0, _snapssdk.getErrorMessage)(error), (0, _snapssdk.getErrorStack)(error)),
217
- false
218
- ];
219
- }
220
-
221
- //# sourceMappingURL=errors.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/errors.ts"],"sourcesContent":["import {\n errorCodes,\n JsonRpcError as RpcError,\n serializeCause,\n} from '@metamask/rpc-errors';\nimport type { DataWithOptionalCause } from '@metamask/rpc-errors';\nimport type { SerializedSnapError, SnapError } from '@metamask/snaps-sdk';\nimport {\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from '@metamask/snaps-sdk';\nimport type { Json, JsonRpcError } from '@metamask/utils';\nimport { isObject, isJsonRpcError } from '@metamask/utils';\n\nexport const SNAP_ERROR_WRAPPER_CODE = -31001;\nexport const SNAP_ERROR_WRAPPER_MESSAGE = 'Wrapped Snap Error';\n\nexport type SerializedSnapErrorWrapper = {\n code: typeof SNAP_ERROR_WRAPPER_CODE;\n message: typeof SNAP_ERROR_WRAPPER_MESSAGE;\n data: {\n cause: Json;\n };\n};\n\nexport class WrappedSnapError extends Error {\n readonly #error: unknown;\n\n readonly #message: string;\n\n readonly #stack?: string;\n\n /**\n * Create a new `WrappedSnapError`.\n *\n * @param error - The error to create the `WrappedSnapError` from.\n */\n constructor(error: unknown) {\n const message = getErrorMessage(error);\n super(message);\n\n this.#error = error;\n this.#message = message;\n this.#stack = getErrorStack(error);\n }\n\n /**\n * The error name.\n *\n * @returns The error name.\n */\n get name() {\n return 'WrappedSnapError';\n }\n\n /**\n * The error message.\n *\n * @returns The error message.\n */\n get message() {\n return this.#message;\n }\n\n /**\n * The error stack.\n *\n * @returns The error stack.\n */\n get stack() {\n return this.#stack;\n }\n\n /**\n * Convert the error to a JSON object.\n *\n * @returns The JSON object.\n */\n toJSON(): SerializedSnapErrorWrapper {\n const cause = isSnapError(this.#error)\n ? this.#error.serialize()\n : serializeCause(this.#error);\n\n return {\n code: SNAP_ERROR_WRAPPER_CODE,\n message: SNAP_ERROR_WRAPPER_MESSAGE,\n data: {\n cause,\n },\n };\n }\n\n /**\n * Serialize the error to a JSON object. This is called by\n * `@metamask/rpc-errors` when serializing the error.\n *\n * @returns The JSON object.\n */\n serialize() {\n return this.toJSON();\n }\n}\n\n/**\n * Check if an object is a `SnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `SnapError`.\n */\nexport function isSnapError(error: unknown): error is SnapError {\n if (\n isObject(error) &&\n 'serialize' in error &&\n typeof error.serialize === 'function'\n ) {\n const serialized = error.serialize();\n return isJsonRpcError(serialized) && isSerializedSnapError(serialized);\n }\n\n return false;\n}\n\n/**\n * Check if a JSON-RPC error is a `SnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `SnapError`.\n */\nexport function isSerializedSnapError(\n error: JsonRpcError,\n): error is SerializedSnapError {\n return error.code === SNAP_ERROR_CODE && error.message === SNAP_ERROR_MESSAGE;\n}\n\n/**\n * Check if a JSON-RPC error is a `WrappedSnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `WrappedSnapError`.\n */\nexport function isWrappedSnapError(\n error: unknown,\n): error is SerializedSnapErrorWrapper {\n return (\n isJsonRpcError(error) &&\n error.code === SNAP_ERROR_WRAPPER_CODE &&\n error.message === SNAP_ERROR_WRAPPER_MESSAGE\n );\n}\n\n/**\n * Get a JSON-RPC error with the given code, message, stack, and data.\n *\n * @param code - The error code.\n * @param message - The error message.\n * @param stack - The error stack.\n * @param data - Additional data for the error.\n * @returns The JSON-RPC error.\n */\nfunction getJsonRpcError(\n code: number,\n message: string,\n stack?: string,\n data?: Json,\n) {\n const error = new RpcError(code, message, data);\n error.stack = stack;\n\n return error;\n}\n\n/**\n * Attempt to unwrap an unknown error to a `JsonRpcError`. This function will\n * try to get the error code, message, and data from the error, and return a\n * `JsonRpcError` with those properties.\n *\n * @param error - The error to unwrap.\n * @returns A tuple containing the unwrapped error and a boolean indicating\n * whether the error was handled.\n */\nexport function unwrapError(\n error: unknown,\n): [error: RpcError<DataWithOptionalCause>, isHandled: boolean] {\n // This logic is a bit complicated, but it's necessary to handle all the\n // different types of errors that can be thrown by a Snap.\n\n // If the error is a wrapped Snap error, unwrap it.\n if (isWrappedSnapError(error)) {\n // The wrapped error can be a JSON-RPC error, or an unknown error. If it's\n // a JSON-RPC error, we can unwrap it further.\n if (isJsonRpcError(error.data.cause)) {\n // If the JSON-RPC error is a wrapped Snap error, unwrap it further.\n if (isSerializedSnapError(error.data.cause)) {\n const { code, message, stack, data } = error.data.cause.data.cause;\n return [getJsonRpcError(code, message, stack, data), true];\n }\n\n // Otherwise, we use the original JSON-RPC error.\n const { code, message, stack, data } = error.data.cause;\n return [getJsonRpcError(code, message, stack, data), false];\n }\n\n // Otherwise, we throw an internal error with the wrapped error as the\n // message.\n return [\n getJsonRpcError(\n errorCodes.rpc.internal,\n getErrorMessage(error.data.cause),\n getErrorStack(error.data.cause),\n ),\n false,\n ];\n }\n\n // The error can be a non-wrapped JSON-RPC error, in which case we can just\n // re-throw it with the same code, message, and data.\n if (isJsonRpcError(error)) {\n const { code, message, stack, data } = error;\n return [getJsonRpcError(code, message, stack, data), false];\n }\n\n // If the error is not a wrapped error, we don't know how to handle it, so we\n // throw an internal error with the error as the message.\n return [\n getJsonRpcError(\n errorCodes.rpc.internal,\n getErrorMessage(error),\n getErrorStack(error),\n ),\n false,\n ];\n}\n"],"names":["SNAP_ERROR_WRAPPER_CODE","SNAP_ERROR_WRAPPER_MESSAGE","WrappedSnapError","isSnapError","isSerializedSnapError","isWrappedSnapError","unwrapError","Error","name","message","stack","toJSON","cause","error","serialize","serializeCause","code","data","constructor","getErrorMessage","getErrorStack","isObject","serialized","isJsonRpcError","SNAP_ERROR_CODE","SNAP_ERROR_MESSAGE","getJsonRpcError","RpcError","errorCodes","rpc","internal"],"mappings":";;;;;;;;;;;IAgBaA,uBAAuB;eAAvBA;;IACAC,0BAA0B;eAA1BA;;IAUAC,gBAAgB;eAAhBA;;IAoFGC,WAAW;eAAXA;;IAmBAC,qBAAqB;eAArBA;;IAYAC,kBAAkB;eAAlBA;;IAwCAC,WAAW;eAAXA;;;2BAlLT;0BAQA;uBAEkC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAElC,MAAMN,0BAA0B,CAAC;AACjC,MAAMC,6BAA6B;IAW/B,sCAEA,wCAEA;AALJ,MAAMC,yBAAyBK;IAqBpC;;;;GAIC,GACD,IAAIC,OAAO;QACT,OAAO;IACT;IAEA;;;;GAIC,GACD,IAAIC,UAAU;QACZ,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACD,IAAIC,QAAQ;QACV,gCAAO,IAAI,EAAEA;IACf;IAEA;;;;GAIC,GACDC,SAAqC;QACnC,MAAMC,QAAQT,qCAAY,IAAI,EAAEU,WAC5B,yBAAA,IAAI,EAAEA,QAAMC,SAAS,KACrBC,IAAAA,yBAAc,2BAAC,IAAI,EAAEF;QAEzB,OAAO;YACLG,MAAMhB;YACNS,SAASR;YACTgB,MAAM;gBACJL;YACF;QACF;IACF;IAEA;;;;;GAKC,GACDE,YAAY;QACV,OAAO,IAAI,CAACH,MAAM;IACpB;IApEA;;;;GAIC,GACDO,YAAYL,KAAc,CAAE;QAC1B,MAAMJ,UAAUU,IAAAA,yBAAe,EAACN;QAChC,KAAK,CAACJ;QAbR,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;QAEA,gCAAS;;mBAAT,KAAA;;uCAWQI,QAAQA;uCACRJ,UAAUA;uCACVC,QAAQU,IAAAA,uBAAa,EAACP;IAC9B;AAyDF;AAQO,SAASV,YAAYU,KAAc;IACxC,IACEQ,IAAAA,eAAQ,EAACR,UACT,eAAeA,SACf,OAAOA,MAAMC,SAAS,KAAK,YAC3B;QACA,MAAMQ,aAAaT,MAAMC,SAAS;QAClC,OAAOS,IAAAA,qBAAc,EAACD,eAAelB,sBAAsBkB;IAC7D;IAEA,OAAO;AACT;AAQO,SAASlB,sBACdS,KAAmB;IAEnB,OAAOA,MAAMG,IAAI,KAAKQ,yBAAe,IAAIX,MAAMJ,OAAO,KAAKgB,4BAAkB;AAC/E;AAQO,SAASpB,mBACdQ,KAAc;IAEd,OACEU,IAAAA,qBAAc,EAACV,UACfA,MAAMG,IAAI,KAAKhB,2BACfa,MAAMJ,OAAO,KAAKR;AAEtB;AAEA;;;;;;;;CAQC,GACD,SAASyB,gBACPV,IAAY,EACZP,OAAe,EACfC,KAAc,EACdO,IAAW;IAEX,MAAMJ,QAAQ,IAAIc,uBAAQ,CAACX,MAAMP,SAASQ;IAC1CJ,MAAMH,KAAK,GAAGA;IAEd,OAAOG;AACT;AAWO,SAASP,YACdO,KAAc;IAEd,wEAAwE;IACxE,0DAA0D;IAE1D,mDAAmD;IACnD,IAAIR,mBAAmBQ,QAAQ;QAC7B,0EAA0E;QAC1E,8CAA8C;QAC9C,IAAIU,IAAAA,qBAAc,EAACV,MAAMI,IAAI,CAACL,KAAK,GAAG;YACpC,oEAAoE;YACpE,IAAIR,sBAAsBS,MAAMI,IAAI,CAACL,KAAK,GAAG;gBAC3C,MAAM,EAAEI,IAAI,EAAEP,OAAO,EAAEC,KAAK,EAAEO,IAAI,EAAE,GAAGJ,MAAMI,IAAI,CAACL,KAAK,CAACK,IAAI,CAACL,KAAK;gBAClE,OAAO;oBAACc,gBAAgBV,MAAMP,SAASC,OAAOO;oBAAO;iBAAK;YAC5D;YAEA,iDAAiD;YACjD,MAAM,EAAED,IAAI,EAAEP,OAAO,EAAEC,KAAK,EAAEO,IAAI,EAAE,GAAGJ,MAAMI,IAAI,CAACL,KAAK;YACvD,OAAO;gBAACc,gBAAgBV,MAAMP,SAASC,OAAOO;gBAAO;aAAM;QAC7D;QAEA,sEAAsE;QACtE,WAAW;QACX,OAAO;YACLS,gBACEE,qBAAU,CAACC,GAAG,CAACC,QAAQ,EACvBX,IAAAA,yBAAe,EAACN,MAAMI,IAAI,CAACL,KAAK,GAChCQ,IAAAA,uBAAa,EAACP,MAAMI,IAAI,CAACL,KAAK;YAEhC;SACD;IACH;IAEA,2EAA2E;IAC3E,qDAAqD;IACrD,IAAIW,IAAAA,qBAAc,EAACV,QAAQ;QACzB,MAAM,EAAEG,IAAI,EAAEP,OAAO,EAAEC,KAAK,EAAEO,IAAI,EAAE,GAAGJ;QACvC,OAAO;YAACa,gBAAgBV,MAAMP,SAASC,OAAOO;YAAO;SAAM;IAC7D;IAEA,6EAA6E;IAC7E,yDAAyD;IACzD,OAAO;QACLS,gBACEE,qBAAU,CAACC,GAAG,CAACC,QAAQ,EACvBX,IAAAA,yBAAe,EAACN,QAChBO,IAAAA,uBAAa,EAACP;QAEhB;KACD;AACH"}
@@ -1,44 +0,0 @@
1
- // eslint-disable-next-line import/no-unassigned-import
2
- "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- require("ses/lockdown");
7
- const _fs = require("fs");
8
- const _handlertypes = require("./handler-types");
9
- const _mock = require("./mock");
10
- lockdown({
11
- consoleTaming: 'unsafe',
12
- errorTaming: 'unsafe',
13
- mathTaming: 'unsafe',
14
- dateTaming: 'unsafe',
15
- overrideTaming: 'severe',
16
- // We disable domain taming, because it does not work in certain cases when
17
- // running tests. This is unlikely to be a problem in production, because
18
- // Node.js domains are deprecated.
19
- domainTaming: 'unsafe'
20
- });
21
- const snapFilePath = process.argv[2];
22
- const snapModule = {
23
- exports: {}
24
- };
25
- const compartment = new Compartment({
26
- ...(0, _mock.generateMockEndowments)(),
27
- module: snapModule,
28
- exports: snapModule.exports
29
- });
30
- // Mirror BaseSnapExecutor
31
- compartment.globalThis.self = compartment.globalThis;
32
- compartment.globalThis.global = compartment.globalThis;
33
- compartment.globalThis.window = compartment.globalThis;
34
- compartment.evaluate((0, _fs.readFileSync)(snapFilePath, 'utf8'));
35
- const invalidExports = Object.keys(snapModule.exports).filter((snapExport)=>!_handlertypes.SNAP_EXPORT_NAMES.includes(snapExport));
36
- if (invalidExports.length > 0) {
37
- // eslint-disable-next-line no-console
38
- console.warn(`Invalid snap exports detected:\n${invalidExports.join('\n')}`);
39
- }
40
- // To ensure the worker exits we explicitly call exit here
41
- // If we didn't the eval would wait for timers set during Compartment eval
42
- process.exit(0);
43
-
44
- //# sourceMappingURL=eval-worker.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/eval-worker.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport type { HandlerType } from './handler-types';\nimport { SNAP_EXPORT_NAMES } from './handler-types';\nimport { generateMockEndowments } from './mock';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n\n // We disable domain taming, because it does not work in certain cases when\n // running tests. This is unlikely to be a problem in production, because\n // Node.js domains are deprecated.\n domainTaming: 'unsafe',\n});\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nconst compartment = new Compartment({\n ...generateMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n});\n\n// Mirror BaseSnapExecutor\ncompartment.globalThis.self = compartment.globalThis;\ncompartment.globalThis.global = compartment.globalThis;\ncompartment.globalThis.window = compartment.globalThis;\n\ncompartment.evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n // eslint-disable-next-line no-console\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\n// To ensure the worker exits we explicitly call exit here\n// If we didn't the eval would wait for timers set during Compartment eval\nprocess.exit(0);\n"],"names":["lockdown","consoleTaming","errorTaming","mathTaming","dateTaming","overrideTaming","domainTaming","snapFilePath","process","argv","snapModule","exports","compartment","Compartment","generateMockEndowments","module","globalThis","self","global","window","evaluate","readFileSync","invalidExports","Object","keys","filter","snapExport","SNAP_EXPORT_NAMES","includes","length","console","warn","join","exit"],"mappings":"AAAA,uDAAuD;;;;;QAChD;oBAEsB;8BAGK;sBACK;AAIvCA,SAAS;IACPC,eAAe;IACfC,aAAa;IACbC,YAAY;IACZC,YAAY;IACZC,gBAAgB;IAEhB,2EAA2E;IAC3E,yEAAyE;IACzE,kCAAkC;IAClCC,cAAc;AAChB;AAEA,MAAMC,eAAeC,QAAQC,IAAI,CAAC,EAAE;AAEpC,MAAMC,aAAgC;IAAEC,SAAS,CAAC;AAAE;AAEpD,MAAMC,cAAc,IAAIC,YAAY;IAClC,GAAGC,IAAAA,4BAAsB,GAAE;IAC3BC,QAAQL;IACRC,SAASD,WAAWC,OAAO;AAC7B;AAEA,0BAA0B;AAC1BC,YAAYI,UAAU,CAACC,IAAI,GAAGL,YAAYI,UAAU;AACpDJ,YAAYI,UAAU,CAACE,MAAM,GAAGN,YAAYI,UAAU;AACtDJ,YAAYI,UAAU,CAACG,MAAM,GAAGP,YAAYI,UAAU;AAEtDJ,YAAYQ,QAAQ,CAACC,IAAAA,gBAAY,EAACd,cAAc;AAEhD,MAAMe,iBAAiBC,OAAOC,IAAI,CAACd,WAAWC,OAAO,EAAEc,MAAM,CAC3D,CAACC,aAAe,CAACC,+BAAiB,CAACC,QAAQ,CAACF;AAG9C,IAAIJ,eAAeO,MAAM,GAAG,GAAG;IAC7B,sCAAsC;IACtCC,QAAQC,IAAI,CAAC,CAAC,gCAAgC,EAAET,eAAeU,IAAI,CAAC,MAAM,CAAC;AAC7E;AAEA,0DAA0D;AAC1D,0EAA0E;AAC1ExB,QAAQyB,IAAI,CAAC"}
package/dist/cjs/eval.js DELETED
@@ -1,77 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- SnapEvalError: function() {
13
- return SnapEvalError;
14
- },
15
- evalBundle: function() {
16
- return evalBundle;
17
- }
18
- });
19
- const _utils = require("@metamask/utils");
20
- const _child_process = require("child_process");
21
- const _path = require("path");
22
- const _fs = require("./fs");
23
- function _define_property(obj, key, value) {
24
- if (key in obj) {
25
- Object.defineProperty(obj, key, {
26
- value: value,
27
- enumerable: true,
28
- configurable: true,
29
- writable: true
30
- });
31
- } else {
32
- obj[key] = value;
33
- }
34
- return obj;
35
- }
36
- class SnapEvalError extends Error {
37
- constructor(message, output){
38
- super(message);
39
- _define_property(this, "output", void 0);
40
- this.name = 'SnapEvalError';
41
- this.output = output;
42
- }
43
- }
44
- async function evalBundle(bundlePath) {
45
- await (0, _fs.validateFilePath)(bundlePath);
46
- return new Promise((resolve, reject)=>{
47
- const worker = (0, _child_process.fork)((0, _path.join)(__dirname, 'eval-worker.js'), [
48
- bundlePath
49
- ], {
50
- // To avoid printing the output of the worker to the console, we set
51
- // `stdio` to `pipe` and handle the output ourselves.
52
- stdio: 'pipe'
53
- });
54
- let stdout = '';
55
- let stderr = '';
56
- (0, _utils.assert)(worker.stdout, '`stdout` should be defined.');
57
- (0, _utils.assert)(worker.stderr, '`stderr` should be defined.');
58
- worker.stdout.on('data', (data)=>{
59
- stdout += data.toString();
60
- });
61
- worker.stderr.on('data', (data)=>{
62
- stderr += data.toString();
63
- });
64
- worker.on('exit', (exitCode)=>{
65
- const output = {
66
- stdout,
67
- stderr
68
- };
69
- if (exitCode === 0) {
70
- return resolve(output);
71
- }
72
- return reject(new SnapEvalError(`Process exited with non-zero exit code: ${exitCode}.`, output));
73
- });
74
- });
75
- }
76
-
77
- //# sourceMappingURL=eval.js.map
@@ -1 +0,0 @@
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"],"names":["SnapEvalError","evalBundle","Error","constructor","message","output","name","bundlePath","validateFilePath","Promise","resolve","reject","worker","fork","join","__dirname","stdio","stdout","stderr","assert","on","data","toString","exitCode"],"mappings":";;;;;;;;;;;IAWaA,aAAa;eAAbA;;IAkBSC,UAAU;eAAVA;;;uBA7BC;+BACF;sBACA;oBAEY;;;;;;;;;;;;;;AAO1B,MAAMD,sBAAsBE;IAGjCC,YAAYC,OAAe,EAAEC,MAAkB,CAAE;QAC/C,KAAK,CAACD;QAHR,uBAASC,UAAT,KAAA;QAKE,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACD,MAAM,GAAGA;IAChB;AACF;AASO,eAAeJ,WAAWM,UAAkB;IACjD,MAAMC,IAAAA,oBAAgB,EAACD;IAEvB,OAAO,IAAIE,QAAQ,CAACC,SAASC;QAC3B,MAAMC,SAASC,IAAAA,mBAAI,EAACC,IAAAA,UAAI,EAACC,WAAW,mBAAmB;YAACR;SAAW,EAAE;YACnE,oEAAoE;YACpE,qDAAqD;YACrDS,OAAO;QACT;QAEA,IAAIC,SAAS;QACb,IAAIC,SAAS;QAEbC,IAAAA,aAAM,EAACP,OAAOK,MAAM,EAAE;QACtBE,IAAAA,aAAM,EAACP,OAAOM,MAAM,EAAE;QAEtBN,OAAOK,MAAM,CAACG,EAAE,CAAC,QAAQ,CAACC;YACxBJ,UAAUI,KAAKC,QAAQ;QACzB;QAEAV,OAAOM,MAAM,CAACE,EAAE,CAAC,QAAQ,CAACC;YACxBH,UAAUG,KAAKC,QAAQ;QACzB;QAEAV,OAAOQ,EAAE,CAAC,QAAQ,CAACG;YACjB,MAAMlB,SAAS;gBACbY;gBACAC;YACF;YAEA,IAAIK,aAAa,GAAG;gBAClB,OAAOb,QAAQL;YACjB;YAEA,OAAOM,OACL,IAAIX,cACF,CAAC,wCAAwC,EAAEuB,SAAS,CAAC,CAAC,EACtDlB;QAGN;IACF;AACF"}
package/dist/cjs/fs.js DELETED
@@ -1,126 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- isDirectory: function() {
13
- return isDirectory;
14
- },
15
- isFile: function() {
16
- return isFile;
17
- },
18
- readJsonFile: function() {
19
- return readJsonFile;
20
- },
21
- getOutfilePath: function() {
22
- return getOutfilePath;
23
- },
24
- validateOutfileName: function() {
25
- return validateOutfileName;
26
- },
27
- validateFilePath: function() {
28
- return validateFilePath;
29
- },
30
- validateDirPath: function() {
31
- return validateDirPath;
32
- },
33
- useTemporaryFile: function() {
34
- return useTemporaryFile;
35
- }
36
- });
37
- const _fs = require("fs");
38
- const _os = /*#__PURE__*/ _interop_require_default(require("os"));
39
- const _path = /*#__PURE__*/ _interop_require_default(require("path"));
40
- const _json = require("./json");
41
- const _virtualfile = require("./virtual-file");
42
- function _interop_require_default(obj) {
43
- return obj && obj.__esModule ? obj : {
44
- default: obj
45
- };
46
- }
47
- async function isDirectory(pathString, createDir) {
48
- try {
49
- const stats = await _fs.promises.stat(pathString);
50
- return stats.isDirectory();
51
- } catch (error) {
52
- if (error.code === 'ENOENT') {
53
- if (!createDir) {
54
- return false;
55
- }
56
- await _fs.promises.mkdir(pathString, {
57
- recursive: true
58
- });
59
- return true;
60
- }
61
- return false;
62
- }
63
- }
64
- async function isFile(pathString) {
65
- try {
66
- const stats = await _fs.promises.stat(pathString);
67
- return stats.isFile();
68
- } catch (error) {
69
- return false;
70
- }
71
- }
72
- async function readJsonFile(pathString) {
73
- if (!pathString.endsWith('.json')) {
74
- throw new Error('The specified file must be a ".json" file.');
75
- }
76
- let file;
77
- try {
78
- file = await (0, _virtualfile.readVirtualFile)(pathString, 'utf8');
79
- } catch (error) {
80
- if (error.code === 'ENOENT') {
81
- throw new Error(`Could not find '${pathString}'. Please ensure that the file exists.`);
82
- }
83
- throw error;
84
- }
85
- file.result = (0, _json.parseJson)(file.toString());
86
- return file;
87
- }
88
- function getOutfilePath(outDir, outFileName) {
89
- return _path.default.join(outDir, outFileName || 'bundle.js');
90
- }
91
- function validateOutfileName(filename) {
92
- if (!filename.endsWith('.js') || filename === '.js' || _path.default.basename(filename) !== filename) {
93
- throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);
94
- }
95
- return true;
96
- }
97
- async function validateFilePath(filePath) {
98
- const exists = await isFile(filePath);
99
- if (!exists) {
100
- throw new Error(`Invalid params: '${filePath}' is not a file or does not exist.`);
101
- }
102
- return true;
103
- }
104
- async function validateDirPath(dirPath, createDir) {
105
- const exists = await isDirectory(dirPath, createDir);
106
- if (!exists) {
107
- throw new Error(`Invalid params: '${dirPath}' is not a directory or could not be created.`);
108
- }
109
- return true;
110
- }
111
- async function useTemporaryFile(fileName, fileContents, fn) {
112
- const filePath = _path.default.join(_os.default.tmpdir(), fileName);
113
- await _fs.promises.mkdir(_path.default.dirname(filePath), {
114
- recursive: true
115
- });
116
- await _fs.promises.writeFile(filePath, fileContents);
117
- try {
118
- await fn(filePath);
119
- } finally{
120
- if (await isFile(filePath)) {
121
- await _fs.promises.unlink(filePath);
122
- }
123
- }
124
- }
125
-
126
- //# sourceMappingURL=fs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/fs.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport os from 'os';\nimport pathUtils from 'path';\n\nimport { parseJson } from './json';\nimport type { VirtualFile } from './virtual-file';\nimport { readVirtualFile } from './virtual-file';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns Whether the given path is an existing directory.\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n await fs.mkdir(pathString, { recursive: true });\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check.\n * @returns Whether the given path is an existing file.\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile<Type extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = parseJson(file.toString());\n return file as VirtualFile<Type>;\n}\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n pathUtils.basename(filename) !== filename\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n\n/**\n * Creates a temporary file with a given name and content, writes it to disk and calls the provided function.\n * This function handles deletion of the temporary file after usage.\n *\n * @param fileName - The name of the temporary file.\n * @param fileContents - The content of the temporary file.\n * @param fn - The callback function to call when the temporary file has been created.\n */\nexport async function useTemporaryFile(\n fileName: string,\n fileContents: string,\n fn: (path: string) => Promise<unknown>,\n): Promise<void> {\n const filePath = pathUtils.join(os.tmpdir(), fileName);\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, fileContents);\n try {\n await fn(filePath);\n } finally {\n if (await isFile(filePath)) {\n await fs.unlink(filePath);\n }\n }\n}\n"],"names":["isDirectory","isFile","readJsonFile","getOutfilePath","validateOutfileName","validateFilePath","validateDirPath","useTemporaryFile","pathString","createDir","stats","fs","stat","error","code","mkdir","recursive","endsWith","Error","file","readVirtualFile","result","parseJson","toString","outDir","outFileName","pathUtils","join","filename","basename","filePath","exists","dirPath","fileName","fileContents","fn","os","tmpdir","dirname","writeFile","unlink"],"mappings":";;;;;;;;;;;IAiBsBA,WAAW;eAAXA;;IA2BAC,MAAM;eAANA;;IAeAC,YAAY;eAAZA;;IA+BNC,cAAc;eAAdA;;IAYAC,mBAAmB;eAAnBA;;IAkBMC,gBAAgB;eAAhBA;;IAkBAC,eAAe;eAAfA;;IAqBAC,gBAAgB;eAAhBA;;;oBA9JS;2DAChB;6DACO;sBAEI;6BAEM;;;;;;AAUzB,eAAeP,YACpBQ,UAAkB,EAClBC,SAAkB;IAElB,IAAI;QACF,MAAMC,QAAQ,MAAMC,YAAE,CAACC,IAAI,CAACJ;QAC5B,OAAOE,MAAMV,WAAW;IAC1B,EAAE,OAAOa,OAAO;QACd,IAAIA,MAAMC,IAAI,KAAK,UAAU;YAC3B,IAAI,CAACL,WAAW;gBACd,OAAO;YACT;YAEA,MAAME,YAAE,CAACI,KAAK,CAACP,YAAY;gBAAEQ,WAAW;YAAK;YAC7C,OAAO;QACT;QAEA,OAAO;IACT;AACF;AAQO,eAAef,OAAOO,UAAkB;IAC7C,IAAI;QACF,MAAME,QAAQ,MAAMC,YAAE,CAACC,IAAI,CAACJ;QAC5B,OAAOE,MAAMT,MAAM;IACrB,EAAE,OAAOY,OAAO;QACd,OAAO;IACT;AACF;AAQO,eAAeX,aACpBM,UAAkB;IAElB,IAAI,CAACA,WAAWS,QAAQ,CAAC,UAAU;QACjC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIC;IACJ,IAAI;QACFA,OAAO,MAAMC,IAAAA,4BAAe,EAACZ,YAAY;IAC3C,EAAE,OAAOK,OAAO;QACd,IAAIA,MAAMC,IAAI,KAAK,UAAU;YAC3B,MAAM,IAAII,MACR,CAAC,gBAAgB,EAAEV,WAAW,sCAAsC,CAAC;QAEzE;QAEA,MAAMK;IACR;IACAM,KAAKE,MAAM,GAAGC,IAAAA,eAAS,EAACH,KAAKI,QAAQ;IACrC,OAAOJ;AACT;AAUO,SAAShB,eAAeqB,MAAc,EAAEC,WAAmB;IAChE,OAAOC,aAAS,CAACC,IAAI,CAACH,QAAQC,eAAe;AAC/C;AAUO,SAASrB,oBAAoBwB,QAAgB;IAClD,IACE,CAACA,SAASX,QAAQ,CAAC,UACnBW,aAAa,SACbF,aAAS,CAACG,QAAQ,CAACD,cAAcA,UACjC;QACA,MAAM,IAAIV,MAAM,CAAC,sBAAsB,EAAEU,SAAS,oBAAoB,CAAC;IACzE;IACA,OAAO;AACT;AASO,eAAevB,iBAAiByB,QAAgB;IACrD,MAAMC,SAAS,MAAM9B,OAAO6B;IAC5B,IAAI,CAACC,QAAQ;QACX,MAAM,IAAIb,MACR,CAAC,iBAAiB,EAAEY,SAAS,kCAAkC,CAAC;IAEpE;IACA,OAAO;AACT;AAUO,eAAexB,gBACpB0B,OAAe,EACfvB,SAAkB;IAElB,MAAMsB,SAAS,MAAM/B,YAAYgC,SAASvB;IAC1C,IAAI,CAACsB,QAAQ;QACX,MAAM,IAAIb,MACR,CAAC,iBAAiB,EAAEc,QAAQ,6CAA6C,CAAC;IAE9E;IACA,OAAO;AACT;AAUO,eAAezB,iBACpB0B,QAAgB,EAChBC,YAAoB,EACpBC,EAAsC;IAEtC,MAAML,WAAWJ,aAAS,CAACC,IAAI,CAACS,WAAE,CAACC,MAAM,IAAIJ;IAC7C,MAAMtB,YAAE,CAACI,KAAK,CAACW,aAAS,CAACY,OAAO,CAACR,WAAW;QAAEd,WAAW;IAAK;IAC9D,MAAML,YAAE,CAAC4B,SAAS,CAACT,UAAUI;IAC7B,IAAI;QACF,MAAMC,GAAGL;IACX,SAAU;QACR,IAAI,MAAM7B,OAAO6B,WAAW;YAC1B,MAAMnB,YAAE,CAAC6B,MAAM,CAACV;QAClB;IACF;AACF"}
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- function _export(target, all) {
6
- for(var name in all)Object.defineProperty(target, name, {
7
- enumerable: true,
8
- get: all[name]
9
- });
10
- }
11
- _export(exports, {
12
- HandlerType: function() {
13
- return HandlerType;
14
- },
15
- SNAP_EXPORT_NAMES: function() {
16
- return SNAP_EXPORT_NAMES;
17
- }
18
- });
19
- var HandlerType;
20
- (function(HandlerType) {
21
- HandlerType["OnRpcRequest"] = 'onRpcRequest';
22
- HandlerType["OnSignature"] = 'onSignature';
23
- HandlerType["OnTransaction"] = 'onTransaction';
24
- HandlerType["OnCronjob"] = 'onCronjob';
25
- HandlerType["OnInstall"] = 'onInstall';
26
- HandlerType["OnUpdate"] = 'onUpdate';
27
- HandlerType["OnNameLookup"] = 'onNameLookup';
28
- HandlerType["OnKeyringRequest"] = 'onKeyringRequest';
29
- HandlerType["OnHomePage"] = 'onHomePage';
30
- HandlerType["OnUserInput"] = 'onUserInput';
31
- })(HandlerType || (HandlerType = {}));
32
- const SNAP_EXPORT_NAMES = Object.values(HandlerType);
33
-
34
- //# sourceMappingURL=handler-types.js.map
@@ -1 +0,0 @@
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"],"names":["SNAP_EXPORT_NAMES","HandlerType","OnRpcRequest","OnSignature","OnTransaction","OnCronjob","OnInstall","OnUpdate","OnNameLookup","OnKeyringRequest","OnHomePage","OnUserInput","Object","values"],"mappings":";;;;;;;;;;;;;;IAqCaA,iBAAiB;eAAjBA;;;IArCN;UAAKC,WAAW;IAAXA,YACVC,kBAAe;IADLD,YAEVE,iBAAc;IAFJF,YAGVG,mBAAgB;IAHNH,YAIVI,eAAY;IAJFJ,YAKVK,eAAY;IALFL,YAMVM,cAAW;IANDN,YAOVO,kBAAe;IAPLP,YAQVQ,sBAAmB;IARTR,YASVS,gBAAa;IATHT,YAUVU,iBAAc;GAVJV,gBAAAA;AAqCL,MAAMD,oBAAoBY,OAAOC,MAAM,CAACZ"}