@metamask/snaps-utils 0.37.1-flask.1 → 0.38.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 (57) hide show
  1. package/CHANGELOG.md +11 -282
  2. package/dist/cjs/enum.js +2 -2
  3. package/dist/cjs/enum.js.map +1 -1
  4. package/dist/cjs/errors.js +19 -0
  5. package/dist/cjs/errors.js.map +1 -0
  6. package/dist/cjs/eval-worker.js.map +1 -1
  7. package/dist/cjs/eval.js +54 -6
  8. package/dist/cjs/eval.js.map +1 -1
  9. package/dist/cjs/handlers.js +59 -0
  10. package/dist/cjs/handlers.js.map +1 -1
  11. package/dist/cjs/index.browser.js +3 -0
  12. package/dist/cjs/index.browser.js.map +1 -1
  13. package/dist/cjs/index.js +3 -0
  14. package/dist/cjs/index.js.map +1 -1
  15. package/dist/cjs/manifest/manifest.js +4 -4
  16. package/dist/cjs/manifest/manifest.js.map +1 -1
  17. package/dist/cjs/snaps.js.map +1 -1
  18. package/dist/cjs/strings.js +21 -0
  19. package/dist/cjs/strings.js.map +1 -0
  20. package/dist/cjs/structs.js +163 -0
  21. package/dist/cjs/structs.js.map +1 -0
  22. package/dist/cjs/types.js +2 -10
  23. package/dist/cjs/types.js.map +1 -1
  24. package/dist/esm/enum.js +1 -1
  25. package/dist/esm/enum.js.map +1 -1
  26. package/dist/esm/errors.js +17 -0
  27. package/dist/esm/errors.js.map +1 -0
  28. package/dist/esm/eval-worker.js.map +1 -1
  29. package/dist/esm/eval.js +43 -3
  30. package/dist/esm/eval.js.map +1 -1
  31. package/dist/esm/handlers.js +45 -1
  32. package/dist/esm/handlers.js.map +1 -1
  33. package/dist/esm/index.browser.js +3 -0
  34. package/dist/esm/index.browser.js.map +1 -1
  35. package/dist/esm/index.js +3 -0
  36. package/dist/esm/index.js.map +1 -1
  37. package/dist/esm/manifest/manifest.js +5 -4
  38. package/dist/esm/manifest/manifest.js.map +1 -1
  39. package/dist/esm/snaps.js.map +1 -1
  40. package/dist/esm/strings.js +11 -0
  41. package/dist/esm/strings.js.map +1 -0
  42. package/dist/esm/structs.js +230 -0
  43. package/dist/esm/structs.js.map +1 -0
  44. package/dist/esm/types.js +2 -7
  45. package/dist/esm/types.js.map +1 -1
  46. package/dist/types/enum.d.ts +1 -1
  47. package/dist/types/errors.d.ts +10 -0
  48. package/dist/types/eval.d.ts +9 -1
  49. package/dist/types/handlers.d.ts +82 -6
  50. package/dist/types/index.browser.d.ts +3 -0
  51. package/dist/types/index.d.ts +3 -0
  52. package/dist/types/manifest/manifest.d.ts +3 -1
  53. package/dist/types/snaps.d.ts +5 -6
  54. package/dist/types/strings.d.ts +8 -0
  55. package/dist/types/structs.d.ts +158 -0
  56. package/dist/types/types.d.ts +1 -5
  57. package/package.json +6 -5
