@metamask/snaps-utils 7.8.0 → 8.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 (332) hide show
  1. package/CHANGELOG.md +14 -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-KSRDEGBC.js → chunk-FBZ5SU7X.js} +11 -1
  46. package/dist/chunk-FBZ5SU7X.js.map +1 -0
  47. package/dist/chunk-GIVJAZ2Q.mjs +248 -0
  48. package/dist/chunk-GIVJAZ2Q.mjs.map +1 -0
  49. package/dist/chunk-GJAVOB7B.js +24 -0
  50. package/dist/chunk-GJAVOB7B.js.map +1 -0
  51. package/dist/{chunk-ZXHR322P.mjs → chunk-GXSTPU7D.mjs} +4 -4
  52. package/dist/chunk-HY4W6BUH.mjs +24 -0
  53. package/dist/chunk-HY4W6BUH.mjs.map +1 -0
  54. package/dist/{chunk-X3XJN63W.mjs → chunk-IELPPZJP.mjs} +11 -1
  55. package/dist/chunk-IELPPZJP.mjs.map +1 -0
  56. package/dist/{chunk-YNOZU43P.mjs → chunk-IPUL74MZ.mjs} +3 -3
  57. package/dist/chunk-IVDERT5W.js +22 -0
  58. package/dist/chunk-IVDERT5W.js.map +1 -0
  59. package/dist/chunk-JETPRED3.js +248 -0
  60. package/dist/chunk-JETPRED3.js.map +1 -0
  61. package/dist/chunk-L2DHOOBX.js +33 -0
  62. package/dist/chunk-L2DHOOBX.js.map +1 -0
  63. package/dist/chunk-LQSEBGOX.js +34 -0
  64. package/dist/chunk-LQSEBGOX.js.map +1 -0
  65. package/dist/chunk-MDOG3S4V.mjs +34 -0
  66. package/dist/chunk-MDOG3S4V.mjs.map +1 -0
  67. package/dist/chunk-MFGLB75H.mjs +22 -0
  68. package/dist/chunk-MFGLB75H.mjs.map +1 -0
  69. package/dist/chunk-MQURBEO4.mjs +16 -0
  70. package/dist/chunk-MQURBEO4.mjs.map +1 -0
  71. package/dist/{chunk-PZNIU23I.js → chunk-MWAZGSRO.js} +2 -22
  72. package/dist/chunk-MWAZGSRO.js.map +1 -0
  73. package/dist/{chunk-AJNKQYKP.mjs → chunk-N2JAYIUP.mjs} +2 -22
  74. package/dist/chunk-N2JAYIUP.mjs.map +1 -0
  75. package/dist/chunk-N4MA537G.js +22 -0
  76. package/dist/chunk-N4MA537G.js.map +1 -0
  77. package/dist/chunk-NNYGTNHP.mjs +1 -0
  78. package/dist/{chunk-H35ZUVQT.mjs → chunk-NSVVZNSD.mjs} +3 -13
  79. package/dist/chunk-NSVVZNSD.mjs.map +1 -0
  80. package/dist/chunk-PAOTMYIM.mjs +69 -0
  81. package/dist/chunk-PAOTMYIM.mjs.map +1 -0
  82. package/dist/chunk-PO5BBHHX.mjs +22 -0
  83. package/dist/chunk-PO5BBHHX.mjs.map +1 -0
  84. package/dist/{chunk-VWGXNUMD.mjs → chunk-PZF4KWU2.mjs} +2 -2
  85. package/dist/chunk-QD3LTING.js +34 -0
  86. package/dist/chunk-QD3LTING.js.map +1 -0
  87. package/dist/chunk-RNMJQSVQ.js +69 -0
  88. package/dist/chunk-RNMJQSVQ.js.map +1 -0
  89. package/dist/chunk-RRFKK45V.mjs +15 -0
  90. package/dist/chunk-RRFKK45V.mjs.map +1 -0
  91. package/dist/{chunk-PHUTP7NB.js → chunk-S3BWTUTZ.js} +9 -3
  92. package/dist/chunk-SKKANJ45.mjs +19 -0
  93. package/dist/chunk-SKKANJ45.mjs.map +1 -0
  94. package/dist/chunk-SYYDKPK3.js +15 -0
  95. package/dist/chunk-SYYDKPK3.js.map +1 -0
  96. package/dist/chunk-T5ZOOZ46.js +22 -0
  97. package/dist/chunk-T5ZOOZ46.js.map +1 -0
  98. package/dist/{chunk-RD6BN2TQ.js → chunk-TAMKWZ4E.js} +8 -18
  99. package/dist/chunk-TAMKWZ4E.js.map +1 -0
  100. package/dist/chunk-TYWGZIOF.mjs +34 -0
  101. package/dist/chunk-TYWGZIOF.mjs.map +1 -0
  102. package/dist/chunk-VBYSWMSU.js +66 -0
  103. package/dist/chunk-VBYSWMSU.js.map +1 -0
  104. package/dist/chunk-VEPYH26P.js +27 -0
  105. package/dist/chunk-VEPYH26P.js.map +1 -0
  106. package/dist/chunk-VWLBM7XM.js +1 -0
  107. package/dist/chunk-W7A3BYUP.mjs +1 -0
  108. package/dist/chunk-YL2EHYAA.js +16 -0
  109. package/dist/chunk-YL2EHYAA.js.map +1 -0
  110. package/dist/constants.js +1 -1
  111. package/dist/constants.mjs +1 -1
  112. package/dist/cronjob.js +1 -1
  113. package/dist/cronjob.mjs +1 -1
  114. package/dist/deep-clone.js +1 -1
  115. package/dist/deep-clone.mjs +1 -1
  116. package/dist/default-endowments.js +1 -1
  117. package/dist/default-endowments.mjs +1 -1
  118. package/dist/derivation-paths.js +3 -3
  119. package/dist/derivation-paths.mjs +2 -2
  120. package/dist/entropy.js +1 -1
  121. package/dist/entropy.mjs +1 -1
  122. package/dist/errors.js +3 -3
  123. package/dist/errors.mjs +2 -2
  124. package/dist/eval-worker.js +1 -1
  125. package/dist/eval-worker.mjs +1 -1
  126. package/dist/eval.js +1 -1
  127. package/dist/eval.mjs +1 -1
  128. package/dist/fs.js +1 -1
  129. package/dist/fs.mjs +1 -1
  130. package/dist/handler-types.js +1 -1
  131. package/dist/handler-types.mjs +1 -1
  132. package/dist/handlers.js +1 -1
  133. package/dist/handlers.mjs +1 -1
  134. package/dist/icon.js +1 -1
  135. package/dist/icon.mjs +1 -1
  136. package/dist/iframe.js +1 -1
  137. package/dist/iframe.mjs +1 -1
  138. package/dist/index.executionenv.js +5 -11
  139. package/dist/index.executionenv.mjs +9 -15
  140. package/dist/index.js +12 -19
  141. package/dist/index.mjs +16 -23
  142. package/dist/json-rpc.js +1 -1
  143. package/dist/json-rpc.mjs +1 -1
  144. package/dist/json.js +1 -1
  145. package/dist/json.mjs +1 -1
  146. package/dist/localization.js +1 -1
  147. package/dist/localization.mjs +1 -1
  148. package/dist/logging.js +1 -1
  149. package/dist/logging.mjs +1 -1
  150. package/dist/manifest/index.js +6 -6
  151. package/dist/manifest/index.mjs +5 -5
  152. package/dist/manifest/manifest.js +23 -9
  153. package/dist/manifest/manifest.mjs +24 -10
  154. package/dist/manifest/node.js +23 -9
  155. package/dist/manifest/node.mjs +24 -10
  156. package/dist/manifest/validation.js +6 -6
  157. package/dist/manifest/validation.mjs +5 -5
  158. package/dist/manifest/validator-types.js +1 -0
  159. package/dist/manifest/validator-types.js.map +1 -0
  160. package/dist/manifest/validator-types.mjs +1 -0
  161. package/dist/manifest/validator-types.mjs.map +1 -0
  162. package/dist/manifest/validator.js +44 -0
  163. package/dist/manifest/validator.js.map +1 -0
  164. package/dist/manifest/validator.mjs +44 -0
  165. package/dist/manifest/validator.mjs.map +1 -0
  166. package/dist/manifest/validators/checksum.js +15 -0
  167. package/dist/manifest/validators/checksum.js.map +1 -0
  168. package/dist/manifest/validators/checksum.mjs +15 -0
  169. package/dist/manifest/validators/checksum.mjs.map +1 -0
  170. package/dist/manifest/validators/expected-files.js +9 -0
  171. package/dist/manifest/validators/expected-files.js.map +1 -0
  172. package/dist/manifest/validators/expected-files.mjs +9 -0
  173. package/dist/manifest/validators/expected-files.mjs.map +1 -0
  174. package/dist/manifest/validators/icon-declared.js +8 -0
  175. package/dist/manifest/validators/icon-declared.js.map +1 -0
  176. package/dist/manifest/validators/icon-declared.mjs +8 -0
  177. package/dist/manifest/validators/icon-declared.mjs.map +1 -0
  178. package/dist/manifest/validators/icon-dimensions.js +10 -0
  179. package/dist/manifest/validators/icon-dimensions.js.map +1 -0
  180. package/dist/manifest/validators/icon-dimensions.mjs +10 -0
  181. package/dist/manifest/validators/icon-dimensions.mjs.map +1 -0
  182. package/dist/manifest/validators/icon-missing.js +8 -0
  183. package/dist/manifest/validators/icon-missing.js.map +1 -0
  184. package/dist/manifest/validators/icon-missing.mjs +8 -0
  185. package/dist/manifest/validators/icon-missing.mjs.map +1 -0
  186. package/dist/manifest/validators/index.js +80 -0
  187. package/dist/manifest/validators/index.js.map +1 -0
  188. package/dist/manifest/validators/index.mjs +80 -0
  189. package/dist/manifest/validators/index.mjs.map +1 -0
  190. package/dist/manifest/validators/is-localization-file.js +12 -0
  191. package/dist/manifest/validators/is-localization-file.js.map +1 -0
  192. package/dist/manifest/validators/is-localization-file.mjs +12 -0
  193. package/dist/manifest/validators/is-localization-file.mjs.map +1 -0
  194. package/dist/manifest/validators/is-package-json.js +11 -0
  195. package/dist/manifest/validators/is-package-json.js.map +1 -0
  196. package/dist/manifest/validators/is-package-json.mjs +11 -0
  197. package/dist/manifest/validators/is-package-json.mjs.map +1 -0
  198. package/dist/manifest/validators/is-snap-icon.js +10 -0
  199. package/dist/manifest/validators/is-snap-icon.js.map +1 -0
  200. package/dist/manifest/validators/is-snap-icon.mjs +10 -0
  201. package/dist/manifest/validators/is-snap-icon.mjs.map +1 -0
  202. package/dist/manifest/validators/is-snap-manifest.js +23 -0
  203. package/dist/manifest/validators/is-snap-manifest.js.map +1 -0
  204. package/dist/manifest/validators/is-snap-manifest.mjs +23 -0
  205. package/dist/manifest/validators/is-snap-manifest.mjs.map +1 -0
  206. package/dist/manifest/validators/manifest-localization.js +10 -0
  207. package/dist/manifest/validators/manifest-localization.js.map +1 -0
  208. package/dist/manifest/validators/manifest-localization.mjs +10 -0
  209. package/dist/manifest/validators/manifest-localization.mjs.map +1 -0
  210. package/dist/manifest/validators/package-json-recommended-fields.js +8 -0
  211. package/dist/manifest/validators/package-json-recommended-fields.js.map +1 -0
  212. package/dist/manifest/validators/package-json-recommended-fields.mjs +8 -0
  213. package/dist/manifest/validators/package-json-recommended-fields.mjs.map +1 -0
  214. package/dist/manifest/validators/package-name-match.js +9 -0
  215. package/dist/manifest/validators/package-name-match.js.map +1 -0
  216. package/dist/manifest/validators/package-name-match.mjs +9 -0
  217. package/dist/manifest/validators/package-name-match.mjs.map +1 -0
  218. package/dist/manifest/validators/repository-match.js +10 -0
  219. package/dist/manifest/validators/repository-match.js.map +1 -0
  220. package/dist/manifest/validators/repository-match.mjs +10 -0
  221. package/dist/manifest/validators/repository-match.mjs.map +1 -0
  222. package/dist/manifest/validators/version-match.js +9 -0
  223. package/dist/manifest/validators/version-match.js.map +1 -0
  224. package/dist/manifest/validators/version-match.mjs +9 -0
  225. package/dist/manifest/validators/version-match.mjs.map +1 -0
  226. package/dist/mock.js +1 -1
  227. package/dist/mock.mjs +1 -1
  228. package/dist/namespace.js +1 -1
  229. package/dist/namespace.mjs +1 -1
  230. package/dist/node.js +29 -28
  231. package/dist/node.mjs +35 -34
  232. package/dist/path.js +1 -1
  233. package/dist/path.mjs +1 -1
  234. package/dist/post-process.js +1 -1
  235. package/dist/post-process.mjs +1 -1
  236. package/dist/promise.js +2 -0
  237. package/dist/promise.js.map +1 -0
  238. package/dist/promise.mjs +2 -0
  239. package/dist/promise.mjs.map +1 -0
  240. package/dist/snaps.js +4 -6
  241. package/dist/snaps.mjs +3 -5
  242. package/dist/strings.js +1 -1
  243. package/dist/strings.mjs +1 -1
  244. package/dist/structs.js +3 -3
  245. package/dist/structs.mjs +2 -2
  246. package/dist/svg.js +1 -1
  247. package/dist/svg.mjs +1 -1
  248. package/dist/tsconfig.build.tsbuildinfo +1 -1
  249. package/dist/types/cronjob.d.ts +3 -3
  250. package/dist/types/derivation-paths.d.ts +1 -1
  251. package/dist/types/entropy.d.ts +1 -1
  252. package/dist/types/errors.d.ts +1 -1
  253. package/dist/types/eval.d.ts +1 -1
  254. package/dist/types/handler-types.d.ts +1 -1
  255. package/dist/types/handlers.d.ts +56 -7
  256. package/dist/types/index.d.ts +1 -0
  257. package/dist/types/json-rpc.d.ts +2 -2
  258. package/dist/types/localization.d.ts +1 -1
  259. package/dist/types/manifest/manifest.d.ts +30 -40
  260. package/dist/types/manifest/validation.d.ts +6 -6
  261. package/dist/types/manifest/validator-types.d.ts +34 -0
  262. package/dist/types/manifest/validator.d.ts +22 -0
  263. package/dist/types/manifest/validators/checksum.d.ts +5 -0
  264. package/dist/types/manifest/validators/expected-files.d.ts +5 -0
  265. package/dist/types/manifest/validators/icon-declared.d.ts +5 -0
  266. package/dist/types/manifest/validators/icon-dimensions.d.ts +5 -0
  267. package/dist/types/manifest/validators/icon-missing.d.ts +5 -0
  268. package/dist/types/manifest/validators/index.d.ts +14 -0
  269. package/dist/types/manifest/validators/is-localization-file.d.ts +5 -0
  270. package/dist/types/manifest/validators/is-package-json.d.ts +5 -0
  271. package/dist/types/manifest/validators/is-snap-icon.d.ts +5 -0
  272. package/dist/types/manifest/validators/is-snap-manifest.d.ts +5 -0
  273. package/dist/types/manifest/validators/manifest-localization.d.ts +5 -0
  274. package/dist/types/manifest/validators/package-json-recommended-fields.d.ts +5 -0
  275. package/dist/types/manifest/validators/package-name-match.d.ts +5 -0
  276. package/dist/types/manifest/validators/repository-match.d.ts +5 -0
  277. package/dist/types/manifest/validators/version-match.d.ts +5 -0
  278. package/dist/types/namespace.d.ts +5 -5
  279. package/dist/types/node.d.ts +0 -1
  280. package/dist/types/post-process.d.ts +3 -3
  281. package/dist/types/promise.d.ts +1 -0
  282. package/dist/types/snaps.d.ts +10 -18
  283. package/dist/types/structs.d.ts +2 -2
  284. package/dist/types/types.d.ts +9 -33
  285. package/dist/types/virtual-file/VirtualFile.d.ts +4 -4
  286. package/dist/types/virtual-file/toVirtualFile.d.ts +1 -1
  287. package/dist/types.js +3 -9
  288. package/dist/types.mjs +2 -8
  289. package/dist/ui.js +1 -1
  290. package/dist/ui.mjs +1 -1
  291. package/dist/validation.js +7 -7
  292. package/dist/validation.mjs +6 -6
  293. package/dist/versions.js +1 -1
  294. package/dist/versions.mjs +1 -1
  295. package/dist/virtual-file/VirtualFile.js +1 -1
  296. package/dist/virtual-file/VirtualFile.mjs +1 -1
  297. package/dist/virtual-file/index.js +1 -1
  298. package/dist/virtual-file/index.mjs +1 -1
  299. package/dist/virtual-file/node.js +1 -1
  300. package/dist/virtual-file/node.mjs +1 -1
  301. package/dist/virtual-file/toVirtualFile.js +1 -1
  302. package/dist/virtual-file/toVirtualFile.mjs +1 -1
  303. package/package.json +6 -6
  304. package/dist/chunk-25ESL4NL.js +0 -409
  305. package/dist/chunk-25ESL4NL.js.map +0 -1
  306. package/dist/chunk-AJNKQYKP.mjs.map +0 -1
  307. package/dist/chunk-F6G67XQ4.js +0 -1
  308. package/dist/chunk-FLSK6ISS.mjs.map +0 -1
  309. package/dist/chunk-H35ZUVQT.mjs.map +0 -1
  310. package/dist/chunk-KCECQM3L.mjs +0 -409
  311. package/dist/chunk-KCECQM3L.mjs.map +0 -1
  312. package/dist/chunk-KSRDEGBC.js.map +0 -1
  313. package/dist/chunk-OYZPBNHS.mjs +0 -1
  314. package/dist/chunk-PZNIU23I.js.map +0 -1
  315. package/dist/chunk-RD6BN2TQ.js.map +0 -1
  316. package/dist/chunk-VOPTAKVG.js.map +0 -1
  317. package/dist/chunk-X3XJN63W.mjs.map +0 -1
  318. package/dist/npm.js +0 -35
  319. package/dist/npm.mjs +0 -35
  320. package/dist/types/npm.d.ts +0 -19
  321. /package/dist/{chunk-5I5WPAVD.js.map → chunk-37EUH3KZ.js.map} +0 -0
  322. /package/dist/{chunk-SB43G2RI.js.map → chunk-3OXW5H4F.js.map} +0 -0
  323. /package/dist/{chunk-K6BCBPXF.js.map → chunk-3RFGTBEP.js.map} +0 -0
  324. /package/dist/{chunk-JMDSN227.mjs.map → chunk-3RUWAMJT.mjs.map} +0 -0
  325. /package/dist/{chunk-F6G67XQ4.js.map → chunk-FA4QIZH6.js.map} +0 -0
  326. /package/dist/{chunk-ZXHR322P.mjs.map → chunk-GXSTPU7D.mjs.map} +0 -0
  327. /package/dist/{chunk-YNOZU43P.mjs.map → chunk-IPUL74MZ.mjs.map} +0 -0
  328. /package/dist/{chunk-OYZPBNHS.mjs.map → chunk-NNYGTNHP.mjs.map} +0 -0
  329. /package/dist/{chunk-VWGXNUMD.mjs.map → chunk-PZF4KWU2.mjs.map} +0 -0
  330. /package/dist/{chunk-PHUTP7NB.js.map → chunk-S3BWTUTZ.js.map} +0 -0
  331. /package/dist/{npm.js.map → chunk-VWLBM7XM.js.map} +0 -0
  332. /package/dist/{npm.mjs.map → chunk-W7A3BYUP.mjs.map} +0 -0
