@metamask/snaps-utils 6.0.0 → 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -1
- package/dist/array.js +8 -0
- package/dist/array.js.map +1 -0
- package/dist/array.mjs +8 -0
- package/dist/array.mjs.map +1 -0
- package/dist/auxiliary-files.js +12 -0
- package/dist/auxiliary-files.js.map +1 -0
- package/dist/auxiliary-files.mjs +12 -0
- package/dist/auxiliary-files.mjs.map +1 -0
- package/dist/base64.js +13 -0
- package/dist/base64.js.map +1 -0
- package/dist/base64.mjs +13 -0
- package/dist/base64.mjs.map +1 -0
- package/dist/bytes.js +10 -0
- package/dist/bytes.js.map +1 -0
- package/dist/bytes.mjs +10 -0
- package/dist/bytes.mjs.map +1 -0
- package/dist/caveats.js +8 -0
- package/dist/caveats.js.map +1 -0
- package/dist/caveats.mjs +8 -0
- package/dist/caveats.mjs.map +1 -0
- package/dist/checksum.js +13 -0
- package/dist/checksum.js.map +1 -0
- package/dist/checksum.mjs +13 -0
- package/dist/checksum.mjs.map +1 -0
- package/dist/chunk-224S5XKL.js +32 -0
- package/dist/chunk-224S5XKL.js.map +1 -0
- package/dist/chunk-2G4HD42C.mjs +22 -0
- package/dist/chunk-2G4HD42C.mjs.map +1 -0
- package/dist/chunk-2IVFF3AA.mjs +211 -0
- package/dist/chunk-2IVFF3AA.mjs.map +1 -0
- package/dist/chunk-2QS3W66J.js +64 -0
- package/dist/chunk-2QS3W66J.js.map +1 -0
- package/dist/chunk-2XF32FCF.js +1 -0
- package/dist/chunk-2XF32FCF.js.map +1 -0
- package/dist/chunk-32B4YQM7.mjs +103 -0
- package/dist/chunk-32B4YQM7.mjs.map +1 -0
- package/dist/chunk-3SARO5TJ.mjs +18 -0
- package/dist/chunk-3SARO5TJ.mjs.map +1 -0
- package/dist/chunk-3TH3NLQL.js +169 -0
- package/dist/chunk-3TH3NLQL.js.map +1 -0
- package/dist/chunk-3ZSMMNQB.mjs +41 -0
- package/dist/chunk-3ZSMMNQB.mjs.map +1 -0
- package/dist/chunk-43EBXDVP.mjs +30 -0
- package/dist/chunk-43EBXDVP.mjs.map +1 -0
- package/dist/chunk-4GBOSMF7.mjs +33 -0
- package/dist/chunk-4GBOSMF7.mjs.map +1 -0
- package/dist/chunk-4IKNNAVC.mjs +30 -0
- package/dist/chunk-4IKNNAVC.mjs.map +1 -0
- package/dist/chunk-4UMDRHDR.js +95 -0
- package/dist/chunk-4UMDRHDR.js.map +1 -0
- package/dist/chunk-6CTV7VW5.mjs +20 -0
- package/dist/chunk-6CTV7VW5.mjs.map +1 -0
- package/dist/chunk-6H32HLTZ.js +10 -0
- package/dist/chunk-6H32HLTZ.js.map +1 -0
- package/dist/chunk-6WBLB5BX.js +9 -0
- package/dist/chunk-6WBLB5BX.js.map +1 -0
- package/dist/chunk-7H5TGXZ5.js +70 -0
- package/dist/chunk-7H5TGXZ5.js.map +1 -0
- package/dist/chunk-7KKLGQNE.js +38 -0
- package/dist/chunk-7KKLGQNE.js.map +1 -0
- package/dist/chunk-7PNGOFLU.js +22 -0
- package/dist/chunk-7PNGOFLU.js.map +1 -0
- package/dist/chunk-7T3N2ZGQ.mjs +107 -0
- package/dist/chunk-7T3N2ZGQ.mjs.map +1 -0
- package/dist/chunk-7XA5VYYV.mjs +9 -0
- package/dist/chunk-7XA5VYYV.mjs.map +1 -0
- package/dist/chunk-B2DMAQNK.mjs +8 -0
- package/dist/chunk-B2DMAQNK.mjs.map +1 -0
- package/dist/chunk-B3YQVRPE.js +107 -0
- package/dist/chunk-B3YQVRPE.js.map +1 -0
- package/dist/chunk-DK3IYVMP.mjs +1 -0
- package/dist/chunk-DK3IYVMP.mjs.map +1 -0
- package/dist/chunk-DKSB4FMW.mjs +74 -0
- package/dist/chunk-DKSB4FMW.mjs.map +1 -0
- package/dist/chunk-F33RMB76.js +69 -0
- package/dist/chunk-F33RMB76.js.map +1 -0
- package/dist/chunk-FJH6DDEL.mjs +193 -0
- package/dist/chunk-FJH6DDEL.mjs.map +1 -0
- package/dist/chunk-FTY3BOF7.js +9 -0
- package/dist/chunk-FTY3BOF7.js.map +1 -0
- package/dist/chunk-GK4IJQVW.js +409 -0
- package/dist/chunk-GK4IJQVW.js.map +1 -0
- package/dist/chunk-GMC2A3D7.js +211 -0
- package/dist/chunk-GMC2A3D7.js.map +1 -0
- package/dist/chunk-GW5NQXN4.mjs +151 -0
- package/dist/chunk-GW5NQXN4.mjs.map +1 -0
- package/dist/chunk-H34N3OWO.mjs +169 -0
- package/dist/chunk-H34N3OWO.mjs.map +1 -0
- package/dist/chunk-H636DAOG.js +193 -0
- package/dist/chunk-H636DAOG.js.map +1 -0
- package/dist/chunk-HOTDTMNP.mjs +21 -0
- package/dist/chunk-HOTDTMNP.mjs.map +1 -0
- package/dist/chunk-HWFLO7W5.mjs +281 -0
- package/dist/chunk-HWFLO7W5.mjs.map +1 -0
- package/dist/chunk-I3BUOULW.js +18 -0
- package/dist/chunk-I3BUOULW.js.map +1 -0
- package/dist/chunk-IIDK6BRC.mjs +1 -0
- package/dist/chunk-IIDK6BRC.mjs.map +1 -0
- package/dist/chunk-IUNNN6HN.mjs +29 -0
- package/dist/chunk-IUNNN6HN.mjs.map +1 -0
- package/dist/chunk-IWENO6LT.js +20 -0
- package/dist/chunk-IWENO6LT.js.map +1 -0
- package/dist/chunk-JGMGNLZW.mjs +38 -0
- package/dist/chunk-JGMGNLZW.mjs.map +1 -0
- package/dist/chunk-JV7OA3FD.js +1 -0
- package/dist/chunk-JV7OA3FD.js.map +1 -0
- package/dist/chunk-KEXZDQAN.js +50 -0
- package/dist/chunk-KEXZDQAN.js.map +1 -0
- package/dist/chunk-KWQKGJSV.js +152 -0
- package/dist/chunk-KWQKGJSV.js.map +1 -0
- package/dist/chunk-LEFOMYX3.mjs +1 -0
- package/dist/chunk-LEFOMYX3.mjs.map +1 -0
- package/dist/chunk-LHIPBIPS.mjs +32 -0
- package/dist/chunk-LHIPBIPS.mjs.map +1 -0
- package/dist/chunk-LOW2T4MV.mjs +50 -0
- package/dist/chunk-LOW2T4MV.mjs.map +1 -0
- package/dist/chunk-MJABESWH.js +20 -0
- package/dist/chunk-MJABESWH.js.map +1 -0
- package/dist/chunk-MSUZTHYT.js +9 -0
- package/dist/chunk-MSUZTHYT.js.map +1 -0
- package/dist/chunk-MYSBDK36.mjs +1 -0
- package/dist/chunk-MYSBDK36.mjs.map +1 -0
- package/dist/chunk-N52KMB25.mjs +109 -0
- package/dist/chunk-N52KMB25.mjs.map +1 -0
- package/dist/chunk-O3XKEEJV.mjs +249 -0
- package/dist/chunk-O3XKEEJV.mjs.map +1 -0
- package/dist/chunk-O4PW77JW.mjs +1 -0
- package/dist/chunk-O4PW77JW.mjs.map +1 -0
- package/dist/chunk-OQSLMZJN.js +281 -0
- package/dist/chunk-OQSLMZJN.js.map +1 -0
- package/dist/chunk-P5V6S2PA.mjs +69 -0
- package/dist/chunk-P5V6S2PA.mjs.map +1 -0
- package/dist/chunk-PHUTP7NB.js +25 -0
- package/dist/chunk-PHUTP7NB.js.map +1 -0
- package/dist/chunk-Q5T57UNN.js +1 -0
- package/dist/chunk-Q5T57UNN.js.map +1 -0
- package/dist/chunk-Q7FGULTV.js +8 -0
- package/dist/chunk-Q7FGULTV.js.map +1 -0
- package/dist/chunk-QF3LHIJ5.mjs +9 -0
- package/dist/chunk-QF3LHIJ5.mjs.map +1 -0
- package/dist/chunk-QJTAFTW7.js +30 -0
- package/dist/chunk-QJTAFTW7.js.map +1 -0
- package/dist/chunk-QWEXXUTO.mjs +10 -0
- package/dist/chunk-QWEXXUTO.mjs.map +1 -0
- package/dist/chunk-QYFDFOWT.js +41 -0
- package/dist/chunk-QYFDFOWT.js.map +1 -0
- package/dist/chunk-R4BBIGBN.js +18 -0
- package/dist/chunk-R4BBIGBN.js.map +1 -0
- package/dist/chunk-R7UAMO2U.js +21 -0
- package/dist/chunk-R7UAMO2U.js.map +1 -0
- package/dist/chunk-RRPU7M4Y.js +29 -0
- package/dist/chunk-RRPU7M4Y.js.map +1 -0
- package/dist/chunk-RS5HE55U.js +109 -0
- package/dist/chunk-RS5HE55U.js.map +1 -0
- package/dist/chunk-TUAHXE75.mjs +21 -0
- package/dist/chunk-TUAHXE75.mjs.map +1 -0
- package/dist/chunk-TURGGK5F.mjs +59 -0
- package/dist/chunk-TURGGK5F.mjs.map +1 -0
- package/dist/chunk-UGQQ5DJ4.mjs +50 -0
- package/dist/chunk-UGQQ5DJ4.mjs.map +1 -0
- package/dist/chunk-VGWELVCX.mjs +18 -0
- package/dist/chunk-VGWELVCX.mjs.map +1 -0
- package/dist/chunk-VMUXXXJC.js +103 -0
- package/dist/chunk-VMUXXXJC.js.map +1 -0
- package/dist/chunk-WDGBH5CP.js +249 -0
- package/dist/chunk-WDGBH5CP.js.map +1 -0
- package/dist/chunk-WJOAEPZ7.js +30 -0
- package/dist/chunk-WJOAEPZ7.js.map +1 -0
- package/dist/chunk-XC5E26VE.mjs +20 -0
- package/dist/chunk-XC5E26VE.mjs.map +1 -0
- package/dist/chunk-XDEHYKW2.js +1 -0
- package/dist/chunk-XDEHYKW2.js.map +1 -0
- package/dist/chunk-XEY3KVEH.js +21 -0
- package/dist/chunk-XEY3KVEH.js.map +1 -0
- package/dist/chunk-XKXHM3PC.mjs +9 -0
- package/dist/chunk-XKXHM3PC.mjs.map +1 -0
- package/dist/chunk-XRGYWWT7.js +151 -0
- package/dist/chunk-XRGYWWT7.js.map +1 -0
- package/dist/chunk-XWFKTDB3.js +50 -0
- package/dist/chunk-XWFKTDB3.js.map +1 -0
- package/dist/chunk-Y3F7VUZB.mjs +409 -0
- package/dist/chunk-Y3F7VUZB.mjs.map +1 -0
- package/dist/chunk-YF4PGFCO.js +1 -0
- package/dist/chunk-YF4PGFCO.js.map +1 -0
- package/dist/chunk-YLT6CNSL.mjs +64 -0
- package/dist/chunk-YLT6CNSL.mjs.map +1 -0
- package/dist/chunk-Z4J4GUGG.mjs +152 -0
- package/dist/chunk-Z4J4GUGG.mjs.map +1 -0
- package/dist/chunk-ZLFA4R5X.js +56 -0
- package/dist/chunk-ZLFA4R5X.js.map +1 -0
- package/dist/chunk-ZRVOIW3H.js +74 -0
- package/dist/chunk-ZRVOIW3H.js.map +1 -0
- package/dist/chunk-ZVXX2CTH.mjs +95 -0
- package/dist/chunk-ZVXX2CTH.mjs.map +1 -0
- package/dist/chunk-ZXCNX3ZB.mjs +70 -0
- package/dist/chunk-ZXCNX3ZB.mjs.map +1 -0
- package/dist/cronjob.js +20 -0
- package/dist/cronjob.js.map +1 -0
- package/dist/cronjob.mjs +20 -0
- package/dist/cronjob.mjs.map +1 -0
- package/dist/deep-clone.js +8 -0
- package/dist/deep-clone.js.map +1 -0
- package/dist/deep-clone.mjs +8 -0
- package/dist/deep-clone.mjs.map +1 -0
- package/dist/default-endowments.js +8 -0
- package/dist/default-endowments.js.map +1 -0
- package/dist/default-endowments.mjs +8 -0
- package/dist/default-endowments.mjs.map +1 -0
- package/dist/derivation-paths.js +13 -0
- package/dist/derivation-paths.js.map +1 -0
- package/dist/derivation-paths.mjs +13 -0
- package/dist/derivation-paths.mjs.map +1 -0
- package/dist/entropy.js +10 -0
- package/dist/entropy.js.map +1 -0
- package/dist/entropy.mjs +10 -0
- package/dist/entropy.mjs.map +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +20 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/eval-worker.js +43 -0
- package/dist/eval-worker.js.map +1 -0
- package/dist/eval-worker.mjs +43 -0
- package/dist/eval-worker.mjs.map +1 -0
- package/dist/eval.js +17 -0
- package/dist/eval.js.map +1 -0
- package/dist/eval.mjs +17 -0
- package/dist/eval.mjs.map +1 -0
- package/dist/fs.js +28 -0
- package/dist/fs.js.map +1 -0
- package/dist/fs.mjs +28 -0
- package/dist/fs.mjs.map +1 -0
- package/dist/handler-types.js +10 -0
- package/dist/handler-types.js.map +1 -0
- package/dist/handler-types.mjs +10 -0
- package/dist/handler-types.mjs.map +1 -0
- package/dist/handlers.js +35 -0
- package/dist/handlers.js.map +1 -0
- package/dist/handlers.mjs +35 -0
- package/dist/handlers.mjs.map +1 -0
- package/dist/icon.js +14 -0
- package/dist/icon.js.map +1 -0
- package/dist/icon.mjs +14 -0
- package/dist/icon.mjs.map +1 -0
- package/dist/iframe.js +8 -0
- package/dist/iframe.js.map +1 -0
- package/dist/iframe.mjs +8 -0
- package/dist/iframe.mjs.map +1 -0
- package/dist/index.executionenv.js +134 -0
- package/dist/index.executionenv.js.map +1 -0
- package/dist/index.executionenv.mjs +134 -0
- package/dist/index.executionenv.mjs.map +1 -0
- package/dist/index.js +378 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +378 -0
- package/dist/index.mjs.map +1 -0
- package/dist/json-rpc.js +18 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/json-rpc.mjs +18 -0
- package/dist/json-rpc.mjs.map +1 -0
- package/dist/json.js +8 -0
- package/dist/json.js.map +1 -0
- package/dist/json.mjs +8 -0
- package/dist/json.mjs.map +1 -0
- package/dist/localization.js +23 -0
- package/dist/localization.js.map +1 -0
- package/dist/localization.mjs +23 -0
- package/dist/localization.mjs.map +1 -0
- package/dist/logging.js +14 -0
- package/dist/logging.js.map +1 -0
- package/dist/logging.mjs +14 -0
- package/dist/logging.mjs.map +1 -0
- package/dist/manifest/index.js +59 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/index.mjs +59 -0
- package/dist/manifest/index.mjs.map +1 -0
- package/dist/manifest/manifest.js +42 -0
- package/dist/manifest/manifest.js.map +1 -0
- package/dist/manifest/manifest.mjs +42 -0
- package/dist/manifest/manifest.mjs.map +1 -0
- package/dist/manifest/node.js +85 -0
- package/dist/manifest/node.js.map +1 -0
- package/dist/manifest/node.mjs +85 -0
- package/dist/manifest/node.mjs.map +1 -0
- package/dist/manifest/validation.js +58 -0
- package/dist/manifest/validation.js.map +1 -0
- package/dist/manifest/validation.mjs +58 -0
- package/dist/manifest/validation.mjs.map +1 -0
- package/dist/mock.js +13 -0
- package/dist/mock.js.map +1 -0
- package/dist/mock.mjs +13 -0
- package/dist/mock.mjs.map +1 -0
- package/dist/namespace.js +44 -0
- package/dist/namespace.js.map +1 -0
- package/dist/namespace.mjs +44 -0
- package/dist/namespace.mjs.map +1 -0
- package/dist/node.js +448 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +448 -0
- package/dist/node.mjs.map +1 -0
- package/dist/npm.js +32 -0
- package/dist/npm.js.map +1 -0
- package/dist/npm.mjs +32 -0
- package/dist/npm.mjs.map +1 -0
- package/dist/path.js +8 -0
- package/dist/path.js.map +1 -0
- package/dist/path.mjs +8 -0
- package/dist/path.mjs.map +1 -0
- package/dist/post-process.js +10 -0
- package/dist/post-process.js.map +1 -0
- package/dist/post-process.mjs +10 -0
- package/dist/post-process.mjs.map +1 -0
- package/dist/snaps.js +48 -0
- package/dist/snaps.js.map +1 -0
- package/dist/snaps.mjs +48 -0
- package/dist/snaps.mjs.map +1 -0
- package/dist/strings.js +8 -0
- package/dist/strings.js.map +1 -0
- package/dist/strings.mjs +8 -0
- package/dist/strings.mjs.map +1 -0
- package/dist/structs.js +31 -0
- package/dist/structs.js.map +1 -0
- package/dist/structs.mjs +31 -0
- package/dist/structs.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/bytes.d.ts +1 -1
- package/dist/types/checksum.d.ts +1 -1
- package/dist/types/icon.d.ts +16 -1
- package/dist/types/index.d.ts +1 -6
- package/dist/types/json-rpc.d.ts +1 -1
- package/dist/types/localization.d.ts +1 -1
- package/dist/types/manifest/index.d.ts +0 -1
- package/dist/types/manifest/manifest.d.ts +1 -1
- package/dist/types/manifest/node.d.ts +2 -0
- package/dist/types/manifest/validation.d.ts +5 -5
- package/dist/types/node.d.ts +8 -0
- package/dist/types/post-process.d.ts +1 -1
- package/dist/types/structs.d.ts +0 -20
- package/dist/types/ui.d.ts +7 -0
- package/dist/types/virtual-file/index.d.ts +0 -1
- package/dist/types/virtual-file/node.d.ts +2 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +28 -0
- package/dist/types.mjs.map +1 -0
- package/dist/ui.js +12 -0
- package/dist/ui.js.map +1 -0
- package/dist/ui.mjs +12 -0
- package/dist/ui.mjs.map +1 -0
- package/dist/validation.js +24 -0
- package/dist/validation.js.map +1 -0
- package/dist/validation.mjs +24 -0
- package/dist/validation.mjs.map +1 -0
- package/dist/versions.js +12 -0
- package/dist/versions.js.map +1 -0
- package/dist/versions.mjs +12 -0
- package/dist/versions.mjs.map +1 -0
- package/dist/virtual-file/VirtualFile.js +9 -0
- package/dist/virtual-file/VirtualFile.js.map +1 -0
- package/dist/virtual-file/VirtualFile.mjs +9 -0
- package/dist/virtual-file/VirtualFile.mjs.map +1 -0
- package/dist/virtual-file/index.js +10 -0
- package/dist/virtual-file/index.js.map +1 -0
- package/dist/virtual-file/index.mjs +10 -0
- package/dist/virtual-file/index.mjs.map +1 -0
- package/dist/virtual-file/node.js +17 -0
- package/dist/virtual-file/node.js.map +1 -0
- package/dist/virtual-file/node.mjs +17 -0
- package/dist/virtual-file/node.mjs.map +1 -0
- package/dist/virtual-file/toVirtualFile.js +12 -0
- package/dist/virtual-file/toVirtualFile.js.map +1 -0
- package/dist/virtual-file/toVirtualFile.mjs +12 -0
- package/dist/virtual-file/toVirtualFile.mjs.map +1 -0
- package/package.json +24 -40
- package/dist/cjs/array.js +0 -23
- package/dist/cjs/array.js.map +0 -1
- package/dist/cjs/auxiliary-files.js +0 -27
- package/dist/cjs/auxiliary-files.js.map +0 -1
- package/dist/cjs/base64.js +0 -44
- package/dist/cjs/base64.js.map +0 -1
- package/dist/cjs/bytes.js +0 -23
- package/dist/cjs/bytes.js.map +0 -1
- package/dist/cjs/caveats.js +0 -48
- package/dist/cjs/caveats.js.map +0 -1
- package/dist/cjs/checksum.js +0 -43
- package/dist/cjs/checksum.js.map +0 -1
- package/dist/cjs/cronjob.js +0 -77
- package/dist/cjs/cronjob.js.map +0 -1
- package/dist/cjs/deep-clone.js +0 -22
- package/dist/cjs/deep-clone.js.map +0 -1
- package/dist/cjs/default-endowments.js +0 -49
- package/dist/cjs/default-endowments.js.map +0 -1
- package/dist/cjs/derivation-paths.js +0 -300
- package/dist/cjs/derivation-paths.js.map +0 -1
- package/dist/cjs/entropy.js +0 -23
- package/dist/cjs/entropy.js.map +0 -1
- package/dist/cjs/errors.js +0 -221
- package/dist/cjs/errors.js.map +0 -1
- package/dist/cjs/eval-worker.js +0 -44
- package/dist/cjs/eval-worker.js.map +0 -1
- package/dist/cjs/eval.js +0 -77
- package/dist/cjs/eval.js.map +0 -1
- package/dist/cjs/fs.js +0 -126
- package/dist/cjs/fs.js.map +0 -1
- package/dist/cjs/handler-types.js +0 -34
- package/dist/cjs/handler-types.js.map +0 -1
- package/dist/cjs/handlers.js +0 -173
- package/dist/cjs/handlers.js.map +0 -1
- package/dist/cjs/icon.js +0 -37
- package/dist/cjs/icon.js.map +0 -1
- package/dist/cjs/iframe.js +0 -59
- package/dist/cjs/iframe.js.map +0 -1
- package/dist/cjs/index.browser.js +0 -49
- package/dist/cjs/index.browser.js.map +0 -1
- package/dist/cjs/index.executionenv.js +0 -27
- package/dist/cjs/index.executionenv.js.map +0 -1
- package/dist/cjs/index.js +0 -54
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json-rpc.js +0 -81
- package/dist/cjs/json-rpc.js.map +0 -1
- package/dist/cjs/json.js +0 -16
- package/dist/cjs/json.js.map +0 -1
- package/dist/cjs/localization.js +0 -113
- package/dist/cjs/localization.js.map +0 -1
- package/dist/cjs/logging.js +0 -40
- package/dist/cjs/logging.js.map +0 -1
- package/dist/cjs/manifest/index.browser.js +0 -20
- package/dist/cjs/manifest/index.browser.js.map +0 -1
- package/dist/cjs/manifest/index.js +0 -21
- package/dist/cjs/manifest/index.js.map +0 -1
- package/dist/cjs/manifest/manifest.js +0 -275
- package/dist/cjs/manifest/manifest.js.map +0 -1
- package/dist/cjs/manifest/validation.js +0 -244
- package/dist/cjs/manifest/validation.js.map +0 -1
- package/dist/cjs/mock.js +0 -128
- package/dist/cjs/mock.js.map +0 -1
- package/dist/cjs/namespace.js +0 -136
- package/dist/cjs/namespace.js.map +0 -1
- package/dist/cjs/npm.js +0 -96
- package/dist/cjs/npm.js.map +0 -1
- package/dist/cjs/path.js +0 -21
- package/dist/cjs/path.js.map +0 -1
- package/dist/cjs/post-process.js +0 -328
- package/dist/cjs/post-process.js.map +0 -1
- package/dist/cjs/snaps.js +0 -232
- package/dist/cjs/snaps.js.map +0 -1
- package/dist/cjs/strings.js +0 -21
- package/dist/cjs/strings.js.map +0 -1
- package/dist/cjs/structs.js +0 -210
- package/dist/cjs/structs.js.map +0 -1
- package/dist/cjs/types.js +0 -104
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/ui.js +0 -53
- package/dist/cjs/ui.js.map +0 -1
- package/dist/cjs/validation.js +0 -24
- package/dist/cjs/validation.js.map +0 -1
- package/dist/cjs/versions.js +0 -47
- package/dist/cjs/versions.js.map +0 -1
- package/dist/cjs/virtual-file/VirtualFile.js +0 -92
- package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
- package/dist/cjs/virtual-file/index.browser.js +0 -20
- package/dist/cjs/virtual-file/index.browser.js.map +0 -1
- package/dist/cjs/virtual-file/index.js +0 -21
- package/dist/cjs/virtual-file/index.js.map +0 -1
- package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
- package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/esm/array.js +0 -13
- package/dist/esm/array.js.map +0 -1
- package/dist/esm/auxiliary-files.js +0 -23
- package/dist/esm/auxiliary-files.js.map +0 -1
- package/dist/esm/base64.js +0 -36
- package/dist/esm/base64.js.map +0 -1
- package/dist/esm/bytes.js +0 -18
- package/dist/esm/bytes.js.map +0 -1
- package/dist/esm/caveats.js +0 -38
- package/dist/esm/caveats.js.map +0 -1
- package/dist/esm/checksum.js +0 -41
- package/dist/esm/checksum.js.map +0 -1
- package/dist/esm/cronjob.js +0 -59
- package/dist/esm/cronjob.js.map +0 -1
- package/dist/esm/deep-clone.js +0 -7
- package/dist/esm/deep-clone.js.map +0 -1
- package/dist/esm/default-endowments.js +0 -39
- package/dist/esm/default-endowments.js.map +0 -1
- package/dist/esm/derivation-paths.js +0 -287
- package/dist/esm/derivation-paths.js.map +0 -1
- package/dist/esm/entropy.js +0 -6
- package/dist/esm/entropy.js.map +0 -1
- package/dist/esm/errors.js +0 -211
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/eval-worker.js +0 -40
- package/dist/esm/eval-worker.js.map +0 -1
- package/dist/esm/eval.js +0 -65
- package/dist/esm/eval.js.map +0 -1
- package/dist/esm/fs.js +0 -136
- package/dist/esm/fs.js.map +0 -1
- package/dist/esm/handler-types.js +0 -16
- package/dist/esm/handler-types.js.map +0 -1
- package/dist/esm/handlers.js +0 -119
- package/dist/esm/handlers.js.map +0 -1
- package/dist/esm/icon.js +0 -11
- package/dist/esm/icon.js.map +0 -1
- package/dist/esm/iframe.js +0 -49
- package/dist/esm/iframe.js.map +0 -1
- package/dist/esm/index.browser.js +0 -32
- package/dist/esm/index.browser.js.map +0 -1
- package/dist/esm/index.executionenv.js +0 -10
- package/dist/esm/index.executionenv.js.map +0 -1
- package/dist/esm/index.js +0 -37
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json-rpc.js +0 -79
- package/dist/esm/json-rpc.js.map +0 -1
- package/dist/esm/json.js +0 -17
- package/dist/esm/json.js.map +0 -1
- package/dist/esm/localization.js +0 -115
- package/dist/esm/localization.js.map +0 -1
- package/dist/esm/logging.js +0 -59
- package/dist/esm/logging.js.map +0 -1
- package/dist/esm/manifest/index.browser.js +0 -3
- package/dist/esm/manifest/index.browser.js.map +0 -1
- package/dist/esm/manifest/index.js +0 -4
- package/dist/esm/manifest/index.js.map +0 -1
- package/dist/esm/manifest/manifest.js +0 -299
- package/dist/esm/manifest/manifest.js.map +0 -1
- package/dist/esm/manifest/validation.js +0 -190
- package/dist/esm/manifest/validation.js.map +0 -1
- package/dist/esm/mock.js +0 -111
- package/dist/esm/mock.js.map +0 -1
- package/dist/esm/namespace.js +0 -113
- package/dist/esm/namespace.js.map +0 -1
- package/dist/esm/npm.js +0 -85
- package/dist/esm/npm.js.map +0 -1
- package/dist/esm/path.js +0 -17
- package/dist/esm/path.js.map +0 -1
- package/dist/esm/post-process.js +0 -333
- package/dist/esm/post-process.js.map +0 -1
- package/dist/esm/snaps.js +0 -217
- package/dist/esm/snaps.js.map +0 -1
- package/dist/esm/strings.js +0 -11
- package/dist/esm/strings.js.map +0 -1
- package/dist/esm/structs.js +0 -295
- package/dist/esm/structs.js.map +0 -1
- package/dist/esm/types.js +0 -78
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/ui.js +0 -50
- package/dist/esm/ui.js.map +0 -1
- package/dist/esm/validation.js +0 -19
- package/dist/esm/validation.js.map +0 -1
- package/dist/esm/versions.js +0 -41
- package/dist/esm/versions.js.map +0 -1
- package/dist/esm/virtual-file/VirtualFile.js +0 -82
- package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
- package/dist/esm/virtual-file/index.browser.js +0 -3
- package/dist/esm/virtual-file/index.browser.js.map +0 -1
- package/dist/esm/virtual-file/index.js +0 -4
- package/dist/esm/virtual-file/index.js.map +0 -1
- package/dist/esm/virtual-file/toVirtualFile.js +0 -26
- package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/types/index.browser.d.ts +0 -30
- package/dist/types/manifest/index.browser.d.ts +0 -1
- package/dist/types/virtual-file/index.browser.d.ts +0 -1
package/dist/esm/json-rpc.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { SubjectType } from '@metamask/permission-controller';
|
|
2
|
-
import { assertStruct, isJsonRpcFailure, isJsonRpcSuccess } from '@metamask/utils';
|
|
3
|
-
import { array, boolean, object, optional, refine, string } from 'superstruct';
|
|
4
|
-
export const RpcOriginsStruct = refine(object({
|
|
5
|
-
dapps: optional(boolean()),
|
|
6
|
-
snaps: optional(boolean()),
|
|
7
|
-
allowedOrigins: optional(array(string()))
|
|
8
|
-
}), 'RPC origins', (value)=>{
|
|
9
|
-
const hasOrigins = Boolean(value.snaps === true || value.dapps === true || value.allowedOrigins && value.allowedOrigins.length > 0);
|
|
10
|
-
if (hasOrigins) {
|
|
11
|
-
return true;
|
|
12
|
-
}
|
|
13
|
-
return 'Must specify at least one JSON-RPC origin.';
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Asserts that the given value is a valid {@link RpcOrigins} object.
|
|
17
|
-
*
|
|
18
|
-
* @param value - The value to assert.
|
|
19
|
-
* @param ErrorWrapper - An optional error wrapper to use. Defaults to
|
|
20
|
-
* {@link AssertionError}.
|
|
21
|
-
* @throws If the value is not a valid {@link RpcOrigins} object.
|
|
22
|
-
*/ export function assertIsRpcOrigins(value, // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
23
|
-
ErrorWrapper) {
|
|
24
|
-
assertStruct(value, RpcOriginsStruct, 'Invalid JSON-RPC origins', ErrorWrapper);
|
|
25
|
-
}
|
|
26
|
-
export const KeyringOriginsStruct = object({
|
|
27
|
-
allowedOrigins: optional(array(string()))
|
|
28
|
-
});
|
|
29
|
-
/**
|
|
30
|
-
* Assert that the given value is a valid {@link KeyringOrigins} object.
|
|
31
|
-
*
|
|
32
|
-
* @param value - The value to assert.
|
|
33
|
-
* @param ErrorWrapper - An optional error wrapper to use. Defaults to
|
|
34
|
-
* {@link AssertionError}.
|
|
35
|
-
* @throws If the value is not a valid {@link KeyringOrigins} object.
|
|
36
|
-
*/ export function assertIsKeyringOrigins(value, // eslint-disable-next-line @typescript-eslint/naming-convention
|
|
37
|
-
ErrorWrapper) {
|
|
38
|
-
assertStruct(value, KeyringOriginsStruct, 'Invalid keyring origins', ErrorWrapper);
|
|
39
|
-
}
|
|
40
|
-
/**
|
|
41
|
-
* Check if the given origin is allowed by the given JSON-RPC origins object.
|
|
42
|
-
*
|
|
43
|
-
* @param origins - The JSON-RPC origins object.
|
|
44
|
-
* @param subjectType - The type of the origin.
|
|
45
|
-
* @param origin - The origin to check.
|
|
46
|
-
* @returns Whether the origin is allowed.
|
|
47
|
-
*/ export function isOriginAllowed(origins, subjectType, origin) {
|
|
48
|
-
// The MetaMask client is always allowed.
|
|
49
|
-
if (origin === 'metamask') {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
// If the origin is in the `allowedOrigins` list, it is allowed.
|
|
53
|
-
if (origins.allowedOrigins?.includes(origin)) {
|
|
54
|
-
return true;
|
|
55
|
-
}
|
|
56
|
-
// If the origin is a website and `dapps` is true, it is allowed.
|
|
57
|
-
if (subjectType === SubjectType.Website && origins.dapps) {
|
|
58
|
-
return true;
|
|
59
|
-
}
|
|
60
|
-
// If the origin is a snap and `snaps` is true, it is allowed.
|
|
61
|
-
return Boolean(subjectType === SubjectType.Snap && origins.snaps);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Assert that the given value is a successful JSON-RPC response. If the value
|
|
65
|
-
* is not a success response, an error is thrown. If the value is an JSON-RPC
|
|
66
|
-
* error, the error message is included in the thrown error.
|
|
67
|
-
*
|
|
68
|
-
* @param value - The value to check.
|
|
69
|
-
* @throws If the value is not a JSON-RPC success response.
|
|
70
|
-
*/ export function assertIsJsonRpcSuccess(value) {
|
|
71
|
-
if (!isJsonRpcSuccess(value)) {
|
|
72
|
-
if (isJsonRpcFailure(value)) {
|
|
73
|
-
throw new Error(`JSON-RPC request failed: ${value.error.message}`);
|
|
74
|
-
}
|
|
75
|
-
throw new Error('Invalid JSON-RPC response.');
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
//# sourceMappingURL=json-rpc.js.map
|
package/dist/esm/json-rpc.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/json-rpc.ts"],"sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type {\n AssertionErrorConstructor,\n Json,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, boolean, object, optional, refine, string } from 'superstruct';\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(array(string())),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(array(string())),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (origins.allowedOrigins?.includes(origin)) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess<Json> {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"],"names":["SubjectType","assertStruct","isJsonRpcFailure","isJsonRpcSuccess","array","boolean","object","optional","refine","string","RpcOriginsStruct","dapps","snaps","allowedOrigins","value","hasOrigins","Boolean","length","assertIsRpcOrigins","ErrorWrapper","KeyringOriginsStruct","assertIsKeyringOrigins","isOriginAllowed","origins","subjectType","origin","includes","Website","Snap","assertIsJsonRpcSuccess","Error","error","message"],"mappings":"AAAA,SAASA,WAAW,QAAQ,kCAAkC;AAM9D,SACEC,YAAY,EACZC,gBAAgB,EAChBC,gBAAgB,QACX,kBAAkB;AAEzB,SAASC,KAAK,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,MAAM,EAAEC,MAAM,QAAQ,cAAc;AAE/E,OAAO,MAAMC,mBAAmBF,OAC9BF,OAAO;IACLK,OAAOJ,SAASF;IAChBO,OAAOL,SAASF;IAChBQ,gBAAgBN,SAASH,MAAMK;AACjC,IACA,eACA,CAACK;IACC,MAAMC,aAAaC,QACjBF,MAAMF,KAAK,KAAK,QACdE,MAAMH,KAAK,KAAK,QACfG,MAAMD,cAAc,IAAIC,MAAMD,cAAc,CAACI,MAAM,GAAG;IAG3D,IAAIF,YAAY;QACd,OAAO;IACT;IAEA,OAAO;AACT,GACA;AAIF;;;;;;;CAOC,GACD,OAAO,SAASG,mBACdJ,KAAc,EACd,gEAAgE;AAChEK,YAAwC;IAExClB,aACEa,OACAJ,kBACA,4BACAS;AAEJ;AAEA,OAAO,MAAMC,uBAAuBd,OAAO;IACzCO,gBAAgBN,SAASH,MAAMK;AACjC,GAAG;AAIH;;;;;;;CAOC,GACD,OAAO,SAASY,uBACdP,KAAc,EACd,gEAAgE;AAChEK,YAAwC;IAExClB,aACEa,OACAM,sBACA,2BACAD;AAEJ;AAEA;;;;;;;CAOC,GACD,OAAO,SAASG,gBACdC,OAAmB,EACnBC,WAAwB,EACxBC,MAAc;IAEd,yCAAyC;IACzC,IAAIA,WAAW,YAAY;QACzB,OAAO;IACT;IAEA,gEAAgE;IAChE,IAAIF,QAAQV,cAAc,EAAEa,SAASD,SAAS;QAC5C,OAAO;IACT;IAEA,iEAAiE;IACjE,IAAID,gBAAgBxB,YAAY2B,OAAO,IAAIJ,QAAQZ,KAAK,EAAE;QACxD,OAAO;IACT;IAEA,8DAA8D;IAC9D,OAAOK,QAAQQ,gBAAgBxB,YAAY4B,IAAI,IAAIL,QAAQX,KAAK;AAClE;AAEA;;;;;;;CAOC,GACD,OAAO,SAASiB,uBACdf,KAAc;IAEd,IAAI,CAACX,iBAAiBW,QAAQ;QAC5B,IAAIZ,iBAAiBY,QAAQ;YAC3B,MAAM,IAAIgB,MAAM,CAAC,yBAAyB,EAAEhB,MAAMiB,KAAK,CAACC,OAAO,CAAC,CAAC;QACnE;QAEA,MAAM,IAAIF,MAAM;IAClB;AACF"}
|
package/dist/esm/json.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { getSafeJson } from '@metamask/utils';
|
|
2
|
-
// TODO: Upstream this to @metamask/utils
|
|
3
|
-
/**
|
|
4
|
-
* Parse JSON safely.
|
|
5
|
-
*
|
|
6
|
-
* Does multiple kinds of validation and strips unwanted properties like
|
|
7
|
-
* `__proto__` and `constructor`.
|
|
8
|
-
*
|
|
9
|
-
* @param json - A JSON string to be parsed.
|
|
10
|
-
* @returns The parsed JSON object.
|
|
11
|
-
* @template Type - The type of the JSON object. The type is not actually
|
|
12
|
-
* checked, but it is used to infer the return type.
|
|
13
|
-
*/ export function parseJson(json) {
|
|
14
|
-
return getSafeJson(JSON.parse(json));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
//# sourceMappingURL=json.js.map
|
package/dist/esm/json.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/json.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n"],"names":["getSafeJson","parseJson","json","JSON","parse"],"mappings":"AACA,SAASA,WAAW,QAAQ,kBAAkB;AAE9C,yCAAyC;AAEzC;;;;;;;;;;CAUC,GACD,OAAO,SAASC,UAAoCC,IAAY;IAC9D,OAAOF,YAAkBG,KAAKC,KAAK,CAACF;AACtC"}
|
package/dist/esm/localization.js
DELETED
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
import { getErrorMessage } from '@metamask/snaps-sdk';
|
|
2
|
-
import { create, object, optional, record, string, StructError } from 'superstruct';
|
|
3
|
-
import { parseJson } from './json';
|
|
4
|
-
export const LOCALIZABLE_FIELDS = [
|
|
5
|
-
'description',
|
|
6
|
-
'proposedName'
|
|
7
|
-
];
|
|
8
|
-
export const LocalizationFileStruct = object({
|
|
9
|
-
locale: string(),
|
|
10
|
-
messages: record(string(), object({
|
|
11
|
-
message: string(),
|
|
12
|
-
description: optional(string())
|
|
13
|
-
}))
|
|
14
|
-
});
|
|
15
|
-
/**
|
|
16
|
-
* Validate a list of localization files.
|
|
17
|
-
*
|
|
18
|
-
* @param localizationFiles - The localization files to validate.
|
|
19
|
-
* @returns The validated localization files.
|
|
20
|
-
* @throws If any of the files are considered invalid.
|
|
21
|
-
*/ export function getValidatedLocalizationFiles(localizationFiles) {
|
|
22
|
-
for (const file of localizationFiles){
|
|
23
|
-
try {
|
|
24
|
-
file.result = create(parseJson(file.toString()), LocalizationFileStruct);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
if (error instanceof StructError) {
|
|
27
|
-
throw new Error(`Failed to validate localization file "${file.path}": ${error.message}.`);
|
|
28
|
-
}
|
|
29
|
-
if (error instanceof SyntaxError) {
|
|
30
|
-
throw new Error(`Failed to parse localization file "${file.path}" as JSON.`);
|
|
31
|
-
}
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return localizationFiles;
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Get the localization file for a given locale. If the locale is not found,
|
|
39
|
-
* the English localization file will be returned.
|
|
40
|
-
*
|
|
41
|
-
* @param locale - The locale to use.
|
|
42
|
-
* @param localizationFiles - The localization files to use.
|
|
43
|
-
* @returns The localization file, or `undefined` if no localization file was
|
|
44
|
-
* found.
|
|
45
|
-
*/ export function getLocalizationFile(locale, localizationFiles) {
|
|
46
|
-
const file = localizationFiles.find((localizationFile)=>localizationFile.locale === locale);
|
|
47
|
-
if (!file) {
|
|
48
|
-
return localizationFiles.find((localizationFile)=>localizationFile.locale === 'en');
|
|
49
|
-
}
|
|
50
|
-
return file;
|
|
51
|
-
}
|
|
52
|
-
export const TRANSLATION_REGEX = /\{\{\s?([a-zA-Z0-9-_\s]+)\s?\}\}/gu;
|
|
53
|
-
/**
|
|
54
|
-
* Translate a string using a localization file. This will replace all instances
|
|
55
|
-
* of `{{key}}` with the localized version of `key`.
|
|
56
|
-
*
|
|
57
|
-
* @param value - The string to translate.
|
|
58
|
-
* @param file - The localization file to use, or `undefined` if no localization
|
|
59
|
-
* file was found.
|
|
60
|
-
* @returns The translated string.
|
|
61
|
-
* @throws If the string contains a key that is not present in the localization
|
|
62
|
-
* file, or if no localization file was found.
|
|
63
|
-
*/ export function translate(value, file) {
|
|
64
|
-
const matches = value.matchAll(TRANSLATION_REGEX);
|
|
65
|
-
const array = Array.from(matches);
|
|
66
|
-
return array.reduce((result, [match, key])=>{
|
|
67
|
-
if (!file) {
|
|
68
|
-
throw new Error(`Failed to translate "${value}": No localization file found.`);
|
|
69
|
-
}
|
|
70
|
-
const translation = file.messages[key.trim()];
|
|
71
|
-
if (!translation) {
|
|
72
|
-
throw new Error(`Failed to translate "${value}": No translation found for "${key.trim()}" in "${file.locale}" file.`);
|
|
73
|
-
}
|
|
74
|
-
return result.replace(match, translation.message);
|
|
75
|
-
}, value);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Get the localized Snap manifest for a given locale. This will replace all
|
|
79
|
-
* localized strings in the manifest with the localized version.
|
|
80
|
-
*
|
|
81
|
-
* @param snapManifest - The Snap manifest to localize.
|
|
82
|
-
* @param locale - The locale to use.
|
|
83
|
-
* @param localizationFiles - The localization files to use.
|
|
84
|
-
* @returns The localized Snap manifest.
|
|
85
|
-
*/ export function getLocalizedSnapManifest(snapManifest, locale, localizationFiles) {
|
|
86
|
-
const file = getLocalizationFile(locale, localizationFiles);
|
|
87
|
-
return LOCALIZABLE_FIELDS.reduce((manifest, field)=>{
|
|
88
|
-
const translation = translate(manifest[field], file);
|
|
89
|
-
return {
|
|
90
|
-
...manifest,
|
|
91
|
-
[field]: translation
|
|
92
|
-
};
|
|
93
|
-
}, snapManifest);
|
|
94
|
-
}
|
|
95
|
-
/**
|
|
96
|
-
* Validate the localization files for a Snap manifest.
|
|
97
|
-
*
|
|
98
|
-
* @param snapManifest - The Snap manifest to validate.
|
|
99
|
-
* @param localizationFiles - The localization files to validate.
|
|
100
|
-
* @throws If the manifest cannot be localized.
|
|
101
|
-
*/ export function validateSnapManifestLocalizations(snapManifest, localizationFiles) {
|
|
102
|
-
try {
|
|
103
|
-
// `translate` throws if the manifest cannot be localized, so we just attempt
|
|
104
|
-
// to translate the manifest using all localization files.
|
|
105
|
-
localizationFiles.filter((file)=>file.locale !== 'en').forEach((file)=>{
|
|
106
|
-
getLocalizedSnapManifest(snapManifest, file.locale, localizationFiles);
|
|
107
|
-
});
|
|
108
|
-
// The manifest must be localizable in English.
|
|
109
|
-
getLocalizedSnapManifest(snapManifest, 'en', localizationFiles);
|
|
110
|
-
} catch (error) {
|
|
111
|
-
throw new Error(`Failed to localize Snap manifest: ${getErrorMessage(error)}`);
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
//# sourceMappingURL=localization.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/localization.ts"],"sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Infer } from 'superstruct';\nimport {\n create,\n object,\n optional,\n record,\n string,\n StructError,\n} from 'superstruct';\n\nimport { parseJson } from './json';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport const LOCALIZABLE_FIELDS = ['description', 'proposedName'] as const;\n\nexport const LocalizationFileStruct = object({\n locale: string(),\n messages: record(\n string(),\n object({\n message: string(),\n description: optional(string()),\n }),\n ),\n});\n\nexport type LocalizationFile = Infer<typeof LocalizationFileStruct>;\n\n/**\n * Validate a list of localization files.\n *\n * @param localizationFiles - The localization files to validate.\n * @returns The validated localization files.\n * @throws If any of the files are considered invalid.\n */\nexport function getValidatedLocalizationFiles(\n localizationFiles: VirtualFile[],\n): VirtualFile<LocalizationFile>[] {\n for (const file of localizationFiles) {\n try {\n file.result = create(parseJson(file.toString()), LocalizationFileStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Failed to validate localization file \"${file.path}\": ${error.message}.`,\n );\n }\n\n if (error instanceof SyntaxError) {\n throw new Error(\n `Failed to parse localization file \"${file.path}\" as JSON.`,\n );\n }\n\n throw error;\n }\n }\n\n return localizationFiles as VirtualFile<LocalizationFile>[];\n}\n\n/**\n * Get the localization file for a given locale. If the locale is not found,\n * the English localization file will be returned.\n *\n * @param locale - The locale to use.\n * @param localizationFiles - The localization files to use.\n * @returns The localization file, or `undefined` if no localization file was\n * found.\n */\nexport function getLocalizationFile(\n locale: string,\n localizationFiles: LocalizationFile[],\n) {\n const file = localizationFiles.find(\n (localizationFile) => localizationFile.locale === locale,\n );\n\n if (!file) {\n return localizationFiles.find(\n (localizationFile) => localizationFile.locale === 'en',\n );\n }\n\n return file;\n}\n\nexport const TRANSLATION_REGEX = /\\{\\{\\s?([a-zA-Z0-9-_\\s]+)\\s?\\}\\}/gu;\n\n/**\n * Translate a string using a localization file. This will replace all instances\n * of `{{key}}` with the localized version of `key`.\n *\n * @param value - The string to translate.\n * @param file - The localization file to use, or `undefined` if no localization\n * file was found.\n * @returns The translated string.\n * @throws If the string contains a key that is not present in the localization\n * file, or if no localization file was found.\n */\nexport function translate(value: string, file: LocalizationFile | undefined) {\n const matches = value.matchAll(TRANSLATION_REGEX);\n const array = Array.from(matches);\n\n return array.reduce<string>((result, [match, key]) => {\n if (!file) {\n throw new Error(\n `Failed to translate \"${value}\": No localization file found.`,\n );\n }\n\n const translation = file.messages[key.trim()];\n if (!translation) {\n throw new Error(\n `Failed to translate \"${value}\": No translation found for \"${key.trim()}\" in \"${\n file.locale\n }\" file.`,\n );\n }\n\n return result.replace(match, translation.message);\n }, value);\n}\n\n/**\n * Get the localized Snap manifest for a given locale. This will replace all\n * localized strings in the manifest with the localized version.\n *\n * @param snapManifest - The Snap manifest to localize.\n * @param locale - The locale to use.\n * @param localizationFiles - The localization files to use.\n * @returns The localized Snap manifest.\n */\nexport function getLocalizedSnapManifest(\n snapManifest: SnapManifest,\n locale: string,\n localizationFiles: LocalizationFile[],\n) {\n const file = getLocalizationFile(locale, localizationFiles);\n\n return LOCALIZABLE_FIELDS.reduce((manifest, field) => {\n const translation = translate(manifest[field], file);\n return {\n ...manifest,\n [field]: translation,\n };\n }, snapManifest);\n}\n\n/**\n * Validate the localization files for a Snap manifest.\n *\n * @param snapManifest - The Snap manifest to validate.\n * @param localizationFiles - The localization files to validate.\n * @throws If the manifest cannot be localized.\n */\nexport function validateSnapManifestLocalizations(\n snapManifest: SnapManifest,\n localizationFiles: LocalizationFile[],\n) {\n try {\n // `translate` throws if the manifest cannot be localized, so we just attempt\n // to translate the manifest using all localization files.\n localizationFiles\n .filter((file) => file.locale !== 'en')\n .forEach((file) => {\n getLocalizedSnapManifest(snapManifest, file.locale, localizationFiles);\n });\n\n // The manifest must be localizable in English.\n getLocalizedSnapManifest(snapManifest, 'en', localizationFiles);\n } catch (error) {\n throw new Error(\n `Failed to localize Snap manifest: ${getErrorMessage(error)}`,\n );\n }\n}\n"],"names":["getErrorMessage","create","object","optional","record","string","StructError","parseJson","LOCALIZABLE_FIELDS","LocalizationFileStruct","locale","messages","message","description","getValidatedLocalizationFiles","localizationFiles","file","result","toString","error","Error","path","SyntaxError","getLocalizationFile","find","localizationFile","TRANSLATION_REGEX","translate","value","matches","matchAll","array","Array","from","reduce","match","key","translation","trim","replace","getLocalizedSnapManifest","snapManifest","manifest","field","validateSnapManifestLocalizations","filter","forEach"],"mappings":"AAAA,SAASA,eAAe,QAAQ,sBAAsB;AAEtD,SACEC,MAAM,EACNC,MAAM,EACNC,QAAQ,EACRC,MAAM,EACNC,MAAM,EACNC,WAAW,QACN,cAAc;AAErB,SAASC,SAAS,QAAQ,SAAS;AAInC,OAAO,MAAMC,qBAAqB;IAAC;IAAe;CAAe,CAAU;AAE3E,OAAO,MAAMC,yBAAyBP,OAAO;IAC3CQ,QAAQL;IACRM,UAAUP,OACRC,UACAH,OAAO;QACLU,SAASP;QACTQ,aAAaV,SAASE;IACxB;AAEJ,GAAG;AAIH;;;;;;CAMC,GACD,OAAO,SAASS,8BACdC,iBAAgC;IAEhC,KAAK,MAAMC,QAAQD,kBAAmB;QACpC,IAAI;YACFC,KAAKC,MAAM,GAAGhB,OAAOM,UAAUS,KAAKE,QAAQ,KAAKT;QACnD,EAAE,OAAOU,OAAO;YACd,IAAIA,iBAAiBb,aAAa;gBAChC,MAAM,IAAIc,MACR,CAAC,sCAAsC,EAAEJ,KAAKK,IAAI,CAAC,GAAG,EAAEF,MAAMP,OAAO,CAAC,CAAC,CAAC;YAE5E;YAEA,IAAIO,iBAAiBG,aAAa;gBAChC,MAAM,IAAIF,MACR,CAAC,mCAAmC,EAAEJ,KAAKK,IAAI,CAAC,UAAU,CAAC;YAE/D;YAEA,MAAMF;QACR;IACF;IAEA,OAAOJ;AACT;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASQ,oBACdb,MAAc,EACdK,iBAAqC;IAErC,MAAMC,OAAOD,kBAAkBS,IAAI,CACjC,CAACC,mBAAqBA,iBAAiBf,MAAM,KAAKA;IAGpD,IAAI,CAACM,MAAM;QACT,OAAOD,kBAAkBS,IAAI,CAC3B,CAACC,mBAAqBA,iBAAiBf,MAAM,KAAK;IAEtD;IAEA,OAAOM;AACT;AAEA,OAAO,MAAMU,oBAAoB,qCAAqC;AAEtE;;;;;;;;;;CAUC,GACD,OAAO,SAASC,UAAUC,KAAa,EAAEZ,IAAkC;IACzE,MAAMa,UAAUD,MAAME,QAAQ,CAACJ;IAC/B,MAAMK,QAAQC,MAAMC,IAAI,CAACJ;IAEzB,OAAOE,MAAMG,MAAM,CAAS,CAACjB,QAAQ,CAACkB,OAAOC,IAAI;QAC/C,IAAI,CAACpB,MAAM;YACT,MAAM,IAAII,MACR,CAAC,qBAAqB,EAAEQ,MAAM,8BAA8B,CAAC;QAEjE;QAEA,MAAMS,cAAcrB,KAAKL,QAAQ,CAACyB,IAAIE,IAAI,GAAG;QAC7C,IAAI,CAACD,aAAa;YAChB,MAAM,IAAIjB,MACR,CAAC,qBAAqB,EAAEQ,MAAM,6BAA6B,EAAEQ,IAAIE,IAAI,GAAG,MAAM,EAC5EtB,KAAKN,MAAM,CACZ,OAAO,CAAC;QAEb;QAEA,OAAOO,OAAOsB,OAAO,CAACJ,OAAOE,YAAYzB,OAAO;IAClD,GAAGgB;AACL;AAEA;;;;;;;;CAQC,GACD,OAAO,SAASY,yBACdC,YAA0B,EAC1B/B,MAAc,EACdK,iBAAqC;IAErC,MAAMC,OAAOO,oBAAoBb,QAAQK;IAEzC,OAAOP,mBAAmB0B,MAAM,CAAC,CAACQ,UAAUC;QAC1C,MAAMN,cAAcV,UAAUe,QAAQ,CAACC,MAAM,EAAE3B;QAC/C,OAAO;YACL,GAAG0B,QAAQ;YACX,CAACC,MAAM,EAAEN;QACX;IACF,GAAGI;AACL;AAEA;;;;;;CAMC,GACD,OAAO,SAASG,kCACdH,YAA0B,EAC1B1B,iBAAqC;IAErC,IAAI;QACF,6EAA6E;QAC7E,0DAA0D;QAC1DA,kBACG8B,MAAM,CAAC,CAAC7B,OAASA,KAAKN,MAAM,KAAK,MACjCoC,OAAO,CAAC,CAAC9B;YACRwB,yBAAyBC,cAAczB,KAAKN,MAAM,EAAEK;QACtD;QAEF,+CAA+C;QAC/CyB,yBAAyBC,cAAc,MAAM1B;IAC/C,EAAE,OAAOI,OAAO;QACd,MAAM,IAAIC,MACR,CAAC,kCAAkC,EAAEpB,gBAAgBmB,OAAO,CAAC;IAEjE;AACF"}
|
package/dist/esm/logging.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { createProjectLogger } from '@metamask/utils';
|
|
2
|
-
// The global logger used across the monorepo. Other projects should use this
|
|
3
|
-
// to create a module logger.
|
|
4
|
-
export const snapsLogger = createProjectLogger('snaps');
|
|
5
|
-
/**
|
|
6
|
-
* Log a message. Currently, this is just a wrapper around `console.log`, but
|
|
7
|
-
* the implementation may change in the future. These logs will be included in
|
|
8
|
-
* production builds, so they should be used sparingly, and not contain any
|
|
9
|
-
* sensitive information.
|
|
10
|
-
*
|
|
11
|
-
* This function makes it easy to swap out the logging implementation in all
|
|
12
|
-
* files at once.
|
|
13
|
-
*
|
|
14
|
-
* @param message - The message to log.
|
|
15
|
-
* @param optionalParams - Additional parameters to pass to the logging.
|
|
16
|
-
*/ export function logInfo(message, ...optionalParams) {
|
|
17
|
-
// eslint-disable-next-line no-console
|
|
18
|
-
console.log(message, ...optionalParams);
|
|
19
|
-
}
|
|
20
|
-
/**
|
|
21
|
-
* Log an error. Currently, this is just a wrapper around `console.error`, but
|
|
22
|
-
* the implementation may change in the future. These logs will be included in
|
|
23
|
-
* production builds, so they should be used sparingly, and not contain any
|
|
24
|
-
* sensitive information.
|
|
25
|
-
*
|
|
26
|
-
* These logs should always be visible, without requiring the user to enable
|
|
27
|
-
* verbose logging (like setting a `DEBUG` environment variable), as they are
|
|
28
|
-
* important for debugging snaps.
|
|
29
|
-
*
|
|
30
|
-
* This function makes it easy to swap out the logging implementation in all
|
|
31
|
-
* files at once.
|
|
32
|
-
*
|
|
33
|
-
* @param error - The error to log.
|
|
34
|
-
* @param optionalParams - Additional parameters to pass to the logging.
|
|
35
|
-
*/ export function logError(error, ...optionalParams) {
|
|
36
|
-
// eslint-disable-next-line no-console
|
|
37
|
-
console.error(error, ...optionalParams);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Log a warning. Currently, this is just a wrapper around `console.warn`, but
|
|
41
|
-
* the implementation may change in the future. These logs will be included in
|
|
42
|
-
* production builds, so they should be used sparingly, and not contain any
|
|
43
|
-
* sensitive information.
|
|
44
|
-
*
|
|
45
|
-
* These logs should always be visible, without requiring the user to enable
|
|
46
|
-
* verbose logging (like setting a `DEBUG` environment variable), as they are
|
|
47
|
-
* important for debugging snaps.
|
|
48
|
-
*
|
|
49
|
-
* This function makes it easy to swap out the logging implementation in all
|
|
50
|
-
* files at once.
|
|
51
|
-
*
|
|
52
|
-
* @param message - The message to log.
|
|
53
|
-
* @param optionalParams - Additional parameters to pass to the logging.
|
|
54
|
-
*/ export function logWarning(message, ...optionalParams) {
|
|
55
|
-
// eslint-disable-next-line no-console
|
|
56
|
-
console.warn(message, ...optionalParams);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
//# sourceMappingURL=logging.js.map
|
package/dist/esm/logging.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/logging.ts"],"sourcesContent":["import { createProjectLogger } from '@metamask/utils';\n\n// The global logger used across the monorepo. Other projects should use this\n// to create a module logger.\nexport const snapsLogger = createProjectLogger('snaps');\n\n/**\n * Log a message. Currently, this is just a wrapper around `console.log`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param message - The message to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logInfo(message: string, ...optionalParams: unknown[]): void {\n // eslint-disable-next-line no-console\n console.log(message, ...optionalParams);\n}\n\n/**\n * Log an error. Currently, this is just a wrapper around `console.error`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * These logs should always be visible, without requiring the user to enable\n * verbose logging (like setting a `DEBUG` environment variable), as they are\n * important for debugging snaps.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param error - The error to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logError(error: unknown, ...optionalParams: unknown[]): void {\n // eslint-disable-next-line no-console\n console.error(error, ...optionalParams);\n}\n\n/**\n * Log a warning. Currently, this is just a wrapper around `console.warn`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * These logs should always be visible, without requiring the user to enable\n * verbose logging (like setting a `DEBUG` environment variable), as they are\n * important for debugging snaps.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param message - The message to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logWarning(\n message: string,\n ...optionalParams: unknown[]\n): void {\n // eslint-disable-next-line no-console\n console.warn(message, ...optionalParams);\n}\n"],"names":["createProjectLogger","snapsLogger","logInfo","message","optionalParams","console","log","logError","error","logWarning","warn"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,kBAAkB;AAEtD,6EAA6E;AAC7E,6BAA6B;AAC7B,OAAO,MAAMC,cAAcD,oBAAoB,SAAS;AAExD;;;;;;;;;;;CAWC,GACD,OAAO,SAASE,QAAQC,OAAe,EAAE,GAAGC,cAAyB;IACnE,sCAAsC;IACtCC,QAAQC,GAAG,CAACH,YAAYC;AAC1B;AAEA;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASG,SAASC,KAAc,EAAE,GAAGJ,cAAyB;IACnE,sCAAsC;IACtCC,QAAQG,KAAK,CAACA,UAAUJ;AAC1B;AAEA;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASK,WACdN,OAAe,EACf,GAAGC,cAAyB;IAE5B,sCAAsC;IACtCC,QAAQK,IAAI,CAACP,YAAYC;AAC3B"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/manifest/index.browser.ts"],"sourcesContent":["export * from './validation';\n"],"names":[],"mappings":"AAAA,cAAc,eAAe"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/manifest/index.ts"],"sourcesContent":["export * from './manifest';\nexport * from './validation';\n"],"names":[],"mappings":"AAAA,cAAc,aAAa;AAC3B,cAAc,eAAe"}
|
|
@@ -1,299 +0,0 @@
|
|
|
1
|
-
import { getErrorMessage } from '@metamask/snaps-sdk';
|
|
2
|
-
import { assertExhaustive, assert, isPlainObject } from '@metamask/utils';
|
|
3
|
-
import deepEqual from 'fast-deep-equal';
|
|
4
|
-
import { promises as fs } from 'fs';
|
|
5
|
-
import pathUtils from 'path';
|
|
6
|
-
import { deepClone } from '../deep-clone';
|
|
7
|
-
import { readJsonFile } from '../fs';
|
|
8
|
-
import { validateNpmSnap } from '../npm';
|
|
9
|
-
import { getSnapChecksum, ProgrammaticallyFixableSnapError, validateSnapShasum } from '../snaps';
|
|
10
|
-
import { NpmSnapFileNames, SnapValidationFailureReason } from '../types';
|
|
11
|
-
import { readVirtualFile, VirtualFile } from '../virtual-file';
|
|
12
|
-
const MANIFEST_SORT_ORDER = {
|
|
13
|
-
$schema: 1,
|
|
14
|
-
version: 2,
|
|
15
|
-
description: 3,
|
|
16
|
-
proposedName: 4,
|
|
17
|
-
repository: 5,
|
|
18
|
-
source: 6,
|
|
19
|
-
initialConnections: 7,
|
|
20
|
-
initialPermissions: 8,
|
|
21
|
-
manifestVersion: 9
|
|
22
|
-
};
|
|
23
|
-
/**
|
|
24
|
-
* Validates a snap.manifest.json file. Attempts to fix the manifest and write
|
|
25
|
-
* the fixed version to disk if `writeManifest` is true. Throws if validation
|
|
26
|
-
* fails.
|
|
27
|
-
*
|
|
28
|
-
* @param basePath - The path to the folder with the manifest files.
|
|
29
|
-
* @param writeManifest - Whether to write the fixed manifest to disk.
|
|
30
|
-
* @param sourceCode - The source code of the Snap.
|
|
31
|
-
* @param writeFileFn - The function to use to write the manifest to disk.
|
|
32
|
-
* @returns Whether the manifest was updated, and an array of warnings that
|
|
33
|
-
* were encountered during processing of the manifest files.
|
|
34
|
-
*/ export async function checkManifest(basePath, writeManifest = true, sourceCode, writeFileFn = fs.writeFile) {
|
|
35
|
-
const warnings = [];
|
|
36
|
-
const errors = [];
|
|
37
|
-
let updated = false;
|
|
38
|
-
const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);
|
|
39
|
-
const manifestFile = await readJsonFile(manifestPath);
|
|
40
|
-
const unvalidatedManifest = manifestFile.result;
|
|
41
|
-
const packageFile = await readJsonFile(pathUtils.join(basePath, NpmSnapFileNames.PackageJson));
|
|
42
|
-
const auxiliaryFilePaths = getSnapFilePaths(unvalidatedManifest, (manifest)=>manifest?.source?.files);
|
|
43
|
-
const localizationFilePaths = getSnapFilePaths(unvalidatedManifest, (manifest)=>manifest?.source?.locales);
|
|
44
|
-
const snapFiles = {
|
|
45
|
-
manifest: manifestFile,
|
|
46
|
-
packageJson: packageFile,
|
|
47
|
-
sourceCode: await getSnapSourceCode(basePath, unvalidatedManifest, sourceCode),
|
|
48
|
-
svgIcon: await getSnapIcon(basePath, unvalidatedManifest),
|
|
49
|
-
// Intentionally pass null as the encoding here since the files may be binary
|
|
50
|
-
auxiliaryFiles: await getSnapFiles(basePath, auxiliaryFilePaths, null) ?? [],
|
|
51
|
-
localizationFiles: await getSnapFiles(basePath, localizationFilePaths) ?? []
|
|
52
|
-
};
|
|
53
|
-
let manifest;
|
|
54
|
-
try {
|
|
55
|
-
({ manifest } = await validateNpmSnap(snapFiles));
|
|
56
|
-
} catch (error) {
|
|
57
|
-
if (error instanceof ProgrammaticallyFixableSnapError) {
|
|
58
|
-
errors.push(error.message);
|
|
59
|
-
// If we get here, the files at least have the correct shape.
|
|
60
|
-
const partiallyValidatedFiles = snapFiles;
|
|
61
|
-
let isInvalid = true;
|
|
62
|
-
let currentError = error;
|
|
63
|
-
const maxAttempts = Object.keys(SnapValidationFailureReason).length;
|
|
64
|
-
// Attempt to fix all fixable validation failure reasons. All such reasons
|
|
65
|
-
// are enumerated by the `SnapValidationFailureReason` enum, so we only
|
|
66
|
-
// attempt to fix the manifest the same amount of times as there are
|
|
67
|
-
// reasons in the enum.
|
|
68
|
-
for(let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++){
|
|
69
|
-
manifest = await fixManifest(manifest ? {
|
|
70
|
-
...partiallyValidatedFiles,
|
|
71
|
-
manifest
|
|
72
|
-
} : partiallyValidatedFiles, currentError);
|
|
73
|
-
try {
|
|
74
|
-
await validateNpmSnapManifest({
|
|
75
|
-
...partiallyValidatedFiles,
|
|
76
|
-
manifest
|
|
77
|
-
});
|
|
78
|
-
isInvalid = false;
|
|
79
|
-
} catch (nextValidationError) {
|
|
80
|
-
currentError = nextValidationError;
|
|
81
|
-
/* istanbul ignore next: this should be impossible */ if (!(nextValidationError instanceof ProgrammaticallyFixableSnapError) || attempts === maxAttempts && !isInvalid) {
|
|
82
|
-
throw new Error(`Internal error: Failed to fix manifest. This is a bug, please report it. Reason:\n${error.message}`);
|
|
83
|
-
}
|
|
84
|
-
errors.push(currentError.message);
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
updated = true;
|
|
88
|
-
} else {
|
|
89
|
-
throw error;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
// TypeScript assumes `manifest` can still be undefined, that is not the case.
|
|
93
|
-
// But we assert to keep TypeScript happy.
|
|
94
|
-
assert(manifest);
|
|
95
|
-
const validatedManifest = manifest.result;
|
|
96
|
-
// Check presence of recommended keys
|
|
97
|
-
const recommendedFields = [
|
|
98
|
-
'repository'
|
|
99
|
-
];
|
|
100
|
-
const missingRecommendedFields = recommendedFields.filter((key)=>!validatedManifest[key]);
|
|
101
|
-
if (missingRecommendedFields.length > 0) {
|
|
102
|
-
warnings.push(`Missing recommended package.json properties:\n${missingRecommendedFields.reduce((allMissing, currentField)=>{
|
|
103
|
-
return `${allMissing}\t${currentField}\n`;
|
|
104
|
-
}, '')}`);
|
|
105
|
-
}
|
|
106
|
-
if (writeManifest) {
|
|
107
|
-
try {
|
|
108
|
-
const newManifest = `${JSON.stringify(getWritableManifest(validatedManifest), null, 2)}\n`;
|
|
109
|
-
if (updated || newManifest !== manifestFile.value) {
|
|
110
|
-
await writeFileFn(pathUtils.join(basePath, NpmSnapFileNames.Manifest), newManifest);
|
|
111
|
-
}
|
|
112
|
-
} catch (error) {
|
|
113
|
-
// Note: This error isn't pushed to the errors array, because it's not an
|
|
114
|
-
// error in the manifest itself.
|
|
115
|
-
throw new Error(`Failed to update snap.manifest.json: ${error.message}`);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return {
|
|
119
|
-
manifest: validatedManifest,
|
|
120
|
-
updated,
|
|
121
|
-
warnings,
|
|
122
|
-
errors
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Given the relevant Snap files (manifest, `package.json`, and bundle) and a
|
|
127
|
-
* Snap manifest validation error, fixes the fault in the manifest that caused
|
|
128
|
-
* the error.
|
|
129
|
-
*
|
|
130
|
-
* @param snapFiles - The contents of all Snap files.
|
|
131
|
-
* @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.
|
|
132
|
-
* @returns A copy of the manifest file where the cause of the error is fixed.
|
|
133
|
-
*/ export async function fixManifest(snapFiles, error) {
|
|
134
|
-
const { manifest, packageJson } = snapFiles;
|
|
135
|
-
const clonedFile = manifest.clone();
|
|
136
|
-
const manifestCopy = clonedFile.result;
|
|
137
|
-
switch(error.reason){
|
|
138
|
-
case SnapValidationFailureReason.NameMismatch:
|
|
139
|
-
manifestCopy.source.location.npm.packageName = packageJson.result.name;
|
|
140
|
-
break;
|
|
141
|
-
case SnapValidationFailureReason.VersionMismatch:
|
|
142
|
-
manifestCopy.version = packageJson.result.version;
|
|
143
|
-
break;
|
|
144
|
-
case SnapValidationFailureReason.RepositoryMismatch:
|
|
145
|
-
manifestCopy.repository = packageJson.result.repository ? deepClone(packageJson.result.repository) : undefined;
|
|
146
|
-
break;
|
|
147
|
-
case SnapValidationFailureReason.ShasumMismatch:
|
|
148
|
-
manifestCopy.source.shasum = await getSnapChecksum(snapFiles);
|
|
149
|
-
break;
|
|
150
|
-
/* istanbul ignore next */ default:
|
|
151
|
-
assertExhaustive(error.reason);
|
|
152
|
-
}
|
|
153
|
-
clonedFile.result = manifestCopy;
|
|
154
|
-
clonedFile.value = JSON.stringify(manifestCopy);
|
|
155
|
-
return clonedFile;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Given an unvalidated Snap manifest, attempts to extract the location of the
|
|
159
|
-
* bundle source file location and read the file.
|
|
160
|
-
*
|
|
161
|
-
* @param basePath - The path to the folder with the manifest files.
|
|
162
|
-
* @param manifest - The unvalidated Snap manifest file contents.
|
|
163
|
-
* @param sourceCode - Override source code for plugins.
|
|
164
|
-
* @returns The contents of the bundle file, if any.
|
|
165
|
-
*/ export async function getSnapSourceCode(basePath, manifest, sourceCode) {
|
|
166
|
-
if (!isPlainObject(manifest)) {
|
|
167
|
-
return undefined;
|
|
168
|
-
}
|
|
169
|
-
const sourceFilePath = manifest.source?.location?.npm?.filePath;
|
|
170
|
-
if (!sourceFilePath) {
|
|
171
|
-
return undefined;
|
|
172
|
-
}
|
|
173
|
-
if (sourceCode) {
|
|
174
|
-
return new VirtualFile({
|
|
175
|
-
path: pathUtils.join(basePath, sourceFilePath),
|
|
176
|
-
value: sourceCode
|
|
177
|
-
});
|
|
178
|
-
}
|
|
179
|
-
try {
|
|
180
|
-
const virtualFile = await readVirtualFile(pathUtils.join(basePath, sourceFilePath), 'utf8');
|
|
181
|
-
return virtualFile;
|
|
182
|
-
} catch (error) {
|
|
183
|
-
throw new Error(`Failed to read snap bundle file: ${getErrorMessage(error)}`);
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Given an unvalidated Snap manifest, attempts to extract the location of the
|
|
188
|
-
* icon and read the file.
|
|
189
|
-
*
|
|
190
|
-
* @param basePath - The path to the folder with the manifest files.
|
|
191
|
-
* @param manifest - The unvalidated Snap manifest file contents.
|
|
192
|
-
* @returns The contents of the icon, if any.
|
|
193
|
-
*/ export async function getSnapIcon(basePath, manifest) {
|
|
194
|
-
if (!isPlainObject(manifest)) {
|
|
195
|
-
return undefined;
|
|
196
|
-
}
|
|
197
|
-
const iconPath = manifest.source?.location?.npm?.iconPath;
|
|
198
|
-
if (!iconPath) {
|
|
199
|
-
return undefined;
|
|
200
|
-
}
|
|
201
|
-
try {
|
|
202
|
-
const virtualFile = await readVirtualFile(pathUtils.join(basePath, iconPath), 'utf8');
|
|
203
|
-
return virtualFile;
|
|
204
|
-
} catch (error) {
|
|
205
|
-
throw new Error(`Failed to read snap icon file: ${getErrorMessage(error)}`);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
/**
|
|
209
|
-
* Get an array of paths from an unvalidated Snap manifest.
|
|
210
|
-
*
|
|
211
|
-
* @param manifest - The unvalidated Snap manifest file contents.
|
|
212
|
-
* @param selector - A function that returns the paths to the files.
|
|
213
|
-
* @returns The paths to the files, if any.
|
|
214
|
-
*/ export function getSnapFilePaths(manifest, selector) {
|
|
215
|
-
if (!isPlainObject(manifest)) {
|
|
216
|
-
return undefined;
|
|
217
|
-
}
|
|
218
|
-
const snapManifest = manifest;
|
|
219
|
-
const paths = selector(snapManifest);
|
|
220
|
-
if (!Array.isArray(paths)) {
|
|
221
|
-
return undefined;
|
|
222
|
-
}
|
|
223
|
-
return paths;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Given an unvalidated Snap manifest, attempts to extract the files with the
|
|
227
|
-
* given paths and read them.
|
|
228
|
-
*
|
|
229
|
-
* @param basePath - The path to the folder with the manifest files.
|
|
230
|
-
* @param paths - The paths to the files.
|
|
231
|
-
* @param encoding - An optional encoding to pass down to readVirtualFile.
|
|
232
|
-
* @returns A list of auxiliary files and their contents, if any.
|
|
233
|
-
*/ export async function getSnapFiles(basePath, paths, encoding = 'utf8') {
|
|
234
|
-
if (!paths) {
|
|
235
|
-
return undefined;
|
|
236
|
-
}
|
|
237
|
-
try {
|
|
238
|
-
return await Promise.all(paths.map(async (filePath)=>readVirtualFile(pathUtils.join(basePath, filePath), encoding)));
|
|
239
|
-
} catch (error) {
|
|
240
|
-
throw new Error(`Failed to read snap files: ${getErrorMessage(error)}`);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* Sorts the given manifest in our preferred sort order and removes the
|
|
245
|
-
* `repository` field if it is falsy (it may be `null`).
|
|
246
|
-
*
|
|
247
|
-
* @param manifest - The manifest to sort and modify.
|
|
248
|
-
* @returns The disk-ready manifest.
|
|
249
|
-
*/ export function getWritableManifest(manifest) {
|
|
250
|
-
const { repository, ...remaining } = manifest;
|
|
251
|
-
const keys = Object.keys(repository ? {
|
|
252
|
-
...remaining,
|
|
253
|
-
repository
|
|
254
|
-
} : remaining);
|
|
255
|
-
const writableManifest = keys.sort((a, b)=>MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b]).reduce((result, key)=>({
|
|
256
|
-
...result,
|
|
257
|
-
[key]: manifest[key]
|
|
258
|
-
}), {});
|
|
259
|
-
return writableManifest;
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Validates the fields of an NPM Snap manifest that has already passed JSON
|
|
263
|
-
* Schema validation.
|
|
264
|
-
*
|
|
265
|
-
* @param snapFiles - The relevant snap files to validate.
|
|
266
|
-
* @param snapFiles.manifest - The npm Snap manifest to validate.
|
|
267
|
-
* @param snapFiles.packageJson - The npm Snap's `package.json`.
|
|
268
|
-
* @param snapFiles.sourceCode - The Snap's source code.
|
|
269
|
-
* @param snapFiles.svgIcon - The Snap's optional icon.
|
|
270
|
-
* @param snapFiles.auxiliaryFiles - Any auxiliary files required by the snap at runtime.
|
|
271
|
-
* @param snapFiles.localizationFiles - The Snap's localization files.
|
|
272
|
-
*/ export async function validateNpmSnapManifest({ manifest, packageJson, sourceCode, svgIcon, auxiliaryFiles, localizationFiles }) {
|
|
273
|
-
const packageJsonName = packageJson.result.name;
|
|
274
|
-
const packageJsonVersion = packageJson.result.version;
|
|
275
|
-
const packageJsonRepository = packageJson.result.repository;
|
|
276
|
-
const manifestPackageName = manifest.result.source.location.npm.packageName;
|
|
277
|
-
const manifestPackageVersion = manifest.result.version;
|
|
278
|
-
const manifestRepository = manifest.result.repository;
|
|
279
|
-
if (packageJsonName !== manifestPackageName) {
|
|
280
|
-
throw new ProgrammaticallyFixableSnapError(`"${NpmSnapFileNames.Manifest}" npm package name ("${manifestPackageName}") does not match the "${NpmSnapFileNames.PackageJson}" "name" field ("${packageJsonName}").`, SnapValidationFailureReason.NameMismatch);
|
|
281
|
-
}
|
|
282
|
-
if (packageJsonVersion !== manifestPackageVersion) {
|
|
283
|
-
throw new ProgrammaticallyFixableSnapError(`"${NpmSnapFileNames.Manifest}" npm package version ("${manifestPackageVersion}") does not match the "${NpmSnapFileNames.PackageJson}" "version" field ("${packageJsonVersion}").`, SnapValidationFailureReason.VersionMismatch);
|
|
284
|
-
}
|
|
285
|
-
if (// The repository may be `undefined` in package.json but can only be defined
|
|
286
|
-
// or `null` in the Snap manifest due to TS@<4.4 issues.
|
|
287
|
-
(packageJsonRepository || manifestRepository) && !deepEqual(packageJsonRepository, manifestRepository)) {
|
|
288
|
-
throw new ProgrammaticallyFixableSnapError(`"${NpmSnapFileNames.Manifest}" "repository" field does not match the "${NpmSnapFileNames.PackageJson}" "repository" field.`, SnapValidationFailureReason.RepositoryMismatch);
|
|
289
|
-
}
|
|
290
|
-
await validateSnapShasum({
|
|
291
|
-
manifest,
|
|
292
|
-
sourceCode,
|
|
293
|
-
svgIcon,
|
|
294
|
-
auxiliaryFiles,
|
|
295
|
-
localizationFiles
|
|
296
|
-
}, `"${NpmSnapFileNames.Manifest}" "shasum" field does not match computed shasum.`);
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
//# sourceMappingURL=manifest.js.map
|