@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,211 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkIJX3CXOYjs = require('./chunk-IJX3CXOY.js');
|
|
4
|
+
|
|
5
|
+
// src/structs.ts
|
|
6
|
+
var _snapssdk = require('@metamask/snaps-sdk');
|
|
7
|
+
var _utils = require('@metamask/utils');
|
|
8
|
+
var _chalk = require('chalk');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
var _superstruct = require('superstruct');
|
|
17
|
+
function color(value, colorFunction, enabled) {
|
|
18
|
+
if (enabled) {
|
|
19
|
+
return colorFunction(value);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function named(name, struct) {
|
|
24
|
+
return new (0, _superstruct.Struct)({
|
|
25
|
+
...struct,
|
|
26
|
+
type: name
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var SnapsStructError = class extends _superstruct.StructError {
|
|
30
|
+
constructor(struct, prefix, suffix, failure, failures, colorize = true) {
|
|
31
|
+
super(failure, failures);
|
|
32
|
+
this.name = "SnapsStructError";
|
|
33
|
+
this.message = `${prefix}.
|
|
34
|
+
|
|
35
|
+
${getStructErrorMessage(
|
|
36
|
+
struct,
|
|
37
|
+
[...failures()],
|
|
38
|
+
colorize
|
|
39
|
+
)}${suffix ? `
|
|
40
|
+
|
|
41
|
+
${suffix}` : ""}`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function* arrayToGenerator(array) {
|
|
45
|
+
for (const item of array) {
|
|
46
|
+
yield item;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function getError({
|
|
50
|
+
struct,
|
|
51
|
+
prefix,
|
|
52
|
+
suffix = "",
|
|
53
|
+
error,
|
|
54
|
+
colorize
|
|
55
|
+
}) {
|
|
56
|
+
return new SnapsStructError(
|
|
57
|
+
struct,
|
|
58
|
+
prefix,
|
|
59
|
+
suffix,
|
|
60
|
+
error,
|
|
61
|
+
() => arrayToGenerator(error.failures()),
|
|
62
|
+
colorize
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function createFromStruct(value, struct, prefix, suffix = "") {
|
|
66
|
+
try {
|
|
67
|
+
return _superstruct.create.call(void 0, value, struct);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error instanceof _superstruct.StructError) {
|
|
70
|
+
throw getError({ struct, prefix, suffix, error });
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function getStructFromPath(struct, path) {
|
|
76
|
+
return path.reduce((result, key) => {
|
|
77
|
+
if (_utils.isObject.call(void 0, struct.schema) && struct.schema[key]) {
|
|
78
|
+
return struct.schema[key];
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}, struct);
|
|
82
|
+
}
|
|
83
|
+
function getUnionStructNames(struct, colorize = true) {
|
|
84
|
+
if (Array.isArray(struct.schema)) {
|
|
85
|
+
return struct.schema.map(({ type }) => color(type, _chalk.green, colorize));
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function getStructErrorPrefix(failure, colorize = true) {
|
|
90
|
+
if (failure.type === "never" || failure.path.length === 0) {
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
return `At path: ${color(failure.path.join("."), _chalk.bold, colorize)} \u2014 `;
|
|
94
|
+
}
|
|
95
|
+
function getStructFailureMessage(struct, failure, colorize = true) {
|
|
96
|
+
const received = color(JSON.stringify(failure.value), _chalk.red, colorize);
|
|
97
|
+
const prefix = getStructErrorPrefix(failure, colorize);
|
|
98
|
+
if (failure.type === "union") {
|
|
99
|
+
const childStruct = getStructFromPath(struct, failure.path);
|
|
100
|
+
const unionNames = getUnionStructNames(childStruct, colorize);
|
|
101
|
+
if (unionNames) {
|
|
102
|
+
return `${prefix}Expected the value to be one of: ${unionNames.join(
|
|
103
|
+
", "
|
|
104
|
+
)}, but received: ${received}.`;
|
|
105
|
+
}
|
|
106
|
+
return `${prefix}${failure.message}.`;
|
|
107
|
+
}
|
|
108
|
+
if (failure.type === "literal") {
|
|
109
|
+
const message = failure.message.replace(
|
|
110
|
+
/the literal `(.+)`,/u,
|
|
111
|
+
`the value to be \`${color("$1", _chalk.green, colorize)}\`,`
|
|
112
|
+
).replace(
|
|
113
|
+
/, but received: (.+)/u,
|
|
114
|
+
`, but received: ${color("$1", _chalk.red, colorize)}`
|
|
115
|
+
);
|
|
116
|
+
return `${prefix}${message}.`;
|
|
117
|
+
}
|
|
118
|
+
if (failure.type === "never") {
|
|
119
|
+
return `Unknown key: ${color(
|
|
120
|
+
failure.path.join("."),
|
|
121
|
+
_chalk.bold,
|
|
122
|
+
colorize
|
|
123
|
+
)}, received: ${received}.`;
|
|
124
|
+
}
|
|
125
|
+
if (failure.refinement === "size") {
|
|
126
|
+
const message = failure.message.replace(
|
|
127
|
+
/length between `(\d+)` and `(\d+)`/u,
|
|
128
|
+
`length between ${color("$1", _chalk.green, colorize)} and ${color(
|
|
129
|
+
"$2",
|
|
130
|
+
_chalk.green,
|
|
131
|
+
colorize
|
|
132
|
+
)},`
|
|
133
|
+
).replace(/length of `(\d+)`/u, `length of ${color("$1", _chalk.red, colorize)}`).replace(/a array/u, "an array");
|
|
134
|
+
return `${prefix}${message}.`;
|
|
135
|
+
}
|
|
136
|
+
return `${prefix}Expected a value of type ${color(
|
|
137
|
+
failure.type,
|
|
138
|
+
_chalk.green,
|
|
139
|
+
colorize
|
|
140
|
+
)}, but received: ${received}.`;
|
|
141
|
+
}
|
|
142
|
+
function getStructErrorMessage(struct, failures, colorize = true) {
|
|
143
|
+
const formattedFailures = failures.map(
|
|
144
|
+
(failure) => _chunkIJX3CXOYjs.indent.call(void 0, `\u2022 ${getStructFailureMessage(struct, failure, colorize)}`)
|
|
145
|
+
);
|
|
146
|
+
return formattedFailures.join("\n");
|
|
147
|
+
}
|
|
148
|
+
function validateUnion(value, struct, structKey, coerce = false) {
|
|
149
|
+
_utils.assert.call(void 0,
|
|
150
|
+
struct.schema,
|
|
151
|
+
"Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`."
|
|
152
|
+
);
|
|
153
|
+
_utils.assert.call(void 0, struct.schema.length > 0, "Expected a non-empty array of structs.");
|
|
154
|
+
const keyUnion = struct.schema.map(
|
|
155
|
+
(innerStruct) => innerStruct.schema[structKey]
|
|
156
|
+
// This is guaranteed to be a non-empty array by the assertion above. We
|
|
157
|
+
// need to cast it since `superstruct` requires a non-empty array of structs
|
|
158
|
+
// for the `union` struct.
|
|
159
|
+
);
|
|
160
|
+
const key = _superstruct.type.call(void 0, {
|
|
161
|
+
[structKey]: _snapssdk.union.call(void 0, keyUnion)
|
|
162
|
+
});
|
|
163
|
+
const [keyError] = _superstruct.validate.call(void 0, value, key, { coerce });
|
|
164
|
+
if (keyError) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
getStructFailureMessage(key, keyError.failures()[0], false)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
const objectValue = value;
|
|
170
|
+
const objectStructs = struct.schema.filter(
|
|
171
|
+
(innerStruct) => _superstruct.is.call(void 0, objectValue[structKey], innerStruct.schema[structKey])
|
|
172
|
+
);
|
|
173
|
+
_utils.assert.call(void 0, objectStructs.length > 0, "Expected a struct to match the value.");
|
|
174
|
+
const validationResults = objectStructs.map(
|
|
175
|
+
(objectStruct) => _superstruct.validate.call(void 0, objectValue, objectStruct, { coerce })
|
|
176
|
+
);
|
|
177
|
+
const validatedValue = validationResults.find(([error]) => !error);
|
|
178
|
+
if (validatedValue) {
|
|
179
|
+
return validatedValue[1];
|
|
180
|
+
}
|
|
181
|
+
_utils.assert.call(void 0, validationResults[0][0], "Expected at least one error.");
|
|
182
|
+
const validationError = validationResults.reduce((error, [innerError]) => {
|
|
183
|
+
_utils.assert.call(void 0, innerError, "Expected an error.");
|
|
184
|
+
if (innerError.failures().length < error.failures().length) {
|
|
185
|
+
return innerError;
|
|
186
|
+
}
|
|
187
|
+
return error;
|
|
188
|
+
}, validationResults[0][0]);
|
|
189
|
+
throw new Error(
|
|
190
|
+
getStructFailureMessage(struct, validationError.failures()[0], false)
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
function createUnion(value, struct, structKey) {
|
|
194
|
+
return validateUnion(value, struct, structKey, true);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
exports.named = named; exports.SnapsStructError = SnapsStructError; exports.arrayToGenerator = arrayToGenerator; exports.getError = getError; exports.createFromStruct = createFromStruct; exports.getStructFromPath = getStructFromPath; exports.getUnionStructNames = getUnionStructNames; exports.getStructErrorPrefix = getStructErrorPrefix; exports.getStructFailureMessage = getStructFailureMessage; exports.getStructErrorMessage = getStructErrorMessage; exports.validateUnion = validateUnion; exports.createUnion = createUnion;
|
|
211
|
+
//# sourceMappingURL=chunk-A6E325SZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/structs.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,aAAa;AAEtB,SAAS,QAAQ,gBAAgB;AACjC,SAAS,MAAM,OAAO,WAAW;AAEjC;AAAA,EACE;AAAA,EACA;AAAA,EACA,QAAQ;AAAA,EACR;AAAA,EACA;AAAA,EACA;AAAA,OACK;AA2CP,SAAS,MACP,OACA,eACA,SACA;AACA,MAAI,SAAS;AACX,WAAO,cAAc,KAAK;AAAA,EAC5B;AAEA,SAAO;AACT;AAWO,SAAS,MACd,MACA,QACA;AACA,SAAO,IAAI,OAAO;AAAA,IAChB,GAAG;AAAA,IACH,MAAM;AAAA,EACR,CAAC;AACH;AAEO,IAAM,mBAAN,cAA6C,YAAY;AAAA,EAC9D,YACE,QACA,QACA,QACA,SACA,UACA,WAAW,MACX;AACA,UAAM,SAAS,QAAQ;AAEvB,SAAK,OAAO;AACZ,SAAK,UAAU,GAAG,MAAM;AAAA;AAAA,EAAQ;AAAA,MAC9B;AAAA,MACA,CAAC,GAAG,SAAS,CAAC;AAAA,MACd;AAAA,IACF,CAAC,GAAG,SAAS;AAAA;AAAA,EAAO,MAAM,KAAK,EAAE;AAAA,EACnC;AACF;AAkBO,UAAU,iBACf,OACkC;AAClC,aAAW,QAAQ,OAAO;AACxB,UAAM;AAAA,EACR;AACF;AAcO,SAAS,SAAuB;AAAA,EACrC;AAAA,EACA;AAAA,EACA,SAAS;AAAA,EACT;AAAA,EACA;AACF,GAAkC;AAChC,SAAO,IAAI;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,MAAM,iBAAiB,MAAM,SAAS,CAAC;AAAA,IACvC;AAAA,EACF;AACF;AAcO,SAAS,iBACd,OACA,QACA,QACA,SAAS,IACT;AACA,MAAI;AACF,WAAO,OAAO,OAAO,MAAM;AAAA,EAC7B,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,SAAS,EAAE,QAAQ,QAAQ,QAAQ,MAAM,CAAC;AAAA,IAClD;AAEA,UAAM;AAAA,EACR;AACF;AASO,SAAS,kBACd,QACA,MACA;AACA,SAAO,KAAK,OAAkB,CAAC,QAAQ,QAAQ;AAC7C,QAAI,SAAS,OAAO,MAAM,KAAK,OAAO,OAAO,GAAG,GAAG;AACjD,aAAO,OAAO,OAAO,GAAG;AAAA,IAC1B;AAEA,WAAO;AAAA,EACT,GAAG,MAAM;AACX;AAUO,SAAS,oBACd,QACA,WAAW,MACX;AACA,MAAI,MAAM,QAAQ,OAAO,MAAM,GAAG;AAChC,WAAO,OAAO,OAAO,IAAI,CAAC,EAAE,KAAK,MAAM,MAAM,MAAM,OAAO,QAAQ,CAAC;AAAA,EACrE;AAEA,SAAO;AACT;AAUO,SAAS,qBAAqB,SAAkB,WAAW,MAAM;AACtE,MAAI,QAAQ,SAAS,WAAW,QAAQ,KAAK,WAAW,GAAG;AACzD,WAAO;AAAA,EACT;AAEA,SAAO,YAAY,MAAM,QAAQ,KAAK,KAAK,GAAG,GAAG,MAAM,QAAQ,CAAC;AAClE;AAYO,SAAS,wBACd,QACA,SACA,WAAW,MACX;AACA,QAAM,WAAW,MAAM,KAAK,UAAU,QAAQ,KAAK,GAAG,KAAK,QAAQ;AACnE,QAAM,SAAS,qBAAqB,SAAS,QAAQ;AAErD,MAAI,QAAQ,SAAS,SAAS;AAC5B,UAAM,cAAc,kBAAkB,QAAQ,QAAQ,IAAI;AAC1D,UAAM,aAAa,oBAAoB,aAAa,QAAQ;AAE5D,QAAI,YAAY;AACd,aAAO,GAAG,MAAM,oCAAoC,WAAW;AAAA,QAC7D;AAAA,MACF,CAAC,mBAAmB,QAAQ;AAAA,IAC9B;AAEA,WAAO,GAAG,MAAM,GAAG,QAAQ,OAAO;AAAA,EACpC;AAEA,MAAI,QAAQ,SAAS,WAAW;AAG9B,UAAM,UAAU,QAAQ,QACrB;AAAA,MACC;AAAA,MACA,qBAAqB,MAAM,MAAM,OAAO,QAAQ,CAAC;AAAA,IACnD,EACC;AAAA,MACC;AAAA,MACA,mBAAmB,MAAM,MAAM,KAAK,QAAQ,CAAC;AAAA,IAC/C;AAEF,WAAO,GAAG,MAAM,GAAG,OAAO;AAAA,EAC5B;AAEA,MAAI,QAAQ,SAAS,SAAS;AAC5B,WAAO,gBAAgB;AAAA,MACrB,QAAQ,KAAK,KAAK,GAAG;AAAA,MACrB;AAAA,MACA;AAAA,IACF,CAAC,eAAe,QAAQ;AAAA,EAC1B;AAEA,MAAI,QAAQ,eAAe,QAAQ;AACjC,UAAM,UAAU,QAAQ,QACrB;AAAA,MACC;AAAA,MACA,kBAAkB,MAAM,MAAM,OAAO,QAAQ,CAAC,QAAQ;AAAA,QACpD;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAAA,IACH,EACC,QAAQ,sBAAsB,aAAa,MAAM,MAAM,KAAK,QAAQ,CAAC,EAAE,EACvE,QAAQ,YAAY,UAAU;AAEjC,WAAO,GAAG,MAAM,GAAG,OAAO;AAAA,EAC5B;AAEA,SAAO,GAAG,MAAM,4BAA4B;AAAA,IAC1C,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EACF,CAAC,mBAAmB,QAAQ;AAC9B;AAWO,SAAS,sBACd,QACA,UACA,WAAW,MACX;AACA,QAAM,oBAAoB,SAAS;AAAA,IAAI,CAAC,YACtC,OAAO,UAAK,wBAAwB,QAAQ,SAAS,QAAQ,CAAC,EAAE;AAAA,EAClE;AAEA,SAAO,kBAAkB,KAAK,IAAI;AACpC;AAgCO,SAAS,cACd,OACA,QACA,WACA,SAAS,OACT;AACA;AAAA,IACE,OAAO;AAAA,IACP;AAAA,EACF;AACA,SAAO,OAAO,OAAO,SAAS,GAAG,wCAAwC;AAEzE,QAAM,WAAW,OAAO,OAAO;AAAA,IAC7B,CAAC,gBAAgB,YAAY,OAAO,SAAS;AAAA;AAAA;AAAA;AAAA,EAI/C;AAEA,QAAM,MAAM,gBAAgB;AAAA,IAC1B,CAAC,SAAS,GAAG,MAAM,QAAQ;AAAA,EAC7B,CAAC;AAED,QAAM,CAAC,QAAQ,IAAI,SAAS,OAAO,KAAK,EAAE,OAAO,CAAC;AAClD,MAAI,UAAU;AACZ,UAAM,IAAI;AAAA,MACR,wBAAwB,KAAK,SAAS,SAAS,EAAE,CAAC,GAAG,KAAK;AAAA,IAC5D;AAAA,EACF;AAIA,QAAM,cAAc;AACpB,QAAM,gBAAgB,OAAO,OAAO;AAAA,IAAO,CAAC,gBAC1C,GAAG,YAAY,SAAS,GAAG,YAAY,OAAO,SAAS,CAAC;AAAA,EAC1D;AAEA,SAAO,cAAc,SAAS,GAAG,uCAAuC;AAIxE,QAAM,oBAAoB,cAAc;AAAA,IAAI,CAAC,iBAC3C,SAAS,aAAa,cAAc,EAAE,OAAO,CAAC;AAAA,EAChD;AAEA,QAAM,iBAAiB,kBAAkB,KAAK,CAAC,CAAC,KAAK,MAAM,CAAC,KAAK;AACjE,MAAI,gBAAgB;AAClB,WAAO,eAAe,CAAC;AAAA,EACzB;AAEA,SAAO,kBAAkB,CAAC,EAAE,CAAC,GAAG,8BAA8B;AAI9D,QAAM,kBAAkB,kBAAkB,OAAO,CAAC,OAAO,CAAC,UAAU,MAAM;AACxE,WAAO,YAAY,oBAAoB;AACvC,QAAI,WAAW,SAAS,EAAE,SAAS,MAAM,SAAS,EAAE,QAAQ;AAC1D,aAAO;AAAA,IACT;AAEA,WAAO;AAAA,EACT,GAAG,kBAAkB,CAAC,EAAE,CAAC,CAAC;AAE1B,QAAM,IAAI;AAAA,IACR,wBAAwB,QAAQ,gBAAgB,SAAS,EAAE,CAAC,GAAG,KAAK;AAAA,EACtE;AACF;AAkBO,SAAS,YACd,OACA,QACA,WACA;AACA,SAAO,cAAc,OAAO,QAAQ,WAAW,IAAI;AACrD","sourcesContent":["import { union } from '@metamask/snaps-sdk';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert, isObject } from '@metamask/utils';\nimport { bold, green, red } from 'chalk';\nimport type { Failure } from 'superstruct';\nimport {\n is,\n validate,\n type as superstructType,\n Struct,\n StructError,\n create,\n} from 'superstruct';\nimport type { AnyStruct } from 'superstruct/dist/utils';\n\nimport { indent } from './strings';\n\n/**\n * Infer a struct type, only if it matches the specified type. This is useful\n * for defining types and structs that are related to each other in separate\n * files.\n *\n * @example\n * ```typescript\n * // In file A\n * export type GetFileArgs = {\n * path: string;\n * encoding?: EnumToUnion<AuxiliaryFileEncoding>;\n * };\n *\n * // In file B\n * export const GetFileArgsStruct = object(...);\n *\n * // If the type and struct are in the same file, this will return the type.\n * // Otherwise, it will return `never`.\n * export type GetFileArgs =\n * InferMatching<typeof GetFileArgsStruct, GetFileArgs>;\n * ```\n */\nexport type InferMatching<\n StructType extends Struct<any, any>,\n Type,\n> = StructType['TYPE'] extends Type ? Type : never;\n\n/**\n * Colorize a value with a color function. This is useful for colorizing values\n * in error messages. If colorization is disabled, the original value is\n * returned.\n *\n * @param value - The value to colorize.\n * @param colorFunction - The color function to use.\n * @param enabled - Whether to colorize the value.\n * @returns The colorized value, or the original value if colorization is\n * disabled.\n */\nfunction color(\n value: string,\n colorFunction: (value: string) => string,\n enabled: boolean,\n) {\n if (enabled) {\n return colorFunction(value);\n }\n\n return value;\n}\n\n/**\n * Define a struct, and also define the name of the struct as the given name.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n *\n * @param name - The name of the struct.\n * @param struct - The struct.\n * @returns The struct.\n */\nexport function named<Type, Schema>(\n name: string,\n struct: Struct<Type, Schema>,\n) {\n return new Struct({\n ...struct,\n type: name,\n });\n}\n\nexport class SnapsStructError<Type, Schema> extends StructError {\n constructor(\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix: string,\n failure: StructError,\n failures: () => Generator<Failure>,\n colorize = true,\n ) {\n super(failure, failures);\n\n this.name = 'SnapsStructError';\n this.message = `${prefix}.\\n\\n${getStructErrorMessage(\n struct,\n [...failures()],\n colorize,\n )}${suffix ? `\\n\\n${suffix}` : ''}`;\n }\n}\n\ntype GetErrorOptions<Type, Schema> = {\n struct: Struct<Type, Schema>;\n prefix: string;\n suffix?: string;\n error: StructError;\n colorize?: boolean;\n};\n\n/**\n * Converts an array to a generator function that yields the items in the\n * array.\n *\n * @param array - The array.\n * @returns A generator function.\n * @yields The items in the array.\n */\nexport function* arrayToGenerator<Type>(\n array: Type[],\n): Generator<Type, void, undefined> {\n for (const item of array) {\n yield item;\n }\n}\n\n/**\n * Returns a `SnapsStructError` with the given prefix and suffix.\n *\n * @param options - The options.\n * @param options.struct - The struct that caused the error.\n * @param options.prefix - The prefix to add to the error message.\n * @param options.suffix - The suffix to add to the error message. Defaults to\n * an empty string.\n * @param options.error - The `superstruct` error to wrap.\n * @param options.colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The `SnapsStructError`.\n */\nexport function getError<Type, Schema>({\n struct,\n prefix,\n suffix = '',\n error,\n colorize,\n}: GetErrorOptions<Type, Schema>) {\n return new SnapsStructError(\n struct,\n prefix,\n suffix,\n error,\n () => arrayToGenerator(error.failures()),\n colorize,\n );\n}\n\n/**\n * A wrapper of `superstruct`'s `create` function that throws a\n * `SnapsStructError` instead of a `StructError`. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` struct to validate the value against.\n * @param prefix - The prefix to add to the error message.\n * @param suffix - The suffix to add to the error message. Defaults to an empty\n * string.\n * @returns The validated value.\n */\nexport function createFromStruct<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix = '',\n) {\n try {\n return create(value, struct);\n } catch (error) {\n if (error instanceof StructError) {\n throw getError({ struct, prefix, suffix, error });\n }\n\n throw error;\n }\n}\n\n/**\n * Get a struct from a failure path.\n *\n * @param struct - The struct.\n * @param path - The failure path.\n * @returns The struct at the failure path.\n */\nexport function getStructFromPath<Type, Schema>(\n struct: Struct<Type, Schema>,\n path: string[],\n) {\n return path.reduce<AnyStruct>((result, key) => {\n if (isObject(struct.schema) && struct.schema[key]) {\n return struct.schema[key] as AnyStruct;\n }\n\n return result;\n }, struct);\n}\n\n/**\n * Get the union struct names from a struct.\n *\n * @param struct - The struct.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The union struct names, or `null` if the struct is not a union\n * struct.\n */\nexport function getUnionStructNames<Type, Schema>(\n struct: Struct<Type, Schema>,\n colorize = true,\n) {\n if (Array.isArray(struct.schema)) {\n return struct.schema.map(({ type }) => color(type, green, colorize));\n }\n\n return null;\n}\n\n/**\n * Get an error prefix from a `superstruct` failure. This is useful for\n * formatting the error message returned by `superstruct`.\n *\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The error prefix.\n */\nexport function getStructErrorPrefix(failure: Failure, colorize = true) {\n if (failure.type === 'never' || failure.path.length === 0) {\n return '';\n }\n\n return `At path: ${color(failure.path.join('.'), bold, colorize)} — `;\n}\n\n/**\n * Get a string describing the failure. This is similar to the `message`\n * property of `superstruct`'s `Failure` type, but formats the value in a more\n * readable way.\n *\n * @param struct - The struct that caused the failure.\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the failure.\n */\nexport function getStructFailureMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failure: Failure,\n colorize = true,\n) {\n const received = color(JSON.stringify(failure.value), red, colorize);\n const prefix = getStructErrorPrefix(failure, colorize);\n\n if (failure.type === 'union') {\n const childStruct = getStructFromPath(struct, failure.path);\n const unionNames = getUnionStructNames(childStruct, colorize);\n\n if (unionNames) {\n return `${prefix}Expected the value to be one of: ${unionNames.join(\n ', ',\n )}, but received: ${received}.`;\n }\n\n return `${prefix}${failure.message}.`;\n }\n\n if (failure.type === 'literal') {\n // Superstruct's failure does not provide information about which literal\n // value was expected, so we need to parse the message to get the literal.\n const message = failure.message\n .replace(\n /the literal `(.+)`,/u,\n `the value to be \\`${color('$1', green, colorize)}\\`,`,\n )\n .replace(\n /, but received: (.+)/u,\n `, but received: ${color('$1', red, colorize)}`,\n );\n\n return `${prefix}${message}.`;\n }\n\n if (failure.type === 'never') {\n return `Unknown key: ${color(\n failure.path.join('.'),\n bold,\n colorize,\n )}, received: ${received}.`;\n }\n\n if (failure.refinement === 'size') {\n const message = failure.message\n .replace(\n /length between `(\\d+)` and `(\\d+)`/u,\n `length between ${color('$1', green, colorize)} and ${color(\n '$2',\n green,\n colorize,\n )},`,\n )\n .replace(/length of `(\\d+)`/u, `length of ${color('$1', red, colorize)}`)\n .replace(/a array/u, 'an array');\n\n return `${prefix}${message}.`;\n }\n\n return `${prefix}Expected a value of type ${color(\n failure.type,\n green,\n colorize,\n )}, but received: ${received}.`;\n}\n\n/**\n * Get a string describing the errors. This formats all the errors in a\n * human-readable way.\n *\n * @param struct - The struct that caused the failures.\n * @param failures - The `superstruct` failures.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the errors.\n */\nexport function getStructErrorMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failures: Failure[],\n colorize = true,\n) {\n const formattedFailures = failures.map((failure) =>\n indent(`• ${getStructFailureMessage(struct, failure, colorize)}`),\n );\n\n return formattedFailures.join('\\n');\n}\n\n/**\n * Validate a union struct, and throw readable errors if the value does not\n * satisfy the struct. This is useful for improving the error messages returned\n * by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @param coerce - Whether to coerce the value to satisfy the struct. Defaults\n * to `false`.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @example\n * const struct = union([\n * object({ type: literal('a'), value: string() }),\n * object({ type: literal('b'), value: number() }),\n * object({ type: literal('c'), value: boolean() }),\n * // ...\n * ]);\n *\n * // At path: type — Expected the value to be one of: \"a\", \"b\", \"c\", but received: \"d\".\n * validateUnion({ type: 'd', value: 'foo' }, struct, 'type');\n *\n * // At path: value — Expected a value of type string, but received: 42.\n * validateUnion({ type: 'a', value: 42 }, struct, 'value');\n */\nexport function validateUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n coerce = false,\n) {\n assert(\n struct.schema,\n 'Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`.',\n );\n assert(struct.schema.length > 0, 'Expected a non-empty array of structs.');\n\n const keyUnion = struct.schema.map(\n (innerStruct) => innerStruct.schema[structKey],\n // This is guaranteed to be a non-empty array by the assertion above. We\n // need to cast it since `superstruct` requires a non-empty array of structs\n // for the `union` struct.\n ) as NonEmptyArray<Struct>;\n\n const key = superstructType({\n [structKey]: union(keyUnion),\n });\n\n const [keyError] = validate(value, key, { coerce });\n if (keyError) {\n throw new Error(\n getStructFailureMessage(key, keyError.failures()[0], false),\n );\n }\n\n // At this point it's guaranteed that the value is an object, so we can safely\n // cast it to a Record.\n const objectValue = value as Record<PropertyKey, unknown>;\n const objectStructs = struct.schema.filter((innerStruct) =>\n is(objectValue[structKey], innerStruct.schema[structKey]),\n );\n\n assert(objectStructs.length > 0, 'Expected a struct to match the value.');\n\n // We need to validate the value against all the object structs that match the\n // struct key, and return the first validated value.\n const validationResults = objectStructs.map((objectStruct) =>\n validate(objectValue, objectStruct, { coerce }),\n );\n\n const validatedValue = validationResults.find(([error]) => !error);\n if (validatedValue) {\n return validatedValue[1];\n }\n\n assert(validationResults[0][0], 'Expected at least one error.');\n\n // If there is no validated value, we need to find the error with the least\n // number of failures (with the assumption that it's the most specific error).\n const validationError = validationResults.reduce((error, [innerError]) => {\n assert(innerError, 'Expected an error.');\n if (innerError.failures().length < error.failures().length) {\n return innerError;\n }\n\n return error;\n }, validationResults[0][0]);\n\n throw new Error(\n getStructFailureMessage(struct, validationError.failures()[0], false),\n );\n}\n\n/**\n * Create a value with the coercion logic of a union struct, and throw readable\n * errors if the value does not satisfy the struct. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @see validateUnion\n */\nexport function createUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n) {\n return validateUnion(value, struct, structKey, true);\n}\n"]}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkHF7HUZ5Zjs = require('./chunk-HF7HUZ5Z.js');
|
|
4
|
+
|
|
5
|
+
// src/localization.ts
|
|
6
|
+
var _snapssdk = require('@metamask/snaps-sdk');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
var _superstruct = require('superstruct');
|
|
15
|
+
var LOCALIZABLE_FIELDS = ["description", "proposedName"];
|
|
16
|
+
var LocalizationFileStruct = _superstruct.object.call(void 0, {
|
|
17
|
+
locale: _superstruct.string.call(void 0, ),
|
|
18
|
+
messages: _superstruct.record.call(void 0,
|
|
19
|
+
_superstruct.string.call(void 0, ),
|
|
20
|
+
_superstruct.object.call(void 0, {
|
|
21
|
+
message: _superstruct.string.call(void 0, ),
|
|
22
|
+
description: _superstruct.optional.call(void 0, _superstruct.string.call(void 0, ))
|
|
23
|
+
})
|
|
24
|
+
)
|
|
25
|
+
});
|
|
26
|
+
function getValidatedLocalizationFiles(localizationFiles) {
|
|
27
|
+
for (const file of localizationFiles) {
|
|
28
|
+
try {
|
|
29
|
+
file.result = _superstruct.create.call(void 0, _chunkHF7HUZ5Zjs.parseJson.call(void 0, file.toString()), LocalizationFileStruct);
|
|
30
|
+
} catch (error) {
|
|
31
|
+
if (error instanceof _superstruct.StructError) {
|
|
32
|
+
throw new Error(
|
|
33
|
+
`Failed to validate localization file "${file.path}": ${error.message}.`
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
if (error instanceof SyntaxError) {
|
|
37
|
+
throw new Error(
|
|
38
|
+
`Failed to parse localization file "${file.path}" as JSON.`
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return localizationFiles;
|
|
45
|
+
}
|
|
46
|
+
function getLocalizationFile(locale, localizationFiles) {
|
|
47
|
+
const file = localizationFiles.find(
|
|
48
|
+
(localizationFile) => localizationFile.locale === locale
|
|
49
|
+
);
|
|
50
|
+
if (!file) {
|
|
51
|
+
return localizationFiles.find(
|
|
52
|
+
(localizationFile) => localizationFile.locale === "en"
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
return file;
|
|
56
|
+
}
|
|
57
|
+
var TRANSLATION_REGEX = /\{\{\s?([a-zA-Z0-9-_\s]+)\s?\}\}/gu;
|
|
58
|
+
function translate(value, file) {
|
|
59
|
+
const matches = value.matchAll(TRANSLATION_REGEX);
|
|
60
|
+
const array = Array.from(matches);
|
|
61
|
+
return array.reduce((result, [match, key]) => {
|
|
62
|
+
if (!file) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
`Failed to translate "${value}": No localization file found.`
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
const translation = file.messages[key.trim()];
|
|
68
|
+
if (!translation) {
|
|
69
|
+
throw new Error(
|
|
70
|
+
`Failed to translate "${value}": No translation found for "${key.trim()}" in "${file.locale}" file.`
|
|
71
|
+
);
|
|
72
|
+
}
|
|
73
|
+
return result.replace(match, translation.message);
|
|
74
|
+
}, value);
|
|
75
|
+
}
|
|
76
|
+
function getLocalizedSnapManifest(snapManifest, locale, localizationFiles) {
|
|
77
|
+
const file = getLocalizationFile(locale, localizationFiles);
|
|
78
|
+
return LOCALIZABLE_FIELDS.reduce((manifest, field) => {
|
|
79
|
+
const translation = translate(manifest[field], file);
|
|
80
|
+
return {
|
|
81
|
+
...manifest,
|
|
82
|
+
[field]: translation
|
|
83
|
+
};
|
|
84
|
+
}, snapManifest);
|
|
85
|
+
}
|
|
86
|
+
function validateSnapManifestLocalizations(snapManifest, localizationFiles) {
|
|
87
|
+
try {
|
|
88
|
+
localizationFiles.filter((file) => file.locale !== "en").forEach((file) => {
|
|
89
|
+
getLocalizedSnapManifest(snapManifest, file.locale, localizationFiles);
|
|
90
|
+
});
|
|
91
|
+
getLocalizedSnapManifest(snapManifest, "en", localizationFiles);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Failed to localize Snap manifest: ${_snapssdk.getErrorMessage.call(void 0, error)}`
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
exports.LOCALIZABLE_FIELDS = LOCALIZABLE_FIELDS; exports.LocalizationFileStruct = LocalizationFileStruct; exports.getValidatedLocalizationFiles = getValidatedLocalizationFiles; exports.getLocalizationFile = getLocalizationFile; exports.TRANSLATION_REGEX = TRANSLATION_REGEX; exports.translate = translate; exports.getLocalizedSnapManifest = getLocalizedSnapManifest; exports.validateSnapManifestLocalizations = validateSnapManifestLocalizations;
|
|
109
|
+
//# sourceMappingURL=chunk-AFQY2CNY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/localization.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,uBAAuB;AAEhC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAMA,IAAM,qBAAqB,CAAC,eAAe,cAAc;AAEzD,IAAM,yBAAyB,OAAO;AAAA,EAC3C,QAAQ,OAAO;AAAA,EACf,UAAU;AAAA,IACR,OAAO;AAAA,IACP,OAAO;AAAA,MACL,SAAS,OAAO;AAAA,MAChB,aAAa,SAAS,OAAO,CAAC;AAAA,IAChC,CAAC;AAAA,EACH;AACF,CAAC;AAWM,SAAS,8BACd,mBACiC;AACjC,aAAW,QAAQ,mBAAmB;AACpC,QAAI;AACF,WAAK,SAAS,OAAO,UAAU,KAAK,SAAS,CAAC,GAAG,sBAAsB;AAAA,IACzE,SAAS,OAAO;AACd,UAAI,iBAAiB,aAAa;AAChC,cAAM,IAAI;AAAA,UACR,yCAAyC,KAAK,IAAI,MAAM,MAAM,OAAO;AAAA,QACvE;AAAA,MACF;AAEA,UAAI,iBAAiB,aAAa;AAChC,cAAM,IAAI;AAAA,UACR,sCAAsC,KAAK,IAAI;AAAA,QACjD;AAAA,MACF;AAEA,YAAM;AAAA,IACR;AAAA,EACF;AAEA,SAAO;AACT;AAWO,SAAS,oBACd,QACA,mBACA;AACA,QAAM,OAAO,kBAAkB;AAAA,IAC7B,CAAC,qBAAqB,iBAAiB,WAAW;AAAA,EACpD;AAEA,MAAI,CAAC,MAAM;AACT,WAAO,kBAAkB;AAAA,MACvB,CAAC,qBAAqB,iBAAiB,WAAW;AAAA,IACpD;AAAA,EACF;AAEA,SAAO;AACT;AAEO,IAAM,oBAAoB;AAa1B,SAAS,UAAU,OAAe,MAAoC;AAC3E,QAAM,UAAU,MAAM,SAAS,iBAAiB;AAChD,QAAM,QAAQ,MAAM,KAAK,OAAO;AAEhC,SAAO,MAAM,OAAe,CAAC,QAAQ,CAAC,OAAO,GAAG,MAAM;AACpD,QAAI,CAAC,MAAM;AACT,YAAM,IAAI;AAAA,QACR,wBAAwB,KAAK;AAAA,MAC/B;AAAA,IACF;AAEA,UAAM,cAAc,KAAK,SAAS,IAAI,KAAK,CAAC;AAC5C,QAAI,CAAC,aAAa;AAChB,YAAM,IAAI;AAAA,QACR,wBAAwB,KAAK,gCAAgC,IAAI,KAAK,CAAC,SACrE,KAAK,MACP;AAAA,MACF;AAAA,IACF;AAEA,WAAO,OAAO,QAAQ,OAAO,YAAY,OAAO;AAAA,EAClD,GAAG,KAAK;AACV;AAWO,SAAS,yBACd,cACA,QACA,mBACA;AACA,QAAM,OAAO,oBAAoB,QAAQ,iBAAiB;AAE1D,SAAO,mBAAmB,OAAO,CAAC,UAAU,UAAU;AACpD,UAAM,cAAc,UAAU,SAAS,KAAK,GAAG,IAAI;AACnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,CAAC,KAAK,GAAG;AAAA,IACX;AAAA,EACF,GAAG,YAAY;AACjB;AASO,SAAS,kCACd,cACA,mBACA;AACA,MAAI;AAGF,sBACG,OAAO,CAAC,SAAS,KAAK,WAAW,IAAI,EACrC,QAAQ,CAAC,SAAS;AACjB,+BAAyB,cAAc,KAAK,QAAQ,iBAAiB;AAAA,IACvE,CAAC;AAGH,6BAAyB,cAAc,MAAM,iBAAiB;AAAA,EAChE,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,qCAAqC,gBAAgB,KAAK,CAAC;AAAA,IAC7D;AAAA,EACF;AACF","sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Infer } from 'superstruct';\nimport {\n create,\n object,\n optional,\n record,\n string,\n StructError,\n} from 'superstruct';\n\nimport { parseJson } from './json';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport const LOCALIZABLE_FIELDS = ['description', 'proposedName'] as const;\n\nexport const LocalizationFileStruct = object({\n locale: string(),\n messages: record(\n string(),\n object({\n message: string(),\n description: optional(string()),\n }),\n ),\n});\n\nexport type LocalizationFile = Infer<typeof LocalizationFileStruct>;\n\n/**\n * Validate a list of localization files.\n *\n * @param localizationFiles - The localization files to validate.\n * @returns The validated localization files.\n * @throws If any of the files are considered invalid.\n */\nexport function getValidatedLocalizationFiles(\n localizationFiles: VirtualFile[],\n): VirtualFile<LocalizationFile>[] {\n for (const file of localizationFiles) {\n try {\n file.result = create(parseJson(file.toString()), LocalizationFileStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw new Error(\n `Failed to validate localization file \"${file.path}\": ${error.message}.`,\n );\n }\n\n if (error instanceof SyntaxError) {\n throw new Error(\n `Failed to parse localization file \"${file.path}\" as JSON.`,\n );\n }\n\n throw error;\n }\n }\n\n return localizationFiles as VirtualFile<LocalizationFile>[];\n}\n\n/**\n * Get the localization file for a given locale. If the locale is not found,\n * the English localization file will be returned.\n *\n * @param locale - The locale to use.\n * @param localizationFiles - The localization files to use.\n * @returns The localization file, or `undefined` if no localization file was\n * found.\n */\nexport function getLocalizationFile(\n locale: string,\n localizationFiles: LocalizationFile[],\n) {\n const file = localizationFiles.find(\n (localizationFile) => localizationFile.locale === locale,\n );\n\n if (!file) {\n return localizationFiles.find(\n (localizationFile) => localizationFile.locale === 'en',\n );\n }\n\n return file;\n}\n\nexport const TRANSLATION_REGEX = /\\{\\{\\s?([a-zA-Z0-9-_\\s]+)\\s?\\}\\}/gu;\n\n/**\n * Translate a string using a localization file. This will replace all instances\n * of `{{key}}` with the localized version of `key`.\n *\n * @param value - The string to translate.\n * @param file - The localization file to use, or `undefined` if no localization\n * file was found.\n * @returns The translated string.\n * @throws If the string contains a key that is not present in the localization\n * file, or if no localization file was found.\n */\nexport function translate(value: string, file: LocalizationFile | undefined) {\n const matches = value.matchAll(TRANSLATION_REGEX);\n const array = Array.from(matches);\n\n return array.reduce<string>((result, [match, key]) => {\n if (!file) {\n throw new Error(\n `Failed to translate \"${value}\": No localization file found.`,\n );\n }\n\n const translation = file.messages[key.trim()];\n if (!translation) {\n throw new Error(\n `Failed to translate \"${value}\": No translation found for \"${key.trim()}\" in \"${\n file.locale\n }\" file.`,\n );\n }\n\n return result.replace(match, translation.message);\n }, value);\n}\n\n/**\n * Get the localized Snap manifest for a given locale. This will replace all\n * localized strings in the manifest with the localized version.\n *\n * @param snapManifest - The Snap manifest to localize.\n * @param locale - The locale to use.\n * @param localizationFiles - The localization files to use.\n * @returns The localized Snap manifest.\n */\nexport function getLocalizedSnapManifest(\n snapManifest: SnapManifest,\n locale: string,\n localizationFiles: LocalizationFile[],\n) {\n const file = getLocalizationFile(locale, localizationFiles);\n\n return LOCALIZABLE_FIELDS.reduce((manifest, field) => {\n const translation = translate(manifest[field], file);\n return {\n ...manifest,\n [field]: translation,\n };\n }, snapManifest);\n}\n\n/**\n * Validate the localization files for a Snap manifest.\n *\n * @param snapManifest - The Snap manifest to validate.\n * @param localizationFiles - The localization files to validate.\n * @throws If the manifest cannot be localized.\n */\nexport function validateSnapManifestLocalizations(\n snapManifest: SnapManifest,\n localizationFiles: LocalizationFile[],\n) {\n try {\n // `translate` throws if the manifest cannot be localized, so we just attempt\n // to translate the manifest using all localization files.\n localizationFiles\n .filter((file) => file.locale !== 'en')\n .forEach((file) => {\n getLocalizedSnapManifest(snapManifest, file.locale, localizationFiles);\n });\n\n // The manifest must be localizable in English.\n getLocalizedSnapManifest(snapManifest, 'en', localizationFiles);\n } catch (error) {\n throw new Error(\n `Failed to localize Snap manifest: ${getErrorMessage(error)}`,\n );\n }\n}\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/path.ts
|
|
2
|
+
var _utils = require('@metamask/utils');
|
|
3
|
+
function normalizeRelative(path) {
|
|
4
|
+
_utils.assert.call(void 0, !path.startsWith("/"));
|
|
5
|
+
_utils.assert.call(void 0,
|
|
6
|
+
path.search(/:|\/\//u) === -1,
|
|
7
|
+
`Path "${path}" potentially an URI instead of local relative`
|
|
8
|
+
);
|
|
9
|
+
if (path.startsWith("./")) {
|
|
10
|
+
return path.slice(2);
|
|
11
|
+
}
|
|
12
|
+
return path;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
exports.normalizeRelative = normalizeRelative;
|
|
18
|
+
//# sourceMappingURL=chunk-AOGVLPQZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/path.ts"],"names":[],"mappings":";AAAA,SAAS,cAAc;AAShB,SAAS,kBAAkB,MAAsB;AACtD,SAAO,CAAC,KAAK,WAAW,GAAG,CAAC;AAC5B;AAAA,IACE,KAAK,OAAO,SAAS,MAAM;AAAA,IAC3B,SAAS,IAAI;AAAA,EACf;AAEA,MAAI,KAAK,WAAW,IAAI,GAAG;AACzB,WAAO,KAAK,MAAM,CAAC;AAAA,EACrB;AACA,SAAO;AACT","sourcesContent":["import { assert } from '@metamask/utils';\n\n/**\n * Normalizes relative paths by optionally removing `./` prefix.\n *\n * @param path - Path to make normalize.\n * @returns The same path, with `./` prefix remove.\n */\n// TODO(ritave): Include NodeJS path polyfill and use path.normalize as well\nexport function normalizeRelative(path: string): string {\n assert(!path.startsWith('/'));\n assert(\n path.search(/:|\\/\\//u) === -1,\n `Path \"${path}\" potentially an URI instead of local relative`,\n );\n\n if (path.startsWith('./')) {\n return path.slice(2);\n }\n return path;\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/entropy.ts"],"sourcesContent":["// 0xd36e6170 - 0x80000000\nexport const SIP_6_MAGIC_VALUE = `1399742832'` as `${number}'`;\n\n// `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`\nexport const STATE_ENCRYPTION_MAGIC_VALUE = `572232532'` as `${number}'`;\n\nexport type MagicValue =\n | typeof SIP_6_MAGIC_VALUE\n | typeof STATE_ENCRYPTION_MAGIC_VALUE;\n"],"mappings":";AACO,IAAM,oBAAoB;AAG1B,IAAM,+BAA+B;","names":[]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/caveats.ts
|
|
2
|
+
var SnapCaveatType = /* @__PURE__ */ ((SnapCaveatType2) => {
|
|
3
|
+
SnapCaveatType2["PermittedDerivationPaths"] = "permittedDerivationPaths";
|
|
4
|
+
SnapCaveatType2["PermittedCoinTypes"] = "permittedCoinTypes";
|
|
5
|
+
SnapCaveatType2["SnapCronjob"] = "snapCronjob";
|
|
6
|
+
SnapCaveatType2["TransactionOrigin"] = "transactionOrigin";
|
|
7
|
+
SnapCaveatType2["SignatureOrigin"] = "signatureOrigin";
|
|
8
|
+
SnapCaveatType2["RpcOrigin"] = "rpcOrigin";
|
|
9
|
+
SnapCaveatType2["KeyringOrigin"] = "keyringOrigin";
|
|
10
|
+
SnapCaveatType2["SnapIds"] = "snapIds";
|
|
11
|
+
SnapCaveatType2["ChainIds"] = "chainIds";
|
|
12
|
+
SnapCaveatType2["LookupMatchers"] = "lookupMatchers";
|
|
13
|
+
SnapCaveatType2["MaxRequestTime"] = "maxRequestTime";
|
|
14
|
+
return SnapCaveatType2;
|
|
15
|
+
})(SnapCaveatType || {});
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
exports.SnapCaveatType = SnapCaveatType;
|
|
20
|
+
//# sourceMappingURL=chunk-ASZWZ7JT.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/caveats.ts"],"names":["SnapCaveatType"],"mappings":";AAAO,IAAK,iBAAL,kBAAKA,oBAAL;AAIL,EAAAA,gBAAA,8BAA2B;AAK3B,EAAAA,gBAAA,wBAAqB;AAKrB,EAAAA,gBAAA,iBAAc;AAKd,EAAAA,gBAAA,uBAAoB;AAKpB,EAAAA,gBAAA,qBAAkB;AAKlB,EAAAA,gBAAA,eAAY;AAKZ,EAAAA,gBAAA,mBAAgB;AAKhB,EAAAA,gBAAA,aAAU;AAKV,EAAAA,gBAAA,cAAW;AAKX,EAAAA,gBAAA,oBAAiB;AAKjB,EAAAA,gBAAA,oBAAiB;AAtDP,SAAAA;AAAA,GAAA","sourcesContent":["export enum SnapCaveatType {\n /**\n * Permitted derivation paths, used by `snap_getBip32Entropy`.\n */\n PermittedDerivationPaths = 'permittedDerivationPaths',\n\n /**\n * Permitted coin types, used by `snap_getBip44Entropy`.\n */\n PermittedCoinTypes = 'permittedCoinTypes',\n\n /**\n * Caveat specifying a snap cronjob.\n */\n SnapCronjob = 'snapCronjob',\n\n /**\n * Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.\n */\n TransactionOrigin = 'transactionOrigin',\n\n /**\n * Caveat specifying access to the signature origin, used by `endowment:signature-insight`.\n */\n SignatureOrigin = 'signatureOrigin',\n\n /**\n * The origins that a Snap can receive JSON-RPC messages from.\n */\n RpcOrigin = 'rpcOrigin',\n\n /**\n * The origins that a Snap can receive keyring messages from.\n */\n KeyringOrigin = 'keyringOrigin',\n\n /**\n * Caveat specifying the snap IDs that can be interacted with.\n */\n SnapIds = 'snapIds',\n\n /**\n * Caveat specifying the CAIP-2 chain IDs that a snap can service, currently limited to `endowment:name-lookup`.\n */\n ChainIds = 'chainIds',\n\n /**\n * Caveat specifying the input that a name lookup snap can service, currently limited to `endowment:name-lookup`.\n */\n LookupMatchers = 'lookupMatchers',\n\n /**\n * Caveat specifying the max request time for a handler endowment.\n */\n MaxRequestTime = 'maxRequestTime',\n}\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/default-endowments.ts
|
|
2
|
+
var DEFAULT_ENDOWMENTS = Object.freeze([
|
|
3
|
+
"atob",
|
|
4
|
+
"btoa",
|
|
5
|
+
"BigInt",
|
|
6
|
+
"console",
|
|
7
|
+
"crypto",
|
|
8
|
+
"Date",
|
|
9
|
+
"Math",
|
|
10
|
+
"setTimeout",
|
|
11
|
+
"clearTimeout",
|
|
12
|
+
"SubtleCrypto",
|
|
13
|
+
"TextDecoder",
|
|
14
|
+
"TextEncoder",
|
|
15
|
+
"URL",
|
|
16
|
+
"setInterval",
|
|
17
|
+
"clearInterval",
|
|
18
|
+
"Int8Array",
|
|
19
|
+
"Uint8Array",
|
|
20
|
+
"Uint8ClampedArray",
|
|
21
|
+
"Int16Array",
|
|
22
|
+
"Uint16Array",
|
|
23
|
+
"Int32Array",
|
|
24
|
+
"Uint32Array",
|
|
25
|
+
"Float32Array",
|
|
26
|
+
"Float64Array",
|
|
27
|
+
"BigInt64Array",
|
|
28
|
+
"BigUint64Array",
|
|
29
|
+
"DataView",
|
|
30
|
+
"ArrayBuffer",
|
|
31
|
+
// Used by fetch, but also as API for some packages that don't do network connections
|
|
32
|
+
// https://github.com/MetaMask/snaps-monorepo/issues/662
|
|
33
|
+
// https://github.com/MetaMask/snaps-monorepo/discussions/678
|
|
34
|
+
"AbortController",
|
|
35
|
+
"AbortSignal"
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
export {
|
|
39
|
+
DEFAULT_ENDOWMENTS
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=chunk-BGSO2GQC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/default-endowments.ts"],"sourcesContent":["/**\n * Global JavaScript APIs exposed by default to all snaps.\n */\nexport const DEFAULT_ENDOWMENTS: readonly string[] = Object.freeze([\n 'atob',\n 'btoa',\n 'BigInt',\n 'console',\n 'crypto',\n 'Date',\n 'Math',\n 'setTimeout',\n 'clearTimeout',\n 'SubtleCrypto',\n 'TextDecoder',\n 'TextEncoder',\n 'URL',\n 'setInterval',\n 'clearInterval',\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n 'ArrayBuffer',\n // Used by fetch, but also as API for some packages that don't do network connections\n // https://github.com/MetaMask/snaps-monorepo/issues/662\n // https://github.com/MetaMask/snaps-monorepo/discussions/678\n 'AbortController',\n 'AbortSignal',\n]);\n"],"mappings":";AAGO,IAAM,qBAAwC,OAAO,OAAO;AAAA,EACjE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA;AAAA;AAAA;AAAA,EAIA;AAAA,EACA;AACF,CAAC;","names":[]}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/types.ts
|
|
2
|
+
var _utils = require('@metamask/utils');
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _superstruct = require('superstruct');
|
|
16
|
+
var NpmSnapFileNames = /* @__PURE__ */ ((NpmSnapFileNames2) => {
|
|
17
|
+
NpmSnapFileNames2["PackageJson"] = "package.json";
|
|
18
|
+
NpmSnapFileNames2["Manifest"] = "snap.manifest.json";
|
|
19
|
+
return NpmSnapFileNames2;
|
|
20
|
+
})(NpmSnapFileNames || {});
|
|
21
|
+
var NameStruct = _superstruct.size.call(void 0,
|
|
22
|
+
_superstruct.pattern.call(void 0,
|
|
23
|
+
_superstruct.string.call(void 0, ),
|
|
24
|
+
/^(?:@[a-z0-9-*~][a-z0-9-*._~]*\/)?[a-z0-9-~][a-z0-9-._~]*$/u
|
|
25
|
+
),
|
|
26
|
+
1,
|
|
27
|
+
214
|
|
28
|
+
);
|
|
29
|
+
var NpmSnapPackageJsonStruct = _superstruct.type.call(void 0, {
|
|
30
|
+
version: _utils.VersionStruct,
|
|
31
|
+
name: NameStruct,
|
|
32
|
+
main: _superstruct.optional.call(void 0, _superstruct.size.call(void 0, _superstruct.string.call(void 0, ), 1, Infinity)),
|
|
33
|
+
repository: _superstruct.optional.call(void 0,
|
|
34
|
+
_superstruct.object.call(void 0, {
|
|
35
|
+
type: _superstruct.size.call(void 0, _superstruct.string.call(void 0, ), 1, Infinity),
|
|
36
|
+
url: _superstruct.size.call(void 0, _superstruct.string.call(void 0, ), 1, Infinity)
|
|
37
|
+
})
|
|
38
|
+
)
|
|
39
|
+
});
|
|
40
|
+
function isNpmSnapPackageJson(value) {
|
|
41
|
+
return _superstruct.is.call(void 0, value, NpmSnapPackageJsonStruct);
|
|
42
|
+
}
|
|
43
|
+
function assertIsNpmSnapPackageJson(value) {
|
|
44
|
+
_utils.assertStruct.call(void 0,
|
|
45
|
+
value,
|
|
46
|
+
NpmSnapPackageJsonStruct,
|
|
47
|
+
`"${"package.json" /* PackageJson */}" is invalid`
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
var SnapIdPrefixes = /* @__PURE__ */ ((SnapIdPrefixes2) => {
|
|
51
|
+
SnapIdPrefixes2["npm"] = "npm:";
|
|
52
|
+
SnapIdPrefixes2["local"] = "local:";
|
|
53
|
+
return SnapIdPrefixes2;
|
|
54
|
+
})(SnapIdPrefixes || {});
|
|
55
|
+
var SnapValidationFailureReason = /* @__PURE__ */ ((SnapValidationFailureReason2) => {
|
|
56
|
+
SnapValidationFailureReason2["NameMismatch"] = '"name" field mismatch';
|
|
57
|
+
SnapValidationFailureReason2["VersionMismatch"] = '"version" field mismatch';
|
|
58
|
+
SnapValidationFailureReason2["RepositoryMismatch"] = '"repository" field mismatch';
|
|
59
|
+
SnapValidationFailureReason2["ShasumMismatch"] = '"shasum" field mismatch';
|
|
60
|
+
return SnapValidationFailureReason2;
|
|
61
|
+
})(SnapValidationFailureReason || {});
|
|
62
|
+
var SNAP_STREAM_NAMES = /* @__PURE__ */ ((SNAP_STREAM_NAMES2) => {
|
|
63
|
+
SNAP_STREAM_NAMES2["JSON_RPC"] = "jsonRpc";
|
|
64
|
+
SNAP_STREAM_NAMES2["COMMAND"] = "command";
|
|
65
|
+
return SNAP_STREAM_NAMES2;
|
|
66
|
+
})(SNAP_STREAM_NAMES || {});
|
|
67
|
+
var uri = (opts = {}) => _superstruct.refine.call(void 0, _superstruct.union.call(void 0, [_superstruct.string.call(void 0, ), _superstruct.instance.call(void 0, URL)]), "uri", (value) => {
|
|
68
|
+
try {
|
|
69
|
+
const url = new URL(value);
|
|
70
|
+
const UrlStruct = _superstruct.type.call(void 0, opts);
|
|
71
|
+
_superstruct.assert.call(void 0, url, UrlStruct);
|
|
72
|
+
return true;
|
|
73
|
+
} catch {
|
|
74
|
+
return `Expected URL, got "${value.toString()}".`;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
function isValidUrl(url, opts = {}) {
|
|
78
|
+
return _superstruct.is.call(void 0, url, uri(opts));
|
|
79
|
+
}
|
|
80
|
+
var WALLET_SNAP_PERMISSION_KEY = "wallet_snap";
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
exports.NpmSnapFileNames = NpmSnapFileNames; exports.NameStruct = NameStruct; exports.NpmSnapPackageJsonStruct = NpmSnapPackageJsonStruct; exports.isNpmSnapPackageJson = isNpmSnapPackageJson; exports.assertIsNpmSnapPackageJson = assertIsNpmSnapPackageJson; exports.SnapIdPrefixes = SnapIdPrefixes; exports.SnapValidationFailureReason = SnapValidationFailureReason; exports.SNAP_STREAM_NAMES = SNAP_STREAM_NAMES; exports.uri = uri; exports.isValidUrl = isValidUrl; exports.WALLET_SNAP_PERMISSION_KEY = WALLET_SNAP_PERMISSION_KEY;
|
|
95
|
+
//# sourceMappingURL=chunk-CMOSYNZR.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"names":["NpmSnapFileNames","SnapIdPrefixes","SnapValidationFailureReason","SNAP_STREAM_NAMES"],"mappings":";AACA,SAAS,cAAc,qBAAqB;AAE5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,OACL;AAQA,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,iBAAc;AACd,EAAAA,kBAAA,cAAW;AAFD,SAAAA;AAAA,GAAA;AAKL,IAAM,aAAa;AAAA,EACxB;AAAA,IACE,OAAO;AAAA,IACP;AAAA,EACF;AAAA,EACA;AAAA,EACA;AACF;AAIO,IAAM,2BAA2B,KAAK;AAAA,EAC3C,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM,SAAS,KAAK,OAAO,GAAG,GAAG,QAAQ,CAAC;AAAA,EAC1C,YAAY;AAAA,IACV,OAAO;AAAA,MACL,MAAM,KAAK,OAAO,GAAG,GAAG,QAAQ;AAAA,MAChC,KAAK,KAAK,OAAO,GAAG,GAAG,QAAQ;AAAA,IACjC,CAAC;AAAA,EACH;AACF,CAAC;AAWM,SAAS,qBACd,OAC6B;AAC7B,SAAO,GAAG,OAAO,wBAAwB;AAC3C;AAQO,SAAS,2BACd,OACqC;AACrC;AAAA,IACE;AAAA,IACA;AAAA,IACA,IAAI,gCAA4B;AAAA,EAClC;AACF;AAuCO,IAAK,iBAAL,kBAAKC,oBAAL;AACL,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AAUL,IAAK,8BAAL,kBAAKC,iCAAL;AACL,EAAAA,6BAAA,kBAAe;AACf,EAAAA,6BAAA,qBAAkB;AAClB,EAAAA,6BAAA,wBAAqB;AACrB,EAAAA,6BAAA,oBAAiB;AAJP,SAAAA;AAAA,GAAA;AAQL,IAAK,oBAAL,kBAAKC,uBAAL;AACL,EAAAA,mBAAA,cAAW;AACX,EAAAA,mBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;AAwBL,IAAM,MAAM,CAAC,OAAwB,CAAC,MAC3C,OAAO,MAAM,CAAC,OAAO,GAAG,SAAS,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU;AACzD,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,KAAK;AAEzB,UAAM,YAAY,KAAK,IAAI;AAC3B,sBAAkB,KAAK,SAAS;AAChC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO,sBAAsB,MAAM,SAAS,CAAC;AAAA,EAC/C;AACF,CAAC;AASI,SAAS,WACd,KACA,OAAwB,CAAC,GACJ;AACrB,SAAO,GAAG,KAAK,IAAI,IAAI,CAAC;AAC1B;AAGO,IAAM,6BAA6B","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { assertStruct, VersionStruct } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n type,\n union,\n assert as assertSuperstruct,\n} from 'superstruct';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n pattern(\n string(),\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * Check if the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link NpmSnapPackageJson} object.\n */\nexport function isNpmSnapPackageJson(\n value: unknown,\n): value is NpmSnapPackageJson {\n return is(value, NpmSnapPackageJsonStruct);\n}\n\n/**\n * Asserts that the given value is a valid {@link NpmSnapPackageJson} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link NpmSnapPackageJson} object.\n */\nexport function assertIsNpmSnapPackageJson(\n value: unknown,\n): asserts value is NpmSnapPackageJson {\n assertStruct(\n value,\n NpmSnapPackageJsonStruct,\n `\"${NpmSnapFileNames.PackageJson}\" is invalid`,\n );\n}\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/**\n * Snap validation failure reason codes that are programmatically fixable\n * if validation occurs during development.\n */\nexport enum SnapValidationFailureReason {\n NameMismatch = '\"name\" field mismatch',\n VersionMismatch = '\"version\" field mismatch',\n RepositoryMismatch = '\"repository\" field mismatch',\n ShasumMismatch = '\"shasum\" field mismatch',\n}\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(union([string(), instance(URL)]), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch {\n return `Expected URL, got \"${value.toString()}\".`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string | URL {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"]}
|