@metamask/snaps-jest 4.0.1 → 6.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 +25 -1
- package/README.md +66 -179
- package/dist/chunk-2KLZ7GOW.js +15 -0
- package/dist/chunk-2KLZ7GOW.js.map +1 -0
- package/dist/chunk-2M7WQ26F.js +28 -0
- package/dist/chunk-2M7WQ26F.js.map +1 -0
- package/dist/chunk-34GS3AHA.js +33 -0
- package/dist/chunk-34GS3AHA.js.map +1 -0
- package/dist/chunk-3CC2NI7R.js +80 -0
- package/dist/chunk-3CC2NI7R.js.map +1 -0
- package/dist/chunk-3IUQA6YL.mjs +1 -0
- package/dist/chunk-3IUQA6YL.mjs.map +1 -0
- package/dist/chunk-3KCEPGJA.js +39 -0
- package/dist/chunk-3KCEPGJA.js.map +1 -0
- package/dist/chunk-3KQYPQZY.js +20 -0
- package/dist/chunk-3KQYPQZY.js.map +1 -0
- package/dist/chunk-3O5OISLU.js +16 -0
- package/dist/chunk-3O5OISLU.js.map +1 -0
- package/dist/chunk-3ZW2EE3B.js +1 -0
- package/dist/chunk-3ZW2EE3B.js.map +1 -0
- package/dist/chunk-4FCRZDOX.js +134 -0
- package/dist/chunk-4FCRZDOX.js.map +1 -0
- package/dist/chunk-4HY4SM3A.js +1 -0
- package/dist/chunk-4HY4SM3A.js.map +1 -0
- package/dist/chunk-4JUUFDTC.js +104 -0
- package/dist/chunk-4JUUFDTC.js.map +1 -0
- package/dist/chunk-4VCE3DRR.mjs +34 -0
- package/dist/chunk-4VCE3DRR.mjs.map +1 -0
- package/dist/chunk-4WCFXE73.js +48 -0
- package/dist/chunk-4WCFXE73.js.map +1 -0
- package/dist/chunk-5IUHGC5S.js +153 -0
- package/dist/chunk-5IUHGC5S.js.map +1 -0
- package/dist/chunk-5O6VBW42.js +42 -0
- package/dist/chunk-5O6VBW42.js.map +1 -0
- package/dist/chunk-6IMEYERE.js +137 -0
- package/dist/chunk-6IMEYERE.js.map +1 -0
- package/dist/chunk-6KNT4UMX.mjs +35 -0
- package/dist/chunk-6KNT4UMX.mjs.map +1 -0
- package/dist/chunk-6RDNSELT.mjs +39 -0
- package/dist/chunk-6RDNSELT.mjs.map +1 -0
- package/dist/chunk-72YN2D26.mjs +60 -0
- package/dist/chunk-72YN2D26.mjs.map +1 -0
- package/dist/chunk-7JLVQJK7.js +14 -0
- package/dist/chunk-7JLVQJK7.js.map +1 -0
- package/dist/chunk-AH7YNG6N.js +22 -0
- package/dist/chunk-AH7YNG6N.js.map +1 -0
- package/dist/chunk-AIZADBRK.mjs +36 -0
- package/dist/chunk-AIZADBRK.mjs.map +1 -0
- package/dist/chunk-AKFRQ5EJ.mjs +42 -0
- package/dist/chunk-AKFRQ5EJ.mjs.map +1 -0
- package/dist/chunk-AUB7XPDH.mjs +28 -0
- package/dist/chunk-AUB7XPDH.mjs.map +1 -0
- package/dist/chunk-BJMTD7H2.mjs +20 -0
- package/dist/chunk-BJMTD7H2.mjs.map +1 -0
- package/dist/chunk-BN5VBVT3.mjs +233 -0
- package/dist/chunk-BN5VBVT3.mjs.map +1 -0
- package/dist/chunk-CKOGTHM4.mjs +22 -0
- package/dist/chunk-CKOGTHM4.mjs.map +1 -0
- package/dist/chunk-CZQKOZLR.js +11 -0
- package/dist/chunk-CZQKOZLR.js.map +1 -0
- package/dist/chunk-D36QBJ35.js +24 -0
- package/dist/chunk-D36QBJ35.js.map +1 -0
- package/dist/chunk-DEFFA5IJ.mjs +24 -0
- package/dist/chunk-DEFFA5IJ.mjs.map +1 -0
- package/dist/chunk-EFB6AQPB.js +36 -0
- package/dist/chunk-EFB6AQPB.js.map +1 -0
- package/dist/chunk-EOCDSPT7.mjs +97 -0
- package/dist/chunk-EOCDSPT7.mjs.map +1 -0
- package/dist/chunk-FPFX5AKR.mjs +36 -0
- package/dist/chunk-FPFX5AKR.mjs.map +1 -0
- package/dist/chunk-HBT34TJ2.mjs +1 -0
- package/dist/chunk-HBT34TJ2.mjs.map +1 -0
- package/dist/chunk-HBVDXIVN.mjs +80 -0
- package/dist/chunk-HBVDXIVN.mjs.map +1 -0
- package/dist/chunk-HMF2CKYT.mjs +39 -0
- package/dist/chunk-HMF2CKYT.mjs.map +1 -0
- package/dist/chunk-HP56MLQ3.js +1 -0
- package/dist/chunk-HP56MLQ3.js.map +1 -0
- package/dist/chunk-I5LVU57H.mjs +69 -0
- package/dist/chunk-I5LVU57H.mjs.map +1 -0
- package/dist/chunk-I7FLOZU7.mjs +1 -0
- package/dist/chunk-I7FLOZU7.mjs.map +1 -0
- package/dist/chunk-J2ID3DS7.mjs +33 -0
- package/dist/chunk-J2ID3DS7.mjs.map +1 -0
- package/dist/chunk-JA7RJLI7.js +34 -0
- package/dist/chunk-JA7RJLI7.js.map +1 -0
- package/dist/chunk-JB2H2XEL.mjs +1 -0
- package/dist/chunk-JB2H2XEL.mjs.map +1 -0
- package/dist/chunk-JDN3VGMO.js +21 -0
- package/dist/chunk-JDN3VGMO.js.map +1 -0
- package/dist/chunk-JGQJFYU4.js +57 -0
- package/dist/chunk-JGQJFYU4.js.map +1 -0
- package/dist/chunk-JJCX335U.mjs +91 -0
- package/dist/chunk-JJCX335U.mjs.map +1 -0
- package/dist/chunk-JMDSN227.mjs +25 -0
- package/dist/chunk-JMDSN227.mjs.map +1 -0
- package/dist/chunk-JXOKRTEH.mjs +11 -0
- package/dist/chunk-JXOKRTEH.mjs.map +1 -0
- package/dist/chunk-JZJWUVD7.mjs +1 -0
- package/dist/chunk-JZJWUVD7.mjs.map +1 -0
- package/dist/chunk-K2KTKFLP.js +76 -0
- package/dist/chunk-K2KTKFLP.js.map +1 -0
- package/dist/chunk-KGIWSGTT.js +91 -0
- package/dist/chunk-KGIWSGTT.js.map +1 -0
- package/dist/chunk-KPXLJ6RH.js +60 -0
- package/dist/chunk-KPXLJ6RH.js.map +1 -0
- package/dist/chunk-LD5PSHHT.mjs +57 -0
- package/dist/chunk-LD5PSHHT.mjs.map +1 -0
- package/dist/chunk-LNNKGOHQ.mjs +16 -0
- package/dist/chunk-LNNKGOHQ.mjs.map +1 -0
- package/dist/chunk-MNDF32ZV.js +8 -0
- package/dist/chunk-MNDF32ZV.js.map +1 -0
- package/dist/chunk-MSQ7Q2VJ.mjs +13 -0
- package/dist/chunk-MSQ7Q2VJ.mjs.map +1 -0
- package/dist/chunk-O3VJYBFN.mjs +15 -0
- package/dist/chunk-O3VJYBFN.mjs.map +1 -0
- package/dist/chunk-O4MJRHZD.js +69 -0
- package/dist/chunk-O4MJRHZD.js.map +1 -0
- package/dist/chunk-OC64PNDU.mjs +21 -0
- package/dist/chunk-OC64PNDU.mjs.map +1 -0
- package/dist/chunk-ON6M4WG5.js +36 -0
- package/dist/chunk-ON6M4WG5.js.map +1 -0
- package/dist/chunk-P7JA42ZC.mjs +153 -0
- package/dist/chunk-P7JA42ZC.mjs.map +1 -0
- package/dist/chunk-PHUTP7NB.js +25 -0
- package/dist/chunk-PHUTP7NB.js.map +1 -0
- package/dist/chunk-QFPRGU5L.mjs +104 -0
- package/dist/chunk-QFPRGU5L.mjs.map +1 -0
- package/dist/chunk-QMHWGASM.js +1 -0
- package/dist/chunk-QMHWGASM.js.map +1 -0
- package/dist/chunk-QNDLJ2W7.js +1 -0
- package/dist/chunk-QNDLJ2W7.js.map +1 -0
- package/dist/chunk-QUUILTDY.mjs +137 -0
- package/dist/chunk-QUUILTDY.mjs.map +1 -0
- package/dist/chunk-R7ORBTUD.js +1 -0
- package/dist/chunk-R7ORBTUD.js.map +1 -0
- package/dist/chunk-RQBZLDXL.js +233 -0
- package/dist/chunk-RQBZLDXL.js.map +1 -0
- package/dist/chunk-S3DHQTXB.js +1 -0
- package/dist/chunk-S3DHQTXB.js.map +1 -0
- package/dist/chunk-SWSSV3LK.js +35 -0
- package/dist/chunk-SWSSV3LK.js.map +1 -0
- package/dist/chunk-T4TRX3ZR.js +22 -0
- package/dist/chunk-T4TRX3ZR.js.map +1 -0
- package/dist/chunk-UXHKMILA.mjs +1 -0
- package/dist/chunk-UXHKMILA.mjs.map +1 -0
- package/dist/chunk-VCXM6FKU.mjs +1 -0
- package/dist/chunk-VCXM6FKU.mjs.map +1 -0
- package/dist/chunk-VHTVUQWR.mjs +14 -0
- package/dist/chunk-VHTVUQWR.mjs.map +1 -0
- package/dist/chunk-VNQIROKZ.js +97 -0
- package/dist/chunk-VNQIROKZ.js.map +1 -0
- package/dist/chunk-VXQOXWRO.mjs +48 -0
- package/dist/chunk-VXQOXWRO.mjs.map +1 -0
- package/dist/chunk-VYKYQSUI.mjs +22 -0
- package/dist/chunk-VYKYQSUI.mjs.map +1 -0
- package/dist/chunk-WEI35OIM.mjs +8 -0
- package/dist/chunk-WEI35OIM.mjs.map +1 -0
- package/dist/chunk-WL2GRM5E.mjs +76 -0
- package/dist/chunk-WL2GRM5E.mjs.map +1 -0
- package/dist/chunk-XDZPH5WD.js +39 -0
- package/dist/chunk-XDZPH5WD.js.map +1 -0
- package/dist/chunk-Y5NWZU43.js +13 -0
- package/dist/chunk-Y5NWZU43.js.map +1 -0
- package/dist/chunk-YZFWCFMG.js +1 -0
- package/dist/chunk-YZFWCFMG.js.map +1 -0
- package/dist/chunk-ZCE26WZM.mjs +1 -0
- package/dist/chunk-ZCE26WZM.mjs.map +1 -0
- package/dist/chunk-ZZPKZRJQ.mjs +134 -0
- package/dist/chunk-ZZPKZRJQ.mjs.map +1 -0
- package/dist/environment.js +47 -0
- package/dist/environment.js.map +1 -0
- package/dist/environment.mjs +47 -0
- package/dist/environment.mjs.map +1 -0
- package/dist/helpers.js +44 -0
- package/dist/helpers.js.map +1 -0
- package/dist/helpers.mjs +44 -0
- package/dist/helpers.mjs.map +1 -0
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +54 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internals/environment.js +8 -0
- package/dist/internals/environment.js.map +1 -0
- package/dist/internals/environment.mjs +8 -0
- package/dist/internals/environment.mjs.map +1 -0
- package/dist/internals/index.js +123 -0
- package/dist/internals/index.js.map +1 -0
- package/dist/internals/index.mjs +123 -0
- package/dist/internals/index.mjs.map +1 -0
- package/dist/internals/logger.js +8 -0
- package/dist/internals/logger.js.map +1 -0
- package/dist/internals/logger.mjs +8 -0
- package/dist/internals/logger.mjs.map +1 -0
- package/dist/internals/request.js +40 -0
- package/dist/internals/request.js.map +1 -0
- package/dist/internals/request.mjs +40 -0
- package/dist/internals/request.mjs.map +1 -0
- package/dist/internals/server.js +9 -0
- package/dist/internals/server.js.map +1 -0
- package/dist/internals/server.mjs +9 -0
- package/dist/internals/server.mjs.map +1 -0
- package/dist/internals/simulation/constants.js +12 -0
- package/dist/internals/simulation/constants.js.map +1 -0
- package/dist/internals/simulation/constants.mjs +12 -0
- package/dist/internals/simulation/constants.mjs.map +1 -0
- package/dist/internals/simulation/controllers.js +26 -0
- package/dist/internals/simulation/controllers.js.map +1 -0
- package/dist/internals/simulation/controllers.mjs +26 -0
- package/dist/internals/simulation/controllers.mjs.map +1 -0
- package/dist/internals/simulation/files.js +8 -0
- package/dist/internals/simulation/files.js.map +1 -0
- package/dist/internals/simulation/files.mjs +8 -0
- package/dist/internals/simulation/files.mjs.map +1 -0
- package/dist/internals/simulation/index.js +90 -0
- package/dist/internals/simulation/index.js.map +1 -0
- package/dist/internals/simulation/index.mjs +90 -0
- package/dist/internals/simulation/index.mjs.map +1 -0
- package/dist/internals/simulation/interface.js +16 -0
- package/dist/internals/simulation/interface.js.map +1 -0
- package/dist/internals/simulation/interface.mjs +16 -0
- package/dist/internals/simulation/interface.mjs.map +1 -0
- package/dist/internals/simulation/methods/constants.js +12 -0
- package/dist/internals/simulation/methods/constants.js.map +1 -0
- package/dist/internals/simulation/methods/constants.mjs +12 -0
- package/dist/internals/simulation/methods/constants.mjs.map +1 -0
- package/dist/internals/simulation/methods/hooks/encryption.js +10 -0
- package/dist/internals/simulation/methods/hooks/encryption.js.map +1 -0
- package/dist/internals/simulation/methods/hooks/encryption.mjs +10 -0
- package/dist/internals/simulation/methods/hooks/encryption.mjs.map +1 -0
- package/dist/internals/simulation/methods/hooks/get-locale.js +8 -0
- package/dist/internals/simulation/methods/hooks/get-locale.js.map +1 -0
- package/dist/internals/simulation/methods/hooks/get-locale.mjs +8 -0
- package/dist/internals/simulation/methods/hooks/get-locale.mjs.map +1 -0
- package/dist/internals/simulation/methods/hooks/index.js +45 -0
- package/dist/internals/simulation/methods/hooks/index.js.map +1 -0
- package/dist/internals/simulation/methods/hooks/index.mjs +45 -0
- package/dist/internals/simulation/methods/hooks/index.mjs.map +1 -0
- package/dist/internals/simulation/methods/hooks/interface.js +10 -0
- package/dist/internals/simulation/methods/hooks/interface.js.map +1 -0
- package/dist/internals/simulation/methods/hooks/interface.mjs +10 -0
- package/dist/internals/simulation/methods/hooks/interface.mjs.map +1 -0
- package/dist/internals/simulation/methods/hooks/notifications.js +16 -0
- package/dist/internals/simulation/methods/hooks/notifications.js.map +1 -0
- package/dist/internals/simulation/methods/hooks/notifications.mjs +16 -0
- package/dist/internals/simulation/methods/hooks/notifications.mjs.map +1 -0
- package/dist/internals/simulation/methods/hooks/show-dialog.js +14 -0
- package/dist/internals/simulation/methods/hooks/show-dialog.js.map +1 -0
- package/dist/internals/simulation/methods/hooks/show-dialog.mjs +14 -0
- package/dist/internals/simulation/methods/hooks/show-dialog.mjs.map +1 -0
- package/dist/internals/simulation/methods/hooks/state.js +18 -0
- package/dist/internals/simulation/methods/hooks/state.js.map +1 -0
- package/dist/internals/simulation/methods/hooks/state.mjs +18 -0
- package/dist/internals/simulation/methods/hooks/state.mjs.map +1 -0
- package/dist/internals/simulation/methods/index.js +29 -0
- package/dist/internals/simulation/methods/index.js.map +1 -0
- package/dist/internals/simulation/methods/index.mjs +29 -0
- package/dist/internals/simulation/methods/index.mjs.map +1 -0
- package/dist/internals/simulation/methods/specifications.js +28 -0
- package/dist/internals/simulation/methods/specifications.js.map +1 -0
- package/dist/internals/simulation/methods/specifications.mjs +28 -0
- package/dist/internals/simulation/methods/specifications.mjs.map +1 -0
- package/dist/internals/simulation/middleware/engine.js +15 -0
- package/dist/internals/simulation/middleware/engine.js.map +1 -0
- package/dist/internals/simulation/middleware/engine.mjs +15 -0
- package/dist/internals/simulation/middleware/engine.mjs.map +1 -0
- package/dist/internals/simulation/middleware/index.js +16 -0
- package/dist/internals/simulation/middleware/index.js.map +1 -0
- package/dist/internals/simulation/middleware/index.mjs +16 -0
- package/dist/internals/simulation/middleware/index.mjs.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/accounts.js +8 -0
- package/dist/internals/simulation/middleware/internal-methods/accounts.js.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs +8 -0
- package/dist/internals/simulation/middleware/internal-methods/accounts.mjs.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/index.js +11 -0
- package/dist/internals/simulation/middleware/internal-methods/index.js.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/index.mjs +11 -0
- package/dist/internals/simulation/middleware/internal-methods/index.mjs.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/middleware.js +10 -0
- package/dist/internals/simulation/middleware/internal-methods/middleware.js.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs +10 -0
- package/dist/internals/simulation/middleware/internal-methods/middleware.mjs.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/provider-state.js +8 -0
- package/dist/internals/simulation/middleware/internal-methods/provider-state.js.map +1 -0
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs +8 -0
- package/dist/internals/simulation/middleware/internal-methods/provider-state.mjs.map +1 -0
- package/dist/internals/simulation/middleware/mock.js +9 -0
- package/dist/internals/simulation/middleware/mock.js.map +1 -0
- package/dist/internals/simulation/middleware/mock.mjs +9 -0
- package/dist/internals/simulation/middleware/mock.mjs.map +1 -0
- package/dist/internals/simulation/options.js +9 -0
- package/dist/internals/simulation/options.js.map +1 -0
- package/dist/internals/simulation/options.mjs +9 -0
- package/dist/internals/simulation/options.mjs.map +1 -0
- package/dist/internals/simulation/simulation.js +39 -0
- package/dist/internals/simulation/simulation.js.map +1 -0
- package/dist/internals/simulation/simulation.mjs +39 -0
- package/dist/internals/simulation/simulation.mjs.map +1 -0
- package/dist/internals/simulation/store/index.js +44 -0
- package/dist/internals/simulation/store/index.js.map +1 -0
- package/dist/internals/simulation/store/index.mjs +44 -0
- package/dist/internals/simulation/store/index.mjs.map +1 -0
- package/dist/internals/simulation/store/mocks.js +16 -0
- package/dist/internals/simulation/store/mocks.js.map +1 -0
- package/dist/internals/simulation/store/mocks.mjs +16 -0
- package/dist/internals/simulation/store/mocks.mjs.map +1 -0
- package/dist/internals/simulation/store/notifications.js +16 -0
- package/dist/internals/simulation/store/notifications.js.map +1 -0
- package/dist/internals/simulation/store/notifications.mjs +16 -0
- package/dist/internals/simulation/store/notifications.mjs.map +1 -0
- package/dist/internals/simulation/store/state.js +14 -0
- package/dist/internals/simulation/store/state.js.map +1 -0
- package/dist/internals/simulation/store/state.mjs +14 -0
- package/dist/internals/simulation/store/state.mjs.map +1 -0
- package/dist/internals/simulation/store/store.js +12 -0
- package/dist/internals/simulation/store/store.js.map +1 -0
- package/dist/internals/simulation/store/store.mjs +12 -0
- package/dist/internals/simulation/store/store.mjs.map +1 -0
- package/dist/internals/simulation/store/ui.js +16 -0
- package/dist/internals/simulation/store/ui.js.map +1 -0
- package/dist/internals/simulation/store/ui.mjs +16 -0
- package/dist/internals/simulation/store/ui.mjs.map +1 -0
- package/dist/internals/structs.js +18 -0
- package/dist/internals/structs.js.map +1 -0
- package/dist/internals/structs.mjs +18 -0
- package/dist/internals/structs.mjs.map +1 -0
- package/dist/matchers.js +50 -0
- package/dist/matchers.js.map +1 -0
- package/dist/matchers.mjs +50 -0
- package/dist/matchers.mjs.map +1 -0
- package/dist/options.js +8 -0
- package/dist/options.js.map +1 -0
- package/dist/options.mjs +8 -0
- package/dist/options.mjs.map +1 -0
- package/dist/setup.js +39 -0
- package/dist/setup.js.map +1 -0
- package/dist/setup.mjs +39 -0
- package/dist/setup.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/environment.d.ts +14 -15
- package/dist/types/helpers.d.ts +64 -3
- package/dist/types/internals/index.d.ts +1 -4
- package/dist/types/internals/request.d.ts +38 -74
- package/dist/types/internals/simulation/constants.d.ts +13 -0
- package/dist/types/internals/simulation/controllers.d.ts +40 -0
- package/dist/types/internals/simulation/files.d.ts +11 -0
- package/dist/types/internals/simulation/index.d.ts +5 -0
- package/dist/types/internals/simulation/interface.d.ts +25 -0
- package/dist/types/internals/simulation/methods/constants.d.ts +10 -0
- package/dist/types/internals/simulation/methods/hooks/encryption.d.ts +29 -0
- package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +9 -0
- package/dist/types/internals/simulation/methods/hooks/index.d.ts +6 -0
- package/dist/types/internals/simulation/methods/hooks/interface.d.ts +16 -0
- package/dist/types/internals/simulation/methods/hooks/notifications.d.ts +16 -0
- package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +9 -0
- package/dist/types/internals/simulation/methods/hooks/state.d.ts +22 -0
- package/dist/types/internals/simulation/methods/index.d.ts +1 -0
- package/dist/types/internals/simulation/methods/specifications.d.ts +56 -0
- package/dist/types/internals/simulation/middleware/engine.d.ts +26 -0
- package/dist/types/internals/simulation/middleware/index.d.ts +1 -0
- package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +18 -0
- package/dist/types/internals/simulation/middleware/internal-methods/index.d.ts +1 -0
- package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +22 -0
- package/dist/types/internals/simulation/middleware/internal-methods/provider-state.d.ts +14 -0
- package/dist/types/internals/simulation/middleware/mock.d.ts +10 -0
- package/dist/types/internals/simulation/options.d.ts +37 -0
- package/dist/types/internals/simulation/simulation.d.ts +98 -0
- package/dist/types/internals/simulation/store/index.d.ts +4 -0
- package/dist/types/internals/simulation/store/mocks.d.ts +35 -0
- package/dist/types/internals/simulation/store/notifications.d.ts +44 -0
- package/dist/types/internals/simulation/store/state.d.ts +55 -0
- package/dist/types/internals/simulation/store/store.d.ts +22 -0
- package/dist/types/internals/simulation/store/ui.d.ts +25 -0
- package/dist/types/internals/structs.d.ts +153 -0
- package/dist/types/options.d.ts +3 -35
- package/dist/types/types.d.ts +88 -41
- package/dist/types/vendor/readable-stream.d.js +1 -0
- package/dist/types/vendor/readable-stream.d.js.map +1 -0
- package/dist/types/vendor/readable-stream.d.mjs +1 -0
- package/dist/types/vendor/readable-stream.d.mjs.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/jest-preset.js +1 -1
- package/package.json +37 -24
- package/dist/cjs/environment.js +0 -205
- package/dist/cjs/environment.js.map +0 -1
- package/dist/cjs/helpers.js +0 -67
- package/dist/cjs/helpers.js.map +0 -1
- package/dist/cjs/index.js +0 -42
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/internals/environment.js +0 -19
- package/dist/cjs/internals/environment.js.map +0 -1
- package/dist/cjs/internals/index.js +0 -28
- package/dist/cjs/internals/index.js.map +0 -1
- package/dist/cjs/internals/interface.js +0 -103
- package/dist/cjs/internals/interface.js.map +0 -1
- package/dist/cjs/internals/logger.js +0 -14
- package/dist/cjs/internals/logger.js.map +0 -1
- package/dist/cjs/internals/network.js +0 -148
- package/dist/cjs/internals/network.js.map +0 -1
- package/dist/cjs/internals/request.js +0 -121
- package/dist/cjs/internals/request.js.map +0 -1
- package/dist/cjs/internals/server.js +0 -75
- package/dist/cjs/internals/server.js.map +0 -1
- package/dist/cjs/internals/structs.js +0 -122
- package/dist/cjs/internals/structs.js.map +0 -1
- package/dist/cjs/internals/types.js +0 -6
- package/dist/cjs/internals/types.js.map +0 -1
- package/dist/cjs/internals/wait-for.js +0 -63
- package/dist/cjs/internals/wait-for.js.map +0 -1
- package/dist/cjs/matchers.js +0 -117
- package/dist/cjs/matchers.js.map +0 -1
- package/dist/cjs/options.js +0 -29
- package/dist/cjs/options.js.map +0 -1
- package/dist/cjs/setup.js +0 -10
- package/dist/cjs/setup.js.map +0 -1
- package/dist/cjs/types.js +0 -6
- package/dist/cjs/types.js.map +0 -1
- package/dist/esm/environment.js +0 -182
- package/dist/esm/environment.js.map +0 -1
- package/dist/esm/helpers.js +0 -82
- package/dist/esm/helpers.js.map +0 -1
- package/dist/esm/index.js +0 -6
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/internals/environment.js +0 -14
- package/dist/esm/internals/environment.js.map +0 -1
- package/dist/esm/internals/index.js +0 -12
- package/dist/esm/internals/index.js.map +0 -1
- package/dist/esm/internals/interface.js +0 -100
- package/dist/esm/internals/interface.js.map +0 -1
- package/dist/esm/internals/logger.js +0 -4
- package/dist/esm/internals/logger.js.map +0 -1
- package/dist/esm/internals/network.js +0 -143
- package/dist/esm/internals/network.js.map +0 -1
- package/dist/esm/internals/request.js +0 -120
- package/dist/esm/internals/request.js.map +0 -1
- package/dist/esm/internals/server.js +0 -68
- package/dist/esm/internals/server.js.map +0 -1
- package/dist/esm/internals/structs.js +0 -98
- package/dist/esm/internals/structs.js.map +0 -1
- package/dist/esm/internals/types.js +0 -3
- package/dist/esm/internals/types.js.map +0 -1
- package/dist/esm/internals/wait-for.js +0 -63
- package/dist/esm/internals/wait-for.js.map +0 -1
- package/dist/esm/matchers.js +0 -108
- package/dist/esm/matchers.js.map +0 -1
- package/dist/esm/options.js +0 -26
- package/dist/esm/options.js.map +0 -1
- package/dist/esm/setup.js +0 -6
- package/dist/esm/setup.js.map +0 -1
- package/dist/esm/types.js +0 -3
- package/dist/esm/types.js.map +0 -1
- package/dist/types/internals/interface.d.ts +0 -25
- package/dist/types/internals/network.d.ts +0 -87
- package/dist/types/internals/types.d.ts +0 -18
- package/dist/types/internals/wait-for.d.ts +0 -38
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }
|
|
2
|
+
|
|
3
|
+
var _chunkXDZPH5WDjs = require('./chunk-XDZPH5WD.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkEFB6AQPBjs = require('./chunk-EFB6AQPB.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
var _chunkKGIWSGTTjs = require('./chunk-KGIWSGTT.js');
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
var _chunkVNQIROKZjs = require('./chunk-VNQIROKZ.js');
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkJGQJFYU4js = require('./chunk-JGQJFYU4.js');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
var _chunk3O5OISLUjs = require('./chunk-3O5OISLU.js');
|
|
20
|
+
|
|
21
|
+
// src/internals/simulation/simulation.ts
|
|
22
|
+
var _basecontroller = require('@metamask/base-controller');
|
|
23
|
+
var _jsonrpcmiddlewarestream = require('@metamask/json-rpc-middleware-stream');
|
|
24
|
+
var _keytree = require('@metamask/key-tree');
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var _node = require('@metamask/snaps-controllers/node');
|
|
31
|
+
var _snapsrpcmethods = require('@metamask/snaps-rpc-methods');
|
|
32
|
+
var _snapsutils = require('@metamask/snaps-utils');
|
|
33
|
+
var _readablestream = require('readable-stream');
|
|
34
|
+
async function handleInstallSnap(snapId, {
|
|
35
|
+
executionService,
|
|
36
|
+
executionServiceOptions,
|
|
37
|
+
options: rawOptions = {}
|
|
38
|
+
} = {}) {
|
|
39
|
+
const options = _chunkEFB6AQPBjs.getOptions.call(void 0, rawOptions);
|
|
40
|
+
const location = _node.detectSnapLocation.call(void 0, snapId, {
|
|
41
|
+
allowLocal: true
|
|
42
|
+
});
|
|
43
|
+
const snapFiles = await _node.fetchSnap.call(void 0, snapId, location);
|
|
44
|
+
const password = await _snapsrpcmethods.getEncryptionKey.call(void 0, {
|
|
45
|
+
mnemonicPhrase: _keytree.mnemonicPhraseToBytes.call(void 0, options.secretRecoveryPhrase),
|
|
46
|
+
snapId
|
|
47
|
+
});
|
|
48
|
+
const { store, runSaga } = _chunkJGQJFYU4js.createStore.call(void 0, password, options);
|
|
49
|
+
const controllerMessenger = new (0, _basecontroller.ControllerMessenger)();
|
|
50
|
+
registerActions(controllerMessenger);
|
|
51
|
+
const hooks = getHooks(options, snapFiles, snapId, controllerMessenger);
|
|
52
|
+
const { subjectMetadataController, permissionController } = _chunkKGIWSGTTjs.getControllers.call(void 0, {
|
|
53
|
+
controllerMessenger,
|
|
54
|
+
hooks,
|
|
55
|
+
runSaga,
|
|
56
|
+
options
|
|
57
|
+
});
|
|
58
|
+
const engine = _chunkXDZPH5WDjs.createJsonRpcEngine.call(void 0, {
|
|
59
|
+
store,
|
|
60
|
+
hooks,
|
|
61
|
+
permissionMiddleware: permissionController.createPermissionMiddleware({
|
|
62
|
+
origin: snapId
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
const ExecutionService = _nullishCoalesce(executionService, () => ( _node.NodeThreadExecutionService));
|
|
66
|
+
const service = new ExecutionService({
|
|
67
|
+
...executionServiceOptions,
|
|
68
|
+
messenger: controllerMessenger.getRestricted({
|
|
69
|
+
name: "ExecutionService"
|
|
70
|
+
}),
|
|
71
|
+
setupSnapProvider: (_snapId, rpcStream) => {
|
|
72
|
+
const mux = _node.setupMultiplex.call(void 0, rpcStream, "snapStream");
|
|
73
|
+
const stream = mux.createStream("metamask-provider");
|
|
74
|
+
const providerStream = _jsonrpcmiddlewarestream.createEngineStream.call(void 0, { engine });
|
|
75
|
+
_readablestream.pipeline.call(void 0, stream, providerStream, stream, (error) => {
|
|
76
|
+
if (error) {
|
|
77
|
+
_snapsutils.logError.call(void 0, `Provider stream failure.`, error);
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
await _chunkKGIWSGTTjs.registerSnap.call(void 0, snapId, snapFiles.manifest.result, {
|
|
83
|
+
permissionController,
|
|
84
|
+
subjectMetadataController
|
|
85
|
+
});
|
|
86
|
+
await service.executeSnap({
|
|
87
|
+
snapId,
|
|
88
|
+
sourceCode: snapFiles.sourceCode.toString("utf8"),
|
|
89
|
+
endowments: await _chunkVNQIROKZjs.getEndowments.call(void 0, permissionController, snapId)
|
|
90
|
+
});
|
|
91
|
+
return {
|
|
92
|
+
snapId,
|
|
93
|
+
store,
|
|
94
|
+
executionService: service,
|
|
95
|
+
controllerMessenger,
|
|
96
|
+
runSaga
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
function getHooks(options, snapFiles, snapId, controllerMessenger) {
|
|
100
|
+
return {
|
|
101
|
+
getMnemonic: async () => Promise.resolve(_keytree.mnemonicPhraseToBytes.call(void 0, options.secretRecoveryPhrase)),
|
|
102
|
+
getSnapFile: async (path, encoding) => await _chunk3O5OISLUjs.getSnapFile.call(void 0, snapFiles.auxiliaryFiles, path, encoding),
|
|
103
|
+
getIsLocked: () => false,
|
|
104
|
+
createInterface: async (...args) => controllerMessenger.call(
|
|
105
|
+
"SnapInterfaceController:createInterface",
|
|
106
|
+
snapId,
|
|
107
|
+
...args
|
|
108
|
+
),
|
|
109
|
+
updateInterface: async (...args) => controllerMessenger.call(
|
|
110
|
+
"SnapInterfaceController:updateInterface",
|
|
111
|
+
snapId,
|
|
112
|
+
...args
|
|
113
|
+
),
|
|
114
|
+
getInterfaceState: (...args) => controllerMessenger.call(
|
|
115
|
+
"SnapInterfaceController:getInterface",
|
|
116
|
+
snapId,
|
|
117
|
+
...args
|
|
118
|
+
).state
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function registerActions(controllerMessenger) {
|
|
122
|
+
controllerMessenger.registerActionHandler(
|
|
123
|
+
"PhishingController:maybeUpdateState",
|
|
124
|
+
async () => Promise.resolve()
|
|
125
|
+
);
|
|
126
|
+
controllerMessenger.registerActionHandler(
|
|
127
|
+
"PhishingController:testOrigin",
|
|
128
|
+
() => ({ result: false, type: "all" })
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
exports.handleInstallSnap = handleInstallSnap; exports.getHooks = getHooks; exports.registerActions = registerActions;
|
|
137
|
+
//# sourceMappingURL=chunk-6IMEYERE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/simulation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIA,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AAEtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AAQjC,SAAS,gBAAgB;AAEzB,SAAS,gBAAgB;AAyGzB,eAAsB,kBAKpB,QACA;AAAA,EACE;AAAA,EACA;AAAA,EACA,SAAS,aAAa,CAAC;AACzB,IAA0C,CAAC,GACnB;AACxB,QAAM,UAAU,WAAW,UAAU;AAGrC,QAAM,WAAW,mBAAmB,QAAQ;AAAA,IAC1C,YAAY;AAAA,EACd,CAAC;AAED,QAAM,YAAY,MAAM,UAAU,QAAQ,QAAQ;AAGlD,QAAM,WAAW,MAAM,iBAAiB;AAAA,IACtC,gBAAgB,sBAAsB,QAAQ,oBAAoB;AAAA,IAClE;AAAA,EACF,CAAC;AAED,QAAM,EAAE,OAAO,QAAQ,IAAI,YAAY,UAAU,OAAO;AAExD,QAAM,sBAAsB,IAAI,oBAA8B;AAE9D,kBAAgB,mBAAmB;AAGnC,QAAM,QAAQ,SAAS,SAAS,WAAW,QAAQ,mBAAmB;AAEtE,QAAM,EAAE,2BAA2B,qBAAqB,IAAI,eAAe;AAAA,IACzE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,QAAM,SAAS,oBAAoB;AAAA,IACjC;AAAA,IACA;AAAA,IACA,sBAAsB,qBAAqB,2BAA2B;AAAA,MACpE,QAAQ;AAAA,IACV,CAAC;AAAA,EACH,CAAC;AAGD,QAAM,mBAAmB,oBAAoB;AAC7C,QAAM,UAAU,IAAI,iBAAiB;AAAA,IACnC,GAAG;AAAA,IACH,WAAW,oBAAoB,cAAc;AAAA,MAC3C,MAAM;AAAA,IACR,CAAC;AAAA,IACD,mBAAmB,CAAC,SAAiB,cAAsB;AACzD,YAAM,MAAM,eAAe,WAAW,YAAY;AAClD,YAAM,SAAS,IAAI,aAAa,mBAAmB;AACnD,YAAM,iBAAiB,mBAAmB,EAAE,OAAO,CAAC;AAIpD,eAAS,QAAQ,gBAAgB,QAAQ,CAAC,UAAmB;AAC3D,YAAI,OAAO;AACT,mBAAS,4BAA4B,KAAK;AAAA,QAC5C;AAAA,MACF,CAAC;AAAA,IACH;AAAA,EACF,CAAC;AAID,QAAM,aAAa,QAAQ,UAAU,SAAS,QAAQ;AAAA,IACpD;AAAA,IACA;AAAA,EACF,CAAC;AAGD,QAAM,QAAQ,YAAY;AAAA,IACxB;AAAA,IACA,YAAY,UAAU,WAAW,SAAS,MAAM;AAAA,IAChD,YAAY,MAAM,cAAc,sBAAsB,MAAM;AAAA,EAC9D,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;AAWO,SAAS,SACd,SACA,WACA,QACA,qBACiB;AACjB,SAAO;AAAA,IACL,aAAa,YACX,QAAQ,QAAQ,sBAAsB,QAAQ,oBAAoB,CAAC;AAAA,IACrE,aAAa,OAAO,MAAc,aAChC,MAAM,YAAY,UAAU,gBAAgB,MAAM,QAAQ;AAAA,IAC5D,aAAa,MAAM;AAAA,IACnB,iBAAiB,UAAU,SACzB,oBAAoB;AAAA,MAClB;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL;AAAA,IACF,iBAAiB,UAAU,SACzB,oBAAoB;AAAA,MAClB;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL;AAAA,IACF,mBAAmB,IAAI,SACrB,oBAAoB;AAAA,MAClB;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,EAAE;AAAA,EACN;AACF;AAOO,SAAS,gBAAgB,qBAA8C;AAC5E,sBAAoB;AAAA,IAClB;AAAA,IACA,YAAY,QAAQ,QAAQ;AAAA,EAC9B;AAEA,sBAAoB;AAAA,IAClB;AAAA,IACA,OAAO,EAAE,QAAQ,OAAO,MAAM,MAAM;AAAA,EACtC;AACF","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { ControllerMessenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport { mnemonicPhraseToBytes } from '@metamask/key-tree';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n fetchSnap,\n detectSnapLocation,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { getEncryptionKey } from '@metamask/snaps-rpc-methods';\nimport type {\n SnapId,\n AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport { getEndowments } from './methods';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { RunSagaFunction, Store } from './store';\nimport { createStore } from './store';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService<unknown>\n >,\n> = ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof AbstractExecutionService>;\n controllerMessenger: ControllerMessenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type MiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * A hook that returns the Snap's auxiliary file for the given path.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n createInterface: (content: Component) => Promise<string>;\n updateInterface: (id: string, content: Component) => Promise<void>;\n getInterfaceState: (id: string) => InterfaceState;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport async function handleInstallSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const password = await getEncryptionKey({\n mnemonicPhrase: mnemonicPhraseToBytes(options.secretRecoveryPhrase),\n snapId,\n });\n\n const { store, runSaga } = createStore(password, options);\n\n const controllerMessenger = new ControllerMessenger<any, any>();\n\n registerActions(controllerMessenger);\n\n // Set up controllers and JSON-RPC stack.\n const hooks = getHooks(options, snapFiles, snapId, controllerMessenger);\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n hooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: controllerMessenger.getRestricted({\n name: 'ExecutionService',\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error: unknown) => {\n if (error) {\n logError(`Provider stream failure.`, error);\n }\n });\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @param snapFiles - The Snap files.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the simulation.\n */\nexport function getHooks(\n options: SimulationOptions,\n snapFiles: FetchedSnapFiles,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): MiddlewareHooks {\n return {\n getMnemonic: async () =>\n Promise.resolve(mnemonicPhraseToBytes(options.secretRecoveryPhrase)),\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n getIsLocked: () => false,\n createInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n };\n}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n */\nexport function registerActions(controllerMessenger: RootControllerMessenger) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:maybeUpdateState',\n async () => Promise.resolve(),\n );\n\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: 'all' }),\n );\n}\n"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getAccountsHandler
|
|
3
|
+
} from "./chunk-CKOGTHM4.mjs";
|
|
4
|
+
import {
|
|
5
|
+
getProviderStateHandler
|
|
6
|
+
} from "./chunk-O3VJYBFN.mjs";
|
|
7
|
+
|
|
8
|
+
// src/internals/simulation/middleware/internal-methods/middleware.ts
|
|
9
|
+
import { logError } from "@metamask/snaps-utils";
|
|
10
|
+
var methodHandlers = {
|
|
11
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
12
|
+
metamask_getProviderState: getProviderStateHandler,
|
|
13
|
+
eth_requestAccounts: getAccountsHandler,
|
|
14
|
+
eth_accounts: getAccountsHandler
|
|
15
|
+
/* eslint-enable @typescript-eslint/naming-convention */
|
|
16
|
+
};
|
|
17
|
+
function createInternalMethodsMiddleware(hooks) {
|
|
18
|
+
return async function methodMiddleware(request, response, next, end) {
|
|
19
|
+
const handler = methodHandlers[request.method];
|
|
20
|
+
if (handler) {
|
|
21
|
+
try {
|
|
22
|
+
return await handler(request, response, next, end, hooks);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
logError(error);
|
|
25
|
+
return end(error);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return next();
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export {
|
|
33
|
+
createInternalMethodsMiddleware
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=chunk-6KNT4UMX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/middleware/internal-methods/middleware.ts"],"sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { getAccountsHandler } from './accounts';\nimport { getProviderStateHandler } from './provider-state';\n\nexport type InternalMethodsMiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n};\n\nconst methodHandlers = {\n /* eslint-disable @typescript-eslint/naming-convention */\n metamask_getProviderState: getProviderStateHandler,\n eth_requestAccounts: getAccountsHandler,\n eth_accounts: getAccountsHandler,\n /* eslint-enable @typescript-eslint/naming-convention */\n};\n\n/**\n * Create a middleware for handling JSON-RPC methods normally handled internally\n * by the MetaMask client.\n *\n * NOTE: This middleware provides all `hooks` to all handlers and should\n * therefore NOT be used outside of the simulation environment. It is intended\n * for testing purposes only.\n *\n * @param hooks - Any hooks used by the middleware handlers.\n * @returns A middleware function.\n */\nexport function createInternalMethodsMiddleware(\n hooks: InternalMethodsMiddlewareHooks,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This should probably use createAsyncMiddleware.\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n try {\n // Implementations may or may not be async, so we must await them.\n return await handler(request, response, next, end, hooks);\n } catch (error: any) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"],"mappings":";;;;;;;;AACA,SAAS,gBAAgB;AAezB,IAAM,iBAAiB;AAAA;AAAA,EAErB,2BAA2B;AAAA,EAC3B,qBAAqB;AAAA,EACrB,cAAc;AAAA;AAEhB;AAaO,SAAS,gCACd,OACwC;AAGxC,SAAO,eAAe,iBAAiB,SAAS,UAAU,MAAM,KAAK;AACnE,UAAM,UACJ,eAAe,QAAQ,MAAqC;AAC9D,QAAI,SAAS;AACX,UAAI;AAEF,eAAO,MAAM,QAAQ,SAAS,UAAU,MAAM,KAAK,KAAK;AAAA,MAC1D,SAAS,OAAY;AACnB,iBAAS,KAAK;AACd,eAAO,IAAI,KAAK;AAAA,MAClB;AAAA,IACF;AAEA,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
clearState,
|
|
3
|
+
getState,
|
|
4
|
+
setState
|
|
5
|
+
} from "./chunk-VXQOXWRO.mjs";
|
|
6
|
+
|
|
7
|
+
// src/internals/simulation/methods/hooks/state.ts
|
|
8
|
+
import { put, select } from "redux-saga/effects";
|
|
9
|
+
function* getSnapStateImplementation(_snapId, encrypted = true) {
|
|
10
|
+
return yield select(getState(encrypted));
|
|
11
|
+
}
|
|
12
|
+
function getGetSnapStateMethodImplementation(runSaga) {
|
|
13
|
+
return (...args) => {
|
|
14
|
+
return runSaga(getSnapStateImplementation, ...args).result();
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function* updateSnapStateImplementation(_snapId, newState, encrypted = true) {
|
|
18
|
+
yield put(setState({ state: newState, encrypted }));
|
|
19
|
+
}
|
|
20
|
+
function getUpdateSnapStateMethodImplementation(runSaga) {
|
|
21
|
+
return (...args) => {
|
|
22
|
+
runSaga(updateSnapStateImplementation, ...args).result();
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function* clearSnapStateImplementation(_snapId, encrypted = true) {
|
|
26
|
+
yield put(clearState({ encrypted }));
|
|
27
|
+
}
|
|
28
|
+
function getClearSnapStateMethodImplementation(runSaga) {
|
|
29
|
+
return async (...args) => {
|
|
30
|
+
runSaga(clearSnapStateImplementation, ...args).result();
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
getGetSnapStateMethodImplementation,
|
|
36
|
+
getUpdateSnapStateMethodImplementation,
|
|
37
|
+
getClearSnapStateMethodImplementation
|
|
38
|
+
};
|
|
39
|
+
//# sourceMappingURL=chunk-6RDNSELT.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/hooks/state.ts"],"sourcesContent":["import type { SagaIterator } from 'redux-saga';\nimport { put, select } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { clearState, getState, setState } from '../../store';\n\n/**\n * Get the Snap state from the store.\n *\n * @param _snapId - The ID of the Snap to get the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to get the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @returns The state of the Snap.\n * @yields Selects the state from the store.\n */\nfunction* getSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<string> {\n return yield select(getState(encrypted));\n}\n\n/**\n * Get the implementation of the `getSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `getSnapState` hook.\n */\nexport function getGetSnapStateMethodImplementation(runSaga: RunSagaFunction) {\n return (...args: Parameters<typeof getSnapStateImplementation>) => {\n return runSaga(getSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Update the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to update the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param newState - The new state.\n * @param encrypted - Whether to update the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* updateSnapStateImplementation(\n _snapId: string,\n newState: string,\n encrypted = true,\n): SagaIterator<void> {\n yield put(setState({ state: newState, encrypted }));\n}\n\n/**\n * Get the implementation of the `updateSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `updateSnapState` hook.\n */\nexport function getUpdateSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return (...args: Parameters<typeof updateSnapStateImplementation>) => {\n runSaga(updateSnapStateImplementation, ...args).result();\n };\n}\n\n/**\n * Clear the Snap state in the store.\n *\n * @param _snapId - The ID of the Snap to clear the state for. This is ignored\n * because the simulator only supports one Snap.\n * @param encrypted - Whether to clear the encrypted or unencrypted state.\n * Defaults to encrypted state.\n * @yields Puts the new state in the store.\n */\nfunction* clearSnapStateImplementation(\n _snapId: string,\n encrypted = true,\n): SagaIterator<void> {\n yield put(clearState({ encrypted }));\n}\n\n/**\n * Get the implementation of the `clearSnapState` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `clearSnapState` hook.\n */\nexport function getClearSnapStateMethodImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (...args: Parameters<typeof clearSnapStateImplementation>) => {\n runSaga(clearSnapStateImplementation, ...args).result();\n };\n}\n"],"mappings":";;;;;;;AACA,SAAS,KAAK,cAAc;AAe5B,UAAU,2BACR,SACA,YAAY,MACU;AACtB,SAAO,MAAM,OAAO,SAAS,SAAS,CAAC;AACzC;AAQO,SAAS,oCAAoC,SAA0B;AAC5E,SAAO,IAAI,SAAwD;AACjE,WAAO,QAAQ,4BAA4B,GAAG,IAAI,EAAE,OAAO;AAAA,EAC7D;AACF;AAYA,UAAU,8BACR,SACA,UACA,YAAY,MACQ;AACpB,QAAM,IAAI,SAAS,EAAE,OAAO,UAAU,UAAU,CAAC,CAAC;AACpD;AAQO,SAAS,uCACd,SACA;AACA,SAAO,IAAI,SAA2D;AACpE,YAAQ,+BAA+B,GAAG,IAAI,EAAE,OAAO;AAAA,EACzD;AACF;AAWA,UAAU,6BACR,SACA,YAAY,MACQ;AACpB,QAAM,IAAI,WAAW,EAAE,UAAU,CAAC,CAAC;AACrC;AAQO,SAAS,sCACd,SACA;AACA,SAAO,UAAU,SAA0D;AACzE,YAAQ,8BAA8B,GAAG,IAAI,EAAE,OAAO;AAAA,EACxD;AACF;","names":[]}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
rootLogger
|
|
3
|
+
} from "./chunk-WEI35OIM.mjs";
|
|
4
|
+
|
|
5
|
+
// src/internals/server.ts
|
|
6
|
+
import {
|
|
7
|
+
assertIsSnapManifest,
|
|
8
|
+
isDirectory,
|
|
9
|
+
isFile
|
|
10
|
+
} from "@metamask/snaps-utils/node";
|
|
11
|
+
import { createModuleLogger } from "@metamask/utils";
|
|
12
|
+
import express from "express";
|
|
13
|
+
import { promises as fs } from "fs";
|
|
14
|
+
import { createServer } from "http";
|
|
15
|
+
import { resolve as pathResolve } from "path";
|
|
16
|
+
async function assertRoot(root) {
|
|
17
|
+
if (!root) {
|
|
18
|
+
throw new Error("You must specify a root directory.");
|
|
19
|
+
}
|
|
20
|
+
if (!await isDirectory(root, false)) {
|
|
21
|
+
throw new Error(`Root directory "${root}" is not a directory.`);
|
|
22
|
+
}
|
|
23
|
+
const manifestPath = pathResolve(root, "snap.manifest.json");
|
|
24
|
+
const manifest = await fs.readFile(manifestPath, "utf8").then(JSON.parse);
|
|
25
|
+
assertIsSnapManifest(manifest);
|
|
26
|
+
const filePath = pathResolve(root, manifest.source.location.npm.filePath);
|
|
27
|
+
if (!await isFile(filePath)) {
|
|
28
|
+
throw new Error(
|
|
29
|
+
`File "${filePath}" does not exist, or is not a file. Did you forget to build your snap?`
|
|
30
|
+
);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
async function startServer(options) {
|
|
34
|
+
await assertRoot(options.root);
|
|
35
|
+
const log = createModuleLogger(rootLogger, "server");
|
|
36
|
+
const app = express();
|
|
37
|
+
app.use((_request, response, next) => {
|
|
38
|
+
response.header("Access-Control-Allow-Origin", "*");
|
|
39
|
+
response.header("Access-Control-Allow-Credentials", "true");
|
|
40
|
+
response.header("Access-Control-Allow-Methods", "GET, OPTIONS");
|
|
41
|
+
response.header("Access-Control-Allow-Headers", "Content-Type");
|
|
42
|
+
next();
|
|
43
|
+
});
|
|
44
|
+
app.use(express.static(pathResolve(process.cwd(), options.root)));
|
|
45
|
+
const server = createServer(app);
|
|
46
|
+
return await new Promise((resolve, reject) => {
|
|
47
|
+
server.listen(options.port, () => {
|
|
48
|
+
resolve(server);
|
|
49
|
+
});
|
|
50
|
+
server.on("error", (error) => {
|
|
51
|
+
log(error);
|
|
52
|
+
reject(error);
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export {
|
|
58
|
+
startServer
|
|
59
|
+
};
|
|
60
|
+
//# sourceMappingURL=chunk-72YN2D26.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/server.ts"],"sourcesContent":["import type { SnapManifest } from '@metamask/snaps-utils';\nimport {\n assertIsSnapManifest,\n isDirectory,\n isFile,\n} from '@metamask/snaps-utils/node';\nimport { createModuleLogger } from '@metamask/utils';\nimport express from 'express';\nimport { promises as fs } from 'fs';\nimport type { Server } from 'http';\nimport { createServer } from 'http';\nimport { resolve as pathResolve } from 'path';\n\nimport type { SnapsEnvironmentOptions } from '../options';\nimport { rootLogger } from './logger';\n\nexport type ServerOptions = Required<\n // We need a double `Required` for the type to be inferred correctly.\n Required<SnapsEnvironmentOptions>['server']\n>;\n\n/**\n * Check that:\n *\n * - The root directory exists.\n * - The root directory contains a `snap.manifest.json` file.\n * - The file path in the manifest exists.\n *\n * @param root - The root directory.\n * @throws If any of the checks fail.\n */\nasync function assertRoot(root: string) {\n if (!root) {\n throw new Error('You must specify a root directory.');\n }\n\n if (!(await isDirectory(root, false))) {\n throw new Error(`Root directory \"${root}\" is not a directory.`);\n }\n\n const manifestPath = pathResolve(root, 'snap.manifest.json');\n const manifest: SnapManifest = await fs\n .readFile(manifestPath, 'utf8')\n .then(JSON.parse);\n\n assertIsSnapManifest(manifest);\n const filePath = pathResolve(root, manifest.source.location.npm.filePath);\n\n if (!(await isFile(filePath))) {\n throw new Error(\n `File \"${filePath}\" does not exist, or is not a file. Did you forget to build your snap?`,\n );\n }\n}\n\n/**\n * Start an HTTP server on `localhost` with a random port. This is used to serve\n * the static files for the environment.\n *\n * @param options - The options to use.\n * @param options.port - The port to use for the server.\n * @param options.root - The root directory to serve from the server.\n * @returns The HTTP server.\n */\nexport async function startServer(options: ServerOptions) {\n await assertRoot(options.root);\n\n const log = createModuleLogger(rootLogger, 'server');\n const app = express();\n\n app.use((_request, response, next) => {\n response.header('Access-Control-Allow-Origin', '*');\n response.header('Access-Control-Allow-Credentials', 'true');\n response.header('Access-Control-Allow-Methods', 'GET, OPTIONS');\n response.header('Access-Control-Allow-Headers', 'Content-Type');\n\n next();\n });\n\n app.use(express.static(pathResolve(process.cwd(), options.root)));\n\n const server = createServer(app);\n return await new Promise<Server>((resolve, reject) => {\n server.listen(options.port, () => {\n resolve(server);\n });\n\n server.on('error', (error) => {\n log(error);\n reject(error);\n });\n });\n}\n"],"mappings":";;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,0BAA0B;AACnC,OAAO,aAAa;AACpB,SAAS,YAAY,UAAU;AAE/B,SAAS,oBAAoB;AAC7B,SAAS,WAAW,mBAAmB;AAoBvC,eAAe,WAAW,MAAc;AACtC,MAAI,CAAC,MAAM;AACT,UAAM,IAAI,MAAM,oCAAoC;AAAA,EACtD;AAEA,MAAI,CAAE,MAAM,YAAY,MAAM,KAAK,GAAI;AACrC,UAAM,IAAI,MAAM,mBAAmB,IAAI,uBAAuB;AAAA,EAChE;AAEA,QAAM,eAAe,YAAY,MAAM,oBAAoB;AAC3D,QAAM,WAAyB,MAAM,GAClC,SAAS,cAAc,MAAM,EAC7B,KAAK,KAAK,KAAK;AAElB,uBAAqB,QAAQ;AAC7B,QAAM,WAAW,YAAY,MAAM,SAAS,OAAO,SAAS,IAAI,QAAQ;AAExE,MAAI,CAAE,MAAM,OAAO,QAAQ,GAAI;AAC7B,UAAM,IAAI;AAAA,MACR,SAAS,QAAQ;AAAA,IACnB;AAAA,EACF;AACF;AAWA,eAAsB,YAAY,SAAwB;AACxD,QAAM,WAAW,QAAQ,IAAI;AAE7B,QAAM,MAAM,mBAAmB,YAAY,QAAQ;AACnD,QAAM,MAAM,QAAQ;AAEpB,MAAI,IAAI,CAAC,UAAU,UAAU,SAAS;AACpC,aAAS,OAAO,+BAA+B,GAAG;AAClD,aAAS,OAAO,oCAAoC,MAAM;AAC1D,aAAS,OAAO,gCAAgC,cAAc;AAC9D,aAAS,OAAO,gCAAgC,cAAc;AAE9D,SAAK;AAAA,EACP,CAAC;AAED,MAAI,IAAI,QAAQ,OAAO,YAAY,QAAQ,IAAI,GAAG,QAAQ,IAAI,CAAC,CAAC;AAEhE,QAAM,SAAS,aAAa,GAAG;AAC/B,SAAO,MAAM,IAAI,QAAgB,CAAC,SAAS,WAAW;AACpD,WAAO,OAAO,QAAQ,MAAM,MAAM;AAChC,cAAQ,MAAM;AAAA,IAChB,CAAC;AAED,WAAO,GAAG,SAAS,CAAC,UAAU;AAC5B,UAAI,KAAK;AACT,aAAO,KAAK;AAAA,IACd,CAAC;AAAA,EACH,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/internals/environment.ts
|
|
2
|
+
var _utils = require('@metamask/utils');
|
|
3
|
+
function getEnvironment() {
|
|
4
|
+
_utils.assert.call(void 0,
|
|
5
|
+
typeof snapsEnvironment !== "undefined",
|
|
6
|
+
"Snaps environment not found. Make sure you have configured the environment correctly."
|
|
7
|
+
);
|
|
8
|
+
return snapsEnvironment;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
exports.getEnvironment = getEnvironment;
|
|
14
|
+
//# sourceMappingURL=chunk-7JLVQJK7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/environment.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAQhB,SAAS,iBAAiB;AAG/B;AAAA,IACE,OAAO,qBAAqB;AAAA,IAC5B;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["import { assert } from '@metamask/utils';\n\n/**\n * Get the Snaps environment. This asserts that the environment has been\n * configured.\n *\n * @returns The Snaps environment.\n */\nexport function getEnvironment() {\n // `snapsEnvironment` is a global variable that is set by the Jest\n // environment.\n assert(\n typeof snapsEnvironment !== 'undefined',\n 'Snaps environment not found. Make sure you have configured the environment correctly.',\n );\n\n return snapsEnvironment;\n}\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/internals/simulation/methods/hooks/encryption.ts
|
|
2
|
+
function encryptImplementation(password, value) {
|
|
3
|
+
return JSON.stringify({
|
|
4
|
+
password,
|
|
5
|
+
value
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
function decryptImplementation(password, value) {
|
|
9
|
+
const decryptedValue = JSON.parse(value);
|
|
10
|
+
if (decryptedValue.password !== password) {
|
|
11
|
+
throw new Error(
|
|
12
|
+
"Incorrect password. This is a bug in `@metamask/snaps-jest`, please report it."
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return decryptedValue.value;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.encryptImplementation = encryptImplementation; exports.decryptImplementation = decryptImplementation;
|
|
22
|
+
//# sourceMappingURL=chunk-AH7YNG6N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/hooks/encryption.ts"],"names":[],"mappings":";AAeO,SAAS,sBAAsB,UAAkB,OAAa;AACnE,SAAO,KAAK,UAAU;AAAA,IACpB;AAAA,IACA;AAAA,EACF,CAAC;AACH;AAeO,SAAS,sBAAsB,UAAkB,OAAe;AACrE,QAAM,iBAAiB,KAAK,MAAM,KAAK;AACvC,MAAI,eAAe,aAAa,UAAU;AACxC,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO,eAAe;AACxB","sourcesContent":["import type { Json } from '@metamask/utils';\n\n/**\n * Mocks encrypting a value using a password. This is not a real encryption\n * method, but rather is used to simulate encryption in the tests.\n *\n * Ideally we would use a real encryption method, such as\n * `@metamask/browser-passworder`, but it doesn't seem to work with Node.js 18\n * without some mocking. We can switch to a real encryption method once we\n * drop support for Node.js 18.\n *\n * @param password - The password to use.\n * @param value - The value to encrypt.\n * @returns The \"encrypted\" value.\n */\nexport function encryptImplementation(password: string, value: Json) {\n return JSON.stringify({\n password,\n value,\n });\n}\n\n/**\n * Mocks decrypting a value using a password. This is not a real encryption\n * method, but rather is used to simulate encryption in the tests.\n *\n * Ideally we would use a real decryption method, such as\n * `@metamask/browser-passworder`, but it doesn't seem to work with Node.js 18\n * without some mocking. We can switch to a real encryption method once we\n * drop support for Node.js 18.\n *\n * @param password - The password to use.\n * @param value - The value to decrypt.\n * @returns The \"decrypted\" value.\n */\nexport function decryptImplementation(password: string, value: string) {\n const decryptedValue = JSON.parse(value);\n if (decryptedValue.password !== password) {\n throw new Error(\n 'Incorrect password. This is a bug in `@metamask/snaps-jest`, please report it.',\n );\n }\n\n return decryptedValue.value;\n}\n"]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// src/internals/simulation/store/notifications.ts
|
|
2
|
+
import { createSelector, createSlice } from "@reduxjs/toolkit";
|
|
3
|
+
var INITIAL_STATE = {
|
|
4
|
+
notifications: []
|
|
5
|
+
};
|
|
6
|
+
var notificationsSlice = createSlice({
|
|
7
|
+
name: "notifications",
|
|
8
|
+
initialState: INITIAL_STATE,
|
|
9
|
+
reducers: {
|
|
10
|
+
addNotification: (state, action) => {
|
|
11
|
+
state.notifications.push(action.payload);
|
|
12
|
+
},
|
|
13
|
+
removeNotification: (state, action) => {
|
|
14
|
+
state.notifications = state.notifications.filter(
|
|
15
|
+
(notification) => notification.id !== action.payload
|
|
16
|
+
);
|
|
17
|
+
},
|
|
18
|
+
clearNotifications: (state) => {
|
|
19
|
+
state.notifications = [];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
var { addNotification, removeNotification, clearNotifications } = notificationsSlice.actions;
|
|
24
|
+
var getNotifications = createSelector(
|
|
25
|
+
(state) => state.notifications,
|
|
26
|
+
({ notifications }) => notifications
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
export {
|
|
30
|
+
notificationsSlice,
|
|
31
|
+
addNotification,
|
|
32
|
+
removeNotification,
|
|
33
|
+
clearNotifications,
|
|
34
|
+
getNotifications
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=chunk-AIZADBRK.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/store/notifications.ts"],"sourcesContent":["import type { NotificationType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\n/**\n * A notification object.\n *\n * @property id - A unique ID for the notification.\n * @property message - The notification message.\n * @property type - The notification type.\n */\nexport type Notification = {\n id: string;\n message: string;\n type: NotificationType;\n};\n\n/**\n * The notifications state.\n *\n * @property notifications - An array of notifications.\n */\nexport type NotificationsState = {\n notifications: Notification[];\n};\n\n/**\n * The initial notifications state.\n */\nconst INITIAL_STATE: NotificationsState = {\n notifications: [],\n};\n\nexport const notificationsSlice = createSlice({\n name: 'notifications',\n initialState: INITIAL_STATE,\n reducers: {\n addNotification: (state, action: PayloadAction<Notification>) => {\n state.notifications.push(action.payload);\n },\n removeNotification: (state, action: PayloadAction<string>) => {\n state.notifications = state.notifications.filter(\n (notification) => notification.id !== action.payload,\n );\n },\n clearNotifications: (state) => {\n state.notifications = [];\n },\n },\n});\n\nexport const { addNotification, removeNotification, clearNotifications } =\n notificationsSlice.actions;\n\n/**\n * Get the notifications from the state.\n *\n * @param state - The application state.\n * @returns An array of notifications.\n */\nexport const getNotifications = createSelector(\n (state: ApplicationState) => state.notifications,\n ({ notifications }) => notifications,\n);\n"],"mappings":";AAEA,SAAS,gBAAgB,mBAAmB;AA6B5C,IAAM,gBAAoC;AAAA,EACxC,eAAe,CAAC;AAClB;AAEO,IAAM,qBAAqB,YAAY;AAAA,EAC5C,MAAM;AAAA,EACN,cAAc;AAAA,EACd,UAAU;AAAA,IACR,iBAAiB,CAAC,OAAO,WAAwC;AAC/D,YAAM,cAAc,KAAK,OAAO,OAAO;AAAA,IACzC;AAAA,IACA,oBAAoB,CAAC,OAAO,WAAkC;AAC5D,YAAM,gBAAgB,MAAM,cAAc;AAAA,QACxC,CAAC,iBAAiB,aAAa,OAAO,OAAO;AAAA,MAC/C;AAAA,IACF;AAAA,IACA,oBAAoB,CAAC,UAAU;AAC7B,YAAM,gBAAgB,CAAC;AAAA,IACzB;AAAA,EACF;AACF,CAAC;AAEM,IAAM,EAAE,iBAAiB,oBAAoB,mBAAmB,IACrE,mBAAmB;AAQd,IAAM,mBAAmB;AAAA,EAC9B,CAAC,UAA4B,MAAM;AAAA,EACnC,CAAC,EAAE,cAAc,MAAM;AACzB;","names":[]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
addNotification
|
|
3
|
+
} from "./chunk-AIZADBRK.mjs";
|
|
4
|
+
|
|
5
|
+
// src/internals/simulation/methods/hooks/notifications.ts
|
|
6
|
+
import { NotificationType } from "@metamask/snaps-sdk";
|
|
7
|
+
import { nanoid } from "@reduxjs/toolkit";
|
|
8
|
+
import { put } from "redux-saga/effects";
|
|
9
|
+
function* showNativeNotificationImplementation(_snapId, { message }) {
|
|
10
|
+
yield put(
|
|
11
|
+
addNotification({ id: nanoid(), type: NotificationType.Native, message })
|
|
12
|
+
);
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
function getShowNativeNotificationImplementation(runSaga) {
|
|
16
|
+
return async (...args) => {
|
|
17
|
+
return await runSaga(
|
|
18
|
+
showNativeNotificationImplementation,
|
|
19
|
+
...args
|
|
20
|
+
).toPromise();
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
function* showInAppNotificationImplementation(_snapId, { message }) {
|
|
24
|
+
yield put(
|
|
25
|
+
addNotification({ id: nanoid(), type: NotificationType.InApp, message })
|
|
26
|
+
);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function getShowInAppNotificationImplementation(runSaga) {
|
|
30
|
+
return async (...args) => {
|
|
31
|
+
return await runSaga(
|
|
32
|
+
showInAppNotificationImplementation,
|
|
33
|
+
...args
|
|
34
|
+
).toPromise();
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
getShowNativeNotificationImplementation,
|
|
40
|
+
getShowInAppNotificationImplementation
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=chunk-AKFRQ5EJ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/methods/hooks/notifications.ts"],"sourcesContent":["import type { NotifyParams } from '@metamask/snaps-sdk';\nimport { NotificationType } from '@metamask/snaps-sdk';\nimport { nanoid } from '@reduxjs/toolkit';\nimport type { SagaIterator } from 'redux-saga';\nimport { put } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { addNotification } from '../../store';\n\n/**\n * Show a native notification to the user.\n *\n * @param _snapId - The ID of the Snap that created the notification.\n * @param options - The notification options.\n * @param options.message - The message to show in the notification.\n * @yields Adds the notification to the store.\n * @returns `null`.\n */\nfunction* showNativeNotificationImplementation(\n _snapId: string,\n { message }: NotifyParams,\n): SagaIterator {\n yield put(\n addNotification({ id: nanoid(), type: NotificationType.Native, message }),\n );\n\n return null;\n}\n\n/**\n * Get a method that can be used to show a native notification.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A method that can be used to show a native notification.\n */\nexport function getShowNativeNotificationImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (\n ...args: Parameters<typeof showNativeNotificationImplementation>\n ) => {\n return await runSaga(\n showNativeNotificationImplementation,\n ...args,\n ).toPromise();\n };\n}\n\n/**\n * Show an in-app notification to the user.\n *\n * @param _snapId - The ID of the Snap that created the notification.\n * @param options - The notification options.\n * @param options.message - The message to show in the notification.\n * @yields Adds the notification to the store.\n * @returns `null`.\n */\nfunction* showInAppNotificationImplementation(\n _snapId: string,\n { message }: NotifyParams,\n): SagaIterator<null> {\n yield put(\n addNotification({ id: nanoid(), type: NotificationType.InApp, message }),\n );\n\n return null;\n}\n\n/**\n * Get a method that can be used to show an in-app notification.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A method that can be used to show an in-app notification.\n */\nexport function getShowInAppNotificationImplementation(\n runSaga: RunSagaFunction,\n) {\n return async (\n ...args: Parameters<typeof showInAppNotificationImplementation>\n ) => {\n return await runSaga(\n showInAppNotificationImplementation,\n ...args,\n ).toPromise();\n };\n}\n"],"mappings":";;;;;AACA,SAAS,wBAAwB;AACjC,SAAS,cAAc;AAEvB,SAAS,WAAW;AAcpB,UAAU,qCACR,SACA,EAAE,QAAQ,GACI;AACd,QAAM;AAAA,IACJ,gBAAgB,EAAE,IAAI,OAAO,GAAG,MAAM,iBAAiB,QAAQ,QAAQ,CAAC;AAAA,EAC1E;AAEA,SAAO;AACT;AAQO,SAAS,wCACd,SACA;AACA,SAAO,UACF,SACA;AACH,WAAO,MAAM;AAAA,MACX;AAAA,MACA,GAAG;AAAA,IACL,EAAE,UAAU;AAAA,EACd;AACF;AAWA,UAAU,oCACR,SACA,EAAE,QAAQ,GACU;AACpB,QAAM;AAAA,IACJ,gBAAgB,EAAE,IAAI,OAAO,GAAG,MAAM,iBAAiB,OAAO,QAAQ,CAAC;AAAA,EACzE;AAEA,SAAO;AACT;AAQO,SAAS,uCACd,SACA;AACA,SAAO,UACF,SACA;AACH,WAAO,MAAM;AAAA,MACX;AAAA,MACA,GAAG;AAAA,IACL,EAAE,UAAU;AAAA,EACd;AACF;","names":[]}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// src/options.ts
|
|
2
|
+
import {
|
|
3
|
+
boolean,
|
|
4
|
+
create,
|
|
5
|
+
defaulted,
|
|
6
|
+
number,
|
|
7
|
+
object,
|
|
8
|
+
string,
|
|
9
|
+
type
|
|
10
|
+
} from "superstruct";
|
|
11
|
+
var SnapsEnvironmentOptionsStruct = type({
|
|
12
|
+
server: defaulted(
|
|
13
|
+
object({
|
|
14
|
+
enabled: defaulted(boolean(), true),
|
|
15
|
+
port: defaulted(number(), 0),
|
|
16
|
+
root: defaulted(string(), process.cwd())
|
|
17
|
+
}),
|
|
18
|
+
{}
|
|
19
|
+
)
|
|
20
|
+
});
|
|
21
|
+
function getOptions(testEnvironmentOptions) {
|
|
22
|
+
return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export {
|
|
26
|
+
getOptions
|
|
27
|
+
};
|
|
28
|
+
//# sourceMappingURL=chunk-AUB7XPDH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/options.ts"],"sourcesContent":["import type { Infer } from 'superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from 'superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,gCAAgC,KAAK;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,SAAS,UAAU,QAAQ,GAAG,IAAI;AAAA,MAClC,MAAM,UAAU,OAAO,GAAG,CAAC;AAAA,MAC3B,MAAM,UAAU,OAAO,GAAG,QAAQ,IAAI,CAAC;AAAA,IACzC,CAAC;AAAA,IACD,CAAC;AAAA,EACH;AACF,CAAC;AAuCM,SAAS,WAAW,wBAAiD;AAC1E,SAAO,OAAO,wBAAwB,6BAA6B;AACrE;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getJsonRpcMock
|
|
3
|
+
} from "./chunk-J2ID3DS7.mjs";
|
|
4
|
+
|
|
5
|
+
// src/internals/simulation/middleware/mock.ts
|
|
6
|
+
function createMockMiddleware(store) {
|
|
7
|
+
return function mockMiddleware(request, response, next, end) {
|
|
8
|
+
const result = getJsonRpcMock(store.getState(), request.method);
|
|
9
|
+
if (result) {
|
|
10
|
+
response.result = result;
|
|
11
|
+
return end();
|
|
12
|
+
}
|
|
13
|
+
return next();
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
createMockMiddleware
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=chunk-BJMTD7H2.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internals/simulation/middleware/mock.ts"],"sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport type { Store } from '../store';\nimport { getJsonRpcMock } from '../store/mocks';\n\n/**\n * Create a middleware for handling JSON-RPC methods that have been mocked.\n *\n * @param store - The Redux store to use.\n * @returns A middleware function.\n */\nexport function createMockMiddleware(\n store: Store,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n return function mockMiddleware(request, response, next, end) {\n const result = getJsonRpcMock(store.getState(), request.method);\n if (result) {\n response.result = result;\n return end();\n }\n\n return next();\n };\n}\n"],"mappings":";;;;;AAYO,SAAS,qBACd,OACwC;AACxC,SAAO,SAAS,eAAe,SAAS,UAAU,MAAM,KAAK;AAC3D,UAAM,SAAS,eAAe,MAAM,SAAS,GAAG,QAAQ,MAAM;AAC9D,QAAI,QAAQ;AACV,eAAS,SAAS;AAClB,aAAO,IAAI;AAAA,IACb;AAEA,WAAO,KAAK;AAAA,EACd;AACF;","names":[]}
|