@metamask/snaps-utils 9.2.2 → 9.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/CHANGELOG.md +22 -1
  2. package/dist/account.cjs +53 -0
  3. package/dist/account.cjs.map +1 -1
  4. package/dist/account.d.cts +26 -1
  5. package/dist/account.d.cts.map +1 -1
  6. package/dist/account.d.mts +26 -1
  7. package/dist/account.d.mts.map +1 -1
  8. package/dist/account.mjs +49 -1
  9. package/dist/account.mjs.map +1 -1
  10. package/dist/eval-worker.cjs +38 -11
  11. package/dist/eval-worker.cjs.map +1 -1
  12. package/dist/eval-worker.d.cts.map +1 -1
  13. package/dist/eval-worker.d.mts.map +1 -1
  14. package/dist/eval-worker.mjs +38 -11
  15. package/dist/eval-worker.mjs.map +1 -1
  16. package/dist/eval.cjs +6 -0
  17. package/dist/eval.cjs.map +1 -1
  18. package/dist/eval.d.cts +7 -0
  19. package/dist/eval.d.cts.map +1 -1
  20. package/dist/eval.d.mts +7 -0
  21. package/dist/eval.d.mts.map +1 -1
  22. package/dist/eval.mjs +6 -0
  23. package/dist/eval.mjs.map +1 -1
  24. package/dist/fs.cjs +51 -6
  25. package/dist/fs.cjs.map +1 -1
  26. package/dist/fs.d.cts +16 -4
  27. package/dist/fs.d.cts.map +1 -1
  28. package/dist/fs.d.mts +16 -4
  29. package/dist/fs.d.mts.map +1 -1
  30. package/dist/fs.mjs +49 -5
  31. package/dist/fs.mjs.map +1 -1
  32. package/dist/handlers/exports.cjs +7 -0
  33. package/dist/handlers/exports.cjs.map +1 -1
  34. package/dist/handlers/exports.d.cts +6 -1
  35. package/dist/handlers/exports.d.cts.map +1 -1
  36. package/dist/handlers/exports.d.mts +6 -1
  37. package/dist/handlers/exports.d.mts.map +1 -1
  38. package/dist/handlers/exports.mjs +7 -0
  39. package/dist/handlers/exports.mjs.map +1 -1
  40. package/dist/handlers/home-page.d.cts +3 -3
  41. package/dist/handlers/home-page.d.mts +3 -3
  42. package/dist/handlers/settings-page.d.cts +1 -1
  43. package/dist/handlers/settings-page.d.mts +1 -1
  44. package/dist/handlers/signature.d.cts +1 -1
  45. package/dist/handlers/signature.d.mts +1 -1
  46. package/dist/handlers/transaction.d.cts +3 -3
  47. package/dist/handlers/transaction.d.mts +3 -3
  48. package/dist/handlers/types.cjs +1 -0
  49. package/dist/handlers/types.cjs.map +1 -1
  50. package/dist/handlers/types.d.cts +2 -1
  51. package/dist/handlers/types.d.cts.map +1 -1
  52. package/dist/handlers/types.d.mts +2 -1
  53. package/dist/handlers/types.d.mts.map +1 -1
  54. package/dist/handlers/types.mjs +1 -0
  55. package/dist/handlers/types.mjs.map +1 -1
  56. package/dist/index.cjs +1 -0
  57. package/dist/index.cjs.map +1 -1
  58. package/dist/index.d.cts +1 -1
  59. package/dist/index.d.cts.map +1 -1
  60. package/dist/index.d.mts +1 -1
  61. package/dist/index.d.mts.map +1 -1
  62. package/dist/index.mjs +1 -0
  63. package/dist/index.mjs.map +1 -1
  64. package/dist/manifest/manifest.cjs +36 -4
  65. package/dist/manifest/manifest.cjs.map +1 -1
  66. package/dist/manifest/manifest.d.cts +40 -7
  67. package/dist/manifest/manifest.d.cts.map +1 -1
  68. package/dist/manifest/manifest.d.mts +40 -7
  69. package/dist/manifest/manifest.d.mts.map +1 -1
  70. package/dist/manifest/manifest.mjs +13 -4
  71. package/dist/manifest/manifest.mjs.map +1 -1
  72. package/dist/manifest/validator-types.cjs.map +1 -1
  73. package/dist/manifest/validator-types.d.cts +18 -1
  74. package/dist/manifest/validator-types.d.cts.map +1 -1
  75. package/dist/manifest/validator-types.d.mts +18 -1
  76. package/dist/manifest/validator-types.d.mts.map +1 -1
  77. package/dist/manifest/validator-types.mjs.map +1 -1
  78. package/dist/manifest/validator.cjs +23 -10
  79. package/dist/manifest/validator.cjs.map +1 -1
  80. package/dist/manifest/validator.d.cts +4 -2
  81. package/dist/manifest/validator.d.cts.map +1 -1
  82. package/dist/manifest/validator.d.mts +4 -2
  83. package/dist/manifest/validator.d.mts.map +1 -1
  84. package/dist/manifest/validator.mjs +23 -10
  85. package/dist/manifest/validator.mjs.map +1 -1
  86. package/dist/manifest/validators/index.cjs +2 -0
  87. package/dist/manifest/validators/index.cjs.map +1 -1
  88. package/dist/manifest/validators/index.d.cts +2 -0
  89. package/dist/manifest/validators/index.d.cts.map +1 -1
  90. package/dist/manifest/validators/index.d.mts +2 -0
  91. package/dist/manifest/validators/index.d.mts.map +1 -1
  92. package/dist/manifest/validators/index.mjs +2 -0
  93. package/dist/manifest/validators/index.mjs.map +1 -1
  94. package/dist/manifest/validators/production-platform-version.cjs +47 -0
  95. package/dist/manifest/validators/production-platform-version.cjs.map +1 -0
  96. package/dist/manifest/validators/production-platform-version.d.cts +7 -0
  97. package/dist/manifest/validators/production-platform-version.d.cts.map +1 -0
  98. package/dist/manifest/validators/production-platform-version.d.mts +7 -0
  99. package/dist/manifest/validators/production-platform-version.d.mts.map +1 -0
  100. package/dist/manifest/validators/production-platform-version.mjs +44 -0
  101. package/dist/manifest/validators/production-platform-version.mjs.map +1 -0
  102. package/dist/manifest/validators/unused-exports.cjs +53 -0
  103. package/dist/manifest/validators/unused-exports.cjs.map +1 -0
  104. package/dist/manifest/validators/unused-exports.d.cts +7 -0
  105. package/dist/manifest/validators/unused-exports.d.cts.map +1 -0
  106. package/dist/manifest/validators/unused-exports.d.mts +7 -0
  107. package/dist/manifest/validators/unused-exports.d.mts.map +1 -0
  108. package/dist/manifest/validators/unused-exports.mjs +50 -0
  109. package/dist/manifest/validators/unused-exports.mjs.map +1 -0
  110. package/dist/time.cjs +15 -1
  111. package/dist/time.cjs.map +1 -1
  112. package/dist/time.d.cts +7 -0
  113. package/dist/time.d.cts.map +1 -1
  114. package/dist/time.d.mts +7 -0
  115. package/dist/time.d.mts.map +1 -1
  116. package/dist/time.mjs +13 -0
  117. package/dist/time.mjs.map +1 -1
  118. package/package.json +4 -3
