@metamask/snaps-utils 11.4.0 → 11.6.0
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/base64.cjs +3 -2
- package/dist/base64.cjs.map +1 -1
- package/dist/base64.d.cts.map +1 -1
- package/dist/base64.d.mts.map +1 -1
- package/dist/base64.mjs +3 -2
- package/dist/base64.mjs.map +1 -1
- package/dist/derivation-paths.cjs +5 -0
- package/dist/derivation-paths.cjs.map +1 -1
- package/dist/derivation-paths.d.cts.map +1 -1
- package/dist/derivation-paths.d.mts.map +1 -1
- package/dist/derivation-paths.mjs +5 -0
- package/dist/derivation-paths.mjs.map +1 -1
- package/dist/json.cjs +5 -4
- package/dist/json.cjs.map +1 -1
- package/dist/json.d.cts +3 -2
- package/dist/json.d.cts.map +1 -1
- package/dist/json.d.mts +3 -2
- package/dist/json.d.mts.map +1 -1
- package/dist/json.mjs +5 -4
- package/dist/json.mjs.map +1 -1
- package/dist/manifest/manifest.cjs +9 -5
- package/dist/manifest/manifest.cjs.map +1 -1
- package/dist/manifest/manifest.d.cts.map +1 -1
- package/dist/manifest/manifest.d.mts.map +1 -1
- package/dist/manifest/manifest.mjs +9 -5
- package/dist/manifest/manifest.mjs.map +1 -1
- package/dist/manifest/validator-types.cjs.map +1 -1
- package/dist/manifest/validator-types.d.cts +4 -2
- package/dist/manifest/validator-types.d.cts.map +1 -1
- package/dist/manifest/validator-types.d.mts +4 -2
- package/dist/manifest/validator-types.d.mts.map +1 -1
- package/dist/manifest/validator-types.mjs.map +1 -1
- package/dist/manifest/validator.cjs +11 -2
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.d.cts.map +1 -1
- package/dist/manifest/validator.d.mts.map +1 -1
- package/dist/manifest/validator.mjs +11 -2
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/manifest/validators/checksum.cjs +1 -1
- package/dist/manifest/validators/checksum.cjs.map +1 -1
- package/dist/manifest/validators/checksum.d.cts.map +1 -1
- package/dist/manifest/validators/checksum.d.mts.map +1 -1
- package/dist/manifest/validators/checksum.mjs +1 -1
- package/dist/manifest/validators/checksum.mjs.map +1 -1
- package/dist/manifest/validators/expected-files.cjs +1 -1
- package/dist/manifest/validators/expected-files.cjs.map +1 -1
- package/dist/manifest/validators/expected-files.d.cts.map +1 -1
- package/dist/manifest/validators/expected-files.d.mts.map +1 -1
- package/dist/manifest/validators/expected-files.mjs +1 -1
- package/dist/manifest/validators/expected-files.mjs.map +1 -1
- package/dist/manifest/validators/icon-declared.cjs +1 -1
- package/dist/manifest/validators/icon-declared.cjs.map +1 -1
- package/dist/manifest/validators/icon-declared.d.cts.map +1 -1
- package/dist/manifest/validators/icon-declared.d.mts.map +1 -1
- package/dist/manifest/validators/icon-declared.mjs +1 -1
- package/dist/manifest/validators/icon-declared.mjs.map +1 -1
- package/dist/manifest/validators/icon-dimensions.cjs +1 -1
- package/dist/manifest/validators/icon-dimensions.cjs.map +1 -1
- package/dist/manifest/validators/icon-dimensions.d.cts.map +1 -1
- package/dist/manifest/validators/icon-dimensions.d.mts.map +1 -1
- package/dist/manifest/validators/icon-dimensions.mjs +1 -1
- package/dist/manifest/validators/icon-dimensions.mjs.map +1 -1
- package/dist/manifest/validators/icon-missing.cjs +1 -1
- package/dist/manifest/validators/icon-missing.cjs.map +1 -1
- package/dist/manifest/validators/icon-missing.mjs +1 -1
- package/dist/manifest/validators/icon-missing.mjs.map +1 -1
- package/dist/manifest/validators/is-localization-file.cjs +1 -1
- package/dist/manifest/validators/is-localization-file.cjs.map +1 -1
- package/dist/manifest/validators/is-localization-file.d.cts.map +1 -1
- package/dist/manifest/validators/is-localization-file.d.mts.map +1 -1
- package/dist/manifest/validators/is-localization-file.mjs +1 -1
- package/dist/manifest/validators/is-localization-file.mjs.map +1 -1
- package/dist/manifest/validators/is-package-json.cjs +1 -1
- package/dist/manifest/validators/is-package-json.cjs.map +1 -1
- package/dist/manifest/validators/is-package-json.d.cts.map +1 -1
- package/dist/manifest/validators/is-package-json.d.mts.map +1 -1
- package/dist/manifest/validators/is-package-json.mjs +1 -1
- package/dist/manifest/validators/is-package-json.mjs.map +1 -1
- package/dist/manifest/validators/is-snap-icon.cjs +1 -1
- package/dist/manifest/validators/is-snap-icon.cjs.map +1 -1
- package/dist/manifest/validators/is-snap-icon.mjs +1 -1
- package/dist/manifest/validators/is-snap-icon.mjs.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.cjs +1 -1
- package/dist/manifest/validators/is-snap-manifest.cjs.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.d.cts.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.d.mts.map +1 -1
- package/dist/manifest/validators/is-snap-manifest.mjs +1 -1
- package/dist/manifest/validators/is-snap-manifest.mjs.map +1 -1
- package/dist/manifest/validators/manifest-localization.cjs +1 -1
- package/dist/manifest/validators/manifest-localization.cjs.map +1 -1
- package/dist/manifest/validators/manifest-localization.d.cts.map +1 -1
- package/dist/manifest/validators/manifest-localization.d.mts.map +1 -1
- package/dist/manifest/validators/manifest-localization.mjs +1 -1
- package/dist/manifest/validators/manifest-localization.mjs.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.cjs +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.cjs.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.d.cts.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.d.mts.map +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.mjs +1 -1
- package/dist/manifest/validators/package-json-recommended-fields.mjs.map +1 -1
- package/dist/manifest/validators/package-name-match.cjs +1 -1
- package/dist/manifest/validators/package-name-match.cjs.map +1 -1
- package/dist/manifest/validators/package-name-match.d.cts.map +1 -1
- package/dist/manifest/validators/package-name-match.d.mts.map +1 -1
- package/dist/manifest/validators/package-name-match.mjs +1 -1
- package/dist/manifest/validators/package-name-match.mjs.map +1 -1
- package/dist/manifest/validators/platform-version.cjs +2 -2
- package/dist/manifest/validators/platform-version.cjs.map +1 -1
- package/dist/manifest/validators/platform-version.d.cts.map +1 -1
- package/dist/manifest/validators/platform-version.d.mts.map +1 -1
- package/dist/manifest/validators/platform-version.mjs +2 -2
- package/dist/manifest/validators/platform-version.mjs.map +1 -1
- package/dist/manifest/validators/production-platform-version.cjs +1 -1
- package/dist/manifest/validators/production-platform-version.cjs.map +1 -1
- package/dist/manifest/validators/production-platform-version.d.cts.map +1 -1
- package/dist/manifest/validators/production-platform-version.d.mts.map +1 -1
- package/dist/manifest/validators/production-platform-version.mjs +1 -1
- package/dist/manifest/validators/production-platform-version.mjs.map +1 -1
- package/dist/manifest/validators/repository-match.cjs +1 -1
- package/dist/manifest/validators/repository-match.cjs.map +1 -1
- package/dist/manifest/validators/repository-match.d.cts.map +1 -1
- package/dist/manifest/validators/repository-match.d.mts.map +1 -1
- package/dist/manifest/validators/repository-match.mjs +1 -1
- package/dist/manifest/validators/repository-match.mjs.map +1 -1
- package/dist/manifest/validators/unused-exports.cjs +2 -2
- package/dist/manifest/validators/unused-exports.cjs.map +1 -1
- package/dist/manifest/validators/unused-exports.d.cts.map +1 -1
- package/dist/manifest/validators/unused-exports.d.mts.map +1 -1
- package/dist/manifest/validators/unused-exports.mjs +2 -2
- package/dist/manifest/validators/unused-exports.mjs.map +1 -1
- package/dist/manifest/validators/version-match.cjs +1 -1
- package/dist/manifest/validators/version-match.cjs.map +1 -1
- package/dist/manifest/validators/version-match.d.cts.map +1 -1
- package/dist/manifest/validators/version-match.d.mts.map +1 -1
- package/dist/manifest/validators/version-match.mjs +1 -1
- package/dist/manifest/validators/version-match.mjs.map +1 -1
- package/dist/platform-version.cjs.map +1 -1
- package/dist/platform-version.d.cts +2 -1
- package/dist/platform-version.d.cts.map +1 -1
- package/dist/platform-version.d.mts +2 -1
- package/dist/platform-version.d.mts.map +1 -1
- package/dist/platform-version.mjs.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"repository-match.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/repository-match.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,UAAS,wBAAwB;;AAExC,OAAO,EAAE,SAAS,EAAE,6BAAyB;AAC7C,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAG/C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAkB;IAC5C,QAAQ,EAAE,OAAO;IACjB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,qBAAqB,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC;QAClE,MAAM,kBAAkB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC;QAC5D,IACE,CAAC,qBAAqB,IAAI,kBAAkB,CAAC;YAC7C,CAAC,SAAS,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,EACrD,CAAC;YACD,OAAO,CAAC,MAAM,CACZ,IAAI,gBAAgB,CAAC,QAAQ,4CAA4C,gBAAgB,CAAC,WAAW,uBAAuB,EAC5H,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,QAAQ,CAAC,UAAU,GAAG,qBAAqB;oBACzC,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC;oBAClC,CAAC,CAAC,SAAS,CAAC;gBACd,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import deepEqual from 'fast-deep-equal';\n\nimport { deepClone } from '../../deep-clone';\nimport { NpmSnapFileNames } from '../../types';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the repository object in manifest is the same as in package.json.\n */\nexport const repositoryMatch: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const packageJsonRepository = files.packageJson.result.repository;\n const manifestRepository = files.manifest.result.repository;\n if (\n (packageJsonRepository || manifestRepository) &&\n !deepEqual(packageJsonRepository, manifestRepository)\n ) {\n context.report(\n `\"${NpmSnapFileNames.Manifest}\" \"repository\" field does not match the \"${NpmSnapFileNames.PackageJson}\" \"repository\" field.`,\n ({ manifest }) => {\n manifest.repository = packageJsonRepository\n ? deepClone(packageJsonRepository)\n : undefined;\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"repository-match.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/repository-match.ts"],"names":[],"mappings":";;;;;;AAAA,OAAO,UAAS,wBAAwB;;AAExC,OAAO,EAAE,SAAS,EAAE,6BAAyB;AAC7C,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAG/C;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAAkB;IAC5C,QAAQ,EAAE,OAAO;IACjB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,qBAAqB,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,UAAU,CAAC;QAClE,MAAM,kBAAkB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC;QAC5D,IACE,CAAC,qBAAqB,IAAI,kBAAkB,CAAC;YAC7C,CAAC,SAAS,CAAC,qBAAqB,EAAE,kBAAkB,CAAC,EACrD,CAAC;YACD,OAAO,CAAC,MAAM,CACZ,kBAAkB,EAClB,IAAI,gBAAgB,CAAC,QAAQ,4CAA4C,gBAAgB,CAAC,WAAW,uBAAuB,EAC5H,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,QAAQ,CAAC,UAAU,GAAG,qBAAqB;oBACzC,CAAC,CAAC,SAAS,CAAC,qBAAqB,CAAC;oBAClC,CAAC,CAAC,SAAS,CAAC;gBACd,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import deepEqual from 'fast-deep-equal';\n\nimport { deepClone } from '../../deep-clone';\nimport { NpmSnapFileNames } from '../../types';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the repository object in manifest is the same as in package.json.\n */\nexport const repositoryMatch: ValidatorMeta = {\n severity: 'error',\n semanticCheck(files, context) {\n const packageJsonRepository = files.packageJson.result.repository;\n const manifestRepository = files.manifest.result.repository;\n if (\n (packageJsonRepository || manifestRepository) &&\n !deepEqual(packageJsonRepository, manifestRepository)\n ) {\n context.report(\n 'repository-match',\n `\"${NpmSnapFileNames.Manifest}\" \"repository\" field does not match the \"${NpmSnapFileNames.PackageJson}\" \"repository\" field.`,\n ({ manifest }) => {\n manifest.repository = packageJsonRepository\n ? deepClone(packageJsonRepository)\n : undefined;\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
@@ -45,13 +45,13 @@ exports.unusedExports = {
|
|
|
45
45
|
// requires AST manipulation.
|
|
46
46
|
// 2. Adding the permission to the manifest is not always possible, as it
|
|
47
47
|
// may require additional configuration in the manifest.
|
|
48
|
-
context.report(`The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(', ')}.`);
|
|
48
|
+
context.report(`unused-exports`, `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(', ')}.`);
|
|
49
49
|
}
|
|
50
50
|
if (unusedEndowments.length > 0) {
|
|
51
51
|
const formattedEndowments = unusedEndowments
|
|
52
52
|
.map(([handler, endowment]) => `${handler} (${endowment})`)
|
|
53
53
|
.join(', ');
|
|
54
|
-
context.report(`The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`, ({ manifest }) => {
|
|
54
|
+
context.report(`unused-endowments`, `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`, ({ manifest }) => {
|
|
55
55
|
unusedEndowments.forEach(([, endowment]) => {
|
|
56
56
|
delete manifest.initialPermissions[endowment];
|
|
57
57
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":";;;AAIA,kDAAkD;AAClD,MAAM,kB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amask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n// Special case endowments that should be ignored.\nconst IGNORED_ENDOWMENTS = ['endowment:network-access'];\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n // Endowments used based on the exports from the Snap. This is used to\n // filter endowments that are used by multiple handlers, e.g., the lifecycle\n // handlers.\n const usedEndowments = Object.entries(handlerEndowments)\n .filter(\n ([handler, endowment]) =>\n endowment === null || exports.includes(handler),\n )\n .map(([, endowment]) => endowment);\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {\n return false;\n }\n\n return (\n !usedEndowments.includes(endowment) &&\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] &&\n !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"unused-exports.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":";;;AAIA,kDAAkD;AAClD,MAAM,kBAAkB,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAExD;;;GAGG;AACU,QAAA,aAAa,GAAkB;IAC1C,QAAQ,EAAE,SAAS;IACnB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAE7D,0EAA0E;QAC1E,aAAa;QACb,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,sEAAsE;QACtE,4EAA4E;QAC5E,YAAY;QACZ,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;aACrD,MAAM,CACL,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CACvB,SAAS,KAAK,IAAI,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAClD;aACA,GAAG,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,CAAC;QAErC,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;aACrD,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YAC/B,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBACzB,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAk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;gBACf,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE;oBACzC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,SAAqC,CACtC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import type { InitialPermissions } from '@metamask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n// Special case endowments that should be ignored.\nconst IGNORED_ENDOWMENTS = ['endowment:network-access'];\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n // Endowments used based on the exports from the Snap. This is used to\n // filter endowments that are used by multiple handlers, e.g., the lifecycle\n // handlers.\n const usedEndowments = Object.entries(handlerEndowments)\n .filter(\n ([handler, endowment]) =>\n endowment === null || exports.includes(handler),\n )\n .map(([, endowment]) => endowment);\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {\n return false;\n }\n\n return (\n !usedEndowments.includes(endowment) &&\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] &&\n !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `unused-exports`,\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `unused-endowments`,\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAKxD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"unused-exports.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAKxD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAsF3B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAKxD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,
|
|
1
|
+
{"version":3,"file":"unused-exports.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAKxD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAsF3B,CAAC"}
|
|
@@ -42,13 +42,13 @@ export const unusedExports = {
|
|
|
42
42
|
// requires AST manipulation.
|
|
43
43
|
// 2. Adding the permission to the manifest is not always possible, as it
|
|
44
44
|
// may require additional configuration in the manifest.
|
|
45
|
-
context.report(`The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(', ')}.`);
|
|
45
|
+
context.report(`unused-exports`, `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(', ')}.`);
|
|
46
46
|
}
|
|
47
47
|
if (unusedEndowments.length > 0) {
|
|
48
48
|
const formattedEndowments = unusedEndowments
|
|
49
49
|
.map(([handler, endowment]) => `${handler} (${endowment})`)
|
|
50
50
|
.join(', ');
|
|
51
|
-
context.report(`The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`, ({ manifest }) => {
|
|
51
|
+
context.report(`unused-endowments`, `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`, ({ manifest }) => {
|
|
52
52
|
unusedEndowments.forEach(([, endowment]) => {
|
|
53
53
|
delete manifest.initialPermissions[endowment];
|
|
54
54
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unused-exports.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAIA,kDAAkD;AAClD,MAAM,kBAAkB,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,QAAQ,EAAE,SAAS;IACnB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAE7D,0EAA0E;QAC1E,aAAa;QACb,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,sEAAsE;QACtE,4EAA4E;QAC5E,YAAY;QACZ,MAAM,cAAc,GAA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Ac,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,iDAAiD;YACjD,oEAAoE;YACpE,gCAAgC;YAChC,yEAAyE;YACzE,2DAA2D;YAC3D,OAAO,CAAC,MAAM,CACZ,sFAAsF,cAAc,CAAC,IAAI,CACvG,IAAI,CACL,GAAG,CACL,CAAC;QACJ,CAAC;QAED,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,mBAAmB,GAAG,gBAAgB;iBACzC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC;iBAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,OAAO,CAAC,MAAM,CACZ,sFAAsF,mBAAmB,GAAG,EAC5G,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE;oBACzC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,SAAqC,CACtC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import type { InitialPermissions } from '@metamask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n// Special case endowments that should be ignored.\nconst IGNORED_ENDOWMENTS = ['endowment:network-access'];\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n // Endowments used based on the exports from the Snap. This is used to\n // filter endowments that are used by multiple handlers, e.g., the lifecycle\n // handlers.\n const usedEndowments = Object.entries(handlerEndowments)\n .filter(\n ([handler, endowment]) =>\n endowment === null || exports.includes(handler),\n )\n .map(([, endowment]) => endowment);\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {\n return false;\n }\n\n return (\n !usedEndowments.includes(endowment) &&\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] &&\n !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"unused-exports.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAIA,kDAAkD;AAClD,MAAM,kBAAkB,GAAG,CAAC,0BAA0B,CAAC,CAAC;AAExD;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,QAAQ,EAAE,SAAS;IACnB,aAAa,CAAC,KAAK,EAAE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ACjE,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,CAAC,cAAc,CAAC,QAAQ,CAAC,SAAS,CAAC;gBACnC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACtC,SAAqC,CACtC;gBACD,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAC3B,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,iDAAiD;YACjD,oEAAoE;YACpE,gCAAgC;YAChC,yEAAyE;YACzE,2DAA2D;YAC3D,OAAO,CAAC,MAAM,CACZ,gBAAgB,EAChB,sFAAsF,cAAc,CAAC,IAAI,CACvG,IAAI,CACL,GAAG,CACL,CAAC;QACJ,CAAC;QAED,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,mBAAmB,GAAG,gBAAgB;iBACzC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC;iBAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,OAAO,CAAC,MAAM,CACZ,mBAAmB,EACnB,sFAAsF,mBAAmB,GAAG,EAC5G,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE;oBACzC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,SAAqC,CACtC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import type { InitialPermissions } from '@metamask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n// Special case endowments that should be ignored.\nconst IGNORED_ENDOWMENTS = ['endowment:network-access'];\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n // Endowments used based on the exports from the Snap. This is used to\n // filter endowments that are used by multiple handlers, e.g., the lifecycle\n // handlers.\n const usedEndowments = Object.entries(handlerEndowments)\n .filter(\n ([handler, endowment]) =>\n endowment === null || exports.includes(handler),\n )\n .map(([, endowment]) => endowment);\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null || IGNORED_ENDOWMENTS.includes(endowment)) {\n return false;\n }\n\n return (\n !usedEndowments.includes(endowment) &&\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] &&\n !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `unused-exports`,\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `unused-endowments`,\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
|
|
@@ -11,7 +11,7 @@ exports.versionMatch = {
|
|
|
11
11
|
const packageJsonVersion = files.packageJson.result.version;
|
|
12
12
|
const manifestPackageVersion = files.manifest.result.version;
|
|
13
13
|
if (packageJsonVersion !== manifestPackageVersion) {
|
|
14
|
-
context.report(`"${types_1.NpmSnapFileNames.Manifest}" npm package version ("${manifestPackageVersion}") does not match the "${types_1.NpmSnapFileNames.PackageJson}" "version" field ("${packageJsonVersion}").`, ({ manifest }) => {
|
|
14
|
+
context.report('version-match', `"${types_1.NpmSnapFileNames.Manifest}" npm package version ("${manifestPackageVersion}") does not match the "${types_1.NpmSnapFileNames.PackageJson}" "version" field ("${packageJsonVersion}").`, ({ manifest }) => {
|
|
15
15
|
manifest.version = packageJsonVersion;
|
|
16
16
|
return { manifest };
|
|
17
17
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-match.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/version-match.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAG/C;;GAEG;AACU,QAAA,YAAY,GAAkB;IACzC,QAAQ,EAAE,OAAO;IACjB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC;QAC5D,MAAM,sBAAsB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7D,IAAI,kBAAkB,KAAK,sBAAsB,EAAE,CAAC;YAClD,OAAO,CAAC,MAAM,CACZ,IAAI,wBAAgB,CAAC,QAAQ,2BAA2B,sBAAsB,0BAA0B,wBAAgB,CAAC,WAAW,uBAAuB,kBAAkB,KAAK,EAClL,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,QAAQ,CAAC,OAAO,GAAG,kBAAkB,CAAC;gBACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","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"]}
|
|
1
|
+
{"version":3,"file":"version-match.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/version-match.ts"],"names":[],"mappings":";;;AAAA,2CAA+C;AAG/C;;GAEG;AACU,QAAA,YAAY,GAAkB;IACzC,QAAQ,EAAE,OAAO;IACjB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC;QAC5D,MAAM,sBAAsB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7D,IAAI,kBAAkB,KAAK,sBAAsB,EAAE,CAAC;YAClD,OAAO,CAAC,MAAM,CACZ,eAAe,EACf,IAAI,wBAAgB,CAAC,QAAQ,2BAA2B,sBAAsB,0BAA0B,wBAAgB,CAAC,WAAW,uBAAuB,kBAAkB,KAAK,EAClL,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,QAAQ,CAAC,OAAO,GAAG,kBAAkB,CAAC;gBACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","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 'version-match',\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-match.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/version-match.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAExD;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"version-match.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/version-match.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAExD;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,aAgB1B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-match.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/version-match.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAExD;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"version-match.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/version-match.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAExD;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,aAgB1B,CAAC"}
|
|
@@ -8,7 +8,7 @@ export const versionMatch = {
|
|
|
8
8
|
const packageJsonVersion = files.packageJson.result.version;
|
|
9
9
|
const manifestPackageVersion = files.manifest.result.version;
|
|
10
10
|
if (packageJsonVersion !== manifestPackageVersion) {
|
|
11
|
-
context.report(`"${NpmSnapFileNames.Manifest}" npm package version ("${manifestPackageVersion}") does not match the "${NpmSnapFileNames.PackageJson}" "version" field ("${packageJsonVersion}").`, ({ manifest }) => {
|
|
11
|
+
context.report('version-match', `"${NpmSnapFileNames.Manifest}" npm package version ("${manifestPackageVersion}") does not match the "${NpmSnapFileNames.PackageJson}" "version" field ("${packageJsonVersion}").`, ({ manifest }) => {
|
|
12
12
|
manifest.version = packageJsonVersion;
|
|
13
13
|
return { manifest };
|
|
14
14
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version-match.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/version-match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAG/C;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAkB;IACzC,QAAQ,EAAE,OAAO;IACjB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC;QAC5D,MAAM,sBAAsB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7D,IAAI,kBAAkB,KAAK,sBAAsB,EAAE,CAAC;YAClD,OAAO,CAAC,MAAM,CACZ,IAAI,gBAAgB,CAAC,QAAQ,2BAA2B,sBAAsB,0BAA0B,gBAAgB,CAAC,WAAW,uBAAuB,kBAAkB,KAAK,EAClL,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,QAAQ,CAAC,OAAO,GAAG,kBAAkB,CAAC;gBACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","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"]}
|
|
1
|
+
{"version":3,"file":"version-match.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/version-match.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAG/C;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAkB;IACzC,QAAQ,EAAE,OAAO;IACjB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,kBAAkB,GAAG,KAAK,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC;QAC5D,MAAM,sBAAsB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC;QAC7D,IAAI,kBAAkB,KAAK,sBAAsB,EAAE,CAAC;YAClD,OAAO,CAAC,MAAM,CACZ,eAAe,EACf,IAAI,gBAAgB,CAAC,QAAQ,2BAA2B,sBAAsB,0BAA0B,gBAAgB,CAAC,WAAW,uBAAuB,kBAAkB,KAAK,EAClL,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,QAAQ,CAAC,OAAO,GAAG,kBAAkB,CAAC;gBACtC,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","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 'version-match',\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"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-version.cjs","sourceRoot":"","sources":["../src/platform-version.ts"],"names":[],"mappings":";;;;;;AAAA,oFAA2D;
|
|
1
|
+
{"version":3,"file":"platform-version.cjs","sourceRoot":"","sources":["../src/platform-version.ts"],"names":[],"mappings":";;;;;;AAAA,oFAA2D;AAG3D;;;;;;;;GAQG;AACH,SAAgB,kBAAkB;IAChC,OAAO,sBAAW,CAAC,OAAwB,CAAC;AAC9C,CAAC;AAFD,gDAEC","sourcesContent":["import packageJson from '@metamask/snaps-sdk/package.json';\nimport type { SemVerVersion } from '@metamask/utils';\n\n/**\n * Get the current supported platform version.\n *\n * Note: This function assumes that the same SDK version is used across all\n * dependencies. If this is not the case, the version of the SDK that is\n * closest to the `snaps-utils` package will be returned.\n *\n * @returns The platform version.\n */\nexport function getPlatformVersion() {\n return packageJson.version as SemVerVersion;\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SemVerVersion } from "@metamask/utils";
|
|
1
2
|
/**
|
|
2
3
|
* Get the current supported platform version.
|
|
3
4
|
*
|
|
@@ -7,5 +8,5 @@
|
|
|
7
8
|
*
|
|
8
9
|
* @returns The platform version.
|
|
9
10
|
*/
|
|
10
|
-
export declare function getPlatformVersion():
|
|
11
|
+
export declare function getPlatformVersion(): SemVerVersion;
|
|
11
12
|
//# sourceMappingURL=platform-version.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-version.d.cts","sourceRoot":"","sources":["../src/platform-version.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform-version.d.cts","sourceRoot":"","sources":["../src/platform-version.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,kBAEjC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { SemVerVersion } from "@metamask/utils";
|
|
1
2
|
/**
|
|
2
3
|
* Get the current supported platform version.
|
|
3
4
|
*
|
|
@@ -7,5 +8,5 @@
|
|
|
7
8
|
*
|
|
8
9
|
* @returns The platform version.
|
|
9
10
|
*/
|
|
10
|
-
export declare function getPlatformVersion():
|
|
11
|
+
export declare function getPlatformVersion(): SemVerVersion;
|
|
11
12
|
//# sourceMappingURL=platform-version.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-version.d.mts","sourceRoot":"","sources":["../src/platform-version.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"platform-version.d.mts","sourceRoot":"","sources":["../src/platform-version.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,wBAAwB;AAErD;;;;;;;;GAQG;AACH,wBAAgB,kBAAkB,kBAEjC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"platform-version.mjs","sourceRoot":"","sources":["../src/platform-version.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,+DAAyC;
|
|
1
|
+
{"version":3,"file":"platform-version.mjs","sourceRoot":"","sources":["../src/platform-version.ts"],"names":[],"mappings":"AAAA,OAAO,WAAW,+DAAyC;AAG3D;;;;;;;;GAQG;AACH,MAAM,UAAU,kBAAkB;IAChC,OAAO,WAAW,CAAC,OAAwB,CAAC;AAC9C,CAAC","sourcesContent":["import packageJson from '@metamask/snaps-sdk/package.json';\nimport type { SemVerVersion } from '@metamask/utils';\n\n/**\n * Get the current supported platform version.\n *\n * Note: This function assumes that the same SDK version is used across all\n * dependencies. If this is not the case, the version of the SDK that is\n * closest to the `snaps-utils` package will be returned.\n *\n * @returns The platform version.\n */\nexport function getPlatformVersion() {\n return packageJson.version as SemVerVersion;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-utils",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.6.0",
|
|
4
4
|
"description": "A collection of utilities for MetaMask Snaps",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -80,15 +80,15 @@
|
|
|
80
80
|
"dependencies": {
|
|
81
81
|
"@babel/core": "^7.23.2",
|
|
82
82
|
"@babel/types": "^7.23.0",
|
|
83
|
-
"@metamask/base-controller": "^8.0
|
|
83
|
+
"@metamask/base-controller": "^8.4.0",
|
|
84
84
|
"@metamask/key-tree": "^10.1.1",
|
|
85
85
|
"@metamask/permission-controller": "^11.0.6",
|
|
86
86
|
"@metamask/rpc-errors": "^7.0.3",
|
|
87
|
-
"@metamask/slip44": "^4.
|
|
87
|
+
"@metamask/slip44": "^4.3.0",
|
|
88
88
|
"@metamask/snaps-registry": "^3.2.3",
|
|
89
|
-
"@metamask/snaps-sdk": "^
|
|
89
|
+
"@metamask/snaps-sdk": "^10.0.0",
|
|
90
90
|
"@metamask/superstruct": "^3.2.1",
|
|
91
|
-
"@metamask/utils": "^11.
|
|
91
|
+
"@metamask/utils": "^11.8.1",
|
|
92
92
|
"@noble/hashes": "^1.7.1",
|
|
93
93
|
"@scure/base": "^1.1.1",
|
|
94
94
|
"chalk": "^4.1.2",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
"validate-npm-package-name": "^5.0.0"
|
|
105
105
|
},
|
|
106
106
|
"devDependencies": {
|
|
107
|
-
"@lavamoat/allow-scripts": "^3.
|
|
107
|
+
"@lavamoat/allow-scripts": "^3.4.0",
|
|
108
108
|
"@metamask/auto-changelog": "^5.0.2",
|
|
109
109
|
"@metamask/post-message-stream": "^10.0.0",
|
|
110
110
|
"@swc/core": "1.11.31",
|