@metamask/snaps-utils 6.1.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 (560) hide show
  1. package/CHANGELOG.md +18 -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/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
package/dist/cjs/snaps.js DELETED
@@ -1,232 +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
- SnapStatus: function() {
13
- return SnapStatus;
14
- },
15
- SnapStatusEvents: function() {
16
- return SnapStatusEvents;
17
- },
18
- PROPOSED_NAME_REGEX: function() {
19
- return PROPOSED_NAME_REGEX;
20
- },
21
- ProgrammaticallyFixableSnapError: function() {
22
- return ProgrammaticallyFixableSnapError;
23
- },
24
- getSnapChecksum: function() {
25
- return getSnapChecksum;
26
- },
27
- validateSnapShasum: function() {
28
- return validateSnapShasum;
29
- },
30
- LOCALHOST_HOSTNAMES: function() {
31
- return LOCALHOST_HOSTNAMES;
32
- },
33
- BaseSnapIdStruct: function() {
34
- return BaseSnapIdStruct;
35
- },
36
- LocalSnapIdStruct: function() {
37
- return LocalSnapIdStruct;
38
- },
39
- NpmSnapIdStruct: function() {
40
- return NpmSnapIdStruct;
41
- },
42
- HttpSnapIdStruct: function() {
43
- return HttpSnapIdStruct;
44
- },
45
- SnapIdStruct: function() {
46
- return SnapIdStruct;
47
- },
48
- getSnapPrefix: function() {
49
- return getSnapPrefix;
50
- },
51
- stripSnapPrefix: function() {
52
- return stripSnapPrefix;
53
- },
54
- assertIsValidSnapId: function() {
55
- return assertIsValidSnapId;
56
- },
57
- isCaipChainId: function() {
58
- return isCaipChainId;
59
- },
60
- isSnapPermitted: function() {
61
- return isSnapPermitted;
62
- },
63
- verifyRequestedSnapPermissions: function() {
64
- return verifyRequestedSnapPermissions;
65
- }
66
- });
67
- const _utils = require("@metamask/utils");
68
- const _base = require("@scure/base");
69
- const _fastjsonstablestringify = /*#__PURE__*/ _interop_require_default(require("fast-json-stable-stringify"));
70
- const _superstruct = require("superstruct");
71
- const _validatenpmpackagename = /*#__PURE__*/ _interop_require_default(require("validate-npm-package-name"));
72
- const _caveats = require("./caveats");
73
- const _checksum = require("./checksum");
74
- const _types = require("./types");
75
- function _define_property(obj, key, value) {
76
- if (key in obj) {
77
- Object.defineProperty(obj, key, {
78
- value: value,
79
- enumerable: true,
80
- configurable: true,
81
- writable: true
82
- });
83
- } else {
84
- obj[key] = value;
85
- }
86
- return obj;
87
- }
88
- function _interop_require_default(obj) {
89
- return obj && obj.__esModule ? obj : {
90
- default: obj
91
- };
92
- }
93
- const PROPOSED_NAME_REGEX = /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u;
94
- var SnapStatus;
95
- (function(SnapStatus) {
96
- SnapStatus["Installing"] = 'installing';
97
- SnapStatus["Updating"] = 'updating';
98
- SnapStatus["Running"] = 'running';
99
- SnapStatus["Stopped"] = 'stopped';
100
- SnapStatus["Crashed"] = 'crashed';
101
- })(SnapStatus || (SnapStatus = {}));
102
- var SnapStatusEvents;
103
- (function(SnapStatusEvents) {
104
- SnapStatusEvents["Start"] = 'START';
105
- SnapStatusEvents["Stop"] = 'STOP';
106
- SnapStatusEvents["Crash"] = 'CRASH';
107
- SnapStatusEvents["Update"] = 'UPDATE';
108
- })(SnapStatusEvents || (SnapStatusEvents = {}));
109
- class ProgrammaticallyFixableSnapError extends Error {
110
- constructor(message, reason){
111
- super(message);
112
- _define_property(this, "reason", void 0);
113
- this.reason = reason;
114
- }
115
- }
116
- /**
117
- * Gets a checksummable manifest by removing the shasum property and reserializing the JSON using a deterministic algorithm.
118
- *
119
- * @param manifest - The manifest itself.
120
- * @returns A virtual file containing the checksummable manifest.
121
- */ function getChecksummableManifest(manifest) {
122
- const manifestCopy = manifest.clone();
123
- delete manifestCopy.result.source.shasum;
124
- // We use fast-json-stable-stringify to deterministically serialize the JSON
125
- // This is required before checksumming so we get reproducible checksums across platforms etc
126
- manifestCopy.value = (0, _fastjsonstablestringify.default)(manifestCopy.result);
127
- return manifestCopy;
128
- }
129
- async function getSnapChecksum(files) {
130
- const { manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles } = files;
131
- const all = [
132
- getChecksummableManifest(manifest),
133
- sourceCode,
134
- svgIcon,
135
- ...auxiliaryFiles,
136
- ...localizationFiles
137
- ].filter((file)=>file !== undefined);
138
- return _base.base64.encode(await (0, _checksum.checksumFiles)(all));
139
- }
140
- async function validateSnapShasum(files, errorMessage = 'Invalid Snap manifest: manifest shasum does not match computed shasum.') {
141
- if (files.manifest.result.source.shasum !== await getSnapChecksum(files)) {
142
- throw new ProgrammaticallyFixableSnapError(errorMessage, _types.SnapValidationFailureReason.ShasumMismatch);
143
- }
144
- }
145
- const LOCALHOST_HOSTNAMES = [
146
- 'localhost',
147
- '127.0.0.1',
148
- '[::1]'
149
- ];
150
- const BaseSnapIdStruct = (0, _superstruct.pattern)((0, _superstruct.string)(), /^[\x21-\x7E]*$/u);
151
- const LocalSnapIdSubUrlStruct = (0, _types.uri)({
152
- protocol: (0, _superstruct.enums)([
153
- 'http:',
154
- 'https:'
155
- ]),
156
- hostname: (0, _superstruct.enums)(LOCALHOST_HOSTNAMES),
157
- hash: (0, _superstruct.empty)((0, _superstruct.string)()),
158
- search: (0, _superstruct.empty)((0, _superstruct.string)())
159
- });
160
- const LocalSnapIdStruct = (0, _superstruct.refine)(BaseSnapIdStruct, 'local Snap Id', (value)=>{
161
- if (!value.startsWith(_types.SnapIdPrefixes.local)) {
162
- return `Expected local snap ID, got "${value}".`;
163
- }
164
- const [error] = (0, _superstruct.validate)(value.slice(_types.SnapIdPrefixes.local.length), LocalSnapIdSubUrlStruct);
165
- return error ?? true;
166
- });
167
- const NpmSnapIdStruct = (0, _superstruct.intersection)([
168
- BaseSnapIdStruct,
169
- (0, _types.uri)({
170
- protocol: (0, _superstruct.literal)(_types.SnapIdPrefixes.npm),
171
- pathname: (0, _superstruct.refine)((0, _superstruct.string)(), 'package name', function*(value) {
172
- const normalized = value.startsWith('/') ? value.slice(1) : value;
173
- const { errors, validForNewPackages, warnings } = (0, _validatenpmpackagename.default)(normalized);
174
- if (!validForNewPackages) {
175
- if (errors === undefined) {
176
- (0, _utils.assert)(warnings !== undefined);
177
- yield* warnings;
178
- } else {
179
- yield* errors;
180
- }
181
- }
182
- return true;
183
- }),
184
- search: (0, _superstruct.empty)((0, _superstruct.string)()),
185
- hash: (0, _superstruct.empty)((0, _superstruct.string)())
186
- })
187
- ]);
188
- const HttpSnapIdStruct = (0, _superstruct.intersection)([
189
- BaseSnapIdStruct,
190
- (0, _types.uri)({
191
- protocol: (0, _superstruct.enums)([
192
- 'http:',
193
- 'https:'
194
- ]),
195
- search: (0, _superstruct.empty)((0, _superstruct.string)()),
196
- hash: (0, _superstruct.empty)((0, _superstruct.string)())
197
- })
198
- ]);
199
- const SnapIdStruct = (0, _superstruct.union)([
200
- NpmSnapIdStruct,
201
- LocalSnapIdStruct
202
- ]);
203
- function getSnapPrefix(snapId) {
204
- const prefix = Object.values(_types.SnapIdPrefixes).find((possiblePrefix)=>snapId.startsWith(possiblePrefix));
205
- if (prefix !== undefined) {
206
- return prefix;
207
- }
208
- throw new Error(`Invalid or no prefix found for "${snapId}"`);
209
- }
210
- function stripSnapPrefix(snapId) {
211
- return snapId.replace(getSnapPrefix(snapId), '');
212
- }
213
- function assertIsValidSnapId(value) {
214
- (0, _utils.assertStruct)(value, SnapIdStruct, 'Invalid snap ID');
215
- }
216
- function isCaipChainId(chainId) {
217
- return typeof chainId === 'string' && RegExp("^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$", "u").test(chainId);
218
- }
219
- function isSnapPermitted(permissions, snapId) {
220
- return Boolean((permissions?.wallet_snap?.caveats?.find((caveat)=>caveat.type === _caveats.SnapCaveatType.SnapIds) ?? {}).value?.[snapId]);
221
- }
222
- function verifyRequestedSnapPermissions(requestedPermissions) {
223
- (0, _utils.assert)((0, _utils.isObject)(requestedPermissions), 'Requested permissions must be an object.');
224
- const { wallet_snap: walletSnapPermission } = requestedPermissions;
225
- (0, _utils.assert)((0, _utils.isObject)(walletSnapPermission), 'wallet_snap is missing from the requested permissions.');
226
- const { caveats } = walletSnapPermission;
227
- (0, _utils.assert)(Array.isArray(caveats) && caveats.length === 1, 'wallet_snap must have a caveat property with a single-item array value.');
228
- const [caveat] = caveats;
229
- (0, _utils.assert)((0, _utils.isObject)(caveat) && caveat.type === _caveats.SnapCaveatType.SnapIds && (0, _utils.isObject)(caveat.value), `The requested permissions do not have a valid ${_caveats.SnapCaveatType.SnapIds} caveat.`);
230
- }
231
-
232
- //# sourceMappingURL=snaps.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/snaps.ts"],"sourcesContent":["import type {\n Caveat,\n SubjectPermissions,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport type { BlockReason } from '@metamask/snaps-registry';\nimport type { SnapId, Snap as TruncatedSnap } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assert, isObject, assertStruct } from '@metamask/utils';\nimport { base64 } from '@scure/base';\nimport stableStringify from 'fast-json-stable-stringify';\nimport type { Struct } from 'superstruct';\nimport {\n empty,\n enums,\n intersection,\n literal,\n pattern,\n refine,\n string,\n union,\n validate,\n} from 'superstruct';\nimport validateNPMPackage from 'validate-npm-package-name';\n\nimport { SnapCaveatType } from './caveats';\nimport { checksumFiles } from './checksum';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest, SnapPermissions } from './manifest/validation';\nimport type { FetchedSnapFiles, SnapsPermissionRequest } from './types';\nimport { SnapIdPrefixes, SnapValidationFailureReason, uri } from './types';\nimport type { VirtualFile } from './virtual-file';\n\n// This RegEx matches valid npm package names (with some exceptions) and space-\n// separated alphanumerical words, optionally with dashes and underscores.\n// The RegEx consists of two parts. The first part matches space-separated\n// words. It is based on the following Stackoverflow answer:\n// https://stackoverflow.com/a/34974982\n// The second part, after the pipe operator, is the same RegEx used for the\n// `name` field of the official package.json JSON Schema, except that we allow\n// mixed-case letters. It was originally copied from:\n// https://github.com/SchemaStore/schemastore/blob/81a16897c1dabfd98c72242a5fd62eb080ff76d8/src/schemas/json/package.json#L132-L138\nexport const PROPOSED_NAME_REGEX =\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u;\n\nexport enum SnapStatus {\n Installing = 'installing',\n Updating = 'updating',\n Running = 'running',\n Stopped = 'stopped',\n Crashed = 'crashed',\n}\n\nexport enum SnapStatusEvents {\n Start = 'START',\n Stop = 'STOP',\n Crash = 'CRASH',\n Update = 'UPDATE',\n}\n\nexport type StatusContext = { snapId: SnapId };\nexport type StatusEvents = { type: SnapStatusEvents };\nexport type StatusStates = {\n value: SnapStatus;\n context: StatusContext;\n};\nexport type Status = StatusStates['value'];\n\nexport type VersionHistory = {\n origin: string;\n version: string;\n // Unix timestamp\n date: number;\n};\n\nexport type SnapAuxilaryFile = {\n path: string;\n // Value here should be stored as base64\n value: string;\n};\n\nexport type PersistedSnap = Snap;\n\n/**\n * A Snap as it exists in {@link SnapController} state.\n */\nexport type Snap = TruncatedSnap & {\n /**\n * The initial permissions of the Snap, which will be requested when it is\n * installed.\n */\n initialPermissions: SnapPermissions;\n\n /**\n * The source code of the Snap.\n */\n sourceCode: string;\n\n /**\n * The Snap's manifest file.\n */\n manifest: SnapManifest;\n\n /**\n * Information detailing why the snap is blocked.\n */\n blockInformation?: BlockReason;\n\n /**\n * The current status of the Snap, e.g. whether it's running or stopped.\n */\n status: Status;\n\n /**\n * The version history of the Snap.\n * Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.\n */\n versionHistory: VersionHistory[];\n\n /**\n * Static auxiliary files that can be loaded at runtime.\n */\n auxiliaryFiles?: SnapAuxilaryFile[];\n\n /**\n * Localization files which are used to translate the manifest.\n */\n localizationFiles?: LocalizationFile[];\n\n /**\n * Flag to signal whether this snap was preinstalled or not.\n *\n * A lack of specifying this option will be deemed as not preinstalled.\n */\n preinstalled?: boolean;\n\n /**\n * Flag to signal whether this snap is removable or not.\n *\n * A lack of specifying this option will be deemed as removable.\n */\n removable?: boolean;\n};\n\nexport type TruncatedSnapFields =\n | 'id'\n | 'initialPermissions'\n | 'version'\n | 'enabled'\n | 'blocked';\n\n/**\n * An error indicating that a Snap validation failure is programmatically\n * fixable during development.\n */\nexport class ProgrammaticallyFixableSnapError extends Error {\n reason: SnapValidationFailureReason;\n\n constructor(message: string, reason: SnapValidationFailureReason) {\n super(message);\n this.reason = reason;\n }\n}\n\n/**\n * Gets a checksummable manifest by removing the shasum property and reserializing the JSON using a deterministic algorithm.\n *\n * @param manifest - The manifest itself.\n * @returns A virtual file containing the checksummable manifest.\n */\nfunction getChecksummableManifest(\n manifest: VirtualFile<SnapManifest>,\n): VirtualFile {\n const manifestCopy = manifest.clone() as VirtualFile<any>;\n delete manifestCopy.result.source.shasum;\n\n // We use fast-json-stable-stringify to deterministically serialize the JSON\n // This is required before checksumming so we get reproducible checksums across platforms etc\n manifestCopy.value = stableStringify(manifestCopy.result);\n return manifestCopy;\n}\n\n/**\n * Calculates the Base64-encoded SHA-256 digest of all required Snap files.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @returns The Base64-encoded SHA-256 digest of the source code.\n */\nexport async function getSnapChecksum(\n files: FetchedSnapFiles,\n): Promise<string> {\n const { manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles } =\n files;\n\n const all = [\n getChecksummableManifest(manifest),\n sourceCode,\n svgIcon,\n ...auxiliaryFiles,\n ...localizationFiles,\n ].filter((file) => file !== undefined);\n\n return base64.encode(await checksumFiles(all as VirtualFile[]));\n}\n\n/**\n * Checks whether the `source.shasum` property of a Snap manifest matches the\n * shasum of the snap.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @param errorMessage - The error message to throw if validation fails.\n */\nexport async function validateSnapShasum(\n files: FetchedSnapFiles,\n errorMessage = 'Invalid Snap manifest: manifest shasum does not match computed shasum.',\n): Promise<void> {\n if (files.manifest.result.source.shasum !== (await getSnapChecksum(files))) {\n throw new ProgrammaticallyFixableSnapError(\n errorMessage,\n SnapValidationFailureReason.ShasumMismatch,\n );\n }\n}\n\nexport const LOCALHOST_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]'] as const;\n\n// Require snap ids to only consist of printable ASCII characters\nexport const BaseSnapIdStruct = pattern(string(), /^[\\x21-\\x7E]*$/u);\n\nconst LocalSnapIdSubUrlStruct = uri({\n protocol: enums(['http:', 'https:']),\n hostname: enums(LOCALHOST_HOSTNAMES),\n hash: empty(string()),\n search: empty(string()),\n});\n\nexport const LocalSnapIdStruct = refine(\n BaseSnapIdStruct,\n 'local Snap Id',\n (value) => {\n if (!value.startsWith(SnapIdPrefixes.local)) {\n return `Expected local snap ID, got \"${value}\".`;\n }\n\n const [error] = validate(\n value.slice(SnapIdPrefixes.local.length),\n LocalSnapIdSubUrlStruct,\n );\n return error ?? true;\n },\n);\nexport const NpmSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: literal(SnapIdPrefixes.npm),\n pathname: refine(string(), 'package name', function* (value) {\n const normalized = value.startsWith('/') ? value.slice(1) : value;\n const { errors, validForNewPackages, warnings } =\n validateNPMPackage(normalized);\n if (!validForNewPackages) {\n if (errors === undefined) {\n assert(warnings !== undefined);\n yield* warnings;\n } else {\n yield* errors;\n }\n }\n return true;\n }),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const HttpSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: enums(['http:', 'https:']),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const SnapIdStruct = union([NpmSnapIdStruct, LocalSnapIdStruct]);\n\n/**\n * Extracts the snap prefix from a snap ID.\n *\n * @param snapId - The snap ID to extract the prefix from.\n * @returns The snap prefix from a snap id, e.g. `npm:`.\n */\nexport function getSnapPrefix(snapId: string): SnapIdPrefixes {\n const prefix = Object.values(SnapIdPrefixes).find((possiblePrefix) =>\n snapId.startsWith(possiblePrefix),\n );\n if (prefix !== undefined) {\n return prefix;\n }\n throw new Error(`Invalid or no prefix found for \"${snapId}\"`);\n}\n\n/**\n * Strips snap prefix from a full snap ID.\n *\n * @param snapId - The snap ID to strip.\n * @returns The stripped snap ID.\n */\nexport function stripSnapPrefix(snapId: string): string {\n return snapId.replace(getSnapPrefix(snapId), '');\n}\n\n/**\n * Assert that the given value is a valid snap ID.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid snap ID.\n */\nexport function assertIsValidSnapId(value: unknown): asserts value is SnapId {\n assertStruct(value, SnapIdStruct, 'Invalid snap ID');\n}\n\n/**\n * Typeguard to ensure a chainId follows the CAIP-2 standard.\n *\n * @param chainId - The chainId being tested.\n * @returns `true` if the value is a valid CAIP chain id, and `false` otherwise.\n */\nexport function isCaipChainId(chainId: unknown): chainId is string {\n return (\n typeof chainId === 'string' &&\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u.test(\n chainId,\n )\n );\n}\n\n/**\n * Utility function to check if an origin has permission (and caveat) for a particular snap.\n *\n * @param permissions - An origin's permissions object.\n * @param snapId - The id of the snap.\n * @returns A boolean based on if an origin has the specified snap.\n */\nexport function isSnapPermitted(\n permissions: SubjectPermissions<PermissionConstraint>,\n snapId: SnapId,\n) {\n return Boolean(\n (\n (\n (permissions?.wallet_snap?.caveats?.find(\n (caveat) => caveat.type === SnapCaveatType.SnapIds,\n ) ?? {}) as Caveat<string, Json>\n ).value as Record<string, unknown>\n )?.[snapId],\n );\n}\n\n/**\n * Checks whether the passed in requestedPermissions is a valid\n * permission request for a `wallet_snap` permission.\n *\n * @param requestedPermissions - The requested permissions.\n * @throws If the criteria is not met.\n */\nexport function verifyRequestedSnapPermissions(\n requestedPermissions: unknown,\n): asserts requestedPermissions is SnapsPermissionRequest {\n assert(\n isObject(requestedPermissions),\n 'Requested permissions must be an object.',\n );\n\n const { wallet_snap: walletSnapPermission } = requestedPermissions;\n\n assert(\n isObject(walletSnapPermission),\n 'wallet_snap is missing from the requested permissions.',\n );\n\n const { caveats } = walletSnapPermission;\n\n assert(\n Array.isArray(caveats) && caveats.length === 1,\n 'wallet_snap must have a caveat property with a single-item array value.',\n );\n\n const [caveat] = caveats;\n\n assert(\n isObject(caveat) &&\n caveat.type === SnapCaveatType.SnapIds &&\n isObject(caveat.value),\n `The requested permissions do not have a valid ${SnapCaveatType.SnapIds} caveat.`,\n );\n}\n\nexport type { Snap as TruncatedSnap } from '@metamask/snaps-sdk';\n"],"names":["PROPOSED_NAME_REGEX","ProgrammaticallyFixableSnapError","getSnapChecksum","validateSnapShasum","LOCALHOST_HOSTNAMES","BaseSnapIdStruct","LocalSnapIdStruct","NpmSnapIdStruct","HttpSnapIdStruct","SnapIdStruct","getSnapPrefix","stripSnapPrefix","assertIsValidSnapId","isCaipChainId","isSnapPermitted","verifyRequestedSnapPermissions","SnapStatus","Installing","Updating","Running","Stopped","Crashed","SnapStatusEvents","Start","Stop","Crash","Update","Error","constructor","message","reason","getChecksummableManifest","manifest","manifestCopy","clone","result","source","shasum","value","stableStringify","files","sourceCode","svgIcon","auxiliaryFiles","localizationFiles","all","filter","file","undefined","base64","encode","checksumFiles","errorMessage","SnapValidationFailureReason","ShasumMismatch","pattern","string","LocalSnapIdSubUrlStruct","uri","protocol","enums","hostname","hash","empty","search","refine","startsWith","SnapIdPrefixes","local","error","validate","slice","length","intersection","literal","npm","pathname","normalized","errors","validForNewPackages","warnings","validateNPMPackage","assert","union","snapId","prefix","Object","values","find","possiblePrefix","replace","assertStruct","chainId","test","permissions","Boolean","wallet_snap","caveats","caveat","type","SnapCaveatType","SnapIds","requestedPermissions","isObject","walletSnapPermission","Array","isArray"],"mappings":";;;;;;;;;;;;;;;;;IA0CaA,mBAAmB;eAAnBA;;IAiHAC,gCAAgC;eAAhCA;;IAiCSC,eAAe;eAAfA;;IAwBAC,kBAAkB;eAAlBA;;IAYTC,mBAAmB;eAAnBA;;IAGAC,gBAAgB;eAAhBA;;IASAC,iBAAiB;eAAjBA;;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OAAOW,QAEH,AACGD,CAAAA,aAAaE,aAAaC,SAAST,KAClC,CAACU,SAAWA,OAAOC,IAAI,KAAKC,uBAAc,CAACC,OAAO,KAC/C,CAAC,CAAA,EACN/D,KAAK,EACN,CAAC8C,OAAO;AAEf;AASO,SAASrE,+BACduF,oBAA6B;IAE7BpB,IAAAA,aAAM,EACJqB,IAAAA,eAAQ,EAACD,uBACT;IAGF,MAAM,EAAEN,aAAaQ,oBAAoB,EAAE,GAAGF;IAE9CpB,IAAAA,aAAM,EACJqB,IAAAA,eAAQ,EAACC,uBACT;IAGF,MAAM,EAAEP,OAAO,EAAE,GAAGO;IAEpBtB,IAAAA,aAAM,EACJuB,MAAMC,OAAO,CAACT,YAAYA,QAAQzB,MAAM,KAAK,GAC7C;IAGF,MAAM,CAAC0B,OAAO,GAAGD;IAEjBf,IAAAA,aAAM,EACJqB,IAAAA,eAAQ,EAACL,WACPA,OAAOC,IAAI,KAAKC,uBAAc,CAACC,OAAO,IACtCE,IAAAA,eAAQ,EAACL,OAAO5D,KAAK,GACvB,CAAC,8CAA8C,EAAE8D,uBAAc,CAACC,OAAO,CAAC,QAAQ,CAAC;AAErF"}
@@ -1,21 +0,0 @@
1
- /**
2
- * Indent a message by adding a number of spaces to the beginning of each line.
3
- *
4
- * @param message - The message to indent.
5
- * @param spaces - The number of spaces to indent by. Defaults to 2.
6
- * @returns The indented message.
7
- */ "use strict";
8
- Object.defineProperty(exports, "__esModule", {
9
- value: true
10
- });
11
- Object.defineProperty(exports, "indent", {
12
- enumerable: true,
13
- get: function() {
14
- return indent;
15
- }
16
- });
17
- function indent(message, spaces = 2) {
18
- return message.replace(/^/gmu, ' '.repeat(spaces));
19
- }
20
-
21
- //# sourceMappingURL=strings.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/strings.ts"],"sourcesContent":["/**\n * Indent a message by adding a number of spaces to the beginning of each line.\n *\n * @param message - The message to indent.\n * @param spaces - The number of spaces to indent by. Defaults to 2.\n * @returns The indented message.\n */\nexport function indent(message: string, spaces = 2) {\n return message.replace(/^/gmu, ' '.repeat(spaces));\n}\n"],"names":["indent","message","spaces","replace","repeat"],"mappings":"AAAA;;;;;;CAMC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,OAAOC,OAAe,EAAEC,SAAS,CAAC;IAChD,OAAOD,QAAQE,OAAO,CAAC,QAAQ,IAAIC,MAAM,CAACF;AAC5C"}
@@ -1,210 +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
- file: function() {
13
- return file;
14
- },
15
- named: function() {
16
- return named;
17
- },
18
- SnapsStructError: function() {
19
- return SnapsStructError;
20
- },
21
- arrayToGenerator: function() {
22
- return arrayToGenerator;
23
- },
24
- getError: function() {
25
- return getError;
26
- },
27
- createFromStruct: function() {
28
- return createFromStruct;
29
- },
30
- getStructFromPath: function() {
31
- return getStructFromPath;
32
- },
33
- getUnionStructNames: function() {
34
- return getUnionStructNames;
35
- },
36
- getStructErrorPrefix: function() {
37
- return getStructErrorPrefix;
38
- },
39
- getStructFailureMessage: function() {
40
- return getStructFailureMessage;
41
- },
42
- getStructErrorMessage: function() {
43
- return getStructErrorMessage;
44
- },
45
- validateUnion: function() {
46
- return validateUnion;
47
- },
48
- createUnion: function() {
49
- return createUnion;
50
- }
51
- });
52
- const _snapssdk = require("@metamask/snaps-sdk");
53
- const _utils = require("@metamask/utils");
54
- const _chalk = require("chalk");
55
- const _path = require("path");
56
- const _superstruct = require("superstruct");
57
- const _strings = require("./strings");
58
- /**
59
- * Colorize a value with a color function. This is useful for colorizing values
60
- * in error messages. If colorization is disabled, the original value is
61
- * returned.
62
- *
63
- * @param value - The value to colorize.
64
- * @param colorFunction - The color function to use.
65
- * @param enabled - Whether to colorize the value.
66
- * @returns The colorized value, or the original value if colorization is
67
- * disabled.
68
- */ function color(value, colorFunction, enabled) {
69
- if (enabled) {
70
- return colorFunction(value);
71
- }
72
- return value;
73
- }
74
- function file() {
75
- return (0, _superstruct.coerce)((0, _superstruct.string)(), (0, _superstruct.string)(), (value)=>{
76
- return (0, _path.resolve)(process.cwd(), value);
77
- });
78
- }
79
- function named(name, struct) {
80
- return new _superstruct.Struct({
81
- ...struct,
82
- type: name
83
- });
84
- }
85
- class SnapsStructError extends _superstruct.StructError {
86
- constructor(struct, prefix, suffix, failure, failures, colorize = true){
87
- super(failure, failures);
88
- this.name = 'SnapsStructError';
89
- this.message = `${prefix}.\n\n${getStructErrorMessage(struct, [
90
- ...failures()
91
- ], colorize)}${suffix ? `\n\n${suffix}` : ''}`;
92
- }
93
- }
94
- function* arrayToGenerator(array) {
95
- for (const item of array){
96
- yield item;
97
- }
98
- }
99
- function getError({ struct, prefix, suffix = '', error, colorize }) {
100
- return new SnapsStructError(struct, prefix, suffix, error, ()=>arrayToGenerator(error.failures()), colorize);
101
- }
102
- function createFromStruct(value, struct, prefix, suffix = '') {
103
- try {
104
- return (0, _superstruct.create)(value, struct);
105
- } catch (error) {
106
- if (error instanceof _superstruct.StructError) {
107
- throw getError({
108
- struct,
109
- prefix,
110
- suffix,
111
- error
112
- });
113
- }
114
- throw error;
115
- }
116
- }
117
- function getStructFromPath(struct, path) {
118
- return path.reduce((result, key)=>{
119
- if ((0, _utils.isObject)(struct.schema) && struct.schema[key]) {
120
- return struct.schema[key];
121
- }
122
- return result;
123
- }, struct);
124
- }
125
- function getUnionStructNames(struct, colorize = true) {
126
- if (Array.isArray(struct.schema)) {
127
- return struct.schema.map(({ type })=>color(type, _chalk.green, colorize));
128
- }
129
- return null;
130
- }
131
- function getStructErrorPrefix(failure, colorize = true) {
132
- if (failure.type === 'never' || failure.path.length === 0) {
133
- return '';
134
- }
135
- return `At path: ${color(failure.path.join('.'), _chalk.bold, colorize)} — `;
136
- }
137
- function getStructFailureMessage(struct, failure, colorize = true) {
138
- const received = color(JSON.stringify(failure.value), _chalk.red, colorize);
139
- const prefix = getStructErrorPrefix(failure, colorize);
140
- if (failure.type === 'union') {
141
- const childStruct = getStructFromPath(struct, failure.path);
142
- const unionNames = getUnionStructNames(childStruct, colorize);
143
- if (unionNames) {
144
- return `${prefix}Expected the value to be one of: ${unionNames.join(', ')}, but received: ${received}.`;
145
- }
146
- return `${prefix}${failure.message}.`;
147
- }
148
- if (failure.type === 'literal') {
149
- // Superstruct's failure does not provide information about which literal
150
- // value was expected, so we need to parse the message to get the literal.
151
- const message = failure.message.replace(/the literal `(.+)`,/u, `the value to be \`${color('$1', _chalk.green, colorize)}\`,`).replace(/, but received: (.+)/u, `, but received: ${color('$1', _chalk.red, colorize)}`);
152
- return `${prefix}${message}.`;
153
- }
154
- if (failure.type === 'never') {
155
- return `Unknown key: ${color(failure.path.join('.'), _chalk.bold, colorize)}, received: ${received}.`;
156
- }
157
- if (failure.refinement === 'size') {
158
- const message = failure.message.replace(/length between `(\d+)` and `(\d+)`/u, `length between ${color('$1', _chalk.green, colorize)} and ${color('$2', _chalk.green, colorize)},`).replace(/length of `(\d+)`/u, `length of ${color('$1', _chalk.red, colorize)}`).replace(/a array/u, 'an array');
159
- return `${prefix}${message}.`;
160
- }
161
- return `${prefix}Expected a value of type ${color(failure.type, _chalk.green, colorize)}, but received: ${received}.`;
162
- }
163
- function getStructErrorMessage(struct, failures, colorize = true) {
164
- const formattedFailures = failures.map((failure)=>(0, _strings.indent)(`• ${getStructFailureMessage(struct, failure, colorize)}`));
165
- return formattedFailures.join('\n');
166
- }
167
- function validateUnion(value, struct, structKey, coerce = false) {
168
- (0, _utils.assert)(struct.schema, 'Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`.');
169
- (0, _utils.assert)(struct.schema.length > 0, 'Expected a non-empty array of structs.');
170
- const keyUnion = struct.schema.map((innerStruct)=>innerStruct.schema[structKey]);
171
- const key = (0, _superstruct.type)({
172
- [structKey]: (0, _snapssdk.union)(keyUnion)
173
- });
174
- const [keyError] = (0, _superstruct.validate)(value, key, {
175
- coerce
176
- });
177
- if (keyError) {
178
- throw new Error(getStructFailureMessage(key, keyError.failures()[0], false));
179
- }
180
- // At this point it's guaranteed that the value is an object, so we can safely
181
- // cast it to a Record.
182
- const objectValue = value;
183
- const objectStructs = struct.schema.filter((innerStruct)=>(0, _superstruct.is)(objectValue[structKey], innerStruct.schema[structKey]));
184
- (0, _utils.assert)(objectStructs.length > 0, 'Expected a struct to match the value.');
185
- // We need to validate the value against all the object structs that match the
186
- // struct key, and return the first validated value.
187
- const validationResults = objectStructs.map((objectStruct)=>(0, _superstruct.validate)(objectValue, objectStruct, {
188
- coerce
189
- }));
190
- const validatedValue = validationResults.find(([error])=>!error);
191
- if (validatedValue) {
192
- return validatedValue[1];
193
- }
194
- (0, _utils.assert)(validationResults[0][0], 'Expected at least one error.');
195
- // If there is no validated value, we need to find the error with the least
196
- // number of failures (with the assumption that it's the most specific error).
197
- const validationError = validationResults.reduce((error, [innerError])=>{
198
- (0, _utils.assert)(innerError, 'Expected an error.');
199
- if (innerError.failures().length < error.failures().length) {
200
- return innerError;
201
- }
202
- return error;
203
- }, validationResults[0][0]);
204
- throw new Error(getStructFailureMessage(struct, validationError.failures()[0], false));
205
- }
206
- function createUnion(value, struct, structKey) {
207
- return validateUnion(value, struct, structKey, true);
208
- }
209
-
210
- //# sourceMappingURL=structs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/structs.ts"],"sourcesContent":["import { union } from '@metamask/snaps-sdk';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert, isObject } from '@metamask/utils';\nimport { bold, green, red } from 'chalk';\nimport { resolve } from 'path';\nimport type { Failure } from 'superstruct';\nimport {\n is,\n validate,\n type as superstructType,\n Struct,\n StructError,\n create,\n string,\n coerce as superstructCoerce,\n} from 'superstruct';\nimport type { AnyStruct } from 'superstruct/dist/utils';\n\nimport { indent } from './strings';\n\n/**\n * Infer a struct type, only if it matches the specified type. This is useful\n * for defining types and structs that are related to each other in separate\n * files.\n *\n * @example\n * ```typescript\n * // In file A\n * export type GetFileArgs = {\n * path: string;\n * encoding?: EnumToUnion<AuxiliaryFileEncoding>;\n * };\n *\n * // In file B\n * export const GetFileArgsStruct = object(...);\n *\n * // If the type and struct are in the same file, this will return the type.\n * // Otherwise, it will return `never`.\n * export type GetFileArgs =\n * InferMatching<typeof GetFileArgsStruct, GetFileArgs>;\n * ```\n */\nexport type InferMatching<\n StructType extends Struct<any, any>,\n Type,\n> = StructType['TYPE'] extends Type ? Type : never;\n\n/**\n * Colorize a value with a color function. This is useful for colorizing values\n * in error messages. If colorization is disabled, the original value is\n * returned.\n *\n * @param value - The value to colorize.\n * @param colorFunction - The color function to use.\n * @param enabled - Whether to colorize the value.\n * @returns The colorized value, or the original value if colorization is\n * disabled.\n */\nfunction color(\n value: string,\n colorFunction: (value: string) => string,\n enabled: boolean,\n) {\n if (enabled) {\n return colorFunction(value);\n }\n\n return value;\n}\n\n/**\n * A wrapper of `superstruct`'s `string` struct that coerces a value to a string\n * and resolves it relative to the current working directory. This is useful\n * for specifying file paths in a configuration file, as it allows the user to\n * use both relative and absolute paths.\n *\n * @returns The `superstruct` struct, which validates that the value is a\n * string, and resolves it relative to the current working directory.\n * @example\n * ```ts\n * const config = struct({\n * file: file(),\n * // ...\n * });\n *\n * const value = create({ file: 'path/to/file' }, config);\n * console.log(value.file); // /process/cwd/path/to/file\n * ```\n */\nexport function file() {\n return superstructCoerce(string(), string(), (value) => {\n return resolve(process.cwd(), value);\n });\n}\n\n/**\n * Define a struct, and also define the name of the struct as the given name.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n *\n * @param name - The name of the struct.\n * @param struct - The struct.\n * @returns The struct.\n */\nexport function named<Type, Schema>(\n name: string,\n struct: Struct<Type, Schema>,\n) {\n return new Struct({\n ...struct,\n type: name,\n });\n}\n\nexport class SnapsStructError<Type, Schema> extends StructError {\n constructor(\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix: string,\n failure: StructError,\n failures: () => Generator<Failure>,\n colorize = true,\n ) {\n super(failure, failures);\n\n this.name = 'SnapsStructError';\n this.message = `${prefix}.\\n\\n${getStructErrorMessage(\n struct,\n [...failures()],\n colorize,\n )}${suffix ? `\\n\\n${suffix}` : ''}`;\n }\n}\n\ntype GetErrorOptions<Type, Schema> = {\n struct: Struct<Type, Schema>;\n prefix: string;\n suffix?: string;\n error: StructError;\n colorize?: boolean;\n};\n\n/**\n * Converts an array to a generator function that yields the items in the\n * array.\n *\n * @param array - The array.\n * @returns A generator function.\n * @yields The items in the array.\n */\nexport function* arrayToGenerator<Type>(\n array: Type[],\n): Generator<Type, void, undefined> {\n for (const item of array) {\n yield item;\n }\n}\n\n/**\n * Returns a `SnapsStructError` with the given prefix and suffix.\n *\n * @param options - The options.\n * @param options.struct - The struct that caused the error.\n * @param options.prefix - The prefix to add to the error message.\n * @param options.suffix - The suffix to add to the error message. Defaults to\n * an empty string.\n * @param options.error - The `superstruct` error to wrap.\n * @param options.colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The `SnapsStructError`.\n */\nexport function getError<Type, Schema>({\n struct,\n prefix,\n suffix = '',\n error,\n colorize,\n}: GetErrorOptions<Type, Schema>) {\n return new SnapsStructError(\n struct,\n prefix,\n suffix,\n error,\n () => arrayToGenerator(error.failures()),\n colorize,\n );\n}\n\n/**\n * A wrapper of `superstruct`'s `create` function that throws a\n * `SnapsStructError` instead of a `StructError`. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` struct to validate the value against.\n * @param prefix - The prefix to add to the error message.\n * @param suffix - The suffix to add to the error message. Defaults to an empty\n * string.\n * @returns The validated value.\n */\nexport function createFromStruct<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix = '',\n) {\n try {\n return create(value, struct);\n } catch (error) {\n if (error instanceof StructError) {\n throw getError({ struct, prefix, suffix, error });\n }\n\n throw error;\n }\n}\n\n/**\n * Get a struct from a failure path.\n *\n * @param struct - The struct.\n * @param path - The failure path.\n * @returns The struct at the failure path.\n */\nexport function getStructFromPath<Type, Schema>(\n struct: Struct<Type, Schema>,\n path: string[],\n) {\n return path.reduce<AnyStruct>((result, key) => {\n if (isObject(struct.schema) && struct.schema[key]) {\n return struct.schema[key] as AnyStruct;\n }\n\n return result;\n }, struct);\n}\n\n/**\n * Get the union struct names from a struct.\n *\n * @param struct - The struct.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The union struct names, or `null` if the struct is not a union\n * struct.\n */\nexport function getUnionStructNames<Type, Schema>(\n struct: Struct<Type, Schema>,\n colorize = true,\n) {\n if (Array.isArray(struct.schema)) {\n return struct.schema.map(({ type }) => color(type, green, colorize));\n }\n\n return null;\n}\n\n/**\n * Get an error prefix from a `superstruct` failure. This is useful for\n * formatting the error message returned by `superstruct`.\n *\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The error prefix.\n */\nexport function getStructErrorPrefix(failure: Failure, colorize = true) {\n if (failure.type === 'never' || failure.path.length === 0) {\n return '';\n }\n\n return `At path: ${color(failure.path.join('.'), bold, colorize)} — `;\n}\n\n/**\n * Get a string describing the failure. This is similar to the `message`\n * property of `superstruct`'s `Failure` type, but formats the value in a more\n * readable way.\n *\n * @param struct - The struct that caused the failure.\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the failure.\n */\nexport function getStructFailureMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failure: Failure,\n colorize = true,\n) {\n const received = color(JSON.stringify(failure.value), red, colorize);\n const prefix = getStructErrorPrefix(failure, colorize);\n\n if (failure.type === 'union') {\n const childStruct = getStructFromPath(struct, failure.path);\n const unionNames = getUnionStructNames(childStruct, colorize);\n\n if (unionNames) {\n return `${prefix}Expected the value to be one of: ${unionNames.join(\n ', ',\n )}, but received: ${received}.`;\n }\n\n return `${prefix}${failure.message}.`;\n }\n\n if (failure.type === 'literal') {\n // Superstruct's failure does not provide information about which literal\n // value was expected, so we need to parse the message to get the literal.\n const message = failure.message\n .replace(\n /the literal `(.+)`,/u,\n `the value to be \\`${color('$1', green, colorize)}\\`,`,\n )\n .replace(\n /, but received: (.+)/u,\n `, but received: ${color('$1', red, colorize)}`,\n );\n\n return `${prefix}${message}.`;\n }\n\n if (failure.type === 'never') {\n return `Unknown key: ${color(\n failure.path.join('.'),\n bold,\n colorize,\n )}, received: ${received}.`;\n }\n\n if (failure.refinement === 'size') {\n const message = failure.message\n .replace(\n /length between `(\\d+)` and `(\\d+)`/u,\n `length between ${color('$1', green, colorize)} and ${color(\n '$2',\n green,\n colorize,\n )},`,\n )\n .replace(/length of `(\\d+)`/u, `length of ${color('$1', red, colorize)}`)\n .replace(/a array/u, 'an array');\n\n return `${prefix}${message}.`;\n }\n\n return `${prefix}Expected a value of type ${color(\n failure.type,\n green,\n colorize,\n )}, but received: ${received}.`;\n}\n\n/**\n * Get a string describing the errors. This formats all the errors in a\n * human-readable way.\n *\n * @param struct - The struct that caused the failures.\n * @param failures - The `superstruct` failures.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the errors.\n */\nexport function getStructErrorMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failures: Failure[],\n colorize = true,\n) {\n const formattedFailures = failures.map((failure) =>\n indent(`• ${getStructFailureMessage(struct, failure, colorize)}`),\n );\n\n return formattedFailures.join('\\n');\n}\n\n/**\n * Validate a union struct, and throw readable errors if the value does not\n * satisfy the struct. This is useful for improving the error messages returned\n * by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @param coerce - Whether to coerce the value to satisfy the struct. Defaults\n * to `false`.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @example\n * const struct = union([\n * object({ type: literal('a'), value: string() }),\n * object({ type: literal('b'), value: number() }),\n * object({ type: literal('c'), value: boolean() }),\n * // ...\n * ]);\n *\n * // At path: type — Expected the value to be one of: \"a\", \"b\", \"c\", but received: \"d\".\n * validateUnion({ type: 'd', value: 'foo' }, struct, 'type');\n *\n * // At path: value — Expected a value of type string, but received: 42.\n * validateUnion({ type: 'a', value: 42 }, struct, 'value');\n */\nexport function validateUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n coerce = false,\n) {\n assert(\n struct.schema,\n 'Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`.',\n );\n assert(struct.schema.length > 0, 'Expected a non-empty array of structs.');\n\n const keyUnion = struct.schema.map(\n (innerStruct) => innerStruct.schema[structKey],\n // This is guaranteed to be a non-empty array by the assertion above. We\n // need to cast it since `superstruct` requires a non-empty array of structs\n // for the `union` struct.\n ) as NonEmptyArray<Struct>;\n\n const key = superstructType({\n [structKey]: union(keyUnion),\n });\n\n const [keyError] = validate(value, key, { coerce });\n if (keyError) {\n throw new Error(\n getStructFailureMessage(key, keyError.failures()[0], false),\n );\n }\n\n // At this point it's guaranteed that the value is an object, so we can safely\n // cast it to a Record.\n const objectValue = value as Record<PropertyKey, unknown>;\n const objectStructs = struct.schema.filter((innerStruct) =>\n is(objectValue[structKey], innerStruct.schema[structKey]),\n );\n\n assert(objectStructs.length > 0, 'Expected a struct to match the value.');\n\n // We need to validate the value against all the object structs that match the\n // struct key, and return the first validated value.\n const validationResults = objectStructs.map((objectStruct) =>\n validate(objectValue, objectStruct, { coerce }),\n );\n\n const validatedValue = validationResults.find(([error]) => !error);\n if (validatedValue) {\n return validatedValue[1];\n }\n\n assert(validationResults[0][0], 'Expected at least one error.');\n\n // If there is no validated value, we need to find the error with the least\n // number of failures (with the assumption that it's the most specific error).\n const validationError = validationResults.reduce((error, [innerError]) => {\n assert(innerError, 'Expected an error.');\n if (innerError.failures().length < error.failures().length) {\n return innerError;\n }\n\n return error;\n }, validationResults[0][0]);\n\n throw new Error(\n getStructFailureMessage(struct, validationError.failures()[0], false),\n );\n}\n\n/**\n * Create a value with the coercion logic of a union struct, and throw readable\n * errors if the value does not satisfy the struct. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @see validateUnion\n */\nexport function createUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n) {\n return validateUnion(value, struct, structKey, true);\n}\n"],"names":["file","named","SnapsStructError","arrayToGenerator","getError","createFromStruct","getStructFromPath","getUnionStructNames","getStructErrorPrefix","getStructFailureMessage","getStructErrorMessage","validateUnion","createUnion","color","value","colorFunction","enabled","superstructCoerce","string","resolve","process","cwd","name","struct","Struct","type","StructError","constructor","prefix","suffix","failure","failures","colorize","message","array","item","error","create","path","reduce","result","key","isObject","schema","Array","isArray","map","green","length","join","bold","received","JSON","stringify","red","childStruct","unionNames","replace","refinement","formattedFailures","indent","structKey","coerce","assert","keyUnion","innerStruct","superstructType","union","keyError","validate","Error","objectValue","objectStructs","filter","is","validationResults","objectStruct","validatedValue","find","validationError","innerError"],"mappings":";;;;;;;;;;;IAyFgBA,IAAI;eAAJA;;IAeAC,KAAK;eAALA;;IAUHC,gBAAgB;eAAhBA;;IAoCIC,gBAAgB;eAAhBA;;IAoBDC,QAAQ;eAARA;;IA6BAC,gBAAgB;eAAhBA;;IAwBAC,iBAAiB;eAAjBA;;IAqBAC,mBAAmB;eAAnBA;;IAmBAC,oBAAoB;eAApBA;;IAkBAC,uBAAuB;eAAvBA;;IA6EAC,qBAAqB;eAArBA;;IA0CAC,aAAa;eAAbA;;I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B,eAC3CP,IAAAA,qBAAQ,EAACE,aAAaK,cAAc;YAAEd;QAAO;IAG/C,MAAMe,iBAAiBF,kBAAkBG,IAAI,CAAC,CAAC,CAAC1C,MAAM,GAAK,CAACA;IAC5D,IAAIyC,gBAAgB;QAClB,OAAOA,cAAc,CAAC,EAAE;IAC1B;IAEAd,IAAAA,aAAM,EAACY,iBAAiB,CAAC,EAAE,CAAC,EAAE,EAAE;IAEhC,2EAA2E;IAC3E,8EAA8E;IAC9E,MAAMI,kBAAkBJ,kBAAkBpC,MAAM,CAAC,CAACH,OAAO,CAAC4C,WAAW;QACnEjB,IAAAA,aAAM,EAACiB,YAAY;QACnB,IAAIA,WAAWjD,QAAQ,GAAGiB,MAAM,GAAGZ,MAAML,QAAQ,GAAGiB,MAAM,EAAE;YAC1D,OAAOgC;QACT;QAEA,OAAO5C;IACT,GAAGuC,iBAAiB,CAAC,EAAE,CAAC,EAAE;IAE1B,MAAM,IAAIL,MACR7D,wBAAwBc,QAAQwD,gBAAgBhD,QAAQ,EAAE,CAAC,EAAE,EAAE;AAEnE;AAkBO,SAASnB,YACdE,KAAc,EACdS,MAA4B,EAC5BsC,SAAqB;IAErB,OAAOlD,cAAcG,OAAOS,QAAQsC,WAAW;AACjD"}
package/dist/cjs/types.js DELETED
@@ -1,104 +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
- NpmSnapFileNames: function() {
13
- return NpmSnapFileNames;
14
- },
15
- SnapIdPrefixes: function() {
16
- return SnapIdPrefixes;
17
- },
18
- SnapValidationFailureReason: function() {
19
- return SnapValidationFailureReason;
20
- },
21
- SNAP_STREAM_NAMES: function() {
22
- return SNAP_STREAM_NAMES;
23
- },
24
- NameStruct: function() {
25
- return NameStruct;
26
- },
27
- NpmSnapPackageJsonStruct: function() {
28
- return NpmSnapPackageJsonStruct;
29
- },
30
- isNpmSnapPackageJson: function() {
31
- return isNpmSnapPackageJson;
32
- },
33
- assertIsNpmSnapPackageJson: function() {
34
- return assertIsNpmSnapPackageJson;
35
- },
36
- uri: function() {
37
- return uri;
38
- },
39
- isValidUrl: function() {
40
- return isValidUrl;
41
- },
42
- WALLET_SNAP_PERMISSION_KEY: function() {
43
- return WALLET_SNAP_PERMISSION_KEY;
44
- }
45
- });
46
- const _utils = require("@metamask/utils");
47
- const _superstruct = require("superstruct");
48
- var NpmSnapFileNames;
49
- (function(NpmSnapFileNames) {
50
- NpmSnapFileNames["PackageJson"] = 'package.json';
51
- NpmSnapFileNames["Manifest"] = 'snap.manifest.json';
52
- })(NpmSnapFileNames || (NpmSnapFileNames = {}));
53
- const NameStruct = (0, _superstruct.size)((0, _superstruct.pattern)((0, _superstruct.string)(), /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u), 1, 214);
54
- const NpmSnapPackageJsonStruct = (0, _superstruct.type)({
55
- version: _utils.VersionStruct,
56
- name: NameStruct,
57
- main: (0, _superstruct.optional)((0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity)),
58
- repository: (0, _superstruct.optional)((0, _superstruct.object)({
59
- type: (0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity),
60
- url: (0, _superstruct.size)((0, _superstruct.string)(), 1, Infinity)
61
- }))
62
- });
63
- function isNpmSnapPackageJson(value) {
64
- return (0, _superstruct.is)(value, NpmSnapPackageJsonStruct);
65
- }
66
- function assertIsNpmSnapPackageJson(value) {
67
- (0, _utils.assertStruct)(value, NpmSnapPackageJsonStruct, `"${NpmSnapFileNames.PackageJson}" is invalid`);
68
- }
69
- var SnapIdPrefixes;
70
- (function(SnapIdPrefixes) {
71
- SnapIdPrefixes["npm"] = 'npm:';
72
- SnapIdPrefixes["local"] = 'local:';
73
- })(SnapIdPrefixes || (SnapIdPrefixes = {}));
74
- var SnapValidationFailureReason;
75
- (function(SnapValidationFailureReason) {
76
- SnapValidationFailureReason["NameMismatch"] = '"name" field mismatch';
77
- SnapValidationFailureReason["VersionMismatch"] = '"version" field mismatch';
78
- SnapValidationFailureReason["RepositoryMismatch"] = '"repository" field mismatch';
79
- SnapValidationFailureReason["ShasumMismatch"] = '"shasum" field mismatch';
80
- })(SnapValidationFailureReason || (SnapValidationFailureReason = {}));
81
- var SNAP_STREAM_NAMES;
82
- (function(SNAP_STREAM_NAMES) {
83
- SNAP_STREAM_NAMES["JSON_RPC"] = 'jsonRpc';
84
- SNAP_STREAM_NAMES["COMMAND"] = 'command';
85
- })(SNAP_STREAM_NAMES || (SNAP_STREAM_NAMES = {}));
86
- const uri = (opts = {})=>(0, _superstruct.refine)((0, _superstruct.union)([
87
- (0, _superstruct.string)(),
88
- (0, _superstruct.instance)(URL)
89
- ]), 'uri', (value)=>{
90
- try {
91
- const url = new URL(value);
92
- const UrlStruct = (0, _superstruct.type)(opts);
93
- (0, _superstruct.assert)(url, UrlStruct);
94
- return true;
95
- } catch {
96
- return `Expected URL, got "${value.toString()}".`;
97
- }
98
- });
99
- function isValidUrl(url, opts = {}) {
100
- return (0, _superstruct.is)(url, uri(opts));
101
- }
102
- const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';
103
-
104
- //# sourceMappingURL=types.js.map