@@ -0,0 +1,7 @@
1
+ import type { ValidatorMeta } from "../validator-types.mjs";
2
+ /**
3
+ * Check if the platform version in manifest exceeds the version
4
+ * used in production.
5
+ */
6
+ export declare const productionPlatformVersion: ValidatorMeta;
7
+ //# sourceMappingURL=production-platform-version.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production-platform-version.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/production-platform-version.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAqCxD;;;GAGG;AACH,eAAO,MAAM,yBAAyB,EAAE,aAqBvC,CAAC"}
@@ -0,0 +1,44 @@
1
+ import { Duration, inMilliseconds } from "@metamask/utils";
2
+ import { minVersion, gt } from "semver";
3
+ import { useFileSystemCache } from "../../fs.mjs";
4
+ /**
5
+ * Determine the production version of the Snaps platform by inspecting
6
+ * the latest GitHub release of the MetaMask extension.
7
+ *
8
+ * @returns The production version of the Snaps platform or null if any error occurred.
9
+ */
10
+ const determineProductionVersion = useFileSystemCache('snaps-production-version', inMilliseconds(3, Duration.Day), async () => {
11
+ try {
12
+ const latestRelease = await fetch('https://api.github.com/repos/metamask/metamask-extension/releases/latest');
13
+ const latestReleaseJson = await latestRelease.json();
14
+ const latestReleaseCommit = latestReleaseJson.target_commitish;
15
+ const packageJsonResponse = await fetch(`https://api.github.com/repos/metamask/metamask-extension/contents/package.json?ref=${latestReleaseCommit}`, { headers: new Headers({ accept: 'application/vnd.github.raw+json' }) });
16
+ const packageJson = await packageJsonResponse.json();
17
+ const versionRange = packageJson.dependencies['@metamask/snaps-sdk'];
18
+ return minVersion(versionRange)?.format();
19
+ }
20
+ catch {
21
+ return null;
22
+ }
23
+ });
24
+ /**
25
+ * Check if the platform version in manifest exceeds the version
26
+ * used in production.
27
+ */
28
+ export const productionPlatformVersion = {
29
+ severity: 'warning',
30
+ async semanticCheck(files, context) {
31
+ const manifestPlatformVersion = files.manifest.result.platformVersion;
32
+ if (!manifestPlatformVersion) {
33
+ return;
34
+ }
35
+ const maximumVersion = await determineProductionVersion();
36
+ if (!maximumVersion) {
37
+ return;
38
+ }
39
+ if (gt(manifestPlatformVersion, maximumVersion)) {
40
+ context.report(`The specified platform version "${manifestPlatformVersion}" is not supported in the production version of MetaMask. The current maximum supported version is "${maximumVersion}". To resolve this, downgrade \`@metamask/snaps-sdk\` to a compatible version.`);
41
+ }
42
+ },
43
+ };
44
+ //# sourceMappingURL=production-platform-version.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"production-platform-version.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/production-platform-version.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,wBAAwB;AAC3D,OAAO,EAAE,UAAU,EAAE,EAAE,EAAE,eAAe;AAExC,OAAO,EAAE,kBAAkB,EAAE,qBAAiB;AAG9C;;;;;GAKG;AACH,MAAM,0BAA0B,GAAG,kBAAkB,CACnD,0BAA0B,EAC1B,cAAc,CAAC,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,EAC/B,KAAK,IAAI,EAAE;IACT,IAAI,CAAC;QACH,MAAM,aAAa,GAAG,MAAM,KAAK,CAC/B,0EAA0E,CAC3E,CAAC;QAEF,MAAM,iBAAiB,GAAG,MAAM,aAAa,CAAC,IAAI,EAAE,CAAC;QAErD,MAAM,mBAAmB,GAAG,iBAAiB,CAAC,gBAAgB,CAAC;QAE/D,MAAM,mBAAmB,GAAG,MAAM,KAAK,CACrC,sFAAsF,mBAAmB,EAAE,EAC3G,EAAE,OAAO,EAAE,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,iCAAiC,EAAE,CAAC,EAAE,CACxE,CAAC;QAEF,MAAM,WAAW,GAAG,MAAM,mBAAmB,CAAC,IAAI,EAAE,CAAC;QAErD,MAAM,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC,qBAAqB,CAAC,CAAC;QAErE,OAAO,UAAU,CAAC,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC,CACF,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAkB;IACtD,QAAQ,EAAE,SAAS;IACnB,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,OAAO;QAChC,MAAM,uBAAuB,GAAG,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,eAAe,CAAC;QAEtE,IAAI,CAAC,uBAAuB,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,0BAA0B,EAAE,CAAC;QAE1D,IAAI,CAAC,cAAc,EAAE,CAAC;YACpB,OAAO;QACT,CAAC;QAED,IAAI,EAAE,CAAC,uBAAuB,EAAE,cAAc,CAAC,EAAE,CAAC;YAChD,OAAO,CAAC,MAAM,CACZ,mCAAmC,uBAAuB,uGAAuG,cAAc,gFAAgF,CAChQ,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import { Duration, inMilliseconds } from '@metamask/utils';\nimport { minVersion, gt } from 'semver';\n\nimport { useFileSystemCache } from '../../fs';\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Determine the production version of the Snaps platform by inspecting\n * the latest GitHub release of the MetaMask extension.\n *\n * @returns The production version of the Snaps platform or null if any error occurred.\n */\nconst determineProductionVersion = useFileSystemCache(\n 'snaps-production-version',\n inMilliseconds(3, Duration.Day),\n async () => {\n try {\n const latestRelease = await fetch(\n 'https://api.github.com/repos/metamask/metamask-extension/releases/latest',\n );\n\n const latestReleaseJson = await latestRelease.json();\n\n const latestReleaseCommit = latestReleaseJson.target_commitish;\n\n const packageJsonResponse = await fetch(\n `https://api.github.com/repos/metamask/metamask-extension/contents/package.json?ref=${latestReleaseCommit}`,\n { headers: new Headers({ accept: 'application/vnd.github.raw+json' }) },\n );\n\n const packageJson = await packageJsonResponse.json();\n\n const versionRange = packageJson.dependencies['@metamask/snaps-sdk'];\n\n return minVersion(versionRange)?.format();\n } catch {\n return null;\n }\n },\n);\n\n/**\n * Check if the platform version in manifest exceeds the version\n * used in production.\n */\nexport const productionPlatformVersion: ValidatorMeta = {\n severity: 'warning',\n async semanticCheck(files, context) {\n const manifestPlatformVersion = files.manifest.result.platformVersion;\n\n if (!manifestPlatformVersion) {\n return;\n }\n\n const maximumVersion = await determineProductionVersion();\n\n if (!maximumVersion) {\n return;\n }\n\n if (gt(manifestPlatformVersion, maximumVersion)) {\n context.report(\n `The specified platform version \"${manifestPlatformVersion}\" is not supported in the production version of MetaMask. The current maximum supported version is \"${maximumVersion}\". To resolve this, downgrade \\`@metamask/snaps-sdk\\` to a compatible version.`,\n );\n }\n },\n};\n"]}
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unusedExports = void 0;
4
+ /**
5
+ * Check if the Snap exports handlers that are not requested in the manifest, or
6
+ * if the Snap requests permissions for handlers that are not exported.
7
+ */
8
+ exports.unusedExports = {
9
+ severity: 'warning',
10
+ semanticCheck(files, context) {
11
+ const { handlerEndowments, exports } = context.options ?? {};
12
+ // The handler endowments or exports must be provided for this check to be
13
+ // performed.
14
+ if (!handlerEndowments || !exports) {
15
+ return;
16
+ }
17
+ const unusedHandlers = Object.entries(handlerEndowments)
18
+ .filter(([handler, endowment]) => {
19
+ if (endowment === null) {
20
+ return false;
21
+ }
22
+ return (exports.includes(handler) &&
23
+ !files.manifest.result.initialPermissions[endowment]);
24
+ })
25
+ .map(([handler, endowment]) => `${handler} (${endowment})`);
26
+ const unusedEndowments = Object.entries(handlerEndowments).filter(([handler, endowment]) => {
27
+ if (endowment === null) {
28
+ return false;
29
+ }
30
+ return (files.manifest.result.initialPermissions[endowment] && !exports.includes(handler));
31
+ });
32
+ if (unusedHandlers.length > 0) {
33
+ // We don't specify a fix function here, because:
34
+ // 1. Removing the export from the Snap bundle is complicated, as it
35
+ // requires AST manipulation.
36
+ // 2. Adding the permission to the manifest is not always possible, as it
37
+ // may require additional configuration in the manifest.
38
+ context.report(`The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(', ')}.`);
39
+ }
40
+ if (unusedEndowments.length > 0) {
41
+ const formattedEndowments = unusedEndowments
42
+ .map(([handler, endowment]) => `${handler} (${endowment})`)
43
+ .join(', ');
44
+ context.report(`The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`, ({ manifest }) => {
45
+ unusedEndowments.forEach(([, endowment]) => {
46
+ delete manifest.initialPermissions[endowment];
47
+ });
48
+ return { manifest };
49
+ });
50
+ }
51
+ },
52
+ };
53
+ //# sourceMappingURL=unused-exports.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unused-exports.cjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":";;;AAIA;;;GAGG;AACU,QAAA,aAAa,GAAkB;IAC1C,QAAQ,EAAE,SAAS;IACnB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAE7D,0EAA0E;QAC1E,aAAa;QACb,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;aACrD,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YAC/B,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBACzB,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACvC,SAAqC,CACtC,CACF,CAAC;QACJ,CAAC,CAAC;aACD,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC,CAAC;QAE9D,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAC/D,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YACvB,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACtC,SAAqC,CACtC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAChC,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,iDAAiD;YACjD,oEAAoE;YACpE,gCAAgC;YAChC,yEAAyE;YACzE,2DAA2D;YAC3D,OAAO,CAAC,MAAM,CACZ,sFAAsF,cAAc,CAAC,IAAI,CACvG,IAAI,CACL,GAAG,CACL,CAAC;QACJ,CAAC;QAED,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,mBAAmB,GAAG,gBAAgB;iBACzC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC;iBAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,OAAO,CAAC,MAAM,CACZ,sFAAsF,mBAAmB,GAAG,EAC5G,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE;oBACzC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,SAAqC,CACtC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import type { InitialPermissions } from '@metamask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] && !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
@@ -0,0 +1,7 @@
1
+ import type { ValidatorMeta } from "../validator-types.cjs";
2
+ /**
3
+ * Check if the Snap exports handlers that are not requested in the manifest, or
4
+ * if the Snap requests permissions for handlers that are not exported.
5
+ */
6
+ export declare const unusedExports: ValidatorMeta;
7
+ //# sourceMappingURL=unused-exports.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unused-exports.d.cts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAExD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAwE3B,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { ValidatorMeta } from "../validator-types.mjs";
2
+ /**
3
+ * Check if the Snap exports handlers that are not requested in the manifest, or
4
+ * if the Snap requests permissions for handlers that are not exported.
5
+ */
6
+ export declare const unusedExports: ValidatorMeta;
7
+ //# sourceMappingURL=unused-exports.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unused-exports.d.mts","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,+BAA2B;AAExD;;;GAGG;AACH,eAAO,MAAM,aAAa,EAAE,aAwE3B,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Check if the Snap exports handlers that are not requested in the manifest, or
3
+ * if the Snap requests permissions for handlers that are not exported.
4
+ */
5
+ export const unusedExports = {
6
+ severity: 'warning',
7
+ semanticCheck(files, context) {
8
+ const { handlerEndowments, exports } = context.options ?? {};
9
+ // The handler endowments or exports must be provided for this check to be
10
+ // performed.
11
+ if (!handlerEndowments || !exports) {
12
+ return;
13
+ }
14
+ const unusedHandlers = Object.entries(handlerEndowments)
15
+ .filter(([handler, endowment]) => {
16
+ if (endowment === null) {
17
+ return false;
18
+ }
19
+ return (exports.includes(handler) &&
20
+ !files.manifest.result.initialPermissions[endowment]);
21
+ })
22
+ .map(([handler, endowment]) => `${handler} (${endowment})`);
23
+ const unusedEndowments = Object.entries(handlerEndowments).filter(([handler, endowment]) => {
24
+ if (endowment === null) {
25
+ return false;
26
+ }
27
+ return (files.manifest.result.initialPermissions[endowment] && !exports.includes(handler));
28
+ });
29
+ if (unusedHandlers.length > 0) {
30
+ // We don't specify a fix function here, because:
31
+ // 1. Removing the export from the Snap bundle is complicated, as it
32
+ // requires AST manipulation.
33
+ // 2. Adding the permission to the manifest is not always possible, as it
34
+ // may require additional configuration in the manifest.
35
+ context.report(`The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(', ')}.`);
36
+ }
37
+ if (unusedEndowments.length > 0) {
38
+ const formattedEndowments = unusedEndowments
39
+ .map(([handler, endowment]) => `${handler} (${endowment})`)
40
+ .join(', ');
41
+ context.report(`The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`, ({ manifest }) => {
42
+ unusedEndowments.forEach(([, endowment]) => {
43
+ delete manifest.initialPermissions[endowment];
44
+ });
45
+ return { manifest };
46
+ });
47
+ }
48
+ },
49
+ };
50
+ //# sourceMappingURL=unused-exports.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unused-exports.mjs","sourceRoot":"","sources":["../../../src/manifest/validators/unused-exports.ts"],"names":[],"mappings":"AAIA;;;GAGG;AACH,MAAM,CAAC,MAAM,aAAa,GAAkB;IAC1C,QAAQ,EAAE,SAAS;IACnB,aAAa,CAAC,KAAK,EAAE,OAAO;QAC1B,MAAM,EAAE,iBAAiB,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,IAAI,EAAE,CAAC;QAE7D,0EAA0E;QAC1E,aAAa;QACb,IAAI,CAAC,iBAAiB,IAAI,CAAC,OAAO,EAAE,CAAC;YACnC,OAAO;QACT,CAAC;QAED,MAAM,cAAc,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC;aACrD,MAAM,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YAC/B,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC;gBACzB,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACvC,SAAqC,CACtC,CACF,CAAC;QACJ,CAAC,CAAC;aACD,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC,CAAC;QAE9D,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,MAAM,CAC/D,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE;YACvB,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC;YACf,CAAC;YAED,OAAO,CACL,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,kBAAkB,CACtC,SAAqC,CACtC,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,CAChC,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC9B,iDAAiD;YACjD,oEAAoE;YACpE,gCAAgC;YAChC,yEAAyE;YACzE,2DAA2D;YAC3D,OAAO,CAAC,MAAM,CACZ,sFAAsF,cAAc,CAAC,IAAI,CACvG,IAAI,CACL,GAAG,CACL,CAAC;QACJ,CAAC;QAED,IAAI,gBAAgB,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAChC,MAAM,mBAAmB,GAAG,gBAAgB;iBACzC,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,SAAS,CAAC,EAAE,EAAE,CAAC,GAAG,OAAO,KAAK,SAAS,GAAG,CAAC;iBAC1D,IAAI,CAAC,IAAI,CAAC,CAAC;YAEd,OAAO,CAAC,MAAM,CACZ,sFAAsF,mBAAmB,GAAG,EAC5G,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE;gBACf,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE;oBACzC,OAAO,QAAQ,CAAC,kBAAkB,CAChC,SAAqC,CACtC,CAAC;gBACJ,CAAC,CAAC,CAAC;gBAEH,OAAO,EAAE,QAAQ,EAAE,CAAC;YACtB,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;CACF,CAAC","sourcesContent":["import type { InitialPermissions } from '@metamask/snaps-sdk';\n\nimport type { ValidatorMeta } from '../validator-types';\n\n/**\n * Check if the Snap exports handlers that are not requested in the manifest, or\n * if the Snap requests permissions for handlers that are not exported.\n */\nexport const unusedExports: ValidatorMeta = {\n severity: 'warning',\n semanticCheck(files, context) {\n const { handlerEndowments, exports } = context.options ?? {};\n\n // The handler endowments or exports must be provided for this check to be\n // performed.\n if (!handlerEndowments || !exports) {\n return;\n }\n\n const unusedHandlers = Object.entries(handlerEndowments)\n .filter(([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n exports.includes(handler) &&\n !files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ]\n );\n })\n .map(([handler, endowment]) => `${handler} (${endowment})`);\n\n const unusedEndowments = Object.entries(handlerEndowments).filter(\n ([handler, endowment]) => {\n if (endowment === null) {\n return false;\n }\n\n return (\n files.manifest.result.initialPermissions[\n endowment as keyof InitialPermissions\n ] && !exports.includes(handler)\n );\n },\n );\n\n if (unusedHandlers.length > 0) {\n // We don't specify a fix function here, because:\n // 1. Removing the export from the Snap bundle is complicated, as it\n // requires AST manipulation.\n // 2. Adding the permission to the manifest is not always possible, as it\n // may require additional configuration in the manifest.\n context.report(\n `The Snap exports the following handlers, but does not request permission for them: ${unusedHandlers.join(\n ', ',\n )}.`,\n );\n }\n\n if (unusedEndowments.length > 0) {\n const formattedEndowments = unusedEndowments\n .map(([handler, endowment]) => `${handler} (${endowment})`)\n .join(', ');\n\n context.report(\n `The Snap requests permission for the following handlers, but does not export them: ${formattedEndowments}.`,\n ({ manifest }) => {\n unusedEndowments.forEach(([, endowment]) => {\n delete manifest.initialPermissions[\n endowment as keyof InitialPermissions\n ];\n });\n\n return { manifest };\n },\n );\n }\n },\n};\n"]}
package/dist/time.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ISO8601DateStruct = exports.ISO8601DurationStruct = void 0;
3
+ exports.toCensoredISO8601String = exports.ISO8601DateStruct = exports.ISO8601DurationStruct = void 0;
4
4
  const superstruct_1 = require("@metamask/superstruct");
