@metamask/snaps-utils 6.1.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 +18 -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/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/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 +23 -38
- 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 -66
- 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 -283
- 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 -51
- 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 -307
- package/dist/esm/manifest/manifest.js.map +0 -1
- package/dist/esm/manifest/validation.js +0 -190
- package/dist/esm/manifest/validation.js.map +0 -1
- package/dist/esm/mock.js +0 -111
- package/dist/esm/mock.js.map +0 -1
- package/dist/esm/namespace.js +0 -113
- package/dist/esm/namespace.js.map +0 -1
- package/dist/esm/npm.js +0 -85
- package/dist/esm/npm.js.map +0 -1
- package/dist/esm/path.js +0 -17
- package/dist/esm/path.js.map +0 -1
- package/dist/esm/post-process.js +0 -333
- package/dist/esm/post-process.js.map +0 -1
- package/dist/esm/snaps.js +0 -217
- package/dist/esm/snaps.js.map +0 -1
- package/dist/esm/strings.js +0 -11
- package/dist/esm/strings.js.map +0 -1
- package/dist/esm/structs.js +0 -295
- package/dist/esm/structs.js.map +0 -1
- package/dist/esm/types.js +0 -78
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/ui.js +0 -50
- package/dist/esm/ui.js.map +0 -1
- package/dist/esm/validation.js +0 -19
- package/dist/esm/validation.js.map +0 -1
- package/dist/esm/versions.js +0 -41
- package/dist/esm/versions.js.map +0 -1
- package/dist/esm/virtual-file/VirtualFile.js +0 -82
- package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
- package/dist/esm/virtual-file/index.browser.js +0 -3
- package/dist/esm/virtual-file/index.browser.js.map +0 -1
- package/dist/esm/virtual-file/index.js +0 -4
- package/dist/esm/virtual-file/index.js.map +0 -1
- package/dist/esm/virtual-file/toVirtualFile.js +0 -26
- package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/types/index.browser.d.ts +0 -30
- package/dist/types/manifest/index.browser.d.ts +0 -1
- package/dist/types/virtual-file/index.browser.d.ts +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [7.0.0]
|
|
10
|
+
### Changed
|
|
11
|
+
- **BREAKING:** Update ESM build to be fully compliant with the ESM standard ([#2210](https://github.com/MetaMask/snaps/pull/2210))
|
|
12
|
+
- **BREAKING:** Move Node.js exports to separate export ([#2210](https://github.com/MetaMask/snaps/pull/2210))
|
|
13
|
+
- The default export is now browser-compatible.
|
|
14
|
+
- Node.js APIs can be imported from `<package>/node`.
|
|
15
|
+
- Bump `@metamask/rpc-errors` to `^6.2.1` ([#2209](https://github.com/MetaMask/snaps/pull/2209))
|
|
16
|
+
|
|
17
|
+
### Removed
|
|
18
|
+
- **BREAKING:** Move `file` struct to CLI ([#2207](https://github.com/MetaMask/snaps/pull/2207))
|
|
19
|
+
- The previously exported `file` struct can now be found in `@metamask/snaps-cli`.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
- Add sizing limits for custom UI ([#2199](https://github.com/MetaMask/snaps/pull/2199))
|
|
23
|
+
- Properly validate links contained in rows ([#2205](https://github.com/MetaMask/snaps/pull/2205))
|
|
24
|
+
|
|
9
25
|
## [6.1.0]
|
|
10
26
|
### Added
|
|
11
27
|
- Add a manifest warning when no icon is found and when icon is not square ([#2185](https://github.com/MetaMask/snaps/pull/2185))
|
|
@@ -169,7 +185,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
169
185
|
- The version of the package no longer needs to match the version of all other
|
|
170
186
|
MetaMask Snaps packages.
|
|
171
187
|
|
|
172
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@
|
|
188
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@7.0.0...HEAD
|
|
189
|
+
[7.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@6.1.0...@metamask/snaps-utils@7.0.0
|
|
173
190
|
[6.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@6.0.0...@metamask/snaps-utils@6.1.0
|
|
174
191
|
[6.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@5.2.0...@metamask/snaps-utils@6.0.0
|
|
175
192
|
[5.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@5.1.2...@metamask/snaps-utils@5.2.0
|
package/dist/array.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/array.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk7PNGOFLUjs = require('./chunk-7PNGOFLU.js');
|
|
4
|
+
require('./chunk-7KKLGQNE.js');
|
|
5
|
+
require('./chunk-R4BBIGBN.js');
|
|
6
|
+
require('./chunk-XWFKTDB3.js');
|
|
7
|
+
require('./chunk-Q7FGULTV.js');
|
|
8
|
+
require('./chunk-PHUTP7NB.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.encodeAuxiliaryFile = _chunk7PNGOFLUjs.encodeAuxiliaryFile;
|
|
12
|
+
//# sourceMappingURL=auxiliary-files.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
encodeAuxiliaryFile
|
|
3
|
+
} from "./chunk-2G4HD42C.mjs";
|
|
4
|
+
import "./chunk-JGMGNLZW.mjs";
|
|
5
|
+
import "./chunk-VGWELVCX.mjs";
|
|
6
|
+
import "./chunk-LOW2T4MV.mjs";
|
|
7
|
+
import "./chunk-B2DMAQNK.mjs";
|
|
8
|
+
import "./chunk-4GBOSMF7.mjs";
|
|
9
|
+
export {
|
|
10
|
+
encodeAuxiliaryFile
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=auxiliary-files.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/base64.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk7KKLGQNEjs = require('./chunk-7KKLGQNE.js');
|
|
5
|
+
require('./chunk-R4BBIGBN.js');
|
|
6
|
+
require('./chunk-XWFKTDB3.js');
|
|
7
|
+
require('./chunk-Q7FGULTV.js');
|
|
8
|
+
require('./chunk-PHUTP7NB.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.decodeBase64 = _chunk7KKLGQNEjs.decodeBase64; exports.encodeBase64 = _chunk7KKLGQNEjs.encodeBase64;
|
|
13
|
+
//# sourceMappingURL=base64.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/base64.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeBase64,
|
|
3
|
+
encodeBase64
|
|
4
|
+
} from "./chunk-JGMGNLZW.mjs";
|
|
5
|
+
import "./chunk-VGWELVCX.mjs";
|
|
6
|
+
import "./chunk-LOW2T4MV.mjs";
|
|
7
|
+
import "./chunk-B2DMAQNK.mjs";
|
|
8
|
+
import "./chunk-4GBOSMF7.mjs";
|
|
9
|
+
export {
|
|
10
|
+
decodeBase64,
|
|
11
|
+
encodeBase64
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=base64.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/bytes.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkR4BBIGBNjs = require('./chunk-R4BBIGBN.js');
|
|
4
|
+
require('./chunk-XWFKTDB3.js');
|
|
5
|
+
require('./chunk-Q7FGULTV.js');
|
|
6
|
+
require('./chunk-PHUTP7NB.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.getBytes = _chunkR4BBIGBNjs.getBytes;
|
|
10
|
+
//# sourceMappingURL=bytes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/bytes.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/caveats.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkMJABESWHjs = require('./chunk-MJABESWH.js');
|
|
4
|
+
require('./chunk-PHUTP7NB.js');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
exports.SnapCaveatType = _chunkMJABESWHjs.SnapCaveatType;
|
|
8
|
+
//# sourceMappingURL=caveats.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/caveats.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
package/dist/checksum.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
var _chunk224S5XKLjs = require('./chunk-224S5XKL.js');
|
|
5
|
+
require('./chunk-R4BBIGBN.js');
|
|
6
|
+
require('./chunk-XWFKTDB3.js');
|
|
7
|
+
require('./chunk-Q7FGULTV.js');
|
|
8
|
+
require('./chunk-PHUTP7NB.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.checksum = _chunk224S5XKLjs.checksum; exports.checksumFiles = _chunk224S5XKLjs.checksumFiles;
|
|
13
|
+
//# sourceMappingURL=checksum.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {
|
|
2
|
+
checksum,
|
|
3
|
+
checksumFiles
|
|
4
|
+
} from "./chunk-LHIPBIPS.mjs";
|
|
5
|
+
import "./chunk-VGWELVCX.mjs";
|
|
6
|
+
import "./chunk-LOW2T4MV.mjs";
|
|
7
|
+
import "./chunk-B2DMAQNK.mjs";
|
|
8
|
+
import "./chunk-4GBOSMF7.mjs";
|
|
9
|
+
export {
|
|
10
|
+
checksum,
|
|
11
|
+
checksumFiles
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=checksum.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
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; }
|
|
2
|
+
|
|
3
|
+
var _chunkR4BBIGBNjs = require('./chunk-R4BBIGBN.js');
|
|
4
|
+
|
|
5
|
+
// src/checksum.ts
|
|
6
|
+
var _utils = require('@metamask/utils');
|
|
7
|
+
var _sha256 = require('@noble/hashes/sha256');
|
|
8
|
+
async function checksum(bytes) {
|
|
9
|
+
const value = _chunkR4BBIGBNjs.getBytes.call(void 0, bytes);
|
|
10
|
+
if ("crypto" in globalThis && typeof globalThis.crypto === "object" && _optionalChain([crypto, 'access', _ => _.subtle, 'optionalAccess', _2 => _2.digest])) {
|
|
11
|
+
return new Uint8Array(await crypto.subtle.digest("SHA-256", value));
|
|
12
|
+
}
|
|
13
|
+
return _sha256.sha256.call(void 0, value);
|
|
14
|
+
}
|
|
15
|
+
async function checksumFiles(files) {
|
|
16
|
+
const checksums = await Promise.all(
|
|
17
|
+
[...files].sort((a, b) => {
|
|
18
|
+
_utils.assert.call(void 0, a.path !== b.path, "Tried to sort files with non-unique paths.");
|
|
19
|
+
if (a.path < b.path) {
|
|
20
|
+
return -1;
|
|
21
|
+
}
|
|
22
|
+
return 1;
|
|
23
|
+
}).map(async (file) => checksum(file))
|
|
24
|
+
);
|
|
25
|
+
return checksum(_utils.concatBytes.call(void 0, checksums));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
exports.checksum = checksum; exports.checksumFiles = checksumFiles;
|
|
32
|
+
//# sourceMappingURL=chunk-224S5XKL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/checksum.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,cAAc;AAWvB,eAAsB,SACpB,OACqB;AACrB,QAAM,QAAQ,SAAS,KAAK;AAE5B,MACE,YAAY,cACZ,OAAO,WAAW,WAAW,YAC7B,OAAO,QAAQ,QACf;AACA,WAAO,IAAI,WAAW,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,CAAC;AAAA,EACpE;AACA,SAAO,OAAO,KAAK;AACrB;AAcA,eAAsB,cAAc,OAAsB;AACxD,QAAM,YAAY,MAAM,QAAQ;AAAA,IAC9B,CAAC,GAAG,KAAK,EACN,KAAK,CAAC,GAAG,MAAM;AACd,aAAO,EAAE,SAAS,EAAE,MAAM,4CAA4C;AACtE,UAAI,EAAE,OAAO,EAAE,MAAM;AACnB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT,CAAC,EACA,IAAI,OAAO,SAAS,SAAS,IAAI,CAAC;AAAA,EACvC;AAEA,SAAO,SAAS,YAAY,SAAS,CAAC;AACxC","sourcesContent":["import { assert, concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { getBytes } from './bytes';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Calculates checksum for a single byte array.\n *\n * @param bytes - The byte array to calculate the checksum for.\n * @returns A single sha-256 checksum.\n */\nexport async function checksum(\n bytes: VirtualFile | Uint8Array | string,\n): Promise<Uint8Array> {\n const value = getBytes(bytes);\n // Use crypto.subtle.digest whenever possible as it is faster.\n if (\n 'crypto' in globalThis &&\n typeof globalThis.crypto === 'object' &&\n crypto.subtle?.digest\n ) {\n return new Uint8Array(await crypto.subtle.digest('SHA-256', value));\n }\n return sha256(value);\n}\n\n/**\n * Calculates checksum over multiple files in a reproducible way.\n *\n * 1. Sort all the files by their paths.\n * 2. Calculate sha-256 checksum of each file separately.\n * 3. Concatenate all the checksums into one buffer and sha-256 that buffer.\n *\n * The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.\n *\n * @param files - The files over which to calculate the checksum.\n * @returns A single sha-256 checksum.\n */\nexport async function checksumFiles(files: VirtualFile[]) {\n const checksums = await Promise.all(\n [...files]\n .sort((a, b) => {\n assert(a.path !== b.path, 'Tried to sort files with non-unique paths.');\n if (a.path < b.path) {\n return -1;\n }\n return 1;\n })\n .map(async (file) => checksum(file)),\n );\n\n return checksum(concatBytes(checksums));\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeBase64
|
|
3
|
+
} from "./chunk-JGMGNLZW.mjs";
|
|
4
|
+
|
|
5
|
+
// src/auxiliary-files.ts
|
|
6
|
+
import { AuxiliaryFileEncoding } from "@metamask/snaps-sdk";
|
|
7
|
+
import { bytesToHex, bytesToString } from "@metamask/utils";
|
|
8
|
+
async function encodeAuxiliaryFile(value, encoding) {
|
|
9
|
+
if (encoding === AuxiliaryFileEncoding.Base64) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
const decoded = await decodeBase64(value);
|
|
13
|
+
if (encoding === AuxiliaryFileEncoding.Utf8) {
|
|
14
|
+
return bytesToString(decoded);
|
|
15
|
+
}
|
|
16
|
+
return bytesToHex(decoded);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
encodeAuxiliaryFile
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=chunk-2G4HD42C.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auxiliary-files.ts"],"sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport { bytesToHex, bytesToString } from '@metamask/utils';\n\nimport { decodeBase64 } from './base64';\n\n/**\n * Re-encodes an auxiliary file if needed depending on the requested file encoding.\n *\n * @param value - The base64 value stored for the auxiliary file.\n * @param encoding - The chosen encoding.\n * @returns The file encoded in the requested encoding.\n */\nexport async function encodeAuxiliaryFile(\n value: string,\n encoding: AuxiliaryFileEncoding,\n) {\n // Input is assumed to be the stored file in base64.\n if (encoding === AuxiliaryFileEncoding.Base64) {\n return value;\n }\n\n // TODO: Use @metamask/utils for this\n const decoded = await decodeBase64(value);\n if (encoding === AuxiliaryFileEncoding.Utf8) {\n return bytesToString(decoded);\n }\n\n return bytesToHex(decoded);\n}\n"],"mappings":";;;;;AAAA,SAAS,6BAA6B;AACtC,SAAS,YAAY,qBAAqB;AAW1C,eAAsB,oBACpB,OACA,UACA;AAEA,MAAI,aAAa,sBAAsB,QAAQ;AAC7C,WAAO;AAAA,EACT;AAGA,QAAM,UAAU,MAAM,aAAa,KAAK;AACxC,MAAI,aAAa,sBAAsB,MAAM;AAC3C,WAAO,cAAc,OAAO;AAAA,EAC9B;AAEA,SAAO,WAAW,OAAO;AAC3B;","names":[]}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import {
|
|
2
|
+
indent
|
|
3
|
+
} from "./chunk-7XA5VYYV.mjs";
|
|
4
|
+
|
|
5
|
+
// src/structs.ts
|
|
6
|
+
import { union } from "@metamask/snaps-sdk";
|
|
7
|
+
import { assert, isObject } from "@metamask/utils";
|
|
8
|
+
import { bold, green, red } from "chalk";
|
|
9
|
+
import {
|
|
10
|
+
is,
|
|
11
|
+
validate,
|
|
12
|
+
type as superstructType,
|
|
13
|
+
Struct,
|
|
14
|
+
StructError,
|
|
15
|
+
create
|
|
16
|
+
} from "superstruct";
|
|
17
|
+
function color(value, colorFunction, enabled) {
|
|
18
|
+
if (enabled) {
|
|
19
|
+
return colorFunction(value);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function named(name, struct) {
|
|
24
|
+
return new Struct({
|
|
25
|
+
...struct,
|
|
26
|
+
type: name
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var SnapsStructError = class extends StructError {
|
|
30
|
+
constructor(struct, prefix, suffix, failure, failures, colorize = true) {
|
|
31
|
+
super(failure, failures);
|
|
32
|
+
this.name = "SnapsStructError";
|
|
33
|
+
this.message = `${prefix}.
|
|
34
|
+
|
|
35
|
+
${getStructErrorMessage(
|
|
36
|
+
struct,
|
|
37
|
+
[...failures()],
|
|
38
|
+
colorize
|
|
39
|
+
)}${suffix ? `
|
|
40
|
+
|
|
41
|
+
${suffix}` : ""}`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function* arrayToGenerator(array) {
|
|
45
|
+
for (const item of array) {
|
|
46
|
+
yield item;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function getError({
|
|
50
|
+
struct,
|
|
51
|
+
prefix,
|
|
52
|
+
suffix = "",
|
|
53
|
+
error,
|
|
54
|
+
colorize
|
|
55
|
+
}) {
|
|
56
|
+
return new SnapsStructError(
|
|
57
|
+
struct,
|
|
58
|
+
prefix,
|
|
59
|
+
suffix,
|
|
60
|
+
error,
|
|
61
|
+
() => arrayToGenerator(error.failures()),
|
|
62
|
+
colorize
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function createFromStruct(value, struct, prefix, suffix = "") {
|
|
66
|
+
try {
|
|
67
|
+
return create(value, struct);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error instanceof StructError) {
|
|
70
|
+
throw getError({ struct, prefix, suffix, error });
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function getStructFromPath(struct, path) {
|
|
76
|
+
return path.reduce((result, key) => {
|
|
77
|
+
if (isObject(struct.schema) && struct.schema[key]) {
|
|
78
|
+
return struct.schema[key];
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}, struct);
|
|
82
|
+
}
|
|
83
|
+
function getUnionStructNames(struct, colorize = true) {
|
|
84
|
+
if (Array.isArray(struct.schema)) {
|
|
85
|
+
return struct.schema.map(({ type }) => color(type, green, colorize));
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function getStructErrorPrefix(failure, colorize = true) {
|
|
90
|
+
if (failure.type === "never" || failure.path.length === 0) {
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
return `At path: ${color(failure.path.join("."), bold, colorize)} \u2014 `;
|
|
94
|
+
}
|
|
95
|
+
function getStructFailureMessage(struct, failure, colorize = true) {
|
|
96
|
+
const received = color(JSON.stringify(failure.value), red, colorize);
|
|
97
|
+
const prefix = getStructErrorPrefix(failure, colorize);
|
|
98
|
+
if (failure.type === "union") {
|
|
99
|
+
const childStruct = getStructFromPath(struct, failure.path);
|
|
100
|
+
const unionNames = getUnionStructNames(childStruct, colorize);
|
|
101
|
+
if (unionNames) {
|
|
102
|
+
return `${prefix}Expected the value to be one of: ${unionNames.join(
|
|
103
|
+
", "
|
|
104
|
+
)}, but received: ${received}.`;
|
|
105
|
+
}
|
|
106
|
+
return `${prefix}${failure.message}.`;
|
|
107
|
+
}
|
|
108
|
+
if (failure.type === "literal") {
|
|
109
|
+
const message = failure.message.replace(
|
|
110
|
+
/the literal `(.+)`,/u,
|
|
111
|
+
`the value to be \`${color("$1", green, colorize)}\`,`
|
|
112
|
+
).replace(
|
|
113
|
+
/, but received: (.+)/u,
|
|
114
|
+
`, but received: ${color("$1", red, colorize)}`
|
|
115
|
+
);
|
|
116
|
+
return `${prefix}${message}.`;
|
|
117
|
+
}
|
|
118
|
+
if (failure.type === "never") {
|
|
119
|
+
return `Unknown key: ${color(
|
|
120
|
+
failure.path.join("."),
|
|
121
|
+
bold,
|
|
122
|
+
colorize
|
|
123
|
+
)}, received: ${received}.`;
|
|
124
|
+
}
|
|
125
|
+
if (failure.refinement === "size") {
|
|
126
|
+
const message = failure.message.replace(
|
|
127
|
+
/length between `(\d+)` and `(\d+)`/u,
|
|
128
|
+
`length between ${color("$1", green, colorize)} and ${color(
|
|
129
|
+
"$2",
|
|
130
|
+
green,
|
|
131
|
+
colorize
|
|
132
|
+
)},`
|
|
133
|
+
).replace(/length of `(\d+)`/u, `length of ${color("$1", red, colorize)}`).replace(/a array/u, "an array");
|
|
134
|
+
return `${prefix}${message}.`;
|
|
135
|
+
}
|
|
136
|
+
return `${prefix}Expected a value of type ${color(
|
|
137
|
+
failure.type,
|
|
138
|
+
green,
|
|
139
|
+
colorize
|
|
140
|
+
)}, but received: ${received}.`;
|
|
141
|
+
}
|
|
142
|
+
function getStructErrorMessage(struct, failures, colorize = true) {
|
|
143
|
+
const formattedFailures = failures.map(
|
|
144
|
+
(failure) => indent(`\u2022 ${getStructFailureMessage(struct, failure, colorize)}`)
|
|
145
|
+
);
|
|
146
|
+
return formattedFailures.join("\n");
|
|
147
|
+
}
|
|
148
|
+
function validateUnion(value, struct, structKey, coerce = false) {
|
|
149
|
+
assert(
|
|
150
|
+
struct.schema,
|
|
151
|
+
"Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`."
|
|
152
|
+
);
|
|
153
|
+
assert(struct.schema.length > 0, "Expected a non-empty array of structs.");
|
|
154
|
+
const keyUnion = struct.schema.map(
|
|
155
|
+
(innerStruct) => innerStruct.schema[structKey]
|
|
156
|
+
// This is guaranteed to be a non-empty array by the assertion above. We
|
|
157
|
+
// need to cast it since `superstruct` requires a non-empty array of structs
|
|
158
|
+
// for the `union` struct.
|
|
159
|
+
);
|
|
160
|
+
const key = superstructType({
|
|
161
|
+
[structKey]: union(keyUnion)
|
|
162
|
+
});
|
|
163
|
+
const [keyError] = validate(value, key, { coerce });
|
|
164
|
+
if (keyError) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
getStructFailureMessage(key, keyError.failures()[0], false)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
const objectValue = value;
|
|
170
|
+
const objectStructs = struct.schema.filter(
|
|
171
|
+
(innerStruct) => is(objectValue[structKey], innerStruct.schema[structKey])
|
|
172
|
+
);
|
|
173
|
+
assert(objectStructs.length > 0, "Expected a struct to match the value.");
|
|
174
|
+
const validationResults = objectStructs.map(
|
|
175
|
+
(objectStruct) => validate(objectValue, objectStruct, { coerce })
|
|
176
|
+
);
|
|
177
|
+
const validatedValue = validationResults.find(([error]) => !error);
|
|
178
|
+
if (validatedValue) {
|
|
179
|
+
return validatedValue[1];
|
|
180
|
+
}
|
|
181
|
+
assert(validationResults[0][0], "Expected at least one error.");
|
|
182
|
+
const validationError = validationResults.reduce((error, [innerError]) => {
|
|
183
|
+
assert(innerError, "Expected an error.");
|
|
184
|
+
if (innerError.failures().length < error.failures().length) {
|
|
185
|
+
return innerError;
|
|
186
|
+
}
|
|
187
|
+
return error;
|
|
188
|
+
}, validationResults[0][0]);
|
|
189
|
+
throw new Error(
|
|
190
|
+
getStructFailureMessage(struct, validationError.failures()[0], false)
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
function createUnion(value, struct, structKey) {
|
|
194
|
+
return validateUnion(value, struct, structKey, true);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export {
|
|
198
|
+
named,
|
|
199
|
+
SnapsStructError,
|
|
200
|
+
arrayToGenerator,
|
|
201
|
+
getError,
|
|
202
|
+
createFromStruct,
|
|
203
|
+
getStructFromPath,
|
|
204
|
+
getUnionStructNames,
|
|
205
|
+
getStructErrorPrefix,
|
|
206
|
+
getStructFailureMessage,
|
|
207
|
+
getStructErrorMessage,
|
|
208
|
+
validateUnion,
|
|
209
|
+
createUnion
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=chunk-2IVFF3AA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/structs.ts"],"sourcesContent":["import { union } from '@metamask/snaps-sdk';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert, isObject } from '@metamask/utils';\nimport { bold, green, red } from 'chalk';\nimport type { Failure } from 'superstruct';\nimport {\n is,\n validate,\n type as superstructType,\n Struct,\n StructError,\n create,\n} from 'superstruct';\nimport type { AnyStruct } from 'superstruct/dist/utils';\n\nimport { indent } from './strings';\n\n/**\n * Infer a struct type, only if it matches the specified type. This is useful\n * for defining types and structs that are related to each other in separate\n * files.\n *\n * @example\n * ```typescript\n * // In file A\n * export type GetFileArgs = {\n * path: string;\n * encoding?: EnumToUnion<AuxiliaryFileEncoding>;\n * };\n *\n * // In file B\n * export const GetFileArgsStruct = object(...);\n *\n * // If the type and struct are in the same file, this will return the type.\n * // Otherwise, it will return `never`.\n * export type GetFileArgs =\n * InferMatching<typeof GetFileArgsStruct, GetFileArgs>;\n * ```\n */\nexport type InferMatching<\n StructType extends Struct<any, any>,\n Type,\n> = StructType['TYPE'] extends Type ? Type : never;\n\n/**\n * Colorize a value with a color function. This is useful for colorizing values\n * in error messages. If colorization is disabled, the original value is\n * returned.\n *\n * @param value - The value to colorize.\n * @param colorFunction - The color function to use.\n * @param enabled - Whether to colorize the value.\n * @returns The colorized value, or the original value if colorization is\n * disabled.\n */\nfunction color(\n value: string,\n colorFunction: (value: string) => string,\n enabled: boolean,\n) {\n if (enabled) {\n return colorFunction(value);\n }\n\n return value;\n}\n\n/**\n * Define a struct, and also define the name of the struct as the given name.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n *\n * @param name - The name of the struct.\n * @param struct - The struct.\n * @returns The struct.\n */\nexport function named<Type, Schema>(\n name: string,\n struct: Struct<Type, Schema>,\n) {\n return new Struct({\n ...struct,\n type: name,\n });\n}\n\nexport class SnapsStructError<Type, Schema> extends StructError {\n constructor(\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix: string,\n failure: StructError,\n failures: () => Generator<Failure>,\n colorize = true,\n ) {\n super(failure, failures);\n\n this.name = 'SnapsStructError';\n this.message = `${prefix}.\\n\\n${getStructErrorMessage(\n struct,\n [...failures()],\n colorize,\n )}${suffix ? `\\n\\n${suffix}` : ''}`;\n }\n}\n\ntype GetErrorOptions<Type, Schema> = {\n struct: Struct<Type, Schema>;\n prefix: string;\n suffix?: string;\n error: StructError;\n colorize?: boolean;\n};\n\n/**\n * Converts an array to a generator function that yields the items in the\n * array.\n *\n * @param array - The array.\n * @returns A generator function.\n * @yields The items in the array.\n */\nexport function* arrayToGenerator<Type>(\n array: Type[],\n): Generator<Type, void, undefined> {\n for (const item of array) {\n yield item;\n }\n}\n\n/**\n * Returns a `SnapsStructError` with the given prefix and suffix.\n *\n * @param options - The options.\n * @param options.struct - The struct that caused the error.\n * @param options.prefix - The prefix to add to the error message.\n * @param options.suffix - The suffix to add to the error message. Defaults to\n * an empty string.\n * @param options.error - The `superstruct` error to wrap.\n * @param options.colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The `SnapsStructError`.\n */\nexport function getError<Type, Schema>({\n struct,\n prefix,\n suffix = '',\n error,\n colorize,\n}: GetErrorOptions<Type, Schema>) {\n return new SnapsStructError(\n struct,\n prefix,\n suffix,\n error,\n () => arrayToGenerator(error.failures()),\n colorize,\n );\n}\n\n/**\n * A wrapper of `superstruct`'s `create` function that throws a\n * `SnapsStructError` instead of a `StructError`. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` struct to validate the value against.\n * @param prefix - The prefix to add to the error message.\n * @param suffix - The suffix to add to the error message. Defaults to an empty\n * string.\n * @returns The validated value.\n */\nexport function createFromStruct<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix = '',\n) {\n try {\n return create(value, struct);\n } catch (error) {\n if (error instanceof StructError) {\n throw getError({ struct, prefix, suffix, error });\n }\n\n throw error;\n }\n}\n\n/**\n * Get a struct from a failure path.\n *\n * @param struct - The struct.\n * @param path - The failure path.\n * @returns The struct at the failure path.\n */\nexport function getStructFromPath<Type, Schema>(\n struct: Struct<Type, Schema>,\n path: string[],\n) {\n return path.reduce<AnyStruct>((result, key) => {\n if (isObject(struct.schema) && struct.schema[key]) {\n return struct.schema[key] as AnyStruct;\n }\n\n return result;\n }, struct);\n}\n\n/**\n * Get the union struct names from a struct.\n *\n * @param struct - The struct.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The union struct names, or `null` if the struct is not a union\n * struct.\n */\nexport function getUnionStructNames<Type, Schema>(\n struct: Struct<Type, Schema>,\n colorize = true,\n) {\n if (Array.isArray(struct.schema)) {\n return struct.schema.map(({ type }) => color(type, green, colorize));\n }\n\n return null;\n}\n\n/**\n * Get an error prefix from a `superstruct` failure. This is useful for\n * formatting the error message returned by `superstruct`.\n *\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The error prefix.\n */\nexport function getStructErrorPrefix(failure: Failure, colorize = true) {\n if (failure.type === 'never' || failure.path.length === 0) {\n return '';\n }\n\n return `At path: ${color(failure.path.join('.'), bold, colorize)} — `;\n}\n\n/**\n * Get a string describing the failure. This is similar to the `message`\n * property of `superstruct`'s `Failure` type, but formats the value in a more\n * readable way.\n *\n * @param struct - The struct that caused the failure.\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the failure.\n */\nexport function getStructFailureMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failure: Failure,\n colorize = true,\n) {\n const received = color(JSON.stringify(failure.value), red, colorize);\n const prefix = getStructErrorPrefix(failure, colorize);\n\n if (failure.type === 'union') {\n const childStruct = getStructFromPath(struct, failure.path);\n const unionNames = getUnionStructNames(childStruct, colorize);\n\n if (unionNames) {\n return `${prefix}Expected the value to be one of: ${unionNames.join(\n ', ',\n )}, but received: ${received}.`;\n }\n\n return `${prefix}${failure.message}.`;\n }\n\n if (failure.type === 'literal') {\n // Superstruct's failure does not provide information about which literal\n // value was expected, so we need to parse the message to get the literal.\n const message = failure.message\n .replace(\n /the literal `(.+)`,/u,\n `the value to be \\`${color('$1', green, colorize)}\\`,`,\n )\n .replace(\n /, but received: (.+)/u,\n `, but received: ${color('$1', red, colorize)}`,\n );\n\n return `${prefix}${message}.`;\n }\n\n if (failure.type === 'never') {\n return `Unknown key: ${color(\n failure.path.join('.'),\n bold,\n colorize,\n )}, received: ${received}.`;\n }\n\n if (failure.refinement === 'size') {\n const message = failure.message\n .replace(\n /length between `(\\d+)` and `(\\d+)`/u,\n `length between ${color('$1', green, colorize)} and ${color(\n '$2',\n green,\n colorize,\n )},`,\n )\n .replace(/length of `(\\d+)`/u, `length of ${color('$1', red, colorize)}`)\n .replace(/a array/u, 'an array');\n\n return `${prefix}${message}.`;\n }\n\n return `${prefix}Expected a value of type ${color(\n failure.type,\n green,\n colorize,\n )}, but received: ${received}.`;\n}\n\n/**\n * Get a string describing the errors. This formats all the errors in a\n * human-readable way.\n *\n * @param struct - The struct that caused the failures.\n * @param failures - The `superstruct` failures.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the errors.\n */\nexport function getStructErrorMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failures: Failure[],\n colorize = true,\n) {\n const formattedFailures = failures.map((failure) =>\n indent(`• ${getStructFailureMessage(struct, failure, colorize)}`),\n );\n\n return formattedFailures.join('\\n');\n}\n\n/**\n * Validate a union struct, and throw readable errors if the value does not\n * satisfy the struct. This is useful for improving the error messages returned\n * by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @param coerce - Whether to coerce the value to satisfy the struct. Defaults\n * to `false`.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @example\n * const struct = union([\n * object({ type: literal('a'), value: string() }),\n * object({ type: literal('b'), value: number() }),\n * object({ type: literal('c'), value: boolean() }),\n * // ...\n * ]);\n *\n * // At path: type — Expected the value to be one of: \"a\", \"b\", \"c\", but received: \"d\".\n * validateUnion({ type: 'd', value: 'foo' }, struct, 'type');\n *\n * // At path: value — Expected a value of type string, but received: 42.\n * validateUnion({ type: 'a', value: 42 }, struct, 'value');\n */\nexport function validateUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n coerce = false,\n) {\n assert(\n struct.schema,\n 'Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`.',\n );\n assert(struct.schema.length > 0, 'Expected a non-empty array of structs.');\n\n const keyUnion = struct.schema.map(\n (innerStruct) => innerStruct.schema[structKey],\n // This is guaranteed to be a non-empty array by the assertion above. We\n // need to cast it since `superstruct` requires a non-empty array of structs\n // for the `union` struct.\n ) as NonEmptyArray<Struct>;\n\n const key = superstructType({\n [structKey]: union(keyUnion),\n });\n\n const [keyError] = validate(value, key, { coerce });\n if (keyError) {\n throw new Error(\n getStructFailureMessage(key, keyError.failures()[0], false),\n );\n }\n\n // At this point it's guaranteed that the value is an object, so we can safely\n // cast it to a Record.\n const objectValue = value as Record<PropertyKey, unknown>;\n const objectStructs = struct.schema.filter((innerStruct) =>\n is(objectValue[structKey], innerStruct.schema[structKey]),\n );\n\n assert(objectStructs.length > 0, 'Expected a struct to match the value.');\n\n // We need to validate the value against all the object structs that match the\n // struct key, and return the first validated value.\n const validationResults = objectStructs.map((objectStruct) =>\n validate(objectValue, objectStruct, { coerce }),\n );\n\n const validatedValue = validationResults.find(([error]) => !error);\n if (validatedValue) {\n return validatedValue[1];\n }\n\n assert(validationResults[0][0], 'Expected at least one error.');\n\n // If there is no validated value, we need to find the error with the least\n // number of failures (with the assumption that it's the most specific error).\n const validationError = validationResults.reduce((error, [innerError]) => {\n assert(innerError, 'Expected an error.');\n if (innerError.failures().length < error.failures().length) {\n return innerError;\n }\n\n return error;\n }, validationResults[0][0]);\n\n throw new Error(\n getStructFailureMessage(struct, validationError.failures()[0], false),\n );\n}\n\n/**\n * Create a value with the coercion logic of a union struct, and throw readable\n * errors if the value does not satisfy the struct. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @see validateUnion\n */\nexport function createUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n) {\n return validateUnion(value, struct, structKey, true);\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/cronjob.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _utils = require('@metamask/utils');
|
|
7
|
+
var _cronparser = require('cron-parser');
|
|
8
|
+
var _superstruct = require('superstruct');
|
|
9
|
+
var CronjobRpcRequestStruct = _superstruct.object.call(void 0, {
|
|
10
|
+
jsonrpc: _superstruct.optional.call(void 0, _utils.JsonRpcVersionStruct),
|
|
11
|
+
id: _superstruct.optional.call(void 0, _utils.JsonRpcIdStruct),
|
|
12
|
+
method: _superstruct.string.call(void 0, ),
|
|
13
|
+
params: _superstruct.optional.call(void 0, _utils.JsonRpcParamsStruct)
|
|
14
|
+
});
|
|
15
|
+
var CronExpressionStruct = _superstruct.refine.call(void 0,
|
|
16
|
+
_superstruct.string.call(void 0, ),
|
|
17
|
+
"CronExpression",
|
|
18
|
+
(value) => {
|
|
19
|
+
try {
|
|
20
|
+
_cronparser.parseExpression.call(void 0, value);
|
|
21
|
+
return true;
|
|
22
|
+
} catch (e) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
function parseCronExpression(expression) {
|
|
28
|
+
const ensureStringExpression = _superstruct.create.call(void 0, expression, CronExpressionStruct);
|
|
29
|
+
return _cronparser.parseExpression.call(void 0, ensureStringExpression);
|
|
30
|
+
}
|
|
31
|
+
var CronjobSpecificationStruct = _superstruct.object.call(void 0, {
|
|
32
|
+
expression: CronExpressionStruct,
|
|
33
|
+
request: CronjobRpcRequestStruct
|
|
34
|
+
});
|
|
35
|
+
function isCronjobSpecification(value) {
|
|
36
|
+
try {
|
|
37
|
+
_superstruct.create.call(void 0, value, CronjobSpecificationStruct);
|
|
38
|
+
return true;
|
|
39
|
+
} catch (e2) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var CronjobSpecificationArrayStruct = _superstruct.array.call(void 0,
|
|
44
|
+
CronjobSpecificationStruct
|
|
45
|
+
);
|
|
46
|
+
function isCronjobSpecificationArray(value) {
|
|
47
|
+
try {
|
|
48
|
+
_superstruct.create.call(void 0, value, CronjobSpecificationArrayStruct);
|
|
49
|
+
return true;
|
|
50
|
+
} catch (e3) {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
exports.CronjobRpcRequestStruct = CronjobRpcRequestStruct; exports.CronExpressionStruct = CronExpressionStruct; exports.parseCronExpression = parseCronExpression; exports.CronjobSpecificationStruct = CronjobSpecificationStruct; exports.isCronjobSpecification = isCronjobSpecification; exports.CronjobSpecificationArrayStruct = CronjobSpecificationArrayStruct; exports.isCronjobSpecificationArray = isCronjobSpecificationArray;
|
|
64
|
+
//# sourceMappingURL=chunk-2QS3W66J.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cronjob.ts"],"names":[],"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","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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";//# sourceMappingURL=chunk-2XF32FCF.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|