@metamask/snaps-utils 8.2.0 → 8.3.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 (60) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/currency.cjs +20 -0
  3. package/dist/currency.cjs.map +1 -0
  4. package/dist/currency.d.cts +11 -0
  5. package/dist/currency.d.cts.map +1 -0
  6. package/dist/currency.d.mts +11 -0
  7. package/dist/currency.d.mts.map +1 -0
  8. package/dist/currency.mjs +16 -0
  9. package/dist/currency.mjs.map +1 -0
  10. package/dist/errors.cjs +24 -11
  11. package/dist/errors.cjs.map +1 -1
  12. package/dist/errors.mjs +24 -11
  13. package/dist/errors.mjs.map +1 -1
  14. package/dist/eval.cjs +0 -1
  15. package/dist/eval.cjs.map +1 -1
  16. package/dist/eval.mjs +0 -1
  17. package/dist/eval.mjs.map +1 -1
  18. package/dist/handlers.d.cts +7 -0
  19. package/dist/handlers.d.cts.map +1 -1
  20. package/dist/handlers.d.mts +7 -0
  21. package/dist/handlers.d.mts.map +1 -1
  22. package/dist/iframe.cjs +8 -5
  23. package/dist/iframe.cjs.map +1 -1
  24. package/dist/iframe.d.cts +12 -4
  25. package/dist/iframe.d.cts.map +1 -1
  26. package/dist/iframe.d.mts +12 -4
  27. package/dist/iframe.d.mts.map +1 -1
  28. package/dist/iframe.mjs +8 -5
  29. package/dist/iframe.mjs.map +1 -1
  30. package/dist/iframe.test.browser.cjs +36 -1
  31. package/dist/iframe.test.browser.cjs.map +1 -1
  32. package/dist/iframe.test.browser.mjs +36 -1
  33. package/dist/iframe.test.browser.mjs.map +1 -1
  34. package/dist/index.cjs +1 -0
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +1 -0
  37. package/dist/index.d.cts.map +1 -1
  38. package/dist/index.d.mts +1 -0
  39. package/dist/index.d.mts.map +1 -1
  40. package/dist/index.mjs +1 -0
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/manifest/validation.cjs +1 -1
  43. package/dist/manifest/validation.cjs.map +1 -1
  44. package/dist/manifest/validation.mjs +1 -1
  45. package/dist/manifest/validation.mjs.map +1 -1
  46. package/dist/manifest/validator.cjs +20 -5
  47. package/dist/manifest/validator.cjs.map +1 -1
  48. package/dist/manifest/validator.mjs +20 -5
  49. package/dist/manifest/validator.mjs.map +1 -1
  50. package/dist/types.cjs +1 -1
  51. package/dist/types.cjs.map +1 -1
  52. package/dist/types.d.cts.map +1 -1
  53. package/dist/types.d.mts.map +1 -1
  54. package/dist/types.mjs +2 -2
  55. package/dist/types.mjs.map +1 -1
  56. package/dist/virtual-file/VirtualFile.cjs +0 -4
  57. package/dist/virtual-file/VirtualFile.cjs.map +1 -1
  58. package/dist/virtual-file/VirtualFile.mjs +0 -4
  59. package/dist/virtual-file/VirtualFile.mjs.map +1 -1
  60. package/package.json +2 -2
@@ -1 +1 @@
1
- {"version":3,"file":"iframe.cjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,GAAW,EACX,EAAU,EACV,OAAO,GAAG,IAAI;IAEd,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;QAEnD,IAAI,OAAO,EAAE,CAAC;YACZ,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAClD,CAAC;QAED,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACnC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACzB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,EAAE,IAAI,CAC5D,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhDD,oCAgDC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n * @param uri - The iframe URI.\n * @param id - The ID to assign to the iframe.\n * @param sandbox - Whether to enable the sandbox attribute.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow(\n uri: string,\n id: string,\n sandbox = true,\n): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', 'snaps-iframe');\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n });\n });\n}\n"]}
1
+ {"version":3,"file":"iframe.cjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;GAYG;AACI,KAAK,UAAU,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAO,GAAG,IAAI,EACd,MAAM,GAAG,cAAc,GAMxB;IACC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAE3C,IAAI,OAAO,EAAE,CAAC;YACZ,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAClD,CAAC;QAED,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACnC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACzB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,EAAE,IAAI,CAC5D,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAtDD,oCAsDC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n *\n * @param options - The options for createWindow.\n * @param options.uri - The iframe URI.\n * @param options.id - The ID to assign to the iframe.\n * @param options.sandbox - Whether to enable the sandbox attribute.\n * @param options.testId - The data-testid attribute to assign to the iframe.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow({\n uri,\n id,\n sandbox = true,\n testId = 'snaps-iframe',\n}: {\n uri: string;\n id: string;\n sandbox?: boolean;\n testId?: string;\n}): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', testId);\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n });\n });\n}\n"]}
package/dist/iframe.d.cts CHANGED
@@ -3,10 +3,18 @@
3
3
  * forever if the iframe never loads, but the promise should be wrapped in
4
4
  * an initialization timeout in the SnapController.
5
5
  *
6
- * @param uri - The iframe URI.
7
- * @param id - The ID to assign to the iframe.
8
- * @param sandbox - Whether to enable the sandbox attribute.
6
+ *
7
+ * @param options - The options for createWindow.
8
+ * @param options.uri - The iframe URI.
9
+ * @param options.id - The ID to assign to the iframe.
10
+ * @param options.sandbox - Whether to enable the sandbox attribute.
11
+ * @param options.testId - The data-testid attribute to assign to the iframe.
9
12
  * @returns A promise that resolves to the contentWindow of the iframe.
10
13
  */
11
- export declare function createWindow(uri: string, id: string, sandbox?: boolean): Promise<Window>;
14
+ export declare function createWindow({ uri, id, sandbox, testId, }: {
15
+ uri: string;
16
+ id: string;
17
+ sandbox?: boolean;
18
+ testId?: string;
19
+ }): Promise<Window>;
12
20
  //# sourceMappingURL=iframe.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"iframe.d.cts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,EACV,OAAO,UAAO,GACb,OAAO,CAAC,MAAM,CAAC,CA4CjB"}
1
+ {"version":3,"file":"iframe.d.cts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAc,EACd,MAAuB,GACxB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4ClB"}
package/dist/iframe.d.mts CHANGED
@@ -3,10 +3,18 @@
3
3
  * forever if the iframe never loads, but the promise should be wrapped in
4
4
  * an initialization timeout in the SnapController.
5
5
  *
6
- * @param uri - The iframe URI.
7
- * @param id - The ID to assign to the iframe.
8
- * @param sandbox - Whether to enable the sandbox attribute.
6
+ *
7
+ * @param options - The options for createWindow.
8
+ * @param options.uri - The iframe URI.
9
+ * @param options.id - The ID to assign to the iframe.
10
+ * @param options.sandbox - Whether to enable the sandbox attribute.
11
+ * @param options.testId - The data-testid attribute to assign to the iframe.
9
12
  * @returns A promise that resolves to the contentWindow of the iframe.
10
13
  */
11
- export declare function createWindow(uri: string, id: string, sandbox?: boolean): Promise<Window>;
14
+ export declare function createWindow({ uri, id, sandbox, testId, }: {
15
+ uri: string;
16
+ id: string;
17
+ sandbox?: boolean;
18
+ testId?: string;
19
+ }): Promise<Window>;
12
20
  //# sourceMappingURL=iframe.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"iframe.d.mts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAChC,GAAG,EAAE,MAAM,EACX,EAAE,EAAE,MAAM,EACV,OAAO,UAAO,GACb,OAAO,CAAC,MAAM,CAAC,CA4CjB"}
