@metamask/snaps-utils 7.8.1 → 8.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 +13 -1
- package/dist/array.js +1 -1
- package/dist/array.mjs +1 -1
- package/dist/auxiliary-files.js +1 -1
- package/dist/auxiliary-files.mjs +1 -1
- package/dist/base64.js +1 -1
- package/dist/base64.mjs +1 -1
- package/dist/bytes.js +1 -1
- package/dist/bytes.mjs +1 -1
- package/dist/caveats.js +1 -1
- package/dist/caveats.mjs +1 -1
- package/dist/checksum.js +1 -1
- package/dist/checksum.mjs +1 -1
- package/dist/{chunk-5I5WPAVD.js → chunk-37EUH3KZ.js} +13 -13
- package/dist/{chunk-FLSK6ISS.mjs → chunk-3N27GIUS.mjs} +4 -1
- package/dist/chunk-3N27GIUS.mjs.map +1 -0
- package/dist/{chunk-SB43G2RI.js → chunk-3OXW5H4F.js} +5 -5
- package/dist/{chunk-K6BCBPXF.js → chunk-3RFGTBEP.js} +11 -11
- package/dist/{chunk-JMDSN227.mjs → chunk-3RUWAMJT.mjs} +7 -1
- package/dist/chunk-4BGZ2CHC.mjs +22 -0
- package/dist/chunk-4BGZ2CHC.mjs.map +1 -0
- package/dist/chunk-4RYTYEUQ.mjs +33 -0
- package/dist/chunk-4RYTYEUQ.mjs.map +1 -0
- package/dist/{chunk-VOPTAKVG.js → chunk-53QXTM77.js} +4 -1
- package/dist/chunk-53QXTM77.js.map +1 -0
- package/dist/chunk-5FTBWYCW.mjs +27 -0
- package/dist/chunk-5FTBWYCW.mjs.map +1 -0
- package/dist/chunk-5MABKEV7.mjs +66 -0
- package/dist/chunk-5MABKEV7.mjs.map +1 -0
- package/dist/chunk-5UAPBOKO.js +37 -0
- package/dist/chunk-5UAPBOKO.js.map +1 -0
- package/dist/chunk-6YJWU77L.js +19 -0
- package/dist/chunk-6YJWU77L.js.map +1 -0
- package/dist/chunk-7T7FYH77.mjs +37 -0
- package/dist/chunk-7T7FYH77.mjs.map +1 -0
- package/dist/chunk-BPK5BH7K.js +27 -0
- package/dist/chunk-BPK5BH7K.js.map +1 -0
- package/dist/chunk-CPG2UGAA.js +25 -0
- package/dist/chunk-CPG2UGAA.js.map +1 -0
- package/dist/chunk-DKO64Y4H.mjs +27 -0
- package/dist/chunk-DKO64Y4H.mjs.map +1 -0
- package/dist/chunk-EYWMVDCD.mjs +25 -0
- package/dist/chunk-EYWMVDCD.mjs.map +1 -0
- package/dist/chunk-FA4QIZH6.js +1 -0
- package/dist/chunk-GIVJAZ2Q.mjs +248 -0
- package/dist/chunk-GIVJAZ2Q.mjs.map +1 -0
- package/dist/chunk-GJAVOB7B.js +24 -0
- package/dist/chunk-GJAVOB7B.js.map +1 -0
- package/dist/{chunk-ZXHR322P.mjs → chunk-GXSTPU7D.mjs} +4 -4
- package/dist/chunk-HY4W6BUH.mjs +24 -0
- package/dist/chunk-HY4W6BUH.mjs.map +1 -0
- package/dist/{chunk-YNOZU43P.mjs → chunk-IPUL74MZ.mjs} +3 -3
- package/dist/chunk-IVDERT5W.js +22 -0
- package/dist/chunk-IVDERT5W.js.map +1 -0
- package/dist/chunk-JETPRED3.js +248 -0
- package/dist/chunk-JETPRED3.js.map +1 -0
- package/dist/chunk-L2DHOOBX.js +33 -0
- package/dist/chunk-L2DHOOBX.js.map +1 -0
- package/dist/chunk-LQSEBGOX.js +34 -0
- package/dist/chunk-LQSEBGOX.js.map +1 -0
- package/dist/chunk-MDOG3S4V.mjs +34 -0
- package/dist/chunk-MDOG3S4V.mjs.map +1 -0
- package/dist/chunk-MFGLB75H.mjs +22 -0
- package/dist/chunk-MFGLB75H.mjs.map +1 -0
- package/dist/chunk-MQURBEO4.mjs +16 -0
- package/dist/chunk-MQURBEO4.mjs.map +1 -0
- package/dist/{chunk-PZNIU23I.js → chunk-MWAZGSRO.js} +2 -22
- package/dist/chunk-MWAZGSRO.js.map +1 -0
- package/dist/{chunk-AJNKQYKP.mjs → chunk-N2JAYIUP.mjs} +2 -22
- package/dist/chunk-N2JAYIUP.mjs.map +1 -0
- package/dist/chunk-N4MA537G.js +22 -0
- package/dist/chunk-N4MA537G.js.map +1 -0
- package/dist/chunk-NNYGTNHP.mjs +1 -0
- package/dist/{chunk-H35ZUVQT.mjs → chunk-NSVVZNSD.mjs} +3 -13
- package/dist/chunk-NSVVZNSD.mjs.map +1 -0
- package/dist/chunk-PAOTMYIM.mjs +69 -0
- package/dist/chunk-PAOTMYIM.mjs.map +1 -0
- package/dist/chunk-PO5BBHHX.mjs +22 -0
- package/dist/chunk-PO5BBHHX.mjs.map +1 -0
- package/dist/{chunk-VWGXNUMD.mjs → chunk-PZF4KWU2.mjs} +2 -2
- package/dist/chunk-QD3LTING.js +34 -0
- package/dist/chunk-QD3LTING.js.map +1 -0
- package/dist/chunk-RNMJQSVQ.js +69 -0
- package/dist/chunk-RNMJQSVQ.js.map +1 -0
- package/dist/chunk-RRFKK45V.mjs +15 -0
- package/dist/chunk-RRFKK45V.mjs.map +1 -0
- package/dist/{chunk-PHUTP7NB.js → chunk-S3BWTUTZ.js} +9 -3
- package/dist/chunk-SKKANJ45.mjs +19 -0
- package/dist/chunk-SKKANJ45.mjs.map +1 -0
- package/dist/chunk-SYYDKPK3.js +15 -0
- package/dist/chunk-SYYDKPK3.js.map +1 -0
- package/dist/chunk-T5ZOOZ46.js +22 -0
- package/dist/chunk-T5ZOOZ46.js.map +1 -0
- package/dist/{chunk-RD6BN2TQ.js → chunk-TAMKWZ4E.js} +8 -18
- package/dist/chunk-TAMKWZ4E.js.map +1 -0
- package/dist/chunk-TYWGZIOF.mjs +34 -0
- package/dist/chunk-TYWGZIOF.mjs.map +1 -0
- package/dist/chunk-VBYSWMSU.js +66 -0
- package/dist/chunk-VBYSWMSU.js.map +1 -0
- package/dist/chunk-VEPYH26P.js +27 -0
- package/dist/chunk-VEPYH26P.js.map +1 -0
- package/dist/chunk-VWLBM7XM.js +1 -0
- package/dist/chunk-W7A3BYUP.mjs +1 -0
- package/dist/chunk-YL2EHYAA.js +16 -0
- package/dist/chunk-YL2EHYAA.js.map +1 -0
- package/dist/constants.js +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/cronjob.js +1 -1
- package/dist/cronjob.mjs +1 -1
- package/dist/deep-clone.js +1 -1
- package/dist/deep-clone.mjs +1 -1
- package/dist/default-endowments.js +1 -1
- package/dist/default-endowments.mjs +1 -1
- package/dist/derivation-paths.js +1 -1
- package/dist/derivation-paths.mjs +1 -1
- package/dist/entropy.js +1 -1
- package/dist/entropy.mjs +1 -1
- package/dist/errors.js +3 -3
- package/dist/errors.mjs +2 -2
- package/dist/eval-worker.js +1 -1
- package/dist/eval-worker.mjs +1 -1
- package/dist/eval.js +1 -1
- package/dist/eval.mjs +1 -1
- package/dist/fs.js +1 -1
- package/dist/fs.mjs +1 -1
- package/dist/handler-types.js +1 -1
- package/dist/handler-types.mjs +1 -1
- package/dist/handlers.js +1 -1
- package/dist/handlers.mjs +1 -1
- package/dist/icon.js +1 -1
- package/dist/icon.mjs +1 -1
- package/dist/iframe.js +1 -1
- package/dist/iframe.mjs +1 -1
- package/dist/index.executionenv.js +5 -11
- package/dist/index.executionenv.mjs +9 -15
- package/dist/index.js +11 -18
- package/dist/index.mjs +15 -22
- package/dist/json-rpc.js +1 -1
- package/dist/json-rpc.mjs +1 -1
- package/dist/json.js +1 -1
- package/dist/json.mjs +1 -1
- package/dist/localization.js +1 -1
- package/dist/localization.mjs +1 -1
- package/dist/logging.js +1 -1
- package/dist/logging.mjs +1 -1
- package/dist/manifest/index.js +6 -6
- package/dist/manifest/index.mjs +5 -5
- package/dist/manifest/manifest.js +23 -9
- package/dist/manifest/manifest.mjs +24 -10
- package/dist/manifest/node.js +23 -9
- package/dist/manifest/node.mjs +24 -10
- package/dist/manifest/validation.js +6 -6
- package/dist/manifest/validation.mjs +5 -5
- package/dist/manifest/validator-types.js +1 -0
- package/dist/manifest/validator-types.js.map +1 -0
- package/dist/manifest/validator-types.mjs +1 -0
- package/dist/manifest/validator-types.mjs.map +1 -0
- package/dist/manifest/validator.js +44 -0
- package/dist/manifest/validator.js.map +1 -0
- package/dist/manifest/validator.mjs +44 -0
- package/dist/manifest/validator.mjs.map +1 -0
- package/dist/manifest/validators/checksum.js +15 -0
- package/dist/manifest/validators/checksum.js.map +1 -0
- package/dist/manifest/validators/checksum.mjs +15 -0
- package/dist/manifest/validators/checksum.mjs.map +1 -0
- package/dist/manifest/validators/expected-files.js +9 -0
- package/dist/manifest/validators/expected-files.js.map +1 -0
- package/dist/manifest/validators/expected-files.mjs +9 -0
- package/dist/manifest/validators/expected-files.mjs.map +1 -0
- package/dist/manifest/validators/icon-declared.js +8 -0
- package/dist/manifest/validators/icon-declared.js.map +1 -0
- package/dist/manifest/validators/icon-declared.mjs +8 -0
- package/dist/manifest/validators/icon-declared.mjs.map +1 -0
- package/dist/manifest/validators/icon-dimensions.js +10 -0
- package/dist/manifest/validators/icon-dimensions.js.map +1 -0
- package/dist/manifest/validators/icon-dimensions.mjs +10 -0
- package/dist/manifest/validators/icon-dimensions.mjs.map +1 -0
- package/dist/manifest/validators/icon-missing.js +8 -0
- package/dist/manifest/validators/icon-missing.js.map +1 -0
- package/dist/manifest/validators/icon-missing.mjs +8 -0
- package/dist/manifest/validators/icon-missing.mjs.map +1 -0
- package/dist/manifest/validators/index.js +80 -0
- package/dist/manifest/validators/index.js.map +1 -0
- package/dist/manifest/validators/index.mjs +80 -0
- package/dist/manifest/validators/index.mjs.map +1 -0
- package/dist/manifest/validators/is-localization-file.js +12 -0
- package/dist/manifest/validators/is-localization-file.js.map +1 -0
- package/dist/manifest/validators/is-localization-file.mjs +12 -0
- package/dist/manifest/validators/is-localization-file.mjs.map +1 -0
- package/dist/manifest/validators/is-package-json.js +11 -0
- package/dist/manifest/validators/is-package-json.js.map +1 -0
- package/dist/manifest/validators/is-package-json.mjs +11 -0
- package/dist/manifest/validators/is-package-json.mjs.map +1 -0
- package/dist/manifest/validators/is-snap-icon.js +10 -0
- package/dist/manifest/validators/is-snap-icon.js.map +1 -0
- package/dist/manifest/validators/is-snap-icon.mjs +10 -0
- package/dist/manifest/validators/is-snap-icon.mjs.map +1 -0
- package/dist/manifest/validators/is-snap-manifest.js +23 -0
- package/dist/manifest/validators/is-snap-manifest.js.map +1 -0
- package/dist/manifest/validators/is-snap-manifest.mjs +23 -0
- package/dist/manifest/validators/is-snap-manifest.mjs.map +1 -0
- package/dist/manifest/validators/manifest-localization.js +10 -0
- package/dist/manifest/validators/manifest-localization.js.map +1 -0
- package/dist/manifest/validators/manifest-localization.mjs +10 -0
- package/dist/manifest/validators/manifest-localization.mjs.map +1 -0
- package/dist/manifest/validators/package-json-recommended-fields.js +8 -0
- package/dist/manifest/validators/package-json-recommended-fields.js.map +1 -0
- package/dist/manifest/validators/package-json-recommended-fields.mjs +8 -0
- package/dist/manifest/validators/package-json-recommended-fields.mjs.map +1 -0
- package/dist/manifest/validators/package-name-match.js +9 -0
- package/dist/manifest/validators/package-name-match.js.map +1 -0
- package/dist/manifest/validators/package-name-match.mjs +9 -0
- package/dist/manifest/validators/package-name-match.mjs.map +1 -0
- package/dist/manifest/validators/repository-match.js +10 -0
- package/dist/manifest/validators/repository-match.js.map +1 -0
- package/dist/manifest/validators/repository-match.mjs +10 -0
- package/dist/manifest/validators/repository-match.mjs.map +1 -0
- package/dist/manifest/validators/version-match.js +9 -0
- package/dist/manifest/validators/version-match.js.map +1 -0
- package/dist/manifest/validators/version-match.mjs +9 -0
- package/dist/manifest/validators/version-match.mjs.map +1 -0
- package/dist/mock.js +1 -1
- package/dist/mock.mjs +1 -1
- package/dist/namespace.js +1 -1
- package/dist/namespace.mjs +1 -1
- package/dist/node.js +28 -27
- package/dist/node.mjs +34 -33
- package/dist/path.js +1 -1
- package/dist/path.mjs +1 -1
- package/dist/post-process.js +1 -1
- package/dist/post-process.mjs +1 -1
- package/dist/promise.js +2 -0
- package/dist/promise.js.map +1 -0
- package/dist/promise.mjs +2 -0
- package/dist/promise.mjs.map +1 -0
- package/dist/snaps.js +4 -6
- package/dist/snaps.mjs +3 -5
- package/dist/strings.js +1 -1
- package/dist/strings.mjs +1 -1
- package/dist/structs.js +3 -3
- package/dist/structs.mjs +2 -2
- package/dist/svg.js +1 -1
- package/dist/svg.mjs +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/cronjob.d.ts +3 -3
- package/dist/types/derivation-paths.d.ts +1 -1
- package/dist/types/entropy.d.ts +1 -1
- package/dist/types/errors.d.ts +1 -1
- package/dist/types/eval.d.ts +1 -1
- package/dist/types/handler-types.d.ts +1 -1
- package/dist/types/handlers.d.ts +56 -7
- package/dist/types/index.d.ts +1 -0
- package/dist/types/json-rpc.d.ts +2 -2
- package/dist/types/localization.d.ts +1 -1
- package/dist/types/manifest/manifest.d.ts +30 -40
- package/dist/types/manifest/validation.d.ts +6 -6
- package/dist/types/manifest/validator-types.d.ts +34 -0
- package/dist/types/manifest/validator.d.ts +22 -0
- package/dist/types/manifest/validators/checksum.d.ts +5 -0
- package/dist/types/manifest/validators/expected-files.d.ts +5 -0
- package/dist/types/manifest/validators/icon-declared.d.ts +5 -0
- package/dist/types/manifest/validators/icon-dimensions.d.ts +5 -0
- package/dist/types/manifest/validators/icon-missing.d.ts +5 -0
- package/dist/types/manifest/validators/index.d.ts +14 -0
- package/dist/types/manifest/validators/is-localization-file.d.ts +5 -0
- package/dist/types/manifest/validators/is-package-json.d.ts +5 -0
- package/dist/types/manifest/validators/is-snap-icon.d.ts +5 -0
- package/dist/types/manifest/validators/is-snap-manifest.d.ts +5 -0
- package/dist/types/manifest/validators/manifest-localization.d.ts +5 -0
- package/dist/types/manifest/validators/package-json-recommended-fields.d.ts +5 -0
- package/dist/types/manifest/validators/package-name-match.d.ts +5 -0
- package/dist/types/manifest/validators/repository-match.d.ts +5 -0
- package/dist/types/manifest/validators/version-match.d.ts +5 -0
- package/dist/types/namespace.d.ts +5 -5
- package/dist/types/node.d.ts +0 -1
- package/dist/types/post-process.d.ts +3 -3
- package/dist/types/promise.d.ts +1 -0
- package/dist/types/snaps.d.ts +10 -18
- package/dist/types/structs.d.ts +2 -2
- package/dist/types/types.d.ts +9 -33
- package/dist/types/virtual-file/VirtualFile.d.ts +4 -4
- package/dist/types/virtual-file/toVirtualFile.d.ts +1 -1
- package/dist/types.js +3 -9
- package/dist/types.mjs +2 -8
- package/dist/ui.js +1 -1
- package/dist/ui.mjs +1 -1
- package/dist/validation.js +7 -7
- package/dist/validation.mjs +6 -6
- package/dist/versions.js +1 -1
- package/dist/versions.mjs +1 -1
- package/dist/virtual-file/VirtualFile.js +1 -1
- package/dist/virtual-file/VirtualFile.mjs +1 -1
- package/dist/virtual-file/index.js +1 -1
- package/dist/virtual-file/index.mjs +1 -1
- package/dist/virtual-file/node.js +1 -1
- package/dist/virtual-file/node.mjs +1 -1
- package/dist/virtual-file/toVirtualFile.js +1 -1
- package/dist/virtual-file/toVirtualFile.mjs +1 -1
- package/package.json +5 -5
- package/dist/chunk-25ESL4NL.js +0 -409
- package/dist/chunk-25ESL4NL.js.map +0 -1
- package/dist/chunk-AJNKQYKP.mjs.map +0 -1
- package/dist/chunk-F6G67XQ4.js +0 -1
- package/dist/chunk-FLSK6ISS.mjs.map +0 -1
- package/dist/chunk-H35ZUVQT.mjs.map +0 -1
- package/dist/chunk-KCECQM3L.mjs +0 -409
- package/dist/chunk-KCECQM3L.mjs.map +0 -1
- package/dist/chunk-OYZPBNHS.mjs +0 -1
- package/dist/chunk-PZNIU23I.js.map +0 -1
- package/dist/chunk-RD6BN2TQ.js.map +0 -1
- package/dist/chunk-VOPTAKVG.js.map +0 -1
- package/dist/npm.js +0 -35
- package/dist/npm.mjs +0 -35
- package/dist/types/npm.d.ts +0 -19
- /package/dist/{chunk-5I5WPAVD.js.map → chunk-37EUH3KZ.js.map} +0 -0
- /package/dist/{chunk-SB43G2RI.js.map → chunk-3OXW5H4F.js.map} +0 -0
- /package/dist/{chunk-K6BCBPXF.js.map → chunk-3RFGTBEP.js.map} +0 -0
- /package/dist/{chunk-JMDSN227.mjs.map → chunk-3RUWAMJT.mjs.map} +0 -0
- /package/dist/{chunk-F6G67XQ4.js.map → chunk-FA4QIZH6.js.map} +0 -0
- /package/dist/{chunk-ZXHR322P.mjs.map → chunk-GXSTPU7D.mjs.map} +0 -0
- /package/dist/{chunk-YNOZU43P.mjs.map → chunk-IPUL74MZ.mjs.map} +0 -0
- /package/dist/{chunk-OYZPBNHS.mjs.map → chunk-NNYGTNHP.mjs.map} +0 -0
- /package/dist/{chunk-VWGXNUMD.mjs.map → chunk-PZF4KWU2.mjs.map} +0 -0
- /package/dist/{chunk-PHUTP7NB.js.map → chunk-S3BWTUTZ.js.map} +0 -0
- /package/dist/{npm.js.map → chunk-VWLBM7XM.js.map} +0 -0
- /package/dist/{npm.mjs.map → chunk-W7A3BYUP.mjs.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["import {\n instance,\n is,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n type,\n union,\n assert as assertSuperstruct,\n} from '@metamask/superstruct';\nimport type { Infer, Struct } from '@metamask/superstruct';\nimport type { Json } from '@metamask/utils';\nimport { VersionStruct } from '@metamask/utils';\n\nimport type { SnapCaveatType } from './caveats';\nimport type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest } from './manifest';\nimport type { VirtualFile } from './virtual-file';\n\nexport enum NpmSnapFileNames {\n PackageJson = 'package.json',\n Manifest = 'snap.manifest.json',\n}\n\nexport const NameStruct = size(\n pattern(\n string(),\n /^(?:@[a-z0-9-*~][a-z0-9-*._~]*\\/)?[a-z0-9-~][a-z0-9-._~]*$/u,\n ),\n 1,\n 214,\n);\n\n// Note we use `type` instead of `object` here, because the latter does not\n// allow unknown keys.\nexport const NpmSnapPackageJsonStruct = type({\n version: VersionStruct,\n name: NameStruct,\n main: optional(size(string(), 1, Infinity)),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n});\n\nexport type NpmSnapPackageJson = Infer<typeof NpmSnapPackageJsonStruct> &\n Record<string, any>;\n\n/**\n * An object for storing parsed but unvalidated Snap file contents.\n */\nexport type UnvalidatedSnapFiles = {\n manifest?: VirtualFile<Json>;\n packageJson?: VirtualFile<Json>;\n sourceCode?: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile[];\n};\n\n/**\n * An object for storing the contents of Snap files that have passed JSON\n * Schema validation, or are non-empty if they are strings.\n */\nexport type SnapFiles = {\n manifest: VirtualFile<SnapManifest>;\n packageJson: VirtualFile<NpmSnapPackageJson>;\n sourceCode: VirtualFile;\n svgIcon?: VirtualFile;\n auxiliaryFiles: VirtualFile[];\n localizationFiles: VirtualFile<LocalizationFile>[];\n};\n\n/**\n * A subset of snap files extracted from a fetched snap.\n */\nexport type FetchedSnapFiles = Pick<\n SnapFiles,\n 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'\n>;\n\n/**\n * The possible prefixes for snap ids.\n */\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SnapIdPrefixes {\n npm = 'npm:',\n local = 'local:',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport enum SNAP_STREAM_NAMES {\n JSON_RPC = 'jsonRpc',\n COMMAND = 'command',\n}\n/* eslint-enable @typescript-eslint/naming-convention */\n\n// The snap is the callee\nexport type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;\n\ntype ObjectParameters<\n Type extends Record<string, (...args: any[]) => unknown>,\n> = Parameters<Type[keyof Type]>;\n\nexport type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;\n\ntype UriOptions<Type extends string> = {\n protocol?: Struct<Type>;\n hash?: Struct<Type>;\n port?: Struct<Type>;\n hostname?: Struct<Type>;\n pathname?: Struct<Type>;\n search?: Struct<Type>;\n};\n\nexport const uri = (opts: UriOptions<any> = {}) =>\n refine(union([string(), instance(URL)]), 'uri', (value) => {\n try {\n const url = new URL(value);\n\n const UrlStruct = type(opts);\n assertSuperstruct(url, UrlStruct);\n return true;\n } catch {\n return `Expected URL, got \"${value.toString()}\".`;\n }\n });\n\n/**\n * Returns whether a given value is a valid URL.\n *\n * @param url - The value to check.\n * @param opts - Optional constraints for url checking.\n * @returns Whether `url` is valid URL or not.\n */\nexport function isValidUrl(\n url: unknown,\n opts: UriOptions<any> = {},\n): url is string | URL {\n return is(url, uri(opts));\n}\n\n// redefining here to avoid circular dependency\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\nexport type SnapsPermissionRequest = {\n [WALLET_SNAP_PERMISSION_KEY]: {\n caveats: [\n {\n type: SnapCaveatType.SnapIds;\n value: Record<string, Json>;\n },\n ];\n };\n};\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,UAAU;AAAA,OACL;AAGP,SAAS,qBAAqB;AAQvB,IAAK,mBAAL,kBAAKA,sBAAL;AACL,EAAAA,kBAAA,iBAAc;AACd,EAAAA,kBAAA,cAAW;AAFD,SAAAA;AAAA,GAAA;AAKL,IAAM,aAAa;AAAA,EACxB;AAAA,IACE,OAAO;AAAA,IACP;AAAA,EACF;AAAA,EACA;AAAA,EACA;AACF;AAIO,IAAM,2BAA2B,KAAK;AAAA,EAC3C,SAAS;AAAA,EACT,MAAM;AAAA,EACN,MAAM,SAAS,KAAK,OAAO,GAAG,GAAG,QAAQ,CAAC;AAAA,EAC1C,YAAY;AAAA,IACV,OAAO;AAAA,MACL,MAAM,KAAK,OAAO,GAAG,GAAG,QAAQ;AAAA,MAChC,KAAK,KAAK,OAAO,GAAG,GAAG,QAAQ;AAAA,IACjC,CAAC;AAAA,EACH;AACF,CAAC;AA0CM,IAAK,iBAAL,kBAAKC,oBAAL;AACL,EAAAA,gBAAA,SAAM;AACN,EAAAA,gBAAA,WAAQ;AAFE,SAAAA;AAAA,GAAA;AAOL,IAAK,oBAAL,kBAAKC,uBAAL;AACL,EAAAA,mBAAA,cAAW;AACX,EAAAA,mBAAA,aAAU;AAFA,SAAAA;AAAA,GAAA;AAwBL,IAAM,MAAM,CAAC,OAAwB,CAAC,MAC3C,OAAO,MAAM,CAAC,OAAO,GAAG,SAAS,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,UAAU;AACzD,MAAI;AACF,UAAM,MAAM,IAAI,IAAI,KAAK;AAEzB,UAAM,YAAY,KAAK,IAAI;AAC3B,sBAAkB,KAAK,SAAS;AAChC,WAAO;AAAA,EACT,QAAQ;AACN,WAAO,sBAAsB,MAAM,SAAS,CAAC;AAAA,EAC/C;AACF,CAAC;AASI,SAAS,WACd,KACA,OAAwB,CAAC,GACJ;AACrB,SAAO,GAAG,KAAK,IAAI,IAAI,CAAC;AAC1B;AAGO,IAAM,6BAA6B;","names":["NpmSnapFileNames","SnapIdPrefixes","SNAP_STREAM_NAMES"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/manifest/validators/version-match.ts
|
|
2
|
+
var versionMatch = {
|
|
3
|
+
severity: "error",
|
|
4
|
+
semanticCheck(files, context) {
|
|
5
|
+
const packageJsonVersion = files.packageJson.result.version;
|
|
6
|
+
const manifestPackageVersion = files.manifest.result.version;
|
|
7
|
+
if (packageJsonVersion !== manifestPackageVersion) {
|
|
8
|
+
context.report(
|
|
9
|
+
`"${"snap.manifest.json" /* Manifest */}" npm package version ("${manifestPackageVersion}") does not match the "${"package.json" /* PackageJson */}" "version" field ("${packageJsonVersion}").`,
|
|
10
|
+
({ manifest }) => {
|
|
11
|
+
manifest.version = packageJsonVersion;
|
|
12
|
+
return { manifest };
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.versionMatch = versionMatch;
|
|
22
|
+
//# sourceMappingURL=chunk-N4MA537G.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/validators/version-match.ts"],"names":[],"mappings":";AAMO,IAAM,eAA8B;AAAA,EACzC,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,UAAM,qBAAqB,MAAM,YAAY,OAAO;AACpD,UAAM,yBAAyB,MAAM,SAAS,OAAO;AACrD,QAAI,uBAAuB,wBAAwB;AACjD,cAAQ;AAAA,QACN,uCAA6B,2BAA2B,sBAAsB,0DAAsD,uBAAuB,kBAAkB;AAAA,QAC7K,CAAC,EAAE,SAAS,MAAM;AAChB,mBAAS,UAAU;AACnB,iBAAO,EAAE,SAAS;AAAA,QACpB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import { NpmSnapFileNames } from '../../types';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the version in manifest is the same as in package.json.\n */\nexport const versionMatch: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const packageJsonVersion = files.packageJson.result.version;\n const manifestPackageVersion = files.manifest.result.version;\n if (packageJsonVersion !== manifestPackageVersion) {\n context.report(\n `\"${NpmSnapFileNames.Manifest}\" npm package version (\"${manifestPackageVersion}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"version\" field (\"${packageJsonVersion}\").`,\n ({ manifest }) => {\n manifest.version = packageJsonVersion;\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-NNYGTNHP.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
SnapIdPrefixes,
|
|
3
3
|
uri
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-N2JAYIUP.mjs";
|
|
5
5
|
import {
|
|
6
6
|
checksumFiles
|
|
7
7
|
} from "./chunk-XF2AZMWG.mjs";
|
|
@@ -38,12 +38,6 @@ var SnapStatusEvents = /* @__PURE__ */ ((SnapStatusEvents2) => {
|
|
|
38
38
|
SnapStatusEvents2["Update"] = "UPDATE";
|
|
39
39
|
return SnapStatusEvents2;
|
|
40
40
|
})(SnapStatusEvents || {});
|
|
41
|
-
var ProgrammaticallyFixableSnapError = class extends Error {
|
|
42
|
-
constructor(message, reason) {
|
|
43
|
-
super(message);
|
|
44
|
-
this.reason = reason;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
41
|
function getChecksummableManifest(manifest) {
|
|
48
42
|
const manifestCopy = manifest.clone();
|
|
49
43
|
delete manifestCopy.result.source.shasum;
|
|
@@ -63,10 +57,7 @@ async function getSnapChecksum(files) {
|
|
|
63
57
|
}
|
|
64
58
|
async function validateSnapShasum(files, errorMessage = "Invalid Snap manifest: manifest shasum does not match computed shasum.") {
|
|
65
59
|
if (files.manifest.result.source.shasum !== await getSnapChecksum(files)) {
|
|
66
|
-
throw new
|
|
67
|
-
errorMessage,
|
|
68
|
-
'"shasum" field mismatch' /* ShasumMismatch */
|
|
69
|
-
);
|
|
60
|
+
throw new Error(errorMessage);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
var LOCALHOST_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]"];
|
|
@@ -174,7 +165,6 @@ export {
|
|
|
174
165
|
PROPOSED_NAME_REGEX,
|
|
175
166
|
SnapStatus,
|
|
176
167
|
SnapStatusEvents,
|
|
177
|
-
ProgrammaticallyFixableSnapError,
|
|
178
168
|
getSnapChecksum,
|
|
179
169
|
validateSnapShasum,
|
|
180
170
|
LOCALHOST_HOSTNAMES,
|
|
@@ -190,4 +180,4 @@ export {
|
|
|
190
180
|
isSnapPermitted,
|
|
191
181
|
verifyRequestedSnapPermissions
|
|
192
182
|
};
|
|
193
|
-
//# sourceMappingURL=chunk-
|
|
183
|
+
//# sourceMappingURL=chunk-NSVVZNSD.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 { Struct } from '@metamask/superstruct';\nimport {\n empty,\n enums,\n intersection,\n literal,\n pattern,\n refine,\n string,\n union,\n validate,\n} from '@metamask/superstruct';\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 validateNPMPackage from 'validate-npm-package-name';\n\nimport { SnapCaveatType } from './caveats';\nimport { checksumFiles } from './checksum';\nimport type { LocalizationFile } from './localization';\nimport type {\n InitialConnections,\n SnapManifest,\n SnapPermissions,\n} from './manifest/validation';\nimport type { FetchedSnapFiles, SnapsPermissionRequest } from './types';\nimport { SnapIdPrefixes, 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 connections of the Snap, optional, requested on installation.\n */\n initialConnections?: InitialConnections;\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 /**\n * Flag to signal whether this snap should be hidden from the user or not.\n */\n hidden?: boolean;\n};\n\nexport type TruncatedSnapFields =\n | 'id'\n | 'initialPermissions'\n | 'version'\n | 'enabled'\n | 'blocked';\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 Error(errorMessage);\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"],"m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
+
import {
|
|
5
|
+
isSnapIcon
|
|
6
|
+
} from "./chunk-EYWMVDCD.mjs";
|
|
7
|
+
import {
|
|
8
|
+
isSnapManifest
|
|
9
|
+
} from "./chunk-MDOG3S4V.mjs";
|
|
10
|
+
import {
|
|
11
|
+
manifestLocalization
|
|
12
|
+
} from "./chunk-TYWGZIOF.mjs";
|
|
13
|
+
import {
|
|
14
|
+
packageJsonRecommendedFields
|
|
15
|
+
} from "./chunk-SKKANJ45.mjs";
|
|
16
|
+
import {
|
|
17
|
+
packageNameMatch
|
|
18
|
+
} from "./chunk-MFGLB75H.mjs";
|
|
19
|
+
import {
|
|
20
|
+
repositoryMatch
|
|
21
|
+
} from "./chunk-5FTBWYCW.mjs";
|
|
22
|
+
import {
|
|
23
|
+
versionMatch
|
|
24
|
+
} from "./chunk-PO5BBHHX.mjs";
|
|
25
|
+
import {
|
|
26
|
+
checksum
|
|
27
|
+
} from "./chunk-DKO64Y4H.mjs";
|
|
28
|
+
import {
|
|
29
|
+
expectedFiles
|
|
30
|
+
} from "./chunk-4BGZ2CHC.mjs";
|
|
31
|
+
import {
|
|
32
|
+
iconDeclared
|
|
33
|
+
} from "./chunk-MQURBEO4.mjs";
|
|
34
|
+
import {
|
|
35
|
+
iconDimensions
|
|
36
|
+
} from "./chunk-HY4W6BUH.mjs";
|
|
37
|
+
import {
|
|
38
|
+
iconMissing
|
|
39
|
+
} from "./chunk-RRFKK45V.mjs";
|
|
40
|
+
import {
|
|
41
|
+
isLocalizationFile
|
|
42
|
+
} from "./chunk-4RYTYEUQ.mjs";
|
|
43
|
+
import {
|
|
44
|
+
__export
|
|
45
|
+
} from "./chunk-3RUWAMJT.mjs";
|
|
46
|
+
|
|
47
|
+
// src/manifest/validators/index.ts
|
|
48
|
+
var validators_exports = {};
|
|
49
|
+
__export(validators_exports, {
|
|
50
|
+
checksum: () => checksum,
|
|
51
|
+
expectedFiles: () => expectedFiles,
|
|
52
|
+
iconDeclared: () => iconDeclared,
|
|
53
|
+
iconDimensions: () => iconDimensions,
|
|
54
|
+
iconMissing: () => iconMissing,
|
|
55
|
+
isLocalizationFile: () => isLocalizationFile,
|
|
56
|
+
isPackageJson: () => isPackageJson,
|
|
57
|
+
isSnapIcon: () => isSnapIcon,
|
|
58
|
+
isSnapManifest: () => isSnapManifest,
|
|
59
|
+
manifestLocalization: () => manifestLocalization,
|
|
60
|
+
packageJsonRecommendedFields: () => packageJsonRecommendedFields,
|
|
61
|
+
packageNameMatch: () => packageNameMatch,
|
|
62
|
+
repositoryMatch: () => repositoryMatch,
|
|
63
|
+
versionMatch: () => versionMatch
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
export {
|
|
67
|
+
validators_exports
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=chunk-PAOTMYIM.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/validators/index.ts"],"sourcesContent":["export * from './checksum';\nexport * from './expected-files';\nexport * from './icon-dimensions';\nexport * from './is-localization-file';\nexport * from './is-package-json';\nexport * from './is-snap-icon';\nexport * from './is-snap-manifest';\nexport * from './manifest-localization';\nexport * from './package-json-recommended-fields';\nexport * from './package-name-match';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;","names":[]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// src/manifest/validators/version-match.ts
|
|
2
|
+
var versionMatch = {
|
|
3
|
+
severity: "error",
|
|
4
|
+
semanticCheck(files, context) {
|
|
5
|
+
const packageJsonVersion = files.packageJson.result.version;
|
|
6
|
+
const manifestPackageVersion = files.manifest.result.version;
|
|
7
|
+
if (packageJsonVersion !== manifestPackageVersion) {
|
|
8
|
+
context.report(
|
|
9
|
+
`"${"snap.manifest.json" /* Manifest */}" npm package version ("${manifestPackageVersion}") does not match the "${"package.json" /* PackageJson */}" "version" field ("${packageJsonVersion}").`,
|
|
10
|
+
({ manifest }) => {
|
|
11
|
+
manifest.version = packageJsonVersion;
|
|
12
|
+
return { manifest };
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export {
|
|
20
|
+
versionMatch
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=chunk-PO5BBHHX.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/validators/version-match.ts"],"sourcesContent":["import { NpmSnapFileNames } from '../../types';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the version in manifest is the same as in package.json.\n */\nexport const versionMatch: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const packageJsonVersion = files.packageJson.result.version;\n const manifestPackageVersion = files.manifest.result.version;\n if (packageJsonVersion !== manifestPackageVersion) {\n context.report(\n `\"${NpmSnapFileNames.Manifest}\" npm package version (\"${manifestPackageVersion}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"version\" field (\"${packageJsonVersion}\").`,\n ({ manifest }) => {\n manifest.version = packageJsonVersion;\n return { manifest };\n },\n );\n }\n },\n};\n"],"mappings":";AAMO,IAAM,eAA8B;AAAA,EACzC,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,UAAM,qBAAqB,MAAM,YAAY,OAAO;AACpD,UAAM,yBAAyB,MAAM,SAAS,OAAO;AACrD,QAAI,uBAAuB,wBAAwB;AACjD,cAAQ;AAAA,QACN,uCAA6B,2BAA2B,sBAAsB,0DAAsD,uBAAuB,kBAAkB;AAAA,QAC7K,CAAC,EAAE,SAAS,MAAM;AAChB,mBAAS,UAAU;AACnB,iBAAO,EAAE,SAAS;AAAA,QACpB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
__privateAdd,
|
|
3
3
|
__privateGet,
|
|
4
4
|
__privateSet
|
|
5
|
-
} from "./chunk-
|
|
5
|
+
} from "./chunk-3RUWAMJT.mjs";
|
|
6
6
|
|
|
7
7
|
// src/errors.ts
|
|
8
8
|
import {
|
|
@@ -148,4 +148,4 @@ export {
|
|
|
148
148
|
isWrappedSnapError,
|
|
149
149
|
unwrapError
|
|
150
150
|
};
|
|
151
|
-
//# sourceMappingURL=chunk-
|
|
151
|
+
//# sourceMappingURL=chunk-PZF4KWU2.mjs.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk37EUH3KZjs = require('./chunk-37EUH3KZ.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunk53QXTM77js = require('./chunk-53QXTM77.js');
|
|
7
|
+
|
|
8
|
+
// src/manifest/validators/is-snap-manifest.ts
|
|
9
|
+
var _superstruct = require('@metamask/superstruct');
|
|
10
|
+
var isSnapManifest = {
|
|
11
|
+
severity: "error",
|
|
12
|
+
structureCheck(files, context) {
|
|
13
|
+
if (!files.manifest) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
const [error] = _superstruct.validate.call(void 0, files.manifest.result, _chunk37EUH3KZjs.SnapManifestStruct);
|
|
17
|
+
if (error) {
|
|
18
|
+
for (const failure of error.failures()) {
|
|
19
|
+
context.report(
|
|
20
|
+
`"${"snap.manifest.json" /* Manifest */}" is invalid: ${_chunk53QXTM77js.getStructFailureMessage.call(void 0,
|
|
21
|
+
_chunk37EUH3KZjs.SnapManifestStruct,
|
|
22
|
+
failure,
|
|
23
|
+
false
|
|
24
|
+
)}`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
exports.isSnapManifest = isSnapManifest;
|
|
34
|
+
//# sourceMappingURL=chunk-QD3LTING.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/validators/is-snap-manifest.ts"],"names":[],"mappings":";;;;;;;;AAAA,SAAS,gBAAgB;AAUlB,IAAM,iBAAgC;AAAA,EAC3C,UAAU;AAAA,EACV,eAAe,OAAO,SAAS;AAC7B,QAAI,CAAC,MAAM,UAAU;AACnB;AAAA,IACF;AACA,UAAM,CAAC,KAAK,IAAI,SAAS,MAAM,SAAS,QAAQ,kBAAkB;AAClE,QAAI,OAAO;AACT,iBAAW,WAAW,MAAM,SAAS,GAAG;AACtC,gBAAQ;AAAA,UACN,uCAA6B,iBAAiB;AAAA,YAC5C;AAAA,YACA;AAAA,YACA;AAAA,UACF,CAAC;AAAA,QACH;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import { validate } from '@metamask/superstruct';\n\nimport { getStructFailureMessage } from '../../structs';\nimport { NpmSnapFileNames } from '../../types';\nimport { SnapManifestStruct } from '../validation';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Verify the structure of snap.manifest.json.\n */\nexport const isSnapManifest: ValidatorMeta = {\n severity: 'error',\n structureCheck(files, context) {\n if (!files.manifest) {\n return;\n }\n const [error] = validate(files.manifest.result, SnapManifestStruct);\n if (error) {\n for (const failure of error.failures()) {\n context.report(\n `\"${NpmSnapFileNames.Manifest}\" is invalid: ${getStructFailureMessage(\n SnapManifestStruct,\n failure,\n false,\n )}`,\n );\n }\n }\n },\n};\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunk5UAPBOKOjs = require('./chunk-5UAPBOKO.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkCPG2UGAAjs = require('./chunk-CPG2UGAA.js');
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
var _chunkQD3LTINGjs = require('./chunk-QD3LTING.js');
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
var _chunkLQSEBGOXjs = require('./chunk-LQSEBGOX.js');
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
var _chunk6YJWU77Ljs = require('./chunk-6YJWU77L.js');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
var _chunkT5ZOOZ46js = require('./chunk-T5ZOOZ46.js');
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
var _chunkBPK5BH7Kjs = require('./chunk-BPK5BH7K.js');
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
var _chunkN4MA537Gjs = require('./chunk-N4MA537G.js');
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
var _chunkVEPYH26Pjs = require('./chunk-VEPYH26P.js');
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
var _chunkIVDERT5Wjs = require('./chunk-IVDERT5W.js');
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
var _chunkYL2EHYAAjs = require('./chunk-YL2EHYAA.js');
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
var _chunkGJAVOB7Bjs = require('./chunk-GJAVOB7B.js');
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
var _chunkSYYDKPK3js = require('./chunk-SYYDKPK3.js');
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
var _chunkL2DHOOBXjs = require('./chunk-L2DHOOBX.js');
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
var _chunkS3BWTUTZjs = require('./chunk-S3BWTUTZ.js');
|
|
46
|
+
|
|
47
|
+
// src/manifest/validators/index.ts
|
|
48
|
+
var validators_exports = {};
|
|
49
|
+
_chunkS3BWTUTZjs.__export.call(void 0, validators_exports, {
|
|
50
|
+
checksum: () => _chunkVEPYH26Pjs.checksum,
|
|
51
|
+
expectedFiles: () => _chunkIVDERT5Wjs.expectedFiles,
|
|
52
|
+
iconDeclared: () => _chunkYL2EHYAAjs.iconDeclared,
|
|
53
|
+
iconDimensions: () => _chunkGJAVOB7Bjs.iconDimensions,
|
|
54
|
+
iconMissing: () => _chunkSYYDKPK3js.iconMissing,
|
|
55
|
+
isLocalizationFile: () => _chunkL2DHOOBXjs.isLocalizationFile,
|
|
56
|
+
isPackageJson: () => _chunk5UAPBOKOjs.isPackageJson,
|
|
57
|
+
isSnapIcon: () => _chunkCPG2UGAAjs.isSnapIcon,
|
|
58
|
+
isSnapManifest: () => _chunkQD3LTINGjs.isSnapManifest,
|
|
59
|
+
manifestLocalization: () => _chunkLQSEBGOXjs.manifestLocalization,
|
|
60
|
+
packageJsonRecommendedFields: () => _chunk6YJWU77Ljs.packageJsonRecommendedFields,
|
|
61
|
+
packageNameMatch: () => _chunkT5ZOOZ46js.packageNameMatch,
|
|
62
|
+
repositoryMatch: () => _chunkBPK5BH7Kjs.repositoryMatch,
|
|
63
|
+
versionMatch: () => _chunkN4MA537Gjs.versionMatch
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
exports.validators_exports = validators_exports;
|
|
69
|
+
//# sourceMappingURL=chunk-RNMJQSVQ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export * from './checksum';\nexport * from './expected-files';\nexport * from './icon-dimensions';\nexport * from './is-localization-file';\nexport * from './is-package-json';\nexport * from './is-snap-icon';\nexport * from './is-snap-manifest';\nexport * from './manifest-localization';\nexport * from './package-json-recommended-fields';\nexport * from './package-name-match';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// src/manifest/validators/icon-missing.ts
|
|
2
|
+
var iconMissing = {
|
|
3
|
+
severity: "error",
|
|
4
|
+
semanticCheck(files, context) {
|
|
5
|
+
const { iconPath } = files.manifest.result.source.location.npm;
|
|
6
|
+
if (iconPath && !files.svgIcon) {
|
|
7
|
+
context.report(`Could not find icon "${iconPath}".`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export {
|
|
13
|
+
iconMissing
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=chunk-RRFKK45V.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/validators/icon-missing.ts"],"sourcesContent":["import type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if declared icon exists on filesystem.\n */\nexport const iconMissing: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const { iconPath } = files.manifest.result.source.location.npm;\n if (iconPath && !files.svgIcon) {\n context.report(`Could not find icon \"${iconPath}\".`);\n }\n },\n};\n"],"mappings":";AAKO,IAAM,cAA6B;AAAA,EACxC,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,UAAM,EAAE,SAAS,IAAI,MAAM,SAAS,OAAO,OAAO,SAAS;AAC3D,QAAI,YAAY,CAAC,MAAM,SAAS;AAC9B,cAAQ,OAAO,wBAAwB,QAAQ,IAAI;AAAA,IACrD;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});var __defProp = Object.defineProperty;
|
|
2
|
+
var __export = (target, all) => {
|
|
3
|
+
for (var name in all)
|
|
4
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
5
|
+
};
|
|
6
|
+
var __accessCheck = (obj, member, msg) => {
|
|
2
7
|
if (!member.has(obj))
|
|
3
8
|
throw TypeError("Cannot " + msg);
|
|
4
9
|
};
|
|
@@ -21,5 +26,6 @@ var __privateSet = (obj, member, value, setter) => {
|
|
|
21
26
|
|
|
22
27
|
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
|
|
30
|
+
exports.__export = __export; exports.__privateGet = __privateGet; exports.__privateAdd = __privateAdd; exports.__privateSet = __privateSet;
|
|
31
|
+
//# sourceMappingURL=chunk-S3BWTUTZ.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/manifest/validators/package-json-recommended-fields.ts
|
|
2
|
+
var RECOMMENDED_FIELDS = ["repository"];
|
|
3
|
+
var packageJsonRecommendedFields = {
|
|
4
|
+
severity: "warning",
|
|
5
|
+
semanticCheck(files, context) {
|
|
6
|
+
for (const recommendedField of RECOMMENDED_FIELDS) {
|
|
7
|
+
if (!files.packageJson.result[recommendedField]) {
|
|
8
|
+
context.report(
|
|
9
|
+
`Missing recommended package.json property: "${recommendedField}".`
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export {
|
|
17
|
+
packageJsonRecommendedFields
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=chunk-SKKANJ45.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/validators/package-json-recommended-fields.ts"],"sourcesContent":["import type { ValidatorMeta } from '../validator-types';\n\nconst RECOMMENDED_FIELDS = ['repository'] as const;\n\n/**\n * Check if package.json contains recommended fields.\n */\nexport const packageJsonRecommendedFields: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n for (const recommendedField of RECOMMENDED_FIELDS) {\n if (!files.packageJson.result[recommendedField]) {\n context.report(\n `Missing recommended package.json property: \"${recommendedField}\".`,\n );\n }\n }\n },\n};\n"],"mappings":";AAEA,IAAM,qBAAqB,CAAC,YAAY;AAKjC,IAAM,+BAA8C;AAAA,EACzD,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,eAAW,oBAAoB,oBAAoB;AACjD,UAAI,CAAC,MAAM,YAAY,OAAO,gBAAgB,GAAG;AAC/C,gBAAQ;AAAA,UACN,+CAA+C,gBAAgB;AAAA,QACjE;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/manifest/validators/icon-missing.ts
|
|
2
|
+
var iconMissing = {
|
|
3
|
+
severity: "error",
|
|
4
|
+
semanticCheck(files, context) {
|
|
5
|
+
const { iconPath } = files.manifest.result.source.location.npm;
|
|
6
|
+
if (iconPath && !files.svgIcon) {
|
|
7
|
+
context.report(`Could not find icon "${iconPath}".`);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.iconMissing = iconMissing;
|
|
15
|
+
//# sourceMappingURL=chunk-SYYDKPK3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/validators/icon-missing.ts"],"names":[],"mappings":";AAKO,IAAM,cAA6B;AAAA,EACxC,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,UAAM,EAAE,SAAS,IAAI,MAAM,SAAS,OAAO,OAAO,SAAS;AAC3D,QAAI,YAAY,CAAC,MAAM,SAAS;AAC9B,cAAQ,OAAO,wBAAwB,QAAQ,IAAI;AAAA,IACrD;AAAA,EACF;AACF","sourcesContent":["import type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if declared icon exists on filesystem.\n */\nexport const iconMissing: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const { iconPath } = files.manifest.result.source.location.npm;\n if (iconPath && !files.svgIcon) {\n context.report(`Could not find icon \"${iconPath}\".`);\n }\n },\n};\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/manifest/validators/package-name-match.ts
|
|
2
|
+
var packageNameMatch = {
|
|
3
|
+
severity: "error",
|
|
4
|
+
semanticCheck(files, context) {
|
|
5
|
+
const packageJsonName = files.packageJson.result.name;
|
|
6
|
+
const manifestPackageName = files.manifest.result.source.location.npm.packageName;
|
|
7
|
+
if (packageJsonName !== manifestPackageName) {
|
|
8
|
+
context.report(
|
|
9
|
+
`"${"snap.manifest.json" /* Manifest */}" npm package name ("${manifestPackageName}") does not match the "${"package.json" /* PackageJson */}" "name" field ("${packageJsonName}").`,
|
|
10
|
+
({ manifest }) => {
|
|
11
|
+
manifest.source.location.npm.packageName = packageJsonName;
|
|
12
|
+
return { manifest };
|
|
13
|
+
}
|
|
14
|
+
);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
exports.packageNameMatch = packageNameMatch;
|
|
22
|
+
//# sourceMappingURL=chunk-T5ZOOZ46.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/manifest/validators/package-name-match.ts"],"names":[],"mappings":";AAMO,IAAM,mBAAkC;AAAA,EAC7C,UAAU;AAAA,EACV,cAAc,OAAO,SAAS;AAC5B,UAAM,kBAAkB,MAAM,YAAY,OAAO;AACjD,UAAM,sBACJ,MAAM,SAAS,OAAO,OAAO,SAAS,IAAI;AAC5C,QAAI,oBAAoB,qBAAqB;AAC3C,cAAQ;AAAA,QACN,uCAA6B,wBAAwB,mBAAmB,0DAAsD,oBAAoB,eAAe;AAAA,QACjK,CAAC,EAAE,SAAS,MAAM;AAChB,mBAAS,OAAO,SAAS,IAAI,cAAc;AAC3C,iBAAO,EAAE,SAAS;AAAA,QACpB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF","sourcesContent":["import { NpmSnapFileNames } from '../../types';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the package name in manifest matches package.json name.\n */\nexport const packageNameMatch: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const packageJsonName = files.packageJson.result.name;\n const manifestPackageName =\n files.manifest.result.source.location.npm.packageName;\n if (packageJsonName !== manifestPackageName) {\n context.report(\n `\"${NpmSnapFileNames.Manifest}\" npm package name (\"${manifestPackageName}\") does not match the \"${NpmSnapFileNames.PackageJson}\" \"name\" field (\"${packageJsonName}\").`,\n ({ manifest }) => {\n manifest.source.location.npm.packageName = packageJsonName;\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
var
|
|
4
|
+
var _chunkMWAZGSROjs = require('./chunk-MWAZGSRO.js');
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
var _chunkAMW2VJ3Njs = require('./chunk-AMW2VJ3N.js');
|
|
@@ -38,12 +38,6 @@ var SnapStatusEvents = /* @__PURE__ */ ((SnapStatusEvents2) => {
|
|
|
38
38
|
SnapStatusEvents2["Update"] = "UPDATE";
|
|
39
39
|
return SnapStatusEvents2;
|
|
40
40
|
})(SnapStatusEvents || {});
|
|
41
|
-
var ProgrammaticallyFixableSnapError = class extends Error {
|
|
42
|
-
constructor(message, reason) {
|
|
43
|
-
super(message);
|
|
44
|
-
this.reason = reason;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
41
|
function getChecksummableManifest(manifest) {
|
|
48
42
|
const manifestCopy = manifest.clone();
|
|
49
43
|
delete manifestCopy.result.source.shasum;
|
|
@@ -63,15 +57,12 @@ async function getSnapChecksum(files) {
|
|
|
63
57
|
}
|
|
64
58
|
async function validateSnapShasum(files, errorMessage = "Invalid Snap manifest: manifest shasum does not match computed shasum.") {
|
|
65
59
|
if (files.manifest.result.source.shasum !== await getSnapChecksum(files)) {
|
|
66
|
-
throw new
|
|
67
|
-
errorMessage,
|
|
68
|
-
'"shasum" field mismatch' /* ShasumMismatch */
|
|
69
|
-
);
|
|
60
|
+
throw new Error(errorMessage);
|
|
70
61
|
}
|
|
71
62
|
}
|
|
72
63
|
var LOCALHOST_HOSTNAMES = ["localhost", "127.0.0.1", "[::1]"];
|
|
73
64
|
var BaseSnapIdStruct = _superstruct.pattern.call(void 0, _superstruct.string.call(void 0, ), /^[\x21-\x7E]*$/u);
|
|
74
|
-
var LocalSnapIdSubUrlStruct =
|
|
65
|
+
var LocalSnapIdSubUrlStruct = _chunkMWAZGSROjs.uri.call(void 0, {
|
|
75
66
|
protocol: _superstruct.enums.call(void 0, ["http:", "https:"]),
|
|
76
67
|
hostname: _superstruct.enums.call(void 0, LOCALHOST_HOSTNAMES),
|
|
77
68
|
hash: _superstruct.empty.call(void 0, _superstruct.string.call(void 0, )),
|
|
@@ -93,7 +84,7 @@ var LocalSnapIdStruct = _superstruct.refine.call(void 0,
|
|
|
93
84
|
);
|
|
94
85
|
var NpmSnapIdStruct = _superstruct.intersection.call(void 0, [
|
|
95
86
|
BaseSnapIdStruct,
|
|
96
|
-
|
|
87
|
+
_chunkMWAZGSROjs.uri.call(void 0, {
|
|
97
88
|
protocol: _superstruct.literal.call(void 0, "npm:" /* npm */),
|
|
98
89
|
pathname: _superstruct.refine.call(void 0, _superstruct.string.call(void 0, ), "package name", function* (value) {
|
|
99
90
|
const normalized = value.startsWith("/") ? value.slice(1) : value;
|
|
@@ -114,7 +105,7 @@ var NpmSnapIdStruct = _superstruct.intersection.call(void 0, [
|
|
|
114
105
|
]);
|
|
115
106
|
var HttpSnapIdStruct = _superstruct.intersection.call(void 0, [
|
|
116
107
|
BaseSnapIdStruct,
|
|
117
|
-
|
|
108
|
+
_chunkMWAZGSROjs.uri.call(void 0, {
|
|
118
109
|
protocol: _superstruct.enums.call(void 0, ["http:", "https:"]),
|
|
119
110
|
search: _superstruct.empty.call(void 0, _superstruct.string.call(void 0, )),
|
|
120
111
|
hash: _superstruct.empty.call(void 0, _superstruct.string.call(void 0, ))
|
|
@@ -122,7 +113,7 @@ var HttpSnapIdStruct = _superstruct.intersection.call(void 0, [
|
|
|
122
113
|
]);
|
|
123
114
|
var SnapIdStruct = _superstruct.union.call(void 0, [NpmSnapIdStruct, LocalSnapIdStruct]);
|
|
124
115
|
function getSnapPrefix(snapId) {
|
|
125
|
-
const prefix = Object.values(
|
|
116
|
+
const prefix = Object.values(_chunkMWAZGSROjs.SnapIdPrefixes).find(
|
|
126
117
|
(possiblePrefix) => snapId.startsWith(possiblePrefix)
|
|
127
118
|
);
|
|
128
119
|
if (prefix !== void 0) {
|
|
@@ -188,6 +179,5 @@ function verifyRequestedSnapPermissions(requestedPermissions) {
|
|
|
188
179
|
|
|
189
180
|
|
|
190
181
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
//# sourceMappingURL=chunk-RD6BN2TQ.js.map
|
|
182
|
+
exports.PROPOSED_NAME_REGEX = PROPOSED_NAME_REGEX; exports.SnapStatus = SnapStatus; exports.SnapStatusEvents = SnapStatusEvents; exports.getSnapChecksum = getSnapChecksum; exports.validateSnapShasum = validateSnapShasum; exports.LOCALHOST_HOSTNAMES = LOCALHOST_HOSTNAMES; exports.BaseSnapIdStruct = BaseSnapIdStruct; exports.LocalSnapIdStruct = LocalSnapIdStruct; exports.NpmSnapIdStruct = NpmSnapIdStruct; exports.HttpSnapIdStruct = HttpSnapIdStruct; exports.SnapIdStruct = SnapIdStruct; exports.getSnapPrefix = getSnapPrefix; exports.stripSnapPrefix = stripSnapPrefix; exports.assertIsValidSnapId = assertIsValidSnapId; exports.isCaipChainId = isCaipChainId; exports.isSnapPermitted = isSnapPermitted; exports.verifyRequestedSnapPermissions = verifyRequestedSnapPermissions;
|
|
183
|
+
//# sourceMappingURL=chunk-TAMKWZ4E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["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AAM,OAAO,CAAC;AAAA,EACtB,CAAC;AACH,CAAC;AAEM,IAAM,eAAe,MAAM,CAAC,iBAAiB,iBAAiB,CAAC;AAQ/D,SAAS,cAAc,QAAgC;AAC5D,QAAM,SAAS,OAAO,OAAO,cAAc,EAAE;AAAA,IAAK,CAAC,mBACjD,OAAO,WAAW,cAAc;AAAA,EAClC;AACA,MAAI,WAAW,QAAW;AACxB,WAAO;AAAA,EACT;AACA,QAAM,IAAI,MAAM,mCAAmC,MAAM,GAAG;AAC9D;AAQO,SAAS,gBAAgB,QAAwB;AACtD,SAAO,OAAO,QAAQ,cAAc,MAAM,GAAG,EAAE;AACjD;AAQO,SAAS,oBAAoB,OAAyC;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","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 { Struct } from '@metamask/superstruct';\nimport {\n empty,\n enums,\n intersection,\n literal,\n pattern,\n refine,\n string,\n union,\n validate,\n} from '@metamask/superstruct';\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 validateNPMPackage from 'validate-npm-package-name';\n\nimport { SnapCaveatType } from './caveats';\nimport { checksumFiles } from './checksum';\nimport type { LocalizationFile } from './localization';\nimport type {\n InitialConnections,\n SnapManifest,\n SnapPermissions,\n} from './manifest/validation';\nimport type { FetchedSnapFiles, SnapsPermissionRequest } from './types';\nimport { SnapIdPrefixes, 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 connections of the Snap, optional, requested on installation.\n */\n initialConnections?: InitialConnections;\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 /**\n * Flag to signal whether this snap should be hidden from the user or not.\n */\n hidden?: boolean;\n};\n\nexport type TruncatedSnapFields =\n | 'id'\n | 'initialPermissions'\n | 'version'\n | 'enabled'\n | 'blocked';\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 Error(errorMessage);\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"]}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {
|
|
2
|
+
getLocalizedSnapManifest
|
|
3
|
+
} from "./chunk-CJK7DDV2.mjs";
|
|
4
|
+
|
|
5
|
+
// src/manifest/validators/manifest-localization.ts
|
|
6
|
+
import { getErrorMessage } from "@metamask/snaps-sdk";
|
|
7
|
+
var manifestLocalization = {
|
|
8
|
+
severity: "error",
|
|
9
|
+
semanticCheck(files, context) {
|
|
10
|
+
const manifest = files.manifest.result;
|
|
11
|
+
const localizations = files.localizationFiles.map(
|
|
12
|
+
(file) => file.result
|
|
13
|
+
);
|
|
14
|
+
const locales = [
|
|
15
|
+
"en",
|
|
16
|
+
// The manifest must be able to be localized in English.
|
|
17
|
+
...localizations.map(({ locale }) => locale).filter((locale) => locale !== "en")
|
|
18
|
+
];
|
|
19
|
+
for (const locale of locales) {
|
|
20
|
+
try {
|
|
21
|
+
getLocalizedSnapManifest(manifest, locale, localizations);
|
|
22
|
+
} catch (error) {
|
|
23
|
+
context.report(
|
|
24
|
+
`Failed to localize Snap manifest: ${getErrorMessage(error)}`
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export {
|
|
32
|
+
manifestLocalization
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=chunk-TYWGZIOF.mjs.map
|