@metamask/snaps-utils 7.0.4 → 7.1.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +9 -1
  2. package/dist/{chunk-2IWSQJKQ.mjs → chunk-2M6G46W6.mjs} +1 -1
  3. package/dist/chunk-2M6G46W6.mjs.map +1 -0
  4. package/dist/{chunk-HKJDVWVO.js → chunk-7EDRFEUH.js} +11 -11
  5. package/dist/{chunk-LTWLSRSR.js → chunk-E5WSD47S.js} +3 -3
  6. package/dist/{chunk-RQVVWCOW.mjs → chunk-E6U344HR.mjs} +3 -3
  7. package/dist/{chunk-6F2DZTGM.mjs → chunk-HTS6HGUU.mjs} +2 -2
  8. package/dist/{chunk-TG4BDSYJ.js → chunk-HVTYDKBO.js} +1 -1
  9. package/dist/chunk-HVTYDKBO.js.map +1 -0
  10. package/dist/{chunk-HDZ3BJBL.mjs → chunk-KP4ZAWMP.mjs} +8 -4
  11. package/dist/chunk-KP4ZAWMP.mjs.map +1 -0
  12. package/dist/{chunk-OK2Q2GT7.js → chunk-MKTAIEG7.js} +5 -5
  13. package/dist/{chunk-EX4PPLND.js → chunk-NDIITWO4.js} +7 -3
  14. package/dist/chunk-NDIITWO4.js.map +1 -0
  15. package/dist/{chunk-QX6MAFJU.mjs → chunk-PBXAWRWW.mjs} +6 -1
  16. package/dist/chunk-PBXAWRWW.mjs.map +1 -0
  17. package/dist/{chunk-2PCPD5XY.js → chunk-XNUUUOKX.js} +6 -1
  18. package/dist/chunk-XNUUUOKX.js.map +1 -0
  19. package/dist/{chunk-ZO24JBZA.mjs → chunk-YP3ZXUME.mjs} +3 -3
  20. package/dist/derivation-paths.js +2 -2
  21. package/dist/derivation-paths.mjs +1 -1
  22. package/dist/index.js +8 -6
  23. package/dist/index.mjs +7 -5
  24. package/dist/manifest/index.js +3 -3
  25. package/dist/manifest/index.mjs +2 -2
  26. package/dist/manifest/manifest.js +4 -4
  27. package/dist/manifest/manifest.mjs +3 -3
  28. package/dist/manifest/node.js +4 -4
  29. package/dist/manifest/node.mjs +3 -3
  30. package/dist/manifest/validation.js +3 -3
  31. package/dist/manifest/validation.mjs +2 -2
  32. package/dist/node.js +9 -7
  33. package/dist/node.mjs +8 -6
  34. package/dist/npm.js +4 -4
  35. package/dist/npm.mjs +3 -3
  36. package/dist/snaps.js +2 -2
  37. package/dist/snaps.mjs +1 -1
  38. package/dist/tsconfig.build.tsbuildinfo +1 -1
  39. package/dist/types/handlers.d.ts +87 -87
  40. package/dist/types/snaps.d.ts +5 -1
  41. package/dist/types/ui.d.ts +8 -1
  42. package/dist/ui.js +4 -2
  43. package/dist/ui.mjs +3 -1
  44. package/dist/validation.js +4 -4
  45. package/dist/validation.mjs +3 -3
  46. package/package.json +3 -3
  47. package/dist/chunk-2IWSQJKQ.mjs.map +0 -1
  48. package/dist/chunk-2PCPD5XY.js.map +0 -1
  49. package/dist/chunk-EX4PPLND.js.map +0 -1
  50. package/dist/chunk-HDZ3BJBL.mjs.map +0 -1
  51. package/dist/chunk-QX6MAFJU.mjs.map +0 -1
  52. package/dist/chunk-TG4BDSYJ.js.map +0 -1
  53. /package/dist/{chunk-HKJDVWVO.js.map → chunk-7EDRFEUH.js.map} +0 -0
  54. /package/dist/{chunk-LTWLSRSR.js.map → chunk-E5WSD47S.js.map} +0 -0
  55. /package/dist/{chunk-RQVVWCOW.mjs.map → chunk-E6U344HR.mjs.map} +0 -0
  56. /package/dist/{chunk-6F2DZTGM.mjs.map → chunk-HTS6HGUU.mjs.map} +0 -0
  57. /package/dist/{chunk-OK2Q2GT7.js.map → chunk-MKTAIEG7.js.map} +0 -0
  58. /package/dist/{chunk-ZO24JBZA.mjs.map → chunk-YP3ZXUME.mjs.map} +0 -0
@@ -73,6 +73,38 @@ export declare const OnTransactionResponseWithIdStruct: import("superstruct").St
73
73
  }>;
74
74
  export declare const OnTransactionResponseWithContentStruct: import("superstruct").Struct<{
75
75
  content: import("@metamask/snaps-sdk").Panel | {
76
+ type: import("@metamask/snaps-sdk").NodeType.Input;
77
+ name: string;
78
+ value?: string | undefined;
79
+ error?: string | undefined;
80
+ inputType?: "number" | "text" | "password" | undefined;
81
+ placeholder?: string | undefined;
82
+ label?: string | undefined;
83
+ } | {
84
+ value: string;
85
+ type: import("@metamask/snaps-sdk").NodeType.Button;
86
+ name?: string | undefined;
87
+ variant?: "primary" | "secondary" | undefined;
88
+ buttonType?: "button" | "submit" | undefined;
89
+ } | {
90
+ type: import("@metamask/snaps-sdk").NodeType.Form;
91
+ name: string;
92
+ children: ({
93
+ type: import("@metamask/snaps-sdk").NodeType.Input;
94
+ name: string;
95
+ value?: string | undefined;
96
+ error?: string | undefined;
97
+ inputType?: "number" | "text" | "password" | undefined;
98
+ placeholder?: string | undefined;
99
+ label?: string | undefined;
100
+ } | {
101
+ value: string;
102
+ type: import("@metamask/snaps-sdk").NodeType.Button;
103
+ name?: string | undefined;
104
+ variant?: "primary" | "secondary" | undefined;
105
+ buttonType?: "button" | "submit" | undefined;
106
+ })[];
107
+ } | {
76
108
  value: string;
77
109
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
78
110
  sensitive?: boolean | undefined;
@@ -108,14 +140,17 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
108
140
  type: import("@metamask/snaps-sdk").NodeType.Row;
109
141
  label: string;
110
142
  variant?: "default" | "warning" | "critical" | undefined;
111
- } | {
143
+ };
144
+ severity?: SeverityLevel | undefined;
145
+ }, {
146
+ content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
112
147
  type: import("@metamask/snaps-sdk").NodeType.Input;
113
148
  name: string;
114
149
  value?: string | undefined;
115
150
  error?: string | undefined;
116
- label?: string | undefined;
117
151
  inputType?: "number" | "text" | "password" | undefined;
118
152
  placeholder?: string | undefined;
153
+ label?: string | undefined;
119
154
  } | {
120
155
  value: string;
121
156
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -130,9 +165,9 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
130
165
  name: string;
131
166
  value?: string | undefined;
132
167
  error?: string | undefined;
133
- label?: string | undefined;
134
168
  inputType?: "number" | "text" | "password" | undefined;
135
169
  placeholder?: string | undefined;
170
+ label?: string | undefined;
136
171
  } | {
137
172
  value: string;
138
173
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -140,10 +175,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
140
175
  variant?: "primary" | "secondary" | undefined;
141
176
  buttonType?: "button" | "submit" | undefined;
142
177
  })[];
143
- };
144
- severity?: SeverityLevel | undefined;
145
- }, {
146
- content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
178
+ } | {
147
179
  value: string;
148
180
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
149
181
  sensitive?: boolean | undefined;
@@ -179,14 +211,21 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
179
211
  type: import("@metamask/snaps-sdk").NodeType.Row;
180
212
  label: string;
181
213
  variant?: "default" | "warning" | "critical" | undefined;
182
- } | {
214
+ }, null>;
215
+ severity: import("superstruct").Struct<SeverityLevel | undefined, SeverityLevel>;
216
+ }>;
217
+ export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
218
+ id: string;
219
+ severity?: SeverityLevel | undefined;
220
+ } | {
221
+ content: import("@metamask/snaps-sdk").Panel | {
183
222
  type: import("@metamask/snaps-sdk").NodeType.Input;
184
223
  name: string;
185
224
  value?: string | undefined;
186
225
  error?: string | undefined;
187
- label?: string | undefined;
188
226
  inputType?: "number" | "text" | "password" | undefined;
189
227
  placeholder?: string | undefined;
228
+ label?: string | undefined;
190
229
  } | {
191
230
  value: string;
192
231
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -201,9 +240,9 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
201
240
  name: string;
202
241
  value?: string | undefined;
203
242
  error?: string | undefined;
204
- label?: string | undefined;
205
243
  inputType?: "number" | "text" | "password" | undefined;
206
244
  placeholder?: string | undefined;
245
+ label?: string | undefined;
207
246
  } | {
208
247
  value: string;
209
248
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -211,14 +250,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
211
250
  variant?: "primary" | "secondary" | undefined;
212
251
  buttonType?: "button" | "submit" | undefined;
213
252
  })[];