1
+ {"version":3,"file":"iframe.d.mts","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,wBAAsB,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAc,EACd,MAAuB,GACxB,EAAE;IACD,GAAG,EAAE,MAAM,CAAC;IACZ,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,GAAG,OAAO,CAAC,MAAM,CAAC,CA4ClB"}
package/dist/iframe.mjs CHANGED
@@ -3,18 +3,21 @@
3
3
  * forever if the iframe never loads, but the promise should be wrapped in
4
4
  * an initialization timeout in the SnapController.
5
5
  *
6
- * @param uri - The iframe URI.
7
- * @param id - The ID to assign to the iframe.
8
- * @param sandbox - Whether to enable the sandbox attribute.
6
+ *
7
+ * @param options - The options for createWindow.
8
+ * @param options.uri - The iframe URI.
9
+ * @param options.id - The ID to assign to the iframe.
10
+ * @param options.sandbox - Whether to enable the sandbox attribute.
11
+ * @param options.testId - The data-testid attribute to assign to the iframe.
9
12
  * @returns A promise that resolves to the contentWindow of the iframe.
10
13
  */
11
- export async function createWindow(uri, id, sandbox = true) {
14
+ export async function createWindow({ uri, id, sandbox = true, testId = 'snaps-iframe', }) {
12
15
  return await new Promise((resolve, reject) => {
13
16
  const iframe = document.createElement('iframe');
14
17
  // The order of operations appears to matter for everything except this
15
18
  // attribute. We may as well set it here.
16
19
  iframe.setAttribute('id', id);
17
- iframe.setAttribute('data-testid', 'snaps-iframe');
20
+ iframe.setAttribute('data-testid', testId);
18
21
  if (sandbox) {
19
22
  // For the sandbox property to have any effect it needs to be set before the iframe is appended.
20
23
  // We apply this property as a principle of least authority (POLA)
@@ -1 +1 @@
1
- {"version":3,"file":"iframe.mjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,GAAW,EACX,EAAU,EACV,OAAO,GAAG,IAAI;IAEd,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;QAEnD,IAAI,OAAO,EAAE,CAAC;YACZ,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAClD,CAAC;QAED,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACnC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACzB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,EAAE,IAAI,CAC5D,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n * @param uri - The iframe URI.\n * @param id - The ID to assign to the iframe.\n * @param sandbox - Whether to enable the sandbox attribute.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow(\n uri: string,\n id: string,\n sandbox = true,\n): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', 'snaps-iframe');\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n });\n });\n}\n"]}
1
+ {"version":3,"file":"iframe.mjs","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAAC,EACjC,GAAG,EACH,EAAE,EACF,OAAO,GAAG,IAAI,EACd,MAAM,GAAG,cAAc,GAMxB;IACC,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,MAAM,CAAC,CAAC;QAE3C,IAAI,OAAO,EAAE,CAAC;YACZ,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAClD,CAAC;QAED,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACnC,IAAI,MAAM,CAAC,aAAa,EAAE,CAAC;gBACzB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;YAChC,CAAC;iBAAM,CAAC;gBACN,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,EAAE,IAAI,CAC5D,CACF,CAAC;YACJ,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n *\n * @param options - The options for createWindow.\n * @param options.uri - The iframe URI.\n * @param options.id - The ID to assign to the iframe.\n * @param options.sandbox - Whether to enable the sandbox attribute.\n * @param options.testId - The data-testid attribute to assign to the iframe.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow({\n uri,\n id,\n sandbox = true,\n testId = 'snaps-iframe',\n}: {\n uri: string;\n id: string;\n sandbox?: boolean;\n testId?: string;\n}): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', testId);\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n });\n });\n}\n"]}
@@ -4,12 +4,47 @@ const iframe_1 = require("./iframe.cjs");
4
4
  const IFRAME_URL = `http://localhost:4569`;
5
5
  const MOCK_JOB_ID = 'job-id';
6
6
  describe('createWindow', () => {
7
+ afterEach(() => {
8
+ const iframe = document.getElementById(MOCK_JOB_ID);
9
+ if (iframe) {
10
+ document.body.removeChild(iframe);
11
+ }
12
+ });
7
13
  it('creates an iframe window with the provided job ID as the iframe ID', async () => {
8
- const window = await (0, iframe_1.createWindow)(IFRAME_URL, MOCK_JOB_ID);
14
+ const window = await (0, iframe_1.createWindow)({ uri: IFRAME_URL, id: MOCK_JOB_ID });
9
15
  const iframe = document.getElementById(MOCK_JOB_ID);
10
16
  expect(iframe).toBeDefined();
11
17
  expect(iframe.contentWindow).toBe(window);
12
18
  expect(iframe.id).toBe(MOCK_JOB_ID);
13
19
  });
20
+ it('sets the sandbox attribute when the sandbox option is true', async () => {
21
+ await (0, iframe_1.createWindow)({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: true });
22
+ const iframe = document.getElementById(MOCK_JOB_ID);
23
+ expect(iframe).toBeDefined();
24
+ expect(iframe.getAttribute('sandbox')).toBe('allow-scripts');
25
+ });
26
+ it('does not set the sandbox attribute when the sandbox option is false', async () => {
27
+ await (0, iframe_1.createWindow)({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: false });
28
+ const iframe = document.getElementById(MOCK_JOB_ID);
29
+ expect(iframe).toBeDefined();
30
+ expect(iframe.getAttribute('sandbox')).toBeNull();
31
+ });
32
+ it('sets the data-testid attribute when provided', async () => {
33
+ const testId = 'test-id';
34
+ await (0, iframe_1.createWindow)({
35
+ uri: IFRAME_URL,
36
+ id: MOCK_JOB_ID,
37
+ testId,
38
+ });
39
+ const iframe = document.getElementById(MOCK_JOB_ID);
40
+ expect(iframe).toBeDefined();
41
+ expect(iframe.getAttribute('data-testid')).toBe(testId);
42
+ });
43
+ it('uses the default data-testid attribute when not provided', async () => {
44
+ await (0, iframe_1.createWindow)({ uri: IFRAME_URL, id: MOCK_JOB_ID });
45
+ const iframe = document.getElementById(MOCK_JOB_ID);
46
+ expect(iframe).toBeDefined();
47
+ expect(iframe.getAttribute('data-testid')).toBe('snaps-iframe');
48
+ });
14
49
  });
15
50
  //# sourceMappingURL=iframe.test.browser.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"iframe.test.browser.cjs","sourceRoot":"","sources":["../src/iframe.test.browser.ts"],"names":[],"mappings":";;AAAA,yCAAwC;AAExC,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,oEAAoE,EAAE,KAAK,IAAI,EAAE;QAClF,MAAM,MAAM,GAAG,MAAM,IAAA,qBAAY,EAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAsB,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { createWindow } from './iframe';\n\nconst IFRAME_URL = `http://localhost:4569`;\n\nconst MOCK_JOB_ID = 'job-id';\n\ndescribe('createWindow', () => {\n it('creates an iframe window with the provided job ID as the iframe ID', async () => {\n const window = await createWindow(IFRAME_URL, MOCK_JOB_ID);\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.contentWindow).toBe(window);\n expect(iframe.id).toBe(MOCK_JOB_ID);\n });\n});\n"]}
1
+ {"version":3,"file":"iframe.test.browser.cjs","sourceRoot":"","sources":["../src/iframe.test.browser.ts"],"names":[],"mappings":";;AAAA,yCAAwC;AAExC,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,MAAM,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B,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,MAAM,GAAG,SAAS,CAAC;QAEzB,MAAM,IAAA,qBAAY,EAAC;YACjB,GAAG,EAAE,UAAU;YACf,EAAE,EAAE,WAAW;YACf,MAAM;SACP,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAsB,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;QACxE,MAAM,IAAA,qBAAY,EAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;QACzD,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAsB,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { createWindow } from './iframe';\n\nconst IFRAME_URL = `http://localhost:4569`;\n\nconst MOCK_JOB_ID = 'job-id';\n\ndescribe('createWindow', () => {\n afterEach(() => {\n const iframe = document.getElementById(MOCK_JOB_ID);\n if (iframe) {\n document.body.removeChild(iframe);\n }\n });\n\n it('creates an iframe window with the provided job ID as the iframe ID', async () => {\n const window = await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.contentWindow).toBe(window);\n expect(iframe.id).toBe(MOCK_JOB_ID);\n });\n\n it('sets the sandbox attribute when the sandbox option is true', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: true });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('sandbox')).toBe('allow-scripts');\n });\n\n it('does not set the sandbox attribute when the sandbox option is false', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: false });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('sandbox')).toBeNull();\n });\n\n it('sets the data-testid attribute when provided', async () => {\n const testId = 'test-id';\n\n await createWindow({\n uri: IFRAME_URL,\n id: MOCK_JOB_ID,\n testId,\n });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('data-testid')).toBe(testId);\n });\n\n it('uses the default data-testid attribute when not provided', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('data-testid')).toBe('snaps-iframe');\n });\n});\n"]}
@@ -2,12 +2,47 @@ import { createWindow } from "./iframe.mjs";
2
2
  const IFRAME_URL = `http://localhost:4569`;
3
3
  const MOCK_JOB_ID = 'job-id';
4
4
  describe('createWindow', () => {
5
+ afterEach(() => {
6
+ const iframe = document.getElementById(MOCK_JOB_ID);
7
+ if (iframe) {
8
+ document.body.removeChild(iframe);
9
+ }
10
+ });
5
11
  it('creates an iframe window with the provided job ID as the iframe ID', async () => {
6
- const window = await createWindow(IFRAME_URL, MOCK_JOB_ID);
12
+ const window = await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });
7
13
  const iframe = document.getElementById(MOCK_JOB_ID);
8
14
  expect(iframe).toBeDefined();
9
15
  expect(iframe.contentWindow).toBe(window);
10
16
  expect(iframe.id).toBe(MOCK_JOB_ID);
11
17
  });
18
+ it('sets the sandbox attribute when the sandbox option is true', async () => {
19
+ await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: true });
20
+ const iframe = document.getElementById(MOCK_JOB_ID);
21
+ expect(iframe).toBeDefined();
22
+ expect(iframe.getAttribute('sandbox')).toBe('allow-scripts');
23
+ });
24
+ it('does not set the sandbox attribute when the sandbox option is false', async () => {
25
+ await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: false });
26
+ const iframe = document.getElementById(MOCK_JOB_ID);
27
+ expect(iframe).toBeDefined();
28
+ expect(iframe.getAttribute('sandbox')).toBeNull();
29
+ });
30
+ it('sets the data-testid attribute when provided', async () => {
31
+ const testId = 'test-id';
32
+ await createWindow({
33
+ uri: IFRAME_URL,
34
+ id: MOCK_JOB_ID,
35
+ testId,
36
+ });
37
+ const iframe = document.getElementById(MOCK_JOB_ID);
38
+ expect(iframe).toBeDefined();
39
+ expect(iframe.getAttribute('data-testid')).toBe(testId);
40
+ });
41
+ it('uses the default data-testid attribute when not provided', async () => {
42
+ await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });
43
+ const iframe = document.getElementById(MOCK_JOB_ID);
44
+ expect(iframe).toBeDefined();
45
+ expect(iframe.getAttribute('data-testid')).toBe('snaps-iframe');
46
+ });
12
47
  });