5
5
  const luxon_1 = require("luxon");
6
6
  /**
@@ -31,4 +31,18 @@ exports.ISO8601DateStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(
31
31
  }
32
32
  return true;
33
33
  });
34
+ /**
35
+ * Remove millisecond precision from an ISO 8601 string.
36
+ *
37
+ * @param value - A valid ISO 8601 date.
38
+ * @returns A valid ISO 8601 date with millisecond precision removed.
39
+ */
40
+ function toCensoredISO8601String(value) {
41
+ const date = luxon_1.DateTime.fromISO(value, { setZone: true });
42
+ // Make sure any millisecond precision is removed.
43
+ return date.startOf('second').toISO({
44
+ suppressMilliseconds: true,
45
+ });
46
+ }
47
+ exports.toCensoredISO8601String = toCensoredISO8601String;
34
48
  //# sourceMappingURL=time.cjs.map
package/dist/time.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"time.cjs","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,iCAA2C;AAE3C;;GAEG;AACU,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EACzC,IAAA,oBAAM,GAAE,EACR,mBAAmB,EACnB,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,cAAc,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CAAC;IACzC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3E,MAAM,UAAU,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE3C,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,2BAA2B,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,+EAA+E;QAC/E,OAAO,8CAA8C,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC","sourcesContent":["import { refine, string } from '@metamask/superstruct';\nimport { DateTime, Duration } from 'luxon';\n\n/**\n * Refines a string as an ISO 8601 duration.\n */\nexport const ISO8601DurationStruct = refine(\n string(),\n 'ISO 8601 duration',\n (value) => {\n const parsedDuration = Duration.fromISO(value);\n if (!parsedDuration.isValid) {\n return 'Not a valid ISO 8601 duration';\n }\n return true;\n },\n);\n\n/**\n * Regex to match the offset part of an ISO 8601 date.\n */\nconst offsetRegex = /Z|([+-]\\d{2}:?\\d{2})$/u;\n\n/**\n * Refines a string as an ISO 8601 date.\n */\nexport const ISO8601DateStruct = refine(string(), 'ISO 8601 date', (value) => {\n const parsedDate = DateTime.fromISO(value);\n\n if (!parsedDate.isValid) {\n return 'Not a valid ISO 8601 date';\n }\n\n if (!offsetRegex.test(value)) {\n // Luxon doesn't have a reliable way to check if timezone info was not provided\n return 'ISO 8601 date must have timezone information';\n }\n\n return true;\n});\n"]}
1
+ {"version":3,"file":"time.cjs","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":";;;AAAA,uDAAuD;AACvD,iCAA2C;AAE3C;;GAEG;AACU,QAAA,qBAAqB,GAAG,IAAA,oBAAM,EACzC,IAAA,oBAAM,GAAE,EACR,mBAAmB,EACnB,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,cAAc,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CAAC;IACzC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;GAEG;AACU,QAAA,iBAAiB,GAAG,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3E,MAAM,UAAU,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE3C,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,2BAA2B,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,+EAA+E;QAC/E,OAAO,8CAA8C,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,SAAgB,uBAAuB,CAAC,KAAa;IACnD,MAAM,IAAI,GAAG,gBAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAExD,kDAAkD;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;QAClC,oBAAoB,EAAE,IAAI;KAC3B,CAAW,CAAC;AACf,CAAC;AAPD,0DAOC","sourcesContent":["import { refine, string } from '@metamask/superstruct';\nimport { DateTime, Duration } from 'luxon';\n\n/**\n * Refines a string as an ISO 8601 duration.\n */\nexport const ISO8601DurationStruct = refine(\n string(),\n 'ISO 8601 duration',\n (value) => {\n const parsedDuration = Duration.fromISO(value);\n if (!parsedDuration.isValid) {\n return 'Not a valid ISO 8601 duration';\n }\n return true;\n },\n);\n\n/**\n * Regex to match the offset part of an ISO 8601 date.\n */\nconst offsetRegex = /Z|([+-]\\d{2}:?\\d{2})$/u;\n\n/**\n * Refines a string as an ISO 8601 date.\n */\nexport const ISO8601DateStruct = refine(string(), 'ISO 8601 date', (value) => {\n const parsedDate = DateTime.fromISO(value);\n\n if (!parsedDate.isValid) {\n return 'Not a valid ISO 8601 date';\n }\n\n if (!offsetRegex.test(value)) {\n // Luxon doesn't have a reliable way to check if timezone info was not provided\n return 'ISO 8601 date must have timezone information';\n }\n\n return true;\n});\n\n/**\n * Remove millisecond precision from an ISO 8601 string.\n *\n * @param value - A valid ISO 8601 date.\n * @returns A valid ISO 8601 date with millisecond precision removed.\n */\nexport function toCensoredISO8601String(value: string) {\n const date = DateTime.fromISO(value, { setZone: true });\n\n // Make sure any millisecond precision is removed.\n return date.startOf('second').toISO({\n suppressMilliseconds: true,\n }) as string;\n}\n"]}
package/dist/time.d.cts CHANGED
@@ -6,4 +6,11 @@ export declare const ISO8601DurationStruct: import("@metamask/superstruct").Stru
6
6
  * Refines a string as an ISO 8601 date.
