@metamask/snaps-utils 0.32.2 → 0.33.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.
package/CHANGELOG.md ADDED
@@ -0,0 +1,229 @@
1
+ # Changelog
2
+ All notable changes to this project will be documented in this file.
3
+
4
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5
+ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
+
7
+ ## [Unreleased]
8
+
9
+ ## [0.33.0-flask.1]
10
+ ### Changed
11
+ - **BREAKING:** Added `snapIds` caveat mapper ([#1360](https://github.com/MetaMask/snaps-monorepo/pull/1360))
12
+ - Snap dependencies must be specified in a simplified manner. See the PR for an example.
13
+ - Add subject type restrictions to snap-specific permissions ([#1366](https://github.com/MetaMask/snaps-monorepo/pull/1366))
14
+ - Add Web Worker support for snap execution ([#1320](https://github.com/MetaMask/snaps-monorepo/pull/1320))
15
+
16
+ ### Fixed
17
+ - Add `WebAssembly` to eval mock ([#1359](https://github.com/MetaMask/snaps-monorepo/pull/1359))
18
+
19
+ ## [0.32.2]
20
+ ### Changed
21
+ - No changes this release.
22
+
23
+ ## [0.32.1]
24
+ ### Changed
25
+ - No changes this release.
26
+
27
+ ## [0.32.0]
28
+ ### Changed
29
+ - Use side effects to install snaps via `wallet_snap` permission ([#1301](https://github.com/MetaMask/snaps-monorepo/pull/1301))
30
+
31
+ ## [0.31.0]
32
+ ### Changed
33
+ - **BREAKING:** Target `ES2020` ([#1247](https://github.com/MetaMask/snaps-monorepo/pull/1247))
34
+ - Improve validation and sanitizing of snap IDs ([#1237](https://github.com/MetaMask/snaps-monorepo/pull/1237))
35
+
36
+ ## [0.30.0]
37
+ ### Changed
38
+ - Properly sandbox iframe and inline SES in execution bundles ([#1193](https://github.com/MetaMask/snaps-monorepo/pull/1193))
39
+
40
+ ## [0.29.0]
41
+ ### Changed
42
+ - Skip writing manifest if identical ([#1171](https://github.com/MetaMask/snaps-monorepo/pull/1171))
43
+ - This fixes a bug on Windows where the CLI could get stuck in a loop
44
+
45
+ ### Removed
46
+ - **BREAKING:** Remove `SnapsGlobalObject` type ([#1014](https://github.com/MetaMask/snaps-monorepo/pull/1014))
47
+
48
+ ## [0.28.0]
49
+ ### Added
50
+ - **BREAKING:** Add support for snap registries ([#1090](https://github.com/MetaMask/snaps-monorepo/pull/1090))
51
+ - This removes the `checkBlockList` constructor argument in favor of `registry`
52
+ - A registry implementation can be passed here, defaulting to a hosted JSON file
53
+ - Requiring a snap to be on the allowlist can be toggled with the feature flag `requireAllowlist`
54
+ - Add experimental offscreen execution environment ([#1082](https://github.com/MetaMask/snaps-monorepo/pull/1082))
55
+
56
+ ### Changed
57
+ - **BREAKING:** Bump `key-tree` to 6.2.0 and use `Uint8Array` for secret recovery phrases ([#1137](https://github.com/MetaMask/snaps-monorepo/pull/1137))
58
+
59
+ ### Removed
60
+ - **BREAKING:** Remove `WebSocket` endowment ([#1122](https://github.com/MetaMask/snaps-monorepo/pull/1122))
61
+
62
+ ### Fixed
63
+ - Fix missing cronjob export ([#1134](https://github.com/MetaMask/snaps-monorepo/pull/1134))
64
+
65
+ ## [0.27.1]
66
+ ### Changed
67
+ - No changes this release.
68
+
69
+ ## [0.27.0]
70
+ ### Changed
71
+ - **BREAKING:** Use SIP-6 algorithm for state encryption ([#1055](https://github.com/MetaMask/snaps-monorepo/pull/1055))
72
+ - This breaks all existing snaps that use `snap_manageState`
73
+ - **BREAKING:** Use custom UI in transaction insights ([#1047](https://github.com/MetaMask/snaps-monorepo/pull/1047))
74
+ - **BREAKING:** Move all internal types from `snaps-types` to `snaps-utils` ([#1060](https://github.com/MetaMask/snaps-monorepo/pull/1060))
75
+
76
+ ## [0.26.2]
77
+ ### Changed
78
+ - No changes this release.
79
+
80
+ ## [0.26.1]
81
+ ### Fixed
82
+ - Fix some paths being wrongly normalized ([#1053](https://github.com/MetaMask/snaps-monorepo/pull/1053))
83
+ - Fix utils browser export ([#1049](https://github.com/MetaMask/snaps-monorepo/pull/1049))
84
+
85
+ ## [0.26.0]
86
+ ### Fixed
87
+ - Fix post processing issue with `object.eval` ([#1040](https://github.com/MetaMask/snaps-monorepo/pull/1040))
88
+
89
+ ## [0.25.0]
90
+ ### Added
91
+ - **BREAKING:** Add JSON-RPC handler permission ([#905](https://github.com/MetaMask/snaps-monorepo/pull/905))
92
+ - Snaps are now required to request `endowment:rpc` to receive RPC requests.
93
+
94
+ ## [0.24.1]
95
+ ### Fixed
96
+ - Fix `snap_getBip32PublicKey` manifest validation ([#970](https://github.com/MetaMask/snaps-monorepo/pull/970))
97
+
98
+ ## [0.24.0]
99
+ ### Added
100
+ - Add transaction insight caveat for accessing transaction origin ([#902](https://github.com/MetaMask/snaps-monorepo/pull/902))
101
+ - Add `snap_getEntropy` JSON-RPC method ([#940](https://github.com/MetaMask/snaps-monorepo/pull/940))
102
+ - Add permission validation to `snap.manifest.json` ([#910](https://github.com/MetaMask/snaps-monorepo/pull/910))
103
+ - Add compile-time warning when using `Math.random` ([#950](https://github.com/MetaMask/snaps-monorepo/pull/950))
104
+
105
+ ### Changed
106
+ - **BREAKING:** Rename package to start with `snaps-` ([#937](https://github.com/MetaMask/snaps-monorepo/pull/937))
107
+ - **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))
108
+
109
+ ## [0.23.0]
110
+ ### Added
111
+ - Add snap cronjobs ([#651](https://github.com/MetaMask/snaps-monorepo/pull/651))
112
+
113
+ ### Changed
114
+ - **BREAKING:** Replace Buffer with Typed Arrays ([#878](https://github.com/MetaMask/snaps-monorepo/pull/878))
115
+ - Improve keyring endowment error messaging ([#884](https://github.com/MetaMask/snaps-monorepo/pull/884))
116
+ - Replace JSON schema validation with structs ([#862](https://github.com/MetaMask/snaps-monorepo/pull/862))
117
+
118
+ ### Removed
119
+ - **BREAKING:** Stop including source code in SnapController state ([#861](https://github.com/MetaMask/snaps-monorepo/pull/861))
120
+
121
+ ## [0.22.3]
122
+ ### Fixed
123
+ - Make @babel/types a regular dependency ([#852](https://github.com/MetaMask/snaps-monorepo/pull/852))
124
+
125
+ ## [0.22.2]
126
+ ### Changed
127
+ - No changes this release.
128
+
129
+ ## [0.22.1]
130
+ ### Fixed
131
+ - Add browser entry point for `snap-utils` ([#820](https://github.com/MetaMask/snaps-monorepo/pull/820))
132
+
133
+ ## [0.22.0]
134
+ ### Added
135
+ - 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))
136
+
137
+ ## [0.21.0]
138
+ ### Changed
139
+ - Run eval and fix manifest in bundler plugins ([#731](https://github.com/MetaMask/snaps-monorepo/pull/731))
140
+
141
+ ## [0.20.0]
142
+ ### Added
143
+ - **BREAKING:** Add Transaction Insight API ([#642](https://github.com/MetaMask/snaps-monorepo/pull/642))
144
+ - Add internal types from `@metamask/snaps-types` ([#695](https://github.com/MetaMask/snaps-monorepo/pull/695))
145
+
146
+ ### Changed
147
+ - **BREAKING:** Simplify manifest format for permission caveats ([#705](https://github.com/MetaMask/snaps-monorepo/pull/705))
148
+ - Reduce TypeScript compilation target for `snap-controllers` ([#708](https://github.com/MetaMask/snaps-monorepo/pull/708))
149
+
150
+ ## [0.19.1]
151
+ ### Added
152
+ - Generate source maps from modified code ([#615](https://github.com/MetaMask/snaps-monorepo/pull/615))
153
+
154
+ ## [0.19.0]
155
+ ### Changed
156
+ - Move eval functionality to utils package ([#666](https://github.com/MetaMask/snaps-monorepo/pull/666))
157
+ - Move manifest handling functionality to utils ([#652](https://github.com/MetaMask/snaps-monorepo/pull/652))
158
+ - Move JSON schemas and controller utils to utils package ([#623](https://github.com/MetaMask/snaps-monorepo/pull/623))
159
+
160
+ ### Fixed
161
+ - Fixed missing AbortSignal in default endowments ([#682](https://github.com/MetaMask/snaps-monorepo/pull/682))
162
+
163
+ ## [0.18.1]
164
+ ### Changed
165
+ - No changes this release.
166
+
167
+ ## [0.18.0]
168
+ ### Changed
169
+ - Reduce TypeScript compilation target to ES2017 ([#628](https://github.com/MetaMask/snaps-monorepo/pull/628))
170
+
171
+ ## [0.17.0]
172
+ ### Changed
173
+ - **BREAKING:** Bump minimum Node version to 16 ([#601](https://github.com/MetaMask/snaps-monorepo/pull/601))
174
+
175
+ ## [0.16.0]
176
+ ### Changed
177
+ - No changes this release.
178
+
179
+ ## [0.15.0]
180
+ ### Fixed
181
+ - Fix an issue where comment stripping would break for large files ([#468](https://github.com/MetaMask/snaps-monorepo/pull/468))
182
+
183
+ ## [0.14.0]
184
+ ### Changed
185
+ - **BREAKING:** Increase TypeScript compilation target to ES2020 ([#449](https://github.com/MetaMask/snaps-monorepo/pull/449))
186
+ - This should not be breaking for consumers on any non-deprecated browser or Node.js version.
187
+
188
+ ## [0.13.0]
189
+ ### Changed
190
+ - No changes this release.
191
+
192
+ ## [0.12.0]
193
+ ### Added
194
+ - Initial release ([#410](https://github.com/MetaMask/snaps-monorepo/pull/410), [#421](https://github.com/MetaMask/snaps-monorepo/pull/421))
195
+
196
+ [Unreleased]: https://github.com/MetaMask/snaps-monorepo/compare/v0.33.0-flask.1...HEAD
197
+ [0.33.0-flask.1]: https://github.com/MetaMask/snaps-monorepo/compare/v0.32.2...v0.33.0-flask.1
198
+ [0.32.2]: https://github.com/MetaMask/snaps-monorepo/compare/v0.32.1...v0.32.2
199
+ [0.32.1]: https://github.com/MetaMask/snaps-monorepo/compare/v0.32.0...v0.32.1
200
+ [0.32.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.31.0...v0.32.0
201
+ [0.31.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.30.0...v0.31.0
202
+ [0.30.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.29.0...v0.30.0
203
+ [0.29.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.28.0...v0.29.0
204
+ [0.28.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.27.1...v0.28.0
205
+ [0.27.1]: https://github.com/MetaMask/snaps-monorepo/compare/v0.27.0...v0.27.1
206
+ [0.27.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.26.2...v0.27.0
207
+ [0.26.2]: https://github.com/MetaMask/snaps-monorepo/compare/v0.26.1...v0.26.2
208
+ [0.26.1]: https://github.com/MetaMask/snaps-monorepo/compare/v0.26.0...v0.26.1
209
+ [0.26.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.25.0...v0.26.0
210
+ [0.25.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.24.1...v0.25.0
211
+ [0.24.1]: https://github.com/MetaMask/snaps-monorepo/compare/v0.24.0...v0.24.1
212
+ [0.24.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.23.0...v0.24.0
213
+ [0.23.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.22.3...v0.23.0
214
+ [0.22.3]: https://github.com/MetaMask/snaps-monorepo/compare/v0.22.2...v0.22.3
215
+ [0.22.2]: https://github.com/MetaMask/snaps-monorepo/compare/v0.22.1...v0.22.2
216
+ [0.22.1]: https://github.com/MetaMask/snaps-monorepo/compare/v0.22.0...v0.22.1
217
+ [0.22.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.21.0...v0.22.0
218
+ [0.21.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.20.0...v0.21.0
219
+ [0.20.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.19.1...v0.20.0
220
+ [0.19.1]: https://github.com/MetaMask/snaps-monorepo/compare/v0.19.0...v0.19.1
221
+ [0.19.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.18.1...v0.19.0
222
+ [0.18.1]: https://github.com/MetaMask/snaps-monorepo/compare/v0.18.0...v0.18.1
223
+ [0.18.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.17.0...v0.18.0
224
+ [0.17.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.16.0...v0.17.0
225
+ [0.16.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.15.0...v0.16.0
226
+ [0.15.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.14.0...v0.15.0
227
+ [0.14.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.13.0...v0.14.0
228
+ [0.13.0]: https://github.com/MetaMask/snaps-monorepo/compare/v0.12.0...v0.13.0
229
+ [0.12.0]: https://github.com/MetaMask/snaps-monorepo/releases/tag/v0.12.0
package/dist/iframe.d.ts CHANGED
@@ -4,7 +4,8 @@
4
4
  * an initialization timeout in the SnapController.
5
5
  *
6
6
  * @param uri - The iframe URI.
7
- * @param jobId - The job id.
7
+ * @param id - The ID to assign to the iframe.
8
+ * @param sandbox - Whether to enable the sandbox attribute.
8
9
  * @returns A promise that resolves to the contentWindow of the iframe.
9
10
  */
10
- export declare function createWindow(uri: string, jobId: string): Promise<Window>;
11
+ export declare function createWindow(uri: string, id: string, sandbox?: boolean): Promise<Window>;
package/dist/iframe.js CHANGED
@@ -7,21 +7,24 @@ exports.createWindow = void 0;
7
7
  * an initialization timeout in the SnapController.
8
8
  *
9
9
  * @param uri - The iframe URI.
10
- * @param jobId - The job id.
10
+ * @param id - The ID to assign to the iframe.
11
+ * @param sandbox - Whether to enable the sandbox attribute.
11
12
  * @returns A promise that resolves to the contentWindow of the iframe.
12
13
  */
13
- async function createWindow(uri, jobId) {
14
+ async function createWindow(uri, id, sandbox = true) {
14
15
  return await new Promise((resolve, reject) => {
15
16
  const iframe = document.createElement('iframe');
16
17
  // The order of operations appears to matter for everything except this
17
18
  // attribute. We may as well set it here.
18
- iframe.setAttribute('id', jobId);
19
+ iframe.setAttribute('id', id);
19
20
  iframe.setAttribute('data-testid', 'snaps-iframe');
20
- // For the sandbox property to have any effect it needs to be set before the iframe is appended.
21
- // We apply this property as a principle of least authority (POLA)
22
- // measure.
23
- // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox
24
- iframe.setAttribute('sandbox', 'allow-scripts');
21
+ if (sandbox) {
22
+ // For the sandbox property to have any effect it needs to be set before the iframe is appended.
23
+ // We apply this property as a principle of least authority (POLA)
24
+ // measure.
25
+ // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox
26
+ iframe.setAttribute('sandbox', 'allow-scripts');
27
+ }
25
28
  // In the past, we've had problems that appear to be symptomatic of the
26
29
  // iframe firing the `load` event before its scripts are actually loaded,
27
30
  // which has prevented snaps from executing properly. Therefore, we set
@@ -42,7 +45,7 @@ async function createWindow(uri, jobId) {
42
45
  else {
43
46
  // We don't know of a case when this would happen, but better to fail
44
47
  // fast if it does.
45
- reject(new Error(`iframe.contentWindow not present on load for job "${jobId}".`));
48
+ reject(new Error(`iframe.contentWindow not present on load for job "${id}".`));
46
49
  }
47
50
  });
48
51
  });
@@ -1 +1 @@
1
- {"version":3,"file":"iframe.js","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;GAQG;AACI,KAAK,UAAU,YAAY,CAChC,GAAW,EACX,KAAa;IAEb,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QACjC,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;QAEnD,gGAAgG;QAChG,kEAAkE;QAClE,WAAW;QACX,qFAAqF;QACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;QAEhD,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACnC,IAAI,MAAM,CAAC,aAAa,EAAE;gBACxB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;aAC/B;iBAAM;gBACL,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,KAAK,IAAI,CAC/D,CACF,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AA7CD,oCA6CC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n * @param uri - The iframe URI.\n * @param jobId - The job id.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow(\n uri: string,\n jobId: string,\n): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', jobId);\n iframe.setAttribute('data-testid', 'snaps-iframe');\n\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${jobId}\".`,\n ),\n );\n }\n });\n });\n}\n"]}
1
+ {"version":3,"file":"iframe.js","sourceRoot":"","sources":["../src/iframe.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;GASG;AACI,KAAK,UAAU,YAAY,CAChC,GAAW,EACX,EAAU,EACV,OAAO,GAAG,IAAI;IAEd,OAAO,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QAC3C,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QAChD,uEAAuE;QACvE,yCAAyC;QACzC,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC9B,MAAM,CAAC,YAAY,CAAC,aAAa,EAAE,cAAc,CAAC,CAAC;QAEnD,IAAI,OAAO,EAAE;YACX,gGAAgG;YAChG,kEAAkE;YAClE,WAAW;YACX,qFAAqF;YACrF,MAAM,CAAC,YAAY,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;SACjD;QAED,uEAAuE;QACvE,yEAAyE;QACzE,uEAAuE;QACvE,wEAAwE;QACxE,uBAAuB;QACvB,EAAE;QACF,mEAAmE;QACnE,kCAAkC;QAClC,EAAE;QACF,mGAAmG;QACnG,iJAAiJ;QACjJ,MAAM,CAAC,YAAY,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;QAElC,MAAM,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YACnC,IAAI,MAAM,CAAC,aAAa,EAAE;gBACxB,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC;aAC/B;iBAAM;gBACL,qEAAqE;gBACrE,mBAAmB;gBACnB,MAAM,CACJ,IAAI,KAAK,CACP,qDAAqD,EAAE,IAAI,CAC5D,CACF,CAAC;aACH;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAhDD,oCAgDC","sourcesContent":["/**\n * Creates the iframe to be used as the execution environment. This may run\n * forever if the iframe never loads, but the promise should be wrapped in\n * an initialization timeout in the SnapController.\n *\n * @param uri - The iframe URI.\n * @param id - The ID to assign to the iframe.\n * @param sandbox - Whether to enable the sandbox attribute.\n * @returns A promise that resolves to the contentWindow of the iframe.\n */\nexport async function createWindow(\n uri: string,\n id: string,\n sandbox = true,\n): Promise<Window> {\n return await new Promise((resolve, reject) => {\n const iframe = document.createElement('iframe');\n // The order of operations appears to matter for everything except this\n // attribute. We may as well set it here.\n iframe.setAttribute('id', id);\n iframe.setAttribute('data-testid', 'snaps-iframe');\n\n if (sandbox) {\n // For the sandbox property to have any effect it needs to be set before the iframe is appended.\n // We apply this property as a principle of least authority (POLA)\n // measure.\n // Ref: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe#attr-sandbox\n iframe.setAttribute('sandbox', 'allow-scripts');\n }\n\n // In the past, we've had problems that appear to be symptomatic of the\n // iframe firing the `load` event before its scripts are actually loaded,\n // which has prevented snaps from executing properly. Therefore, we set\n // the `src` attribute and append the iframe to the DOM before attaching\n // the `load` listener.\n //\n // `load` should only fire when \"all dependent resources\" have been\n // loaded, which includes scripts.\n //\n // MDN article for `load` event: https://developer.mozilla.org/en-US/docs/Web/API/Window/load_event\n // Re: `load` firing twice: https://stackoverflow.com/questions/10781880/dynamically-created-iframe-triggers-onload-event-twice/15880489#15880489\n iframe.setAttribute('src', uri);\n document.body.appendChild(iframe);\n\n iframe.addEventListener('load', () => {\n if (iframe.contentWindow) {\n resolve(iframe.contentWindow);\n } else {\n // We don't know of a case when this would happen, but better to fail\n // fast if it does.\n reject(\n new Error(\n `iframe.contentWindow not present on load for job \"${id}\".`,\n ),\n );\n }\n });\n });\n}\n"]}
@@ -28,6 +28,11 @@ export declare const SnapGetBip32EntropyPermissionsStruct: Struct<{
28
28
  secp256k1: "secp256k1";
29
29
  }>;
30
30
  }>>;
31
+ export declare const SemVerRangeStruct: Struct<string, null>;
32
+ export declare const SnapIdsStruct: Struct<Record<string, {
33
+ version?: string | undefined;
34
+ }>, null>;
35
+ export declare type SnapIds = Infer<typeof SnapIdsStruct>;
31
36
  export declare const PermissionsStruct: Struct<{
32
37
  'endowment:long-running'?: {} | undefined;
33
38
  'endowment:network-access'?: {} | undefined;
@@ -76,6 +81,9 @@ export declare const PermissionsStruct: Struct<{
76
81
  events?: string[] | undefined;
77
82
  }>;
78
83
  } | undefined;
84
+ wallet_snap?: Record<string, {
85
+ version?: string | undefined;
86
+ }> | undefined;
79
87
  }, {
80
88
  'endowment:long-running': Struct<{} | undefined, {}>;
81
89
  'endowment:network-access': Struct<{} | undefined, {}>;
@@ -191,6 +199,9 @@ export declare const PermissionsStruct: Struct<{
191
199
  events?: string[] | undefined;
192
200
  }>, null>;
193
201
  }>;
202
+ wallet_snap: Struct<Record<string, {
203
+ version?: string | undefined;
204
+ }> | undefined, null>;
194
205
  }>;
195
206
  export declare type SnapPermissions = Infer<typeof PermissionsStruct>;
196
207
  export declare const SnapManifestStruct: Struct<{
@@ -200,9 +211,9 @@ export declare const SnapManifestStruct: Struct<{
200
211
  source: {
201
212
  location: {
202
213
  npm: {
214
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
203
215
  filePath: string;
204
216
  packageName: string;
205
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
206
217
  iconPath?: string | undefined;
207
218
  };
208
219
  };
@@ -256,6 +267,9 @@ export declare const SnapManifestStruct: Struct<{
256
267
  events?: string[] | undefined;
257
268
  }>;
258
269
  } | undefined;
270
+ wallet_snap?: Record<string, {
271
+ version?: string | undefined;
272
+ }> | undefined;
259
273
  };
260
274
  manifestVersion: "0.1";
261
275
  repository?: {
@@ -276,9 +290,9 @@ export declare const SnapManifestStruct: Struct<{
276
290
  source: Struct<{
277
291
  location: {
278
292
  npm: {
293
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
279
294
  filePath: string;
280
295
  packageName: string;
281
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
282
296
  iconPath?: string | undefined;
283
297
  };
284
298
  };
@@ -287,16 +301,16 @@ export declare const SnapManifestStruct: Struct<{
287
301
  shasum: Struct<string, null>;
288
302
  location: Struct<{
289
303
  npm: {
304
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
290
305
  filePath: string;
291
306
  packageName: string;
292
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
293
307
  iconPath?: string | undefined;
294
308
  };
295
309
  }, {
296
310
  npm: Struct<{
311
+ registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
297
312
  filePath: string;
298
313
  packageName: string;
299
- registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
300
314
  iconPath?: string | undefined;
301
315
  }, {
302
316
  filePath: Struct<string, null>;
@@ -354,6 +368,9 @@ export declare const SnapManifestStruct: Struct<{
354
368
  events?: string[] | undefined;
355
369
  }>;
356
370
  } | undefined;
371
+ wallet_snap?: Record<string, {
372
+ version?: string | undefined;
373
+ }> | undefined;
357
374
  }, {
358
375
  'endowment:long-running': Struct<{} | undefined, {}>;
359
376
  'endowment:network-access': Struct<{} | undefined, {}>;
@@ -469,6 +486,9 @@ export declare const SnapManifestStruct: Struct<{
469
486
  events?: string[] | undefined;
470
487
  }>, null>;
471
488
  }>;
489
+ wallet_snap: Struct<Record<string, {
490
+ version?: string | undefined;
491
+ }> | undefined, null>;
472
492
  }>;
473
493
  manifestVersion: Struct<"0.1", "0.1">;
474
494
  }>;
@@ -1,12 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createSnapManifest = exports.assertIsSnapManifest = exports.isSnapManifest = exports.SnapManifestStruct = exports.PermissionsStruct = exports.SnapGetBip32EntropyPermissionsStruct = exports.Bip32EntropyStruct = exports.bip32entropy = exports.Bip32PathStruct = void 0;
3
+ exports.createSnapManifest = exports.assertIsSnapManifest = exports.isSnapManifest = exports.SnapManifestStruct = exports.PermissionsStruct = exports.SnapIdsStruct = exports.SemVerRangeStruct = exports.SnapGetBip32EntropyPermissionsStruct = exports.Bip32EntropyStruct = exports.bip32entropy = exports.Bip32PathStruct = void 0;
4
4
  const utils_1 = require("@metamask/utils");
5
5
  const superstruct_1 = require("superstruct");
6
6
  const cronjob_1 = require("../cronjob");
7
7
  const entropy_1 = require("../entropy");
8
8
  const json_rpc_1 = require("../json-rpc");
9
9
  const namespace_1 = require("../namespace");
10
+ const snaps_1 = require("../snaps");
10
11
  const types_1 = require("../types");
11
12
  // BIP-43 purposes that cannot be used for entropy derivation. These are in the
12
13
  // string form, ending with `'`.
@@ -47,6 +48,18 @@ exports.Bip32EntropyStruct = (0, exports.bip32entropy)((0, superstruct_1.type)({
47
48
  curve: (0, superstruct_1.enums)(['ed25519', 'secp256k1']),
48
49
  }));
49
50
  exports.SnapGetBip32EntropyPermissionsStruct = (0, superstruct_1.size)((0, superstruct_1.array)(exports.Bip32EntropyStruct), 1, Infinity);
51
+ exports.SemVerRangeStruct = (0, superstruct_1.refine)((0, superstruct_1.string)(), 'SemVer range', (value) => {
52
+ if ((0, utils_1.isValidSemVerRange)(value)) {
53
+ return true;
54
+ }
55
+ return 'Expected a valid SemVer range.';
56
+ });
57
+ exports.SnapIdsStruct = (0, superstruct_1.refine)((0, superstruct_1.record)(snaps_1.SnapIdStruct, (0, superstruct_1.object)({ version: (0, superstruct_1.optional)(exports.SemVerRangeStruct) })), 'SnapIds', (value) => {
58
+ if (Object.keys(value).length === 0) {
59
+ return false;
60
+ }
61
+ return true;
62
+ });
50
63
  /* eslint-disable @typescript-eslint/naming-convention */
51
64
  exports.PermissionsStruct = (0, superstruct_1.type)({
52
65
  'endowment:long-running': (0, superstruct_1.optional)((0, superstruct_1.object)({})),
@@ -69,6 +82,7 @@ exports.PermissionsStruct = (0, superstruct_1.type)({
69
82
  'endowment:keyring': (0, superstruct_1.optional)((0, superstruct_1.object)({
70
83
  namespaces: namespace_1.NamespacesStruct,
71
84
  })),
85
+ wallet_snap: (0, superstruct_1.optional)(exports.SnapIdsStruct),
72
86
  });
73
87
  exports.SnapManifestStruct = (0, superstruct_1.object)({
74
88
  version: utils_1.VersionStruct,
@@ -1 +1 @@
1
- {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":";;;AAAA,2CAA8E;AAC9E,6CAkBqB;AAErB,wCAA6D;AAC7D,wCAA6E;AAC7E,0CAA+C;AAC/C,4CAAgD;AAChD,oCAAwD;AAExD,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,kBAAkB,GAAa;IACnC,2BAAiB;IACjB,sCAA4B;CAC7B,CAAC;AAEF,MAAM,iBAAiB,GAAG,UAAU,CAAC;AACxB,QAAA,eAAe,GAAG,IAAA,oBAAM,EACnC,IAAA,mBAAK,EAAC,IAAA,oBAAM,GAAE,CAAC,EACf,aAAa,EACb,CAAC,IAAI,EAAE,EAAE;IACP,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE;QACrB,OAAO,uDAAuD,CAAC;KAChE;IAED,IAAI,IAAI,CAAC,CAAC,CAAC,KAAK,GAAG,EAAE;QACnB,OAAO,2BAA2B,CAAC;KACpC;IAED,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE;QACnB,OAAO,6CAA6C,CAAC;KACtD;IAED,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,EAAE;QAC/D,OAAO,oDAAoD,CAAC;KAC7D;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AFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,IAAI,wBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AARD,oDAQC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AAC3C,CAAC;AAHD,gDAGC","sourcesContent":["import { assertStruct, ChecksumStruct, VersionStruct } from '@metamask/utils';\nimport {\n array,\n boolean,\n create,\n enums,\n Infer,\n integer,\n is,\n literal,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n Struct,\n type,\n union,\n} from 'superstruct';\n\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { RpcOriginsStruct } from '../json-rpc';\nimport { NamespacesStruct } from '../namespace';\nimport { NameStruct, NpmSnapFileNames } from '../types';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nconst BIP32_INDEX_REGEX = /^\\d+'?$/u;\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !BIP32_INDEX_REGEX.test(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <T extends { path: string[]; curve: string }, S>(\n struct: Struct<T, S>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: enums(['ed25519', 'secp256k1']),\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct = type({\n 'endowment:long-running': optional(object({})),\n 'endowment:network-access': optional(object({})),\n 'endowment:webassembly': optional(object({})),\n 'endowment:transaction-insight': optional(\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n 'endowment:cronjob': optional(\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n 'endowment:rpc': optional(RpcOriginsStruct),\n snap_dialog: optional(object({})),\n // TODO: Remove\n snap_confirm: optional(object({})),\n snap_manageState: optional(object({})),\n snap_notify: optional(object({})),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(object({})),\n 'endowment:keyring': optional(\n object({\n namespaces: NamespacesStruct,\n }),\n ),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = Infer<typeof PermissionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(\n pattern(\n string(),\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u,\n ),\n 1,\n 214,\n ),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: ChecksumStruct,\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n }),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"]}
1
+ {"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":";;;AAAA,2CAKyB;AACzB,6CAmBqB;AAErB,wCAA6D;AAC7D,wCAA6E;AAC7E,0CAA+C;AAC/C,4CAAgD;AAChD,oCAAwC;AACxC,oCAAwD;AAExD,+E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SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,IAAI,wBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AARD,oDAQC;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AAC3C,CAAC;AAHD,gDAGC","sourcesContent":["import {\n assertStruct,\n ChecksumStruct,\n VersionStruct,\n isValidSemVerRange,\n} from '@metamask/utils';\nimport {\n array,\n boolean,\n create,\n enums,\n Infer,\n integer,\n is,\n literal,\n object,\n optional,\n pattern,\n refine,\n record,\n size,\n string,\n Struct,\n type,\n union,\n} from 'superstruct';\n\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { RpcOriginsStruct } from '../json-rpc';\nimport { NamespacesStruct } from '../namespace';\nimport { SnapIdStruct } from '../snaps';\nimport { NameStruct, NpmSnapFileNames } from '../types';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nconst BIP32_INDEX_REGEX = /^\\d+'?$/u;\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !BIP32_INDEX_REGEX.test(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <T extends { path: string[]; curve: string }, S>(\n struct: Struct<T, S>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: enums(['ed25519', 'secp256k1']),\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\nexport const SemVerRangeStruct = refine(string(), 'SemVer range', (value) => {\n if (isValidSemVerRange(value)) {\n return true;\n }\n return 'Expected a valid SemVer range.';\n});\n\nexport const SnapIdsStruct = refine(\n record(SnapIdStruct, object({ version: optional(SemVerRangeStruct) })),\n 'SnapIds',\n (value) => {\n if (Object.keys(value).length === 0) {\n return false;\n }\n\n return true;\n },\n);\n\nexport type SnapIds = Infer<typeof SnapIdsStruct>;\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct = type({\n 'endowment:long-running': optional(object({})),\n 'endowment:network-access': optional(object({})),\n 'endowment:webassembly': optional(object({})),\n 'endowment:transaction-insight': optional(\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n 'endowment:cronjob': optional(\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n 'endowment:rpc': optional(RpcOriginsStruct),\n snap_dialog: optional(object({})),\n // TODO: Remove\n snap_confirm: optional(object({})),\n snap_manageState: optional(object({})),\n snap_notify: optional(object({})),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(object({})),\n 'endowment:keyring': optional(\n object({\n namespaces: NamespacesStruct,\n }),\n ),\n wallet_snap: optional(SnapIdsStruct),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = Infer<typeof PermissionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(\n pattern(\n string(),\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u,\n ),\n 1,\n 214,\n ),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: ChecksumStruct,\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n }),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"]}
package/dist/mock.js CHANGED
@@ -7,8 +7,12 @@ exports.generateMockEndowments = exports.isConstructor = exports.ALL_APIS = void
7
7
  const crypto_1 = __importDefault(require("crypto"));
8
8
  const events_1 = __importDefault(require("events"));
9
9
  const default_endowments_1 = require("./default-endowments");
10
- const NETWORK_APIS = ['fetch'];
11
- exports.ALL_APIS = [...default_endowments_1.DEFAULT_ENDOWMENTS, ...NETWORK_APIS];
10
+ const NETWORK_APIS = ['fetch', 'Request', 'Headers', 'Response'];
11
+ exports.ALL_APIS = [
12
+ ...default_endowments_1.DEFAULT_ENDOWMENTS,
13
+ ...NETWORK_APIS,
14
+ 'WebAssembly',
15
+ ];
12
16
  /**
13
17
  * Get a mock snap API, that always returns `true` for requests.
14
18
  *
package/dist/mock.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,oDAAkC;AAElC,6DAA0D;AAE1D,MAAM,YAAY,GAAG,CAAC,OAAO,CAAC,CAAC;AAElB,QAAA,QAAQ,GAAa,CAAC,GAAG,uCAAkB,EAAE,GAAG,YAAY,CAAC,CAAC;AAU3E;;;;GAIG;AACH,SAAS,iBAAiB;IACxB,4DAA4D;IAC5D,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,SAAS,uBAAuB;IAC9B,MAAM,YAAY,GAAG,IAAI,gBAAY,EAAmC,CAAC;IACzE,4DAA4D;IAC5D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AAI,GAAG,OAAO,cAAc,CAAC;IACnC,MAAM,UAAU,GAAG,IAAI,KAAK,UAAU,CAAC;IACvC,IAAI,UAAU,IAAI,IAAA,qBAAa,EAAC,cAAc,CAAC,EAAE;QAC/C,OAAO,iBAAiB,CAAC,cAAc,CAAC,CAAC;KAC1C;SAAM,IAAI,UAAU,IAAI,CAAC,cAAc,EAAE;QACxC,qCAAqC;QACrC,OAAO,YAAY,CAAC;KACrB;IACD,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,OAAO,gBAAQ,CAAC,MAAM,CACpB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC,EAC7D,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,QAAQ,EAAE,uBAAuB,EAAE,EAAE,CACnE,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,sBAAsB,0BAKjC","sourcesContent":["import crypto from 'crypto';\nimport EventEmitter from 'events';\n\nimport { DEFAULT_ENDOWMENTS } from './default-endowments';\n\nconst NETWORK_APIS = ['fetch'];\n\nexport const ALL_APIS: string[] = [...DEFAULT_ENDOWMENTS, ...NETWORK_APIS];\n\ntype MockSnapGlobal = {\n request: () => Promise<any>;\n};\n\ntype MockEthereumProvider = EventEmitter & {\n request: () => Promise<any>;\n};\n\n/**\n * Get a mock snap API, that always returns `true` for requests.\n *\n * @returns A mocked snap provider.\n */\nfunction getMockSnapGlobal(): MockSnapGlobal {\n // eslint-disable-next-line @typescript-eslint/require-await\n return { request: async () => true };\n}\n\n/**\n * Get a mock Ethereum provider, that always returns `true` for requests.\n *\n * @returns A mocked ethereum provider.\n */\nfunction getMockEthereumProvider(): MockEthereumProvider {\n const mockProvider = new EventEmitter() as Partial<MockEthereumProvider>;\n // eslint-disable-next-line @typescript-eslint/require-await\n mockProvider.request = async () => true;\n return mockProvider as MockEthereumProvider;\n}\n\n/**\n * Check if a value is a constructor.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nexport const isConstructor = (value: any) =>\n Boolean(typeof value?.prototype?.constructor?.name === 'string');\n\n/**\n * A function that always returns `true`.\n *\n * @returns `true`.\n */\nconst mockFunction = () => true;\nclass MockClass {}\n\nconst handler = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n construct(Target: any, args: any[]): any {\n return new Proxy(new Target(...args), handler);\n },\n get(_target: any, _prop: any) {\n return mockFunction;\n },\n};\n\n/**\n * Generate a mock class for a given value. The value is wrapped in a Proxy, and\n * all methods are replaced with a mock function.\n *\n * @param value - The value to mock.\n * @returns A mock class.\n */\nconst generateMockClass = (value: any) => {\n return new Proxy(value, handler);\n};\n\n// Things not currently auto-mocked because of NodeJS, by adding them here we\n// have types for them and can use that to generate mocks if needed.\nconst mockWindow: Record<string, unknown> = {\n crypto,\n SubtleCrypto: MockClass,\n};\n\n/**\n * Generate a mock endowment for a certain class or function on the `globalThis`\n * object.\n *\n * @param key - The key to generate the mock endowment for.\n * @returns A mocked class or function. If the key is part of the default\n * endowments, the original value is returned.\n */\nconst generateMockEndowment = (key: string) => {\n const globalValue = (globalThis as any)[key];\n\n // Default exposed APIs don't need to be mocked\n if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {\n return globalValue;\n }\n\n // Fall back to mockWindow for certain APIs not exposed in global in Node.JS\n const globalOrMocked = globalValue ?? mockWindow[key];\n\n const type = typeof globalOrMocked;\n const isFunction = type === 'function';\n if (isFunction && isConstructor(globalOrMocked)) {\n return generateMockClass(globalOrMocked);\n } else if (isFunction || !globalOrMocked) {\n // Fall back to function mock for now\n return mockFunction;\n }\n return globalOrMocked;\n};\n\n/**\n * Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.\n *\n * @returns A map of endowments.\n */\nexport const generateMockEndowments = () => {\n return ALL_APIS.reduce<Record<string, any>>(\n (acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),\n { snap: getMockSnapGlobal(), ethereum: getMockEthereumProvider() },\n );\n};\n"]}
1
+ {"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,oDAAkC;AAElC,6DAA0D;AAE1D,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AAEpD,QAAA,QAAQ,GAAa;IAChC,GAAG,uCAAkB;IACrB,GAAG,YAAY;IACf,aAAa;CACd,CAAC;AAUF;;;;GAIG;AACH,SAAS,iBAAiB;IACxB,4DAA4D;IAC5D,OAAO,EAAE,OAAO,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC;AACvC,CAAC;AAED;;;;GAIG;AACH,SAAS,uBAAuB;IAC9B,MAAM,YAAY,GAAG,IAAI,gBAAY,EAAmC,CAAC;IACzE,4DAA4D;IAC5D,YAAY,CAAC,OAAO,GAAG,KAAK,IAAI,EAAE,CAAC,IAAI,CAAC;IACxC,OAAO,YAAoC,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACI,MAAM,aAAa,GAAG,CAAC,KAAU,EAAE,EAAE,CAC1C,OAAO,CAAC,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,KAAK,QAAQ,CAAC,CAAC;AADtD,QAAA,aAAa,iBACyC;AAEnE;;;;GAIG;AACH,MAAM,YAAY,GAAG,GAAG,EAAE,CAAC,IAAI,CAAC;AAChC,MAAM,SAAS;CAAG;AAElB,MAAM,OAAO,GAAG;IACd,gEAAgE;IAChE,SAAS,CAAC,MAAW,EAAE,IAAW;QAChC,OAAO,IAAI,KAAK,CAAC,IAAI,MAAM,CAAC,GAAG,IAAI,CAAC,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IACD,GAAG,CAAC,OAAY,EAAE,KAAU;Q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AAE,QAAQ,EAAE,uBAAuB,EAAE,EAAE,CACnE,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,sBAAsB,0BAKjC","sourcesContent":["import crypto from 'crypto';\nimport EventEmitter from 'events';\n\nimport { DEFAULT_ENDOWMENTS } from './default-endowments';\n\nconst NETWORK_APIS = ['fetch', 'Request', 'Headers', 'Response'];\n\nexport const ALL_APIS: string[] = [\n ...DEFAULT_ENDOWMENTS,\n ...NETWORK_APIS,\n 'WebAssembly',\n];\n\ntype MockSnapGlobal = {\n request: () => Promise<any>;\n};\n\ntype MockEthereumProvider = EventEmitter & {\n request: () => Promise<any>;\n};\n\n/**\n * Get a mock snap API, that always returns `true` for requests.\n *\n * @returns A mocked snap provider.\n */\nfunction getMockSnapGlobal(): MockSnapGlobal {\n // eslint-disable-next-line @typescript-eslint/require-await\n return { request: async () => true };\n}\n\n/**\n * Get a mock Ethereum provider, that always returns `true` for requests.\n *\n * @returns A mocked ethereum provider.\n */\nfunction getMockEthereumProvider(): MockEthereumProvider {\n const mockProvider = new EventEmitter() as Partial<MockEthereumProvider>;\n // eslint-disable-next-line @typescript-eslint/require-await\n mockProvider.request = async () => true;\n return mockProvider as MockEthereumProvider;\n}\n\n/**\n * Check if a value is a constructor.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nexport const isConstructor = (value: any) =>\n Boolean(typeof value?.prototype?.constructor?.name === 'string');\n\n/**\n * A function that always returns `true`.\n *\n * @returns `true`.\n */\nconst mockFunction = () => true;\nclass MockClass {}\n\nconst handler = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n construct(Target: any, args: any[]): any {\n return new Proxy(new Target(...args), handler);\n },\n get(_target: any, _prop: any) {\n return mockFunction;\n },\n};\n\n/**\n * Generate a mock class for a given value. The value is wrapped in a Proxy, and\n * all methods are replaced with a mock function.\n *\n * @param value - The value to mock.\n * @returns A mock class.\n */\nconst generateMockClass = (value: any) => {\n return new Proxy(value, handler);\n};\n\n// Things not currently auto-mocked because of NodeJS, by adding them here we\n// have types for them and can use that to generate mocks if needed.\nconst mockWindow: Record<string, unknown> = {\n crypto,\n SubtleCrypto: MockClass,\n};\n\n/**\n * Generate a mock endowment for a certain class or function on the `globalThis`\n * object.\n *\n * @param key - The key to generate the mock endowment for.\n * @returns A mocked class or function. If the key is part of the default\n * endowments, the original value is returned.\n */\nconst generateMockEndowment = (key: string) => {\n const globalValue = (globalThis as any)[key];\n\n // Default exposed APIs don't need to be mocked\n if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {\n return globalValue;\n }\n\n // Fall back to mockWindow for certain APIs not exposed in global in Node.JS\n const globalOrMocked = globalValue ?? mockWindow[key];\n\n const type = typeof globalOrMocked;\n const isFunction = type === 'function';\n if (isFunction && isConstructor(globalOrMocked)) {\n return generateMockClass(globalOrMocked);\n } else if (isFunction || !globalOrMocked) {\n // Fall back to function mock for now\n return mockFunction;\n }\n return globalOrMocked;\n};\n\n/**\n * Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.\n *\n * @returns A map of endowments.\n */\nexport const generateMockEndowments = () => {\n return ALL_APIS.reduce<Record<string, any>>(\n (acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),\n { snap: getMockSnapGlobal(), ethereum: getMockEthereumProvider() },\n );\n};\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-utils",
3
- "version": "0.32.2",
3
+ "version": "0.33.0-flask.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/MetaMask/snaps-monorepo.git"
@@ -49,17 +49,16 @@
49
49
  "build:clean": "yarn clean && yarn build",
50
50
  "clean": "rimraf '*.tsbuildinfo' 'dist/*'",
51
51
  "prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
52
- "publish:preview": "yarn npm publish --tag preview",
53
- "publish:package": "../../scripts/publish-package.sh"
52
+ "publish:preview": "yarn npm publish --tag preview"
54
53
  },
55
54
  "dependencies": {
56
- "@babel/core": "^7.18.6",
55
+ "@babel/core": "^7.20.12",
57
56
  "@babel/types": "^7.18.7",
58
57
  "@metamask/base-controller": "^2.0.0",
59
- "@metamask/permission-controller": "^3.1.0",
58
+ "@metamask/permission-controller": "^3.2.0",
60
59
  "@metamask/providers": "^10.2.1",
61
60
  "@metamask/snaps-registry": "^1.2.0",
62
- "@metamask/snaps-ui": "^0.32.2",
61
+ "@metamask/snaps-ui": "^0.33.0-flask.1",
63
62
  "@metamask/utils": "^5.0.0",
64
63
  "@noble/hashes": "^1.1.3",
65
64
  "@scure/base": "^1.1.1",
@@ -76,27 +75,29 @@
76
75
  "devDependencies": {
77
76
  "@esbuild-plugins/node-globals-polyfill": "^0.2.3",
78
77
  "@esbuild-plugins/node-modules-polyfill": "^0.2.2",
79
- "@lavamoat/allow-scripts": "^2.0.3",
78
+ "@lavamoat/allow-scripts": "^2.3.1",
80
79
  "@metamask/auto-changelog": "^3.1.0",
81
80
  "@metamask/eslint-config": "^11.0.0",
82
81
  "@metamask/eslint-config-jest": "^11.0.0",
83
82
  "@metamask/eslint-config-nodejs": "^11.0.1",
84
83
  "@metamask/eslint-config-typescript": "^11.0.0",
85
84
  "@metamask/key-tree": "^7.0.0",
86
- "@metamask/post-message-stream": "^6.1.1",
85
+ "@metamask/post-message-stream": "^6.1.2",
87
86
  "@types/jest": "^27.5.1",
88
87
  "@types/mocha": "^10.0.1",
88
+ "@types/node": "^17.0.36",
89
89
  "@types/semver": "^7.3.10",
90
90
  "@types/validate-npm-package-name": "^4.0.0",
91
91
  "@typescript-eslint/eslint-plugin": "^5.42.1",
92
92
  "@typescript-eslint/parser": "^5.42.1",
93
93
  "@wdio/browser-runner": "^8.5.2",
94
- "@wdio/cli": "^8.5.1",
95
- "@wdio/globals": "^8.5.1",
96
- "@wdio/mocha-framework": "^8.4.0",
97
- "@wdio/spec-reporter": "^8.4.0",
98
- "@wdio/static-server-service": "^8.4.0",
94
+ "@wdio/cli": "^8.5.2",
95
+ "@wdio/globals": "^8.5.2",
96
+ "@wdio/mocha-framework": "^8.5.2",
97
+ "@wdio/spec-reporter": "^8.5.2",
98
+ "@wdio/static-server-service": "^8.5.2",
99
99
  "deepmerge": "^4.2.2",
100
+ "esbuild": "^0.17.15",
100
101
  "eslint": "^8.27.0",
101
102
  "eslint-config-prettier": "^8.5.0",
102
103
  "eslint-plugin-import": "^2.26.0",
@@ -109,19 +110,19 @@
109
110
  "istanbul-lib-report": "^3.0.0",
110
111
  "istanbul-reports": "^3.1.5",
111
112
  "jest": "^29.0.2",
112
- "memfs": "^3.4.12",
113
+ "memfs": "^3.4.13",
113
114
  "prettier": "^2.7.1",
114
115
  "prettier-plugin-packagejson": "^2.2.11",
115
- "rimraf": "^3.0.2",
116
+ "rimraf": "^4.1.2",
116
117
  "serve-handler": "^6.1.5",
117
- "ts-jest": "^29.0.0",
118
+ "ts-jest": "^29.0.2",
118
119
  "ts-node": "^10.9.1",
119
120
  "typescript": "~4.8.4",
120
121
  "vite": "^4.1.4",
121
122
  "vite-tsconfig-paths": "^4.0.5",
122
123
  "wdio-chromedriver-service": "^8.1.1",
123
124
  "wdio-geckodriver-service": "^4.1.0",
124
- "webdriverio": "^8.5.1"
125
+ "webdriverio": "^8.5.2"
125
126
  },
126
127
  "engines": {
127
128
  "node": ">=16.0.0"
@@ -130,4 +131,4 @@
130
131
  "access": "public",
131
132
  "registry": "https://registry.npmjs.org/"
132
133
  }
133
- }
134
+ }