package/CHANGELOG.md CHANGED
@@ -6,291 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
- ## [0.37.1-flask.1]
10
- ### Changed
11
- - No changes this release.
12
-
13
- ## [0.37.0-flask.1]
14
- ### Changed
15
- - No changes this release.
16
-
17
- ## [0.36.1-flask.1]
18
- ### Changed
19
- - No changes this release.
20
-
21
- ## [0.36.0-flask.1]
22
- ### Changed
23
- - No changes this release.
24
-
25
- ## [0.35.2-flask.1]
26
- ### Fixed
27
- - Fix type issue introduced by [#1532](https://github.com/MetaMask/snaps/pull/1532) ([#1541](https://github.com/MetaMask/snaps/pull/1541))
28
-
29
- ## [0.35.1-flask.1]
30
- ### Changed
31
- - No changes this release.
32
-
33
- ## [0.35.0-flask.1]
34
- ### Added
35
- - Add `snap_manageAccounts` RPC method ([#1290](https://github.com/MetaMask/snaps/pull/1290))
36
-
37
- ### Changed
38
- - **BREAKING:** Build packages as both CJS and ESM ([#1519](https://github.com/MetaMask/snaps/pull/1519), ([#1532](https://github.com/MetaMask/snaps/pull/1532)))
39
- - This is breaking in the sense that imports to `dist/` will now require you to import either `dist/cjs` or `dist/esm`.
40
- - **BREAKING:** Disallow deriving Ethereum keys ([#1217](https://github.com/MetaMask/snaps/pull/1217))
41
- - Coin type `60` is now blocked for derivation.
42
- - Add `sideEffects: false` ([#1486](https://github.com/MetaMask/snaps/pull/1486))
43
-
44
- ### Removed
45
- - **BREAKING:** Remove utility functions used for multichain/keyring effort ([#1527](https://github.com/MetaMask/snaps/pull/1527))
46
-
47
- ### Fixed
48
- - Improve JSON parsing safety ([#1499](https://github.com/MetaMask/snaps/pull/1499))
49
- - Fix false positives when post processing code with HTML comment tokens ([#1522](https://github.com/MetaMask/snaps/pull/1522))
50
- - Fix BIP-32 path validation ([#1506](https://github.com/MetaMask/snaps/pull/1506))
51
-
52
- ## [0.34.1-flask.1]
53
- ### Changed
54
- - No changes this release.
55
-
56
- ## [0.34.0-flask.1]
57
- ### Changed
58
- - Add SVG validation ([#1401](https://github.com/MetaMask/snaps/pull/1401))
59
- - Make handler types generic, allowing them to be changed ([#1409](https://github.com/MetaMask/snaps/pull/1409))
60
- - Allow use of `$schema` in manifest files ([#1389](https://github.com/MetaMask/snaps/pull/1389))
61
-
62
- ## [0.33.1-flask.1]
63
- ### Changed
64
- - No changes this release.
65
-
66
- ## [0.33.0-flask.1]
67
- ### Changed
68
- - **BREAKING:** Added `snapIds` caveat mapper ([#1360](https://github.com/MetaMask/snaps-monorepo/pull/1360))
69
- - Snap dependencies must be specified in a simplified manner. See the PR for an example.
70
- - Add subject type restrictions to snap-specific permissions ([#1366](https://github.com/MetaMask/snaps-monorepo/pull/1366))
71
- - Add Web Worker support for snap execution ([#1320](https://github.com/MetaMask/snaps-monorepo/pull/1320))
72
-
73
- ### Fixed
74
- - Add `WebAssembly` to eval mock ([#1359](https://github.com/MetaMask/snaps-monorepo/pull/1359))
75
-
76
- ## [0.32.2]
77
- ### Changed
78
- - No changes this release.
79
-
80
- ## [0.32.1]
81
- ### Changed
82
- - No changes this release.
83
-
84
- ## [0.32.0]
85
- ### Changed
86
- - Use side effects to install snaps via `wallet_snap` permission ([#1301](https://github.com/MetaMask/snaps-monorepo/pull/1301))
87
-
88
- ## [0.31.0]
89
- ### Changed
90
- - **BREAKING:** Target `ES2020` ([#1247](https://github.com/MetaMask/snaps-monorepo/pull/1247))
91
- - Improve validation and sanitizing of snap IDs ([#1237](https://github.com/MetaMask/snaps-monorepo/pull/1237))
92
-
93
- ## [0.30.0]
94
- ### Changed
95
- - Properly sandbox iframe and inline SES in execution bundles ([#1193](https://github.com/MetaMask/snaps-monorepo/pull/1193))
96
-
97
- ## [0.29.0]
98
- ### Changed
99
- - Skip writing manifest if identical ([#1171](https://github.com/MetaMask/snaps-monorepo/pull/1171))
100
- - This fixes a bug on Windows where the CLI could get stuck in a loop
101
-
102
- ### Removed
103
- - **BREAKING:** Remove `SnapsGlobalObject` type ([#1014](https://github.com/MetaMask/snaps-monorepo/pull/1014))
104
-
105
- ## [0.28.0]
9
+ ## [0.38.0-flask.1]
106
10
  ### Added
107
- - **BREAKING:** Add support for snap registries ([#1090](https://github.com/MetaMask/snaps-monorepo/pull/1090))
108
- - This removes the `checkBlockList` constructor argument in favor of `registry`
109
- - A registry implementation can be passed here, defaulting to a hosted JSON file
110
- - Requiring a snap to be on the allowlist can be toggled with the feature flag `requireAllowlist`
111
- - Add experimental offscreen execution environment ([#1082](https://github.com/MetaMask/snaps-monorepo/pull/1082))
11
+ - Add `onInstall` and `onUpdate` lifecycle hooks ([#1643](https://github.com/MetaMask/snaps/pull/1643))
112
12
 
113
13
  ### Changed
114
- - **BREAKING:** Bump `key-tree` to 6.2.0 and use `Uint8Array` for secret recovery phrases ([#1137](https://github.com/MetaMask/snaps-monorepo/pull/1137))
115
-
116
- ### Removed
117
- - **BREAKING:** Remove `WebSocket` endowment ([#1122](https://github.com/MetaMask/snaps-monorepo/pull/1122))
118
-
119
- ### Fixed
120
- - Fix missing cronjob export ([#1134](https://github.com/MetaMask/snaps-monorepo/pull/1134))
14
+ - Move source code and snap state back to controller state ([#1634](https://github.com/MetaMask/snaps/pull/1634))
15
+ - Bump `semver` to `^7.5.4` ([#1631](https://github.com/MetaMask/snaps/pull/1631))
121
16
 
122
- ## [0.27.1]
17
+ ## [0.37.2-flask.1]
123
18
  ### Changed
124
- - No changes this release.
125
-
126
- ## [0.27.0]
127
- ### Changed
128
- - **BREAKING:** Use SIP-6 algorithm for state encryption ([#1055](https://github.com/MetaMask/snaps-monorepo/pull/1055))
129
- - This breaks all existing snaps that use `snap_manageState`
130
- - **BREAKING:** Use custom UI in transaction insights ([#1047](https://github.com/MetaMask/snaps-monorepo/pull/1047))
131
- - **BREAKING:** Move all internal types from `snaps-types` to `snaps-utils` ([#1060](https://github.com/MetaMask/snaps-monorepo/pull/1060))
132
-
133
- ## [0.26.2]
134
- ### Changed
135
- - No changes this release.
136
-
137
- ## [0.26.1]
138
- ### Fixed
139
- - Fix some paths being wrongly normalized ([#1053](https://github.com/MetaMask/snaps-monorepo/pull/1053))
140
- - Fix utils browser export ([#1049](https://github.com/MetaMask/snaps-monorepo/pull/1049))
141
-
142
- ## [0.26.0]
143
- ### Fixed
144
- - Fix post processing issue with `object.eval` ([#1040](https://github.com/MetaMask/snaps-monorepo/pull/1040))
145
-
146
- ## [0.25.0]
147
- ### Added
148
- - **BREAKING:** Add JSON-RPC handler permission ([#905](https://github.com/MetaMask/snaps-monorepo/pull/905))
149
- - Snaps are now required to request `endowment:rpc` to receive RPC requests.
150
-
151
- ## [0.24.1]
152
- ### Fixed
153
- - Fix `snap_getBip32PublicKey` manifest validation ([#970](https://github.com/MetaMask/snaps-monorepo/pull/970))
154
-
155
- ## [0.24.0]
156
- ### Added
157
- - Add transaction insight caveat for accessing transaction origin ([#902](https://github.com/MetaMask/snaps-monorepo/pull/902))
158
- - Add `snap_getEntropy` JSON-RPC method ([#940](https://github.com/MetaMask/snaps-monorepo/pull/940))
159
- - Add permission validation to `snap.manifest.json` ([#910](https://github.com/MetaMask/snaps-monorepo/pull/910))
160
- - Add compile-time warning when using `Math.random` ([#950](https://github.com/MetaMask/snaps-monorepo/pull/950))
161
-
162
- ### Changed
163
- - **BREAKING:** Rename package to start with `snaps-` ([#937](https://github.com/MetaMask/snaps-monorepo/pull/937))
164
- - **BREAKING:** Remove `wallet` global in favor of `snap` and `ethereum` ([#939](https://github.com/MetaMask/snaps-monorepo/pull/939), [#964](https://github.com/MetaMask/snaps-monorepo/pull/964))
165
-
166
- ## [0.23.0]
167
- ### Added
168
- - Add snap cronjobs ([#651](https://github.com/MetaMask/snaps-monorepo/pull/651))
169
-
170
- ### Changed
171
- - **BREAKING:** Replace Buffer with Typed Arrays ([#878](https://github.com/MetaMask/snaps-monorepo/pull/878))
172
- - Improve keyring endowment error messaging ([#884](https://github.com/MetaMask/snaps-monorepo/pull/884))
173
- - Replace JSON schema validation with structs ([#862](https://github.com/MetaMask/snaps-monorepo/pull/862))
174
-
175
- ### Removed
176
- - **BREAKING:** Stop including source code in SnapController state ([#861](https://github.com/MetaMask/snaps-monorepo/pull/861))
177
-
178
- ## [0.22.3]
179
- ### Fixed
180
- - Make @babel/types a regular dependency ([#852](https://github.com/MetaMask/snaps-monorepo/pull/852))
181
-
182
- ## [0.22.2]
183
- ### Changed
184
- - No changes this release.
185
-
186
- ## [0.22.1]
187
- ### Fixed
188
- - Add browser entry point for `snap-utils` ([#820](https://github.com/MetaMask/snaps-monorepo/pull/820))
189
-
190
- ## [0.22.0]
191
- ### Added
192
- - Add functionality required for Snap Keyring support ([#700](https://github.com/MetaMask/snaps-monorepo/pull/700), [#777](https://github.com/MetaMask/snaps-monorepo/pull/777))
193
-
194
- ## [0.21.0]
195
- ### Changed
196
- - Run eval and fix manifest in bundler plugins ([#731](https://github.com/MetaMask/snaps-monorepo/pull/731))
197
-
198
- ## [0.20.0]
199
- ### Added
200
- - **BREAKING:** Add Transaction Insight API ([#642](https://github.com/MetaMask/snaps-monorepo/pull/642))
201
- - Add internal types from `@metamask/snaps-types` ([#695](https://github.com/MetaMask/snaps-monorepo/pull/695))
202
-
203
- ### Changed
204
- - **BREAKING:** Simplify manifest format for permission caveats ([#705](https://github.com/MetaMask/snaps-monorepo/pull/705))
205
- - Reduce TypeScript compilation target for `snap-controllers` ([#708](https://github.com/MetaMask/snaps-monorepo/pull/708))
206
-
207
- ## [0.19.1]
208
- ### Added
209
- - Generate source maps from modified code ([#615](https://github.com/MetaMask/snaps-monorepo/pull/615))
210
-
211
- ## [0.19.0]
212
- ### Changed
213
- - Move eval functionality to utils package ([#666](https://github.com/MetaMask/snaps-monorepo/pull/666))
214
- - Move manifest handling functionality to utils ([#652](https://github.com/MetaMask/snaps-monorepo/pull/652))
215
- - Move JSON schemas and controller utils to utils package ([#623](https://github.com/MetaMask/snaps-monorepo/pull/623))
216
-
217
- ### Fixed
218
- - Fixed missing AbortSignal in default endowments ([#682](https://github.com/MetaMask/snaps-monorepo/pull/682))
219
-
220
- ## [0.18.1]
221
- ### Changed
222
- - No changes this release.
223
-
224
- ## [0.18.0]
225
- ### Changed
226
- - Reduce TypeScript compilation target to ES2017 ([#628](https://github.com/MetaMask/snaps-monorepo/pull/628))
227
-
228
- ## [0.17.0]
229
- ### Changed
230
- - **BREAKING:** Bump minimum Node version to 16 ([#601](https://github.com/MetaMask/snaps-monorepo/pull/601))
231
-
232
- ## [0.16.0]
233
- ### Changed
234
- - No changes this release.
235
-
236
- ## [0.15.0]
237
- ### Fixed
238
- - Fix an issue where comment stripping would break for large files ([#468](https://github.com/MetaMask/snaps-monorepo/pull/468))
239
-
240
- ## [0.14.0]
241
- ### Changed
242
- - **BREAKING:** Increase TypeScript compilation target to ES2020 ([#449](https://github.com/MetaMask/snaps-monorepo/pull/449))
243
- - This should not be breaking for consumers on any non-deprecated browser or Node.js version.
244
-
245
- ## [0.13.0]
246
- ### Changed
247
- - No changes this release.
248
-
249
- ## [0.12.0]
250
- ### Added
251
- - Initial release ([#410](https://github.com/MetaMask/snaps-monorepo/pull/410), [#421](https://github.com/MetaMask/snaps-monorepo/pull/421))
19
+ - Release package independently ([#1600](https://github.com/MetaMask/snaps/pull/1600))
20
+ - The version of the package no longer needs to match the version of all other
21
+ MetaMask Snaps packages.
252
22
 
253
- [Unreleased]: https://github.com/MetaMask/snaps/compare/v0.37.1-flask.1...HEAD
254
- [0.37.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.37.0-flask.1...v0.37.1-flask.1
255
- [0.37.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.36.1-flask.1...v0.37.0-flask.1
256
- [0.36.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.36.0-flask.1...v0.36.1-flask.1
257
- [0.36.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.35.2-flask.1...v0.36.0-flask.1
258
- [0.35.2-flask.1]: https://github.com/MetaMask/snaps/compare/v0.35.1-flask.1...v0.35.2-flask.1
259
- [0.35.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.35.0-flask.1...v0.35.1-flask.1
260
- [0.35.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.1-flask.1...v0.35.0-flask.1
261
- [0.34.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.34.0-flask.1...v0.34.1-flask.1
262
- [0.34.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.1-flask.1...v0.34.0-flask.1
263
- [0.33.1-flask.1]: https://github.com/MetaMask/snaps/compare/v0.33.0-flask.1...v0.33.1-flask.1
264
- [0.33.0-flask.1]: https://github.com/MetaMask/snaps/compare/v0.32.2...v0.33.0-flask.1
265
- [0.32.2]: https://github.com/MetaMask/snaps/compare/v0.32.1...v0.32.2
266
- [0.32.1]: https://github.com/MetaMask/snaps/compare/v0.32.0...v0.32.1
267
- [0.32.0]: https://github.com/MetaMask/snaps/compare/v0.31.0...v0.32.0
268
- [0.31.0]: https://github.com/MetaMask/snaps/compare/v0.30.0...v0.31.0
269
- [0.30.0]: https://github.com/MetaMask/snaps/compare/v0.29.0...v0.30.0
270
- [0.29.0]: https://github.com/MetaMask/snaps/compare/v0.28.0...v0.29.0
271
- [0.28.0]: https://github.com/MetaMask/snaps/compare/v0.27.1...v0.28.0
272
- [0.27.1]: https://github.com/MetaMask/snaps/compare/v0.27.0...v0.27.1
273
- [0.27.0]: https://github.com/MetaMask/snaps/compare/v0.26.2...v0.27.0
274
- [0.26.2]: https://github.com/MetaMask/snaps/compare/v0.26.1...v0.26.2
275
- [0.26.1]: https://github.com/MetaMask/snaps/compare/v0.26.0...v0.26.1
276
- [0.26.0]: https://github.com/MetaMask/snaps/compare/v0.25.0...v0.26.0
277
- [0.25.0]: https://github.com/MetaMask/snaps/compare/v0.24.1...v0.25.0
278
- [0.24.1]: https://github.com/MetaMask/snaps/compare/v0.24.0...v0.24.1
279
- [0.24.0]: https://github.com/MetaMask/snaps/compare/v0.23.0...v0.24.0
280
- [0.23.0]: https://github.com/MetaMask/snaps/compare/v0.22.3...v0.23.0
281
- [0.22.3]: https://github.com/MetaMask/snaps/compare/v0.22.2...v0.22.3
282
- [0.22.2]: https://github.com/MetaMask/snaps/compare/v0.22.1...v0.22.2
283
- [0.22.1]: https://github.com/MetaMask/snaps/compare/v0.22.0...v0.22.1
284
- [0.22.0]: https://github.com/MetaMask/snaps/compare/v0.21.0...v0.22.0
285
- [0.21.0]: https://github.com/MetaMask/snaps/compare/v0.20.0...v0.21.0
286
- [0.20.0]: https://github.com/MetaMask/snaps/compare/v0.19.1...v0.20.0
287
- [0.19.1]: https://github.com/MetaMask/snaps/compare/v0.19.0...v0.19.1
288
- [0.19.0]: https://github.com/MetaMask/snaps/compare/v0.18.1...v0.19.0
289
- [0.18.1]: https://github.com/MetaMask/snaps/compare/v0.18.0...v0.18.1
290
- [0.18.0]: https://github.com/MetaMask/snaps/compare/v0.17.0...v0.18.0
291
- [0.17.0]: https://github.com/MetaMask/snaps/compare/v0.16.0...v0.17.0
292
- [0.16.0]: https://github.com/MetaMask/snaps/compare/v0.15.0...v0.16.0
293
- [0.15.0]: https://github.com/MetaMask/snaps/compare/v0.14.0...v0.15.0
294
- [0.14.0]: https://github.com/MetaMask/snaps/compare/v0.13.0...v0.14.0
295
- [0.13.0]: https://github.com/MetaMask/snaps/compare/v0.12.0...v0.13.0
296
- [0.12.0]: https://github.com/MetaMask/snaps/releases/tag/v0.12.0
23
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@0.38.0-flask.1...HEAD
24
+ [0.38.0-flask.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@0.37.2-flask.1...@metamask/snaps-utils@0.38.0-flask.1
25
+ [0.37.2-flask.1]: https://github.com/MetaMask/snaps/releases/tag/@metamask/snaps-utils@0.37.2-flask.1
package/dist/cjs/enum.js CHANGED
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "enumValue", {
8
8
  return enumValue;
9
9
  }
10
10
  });
11
- const _superstruct = require("superstruct");
11
+ const _structs = require("./structs");
12
12
  function enumValue(constant) {
13
- return (0, _superstruct.literal)(constant);
13
+ return (0, _structs.literal)(constant);
14
14
  }
15
15
 
16
16
  //# sourceMappingURL=enum.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/enum.ts"],"sourcesContent":["import type { Struct } from 'superstruct';\nimport { literal } 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":";;;;+BAgCgBA;;;eAAAA;;;6BA/BQ;AA+BjB,SAASA,UACdC,QAAc;IAEd,OAAOC,IAAAA,oBAAO,EAACD;AACjB"}
1
+ {"version":3,"sources":["../../src/enum.ts"],"sourcesContent":["import type { Struct } from 'superstruct';\n\nimport { literal } from './structs';\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>, null> {\n return literal(constant as EnumToUnion<Type>);\n}\n"],"names":["enumValue","constant","literal"],"mappings":";;;;+BAiCgBA;;;eAAAA;;;yBA/BQ;AA+BjB,SAASA,UACdC,QAAc;IAEd,OAAOC,IAAAA,gBAAO,EAACD;AACjB"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "getErrorMessage", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return getErrorMessage;
9
+ }
10
+ });
11
+ const _utils = require("@metamask/utils");
12
+ function getErrorMessage(error) {
13
+ if ((0, _utils.isObject)(error) && (0, _utils.hasProperty)(error, 'message') && typeof error.message === 'string') {
14
+ return error.message;
15
+ }
16
+ return String(error);
17
+ }
18
+
19
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/errors.ts"],"sourcesContent":["import { hasProperty, isObject } from '@metamask/utils';\n\n/**\n * Get the error message from an unknown error type.\n *\n * - If the error is an object with a `message` property, return the message.\n * - Otherwise, return the error converted to a string.\n *\n * @param error - The error to get the message from.\n * @returns The error message.\n */\nexport function getErrorMessage(error: unknown) {\n if (\n isObject(error) &&\n hasProperty(error, 'message') &&\n typeof error.message === 'string'\n ) {\n return error.message;\n }\n\n return String(error);\n}\n"],"names":["getErrorMessage","error","isObject","hasProperty","message","String"],"mappings":";;;;+BAWgBA;;;eAAAA;;;uBAXsB;AAW/B,SAASA,gBAAgBC,KAAc;IAC5C,IACEC,IAAAA,eAAQ,EAACD,UACTE,IAAAA,kBAAW,EAACF,OAAO,cACnB,OAAOA,MAAMG,OAAO,KAAK,UACzB;QACA,OAAOH,MAAMG,OAAO;IACtB;IAEA,OAAOC,OAAOJ;AAChB"}
@@ -1 +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 type { HandlerType } from './types';\nimport { 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;uBAEL;AAIlCA,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"}
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 type { HandlerType } from './handlers';\nimport { generateMockEndowments } from './mock';\nimport { 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;sBAGU;uBACL;AAIlCA,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"}
package/dist/cjs/eval.js CHANGED
@@ -2,26 +2,74 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "evalBundle", {
6
- enumerable: true,
7
- get: function() {
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
+ SnapEvalError: function() {
13
+ return SnapEvalError;
14
+ },
15
+ evalBundle: function() {
8
16
  return evalBundle;
9
17
  }
10
18
  });
19
+ const _utils = require("@metamask/utils");
11
20
  const _child_process = require("child_process");
12
21
  const _path = require("path");
13
22
  const _fs = require("./fs");
23
+ function _define_property(obj, key, value) {
24
+ if (key in obj) {
25
+ Object.defineProperty(obj, key, {
26
+ value: value,
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true
30
+ });
31
+ } else {
32
+ obj[key] = value;
33
+ }
34
+ return obj;
35
+ }
36
+ class SnapEvalError extends Error {
37
+ constructor(message, output){
38
+ super(message);
39
+ _define_property(this, "output", void 0);
40
+ this.name = 'SnapEvalError';
41
+ this.output = output;
42
+ }
43
+ }
14
44
  async function evalBundle(bundlePath) {
15
45
  await (0, _fs.validateFilePath)(bundlePath);
16
46
  return new Promise((resolve, reject)=>{
17
47
  const worker = (0, _child_process.fork)((0, _path.join)(__dirname, 'eval-worker.js'), [
18
48
  bundlePath
19
- ]);
49
+ ], {
50
+ // To avoid printing the output of the worker to the console, we set
51
+ // `stdio` to `pipe` and handle the output ourselves.
52
+ stdio: 'pipe'
53
+ });
54
+ let stdout = '';
55
+ let stderr = '';
56
+ (0, _utils.assert)(worker.stdout, '`stdout` should be defined.');
57
+ (0, _utils.assert)(worker.stderr, '`stderr` should be defined.');
58
+ worker.stdout.on('data', (data)=>{
59
+ stdout += data.toString();
60
+ });
61
+ worker.stderr.on('data', (data)=>{
62
+ stderr += data.toString();
63
+ });
20
64
  worker.on('exit', (exitCode)=>{
65
+ const output = {
66
+ stdout,
67
+ stderr
68
+ };
21
69
  if (exitCode === 0) {
22
- return resolve(null);
70
+ return resolve(output);
23
71
  }
24
- return reject(new Error(`Process exited with non-zero exit code: ${exitCode}`));
72
+ return reject(new SnapEvalError(`Process exited with non-zero exit code: ${exitCode}.`, output));
25
73
  });
26
74
  });
27
75
  }
@@ -1 +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"}
1
+ {"version":3,"sources":["../../src/eval.ts"],"sourcesContent":["import { assert } from '@metamask/utils';\nimport { fork } from 'child_process';\nimport { join } from 'path';\n\nimport { validateFilePath } from './fs';\n\nexport type EvalOutput = {\n stdout: string;\n stderr: string;\n};\n\nexport class SnapEvalError extends Error {\n readonly output: EvalOutput;\n\n constructor(message: string, output: EvalOutput) {\n super(message);\n\n this.name = 'SnapEvalError';\n this.output = output;\n }\n}\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<EvalOutput> {\n await validateFilePath(bundlePath);\n\n return new Promise((resolve, reject) => {\n const worker = fork(join(__dirname, 'eval-worker.js'), [bundlePath], {\n // To avoid printing the output of the worker to the console, we set\n // `stdio` to `pipe` and handle the output ourselves.\n stdio: 'pipe',\n });\n\n let stdout = '';\n let stderr = '';\n\n assert(worker.stdout, '`stdout` should be defined.');\n assert(worker.stderr, '`stderr` should be defined.');\n\n worker.stdout.on('data', (data: Buffer) => {\n stdout += data.toString();\n });\n\n worker.stderr.on('data', (data: Buffer) => {\n stderr += data.toString();\n });\n\n worker.on('exit', (exitCode: number) => {\n const output = {\n stdout,\n stderr,\n };\n\n if (exitCode === 0) {\n return resolve(output);\n }\n\n return reject(\n new SnapEvalError(\n `Process exited with non-zero exit code: ${exitCode}.`,\n output,\n ),\n );\n });\n });\n}\n"],"names":["SnapEvalError","evalBundle","Error","constructor","message","output","name","bundlePath","validateFilePath","Promise","resolve","reject","worker","fork","join","__dirname","stdio","stdout","stderr","assert","on","data","toString","exitCode"],"mappings":";;;;;;;;;;;IAWaA,aAAa;eAAbA;;IAkBSC,UAAU;eAAVA;;;uBA7BC;+BACF;sBACA;oBAEY;;;;;;;;;;;;;;AAO1B,MAAMD,sBAAsBE;IAGjCC,YAAYC,OAAe,EAAEC,MAAkB,CAAE;QAC/C,KAAK,CAACD;QAHR,uBAASC,UAAT,KAAA;QAKE,IAAI,CAACC,IAAI,GAAG;QACZ,IAAI,CAACD,MAAM,GAAGA;IAChB;AACF;AASO,eAAeJ,WAAWM,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,EAAE;YACnE,oEAAoE;YACpE,qDAAqD;YACrDS,OAAO;QACT;QAEA,IAAIC,SAAS;QACb,IAAIC,SAAS;QAEbC,IAAAA,aAAM,EAACP,OAAOK,MAAM,EAAE;QACtBE,IAAAA,aAAM,EAACP,OAAOM,MAAM,EAAE;QAEtBN,OAAOK,MAAM,CAACG,EAAE,CAAC,QAAQ,CAACC;YACxBJ,UAAUI,KAAKC,QAAQ;QACzB;QAEAV,OAAOM,MAAM,CAACE,EAAE,CAAC,QAAQ,CAACC;YACxBH,UAAUG,KAAKC,QAAQ;QACzB;QAEAV,OAAOQ,EAAE,CAAC,QAAQ,CAACG;YACjB,MAAMlB,SAAS;gBACbY;gBACAC;YACF;YAEA,IAAIK,aAAa,GAAG;gBAClB,OAAOb,QAAQL;YACjB;YAEA,OAAOM,OACL,IAAIX,cACF,CAAC,wCAAwC,EAAEuB,SAAS,CAAC,CAAC,EACtDlB;QAGN;IACF;AACF"}
@@ -2,5 +2,64 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
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
+ HandlerType: function() {
13
+ return HandlerType;
14
+ },
15
+ SNAP_EXPORTS: function() {
16
+ return SNAP_EXPORTS;
17
+ }
18
+ });
19
+ var HandlerType;
20
+ (function(HandlerType) {
21
+ HandlerType["OnRpcRequest"] = 'onRpcRequest';
22
+ HandlerType["OnTransaction"] = 'onTransaction';
23
+ HandlerType["OnCronjob"] = 'onCronjob';
24
+ HandlerType["OnInstall"] = 'onInstall';
25
+ HandlerType["OnUpdate"] = 'onUpdate';
26
+ })(HandlerType || (HandlerType = {}));
27
+ const SNAP_EXPORTS = {
28
+ [HandlerType.OnRpcRequest]: {
29
+ type: HandlerType.OnRpcRequest,
30
+ required: true,
31
+ validator: (snapExport)=>{
32
+ return typeof snapExport === 'function';
33
+ }
34
+ },
35
+ [HandlerType.OnTransaction]: {
36
+ type: HandlerType.OnTransaction,
37
+ required: true,
38
+ validator: (snapExport)=>{
39
+ return typeof snapExport === 'function';
40
+ }
41
+ },
42
+ [HandlerType.OnCronjob]: {
43
+ type: HandlerType.OnCronjob,
44
+ required: true,
45
+ validator: (snapExport)=>{
46
+ return typeof snapExport === 'function';
47
+ }
48
+ },
49
+ [HandlerType.OnInstall]: {
50
+ type: HandlerType.OnInstall,
51
+ required: false,
52
+ validator: (snapExport)=>{
53
+ return typeof snapExport === 'function';
54
+ }
55
+ },
56
+ [HandlerType.OnUpdate]: {
57
+ type: HandlerType.OnUpdate,
58
+ required: false,
59
+ validator: (snapExport)=>{
60
+ return typeof snapExport === 'function';
61
+ }
62
+ }
63
+ };
5
64
 
6
65
  //# sourceMappingURL=handlers.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/handlers.ts"],"names":[],"mappings":""}
1
+ {"version":3,"sources":["../../src/handlers.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-ui';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nexport enum HandlerType {\n OnRpcRequest = 'onRpcRequest',\n OnTransaction = 'onTransaction',\n OnCronjob = 'onCronjob',\n OnInstall = 'onInstall',\n OnUpdate = 'onUpdate',\n}\n\ntype SnapHandler = {\n /**\n * The type of handler.\n */\n type: HandlerType;\n\n /**\n * Whether the handler is required, i.e., whether the request will fail if the\n * handler is called, but the snap does not export it.\n *\n * This is primarily used for the lifecycle handlers, which are optional.\n */\n required: boolean;\n\n /**\n * Validate the given snap export. This should return a type guard for the\n * handler type.\n *\n * @param snapExport - The export to validate.\n * @returns Whether the export is valid.\n */\n validator: (snapExport: unknown) => boolean;\n};\n\nexport const SNAP_EXPORTS = {\n [HandlerType.OnRpcRequest]: {\n type: HandlerType.OnRpcRequest,\n required: true,\n validator: (snapExport: unknown): snapExport is OnRpcRequestHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnTransaction]: {\n type: HandlerType.OnTransaction,\n required: true,\n validator: (snapExport: unknown): snapExport is OnTransactionHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnCronjob]: {\n type: HandlerType.OnCronjob,\n required: true,\n validator: (snapExport: unknown): snapExport is OnCronjobHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnInstall]: {\n type: HandlerType.OnInstall,\n required: false,\n validator: (snapExport: unknown): snapExport is OnInstallHandler => {\n return typeof snapExport === 'function';\n },\n },\n [HandlerType.OnUpdate]: {\n type: HandlerType.OnUpdate,\n required: false,\n validator: (snapExport: unknown): snapExport is OnUpdateHandler => {\n return typeof snapExport === 'function';\n },\n },\n} as const;\n\n/**\n * The `onRpcRequest` handler. This is called whenever a JSON-RPC request is\n * made to the snap.\n *\n * @param args - The request arguments.\n * @param args.origin - The origin of the request. This can be the ID of another\n * snap, or the URL of a dapp.\n * @param args.request - The JSON-RPC request sent to the snap.\n * @returns The JSON-RPC response. This must be a JSON-serializable value.\n */\nexport type OnRpcRequestHandler<Params extends JsonRpcParams = JsonRpcParams> =\n (args: {\n origin: string;\n request: JsonRpcRequest<Params>;\n }) => Promise<unknown>;\n\n/**\n * The response from a snap's `onTransaction` handler.\n *\n * @property content - A custom UI component, that will be shown in MetaMask. Can be created using `@metamask/snaps-ui`.\n *\n * If the snap has no insights about the transaction, this should be `null`.\n */\nexport type OnTransactionResponse = {\n content: Component | null;\n};\n\n/**\n * The `onTransaction` handler. This is called whenever a transaction is\n * submitted to the snap. It can return insights about the transaction, which\n * will be displayed to the user.\n *\n * @param args - The request arguments.\n * @param args.transaction - The transaction object.\n * @param args.chainId - The CAIP-2 chain ID of the network the transaction is\n * being submitted to.\n * @param args.transactionOrigin - The origin of the transaction. This is the\n * URL of the dapp that submitted the transaction.\n * @returns Insights about the transaction. See {@link OnTransactionResponse}.\n */\n// TODO: Improve type.\nexport type OnTransactionHandler = (args: {\n transaction: { [key: string]: Json };\n chainId: string;\n transactionOrigin?: string;\n}) => Promise<OnTransactionResponse>;\n\n/**\n * The `onCronjob` handler. This is called on a regular interval, as defined by\n * the snap's manifest.\n *\n * @param args - The request arguments.\n * @param args.request - The JSON-RPC request sent to the snap.\n */\nexport type OnCronjobHandler<Params extends JsonRpcParams = JsonRpcParams> =\n (args: { request: JsonRpcRequest<Params> }) => Promise<unknown>;\n\n/**\n * A handler that can be used for the lifecycle hooks.\n */\nexport type LifecycleEventHandler = (args: {\n request: JsonRpcRequest;\n}) => Promise<unknown>;\n\n/**\n * The `onInstall` handler. This is called after the snap is installed.\n *\n * This type is an alias for {@link LifecycleEventHandler}.\n */\nexport type OnInstallHandler = LifecycleEventHandler;\n\n/**\n * The `onUpdate` handler. This is called after the snap is updated.\n *\n * This type is an alias for {@link LifecycleEventHandler}.\n */\nexport type OnUpdateHandler = LifecycleEventHandler;\n\n/**\n * Utility type for getting the handler function type from a handler type.\n */\nexport type HandlerFunction<Type extends SnapHandler> =\n Type['validator'] extends (snapExport: unknown) => snapExport is infer Handler\n ? Handler\n : never;\n\n/**\n * All the function-based handlers that a snap can implement.\n */\nexport type SnapFunctionExports = {\n [Key in keyof typeof SNAP_EXPORTS]?: HandlerFunction<\n typeof SNAP_EXPORTS[Key]\n >;\n};\n\n/**\n * All handlers that a snap can implement.\n */\nexport type SnapExports = SnapFunctionExports;\n"],"names":["SNAP_EXPORTS","HandlerType","OnRpcRequest","OnTransaction","OnCronjob","OnInstall","OnUpdate","type","required","validator","snapExport"],"mappings":";;;;;;;;;;;;;;IAmCaA,YAAY;eAAZA;;;IAhCN;UAAKC,WAAW;IAAXA,YACVC,kBAAe;IADLD,YAEVE,mBAAgB;IAFNF,YAGVG,eAAY;IAHFH,YAIVI,eAAY;IAJFJ,YAKVK,cAAW;GALDL,gBAAAA;AAgCL,MAAMD,eAAe;IAC1B,CAACC,YAAYC,YAAY,CAAC,EAAE;QAC1BK,MAAMN,YAAYC,YAAY;QAC9BM,UAAU;QACVC,WAAW,CAACC;YACV,OAAO,OAAOA,eAAe;QAC/B;IACF;IACA,CAACT,YAAYE,aAAa,CAAC,EAAE;QAC3BI,MAAMN,YAAYE,aAAa;QAC/BK,UAAU;QACVC,WAAW,CAACC;YACV,OAAO,OAAOA,eAAe;QAC/B;IACF;IACA,CAACT,YAAYG,SAAS,CAAC,EAAE;QACvBG,MAAMN,YAAYG,SAAS;QAC3BI,UAAU;QACVC,WAAW,CAACC;YACV,OAAO,OAAOA,eAAe;QAC/B;IACF;IACA,CAACT,YAAYI,SAAS,CAAC,EAAE;QACvBE,MAAMN,YAAYI,SAAS;QAC3BG,UAAU;QACVC,WAAW,CAACC;YACV,OAAO,OAAOA,eAAe;QAC/B;IACF;IACA,CAACT,YAAYK,QAAQ,CAAC,EAAE;QACtBC,MAAMN,YAAYK,QAAQ;QAC1BE,UAAU;QACVC,WAAW,CAACC;YACV,OAAO,OAAOA,eAAe;QAC/B;IACF;AACF"}
@@ -10,6 +10,7 @@ _export_star(require("./deep-clone"), exports);
10
10
  _export_star(require("./default-endowments"), exports);
11
11
  _export_star(require("./entropy"), exports);
12
12
  _export_star(require("./enum"), exports);
13
+ _export_star(require("./errors"), exports);
13
14
  _export_star(require("./handlers"), exports);
14
15
  _export_star(require("./iframe"), exports);
15
16
  _export_star(require("./json"), exports);
@@ -19,6 +20,8 @@ _export_star(require("./manifest/index.browser"), exports);
19
20
  _export_star(require("./namespace"), exports);
20
21
  _export_star(require("./path"), exports);
21
22
  _export_star(require("./snaps"), exports);
23
+ _export_star(require("./strings"), exports);
24
+ _export_star(require("./structs"), exports);
22
25
  _export_star(require("./types"), exports);
23
26
  _export_star(require("./validation"), exports);
24
27
  _export_star(require("./versions"), exports);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
1
+ {"version":3,"sources":["../../src/index.browser.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './checksum';\nexport * from './cronjob';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './errors';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest/index.browser';\nexport * from './namespace';\nexport * from './path';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file/index.browser';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
package/dist/cjs/index.js CHANGED
@@ -11,6 +11,7 @@ _export_star(require("./default-endowments"), exports);
11
11
  _export_star(require("./entropy"), exports);
12
12
  _export_star(require("./enum"), exports);
13
13
  _export_star(require("./eval"), exports);
14
+ _export_star(require("./errors"), exports);
14
15
  _export_star(require("./fs"), exports);
15
16
  _export_star(require("./handlers"), exports);
16
17
  _export_star(require("./iframe"), exports);
@@ -24,6 +25,8 @@ _export_star(require("./npm"), exports);
24
25
  _export_star(require("./path"), exports);
25
26
  _export_star(require("./post-process"), exports);
26
27
  _export_star(require("./snaps"), exports);
28
+ _export_star(require("./strings"), exports);
29
+ _export_star(require("./structs"), exports);
27
30
  _export_star(require("./types"), exports);
28
31
  _export_star(require("./validation"), exports);
29
32
  _export_star(require("./versions"), exports);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './cronjob';\nexport * from './checksum';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './eval';\nexport * from './fs';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './npm';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
1
+ {"version":3,"sources":["../../src/index.ts"],"sourcesContent":["export * from './array';\nexport * from './caveats';\nexport * from './cronjob';\nexport * from './checksum';\nexport * from './deep-clone';\nexport * from './default-endowments';\nexport * from './entropy';\nexport * from './enum';\nexport * from './eval';\nexport * from './errors';\nexport * from './fs';\nexport * from './handlers';\nexport * from './iframe';\nexport * from './json';\nexport * from './json-rpc';\nexport * from './logging';\nexport * from './manifest';\nexport * from './mock';\nexport * from './namespace';\nexport * from './npm';\nexport * from './path';\nexport * from './post-process';\nexport * from './snaps';\nexport * from './strings';\nexport * from './structs';\nexport * from './types';\nexport * from './validation';\nexport * from './versions';\nexport * from './virtual-file';\n"],"names":[],"mappings":";;;;qBAAc;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA;qBACA"}
@@ -53,7 +53,7 @@ const MANIFEST_SORT_ORDER = {
53
53
  initialPermissions: 7,
54
54
  manifestVersion: 8
55
55
  };
56
- async function checkManifest(basePath, writeManifest = true, sourceCode) {
56
+ async function checkManifest(basePath, writeManifest = true, sourceCode, writeFileFn = _fs.promises.writeFile) {
57
57
  const warnings = [];
58
58
  const errors = [];
59
59
  let updated = false;
@@ -124,7 +124,7 @@ async function checkManifest(basePath, writeManifest = true, sourceCode) {
124
124
  try {
125
125
  const newManifest = `${JSON.stringify(getWritableManifest(validatedManifest), null, 2)}\n`;
126
126
  if (updated || newManifest !== manifestFile.value) {
127
- await _fs.promises.writeFile(_path.default.join(basePath, _types.NpmSnapFileNames.Manifest), newManifest);
127
+ await writeFileFn(_path.default.join(basePath, _types.NpmSnapFileNames.Manifest), newManifest);
128
128
  }
129
129
  } catch (error) {
130
130
  // Note: This error isn't pushed to the errors array, because it's not an
@@ -181,7 +181,7 @@ async function getSnapSourceCode(basePath, manifest, sourceCode) {
181
181
  const virtualFile = await (0, _virtualfile.readVirtualFile)(_path.default.join(basePath, sourceFilePath), 'utf8');
182
182
  return virtualFile;
183
183
  } catch (error) {
184
- throw new Error(`Failed to read Snap bundle file: ${error.message}`);
184
+ throw new Error(`Failed to read snap bundle file: ${error.message}`);
185
185
  }
186
186
  }
187
187
  async function getSnapIcon(basePath, manifest) {
@@ -196,7 +196,7 @@ async function getSnapIcon(basePath, manifest) {
196
196
  const virtualFile = await (0, _virtualfile.readVirtualFile)(_path.default.join(basePath, iconPath), 'utf8');
197
197
  return virtualFile;
198
198
  } catch (error) {
199
- throw new Error(`Failed to read Snap icon file: ${error.message}`);
199
+ throw new Error(`Failed to read snap icon file: ${error.message}`);
200
200
  }
201
201
  }
202
202
  function getWritableManifest(manifest) {