@metamask/snaps-utils 7.8.1 → 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 (326) hide show
  1. package/CHANGELOG.md +8 -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 +4 -4
  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
package/CHANGELOG.md CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [8.0.0]
10
+ ### Changed
11
+ - **BREAKING:** Improve manifest validation output ([#2605](https://github.com/MetaMask/snaps/pull/2605), [#2572](https://github.com/MetaMask/snaps/pull/2572))
12
+ - This is breaking as it removes exports such as `validateNpmSnap`.
13
+ - Bump `fast-xml-parser` ([#2610](https://github.com/MetaMask/snaps/pull/2610))
14
+
9
15
  ## [7.8.1]
10
16
  ### Changed
11
17
  - Bump `@metamask/base-controller` from `^6.0.1` to `^6.0.2` ([#2593](https://github.com/metamask/snaps/pull/2593))
@@ -287,7 +293,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
287
293
  - The version of the package no longer needs to match the version of all other
288
294
  MetaMask Snaps packages.
289
295
 
290
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@7.8.1...HEAD
296
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.0.0...HEAD
297
+ [8.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@7.8.1...@metamask/snaps-utils@8.0.0
291
298
  [7.8.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@7.8.0...@metamask/snaps-utils@7.8.1
292
299
  [7.8.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@7.7.0...@metamask/snaps-utils@7.8.0
293
300
  [7.7.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@7.6.0...@metamask/snaps-utils@7.7.0
package/dist/array.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
  var _chunkT3YY4JIJjs = require('./chunk-T3YY4JIJ.js');
4
- require('./chunk-PHUTP7NB.js');
4
+ require('./chunk-S3BWTUTZ.js');
5
5
 
6
6
 
7
7
  exports.isEqual = _chunkT3YY4JIJjs.isEqual;
package/dist/array.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isEqual
3
3
  } from "./chunk-P252LKUT.mjs";
4
- import "./chunk-JMDSN227.mjs";
4
+ import "./chunk-3RUWAMJT.mjs";
5
5
  export {
6
6
  isEqual
7
7
  };
@@ -7,7 +7,7 @@ require('./chunk-UAINMOUU.js');
7
7
  require('./chunk-DEQUNIME.js');
8
8
  require('./chunk-NUCLSR2G.js');
9
9
  require('./chunk-5WKQI22S.js');
10
- require('./chunk-PHUTP7NB.js');
10
+ require('./chunk-S3BWTUTZ.js');
11
11
 
12
12
 
13
13
 
@@ -7,7 +7,7 @@ import "./chunk-3S4INAGA.mjs";
7
7
  import "./chunk-DE22V5AO.mjs";
8
8
  import "./chunk-Z2JQNSVL.mjs";
9
9
  import "./chunk-SPCIIRSB.mjs";
10
- import "./chunk-JMDSN227.mjs";
10
+ import "./chunk-3RUWAMJT.mjs";
11
11
  export {
12
12
  encodeAuxiliaryFile,
13
13
  validateAuxiliaryFiles
package/dist/base64.js CHANGED
@@ -5,7 +5,7 @@ var _chunkOBN2WDFUjs = require('./chunk-OBN2WDFU.js');
5
5
  require('./chunk-UAINMOUU.js');
6
6
  require('./chunk-DEQUNIME.js');
7
7
  require('./chunk-NUCLSR2G.js');
8
- require('./chunk-PHUTP7NB.js');
8
+ require('./chunk-S3BWTUTZ.js');
9
9
 
10
10
 
11
11
 
package/dist/base64.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  import "./chunk-3S4INAGA.mjs";
6
6
  import "./chunk-DE22V5AO.mjs";
7
7
  import "./chunk-Z2JQNSVL.mjs";
8
- import "./chunk-JMDSN227.mjs";
8
+ import "./chunk-3RUWAMJT.mjs";
9
9
  export {
10
10
  decodeBase64,
11
11
  encodeBase64
package/dist/bytes.js CHANGED
@@ -3,7 +3,7 @@
3
3
  var _chunkUAINMOUUjs = require('./chunk-UAINMOUU.js');
4
4
  require('./chunk-DEQUNIME.js');
5
5
  require('./chunk-NUCLSR2G.js');
6
- require('./chunk-PHUTP7NB.js');
6
+ require('./chunk-S3BWTUTZ.js');
7
7
 
8
8
 
9
9
  exports.getBytes = _chunkUAINMOUUjs.getBytes;
package/dist/bytes.mjs CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  } from "./chunk-3S4INAGA.mjs";
4
4
  import "./chunk-DE22V5AO.mjs";
5
5
  import "./chunk-Z2JQNSVL.mjs";
6
- import "./chunk-JMDSN227.mjs";
6
+ import "./chunk-3RUWAMJT.mjs";
7
7
  export {
8
8
  getBytes
9
9
  };
package/dist/caveats.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
  var _chunkASZWZ7JTjs = require('./chunk-ASZWZ7JT.js');
4
- require('./chunk-PHUTP7NB.js');
4
+ require('./chunk-S3BWTUTZ.js');
5
5
 
6
6
 
7
7
  exports.SnapCaveatType = _chunkASZWZ7JTjs.SnapCaveatType;
package/dist/caveats.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  SnapCaveatType
3
3
  } from "./chunk-7LG4D4XA.mjs";
4
- import "./chunk-JMDSN227.mjs";
4
+ import "./chunk-3RUWAMJT.mjs";
5
5
  export {
6
6
  SnapCaveatType
7
7
  };
package/dist/checksum.js CHANGED
@@ -5,7 +5,7 @@ var _chunkAMW2VJ3Njs = require('./chunk-AMW2VJ3N.js');
5
5
  require('./chunk-UAINMOUU.js');
6
6
  require('./chunk-DEQUNIME.js');
7
7
  require('./chunk-NUCLSR2G.js');
8
- require('./chunk-PHUTP7NB.js');
8
+ require('./chunk-S3BWTUTZ.js');
9
9
 
10
10
 
11
11
 
package/dist/checksum.mjs CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  import "./chunk-3S4INAGA.mjs";
6
6
  import "./chunk-DE22V5AO.mjs";
7
7
  import "./chunk-Z2JQNSVL.mjs";
8
- import "./chunk-JMDSN227.mjs";
8
+ import "./chunk-3RUWAMJT.mjs";
9
9
  export {
10
10
  checksum,
11
11
  checksumFiles
@@ -1,13 +1,13 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkRD6BN2TQjs = require('./chunk-RD6BN2TQ.js');
3
+ var _chunkTAMKWZ4Ejs = require('./chunk-TAMKWZ4E.js');
4
4
 
5
5
 
6
- var _chunkVOPTAKVGjs = require('./chunk-VOPTAKVG.js');
6
+ var _chunk53QXTM77js = require('./chunk-53QXTM77.js');
7
7
 
8
8
 
9
9
 
10
- var _chunkPZNIU23Ijs = require('./chunk-PZNIU23I.js');
10
+ var _chunkMWAZGSROjs = require('./chunk-MWAZGSRO.js');
11
11
 
12
12
 
13
13
  var _chunkLOJA2ZS4js = require('./chunk-LOJA2ZS4.js');
@@ -122,7 +122,7 @@ var SemVerRangeStruct = _superstruct.refine.call(void 0, _superstruct.string.cal
122
122
  return "Expected a valid SemVer range.";
123
123
  });
124
124
  var SnapIdsStruct = _superstruct.refine.call(void 0,
125
- _superstruct.record.call(void 0, _chunkRD6BN2TQjs.SnapIdStruct, _superstruct.object.call(void 0, { version: _superstruct.optional.call(void 0, SemVerRangeStruct) })),
125
+ _superstruct.record.call(void 0, _chunkTAMKWZ4Ejs.SnapIdStruct, _superstruct.object.call(void 0, { version: _superstruct.optional.call(void 0, SemVerRangeStruct) })),
126
126
  "SnapIds",
127
127
  (value) => {
128
128
  if (Object.keys(value).length === 0) {
@@ -157,18 +157,18 @@ var HandlerCaveatsStruct = _superstruct.object.call(void 0, {
157
157
  var EmptyObjectStruct = _superstruct.object.call(void 0, {});
158
158
  var PermissionsStruct = _superstruct.type.call(void 0, {
159
159
  "endowment:cronjob": _superstruct.optional.call(void 0,
160
- _chunkVOPTAKVGjs.mergeStructs.call(void 0,
160
+ _chunk53QXTM77js.mergeStructs.call(void 0,
161
161
  HandlerCaveatsStruct,
162
162
  _superstruct.object.call(void 0, { jobs: _chunk4ZJOU3LRjs.CronjobSpecificationArrayStruct })
163
163
  )
164
164
  ),
165
165
  "endowment:ethereum-provider": _superstruct.optional.call(void 0, EmptyObjectStruct),
166
166
  "endowment:keyring": _superstruct.optional.call(void 0,
167
- _chunkVOPTAKVGjs.mergeStructs.call(void 0, HandlerCaveatsStruct, _chunkT2VA4YJEjs.KeyringOriginsStruct)
167
+ _chunk53QXTM77js.mergeStructs.call(void 0, HandlerCaveatsStruct, _chunkT2VA4YJEjs.KeyringOriginsStruct)
168
168
  ),
169
169
  "endowment:lifecycle-hooks": _superstruct.optional.call(void 0, HandlerCaveatsStruct),
170
170
  "endowment:name-lookup": _superstruct.optional.call(void 0,
171
- _chunkVOPTAKVGjs.mergeStructs.call(void 0,
171
+ _chunk53QXTM77js.mergeStructs.call(void 0,
172
172
  HandlerCaveatsStruct,
173
173
  _superstruct.object.call(void 0, {
174
174
  chains: _superstruct.optional.call(void 0, ChainIdsStruct),
@@ -179,10 +179,10 @@ var PermissionsStruct = _superstruct.type.call(void 0, {
179
179
  "endowment:network-access": _superstruct.optional.call(void 0, EmptyObjectStruct),
180
180
  "endowment:page-home": _superstruct.optional.call(void 0, HandlerCaveatsStruct),
181
181
  "endowment:rpc": _superstruct.optional.call(void 0,
182
- _chunkVOPTAKVGjs.mergeStructs.call(void 0, HandlerCaveatsStruct, _chunkT2VA4YJEjs.RpcOriginsStruct)
182
+ _chunk53QXTM77js.mergeStructs.call(void 0, HandlerCaveatsStruct, _chunkT2VA4YJEjs.RpcOriginsStruct)
183
183
  ),
184
184
  "endowment:signature-insight": _superstruct.optional.call(void 0,
185
- _chunkVOPTAKVGjs.mergeStructs.call(void 0,
185
+ _chunk53QXTM77js.mergeStructs.call(void 0,
186
186
  HandlerCaveatsStruct,
187
187
  _superstruct.object.call(void 0, {
188
188
  allowSignatureOrigin: _superstruct.optional.call(void 0, _superstruct.boolean.call(void 0, ))
@@ -190,7 +190,7 @@ var PermissionsStruct = _superstruct.type.call(void 0, {
190
190
  )
191
191
  ),
192
192
  "endowment:transaction-insight": _superstruct.optional.call(void 0,
193
- _chunkVOPTAKVGjs.mergeStructs.call(void 0,
193
+ _chunk53QXTM77js.mergeStructs.call(void 0,
194
194
  HandlerCaveatsStruct,
195
195
  _superstruct.object.call(void 0, {
196
196
  allowTransactionOrigin: _superstruct.optional.call(void 0, _superstruct.boolean.call(void 0, ))
@@ -217,7 +217,7 @@ var PermissionsStruct = _superstruct.type.call(void 0, {
217
217
  });
218
218
  var SnapAuxilaryFilesStruct = _superstruct.array.call(void 0, _superstruct.string.call(void 0, ));
219
219
  var InitialConnectionsStruct = _superstruct.record.call(void 0,
220
- _superstruct.intersection.call(void 0, [_superstruct.string.call(void 0, ), _chunkPZNIU23Ijs.uri.call(void 0, )]),
220
+ _superstruct.intersection.call(void 0, [_superstruct.string.call(void 0, ), _chunkMWAZGSROjs.uri.call(void 0, )]),
221
221
  _superstruct.object.call(void 0, {})
222
222
  );
223
223
  var SnapManifestStruct = _superstruct.object.call(void 0, {
@@ -236,7 +236,7 @@ var SnapManifestStruct = _superstruct.object.call(void 0, {
236
236
  npm: _superstruct.object.call(void 0, {
237
237
  filePath: _superstruct.size.call(void 0, _superstruct.string.call(void 0, ), 1, Infinity),
238
238
  iconPath: _superstruct.optional.call(void 0, _superstruct.size.call(void 0, _superstruct.string.call(void 0, ), 1, Infinity)),
239
- packageName: _chunkPZNIU23Ijs.NameStruct,
239
+ packageName: _chunkMWAZGSROjs.NameStruct,
240
240
  registry: _superstruct.union.call(void 0, [
241
241
  _superstruct.literal.call(void 0, "https://registry.npmjs.org"),
242
242
  _superstruct.literal.call(void 0, "https://registry.npmjs.org/")
@@ -290,4 +290,4 @@ function createSnapManifest(value) {
290
290
 
291
291
 
292
292
  exports.FORBIDDEN_COIN_TYPES = FORBIDDEN_COIN_TYPES; exports.Bip32PathStruct = Bip32PathStruct; exports.bip32entropy = bip32entropy; exports.CurveStruct = CurveStruct; exports.Bip32EntropyStruct = Bip32EntropyStruct; exports.SnapGetBip32EntropyPermissionsStruct = SnapGetBip32EntropyPermissionsStruct; exports.SemVerRangeStruct = SemVerRangeStruct; exports.SnapIdsStruct = SnapIdsStruct; exports.ChainIdsStruct = ChainIdsStruct; exports.LookupMatchersStruct = LookupMatchersStruct; exports.MINIMUM_REQUEST_TIMEOUT = MINIMUM_REQUEST_TIMEOUT; exports.MAXIMUM_REQUEST_TIMEOUT = MAXIMUM_REQUEST_TIMEOUT; exports.MaxRequestTimeStruct = MaxRequestTimeStruct; exports.HandlerCaveatsStruct = HandlerCaveatsStruct; exports.EmptyObjectStruct = EmptyObjectStruct; exports.PermissionsStruct = PermissionsStruct; exports.SnapAuxilaryFilesStruct = SnapAuxilaryFilesStruct; exports.InitialConnectionsStruct = InitialConnectionsStruct; exports.SnapManifestStruct = SnapManifestStruct; exports.isSnapManifest = isSnapManifest; exports.assertIsSnapManifest = assertIsSnapManifest; exports.createSnapManifest = createSnapManifest;
293
- //# sourceMappingURL=chunk-5I5WPAVD.js.map
293
+ //# sourceMappingURL=chunk-37EUH3KZ.js.map
@@ -134,6 +134,9 @@ function getStructFailureMessage(struct, failure, colorize = true) {
134
134
  ).replace(/length of `(\d+)`/u, `length of ${color("$1", red, colorize)}`).replace(/a array/u, "an array");
135
135
  return `${prefix}${message}.`;
136
136
  }
137
+ if (failure.refinement !== void 0) {
138
+ return `${prefix}${failure.message}.`;
139
+ }
137
140
  return `${prefix}Expected a value of type ${color(
138
141
  failure.type,
139
142
  green,
@@ -223,4 +226,4 @@ export {
223
226
  createUnion,
224
227
  mergeStructs
225
228
  };
226
- //# sourceMappingURL=chunk-FLSK6ISS.mjs.map
229
+ //# sourceMappingURL=chunk-3N27GIUS.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/structs.ts"],"sourcesContent":["import { union } from '@metamask/snaps-sdk';\nimport type {\n AnyStruct,\n Assign,\n Failure,\n ObjectSchema,\n ObjectType,\n} from '@metamask/superstruct';\nimport {\n assign,\n is,\n validate,\n type as superstructType,\n Struct,\n StructError,\n create,\n} from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert, isObject } from '@metamask/utils';\nimport { bold, green, red } from 'chalk';\n\nimport { indent } from './strings';\n\n/**\n * Infer a struct type, only if it matches the specified type. This is useful\n * for defining types and structs that are related to each other in separate\n * files.\n *\n * @example\n * ```typescript\n * // In file A\n * export type GetFileArgs = {\n * path: string;\n * encoding?: EnumToUnion<AuxiliaryFileEncoding>;\n * };\n *\n * // In file B\n * export const GetFileArgsStruct = object(...);\n *\n * // If the type and struct are in the same file, this will return the type.\n * // Otherwise, it will return `never`.\n * export type GetFileArgs =\n * InferMatching<typeof GetFileArgsStruct, GetFileArgs>;\n * ```\n */\nexport type InferMatching<\n StructType extends Struct<any, any>,\n Type,\n> = StructType['TYPE'] extends Type ? Type : never;\n\n/**\n * Colorize a value with a color function. This is useful for colorizing values\n * in error messages. If colorization is disabled, the original value is\n * returned.\n *\n * @param value - The value to colorize.\n * @param colorFunction - The color function to use.\n * @param enabled - Whether to colorize the value.\n * @returns The colorized value, or the original value if colorization is\n * disabled.\n */\nfunction color(\n value: string,\n colorFunction: (value: string) => string,\n enabled: boolean,\n) {\n if (enabled) {\n return colorFunction(value);\n }\n\n return value;\n}\n\n/**\n * Define a struct, and also define the name of the struct as the given name.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n *\n * @param name - The name of the struct.\n * @param struct - The struct.\n * @returns The struct.\n */\nexport function named<Type, Schema>(\n name: string,\n struct: Struct<Type, Schema>,\n) {\n return new Struct({\n ...struct,\n type: name,\n });\n}\n\nexport class SnapsStructError<Type, Schema> extends StructError {\n constructor(\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix: string,\n failure: StructError,\n failures: () => Generator<Failure>,\n colorize = true,\n ) {\n super(failure, failures);\n\n this.name = 'SnapsStructError';\n this.message = `${prefix}.\\n\\n${getStructErrorMessage(\n struct,\n [...failures()],\n colorize,\n )}${suffix ? `\\n\\n${suffix}` : ''}`;\n }\n}\n\ntype GetErrorOptions<Type, Schema> = {\n struct: Struct<Type, Schema>;\n prefix: string;\n suffix?: string;\n error: StructError;\n colorize?: boolean;\n};\n\n/**\n * Converts an array to a generator function that yields the items in the\n * array.\n *\n * @param array - The array.\n * @returns A generator function.\n * @yields The items in the array.\n */\nexport function* arrayToGenerator<Type>(\n array: Type[],\n): Generator<Type, void, undefined> {\n for (const item of array) {\n yield item;\n }\n}\n\n/**\n * Returns a `SnapsStructError` with the given prefix and suffix.\n *\n * @param options - The options.\n * @param options.struct - The struct that caused the error.\n * @param options.prefix - The prefix to add to the error message.\n * @param options.suffix - The suffix to add to the error message. Defaults to\n * an empty string.\n * @param options.error - The `superstruct` error to wrap.\n * @param options.colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The `SnapsStructError`.\n */\nexport function getError<Type, Schema>({\n struct,\n prefix,\n suffix = '',\n error,\n colorize,\n}: GetErrorOptions<Type, Schema>) {\n return new SnapsStructError(\n struct,\n prefix,\n suffix,\n error,\n () => arrayToGenerator(error.failures()),\n colorize,\n );\n}\n\n/**\n * A wrapper of `superstruct`'s `create` function that throws a\n * `SnapsStructError` instead of a `StructError`. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` struct to validate the value against.\n * @param prefix - The prefix to add to the error message.\n * @param suffix - The suffix to add to the error message. Defaults to an empty\n * string.\n * @returns The validated value.\n */\nexport function createFromStruct<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix = '',\n) {\n try {\n return create(value, struct);\n } catch (error) {\n if (error instanceof StructError) {\n throw getError({ struct, prefix, suffix, error });\n }\n\n throw error;\n }\n}\n\n/**\n * Get a struct from a failure path.\n *\n * @param struct - The struct.\n * @param path - The failure path.\n * @returns The struct at the failure path.\n */\nexport function getStructFromPath<Type, Schema>(\n struct: Struct<Type, Schema>,\n path: string[],\n) {\n return path.reduce<AnyStruct>((result, key) => {\n if (isObject(struct.schema) && struct.schema[key]) {\n return struct.schema[key] as AnyStruct;\n }\n\n return result;\n }, struct);\n}\n\n/**\n * Get the union struct names from a struct.\n *\n * @param struct - The struct.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The union struct names, or `null` if the struct is not a union\n * struct.\n */\nexport function getUnionStructNames<Type, Schema>(\n struct: Struct<Type, Schema>,\n colorize = true,\n) {\n if (Array.isArray(struct.schema)) {\n return struct.schema.map(({ type }) => color(type, green, colorize));\n }\n\n return null;\n}\n\n/**\n * Get an error prefix from a `superstruct` failure. This is useful for\n * formatting the error message returned by `superstruct`.\n *\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The error prefix.\n */\nexport function getStructErrorPrefix(failure: Failure, colorize = true) {\n if (failure.type === 'never' || failure.path.length === 0) {\n return '';\n }\n\n return `At path: ${color(failure.path.join('.'), bold, colorize)} — `;\n}\n\n/**\n * Get a string describing the failure. This is similar to the `message`\n * property of `superstruct`'s `Failure` type, but formats the value in a more\n * readable way.\n *\n * @param struct - The struct that caused the failure.\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the failure.\n */\nexport function getStructFailureMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failure: Failure,\n colorize = true,\n) {\n const received = color(JSON.stringify(failure.value), red, colorize);\n const prefix = getStructErrorPrefix(failure, colorize);\n\n if (failure.type === 'union') {\n const childStruct = getStructFromPath(struct, failure.path);\n const unionNames = getUnionStructNames(childStruct, colorize);\n\n if (unionNames) {\n return `${prefix}Expected the value to be one of: ${unionNames.join(\n ', ',\n )}, but received: ${received}.`;\n }\n\n return `${prefix}${failure.message}.`;\n }\n\n if (failure.type === 'literal') {\n // Superstruct's failure does not provide information about which literal\n // value was expected, so we need to parse the message to get the literal.\n const message = failure.message\n .replace(\n /the literal `(.+)`,/u,\n `the value to be \\`${color('$1', green, colorize)}\\`,`,\n )\n .replace(\n /, but received: (.+)/u,\n `, but received: ${color('$1', red, colorize)}`,\n );\n\n return `${prefix}${message}.`;\n }\n\n if (failure.type === 'never') {\n return `Unknown key: ${color(\n failure.path.join('.'),\n bold,\n colorize,\n )}, received: ${received}.`;\n }\n\n if (failure.refinement === 'size') {\n const message = failure.message\n .replace(\n /length between `(\\d+)` and `(\\d+)`/u,\n `length between ${color('$1', green, colorize)} and ${color(\n '$2',\n green,\n colorize,\n )},`,\n )\n .replace(/length of `(\\d+)`/u, `length of ${color('$1', red, colorize)}`)\n .replace(/a array/u, 'an array');\n\n return `${prefix}${message}.`;\n }\n\n // Refinements we built ourselves have nice error messages\n if (failure.refinement !== undefined) {\n return `${prefix}${failure.message}.`;\n }\n\n return `${prefix}Expected a value of type ${color(\n failure.type,\n green,\n colorize,\n )}, but received: ${received}.`;\n}\n\n/**\n * Get a string describing the errors. This formats all the errors in a\n * human-readable way.\n *\n * @param struct - The struct that caused the failures.\n * @param failures - The `superstruct` failures.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the errors.\n */\nexport function getStructErrorMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failures: Failure[],\n colorize = true,\n) {\n const formattedFailures = failures.map((failure) =>\n indent(`• ${getStructFailureMessage(struct, failure, colorize)}`),\n );\n\n return formattedFailures.join('\\n');\n}\n\n/**\n * Validate a union struct, and throw readable errors if the value does not\n * satisfy the struct. This is useful for improving the error messages returned\n * by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @param coerce - Whether to coerce the value to satisfy the struct. Defaults\n * to `false`.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @example\n * const struct = union([\n * object({ type: literal('a'), value: string() }),\n * object({ type: literal('b'), value: number() }),\n * object({ type: literal('c'), value: boolean() }),\n * // ...\n * ]);\n *\n * // At path: type — Expected the value to be one of: \"a\", \"b\", \"c\", but received: \"d\".\n * validateUnion({ type: 'd', value: 'foo' }, struct, 'type');\n *\n * // At path: value — Expected a value of type string, but received: 42.\n * validateUnion({ type: 'a', value: 42 }, struct, 'value');\n */\nexport function validateUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n coerce = false,\n) {\n assert(\n struct.schema,\n 'Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`.',\n );\n assert(struct.schema.length > 0, 'Expected a non-empty array of structs.');\n\n const keyUnion = struct.schema.map(\n (innerStruct) => innerStruct.schema[structKey],\n // This is guaranteed to be a non-empty array by the assertion above. We\n // need to cast it since `superstruct` requires a non-empty array of structs\n // for the `union` struct.\n ) as NonEmptyArray<Struct>;\n\n const key = superstructType({\n [structKey]: union(keyUnion),\n });\n\n const [keyError] = validate(value, key, { coerce });\n if (keyError) {\n throw new Error(\n getStructFailureMessage(key, keyError.failures()[0], false),\n );\n }\n\n // At this point it's guaranteed that the value is an object, so we can safely\n // cast it to a Record.\n const objectValue = value as Record<PropertyKey, unknown>;\n const objectStructs = struct.schema.filter((innerStruct) =>\n is(objectValue[structKey], innerStruct.schema[structKey]),\n );\n\n assert(objectStructs.length > 0, 'Expected a struct to match the value.');\n\n // We need to validate the value against all the object structs that match the\n // struct key, and return the first validated value.\n const validationResults = objectStructs.map((objectStruct) =>\n validate(objectValue, objectStruct, { coerce }),\n );\n\n const validatedValue = validationResults.find(([error]) => !error);\n if (validatedValue) {\n return validatedValue[1];\n }\n\n assert(validationResults[0][0], 'Expected at least one error.');\n\n // If there is no validated value, we need to find the error with the least\n // number of failures (with the assumption that it's the most specific error).\n const validationError = validationResults.reduce((error, [innerError]) => {\n assert(innerError, 'Expected an error.');\n if (innerError.failures().length < error.failures().length) {\n return innerError;\n }\n\n return error;\n }, validationResults[0][0]);\n\n throw new Error(\n getStructFailureMessage(struct, validationError.failures()[0], false),\n );\n}\n\n/**\n * Create a value with the coercion logic of a union struct, and throw readable\n * errors if the value does not satisfy the struct. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @see validateUnion\n */\nexport function createUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n) {\n return validateUnion(value, struct, structKey, true);\n}\n\n// These types are copied from Superstruct, to mirror `assign`.\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n): Struct<ObjectType<Assign<ObjectA, ObjectB>>, Assign<ObjectA, ObjectB>>;\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n ObjectC extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n C: Struct<ObjectType<ObjectC>, ObjectC>,\n): Struct<\n ObjectType<Assign<Assign<ObjectA, ObjectB>, ObjectC>>,\n Assign<Assign<ObjectA, ObjectB>, ObjectC>\n>;\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n ObjectC extends ObjectSchema,\n ObjectD extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n C: Struct<ObjectType<ObjectC>, ObjectC>,\n D: Struct<ObjectType<ObjectD>, ObjectD>,\n): Struct<\n ObjectType<Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>>,\n Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>\n>;\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n ObjectC extends ObjectSchema,\n ObjectD extends ObjectSchema,\n ObjectE extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n C: Struct<ObjectType<ObjectC>, ObjectC>,\n D: Struct<ObjectType<ObjectD>, ObjectD>,\n E: Struct<ObjectType<ObjectE>, ObjectE>,\n): Struct<\n ObjectType<\n Assign<Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>, ObjectE>\n >,\n Assign<Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>, ObjectE>\n>;\n\n/**\n * Merge multiple structs into one, using superstruct `assign`.\n *\n * Differently from plain `assign`, this function also copies over refinements from each struct.\n *\n * @param structs - The `superstruct` structs to merge.\n * @returns The merged struct.\n */\nexport function mergeStructs(...structs: Struct<any>[]): Struct<any> {\n const mergedStruct = (assign as (...structs: Struct<any>[]) => Struct)(\n ...structs,\n );\n return new Struct({\n ...mergedStruct,\n *refiner(value, ctx) {\n for (const struct of structs) {\n yield* struct.refiner(value, ctx);\n }\n },\n });\n}\n"],"mappings":";;;;;AAAA,SAAS,aAAa;AAQtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,QAAQ,gBAAgB;AACjC,SAAS,MAAM,OAAO,WAAW;AA0CjC,SAAS,MACP,OACA,eACA,SACA;AACA,MAAI,SAAS;AACX,WAAO,cAAc,KAAK;AAAA,EAC5B;AAEA,SAAO;AACT;AAWO,SAAS,MACd,MACA,QACA;AACA,SAAO,IAAI,OAAO;AAAA,IAChB,GAAG;AAAA,IACH,MAAM;AAAA,EACR,CAAC;AACH;AAEO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A,SAAO,cAAc,SAAS,GAAG,uCAAuC;AAIxE,QAAM,oBAAoB,cAAc;AAAA,IAAI,CAAC,iBAC3C,SAAS,aAAa,cAAc,EAAE,OAAO,CAAC;AAAA,EAChD;AAEA,QAAM,iBAAiB,kBAAkB,KAAK,CAAC,CAAC,KAAK,MAAM,CAAC,KAAK;AACjE,MAAI,gBAAgB;AAClB,WAAO,eAAe,CAAC;AAAA,EACzB;AAEA,SAAO,kBAAkB,CAAC,EAAE,CAAC,GAAG,8BAA8B;AAI9D,QAAM,kBAAkB,kBAAkB,OAAO,CAAC,OAAO,CAAC,UAAU,MAAM;AACxE,WAAO,YAAY,oBAAoB;AACvC,QAAI,WAAW,SAAS,EAAE,SAAS,MAAM,SAAS,EAAE,QAAQ;AAC1D,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAC;AAE1B,QAAM,IAAI;AAAA,IACR,wBAAwB,QAAQ,gBAAgB,SAAS,EAAE,CAAC,GAAG,KAAK;AAAA,EACtE;AACF;AAkBO,SAAS,YACd,OACA,QACA,WACA;AACA,SAAO,cAAc,OAAO,QAAQ,WAAW,IAAI;AACrD;AA+DO,SAAS,gBAAgB,SAAqC;AACnE,QAAM,eAAgB;AAAA,IACpB,GAAG;AAAA,EACL;AACA,SAAO,IAAI,OAAO;AAAA,IAChB,GAAG;AAAA,IACH,CAAC,QAAQ,OAAO,KAAK;AACnB,iBAAW,UAAU,SAAS;AAC5B,eAAO,OAAO,QAAQ,OAAO,GAAG;AAAA,MAClC;AAAA,IACF;AAAA,EACF,CAAC;AACH;","names":[]}
@@ -1,9 +1,9 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunk5I5WPAVDjs = require('./chunk-5I5WPAVD.js');
3
+ var _chunk37EUH3KZjs = require('./chunk-37EUH3KZ.js');
4
4
 
5
5
 
6
- var _chunkRD6BN2TQjs = require('./chunk-RD6BN2TQ.js');
6
+ var _chunkTAMKWZ4Ejs = require('./chunk-TAMKWZ4E.js');
7
7
 
8
8
 
9
9
  var _chunkB5GNTDE2js = require('./chunk-B5GNTDE2.js');
@@ -13,8 +13,8 @@ var _chunkW7KRIAIXjs = require('./chunk-W7KRIAIX.js');
13
13
 
14
14
  // src/validation.ts
15
15
  async function validateFetchedSnap(files) {
16
- _chunk5I5WPAVDjs.assertIsSnapManifest.call(void 0, files.manifest.result);
17
- await _chunkRD6BN2TQjs.validateSnapShasum.call(void 0, files);
16
+ _chunk37EUH3KZjs.assertIsSnapManifest.call(void 0, files.manifest.result);
17
+ await _chunkTAMKWZ4Ejs.validateSnapShasum.call(void 0, files);
18
18
  _chunkB5GNTDE2js.validateSnapManifestLocalizations.call(void 0,
19
19
  files.manifest.result,
20
20
  files.localizationFiles.map((file) => file.result)
@@ -27,4 +27,4 @@ async function validateFetchedSnap(files) {
27
27
 
28
28
 
29
29
  exports.validateFetchedSnap = validateFetchedSnap;
30
- //# sourceMappingURL=chunk-SB43G2RI.js.map
30
+ //# sourceMappingURL=chunk-3OXW5H4F.js.map
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkPHUTP7NBjs = require('./chunk-PHUTP7NB.js');
5
+ var _chunkS3BWTUTZjs = require('./chunk-S3BWTUTZ.js');
6
6
 
7
7
  // src/errors.ts
8
8
 
@@ -29,12 +29,12 @@ var WrappedSnapError = class extends Error {
29
29
  constructor(error) {
30
30
  const message = _snapssdk.getErrorMessage.call(void 0, error);
31
31
  super(message);
32
- _chunkPHUTP7NBjs.__privateAdd.call(void 0, this, _error, void 0);
33
- _chunkPHUTP7NBjs.__privateAdd.call(void 0, this, _message, void 0);
34
- _chunkPHUTP7NBjs.__privateAdd.call(void 0, this, _stack, void 0);
35
- _chunkPHUTP7NBjs.__privateSet.call(void 0, this, _error, error);
36
- _chunkPHUTP7NBjs.__privateSet.call(void 0, this, _message, message);
37
- _chunkPHUTP7NBjs.__privateSet.call(void 0, this, _stack, _snapssdk.getErrorStack.call(void 0, error));
32
+ _chunkS3BWTUTZjs.__privateAdd.call(void 0, this, _error, void 0);
33
+ _chunkS3BWTUTZjs.__privateAdd.call(void 0, this, _message, void 0);
34
+ _chunkS3BWTUTZjs.__privateAdd.call(void 0, this, _stack, void 0);
35
+ _chunkS3BWTUTZjs.__privateSet.call(void 0, this, _error, error);
36
+ _chunkS3BWTUTZjs.__privateSet.call(void 0, this, _message, message);
37
+ _chunkS3BWTUTZjs.__privateSet.call(void 0, this, _stack, _snapssdk.getErrorStack.call(void 0, error));
38
38
  }
39
39
  /**
40
40
  * The error name.
@@ -50,7 +50,7 @@ var WrappedSnapError = class extends Error {
50
50
  * @returns The error message.
51
51
  */
52
52
  get message() {
53
- return _chunkPHUTP7NBjs.__privateGet.call(void 0, this, _message);
53
+ return _chunkS3BWTUTZjs.__privateGet.call(void 0, this, _message);
54
54
  }
55
55
  /**
56
56
  * The error stack.
@@ -58,7 +58,7 @@ var WrappedSnapError = class extends Error {
58
58
  * @returns The error stack.
59
59
  */
60
60
  get stack() {
61
- return _chunkPHUTP7NBjs.__privateGet.call(void 0, this, _stack);
61
+ return _chunkS3BWTUTZjs.__privateGet.call(void 0, this, _stack);
62
62
  }
63
63
  /**
64
64
  * Convert the error to a JSON object.
@@ -66,7 +66,7 @@ var WrappedSnapError = class extends Error {
66
66
  * @returns The JSON object.
67
67
  */
68
68
  toJSON() {
69
- const cause = isSnapError(_chunkPHUTP7NBjs.__privateGet.call(void 0, this, _error)) ? _chunkPHUTP7NBjs.__privateGet.call(void 0, this, _error).serialize() : _rpcerrors.serializeCause.call(void 0, _chunkPHUTP7NBjs.__privateGet.call(void 0, this, _error));
69
+ const cause = isSnapError(_chunkS3BWTUTZjs.__privateGet.call(void 0, this, _error)) ? _chunkS3BWTUTZjs.__privateGet.call(void 0, this, _error).serialize() : _rpcerrors.serializeCause.call(void 0, _chunkS3BWTUTZjs.__privateGet.call(void 0, this, _error));
70
70
  return {
71
71
  code: SNAP_ERROR_WRAPPER_CODE,
72
72
  message: SNAP_ERROR_WRAPPER_MESSAGE,
@@ -148,4 +148,4 @@ function unwrapError(error) {
148
148
 
149
149
 
150
150
  exports.SNAP_ERROR_WRAPPER_CODE = SNAP_ERROR_WRAPPER_CODE; exports.SNAP_ERROR_WRAPPER_MESSAGE = SNAP_ERROR_WRAPPER_MESSAGE; exports.WrappedSnapError = WrappedSnapError; exports.isSnapError = isSnapError; exports.isSerializedSnapError = isSerializedSnapError; exports.isWrappedSnapError = isWrappedSnapError; exports.unwrapError = unwrapError;
151
- //# sourceMappingURL=chunk-K6BCBPXF.js.map
151
+ //# sourceMappingURL=chunk-3RFGTBEP.js.map
@@ -1,3 +1,8 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
1
6
  var __accessCheck = (obj, member, msg) => {
2
7
  if (!member.has(obj))
3
8
  throw TypeError("Cannot " + msg);
@@ -18,8 +23,9 @@ var __privateSet = (obj, member, value, setter) => {
18
23
  };
19
24
 
20
25
  export {
26
+ __export,
21
27
  __privateGet,
22
28
  __privateAdd,
23
29
  __privateSet
24
30
  };
25
- //# sourceMappingURL=chunk-JMDSN227.mjs.map
31
+ //# sourceMappingURL=chunk-3RUWAMJT.mjs.map
@@ -0,0 +1,22 @@
1
+ // 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
+ export {
20
+ expectedFiles
21
+ };
22
+ //# sourceMappingURL=chunk-4BGZ2CHC.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/expected-files.ts"],"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"],"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;","names":[]}
@@ -0,0 +1,33 @@
1
+ import {
2
+ getStructFailureMessage
3
+ } from "./chunk-3N27GIUS.mjs";
4
+ import {
5
+ LocalizationFileStruct
6
+ } from "./chunk-CJK7DDV2.mjs";
7
+
8
+ // src/manifest/validators/is-localization-file.ts
9
+ import { validate } from "@metamask/superstruct";
10
+ var isLocalizationFile = {
11
+ severity: "error",
12
+ structureCheck(files, context) {
13
+ for (const file of files.localizationFiles) {
14
+ const [error] = validate(file.result, LocalizationFileStruct);
15
+ if (error) {
16
+ for (const failure of error.failures()) {
17
+ context.report(
18
+ `Failed to validate localization file "${file.path}": ${getStructFailureMessage(
19
+ LocalizationFileStruct,
20
+ failure,
21
+ false
22
+ )}`
23
+ );
24
+ }
25
+ }
26
+ }
27
+ }
28
+ };
29
+
30
+ export {
31
+ isLocalizationFile
32
+ };
33
+ //# sourceMappingURL=chunk-4RYTYEUQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/is-localization-file.ts"],"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"],"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;","names":[]}
@@ -134,6 +134,9 @@ function getStructFailureMessage(struct, failure, colorize = true) {
134
134
  ).replace(/length of `(\d+)`/u, `length of ${color("$1", _chalk.red, colorize)}`).replace(/a array/u, "an array");
135
135
  return `${prefix}${message}.`;
136
136
  }
137
+ if (failure.refinement !== void 0) {
138
+ return `${prefix}${failure.message}.`;
139
+ }
137
140
  return `${prefix}Expected a value of type ${color(
138
141
  failure.type,
139
142
  _chalk.green,
@@ -223,4 +226,4 @@ function mergeStructs(...structs) {
223
226
 
224
227
 
225
228
  exports.named = named; exports.SnapsStructError = SnapsStructError; exports.arrayToGenerator = arrayToGenerator; exports.getError = getError; exports.createFromStruct = createFromStruct; exports.getStructFromPath = getStructFromPath; exports.getUnionStructNames = getUnionStructNames; exports.getStructErrorPrefix = getStructErrorPrefix; exports.getStructFailureMessage = getStructFailureMessage; exports.getStructErrorMessage = getStructErrorMessage; exports.validateUnion = validateUnion; exports.createUnion = createUnion; exports.mergeStructs = mergeStructs;
226
- //# sourceMappingURL=chunk-VOPTAKVG.js.map
229
+ //# sourceMappingURL=chunk-53QXTM77.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/structs.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,aAAa;AAQtB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,QAAQ,gBAAgB;AACjC,SAAS,MAAM,OAAO,WAAW;AA0CjC,SAAS,MACP,OACA,eACA,SACA;AACA,MAAI,SAAS;AACX,WAAO,cAAc,KAAK;AAAA,EAC5B;AAEA,SAAO;AACT;AAWO,SAAS,MACd,MACA,QACA;AACA,SAAO,IAAI,OAAO;AAAA,IAChB,GAAG;AAAA,IACH,MAAM;AAAA,EACR,CAAC;AACH;AAEO,IAAM,mBAAN,cAA6C,YAAY;AAAA,EAC9D,YACE,QACA,QACA,QACA,SACA,UACA,WAAW,MACX;AACA,UAAM,SAAS,QAAQ;AAEvB,SAAK,OAAO;AACZ,SAAK,UAAU,GAAG,MAAM;AAAA;AAAA,EAAQ;AAAA,MAC9B;AAAA,MACA,CAAC,GAAG,SAAS,CAAC;AAAA,MACd;AAAA,IACF,CAAC,GA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;AAAA,EACzB;AAEA,SAAO,kBAAkB,CAAC,EAAE,CAAC,GAAG,8BAA8B;AAI9D,QAAM,kBAAkB,kBAAkB,OAAO,CAAC,OAAO,CAAC,UAAU,MAAM;AACxE,WAAO,YAAY,oBAAoB;AACvC,QAAI,WAAW,SAAS,EAAE,SAAS,MAAM,SAAS,EAAE,QAAQ;AAC1D,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAC;AAE1B,QAAM,IAAI;AAAA,IACR,wBAAwB,QAAQ,gBAAgB,SAAS,EAAE,CAAC,GAAG,KAAK;AAAA,EACtE;AACF;AAkBO,SAAS,YACd,OACA,QACA,WACA;AACA,SAAO,cAAc,OAAO,QAAQ,WAAW,IAAI;AACrD;AA+DO,SAAS,gBAAgB,SAAqC;AACnE,QAAM,eAAgB;AAAA,IACpB,GAAG;AAAA,EACL;AACA,SAAO,IAAI,OAAO;AAAA,IAChB,GAAG;AAAA,IACH,CAAC,QAAQ,OAAO,KAAK;AACnB,iBAAW,UAAU,SAAS;AAC5B,eAAO,OAAO,QAAQ,OAAO,GAAG;AAAA,MAClC;AAAA,IACF;AAAA,EACF,CAAC;AACH","sourcesContent":["import { union } from '@metamask/snaps-sdk';\nimport type {\n AnyStruct,\n Assign,\n Failure,\n ObjectSchema,\n ObjectType,\n} from '@metamask/superstruct';\nimport {\n assign,\n is,\n validate,\n type as superstructType,\n Struct,\n StructError,\n create,\n} from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert, isObject } from '@metamask/utils';\nimport { bold, green, red } from 'chalk';\n\nimport { indent } from './strings';\n\n/**\n * Infer a struct type, only if it matches the specified type. This is useful\n * for defining types and structs that are related to each other in separate\n * files.\n *\n * @example\n * ```typescript\n * // In file A\n * export type GetFileArgs = {\n * path: string;\n * encoding?: EnumToUnion<AuxiliaryFileEncoding>;\n * };\n *\n * // In file B\n * export const GetFileArgsStruct = object(...);\n *\n * // If the type and struct are in the same file, this will return the type.\n * // Otherwise, it will return `never`.\n * export type GetFileArgs =\n * InferMatching<typeof GetFileArgsStruct, GetFileArgs>;\n * ```\n */\nexport type InferMatching<\n StructType extends Struct<any, any>,\n Type,\n> = StructType['TYPE'] extends Type ? Type : never;\n\n/**\n * Colorize a value with a color function. This is useful for colorizing values\n * in error messages. If colorization is disabled, the original value is\n * returned.\n *\n * @param value - The value to colorize.\n * @param colorFunction - The color function to use.\n * @param enabled - Whether to colorize the value.\n * @returns The colorized value, or the original value if colorization is\n * disabled.\n */\nfunction color(\n value: string,\n colorFunction: (value: string) => string,\n enabled: boolean,\n) {\n if (enabled) {\n return colorFunction(value);\n }\n\n return value;\n}\n\n/**\n * Define a struct, and also define the name of the struct as the given name.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n *\n * @param name - The name of the struct.\n * @param struct - The struct.\n * @returns The struct.\n */\nexport function named<Type, Schema>(\n name: string,\n struct: Struct<Type, Schema>,\n) {\n return new Struct({\n ...struct,\n type: name,\n });\n}\n\nexport class SnapsStructError<Type, Schema> extends StructError {\n constructor(\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix: string,\n failure: StructError,\n failures: () => Generator<Failure>,\n colorize = true,\n ) {\n super(failure, failures);\n\n this.name = 'SnapsStructError';\n this.message = `${prefix}.\\n\\n${getStructErrorMessage(\n struct,\n [...failures()],\n colorize,\n )}${suffix ? `\\n\\n${suffix}` : ''}`;\n }\n}\n\ntype GetErrorOptions<Type, Schema> = {\n struct: Struct<Type, Schema>;\n prefix: string;\n suffix?: string;\n error: StructError;\n colorize?: boolean;\n};\n\n/**\n * Converts an array to a generator function that yields the items in the\n * array.\n *\n * @param array - The array.\n * @returns A generator function.\n * @yields The items in the array.\n */\nexport function* arrayToGenerator<Type>(\n array: Type[],\n): Generator<Type, void, undefined> {\n for (const item of array) {\n yield item;\n }\n}\n\n/**\n * Returns a `SnapsStructError` with the given prefix and suffix.\n *\n * @param options - The options.\n * @param options.struct - The struct that caused the error.\n * @param options.prefix - The prefix to add to the error message.\n * @param options.suffix - The suffix to add to the error message. Defaults to\n * an empty string.\n * @param options.error - The `superstruct` error to wrap.\n * @param options.colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The `SnapsStructError`.\n */\nexport function getError<Type, Schema>({\n struct,\n prefix,\n suffix = '',\n error,\n colorize,\n}: GetErrorOptions<Type, Schema>) {\n return new SnapsStructError(\n struct,\n prefix,\n suffix,\n error,\n () => arrayToGenerator(error.failures()),\n colorize,\n );\n}\n\n/**\n * A wrapper of `superstruct`'s `create` function that throws a\n * `SnapsStructError` instead of a `StructError`. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` struct to validate the value against.\n * @param prefix - The prefix to add to the error message.\n * @param suffix - The suffix to add to the error message. Defaults to an empty\n * string.\n * @returns The validated value.\n */\nexport function createFromStruct<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix = '',\n) {\n try {\n return create(value, struct);\n } catch (error) {\n if (error instanceof StructError) {\n throw getError({ struct, prefix, suffix, error });\n }\n\n throw error;\n }\n}\n\n/**\n * Get a struct from a failure path.\n *\n * @param struct - The struct.\n * @param path - The failure path.\n * @returns The struct at the failure path.\n */\nexport function getStructFromPath<Type, Schema>(\n struct: Struct<Type, Schema>,\n path: string[],\n) {\n return path.reduce<AnyStruct>((result, key) => {\n if (isObject(struct.schema) && struct.schema[key]) {\n return struct.schema[key] as AnyStruct;\n }\n\n return result;\n }, struct);\n}\n\n/**\n * Get the union struct names from a struct.\n *\n * @param struct - The struct.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The union struct names, or `null` if the struct is not a union\n * struct.\n */\nexport function getUnionStructNames<Type, Schema>(\n struct: Struct<Type, Schema>,\n colorize = true,\n) {\n if (Array.isArray(struct.schema)) {\n return struct.schema.map(({ type }) => color(type, green, colorize));\n }\n\n return null;\n}\n\n/**\n * Get an error prefix from a `superstruct` failure. This is useful for\n * formatting the error message returned by `superstruct`.\n *\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The error prefix.\n */\nexport function getStructErrorPrefix(failure: Failure, colorize = true) {\n if (failure.type === 'never' || failure.path.length === 0) {\n return '';\n }\n\n return `At path: ${color(failure.path.join('.'), bold, colorize)} — `;\n}\n\n/**\n * Get a string describing the failure. This is similar to the `message`\n * property of `superstruct`'s `Failure` type, but formats the value in a more\n * readable way.\n *\n * @param struct - The struct that caused the failure.\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the failure.\n */\nexport function getStructFailureMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failure: Failure,\n colorize = true,\n) {\n const received = color(JSON.stringify(failure.value), red, colorize);\n const prefix = getStructErrorPrefix(failure, colorize);\n\n if (failure.type === 'union') {\n const childStruct = getStructFromPath(struct, failure.path);\n const unionNames = getUnionStructNames(childStruct, colorize);\n\n if (unionNames) {\n return `${prefix}Expected the value to be one of: ${unionNames.join(\n ', ',\n )}, but received: ${received}.`;\n }\n\n return `${prefix}${failure.message}.`;\n }\n\n if (failure.type === 'literal') {\n // Superstruct's failure does not provide information about which literal\n // value was expected, so we need to parse the message to get the literal.\n const message = failure.message\n .replace(\n /the literal `(.+)`,/u,\n `the value to be \\`${color('$1', green, colorize)}\\`,`,\n )\n .replace(\n /, but received: (.+)/u,\n `, but received: ${color('$1', red, colorize)}`,\n );\n\n return `${prefix}${message}.`;\n }\n\n if (failure.type === 'never') {\n return `Unknown key: ${color(\n failure.path.join('.'),\n bold,\n colorize,\n )}, received: ${received}.`;\n }\n\n if (failure.refinement === 'size') {\n const message = failure.message\n .replace(\n /length between `(\\d+)` and `(\\d+)`/u,\n `length between ${color('$1', green, colorize)} and ${color(\n '$2',\n green,\n colorize,\n )},`,\n )\n .replace(/length of `(\\d+)`/u, `length of ${color('$1', red, colorize)}`)\n .replace(/a array/u, 'an array');\n\n return `${prefix}${message}.`;\n }\n\n // Refinements we built ourselves have nice error messages\n if (failure.refinement !== undefined) {\n return `${prefix}${failure.message}.`;\n }\n\n return `${prefix}Expected a value of type ${color(\n failure.type,\n green,\n colorize,\n )}, but received: ${received}.`;\n}\n\n/**\n * Get a string describing the errors. This formats all the errors in a\n * human-readable way.\n *\n * @param struct - The struct that caused the failures.\n * @param failures - The `superstruct` failures.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the errors.\n */\nexport function getStructErrorMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failures: Failure[],\n colorize = true,\n) {\n const formattedFailures = failures.map((failure) =>\n indent(`• ${getStructFailureMessage(struct, failure, colorize)}`),\n );\n\n return formattedFailures.join('\\n');\n}\n\n/**\n * Validate a union struct, and throw readable errors if the value does not\n * satisfy the struct. This is useful for improving the error messages returned\n * by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @param coerce - Whether to coerce the value to satisfy the struct. Defaults\n * to `false`.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @example\n * const struct = union([\n * object({ type: literal('a'), value: string() }),\n * object({ type: literal('b'), value: number() }),\n * object({ type: literal('c'), value: boolean() }),\n * // ...\n * ]);\n *\n * // At path: type — Expected the value to be one of: \"a\", \"b\", \"c\", but received: \"d\".\n * validateUnion({ type: 'd', value: 'foo' }, struct, 'type');\n *\n * // At path: value — Expected a value of type string, but received: 42.\n * validateUnion({ type: 'a', value: 42 }, struct, 'value');\n */\nexport function validateUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n coerce = false,\n) {\n assert(\n struct.schema,\n 'Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`.',\n );\n assert(struct.schema.length > 0, 'Expected a non-empty array of structs.');\n\n const keyUnion = struct.schema.map(\n (innerStruct) => innerStruct.schema[structKey],\n // This is guaranteed to be a non-empty array by the assertion above. We\n // need to cast it since `superstruct` requires a non-empty array of structs\n // for the `union` struct.\n ) as NonEmptyArray<Struct>;\n\n const key = superstructType({\n [structKey]: union(keyUnion),\n });\n\n const [keyError] = validate(value, key, { coerce });\n if (keyError) {\n throw new Error(\n getStructFailureMessage(key, keyError.failures()[0], false),\n );\n }\n\n // At this point it's guaranteed that the value is an object, so we can safely\n // cast it to a Record.\n const objectValue = value as Record<PropertyKey, unknown>;\n const objectStructs = struct.schema.filter((innerStruct) =>\n is(objectValue[structKey], innerStruct.schema[structKey]),\n );\n\n assert(objectStructs.length > 0, 'Expected a struct to match the value.');\n\n // We need to validate the value against all the object structs that match the\n // struct key, and return the first validated value.\n const validationResults = objectStructs.map((objectStruct) =>\n validate(objectValue, objectStruct, { coerce }),\n );\n\n const validatedValue = validationResults.find(([error]) => !error);\n if (validatedValue) {\n return validatedValue[1];\n }\n\n assert(validationResults[0][0], 'Expected at least one error.');\n\n // If there is no validated value, we need to find the error with the least\n // number of failures (with the assumption that it's the most specific error).\n const validationError = validationResults.reduce((error, [innerError]) => {\n assert(innerError, 'Expected an error.');\n if (innerError.failures().length < error.failures().length) {\n return innerError;\n }\n\n return error;\n }, validationResults[0][0]);\n\n throw new Error(\n getStructFailureMessage(struct, validationError.failures()[0], false),\n );\n}\n\n/**\n * Create a value with the coercion logic of a union struct, and throw readable\n * errors if the value does not satisfy the struct. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @see validateUnion\n */\nexport function createUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n) {\n return validateUnion(value, struct, structKey, true);\n}\n\n// These types are copied from Superstruct, to mirror `assign`.\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n): Struct<ObjectType<Assign<ObjectA, ObjectB>>, Assign<ObjectA, ObjectB>>;\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n ObjectC extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n C: Struct<ObjectType<ObjectC>, ObjectC>,\n): Struct<\n ObjectType<Assign<Assign<ObjectA, ObjectB>, ObjectC>>,\n Assign<Assign<ObjectA, ObjectB>, ObjectC>\n>;\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n ObjectC extends ObjectSchema,\n ObjectD extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n C: Struct<ObjectType<ObjectC>, ObjectC>,\n D: Struct<ObjectType<ObjectD>, ObjectD>,\n): Struct<\n ObjectType<Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>>,\n Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>\n>;\nexport function mergeStructs<\n ObjectA extends ObjectSchema,\n ObjectB extends ObjectSchema,\n ObjectC extends ObjectSchema,\n ObjectD extends ObjectSchema,\n ObjectE extends ObjectSchema,\n>(\n A: Struct<ObjectType<ObjectA>, ObjectA>,\n B: Struct<ObjectType<ObjectB>, ObjectB>,\n C: Struct<ObjectType<ObjectC>, ObjectC>,\n D: Struct<ObjectType<ObjectD>, ObjectD>,\n E: Struct<ObjectType<ObjectE>, ObjectE>,\n): Struct<\n ObjectType<\n Assign<Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>, ObjectE>\n >,\n Assign<Assign<Assign<Assign<ObjectA, ObjectB>, ObjectC>, ObjectD>, ObjectE>\n>;\n\n/**\n * Merge multiple structs into one, using superstruct `assign`.\n *\n * Differently from plain `assign`, this function also copies over refinements from each struct.\n *\n * @param structs - The `superstruct` structs to merge.\n * @returns The merged struct.\n */\nexport function mergeStructs(...structs: Struct<any>[]): Struct<any> {\n const mergedStruct = (assign as (...structs: Struct<any>[]) => Struct)(\n ...structs,\n );\n return new Struct({\n ...mergedStruct,\n *refiner(value, ctx) {\n for (const struct of structs) {\n yield* struct.refiner(value, ctx);\n }\n },\n });\n}\n"]}
@@ -0,0 +1,27 @@
1
+ import {
2
+ deepClone
3
+ } from "./chunk-Z2JQNSVL.mjs";
4
+
5
+ // src/manifest/validators/repository-match.ts
6
+ import deepEqual from "fast-deep-equal";
7
+ var repositoryMatch = {
8
+ severity: "error",
9
+ semanticCheck(files, context) {
10
+ const packageJsonRepository = files.packageJson.result.repository;
11
+ const manifestRepository = files.manifest.result.repository;
12
+ if ((packageJsonRepository || manifestRepository) && !deepEqual(packageJsonRepository, manifestRepository)) {
13
+ context.report(
14
+ `"${"snap.manifest.json" /* Manifest */}" "repository" field does not match the "${"package.json" /* PackageJson */}" "repository" field.`,
15
+ ({ manifest }) => {
16
+ manifest.repository = packageJsonRepository ? deepClone(packageJsonRepository) : void 0;
17
+ return { manifest };
18
+ }
19
+ );
20
+ }
21
+ }
22
+ };
23
+
24
+ export {
25
+ repositoryMatch
26
+ };
27
+ //# sourceMappingURL=chunk-5FTBWYCW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/manifest/validators/repository-match.ts"],"sourcesContent":["import deepEqual from 'fast-deep-equal';\n\nimport { deepClone } from '../../deep-clone';\nimport { NpmSnapFileNames } from '../../types';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the repository object in manifest is the same as in package.json.\n */\nexport const repositoryMatch: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const packageJsonRepository = files.packageJson.result.repository;\n const manifestRepository = files.manifest.result.repository;\n if (\n (packageJsonRepository || manifestRepository) &&\n !deepEqual(packageJsonRepository, manifestRepository)\n ) {\n context.report(\n `\"${NpmSnapFileNames.Manifest}\" \"repository\" field does not match the \"${NpmSnapFileNames.PackageJson}\" \"repository\" field.`,\n ({ manifest }) => {\n manifest.repository = packageJsonRepository\n ? deepClone(packageJsonRepository)\n : undefined;\n return { manifest };\n },\n );\n }\n },\n};\n"],"mappings":";;;;;AAAA,OAAO,eAAe;AASf,IAAM,kBAAiC;AAAA,EAC5C,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,UAAM,wBAAwB,MAAM,YAAY,OAAO;AACvD,UAAM,qBAAqB,MAAM,SAAS,OAAO;AACjD,SACG,yBAAyB,uBAC1B,CAAC,UAAU,uBAAuB,kBAAkB,GACpD;AACA,cAAQ;AAAA,QACN,uCAA6B,4EAAwE;AAAA,QACrG,CAAC,EAAE,SAAS,MAAM;AAChB,mBAAS,aAAa,wBAClB,UAAU,qBAAqB,IAC/B;AACJ,iBAAO,EAAE,SAAS;AAAA,QACpB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}