@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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/manifest.ts","../src/npm.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 { getSvgDimensions } from '../icon';\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/node';\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 (!snapFiles.svgIcon) {\n warnings.push(\n 'No icon found in the Snap manifest. It is recommended to include an icon for the Snap. See https://docs.metamask.io/snaps/how-to/design-a-snap/#guidelines-at-a-glance for more information.',\n );\n }\n\n const iconDimensions =\n snapFiles.svgIcon && getSvgDimensions(snapFiles.svgIcon.toString());\n if (iconDimensions && iconDimensions.height !== iconDimensions.width) {\n warnings.push(\n 'The icon in the Snap manifest is not square. It is recommended to use a square icon for the Snap.',\n );\n }\n\n 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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,uBAAuB;AAEhC,SAAS,kBAAkB,QAAQ,qBAAqB;AACxD,OAAO,eAAe;AACtB,SAAS,YAAY,UAAU;AAC/B,OAAO,eAAe;AAgBtB,IAAM,sBAA0D;AAAA,EAC9D,SAAS;AAAA,EACT,SAAS;AAAA,EACT,aAAa;AAAA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AAEA,SAAO;AAAA,IACL,UAAU;AAAA,IACV,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["manifest"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";//# sourceMappingURL=chunk-YF4PGFCO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// src/cronjob.ts
|
|
2
|
+
import {
|
|
3
|
+
JsonRpcIdStruct,
|
|
4
|
+
JsonRpcParamsStruct,
|
|
5
|
+
JsonRpcVersionStruct
|
|
6
|
+
} from "@metamask/utils";
|
|
7
|
+
import { parseExpression } from "cron-parser";
|
|
8
|
+
import { array, create, object, optional, refine, string } from "superstruct";
|
|
9
|
+
var CronjobRpcRequestStruct = object({
|
|
10
|
+
jsonrpc: optional(JsonRpcVersionStruct),
|
|
11
|
+
id: optional(JsonRpcIdStruct),
|
|
12
|
+
method: string(),
|
|
13
|
+
params: optional(JsonRpcParamsStruct)
|
|
14
|
+
});
|
|
15
|
+
var CronExpressionStruct = refine(
|
|
16
|
+
string(),
|
|
17
|
+
"CronExpression",
|
|
18
|
+
(value) => {
|
|
19
|
+
try {
|
|
20
|
+
parseExpression(value);
|
|
21
|
+
return true;
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
function parseCronExpression(expression) {
|
|
28
|
+
const ensureStringExpression = create(expression, CronExpressionStruct);
|
|
29
|
+
return parseExpression(ensureStringExpression);
|
|
30
|
+
}
|
|
31
|
+
var CronjobSpecificationStruct = object({
|
|
32
|
+
expression: CronExpressionStruct,
|
|
33
|
+
request: CronjobRpcRequestStruct
|
|
34
|
+
});
|
|
35
|
+
function isCronjobSpecification(value) {
|
|
36
|
+
try {
|
|
37
|
+
create(value, CronjobSpecificationStruct);
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var CronjobSpecificationArrayStruct = array(
|
|
44
|
+
CronjobSpecificationStruct
|
|
45
|
+
);
|
|
46
|
+
function isCronjobSpecificationArray(value) {
|
|
47
|
+
try {
|
|
48
|
+
create(value, CronjobSpecificationArrayStruct);
|
|
49
|
+
return true;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
CronjobRpcRequestStruct,
|
|
57
|
+
CronExpressionStruct,
|
|
58
|
+
parseCronExpression,
|
|
59
|
+
CronjobSpecificationStruct,
|
|
60
|
+
isCronjobSpecification,
|
|
61
|
+
CronjobSpecificationArrayStruct,
|
|
62
|
+
isCronjobSpecificationArray
|
|
63
|
+
};
|
|
64
|
+
//# sourceMappingURL=chunk-YLT6CNSL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cronjob.ts"],"sourcesContent":["import {\n JsonRpcIdStruct,\n JsonRpcParamsStruct,\n JsonRpcVersionStruct,\n} from '@metamask/utils';\nimport { parseExpression } from 'cron-parser';\nimport type { Infer } from 'superstruct';\nimport { array, create, object, optional, refine, string } from 'superstruct';\n\nexport const CronjobRpcRequestStruct = object({\n jsonrpc: optional(JsonRpcVersionStruct),\n id: optional(JsonRpcIdStruct),\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;\n\nexport const CronExpressionStruct = refine(\n string(),\n 'CronExpression',\n (value) => {\n try {\n parseExpression(value);\n return true;\n } catch {\n return false;\n }\n },\n);\n\nexport type CronExpression = Infer<typeof CronExpressionStruct>;\n\n/**\n * Parses a cron expression.\n *\n * @param expression - Expression to parse.\n * @returns A CronExpression class instance.\n */\nexport function parseCronExpression(expression: string | object) {\n const ensureStringExpression = create(expression, CronExpressionStruct);\n return parseExpression(ensureStringExpression);\n}\n\nexport const CronjobSpecificationStruct = object({\n expression: CronExpressionStruct,\n request: CronjobRpcRequestStruct,\n});\nexport type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;\n\n/**\n * Check if the given value is a {@link CronjobSpecification} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link CronjobSpecification} object.\n */\nexport function isCronjobSpecification(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationStruct);\n return true;\n } catch {\n return false;\n }\n}\n\nexport const CronjobSpecificationArrayStruct = array(\n CronjobSpecificationStruct,\n);\n\n/**\n * Check if the given value is an array of {@link CronjobSpecification} objects.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid array of {@link CronjobSpecification} objects.\n */\nexport function isCronjobSpecificationArray(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationArrayStruct);\n return true;\n } catch {\n return false;\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAEhC,SAAS,OAAO,QAAQ,QAAQ,UAAU,QAAQ,cAAc;AAEzD,IAAM,0BAA0B,OAAO;AAAA,EAC5C,SAAS,SAAS,oBAAoB;AAAA,EACtC,IAAI,SAAS,eAAe;AAAA,EAC5B,QAAQ,OAAO;AAAA,EACf,QAAQ,SAAS,mBAAmB;AACtC,CAAC;AAIM,IAAM,uBAAuB;AAAA,EAClC,OAAO;AAAA,EACP;AAAA,EACA,CAAC,UAAU;AACT,QAAI;AACF,sBAAgB,KAAK;AACrB,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAUO,SAAS,oBAAoB,YAA6B;AAC/D,QAAM,yBAAyB,OAAO,YAAY,oBAAoB;AACtE,SAAO,gBAAgB,sBAAsB;AAC/C;AAEO,IAAM,6BAA6B,OAAO;AAAA,EAC/C,YAAY;AAAA,EACZ,SAAS;AACX,CAAC;AASM,SAAS,uBAAuB,OAAyB;AAC9D,MAAI;AACF,WAAO,OAAO,0BAA0B;AACxC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,IAAM,kCAAkC;AAAA,EAC7C;AACF;AAQO,SAAS,4BAA4B,OAAyB;AACnE,MAAI;AACF,WAAO,OAAO,+BAA+B;AAC7C,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// src/handlers.ts
|
|
2
|
+
import { SeverityLevel, ComponentStruct } from "@metamask/snaps-sdk";
|
|
3
|
+
import {
|
|
4
|
+
assign,
|
|
5
|
+
literal,
|
|
6
|
+
nullable,
|
|
7
|
+
object,
|
|
8
|
+
optional,
|
|
9
|
+
string,
|
|
10
|
+
array,
|
|
11
|
+
size,
|
|
12
|
+
union
|
|
13
|
+
} from "superstruct";
|
|
14
|
+
var SNAP_EXPORTS = {
|
|
15
|
+
["onRpcRequest" /* OnRpcRequest */]: {
|
|
16
|
+
type: "onRpcRequest" /* OnRpcRequest */,
|
|
17
|
+
required: true,
|
|
18
|
+
validator: (snapExport) => {
|
|
19
|
+
return typeof snapExport === "function";
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
["onTransaction" /* OnTransaction */]: {
|
|
23
|
+
type: "onTransaction" /* OnTransaction */,
|
|
24
|
+
required: true,
|
|
25
|
+
validator: (snapExport) => {
|
|
26
|
+
return typeof snapExport === "function";
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
["onCronjob" /* OnCronjob */]: {
|
|
30
|
+
type: "onCronjob" /* OnCronjob */,
|
|
31
|
+
required: true,
|
|
32
|
+
validator: (snapExport) => {
|
|
33
|
+
return typeof snapExport === "function";
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
["onNameLookup" /* OnNameLookup */]: {
|
|
37
|
+
type: "onNameLookup" /* OnNameLookup */,
|
|
38
|
+
required: true,
|
|
39
|
+
validator: (snapExport) => {
|
|
40
|
+
return typeof snapExport === "function";
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
["onInstall" /* OnInstall */]: {
|
|
44
|
+
type: "onInstall" /* OnInstall */,
|
|
45
|
+
required: false,
|
|
46
|
+
validator: (snapExport) => {
|
|
47
|
+
return typeof snapExport === "function";
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
["onUpdate" /* OnUpdate */]: {
|
|
51
|
+
type: "onUpdate" /* OnUpdate */,
|
|
52
|
+
required: false,
|
|
53
|
+
validator: (snapExport) => {
|
|
54
|
+
return typeof snapExport === "function";
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
["onKeyringRequest" /* OnKeyringRequest */]: {
|
|
58
|
+
type: "onKeyringRequest" /* OnKeyringRequest */,
|
|
59
|
+
required: true,
|
|
60
|
+
validator: (snapExport) => {
|
|
61
|
+
return typeof snapExport === "function";
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
["onHomePage" /* OnHomePage */]: {
|
|
65
|
+
type: "onHomePage" /* OnHomePage */,
|
|
66
|
+
required: true,
|
|
67
|
+
validator: (snapExport) => {
|
|
68
|
+
return typeof snapExport === "function";
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
["onSignature" /* OnSignature */]: {
|
|
72
|
+
type: "onSignature" /* OnSignature */,
|
|
73
|
+
required: true,
|
|
74
|
+
validator: (snapExport) => {
|
|
75
|
+
return typeof snapExport === "function";
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
["onUserInput" /* OnUserInput */]: {
|
|
79
|
+
type: "onUserInput" /* OnUserInput */,
|
|
80
|
+
required: true,
|
|
81
|
+
validator: (snapExport) => {
|
|
82
|
+
return typeof snapExport === "function";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var OnTransactionSeverityResponseStruct = object({
|
|
87
|
+
severity: optional(literal(SeverityLevel.Critical))
|
|
88
|
+
});
|
|
89
|
+
var OnTransactionResponseWithIdStruct = assign(
|
|
90
|
+
OnTransactionSeverityResponseStruct,
|
|
91
|
+
object({
|
|
92
|
+
id: string()
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
var OnTransactionResponseWithContentStruct = assign(
|
|
96
|
+
OnTransactionSeverityResponseStruct,
|
|
97
|
+
object({
|
|
98
|
+
content: ComponentStruct
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
var OnTransactionResponseStruct = nullable(
|
|
102
|
+
union([
|
|
103
|
+
OnTransactionResponseWithContentStruct,
|
|
104
|
+
OnTransactionResponseWithIdStruct
|
|
105
|
+
])
|
|
106
|
+
);
|
|
107
|
+
var OnSignatureResponseStruct = OnTransactionResponseStruct;
|
|
108
|
+
var OnHomePageResponseWithContentStruct = object({
|
|
109
|
+
content: ComponentStruct
|
|
110
|
+
});
|
|
111
|
+
var OnHomePageResponseWithIdStruct = object({
|
|
112
|
+
id: string()
|
|
113
|
+
});
|
|
114
|
+
var OnHomePageResponseStruct = union([
|
|
115
|
+
OnHomePageResponseWithContentStruct,
|
|
116
|
+
OnHomePageResponseWithIdStruct
|
|
117
|
+
]);
|
|
118
|
+
var AddressResolutionStruct = object({
|
|
119
|
+
protocol: string(),
|
|
120
|
+
resolvedDomain: string()
|
|
121
|
+
});
|
|
122
|
+
var DomainResolutionStruct = object({
|
|
123
|
+
protocol: string(),
|
|
124
|
+
resolvedAddress: string()
|
|
125
|
+
});
|
|
126
|
+
var AddressResolutionResponseStruct = object({
|
|
127
|
+
resolvedDomains: size(array(AddressResolutionStruct), 1, Infinity)
|
|
128
|
+
});
|
|
129
|
+
var DomainResolutionResponseStruct = object({
|
|
130
|
+
resolvedAddresses: size(array(DomainResolutionStruct), 1, Infinity)
|
|
131
|
+
});
|
|
132
|
+
var OnNameLookupResponseStruct = nullable(
|
|
133
|
+
union([AddressResolutionResponseStruct, DomainResolutionResponseStruct])
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
export {
|
|
137
|
+
SNAP_EXPORTS,
|
|
138
|
+
OnTransactionSeverityResponseStruct,
|
|
139
|
+
OnTransactionResponseWithIdStruct,
|
|
140
|
+
OnTransactionResponseWithContentStruct,
|
|
141
|
+
OnTransactionResponseStruct,
|
|
142
|
+
OnSignatureResponseStruct,
|
|
143
|
+
OnHomePageResponseWithContentStruct,
|
|
144
|
+
OnHomePageResponseWithIdStruct,
|
|
145
|
+
OnHomePageResponseStruct,
|
|
146
|
+
AddressResolutionStruct,
|
|
147
|
+
DomainResolutionStruct,
|
|
148
|
+
AddressResolutionResponseStruct,
|
|
149
|
+
DomainResolutionResponseStruct,
|
|
150
|
+
OnNameLookupResponseStruct
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=chunk-Z4J4GUGG.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/handlers.ts"],"sourcesContent":["import type {\n OnCronjobHandler,\n OnHomePageHandler,\n OnInstallHandler,\n OnKeyringRequestHandler,\n OnNameLookupHandler,\n OnRpcRequestHandler,\n OnSignatureHandler,\n OnTransactionHandler,\n OnUpdateHandler,\n OnUserInputHandler,\n} from '@metamask/snaps-sdk';\nimport { SeverityLevel, ComponentStruct } from '@metamask/snaps-sdk';\nimport {\n assign,\n literal,\n nullable,\n object,\n optional,\n string,\n array,\n size,\n union,\n} from 'superstruct';\n\nimport type { SnapHandler } from './handler-types';\nimport { HandlerType } from './handler-types';\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\nexport const SNAP_EXPORTS = {\n [HandlerType.OnRpcRequest]: {\n type: HandlerType.OnRpcRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnRpcRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnTransaction]: {\n type: HandlerType.OnTransaction,\n required: true,\n validator: (snapExport: unknown): snapExport is OnTransactionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnCronjob]: {\n type: HandlerType.OnCronjob,\n required: true,\n validator: (snapExport: unknown): snapExport is OnCronjobHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnNameLookup]: {\n type: HandlerType.OnNameLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnNameLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnInstall]: {\n type: HandlerType.OnInstall,\n required: false,\n validator: (snapExport: unknown): snapExport is OnInstallHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUpdate]: {\n type: HandlerType.OnUpdate,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUpdateHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnKeyringRequest]: {\n type: HandlerType.OnKeyringRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnKeyringRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnHomePage]: {\n type: HandlerType.OnHomePage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnHomePageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSignature]: {\n type: HandlerType.OnSignature,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSignatureHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUserInput]: {\n type: HandlerType.OnUserInput,\n required: true,\n validator: (snapExport: unknown): snapExport is OnUserInputHandler => {\n return typeof snapExport === 'function';\n },\n },\n} as const;\n\nexport const OnTransactionSeverityResponseStruct = object({\n severity: optional(literal(SeverityLevel.Critical)),\n});\n\nexport const OnTransactionResponseWithIdStruct = assign(\n OnTransactionSeverityResponseStruct,\n object({\n id: string(),\n }),\n);\n\nexport const OnTransactionResponseWithContentStruct = assign(\n OnTransactionSeverityResponseStruct,\n object({\n content: ComponentStruct,\n }),\n);\n\nexport const OnTransactionResponseStruct = nullable(\n union([\n OnTransactionResponseWithContentStruct,\n OnTransactionResponseWithIdStruct,\n ]),\n);\n\nexport const OnSignatureResponseStruct = OnTransactionResponseStruct;\n\nexport const OnHomePageResponseWithContentStruct = object({\n content: ComponentStruct,\n});\n\nexport const OnHomePageResponseWithIdStruct = object({\n id: string(),\n});\n\nexport const OnHomePageResponseStruct = union([\n OnHomePageResponseWithContentStruct,\n OnHomePageResponseWithIdStruct,\n]);\n\nexport const AddressResolutionStruct = object({\n protocol: string(),\n resolvedDomain: string(),\n});\n\nexport const DomainResolutionStruct = object({\n protocol: string(),\n resolvedAddress: string(),\n});\n\nexport const AddressResolutionResponseStruct = object({\n resolvedDomains: size(array(AddressResolutionStruct), 1, Infinity),\n});\n\nexport const DomainResolutionResponseStruct = object({\n resolvedAddresses: size(array(DomainResolutionStruct), 1, Infinity),\n});\n\nexport const OnNameLookupResponseStruct = nullable(\n union([AddressResolutionResponseStruct, DomainResolutionResponseStruct]),\n);\n\n/**\n * Utility type for getting the handler function type from a handler type.\n */\nexport type HandlerFunction<Type extends SnapHandler> =\n Type['validator'] extends (snapExport: unknown) => snapExport is infer Handler\n ? Handler\n : never;\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<\n (typeof SNAP_EXPORTS)[Key]\n >;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports;\n"],"mappings":";AAYA,SAAS,eAAe,uBAAuB;AAC/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAWA,IAAM,eAAe;AAAA,EAC1B,kCAAyB,GAAG;AAAA,IAC1B;AAAA,IACA,UAAU;AAAA,IACV,WAAW,CAAC,eAA2D;AACrE,aAAO,OAAO,eAAe;AAAA,IAC/B;AAAA,EACF;AAAA,EACA,oCAA0B,GAAG;AAAA,IAC3B;AAAA,IACA,UAAU;AAAA,IACV,WAAW,CAAC,eAA4D;AACtE,aAAO,OAAO,eAAe;AAAA,IAC/B;A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OAAO;AAAA,EACb,CAAC;AACH;AAEO,IAAM,yCAAyC;AAAA,EACpD;AAAA,EACA,OAAO;AAAA,IACL,SAAS;AAAA,EACX,CAAC;AACH;AAEO,IAAM,8BAA8B;AAAA,EACzC,MAAM;AAAA,IACJ;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAEO,IAAM,4BAA4B;AAElC,IAAM,sCAAsC,OAAO;AAAA,EACxD,SAAS;AACX,CAAC;AAEM,IAAM,iCAAiC,OAAO;AAAA,EACnD,IAAI,OAAO;AACb,CAAC;AAEM,IAAM,2BAA2B,MAAM;AAAA,EAC5C;AAAA,EACA;AACF,CAAC;AAEM,IAAM,0BAA0B,OAAO;AAAA,EAC5C,UAAU,OAAO;AAAA,EACjB,gBAAgB,OAAO;AACzB,CAAC;AAEM,IAAM,yBAAyB,OAAO;AAAA,EAC3C,UAAU,OAAO;AAAA,EACjB,iBAAiB,OAAO;AAC1B,CAAC;AAEM,IAAM,kCAAkC,OAAO;AAAA,EACpD,iBAAiB,KAAK,MAAM,uBAAuB,GAAG,GAAG,QAAQ;AACnE,CAAC;AAEM,IAAM,iCAAiC,OAAO;AAAA,EACnD,mBAAmB,KAAK,MAAM,sBAAsB,GAAG,GAAG,QAAQ;AACpE,CAAC;AAEM,IAAM,6BAA6B;AAAA,EACxC,MAAM,CAAC,iCAAiC,8BAA8B,CAAC;AACzE;","names":[]}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkVMUXXXJCjs = require('./chunk-VMUXXXJC.js');
|
|
4
|
+
|
|
5
|
+
// src/eval.ts
|
|
6
|
+
var _utils = require('@metamask/utils');
|
|
7
|
+
var _child_process = require('child_process');
|
|
8
|
+
var _path = require('path');
|
|
9
|
+
var SnapEvalError = class extends Error {
|
|
10
|
+
constructor(message, output) {
|
|
11
|
+
super(message);
|
|
12
|
+
this.name = "SnapEvalError";
|
|
13
|
+
this.output = output;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
async function evalBundle(bundlePath) {
|
|
17
|
+
await _chunkVMUXXXJCjs.validateFilePath.call(void 0, bundlePath);
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
const worker = _child_process.fork.call(void 0, _path.join.call(void 0, __dirname, "eval-worker.js"), [bundlePath], {
|
|
20
|
+
// To avoid printing the output of the worker to the console, we set
|
|
21
|
+
// `stdio` to `pipe` and handle the output ourselves.
|
|
22
|
+
stdio: "pipe"
|
|
23
|
+
});
|
|
24
|
+
let stdout = "";
|
|
25
|
+
let stderr = "";
|
|
26
|
+
_utils.assert.call(void 0, worker.stdout, "`stdout` should be defined.");
|
|
27
|
+
_utils.assert.call(void 0, worker.stderr, "`stderr` should be defined.");
|
|
28
|
+
worker.stdout.on("data", (data) => {
|
|
29
|
+
stdout += data.toString();
|
|
30
|
+
});
|
|
31
|
+
worker.stderr.on("data", (data) => {
|
|
32
|
+
stderr += data.toString();
|
|
33
|
+
});
|
|
34
|
+
worker.on("exit", (exitCode) => {
|
|
35
|
+
const output = {
|
|
36
|
+
stdout,
|
|
37
|
+
stderr
|
|
38
|
+
};
|
|
39
|
+
if (exitCode === 0) {
|
|
40
|
+
return resolve(output);
|
|
41
|
+
}
|
|
42
|
+
return reject(
|
|
43
|
+
new SnapEvalError(
|
|
44
|
+
`Process exited with non-zero exit code: ${exitCode}.`,
|
|
45
|
+
output
|
|
46
|
+
)
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
exports.SnapEvalError = SnapEvalError; exports.evalBundle = evalBundle;
|
|
56
|
+
//# sourceMappingURL=chunk-ZLFA4R5X.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/eval.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,cAAc;AACvB,SAAS,YAAY;AACrB,SAAS,YAAY;AASd,IAAM,gBAAN,cAA4B,MAAM;AAAA,EAGvC,YAAY,SAAiB,QAAoB;AAC/C,UAAM,OAAO;AAEb,SAAK,OAAO;AACZ,SAAK,SAAS;AAAA,EAChB;AACF;AASA,eAAsB,WAAW,YAAyC;AACxE,QAAM,iBAAiB,UAAU;AAEjC,SAAO,IAAI,QAAQ,CAAC,SAAS,WAAW;AACtC,UAAM,SAAS,KAAK,KAAK,WAAW,gBAAgB,GAAG,CAAC,UAAU,GAAG;AAAA;AAAA;AAAA,MAGnE,OAAO;AAAA,IACT,CAAC;AAED,QAAI,SAAS;AACb,QAAI,SAAS;AAEb,WAAO,OAAO,QAAQ,6BAA6B;AACnD,WAAO,OAAO,QAAQ,6BAA6B;AAEnD,WAAO,OAAO,GAAG,QAAQ,CAAC,SAAiB;AACzC,gBAAU,KAAK,SAAS;AAAA,IAC1B,CAAC;AAED,WAAO,OAAO,GAAG,QAAQ,CAAC,SAAiB;AACzC,gBAAU,KAAK,SAAS;AAAA,IAC1B,CAAC;AAED,WAAO,GAAG,QAAQ,CAAC,aAAqB;AACtC,YAAM,SAAS;AAAA,QACb;AAAA,QACA;AAAA,MACF;AAEA,UAAI,aAAa,GAAG;AAClB,eAAO,QAAQ,MAAM;AAAA,MACvB;AAEA,aAAO;AAAA,QACL,IAAI;AAAA,UACF,2CAA2C,QAAQ;AAAA,UACnD;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH,CAAC;AACH","sourcesContent":["import { assert } from '@metamask/utils';\nimport { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\nexport type EvalOutput = {\n stdout: string;\n stderr: string;\n};\n\nexport class SnapEvalError extends Error {\n readonly output: EvalOutput;\n\n constructor(message: string, output: EvalOutput) {\n super(message);\n\n this.name = 'SnapEvalError';\n this.output = output;\n }\n}\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<EvalOutput> {\n await validateFilePath(bundlePath);\n\n return new Promise((resolve, reject) => {\n const worker = fork(join(__dirname, 'eval-worker.js'), [bundlePath], {\n // To avoid printing the output of the worker to the console, we set\n // `stdio` to `pipe` and handle the output ourselves.\n stdio: 'pipe',\n });\n\n let stdout = '';\n let stderr = '';\n\n assert(worker.stdout, '`stdout` should be defined.');\n assert(worker.stderr, '`stderr` should be defined.');\n\n worker.stdout.on('data', (data: Buffer) => {\n stdout += data.toString();\n });\n\n worker.stderr.on('data', (data: Buffer) => {\n stderr += data.toString();\n });\n\n worker.on('exit', (exitCode: number) => {\n const output = {\n stdout,\n stderr,\n };\n\n if (exitCode === 0) {\n return resolve(output);\n }\n\n return reject(\n new SnapEvalError(\n `Process exited with non-zero exit code: ${exitCode}.`,\n output,\n ),\n );\n });\n });\n}\n"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/json-rpc.ts
|
|
2
|
+
var _permissioncontroller = require('@metamask/permission-controller');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _utils = require('@metamask/utils');
|
|
8
|
+
var _superstruct = require('superstruct');
|
|
9
|
+
var RpcOriginsStruct = _superstruct.refine.call(void 0,
|
|
10
|
+
_superstruct.object.call(void 0, {
|
|
11
|
+
dapps: _superstruct.optional.call(void 0, _superstruct.boolean.call(void 0, )),
|
|
12
|
+
snaps: _superstruct.optional.call(void 0, _superstruct.boolean.call(void 0, )),
|
|
13
|
+
allowedOrigins: _superstruct.optional.call(void 0, _superstruct.array.call(void 0, _superstruct.string.call(void 0, )))
|
|
14
|
+
}),
|
|
15
|
+
"RPC origins",
|
|
16
|
+
(value) => {
|
|
17
|
+
const hasOrigins = Boolean(
|
|
18
|
+
value.snaps === true || value.dapps === true || value.allowedOrigins && value.allowedOrigins.length > 0
|
|
19
|
+
);
|
|
20
|
+
if (hasOrigins) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return "Must specify at least one JSON-RPC origin.";
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
function assertIsRpcOrigins(value, ErrorWrapper) {
|
|
27
|
+
_utils.assertStruct.call(void 0,
|
|
28
|
+
value,
|
|
29
|
+
RpcOriginsStruct,
|
|
30
|
+
"Invalid JSON-RPC origins",
|
|
31
|
+
ErrorWrapper
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
var KeyringOriginsStruct = _superstruct.object.call(void 0, {
|
|
35
|
+
allowedOrigins: _superstruct.optional.call(void 0, _superstruct.array.call(void 0, _superstruct.string.call(void 0, )))
|
|
36
|
+
});
|
|
37
|
+
function assertIsKeyringOrigins(value, ErrorWrapper) {
|
|
38
|
+
_utils.assertStruct.call(void 0,
|
|
39
|
+
value,
|
|
40
|
+
KeyringOriginsStruct,
|
|
41
|
+
"Invalid keyring origins",
|
|
42
|
+
ErrorWrapper
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function isOriginAllowed(origins, subjectType, origin) {
|
|
46
|
+
if (origin === "metamask") {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (_optionalChain([origins, 'access', _ => _.allowedOrigins, 'optionalAccess', _2 => _2.includes, 'call', _3 => _3(origin)])) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (subjectType === _permissioncontroller.SubjectType.Website && origins.dapps) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return Boolean(subjectType === _permissioncontroller.SubjectType.Snap && origins.snaps);
|
|
56
|
+
}
|
|
57
|
+
function assertIsJsonRpcSuccess(value) {
|
|
58
|
+
if (!_utils.isJsonRpcSuccess.call(void 0, value)) {
|
|
59
|
+
if (_utils.isJsonRpcFailure.call(void 0, value)) {
|
|
60
|
+
throw new Error(`JSON-RPC request failed: ${value.error.message}`);
|
|
61
|
+
}
|
|
62
|
+
throw new Error("Invalid JSON-RPC response.");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
exports.RpcOriginsStruct = RpcOriginsStruct; exports.assertIsRpcOrigins = assertIsRpcOrigins; exports.KeyringOriginsStruct = KeyringOriginsStruct; exports.assertIsKeyringOrigins = assertIsKeyringOrigins; exports.isOriginAllowed = isOriginAllowed; exports.assertIsJsonRpcSuccess = assertIsJsonRpcSuccess;
|
|
74
|
+
//# sourceMappingURL=chunk-ZRVOIW3H.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/json-rpc.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAM5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,OAAO,SAAS,QAAQ,UAAU,QAAQ,cAAc;AAE1D,IAAM,mBAAmB;AAAA,EAC9B,OAAO;AAAA,IACL,OAAO,SAAS,QAAQ,CAAC;AAAA,IACzB,OAAO,SAAS,QAAQ,CAAC;AAAA,IACzB,gBAAgB,SAAS,MAAM,OAAO,CAAC,CAAC;AAAA,EAC1C,CAAC;AAAA,EACD;AAAA,EACA,CAAC,UAAU;AACT,UAAM,aAAa;AAAA,MACjB,MAAM,UAAU,QACd,MAAM,UAAU,QACf,MAAM,kBAAkB,MAAM,eAAe,SAAS;AAAA,IAC3D;AAEA,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AACF;AAYO,SAAS,mBACd,OAEA,cAC6B;AAC7B;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,IAAM,uBAAuB,OAAO;AAAA,EACzC,gBAAgB,SAAS,MAAM,OAAO,CAAC,CAAC;AAC1C,CAAC;AAYM,SAAS,uBACd,OAEA,cACiC;AACjC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAUO,SAAS,gBACd,SACA,aACA,QACA;AAEA,MAAI,WAAW,YAAY;AACzB,WAAO;AAAA,EACT;AAGA,MAAI,QAAQ,gBAAgB,SAAS,MAAM,GAAG;AAC5C,WAAO;AAAA,EACT;AAGA,MAAI,gBAAgB,YAAY,WAAW,QAAQ,OAAO;AACxD,WAAO;AAAA,EACT;AAGA,SAAO,QAAQ,gBAAgB,YAAY,QAAQ,QAAQ,KAAK;AAClE;AAUO,SAAS,uBACd,OACuC;AACvC,MAAI,CAAC,iBAAiB,KAAK,GAAG;AAC5B,QAAI,iBAAiB,KAAK,GAAG;AAC3B,YAAM,IAAI,MAAM,4BAA4B,MAAM,MAAM,OAAO,EAAE;AAAA,IACnE;AAEA,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AACF","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"]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
import { assertStruct, VersionStruct } from "@metamask/utils";
|
|
3
|
+
import {
|
|
4
|
+
instance,
|
|
5
|
+
is,
|
|
6
|
+
object,
|
|
7
|
+
optional,
|
|
8
|
+
pattern,
|
|
9
|
+
refine,
|
|
10
|
+
size,
|
|
11
|
+
string,
|
|
12
|
+
type,
|
|
13
|
+
union,
|
|
14
|
+
assert as assertSuperstruct
|
|
15
|
+
} from "superstruct";
|
|
16
|
+
var NpmSnapFileNames = /* @__PURE__ */ ((NpmSnapFileNames2) => {
|
|
17
|
+
NpmSnapFileNames2["PackageJson"] = "package.json";
|
|
18
|
+
NpmSnapFileNames2["Manifest"] = "snap.manifest.json";
|
|
19
|
+
return NpmSnapFileNames2;
|
|
20
|
+
})(NpmSnapFileNames || {});
|
|
21
|
+
var NameStruct = size(
|
|
22
|
+
pattern(
|
|
23
|
+
string(),
|
|
24
|
+
/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u
|
|
25
|
+
),
|
|
26
|
+
1,
|
|
27
|
+
214
|
|
28
|
+
);
|
|
29
|
+
var NpmSnapPackageJsonStruct = type({
|
|
30
|
+
version: VersionStruct,
|
|
31
|
+
name: NameStruct,
|
|
32
|
+
main: optional(size(string(), 1, Infinity)),
|
|
33
|
+
repository: optional(
|
|
34
|
+
object({
|
|
35
|
+
type: size(string(), 1, Infinity),
|
|
36
|
+
url: size(string(), 1, Infinity)
|
|
37
|
+
})
|
|
38
|
+
)
|
|
39
|
+
});
|
|
40
|
+
function isNpmSnapPackageJson(value) {
|
|
41
|
+
return is(value, NpmSnapPackageJsonStruct);
|
|
42
|
+
}
|
|
43
|
+
function assertIsNpmSnapPackageJson(value) {
|
|
44
|
+
assertStruct(
|
|
45
|
+
value,
|
|
46
|
+
NpmSnapPackageJsonStruct,
|
|
47
|
+
`"${"package.json" /* PackageJson */}" is invalid`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
var SnapIdPrefixes = /* @__PURE__ */ ((SnapIdPrefixes2) => {
|
|
51
|
+
SnapIdPrefixes2["npm"] = "npm:";
|
|
52
|
+
SnapIdPrefixes2["local"] = "local:";
|
|
53
|
+
return SnapIdPrefixes2;
|
|
54
|
+
})(SnapIdPrefixes || {});
|
|
55
|
+
var SnapValidationFailureReason = /* @__PURE__ */ ((SnapValidationFailureReason2) => {
|
|
56
|
+
SnapValidationFailureReason2["NameMismatch"] = '"name" field mismatch';
|
|
57
|
+
SnapValidationFailureReason2["VersionMismatch"] = '"version" field mismatch';
|
|
58
|
+
SnapValidationFailureReason2["RepositoryMismatch"] = '"repository" field mismatch';
|
|
59
|
+
SnapValidationFailureReason2["ShasumMismatch"] = '"shasum" field mismatch';
|
|
60
|
+
return SnapValidationFailureReason2;
|
|
61
|
+
})(SnapValidationFailureReason || {});
|
|
62
|
+
var SNAP_STREAM_NAMES = /* @__PURE__ */ ((SNAP_STREAM_NAMES2) => {
|
|
63
|
+
SNAP_STREAM_NAMES2["JSON_RPC"] = "jsonRpc";
|
|
64
|
+
SNAP_STREAM_NAMES2["COMMAND"] = "command";
|
|
65
|
+
return SNAP_STREAM_NAMES2;
|
|
66
|
+
})(SNAP_STREAM_NAMES || {});
|
|
67
|
+
var uri = (opts = {}) => refine(union([string(), instance(URL)]), "uri", (value) => {
|
|
68
|
+
try {
|
|
69
|
+
const url = new URL(value);
|
|
70
|
+
const UrlStruct = type(opts);
|
|
71
|
+
assertSuperstruct(url, UrlStruct);
|
|
72
|
+
return true;
|
|
73
|
+
} catch {
|
|
74
|
+
return `Expected URL, got "${value.toString()}".`;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
function isValidUrl(url, opts = {}) {
|
|
78
|
+
return is(url, uri(opts));
|
|
79
|
+
}
|
|
80
|
+
var WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
|
|
81
|
+
|
|
82
|
+
export {
|
|
83
|
+
NpmSnapFileNames,
|
|
84
|
+
NameStruct,
|
|
85
|
+
NpmSnapPackageJsonStruct,
|
|
86
|
+
isNpmSnapPackageJson,
|
|
87
|
+
assertIsNpmSnapPackageJson,
|
|
88
|
+
SnapIdPrefixes,
|
|
89
|
+
SnapValidationFailureReason,
|
|
90
|
+
SNAP_STREAM_NAMES,
|
|
91
|
+
uri,
|
|
92
|
+
isValidUrl,
|
|
93
|
+
WALLET_SNAP_PERMISSION_KEY
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=chunk-ZVXX2CTH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assertStruct, VersionStruct } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n type,\n union,\n assert as assertSuperstruct,\n} from 'superstruct';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n pattern(\n string(),\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * Check if the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link NpmSnapPackageJson} object.\n */\nexport function isNpmSnapPackageJson(\n value: unknown,\n): value is NpmSnapPackageJson {\n return is(value, NpmSnapPackageJsonStruct);\n}\n\n/**\n * Asserts that the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link NpmSnapPackageJson} object.\n */\nexport function assertIsNpmSnapPackageJson(\n value: unknown,\n): asserts value is NpmSnapPackageJson {\n assertStruct(\n value,\n NpmSnapPackageJsonStruct,\n `\"${NpmSnapFileNames.PackageJson}\" is invalid`,\n );\n}\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/**\n * Snap validation failure reason codes that are programmatically fixable\n * if validation occurs during development.\n */\nexport enum SnapValidationFailureReason {\n NameMismatch = '\"name\" field mismatch',\n VersionMismatch = '\"version\" field mismatch',\n RepositoryMismatch = '\"repository\" field mismatch',\n ShasumMismatch = '\"shasum\" field mismatch',\n}\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(union([string(), instance(URL)]), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch {\n return `Expected URL, got \"${value.toString()}\".`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string | URL {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"],"mappings":";AACA,SAAS,cAAc,qBAAqB;AAE5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,OACL;AAQA,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,iBAAc;AACd,EAAAA,kBAAA,cAAW;AAFD,SAAAA;AAAA,GAAA;AAKL,IAAM,aAAa;AAAA,EACxB;AAAA,IACE,OAAO;AAAA,IACP;AAAA,EACF;AAAA,EACA;AAAA,EACA;AACF;AAIO,IAAM,2BAA2B,KAAK;AAAA,EAC3C,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM,SAAS,KAAK,OAAO,GAAG,GAAG,QAAQ,CAAC;AAAA,EAC1C,YAAY;AAAA,IACV,OAAO;AAAA,MACL,MAAM,KAAK,OAAO,GAAG,GAAG,QAAQ;AAAA,MAChC,KAAK,KAAK,OAAO,GAAG,GAAG,QAAQ;AAAA,IACjC,CAAC;AAAA,EACH;AACF,CAAC;AAWM,SAAS,qBACd,OAC6B;AAC7B,SAAO,GAAG,OAAO,wBAAwB;AAC3C;AAQO,SAAS,2BACd,OACqC;AACrC;AAAA,IACE;AAAA,IACA;AAAA,IACA,IAAI,gCAA4B;AAAA,EAClC;AACF;AAuCO,IAAK,iBAAL,kBAAKC,oBAAL;AACL,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AAUL,IAAK,8BAAL,kBAAKC,iCAAL;AACL,EAAAA,6BAAA,kBAAe;AACf,EAAAA,6BAAA,qBAAkB;AAClB,EAAAA,6BAAA,wBAAqB;AACrB,EAAAA,6BAAA,oBAAiB;AAJP,SAAAA;AAAA,GAAA;AAQL,IAAK,oBAAL,kBAAKC,uBAAL;AACL,EAAAA,mBAAA,cAAW;AACX,EAAAA,mBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;AAwBL,IAAM,MAAM,CAAC,OAAwB,CAAC,MAC3C,OAAO,MAAM,CAAC,OAAO,GAAG,SAAS,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU;AACzD,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,KAAK;AAEzB,UAAM,YAAY,KAAK,IAAI;AAC3B,sBAAkB,KAAK,SAAS;AAChC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO,sBAAsB,MAAM,SAAS,CAAC;AAAA,EAC/C;AACF,CAAC;AASI,SAAS,WACd,KACA,OAAwB,CAAC,GACJ;AACrB,SAAO,GAAG,KAAK,IAAI,IAAI,CAAC;AAC1B;AAGO,IAAM,6BAA6B;","names":["NpmSnapFileNames","SnapIdPrefixes","SnapValidationFailureReason","SNAP_STREAM_NAMES"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// src/ui.ts
|
|
2
|
+
import { NodeType } from "@metamask/snaps-sdk";
|
|
3
|
+
import { assert, AssertionError } from "@metamask/utils";
|
|
4
|
+
var MARKDOWN_LINK_REGEX = /\[(?<name>[^\]]*)\]\((?<url>[^)]+)\)/giu;
|
|
5
|
+
var ALLOWED_PROTOCOLS = ["https:", "mailto:"];
|
|
6
|
+
function validateTextLinks(text, isOnPhishingList) {
|
|
7
|
+
const matches = String.prototype.matchAll.call(text, MARKDOWN_LINK_REGEX);
|
|
8
|
+
for (const { groups } of matches) {
|
|
9
|
+
const link = groups?.url;
|
|
10
|
+
if (!link) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(link);
|
|
15
|
+
assert(
|
|
16
|
+
ALLOWED_PROTOCOLS.includes(url.protocol),
|
|
17
|
+
`Protocol must be one of: ${ALLOWED_PROTOCOLS.join(", ")}.`
|
|
18
|
+
);
|
|
19
|
+
const hostname = url.protocol === "mailto:" ? url.pathname.split("@")[1] : url.hostname;
|
|
20
|
+
assert(!isOnPhishingList(hostname), "The specified URL is not allowed.");
|
|
21
|
+
} catch (error) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Invalid URL: ${error instanceof AssertionError ? error.message : "Unable to parse URL."}`
|
|
24
|
+
);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
function validateComponentLinks(component, isOnPhishingList) {
|
|
29
|
+
const { type } = component;
|
|
30
|
+
switch (type) {
|
|
31
|
+
case NodeType.Panel:
|
|
32
|
+
component.children.forEach(
|
|
33
|
+
(node) => validateComponentLinks(node, isOnPhishingList)
|
|
34
|
+
);
|
|
35
|
+
break;
|
|
36
|
+
case NodeType.Row:
|
|
37
|
+
validateComponentLinks(component.value, isOnPhishingList);
|
|
38
|
+
break;
|
|
39
|
+
case NodeType.Text:
|
|
40
|
+
validateTextLinks(component.value, isOnPhishingList);
|
|
41
|
+
break;
|
|
42
|
+
default:
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
function getTotalTextLength(component) {
|
|
47
|
+
const { type } = component;
|
|
48
|
+
switch (type) {
|
|
49
|
+
case NodeType.Panel:
|
|
50
|
+
return component.children.reduce(
|
|
51
|
+
// This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
53
|
+
(sum, node) => sum + getTotalTextLength(node),
|
|
54
|
+
0
|
|
55
|
+
);
|
|
56
|
+
case NodeType.Row:
|
|
57
|
+
return getTotalTextLength(component.value);
|
|
58
|
+
case NodeType.Text:
|
|
59
|
+
return component.value.length;
|
|
60
|
+
default:
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export {
|
|
66
|
+
validateTextLinks,
|
|
67
|
+
validateComponentLinks,
|
|
68
|
+
getTotalTextLength
|
|
69
|
+
};
|
|
70
|
+
//# sourceMappingURL=chunk-ZXCNX3ZB.mjs.map
|