@metamask/snaps-utils 0.35.0-flask.1 → 1.0.0-prerelease.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 (252) hide show
  1. package/CHANGELOG.md +5 -41
  2. package/dist/{esm/array.js → array.js} +7 -3
  3. package/dist/array.js.map +1 -0
  4. package/dist/{types/caveats.d.ts → caveats.d.ts} +4 -0
  5. package/dist/caveats.js +35 -0
  6. package/dist/caveats.js.map +1 -0
  7. package/dist/checksum.js +42 -0
  8. package/dist/checksum.js.map +1 -0
  9. package/dist/cronjob.js +71 -0
  10. package/dist/cronjob.js.map +1 -0
  11. package/dist/deep-clone.js +9 -0
  12. package/dist/deep-clone.js.map +1 -0
  13. package/dist/{esm/default-endowments.js → default-endowments.js} +6 -3
  14. package/dist/default-endowments.js.map +1 -0
  15. package/dist/entropy.js +8 -0
  16. package/dist/entropy.js.map +1 -0
  17. package/dist/{cjs/eval-worker.js → eval-worker.js} +21 -22
  18. package/dist/eval-worker.js.map +1 -0
  19. package/dist/eval.js +27 -0
  20. package/dist/eval.js.map +1 -0
  21. package/dist/{esm/fs.js → fs.js} +56 -33
  22. package/dist/fs.js.map +1 -0
  23. package/dist/{types/handlers.d.ts → handlers.d.ts} +42 -5
  24. package/dist/handlers.js +3 -0
  25. package/dist/handlers.js.map +1 -0
  26. package/dist/{types/iframe.d.ts → iframe.d.ts} +2 -3
  27. package/dist/{esm/iframe.js → iframe.js} +18 -16
  28. package/dist/iframe.js.map +1 -0
  29. package/dist/iframe.test.browser.js +15 -0
  30. package/dist/iframe.test.browser.js.map +1 -0
  31. package/dist/{types/index.browser.d.ts → index.browser.d.ts} +1 -2
  32. package/dist/index.browser.js +37 -0
  33. package/dist/index.browser.js.map +1 -0
  34. package/dist/{types/index.d.ts → index.d.ts} +1 -2
  35. package/dist/index.executionenv.js +22 -0
  36. package/dist/index.executionenv.js.map +1 -0
  37. package/dist/index.js +42 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/json-rpc.js +46 -0
  40. package/dist/json-rpc.js.map +1 -0
  41. package/dist/json.d.ts +9 -0
  42. package/dist/json.js +18 -0
  43. package/dist/json.js.map +1 -0
  44. package/dist/{esm/logging.js → logging.js} +14 -6
  45. package/dist/logging.js.map +1 -0
  46. package/dist/manifest/index.browser.js +18 -0
  47. package/dist/manifest/index.browser.js.map +1 -0
  48. package/dist/manifest/index.js +19 -0
  49. package/dist/manifest/index.js.map +1 -0
  50. package/dist/{esm/manifest → manifest}/manifest.js +113 -98
  51. package/dist/manifest/manifest.js.map +1 -0
  52. package/dist/{types/manifest → manifest}/validation.d.ts +73 -31
  53. package/dist/manifest/validation.js +141 -0
  54. package/dist/manifest/validation.js.map +1 -0
  55. package/dist/{esm/mock.js → mock.js} +40 -42
  56. package/dist/mock.js.map +1 -0
  57. package/dist/namespace.d.ts +275 -0
  58. package/dist/namespace.js +225 -0
  59. package/dist/namespace.js.map +1 -0
  60. package/dist/notification.d.ts +66 -0
  61. package/dist/notification.js +58 -0
  62. package/dist/notification.js.map +1 -0
  63. package/dist/{types/npm.d.ts → npm.d.ts} +2 -0
  64. package/dist/npm.js +74 -0
  65. package/dist/npm.js.map +1 -0
  66. package/dist/path.js +21 -0
  67. package/dist/path.js.map +1 -0
  68. package/dist/{esm/post-process.js → post-process.js} +99 -110
  69. package/dist/post-process.js.map +1 -0
  70. package/dist/{types/snaps.d.ts → snaps.d.ts} +2 -9
  71. package/dist/snaps.js +202 -0
  72. package/dist/snaps.js.map +1 -0
  73. package/dist/{types/types.d.ts → types.d.ts} +5 -2
  74. package/dist/types.js +103 -0
  75. package/dist/types.js.map +1 -0
  76. package/dist/{esm/versions.js → versions.js} +18 -15
  77. package/dist/versions.js.map +1 -0
  78. package/dist/{esm/virtual-file → virtual-file}/VirtualFile.js +33 -47
  79. package/dist/virtual-file/VirtualFile.js.map +1 -0
  80. package/dist/virtual-file/index.browser.js +18 -0
  81. package/dist/virtual-file/index.browser.js.map +1 -0
  82. package/dist/virtual-file/index.js +19 -0
  83. package/dist/virtual-file/index.js.map +1 -0
  84. package/dist/virtual-file/toVirtualFile.js +30 -0
  85. package/dist/virtual-file/toVirtualFile.js.map +1 -0
  86. package/package.json +32 -61
  87. package/dist/cjs/array.js +0 -23
  88. package/dist/cjs/array.js.map +0 -1
  89. package/dist/cjs/caveats.js +0 -33
  90. package/dist/cjs/caveats.js.map +0 -1
  91. package/dist/cjs/checksum.js +0 -38
  92. package/dist/cjs/checksum.js.map +0 -1
  93. package/dist/cjs/cronjob.js +0 -84
  94. package/dist/cjs/cronjob.js.map +0 -1
  95. package/dist/cjs/deep-clone.js +0 -22
  96. package/dist/cjs/deep-clone.js.map +0 -1
  97. package/dist/cjs/default-endowments.js +0 -49
  98. package/dist/cjs/default-endowments.js.map +0 -1
  99. package/dist/cjs/entropy.js +0 -23
  100. package/dist/cjs/entropy.js.map +0 -1
  101. package/dist/cjs/enum.js +0 -16
  102. package/dist/cjs/enum.js.map +0 -1
  103. package/dist/cjs/eval-worker.js.map +0 -1
  104. package/dist/cjs/eval.js +0 -29
  105. package/dist/cjs/eval.js.map +0 -1
  106. package/dist/cjs/fs.js +0 -126
  107. package/dist/cjs/fs.js.map +0 -1
  108. package/dist/cjs/handlers.js +0 -6
  109. package/dist/cjs/handlers.js.map +0 -1
  110. package/dist/cjs/icon.js +0 -37
  111. package/dist/cjs/icon.js.map +0 -1
  112. package/dist/cjs/iframe.js +0 -59
  113. package/dist/cjs/iframe.js.map +0 -1
  114. package/dist/cjs/index.browser.js +0 -40
  115. package/dist/cjs/index.browser.js.map +0 -1
  116. package/dist/cjs/index.executionenv.js +0 -24
  117. package/dist/cjs/index.executionenv.js.map +0 -1
  118. package/dist/cjs/index.js +0 -45
  119. package/dist/cjs/index.js.map +0 -1
  120. package/dist/cjs/json-rpc.js +0 -46
  121. package/dist/cjs/json-rpc.js.map +0 -1
  122. package/dist/cjs/json.js +0 -16
  123. package/dist/cjs/json.js.map +0 -1
  124. package/dist/cjs/logging.js +0 -40
  125. package/dist/cjs/logging.js.map +0 -1
  126. package/dist/cjs/manifest/index.browser.js +0 -20
  127. package/dist/cjs/manifest/index.browser.js.map +0 -1
  128. package/dist/cjs/manifest/index.js +0 -21
  129. package/dist/cjs/manifest/index.js.map +0 -1
  130. package/dist/cjs/manifest/manifest.js +0 -239
  131. package/dist/cjs/manifest/manifest.js.map +0 -1
  132. package/dist/cjs/manifest/validation.js +0 -183
  133. package/dist/cjs/manifest/validation.js.map +0 -1
  134. package/dist/cjs/mock.js +0 -128
  135. package/dist/cjs/mock.js.map +0 -1
  136. package/dist/cjs/namespace.js +0 -124
  137. package/dist/cjs/namespace.js.map +0 -1
  138. package/dist/cjs/npm.js +0 -81
  139. package/dist/cjs/npm.js.map +0 -1
  140. package/dist/cjs/path.js +0 -21
  141. package/dist/cjs/path.js.map +0 -1
  142. package/dist/cjs/post-process.js +0 -328
  143. package/dist/cjs/post-process.js.map +0 -1
  144. package/dist/cjs/snaps.js +0 -230
  145. package/dist/cjs/snaps.js.map +0 -1
  146. package/dist/cjs/types.js +0 -117
  147. package/dist/cjs/types.js.map +0 -1
  148. package/dist/cjs/validation.js +0 -22
  149. package/dist/cjs/validation.js.map +0 -1
  150. package/dist/cjs/versions.js +0 -47
  151. package/dist/cjs/versions.js.map +0 -1
  152. package/dist/cjs/virtual-file/VirtualFile.js +0 -85
  153. package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
  154. package/dist/cjs/virtual-file/index.browser.js +0 -20
  155. package/dist/cjs/virtual-file/index.browser.js.map +0 -1
  156. package/dist/cjs/virtual-file/index.js +0 -21
  157. package/dist/cjs/virtual-file/index.js.map +0 -1
  158. package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
  159. package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
  160. package/dist/esm/array.js.map +0 -1
  161. package/dist/esm/caveats.js +0 -23
  162. package/dist/esm/caveats.js.map +0 -1
  163. package/dist/esm/checksum.js +0 -36
  164. package/dist/esm/checksum.js.map +0 -1
  165. package/dist/esm/cronjob.js +0 -66
  166. package/dist/esm/cronjob.js.map +0 -1
  167. package/dist/esm/deep-clone.js +0 -7
  168. package/dist/esm/deep-clone.js.map +0 -1
  169. package/dist/esm/default-endowments.js.map +0 -1
  170. package/dist/esm/entropy.js +0 -6
  171. package/dist/esm/entropy.js.map +0 -1
  172. package/dist/esm/enum.js +0 -12
  173. package/dist/esm/enum.js.map +0 -1
  174. package/dist/esm/eval-worker.js +0 -47
  175. package/dist/esm/eval-worker.js.map +0 -1
  176. package/dist/esm/eval.js +0 -25
  177. package/dist/esm/eval.js.map +0 -1
  178. package/dist/esm/fs.js.map +0 -1
  179. package/dist/esm/handlers.js +0 -3
  180. package/dist/esm/handlers.js.map +0 -1
  181. package/dist/esm/icon.js +0 -11
  182. package/dist/esm/icon.js.map +0 -1
  183. package/dist/esm/iframe.js.map +0 -1
  184. package/dist/esm/index.browser.js +0 -23
  185. package/dist/esm/index.browser.js.map +0 -1
  186. package/dist/esm/index.executionenv.js +0 -7
  187. package/dist/esm/index.executionenv.js.map +0 -1
  188. package/dist/esm/index.js +0 -28
  189. package/dist/esm/index.js.map +0 -1
  190. package/dist/esm/json-rpc.js +0 -39
  191. package/dist/esm/json-rpc.js.map +0 -1
  192. package/dist/esm/json.js +0 -17
  193. package/dist/esm/json.js.map +0 -1
  194. package/dist/esm/logging.js.map +0 -1
  195. package/dist/esm/manifest/index.browser.js +0 -3
  196. package/dist/esm/manifest/index.browser.js.map +0 -1
  197. package/dist/esm/manifest/index.js +0 -4
  198. package/dist/esm/manifest/index.js.map +0 -1
  199. package/dist/esm/manifest/manifest.js.map +0 -1
  200. package/dist/esm/manifest/validation.js +0 -152
  201. package/dist/esm/manifest/validation.js.map +0 -1
  202. package/dist/esm/mock.js.map +0 -1
  203. package/dist/esm/namespace.js +0 -110
  204. package/dist/esm/namespace.js.map +0 -1
  205. package/dist/esm/npm.js +0 -70
  206. package/dist/esm/npm.js.map +0 -1
  207. package/dist/esm/path.js +0 -17
  208. package/dist/esm/path.js.map +0 -1
  209. package/dist/esm/post-process.js.map +0 -1
  210. package/dist/esm/snaps.js +0 -215
  211. package/dist/esm/snaps.js.map +0 -1
  212. package/dist/esm/types.js +0 -85
  213. package/dist/esm/types.js.map +0 -1
  214. package/dist/esm/validation.js +0 -17
  215. package/dist/esm/validation.js.map +0 -1
  216. package/dist/esm/versions.js.map +0 -1
  217. package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
  218. package/dist/esm/virtual-file/index.browser.js +0 -3
  219. package/dist/esm/virtual-file/index.browser.js.map +0 -1
  220. package/dist/esm/virtual-file/index.js +0 -4
  221. package/dist/esm/virtual-file/index.js.map +0 -1
  222. package/dist/esm/virtual-file/toVirtualFile.js +0 -26
  223. package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
  224. package/dist/types/enum.d.ts +0 -30
  225. package/dist/types/icon.d.ts +0 -4
  226. package/dist/types/json.d.ts +0 -13
  227. package/dist/types/namespace.d.ts +0 -124
  228. package/dist/types/validation.d.ts +0 -8
  229. /package/dist/{types/array.d.ts → array.d.ts} +0 -0
  230. /package/dist/{types/checksum.d.ts → checksum.d.ts} +0 -0
  231. /package/dist/{types/cronjob.d.ts → cronjob.d.ts} +0 -0
  232. /package/dist/{types/deep-clone.d.ts → deep-clone.d.ts} +0 -0
  233. /package/dist/{types/default-endowments.d.ts → default-endowments.d.ts} +0 -0
  234. /package/dist/{types/entropy.d.ts → entropy.d.ts} +0 -0
  235. /package/dist/{types/eval-worker.d.ts → eval-worker.d.ts} +0 -0
  236. /package/dist/{types/eval.d.ts → eval.d.ts} +0 -0
  237. /package/dist/{types/fs.d.ts → fs.d.ts} +0 -0
  238. /package/dist/{types/iframe.test.browser.d.ts → iframe.test.browser.d.ts} +0 -0
  239. /package/dist/{types/index.executionenv.d.ts → index.executionenv.d.ts} +0 -0
  240. /package/dist/{types/json-rpc.d.ts → json-rpc.d.ts} +0 -0
  241. /package/dist/{types/logging.d.ts → logging.d.ts} +0 -0
  242. /package/dist/{types/manifest → manifest}/index.browser.d.ts +0 -0
  243. /package/dist/{types/manifest → manifest}/index.d.ts +0 -0
  244. /package/dist/{types/manifest → manifest}/manifest.d.ts +0 -0
  245. /package/dist/{types/mock.d.ts → mock.d.ts} +0 -0
  246. /package/dist/{types/path.d.ts → path.d.ts} +0 -0
  247. /package/dist/{types/post-process.d.ts → post-process.d.ts} +0 -0
  248. /package/dist/{types/versions.d.ts → versions.d.ts} +0 -0
  249. /package/dist/{types/virtual-file → virtual-file}/VirtualFile.d.ts +0 -0
  250. /package/dist/{types/virtual-file → virtual-file}/index.browser.d.ts +0 -0
  251. /package/dist/{types/virtual-file → virtual-file}/index.d.ts +0 -0
  252. /package/dist/{types/virtual-file → virtual-file}/toVirtualFile.d.ts +0 -0
