@metamask/snaps-utils 0.34.0-flask.1 → 0.35.0-flask.1

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 (249) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/dist/cjs/array.js +23 -0
  3. package/dist/cjs/array.js.map +1 -0
  4. package/dist/cjs/caveats.js +33 -0
  5. package/dist/cjs/caveats.js.map +1 -0
  6. package/dist/cjs/checksum.js +38 -0
  7. package/dist/cjs/checksum.js.map +1 -0
  8. package/dist/cjs/cronjob.js +84 -0
  9. package/dist/cjs/cronjob.js.map +1 -0
  10. package/dist/cjs/deep-clone.js +22 -0
  11. package/dist/cjs/deep-clone.js.map +1 -0
  12. package/dist/cjs/default-endowments.js +49 -0
  13. package/dist/cjs/default-endowments.js.map +1 -0
  14. package/dist/cjs/entropy.js +23 -0
  15. package/dist/cjs/entropy.js.map +1 -0
  16. package/dist/cjs/enum.js +16 -0
  17. package/dist/cjs/enum.js.map +1 -0
  18. package/dist/{eval-worker.js → cjs/eval-worker.js} +22 -21
  19. package/dist/cjs/eval-worker.js.map +1 -0
  20. package/dist/cjs/eval.js +29 -0
  21. package/dist/cjs/eval.js.map +1 -0
  22. package/dist/cjs/fs.js +126 -0
  23. package/dist/cjs/fs.js.map +1 -0
  24. package/dist/cjs/handlers.js +6 -0
  25. package/dist/cjs/handlers.js.map +1 -0
  26. package/dist/cjs/icon.js +37 -0
  27. package/dist/cjs/icon.js.map +1 -0
  28. package/dist/{iframe.js → cjs/iframe.js} +14 -9
  29. package/dist/cjs/iframe.js.map +1 -0
  30. package/dist/cjs/index.browser.js +40 -0
  31. package/dist/cjs/index.browser.js.map +1 -0
  32. package/dist/cjs/index.executionenv.js +24 -0
  33. package/dist/cjs/index.executionenv.js.map +1 -0
  34. package/dist/cjs/index.js +45 -0
  35. package/dist/cjs/index.js.map +1 -0
  36. package/dist/cjs/json-rpc.js +46 -0
  37. package/dist/cjs/json-rpc.js.map +1 -0
  38. package/dist/cjs/json.js +16 -0
  39. package/dist/cjs/json.js.map +1 -0
  40. package/dist/cjs/logging.js +40 -0
  41. package/dist/cjs/logging.js.map +1 -0
  42. package/dist/cjs/manifest/index.browser.js +20 -0
  43. package/dist/cjs/manifest/index.browser.js.map +1 -0
  44. package/dist/cjs/manifest/index.js +21 -0
  45. package/dist/cjs/manifest/index.js.map +1 -0
  46. package/dist/cjs/manifest/manifest.js +239 -0
  47. package/dist/cjs/manifest/manifest.js.map +1 -0
  48. package/dist/cjs/manifest/validation.js +183 -0
  49. package/dist/cjs/manifest/validation.js.map +1 -0
  50. package/dist/cjs/mock.js +128 -0
  51. package/dist/cjs/mock.js.map +1 -0
  52. package/dist/cjs/namespace.js +124 -0
  53. package/dist/cjs/namespace.js.map +1 -0
  54. package/dist/cjs/npm.js +81 -0
  55. package/dist/cjs/npm.js.map +1 -0
  56. package/dist/cjs/path.js +21 -0
  57. package/dist/cjs/path.js.map +1 -0
  58. package/dist/cjs/post-process.js +328 -0
  59. package/dist/cjs/post-process.js.map +1 -0
  60. package/dist/cjs/snaps.js +230 -0
  61. package/dist/cjs/snaps.js.map +1 -0
  62. package/dist/cjs/types.js +117 -0
  63. package/dist/cjs/types.js.map +1 -0
  64. package/dist/cjs/validation.js +22 -0
  65. package/dist/cjs/validation.js.map +1 -0
  66. package/dist/cjs/versions.js +47 -0
  67. package/dist/cjs/versions.js.map +1 -0
  68. package/dist/cjs/virtual-file/VirtualFile.js +85 -0
  69. package/dist/cjs/virtual-file/VirtualFile.js.map +1 -0
  70. package/dist/cjs/virtual-file/index.browser.js +20 -0
  71. package/dist/cjs/virtual-file/index.browser.js.map +1 -0
  72. package/dist/cjs/virtual-file/index.js +21 -0
  73. package/dist/cjs/virtual-file/index.js.map +1 -0
  74. package/dist/cjs/virtual-file/toVirtualFile.js +33 -0
  75. package/dist/cjs/virtual-file/toVirtualFile.js.map +1 -0
  76. package/dist/esm/array.js +13 -0
  77. package/dist/esm/array.js.map +1 -0
  78. package/dist/esm/caveats.js +23 -0
  79. package/dist/esm/caveats.js.map +1 -0
  80. package/dist/esm/checksum.js +36 -0
  81. package/dist/esm/checksum.js.map +1 -0
  82. package/dist/esm/cronjob.js +66 -0
  83. package/dist/esm/cronjob.js.map +1 -0
  84. package/dist/esm/deep-clone.js +7 -0
  85. package/dist/esm/deep-clone.js.map +1 -0
  86. package/dist/{default-endowments.js → esm/default-endowments.js} +3 -6
  87. package/dist/esm/default-endowments.js.map +1 -0
  88. package/dist/esm/entropy.js +6 -0
  89. package/dist/esm/entropy.js.map +1 -0
  90. package/dist/esm/enum.js +12 -0
  91. package/dist/esm/enum.js.map +1 -0
  92. package/dist/esm/eval-worker.js +47 -0
  93. package/dist/esm/eval-worker.js.map +1 -0
  94. package/dist/esm/eval.js +25 -0
  95. package/dist/esm/eval.js.map +1 -0
  96. package/dist/{fs.js → esm/fs.js} +33 -55
  97. package/dist/esm/fs.js.map +1 -0
  98. package/dist/esm/handlers.js +3 -0
  99. package/dist/esm/handlers.js.map +1 -0
  100. package/dist/esm/icon.js +11 -0
  101. package/dist/esm/icon.js.map +1 -0
  102. package/dist/esm/iframe.js +49 -0
  103. package/dist/esm/iframe.js.map +1 -0
  104. package/dist/esm/index.browser.js +23 -0
  105. package/dist/esm/index.browser.js.map +1 -0
  106. package/dist/esm/index.executionenv.js +7 -0
  107. package/dist/esm/index.executionenv.js.map +1 -0
  108. package/dist/esm/index.js +28 -0
  109. package/dist/esm/index.js.map +1 -0
  110. package/dist/esm/json-rpc.js +39 -0
  111. package/dist/esm/json-rpc.js.map +1 -0
  112. package/dist/esm/json.js +17 -0
  113. package/dist/esm/json.js.map +1 -0
  114. package/dist/{logging.js → esm/logging.js} +6 -14
  115. package/dist/esm/logging.js.map +1 -0
  116. package/dist/esm/manifest/index.browser.js +3 -0
  117. package/dist/esm/manifest/index.browser.js.map +1 -0
  118. package/dist/esm/manifest/index.js +4 -0
  119. package/dist/esm/manifest/index.js.map +1 -0
  120. package/dist/{manifest → esm/manifest}/manifest.js +91 -107
  121. package/dist/esm/manifest/manifest.js.map +1 -0
  122. package/dist/esm/manifest/validation.js +152 -0
  123. package/dist/esm/manifest/validation.js.map +1 -0
  124. package/dist/{mock.js → esm/mock.js} +40 -42
  125. package/dist/esm/mock.js.map +1 -0
  126. package/dist/esm/namespace.js +110 -0
  127. package/dist/esm/namespace.js.map +1 -0
  128. package/dist/{npm.js → esm/npm.js} +23 -30
  129. package/dist/esm/npm.js.map +1 -0
  130. package/dist/esm/path.js +17 -0
  131. package/dist/esm/path.js.map +1 -0
  132. package/dist/{post-process.js → esm/post-process.js} +110 -99
  133. package/dist/esm/post-process.js.map +1 -0
  134. package/dist/esm/snaps.js +215 -0
  135. package/dist/esm/snaps.js.map +1 -0
  136. package/dist/esm/types.js +85 -0
  137. package/dist/esm/types.js.map +1 -0
  138. package/dist/esm/validation.js +17 -0
  139. package/dist/esm/validation.js.map +1 -0
  140. package/dist/{versions.js → esm/versions.js} +15 -18
  141. package/dist/esm/versions.js.map +1 -0
  142. package/dist/{virtual-file → esm/virtual-file}/VirtualFile.js +47 -33
  143. package/dist/esm/virtual-file/VirtualFile.js.map +1 -0
  144. package/dist/esm/virtual-file/index.browser.js +3 -0
  145. package/dist/esm/virtual-file/index.browser.js.map +1 -0
  146. package/dist/esm/virtual-file/index.js +4 -0
  147. package/dist/esm/virtual-file/index.js.map +1 -0
  148. package/dist/esm/virtual-file/toVirtualFile.js +26 -0
  149. package/dist/esm/virtual-file/toVirtualFile.js.map +1 -0
  150. package/dist/types/array.d.ts +10 -0
  151. package/dist/{caveats.d.ts → types/caveats.d.ts} +0 -4
  152. package/dist/types/enum.d.ts +30 -0
  153. package/dist/{handlers.d.ts → types/handlers.d.ts} +1 -38
  154. package/dist/{index.browser.d.ts → types/index.browser.d.ts} +3 -1
  155. package/dist/{index.d.ts → types/index.d.ts} +3 -1
  156. package/dist/types/index.executionenv.d.ts +4 -0
  157. package/dist/types/json.d.ts +13 -0
  158. package/dist/{manifest → types/manifest}/validation.d.ts +6 -69
  159. package/dist/types/namespace.d.ts +124 -0
  160. package/dist/{types.d.ts → types/types.d.ts} +2 -5
  161. package/package.json +52 -25
  162. package/dist/caveats.js +0 -35
  163. package/dist/caveats.js.map +0 -1
  164. package/dist/checksum.js +0 -42
  165. package/dist/checksum.js.map +0 -1
  166. package/dist/cronjob.js +0 -71
  167. package/dist/cronjob.js.map +0 -1
  168. package/dist/deep-clone.js +0 -9
  169. package/dist/deep-clone.js.map +0 -1
  170. package/dist/default-endowments.js.map +0 -1
  171. package/dist/entropy.js +0 -8
  172. package/dist/entropy.js.map +0 -1
  173. package/dist/eval-worker.js.map +0 -1
  174. package/dist/eval.js +0 -27
  175. package/dist/eval.js.map +0 -1
  176. package/dist/fs.js.map +0 -1
  177. package/dist/handlers.js +0 -3
  178. package/dist/handlers.js.map +0 -1
  179. package/dist/icon.js +0 -17
  180. package/dist/icon.js.map +0 -1
  181. package/dist/iframe.js.map +0 -1
  182. package/dist/iframe.test.browser.js +0 -15
  183. package/dist/iframe.test.browser.js.map +0 -1
  184. package/dist/index.browser.js +0 -36
  185. package/dist/index.browser.js.map +0 -1
  186. package/dist/index.js +0 -41
  187. package/dist/index.js.map +0 -1
  188. package/dist/json-rpc.js +0 -46
  189. package/dist/json-rpc.js.map +0 -1
  190. package/dist/logging.js.map +0 -1
  191. package/dist/manifest/index.browser.js +0 -18
  192. package/dist/manifest/index.browser.js.map +0 -1
  193. package/dist/manifest/index.js +0 -19
  194. package/dist/manifest/index.js.map +0 -1
  195. package/dist/manifest/manifest.js.map +0 -1
  196. package/dist/manifest/validation.js +0 -146
  197. package/dist/manifest/validation.js.map +0 -1
  198. package/dist/mock.js.map +0 -1
  199. package/dist/namespace.d.ts +0 -275
  200. package/dist/namespace.js +0 -225
  201. package/dist/namespace.js.map +0 -1
  202. package/dist/notification.d.ts +0 -66
  203. package/dist/notification.js +0 -58
  204. package/dist/notification.js.map +0 -1
  205. package/dist/npm.js.map +0 -1
  206. package/dist/path.js +0 -21
  207. package/dist/path.js.map +0 -1
  208. package/dist/post-process.js.map +0 -1
  209. package/dist/snaps.js +0 -212
  210. package/dist/snaps.js.map +0 -1
  211. package/dist/types.js +0 -103
  212. package/dist/types.js.map +0 -1
  213. package/dist/validation.js +0 -21
  214. package/dist/validation.js.map +0 -1
  215. package/dist/versions.js.map +0 -1
  216. package/dist/virtual-file/VirtualFile.js.map +0 -1
  217. package/dist/virtual-file/index.browser.js +0 -18
  218. package/dist/virtual-file/index.browser.js.map +0 -1
  219. package/dist/virtual-file/index.js +0 -19
  220. package/dist/virtual-file/index.js.map +0 -1
  221. package/dist/virtual-file/toVirtualFile.js +0 -30
  222. package/dist/virtual-file/toVirtualFile.js.map +0 -1
  223. /package/dist/{checksum.d.ts → types/checksum.d.ts} +0 -0
  224. /package/dist/{cronjob.d.ts → types/cronjob.d.ts} +0 -0
  225. /package/dist/{deep-clone.d.ts → types/deep-clone.d.ts} +0 -0
  226. /package/dist/{default-endowments.d.ts → types/default-endowments.d.ts} +0 -0
  227. /package/dist/{entropy.d.ts → types/entropy.d.ts} +0 -0
  228. /package/dist/{eval-worker.d.ts → types/eval-worker.d.ts} +0 -0
  229. /package/dist/{eval.d.ts → types/eval.d.ts} +0 -0
  230. /package/dist/{fs.d.ts → types/fs.d.ts} +0 -0
  231. /package/dist/{icon.d.ts → types/icon.d.ts} +0 -0
  232. /package/dist/{iframe.d.ts → types/iframe.d.ts} +0 -0
  233. /package/dist/{iframe.test.browser.d.ts → types/iframe.test.browser.d.ts} +0 -0
  234. /package/dist/{json-rpc.d.ts → types/json-rpc.d.ts} +0 -0
  235. /package/dist/{logging.d.ts → types/logging.d.ts} +0 -0
  236. /package/dist/{manifest → types/manifest}/index.browser.d.ts +0 -0
  237. /package/dist/{manifest → types/manifest}/index.d.ts +0 -0
  238. /package/dist/{manifest → types/manifest}/manifest.d.ts +0 -0
  239. /package/dist/{mock.d.ts → types/mock.d.ts} +0 -0
  240. /package/dist/{npm.d.ts → types/npm.d.ts} +0 -0
  241. /package/dist/{path.d.ts → types/path.d.ts} +0 -0
  242. /package/dist/{post-process.d.ts → types/post-process.d.ts} +0 -0
  243. /package/dist/{snaps.d.ts → types/snaps.d.ts} +0 -0
  244. /package/dist/{validation.d.ts → types/validation.d.ts} +0 -0
  245. /package/dist/{versions.d.ts → types/versions.d.ts} +0 -0
  246. /package/dist/{virtual-file → types/virtual-file}/VirtualFile.d.ts +0 -0
  247. /package/dist/{virtual-file → types/virtual-file}/index.browser.d.ts +0 -0
  248. /package/dist/{virtual-file → types/virtual-file}/index.d.ts +0 -0
  249. /package/dist/{virtual-file → types/virtual-file}/toVirtualFile.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [0.35.0-flask.1]
