@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
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/manifest/manifest.ts"],"sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assertExhaustive, assert, isPlainObject } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { validateNpmSnap } from '../npm';\nimport {\n getSnapChecksum,\n ProgrammaticallyFixableSnapError,\n validateSnapShasum,\n} from '../snaps';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames, SnapValidationFailureReason } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file';\nimport type { SnapManifest } from './validation';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialConnections: 7,\n initialPermissions: 8,\n manifestVersion: 9,\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was updated.\n * @property warnings - An array of warnings that were encountered during\n * processing of the manifest files. These warnings are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n * @property errors - An array of errors that were encountered during\n * processing of the manifest files. These errors are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n */\nexport type CheckManifestResult = {\n manifest: SnapManifest;\n updated?: boolean;\n warnings: string[];\n errors: string[];\n};\n\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param writeManifest - Whether to write the fixed manifest to disk.\n * @param sourceCode - The source code of the Snap.\n * @param writeFileFn - The function to use to write the manifest to disk.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n writeManifest = true,\n sourceCode?: string,\n writeFileFn: WriteFileFunction = fs.writeFile,\n): Promise<CheckManifestResult> {\n const warnings: string[] = [];\n const errors: string[] = [];\n\n let updated = false;\n\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const auxiliaryFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.files,\n );\n\n const localizationFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.locales,\n );\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n // Intentionally pass null as the encoding here since the files may be binary\n auxiliaryFiles:\n (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],\n localizationFiles:\n (await getSnapFiles(basePath, localizationFilePaths)) ?? [],\n };\n\n let manifest: VirtualFile<SnapManifest> | undefined;\n try {\n ({ manifest } = await validateNpmSnap(snapFiles));\n } catch (error) {\n if (error instanceof ProgrammaticallyFixableSnapError) {\n errors.push(error.message);\n\n // If we get here, the files at least have the correct shape.\n const partiallyValidatedFiles = snapFiles as SnapFiles;\n\n let isInvalid = true;\n let currentError = error;\n const maxAttempts = Object.keys(SnapValidationFailureReason).length;\n\n // Attempt to fix all fixable validation failure reasons. All such reasons\n // are enumerated by the `SnapValidationFailureReason` enum, so we only\n // attempt to fix the manifest the same amount of times as there are\n // reasons in the enum.\n for (let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++) {\n manifest = await fixManifest(\n manifest\n ? { ...partiallyValidatedFiles, manifest }\n : partiallyValidatedFiles,\n currentError,\n );\n\n try {\n await validateNpmSnapManifest({\n ...partiallyValidatedFiles,\n manifest,\n });\n\n isInvalid = false;\n } catch (nextValidationError) {\n currentError = nextValidationError;\n /* istanbul ignore next: this should be impossible */\n if (\n !(\n nextValidationError instanceof ProgrammaticallyFixableSnapError\n ) ||\n (attempts === maxAttempts && !isInvalid)\n ) {\n throw new Error(\n `Internal error: Failed to fix manifest. This is a bug, please report it. Reason:\\n${error.message}`,\n );\n }\n\n errors.push(currentError.message);\n }\n }\n\n updated = true;\n } else {\n throw error;\n }\n }\n\n // TypeScript assumes `manifest` can still be undefined, that is not the case.\n // But we assert to keep TypeScript happy.\n assert(manifest);\n\n const validatedManifest = manifest.result;\n\n // Check presence of recommended keys\n const recommendedFields = ['repository'] as const;\n\n const missingRecommendedFields = recommendedFields.filter(\n (key) => !validatedManifest[key],\n );\n\n if (missingRecommendedFields.length > 0) {\n warnings.push(\n `Missing recommended package.json properties:\\n${missingRecommendedFields.reduce(\n (allMissing, currentField) => {\n return `${allMissing}\\t${currentField}\\n`;\n },\n '',\n )}`,\n );\n }\n\n if (writeManifest) {\n try {\n const newManifest = `${JSON.stringify(\n getWritableManifest(validatedManifest),\n null,\n 2,\n )}\\n`;\n\n if (updated || newManifest !== manifestFile.value) {\n await writeFileFn(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n newManifest,\n );\n }\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(`Failed to update snap.manifest.json: ${error.message}`);\n }\n }\n\n return { manifest: validatedManifest, updated, warnings, errors };\n}\n\n/**\n * Given the relevant Snap files (manifest, `package.json`, and bundle) and a\n * Snap manifest validation error, fixes the fault in the manifest that caused\n * the error.\n *\n * @param snapFiles - The contents of all Snap files.\n * @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.\n * @returns A copy of the manifest file where the cause of the error is fixed.\n */\nexport async function fixManifest(\n snapFiles: SnapFiles,\n error: ProgrammaticallyFixableSnapError,\n): Promise<VirtualFile<SnapManifest>> {\n const { manifest, packageJson } = snapFiles;\n const clonedFile = manifest.clone();\n const manifestCopy = clonedFile.result;\n\n switch (error.reason) {\n case SnapValidationFailureReason.NameMismatch:\n manifestCopy.source.location.npm.packageName = packageJson.result.name;\n break;\n\n case SnapValidationFailureReason.VersionMismatch:\n manifestCopy.version = packageJson.result.version;\n break;\n\n case SnapValidationFailureReason.RepositoryMismatch:\n manifestCopy.repository = packageJson.result.repository\n ? deepClone(packageJson.result.repository)\n : undefined;\n break;\n\n case SnapValidationFailureReason.ShasumMismatch:\n manifestCopy.source.shasum = await getSnapChecksum(snapFiles);\n break;\n\n /* istanbul ignore next */\n default:\n assertExhaustive(error.reason);\n }\n\n clonedFile.result = manifestCopy;\n clonedFile.value = JSON.stringify(manifestCopy);\n return clonedFile;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(\n `Failed to read snap bundle file: ${getErrorMessage(error)}`,\n );\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap icon file: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Get an array of paths from an unvalidated Snap manifest.\n *\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param selector - A function that returns the paths to the files.\n * @returns The paths to the files, if any.\n */\nexport function getSnapFilePaths(\n manifest: Json,\n selector: (manifest: Partial<SnapManifest>) => string[] | undefined,\n) {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const snapManifest = manifest as Partial<SnapManifest>;\n const paths = selector(snapManifest);\n\n if (!Array.isArray(paths)) {\n return undefined;\n }\n\n return paths;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the files with the\n * given paths and read them.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param paths - The paths to the files.\n * @param encoding - An optional encoding to pass down to readVirtualFile.\n * @returns A list of auxiliary files and their contents, if any.\n */\nexport async function getSnapFiles(\n basePath: string,\n paths: string[] | undefined,\n encoding: BufferEncoding | null = 'utf8',\n): Promise<VirtualFile[] | undefined> {\n if (!paths) {\n return undefined;\n }\n\n try {\n return await Promise.all(\n paths.map(async (filePath) =>\n readVirtualFile(pathUtils.join(basePath, filePath), encoding),\n ),\n );\n } catch (error) {\n throw new Error(`Failed to read snap files: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n\n/**\n * Validates the fields of an NPM Snap manifest that has already passed JSON\n * Schema validation.\n *\n * @param snapFiles - The relevant snap files to validate.\n * @param snapFiles.manifest - The npm Snap manifest to validate.\n * @param snapFiles.packageJson - The npm Snap's `package.json`.\n * @param snapFiles.sourceCode - The Snap's source code.\n * @param snapFiles.svgIcon - The Snap's optional icon.\n * @param snapFiles.auxiliaryFiles - Any auxiliary files required by the snap at runtime.\n * @param snapFiles.localizationFiles - The Snap's localization files.\n */\nexport async function validateNpmSnapManifest({\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n}: SnapFiles) {\n const packageJsonName = packageJson.result.name;\n const packageJsonVersion = packageJson.result.version;\n const packageJsonRepository = packageJson.result.repository;\n\n const manifestPackageName = manifest.result.source.location.npm.packageName;\n const manifestPackageVersion = manifest.result.version;\n const manifestRepository = manifest.result.repository;\n\n if (packageJsonName !== manifestPackageName) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package name (\"${manifestPackageName}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"name\" field (\"${packageJsonName}\").`,\n SnapValidationFailureReason.NameMismatch,\n );\n }\n\n if (packageJsonVersion !== manifestPackageVersion) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package version (\"${manifestPackageVersion}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"version\" field (\"${packageJsonVersion}\").`,\n SnapValidationFailureReason.VersionMismatch,\n );\n }\n\n if (\n // The repository may be `undefined` in package.json but can only be defined\n // or `null` in the Snap manifest due to TS@<4.4 issues.\n (packageJsonRepository || manifestRepository) &&\n !deepEqual(packageJsonRepository, manifestRepository)\n ) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" \"repository\" field does not match the \"${NpmSnapFileNames.PackageJson}\" \"repository\" field.`,\n SnapValidationFailureReason.RepositoryMismatch,\n );\n }\n\n await validateSnapShasum(\n { manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles },\n `\"${NpmSnapFileNames.Manifest}\" \"shasum\" field does not match computed shasum.`,\n );\n}\n"],"names":["getErrorMessage","assertExhaustive","assert","isPlainObject","deepEqual","promises","fs","pathUtils","deepClone","readJsonFile","validateNpmSnap","getSnapChecksum","ProgrammaticallyFixableSnapError","validateSnapShasum","NpmSnapFileNames","SnapValidationFailureReason","readVirtualFile","VirtualFile","MANIFEST_SORT_ORDER","$schema","version","description","proposedName","repository","source","initialConnections","initialPermissions","manifestVersion","checkManifest","basePath","writeManifest","sourceCode","writeFileFn","writeFile","warnings","errors","updated","manifestPath","join","Manifest","manifestFile","unvalidatedManifest","result","packageFile","PackageJson","auxiliaryFilePaths","getSnapFilePaths","manifest","files","localizationFilePaths","locales","snapFiles","packageJson","getSnapSourceCode","svgIcon","getSnapIcon","auxiliaryFiles","getSnapFiles","localizationFiles","error","push","message","partiallyValidatedFiles","isInvalid","currentError","maxAttempts","Object","keys","length","attempts","fixManifest","validateNpmSnapManifest","nextValidationError","Error","validatedManifest","recommendedFields","missingRecommendedFields","filter","key","reduce","allMissing","currentField","newManifest","JSON","stringify","getWritableManifest","value","clonedFile","clone","manifestCopy","reason","NameMismatch","location","npm","packageName","name","VersionMismatch","RepositoryMismatch","undefined","ShasumMismatch","shasum","sourceFilePath","filePath","path","virtualFile","iconPath","selector","snapManifest","paths","Array","isArray","encoding","Promise","all","map","remaining","writableManifest","sort","a","b","packageJsonName","packageJsonVersion","packageJsonRepository","manifestPackageName","manifestPackageVersion","manifestRepository"],"mappings":"AAAA,SAASA,eAAe,QAAQ,sBAAsB;AAEtD,SAASC,gBAAgB,EAAEC,MAAM,EAAEC,aAAa,QAAQ,kBAAkB;AAC1E,OAAOC,eAAe,kBAAkB;AACxC,SAASC,YAAYC,EAAE,QAAQ,KAAK;AACpC,OAAOC,eAAe,OAAO;A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D,CAAC;AAEnF"}
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { isValidBIP32PathSegment } from '@metamask/key-tree';
|
|
2
|
-
import { assertStruct, ChecksumStruct, VersionStruct, isValidSemVerRange, inMilliseconds, Duration } from '@metamask/utils';
|
|
3
|
-
import { array, boolean, create, enums, integer, is, literal, object, optional, refine, record, size, string, type, union, intersection, assign } from 'superstruct';
|
|
4
|
-
import { isEqual } from '../array';
|
|
5
|
-
import { CronjobSpecificationArrayStruct } from '../cronjob';
|
|
6
|
-
import { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';
|
|
7
|
-
import { KeyringOriginsStruct, RpcOriginsStruct } from '../json-rpc';
|
|
8
|
-
import { ChainIdStruct } from '../namespace';
|
|
9
|
-
import { SnapIdStruct } from '../snaps';
|
|
10
|
-
import { NameStruct, NpmSnapFileNames, uri } from '../types';
|
|
11
|
-
// BIP-43 purposes that cannot be used for entropy derivation. These are in the
|
|
12
|
-
// string form, ending with `'`.
|
|
13
|
-
const FORBIDDEN_PURPOSES = [
|
|
14
|
-
SIP_6_MAGIC_VALUE,
|
|
15
|
-
STATE_ENCRYPTION_MAGIC_VALUE
|
|
16
|
-
];
|
|
17
|
-
export const FORBIDDEN_COIN_TYPES = [
|
|
18
|
-
60
|
|
19
|
-
];
|
|
20
|
-
const FORBIDDEN_PATHS = FORBIDDEN_COIN_TYPES.map((coinType)=>[
|
|
21
|
-
'm',
|
|
22
|
-
"44'",
|
|
23
|
-
`${coinType}'`
|
|
24
|
-
]);
|
|
25
|
-
export const Bip32PathStruct = refine(array(string()), 'BIP-32 path', (path)=>{
|
|
26
|
-
if (path.length === 0) {
|
|
27
|
-
return 'Path must be a non-empty BIP-32 derivation path array';
|
|
28
|
-
}
|
|
29
|
-
if (path[0] !== 'm') {
|
|
30
|
-
return 'Path must start with "m".';
|
|
31
|
-
}
|
|
32
|
-
if (path.length < 3) {
|
|
33
|
-
return 'Paths must have a length of at least three.';
|
|
34
|
-
}
|
|
35
|
-
if (path.slice(1).some((part)=>!isValidBIP32PathSegment(part))) {
|
|
36
|
-
return 'Path must be a valid BIP-32 derivation path array.';
|
|
37
|
-
}
|
|
38
|
-
if (FORBIDDEN_PURPOSES.includes(path[1])) {
|
|
39
|
-
return `The purpose "${path[1]}" is not allowed for entropy derivation.`;
|
|
40
|
-
}
|
|
41
|
-
if (FORBIDDEN_PATHS.some((forbiddenPath)=>isEqual(path.slice(0, forbiddenPath.length), forbiddenPath))) {
|
|
42
|
-
return `The path "${path.join('/')}" is not allowed for entropy derivation.`;
|
|
43
|
-
}
|
|
44
|
-
return true;
|
|
45
|
-
});
|
|
46
|
-
export const bip32entropy = (struct)=>refine(struct, 'BIP-32 entropy', (value)=>{
|
|
47
|
-
if (value.curve === 'ed25519' && value.path.slice(1).some((part)=>!part.endsWith("'"))) {
|
|
48
|
-
return 'Ed25519 does not support unhardened paths.';
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
});
|
|
52
|
-
// Used outside @metamask/snap-utils
|
|
53
|
-
export const Bip32EntropyStruct = bip32entropy(type({
|
|
54
|
-
path: Bip32PathStruct,
|
|
55
|
-
curve: enums([
|
|
56
|
-
'ed25519',
|
|
57
|
-
'secp256k1'
|
|
58
|
-
])
|
|
59
|
-
}));
|
|
60
|
-
export const SnapGetBip32EntropyPermissionsStruct = size(array(Bip32EntropyStruct), 1, Infinity);
|
|
61
|
-
export const SemVerRangeStruct = refine(string(), 'SemVer range', (value)=>{
|
|
62
|
-
if (isValidSemVerRange(value)) {
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
return 'Expected a valid SemVer range.';
|
|
66
|
-
});
|
|
67
|
-
export const SnapIdsStruct = refine(record(SnapIdStruct, object({
|
|
68
|
-
version: optional(SemVerRangeStruct)
|
|
69
|
-
})), 'SnapIds', (value)=>{
|
|
70
|
-
if (Object.keys(value).length === 0) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
return true;
|
|
74
|
-
});
|
|
75
|
-
export const ChainIdsStruct = size(array(ChainIdStruct), 1, Infinity);
|
|
76
|
-
export const LookupMatchersStruct = union([
|
|
77
|
-
object({
|
|
78
|
-
tlds: size(array(string()), 1, Infinity)
|
|
79
|
-
}),
|
|
80
|
-
object({
|
|
81
|
-
schemes: size(array(string()), 1, Infinity)
|
|
82
|
-
}),
|
|
83
|
-
object({
|
|
84
|
-
tlds: size(array(string()), 1, Infinity),
|
|
85
|
-
schemes: size(array(string()), 1, Infinity)
|
|
86
|
-
})
|
|
87
|
-
]);
|
|
88
|
-
export const MINIMUM_REQUEST_TIMEOUT = inMilliseconds(5, Duration.Second);
|
|
89
|
-
export const MAXIMUM_REQUEST_TIMEOUT = inMilliseconds(3, Duration.Minute);
|
|
90
|
-
export const MaxRequestTimeStruct = size(integer(), MINIMUM_REQUEST_TIMEOUT, MAXIMUM_REQUEST_TIMEOUT);
|
|
91
|
-
// Utility type to union with for all handler structs
|
|
92
|
-
export const HandlerCaveatsStruct = object({
|
|
93
|
-
maxRequestTime: optional(MaxRequestTimeStruct)
|
|
94
|
-
});
|
|
95
|
-
/* eslint-disable @typescript-eslint/naming-convention */ export const PermissionsStruct = type({
|
|
96
|
-
'endowment:cronjob': optional(assign(HandlerCaveatsStruct, object({
|
|
97
|
-
jobs: CronjobSpecificationArrayStruct
|
|
98
|
-
}))),
|
|
99
|
-
'endowment:ethereum-provider': optional(object({})),
|
|
100
|
-
'endowment:keyring': optional(assign(HandlerCaveatsStruct, KeyringOriginsStruct)),
|
|
101
|
-
'endowment:lifecycle-hooks': optional(HandlerCaveatsStruct),
|
|
102
|
-
'endowment:name-lookup': optional(assign(HandlerCaveatsStruct, object({
|
|
103
|
-
chains: optional(ChainIdsStruct),
|
|
104
|
-
matchers: optional(LookupMatchersStruct)
|
|
105
|
-
}))),
|
|
106
|
-
'endowment:network-access': optional(object({})),
|
|
107
|
-
'endowment:page-home': optional(HandlerCaveatsStruct),
|
|
108
|
-
'endowment:rpc': optional(RpcOriginsStruct),
|
|
109
|
-
'endowment:signature-insight': optional(assign(HandlerCaveatsStruct, object({
|
|
110
|
-
allowSignatureOrigin: optional(boolean())
|
|
111
|
-
}))),
|
|
112
|
-
'endowment:transaction-insight': optional(assign(HandlerCaveatsStruct, object({
|
|
113
|
-
allowTransactionOrigin: optional(boolean())
|
|
114
|
-
}))),
|
|
115
|
-
'endowment:webassembly': optional(object({})),
|
|
116
|
-
snap_dialog: optional(object({})),
|
|
117
|
-
snap_manageState: optional(object({})),
|
|
118
|
-
snap_manageAccounts: optional(object({})),
|
|
119
|
-
snap_notify: optional(object({})),
|
|
120
|
-
snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),
|
|
121
|
-
snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),
|
|
122
|
-
snap_getBip44Entropy: optional(size(array(object({
|
|
123
|
-
coinType: size(integer(), 0, 2 ** 32 - 1)
|
|
124
|
-
})), 1, Infinity)),
|
|
125
|
-
snap_getEntropy: optional(object({})),
|
|
126
|
-
snap_getLocale: optional(object({})),
|
|
127
|
-
wallet_snap: optional(SnapIdsStruct)
|
|
128
|
-
});
|
|
129
|
-
export const SnapAuxilaryFilesStruct = array(string());
|
|
130
|
-
export const InitialConnectionsStruct = record(intersection([
|
|
131
|
-
string(),
|
|
132
|
-
uri()
|
|
133
|
-
]), object({}));
|
|
134
|
-
export const SnapManifestStruct = object({
|
|
135
|
-
version: VersionStruct,
|
|
136
|
-
description: size(string(), 1, 280),
|
|
137
|
-
proposedName: size(string(), 1, 214),
|
|
138
|
-
repository: optional(object({
|
|
139
|
-
type: size(string(), 1, Infinity),
|
|
140
|
-
url: size(string(), 1, Infinity)
|
|
141
|
-
})),
|
|
142
|
-
source: object({
|
|
143
|
-
shasum: ChecksumStruct,
|
|
144
|
-
location: object({
|
|
145
|
-
npm: object({
|
|
146
|
-
filePath: size(string(), 1, Infinity),
|
|
147
|
-
iconPath: optional(size(string(), 1, Infinity)),
|
|
148
|
-
packageName: NameStruct,
|
|
149
|
-
registry: union([
|
|
150
|
-
literal('https://registry.npmjs.org'),
|
|
151
|
-
literal('https://registry.npmjs.org/')
|
|
152
|
-
])
|
|
153
|
-
})
|
|
154
|
-
}),
|
|
155
|
-
files: optional(SnapAuxilaryFilesStruct),
|
|
156
|
-
locales: optional(SnapAuxilaryFilesStruct)
|
|
157
|
-
}),
|
|
158
|
-
initialConnections: optional(InitialConnectionsStruct),
|
|
159
|
-
initialPermissions: PermissionsStruct,
|
|
160
|
-
manifestVersion: literal('0.1'),
|
|
161
|
-
$schema: optional(string())
|
|
162
|
-
});
|
|
163
|
-
/**
|
|
164
|
-
* Check if the given value is a valid {@link SnapManifest} object.
|
|
165
|
-
*
|
|
166
|
-
* @param value - The value to check.
|
|
167
|
-
* @returns Whether the value is a valid {@link SnapManifest} object.
|
|
168
|
-
*/ export function isSnapManifest(value) {
|
|
169
|
-
return is(value, SnapManifestStruct);
|
|
170
|
-
}
|
|
171
|
-
/**
|
|
172
|
-
* Assert that the given value is a valid {@link SnapManifest} object.
|
|
173
|
-
*
|
|
174
|
-
* @param value - The value to check.
|
|
175
|
-
* @throws If the value is not a valid {@link SnapManifest} object.
|
|
176
|
-
*/ export function assertIsSnapManifest(value) {
|
|
177
|
-
assertStruct(value, SnapManifestStruct, `"${NpmSnapFileNames.Manifest}" is invalid`);
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Creates a {@link SnapManifest} object from JSON.
|
|
181
|
-
*
|
|
182
|
-
* @param value - The value to check.
|
|
183
|
-
* @throws If the value cannot be coerced to a {@link SnapManifest} object.
|
|
184
|
-
* @returns The created {@link SnapManifest} object.
|
|
185
|
-
*/ export function createSnapManifest(value) {
|
|
186
|
-
// TODO: Add a utility to prefix these errors similar to assertStruct
|
|
187
|
-
return create(value, SnapManifestStruct);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
//# sourceMappingURL=validation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/manifest/validation.ts"],"sourcesContent":["import { isValidBIP32PathSegment } from '@metamask/key-tree';\nimport type { InitialPermissions } from '@metamask/snaps-sdk';\nimport {\n assertStruct,\n ChecksumStruct,\n VersionStruct,\n isValidSemVerRange,\n inMilliseconds,\n Duration,\n} from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n array,\n boolean,\n create,\n enums,\n integer,\n is,\n literal,\n object,\n optional,\n refine,\n record,\n size,\n string,\n type,\n union,\n intersection,\n assign,\n} from 'superstruct';\n\nimport { isEqual } from '../array';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { KeyringOriginsStruct, RpcOriginsStruct } from '../json-rpc';\nimport { ChainIdStruct } from '../namespace';\nimport { SnapIdStruct } from '../snaps';\nimport type { InferMatching } from '../structs';\nimport { NameStruct, NpmSnapFileNames, uri } from '../types';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nexport const FORBIDDEN_COIN_TYPES: number[] = [60];\nconst FORBIDDEN_PATHS: string[][] = FORBIDDEN_COIN_TYPES.map((coinType) => [\n 'm',\n \"44'\",\n `${coinType}'`,\n]);\n\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path: string[]) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !isValidBIP32PathSegment(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n if (\n FORBIDDEN_PATHS.some((forbiddenPath) =>\n isEqual(path.slice(0, forbiddenPath.length), forbiddenPath),\n )\n ) {\n return `The path \"${path.join(\n '/',\n )}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <\n Type extends { path: string[]; curve: string },\n Schema,\n>(\n struct: Struct<Type, Schema>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: enums(['ed25519', 'secp256k1']),\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\nexport const SemVerRangeStruct = refine(string(), 'SemVer range', (value) => {\n if (isValidSemVerRange(value)) {\n return true;\n }\n return 'Expected a valid SemVer range.';\n});\n\nexport const SnapIdsStruct = refine(\n record(SnapIdStruct, object({ version: optional(SemVerRangeStruct) })),\n 'SnapIds',\n (value) => {\n if (Object.keys(value).length === 0) {\n return false;\n }\n\n return true;\n },\n);\n\nexport type SnapIds = Infer<typeof SnapIdsStruct>;\n\nexport const ChainIdsStruct = size(array(ChainIdStruct), 1, Infinity);\n\nexport const LookupMatchersStruct = union([\n object({\n tlds: size(array(string()), 1, Infinity),\n }),\n object({\n schemes: size(array(string()), 1, Infinity),\n }),\n object({\n tlds: size(array(string()), 1, Infinity),\n schemes: size(array(string()), 1, Infinity),\n }),\n]);\n\nexport const MINIMUM_REQUEST_TIMEOUT = inMilliseconds(5, Duration.Second);\nexport const MAXIMUM_REQUEST_TIMEOUT = inMilliseconds(3, Duration.Minute);\n\nexport const MaxRequestTimeStruct = size(\n integer(),\n MINIMUM_REQUEST_TIMEOUT,\n MAXIMUM_REQUEST_TIMEOUT,\n);\n\n// Utility type to union with for all handler structs\nexport const HandlerCaveatsStruct = object({\n maxRequestTime: optional(MaxRequestTimeStruct),\n});\n\nexport type HandlerCaveats = Infer<typeof HandlerCaveatsStruct>;\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct = type({\n 'endowment:cronjob': optional(\n assign(\n HandlerCaveatsStruct,\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n ),\n 'endowment:ethereum-provider': optional(object({})),\n 'endowment:keyring': optional(\n assign(HandlerCaveatsStruct, KeyringOriginsStruct),\n ),\n 'endowment:lifecycle-hooks': optional(HandlerCaveatsStruct),\n 'endowment:name-lookup': optional(\n assign(\n HandlerCaveatsStruct,\n object({\n chains: optional(ChainIdsStruct),\n matchers: optional(LookupMatchersStruct),\n }),\n ),\n ),\n 'endowment:network-access': optional(object({})),\n 'endowment:page-home': optional(HandlerCaveatsStruct),\n 'endowment:rpc': optional(RpcOriginsStruct),\n 'endowment:signature-insight': optional(\n assign(\n HandlerCaveatsStruct,\n object({\n allowSignatureOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:transaction-insight': optional(\n assign(\n HandlerCaveatsStruct,\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:webassembly': optional(object({})),\n snap_dialog: optional(object({})),\n snap_manageState: optional(object({})),\n snap_manageAccounts: optional(object({})),\n snap_notify: optional(object({})),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(object({})),\n snap_getLocale: optional(object({})),\n wallet_snap: optional(SnapIdsStruct),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = InferMatching<\n typeof PermissionsStruct,\n InitialPermissions\n>;\n\nexport const SnapAuxilaryFilesStruct = array(string());\n\nexport const InitialConnectionsStruct = record(\n intersection([string(), uri()]),\n object({}),\n);\n\nexport type InitialConnections = Infer<typeof InitialConnectionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(string(), 1, 214),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: ChecksumStruct,\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n files: optional(SnapAuxilaryFilesStruct),\n locales: optional(SnapAuxilaryFilesStruct),\n }),\n initialConnections: optional(InitialConnectionsStruct),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n $schema: optional(string()), // enables JSON-Schema linting in VSC and other IDEs\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"],"names":["isValidBIP32PathSegment","assertStruct","ChecksumStruct","VersionStruct","isValidSemVerRange","inMilliseconds","Duration","array","boolean","create","enums","integer","is","literal","object","optional","refine","record","size","string","type","union","intersection","assign","isEqual","CronjobSpecificationArrayStruct","SIP_6_MAGIC_VALUE","STATE_ENCRYPTION_MAGIC_VALUE","KeyringOriginsStruct","RpcOriginsStruct","ChainIdStruct","SnapIdStruct","NameStruct","NpmSnapFileNames","uri","FORBIDDEN_PURPOSES","FORBIDDEN_COIN_TYPES","FORBIDDEN_PATHS","map","coinType","Bip32PathStruct","path","length","slice","some","part","includes","forbiddenPath","join","bip32entropy","struct","value","curve","endsWith","Bip32EntropyStruct","SnapGetBip32EntropyPermissionsStruct","Infinity","SemVerRangeStruct","SnapIdsStruct","version","Object","keys","ChainIdsStruct","LookupMatchersStruct","tlds","schemes","MINIMUM_REQUEST_TIMEOUT","Second","MAXIMUM_REQUEST_TIMEOUT","Minute","MaxRequestTimeStruct","HandlerCaveatsStruct","maxRequestTime","PermissionsStruct","jobs","chains","matchers","allowSignatureOrigin","allowTransactionOrigin","snap_dialog","snap_manageState","snap_manageAccounts","snap_notify","snap_getBip32Entropy","snap_getBip32PublicKey","snap_getBip44Entropy","snap_getEntropy","snap_getLocale","wallet_snap","SnapAuxilaryFilesStruct","InitialConnectionsStruct","SnapManifestStruct","description","proposedName","repository","url","source","shasum","location","npm","filePath","iconPath","packageName","registry","files","locales","initialConnections","initialPermissions","manifestVersion","$schema","isSnapManifest","assertIsSnapManifest","Manifest","createSnapManifest"],"mappings":"AAAA,SAASA,uBAAuB,QAAQ,qBAAqB;AAE7D,SACEC,YAAY,EACZC,cAAc,EACdC,aAAa,EACbC,kBAAkB,EAClBC,cAAc,EACdC,QAAQ,QACH,kBAAkB;AAEzB,SACEC,KAAK,EACLC,OAAO,EACPC,MAAM,EACNC,KAAK,EACLC,OAAO,EACPC,EAAE,EACFC,OAAO,EACPC,MAAM,EACNC,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 'crypto';
|
|
2
|
-
import EventEmitter from 'events';
|
|
3
|
-
import { DEFAULT_ENDOWMENTS } from './default-endowments';
|
|
4
|
-
const NETWORK_APIS = [
|
|
5
|
-
'fetch',
|
|
6
|
-
'Request',
|
|
7
|
-
'Headers',
|
|
8
|
-
'Response'
|
|
9
|
-
];
|
|
10
|
-
export const ALL_APIS = [
|
|
11
|
-
...DEFAULT_ENDOWMENTS,
|
|
12
|
-
...NETWORK_APIS,
|
|
13
|
-
'WebAssembly'
|
|
14
|
-
];
|
|
15
|
-
/**
|
|
16
|
-
* Get a mock snap API, that always returns `true` for requests.
|
|
17
|
-
*
|
|
18
|
-
* @returns A mocked snap provider.
|
|
19
|
-
*/ function getMockSnapGlobal() {
|
|
20
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
21
|
-
return {
|
|
22
|
-
request: async ()=>true
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Get a mock Ethereum provider, that always returns `true` for requests.
|
|
27
|
-
*
|
|
28
|
-
* @returns A mocked ethereum provider.
|
|
29
|
-
*/ function getMockEthereumProvider() {
|
|
30
|
-
const mockProvider = new EventEmitter();
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/require-await
|
|
32
|
-
mockProvider.request = async ()=>true;
|
|
33
|
-
return mockProvider;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Check if a value is a constructor.
|
|
37
|
-
*
|
|
38
|
-
* @param value - The value to check.
|
|
39
|
-
* @returns `true` if the value is a constructor, or `false` otherwise.
|
|
40
|
-
*/ export const isConstructor = (value)=>Boolean(typeof value?.prototype?.constructor?.name === 'string');
|
|
41
|
-
/**
|
|
42
|
-
* A function that always returns `true`.
|
|
43
|
-
*
|
|
44
|
-
* @returns `true`.
|
|
45
|
-
*/ const mockFunction = ()=>true;
|
|
46
|
-
class MockClass {
|
|
47
|
-
}
|
|
48
|
-
const handler = {
|
|
49
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
50
|
-
construct (Target, args) {
|
|
51
|
-
return new Proxy(new Target(...args), handler);
|
|
52
|
-
},
|
|
53
|
-
get (_target, _prop) {
|
|
54
|
-
return mockFunction;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
/**
|
|
58
|
-
* Generate a mock class for a given value. The value is wrapped in a Proxy, and
|
|
59
|
-
* all methods are replaced with a mock function.
|
|
60
|
-
*
|
|
61
|
-
* @param value - The value to mock.
|
|
62
|
-
* @returns A mock class.
|
|
63
|
-
*/ const generateMockClass = (value)=>{
|
|
64
|
-
return new Proxy(value, handler);
|
|
65
|
-
};
|
|
66
|
-
// Things not currently auto-mocked because of NodeJS, by adding them here we
|
|
67
|
-
// have types for them and can use that to generate mocks if needed.
|
|
68
|
-
const mockWindow = {
|
|
69
|
-
crypto,
|
|
70
|
-
SubtleCrypto: MockClass
|
|
71
|
-
};
|
|
72
|
-
/**
|
|
73
|
-
* Generate a mock endowment for a certain class or function on the `globalThis`
|
|
74
|
-
* object.
|
|
75
|
-
*
|
|
76
|
-
* @param key - The key to generate the mock endowment for.
|
|
77
|
-
* @returns A mocked class or function. If the key is part of the default
|
|
78
|
-
* endowments, the original value is returned.
|
|
79
|
-
*/ const generateMockEndowment = (key)=>{
|
|
80
|
-
const globalValue = globalThis[key];
|
|
81
|
-
// Default exposed APIs don't need to be mocked
|
|
82
|
-
if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {
|
|
83
|
-
return globalValue;
|
|
84
|
-
}
|
|
85
|
-
// Fall back to mockWindow for certain APIs not exposed in global in Node.JS
|
|
86
|
-
const globalOrMocked = globalValue ?? mockWindow[key];
|
|
87
|
-
const type = typeof globalOrMocked;
|
|
88
|
-
const isFunction = type === 'function';
|
|
89
|
-
if (isFunction && isConstructor(globalOrMocked)) {
|
|
90
|
-
return generateMockClass(globalOrMocked);
|
|
91
|
-
} else if (isFunction || !globalOrMocked) {
|
|
92
|
-
// Fall back to function mock for now
|
|
93
|
-
return mockFunction;
|
|
94
|
-
}
|
|
95
|
-
return globalOrMocked;
|
|
96
|
-
};
|
|
97
|
-
/**
|
|
98
|
-
* Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.
|
|
99
|
-
*
|
|
100
|
-
* @returns A map of endowments.
|
|
101
|
-
*/ export const generateMockEndowments = ()=>{
|
|
102
|
-
return ALL_APIS.reduce((acc, cur)=>({
|
|
103
|
-
...acc,
|
|
104
|
-
[cur]: generateMockEndowment(cur)
|
|
105
|
-
}), {
|
|
106
|
-
snap: getMockSnapGlobal(),
|
|
107
|
-
ethereum: getMockEthereumProvider()
|
|
108
|
-
});
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
//# sourceMappingURL=mock.js.map
|
package/dist/esm/mock.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/mock.ts"],"sourcesContent":["import crypto from 'crypto';\nimport EventEmitter from 'events';\n\nimport { DEFAULT_ENDOWMENTS } from './default-endowments';\n\nconst NETWORK_APIS = ['fetch', 'Request', 'Headers', 'Response'];\n\nexport const ALL_APIS: string[] = [\n ...DEFAULT_ENDOWMENTS,\n ...NETWORK_APIS,\n 'WebAssembly',\n];\n\ntype MockSnapGlobal = {\n request: () => Promise<any>;\n};\n\ntype MockEthereumProvider = EventEmitter & {\n request: () => Promise<any>;\n};\n\n/**\n * Get a mock snap API, that always returns `true` for requests.\n *\n * @returns A mocked snap provider.\n */\nfunction getMockSnapGlobal(): MockSnapGlobal {\n // eslint-disable-next-line @typescript-eslint/require-await\n return { request: async () => true };\n}\n\n/**\n * Get a mock Ethereum provider, that always returns `true` for requests.\n *\n * @returns A mocked ethereum provider.\n */\nfunction getMockEthereumProvider(): MockEthereumProvider {\n const mockProvider = new EventEmitter() as Partial<MockEthereumProvider>;\n // eslint-disable-next-line @typescript-eslint/require-await\n mockProvider.request = async () => true;\n return mockProvider as MockEthereumProvider;\n}\n\n/**\n * Check if a value is a constructor.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nexport const isConstructor = (value: any) =>\n Boolean(typeof value?.prototype?.constructor?.name === 'string');\n\n/**\n * A function that always returns `true`.\n *\n * @returns `true`.\n */\nconst mockFunction = () => true;\nclass MockClass {}\n\nconst handler = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n construct(Target: any, args: any[]): any {\n return new Proxy(new Target(...args), handler);\n },\n get(_target: any, _prop: any) {\n return mockFunction;\n },\n};\n\n/**\n * Generate a mock class for a given value. The value is wrapped in a Proxy, and\n * all methods are replaced with a mock function.\n *\n * @param value - The value to mock.\n * @returns A mock class.\n */\nconst generateMockClass = (value: any) => {\n return new Proxy(value, handler);\n};\n\n// Things not currently auto-mocked because of NodeJS, by adding them here we\n// have types for them and can use that to generate mocks if needed.\nconst mockWindow: Record<string, unknown> = {\n crypto,\n SubtleCrypto: MockClass,\n};\n\n/**\n * Generate a mock endowment for a certain class or function on the `globalThis`\n * object.\n *\n * @param key - The key to generate the mock endowment for.\n * @returns A mocked class or function. If the key is part of the default\n * endowments, the original value is returned.\n */\nconst generateMockEndowment = (key: string) => {\n const globalValue = (globalThis as any)[key];\n\n // Default exposed APIs don't need to be mocked\n if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {\n return globalValue;\n }\n\n // Fall back to mockWindow for certain APIs not exposed in global in Node.JS\n const globalOrMocked = globalValue ?? mockWindow[key];\n\n const type = typeof globalOrMocked;\n const isFunction = type === 'function';\n if (isFunction && isConstructor(globalOrMocked)) {\n return generateMockClass(globalOrMocked);\n } else if (isFunction || !globalOrMocked) {\n // Fall back to function mock for now\n return mockFunction;\n }\n return globalOrMocked;\n};\n\n/**\n * Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.\n *\n * @returns A map of endowments.\n */\nexport const generateMockEndowments = () => {\n return ALL_APIS.reduce<Record<string, any>>(\n (acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),\n { snap: getMockSnapGlobal(), ethereum: getMockEthereumProvider() },\n );\n};\n"],"names":["crypto","EventEmitter","DEFAULT_ENDOWMENTS","NETWORK_APIS","ALL_APIS","getMockSnapGlobal","request","getMockEthereumProvider","mockProvider","isConstructor","value","Boolean","prototype","constructor","name","mockFunction","MockClass","handler","construct","Target","args","Proxy","get","_target","_prop","generateMockClass","mockWindow","SubtleCrypto","generateMockEndowment","key","globalValue","globalThis","includes","globalOrMocked","type","isFunction","generateMockEndowments","reduce","acc","cur","snap","ethereum"],"mappings":"AAAA,OAAOA,YAAY,SAAS;AAC5B,OAAOC,kBAAkB,SAAS;AAElC,SAASC,kBAAkB,QAAQ,uBAAuB;AAE1D,MAAMC,eAAe;IAAC;IAAS;IAAW;IAAW;CAAW;AAEhE,OAAO,MAAMC,WAAqB;OAC7BF;OACAC;IACH;CACD,CAAC;AAUF;;;;CAIC,GACD,SAASE;IACP,4DAA4D;IAC5D,OAAO;QAAEC,SAAS,UAAY;IAAK;AACrC;AAEA;;;;CAIC,GACD,SAASC;IACP,MAAMC,eAAe,IAAIP;IACzB,4DAA4D;IAC5DO,aAAaF,OAAO,GAAG,UAAY;IACnC,OAAOE;AACT;AAEA;;;;;CAKC,GACD,OAAO,MAAMC,gBAAgB,CAACC,QAC5BC,QAAQ,OAAOD,OAAOE,WAAWC,aAAaC,SAAS,UAAU;AAEnE;;;;CAIC,GACD,MAAMC,eAAe,IAAM;AAC3B,MAAMC;AAAW;AAEjB,MAAMC,UAAU;IACd,gEAAgE;IAChEC,WAAUC,MAAW,EAAEC,IAAW;QAChC,OAAO,IAAIC,MAAM,IAAIF,UAAUC,OAAOH;IACxC;IACAK,KAAIC,OAAY,EAAEC,KAAU;QAC1B,OAAOT;IACT;AACF;AAEA;;;;;;CAMC,GACD,MAAMU,oBAAoB,CAACf;IACzB,OAAO,IAAIW,MAAMX,OAAOO;AAC1B;AAEA,6EAA6E;AAC7E,oEAAoE;AACpE,MAAMS,aAAsC;IAC1C1B;IACA2B,cAAcX;AAChB;AAEA;;;;;;;CAOC,GACD,MAAMY,wBAAwB,CAACC;IAC7B,MAAMC,cAAc,AAACC,UAAkB,CAACF,IAAI;IAE5C,+CAA+C;IAC/C,IAAIC,eAAe5B,mBAAmB8B,QAAQ,CAACH,MAAM;QACnD,OAAOC;IACT;IAEA,4EAA4E;IAC5E,MAAMG,iBAAiBH,eAAeJ,UAAU,CAACG,IAAI;IAErD,MAAMK,OAAO,OAAOD;IACpB,MAAME,aAAaD,SAAS;IAC5B,IAAIC,cAAc1B,cAAcwB,iBAAiB;QAC/C,OAAOR,kBAAkBQ;IAC3B,OAAO,IAAIE,cAAc,CAACF,gBAAgB;QACxC,qCAAqC;QACrC,OAAOlB;IACT;IACA,OAAOkB;AACT;AAEA;;;;CAIC,GACD,OAAO,MAAMG,yBAAyB;IACpC,OAAOhC,SAASiC,MAAM,CACpB,CAACC,KAAKC,MAAS,CAAA;YAAE,GAAGD,GAAG;YAAE,CAACC,IAAI,EAAEX,sBAAsBW;QAAK,CAAA,GAC3D;QAAEC,MAAMnC;QAAqBoC,UAAUlC;IAA0B;AAErE,EAAE"}
|
package/dist/esm/namespace.js
DELETED
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
import { array, define, is, object, optional, pattern, size, string } from 'superstruct';
|
|
2
|
-
export const CHAIN_ID_REGEX = RegExp("^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$", "u");
|
|
3
|
-
export const ACCOUNT_ID_REGEX = RegExp("^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})):(?<accountAddress>[a-zA-Z0-9]{1,64})$", "u");
|
|
4
|
-
export const ACCOUNT_ADDRESS_REGEX = RegExp("^(?<accountAddress>[a-zA-Z0-9]{1,64})$", "u");
|
|
5
|
-
/**
|
|
6
|
-
* Parse a chain ID string to an object containing the namespace and reference.
|
|
7
|
-
* This validates the chain ID before parsing it.
|
|
8
|
-
*
|
|
9
|
-
* @param chainId - The chain ID to validate and parse.
|
|
10
|
-
* @returns The parsed chain ID.
|
|
11
|
-
*/ export function parseChainId(chainId) {
|
|
12
|
-
const match = CHAIN_ID_REGEX.exec(chainId);
|
|
13
|
-
if (!match?.groups) {
|
|
14
|
-
throw new Error('Invalid chain ID.');
|
|
15
|
-
}
|
|
16
|
-
return {
|
|
17
|
-
namespace: match.groups.namespace,
|
|
18
|
-
reference: match.groups.reference
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Parse an account ID to an object containing the chain, chain ID and address.
|
|
23
|
-
* This validates the account ID before parsing it.
|
|
24
|
-
*
|
|
25
|
-
* @param accountId - The account ID to validate and parse.
|
|
26
|
-
* @returns The parsed account ID.
|
|
27
|
-
*/ export function parseAccountId(accountId) {
|
|
28
|
-
const match = ACCOUNT_ID_REGEX.exec(accountId);
|
|
29
|
-
if (!match?.groups) {
|
|
30
|
-
throw new Error('Invalid account ID.');
|
|
31
|
-
}
|
|
32
|
-
return {
|
|
33
|
-
address: match.groups.accountAddress,
|
|
34
|
-
chainId: match.groups.chainId,
|
|
35
|
-
chain: {
|
|
36
|
-
namespace: match.groups.namespace,
|
|
37
|
-
reference: match.groups.reference
|
|
38
|
-
}
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* A helper struct for a string with a minimum length of 1 and a maximum length
|
|
43
|
-
* of 40.
|
|
44
|
-
*/ export const LimitedString = size(string(), 1, 40);
|
|
45
|
-
export const ChainIdStringStruct = define('Chain ID', string().validator);
|
|
46
|
-
/**
|
|
47
|
-
* A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
|
|
48
|
-
*/ export const ChainIdStruct = pattern(ChainIdStringStruct, CHAIN_ID_REGEX);
|
|
49
|
-
export const AccountIdStruct = pattern(string(), ACCOUNT_ID_REGEX);
|
|
50
|
-
export const AccountIdArrayStruct = array(AccountIdStruct);
|
|
51
|
-
export const AccountAddressStruct = pattern(string(), ACCOUNT_ADDRESS_REGEX);
|
|
52
|
-
/**
|
|
53
|
-
* A chain descriptor.
|
|
54
|
-
*/ export const ChainStruct = object({
|
|
55
|
-
id: ChainIdStruct,
|
|
56
|
-
name: LimitedString
|
|
57
|
-
});
|
|
58
|
-
export const NamespaceStruct = object({
|
|
59
|
-
/**
|
|
60
|
-
* A list of supported chains in the namespace.
|
|
61
|
-
*/ chains: array(ChainStruct),
|
|
62
|
-
/**
|
|
63
|
-
* A list of supported RPC methods on the namespace, that a DApp can call.
|
|
64
|
-
*/ methods: optional(array(LimitedString)),
|
|
65
|
-
/**
|
|
66
|
-
* A list of supported RPC events on the namespace, that a DApp can listen to.
|
|
67
|
-
*/ events: optional(array(LimitedString))
|
|
68
|
-
});
|
|
69
|
-
/**
|
|
70
|
-
* A CAIP-2 namespace, i.e., the first part of a chain ID.
|
|
71
|
-
*/ export const NamespaceIdStruct = pattern(string(), /^[-a-z0-9]{3,8}$/u);
|
|
72
|
-
/**
|
|
73
|
-
* Check if the given value is a CAIP-2 namespace ID.
|
|
74
|
-
*
|
|
75
|
-
* @param value - The value to check.
|
|
76
|
-
* @returns Whether the value is a CAIP-2 namespace ID.
|
|
77
|
-
*/ export function isNamespaceId(value) {
|
|
78
|
-
return is(value, NamespaceIdStruct);
|
|
79
|
-
}
|
|
80
|
-
/**
|
|
81
|
-
* Check if the given value is a CAIP-2 chain ID.
|
|
82
|
-
*
|
|
83
|
-
* @param value - The value to check.
|
|
84
|
-
* @returns Whether the value is a CAIP-2 chain ID.
|
|
85
|
-
*/ export function isChainId(value) {
|
|
86
|
-
return is(value, ChainIdStruct);
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Check if the given value is a CAIP-10 account ID.
|
|
90
|
-
*
|
|
91
|
-
* @param value - The value to check.
|
|
92
|
-
* @returns Whether the value is a CAIP-10 account ID.
|
|
93
|
-
*/ export function isAccountId(value) {
|
|
94
|
-
return is(value, AccountIdStruct);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* Check if the given value is an array of CAIP-10 account IDs.
|
|
98
|
-
*
|
|
99
|
-
* @param value - The value to check.
|
|
100
|
-
* @returns Whether the value is an array of CAIP-10 account IDs.
|
|
101
|
-
*/ export function isAccountIdArray(value) {
|
|
102
|
-
return is(value, AccountIdArrayStruct);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Check if a value is a {@link Namespace}.
|
|
106
|
-
*
|
|
107
|
-
* @param value - The value to validate.
|
|
108
|
-
* @returns True if the value is a valid {@link Namespace}.
|
|
109
|
-
*/ export function isNamespace(value) {
|
|
110
|
-
return is(value, NamespaceStruct);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
//# sourceMappingURL=namespace.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/namespace.ts"],"sourcesContent":["import type { AccountId, ChainId } from '@metamask/snaps-sdk';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n define,\n is,\n object,\n optional,\n pattern,\n size,\n string,\n} from 'superstruct';\n\nimport type { InferMatching } from './structs';\n\nexport const CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u;\n\nexport const ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})):(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;\n\nexport const ACCOUNT_ADDRESS_REGEX = /^(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;\n\n/**\n * Parse a chain ID string to an object containing the namespace and reference.\n * This validates the chain ID before parsing it.\n *\n * @param chainId - The chain ID to validate and parse.\n * @returns The parsed chain ID.\n */\nexport function parseChainId(chainId: ChainId): {\n namespace: NamespaceId;\n reference: string;\n} {\n const match = CHAIN_ID_REGEX.exec(chainId);\n if (!match?.groups) {\n throw new Error('Invalid chain ID.');\n }\n\n return {\n namespace: match.groups.namespace,\n reference: match.groups.reference,\n };\n}\n\n/**\n * Parse an account ID to an object containing the chain, chain ID and address.\n * This validates the account ID before parsing it.\n *\n * @param accountId - The account ID to validate and parse.\n * @returns The parsed account ID.\n */\nexport function parseAccountId(accountId: AccountId): {\n chain: { namespace: NamespaceId; reference: string };\n chainId: ChainId;\n address: string;\n} {\n const match = ACCOUNT_ID_REGEX.exec(accountId);\n if (!match?.groups) {\n throw new Error('Invalid account ID.');\n }\n\n return {\n address: match.groups.accountAddress,\n chainId: match.groups.chainId as ChainId,\n chain: {\n namespace: match.groups.namespace,\n reference: match.groups.reference,\n },\n };\n}\n\n/**\n * A helper struct for a string with a minimum length of 1 and a maximum length\n * of 40.\n */\nexport const LimitedString = size(string(), 1, 40);\n\nexport const ChainIdStringStruct = define<ChainId>(\n 'Chain ID',\n string().validator,\n);\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const ChainIdStruct = pattern<ChainId, null>(\n ChainIdStringStruct,\n CHAIN_ID_REGEX,\n);\n\nexport type Caip2ChainId = InferMatching<typeof ChainIdStruct, ChainId>;\n\nexport const AccountIdStruct = pattern(string(), ACCOUNT_ID_REGEX);\n\nexport const AccountIdArrayStruct = array(AccountIdStruct);\nexport const AccountAddressStruct = pattern(string(), ACCOUNT_ADDRESS_REGEX);\nexport type AccountAddress = Infer<typeof AccountAddressStruct>;\n\n/**\n * A chain descriptor.\n */\nexport const ChainStruct = object({\n id: ChainIdStruct,\n name: LimitedString,\n});\nexport type Chain = Infer<typeof ChainStruct>;\n\nexport const NamespaceStruct = object({\n /**\n * A list of supported chains in the namespace.\n */\n chains: array(ChainStruct),\n\n /**\n * A list of supported RPC methods on the namespace, that a DApp can call.\n */\n methods: optional(array(LimitedString)),\n\n /**\n * A list of supported RPC events on the namespace, that a DApp can listen to.\n */\n events: optional(array(LimitedString)),\n});\nexport type Namespace = Infer<typeof NamespaceStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a chain ID.\n */\nexport const NamespaceIdStruct = pattern(string(), /^[-a-z0-9]{3,8}$/u);\nexport type NamespaceId = Infer<typeof NamespaceIdStruct>;\n\n/**\n * Check if the given value is a CAIP-2 namespace ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-2 namespace ID.\n */\nexport function isNamespaceId(value: unknown): value is NamespaceId {\n return is(value, NamespaceIdStruct);\n}\n\n/**\n * Check if the given value is a CAIP-2 chain ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-2 chain ID.\n */\nexport function isChainId(value: unknown): value is ChainId {\n return is(value, ChainIdStruct);\n}\n\n/**\n * Check if the given value is a CAIP-10 account ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-10 account ID.\n */\nexport function isAccountId(value: unknown): value is AccountId {\n return is(value, AccountIdStruct);\n}\n\n/**\n * Check if the given value is an array of CAIP-10 account IDs.\n *\n * @param value - The value to check.\n * @returns Whether the value is an array of CAIP-10 account IDs.\n */\nexport function isAccountIdArray(value: unknown): value is AccountId[] {\n return is(value, AccountIdArrayStruct);\n}\n\n/**\n * Check if a value is a {@link Namespace}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link Namespace}.\n */\nexport function isNamespace(value: unknown): value is Namespace {\n return is(value, NamespaceStruct);\n}\n"],"names":["array","define","is","object","optional","pattern","size","string","CHAIN_ID_REGEX","ACCOUNT_ID_REGEX","ACCOUNT_ADDRESS_REGEX","parseChainId","chainId","match","exec","groups","Error","namespace","reference","parseAccountId","accountId","address","accountAddress","chain","LimitedString","ChainIdStringStruct","validator","ChainIdStruct","AccountIdStruct","AccountIdArrayStruct","AccountAddressStruct","ChainStruct","id","name","NamespaceStruct","chains","methods","events","NamespaceIdStruct","isNamespaceId","value","isChainId","isAccountId","isAccountIdArray","isNamespace"],"mappings":"AAEA,SACEA,KAAK,EACLC,MAAM,EACNC,EAAE,EACFC,MAAM,EACNC,QAAQ,EACRC,OAAO,EACPC,IAAI,EACJC,MAAM,QACD,cAAc;AAIrB,OAAO,MAAMC,iBACX,+EAAmE;AAErE,OAAO,MAAM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ACDa,QAAQjC,SAASJ,MAAMwB;AACzB,GAAG;AAGH;;CAEC,GACD,OAAO,MAAMc,oBAAoBjC,QAAQE,UAAU,qBAAqB;AAGxE;;;;;CAKC,GACD,OAAO,SAASgC,cAAcC,KAAc;IAC1C,OAAOtC,GAAGsC,OAAOF;AACnB;AAEA;;;;;CAKC,GACD,OAAO,SAASG,UAAUD,KAAc;IACtC,OAAOtC,GAAGsC,OAAOb;AACnB;AAEA;;;;;CAKC,GACD,OAAO,SAASe,YAAYF,KAAc;IACxC,OAAOtC,GAAGsC,OAAOZ;AACnB;AAEA;;;;;CAKC,GACD,OAAO,SAASe,iBAAiBH,KAAc;IAC7C,OAAOtC,GAAGsC,OAAOX;AACnB;AAEA;;;;;CAKC,GACD,OAAO,SAASe,YAAYJ,KAAc;IACxC,OAAOtC,GAAGsC,OAAON;AACnB"}
|
package/dist/esm/npm.js
DELETED
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { assertIsSnapIcon } from './icon';
|
|
2
|
-
import { getValidatedLocalizationFiles, validateSnapManifestLocalizations } from './localization';
|
|
3
|
-
import { validateNpmSnapManifest } from './manifest/manifest';
|
|
4
|
-
import { assertIsSnapManifest } from './manifest/validation';
|
|
5
|
-
import { assertIsNpmSnapPackageJson, NpmSnapFileNames } from './types';
|
|
6
|
-
export const EXPECTED_SNAP_FILES = [
|
|
7
|
-
'manifest',
|
|
8
|
-
'packageJson',
|
|
9
|
-
'sourceCode'
|
|
10
|
-
];
|
|
11
|
-
export const SnapFileNameFromKey = {
|
|
12
|
-
manifest: NpmSnapFileNames.Manifest,
|
|
13
|
-
packageJson: NpmSnapFileNames.PackageJson,
|
|
14
|
-
sourceCode: 'source code bundle'
|
|
15
|
-
};
|
|
16
|
-
// TODO: Refactor this to be more shared with other validation.
|
|
17
|
-
/**
|
|
18
|
-
* Validates the files extracted from an npm Snap package tarball by ensuring
|
|
19
|
-
* that they're non-empty and that the Json files match their respective schemas
|
|
20
|
-
* and the Snaps publishing specification.
|
|
21
|
-
*
|
|
22
|
-
* @param snapFiles - The object containing the expected Snap file contents,
|
|
23
|
-
* if any.
|
|
24
|
-
* @param errorPrefix - The prefix of the error message.
|
|
25
|
-
* @returns A tuple of the Snap manifest object and the Snap source code.
|
|
26
|
-
*/ export async function validateNpmSnap(snapFiles, errorPrefix) {
|
|
27
|
-
EXPECTED_SNAP_FILES.forEach((key)=>{
|
|
28
|
-
if (!snapFiles[key]) {
|
|
29
|
-
throw new Error(`${errorPrefix ?? ''}Missing file "${SnapFileNameFromKey[key]}".`);
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
// Typecast: We are assured that the required files exist if we get here.
|
|
33
|
-
const { manifest, packageJson, sourceCode, svgIcon, auxiliaryFiles, localizationFiles } = snapFiles;
|
|
34
|
-
try {
|
|
35
|
-
assertIsSnapManifest(manifest.result);
|
|
36
|
-
} catch (error) {
|
|
37
|
-
throw new Error(`${errorPrefix ?? ''}${error.message}`);
|
|
38
|
-
}
|
|
39
|
-
const validatedManifest = manifest;
|
|
40
|
-
const { iconPath } = validatedManifest.result.source.location.npm;
|
|
41
|
-
if (iconPath && !svgIcon) {
|
|
42
|
-
throw new Error(`Missing file "${iconPath}".`);
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
assertIsNpmSnapPackageJson(packageJson.result);
|
|
46
|
-
} catch (error) {
|
|
47
|
-
throw new Error(`${errorPrefix ?? ''}${error.message}`);
|
|
48
|
-
}
|
|
49
|
-
const validatedPackageJson = packageJson;
|
|
50
|
-
await validateNpmSnapManifest({
|
|
51
|
-
manifest: validatedManifest,
|
|
52
|
-
packageJson: validatedPackageJson,
|
|
53
|
-
sourceCode,
|
|
54
|
-
svgIcon,
|
|
55
|
-
auxiliaryFiles,
|
|
56
|
-
localizationFiles
|
|
57
|
-
});
|
|
58
|
-
if (svgIcon) {
|
|
59
|
-
try {
|
|
60
|
-
assertIsSnapIcon(svgIcon);
|
|
61
|
-
} catch (error) {
|
|
62
|
-
throw new Error(`${errorPrefix ?? ''}${error.message}`);
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (localizationFiles) {
|
|
66
|
-
try {
|
|
67
|
-
// This function validates and returns the localization files. We don't
|
|
68
|
-
// use the return value here, but we do want to validate the files.
|
|
69
|
-
getValidatedLocalizationFiles(localizationFiles);
|
|
70
|
-
validateSnapManifestLocalizations(manifest.result, localizationFiles.map((file)=>file.result));
|
|
71
|
-
} catch (error) {
|
|
72
|
-
throw new Error(`${errorPrefix ?? ''}${error.message}`);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
manifest: validatedManifest,
|
|
77
|
-
packageJson: validatedPackageJson,
|
|
78
|
-
sourceCode,
|
|
79
|
-
svgIcon,
|
|
80
|
-
auxiliaryFiles,
|
|
81
|
-
localizationFiles
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
//# sourceMappingURL=npm.js.map
|
package/dist/esm/npm.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/npm.ts"],"sourcesContent":["import { assertIsSnapIcon } from './icon';\nimport {\n getValidatedLocalizationFiles,\n validateSnapManifestLocalizations,\n} from './localization';\nimport { validateNpmSnapManifest } from './manifest/manifest';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport type { SnapFiles, UnvalidatedSnapFiles } from './types';\nimport { assertIsNpmSnapPackageJson, NpmSnapFileNames } from './types';\n\nexport const EXPECTED_SNAP_FILES = [\n 'manifest',\n 'packageJson',\n 'sourceCode',\n] as const;\n\nexport const SnapFileNameFromKey = {\n manifest: NpmSnapFileNames.Manifest,\n packageJson: NpmSnapFileNames.PackageJson,\n sourceCode: 'source code bundle',\n} as const;\n\n// TODO: Refactor this to be more shared with other validation.\n\n/**\n * Validates the files extracted from an npm Snap package tarball by ensuring\n * that they're non-empty and that the Json files match their respective schemas\n * and the Snaps publishing specification.\n *\n * @param snapFiles - The object containing the expected Snap file contents,\n * if any.\n * @param errorPrefix - The prefix of the error message.\n * @returns A tuple of the Snap manifest object and the Snap source code.\n */\nexport async function validateNpmSnap(\n snapFiles: UnvalidatedSnapFiles,\n errorPrefix?: `${string}: `,\n): Promise<SnapFiles> {\n EXPECTED_SNAP_FILES.forEach((key) => {\n if (!snapFiles[key]) {\n throw new Error(\n `${errorPrefix ?? ''}Missing file \"${SnapFileNameFromKey[key]}\".`,\n );\n }\n });\n\n // Typecast: We are assured that the required files exist if we get here.\n const {\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n } = snapFiles as SnapFiles;\n\n try {\n assertIsSnapManifest(manifest.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n const validatedManifest = manifest;\n\n const { iconPath } = validatedManifest.result.source.location.npm;\n if (iconPath && !svgIcon) {\n throw new Error(`Missing file \"${iconPath}\".`);\n }\n\n try {\n assertIsNpmSnapPackageJson(packageJson.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n\n const validatedPackageJson = packageJson;\n await validateNpmSnapManifest({\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n });\n\n if (svgIcon) {\n try {\n assertIsSnapIcon(svgIcon);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n }\n\n if (localizationFiles) {\n try {\n // This function validates and returns the localization files. We don't\n // use the return value here, but we do want to validate the files.\n getValidatedLocalizationFiles(localizationFiles);\n\n validateSnapManifestLocalizations(\n manifest.result,\n localizationFiles.map((file) => file.result),\n );\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n }\n\n return {\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n };\n}\n"],"names":["assertIsSnapIcon","getValidatedLocalizationFiles","validateSnapManifestLocalizations","validateNpmSnapManifest","assertIsSnapManifest","assertIsNpmSnapPackageJson","NpmSnapFileNames","EXPECTED_SNAP_FILES","SnapFileNameFromKey","manifest","Manifest","packageJson","PackageJson","sourceCode","validateNpmSnap","snapFiles","errorPrefix","forEach","key","Error","svgIcon","auxiliaryFiles","localizationFiles","result","error","message","validatedManifest","iconPath","source","location","npm","validatedPackageJson","map","file"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,SAAS;AAC1C,SACEC,6BAA6B,EAC7BC,iCAAiC,QAC5B,iBAAiB;AACxB,SAASC,uBAAuB,QAAQ,sBAAsB;AAC9D,SAASC,oBAAoB,QAAQ,wBAAwB;AAE7D,SAASC,0BAA0B,EAAEC,gBAAgB,QAAQ,UAAU;AAEvE,OAAO,MAAMC,sBAAsB;IACjC;IACA;IACA;CACD,CAAU;AAEX,OAAO,MAAMC,sBAAsB;IACjCC,UAAUH,iBAAiBI,QAAQ;IACnCC,aAAaL,iBAAiBM,WAAW;IACzCC,YAAY;AACd,EAAW;AAEX,+DAA+D;AAE/D;;;;;;;;;CASC,GACD,OAAO,eAAeC,gBACpBC,SAA+B,EAC/BC,WAA2B;IAE3BT,oBAAoBU,OAAO,CAAC,CAACC;QAC3B,IAAI,CAACH,SAAS,CAACG,IAAI,EAAE;YACnB,MAAM,IAAIC,MACR,CAAC,EAAEH,eAAe,GAAG,cAAc,EAAER,mBAAmB,CAACU,IAAI,CAAC,EAAE,CAAC;QAErE;IACF;IAEA,yEAAyE;IACzE,MAAM,EACJT,QAAQ,EACRE,WAAW,EACXE,UAAU,EACVO,OAAO,EACPC,cAAc,EACdC,iBAAiB,EAClB,GAAGP;IAEJ,IAAI;QACFX,qBAAqBK,SAASc,MAAM;IACtC,EAAE,OAAOC,OAAO;QACd,MAAM,IAAIL,MAAM,CAAC,EAAEH,eAAe,GAAG,EAAEQ,MAAMC,OAAO,CAAC,CAAC;IACxD;IACA,MAAMC,oBAAoBjB;IAE1B,MAAM,EAAEkB,QAAQ,EAAE,GAAGD,k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