@metamask/snaps-utils 0.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +15 -0
- package/README.md +3 -0
- package/dist/caveats.d.ts +22 -0
- package/dist/caveats.js +27 -0
- package/dist/caveats.js.map +1 -0
- package/dist/cronjob.d.ts +89 -0
- package/dist/cronjob.js +74 -0
- package/dist/cronjob.js.map +1 -0
- package/dist/deep-clone.d.ts +1 -0
- package/dist/deep-clone.js +9 -0
- package/dist/deep-clone.js.map +1 -0
- package/dist/default-endowments.d.ts +4 -0
- package/dist/default-endowments.js +43 -0
- package/dist/default-endowments.js.map +1 -0
- package/dist/eval-worker.d.ts +1 -0
- package/dist/eval-worker.js +32 -0
- package/dist/eval-worker.js.map +1 -0
- package/dist/eval.d.ts +8 -0
- package/dist/eval.js +28 -0
- package/dist/eval.js.map +1 -0
- package/dist/flatMap.d.ts +22 -0
- package/dist/flatMap.js +38 -0
- package/dist/flatMap.js.map +1 -0
- package/dist/fs.d.ts +69 -0
- package/dist/fs.js +144 -0
- package/dist/fs.js.map +1 -0
- package/dist/index.browser.d.ts +13 -0
- package/dist/index.browser.js +30 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/json-rpc.d.ts +10 -0
- package/dist/json-rpc.js +22 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/manifest/index.browser.d.ts +1 -0
- package/dist/manifest/index.browser.js +18 -0
- package/dist/manifest/index.browser.js.map +1 -0
- package/dist/manifest/index.d.ts +2 -0
- package/dist/manifest/index.js +19 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/manifest/manifest.d.ts +75 -0
- package/dist/manifest/manifest.js +237 -0
- package/dist/manifest/manifest.js.map +1 -0
- package/dist/manifest/validation.d.ts +483 -0
- package/dist/manifest/validation.js +142 -0
- package/dist/manifest/validation.js.map +1 -0
- package/dist/mock.d.ts +14 -0
- package/dist/mock.js +107 -0
- package/dist/mock.js.map +1 -0
- package/dist/namespace.d.ts +275 -0
- package/dist/namespace.js +223 -0
- package/dist/namespace.js.map +1 -0
- package/dist/notification.d.ts +66 -0
- package/dist/notification.js +58 -0
- package/dist/notification.js.map +1 -0
- package/dist/npm.d.ts +20 -0
- package/dist/npm.js +73 -0
- package/dist/npm.js.map +1 -0
- package/dist/object.d.ts +8 -0
- package/dist/object.js +15 -0
- package/dist/object.js.map +1 -0
- package/dist/post-process.d.ts +71 -0
- package/dist/post-process.js +321 -0
- package/dist/post-process.js.map +1 -0
- package/dist/snaps.d.ts +165 -0
- package/dist/snaps.js +123 -0
- package/dist/snaps.js.map +1 -0
- package/dist/types.d.ts +107 -0
- package/dist/types.js +82 -0
- package/dist/types.js.map +1 -0
- package/dist/url.d.ts +7 -0
- package/dist/url.js +19 -0
- package/dist/url.js.map +1 -0
- package/dist/versions.d.ts +44 -0
- package/dist/versions.js +77 -0
- package/dist/versions.js.map +1 -0
- package/package.json +100 -0
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
import { Infer, Struct } from 'superstruct';
|
|
2
|
+
export declare const SIP_6_MAGIC_VALUE: `${number}'`;
|
|
3
|
+
export declare type Base64Opts = {
|
|
4
|
+
/**
|
|
5
|
+
* Is the `=` padding at the end required or not.
|
|
6
|
+
*
|
|
7
|
+
* @default false
|
|
8
|
+
*/
|
|
9
|
+
paddingRequired?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Which character set should be used.
|
|
12
|
+
* The sets are based on {@link https://datatracker.ietf.org/doc/html/rfc4648 RFC 4648}.
|
|
13
|
+
*
|
|
14
|
+
* @default 'base64'
|
|
15
|
+
*/
|
|
16
|
+
characterSet?: 'base64' | 'base64url';
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Ensure that a provided string-based struct is valid base64.
|
|
20
|
+
*
|
|
21
|
+
* @param struct - The string based struct.
|
|
22
|
+
* @param opts - Optional options to specialize base64 validation. See {@link Base64Opts} documentation.
|
|
23
|
+
* @returns A superstruct validating base64.
|
|
24
|
+
*/
|
|
25
|
+
export declare const base64: <T extends string, S>(struct: Struct<T, S>, opts?: Base64Opts) => Struct<T, S>;
|
|
26
|
+
export declare const Bip32PathStruct: Struct<string[], Struct<string, null>>;
|
|
27
|
+
export declare const Bip32EntropyStruct: Struct<{
|
|
28
|
+
path: string[];
|
|
29
|
+
curve: "ed25519" | "secp256k1";
|
|
30
|
+
}, {
|
|
31
|
+
path: Struct<string[], Struct<string, null>>;
|
|
32
|
+
curve: Struct<"ed25519" | "secp256k1", {
|
|
33
|
+
ed25519: "ed25519";
|
|
34
|
+
secp256k1: "secp256k1";
|
|
35
|
+
}>;
|
|
36
|
+
}>;
|
|
37
|
+
export declare type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;
|
|
38
|
+
export declare const Bip32PublicKeyStruct: Struct<{
|
|
39
|
+
path: string[];
|
|
40
|
+
curve: "secp256k1" | "ed225519";
|
|
41
|
+
compressed?: boolean | undefined;
|
|
42
|
+
}, {
|
|
43
|
+
path: Struct<string[], Struct<string, null>>;
|
|
44
|
+
curve: Struct<"secp256k1" | "ed225519", {
|
|
45
|
+
secp256k1: "secp256k1";
|
|
46
|
+
ed225519: "ed225519";
|
|
47
|
+
}>;
|
|
48
|
+
compressed: Struct<boolean | undefined, null>;
|
|
49
|
+
}>;
|
|
50
|
+
export declare type Bip32PublicKey = Infer<typeof Bip32PublicKeyStruct>;
|
|
51
|
+
declare const PermissionsStruct: Struct<{
|
|
52
|
+
'endowment:long-running'?: {} | undefined;
|
|
53
|
+
'endowment:network-access'?: {} | undefined;
|
|
54
|
+
'endowment:transaction-insight'?: {
|
|
55
|
+
allowTransactionOrigin?: boolean | undefined;
|
|
56
|
+
} | undefined;
|
|
57
|
+
'endowment:cronjob'?: {
|
|
58
|
+
jobs: {
|
|
59
|
+
expression: string;
|
|
60
|
+
request: {
|
|
61
|
+
method: string;
|
|
62
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
63
|
+
id?: string | number | null | undefined;
|
|
64
|
+
jsonrpc?: "2.0" | undefined;
|
|
65
|
+
};
|
|
66
|
+
}[];
|
|
67
|
+
} | undefined;
|
|
68
|
+
snap_confirm?: {} | undefined;
|
|
69
|
+
snap_manageState?: {} | undefined;
|
|
70
|
+
snap_notify?: {} | undefined;
|
|
71
|
+
snap_getBip32Entropy?: {
|
|
72
|
+
path: string[];
|
|
73
|
+
curve: "ed25519" | "secp256k1";
|
|
74
|
+
}[] | undefined;
|
|
75
|
+
snap_getBip32PublicKey?: {
|
|
76
|
+
path: string[];
|
|
77
|
+
curve: "secp256k1" | "ed225519";
|
|
78
|
+
compressed?: boolean | undefined;
|
|
79
|
+
}[] | undefined;
|
|
80
|
+
snap_getBip44Entropy?: {
|
|
81
|
+
coinType: number;
|
|
82
|
+
}[] | undefined;
|
|
83
|
+
snap_getEntropy?: {} | undefined;
|
|
84
|
+
'endowment:keyring'?: {
|
|
85
|
+
namespaces: Record<string, {
|
|
86
|
+
chains: {
|
|
87
|
+
name: string;
|
|
88
|
+
id: string;
|
|
89
|
+
}[];
|
|
90
|
+
methods?: string[] | undefined;
|
|
91
|
+
events?: string[] | undefined;
|
|
92
|
+
}>;
|
|
93
|
+
} | undefined;
|
|
94
|
+
}, {
|
|
95
|
+
'endowment:long-running': Struct<{} | undefined, {}>;
|
|
96
|
+
'endowment:network-access': Struct<{} | undefined, {}>;
|
|
97
|
+
'endowment:transaction-insight': Struct<{
|
|
98
|
+
allowTransactionOrigin?: boolean | undefined;
|
|
99
|
+
} | undefined, {
|
|
100
|
+
allowTransactionOrigin: Struct<boolean | undefined, null>;
|
|
101
|
+
}>;
|
|
102
|
+
'endowment:cronjob': Struct<{
|
|
103
|
+
jobs: {
|
|
104
|
+
expression: string;
|
|
105
|
+
request: {
|
|
106
|
+
method: string;
|
|
107
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
108
|
+
id?: string | number | null | undefined;
|
|
109
|
+
jsonrpc?: "2.0" | undefined;
|
|
110
|
+
};
|
|
111
|
+
}[];
|
|
112
|
+
} | undefined, {
|
|
113
|
+
jobs: Struct<{
|
|
114
|
+
expression: string;
|
|
115
|
+
request: {
|
|
116
|
+
method: string;
|
|
117
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
118
|
+
id?: string | number | null | undefined;
|
|
119
|
+
jsonrpc?: "2.0" | undefined;
|
|
120
|
+
};
|
|
121
|
+
}[], Struct<{
|
|
122
|
+
expression: string;
|
|
123
|
+
request: {
|
|
124
|
+
method: string;
|
|
125
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
126
|
+
id?: string | number | null | undefined;
|
|
127
|
+
jsonrpc?: "2.0" | undefined;
|
|
128
|
+
};
|
|
129
|
+
}, {
|
|
130
|
+
expression: Struct<string, null>;
|
|
131
|
+
request: Struct<{
|
|
132
|
+
method: string;
|
|
133
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
134
|
+
id?: string | number | null | undefined;
|
|
135
|
+
jsonrpc?: "2.0" | undefined;
|
|
136
|
+
}, {
|
|
137
|
+
params: Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
|
|
138
|
+
method: Struct<string, null>;
|
|
139
|
+
id: Struct<string | number | null | undefined, unknown>;
|
|
140
|
+
jsonrpc: Struct<"2.0" | undefined, unknown>;
|
|
141
|
+
}>;
|
|
142
|
+
}>>;
|
|
143
|
+
}>;
|
|
144
|
+
snap_confirm: Struct<{} | undefined, {}>;
|
|
145
|
+
snap_manageState: Struct<{} | undefined, {}>;
|
|
146
|
+
snap_notify: Struct<{} | undefined, {}>;
|
|
147
|
+
snap_getBip32Entropy: Struct<{
|
|
148
|
+
path: string[];
|
|
149
|
+
curve: "ed25519" | "secp256k1";
|
|
150
|
+
}[] | undefined, Struct<{
|
|
151
|
+
path: string[];
|
|
152
|
+
curve: "ed25519" | "secp256k1";
|
|
153
|
+
}, {
|
|
154
|
+
path: Struct<string[], Struct<string, null>>;
|
|
155
|
+
curve: Struct<"ed25519" | "secp256k1", {
|
|
156
|
+
ed25519: "ed25519";
|
|
157
|
+
secp256k1: "secp256k1";
|
|
158
|
+
}>;
|
|
159
|
+
}>>;
|
|
160
|
+
snap_getBip32PublicKey: Struct<{
|
|
161
|
+
path: string[];
|
|
162
|
+
curve: "secp256k1" | "ed225519";
|
|
163
|
+
compressed?: boolean | undefined;
|
|
164
|
+
}[] | undefined, Struct<{
|
|
165
|
+
path: string[];
|
|
166
|
+
curve: "secp256k1" | "ed225519";
|
|
167
|
+
compressed?: boolean | undefined;
|
|
168
|
+
}, {
|
|
169
|
+
path: Struct<string[], Struct<string, null>>;
|
|
170
|
+
curve: Struct<"secp256k1" | "ed225519", {
|
|
171
|
+
secp256k1: "secp256k1";
|
|
172
|
+
ed225519: "ed225519";
|
|
173
|
+
}>;
|
|
174
|
+
compressed: Struct<boolean | undefined, null>;
|
|
175
|
+
}>>;
|
|
176
|
+
snap_getBip44Entropy: Struct<{
|
|
177
|
+
coinType: number;
|
|
178
|
+
}[] | undefined, Struct<{
|
|
179
|
+
coinType: number;
|
|
180
|
+
}, {
|
|
181
|
+
coinType: Struct<number, null>;
|
|
182
|
+
}>>;
|
|
183
|
+
snap_getEntropy: Struct<{} | undefined, {}>;
|
|
184
|
+
'endowment:keyring': Struct<{
|
|
185
|
+
namespaces: Record<string, {
|
|
186
|
+
chains: {
|
|
187
|
+
name: string;
|
|
188
|
+
id: string;
|
|
189
|
+
}[];
|
|
190
|
+
methods?: string[] | undefined;
|
|
191
|
+
events?: string[] | undefined;
|
|
192
|
+
}>;
|
|
193
|
+
} | undefined, {
|
|
194
|
+
namespaces: Struct<Record<string, {
|
|
195
|
+
chains: {
|
|
196
|
+
name: string;
|
|
197
|
+
id: string;
|
|
198
|
+
}[];
|
|
199
|
+
methods?: string[] | undefined;
|
|
200
|
+
events?: string[] | undefined;
|
|
201
|
+
}>, null>;
|
|
202
|
+
}>;
|
|
203
|
+
}>;
|
|
204
|
+
export declare type SnapPermissions = Infer<typeof PermissionsStruct>;
|
|
205
|
+
export declare const SnapManifestStruct: Struct<{
|
|
206
|
+
version: string;
|
|
207
|
+
description: string;
|
|
208
|
+
proposedName: string;
|
|
209
|
+
source: {
|
|
210
|
+
location: {
|
|
211
|
+
npm: {
|
|
212
|
+
filePath: string;
|
|
213
|
+
packageName: string;
|
|
214
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
215
|
+
iconPath?: string | undefined;
|
|
216
|
+
};
|
|
217
|
+
};
|
|
218
|
+
shasum: string;
|
|
219
|
+
};
|
|
220
|
+
initialPermissions: {
|
|
221
|
+
'endowment:long-running'?: {} | undefined;
|
|
222
|
+
'endowment:network-access'?: {} | undefined;
|
|
223
|
+
'endowment:transaction-insight'?: {
|
|
224
|
+
allowTransactionOrigin?: boolean | undefined;
|
|
225
|
+
} | undefined;
|
|
226
|
+
'endowment:cronjob'?: {
|
|
227
|
+
jobs: {
|
|
228
|
+
expression: string;
|
|
229
|
+
request: {
|
|
230
|
+
method: string;
|
|
231
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
232
|
+
id?: string | number | null | undefined;
|
|
233
|
+
jsonrpc?: "2.0" | undefined;
|
|
234
|
+
};
|
|
235
|
+
}[];
|
|
236
|
+
} | undefined;
|
|
237
|
+
snap_confirm?: {} | undefined;
|
|
238
|
+
snap_manageState?: {} | undefined;
|
|
239
|
+
snap_notify?: {} | undefined;
|
|
240
|
+
snap_getBip32Entropy?: {
|
|
241
|
+
path: string[];
|
|
242
|
+
curve: "ed25519" | "secp256k1";
|
|
243
|
+
}[] | undefined;
|
|
244
|
+
snap_getBip32PublicKey?: {
|
|
245
|
+
path: string[];
|
|
246
|
+
curve: "secp256k1" | "ed225519";
|
|
247
|
+
compressed?: boolean | undefined;
|
|
248
|
+
}[] | undefined;
|
|
249
|
+
snap_getBip44Entropy?: {
|
|
250
|
+
coinType: number;
|
|
251
|
+
}[] | undefined;
|
|
252
|
+
snap_getEntropy?: {} | undefined;
|
|
253
|
+
'endowment:keyring'?: {
|
|
254
|
+
namespaces: Record<string, {
|
|
255
|
+
chains: {
|
|
256
|
+
name: string;
|
|
257
|
+
id: string;
|
|
258
|
+
}[];
|
|
259
|
+
methods?: string[] | undefined;
|
|
260
|
+
events?: string[] | undefined;
|
|
261
|
+
}>;
|
|
262
|
+
} | undefined;
|
|
263
|
+
};
|
|
264
|
+
manifestVersion: "0.1";
|
|
265
|
+
repository?: {
|
|
266
|
+
type: string;
|
|
267
|
+
url: string;
|
|
268
|
+
} | undefined;
|
|
269
|
+
}, {
|
|
270
|
+
version: Struct<string, null>;
|
|
271
|
+
description: Struct<string, null>;
|
|
272
|
+
proposedName: Struct<string, null>;
|
|
273
|
+
repository: Struct<{
|
|
274
|
+
type: string;
|
|
275
|
+
url: string;
|
|
276
|
+
} | undefined, {
|
|
277
|
+
type: Struct<string, null>;
|
|
278
|
+
url: Struct<string, null>;
|
|
279
|
+
}>;
|
|
280
|
+
source: Struct<{
|
|
281
|
+
location: {
|
|
282
|
+
npm: {
|
|
283
|
+
filePath: string;
|
|
284
|
+
packageName: string;
|
|
285
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
286
|
+
iconPath?: string | undefined;
|
|
287
|
+
};
|
|
288
|
+
};
|
|
289
|
+
shasum: string;
|
|
290
|
+
}, {
|
|
291
|
+
shasum: Struct<string, null>;
|
|
292
|
+
location: Struct<{
|
|
293
|
+
npm: {
|
|
294
|
+
filePath: string;
|
|
295
|
+
packageName: string;
|
|
296
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
297
|
+
iconPath?: string | undefined;
|
|
298
|
+
};
|
|
299
|
+
}, {
|
|
300
|
+
npm: Struct<{
|
|
301
|
+
filePath: string;
|
|
302
|
+
packageName: string;
|
|
303
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
304
|
+
iconPath?: string | undefined;
|
|
305
|
+
}, {
|
|
306
|
+
filePath: Struct<string, null>;
|
|
307
|
+
iconPath: Struct<string | undefined, null>;
|
|
308
|
+
packageName: Struct<string, null>;
|
|
309
|
+
registry: Struct<"https://registry.npmjs.org" | "https://registry.npmjs.org/", null>;
|
|
310
|
+
}>;
|
|
311
|
+
}>;
|
|
312
|
+
}>;
|
|
313
|
+
initialPermissions: Struct<{
|
|
314
|
+
'endowment:long-running'?: {} | undefined;
|
|
315
|
+
'endowment:network-access'?: {} | undefined;
|
|
316
|
+
'endowment:transaction-insight'?: {
|
|
317
|
+
allowTransactionOrigin?: boolean | undefined;
|
|
318
|
+
} | undefined;
|
|
319
|
+
'endowment:cronjob'?: {
|
|
320
|
+
jobs: {
|
|
321
|
+
expression: string;
|
|
322
|
+
request: {
|
|
323
|
+
method: string;
|
|
324
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
325
|
+
id?: string | number | null | undefined;
|
|
326
|
+
jsonrpc?: "2.0" | undefined;
|
|
327
|
+
};
|
|
328
|
+
}[];
|
|
329
|
+
} | undefined;
|
|
330
|
+
snap_confirm?: {} | undefined;
|
|
331
|
+
snap_manageState?: {} | undefined;
|
|
332
|
+
snap_notify?: {} | undefined;
|
|
333
|
+
snap_getBip32Entropy?: {
|
|
334
|
+
path: string[];
|
|
335
|
+
curve: "ed25519" | "secp256k1";
|
|
336
|
+
}[] | undefined;
|
|
337
|
+
snap_getBip32PublicKey?: {
|
|
338
|
+
path: string[];
|
|
339
|
+
curve: "secp256k1" | "ed225519";
|
|
340
|
+
compressed?: boolean | undefined;
|
|
341
|
+
}[] | undefined;
|
|
342
|
+
snap_getBip44Entropy?: {
|
|
343
|
+
coinType: number;
|
|
344
|
+
}[] | undefined;
|
|
345
|
+
snap_getEntropy?: {} | undefined;
|
|
346
|
+
'endowment:keyring'?: {
|
|
347
|
+
namespaces: Record<string, {
|
|
348
|
+
chains: {
|
|
349
|
+
name: string;
|
|
350
|
+
id: string;
|
|
351
|
+
}[];
|
|
352
|
+
methods?: string[] | undefined;
|
|
353
|
+
events?: string[] | undefined;
|
|
354
|
+
}>;
|
|
355
|
+
} | undefined;
|
|
356
|
+
}, {
|
|
357
|
+
'endowment:long-running': Struct<{} | undefined, {}>;
|
|
358
|
+
'endowment:network-access': Struct<{} | undefined, {}>;
|
|
359
|
+
'endowment:transaction-insight': Struct<{
|
|
360
|
+
allowTransactionOrigin?: boolean | undefined;
|
|
361
|
+
} | undefined, {
|
|
362
|
+
allowTransactionOrigin: Struct<boolean | undefined, null>;
|
|
363
|
+
}>;
|
|
364
|
+
'endowment:cronjob': Struct<{
|
|
365
|
+
jobs: {
|
|
366
|
+
expression: string;
|
|
367
|
+
request: {
|
|
368
|
+
method: string;
|
|
369
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
370
|
+
id?: string | number | null | undefined;
|
|
371
|
+
jsonrpc?: "2.0" | undefined;
|
|
372
|
+
};
|
|
373
|
+
}[];
|
|
374
|
+
} | undefined, {
|
|
375
|
+
jobs: Struct<{
|
|
376
|
+
expression: string;
|
|
377
|
+
request: {
|
|
378
|
+
method: string;
|
|
379
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
380
|
+
id?: string | number | null | undefined;
|
|
381
|
+
jsonrpc?: "2.0" | undefined;
|
|
382
|
+
};
|
|
383
|
+
}[], Struct<{
|
|
384
|
+
expression: string;
|
|
385
|
+
request: {
|
|
386
|
+
method: string;
|
|
387
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
388
|
+
id?: string | number | null | undefined;
|
|
389
|
+
jsonrpc?: "2.0" | undefined;
|
|
390
|
+
};
|
|
391
|
+
}, {
|
|
392
|
+
expression: Struct<string, null>;
|
|
393
|
+
request: Struct<{
|
|
394
|
+
method: string;
|
|
395
|
+
params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
|
|
396
|
+
id?: string | number | null | undefined;
|
|
397
|
+
jsonrpc?: "2.0" | undefined;
|
|
398
|
+
}, {
|
|
399
|
+
params: Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
|
|
400
|
+
method: Struct<string, null>;
|
|
401
|
+
id: Struct<string | number | null | undefined, unknown>;
|
|
402
|
+
jsonrpc: Struct<"2.0" | undefined, unknown>;
|
|
403
|
+
}>;
|
|
404
|
+
}>>;
|
|
405
|
+
}>;
|
|
406
|
+
snap_confirm: Struct<{} | undefined, {}>;
|
|
407
|
+
snap_manageState: Struct<{} | undefined, {}>;
|
|
408
|
+
snap_notify: Struct<{} | undefined, {}>;
|
|
409
|
+
snap_getBip32Entropy: Struct<{
|
|
410
|
+
path: string[];
|
|
411
|
+
curve: "ed25519" | "secp256k1";
|
|
412
|
+
}[] | undefined, Struct<{
|
|
413
|
+
path: string[];
|
|
414
|
+
curve: "ed25519" | "secp256k1";
|
|
415
|
+
}, {
|
|
416
|
+
path: Struct<string[], Struct<string, null>>;
|
|
417
|
+
curve: Struct<"ed25519" | "secp256k1", {
|
|
418
|
+
ed25519: "ed25519";
|
|
419
|
+
secp256k1: "secp256k1";
|
|
420
|
+
}>;
|
|
421
|
+
}>>;
|
|
422
|
+
snap_getBip32PublicKey: Struct<{
|
|
423
|
+
path: string[];
|
|
424
|
+
curve: "secp256k1" | "ed225519";
|
|
425
|
+
compressed?: boolean | undefined;
|
|
426
|
+
}[] | undefined, Struct<{
|
|
427
|
+
path: string[];
|
|
428
|
+
curve: "secp256k1" | "ed225519";
|
|
429
|
+
compressed?: boolean | undefined;
|
|
430
|
+
}, {
|
|
431
|
+
path: Struct<string[], Struct<string, null>>;
|
|
432
|
+
curve: Struct<"secp256k1" | "ed225519", {
|
|
433
|
+
secp256k1: "secp256k1";
|
|
434
|
+
ed225519: "ed225519";
|
|
435
|
+
}>;
|
|
436
|
+
compressed: Struct<boolean | undefined, null>;
|
|
437
|
+
}>>;
|
|
438
|
+
snap_getBip44Entropy: Struct<{
|
|
439
|
+
coinType: number;
|
|
440
|
+
}[] | undefined, Struct<{
|
|
441
|
+
coinType: number;
|
|
442
|
+
}, {
|
|
443
|
+
coinType: Struct<number, null>;
|
|
444
|
+
}>>;
|
|
445
|
+
snap_getEntropy: Struct<{} | undefined, {}>;
|
|
446
|
+
'endowment:keyring': Struct<{
|
|
447
|
+
namespaces: Record<string, {
|
|
448
|
+
chains: {
|
|
449
|
+
name: string;
|
|
450
|
+
id: string;
|
|
451
|
+
}[];
|
|
452
|
+
methods?: string[] | undefined;
|
|
453
|
+
events?: string[] | undefined;
|
|
454
|
+
}>;
|
|
455
|
+
} | undefined, {
|
|
456
|
+
namespaces: Struct<Record<string, {
|
|
457
|
+
chains: {
|
|
458
|
+
name: string;
|
|
459
|
+
id: string;
|
|
460
|
+
}[];
|
|
461
|
+
methods?: string[] | undefined;
|
|
462
|
+
events?: string[] | undefined;
|
|
463
|
+
}>, null>;
|
|
464
|
+
}>;
|
|
465
|
+
}>;
|
|
466
|
+
manifestVersion: Struct<"0.1", "0.1">;
|
|
467
|
+
}>;
|
|
468
|
+
export declare type SnapManifest = Infer<typeof SnapManifestStruct>;
|
|
469
|
+
/**
|
|
470
|
+
* Check if the given value is a valid {@link SnapManifest} object.
|
|
471
|
+
*
|
|
472
|
+
* @param value - The value to check.
|
|
473
|
+
* @returns Whether the value is a valid {@link SnapManifest} object.
|
|
474
|
+
*/
|
|
475
|
+
export declare function isSnapManifest(value: unknown): value is SnapManifest;
|
|
476
|
+
/**
|
|
477
|
+
* Assert that the given value is a valid {@link SnapManifest} object.
|
|
478
|
+
*
|
|
479
|
+
* @param value - The value to check.
|
|
480
|
+
* @throws If the value is not a valid {@link SnapManifest} object.
|
|
481
|
+
*/
|
|
482
|
+
export declare function assertIsSnapManifest(value: unknown): asserts value is SnapManifest;
|
|
483
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.assertIsSnapManifest = exports.isSnapManifest = exports.SnapManifestStruct = exports.Bip32PublicKeyStruct = exports.Bip32EntropyStruct = exports.Bip32PathStruct = exports.base64 = exports.SIP_6_MAGIC_VALUE = void 0;
|
|
4
|
+
const utils_1 = require("@metamask/utils");
|
|
5
|
+
const superstruct_1 = require("superstruct");
|
|
6
|
+
const cronjob_1 = require("../cronjob");
|
|
7
|
+
const namespace_1 = require("../namespace");
|
|
8
|
+
const types_1 = require("../types");
|
|
9
|
+
// 0xd36e6170 - 0x80000000
|
|
10
|
+
exports.SIP_6_MAGIC_VALUE = `1399742832'`;
|
|
11
|
+
// BIP-43 purposes that cannot be used for entropy derivation. These are in the
|
|
12
|
+
// string form, ending with `'`.
|
|
13
|
+
const FORBIDDEN_PURPOSES = [exports.SIP_6_MAGIC_VALUE];
|
|
14
|
+
/**
|
|
15
|
+
* Ensure that a provided string-based struct is valid base64.
|
|
16
|
+
*
|
|
17
|
+
* @param struct - The string based struct.
|
|
18
|
+
* @param opts - Optional options to specialize base64 validation. See {@link Base64Opts} documentation.
|
|
19
|
+
* @returns A superstruct validating base64.
|
|
20
|
+
*/
|
|
21
|
+
const base64 = (struct, opts = {}) => {
|
|
22
|
+
var _a, _b;
|
|
23
|
+
const paddingRequired = (_a = opts.paddingRequired) !== null && _a !== void 0 ? _a : false;
|
|
24
|
+
const characterSet = (_b = opts.characterSet) !== null && _b !== void 0 ? _b : 'base64';
|
|
25
|
+
let letters;
|
|
26
|
+
if (characterSet === 'base64') {
|
|
27
|
+
letters = String.raw `[A-Za-z0-9+\/]`;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
(0, utils_1.assert)(characterSet === 'base64url');
|
|
31
|
+
letters = String.raw `[-_A-Za-z0-9]`;
|
|
32
|
+
}
|
|
33
|
+
let re;
|
|
34
|
+
if (paddingRequired) {
|
|
35
|
+
re = new RegExp(`^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`, 'u');
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
re = new RegExp(`^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`, 'u');
|
|
39
|
+
}
|
|
40
|
+
return (0, superstruct_1.pattern)(struct, re);
|
|
41
|
+
};
|
|
42
|
+
exports.base64 = base64;
|
|
43
|
+
const BIP32_INDEX_REGEX = /^\d+'?$/u;
|
|
44
|
+
exports.Bip32PathStruct = (0, superstruct_1.refine)((0, superstruct_1.array)((0, superstruct_1.string)()), 'BIP-32 path', (path) => {
|
|
45
|
+
if (path.length === 0) {
|
|
46
|
+
return 'Path must be a non-empty BIP-32 derivation path array';
|
|
47
|
+
}
|
|
48
|
+
if (path[0] !== 'm') {
|
|
49
|
+
return 'Path must start with "m".';
|
|
50
|
+
}
|
|
51
|
+
if (path.length < 3) {
|
|
52
|
+
return 'Paths must have a length of at least three.';
|
|
53
|
+
}
|
|
54
|
+
if (path.slice(1).some((e) => !BIP32_INDEX_REGEX.test(e))) {
|
|
55
|
+
return 'Path must be a valid BIP-32 derivation path array.';
|
|
56
|
+
}
|
|
57
|
+
if (FORBIDDEN_PURPOSES.includes(path[1])) {
|
|
58
|
+
return `The purpose "${path[1]}" is not allowed for entropy derivation.`;
|
|
59
|
+
}
|
|
60
|
+
return true;
|
|
61
|
+
});
|
|
62
|
+
const bip32entropy = (struct) => (0, superstruct_1.refine)(struct, 'BIP-32 entropy', (value) => {
|
|
63
|
+
if (value.curve === 'ed25519' &&
|
|
64
|
+
value.path.slice(1).some((e) => !e.endsWith("'"))) {
|
|
65
|
+
return 'Ed25519 does not support unhardened paths.';
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
});
|
|
69
|
+
// Used outside @metamask/snap-utils
|
|
70
|
+
exports.Bip32EntropyStruct = bip32entropy((0, superstruct_1.object)({
|
|
71
|
+
path: exports.Bip32PathStruct,
|
|
72
|
+
curve: (0, superstruct_1.enums)(['ed25519', 'secp256k1']),
|
|
73
|
+
}));
|
|
74
|
+
exports.Bip32PublicKeyStruct = bip32entropy((0, superstruct_1.object)({
|
|
75
|
+
path: exports.Bip32PathStruct,
|
|
76
|
+
curve: (0, superstruct_1.enums)(['ed225519', 'secp256k1']),
|
|
77
|
+
compressed: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
78
|
+
}));
|
|
79
|
+
const PermissionsStruct = (0, superstruct_1.type)({
|
|
80
|
+
'endowment:long-running': (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
81
|
+
'endowment:network-access': (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
82
|
+
'endowment:transaction-insight': (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
83
|
+
allowTransactionOrigin: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
84
|
+
})),
|
|
85
|
+
'endowment:cronjob': (0, superstruct_1.optional)((0, superstruct_1.object)({ jobs: cronjob_1.CronjobSpecificationArrayStruct })),
|
|
86
|
+
snap_confirm: (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
87
|
+
snap_manageState: (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
88
|
+
snap_notify: (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
89
|
+
snap_getBip32Entropy: (0, superstruct_1.optional)((0, superstruct_1.size)((0, superstruct_1.array)(exports.Bip32EntropyStruct), 1, Infinity)),
|
|
90
|
+
snap_getBip32PublicKey: (0, superstruct_1.optional)((0, superstruct_1.size)((0, superstruct_1.array)(exports.Bip32PublicKeyStruct), 1, Infinity)),
|
|
91
|
+
snap_getBip44Entropy: (0, superstruct_1.optional)((0, superstruct_1.size)((0, superstruct_1.array)((0, superstruct_1.object)({ coinType: (0, superstruct_1.size)((0, superstruct_1.integer)(), 0, 2 ** 32 - 1) })), 1, Infinity)),
|
|
92
|
+
snap_getEntropy: (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
93
|
+
'endowment:keyring': (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
94
|
+
namespaces: namespace_1.NamespacesStruct,
|
|
95
|
+
})),
|
|
96
|
+
});
|
|
97
|
+
exports.SnapManifestStruct = (0, superstruct_1.object)({
|
|
98
|
+
version: types_1.VersionStruct,
|
|
99
|
+
description: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, 280),
|
|
100
|
+
proposedName: (0, superstruct_1.size)((0, superstruct_1.pattern)((0, superstruct_1.string)(), /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u), 1, 214),
|
|
101
|
+
repository: (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
102
|
+
type: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
103
|
+
url: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
104
|
+
})),
|
|
105
|
+
source: (0, superstruct_1.object)({
|
|
106
|
+
shasum: (0, superstruct_1.size)((0, exports.base64)((0, superstruct_1.string)(), { paddingRequired: true }), 44, 44),
|
|
107
|
+
location: (0, superstruct_1.object)({
|
|
108
|
+
npm: (0, superstruct_1.object)({
|
|
109
|
+
filePath: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
110
|
+
iconPath: (0, superstruct_1.optional)((0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity)),
|
|
111
|
+
packageName: types_1.NameStruct,
|
|
112
|
+
registry: (0, superstruct_1.union)([
|
|
113
|
+
(0, superstruct_1.literal)('https://registry.npmjs.org'),
|
|
114
|
+
(0, superstruct_1.literal)('https://registry.npmjs.org/'),
|
|
115
|
+
]),
|
|
116
|
+
}),
|
|
117
|
+
}),
|
|
118
|
+
}),
|
|
119
|
+
initialPermissions: PermissionsStruct,
|
|
120
|
+
manifestVersion: (0, superstruct_1.literal)('0.1'),
|
|
121
|
+
});
|
|
122
|
+
/**
|
|
123
|
+
* Check if the given value is a valid {@link SnapManifest} object.
|
|
124
|
+
*
|
|
125
|
+
* @param value - The value to check.
|
|
126
|
+
* @returns Whether the value is a valid {@link SnapManifest} object.
|
|
127
|
+
*/
|
|
128
|
+
function isSnapManifest(value) {
|
|
129
|
+
return (0, superstruct_1.is)(value, exports.SnapManifestStruct);
|
|
130
|
+
}
|
|
131
|
+
exports.isSnapManifest = isSnapManifest;
|
|
132
|
+
/**
|
|
133
|
+
* Assert that the given value is a valid {@link SnapManifest} object.
|
|
134
|
+
*
|
|
135
|
+
* @param value - The value to check.
|
|
136
|
+
* @throws If the value is not a valid {@link SnapManifest} object.
|
|
137
|
+
*/
|
|
138
|
+
function assertIsSnapManifest(value) {
|
|
139
|
+
(0, utils_1.assertStruct)(value, exports.SnapManifestStruct, `"${types_1.NpmSnapFileNames.Manifest}" is invalid`);
|
|
140
|
+
}
|
|
141
|
+
exports.assertIsSnapManifest = assertIsSnapManifest;
|
|
142
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":";;;AAAA,2CAAuD;AACvD,6CAiBqB;AACrB,wCAA6D;AAC7D,4CAAgD;AAChD,oCAAuE;AAEvE,0BAA0B;AACb,QAAA,iBAAiB,GAAG,aAA6B,CAAC;AAE/D,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,kBAAkB,GAAa,CAAC,yBAAiB,CAAC,CAAC;AAmBzD;;;;;;GAMG;AACI,MAAM,MAAM,GAAG,CACpB,MAAoB,EACpB,OAAmB,EAAE,EACrB,EAAE;;IACF,MAAM,eAAe,GAAG,MAAA,IAAI,CAAC,eAAe,mCAAI,KAAK,CAAC;IACtD,M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,eAAe,EAAE,IAAA,qBAAO,EAAC,KAAK,CAAC;CAChC,CAAC,CAAC;AAIH;;;;;GAKG;AACH,SAAgB,cAAc,CAAC,KAAc;IAC3C,OAAO,IAAA,gBAAE,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AACvC,CAAC;AAFD,wCAEC;AAED;;;;;GAKG;AACH,SAAgB,oBAAoB,CAClC,KAAc;IAEd,IAAA,oBAAY,EACV,KAAK,EACL,0BAAkB,EAClB,IAAI,wBAAgB,CAAC,QAAQ,cAAc,CAC5C,CAAC;AACJ,CAAC;AARD,oDAQC","sourcesContent":["import { assert, assertStruct } from '@metamask/utils';\nimport {\n array,\n boolean,\n enums,\n Infer,\n integer,\n is,\n literal,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n Struct,\n type,\n union,\n} from 'superstruct';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { NamespacesStruct } from '../namespace';\nimport { NameStruct, NpmSnapFileNames, VersionStruct } from '../types';\n\n// 0xd36e6170 - 0x80000000\nexport const SIP_6_MAGIC_VALUE = `1399742832'` as `${number}'`;\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [SIP_6_MAGIC_VALUE];\n\nexport type Base64Opts = {\n /**\n * Is the `=` padding at the end required or not.\n *\n * @default false\n */\n // Padding is optional in RFC 4648, that's why the default value is false\n paddingRequired?: boolean;\n /**\n * Which character set should be used.\n * The sets are based on {@link https://datatracker.ietf.org/doc/html/rfc4648 RFC 4648}.\n *\n * @default 'base64'\n */\n characterSet?: 'base64' | 'base64url';\n};\n\n/**\n * Ensure that a provided string-based struct is valid base64.\n *\n * @param struct - The string based struct.\n * @param opts - Optional options to specialize base64 validation. See {@link Base64Opts} documentation.\n * @returns A superstruct validating base64.\n */\nexport const base64 = <T extends string, S>(\n struct: Struct<T, S>,\n opts: Base64Opts = {},\n) => {\n const paddingRequired = opts.paddingRequired ?? false;\n const characterSet = opts.characterSet ?? 'base64';\n\n let letters: string;\n if (characterSet === 'base64') {\n letters = String.raw`[A-Za-z0-9+\\/]`;\n } else {\n assert(characterSet === 'base64url');\n letters = String.raw`[-_A-Za-z0-9]`;\n }\n\n let re: RegExp;\n if (paddingRequired) {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n } else {\n re = new RegExp(\n `^(?:${letters}{4})*(?:${letters}{2,3}|${letters}{3}=|${letters}{2}==)?$`,\n 'u',\n );\n }\n\n return pattern(struct, re);\n};\n\nconst BIP32_INDEX_REGEX = /^\\d+'?$/u;\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((e) => !BIP32_INDEX_REGEX.test(e))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nconst bip32entropy = <T extends { path: string[]; curve: string }, S>(\n struct: Struct<T, S>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((e) => !e.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n object({\n path: Bip32PathStruct,\n curve: enums(['ed25519', 'secp256k1']),\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const Bip32PublicKeyStruct = bip32entropy(\n object({\n path: Bip32PathStruct,\n curve: enums(['ed225519', 'secp256k1']),\n compressed: optional(boolean()),\n }),\n);\n\nexport type Bip32PublicKey = Infer<typeof Bip32PublicKeyStruct>;\n\nconst PermissionsStruct = type({\n 'endowment:long-running': optional(object({})),\n 'endowment:network-access': optional(object({})),\n 'endowment:transaction-insight': optional(\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n 'endowment:cronjob': optional(\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n snap_confirm: optional(object({})),\n snap_manageState: optional(object({})),\n snap_notify: optional(object({})),\n snap_getBip32Entropy: optional(size(array(Bip32EntropyStruct), 1, Infinity)),\n snap_getBip32PublicKey: optional(\n size(array(Bip32PublicKeyStruct), 1, Infinity),\n ),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(object({})),\n 'endowment:keyring': optional(\n object({\n namespaces: NamespacesStruct,\n }),\n ),\n});\n\nexport type SnapPermissions = Infer<typeof PermissionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(\n pattern(\n string(),\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u,\n ),\n 1,\n 214,\n ),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: size(base64(string(), { paddingRequired: true }), 44, 44),\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n }),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n"]}
|
package/dist/mock.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const ALL_APIS: string[];
|
|
2
|
+
/**
|
|
3
|
+
* Check if a value is a constructor.
|
|
4
|
+
*
|
|
5
|
+
* @param value - The value to check.
|
|
6
|
+
* @returns `true` if the value is a constructor, or `false` otherwise.
|
|
7
|
+
*/
|
|
8
|
+
export declare const isConstructor: (value: any) => boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.
|
|
11
|
+
*
|
|
12
|
+
* @returns A map of endowments.
|
|
13
|
+
*/
|
|
14
|
+
export declare const generateMockEndowments: () => Record<string, any>;
|