@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,9 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/strings.ts
|
|
2
|
+
function indent(message, spaces = 2) {
|
|
3
|
+
return message.replace(/^/gmu, " ".repeat(spaces));
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.indent = indent;
|
|
9
|
+
//# sourceMappingURL=chunk-6WBLB5BX.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/strings.ts"],"names":[],"mappings":";AAOO,SAAS,OAAO,SAAiB,SAAS,GAAG;AAClD,SAAO,QAAQ,QAAQ,QAAQ,IAAI,OAAO,MAAM,CAAC;AACnD","sourcesContent":["/**\n * Indent a message by adding a number of spaces to the beginning of each line.\n *\n * @param message - The message to indent.\n * @param spaces - The number of spaces to indent by. Defaults to 2.\n * @returns The indented message.\n */\nexport function indent(message: string, spaces = 2) {\n return message.replace(/^/gmu, ' '.repeat(spaces));\n}\n"]}
|
|
@@ -0,0 +1,70 @@
|
|
|
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/ui.ts
|
|
2
|
+
var _snapssdk = require('@metamask/snaps-sdk');
|
|
3
|
+
var _utils = require('@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 = _optionalChain([groups, 'optionalAccess', _ => _.url]);
|
|
10
|
+
if (!link) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
try {
|
|
14
|
+
const url = new URL(link);
|
|
15
|
+
_utils.assert.call(void 0,
|
|
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
|
+
_utils.assert.call(void 0, !isOnPhishingList(hostname), "The specified URL is not allowed.");
|
|
21
|
+
} catch (error) {
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Invalid URL: ${error instanceof _utils.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 _snapssdk.NodeType.Panel:
|
|
32
|
+
component.children.forEach(
|
|
33
|
+
(node) => validateComponentLinks(node, isOnPhishingList)
|
|
34
|
+
);
|
|
35
|
+
break;
|
|
36
|
+
case _snapssdk.NodeType.Row:
|
|
37
|
+
validateComponentLinks(component.value, isOnPhishingList);
|
|
38
|
+
break;
|
|
39
|
+
case _snapssdk.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 _snapssdk.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 _snapssdk.NodeType.Row:
|
|
57
|
+
return getTotalTextLength(component.value);
|
|
58
|
+
case _snapssdk.NodeType.Text:
|
|
59
|
+
return component.value.length;
|
|
60
|
+
default:
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
exports.validateTextLinks = validateTextLinks; exports.validateComponentLinks = validateComponentLinks; exports.getTotalTextLength = getTotalTextLength;
|
|
70
|
+
//# sourceMappingURL=chunk-7H5TGXZ5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/ui.ts"],"names":[],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,QAAQ,sBAAsB;AAEvC,IAAM,sBAAsB;AAE5B,IAAM,oBAAoB,CAAC,UAAU,SAAS;AAUvC,SAAS,kBACd,MACA,kBACA;AACA,QAAM,UAAU,OAAO,UAAU,SAAS,KAAK,MAAM,mBAAmB;AAExE,aAAW,EAAE,OAAO,KAAK,SAAS;AAChC,UAAM,OAAO,QAAQ;AAIrB,QAAI,CAAC,MAAM;AACT;AAAA,IACF;AAEA,QAAI;AACF,YAAM,MAAM,IAAI,IAAI,IAAI;AACxB;AAAA,QACE,kBAAkB,SAAS,IAAI,QAAQ;AAAA,QACvC,4BAA4B,kBAAkB,KAAK,IAAI,CAAC;AAAA,MAC1D;AAEA,YAAM,WACJ,IAAI,aAAa,YAAY,IAAI,SAAS,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI;AAEhE,aAAO,CAAC,iBAAiB,QAAQ,GAAG,mCAAmC;AAAA,IACzE,SAAS,OAAO;AACd,YAAM,IAAI;AAAA,QACR,gBACE,iBAAiB,iBACb,MAAM,UACN,sBACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAWO,SAAS,uBACd,WACA,kBACA;AACA,QAAM,EAAE,KAAK,IAAI;AACjB,UAAQ,MAAM;AAAA,IACZ,KAAK,SAAS;AACZ,gBAAU,SAAS;AAAA,QAAQ,CAAC,SAC1B,uBAAuB,MAAM,gBAAgB;AAAA,MAC/C;AACA;AAAA,IACF,KAAK,SAAS;AACZ,6BAAuB,UAAU,OAAO,gBAAgB;AACxD;AAAA,IACF,KAAK,SAAS;AACZ,wBAAkB,UAAU,OAAO,gBAAgB;AACnD;AAAA,IACF;AACE;AAAA,EACJ;AACF;AAQO,SAAS,mBAAmB,WAA8B;AAC/D,QAAM,EAAE,KAAK,IAAI;AAEjB,UAAQ,MAAM;AAAA,IACZ,KAAK,SAAS;AACZ,aAAO,UAAU,SAAS;AAAA;AAAA;AAAA,QAGxB,CAAC,KAAK,SAAS,MAAM,mBAAmB,IAAI;AAAA,QAC5C;AAAA,MACF;AAAA,IACF,KAAK,SAAS;AACZ,aAAO,mBAAmB,UAAU,KAAK;AAAA,IAC3C,KAAK,SAAS;AACZ,aAAO,UAAU,MAAM;AAAA,IACzB;AACE,aAAO;AAAA,EACX;AACF","sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport { NodeType } from '@metamask/snaps-sdk';\nimport { assert, AssertionError } from '@metamask/utils';\n\nconst MARKDOWN_LINK_REGEX = /\\[(?<name>[^\\]]*)\\]\\((?<url>[^)]+)\\)/giu;\n\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n\n/**\n * Searches for markdown links in a string and checks them against the phishing list.\n *\n * @param text - The text to verify.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the text contains a link that is not allowed.\n */\nexport function validateTextLinks(\n text: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n const matches = String.prototype.matchAll.call(text, MARKDOWN_LINK_REGEX);\n\n for (const { groups } of matches) {\n const link = groups?.url;\n\n /* This case should never happen with the regex but the TS type allows for undefined */\n /* istanbul ignore next */\n if (!link) {\n continue;\n }\n\n try {\n const url = new URL(link);\n assert(\n ALLOWED_PROTOCOLS.includes(url.protocol),\n `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`,\n );\n\n const hostname =\n url.protocol === 'mailto:' ? url.pathname.split('@')[1] : url.hostname;\n\n assert(!isOnPhishingList(hostname), 'The specified URL is not allowed.');\n } catch (error) {\n throw new Error(\n `Invalid URL: ${\n error instanceof AssertionError\n ? error.message\n : 'Unable to parse URL.'\n }`,\n );\n }\n }\n}\n\n/**\n * Search for links in UI components and check that the URL they are trying to\n * pass in is not in the phishing list.\n *\n * @param component - The custom UI component.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the component contains a link that is not allowed.\n */\nexport function validateComponentLinks(\n component: Component,\n isOnPhishingList: (url: string) => boolean,\n) {\n const { type } = component;\n switch (type) {\n case NodeType.Panel:\n component.children.forEach((node) =>\n validateComponentLinks(node, isOnPhishingList),\n );\n break;\n case NodeType.Row:\n validateComponentLinks(component.value, isOnPhishingList);\n break;\n case NodeType.Text:\n validateTextLinks(component.value, isOnPhishingList);\n break;\n default:\n break;\n }\n}\n\n/**\n * Calculate the total length of all text in the component.\n *\n * @param component - A custom UI component.\n * @returns The total length of all text components in the component.\n */\nexport function getTotalTextLength(component: Component): number {\n const { type } = component;\n\n switch (type) {\n case NodeType.Panel:\n return component.children.reduce<number>(\n // This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n (sum, node) => sum + getTotalTextLength(node),\n 0,\n );\n case NodeType.Row:\n return getTotalTextLength(component.value);\n case NodeType.Text:\n return component.value.length;\n default:\n return 0;\n }\n}\n"]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkR4BBIGBNjs = require('./chunk-R4BBIGBN.js');
|
|
4
|
+
|
|
5
|
+
// src/base64.ts
|
|
6
|
+
var _utils = require('@metamask/utils');
|
|
7
|
+
async function encodeBase64(input) {
|
|
8
|
+
const bytes = _chunkR4BBIGBNjs.getBytes.call(void 0, input);
|
|
9
|
+
if ("FileReader" in globalThis) {
|
|
10
|
+
return await new Promise((resolve, reject) => {
|
|
11
|
+
const reader = Object.assign(new FileReader(), {
|
|
12
|
+
onload: () => resolve(
|
|
13
|
+
reader.result.replace(
|
|
14
|
+
"data:application/octet-stream;base64,",
|
|
15
|
+
""
|
|
16
|
+
)
|
|
17
|
+
),
|
|
18
|
+
onerror: () => reject(reader.error)
|
|
19
|
+
});
|
|
20
|
+
reader.readAsDataURL(
|
|
21
|
+
new File([bytes], "", { type: "application/octet-stream" })
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return _utils.bytesToBase64.call(void 0, bytes);
|
|
26
|
+
}
|
|
27
|
+
async function decodeBase64(base64) {
|
|
28
|
+
const response = await fetch(
|
|
29
|
+
`data:application/octet-stream;base64,${base64}`
|
|
30
|
+
);
|
|
31
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
exports.encodeBase64 = encodeBase64; exports.decodeBase64 = decodeBase64;
|
|
38
|
+
//# sourceMappingURL=chunk-7KKLGQNE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/base64.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,qBAAqB;AAW9B,eAAsB,aAAa,OAA0C;AAC3E,QAAM,QAAQ,SAAS,KAAK;AAE5B,MAAI,gBAAgB,YAAY;AAC9B,WAAO,MAAM,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC5C,YAAM,SAAS,OAAO,OAAO,IAAI,WAAW,GAAG;AAAA,QAC7C,QAAQ,MACN;AAAA,UACG,OAAO,OAAkB;AAAA,YACxB;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACF,SAAS,MAAM,OAAO,OAAO,KAAK;AAAA,MACpC,CAAC;AACD,aAAO;AAAA,QACL,IAAI,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAAA,MAC5D;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,cAAc,KAAK;AAC5B;AAQA,eAAsB,aAAa,QAAgB;AACjD,QAAM,WAAW,MAAM;AAAA,IACrB,wCAAwC,MAAM;AAAA,EAChD;AACA,SAAO,IAAI,WAAW,MAAM,SAAS,YAAY,CAAC;AACpD","sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\n\nimport { getBytes } from './bytes';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Provides fast, asynchronous base64 encoding.\n *\n * @param input - The input value, assumed to be coercable to bytes.\n * @returns A base64 string.\n */\nexport async function encodeBase64(input: Uint8Array | VirtualFile | string) {\n const bytes = getBytes(input);\n // In the browser, FileReader is much faster than bytesToBase64.\n if ('FileReader' in globalThis) {\n return await new Promise((resolve, reject) => {\n const reader = Object.assign(new FileReader(), {\n onload: () =>\n resolve(\n (reader.result as string).replace(\n 'data:application/octet-stream;base64,',\n '',\n ),\n ),\n onerror: () => reject(reader.error),\n });\n reader.readAsDataURL(\n new File([bytes], '', { type: 'application/octet-stream' }),\n );\n });\n }\n return bytesToBase64(bytes);\n}\n\n/**\n * Provides fast, asynchronous base64 decoding.\n *\n * @param base64 - A base64 string.\n * @returns A Uint8Array of bytes.\n */\nexport async function decodeBase64(base64: string) {\n const response = await fetch(\n `data:application/octet-stream;base64,${base64}`,\n );\n return new Uint8Array(await response.arrayBuffer());\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk7KKLGQNEjs = require('./chunk-7KKLGQNE.js');
|
|
4
|
+
|
|
5
|
+
// src/auxiliary-files.ts
|
|
6
|
+
var _snapssdk = require('@metamask/snaps-sdk');
|
|
7
|
+
var _utils = require('@metamask/utils');
|
|
8
|
+
async function encodeAuxiliaryFile(value, encoding) {
|
|
9
|
+
if (encoding === _snapssdk.AuxiliaryFileEncoding.Base64) {
|
|
10
|
+
return value;
|
|
11
|
+
}
|
|
12
|
+
const decoded = await _chunk7KKLGQNEjs.decodeBase64.call(void 0, value);
|
|
13
|
+
if (encoding === _snapssdk.AuxiliaryFileEncoding.Utf8) {
|
|
14
|
+
return _utils.bytesToString.call(void 0, decoded);
|
|
15
|
+
}
|
|
16
|
+
return _utils.bytesToHex.call(void 0, decoded);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.encodeAuxiliaryFile = encodeAuxiliaryFile;
|
|
22
|
+
//# sourceMappingURL=chunk-7PNGOFLU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/auxiliary-files.ts"],"names":[],"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","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"]}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// src/namespace.ts
|
|
2
|
+
import {
|
|
3
|
+
array,
|
|
4
|
+
define,
|
|
5
|
+
is,
|
|
6
|
+
object,
|
|
7
|
+
optional,
|
|
8
|
+
pattern,
|
|
9
|
+
size,
|
|
10
|
+
string
|
|
11
|
+
} from "superstruct";
|
|
12
|
+
var CHAIN_ID_REGEX = /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u;
|
|
13
|
+
var ACCOUNT_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})):(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;
|
|
14
|
+
var ACCOUNT_ADDRESS_REGEX = /^(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;
|
|
15
|
+
function parseChainId(chainId) {
|
|
16
|
+
const match = CHAIN_ID_REGEX.exec(chainId);
|
|
17
|
+
if (!match?.groups) {
|
|
18
|
+
throw new Error("Invalid chain ID.");
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
namespace: match.groups.namespace,
|
|
22
|
+
reference: match.groups.reference
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function parseAccountId(accountId) {
|
|
26
|
+
const match = ACCOUNT_ID_REGEX.exec(accountId);
|
|
27
|
+
if (!match?.groups) {
|
|
28
|
+
throw new Error("Invalid account ID.");
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
address: match.groups.accountAddress,
|
|
32
|
+
chainId: match.groups.chainId,
|
|
33
|
+
chain: {
|
|
34
|
+
namespace: match.groups.namespace,
|
|
35
|
+
reference: match.groups.reference
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var LimitedString = size(string(), 1, 40);
|
|
40
|
+
var ChainIdStringStruct = define(
|
|
41
|
+
"Chain ID",
|
|
42
|
+
string().validator
|
|
43
|
+
);
|
|
44
|
+
var ChainIdStruct = pattern(
|
|
45
|
+
ChainIdStringStruct,
|
|
46
|
+
CHAIN_ID_REGEX
|
|
47
|
+
);
|
|
48
|
+
var AccountIdStruct = pattern(string(), ACCOUNT_ID_REGEX);
|
|
49
|
+
var AccountIdArrayStruct = array(AccountIdStruct);
|
|
50
|
+
var AccountAddressStruct = pattern(string(), ACCOUNT_ADDRESS_REGEX);
|
|
51
|
+
var ChainStruct = object({
|
|
52
|
+
id: ChainIdStruct,
|
|
53
|
+
name: LimitedString
|
|
54
|
+
});
|
|
55
|
+
var NamespaceStruct = object({
|
|
56
|
+
/**
|
|
57
|
+
* A list of supported chains in the namespace.
|
|
58
|
+
*/
|
|
59
|
+
chains: array(ChainStruct),
|
|
60
|
+
/**
|
|
61
|
+
* A list of supported RPC methods on the namespace, that a DApp can call.
|
|
62
|
+
*/
|
|
63
|
+
methods: optional(array(LimitedString)),
|
|
64
|
+
/**
|
|
65
|
+
* A list of supported RPC events on the namespace, that a DApp can listen to.
|
|
66
|
+
*/
|
|
67
|
+
events: optional(array(LimitedString))
|
|
68
|
+
});
|
|
69
|
+
var NamespaceIdStruct = pattern(string(), /^[-a-z0-9]{3,8}$/u);
|
|
70
|
+
function isNamespaceId(value) {
|
|
71
|
+
return is(value, NamespaceIdStruct);
|
|
72
|
+
}
|
|
73
|
+
function isChainId(value) {
|
|
74
|
+
return is(value, ChainIdStruct);
|
|
75
|
+
}
|
|
76
|
+
function isAccountId(value) {
|
|
77
|
+
return is(value, AccountIdStruct);
|
|
78
|
+
}
|
|
79
|
+
function isAccountIdArray(value) {
|
|
80
|
+
return is(value, AccountIdArrayStruct);
|
|
81
|
+
}
|
|
82
|
+
function isNamespace(value) {
|
|
83
|
+
return is(value, NamespaceStruct);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export {
|
|
87
|
+
CHAIN_ID_REGEX,
|
|
88
|
+
ACCOUNT_ID_REGEX,
|
|
89
|
+
ACCOUNT_ADDRESS_REGEX,
|
|
90
|
+
parseChainId,
|
|
91
|
+
parseAccountId,
|
|
92
|
+
LimitedString,
|
|
93
|
+
ChainIdStringStruct,
|
|
94
|
+
ChainIdStruct,
|
|
95
|
+
AccountIdStruct,
|
|
96
|
+
AccountIdArrayStruct,
|
|
97
|
+
AccountAddressStruct,
|
|
98
|
+
ChainStruct,
|
|
99
|
+
NamespaceStruct,
|
|
100
|
+
NamespaceIdStruct,
|
|
101
|
+
isNamespaceId,
|
|
102
|
+
isChainId,
|
|
103
|
+
isAccountId,
|
|
104
|
+
isAccountIdArray,
|
|
105
|
+
isNamespace
|
|
106
|
+
};
|
|
107
|
+
//# sourceMappingURL=chunk-7T3N2ZGQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/namespace.ts"],"sourcesContent":["import type { AccountId, ChainId } from '@metamask/snaps-sdk';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n define,\n is,\n object,\n optional,\n pattern,\n size,\n string,\n} from 'superstruct';\n\nimport type { InferMatching } from './structs';\n\nexport const CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u;\n\nexport const ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})):(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;\n\nexport const ACCOUNT_ADDRESS_REGEX = /^(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;\n\n/**\n * Parse a chain ID string to an object containing the namespace and reference.\n * This validates the chain ID before parsing it.\n *\n * @param chainId - The chain ID to validate and parse.\n * @returns The parsed chain ID.\n */\nexport function parseChainId(chainId: ChainId): {\n namespace: NamespaceId;\n reference: string;\n} {\n const match = CHAIN_ID_REGEX.exec(chainId);\n if (!match?.groups) {\n throw new Error('Invalid chain ID.');\n }\n\n return {\n namespace: match.groups.namespace,\n reference: match.groups.reference,\n };\n}\n\n/**\n * Parse an account ID to an object containing the chain, chain ID and address.\n * This validates the account ID before parsing it.\n *\n * @param accountId - The account ID to validate and parse.\n * @returns The parsed account ID.\n */\nexport function parseAccountId(accountId: AccountId): {\n chain: { namespace: NamespaceId; reference: string };\n chainId: ChainId;\n address: string;\n} {\n const match = ACCOUNT_ID_REGEX.exec(accountId);\n if (!match?.groups) {\n throw new Error('Invalid account ID.');\n }\n\n return {\n address: match.groups.accountAddress,\n chainId: match.groups.chainId as ChainId,\n chain: {\n namespace: match.groups.namespace,\n reference: match.groups.reference,\n },\n };\n}\n\n/**\n * A helper struct for a string with a minimum length of 1 and a maximum length\n * of 40.\n */\nexport const LimitedString = size(string(), 1, 40);\n\nexport const ChainIdStringStruct = define<ChainId>(\n 'Chain ID',\n string().validator,\n);\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const ChainIdStruct = pattern<ChainId, null>(\n ChainIdStringStruct,\n CHAIN_ID_REGEX,\n);\n\nexport type Caip2ChainId = InferMatching<typeof ChainIdStruct, ChainId>;\n\nexport const AccountIdStruct = pattern(string(), ACCOUNT_ID_REGEX);\n\nexport const AccountIdArrayStruct = array(AccountIdStruct);\nexport const AccountAddressStruct = pattern(string(), ACCOUNT_ADDRESS_REGEX);\nexport type AccountAddress = Infer<typeof AccountAddressStruct>;\n\n/**\n * A chain descriptor.\n */\nexport const ChainStruct = object({\n id: ChainIdStruct,\n name: LimitedString,\n});\nexport type Chain = Infer<typeof ChainStruct>;\n\nexport const NamespaceStruct = object({\n /**\n * A list of supported chains in the namespace.\n */\n chains: array(ChainStruct),\n\n /**\n * A list of supported RPC methods on the namespace, that a DApp can call.\n */\n methods: optional(array(LimitedString)),\n\n /**\n * A list of supported RPC events on the namespace, that a DApp can listen to.\n */\n events: optional(array(LimitedString)),\n});\nexport type Namespace = Infer<typeof NamespaceStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a chain ID.\n */\nexport const NamespaceIdStruct = pattern(string(), /^[-a-z0-9]{3,8}$/u);\nexport type NamespaceId = Infer<typeof NamespaceIdStruct>;\n\n/**\n * Check if the given value is a CAIP-2 namespace ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-2 namespace ID.\n */\nexport function isNamespaceId(value: unknown): value is NamespaceId {\n return is(value, NamespaceIdStruct);\n}\n\n/**\n * Check if the given value is a CAIP-2 chain ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-2 chain ID.\n */\nexport function isChainId(value: unknown): value is ChainId {\n return is(value, ChainIdStruct);\n}\n\n/**\n * Check if the given value is a CAIP-10 account ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-10 account ID.\n */\nexport function isAccountId(value: unknown): value is AccountId {\n return is(value, AccountIdStruct);\n}\n\n/**\n * Check if the given value is an array of CAIP-10 account IDs.\n *\n * @param value - The value to check.\n * @returns Whether the value is an array of CAIP-10 account IDs.\n */\nexport function isAccountIdArray(value: unknown): value is AccountId[] {\n return is(value, AccountIdArrayStruct);\n}\n\n/**\n * Check if a value is a {@link Namespace}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link Namespace}.\n */\nexport function isNamespace(value: unknown): value is Namespace {\n return is(value, NamespaceStruct);\n}\n"],"mappings":";AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIA,IAAM,iBACX;AAEK,IAAM,mBACX;AAEK,IAAM,wBAAwB;AAS9B,SAAS,aAAa,SAG3B;AACA,QAAM,QAAQ,eAAe,KAAK,OAAO;AACzC,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACrC;AAEA,SAAO;AAAA,IACL,WAAW,MAAM,OAAO;AAAA,IACxB,WAAW,MAAM,OAAO;AAAA,EAC1B;AACF;AASO,SAAS,eAAe,WAI7B;AACA,QAAM,QAAQ,iBAAiB,KAAK,SAAS;AAC7C,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAEA,SAAO;AAAA,IACL,SAAS,MAAM,OAAO;AAAA,IACtB,SAAS,MAAM,OAAO;AAAA,IACtB,OAAO;AAAA,MACL,WAAW,MAAM,OAAO;AAAA,MACxB,WAAW,MAAM,OAAO;AAAA,IAC1B;AAAA,EACF;AACF;AAMO,IAAM,gBAAgB,KAAK,OAAO,GAAG,GAAG,EAAE;AAE1C,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA,OAAO,EAAE;AACX;AAKO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AACF;AAIO,IAAM,kBAAkB,QAAQ,OAAO,GAAG,gBAAgB;AAE1D,IAAM,uBAAuB,MAAM,eAAe;AAClD,IAAM,uBAAuB,QAAQ,OAAO,GAAG,qBAAqB;AAMpE,IAAM,cAAc,OAAO;AAAA,EAChC,IAAI;AAAA,EACJ,MAAM;AACR,CAAC;AAGM,IAAM,kBAAkB,OAAO;AAAA;AAAA;AAAA;AAAA,EAIpC,QAAQ,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA,EAKzB,SAAS,SAAS,MAAM,aAAa,CAAC;AAAA;AAAA;AAAA;AAAA,EAKtC,QAAQ,SAAS,MAAM,aAAa,CAAC;AACvC,CAAC;AAMM,IAAM,oBAAoB,QAAQ,OAAO,GAAG,mBAAmB;AAS/D,SAAS,cAAc,OAAsC;AAClE,SAAO,GAAG,OAAO,iBAAiB;AACpC;AAQO,SAAS,UAAU,OAAkC;AAC1D,SAAO,GAAG,OAAO,aAAa;AAChC;AAQO,SAAS,YAAY,OAAoC;AAC9D,SAAO,GAAG,OAAO,eAAe;AAClC;AAQO,SAAS,iBAAiB,OAAsC;AACrE,SAAO,GAAG,OAAO,oBAAoB;AACvC;AAQO,SAAS,YAAY,OAAoC;AAC9D,SAAO,GAAG,OAAO,eAAe;AAClC;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/strings.ts"],"sourcesContent":["/**\n * Indent a message by adding a number of spaces to the beginning of each line.\n *\n * @param message - The message to indent.\n * @param spaces - The number of spaces to indent by. Defaults to 2.\n * @returns The indented message.\n */\nexport function indent(message: string, spaces = 2) {\n return message.replace(/^/gmu, ' '.repeat(spaces));\n}\n"],"mappings":";AAOO,SAAS,OAAO,SAAiB,SAAS,GAAG;AAClD,SAAO,QAAQ,QAAQ,QAAQ,IAAI,OAAO,MAAM,CAAC;AACnD;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/deep-clone.ts"],"sourcesContent":["import rfdc from 'rfdc';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n"],"mappings":";AAAA,OAAO,UAAU;AAEV,IAAM,YAAY,KAAK,EAAE,OAAO,OAAO,SAAS,MAAM,CAAC;","names":[]}
|
|
@@ -0,0 +1,107 @@
|
|
|
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/namespace.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
var _superstruct = require('superstruct');
|
|
12
|
+
var CHAIN_ID_REGEX = /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u;
|
|
13
|
+
var ACCOUNT_ID_REGEX = /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})):(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;
|
|
14
|
+
var ACCOUNT_ADDRESS_REGEX = /^(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;
|
|
15
|
+
function parseChainId(chainId) {
|
|
16
|
+
const match = CHAIN_ID_REGEX.exec(chainId);
|
|
17
|
+
if (!_optionalChain([match, 'optionalAccess', _ => _.groups])) {
|
|
18
|
+
throw new Error("Invalid chain ID.");
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
namespace: match.groups.namespace,
|
|
22
|
+
reference: match.groups.reference
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function parseAccountId(accountId) {
|
|
26
|
+
const match = ACCOUNT_ID_REGEX.exec(accountId);
|
|
27
|
+
if (!_optionalChain([match, 'optionalAccess', _2 => _2.groups])) {
|
|
28
|
+
throw new Error("Invalid account ID.");
|
|
29
|
+
}
|
|
30
|
+
return {
|
|
31
|
+
address: match.groups.accountAddress,
|
|
32
|
+
chainId: match.groups.chainId,
|
|
33
|
+
chain: {
|
|
34
|
+
namespace: match.groups.namespace,
|
|
35
|
+
reference: match.groups.reference
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
var LimitedString = _superstruct.size.call(void 0, _superstruct.string.call(void 0, ), 1, 40);
|
|
40
|
+
var ChainIdStringStruct = _superstruct.define.call(void 0,
|
|
41
|
+
"Chain ID",
|
|
42
|
+
_superstruct.string.call(void 0, ).validator
|
|
43
|
+
);
|
|
44
|
+
var ChainIdStruct = _superstruct.pattern.call(void 0,
|
|
45
|
+
ChainIdStringStruct,
|
|
46
|
+
CHAIN_ID_REGEX
|
|
47
|
+
);
|
|
48
|
+
var AccountIdStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), ACCOUNT_ID_REGEX);
|
|
49
|
+
var AccountIdArrayStruct = _superstruct.array.call(void 0, AccountIdStruct);
|
|
50
|
+
var AccountAddressStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), ACCOUNT_ADDRESS_REGEX);
|
|
51
|
+
var ChainStruct = _superstruct.object.call(void 0, {
|
|
52
|
+
id: ChainIdStruct,
|
|
53
|
+
name: LimitedString
|
|
54
|
+
});
|
|
55
|
+
var NamespaceStruct = _superstruct.object.call(void 0, {
|
|
56
|
+
/**
|
|
57
|
+
* A list of supported chains in the namespace.
|
|
58
|
+
*/
|
|
59
|
+
chains: _superstruct.array.call(void 0, ChainStruct),
|
|
60
|
+
/**
|
|
61
|
+
* A list of supported RPC methods on the namespace, that a DApp can call.
|
|
62
|
+
*/
|
|
63
|
+
methods: _superstruct.optional.call(void 0, _superstruct.array.call(void 0, LimitedString)),
|
|
64
|
+
/**
|
|
65
|
+
* A list of supported RPC events on the namespace, that a DApp can listen to.
|
|
66
|
+
*/
|
|
67
|
+
events: _superstruct.optional.call(void 0, _superstruct.array.call(void 0, LimitedString))
|
|
68
|
+
});
|
|
69
|
+
var NamespaceIdStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), /^[-a-z0-9]{3,8}$/u);
|
|
70
|
+
function isNamespaceId(value) {
|
|
71
|
+
return _superstruct.is.call(void 0, value, NamespaceIdStruct);
|
|
72
|
+
}
|
|
73
|
+
function isChainId(value) {
|
|
74
|
+
return _superstruct.is.call(void 0, value, ChainIdStruct);
|
|
75
|
+
}
|
|
76
|
+
function isAccountId(value) {
|
|
77
|
+
return _superstruct.is.call(void 0, value, AccountIdStruct);
|
|
78
|
+
}
|
|
79
|
+
function isAccountIdArray(value) {
|
|
80
|
+
return _superstruct.is.call(void 0, value, AccountIdArrayStruct);
|
|
81
|
+
}
|
|
82
|
+
function isNamespace(value) {
|
|
83
|
+
return _superstruct.is.call(void 0, value, NamespaceStruct);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
exports.CHAIN_ID_REGEX = CHAIN_ID_REGEX; exports.ACCOUNT_ID_REGEX = ACCOUNT_ID_REGEX; exports.ACCOUNT_ADDRESS_REGEX = ACCOUNT_ADDRESS_REGEX; exports.parseChainId = parseChainId; exports.parseAccountId = parseAccountId; exports.LimitedString = LimitedString; exports.ChainIdStringStruct = ChainIdStringStruct; exports.ChainIdStruct = ChainIdStruct; exports.AccountIdStruct = AccountIdStruct; exports.AccountIdArrayStruct = AccountIdArrayStruct; exports.AccountAddressStruct = AccountAddressStruct; exports.ChainStruct = ChainStruct; exports.NamespaceStruct = NamespaceStruct; exports.NamespaceIdStruct = NamespaceIdStruct; exports.isNamespaceId = isNamespaceId; exports.isChainId = isChainId; exports.isAccountId = isAccountId; exports.isAccountIdArray = isAccountIdArray; exports.isNamespace = isNamespace;
|
|
107
|
+
//# sourceMappingURL=chunk-B3YQVRPE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/namespace.ts"],"names":[],"mappings":";AAEA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIA,IAAM,iBACX;AAEK,IAAM,mBACX;AAEK,IAAM,wBAAwB;AAS9B,SAAS,aAAa,SAG3B;AACA,QAAM,QAAQ,eAAe,KAAK,OAAO;AACzC,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,mBAAmB;AAAA,EACrC;AAEA,SAAO;AAAA,IACL,WAAW,MAAM,OAAO;AAAA,IACxB,WAAW,MAAM,OAAO;AAAA,EAC1B;AACF;AASO,SAAS,eAAe,WAI7B;AACA,QAAM,QAAQ,iBAAiB,KAAK,SAAS;AAC7C,MAAI,CAAC,OAAO,QAAQ;AAClB,UAAM,IAAI,MAAM,qBAAqB;AAAA,EACvC;AAEA,SAAO;AAAA,IACL,SAAS,MAAM,OAAO;AAAA,IACtB,SAAS,MAAM,OAAO;AAAA,IACtB,OAAO;AAAA,MACL,WAAW,MAAM,OAAO;AAAA,MACxB,WAAW,MAAM,OAAO;AAAA,IAC1B;AAAA,EACF;AACF;AAMO,IAAM,gBAAgB,KAAK,OAAO,GAAG,GAAG,EAAE;AAE1C,IAAM,sBAAsB;AAAA,EACjC;AAAA,EACA,OAAO,EAAE;AACX;AAKO,IAAM,gBAAgB;AAAA,EAC3B;AAAA,EACA;AACF;AAIO,IAAM,kBAAkB,QAAQ,OAAO,GAAG,gBAAgB;AAE1D,IAAM,uBAAuB,MAAM,eAAe;AAClD,IAAM,uBAAuB,QAAQ,OAAO,GAAG,qBAAqB;AAMpE,IAAM,cAAc,OAAO;AAAA,EAChC,IAAI;AAAA,EACJ,MAAM;AACR,CAAC;AAGM,IAAM,kBAAkB,OAAO;AAAA;AAAA;AAAA;AAAA,EAIpC,QAAQ,MAAM,WAAW;AAAA;AAAA;AAAA;AAAA,EAKzB,SAAS,SAAS,MAAM,aAAa,CAAC;AAAA;AAAA;AAAA;AAAA,EAKtC,QAAQ,SAAS,MAAM,aAAa,CAAC;AACvC,CAAC;AAMM,IAAM,oBAAoB,QAAQ,OAAO,GAAG,mBAAmB;AAS/D,SAAS,cAAc,OAAsC;AAClE,SAAO,GAAG,OAAO,iBAAiB;AACpC;AAQO,SAAS,UAAU,OAAkC;AAC1D,SAAO,GAAG,OAAO,aAAa;AAChC;AAQO,SAAS,YAAY,OAAoC;AAC9D,SAAO,GAAG,OAAO,eAAe;AAClC;AAQO,SAAS,iBAAiB,OAAsC;AACrE,SAAO,GAAG,OAAO,oBAAoB;AACvC;AAQO,SAAS,YAAY,OAAoC;AAC9D,SAAO,GAAG,OAAO,eAAe;AAClC","sourcesContent":["import type { AccountId, ChainId } from '@metamask/snaps-sdk';\nimport type { Infer } from 'superstruct';\nimport {\n array,\n define,\n is,\n object,\n optional,\n pattern,\n size,\n string,\n} from 'superstruct';\n\nimport type { InferMatching } from './structs';\n\nexport const CHAIN_ID_REGEX =\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u;\n\nexport const ACCOUNT_ID_REGEX =\n /^(?<chainId>(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})):(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;\n\nexport const ACCOUNT_ADDRESS_REGEX = /^(?<accountAddress>[a-zA-Z0-9]{1,64})$/u;\n\n/**\n * Parse a chain ID string to an object containing the namespace and reference.\n * This validates the chain ID before parsing it.\n *\n * @param chainId - The chain ID to validate and parse.\n * @returns The parsed chain ID.\n */\nexport function parseChainId(chainId: ChainId): {\n namespace: NamespaceId;\n reference: string;\n} {\n const match = CHAIN_ID_REGEX.exec(chainId);\n if (!match?.groups) {\n throw new Error('Invalid chain ID.');\n }\n\n return {\n namespace: match.groups.namespace,\n reference: match.groups.reference,\n };\n}\n\n/**\n * Parse an account ID to an object containing the chain, chain ID and address.\n * This validates the account ID before parsing it.\n *\n * @param accountId - The account ID to validate and parse.\n * @returns The parsed account ID.\n */\nexport function parseAccountId(accountId: AccountId): {\n chain: { namespace: NamespaceId; reference: string };\n chainId: ChainId;\n address: string;\n} {\n const match = ACCOUNT_ID_REGEX.exec(accountId);\n if (!match?.groups) {\n throw new Error('Invalid account ID.');\n }\n\n return {\n address: match.groups.accountAddress,\n chainId: match.groups.chainId as ChainId,\n chain: {\n namespace: match.groups.namespace,\n reference: match.groups.reference,\n },\n };\n}\n\n/**\n * A helper struct for a string with a minimum length of 1 and a maximum length\n * of 40.\n */\nexport const LimitedString = size(string(), 1, 40);\n\nexport const ChainIdStringStruct = define<ChainId>(\n 'Chain ID',\n string().validator,\n);\n\n/**\n * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.\n */\nexport const ChainIdStruct = pattern<ChainId, null>(\n ChainIdStringStruct,\n CHAIN_ID_REGEX,\n);\n\nexport type Caip2ChainId = InferMatching<typeof ChainIdStruct, ChainId>;\n\nexport const AccountIdStruct = pattern(string(), ACCOUNT_ID_REGEX);\n\nexport const AccountIdArrayStruct = array(AccountIdStruct);\nexport const AccountAddressStruct = pattern(string(), ACCOUNT_ADDRESS_REGEX);\nexport type AccountAddress = Infer<typeof AccountAddressStruct>;\n\n/**\n * A chain descriptor.\n */\nexport const ChainStruct = object({\n id: ChainIdStruct,\n name: LimitedString,\n});\nexport type Chain = Infer<typeof ChainStruct>;\n\nexport const NamespaceStruct = object({\n /**\n * A list of supported chains in the namespace.\n */\n chains: array(ChainStruct),\n\n /**\n * A list of supported RPC methods on the namespace, that a DApp can call.\n */\n methods: optional(array(LimitedString)),\n\n /**\n * A list of supported RPC events on the namespace, that a DApp can listen to.\n */\n events: optional(array(LimitedString)),\n});\nexport type Namespace = Infer<typeof NamespaceStruct>;\n\n/**\n * A CAIP-2 namespace, i.e., the first part of a chain ID.\n */\nexport const NamespaceIdStruct = pattern(string(), /^[-a-z0-9]{3,8}$/u);\nexport type NamespaceId = Infer<typeof NamespaceIdStruct>;\n\n/**\n * Check if the given value is a CAIP-2 namespace ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-2 namespace ID.\n */\nexport function isNamespaceId(value: unknown): value is NamespaceId {\n return is(value, NamespaceIdStruct);\n}\n\n/**\n * Check if the given value is a CAIP-2 chain ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-2 chain ID.\n */\nexport function isChainId(value: unknown): value is ChainId {\n return is(value, ChainIdStruct);\n}\n\n/**\n * Check if the given value is a CAIP-10 account ID.\n *\n * @param value - The value to check.\n * @returns Whether the value is a CAIP-10 account ID.\n */\nexport function isAccountId(value: unknown): value is AccountId {\n return is(value, AccountIdStruct);\n}\n\n/**\n * Check if the given value is an array of CAIP-10 account IDs.\n *\n * @param value - The value to check.\n * @returns Whether the value is an array of CAIP-10 account IDs.\n */\nexport function isAccountIdArray(value: unknown): value is AccountId[] {\n return is(value, AccountIdArrayStruct);\n}\n\n/**\n * Check if a value is a {@link Namespace}.\n *\n * @param value - The value to validate.\n * @returns True if the value is a valid {@link Namespace}.\n */\nexport function isNamespace(value: unknown): value is Namespace {\n return is(value, NamespaceStruct);\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-DK3IYVMP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// src/json-rpc.ts
|
|
2
|
+
import { SubjectType } from "@metamask/permission-controller";
|
|
3
|
+
import {
|
|
4
|
+
assertStruct,
|
|
5
|
+
isJsonRpcFailure,
|
|
6
|
+
isJsonRpcSuccess
|
|
7
|
+
} from "@metamask/utils";
|
|
8
|
+
import { array, boolean, object, optional, refine, string } from "superstruct";
|
|
9
|
+
var RpcOriginsStruct = refine(
|
|
10
|
+
object({
|
|
11
|
+
dapps: optional(boolean()),
|
|
12
|
+
snaps: optional(boolean()),
|
|
13
|
+
allowedOrigins: optional(array(string()))
|
|
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
|
+
assertStruct(
|
|
28
|
+
value,
|
|
29
|
+
RpcOriginsStruct,
|
|
30
|
+
"Invalid JSON-RPC origins",
|
|
31
|
+
ErrorWrapper
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
var KeyringOriginsStruct = object({
|
|
35
|
+
allowedOrigins: optional(array(string()))
|
|
36
|
+
});
|
|
37
|
+
function assertIsKeyringOrigins(value, ErrorWrapper) {
|
|
38
|
+
assertStruct(
|
|
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 (origins.allowedOrigins?.includes(origin)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (subjectType === SubjectType.Website && origins.dapps) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return Boolean(subjectType === SubjectType.Snap && origins.snaps);
|
|
56
|
+
}
|
|
57
|
+
function assertIsJsonRpcSuccess(value) {
|
|
58
|
+
if (!isJsonRpcSuccess(value)) {
|
|
59
|
+
if (isJsonRpcFailure(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
|
+
export {
|
|
67
|
+
RpcOriginsStruct,
|
|
68
|
+
assertIsRpcOrigins,
|
|
69
|
+
KeyringOriginsStruct,
|
|
70
|
+
assertIsKeyringOrigins,
|
|
71
|
+
isOriginAllowed,
|
|
72
|
+
assertIsJsonRpcSuccess
|
|
73
|
+
};
|
|
74
|
+
//# sourceMappingURL=chunk-DKSB4FMW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/json-rpc.ts"],"sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type {\n AssertionErrorConstructor,\n Json,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, boolean, object, optional, refine, string } from 'superstruct';\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(array(string())),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(array(string())),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (origins.allowedOrigins?.includes(origin)) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess<Json> {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"],"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;","names":[]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } 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 _chunkQYFDFOWTjs = require('./chunk-QYFDFOWT.js');
|
|
4
|
+
|
|
5
|
+
// src/mock.ts
|
|
6
|
+
var _crypto = require('crypto'); var _crypto2 = _interopRequireDefault(_crypto);
|
|
7
|
+
var _events = require('events'); var _events2 = _interopRequireDefault(_events);
|
|
8
|
+
var NETWORK_APIS = ["fetch", "Request", "Headers", "Response"];
|
|
9
|
+
var ALL_APIS = [
|
|
10
|
+
..._chunkQYFDFOWTjs.DEFAULT_ENDOWMENTS,
|
|
11
|
+
...NETWORK_APIS,
|
|
12
|
+
"WebAssembly"
|
|
13
|
+
];
|
|
14
|
+
function getMockSnapGlobal() {
|
|
15
|
+
return { request: async () => true };
|
|
16
|
+
}
|
|
17
|
+
function getMockEthereumProvider() {
|
|
18
|
+
const mockProvider = new (0, _events2.default)();
|
|
19
|
+
mockProvider.request = async () => true;
|
|
20
|
+
return mockProvider;
|
|
21
|
+
}
|
|
22
|
+
var isConstructor = (value) => Boolean(typeof _optionalChain([value, 'optionalAccess', _ => _.prototype, 'optionalAccess', _2 => _2.constructor, 'optionalAccess', _3 => _3.name]) === "string");
|
|
23
|
+
var mockFunction = () => true;
|
|
24
|
+
var MockClass = class {
|
|
25
|
+
};
|
|
26
|
+
var handler = {
|
|
27
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
28
|
+
construct(Target, args) {
|
|
29
|
+
return new Proxy(new Target(...args), handler);
|
|
30
|
+
},
|
|
31
|
+
get(_target, _prop) {
|
|
32
|
+
return mockFunction;
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
var generateMockClass = (value) => {
|
|
36
|
+
return new Proxy(value, handler);
|
|
37
|
+
};
|
|
38
|
+
var mockWindow = {
|
|
39
|
+
crypto: _crypto2.default,
|
|
40
|
+
SubtleCrypto: MockClass
|
|
41
|
+
};
|
|
42
|
+
var generateMockEndowment = (key) => {
|
|
43
|
+
const globalValue = globalThis[key];
|
|
44
|
+
if (globalValue && _chunkQYFDFOWTjs.DEFAULT_ENDOWMENTS.includes(key)) {
|
|
45
|
+
return globalValue;
|
|
46
|
+
}
|
|
47
|
+
const globalOrMocked = _nullishCoalesce(globalValue, () => ( mockWindow[key]));
|
|
48
|
+
const type = typeof globalOrMocked;
|
|
49
|
+
const isFunction = type === "function";
|
|
50
|
+
if (isFunction && isConstructor(globalOrMocked)) {
|
|
51
|
+
return generateMockClass(globalOrMocked);
|
|
52
|
+
} else if (isFunction || !globalOrMocked) {
|
|
53
|
+
return mockFunction;
|
|
54
|
+
}
|
|
55
|
+
return globalOrMocked;
|
|
56
|
+
};
|
|
57
|
+
var generateMockEndowments = () => {
|
|
58
|
+
return ALL_APIS.reduce(
|
|
59
|
+
(acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),
|
|
60
|
+
{ snap: getMockSnapGlobal(), ethereum: getMockEthereumProvider() }
|
|
61
|
+
);
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
exports.ALL_APIS = ALL_APIS; exports.isConstructor = isConstructor; exports.generateMockEndowments = generateMockEndowments;
|
|
69
|
+
//# sourceMappingURL=chunk-F33RMB76.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/mock.ts"],"names":[],"mappings":";;;;;AAAA,OAAO,YAAY;AACnB,OAAO,kBAAkB;AAIzB,IAAM,eAAe,CAAC,SAAS,WAAW,WAAW,UAAU;AAExD,IAAM,WAAqB;AAAA,EAChC,GAAG;AAAA,EACH,GAAG;AAAA,EACH;AACF;AAeA,SAAS,oBAAoC;AAE3C,SAAO,EAAE,SAAS,YAAY,KAAK;AACrC;AAOA,SAAS,0BAAgD;AACvD,QAAM,eAAe,IAAI,aAAa;AAEtC,eAAa,UAAU,YAAY;AACnC,SAAO;AACT;AAQO,IAAM,gBAAgB,CAAC,UAC5B,QAAQ,OAAO,OAAO,WAAW,aAAa,SAAS,QAAQ;AAOjE,IAAM,eAAe,MAAM;AAC3B,IAAM,YAAN,MAAgB;AAAC;AAEjB,IAAM,UAAU;AAAA;AAAA,EAEd,UAAU,QAAa,MAAkB;AACvC,WAAO,IAAI,MAAM,IAAI,OAAO,GAAG,IAAI,GAAG,OAAO;AAAA,EAC/C;AAAA,EACA,IAAI,SAAc,OAAY;AAC5B,WAAO;AAAA,EACT;AACF;AASA,IAAM,oBAAoB,CAAC,UAAe;AACxC,SAAO,IAAI,MAAM,OAAO,OAAO;AACjC;AAIA,IAAM,aAAsC;AAAA,EAC1C;AAAA,EACA,cAAc;AAChB;AAUA,IAAM,wBAAwB,CAAC,QAAgB;AAC7C,QAAM,cAAe,WAAmB,GAAG;AAG3C,MAAI,eAAe,mBAAmB,SAAS,GAAG,GAAG;AACnD,WAAO;AAAA,EACT;AAGA,QAAM,iBAAiB,eAAe,WAAW,GAAG;AAEpD,QAAM,OAAO,OAAO;AACpB,QAAM,aAAa,SAAS;AAC5B,MAAI,cAAc,cAAc,cAAc,GAAG;AAC/C,WAAO,kBAAkB,cAAc;AAAA,EACzC,WAAW,cAAc,CAAC,gBAAgB;AAExC,WAAO;AAAA,EACT;AACA,SAAO;AACT;AAOO,IAAM,yBAAyB,MAAM;AAC1C,SAAO,SAAS;AAAA,IACd,CAAC,KAAK,SAAS,EAAE,GAAG,KAAK,CAAC,GAAG,GAAG,sBAAsB,GAAG,EAAE;AAAA,IAC3D,EAAE,MAAM,kBAAkB,GAAG,UAAU,wBAAwB,EAAE;AAAA,EACnE;AACF","sourcesContent":["import crypto from 'crypto';\nimport EventEmitter from 'events';\n\nimport { DEFAULT_ENDOWMENTS } from './default-endowments';\n\nconst NETWORK_APIS = ['fetch', 'Request', 'Headers', 'Response'];\n\nexport const ALL_APIS: string[] = [\n ...DEFAULT_ENDOWMENTS,\n ...NETWORK_APIS,\n 'WebAssembly',\n];\n\ntype MockSnapGlobal = {\n request: () => Promise<any>;\n};\n\ntype MockEthereumProvider = EventEmitter & {\n request: () => Promise<any>;\n};\n\n/**\n * Get a mock snap API, that always returns `true` for requests.\n *\n * @returns A mocked snap provider.\n */\nfunction getMockSnapGlobal(): MockSnapGlobal {\n // eslint-disable-next-line @typescript-eslint/require-await\n return { request: async () => true };\n}\n\n/**\n * Get a mock Ethereum provider, that always returns `true` for requests.\n *\n * @returns A mocked ethereum provider.\n */\nfunction getMockEthereumProvider(): MockEthereumProvider {\n const mockProvider = new EventEmitter() as Partial<MockEthereumProvider>;\n // eslint-disable-next-line @typescript-eslint/require-await\n mockProvider.request = async () => true;\n return mockProvider as MockEthereumProvider;\n}\n\n/**\n * Check if a value is a constructor.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nexport const isConstructor = (value: any) =>\n Boolean(typeof value?.prototype?.constructor?.name === 'string');\n\n/**\n * A function that always returns `true`.\n *\n * @returns `true`.\n */\nconst mockFunction = () => true;\nclass MockClass {}\n\nconst handler = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n construct(Target: any, args: any[]): any {\n return new Proxy(new Target(...args), handler);\n },\n get(_target: any, _prop: any) {\n return mockFunction;\n },\n};\n\n/**\n * Generate a mock class for a given value. The value is wrapped in a Proxy, and\n * all methods are replaced with a mock function.\n *\n * @param value - The value to mock.\n * @returns A mock class.\n */\nconst generateMockClass = (value: any) => {\n return new Proxy(value, handler);\n};\n\n// Things not currently auto-mocked because of NodeJS, by adding them here we\n// have types for them and can use that to generate mocks if needed.\nconst mockWindow: Record<string, unknown> = {\n crypto,\n SubtleCrypto: MockClass,\n};\n\n/**\n * Generate a mock endowment for a certain class or function on the `globalThis`\n * object.\n *\n * @param key - The key to generate the mock endowment for.\n * @returns A mocked class or function. If the key is part of the default\n * endowments, the original value is returned.\n */\nconst generateMockEndowment = (key: string) => {\n const globalValue = (globalThis as any)[key];\n\n // Default exposed APIs don't need to be mocked\n if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {\n return globalValue;\n }\n\n // Fall back to mockWindow for certain APIs not exposed in global in Node.JS\n const globalOrMocked = globalValue ?? mockWindow[key];\n\n const type = typeof globalOrMocked;\n const isFunction = type === 'function';\n if (isFunction && isConstructor(globalOrMocked)) {\n return generateMockClass(globalOrMocked);\n } else if (isFunction || !globalOrMocked) {\n // Fall back to function mock for now\n return mockFunction;\n }\n return globalOrMocked;\n};\n\n/**\n * Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.\n *\n * @returns A map of endowments.\n */\nexport const generateMockEndowments = () => {\n return ALL_APIS.reduce<Record<string, any>>(\n (acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),\n { snap: getMockSnapGlobal(), ethereum: getMockEthereumProvider() },\n );\n};\n"]}
|