@metamask/snaps-utils 9.3.0 → 10.0.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 (120) hide show
  1. package/CHANGELOG.md +30 -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/cronjob.cjs +16 -15
  11. package/dist/cronjob.cjs.map +1 -1
  12. package/dist/cronjob.d.cts +27 -36
  13. package/dist/cronjob.d.cts.map +1 -1
  14. package/dist/cronjob.d.mts +27 -36
  15. package/dist/cronjob.d.mts.map +1 -1
  16. package/dist/cronjob.mjs +16 -14
  17. package/dist/cronjob.mjs.map +1 -1
  18. package/dist/errors.cjs +22 -24
  19. package/dist/errors.cjs.map +1 -1
  20. package/dist/errors.d.cts.map +1 -1
  21. package/dist/errors.d.mts.map +1 -1
  22. package/dist/errors.mjs +22 -24
  23. package/dist/errors.mjs.map +1 -1
  24. package/dist/eval-worker.cjs +38 -11
  25. package/dist/eval-worker.cjs.map +1 -1
  26. package/dist/eval-worker.d.cts.map +1 -1
  27. package/dist/eval-worker.d.mts.map +1 -1
  28. package/dist/eval-worker.mjs +38 -11
  29. package/dist/eval-worker.mjs.map +1 -1
  30. package/dist/eval.cjs +7 -0
  31. package/dist/eval.cjs.map +1 -1
  32. package/dist/eval.d.cts +7 -0
  33. package/dist/eval.d.cts.map +1 -1
  34. package/dist/eval.d.mts +7 -0
  35. package/dist/eval.d.mts.map +1 -1
  36. package/dist/eval.mjs +7 -0
  37. package/dist/eval.mjs.map +1 -1
  38. package/dist/fs.cjs +51 -6
  39. package/dist/fs.cjs.map +1 -1
  40. package/dist/fs.d.cts +16 -4
  41. package/dist/fs.d.cts.map +1 -1
  42. package/dist/fs.d.mts +16 -4
  43. package/dist/fs.d.mts.map +1 -1
  44. package/dist/fs.mjs +49 -5
  45. package/dist/fs.mjs.map +1 -1
  46. package/dist/handlers/home-page.d.cts +3 -3
  47. package/dist/handlers/home-page.d.mts +3 -3
  48. package/dist/handlers/settings-page.d.cts +1 -1
  49. package/dist/handlers/settings-page.d.mts +1 -1
  50. package/dist/handlers/signature.d.cts +1 -1
  51. package/dist/handlers/signature.d.mts +1 -1
  52. package/dist/handlers/transaction.d.cts +3 -3
  53. package/dist/handlers/transaction.d.mts +3 -3
  54. package/dist/index.cjs +1 -0
  55. package/dist/index.cjs.map +1 -1
  56. package/dist/index.d.cts +1 -1
  57. package/dist/index.d.cts.map +1 -1
  58. package/dist/index.d.mts +1 -1
  59. package/dist/index.d.mts.map +1 -1
  60. package/dist/index.mjs +1 -0
  61. package/dist/index.mjs.map +1 -1
  62. package/dist/manifest/manifest.cjs +36 -4
  63. package/dist/manifest/manifest.cjs.map +1 -1
  64. package/dist/manifest/manifest.d.cts +40 -7
  65. package/dist/manifest/manifest.d.cts.map +1 -1
  66. package/dist/manifest/manifest.d.mts +40 -7
  67. package/dist/manifest/manifest.d.mts.map +1 -1
  68. package/dist/manifest/manifest.mjs +13 -4
  69. package/dist/manifest/manifest.mjs.map +1 -1
  70. package/dist/manifest/validator-types.cjs.map +1 -1
  71. package/dist/manifest/validator-types.d.cts +18 -1
  72. package/dist/manifest/validator-types.d.cts.map +1 -1
  73. package/dist/manifest/validator-types.d.mts +18 -1
  74. package/dist/manifest/validator-types.d.mts.map +1 -1
  75. package/dist/manifest/validator-types.mjs.map +1 -1
  76. package/dist/manifest/validator.cjs +21 -21
  77. package/dist/manifest/validator.cjs.map +1 -1
  78. package/dist/manifest/validator.d.cts +4 -2
  79. package/dist/manifest/validator.d.cts.map +1 -1
  80. package/dist/manifest/validator.d.mts +4 -2
  81. package/dist/manifest/validator.d.mts.map +1 -1
  82. package/dist/manifest/validator.mjs +21 -21
  83. package/dist/manifest/validator.mjs.map +1 -1
  84. package/dist/manifest/validators/index.cjs +2 -0
  85. package/dist/manifest/validators/index.cjs.map +1 -1
  86. package/dist/manifest/validators/index.d.cts +2 -0
  87. package/dist/manifest/validators/index.d.cts.map +1 -1
  88. package/dist/manifest/validators/index.d.mts +2 -0
  89. package/dist/manifest/validators/index.d.mts.map +1 -1
  90. package/dist/manifest/validators/index.mjs +2 -0
  91. package/dist/manifest/validators/index.mjs.map +1 -1
  92. package/dist/manifest/validators/production-platform-version.cjs +47 -0
  93. package/dist/manifest/validators/production-platform-version.cjs.map +1 -0
  94. package/dist/manifest/validators/production-platform-version.d.cts +7 -0
  95. package/dist/manifest/validators/production-platform-version.d.cts.map +1 -0
  96. package/dist/manifest/validators/production-platform-version.d.mts +7 -0
  97. package/dist/manifest/validators/production-platform-version.d.mts.map +1 -0
  98. package/dist/manifest/validators/production-platform-version.mjs +44 -0
  99. package/dist/manifest/validators/production-platform-version.mjs.map +1 -0
  100. package/dist/manifest/validators/unused-exports.cjs +53 -0
  101. package/dist/manifest/validators/unused-exports.cjs.map +1 -0
  102. package/dist/manifest/validators/unused-exports.d.cts +7 -0
  103. package/dist/manifest/validators/unused-exports.d.cts.map +1 -0
  104. package/dist/manifest/validators/unused-exports.d.mts +7 -0
  105. package/dist/manifest/validators/unused-exports.d.mts.map +1 -0
  106. package/dist/manifest/validators/unused-exports.mjs +50 -0
  107. package/dist/manifest/validators/unused-exports.mjs.map +1 -0
  108. package/dist/time.cjs +15 -1
  109. package/dist/time.cjs.map +1 -1
  110. package/dist/time.d.cts +7 -0
  111. package/dist/time.d.cts.map +1 -1
  112. package/dist/time.d.mts +7 -0
  113. package/dist/time.d.mts.map +1 -1
  114. package/dist/time.mjs +13 -0
  115. package/dist/time.mjs.map +1 -1
  116. package/dist/virtual-file/VirtualFile.cjs +4 -0
  117. package/dist/virtual-file/VirtualFile.cjs.map +1 -1
  118. package/dist/virtual-file/VirtualFile.mjs +4 -0
  119. package/dist/virtual-file/VirtualFile.mjs.map +1 -1
  120. package/package.json +8 -7
