@metamask/snaps-utils 6.1.0 → 7.0.1
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 +24 -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-224DMTNJ.mjs +409 -0
- package/dist/chunk-224DMTNJ.mjs.map +1 -0
- package/dist/chunk-2IWSQJKQ.mjs +193 -0
- package/dist/chunk-2IWSQJKQ.mjs.map +1 -0
- package/dist/chunk-2LBN5T56.js +64 -0
- package/dist/chunk-2LBN5T56.js.map +1 -0
- package/dist/chunk-2PCPD5XY.js +169 -0
- package/dist/chunk-2PCPD5XY.js.map +1 -0
- package/dist/chunk-3SOYDY4W.js +152 -0
- package/dist/chunk-3SOYDY4W.js.map +1 -0
- package/dist/chunk-44GPX66J.mjs +70 -0
- package/dist/chunk-44GPX66J.mjs.map +1 -0
- package/dist/chunk-44VFHYJO.js +249 -0
- package/dist/chunk-44VFHYJO.js.map +1 -0
- package/dist/chunk-473MIETW.js +18 -0
- package/dist/chunk-473MIETW.js.map +1 -0
- package/dist/chunk-4BDR6KRH.js +50 -0
- package/dist/chunk-4BDR6KRH.js.map +1 -0
- package/dist/chunk-4CMD46B2.js +1 -0
- package/dist/chunk-4CMD46B2.js.map +1 -0
- package/dist/chunk-5R7UF7KM.mjs +21 -0
- package/dist/chunk-5R7UF7KM.mjs.map +1 -0
- package/dist/chunk-63OXILAY.mjs +69 -0
- package/dist/chunk-63OXILAY.mjs.map +1 -0
- package/dist/chunk-6CHO3LOX.mjs +10 -0
- package/dist/chunk-6CHO3LOX.mjs.map +1 -0
- package/dist/chunk-6LOYTBS3.js +107 -0
- package/dist/chunk-6LOYTBS3.js.map +1 -0
- package/dist/chunk-6YRUDGNL.mjs +18 -0
- package/dist/chunk-6YRUDGNL.mjs.map +1 -0
- package/dist/chunk-772OPTGX.js +70 -0
- package/dist/chunk-772OPTGX.js.map +1 -0
- package/dist/chunk-7LG4D4XA.mjs +20 -0
- package/dist/chunk-7LG4D4XA.mjs.map +1 -0
- package/dist/chunk-7LOABHVW.js +1 -0
- package/dist/chunk-7LOABHVW.js.map +1 -0
- package/dist/chunk-7MTAHOWC.mjs +1 -0
- package/dist/chunk-7MTAHOWC.mjs.map +1 -0
- package/dist/chunk-7P62OIGX.js +69 -0
- package/dist/chunk-7P62OIGX.js.map +1 -0
- package/dist/chunk-7Y3WSN44.mjs +103 -0
- package/dist/chunk-7Y3WSN44.mjs.map +1 -0
- package/dist/chunk-A3RRMELT.mjs +1 -0
- package/dist/chunk-A3RRMELT.mjs.map +1 -0
- package/dist/chunk-A6E325SZ.js +211 -0
- package/dist/chunk-A6E325SZ.js.map +1 -0
- package/dist/chunk-AFQY2CNY.js +109 -0
- package/dist/chunk-AFQY2CNY.js.map +1 -0
- package/dist/chunk-AOGVLPQZ.js +18 -0
- package/dist/chunk-AOGVLPQZ.js.map +1 -0
- package/dist/chunk-AS5P6JRP.mjs +9 -0
- package/dist/chunk-AS5P6JRP.mjs.map +1 -0
- package/dist/chunk-ASZWZ7JT.js +20 -0
- package/dist/chunk-ASZWZ7JT.js.map +1 -0
- package/dist/chunk-BGSO2GQC.mjs +41 -0
- package/dist/chunk-BGSO2GQC.mjs.map +1 -0
- package/dist/chunk-CMOSYNZR.js +95 -0
- package/dist/chunk-CMOSYNZR.js.map +1 -0
- package/dist/chunk-CNNMLOQ6.js +409 -0
- package/dist/chunk-CNNMLOQ6.js.map +1 -0
- package/dist/chunk-CQRPSEH3.js +74 -0
- package/dist/chunk-CQRPSEH3.js.map +1 -0
- package/dist/chunk-DKDGMZFU.mjs +74 -0
- package/dist/chunk-DKDGMZFU.mjs.map +1 -0
- package/dist/chunk-E3BDBG6T.js +20 -0
- package/dist/chunk-E3BDBG6T.js.map +1 -0
- package/dist/chunk-EA2FOAEG.mjs +64 -0
- package/dist/chunk-EA2FOAEG.mjs.map +1 -0
- package/dist/chunk-EFRPCO3C.js +1 -0
- package/dist/chunk-EFRPCO3C.js.map +1 -0
- package/dist/chunk-ENKAY3PI.js +281 -0
- package/dist/chunk-ENKAY3PI.js.map +1 -0
- package/dist/chunk-EXUEHPZ4.mjs +107 -0
- package/dist/chunk-EXUEHPZ4.mjs.map +1 -0
- package/dist/chunk-FOWIC2SO.mjs +38 -0
- package/dist/chunk-FOWIC2SO.mjs.map +1 -0
- package/dist/chunk-GTAYOKI4.mjs +211 -0
- package/dist/chunk-GTAYOKI4.mjs.map +1 -0
- package/dist/chunk-HF7HUZ5Z.js +10 -0
- package/dist/chunk-HF7HUZ5Z.js.map +1 -0
- package/dist/chunk-HJRCBSNA.mjs +32 -0
- package/dist/chunk-HJRCBSNA.mjs.map +1 -0
- package/dist/chunk-HJYRGKCX.js +50 -0
- package/dist/chunk-HJYRGKCX.js.map +1 -0
- package/dist/chunk-HYF7Q6VY.mjs +1 -0
- package/dist/chunk-HYF7Q6VY.mjs.map +1 -0
- package/dist/chunk-I77AVJKV.mjs +152 -0
- package/dist/chunk-I77AVJKV.mjs.map +1 -0
- package/dist/chunk-IGMAXVPP.mjs +21 -0
- package/dist/chunk-IGMAXVPP.mjs.map +1 -0
- package/dist/chunk-IHQPAJ2B.js +38 -0
- package/dist/chunk-IHQPAJ2B.js.map +1 -0
- package/dist/chunk-IJX3CXOY.js +9 -0
- package/dist/chunk-IJX3CXOY.js.map +1 -0
- package/dist/chunk-IPOE62V4.js +30 -0
- package/dist/chunk-IPOE62V4.js.map +1 -0
- package/dist/chunk-IV3FSWZ7.mjs +9 -0
- package/dist/chunk-IV3FSWZ7.mjs.map +1 -0
- package/dist/chunk-IXBJNVHK.js +22 -0
- package/dist/chunk-IXBJNVHK.js.map +1 -0
- package/dist/chunk-JI5NQ2C3.mjs +1 -0
- package/dist/chunk-JI5NQ2C3.mjs.map +1 -0
- package/dist/chunk-JMDSN227.mjs +25 -0
- package/dist/chunk-JMDSN227.mjs.map +1 -0
- package/dist/chunk-K6BCBPXF.js +151 -0
- package/dist/chunk-K6BCBPXF.js.map +1 -0
- package/dist/chunk-KMLVVVK3.mjs +22 -0
- package/dist/chunk-KMLVVVK3.mjs.map +1 -0
- package/dist/chunk-LBRWAC27.js +56 -0
- package/dist/chunk-LBRWAC27.js.map +1 -0
- package/dist/chunk-LCWDLIK5.mjs +281 -0
- package/dist/chunk-LCWDLIK5.mjs.map +1 -0
- package/dist/chunk-LEKZPKS2.js +21 -0
- package/dist/chunk-LEKZPKS2.js.map +1 -0
- package/dist/chunk-LSPOXPJJ.mjs +63 -0
- package/dist/chunk-LSPOXPJJ.mjs.map +1 -0
- package/dist/chunk-MCEKOGEG.mjs +50 -0
- package/dist/chunk-MCEKOGEG.mjs.map +1 -0
- package/dist/chunk-MLOQHUOY.js +32 -0
- package/dist/chunk-MLOQHUOY.js.map +1 -0
- package/dist/chunk-N722KRZW.js +41 -0
- package/dist/chunk-N722KRZW.js.map +1 -0
- package/dist/chunk-NUCLSR2G.js +8 -0
- package/dist/chunk-NUCLSR2G.js.map +1 -0
- package/dist/chunk-P252LKUT.mjs +9 -0
- package/dist/chunk-P252LKUT.mjs.map +1 -0
- package/dist/chunk-PHUTP7NB.js +25 -0
- package/dist/chunk-PHUTP7NB.js.map +1 -0
- package/dist/chunk-PJMEJVOB.mjs +29 -0
- package/dist/chunk-PJMEJVOB.mjs.map +1 -0
- package/dist/chunk-PLBSSUVY.js +29 -0
- package/dist/chunk-PLBSSUVY.js.map +1 -0
- package/dist/chunk-Q7RCL5IE.js +30 -0
- package/dist/chunk-Q7RCL5IE.js.map +1 -0
- package/dist/chunk-QSCKTRRU.js +21 -0
- package/dist/chunk-QSCKTRRU.js.map +1 -0
- package/dist/chunk-QX6MAFJU.mjs +169 -0
- package/dist/chunk-QX6MAFJU.mjs.map +1 -0
- package/dist/chunk-QYPLUMB7.mjs +249 -0
- package/dist/chunk-QYPLUMB7.mjs.map +1 -0
- package/dist/chunk-RAZ7XG4Z.mjs +1 -0
- package/dist/chunk-RAZ7XG4Z.mjs.map +1 -0
- package/dist/chunk-SRMDDOVO.mjs +20 -0
- package/dist/chunk-SRMDDOVO.mjs.map +1 -0
- package/dist/chunk-T3VM5YXY.js +1 -0
- package/dist/chunk-T3VM5YXY.js.map +1 -0
- package/dist/chunk-T3YY4JIJ.js +9 -0
- package/dist/chunk-T3YY4JIJ.js.map +1 -0
- package/dist/chunk-T6FWIDA6.mjs +95 -0
- package/dist/chunk-T6FWIDA6.mjs.map +1 -0
- package/dist/chunk-TFP64TMV.js +1 -0
- package/dist/chunk-TFP64TMV.js.map +1 -0
- package/dist/chunk-TG4BDSYJ.js +193 -0
- package/dist/chunk-TG4BDSYJ.js.map +1 -0
- package/dist/chunk-UMZNVWEM.mjs +30 -0
- package/dist/chunk-UMZNVWEM.mjs.map +1 -0
- package/dist/chunk-UW74NLTC.mjs +18 -0
- package/dist/chunk-UW74NLTC.mjs.map +1 -0
- package/dist/chunk-VWGXNUMD.mjs +151 -0
- package/dist/chunk-VWGXNUMD.mjs.map +1 -0
- package/dist/chunk-WEOCOYES.mjs +109 -0
- package/dist/chunk-WEOCOYES.mjs.map +1 -0
- package/dist/chunk-WF56W2AR.mjs +30 -0
- package/dist/chunk-WF56W2AR.mjs.map +1 -0
- package/dist/chunk-X44Z53IG.js +103 -0
- package/dist/chunk-X44Z53IG.js.map +1 -0
- package/dist/chunk-Z2JQNSVL.mjs +8 -0
- package/dist/chunk-Z2JQNSVL.mjs.map +1 -0
- package/dist/chunk-ZJRWU4AJ.mjs +50 -0
- package/dist/chunk-ZJRWU4AJ.mjs.map +1 -0
- package/dist/chunk-ZT3KKTS2.js +9 -0
- package/dist/chunk-ZT3KKTS2.js.map +1 -0
- package/dist/cronjob.js +20 -0
- package/dist/cronjob.js.map +1 -0
- package/dist/cronjob.mjs +20 -0
- package/dist/cronjob.mjs.map +1 -0
- package/dist/deep-clone.js +8 -0
- package/dist/deep-clone.js.map +1 -0
- package/dist/deep-clone.mjs +8 -0
- package/dist/deep-clone.mjs.map +1 -0
- package/dist/default-endowments.js +8 -0
- package/dist/default-endowments.js.map +1 -0
- package/dist/default-endowments.mjs +8 -0
- package/dist/default-endowments.mjs.map +1 -0
- package/dist/derivation-paths.js +13 -0
- package/dist/derivation-paths.js.map +1 -0
- package/dist/derivation-paths.mjs +13 -0
- package/dist/derivation-paths.mjs.map +1 -0
- package/dist/entropy.js +10 -0
- package/dist/entropy.js.map +1 -0
- package/dist/entropy.mjs +10 -0
- package/dist/entropy.mjs.map +1 -0
- package/dist/errors.js +20 -0
- package/dist/errors.js.map +1 -0
- package/dist/errors.mjs +20 -0
- package/dist/errors.mjs.map +1 -0
- package/dist/eval-worker.js +43 -0
- package/dist/eval-worker.js.map +1 -0
- package/dist/eval-worker.mjs +43 -0
- package/dist/eval-worker.mjs.map +1 -0
- package/dist/eval.js +17 -0
- package/dist/eval.js.map +1 -0
- package/dist/eval.mjs +17 -0
- package/dist/eval.mjs.map +1 -0
- package/dist/fs.js +28 -0
- package/dist/fs.js.map +1 -0
- package/dist/fs.mjs +28 -0
- package/dist/fs.mjs.map +1 -0
- package/dist/handler-types.js +10 -0
- package/dist/handler-types.js.map +1 -0
- package/dist/handler-types.mjs +10 -0
- package/dist/handler-types.mjs.map +1 -0
- package/dist/handlers.js +35 -0
- package/dist/handlers.js.map +1 -0
- package/dist/handlers.mjs +35 -0
- package/dist/handlers.mjs.map +1 -0
- package/dist/icon.js +14 -0
- package/dist/icon.js.map +1 -0
- package/dist/icon.mjs +14 -0
- package/dist/icon.mjs.map +1 -0
- package/dist/iframe.js +8 -0
- package/dist/iframe.js.map +1 -0
- package/dist/iframe.mjs +8 -0
- package/dist/iframe.mjs.map +1 -0
- package/dist/index.executionenv.js +134 -0
- package/dist/index.executionenv.js.map +1 -0
- package/dist/index.executionenv.mjs +134 -0
- package/dist/index.executionenv.mjs.map +1 -0
- package/dist/index.js +378 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +378 -0
- package/dist/index.mjs.map +1 -0
- package/dist/json-rpc.js +18 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/json-rpc.mjs +18 -0
- package/dist/json-rpc.mjs.map +1 -0
- package/dist/json.js +8 -0
- package/dist/json.js.map +1 -0
- package/dist/json.mjs +8 -0
- package/dist/json.mjs.map +1 -0
- package/dist/localization.js +23 -0
- package/dist/localization.js.map +1 -0
- package/dist/localization.mjs +23 -0
- package/dist/localization.mjs.map +1 -0
- package/dist/logging.js +14 -0
- package/dist/logging.js.map +1 -0
- package/dist/logging.mjs +14 -0
- package/dist/logging.mjs.map +1 -0
- package/dist/manifest/index.js +59 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/index.mjs +59 -0
- package/dist/manifest/index.mjs.map +1 -0
- package/dist/manifest/manifest.js +42 -0
- package/dist/manifest/manifest.js.map +1 -0
- package/dist/manifest/manifest.mjs +42 -0
- package/dist/manifest/manifest.mjs.map +1 -0
- package/dist/manifest/node.js +85 -0
- package/dist/manifest/node.js.map +1 -0
- package/dist/manifest/node.mjs +85 -0
- package/dist/manifest/node.mjs.map +1 -0
- package/dist/manifest/validation.js +58 -0
- package/dist/manifest/validation.js.map +1 -0
- package/dist/manifest/validation.mjs +58 -0
- package/dist/manifest/validation.mjs.map +1 -0
- package/dist/mock.js +13 -0
- package/dist/mock.js.map +1 -0
- package/dist/mock.mjs +13 -0
- package/dist/mock.mjs.map +1 -0
- package/dist/namespace.js +44 -0
- package/dist/namespace.js.map +1 -0
- package/dist/namespace.mjs +44 -0
- package/dist/namespace.mjs.map +1 -0
- package/dist/node.js +448 -0
- package/dist/node.js.map +1 -0
- package/dist/node.mjs +448 -0
- package/dist/node.mjs.map +1 -0
- package/dist/npm.js +32 -0
- package/dist/npm.js.map +1 -0
- package/dist/npm.mjs +32 -0
- package/dist/npm.mjs.map +1 -0
- package/dist/path.js +8 -0
- package/dist/path.js.map +1 -0
- package/dist/path.mjs +8 -0
- package/dist/path.mjs.map +1 -0
- package/dist/post-process.js +10 -0
- package/dist/post-process.js.map +1 -0
- package/dist/post-process.mjs +10 -0
- package/dist/post-process.mjs.map +1 -0
- package/dist/snaps.js +48 -0
- package/dist/snaps.js.map +1 -0
- package/dist/snaps.mjs +48 -0
- package/dist/snaps.mjs.map +1 -0
- package/dist/strings.js +8 -0
- package/dist/strings.js.map +1 -0
- package/dist/strings.mjs +8 -0
- package/dist/strings.mjs.map +1 -0
- package/dist/structs.js +31 -0
- package/dist/structs.js.map +1 -0
- package/dist/structs.mjs +31 -0
- package/dist/structs.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/types/bytes.d.ts +1 -1
- package/dist/types/checksum.d.ts +1 -1
- package/dist/types/index.d.ts +1 -6
- package/dist/types/json-rpc.d.ts +1 -1
- package/dist/types/localization.d.ts +1 -1
- package/dist/types/manifest/index.d.ts +0 -1
- package/dist/types/manifest/manifest.d.ts +1 -1
- package/dist/types/manifest/node.d.ts +2 -0
- package/dist/types/manifest/validation.d.ts +5 -5
- package/dist/types/node.d.ts +8 -0
- package/dist/types/structs.d.ts +0 -20
- package/dist/types/ui.d.ts +7 -0
- package/dist/types/virtual-file/index.d.ts +0 -1
- package/dist/types/virtual-file/node.d.ts +2 -0
- package/dist/types.js +28 -0
- package/dist/types.js.map +1 -0
- package/dist/types.mjs +28 -0
- package/dist/types.mjs.map +1 -0
- package/dist/ui.js +12 -0
- package/dist/ui.js.map +1 -0
- package/dist/ui.mjs +12 -0
- package/dist/ui.mjs.map +1 -0
- package/dist/validation.js +24 -0
- package/dist/validation.js.map +1 -0
- package/dist/validation.mjs +24 -0
- package/dist/validation.mjs.map +1 -0
- package/dist/versions.js +12 -0
- package/dist/versions.js.map +1 -0
- package/dist/versions.mjs +12 -0
- package/dist/versions.mjs.map +1 -0
- package/dist/virtual-file/VirtualFile.js +9 -0
- package/dist/virtual-file/VirtualFile.js.map +1 -0
- package/dist/virtual-file/VirtualFile.mjs +9 -0
- package/dist/virtual-file/VirtualFile.mjs.map +1 -0
- package/dist/virtual-file/index.js +10 -0
- package/dist/virtual-file/index.js.map +1 -0
- package/dist/virtual-file/index.mjs +10 -0
- package/dist/virtual-file/index.mjs.map +1 -0
- package/dist/virtual-file/node.js +17 -0
- package/dist/virtual-file/node.js.map +1 -0
- package/dist/virtual-file/node.mjs +17 -0
- package/dist/virtual-file/node.mjs.map +1 -0
- package/dist/virtual-file/toVirtualFile.js +12 -0
- package/dist/virtual-file/toVirtualFile.js.map +1 -0
- package/dist/virtual-file/toVirtualFile.mjs +12 -0
- package/dist/virtual-file/toVirtualFile.mjs.map +1 -0
- package/package.json +23 -38
- package/dist/cjs/array.js +0 -23
- package/dist/cjs/array.js.map +0 -1
- package/dist/cjs/auxiliary-files.js +0 -27
- package/dist/cjs/auxiliary-files.js.map +0 -1
- package/dist/cjs/base64.js +0 -44
- package/dist/cjs/base64.js.map +0 -1
- package/dist/cjs/bytes.js +0 -23
- package/dist/cjs/bytes.js.map +0 -1
- package/dist/cjs/caveats.js +0 -48
- package/dist/cjs/caveats.js.map +0 -1
- package/dist/cjs/checksum.js +0 -43
- package/dist/cjs/checksum.js.map +0 -1
- package/dist/cjs/cronjob.js +0 -77
- package/dist/cjs/cronjob.js.map +0 -1
- package/dist/cjs/deep-clone.js +0 -22
- package/dist/cjs/deep-clone.js.map +0 -1
- package/dist/cjs/default-endowments.js +0 -49
- package/dist/cjs/default-endowments.js.map +0 -1
- package/dist/cjs/derivation-paths.js +0 -300
- package/dist/cjs/derivation-paths.js.map +0 -1
- package/dist/cjs/entropy.js +0 -23
- package/dist/cjs/entropy.js.map +0 -1
- package/dist/cjs/errors.js +0 -221
- package/dist/cjs/errors.js.map +0 -1
- package/dist/cjs/eval-worker.js +0 -44
- package/dist/cjs/eval-worker.js.map +0 -1
- package/dist/cjs/eval.js +0 -77
- package/dist/cjs/eval.js.map +0 -1
- package/dist/cjs/fs.js +0 -126
- package/dist/cjs/fs.js.map +0 -1
- package/dist/cjs/handler-types.js +0 -34
- package/dist/cjs/handler-types.js.map +0 -1
- package/dist/cjs/handlers.js +0 -173
- package/dist/cjs/handlers.js.map +0 -1
- package/dist/cjs/icon.js +0 -66
- package/dist/cjs/icon.js.map +0 -1
- package/dist/cjs/iframe.js +0 -59
- package/dist/cjs/iframe.js.map +0 -1
- package/dist/cjs/index.browser.js +0 -49
- package/dist/cjs/index.browser.js.map +0 -1
- package/dist/cjs/index.executionenv.js +0 -27
- package/dist/cjs/index.executionenv.js.map +0 -1
- package/dist/cjs/index.js +0 -54
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json-rpc.js +0 -81
- package/dist/cjs/json-rpc.js.map +0 -1
- package/dist/cjs/json.js +0 -16
- package/dist/cjs/json.js.map +0 -1
- package/dist/cjs/localization.js +0 -113
- package/dist/cjs/localization.js.map +0 -1
- package/dist/cjs/logging.js +0 -40
- package/dist/cjs/logging.js.map +0 -1
- package/dist/cjs/manifest/index.browser.js +0 -20
- package/dist/cjs/manifest/index.browser.js.map +0 -1
- package/dist/cjs/manifest/index.js +0 -21
- package/dist/cjs/manifest/index.js.map +0 -1
- package/dist/cjs/manifest/manifest.js +0 -283
- package/dist/cjs/manifest/manifest.js.map +0 -1
- package/dist/cjs/manifest/validation.js +0 -244
- package/dist/cjs/manifest/validation.js.map +0 -1
- package/dist/cjs/mock.js +0 -128
- package/dist/cjs/mock.js.map +0 -1
- package/dist/cjs/namespace.js +0 -136
- package/dist/cjs/namespace.js.map +0 -1
- package/dist/cjs/npm.js +0 -96
- package/dist/cjs/npm.js.map +0 -1
- package/dist/cjs/path.js +0 -21
- package/dist/cjs/path.js.map +0 -1
- package/dist/cjs/post-process.js +0 -328
- package/dist/cjs/post-process.js.map +0 -1
- package/dist/cjs/snaps.js +0 -232
- package/dist/cjs/snaps.js.map +0 -1
- package/dist/cjs/strings.js +0 -21
- package/dist/cjs/strings.js.map +0 -1
- package/dist/cjs/structs.js +0 -210
- package/dist/cjs/structs.js.map +0 -1
- package/dist/cjs/types.js +0 -104
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/ui.js +0 -53
- package/dist/cjs/ui.js.map +0 -1
- package/dist/cjs/validation.js +0 -24
- package/dist/cjs/validation.js.map +0 -1
- package/dist/cjs/versions.js +0 -47
- package/dist/cjs/versions.js.map +0 -1
- package/dist/cjs/virtual-file/VirtualFile.js +0 -92
- package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
- package/dist/cjs/virtual-file/index.browser.js +0 -20
- package/dist/cjs/virtual-file/index.browser.js.map +0 -1
- package/dist/cjs/virtual-file/index.js +0 -21
- package/dist/cjs/virtual-file/index.js.map +0 -1
- package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
- package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/esm/array.js +0 -13
- package/dist/esm/array.js.map +0 -1
- package/dist/esm/auxiliary-files.js +0 -23
- package/dist/esm/auxiliary-files.js.map +0 -1
- package/dist/esm/base64.js +0 -36
- package/dist/esm/base64.js.map +0 -1
- package/dist/esm/bytes.js +0 -18
- package/dist/esm/bytes.js.map +0 -1
- package/dist/esm/caveats.js +0 -38
- package/dist/esm/caveats.js.map +0 -1
- package/dist/esm/checksum.js +0 -41
- package/dist/esm/checksum.js.map +0 -1
- package/dist/esm/cronjob.js +0 -59
- package/dist/esm/cronjob.js.map +0 -1
- package/dist/esm/deep-clone.js +0 -7
- package/dist/esm/deep-clone.js.map +0 -1
- package/dist/esm/default-endowments.js +0 -39
- package/dist/esm/default-endowments.js.map +0 -1
- package/dist/esm/derivation-paths.js +0 -287
- package/dist/esm/derivation-paths.js.map +0 -1
- package/dist/esm/entropy.js +0 -6
- package/dist/esm/entropy.js.map +0 -1
- package/dist/esm/errors.js +0 -211
- package/dist/esm/errors.js.map +0 -1
- package/dist/esm/eval-worker.js +0 -40
- package/dist/esm/eval-worker.js.map +0 -1
- package/dist/esm/eval.js +0 -65
- package/dist/esm/eval.js.map +0 -1
- package/dist/esm/fs.js +0 -136
- package/dist/esm/fs.js.map +0 -1
- package/dist/esm/handler-types.js +0 -16
- package/dist/esm/handler-types.js.map +0 -1
- package/dist/esm/handlers.js +0 -119
- package/dist/esm/handlers.js.map +0 -1
- package/dist/esm/icon.js +0 -51
- package/dist/esm/icon.js.map +0 -1
- package/dist/esm/iframe.js +0 -49
- package/dist/esm/iframe.js.map +0 -1
- package/dist/esm/index.browser.js +0 -32
- package/dist/esm/index.browser.js.map +0 -1
- package/dist/esm/index.executionenv.js +0 -10
- package/dist/esm/index.executionenv.js.map +0 -1
- package/dist/esm/index.js +0 -37
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json-rpc.js +0 -79
- package/dist/esm/json-rpc.js.map +0 -1
- package/dist/esm/json.js +0 -17
- package/dist/esm/json.js.map +0 -1
- package/dist/esm/localization.js +0 -115
- package/dist/esm/localization.js.map +0 -1
- package/dist/esm/logging.js +0 -59
- package/dist/esm/logging.js.map +0 -1
- package/dist/esm/manifest/index.browser.js +0 -3
- package/dist/esm/manifest/index.browser.js.map +0 -1
- package/dist/esm/manifest/index.js +0 -4
- package/dist/esm/manifest/index.js.map +0 -1
- package/dist/esm/manifest/manifest.js +0 -307
- package/dist/esm/manifest/manifest.js.map +0 -1
- package/dist/esm/manifest/validation.js +0 -190
- package/dist/esm/manifest/validation.js.map +0 -1
- package/dist/esm/mock.js +0 -111
- package/dist/esm/mock.js.map +0 -1
- package/dist/esm/namespace.js +0 -113
- package/dist/esm/namespace.js.map +0 -1
- package/dist/esm/npm.js +0 -85
- package/dist/esm/npm.js.map +0 -1
- package/dist/esm/path.js +0 -17
- package/dist/esm/path.js.map +0 -1
- package/dist/esm/post-process.js +0 -333
- package/dist/esm/post-process.js.map +0 -1
- package/dist/esm/snaps.js +0 -217
- package/dist/esm/snaps.js.map +0 -1
- package/dist/esm/strings.js +0 -11
- package/dist/esm/strings.js.map +0 -1
- package/dist/esm/structs.js +0 -295
- package/dist/esm/structs.js.map +0 -1
- package/dist/esm/types.js +0 -78
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/ui.js +0 -50
- package/dist/esm/ui.js.map +0 -1
- package/dist/esm/validation.js +0 -19
- package/dist/esm/validation.js.map +0 -1
- package/dist/esm/versions.js +0 -41
- package/dist/esm/versions.js.map +0 -1
- package/dist/esm/virtual-file/VirtualFile.js +0 -82
- package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
- package/dist/esm/virtual-file/index.browser.js +0 -3
- package/dist/esm/virtual-file/index.browser.js.map +0 -1
- package/dist/esm/virtual-file/index.js +0 -4
- package/dist/esm/virtual-file/index.js.map +0 -1
- package/dist/esm/virtual-file/toVirtualFile.js +0 -26
- package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/types/index.browser.d.ts +0 -30
- package/dist/types/manifest/index.browser.d.ts +0 -1
- package/dist/types/virtual-file/index.browser.d.ts +0 -1
|
@@ -0,0 +1,409 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
var _chunkENKAY3PIjs = require('./chunk-ENKAY3PI.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkTG4BDSYJjs = require('./chunk-TG4BDSYJ.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunk4BDR6KRHjs = require('./chunk-4BDR6KRH.js');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _chunkCMOSYNZRjs = require('./chunk-CMOSYNZR.js');
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
var _chunkAFQY2CNYjs = require('./chunk-AFQY2CNY.js');
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
var _chunkX44Z53IGjs = require('./chunk-X44Z53IG.js');
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var _chunkQSCKTRRUjs = require('./chunk-QSCKTRRU.js');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
var _chunkHJYRGKCXjs = require('./chunk-HJYRGKCX.js');
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
var _chunkNUCLSR2Gjs = require('./chunk-NUCLSR2G.js');
|
|
33
|
+
|
|
34
|
+
// src/manifest/manifest.ts
|
|
35
|
+
var _snapssdk = require('@metamask/snaps-sdk');
|
|
36
|
+
var _utils = require('@metamask/utils');
|
|
37
|
+
var _fastdeepequal = require('fast-deep-equal'); var _fastdeepequal2 = _interopRequireDefault(_fastdeepequal);
|
|
38
|
+
var _fs = require('fs');
|
|
39
|
+
var _path = require('path'); var _path2 = _interopRequireDefault(_path);
|
|
40
|
+
var MANIFEST_SORT_ORDER = {
|
|
41
|
+
$schema: 1,
|
|
42
|
+
version: 2,
|
|
43
|
+
description: 3,
|
|
44
|
+
proposedName: 4,
|
|
45
|
+
repository: 5,
|
|
46
|
+
source: 6,
|
|
47
|
+
initialConnections: 7,
|
|
48
|
+
initialPermissions: 8,
|
|
49
|
+
manifestVersion: 9
|
|
50
|
+
};
|
|
51
|
+
async function checkManifest(basePath, writeManifest = true, sourceCode, writeFileFn = _fs.promises.writeFile) {
|
|
52
|
+
const warnings = [];
|
|
53
|
+
const errors = [];
|
|
54
|
+
let updated = false;
|
|
55
|
+
const manifestPath = _path2.default.join(basePath, "snap.manifest.json" /* Manifest */);
|
|
56
|
+
const manifestFile = await _chunkX44Z53IGjs.readJsonFile.call(void 0, manifestPath);
|
|
57
|
+
const unvalidatedManifest = manifestFile.result;
|
|
58
|
+
const packageFile = await _chunkX44Z53IGjs.readJsonFile.call(void 0,
|
|
59
|
+
_path2.default.join(basePath, "package.json" /* PackageJson */)
|
|
60
|
+
);
|
|
61
|
+
const auxiliaryFilePaths = getSnapFilePaths(
|
|
62
|
+
unvalidatedManifest,
|
|
63
|
+
(manifest2) => manifest2?.source?.files
|
|
64
|
+
);
|
|
65
|
+
const localizationFilePaths = getSnapFilePaths(
|
|
66
|
+
unvalidatedManifest,
|
|
67
|
+
(manifest2) => manifest2?.source?.locales
|
|
68
|
+
);
|
|
69
|
+
const snapFiles = {
|
|
70
|
+
manifest: manifestFile,
|
|
71
|
+
packageJson: packageFile,
|
|
72
|
+
sourceCode: await getSnapSourceCode(
|
|
73
|
+
basePath,
|
|
74
|
+
unvalidatedManifest,
|
|
75
|
+
sourceCode
|
|
76
|
+
),
|
|
77
|
+
svgIcon: await getSnapIcon(basePath, unvalidatedManifest),
|
|
78
|
+
// Intentionally pass null as the encoding here since the files may be binary
|
|
79
|
+
auxiliaryFiles: await getSnapFiles(basePath, auxiliaryFilePaths, null) ?? [],
|
|
80
|
+
localizationFiles: await getSnapFiles(basePath, localizationFilePaths) ?? []
|
|
81
|
+
};
|
|
82
|
+
let manifest;
|
|
83
|
+
try {
|
|
84
|
+
({ manifest } = await validateNpmSnap(snapFiles));
|
|
85
|
+
} catch (error) {
|
|
86
|
+
if (error instanceof _chunkTG4BDSYJjs.ProgrammaticallyFixableSnapError) {
|
|
87
|
+
errors.push(error.message);
|
|
88
|
+
const partiallyValidatedFiles = snapFiles;
|
|
89
|
+
let isInvalid = true;
|
|
90
|
+
let currentError = error;
|
|
91
|
+
const maxAttempts = Object.keys(_chunkCMOSYNZRjs.SnapValidationFailureReason).length;
|
|
92
|
+
for (let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++) {
|
|
93
|
+
manifest = await fixManifest(
|
|
94
|
+
manifest ? { ...partiallyValidatedFiles, manifest } : partiallyValidatedFiles,
|
|
95
|
+
currentError
|
|
96
|
+
);
|
|
97
|
+
try {
|
|
98
|
+
await validateNpmSnapManifest({
|
|
99
|
+
...partiallyValidatedFiles,
|
|
100
|
+
manifest
|
|
101
|
+
});
|
|
102
|
+
isInvalid = false;
|
|
103
|
+
} catch (nextValidationError) {
|
|
104
|
+
currentError = nextValidationError;
|
|
105
|
+
if (!(nextValidationError instanceof _chunkTG4BDSYJjs.ProgrammaticallyFixableSnapError) || attempts === maxAttempts && !isInvalid) {
|
|
106
|
+
throw new Error(
|
|
107
|
+
`Internal error: Failed to fix manifest. This is a bug, please report it. Reason:
|
|
108
|
+
${error.message}`
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
errors.push(currentError.message);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
updated = true;
|
|
115
|
+
} else {
|
|
116
|
+
throw error;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
_utils.assert.call(void 0, manifest);
|
|
120
|
+
const validatedManifest = manifest.result;
|
|
121
|
+
const recommendedFields = ["repository"];
|
|
122
|
+
const missingRecommendedFields = recommendedFields.filter(
|
|
123
|
+
(key) => !validatedManifest[key]
|
|
124
|
+
);
|
|
125
|
+
if (missingRecommendedFields.length > 0) {
|
|
126
|
+
warnings.push(
|
|
127
|
+
`Missing recommended package.json properties:
|
|
128
|
+
${missingRecommendedFields.reduce(
|
|
129
|
+
(allMissing, currentField) => {
|
|
130
|
+
return `${allMissing} ${currentField}
|
|
131
|
+
`;
|
|
132
|
+
},
|
|
133
|
+
""
|
|
134
|
+
)}`
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (!snapFiles.svgIcon) {
|
|
138
|
+
warnings.push(
|
|
139
|
+
"No icon found in the Snap manifest. It is recommended to include an icon for the Snap. See https://docs.metamask.io/snaps/how-to/design-a-snap/#guidelines-at-a-glance for more information."
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
const iconDimensions = snapFiles.svgIcon && _chunk4BDR6KRHjs.getSvgDimensions.call(void 0, snapFiles.svgIcon.toString());
|
|
143
|
+
if (iconDimensions && iconDimensions.height !== iconDimensions.width) {
|
|
144
|
+
warnings.push(
|
|
145
|
+
"The icon in the Snap manifest is not square. It is recommended to use a square icon for the Snap."
|
|
146
|
+
);
|
|
147
|
+
}
|
|
148
|
+
if (writeManifest) {
|
|
149
|
+
try {
|
|
150
|
+
const newManifest = `${JSON.stringify(
|
|
151
|
+
getWritableManifest(validatedManifest),
|
|
152
|
+
null,
|
|
153
|
+
2
|
|
154
|
+
)}
|
|
155
|
+
`;
|
|
156
|
+
if (updated || newManifest !== manifestFile.value) {
|
|
157
|
+
await writeFileFn(
|
|
158
|
+
_path2.default.join(basePath, "snap.manifest.json" /* Manifest */),
|
|
159
|
+
newManifest
|
|
160
|
+
);
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
throw new Error(`Failed to update snap.manifest.json: ${error.message}`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return { manifest: validatedManifest, updated, warnings, errors };
|
|
167
|
+
}
|
|
168
|
+
async function fixManifest(snapFiles, error) {
|
|
169
|
+
const { manifest, packageJson } = snapFiles;
|
|
170
|
+
const clonedFile = manifest.clone();
|
|
171
|
+
const manifestCopy = clonedFile.result;
|
|
172
|
+
switch (error.reason) {
|
|
173
|
+
case '"name" field mismatch' /* NameMismatch */:
|
|
174
|
+
manifestCopy.source.location.npm.packageName = packageJson.result.name;
|
|
175
|
+
break;
|
|
176
|
+
case '"version" field mismatch' /* VersionMismatch */:
|
|
177
|
+
manifestCopy.version = packageJson.result.version;
|
|
178
|
+
break;
|
|
179
|
+
case '"repository" field mismatch' /* RepositoryMismatch */:
|
|
180
|
+
manifestCopy.repository = packageJson.result.repository ? _chunkNUCLSR2Gjs.deepClone.call(void 0, packageJson.result.repository) : void 0;
|
|
181
|
+
break;
|
|
182
|
+
case '"shasum" field mismatch' /* ShasumMismatch */:
|
|
183
|
+
manifestCopy.source.shasum = await _chunkTG4BDSYJjs.getSnapChecksum.call(void 0, snapFiles);
|
|
184
|
+
break;
|
|
185
|
+
default:
|
|
186
|
+
_utils.assertExhaustive.call(void 0, error.reason);
|
|
187
|
+
}
|
|
188
|
+
clonedFile.result = manifestCopy;
|
|
189
|
+
clonedFile.value = JSON.stringify(manifestCopy);
|
|
190
|
+
return clonedFile;
|
|
191
|
+
}
|
|
192
|
+
async function getSnapSourceCode(basePath, manifest, sourceCode) {
|
|
193
|
+
if (!_utils.isPlainObject.call(void 0, manifest)) {
|
|
194
|
+
return void 0;
|
|
195
|
+
}
|
|
196
|
+
const sourceFilePath = manifest.source?.location?.npm?.filePath;
|
|
197
|
+
if (!sourceFilePath) {
|
|
198
|
+
return void 0;
|
|
199
|
+
}
|
|
200
|
+
if (sourceCode) {
|
|
201
|
+
return new (0, _chunkHJYRGKCXjs.VirtualFile)({
|
|
202
|
+
path: _path2.default.join(basePath, sourceFilePath),
|
|
203
|
+
value: sourceCode
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
try {
|
|
207
|
+
const virtualFile = await _chunkQSCKTRRUjs.readVirtualFile.call(void 0,
|
|
208
|
+
_path2.default.join(basePath, sourceFilePath),
|
|
209
|
+
"utf8"
|
|
210
|
+
);
|
|
211
|
+
return virtualFile;
|
|
212
|
+
} catch (error) {
|
|
213
|
+
throw new Error(
|
|
214
|
+
`Failed to read snap bundle file: ${_snapssdk.getErrorMessage.call(void 0, error)}`
|
|
215
|
+
);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
async function getSnapIcon(basePath, manifest) {
|
|
219
|
+
if (!_utils.isPlainObject.call(void 0, manifest)) {
|
|
220
|
+
return void 0;
|
|
221
|
+
}
|
|
222
|
+
const iconPath = manifest.source?.location?.npm?.iconPath;
|
|
223
|
+
if (!iconPath) {
|
|
224
|
+
return void 0;
|
|
225
|
+
}
|
|
226
|
+
try {
|
|
227
|
+
const virtualFile = await _chunkQSCKTRRUjs.readVirtualFile.call(void 0,
|
|
228
|
+
_path2.default.join(basePath, iconPath),
|
|
229
|
+
"utf8"
|
|
230
|
+
);
|
|
231
|
+
return virtualFile;
|
|
232
|
+
} catch (error) {
|
|
233
|
+
throw new Error(`Failed to read snap icon file: ${_snapssdk.getErrorMessage.call(void 0, error)}`);
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
function getSnapFilePaths(manifest, selector) {
|
|
237
|
+
if (!_utils.isPlainObject.call(void 0, manifest)) {
|
|
238
|
+
return void 0;
|
|
239
|
+
}
|
|
240
|
+
const snapManifest = manifest;
|
|
241
|
+
const paths = selector(snapManifest);
|
|
242
|
+
if (!Array.isArray(paths)) {
|
|
243
|
+
return void 0;
|
|
244
|
+
}
|
|
245
|
+
return paths;
|
|
246
|
+
}
|
|
247
|
+
async function getSnapFiles(basePath, paths, encoding = "utf8") {
|
|
248
|
+
if (!paths) {
|
|
249
|
+
return void 0;
|
|
250
|
+
}
|
|
251
|
+
try {
|
|
252
|
+
return await Promise.all(
|
|
253
|
+
paths.map(
|
|
254
|
+
async (filePath) => _chunkQSCKTRRUjs.readVirtualFile.call(void 0, _path2.default.join(basePath, filePath), encoding)
|
|
255
|
+
)
|
|
256
|
+
);
|
|
257
|
+
} catch (error) {
|
|
258
|
+
throw new Error(`Failed to read snap files: ${_snapssdk.getErrorMessage.call(void 0, error)}`);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
function getWritableManifest(manifest) {
|
|
262
|
+
const { repository, ...remaining } = manifest;
|
|
263
|
+
const keys = Object.keys(
|
|
264
|
+
repository ? { ...remaining, repository } : remaining
|
|
265
|
+
);
|
|
266
|
+
const writableManifest = keys.sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b]).reduce(
|
|
267
|
+
(result, key) => ({
|
|
268
|
+
...result,
|
|
269
|
+
[key]: manifest[key]
|
|
270
|
+
}),
|
|
271
|
+
{}
|
|
272
|
+
);
|
|
273
|
+
return writableManifest;
|
|
274
|
+
}
|
|
275
|
+
async function validateNpmSnapManifest({
|
|
276
|
+
manifest,
|
|
277
|
+
packageJson,
|
|
278
|
+
sourceCode,
|
|
279
|
+
svgIcon,
|
|
280
|
+
auxiliaryFiles,
|
|
281
|
+
localizationFiles
|
|
282
|
+
}) {
|
|
283
|
+
const packageJsonName = packageJson.result.name;
|
|
284
|
+
const packageJsonVersion = packageJson.result.version;
|
|
285
|
+
const packageJsonRepository = packageJson.result.repository;
|
|
286
|
+
const manifestPackageName = manifest.result.source.location.npm.packageName;
|
|
287
|
+
const manifestPackageVersion = manifest.result.version;
|
|
288
|
+
const manifestRepository = manifest.result.repository;
|
|
289
|
+
if (packageJsonName !== manifestPackageName) {
|
|
290
|
+
throw new (0, _chunkTG4BDSYJjs.ProgrammaticallyFixableSnapError)(
|
|
291
|
+
`"${"snap.manifest.json" /* Manifest */}" npm package name ("${manifestPackageName}") does not match the "${"package.json" /* PackageJson */}" "name" field ("${packageJsonName}").`,
|
|
292
|
+
'"name" field mismatch' /* NameMismatch */
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
if (packageJsonVersion !== manifestPackageVersion) {
|
|
296
|
+
throw new (0, _chunkTG4BDSYJjs.ProgrammaticallyFixableSnapError)(
|
|
297
|
+
`"${"snap.manifest.json" /* Manifest */}" npm package version ("${manifestPackageVersion}") does not match the "${"package.json" /* PackageJson */}" "version" field ("${packageJsonVersion}").`,
|
|
298
|
+
'"version" field mismatch' /* VersionMismatch */
|
|
299
|
+
);
|
|
300
|
+
}
|
|
301
|
+
if (
|
|
302
|
+
// The repository may be `undefined` in package.json but can only be defined
|
|
303
|
+
// or `null` in the Snap manifest due to TS@<4.4 issues.
|
|
304
|
+
(packageJsonRepository || manifestRepository) && !_fastdeepequal2.default.call(void 0, packageJsonRepository, manifestRepository)
|
|
305
|
+
) {
|
|
306
|
+
throw new (0, _chunkTG4BDSYJjs.ProgrammaticallyFixableSnapError)(
|
|
307
|
+
`"${"snap.manifest.json" /* Manifest */}" "repository" field does not match the "${"package.json" /* PackageJson */}" "repository" field.`,
|
|
308
|
+
'"repository" field mismatch' /* RepositoryMismatch */
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
await _chunkTG4BDSYJjs.validateSnapShasum.call(void 0,
|
|
312
|
+
{ manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles },
|
|
313
|
+
`"${"snap.manifest.json" /* Manifest */}" "shasum" field does not match computed shasum.`
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/npm.ts
|
|
318
|
+
var EXPECTED_SNAP_FILES = [
|
|
319
|
+
"manifest",
|
|
320
|
+
"packageJson",
|
|
321
|
+
"sourceCode"
|
|
322
|
+
];
|
|
323
|
+
var SnapFileNameFromKey = {
|
|
324
|
+
manifest: "snap.manifest.json" /* Manifest */,
|
|
325
|
+
packageJson: "package.json" /* PackageJson */,
|
|
326
|
+
sourceCode: "source code bundle"
|
|
327
|
+
};
|
|
328
|
+
async function validateNpmSnap(snapFiles, errorPrefix) {
|
|
329
|
+
EXPECTED_SNAP_FILES.forEach((key) => {
|
|
330
|
+
if (!snapFiles[key]) {
|
|
331
|
+
throw new Error(
|
|
332
|
+
`${errorPrefix ?? ""}Missing file "${SnapFileNameFromKey[key]}".`
|
|
333
|
+
);
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
const {
|
|
337
|
+
manifest,
|
|
338
|
+
packageJson,
|
|
339
|
+
sourceCode,
|
|
340
|
+
svgIcon,
|
|
341
|
+
auxiliaryFiles,
|
|
342
|
+
localizationFiles
|
|
343
|
+
} = snapFiles;
|
|
344
|
+
try {
|
|
345
|
+
_chunkENKAY3PIjs.assertIsSnapManifest.call(void 0, manifest.result);
|
|
346
|
+
} catch (error) {
|
|
347
|
+
throw new Error(`${errorPrefix ?? ""}${error.message}`);
|
|
348
|
+
}
|
|
349
|
+
const validatedManifest = manifest;
|
|
350
|
+
const { iconPath } = validatedManifest.result.source.location.npm;
|
|
351
|
+
if (iconPath && !svgIcon) {
|
|
352
|
+
throw new Error(`Missing file "${iconPath}".`);
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
_chunkCMOSYNZRjs.assertIsNpmSnapPackageJson.call(void 0, packageJson.result);
|
|
356
|
+
} catch (error) {
|
|
357
|
+
throw new Error(`${errorPrefix ?? ""}${error.message}`);
|
|
358
|
+
}
|
|
359
|
+
const validatedPackageJson = packageJson;
|
|
360
|
+
await validateNpmSnapManifest({
|
|
361
|
+
manifest: validatedManifest,
|
|
362
|
+
packageJson: validatedPackageJson,
|
|
363
|
+
sourceCode,
|
|
364
|
+
svgIcon,
|
|
365
|
+
auxiliaryFiles,
|
|
366
|
+
localizationFiles
|
|
367
|
+
});
|
|
368
|
+
if (svgIcon) {
|
|
369
|
+
try {
|
|
370
|
+
_chunk4BDR6KRHjs.assertIsSnapIcon.call(void 0, svgIcon);
|
|
371
|
+
} catch (error) {
|
|
372
|
+
throw new Error(`${errorPrefix ?? ""}${error.message}`);
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (localizationFiles) {
|
|
376
|
+
try {
|
|
377
|
+
_chunkAFQY2CNYjs.getValidatedLocalizationFiles.call(void 0, localizationFiles);
|
|
378
|
+
_chunkAFQY2CNYjs.validateSnapManifestLocalizations.call(void 0,
|
|
379
|
+
manifest.result,
|
|
380
|
+
localizationFiles.map((file) => file.result)
|
|
381
|
+
);
|
|
382
|
+
} catch (error) {
|
|
383
|
+
throw new Error(`${errorPrefix ?? ""}${error.message}`);
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
manifest: validatedManifest,
|
|
388
|
+
packageJson: validatedPackageJson,
|
|
389
|
+
sourceCode,
|
|
390
|
+
svgIcon,
|
|
391
|
+
auxiliaryFiles,
|
|
392
|
+
localizationFiles
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
|
|
407
|
+
|
|
408
|
+
exports.EXPECTED_SNAP_FILES = EXPECTED_SNAP_FILES; exports.SnapFileNameFromKey = SnapFileNameFromKey; exports.validateNpmSnap = validateNpmSnap; exports.checkManifest = checkManifest; exports.fixManifest = fixManifest; exports.getSnapSourceCode = getSnapSourceCode; exports.getSnapIcon = getSnapIcon; exports.getSnapFilePaths = getSnapFilePaths; exports.getSnapFiles = getSnapFiles; exports.getWritableManifest = getWritableManifest; exports.validateNpmSnapManifest = validateNpmSnapManifest;
|
|
409
|
+
//# sourceMappingURL=chunk-CNNMLOQ6.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/manifest.ts","../src/npm.ts"],"names":["manifest"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,uBAAuB;AAEhC,SAAS,kBAAkB,QAAQ,qBAAqB;AACxD,OAAO,eAAe;AACtB,SAAS,YAAY,UAAU;AAC/B,OAAO,eAAe;AAgBtB,IAAM,sBAA0D;AAAA,EAC9D,SAAS;AAAA,EACT,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,QAAQ;AAAA,EACR,oBAAoB;AAAA,EACpB,oBAAoB;AAAA,EACpB,iBAAiB;AACnB;AAqCA,eAAsB,cACpB,UACA,gBAAgB,MAChB,YACA,cAAiC,GAAG,WACN;AAC9B,QAAM,WAAqB,CAAC;AAC5B,QAAM,SAAmB,CAAC;AAE1B,MAAI,UAAU;AAEd,QAAM,eAAe,UAAU,KAAK,6CAAmC;AACvE,QAAM,eAAe,MAAM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AI,MAAM,GAAG,eAAe,EAAE,GAAG,MAAM,OAAO,EAAE;AAAA,EACxD;AACA,QAAM,oBAAoB;AAE1B,QAAM,EAAE,SAAS,IAAI,kBAAkB,OAAO,OAAO,SAAS;AAC9D,MAAI,YAAY,CAAC,SAAS;AACxB,UAAM,IAAI,MAAM,iBAAiB,QAAQ,IAAI;AAAA,EAC/C;AAEA,MAAI;AACF,+BAA2B,YAAY,MAAM;AAAA,EAC/C,SAAS,OAAO;AACd,UAAM,IAAI,MAAM,GAAG,eAAe,EAAE,GAAG,MAAM,OAAO,EAAE;AAAA,EACxD;AAEA,QAAM,uBAAuB;AAC7B,QAAM,wBAAwB;AAAA,IAC5B,UAAU;AAAA,IACV,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,CAAC;AAED,MAAI,SAAS;AACX,QAAI;AACF,uBAAiB,OAAO;AAAA,IAC1B,SAAS,OAAO;AACd,YAAM,IAAI,MAAM,GAAG,eAAe,EAAE,GAAG,MAAM,OAAO,EAAE;AAAA,IACxD;AAAA,EACF;AAEA,MAAI,mBAAmB;AACrB,QAAI;AAGF,oCAA8B,iBAAiB;AAE/C;AAAA,QACE,SAAS;AAAA,QACT,kBAAkB,IAAI,CAAC,SAAS,KAAK,MAAM;AAAA,MAC7C;AAAA,IACF,SAAS,OAAO;AACd,YAAM,IAAI,MAAM,GAAG,eAAe,EAAE,GAAG,MAAM,OAAO,EAAE;AAAA,IACxD;AAAA,EACF;AAEA,SAAO;AAAA,IACL,UAAU;AAAA,IACV,aAAa;AAAA,IACb;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assertExhaustive, assert, isPlainObject } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { getSvgDimensions } from '../icon';\nimport { validateNpmSnap } from '../npm';\nimport {\n getSnapChecksum,\n ProgrammaticallyFixableSnapError,\n validateSnapShasum,\n} from '../snaps';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames, SnapValidationFailureReason } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file/node';\nimport type { SnapManifest } from './validation';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialConnections: 7,\n initialPermissions: 8,\n manifestVersion: 9,\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was updated.\n * @property warnings - An array of warnings that were encountered during\n * processing of the manifest files. These warnings are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n * @property errors - An array of errors that were encountered during\n * processing of the manifest files. These errors are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n */\nexport type CheckManifestResult = {\n manifest: SnapManifest;\n updated?: boolean;\n warnings: string[];\n errors: string[];\n};\n\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param writeManifest - Whether to write the fixed manifest to disk.\n * @param sourceCode - The source code of the Snap.\n * @param writeFileFn - The function to use to write the manifest to disk.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n writeManifest = true,\n sourceCode?: string,\n writeFileFn: WriteFileFunction = fs.writeFile,\n): Promise<CheckManifestResult> {\n const warnings: string[] = [];\n const errors: string[] = [];\n\n let updated = false;\n\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const auxiliaryFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.files,\n );\n\n const localizationFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.locales,\n );\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n // Intentionally pass null as the encoding here since the files may be binary\n auxiliaryFiles:\n (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],\n localizationFiles:\n (await getSnapFiles(basePath, localizationFilePaths)) ?? [],\n };\n\n let manifest: VirtualFile<SnapManifest> | undefined;\n try {\n ({ manifest } = await validateNpmSnap(snapFiles));\n } catch (error) {\n if (error instanceof ProgrammaticallyFixableSnapError) {\n errors.push(error.message);\n\n // If we get here, the files at least have the correct shape.\n const partiallyValidatedFiles = snapFiles as SnapFiles;\n\n let isInvalid = true;\n let currentError = error;\n const maxAttempts = Object.keys(SnapValidationFailureReason).length;\n\n // Attempt to fix all fixable validation failure reasons. All such reasons\n // are enumerated by the `SnapValidationFailureReason` enum, so we only\n // attempt to fix the manifest the same amount of times as there are\n // reasons in the enum.\n for (let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++) {\n manifest = await fixManifest(\n manifest\n ? { ...partiallyValidatedFiles, manifest }\n : partiallyValidatedFiles,\n currentError,\n );\n\n try {\n await validateNpmSnapManifest({\n ...partiallyValidatedFiles,\n manifest,\n });\n\n isInvalid = false;\n } catch (nextValidationError) {\n currentError = nextValidationError;\n /* istanbul ignore next: this should be impossible */\n if (\n !(\n nextValidationError instanceof ProgrammaticallyFixableSnapError\n ) ||\n (attempts === maxAttempts && !isInvalid)\n ) {\n throw new Error(\n `Internal error: Failed to fix manifest. This is a bug, please report it. Reason:\\n${error.message}`,\n );\n }\n\n errors.push(currentError.message);\n }\n }\n\n updated = true;\n } else {\n throw error;\n }\n }\n\n // TypeScript assumes `manifest` can still be undefined, that is not the case.\n // But we assert to keep TypeScript happy.\n assert(manifest);\n\n const validatedManifest = manifest.result;\n\n // Check presence of recommended keys\n const recommendedFields = ['repository'] as const;\n\n const missingRecommendedFields = recommendedFields.filter(\n (key) => !validatedManifest[key],\n );\n\n if (missingRecommendedFields.length > 0) {\n warnings.push(\n `Missing recommended package.json properties:\\n${missingRecommendedFields.reduce(\n (allMissing, currentField) => {\n return `${allMissing}\\t${currentField}\\n`;\n },\n '',\n )}`,\n );\n }\n\n if (!snapFiles.svgIcon) {\n warnings.push(\n 'No icon found in the Snap manifest. It is recommended to include an icon for the Snap. See https://docs.metamask.io/snaps/how-to/design-a-snap/#guidelines-at-a-glance for more information.',\n );\n }\n\n const iconDimensions =\n snapFiles.svgIcon && getSvgDimensions(snapFiles.svgIcon.toString());\n if (iconDimensions && iconDimensions.height !== iconDimensions.width) {\n warnings.push(\n 'The icon in the Snap manifest is not square. It is recommended to use a square icon for the Snap.',\n );\n }\n\n if (writeManifest) {\n try {\n const newManifest = `${JSON.stringify(\n getWritableManifest(validatedManifest),\n null,\n 2,\n )}\\n`;\n\n if (updated || newManifest !== manifestFile.value) {\n await writeFileFn(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n newManifest,\n );\n }\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(`Failed to update snap.manifest.json: ${error.message}`);\n }\n }\n\n return { manifest: validatedManifest, updated, warnings, errors };\n}\n\n/**\n * Given the relevant Snap files (manifest, `package.json`, and bundle) and a\n * Snap manifest validation error, fixes the fault in the manifest that caused\n * the error.\n *\n * @param snapFiles - The contents of all Snap files.\n * @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.\n * @returns A copy of the manifest file where the cause of the error is fixed.\n */\nexport async function fixManifest(\n snapFiles: SnapFiles,\n error: ProgrammaticallyFixableSnapError,\n): Promise<VirtualFile<SnapManifest>> {\n const { manifest, packageJson } = snapFiles;\n const clonedFile = manifest.clone();\n const manifestCopy = clonedFile.result;\n\n switch (error.reason) {\n case SnapValidationFailureReason.NameMismatch:\n manifestCopy.source.location.npm.packageName = packageJson.result.name;\n break;\n\n case SnapValidationFailureReason.VersionMismatch:\n manifestCopy.version = packageJson.result.version;\n break;\n\n case SnapValidationFailureReason.RepositoryMismatch:\n manifestCopy.repository = packageJson.result.repository\n ? deepClone(packageJson.result.repository)\n : undefined;\n break;\n\n case SnapValidationFailureReason.ShasumMismatch:\n manifestCopy.source.shasum = await getSnapChecksum(snapFiles);\n break;\n\n /* istanbul ignore next */\n default:\n assertExhaustive(error.reason);\n }\n\n clonedFile.result = manifestCopy;\n clonedFile.value = JSON.stringify(manifestCopy);\n return clonedFile;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(\n `Failed to read snap bundle file: ${getErrorMessage(error)}`,\n );\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap icon file: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Get an array of paths from an unvalidated Snap manifest.\n *\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param selector - A function that returns the paths to the files.\n * @returns The paths to the files, if any.\n */\nexport function getSnapFilePaths(\n manifest: Json,\n selector: (manifest: Partial<SnapManifest>) => string[] | undefined,\n) {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const snapManifest = manifest as Partial<SnapManifest>;\n const paths = selector(snapManifest);\n\n if (!Array.isArray(paths)) {\n return undefined;\n }\n\n return paths;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the files with the\n * given paths and read them.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param paths - The paths to the files.\n * @param encoding - An optional encoding to pass down to readVirtualFile.\n * @returns A list of auxiliary files and their contents, if any.\n */\nexport async function getSnapFiles(\n basePath: string,\n paths: string[] | undefined,\n encoding: BufferEncoding | null = 'utf8',\n): Promise<VirtualFile[] | undefined> {\n if (!paths) {\n return undefined;\n }\n\n try {\n return await Promise.all(\n paths.map(async (filePath) =>\n readVirtualFile(pathUtils.join(basePath, filePath), encoding),\n ),\n );\n } catch (error) {\n throw new Error(`Failed to read snap files: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n\n/**\n * Validates the fields of an NPM Snap manifest that has already passed JSON\n * Schema validation.\n *\n * @param snapFiles - The relevant snap files to validate.\n * @param snapFiles.manifest - The npm Snap manifest to validate.\n * @param snapFiles.packageJson - The npm Snap's `package.json`.\n * @param snapFiles.sourceCode - The Snap's source code.\n * @param snapFiles.svgIcon - The Snap's optional icon.\n * @param snapFiles.auxiliaryFiles - Any auxiliary files required by the snap at runtime.\n * @param snapFiles.localizationFiles - The Snap's localization files.\n */\nexport async function validateNpmSnapManifest({\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n}: SnapFiles) {\n const packageJsonName = packageJson.result.name;\n const packageJsonVersion = packageJson.result.version;\n const packageJsonRepository = packageJson.result.repository;\n\n const manifestPackageName = manifest.result.source.location.npm.packageName;\n const manifestPackageVersion = manifest.result.version;\n const manifestRepository = manifest.result.repository;\n\n if (packageJsonName !== manifestPackageName) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package name (\"${manifestPackageName}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"name\" field (\"${packageJsonName}\").`,\n SnapValidationFailureReason.NameMismatch,\n );\n }\n\n if (packageJsonVersion !== manifestPackageVersion) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package version (\"${manifestPackageVersion}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"version\" field (\"${packageJsonVersion}\").`,\n SnapValidationFailureReason.VersionMismatch,\n );\n }\n\n if (\n // The repository may be `undefined` in package.json but can only be defined\n // or `null` in the Snap manifest due to TS@<4.4 issues.\n (packageJsonRepository || manifestRepository) &&\n !deepEqual(packageJsonRepository, manifestRepository)\n ) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" \"repository\" field does not match the \"${NpmSnapFileNames.PackageJson}\" \"repository\" field.`,\n SnapValidationFailureReason.RepositoryMismatch,\n );\n }\n\n await validateSnapShasum(\n { manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles },\n `\"${NpmSnapFileNames.Manifest}\" \"shasum\" field does not match computed shasum.`,\n );\n}\n","import { assertIsSnapIcon } from './icon';\nimport {\n getValidatedLocalizationFiles,\n validateSnapManifestLocalizations,\n} from './localization';\nimport { validateNpmSnapManifest } from './manifest/manifest';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport type { SnapFiles, UnvalidatedSnapFiles } from './types';\nimport { assertIsNpmSnapPackageJson, NpmSnapFileNames } from './types';\n\nexport const EXPECTED_SNAP_FILES = [\n 'manifest',\n 'packageJson',\n 'sourceCode',\n] as const;\n\nexport const SnapFileNameFromKey = {\n manifest: NpmSnapFileNames.Manifest,\n packageJson: NpmSnapFileNames.PackageJson,\n sourceCode: 'source code bundle',\n} as const;\n\n// TODO: Refactor this to be more shared with other validation.\n\n/**\n * Validates the files extracted from an npm Snap package tarball by ensuring\n * that they're non-empty and that the Json files match their respective schemas\n * and the Snaps publishing specification.\n *\n * @param snapFiles - The object containing the expected Snap file contents,\n * if any.\n * @param errorPrefix - The prefix of the error message.\n * @returns A tuple of the Snap manifest object and the Snap source code.\n */\nexport async function validateNpmSnap(\n snapFiles: UnvalidatedSnapFiles,\n errorPrefix?: `${string}: `,\n): Promise<SnapFiles> {\n EXPECTED_SNAP_FILES.forEach((key) => {\n if (!snapFiles[key]) {\n throw new Error(\n `${errorPrefix ?? ''}Missing file \"${SnapFileNameFromKey[key]}\".`,\n );\n }\n });\n\n // Typecast: We are assured that the required files exist if we get here.\n const {\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n } = snapFiles as SnapFiles;\n\n try {\n assertIsSnapManifest(manifest.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n const validatedManifest = manifest;\n\n const { iconPath } = validatedManifest.result.source.location.npm;\n if (iconPath && !svgIcon) {\n throw new Error(`Missing file \"${iconPath}\".`);\n }\n\n try {\n assertIsNpmSnapPackageJson(packageJson.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n\n const validatedPackageJson = packageJson;\n await validateNpmSnapManifest({\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n });\n\n if (svgIcon) {\n try {\n assertIsSnapIcon(svgIcon);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n }\n\n if (localizationFiles) {\n try {\n // This function validates and returns the localization files. We don't\n // use the return value here, but we do want to validate the files.\n getValidatedLocalizationFiles(localizationFiles);\n\n validateSnapManifestLocalizations(\n manifest.result,\n localizationFiles.map((file) => file.result),\n );\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n }\n\n return {\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n };\n}\n"]}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/json-rpc.ts
|
|
2
|
+
var _permissioncontroller = require('@metamask/permission-controller');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
var _utils = require('@metamask/utils');
|
|
8
|
+
var _superstruct = require('superstruct');
|
|
9
|
+
var RpcOriginsStruct = _superstruct.refine.call(void 0,
|
|
10
|
+
_superstruct.object.call(void 0, {
|
|
11
|
+
dapps: _superstruct.optional.call(void 0, _superstruct.boolean.call(void 0, )),
|
|
12
|
+
snaps: _superstruct.optional.call(void 0, _superstruct.boolean.call(void 0, )),
|
|
13
|
+
allowedOrigins: _superstruct.optional.call(void 0, _superstruct.array.call(void 0, _superstruct.string.call(void 0, )))
|
|
14
|
+
}),
|
|
15
|
+
"RPC origins",
|
|
16
|
+
(value) => {
|
|
17
|
+
const hasOrigins = Boolean(
|
|
18
|
+
value.snaps === true || value.dapps === true || value.allowedOrigins && value.allowedOrigins.length > 0
|
|
19
|
+
);
|
|
20
|
+
if (hasOrigins) {
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
return "Must specify at least one JSON-RPC origin.";
|
|
24
|
+
}
|
|
25
|
+
);
|
|
26
|
+
function assertIsRpcOrigins(value, ErrorWrapper) {
|
|
27
|
+
_utils.assertStruct.call(void 0,
|
|
28
|
+
value,
|
|
29
|
+
RpcOriginsStruct,
|
|
30
|
+
"Invalid JSON-RPC origins",
|
|
31
|
+
ErrorWrapper
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
var KeyringOriginsStruct = _superstruct.object.call(void 0, {
|
|
35
|
+
allowedOrigins: _superstruct.optional.call(void 0, _superstruct.array.call(void 0, _superstruct.string.call(void 0, )))
|
|
36
|
+
});
|
|
37
|
+
function assertIsKeyringOrigins(value, ErrorWrapper) {
|
|
38
|
+
_utils.assertStruct.call(void 0,
|
|
39
|
+
value,
|
|
40
|
+
KeyringOriginsStruct,
|
|
41
|
+
"Invalid keyring origins",
|
|
42
|
+
ErrorWrapper
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
function isOriginAllowed(origins, subjectType, origin) {
|
|
46
|
+
if (origin === "metamask") {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (origins.allowedOrigins?.includes(origin)) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (subjectType === _permissioncontroller.SubjectType.Website && origins.dapps) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
return Boolean(subjectType === _permissioncontroller.SubjectType.Snap && origins.snaps);
|
|
56
|
+
}
|
|
57
|
+
function assertIsJsonRpcSuccess(value) {
|
|
58
|
+
if (!_utils.isJsonRpcSuccess.call(void 0, value)) {
|
|
59
|
+
if (_utils.isJsonRpcFailure.call(void 0, value)) {
|
|
60
|
+
throw new Error(`JSON-RPC request failed: ${value.error.message}`);
|
|
61
|
+
}
|
|
62
|
+
throw new Error("Invalid JSON-RPC response.");
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
exports.RpcOriginsStruct = RpcOriginsStruct; exports.assertIsRpcOrigins = assertIsRpcOrigins; exports.KeyringOriginsStruct = KeyringOriginsStruct; exports.assertIsKeyringOrigins = assertIsKeyringOrigins; exports.isOriginAllowed = isOriginAllowed; exports.assertIsJsonRpcSuccess = assertIsJsonRpcSuccess;
|
|
74
|
+
//# sourceMappingURL=chunk-CQRPSEH3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/json-rpc.ts"],"names":[],"mappings":";AAAA,SAAS,mBAAmB;AAM5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,OAAO,SAAS,QAAQ,UAAU,QAAQ,cAAc;AAE1D,IAAM,mBAAmB;AAAA,EAC9B,OAAO;AAAA,IACL,OAAO,SAAS,QAAQ,CAAC;AAAA,IACzB,OAAO,SAAS,QAAQ,CAAC;AAAA,IACzB,gBAAgB,SAAS,MAAM,OAAO,CAAC,CAAC;AAAA,EAC1C,CAAC;AAAA,EACD;AAAA,EACA,CAAC,UAAU;AACT,UAAM,aAAa;AAAA,MACjB,MAAM,UAAU,QACd,MAAM,UAAU,QACf,MAAM,kBAAkB,MAAM,eAAe,SAAS;AAAA,IAC3D;AAEA,QAAI,YAAY;AACd,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT;AACF;AAYO,SAAS,mBACd,OAEA,cAC6B;AAC7B;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAEO,IAAM,uBAAuB,OAAO;AAAA,EACzC,gBAAgB,SAAS,MAAM,OAAO,CAAC,CAAC;AAC1C,CAAC;AAYM,SAAS,uBACd,OAEA,cACiC;AACjC;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;AAUO,SAAS,gBACd,SACA,aACA,QACA;AAEA,MAAI,WAAW,YAAY;AACzB,WAAO;AAAA,EACT;AAGA,MAAI,QAAQ,gBAAgB,SAAS,MAAM,GAAG;AAC5C,WAAO;AAAA,EACT;AAGA,MAAI,gBAAgB,YAAY,WAAW,QAAQ,OAAO;AACxD,WAAO;AAAA,EACT;AAGA,SAAO,QAAQ,gBAAgB,YAAY,QAAQ,QAAQ,KAAK;AAClE;AAUO,SAAS,uBACd,OACuC;AACvC,MAAI,CAAC,iBAAiB,KAAK,GAAG;AAC5B,QAAI,iBAAiB,KAAK,GAAG;AAC3B,YAAM,IAAI,MAAM,4BAA4B,MAAM,MAAM,OAAO,EAAE;AAAA,IACnE;AAEA,UAAM,IAAI,MAAM,4BAA4B;AAAA,EAC9C;AACF","sourcesContent":["import { SubjectType } from '@metamask/permission-controller';\nimport type {\n AssertionErrorConstructor,\n Json,\n JsonRpcSuccess,\n} from '@metamask/utils';\nimport {\n assertStruct,\n isJsonRpcFailure,\n isJsonRpcSuccess,\n} from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport { array, boolean, object, optional, refine, string } from 'superstruct';\n\nexport const RpcOriginsStruct = refine(\n object({\n dapps: optional(boolean()),\n snaps: optional(boolean()),\n allowedOrigins: optional(array(string())),\n }),\n 'RPC origins',\n (value) => {\n const hasOrigins = Boolean(\n value.snaps === true ||\n value.dapps === true ||\n (value.allowedOrigins && value.allowedOrigins.length > 0),\n );\n\n if (hasOrigins) {\n return true;\n }\n\n return 'Must specify at least one JSON-RPC origin.';\n },\n);\n\nexport type RpcOrigins = Infer<typeof RpcOriginsStruct>;\n\n/**\n * Asserts that the given value is a valid {@link RpcOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link RpcOrigins} object.\n */\nexport function assertIsRpcOrigins(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is RpcOrigins {\n assertStruct(\n value,\n RpcOriginsStruct,\n 'Invalid JSON-RPC origins',\n ErrorWrapper,\n );\n}\n\nexport const KeyringOriginsStruct = object({\n allowedOrigins: optional(array(string())),\n});\n\nexport type KeyringOrigins = Infer<typeof KeyringOriginsStruct>;\n\n/**\n * Assert that the given value is a valid {@link KeyringOrigins} object.\n *\n * @param value - The value to assert.\n * @param ErrorWrapper - An optional error wrapper to use. Defaults to\n * {@link AssertionError}.\n * @throws If the value is not a valid {@link KeyringOrigins} object.\n */\nexport function assertIsKeyringOrigins(\n value: unknown,\n // eslint-disable-next-line @typescript-eslint/naming-convention\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is KeyringOrigins {\n assertStruct(\n value,\n KeyringOriginsStruct,\n 'Invalid keyring origins',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given origin is allowed by the given JSON-RPC origins object.\n *\n * @param origins - The JSON-RPC origins object.\n * @param subjectType - The type of the origin.\n * @param origin - The origin to check.\n * @returns Whether the origin is allowed.\n */\nexport function isOriginAllowed(\n origins: RpcOrigins,\n subjectType: SubjectType,\n origin: string,\n) {\n // The MetaMask client is always allowed.\n if (origin === 'metamask') {\n return true;\n }\n\n // If the origin is in the `allowedOrigins` list, it is allowed.\n if (origins.allowedOrigins?.includes(origin)) {\n return true;\n }\n\n // If the origin is a website and `dapps` is true, it is allowed.\n if (subjectType === SubjectType.Website && origins.dapps) {\n return true;\n }\n\n // If the origin is a snap and `snaps` is true, it is allowed.\n return Boolean(subjectType === SubjectType.Snap && origins.snaps);\n}\n\n/**\n * Assert that the given value is a successful JSON-RPC response. If the value\n * is not a success response, an error is thrown. If the value is an JSON-RPC\n * error, the error message is included in the thrown error.\n *\n * @param value - The value to check.\n * @throws If the value is not a JSON-RPC success response.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n): asserts value is JsonRpcSuccess<Json> {\n if (!isJsonRpcSuccess(value)) {\n if (isJsonRpcFailure(value)) {\n throw new Error(`JSON-RPC request failed: ${value.error.message}`);\n }\n\n throw new Error('Invalid JSON-RPC response.');\n }\n}\n"]}
|
|
@@ -0,0 +1,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-DKDGMZFU.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,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/logging.ts
|
|
2
|
+
var _utils = require('@metamask/utils');
|
|
3
|
+
var snapsLogger = _utils.createProjectLogger.call(void 0, "snaps");
|
|
4
|
+
function logInfo(message, ...optionalParams) {
|
|
5
|
+
console.log(message, ...optionalParams);
|
|
6
|
+
}
|
|
7
|
+
function logError(error, ...optionalParams) {
|
|
8
|
+
console.error(error, ...optionalParams);
|
|
9
|
+
}
|
|
10
|
+
function logWarning(message, ...optionalParams) {
|
|
11
|
+
console.warn(message, ...optionalParams);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.snapsLogger = snapsLogger; exports.logInfo = logInfo; exports.logError = logError; exports.logWarning = logWarning;
|
|
20
|
+
//# sourceMappingURL=chunk-E3BDBG6T.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logging.ts"],"names":[],"mappings":";AAAA,SAAS,2BAA2B;AAI7B,IAAM,cAAc,oBAAoB,OAAO;AAc/C,SAAS,QAAQ,YAAoB,gBAAiC;AAE3E,UAAQ,IAAI,SAAS,GAAG,cAAc;AACxC;AAkBO,SAAS,SAAS,UAAmB,gBAAiC;AAE3E,UAAQ,MAAM,OAAO,GAAG,cAAc;AACxC;AAkBO,SAAS,WACd,YACG,gBACG;AAEN,UAAQ,KAAK,SAAS,GAAG,cAAc;AACzC","sourcesContent":["import { createProjectLogger } from '@metamask/utils';\n\n// The global logger used across the monorepo. Other projects should use this\n// to create a module logger.\nexport const snapsLogger = createProjectLogger('snaps');\n\n/**\n * Log a message. Currently, this is just a wrapper around `console.log`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param message - The message to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logInfo(message: string, ...optionalParams: unknown[]): void {\n // eslint-disable-next-line no-console\n console.log(message, ...optionalParams);\n}\n\n/**\n * Log an error. Currently, this is just a wrapper around `console.error`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * These logs should always be visible, without requiring the user to enable\n * verbose logging (like setting a `DEBUG` environment variable), as they are\n * important for debugging snaps.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param error - The error to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logError(error: unknown, ...optionalParams: unknown[]): void {\n // eslint-disable-next-line no-console\n console.error(error, ...optionalParams);\n}\n\n/**\n * Log a warning. Currently, this is just a wrapper around `console.warn`, but\n * the implementation may change in the future. These logs will be included in\n * production builds, so they should be used sparingly, and not contain any\n * sensitive information.\n *\n * These logs should always be visible, without requiring the user to enable\n * verbose logging (like setting a `DEBUG` environment variable), as they are\n * important for debugging snaps.\n *\n * This function makes it easy to swap out the logging implementation in all\n * files at once.\n *\n * @param message - The message to log.\n * @param optionalParams - Additional parameters to pass to the logging.\n */\nexport function logWarning(\n message: string,\n ...optionalParams: unknown[]\n): void {\n // eslint-disable-next-line no-console\n console.warn(message, ...optionalParams);\n}\n"]}
|