10
+ ### Added
11
+ - Add `snap_manageAccounts` RPC method ([#1290](https://github.com/MetaMask/snaps/pull/1290))
12
+
13
+ ### Changed
14
+ - **BREAKING:** Build packages as both CJS and ESM ([#1519](https://github.com/MetaMask/snaps/pull/1519), ([#1532](https://github.com/MetaMask/snaps/pull/1532)))
15
+ - This is breaking in the sense that imports to `dist/` will now require you to import either `dist/cjs` or `dist/esm`.
16
+ - **BREAKING:** Disallow deriving Ethereum keys ([#1217](https://github.com/MetaMask/snaps/pull/1217))
17
+ - Coin type `60` is now blocked for derivation.
18
+ - Add `sideEffects: false` ([#1486](https://github.com/MetaMask/snaps/pull/1486))
19
+
20
+ ### Removed
21
+ - **BREAKING:** Remove utility functions used for multichain/keyring effort ([#1527](https://github.com/MetaMask/snaps/pull/1527))
22
+
23
+ ### Fixed
24
+ - Improve JSON parsing safety ([#1499](https://github.com/MetaMask/snaps/pull/1499))
25
+ - Fix false positives when post processing code with HTML comment tokens ([#1522](https://github.com/MetaMask/snaps/pull/1522))
26
+ - Fix BIP-32 path validation ([#1506](https://github.com/MetaMask/snaps/pull/1506))
27
+
28
+ ## [0.34.1-flask.1]
29
+ ### Changed
30
+ - No changes this release.
31
+
9
32
  ## [0.34.0-flask.1]
10
33
  ### Changed
11
34
  - Add SVG validation ([#1401](https://github.com/MetaMask/snaps/pull/1401))
@@ -203,7 +226,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
203
226
  ### Added
204
227
  - Initial release ([#410](https://github.com/MetaMask/snaps-monorepo/pull/410), [#421](https://github.com/MetaMask/snaps-monorepo/pull/421))
205
228
 
206
- [Unreleased]: https://github.com/MetaMask/snaps/compare/v0.34.0-flask.1...HEAD
229
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/v0.35.0-flask.1...HEAD
230
+ [0.35.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.1-flask.1...v0.35.0-flask.1
231
+ [0.34.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.0-flask.1...v0.34.1-flask.1
207
232
  [0.34.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.1-flask.1...v0.34.0-flask.1
208
233
  [0.33.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.0-flask.1...v0.33.1-flask.1
209
234
  [0.33.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v0.33.0-flask.1
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Checks if array `a` is equal to array `b`. Note that this does not do a deep
3
+ * equality check. It only checks if the arrays are the same length and if each
4
+ * element in `a` is equal to (`===`) the corresponding element in `b`.
5
+ *
6
+ * @param a - The first array to compare.
7
+ * @param b - The second array to compare.
8
+ * @returns `true` if the arrays are equal, `false` otherwise.
9
+ */ "use strict";
10
+ Object.defineProperty(exports, "__esModule", {
11
+ value: true
12
+ });
13
+ Object.defineProperty(exports, "isEqual", {
14
+ enumerable: true,
15
+ get: function() {
16
+ return isEqual;
17
+ }
18
+ });
19
+ function isEqual(a, b) {
20
+ return a.length === b.length && a.every((value, index)=>value === b[index]);
21
+ }
22
+
23
+ //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/array.ts"],"sourcesContent":["/**\n * Checks if array `a` is equal to array `b`. Note that this does not do a deep\n * equality check. It only checks if the arrays are the same length and if each\n * element in `a` is equal to (`===`) the corresponding element in `b`.\n *\n * @param a - The first array to compare.\n * @param b - The second array to compare.\n * @returns `true` if the arrays are equal, `false` otherwise.\n */\nexport function isEqual(a: unknown[], b: unknown[]): boolean {\n return a.length === b.length && a.every((value, index) => value === b[index]);\n}\n"],"names":["isEqual","a","b","length","every","value","index"],"mappings":"AAAA;;;;;;;;CAQC;;;;+BACeA;;;eAAAA;;;AAAT,SAASA,QAAQC,CAAY,EAAEC,CAAY;IAChD,OAAOD,EAAEE,MAAM,KAAKD,EAAEC,MAAM,IAAIF,EAAEG,KAAK,CAAC,CAACC,OAAOC,QAAUD,UAAUH,CAAC,CAACI,MAAM;AAC9E"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "SnapCaveatType", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return SnapCaveatType;
9
+ }
10
+ });
11
+ var SnapCaveatType;
12
+ (function(SnapCaveatType) {
13
+ SnapCaveatType[/**
14
+ * Permitted derivation paths, used by `snap_getBip32Entropy`.
15
+ */ "PermittedDerivationPaths"] = 'permittedDerivationPaths';
16
+ SnapCaveatType[/**
17
+ * Permitted coin types, used by `snap_getBip44Entropy`.
18
+ */ "PermittedCoinTypes"] = 'permittedCoinTypes';
19
+ SnapCaveatType[/**
20
+ * Caveat specifying a snap cronjob.
21
+ */ "SnapCronjob"] = 'snapCronjob';
22
+ SnapCaveatType[/**
23
+ * Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.
24
+ */ "TransactionOrigin"] = 'transactionOrigin';
25
+ SnapCaveatType[/**
26
+ * The origins that a Snap can receive JSON-RPC messages from.
27
+ */ "RpcOrigin"] = 'rpcOrigin';
28
+ SnapCaveatType[/**
29
+ * Caveat specifying the snap IDs that can be interacted with.
30
+ */ "SnapIds"] = 'snapIds';
31
+ })(SnapCaveatType || (SnapCaveatType = {}));
32
+
33
+ //# sourceMappingURL=caveats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/caveats.ts"],"sourcesContent":["export enum SnapCaveatType {\n /**\n * Permitted derivation paths, used by `snap_getBip32Entropy`.\n */\n PermittedDerivationPaths = 'permittedDerivationPaths',\n\n /**\n * Permitted coin types, used by `snap_getBip44Entropy`.\n */\n PermittedCoinTypes = 'permittedCoinTypes',\n\n /**\n * Caveat specifying a snap cronjob.\n */\n SnapCronjob = 'snapCronjob',\n\n /**\n * Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.\n */\n TransactionOrigin = 'transactionOrigin',\n\n /**\n * The origins that a Snap can receive JSON-RPC messages from.\n */\n RpcOrigin = 'rpcOrigin',\n\n /**\n * Caveat specifying the snap IDs that can be interacted with.\n */\n SnapIds = 'snapIds',\n}\n"],"names":["SnapCaveatType","PermittedDerivationPaths","PermittedCoinTypes","SnapCronjob","TransactionOrigin","RpcOrigin","SnapIds"],"mappings":";;;;;;;;;;IAAO;UAAKA,cAAc;IAAdA,eACV;;GAEC,GACDC,8BAA2B;IAJjBD,eAMV;;GAEC,GACDE,wBAAqB;IATXF,eAWV;;GAEC,GACDG,iBAAc;IAdJH,eAgBV;;GAEC,GACDI,uBAAoB;IAnBVJ,eAqBV;;GAEC,GACDK,eAAY;IAxBFL,eA0BV;;GAEC,GACDM,aAAU;GA7BAN,mBAAAA"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ checksum: function() {
13
+ return checksum;
14
+ },
15
+ checksumFiles: function() {
16
+ return checksumFiles;
17
+ }
18
+ });
19
+ const _utils = require("@metamask/utils");
20
+ const _sha256 = require("@noble/hashes/sha256");
21
+ const _VirtualFile = require("./virtual-file/VirtualFile");
22
+ function checksum(bytes) {
23
+ const value = bytes instanceof _VirtualFile.VirtualFile ? bytes.value : bytes;
24
+ return (0, _sha256.sha256)(value);
25
+ }
26
+ function checksumFiles(files) {
27
+ return checksum((0, _utils.concatBytes)([
28
+ ...files
29
+ ].sort((a, b)=>{
30
+ (0, _utils.assert)(a.path !== b.path, 'Tried to sort files with non-unique paths.');
31
+ if (a.path < b.path) {
32
+ return -1;
33
+ }
34
+ return 1;
35
+ }).map((file)=>checksum(file))));
36
+ }
37
+
38
+ //# sourceMappingURL=checksum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/checksum.ts"],"sourcesContent":["import { assert, concatBytes } from '@metamask/utils';\nimport { sha256 } from '@noble/hashes/sha256';\n\nimport { VirtualFile } from './virtual-file/VirtualFile';\n\n/**\n * Calculates checksum for a single byte array.\n *\n * @param bytes - The byte array to calculate the checksum for.\n * @returns A single sha-256 checksum.\n */\nexport function checksum(bytes: VirtualFile | Uint8Array | string): Uint8Array {\n const value = bytes instanceof VirtualFile ? bytes.value : bytes;\n return sha256(value);\n}\n\n/**\n * Calculates checksum over multiple files in a reproducible way.\n *\n * 1. Sort all the files by their paths.\n * 2. Calculate sha-256 checksum of each file separately.\n * 3. Concatenate all the checksums into one buffer and sha-256 that buffer.\n *\n * The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.\n *\n * @param files - The files over which to calculate the checksum.\n * @returns A single sha-256 checksum.\n */\nexport function checksumFiles(files: VirtualFile[]) {\n return checksum(\n concatBytes(\n [...files]\n .sort((a, b) => {\n assert(\n a.path !== b.path,\n 'Tried to sort files with non-unique paths.',\n );\n if (a.path < b.path) {\n return -1;\n }\n return 1;\n })\n .map((file) => checksum(file)),\n ),\n );\n}\n"],"names":["checksum","checksumFiles","bytes","value","VirtualFile","sha256","files","concatBytes","sort","a","b","assert","path","map","file"],"mappings":";;;;;;;;;;;IAWgBA,QAAQ;eAARA;;IAiBAC,aAAa;eAAbA;;;uBA5BoB;wBACb;6BAEK;AAQrB,SAASD,SAASE,KAAwC;IAC/D,MAAMC,QAAQD,iBAAiBE,wBAAW,GAAGF,MAAMC,KAAK,GAAGD;IAC3D,OAAOG,IAAAA,cAAM,EAACF;AAChB;AAcO,SAASF,cAAcK,KAAoB;IAChD,OAAON,SACLO,IAAAA,kBAAW,EACT;WAAID;KAAM,CACPE,IAAI,CAAC,CAACC,GAAGC;QACRC,IAAAA,aAAM,EACJF,EAAEG,IAAI,KAAKF,EAAEE,IAAI,EACjB;QAEF,IAAIH,EAAEG,IAAI,GAAGF,EAAEE,IAAI,EAAE;YACnB,OAAO,CAAC;QACV;QACA,OAAO;IACT,GACCC,GAAG,CAAC,CAACC,OAASd,SAASc;AAGhC"}
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ CronjobRpcRequestStruct: function() {
13
+ return CronjobRpcRequestStruct;
14
+ },
15
+ CronExpressionStruct: function() {
16
+ return CronExpressionStruct;
17
+ },
18
+ parseCronExpression: function() {
19
+ return parseCronExpression;
20
+ },
21
+ CronjobSpecificationStruct: function() {
22
+ return CronjobSpecificationStruct;
23
+ },
24
+ isCronjobSpecification: function() {
25
+ return isCronjobSpecification;
26
+ },
27
+ CronjobSpecificationArrayStruct: function() {
28
+ return CronjobSpecificationArrayStruct;
29
+ },
30
+ isCronjobSpecificationArray: function() {
31
+ return isCronjobSpecificationArray;
32
+ }
33
+ });
34
+ const _utils = require("@metamask/utils");
35
+ const _cronparser = require("cron-parser");
36
+ const _superstruct = require("superstruct");
37
+ const CronjobRpcRequestStruct = (0, _superstruct.assign)((0, _superstruct.partial)((0, _superstruct.pick)(_utils.JsonRpcRequestStruct, [
38
+ 'id',
39
+ 'jsonrpc'
40
+ ])), (0, _superstruct.omit)(_utils.JsonRpcRequestStruct, [
41
+ 'id',
42
+ 'jsonrpc'
43
+ ]));
44
+ const CronExpressionStruct = (0, _superstruct.refine)((0, _superstruct.coerce)((0, _superstruct.string)(), (0, _superstruct.object)({
45
+ minute: (0, _superstruct.optional)((0, _superstruct.string)()),
46
+ hour: (0, _superstruct.optional)((0, _superstruct.string)()),
47
+ dayOfMonth: (0, _superstruct.optional)((0, _superstruct.string)()),
48
+ month: (0, _superstruct.optional)((0, _superstruct.string)()),
49
+ dayOfWeek: (0, _superstruct.optional)((0, _superstruct.string)())
50
+ }), (value)=>`${value.minute ?? '*'} ${value.hour ?? '*'} ${value.dayOfMonth ?? '*'} ${value.month ?? '*'} ${value.dayOfWeek ?? '*'}`), 'CronExpression', (value)=>{
51
+ try {
52
+ (0, _cronparser.parseExpression)(value);
53
+ return true;
54
+ } catch {
55
+ return false;
56
+ }
57
+ });
58
+ function parseCronExpression(expression) {
59
+ const ensureStringExpression = (0, _superstruct.create)(expression, CronExpressionStruct);
60
+ return (0, _cronparser.parseExpression)(ensureStringExpression);
61
+ }
62
+ const CronjobSpecificationStruct = (0, _superstruct.object)({
63
+ expression: CronExpressionStruct,
64
+ request: CronjobRpcRequestStruct
65
+ });
66
+ function isCronjobSpecification(value) {
67
+ try {
68
+ (0, _superstruct.create)(value, CronjobSpecificationStruct);
69
+ return true;
70
+ } catch {
71
+ return false;
72
+ }
73
+ }
74
+ const CronjobSpecificationArrayStruct = (0, _superstruct.array)(CronjobSpecificationStruct);
75
+ function isCronjobSpecificationArray(value) {
76
+ try {
77
+ (0, _superstruct.create)(value, CronjobSpecificationArrayStruct);
78
+ return true;
79
+ } catch {
80
+ return false;
81
+ }
82
+ }
83
+
84
+ //# sourceMappingURL=cronjob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/cronjob.ts"],"sourcesContent":["import { JsonRpcRequestStruct } from '@metamask/utils';\nimport { parseExpression } from 'cron-parser';\nimport {\n array,\n assign,\n coerce,\n create,\n Infer,\n object,\n omit,\n optional,\n partial,\n pick,\n refine,\n string,\n} from 'superstruct';\n\nexport const CronjobRpcRequestStruct = assign(\n partial(pick(JsonRpcRequestStruct, ['id', 'jsonrpc'])),\n omit(JsonRpcRequestStruct, ['id', 'jsonrpc']),\n);\nexport type CronjobRpcRequest = Infer<typeof CronjobRpcRequestStruct>;\n\nexport const CronExpressionStruct = refine(\n coerce(\n string(),\n object({\n minute: optional(string()),\n hour: optional(string()),\n dayOfMonth: optional(string()),\n month: optional(string()),\n dayOfWeek: optional(string()),\n }),\n (value) =>\n `${value.minute ?? '*'} ${value.hour ?? '*'} ${value.dayOfMonth ?? '*'} ${\n value.month ?? '*'\n } ${value.dayOfWeek ?? '*'}`,\n ),\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"],"names":["CronjobRpcRequestStruct","CronExpressionStruct","parseCronExpression","CronjobSpecificationStruct","isCronjobSpecification","CronjobSpecificationArrayStruct","isCronjobSpecificationArray","assign","partial","pick","JsonRpcRequestStruct","omit","refine","coerce","string","object","minute","optional","hour","dayOfMonth","month","dayOfWeek","value","parseExpression","expression","ensureStringExpression","create","request","array"],"mappings":";;;;;;;;;;;IAiBaA,uBAAuB;eAAvBA;;IAMAC,oBAAoB;eAApBA;;IAkCGC,mBAAmB;eAAnBA;;IAKHC,0BAA0B;eAA1BA;;IAYGC,sBAAsB;eAAtBA;;IASHC,+BAA+B;eAA/BA;;IAUGC,2BAA2B;eAA3BA;;;uBA7FqB;4BACL;6BAczB;AAEA,MAAMN,0BAA0BO,IAAAA,mBAAM,EAC3CC,IAAAA,oBAAO,EAACC,IAAAA,iBAAI,EAACC,2BAAoB,EAAE;IAAC;IAAM;CAAU,IACpDC,IAAAA,iBAAI,EAACD,2BAAoB,EAAE;IAAC;IAAM;CAAU;AAIvC,MAAMT,uBAAuBW,IAAAA,mBAAM,EACxCC,IAAAA,mBAAM,EACJC,IAAAA,mBAAM,KACNC,IAAAA,mBAAM,EAAC;IACLC,QAAQC,IAAAA,qBAAQ,EAACH,IAAAA,mBAAM;IACvBI,MAAMD,IAAAA,qBAAQ,EAACH,IAAAA,mBAAM;IACrBK,YAAYF,IAAAA,qBAAQ,EAACH,IAAAA,mBAAM;IAC3BM,OAAOH,IAAAA,qBAAQ,EAACH,IAAAA,mBAAM;IACtBO,WAAWJ,IAAAA,qBAAQ,EAACH,IAAAA,mBAAM;AAC5B,IACA,CAACQ,QACC,CAAC,EAAEA,MAAMN,MAAM,IAAI,IAAI,CAAC,EAAEM,MAAMJ,IAAI,IAAI,IAAI,CAAC,EAAEI,MAAMH,UAAU,IAAI,IAAI,CAAC,EACtEG,MAAMF,KAAK,IAAI,IAChB,CAAC,EAAEE,MAAMD,SAAS,IAAI,IAAI,CAAC,GAEhC,kBACA,CAACC;IACC,IAAI;QACFC,IAAAA,2BAAe,EAACD;QAChB,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAWK,SAASpB,oBAAoBsB,UAA2B;IAC7D,MAAMC,yBAAyBC,IAAAA,mBAAM,EAACF,YAAYvB;IAClD,OAAOsB,IAAAA,2BAAe,EAACE;AACzB;AAEO,MAAMtB,6BAA6BY,IAAAA,mBAAM,EAAC;IAC/CS,YAAYvB;IACZ0B,SAAS3B;AACX;AASO,SAASI,uBAAuBkB,KAAc;IACnD,IAAI;QACFI,IAAAA,mBAAM,EAACJ,OAAOnB;QACd,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF;AAEO,MAAME,kCAAkCuB,IAAAA,kBAAK,EAClDzB;AASK,SAASG,4BAA4BgB,KAAc;IACxD,IAAI;QACFI,IAAAA,mBAAM,EAACJ,OAAOjB;QACd,OAAO;IACT,EAAE,OAAM;QACN,OAAO;IACT;AACF"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "deepClone", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return deepClone;
9
+ }
10
+ });
11
+ const _rfdc = /*#__PURE__*/ _interop_require_default(require("rfdc"));
12
+ function _interop_require_default(obj) {
13
+ return obj && obj.__esModule ? obj : {
14
+ default: obj
15
+ };
16
+ }
17
+ const deepClone = (0, _rfdc.default)({
18
+ proto: false,
19
+ circles: false
20
+ });
21
+
22
+ //# sourceMappingURL=deep-clone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/deep-clone.ts"],"sourcesContent":["import rfdc from 'rfdc';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n"],"names":["deepClone","rfdc","proto","circles"],"mappings":";;;;+BAEaA;;;eAAAA;;;6DAFI;;;;;;AAEV,MAAMA,YAAYC,IAAAA,aAAI,EAAC;IAAEC,OAAO;IAAOC,SAAS;AAAM"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Global JavaScript APIs exposed by default to all snaps.
3
+ */ "use strict";
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "DEFAULT_ENDOWMENTS", {
8
+ enumerable: true,
9
+ get: function() {
10
+ return DEFAULT_ENDOWMENTS;
11
+ }
12
+ });
13
+ const DEFAULT_ENDOWMENTS = Object.freeze([
14
+ 'atob',
15
+ 'btoa',
16
+ 'BigInt',
17
+ 'console',
18
+ 'crypto',
19
+ 'Date',
20
+ 'Math',
21
+ 'setTimeout',
22
+ 'clearTimeout',
23
+ 'SubtleCrypto',
24
+ 'TextDecoder',
25
+ 'TextEncoder',
26
+ 'URL',
27
+ 'setInterval',
28
+ 'clearInterval',
29
+ 'Int8Array',
30
+ 'Uint8Array',
31
+ 'Uint8ClampedArray',
32
+ 'Int16Array',
33
+ 'Uint16Array',
34
+ 'Int32Array',
35
+ 'Uint32Array',
36
+ 'Float32Array',
37
+ 'Float64Array',
38
+ 'BigInt64Array',
39
+ 'BigUint64Array',
40
+ 'DataView',
41
+ 'ArrayBuffer',
42
+ // Used by fetch, but also as API for some packages that don't do network connections
43
+ // https://github.com/MetaMask/snaps-monorepo/issues/662
44
+ // https://github.com/MetaMask/snaps-monorepo/discussions/678
45
+ 'AbortController',
46
+ 'AbortSignal'
47
+ ]);
48
+
49
+ //# sourceMappingURL=default-endowments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/default-endowments.ts"],"sourcesContent":["/**\n * Global JavaScript APIs exposed by default to all snaps.\n */\nexport const DEFAULT_ENDOWMENTS: readonly string[] = Object.freeze([\n 'atob',\n 'btoa',\n 'BigInt',\n 'console',\n 'crypto',\n 'Date',\n 'Math',\n 'setTimeout',\n 'clearTimeout',\n 'SubtleCrypto',\n 'TextDecoder',\n 'TextEncoder',\n 'URL',\n 'setInterval',\n 'clearInterval',\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n 'ArrayBuffer',\n // Used by fetch, but also as API for some packages that don't do network connections\n // https://github.com/MetaMask/snaps-monorepo/issues/662\n // https://github.com/MetaMask/snaps-monorepo/discussions/678\n 'AbortController',\n 'AbortSignal',\n]);\n"],"names":["DEFAULT_ENDOWMENTS","Object","freeze"],"mappings":"AAAA;;CAEC;;;;+BACYA;;;eAAAA;;;AAAN,MAAMA,qBAAwCC,OAAOC,MAAM,CAAC;IACjE;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,qFAAqF;IACrF,wDAAwD;IACxD,6DAA6D;IAC7D;IACA;CACD"}
@@ -0,0 +1,23 @@
1
+ // 0xd36e6170 - 0x80000000
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ function _export(target, all) {
7
+ for(var name in all)Object.defineProperty(target, name, {
8
+ enumerable: true,
9
+ get: all[name]
10
+ });
11
+ }
12
+ _export(exports, {
13
+ SIP_6_MAGIC_VALUE: function() {
14
+ return SIP_6_MAGIC_VALUE;
15
+ },
16
+ STATE_ENCRYPTION_MAGIC_VALUE: function() {
17
+ return STATE_ENCRYPTION_MAGIC_VALUE;
18
+ }
19
+ });
20
+ const SIP_6_MAGIC_VALUE = `1399742832'`;
21
+ const STATE_ENCRYPTION_MAGIC_VALUE = `572232532'`;
22
+
23
+ //# sourceMappingURL=entropy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/entropy.ts"],"sourcesContent":["// 0xd36e6170 - 0x80000000\nexport const SIP_6_MAGIC_VALUE = `1399742832'` as `${number}'`;\n\n// `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`\nexport const STATE_ENCRYPTION_MAGIC_VALUE = `572232532'` as `${number}'`;\n\nexport type MagicValue =\n | typeof SIP_6_MAGIC_VALUE\n | typeof STATE_ENCRYPTION_MAGIC_VALUE;\n"],"names":["SIP_6_MAGIC_VALUE","STATE_ENCRYPTION_MAGIC_VALUE"],"mappings":"AAAA,0BAA0B;;;;;;;;;;;;IACbA,iBAAiB;eAAjBA;;IAGAC,4BAA4B;eAA5BA;;;AAHN,MAAMD,oBAAoB,CAAC,WAAW,CAAC;AAGvC,MAAMC,+BAA+B,CAAC,UAAU,CAAC"}
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "enumValue", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return enumValue;
9
+ }
10
+ });
11
+ const _superstruct = require("superstruct");
12
+ function enumValue(constant) {
13
+ return (0, _superstruct.literal)(constant);
14
+ }
15
+
16
+ //# sourceMappingURL=enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/enum.ts"],"sourcesContent":["import { literal, Struct } from 'superstruct';\n\n/**\n * Get the enum values as union type. This allows using both the enum string\n * values and the enum itself as values.\n *\n * Note: This only works for string enums.\n *\n * @example\n * ```typescript\n * enum Foo {\n * Bar = 'bar',\n * Baz = 'baz',\n * }\n *\n * type FooValue = EnumToUnion<Foo>;\n * // FooValue is 'bar' | 'baz'\n *\n * const foo: FooValue = Foo.Bar; // Works\n * const foo: FooValue = 'bar'; // Also works\n * ```\n */\nexport type EnumToUnion<Type extends string> = `${Type}`;\n\n/**\n * Superstruct struct for validating an enum value. This allows using both the\n * enum string values and the enum itself as values.\n *\n * @param constant - The enum to validate against.\n * @returns The superstruct struct.\n */\nexport function enumValue<Type extends string>(\n constant: Type,\n): Struct<EnumToUnion<Type>, EnumToUnion<Type>> {\n return literal(constant as EnumToUnion<Type>);\n}\n"],"names":["enumValue","constant","literal"],"mappings":";;;;+BA+BgBA;;;eAAAA;;;6BA/BgB;AA+BzB,SAASA,UACdC,QAAc;IAEd,OAAOC,IAAAA,oBAAO,EAACD;AACjB"}
@@ -1,23 +1,22 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
1
  // eslint-disable-next-line import/no-unassigned-import
2
+ "use strict";
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
4
6
  require("ses/lockdown");
5
- const fs_1 = require("fs");
6
- const mock_1 = require("./mock");
7
- const types_1 = require("./types");
7
+ const _fs = require("fs");
8
+ const _mock = require("./mock");
9
+ const _types = require("./types");
8
10
  lockdown({
9
11
  consoleTaming: 'unsafe',
10
12
  errorTaming: 'unsafe',
11
13
  mathTaming: 'unsafe',
12
14
  dateTaming: 'unsafe',
13
15
  overrideTaming: 'severe',
14
- // TODO: See if there's an easier way to do this. This file is ran in a
15
- // separate process, so we can't mock SES with Jest.
16
- ...(process.env.NODE_ENV === 'test'
17
- ? {
18
- domainTaming: 'unsafe',
19
- }
20
- : {}),
16
+ // We disable domain taming, because it does not work in certain cases when
17
+ // running tests. This is unlikely to be a problem in production, because
18
+ // Node.js domains are deprecated.
19
+ domainTaming: 'unsafe'
21
20
  });
22
21
  /**
23
22
  * Get mock endowments that don't do anything. This is useful for running the
@@ -25,26 +24,28 @@ lockdown({
25
24
  * for example.
26
25
  *
27
26
  * @returns The mock endowments.
28
- */
29
- function getMockEndowments() {
30
- const endowments = (0, mock_1.generateMockEndowments)();
27
+ */ function getMockEndowments() {
28
+ const endowments = (0, _mock.generateMockEndowments)();
31
29
  return {
32
30
  ...endowments,
33
31
  window: endowments,
34
- self: endowments,
32
+ self: endowments
35
33
  };
36
34
  }
37
35
  const snapFilePath = process.argv[2];
38
- const snapModule = { exports: {} };
36
+ const snapModule = {
37
+ exports: {}
38
+ };
39
39
  new Compartment({
40
40
  ...getMockEndowments(),
41
41
  module: snapModule,
42
- exports: snapModule.exports,
43
- }).evaluate((0, fs_1.readFileSync)(snapFilePath, 'utf8'));
44
- const invalidExports = Object.keys(snapModule.exports).filter((snapExport) => !types_1.SNAP_EXPORT_NAMES.includes(snapExport));
42
+ exports: snapModule.exports
43
+ }).evaluate((0, _fs.readFileSync)(snapFilePath, 'utf8'));
44
+ const invalidExports = Object.keys(snapModule.exports).filter((snapExport)=>!_types.SNAP_EXPORT_NAMES.includes(snapExport));
45
45
  if (invalidExports.length > 0) {
46
46
  // eslint-disable-next-line no-console
47
47
  console.warn(`Invalid snap exports detected:\n${invalidExports.join('\n')}`);
48
48
  }
49
- setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
49
+ setTimeout(()=>process.exit(0), 1000); // Hack to ensure worker exits
50
+
50
51
  //# sourceMappingURL=eval-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/eval-worker.ts"],"sourcesContent":["// eslint-disable-next-line import/no-unassigned-import\nimport 'ses/lockdown';\n\nimport { readFileSync } from 'fs';\n\nimport { generateMockEndowments } from './mock';\nimport { HandlerType, SNAP_EXPORT_NAMES } from './types';\n\ndeclare let lockdown: any, Compartment: any;\n\nlockdown({\n consoleTaming: 'unsafe',\n errorTaming: 'unsafe',\n mathTaming: 'unsafe',\n dateTaming: 'unsafe',\n overrideTaming: 'severe',\n\n // We disable domain taming, because it does not work in certain cases when\n // running tests. This is unlikely to be a problem in production, because\n // Node.js domains are deprecated.\n domainTaming: 'unsafe',\n});\n\n/**\n * Get mock endowments that don't do anything. This is useful for running the\n * eval, for snaps that try to communicate with the extension on initialisation,\n * for example.\n *\n * @returns The mock endowments.\n */\nfunction getMockEndowments() {\n const endowments = generateMockEndowments();\n return {\n ...endowments,\n window: endowments,\n self: endowments,\n };\n}\n\nconst snapFilePath = process.argv[2];\n\nconst snapModule: { exports?: any } = { exports: {} };\n\nnew Compartment({\n ...getMockEndowments(),\n module: snapModule,\n exports: snapModule.exports,\n}).evaluate(readFileSync(snapFilePath, 'utf8'));\n\nconst invalidExports = Object.keys(snapModule.exports).filter(\n (snapExport) => !SNAP_EXPORT_NAMES.includes(snapExport as HandlerType),\n);\n\nif (invalidExports.length > 0) {\n // eslint-disable-next-line no-console\n console.warn(`Invalid snap exports detected:\\n${invalidExports.join('\\n')}`);\n}\n\nsetTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits\n"],"names":["lockdown","consoleTaming","errorTaming","mathTaming","dateTaming","overrideTaming","domainTaming","getMockEndowments","endowments","generateMockEndowments","window","self","snapFilePath","process","argv","snapModule","exports","Compartment","module","evaluate","readFileSync","invalidExports","Object","keys","filter","snapExport","SNAP_EXPORT_NAMES","includes","length","console","warn","join","setTimeout","exit"],"mappings":"AAAA,uDAAuD;;;;;QAChD;oBAEsB;sBAEU;uBACQ;AAI/CA,SAAS;IACPC,eAAe;IACfC,aAAa;IACbC,YAAY;IACZC,YAAY;IACZC,gBAAgB;IAEhB,2EAA2E;IAC3E,yEAAyE;IACzE,kCAAkC;IAClCC,cAAc;AAChB;AAEA;;;;;;CAMC,GACD,SAASC;IACP,MAAMC,aAAaC,IAAAA,4BAAsB;IACzC,OAAO;QACL,GAAGD,UAAU;QACbE,QAAQF;QACRG,MAAMH;IACR;AACF;AAEA,MAAMI,eAAeC,QAAQC,IAAI,CAAC,EAAE;AAEpC,MAAMC,aAAgC;IAAEC,SAAS,CAAC;AAAE;AAEpD,IAAIC,YAAY;IACd,GAAGV,mBAAmB;IACtBW,QAAQH;IACRC,SAASD,WAAWC,OAAO;AAC7B,GAAGG,QAAQ,CAACC,IAAAA,gBAAY,EAACR,cAAc;AAEvC,MAAMS,iBAAiBC,OAAOC,IAAI,CAACR,WAAWC,OAAO,EAAEQ,MAAM,CAC3D,CAACC,aAAe,CAACC,wBAAiB,CAACC,QAAQ,CAACF;AAG9C,IAAIJ,eAAeO,MAAM,GAAG,GAAG;IAC7B,sCAAsC;IACtCC,QAAQC,IAAI,CAAC,CAAC,gCAAgC,EAAET,eAAeU,IAAI,CAAC,MAAM,CAAC;AAC7E;AAEAC,WAAW,IAAMnB,QAAQoB,IAAI,CAAC,IAAI,OAAO,8BAA8B"}
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "evalBundle", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return evalBundle;
9
+ }
10
+ });
11
+ const _child_process = require("child_process");
12
+ const _path = require("path");
13
+ const _fs = require("./fs");
14
+ async function evalBundle(bundlePath) {
15
+ await (0, _fs.validateFilePath)(bundlePath);
16
+ return new Promise((resolve, reject)=>{
17
+ const worker = (0, _child_process.fork)((0, _path.join)(__dirname, 'eval-worker.js'), [
18
+ bundlePath
19
+ ]);
20
+ worker.on('exit', (exitCode)=>{
21
+ if (exitCode === 0) {
22
+ return resolve(null);
23
+ }
24
+ return reject(new Error(`Process exited with non-zero exit code: ${exitCode}`));
25
+ });
26
+ });
27
+ }
28
+
29
+ //# sourceMappingURL=eval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/eval.ts"],"sourcesContent":["import { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\n/**\n * Spawn a new process to run the provided bundle in.\n *\n * @param bundlePath - The path to the bundle to run.\n * @returns `null` if the worker ran successfully.\n * @throws If the worker failed to run successfully.\n */\nexport async function evalBundle(bundlePath: string): Promise<null> {\n await validateFilePath(bundlePath);\n\n return new Promise((resolve, reject) => {\n const worker = fork(join(__dirname, 'eval-worker.js'), [bundlePath]);\n\n worker.on('exit', (exitCode: number) => {\n if (exitCode === 0) {\n return resolve(null);\n }\n\n return reject(\n new Error(`Process exited with non-zero exit code: ${exitCode}`),\n );\n });\n });\n}\n"],"names":["evalBundle","bundlePath","validateFilePath","Promise","resolve","reject","worker","fork","join","__dirname","on","exitCode","Error"],"mappings":";;;;+BAYsBA;;;eAAAA;;;+BAZD;sBACA;oBAEY;AAS1B,eAAeA,WAAWC,UAAkB;IACjD,MAAMC,IAAAA,oBAAgB,EAACD;IAEvB,OAAO,IAAIE,QAAQ,CAACC,SAASC;QAC3B,MAAMC,SAASC,IAAAA,mBAAI,EAACC,IAAAA,UAAI,EAACC,WAAW,mBAAmB;YAACR;SAAW;QAEnEK,OAAOI,EAAE,CAAC,QAAQ,CAACC;YACjB,IAAIA,aAAa,GAAG;gBAClB,OAAOP,QAAQ;YACjB;YAEA,OAAOC,OACL,IAAIO,MAAM,CAAC,wCAAwC,EAAED,SAAS,CAAC;QAEnE;IACF;AACF"}
package/dist/cjs/fs.js ADDED
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: all[name]
9
+ });
10
+ }
11
+ _export(exports, {
12
+ isDirectory: function() {
13
+ return isDirectory;
14
+ },
15
+ isFile: function() {
16
+ return isFile;
17
+ },
18
+ readJsonFile: function() {
19
+ return readJsonFile;
20
+ },
21
+ getOutfilePath: function() {
22
+ return getOutfilePath;
23
+ },
24
+ validateOutfileName: function() {
25
+ return validateOutfileName;
26
+ },
27
+ validateFilePath: function() {
28
+ return validateFilePath;
29
+ },
30
+ validateDirPath: function() {
31
+ return validateDirPath;
32
+ },
33
+ useTemporaryFile: function() {
34
+ return useTemporaryFile;
35
+ }
36
+ });
37
+ const _fs = require("fs");
38
+ const _os = /*#__PURE__*/ _interop_require_default(require("os"));
39
+ const _path = /*#__PURE__*/ _interop_require_default(require("path"));
40
+ const _json = require("./json");
41
+ const _virtualfile = require("./virtual-file");
42
+ function _interop_require_default(obj) {
43
+ return obj && obj.__esModule ? obj : {
44
+ default: obj
45
+ };
46
+ }
47
+ async function isDirectory(pathString, createDir) {
48
+ try {
49
+ const stats = await _fs.promises.stat(pathString);
50
+ return stats.isDirectory();
51
+ } catch (error) {
52
+ if (error.code === 'ENOENT') {
53
+ if (!createDir) {
54
+ return false;
55
+ }
56
+ await _fs.promises.mkdir(pathString, {
57
+ recursive: true
58
+ });
59
+ return true;
60
+ }
61
+ return false;
62
+ }
63
+ }
64
+ async function isFile(pathString) {
65
+ try {
66
+ const stats = await _fs.promises.stat(pathString);
67
+ return stats.isFile();
68
+ } catch (error) {
69
+ return false;
70
+ }
71
+ }
72
+ async function readJsonFile(pathString) {
73
+ if (!pathString.endsWith('.json')) {
74
+ throw new Error('The specified file must be a ".json" file.');
75
+ }
76
+ let file;
77
+ try {
78
+ file = await (0, _virtualfile.readVirtualFile)(pathString, 'utf8');
79
+ } catch (error) {
80
+ if (error.code === 'ENOENT') {
81
+ throw new Error(`Could not find '${pathString}'. Please ensure that the file exists.`);
82
+ }
83
+ throw error;
84
+ }
85
+ file.result = (0, _json.parseJson)(file.toString());
86
+ return file;
87
+ }
88
+ function getOutfilePath(outDir, outFileName) {
89
+ return _path.default.join(outDir, outFileName || 'bundle.js');
90
+ }
91
+ function validateOutfileName(filename) {
92
+ if (!filename.endsWith('.js') || filename === '.js' || _path.default.basename(filename) !== filename) {
93
+ throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);
94
+ }
95
+ return true;
96
+ }
97
+ async function validateFilePath(filePath) {
98
+ const exists = await isFile(filePath);
99
+ if (!exists) {
100
+ throw new Error(`Invalid params: '${filePath}' is not a file or does not exist.`);
101
+ }
102
+ return true;
103
+ }
104
+ async function validateDirPath(dirPath, createDir) {
105
+ const exists = await isDirectory(dirPath, createDir);
106
+ if (!exists) {
107
+ throw new Error(`Invalid params: '${dirPath}' is not a directory or could not be created.`);
108
+ }
109
+ return true;
110
+ }
111
+ async function useTemporaryFile(fileName, fileContents, fn) {
112
+ const filePath = _path.default.join(_os.default.tmpdir(), fileName);
113
+ await _fs.promises.mkdir(_path.default.dirname(filePath), {
114
+ recursive: true
115
+ });
116
+ await _fs.promises.writeFile(filePath, fileContents);
117
+ try {
118
+ await fn(filePath);
119
+ } finally{
120
+ if (await isFile(filePath)) {
121
+ await _fs.promises.unlink(filePath);
122
+ }
123
+ }
124
+ }
125
+
126
+ //# sourceMappingURL=fs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/fs.ts"],"sourcesContent":["import { Json } from '@metamask/utils';\nimport { promises as fs } from 'fs';\nimport os from 'os';\nimport pathUtils from 'path';\n\nimport { parseJson } from './json';\nimport { readVirtualFile, VirtualFile } from './virtual-file';\n\n/**\n * Checks whether the given path string resolves to an existing directory, and\n * optionally creates the directory if it doesn't exist.\n *\n * @param pathString - The path string to check.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns Whether the given path is an existing directory.\n */\nexport async function isDirectory(\n pathString: string,\n createDir: boolean,\n): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isDirectory();\n } catch (error) {\n if (error.code === 'ENOENT') {\n if (!createDir) {\n return false;\n }\n\n await fs.mkdir(pathString, { recursive: true });\n return true;\n }\n\n return false;\n }\n}\n\n/**\n * Checks whether the given path string resolves to an existing file.\n *\n * @param pathString - The path string to check.\n * @returns Whether the given path is an existing file.\n */\nexport async function isFile(pathString: string): Promise<boolean> {\n try {\n const stats = await fs.stat(pathString);\n return stats.isFile();\n } catch (error) {\n return false;\n }\n}\n\n/**\n * Reads a `.json` file, parses its contents, and returns them.\n *\n * @param pathString - The path to the JSON file.\n * @returns The parsed contents of the JSON file.\n */\nexport async function readJsonFile<Type extends Json = Json>(\n pathString: string,\n): Promise<VirtualFile<Type>> {\n if (!pathString.endsWith('.json')) {\n throw new Error('The specified file must be a \".json\" file.');\n }\n\n let file;\n try {\n file = await readVirtualFile(pathString, 'utf8');\n } catch (error) {\n if (error.code === 'ENOENT') {\n throw new Error(\n `Could not find '${pathString}'. Please ensure that the file exists.`,\n );\n }\n\n throw error;\n }\n file.result = parseJson(file.toString());\n return file as VirtualFile<Type>;\n}\n\n/**\n * Gets the complete out file path from an output file name and parent\n * directory path.\n *\n * @param outDir - The path to the out file's parent directory.\n * @param outFileName - The out file's name.\n * @returns The complete path to the out file.\n */\nexport function getOutfilePath(outDir: string, outFileName: string): string {\n return pathUtils.join(outDir, outFileName || 'bundle.js');\n}\n\n/**\n * Ensures that the outfile name is just a `.js` file name.\n * Throws on validation failure.\n *\n * @param filename - The file name to validate.\n * @returns `true` if validation succeeded.\n * @throws If the file name is invalid.\n */\nexport function validateOutfileName(filename: string): boolean {\n if (\n !filename.endsWith('.js') ||\n filename === '.js' ||\n pathUtils.basename(filename) !== filename\n ) {\n throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);\n }\n return true;\n}\n\n/**\n * Validates a file path. Throws on validation failure.\n *\n * @param filePath - The file path to validate.\n * @returns `true` if validation succeeded.\n * @throws If the path does not resolve to a file.\n */\nexport async function validateFilePath(filePath: string): Promise<boolean> {\n const exists = await isFile(filePath);\n if (!exists) {\n throw new Error(\n `Invalid params: '${filePath}' is not a file or does not exist.`,\n );\n }\n return true;\n}\n\n/**\n * Validates a directory path. Throws on validation failure.\n *\n * @param dirPath - The directory path to validate.\n * @param createDir - Whether to create the directory if it doesn't exist.\n * @returns `true` if validation succeeded or the directory was created.\n * @throws If the directory does not exist or could not be created.\n */\nexport async function validateDirPath(\n dirPath: string,\n createDir: boolean,\n): Promise<boolean> {\n const exists = await isDirectory(dirPath, createDir);\n if (!exists) {\n throw new Error(\n `Invalid params: '${dirPath}' is not a directory or could not be created.`,\n );\n }\n return true;\n}\n\n/**\n * Creates a temporary file with a given name and content, writes it to disk and calls the provided function.\n * This function handles deletion of the temporary file after usage.\n *\n * @param fileName - The name of the temporary file.\n * @param fileContents - The content of the temporary file.\n * @param fn - The callback function to call when the temporary file has been created.\n */\nexport async function useTemporaryFile(\n fileName: string,\n fileContents: string,\n fn: (path: string) => Promise<unknown>,\n): Promise<void> {\n const filePath = pathUtils.join(os.tmpdir(), fileName);\n await fs.mkdir(pathUtils.dirname(filePath), { recursive: true });\n await fs.writeFile(filePath, fileContents);\n try {\n await fn(filePath);\n } finally {\n if (await isFile(filePath)) {\n await fs.unlink(filePath);\n }\n }\n}\n"],"names":["isDirectory","isFile","readJsonFile","getOutfilePath","validateOutfileName","validateFilePath","validateDirPath","useTemporaryFile","pathString","createDir","stats","fs","stat","error","code","mkdir","recursive","endsWith","Error","file","readVirtualFile","result","parseJson","toString","outDir","outFileName","pathUtils","join","filename","basename","filePath","exists","dirPath","fileName","fileContents","fn","os","tmpdir","dirname","writeFile","unlink"],"mappings":";;;;;;;;;;;IAgBsBA,WAAW;eAAXA;;IA2BAC,MAAM;eAANA;;IAeAC,YAAY;eAAZA;;IA+BNC,cAAc;eAAdA;;IAYAC,mBAAmB;eAAnBA;;IAkBMC,gBAAgB;eAAhBA;;IAkBAC,eAAe;eAAfA;;IAqBAC,gBAAgB;eAAhBA;;;oBA7JS;2DAChB;6DACO;sBAEI;6BACmB;;;;;;AAUtC,eAAeP,YACpBQ,UAAkB,EAClBC,SAAkB;IAElB,IAAI;QACF,MAAMC,QAAQ,MAAMC,YAAE,CAACC,IAAI,CAACJ;QAC5B,OAAOE,MAAMV,WAAW;IAC1B,EAAE,OAAOa,OAAO;QACd,IAAIA,MAAMC,IAAI,KAAK,UAAU;YAC3B,IAAI,CAACL,WAAW;gBACd,OAAO;YACT;YAEA,MAAME,YAAE,CAACI,KAAK,CAACP,YAAY;gBAAEQ,WAAW;YAAK;YAC7C,OAAO;QACT;QAEA,OAAO;IACT;AACF;AAQO,eAAef,OAAOO,UAAkB;IAC7C,IAAI;QACF,MAAME,QAAQ,MAAMC,YAAE,CAACC,IAAI,CAACJ;QAC5B,OAAOE,MAAMT,MAAM;IACrB,EAAE,OAAOY,OAAO;QACd,OAAO;IACT;AACF;AAQO,eAAeX,aACpBM,UAAkB;IAElB,IAAI,CAACA,WAAWS,QAAQ,CAAC,UAAU;QACjC,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIC;IACJ,IAAI;QACFA,OAAO,MAAMC,IAAAA,4BAAe,EAACZ,YAAY;IAC3C,EAAE,OAAOK,OAAO;QACd,IAAIA,MAAMC,IAAI,KAAK,UAAU;YAC3B,MAAM,IAAII,MACR,CAAC,gBAAgB,EAAEV,WAAW,sCAAsC,CAAC;QAEzE;QAEA,MAAMK;IACR;IACAM,KAAKE,MAAM,GAAGC,IAAAA,eAAS,EAACH,KAAKI,QAAQ;IACrC,OAAOJ;AACT;AAUO,SAAShB,eAAeqB,MAAc,EAAEC,WAAmB;IAChE,OAAOC,aAAS,CAACC,IAAI,CAACH,QAAQC,eAAe;AAC/C;AAUO,SAASrB,oBAAoBwB,QAAgB;IAClD,IACE,CAACA,SAASX,QAAQ,CAAC,UACnBW,aAAa,SACbF,aAAS,CAACG,QAAQ,CAACD,cAAcA,UACjC;QACA,MAAM,IAAIV,MAAM,CAAC,sBAAsB,EAAEU,SAAS,oBAAoB,CAAC;IACzE;IACA,OAAO;AACT;AASO,eAAevB,iBAAiByB,QAAgB;IACrD,MAAMC,SAAS,MAAM9B,OAAO6B;IAC5B,IAAI,CAACC,QAAQ;QACX,MAAM,IAAIb,MACR,CAAC,iBAAiB,EAAEY,SAAS,kCAAkC,CAAC;IAEpE;IACA,OAAO;AACT;AAUO,eAAexB,gBACpB0B,OAAe,EACfvB,SAAkB;IAElB,MAAMsB,SAAS,MAAM/B,YAAYgC,SAASvB;IAC1C,IAAI,CAACsB,QAAQ;QACX,MAAM,IAAIb,MACR,CAAC,iBAAiB,EAAEc,QAAQ,6CAA6C,CAAC;IAE9E;IACA,OAAO;AACT;AAUO,eAAezB,iBACpB0B,QAAgB,EAChBC,YAAoB,EACpBC,EAAsC;IAEtC,MAAML,WAAWJ,aAAS,CAACC,IAAI,CAACS,WAAE,CAACC,MAAM,IAAIJ;IAC7C,MAAMtB,YAAE,CAACI,KAAK,CAACW,aAAS,CAACY,OAAO,CAACR,WAAW;QAAEd,WAAW;IAAK;IAC9D,MAAML,YAAE,CAAC4B,SAAS,CAACT,UAAUI;IAC7B,IAAI;QACF,MAAMC,GAAGL;IACX,SAAU;QACR,IAAI,MAAM7B,OAAO6B,WAAW;YAC1B,MAAMnB,YAAE,CAAC6B,MAAM,CAACV;QAClB;IACF;AACF"}