13
48
  //# sourceMappingURL=iframe.test.browser.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"iframe.test.browser.mjs","sourceRoot":"","sources":["../src/iframe.test.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAiB;AAExC,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,EAAE,CAAC,oEAAoE,EAAE,KAAK,IAAI,EAAE;QAClF,MAAM,MAAM,GAAG,MAAM,YAAY,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAsB,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { createWindow } from './iframe';\n\nconst IFRAME_URL = `http://localhost:4569`;\n\nconst MOCK_JOB_ID = 'job-id';\n\ndescribe('createWindow', () => {\n it('creates an iframe window with the provided job ID as the iframe ID', async () => {\n const window = await createWindow(IFRAME_URL, MOCK_JOB_ID);\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.contentWindow).toBe(window);\n expect(iframe.id).toBe(MOCK_JOB_ID);\n });\n});\n"]}
1
+ {"version":3,"file":"iframe.test.browser.mjs","sourceRoot":"","sources":["../src/iframe.test.browser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qBAAiB;AAExC,MAAM,UAAU,GAAG,uBAAuB,CAAC;AAE3C,MAAM,WAAW,GAAG,QAAQ,CAAC;AAE7B,QAAQ,CAAC,cAAc,EAAE,GAAG,EAAE;IAC5B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC;QAC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C;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;IACpD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,8CAA8C,EAAE,KAAK,IAAI,EAAE;QAC5D,MAAM,MAAM,GAAG,SAAS,CAAC;QAEzB,MAAM,YAAY,CAAC;YACjB,GAAG,EAAE,UAAU;YACf,EAAE,EAAE,WAAW;YACf,MAAM;SACP,CAAC,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAsB,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,0DAA0D,EAAE,KAAK,IAAI,EAAE;QACxE,MAAM,YAAY,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;QACzD,MAAM,MAAM,GAAG,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAsB,CAAC;QAEzE,MAAM,CAAC,MAAM,CAAC,CAAC,WAAW,EAAE,CAAC;QAC7B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { createWindow } from './iframe';\n\nconst IFRAME_URL = `http://localhost:4569`;\n\nconst MOCK_JOB_ID = 'job-id';\n\ndescribe('createWindow', () => {\n afterEach(() => {\n const iframe = document.getElementById(MOCK_JOB_ID);\n if (iframe) {\n document.body.removeChild(iframe);\n }\n });\n\n it('creates an iframe window with the provided job ID as the iframe ID', async () => {\n const window = await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.contentWindow).toBe(window);\n expect(iframe.id).toBe(MOCK_JOB_ID);\n });\n\n it('sets the sandbox attribute when the sandbox option is true', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: true });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('sandbox')).toBe('allow-scripts');\n });\n\n it('does not set the sandbox attribute when the sandbox option is false', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID, sandbox: false });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('sandbox')).toBeNull();\n });\n\n it('sets the data-testid attribute when provided', async () => {\n const testId = 'test-id';\n\n await createWindow({\n uri: IFRAME_URL,\n id: MOCK_JOB_ID,\n testId,\n });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('data-testid')).toBe(testId);\n });\n\n it('uses the default data-testid attribute when not provided', async () => {\n await createWindow({ uri: IFRAME_URL, id: MOCK_JOB_ID });\n const iframe = document.getElementById(MOCK_JOB_ID) as HTMLIFrameElement;\n\n expect(iframe).toBeDefined();\n expect(iframe.getAttribute('data-testid')).toBe('snaps-iframe');\n });\n});\n"]}
package/dist/index.cjs CHANGED
@@ -22,6 +22,7 @@ __exportStar(require("./caveats.cjs"), exports);
22
22
  __exportStar(require("./checksum.cjs"), exports);
23
23
  __exportStar(require("./constants.cjs"), exports);
24
24
  __exportStar(require("./cronjob.cjs"), exports);
25
+ __exportStar(require("./currency.cjs"), exports);
25
26
  __exportStar(require("./deep-clone.cjs"), exports);
26
27
  __exportStar(require("./default-endowments.cjs"), exports);