7
7
  */
8
8
  export declare const ISO8601DateStruct: import("@metamask/superstruct").Struct<string, null>;
9
+ /**
10
+ * Remove millisecond precision from an ISO 8601 string.
11
+ *
12
+ * @param value - A valid ISO 8601 date.
13
+ * @returns A valid ISO 8601 date with millisecond precision removed.
14
+ */
15
+ export declare function toCensoredISO8601String(value: string): string;
9
16
  //# sourceMappingURL=time.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.cts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,qBAAqB,sDAUjC,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,iBAAiB,sDAa5B,CAAC"}
1
+ {"version":3,"file":"time.d.cts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,qBAAqB,sDAUjC,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,iBAAiB,sDAa5B,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,UAOpD"}
package/dist/time.d.mts CHANGED
@@ -6,4 +6,11 @@ export declare const ISO8601DurationStruct: import("@metamask/superstruct").Stru
6
6
  * Refines a string as an ISO 8601 date.
7
7
  */
8
8
  export declare const ISO8601DateStruct: import("@metamask/superstruct").Struct<string, null>;
9
+ /**
10
+ * Remove millisecond precision from an ISO 8601 string.
11
+ *
12
+ * @param value - A valid ISO 8601 date.
13
+ * @returns A valid ISO 8601 date with millisecond precision removed.
14
+ */
15
+ export declare function toCensoredISO8601String(value: string): string;
9
16
  //# sourceMappingURL=time.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.mts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,qBAAqB,sDAUjC,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,iBAAiB,sDAa5B,CAAC"}
