@metamask/snaps-utils 9.3.0 → 9.4.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.
Files changed (102) hide show
  1. package/CHANGELOG.md +15 -1
  2. package/dist/account.cjs +53 -0
  3. package/dist/account.cjs.map +1 -1
  4. package/dist/account.d.cts +26 -1
  5. package/dist/account.d.cts.map +1 -1
  6. package/dist/account.d.mts +26 -1
  7. package/dist/account.d.mts.map +1 -1
  8. package/dist/account.mjs +49 -1
  9. package/dist/account.mjs.map +1 -1
  10. package/dist/eval-worker.cjs +38 -11
  11. package/dist/eval-worker.cjs.map +1 -1
  12. package/dist/eval-worker.d.cts.map +1 -1
  13. package/dist/eval-worker.d.mts.map +1 -1
  14. package/dist/eval-worker.mjs +38 -11
  15. package/dist/eval-worker.mjs.map +1 -1
  16. package/dist/eval.cjs +6 -0
  17. package/dist/eval.cjs.map +1 -1
  18. package/dist/eval.d.cts +7 -0
  19. package/dist/eval.d.cts.map +1 -1
  20. package/dist/eval.d.mts +7 -0
  21. package/dist/eval.d.mts.map +1 -1
  22. package/dist/eval.mjs +6 -0
  23. package/dist/eval.mjs.map +1 -1
  24. package/dist/fs.cjs +51 -6
  25. package/dist/fs.cjs.map +1 -1
  26. package/dist/fs.d.cts +16 -4
  27. package/dist/fs.d.cts.map +1 -1
  28. package/dist/fs.d.mts +16 -4
  29. package/dist/fs.d.mts.map +1 -1
  30. package/dist/fs.mjs +49 -5
  31. package/dist/fs.mjs.map +1 -1
  32. package/dist/handlers/home-page.d.cts +3 -3
  33. package/dist/handlers/home-page.d.mts +3 -3
  34. package/dist/handlers/settings-page.d.cts +1 -1
  35. package/dist/handlers/settings-page.d.mts +1 -1
  36. package/dist/handlers/signature.d.cts +1 -1
  37. package/dist/handlers/signature.d.mts +1 -1
  38. package/dist/handlers/transaction.d.cts +3 -3
  39. package/dist/handlers/transaction.d.mts +3 -3
  40. package/dist/index.cjs +1 -0
  41. package/dist/index.cjs.map +1 -1
  42. package/dist/index.d.cts +1 -1
  43. package/dist/index.d.cts.map +1 -1
  44. package/dist/index.d.mts +1 -1
  45. package/dist/index.d.mts.map +1 -1
  46. package/dist/index.mjs +1 -0
  47. package/dist/index.mjs.map +1 -1
  48. package/dist/manifest/manifest.cjs +36 -4
  49. package/dist/manifest/manifest.cjs.map +1 -1
  50. package/dist/manifest/manifest.d.cts +40 -7
  51. package/dist/manifest/manifest.d.cts.map +1 -1
  52. package/dist/manifest/manifest.d.mts +40 -7
  53. package/dist/manifest/manifest.d.mts.map +1 -1
  54. package/dist/manifest/manifest.mjs +13 -4
  55. package/dist/manifest/manifest.mjs.map +1 -1
  56. package/dist/manifest/validator-types.cjs.map +1 -1
  57. package/dist/manifest/validator-types.d.cts +18 -1
  58. package/dist/manifest/validator-types.d.cts.map +1 -1
  59. package/dist/manifest/validator-types.d.mts +18 -1
  60. package/dist/manifest/validator-types.d.mts.map +1 -1
  61. package/dist/manifest/validator-types.mjs.map +1 -1
  62. package/dist/manifest/validator.cjs +23 -10
  63. package/dist/manifest/validator.cjs.map +1 -1
  64. package/dist/manifest/validator.d.cts +4 -2
  65. package/dist/manifest/validator.d.cts.map +1 -1
  66. package/dist/manifest/validator.d.mts +4 -2
  67. package/dist/manifest/validator.d.mts.map +1 -1
  68. package/dist/manifest/validator.mjs +23 -10
  69. package/dist/manifest/validator.mjs.map +1 -1
  70. package/dist/manifest/validators/index.cjs +2 -0
  71. package/dist/manifest/validators/index.cjs.map +1 -1
  72. package/dist/manifest/validators/index.d.cts +2 -0
  73. package/dist/manifest/validators/index.d.cts.map +1 -1
  74. package/dist/manifest/validators/index.d.mts +2 -0
  75. package/dist/manifest/validators/index.d.mts.map +1 -1
  76. package/dist/manifest/validators/index.mjs +2 -0
  77. package/dist/manifest/validators/index.mjs.map +1 -1
  78. package/dist/manifest/validators/production-platform-version.cjs +47 -0
  79. package/dist/manifest/validators/production-platform-version.cjs.map +1 -0
  80. package/dist/manifest/validators/production-platform-version.d.cts +7 -0
  81. package/dist/manifest/validators/production-platform-version.d.cts.map +1 -0
  82. package/dist/manifest/validators/production-platform-version.d.mts +7 -0
  83. package/dist/manifest/validators/production-platform-version.d.mts.map +1 -0
  84. package/dist/manifest/validators/production-platform-version.mjs +44 -0
  85. package/dist/manifest/validators/production-platform-version.mjs.map +1 -0
  86. package/dist/manifest/validators/unused-exports.cjs +53 -0
  87. package/dist/manifest/validators/unused-exports.cjs.map +1 -0
  88. package/dist/manifest/validators/unused-exports.d.cts +7 -0
  89. package/dist/manifest/validators/unused-exports.d.cts.map +1 -0
  90. package/dist/manifest/validators/unused-exports.d.mts +7 -0
  91. package/dist/manifest/validators/unused-exports.d.mts.map +1 -0
  92. package/dist/manifest/validators/unused-exports.mjs +50 -0
  93. package/dist/manifest/validators/unused-exports.mjs.map +1 -0
  94. package/dist/time.cjs +15 -1
  95. package/dist/time.cjs.map +1 -1
  96. package/dist/time.d.cts +7 -0
  97. package/dist/time.d.cts.map +1 -1
  98. package/dist/time.d.mts +7 -0
  99. package/dist/time.d.mts.map +1 -1
  100. package/dist/time.mjs +13 -0
  101. package/dist/time.mjs.map +1 -1
  102. package/package.json +4 -3
@@ -22,26 +22,34 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
26
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
27
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
28
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
29
- };
30
25
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
31
26
  if (kind === "m") throw new TypeError("Private method is not writable");
