@metamask/snaps-utils 3.3.0 → 4.0.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.
Files changed (82) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/dist/cjs/auxiliary-files.js +6 -19
  3. package/dist/cjs/auxiliary-files.js.map +1 -1
  4. package/dist/cjs/checksum.js +22 -5
  5. package/dist/cjs/checksum.js.map +1 -1
  6. package/dist/cjs/cronjob.js.map +1 -1
  7. package/dist/cjs/enum.js.map +1 -1
  8. package/dist/cjs/errors.js +6 -154
  9. package/dist/cjs/errors.js.map +1 -1
  10. package/dist/cjs/handlers.js +6 -13
  11. package/dist/cjs/handlers.js.map +1 -1
  12. package/dist/cjs/index.browser.js +1 -0
  13. package/dist/cjs/index.browser.js.map +1 -1
  14. package/dist/cjs/index.js +1 -0
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/localization.js +2 -2
  17. package/dist/cjs/localization.js.map +1 -1
  18. package/dist/cjs/manifest/manifest.js +11 -11
  19. package/dist/cjs/manifest/manifest.js.map +1 -1
  20. package/dist/cjs/manifest/validation.js.map +1 -1
  21. package/dist/cjs/namespace.js +5 -1
  22. package/dist/cjs/namespace.js.map +1 -1
  23. package/dist/cjs/npm.js +2 -2
  24. package/dist/cjs/npm.js.map +1 -1
  25. package/dist/cjs/snaps.js +7 -6
  26. package/dist/cjs/snaps.js.map +1 -1
  27. package/dist/cjs/structs.js.map +1 -1
  28. package/dist/cjs/types.js.map +1 -1
  29. package/dist/cjs/ui.js +53 -0
  30. package/dist/cjs/ui.js.map +1 -0
  31. package/dist/cjs/validation.js +2 -2
  32. package/dist/cjs/validation.js.map +1 -1
  33. package/dist/esm/auxiliary-files.js +1 -6
  34. package/dist/esm/auxiliary-files.js.map +1 -1
  35. package/dist/esm/checksum.js +25 -6
  36. package/dist/esm/checksum.js.map +1 -1
  37. package/dist/esm/cronjob.js +1 -1
  38. package/dist/esm/cronjob.js.map +1 -1
  39. package/dist/esm/enum.js.map +1 -1
  40. package/dist/esm/errors.js +2 -157
  41. package/dist/esm/errors.js.map +1 -1
  42. package/dist/esm/handlers.js +4 -8
  43. package/dist/esm/handlers.js.map +1 -1
  44. package/dist/esm/index.browser.js +1 -0
  45. package/dist/esm/index.browser.js.map +1 -1
  46. package/dist/esm/index.js +1 -0
  47. package/dist/esm/index.js.map +1 -1
  48. package/dist/esm/localization.js +1 -1
  49. package/dist/esm/localization.js.map +1 -1
  50. package/dist/esm/manifest/manifest.js +8 -8
  51. package/dist/esm/manifest/manifest.js.map +1 -1
  52. package/dist/esm/manifest/validation.js.map +1 -1
  53. package/dist/esm/namespace.js +3 -2
  54. package/dist/esm/namespace.js.map +1 -1
  55. package/dist/esm/npm.js +2 -2
  56. package/dist/esm/npm.js.map +1 -1
  57. package/dist/esm/snaps.js +7 -6
  58. package/dist/esm/snaps.js.map +1 -1
  59. package/dist/esm/structs.js.map +1 -1
  60. package/dist/esm/types.js.map +1 -1
  61. package/dist/esm/ui.js +50 -0
  62. package/dist/esm/ui.js.map +1 -0
  63. package/dist/esm/validation.js +2 -2
  64. package/dist/esm/validation.js.map +1 -1
  65. package/dist/types/auxiliary-files.d.ts +1 -5
  66. package/dist/types/checksum.d.ts +9 -2
  67. package/dist/types/enum.d.ts +1 -21
  68. package/dist/types/errors.d.ts +1 -109
  69. package/dist/types/handlers.d.ts +48 -173
  70. package/dist/types/index.browser.d.ts +1 -0
  71. package/dist/types/index.d.ts +1 -0
  72. package/dist/types/localization.d.ts +22 -22
  73. package/dist/types/manifest/manifest.d.ts +2 -2
  74. package/dist/types/manifest/validation.d.ts +80 -78
  75. package/dist/types/namespace.d.ts +11 -10
  76. package/dist/types/npm.d.ts +1 -1
  77. package/dist/types/snaps.d.ts +8 -43
  78. package/dist/types/structs.d.ts +23 -0
  79. package/dist/types/types.d.ts +0 -1
  80. package/dist/types/ui.d.ts +20 -0
  81. package/dist/types/validation.d.ts +1 -1
  82. 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<string[], Struct<string, null>>;
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/utils").Json> | import("@metamask/utils").Json[] | undefined;
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/utils").Json> | import("@metamask/utils").Json[] | undefined;
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/utils").Json> | import("@metamask/utils").Json[] | undefined;
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/utils").Json> | import("@metamask/utils").Json[] | undefined;
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/utils").Json> | import("@metamask/utils").Json[] | undefined;
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/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
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<string[] | undefined, Struct<string, null>>;
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 = Infer<typeof PermissionsStruct>;
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: {
@@ -206,9 +209,27 @@ export declare const SnapManifestStruct: Struct<{
206
209
  files?: string[] | undefined;
207
210
  locales?: string[] | undefined;
208
211
  };
209
- version: import("@metamask/utils").SemVerVersion;
210
212
  proposedName: string;
211
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;
212
233
  'endowment:network-access'?: {} | undefined;
213
234
  'endowment:webassembly'?: {} | undefined;
214
235
  'endowment:transaction-insight'?: {
@@ -218,7 +239,7 @@ export declare const SnapManifestStruct: Struct<{
218
239
  jobs: {
219
240
  request: {
220
241
  method: string;
221
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
242
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
222
243
  id?: string | number | null | undefined;
223
244
  jsonrpc?: "2.0" | undefined;
224
245
  };
@@ -230,30 +251,11 @@ export declare const SnapManifestStruct: Struct<{
230
251
  snaps?: boolean | undefined;
231
252
  allowedOrigins?: string[] | undefined;
232
253
  } | undefined;
233
- 'endowment:name-lookup'?: string[] | undefined;
254
+ 'endowment:name-lookup'?: `${string}:${string}`[] | undefined;
234
255
  'endowment:keyring'?: {
235
256
  allowedOrigins?: string[] | undefined;
236
257
  } | undefined;
237
- snap_dialog?: {} | undefined;
238
258
  snap_confirm?: {} | undefined;
239
- snap_manageState?: {} | undefined;
240
- snap_manageAccounts?: {} | undefined;
241
- snap_notify?: {} | undefined;
242
- snap_getBip32Entropy?: {
243
- path: string[];
244
- curve: "ed25519" | "secp256k1";
245
- }[] | undefined;
246
- snap_getBip32PublicKey?: {
247
- path: string[];
248
- curve: "ed25519" | "secp256k1";
249
- }[] | undefined;
250
- snap_getBip44Entropy?: {
251
- coinType: number;
252
- }[] | undefined;
253
- snap_getEntropy?: {} | undefined;
254
- wallet_snap?: Record<string, {
255
- version?: string | undefined;
256
- }> | undefined;
257
259
  };
258
260
  manifestVersion: "0.1";
259
261
  repository?: {
@@ -310,6 +312,25 @@ export declare const SnapManifestStruct: Struct<{
310
312
  locales: Struct<string[] | undefined, Struct<string, null>>;
311
313
  }>;
312
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;
313
334
  'endowment:network-access'?: {} | undefined;
314
335
  'endowment:webassembly'?: {} | undefined;
315
336
  'endowment:transaction-insight'?: {
@@ -319,7 +340,7 @@ export declare const SnapManifestStruct: Struct<{
319
340
  jobs: {
320
341
  request: {
321
342
  method: string;
322
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
343
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
323
344
  id?: string | number | null | undefined;
324
345
  jsonrpc?: "2.0" | undefined;
325
346
  };
@@ -331,30 +352,11 @@ export declare const SnapManifestStruct: Struct<{
331
352
  snaps?: boolean | undefined;
332
353
  allowedOrigins?: string[] | undefined;
333
354
  } | undefined;
334
- 'endowment:name-lookup'?: string[] | undefined;
355
+ 'endowment:name-lookup'?: `${string}:${string}`[] | undefined;
335
356
  'endowment:keyring'?: {
336
357
  allowedOrigins?: string[] | undefined;
337
358
  } | undefined;
338
- snap_dialog?: {} | undefined;
339
359
  snap_confirm?: {} | undefined;
340
- snap_manageState?: {} | undefined;
341
- snap_manageAccounts?: {} | undefined;
342
- snap_notify?: {} | undefined;
343
- snap_getBip32Entropy?: {
344
- path: string[];
345
- curve: "ed25519" | "secp256k1";
346
- }[] | undefined;
347
- snap_getBip32PublicKey?: {
348
- path: string[];
349
- curve: "ed25519" | "secp256k1";
350
- }[] | undefined;
351
- snap_getBip44Entropy?: {
352
- coinType: number;
353
- }[] | undefined;
354
- snap_getEntropy?: {} | undefined;
355
- wallet_snap?: Record<string, {
356
- version?: string | undefined;
357
- }> | undefined;
358
360
  }, {
359
361
  'endowment:network-access': Struct<{} | undefined, {}>;
360
362
  'endowment:webassembly': Struct<{} | undefined, {}>;
@@ -367,7 +369,7 @@ export declare const SnapManifestStruct: Struct<{
367
369
  jobs: {
368
370
  request: {
369
371
  method: string;
370
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
372
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
371
373
  id?: string | number | null | undefined;
372
374
  jsonrpc?: "2.0" | undefined;
373
375
  };
@@ -377,7 +379,7 @@ export declare const SnapManifestStruct: Struct<{
377
379
  jobs: Struct<{
378
380
  request: {
379
381
  method: string;
380
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
382
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
381
383
  id?: string | number | null | undefined;
382
384
  jsonrpc?: "2.0" | undefined;
383
385
  };
@@ -385,7 +387,7 @@ export declare const SnapManifestStruct: Struct<{
385
387
  }[], Struct<{
386
388
  request: {
387
389
  method: string;
388
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
390
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
389
391
  id?: string | number | null | undefined;
390
392
  jsonrpc?: "2.0" | undefined;
391
393
  };
@@ -394,11 +396,11 @@ export declare const SnapManifestStruct: Struct<{
394
396
  expression: Struct<string, null>;
395
397
  request: Struct<{
396
398
  method: string;
397
- params?: Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined;
399
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
398
400
  id?: string | number | null | undefined;
399
401
  jsonrpc?: "2.0" | undefined;
400
402
  }, {
401
- params: Struct<Record<string, import("@metamask/utils").Json> | import("@metamask/utils").Json[] | undefined, null>;
403
+ params: Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
402
404
  method: Struct<string, null>;
403
405
  id: Struct<string | number | null | undefined, unknown>;
404
406
  jsonrpc: Struct<"2.0" | undefined, unknown>;
@@ -414,7 +416,7 @@ export declare const SnapManifestStruct: Struct<{
414
416
  snaps: Struct<boolean | undefined, null>;
415
417
  allowedOrigins: Struct<string[] | undefined, Struct<string, null>>;
416
418
  }>;
417
- 'endowment:name-lookup': Struct<string[] | undefined, Struct<string, null>>;
419
+ 'endowment:name-lookup': Struct<`${string}:${string}`[] | undefined, Struct<`${string}:${string}`, null>>;
418
420
  'endowment:keyring': Struct<{
419
421
  allowedOrigins?: string[] | undefined;
420
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<string, null>;
40
- export declare type ChainId = `${string}:${string}`;
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<string, null>;
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<string, null>;
77
+ id: import("superstruct").Struct<`${string}:${string}`, null>;
77
78
  name: import("superstruct").Struct<string, null>;
78
79
  }>>;
79
80
  /**
@@ -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>;
@@ -1,20 +1,12 @@
1
1
  import type { SubjectPermissions, PermissionConstraint } from '@metamask/permission-controller';
2
2
  import type { BlockReason } from '@metamask/snaps-registry';
3
- import type { Json, JsonRpcError, Opaque, SemVerVersion } from '@metamask/utils';
3
+ import type { SnapId, Snap as TruncatedSnap } from '@metamask/snaps-sdk';
4
4
  import type { Struct } from 'superstruct';
5
5
  import type { LocalizationFile } from './localization';
6
6
  import type { SnapManifest, SnapPermissions } from './manifest/validation';
7
- import type { FetchedSnapFiles, SnapId, SnapsPermissionRequest } from './types';
7
+ import type { FetchedSnapFiles, SnapsPermissionRequest } from './types';
8
8
  import { SnapIdPrefixes, SnapValidationFailureReason } from './types';
9
9
  export declare const PROPOSED_NAME_REGEX: RegExp;
10
- /**
11
- * wallet_enable / wallet_installSnaps permission typing.
12
- *
13
- * @deprecated This type is confusing and not descriptive, people confused it with typing initialPermissions, remove when removing wallet_enable.
14
- */
15
- export declare type RequestedSnapPermissions = {
16
- [permission: string]: Record<string, Json>;
17
- };
18
10
  export declare enum SnapStatus {
19
11
  Installing = "installing",
20
12
  Updating = "updating",
@@ -29,7 +21,7 @@ export declare enum SnapStatusEvents {
29
21
  Update = "UPDATE"
30
22
  }
31
23
  export declare type StatusContext = {
32
- snapId: ValidatedSnapId;
24
+ snapId: SnapId;
33
25
  };
34
26
  export declare type StatusEvents = {
35
27
  type: SnapStatusEvents;
@@ -52,15 +44,7 @@ export declare type PersistedSnap = Snap;
52
44
  /**
53
45
  * A Snap as it exists in {@link SnapController} state.
54
46
  */
55
- export declare type Snap = {
56
- /**
57
- * Whether the Snap is enabled, which determines if it can be started.
58
- */
59
- enabled: boolean;
60
- /**
61
- * The ID of the Snap.
62
- */
63
- id: ValidatedSnapId;
47
+ export declare type Snap = TruncatedSnap & {
64
48
  /**
65
49
  * The initial permissions of the Snap, which will be requested when it is
66
50
  * installed.
@@ -74,10 +58,6 @@ export declare type Snap = {
74
58
  * The Snap's manifest file.
75
59
  */
76
60
  manifest: SnapManifest;
77
- /**
78
- * Whether the Snap is blocked.
79
- */
80
- blocked: boolean;
81
61
  /**
82
62
  * Information detailing why the snap is blocked.
83
63
  */
@@ -86,10 +66,6 @@ export declare type Snap = {
86
66
  * The current status of the Snap, e.g. whether it's running or stopped.
87
67
  */
88
68
  status: Status;
89
- /**
90
- * The version of the Snap.
91
- */
92
- version: SemVerVersion;
93
69
  /**
94
70
  * The version history of the Snap.
95
71
  * Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.
@@ -105,15 +81,6 @@ export declare type Snap = {
105
81
  localizationFiles?: LocalizationFile[];
106
82
  };
107
83
  export declare type TruncatedSnapFields = 'id' | 'initialPermissions' | 'version' | 'enabled' | 'blocked';
108
- /**
109
- * A {@link Snap} object with the fields that are relevant to an external
110
- * caller.
111
- */
112
- export declare type TruncatedSnap = Pick<Snap, TruncatedSnapFields>;
113
- export declare type ProcessSnapResult = TruncatedSnap | {
114
- error: JsonRpcError;
115
- };
116
- export declare type InstallSnapsResult = Record<SnapId, ProcessSnapResult>;
117
84
  /**
118
85
  * An error indicating that a Snap validation failure is programmatically
119
86
  * fixable during development.
@@ -128,7 +95,7 @@ export declare class ProgrammaticallyFixableSnapError extends Error {
128
95
  * @param files - All required Snap files to be included in the checksum.
129
96
  * @returns The Base64-encoded SHA-256 digest of the source code.
130
97
  */
131
- export declare function getSnapChecksum(files: FetchedSnapFiles): string;
98
+ export declare function getSnapChecksum(files: FetchedSnapFiles): Promise<string>;
132
99
  /**
133
100
  * Checks whether the `source.shasum` property of a Snap manifest matches the
134
101
  * shasum of the snap.
@@ -136,15 +103,13 @@ export declare function getSnapChecksum(files: FetchedSnapFiles): string;
136
103
  * @param files - All required Snap files to be included in the checksum.
137
104
  * @param errorMessage - The error message to throw if validation fails.
138
105
  */
139
- export declare function validateSnapShasum(files: FetchedSnapFiles, errorMessage?: string): void;
106
+ export declare function validateSnapShasum(files: FetchedSnapFiles, errorMessage?: string): Promise<void>;
140
107
  export declare const LOCALHOST_HOSTNAMES: readonly ["localhost", "127.0.0.1", "[::1]"];
141
108
  export declare const BaseSnapIdStruct: Struct<string, null>;
142
109
  export declare const LocalSnapIdStruct: Struct<string, null>;
143
110
  export declare const NpmSnapIdStruct: Struct<string, null>;
144
111
  export declare const HttpSnapIdStruct: Struct<string, null>;
145
112
  export declare const SnapIdStruct: Struct<string, null>;
146
- export declare type ValidatedSnapId = Opaque<string, typeof snapIdSymbol>;
147
- declare const snapIdSymbol: unique symbol;
148
113
  /**
149
114
  * Extracts the snap prefix from a snap ID.
150
115
  *
@@ -165,7 +130,7 @@ export declare function stripSnapPrefix(snapId: string): string;
165
130
  * @param value - The value to check.
166
131
  * @throws If the value is not a valid snap ID.
167
132
  */
168
- export declare function assertIsValidSnapId(value: unknown): asserts value is ValidatedSnapId;
133
+ export declare function assertIsValidSnapId(value: unknown): asserts value is SnapId;
169
134
  /**
170
135
  * Typeguard to ensure a chainId follows the CAIP-2 standard.
171
136
  *
@@ -189,4 +154,4 @@ export declare function isSnapPermitted(permissions: SubjectPermissions<Permissi
189
154
  * @throws If the criteria is not met.
190
155
  */
191
156
  export declare function verifyRequestedSnapPermissions(requestedPermissions: unknown): asserts requestedPermissions is SnapsPermissionRequest;
192
- export {};
157
+ export type { Snap as TruncatedSnap } from '@metamask/snaps-sdk';
@@ -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.
@@ -79,7 +79,6 @@ export declare enum SnapIdPrefixes {
79
79
  npm = "npm:",
80
80
  local = "local:"
81
81
  }
82
- export declare type SnapId = string;
83
82
  /**
84
83
  * Snap validation failure reason codes that are programmatically fixable
85
84
  * if validation occurs during development.
@@ -0,0 +1,20 @@
1
+ import type { Component } from '@metamask/snaps-sdk';
2
+ /**
3
+ * Searches for markdown links in a string and checks 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.3.0",
3
+ "version": "4.0.1",
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-ui": "^3.1.0",
75
+ "@metamask/snaps-sdk": "^1.1.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.0",
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",