@metamask/snaps-utils 8.1.1 → 8.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +122 -1
- package/dist/errors.cjs +11 -24
- package/dist/errors.cjs.map +1 -1
- package/dist/errors.mjs +11 -24
- package/dist/errors.mjs.map +1 -1
- package/dist/eval.cjs +1 -0
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.mjs +1 -0
- package/dist/eval.mjs.map +1 -1
- package/dist/manifest/validator.cjs +5 -20
- package/dist/manifest/validator.cjs.map +1 -1
- package/dist/manifest/validator.mjs +5 -20
- package/dist/manifest/validator.mjs.map +1 -1
- package/dist/ui.cjs +26 -8
- package/dist/ui.cjs.map +1 -1
- package/dist/ui.d.cts +8 -3
- package/dist/ui.d.cts.map +1 -1
- package/dist/ui.d.mts +8 -3
- package/dist/ui.d.mts.map +1 -1
- package/dist/ui.mjs +26 -8
- package/dist/ui.mjs.map +1 -1
- package/dist/url.cjs +76 -0
- package/dist/url.cjs.map +1 -0
- package/dist/url.d.cts +20 -0
- package/dist/url.d.cts.map +1 -0
- package/dist/url.d.mts +20 -0
- package/dist/url.d.mts.map +1 -0
- package/dist/url.mjs +72 -0
- package/dist/url.mjs.map +1 -0
- package/dist/virtual-file/VirtualFile.cjs +4 -0
- package/dist/virtual-file/VirtualFile.cjs.map +1 -1
- package/dist/virtual-file/VirtualFile.mjs +4 -0
- package/dist/virtual-file/VirtualFile.mjs.map +1 -1
- package/package.json +31 -15
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Changelog
|
|
2
|
+
|
|
2
3
|
All notable changes to this project will be documented in this file.
|
|
3
4
|
|
|
4
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
@@ -6,18 +7,35 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
7
|
|
|
7
8
|
## [Unreleased]
|
|
8
9
|
|
|
10
|
+
## [8.2.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add support for `metamask:` schemed URLs ([#2719](https://github.com/MetaMask/snaps/pull/2719))
|
|
15
|
+
- Add support for JSX in `snap_notify` notifications ([#2706](https://github.com/MetaMask/snaps/pull/2706))
|
|
16
|
+
|
|
17
|
+
### Fixed
|
|
18
|
+
|
|
19
|
+
- Validate list of emails in `validateLink` function ([#2750](https://github.com/MetaMask/snaps/pull/2750))
|
|
20
|
+
|
|
9
21
|
## [8.1.1]
|
|
22
|
+
|
|
10
23
|
### Fixed
|
|
24
|
+
|
|
11
25
|
- Fix invalid types in type declaration in some cases ([#2714](https://github.com/MetaMask/snaps/pull/2714))
|
|
12
26
|
|
|
13
27
|
## [8.1.0]
|
|
28
|
+
|
|
14
29
|
### Added
|
|
30
|
+
|
|
15
31
|
- Add Bitcoin Taproot derivation paths ([#2695](https://github.com/MetaMask/snaps/pull/2695))
|
|
16
32
|
|
|
17
33
|
### Changed
|
|
34
|
+
|
|
18
35
|
- Improve `validateLink` error handling ([#2702](https://github.com/MetaMask/snaps/pull/2702))
|
|
19
36
|
|
|
20
37
|
### Fixed
|
|
38
|
+
|
|
21
39
|
- Fix ESM version of the package ([#2682](https://github.com/MetaMask/snaps/pull/2682))
|
|
22
40
|
- This fixes the ESM version of the package to be fully compliant with the ESM
|
|
23
41
|
standard.
|
|
@@ -25,25 +43,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
25
43
|
- Bump other MetaMask dependencies ([#2703](https://github.com/MetaMask/snaps/pull/2703))
|
|
26
44
|
|
|
27
45
|
## [8.0.1]
|
|
46
|
+
|
|
28
47
|
### Changed
|
|
48
|
+
|
|
29
49
|
- Bump `@metamask/slip44` to 4.0.0 ([#2624](https://github.com/MetaMask/snaps/pull/2624))
|
|
30
50
|
|
|
31
51
|
## [8.0.0]
|
|
52
|
+
|
|
32
53
|
### Changed
|
|
54
|
+
|
|
33
55
|
- **BREAKING:** Improve manifest validation output ([#2605](https://github.com/MetaMask/snaps/pull/2605), [#2572](https://github.com/MetaMask/snaps/pull/2572))
|
|
34
56
|
- This is breaking as it removes exports such as `validateNpmSnap`.
|
|
35
57
|
- Bump `fast-xml-parser` ([#2610](https://github.com/MetaMask/snaps/pull/2610))
|
|
36
58
|
|
|
37
59
|
## [7.8.1]
|
|
60
|
+
|
|
38
61
|
### Changed
|
|
62
|
+
|
|
39
63
|
- Bump `@metamask/base-controller` from `^6.0.1` to `^6.0.2` ([#2593](https://github.com/metamask/snaps/pull/2593))
|
|
40
64
|
- Bump `@metamask/permission-controller` from `^10.0.1` to `^11.0.0` ([#2593](https://github.com/metamask/snaps/pull/2593))
|
|
41
65
|
|
|
42
66
|
## [7.8.0]
|
|
67
|
+
|
|
43
68
|
### Added
|
|
69
|
+
|
|
44
70
|
- Move `serialiseJsx` function from `snaps-jest` to `snaps-utils` ([#2409](https://github.com/metamask/snaps/pull/2409))
|
|
45
71
|
|
|
46
72
|
### Changed
|
|
73
|
+
|
|
47
74
|
- Bump `@metamask/base-controller` from `^6.0.0` to `^6.0.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
48
75
|
- Bump `@metamask/key-tree` from `^9.1.1` to `^9.1.2` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
49
76
|
- Bump `@metamask/permission-controller` from `^10.0.0` to `^10.0.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
@@ -52,44 +79,59 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
52
79
|
- Bump `@metamask/utils` from `^8.3.0` to `^9.1.0` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
53
80
|
|
|
54
81
|
### Fixed
|
|
82
|
+
|
|
55
83
|
- Replace `superstruct` with ESM-compatible `@metamask/superstruct` `^3.1.0` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
56
84
|
- This fixes the issue of this package being unusable by any TypeScript project that uses `Node16` or `NodeNext` as its `moduleResolution` option.
|
|
57
85
|
- Fix `allowedOrigins` bypass caused by unterminated regex ([#2576](https://github.com/metamask/snaps/pull/2576))
|
|
58
86
|
|
|
59
87
|
## [7.7.0]
|
|
88
|
+
|
|
60
89
|
### Added
|
|
90
|
+
|
|
61
91
|
- Support conditional children in most JSX components ([#2506](https://github.com/MetaMask/snaps/pull/2506))
|
|
62
92
|
- Support additional components inside forms ([#2497](https://github.com/MetaMask/snaps/pull/2497))
|
|
63
93
|
|
|
64
94
|
### Fixed
|
|
95
|
+
|
|
65
96
|
- Improve validation of `endowment:rpc` ([#2512](https://github.com/MetaMask/snaps/pull/2512))
|
|
66
97
|
|
|
67
98
|
## [7.6.0]
|
|
99
|
+
|
|
68
100
|
### Added
|
|
101
|
+
|
|
69
102
|
- Support nested children in JSX ([#2482](https://github.com/MetaMask/snaps/pull/2482))
|
|
70
103
|
|
|
71
104
|
### Changed
|
|
105
|
+
|
|
72
106
|
- Update `onNameLookup` response to include `domainName` ([#2484](https://github.com/MetaMask/snaps/pull/2484))
|
|
73
107
|
- Bump MetaMask dependencies ([#2460](https://github.com/MetaMask/snaps/pull/2460))
|
|
74
108
|
|
|
75
109
|
### Fixed
|
|
110
|
+
|
|
76
111
|
- Fix a problem with converting legacy UIs that used `row()` ([#2486](https://github.com/MetaMask/snaps/pull/2486))
|
|
77
112
|
- Revert requiring at least one child in JSX components ([#2470](https://github.com/MetaMask/snaps/pull/2470))
|
|
78
113
|
|
|
79
114
|
## [7.5.0]
|
|
115
|
+
|
|
80
116
|
### Added
|
|
117
|
+
|
|
81
118
|
- Allow wildcards in `allowedOrigins` ([#2458](https://github.com/MetaMask/snaps/pull/2458))
|
|
82
119
|
- Add `hidden` flag for preinstalled Snaps ([#2463](https://github.com/MetaMask/snaps/pull/2463))
|
|
83
120
|
|
|
84
121
|
### Fixed
|
|
122
|
+
|
|
85
123
|
- Require at least 1 child in JSX components ([#2466](https://github.com/MetaMask/snaps/pull/2466))
|
|
86
124
|
|
|
87
125
|
## [7.4.1]
|
|
126
|
+
|
|
88
127
|
### Fixed
|
|
128
|
+
|
|
89
129
|
- Fix invalid `@metamask/snaps-sdk` imports ([#2452](https://github.com/MetaMask/snaps/pull/2452))
|
|
90
130
|
|
|
91
131
|
## [7.4.0]
|
|
132
|
+
|
|
92
133
|
### Added
|
|
134
|
+
|
|
93
135
|
- Add support for BIP-32-Ed25519 / CIP-3 key derivation ([#2408](https://github.com/MetaMask/snaps/pull/2408))
|
|
94
136
|
|
|
95
137
|
## Fixed
|
|
@@ -97,47 +139,66 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
97
139
|
- Fix build producing invalid JSX types ([#2410](https://github.com/MetaMask/snaps/pull/2410))
|
|
98
140
|
|
|
99
141
|
## [7.3.0]
|
|
142
|
+
|
|
100
143
|
### Added
|
|
144
|
+
|
|
101
145
|
- Add JSX support for custom UI ([#2258](https://github.com/MetaMask/snaps/pull/2258), [#2383](https://github.com/MetaMask/snaps/pull/2383))
|
|
102
146
|
- This adds utility functions for working with JSX in Snaps.
|
|
103
147
|
|
|
104
148
|
### Changed
|
|
149
|
+
|
|
105
150
|
- Bump `@metamask/base-controller` from `5.0.1` to `5.0.2` ([#2375](https://github.com/MetaMask/snaps/pull/2375))
|
|
106
151
|
|
|
107
152
|
## [7.2.0]
|
|
153
|
+
|
|
108
154
|
### Added
|
|
155
|
+
|
|
109
156
|
- Add `getJsonSizeUnsafe` ([#2342](https://github.com/MetaMask/snaps/pull/2342))
|
|
110
157
|
|
|
111
158
|
## [7.1.0]
|
|
159
|
+
|
|
112
160
|
### Added
|
|
161
|
+
|
|
113
162
|
- Add derivation path for Nimiq ([#2309](https://github.com/MetaMask/snaps/pull/2309))
|
|
114
163
|
|
|
115
164
|
### Fixed
|
|
165
|
+
|
|
116
166
|
- Disable GitHub flavored Markdown when lexing ([#2317](https://github.com/MetaMask/snaps/pull/2317))
|
|
117
167
|
|
|
118
168
|
## [7.0.4]
|
|
169
|
+
|
|
119
170
|
### Changed
|
|
171
|
+
|
|
120
172
|
- Bump MetaMask dependencies ([#2270](https://github.com/MetaMask/snaps/pull/2270))
|
|
121
173
|
|
|
122
174
|
### Fixed
|
|
175
|
+
|
|
123
176
|
- Allow `maxRequestTime` on `endowment:rpc` ([#2291](https://github.com/MetaMask/snaps/pull/2291))
|
|
124
177
|
|
|
125
178
|
## [7.0.3]
|
|
179
|
+
|
|
126
180
|
### Changed
|
|
181
|
+
|
|
127
182
|
- Update markdown parsing for better link validation ([#2261](https://github.com/MetaMask/snaps/pull/2261))
|
|
128
183
|
- Bump `@metamask/snaps-registry` to `^3.0.1` ([#2255](https://github.com/MetaMask/snaps/pull/2255))
|
|
129
184
|
|
|
130
185
|
## [7.0.2]
|
|
186
|
+
|
|
131
187
|
### Fixed
|
|
188
|
+
|
|
132
189
|
- Remove usage of `Buffer` from browser entrypoint ([#2238](https://github.com/MetaMask/snaps/pull/2238))
|
|
133
190
|
|
|
134
191
|
## [7.0.1]
|
|
192
|
+
|
|
135
193
|
### Fixed
|
|
194
|
+
|
|
136
195
|
- Fix minor build configuration problems ([#2220](https://github.com/MetaMask/snaps/pull/2220))
|
|
137
196
|
- Fix regex for HTML comment tokens ([#2222](https://github.com/MetaMask/snaps/pull/2222))
|
|
138
197
|
|
|
139
198
|
## [7.0.0]
|
|
199
|
+
|
|
140
200
|
### Changed
|
|
201
|
+
|
|
141
202
|
- **BREAKING:** Update ESM build to be fully compliant with the ESM standard ([#2210](https://github.com/MetaMask/snaps/pull/2210))
|
|
142
203
|
- **BREAKING:** Move Node.js exports to separate export ([#2210](https://github.com/MetaMask/snaps/pull/2210))
|
|
143
204
|
- The default export is now browser-compatible.
|
|
@@ -145,81 +206,110 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
145
206
|
- Bump `@metamask/rpc-errors` to `^6.2.1` ([#2209](https://github.com/MetaMask/snaps/pull/2209))
|
|
146
207
|
|
|
147
208
|
### Removed
|
|
209
|
+
|
|
148
210
|
- **BREAKING:** Move `file` struct to CLI ([#2207](https://github.com/MetaMask/snaps/pull/2207))
|
|
149
211
|
- The previously exported `file` struct can now be found in `@metamask/snaps-cli`.
|
|
150
212
|
|
|
151
213
|
### Fixed
|
|
214
|
+
|
|
152
215
|
- Add sizing limits for custom UI ([#2199](https://github.com/MetaMask/snaps/pull/2199))
|
|
153
216
|
- Properly validate links contained in rows ([#2205](https://github.com/MetaMask/snaps/pull/2205))
|
|
154
217
|
|
|
155
218
|
## [6.1.0]
|
|
219
|
+
|
|
156
220
|
### Added
|
|
221
|
+
|
|
157
222
|
- Add a manifest warning when no icon is found and when icon is not square ([#2185](https://github.com/MetaMask/snaps/pull/2185))
|
|
158
223
|
|
|
159
224
|
## [6.0.0]
|
|
225
|
+
|
|
160
226
|
### Added
|
|
227
|
+
|
|
161
228
|
- Add support for dynamic user interfaces ([#1465](https://github.com/MetaMask/snaps/pull/1465), [#2126](https://github.com/MetaMask/snaps/pull/2126))
|
|
162
229
|
- Add support for snap defined execution timeouts ([#2098](https://github.com/MetaMask/snaps/pull/2098))
|
|
163
230
|
|
|
164
231
|
### Changed
|
|
232
|
+
|
|
165
233
|
- **BREAKING:** Update name lookup type validation ([#2113](https://github.com/MetaMask/snaps/pull/2113))
|
|
166
234
|
- The return value and the permission format has changed, see [SIP-12](https://metamask.github.io/SIPs/SIPS/sip-12) for more details.
|
|
167
235
|
- Speed up eval-worker for improved CLI performance ([#2147](https://github.com/MetaMask/snaps/pull/2147))
|
|
168
236
|
- Update MetaMask dependencies ([#2132](https://github.com/MetaMask/snaps/pull/2132), [#2142](https://github.com/MetaMask/snaps/pull/2142))
|
|
169
237
|
|
|
170
238
|
### Fixed
|
|
239
|
+
|
|
171
240
|
- Fix initial permissions types ([#2111](https://github.com/MetaMask/snaps/pull/2111))
|
|
172
241
|
|
|
173
242
|
## [5.2.0]
|
|
243
|
+
|
|
174
244
|
### Added
|
|
245
|
+
|
|
175
246
|
- Add support for initial connections ([#2048](https://github.com/MetaMask/snaps/pull/2048))
|
|
176
247
|
- Add support for preinstalled snaps ([#2008](https://github.com/MetaMask/snaps/pull/2008))
|
|
177
248
|
- Add support for signature insights ([#2074](https://github.com/MetaMask/snaps/pull/2074))
|
|
178
249
|
|
|
179
250
|
### Changed
|
|
251
|
+
|
|
180
252
|
- Bump several MetaMask dependencies ([#2086](https://github.com/MetaMask/snaps/pull/2086), [#2100](https://github.com/MetaMask/snaps/pull/2100))
|
|
181
253
|
|
|
182
254
|
## [5.1.2]
|
|
255
|
+
|
|
183
256
|
### Fixed
|
|
257
|
+
|
|
184
258
|
- Fix missing `global` during snap evaluation ([#2072](https://github.com/MetaMask/snaps/pull/2072))
|
|
185
259
|
|
|
186
260
|
## [5.1.1]
|
|
261
|
+
|
|
187
262
|
### Changed
|
|
263
|
+
|
|
188
264
|
- Fix missing export ([#2045](https://github.com/MetaMask/snaps/pull/2045))
|
|
189
265
|
- Bump `@metamask/permission-controller` from `6.0.0` to `7.0.0` ([#2064](https://github.com/MetaMask/snaps/pull/2064))
|
|
190
266
|
|
|
191
267
|
### Removed
|
|
268
|
+
|
|
192
269
|
- Remove support for object-like syntax for cronjobs ([#2057](https://github.com/MetaMask/snaps/pull/2057))
|
|
193
270
|
- Since this never worked in the first place we aren't marking it as breaking.
|
|
194
271
|
|
|
195
272
|
## [5.1.0]
|
|
273
|
+
|
|
196
274
|
### Added
|
|
275
|
+
|
|
197
276
|
- Add `getSnapDerivationPathName` and `getSlip44ProtocolName` to be shared across clients ([#2033](https://github.com/MetaMask/snaps/pull/2033))
|
|
198
277
|
|
|
199
278
|
### Changed
|
|
279
|
+
|
|
200
280
|
- Bump `snaps-registry` ([#2020](https://hub.com/MetaMask/snaps/pull/2020))
|
|
201
281
|
|
|
202
282
|
## [5.0.1]
|
|
283
|
+
|
|
203
284
|
### Changed
|
|
285
|
+
|
|
204
286
|
- Improve base64 encoding/decoding speeds ([#1985](https://github.com/MetaMask/snaps/pull/1985))
|
|
205
287
|
- Bump several MetaMask dependencies ([#1989](https://github.com/MetaMask/snaps/pull/1989), [#1993](https://github.com/MetaMask/snaps/pull/1993))
|
|
206
288
|
|
|
207
289
|
## [5.0.0]
|
|
290
|
+
|
|
208
291
|
### Changed
|
|
292
|
+
|
|
209
293
|
- Bump several MetaMask dependencies ([#1964](https://github.com/MetaMask/snaps/pull/1964))
|
|
210
294
|
|
|
211
295
|
### Removed
|
|
296
|
+
|
|
212
297
|
- **BREAKING:** Move `enumValue`, `literal` and `union` to `snaps-sdk` ([#1968](https://github.com/MetaMask/snaps/pull/1968))
|
|
213
298
|
|
|
214
299
|
### Fixed
|
|
300
|
+
|
|
215
301
|
- Fix issues generating checksum with binary auxiliary files ([#1975](https://github.com/MetaMask/snaps/pull/1975))
|
|
216
302
|
|
|
217
303
|
## [4.0.1]
|
|
304
|
+
|
|
218
305
|
### Fixed
|
|
306
|
+
|
|
219
307
|
- Change `validateTextLinks` to only get URL in markdown links ([#1914](https://github.com/MetaMask/snaps/pull/1914))
|
|
220
308
|
|
|
221
309
|
## [4.0.0]
|
|
310
|
+
|
|
222
311
|
### Changed
|
|
312
|
+
|
|
223
313
|
- Use `SubtleCrypto` for checksum calculation if available ([#1953](https://github.com/MetaMask/snaps/pull/1953))
|
|
224
314
|
- This reduces the time of the checksum calculation by up to 95% in some
|
|
225
315
|
environments.
|
|
@@ -230,6 +320,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
230
320
|
- `@metamask/snaps-ui` packages, and is much more lightweight.
|
|
231
321
|
|
|
232
322
|
### Removed
|
|
323
|
+
|
|
233
324
|
- **BREAKING**: Remove `ValidatedSnapId` and `SnapId` types ([#1930](https://github.com/MetaMask/snaps/pull/1930))
|
|
234
325
|
- `ValidatedSnapId` was moved to the `@metamask/snaps-sdk` package as
|
|
235
326
|
`SnapId`.
|
|
@@ -243,79 +334,109 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
243
334
|
type from the `@metamask/snaps-sdk` package.
|
|
244
335
|
|
|
245
336
|
### Fixed
|
|
337
|
+
|
|
246
338
|
- Include localization files in checksum calculations ([#1956](https://github.com/MetaMask/snaps/pull/1956))
|
|
247
339
|
|
|
248
340
|
## [3.3.0]
|
|
341
|
+
|
|
249
342
|
### Added
|
|
343
|
+
|
|
250
344
|
- Add manifest localization functionality ([#1889](https://github.com/MetaMask/snaps/pull/1889))
|
|
251
345
|
- Add `OnHomePage` export ([#1896](https://github.com/MetaMask/snaps/pull/1896))
|
|
252
346
|
|
|
253
347
|
## [3.2.0]
|
|
348
|
+
|
|
254
349
|
### Added
|
|
350
|
+
|
|
255
351
|
- Add support for links in custom UI and notifications ([#1814](https://github.com/MetaMask/snaps/pull/1814))
|
|
256
352
|
|
|
257
353
|
## [3.1.0]
|
|
354
|
+
|
|
258
355
|
### Added
|
|
356
|
+
|
|
259
357
|
- Add static file API ([#1836](https://github.com/MetaMask/snaps/pull/1836), [#1858](https://github.com/MetaMask/snaps/pull/1858))
|
|
260
358
|
|
|
261
359
|
### Changed
|
|
360
|
+
|
|
262
361
|
- Update multiple MetaMask dependencies ([#1841](https://github.com/MetaMask/snaps/pull/1841))
|
|
263
362
|
- Bump Babel packages from `^7.20.12` to `^7.23.2` ([#1862](https://github.com/MetaMask/snaps/pull/1862))
|
|
264
363
|
|
|
265
364
|
## [3.0.0]
|
|
365
|
+
|
|
266
366
|
### Added
|
|
367
|
+
|
|
267
368
|
- Add keyring export and endowment ([#1787](https://github.com/MetaMask/snaps/pull/1787))
|
|
268
369
|
- Add optional `allowedOrigins` field to `endowment:rpc` ([#1822](https://github.com/MetaMask/snaps/pull/1822))
|
|
269
370
|
- This can be used to only accept certain origins in your Snap.
|
|
270
371
|
|
|
271
372
|
### Changed
|
|
373
|
+
|
|
272
374
|
- **BREAKING:** Bump minimum Node.js version to `^18.16.0` ([#1741](https://github.com/MetaMask/snaps/pull/1741))
|
|
273
375
|
|
|
274
376
|
## [2.0.1]
|
|
377
|
+
|
|
275
378
|
### Changed
|
|
379
|
+
|
|
276
380
|
- Remove deprecated `endowment:long-running` ([#1751](https://github.com/MetaMask/snaps/pull/1751))
|
|
277
381
|
|
|
278
382
|
## [2.0.0]
|
|
383
|
+
|
|
279
384
|
### Changed
|
|
385
|
+
|
|
280
386
|
- Initial stable release from main branch ([#1757](https://github.com/MetaMask/snaps/pull/1757))
|
|
281
387
|
|
|
282
388
|
## [0.38.4-flask.1]
|
|
389
|
+
|
|
283
390
|
### Added
|
|
391
|
+
|
|
284
392
|
- Add `onNameLookup` export ([#1394](https://github.com/MetaMask/snaps/pull/1394), [#1759](https://github.com/MetaMask/snaps/pull/1759))
|
|
285
393
|
|
|
286
394
|
### Changed
|
|
395
|
+
|
|
287
396
|
- Bump `metamask/utils` and `metamask/snaps-registry` ([#1738](https://github.com/MetaMask/snaps/pull/1738))
|
|
288
397
|
|
|
289
398
|
## [0.38.3-flask.1]
|
|
399
|
+
|
|
290
400
|
### Changed
|
|
401
|
+
|
|
291
402
|
- Bump `@metamask/post-message-stream` from 6.1.2 to 7.0.0 ([#1707](https://github.com/MetaMask/snaps/pull/1707), [#1724](https://github.com/MetaMask/snaps/pull/1724))
|
|
292
403
|
- Bump `@metamask/utils` and `@metamask/snaps-registry` ([#1694](https://github.com/MetaMask/snaps/pull/1694))
|
|
293
404
|
|
|
294
405
|
## [0.38.2-flask.1]
|
|
406
|
+
|
|
295
407
|
### Fixed
|
|
408
|
+
|
|
296
409
|
- Remove unused dependencies ([#1680](https://github.com/MetaMask/snaps/pull/1680))
|
|
297
410
|
|
|
298
411
|
## [0.38.1-flask.1]
|
|
412
|
+
|
|
299
413
|
### Changed
|
|
414
|
+
|
|
300
415
|
- Update transaction insights response and add severity level enum ([#1653](https://github.com/MetaMask/snaps/pull/1653))
|
|
301
416
|
- Snaps are now able to specify a `severity` for alongside their insights.
|
|
302
417
|
- See [SIP-11](https://metamask.github.io/SIPs/SIPS/sip-11) for more information.
|
|
303
418
|
|
|
304
419
|
## [0.38.0-flask.1]
|
|
420
|
+
|
|
305
421
|
### Added
|
|
422
|
+
|
|
306
423
|
- Add `onInstall` and `onUpdate` lifecycle hooks ([#1643](https://github.com/MetaMask/snaps/pull/1643))
|
|
307
424
|
|
|
308
425
|
### Changed
|
|
426
|
+
|
|
309
427
|
- Move source code and snap state back to controller state ([#1634](https://github.com/MetaMask/snaps/pull/1634))
|
|
310
428
|
- Bump `semver` to `^7.5.4` ([#1631](https://github.com/MetaMask/snaps/pull/1631))
|
|
311
429
|
|
|
312
430
|
## [0.37.2-flask.1]
|
|
431
|
+
|
|
313
432
|
### Changed
|
|
433
|
+
|
|
314
434
|
- Release package independently ([#1600](https://github.com/MetaMask/snaps/pull/1600))
|
|
315
435
|
- The version of the package no longer needs to match the version of all other
|
|
316
436
|
MetaMask Snaps packages.
|
|
317
437
|
|
|
318
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.
|
|
438
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.2.0...HEAD
|
|
439
|
+
[8.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.1.1...@metamask/snaps-utils@8.2.0
|
|
319
440
|
[8.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.1.0...@metamask/snaps-utils@8.1.1
|
|
320
441
|
[8.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.0.1...@metamask/snaps-utils@8.1.0
|
|
321
442
|
[8.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-utils@8.0.0...@metamask/snaps-utils@8.0.1
|
package/dist/errors.cjs
CHANGED
|
@@ -1,16 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
-
};
|
|
8
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _WrappedSnapError_error, _WrappedSnapError_message, _WrappedSnapError_stack;
|
|
14
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
3
|
exports.unwrapError = exports.isWrappedSnapError = exports.isSerializedSnapError = exports.isSnapError = exports.WrappedSnapError = exports.SNAP_ERROR_WRAPPER_MESSAGE = exports.SNAP_ERROR_WRAPPER_CODE = void 0;
|
|
16
4
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
@@ -19,6 +7,9 @@ const utils_1 = require("@metamask/utils");
|
|
|
19
7
|
exports.SNAP_ERROR_WRAPPER_CODE = -31001;
|
|
20
8
|
exports.SNAP_ERROR_WRAPPER_MESSAGE = 'Wrapped Snap Error';
|
|
21
9
|
class WrappedSnapError extends Error {
|
|
10
|
+
#error;
|
|
11
|
+
#message;
|
|
12
|
+
#stack;
|
|
22
13
|
/**
|
|
23
14
|
* Create a new `WrappedSnapError`.
|
|
24
15
|
*
|
|
@@ -27,12 +18,9 @@ class WrappedSnapError extends Error {
|
|
|
27
18
|
constructor(error) {
|
|
28
19
|
const message = (0, snaps_sdk_1.getErrorMessage)(error);
|
|
29
20
|
super(message);
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
__classPrivateFieldSet(this, _WrappedSnapError_error, error, "f");
|
|
34
|
-
__classPrivateFieldSet(this, _WrappedSnapError_message, message, "f");
|
|
35
|
-
__classPrivateFieldSet(this, _WrappedSnapError_stack, (0, snaps_sdk_1.getErrorStack)(error), "f");
|
|
21
|
+
this.#error = error;
|
|
22
|
+
this.#message = message;
|
|
23
|
+
this.#stack = (0, snaps_sdk_1.getErrorStack)(error);
|
|
36
24
|
}
|
|
37
25
|
/**
|
|
38
26
|
* The error name.
|
|
@@ -48,7 +36,7 @@ class WrappedSnapError extends Error {
|
|
|
48
36
|
* @returns The error message.
|
|
49
37
|
*/
|
|
50
38
|
get message() {
|
|
51
|
-
return
|
|
39
|
+
return this.#message;
|
|
52
40
|
}
|
|
53
41
|
/**
|
|
54
42
|
* The error stack.
|
|
@@ -56,7 +44,7 @@ class WrappedSnapError extends Error {
|
|
|
56
44
|
* @returns The error stack.
|
|
57
45
|
*/
|
|
58
46
|
get stack() {
|
|
59
|
-
return
|
|
47
|
+
return this.#stack;
|
|
60
48
|
}
|
|
61
49
|
/**
|
|
62
50
|
* Convert the error to a JSON object.
|
|
@@ -64,9 +52,9 @@ class WrappedSnapError extends Error {
|
|
|
64
52
|
* @returns The JSON object.
|
|
65
53
|
*/
|
|
66
54
|
toJSON() {
|
|
67
|
-
const cause = isSnapError(
|
|
68
|
-
?
|
|
69
|
-
: (0, rpc_errors_1.serializeCause)(
|
|
55
|
+
const cause = isSnapError(this.#error)
|
|
56
|
+
? this.#error.serialize()
|
|
57
|
+
: (0, rpc_errors_1.serializeCause)(this.#error);
|
|
70
58
|
return {
|
|
71
59
|
code: exports.SNAP_ERROR_WRAPPER_CODE,
|
|
72
60
|
message: exports.SNAP_ERROR_WRAPPER_MESSAGE,
|
|
@@ -86,7 +74,6 @@ class WrappedSnapError extends Error {
|
|
|
86
74
|
}
|
|
87
75
|
}
|
|
88
76
|
exports.WrappedSnapError = WrappedSnapError;
|
|
89
|
-
_WrappedSnapError_error = new WeakMap(), _WrappedSnapError_message = new WeakMap(), _WrappedSnapError_stack = new WeakMap();
|
|
90
77
|
/**
|
|
91
78
|
* Check if an object is a `SnapError`.
|
|
92
79
|
*
|
package/dist/errors.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"errors.cjs","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n errorCodes,\n JsonRpcError as RpcError,\n serializeCause,\n} from '@metamask/rpc-errors';\nimport type { DataWithOptionalCause } from '@metamask/rpc-errors';\nimport type { SerializedSnapError, SnapError } from '@metamask/snaps-sdk';\nimport {\n getErrorMessage,\n getErrorStack,\n SNAP_ERROR_CODE,\n SNAP_ERROR_MESSAGE,\n} from '@metamask/snaps-sdk';\nimport type { Json, JsonRpcError } from '@metamask/utils';\nimport { isObject, isJsonRpcError } from '@metamask/utils';\n\nexport const SNAP_ERROR_WRAPPER_CODE = -31001;\nexport const SNAP_ERROR_WRAPPER_MESSAGE = 'Wrapped Snap Error';\n\nexport type SerializedSnapErrorWrapper = {\n code: typeof SNAP_ERROR_WRAPPER_CODE;\n message: typeof SNAP_ERROR_WRAPPER_MESSAGE;\n data: {\n cause: Json;\n };\n};\n\nexport class WrappedSnapError extends Error {\n readonly #error: unknown;\n\n readonly #message: string;\n\n readonly #stack?: string;\n\n /**\n * Create a new `WrappedSnapError`.\n *\n * @param error - The error to create the `WrappedSnapError` from.\n */\n constructor(error: unknown) {\n const message = getErrorMessage(error);\n super(message);\n\n this.#error = error;\n this.#message = message;\n this.#stack = getErrorStack(error);\n }\n\n /**\n * The error name.\n *\n * @returns The error name.\n */\n get name() {\n return 'WrappedSnapError';\n }\n\n /**\n * The error message.\n *\n * @returns The error message.\n */\n get message() {\n return this.#message;\n }\n\n /**\n * The error stack.\n *\n * @returns The error stack.\n */\n get stack() {\n return this.#stack;\n }\n\n /**\n * Convert the error to a JSON object.\n *\n * @returns The JSON object.\n */\n toJSON(): SerializedSnapErrorWrapper {\n const cause = isSnapError(this.#error)\n ? this.#error.serialize()\n : serializeCause(this.#error);\n\n return {\n code: SNAP_ERROR_WRAPPER_CODE,\n message: SNAP_ERROR_WRAPPER_MESSAGE,\n data: {\n cause,\n },\n };\n }\n\n /**\n * Serialize the error to a JSON object. This is called by\n * `@metamask/rpc-errors` when serializing the error.\n *\n * @returns The JSON object.\n */\n serialize() {\n return this.toJSON();\n }\n}\n\n/**\n * Check if an object is a `SnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `SnapError`.\n */\nexport function isSnapError(error: unknown): error is SnapError {\n if (\n isObject(error) &&\n 'serialize' in error &&\n typeof error.serialize === 'function'\n ) {\n const serialized = error.serialize();\n return isJsonRpcError(serialized) && isSerializedSnapError(serialized);\n }\n\n return false;\n}\n\n/**\n * Check if a JSON-RPC error is a `SnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `SnapError`.\n */\nexport function isSerializedSnapError(\n error: JsonRpcError,\n): error is SerializedSnapError {\n return error.code === SNAP_ERROR_CODE && error.message === SNAP_ERROR_MESSAGE;\n}\n\n/**\n * Check if a JSON-RPC error is a `WrappedSnapError`.\n *\n * @param error - The object to check.\n * @returns Whether the object is a `WrappedSnapError`.\n */\nexport function isWrappedSnapError(\n error: unknown,\n): error is SerializedSnapErrorWrapper {\n return (\n isJsonRpcError(error) &&\n error.code === SNAP_ERROR_WRAPPER_CODE &&\n error.message === SNAP_ERROR_WRAPPER_MESSAGE\n );\n}\n\n/**\n * Get a JSON-RPC error with the given code, message, stack, and data.\n *\n * @param code - The error code.\n * @param message - The error message.\n * @param stack - The error stack.\n * @param data - Additional data for the error.\n * @returns The JSON-RPC error.\n */\nfunction getJsonRpcError(\n code: number,\n message: string,\n stack?: string,\n data?: Json,\n) {\n const error = new RpcError(code, message, data);\n error.stack = stack;\n\n return error;\n}\n\n/**\n * Attempt to unwrap an unknown error to a `JsonRpcError`. This function will\n * try to get the error code, message, and data from the error, and return a\n * `JsonRpcError` with those properties.\n *\n * @param error - The error to unwrap.\n * @returns A tuple containing the unwrapped error and a boolean indicating\n * whether the error was handled.\n */\nexport function unwrapError(\n error: unknown,\n): [error: RpcError<DataWithOptionalCause>, isHandled: boolean] {\n // This logic is a bit complicated, but it's necessary to handle all the\n // different types of errors that can be thrown by a Snap.\n\n // If the error is a wrapped Snap error, unwrap it.\n if (isWrappedSnapError(error)) {\n // The wrapped error can be a JSON-RPC error, or an unknown error. If it's\n // a JSON-RPC error, we can unwrap it further.\n if (isJsonRpcError(error.data.cause)) {\n // If the JSON-RPC error is a wrapped Snap error, unwrap it further.\n if (isSerializedSnapError(error.data.cause)) {\n const { code, message, stack, data } = error.data.cause.data.cause;\n return [getJsonRpcError(code, message, stack, data), true];\n }\n\n // Otherwise, we use the original JSON-RPC error.\n const { code, message, stack, data } = error.data.cause;\n return [getJsonRpcError(code, message, stack, data), false];\n }\n\n // Otherwise, we throw an internal error with the wrapped error as the\n // message.\n return [\n getJsonRpcError(\n errorCodes.rpc.internal,\n getErrorMessage(error.data.cause),\n getErrorStack(error.data.cause),\n ),\n false,\n ];\n }\n\n // The error can be a non-wrapped JSON-RPC error, in which case we can just\n // re-throw it with the same code, message, and data.\n if (isJsonRpcError(error)) {\n const { code, message, stack, data } = error;\n return [getJsonRpcError(code, message, stack, data), false];\n }\n\n // If the error is not a wrapped error, we don't know how to handle it, so we\n // throw an internal error with the error as the message.\n return [\n getJsonRpcError(\n errorCodes.rpc.internal,\n getErrorMessage(error),\n getErrorStack(error),\n ),\n false,\n ];\n}\n"]}
|
package/dist/errors.mjs
CHANGED
|
@@ -1,21 +1,12 @@
|
|
|
1
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
-
};
|
|
7
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _WrappedSnapError_error, _WrappedSnapError_message, _WrappedSnapError_stack;
|
|
13
1
|
import { errorCodes, JsonRpcError as RpcError, serializeCause } from "@metamask/rpc-errors";
|
|
14
2
|
import { getErrorMessage, getErrorStack, SNAP_ERROR_CODE, SNAP_ERROR_MESSAGE } from "@metamask/snaps-sdk";
|
|
15
3
|
import { isObject, isJsonRpcError } from "@metamask/utils";
|
|
16
4
|
export const SNAP_ERROR_WRAPPER_CODE = -31001;
|
|
17
5
|
export const SNAP_ERROR_WRAPPER_MESSAGE = 'Wrapped Snap Error';
|
|
18
6
|
export class WrappedSnapError extends Error {
|
|
7
|
+
#error;
|
|
8
|
+
#message;
|
|
9
|
+
#stack;
|
|
19
10
|
/**
|
|
20
11
|
* Create a new `WrappedSnapError`.
|
|
21
12
|
*
|
|
@@ -24,12 +15,9 @@ export class WrappedSnapError extends Error {
|
|
|
24
15
|
constructor(error) {
|
|
25
16
|
const message = getErrorMessage(error);
|
|
26
17
|
super(message);
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
__classPrivateFieldSet(this, _WrappedSnapError_error, error, "f");
|
|
31
|
-
__classPrivateFieldSet(this, _WrappedSnapError_message, message, "f");
|
|
32
|
-
__classPrivateFieldSet(this, _WrappedSnapError_stack, getErrorStack(error), "f");
|
|
18
|
+
this.#error = error;
|
|
19
|
+
this.#message = message;
|
|
20
|
+
this.#stack = getErrorStack(error);
|
|
33
21
|
}
|
|
34
22
|
/**
|
|
35
23
|
* The error name.
|
|
@@ -45,7 +33,7 @@ export class WrappedSnapError extends Error {
|
|
|
45
33
|
* @returns The error message.
|
|
46
34
|
*/
|
|
47
35
|
get message() {
|
|
48
|
-
return
|
|
36
|
+
return this.#message;
|
|
49
37
|
}
|
|
50
38
|
/**
|
|
51
39
|
* The error stack.
|
|
@@ -53,7 +41,7 @@ export class WrappedSnapError extends Error {
|
|
|
53
41
|
* @returns The error stack.
|
|
54
42
|
*/
|
|
55
43
|
get stack() {
|
|
56
|
-
return
|
|
44
|
+
return this.#stack;
|
|
57
45
|
}
|
|
58
46
|
/**
|
|
59
47
|
* Convert the error to a JSON object.
|
|
@@ -61,9 +49,9 @@ export class WrappedSnapError extends Error {
|
|
|
61
49
|
* @returns The JSON object.
|
|
62
50
|
*/
|
|
63
51
|
toJSON() {
|
|
64
|
-
const cause = isSnapError(
|
|
65
|
-
?
|
|
66
|
-
: serializeCause(
|
|
52
|
+
const cause = isSnapError(this.#error)
|
|
53
|
+
? this.#error.serialize()
|
|
54
|
+
: serializeCause(this.#error);
|
|
67
55
|
return {
|
|
68
56
|
code: SNAP_ERROR_WRAPPER_CODE,
|
|
69
57
|
message: SNAP_ERROR_WRAPPER_MESSAGE,
|
|
@@ -82,7 +70,6 @@ export class WrappedSnapError extends Error {
|
|
|
82
70
|
return this.toJSON();
|
|
83
71
|
}
|
|
84
72
|
}
|
|
85
|
-
_WrappedSnapError_error = new WeakMap(), _WrappedSnapError_message = new WeakMap(), _WrappedSnapError_stack = new WeakMap();
|
|
86
73
|
/**
|
|
87
74
|
* Check if an object is a `SnapError`.
|
|
88
75
|
*
|