@@ -0,0 +1,24 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkW7KRIAIXjs = require('./chunk-W7KRIAIX.js');
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 = _chunkW7KRIAIXjs.getSvgDimensions.call(void 0, 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
+
22
+
23
+ exports.iconDimensions = iconDimensions;
24
+ //# sourceMappingURL=chunk-GJAVOB7B.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/icon-dimensions.ts"],"names":[],"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","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"]}
@@ -1,13 +1,13 @@
1
1
  import {
2
2
  SnapIdStruct
3
- } from "./chunk-H35ZUVQT.mjs";
3
+ } from "./chunk-NSVVZNSD.mjs";
4
4
  import {
5
5
  mergeStructs
6
- } from "./chunk-FLSK6ISS.mjs";
6
+ } from "./chunk-3N27GIUS.mjs";
7
7
  import {
8
8
  NameStruct,
9
9
  uri
10
- } from "./chunk-AJNKQYKP.mjs";
10
+ } from "./chunk-N2JAYIUP.mjs";
11
11
  import {
12
12
  ChainIdStruct
13
13
  } from "./chunk-LHQP7CUJ.mjs";
@@ -290,4 +290,4 @@ export {
290
290
  assertIsSnapManifest,
291
291
  createSnapManifest
292
292
  };
293
- //# sourceMappingURL=chunk-ZXHR322P.mjs.map
293
+ //# sourceMappingURL=chunk-GXSTPU7D.mjs.map
@@ -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":[]}
@@ -149,6 +149,16 @@ var SNAPS_DERIVATION_PATHS = [
149
149
  path: ["m", `1852'`, `1815'`],
150
150
  curve: "ed25519Bip32",
151
151
  name: "Cardano"
152
+ },
153
+ {
154
+ path: ["m", `44'`, `508'`, `0'`, `0'`, `0'`],
155
+ curve: "ed25519",
156
+ name: "MultiversX"
157
+ },
158
+ {
159
+ path: ["m", `44'`, `709'`],
160
+ curve: "secp256k1",
161
+ name: "Avail"
152
162
  }