27
28
  __exportStar(require("./derivation-paths.cjs"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,wDAAkC;AAClC,+CAAyB;AACzB,8CAAwB;AACxB,gDAA0B;AAC1B,iDAA2B;AAC3B,kDAA4B;AAC5B,gDAA0B;AAC1B,mDAA6B;AAC7B,2DAAqC;AACrC,yDAAmC;AACnC,gDAA0B;AAC1B,+CAAyB;AACzB,iDAA2B;AAC3B,sDAAgC;AAChC,+CAAyB;AACzB,6CAAuB;AACvB,iDAA2B;AAC3B,qDAA+B;AAC/B,gDAA0B;AAC1B,uDAA2B;AAC3B,kDAA4B;AAC5B,6CAAuB;AACvB,8CAAwB;AACxB,gDAA0B;AAC1B,gDAA0B;AAC1B,8CAAwB;AACxB,2CAAqB;AACrB,mDAA6B;AAC7B,iDAA2B;AAC3B,2DAA+B;AAC/B,gDAA0B","sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport * from './promise';\n"]}
1
+ {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAAwB;AACxB,wDAAkC;AAClC,+CAAyB;AACzB,8CAAwB;AACxB,gDAA0B;AAC1B,iDAA2B;AAC3B,kDAA4B;AAC5B,gDAA0B;AAC1B,iDAA2B;AAC3B,mDAA6B;AAC7B,2DAAqC;AACrC,yDAAmC;AACnC,gDAA0B;AAC1B,+CAAyB;AACzB,iDAA2B;AAC3B,sDAAgC;AAChC,+CAAyB;AACzB,6CAAuB;AACvB,iDAA2B;AAC3B,qDAA+B;AAC/B,gDAA0B;AAC1B,uDAA2B;AAC3B,kDAA4B;AAC5B,6CAAuB;AACvB,8CAAwB;AACxB,gDAA0B;AAC1B,gDAA0B;AAC1B,8CAAwB;AACxB,2CAAqB;AACrB,mDAA6B;AAC7B,iDAA2B;AAC3B,2DAA+B;AAC/B,gDAA0B","sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './currency';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport * from './promise';\n"]}
package/dist/index.d.cts CHANGED
@@ -6,6 +6,7 @@ export * from "./caveats.cjs";
6
6
  export * from "./checksum.cjs";
7
7
  export * from "./constants.cjs";
8
8
  export * from "./cronjob.cjs";
9
+ export * from "./currency.cjs";
9
10
  export * from "./deep-clone.cjs";
10
11
  export * from "./default-endowments.cjs";
11
12
  export * from "./derivation-paths.cjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B"}
1
+ {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B"}
package/dist/index.d.mts CHANGED
@@ -6,6 +6,7 @@ export * from "./caveats.mjs";
6
6
  export * from "./checksum.mjs";
7
7
  export * from "./constants.mjs";
8
8
  export * from "./cronjob.mjs";
9
+ export * from "./currency.mjs";
9
10
  export * from "./deep-clone.mjs";
10
11
  export * from "./default-endowments.mjs";
11
12
  export * from "./derivation-paths.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B"}
1
+ {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B"}
package/dist/index.mjs CHANGED
@@ -6,6 +6,7 @@ export * from "./caveats.mjs";
6
6
  export * from "./checksum.mjs";
7
7
  export * from "./constants.mjs";
8
8
  export * from "./cronjob.mjs";
9
+ export * from "./currency.mjs";
9
10
  export * from "./deep-clone.mjs";
10
11
  export * from "./default-endowments.mjs";
11
12
  export * from "./derivation-paths.mjs";
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B","sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport * from './promise';\n"]}
1
+ {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,4BAAwB;AACxB,sCAAkC;AAClC,6BAAyB;AACzB,4BAAwB;AACxB,8BAA0B;AAC1B,+BAA2B;AAC3B,gCAA4B;AAC5B,8BAA0B;AAC1B,+BAA2B;AAC3B,iCAA6B;AAC7B,yCAAqC;AACrC,uCAAmC;AACnC,8BAA0B;AAC1B,6BAAyB;AACzB,+BAA2B;AAC3B,oCAAgC;AAChC,6BAAyB;AACzB,2BAAuB;AACvB,+BAA2B;AAC3B,mCAA+B;AAC/B,8BAA0B;AAC1B,qCAA2B;AAC3B,gCAA4B;AAC5B,2BAAuB;AACvB,4BAAwB;AACxB,8BAA0B;AAC1B,8BAA0B;AAC1B,4BAAwB;AACxB,yBAAqB;AACrB,iCAA6B;AAC7B,+BAA2B;AAC3B,yCAA+B;AAC/B,8BAA0B","sourcesContent":["export * from './array';\nexport * from './auxiliary-files';\nexport * from './base64';\nexport * from './bytes';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './constants';\nexport * from './cronjob';\nexport * from './currency';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './derivation-paths';\nexport * from './entropy';\nexport * from './errors';\nexport * from './handlers';\nexport * from './handler-types';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './localization';\nexport * from './logging';\nexport * from './manifest';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './ui';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\nexport * from './promise';\n"]}
@@ -134,7 +134,7 @@ exports.SnapManifestStruct = (0, superstruct_1.object)({
134
134
  version: utils_1.VersionStruct,
135
135
  description: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, 280),
136
136
  proposedName: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, 214),
137
- repository: (0, superstruct_1.optional)((0, superstruct_1.object)({
137
+ repository: (0, superstruct_1.optional)((0, superstruct_1.type)({
138
138
  type: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
139
139
  url: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
140
140
  })),
@@ -1 +1 @@
1
- {"version":3,"file":"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EAAC;oBACd,IAAA,qBAAO,EAAC,4BAA4B,CAAC;oBACrC,IAAA,qBAAO,EAAC,6BAA6B,CAAC;iBACvC,CAAC;aACH,CAAC;SACH,CAAC;QACF,KAAK,EAAE,IAAA,sBAAQ,EAAC,+BAAuB,CAAC;QACxC,OAAO,EAAE,IAAA,sBAAQ,EAAC,+BAAuB,CAAC;KAC3C,CAAC;IACF,kBAAkB,EAAE,IAAA,sBAAQ,EAAC,gCAAwB,CAAC;IACtD,kBAAkB,EAAE,yBAAiB;IACrC,eAAe,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IAC/B,OAAO,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,oDAAoD;CAClF,CAAC,CAAC;AAIH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,IAAI,wBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AARD,oDAQC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AAC3C,CAAC;AAHD,gDAGC","sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport { isValidBIP32PathSegment } from '@metamask/key-tree';\nimport type { EmptyObject, InitialPermissions } from '@metamask/snaps-sdk';\nimport type { Describe, Infer, Struct } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n create,\n enums,\n integer,\n is,\n literal,\n object,\n optional,\n refine,\n record,\n size,\n string,\n type,\n union,\n intersection,\n} from '@metamask/superstruct';\nimport {\n assertStruct,\n ChecksumStruct,\n VersionStruct,\n isValidSemVerRange,\n inMilliseconds,\n Duration,\n} from '@metamask/utils';\n\nimport { isEqual } from '../array';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { KeyringOriginsStruct, RpcOriginsStruct } from '../json-rpc';\nimport { ChainIdStruct } from '../namespace';\nimport { SnapIdStruct } from '../snaps';\nimport { mergeStructs, type InferMatching } from '../structs';\nimport { NameStruct, NpmSnapFileNames, uri } from '../types';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nexport const FORBIDDEN_COIN_TYPES: number[] = [60];\nconst FORBIDDEN_PATHS: string[][] = FORBIDDEN_COIN_TYPES.map((coinType) => [\n 'm',\n \"44'\",\n `${coinType}'`,\n]);\n\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path: string[]) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !isValidBIP32PathSegment(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n if (\n FORBIDDEN_PATHS.some((forbiddenPath) =>\n isEqual(path.slice(0, forbiddenPath.length), forbiddenPath),\n )\n ) {\n return `The path \"${path.join(\n '/',\n )}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <\n Type extends { path: string[]; curve: string },\n Schema,\n>(\n struct: Struct<Type, Schema>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\nexport const CurveStruct: Describe<SupportedCurve> = enums([\n 'ed25519',\n 'secp256k1',\n 'ed25519Bip32',\n]);\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: CurveStruct,\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\nexport const SemVerRangeStruct = refine(string(), 'SemVer range', (value) => {\n if (isValidSemVerRange(value)) {\n return true;\n }\n return 'Expected a valid SemVer range.';\n});\n\nexport const SnapIdsStruct = refine(\n record(SnapIdStruct, object({ version: optional(SemVerRangeStruct) })),\n 'SnapIds',\n (value) => {\n if (Object.keys(value).length === 0) {\n return false;\n }\n\n return true;\n },\n);\n\nexport type SnapIds = Infer<typeof SnapIdsStruct>;\n\nexport const ChainIdsStruct = size(array(ChainIdStruct), 1, Infinity);\n\nexport const LookupMatchersStruct = union([\n object({\n tlds: size(array(string()), 1, Infinity),\n }),\n object({\n schemes: size(array(string()), 1, Infinity),\n }),\n object({\n tlds: size(array(string()), 1, Infinity),\n schemes: size(array(string()), 1, Infinity),\n }),\n]);\n\nexport const MINIMUM_REQUEST_TIMEOUT = inMilliseconds(5, Duration.Second);\nexport const MAXIMUM_REQUEST_TIMEOUT = inMilliseconds(3, Duration.Minute);\n\nexport const MaxRequestTimeStruct = size(\n integer(),\n MINIMUM_REQUEST_TIMEOUT,\n MAXIMUM_REQUEST_TIMEOUT,\n);\n\n// Utility type to union with for all handler structs\nexport const HandlerCaveatsStruct = object({\n maxRequestTime: optional(MaxRequestTimeStruct),\n});\n\nexport type HandlerCaveats = Infer<typeof HandlerCaveatsStruct>;\n\nexport const EmptyObjectStruct = object<EmptyObject>({}) as unknown as Struct<\n EmptyObject,\n null\n>;\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct: Describe<InitialPermissions> = type({\n 'endowment:cronjob': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n ),\n 'endowment:ethereum-provider': optional(EmptyObjectStruct),\n 'endowment:keyring': optional(\n mergeStructs(HandlerCaveatsStruct, KeyringOriginsStruct),\n ),\n 'endowment:lifecycle-hooks': optional(HandlerCaveatsStruct),\n 'endowment:name-lookup': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n chains: optional(ChainIdsStruct),\n matchers: optional(LookupMatchersStruct),\n }),\n ),\n ),\n 'endowment:network-access': optional(EmptyObjectStruct),\n 'endowment:page-home': optional(HandlerCaveatsStruct),\n 'endowment:rpc': optional(\n mergeStructs(HandlerCaveatsStruct, RpcOriginsStruct),\n ),\n 'endowment:signature-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowSignatureOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:transaction-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:webassembly': optional(EmptyObjectStruct),\n snap_dialog: optional(EmptyObjectStruct),\n snap_manageState: optional(EmptyObjectStruct),\n snap_manageAccounts: optional(EmptyObjectStruct),\n snap_notify: optional(EmptyObjectStruct),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(EmptyObjectStruct),\n snap_getLocale: optional(EmptyObjectStruct),\n wallet_snap: optional(SnapIdsStruct),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = InferMatching<\n typeof PermissionsStruct,\n InitialPermissions\n>;\n\nexport const SnapAuxilaryFilesStruct = array(string());\n\nexport const InitialConnectionsStruct = record(\n intersection([string(), uri()]),\n object({}),\n);\n\nexport type InitialConnections = Infer<typeof InitialConnectionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(string(), 1, 214),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: ChecksumStruct,\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n files: optional(SnapAuxilaryFilesStruct),\n locales: optional(SnapAuxilaryFilesStruct),\n }),\n initialConnections: optional(InitialConnectionsStruct),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n $schema: optional(string()), // enables JSON-Schema linting in VSC and other IDEs\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"]}
1
+ {"version":3,"file":"validation.cjs","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":";;;AACA,iDAA6D;AAG7D,uDAiB+B;AAC/B,2CAOyB;AAEzB,wCAAmC;AACnC,4CAA6D;AAC7D,4CAA6E;AAC7E,8CAAqE;AACrE,gDAA6C;AAC7C,wCAAwC;AACxC,4CAA8D;AAC9D,wCAA6D;AAE7D,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,kBAAkB,GAAa;IACnC,2BAAiB;IACjB,sCAA4B;CAC7B,CAAC;AAEW,QAAA,oBAAoB,GAAa,CAAC,EAAE,CAAC,CAAC;AACnD,MAAM,eAAe,GAAe,4BAAoB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;IACzE,GAAG;IACH,KAAK;IACL,GAAG,QAAQ,GAAG;CACf,CAAC,CAAC;AAEU,QAAA,eAAe,GAAG,IAAA,oBAAM,EACnC,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC,EACf,aAAa,EACb,CAAC,IAAc,EAAE,EAAE;IACjB,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtB,OAAO,uDAAuD,CAAC;IACjE,CAAC;IAED,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE,CAAC;QACpB,OAAO,2BAA2B,CAAC;IACrC,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACpB,OAAO,6CAA6C,CAAC;IACvD,CAAC;IAED,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAA,kCAAuB,EAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QACjE,OAAO,oDAAoD,CAAC;IAC9D,CAAC;IAED,IAAI,kBAAkB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,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,kBAAU;gBACvB,QAAQ,EAAE,IAAA,mBAAK,EAAC;oBACd,IAAA,qBAAO,EAAC,4BAA4B,CAAC;oBACrC,IAAA,qBAAO,EAAC,6BAA6B,CAAC;iBACvC,CAAC;aACH,CAAC;SACH,CAAC;QACF,KAAK,EAAE,IAAA,sBAAQ,EAAC,+BAAuB,CAAC;QACxC,OAAO,EAAE,IAAA,sBAAQ,EAAC,+BAAuB,CAAC;KAC3C,CAAC;IACF,kBAAkB,EAAE,IAAA,sBAAQ,EAAC,gCAAwB,CAAC;IACtD,kBAAkB,EAAE,yBAAiB;IACrC,eAAe,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;IAC/B,OAAO,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC,EAAE,oDAAoD;CAClF,CAAC,CAAC;AAIH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,IAAI,wBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AARD,oDAQC;AAED;;;;;;GAMG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AAC3C,CAAC;AAHD,gDAGC","sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport { isValidBIP32PathSegment } from '@metamask/key-tree';\nimport type { EmptyObject, InitialPermissions } from '@metamask/snaps-sdk';\nimport type { Describe, Infer, Struct } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n create,\n enums,\n integer,\n is,\n literal,\n object,\n optional,\n refine,\n record,\n size,\n string,\n type,\n union,\n intersection,\n} from '@metamask/superstruct';\nimport {\n assertStruct,\n ChecksumStruct,\n VersionStruct,\n isValidSemVerRange,\n inMilliseconds,\n Duration,\n} from '@metamask/utils';\n\nimport { isEqual } from '../array';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { KeyringOriginsStruct, RpcOriginsStruct } from '../json-rpc';\nimport { ChainIdStruct } from '../namespace';\nimport { SnapIdStruct } from '../snaps';\nimport { mergeStructs, type InferMatching } from '../structs';\nimport { NameStruct, NpmSnapFileNames, uri } from '../types';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nexport const FORBIDDEN_COIN_TYPES: number[] = [60];\nconst FORBIDDEN_PATHS: string[][] = FORBIDDEN_COIN_TYPES.map((coinType) => [\n 'm',\n \"44'\",\n `${coinType}'`,\n]);\n\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path: string[]) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !isValidBIP32PathSegment(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n if (\n FORBIDDEN_PATHS.some((forbiddenPath) =>\n isEqual(path.slice(0, forbiddenPath.length), forbiddenPath),\n )\n ) {\n return `The path \"${path.join(\n '/',\n )}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <\n Type extends { path: string[]; curve: string },\n Schema,\n>(\n struct: Struct<Type, Schema>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\nexport const CurveStruct: Describe<SupportedCurve> = enums([\n 'ed25519',\n 'secp256k1',\n 'ed25519Bip32',\n]);\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: CurveStruct,\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\nexport const SemVerRangeStruct = refine(string(), 'SemVer range', (value) => {\n if (isValidSemVerRange(value)) {\n return true;\n }\n return 'Expected a valid SemVer range.';\n});\n\nexport const SnapIdsStruct = refine(\n record(SnapIdStruct, object({ version: optional(SemVerRangeStruct) })),\n 'SnapIds',\n (value) => {\n if (Object.keys(value).length === 0) {\n return false;\n }\n\n return true;\n },\n);\n\nexport type SnapIds = Infer<typeof SnapIdsStruct>;\n\nexport const ChainIdsStruct = size(array(ChainIdStruct), 1, Infinity);\n\nexport const LookupMatchersStruct = union([\n object({\n tlds: size(array(string()), 1, Infinity),\n }),\n object({\n schemes: size(array(string()), 1, Infinity),\n }),\n object({\n tlds: size(array(string()), 1, Infinity),\n schemes: size(array(string()), 1, Infinity),\n }),\n]);\n\nexport const MINIMUM_REQUEST_TIMEOUT = inMilliseconds(5, Duration.Second);\nexport const MAXIMUM_REQUEST_TIMEOUT = inMilliseconds(3, Duration.Minute);\n\nexport const MaxRequestTimeStruct = size(\n integer(),\n MINIMUM_REQUEST_TIMEOUT,\n MAXIMUM_REQUEST_TIMEOUT,\n);\n\n// Utility type to union with for all handler structs\nexport const HandlerCaveatsStruct = object({\n maxRequestTime: optional(MaxRequestTimeStruct),\n});\n\nexport type HandlerCaveats = Infer<typeof HandlerCaveatsStruct>;\n\nexport const EmptyObjectStruct = object<EmptyObject>({}) as unknown as Struct<\n EmptyObject,\n null\n>;\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct: Describe<InitialPermissions> = type({\n 'endowment:cronjob': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n ),\n 'endowment:ethereum-provider': optional(EmptyObjectStruct),\n 'endowment:keyring': optional(\n mergeStructs(HandlerCaveatsStruct, KeyringOriginsStruct),\n ),\n 'endowment:lifecycle-hooks': optional(HandlerCaveatsStruct),\n 'endowment:name-lookup': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n chains: optional(ChainIdsStruct),\n matchers: optional(LookupMatchersStruct),\n }),\n ),\n ),\n 'endowment:network-access': optional(EmptyObjectStruct),\n 'endowment:page-home': optional(HandlerCaveatsStruct),\n 'endowment:rpc': optional(\n mergeStructs(HandlerCaveatsStruct, RpcOriginsStruct),\n ),\n 'endowment:signature-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowSignatureOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:transaction-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:webassembly': optional(EmptyObjectStruct),\n snap_dialog: optional(EmptyObjectStruct),\n snap_manageState: optional(EmptyObjectStruct),\n snap_manageAccounts: optional(EmptyObjectStruct),\n snap_notify: optional(EmptyObjectStruct),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(EmptyObjectStruct),\n snap_getLocale: optional(EmptyObjectStruct),\n wallet_snap: optional(SnapIdsStruct),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = InferMatching<\n typeof PermissionsStruct,\n InitialPermissions\n>;\n\nexport const SnapAuxilaryFilesStruct = array(string());\n\nexport const InitialConnectionsStruct = record(\n intersection([string(), uri()]),\n object({}),\n);\n\nexport type InitialConnections = Infer<typeof InitialConnectionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(string(), 1, 214),\n repository: optional(\n type({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: ChecksumStruct,\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n files: optional(SnapAuxilaryFilesStruct),\n locales: optional(SnapAuxilaryFilesStruct),\n }),\n initialConnections: optional(InitialConnectionsStruct),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n $schema: optional(string()), // enables JSON-Schema linting in VSC and other IDEs\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"]}
@@ -130,7 +130,7 @@ export const SnapManifestStruct = object({
130
130
  version: VersionStruct,
131
131
  description: size(string(), 1, 280),
132
132
  proposedName: size(string(), 1, 214),
133
- repository: optional(object({
133
+ repository: optional(type({
134
134
  type: size(string(), 1, Infinity),
135
135
  url: size(string(), 1, Infinity),
136
136
  })),
@@ -1 +1 @@
1
- {"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,2BAA2B;AAG7D,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,KAAK,EACL,OAAO,EACP,EAAE,EACF,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,YAAY,EACb,8BAA8B;AAC/B,OAAO,EACL,YAAY,EACZ,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACT,wBAAwB;AAEzB,OAAO,EAAE,OAAO,EAAE,qBAAiB;AACnC,OAAO,EAAE,+BAA+B,EAAE,uBAAmB;AAC7D,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,uBAAmB;AAC7E,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,wBAAoB;AACrE,OAAO,EAAE,aAAa,EAAE,yBAAqB;AAC7C,OAAO,EAAE,YAAY,EAAE,qBAAiB;AACxC,OAAO,EAAE,YAAY,EAAsB,uBAAmB;AAC9D,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,EAAE,qBAAiB;AAE7D,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,kBAAkB,GAAa;IACnC,iBAAiB;IACjB,4BAA4B;CAC7B,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAa,CAAC,EAAE,CAAC,CAAC;AACn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QAAQ,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC;gBACrC,QAAQ,EAAE,QAAQ,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;gBAC/C,WAAW,EAAE,UAAU;gBACvB,QAAQ,EAAE,KAAK,CAAC;oBACd,OAAO,CAAC,4BAA4B,CAAC;oBACrC,OAAO,CAAC,6BAA6B,CAAC;iBACvC,CAAC;aACH,CAAC;SACH,CAAC;QACF,KAAK,EAAE,QAAQ,CAAC,uBAAuB,CAAC;QACxC,OAAO,EAAE,QAAQ,CAAC,uBAAuB,CAAC;KAC3C,CAAC;IACF,kBAAkB,EAAE,QAAQ,CAAC,wBAAwB,CAAC;IACtD,kBAAkB,EAAE,iBAAiB;IACrC,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC;IAC/B,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,oDAAoD;CAClF,CAAC,CAAC;AAIH;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc;IAEd,YAAY,CACV,KAAK,EACL,kBAAkB,EAClB,IAAI,gBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,MAAM,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport { isValidBIP32PathSegment } from '@metamask/key-tree';\nimport type { EmptyObject, InitialPermissions } from '@metamask/snaps-sdk';\nimport type { Describe, Infer, Struct } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n create,\n enums,\n integer,\n is,\n literal,\n object,\n optional,\n refine,\n record,\n size,\n string,\n type,\n union,\n intersection,\n} from '@metamask/superstruct';\nimport {\n assertStruct,\n ChecksumStruct,\n VersionStruct,\n isValidSemVerRange,\n inMilliseconds,\n Duration,\n} from '@metamask/utils';\n\nimport { isEqual } from '../array';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { KeyringOriginsStruct, RpcOriginsStruct } from '../json-rpc';\nimport { ChainIdStruct } from '../namespace';\nimport { SnapIdStruct } from '../snaps';\nimport { mergeStructs, type InferMatching } from '../structs';\nimport { NameStruct, NpmSnapFileNames, uri } from '../types';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nexport const FORBIDDEN_COIN_TYPES: number[] = [60];\nconst FORBIDDEN_PATHS: string[][] = FORBIDDEN_COIN_TYPES.map((coinType) => [\n 'm',\n \"44'\",\n `${coinType}'`,\n]);\n\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path: string[]) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !isValidBIP32PathSegment(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n if (\n FORBIDDEN_PATHS.some((forbiddenPath) =>\n isEqual(path.slice(0, forbiddenPath.length), forbiddenPath),\n )\n ) {\n return `The path \"${path.join(\n '/',\n )}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <\n Type extends { path: string[]; curve: string },\n Schema,\n>(\n struct: Struct<Type, Schema>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\nexport const CurveStruct: Describe<SupportedCurve> = enums([\n 'ed25519',\n 'secp256k1',\n 'ed25519Bip32',\n]);\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: CurveStruct,\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\nexport const SemVerRangeStruct = refine(string(), 'SemVer range', (value) => {\n if (isValidSemVerRange(value)) {\n return true;\n }\n return 'Expected a valid SemVer range.';\n});\n\nexport const SnapIdsStruct = refine(\n record(SnapIdStruct, object({ version: optional(SemVerRangeStruct) })),\n 'SnapIds',\n (value) => {\n if (Object.keys(value).length === 0) {\n return false;\n }\n\n return true;\n },\n);\n\nexport type SnapIds = Infer<typeof SnapIdsStruct>;\n\nexport const ChainIdsStruct = size(array(ChainIdStruct), 1, Infinity);\n\nexport const LookupMatchersStruct = union([\n object({\n tlds: size(array(string()), 1, Infinity),\n }),\n object({\n schemes: size(array(string()), 1, Infinity),\n }),\n object({\n tlds: size(array(string()), 1, Infinity),\n schemes: size(array(string()), 1, Infinity),\n }),\n]);\n\nexport const MINIMUM_REQUEST_TIMEOUT = inMilliseconds(5, Duration.Second);\nexport const MAXIMUM_REQUEST_TIMEOUT = inMilliseconds(3, Duration.Minute);\n\nexport const MaxRequestTimeStruct = size(\n integer(),\n MINIMUM_REQUEST_TIMEOUT,\n MAXIMUM_REQUEST_TIMEOUT,\n);\n\n// Utility type to union with for all handler structs\nexport const HandlerCaveatsStruct = object({\n maxRequestTime: optional(MaxRequestTimeStruct),\n});\n\nexport type HandlerCaveats = Infer<typeof HandlerCaveatsStruct>;\n\nexport const EmptyObjectStruct = object<EmptyObject>({}) as unknown as Struct<\n EmptyObject,\n null\n>;\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct: Describe<InitialPermissions> = type({\n 'endowment:cronjob': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n ),\n 'endowment:ethereum-provider': optional(EmptyObjectStruct),\n 'endowment:keyring': optional(\n mergeStructs(HandlerCaveatsStruct, KeyringOriginsStruct),\n ),\n 'endowment:lifecycle-hooks': optional(HandlerCaveatsStruct),\n 'endowment:name-lookup': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n chains: optional(ChainIdsStruct),\n matchers: optional(LookupMatchersStruct),\n }),\n ),\n ),\n 'endowment:network-access': optional(EmptyObjectStruct),\n 'endowment:page-home': optional(HandlerCaveatsStruct),\n 'endowment:rpc': optional(\n mergeStructs(HandlerCaveatsStruct, RpcOriginsStruct),\n ),\n 'endowment:signature-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowSignatureOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:transaction-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:webassembly': optional(EmptyObjectStruct),\n snap_dialog: optional(EmptyObjectStruct),\n snap_manageState: optional(EmptyObjectStruct),\n snap_manageAccounts: optional(EmptyObjectStruct),\n snap_notify: optional(EmptyObjectStruct),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(EmptyObjectStruct),\n snap_getLocale: optional(EmptyObjectStruct),\n wallet_snap: optional(SnapIdsStruct),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = InferMatching<\n typeof PermissionsStruct,\n InitialPermissions\n>;\n\nexport const SnapAuxilaryFilesStruct = array(string());\n\nexport const InitialConnectionsStruct = record(\n intersection([string(), uri()]),\n object({}),\n);\n\nexport type InitialConnections = Infer<typeof InitialConnectionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(string(), 1, 214),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: ChecksumStruct,\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n files: optional(SnapAuxilaryFilesStruct),\n locales: optional(SnapAuxilaryFilesStruct),\n }),\n initialConnections: optional(InitialConnectionsStruct),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n $schema: optional(string()), // enables JSON-Schema linting in VSC and other IDEs\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"]}
1
+ {"version":3,"file":"validation.mjs","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,2BAA2B;AAG7D,OAAO,EACL,KAAK,EACL,OAAO,EACP,MAAM,EACN,KAAK,EACL,OAAO,EACP,EAAE,EACF,OAAO,EACP,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,IAAI,EACJ,MAAM,EACN,IAAI,EACJ,KAAK,EACL,YAAY,EACb,8BAA8B;AAC/B,OAAO,EACL,YAAY,EACZ,cAAc,EACd,aAAa,EACb,kBAAkB,EAClB,cAAc,EACd,QAAQ,EACT,wBAAwB;AAEzB,OAAO,EAAE,OAAO,EAAE,qBAAiB;AACnC,OAAO,EAAE,+BAA+B,EAAE,uBAAmB;AAC7D,OAAO,EAAE,iBAAiB,EAAE,4BAA4B,EAAE,uBAAmB;AAC7E,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,wBAAoB;AACrE,OAAO,EAAE,aAAa,EAAE,yBAAqB;AAC7C,OAAO,EAAE,YAAY,EAAE,qBAAiB;AACxC,OAAO,EAAE,YAAY,EAAsB,uBAAmB;AAC9D,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,GAAG,EAAE,qBAAiB;AAE7D,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,kBAAkB,GAAa;IACnC,iBAAiB;IACjB,4BAA4B;CAC7B,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAa,CAAC,EAAE,CAAC,CAAC;AACnD,MAAM,eAAe,GAAe,oBAAoB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;IACzE,GAAG;IACH,KAAK;IACL,GAAG,QAAQ,GAAG;CACf,CAAC,C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,EAAE,QAAQ,CAAC,CAAC;gBAC/C,WAAW,EAAE,UAAU;gBACvB,QAAQ,EAAE,KAAK,CAAC;oBACd,OAAO,CAAC,4BAA4B,CAAC;oBACrC,OAAO,CAAC,6BAA6B,CAAC;iBACvC,CAAC;aACH,CAAC;SACH,CAAC;QACF,KAAK,EAAE,QAAQ,CAAC,uBAAuB,CAAC;QACxC,OAAO,EAAE,QAAQ,CAAC,uBAAuB,CAAC;KAC3C,CAAC;IACF,kBAAkB,EAAE,QAAQ,CAAC,wBAAwB,CAAC;IACtD,kBAAkB,EAAE,iBAAiB;IACrC,eAAe,EAAE,OAAO,CAAC,KAAK,CAAC;IAC/B,OAAO,EAAE,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,oDAAoD;CAClF,CAAC,CAAC;AAIH;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc;IAEd,YAAY,CACV,KAAK,EACL,kBAAkB,EAClB,IAAI,gBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,MAAM,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;AAC3C,CAAC","sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport { isValidBIP32PathSegment } from '@metamask/key-tree';\nimport type { EmptyObject, InitialPermissions } from '@metamask/snaps-sdk';\nimport type { Describe, Infer, Struct } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n create,\n enums,\n integer,\n is,\n literal,\n object,\n optional,\n refine,\n record,\n size,\n string,\n type,\n union,\n intersection,\n} from '@metamask/superstruct';\nimport {\n assertStruct,\n ChecksumStruct,\n VersionStruct,\n isValidSemVerRange,\n inMilliseconds,\n Duration,\n} from '@metamask/utils';\n\nimport { isEqual } from '../array';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { KeyringOriginsStruct, RpcOriginsStruct } from '../json-rpc';\nimport { ChainIdStruct } from '../namespace';\nimport { SnapIdStruct } from '../snaps';\nimport { mergeStructs, type InferMatching } from '../structs';\nimport { NameStruct, NpmSnapFileNames, uri } from '../types';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nexport const FORBIDDEN_COIN_TYPES: number[] = [60];\nconst FORBIDDEN_PATHS: string[][] = FORBIDDEN_COIN_TYPES.map((coinType) => [\n 'm',\n \"44'\",\n `${coinType}'`,\n]);\n\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path: string[]) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !isValidBIP32PathSegment(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n if (\n FORBIDDEN_PATHS.some((forbiddenPath) =>\n isEqual(path.slice(0, forbiddenPath.length), forbiddenPath),\n )\n ) {\n return `The path \"${path.join(\n '/',\n )}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <\n Type extends { path: string[]; curve: string },\n Schema,\n>(\n struct: Struct<Type, Schema>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\nexport const CurveStruct: Describe<SupportedCurve> = enums([\n 'ed25519',\n 'secp256k1',\n 'ed25519Bip32',\n]);\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: CurveStruct,\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\nexport const SemVerRangeStruct = refine(string(), 'SemVer range', (value) => {\n if (isValidSemVerRange(value)) {\n return true;\n }\n return 'Expected a valid SemVer range.';\n});\n\nexport const SnapIdsStruct = refine(\n record(SnapIdStruct, object({ version: optional(SemVerRangeStruct) })),\n 'SnapIds',\n (value) => {\n if (Object.keys(value).length === 0) {\n return false;\n }\n\n return true;\n },\n);\n\nexport type SnapIds = Infer<typeof SnapIdsStruct>;\n\nexport const ChainIdsStruct = size(array(ChainIdStruct), 1, Infinity);\n\nexport const LookupMatchersStruct = union([\n object({\n tlds: size(array(string()), 1, Infinity),\n }),\n object({\n schemes: size(array(string()), 1, Infinity),\n }),\n object({\n tlds: size(array(string()), 1, Infinity),\n schemes: size(array(string()), 1, Infinity),\n }),\n]);\n\nexport const MINIMUM_REQUEST_TIMEOUT = inMilliseconds(5, Duration.Second);\nexport const MAXIMUM_REQUEST_TIMEOUT = inMilliseconds(3, Duration.Minute);\n\nexport const MaxRequestTimeStruct = size(\n integer(),\n MINIMUM_REQUEST_TIMEOUT,\n MAXIMUM_REQUEST_TIMEOUT,\n);\n\n// Utility type to union with for all handler structs\nexport const HandlerCaveatsStruct = object({\n maxRequestTime: optional(MaxRequestTimeStruct),\n});\n\nexport type HandlerCaveats = Infer<typeof HandlerCaveatsStruct>;\n\nexport const EmptyObjectStruct = object<EmptyObject>({}) as unknown as Struct<\n EmptyObject,\n null\n>;\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct: Describe<InitialPermissions> = type({\n 'endowment:cronjob': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n ),\n 'endowment:ethereum-provider': optional(EmptyObjectStruct),\n 'endowment:keyring': optional(\n mergeStructs(HandlerCaveatsStruct, KeyringOriginsStruct),\n ),\n 'endowment:lifecycle-hooks': optional(HandlerCaveatsStruct),\n 'endowment:name-lookup': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n chains: optional(ChainIdsStruct),\n matchers: optional(LookupMatchersStruct),\n }),\n ),\n ),\n 'endowment:network-access': optional(EmptyObjectStruct),\n 'endowment:page-home': optional(HandlerCaveatsStruct),\n 'endowment:rpc': optional(\n mergeStructs(HandlerCaveatsStruct, RpcOriginsStruct),\n ),\n 'endowment:signature-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowSignatureOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:transaction-insight': optional(\n mergeStructs(\n HandlerCaveatsStruct,\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n ),\n 'endowment:webassembly': optional(EmptyObjectStruct),\n snap_dialog: optional(EmptyObjectStruct),\n snap_manageState: optional(EmptyObjectStruct),\n snap_manageAccounts: optional(EmptyObjectStruct),\n snap_notify: optional(EmptyObjectStruct),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(EmptyObjectStruct),\n snap_getLocale: optional(EmptyObjectStruct),\n wallet_snap: optional(SnapIdsStruct),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = InferMatching<\n typeof PermissionsStruct,\n InitialPermissions\n>;\n\nexport const SnapAuxilaryFilesStruct = array(string());\n\nexport const InitialConnectionsStruct = record(\n intersection([string(), uri()]),\n object({}),\n);\n\nexport type InitialConnections = Infer<typeof InitialConnectionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(string(), 1, 214),\n repository: optional(\n type({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: ChecksumStruct,\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n files: optional(SnapAuxilaryFilesStruct),\n locales: optional(SnapAuxilaryFilesStruct),\n }),\n initialConnections: optional(InitialConnectionsStruct),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n $schema: optional(string()), // enables JSON-Schema linting in VSC and other IDEs\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"]}
@@ -22,28 +22,43 @@ 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
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
31
+ if (kind === "m") throw new TypeError("Private method is not writable");
32
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
33
+ 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
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
35
+ };
36
+ var _Context_nextSeverity;
25
37
  Object.defineProperty(exports, "__esModule", { value: true });
26
38
  exports.hasFixes = exports.runValidators = void 0;
27
39
  const utils_1 = require("@metamask/utils");
28
40
  const defaultValidators = __importStar(require("./validators/index.cjs"));
29
41
  class Context {
30
- reports = [];
31
- #nextSeverity = undefined;
42
+ constructor() {
43
+ this.reports = [];
44
+ _Context_nextSeverity.set(this, undefined);
45
+ }
32
46
  report(message, fix) {
33
- (0, utils_1.assert)(this.#nextSeverity !== undefined);
47
+ (0, utils_1.assert)(__classPrivateFieldGet(this, _Context_nextSeverity, "f") !== undefined);
34
48
  this.reports.push({
35
- severity: this.#nextSeverity,
49
+ severity: __classPrivateFieldGet(this, _Context_nextSeverity, "f"),
36
50
  message,
37
51
  fix,
38
52
  });
39
53
  }
40
54
  prepareForValidator(settings) {
41
- this.#nextSeverity = settings.severity;
55
+ __classPrivateFieldSet(this, _Context_nextSeverity, settings.severity, "f");
42
56
  }
43
57
  get hasErrors() {
44
58
  return this.reports.some((report) => report.severity === 'error');
45
59
  }
46
60
  }
61
+ _Context_nextSeverity = new WeakMap();
47
62
  /**
48
63
  * Verify that snap files are completely valid.
49
64
  * First it runs validators on unparsed files to check structure.
@@ -1 +1 @@
1
- {"version":3,"file":"validator.cjs","sourceRoot":"","sources":["../../src/manifest/validator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAyC;AAUzC,0EAAkD;AAOlD,MAAM,OAAO;IACX,OAAO,GAAsB,EAAE,CAAC;IAEhC,aAAa,GAAuB,SAAS,CAAC;IAE9C,MAAM,CAAC,OAAe,EAAE,GAAkB;QACxC,IAAA,cAAM,EAAC,IAAI,CAAC,aAAa,KAAK,SAAS,CAAC,CAAC;QACzC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,QAAQ,EAAE,IAAI,CAAC,aAAa;YAC5B,OAAO;YACP,GAAG;SACJ,CAAC,CAAC;IACL,CAAC;IAED,mBAAmB,CAAC,QAAyC;QAC3D,IAAI,CAAC,aAAa,GAAG,QAAQ,CAAC,QAAQ,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 { SnapFiles, UnvalidatedSnapFiles } from '../types';\nimport type {\n ValidatorContext,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\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;AAOlD,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,OAA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alidatedSnapFiles } from '../types';\nimport type {\n ValidatorContext,\n ValidatorFix,\n ValidatorMeta,\n ValidatorReport,\n ValidatorSeverity,\n} from './validator-types';\nimport * as defaultValidators from './validators';\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"]}