1
+ {"version":3,"file":"time.d.mts","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,eAAO,MAAM,qBAAqB,sDAUjC,CAAC;AAOF;;GAEG;AACH,eAAO,MAAM,iBAAiB,sDAa5B,CAAC;AAEH;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,KAAK,EAAE,MAAM,UAOpD"}
package/dist/time.mjs CHANGED
@@ -28,4 +28,17 @@ export const ISO8601DateStruct = refine(string(), 'ISO 8601 date', (value) => {
28
28
  }
29
29
  return true;
30
30
  });
31
+ /**
32
+ * Remove millisecond precision from an ISO 8601 string.
33
+ *
34
+ * @param value - A valid ISO 8601 date.
35
+ * @returns A valid ISO 8601 date with millisecond precision removed.
36
+ */
37
+ export function toCensoredISO8601String(value) {
38
+ const date = DateTime.fromISO(value, { setZone: true });
39
+ // Make sure any millisecond precision is removed.
40
+ return date.startOf('second').toISO({
41
+ suppressMilliseconds: true,
42
+ });
43
+ }
31
44
  //# sourceMappingURL=time.mjs.map
package/dist/time.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"time.mjs","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AACvD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CACzC,MAAM,EAAE,EACR,mBAAmB,EACnB,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CAAC;IACzC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3E,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE3C,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,2BAA2B,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,+EAA+E;QAC/E,OAAO,8CAA8C,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC","sourcesContent":["import { refine, string } from '@metamask/superstruct';\nimport { DateTime, Duration } from 'luxon';\n\n/**\n * Refines a string as an ISO 8601 duration.\n */\nexport const ISO8601DurationStruct = refine(\n string(),\n 'ISO 8601 duration',\n (value) => {\n const parsedDuration = Duration.fromISO(value);\n if (!parsedDuration.isValid) {\n return 'Not a valid ISO 8601 duration';\n }\n return true;\n },\n);\n\n/**\n * Regex to match the offset part of an ISO 8601 date.\n */\nconst offsetRegex = /Z|([+-]\\d{2}:?\\d{2})$/u;\n\n/**\n * Refines a string as an ISO 8601 date.\n */\nexport const ISO8601DateStruct = refine(string(), 'ISO 8601 date', (value) => {\n const parsedDate = DateTime.fromISO(value);\n\n if (!parsedDate.isValid) {\n return 'Not a valid ISO 8601 date';\n }\n\n if (!offsetRegex.test(value)) {\n // Luxon doesn't have a reliable way to check if timezone info was not provided\n return 'ISO 8601 date must have timezone information';\n }\n\n return true;\n});\n"]}
1
+ {"version":3,"file":"time.mjs","sourceRoot":"","sources":["../src/time.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AACvD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,MAAM,CACzC,MAAM,EAAE,EACR,mBAAmB,EACnB,CAAC,KAAK,EAAE,EAAE;IACR,MAAM,cAAc,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC/C,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE,CAAC;QAC5B,OAAO,+BAA+B,CAAC;IACzC,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC,CACF,CAAC;AAEF;;GAEG;AACH,MAAM,WAAW,GAAG,wBAAwB,CAAC;AAE7C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,EAAE,EAAE,eAAe,EAAE,CAAC,KAAK,EAAE,EAAE;IAC3E,MAAM,UAAU,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAE3C,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;QACxB,OAAO,2BAA2B,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;QAC7B,+EAA+E;QAC/E,OAAO,8CAA8C,CAAC;IACxD,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC,CAAC;AAEH;;;;;GAKG;AACH,MAAM,UAAU,uBAAuB,CAAC,KAAa;IACnD,MAAM,IAAI,GAAG,QAAQ,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAExD,kDAAkD;IAClD,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC;QAClC,oBAAoB,EAAE,IAAI;KAC3B,CAAW,CAAC;AACf,CAAC","sourcesContent":["import { refine, string } from '@metamask/superstruct';\nimport { DateTime, Duration } from 'luxon';\n\n/**\n * Refines a string as an ISO 8601 duration.\n */\nexport const ISO8601DurationStruct = refine(\n string(),\n 'ISO 8601 duration',\n (value) => {\n const parsedDuration = Duration.fromISO(value);\n if (!parsedDuration.isValid) {\n return 'Not a valid ISO 8601 duration';\n }\n return true;\n },\n);\n\n/**\n * Regex to match the offset part of an ISO 8601 date.\n */\nconst offsetRegex = /Z|([+-]\\d{2}:?\\d{2})$/u;\n\n/**\n * Refines a string as an ISO 8601 date.\n */\nexport const ISO8601DateStruct = refine(string(), 'ISO 8601 date', (value) => {\n const parsedDate = DateTime.fromISO(value);\n\n if (!parsedDate.isValid) {\n return 'Not a valid ISO 8601 date';\n }\n\n if (!offsetRegex.test(value)) {\n // Luxon doesn't have a reliable way to check if timezone info was not provided\n return 'ISO 8601 date must have timezone information';\n }\n\n return true;\n});\n\n/**\n * Remove millisecond precision from an ISO 8601 string.\n *\n * @param value - A valid ISO 8601 date.\n * @returns A valid ISO 8601 date with millisecond precision removed.\n */\nexport function toCensoredISO8601String(value: string) {\n const date = DateTime.fromISO(value, { setZone: true });\n\n // Make sure any millisecond precision is removed.\n return date.startOf('second').toISO({\n suppressMilliseconds: true,\n }) as string;\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-utils",
3
- "version": "9.2.2",
3
+ "version": "9.4.0",
4
4
  "description": "A collection of utilities for MetaMask Snaps",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -84,9 +84,9 @@
84
84
  "@metamask/key-tree": "^10.1.1",
85
85
  "@metamask/permission-controller": "^11.0.6",
86
86
  "@metamask/rpc-errors": "^7.0.2",
87
- "@metamask/slip44": "^4.1.0",
87
+ "@metamask/slip44": "^4.2.0",
88
88
  "@metamask/snaps-registry": "^3.2.3",
89
- "@metamask/snaps-sdk": "^6.23.0",
89
+ "@metamask/snaps-sdk": "^7.1.0",
90
90
  "@metamask/superstruct": "^3.2.1",
91
91
  "@metamask/utils": "^11.4.0",
92
92
  "@noble/hashes": "^1.7.1",
@@ -125,6 +125,7 @@
125
125
  "istanbul-lib-report": "^3.0.0",
126
126
  "istanbul-reports": "^3.1.5",
127
127
  "jest": "^29.0.2",
128
+ "jest-fetch-mock": "^3.0.3",
128
129
  "jest-silent-reporter": "^0.6.0",
129
130
  "memfs": "^3.4.13",
130
131
  "prettier": "^3.3.3",