package/CHANGELOG.md CHANGED
@@ -6,48 +6,16 @@ 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]
9
+ ## [1.0.0-prerelease.1]
10
10
  ### Added
11
- - Add `snap_manageAccounts` RPC method ([#1290](https://github.com/MetaMask/snaps/pull/1290))
11
+ - Add subject type restrictions to snap-specific permissions ([#1366](https://github.com/MetaMask/snaps/pull/1366))
12
12
 
13
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
14
  - **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))
15
+ - Coin type `60` is now blocked for derivation.
22
16
 
23
17
  ### Fixed
24
18
  - 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
-
32
- ## [0.34.0-flask.1]
33
- ### Changed
34
- - Add SVG validation ([#1401](https://github.com/MetaMask/snaps/pull/1401))
35
- - Make handler types generic, allowing them to be changed ([#1409](https://github.com/MetaMask/snaps/pull/1409))
36
- - Allow use of `$schema` in manifest files ([#1389](https://github.com/MetaMask/snaps/pull/1389))
37
-
38
- ## [0.33.1-flask.1]
39
- ### Changed
40
- - No changes this release.
41
-
42
- ## [0.33.0-flask.1]
43
- ### Changed
44
- - **BREAKING:** Added `snapIds` caveat mapper ([#1360](https://github.com/MetaMask/snaps-monorepo/pull/1360))
45
- - Snap dependencies must be specified in a simplified manner. See the PR for an example.
46
- - Add subject type restrictions to snap-specific permissions ([#1366](https://github.com/MetaMask/snaps-monorepo/pull/1366))
47
- - Add Web Worker support for snap execution ([#1320](https://github.com/MetaMask/snaps-monorepo/pull/1320))
48
-
49
- ### Fixed
50
- - Add `WebAssembly` to eval mock ([#1359](https://github.com/MetaMask/snaps-monorepo/pull/1359))
51
19
 
52
20
  ## [0.32.2]
53
21
  ### Changed
@@ -226,12 +194,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
226
194
  ### Added
227
195
  - Initial release ([#410](https://github.com/MetaMask/snaps-monorepo/pull/410), [#421](https://github.com/MetaMask/snaps-monorepo/pull/421))
228
196
 
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
232
- [0.34.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.1-flask.1...v0.34.0-flask.1
233
- [0.33.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.0-flask.1...v0.33.1-flask.1
234
- [0.33.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v0.33.0-flask.1
197
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/v1.0.0-prerelease.1...HEAD
198
+ [1.0.0-prerelease.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v1.0.0-prerelease.1
235
199
  [0.32.2]: https://github.com/MetaMask/snaps/compare/v0.32.1...v0.32.2
236
200
  [0.32.1]: https://github.com/MetaMask/snaps/compare/v0.32.0...v0.32.1
237
201
  [0.32.0]: https://github.com/MetaMask/snaps/compare/v0.31.0...v0.32.0
@@ -1,3 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isEqual = void 0;
1
4
  /**
2
5
  * Checks if array `a` is equal to array `b`. Note that this does not do a deep
3
6
  * equality check. It only checks if the arrays are the same length and if each
@@ -6,8 +9,9 @@
6
9
  * @param a - The first array to compare.
7
10
  * @param b - The second array to compare.
8
11
  * @returns `true` if the arrays are equal, `false` otherwise.
9
- */ export function isEqual(a, b) {
10
- return a.length === b.length && a.every((value, index)=>value === b[index]);
12
+ */
13
+ function isEqual(a, b) {
14
+ return a.length === b.length && a.every((value, index) => value === b[index]);
11
15
  }
12
-
16
+ exports.isEqual = isEqual;
13
17
  //# sourceMappingURL=array.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"array.js","sourceRoot":"","sources":["../src/array.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACH,SAAgB,OAAO,CAAC,CAAY,EAAE,CAAY;IAChD,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC,MAAM,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;AAChF,CAAC;AAFD,0BAEC","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"]}
@@ -7,6 +7,10 @@ export declare enum SnapCaveatType {
7
7
  * Permitted coin types, used by `snap_getBip44Entropy`.
8
8
  */
9
9
  PermittedCoinTypes = "permittedCoinTypes",
10
+ /**
11
+ * Permission to use the Snap keyring API.
12
+ */
13
+ SnapKeyring = "snapKeyring",
10
14
  /**
11
15
  * Caveat specifying a snap cronjob.
12
16
  */
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SnapCaveatType = void 0;
4
+ var SnapCaveatType;
5
+ (function (SnapCaveatType) {
6
+ /**
7
+ * Permitted derivation paths, used by `snap_getBip32Entropy`.
8
+ */
9
+ SnapCaveatType["PermittedDerivationPaths"] = "permittedDerivationPaths";
10
+ /**
11
+ * Permitted coin types, used by `snap_getBip44Entropy`.
12
+ */
13
+ SnapCaveatType["PermittedCoinTypes"] = "permittedCoinTypes";
14
+ /**
15
+ * Permission to use the Snap keyring API.
16
+ */
17
+ SnapCaveatType["SnapKeyring"] = "snapKeyring";
18
+ /**
19
+ * Caveat specifying a snap cronjob.
20
+ */
21
+ SnapCaveatType["SnapCronjob"] = "snapCronjob";
22
+ /**
23
+ * Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.
24
+ */
25
+ SnapCaveatType["TransactionOrigin"] = "transactionOrigin";
26
+ /**
27
+ * The origins that a Snap can receive JSON-RPC messages from.
28
+ */
29
+ SnapCaveatType["RpcOrigin"] = "rpcOrigin";
30
+ /**
31
+ * Caveat specifying the snap IDs that can be interacted with.
32
+ */
33
+ SnapCaveatType["SnapIds"] = "snapIds";
34
+ })(SnapCaveatType = exports.SnapCaveatType || (exports.SnapCaveatType = {}));
35
+ //# sourceMappingURL=caveats.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"caveats.js","sourceRoot":"","sources":["../src/caveats.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAmCX;AAnCD,WAAY,cAAc;IACxB;;OAEG;IACH,uEAAqD,CAAA;IAErD;;OAEG;IACH,2DAAyC,CAAA;IAEzC;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,yDAAuC,CAAA;IAEvC;;OAEG;IACH,yCAAuB,CAAA;IAEvB;;OAEG;IACH,qCAAmB,CAAA;AACrB,CAAC,EAnCW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAmCzB","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 * Permission to use the Snap keyring API.\n */\n SnapKeyring = 'snapKeyring',\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"]}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.checksumFiles = exports.checksum = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const sha256_1 = require("@noble/hashes/sha256");
6
+ const VirtualFile_1 = require("./virtual-file/VirtualFile");
7
+ /**
8
+ * Calculates checksum for a single byte array.
9
+ *
10
+ * @param bytes - The byte array to calculate the checksum for.
11
+ * @returns A single sha-256 checksum.
12
+ */
13
+ function checksum(bytes) {
14
+ const value = bytes instanceof VirtualFile_1.VirtualFile ? bytes.value : bytes;
15
+ return (0, sha256_1.sha256)(value);
16
+ }
17
+ exports.checksum = checksum;
18
+ /**
19
+ * Calculates checksum over multiple files in a reproducible way.
20
+ *
21
+ * 1. Sort all the files by their paths.
22
+ * 2. Calculate sha-256 checksum of each file separately.
23
+ * 3. Concatenate all the checksums into one buffer and sha-256 that buffer.
24
+ *
25
+ * The sorting of paths is done using {@link https://tc39.es/ecma262/#sec-islessthan UTF-16 Code Units}.
26
+ *
27
+ * @param files - The files over which to calculate the checksum.
28
+ * @returns A single sha-256 checksum.
29
+ */
30
+ function checksumFiles(files) {
31
+ return checksum((0, utils_1.concatBytes)([...files]
32
+ .sort((a, b) => {
33
+ (0, utils_1.assert)(a.path !== b.path, 'Tried to sort files with non-unique paths.');
34
+ if (a.path < b.path) {
35
+ return -1;
36
+ }
37
+ return 1;
38
+ })
39
+ .map((file) => checksum(file))));
40
+ }
41
+ exports.checksumFiles = checksumFiles;
42
+ //# sourceMappingURL=checksum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"checksum.js","sourceRoot":"","sources":["../src/checksum.ts"],"names":[],"mappings":";;;AAAA,2CAAsD;AACtD,iDAA8C;AAE9C,4DAAyD;AAEzD;;;;;GAKG;AACH,SAAgB,QAAQ,CAAC,KAAwC;IAC/D,MAAM,KAAK,GAAG,KAAK,YAAY,yBAAW,CAAC,CAAC,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC;IACjE,OAAO,IAAA,eAAM,EAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAHD,4BAGC;AAED;;;;;;;;;;;GAWG;AACH,SAAgB,aAAa,CAAC,KAAoB;IAChD,OAAO,QAAQ,CACb,IAAA,mBAAW,EACT,CAAC,GAAG,KAAK,CAAC;SACP,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,IAAA,cAAM,EACJ,CAAC,CAAC,IAAI,KAAK,CAAC,CAAC,IAAI,EACjB,4CAA4C,CAC7C,CAAC;QACF,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE;YACnB,OAAO,CAAC,CAAC,CAAC;SACX;QACD,OAAO,CAAC,CAAC;IACX,CAAC,CAAC;SACD,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CACjC,CACF,CAAC;AACJ,CAAC;AAjBD,sCAiBC","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"]}
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCronjobSpecificationArray = exports.CronjobSpecificationArrayStruct = exports.isCronjobSpecification = exports.CronjobSpecificationStruct = exports.parseCronExpression = exports.CronExpressionStruct = exports.CronjobRpcRequestStruct = void 0;
4
+ const utils_1 = require("@metamask/utils");
5
+ const cron_parser_1 = require("cron-parser");
6
+ const superstruct_1 = require("superstruct");
7
+ exports.CronjobRpcRequestStruct = (0, superstruct_1.assign)((0, superstruct_1.partial)((0, superstruct_1.pick)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc'])), (0, superstruct_1.omit)(utils_1.JsonRpcRequestStruct, ['id', 'jsonrpc']));
8
+ exports.CronExpressionStruct = (0, superstruct_1.refine)((0, superstruct_1.coerce)((0, superstruct_1.string)(), (0, superstruct_1.object)({
9
+ minute: (0, superstruct_1.optional)((0, superstruct_1.string)()),
10
+ hour: (0, superstruct_1.optional)((0, superstruct_1.string)()),
11
+ dayOfMonth: (0, superstruct_1.optional)((0, superstruct_1.string)()),
12
+ month: (0, superstruct_1.optional)((0, superstruct_1.string)()),
13
+ dayOfWeek: (0, superstruct_1.optional)((0, superstruct_1.string)()),
14
+ }), (value) => `${value.minute ?? '*'} ${value.hour ?? '*'} ${value.dayOfMonth ?? '*'} ${value.month ?? '*'} ${value.dayOfWeek ?? '*'}`), 'CronExpression', (value) => {
15
+ try {
16
+ (0, cron_parser_1.parseExpression)(value);
17
+ return true;
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ });
23
+ /**
24
+ * Parses a cron expression.
25
+ *
26
+ * @param expression - Expression to parse.
27
+ * @returns A CronExpression class instance.
28
+ */
29
+ function parseCronExpression(expression) {
30
+ const ensureStringExpression = (0, superstruct_1.create)(expression, exports.CronExpressionStruct);
31
+ return (0, cron_parser_1.parseExpression)(ensureStringExpression);
32
+ }
33
+ exports.parseCronExpression = parseCronExpression;
34
+ exports.CronjobSpecificationStruct = (0, superstruct_1.object)({
35
+ expression: exports.CronExpressionStruct,
36
+ request: exports.CronjobRpcRequestStruct,
37
+ });
38
+ /**
39
+ * Check if the given value is a {@link CronjobSpecification} object.
40
+ *
41
+ * @param value - The value to check.
42
+ * @returns Whether the value is a valid {@link CronjobSpecification} object.
43
+ */
44
+ function isCronjobSpecification(value) {
45
+ try {
46
+ (0, superstruct_1.create)(value, exports.CronjobSpecificationStruct);
47
+ return true;
48
+ }
49
+ catch {
50
+ return false;
51
+ }
52
+ }
53
+ exports.isCronjobSpecification = isCronjobSpecification;
54
+ exports.CronjobSpecificationArrayStruct = (0, superstruct_1.array)(exports.CronjobSpecificationStruct);
55
+ /**
56
+ * Check if the given value is an array of {@link CronjobSpecification} objects.
57
+ *
58
+ * @param value - The value to check.
59
+ * @returns Whether the value is a valid array of {@link CronjobSpecification} objects.
60
+ */
61
+ function isCronjobSpecificationArray(value) {
62
+ try {
63
+ (0, superstruct_1.create)(value, exports.CronjobSpecificationArrayStruct);
64
+ return true;
65
+ }
66
+ catch {
67
+ return false;
68
+ }
69
+ }
70
+ exports.isCronjobSpecificationArray = isCronjobSpecificationArray;
71
+ //# sourceMappingURL=cronjob.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cronjob.js","sourceRoot":"","sources":["../src/cronjob.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,6CAA8C;AAC9C,6CAaqB;AAER,QAAA,uBAAuB,GAAG,IAAA,oBAAM,EAC3C,IAAA,qBAAO,EAAC,IAAA,kBAAI,EAAC,4BAAoB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,EACtD,IAAA,kBAAI,EAAC,4BAAoB,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC,CAC9C,CAAC;AAGW,QAAA,oBAAoB,GAAG,IAAA,oBAAM,EACxC,IAAA,oBAAM,EACJ,IAAA,oBAAM,GAAE,EACR,IAAA,oBAAM,EAAC;IACL,MAAM,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC1B,IAAI,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACxB,UAAU,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IAC9B,KAAK,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;IACzB,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC9B,CAAC,EACF,CAAC,KAAK,EAAE,EAAE,CACR,GAAG,KAAK,CAAC,MAAM,IAAI,GAAG,IAAI,KAAK,CAAC,IAAI,IAAI,GAAG,IAAI,KAAK,CAAC,UAAU,IAAI,GAAG,IACpE,KAAK,CAAC,KAAK,IAAI,GACjB,IAAI,KAAK,CAAC,SAAS,IAAI,GAAG,EAAE,CAC/B,EACD,gBAAgB,EAChB,CAAC,KAAK,EAAE,EAAE;IACR,IAAI;QACF,IAAA,6BAAe,EAAC,KAAK,CAAC,CAAC;QACvB,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;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;QACF,IAAA,oBAAM,EAAC,KAAK,EAAE,kCAA0B,CAAC,CAAC;QAC1C,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,wDAOC;AAEY,QAAA,+BAA+B,GAAG,IAAA,mBAAK,EAClD,kCAA0B,CAC3B,CAAC;AAEF;;;;;GAKG;AACH,SAAgB,2BAA2B,CAAC,KAAc;IACxD,IAAI;QACF,IAAA,oBAAM,EAAC,KAAK,EAAE,uCAA+B,CAAC,CAAC;QAC/C,OAAO,IAAI,CAAC;KACb;IAAC,MAAM;QACN,OAAO,KAAK,CAAC;KACd;AACH,CAAC;AAPD,kEAOC","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"]}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.deepClone = void 0;
7
+ const rfdc_1 = __importDefault(require("rfdc"));
8
+ exports.deepClone = (0, rfdc_1.default)({ proto: false, circles: false });
9
+ //# sourceMappingURL=deep-clone.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"deep-clone.js","sourceRoot":"","sources":["../src/deep-clone.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAEX,QAAA,SAAS,GAAG,IAAA,cAAI,EAAC,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC","sourcesContent":["import rfdc from 'rfdc';\n\nexport const deepClone = rfdc({ proto: false, circles: false });\n"]}
@@ -1,6 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DEFAULT_ENDOWMENTS = void 0;
1
4
  /**
2
5
  * Global JavaScript APIs exposed by default to all snaps.
3
- */ export const DEFAULT_ENDOWMENTS = Object.freeze([
6
+ */
7
+ exports.DEFAULT_ENDOWMENTS = Object.freeze([
4
8
  'atob',
5
9
  'btoa',
6
10
  'BigInt',
@@ -33,7 +37,6 @@
33
37
  // https://github.com/MetaMask/snaps-monorepo/issues/662
34
38
  // https://github.com/MetaMask/snaps-monorepo/discussions/678
35
39
  'AbortController',
36
- 'AbortSignal'
40
+ 'AbortSignal',
37
41
  ]);
38
-
39
42
  //# sourceMappingURL=default-endowments.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"default-endowments.js","sourceRoot":"","sources":["../src/default-endowments.ts"],"names":[],"mappings":";;;AAAA;;GAEG;AACU,QAAA,kBAAkB,GAAsB,MAAM,CAAC,MAAM,CAAC;IACjE,MAAM;IACN,MAAM;IACN,QAAQ;IACR,SAAS;IACT,QAAQ;IACR,MAAM;IACN,MAAM;IACN,YAAY;IACZ,cAAc;IACd,cAAc;IACd,aAAa;IACb,aAAa;IACb,KAAK;IACL,aAAa;IACb,eAAe;IACf,WAAW;IACX,YAAY;IACZ,mBAAmB;IACnB,YAAY;IACZ,aAAa;IACb,YAAY;IACZ,aAAa;IACb,cAAc;IACd,cAAc;IACd,eAAe;IACf,gBAAgB;IAChB,UAAU;IACV,aAAa;IACb,qFAAqF;IACrF,wDAAwD;IACxD,6DAA6D;IAC7D,iBAAiB;IACjB,aAAa;CACd,CAAC,CAAC","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"]}
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.STATE_ENCRYPTION_MAGIC_VALUE = exports.SIP_6_MAGIC_VALUE = void 0;
4
+ // 0xd36e6170 - 0x80000000
5
+ exports.SIP_6_MAGIC_VALUE = `1399742832'`;
6
+ // `${bytesToNumber(keccak256('Snaps state encryption').slice(0, 4))}'`
7
+ exports.STATE_ENCRYPTION_MAGIC_VALUE = `572232532'`;
8
+ //# sourceMappingURL=entropy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entropy.js","sourceRoot":"","sources":["../src/entropy.ts"],"names":[],"mappings":";;;AAAA,0BAA0B;AACb,QAAA,iBAAiB,GAAG,aAA6B,CAAC;AAE/D,uEAAuE;AAC1D,QAAA,4BAA4B,GAAG,YAA4B,CAAC","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"]}
@@ -1,22 +1,23 @@
1
- // eslint-disable-next-line import/no-unassigned-import
2
1
  "use strict";
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // eslint-disable-next-line import/no-unassigned-import
6
4
  require("ses/lockdown");
7
- const _fs = require("fs");
8
- const _mock = require("./mock");
9
- const _types = require("./types");
5
+ const fs_1 = require("fs");
6
+ const mock_1 = require("./mock");
7
+ const types_1 = require("./types");
10
8
  lockdown({
11
9
  consoleTaming: 'unsafe',
12
10
  errorTaming: 'unsafe',
13
11
  mathTaming: 'unsafe',
14
12
  dateTaming: 'unsafe',
15
13
  overrideTaming: 'severe',
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'
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
+ : {}),
20
21
  });
21
22
  /**
22
23
  * Get mock endowments that don't do anything. This is useful for running the
@@ -24,28 +25,26 @@ lockdown({
24
25
  * for example.
25
26
  *
26
27
  * @returns The mock endowments.
27
- */ function getMockEndowments() {
28
- const endowments = (0, _mock.generateMockEndowments)();
28
+ */
29
+ function getMockEndowments() {
30
+ const endowments = (0, mock_1.generateMockEndowments)();
29
31
  return {
30
32
  ...endowments,
31
33
  window: endowments,
32
- self: endowments
34
+ self: endowments,
33
35
  };
34
36
  }
35
37
  const snapFilePath = process.argv[2];
36
- const snapModule = {
37
- exports: {}
38
- };
38
+ const snapModule = { exports: {} };
39
39
  new Compartment({
40
40
  ...getMockEndowments(),
41
41
  module: snapModule,
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));
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));
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
50
-
49
+ setTimeout(() => process.exit(0), 1000); // Hack to ensure worker exits
51
50
  //# sourceMappingURL=eval-worker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eval-worker.js","sourceRoot":"","sources":["../src/eval-worker.ts"],"names":[],"mappings":";;AAAA,uDAAuD;AACvD,wBAAsB;AAEtB,2BAAkC;AAElC,iCAAgD;AAChD,mCAAyD;AAIzD,QAAQ,CAAC;IACP,aAAa,EAAE,QAAQ;IACvB,WAAW,EAAE,QAAQ;IACrB,UAAU,EAAE,QAAQ;IACpB,UAAU,EAAE,QAAQ;IACpB,cAAc,EAAE,QAAQ;IAExB,uEAAuE;IACvE,oDAAoD;IACpD,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,MAAM;QACjC,CAAC,CAAC;YACE,YAAY,EAAE,QAAQ;SACvB;QACH,CAAC,CAAC,EAAE,CAAC;CACR,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,SAAS,iBAAiB;IACxB,MAAM,UAAU,GAAG,IAAA,6BAAsB,GAAE,CAAC;IAC5C,OAAO;QACL,GAAG,UAAU;QACb,MAAM,EAAE,UAAU;QAClB,IAAI,EAAE,UAAU;KACjB,CAAC;AACJ,CAAC;AAED,MAAM,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAErC,MAAM,UAAU,GAAsB,EAAE,OAAO,EAAE,EAAE,EAAE,CAAC;AAEtD,IAAI,WAAW,CAAC;IACd,GAAG,iBAAiB,EAAE;IACtB,MAAM,EAAE,UAAU;IAClB,OAAO,EAAE,UAAU,CAAC,OAAO;CAC5B,CAAC,CAAC,QAAQ,CAAC,IAAA,iBAAY,EAAC,YAAY,EAAE,MAAM,CAAC,CAAC,CAAC;AAEhD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,MAAM,CAC3D,CAAC,UAAU,EAAE,EAAE,CAAC,CAAC,yBAAiB,CAAC,QAAQ,CAAC,UAAyB,CAAC,CACvE,CAAC;AAEF,IAAI,cAAc,CAAC,MAAM,GAAG,CAAC,EAAE;IAC7B,sCAAsC;IACtC,OAAO,CAAC,IAAI,CAAC,mCAAmC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;CAC9E;AAED,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,8BAA8B","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 // TODO: See if there's an easier way to do this. This file is ran in a\n // separate process, so we can't mock SES with Jest.\n ...(process.env.NODE_ENV === 'test'\n ? {\n domainTaming: 'unsafe',\n }\n : {}),\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"]}
package/dist/eval.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.evalBundle = void 0;
4
+ const child_process_1 = require("child_process");
5
+ const path_1 = require("path");
6
+ const fs_1 = require("./fs");
7
+ /**
8
+ * Spawn a new process to run the provided bundle in.
9
+ *
10
+ * @param bundlePath - The path to the bundle to run.
11
+ * @returns `null` if the worker ran successfully.
12
+ * @throws If the worker failed to run successfully.
13
+ */
14
+ async function evalBundle(bundlePath) {
15
+ await (0, fs_1.validateFilePath)(bundlePath);
16
+ return new Promise((resolve, reject) => {
17
+ const worker = (0, child_process_1.fork)((0, path_1.join)(__dirname, 'eval-worker.js'), [bundlePath]);
18
+ worker.on('exit', (exitCode) => {
19
+ if (exitCode === 0) {
20
+ return resolve(null);
21
+ }
22
+ return reject(new Error(`Process exited with non-zero exit code: ${exitCode}`));
23
+ });
24
+ });
25
+ }
26
+ exports.evalBundle = evalBundle;
27
+ //# sourceMappingURL=eval.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"eval.js","sourceRoot":"","sources":["../src/eval.ts"],"names":[],"mappings":";;;AAAA,iDAAqC;AACrC,+BAA4B;AAE5B,6BAAwC;AAExC;;;;;;GAMG;AACI,KAAK,UAAU,UAAU,CAAC,UAAkB;IACjD,MAAM,IAAA,qBAAgB,EAAC,UAAU,CAAC,CAAC;IAEnC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,MAAM,GAAG,IAAA,oBAAI,EAAC,IAAA,WAAI,EAAC,SAAS,EAAE,gBAAgB,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;QAErE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,QAAgB,EAAE,EAAE;YACrC,IAAI,QAAQ,KAAK,CAAC,EAAE;gBAClB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;aACtB;YAED,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,2CAA2C,QAAQ,EAAE,CAAC,CACjE,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhBD,gCAgBC","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"]}
@@ -1,8 +1,14 @@
1
- import { promises as fs } from 'fs';
2
- import os from 'os';
3
- import pathUtils from 'path';
4
- import { parseJson } from './json';
5
- import { readVirtualFile } from './virtual-file';
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.useTemporaryFile = exports.validateDirPath = exports.validateFilePath = exports.validateOutfileName = exports.getOutfilePath = exports.readJsonFile = exports.isFile = exports.isDirectory = void 0;
7
+ const fs_1 = require("fs");
8
+ const os_1 = __importDefault(require("os"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const json_1 = require("./json");
11
+ const virtual_file_1 = require("./virtual-file");
6
12
  /**
7
13
  * Checks whether the given path string resolves to an existing directory, and
8
14
  * optionally creates the directory if it doesn't exist.
@@ -10,57 +16,64 @@ import { readVirtualFile } from './virtual-file';
10
16
  * @param pathString - The path string to check.
11
17
  * @param createDir - Whether to create the directory if it doesn't exist.
12
18
  * @returns Whether the given path is an existing directory.
13
- */ export async function isDirectory(pathString, createDir) {
19
+ */
20
+ async function isDirectory(pathString, createDir) {
14
21
  try {
15
- const stats = await fs.stat(pathString);
22
+ const stats = await fs_1.promises.stat(pathString);
16
23
  return stats.isDirectory();
17
- } catch (error) {
24
+ }
25
+ catch (error) {
18
26
  if (error.code === 'ENOENT') {
19
27
  if (!createDir) {
20
28
  return false;
21
29
  }
22
- await fs.mkdir(pathString, {
23
- recursive: true
24
- });
30
+ await fs_1.promises.mkdir(pathString, { recursive: true });
25
31
  return true;
26
32
  }
27
33
  return false;
28
34
  }
29
35
  }
36
+ exports.isDirectory = isDirectory;
30
37
  /**
31
38
  * Checks whether the given path string resolves to an existing file.
32
39
  *
33
40
  * @param pathString - The path string to check.
34
41
  * @returns Whether the given path is an existing file.
35
- */ export async function isFile(pathString) {
42
+ */
43
+ async function isFile(pathString) {
36
44
  try {
37
- const stats = await fs.stat(pathString);
45
+ const stats = await fs_1.promises.stat(pathString);
38
46
  return stats.isFile();
39
- } catch (error) {
47
+ }
48
+ catch (error) {
40
49
  return false;
41
50
  }
42
51
  }
52
+ exports.isFile = isFile;
43
53
  /**
44
54
  * Reads a `.json` file, parses its contents, and returns them.
45
55
  *
46
56
  * @param pathString - The path to the JSON file.
47
57
  * @returns The parsed contents of the JSON file.
48
- */ export async function readJsonFile(pathString) {
58
+ */
59
+ async function readJsonFile(pathString) {
49
60
  if (!pathString.endsWith('.json')) {
50
61
  throw new Error('The specified file must be a ".json" file.');
51
62
  }
52
63
  let file;
53
64
  try {
54
- file = await readVirtualFile(pathString, 'utf8');
55
- } catch (error) {
65
+ file = await (0, virtual_file_1.readVirtualFile)(pathString, 'utf8');
66
+ }
67
+ catch (error) {
56
68
  if (error.code === 'ENOENT') {
57
69
  throw new Error(`Could not find '${pathString}'. Please ensure that the file exists.`);
58
70
  }
59
71
  throw error;
60
72
  }
61
- file.result = parseJson(file.toString());
73
+ file.result = (0, json_1.parseJson)(file.toString());
62
74
  return file;
63
75
  }
76
+ exports.readJsonFile = readJsonFile;
64
77
  /**
65
78
  * Gets the complete out file path from an output file name and parent
66
79
  * directory path.
@@ -68,9 +81,11 @@ import { readVirtualFile } from './virtual-file';
68
81
  * @param outDir - The path to the out file's parent directory.
69
82
  * @param outFileName - The out file's name.
70
83
  * @returns The complete path to the out file.
71
- */ export function getOutfilePath(outDir, outFileName) {
72
- return pathUtils.join(outDir, outFileName || 'bundle.js');
84
+ */
85
+ function getOutfilePath(outDir, outFileName) {
86
+ return path_1.default.join(outDir, outFileName || 'bundle.js');
73
87
  }
88
+ exports.getOutfilePath = getOutfilePath;
74
89
  /**
75
90
  * Ensures that the outfile name is just a `.js` file name.
76
91
  * Throws on validation failure.
@@ -78,25 +93,31 @@ import { readVirtualFile } from './virtual-file';
78
93
  * @param filename - The file name to validate.
79
94
  * @returns `true` if validation succeeded.
80
95
  * @throws If the file name is invalid.
81
- */ export function validateOutfileName(filename) {
82
- if (!filename.endsWith('.js') || filename === '.js' || pathUtils.basename(filename) !== filename) {
96
+ */
97
+ function validateOutfileName(filename) {
98
+ if (!filename.endsWith('.js') ||
99
+ filename === '.js' ||
100
+ path_1.default.basename(filename) !== filename) {
83
101
  throw new Error(`Invalid outfile name: ${filename}. Must be a .js file`);
84
102
  }
85
103
  return true;
86
104
  }
105
+ exports.validateOutfileName = validateOutfileName;
87
106
  /**
88
107
  * Validates a file path. Throws on validation failure.
89
108
  *
90
109
  * @param filePath - The file path to validate.
91
110
  * @returns `true` if validation succeeded.
92
111
  * @throws If the path does not resolve to a file.
93
- */ export async function validateFilePath(filePath) {
112
+ */
113
+ async function validateFilePath(filePath) {
94
114
  const exists = await isFile(filePath);
95
115
  if (!exists) {
96
116
  throw new Error(`Invalid params: '${filePath}' is not a file or does not exist.`);
97
117
  }
98
118
  return true;
99
119
  }
120
+ exports.validateFilePath = validateFilePath;
100
121
  /**
101
122
  * Validates a directory path. Throws on validation failure.
102
123
  *
@@ -104,13 +125,15 @@ import { readVirtualFile } from './virtual-file';
104
125
  * @param createDir - Whether to create the directory if it doesn't exist.
105
126
  * @returns `true` if validation succeeded or the directory was created.
106
127
  * @throws If the directory does not exist or could not be created.
107
- */ export async function validateDirPath(dirPath, createDir) {
128
+ */
129
+ async function validateDirPath(dirPath, createDir) {
108
130
  const exists = await isDirectory(dirPath, createDir);
109
131
  if (!exists) {
110
132
  throw new Error(`Invalid params: '${dirPath}' is not a directory or could not be created.`);
111
133
  }
112
134
  return true;
113
135
  }
136
+ exports.validateDirPath = validateDirPath;
114
137
  /**
115
138
  * Creates a temporary file with a given name and content, writes it to disk and calls the provided function.
116
139
  * This function handles deletion of the temporary file after usage.
@@ -118,19 +141,19 @@ import { readVirtualFile } from './virtual-file';
118
141
  * @param fileName - The name of the temporary file.
119
142
  * @param fileContents - The content of the temporary file.
120
143
  * @param fn - The callback function to call when the temporary file has been created.
121
- */ export async function useTemporaryFile(fileName, fileContents, fn) {
122
- const filePath = pathUtils.join(os.tmpdir(), fileName);
123
- await fs.mkdir(pathUtils.dirname(filePath), {
124
- recursive: true
125
- });
126
- await fs.writeFile(filePath, fileContents);
144
+ */
145
+ async function useTemporaryFile(fileName, fileContents, fn) {
146
+ const filePath = path_1.default.join(os_1.default.tmpdir(), fileName);
147
+ await fs_1.promises.mkdir(path_1.default.dirname(filePath), { recursive: true });
148
+ await fs_1.promises.writeFile(filePath, fileContents);
127
149
  try {
128
150
  await fn(filePath);
129
- } finally{
151
+ }
152
+ finally {
130
153
  if (await isFile(filePath)) {
131
- await fs.unlink(filePath);
154
+ await fs_1.promises.unlink(filePath);
132
155
  }
133
156
  }
134
157
  }
135
-
158
+ exports.useTemporaryFile = useTemporaryFile;
136
159
  //# sourceMappingURL=fs.js.map