@metamask/snaps-utils 7.8.1 → 8.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 (326) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/array.js +1 -1
  3. package/dist/array.mjs +1 -1
  4. package/dist/auxiliary-files.js +1 -1
  5. package/dist/auxiliary-files.mjs +1 -1
  6. package/dist/base64.js +1 -1
  7. package/dist/base64.mjs +1 -1
  8. package/dist/bytes.js +1 -1
  9. package/dist/bytes.mjs +1 -1
  10. package/dist/caveats.js +1 -1
  11. package/dist/caveats.mjs +1 -1
  12. package/dist/checksum.js +1 -1
  13. package/dist/checksum.mjs +1 -1
  14. package/dist/{chunk-5I5WPAVD.js → chunk-37EUH3KZ.js} +13 -13
  15. package/dist/{chunk-FLSK6ISS.mjs → chunk-3N27GIUS.mjs} +4 -1
  16. package/dist/chunk-3N27GIUS.mjs.map +1 -0
  17. package/dist/{chunk-SB43G2RI.js → chunk-3OXW5H4F.js} +5 -5
  18. package/dist/{chunk-K6BCBPXF.js → chunk-3RFGTBEP.js} +11 -11
  19. package/dist/{chunk-JMDSN227.mjs → chunk-3RUWAMJT.mjs} +7 -1
  20. package/dist/chunk-4BGZ2CHC.mjs +22 -0
  21. package/dist/chunk-4BGZ2CHC.mjs.map +1 -0
  22. package/dist/chunk-4RYTYEUQ.mjs +33 -0
  23. package/dist/chunk-4RYTYEUQ.mjs.map +1 -0
  24. package/dist/{chunk-VOPTAKVG.js → chunk-53QXTM77.js} +4 -1
  25. package/dist/chunk-53QXTM77.js.map +1 -0
  26. package/dist/chunk-5FTBWYCW.mjs +27 -0
  27. package/dist/chunk-5FTBWYCW.mjs.map +1 -0
  28. package/dist/chunk-5MABKEV7.mjs +66 -0
  29. package/dist/chunk-5MABKEV7.mjs.map +1 -0
  30. package/dist/chunk-5UAPBOKO.js +37 -0
  31. package/dist/chunk-5UAPBOKO.js.map +1 -0
  32. package/dist/chunk-6YJWU77L.js +19 -0
  33. package/dist/chunk-6YJWU77L.js.map +1 -0
  34. package/dist/chunk-7T7FYH77.mjs +37 -0
  35. package/dist/chunk-7T7FYH77.mjs.map +1 -0
  36. package/dist/chunk-BPK5BH7K.js +27 -0
  37. package/dist/chunk-BPK5BH7K.js.map +1 -0
  38. package/dist/chunk-CPG2UGAA.js +25 -0
  39. package/dist/chunk-CPG2UGAA.js.map +1 -0
  40. package/dist/chunk-DKO64Y4H.mjs +27 -0
  41. package/dist/chunk-DKO64Y4H.mjs.map +1 -0
  42. package/dist/chunk-EYWMVDCD.mjs +25 -0
  43. package/dist/chunk-EYWMVDCD.mjs.map +1 -0
  44. package/dist/chunk-FA4QIZH6.js +1 -0
  45. package/dist/chunk-GIVJAZ2Q.mjs +248 -0
  46. package/dist/chunk-GIVJAZ2Q.mjs.map +1 -0
  47. package/dist/chunk-GJAVOB7B.js +24 -0
  48. package/dist/chunk-GJAVOB7B.js.map +1 -0
  49. package/dist/{chunk-ZXHR322P.mjs → chunk-GXSTPU7D.mjs} +4 -4
  50. package/dist/chunk-HY4W6BUH.mjs +24 -0
  51. package/dist/chunk-HY4W6BUH.mjs.map +1 -0
  52. package/dist/{chunk-YNOZU43P.mjs → chunk-IPUL74MZ.mjs} +3 -3
  53. package/dist/chunk-IVDERT5W.js +22 -0
  54. package/dist/chunk-IVDERT5W.js.map +1 -0
  55. package/dist/chunk-JETPRED3.js +248 -0
  56. package/dist/chunk-JETPRED3.js.map +1 -0
  57. package/dist/chunk-L2DHOOBX.js +33 -0
  58. package/dist/chunk-L2DHOOBX.js.map +1 -0
  59. package/dist/chunk-LQSEBGOX.js +34 -0
  60. package/dist/chunk-LQSEBGOX.js.map +1 -0
  61. package/dist/chunk-MDOG3S4V.mjs +34 -0
  62. package/dist/chunk-MDOG3S4V.mjs.map +1 -0
  63. package/dist/chunk-MFGLB75H.mjs +22 -0
  64. package/dist/chunk-MFGLB75H.mjs.map +1 -0
  65. package/dist/chunk-MQURBEO4.mjs +16 -0
  66. package/dist/chunk-MQURBEO4.mjs.map +1 -0
  67. package/dist/{chunk-PZNIU23I.js → chunk-MWAZGSRO.js} +2 -22
  68. package/dist/chunk-MWAZGSRO.js.map +1 -0
  69. package/dist/{chunk-AJNKQYKP.mjs → chunk-N2JAYIUP.mjs} +2 -22
  70. package/dist/chunk-N2JAYIUP.mjs.map +1 -0
  71. package/dist/chunk-N4MA537G.js +22 -0
  72. package/dist/chunk-N4MA537G.js.map +1 -0
  73. package/dist/chunk-NNYGTNHP.mjs +1 -0
  74. package/dist/{chunk-H35ZUVQT.mjs → chunk-NSVVZNSD.mjs} +3 -13
  75. package/dist/chunk-NSVVZNSD.mjs.map +1 -0
  76. package/dist/chunk-PAOTMYIM.mjs +69 -0
  77. package/dist/chunk-PAOTMYIM.mjs.map +1 -0
  78. package/dist/chunk-PO5BBHHX.mjs +22 -0
  79. package/dist/chunk-PO5BBHHX.mjs.map +1 -0
  80. package/dist/{chunk-VWGXNUMD.mjs → chunk-PZF4KWU2.mjs} +2 -2
  81. package/dist/chunk-QD3LTING.js +34 -0
  82. package/dist/chunk-QD3LTING.js.map +1 -0
  83. package/dist/chunk-RNMJQSVQ.js +69 -0
  84. package/dist/chunk-RNMJQSVQ.js.map +1 -0
  85. package/dist/chunk-RRFKK45V.mjs +15 -0
  86. package/dist/chunk-RRFKK45V.mjs.map +1 -0
  87. package/dist/{chunk-PHUTP7NB.js → chunk-S3BWTUTZ.js} +9 -3
  88. package/dist/chunk-SKKANJ45.mjs +19 -0
  89. package/dist/chunk-SKKANJ45.mjs.map +1 -0
  90. package/dist/chunk-SYYDKPK3.js +15 -0
  91. package/dist/chunk-SYYDKPK3.js.map +1 -0
  92. package/dist/chunk-T5ZOOZ46.js +22 -0
  93. package/dist/chunk-T5ZOOZ46.js.map +1 -0
  94. package/dist/{chunk-RD6BN2TQ.js → chunk-TAMKWZ4E.js} +8 -18
  95. package/dist/chunk-TAMKWZ4E.js.map +1 -0
  96. package/dist/chunk-TYWGZIOF.mjs +34 -0
  97. package/dist/chunk-TYWGZIOF.mjs.map +1 -0
  98. package/dist/chunk-VBYSWMSU.js +66 -0
  99. package/dist/chunk-VBYSWMSU.js.map +1 -0
  100. package/dist/chunk-VEPYH26P.js +27 -0
  101. package/dist/chunk-VEPYH26P.js.map +1 -0
  102. package/dist/chunk-VWLBM7XM.js +1 -0
  103. package/dist/chunk-W7A3BYUP.mjs +1 -0
  104. package/dist/chunk-YL2EHYAA.js +16 -0
  105. package/dist/chunk-YL2EHYAA.js.map +1 -0
  106. package/dist/constants.js +1 -1
  107. package/dist/constants.mjs +1 -1
  108. package/dist/cronjob.js +1 -1
  109. package/dist/cronjob.mjs +1 -1
  110. package/dist/deep-clone.js +1 -1
  111. package/dist/deep-clone.mjs +1 -1
  112. package/dist/default-endowments.js +1 -1
  113. package/dist/default-endowments.mjs +1 -1
  114. package/dist/derivation-paths.js +1 -1
  115. package/dist/derivation-paths.mjs +1 -1
  116. package/dist/entropy.js +1 -1
  117. package/dist/entropy.mjs +1 -1
  118. package/dist/errors.js +3 -3
  119. package/dist/errors.mjs +2 -2
  120. package/dist/eval-worker.js +1 -1
  121. package/dist/eval-worker.mjs +1 -1
  122. package/dist/eval.js +1 -1
  123. package/dist/eval.mjs +1 -1
  124. package/dist/fs.js +1 -1
  125. package/dist/fs.mjs +1 -1
  126. package/dist/handler-types.js +1 -1
  127. package/dist/handler-types.mjs +1 -1
  128. package/dist/handlers.js +1 -1
  129. package/dist/handlers.mjs +1 -1
  130. package/dist/icon.js +1 -1
  131. package/dist/icon.mjs +1 -1
  132. package/dist/iframe.js +1 -1
  133. package/dist/iframe.mjs +1 -1
  134. package/dist/index.executionenv.js +5 -11
  135. package/dist/index.executionenv.mjs +9 -15
  136. package/dist/index.js +11 -18
  137. package/dist/index.mjs +15 -22
  138. package/dist/json-rpc.js +1 -1
  139. package/dist/json-rpc.mjs +1 -1
  140. package/dist/json.js +1 -1
  141. package/dist/json.mjs +1 -1
  142. package/dist/localization.js +1 -1
  143. package/dist/localization.mjs +1 -1
  144. package/dist/logging.js +1 -1
  145. package/dist/logging.mjs +1 -1
  146. package/dist/manifest/index.js +6 -6
  147. package/dist/manifest/index.mjs +5 -5
  148. package/dist/manifest/manifest.js +23 -9
  149. package/dist/manifest/manifest.mjs +24 -10
  150. package/dist/manifest/node.js +23 -9
  151. package/dist/manifest/node.mjs +24 -10
  152. package/dist/manifest/validation.js +6 -6
  153. package/dist/manifest/validation.mjs +5 -5
  154. package/dist/manifest/validator-types.js +1 -0
  155. package/dist/manifest/validator-types.js.map +1 -0
  156. package/dist/manifest/validator-types.mjs +1 -0
  157. package/dist/manifest/validator-types.mjs.map +1 -0
  158. package/dist/manifest/validator.js +44 -0
  159. package/dist/manifest/validator.js.map +1 -0
  160. package/dist/manifest/validator.mjs +44 -0
  161. package/dist/manifest/validator.mjs.map +1 -0
  162. package/dist/manifest/validators/checksum.js +15 -0
  163. package/dist/manifest/validators/checksum.js.map +1 -0
  164. package/dist/manifest/validators/checksum.mjs +15 -0
  165. package/dist/manifest/validators/checksum.mjs.map +1 -0
  166. package/dist/manifest/validators/expected-files.js +9 -0
  167. package/dist/manifest/validators/expected-files.js.map +1 -0
  168. package/dist/manifest/validators/expected-files.mjs +9 -0
  169. package/dist/manifest/validators/expected-files.mjs.map +1 -0
  170. package/dist/manifest/validators/icon-declared.js +8 -0
  171. package/dist/manifest/validators/icon-declared.js.map +1 -0
  172. package/dist/manifest/validators/icon-declared.mjs +8 -0
  173. package/dist/manifest/validators/icon-declared.mjs.map +1 -0
  174. package/dist/manifest/validators/icon-dimensions.js +10 -0
  175. package/dist/manifest/validators/icon-dimensions.js.map +1 -0
  176. package/dist/manifest/validators/icon-dimensions.mjs +10 -0
  177. package/dist/manifest/validators/icon-dimensions.mjs.map +1 -0
  178. package/dist/manifest/validators/icon-missing.js +8 -0
  179. package/dist/manifest/validators/icon-missing.js.map +1 -0
  180. package/dist/manifest/validators/icon-missing.mjs +8 -0
  181. package/dist/manifest/validators/icon-missing.mjs.map +1 -0
  182. package/dist/manifest/validators/index.js +80 -0
  183. package/dist/manifest/validators/index.js.map +1 -0
  184. package/dist/manifest/validators/index.mjs +80 -0
  185. package/dist/manifest/validators/index.mjs.map +1 -0
  186. package/dist/manifest/validators/is-localization-file.js +12 -0
  187. package/dist/manifest/validators/is-localization-file.js.map +1 -0
  188. package/dist/manifest/validators/is-localization-file.mjs +12 -0
  189. package/dist/manifest/validators/is-localization-file.mjs.map +1 -0
  190. package/dist/manifest/validators/is-package-json.js +11 -0
  191. package/dist/manifest/validators/is-package-json.js.map +1 -0
  192. package/dist/manifest/validators/is-package-json.mjs +11 -0
  193. package/dist/manifest/validators/is-package-json.mjs.map +1 -0
  194. package/dist/manifest/validators/is-snap-icon.js +10 -0
  195. package/dist/manifest/validators/is-snap-icon.js.map +1 -0
  196. package/dist/manifest/validators/is-snap-icon.mjs +10 -0
  197. package/dist/manifest/validators/is-snap-icon.mjs.map +1 -0
  198. package/dist/manifest/validators/is-snap-manifest.js +23 -0
  199. package/dist/manifest/validators/is-snap-manifest.js.map +1 -0
  200. package/dist/manifest/validators/is-snap-manifest.mjs +23 -0
  201. package/dist/manifest/validators/is-snap-manifest.mjs.map +1 -0
  202. package/dist/manifest/validators/manifest-localization.js +10 -0
  203. package/dist/manifest/validators/manifest-localization.js.map +1 -0
  204. package/dist/manifest/validators/manifest-localization.mjs +10 -0
  205. package/dist/manifest/validators/manifest-localization.mjs.map +1 -0
  206. package/dist/manifest/validators/package-json-recommended-fields.js +8 -0
  207. package/dist/manifest/validators/package-json-recommended-fields.js.map +1 -0
  208. package/dist/manifest/validators/package-json-recommended-fields.mjs +8 -0
  209. package/dist/manifest/validators/package-json-recommended-fields.mjs.map +1 -0
  210. package/dist/manifest/validators/package-name-match.js +9 -0
  211. package/dist/manifest/validators/package-name-match.js.map +1 -0
  212. package/dist/manifest/validators/package-name-match.mjs +9 -0
  213. package/dist/manifest/validators/package-name-match.mjs.map +1 -0
  214. package/dist/manifest/validators/repository-match.js +10 -0
  215. package/dist/manifest/validators/repository-match.js.map +1 -0
  216. package/dist/manifest/validators/repository-match.mjs +10 -0
  217. package/dist/manifest/validators/repository-match.mjs.map +1 -0
  218. package/dist/manifest/validators/version-match.js +9 -0
  219. package/dist/manifest/validators/version-match.js.map +1 -0
  220. package/dist/manifest/validators/version-match.mjs +9 -0
  221. package/dist/manifest/validators/version-match.mjs.map +1 -0
  222. package/dist/mock.js +1 -1
  223. package/dist/mock.mjs +1 -1
  224. package/dist/namespace.js +1 -1
  225. package/dist/namespace.mjs +1 -1
  226. package/dist/node.js +28 -27
  227. package/dist/node.mjs +34 -33
  228. package/dist/path.js +1 -1
  229. package/dist/path.mjs +1 -1
  230. package/dist/post-process.js +1 -1
  231. package/dist/post-process.mjs +1 -1
  232. package/dist/promise.js +2 -0
  233. package/dist/promise.js.map +1 -0
  234. package/dist/promise.mjs +2 -0
  235. package/dist/promise.mjs.map +1 -0
  236. package/dist/snaps.js +4 -6
  237. package/dist/snaps.mjs +3 -5
  238. package/dist/strings.js +1 -1
  239. package/dist/strings.mjs +1 -1
  240. package/dist/structs.js +3 -3
  241. package/dist/structs.mjs +2 -2
  242. package/dist/svg.js +1 -1
  243. package/dist/svg.mjs +1 -1
  244. package/dist/tsconfig.build.tsbuildinfo +1 -1
  245. package/dist/types/cronjob.d.ts +3 -3
  246. package/dist/types/derivation-paths.d.ts +1 -1
  247. package/dist/types/entropy.d.ts +1 -1
  248. package/dist/types/errors.d.ts +1 -1
  249. package/dist/types/eval.d.ts +1 -1
  250. package/dist/types/handler-types.d.ts +1 -1
  251. package/dist/types/handlers.d.ts +56 -7
  252. package/dist/types/index.d.ts +1 -0
  253. package/dist/types/json-rpc.d.ts +2 -2
  254. package/dist/types/localization.d.ts +1 -1
  255. package/dist/types/manifest/manifest.d.ts +30 -40
  256. package/dist/types/manifest/validation.d.ts +6 -6
  257. package/dist/types/manifest/validator-types.d.ts +34 -0
  258. package/dist/types/manifest/validator.d.ts +22 -0
  259. package/dist/types/manifest/validators/checksum.d.ts +5 -0
  260. package/dist/types/manifest/validators/expected-files.d.ts +5 -0
  261. package/dist/types/manifest/validators/icon-declared.d.ts +5 -0
  262. package/dist/types/manifest/validators/icon-dimensions.d.ts +5 -0
  263. package/dist/types/manifest/validators/icon-missing.d.ts +5 -0
  264. package/dist/types/manifest/validators/index.d.ts +14 -0
  265. package/dist/types/manifest/validators/is-localization-file.d.ts +5 -0
  266. package/dist/types/manifest/validators/is-package-json.d.ts +5 -0
  267. package/dist/types/manifest/validators/is-snap-icon.d.ts +5 -0
  268. package/dist/types/manifest/validators/is-snap-manifest.d.ts +5 -0
  269. package/dist/types/manifest/validators/manifest-localization.d.ts +5 -0
  270. package/dist/types/manifest/validators/package-json-recommended-fields.d.ts +5 -0
  271. package/dist/types/manifest/validators/package-name-match.d.ts +5 -0
  272. package/dist/types/manifest/validators/repository-match.d.ts +5 -0
  273. package/dist/types/manifest/validators/version-match.d.ts +5 -0
  274. package/dist/types/namespace.d.ts +5 -5
  275. package/dist/types/node.d.ts +0 -1
  276. package/dist/types/post-process.d.ts +3 -3
  277. package/dist/types/promise.d.ts +1 -0
  278. package/dist/types/snaps.d.ts +10 -18
  279. package/dist/types/structs.d.ts +2 -2
  280. package/dist/types/types.d.ts +9 -33
  281. package/dist/types/virtual-file/VirtualFile.d.ts +4 -4
  282. package/dist/types/virtual-file/toVirtualFile.d.ts +1 -1
  283. package/dist/types.js +3 -9
  284. package/dist/types.mjs +2 -8
  285. package/dist/ui.js +1 -1
  286. package/dist/ui.mjs +1 -1
  287. package/dist/validation.js +7 -7
  288. package/dist/validation.mjs +6 -6
  289. package/dist/versions.js +1 -1
  290. package/dist/versions.mjs +1 -1
  291. package/dist/virtual-file/VirtualFile.js +1 -1
  292. package/dist/virtual-file/VirtualFile.mjs +1 -1
  293. package/dist/virtual-file/index.js +1 -1
  294. package/dist/virtual-file/index.mjs +1 -1
  295. package/dist/virtual-file/node.js +1 -1
  296. package/dist/virtual-file/node.mjs +1 -1
  297. package/dist/virtual-file/toVirtualFile.js +1 -1
  298. package/dist/virtual-file/toVirtualFile.mjs +1 -1
  299. package/package.json +5 -5
  300. package/dist/chunk-25ESL4NL.js +0 -409
  301. package/dist/chunk-25ESL4NL.js.map +0 -1
  302. package/dist/chunk-AJNKQYKP.mjs.map +0 -1
  303. package/dist/chunk-F6G67XQ4.js +0 -1
  304. package/dist/chunk-FLSK6ISS.mjs.map +0 -1
  305. package/dist/chunk-H35ZUVQT.mjs.map +0 -1
  306. package/dist/chunk-KCECQM3L.mjs +0 -409
  307. package/dist/chunk-KCECQM3L.mjs.map +0 -1
  308. package/dist/chunk-OYZPBNHS.mjs +0 -1
  309. package/dist/chunk-PZNIU23I.js.map +0 -1
  310. package/dist/chunk-RD6BN2TQ.js.map +0 -1
  311. package/dist/chunk-VOPTAKVG.js.map +0 -1
  312. package/dist/npm.js +0 -35
  313. package/dist/npm.mjs +0 -35
  314. package/dist/types/npm.d.ts +0 -19
  315. /package/dist/{chunk-5I5WPAVD.js.map → chunk-37EUH3KZ.js.map} +0 -0
  316. /package/dist/{chunk-SB43G2RI.js.map → chunk-3OXW5H4F.js.map} +0 -0
  317. /package/dist/{chunk-K6BCBPXF.js.map → chunk-3RFGTBEP.js.map} +0 -0
  318. /package/dist/{chunk-JMDSN227.mjs.map → chunk-3RUWAMJT.mjs.map} +0 -0
  319. /package/dist/{chunk-F6G67XQ4.js.map → chunk-FA4QIZH6.js.map} +0 -0
  320. /package/dist/{chunk-ZXHR322P.mjs.map → chunk-GXSTPU7D.mjs.map} +0 -0
  321. /package/dist/{chunk-YNOZU43P.mjs.map → chunk-IPUL74MZ.mjs.map} +0 -0
  322. /package/dist/{chunk-OYZPBNHS.mjs.map → chunk-NNYGTNHP.mjs.map} +0 -0
  323. /package/dist/{chunk-VWGXNUMD.mjs.map → chunk-PZF4KWU2.mjs.map} +0 -0
  324. /package/dist/{chunk-PHUTP7NB.js.map → chunk-S3BWTUTZ.js.map} +0 -0
  325. /package/dist/{npm.js.map → chunk-VWLBM7XM.js.map} +0 -0
  326. /package/dist/{npm.mjs.map → chunk-W7A3BYUP.mjs.map} +0 -0