32
27
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
33
28
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
34
29
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
35
30
  };
36
- var _Context_nextSeverity;
31
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
32
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
33
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
34
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
35
+ };
36
+ var _Context_options, _Context_nextSeverity;
37
37
  Object.defineProperty(exports, "__esModule", { value: true });
38
38
  exports.hasFixes = exports.runValidators = void 0;
39
39
  const utils_1 = require("@metamask/utils");
40
40
  const defaultValidators = __importStar(require("./validators/index.cjs"));
41
41
  class Context {
42
- constructor() {
42
+ /**
43
+ * Construct a new validator context.
44
+ *
45
+ * @param options - The options for the validator context.
46
+ * @param options.exports - Exports detected by evaluating the bundle.
47
+ */
48
+ constructor(options) {
43
49
  this.reports = [];
50
+ _Context_options.set(this, {});
44
51
  _Context_nextSeverity.set(this, undefined);
52
+ __classPrivateFieldSet(this, _Context_options, options, "f");
45
53
  }
46
54
  report(message, fix) {
47
55
  (0, utils_1.assert)(__classPrivateFieldGet(this, _Context_nextSeverity, "f") !== undefined);
@@ -57,8 +65,11 @@ class Context {
57
65
  get hasErrors() {
58
66
  return this.reports.some((report) => report.severity === 'error');
59
67
  }
68
+ get options() {
69
+ return __classPrivateFieldGet(this, _Context_options, "f");
70
+ }
60
71
  }
61
- _Context_nextSeverity = new WeakMap();
72
+ _Context_options = new WeakMap(), _Context_nextSeverity = new WeakMap();
62
73
  /**
63
74
  * Verify that snap files are completely valid.
64
75
  * First it runs validators on unparsed files to check structure.
@@ -66,13 +77,15 @@ _Context_nextSeverity = new WeakMap();
66
77
  *
67
78
  * @param files - All files required to run a snap.
68
79
  * @param rules - Validators to run.
80
+ * @param options - Options for the validation.
81
+ * @param options.exports - Exports detected by evaluating the bundle.
69
82
  * @returns The validation results.
70
83
  */
71
84
  // TODO(ritave): snap.manifest.json and package.json should check
72
85
  // json parsing as well instead of assuming it's
73
86
  // already parsed
74
- async function runValidators(files, rules = Object.values(defaultValidators)) {
75
- const context = new Context();
87
+ async function runValidators(files, rules = Object.values(defaultValidators), options = {}) {
88
+ const context = new Context(options);
76
89
  for (const rule of rules) {
77
90
  context.prepareForValidator({
78
91
  severity: rule.severity,
@@ -1 +1 @@
1
- {"version":3,"file":"validator.cjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AASzC,0EAAkD;AAQlD,MAAM,OAAO;IAAb;QACE,YAAO,GAAsB,EAAE,CAAC;QAEhC,gCAAoC,SAAS,EAAC;IAkBhD,CAAC;IAhBC,MAAM,CAAC,OAAe,EAAE,GAAkB;QACxC,IAAA,cAAM,EAAC,uBAAA,IAAI,6BAAc,KAAK,SAAS,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,QAAQ,EAAE,uBAAA,IAAI,6BAAc;YAC5B,OAAO;YACP,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,CAAC,QAAyC;QAC3D,uBAAA,IAAI,yBAAiB,QAAQ,CAAC,QAAQ,MAAA,CAAC;IACzC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IACpE,CAAC;CACF;;AAED;;;;;;;;GAQG;AACH,iEAAiE;AACjE,8DAA8D;AAC9D,+BAA+B;AACxB,KAAK,UAAU,aAAa,CACjC,KAA2B,EAC3B,QAAyB,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC;IAEzD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAkB,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO;QACL,KAAK,EAAE,KAAkB;QACzB,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AA5BD,sCA4BC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,OAAyB;IAChD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC;AAFD,4BAEC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type {\n ValidatorContext,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorResults = {\n files?: SnapFiles;\n reports: ValidatorReport[];\n};\n\nclass Context implements ValidatorContext {\n reports: ValidatorReport[] = [];\n\n #nextSeverity?: ValidatorSeverity = undefined;\n\n report(message: string, fix?: ValidatorFix): void {\n assert(this.#nextSeverity !== undefined);\n this.reports.push({\n severity: this.#nextSeverity,\n message,\n fix,\n });\n }\n\n prepareForValidator(settings: { severity: ValidatorSeverity }) {\n this.#nextSeverity = settings.severity;\n }\n\n get hasErrors() {\n return this.reports.some((report) => report.severity === 'error');\n }\n}\n\n/**\n * Verify that snap files are completely valid.\n * First it runs validators on unparsed files to check structure.\n * Secondly it runs validators on parsed files to check semantics.\n *\n * @param files - All files required to run a snap.\n * @param rules - Validators to run.\n * @returns The validation results.\n */\n// TODO(ritave): snap.manifest.json and package.json should check\n// json parsing as well instead of assuming it's\n// already parsed\nexport async function runValidators(\n files: UnvalidatedSnapFiles,\n rules: ValidatorMeta[] = Object.values(defaultValidators),\n): Promise<ValidatorResults> {\n const context = new Context();\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.structureCheck?.(files, context);\n }\n if (context.hasErrors) {\n return {\n reports: context.reports,\n };\n }\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.semanticCheck?.(files as SnapFiles, context);\n }\n return {\n files: files as SnapFiles,\n reports: context.reports,\n };\n}\n\n/**\n * Get whether any reports has pending fixes.\n *\n * @param results - Results of the validation run.\n * @returns Whether there are fixes pending.\n */\nexport function hasFixes(results: ValidatorResults): boolean {\n return results.reports.some((report) => report.fix);\n}\n"]}
1
+ {"version":3,"file":"validator.cjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AAUzC,0EAAkD;AAQlD,MAAM,OAAO;IAOX;;;;;OAKG;IACH,YAAY,OAAgC;QAZ5C,YAAO,GAAsB,EAAE,CAAC;QAEvB,2BAAoC,EAAE,EAAC;QAEhD,gCAAoC,SAAS,EAAC;QAS5C,uBAAA,IAAI,oBAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,OAAe,EAAE,GAAkB;QACxC,IAAA,cAAM,EAAC,uBAAA,IAAI,6BAAc,KAAK,SAAS,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,QAAQ,EAAE,uBAAA,IAAI,6BAAc;YAC5B,OAAO;YACP,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,CAAC,QAAyC;QAC3D,uBAAA,IAAI,yBAAiB,QAAQ,CAAC,QAAQ,MAAA,CAAC;IACzC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,OAAO;QACT,OAAO,uBAAA,IAAI,wBAAS,CAAC;IACvB,CAAC;CACF;;AAED;;;;;;;;;;GAUG;AACH,iEAAiE;AACjE,8DAA8D;AAC9D,+BAA+B;AACxB,KAAK,UAAU,aAAa,CACjC,KAA2B,EAC3B,QAAyB,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,EACzD,UAAmC,EAAE;IAErC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAErC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAkB,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,KAAK,EAAE,KAAkB;QACzB,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AA/BD,sCA+BC;AAED;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,OAAyB;IAChD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC;AAFD,4BAEC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type {\n ValidatorContext,\n ValidatorContextOptions,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorResults = {\n files?: SnapFiles;\n reports: ValidatorReport[];\n};\n\nclass Context implements ValidatorContext {\n reports: ValidatorReport[] = [];\n\n readonly #options: ValidatorContextOptions = {};\n\n #nextSeverity?: ValidatorSeverity = undefined;\n\n /**\n * Construct a new validator context.\n *\n * @param options - The options for the validator context.\n * @param options.exports - Exports detected by evaluating the bundle.\n */\n constructor(options: ValidatorContextOptions) {\n this.#options = options;\n }\n\n report(message: string, fix?: ValidatorFix): void {\n assert(this.#nextSeverity !== undefined);\n this.reports.push({\n severity: this.#nextSeverity,\n message,\n fix,\n });\n }\n\n prepareForValidator(settings: { severity: ValidatorSeverity }) {\n this.#nextSeverity = settings.severity;\n }\n\n get hasErrors() {\n return this.reports.some((report) => report.severity === 'error');\n }\n\n get options() {\n return this.#options;\n }\n}\n\n/**\n * Verify that snap files are completely valid.\n * First it runs validators on unparsed files to check structure.\n * Secondly it runs validators on parsed files to check semantics.\n *\n * @param files - All files required to run a snap.\n * @param rules - Validators to run.\n * @param options - Options for the validation.\n * @param options.exports - Exports detected by evaluating the bundle.\n * @returns The validation results.\n */\n// TODO(ritave): snap.manifest.json and package.json should check\n// json parsing as well instead of assuming it's\n// already parsed\nexport async function runValidators(\n files: UnvalidatedSnapFiles,\n rules: ValidatorMeta[] = Object.values(defaultValidators),\n options: ValidatorContextOptions = {},\n): Promise<ValidatorResults> {\n const context = new Context(options);\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.structureCheck?.(files, context);\n }\n\n if (context.hasErrors) {\n return {\n reports: context.reports,\n };\n }\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.semanticCheck?.(files as SnapFiles, context);\n }\n\n return {\n files: files as SnapFiles,\n reports: context.reports,\n };\n}\n\n/**\n * Get whether any reports has pending fixes.\n *\n * @param results - Results of the validation run.\n * @returns Whether there are fixes pending.\n */\nexport function hasFixes(results: ValidatorResults): boolean {\n return results.reports.some((report) => report.fix);\n}\n"]}
@@ -1,4 +1,4 @@
1
- import type { ValidatorMeta, ValidatorReport } from "./validator-types.cjs";
1
+ import type { ValidatorContextOptions, ValidatorMeta, ValidatorReport } from "./validator-types.cjs";
2
2
  import type { SnapFiles, UnvalidatedSnapFiles } from "../types.cjs";
3
3
  export type ValidatorResults = {
4
4
  files?: SnapFiles;
@@ -11,9 +11,11 @@ export type ValidatorResults = {
11
11
  *
12
12
  * @param files - All files required to run a snap.
13
13
  * @param rules - Validators to run.
14
+ * @param options - Options for the validation.
15
+ * @param options.exports - Exports detected by evaluating the bundle.
14
16
  * @returns The validation results.
15
17
  */
16
- export declare function runValidators(files: UnvalidatedSnapFiles, rules?: ValidatorMeta[]): Promise<ValidatorResults>;
18
+ export declare function runValidators(files: UnvalidatedSnapFiles, rules?: ValidatorMeta[], options?: ValidatorContextOptions): Promise<ValidatorResults>;
17
19
  /**
18
20
  * Get whether any reports has pending fixes.
19
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.cts","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,aAAa,EACb,eAAe,EAEhB,8BAA0B;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC;AAyBF;;;;;;;;GAQG;AAIH,wBAAsB,aAAa,CACjC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,GAAE,aAAa,EAAqC,GACxD,OAAO,CAAC,gBAAgB,CAAC,CAyB3B;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAE3D"}
1
+ {"version":3,"file":"validator.d.cts","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,uBAAuB,EAEvB,aAAa,EACb,eAAe,EAEhB,8BAA0B;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC;AAyCF;;;;;;;;;;GAUG;AAIH,wBAAsB,aAAa,CACjC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,GAAE,aAAa,EAAqC,EACzD,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,gBAAgB,CAAC,CA2B3B;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAE3D"}
@@ -1,4 +1,4 @@
1
- import type { ValidatorMeta, ValidatorReport } from "./validator-types.mjs";
1
+ import type { ValidatorContextOptions, ValidatorMeta, ValidatorReport } from "./validator-types.mjs";
2
2
  import type { SnapFiles, UnvalidatedSnapFiles } from "../types.mjs";
3
3
  export type ValidatorResults = {
4
4
  files?: SnapFiles;
@@ -11,9 +11,11 @@ export type ValidatorResults = {
11
11
  *
12
12
  * @param files - All files required to run a snap.
13
13
  * @param rules - Validators to run.
14
+ * @param options - Options for the validation.
15
+ * @param options.exports - Exports detected by evaluating the bundle.
14
16
  * @returns The validation results.
15
17
  */
16
- export declare function runValidators(files: UnvalidatedSnapFiles, rules?: ValidatorMeta[]): Promise<ValidatorResults>;
18
+ export declare function runValidators(files: UnvalidatedSnapFiles, rules?: ValidatorMeta[], options?: ValidatorContextOptions): Promise<ValidatorResults>;
17
19
  /**
18
20
  * Get whether any reports has pending fixes.
19
21
  *
@@ -1 +1 @@
1
- {"version":3,"file":"validator.d.mts","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAGV,aAAa,EACb,eAAe,EAEhB,8BAA0B;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC;AAyBF;;;;;;;;GAQG;AAIH,wBAAsB,aAAa,CACjC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,GAAE,aAAa,EAAqC,GACxD,OAAO,CAAC,gBAAgB,CAAC,CAyB3B;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAE3D"}
1
+ {"version":3,"file":"validator.d.mts","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAEV,uBAAuB,EAEvB,aAAa,EACb,eAAe,EAEhB,8BAA0B;AAE3B,OAAO,KAAK,EAAE,SAAS,EAAE,oBAAoB,EAAE,qBAAiB;AAEhE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,eAAe,EAAE,CAAC;CAC5B,CAAC;AAyCF;;;;;;;;;;GAUG;AAIH,wBAAsB,aAAa,CACjC,KAAK,EAAE,oBAAoB,EAC3B,KAAK,GAAE,aAAa,EAAqC,EACzD,OAAO,GAAE,uBAA4B,GACpC,OAAO,CAAC,gBAAgB,CAAC,CA2B3B;AAED;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAE3D"}
@@ -1,21 +1,29 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
1
  var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
2
  if (kind === "m") throw new TypeError("Private method is not writable");
8
3
  if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
4
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
5
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
6
  };
12
- var _Context_nextSeverity;
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _Context_options, _Context_nextSeverity;
13
13
  import { assert } from "@metamask/utils";
14
14
  import * as defaultValidators from "./validators/index.mjs";
15
15
  class Context {
16
- constructor() {
16
+ /**
17
+ * Construct a new validator context.
18
+ *
19
+ * @param options - The options for the validator context.
20
+ * @param options.exports - Exports detected by evaluating the bundle.
21
+ */
22
+ constructor(options) {
17
23
  this.reports = [];
24
+ _Context_options.set(this, {});
18
25
  _Context_nextSeverity.set(this, undefined);
26
+ __classPrivateFieldSet(this, _Context_options, options, "f");
19
27
  }
20
28
  report(message, fix) {
21
29
  assert(__classPrivateFieldGet(this, _Context_nextSeverity, "f") !== undefined);
@@ -31,8 +39,11 @@ class Context {
31
39
  get hasErrors() {
32
40
  return this.reports.some((report) => report.severity === 'error');
33
41
  }
42
+ get options() {
43
+ return __classPrivateFieldGet(this, _Context_options, "f");
44
+ }
34
45
  }
35
- _Context_nextSeverity = new WeakMap();
46
+ _Context_options = new WeakMap(), _Context_nextSeverity = new WeakMap();
36
47
  /**
37
48
  * Verify that snap files are completely valid.
38
49
  * First it runs validators on unparsed files to check structure.
@@ -40,13 +51,15 @@ _Context_nextSeverity = new WeakMap();
40
51
  *
41
52
  * @param files - All files required to run a snap.
42
53
  * @param rules - Validators to run.
54
+ * @param options - Options for the validation.
55
+ * @param options.exports - Exports detected by evaluating the bundle.
43
56
  * @returns The validation results.
44
57
  */
45
58
  // TODO(ritave): snap.manifest.json and package.json should check
46
59
  // json parsing as well instead of assuming it's
47
60
  // already parsed
48
- export async function runValidators(files, rules = Object.values(defaultValidators)) {
49
- const context = new Context();
61
+ export async function runValidators(files, rules = Object.values(defaultValidators), options = {}) {
62
+ const context = new Context(options);
50
63
  for (const rule of rules) {
51
64
  context.prepareForValidator({
52
65
  severity: rule.severity,
@@ -1 +1 @@
1
- {"version":3,"file":"validator.mjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AASzC,OAAO,KAAK,iBAAiB,+BAAqB;AAQlD,MAAM,OAAO;IAAb;QACE,YAAO,GAAsB,EAAE,CAAC;QAEhC,gCAAoC,SAAS,EAAC;IAkBhD,CAAC;IAhBC,MAAM,CAAC,OAAe,EAAE,GAAkB;QACxC,MAAM,CAAC,uBAAA,IAAI,6BAAc,KAAK,SAAS,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,QAAQ,EAAE,uBAAA,IAAI,6BAAc;YAC5B,OAAO;YACP,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,CAAC,QAAyC;QAC3D,uBAAA,IAAI,yBAAiB,QAAQ,CAAC,QAAQ,MAAA,CAAC;IACzC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IACpE,CAAC;CACF;;AAED;;;;;;;;GAQG;AACH,iEAAiE;AACjE,8DAA8D;AAC9D,+BAA+B;AAC/B,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAA2B,EAC3B,QAAyB,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC;IAEzD,MAAM,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC;IAE9B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IACD,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAkB,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO;QACL,KAAK,EAAE,KAAkB;QACzB,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAChD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type {\n ValidatorContext,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorResults = {\n files?: SnapFiles;\n reports: ValidatorReport[];\n};\n\nclass Context implements ValidatorContext {\n reports: ValidatorReport[] = [];\n\n #nextSeverity?: ValidatorSeverity = undefined;\n\n report(message: string, fix?: ValidatorFix): void {\n assert(this.#nextSeverity !== undefined);\n this.reports.push({\n severity: this.#nextSeverity,\n message,\n fix,\n });\n }\n\n prepareForValidator(settings: { severity: ValidatorSeverity }) {\n this.#nextSeverity = settings.severity;\n }\n\n get hasErrors() {\n return this.reports.some((report) => report.severity === 'error');\n }\n}\n\n/**\n * Verify that snap files are completely valid.\n * First it runs validators on unparsed files to check structure.\n * Secondly it runs validators on parsed files to check semantics.\n *\n * @param files - All files required to run a snap.\n * @param rules - Validators to run.\n * @returns The validation results.\n */\n// TODO(ritave): snap.manifest.json and package.json should check\n// json parsing as well instead of assuming it's\n// already parsed\nexport async function runValidators(\n files: UnvalidatedSnapFiles,\n rules: ValidatorMeta[] = Object.values(defaultValidators),\n): Promise<ValidatorResults> {\n const context = new Context();\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.structureCheck?.(files, context);\n }\n if (context.hasErrors) {\n return {\n reports: context.reports,\n };\n }\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.semanticCheck?.(files as SnapFiles, context);\n }\n return {\n files: files as SnapFiles,\n reports: context.reports,\n };\n}\n\n/**\n * Get whether any reports has pending fixes.\n *\n * @param results - Results of the validation run.\n * @returns Whether there are fixes pending.\n */\nexport function hasFixes(results: ValidatorResults): boolean {\n return results.reports.some((report) => report.fix);\n}\n"]}
1
+ {"version":3,"file":"validator.mjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,MAAM,EAAE,wBAAwB;AAUzC,OAAO,KAAK,iBAAiB,+BAAqB;AAQlD,MAAM,OAAO;IAOX;;;;;OAKG;IACH,YAAY,OAAgC;QAZ5C,YAAO,GAAsB,EAAE,CAAC;QAEvB,2BAAoC,EAAE,EAAC;QAEhD,gCAAoC,SAAS,EAAC;QAS5C,uBAAA,IAAI,oBAAY,OAAO,MAAA,CAAC;IAC1B,CAAC;IAED,MAAM,CAAC,OAAe,EAAE,GAAkB;QACxC,MAAM,CAAC,uBAAA,IAAI,6BAAc,KAAK,SAAS,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,QAAQ,EAAE,uBAAA,IAAI,6BAAc;YAC5B,OAAO;YACP,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,CAAC,QAAyC;QAC3D,uBAAA,IAAI,yBAAiB,QAAQ,CAAC,QAAQ,MAAA,CAAC;IACzC,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,QAAQ,KAAK,OAAO,CAAC,CAAC;IACpE,CAAC;IAED,IAAI,OAAO;QACT,OAAO,uBAAA,IAAI,wBAAS,CAAC;IACvB,CAAC;CACF;;AAED;;;;;;;;;;GAUG;AACH,iEAAiE;AACjE,8DAA8D;AAC9D,+BAA+B;AAC/B,MAAM,CAAC,KAAK,UAAU,aAAa,CACjC,KAA2B,EAC3B,QAAyB,MAAM,CAAC,MAAM,CAAC,iBAAiB,CAAC,EACzD,UAAmC,EAAE;IAErC,MAAM,OAAO,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAErC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,cAAc,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAC9C,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,EAAE,CAAC;QACtB,OAAO;YACL,OAAO,EAAE,OAAO,CAAC,OAAO;SACzB,CAAC;IACJ,CAAC;IAED,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,OAAO,CAAC,mBAAmB,CAAC;YAC1B,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,aAAa,EAAE,CAAC,KAAkB,EAAE,OAAO,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO;QACL,KAAK,EAAE,KAAkB;QACzB,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAyB;IAChD,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { assert } from '@metamask/utils';\n\nimport type {\n ValidatorContext,\n ValidatorContextOptions,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\nimport type { SnapFiles, UnvalidatedSnapFiles } from '../types';\n\nexport type ValidatorResults = {\n files?: SnapFiles;\n reports: ValidatorReport[];\n};\n\nclass Context implements ValidatorContext {\n reports: ValidatorReport[] = [];\n\n readonly #options: ValidatorContextOptions = {};\n\n #nextSeverity?: ValidatorSeverity = undefined;\n\n /**\n * Construct a new validator context.\n *\n * @param options - The options for the validator context.\n * @param options.exports - Exports detected by evaluating the bundle.\n */\n constructor(options: ValidatorContextOptions) {\n this.#options = options;\n }\n\n report(message: string, fix?: ValidatorFix): void {\n assert(this.#nextSeverity !== undefined);\n this.reports.push({\n severity: this.#nextSeverity,\n message,\n fix,\n });\n }\n\n prepareForValidator(settings: { severity: ValidatorSeverity }) {\n this.#nextSeverity = settings.severity;\n }\n\n get hasErrors() {\n return this.reports.some((report) => report.severity === 'error');\n }\n\n get options() {\n return this.#options;\n }\n}\n\n/**\n * Verify that snap files are completely valid.\n * First it runs validators on unparsed files to check structure.\n * Secondly it runs validators on parsed files to check semantics.\n *\n * @param files - All files required to run a snap.\n * @param rules - Validators to run.\n * @param options - Options for the validation.\n * @param options.exports - Exports detected by evaluating the bundle.\n * @returns The validation results.\n */\n// TODO(ritave): snap.manifest.json and package.json should check\n// json parsing as well instead of assuming it's\n// already parsed\nexport async function runValidators(\n files: UnvalidatedSnapFiles,\n rules: ValidatorMeta[] = Object.values(defaultValidators),\n options: ValidatorContextOptions = {},\n): Promise<ValidatorResults> {\n const context = new Context(options);\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.structureCheck?.(files, context);\n }\n\n if (context.hasErrors) {\n return {\n reports: context.reports,\n };\n }\n\n for (const rule of rules) {\n context.prepareForValidator({\n severity: rule.severity,\n });\n await rule.semanticCheck?.(files as SnapFiles, context);\n }\n\n return {\n files: files as SnapFiles,\n reports: context.reports,\n };\n}\n\n/**\n * Get whether any reports has pending fixes.\n *\n * @param results - Results of the validation run.\n * @returns Whether there are fixes pending.\n */\nexport function hasFixes(results: ValidatorResults): boolean {\n return results.reports.some((report) => report.fix);\n}\n"]}
@@ -16,6 +16,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./checksum.cjs"), exports);
18
18
  __exportStar(require("./expected-files.cjs"), exports);
19
+ __exportStar(require("./unused-exports.cjs"), exports);
19
20
  __exportStar(require("./icon-dimensions.cjs"), exports);
20
21
  __exportStar(require("./is-localization-file.cjs"), exports);
21
22
  __exportStar(require("./is-package-json.cjs"), exports);
@@ -25,6 +26,7 @@ __exportStar(require("./manifest-localization.cjs"), exports);
25
26
  __exportStar(require("./package-json-recommended-fields.cjs"), exports);
26
27
  __exportStar(require("./package-name-match.cjs"), exports);
27
28
  __exportStar(require("./platform-version.cjs"), exports);
29
+ __exportStar(require("./production-platform-version.cjs"), exports);
28
30
  __exportStar(require("./repository-match.cjs"), exports);
29
31
  __exportStar(require("./version-match.cjs"), exports);
30
32
  __exportStar(require("./icon-declared.cjs"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA2B;AAC3B,uDAAiC;AACjC,wDAAkC;AAClC,6DAAuC;AACvC,wDAAkC;AAClC,qDAA+B;AAC/B,yDAAmC;AACnC,8DAAwC;AACxC,wEAAkD;AAClD,2DAAqC;AACrC,yDAAmC;AACnC,yDAAmC;AACnC,sDAAgC;AAChC,sDAAgC;AAChC,qDAA+B","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 './platform-version';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,iDAA2B;AAC3B,uDAAiC;AACjC,uDAAiC;AACjC,wDAAkC;AAClC,6DAAuC;AACvC,wDAAkC;AAClC,qDAA+B;AAC/B,yDAAmC;AACnC,8DAAwC;AACxC,wEAAkD;AAClD,2DAAqC;AACrC,yDAAmC;AACnC,oEAA8C;AAC9C,yDAAmC;AACnC,sDAAgC;AAChC,sDAAgC;AAChC,qDAA+B","sourcesContent":["export * from './checksum';\nexport * from './expected-files';\nexport * from './unused-exports';\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 './platform-version';\nexport * from './production-platform-version';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"]}
@@ -1,5 +1,6 @@
1
1
  export * from "./checksum.cjs";
2
2
  export * from "./expected-files.cjs";
3
+ export * from "./unused-exports.cjs";
3
4
  export * from "./icon-dimensions.cjs";
4
5
  export * from "./is-localization-file.cjs";
5
6
  export * from "./is-package-json.cjs";
@@ -9,6 +10,7 @@ export * from "./manifest-localization.cjs";
9
10
  export * from "./package-json-recommended-fields.cjs";
10
11
  export * from "./package-name-match.cjs";
11
12
  export * from "./platform-version.cjs";
13
+ export * from "./production-platform-version.cjs";
12
14
  export * from "./repository-match.cjs";
13
15
  export * from "./version-match.cjs";
14
16
  export * from "./icon-declared.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,kDAA8C;AAC9C,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B"}
@@ -1,5 +1,6 @@
1
1
  export * from "./checksum.mjs";
2
2
  export * from "./expected-files.mjs";
3
+ export * from "./unused-exports.mjs";
3
4
  export * from "./icon-dimensions.mjs";
4
5
  export * from "./is-localization-file.mjs";
5
6
  export * from "./is-package-json.mjs";
@@ -9,6 +10,7 @@ export * from "./manifest-localization.mjs";
9
10
  export * from "./package-json-recommended-fields.mjs";
10
11
  export * from "./package-name-match.mjs";
11
12
  export * from "./platform-version.mjs";
13
+ export * from "./production-platform-version.mjs";
12
14
  export * from "./repository-match.mjs";
13
15
  export * from "./version-match.mjs";
14
16
  export * from "./icon-declared.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,kDAA8C;AAC9C,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B"}
@@ -1,5 +1,6 @@
1
1
  export * from "./checksum.mjs";
2
2
  export * from "./expected-files.mjs";
3
+ export * from "./unused-exports.mjs";
3
4
  export * from "./icon-dimensions.mjs";
4
5
  export * from "./is-localization-file.mjs";
5
6
  export * from "./is-package-json.mjs";
@@ -9,6 +10,7 @@ export * from "./manifest-localization.mjs";
9
10
  export * from "./package-json-recommended-fields.mjs";
10
11
  export * from "./package-name-match.mjs";
11
12
  export * from "./platform-version.mjs";
13
+ export * from "./production-platform-version.mjs";
12
14
  export * from "./repository-match.mjs";
13
15
  export * from "./version-match.mjs";
14
16
  export * from "./icon-declared.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B","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 './platform-version';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/index.ts"],"names":[],"mappings":"AAAA,+BAA2B;AAC3B,qCAAiC;AACjC,qCAAiC;AACjC,sCAAkC;AAClC,2CAAuC;AACvC,sCAAkC;AAClC,mCAA+B;AAC/B,uCAAmC;AACnC,4CAAwC;AACxC,sDAAkD;AAClD,yCAAqC;AACrC,uCAAmC;AACnC,kDAA8C;AAC9C,uCAAmC;AACnC,oCAAgC;AAChC,oCAAgC;AAChC,mCAA+B","sourcesContent":["export * from './checksum';\nexport * from './expected-files';\nexport * from './unused-exports';\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 './platform-version';\nexport * from './production-platform-version';\nexport * from './repository-match';\nexport * from './version-match';\nexport * from './icon-declared';\nexport * from './icon-missing';\n"]}
@@ -0,0 +1,47 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.productionPlatformVersion = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const semver_1 = require("semver");
6
+ const fs_1 = require("../../fs.cjs");
7
+ /**
8
+ * Determine the production version of the Snaps platform by inspecting
9
+ * the latest GitHub release of the MetaMask extension.
10
+ *
11
+ * @returns The production version of the Snaps platform or null if any error occurred.
12
+ */
13
+ const determineProductionVersion = (0, fs_1.useFileSystemCache)('snaps-production-version', (0, utils_1.inMilliseconds)(3, utils_1.Duration.Day), async () => {
14
+ try {
15
+ const latestRelease = await fetch('https://api.github.com/repos/metamask/metamask-extension/releases/latest');
16
+ const latestReleaseJson = await latestRelease.json();
17
+ const latestReleaseCommit = latestReleaseJson.target_commitish;
18
+ const packageJsonResponse = await fetch(`https://api.github.com/repos/metamask/metamask-extension/contents/package.json?ref=${latestReleaseCommit}`, { headers: new Headers({ accept: 'application/vnd.github.raw+json' }) });
19
+ const packageJson = await packageJsonResponse.json();
20
+ const versionRange = packageJson.dependencies['@metamask/snaps-sdk'];
21
+ return (0, semver_1.minVersion)(versionRange)?.format();
22
+ }
23
+ catch {
24
+ return null;
25
+ }
26
+ });
27
+ /**
28
+ * Check if the platform version in manifest exceeds the version
29
+ * used in production.
30
+ */
31
+ exports.productionPlatformVersion = {
32
+ severity: 'warning',
33
+ async semanticCheck(files, context) {
34
+ const manifestPlatformVersion = files.manifest.result.platformVersion;
35
+ if (!manifestPlatformVersion) {
36
+ return;
37
+ }
38
+ const maximumVersion = await determineProductionVersion();
39
+ if (!maximumVersion) {
40
+ return;
41
+ }
42
+ if ((0, semver_1.gt)(manifestPlatformVersion, maximumVersion)) {
43
+ context.report(`The specified platform version "${manifestPlatformVersion}" is not supported in the production version of MetaMask. The current maximum supported version is "${maximumVersion}". To resolve this, downgrade \`@metamask/snaps-sdk\` to a compatible version.`);
44
+ }
45
+ },
46
+ };
47
+ //# sourceMappingURL=production-platform-version.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production-platform-version.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/production-platform-version.ts"],"names":[],"mappings":";;;AAAA,2CAA2D;AAC3D,mCAAwC;AAExC,qCAA8C;AAG9C;;;;;GAKG;AACH,MAAM,0BAA0B,GAAG,IAAA,uBAAkB,EACnD,0BAA0B,EAC1B,IAAA,sBAAc,EAAC,CAAC,EAAE,gBAAQ,CAAC,GAAG,CAAC,EAC/B,KAAK,IAAI,EAAE;IACT,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,KAAK,CAC/B,0EAA0E,CAC3E,CAAC;QAEF,MAAM,iBAAiB,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,CAAC;QAErD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,gBAAgB,CAAC;QAE/D,MAAM,mBAAmB,GAAG,MAAM,KAAK,CACrC,sFAAsF,mBAAmB,EAAE,EAC3G,EAAE,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,iCAAiC,EAAE,CAAC,EAAE,CACxE,CAAC;QAEF,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,IAAI,EAAE,CAAC;QAErD,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC;QAErE,OAAO,IAAA,mBAAU,EAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC;AAEF;;;GAGG;AACU,QAAA,yBAAyB,GAAkB;IACtD,QAAQ,EAAE,SAAS;IACnB,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO;QAChC,MAAM,uBAAuB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC;QAEtE,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,0BAA0B,EAAE,CAAC;QAE1D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,IAAA,WAAE,EAAC,uBAAuB,EAAE,cAAc,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,MAAM,CACZ,mCAAmC,uBAAuB,uGAAuG,cAAc,gFAAgF,CAChQ,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import { Duration, inMilliseconds } from '@metamask/utils';\nimport { minVersion, gt } from 'semver';\n\nimport { useFileSystemCache } from '../../fs';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Determine the production version of the Snaps platform by inspecting\n * the latest GitHub release of the MetaMask extension.\n *\n * @returns The production version of the Snaps platform or null if any error occurred.\n */\nconst determineProductionVersion = useFileSystemCache(\n 'snaps-production-version',\n inMilliseconds(3, Duration.Day),\n async () => {\n try {\n const latestRelease = await fetch(\n 'https://api.github.com/repos/metamask/metamask-extension/releases/latest',\n );\n\n const latestReleaseJson = await latestRelease.json();\n\n const latestReleaseCommit = latestReleaseJson.target_commitish;\n\n const packageJsonResponse = await fetch(\n `https://api.github.com/repos/metamask/metamask-extension/contents/package.json?ref=${latestReleaseCommit}`,\n { headers: new Headers({ accept: 'application/vnd.github.raw+json' }) },\n );\n\n const packageJson = await packageJsonResponse.json();\n\n const versionRange = packageJson.dependencies['@metamask/snaps-sdk'];\n\n return minVersion(versionRange)?.format();\n } catch {\n return null;\n }\n },\n);\n\n/**\n * Check if the platform version in manifest exceeds the version\n * used in production.\n */\nexport const productionPlatformVersion: ValidatorMeta = {\n severity: 'warning',\n async semanticCheck(files, context) {\n const manifestPlatformVersion = files.manifest.result.platformVersion;\n\n if (!manifestPlatformVersion) {\n return;\n }\n\n const maximumVersion = await determineProductionVersion();\n\n if (!maximumVersion) {\n return;\n }\n\n if (gt(manifestPlatformVersion, maximumVersion)) {\n context.report(\n `The specified platform version \"${manifestPlatformVersion}\" is not supported in the production version of MetaMask. The current maximum supported version is \"${maximumVersion}\". To resolve this, downgrade \\`@metamask/snaps-sdk\\` to a compatible version.`,\n );\n }\n },\n};\n"]}
@@ -0,0 +1,7 @@
1
+ import type { ValidatorMeta } from "../validator-types.cjs";
2
+ /**
3
+ * Check if the platform version in manifest exceeds the version
4
+ * used in production.
5
+ */
6
+ export declare const productionPlatformVersion: ValidatorMeta;
7
+ //# sourceMappingURL=production-platform-version.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production-platform-version.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/production-platform-version.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAqCxD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,aAqBvC,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ValidatorMeta } from "../validator-types.mjs";
2
+ /**
3
+ * Check if the platform version in manifest exceeds the version
4
+ * used in production.
5
+ */
6
+ export declare const productionPlatformVersion: ValidatorMeta;
7
+ //# sourceMappingURL=production-platform-version.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production-platform-version.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/production-platform-version.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAqCxD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,aAqBvC,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { Duration, inMilliseconds } from "@metamask/utils";
2
+ import { minVersion, gt } from "semver";
3
+ import { useFileSystemCache } from "../../fs.mjs";
4
+ /**
5
+ * Determine the production version of the Snaps platform by inspecting
6
+ * the latest GitHub release of the MetaMask extension.
7
+ *
8
+ * @returns The production version of the Snaps platform or null if any error occurred.
9
+ */
10
+ const determineProductionVersion = useFileSystemCache('snaps-production-version', inMilliseconds(3, Duration.Day), async () => {
11
+ try {
12
+ const latestRelease = await fetch('https://api.github.com/repos/metamask/metamask-extension/releases/latest');
13
+ const latestReleaseJson = await latestRelease.json();
14
+ const latestReleaseCommit = latestReleaseJson.target_commitish;
15
+ const packageJsonResponse = await fetch(`https://api.github.com/repos/metamask/metamask-extension/contents/package.json?ref=${latestReleaseCommit}`, { headers: new Headers({ accept: 'application/vnd.github.raw+json' }) });
16
+ const packageJson = await packageJsonResponse.json();
17
+ const versionRange = packageJson.dependencies['@metamask/snaps-sdk'];
18
+ return minVersion(versionRange)?.format();
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ });
24
+ /**
25
+ * Check if the platform version in manifest exceeds the version
26
+ * used in production.
27
+ */
28
+ export const productionPlatformVersion = {
29
+ severity: 'warning',
30
+ async semanticCheck(files, context) {
31
+ const manifestPlatformVersion = files.manifest.result.platformVersion;
32
+ if (!manifestPlatformVersion) {
33
+ return;
34
+ }
35
+ const maximumVersion = await determineProductionVersion();
36
+ if (!maximumVersion) {
37
+ return;
38
+ }
39
+ if (gt(manifestPlatformVersion, maximumVersion)) {
40
+ context.report(`The specified platform version "${manifestPlatformVersion}" is not supported in the production version of MetaMask. The current maximum supported version is "${maximumVersion}". To resolve this, downgrade \`@metamask/snaps-sdk\` to a compatible version.`);
41
+ }
42
+ },
43
+ };
44
+ //# sourceMappingURL=production-platform-version.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production-platform-version.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/production-platform-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,wBAAwB;AAC3D,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe;AAExC,OAAO,EAAE,kBAAkB,EAAE,qBAAiB;AAG9C;;;;;GAKG;AACH,MAAM,0BAA0B,GAAG,kBAAkB,CACnD,0BAA0B,EAC1B,cAAc,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,EAC/B,KAAK,IAAI,EAAE;IACT,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,KAAK,CAC/B,0EAA0E,CAC3E,CAAC;QAEF,MAAM,iBAAiB,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,CAAC;QAErD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,gBAAgB,CAAC;QAE/D,MAAM,mBAAmB,GAAG,MAAM,KAAK,CACrC,sFAAsF,mBAAmB,EAAE,EAC3G,EAAE,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,iCAAiC,EAAE,CAAC,EAAE,CACxE,CAAC;QAEF,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,IAAI,EAAE,CAAC;QAErD,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC;QAErE,OAAO,UAAU,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAkB;IACtD,QAAQ,EAAE,SAAS;IACnB,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO;QAChC,MAAM,uBAAuB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC;QAEtE,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,0BAA0B,EAAE,CAAC;QAE1D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,EAAE,CAAC,uBAAuB,EAAE,cAAc,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,MAAM,CACZ,mCAAmC,uBAAuB,uGAAuG,cAAc,gFAAgF,CAChQ,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import { Duration, inMilliseconds } from '@metamask/utils';\nimport { minVersion, gt } from 'semver';\n\nimport { useFileSystemCache } from '../../fs';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Determine the production version of the Snaps platform by inspecting\n * the latest GitHub release of the MetaMask extension.\n *\n * @returns The production version of the Snaps platform or null if any error occurred.\n */\nconst determineProductionVersion = useFileSystemCache(\n 'snaps-production-version',\n inMilliseconds(3, Duration.Day),\n async () => {\n try {\n const latestRelease = await fetch(\n 'https://api.github.com/repos/metamask/metamask-extension/releases/latest',\n );\n\n const latestReleaseJson = await latestRelease.json();\n\n const latestReleaseCommit = latestReleaseJson.target_commitish;\n\n const packageJsonResponse = await fetch(\n `https://api.github.com/repos/metamask/metamask-extension/contents/package.json?ref=${latestReleaseCommit}`,\n { headers: new Headers({ accept: 'application/vnd.github.raw+json' }) },\n );\n\n const packageJson = await packageJsonResponse.json();\n\n const versionRange = packageJson.dependencies['@metamask/snaps-sdk'];\n\n return minVersion(versionRange)?.format();\n } catch {\n return null;\n }\n },\n);\n\n/**\n * Check if the platform version in manifest exceeds the version\n * used in production.\n */\nexport const productionPlatformVersion: ValidatorMeta = {\n severity: 'warning',\n async semanticCheck(files, context) {\n const manifestPlatformVersion = files.manifest.result.platformVersion;\n\n if (!manifestPlatformVersion) {\n return;\n }\n\n const maximumVersion = await determineProductionVersion();\n\n if (!maximumVersion) {\n return;\n }\n\n if (gt(manifestPlatformVersion, maximumVersion)) {\n context.report(\n `The specified platform version \"${manifestPlatformVersion}\" is not supported in the production version of MetaMask. The current maximum supported version is \"${maximumVersion}\". To resolve this, downgrade \\`@metamask/snaps-sdk\\` to a compatible version.`,\n );\n }\n },\n};\n"]}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unusedExports = void 0;
4
+ /**
5
+ * Check if the Snap exports handlers that are not requested in the manifest, or
6
+ * if the Snap requests permissions for handlers that are not exported.
7
+ */
8
+ exports.unusedExports = {
9
+ severity: 'warning',
10
+ semanticCheck(files, context) {
11
+ const { handlerEndowments, exports } = context.options ?? {};
12
+ // The handler endowments or exports must be provided for this check to be
13
+ // performed.
14
+ if (!handlerEndowments || !exports) {
15
+ return;
16
+ }
17
+ const unusedHandlers = Object.entries(handlerEndowments)
18
+ .filter(([handler, endowment]) => {
19
+ if (endowment === null) {
20
+ return false;
21
+ }
22
+ return (exports.includes(handler) &&
23
+ !files.manifest.result.initialPermissions[endowment]);
24
+ })
25
+ .map(([handler, endowment]) => `${handler} (${endowment})`);
26
+ const unusedEndowments = Object.entries(handlerEndowments).filter(([handler, endowment]) => {
27
+ if (endowment === null) {
28
+ return false;
29
+ }
30
+ return (files.manifest.result.initialPermissions[endowment] && !exports.includes(handler));
31
+ });
32
+ if (unusedHandlers.length > 0) {
33
+ // We don't specify a fix function here, because:
34
+ // 1. Removing the export from the Snap bundle is complicated, as it
35
+ // requires AST manipulation.
36
+ // 2. Adding the permission to the manifest is not always possible, as it
37
+ // may require additional configuration in the manifest.
38
+ context.report(`The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(', ')}.`);
39
+ }
40
+ if (unusedEndowments.length > 0) {
41
+ const formattedEndowments = unusedEndowments
42
+ .map(([handler, endowment]) => `${handler} (${endowment})`)
43
+ .join(', ');
44
+ context.report(`The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`, ({ manifest }) => {
45
+ unusedEndowments.forEach(([, endowment]) => {
46
+ delete manifest.initialPermissions[endowment];
47
+ });
48
+ return { manifest };
49
+ });
50
+ }
51
+ },
52
+ };
53
+ //# sourceMappingURL=unused-exports.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unused-exports.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":";;;AAIA;;;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,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,kBAAkB,CACvC,SAAqC,CACtC,CACF,CAAC;QACJ,CAAC,CAAC;aACD,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC,CAAC;QAE9D,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAC/D,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YACvB,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACtC,SAAqC,CACtC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAChC,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,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/**\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 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) {\n return false;\n }\n\n return (\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\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"]}
@@ -0,0 +1,7 @@
1
+ import type { ValidatorMeta } from "../validator-types.cjs";
2
+ /**
3
+ * Check if the Snap exports handlers that are not requested in the manifest, or
4
+ * if the Snap requests permissions for handlers that are not exported.
5
+ */
6
+ export declare const unusedExports: ValidatorMeta;
7
+ //# sourceMappingURL=unused-exports.d.cts.map
@@ -0,0 +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;AAExD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAwE3B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ValidatorMeta } from "../validator-types.mjs";
2
+ /**
3
+ * Check if the Snap exports handlers that are not requested in the manifest, or
4
+ * if the Snap requests permissions for handlers that are not exported.
5
+ */
6
+ export declare const unusedExports: ValidatorMeta;
7
+ //# sourceMappingURL=unused-exports.d.mts.map
@@ -0,0 +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;AAExD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAwE3B,CAAC"}