@metamask/snaps-utils 0.35.1-flask.1 → 1.0.0-prerelease.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -46
- package/dist/{esm/array.js → array.js} +7 -3
- package/dist/array.js.map +1 -0
- package/dist/{types/caveats.d.ts → caveats.d.ts} +4 -0
- package/dist/caveats.js +35 -0
- package/dist/caveats.js.map +1 -0
- package/dist/checksum.js +42 -0
- package/dist/checksum.js.map +1 -0
- package/dist/cronjob.js +71 -0
- package/dist/cronjob.js.map +1 -0
- package/dist/deep-clone.js +9 -0
- package/dist/deep-clone.js.map +1 -0
- package/dist/{esm/default-endowments.js → default-endowments.js} +6 -3
- package/dist/default-endowments.js.map +1 -0
- package/dist/entropy.js +8 -0
- package/dist/entropy.js.map +1 -0
- package/dist/{cjs/eval-worker.js → eval-worker.js} +21 -22
- package/dist/eval-worker.js.map +1 -0
- package/dist/eval.js +27 -0
- package/dist/eval.js.map +1 -0
- package/dist/{esm/fs.js → fs.js} +56 -33
- package/dist/fs.js.map +1 -0
- package/dist/{types/handlers.d.ts → handlers.d.ts} +42 -5
- package/dist/handlers.js +3 -0
- package/dist/handlers.js.map +1 -0
- package/dist/{types/iframe.d.ts → iframe.d.ts} +2 -3
- package/dist/{esm/iframe.js → iframe.js} +18 -16
- package/dist/iframe.js.map +1 -0
- package/dist/iframe.test.browser.js +15 -0
- package/dist/iframe.test.browser.js.map +1 -0
- package/dist/{types/index.browser.d.ts → index.browser.d.ts} +1 -2
- package/dist/index.browser.js +37 -0
- package/dist/index.browser.js.map +1 -0
- package/dist/{types/index.d.ts → index.d.ts} +1 -2
- package/dist/index.executionenv.js +22 -0
- package/dist/index.executionenv.js.map +1 -0
- package/dist/index.js +42 -0
- package/dist/index.js.map +1 -0
- package/dist/json-rpc.js +46 -0
- package/dist/json-rpc.js.map +1 -0
- package/dist/json.d.ts +9 -0
- package/dist/json.js +18 -0
- package/dist/json.js.map +1 -0
- package/dist/{esm/logging.js → logging.js} +14 -6
- package/dist/logging.js.map +1 -0
- package/dist/manifest/index.browser.js +18 -0
- package/dist/manifest/index.browser.js.map +1 -0
- package/dist/manifest/index.js +19 -0
- package/dist/manifest/index.js.map +1 -0
- package/dist/{esm/manifest → manifest}/manifest.js +113 -98
- package/dist/manifest/manifest.js.map +1 -0
- package/dist/{types/manifest → manifest}/validation.d.ts +73 -31
- package/dist/manifest/validation.js +141 -0
- package/dist/manifest/validation.js.map +1 -0
- package/dist/{esm/mock.js → mock.js} +40 -42
- package/dist/mock.js.map +1 -0
- package/dist/namespace.d.ts +275 -0
- package/dist/namespace.js +225 -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/{types/npm.d.ts → npm.d.ts} +2 -0
- package/dist/npm.js +74 -0
- package/dist/npm.js.map +1 -0
- package/dist/path.js +21 -0
- package/dist/path.js.map +1 -0
- package/dist/{esm/post-process.js → post-process.js} +99 -110
- package/dist/post-process.js.map +1 -0
- package/dist/{types/snaps.d.ts → snaps.d.ts} +2 -9
- package/dist/snaps.js +202 -0
- package/dist/snaps.js.map +1 -0
- package/dist/{types/types.d.ts → types.d.ts} +5 -2
- package/dist/types.js +103 -0
- package/dist/types.js.map +1 -0
- package/dist/{esm/versions.js → versions.js} +18 -15
- package/dist/versions.js.map +1 -0
- package/dist/{esm/virtual-file → virtual-file}/VirtualFile.js +33 -47
- package/dist/virtual-file/VirtualFile.js.map +1 -0
- package/dist/virtual-file/index.browser.js +18 -0
- package/dist/virtual-file/index.browser.js.map +1 -0
- package/dist/virtual-file/index.js +19 -0
- package/dist/virtual-file/index.js.map +1 -0
- package/dist/virtual-file/toVirtualFile.js +30 -0
- package/dist/virtual-file/toVirtualFile.js.map +1 -0
- package/package.json +32 -61
- package/dist/cjs/array.js +0 -23
- package/dist/cjs/array.js.map +0 -1
- package/dist/cjs/caveats.js +0 -33
- package/dist/cjs/caveats.js.map +0 -1
- package/dist/cjs/checksum.js +0 -38
- package/dist/cjs/checksum.js.map +0 -1
- package/dist/cjs/cronjob.js +0 -84
- package/dist/cjs/cronjob.js.map +0 -1
- package/dist/cjs/deep-clone.js +0 -22
- package/dist/cjs/deep-clone.js.map +0 -1
- package/dist/cjs/default-endowments.js +0 -49
- package/dist/cjs/default-endowments.js.map +0 -1
- package/dist/cjs/entropy.js +0 -23
- package/dist/cjs/entropy.js.map +0 -1
- package/dist/cjs/enum.js +0 -16
- package/dist/cjs/enum.js.map +0 -1
- package/dist/cjs/eval-worker.js.map +0 -1
- package/dist/cjs/eval.js +0 -29
- package/dist/cjs/eval.js.map +0 -1
- package/dist/cjs/fs.js +0 -126
- package/dist/cjs/fs.js.map +0 -1
- package/dist/cjs/handlers.js +0 -6
- package/dist/cjs/handlers.js.map +0 -1
- package/dist/cjs/icon.js +0 -37
- package/dist/cjs/icon.js.map +0 -1
- package/dist/cjs/iframe.js +0 -59
- package/dist/cjs/iframe.js.map +0 -1
- package/dist/cjs/index.browser.js +0 -40
- package/dist/cjs/index.browser.js.map +0 -1
- package/dist/cjs/index.executionenv.js +0 -24
- package/dist/cjs/index.executionenv.js.map +0 -1
- package/dist/cjs/index.js +0 -45
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/json-rpc.js +0 -46
- package/dist/cjs/json-rpc.js.map +0 -1
- package/dist/cjs/json.js +0 -16
- package/dist/cjs/json.js.map +0 -1
- package/dist/cjs/logging.js +0 -40
- package/dist/cjs/logging.js.map +0 -1
- package/dist/cjs/manifest/index.browser.js +0 -20
- package/dist/cjs/manifest/index.browser.js.map +0 -1
- package/dist/cjs/manifest/index.js +0 -21
- package/dist/cjs/manifest/index.js.map +0 -1
- package/dist/cjs/manifest/manifest.js +0 -239
- package/dist/cjs/manifest/manifest.js.map +0 -1
- package/dist/cjs/manifest/validation.js +0 -183
- package/dist/cjs/manifest/validation.js.map +0 -1
- package/dist/cjs/mock.js +0 -128
- package/dist/cjs/mock.js.map +0 -1
- package/dist/cjs/namespace.js +0 -124
- package/dist/cjs/namespace.js.map +0 -1
- package/dist/cjs/npm.js +0 -81
- package/dist/cjs/npm.js.map +0 -1
- package/dist/cjs/path.js +0 -21
- package/dist/cjs/path.js.map +0 -1
- package/dist/cjs/post-process.js +0 -328
- package/dist/cjs/post-process.js.map +0 -1
- package/dist/cjs/snaps.js +0 -230
- package/dist/cjs/snaps.js.map +0 -1
- package/dist/cjs/types.js +0 -117
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/validation.js +0 -22
- package/dist/cjs/validation.js.map +0 -1
- package/dist/cjs/versions.js +0 -47
- package/dist/cjs/versions.js.map +0 -1
- package/dist/cjs/virtual-file/VirtualFile.js +0 -85
- package/dist/cjs/virtual-file/VirtualFile.js.map +0 -1
- package/dist/cjs/virtual-file/index.browser.js +0 -20
- package/dist/cjs/virtual-file/index.browser.js.map +0 -1
- package/dist/cjs/virtual-file/index.js +0 -21
- package/dist/cjs/virtual-file/index.js.map +0 -1
- package/dist/cjs/virtual-file/toVirtualFile.js +0 -33
- package/dist/cjs/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/esm/array.js.map +0 -1
- package/dist/esm/caveats.js +0 -23
- package/dist/esm/caveats.js.map +0 -1
- package/dist/esm/checksum.js +0 -36
- package/dist/esm/checksum.js.map +0 -1
- package/dist/esm/cronjob.js +0 -66
- package/dist/esm/cronjob.js.map +0 -1
- package/dist/esm/deep-clone.js +0 -7
- package/dist/esm/deep-clone.js.map +0 -1
- package/dist/esm/default-endowments.js.map +0 -1
- package/dist/esm/entropy.js +0 -6
- package/dist/esm/entropy.js.map +0 -1
- package/dist/esm/enum.js +0 -12
- package/dist/esm/enum.js.map +0 -1
- package/dist/esm/eval-worker.js +0 -47
- package/dist/esm/eval-worker.js.map +0 -1
- package/dist/esm/eval.js +0 -25
- package/dist/esm/eval.js.map +0 -1
- package/dist/esm/fs.js.map +0 -1
- package/dist/esm/handlers.js +0 -3
- package/dist/esm/handlers.js.map +0 -1
- package/dist/esm/icon.js +0 -11
- package/dist/esm/icon.js.map +0 -1
- package/dist/esm/iframe.js.map +0 -1
- package/dist/esm/index.browser.js +0 -23
- package/dist/esm/index.browser.js.map +0 -1
- package/dist/esm/index.executionenv.js +0 -7
- package/dist/esm/index.executionenv.js.map +0 -1
- package/dist/esm/index.js +0 -28
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/json-rpc.js +0 -39
- package/dist/esm/json-rpc.js.map +0 -1
- package/dist/esm/json.js +0 -17
- package/dist/esm/json.js.map +0 -1
- package/dist/esm/logging.js.map +0 -1
- package/dist/esm/manifest/index.browser.js +0 -3
- package/dist/esm/manifest/index.browser.js.map +0 -1
- package/dist/esm/manifest/index.js +0 -4
- package/dist/esm/manifest/index.js.map +0 -1
- package/dist/esm/manifest/manifest.js.map +0 -1
- package/dist/esm/manifest/validation.js +0 -152
- package/dist/esm/manifest/validation.js.map +0 -1
- package/dist/esm/mock.js.map +0 -1
- package/dist/esm/namespace.js +0 -110
- package/dist/esm/namespace.js.map +0 -1
- package/dist/esm/npm.js +0 -70
- package/dist/esm/npm.js.map +0 -1
- package/dist/esm/path.js +0 -17
- package/dist/esm/path.js.map +0 -1
- package/dist/esm/post-process.js.map +0 -1
- package/dist/esm/snaps.js +0 -215
- package/dist/esm/snaps.js.map +0 -1
- package/dist/esm/types.js +0 -85
- package/dist/esm/types.js.map +0 -1
- package/dist/esm/validation.js +0 -17
- package/dist/esm/validation.js.map +0 -1
- package/dist/esm/versions.js.map +0 -1
- package/dist/esm/virtual-file/VirtualFile.js.map +0 -1
- package/dist/esm/virtual-file/index.browser.js +0 -3
- package/dist/esm/virtual-file/index.browser.js.map +0 -1
- package/dist/esm/virtual-file/index.js +0 -4
- package/dist/esm/virtual-file/index.js.map +0 -1
- package/dist/esm/virtual-file/toVirtualFile.js +0 -26
- package/dist/esm/virtual-file/toVirtualFile.js.map +0 -1
- package/dist/types/enum.d.ts +0 -30
- package/dist/types/icon.d.ts +0 -4
- package/dist/types/json.d.ts +0 -13
- package/dist/types/namespace.d.ts +0 -124
- package/dist/types/validation.d.ts +0 -8
- /package/dist/{types/array.d.ts → array.d.ts} +0 -0
- /package/dist/{types/checksum.d.ts → checksum.d.ts} +0 -0
- /package/dist/{types/cronjob.d.ts → cronjob.d.ts} +0 -0
- /package/dist/{types/deep-clone.d.ts → deep-clone.d.ts} +0 -0
- /package/dist/{types/default-endowments.d.ts → default-endowments.d.ts} +0 -0
- /package/dist/{types/entropy.d.ts → entropy.d.ts} +0 -0
- /package/dist/{types/eval-worker.d.ts → eval-worker.d.ts} +0 -0
- /package/dist/{types/eval.d.ts → eval.d.ts} +0 -0
- /package/dist/{types/fs.d.ts → fs.d.ts} +0 -0
- /package/dist/{types/iframe.test.browser.d.ts → iframe.test.browser.d.ts} +0 -0
- /package/dist/{types/index.executionenv.d.ts → index.executionenv.d.ts} +0 -0
- /package/dist/{types/json-rpc.d.ts → json-rpc.d.ts} +0 -0
- /package/dist/{types/logging.d.ts → logging.d.ts} +0 -0
- /package/dist/{types/manifest → manifest}/index.browser.d.ts +0 -0
- /package/dist/{types/manifest → manifest}/index.d.ts +0 -0
- /package/dist/{types/manifest → manifest}/manifest.d.ts +0 -0
- /package/dist/{types/mock.d.ts → mock.d.ts} +0 -0
- /package/dist/{types/path.d.ts → path.d.ts} +0 -0
- /package/dist/{types/post-process.d.ts → post-process.d.ts} +0 -0
- /package/dist/{types/versions.d.ts → versions.d.ts} +0 -0
- /package/dist/{types/virtual-file → virtual-file}/VirtualFile.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/index.browser.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/index.d.ts +0 -0
- /package/dist/{types/virtual-file → virtual-file}/toVirtualFile.d.ts +0 -0
|
@@ -29,11 +29,6 @@ export declare const SnapGetBip32EntropyPermissionsStruct: Struct<{
|
|
|
29
29
|
secp256k1: "secp256k1";
|
|
30
30
|
}>;
|
|
31
31
|
}>>;
|
|
32
|
-
export declare const SemVerRangeStruct: Struct<string, null>;
|
|
33
|
-
export declare const SnapIdsStruct: Struct<Record<string, {
|
|
34
|
-
version?: string | undefined;
|
|
35
|
-
}>, null>;
|
|
36
|
-
export declare type SnapIds = Infer<typeof SnapIdsStruct>;
|
|
37
32
|
export declare const PermissionsStruct: Struct<{
|
|
38
33
|
'endowment:long-running'?: {} | undefined;
|
|
39
34
|
'endowment:network-access'?: {} | undefined;
|
|
@@ -59,7 +54,6 @@ export declare const PermissionsStruct: Struct<{
|
|
|
59
54
|
snap_dialog?: {} | undefined;
|
|
60
55
|
snap_confirm?: {} | undefined;
|
|
61
56
|
snap_manageState?: {} | undefined;
|
|
62
|
-
snap_manageAccounts?: {} | undefined;
|
|
63
57
|
snap_notify?: {} | undefined;
|
|
64
58
|
snap_getBip32Entropy?: {
|
|
65
59
|
path: string[];
|
|
@@ -73,9 +67,16 @@ export declare const PermissionsStruct: Struct<{
|
|
|
73
67
|
coinType: number;
|
|
74
68
|
}[] | undefined;
|
|
75
69
|
snap_getEntropy?: {} | undefined;
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
70
|
+
'endowment:keyring'?: {
|
|
71
|
+
namespaces: Record<string, {
|
|
72
|
+
chains: {
|
|
73
|
+
name: string;
|
|
74
|
+
id: string;
|
|
75
|
+
}[];
|
|
76
|
+
methods?: string[] | undefined;
|
|
77
|
+
events?: string[] | undefined;
|
|
78
|
+
}>;
|
|
79
|
+
} | undefined;
|
|
79
80
|
}, {
|
|
80
81
|
'endowment:long-running': Struct<{} | undefined, {}>;
|
|
81
82
|
'endowment:network-access': Struct<{} | undefined, {}>;
|
|
@@ -137,7 +138,6 @@ export declare const PermissionsStruct: Struct<{
|
|
|
137
138
|
snap_dialog: Struct<{} | undefined, {}>;
|
|
138
139
|
snap_confirm: Struct<{} | undefined, {}>;
|
|
139
140
|
snap_manageState: Struct<{} | undefined, {}>;
|
|
140
|
-
snap_manageAccounts: Struct<{} | undefined, {}>;
|
|
141
141
|
snap_notify: Struct<{} | undefined, {}>;
|
|
142
142
|
snap_getBip32Entropy: Struct<{
|
|
143
143
|
path: string[];
|
|
@@ -173,9 +173,25 @@ export declare const PermissionsStruct: Struct<{
|
|
|
173
173
|
coinType: Struct<number, null>;
|
|
174
174
|
}>>;
|
|
175
175
|
snap_getEntropy: Struct<{} | undefined, {}>;
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
'endowment:keyring': Struct<{
|
|
177
|
+
namespaces: Record<string, {
|
|
178
|
+
chains: {
|
|
179
|
+
name: string;
|
|
180
|
+
id: string;
|
|
181
|
+
}[];
|
|
182
|
+
methods?: string[] | undefined;
|
|
183
|
+
events?: string[] | undefined;
|
|
184
|
+
}>;
|
|
185
|
+
} | undefined, {
|
|
186
|
+
namespaces: Struct<Record<string, {
|
|
187
|
+
chains: {
|
|
188
|
+
name: string;
|
|
189
|
+
id: string;
|
|
190
|
+
}[];
|
|
191
|
+
methods?: string[] | undefined;
|
|
192
|
+
events?: string[] | undefined;
|
|
193
|
+
}>, null>;
|
|
194
|
+
}>;
|
|
179
195
|
}>;
|
|
180
196
|
export declare type SnapPermissions = Infer<typeof PermissionsStruct>;
|
|
181
197
|
export declare const SnapManifestStruct: Struct<{
|
|
@@ -185,9 +201,9 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
185
201
|
source: {
|
|
186
202
|
location: {
|
|
187
203
|
npm: {
|
|
188
|
-
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
189
204
|
filePath: string;
|
|
190
205
|
packageName: string;
|
|
206
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
191
207
|
iconPath?: string | undefined;
|
|
192
208
|
};
|
|
193
209
|
};
|
|
@@ -218,7 +234,6 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
218
234
|
snap_dialog?: {} | undefined;
|
|
219
235
|
snap_confirm?: {} | undefined;
|
|
220
236
|
snap_manageState?: {} | undefined;
|
|
221
|
-
snap_manageAccounts?: {} | undefined;
|
|
222
237
|
snap_notify?: {} | undefined;
|
|
223
238
|
snap_getBip32Entropy?: {
|
|
224
239
|
path: string[];
|
|
@@ -232,16 +247,22 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
232
247
|
coinType: number;
|
|
233
248
|
}[] | undefined;
|
|
234
249
|
snap_getEntropy?: {} | undefined;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
250
|
+
'endowment:keyring'?: {
|
|
251
|
+
namespaces: Record<string, {
|
|
252
|
+
chains: {
|
|
253
|
+
name: string;
|
|
254
|
+
id: string;
|
|
255
|
+
}[];
|
|
256
|
+
methods?: string[] | undefined;
|
|
257
|
+
events?: string[] | undefined;
|
|
258
|
+
}>;
|
|
259
|
+
} | undefined;
|
|
238
260
|
};
|
|
239
261
|
manifestVersion: "0.1";
|
|
240
262
|
repository?: {
|
|
241
263
|
type: string;
|
|
242
264
|
url: string;
|
|
243
265
|
} | undefined;
|
|
244
|
-
$schema?: string | undefined;
|
|
245
266
|
}, {
|
|
246
267
|
version: Struct<import("@metamask/utils").SemVerVersion, null>;
|
|
247
268
|
description: Struct<string, null>;
|
|
@@ -256,9 +277,9 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
256
277
|
source: Struct<{
|
|
257
278
|
location: {
|
|
258
279
|
npm: {
|
|
259
|
-
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
260
280
|
filePath: string;
|
|
261
281
|
packageName: string;
|
|
282
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
262
283
|
iconPath?: string | undefined;
|
|
263
284
|
};
|
|
264
285
|
};
|
|
@@ -267,16 +288,16 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
267
288
|
shasum: Struct<string, null>;
|
|
268
289
|
location: Struct<{
|
|
269
290
|
npm: {
|
|
270
|
-
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
271
291
|
filePath: string;
|
|
272
292
|
packageName: string;
|
|
293
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
273
294
|
iconPath?: string | undefined;
|
|
274
295
|
};
|
|
275
296
|
}, {
|
|
276
297
|
npm: Struct<{
|
|
277
|
-
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
278
298
|
filePath: string;
|
|
279
299
|
packageName: string;
|
|
300
|
+
registry: "https://registry.npmjs.org" | "https://registry.npmjs.org/";
|
|
280
301
|
iconPath?: string | undefined;
|
|
281
302
|
}, {
|
|
282
303
|
filePath: Struct<string, null>;
|
|
@@ -311,7 +332,6 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
311
332
|
snap_dialog?: {} | undefined;
|
|
312
333
|
snap_confirm?: {} | undefined;
|
|
313
334
|
snap_manageState?: {} | undefined;
|
|
314
|
-
snap_manageAccounts?: {} | undefined;
|
|
315
335
|
snap_notify?: {} | undefined;
|
|
316
336
|
snap_getBip32Entropy?: {
|
|
317
337
|
path: string[];
|
|
@@ -325,9 +345,16 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
325
345
|
coinType: number;
|
|
326
346
|
}[] | undefined;
|
|
327
347
|
snap_getEntropy?: {} | undefined;
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
348
|
+
'endowment:keyring'?: {
|
|
349
|
+
namespaces: Record<string, {
|
|
350
|
+
chains: {
|
|
351
|
+
name: string;
|
|
352
|
+
id: string;
|
|
353
|
+
}[];
|
|
354
|
+
methods?: string[] | undefined;
|
|
355
|
+
events?: string[] | undefined;
|
|
356
|
+
}>;
|
|
357
|
+
} | undefined;
|
|
331
358
|
}, {
|
|
332
359
|
'endowment:long-running': Struct<{} | undefined, {}>;
|
|
333
360
|
'endowment:network-access': Struct<{} | undefined, {}>;
|
|
@@ -389,7 +416,6 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
389
416
|
snap_dialog: Struct<{} | undefined, {}>;
|
|
390
417
|
snap_confirm: Struct<{} | undefined, {}>;
|
|
391
418
|
snap_manageState: Struct<{} | undefined, {}>;
|
|
392
|
-
snap_manageAccounts: Struct<{} | undefined, {}>;
|
|
393
419
|
snap_notify: Struct<{} | undefined, {}>;
|
|
394
420
|
snap_getBip32Entropy: Struct<{
|
|
395
421
|
path: string[];
|
|
@@ -425,12 +451,27 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
425
451
|
coinType: Struct<number, null>;
|
|
426
452
|
}>>;
|
|
427
453
|
snap_getEntropy: Struct<{} | undefined, {}>;
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
454
|
+
'endowment:keyring': Struct<{
|
|
455
|
+
namespaces: Record<string, {
|
|
456
|
+
chains: {
|
|
457
|
+
name: string;
|
|
458
|
+
id: string;
|
|
459
|
+
}[];
|
|
460
|
+
methods?: string[] | undefined;
|
|
461
|
+
events?: string[] | undefined;
|
|
462
|
+
}>;
|
|
463
|
+
} | undefined, {
|
|
464
|
+
namespaces: Struct<Record<string, {
|
|
465
|
+
chains: {
|
|
466
|
+
name: string;
|
|
467
|
+
id: string;
|
|
468
|
+
}[];
|
|
469
|
+
methods?: string[] | undefined;
|
|
470
|
+
events?: string[] | undefined;
|
|
471
|
+
}>, null>;
|
|
472
|
+
}>;
|
|
431
473
|
}>;
|
|
432
474
|
manifestVersion: Struct<"0.1", "0.1">;
|
|
433
|
-
$schema: Struct<string | undefined, null>;
|
|
434
475
|
}>;
|
|
435
476
|
export declare type SnapManifest = Infer<typeof SnapManifestStruct>;
|
|
436
477
|
/**
|
|
@@ -450,6 +491,7 @@ export declare function assertIsSnapManifest(value: unknown): asserts value is S
|
|
|
450
491
|
/**
|
|
451
492
|
* Creates a {@link SnapManifest} object from JSON.
|
|
452
493
|
*
|
|
494
|
+
*
|
|
453
495
|
* @param value - The value to check.
|
|
454
496
|
* @throws If the value cannot be coerced to a {@link SnapManifest} object.
|
|
455
497
|
* @returns The created {@link SnapManifest} object.
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.createSnapManifest = exports.assertIsSnapManifest = exports.isSnapManifest = exports.SnapManifestStruct = exports.PermissionsStruct = exports.SnapGetBip32EntropyPermissionsStruct = exports.Bip32EntropyStruct = exports.bip32entropy = exports.Bip32PathStruct = exports.FORBIDDEN_COIN_TYPES = void 0;
|
|
4
|
+
const key_tree_1 = require("@metamask/key-tree");
|
|
5
|
+
const utils_1 = require("@metamask/utils");
|
|
6
|
+
const superstruct_1 = require("superstruct");
|
|
7
|
+
const array_1 = require("../array");
|
|
8
|
+
const cronjob_1 = require("../cronjob");
|
|
9
|
+
const entropy_1 = require("../entropy");
|
|
10
|
+
const json_rpc_1 = require("../json-rpc");
|
|
11
|
+
const namespace_1 = require("../namespace");
|
|
12
|
+
const types_1 = require("../types");
|
|
13
|
+
// BIP-43 purposes that cannot be used for entropy derivation. These are in the
|
|
14
|
+
// string form, ending with `'`.
|
|
15
|
+
const FORBIDDEN_PURPOSES = [
|
|
16
|
+
entropy_1.SIP_6_MAGIC_VALUE,
|
|
17
|
+
entropy_1.STATE_ENCRYPTION_MAGIC_VALUE,
|
|
18
|
+
];
|
|
19
|
+
exports.FORBIDDEN_COIN_TYPES = [60];
|
|
20
|
+
const FORBIDDEN_PATHS = exports.FORBIDDEN_COIN_TYPES.map((coinType) => [
|
|
21
|
+
'm',
|
|
22
|
+
"44'",
|
|
23
|
+
`${coinType}'`,
|
|
24
|
+
]);
|
|
25
|
+
exports.Bip32PathStruct = (0, superstruct_1.refine)((0, superstruct_1.array)((0, superstruct_1.string)()), 'BIP-32 path', (path) => {
|
|
26
|
+
if (path.length === 0) {
|
|
27
|
+
return 'Path must be a non-empty BIP-32 derivation path array';
|
|
28
|
+
}
|
|
29
|
+
if (path[0] !== 'm') {
|
|
30
|
+
return 'Path must start with "m".';
|
|
31
|
+
}
|
|
32
|
+
if (path.length < 3) {
|
|
33
|
+
return 'Paths must have a length of at least three.';
|
|
34
|
+
}
|
|
35
|
+
if (path.slice(1).some((part) => !(0, key_tree_1.isValidBIP32PathSegment)(part))) {
|
|
36
|
+
return 'Path must be a valid BIP-32 derivation path array.';
|
|
37
|
+
}
|
|
38
|
+
if (FORBIDDEN_PURPOSES.includes(path[1])) {
|
|
39
|
+
return `The purpose "${path[1]}" is not allowed for entropy derivation.`;
|
|
40
|
+
}
|
|
41
|
+
if (FORBIDDEN_PATHS.some((forbiddenPath) => (0, array_1.isEqual)(path.slice(0, forbiddenPath.length), forbiddenPath))) {
|
|
42
|
+
return `The path "${path.join('/')}" is not allowed for entropy derivation.`;
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
const bip32entropy = (struct) => (0, superstruct_1.refine)(struct, 'BIP-32 entropy', (value) => {
|
|
47
|
+
if (value.curve === 'ed25519' &&
|
|
48
|
+
value.path.slice(1).some((part) => !part.endsWith("'"))) {
|
|
49
|
+
return 'Ed25519 does not support unhardened paths.';
|
|
50
|
+
}
|
|
51
|
+
return true;
|
|
52
|
+
});
|
|
53
|
+
exports.bip32entropy = bip32entropy;
|
|
54
|
+
// Used outside @metamask/snap-utils
|
|
55
|
+
exports.Bip32EntropyStruct = (0, exports.bip32entropy)((0, superstruct_1.type)({
|
|
56
|
+
path: exports.Bip32PathStruct,
|
|
57
|
+
curve: (0, superstruct_1.enums)(['ed25519', 'secp256k1']),
|
|
58
|
+
}));
|
|
59
|
+
exports.SnapGetBip32EntropyPermissionsStruct = (0, superstruct_1.size)((0, superstruct_1.array)(exports.Bip32EntropyStruct), 1, Infinity);
|
|
60
|
+
/* eslint-disable @typescript-eslint/naming-convention */
|
|
61
|
+
exports.PermissionsStruct = (0, superstruct_1.type)({
|
|
62
|
+
'endowment:long-running': (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
63
|
+
'endowment:network-access': (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
64
|
+
'endowment:webassembly': (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
65
|
+
'endowment:transaction-insight': (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
66
|
+
allowTransactionOrigin: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
67
|
+
})),
|
|
68
|
+
'endowment:cronjob': (0, superstruct_1.optional)((0, superstruct_1.object)({ jobs: cronjob_1.CronjobSpecificationArrayStruct })),
|
|
69
|
+
'endowment:rpc': (0, superstruct_1.optional)(json_rpc_1.RpcOriginsStruct),
|
|
70
|
+
snap_dialog: (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
71
|
+
// TODO: Remove
|
|
72
|
+
snap_confirm: (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
73
|
+
snap_manageState: (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
74
|
+
snap_notify: (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
75
|
+
snap_getBip32Entropy: (0, superstruct_1.optional)(exports.SnapGetBip32EntropyPermissionsStruct),
|
|
76
|
+
snap_getBip32PublicKey: (0, superstruct_1.optional)(exports.SnapGetBip32EntropyPermissionsStruct),
|
|
77
|
+
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)),
|
|
78
|
+
snap_getEntropy: (0, superstruct_1.optional)((0, superstruct_1.object)({})),
|
|
79
|
+
'endowment:keyring': (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
80
|
+
namespaces: namespace_1.NamespacesStruct,
|
|
81
|
+
})),
|
|
82
|
+
});
|
|
83
|
+
exports.SnapManifestStruct = (0, superstruct_1.object)({
|
|
84
|
+
version: utils_1.VersionStruct,
|
|
85
|
+
description: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, 280),
|
|
86
|
+
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),
|
|
87
|
+
repository: (0, superstruct_1.optional)((0, superstruct_1.object)({
|
|
88
|
+
type: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
89
|
+
url: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
90
|
+
})),
|
|
91
|
+
source: (0, superstruct_1.object)({
|
|
92
|
+
shasum: utils_1.ChecksumStruct,
|
|
93
|
+
location: (0, superstruct_1.object)({
|
|
94
|
+
npm: (0, superstruct_1.object)({
|
|
95
|
+
filePath: (0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity),
|
|
96
|
+
iconPath: (0, superstruct_1.optional)((0, superstruct_1.size)((0, superstruct_1.string)(), 1, Infinity)),
|
|
97
|
+
packageName: types_1.NameStruct,
|
|
98
|
+
registry: (0, superstruct_1.union)([
|
|
99
|
+
(0, superstruct_1.literal)('https://registry.npmjs.org'),
|
|
100
|
+
(0, superstruct_1.literal)('https://registry.npmjs.org/'),
|
|
101
|
+
]),
|
|
102
|
+
}),
|
|
103
|
+
}),
|
|
104
|
+
}),
|
|
105
|
+
initialPermissions: exports.PermissionsStruct,
|
|
106
|
+
manifestVersion: (0, superstruct_1.literal)('0.1'),
|
|
107
|
+
});
|
|
108
|
+
/**
|
|
109
|
+
* Check if the given value is a valid {@link SnapManifest} object.
|
|
110
|
+
*
|
|
111
|
+
* @param value - The value to check.
|
|
112
|
+
* @returns Whether the value is a valid {@link SnapManifest} object.
|
|
113
|
+
*/
|
|
114
|
+
function isSnapManifest(value) {
|
|
115
|
+
return (0, superstruct_1.is)(value, exports.SnapManifestStruct);
|
|
116
|
+
}
|
|
117
|
+
exports.isSnapManifest = isSnapManifest;
|
|
118
|
+
/**
|
|
119
|
+
* Assert that the given value is a valid {@link SnapManifest} object.
|
|
120
|
+
*
|
|
121
|
+
* @param value - The value to check.
|
|
122
|
+
* @throws If the value is not a valid {@link SnapManifest} object.
|
|
123
|
+
*/
|
|
124
|
+
function assertIsSnapManifest(value) {
|
|
125
|
+
(0, utils_1.assertStruct)(value, exports.SnapManifestStruct, `"${types_1.NpmSnapFileNames.Manifest}" is invalid`);
|
|
126
|
+
}
|
|
127
|
+
exports.assertIsSnapManifest = assertIsSnapManifest;
|
|
128
|
+
/**
|
|
129
|
+
* Creates a {@link SnapManifest} object from JSON.
|
|
130
|
+
*
|
|
131
|
+
*
|
|
132
|
+
* @param value - The value to check.
|
|
133
|
+
* @throws If the value cannot be coerced to a {@link SnapManifest} object.
|
|
134
|
+
* @returns The created {@link SnapManifest} object.
|
|
135
|
+
*/
|
|
136
|
+
function createSnapManifest(value) {
|
|
137
|
+
// TODO: Add a utility to prefix these errors similar to assertStruct
|
|
138
|
+
return (0, superstruct_1.create)(value, exports.SnapManifestStruct);
|
|
139
|
+
}
|
|
140
|
+
exports.createSnapManifest = createSnapManifest;
|
|
141
|
+
//# sourceMappingURL=validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.js","sourceRoot":"","sources":["../../src/manifest/validation.ts"],"names":[],"mappings":";;;AAAA,iDAA6D;AAC7D,2CAA8E;AAC9E,6CAkBqB;AAErB,oCAAmC;AACnC,wCAA6D;AAC7D,wCAA6E;AAC7E,0CAA+C;AAC/C,4CAAgD;AAChD,oCAAwD;AAExD,+EAA+E;AAC/E,gCAAgC;AAChC,MAAM,kBAAkB,GAAa;IACnC,2BAAiB;IACjB,sCAA4B;CAC7B,CAAC;AAEW,QAAA,oBAAoB,GAAa,CAAC,EAAE,CAAC,CAAC;AACnD,MAAM,eAAe,GAAe,4BAAoB,CAAC,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC;IACzE,GAAG;IACH,KAAK;IACL,GAAG,QAAQ,GAAG;CACf,CAAC,CAAC;AAEU,QAAA,eAAe,GAAG,IAAA,oBAAM,E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C,CACH;IACD,MAAM,EAAE,IAAA,oBAAM,EAAC;QACb,MAAM,EAAE,sBAAc;QACtB,QAAQ,EAAE,IAAA,oBAAM,EAAC;YACf,GAAG,EAAE,IAAA,oBAAM,EAAC;gBACV,QAAQ,EAAE,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,QAAQ,CAAC;gBACrC,QAAQ,EAAE,IAAA,sBAAQ,EAAC,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAC;gBAC/C,WAAW,EAAE,kBAAU;gBACvB,QAAQ,EAAE,IAAA,mBAAK,EAAC;oBACd,IAAA,qBAAO,EAAC,4BAA4B,CAAC;oBACrC,IAAA,qBAAO,EAAC,6BAA6B,CAAC;iBACvC,CAAC;aACH,CAAC;SACH,CAAC;KACH,CAAC;IACF,kBAAkB,EAAE,yBAAiB;IACrC,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;AAED;;;;;;;GAOG;AACH,SAAgB,kBAAkB,CAAC,KAAc;IAC/C,qEAAqE;IACrE,OAAO,IAAA,oBAAM,EAAC,KAAK,EAAE,0BAAkB,CAAC,CAAC;AAC3C,CAAC;AAHD,gDAGC","sourcesContent":["import { isValidBIP32PathSegment } from '@metamask/key-tree';\nimport { assertStruct, ChecksumStruct, VersionStruct } from '@metamask/utils';\nimport {\n array,\n boolean,\n create,\n enums,\n Infer,\n integer,\n is,\n literal,\n object,\n optional,\n pattern,\n refine,\n size,\n string,\n Struct,\n type,\n union,\n} from 'superstruct';\n\nimport { isEqual } from '../array';\nimport { CronjobSpecificationArrayStruct } from '../cronjob';\nimport { SIP_6_MAGIC_VALUE, STATE_ENCRYPTION_MAGIC_VALUE } from '../entropy';\nimport { RpcOriginsStruct } from '../json-rpc';\nimport { NamespacesStruct } from '../namespace';\nimport { NameStruct, NpmSnapFileNames } from '../types';\n\n// BIP-43 purposes that cannot be used for entropy derivation. These are in the\n// string form, ending with `'`.\nconst FORBIDDEN_PURPOSES: string[] = [\n SIP_6_MAGIC_VALUE,\n STATE_ENCRYPTION_MAGIC_VALUE,\n];\n\nexport const FORBIDDEN_COIN_TYPES: number[] = [60];\nconst FORBIDDEN_PATHS: string[][] = FORBIDDEN_COIN_TYPES.map((coinType) => [\n 'm',\n \"44'\",\n `${coinType}'`,\n]);\n\nexport const Bip32PathStruct = refine(\n array(string()),\n 'BIP-32 path',\n (path: string[]) => {\n if (path.length === 0) {\n return 'Path must be a non-empty BIP-32 derivation path array';\n }\n\n if (path[0] !== 'm') {\n return 'Path must start with \"m\".';\n }\n\n if (path.length < 3) {\n return 'Paths must have a length of at least three.';\n }\n\n if (path.slice(1).some((part) => !isValidBIP32PathSegment(part))) {\n return 'Path must be a valid BIP-32 derivation path array.';\n }\n\n if (FORBIDDEN_PURPOSES.includes(path[1])) {\n return `The purpose \"${path[1]}\" is not allowed for entropy derivation.`;\n }\n\n if (\n FORBIDDEN_PATHS.some((forbiddenPath) =>\n isEqual(path.slice(0, forbiddenPath.length), forbiddenPath),\n )\n ) {\n return `The path \"${path.join(\n '/',\n )}\" is not allowed for entropy derivation.`;\n }\n\n return true;\n },\n);\n\nexport const bip32entropy = <T extends { path: string[]; curve: string }, S>(\n struct: Struct<T, S>,\n) =>\n refine(struct, 'BIP-32 entropy', (value) => {\n if (\n value.curve === 'ed25519' &&\n value.path.slice(1).some((part) => !part.endsWith(\"'\"))\n ) {\n return 'Ed25519 does not support unhardened paths.';\n }\n\n return true;\n });\n\n// Used outside @metamask/snap-utils\nexport const Bip32EntropyStruct = bip32entropy(\n type({\n path: Bip32PathStruct,\n curve: enums(['ed25519', 'secp256k1']),\n }),\n);\n\nexport type Bip32Entropy = Infer<typeof Bip32EntropyStruct>;\n\nexport const SnapGetBip32EntropyPermissionsStruct = size(\n array(Bip32EntropyStruct),\n 1,\n Infinity,\n);\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const PermissionsStruct = type({\n 'endowment:long-running': optional(object({})),\n 'endowment:network-access': optional(object({})),\n 'endowment:webassembly': optional(object({})),\n 'endowment:transaction-insight': optional(\n object({\n allowTransactionOrigin: optional(boolean()),\n }),\n ),\n 'endowment:cronjob': optional(\n object({ jobs: CronjobSpecificationArrayStruct }),\n ),\n 'endowment:rpc': optional(RpcOriginsStruct),\n snap_dialog: optional(object({})),\n // TODO: Remove\n snap_confirm: optional(object({})),\n snap_manageState: optional(object({})),\n snap_notify: optional(object({})),\n snap_getBip32Entropy: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip32PublicKey: optional(SnapGetBip32EntropyPermissionsStruct),\n snap_getBip44Entropy: optional(\n size(\n array(object({ coinType: size(integer(), 0, 2 ** 32 - 1) })),\n 1,\n Infinity,\n ),\n ),\n snap_getEntropy: optional(object({})),\n 'endowment:keyring': optional(\n object({\n namespaces: NamespacesStruct,\n }),\n ),\n});\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport type SnapPermissions = Infer<typeof PermissionsStruct>;\n\nexport const SnapManifestStruct = object({\n version: VersionStruct,\n description: size(string(), 1, 280),\n proposedName: size(\n pattern(\n string(),\n /^(?:[A-Za-z0-9-_]+( [A-Za-z0-9-_]+)*)|(?:(?:@[A-Za-z0-9-*~][A-Za-z0-9-*._~]*\\/)?[A-Za-z0-9-~][A-Za-z0-9-._~]*)$/u,\n ),\n 1,\n 214,\n ),\n repository: optional(\n object({\n type: size(string(), 1, Infinity),\n url: size(string(), 1, Infinity),\n }),\n ),\n source: object({\n shasum: ChecksumStruct,\n location: object({\n npm: object({\n filePath: size(string(), 1, Infinity),\n iconPath: optional(size(string(), 1, Infinity)),\n packageName: NameStruct,\n registry: union([\n literal('https://registry.npmjs.org'),\n literal('https://registry.npmjs.org/'),\n ]),\n }),\n }),\n }),\n initialPermissions: PermissionsStruct,\n manifestVersion: literal('0.1'),\n});\n\nexport type SnapManifest = Infer<typeof SnapManifestStruct>;\n\n/**\n * Check if the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @returns Whether the value is a valid {@link SnapManifest} object.\n */\nexport function isSnapManifest(value: unknown): value is SnapManifest {\n return is(value, SnapManifestStruct);\n}\n\n/**\n * Assert that the given value is a valid {@link SnapManifest} object.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid {@link SnapManifest} object.\n */\nexport function assertIsSnapManifest(\n value: unknown,\n): asserts value is SnapManifest {\n assertStruct(\n value,\n SnapManifestStruct,\n `\"${NpmSnapFileNames.Manifest}\" is invalid`,\n );\n}\n\n/**\n * Creates a {@link SnapManifest} object from JSON.\n *\n *\n * @param value - The value to check.\n * @throws If the value cannot be coerced to a {@link SnapManifest} object.\n * @returns The created {@link SnapManifest} object.\n */\nexport function createSnapManifest(value: unknown): SnapManifest {\n // TODO: Add a utility to prefix these errors similar to assertStruct\n return create(value, SnapManifestStruct);\n}\n"]}
|
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
...NETWORK_APIS,
|
|
13
|
-
'WebAssembly'
|
|
14
|
-
];
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateMockEndowments = exports.isConstructor = exports.ALL_APIS = void 0;
|
|
7
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
8
|
+
const events_1 = __importDefault(require("events"));
|
|
9
|
+
const default_endowments_1 = require("./default-endowments");
|
|
10
|
+
const NETWORK_APIS = ['fetch'];
|
|
11
|
+
exports.ALL_APIS = [...default_endowments_1.DEFAULT_ENDOWMENTS, ...NETWORK_APIS];
|
|
15
12
|
/**
|
|
16
13
|
* Get a mock snap API, that always returns `true` for requests.
|
|
17
14
|
*
|
|
18
15
|
* @returns A mocked snap provider.
|
|
19
|
-
*/
|
|
16
|
+
*/
|
|
17
|
+
function getMockSnapGlobal() {
|
|
20
18
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
21
|
-
return {
|
|
22
|
-
request: async ()=>true
|
|
23
|
-
};
|
|
19
|
+
return { request: async () => true };
|
|
24
20
|
}
|
|
25
21
|
/**
|
|
26
22
|
* Get a mock Ethereum provider, that always returns `true` for requests.
|
|
27
23
|
*
|
|
28
24
|
* @returns A mocked ethereum provider.
|
|
29
|
-
*/
|
|
30
|
-
|
|
25
|
+
*/
|
|
26
|
+
function getMockEthereumProvider() {
|
|
27
|
+
const mockProvider = new events_1.default();
|
|
31
28
|
// eslint-disable-next-line @typescript-eslint/require-await
|
|
32
|
-
mockProvider.request = async ()=>true;
|
|
29
|
+
mockProvider.request = async () => true;
|
|
33
30
|
return mockProvider;
|
|
34
31
|
}
|
|
35
32
|
/**
|
|
@@ -37,22 +34,25 @@ export const ALL_APIS = [
|
|
|
37
34
|
*
|
|
38
35
|
* @param value - The value to check.
|
|
39
36
|
* @returns `true` if the value is a constructor, or `false` otherwise.
|
|
40
|
-
*/
|
|
37
|
+
*/
|
|
38
|
+
const isConstructor = (value) => Boolean(typeof value?.prototype?.constructor?.name === 'string');
|
|
39
|
+
exports.isConstructor = isConstructor;
|
|
41
40
|
/**
|
|
42
41
|
* A function that always returns `true`.
|
|
43
42
|
*
|
|
44
43
|
* @returns `true`.
|
|
45
|
-
*/
|
|
44
|
+
*/
|
|
45
|
+
const mockFunction = () => true;
|
|
46
46
|
class MockClass {
|
|
47
47
|
}
|
|
48
48
|
const handler = {
|
|
49
49
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
50
|
-
construct
|
|
50
|
+
construct(Target, args) {
|
|
51
51
|
return new Proxy(new Target(...args), handler);
|
|
52
52
|
},
|
|
53
|
-
get
|
|
53
|
+
get(_target, _prop) {
|
|
54
54
|
return mockFunction;
|
|
55
|
-
}
|
|
55
|
+
},
|
|
56
56
|
};
|
|
57
57
|
/**
|
|
58
58
|
* Generate a mock class for a given value. The value is wrapped in a Proxy, and
|
|
@@ -60,14 +60,15 @@ const handler = {
|
|
|
60
60
|
*
|
|
61
61
|
* @param value - The value to mock.
|
|
62
62
|
* @returns A mock class.
|
|
63
|
-
*/
|
|
63
|
+
*/
|
|
64
|
+
const generateMockClass = (value) => {
|
|
64
65
|
return new Proxy(value, handler);
|
|
65
66
|
};
|
|
66
67
|
// Things not currently auto-mocked because of NodeJS, by adding them here we
|
|
67
68
|
// have types for them and can use that to generate mocks if needed.
|
|
68
69
|
const mockWindow = {
|
|
69
|
-
crypto,
|
|
70
|
-
SubtleCrypto: MockClass
|
|
70
|
+
crypto: crypto_1.default,
|
|
71
|
+
SubtleCrypto: MockClass,
|
|
71
72
|
};
|
|
72
73
|
/**
|
|
73
74
|
* Generate a mock endowment for a certain class or function on the `globalThis`
|
|
@@ -76,19 +77,21 @@ const mockWindow = {
|
|
|
76
77
|
* @param key - The key to generate the mock endowment for.
|
|
77
78
|
* @returns A mocked class or function. If the key is part of the default
|
|
78
79
|
* endowments, the original value is returned.
|
|
79
|
-
*/
|
|
80
|
+
*/
|
|
81
|
+
const generateMockEndowment = (key) => {
|
|
80
82
|
const globalValue = globalThis[key];
|
|
81
83
|
// Default exposed APIs don't need to be mocked
|
|
82
|
-
if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {
|
|
84
|
+
if (globalValue && default_endowments_1.DEFAULT_ENDOWMENTS.includes(key)) {
|
|
83
85
|
return globalValue;
|
|
84
86
|
}
|
|
85
87
|
// Fall back to mockWindow for certain APIs not exposed in global in Node.JS
|
|
86
88
|
const globalOrMocked = globalValue ?? mockWindow[key];
|
|
87
89
|
const type = typeof globalOrMocked;
|
|
88
90
|
const isFunction = type === 'function';
|
|
89
|
-
if (isFunction && isConstructor(globalOrMocked)) {
|
|
91
|
+
if (isFunction && (0, exports.isConstructor)(globalOrMocked)) {
|
|
90
92
|
return generateMockClass(globalOrMocked);
|
|
91
|
-
}
|
|
93
|
+
}
|
|
94
|
+
else if (isFunction || !globalOrMocked) {
|
|
92
95
|
// Fall back to function mock for now
|
|
93
96
|
return mockFunction;
|
|
94
97
|
}
|
|
@@ -98,14 +101,9 @@ const mockWindow = {
|
|
|
98
101
|
* Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.
|
|
99
102
|
*
|
|
100
103
|
* @returns A map of endowments.
|
|
101
|
-
*/
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
[cur]: generateMockEndowment(cur)
|
|
105
|
-
}), {
|
|
106
|
-
snap: getMockSnapGlobal(),
|
|
107
|
-
ethereum: getMockEthereumProvider()
|
|
108
|
-
});
|
|
104
|
+
*/
|
|
105
|
+
const generateMockEndowments = () => {
|
|
106
|
+
return exports.ALL_APIS.reduce((acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }), { snap: getMockSnapGlobal(), ethereum: getMockEthereumProvider() });
|
|
109
107
|
};
|
|
110
|
-
|
|
108
|
+
exports.generateMockEndowments = generateMockEndowments;
|
|
111
109
|
//# sourceMappingURL=mock.js.map
|
package/dist/mock.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mock.js","sourceRoot":"","sources":["../src/mock.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAC5B,oDAAkC;AAElC,6DAA0D;AAE1D,MAAM,YAAY,GAAG,CAAC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AAEF;;;;;;;GAOG;AACH,MAAM,qBAAqB,GAAG,CAAC,GAAW,EAAE,EAAE;IAC5C,MAAM,WAAW,GAAI,UAAkB,CAAC,GAAG,CAAC,CAAC;IAE7C,+CAA+C;IAC/C,IAAI,WAAW,IAAI,uCAAkB,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;QACnD,OAAO,WAAW,CAAC;KACpB;IAED,4EAA4E;IAC5E,MAAM,cAAc,GAAG,WAAW,IAAI,UAAU,CAAC,GAAG,CAAC,CAAC;IAEtD,MAAM,IAAI,GAAG,OAAO,cAAc,CAAC;IACnC,MAAM,UAAU,GAAG,IAAI,KAAK,UAAU,CAAC;IACvC,IAAI,UAAU,IAAI,IAAA,qBAAa,EAAC,cAAc,CAAC,EAAE;QAC/C,OAAO,iBAAiB,CAAC,cAAc,CAAC,CAAC;KAC1C;SAAM,IAAI,UAAU,IAAI,CAAC,cAAc,EAAE;QACxC,qCAAqC;QACrC,OAAO,YAAY,CAAC;KACrB;IACD,OAAO,cAAc,CAAC;AACxB,CAAC,CAAC;AAEF;;;;GAIG;AACI,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACzC,OAAO,gBAAQ,CAAC,MAAM,CACpB,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,EAAE,qBAAqB,CAAC,GAAG,CAAC,EAAE,CAAC,EAC7D,EAAE,IAAI,EAAE,iBAAiB,EAAE,EAAE,QAAQ,EAAE,uBAAuB,EAAE,EAAE,CACnE,CAAC;AACJ,CAAC,CAAC;AALW,QAAA,sBAAsB,0BAKjC","sourcesContent":["import crypto from 'crypto';\nimport EventEmitter from 'events';\n\nimport { DEFAULT_ENDOWMENTS } from './default-endowments';\n\nconst NETWORK_APIS = ['fetch'];\n\nexport const ALL_APIS: string[] = [...DEFAULT_ENDOWMENTS, ...NETWORK_APIS];\n\ntype MockSnapGlobal = {\n request: () => Promise<any>;\n};\n\ntype MockEthereumProvider = EventEmitter & {\n request: () => Promise<any>;\n};\n\n/**\n * Get a mock snap API, that always returns `true` for requests.\n *\n * @returns A mocked snap provider.\n */\nfunction getMockSnapGlobal(): MockSnapGlobal {\n // eslint-disable-next-line @typescript-eslint/require-await\n return { request: async () => true };\n}\n\n/**\n * Get a mock Ethereum provider, that always returns `true` for requests.\n *\n * @returns A mocked ethereum provider.\n */\nfunction getMockEthereumProvider(): MockEthereumProvider {\n const mockProvider = new EventEmitter() as Partial<MockEthereumProvider>;\n // eslint-disable-next-line @typescript-eslint/require-await\n mockProvider.request = async () => true;\n return mockProvider as MockEthereumProvider;\n}\n\n/**\n * Check if a value is a constructor.\n *\n * @param value - The value to check.\n * @returns `true` if the value is a constructor, or `false` otherwise.\n */\nexport const isConstructor = (value: any) =>\n Boolean(typeof value?.prototype?.constructor?.name === 'string');\n\n/**\n * A function that always returns `true`.\n *\n * @returns `true`.\n */\nconst mockFunction = () => true;\nclass MockClass {}\n\nconst handler = {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n construct(Target: any, args: any[]): any {\n return new Proxy(new Target(...args), handler);\n },\n get(_target: any, _prop: any) {\n return mockFunction;\n },\n};\n\n/**\n * Generate a mock class for a given value. The value is wrapped in a Proxy, and\n * all methods are replaced with a mock function.\n *\n * @param value - The value to mock.\n * @returns A mock class.\n */\nconst generateMockClass = (value: any) => {\n return new Proxy(value, handler);\n};\n\n// Things not currently auto-mocked because of NodeJS, by adding them here we\n// have types for them and can use that to generate mocks if needed.\nconst mockWindow: Record<string, unknown> = {\n crypto,\n SubtleCrypto: MockClass,\n};\n\n/**\n * Generate a mock endowment for a certain class or function on the `globalThis`\n * object.\n *\n * @param key - The key to generate the mock endowment for.\n * @returns A mocked class or function. If the key is part of the default\n * endowments, the original value is returned.\n */\nconst generateMockEndowment = (key: string) => {\n const globalValue = (globalThis as any)[key];\n\n // Default exposed APIs don't need to be mocked\n if (globalValue && DEFAULT_ENDOWMENTS.includes(key)) {\n return globalValue;\n }\n\n // Fall back to mockWindow for certain APIs not exposed in global in Node.JS\n const globalOrMocked = globalValue ?? mockWindow[key];\n\n const type = typeof globalOrMocked;\n const isFunction = type === 'function';\n if (isFunction && isConstructor(globalOrMocked)) {\n return generateMockClass(globalOrMocked);\n } else if (isFunction || !globalOrMocked) {\n // Fall back to function mock for now\n return mockFunction;\n }\n return globalOrMocked;\n};\n\n/**\n * Generate mock endowments for all the APIs as defined in {@link ALL_APIS}.\n *\n * @returns A map of endowments.\n */\nexport const generateMockEndowments = () => {\n return ALL_APIS.reduce<Record<string, any>>(\n (acc, cur) => ({ ...acc, [cur]: generateMockEndowment(cur) }),\n { snap: getMockSnapGlobal(), ethereum: getMockEthereumProvider() },\n );\n};\n"]}
|