package/CHANGELOG.md CHANGED
@@ -7,6 +7,33 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [10.0.0]
11
+
12
+ ### Added
13
+
14
+ - Support scheduling cronjobs with an ISO 8601 duration ([#3421](https://github.com/MetaMask/snaps/pull/3421))
15
+
16
+ ### Changed
17
+
18
+ - **BREAKING:** Drop support for Node.js 18 and 21 ([#3447](https://github.com/MetaMask/snaps/pull/3447))
19
+
20
+ ### Fixed
21
+
22
+ - Unwrap double-wrapped JSON-RPC errors ([#3432](https://github.com/MetaMask/snaps/pull/3432))
23
+
24
+ ## [9.4.0]
25
+
26
+ ### Added
27
+
28
+ - Validate platform version against production ([#3417](https://github.com/MetaMask/snaps/pull/3417))
29
+ - Detect unused permissions in Snaps CLI ([#3335](https://github.com/MetaMask/snaps/pull/3335))
30
+ - Add support for `AccountSelector` component ([#3088](https://github.com/MetaMask/snaps/pull/3088))
31
+ - Add `toCensoredISO8601String` util function ([#3414](https://github.com/MetaMask/snaps/pull/3414))
32
+
33
+ ### Changed
34
+
35
+ - Bump `@metamask/slip44` from `4.1.0` to `4.2.0` ([#3419](https://github.com/MetaMask/snaps/pull/3419))
36
+
10
37
  ## [9.3.0]
11
38
 
12
39
  ### Added
@@ -610,7 +637,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
610
637
  - The version of the package no longer needs to match the version of all other
611
638
  MetaMask Snaps packages.
612
639
 
613
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.3.0...HEAD
640
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@10.0.0...HEAD
641
+ [10.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.4.0...@metamask/snaps-utils@10.0.0
642
+ [9.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.3.0...@metamask/snaps-utils@9.4.0
614
643
  [9.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.2.2...@metamask/snaps-utils@9.3.0
615
644
  [9.2.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.2.1...@metamask/snaps-utils@9.2.2
616
645
  [9.2.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@9.2.0...@metamask/snaps-utils@9.2.1
package/dist/account.cjs CHANGED
@@ -1,3 +1,56 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.snapOwnsAccount = exports.createChainIdList = exports.createAccountList = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ /**
6
+ * Create a list of CAIP account IDs from an address and a list of scopes.
7
+ *
8
+ * @param address - The address to create the account IDs from.
9
+ * @param scopes - The scopes to create the account IDs from.
10
+ * @returns The list of CAIP account IDs.
11
+ */
12
+ function createAccountList(address, scopes) {
13
+ return scopes.map((scope) => `${scope}:${address}`);
14
+ }
15
+ exports.createAccountList = createAccountList;
16
+ /**
17
+ * Create a list of CAIP chain IDs from a list of account scopes and a list of requested chain IDs.
18
+ *
19
+ * @param accountScopes - The account scopes to create the chain ID list from.
20
+ * @param requestedChainIds - The requested chain IDs to filter the account scopes by.
21
+ * @returns The list of CAIP chain IDs.
22
+ */
23
+ function createChainIdList(accountScopes, requestedChainIds) {
24
+ // If there are no requested chain IDs, return all account scopes.
25
+ if (!requestedChainIds || requestedChainIds.length === 0) {
26
+ return accountScopes;
27
+ }
28
+ return accountScopes.reduce((acc, scope) => {
29
+ // If the scope represents all EVM compatible chains, return all requested chain IDs.
30
+ if (scope === 'eip155:0') {
31
+ const evmChainIds = requestedChainIds.filter((chainId) => {
32
+ const { namespace } = (0, utils_1.parseCaipChainId)(chainId);
33
+ return namespace === utils_1.KnownCaipNamespace.Eip155;
34
+ });
35
+ acc.push(...evmChainIds);
36
+ }
37
+ // If the scope is not in the requested chain IDs, skip it.
38
+ else if (requestedChainIds.includes(scope)) {
39
+ acc.push(scope);
40
+ }
41
+ return acc;
42
+ }, []);
43
+ }
44
+ exports.createChainIdList = createChainIdList;
45
+ /**
46
+ * Whether if the snap owns the account.
47
+ *
48
+ * @param snapId - The snap id.
49
+ * @param account - The account.
50
+ * @returns True if the snap owns the account, otherwise false.
51
+ */
52
+ function snapOwnsAccount(snapId, account) {
53
+ return account.metadata.snap?.id === snapId;
54
+ }
55
+ exports.snapOwnsAccount = snapOwnsAccount;
3
56
  //# sourceMappingURL=account.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.cjs","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"","sourcesContent":["import type { SnapId } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Copy of the original type from\n * https://github.com/MetaMask/accounts/blob/main/packages/keyring-internal-api/src/types.ts\n */\nexport type InternalAccount = {\n id: string;\n type: string;\n address: string;\n options: Record<string, Json>;\n methods: string[];\n metadata: {\n name: string;\n snap?: { id: SnapId; enabled: boolean; name: string };\n };\n};\n"]}
1
+ {"version":3,"file":"account.cjs","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":";;;AAEA,2CAAuE;AAmBvE;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,OAAe,EACf,MAAqB;IAErB,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,IAAI,OAAO,EAAE,CAAoB,CAAC;AACzE,CAAC;AALD,8CAKC;AAED;;;;;;GAMG;AACH,SAAgB,iBAAiB,CAC/B,aAA4B,EAC5B,iBAAiC;IAEjC,kEAAkE;IAClE,IAAI,CAAC,iBAAiB,IAAI,iBAAiB,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACzD,OAAO,aAAa,CAAC;IACvB,CAAC;IAED,OAAO,aAAa,CAAC,MAAM,CAAgB,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QACxD,qFAAqF;QACrF,IAAI,KAAK,KAAK,UAAU,EAAE,CAAC;YACzB,MAAM,WAAW,GAAG,iBAAiB,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE;gBACvD,MAAM,EAAE,SAAS,EAAE,GAAG,IAAA,wBAAgB,EAAC,OAAO,CAAC,CAAC;gBAEhD,OAAO,SAAS,KAAK,0BAAkB,CAAC,MAAM,CAAC;YACjD,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,CAAC;QAC3B,CAAC;QAED,2DAA2D;aACtD,IAAI,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;YAC3C,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAClB,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC;AA5BD,8CA4BC;AAED;;;;;;GAMG;AACH,SAAgB,eAAe,CAAC,MAAc,EAAE,OAAwB;IACtE,OAAO,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,MAAM,CAAC;AAC9C,CAAC;AAFD,0CAEC","sourcesContent":["import type { SnapId } from '@metamask/snaps-sdk';\nimport type { Json, CaipAccountId, CaipChainId } from '@metamask/utils';\nimport { KnownCaipNamespace, parseCaipChainId } from '@metamask/utils';\n\n/**\n * Copy of the original type from\n * https://github.com/MetaMask/accounts/blob/main/packages/keyring-internal-api/src/types.ts\n */\nexport type InternalAccount = {\n id: string;\n type: string;\n address: string;\n options: Record<string, Json>;\n methods: string[];\n scopes: CaipChainId[];\n metadata: {\n name: string;\n snap?: { id: SnapId; enabled: boolean; name: string };\n };\n};\n\n/**\n * Create a list of CAIP account IDs from an address and a list of scopes.\n *\n * @param address - The address to create the account IDs from.\n * @param scopes - The scopes to create the account IDs from.\n * @returns The list of CAIP account IDs.\n */\nexport function createAccountList(\n address: string,\n scopes: CaipChainId[],\n): CaipAccountId[] {\n return scopes.map((scope) => `${scope}:${address}`) as CaipAccountId[];\n}\n\n/**\n * Create a list of CAIP chain IDs from a list of account scopes and a list of requested chain IDs.\n *\n * @param accountScopes - The account scopes to create the chain ID list from.\n * @param requestedChainIds - The requested chain IDs to filter the account scopes by.\n * @returns The list of CAIP chain IDs.\n */\nexport function createChainIdList(\n accountScopes: CaipChainId[],\n requestedChainIds?: CaipChainId[],\n) {\n // If there are no requested chain IDs, return all account scopes.\n if (!requestedChainIds || requestedChainIds.length === 0) {\n return accountScopes;\n }\n\n return accountScopes.reduce<CaipChainId[]>((acc, scope) => {\n // If the scope represents all EVM compatible chains, return all requested chain IDs.\n if (scope === 'eip155:0') {\n const evmChainIds = requestedChainIds.filter((chainId) => {\n const { namespace } = parseCaipChainId(chainId);\n\n return namespace === KnownCaipNamespace.Eip155;\n });\n\n acc.push(...evmChainIds);\n }\n\n // If the scope is not in the requested chain IDs, skip it.\n else if (requestedChainIds.includes(scope)) {\n acc.push(scope);\n }\n\n return acc;\n }, []);\n}\n\n/**\n * Whether if the snap owns the account.\n *\n * @param snapId - The snap id.\n * @param account - The account.\n * @returns True if the snap owns the account, otherwise false.\n */\nexport function snapOwnsAccount(snapId: SnapId, account: InternalAccount) {\n return account.metadata.snap?.id === snapId;\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import type { SnapId } from "@metamask/snaps-sdk";
2
- import type { Json } from "@metamask/utils";
2
+ import type { Json, CaipAccountId, CaipChainId } from "@metamask/utils";
3
3
  /**
4
4
  * Copy of the original type from
5
5
  * https://github.com/MetaMask/accounts/blob/main/packages/keyring-internal-api/src/types.ts
@@ -10,6 +10,7 @@ export type InternalAccount = {
10
10
  address: string;
11
11
  options: Record<string, Json>;
12
12
  methods: string[];
13
+ scopes: CaipChainId[];
13
14
  metadata: {
14
15
  name: string;
15
16
  snap?: {
@@ -19,4 +20,28 @@ export type InternalAccount = {
19
20
  };
20
21
  };
21
22
  };
23
+ /**
24
+ * Create a list of CAIP account IDs from an address and a list of scopes.
25
+ *
26
+ * @param address - The address to create the account IDs from.
27
+ * @param scopes - The scopes to create the account IDs from.
28
+ * @returns The list of CAIP account IDs.
29
+ */
30
+ export declare function createAccountList(address: string, scopes: CaipChainId[]): CaipAccountId[];
31
+ /**
32
+ * Create a list of CAIP chain IDs from a list of account scopes and a list of requested chain IDs.
33
+ *
34
+ * @param accountScopes - The account scopes to create the chain ID list from.
35
+ * @param requestedChainIds - The requested chain IDs to filter the account scopes by.
36
+ * @returns The list of CAIP chain IDs.
37
+ */
38
+ export declare function createChainIdList(accountScopes: CaipChainId[], requestedChainIds?: CaipChainId[]): `${string}:${string}`[];
39
+ /**
40
+ * Whether if the snap owns the account.
41
+ *
42
+ * @param snapId - The snap id.
43
+ * @param account - The account.
44
+ * @returns True if the snap owns the account, otherwise false.
45
+ */
46
+ export declare function snapOwnsAccount(snapId: SnapId, account: InternalAccount): boolean;
22
47
  //# sourceMappingURL=account.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.cts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,OAAO,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;KACvD,CAAC;CACH,CAAC"}
1
+ {"version":3,"file":"account.d.cts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,wBAAwB;AAGxE;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,OAAO,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;KACvD,CAAC;CACH,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,WAAW,EAAE,GACpB,aAAa,EAAE,CAEjB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,WAAW,EAAE,EAC5B,iBAAiB,CAAC,EAAE,WAAW,EAAE,2BA0BlC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,WAEvE"}
@@ -1,5 +1,5 @@
1
1
  import type { SnapId } from "@metamask/snaps-sdk";
2
- import type { Json } from "@metamask/utils";
2
+ import type { Json, CaipAccountId, CaipChainId } from "@metamask/utils";
3
3
  /**
4
4
  * Copy of the original type from
5
5
  * https://github.com/MetaMask/accounts/blob/main/packages/keyring-internal-api/src/types.ts
@@ -10,6 +10,7 @@ export type InternalAccount = {
10
10
  address: string;
11
11
  options: Record<string, Json>;
12
12
  methods: string[];
13
+ scopes: CaipChainId[];
13
14
  metadata: {
14
15
  name: string;
15
16
  snap?: {
@@ -19,4 +20,28 @@ export type InternalAccount = {
19
20
  };
20
21
  };
21
22
  };
23
+ /**
24
+ * Create a list of CAIP account IDs from an address and a list of scopes.
25
+ *
26
+ * @param address - The address to create the account IDs from.
27
+ * @param scopes - The scopes to create the account IDs from.
28
+ * @returns The list of CAIP account IDs.
29
+ */
30
+ export declare function createAccountList(address: string, scopes: CaipChainId[]): CaipAccountId[];
31
+ /**
32
+ * Create a list of CAIP chain IDs from a list of account scopes and a list of requested chain IDs.
33
+ *
34
+ * @param accountScopes - The account scopes to create the chain ID list from.
35
+ * @param requestedChainIds - The requested chain IDs to filter the account scopes by.
36
+ * @returns The list of CAIP chain IDs.
37
+ */
38
+ export declare function createChainIdList(accountScopes: CaipChainId[], requestedChainIds?: CaipChainId[]): `${string}:${string}`[];
39
+ /**
40
+ * Whether if the snap owns the account.
41
+ *
42
+ * @param snapId - The snap id.
43
+ * @param account - The account.
44
+ * @returns True if the snap owns the account, otherwise false.
45
+ */
46
+ export declare function snapOwnsAccount(snapId: SnapId, account: InternalAccount): boolean;
22
47
  //# sourceMappingURL=account.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.mts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,wBAAwB;AAE5C;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,OAAO,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;KACvD,CAAC;CACH,CAAC"}
1
+ {"version":3,"file":"account.d.mts","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,WAAW,EAAE,wBAAwB;AAGxE;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,EAAE,WAAW,EAAE,CAAC;IACtB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,CAAC,EAAE;YAAE,EAAE,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,OAAO,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;KACvD,CAAC;CACH,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,MAAM,EACf,MAAM,EAAE,WAAW,EAAE,GACpB,aAAa,EAAE,CAEjB;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,aAAa,EAAE,WAAW,EAAE,EAC5B,iBAAiB,CAAC,EAAE,WAAW,EAAE,2BA0BlC;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,eAAe,WAEvE"}
package/dist/account.mjs CHANGED
@@ -1,2 +1,50 @@
1
- export {};
1
+ import { KnownCaipNamespace, parseCaipChainId } from "@metamask/utils";
2
+ /**
3
+ * Create a list of CAIP account IDs from an address and a list of scopes.
4
+ *
5
+ * @param address - The address to create the account IDs from.
6
+ * @param scopes - The scopes to create the account IDs from.
7
+ * @returns The list of CAIP account IDs.
8
+ */
9
+ export function createAccountList(address, scopes) {
10
+ return scopes.map((scope) => `${scope}:${address}`);
11
+ }
12
+ /**
13
+ * Create a list of CAIP chain IDs from a list of account scopes and a list of requested chain IDs.
14
+ *
15
+ * @param accountScopes - The account scopes to create the chain ID list from.
16
+ * @param requestedChainIds - The requested chain IDs to filter the account scopes by.
17
+ * @returns The list of CAIP chain IDs.
18
+ */
19
+ export function createChainIdList(accountScopes, requestedChainIds) {
20
+ // If there are no requested chain IDs, return all account scopes.
21
+ if (!requestedChainIds || requestedChainIds.length === 0) {
22
+ return accountScopes;
23
+ }
24
+ return accountScopes.reduce((acc, scope) => {
25
+ // If the scope represents all EVM compatible chains, return all requested chain IDs.
26
+ if (scope === 'eip155:0') {
27
+ const evmChainIds = requestedChainIds.filter((chainId) => {
28
+ const { namespace } = parseCaipChainId(chainId);
29
+ return namespace === KnownCaipNamespace.Eip155;
30
+ });
31
+ acc.push(...evmChainIds);
32
+ }
33
+ // If the scope is not in the requested chain IDs, skip it.
34
+ else if (requestedChainIds.includes(scope)) {
35
+ acc.push(scope);
36
+ }
37
+ return acc;
38
+ }, []);
39
+ }
40
+ /**
41
+ * Whether if the snap owns the account.
42
+ *
43
+ * @param snapId - The snap id.
44
+ * @param account - The account.
45
+ * @returns True if the snap owns the account, otherwise false.
46
+ */
47
+ export function snapOwnsAccount(snapId, account) {
48
+ return account.metadata.snap?.id === snapId;
49
+ }
2
50
  //# sourceMappingURL=account.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"account.mjs","sourceRoot":"","sources":["../src/account.ts"],"names":[],"mappings":"","sourcesContent":["import type { SnapId } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\n\n/**\n * Copy of the original type from\n * https://github.com/MetaMask/accounts/blob/main/packages/keyring-internal-api/src/types.ts\n */\nexport type InternalAccount = {\n id: string;\n type: string;\n address: string;\n options: Record<string, Json>;\n methods: string[];\n metadata: {\n name: string;\n snap?: { id: SnapId; enabled: bo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AAO,OAAO,CAAC,QAAQ,CAAC,IAAI,EAAE,EAAE,KAAK,MAAM,CAAC;AAC9C,CAAC","sourcesContent":["import type { SnapId } from '@metamask/snaps-sdk';\nimport type { Json, CaipAccountId, CaipChainId } from '@metamask/utils';\nimport { KnownCaipNamespace, parseCaipChainId } from '@metamask/utils';\n\n/**\n * Copy of the original type from\n * https://github.com/MetaMask/accounts/blob/main/packages/keyring-internal-api/src/types.ts\n */\nexport type InternalAccount = {\n id: string;\n type: string;\n address: string;\n options: Record<string, Json>;\n methods: string[];\n scopes: CaipChainId[];\n metadata: {\n name: string;\n snap?: { id: SnapId; enabled: boolean; name: string };\n };\n};\n\n/**\n * Create a list of CAIP account IDs from an address and a list of scopes.\n *\n * @param address - The address to create the account IDs from.\n * @param scopes - The scopes to create the account IDs from.\n * @returns The list of CAIP account IDs.\n */\nexport function createAccountList(\n address: string,\n scopes: CaipChainId[],\n): CaipAccountId[] {\n return scopes.map((scope) => `${scope}:${address}`) as CaipAccountId[];\n}\n\n/**\n * Create a list of CAIP chain IDs from a list of account scopes and a list of requested chain IDs.\n *\n * @param accountScopes - The account scopes to create the chain ID list from.\n * @param requestedChainIds - The requested chain IDs to filter the account scopes by.\n * @returns The list of CAIP chain IDs.\n */\nexport function createChainIdList(\n accountScopes: CaipChainId[],\n requestedChainIds?: CaipChainId[],\n) {\n // If there are no requested chain IDs, return all account scopes.\n if (!requestedChainIds || requestedChainIds.length === 0) {\n return accountScopes;\n }\n\n return accountScopes.reduce<CaipChainId[]>((acc, scope) => {\n // If the scope represents all EVM compatible chains, return all requested chain IDs.\n if (scope === 'eip155:0') {\n const evmChainIds = requestedChainIds.filter((chainId) => {\n const { namespace } = parseCaipChainId(chainId);\n\n return namespace === KnownCaipNamespace.Eip155;\n });\n\n acc.push(...evmChainIds);\n }\n\n // If the scope is not in the requested chain IDs, skip it.\n else if (requestedChainIds.includes(scope)) {\n acc.push(scope);\n }\n\n return acc;\n }, []);\n}\n\n/**\n * Whether if the snap owns the account.\n *\n * @param snapId - The snap id.\n * @param account - The account.\n * @returns True if the snap owns the account, otherwise false.\n */\nexport function snapOwnsAccount(snapId: SnapId, account: InternalAccount) {\n return account.metadata.snap?.id === snapId;\n}\n"]}
package/dist/cronjob.cjs CHANGED
@@ -1,39 +1,40 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isCronjobSpecificationArray = exports.CronjobSpecificationArrayStruct = exports.isCronjobSpecification = exports.CronjobSpecificationStruct = exports.parseCronExpression = exports.CronExpressionStruct = exports.CronjobRpcRequestStruct = void 0;
3
+ exports.isCronjobSpecificationArray = exports.CronjobSpecificationArrayStruct = exports.isCronjobSpecification = exports.CronjobSpecificationStruct = exports.CronExpressionStruct = exports.CronjobRpcRequestStruct = void 0;
4
+ const snaps_sdk_1 = require("@metamask/snaps-sdk");
4
5
  const superstruct_1 = require("@metamask/superstruct");
5
6
  const utils_1 = require("@metamask/utils");
6
7
  const cron_parser_1 = require("cron-parser");
8
+ const time_1 = require("./time.cjs");
7
9
  exports.CronjobRpcRequestStruct = (0, superstruct_1.object)({
8
10
  jsonrpc: (0, superstruct_1.optional)(utils_1.JsonRpcVersionStruct),
9
11
  id: (0, superstruct_1.optional)(utils_1.JsonRpcIdStruct),
10
12
  method: (0, superstruct_1.string)(),
11
13
  params: (0, superstruct_1.optional)(utils_1.JsonRpcParamsStruct),
12
14
  });
13
- exports.CronExpressionStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'CronExpression', (value) => {
15
+ exports.CronExpressionStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'cronjob expression', (value) => {
14
16
  try {
15
17
  (0, cron_parser_1.parseExpression)(value);
16
18
  return true;
17
19
  }
18
20
  catch {
19
- return false;
21
+ return `Expected a cronjob expression, but received: "${value}"`;
20
22
  }
21
23
  });
22
- /**
23
- * Parses a cron expression.
24
- *
25
- * @param expression - Expression to parse.
26
- * @returns A CronExpression class instance.
27
- */
28
- function parseCronExpression(expression) {
29
- const ensureStringExpression = (0, superstruct_1.create)(expression, exports.CronExpressionStruct);
30
- return (0, cron_parser_1.parseExpression)(ensureStringExpression);
31
- }
32
- exports.parseCronExpression = parseCronExpression;
33
- exports.CronjobSpecificationStruct = (0, superstruct_1.object)({
24
+ const CronjobExpressionSpecificationStruct = (0, superstruct_1.object)({
34
25
  expression: exports.CronExpressionStruct,
35
26
  request: exports.CronjobRpcRequestStruct,
36
27
  });
28
+ const CronjobDurationSpecificationStruct = (0, superstruct_1.object)({
29
+ duration: time_1.ISO8601DurationStruct,
30
+ request: exports.CronjobRpcRequestStruct,
31
+ });
32
+ exports.CronjobSpecificationStruct = (0, snaps_sdk_1.selectiveUnion)((value) => {
33
+ if ((0, utils_1.isObject)(value) && (0, utils_1.hasProperty)(value, 'duration')) {
34
+ return CronjobDurationSpecificationStruct;
35
+ }
36
+ return CronjobExpressionSpecificationStruct;
37
+ });
37
38
  /**
38
39
  * Check if the given value is a {@link CronjobSpecification} object.
39
40
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cronjob.cjs","sourceRoot":"","sources":["../src/cronjob.ts"],"names":[],"mappings":";;;AACA,uDAO+B;AAC/B,2CAIyB;AACzB,6CAA8C;AAEjC,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IAC5C,OAAO,EAAE,IAAA,sBAAQ,EAAC,4BAAoB,CAAC;IACvC,EAAE,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;IAC7B,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,MAAM,EAAE,IAAA,sBAAQ,EAAC,2BAAmB,CAAC;CACtC,CAAC,CAAC;AAIU,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EACxC,IAAA,oBAAM,GAAE,EACR,gBAAgB,EAChB,CAAC,KAAK,EAAE,EAAE;IACR,IAAI,CAAC;QACH,IAAA,6BAAe,EAAC,KAAK,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC,CACF,CAAC;AAIF;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAC,UAA2B;IAC7D,MAAM,sBAAsB,GAAG,IAAA,oBAAM,EAAC,UAAU,EAAE,4BAAoB,CAAC,CAAC;IACxE,OAAO,IAAA,6BAAe,EAAC,sBAAsB,CAAC,CAAC;AACjD,CAAC;AAHD,kDAGC;AAEY,QAAA,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IAC/C,UAAU,EAAE,4BAAoB;IAChC,OAAO,EAAE,+BAAuB;CACjC,CAAC,CAAC;AAGH;;;;;GAKG;AACH,SAAgB,sBAAsB,CAAC,KAAc;IACnD,IAAI,CAAC;QACH,IAAA,oBAAM,EAAC,KAAK,EAAE,kCAA0B,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAPD,wDAOC;AAEY,QAAA,+BAA+B,GAAG,IAAA,mBAAK,EAClD,kCAA0B,CAC3B,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,2BAA2B,CAAC,KAAc;IACxD,IAAI,CAAC;QACH,IAAA,oBAAM,EAAC,KAAK,EAAE,uCAA+B,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAPD,kEAOC","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n array,\n create,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport {\n JsonRpcIdStruct,\n JsonRpcParamsStruct,\n JsonRpcVersionStruct,\n} from '@metamask/utils';\nimport { parseExpression } from 'cron-parser';\n\nexport const CronjobRpcRequestStruct = object({\n jsonrpc: optional(JsonRpcVersionStruct),\n id: optional(JsonRpcIdStruct),\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;\n\nexport const CronExpressionStruct = refine(\n string(),\n 'CronExpression',\n (value) => {\n try {\n parseExpression(value);\n return true;\n } catch {\n return false;\n }\n },\n);\n\nexport type CronExpression = Infer<typeof CronExpressionStruct>;\n\n/**\n * Parses a cron expression.\n *\n * @param expression - Expression to parse.\n * @returns A CronExpression class instance.\n */\nexport function parseCronExpression(expression: string | object) {\n const ensureStringExpression = create(expression, CronExpressionStruct);\n return parseExpression(ensureStringExpression);\n}\n\nexport const CronjobSpecificationStruct = object({\n expression: CronExpressionStruct,\n request: CronjobRpcRequestStruct,\n});\nexport type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;\n\n/**\n * Check if the given value is a {@link CronjobSpecification} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link CronjobSpecification} object.\n */\nexport function isCronjobSpecification(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationStruct);\n return true;\n } catch {\n return false;\n }\n}\n\nexport const CronjobSpecificationArrayStruct = array(\n CronjobSpecificationStruct,\n);\n\n/**\n * Check if the given value is an array of {@link CronjobSpecification} objects.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid array of {@link CronjobSpecification} objects.\n */\nexport function isCronjobSpecificationArray(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationArrayStruct);\n return true;\n } catch {\n return false;\n }\n}\n"]}
1
+ {"version":3,"file":"cronjob.cjs","sourceRoot":"","sources":["../src/cronjob.ts"],"names":[],"mappings":";;;AAAA,mDAAqD;AAErD,uDAO+B;AAC/B,2CAMyB;AACzB,6CAA8C;AAE9C,qCAA+C;AAElC,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAAC;IAC5C,OAAO,EAAE,IAAA,sBAAQ,EAAC,4BAAoB,CAAC;IACvC,EAAE,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;IAC7B,MAAM,EAAE,IAAA,oBAAM,GAAE;IAChB,MAAM,EAAE,IAAA,sBAAQ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,EAAE,uCAA+B,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC;AAPD,kEAOC","sourcesContent":["import { selectiveUnion } from '@metamask/snaps-sdk';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n create,\n object,\n optional,\n refine,\n string,\n} from '@metamask/superstruct';\nimport {\n hasProperty,\n isObject,\n JsonRpcIdStruct,\n JsonRpcParamsStruct,\n JsonRpcVersionStruct,\n} from '@metamask/utils';\nimport { parseExpression } from 'cron-parser';\n\nimport { ISO8601DurationStruct } from './time';\n\nexport const CronjobRpcRequestStruct = object({\n jsonrpc: optional(JsonRpcVersionStruct),\n id: optional(JsonRpcIdStruct),\n method: string(),\n params: optional(JsonRpcParamsStruct),\n});\n\nexport type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;\n\nexport const CronExpressionStruct = refine(\n string(),\n 'cronjob expression',\n (value) => {\n try {\n parseExpression(value);\n return true;\n } catch {\n return `Expected a cronjob expression, but received: \"${value}\"`;\n }\n },\n);\n\nexport type CronExpression = Infer<typeof CronExpressionStruct>;\n\nconst CronjobExpressionSpecificationStruct = object({\n expression: CronExpressionStruct,\n request: CronjobRpcRequestStruct,\n});\n\nconst CronjobDurationSpecificationStruct = object({\n duration: ISO8601DurationStruct,\n request: CronjobRpcRequestStruct,\n});\n\nexport const CronjobSpecificationStruct = selectiveUnion((value) => {\n if (isObject(value) && hasProperty(value, 'duration')) {\n return CronjobDurationSpecificationStruct;\n }\n\n return CronjobExpressionSpecificationStruct;\n});\n\nexport type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;\n\n/**\n * Check if the given value is a {@link CronjobSpecification} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link CronjobSpecification} object.\n */\nexport function isCronjobSpecification(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationStruct);\n return true;\n } catch {\n return false;\n }\n}\n\nexport const CronjobSpecificationArrayStruct = array(\n CronjobSpecificationStruct,\n);\n\n/**\n * Check if the given value is an array of {@link CronjobSpecification} objects.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid array of {@link CronjobSpecification} objects.\n */\nexport function isCronjobSpecificationArray(value: unknown): boolean {\n try {\n create(value, CronjobSpecificationArrayStruct);\n return true;\n } catch {\n return false;\n }\n}\n"]}
@@ -3,45 +3,33 @@ export declare const CronjobRpcRequestStruct: import("@metamask/superstruct").St
3
3
  method: string;
4
4
  jsonrpc?: "2.0" | undefined;
5
5
  id?: string | number | null | undefined;
6
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
6
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
7
7
  }, {
8
8
  jsonrpc: import("@metamask/superstruct").Struct<"2.0" | undefined, "2.0">;
9
9
  id: import("@metamask/superstruct").Struct<string | number | null | undefined, null>;
10
10
  method: import("@metamask/superstruct").Struct<string, null>;
11
- params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
11
+ params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
12
12
  }>;
13
13
  export type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;
14
14
  export declare const CronExpressionStruct: import("@metamask/superstruct").Struct<string, null>;
15
15
  export type CronExpression = Infer<typeof CronExpressionStruct>;
16
- /**
17
- * Parses a cron expression.
18
- *
19
- * @param expression - Expression to parse.
20
- * @returns A CronExpression class instance.
21
- */
22
- export declare function parseCronExpression(expression: string | object): import("cron-parser").CronExpression<false>;
23
16
  export declare const CronjobSpecificationStruct: import("@metamask/superstruct").Struct<{
24
17
  expression: string;
25
18
  request: {
26
19
  method: string;
27
20
  jsonrpc?: "2.0" | undefined;
28
21
  id?: string | number | null | undefined;
29
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
22
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
30
23
  };
31
- }, {
32
- expression: import("@metamask/superstruct").Struct<string, null>;
33
- request: import("@metamask/superstruct").Struct<{
24
+ } | {
25
+ request: {
34
26
  method: string;
35
27
  jsonrpc?: "2.0" | undefined;
36
28
  id?: string | number | null | undefined;
37
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
38
- }, {
39
- jsonrpc: import("@metamask/superstruct").Struct<"2.0" | undefined, "2.0">;
40
- id: import("@metamask/superstruct").Struct<string | number | null | undefined, null>;
41
- method: import("@metamask/superstruct").Struct<string, null>;
42
- params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
43
- }>;
44
- }>;
29
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
30
+ };
31
+ duration: string;
32
+ }, null>;
45
33
  export type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;
46
34
  /**
47
35
  * Check if the given value is a {@link CronjobSpecification} object.
@@ -50,36 +38,39 @@ export type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;
50
38
  * @returns Whether the value is a valid {@link CronjobSpecification} object.
51
39
  */
52
40
  export declare function isCronjobSpecification(value: unknown): boolean;
53
- export declare const CronjobSpecificationArrayStruct: import("@metamask/superstruct").Struct<{
41
+ export declare const CronjobSpecificationArrayStruct: import("@metamask/superstruct").Struct<({
54
42
  expression: string;
55
43
  request: {
56
44
  method: string;
57
45
  jsonrpc?: "2.0" | undefined;
58
46
  id?: string | number | null | undefined;
59
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
47
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
60
48
  };
61
- }[], import("@metamask/superstruct").Struct<{
49
+ } | {
50
+ request: {
51
+ method: string;
52
+ jsonrpc?: "2.0" | undefined;
53
+ id?: string | number | null | undefined;
54
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
55
+ };
56
+ duration: string;
57
+ })[], import("@metamask/superstruct").Struct<{
62
58
  expression: string;
63
59
  request: {
64
60
  method: string;
65
61
  jsonrpc?: "2.0" | undefined;
66
62
  id?: string | number | null | undefined;
67
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
63
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
68
64
  };
69
- }, {
70
- expression: import("@metamask/superstruct").Struct<string, null>;
71
- request: import("@metamask/superstruct").Struct<{
65
+ } | {
66
+ request: {
72
67
  method: string;
73
68
  jsonrpc?: "2.0" | undefined;
74
69
  id?: string | number | null | undefined;
75
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
76
- }, {
77
- jsonrpc: import("@metamask/superstruct").Struct<"2.0" | undefined, "2.0">;
78
- id: import("@metamask/superstruct").Struct<string | number | null | undefined, null>;
79
- method: import("@metamask/superstruct").Struct<string, null>;
80
- params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
81
- }>;
82
- }>>;
70
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
71
+ };
72
+ duration: string;
73
+ }, null>>;
83
74
  /**
84
75
  * Check if the given value is an array of {@link CronjobSpecification} objects.
85
76
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cronjob.d.cts","sourceRoot":"","sources":["../src/cronjob.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAgBnD,eAAO,MAAM,uBAAuB;;;;;;;;;;EAKlC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,uBA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;GAKG;AACH,wBAAgB,2BAA2B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAOnE"}
@@ -3,45 +3,33 @@ export declare const CronjobRpcRequestStruct: import("@metamask/superstruct").St
3
3
  method: string;
4
4
  jsonrpc?: "2.0" | undefined;
5
5
  id?: string | number | null | undefined;
6
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
6
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
7
7
  }, {
8
8
  jsonrpc: import("@metamask/superstruct").Struct<"2.0" | undefined, "2.0">;
9
9
  id: import("@metamask/superstruct").Struct<string | number | null | undefined, null>;
10
10
  method: import("@metamask/superstruct").Struct<string, null>;
11
- params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
11
+ params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
12
12
  }>;
13
13
  export type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;
14
14
  export declare const CronExpressionStruct: import("@metamask/superstruct").Struct<string, null>;
15
15
  export type CronExpression = Infer<typeof CronExpressionStruct>;
16
- /**
17
- * Parses a cron expression.
18
- *
19
- * @param expression - Expression to parse.
20
- * @returns A CronExpression class instance.
21
- */
22
- export declare function parseCronExpression(expression: string | object): import("cron-parser").CronExpression<false>;
23
16
  export declare const CronjobSpecificationStruct: import("@metamask/superstruct").Struct<{
24
17
  expression: string;
25
18
  request: {
26
19
  method: string;
27
20
  jsonrpc?: "2.0" | undefined;
28
21
  id?: string | number | null | undefined;
29
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
22
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
30
23
  };
31
- }, {
32
- expression: import("@metamask/superstruct").Struct<string, null>;
33
- request: import("@metamask/superstruct").Struct<{
24
+ } | {
25
+ request: {
34
26
  method: string;
35
27
  jsonrpc?: "2.0" | undefined;
36
28
  id?: string | number | null | undefined;
37
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
38
- }, {
39
- jsonrpc: import("@metamask/superstruct").Struct<"2.0" | undefined, "2.0">;
40
- id: import("@metamask/superstruct").Struct<string | number | null | undefined, null>;
41
- method: import("@metamask/superstruct").Struct<string, null>;
42
- params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
43
- }>;
44
- }>;
29
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
30
+ };
31
+ duration: string;
32
+ }, null>;
45
33
  export type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;
46
34
  /**
47
35
  * Check if the given value is a {@link CronjobSpecification} object.
@@ -50,36 +38,39 @@ export type CronjobSpecification = Infer<typeof CronjobSpecificationStruct>;
50
38
  * @returns Whether the value is a valid {@link CronjobSpecification} object.
51
39
  */
52
40
  export declare function isCronjobSpecification(value: unknown): boolean;
53
- export declare const CronjobSpecificationArrayStruct: import("@metamask/superstruct").Struct<{
41
+ export declare const CronjobSpecificationArrayStruct: import("@metamask/superstruct").Struct<({
54
42
  expression: string;
55
43
  request: {
56
44
  method: string;
57
45
  jsonrpc?: "2.0" | undefined;
58
46
  id?: string | number | null | undefined;
59
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
47
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
60
48
  };
61
- }[], import("@metamask/superstruct").Struct<{
49
+ } | {
50
+ request: {
51
+ method: string;
52
+ jsonrpc?: "2.0" | undefined;
53
+ id?: string | number | null | undefined;
54
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
55
+ };
56
+ duration: string;
57
+ })[], import("@metamask/superstruct").Struct<{
62
58
  expression: string;
63
59
  request: {
64
60
  method: string;
65
61
  jsonrpc?: "2.0" | undefined;
66
62
  id?: string | number | null | undefined;
67
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
63
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
68
64
  };
69
- }, {
70
- expression: import("@metamask/superstruct").Struct<string, null>;
71
- request: import("@metamask/superstruct").Struct<{
65
+ } | {
66
+ request: {
72
67
  method: string;
73
68
  jsonrpc?: "2.0" | undefined;
74
69
  id?: string | number | null | undefined;
75
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
76
- }, {
77
- jsonrpc: import("@metamask/superstruct").Struct<"2.0" | undefined, "2.0">;
78
- id: import("@metamask/superstruct").Struct<string | number | null | undefined, null>;
79
- method: import("@metamask/superstruct").Struct<string, null>;
80
- params: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
81
- }>;
82
- }>>;
70
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
71
+ };
72
+ duration: string;
73
+ }, null>>;
83
74
  /**
84
75
  * Check if the given value is an array of {@link CronjobSpecification} objects.
85
76
  *
@@ -1 +1 @@
1
- {"version":3,"file":"cronjob.d.mts","sourceRoot":"","sources":["../src/cronjob.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAgBnD,eAAO,MAAM,uBAAuB;;;;;;;;;;EAKlC,CAAC;AAEH,MAAM,MAAM,iBAAiB,GAAG,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AAEtE,eAAO,MAAM,oBAAoB,sDAWhC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AAEhE;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,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