153
163
  ];
154
164
  function getSnapDerivationPathName(path, curve) {
@@ -176,4 +186,4 @@ export {
176
186
  getSnapDerivationPathName,
177
187
  getSlip44ProtocolName
178
188
  };
179
- //# sourceMappingURL=chunk-X3XJN63W.mjs.map
189
+ //# sourceMappingURL=chunk-IELPPZJP.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/derivation-paths.ts"],"sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport slip44 from '@metamask/slip44';\n\nimport { isEqual } from './array';\n\nexport type SnapsDerivationPath = {\n path: ['m', ...string[]];\n curve: SupportedCurve;\n name: string;\n};\n\nexport const SNAPS_DERIVATION_PATHS: SnapsDerivationPath[] = [\n {\n path: ['m', `44'`, `0'`],\n curve: 'ed25519',\n name: 'Test BIP-32 Path (ed25519)',\n },\n {\n path: ['m', `44'`, `1'`],\n curve: 'secp256k1',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Legacy',\n },\n {\n path: ['m', `49'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Nested SegWit',\n },\n {\n path: ['m', `49'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Nested SegWit',\n },\n {\n path: ['m', `84'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Native SegWit',\n },\n {\n path: ['m', `84'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Native SegWit',\n },\n {\n path: ['m', `44'`, `501'`],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `501'`, \"0'\", \"0'\"],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `2'`],\n curve: 'secp256k1',\n name: 'Litecoin',\n },\n {\n path: ['m', `44'`, `3'`],\n curve: 'secp256k1',\n name: 'Dogecoin',\n },\n {\n path: ['m', `44'`, `60'`],\n curve: 'secp256k1',\n name: 'Ethereum',\n },\n {\n path: ['m', `44'`, `118'`],\n curve: 'secp256k1',\n name: 'Atom',\n },\n {\n path: ['m', `44'`, `145'`],\n curve: 'secp256k1',\n name: 'Bitcoin Cash',\n },\n {\n path: ['m', `44'`, `637'`],\n curve: 'ed25519',\n name: 'Aptos',\n },\n {\n path: ['m', `44'`, `714'`],\n curve: 'secp256k1',\n name: 'Binance (BNB)',\n },\n {\n path: ['m', `44'`, `784'`],\n curve: 'ed25519',\n name: 'Sui',\n },\n {\n path: ['m', `44'`, `931'`],\n curve: 'secp256k1',\n name: 'THORChain (RUNE)',\n },\n {\n path: ['m', `44'`, `330'`],\n curve: 'secp256k1',\n name: 'Terra (LUNA)',\n },\n {\n path: ['m', `44'`, `459'`],\n curve: 'secp256k1',\n name: 'Kava',\n },\n {\n path: ['m', `44'`, `529'`],\n curve: 'secp256k1',\n name: 'Secret Network',\n },\n {\n path: ['m', `44'`, `397'`, `0'`],\n curve: 'ed25519',\n name: 'NEAR Protocol',\n },\n {\n path: ['m', `44'`, `1'`, `0'`],\n curve: 'ed25519',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `472'`],\n curve: 'ed25519',\n name: 'Arweave',\n },\n {\n path: ['m', `44'`, `12586'`],\n curve: 'secp256k1',\n name: 'Mina',\n },\n {\n path: ['m', `44'`, `242'`],\n curve: 'ed25519',\n name: 'Nimiq',\n },\n {\n path: ['m', `44'`, `1729'`, `0'`, `0'`],\n curve: 'ed25519',\n name: 'Tezos',\n },\n {\n path: ['m', `1789'`, `0'`],\n curve: 'ed25519',\n name: 'Vega',\n },\n {\n path: ['m', `1852'`, `1815'`],\n curve: 'ed25519Bip32',\n name: 'Cardano',\n },\n {\n path: ['m', `44'`, `508'`, `0'`, `0'`, `0'`],\n curve: 'ed25519',\n name: 'MultiversX',\n },\n {\n path: ['m', `44'`, `709'`],\n curve: 'secp256k1',\n name: 'Avail',\n },\n];\n\n/**\n * Gets the name of a derivation path supported by snaps.\n *\n * @param path - The derivation path.\n * @param curve - The curve used to derive the keys.\n * @returns The name of the derivation path, otherwise null.\n */\nexport function getSnapDerivationPathName(\n path: SnapsDerivationPath['path'],\n curve: SupportedCurve,\n): string | null {\n const pathMetadata = SNAPS_DERIVATION_PATHS.find(\n (derivationPath) =>\n derivationPath.curve === curve && isEqual(derivationPath.path, path),\n );\n\n if (pathMetadata) {\n return pathMetadata.name;\n }\n\n // If the curve is secp256k1 and the path is a valid BIP44 path\n // we try looking for the network/protocol name in SLIP44\n if (\n curve === 'secp256k1' &&\n path[0] === 'm' &&\n path[1] === `44'` &&\n path[2].endsWith(`'`)\n ) {\n const coinType = path[2].slice(0, -1);\n return getSlip44ProtocolName(coinType) ?? null;\n }\n\n return null;\n}\n\n/**\n * Gets the name of the SLIP-44 protocol corresponding to the specified\n * `coin_type`.\n *\n * @param coinType - The SLIP-44 `coin_type` value whose name\n * to retrieve.\n * @returns The name of the protocol, otherwise null.\n */\nexport function getSlip44ProtocolName(coinType: number | string) {\n if (String(coinType) === '1') {\n return 'Test Networks';\n }\n\n return slip44[coinType as keyof typeof slip44]?.name ?? null;\n}\n"],"mappings":";;;;;AACA,OAAO,YAAY;AAUZ,IAAM,yBAAgD;AAAA,EAC3D;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,MAAM;AAAA,IACzB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,QAAQ,MAAM,IAAI;AAAA,IACrC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AK,CAAC,MAAM,SACZ,KAAK,CAAC,EAAE,SAAS,GAAG,GACpB;AACA,UAAM,WAAW,KAAK,CAAC,EAAE,MAAM,GAAG,EAAE;AACpC,WAAO,sBAAsB,QAAQ,KAAK;AAAA,EAC5C;AAEA,SAAO;AACT;AAUO,SAAS,sBAAsB,UAA2B;AAC/D,MAAI,OAAO,QAAQ,MAAM,KAAK;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,QAA+B,GAAG,QAAQ;AAC1D;","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":";;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,uBAAuB;AAEhC,SAAS,QAAQ,qBAAqB;AACtC,SAAS,YAAY,UAAU;AAC/B,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AAO;AACd,UAAM,IAAI,MAAM,kCAAkC,gBAAgB,KAAK,CAAC,EAAE;AAAA,EAC5E;AACF;AASO,SAAS,iBACd,UACA,UACA;AACA,MAAI,CAAC,cAAc,QAAQ,GAAG;AAC5B,WAAO;AAAA,EACT;AAEA,QAAM,eAAe;AACrB,QAAM,QAAQ,SAAS,YAAY;AAEnC,MAAI,CAAC,MAAM,QAAQ,KAAK,GAAG;AACzB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAWA,eAAsB,aACpB,UACA,OACA,WAAkC,QACE;AACpC,MAAI,CAAC,OAAO;AACV,WAAO;AAAA,EACT;AAEA,MAAI;AACF,WAAO,MAAM,QAAQ;AAAA,MACnB,MAAM;AAAA,QAAI,OAAO,aACf,gBAAgB,UAAU,KAAK,UAAU,QAAQ,GAAG,QAAQ;AAAA,MAC9D;AAAA,IACF;AAAA,EACF,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,8BAA8B,gBAAgB,KAAK,CAAC,EAAE;AAAA,EACxE;AACF;AASO,SAAS,oBAAoB,UAAsC;AACxE,QAAM,EAAE,YAAY,GAAG,UAAU,IAAI;AAErC,QAAM,OAAO,OAAO;AAAA,IAClB,aAAa,EAAE,GAAG,WAAW,WAAW,IAAI;AAAA,EAC9C;AAEA,QAAM,mBAAmB,KACtB,KAAK,CAAC,GAAG,MAAM,oBAAoB,CAAC,IAAI,oBAAoB,CAAC,CAAC,EAC9D;AAAA,IACC,CAAC,QAAQ,SAAS;AAAA,MAChB,GAAG;AAAA,MACH,CAAC,GAAG,GAAG,SAAS,GAAG;AAAA,IACrB;AAAA,IACA,CAAC;AAAA,EACH;AAEF,SAAO;AACT","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":[]}