@metamask-previews/utils 12.0.0-preview-1a1783a → 12.0.0-preview-e81860e6b
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 +3 -574
- package/README.md +2 -93
- package/dist/json.d.ts +8 -8
- package/dist/json.d.ts.map +1 -1
- package/dist/json.js +4 -1
- package/dist/json.js.map +1 -1
- package/package.json +29 -50
package/CHANGELOG.md
CHANGED
|
@@ -7,580 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
## [12.0.0]
|
|
11
|
-
|
|
12
|
-
### Changed
|
|
13
|
-
|
|
14
|
-
- **BREAKING:** Bump TypeScript target to ES2022 ([#332](https://github.com/MetaMask/utils/pull/332))
|
|
15
|
-
- This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
|
|
16
|
-
- **BREAKING:** Drop support for Node 18 and 20 ([#328](https://github.com/MetaMask/utils/pull/328))
|
|
17
|
-
- **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
|
|
18
|
-
- This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
|
|
19
|
-
- Bump `@ethereumjs/tx` from `^4.2.0` to `^5.4.0` ([#321](https://github.com/MetaMask/utils/pull/321))
|
|
20
|
-
- The deprecated `Keyring.signTransaction` now returns `LegacyTxData` rather than `TxData`. These describe the same shape: `@ethereumjs/tx@5` repurposed the name `TxData` for a map keyed by transaction type and renamed the old meaning to `LegacyTxData`. Implementations do not need changing.
|
|
21
|
-
- Bump `@metamask/scure-bip39` from `^2.0.3` to `^2.1.1` ([#311](https://github.com/MetaMask/utils/pull/311))
|
|
22
|
-
- Bump `@metamask/superstruct` from `^3.1.0` to `^3.4.1` ([#311](https://github.com/MetaMask/utils/pull/311))
|
|
23
|
-
- Bump `@noble/hashes` from `^1.3.1` to `^1.8.0` ([#311](https://github.com/MetaMask/utils/pull/311))
|
|
24
|
-
- Bump `@scure/base` from `^1.1.3` to `^1.2.6` ([#311](https://github.com/MetaMask/utils/pull/311))
|
|
25
|
-
- Bump `semver` from `^7.5.4` to `^7.6.3` ([#311](https://github.com/MetaMask/utils/pull/311))
|
|
26
|
-
|
|
27
|
-
## [11.12.1]
|
|
28
|
-
|
|
29
|
-
### Fixed
|
|
30
|
-
|
|
31
|
-
- Fix ESM compatibility for the BIP-39 mnemonic utilities ([#309](https://github.com/MetaMask/utils/pull/309))
|
|
32
|
-
|
|
33
|
-
## [11.12.0]
|
|
34
|
-
|
|
35
|
-
### Added
|
|
36
|
-
|
|
37
|
-
- Add `uint8ArrayToMnemonic` and `convertMnemonicToWordlistIndices` utilities ([#300](https://github.com/MetaMask/utils/pull/300))
|
|
38
|
-
- `uint8ArrayToMnemonic` converts little-endian `Uint16` English BIP-39 wordlist indices into a mnemonic string.
|
|
39
|
-
- `convertMnemonicToWordlistIndices` converts a mnemonic string into little-endian `Uint16` wordlist indices encoded as a `Uint8Array`.
|
|
40
|
-
- Add `@metamask/scure-bip39` as a dependency ([#300](https://github.com/MetaMask/utils/pull/300))
|
|
41
|
-
- Add optimized `sha512` and `sha384` utility functions ([#305](https://github.com/MetaMask/utils/pull/305))
|
|
42
|
-
|
|
43
|
-
## [11.11.0]
|
|
44
|
-
|
|
45
|
-
### Added
|
|
46
|
-
|
|
47
|
-
- Add Stellar CAIP namespace ([#278](https://github.com/MetaMask/utils/pull/278))
|
|
48
|
-
|
|
49
|
-
## [11.10.0]
|
|
50
|
-
|
|
51
|
-
### Added
|
|
52
|
-
|
|
53
|
-
- Add ensureError utility for converting unknown values to error ([#275](https://github.com/MetaMask/utils/pull/275))
|
|
54
|
-
|
|
55
|
-
## [11.9.0]
|
|
56
|
-
|
|
57
|
-
### Added
|
|
58
|
-
|
|
59
|
-
- Add `sha256` utility function ([#273](https://github.com/MetaMask/utils/pull/273))
|
|
60
|
-
|
|
61
|
-
## [11.8.1]
|
|
62
|
-
|
|
63
|
-
### Changed
|
|
64
|
-
|
|
65
|
-
- Replace `superstruct.is` with faster regex checks for `isCaip*` functions ([#270](https://github.com/MetaMask/utils/pull/270))
|
|
66
|
-
- Those calls were slow especially on our mobile client.
|
|
67
|
-
|
|
68
|
-
## [11.8.0]
|
|
69
|
-
|
|
70
|
-
### Added
|
|
71
|
-
|
|
72
|
-
- Add `areUint8ArraysEqual` function to compare two `Uint8Array` types ([#268](https://github.com/MetaMask/utils/pull/268))
|
|
73
|
-
|
|
74
|
-
## [11.7.0]
|
|
75
|
-
|
|
76
|
-
### Added
|
|
77
|
-
|
|
78
|
-
- Add Tron CAIP namespace ([#266](https://github.com/MetaMask/utils/pull/266))
|
|
79
|
-
|
|
80
|
-
### Fixed
|
|
81
|
-
|
|
82
|
-
- Fix API docs generation ([#264](https://github.com/MetaMask/utils/pull/264))
|
|
83
|
-
|
|
84
|
-
## [11.6.0]
|
|
85
|
-
|
|
86
|
-
### Added
|
|
87
|
-
|
|
88
|
-
- Migrate units conversion utils from `@metamask/ethjs-unit` ([#255](https://github.com/MetaMask/utils/pull/255))
|
|
89
|
-
|
|
90
|
-
### Changed
|
|
91
|
-
|
|
92
|
-
- Make `KnownCaipNamespacedChainId` type generic over `Namespace` type parameter ([#262](https://github.com/MetaMask/utils/pull/262))
|
|
93
|
-
|
|
94
|
-
## [11.5.0]
|
|
95
|
-
|
|
96
|
-
### Added
|
|
97
|
-
|
|
98
|
-
- Add `KnownCaipNamespacedChainId` type as narrower subtype of `CaipChainId` ([#258](https://github.com/MetaMask/utils/pull/258))
|
|
99
|
-
|
|
100
|
-
### Changed
|
|
101
|
-
|
|
102
|
-
- Add `lodash` and `@types/lodash` as dependencies ([#253](https://github.com/MetaMask/utils/pull/253), [#257](https://github.com/MetaMask/utils/pull/257))
|
|
103
|
-
|
|
104
|
-
### Removed
|
|
105
|
-
|
|
106
|
-
- Remove `lodash.memoize` (dependency) and `@types/lodash.memoize` (devDependency) ([#253](https://github.com/MetaMask/utils/pull/253)).
|
|
107
|
-
|
|
108
|
-
## [11.4.2]
|
|
109
|
-
|
|
110
|
-
### Fixed
|
|
111
|
-
|
|
112
|
-
- Improve performance of `isValidChecksumAddress` and `isValidHexAddress` functions ([#248](https://github.com/MetaMask/utils/pull/248))
|
|
113
|
-
|
|
114
|
-
## [11.4.1]
|
|
115
|
-
|
|
116
|
-
### Fixed
|
|
117
|
-
|
|
118
|
-
- Improve performance of `getChecksumAddress` function ([#246](https://github.com/MetaMask/utils/pull/246))
|
|
119
|
-
|
|
120
|
-
## [11.4.0]
|
|
121
|
-
|
|
122
|
-
### Changed
|
|
123
|
-
|
|
124
|
-
- Deprecate local `exactOptional` implementation ([#244](https://github.com/MetaMask/utils/pull/244))
|
|
125
|
-
- Use the one from `@metamask/superstruct@>=3.2.0` instead.
|
|
126
|
-
|
|
127
|
-
## [11.3.0]
|
|
128
|
-
|
|
129
|
-
### Added
|
|
130
|
-
|
|
131
|
-
- Add default JSON-RPC generics that extend `Json` to `Json` ([#241](https://github.com/MetaMask/utils/pull/241))
|
|
132
|
-
|
|
133
|
-
### Changed
|
|
134
|
-
|
|
135
|
-
- Deprecate `Keyring` types ([#236](https://github.com/MetaMask/utils/pull/236))
|
|
136
|
-
- These should now be imported from `@metamask/keyring-utils`.
|
|
137
|
-
|
|
138
|
-
## [11.2.0]
|
|
139
|
-
|
|
140
|
-
### Added
|
|
141
|
-
|
|
142
|
-
- Add optional `signEip7702Authorization` method to `Keyring` type ([#231](https://github.com/MetaMask/utils/pull/231))
|
|
143
|
-
|
|
144
|
-
## [11.1.0]
|
|
145
|
-
|
|
146
|
-
### Added
|
|
147
|
-
|
|
148
|
-
- Add additional CAIP-19 types (`CaipAsset{Namespace,Reference,TokenId}` support ([#227](https://github.com/MetaMask/utils/pull/227))
|
|
149
|
-
- Add CAIP-19 `CaipAssetTypeOrId` ([#229](https://github.com/MetaMask/utils/pull/229))
|
|
150
|
-
- This one combines both `CaipAssetType` and `CaipAssetId` to avoid relying on `superstruct.union`, resulting in better error messages.
|
|
151
|
-
- Add `definePattern` superstruct helper ([#228](https://github.com/MetaMask/utils/pull/228))
|
|
152
|
-
- Allow to define a `superstruct.pattern` while naming the struct and enforcing its type.
|
|
153
|
-
|
|
154
|
-
### Changed
|
|
155
|
-
|
|
156
|
-
- Use named structs for all CAIP types ([#228](https://github.com/MetaMask/utils/pull/228))
|
|
157
|
-
|
|
158
|
-
## [11.0.1]
|
|
159
|
-
|
|
160
|
-
### Fixed
|
|
161
|
-
|
|
162
|
-
- Improve error message for invalid JSON values ([#224](https://github.com/MetaMask/utils/pull/224))
|
|
163
|
-
|
|
164
|
-
## [11.0.0]
|
|
165
|
-
|
|
166
|
-
### Changed
|
|
167
|
-
|
|
168
|
-
- **BREAKING:** `generateRandomMnemonic` now returns `Promise<void>` instead of `void` ([#222](https://github.com/MetaMask/utils/pull/222))
|
|
169
|
-
|
|
170
|
-
## [10.0.1]
|
|
171
|
-
|
|
172
|
-
### Added
|
|
173
|
-
|
|
174
|
-
- Add Solana CAIP namespace ([#219](https://github.com/MetaMask/utils/pull/219))
|
|
175
|
-
|
|
176
|
-
## [10.0.0]
|
|
177
|
-
|
|
178
|
-
### Changed
|
|
179
|
-
|
|
180
|
-
- **BREAKING:** Drop support for Node.js versions 16, 21 ([#212](https://github.com/MetaMask/utils/pull/212))
|
|
181
|
-
- Improve JSON validation performance ([#218](https://github.com/MetaMask/utils/pull/218))
|
|
182
|
-
|
|
183
|
-
## [9.3.0]
|
|
184
|
-
|
|
185
|
-
### Added
|
|
186
|
-
|
|
187
|
-
- Add support for CAIP-19 ([#183](https://github.com/MetaMask/utils/pull/183))
|
|
188
|
-
- Add `Bip122` member to `KnownCaipNamespace` ([#213](https://github.com/MetaMask/utils/pull/213))
|
|
189
|
-
|
|
190
|
-
## [9.2.1]
|
|
191
|
-
|
|
192
|
-
### Fixed
|
|
193
|
-
|
|
194
|
-
- Fix wrong types for CAIP-2 and CAIP-10 structs ([#210](https://github.com/MetaMask/utils/pull/210))
|
|
195
|
-
|
|
196
|
-
## [9.2.0]
|
|
197
|
-
|
|
198
|
-
### Added
|
|
199
|
-
|
|
200
|
-
- Add `Wallet` member to `KnownCaipNamespace` enum ([#207](https://github.com/MetaMask/utils/pull/207))
|
|
201
|
-
|
|
202
|
-
## [9.1.0]
|
|
203
|
-
|
|
204
|
-
### Added
|
|
205
|
-
|
|
206
|
-
- Add `PublicInterface` type ([#197](https://github.com/MetaMask/utils/pull/197))
|
|
207
|
-
|
|
208
|
-
## [9.0.0]
|
|
209
|
-
|
|
210
|
-
### Changed
|
|
211
|
-
|
|
212
|
-
- **BREAKING:** The return types of functions `getChecksumAddress`, `numberToHex`, `bigIntToHex` are narrowed from `string` to `Hex` ([#193](https://github.com/MetaMask/utils/pull/193))
|
|
213
|
-
|
|
214
|
-
### Fixed
|
|
215
|
-
|
|
216
|
-
- Bump `@metamask/superstruct` from `^3.0.0` to `^3.1.0` ([#194](https://github.com/MetaMask/utils/pull/194))
|
|
217
|
-
- If `@metamask/utils` `<=8.5.0` is used with `@metamask/superstruct` `>=3.1.0` the following error may be encountered:
|
|
218
|
-
```ts
|
|
219
|
-
error TS2742: The inferred type of 'ExampleType' cannot be named without a reference to '@metamask/utils/node_modules/@metamask/superstruct'. This is likely not portable. A type annotation is necessary.
|
|
220
|
-
```
|
|
221
|
-
This can be resolved by updating `@metamask/utils` to `>=9.0.0`.
|
|
222
|
-
|
|
223
|
-
## [8.5.0]
|
|
224
|
-
|
|
225
|
-
### Changed
|
|
226
|
-
|
|
227
|
-
- Bump dependency `semver` from `^5.7.1` to `^7.6.0` ([#181](https://github.com/MetaMask/utils/pull/181)).
|
|
228
|
-
|
|
229
|
-
### Fixed
|
|
230
|
-
|
|
231
|
-
- Replace dependency `superstruct` `^1.0.3` with ESM-compatible `@metamask/superstruct` `^3.0.0` ([#185](https://github.com/MetaMask/utils/pull/185)).
|
|
232
|
-
- This fixes the issue of this package being unusable by any TypeScript project that uses `Node16` or `NodeNext` as its `moduleResolution` option.
|
|
233
|
-
- Produce and export ESM-compatible TypeScript type declaration files in addition to CommonJS-compatible declaration files ([#182](https://github.com/MetaMask/utils/pull/182))
|
|
234
|
-
- Previously, this package shipped with only one variant of type declaration files, and these files were only CommonJS-compatible, and the `exports` field in `package.json` linked to these files. This is an anti-pattern and was rightfully flagged by the ["Are the Types Wrong?"](https://arethetypeswrong.github.io/) tool as ["masquerading as CJS"](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md). All of the ATTW checks now pass.
|
|
235
|
-
- Remove chunk files ([#182](https://github.com/MetaMask/utils/pull/182)).
|
|
236
|
-
- Previously, the build tool we used to generate JavaScript files extracted common code to "chunk" files. While this was intended to make this package more tree-shakeable, it also made debugging more difficult for our development teams. These chunk files are no longer present.
|
|
237
|
-
|
|
238
|
-
## [8.4.0]
|
|
239
|
-
|
|
240
|
-
### Added
|
|
241
|
-
|
|
242
|
-
- Add `toCaipChainId` utility function ([#175](https://github.com/MetaMask/utils/pull/175))
|
|
243
|
-
- Add `KnownCaipNamespace` enum ([#175](https://github.com/MetaMask/utils/pull/175))
|
|
244
|
-
|
|
245
|
-
### Changed
|
|
246
|
-
|
|
247
|
-
- Update docs for `createDeferredPromise` to caution against using `suppressUnhandledRejection` ([#174](https://github.com/MetaMask/utils/pull/174))
|
|
248
|
-
|
|
249
|
-
### Fixed
|
|
250
|
-
|
|
251
|
-
- Fix `createSandbox` to assign a unique name to the sandbox directory, so that it can be used in multiple concurrently running Jest tests ([#171](https://github.com/MetaMask/utils/pull/171))
|
|
252
|
-
|
|
253
|
-
## [8.3.0]
|
|
254
|
-
|
|
255
|
-
### Added
|
|
256
|
-
|
|
257
|
-
- Add `createDeferredPromise` ([#164](https://github.com/MetaMask/utils/pull/164))
|
|
258
|
-
|
|
259
|
-
## [8.2.1]
|
|
260
|
-
|
|
261
|
-
### Fixed
|
|
262
|
-
|
|
263
|
-
- Fix issue with source maps where line numbers were incorrect for src/error.ts ([#156](https://github.com/MetaMask/utils/pull/156))
|
|
264
|
-
|
|
265
|
-
## [8.2.0]
|
|
266
|
-
|
|
267
|
-
### Added
|
|
268
|
-
|
|
269
|
-
- Add struct utils for validating JSON objects with optional values ([#136](https://github.com/MetaMask/utils/pull/136))
|
|
270
|
-
- Add filesystem utils ([#148](https://github.com/MetaMask/utils/pull/148))
|
|
271
|
-
- Add error utils ([#146](https://github.com/MetaMask/utils/pull/146), [#151](https://github.com/MetaMask/utils/pull/151))
|
|
272
|
-
- Add base64 encoding and decoding functions ([#145](https://github.com/MetaMask/utils/pull/145))
|
|
273
|
-
|
|
274
|
-
### Changed
|
|
275
|
-
|
|
276
|
-
- Use `tsup` for bundling ([#144](https://github.com/MetaMask/utils/pull/144))
|
|
277
|
-
- This makes the package fully compliant with ES modules.
|
|
278
|
-
- Bump `@ethereumjs/tx` from `4.1.2` to `4.2.0` ([#133](https://github.com/MetaMask/utils/pull/133))
|
|
279
|
-
|
|
280
|
-
## [8.1.0]
|
|
281
|
-
|
|
282
|
-
### Changed
|
|
283
|
-
|
|
284
|
-
- Make types for JSON-RPC-related structs more accurate ([#134](https://github.com/MetaMask/utils/pull/134))
|
|
285
|
-
- Aligning `JsonRpcParams` to be optional, yet not `undefined`.
|
|
286
|
-
- Updated types:
|
|
287
|
-
- `InferWithParams`
|
|
288
|
-
- `JsonRpcNotificationStruct`
|
|
289
|
-
- `JsonRpcParamsStruct`
|
|
290
|
-
- `JsonRpcRequestStruct`
|
|
291
|
-
|
|
292
|
-
## [8.0.0]
|
|
293
|
-
|
|
294
|
-
### Changed
|
|
295
|
-
|
|
296
|
-
- **BREAKING:** `JsonRpcParams` type no longer accepts `undefined` as value, as `undefined` is not a valid JSON type ([#130](https://github.com/MetaMask/utils/pull/130))
|
|
297
|
-
|
|
298
|
-
## [7.1.0]
|
|
299
|
-
|
|
300
|
-
### Added
|
|
301
|
-
|
|
302
|
-
- Add CAIP-2 and CAIP-10 types ([#116](https://github.com/MetaMask/utils/pull/116))
|
|
303
|
-
|
|
304
|
-
## [7.0.0]
|
|
305
|
-
|
|
306
|
-
### Added
|
|
307
|
-
|
|
308
|
-
- Add `getKnownPropertyNames` function ([#111](https://github.com/MetaMask/utils/pull/111))
|
|
309
|
-
|
|
310
|
-
### Changed
|
|
311
|
-
|
|
312
|
-
- **BREAKING:** Build the package as both CJS and ESM ([#115](https://github.com/MetaMask/utils/pull/115), [#124](https://github.com/MetaMask/utils/pull/124))
|
|
313
|
-
- It's no longer possible to import from the `dist` folder. Everything must be imported from `@metamask/utils`.
|
|
314
|
-
- Bump `semver` to `^7.5.4` ([#123](https://github.com/MetaMask/utils/pull/123))
|
|
315
|
-
|
|
316
|
-
## [6.2.0]
|
|
317
|
-
|
|
318
|
-
### Added
|
|
319
|
-
|
|
320
|
-
- Add address related utils ([#112](https://github.com/MetaMask/utils/pull/112))
|
|
321
|
-
- `isValidHexAddress` has been added to check the validity of an hex address
|
|
322
|
-
- `getChecksumAddress` has been added to calculate the ERC-55 mixed-case checksum of an hex address
|
|
323
|
-
- `isValidChecksumAddress` has been added to check the validity of an ERC-55 mixed-case checksum address
|
|
324
|
-
|
|
325
|
-
## [6.1.0]
|
|
326
|
-
|
|
327
|
-
### Added
|
|
328
|
-
|
|
329
|
-
- Add optional `destroy` method to `Keyring` type ([#108](https://github.com/MetaMask/utils/pull/108))
|
|
330
|
-
|
|
331
|
-
## [6.0.1]
|
|
332
|
-
|
|
333
|
-
### Fixed
|
|
334
|
-
|
|
335
|
-
- Strip `__proto__` and `constructor` JSON properties in `getSafeJson` ([#105](https://github.com/MetaMask/utils/pull/105))
|
|
336
|
-
|
|
337
|
-
## [6.0.0]
|
|
338
|
-
|
|
339
|
-
### Changed
|
|
340
|
-
|
|
341
|
-
- **BREAKING:** Bump minimum Node version to 16 ([#102](https://github.com/MetaMask/utils/pull/102))
|
|
342
|
-
- **BREAKING:** Target `ES2020` ([#102](https://github.com/MetaMask/utils/pull/102))
|
|
343
|
-
|
|
344
|
-
### Fixed
|
|
345
|
-
|
|
346
|
-
- Fix JSON validation security issue ([#103](https://github.com/MetaMask/utils/pull/103))
|
|
347
|
-
- This adds a new function `getSafeJson` which validates and returns sanitized JSON.
|
|
348
|
-
|
|
349
|
-
## [5.0.2]
|
|
350
|
-
|
|
351
|
-
### Changed
|
|
352
|
-
|
|
353
|
-
- The `Keyring` exposes a new optional method `init` ([#99](https://github.com/MetaMask/utils/pull/99))
|
|
354
|
-
|
|
355
|
-
### Fixed
|
|
356
|
-
|
|
357
|
-
- Bump `@ethereumjs/tx` to `4.1.2` to address runtime compatibility issues ([#100](https://github.com/MetaMask/utils/pull/100))
|
|
358
|
-
|
|
359
|
-
## [5.0.1]
|
|
360
|
-
|
|
361
|
-
### Fixed
|
|
362
|
-
|
|
363
|
-
- Keep original type when using `hasProperty` if defined ([#94](https://github.com/MetaMask/utils/pull/94))
|
|
364
|
-
|
|
365
|
-
## [5.0.0]
|
|
366
|
-
|
|
367
|
-
### Changed
|
|
368
|
-
|
|
369
|
-
- **BREAKING:** Update `Keyring` type ([#89](https://github.com/MetaMask/utils/pull/89))
|
|
370
|
-
- The `Keyring` class now uses the data types `TypedTransaction` and `TxData` from `@ethereumjs/tx` (`v4.1.1`).
|
|
371
|
-
- The `Keyring` now exposes a new optional method called `generateRandomMnemonic`.
|
|
372
|
-
|
|
373
|
-
## [4.0.0]
|
|
374
|
-
|
|
375
10
|
### Changed
|
|
376
11
|
|
|
377
|
-
-
|
|
378
|
-
-
|
|
379
|
-
- Fixes edge cases in our JSON validation logic.
|
|
380
|
-
- The previous function used for JSON validation (`validateJsonAndGetSize`) was removed.
|
|
381
|
-
- The `isValidJson` function now uses the new JSON validation logic.
|
|
382
|
-
- To get the size of a JSON value, you can use the `getJsonSize` function.
|
|
383
|
-
|
|
384
|
-
## [3.6.0]
|
|
385
|
-
|
|
386
|
-
### Added
|
|
387
|
-
|
|
388
|
-
- Add `Keyring` types ([#74](https://github.com/MetaMask/utils/pull/74))
|
|
389
|
-
- New data types added. These are `Keyring`, `Transaction` (`LegacyTransaction`, `EIP2930Transaction`, `EIP1559Transaction`), `SignedTransaction`, `Signature`, and `Eip1024EncryptedData`.
|
|
390
|
-
|
|
391
|
-
## [3.5.0]
|
|
392
|
-
|
|
393
|
-
### Changed
|
|
394
|
-
|
|
395
|
-
- Improve the `hasProperty` function ([#79](https://github.com/MetaMask/utils/pull/79), [#80](https://github.com/MetaMask/utils/pull/80))
|
|
396
|
-
- This function now acts as a type guard, informing TypeScript that the property exists.
|
|
397
|
-
- The function is now compatible with more types of objects, such as Errors and class instances.
|
|
398
|
-
|
|
399
|
-
## [3.4.1]
|
|
400
|
-
|
|
401
|
-
### Fixed
|
|
402
|
-
|
|
403
|
-
- Bump `superstruct` to `^1.0.3` ([#71](https://github.com/MetaMask/utils/pull/71))
|
|
404
|
-
|
|
405
|
-
## [3.4.0]
|
|
406
|
-
|
|
407
|
-
### Added
|
|
408
|
-
|
|
409
|
-
- Add types and utility functions for validating versions and checksums ([#67](https://github.com/MetaMask/utils/pull/67), [#69](https://github.com/MetaMask/utils/pull/69))
|
|
410
|
-
|
|
411
|
-
### Fixed
|
|
412
|
-
|
|
413
|
-
- JSON-RPC types now have a default generic `Params` value ([#54](https://github.com/MetaMask/utils/pull/54))
|
|
414
|
-
|
|
415
|
-
## [3.3.1]
|
|
416
|
-
|
|
417
|
-
### Fixed
|
|
418
|
-
|
|
419
|
-
- JSON-RPC parameters are now properly cast to Json upon validation ([#51](https://github.com/MetaMask/utils/pull/51))
|
|
420
|
-
|
|
421
|
-
## [3.3.0]
|
|
422
|
-
|
|
423
|
-
### Added
|
|
424
|
-
|
|
425
|
-
- Add more assertion utils ([#49](https://github.com/MetaMask/utils/pull/49))
|
|
426
|
-
- Add JSON-RPC error validation functions ([#46](https://github.com/MetaMask/utils/pull/46))
|
|
427
|
-
- Add convenience function for creating a `DataView` ([#45](https://github.com/MetaMask/utils/pull/45))
|
|
428
|
-
|
|
429
|
-
### Fixed
|
|
430
|
-
|
|
431
|
-
- Update JSON validation logic ([#47](https://github.com/MetaMask/utils/pull/47))
|
|
432
|
-
- Validation would previously allow for `undefined` values, which is not a standard JSON type
|
|
433
|
-
|
|
434
|
-
## [3.2.0]
|
|
435
|
-
|
|
436
|
-
### Added
|
|
437
|
-
|
|
438
|
-
- Add `PendingJsonRpcResponse` type ([#43](https://github.com/MetaMask/utils/pull/43))
|
|
439
|
-
- Add utils for converting between numbers and hex ([#41](https://github.com/MetaMask/utils/pull/41))
|
|
440
|
-
- Add coercion utils ([#38](https://github.com/MetaMask/utils/pull/38))
|
|
441
|
-
|
|
442
|
-
## [3.1.0]
|
|
443
|
-
|
|
444
|
-
### Added
|
|
445
|
-
|
|
446
|
-
- Add assertion utils ([#33](https://github.com/MetaMask/utils/pull/33))
|
|
447
|
-
- Add util functions for encoding and decoding bytes ([#34](https://github.com/MetaMask/utils/pull/34))
|
|
448
|
-
|
|
449
|
-
### Fixed
|
|
450
|
-
|
|
451
|
-
- Make JSON-RPC error `data` property optional ([#31](https://github.com/MetaMask/utils/pull/31))
|
|
452
|
-
- Don't include test files in dist folder ([#35](https://github.com/MetaMask/utils/pull/35))
|
|
453
|
-
- Fix typo in README ([#28](https://github.com/MetaMask/utils/pull/28))
|
|
454
|
-
|
|
455
|
-
## [3.0.3]
|
|
456
|
-
|
|
457
|
-
### Fixed
|
|
458
|
-
|
|
459
|
-
- Allow omitting JSON-RPC params when params can be undefined ([#29](https://github.com/MetaMask/utils/pull/29))
|
|
460
|
-
|
|
461
|
-
## [3.0.2]
|
|
462
|
-
|
|
463
|
-
### Fixed
|
|
464
|
-
|
|
465
|
-
- Bump `superstruct` to ^0.16.5 ([#26](https://github.com/MetaMask/utils/pull/26))
|
|
466
|
-
- `superstruct`s 0.16.1 through 0.16.4 were not compatible with Node 14; this restores that compatibility.
|
|
467
|
-
|
|
468
|
-
## [3.0.1]
|
|
469
|
-
|
|
470
|
-
### Fixed
|
|
471
|
-
|
|
472
|
-
- Promote `@types/debug` from development dependencies to production dependencies ([#23](https://github.com/MetaMask/utils/pull/23))
|
|
473
|
-
|
|
474
|
-
## [3.0.0]
|
|
475
|
-
|
|
476
|
-
### Added
|
|
477
|
-
|
|
478
|
-
- Add logging functions ([#20](https://github.com/MetaMask/utils/pull/20))
|
|
479
|
-
- Add frozen collections (implemented in [#5](https://github.com/MetaMask/utils/pull/5) but exported in [#19](https://github.com/MetaMask/utils/pull/19))
|
|
480
|
-
|
|
481
|
-
### Changed
|
|
482
|
-
|
|
483
|
-
- **BREAKING:** Improve types and type validation ([#19](https://github.com/MetaMask/utils/pull/19))
|
|
484
|
-
- Various type changes have been made that might be breaking:
|
|
485
|
-
- The `JsonRpcRequest` and `JsonRpcNotification` types now include a generic constraint requiring that the `Params` type extends the `JsonRpcParams` type.
|
|
486
|
-
- The `JsonRpcSuccess` and `JsonRpcResponse` types now include a generic contraint for the `Result` type, requiring that it extends the `Json` type.
|
|
487
|
-
- Various validation functions now accept `unknown` parameters rather than specific types. This should not be breaking except that it may affect type inference for the parameters passed in.
|
|
488
|
-
- New JSON-related functions have been added:
|
|
489
|
-
- `assertIsJsonRpcResponse`
|
|
490
|
-
- `isJsonRpcResponse`
|
|
491
|
-
- `InferWithParams`
|
|
492
|
-
- `JsonRpcParams`
|
|
493
|
-
- New JSON Struct types have been added:
|
|
494
|
-
- `JsonRpcErrorStruct`
|
|
495
|
-
- `JsonRpcFailureStruct`
|
|
496
|
-
- `JsonRpcIdStruct`
|
|
497
|
-
- `JsonRpcParamsStruct`
|
|
498
|
-
- `JsonRpcRequestStruct`
|
|
499
|
-
- `JsonRpcResponseStruct`
|
|
500
|
-
- `JsonRpcSuccessStruct`
|
|
501
|
-
- `JsonRpcVersionStruct`
|
|
502
|
-
- `JsonStruct`
|
|
503
|
-
|
|
504
|
-
## [2.1.0]
|
|
505
|
-
|
|
506
|
-
### Added
|
|
507
|
-
|
|
508
|
-
- Add JSON storage validation and limit utilities ([#14](https://github.com/MetaMask/utils/pull/14))
|
|
509
|
-
- Adds a new function `validateJsonAndGetSize`.
|
|
510
|
-
|
|
511
|
-
## [2.0.0]
|
|
512
|
-
|
|
513
|
-
### Added
|
|
514
|
-
|
|
515
|
-
- Add more JSON utils ([#8](https://github.com/MetaMask/utils/pull/8))
|
|
516
|
-
|
|
517
|
-
### Changed
|
|
518
|
-
|
|
519
|
-
- **BREAKING:** Refactor and expand time utils ([#9](https://github.com/MetaMask/utils/pull/9))
|
|
520
|
-
- Adds a new function, `inMilliseconds`, and moves the time constants into a TypeScript `enum`.
|
|
521
|
-
|
|
522
|
-
## [1.0.0]
|
|
523
|
-
|
|
524
|
-
### Added
|
|
525
|
-
|
|
526
|
-
- Initial release
|
|
12
|
+
- This package was migrated from `MetaMask/utils` to the `MetaMask/core` monorepo ([#10175](https://github.com/MetaMask/core/pull/10175))
|
|
13
|
+
- See [MetaMask/utils](https://github.com/MetaMask/utils/blob/main/CHANGELOG.md) for the original changelog, which covers every release up to and including `12.0.0`.
|
|
527
14
|
|
|
528
|
-
[Unreleased]: https://github.com/MetaMask/
|
|
529
|
-
[12.0.0]: https://github.com/MetaMask/utils/compare/v11.12.1...v12.0.0
|
|
530
|
-
[11.12.1]: https://github.com/MetaMask/utils/compare/v11.12.0...v11.12.1
|
|
531
|
-
[11.12.0]: https://github.com/MetaMask/utils/compare/v11.11.0...v11.12.0
|
|
532
|
-
[11.11.0]: https://github.com/MetaMask/utils/compare/v11.10.0...v11.11.0
|
|
533
|
-
[11.10.0]: https://github.com/MetaMask/utils/compare/v11.9.0...v11.10.0
|
|
534
|
-
[11.9.0]: https://github.com/MetaMask/utils/compare/v11.8.1...v11.9.0
|
|
535
|
-
[11.8.1]: https://github.com/MetaMask/utils/compare/v11.8.0...v11.8.1
|
|
536
|
-
[11.8.0]: https://github.com/MetaMask/utils/compare/v11.7.0...v11.8.0
|
|
537
|
-
[11.7.0]: https://github.com/MetaMask/utils/compare/v11.6.0...v11.7.0
|
|
538
|
-
[11.6.0]: https://github.com/MetaMask/utils/compare/v11.5.0...v11.6.0
|
|
539
|
-
[11.5.0]: https://github.com/MetaMask/utils/compare/v11.4.2...v11.5.0
|
|
540
|
-
[11.4.2]: https://github.com/MetaMask/utils/compare/v11.4.1...v11.4.2
|
|
541
|
-
[11.4.1]: https://github.com/MetaMask/utils/compare/v11.4.0...v11.4.1
|
|
542
|
-
[11.4.0]: https://github.com/MetaMask/utils/compare/v11.3.0...v11.4.0
|
|
543
|
-
[11.3.0]: https://github.com/MetaMask/utils/compare/v11.2.0...v11.3.0
|
|
544
|
-
[11.2.0]: https://github.com/MetaMask/utils/compare/v11.1.0...v11.2.0
|
|
545
|
-
[11.1.0]: https://github.com/MetaMask/utils/compare/v11.0.1...v11.1.0
|
|
546
|
-
[11.0.1]: https://github.com/MetaMask/utils/compare/v11.0.0...v11.0.1
|
|
547
|
-
[11.0.0]: https://github.com/MetaMask/utils/compare/v10.0.1...v11.0.0
|
|
548
|
-
[10.0.1]: https://github.com/MetaMask/utils/compare/v10.0.0...v10.0.1
|
|
549
|
-
[10.0.0]: https://github.com/MetaMask/utils/compare/v9.3.0...v10.0.0
|
|
550
|
-
[9.3.0]: https://github.com/MetaMask/utils/compare/v9.2.1...v9.3.0
|
|
551
|
-
[9.2.1]: https://github.com/MetaMask/utils/compare/v9.2.0...v9.2.1
|
|
552
|
-
[9.2.0]: https://github.com/MetaMask/utils/compare/v9.1.0...v9.2.0
|
|
553
|
-
[9.1.0]: https://github.com/MetaMask/utils/compare/v9.0.0...v9.1.0
|
|
554
|
-
[9.0.0]: https://github.com/MetaMask/utils/compare/v8.5.0...v9.0.0
|
|
555
|
-
[8.5.0]: https://github.com/MetaMask/utils/compare/v8.4.0...v8.5.0
|
|
556
|
-
[8.4.0]: https://github.com/MetaMask/utils/compare/v8.3.0...v8.4.0
|
|
557
|
-
[8.3.0]: https://github.com/MetaMask/utils/compare/v8.2.1...v8.3.0
|
|
558
|
-
[8.2.1]: https://github.com/MetaMask/utils/compare/v8.2.0...v8.2.1
|
|
559
|
-
[8.2.0]: https://github.com/MetaMask/utils/compare/v8.1.0...v8.2.0
|
|
560
|
-
[8.1.0]: https://github.com/MetaMask/utils/compare/v8.0.0...v8.1.0
|
|
561
|
-
[8.0.0]: https://github.com/MetaMask/utils/compare/v7.1.0...v8.0.0
|
|
562
|
-
[7.1.0]: https://github.com/MetaMask/utils/compare/v7.0.0...v7.1.0
|
|
563
|
-
[7.0.0]: https://github.com/MetaMask/utils/compare/v6.2.0...v7.0.0
|
|
564
|
-
[6.2.0]: https://github.com/MetaMask/utils/compare/v6.1.0...v6.2.0
|
|
565
|
-
[6.1.0]: https://github.com/MetaMask/utils/compare/v6.0.1...v6.1.0
|
|
566
|
-
[6.0.1]: https://github.com/MetaMask/utils/compare/v6.0.0...v6.0.1
|
|
567
|
-
[6.0.0]: https://github.com/MetaMask/utils/compare/v5.0.2...v6.0.0
|
|
568
|
-
[5.0.2]: https://github.com/MetaMask/utils/compare/v5.0.1...v5.0.2
|
|
569
|
-
[5.0.1]: https://github.com/MetaMask/utils/compare/v5.0.0...v5.0.1
|
|
570
|
-
[5.0.0]: https://github.com/MetaMask/utils/compare/v4.0.0...v5.0.0
|
|
571
|
-
[4.0.0]: https://github.com/MetaMask/utils/compare/v3.6.0...v4.0.0
|
|
572
|
-
[3.6.0]: https://github.com/MetaMask/utils/compare/v3.5.0...v3.6.0
|
|
573
|
-
[3.5.0]: https://github.com/MetaMask/utils/compare/v3.4.1...v3.5.0
|
|
574
|
-
[3.4.1]: https://github.com/MetaMask/utils/compare/v3.4.0...v3.4.1
|
|
575
|
-
[3.4.0]: https://github.com/MetaMask/utils/compare/v3.3.1...v3.4.0
|
|
576
|
-
[3.3.1]: https://github.com/MetaMask/utils/compare/v3.3.0...v3.3.1
|
|
577
|
-
[3.3.0]: https://github.com/MetaMask/utils/compare/v3.2.0...v3.3.0
|
|
578
|
-
[3.2.0]: https://github.com/MetaMask/utils/compare/v3.1.0...v3.2.0
|
|
579
|
-
[3.1.0]: https://github.com/MetaMask/utils/compare/v3.0.3...v3.1.0
|
|
580
|
-
[3.0.3]: https://github.com/MetaMask/utils/compare/v3.0.2...v3.0.3
|
|
581
|
-
[3.0.2]: https://github.com/MetaMask/utils/compare/v3.0.1...v3.0.2
|
|
582
|
-
[3.0.1]: https://github.com/MetaMask/utils/compare/v3.0.0...v3.0.1
|
|
583
|
-
[3.0.0]: https://github.com/MetaMask/utils/compare/v2.1.0...v3.0.0
|
|
584
|
-
[2.1.0]: https://github.com/MetaMask/utils/compare/v2.0.0...v2.1.0
|
|
585
|
-
[2.0.0]: https://github.com/MetaMask/utils/compare/v1.0.0...v2.0.0
|
|
586
|
-
[1.0.0]: https://github.com/MetaMask/utils/releases/tag/v1.0.0
|
|
15
|
+
[Unreleased]: https://github.com/MetaMask/core/
|
package/README.md
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
# MetaMask Utils
|
|
1
|
+
# `@metamask/utils`
|
|
4
2
|
|
|
5
3
|
Various JavaScript/TypeScript utilities of wide relevance to the MetaMask codebase.
|
|
6
4
|
|
|
@@ -12,95 +10,6 @@ or
|
|
|
12
10
|
|
|
13
11
|
`npm install @metamask/utils`
|
|
14
12
|
|
|
15
|
-
## API
|
|
16
|
-
|
|
17
|
-
The full API documentation for the latest published version of this library is [available here](https://metamask.github.io/utils/index.html).
|
|
18
|
-
|
|
19
13
|
## Contributing
|
|
20
14
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
- Install [Node.js](https://nodejs.org) version 16
|
|
24
|
-
- If you are using [nvm](https://github.com/creationix/nvm#installation) (recommended) running `nvm use` will automatically choose the right node version for you.
|
|
25
|
-
- Install [Yarn v3](https://yarnpkg.com/getting-started/install)
|
|
26
|
-
- Run `yarn install` to install dependencies and run any required post-install scripts
|
|
27
|
-
|
|
28
|
-
### Testing and Linting
|
|
29
|
-
|
|
30
|
-
Run `yarn test` to run the tests once. To run tests on file changes, run `yarn test:watch`.
|
|
31
|
-
|
|
32
|
-
Run `yarn lint` to run the linter, or run `yarn lint:fix` to run the linter and fix any automatically fixable issues.
|
|
33
|
-
|
|
34
|
-
### Documentation
|
|
35
|
-
|
|
36
|
-
The API documentation can be generated with the command `yarn docs`, which saves it in the `./docs` directory. Open the `./docs/index.html` file to browse the documentation.
|
|
37
|
-
|
|
38
|
-
### Release & Publishing
|
|
39
|
-
|
|
40
|
-
The project follows the same release process as the other libraries in the MetaMask organization. The GitHub Actions [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) and [`action-publish-release`](https://github.com/MetaMask/action-publish-release) are used to automate the release process; see those repositories for more information about how they work.
|
|
41
|
-
|
|
42
|
-
1. Choose a release version.
|
|
43
|
-
- The release version should be chosen according to SemVer. Analyze the changes to see whether they include any breaking changes, new features, or deprecations, then choose the appropriate SemVer version. See [the SemVer specification](https://semver.org/) for more information.
|
|
44
|
-
|
|
45
|
-
2. If this release is backporting changes onto a previous release, then ensure there is a major version branch for that version (e.g. `1.x` for a `v1` backport release).
|
|
46
|
-
- The major version branch should be set to the most recent release with that major version. For example, when backporting a `v1.0.2` release, you'd want to ensure there was a `1.x` branch that was set to the `v1.0.1` tag.
|
|
47
|
-
|
|
48
|
-
3. Trigger the [`workflow_dispatch`](https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch) event [manually](https://docs.github.com/en/actions/managing-workflow-runs/manually-running-a-workflow) for the `Create Release Pull Request` action to create the release PR.
|
|
49
|
-
- For a backport release, the base branch should be the major version branch that you ensured existed in step 2. For a normal release, the base branch should be the main branch for that repository (which should be the default value).
|
|
50
|
-
- This should trigger the [`action-create-release-pr`](https://github.com/MetaMask/action-create-release-pr) workflow to create the release PR.
|
|
51
|
-
|
|
52
|
-
4. Update the changelog to move each change entry into the appropriate change category ([See here](https://keepachangelog.com/en/1.0.0/#types) for the full list of change categories, and the correct ordering), and edit them to be more easily understood by users of the package.
|
|
53
|
-
- Generally any changes that don't affect consumers of the package (e.g. lockfile changes or development environment changes) are omitted. Exceptions may be made for changes that might be of interest despite not having an effect upon the published package (e.g. major test improvements, security improvements, improved documentation, etc.).
|
|
54
|
-
- Try to explain each change in terms that users of the package would understand (e.g. avoid referencing internal variables/concepts).
|
|
55
|
-
- Consolidate related changes into one change entry if it makes it easier to explain.
|
|
56
|
-
- Run `yarn auto-changelog validate --rc` to check that the changelog is correctly formatted.
|
|
57
|
-
|
|
58
|
-
5. Review and QA the release.
|
|
59
|
-
- If changes are made to the base branch, the release branch will need to be updated with these changes and review/QA will need to restart again. As such, it's probably best to avoid merging other PRs into the base branch while review is underway.
|
|
60
|
-
|
|
61
|
-
6. Squash & Merge the release.
|
|
62
|
-
- This should trigger the [`action-publish-release`](https://github.com/MetaMask/action-publish-release) workflow to tag the final release commit and publish the release on GitHub.
|
|
63
|
-
|
|
64
|
-
7. Publish the release on npm.
|
|
65
|
-
- Be very careful to use a clean local environment to publish the release, and follow exactly the same steps used during CI.
|
|
66
|
-
- Use `npm publish --dry-run` to examine the release contents to ensure the correct files are included. Compare to previous releases if necessary (e.g. using `https://unpkg.com/browse/[package name]@[package version]/`).
|
|
67
|
-
- Once you are confident the release contents are correct, publish the release using `npm publish`.
|
|
68
|
-
|
|
69
|
-
### Testing changes in other projects using preview builds
|
|
70
|
-
|
|
71
|
-
If you are working on a pull request and want to test changes in another project before you publish them, you can create a _preview build_ and then configure your project to use it.
|
|
72
|
-
|
|
73
|
-
#### Creating a preview build
|
|
74
|
-
|
|
75
|
-
1. Within your pull request, post a comment with the text `@metamaskbot publish-preview`. This starts the `publish-preview` GitHub action, which will create a preview build and publish it to NPM.
|
|
76
|
-
2. After a few minutes, the action should complete and you will see a new comment. Note two things:
|
|
77
|
-
- The name is scoped to `@metamask-previews` instead of `@metamask`.
|
|
78
|
-
- The ID of the last commit in the branch is appended to the version, e.g. `1.2.3-preview-e2df9b4` instead of `1.2.3`.
|
|
79
|
-
|
|
80
|
-
#### Using a preview build
|
|
81
|
-
|
|
82
|
-
To use a preview build within a project, you need to override the resolution logic for your package manager so that the "production" version of that package is replaced with the preview version. Here's how you do that:
|
|
83
|
-
|
|
84
|
-
1. Open `package.json` in the project and locate the entry for this package in `dependencies`.
|
|
85
|
-
2. Locate the section responsible for resolution overrides (or create it if it doesn't exist). If you're using Yarn, this is `resolutions`; if you're using NPM or any other package manager, this is `overrides`.
|
|
86
|
-
3. Add a line to this section that mirrors the dependency entry on the left-hand side and points to the preview version on the right-hand side. Note the exact format of the left-hand side will differ based on which version of Yarn or NPM you are using. For example:
|
|
87
|
-
- For Yarn Modern, you will add something like this to `resolutions`:
|
|
88
|
-
```
|
|
89
|
-
"@metamask/utils@^1.2.3": "npm:@metamask-previews/utils@1.2.3-preview-abcdefg"
|
|
90
|
-
```
|
|
91
|
-
- For Yarn Classic, you will add something like this to `resolutions`:
|
|
92
|
-
```
|
|
93
|
-
"@metamask/utils": "npm:@metamask-previews/utils@1.2.3-preview-abcdefg"
|
|
94
|
-
```
|
|
95
|
-
- For NPM, you will add something like this to `overrides`:
|
|
96
|
-
```
|
|
97
|
-
"@metamask/utils": "npm:@metamask-previews/utils@1.2.3-preview-abcdefg"
|
|
98
|
-
```
|
|
99
|
-
4. Run `yarn install`.
|
|
100
|
-
|
|
101
|
-
#### Updating a preview build
|
|
102
|
-
|
|
103
|
-
If you make more changes to your pull request and want to create a new preview build:
|
|
104
|
-
|
|
105
|
-
1. Post another `@metamaskbot` comment on the pull request and wait for the response.
|
|
106
|
-
2. Update the version of the preview build in your project's `package.json`. Make sure to re-run `yarn install`!
|
|
15
|
+
This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme).
|
package/dist/json.d.ts
CHANGED
|
@@ -138,8 +138,8 @@ export type JsonRpcId = Infer<typeof JsonRpcIdStruct>;
|
|
|
138
138
|
export declare const JsonRpcErrorStruct: Struct<{
|
|
139
139
|
code: number;
|
|
140
140
|
message: string;
|
|
141
|
-
data?: Json & ExactOptionalGuard;
|
|
142
|
-
stack?: string;
|
|
141
|
+
data?: (Json & ExactOptionalGuard) | undefined;
|
|
142
|
+
stack?: string | undefined;
|
|
143
143
|
}, unknown>;
|
|
144
144
|
/**
|
|
145
145
|
* Mark a certain key of a type as optional.
|
|
@@ -159,7 +159,7 @@ export declare const JsonRpcRequestStruct: Struct<{
|
|
|
159
159
|
id: string | number | null;
|
|
160
160
|
jsonrpc: "2.0";
|
|
161
161
|
method: string;
|
|
162
|
-
params?: (Json[] | Record<string, Json>) & ExactOptionalGuard;
|
|
162
|
+
params?: ((Json[] | Record<string, Json>) & ExactOptionalGuard) | undefined;
|
|
163
163
|
}, unknown>;
|
|
164
164
|
export type InferWithParams<Type extends Struct<any>, Params extends JsonRpcParams> = Infer<Type> & {
|
|
165
165
|
params?: Params;
|
|
@@ -171,7 +171,7 @@ export type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> = Infer
|
|
|
171
171
|
export declare const JsonRpcNotificationStruct: Struct<{
|
|
172
172
|
jsonrpc: "2.0";
|
|
173
173
|
method: string;
|
|
174
|
-
params?: (Json[] | Record<string, Json>) & ExactOptionalGuard;
|
|
174
|
+
params?: ((Json[] | Record<string, Json>) & ExactOptionalGuard) | undefined;
|
|
175
175
|
}, unknown>;
|
|
176
176
|
/**
|
|
177
177
|
* A JSON-RPC notification object.
|
|
@@ -217,8 +217,8 @@ export declare const PendingJsonRpcResponseStruct: Struct<{
|
|
|
217
217
|
error?: {
|
|
218
218
|
code: number;
|
|
219
219
|
message: string;
|
|
220
|
-
data?: Json & ExactOptionalGuard;
|
|
221
|
-
stack?: string;
|
|
220
|
+
data?: (Json & ExactOptionalGuard) | undefined;
|
|
221
|
+
stack?: string | undefined;
|
|
222
222
|
} | undefined;
|
|
223
223
|
}, {
|
|
224
224
|
id: Struct<string | number | null, null>;
|
|
@@ -227,8 +227,8 @@ export declare const PendingJsonRpcResponseStruct: Struct<{
|
|
|
227
227
|
error: Struct<{
|
|
228
228
|
code: number;
|
|
229
229
|
message: string;
|
|
230
|
-
data?: Json & ExactOptionalGuard;
|
|
231
|
-
stack?: string;
|
|
230
|
+
data?: (Json & ExactOptionalGuard) | undefined;
|
|
231
|
+
stack?: string | undefined;
|
|
232
232
|
} | undefined, unknown>;
|
|
233
233
|
}>;
|
|
234
234
|
/**
|
package/dist/json.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.d.ts","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,EAiBL,MAAM,EAEP,MAAM,uBAAuB,CAAC;AAC/B,OAAO,KAAK,EAEV,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAE/B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,aAAa,CAAC;AAI7D;;GAEG;AACH,MAAM,MAAM,IAAI,GACZ,IAAI,GACJ,OAAO,GACP,MAAM,GACN,MAAM,GACN,IAAI,EAAE,GACN;IAAE,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC;AAE7B;;;;;;;;;;GAUG;AACH,MAAM,MAAM,cAAc,CAAC,MAAM,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI;KAClE,GAAG,IAAI,MAAM,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,kBAAkB,GAC1D,GAAG,GACH,KAAK,CAAC,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC,SAAS,kBAAkB,GAAG,CAAC,MAAM,QAAQ,CAAC,GAClE,QAAQ,GACR,KAAK;CACV,GAAG;KACD,GAAG,IAAI,MAAM,MAAM,IAAI,MAAM,CAAC,GAAG,CAAC,SAAS,kBAAkB,GAC1D,KAAK,GACL,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;CACtB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,UAAU,CAAC,MAAM,SAAS,YAAY,IAAI,QAAQ,CAC5D,cAAc,CACZ,WAAW,C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BAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAOjC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,cAAc,CAExE;AAED;;;;;;;GAOG;AACH,wBAAgB,sBAAsB,CACpC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,cAAc,CAOjC;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,OAAO,EACd,YAAY,CAAC,EAAE,yBAAyB,GACvC,OAAO,CAAC,KAAK,IAAI,YAAY,CAO/B;AAED,KAAK,uBAAuB,GAAG;IAC7B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,CAAC,EAAE,uBAAuB,GAChC,CAAC,EAAE,EAAE,OAAO,KAAK,EAAE,IAAI,SAAS,CAwBlC"}
|
package/dist/json.js
CHANGED
|
@@ -247,7 +247,10 @@ export const JsonRpcSuccessStruct = object({
|
|
|
247
247
|
export const JsonRpcFailureStruct = object({
|
|
248
248
|
id: JsonRpcIdStruct,
|
|
249
249
|
jsonrpc: JsonRpcVersionStruct,
|
|
250
|
-
//
|
|
250
|
+
// The assertion does not change assignability, but it does pin the emitted
|
|
251
|
+
// declaration to the named `JsonRpcError`. Without it TypeScript inlines the
|
|
252
|
+
// structure and leaks the unexported `ExactOptionalGuard` into the published
|
|
253
|
+
// types.
|
|
251
254
|
error: JsonRpcErrorStruct,
|
|
252
255
|
});
|
|
253
256
|
export const JsonRpcResponseStruct = union([
|
package/dist/json.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,KAAK,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,EAAE,EACF,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,IAAI,iBAAiB,EAC3B,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,GACP,MAAM,uBAAuB,CAAC;AAU/B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAmDxC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,MAAc,EACc,EAAE;AAC9B,0EAA0E;AAC1E,2EAA2E;AAC3E,2DAA2D;AAC3D,iBAAiB,CAAC,MAAM,CAA0C,CAAC;AAQrE;;;;;;;GAOG;AACH,SAAS,WAAW,CAAC,EAAE,IAAI,EAAE,MAAM,EAAW;IAC5C,MAAM,KAAK,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACpC,OAAO,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACvD,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,UAAU,aAAa,CAC3B,MAA4B;IAE5B,OAAO,IAAI,MAAM,CAAoC;QACnD,GAAG,MAAM;QAET,IAAI,EAAE,YAAY,MAAM,CAAC,IAAI,EAAE;QAC/B,SA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;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,EAAE,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;AACvC,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,oBAAoB,CAClC,KAAc,EACd,YAAwC;IAExC,YAAY,CACV,KAAK,EACL,kBAAkB,EAClB,wBAAwB,EACxB,YAAY,CACb,CAAC;AACJ,CAAC;AAQD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,UAAU,qBAAqB,CACnC,OAAiC;IAEjC,MAAM,EAAE,iBAAiB,EAAE,eAAe,EAAE,UAAU,EAAE,GAAG;QACzD,iBAAiB,EAAE,IAAI;QACvB,eAAe,EAAE,KAAK;QACtB,UAAU,EAAE,IAAI;QAChB,GAAG,OAAO;KACX,CAAC;IAEF;;;;;;OAMG;IACH,MAAM,gBAAgB,GAAG,CAAC,EAAW,EAAmB,EAAE;QACxD,OAAO,OAAO,CACZ,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,eAAe,IAAI,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;YACrE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,iBAAiB,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAChE,CAAC,UAAU,IAAI,EAAE,KAAK,IAAI,CAAC,CAC5B,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["import {\n any,\n array,\n coerce,\n create,\n define,\n integer,\n is,\n literal,\n nullable,\n number,\n object as superstructObject,\n optional,\n record,\n string,\n union,\n unknown,\n Struct,\n refine,\n} from '@metamask/superstruct';\nimport type {\n Context,\n Infer,\n ObjectSchema,\n Simplify,\n Optionalize,\n} from '@metamask/superstruct';\n\nimport type { AssertionErrorConstructor } from './assert.js';\nimport { assertStruct } from './assert.js';\nimport { hasProperty } from './misc.js';\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * A helper type to make properties with `undefined` in their type optional, but\n * not `undefined` itself.\n *\n * @deprecated Use `ObjectType` and/or `ExactOptionalize` from `@metamask/superstruct@>=3.2.0` instead.\n * @example\n * ```ts\n * type Foo = ObjectOptional<{ foo: string | undefined }>;\n * // Foo is equivalent to { foo?: string }\n * ```\n */\nexport type ObjectOptional<Schema extends Record<string, unknown>> = {\n [Key in keyof Schema as Schema[Key] extends ExactOptionalGuard\n ? Key\n : never]?: Schema[Key] extends ExactOptionalGuard & (infer Original)\n ? Original\n : never;\n} & {\n [Key in keyof Schema as Schema[Key] extends ExactOptionalGuard\n ? never\n : Key]: Schema[Key];\n};\n\n/**\n * An object type with support for exact optionals. This is used by the `object`\n * struct. This uses the {@link ObjectOptional} helper to make properties with\n * `undefined` in their type optional, but not `undefined` itself.\n *\n * @deprecated Use `ObjectType` from `@metamask/superstruct@>=3.2.0` instead.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ObjectOptional<\n Optionalize<{\n [Key in keyof Schema]: Infer<Schema[Key]>;\n }>\n >\n>;\n\n/**\n * A struct to check if the given value is a valid object, with support for\n * {@link exactOptional} types.\n *\n * @deprecated Use `exactOptional` and `object` from `@metamask/superstruct@>=3.2.0` instead.\n * @param schema - The schema of the object.\n * @returns A struct to check if the given value is an object.\n */\nexport const object = <Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>> =>\n // The type is slightly different from a regular object struct, because we\n // want to make properties with `undefined` in their type optional, but not\n // `undefined` itself. This means that we need a type cast.\n superstructObject(schema) as unknown as Struct<ObjectType<Schema>>;\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Branding symbol for the opaque guard type; used only via `typeof`.\ndeclare const exactOptionalSymbol: unique symbol;\ntype ExactOptionalGuard = {\n _exactOptionalGuard?: typeof exactOptionalSymbol;\n};\n\n/**\n * Check the last field of a path is present.\n *\n * @param context - The context to check.\n * @param context.path - The path to check.\n * @param context.branch - The branch to check.\n * @returns Whether the last field of a path is present.\n */\nfunction hasOptional({ path, branch }: Context): boolean {\n const field = path[path.length - 1];\n return hasProperty(branch[branch.length - 2], field);\n}\n\n/**\n * A struct which allows the property of an object to be absent, or to be present\n * as long as it's valid and not set to `undefined`.\n *\n * This struct should be used in conjunction with the {@link object} from this\n * library, to get proper type inference.\n *\n * @deprecated Use `exactOptional` and `object` from `@metamask/superstruct@>=3.2.0` instead.\n * @param struct - The struct to check the value against, if present.\n * @returns A struct to check if the given value is valid, or not present.\n * @example\n * ```ts\n * const struct = object({\n * foo: exactOptional(string()),\n * bar: exactOptional(number()),\n * baz: optional(boolean()),\n * qux: unknown(),\n * });\n *\n * type Type = Infer<typeof struct>;\n * // Type is equivalent to:\n * // {\n * // foo?: string;\n * // bar?: number;\n * // baz?: boolean | undefined;\n * // qux: unknown;\n * // }\n * ```\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type & ExactOptionalGuard, Schema> {\n return new Struct<Type & ExactOptionalGuard, Schema>({\n ...struct,\n\n type: `optional ${struct.type}`,\n validator: (value, context) =>\n !hasOptional(context) || struct.validator(value, context),\n\n refiner: (value, context) =>\n !hasOptional(context) || struct.refiner(value, context),\n });\n}\n\n/**\n * Validate an unknown input to be valid JSON.\n *\n * Useful for constructing JSON structs.\n *\n * @param json - An unknown value.\n * @returns True if the value is valid JSON, otherwise false.\n */\nfunction validateJson(json: unknown): boolean {\n if (json === null || typeof json === 'boolean' || typeof json === 'string') {\n return true;\n }\n\n if (typeof json === 'number' && Number.isFinite(json)) {\n return true;\n }\n\n if (typeof json === 'object') {\n let every = true;\n if (Array.isArray(json)) {\n // Ignoring linting error since for-of is significantly slower than a normal for-loop\n // and performance is important in this specific function.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < json.length; i++) {\n if (!validateJson(json[i])) {\n every = false;\n break;\n }\n }\n return every;\n }\n\n const entries = Object.entries(json);\n // Ignoring linting errors since for-of is significantly slower than a normal for-loop\n // and performance is important in this specific function.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < entries.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (typeof entries[i]![0] !== 'string' || !validateJson(entries[i]![1])) {\n every = false;\n break;\n }\n }\n return every;\n }\n\n return false;\n}\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.\n */\nexport const UnsafeJsonStruct: Struct<Json> = define('JSON', (json) =>\n validateJson(json),\n);\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * This struct sanitizes the value before validating it, so that it is safe to\n * use with untrusted input.\n */\nexport const JsonStruct = coerce(\n UnsafeJsonStruct,\n refine(any(), 'JSON', (value) => is(value, UnsafeJsonStruct)),\n (value) =>\n JSON.parse(\n JSON.stringify(value, (propKey, propValue) => {\n // Strip __proto__ and constructor properties to prevent prototype pollution.\n if (propKey === '__proto__' || propKey === 'constructor') {\n return undefined;\n }\n return propValue;\n }),\n ),\n);\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n try {\n getSafeJson(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate and return sanitized JSON.\n *\n * Note:\n * This function uses sanitized JsonStruct for validation\n * that applies stringify and then parse of a value provided\n * to ensure that there are no getters which can have side effects\n * that can cause security issues.\n *\n * @param value - JSON structure to be processed.\n * @returns Sanitized JSON structure.\n */\nexport function getSafeJson<Type extends Json = Json>(value: unknown): Type {\n return create(value, JsonStruct) as Type;\n}\n\n/**\n * Get the size of a JSON value in bytes. This also validates the value.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSize(value: unknown): number {\n assertStruct(value, JsonStruct, 'Invalid JSON value');\n\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer<typeof JsonRpcIdStruct>;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: exactOptional(JsonStruct),\n stack: exactOptional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record<string, unknown>,\n Key extends keyof Type,\n> = Omit<Type, Key> & Partial<Pick<Type, Key>>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer<typeof JsonRpcErrorStruct>,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json>, null> =\n union([record(string(), JsonStruct), array(JsonStruct)]);\n\nexport type JsonRpcParams = Json[] | Record<string, Json>;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: exactOptional(JsonRpcParamsStruct),\n});\n\nexport type InferWithParams<\n Type extends Struct<any>,\n Params extends JsonRpcParams,\n> = Infer<Type> & {\n params?: Params;\n};\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcRequestStruct, Params>;\n\nexport const JsonRpcNotificationStruct = object({\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: exactOptional(JsonRpcParamsStruct),\n});\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcNotificationStruct, Params>;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = superstructObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse<Result extends Json = Json> = Omit<\n Infer<typeof PendingJsonRpcResponseStruct>,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess<Result extends Json = Json> = Omit<\n Infer<typeof JsonRpcSuccessStruct>,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- The assertion does not change assignability, but it does pin the emitted declaration to the named `JsonRpcError`. Without it TypeScript inlines the structure and leaks the unexported `ExactOptionalGuard` into the published types.\n error: JsonRpcErrorStruct as Struct<JsonRpcError>,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer<typeof JsonRpcFailureStruct>;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse<Result extends Json = Json> =\n | JsonRpcSuccess<Result>\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(value: unknown): value is JsonRpcSuccess {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(\n options?: JsonRpcValidatorOptions,\n): (id: unknown) => id is JsonRpcId {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJsonRpcId;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"json.js","sourceRoot":"","sources":["../src/json.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,KAAK,EACL,MAAM,EACN,MAAM,EACN,MAAM,EACN,OAAO,EACP,EAAE,EACF,OAAO,EACP,QAAQ,EACR,MAAM,EACN,MAAM,IAAI,iBAAiB,EAC3B,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,OAAO,EACP,MAAM,EACN,MAAM,GACP,MAAM,uBAAuB,CAAC;AAU/B,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAmDxC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,CACpB,MAAc,EACc,EAAE;AAC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I,MAAM,CAAC,SAAS,CAAC,EAAE,CAAC,CAAC,CAAC;YACrE,CAAC,OAAO,EAAE,KAAK,QAAQ,IAAI,CAAC,iBAAiB,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAChE,CAAC,UAAU,IAAI,EAAE,KAAK,IAAI,CAAC,CAC5B,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC","sourcesContent":["import {\n any,\n array,\n coerce,\n create,\n define,\n integer,\n is,\n literal,\n nullable,\n number,\n object as superstructObject,\n optional,\n record,\n string,\n union,\n unknown,\n Struct,\n refine,\n} from '@metamask/superstruct';\nimport type {\n Context,\n Infer,\n ObjectSchema,\n Simplify,\n Optionalize,\n} from '@metamask/superstruct';\n\nimport type { AssertionErrorConstructor } from './assert.js';\nimport { assertStruct } from './assert.js';\nimport { hasProperty } from './misc.js';\n\n/**\n * Any JSON-compatible value.\n */\nexport type Json =\n | null\n | boolean\n | number\n | string\n | Json[]\n | { [prop: string]: Json };\n\n/**\n * A helper type to make properties with `undefined` in their type optional, but\n * not `undefined` itself.\n *\n * @deprecated Use `ObjectType` and/or `ExactOptionalize` from `@metamask/superstruct@>=3.2.0` instead.\n * @example\n * ```ts\n * type Foo = ObjectOptional<{ foo: string | undefined }>;\n * // Foo is equivalent to { foo?: string }\n * ```\n */\nexport type ObjectOptional<Schema extends Record<string, unknown>> = {\n [Key in keyof Schema as Schema[Key] extends ExactOptionalGuard\n ? Key\n : never]?: Schema[Key] extends ExactOptionalGuard & (infer Original)\n ? Original\n : never;\n} & {\n [Key in keyof Schema as Schema[Key] extends ExactOptionalGuard\n ? never\n : Key]: Schema[Key];\n};\n\n/**\n * An object type with support for exact optionals. This is used by the `object`\n * struct. This uses the {@link ObjectOptional} helper to make properties with\n * `undefined` in their type optional, but not `undefined` itself.\n *\n * @deprecated Use `ObjectType` from `@metamask/superstruct@>=3.2.0` instead.\n */\nexport type ObjectType<Schema extends ObjectSchema> = Simplify<\n ObjectOptional<\n Optionalize<{\n [Key in keyof Schema]: Infer<Schema[Key]>;\n }>\n >\n>;\n\n/**\n * A struct to check if the given value is a valid object, with support for\n * {@link exactOptional} types.\n *\n * @deprecated Use `exactOptional` and `object` from `@metamask/superstruct@>=3.2.0` instead.\n * @param schema - The schema of the object.\n * @returns A struct to check if the given value is an object.\n */\nexport const object = <Schema extends ObjectSchema>(\n schema: Schema,\n): Struct<ObjectType<Schema>> =>\n // The type is slightly different from a regular object struct, because we\n // want to make properties with `undefined` in their type optional, but not\n // `undefined` itself. This means that we need a type cast.\n superstructObject(schema) as unknown as Struct<ObjectType<Schema>>;\n\n// eslint-disable-next-line @typescript-eslint/no-unused-vars -- Branding symbol for the opaque guard type; used only via `typeof`.\ndeclare const exactOptionalSymbol: unique symbol;\ntype ExactOptionalGuard = {\n _exactOptionalGuard?: typeof exactOptionalSymbol;\n};\n\n/**\n * Check the last field of a path is present.\n *\n * @param context - The context to check.\n * @param context.path - The path to check.\n * @param context.branch - The branch to check.\n * @returns Whether the last field of a path is present.\n */\nfunction hasOptional({ path, branch }: Context): boolean {\n const field = path[path.length - 1];\n return hasProperty(branch[branch.length - 2], field);\n}\n\n/**\n * A struct which allows the property of an object to be absent, or to be present\n * as long as it's valid and not set to `undefined`.\n *\n * This struct should be used in conjunction with the {@link object} from this\n * library, to get proper type inference.\n *\n * @deprecated Use `exactOptional` and `object` from `@metamask/superstruct@>=3.2.0` instead.\n * @param struct - The struct to check the value against, if present.\n * @returns A struct to check if the given value is valid, or not present.\n * @example\n * ```ts\n * const struct = object({\n * foo: exactOptional(string()),\n * bar: exactOptional(number()),\n * baz: optional(boolean()),\n * qux: unknown(),\n * });\n *\n * type Type = Infer<typeof struct>;\n * // Type is equivalent to:\n * // {\n * // foo?: string;\n * // bar?: number;\n * // baz?: boolean | undefined;\n * // qux: unknown;\n * // }\n * ```\n */\nexport function exactOptional<Type, Schema>(\n struct: Struct<Type, Schema>,\n): Struct<Type & ExactOptionalGuard, Schema> {\n return new Struct<Type & ExactOptionalGuard, Schema>({\n ...struct,\n\n type: `optional ${struct.type}`,\n validator: (value, context) =>\n !hasOptional(context) || struct.validator(value, context),\n\n refiner: (value, context) =>\n !hasOptional(context) || struct.refiner(value, context),\n });\n}\n\n/**\n * Validate an unknown input to be valid JSON.\n *\n * Useful for constructing JSON structs.\n *\n * @param json - An unknown value.\n * @returns True if the value is valid JSON, otherwise false.\n */\nfunction validateJson(json: unknown): boolean {\n if (json === null || typeof json === 'boolean' || typeof json === 'string') {\n return true;\n }\n\n if (typeof json === 'number' && Number.isFinite(json)) {\n return true;\n }\n\n if (typeof json === 'object') {\n let every = true;\n if (Array.isArray(json)) {\n // Ignoring linting error since for-of is significantly slower than a normal for-loop\n // and performance is important in this specific function.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < json.length; i++) {\n if (!validateJson(json[i])) {\n every = false;\n break;\n }\n }\n return every;\n }\n\n const entries = Object.entries(json);\n // Ignoring linting errors since for-of is significantly slower than a normal for-loop\n // and performance is important in this specific function.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < entries.length; i++) {\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n if (typeof entries[i]![0] !== 'string' || !validateJson(entries[i]![1])) {\n every = false;\n break;\n }\n }\n return every;\n }\n\n return false;\n}\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * Note that this struct is unsafe. For safe validation, use {@link JsonStruct}.\n */\nexport const UnsafeJsonStruct: Struct<Json> = define('JSON', (json) =>\n validateJson(json),\n);\n\n/**\n * A struct to check if the given value is a valid JSON-serializable value.\n *\n * This struct sanitizes the value before validating it, so that it is safe to\n * use with untrusted input.\n */\nexport const JsonStruct = coerce(\n UnsafeJsonStruct,\n refine(any(), 'JSON', (value) => is(value, UnsafeJsonStruct)),\n (value) =>\n JSON.parse(\n JSON.stringify(value, (propKey, propValue) => {\n // Strip __proto__ and constructor properties to prevent prototype pollution.\n if (propKey === '__proto__' || propKey === 'constructor') {\n return undefined;\n }\n return propValue;\n }),\n ),\n);\n\n/**\n * Check if the given value is a valid {@link Json} value, i.e., a value that is\n * serializable to JSON.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link Json} value.\n */\nexport function isValidJson(value: unknown): value is Json {\n try {\n getSafeJson(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/**\n * Validate and return sanitized JSON.\n *\n * Note:\n * This function uses sanitized JsonStruct for validation\n * that applies stringify and then parse of a value provided\n * to ensure that there are no getters which can have side effects\n * that can cause security issues.\n *\n * @param value - JSON structure to be processed.\n * @returns Sanitized JSON structure.\n */\nexport function getSafeJson<Type extends Json = Json>(value: unknown): Type {\n return create(value, JsonStruct) as Type;\n}\n\n/**\n * Get the size of a JSON value in bytes. This also validates the value.\n *\n * @param value - The JSON value to get the size of.\n * @returns The size of the JSON value in bytes.\n */\nexport function getJsonSize(value: unknown): number {\n assertStruct(value, JsonStruct, 'Invalid JSON value');\n\n const json = JSON.stringify(value);\n return new TextEncoder().encode(json).byteLength;\n}\n\n/**\n * The string '2.0'.\n */\nexport const jsonrpc2 = '2.0' as const;\nexport const JsonRpcVersionStruct = literal(jsonrpc2);\n\n/**\n * A String specifying the version of the JSON-RPC protocol.\n * MUST be exactly \"2.0\".\n */\nexport type JsonRpcVersion2 = typeof jsonrpc2;\n\nexport const JsonRpcIdStruct = nullable(union([number(), string()]));\n\n/**\n * An identifier established by the Client that MUST contain a String, Number,\n * or NULL value if included. If it is not included it is assumed to be a\n * notification. The value SHOULD normally not be Null and Numbers SHOULD\n * NOT contain fractional parts.\n */\nexport type JsonRpcId = Infer<typeof JsonRpcIdStruct>;\n\nexport const JsonRpcErrorStruct = object({\n code: integer(),\n message: string(),\n data: exactOptional(JsonStruct),\n stack: exactOptional(string()),\n});\n\n/**\n * Mark a certain key of a type as optional.\n */\nexport type OptionalField<\n Type extends Record<string, unknown>,\n Key extends keyof Type,\n> = Omit<Type, Key> & Partial<Pick<Type, Key>>;\n\n/**\n * A JSON-RPC error object.\n *\n * Note that TypeScript infers `unknown | undefined` as `unknown`, meaning that\n * the `data` field is not optional. To make it optional, we use the\n * `OptionalField` helper, to explicitly make it optional.\n */\nexport type JsonRpcError = OptionalField<\n Infer<typeof JsonRpcErrorStruct>,\n 'data'\n>;\n\nexport const JsonRpcParamsStruct: Struct<Json[] | Record<string, Json>, null> =\n union([record(string(), JsonStruct), array(JsonStruct)]);\n\nexport type JsonRpcParams = Json[] | Record<string, Json>;\n\nexport const JsonRpcRequestStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: exactOptional(JsonRpcParamsStruct),\n});\n\nexport type InferWithParams<\n Type extends Struct<any>,\n Params extends JsonRpcParams,\n> = Infer<Type> & {\n params?: Params;\n};\n\n/**\n * A JSON-RPC request object.\n */\nexport type JsonRpcRequest<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcRequestStruct, Params>;\n\nexport const JsonRpcNotificationStruct = object({\n jsonrpc: JsonRpcVersionStruct,\n method: string(),\n params: exactOptional(JsonRpcParamsStruct),\n});\n\n/**\n * A JSON-RPC notification object.\n */\nexport type JsonRpcNotification<Params extends JsonRpcParams = JsonRpcParams> =\n InferWithParams<typeof JsonRpcNotificationStruct, Params>;\n\n/**\n * Check if the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcNotification}\n * object.\n */\nexport function isJsonRpcNotification(\n value: unknown,\n): value is JsonRpcNotification {\n return is(value, JsonRpcNotificationStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcNotification} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcNotification} object.\n */\nexport function assertIsJsonRpcNotification(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcNotification {\n assertStruct(\n value,\n JsonRpcNotificationStruct,\n 'Invalid JSON-RPC notification',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcRequest} object.\n */\nexport function isJsonRpcRequest(value: unknown): value is JsonRpcRequest {\n return is(value, JsonRpcRequestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcRequest} object.\n *\n * @param value - The JSON-RPC request or notification to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcRequest} object.\n */\nexport function assertIsJsonRpcRequest(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcRequest {\n assertStruct(\n value,\n JsonRpcRequestStruct,\n 'Invalid JSON-RPC request',\n ErrorWrapper,\n );\n}\n\nexport const PendingJsonRpcResponseStruct = superstructObject({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: optional(unknown()),\n error: optional(JsonRpcErrorStruct),\n});\n\n/**\n * A JSON-RPC response object that has not yet been resolved.\n */\nexport type PendingJsonRpcResponse<Result extends Json = Json> = Omit<\n Infer<typeof PendingJsonRpcResponseStruct>,\n 'result'\n> & {\n result?: Result;\n};\n\nexport const JsonRpcSuccessStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n result: JsonStruct,\n});\n\n/**\n * A successful JSON-RPC response object.\n */\nexport type JsonRpcSuccess<Result extends Json = Json> = Omit<\n Infer<typeof JsonRpcSuccessStruct>,\n 'result'\n> & {\n result: Result;\n};\n\nexport const JsonRpcFailureStruct = object({\n id: JsonRpcIdStruct,\n jsonrpc: JsonRpcVersionStruct,\n // The assertion does not change assignability, but it does pin the emitted\n // declaration to the named `JsonRpcError`. Without it TypeScript inlines the\n // structure and leaks the unexported `ExactOptionalGuard` into the published\n // types.\n error: JsonRpcErrorStruct as Struct<JsonRpcError>,\n});\n\n/**\n * A failed JSON-RPC response object.\n */\nexport type JsonRpcFailure = Infer<typeof JsonRpcFailureStruct>;\n\nexport const JsonRpcResponseStruct = union([\n JsonRpcSuccessStruct,\n JsonRpcFailureStruct,\n]);\n\n/**\n * A JSON-RPC response object. Must be checked to determine whether it's a\n * success or failure.\n *\n * @template Result - The type of the result.\n */\nexport type JsonRpcResponse<Result extends Json = Json> =\n | JsonRpcSuccess<Result>\n | JsonRpcFailure;\n\n/**\n * Type guard to check whether specified JSON-RPC response is a\n * {@link PendingJsonRpcResponse}.\n *\n * @param response - The JSON-RPC response to check.\n * @returns Whether the specified JSON-RPC response is pending.\n */\nexport function isPendingJsonRpcResponse(\n response: unknown,\n): response is PendingJsonRpcResponse {\n return is(response, PendingJsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link PendingJsonRpcResponse} object.\n *\n * @param response - The JSON-RPC response to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link PendingJsonRpcResponse}\n * object.\n */\nexport function assertIsPendingJsonRpcResponse(\n response: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts response is PendingJsonRpcResponse {\n assertStruct(\n response,\n PendingJsonRpcResponseStruct,\n 'Invalid pending JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Type guard to check if a value is a {@link JsonRpcResponse}.\n *\n * @param response - The object to check.\n * @returns Whether the object is a JsonRpcResponse.\n */\nexport function isJsonRpcResponse(\n response: unknown,\n): response is JsonRpcResponse {\n return is(response, JsonRpcResponseStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcResponse} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcResponse} object.\n */\nexport function assertIsJsonRpcResponse(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcResponse {\n assertStruct(\n value,\n JsonRpcResponseStruct,\n 'Invalid JSON-RPC response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcSuccess} object.\n */\nexport function isJsonRpcSuccess(value: unknown): value is JsonRpcSuccess {\n return is(value, JsonRpcSuccessStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcSuccess} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcSuccess} object.\n */\nexport function assertIsJsonRpcSuccess(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcSuccess {\n assertStruct(\n value,\n JsonRpcSuccessStruct,\n 'Invalid JSON-RPC success response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcFailure} object.\n */\nexport function isJsonRpcFailure(value: unknown): value is JsonRpcFailure {\n return is(value, JsonRpcFailureStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcFailure} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcFailure} object.\n */\nexport function assertIsJsonRpcFailure(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcFailure {\n assertStruct(\n value,\n JsonRpcFailureStruct,\n 'Invalid JSON-RPC failure response',\n ErrorWrapper,\n );\n}\n\n/**\n * Check if the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @returns Whether the given value is a valid {@link JsonRpcError} object.\n */\nexport function isJsonRpcError(value: unknown): value is JsonRpcError {\n return is(value, JsonRpcErrorStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link JsonRpcError} object.\n *\n * @param value - The value to check.\n * @param ErrorWrapper - The error class to throw if the assertion fails.\n * Defaults to {@link AssertionError}.\n * @throws If the given value is not a valid {@link JsonRpcError} object.\n */\nexport function assertIsJsonRpcError(\n value: unknown,\n ErrorWrapper?: AssertionErrorConstructor,\n): asserts value is JsonRpcError {\n assertStruct(\n value,\n JsonRpcErrorStruct,\n 'Invalid JSON-RPC error',\n ErrorWrapper,\n );\n}\n\ntype JsonRpcValidatorOptions = {\n permitEmptyString?: boolean;\n permitFractions?: boolean;\n permitNull?: boolean;\n};\n\n/**\n * Gets a function for validating JSON-RPC request / response `id` values.\n *\n * By manipulating the options of this factory, you can control the behavior\n * of the resulting validator for some edge cases. This is useful because e.g.\n * `null` should sometimes but not always be permitted.\n *\n * Note that the empty string (`''`) is always permitted by the JSON-RPC\n * specification, but that kind of sucks and you may want to forbid it in some\n * instances anyway.\n *\n * For more details, see the\n * [JSON-RPC Specification](https://www.jsonrpc.org/specification).\n *\n * @param options - An options object.\n * @param options.permitEmptyString - Whether the empty string (i.e. `''`)\n * should be treated as a valid ID. Default: `true`\n * @param options.permitFractions - Whether fractional numbers (e.g. `1.2`)\n * should be treated as valid IDs. Default: `false`\n * @param options.permitNull - Whether `null` should be treated as a valid ID.\n * Default: `true`\n * @returns The JSON-RPC ID validator function.\n */\nexport function getJsonRpcIdValidator(\n options?: JsonRpcValidatorOptions,\n): (id: unknown) => id is JsonRpcId {\n const { permitEmptyString, permitFractions, permitNull } = {\n permitEmptyString: true,\n permitFractions: false,\n permitNull: true,\n ...options,\n };\n\n /**\n * Type guard for {@link JsonRpcId}.\n *\n * @param id - The JSON-RPC ID value to check.\n * @returns Whether the given ID is valid per the options given to the\n * factory.\n */\n const isValidJsonRpcId = (id: unknown): id is JsonRpcId => {\n return Boolean(\n (typeof id === 'number' && (permitFractions || Number.isInteger(id))) ||\n (typeof id === 'string' && (permitEmptyString || id.length > 0)) ||\n (permitNull && id === null),\n );\n };\n\n return isValidJsonRpcId;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,22 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/utils",
|
|
3
|
-
"version": "12.0.0-preview-
|
|
3
|
+
"version": "12.0.0-preview-e81860e6b",
|
|
4
4
|
"description": "Various JavaScript/TypeScript utilities of wide relevance to the MetaMask codebase",
|
|
5
|
-
"
|
|
5
|
+
"keywords": [
|
|
6
|
+
"Ethereum",
|
|
7
|
+
"MetaMask"
|
|
8
|
+
],
|
|
9
|
+
"homepage": "https://github.com/MetaMask/core/tree/main/packages/utils#readme",
|
|
6
10
|
"bugs": {
|
|
7
|
-
"url": "https://github.com/MetaMask/
|
|
11
|
+
"url": "https://github.com/MetaMask/core/issues"
|
|
8
12
|
},
|
|
9
13
|
"license": "ISC",
|
|
10
14
|
"repository": {
|
|
11
15
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/MetaMask/
|
|
16
|
+
"url": "https://github.com/MetaMask/core.git"
|
|
13
17
|
},
|
|
14
18
|
"files": [
|
|
15
|
-
"dist"
|
|
19
|
+
"dist",
|
|
20
|
+
"dist/"
|
|
16
21
|
],
|
|
17
22
|
"type": "module",
|
|
18
23
|
"sideEffects": false,
|
|
19
|
-
"types": "./dist/index.d.ts",
|
|
20
24
|
"exports": {
|
|
21
25
|
".": {
|
|
22
26
|
"types": "./dist/index.d.ts",
|
|
@@ -34,22 +38,23 @@
|
|
|
34
38
|
},
|
|
35
39
|
"scripts": {
|
|
36
40
|
"build": "tsc --project tsconfig.build.json",
|
|
41
|
+
"build:all": "tsc --build tsconfig.build.json --verbose",
|
|
37
42
|
"build:clean": "yarn build:only-clean && yarn build",
|
|
38
43
|
"build:docs": "typedoc",
|
|
39
|
-
"build:only-clean": "rimraf ./dist ./tsconfig.build.tsbuildinfo",
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"lint:
|
|
43
|
-
"lint:
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"test": "
|
|
50
|
-
"test:
|
|
51
|
-
"test:
|
|
52
|
-
"test:watch": "jest --watch"
|
|
44
|
+
"build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
|
|
45
|
+
"changelog:update": "../../scripts/update-changelog.sh @metamask/utils",
|
|
46
|
+
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/utils",
|
|
47
|
+
"lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
|
|
48
|
+
"lint:tsconfigs:fix": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts --fix",
|
|
49
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
50
|
+
"test": "yarn test:unit && yarn test:types",
|
|
51
|
+
"test:clean": "yarn test:unit:clean && yarn test:types",
|
|
52
|
+
"test:types": "tstyche",
|
|
53
|
+
"test:unit": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
54
|
+
"test:unit:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
55
|
+
"test:unit:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
56
|
+
"test:verbose": "yarn test:unit:verbose && yarn test:types",
|
|
57
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
53
58
|
},
|
|
54
59
|
"dependencies": {
|
|
55
60
|
"@ethereumjs/tx": "^5.4.0",
|
|
@@ -66,53 +71,27 @@
|
|
|
66
71
|
"uuid": "^9.0.1"
|
|
67
72
|
},
|
|
68
73
|
"devDependencies": {
|
|
69
|
-
"@lavamoat/allow-scripts": "^3.0.4",
|
|
70
|
-
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
71
74
|
"@metamask/auto-changelog": "^6.1.0",
|
|
72
|
-
"@metamask/eslint-config": "^15.0.0",
|
|
73
|
-
"@metamask/eslint-config-jest": "^15.0.0",
|
|
74
|
-
"@metamask/eslint-config-nodejs": "^15.0.0",
|
|
75
|
-
"@metamask/eslint-config-typescript": "^15.0.0",
|
|
76
75
|
"@types/jest": "^30.0.0",
|
|
77
76
|
"@types/jest-when": "^3.5.3",
|
|
78
|
-
"@types/node": "^22.13.14",
|
|
79
|
-
"@types/semver": "^7",
|
|
80
77
|
"@types/uuid": "^9.0.8",
|
|
81
78
|
"@typescript/native": "npm:typescript@^7.0.2",
|
|
82
|
-
"
|
|
83
|
-
"eslint-config-prettier": "^9.1.0",
|
|
84
|
-
"eslint-import-resolver-typescript": "^3.6.3",
|
|
85
|
-
"eslint-plugin-import-x": "^4.3.0",
|
|
86
|
-
"eslint-plugin-jest": "^28.8.3",
|
|
87
|
-
"eslint-plugin-jsdoc": "^50.2.4",
|
|
88
|
-
"eslint-plugin-n": "^17.10.3",
|
|
89
|
-
"eslint-plugin-prettier": "^5.2.1",
|
|
90
|
-
"eslint-plugin-promise": "^7.1.0",
|
|
79
|
+
"deepmerge": "^4.2.2",
|
|
91
80
|
"jest": "^30.4.2",
|
|
92
|
-
"jest-it-up": "^2.0.2",
|
|
93
81
|
"jest-when": "^3.7.0",
|
|
94
|
-
"knip": "^6.23.0",
|
|
95
|
-
"oxfmt": "^0.44.0",
|
|
96
|
-
"prettier": "^3.3.3",
|
|
97
82
|
"rimraf": "^5.0.5",
|
|
98
83
|
"stdio-mock": "^1.2.0",
|
|
99
84
|
"ts-jest": "^29.4.11",
|
|
100
|
-
"
|
|
85
|
+
"tstyche": "^7.2.3",
|
|
86
|
+
"tsx": "^4.20.5",
|
|
101
87
|
"typedoc": "^0.25.13",
|
|
88
|
+
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
102
89
|
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
103
|
-
"typescript-eslint": "^8.48.0",
|
|
104
90
|
"web3": "^4.16.0"
|
|
105
91
|
},
|
|
106
|
-
"resolutions": {
|
|
107
|
-
"jest-worker@^28.1.3": "patch:jest-worker@npm%3A28.1.3#./.yarn/patches/jest-worker-npm-28.1.3-5d0ff9006c.patch"
|
|
108
|
-
},
|
|
109
|
-
"tsd": {
|
|
110
|
-
"directory": "src"
|
|
111
|
-
},
|
|
112
92
|
"engines": {
|
|
113
93
|
"node": "^22.14.0 || ^24"
|
|
114
94
|
},
|
|
115
|
-
"packageManager": "yarn@4.17.1+sha256.471ffb15e0523663865bbf46a69e7d157ecf532412eb436c48dfab6e3f2abe88",
|
|
116
95
|
"lavamoat": {
|
|
117
96
|
"allowScripts": {
|
|
118
97
|
"@lavamoat/preinstall-always-fail": false,
|