214
- }, null>;
215
- severity: import("superstruct").Struct<SeverityLevel | undefined, SeverityLevel>;
216
- }>;
217
- export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
218
- id: string;
219
- severity?: SeverityLevel | undefined;
220
- } | {
221
- content: import("@metamask/snaps-sdk").Panel | {
253
+ } | {
222
254
  value: string;
223
255
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
224
256
  sensitive?: boolean | undefined;
@@ -254,14 +286,21 @@ export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
254
286
  type: import("@metamask/snaps-sdk").NodeType.Row;
255
287
  label: string;
256
288
  variant?: "default" | "warning" | "critical" | undefined;
257
- } | {
289
+ };
290
+ severity?: SeverityLevel | undefined;
291
+ } | null, null>;
292
+ export declare const OnSignatureResponseStruct: import("superstruct").Struct<{
293
+ id: string;
294
+ severity?: SeverityLevel | undefined;
295
+ } | {
296
+ content: import("@metamask/snaps-sdk").Panel | {
258
297
  type: import("@metamask/snaps-sdk").NodeType.Input;
259
298
  name: string;
260
299
  value?: string | undefined;
261
300
  error?: string | undefined;
262
- label?: string | undefined;
263
301
  inputType?: "number" | "text" | "password" | undefined;
264
302
  placeholder?: string | undefined;
303
+ label?: string | undefined;
265
304
  } | {
266
305
  value: string;
267
306
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -276,9 +315,9 @@ export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
276
315
  name: string;
277
316
  value?: string | undefined;
278
317
  error?: string | undefined;
279
- label?: string | undefined;
280
318
  inputType?: "number" | "text" | "password" | undefined;
281
319
  placeholder?: string | undefined;
320
+ label?: string | undefined;
282
321
  } | {
283
322
  value: string;
284
323
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -286,14 +325,7 @@ export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
286
325
  variant?: "primary" | "secondary" | undefined;
287
326
  buttonType?: "button" | "submit" | undefined;
288
327
  })[];
289
- };
290
- severity?: SeverityLevel | undefined;
291
- } | null, null>;
292
- export declare const OnSignatureResponseStruct: import("superstruct").Struct<{
293
- id: string;
294
- severity?: SeverityLevel | undefined;
295
- } | {
296
- content: import("@metamask/snaps-sdk").Panel | {
328
+ } | {
297
329
  value: string;
298
330
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
299
331
  sensitive?: boolean | undefined;
@@ -329,14 +361,18 @@ export declare const OnSignatureResponseStruct: import("superstruct").Struct<{
329
361
  type: import("@metamask/snaps-sdk").NodeType.Row;
330
362
  label: string;
331
363
  variant?: "default" | "warning" | "critical" | undefined;
332
- } | {
364
+ };
365
+ severity?: SeverityLevel | undefined;
366
+ } | null, null>;
367
+ export declare const OnHomePageResponseWithContentStruct: import("superstruct").Struct<{
368
+ content: import("@metamask/snaps-sdk").Panel | {
333
369
  type: import("@metamask/snaps-sdk").NodeType.Input;
334
370
  name: string;
335
371
  value?: string | undefined;
336
372
  error?: string | undefined;
337
- label?: string | undefined;
338
373
  inputType?: "number" | "text" | "password" | undefined;
339
374
  placeholder?: string | undefined;
375
+ label?: string | undefined;
340
376
  } | {
341
377
  value: string;
342
378
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -351,9 +387,9 @@ export declare const OnSignatureResponseStruct: import("superstruct").Struct<{
351
387
  name: string;
352
388
  value?: string | undefined;
353
389
  error?: string | undefined;
354
- label?: string | undefined;
355
390
  inputType?: "number" | "text" | "password" | undefined;
356
391
  placeholder?: string | undefined;
392
+ label?: string | undefined;
357
393
  } | {
358
394
  value: string;
359
395
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -361,11 +397,7 @@ export declare const OnSignatureResponseStruct: import("superstruct").Struct<{
361
397
  variant?: "primary" | "secondary" | undefined;
362
398
  buttonType?: "button" | "submit" | undefined;
363
399
  })[];
364
- };
365
- severity?: SeverityLevel | undefined;
366
- } | null, null>;
367
- export declare const OnHomePageResponseWithContentStruct: import("superstruct").Struct<{
368
- content: import("@metamask/snaps-sdk").Panel | {
400
+ } | {
369
401
  value: string;
370
402
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
371
403
  sensitive?: boolean | undefined;
@@ -401,14 +433,16 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
401
433
  type: import("@metamask/snaps-sdk").NodeType.Row;
402
434
  label: string;
403
435
  variant?: "default" | "warning" | "critical" | undefined;
404
- } | {
436
+ };
437
+ }, {
438
+ content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
405
439
  type: import("@metamask/snaps-sdk").NodeType.Input;
406
440
  name: string;
407
441
  value?: string | undefined;
408
442
  error?: string | undefined;
409
- label?: string | undefined;
410
443
  inputType?: "number" | "text" | "password" | undefined;
411
444
  placeholder?: string | undefined;
445
+ label?: string | undefined;
412
446
  } | {
413
447
  value: string;
414
448
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -423,9 +457,9 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
423
457
  name: string;
424
458
  value?: string | undefined;
425
459
  error?: string | undefined;
426
- label?: string | undefined;
427
460
  inputType?: "number" | "text" | "password" | undefined;
428
461
  placeholder?: string | undefined;
462
+ label?: string | undefined;
429
463
  } | {
430
464
  value: string;
431
465
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -433,9 +467,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
433
467
  variant?: "primary" | "secondary" | undefined;
434
468
  buttonType?: "button" | "submit" | undefined;
435
469
  })[];
436
- };
437
- }, {
438
- content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
470
+ } | {
439
471
  value: string;
440
472
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
441
473
  sensitive?: boolean | undefined;
@@ -471,14 +503,22 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
471
503
  type: import("@metamask/snaps-sdk").NodeType.Row;
472
504
  label: string;
473
505
  variant?: "default" | "warning" | "critical" | undefined;
474
- } | {
506
+ }, null>;
507
+ }>;
508
+ export declare const OnHomePageResponseWithIdStruct: import("superstruct").Struct<{
509
+ id: string;
510
+ }, {
511
+ id: import("superstruct").Struct<string, null>;
512
+ }>;
513
+ export declare const OnHomePageResponseStruct: import("superstruct").Struct<{
514
+ content: import("@metamask/snaps-sdk").Panel | {
475
515
  type: import("@metamask/snaps-sdk").NodeType.Input;
476
516
  name: string;
477
517
  value?: string | undefined;
478
518
  error?: string | undefined;
479
- label?: string | undefined;
480
519
  inputType?: "number" | "text" | "password" | undefined;
481
520
  placeholder?: string | undefined;
521
+ label?: string | undefined;
482
522
  } | {
483
523
  value: string;
484
524
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -493,9 +533,9 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
493
533
  name: string;
494
534
  value?: string | undefined;
495
535
  error?: string | undefined;
496
- label?: string | undefined;
497
536
  inputType?: "number" | "text" | "password" | undefined;
498
537
  placeholder?: string | undefined;
538
+ label?: string | undefined;
499
539
  } | {
500
540
  value: string;
501
541
  type: import("@metamask/snaps-sdk").NodeType.Button;
@@ -503,15 +543,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
503
543
  variant?: "primary" | "secondary" | undefined;
504
544
  buttonType?: "button" | "submit" | undefined;
505
545
  })[];