@@ -0,0 +1,24 @@
1
+ import {
2
+ getSvgDimensions
3
+ } from "./chunk-PTOH2SVI.mjs";
4
+
5
+ // src/manifest/validators/icon-dimensions.ts
6
+ var iconDimensions = {
7
+ severity: "warning",
8
+ semanticCheck(files, context) {
9
+ if (!files.svgIcon) {
10
+ return;
11
+ }
12
+ const dimensions = getSvgDimensions(files.svgIcon.toString());
13
+ if (dimensions && dimensions?.height !== dimensions.width) {
14
+ context.report(
15
+ "The icon in the Snap manifest is not square. It is recommended to use a square icon for the Snap."
16
+ );
17
+ }
18
+ }
19
+ };
20
+
21
+ export {
22
+ iconDimensions
23
+ };
24
+ //# sourceMappingURL=chunk-HY4W6BUH.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/icon-dimensions.ts"],"sourcesContent":["import { getSvgDimensions } from '../../icon';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Verify the icon is square.\n */\nexport const iconDimensions: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n if (!files.svgIcon) {\n return;\n }\n\n const dimensions = getSvgDimensions(files.svgIcon.toString());\n if (dimensions && dimensions?.height !== dimensions.width) {\n context.report(\n 'The icon in the Snap manifest is not square. It is recommended to use a square icon for the Snap.',\n );\n }\n },\n};\n"],"mappings":";;;;;AAMO,IAAM,iBAAgC;AAAA,EAC3C,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,QAAI,CAAC,MAAM,SAAS;AAClB;AAAA,IACF;AAEA,UAAM,aAAa,iBAAiB,MAAM,QAAQ,SAAS,CAAC;AAC5D,QAAI,cAAc,YAAY,WAAW,WAAW,OAAO;AACzD,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  assertIsSnapManifest
3
- } from "./chunk-ZXHR322P.mjs";
3
+ } from "./chunk-GXSTPU7D.mjs";
4
4
  import {
5
5
  validateSnapShasum
6
- } from "./chunk-H35ZUVQT.mjs";
6
+ } from "./chunk-NSVVZNSD.mjs";
7
7
  import {
8
8
  validateSnapManifestLocalizations
9
9
  } from "./chunk-CJK7DDV2.mjs";
