@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
|
+
import {
|
|
2
|
+
indent
|
|
3
|
+
} from "./chunk-IV3FSWZ7.mjs";
|
|
4
|
+
|
|
5
|
+
// src/structs.ts
|
|
6
|
+
import { union } from "@metamask/snaps-sdk";
|
|
7
|
+
import { assert, isObject } from "@metamask/utils";
|
|
8
|
+
import { bold, green, red } from "chalk";
|
|
9
|
+
import {
|
|
10
|
+
is,
|
|
11
|
+
validate,
|
|
12
|
+
type as superstructType,
|
|
13
|
+
Struct,
|
|
14
|
+
StructError,
|
|
15
|
+
create
|
|
16
|
+
} from "superstruct";
|
|
17
|
+
function color(value, colorFunction, enabled) {
|
|
18
|
+
if (enabled) {
|
|
19
|
+
return colorFunction(value);
|
|
20
|
+
}
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
function named(name, struct) {
|
|
24
|
+
return new Struct({
|
|
25
|
+
...struct,
|
|
26
|
+
type: name
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
var SnapsStructError = class extends StructError {
|
|
30
|
+
constructor(struct, prefix, suffix, failure, failures, colorize = true) {
|
|
31
|
+
super(failure, failures);
|
|
32
|
+
this.name = "SnapsStructError";
|
|
33
|
+
this.message = `${prefix}.
|
|
34
|
+
|
|
35
|
+
${getStructErrorMessage(
|
|
36
|
+
struct,
|
|
37
|
+
[...failures()],
|
|
38
|
+
colorize
|
|
39
|
+
)}${suffix ? `
|
|
40
|
+
|
|
41
|
+
${suffix}` : ""}`;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
function* arrayToGenerator(array) {
|
|
45
|
+
for (const item of array) {
|
|
46
|
+
yield item;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
function getError({
|
|
50
|
+
struct,
|
|
51
|
+
prefix,
|
|
52
|
+
suffix = "",
|
|
53
|
+
error,
|
|
54
|
+
colorize
|
|
55
|
+
}) {
|
|
56
|
+
return new SnapsStructError(
|
|
57
|
+
struct,
|
|
58
|
+
prefix,
|
|
59
|
+
suffix,
|
|
60
|
+
error,
|
|
61
|
+
() => arrayToGenerator(error.failures()),
|
|
62
|
+
colorize
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
function createFromStruct(value, struct, prefix, suffix = "") {
|
|
66
|
+
try {
|
|
67
|
+
return create(value, struct);
|
|
68
|
+
} catch (error) {
|
|
69
|
+
if (error instanceof StructError) {
|
|
70
|
+
throw getError({ struct, prefix, suffix, error });
|
|
71
|
+
}
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function getStructFromPath(struct, path) {
|
|
76
|
+
return path.reduce((result, key) => {
|
|
77
|
+
if (isObject(struct.schema) && struct.schema[key]) {
|
|
78
|
+
return struct.schema[key];
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}, struct);
|
|
82
|
+
}
|
|
83
|
+
function getUnionStructNames(struct, colorize = true) {
|
|
84
|
+
if (Array.isArray(struct.schema)) {
|
|
85
|
+
return struct.schema.map(({ type }) => color(type, green, colorize));
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
function getStructErrorPrefix(failure, colorize = true) {
|
|
90
|
+
if (failure.type === "never" || failure.path.length === 0) {
|
|
91
|
+
return "";
|
|
92
|
+
}
|
|
93
|
+
return `At path: ${color(failure.path.join("."), bold, colorize)} \u2014 `;
|
|
94
|
+
}
|
|
95
|
+
function getStructFailureMessage(struct, failure, colorize = true) {
|
|
96
|
+
const received = color(JSON.stringify(failure.value), red, colorize);
|
|
97
|
+
const prefix = getStructErrorPrefix(failure, colorize);
|
|
98
|
+
if (failure.type === "union") {
|
|
99
|
+
const childStruct = getStructFromPath(struct, failure.path);
|
|
100
|
+
const unionNames = getUnionStructNames(childStruct, colorize);
|
|
101
|
+
if (unionNames) {
|
|
102
|
+
return `${prefix}Expected the value to be one of: ${unionNames.join(
|
|
103
|
+
", "
|
|
104
|
+
)}, but received: ${received}.`;
|
|
105
|
+
}
|
|
106
|
+
return `${prefix}${failure.message}.`;
|
|
107
|
+
}
|
|
108
|
+
if (failure.type === "literal") {
|
|
109
|
+
const message = failure.message.replace(
|
|
110
|
+
/the literal `(.+)`,/u,
|
|
111
|
+
`the value to be \`${color("$1", green, colorize)}\`,`
|
|
112
|
+
).replace(
|
|
113
|
+
/, but received: (.+)/u,
|
|
114
|
+
`, but received: ${color("$1", red, colorize)}`
|
|
115
|
+
);
|
|
116
|
+
return `${prefix}${message}.`;
|
|
117
|
+
}
|
|
118
|
+
if (failure.type === "never") {
|
|
119
|
+
return `Unknown key: ${color(
|
|
120
|
+
failure.path.join("."),
|
|
121
|
+
bold,
|
|
122
|
+
colorize
|
|
123
|
+
)}, received: ${received}.`;
|
|
124
|
+
}
|
|
125
|
+
if (failure.refinement === "size") {
|
|
126
|
+
const message = failure.message.replace(
|
|
127
|
+
/length between `(\d+)` and `(\d+)`/u,
|
|
128
|
+
`length between ${color("$1", green, colorize)} and ${color(
|
|
129
|
+
"$2",
|
|
130
|
+
green,
|
|
131
|
+
colorize
|
|
132
|
+
)},`
|
|
133
|
+
).replace(/length of `(\d+)`/u, `length of ${color("$1", red, colorize)}`).replace(/a array/u, "an array");
|
|
134
|
+
return `${prefix}${message}.`;
|
|
135
|
+
}
|
|
136
|
+
return `${prefix}Expected a value of type ${color(
|
|
137
|
+
failure.type,
|
|
138
|
+
green,
|
|
139
|
+
colorize
|
|
140
|
+
)}, but received: ${received}.`;
|
|
141
|
+
}
|
|
142
|
+
function getStructErrorMessage(struct, failures, colorize = true) {
|
|
143
|
+
const formattedFailures = failures.map(
|
|
144
|
+
(failure) => indent(`\u2022 ${getStructFailureMessage(struct, failure, colorize)}`)
|
|
145
|
+
);
|
|
146
|
+
return formattedFailures.join("\n");
|
|
147
|
+
}
|
|
148
|
+
function validateUnion(value, struct, structKey, coerce = false) {
|
|
149
|
+
assert(
|
|
150
|
+
struct.schema,
|
|
151
|
+
"Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`."
|
|
152
|
+
);
|
|
153
|
+
assert(struct.schema.length > 0, "Expected a non-empty array of structs.");
|
|
154
|
+
const keyUnion = struct.schema.map(
|
|
155
|
+
(innerStruct) => innerStruct.schema[structKey]
|
|
156
|
+
// This is guaranteed to be a non-empty array by the assertion above. We
|
|
157
|
+
// need to cast it since `superstruct` requires a non-empty array of structs
|
|
158
|
+
// for the `union` struct.
|
|
159
|
+
);
|
|
160
|
+
const key = superstructType({
|
|
161
|
+
[structKey]: union(keyUnion)
|
|
162
|
+
});
|
|
163
|
+
const [keyError] = validate(value, key, { coerce });
|
|
164
|
+
if (keyError) {
|
|
165
|
+
throw new Error(
|
|
166
|
+
getStructFailureMessage(key, keyError.failures()[0], false)
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
const objectValue = value;
|
|
170
|
+
const objectStructs = struct.schema.filter(
|
|
171
|
+
(innerStruct) => is(objectValue[structKey], innerStruct.schema[structKey])
|
|
172
|
+
);
|
|
173
|
+
assert(objectStructs.length > 0, "Expected a struct to match the value.");
|
|
174
|
+
const validationResults = objectStructs.map(
|
|
175
|
+
(objectStruct) => validate(objectValue, objectStruct, { coerce })
|
|
176
|
+
);
|
|
177
|
+
const validatedValue = validationResults.find(([error]) => !error);
|
|
178
|
+
if (validatedValue) {
|
|
179
|
+
return validatedValue[1];
|
|
180
|
+
}
|
|
181
|
+
assert(validationResults[0][0], "Expected at least one error.");
|
|
182
|
+
const validationError = validationResults.reduce((error, [innerError]) => {
|
|
183
|
+
assert(innerError, "Expected an error.");
|
|
184
|
+
if (innerError.failures().length < error.failures().length) {
|
|
185
|
+
return innerError;
|
|
186
|
+
}
|
|
187
|
+
return error;
|
|
188
|
+
}, validationResults[0][0]);
|
|
189
|
+
throw new Error(
|
|
190
|
+
getStructFailureMessage(struct, validationError.failures()[0], false)
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
function createUnion(value, struct, structKey) {
|
|
194
|
+
return validateUnion(value, struct, structKey, true);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export {
|
|
198
|
+
named,
|
|
199
|
+
SnapsStructError,
|
|
200
|
+
arrayToGenerator,
|
|
201
|
+
getError,
|
|
202
|
+
createFromStruct,
|
|
203
|
+
getStructFromPath,
|
|
204
|
+
getUnionStructNames,
|
|
205
|
+
getStructErrorPrefix,
|
|
206
|
+
getStructFailureMessage,
|
|
207
|
+
getStructErrorMessage,
|
|
208
|
+
validateUnion,
|
|
209
|
+
createUnion
|
|
210
|
+
};
|
|
211
|
+
//# sourceMappingURL=chunk-GTAYOKI4.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/structs.ts"],"sourcesContent":["import { union } from '@metamask/snaps-sdk';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assert, isObject } from '@metamask/utils';\nimport { bold, green, red } from 'chalk';\nimport type { Failure } from 'superstruct';\nimport {\n is,\n validate,\n type as superstructType,\n Struct,\n StructError,\n create,\n} from 'superstruct';\nimport type { AnyStruct } from 'superstruct/dist/utils';\n\nimport { indent } from './strings';\n\n/**\n * Infer a struct type, only if it matches the specified type. This is useful\n * for defining types and structs that are related to each other in separate\n * files.\n *\n * @example\n * ```typescript\n * // In file A\n * export type GetFileArgs = {\n * path: string;\n * encoding?: EnumToUnion<AuxiliaryFileEncoding>;\n * };\n *\n * // In file B\n * export const GetFileArgsStruct = object(...);\n *\n * // If the type and struct are in the same file, this will return the type.\n * // Otherwise, it will return `never`.\n * export type GetFileArgs =\n * InferMatching<typeof GetFileArgsStruct, GetFileArgs>;\n * ```\n */\nexport type InferMatching<\n StructType extends Struct<any, any>,\n Type,\n> = StructType['TYPE'] extends Type ? Type : never;\n\n/**\n * Colorize a value with a color function. This is useful for colorizing values\n * in error messages. If colorization is disabled, the original value is\n * returned.\n *\n * @param value - The value to colorize.\n * @param colorFunction - The color function to use.\n * @param enabled - Whether to colorize the value.\n * @returns The colorized value, or the original value if colorization is\n * disabled.\n */\nfunction color(\n value: string,\n colorFunction: (value: string) => string,\n enabled: boolean,\n) {\n if (enabled) {\n return colorFunction(value);\n }\n\n return value;\n}\n\n/**\n * Define a struct, and also define the name of the struct as the given name.\n *\n * This is useful for improving the error messages returned by `superstruct`.\n *\n * @param name - The name of the struct.\n * @param struct - The struct.\n * @returns The struct.\n */\nexport function named<Type, Schema>(\n name: string,\n struct: Struct<Type, Schema>,\n) {\n return new Struct({\n ...struct,\n type: name,\n });\n}\n\nexport class SnapsStructError<Type, Schema> extends StructError {\n constructor(\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix: string,\n failure: StructError,\n failures: () => Generator<Failure>,\n colorize = true,\n ) {\n super(failure, failures);\n\n this.name = 'SnapsStructError';\n this.message = `${prefix}.\\n\\n${getStructErrorMessage(\n struct,\n [...failures()],\n colorize,\n )}${suffix ? `\\n\\n${suffix}` : ''}`;\n }\n}\n\ntype GetErrorOptions<Type, Schema> = {\n struct: Struct<Type, Schema>;\n prefix: string;\n suffix?: string;\n error: StructError;\n colorize?: boolean;\n};\n\n/**\n * Converts an array to a generator function that yields the items in the\n * array.\n *\n * @param array - The array.\n * @returns A generator function.\n * @yields The items in the array.\n */\nexport function* arrayToGenerator<Type>(\n array: Type[],\n): Generator<Type, void, undefined> {\n for (const item of array) {\n yield item;\n }\n}\n\n/**\n * Returns a `SnapsStructError` with the given prefix and suffix.\n *\n * @param options - The options.\n * @param options.struct - The struct that caused the error.\n * @param options.prefix - The prefix to add to the error message.\n * @param options.suffix - The suffix to add to the error message. Defaults to\n * an empty string.\n * @param options.error - The `superstruct` error to wrap.\n * @param options.colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The `SnapsStructError`.\n */\nexport function getError<Type, Schema>({\n struct,\n prefix,\n suffix = '',\n error,\n colorize,\n}: GetErrorOptions<Type, Schema>) {\n return new SnapsStructError(\n struct,\n prefix,\n suffix,\n error,\n () => arrayToGenerator(error.failures()),\n colorize,\n );\n}\n\n/**\n * A wrapper of `superstruct`'s `create` function that throws a\n * `SnapsStructError` instead of a `StructError`. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` struct to validate the value against.\n * @param prefix - The prefix to add to the error message.\n * @param suffix - The suffix to add to the error message. Defaults to an empty\n * string.\n * @returns The validated value.\n */\nexport function createFromStruct<Type, Schema>(\n value: unknown,\n struct: Struct<Type, Schema>,\n prefix: string,\n suffix = '',\n) {\n try {\n return create(value, struct);\n } catch (error) {\n if (error instanceof StructError) {\n throw getError({ struct, prefix, suffix, error });\n }\n\n throw error;\n }\n}\n\n/**\n * Get a struct from a failure path.\n *\n * @param struct - The struct.\n * @param path - The failure path.\n * @returns The struct at the failure path.\n */\nexport function getStructFromPath<Type, Schema>(\n struct: Struct<Type, Schema>,\n path: string[],\n) {\n return path.reduce<AnyStruct>((result, key) => {\n if (isObject(struct.schema) && struct.schema[key]) {\n return struct.schema[key] as AnyStruct;\n }\n\n return result;\n }, struct);\n}\n\n/**\n * Get the union struct names from a struct.\n *\n * @param struct - The struct.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The union struct names, or `null` if the struct is not a union\n * struct.\n */\nexport function getUnionStructNames<Type, Schema>(\n struct: Struct<Type, Schema>,\n colorize = true,\n) {\n if (Array.isArray(struct.schema)) {\n return struct.schema.map(({ type }) => color(type, green, colorize));\n }\n\n return null;\n}\n\n/**\n * Get an error prefix from a `superstruct` failure. This is useful for\n * formatting the error message returned by `superstruct`.\n *\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns The error prefix.\n */\nexport function getStructErrorPrefix(failure: Failure, colorize = true) {\n if (failure.type === 'never' || failure.path.length === 0) {\n return '';\n }\n\n return `At path: ${color(failure.path.join('.'), bold, colorize)} — `;\n}\n\n/**\n * Get a string describing the failure. This is similar to the `message`\n * property of `superstruct`'s `Failure` type, but formats the value in a more\n * readable way.\n *\n * @param struct - The struct that caused the failure.\n * @param failure - The `superstruct` failure.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the failure.\n */\nexport function getStructFailureMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failure: Failure,\n colorize = true,\n) {\n const received = color(JSON.stringify(failure.value), red, colorize);\n const prefix = getStructErrorPrefix(failure, colorize);\n\n if (failure.type === 'union') {\n const childStruct = getStructFromPath(struct, failure.path);\n const unionNames = getUnionStructNames(childStruct, colorize);\n\n if (unionNames) {\n return `${prefix}Expected the value to be one of: ${unionNames.join(\n ', ',\n )}, but received: ${received}.`;\n }\n\n return `${prefix}${failure.message}.`;\n }\n\n if (failure.type === 'literal') {\n // Superstruct's failure does not provide information about which literal\n // value was expected, so we need to parse the message to get the literal.\n const message = failure.message\n .replace(\n /the literal `(.+)`,/u,\n `the value to be \\`${color('$1', green, colorize)}\\`,`,\n )\n .replace(\n /, but received: (.+)/u,\n `, but received: ${color('$1', red, colorize)}`,\n );\n\n return `${prefix}${message}.`;\n }\n\n if (failure.type === 'never') {\n return `Unknown key: ${color(\n failure.path.join('.'),\n bold,\n colorize,\n )}, received: ${received}.`;\n }\n\n if (failure.refinement === 'size') {\n const message = failure.message\n .replace(\n /length between `(\\d+)` and `(\\d+)`/u,\n `length between ${color('$1', green, colorize)} and ${color(\n '$2',\n green,\n colorize,\n )},`,\n )\n .replace(/length of `(\\d+)`/u, `length of ${color('$1', red, colorize)}`)\n .replace(/a array/u, 'an array');\n\n return `${prefix}${message}.`;\n }\n\n return `${prefix}Expected a value of type ${color(\n failure.type,\n green,\n colorize,\n )}, but received: ${received}.`;\n}\n\n/**\n * Get a string describing the errors. This formats all the errors in a\n * human-readable way.\n *\n * @param struct - The struct that caused the failures.\n * @param failures - The `superstruct` failures.\n * @param colorize - Whether to colorize the value. Defaults to `true`.\n * @returns A string describing the errors.\n */\nexport function getStructErrorMessage<Type, Schema>(\n struct: Struct<Type, Schema>,\n failures: Failure[],\n colorize = true,\n) {\n const formattedFailures = failures.map((failure) =>\n indent(`• ${getStructFailureMessage(struct, failure, colorize)}`),\n );\n\n return formattedFailures.join('\\n');\n}\n\n/**\n * Validate a union struct, and throw readable errors if the value does not\n * satisfy the struct. This is useful for improving the error messages returned\n * by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @param coerce - Whether to coerce the value to satisfy the struct. Defaults\n * to `false`.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @example\n * const struct = union([\n * object({ type: literal('a'), value: string() }),\n * object({ type: literal('b'), value: number() }),\n * object({ type: literal('c'), value: boolean() }),\n * // ...\n * ]);\n *\n * // At path: type — Expected the value to be one of: \"a\", \"b\", \"c\", but received: \"d\".\n * validateUnion({ type: 'd', value: 'foo' }, struct, 'type');\n *\n * // At path: value — Expected a value of type string, but received: 42.\n * validateUnion({ type: 'a', value: 42 }, struct, 'value');\n */\nexport function validateUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n coerce = false,\n) {\n assert(\n struct.schema,\n 'Expected a struct with a schema. Make sure to use `union` from `@metamask/snaps-sdk`.',\n );\n assert(struct.schema.length > 0, 'Expected a non-empty array of structs.');\n\n const keyUnion = struct.schema.map(\n (innerStruct) => innerStruct.schema[structKey],\n // This is guaranteed to be a non-empty array by the assertion above. We\n // need to cast it since `superstruct` requires a non-empty array of structs\n // for the `union` struct.\n ) as NonEmptyArray<Struct>;\n\n const key = superstructType({\n [structKey]: union(keyUnion),\n });\n\n const [keyError] = validate(value, key, { coerce });\n if (keyError) {\n throw new Error(\n getStructFailureMessage(key, keyError.failures()[0], false),\n );\n }\n\n // At this point it's guaranteed that the value is an object, so we can safely\n // cast it to a Record.\n const objectValue = value as Record<PropertyKey, unknown>;\n const objectStructs = struct.schema.filter((innerStruct) =>\n is(objectValue[structKey], innerStruct.schema[structKey]),\n );\n\n assert(objectStructs.length > 0, 'Expected a struct to match the value.');\n\n // We need to validate the value against all the object structs that match the\n // struct key, and return the first validated value.\n const validationResults = objectStructs.map((objectStruct) =>\n validate(objectValue, objectStruct, { coerce }),\n );\n\n const validatedValue = validationResults.find(([error]) => !error);\n if (validatedValue) {\n return validatedValue[1];\n }\n\n assert(validationResults[0][0], 'Expected at least one error.');\n\n // If there is no validated value, we need to find the error with the least\n // number of failures (with the assumption that it's the most specific error).\n const validationError = validationResults.reduce((error, [innerError]) => {\n assert(innerError, 'Expected an error.');\n if (innerError.failures().length < error.failures().length) {\n return innerError;\n }\n\n return error;\n }, validationResults[0][0]);\n\n throw new Error(\n getStructFailureMessage(struct, validationError.failures()[0], false),\n );\n}\n\n/**\n * Create a value with the coercion logic of a union struct, and throw readable\n * errors if the value does not satisfy the struct. This is useful for improving\n * the error messages returned by `superstruct`.\n *\n * @param value - The value to validate.\n * @param struct - The `superstruct` union struct to validate the value against.\n * This struct must be a union of object structs, and must have at least one\n * shared key to validate against.\n * @param structKey - The key to validate against. This key must be present in\n * all the object structs in the union struct, and is expected to be a literal\n * value.\n * @returns The validated value.\n * @throws If the value does not satisfy the struct.\n * @see validateUnion\n */\nexport function createUnion<Type, Schema extends readonly Struct<any, any>[]>(\n value: unknown,\n struct: Struct<Type, Schema>,\n structKey: keyof Type,\n) {\n return validateUnion(value, struct, structKey, true);\n}\n"],"mappings":";;;;;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,M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B;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;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/json.ts
|
|
2
|
+
var _utils = require('@metamask/utils');
|
|
3
|
+
function parseJson(json) {
|
|
4
|
+
return _utils.getSafeJson.call(void 0, JSON.parse(json));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
exports.parseJson = parseJson;
|
|
10
|
+
//# sourceMappingURL=chunk-HF7HUZ5Z.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/json.ts"],"names":[],"mappings":";AACA,SAAS,mBAAmB;AAerB,SAAS,UAAoC,MAAc;AAChE,SAAO,YAAkB,KAAK,MAAM,IAAI,CAAC;AAC3C","sourcesContent":["import type { Json } from '@metamask/utils';\nimport { getSafeJson } from '@metamask/utils';\n\n// TODO: Upstream this to @metamask/utils\n\n/**\n * Parse JSON safely.\n *\n * Does multiple kinds of validation and strips unwanted properties like\n * `__proto__` and `constructor`.\n *\n * @param json - A JSON string to be parsed.\n * @returns The parsed JSON object.\n * @template Type - The type of the JSON object. The type is not actually\n * checked, but it is used to infer the return type.\n */\nexport function parseJson<Type extends Json = Json>(json: string) {\n return getSafeJson<Type>(JSON.parse(json));\n}\n"]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getBytes
|
|
3
|
+
} from "./chunk-6YRUDGNL.mjs";
|
|
4
|
+
|
|
5
|
+
// src/checksum.ts
|
|
6
|
+
import { assert, concatBytes } from "@metamask/utils";
|
|
7
|
+
import { sha256 } from "@noble/hashes/sha256";
|
|
8
|
+
async function checksum(bytes) {
|
|
9
|
+
const value = getBytes(bytes);
|
|
10
|
+
if ("crypto" in globalThis && typeof globalThis.crypto === "object" && crypto.subtle?.digest) {
|
|
11
|
+
return new Uint8Array(await crypto.subtle.digest("SHA-256", value));
|
|
12
|
+
}
|
|
13
|
+
return sha256(value);
|
|
14
|
+
}
|
|
15
|
+
async function checksumFiles(files) {
|
|
16
|
+
const checksums = await Promise.all(
|
|
17
|
+
[...files].sort((a, b) => {
|
|
18
|
+
assert(a.path !== b.path, "Tried to sort files with non-unique paths.");
|
|
19
|
+
if (a.path < b.path) {
|
|
20
|
+
return -1;
|
|
21
|
+
}
|
|
22
|
+
return 1;
|
|
23
|
+
}).map(async (file) => checksum(file))
|
|
24
|
+
);
|
|
25
|
+
return checksum(concatBytes(checksums));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export {
|
|
29
|
+
checksum,
|
|
30
|
+
checksumFiles
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=chunk-HJRCBSNA.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/checksum.ts"],"sourcesContent":["import { assert, concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { getBytes } from './bytes';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Calculates checksum for a single byte array.\n *\n * @param bytes - The byte array to calculate the checksum for.\n * @returns A single sha-256 checksum.\n */\nexport async function checksum(\n bytes: VirtualFile | Uint8Array | string,\n): Promise<Uint8Array> {\n const value = getBytes(bytes);\n // Use crypto.subtle.digest whenever possible as it is faster.\n if (\n 'crypto' in globalThis &&\n typeof globalThis.crypto === 'object' &&\n crypto.subtle?.digest\n ) {\n return new Uint8Array(await crypto.subtle.digest('SHA-256', value));\n }\n return sha256(value);\n}\n\n/**\n * Calculates checksum over multiple files in a reproducible way.\n *\n * 1. Sort all the files by their paths.\n * 2. Calculate sha-256 checksum of each file separately.\n * 3. Concatenate all the checksums into one buffer and sha-256 that buffer.\n *\n * The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.\n *\n * @param files - The files over which to calculate the checksum.\n * @returns A single sha-256 checksum.\n */\nexport async function checksumFiles(files: VirtualFile[]) {\n const checksums = await Promise.all(\n [...files]\n .sort((a, b) => {\n assert(a.path !== b.path, 'Tried to sort files with non-unique paths.');\n if (a.path < b.path) {\n return -1;\n }\n return 1;\n })\n .map(async (file) => checksum(file)),\n );\n\n return checksum(concatBytes(checksums));\n}\n"],"mappings":";;;;;AAAA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,cAAc;AAWvB,eAAsB,SACpB,OACqB;AACrB,QAAM,QAAQ,SAAS,KAAK;AAE5B,MACE,YAAY,cACZ,OAAO,WAAW,WAAW,YAC7B,OAAO,QAAQ,QACf;AACA,WAAO,IAAI,WAAW,MAAM,OAAO,OAAO,OAAO,WAAW,KAAK,CAAC;AAAA,EACpE;AACA,SAAO,OAAO,KAAK;AACrB;AAcA,eAAsB,cAAc,OAAsB;AACxD,QAAM,YAAY,MAAM,QAAQ;AAAA,IAC9B,CAAC,GAAG,KAAK,EACN,KAAK,CAAC,GAAG,MAAM;AACd,aAAO,EAAE,SAAS,EAAE,MAAM,4CAA4C;AACtE,UAAI,EAAE,OAAO,EAAE,MAAM;AACnB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT,CAAC,EACA,IAAI,OAAO,SAAS,SAAS,IAAI,CAAC;AAAA,EACvC;AAEA,SAAO,SAAS,YAAY,SAAS,CAAC;AACxC;","names":[]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkNUCLSR2Gjs = require('./chunk-NUCLSR2G.js');
|
|
4
|
+
|
|
5
|
+
// src/virtual-file/VirtualFile.ts
|
|
6
|
+
var _utils = require('@metamask/utils');
|
|
7
|
+
var _base = require('@scure/base');
|
|
8
|
+
var VirtualFile = class _VirtualFile {
|
|
9
|
+
constructor(value) {
|
|
10
|
+
let options;
|
|
11
|
+
if (typeof value === "string" || value instanceof Uint8Array) {
|
|
12
|
+
options = { value };
|
|
13
|
+
} else {
|
|
14
|
+
options = value;
|
|
15
|
+
}
|
|
16
|
+
this.value = options?.value ?? "";
|
|
17
|
+
this.result = options?.result ?? void 0;
|
|
18
|
+
this.data = options?.data ?? {};
|
|
19
|
+
this.path = options?.path ?? "/";
|
|
20
|
+
}
|
|
21
|
+
toString(encoding) {
|
|
22
|
+
if (typeof this.value === "string") {
|
|
23
|
+
_utils.assert.call(void 0, encoding === void 0, "Tried to encode string.");
|
|
24
|
+
return this.value;
|
|
25
|
+
} else if (this.value instanceof Uint8Array && encoding === "hex") {
|
|
26
|
+
return _utils.bytesToHex.call(void 0, this.value);
|
|
27
|
+
} else if (this.value instanceof Uint8Array && encoding === "base64") {
|
|
28
|
+
return _base.base64.encode(this.value);
|
|
29
|
+
}
|
|
30
|
+
const decoder = new TextDecoder(encoding);
|
|
31
|
+
return decoder.decode(this.value);
|
|
32
|
+
}
|
|
33
|
+
clone() {
|
|
34
|
+
const vfile = new _VirtualFile();
|
|
35
|
+
if (typeof this.value === "string") {
|
|
36
|
+
vfile.value = this.value;
|
|
37
|
+
} else {
|
|
38
|
+
vfile.value = this.value.slice(0);
|
|
39
|
+
}
|
|
40
|
+
vfile.result = _chunkNUCLSR2Gjs.deepClone.call(void 0, this.result);
|
|
41
|
+
vfile.data = _chunkNUCLSR2Gjs.deepClone.call(void 0, this.data);
|
|
42
|
+
vfile.path = this.path;
|
|
43
|
+
return vfile;
|
|
44
|
+
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;AAChC,UAAM,OAAO,KAAK;AAClB,WAAO;AAAA,EACT;AACF","sourcesContent":["// TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review\n// TODO(ritave): Streaming vfile contents similar to vinyl maybe?\n// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile\n// similar to unified instead of throwing \"ProgrammaticallyFixableErrors\".\n//\n// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS.\n// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because\n// we're calculating checksums based on original path.\nimport { assert, bytesToHex } from '@metamask/utils';\nimport { base64 } from '@scure/base';\n\nimport { deepClone } from '../deep-clone';\n\n/**\n * This map registers the type of the {@link VirtualFile.data} key of a {@link VirtualFile}.\n *\n * This type can be augmented to register custom `data` types.\n *\n * @example\n * declare module '@metamask/snaps-utils' {\n * interface DataMap {\n * // `file.data.name` is typed as `string`\n * name: string\n * }\n * }\n */\n// eslint-disable-next-line @typescript-eslint/consistent-type-definitions, @typescript-eslint/no-empty-interface\nexport interface DataMap {}\n\nexport type Value = string | Uint8Array;\nexport type Compatible<Result = unknown> =\n | string\n | Uint8Array\n | Options<Result>;\nexport type Data = Record<string, unknown> & Partial<DataMap>;\nexport type Options<Result = unknown> = {\n value: Value;\n path?: string;\n data?: Data;\n result?: Result;\n};\n\nexport class VirtualFile<Result = unknown> {\n constructor(value?: Compatible<Result>) {\n let options: Options | undefined;\n if (typeof value === 'string' || value instanceof Uint8Array) {\n options = { value };\n } else {\n options = value;\n }\n\n this.value = options?.value ?? '';\n // This situations happens when there's no .result used,\n // we expect the file to have default generic in that situation:\n // VirtualFile<unknown> which will handle undefined properly\n //\n // While not 100% type safe, it'll be way less frustrating to work with.\n // The alternative would be to have VirtualFile.result be Result | undefined\n // and that would result in needing to branch out and check in all situations.\n //\n // In short, optimizing for most common use case.\n this.result = options?.result ?? (undefined as any);\n this.data = options?.data ?? {};\n this.path = options?.path ?? '/';\n }\n\n value: Value;\n\n result: Result;\n\n data: Data;\n\n path: string;\n\n toString(encoding?: string) {\n if (typeof this.value === 'string') {\n assert(encoding === undefined, 'Tried to encode string.');\n return this.value;\n } else if (this.value instanceof Uint8Array && encoding === 'hex') {\n return bytesToHex(this.value);\n } else if (this.value instanceof Uint8Array && encoding === 'base64') {\n // For large files, this is quite slow, instead use `encodeBase64()`\n // TODO: Use @metamask/utils for this\n return base64.encode(this.value);\n }\n const decoder = new TextDecoder(encoding);\n return decoder.decode(this.value);\n }\n\n clone() {\n const vfile = new VirtualFile<Result>();\n if (typeof this.value === 'string') {\n vfile.value = this.value;\n } else {\n // deep-clone doesn't clone Buffer properly, even if it's a sub-class of Uint8Array\n vfile.value = this.value.slice(0);\n }\n vfile.result = deepClone(this.result);\n vfile.data = deepClone(this.data);\n vfile.path = this.path;\n return vfile;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-HYF7Q6VY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
// src/handlers.ts
|
|
2
|
+
import { SeverityLevel, ComponentStruct } from "@metamask/snaps-sdk";
|
|
3
|
+
import {
|
|
4
|
+
assign,
|
|
5
|
+
literal,
|
|
6
|
+
nullable,
|
|
7
|
+
object,
|
|
8
|
+
optional,
|
|
9
|
+
string,
|
|
10
|
+
array,
|
|
11
|
+
size,
|
|
12
|
+
union
|
|
13
|
+
} from "superstruct";
|
|
14
|
+
var SNAP_EXPORTS = {
|
|
15
|
+
["onRpcRequest" /* OnRpcRequest */]: {
|
|
16
|
+
type: "onRpcRequest" /* OnRpcRequest */,
|
|
17
|
+
required: true,
|
|
18
|
+
validator: (snapExport) => {
|
|
19
|
+
return typeof snapExport === "function";
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
["onTransaction" /* OnTransaction */]: {
|
|
23
|
+
type: "onTransaction" /* OnTransaction */,
|
|
24
|
+
required: true,
|
|
25
|
+
validator: (snapExport) => {
|
|
26
|
+
return typeof snapExport === "function";
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
["onCronjob" /* OnCronjob */]: {
|
|
30
|
+
type: "onCronjob" /* OnCronjob */,
|
|
31
|
+
required: true,
|
|
32
|
+
validator: (snapExport) => {
|
|
33
|
+
return typeof snapExport === "function";
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
["onNameLookup" /* OnNameLookup */]: {
|
|
37
|
+
type: "onNameLookup" /* OnNameLookup */,
|
|
38
|
+
required: true,
|
|
39
|
+
validator: (snapExport) => {
|
|
40
|
+
return typeof snapExport === "function";
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
["onInstall" /* OnInstall */]: {
|
|
44
|
+
type: "onInstall" /* OnInstall */,
|
|
45
|
+
required: false,
|
|
46
|
+
validator: (snapExport) => {
|
|
47
|
+
return typeof snapExport === "function";
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
["onUpdate" /* OnUpdate */]: {
|
|
51
|
+
type: "onUpdate" /* OnUpdate */,
|
|
52
|
+
required: false,
|
|
53
|
+
validator: (snapExport) => {
|
|
54
|
+
return typeof snapExport === "function";
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
["onKeyringRequest" /* OnKeyringRequest */]: {
|
|
58
|
+
type: "onKeyringRequest" /* OnKeyringRequest */,
|
|
59
|
+
required: true,
|
|
60
|
+
validator: (snapExport) => {
|
|
61
|
+
return typeof snapExport === "function";
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
["onHomePage" /* OnHomePage */]: {
|
|
65
|
+
type: "onHomePage" /* OnHomePage */,
|
|
66
|
+
required: true,
|
|
67
|
+
validator: (snapExport) => {
|
|
68
|
+
return typeof snapExport === "function";
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
["onSignature" /* OnSignature */]: {
|
|
72
|
+
type: "onSignature" /* OnSignature */,
|
|
73
|
+
required: true,
|
|
74
|
+
validator: (snapExport) => {
|
|
75
|
+
return typeof snapExport === "function";
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
["onUserInput" /* OnUserInput */]: {
|
|
79
|
+
type: "onUserInput" /* OnUserInput */,
|
|
80
|
+
required: true,
|
|
81
|
+
validator: (snapExport) => {
|
|
82
|
+
return typeof snapExport === "function";
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var OnTransactionSeverityResponseStruct = object({
|
|
87
|
+
severity: optional(literal(SeverityLevel.Critical))
|
|
88
|
+
});
|
|
89
|
+
var OnTransactionResponseWithIdStruct = assign(
|
|
90
|
+
OnTransactionSeverityResponseStruct,
|
|
91
|
+
object({
|
|
92
|
+
id: string()
|
|
93
|
+
})
|
|
94
|
+
);
|
|
95
|
+
var OnTransactionResponseWithContentStruct = assign(
|
|
96
|
+
OnTransactionSeverityResponseStruct,
|
|
97
|
+
object({
|
|
98
|
+
content: ComponentStruct
|
|
99
|
+
})
|
|
100
|
+
);
|
|
101
|
+
var OnTransactionResponseStruct = nullable(
|
|
102
|
+
union([
|
|
103
|
+
OnTransactionResponseWithContentStruct,
|
|
104
|
+
OnTransactionResponseWithIdStruct
|
|
105
|
+
])
|
|
106
|
+
);
|
|
107
|
+
var OnSignatureResponseStruct = OnTransactionResponseStruct;
|
|
108
|
+
var OnHomePageResponseWithContentStruct = object({
|
|
109
|
+
content: ComponentStruct
|
|
110
|
+
});
|
|
111
|
+
var OnHomePageResponseWithIdStruct = object({
|
|
112
|
+
id: string()
|
|
113
|
+
});
|
|
114
|
+
var OnHomePageResponseStruct = union([
|
|
115
|
+
OnHomePageResponseWithContentStruct,
|
|
116
|
+
OnHomePageResponseWithIdStruct
|
|
117
|
+
]);
|
|
118
|
+
var AddressResolutionStruct = object({
|
|
119
|
+
protocol: string(),
|
|
120
|
+
resolvedDomain: string()
|
|
121
|
+
});
|
|
122
|
+
var DomainResolutionStruct = object({
|
|
123
|
+
protocol: string(),
|
|
124
|
+
resolvedAddress: string()
|
|
125
|
+
});
|
|
126
|
+
var AddressResolutionResponseStruct = object({
|
|
127
|
+
resolvedDomains: size(array(AddressResolutionStruct), 1, Infinity)
|
|
128
|
+
});
|
|
129
|
+
var DomainResolutionResponseStruct = object({
|
|
130
|
+
resolvedAddresses: size(array(DomainResolutionStruct), 1, Infinity)
|
|
131
|
+
});
|
|
132
|
+
var OnNameLookupResponseStruct = nullable(
|
|
133
|
+
union([AddressResolutionResponseStruct, DomainResolutionResponseStruct])
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
export {
|
|
137
|
+
SNAP_EXPORTS,
|
|
138
|
+
OnTransactionSeverityResponseStruct,
|
|
139
|
+
OnTransactionResponseWithIdStruct,
|
|
140
|
+
OnTransactionResponseWithContentStruct,
|
|
141
|
+
OnTransactionResponseStruct,
|
|
142
|
+
OnSignatureResponseStruct,
|
|
143
|
+
OnHomePageResponseWithContentStruct,
|
|
144
|
+
OnHomePageResponseWithIdStruct,
|
|
145
|
+
OnHomePageResponseStruct,
|
|
146
|
+
AddressResolutionStruct,
|
|
147
|
+
DomainResolutionStruct,
|
|
148
|
+
AddressResolutionResponseStruct,
|
|
149
|
+
DomainResolutionResponseStruct,
|
|
150
|
+
OnNameLookupResponseStruct
|
|
151
|
+
};
|
|
152
|
+
//# sourceMappingURL=chunk-I77AVJKV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/handlers.ts"],"sourcesContent":["import type {\n OnCronjobHandler,\n OnHomePageHandler,\n OnInstallHandler,\n OnKeyringRequestHandler,\n OnNameLookupHandler,\n OnRpcRequestHandler,\n OnSignatureHandler,\n OnTransactionHandler,\n OnUpdateHandler,\n OnUserInputHandler,\n} from '@metamask/snaps-sdk';\nimport { SeverityLevel, ComponentStruct } from '@metamask/snaps-sdk';\nimport {\n assign,\n literal,\n nullable,\n object,\n optional,\n string,\n array,\n size,\n union,\n} from 'superstruct';\n\nimport type { SnapHandler } from './handler-types';\nimport { HandlerType } from './handler-types';\n\nexport type SnapRpcHookArgs = {\n origin: string;\n handler: HandlerType;\n request: Record<string, unknown>;\n};\n\nexport const SNAP_EXPORTS = {\n [HandlerType.OnRpcRequest]: {\n type: HandlerType.OnRpcRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnRpcRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnTransaction]: {\n type: HandlerType.OnTransaction,\n required: true,\n validator: (snapExport: unknown): snapExport is OnTransactionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnCronjob]: {\n type: HandlerType.OnCronjob,\n required: true,\n validator: (snapExport: unknown): snapExport is OnCronjobHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnNameLookup]: {\n type: HandlerType.OnNameLookup,\n required: true,\n validator: (snapExport: unknown): snapExport is OnNameLookupHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnInstall]: {\n type: HandlerType.OnInstall,\n required: false,\n validator: (snapExport: unknown): snapExport is OnInstallHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUpdate]: {\n type: HandlerType.OnUpdate,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUpdateHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnKeyringRequest]: {\n type: HandlerType.OnKeyringRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnKeyringRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnHomePage]: {\n type: HandlerType.OnHomePage,\n required: true,\n validator: (snapExport: unknown): snapExport is OnHomePageHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnSignature]: {\n type: HandlerType.OnSignature,\n required: true,\n validator: (snapExport: unknown): snapExport is OnSignatureHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUserInput]: {\n type: HandlerType.OnUserInput,\n required: true,\n validator: (snapExport: unknown): snapExport is OnUserInputHandler => {\n return typeof snapExport === 'function';\n },\n },\n} as const;\n\nexport const OnTransactionSeverityResponseStruct = object({\n severity: optional(literal(SeverityLevel.Critical)),\n});\n\nexport const OnTransactionResponseWithIdStruct = assign(\n OnTransactionSeverityResponseStruct,\n object({\n id: string(),\n }),\n);\n\nexport const OnTransactionResponseWithContentStruct = assign(\n OnTransactionSeverityResponseStruct,\n object({\n content: ComponentStruct,\n }),\n);\n\nexport const OnTransactionResponseStruct = nullable(\n union([\n OnTransactionResponseWithContentStruct,\n OnTransactionResponseWithIdStruct,\n ]),\n);\n\nexport const OnSignatureResponseStruct = OnTransactionResponseStruct;\n\nexport const OnHomePageResponseWithContentStruct = object({\n content: ComponentStruct,\n});\n\nexport const OnHomePageResponseWithIdStruct = object({\n id: string(),\n});\n\nexport const OnHomePageResponseStruct = union([\n OnHomePageResponseWithContentStruct,\n OnHomePageResponseWithIdStruct,\n]);\n\nexport const AddressResolutionStruct = object({\n protocol: string(),\n resolvedDomain: string(),\n});\n\nexport const DomainResolutionStruct = object({\n protocol: string(),\n resolvedAddress: string(),\n});\n\nexport const AddressResolutionResponseStruct = object({\n resolvedDomains: size(array(AddressResolutionStruct), 1, Infinity),\n});\n\nexport const DomainResolutionResponseStruct = object({\n resolvedAddresses: size(array(DomainResolutionStruct), 1, Infinity),\n});\n\nexport const OnNameLookupResponseStruct = nullable(\n union([AddressResolutionResponseStruct, DomainResolutionResponseStruct]),\n);\n\n/**\n * Utility type for getting the handler function type from a handler type.\n */\nexport type HandlerFunction<Type extends SnapHandler> =\n Type['validator'] extends (snapExport: unknown) => snapExport is infer Handler\n ? Handler\n : never;\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<\n (typeof SNAP_EXPORTS)[Key]\n >;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports;\n"],"mappings":";AAYA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AC,iCAAiC,8BAA8B,CAAC;AACzE;","names":[]}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import {
|
|
2
|
+
VirtualFile
|
|
3
|
+
} from "./chunk-ZJRWU4AJ.mjs";
|
|
4
|
+
|
|
5
|
+
// src/virtual-file/toVirtualFile.ts
|
|
6
|
+
import { promises as fsPromises } from "fs";
|
|
7
|
+
async function readVirtualFile(path, encoding = null) {
|
|
8
|
+
return new VirtualFile({
|
|
9
|
+
path,
|
|
10
|
+
value: await fsPromises.readFile(path, { encoding })
|
|
11
|
+
});
|
|
12
|
+
}
|
|
13
|
+
async function writeVirtualFile(vfile, options) {
|
|
14
|
+
return fsPromises.writeFile(vfile.path, vfile.value, options);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export {
|
|
18
|
+
readVirtualFile,
|
|
19
|
+
writeVirtualFile
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=chunk-IGMAXVPP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/virtual-file/toVirtualFile.ts"],"sourcesContent":["import { promises as fsPromises } from 'fs';\n\nimport { VirtualFile } from './VirtualFile';\n\n/**\n * Reads a file from filesystem and creates a vfile.\n *\n * @param path - Filesystem path to load the contents from.\n * @param encoding - Optional encoding to pass down to fs.readFile.\n * @returns Promise returning VFile with loaded file contents.\n */\nexport async function readVirtualFile(\n path: string,\n encoding: BufferEncoding | null = null,\n) {\n return new VirtualFile({\n path,\n value: await fsPromises.readFile(path, { encoding }),\n });\n}\n\ntype WriteVFileOptions = Exclude<\n Parameters<(typeof fsPromises)['writeFile']>[2],\n undefined\n>;\n\n/**\n * Writes vfile to filesystem.\n *\n * @param vfile - The vfile to write.\n * @param options - Options to pass down to fs.writeFile.\n */\nexport async function writeVirtualFile(\n vfile: VirtualFile,\n options?: WriteVFileOptions,\n) {\n return fsPromises.writeFile(vfile.path, vfile.value, options);\n}\n"],"mappings":";;;;;AAAA,SAAS,YAAY,kBAAkB;AAWvC,eAAsB,gBACpB,MACA,WAAkC,MAClC;AACA,SAAO,IAAI,YAAY;AAAA,IACrB;AAAA,IACA,OAAO,MAAM,WAAW,SAAS,MAAM,EAAE,SAAS,CAAC;AAAA,EACrD,CAAC;AACH;AAaA,eAAsB,iBACpB,OACA,SACA;AACA,SAAO,WAAW,UAAU,MAAM,MAAM,MAAM,OAAO,OAAO;AAC9D;","names":[]}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk473MIETWjs = require('./chunk-473MIETW.js');
|
|
4
|
+
|
|
5
|
+
// src/base64.ts
|
|
6
|
+
var _utils = require('@metamask/utils');
|
|
7
|
+
async function encodeBase64(input) {
|
|
8
|
+
const bytes = _chunk473MIETWjs.getBytes.call(void 0, input);
|
|
9
|
+
if ("FileReader" in globalThis) {
|
|
10
|
+
return await new Promise((resolve, reject) => {
|
|
11
|
+
const reader = Object.assign(new FileReader(), {
|
|
12
|
+
onload: () => resolve(
|
|
13
|
+
reader.result.replace(
|
|
14
|
+
"data:application/octet-stream;base64,",
|
|
15
|
+
""
|
|
16
|
+
)
|
|
17
|
+
),
|
|
18
|
+
onerror: () => reject(reader.error)
|
|
19
|
+
});
|
|
20
|
+
reader.readAsDataURL(
|
|
21
|
+
new File([bytes], "", { type: "application/octet-stream" })
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
return _utils.bytesToBase64.call(void 0, bytes);
|
|
26
|
+
}
|
|
27
|
+
async function decodeBase64(base64) {
|
|
28
|
+
const response = await fetch(
|
|
29
|
+
`data:application/octet-stream;base64,${base64}`
|
|
30
|
+
);
|
|
31
|
+
return new Uint8Array(await response.arrayBuffer());
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
exports.encodeBase64 = encodeBase64; exports.decodeBase64 = decodeBase64;
|
|
38
|
+
//# sourceMappingURL=chunk-IHQPAJ2B.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/base64.ts"],"names":[],"mappings":";;;;;AAAA,SAAS,qBAAqB;AAW9B,eAAsB,aAAa,OAA0C;AAC3E,QAAM,QAAQ,SAAS,KAAK;AAE5B,MAAI,gBAAgB,YAAY;AAC9B,WAAO,MAAM,IAAI,QAAQ,CAAC,SAAS,WAAW;AAC5C,YAAM,SAAS,OAAO,OAAO,IAAI,WAAW,GAAG;AAAA,QAC7C,QAAQ,MACN;AAAA,UACG,OAAO,OAAkB;AAAA,YACxB;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACF,SAAS,MAAM,OAAO,OAAO,KAAK;AAAA,MACpC,CAAC;AACD,aAAO;AAAA,QACL,IAAI,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAAA,MAC5D;AAAA,IACF,CAAC;AAAA,EACH;AACA,SAAO,cAAc,KAAK;AAC5B;AAQA,eAAsB,aAAa,QAAgB;AACjD,QAAM,WAAW,MAAM;AAAA,IACrB,wCAAwC,MAAM;AAAA,EAChD;AACA,SAAO,IAAI,WAAW,MAAM,SAAS,YAAY,CAAC;AACpD","sourcesContent":["import { bytesToBase64 } from '@metamask/utils';\n\nimport { getBytes } from './bytes';\nimport type { VirtualFile } from './virtual-file';\n\n/**\n * Provides fast, asynchronous base64 encoding.\n *\n * @param input - The input value, assumed to be coercable to bytes.\n * @returns A base64 string.\n */\nexport async function encodeBase64(input: Uint8Array | VirtualFile | string) {\n const bytes = getBytes(input);\n // In the browser, FileReader is much faster than bytesToBase64.\n if ('FileReader' in globalThis) {\n return await new Promise((resolve, reject) => {\n const reader = Object.assign(new FileReader(), {\n onload: () =>\n resolve(\n (reader.result as string).replace(\n 'data:application/octet-stream;base64,',\n '',\n ),\n ),\n onerror: () => reject(reader.error),\n });\n reader.readAsDataURL(\n new File([bytes], '', { type: 'application/octet-stream' }),\n );\n });\n }\n return bytesToBase64(bytes);\n}\n\n/**\n * Provides fast, asynchronous base64 decoding.\n *\n * @param base64 - A base64 string.\n * @returns A Uint8Array of bytes.\n */\nexport async function decodeBase64(base64: string) {\n const response = await fetch(\n `data:application/octet-stream;base64,${base64}`,\n );\n return new Uint8Array(await response.arrayBuffer());\n}\n"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/strings.ts
|
|
2
|
+
function indent(message, spaces = 2) {
|
|
3
|
+
return message.replace(/^/gmu, " ".repeat(spaces));
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
exports.indent = indent;
|
|
9
|
+
//# sourceMappingURL=chunk-IJX3CXOY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/strings.ts"],"names":[],"mappings":";AAOO,SAAS,OAAO,SAAiB,SAAS,GAAG;AAClD,SAAO,QAAQ,QAAQ,QAAQ,IAAI,OAAO,MAAM,CAAC;AACnD","sourcesContent":["/**\n * Indent a message by adding a number of spaces to the beginning of each line.\n *\n * @param message - The message to indent.\n * @param spaces - The number of spaces to indent by. Defaults to 2.\n * @returns The indented message.\n */\nexport function indent(message: string, spaces = 2) {\n return message.replace(/^/gmu, ' '.repeat(spaces));\n}\n"]}
|