506
- }, null>;
507
- }>;
508
- export declare const OnHomePageResponseWithIdStruct: import("superstruct").Struct<{
509
- id: string;
510
- }, {
511
- id: import("superstruct").Struct<string, null>;
512
- }>;
513
- export declare const OnHomePageResponseStruct: import("superstruct").Struct<{
514
- content: import("@metamask/snaps-sdk").Panel | {
546
+ } | {
515
547
  value: string;
516
548
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
517
549
  sensitive?: boolean | undefined;
@@ -547,38 +579,6 @@ export declare const OnHomePageResponseStruct: import("superstruct").Struct<{
547
579
  type: import("@metamask/snaps-sdk").NodeType.Row;
548
580
  label: string;
549
581
  variant?: "default" | "warning" | "critical" | undefined;
550
- } | {
551
- type: import("@metamask/snaps-sdk").NodeType.Input;
552
- name: string;
553
- value?: string | undefined;
554
- error?: string | undefined;
555
- label?: string | undefined;
556
- inputType?: "number" | "text" | "password" | undefined;
557
- placeholder?: string | undefined;
558
- } | {
559
- value: string;
560
- type: import("@metamask/snaps-sdk").NodeType.Button;
561
- name?: string | undefined;
562
- variant?: "primary" | "secondary" | undefined;
563
- buttonType?: "button" | "submit" | undefined;
564
- } | {
565
- type: import("@metamask/snaps-sdk").NodeType.Form;
566
- name: string;
567
- children: ({
568
- type: import("@metamask/snaps-sdk").NodeType.Input;
569
- name: string;
570
- value?: string | undefined;
571
- error?: string | undefined;
572
- label?: string | undefined;
573
- inputType?: "number" | "text" | "password" | undefined;
574
- placeholder?: string | undefined;
575
- } | {
576
- value: string;
577
- type: import("@metamask/snaps-sdk").NodeType.Button;
578
- name?: string | undefined;
579
- variant?: "primary" | "secondary" | undefined;
580
- buttonType?: "button" | "submit" | undefined;
581
- })[];
582
582
  };
583
583
  } | {
584
584
  id: string;
@@ -3,7 +3,7 @@ import type { BlockReason } from '@metamask/snaps-registry';
3
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
- import type { SnapManifest, SnapPermissions } from './manifest/validation';
6
+ import type { InitialConnections, SnapManifest, SnapPermissions } from './manifest/validation';
7
7
  import type { FetchedSnapFiles, SnapsPermissionRequest } from './types';
8
8
  import { SnapIdPrefixes, SnapValidationFailureReason } from './types';
9
9
  export declare const PROPOSED_NAME_REGEX: RegExp;
@@ -45,6 +45,10 @@ export declare type PersistedSnap = Snap;
45
45
  * A Snap as it exists in {@link SnapController} state.
46
46
  */
47
47
  export declare type Snap = TruncatedSnap & {
48
+ /**
49
+ * The initial connections of the Snap, optional, requested on installation.
50
+ */
51
+ initialConnections?: InitialConnections;
48
52
  /**
49
53
  * The initial permissions of the Snap, which will be requested when it is
50
54
  * installed.
@@ -1,4 +1,4 @@
1
- import type { Component } from '@metamask/snaps-sdk';
1
+ import type { Component, NodeWithChildren } from '@metamask/snaps-sdk';
2
2
  /**
3
3
  * Searches for markdown links in a string and checks them against the phishing list.
4
4
  *
@@ -25,3 +25,10 @@ export declare function validateComponentLinks(component: Component, isOnPhishin
25
25
  * @returns The total length of all text components in the component.
26
26
  */
27
27
  export declare function getTotalTextLength(component: Component): number;
28
+ /**
29
+ * Check if a component has children.
30
+ *
31
+ * @param component - A custom UI component.
32
+ * @returns `true` if the component has children, `false` otherwise.
33
+ */
34
+ export declare function hasChildren(component: Component): component is NodeWithChildren;
package/dist/ui.js CHANGED
@@ -2,11 +2,13 @@
2
2
 
3
3
 
4
4
 
5
- var _chunkEX4PPLNDjs = require('./chunk-EX4PPLND.js');
5
+
6
+ var _chunkNDIITWO4js = require('./chunk-NDIITWO4.js');
6
7
  require('./chunk-PHUTP7NB.js');
7
8
 
8
9
 
9
10
 
10
11
 
11
- exports.getTotalTextLength = _chunkEX4PPLNDjs.getTotalTextLength; exports.validateComponentLinks = _chunkEX4PPLNDjs.validateComponentLinks; exports.validateTextLinks = _chunkEX4PPLNDjs.validateTextLinks;
12
+
13
+ exports.getTotalTextLength = _chunkNDIITWO4js.getTotalTextLength; exports.hasChildren = _chunkNDIITWO4js.hasChildren; exports.validateComponentLinks = _chunkNDIITWO4js.validateComponentLinks; exports.validateTextLinks = _chunkNDIITWO4js.validateTextLinks;
12
14
  //# sourceMappingURL=ui.js.map
package/dist/ui.mjs CHANGED
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  getTotalTextLength,
3
+ hasChildren,
3
4
  validateComponentLinks,
4
5
  validateTextLinks
5
- } from "./chunk-HDZ3BJBL.mjs";
6
+ } from "./chunk-KP4ZAWMP.mjs";
6
7
  import "./chunk-JMDSN227.mjs";
7
8
  export {
8
9
  getTotalTextLength,
10
+ hasChildren,
9
11
  validateComponentLinks,
10
12
  validateTextLinks
11
13
  };
@@ -1,8 +1,8 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkOK2Q2GT7js = require('./chunk-OK2Q2GT7.js');
4
- require('./chunk-LTWLSRSR.js');
5
- require('./chunk-TG4BDSYJ.js');
3
+ var _chunkMKTAIEG7js = require('./chunk-MKTAIEG7.js');
4
+ require('./chunk-E5WSD47S.js');
5
+ require('./chunk-HVTYDKBO.js');
6
6
  require('./chunk-M3KAAQFK.js');
7
7
  require('./chunk-6LOYTBS3.js');
8
8
  require('./chunk-CMOSYNZR.js');
@@ -20,5 +20,5 @@ require('./chunk-NUCLSR2G.js');
20
20
  require('./chunk-PHUTP7NB.js');
21
21
 
22
22
 
23
- exports.validateFetchedSnap = _chunkOK2Q2GT7js.validateFetchedSnap;
23
+ exports.validateFetchedSnap = _chunkMKTAIEG7js.validateFetchedSnap;
24
24
  //# sourceMappingURL=validation.js.map
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  validateFetchedSnap
3
- } from "./chunk-RQVVWCOW.mjs";
4
- import "./chunk-6F2DZTGM.mjs";
5
- import "./chunk-2IWSQJKQ.mjs";
3
+ } from "./chunk-E6U344HR.mjs";
4
+ import "./chunk-HTS6HGUU.mjs";
5
+ import "./chunk-2M6G46W6.mjs";
6
6
  import "./chunk-MNCFAD4E.mjs";
7
7
  import "./chunk-EXUEHPZ4.mjs";
8
8
  import "./chunk-T6FWIDA6.mjs";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-utils",
3
- "version": "7.0.4",
3
+ "version": "7.1.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/MetaMask/snaps.git"
@@ -57,8 +57,8 @@
57
57
  "@metamask/permission-controller": "^9.0.2",
58
58
  "@metamask/rpc-errors": "^6.2.1",
59
59
  "@metamask/slip44": "^3.1.0",
60
- "@metamask/snaps-registry": "^3.0.1",
61
- "@metamask/snaps-sdk": "^3.2.0",
60
+ "@metamask/snaps-registry": "^3.1.0",
61
+ "@metamask/snaps-sdk": "^4.0.0",
62
62
  "@metamask/utils": "^8.3.0",
63
63
  "@noble/hashes": "^1.3.1",