@@ -27,4 +27,4 @@ async function validateFetchedSnap(files) {
27
27
  export {
28
28
  validateFetchedSnap
29
29
  };
30
- //# sourceMappingURL=chunk-YNOZU43P.mjs.map
30
+ //# sourceMappingURL=chunk-IPUL74MZ.mjs.map
@@ -0,0 +1,22 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/manifest/validators/expected-files.ts
2
+ var EXPECTED_SNAP_FILES = ["manifest", "packageJson", "sourceCode"];
3
+ var SnapFileNameFromKey = {
4
+ manifest: "snap.manifest.json" /* Manifest */,
5
+ packageJson: "package.json" /* PackageJson */,
6
+ sourceCode: "source code bundle"
7
+ };
8
+ var expectedFiles = {
9
+ severity: "error",
10
+ structureCheck(files, context) {
11
+ for (const expectedFile of EXPECTED_SNAP_FILES) {
12
+ if (!files[expectedFile]) {
13
+ context.report(`Missing file "${SnapFileNameFromKey[expectedFile]}".`);
14
+ }
15
+ }
16
+ }
17
+ };
18
+
19
+
20
+
21
+ exports.expectedFiles = expectedFiles;
22
+ //# sourceMappingURL=chunk-IVDERT5W.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/expected-files.ts"],"names":[],"mappings":";AAGA,IAAM,sBAAsB,CAAC,YAAY,eAAe,YAAY;AAEpE,IAAM,sBAAsB;AAAA,EAC1B;AAAA,EACA;AAAA,EACA,YAAY;AACd;AAKO,IAAM,gBAA+B;AAAA,EAC1C,UAAU;AAAA,EACV,eAAe,OAAO,SAAS;AAC7B,eAAW,gBAAgB,qBAAqB;AAC9C,UAAI,CAAC,MAAM,YAAY,GAAG;AACxB,gBAAQ,OAAO,iBAAiB,oBAAoB,YAAY,CAAC,IAAI;AAAA,MACvE;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import { NpmSnapFileNames } from '../../types';\nimport type { ValidatorMeta } from '../validator-types';\n\nconst EXPECTED_SNAP_FILES = ['manifest', 'packageJson', 'sourceCode'] as const;\n\nconst SnapFileNameFromKey = {\n manifest: NpmSnapFileNames.Manifest,\n packageJson: NpmSnapFileNames.PackageJson,\n sourceCode: 'source code bundle',\n} as const;\n\n/**\n * Check if all the required files are included.\n */\nexport const expectedFiles: ValidatorMeta = {\n severity: 'error',\n structureCheck(files, context) {\n for (const expectedFile of EXPECTED_SNAP_FILES) {\n if (!files[expectedFile]) {\n context.report(`Missing file \"${SnapFileNameFromKey[expectedFile]}\".`);\n }\n }\n },\n};\n"]}
@@ -0,0 +1,248 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
+
3
+
4
+ var _chunkVBYSWMSUjs = require('./chunk-VBYSWMSU.js');
5
+
6
+
7
+ var _chunk6HXIPMBNjs = require('./chunk-6HXIPMBN.js');
8
+
9
+
10
+ var _chunkMKFQAXRFjs = require('./chunk-MKFQAXRF.js');
11
+
12
+
13
+ var _chunk7VJ2BOVUjs = require('./chunk-7VJ2BOVU.js');
14
+
15
+
16
+ var _chunkDEQUNIMEjs = require('./chunk-DEQUNIME.js');
17
+
18
+
19
+ var _chunkNUCLSR2Gjs = require('./chunk-NUCLSR2G.js');
20
+
21
+ // src/manifest/manifest.ts
22
+ var _snapssdk = require('@metamask/snaps-sdk');
23
+ var _utils = require('@metamask/utils');
24
+ var _fs = require('fs');
25
+ var _path = require('path'); var _path2 = _interopRequireDefault(_path);
26
+ var MANIFEST_SORT_ORDER = {
27
+ $schema: 1,
28
+ version: 2,
29
+ description: 3,
30
+ proposedName: 4,
31
+ repository: 5,
32
+ source: 6,
33
+ initialConnections: 7,
34
+ initialPermissions: 8,
35
+ manifestVersion: 9
36
+ };
37
+ async function checkManifest(basePath, {
38
+ updateAndWriteManifest = true,
39
+ sourceCode,
40
+ writeFileFn = _fs.promises.writeFile
41
+ } = {}) {
42
+ const manifestPath = _path2.default.join(basePath, "snap.manifest.json" /* Manifest */);
43
+ const manifestFile = await _chunk6HXIPMBNjs.readJsonFile.call(void 0, manifestPath);
44
+ const unvalidatedManifest = manifestFile.result;
45
+ const packageFile = await _chunk6HXIPMBNjs.readJsonFile.call(void 0,
46
+ _path2.default.join(basePath, "package.json" /* PackageJson */)
47
+ );
48
+ const auxiliaryFilePaths = getSnapFilePaths(
49
+ unvalidatedManifest,
50
+ (manifest) => manifest?.source?.files
51
+ );
52
+ const localizationFilePaths = getSnapFilePaths(
53
+ unvalidatedManifest,
54
+ (manifest) => manifest?.source?.locales
55
+ );
56
+ const localizationFiles = await getSnapFiles(basePath, localizationFilePaths) ?? [];
57
+ for (const localization of localizationFiles) {
58
+ try {
59
+ localization.result = _chunk7VJ2BOVUjs.parseJson.call(void 0, localization.toString());
60
+ } catch (error) {
61
+ _utils.assert.call(void 0, error instanceof SyntaxError, error);
62
+ throw new Error(
63
+ `Failed to parse localization file "${localization.path}" as JSON.`
64
+ );
65
+ }
66
+ }
67
+ const snapFiles = {
68
+ manifest: manifestFile,
69
+ packageJson: packageFile,
70
+ sourceCode: await getSnapSourceCode(
71
+ basePath,
72
+ unvalidatedManifest,
73
+ sourceCode
74
+ ),
75
+ svgIcon: await getSnapIcon(basePath, unvalidatedManifest),
76
+ // Intentionally pass null as the encoding here since the files may be binary
77
+ auxiliaryFiles: await getSnapFiles(basePath, auxiliaryFilePaths, null) ?? [],
78
+ localizationFiles
79
+ };
80
+ const validatorResults = await _chunkVBYSWMSUjs.runValidators.call(void 0, snapFiles);
81
+ let manifestResults = {
82
+ updated: false,
83
+ files: validatorResults.files,
84
+ reports: validatorResults.reports
85
+ };
86
+ if (updateAndWriteManifest && _chunkVBYSWMSUjs.hasFixes.call(void 0, manifestResults)) {
87
+ const fixedResults = await runFixes(validatorResults);
88
+ if (fixedResults.updated) {
89
+ manifestResults = fixedResults;
90
+ _utils.assert.call(void 0, manifestResults.files);
91
+ try {
92
+ await writeFileFn(
93
+ _path2.default.join(basePath, "snap.manifest.json" /* Manifest */),
94
+ manifestResults.files.manifest.toString()
95
+ );
96
+ } catch (error) {
97
+ throw new Error(
98
+ `Failed to update "snap.manifest.json": ${_snapssdk.getErrorMessage.call(void 0, error)}`
99
+ );
100
+ }
101
+ }
102
+ }
103
+ return manifestResults;
104
+ }
105
+ async function runFixes(results, rules) {
106
+ let shouldRunFixes = true;
107
+ const MAX_ATTEMPTS = 10;
108
+ _utils.assert.call(void 0, results.files);
109
+ let fixResults = results;
110
+ _utils.assert.call(void 0, fixResults.files);
111
+ fixResults.files.manifest = fixResults.files.manifest.clone();
112
+ for (let attempts = 1; shouldRunFixes && attempts <= MAX_ATTEMPTS; attempts++) {
113
+ _utils.assert.call(void 0, fixResults.files);
114
+ let manifest = fixResults.files.manifest.result;
115
+ const fixable = fixResults.reports.filter((report) => report.fix);
116
+ for (const report of fixable) {
117
+ _utils.assert.call(void 0, report.fix);
118
+ ({ manifest } = await report.fix({ manifest }));
119
+ }
120
+ fixResults.files.manifest.value = `${JSON.stringify(
121
+ getWritableManifest(manifest),
122
+ null,
123
+ 2
124
+ )}
125
+ `;
126
+ fixResults.files.manifest.result = manifest;
127
+ fixResults = await _chunkVBYSWMSUjs.runValidators.call(void 0, fixResults.files, rules);
128
+ shouldRunFixes = _chunkVBYSWMSUjs.hasFixes.call(void 0, fixResults);
129
+ }
130
+ const initialReports = _chunkNUCLSR2Gjs.deepClone.call(void 0,
131
+ results.reports
132
+ );
133
+ if (!shouldRunFixes) {
134
+ for (const report of initialReports) {
135
+ if (report.fix) {
136
+ report.wasFixed = true;
137
+ delete report.fix;
138
+ }
139
+ }
140
+ return {
141
+ files: fixResults.files,
142
+ updated: true,
143
+ reports: initialReports
144
+ };
145
+ }
146
+ for (const report of initialReports) {
147
+ delete report.fix;
148
+ }
149
+ return {
150
+ files: results.files,
151
+ updated: false,
152
+ reports: initialReports
153
+ };
154
+ }
155
+ async function getSnapSourceCode(basePath, manifest, sourceCode) {
156
+ if (!_utils.isPlainObject.call(void 0, manifest)) {
157
+ return void 0;
158
+ }
159
+ const sourceFilePath = manifest.source?.location?.npm?.filePath;
160
+ if (!sourceFilePath) {
161
+ return void 0;
162
+ }
163
+ if (sourceCode) {
164
+ return new (0, _chunkDEQUNIMEjs.VirtualFile)({
165
+ path: _path2.default.join(basePath, sourceFilePath),
166
+ value: sourceCode
167
+ });
168
+ }
169
+ try {
170
+ const virtualFile = await _chunkMKFQAXRFjs.readVirtualFile.call(void 0,
171
+ _path2.default.join(basePath, sourceFilePath),
172
+ "utf8"
173
+ );
174
+ return virtualFile;
175
+ } catch (error) {
176
+ throw new Error(
177
+ `Failed to read snap bundle file: ${_snapssdk.getErrorMessage.call(void 0, error)}`
178
+ );
179
+ }
180
+ }
181
+ async function getSnapIcon(basePath, manifest) {
182
+ if (!_utils.isPlainObject.call(void 0, manifest)) {
183
+ return void 0;
184
+ }
185
+ const iconPath = manifest.source?.location?.npm?.iconPath;
186
+ if (!iconPath) {
187
+ return void 0;
188
+ }
189
+ try {
190
+ const virtualFile = await _chunkMKFQAXRFjs.readVirtualFile.call(void 0,
191
+ _path2.default.join(basePath, iconPath),
192
+ "utf8"
193
+ );
194
+ return virtualFile;
195
+ } catch (error) {
196
+ throw new Error(`Failed to read snap icon file: ${_snapssdk.getErrorMessage.call(void 0, error)}`);
197
+ }
198
+ }
199
+ function getSnapFilePaths(manifest, selector) {
200
+ if (!_utils.isPlainObject.call(void 0, manifest)) {
201
+ return void 0;
202
+ }
203
+ const snapManifest = manifest;
204
+ const paths = selector(snapManifest);
205
+ if (!Array.isArray(paths)) {
206
+ return void 0;
207
+ }
208
+ return paths;
209
+ }
210
+ async function getSnapFiles(basePath, paths, encoding = "utf8") {
211
+ if (!paths) {
212
+ return void 0;
213
+ }
214
+ try {
215
+ return await Promise.all(
216
+ paths.map(
217
+ async (filePath) => _chunkMKFQAXRFjs.readVirtualFile.call(void 0, _path2.default.join(basePath, filePath), encoding)
218
+ )
219
+ );
220
+ } catch (error) {
221
+ throw new Error(`Failed to read snap files: ${_snapssdk.getErrorMessage.call(void 0, error)}`);
222
+ }
223
+ }
224
+ function getWritableManifest(manifest) {
225
+ const { repository, ...remaining } = manifest;
226
+ const keys = Object.keys(
227
+ repository ? { ...remaining, repository } : remaining
228
+ );
229
+ const writableManifest = keys.sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b]).reduce(
230
+ (result, key) => ({
231
+ ...result,
232
+ [key]: manifest[key]
233
+ }),
234
+ {}
235
+ );
236
+ return writableManifest;
237
+ }
238
+
239
+
240
+
241
+
242
+
243
+
244
+
245
+
246
+
247
+ exports.checkManifest = checkManifest; exports.runFixes = runFixes; exports.getSnapSourceCode = getSnapSourceCode; exports.getSnapIcon = getSnapIcon; exports.getSnapFilePaths = getSnapFilePaths; exports.getSnapFiles = getSnapFiles; exports.getWritableManifest = getWritableManifest;
248
+ //# sourceMappingURL=chunk-JETPRED3.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/manifest.ts"],"names":[],"mappings":"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","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assert, isPlainObject } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { parseJson } from '../json';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file/node';\nimport type { SnapManifest } from './validation';\nimport type { ValidatorResults } from './validator';\nimport { hasFixes, runValidators } from './validator';\nimport type { ValidatorMeta, ValidatorReport } from './validator-types';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialConnections: 7,\n initialPermissions: 8,\n manifestVersion: 9,\n};\n\nexport type CheckManifestReport = Omit<ValidatorReport, 'fix'> & {\n wasFixed?: boolean;\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was written and updated.\n */\nexport type CheckManifestResult = {\n files?: SnapFiles;\n updated: boolean;\n reports: CheckManifestReport[];\n};\n\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param options - Additional options for the function.\n * @param options.sourceCode - The source code of the Snap.\n * @param options.writeFileFn - The function to use to write the manifest to disk.\n * @param options.updateAndWriteManifest - Whether to auto-magically try to fix errors and then write the manifest to disk.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n {\n updateAndWriteManifest = true,\n sourceCode,\n writeFileFn = fs.writeFile,\n }: {\n updateAndWriteManifest?: boolean;\n sourceCode?: string;\n writeFileFn?: WriteFileFunction;\n } = {},\n): Promise<CheckManifestResult> {\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const auxiliaryFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.files,\n );\n\n const localizationFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.locales,\n );\n const localizationFiles =\n (await getSnapFiles(basePath, localizationFilePaths)) ?? [];\n for (const localization of localizationFiles) {\n try {\n localization.result = parseJson(localization.toString());\n } catch (error) {\n assert(error instanceof SyntaxError, error);\n throw new Error(\n `Failed to parse localization file \"${localization.path}\" as JSON.`,\n );\n }\n }\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n // Intentionally pass null as the encoding here since the files may be binary\n auxiliaryFiles:\n (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],\n localizationFiles,\n };\n\n const validatorResults = await runValidators(snapFiles);\n let manifestResults: CheckManifestResult = {\n updated: false,\n files: validatorResults.files,\n reports: validatorResults.reports,\n };\n\n if (updateAndWriteManifest && hasFixes(manifestResults)) {\n const fixedResults = await runFixes(validatorResults);\n\n if (fixedResults.updated) {\n manifestResults = fixedResults;\n\n assert(manifestResults.files);\n\n try {\n await writeFileFn(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n manifestResults.files.manifest.toString(),\n );\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(\n `Failed to update \"snap.manifest.json\": ${getErrorMessage(error)}`,\n );\n }\n }\n }\n\n return manifestResults;\n}\n\n/**\n * Run the algorithm for automatically fixing errors in manifest.\n *\n * The algorithm updates the manifest by fixing all fixable problems,\n * and then run validation again to check if the new manifest is now correct.\n * If not correct, the algorithm will use the manifest from previous iteration\n * and try again `MAX_ATTEMPTS` times to update it before bailing and\n * resulting in failure.\n *\n * @param results - Results of the initial run of validation.\n * @param rules - Optional list of rules to run the fixes with.\n */\nexport async function runFixes(\n results: ValidatorResults,\n rules?: ValidatorMeta[],\n): Promise<CheckManifestResult> {\n let shouldRunFixes = true;\n const MAX_ATTEMPTS = 10;\n\n assert(results.files);\n\n let fixResults: ValidatorResults = results;\n assert(fixResults.files);\n fixResults.files.manifest = fixResults.files.manifest.clone();\n\n for (\n let attempts = 1;\n shouldRunFixes && attempts <= MAX_ATTEMPTS;\n attempts++\n ) {\n assert(fixResults.files);\n\n let manifest = fixResults.files.manifest.result;\n\n const fixable = fixResults.reports.filter((report) => report.fix);\n for (const report of fixable) {\n assert(report.fix);\n ({ manifest } = await report.fix({ manifest }));\n }\n\n fixResults.files.manifest.value = `${JSON.stringify(\n getWritableManifest(manifest),\n null,\n 2,\n )}\\n`;\n fixResults.files.manifest.result = manifest;\n\n fixResults = await runValidators(fixResults.files, rules);\n shouldRunFixes = hasFixes(fixResults);\n }\n\n const initialReports: (CheckManifestReport & ValidatorReport)[] = deepClone(\n results.reports,\n );\n\n // Was fixed\n if (!shouldRunFixes) {\n for (const report of initialReports) {\n if (report.fix) {\n report.wasFixed = true;\n delete report.fix;\n }\n }\n\n return {\n files: fixResults.files,\n updated: true,\n reports: initialReports,\n };\n }\n\n for (const report of initialReports) {\n delete report.fix;\n }\n\n return {\n files: results.files,\n updated: false,\n reports: initialReports,\n };\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(\n `Failed to read snap bundle file: ${getErrorMessage(error)}`,\n );\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap icon file: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Get an array of paths from an unvalidated Snap manifest.\n *\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param selector - A function that returns the paths to the files.\n * @returns The paths to the files, if any.\n */\nexport function getSnapFilePaths(\n manifest: Json,\n selector: (manifest: Partial<SnapManifest>) => string[] | undefined,\n) {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const snapManifest = manifest as Partial<SnapManifest>;\n const paths = selector(snapManifest);\n\n if (!Array.isArray(paths)) {\n return undefined;\n }\n\n return paths;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the files with the\n * given paths and read them.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param paths - The paths to the files.\n * @param encoding - An optional encoding to pass down to readVirtualFile.\n * @returns A list of auxiliary files and their contents, if any.\n */\nexport async function getSnapFiles(\n basePath: string,\n paths: string[] | undefined,\n encoding: BufferEncoding | null = 'utf8',\n): Promise<VirtualFile[] | undefined> {\n if (!paths) {\n return undefined;\n }\n\n try {\n return await Promise.all(\n paths.map(async (filePath) =>\n readVirtualFile(pathUtils.join(basePath, filePath), encoding),\n ),\n );\n } catch (error) {\n throw new Error(`Failed to read snap files: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n"]}
@@ -0,0 +1,33 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk53QXTM77js = require('./chunk-53QXTM77.js');
4
+
5
+
6
+ var _chunkB5GNTDE2js = require('./chunk-B5GNTDE2.js');
7
+
8
+ // src/manifest/validators/is-localization-file.ts
9
+ var _superstruct = require('@metamask/superstruct');
10
+ var isLocalizationFile = {
11
+ severity: "error",
12
+ structureCheck(files, context) {
13
+ for (const file of files.localizationFiles) {
14
+ const [error] = _superstruct.validate.call(void 0, file.result, _chunkB5GNTDE2js.LocalizationFileStruct);
15
+ if (error) {
16
+ for (const failure of error.failures()) {
17
+ context.report(
18
+ `Failed to validate localization file "${file.path}": ${_chunk53QXTM77js.getStructFailureMessage.call(void 0,
19
+ _chunkB5GNTDE2js.LocalizationFileStruct,
20
+ failure,
21
+ false
22
+ )}`
23
+ );
24
+ }
25
+ }
26
+ }
27
+ }
28
+ };
29
+
30
+
31
+
32
+ exports.isLocalizationFile = isLocalizationFile;
33
+ //# sourceMappingURL=chunk-L2DHOOBX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/is-localization-file.ts"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,gBAAgB;AASlB,IAAM,qBAAoC;AAAA,EAC/C,UAAU;AAAA,EACV,eAAe,OAAO,SAAS;AAC7B,eAAW,QAAQ,MAAM,mBAAmB;AAC1C,YAAM,CAAC,KAAK,IAAI,SAAS,KAAK,QAAQ,sBAAsB;AAE5D,UAAI,OAAO;AACT,mBAAW,WAAW,MAAM,SAAS,GAAG;AACtC,kBAAQ;AAAA,YACN,yCACE,KAAK,IACP,MAAM;AAAA,cACJ;AAAA,cACA;AAAA,cACA;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import { validate } from '@metamask/superstruct';\n\nimport { LocalizationFileStruct } from '../../localization';\nimport { getStructFailureMessage } from '../../structs';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Verify the structure of localization files.\n */\nexport const isLocalizationFile: ValidatorMeta = {\n severity: 'error',\n structureCheck(files, context) {\n for (const file of files.localizationFiles) {\n const [error] = validate(file.result, LocalizationFileStruct);\n\n if (error) {\n for (const failure of error.failures()) {\n context.report(\n `Failed to validate localization file \"${\n file.path\n }\": ${getStructFailureMessage(\n LocalizationFileStruct,\n failure,\n false,\n )}`,\n );\n }\n }\n }\n },\n};\n"]}
@@ -0,0 +1,34 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkB5GNTDE2js = require('./chunk-B5GNTDE2.js');
4
+
5
+ // src/manifest/validators/manifest-localization.ts
6
+ var _snapssdk = require('@metamask/snaps-sdk');
7
+ var manifestLocalization = {
8
+ severity: "error",
9
+ semanticCheck(files, context) {
10
+ const manifest = files.manifest.result;
11
+ const localizations = files.localizationFiles.map(
12
+ (file) => file.result
13
+ );
14
+ const locales = [
15
+ "en",
16
+ // The manifest must be able to be localized in English.
17
+ ...localizations.map(({ locale }) => locale).filter((locale) => locale !== "en")
18
+ ];
19
+ for (const locale of locales) {
20
+ try {
21
+ _chunkB5GNTDE2js.getLocalizedSnapManifest.call(void 0, manifest, locale, localizations);
22
+ } catch (error) {
23
+ context.report(
24
+ `Failed to localize Snap manifest: ${_snapssdk.getErrorMessage.call(void 0, error)}`
25
+ );
26
+ }
27
+ }
28
+ }
29
+ };
30
+
31
+
32
+
33
+ exports.manifestLocalization = manifestLocalization;
34
+ //# sourceMappingURL=chunk-LQSEBGOX.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/manifest-localization.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,uBAAuB;AASzB,IAAM,uBAAsC;AAAA,EACjD,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,UAAM,WAAW,MAAM,SAAS;AAChC,UAAM,gBAAoC,MAAM,kBAAkB;AAAA,MAChE,CAAC,SAAS,KAAK;AAAA,IACjB;AACA,UAAM,UAAU;AAAA,MACd;AAAA;AAAA,MACA,GAAG,cACA,IAAI,CAAC,EAAE,OAAO,MAAM,MAAM,EAC1B,OAAO,CAAC,WAAW,WAAW,IAAI;AAAA,IACvC;AAEA,eAAW,UAAU,SAAS;AAC5B,UAAI;AACF,iCAAyB,UAAU,QAAQ,aAAa;AAAA,MAC1D,SAAS,OAAO;AACd,gBAAQ;AAAA,UACN,qCAAqC,gBAAgB,KAAK,CAAC;AAAA,QAC7D;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\n\nimport type { LocalizationFile } from '../../localization';\nimport { getLocalizedSnapManifest } from '../../localization';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Verify whether the localization files localize the manifest correctly.\n */\nexport const manifestLocalization: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const manifest = files.manifest.result;\n const localizations: LocalizationFile[] = files.localizationFiles.map(\n (file) => file.result,\n );\n const locales = [\n 'en', // The manifest must be able to be localized in English.\n ...localizations\n .map(({ locale }) => locale)\n .filter((locale) => locale !== 'en'),\n ];\n\n for (const locale of locales) {\n try {\n getLocalizedSnapManifest(manifest, locale, localizations);\n } catch (error) {\n context.report(\n `Failed to localize Snap manifest: ${getErrorMessage(error)}`,\n );\n }\n }\n },\n};\n"]}
@@ -0,0 +1,34 @@
1
+ import {
2
+ SnapManifestStruct
3
+ } from "./chunk-GXSTPU7D.mjs";
4
+ import {
5
+ getStructFailureMessage
6
+ } from "./chunk-3N27GIUS.mjs";
7
+
8
+ // src/manifest/validators/is-snap-manifest.ts
9
+ import { validate } from "@metamask/superstruct";
10
+ var isSnapManifest = {
11
+ severity: "error",
12
+ structureCheck(files, context) {
13
+ if (!files.manifest) {
14
+ return;
15
+ }
16
+ const [error] = validate(files.manifest.result, SnapManifestStruct);
17
+ if (error) {
18
+ for (const failure of error.failures()) {
19
+ context.report(
20
+ `"${"snap.manifest.json" /* Manifest */}" is invalid: ${getStructFailureMessage(
21
+ SnapManifestStruct,
22
+ failure,
23
+ false
24
+ )}`
25
+ );
26
+ }
27
+ }
28
+ }
29
+ };
30
+
31
+ export {
32
+ isSnapManifest
33
+ };
34
+ //# sourceMappingURL=chunk-MDOG3S4V.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/is-snap-manifest.ts"],"sourcesContent":["import { validate } from '@metamask/superstruct';\n\nimport { getStructFailureMessage } from '../../structs';\nimport { NpmSnapFileNames } from '../../types';\nimport { SnapManifestStruct } from '../validation';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Verify the structure of snap.manifest.json.\n */\nexport const isSnapManifest: ValidatorMeta = {\n severity: 'error',\n structureCheck(files, context) {\n if (!files.manifest) {\n return;\n }\n const [error] = validate(files.manifest.result, SnapManifestStruct);\n if (error) {\n for (const failure of error.failures()) {\n context.report(\n `\"${NpmSnapFileNames.Manifest}\" is invalid: ${getStructFailureMessage(\n SnapManifestStruct,\n failure,\n false,\n )}`,\n );\n }\n }\n },\n};\n"],"mappings":";;;;;;;;AAAA,SAAS,gBAAgB;AAUlB,IAAM,iBAAgC;AAAA,EAC3C,UAAU;AAAA,EACV,eAAe,OAAO,SAAS;AAC7B,QAAI,CAAC,MAAM,UAAU;AACnB;AAAA,IACF;AACA,UAAM,CAAC,KAAK,IAAI,SAAS,MAAM,SAAS,QAAQ,kBAAkB;AAClE,QAAI,OAAO;AACT,iBAAW,WAAW,MAAM,SAAS,GAAG;AACtC,gBAAQ;AAAA,UACN,uCAA6B,iBAAiB;AAAA,YAC5C;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,22 @@
1
+ // src/manifest/validators/package-name-match.ts
2
+ var packageNameMatch = {
3
+ severity: "error",
4
+ semanticCheck(files, context) {
5
+ const packageJsonName = files.packageJson.result.name;
6
+ const manifestPackageName = files.manifest.result.source.location.npm.packageName;
7
+ if (packageJsonName !== manifestPackageName) {
8
+ context.report(
9
+ `"${"snap.manifest.json" /* Manifest */}" npm package name ("${manifestPackageName}") does not match the "${"package.json" /* PackageJson */}" "name" field ("${packageJsonName}").`,
10
+ ({ manifest }) => {
11
+ manifest.source.location.npm.packageName = packageJsonName;
12
+ return { manifest };
13
+ }
14
+ );
15
+ }
16
+ }
17
+ };
18
+
19
+ export {
20
+ packageNameMatch
21
+ };
22
+ //# sourceMappingURL=chunk-MFGLB75H.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/package-name-match.ts"],"sourcesContent":["import { NpmSnapFileNames } from '../../types';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the package name in manifest matches package.json name.\n */\nexport const packageNameMatch: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const packageJsonName = files.packageJson.result.name;\n const manifestPackageName =\n files.manifest.result.source.location.npm.packageName;\n if (packageJsonName !== manifestPackageName) {\n context.report(\n `\"${NpmSnapFileNames.Manifest}\" npm package name (\"${manifestPackageName}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"name\" field (\"${packageJsonName}\").`,\n ({ manifest }) => {\n manifest.source.location.npm.packageName = packageJsonName;\n return { manifest };\n },\n );\n }\n },\n};\n"],"mappings":";AAMO,IAAM,mBAAkC;AAAA,EAC7C,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,UAAM,kBAAkB,MAAM,YAAY,OAAO;AACjD,UAAM,sBACJ,MAAM,SAAS,OAAO,OAAO,SAAS,IAAI;AAC5C,QAAI,oBAAoB,qBAAqB;AAC3C,cAAQ;AAAA,QACN,uCAA6B,wBAAwB,mBAAmB,0DAAsD,oBAAoB,eAAe;AAAA,QACjK,CAAC,EAAE,SAAS,MAAM;AAChB,mBAAS,OAAO,SAAS,IAAI,cAAc;AAC3C,iBAAO,EAAE,SAAS;AAAA,QACpB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,16 @@
1
+ // src/manifest/validators/icon-declared.ts
2
+ var iconDeclared = {
3
+ severity: "warning",
4
+ semanticCheck(files, context) {
5
+ if (!files.manifest.result.source.location.npm.iconPath) {
6
+ context.report(
7
+ "No icon found in the Snap manifest. It is recommended to include an icon for the Snap. See https://docs.metamask.io/snaps/how-to/design-a-snap/#guidelines-at-a-glance for more information."
8
+ );
9
+ }
10
+ }
11
+ };
12
+
13
+ export {
14
+ iconDeclared
15
+ };
16
+ //# sourceMappingURL=chunk-MQURBEO4.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/icon-declared.ts"],"sourcesContent":["import type { ValidatorMeta } from '../validator-types';\n\n/**\n * Suggest including an icon if not found in manifest.\n */\nexport const iconDeclared: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n if (!files.manifest.result.source.location.npm.iconPath) {\n context.report(\n 'No icon found in the Snap manifest. It is recommended to include an icon for the Snap. See https://docs.metamask.io/snaps/how-to/design-a-snap/#guidelines-at-a-glance for more information.',\n );\n }\n },\n};\n"],"mappings":";AAKO,IAAM,eAA8B;AAAA,EACzC,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,QAAI,CAAC,MAAM,SAAS,OAAO,OAAO,SAAS,IAAI,UAAU;AACvD,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -37,28 +37,11 @@ var NpmSnapPackageJsonStruct = _superstruct.type.call(void 0, {
37
37
  })
