@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 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/manifest.ts","../src/npm.ts"],"sourcesContent":["import { getErrorMessage } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assertExhaustive, assert, isPlainObject } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\nimport { promises as fs } from 'fs';\nimport pathUtils from 'path';\n\nimport { deepClone } from '../deep-clone';\nimport { readJsonFile } from '../fs';\nimport { getSvgDimensions } from '../icon';\nimport { validateNpmSnap } from '../npm';\nimport {\n getSnapChecksum,\n ProgrammaticallyFixableSnapError,\n validateSnapShasum,\n} from '../snaps';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport { NpmSnapFileNames, SnapValidationFailureReason } from '../types';\nimport { readVirtualFile, VirtualFile } from '../virtual-file/node';\nimport type { SnapManifest } from './validation';\n\nconst MANIFEST_SORT_ORDER: Record<keyof SnapManifest, number> = {\n $schema: 1,\n version: 2,\n description: 3,\n proposedName: 4,\n repository: 5,\n source: 6,\n initialConnections: 7,\n initialPermissions: 8,\n manifestVersion: 9,\n};\n\n/**\n * The result from the `checkManifest` function.\n *\n * @property manifest - The fixed manifest object.\n * @property updated - Whether the manifest was updated.\n * @property warnings - An array of warnings that were encountered during\n * processing of the manifest files. These warnings are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n * @property errors - An array of errors that were encountered during\n * processing of the manifest files. These errors are not logged to the\n * console automatically, so depending on the environment the function is called\n * in, a different method for logging can be used.\n */\nexport type CheckManifestResult = {\n manifest: SnapManifest;\n updated?: boolean;\n warnings: string[];\n errors: string[];\n};\n\nexport type WriteFileFunction = (path: string, data: string) => Promise<void>;\n\n/**\n * Validates a snap.manifest.json file. Attempts to fix the manifest and write\n * the fixed version to disk if `writeManifest` is true. Throws if validation\n * fails.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param writeManifest - Whether to write the fixed manifest to disk.\n * @param sourceCode - The source code of the Snap.\n * @param writeFileFn - The function to use to write the manifest to disk.\n * @returns Whether the manifest was updated, and an array of warnings that\n * were encountered during processing of the manifest files.\n */\nexport async function checkManifest(\n basePath: string,\n writeManifest = true,\n sourceCode?: string,\n writeFileFn: WriteFileFunction = fs.writeFile,\n): Promise<CheckManifestResult> {\n const warnings: string[] = [];\n const errors: string[] = [];\n\n let updated = false;\n\n const manifestPath = pathUtils.join(basePath, NpmSnapFileNames.Manifest);\n const manifestFile = await readJsonFile(manifestPath);\n const unvalidatedManifest = manifestFile.result;\n\n const packageFile = await readJsonFile(\n pathUtils.join(basePath, NpmSnapFileNames.PackageJson),\n );\n\n const auxiliaryFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.files,\n );\n\n const localizationFilePaths = getSnapFilePaths(\n unvalidatedManifest,\n (manifest) => manifest?.source?.locales,\n );\n\n const snapFiles: UnvalidatedSnapFiles = {\n manifest: manifestFile,\n packageJson: packageFile,\n sourceCode: await getSnapSourceCode(\n basePath,\n unvalidatedManifest,\n sourceCode,\n ),\n svgIcon: await getSnapIcon(basePath, unvalidatedManifest),\n // Intentionally pass null as the encoding here since the files may be binary\n auxiliaryFiles:\n (await getSnapFiles(basePath, auxiliaryFilePaths, null)) ?? [],\n localizationFiles:\n (await getSnapFiles(basePath, localizationFilePaths)) ?? [],\n };\n\n let manifest: VirtualFile<SnapManifest> | undefined;\n try {\n ({ manifest } = await validateNpmSnap(snapFiles));\n } catch (error) {\n if (error instanceof ProgrammaticallyFixableSnapError) {\n errors.push(error.message);\n\n // If we get here, the files at least have the correct shape.\n const partiallyValidatedFiles = snapFiles as SnapFiles;\n\n let isInvalid = true;\n let currentError = error;\n const maxAttempts = Object.keys(SnapValidationFailureReason).length;\n\n // Attempt to fix all fixable validation failure reasons. All such reasons\n // are enumerated by the `SnapValidationFailureReason` enum, so we only\n // attempt to fix the manifest the same amount of times as there are\n // reasons in the enum.\n for (let attempts = 1; isInvalid && attempts <= maxAttempts; attempts++) {\n manifest = await fixManifest(\n manifest\n ? { ...partiallyValidatedFiles, manifest }\n : partiallyValidatedFiles,\n currentError,\n );\n\n try {\n await validateNpmSnapManifest({\n ...partiallyValidatedFiles,\n manifest,\n });\n\n isInvalid = false;\n } catch (nextValidationError) {\n currentError = nextValidationError;\n /* istanbul ignore next: this should be impossible */\n if (\n !(\n nextValidationError instanceof ProgrammaticallyFixableSnapError\n ) ||\n (attempts === maxAttempts && !isInvalid)\n ) {\n throw new Error(\n `Internal error: Failed to fix manifest. This is a bug, please report it. Reason:\\n${error.message}`,\n );\n }\n\n errors.push(currentError.message);\n }\n }\n\n updated = true;\n } else {\n throw error;\n }\n }\n\n // TypeScript assumes `manifest` can still be undefined, that is not the case.\n // But we assert to keep TypeScript happy.\n assert(manifest);\n\n const validatedManifest = manifest.result;\n\n // Check presence of recommended keys\n const recommendedFields = ['repository'] as const;\n\n const missingRecommendedFields = recommendedFields.filter(\n (key) => !validatedManifest[key],\n );\n\n if (missingRecommendedFields.length > 0) {\n warnings.push(\n `Missing recommended package.json properties:\\n${missingRecommendedFields.reduce(\n (allMissing, currentField) => {\n return `${allMissing}\\t${currentField}\\n`;\n },\n '',\n )}`,\n );\n }\n\n if (!snapFiles.svgIcon) {\n warnings.push(\n 'No icon found in the Snap manifest. It is recommended to include an icon for the Snap. See https://docs.metamask.io/snaps/how-to/design-a-snap/#guidelines-at-a-glance for more information.',\n );\n }\n\n const iconDimensions =\n snapFiles.svgIcon && getSvgDimensions(snapFiles.svgIcon.toString());\n if (iconDimensions && iconDimensions.height !== iconDimensions.width) {\n warnings.push(\n 'The icon in the Snap manifest is not square. It is recommended to use a square icon for the Snap.',\n );\n }\n\n if (writeManifest) {\n try {\n const newManifest = `${JSON.stringify(\n getWritableManifest(validatedManifest),\n null,\n 2,\n )}\\n`;\n\n if (updated || newManifest !== manifestFile.value) {\n await writeFileFn(\n pathUtils.join(basePath, NpmSnapFileNames.Manifest),\n newManifest,\n );\n }\n } catch (error) {\n // Note: This error isn't pushed to the errors array, because it's not an\n // error in the manifest itself.\n throw new Error(`Failed to update snap.manifest.json: ${error.message}`);\n }\n }\n\n return { manifest: validatedManifest, updated, warnings, errors };\n}\n\n/**\n * Given the relevant Snap files (manifest, `package.json`, and bundle) and a\n * Snap manifest validation error, fixes the fault in the manifest that caused\n * the error.\n *\n * @param snapFiles - The contents of all Snap files.\n * @param error - The {@link ProgrammaticallyFixableSnapError} that was thrown.\n * @returns A copy of the manifest file where the cause of the error is fixed.\n */\nexport async function fixManifest(\n snapFiles: SnapFiles,\n error: ProgrammaticallyFixableSnapError,\n): Promise<VirtualFile<SnapManifest>> {\n const { manifest, packageJson } = snapFiles;\n const clonedFile = manifest.clone();\n const manifestCopy = clonedFile.result;\n\n switch (error.reason) {\n case SnapValidationFailureReason.NameMismatch:\n manifestCopy.source.location.npm.packageName = packageJson.result.name;\n break;\n\n case SnapValidationFailureReason.VersionMismatch:\n manifestCopy.version = packageJson.result.version;\n break;\n\n case SnapValidationFailureReason.RepositoryMismatch:\n manifestCopy.repository = packageJson.result.repository\n ? deepClone(packageJson.result.repository)\n : undefined;\n break;\n\n case SnapValidationFailureReason.ShasumMismatch:\n manifestCopy.source.shasum = await getSnapChecksum(snapFiles);\n break;\n\n /* istanbul ignore next */\n default:\n assertExhaustive(error.reason);\n }\n\n clonedFile.result = manifestCopy;\n clonedFile.value = JSON.stringify(manifestCopy);\n return clonedFile;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * bundle source file location and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param sourceCode - Override source code for plugins.\n * @returns The contents of the bundle file, if any.\n */\nexport async function getSnapSourceCode(\n basePath: string,\n manifest: Json,\n sourceCode?: string,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const sourceFilePath = (manifest as Partial<SnapManifest>).source?.location\n ?.npm?.filePath;\n\n if (!sourceFilePath) {\n return undefined;\n }\n\n if (sourceCode) {\n return new VirtualFile({\n path: pathUtils.join(basePath, sourceFilePath),\n value: sourceCode,\n });\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, sourceFilePath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(\n `Failed to read snap bundle file: ${getErrorMessage(error)}`,\n );\n }\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the location of the\n * icon and read the file.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param manifest - The unvalidated Snap manifest file contents.\n * @returns The contents of the icon, if any.\n */\nexport async function getSnapIcon(\n basePath: string,\n manifest: Json,\n): Promise<VirtualFile | undefined> {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const iconPath = (manifest as Partial<SnapManifest>).source?.location?.npm\n ?.iconPath;\n\n if (!iconPath) {\n return undefined;\n }\n\n try {\n const virtualFile = await readVirtualFile(\n pathUtils.join(basePath, iconPath),\n 'utf8',\n );\n return virtualFile;\n } catch (error) {\n throw new Error(`Failed to read snap icon file: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Get an array of paths from an unvalidated Snap manifest.\n *\n * @param manifest - The unvalidated Snap manifest file contents.\n * @param selector - A function that returns the paths to the files.\n * @returns The paths to the files, if any.\n */\nexport function getSnapFilePaths(\n manifest: Json,\n selector: (manifest: Partial<SnapManifest>) => string[] | undefined,\n) {\n if (!isPlainObject(manifest)) {\n return undefined;\n }\n\n const snapManifest = manifest as Partial<SnapManifest>;\n const paths = selector(snapManifest);\n\n if (!Array.isArray(paths)) {\n return undefined;\n }\n\n return paths;\n}\n\n/**\n * Given an unvalidated Snap manifest, attempts to extract the files with the\n * given paths and read them.\n *\n * @param basePath - The path to the folder with the manifest files.\n * @param paths - The paths to the files.\n * @param encoding - An optional encoding to pass down to readVirtualFile.\n * @returns A list of auxiliary files and their contents, if any.\n */\nexport async function getSnapFiles(\n basePath: string,\n paths: string[] | undefined,\n encoding: BufferEncoding | null = 'utf8',\n): Promise<VirtualFile[] | undefined> {\n if (!paths) {\n return undefined;\n }\n\n try {\n return await Promise.all(\n paths.map(async (filePath) =>\n readVirtualFile(pathUtils.join(basePath, filePath), encoding),\n ),\n );\n } catch (error) {\n throw new Error(`Failed to read snap files: ${getErrorMessage(error)}`);\n }\n}\n\n/**\n * Sorts the given manifest in our preferred sort order and removes the\n * `repository` field if it is falsy (it may be `null`).\n *\n * @param manifest - The manifest to sort and modify.\n * @returns The disk-ready manifest.\n */\nexport function getWritableManifest(manifest: SnapManifest): SnapManifest {\n const { repository, ...remaining } = manifest;\n\n const keys = Object.keys(\n repository ? { ...remaining, repository } : remaining,\n ) as (keyof SnapManifest)[];\n\n const writableManifest = keys\n .sort((a, b) => MANIFEST_SORT_ORDER[a] - MANIFEST_SORT_ORDER[b])\n .reduce<Partial<SnapManifest>>(\n (result, key) => ({\n ...result,\n [key]: manifest[key],\n }),\n {},\n );\n\n return writableManifest as SnapManifest;\n}\n\n/**\n * Validates the fields of an NPM Snap manifest that has already passed JSON\n * Schema validation.\n *\n * @param snapFiles - The relevant snap files to validate.\n * @param snapFiles.manifest - The npm Snap manifest to validate.\n * @param snapFiles.packageJson - The npm Snap's `package.json`.\n * @param snapFiles.sourceCode - The Snap's source code.\n * @param snapFiles.svgIcon - The Snap's optional icon.\n * @param snapFiles.auxiliaryFiles - Any auxiliary files required by the snap at runtime.\n * @param snapFiles.localizationFiles - The Snap's localization files.\n */\nexport async function validateNpmSnapManifest({\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n}: SnapFiles) {\n const packageJsonName = packageJson.result.name;\n const packageJsonVersion = packageJson.result.version;\n const packageJsonRepository = packageJson.result.repository;\n\n const manifestPackageName = manifest.result.source.location.npm.packageName;\n const manifestPackageVersion = manifest.result.version;\n const manifestRepository = manifest.result.repository;\n\n if (packageJsonName !== manifestPackageName) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package name (\"${manifestPackageName}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"name\" field (\"${packageJsonName}\").`,\n SnapValidationFailureReason.NameMismatch,\n );\n }\n\n if (packageJsonVersion !== manifestPackageVersion) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" npm package version (\"${manifestPackageVersion}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"version\" field (\"${packageJsonVersion}\").`,\n SnapValidationFailureReason.VersionMismatch,\n );\n }\n\n if (\n // The repository may be `undefined` in package.json but can only be defined\n // or `null` in the Snap manifest due to TS@<4.4 issues.\n (packageJsonRepository || manifestRepository) &&\n !deepEqual(packageJsonRepository, manifestRepository)\n ) {\n throw new ProgrammaticallyFixableSnapError(\n `\"${NpmSnapFileNames.Manifest}\" \"repository\" field does not match the \"${NpmSnapFileNames.PackageJson}\" \"repository\" field.`,\n SnapValidationFailureReason.RepositoryMismatch,\n );\n }\n\n await validateSnapShasum(\n { manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles },\n `\"${NpmSnapFileNames.Manifest}\" \"shasum\" field does not match computed shasum.`,\n );\n}\n","import { assertIsSnapIcon } from './icon';\nimport {\n getValidatedLocalizationFiles,\n validateSnapManifestLocalizations,\n} from './localization';\nimport { validateNpmSnapManifest } from './manifest/manifest';\nimport { assertIsSnapManifest } from './manifest/validation';\nimport type { SnapFiles, UnvalidatedSnapFiles } from './types';\nimport { assertIsNpmSnapPackageJson, NpmSnapFileNames } from './types';\n\nexport const EXPECTED_SNAP_FILES = [\n 'manifest',\n 'packageJson',\n 'sourceCode',\n] as const;\n\nexport const SnapFileNameFromKey = {\n manifest: NpmSnapFileNames.Manifest,\n packageJson: NpmSnapFileNames.PackageJson,\n sourceCode: 'source code bundle',\n} as const;\n\n// TODO: Refactor this to be more shared with other validation.\n\n/**\n * Validates the files extracted from an npm Snap package tarball by ensuring\n * that they're non-empty and that the Json files match their respective schemas\n * and the Snaps publishing specification.\n *\n * @param snapFiles - The object containing the expected Snap file contents,\n * if any.\n * @param errorPrefix - The prefix of the error message.\n * @returns A tuple of the Snap manifest object and the Snap source code.\n */\nexport async function validateNpmSnap(\n snapFiles: UnvalidatedSnapFiles,\n errorPrefix?: `${string}: `,\n): Promise<SnapFiles> {\n EXPECTED_SNAP_FILES.forEach((key) => {\n if (!snapFiles[key]) {\n throw new Error(\n `${errorPrefix ?? ''}Missing file \"${SnapFileNameFromKey[key]}\".`,\n );\n }\n });\n\n // Typecast: We are assured that the required files exist if we get here.\n const {\n manifest,\n packageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n } = snapFiles as SnapFiles;\n\n try {\n assertIsSnapManifest(manifest.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n const validatedManifest = manifest;\n\n const { iconPath } = validatedManifest.result.source.location.npm;\n if (iconPath && !svgIcon) {\n throw new Error(`Missing file \"${iconPath}\".`);\n }\n\n try {\n assertIsNpmSnapPackageJson(packageJson.result);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n\n const validatedPackageJson = packageJson;\n await validateNpmSnapManifest({\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n });\n\n if (svgIcon) {\n try {\n assertIsSnapIcon(svgIcon);\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n }\n\n if (localizationFiles) {\n try {\n // This function validates and returns the localization files. We don't\n // use the return value here, but we do want to validate the files.\n getValidatedLocalizationFiles(localizationFiles);\n\n validateSnapManifestLocalizations(\n manifest.result,\n localizationFiles.map((file) => file.result),\n );\n } catch (error) {\n throw new Error(`${errorPrefix ?? ''}${error.message}`);\n }\n }\n\n return {\n manifest: validatedManifest,\n packageJson: validatedPackageJson,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles,\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,uBAAuB;AAEhC,SAAS,kBAAkB,QAAQ,qBAAqB;AACxD,OAAO,eAAe;AACtB,SAAS,YAAY,UAAU;AAC/B,OAAO,eAAe;AAgBtB,IAAM,sBAA0D;AAAA,EAC9D,SAAS;AAAA,EACT,SAAS;AAAA,EACT,aAAa;AAAA,EACb,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,QAAQ;AAAA,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b;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;","names":["manifest"]}
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SnapIdPrefixes,
|
|
3
|
+
uri
|
|
4
|
+
} from "./chunk-T6FWIDA6.mjs";
|
|
5
|
+
import {
|
|
6
|
+
checksumFiles
|
|
7
|
+
} from "./chunk-HJRCBSNA.mjs";
|
|
8
|
+
|
|
9
|
+
// src/snaps.ts
|
|
10
|
+
import { assert, isObject, assertStruct } from "@metamask/utils";
|
|
11
|
+
import { base64 } from "@scure/base";
|
|
12
|
+
import stableStringify from "fast-json-stable-stringify";
|
|
13
|
+
import {
|
|
14
|
+
empty,
|
|
15
|
+
enums,
|
|
16
|
+
intersection,
|
|
17
|
+
literal,
|
|
18
|
+
pattern,
|
|
19
|
+
refine,
|
|
20
|
+
string,
|
|
21
|
+
union,
|
|
22
|
+
validate
|
|
23
|
+
} from "superstruct";
|
|
24
|
+
import validateNPMPackage from "validate-npm-package-name";
|
|
25
|
+
var PROPOSED_NAME_REGEX = /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u;
|
|
26
|
+
var SnapStatus = /* @__PURE__ */ ((SnapStatus2) => {
|
|
27
|
+
SnapStatus2["Installing"] = "installing";
|
|
28
|
+
SnapStatus2["Updating"] = "updating";
|
|
29
|
+
SnapStatus2["Running"] = "running";
|
|
30
|
+
SnapStatus2["Stopped"] = "stopped";
|
|
31
|
+
SnapStatus2["Crashed"] = "crashed";
|
|
32
|
+
return SnapStatus2;
|
|
33
|
+
})(SnapStatus || {});
|
|
34
|
+
var SnapStatusEvents = /* @__PURE__ */ ((SnapStatusEvents2) => {
|
|
35
|
+
SnapStatusEvents2["Start"] = "START";
|
|
36
|
+
SnapStatusEvents2["Stop"] = "STOP";
|
|
37
|
+
SnapStatusEvents2["Crash"] = "CRASH";
|
|
38
|
+
SnapStatusEvents2["Update"] = "UPDATE";
|
|
39
|
+
return SnapStatusEvents2;
|
|
40
|
+
})(SnapStatusEvents || {});
|
|
41
|
+
var ProgrammaticallyFixableSnapError = class extends Error {
|
|
42
|
+
constructor(message, reason) {
|
|
43
|
+
super(message);
|
|
44
|
+
this.reason = reason;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
function getChecksummableManifest(manifest) {
|
|
48
|
+
const manifestCopy = manifest.clone();
|
|
49
|
+
delete manifestCopy.result.source.shasum;
|
|
50
|
+
manifestCopy.value = stableStringify(manifestCopy.result);
|
|
51
|
+
return manifestCopy;
|
|
52
|
+
}
|
|
53
|
+
async function getSnapChecksum(files) {
|
|
54
|
+
const { manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles } = files;
|
|
55
|
+
const all = [
|
|
56
|
+
getChecksummableManifest(manifest),
|
|
57
|
+
sourceCode,
|
|
58
|
+
svgIcon,
|
|
59
|
+
...auxiliaryFiles,
|
|
60
|
+
...localizationFiles
|
|
61
|
+
].filter((file) => file !== void 0);
|
|
62
|
+
return base64.encode(await checksumFiles(all));
|
|
63
|
+
}
|
|
64
|
+
async function validateSnapShasum(files, errorMessage = "Invalid Snap manifest: manifest shasum does not match computed shasum.") {
|
|
65
|
+
if (files.manifest.result.source.shasum !== await getSnapChecksum(files)) {
|
|
66
|
+
throw new ProgrammaticallyFixableSnapError(
|
|
67
|
+
errorMessage,
|
|
68
|
+
'"shasum" field mismatch' /* ShasumMismatch */
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
var LOCALHOST_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]"];
|
|
73
|
+
var BaseSnapIdStruct = pattern(string(), /^[\x21-\x7E]*$/u);
|
|
74
|
+
var LocalSnapIdSubUrlStruct = uri({
|
|
75
|
+
protocol: enums(["http:", "https:"]),
|
|
76
|
+
hostname: enums(LOCALHOST_HOSTNAMES),
|
|
77
|
+
hash: empty(string()),
|
|
78
|
+
search: empty(string())
|
|
79
|
+
});
|
|
80
|
+
var LocalSnapIdStruct = refine(
|
|
81
|
+
BaseSnapIdStruct,
|
|
82
|
+
"local Snap Id",
|
|
83
|
+
(value) => {
|
|
84
|
+
if (!value.startsWith("local:" /* local */)) {
|
|
85
|
+
return `Expected local snap ID, got "${value}".`;
|
|
86
|
+
}
|
|
87
|
+
const [error] = validate(
|
|
88
|
+
value.slice("local:" /* local */.length),
|
|
89
|
+
LocalSnapIdSubUrlStruct
|
|
90
|
+
);
|
|
91
|
+
return error ?? true;
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
var NpmSnapIdStruct = intersection([
|
|
95
|
+
BaseSnapIdStruct,
|
|
96
|
+
uri({
|
|
97
|
+
protocol: literal("npm:" /* npm */),
|
|
98
|
+
pathname: refine(string(), "package name", function* (value) {
|
|
99
|
+
const normalized = value.startsWith("/") ? value.slice(1) : value;
|
|
100
|
+
const { errors, validForNewPackages, warnings } = validateNPMPackage(normalized);
|
|
101
|
+
if (!validForNewPackages) {
|
|
102
|
+
if (errors === void 0) {
|
|
103
|
+
assert(warnings !== void 0);
|
|
104
|
+
yield* warnings;
|
|
105
|
+
} else {
|
|
106
|
+
yield* errors;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
}),
|
|
111
|
+
search: empty(string()),
|
|
112
|
+
hash: empty(string())
|
|
113
|
+
})
|
|
114
|
+
]);
|
|
115
|
+
var HttpSnapIdStruct = intersection([
|
|
116
|
+
BaseSnapIdStruct,
|
|
117
|
+
uri({
|
|
118
|
+
protocol: enums(["http:", "https:"]),
|
|
119
|
+
search: empty(string()),
|
|
120
|
+
hash: empty(string())
|
|
121
|
+
})
|
|
122
|
+
]);
|
|
123
|
+
var SnapIdStruct = union([NpmSnapIdStruct, LocalSnapIdStruct]);
|
|
124
|
+
function getSnapPrefix(snapId) {
|
|
125
|
+
const prefix = Object.values(SnapIdPrefixes).find(
|
|
126
|
+
(possiblePrefix) => snapId.startsWith(possiblePrefix)
|
|
127
|
+
);
|
|
128
|
+
if (prefix !== void 0) {
|
|
129
|
+
return prefix;
|
|
130
|
+
}
|
|
131
|
+
throw new Error(`Invalid or no prefix found for "${snapId}"`);
|
|
132
|
+
}
|
|
133
|
+
function stripSnapPrefix(snapId) {
|
|
134
|
+
return snapId.replace(getSnapPrefix(snapId), "");
|
|
135
|
+
}
|
|
136
|
+
function assertIsValidSnapId(value) {
|
|
137
|
+
assertStruct(value, SnapIdStruct, "Invalid snap ID");
|
|
138
|
+
}
|
|
139
|
+
function isCaipChainId(chainId) {
|
|
140
|
+
return typeof chainId === "string" && /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u.test(
|
|
141
|
+
chainId
|
|
142
|
+
);
|
|
143
|
+
}
|
|
144
|
+
function isSnapPermitted(permissions, snapId) {
|
|
145
|
+
return Boolean(
|
|
146
|
+
(permissions?.wallet_snap?.caveats?.find(
|
|
147
|
+
(caveat) => caveat.type === "snapIds" /* SnapIds */
|
|
148
|
+
) ?? {}).value?.[snapId]
|
|
149
|
+
);
|
|
150
|
+
}
|
|
151
|
+
function verifyRequestedSnapPermissions(requestedPermissions) {
|
|
152
|
+
assert(
|
|
153
|
+
isObject(requestedPermissions),
|
|
154
|
+
"Requested permissions must be an object."
|
|
155
|
+
);
|
|
156
|
+
const { wallet_snap: walletSnapPermission } = requestedPermissions;
|
|
157
|
+
assert(
|
|
158
|
+
isObject(walletSnapPermission),
|
|
159
|
+
"wallet_snap is missing from the requested permissions."
|
|
160
|
+
);
|
|
161
|
+
const { caveats } = walletSnapPermission;
|
|
162
|
+
assert(
|
|
163
|
+
Array.isArray(caveats) && caveats.length === 1,
|
|
164
|
+
"wallet_snap must have a caveat property with a single-item array value."
|
|
165
|
+
);
|
|
166
|
+
const [caveat] = caveats;
|
|
167
|
+
assert(
|
|
168
|
+
isObject(caveat) && caveat.type === "snapIds" /* SnapIds */ && isObject(caveat.value),
|
|
169
|
+
`The requested permissions do not have a valid ${"snapIds" /* SnapIds */} caveat.`
|
|
170
|
+
);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
export {
|
|
174
|
+
PROPOSED_NAME_REGEX,
|
|
175
|
+
SnapStatus,
|
|
176
|
+
SnapStatusEvents,
|
|
177
|
+
ProgrammaticallyFixableSnapError,
|
|
178
|
+
getSnapChecksum,
|
|
179
|
+
validateSnapShasum,
|
|
180
|
+
LOCALHOST_HOSTNAMES,
|
|
181
|
+
BaseSnapIdStruct,
|
|
182
|
+
LocalSnapIdStruct,
|
|
183
|
+
NpmSnapIdStruct,
|
|
184
|
+
HttpSnapIdStruct,
|
|
185
|
+
SnapIdStruct,
|
|
186
|
+
getSnapPrefix,
|
|
187
|
+
stripSnapPrefix,
|
|
188
|
+
assertIsValidSnapId,
|
|
189
|
+
isCaipChainId,
|
|
190
|
+
isSnapPermitted,
|
|
191
|
+
verifyRequestedSnapPermissions
|
|
192
|
+
};
|
|
193
|
+
//# sourceMappingURL=chunk-2IWSQJKQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/snaps.ts"],"sourcesContent":["import type {\n Caveat,\n SubjectPermissions,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport type { BlockReason } from '@metamask/snaps-registry';\nimport type { SnapId, Snap as TruncatedSnap } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assert, isObject, assertStruct } from '@metamask/utils';\nimport { base64 } from '@scure/base';\nimport stableStringify from 'fast-json-stable-stringify';\nimport type { Struct } from 'superstruct';\nimport {\n empty,\n enums,\n intersection,\n literal,\n pattern,\n refine,\n string,\n union,\n validate,\n} from 'superstruct';\nimport validateNPMPackage from 'validate-npm-package-name';\n\nimport { SnapCaveatType } from './caveats';\nimport { checksumFiles } from './checksum';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest, SnapPermissions } from './manifest/validation';\nimport type { FetchedSnapFiles, SnapsPermissionRequest } from './types';\nimport { SnapIdPrefixes, SnapValidationFailureReason, uri } from './types';\nimport type { VirtualFile } from './virtual-file';\n\n// This RegEx matches valid npm package names (with some exceptions) and space-\n// separated alphanumerical words, optionally with dashes and underscores.\n// The RegEx consists of two parts. The first part matches space-separated\n// words. It is based on the following Stackoverflow answer:\n// https://stackoverflow.com/a/34974982\n// The second part, after the pipe operator, is the same RegEx used for the\n// `name` field of the official package.json JSON Schema, except that we allow\n// mixed-case letters. It was originally copied from:\n// https://github.com/SchemaStore/schemastore/blob/81a16897c1dabfd98c72242a5fd62eb080ff76d8/src/schemas/json/package.json#L132-L138\nexport const PROPOSED_NAME_REGEX =\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u;\n\nexport enum SnapStatus {\n Installing = 'installing',\n Updating = 'updating',\n Running = 'running',\n Stopped = 'stopped',\n Crashed = 'crashed',\n}\n\nexport enum SnapStatusEvents {\n Start = 'START',\n Stop = 'STOP',\n Crash = 'CRASH',\n Update = 'UPDATE',\n}\n\nexport type StatusContext = { snapId: SnapId };\nexport type StatusEvents = { type: SnapStatusEvents };\nexport type StatusStates = {\n value: SnapStatus;\n context: StatusContext;\n};\nexport type Status = StatusStates['value'];\n\nexport type VersionHistory = {\n origin: string;\n version: string;\n // Unix timestamp\n date: number;\n};\n\nexport type SnapAuxilaryFile = {\n path: string;\n // Value here should be stored as base64\n value: string;\n};\n\nexport type PersistedSnap = Snap;\n\n/**\n * A Snap as it exists in {@link SnapController} state.\n */\nexport type Snap = TruncatedSnap & {\n /**\n * The initial permissions of the Snap, which will be requested when it is\n * installed.\n */\n initialPermissions: SnapPermissions;\n\n /**\n * The source code of the Snap.\n */\n sourceCode: string;\n\n /**\n * The Snap's manifest file.\n */\n manifest: SnapManifest;\n\n /**\n * Information detailing why the snap is blocked.\n */\n blockInformation?: BlockReason;\n\n /**\n * The current status of the Snap, e.g. whether it's running or stopped.\n */\n status: Status;\n\n /**\n * The version history of the Snap.\n * Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.\n */\n versionHistory: VersionHistory[];\n\n /**\n * Static auxiliary files that can be loaded at runtime.\n */\n auxiliaryFiles?: SnapAuxilaryFile[];\n\n /**\n * Localization files which are used to translate the manifest.\n */\n localizationFiles?: LocalizationFile[];\n\n /**\n * Flag to signal whether this snap was preinstalled or not.\n *\n * A lack of specifying this option will be deemed as not preinstalled.\n */\n preinstalled?: boolean;\n\n /**\n * Flag to signal whether this snap is removable or not.\n *\n * A lack of specifying this option will be deemed as removable.\n */\n removable?: boolean;\n};\n\nexport type TruncatedSnapFields =\n | 'id'\n | 'initialPermissions'\n | 'version'\n | 'enabled'\n | 'blocked';\n\n/**\n * An error indicating that a Snap validation failure is programmatically\n * fixable during development.\n */\nexport class ProgrammaticallyFixableSnapError extends Error {\n reason: SnapValidationFailureReason;\n\n constructor(message: string, reason: SnapValidationFailureReason) {\n super(message);\n this.reason = reason;\n }\n}\n\n/**\n * Gets a checksummable manifest by removing the shasum property and reserializing the JSON using a deterministic algorithm.\n *\n * @param manifest - The manifest itself.\n * @returns A virtual file containing the checksummable manifest.\n */\nfunction getChecksummableManifest(\n manifest: VirtualFile<SnapManifest>,\n): VirtualFile {\n const manifestCopy = manifest.clone() as VirtualFile<any>;\n delete manifestCopy.result.source.shasum;\n\n // We use fast-json-stable-stringify to deterministically serialize the JSON\n // This is required before checksumming so we get reproducible checksums across platforms etc\n manifestCopy.value = stableStringify(manifestCopy.result);\n return manifestCopy;\n}\n\n/**\n * Calculates the Base64-encoded SHA-256 digest of all required Snap files.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @returns The Base64-encoded SHA-256 digest of the source code.\n */\nexport async function getSnapChecksum(\n files: FetchedSnapFiles,\n): Promise<string> {\n const { manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles } =\n files;\n\n const all = [\n getChecksummableManifest(manifest),\n sourceCode,\n svgIcon,\n ...auxiliaryFiles,\n ...localizationFiles,\n ].filter((file) => file !== undefined);\n\n return base64.encode(await checksumFiles(all as VirtualFile[]));\n}\n\n/**\n * Checks whether the `source.shasum` property of a Snap manifest matches the\n * shasum of the snap.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @param errorMessage - The error message to throw if validation fails.\n */\nexport async function validateSnapShasum(\n files: FetchedSnapFiles,\n errorMessage = 'Invalid Snap manifest: manifest shasum does not match computed shasum.',\n): Promise<void> {\n if (files.manifest.result.source.shasum !== (await getSnapChecksum(files))) {\n throw new ProgrammaticallyFixableSnapError(\n errorMessage,\n SnapValidationFailureReason.ShasumMismatch,\n );\n }\n}\n\nexport const LOCALHOST_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]'] as const;\n\n// Require snap ids to only consist of printable ASCII characters\nexport const BaseSnapIdStruct = pattern(string(), /^[\\x21-\\x7E]*$/u);\n\nconst LocalSnapIdSubUrlStruct = uri({\n protocol: enums(['http:', 'https:']),\n hostname: enums(LOCALHOST_HOSTNAMES),\n hash: empty(string()),\n search: empty(string()),\n});\n\nexport const LocalSnapIdStruct = refine(\n BaseSnapIdStruct,\n 'local Snap Id',\n (value) => {\n if (!value.startsWith(SnapIdPrefixes.local)) {\n return `Expected local snap ID, got \"${value}\".`;\n }\n\n const [error] = validate(\n value.slice(SnapIdPrefixes.local.length),\n LocalSnapIdSubUrlStruct,\n );\n return error ?? true;\n },\n);\nexport const NpmSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: literal(SnapIdPrefixes.npm),\n pathname: refine(string(), 'package name', function* (value) {\n const normalized = value.startsWith('/') ? value.slice(1) : value;\n const { errors, validForNewPackages, warnings } =\n validateNPMPackage(normalized);\n if (!validForNewPackages) {\n if (errors === undefined) {\n assert(warnings !== undefined);\n yield* warnings;\n } else {\n yield* errors;\n }\n }\n return true;\n }),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const HttpSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: enums(['http:', 'https:']),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const SnapIdStruct = union([NpmSnapIdStruct, LocalSnapIdStruct]);\n\n/**\n * Extracts the snap prefix from a snap ID.\n *\n * @param snapId - The snap ID to extract the prefix from.\n * @returns The snap prefix from a snap id, e.g. `npm:`.\n */\nexport function getSnapPrefix(snapId: string): SnapIdPrefixes {\n const prefix = Object.values(SnapIdPrefixes).find((possiblePrefix) =>\n snapId.startsWith(possiblePrefix),\n );\n if (prefix !== undefined) {\n return prefix;\n }\n throw new Error(`Invalid or no prefix found for \"${snapId}\"`);\n}\n\n/**\n * Strips snap prefix from a full snap ID.\n *\n * @param snapId - The snap ID to strip.\n * @returns The stripped snap ID.\n */\nexport function stripSnapPrefix(snapId: string): string {\n return snapId.replace(getSnapPrefix(snapId), '');\n}\n\n/**\n * Assert that the given value is a valid snap ID.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid snap ID.\n */\nexport function assertIsValidSnapId(value: unknown): asserts value is SnapId {\n assertStruct(value, SnapIdStruct, 'Invalid snap ID');\n}\n\n/**\n * Typeguard to ensure a chainId follows the CAIP-2 standard.\n *\n * @param chainId - The chainId being tested.\n * @returns `true` if the value is a valid CAIP chain id, and `false` otherwise.\n */\nexport function isCaipChainId(chainId: unknown): chainId is string {\n return (\n typeof chainId === 'string' &&\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u.test(\n chainId,\n )\n );\n}\n\n/**\n * Utility function to check if an origin has permission (and caveat) for a particular snap.\n *\n * @param permissions - An origin's permissions object.\n * @param snapId - The id of the snap.\n * @returns A boolean based on if an origin has the specified snap.\n */\nexport function isSnapPermitted(\n permissions: SubjectPermissions<PermissionConstraint>,\n snapId: SnapId,\n) {\n return Boolean(\n (\n (\n (permissions?.wallet_snap?.caveats?.find(\n (caveat) => caveat.type === SnapCaveatType.SnapIds,\n ) ?? {}) as Caveat<string, Json>\n ).value as Record<string, unknown>\n )?.[snapId],\n );\n}\n\n/**\n * Checks whether the passed in requestedPermissions is a valid\n * permission request for a `wallet_snap` permission.\n *\n * @param requestedPermissions - The requested permissions.\n * @throws If the criteria is not met.\n */\nexport function verifyRequestedSnapPermissions(\n requestedPermissions: unknown,\n): asserts requestedPermissions is SnapsPermissionRequest {\n assert(\n isObject(requestedPermissions),\n 'Requested permissions must be an object.',\n );\n\n const { wallet_snap: walletSnapPermission } = requestedPermissions;\n\n assert(\n isObject(walletSnapPermission),\n 'wallet_snap is missing from the requested permissions.',\n );\n\n const { caveats } = walletSnapPermission;\n\n assert(\n Array.isArray(caveats) && caveats.length === 1,\n 'wallet_snap must have a caveat property with a single-item array value.',\n );\n\n const [caveat] = caveats;\n\n assert(\n isObject(caveat) &&\n caveat.type === SnapCaveatType.SnapIds &&\n isObject(caveat.value),\n `The requested permissions do not have a valid ${SnapCaveatType.SnapIds} caveat.`,\n );\n}\n\nexport type { Snap as TruncatedSnap } from '@metamask/snaps-sdk';\n"],"mappings":";;;;;;;;;AAQA,SAAS,QAAQ,UAAU,oBAAoB;AAC/C,SAAS,cAAc;AACvB,OAAO,qBAAqB;AAE5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,wBAAwB;AAmBxB,IAAM,sBACX;AAEK,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,aAAU;AALA,SAAAA;AAAA,GAAA;AAQL,IAAK,mBAAL,kBAAKC,sBAAL;AACL,EAAAA,kBAAA,WAAQ;AACR,EAAAA,kBAAA,UAAO;AACP,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AAyC;AAC3E,eAAa,OAAO,cAAc,iBAAiB;AACrD;AAQO,SAAS,cAAc,SAAqC;AACjE,SACE,OAAO,YAAY,YACnB,mEAAmE;AAAA,IACjE;AAAA,EACF;AAEJ;AASO,SAAS,gBACd,aACA,QACA;AACA,SAAO;AAAA,KAGA,aAAa,aAAa,SAAS;AAAA,MAClC,CAAC,WAAW,OAAO;AAAA,IACrB,KAAK,CAAC,GACN,QACA,MAAM;AAAA,EACZ;AACF;AASO,SAAS,+BACd,sBACwD;AACxD;AAAA,IACE,SAAS,oBAAoB;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,EAAE,aAAa,qBAAqB,IAAI;AAE9C;AAAA,IACE,SAAS,oBAAoB;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,EAAE,QAAQ,IAAI;AAEpB;AAAA,IACE,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW;AAAA,IAC7C;AAAA,EACF;AAEA,QAAM,CAAC,MAAM,IAAI;AAEjB;AAAA,IACE,SAAS,MAAM,KACb,OAAO,oCACP,SAAS,OAAO,KAAK;AAAA,IACvB,wEAAuE;AAAA,EACzE;AACF;","names":["SnapStatus","SnapStatusEvents"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/cronjob.ts
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _utils = require('@metamask/utils');
|
|
7
|
+
var _cronparser = require('cron-parser');
|
|
8
|
+
var _superstruct = require('superstruct');
|
|
9
|
+
var CronjobRpcRequestStruct = _superstruct.object.call(void 0, {
|
|
10
|
+
jsonrpc: _superstruct.optional.call(void 0, _utils.JsonRpcVersionStruct),
|
|
11
|
+
id: _superstruct.optional.call(void 0, _utils.JsonRpcIdStruct),
|
|
12
|
+
method: _superstruct.string.call(void 0, ),
|
|
13
|
+
params: _superstruct.optional.call(void 0, _utils.JsonRpcParamsStruct)
|
|
14
|
+
});
|
|
15
|
+
var CronExpressionStruct = _superstruct.refine.call(void 0,
|
|
16
|
+
_superstruct.string.call(void 0, ),
|
|
17
|
+
"CronExpression",
|
|
18
|
+
(value) => {
|
|
19
|
+
try {
|
|
20
|
+
_cronparser.parseExpression.call(void 0, value);
|
|
21
|
+
return true;
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
);
|
|
27
|
+
function parseCronExpression(expression) {
|
|
28
|
+
const ensureStringExpression = _superstruct.create.call(void 0, expression, CronExpressionStruct);
|
|
29
|
+
return _cronparser.parseExpression.call(void 0, ensureStringExpression);
|
|
30
|
+
}
|
|
31
|
+
var CronjobSpecificationStruct = _superstruct.object.call(void 0, {
|
|
32
|
+
expression: CronExpressionStruct,
|
|
33
|
+
request: CronjobRpcRequestStruct
|
|
34
|
+
});
|
|
35
|
+
function isCronjobSpecification(value) {
|
|
36
|
+
try {
|
|
37
|
+
_superstruct.create.call(void 0, value, CronjobSpecificationStruct);
|
|
38
|
+
return true;
|
|
39
|
+
} catch {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
var CronjobSpecificationArrayStruct = _superstruct.array.call(void 0,
|
|
44
|
+
CronjobSpecificationStruct
|
|
45
|
+
);
|
|
46
|
+
function isCronjobSpecificationArray(value) {
|
|
47
|
+
try {
|
|
48
|
+
_superstruct.create.call(void 0, value, CronjobSpecificationArrayStruct);
|
|
49
|
+
return true;
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
exports.CronjobRpcRequestStruct = CronjobRpcRequestStruct; exports.CronExpressionStruct = CronExpressionStruct; exports.parseCronExpression = parseCronExpression; exports.CronjobSpecificationStruct = CronjobSpecificationStruct; exports.isCronjobSpecification = isCronjobSpecification; exports.CronjobSpecificationArrayStruct = CronjobSpecificationArrayStruct; exports.isCronjobSpecificationArray = isCronjobSpecificationArray;
|
|
64
|
+
//# sourceMappingURL=chunk-2LBN5T56.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cronjob.ts"],"names":[],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAEhC,SAAS,OAAO,QAAQ,QAAQ,UAAU,QAAQ,cAAc;AAEzD,IAAM,0BAA0B,OAAO;AAAA,EAC5C,SAAS,SAAS,oBAAoB;AAAA,EACtC,IAAI,SAAS,eAAe;AAAA,EAC5B,QAAQ,OAAO;AAAA,EACf,QAAQ,SAAS,mBAAmB;AACtC,CAAC;AAIM,IAAM,uBAAuB;AAAA,EAClC,OAAO;AAAA,EACP;AAAA,EACA,CAAC,UAAU;AACT,QAAI;AACF,sBAAgB,KAAK;AACrB,aAAO;AAAA,IACT,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAUO,SAAS,oBAAoB,YAA6B;AAC/D,QAAM,yBAAyB,OAAO,YAAY,oBAAoB;AACtE,SAAO,gBAAgB,sBAAsB;AAC/C;AAEO,IAAM,6BAA6B,OAAO;AAAA,EAC/C,YAAY;AAAA,EACZ,SAAS;AACX,CAAC;AASM,SAAS,uBAAuB,OAAyB;AAC9D,MAAI;AACF,WAAO,OAAO,0BAA0B;AACxC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEO,IAAM,kCAAkC;AAAA,EAC7C;AACF;AAQO,SAAS,4BAA4B,OAAyB;AACnE,MAAI;AACF,WAAO,OAAO,+BAA+B;AAC7C,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF","sourcesContent":["import {\n JsonRpcIdStruct,\n JsonRpcParamsStruct,\n JsonRpcVersionStruct,\n} from '@metamask/utils';\nimport { parseExpression } from 'cron-parser';\nimport type { Infer } from 'superstruct';\nimport { array, create, object, optional, refine, string } from 'superstruct';\n\nexport const CronjobRpcRequestStruct = object({\n jsonrpc: optional(JsonRpcVersionStruct),\n id: optional(JsonRpcIdStruct),\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;\n\nexport const CronExpressionStruct = refine(\n string(),\n 'CronExpression',\n (value) => {\n try {\n parseExpression(value);\n return true;\n } catch {\n return false;\n }\n },\n);\n\nexport type CronExpression = Infer<typeof CronExpressionStruct>;\n\n/**\n * Parses a cron expression.\n *\n * @param expression - Expression to parse.\n * @returns A CronExpression class instance.\n */\nexport function parseCronExpression(expression: string | object) {\n const ensureStringExpression = create(expression, CronExpressionStruct);\n return parseExpression(ensureStringExpression);\n}\n\nexport const CronjobSpecificationStruct = object({\n expression: CronExpressionStruct,\n request: CronjobRpcRequestStruct,\n});\nexport type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;\n\n/**\n * Check if the given value is a {@link CronjobSpecification} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link CronjobSpecification} object.\n */\nexport function isCronjobSpecification(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationStruct);\n return true;\n } catch {\n return false;\n }\n}\n\nexport const CronjobSpecificationArrayStruct = array(\n CronjobSpecificationStruct,\n);\n\n/**\n * Check if the given value is an array of {@link CronjobSpecification} objects.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid array of {@link CronjobSpecification} objects.\n */\nexport function isCronjobSpecificationArray(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationArrayStruct);\n return true;\n } catch {\n return false;\n }\n}\n"]}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
|
+
|
|
3
|
+
var _chunkT3YY4JIJjs = require('./chunk-T3YY4JIJ.js');
|
|
4
|
+
|
|
5
|
+
// src/derivation-paths.ts
|
|
6
|
+
var _slip44 = require('@metamask/slip44'); var _slip442 = _interopRequireDefault(_slip44);
|
|
7
|
+
var SNAPS_DERIVATION_PATHS = [
|
|
8
|
+
{
|
|
9
|
+
path: ["m", `44'`, `0'`],
|
|
10
|
+
curve: "ed25519",
|
|
11
|
+
name: "Test BIP-32 Path (ed25519)"
|
|
12
|
+
},
|
|
13
|
+
{
|
|
14
|
+
path: ["m", `44'`, `1'`],
|
|
15
|
+
curve: "secp256k1",
|
|
16
|
+
name: "Testnet"
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
path: ["m", `44'`, `0'`],
|
|
20
|
+
curve: "secp256k1",
|
|
21
|
+
name: "Bitcoin Legacy"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
path: ["m", `49'`, `0'`],
|
|
25
|
+
curve: "secp256k1",
|
|
26
|
+
name: "Bitcoin Nested SegWit"
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
path: ["m", `49'`, `1'`],
|
|
30
|
+
curve: "secp256k1",
|
|
31
|
+
name: "Bitcoin Testnet Nested SegWit"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
path: ["m", `84'`, `0'`],
|
|
35
|
+
curve: "secp256k1",
|
|
36
|
+
name: "Bitcoin Native SegWit"
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
path: ["m", `84'`, `1'`],
|
|
40
|
+
curve: "secp256k1",
|
|
41
|
+
name: "Bitcoin Testnet Native SegWit"
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
path: ["m", `44'`, `501'`],
|
|
45
|
+
curve: "ed25519",
|
|
46
|
+
name: "Solana"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
path: ["m", `44'`, `501'`, "0'", "0'"],
|
|
50
|
+
curve: "ed25519",
|
|
51
|
+
name: "Solana"
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
path: ["m", `44'`, `2'`],
|
|
55
|
+
curve: "secp256k1",
|
|
56
|
+
name: "Litecoin"
|
|
57
|
+
},
|
|
58
|
+
{
|
|
59
|
+
path: ["m", `44'`, `3'`],
|
|
60
|
+
curve: "secp256k1",
|
|
61
|
+
name: "Dogecoin"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
path: ["m", `44'`, `60'`],
|
|
65
|
+
curve: "secp256k1",
|
|
66
|
+
name: "Ethereum"
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
path: ["m", `44'`, `118'`],
|
|
70
|
+
curve: "secp256k1",
|
|
71
|
+
name: "Atom"
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
path: ["m", `44'`, `145'`],
|
|
75
|
+
curve: "secp256k1",
|
|
76
|
+
name: "Bitcoin Cash"
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
path: ["m", `44'`, `637'`],
|
|
80
|
+
curve: "ed25519",
|
|
81
|
+
name: "Aptos"
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
path: ["m", `44'`, `714'`],
|
|
85
|
+
curve: "secp256k1",
|
|
86
|
+
name: "Binance (BNB)"
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
path: ["m", `44'`, `784'`],
|
|
90
|
+
curve: "ed25519",
|
|
91
|
+
name: "Sui"
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
path: ["m", `44'`, `931'`],
|
|
95
|
+
curve: "secp256k1",
|
|
96
|
+
name: "THORChain (RUNE)"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
path: ["m", `44'`, `330'`],
|
|
100
|
+
curve: "secp256k1",
|
|
101
|
+
name: "Terra (LUNA)"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
path: ["m", `44'`, `459'`],
|
|
105
|
+
curve: "secp256k1",
|
|
106
|
+
name: "Kava"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
path: ["m", `44'`, `529'`],
|
|
110
|
+
curve: "secp256k1",
|
|
111
|
+
name: "Secret Network"
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
path: ["m", `44'`, `397'`, `0'`],
|
|
115
|
+
curve: "ed25519",
|
|
116
|
+
name: "NEAR Protocol"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
path: ["m", `44'`, `1'`, `0'`],
|
|
120
|
+
curve: "ed25519",
|
|
121
|
+
name: "Testnet"
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
path: ["m", `44'`, `472'`],
|
|
125
|
+
curve: "ed25519",
|
|
126
|
+
name: "Arweave"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
path: ["m", `44'`, `12586'`],
|
|
130
|
+
curve: "secp256k1",
|
|
131
|
+
name: "Mina"
|
|
132
|
+
},
|
|
133
|
+
{
|
|
134
|
+
path: ["m", `44'`, `1729'`, `0'`, `0'`],
|
|
135
|
+
curve: "ed25519",
|
|
136
|
+
name: "Tezos"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
path: ["m", `1789'`, `0'`],
|
|
140
|
+
curve: "ed25519",
|
|
141
|
+
name: "Vega"
|
|
142
|
+
}
|
|
143
|
+
];
|
|
144
|
+
function getSnapDerivationPathName(path, curve) {
|
|
145
|
+
const pathMetadata = SNAPS_DERIVATION_PATHS.find(
|
|
146
|
+
(derivationPath) => derivationPath.curve === curve && _chunkT3YY4JIJjs.isEqual.call(void 0, derivationPath.path, path)
|
|
147
|
+
);
|
|
148
|
+
if (pathMetadata) {
|
|
149
|
+
return pathMetadata.name;
|
|
150
|
+
}
|
|
151
|
+
if (curve === "secp256k1" && path[0] === "m" && path[1] === `44'` && path[2].endsWith(`'`)) {
|
|
152
|
+
const coinType = path[2].slice(0, -1);
|
|
153
|
+
return getSlip44ProtocolName(coinType) ?? null;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
function getSlip44ProtocolName(coinType) {
|
|
158
|
+
if (String(coinType) === "1") {
|
|
159
|
+
return "Test Networks";
|
|
160
|
+
}
|
|
161
|
+
return _slip442.default[coinType]?.name ?? null;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
exports.SNAPS_DERIVATION_PATHS = SNAPS_DERIVATION_PATHS; exports.getSnapDerivationPathName = getSnapDerivationPathName; exports.getSlip44ProtocolName = getSlip44ProtocolName;
|
|
169
|
+
//# sourceMappingURL=chunk-2PCPD5XY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/derivation-paths.ts"],"names":[],"mappings":";;;;;AACA,OAAO,YAAY;AAUZ,IAAM,yBAAgD;AAAA,EAC3D;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,MAAM;AAA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G,QAAQ;AAC1D","sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport slip44 from '@metamask/slip44';\n\nimport { isEqual } from './array';\n\nexport type SnapsDerivationPath = {\n path: ['m', ...string[]];\n curve: SupportedCurve;\n name: string;\n};\n\nexport const SNAPS_DERIVATION_PATHS: SnapsDerivationPath[] = [\n {\n path: ['m', `44'`, `0'`],\n curve: 'ed25519',\n name: 'Test BIP-32 Path (ed25519)',\n },\n {\n path: ['m', `44'`, `1'`],\n curve: 'secp256k1',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Legacy',\n },\n {\n path: ['m', `49'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Nested SegWit',\n },\n {\n path: ['m', `49'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Nested SegWit',\n },\n {\n path: ['m', `84'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Native SegWit',\n },\n {\n path: ['m', `84'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Native SegWit',\n },\n {\n path: ['m', `44'`, `501'`],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `501'`, \"0'\", \"0'\"],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `2'`],\n curve: 'secp256k1',\n name: 'Litecoin',\n },\n {\n path: ['m', `44'`, `3'`],\n curve: 'secp256k1',\n name: 'Dogecoin',\n },\n {\n path: ['m', `44'`, `60'`],\n curve: 'secp256k1',\n name: 'Ethereum',\n },\n {\n path: ['m', `44'`, `118'`],\n curve: 'secp256k1',\n name: 'Atom',\n },\n {\n path: ['m', `44'`, `145'`],\n curve: 'secp256k1',\n name: 'Bitcoin Cash',\n },\n {\n path: ['m', `44'`, `637'`],\n curve: 'ed25519',\n name: 'Aptos',\n },\n {\n path: ['m', `44'`, `714'`],\n curve: 'secp256k1',\n name: 'Binance (BNB)',\n },\n {\n path: ['m', `44'`, `784'`],\n curve: 'ed25519',\n name: 'Sui',\n },\n {\n path: ['m', `44'`, `931'`],\n curve: 'secp256k1',\n name: 'THORChain (RUNE)',\n },\n {\n path: ['m', `44'`, `330'`],\n curve: 'secp256k1',\n name: 'Terra (LUNA)',\n },\n {\n path: ['m', `44'`, `459'`],\n curve: 'secp256k1',\n name: 'Kava',\n },\n {\n path: ['m', `44'`, `529'`],\n curve: 'secp256k1',\n name: 'Secret Network',\n },\n {\n path: ['m', `44'`, `397'`, `0'`],\n curve: 'ed25519',\n name: 'NEAR Protocol',\n },\n {\n path: ['m', `44'`, `1'`, `0'`],\n curve: 'ed25519',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `472'`],\n curve: 'ed25519',\n name: 'Arweave',\n },\n {\n path: ['m', `44'`, `12586'`],\n curve: 'secp256k1',\n name: 'Mina',\n },\n {\n path: ['m', `44'`, `1729'`, `0'`, `0'`],\n curve: 'ed25519',\n name: 'Tezos',\n },\n {\n path: ['m', `1789'`, `0'`],\n curve: 'ed25519',\n name: 'Vega',\n },\n];\n\n/**\n * Gets the name of a derivation path supported by snaps.\n *\n * @param path - The derivation path.\n * @param curve - The curve used to derive the keys.\n * @returns The name of the derivation path, otherwise null.\n */\nexport function getSnapDerivationPathName(\n path: SnapsDerivationPath['path'],\n curve: SupportedCurve,\n): string | null {\n const pathMetadata = SNAPS_DERIVATION_PATHS.find(\n (derivationPath) =>\n derivationPath.curve === curve && isEqual(derivationPath.path, path),\n );\n\n if (pathMetadata) {\n return pathMetadata.name;\n }\n\n // If the curve is secp256k1 and the path is a valid BIP44 path\n // we try looking for the network/protocol name in SLIP44\n if (\n curve === 'secp256k1' &&\n path[0] === 'm' &&\n path[1] === `44'` &&\n path[2].endsWith(`'`)\n ) {\n const coinType = path[2].slice(0, -1);\n return getSlip44ProtocolName(coinType) ?? null;\n }\n\n return null;\n}\n\n/**\n * Gets the name of the SLIP-44 protocol corresponding to the specified\n * `coin_type`.\n *\n * @param coinType - The SLIP-44 `coin_type` value whose name\n * to retrieve.\n * @returns The name of the protocol, otherwise null.\n */\nexport function getSlip44ProtocolName(coinType: number | string) {\n if (String(coinType) === '1') {\n return 'Test Networks';\n }\n\n return slip44[coinType as keyof typeof slip44]?.name ?? null;\n}\n"]}
|