64
64
  "@scure/base": "^1.1.1",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/snaps.ts"],"sourcesContent":["import type {\n Caveat,\n SubjectPermissions,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport type { BlockReason } from '@metamask/snaps-registry';\nimport type { SnapId, Snap as TruncatedSnap } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assert, isObject, assertStruct } from '@metamask/utils';\nimport { base64 } from '@scure/base';\nimport stableStringify from 'fast-json-stable-stringify';\nimport type { Struct } from 'superstruct';\nimport {\n empty,\n enums,\n intersection,\n literal,\n pattern,\n refine,\n string,\n union,\n validate,\n} from 'superstruct';\nimport validateNPMPackage from 'validate-npm-package-name';\n\nimport { SnapCaveatType } from './caveats';\nimport { checksumFiles } from './checksum';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest, SnapPermissions } from './manifest/validation';\nimport type { FetchedSnapFiles, SnapsPermissionRequest } from './types';\nimport { SnapIdPrefixes, SnapValidationFailureReason, uri } from './types';\nimport type { VirtualFile } from './virtual-file';\n\n// This RegEx matches valid npm package names (with some exceptions) and space-\n// separated alphanumerical words, optionally with dashes and underscores.\n// The RegEx consists of two parts. The first part matches space-separated\n// words. It is based on the following Stackoverflow answer:\n// https://stackoverflow.com/a/34974982\n// The second part, after the pipe operator, is the same RegEx used for the\n// `name` field of the official package.json JSON Schema, except that we allow\n// mixed-case letters. It was originally copied from:\n// https://github.com/SchemaStore/schemastore/blob/81a16897c1dabfd98c72242a5fd62eb080ff76d8/src/schemas/json/package.json#L132-L138\nexport const PROPOSED_NAME_REGEX =\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\nexport enum SnapStatus {\n Installing = 'installing',\n Updating = 'updating',\n Running = 'running',\n Stopped = 'stopped',\n Crashed = 'crashed',\n}\n\nexport enum SnapStatusEvents {\n Start = 'START',\n Stop = 'STOP',\n Crash = 'CRASH',\n Update = 'UPDATE',\n}\n\nexport type StatusContext = { snapId: SnapId };\nexport type StatusEvents = { type: SnapStatusEvents };\nexport type StatusStates = {\n value: SnapStatus;\n context: StatusContext;\n};\nexport type Status = StatusStates['value'];\n\nexport type VersionHistory = {\n origin: string;\n version: string;\n // Unix timestamp\n date: number;\n};\n\nexport type SnapAuxilaryFile = {\n path: string;\n // Value here should be stored as base64\n value: string;\n};\n\nexport type PersistedSnap = Snap;\n\n/**\n * A Snap as it exists in {@link SnapController} state.\n */\nexport type Snap = TruncatedSnap & {\n /**\n * The initial permissions of the Snap, which will be requested when it is\n * installed.\n */\n initialPermissions: SnapPermissions;\n\n /**\n * The source code of the Snap.\n */\n sourceCode: string;\n\n /**\n * The Snap's manifest file.\n */\n manifest: SnapManifest;\n\n /**\n * Information detailing why the snap is blocked.\n */\n blockInformation?: BlockReason;\n\n /**\n * The current status of the Snap, e.g. whether it's running or stopped.\n */\n status: Status;\n\n /**\n * The version history of the Snap.\n * Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.\n */\n versionHistory: VersionHistory[];\n\n /**\n * Static auxiliary files that can be loaded at runtime.\n */\n auxiliaryFiles?: SnapAuxilaryFile[];\n\n /**\n * Localization files which are used to translate the manifest.\n */\n localizationFiles?: LocalizationFile[];\n\n /**\n * Flag to signal whether this snap was preinstalled or not.\n *\n * A lack of specifying this option will be deemed as not preinstalled.\n */\n preinstalled?: boolean;\n\n /**\n * Flag to signal whether this snap is removable or not.\n *\n * A lack of specifying this option will be deemed as removable.\n */\n removable?: boolean;\n};\n\nexport type TruncatedSnapFields =\n | 'id'\n | 'initialPermissions'\n | 'version'\n | 'enabled'\n | 'blocked';\n\n/**\n * An error indicating that a Snap validation failure is programmatically\n * fixable during development.\n */\nexport class ProgrammaticallyFixableSnapError extends Error {\n reason: SnapValidationFailureReason;\n\n constructor(message: string, reason: SnapValidationFailureReason) {\n super(message);\n this.reason = reason;\n }\n}\n\n/**\n * Gets a checksummable manifest by removing the shasum property and reserializing the JSON using a deterministic algorithm.\n *\n * @param manifest - The manifest itself.\n * @returns A virtual file containing the checksummable manifest.\n */\nfunction getChecksummableManifest(\n manifest: VirtualFile<SnapManifest>,\n): VirtualFile {\n const manifestCopy = manifest.clone() as VirtualFile<any>;\n delete manifestCopy.result.source.shasum;\n\n // We use fast-json-stable-stringify to deterministically serialize the JSON\n // This is required before checksumming so we get reproducible checksums across platforms etc\n manifestCopy.value = stableStringify(manifestCopy.result);\n return manifestCopy;\n}\n\n/**\n * Calculates the Base64-encoded SHA-256 digest of all required Snap files.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @returns The Base64-encoded SHA-256 digest of the source code.\n */\nexport async function getSnapChecksum(\n files: FetchedSnapFiles,\n): Promise<string> {\n const { manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles } =\n files;\n\n const all = [\n getChecksummableManifest(manifest),\n sourceCode,\n svgIcon,\n ...auxiliaryFiles,\n ...localizationFiles,\n ].filter((file) => file !== undefined);\n\n return base64.encode(await checksumFiles(all as VirtualFile[]));\n}\n\n/**\n * Checks whether the `source.shasum` property of a Snap manifest matches the\n * shasum of the snap.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @param errorMessage - The error message to throw if validation fails.\n */\nexport async function validateSnapShasum(\n files: FetchedSnapFiles,\n errorMessage = 'Invalid Snap manifest: manifest shasum does not match computed shasum.',\n): Promise<void> {\n if (files.manifest.result.source.shasum !== (await getSnapChecksum(files))) {\n throw new ProgrammaticallyFixableSnapError(\n errorMessage,\n SnapValidationFailureReason.ShasumMismatch,\n );\n }\n}\n\nexport const LOCALHOST_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]'] as const;\n\n// Require snap ids to only consist of printable ASCII characters\nexport const BaseSnapIdStruct = pattern(string(), /^[\\x21-\\x7E]*$/u);\n\nconst LocalSnapIdSubUrlStruct = uri({\n protocol: enums(['http:', 'https:']),\n hostname: enums(LOCALHOST_HOSTNAMES),\n hash: empty(string()),\n search: empty(string()),\n});\n\nexport const LocalSnapIdStruct = refine(\n BaseSnapIdStruct,\n 'local Snap Id',\n (value) => {\n if (!value.startsWith(SnapIdPrefixes.local)) {\n return `Expected local snap ID, got \"${value}\".`;\n }\n\n const [error] = validate(\n value.slice(SnapIdPrefixes.local.length),\n LocalSnapIdSubUrlStruct,\n );\n return error ?? true;\n },\n);\nexport const NpmSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: literal(SnapIdPrefixes.npm),\n pathname: refine(string(), 'package name', function* (value) {\n const normalized = value.startsWith('/') ? value.slice(1) : value;\n const { errors, validForNewPackages, warnings } =\n validateNPMPackage(normalized);\n if (!validForNewPackages) {\n if (errors === undefined) {\n assert(warnings !== undefined);\n yield* warnings;\n } else {\n yield* errors;\n }\n }\n return true;\n }),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const HttpSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: enums(['http:', 'https:']),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const SnapIdStruct = union([NpmSnapIdStruct, LocalSnapIdStruct]);\n\n/**\n * Extracts the snap prefix from a snap ID.\n *\n * @param snapId - The snap ID to extract the prefix from.\n * @returns The snap prefix from a snap id, e.g. `npm:`.\n */\nexport function getSnapPrefix(snapId: string): SnapIdPrefixes {\n const prefix = Object.values(SnapIdPrefixes).find((possiblePrefix) =>\n snapId.startsWith(possiblePrefix),\n );\n if (prefix !== undefined) {\n return prefix;\n }\n throw new Error(`Invalid or no prefix found for \"${snapId}\"`);\n}\n\n/**\n * Strips snap prefix from a full snap ID.\n *\n * @param snapId - The snap ID to strip.\n * @returns The stripped snap ID.\n */\nexport function stripSnapPrefix(snapId: string): string {\n return snapId.replace(getSnapPrefix(snapId), '');\n}\n\n/**\n * Assert that the given value is a valid snap ID.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid snap ID.\n */\nexport function assertIsValidSnapId(value: unknown): asserts value is SnapId {\n assertStruct(value, SnapIdStruct, 'Invalid snap ID');\n}\n\n/**\n * Typeguard to ensure a chainId follows the CAIP-2 standard.\n *\n * @param chainId - The chainId being tested.\n * @returns `true` if the value is a valid CAIP chain id, and `false` otherwise.\n */\nexport function isCaipChainId(chainId: unknown): chainId is string {\n return (\n typeof chainId === 'string' &&\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u.test(\n chainId,\n )\n );\n}\n\n/**\n * Utility function to check if an origin has permission (and caveat) for a particular snap.\n *\n * @param permissions - An origin's permissions object.\n * @param snapId - The id of the snap.\n * @returns A boolean based on if an origin has the specified snap.\n */\nexport function isSnapPermitted(\n permissions: SubjectPermissions<PermissionConstraint>,\n snapId: SnapId,\n) {\n return Boolean(\n (\n (\n (permissions?.wallet_snap?.caveats?.find(\n (caveat) => caveat.type === SnapCaveatType.SnapIds,\n ) ?? {}) as Caveat<string, Json>\n ).value as Record<string, unknown>\n )?.[snapId],\n );\n}\n\n/**\n * Checks whether the passed in requestedPermissions is a valid\n * permission request for a `wallet_snap` permission.\n *\n * @param requestedPermissions - The requested permissions.\n * @throws If the criteria is not met.\n */\nexport function verifyRequestedSnapPermissions(\n requestedPermissions: unknown,\n): asserts requestedPermissions is SnapsPermissionRequest {\n assert(\n isObject(requestedPermissions),\n 'Requested permissions must be an object.',\n );\n\n const { wallet_snap: walletSnapPermission } = requestedPermissions;\n\n assert(\n isObject(walletSnapPermission),\n 'wallet_snap is missing from the requested permissions.',\n );\n\n const { caveats } = walletSnapPermission;\n\n assert(\n Array.isArray(caveats) && caveats.length === 1,\n 'wallet_snap must have a caveat property with a single-item array value.',\n );\n\n const [caveat] = caveats;\n\n assert(\n isObject(caveat) &&\n caveat.type === SnapCaveatType.SnapIds &&\n isObject(caveat.value),\n `The requested permissions do not have a valid ${SnapCaveatType.SnapIds} caveat.`,\n );\n}\n\nexport type { Snap as TruncatedSnap } from '@metamask/snaps-sdk';\n"],"mappings":";;;;;;;;;AAQA,SAAS,QAAQ,UAAU,oBAAoB;AAC/C,SAAS,cAAc;AACvB,OAAO,qBAAqB;AAE5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,wBAAwB;AAmBxB,IAAM,sBACX;AAEK,IAAK,aAAL,kBAAKA,gBAAL;AACL,EAAAA,YAAA,gBAAa;AACb,EAAAA,YAAA,cAAW;AACX,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,aAAU;AALA,SAAAA;AAAA,GAAA;AAQL,IAAK,mBAAL,kBAAKC,sBAAL;AACL,EAAAA,kBAAA,WAAQ;AACR,EAAAA,kBAAA,UAAO;AACP,EAAAA,kBAAA,WAAQ;AACR,EAAAA,kBAAA,YAAS;AAJC,SAAAA;AAAA,GAAA;AAsGL,IAAM,mCAAN,cAA+C,MAAM;AAAA,EAG1D,YAAY,SAAiB,QAAqC;AAChE,UAAM,OAAO;AACb,SAAK,SAAS;AAAA,EAChB;AACF;AAQA,SAAS,yBACP,UACa;AACb,QAAM,eAAe,SAAS,MAAM;AACpC,SAAO,aAAa,OAAO,OAAO;AAIlC,eAAa,QAAQ,gBAAgB,aAAa,MAAM;AACxD,SAAO;AACT;AAQA,eAAsB,gBACpB,OACiB;AACjB,QAAM,EAAE,UAAU,YAAY,SAAS,gBAAgB,kBAAkB,IACvE;AAEF,QAAM,MAAM;AAAA,IACV,yBAAyB,QAAQ;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,EACF;AAEA,QAAM,EAAE,QAAQ,IAAI;AAEpB;AAAA,IACE,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW;AAAA,IAC7C;AAAA,EACF;AAEA,QAAM,CAAC,MAAM,IAAI;AAEjB;AAAA,IACE,SAAS,MAAM,KACb,OAAO,oCACP,SAAS,OAAO,KAAK;AAAA,IACvB,wEAAuE;AAAA,EACzE;AACF;","names":["SnapStatus","SnapStatusEvents"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/derivation-paths.ts"],"names":[],"mappings":";;;;;AACA,OAAO,YAAY;AAUZ,IAAM,yBAAgD;AAAA,EAC3D;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,MAAM;AAAA,IACzB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,QAAQ,MAAM,IAAI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,IACE,MAAM,CAAC,KAAK,OAAO,QAAQ,IAAI;AAAA,IAC/B,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,MAAM,IAAI;AAAA,IAC7B,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,MAAM;AAAA,IACzB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,QAAQ;AAAA,IAC3B,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,SAAS,MAAM,IAAI;AAAA,IACtC,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,SAAS,IAAI;AAAA,IACzB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AACF;AASO,SAAS,0BACd,MACA,OACe;AACf,QAAM,eAAe,uBAAuB;AAAA,IAC1C,CAAC,mBACC,eAAe,UAAU,SAAS,QAAQ,eAAe,MAAM,IAAI;AAAA,EACvE;AAEA,MAAI,cAAc;AAChB,WAAO,aAAa;AAAA,EACtB;AAIA,MACE,UAAU,eACV,KAAK,CAAC,MAAM,OACZ,KAAK,CAAC,MAAM,SACZ,KAAK,CAAC,EAAE,SAAS,GAAG,GACpB;AACA,UAAM,WAAW,KAAK,CAAC,EAAE,MAAM,GAAG,EAAE;AACpC,WAAO,sBAAsB,QAAQ,KAAK;AAAA,EAC5C;AAEA,SAAO;AACT;AAUO,SAAS,sBAAsB,UAA2B;AAC/D,MAAI,OAAO,QAAQ,MAAM,KAAK;AAC5B,WAAO;AAAA,EACT;AAEA,SAAO,OAAO,QAA+B,GAAG,QAAQ;AAC1D","sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport slip44 from '@metamask/slip44';\n\nimport { isEqual } from './array';\n\nexport type SnapsDerivationPath = {\n path: ['m', ...string[]];\n curve: SupportedCurve;\n name: string;\n};\n\nexport const SNAPS_DERIVATION_PATHS: SnapsDerivationPath[] = [\n {\n path: ['m', `44'`, `0'`],\n curve: 'ed25519',\n name: 'Test BIP-32 Path (ed25519)',\n },\n {\n path: ['m', `44'`, `1'`],\n curve: 'secp256k1',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Legacy',\n },\n {\n path: ['m', `49'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Nested SegWit',\n },\n {\n path: ['m', `49'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Nested SegWit',\n },\n {\n path: ['m', `84'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Native SegWit',\n },\n {\n path: ['m', `84'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Native SegWit',\n },\n {\n path: ['m', `44'`, `501'`],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `501'`, \"0'\", \"0'\"],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `2'`],\n curve: 'secp256k1',\n name: 'Litecoin',\n },\n {\n path: ['m', `44'`, `3'`],\n curve: 'secp256k1',\n name: 'Dogecoin',\n },\n {\n path: ['m', `44'`, `60'`],\n curve: 'secp256k1',\n name: 'Ethereum',\n },\n {\n path: ['m', `44'`, `118'`],\n curve: 'secp256k1',\n name: 'Atom',\n },\n {\n path: ['m', `44'`, `145'`],\n curve: 'secp256k1',\n name: 'Bitcoin Cash',\n },\n {\n path: ['m', `44'`, `637'`],\n curve: 'ed25519',\n name: 'Aptos',\n },\n {\n path: ['m', `44'`, `714'`],\n curve: 'secp256k1',\n name: 'Binance (BNB)',\n },\n {\n path: ['m', `44'`, `784'`],\n curve: 'ed25519',\n name: 'Sui',\n },\n {\n path: ['m', `44'`, `931'`],\n curve: 'secp256k1',\n name: 'THORChain (RUNE)',\n },\n {\n path: ['m', `44'`, `330'`],\n curve: 'secp256k1',\n name: 'Terra (LUNA)',\n },\n {\n path: ['m', `44'`, `459'`],\n curve: 'secp256k1',\n name: 'Kava',\n },\n {\n path: ['m', `44'`, `529'`],\n curve: 'secp256k1',\n name: 'Secret Network',\n },\n {\n path: ['m', `44'`, `397'`, `0'`],\n curve: 'ed25519',\n name: 'NEAR Protocol',\n },\n {\n path: ['m', `44'`, `1'`, `0'`],\n curve: 'ed25519',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `472'`],\n curve: 'ed25519',\n name: 'Arweave',\n },\n {\n path: ['m', `44'`, `12586'`],\n curve: 'secp256k1',\n name: 'Mina',\n },\n {\n path: ['m', `44'`, `1729'`, `0'`, `0'`],\n curve: 'ed25519',\n name: 'Tezos',\n },\n {\n path: ['m', `1789'`, `0'`],\n curve: 'ed25519',\n name: 'Vega',\n },\n];\n\n/**\n * Gets the name of a derivation path supported by snaps.\n *\n * @param path - The derivation path.\n * @param curve - The curve used to derive the keys.\n * @returns The name of the derivation path, otherwise null.\n */\nexport function getSnapDerivationPathName(\n path: SnapsDerivationPath['path'],\n curve: SupportedCurve,\n): string | null {\n const pathMetadata = SNAPS_DERIVATION_PATHS.find(\n (derivationPath) =>\n derivationPath.curve === curve && isEqual(derivationPath.path, path),\n );\n\n if (pathMetadata) {\n return pathMetadata.name;\n }\n\n // If the curve is secp256k1 and the path is a valid BIP44 path\n // we try looking for the network/protocol name in SLIP44\n if (\n curve === 'secp256k1' &&\n path[0] === 'm' &&\n path[1] === `44'` &&\n path[2].endsWith(`'`)\n ) {\n const coinType = path[2].slice(0, -1);\n return getSlip44ProtocolName(coinType) ?? null;\n }\n\n return null;\n}\n\n/**\n * Gets the name of the SLIP-44 protocol corresponding to the specified\n * `coin_type`.\n *\n * @param coinType - The SLIP-44 `coin_type` value whose name\n * to retrieve.\n * @returns The name of the protocol, otherwise null.\n */\nexport function getSlip44ProtocolName(coinType: number | string) {\n if (String(coinType) === '1') {\n return 'Test Networks';\n }\n\n return slip44[coinType as keyof typeof slip44]?.name ?? null;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/ui.ts"],"names":[],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,QAAQ,sBAAsB;AAEvC,SAAS,OAAO,kBAAkB;AAElC,IAAM,oBAAoB,CAAC,UAAU,SAAS;AAQ9C,SAAS,iBAAiB,MAAc;AACtC,QAAM,SAAS,MAAM,IAAI;AACzB,QAAM,QAA0C,CAAC;AAGjD,aAAW,QAAQ,CAAC,UAAU;AAC5B,QAAI,MAAM,SAAS,QAAQ;AACzB,YAAM,KAAK,KAAK;AAAA,IAClB;AAAA,EACF,CAAC;AAED,SAAO,MAAM,IAAI,CAAC,SAAS,MAAM,IAAI,EAAE,OAAO,OAAO;AACvD;AAUO,SAAS,kBACd,MACA,kBACA;AACA,QAAM,QAAQ,iBAAiB,IAAI;AAEnC,aAAW,QAAQ,OAAO;AACxB,QAAI;AACF,YAAM,MAAM,IAAI,IAAI,IAAI;AACxB;AAAA,QACE,kBAAkB,SAAS,IAAI,QAAQ;AAAA,QACvC,4BAA4B,kBAAkB,KAAK,IAAI,CAAC;AAAA,MAC1D;AAEA,YAAM,WACJ,IAAI,aAAa,YAAY,IAAI,SAAS,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI;AAEhE,aAAO,CAAC,iBAAiB,QAAQ,GAAG,mCAAmC;AAAA,IACzE,SAAS,OAAO;AACd,YAAM,IAAI;AAAA,QACR,gBACE,iBAAiB,iBACb,MAAM,UACN,sBACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAWO,SAAS,uBACd,WACA,kBACA;AACA,QAAM,EAAE,KAAK,IAAI;AACjB,UAAQ,MAAM;AAAA,IACZ,KAAK,SAAS;AACZ,gBAAU,SAAS;AAAA,QAAQ,CAAC,SAC1B,uBAAuB,MAAM,gBAAgB;AAAA,MAC/C;AACA;AAAA,IACF,KAAK,SAAS;AACZ,6BAAuB,UAAU,OAAO,gBAAgB;AACxD;AAAA,IACF,KAAK,SAAS;AACZ,wBAAkB,UAAU,OAAO,gBAAgB;AACnD;AAAA,IACF;AACE;AAAA,EACJ;AACF;AAQO,SAAS,mBAAmB,WAA8B;AAC/D,QAAM,EAAE,KAAK,IAAI;AAEjB,UAAQ,MAAM;AAAA,IACZ,KAAK,SAAS;AACZ,aAAO,UAAU,SAAS;AAAA;AAAA;AAAA,QAGxB,CAAC,KAAK,SAAS,MAAM,mBAAmB,IAAI;AAAA,QAC5C;AAAA,MACF;AAAA,IACF,KAAK,SAAS;AACZ,aAAO,mBAAmB,UAAU,KAAK;AAAA,IAC3C,KAAK,SAAS;AACZ,aAAO,UAAU,MAAM;AAAA,IACzB;AACE,aAAO;AAAA,EACX;AACF","sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport { NodeType } from '@metamask/snaps-sdk';\nimport { assert, AssertionError } from '@metamask/utils';\nimport type { Tokens } from 'marked';\nimport { lexer, walkTokens } from 'marked';\n\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n\n/**\n * Extract all links from a Markdown text string using the `marked` lexer.\n *\n * @param text - The markdown text string.\n * @returns A list of URLs linked to in the string.\n */\nfunction getMarkdownLinks(text: string) {\n const tokens = lexer(text);\n const links: (Tokens.Link | Tokens.Generic)[] = [];\n\n // Walk the lexed tokens and collect all link tokens\n walkTokens(tokens, (token) => {\n if (token.type === 'link') {\n links.push(token);\n }\n });\n\n return links.map((link) => link?.href).filter(Boolean);\n}\n\n/**\n * Searches for markdown links in a string and checks them against the phishing list.\n *\n * @param text - The text to verify.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the text contains a link that is not allowed.\n */\nexport function validateTextLinks(\n text: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n const links = getMarkdownLinks(text);\n\n for (const link of links) {\n try {\n const url = new URL(link);\n assert(\n ALLOWED_PROTOCOLS.includes(url.protocol),\n `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`,\n );\n\n const hostname =\n url.protocol === 'mailto:' ? url.pathname.split('@')[1] : url.hostname;\n\n assert(!isOnPhishingList(hostname), 'The specified URL is not allowed.');\n } catch (error) {\n throw new Error(\n `Invalid URL: ${\n error instanceof AssertionError\n ? error.message\n : 'Unable to parse URL.'\n }`,\n );\n }\n }\n}\n\n/**\n * Search for links in UI components and check that the URL they are trying to\n * pass in is not in the phishing list.\n *\n * @param component - The custom UI component.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the component contains a link that is not allowed.\n */\nexport function validateComponentLinks(\n component: Component,\n isOnPhishingList: (url: string) => boolean,\n) {\n const { type } = component;\n switch (type) {\n case NodeType.Panel:\n component.children.forEach((node) =>\n validateComponentLinks(node, isOnPhishingList),\n );\n break;\n case NodeType.Row:\n validateComponentLinks(component.value, isOnPhishingList);\n break;\n case NodeType.Text:\n validateTextLinks(component.value, isOnPhishingList);\n break;\n default:\n break;\n }\n}\n\n/**\n * Calculate the total length of all text in the component.\n *\n * @param component - A custom UI component.\n * @returns The total length of all text components in the component.\n */\nexport function getTotalTextLength(component: Component): number {\n const { type } = component;\n\n switch (type) {\n case NodeType.Panel:\n return component.children.reduce<number>(\n // This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n (sum, node) => sum + getTotalTextLength(node),\n 0,\n );\n case NodeType.Row:\n return getTotalTextLength(component.value);\n case NodeType.Text:\n return component.value.length;\n default:\n return 0;\n }\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/ui.ts"],"sourcesContent":["import type { Component } from '@metamask/snaps-sdk';\nimport { NodeType } from '@metamask/snaps-sdk';\nimport { assert, AssertionError } from '@metamask/utils';\nimport type { Tokens } from 'marked';\nimport { lexer, walkTokens } from 'marked';\n\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\n\n/**\n * Extract all links from a Markdown text string using the `marked` lexer.\n *\n * @param text - The markdown text string.\n * @returns A list of URLs linked to in the string.\n */\nfunction getMarkdownLinks(text: string) {\n const tokens = lexer(text);\n const links: (Tokens.Link | Tokens.Generic)[] = [];\n\n // Walk the lexed tokens and collect all link tokens\n walkTokens(tokens, (token) => {\n if (token.type === 'link') {\n links.push(token);\n }\n });\n\n return links.map((link) => link?.href).filter(Boolean);\n}\n\n/**\n * Searches for markdown links in a string and checks them against the phishing list.\n *\n * @param text - The text to verify.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the text contains a link that is not allowed.\n */\nexport function validateTextLinks(\n text: string,\n isOnPhishingList: (url: string) => boolean,\n) {\n const links = getMarkdownLinks(text);\n\n for (const link of links) {\n try {\n const url = new URL(link);\n assert(\n ALLOWED_PROTOCOLS.includes(url.protocol),\n `Protocol must be one of: ${ALLOWED_PROTOCOLS.join(', ')}.`,\n );\n\n const hostname =\n url.protocol === 'mailto:' ? url.pathname.split('@')[1] : url.hostname;\n\n assert(!isOnPhishingList(hostname), 'The specified URL is not allowed.');\n } catch (error) {\n throw new Error(\n `Invalid URL: ${\n error instanceof AssertionError\n ? error.message\n : 'Unable to parse URL.'\n }`,\n );\n }\n }\n}\n\n/**\n * Search for links in UI components and check that the URL they are trying to\n * pass in is not in the phishing list.\n *\n * @param component - The custom UI component.\n * @param isOnPhishingList - The function that checks the link against the\n * phishing list.\n * @throws If the component contains a link that is not allowed.\n */\nexport function validateComponentLinks(\n component: Component,\n isOnPhishingList: (url: string) => boolean,\n) {\n const { type } = component;\n switch (type) {\n case NodeType.Panel:\n component.children.forEach((node) =>\n validateComponentLinks(node, isOnPhishingList),\n );\n break;\n case NodeType.Row:\n validateComponentLinks(component.value, isOnPhishingList);\n break;\n case NodeType.Text:\n validateTextLinks(component.value, isOnPhishingList);\n break;\n default:\n break;\n }\n}\n\n/**\n * Calculate the total length of all text in the component.\n *\n * @param component - A custom UI component.\n * @returns The total length of all text components in the component.\n */\nexport function getTotalTextLength(component: Component): number {\n const { type } = component;\n\n switch (type) {\n case NodeType.Panel:\n return component.children.reduce<number>(\n // This is a bug in TypeScript: https://github.com/microsoft/TypeScript/issues/48313\n // eslint-disable-next-line @typescript-eslint/restrict-plus-operands\n (sum, node) => sum + getTotalTextLength(node),\n 0,\n );\n case NodeType.Row:\n return getTotalTextLength(component.value);\n case NodeType.Text:\n return component.value.length;\n default:\n return 0;\n }\n}\n"],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,QAAQ,sBAAsB;AAEvC,SAAS,OAAO,kBAAkB;AAElC,IAAM,oBAAoB,CAAC,UAAU,SAAS;AAQ9C,SAAS,iBAAiB,MAAc;AACtC,QAAM,SAAS,MAAM,IAAI;AACzB,QAAM,QAA0C,CAAC;AAGjD,aAAW,QAAQ,CAAC,UAAU;AAC5B,QAAI,MAAM,SAAS,QAAQ;AACzB,YAAM,KAAK,KAAK;AAAA,IAClB;AAAA,EACF,CAAC;AAED,SAAO,MAAM,IAAI,CAAC,SAAS,MAAM,IAAI,EAAE,OAAO,OAAO;AACvD;AAUO,SAAS,kBACd,MACA,kBACA;AACA,QAAM,QAAQ,iBAAiB,IAAI;AAEnC,aAAW,QAAQ,OAAO;AACxB,QAAI;AACF,YAAM,MAAM,IAAI,IAAI,IAAI;AACxB;AAAA,QACE,kBAAkB,SAAS,IAAI,QAAQ;AAAA,QACvC,4BAA4B,kBAAkB,KAAK,IAAI,CAAC;AAAA,MAC1D;AAEA,YAAM,WACJ,IAAI,aAAa,YAAY,IAAI,SAAS,MAAM,GAAG,EAAE,CAAC,IAAI,IAAI;AAEhE,aAAO,CAAC,iBAAiB,QAAQ,GAAG,mCAAmC;AAAA,IACzE,SAAS,OAAO;AACd,YAAM,IAAI;AAAA,QACR,gBACE,iBAAiB,iBACb,MAAM,UACN,sBACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAWO,SAAS,uBACd,WACA,kBACA;AACA,QAAM,EAAE,KAAK,IAAI;AACjB,UAAQ,MAAM;AAAA,IACZ,KAAK,SAAS;AACZ,gBAAU,SAAS;AAAA,QAAQ,CAAC,SAC1B,uBAAuB,MAAM,gBAAgB;AAAA,MAC/C;AACA;AAAA,IACF,KAAK,SAAS;AACZ,6BAAuB,UAAU,OAAO,gBAAgB;AACxD;AAAA,IACF,KAAK,SAAS;AACZ,wBAAkB,UAAU,OAAO,gBAAgB;AACnD;AAAA,IACF;AACE;AAAA,EACJ;AACF;AAQO,SAAS,mBAAmB,WAA8B;AAC/D,QAAM,EAAE,KAAK,IAAI;AAEjB,UAAQ,MAAM;AAAA,IACZ,KAAK,SAAS;AACZ,aAAO,UAAU,SAAS;AAAA;AAAA;AAAA,QAGxB,CAAC,KAAK,SAAS,MAAM,mBAAmB,IAAI;AAAA,QAC5C;AAAA,MACF;AAAA,IACF,KAAK,SAAS;AACZ,aAAO,mBAAmB,UAAU,KAAK;AAAA,IAC3C,KAAK,SAAS;AACZ,aAAO,UAAU,MAAM;AAAA,IACzB;AACE,aAAO;AAAA,EACX;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/derivation-paths.ts"],"sourcesContent":["import type { SupportedCurve } from '@metamask/key-tree';\nimport slip44 from '@metamask/slip44';\n\nimport { isEqual } from './array';\n\nexport type SnapsDerivationPath = {\n path: ['m', ...string[]];\n curve: SupportedCurve;\n name: string;\n};\n\nexport const SNAPS_DERIVATION_PATHS: SnapsDerivationPath[] = [\n {\n path: ['m', `44'`, `0'`],\n curve: 'ed25519',\n name: 'Test BIP-32 Path (ed25519)',\n },\n {\n path: ['m', `44'`, `1'`],\n curve: 'secp256k1',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Legacy',\n },\n {\n path: ['m', `49'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Nested SegWit',\n },\n {\n path: ['m', `49'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Nested SegWit',\n },\n {\n path: ['m', `84'`, `0'`],\n curve: 'secp256k1',\n name: 'Bitcoin Native SegWit',\n },\n {\n path: ['m', `84'`, `1'`],\n curve: 'secp256k1',\n name: 'Bitcoin Testnet Native SegWit',\n },\n {\n path: ['m', `44'`, `501'`],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `501'`, \"0'\", \"0'\"],\n curve: 'ed25519',\n name: 'Solana',\n },\n {\n path: ['m', `44'`, `2'`],\n curve: 'secp256k1',\n name: 'Litecoin',\n },\n {\n path: ['m', `44'`, `3'`],\n curve: 'secp256k1',\n name: 'Dogecoin',\n },\n {\n path: ['m', `44'`, `60'`],\n curve: 'secp256k1',\n name: 'Ethereum',\n },\n {\n path: ['m', `44'`, `118'`],\n curve: 'secp256k1',\n name: 'Atom',\n },\n {\n path: ['m', `44'`, `145'`],\n curve: 'secp256k1',\n name: 'Bitcoin Cash',\n },\n {\n path: ['m', `44'`, `637'`],\n curve: 'ed25519',\n name: 'Aptos',\n },\n {\n path: ['m', `44'`, `714'`],\n curve: 'secp256k1',\n name: 'Binance (BNB)',\n },\n {\n path: ['m', `44'`, `784'`],\n curve: 'ed25519',\n name: 'Sui',\n },\n {\n path: ['m', `44'`, `931'`],\n curve: 'secp256k1',\n name: 'THORChain (RUNE)',\n },\n {\n path: ['m', `44'`, `330'`],\n curve: 'secp256k1',\n name: 'Terra (LUNA)',\n },\n {\n path: ['m', `44'`, `459'`],\n curve: 'secp256k1',\n name: 'Kava',\n },\n {\n path: ['m', `44'`, `529'`],\n curve: 'secp256k1',\n name: 'Secret Network',\n },\n {\n path: ['m', `44'`, `397'`, `0'`],\n curve: 'ed25519',\n name: 'NEAR Protocol',\n },\n {\n path: ['m', `44'`, `1'`, `0'`],\n curve: 'ed25519',\n name: 'Testnet',\n },\n {\n path: ['m', `44'`, `472'`],\n curve: 'ed25519',\n name: 'Arweave',\n },\n {\n path: ['m', `44'`, `12586'`],\n curve: 'secp256k1',\n name: 'Mina',\n },\n {\n path: ['m', `44'`, `1729'`, `0'`, `0'`],\n curve: 'ed25519',\n name: 'Tezos',\n },\n {\n path: ['m', `1789'`, `0'`],\n curve: 'ed25519',\n name: 'Vega',\n },\n];\n\n/**\n * Gets the name of a derivation path supported by snaps.\n *\n * @param path - The derivation path.\n * @param curve - The curve used to derive the keys.\n * @returns The name of the derivation path, otherwise null.\n */\nexport function getSnapDerivationPathName(\n path: SnapsDerivationPath['path'],\n curve: SupportedCurve,\n): string | null {\n const pathMetadata = SNAPS_DERIVATION_PATHS.find(\n (derivationPath) =>\n derivationPath.curve === curve && isEqual(derivationPath.path, path),\n );\n\n if (pathMetadata) {\n return pathMetadata.name;\n }\n\n // If the curve is secp256k1 and the path is a valid BIP44 path\n // we try looking for the network/protocol name in SLIP44\n if (\n curve === 'secp256k1' &&\n path[0] === 'm' &&\n path[1] === `44'` &&\n path[2].endsWith(`'`)\n ) {\n const coinType = path[2].slice(0, -1);\n return getSlip44ProtocolName(coinType) ?? null;\n }\n\n return null;\n}\n\n/**\n * Gets the name of the SLIP-44 protocol corresponding to the specified\n * `coin_type`.\n *\n * @param coinType - The SLIP-44 `coin_type` value whose name\n * to retrieve.\n * @returns The name of the protocol, otherwise null.\n */\nexport function getSlip44ProtocolName(coinType: number | string) {\n if (String(coinType) === '1') {\n return 'Test Networks';\n }\n\n return slip44[coinType as keyof typeof slip44]?.name ?? null;\n}\n"],"mappings":";;;;;AACA,OAAO,YAAY;AAUZ,IAAM,yBAAgD;AAAA,EAC3D;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,IAAI;AAAA,IACvB,OAAO;AAAA,IACP,MAAM;AAAA,EACR;AAAA,EACA;AAAA,IACE,MAAM,CAAC,KAAK,OAAO,I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AAC,WAAW,OAAO;AAAA,IACrB,KAAK,CAAC,GACN,QACA,MAAM;AAAA,EACZ;AACF;AASO,SAAS,+BACd,sBACwD;AACxD;AAAA,IACE,SAAS,oBAAoB;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,EAAE,aAAa,qBAAqB,IAAI;AAE9C;AAAA,IACE,SAAS,oBAAoB;AAAA,IAC7B;AAAA,EACF;AAEA,QAAM,EAAE,QAAQ,IAAI;AAEpB;AAAA,IACE,MAAM,QAAQ,OAAO,KAAK,QAAQ,WAAW;AAAA,IAC7C;AAAA,EACF;AAEA,QAAM,CAAC,MAAM,IAAI;AAEjB;AAAA,IACE,SAAS,MAAM,KACb,OAAO,oCACP,SAAS,OAAO,KAAK;AAAA,IACvB,wEAAuE;AAAA,EACzE;AACF","sourcesContent":["import type {\n Caveat,\n SubjectPermissions,\n PermissionConstraint,\n} from '@metamask/permission-controller';\nimport type { BlockReason } from '@metamask/snaps-registry';\nimport type { SnapId, Snap as TruncatedSnap } from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { assert, isObject, assertStruct } from '@metamask/utils';\nimport { base64 } from '@scure/base';\nimport stableStringify from 'fast-json-stable-stringify';\nimport type { Struct } from 'superstruct';\nimport {\n empty,\n enums,\n intersection,\n literal,\n pattern,\n refine,\n string,\n union,\n validate,\n} from 'superstruct';\nimport validateNPMPackage from 'validate-npm-package-name';\n\nimport { SnapCaveatType } from './caveats';\nimport { checksumFiles } from './checksum';\nimport type { LocalizationFile } from './localization';\nimport type { SnapManifest, SnapPermissions } from './manifest/validation';\nimport type { FetchedSnapFiles, SnapsPermissionRequest } from './types';\nimport { SnapIdPrefixes, SnapValidationFailureReason, uri } from './types';\nimport type { VirtualFile } from './virtual-file';\n\n// This RegEx matches valid npm package names (with some exceptions) and space-\n// separated alphanumerical words, optionally with dashes and underscores.\n// The RegEx consists of two parts. The first part matches space-separated\n// words. It is based on the following Stackoverflow answer:\n// https://stackoverflow.com/a/34974982\n// The second part, after the pipe operator, is the same RegEx used for the\n// `name` field of the official package.json JSON Schema, except that we allow\n// mixed-case letters. It was originally copied from:\n// https://github.com/SchemaStore/schemastore/blob/81a16897c1dabfd98c72242a5fd62eb080ff76d8/src/schemas/json/package.json#L132-L138\nexport const PROPOSED_NAME_REGEX =\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\nexport enum SnapStatus {\n Installing = 'installing',\n Updating = 'updating',\n Running = 'running',\n Stopped = 'stopped',\n Crashed = 'crashed',\n}\n\nexport enum SnapStatusEvents {\n Start = 'START',\n Stop = 'STOP',\n Crash = 'CRASH',\n Update = 'UPDATE',\n}\n\nexport type StatusContext = { snapId: SnapId };\nexport type StatusEvents = { type: SnapStatusEvents };\nexport type StatusStates = {\n value: SnapStatus;\n context: StatusContext;\n};\nexport type Status = StatusStates['value'];\n\nexport type VersionHistory = {\n origin: string;\n version: string;\n // Unix timestamp\n date: number;\n};\n\nexport type SnapAuxilaryFile = {\n path: string;\n // Value here should be stored as base64\n value: string;\n};\n\nexport type PersistedSnap = Snap;\n\n/**\n * A Snap as it exists in {@link SnapController} state.\n */\nexport type Snap = TruncatedSnap & {\n /**\n * The initial permissions of the Snap, which will be requested when it is\n * installed.\n */\n initialPermissions: SnapPermissions;\n\n /**\n * The source code of the Snap.\n */\n sourceCode: string;\n\n /**\n * The Snap's manifest file.\n */\n manifest: SnapManifest;\n\n /**\n * Information detailing why the snap is blocked.\n */\n blockInformation?: BlockReason;\n\n /**\n * The current status of the Snap, e.g. whether it's running or stopped.\n */\n status: Status;\n\n /**\n * The version history of the Snap.\n * Can be used to derive when the Snap was installed, when it was updated to a certain version and who requested the change.\n */\n versionHistory: VersionHistory[];\n\n /**\n * Static auxiliary files that can be loaded at runtime.\n */\n auxiliaryFiles?: SnapAuxilaryFile[];\n\n /**\n * Localization files which are used to translate the manifest.\n */\n localizationFiles?: LocalizationFile[];\n\n /**\n * Flag to signal whether this snap was preinstalled or not.\n *\n * A lack of specifying this option will be deemed as not preinstalled.\n */\n preinstalled?: boolean;\n\n /**\n * Flag to signal whether this snap is removable or not.\n *\n * A lack of specifying this option will be deemed as removable.\n */\n removable?: boolean;\n};\n\nexport type TruncatedSnapFields =\n | 'id'\n | 'initialPermissions'\n | 'version'\n | 'enabled'\n | 'blocked';\n\n/**\n * An error indicating that a Snap validation failure is programmatically\n * fixable during development.\n */\nexport class ProgrammaticallyFixableSnapError extends Error {\n reason: SnapValidationFailureReason;\n\n constructor(message: string, reason: SnapValidationFailureReason) {\n super(message);\n this.reason = reason;\n }\n}\n\n/**\n * Gets a checksummable manifest by removing the shasum property and reserializing the JSON using a deterministic algorithm.\n *\n * @param manifest - The manifest itself.\n * @returns A virtual file containing the checksummable manifest.\n */\nfunction getChecksummableManifest(\n manifest: VirtualFile<SnapManifest>,\n): VirtualFile {\n const manifestCopy = manifest.clone() as VirtualFile<any>;\n delete manifestCopy.result.source.shasum;\n\n // We use fast-json-stable-stringify to deterministically serialize the JSON\n // This is required before checksumming so we get reproducible checksums across platforms etc\n manifestCopy.value = stableStringify(manifestCopy.result);\n return manifestCopy;\n}\n\n/**\n * Calculates the Base64-encoded SHA-256 digest of all required Snap files.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @returns The Base64-encoded SHA-256 digest of the source code.\n */\nexport async function getSnapChecksum(\n files: FetchedSnapFiles,\n): Promise<string> {\n const { manifest, sourceCode, svgIcon, auxiliaryFiles, localizationFiles } =\n files;\n\n const all = [\n getChecksummableManifest(manifest),\n sourceCode,\n svgIcon,\n ...auxiliaryFiles,\n ...localizationFiles,\n ].filter((file) => file !== undefined);\n\n return base64.encode(await checksumFiles(all as VirtualFile[]));\n}\n\n/**\n * Checks whether the `source.shasum` property of a Snap manifest matches the\n * shasum of the snap.\n *\n * @param files - All required Snap files to be included in the checksum.\n * @param errorMessage - The error message to throw if validation fails.\n */\nexport async function validateSnapShasum(\n files: FetchedSnapFiles,\n errorMessage = 'Invalid Snap manifest: manifest shasum does not match computed shasum.',\n): Promise<void> {\n if (files.manifest.result.source.shasum !== (await getSnapChecksum(files))) {\n throw new ProgrammaticallyFixableSnapError(\n errorMessage,\n SnapValidationFailureReason.ShasumMismatch,\n );\n }\n}\n\nexport const LOCALHOST_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]'] as const;\n\n// Require snap ids to only consist of printable ASCII characters\nexport const BaseSnapIdStruct = pattern(string(), /^[\\x21-\\x7E]*$/u);\n\nconst LocalSnapIdSubUrlStruct = uri({\n protocol: enums(['http:', 'https:']),\n hostname: enums(LOCALHOST_HOSTNAMES),\n hash: empty(string()),\n search: empty(string()),\n});\n\nexport const LocalSnapIdStruct = refine(\n BaseSnapIdStruct,\n 'local Snap Id',\n (value) => {\n if (!value.startsWith(SnapIdPrefixes.local)) {\n return `Expected local snap ID, got \"${value}\".`;\n }\n\n const [error] = validate(\n value.slice(SnapIdPrefixes.local.length),\n LocalSnapIdSubUrlStruct,\n );\n return error ?? true;\n },\n);\nexport const NpmSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: literal(SnapIdPrefixes.npm),\n pathname: refine(string(), 'package name', function* (value) {\n const normalized = value.startsWith('/') ? value.slice(1) : value;\n const { errors, validForNewPackages, warnings } =\n validateNPMPackage(normalized);\n if (!validForNewPackages) {\n if (errors === undefined) {\n assert(warnings !== undefined);\n yield* warnings;\n } else {\n yield* errors;\n }\n }\n return true;\n }),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const HttpSnapIdStruct = intersection([\n BaseSnapIdStruct,\n uri({\n protocol: enums(['http:', 'https:']),\n search: empty(string()),\n hash: empty(string()),\n }),\n]) as unknown as Struct<string, null>;\n\nexport const SnapIdStruct = union([NpmSnapIdStruct, LocalSnapIdStruct]);\n\n/**\n * Extracts the snap prefix from a snap ID.\n *\n * @param snapId - The snap ID to extract the prefix from.\n * @returns The snap prefix from a snap id, e.g. `npm:`.\n */\nexport function getSnapPrefix(snapId: string): SnapIdPrefixes {\n const prefix = Object.values(SnapIdPrefixes).find((possiblePrefix) =>\n snapId.startsWith(possiblePrefix),\n );\n if (prefix !== undefined) {\n return prefix;\n }\n throw new Error(`Invalid or no prefix found for \"${snapId}\"`);\n}\n\n/**\n * Strips snap prefix from a full snap ID.\n *\n * @param snapId - The snap ID to strip.\n * @returns The stripped snap ID.\n */\nexport function stripSnapPrefix(snapId: string): string {\n return snapId.replace(getSnapPrefix(snapId), '');\n}\n\n/**\n * Assert that the given value is a valid snap ID.\n *\n * @param value - The value to check.\n * @throws If the value is not a valid snap ID.\n */\nexport function assertIsValidSnapId(value: unknown): asserts value is SnapId {\n assertStruct(value, SnapIdStruct, 'Invalid snap ID');\n}\n\n/**\n * Typeguard to ensure a chainId follows the CAIP-2 standard.\n *\n * @param chainId - The chainId being tested.\n * @returns `true` if the value is a valid CAIP chain id, and `false` otherwise.\n */\nexport function isCaipChainId(chainId: unknown): chainId is string {\n return (\n typeof chainId === 'string' &&\n /^(?<namespace>[-a-z0-9]{3,8}):(?<reference>[-a-zA-Z0-9]{1,32})$/u.test(\n chainId,\n )\n );\n}\n\n/**\n * Utility function to check if an origin has permission (and caveat) for a particular snap.\n *\n * @param permissions - An origin's permissions object.\n * @param snapId - The id of the snap.\n * @returns A boolean based on if an origin has the specified snap.\n */\nexport function isSnapPermitted(\n permissions: SubjectPermissions<PermissionConstraint>,\n snapId: SnapId,\n) {\n return Boolean(\n (\n (\n (permissions?.wallet_snap?.caveats?.find(\n (caveat) => caveat.type === SnapCaveatType.SnapIds,\n ) ?? {}) as Caveat<string, Json>\n ).value as Record<string, unknown>\n )?.[snapId],\n );\n}\n\n/**\n * Checks whether the passed in requestedPermissions is a valid\n * permission request for a `wallet_snap` permission.\n *\n * @param requestedPermissions - The requested permissions.\n * @throws If the criteria is not met.\n */\nexport function verifyRequestedSnapPermissions(\n requestedPermissions: unknown,\n): asserts requestedPermissions is SnapsPermissionRequest {\n assert(\n isObject(requestedPermissions),\n 'Requested permissions must be an object.',\n );\n\n const { wallet_snap: walletSnapPermission } = requestedPermissions;\n\n assert(\n isObject(walletSnapPermission),\n 'wallet_snap is missing from the requested permissions.',\n );\n\n const { caveats } = walletSnapPermission;\n\n assert(\n Array.isArray(caveats) && caveats.length === 1,\n 'wallet_snap must have a caveat property with a single-item array value.',\n );\n\n const [caveat] = caveats;\n\n assert(\n isObject(caveat) &&\n caveat.type === SnapCaveatType.SnapIds &&\n isObject(caveat.value),\n `The requested permissions do not have a valid ${SnapCaveatType.SnapIds} caveat.`,\n );\n}\n\nexport type { Snap as TruncatedSnap } from '@metamask/snaps-sdk';\n"]}