38
38
  )
39
39
  });
40
- function isNpmSnapPackageJson(value) {
41
- return _superstruct.is.call(void 0, value, NpmSnapPackageJsonStruct);
42
- }
43
- function assertIsNpmSnapPackageJson(value) {
44
- _utils.assertStruct.call(void 0,
45
- value,
46
- NpmSnapPackageJsonStruct,
47
- `"${"package.json" /* PackageJson */}" is invalid`
48
- );
49
- }
50
40
  var SnapIdPrefixes = /* @__PURE__ */ ((SnapIdPrefixes2) => {
51
41
  SnapIdPrefixes2["npm"] = "npm:";
52
42
  SnapIdPrefixes2["local"] = "local:";
53
43
  return SnapIdPrefixes2;
54
44
  })(SnapIdPrefixes || {});
55
- var SnapValidationFailureReason = /* @__PURE__ */ ((SnapValidationFailureReason2) => {
56
- SnapValidationFailureReason2["NameMismatch"] = '"name" field mismatch';
57
- SnapValidationFailureReason2["VersionMismatch"] = '"version" field mismatch';
58
- SnapValidationFailureReason2["RepositoryMismatch"] = '"repository" field mismatch';
59
- SnapValidationFailureReason2["ShasumMismatch"] = '"shasum" field mismatch';
60
- return SnapValidationFailureReason2;
61
- })(SnapValidationFailureReason || {});
62
45
  var SNAP_STREAM_NAMES = /* @__PURE__ */ ((SNAP_STREAM_NAMES2) => {
63
46
  SNAP_STREAM_NAMES2["JSON_RPC"] = "jsonRpc";
64
47
  SNAP_STREAM_NAMES2["COMMAND"] = "command";
@@ -88,8 +71,5 @@ var WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
88
71
 
89
72
 
90
73
 
91
-
92
-
93
-
94
- exports.NpmSnapFileNames = NpmSnapFileNames; exports.NameStruct = NameStruct; exports.NpmSnapPackageJsonStruct = NpmSnapPackageJsonStruct; exports.isNpmSnapPackageJson = isNpmSnapPackageJson; exports.assertIsNpmSnapPackageJson = assertIsNpmSnapPackageJson; exports.SnapIdPrefixes = SnapIdPrefixes; exports.SnapValidationFailureReason = SnapValidationFailureReason; exports.SNAP_STREAM_NAMES = SNAP_STREAM_NAMES; exports.uri = uri; exports.isValidUrl = isValidUrl; exports.WALLET_SNAP_PERMISSION_KEY = WALLET_SNAP_PERMISSION_KEY;
95
- //# sourceMappingURL=chunk-PZNIU23I.js.map
74
+ exports.NpmSnapFileNames = NpmSnapFileNames; exports.NameStruct = NameStruct; exports.NpmSnapPackageJsonStruct = NpmSnapPackageJsonStruct; exports.SnapIdPrefixes = SnapIdPrefixes; exports.SNAP_STREAM_NAMES = SNAP_STREAM_NAMES; exports.uri = uri; exports.isValidUrl = isValidUrl; exports.WALLET_SNAP_PERMISSION_KEY = WALLET_SNAP_PERMISSION_KEY;
75
+ //# sourceMappingURL=chunk-MWAZGSRO.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/types.ts"],"names":["NpmSnapFileNames","SnapIdPrefixes","SNAP_STREAM_NAMES"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,OACL;AAGP,SAAS,qBAAqB;AAQvB,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,iBAAc;AACd,EAAAA,kBAAA,cAAW;AAFD,SAAAA;AAAA,GAAA;AAKL,IAAM,aAAa;AAAA,EACxB;AAAA,IACE,OAAO;AAAA,IACP;AAAA,EACF;AAAA,EACA;AAAA,EACA;AACF;AAIO,IAAM,2BAA2B,KAAK;AAAA,EAC3C,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM,SAAS,KAAK,OAAO,GAAG,GAAG,QAAQ,CAAC;AAAA,EAC1C,YAAY;AAAA,IACV,OAAO;AAAA,MACL,MAAM,KAAK,OAAO,GAAG,GAAG,QAAQ;AAAA,MAChC,KAAK,KAAK,OAAO,GAAG,GAAG,QAAQ;AAAA,IACjC,CAAC;AAAA,EACH;AACF,CAAC;AA0CM,IAAK,iBAAL,kBAAKC,oBAAL;AACL,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AAOL,IAAK,oBAAL,kBAAKC,uBAAL;AACL,EAAAA,mBAAA,cAAW;AACX,EAAAA,mBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;AAwBL,IAAM,MAAM,CAAC,OAAwB,CAAC,MAC3C,OAAO,MAAM,CAAC,OAAO,GAAG,SAAS,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU;AACzD,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,KAAK;AAEzB,UAAM,YAAY,KAAK,IAAI;AAC3B,sBAAkB,KAAK,SAAS;AAChC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO,sBAAsB,MAAM,SAAS,CAAC;AAAA,EAC/C;AACF,CAAC;AASI,SAAS,WACd,KACA,OAAwB,CAAC,GACJ;AACrB,SAAO,GAAG,KAAK,IAAI,IAAI,CAAC;AAC1B;AAGO,IAAM,6BAA6B","sourcesContent":["import {\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n type,\n union,\n assert as assertSuperstruct,\n} from '@metamask/superstruct';\nimport type { Infer, Struct } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { VersionStruct } from '@metamask/utils';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n pattern(\n string(),\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(union([string(), instance(URL)]), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch {\n return `Expected URL, got \"${value.toString()}\".`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string | URL {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"]}
@@ -12,7 +12,7 @@ import {
12
12
  union,
13
13
  assert as assertSuperstruct
14
14
  } from "@metamask/superstruct";
15
- import { assertStruct, VersionStruct } from "@metamask/utils";
15
+ import { VersionStruct } from "@metamask/utils";
16
16
  var NpmSnapFileNames = /* @__PURE__ */ ((NpmSnapFileNames2) => {
17
17
  NpmSnapFileNames2["PackageJson"] = "package.json";
18
18
  NpmSnapFileNames2["Manifest"] = "snap.manifest.json";
@@ -37,28 +37,11 @@ var NpmSnapPackageJsonStruct = type({
37
37
  })
38
38
  )
39
39
  });
40
- function isNpmSnapPackageJson(value) {
41
- return is(value, NpmSnapPackageJsonStruct);
42
- }
43
- function assertIsNpmSnapPackageJson(value) {
44
- assertStruct(
45
- value,
46
- NpmSnapPackageJsonStruct,
47
- `"${"package.json" /* PackageJson */}" is invalid`
48
- );
49
- }
50
40
  var SnapIdPrefixes = /* @__PURE__ */ ((SnapIdPrefixes2) => {
51
41
  SnapIdPrefixes2["npm"] = "npm:";
52
42
  SnapIdPrefixes2["local"] = "local:";
53
43
  return SnapIdPrefixes2;
54
44
  })(SnapIdPrefixes || {});
55
- var SnapValidationFailureReason = /* @__PURE__ */ ((SnapValidationFailureReason2) => {
56
- SnapValidationFailureReason2["NameMismatch"] = '"name" field mismatch';
57
- SnapValidationFailureReason2["VersionMismatch"] = '"version" field mismatch';
58
- SnapValidationFailureReason2["RepositoryMismatch"] = '"repository" field mismatch';
59
- SnapValidationFailureReason2["ShasumMismatch"] = '"shasum" field mismatch';
60
- return SnapValidationFailureReason2;
61
- })(SnapValidationFailureReason || {});
62
45
  var SNAP_STREAM_NAMES = /* @__PURE__ */ ((SNAP_STREAM_NAMES2) => {
63
46
  SNAP_STREAM_NAMES2["JSON_RPC"] = "jsonRpc";
64
47
  SNAP_STREAM_NAMES2["COMMAND"] = "command";
@@ -83,13 +66,10 @@ export {
83
66
  NpmSnapFileNames,
84
67
  NameStruct,
85
68
  NpmSnapPackageJsonStruct,
86
- isNpmSnapPackageJson,
87
- assertIsNpmSnapPackageJson,
88
69
  SnapIdPrefixes,
89
- SnapValidationFailureReason,
90
70
  SNAP_STREAM_NAMES,
91
71
  uri,
92
72
  isValidUrl,
93
73
  WALLET_SNAP_PERMISSION_KEY
94
74
  };
95
- //# sourceMappingURL=chunk-AJNKQYKP.mjs.map
75
+ //# sourceMappingURL=chunk-N2JAYIUP.mjs.map