@metamask/snaps-utils 3.2.0 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +35 -1
- package/dist/cjs/auxiliary-files.js +6 -19
- package/dist/cjs/auxiliary-files.js.map +1 -1
- package/dist/cjs/checksum.js +22 -5
- package/dist/cjs/checksum.js.map +1 -1
- package/dist/cjs/cronjob.js.map +1 -1
- package/dist/cjs/enum.js.map +1 -1
- package/dist/cjs/errors.js +6 -154
- package/dist/cjs/errors.js.map +1 -1
- package/dist/cjs/handler-types.js +1 -0
- package/dist/cjs/handler-types.js.map +1 -1
- package/dist/cjs/handlers.js +17 -11
- package/dist/cjs/handlers.js.map +1 -1
- package/dist/cjs/index.browser.js +2 -0
- package/dist/cjs/index.browser.js.map +1 -1
- package/dist/cjs/index.js +2 -7
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/localization.js +113 -0
- package/dist/cjs/localization.js.map +1 -0
- package/dist/cjs/manifest/manifest.js +33 -19
- package/dist/cjs/manifest/manifest.js.map +1 -1
- package/dist/cjs/manifest/validation.js +3 -2
- package/dist/cjs/manifest/validation.js.map +1 -1
- package/dist/cjs/namespace.js +5 -1
- package/dist/cjs/namespace.js.map +1 -1
- package/dist/cjs/npm.js +18 -5
- package/dist/cjs/npm.js.map +1 -1
- package/dist/cjs/snaps.js +7 -6
- package/dist/cjs/snaps.js.map +1 -1
- package/dist/cjs/structs.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/cjs/ui.js +51 -0
- package/dist/cjs/ui.js.map +1 -0
- package/dist/cjs/validation.js +4 -2
- package/dist/cjs/validation.js.map +1 -1
- package/dist/esm/auxiliary-files.js +1 -6
- package/dist/esm/auxiliary-files.js.map +1 -1
- package/dist/esm/checksum.js +25 -6
- package/dist/esm/checksum.js.map +1 -1
- package/dist/esm/cronjob.js +1 -1
- package/dist/esm/cronjob.js.map +1 -1
- package/dist/esm/enum.js.map +1 -1
- package/dist/esm/errors.js +2 -157
- package/dist/esm/errors.js.map +1 -1
- package/dist/esm/handler-types.js +1 -0
- package/dist/esm/handler-types.js.map +1 -1
- package/dist/esm/handlers.js +13 -7
- package/dist/esm/handlers.js.map +1 -1
- package/dist/esm/index.browser.js +2 -0
- package/dist/esm/index.browser.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/localization.js +115 -0
- package/dist/esm/localization.js.map +1 -0
- package/dist/esm/manifest/manifest.js +37 -19
- package/dist/esm/manifest/manifest.js.map +1 -1
- package/dist/esm/manifest/validation.js +4 -3
- package/dist/esm/manifest/validation.js.map +1 -1
- package/dist/esm/namespace.js +3 -2
- package/dist/esm/namespace.js.map +1 -1
- package/dist/esm/npm.js +18 -5
- package/dist/esm/npm.js.map +1 -1
- package/dist/esm/snaps.js +7 -6
- package/dist/esm/snaps.js.map +1 -1
- package/dist/esm/structs.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/ui.js +48 -0
- package/dist/esm/ui.js.map +1 -0
- package/dist/esm/validation.js +4 -2
- package/dist/esm/validation.js.map +1 -1
- package/dist/types/auxiliary-files.d.ts +1 -5
- package/dist/types/checksum.d.ts +9 -2
- package/dist/types/enum.d.ts +1 -21
- package/dist/types/errors.d.ts +1 -109
- package/dist/types/handler-types.d.ts +2 -1
- package/dist/types/handlers.d.ts +73 -152
- package/dist/types/index.browser.d.ts +2 -0
- package/dist/types/index.d.ts +2 -1
- package/dist/types/localization.d.ts +143 -0
- package/dist/types/manifest/manifest.d.ts +16 -7
- package/dist/types/manifest/validation.d.ts +83 -78
- package/dist/types/namespace.d.ts +11 -10
- package/dist/types/npm.d.ts +1 -1
- package/dist/types/snaps.d.ts +13 -43
- package/dist/types/structs.d.ts +23 -0
- package/dist/types/types.d.ts +4 -2
- package/dist/types/ui.d.ts +20 -0
- package/dist/types/validation.d.ts +1 -1
- package/package.json +3 -3
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { InitialPermissions } from '@metamask/snaps-sdk';
|
|
1
2
|
import type { Infer, Struct } from 'superstruct';
|
|
3
|
+
import type { InferMatching } from '../structs';
|
|
2
4
|
export declare const FORBIDDEN_COIN_TYPES: number[];
|
|
3
5
|
export declare const Bip32PathStruct: Struct<string[], Struct<string, null>>;
|
|
4
6
|
export declare const bip32entropy: <Type extends {
|
|
@@ -34,8 +36,27 @@ export declare const SnapIdsStruct: Struct<Record<string, {
|
|
|
34
36
|
version?: string | undefined;
|
|
35
37
|
}>, null>;
|
|
36
38
|
export declare type SnapIds = Infer<typeof SnapIdsStruct>;
|
|
37
|
-
export declare const ChainIdsStruct: Struct
|
|
39
|
+
export declare const ChainIdsStruct: Struct<`${string}:${string}`[], Struct<`${string}:${string}`, null>>;
|
|
38
40
|
export declare const PermissionsStruct: Struct<{
|
|
41
|
+
snap_dialog?: {} | undefined;
|
|
42
|
+
snap_getBip32Entropy?: {
|
|
43
|
+
path: string[];
|
|
44
|
+
curve: "ed25519" | "secp256k1";
|
|
45
|
+
}[] | undefined;
|
|
46
|
+
snap_getBip32PublicKey?: {
|
|
47
|
+
path: string[];
|
|
48
|
+
curve: "ed25519" | "secp256k1";
|
|
49
|
+
}[] | undefined;
|
|
50
|
+
snap_getBip44Entropy?: {
|
|
51
|
+
coinType: number;
|
|
52
|
+
}[] | undefined;
|
|
53
|
+
snap_getEntropy?: {} | undefined;
|
|
54
|
+
snap_manageAccounts?: {} | undefined;
|
|
55
|
+
snap_manageState?: {} | undefined;
|
|
56
|
+
snap_notify?: {} | undefined;
|
|
57
|
+
wallet_snap?: Record<string, {
|
|
58
|
+
version?: string | undefined;
|
|
59
|
+
}> | undefined;
|
|
39
60
|
'endowment:network-access'?: {} | undefined;
|
|
40
61
|
'endowment:webassembly'?: {} | undefined;
|
|
41
62
|
'endowment:transaction-insight'?: {
|
|
@@ -45,7 +66,7 @@ export declare const PermissionsStruct: Struct<{
|
|
|
45
66
|
jobs: {
|
|
46
67
|
request: {
|
|
47
68
|
method: string;
|
|
48
|
-
params?: Record<string, import("@metamask/
|
|
69
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
49
70
|
id?: string | number | null | undefined;
|
|
50
71
|
jsonrpc?: "2.0" | undefined;
|
|
51
72
|
};
|
|
@@ -57,30 +78,11 @@ export declare const PermissionsStruct: Struct<{
|
|
|
57
78
|
snaps?: boolean | undefined;
|
|
58
79
|
allowedOrigins?: string[] | undefined;
|
|
59
80
|
} | undefined;
|
|
60
|
-
'endowment:name-lookup'?: string[] | undefined;
|
|
81
|
+
'endowment:name-lookup'?: `${string}:${string}`[] | undefined;
|
|
61
82
|
'endowment:keyring'?: {
|
|
62
83
|
allowedOrigins?: string[] | undefined;
|
|
63
84
|
} | undefined;
|
|
64
|
-
snap_dialog?: {} | undefined;
|
|
65
85
|
snap_confirm?: {} | undefined;
|
|
66
|
-
snap_manageState?: {} | undefined;
|
|
67
|
-
snap_manageAccounts?: {} | undefined;
|
|
68
|
-
snap_notify?: {} | undefined;
|
|
69
|
-
snap_getBip32Entropy?: {
|
|
70
|
-
path: string[];
|
|
71
|
-
curve: "ed25519" | "secp256k1";
|
|
72
|
-
}[] | undefined;
|
|
73
|
-
snap_getBip32PublicKey?: {
|
|
74
|
-
path: string[];
|
|
75
|
-
curve: "ed25519" | "secp256k1";
|
|
76
|
-
}[] | undefined;
|
|
77
|
-
snap_getBip44Entropy?: {
|
|
78
|
-
coinType: number;
|
|
79
|
-
}[] | undefined;
|
|
80
|
-
snap_getEntropy?: {} | undefined;
|
|
81
|
-
wallet_snap?: Record<string, {
|
|
82
|
-
version?: string | undefined;
|
|
83
|
-
}> | undefined;
|
|
84
86
|
}, {
|
|
85
87
|
'endowment:network-access': Struct<{} | undefined, {}>;
|
|
86
88
|
'endowment:webassembly': Struct<{} | undefined, {}>;
|
|
@@ -93,7 +95,7 @@ export declare const PermissionsStruct: Struct<{
|
|
|
93
95
|
jobs: {
|
|
94
96
|
request: {
|
|
95
97
|
method: string;
|
|
96
|
-
params?: Record<string, import("@metamask/
|
|
98
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
97
99
|
id?: string | number | null | undefined;
|
|
98
100
|
jsonrpc?: "2.0" | undefined;
|
|
99
101
|
};
|
|
@@ -103,7 +105,7 @@ export declare const PermissionsStruct: Struct<{
|
|
|
103
105
|
jobs: Struct<{
|
|
104
106
|
request: {
|
|
105
107
|
method: string;
|
|
106
|
-
params?: Record<string, import("@metamask/
|
|
108
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
107
109
|
id?: string | number | null | undefined;
|
|
108
110
|
jsonrpc?: "2.0" | undefined;
|
|
109
111
|
};
|
|
@@ -111,7 +113,7 @@ export declare const PermissionsStruct: Struct<{
|
|
|
111
113
|
}[], Struct<{
|
|
112
114
|
request: {
|
|
113
115
|
method: string;
|
|
114
|
-
params?: Record<string, import("@metamask/
|
|
116
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
115
117
|
id?: string | number | null | undefined;
|
|
116
118
|
jsonrpc?: "2.0" | undefined;
|
|
117
119
|
};
|
|
@@ -120,11 +122,11 @@ export declare const PermissionsStruct: Struct<{
|
|
|
120
122
|
expression: Struct<string, null>;
|
|
121
123
|
request: Struct<{
|
|
122
124
|
method: string;
|
|
123
|
-
params?: Record<string, import("@metamask/
|
|
125
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
124
126
|
id?: string | number | null | undefined;
|
|
125
127
|
jsonrpc?: "2.0" | undefined;
|
|
126
128
|
}, {
|
|
127
|
-
params: Struct<Record<string, import("@metamask/
|
|
129
|
+
params: Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
|
|
128
130
|
method: Struct<string, null>;
|
|
129
131
|
id: Struct<string | number | null | undefined, unknown>;
|
|
130
132
|
jsonrpc: Struct<"2.0" | undefined, unknown>;
|
|
@@ -140,7 +142,7 @@ export declare const PermissionsStruct: Struct<{
|
|
|
140
142
|
snaps: Struct<boolean | undefined, null>;
|
|
141
143
|
allowedOrigins: Struct<string[] | undefined, Struct<string, null>>;
|
|
142
144
|
}>;
|
|
143
|
-
'endowment:name-lookup': Struct
|
|
145
|
+
'endowment:name-lookup': Struct<`${string}:${string}`[] | undefined, Struct<`${string}:${string}`, null>>;
|
|
144
146
|
'endowment:keyring': Struct<{
|
|
145
147
|
allowedOrigins?: string[] | undefined;
|
|
146
148
|
} | undefined, {
|
|
@@ -189,10 +191,11 @@ export declare const PermissionsStruct: Struct<{
|
|
|
189
191
|
version?: string | undefined;
|
|
190
192
|
}> | undefined, null>;
|
|
191
193
|
}>;
|
|
192
|
-
export declare type SnapPermissions =
|
|
194
|
+
export declare type SnapPermissions = InferMatching<typeof PermissionsStruct, InitialPermissions>;
|
|
193
195
|
export declare const SnapAuxilaryFilesStruct: Struct<string[], Struct<string, null>>;
|
|
194
196
|
export declare const SnapManifestStruct: Struct<{
|
|
195
197
|
description: string;
|
|
198
|
+
version: import("@metamask/utils").SemVerVersion;
|
|
196
199
|
source: {
|
|
197
200
|
location: {
|
|
198
201
|
npm: {
|
|
@@ -204,10 +207,29 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
204
207
|
};
|
|
205
208
|
shasum: string;
|
|
206
209
|
files?: string[] | undefined;
|
|
210
|
+
locales?: string[] | undefined;
|
|
207
211
|
};
|
|
208
|
-
version: import("@metamask/utils").SemVerVersion;
|
|
209
212
|
proposedName: string;
|
|
210
213
|
initialPermissions: {
|
|
214
|
+
snap_dialog?: {} | undefined;
|
|
215
|
+
snap_getBip32Entropy?: {
|
|
216
|
+
path: string[];
|
|
217
|
+
curve: "ed25519" | "secp256k1";
|
|
218
|
+
}[] | undefined;
|
|
219
|
+
snap_getBip32PublicKey?: {
|
|
220
|
+
path: string[];
|
|
221
|
+
curve: "ed25519" | "secp256k1";
|
|
222
|
+
}[] | undefined;
|
|
223
|
+
snap_getBip44Entropy?: {
|
|
224
|
+
coinType: number;
|
|
225
|
+
}[] | undefined;
|
|
226
|
+
snap_getEntropy?: {} | undefined;
|
|
227
|
+
snap_manageAccounts?: {} | undefined;
|
|
228
|
+
snap_manageState?: {} | undefined;
|
|
229
|
+
snap_notify?: {} | undefined;
|
|
230
|
+
wallet_snap?: Record<string, {
|
|
231
|
+
version?: string | undefined;
|
|
232
|
+
}> | undefined;
|
|
211
233
|
'endowment:network-access'?: {} | undefined;
|
|
212
234
|
'endowment:webassembly'?: {} | undefined;
|
|
213
235
|
'endowment:transaction-insight'?: {
|
|
@@ -217,7 +239,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
217
239
|
jobs: {
|
|
218
240
|
request: {
|
|
219
241
|
method: string;
|
|
220
|
-
params?: Record<string, import("@metamask/
|
|
242
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
221
243
|
id?: string | number | null | undefined;
|
|
222
244
|
jsonrpc?: "2.0" | undefined;
|
|
223
245
|
};
|
|
@@ -229,30 +251,11 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
229
251
|
snaps?: boolean | undefined;
|
|
230
252
|
allowedOrigins?: string[] | undefined;
|
|
231
253
|
} | undefined;
|
|
232
|
-
'endowment:name-lookup'?: string[] | undefined;
|
|
254
|
+
'endowment:name-lookup'?: `${string}:${string}`[] | undefined;
|
|
233
255
|
'endowment:keyring'?: {
|
|
234
256
|
allowedOrigins?: string[] | undefined;
|
|
235
257
|
} | undefined;
|
|
236
|
-
snap_dialog?: {} | undefined;
|
|
237
258
|
snap_confirm?: {} | undefined;
|
|
238
|
-
snap_manageState?: {} | undefined;
|
|
239
|
-
snap_manageAccounts?: {} | undefined;
|
|
240
|
-
snap_notify?: {} | undefined;
|
|
241
|
-
snap_getBip32Entropy?: {
|
|
242
|
-
path: string[];
|
|
243
|
-
curve: "ed25519" | "secp256k1";
|
|
244
|
-
}[] | undefined;
|
|
245
|
-
snap_getBip32PublicKey?: {
|
|
246
|
-
path: string[];
|
|
247
|
-
curve: "ed25519" | "secp256k1";
|
|
248
|
-
}[] | undefined;
|
|
249
|
-
snap_getBip44Entropy?: {
|
|
250
|
-
coinType: number;
|
|
251
|
-
}[] | undefined;
|
|
252
|
-
snap_getEntropy?: {} | undefined;
|
|
253
|
-
wallet_snap?: Record<string, {
|
|
254
|
-
version?: string | undefined;
|
|
255
|
-
}> | undefined;
|
|
256
259
|
};
|
|
257
260
|
manifestVersion: "0.1";
|
|
258
261
|
repository?: {
|
|
@@ -282,6 +285,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
282
285
|
};
|
|
283
286
|
shasum: string;
|
|
284
287
|
files?: string[] | undefined;
|
|
288
|
+
locales?: string[] | undefined;
|
|
285
289
|
}, {
|
|
286
290
|
shasum: Struct<string, null>;
|
|
287
291
|
location: Struct<{
|
|
@@ -305,8 +309,28 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
305
309
|
}>;
|
|
306
310
|
}>;
|
|
307
311
|
files: Struct<string[] | undefined, Struct<string, null>>;
|
|
312
|
+
locales: Struct<string[] | undefined, Struct<string, null>>;
|
|
308
313
|
}>;
|
|
309
314
|
initialPermissions: Struct<{
|
|
315
|
+
snap_dialog?: {} | undefined;
|
|
316
|
+
snap_getBip32Entropy?: {
|
|
317
|
+
path: string[];
|
|
318
|
+
curve: "ed25519" | "secp256k1";
|
|
319
|
+
}[] | undefined;
|
|
320
|
+
snap_getBip32PublicKey?: {
|
|
321
|
+
path: string[];
|
|
322
|
+
curve: "ed25519" | "secp256k1";
|
|
323
|
+
}[] | undefined;
|
|
324
|
+
snap_getBip44Entropy?: {
|
|
325
|
+
coinType: number;
|
|
326
|
+
}[] | undefined;
|
|
327
|
+
snap_getEntropy?: {} | undefined;
|
|
328
|
+
snap_manageAccounts?: {} | undefined;
|
|
329
|
+
snap_manageState?: {} | undefined;
|
|
330
|
+
snap_notify?: {} | undefined;
|
|
331
|
+
wallet_snap?: Record<string, {
|
|
332
|
+
version?: string | undefined;
|
|
333
|
+
}> | undefined;
|
|
310
334
|
'endowment:network-access'?: {} | undefined;
|
|
311
335
|
'endowment:webassembly'?: {} | undefined;
|
|
312
336
|
'endowment:transaction-insight'?: {
|
|
@@ -316,7 +340,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
316
340
|
jobs: {
|
|
317
341
|
request: {
|
|
318
342
|
method: string;
|
|
319
|
-
params?: Record<string, import("@metamask/
|
|
343
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
320
344
|
id?: string | number | null | undefined;
|
|
321
345
|
jsonrpc?: "2.0" | undefined;
|
|
322
346
|
};
|
|
@@ -328,30 +352,11 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
328
352
|
snaps?: boolean | undefined;
|
|
329
353
|
allowedOrigins?: string[] | undefined;
|
|
330
354
|
} | undefined;
|
|
331
|
-
'endowment:name-lookup'?: string[] | undefined;
|
|
355
|
+
'endowment:name-lookup'?: `${string}:${string}`[] | undefined;
|
|
332
356
|
'endowment:keyring'?: {
|
|
333
357
|
allowedOrigins?: string[] | undefined;
|
|
334
358
|
} | undefined;
|
|
335
|
-
snap_dialog?: {} | undefined;
|
|
336
359
|
snap_confirm?: {} | undefined;
|
|
337
|
-
snap_manageState?: {} | undefined;
|
|
338
|
-
snap_manageAccounts?: {} | undefined;
|
|
339
|
-
snap_notify?: {} | undefined;
|
|
340
|
-
snap_getBip32Entropy?: {
|
|
341
|
-
path: string[];
|
|
342
|
-
curve: "ed25519" | "secp256k1";
|
|
343
|
-
}[] | undefined;
|
|
344
|
-
snap_getBip32PublicKey?: {
|
|
345
|
-
path: string[];
|
|
346
|
-
curve: "ed25519" | "secp256k1";
|
|
347
|
-
}[] | undefined;
|
|
348
|
-
snap_getBip44Entropy?: {
|
|
349
|
-
coinType: number;
|
|
350
|
-
}[] | undefined;
|
|
351
|
-
snap_getEntropy?: {} | undefined;
|
|
352
|
-
wallet_snap?: Record<string, {
|
|
353
|
-
version?: string | undefined;
|
|
354
|
-
}> | undefined;
|
|
355
360
|
}, {
|
|
356
361
|
'endowment:network-access': Struct<{} | undefined, {}>;
|
|
357
362
|
'endowment:webassembly': Struct<{} | undefined, {}>;
|
|
@@ -364,7 +369,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
364
369
|
jobs: {
|
|
365
370
|
request: {
|
|
366
371
|
method: string;
|
|
367
|
-
params?: Record<string, import("@metamask/
|
|
372
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
368
373
|
id?: string | number | null | undefined;
|
|
369
374
|
jsonrpc?: "2.0" | undefined;
|
|
370
375
|
};
|
|
@@ -374,7 +379,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
374
379
|
jobs: Struct<{
|
|
375
380
|
request: {
|
|
376
381
|
method: string;
|
|
377
|
-
params?: Record<string, import("@metamask/
|
|
382
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
378
383
|
id?: string | number | null | undefined;
|
|
379
384
|
jsonrpc?: "2.0" | undefined;
|
|
380
385
|
};
|
|
@@ -382,7 +387,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
382
387
|
}[], Struct<{
|
|
383
388
|
request: {
|
|
384
389
|
method: string;
|
|
385
|
-
params?: Record<string, import("@metamask/
|
|
390
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
386
391
|
id?: string | number | null | undefined;
|
|
387
392
|
jsonrpc?: "2.0" | undefined;
|
|
388
393
|
};
|
|
@@ -391,11 +396,11 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
391
396
|
expression: Struct<string, null>;
|
|
392
397
|
request: Struct<{
|
|
393
398
|
method: string;
|
|
394
|
-
params?: Record<string, import("@metamask/
|
|
399
|
+
params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
|
|
395
400
|
id?: string | number | null | undefined;
|
|
396
401
|
jsonrpc?: "2.0" | undefined;
|
|
397
402
|
}, {
|
|
398
|
-
params: Struct<Record<string, import("@metamask/
|
|
403
|
+
params: Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
|
|
399
404
|
method: Struct<string, null>;
|
|
400
405
|
id: Struct<string | number | null | undefined, unknown>;
|
|
401
406
|
jsonrpc: Struct<"2.0" | undefined, unknown>;
|
|
@@ -411,7 +416,7 @@ export declare const SnapManifestStruct: Struct<{
|
|
|
411
416
|
snaps: Struct<boolean | undefined, null>;
|
|
412
417
|
allowedOrigins: Struct<string[] | undefined, Struct<string, null>>;
|
|
413
418
|
}>;
|
|
414
|
-
'endowment:name-lookup': Struct
|
|
419
|
+
'endowment:name-lookup': Struct<`${string}:${string}`[] | undefined, Struct<`${string}:${string}`, null>>;
|
|
415
420
|
'endowment:keyring': Struct<{
|
|
416
421
|
allowedOrigins?: string[] | undefined;
|
|
417
422
|
} | undefined, {
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import type { AccountId, ChainId } from '@metamask/snaps-sdk';
|
|
1
2
|
import type { Infer } from 'superstruct';
|
|
3
|
+
import type { InferMatching } from './structs';
|
|
2
4
|
export declare const CHAIN_ID_REGEX: RegExp;
|
|
3
5
|
export declare const ACCOUNT_ID_REGEX: RegExp;
|
|
4
6
|
export declare const ACCOUNT_ADDRESS_REGEX: RegExp;
|
|
@@ -33,14 +35,13 @@ export declare function parseAccountId(accountId: AccountId): {
|
|
|
33
35
|
* of 40.
|
|
34
36
|
*/
|
|
35
37
|
export declare const LimitedString: import("superstruct").Struct<string, null>;
|
|
38
|
+
export declare const ChainIdStringStruct: import("superstruct").Struct<`${string}:${string}`, null>;
|
|
36
39
|
/**
|
|
37
40
|
* A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
|
|
38
41
|
*/
|
|
39
|
-
export declare const ChainIdStruct: import("superstruct").Struct
|
|
40
|
-
export declare type
|
|
41
|
-
export declare type Caip2ChainId = Infer<typeof ChainIdStruct>;
|
|
42
|
+
export declare const ChainIdStruct: import("superstruct").Struct<`${string}:${string}`, null>;
|
|
43
|
+
export declare type Caip2ChainId = InferMatching<typeof ChainIdStruct, ChainId>;
|
|
42
44
|
export declare const AccountIdStruct: import("superstruct").Struct<string, null>;
|
|
43
|
-
export declare type AccountId = `${ChainId}:${string}`;
|
|
44
45
|
export declare const AccountIdArrayStruct: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
|
|
45
46
|
export declare const AccountAddressStruct: import("superstruct").Struct<string, null>;
|
|
46
47
|
export declare type AccountAddress = Infer<typeof AccountAddressStruct>;
|
|
@@ -49,16 +50,16 @@ export declare type AccountAddress = Infer<typeof AccountAddressStruct>;
|
|
|
49
50
|
*/
|
|
50
51
|
export declare const ChainStruct: import("superstruct").Struct<{
|
|
51
52
|
name: string;
|
|
52
|
-
id: string
|
|
53
|
+
id: `${string}:${string}`;
|
|
53
54
|
}, {
|
|
54
|
-
id: import("superstruct").Struct
|
|
55
|
+
id: import("superstruct").Struct<`${string}:${string}`, null>;
|
|
55
56
|
name: import("superstruct").Struct<string, null>;
|
|
56
57
|
}>;
|
|
57
58
|
export declare type Chain = Infer<typeof ChainStruct>;
|
|
58
59
|
export declare const NamespaceStruct: import("superstruct").Struct<{
|
|
59
60
|
chains: {
|
|
60
61
|
name: string;
|
|
61
|
-
id: string
|
|
62
|
+
id: `${string}:${string}`;
|
|
62
63
|
}[];
|
|
63
64
|
methods?: string[] | undefined;
|
|
64
65
|
events?: string[] | undefined;
|
|
@@ -68,12 +69,12 @@ export declare const NamespaceStruct: import("superstruct").Struct<{
|
|
|
68
69
|
*/
|
|
69
70
|
chains: import("superstruct").Struct<{
|
|
70
71
|
name: string;
|
|
71
|
-
id: string
|
|
72
|
+
id: `${string}:${string}`;
|
|
72
73
|
}[], import("superstruct").Struct<{
|
|
73
74
|
name: string;
|
|
74
|
-
id: string
|
|
75
|
+
id: `${string}:${string}`;
|
|
75
76
|
}, {
|
|
76
|
-
id: import("superstruct").Struct
|
|
77
|
+
id: import("superstruct").Struct<`${string}:${string}`, null>;
|
|
77
78
|
name: import("superstruct").Struct<string, null>;
|
|
78
79
|
}>>;
|
|
79
80
|
/**
|
package/dist/types/npm.d.ts
CHANGED
|
@@ -16,4 +16,4 @@ export declare const SnapFileNameFromKey: {
|
|
|
16
16
|
* @param errorPrefix - The prefix of the error message.
|
|
17
17
|
* @returns A tuple of the Snap manifest object and the Snap source code.
|
|
18
18
|
*/
|
|
19
|
-
export declare function validateNpmSnap(snapFiles: UnvalidatedSnapFiles, errorPrefix?: `${string}: `): SnapFiles
|
|
19
|
+
export declare function validateNpmSnap(snapFiles: UnvalidatedSnapFiles, errorPrefix?: `${string}: `): Promise<SnapFiles>;
|
package/dist/types/snaps.d.ts
CHANGED
|
@@ -1,19 +1,12 @@
|
|
|
1
1
|
import type { SubjectPermissions, PermissionConstraint } from '@metamask/permission-controller';
|
|
2
2
|
import type { BlockReason } from '@metamask/snaps-registry';
|
|
3
|
-
import type {
|
|
3
|
+
import type { SnapId, Snap as TruncatedSnap } from '@metamask/snaps-sdk';
|
|
4
4
|
import type { Struct } from 'superstruct';
|
|
5
|
+
import type { LocalizationFile } from './localization';
|
|
5
6
|
import type { SnapManifest, SnapPermissions } from './manifest/validation';
|
|
6
|
-
import type { FetchedSnapFiles,
|
|
7
|
+
import type { FetchedSnapFiles, SnapsPermissionRequest } from './types';
|
|
7
8
|
import { SnapIdPrefixes, SnapValidationFailureReason } from './types';
|
|
8
9
|
export declare const PROPOSED_NAME_REGEX: RegExp;
|
|
9
|
-
/**
|
|
10
|
-
* wallet_enable / wallet_installSnaps permission typing.
|
|
11
|
-
*
|
|
12
|
-
* @deprecated This type is confusing and not descriptive, people confused it with typing initialPermissions, remove when removing wallet_enable.
|
|
13
|
-
*/
|
|
14
|
-
export declare type RequestedSnapPermissions = {
|
|
15
|
-
[permission: string]: Record<string, Json>;
|
|
16
|
-
};
|
|
17
10
|
export declare enum SnapStatus {
|
|
18
11
|
Installing = "installing",
|
|
19
12
|
Updating = "updating",
|
|
@@ -28,7 +21,7 @@ export declare enum SnapStatusEvents {
|
|
|
28
21
|
Update = "UPDATE"
|
|
29
22
|
}
|
|
30
23
|
export declare type StatusContext = {
|
|
31
|
-
snapId:
|
|
24
|
+
snapId: SnapId;
|
|
32
25
|
};
|
|
33
26
|
export declare type StatusEvents = {
|
|
34
27
|
type: SnapStatusEvents;
|
|
@@ -51,15 +44,7 @@ export declare type PersistedSnap = Snap;
|
|
|
51
44
|
/**
|
|
52
45
|
* A Snap as it exists in {@link SnapController} state.
|
|
53
46
|
*/
|
|
54
|
-
export declare type Snap = {
|
|
55
|
-
/**
|
|
56
|
-
* Whether the Snap is enabled, which determines if it can be started.
|
|
57
|
-
*/
|
|
58
|
-
enabled: boolean;
|
|
59
|
-
/**
|
|
60
|
-
* The ID of the Snap.
|
|
61
|
-
*/
|
|
62
|
-
id: ValidatedSnapId;
|
|
47
|
+
export declare type Snap = TruncatedSnap & {
|
|
63
48
|
/**
|
|
64
49
|
* The initial permissions of the Snap, which will be requested when it is
|
|
65
50
|
* installed.
|
|
@@ -73,10 +58,6 @@ export declare type Snap = {
|
|
|
73
58
|
* The Snap's manifest file.
|
|
74
59
|
*/
|
|
75
60
|
manifest: SnapManifest;
|
|
76
|
-
/**
|
|
77
|
-
* Whether the Snap is blocked.
|
|
78
|
-
*/
|
|
79
|
-
blocked: boolean;
|
|
80
61
|
/**
|
|
81
62
|
* Information detailing why the snap is blocked.
|
|
82
63
|
*/
|
|
@@ -85,10 +66,6 @@ export declare type Snap = {
|
|
|
85
66
|
* The current status of the Snap, e.g. whether it's running or stopped.
|
|
86
67
|
*/
|
|
87
68
|
status: Status;
|
|
88
|
-
/**
|
|
89
|
-
* The version of the Snap.
|
|
90
|
-
*/
|
|
91
|
-
version: SemVerVersion;
|
|
92
69
|
/**
|
|
93
70
|
* The version history of the Snap.
|
|
94
71
|
* Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.
|
|
@@ -98,17 +75,12 @@ export declare type Snap = {
|
|
|
98
75
|
* Static auxiliary files that can be loaded at runtime.
|
|
99
76
|
*/
|
|
100
77
|
auxiliaryFiles?: SnapAuxilaryFile[];
|
|
78
|
+
/**
|
|
79
|
+
* Localization files which are used to translate the manifest.
|
|
80
|
+
*/
|
|
81
|
+
localizationFiles?: LocalizationFile[];
|
|
101
82
|
};
|
|
102
83
|
export declare type TruncatedSnapFields = 'id' | 'initialPermissions' | 'version' | 'enabled' | 'blocked';
|
|
103
|
-
/**
|
|
104
|
-
* A {@link Snap} object with the fields that are relevant to an external
|
|
105
|
-
* caller.
|
|
106
|
-
*/
|
|
107
|
-
export declare type TruncatedSnap = Pick<Snap, TruncatedSnapFields>;
|
|
108
|
-
export declare type ProcessSnapResult = TruncatedSnap | {
|
|
109
|
-
error: JsonRpcError;
|
|
110
|
-
};
|
|
111
|
-
export declare type InstallSnapsResult = Record<SnapId, ProcessSnapResult>;
|
|
112
84
|
/**
|
|
113
85
|
* An error indicating that a Snap validation failure is programmatically
|
|
114
86
|
* fixable during development.
|
|
@@ -123,7 +95,7 @@ export declare class ProgrammaticallyFixableSnapError extends Error {
|
|
|
123
95
|
* @param files - All required Snap files to be included in the checksum.
|
|
124
96
|
* @returns The Base64-encoded SHA-256 digest of the source code.
|
|
125
97
|
*/
|
|
126
|
-
export declare function getSnapChecksum(files: FetchedSnapFiles): string
|
|
98
|
+
export declare function getSnapChecksum(files: FetchedSnapFiles): Promise<string>;
|
|
127
99
|
/**
|
|
128
100
|
* Checks whether the `source.shasum` property of a Snap manifest matches the
|
|
129
101
|
* shasum of the snap.
|
|
@@ -131,15 +103,13 @@ export declare function getSnapChecksum(files: FetchedSnapFiles): string;
|
|
|
131
103
|
* @param files - All required Snap files to be included in the checksum.
|
|
132
104
|
* @param errorMessage - The error message to throw if validation fails.
|
|
133
105
|
*/
|
|
134
|
-
export declare function validateSnapShasum(files: FetchedSnapFiles, errorMessage?: string): void
|
|
106
|
+
export declare function validateSnapShasum(files: FetchedSnapFiles, errorMessage?: string): Promise<void>;
|
|
135
107
|
export declare const LOCALHOST_HOSTNAMES: readonly ["localhost", "127.0.0.1", "[::1]"];
|
|
136
108
|
export declare const BaseSnapIdStruct: Struct<string, null>;
|
|
137
109
|
export declare const LocalSnapIdStruct: Struct<string, null>;
|
|
138
110
|
export declare const NpmSnapIdStruct: Struct<string, null>;
|
|
139
111
|
export declare const HttpSnapIdStruct: Struct<string, null>;
|
|
140
112
|
export declare const SnapIdStruct: Struct<string, null>;
|
|
141
|
-
export declare type ValidatedSnapId = Opaque<string, typeof snapIdSymbol>;
|
|
142
|
-
declare const snapIdSymbol: unique symbol;
|
|
143
113
|
/**
|
|
144
114
|
* Extracts the snap prefix from a snap ID.
|
|
145
115
|
*
|
|
@@ -160,7 +130,7 @@ export declare function stripSnapPrefix(snapId: string): string;
|
|
|
160
130
|
* @param value - The value to check.
|
|
161
131
|
* @throws If the value is not a valid snap ID.
|
|
162
132
|
*/
|
|
163
|
-
export declare function assertIsValidSnapId(value: unknown): asserts value is
|
|
133
|
+
export declare function assertIsValidSnapId(value: unknown): asserts value is SnapId;
|
|
164
134
|
/**
|
|
165
135
|
* Typeguard to ensure a chainId follows the CAIP-2 standard.
|
|
166
136
|
*
|
|
@@ -184,4 +154,4 @@ export declare function isSnapPermitted(permissions: SubjectPermissions<Permissi
|
|
|
184
154
|
* @throws If the criteria is not met.
|
|
185
155
|
*/
|
|
186
156
|
export declare function verifyRequestedSnapPermissions(requestedPermissions: unknown): asserts requestedPermissions is SnapsPermissionRequest;
|
|
187
|
-
export {};
|
|
157
|
+
export type { Snap as TruncatedSnap } from '@metamask/snaps-sdk';
|
package/dist/types/structs.d.ts
CHANGED
|
@@ -1,6 +1,29 @@
|
|
|
1
1
|
import type { Failure, Infer } from 'superstruct';
|
|
2
2
|
import { Struct, StructError } from 'superstruct';
|
|
3
3
|
import type { AnyStruct, InferStructTuple } from 'superstruct/dist/utils';
|
|
4
|
+
/**
|
|
5
|
+
* Infer a struct type, only if it matches the specified type. This is useful
|
|
6
|
+
* for defining types and structs that are related to each other in separate
|
|
7
|
+
* files.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```typescript
|
|
11
|
+
* // In file A
|
|
12
|
+
* export type GetFileArgs = {
|
|
13
|
+
* path: string;
|
|
14
|
+
* encoding?: EnumToUnion<AuxiliaryFileEncoding>;
|
|
15
|
+
* };
|
|
16
|
+
*
|
|
17
|
+
* // In file B
|
|
18
|
+
* export const GetFileArgsStruct = object(...);
|
|
19
|
+
*
|
|
20
|
+
* // If the type and struct are in the same file, this will return the type.
|
|
21
|
+
* // Otherwise, it will return `never`.
|
|
22
|
+
* export type GetFileArgs =
|
|
23
|
+
* InferMatching<typeof GetFileArgsStruct, GetFileArgs>;
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export declare type InferMatching<StructType extends Struct<any, any>, Type> = StructType['TYPE'] extends Type ? Type : never;
|
|
4
27
|
/**
|
|
5
28
|
* A wrapper of `superstruct`'s `literal` struct that also defines the name of
|
|
6
29
|
* the struct as the literal value.
|
package/dist/types/types.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Json } from '@metamask/utils';
|
|
|
2
2
|
import type { Infer, Struct } from 'superstruct';
|
|
3
3
|
import type { SnapCaveatType } from './caveats';
|
|
4
4
|
import type { SnapFunctionExports, SnapRpcHookArgs } from './handlers';
|
|
5
|
+
import type { LocalizationFile } from './localization';
|
|
5
6
|
import type { SnapManifest } from './manifest';
|
|
6
7
|
import type { VirtualFile } from './virtual-file';
|
|
7
8
|
export declare enum NpmSnapFileNames {
|
|
@@ -53,6 +54,7 @@ export declare type UnvalidatedSnapFiles = {
|
|
|
53
54
|
sourceCode?: VirtualFile;
|
|
54
55
|
svgIcon?: VirtualFile;
|
|
55
56
|
auxiliaryFiles: VirtualFile[];
|
|
57
|
+
localizationFiles: VirtualFile[];
|
|
56
58
|
};
|
|
57
59
|
/**
|
|
58
60
|
* An object for storing the contents of Snap files that have passed JSON
|
|
@@ -64,11 +66,12 @@ export declare type SnapFiles = {
|
|
|
64
66
|
sourceCode: VirtualFile;
|
|
65
67
|
svgIcon?: VirtualFile;
|
|
66
68
|
auxiliaryFiles: VirtualFile[];
|
|
69
|
+
localizationFiles: VirtualFile<LocalizationFile>[];
|
|
67
70
|
};
|
|
68
71
|
/**
|
|
69
72
|
* A subset of snap files extracted from a fetched snap.
|
|
70
73
|
*/
|
|
71
|
-
export declare type FetchedSnapFiles = Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles'>;
|
|
74
|
+
export declare type FetchedSnapFiles = Pick<SnapFiles, 'manifest' | 'sourceCode' | 'svgIcon' | 'auxiliaryFiles' | 'localizationFiles'>;
|
|
72
75
|
/**
|
|
73
76
|
* The possible prefixes for snap ids.
|
|
74
77
|
*/
|
|
@@ -76,7 +79,6 @@ export declare enum SnapIdPrefixes {
|
|
|
76
79
|
npm = "npm:",
|
|
77
80
|
local = "local:"
|
|
78
81
|
}
|
|
79
|
-
export declare type SnapId = string;
|
|
80
82
|
/**
|
|
81
83
|
* Snap validation failure reason codes that are programmatically fixable
|
|
82
84
|
* if validation occurs during development.
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Component } from '@metamask/snaps-sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Search for links in a sting and check them against the phishing list.
|
|
4
|
+
*
|
|
5
|
+
* @param text - The text to verify.
|
|
6
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
7
|
+
* phishing list.
|
|
8
|
+
* @throws If the text contains a link that is not allowed.
|
|
9
|
+
*/
|
|
10
|
+
export declare function validateTextLinks(text: string, isOnPhishingList: (url: string) => boolean): void;
|
|
11
|
+
/**
|
|
12
|
+
* Search for links in UI components and check that the URL they are trying to
|
|
13
|
+
* pass in is not in the phishing list.
|
|
14
|
+
*
|
|
15
|
+
* @param component - The custom UI component.
|
|
16
|
+
* @param isOnPhishingList - The function that checks the link against the
|
|
17
|
+
* phishing list.
|
|
18
|
+
* @throws If the component contains a link that is not allowed.
|
|
19
|
+
*/
|
|
20
|
+
export declare function validateComponentLinks(component: Component, isOnPhishingList: (url: string) => boolean): void;
|
|
@@ -5,4 +5,4 @@ import type { FetchedSnapFiles } from './types';
|
|
|
5
5
|
* @param files - All potentially included files in a fetched snap.
|
|
6
6
|
* @throws If any of the files are considered invalid.
|
|
7
7
|
*/
|
|
8
|
-
export declare function validateFetchedSnap(files: FetchedSnapFiles): void
|
|
8
|
+
export declare function validateFetchedSnap(files: FetchedSnapFiles): Promise<void>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/MetaMask/snaps.git"
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"@metamask/permission-controller": "^5.0.0",
|
|
73
73
|
"@metamask/rpc-errors": "^6.1.0",
|
|
74
74
|
"@metamask/snaps-registry": "^2.1.0",
|
|
75
|
-
"@metamask/snaps-
|
|
75
|
+
"@metamask/snaps-sdk": "^1.0.0",
|
|
76
76
|
"@metamask/utils": "^8.1.0",
|
|
77
77
|
"@noble/hashes": "^1.3.1",
|
|
78
78
|
"@scure/base": "^1.1.1",
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
|
92
92
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
93
93
|
"@lavamoat/allow-scripts": "^2.5.1",
|
|
94
|
-
"@metamask/auto-changelog": "^3.3
|
|
94
|
+
"@metamask/auto-changelog": "^3.4.3",
|
|
95
95
|
"@metamask/eslint-config": "^12.1.0",
|
|
96
96
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
97
97
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|