@metamask/snaps-utils 7.0.1 → 7.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -1
- package/dist/{chunk-CNNMLOQ6.js → chunk-AWRMYDIN.js} +4 -4
- package/dist/{chunk-772OPTGX.js → chunk-EX4PPLND.js} +14 -8
- package/dist/chunk-EX4PPLND.js.map +1 -0
- package/dist/{chunk-44GPX66J.mjs → chunk-HDZ3BJBL.mjs} +14 -8
- package/dist/chunk-HDZ3BJBL.mjs.map +1 -0
- package/dist/{chunk-WF56W2AR.mjs → chunk-LGT3PBPZ.mjs} +2 -2
- package/dist/{chunk-4BDR6KRH.js → chunk-M3KAAQFK.js} +3 -2
- package/dist/chunk-M3KAAQFK.js.map +1 -0
- package/dist/{chunk-MCEKOGEG.mjs → chunk-MNCFAD4E.mjs} +4 -3
- package/dist/chunk-MNCFAD4E.mjs.map +1 -0
- package/dist/{chunk-224DMTNJ.mjs → chunk-PIG67G67.mjs} +2 -2
- package/dist/{chunk-Q7RCL5IE.js → chunk-YMUOYQFU.js} +3 -3
- package/dist/icon.js +2 -2
- package/dist/icon.mjs +1 -1
- package/dist/index.js +4 -4
- package/dist/index.mjs +3 -3
- package/dist/manifest/manifest.js +3 -3
- package/dist/manifest/manifest.mjs +2 -2
- package/dist/manifest/node.js +3 -3
- package/dist/manifest/node.mjs +2 -2
- package/dist/node.js +5 -5
- package/dist/node.mjs +4 -4
- package/dist/npm.js +3 -3
- package/dist/npm.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/handlers.d.ts +28 -14
- package/dist/ui.js +2 -2
- package/dist/ui.mjs +1 -1
- package/dist/validation.js +3 -3
- package/dist/validation.mjs +2 -2
- package/package.json +5 -4
- package/dist/chunk-44GPX66J.mjs.map +0 -1
- package/dist/chunk-4BDR6KRH.js.map +0 -1
- package/dist/chunk-772OPTGX.js.map +0 -1
- package/dist/chunk-MCEKOGEG.mjs.map +0 -1
- /package/dist/{chunk-CNNMLOQ6.js.map → chunk-AWRMYDIN.js.map} +0 -0
- /package/dist/{chunk-WF56W2AR.mjs.map → chunk-LGT3PBPZ.mjs.map} +0 -0
- /package/dist/{chunk-224DMTNJ.mjs.map → chunk-PIG67G67.mjs.map} +0 -0
- /package/dist/{chunk-Q7RCL5IE.js.map → chunk-YMUOYQFU.js.map} +0 -0
package/dist/types/handlers.d.ts
CHANGED
|
@@ -91,7 +91,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
|
|
|
91
91
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
92
92
|
markdown?: boolean | undefined;
|
|
93
93
|
} | {
|
|
94
|
-
value: string
|
|
94
|
+
value: `0x${string}`;
|
|
95
95
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
96
96
|
} | {
|
|
97
97
|
value: {
|
|
@@ -102,7 +102,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
|
|
|
102
102
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
103
103
|
markdown?: boolean | undefined;
|
|
104
104
|
} | {
|
|
105
|
-
value: string
|
|
105
|
+
value: `0x${string}`;
|
|
106
106
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
107
107
|
};
|
|
108
108
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
@@ -112,6 +112,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
|
|
|
112
112
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
113
113
|
name: string;
|
|
114
114
|
value?: string | undefined;
|
|
115
|
+
error?: string | undefined;
|
|
115
116
|
label?: string | undefined;
|
|
116
117
|
inputType?: "number" | "text" | "password" | undefined;
|
|
117
118
|
placeholder?: string | undefined;
|
|
@@ -128,6 +129,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
|
|
|
128
129
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
129
130
|
name: string;
|
|
130
131
|
value?: string | undefined;
|
|
132
|
+
error?: string | undefined;
|
|
131
133
|
label?: string | undefined;
|
|
132
134
|
inputType?: "number" | "text" | "password" | undefined;
|
|
133
135
|
placeholder?: string | undefined;
|
|
@@ -160,7 +162,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
|
|
|
160
162
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
161
163
|
markdown?: boolean | undefined;
|
|
162
164
|
} | {
|
|
163
|
-
value: string
|
|
165
|
+
value: `0x${string}`;
|
|
164
166
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
165
167
|
} | {
|
|
166
168
|
value: {
|
|
@@ -171,7 +173,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
|
|
|
171
173
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
172
174
|
markdown?: boolean | undefined;
|
|
173
175
|
} | {
|
|
174
|
-
value: string
|
|
176
|
+
value: `0x${string}`;
|
|
175
177
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
176
178
|
};
|
|
177
179
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
@@ -181,6 +183,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
|
|
|
181
183
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
182
184
|
name: string;
|
|
183
185
|
value?: string | undefined;
|
|
186
|
+
error?: string | undefined;
|
|
184
187
|
label?: string | undefined;
|
|
185
188
|
inputType?: "number" | "text" | "password" | undefined;
|
|
186
189
|
placeholder?: string | undefined;
|
|
@@ -197,6 +200,7 @@ export declare const OnTransactionResponseWithContentStruct: import("superstruct
|
|
|
197
200
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
198
201
|
name: string;
|
|
199
202
|
value?: string | undefined;
|
|
203
|
+
error?: string | undefined;
|
|
200
204
|
label?: string | undefined;
|
|
201
205
|
inputType?: "number" | "text" | "password" | undefined;
|
|
202
206
|
placeholder?: string | undefined;
|
|
@@ -233,7 +237,7 @@ export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
|
|
|
233
237
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
234
238
|
markdown?: boolean | undefined;
|
|
235
239
|
} | {
|
|
236
|
-
value: string
|
|
240
|
+
value: `0x${string}`;
|
|
237
241
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
238
242
|
} | {
|
|
239
243
|
value: {
|
|
@@ -244,7 +248,7 @@ export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
|
|
|
244
248
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
245
249
|
markdown?: boolean | undefined;
|
|
246
250
|
} | {
|
|
247
|
-
value: string
|
|
251
|
+
value: `0x${string}`;
|
|
248
252
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
249
253
|
};
|
|
250
254
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
@@ -254,6 +258,7 @@ export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
|
|
|
254
258
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
255
259
|
name: string;
|
|
256
260
|
value?: string | undefined;
|
|
261
|
+
error?: string | undefined;
|
|
257
262
|
label?: string | undefined;
|
|
258
263
|
inputType?: "number" | "text" | "password" | undefined;
|
|
259
264
|
placeholder?: string | undefined;
|
|
@@ -270,6 +275,7 @@ export declare const OnTransactionResponseStruct: import("superstruct").Struct<{
|
|
|
270
275
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
271
276
|
name: string;
|
|
272
277
|
value?: string | undefined;
|
|
278
|
+
error?: string | undefined;
|
|
273
279
|
label?: string | undefined;
|
|
274
280
|
inputType?: "number" | "text" | "password" | undefined;
|
|
275
281
|
placeholder?: string | undefined;
|
|
@@ -306,7 +312,7 @@ export declare const OnSignatureResponseStruct: import("superstruct").Struct<{
|
|
|
306
312
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
307
313
|
markdown?: boolean | undefined;
|
|
308
314
|
} | {
|
|
309
|
-
value: string
|
|
315
|
+
value: `0x${string}`;
|
|
310
316
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
311
317
|
} | {
|
|
312
318
|
value: {
|
|
@@ -317,7 +323,7 @@ export declare const OnSignatureResponseStruct: import("superstruct").Struct<{
|
|
|
317
323
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
318
324
|
markdown?: boolean | undefined;
|
|
319
325
|
} | {
|
|
320
|
-
value: string
|
|
326
|
+
value: `0x${string}`;
|
|
321
327
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
322
328
|
};
|
|
323
329
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
@@ -327,6 +333,7 @@ export declare const OnSignatureResponseStruct: import("superstruct").Struct<{
|
|
|
327
333
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
328
334
|
name: string;
|
|
329
335
|
value?: string | undefined;
|
|
336
|
+
error?: string | undefined;
|
|
330
337
|
label?: string | undefined;
|
|
331
338
|
inputType?: "number" | "text" | "password" | undefined;
|
|
332
339
|
placeholder?: string | undefined;
|
|
@@ -343,6 +350,7 @@ export declare const OnSignatureResponseStruct: import("superstruct").Struct<{
|
|
|
343
350
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
344
351
|
name: string;
|
|
345
352
|
value?: string | undefined;
|
|
353
|
+
error?: string | undefined;
|
|
346
354
|
label?: string | undefined;
|
|
347
355
|
inputType?: "number" | "text" | "password" | undefined;
|
|
348
356
|
placeholder?: string | undefined;
|
|
@@ -376,7 +384,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
|
|
|
376
384
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
377
385
|
markdown?: boolean | undefined;
|
|
378
386
|
} | {
|
|
379
|
-
value: string
|
|
387
|
+
value: `0x${string}`;
|
|
380
388
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
381
389
|
} | {
|
|
382
390
|
value: {
|
|
@@ -387,7 +395,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
|
|
|
387
395
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
388
396
|
markdown?: boolean | undefined;
|
|
389
397
|
} | {
|
|
390
|
-
value: string
|
|
398
|
+
value: `0x${string}`;
|
|
391
399
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
392
400
|
};
|
|
393
401
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
@@ -397,6 +405,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
|
|
|
397
405
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
398
406
|
name: string;
|
|
399
407
|
value?: string | undefined;
|
|
408
|
+
error?: string | undefined;
|
|
400
409
|
label?: string | undefined;
|
|
401
410
|
inputType?: "number" | "text" | "password" | undefined;
|
|
402
411
|
placeholder?: string | undefined;
|
|
@@ -413,6 +422,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
|
|
|
413
422
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
414
423
|
name: string;
|
|
415
424
|
value?: string | undefined;
|
|
425
|
+
error?: string | undefined;
|
|
416
426
|
label?: string | undefined;
|
|
417
427
|
inputType?: "number" | "text" | "password" | undefined;
|
|
418
428
|
placeholder?: string | undefined;
|
|
@@ -444,7 +454,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
|
|
|
444
454
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
445
455
|
markdown?: boolean | undefined;
|
|
446
456
|
} | {
|
|
447
|
-
value: string
|
|
457
|
+
value: `0x${string}`;
|
|
448
458
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
449
459
|
} | {
|
|
450
460
|
value: {
|
|
@@ -455,7 +465,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
|
|
|
455
465
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
456
466
|
markdown?: boolean | undefined;
|
|
457
467
|
} | {
|
|
458
|
-
value: string
|
|
468
|
+
value: `0x${string}`;
|
|
459
469
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
460
470
|
};
|
|
461
471
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
@@ -465,6 +475,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
|
|
|
465
475
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
466
476
|
name: string;
|
|
467
477
|
value?: string | undefined;
|
|
478
|
+
error?: string | undefined;
|
|
468
479
|
label?: string | undefined;
|
|
469
480
|
inputType?: "number" | "text" | "password" | undefined;
|
|
470
481
|
placeholder?: string | undefined;
|
|
@@ -481,6 +492,7 @@ export declare const OnHomePageResponseWithContentStruct: import("superstruct").
|
|
|
481
492
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
482
493
|
name: string;
|
|
483
494
|
value?: string | undefined;
|
|
495
|
+
error?: string | undefined;
|
|
484
496
|
label?: string | undefined;
|
|
485
497
|
inputType?: "number" | "text" | "password" | undefined;
|
|
486
498
|
placeholder?: string | undefined;
|
|
@@ -518,7 +530,7 @@ export declare const OnHomePageResponseStruct: import("superstruct").Struct<{
|
|
|
518
530
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
519
531
|
markdown?: boolean | undefined;
|
|
520
532
|
} | {
|
|
521
|
-
value: string
|
|
533
|
+
value: `0x${string}`;
|
|
522
534
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
523
535
|
} | {
|
|
524
536
|
value: {
|
|
@@ -529,7 +541,7 @@ export declare const OnHomePageResponseStruct: import("superstruct").Struct<{
|
|
|
529
541
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
530
542
|
markdown?: boolean | undefined;
|
|
531
543
|
} | {
|
|
532
|
-
value: string
|
|
544
|
+
value: `0x${string}`;
|
|
533
545
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
534
546
|
};
|
|
535
547
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
@@ -539,6 +551,7 @@ export declare const OnHomePageResponseStruct: import("superstruct").Struct<{
|
|
|
539
551
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
540
552
|
name: string;
|
|
541
553
|
value?: string | undefined;
|
|
554
|
+
error?: string | undefined;
|
|
542
555
|
label?: string | undefined;
|
|
543
556
|
inputType?: "number" | "text" | "password" | undefined;
|
|
544
557
|
placeholder?: string | undefined;
|
|
@@ -555,6 +568,7 @@ export declare const OnHomePageResponseStruct: import("superstruct").Struct<{
|
|
|
555
568
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
556
569
|
name: string;
|
|
557
570
|
value?: string | undefined;
|
|
571
|
+
error?: string | undefined;
|
|
558
572
|
label?: string | undefined;
|
|
559
573
|
inputType?: "number" | "text" | "password" | undefined;
|
|
560
574
|
placeholder?: string | undefined;
|
package/dist/ui.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkEX4PPLNDjs = require('./chunk-EX4PPLND.js');
|
|
6
6
|
require('./chunk-PHUTP7NB.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
11
|
-
exports.getTotalTextLength =
|
|
11
|
+
exports.getTotalTextLength = _chunkEX4PPLNDjs.getTotalTextLength; exports.validateComponentLinks = _chunkEX4PPLNDjs.validateComponentLinks; exports.validateTextLinks = _chunkEX4PPLNDjs.validateTextLinks;
|
|
12
12
|
//# sourceMappingURL=ui.js.map
|
package/dist/ui.mjs
CHANGED
package/dist/validation.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkYMUOYQFUjs = require('./chunk-YMUOYQFU.js');
|
|
4
4
|
require('./chunk-ENKAY3PI.js');
|
|
5
5
|
require('./chunk-TG4BDSYJ.js');
|
|
6
|
-
require('./chunk-
|
|
6
|
+
require('./chunk-M3KAAQFK.js');
|
|
7
7
|
require('./chunk-6LOYTBS3.js');
|
|
8
8
|
require('./chunk-CMOSYNZR.js');
|
|
9
9
|
require('./chunk-CQRPSEH3.js');
|
|
@@ -20,5 +20,5 @@ require('./chunk-NUCLSR2G.js');
|
|
|
20
20
|
require('./chunk-PHUTP7NB.js');
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
exports.validateFetchedSnap =
|
|
23
|
+
exports.validateFetchedSnap = _chunkYMUOYQFUjs.validateFetchedSnap;
|
|
24
24
|
//# sourceMappingURL=validation.js.map
|
package/dist/validation.mjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
validateFetchedSnap
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-LGT3PBPZ.mjs";
|
|
4
4
|
import "./chunk-LCWDLIK5.mjs";
|
|
5
5
|
import "./chunk-2IWSQJKQ.mjs";
|
|
6
|
-
import "./chunk-
|
|
6
|
+
import "./chunk-MNCFAD4E.mjs";
|
|
7
7
|
import "./chunk-EXUEHPZ4.mjs";
|
|
8
8
|
import "./chunk-T6FWIDA6.mjs";
|
|
9
9
|
import "./chunk-DKDGMZFU.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-utils",
|
|
3
|
-
"version": "7.0.
|
|
3
|
+
"version": "7.0.3",
|
|
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": "^8.0.1",
|
|
58
58
|
"@metamask/rpc-errors": "^6.2.1",
|
|
59
59
|
"@metamask/slip44": "^3.1.0",
|
|
60
|
-
"@metamask/snaps-registry": "^3.0.
|
|
61
|
-
"@metamask/snaps-sdk": "^3.
|
|
60
|
+
"@metamask/snaps-registry": "^3.0.1",
|
|
61
|
+
"@metamask/snaps-sdk": "^3.1.1",
|
|
62
62
|
"@metamask/utils": "^8.3.0",
|
|
63
63
|
"@noble/hashes": "^1.3.1",
|
|
64
64
|
"@scure/base": "^1.1.1",
|
|
@@ -66,6 +66,7 @@
|
|
|
66
66
|
"cron-parser": "^4.5.0",
|
|
67
67
|
"fast-deep-equal": "^3.1.3",
|
|
68
68
|
"fast-json-stable-stringify": "^2.1.0",
|
|
69
|
+
"marked": "^12.0.1",
|
|
69
70
|
"rfdc": "^1.3.0",
|
|
70
71
|
"semver": "^7.5.4",
|
|
71
72
|
"ses": "^1.1.0",
|
|
@@ -75,7 +76,7 @@
|
|
|
75
76
|
"devDependencies": {
|
|
76
77
|
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
|
|
77
78
|
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
|
|
78
|
-
"@lavamoat/allow-scripts": "^3.0.
|
|
79
|
+
"@lavamoat/allow-scripts": "^3.0.3",
|
|
79
80
|
"@metamask/auto-changelog": "^3.4.4",
|
|
80
81
|
"@metamask/eslint-config": "^12.1.0",
|
|
81
82
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
@@ -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';\n\nconst MARKDOWN_LINK_REGEX = /\\[(?<name>[^\\]]*)\\]\\((?<url>[^)]+)\\)/giu;\n\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\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 matches = String.prototype.matchAll.call(text, MARKDOWN_LINK_REGEX);\n\n for (const { groups } of matches) {\n const link = groups?.url;\n\n /* This case should never happen with the regex but the TS type allows for undefined */\n /* istanbul ignore next */\n if (!link) {\n continue;\n }\n\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,IAAM,sBAAsB;AAE5B,IAAM,oBAAoB,CAAC,UAAU,SAAS;AAU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nimport { assert } from '@metamask/utils';\n\nimport type { VirtualFile } from './virtual-file';\n\nexport const SVG_MAX_BYTE_SIZE = 100_000;\nexport const SVG_MAX_BYTE_SIZE_TEXT = `${Math.floor(\n SVG_MAX_BYTE_SIZE / 1000,\n)}kb`;\n\n/**\n * Assert that a virtual file containing a Snap icon is valid.\n *\n * @param icon - A virtual file containing a Snap icon.\n */\nexport function assertIsSnapIcon(icon: VirtualFile) {\n assert(icon.path.endsWith('.svg'), 'Expected snap icon to end in \".svg\".');\n\n assert(\n Buffer.byteLength(icon.value, 'utf8') <= SVG_MAX_BYTE_SIZE,\n `The specified SVG icon exceeds the maximum size of ${SVG_MAX_BYTE_SIZE_TEXT}.`,\n );\n\n assert(isSvg(icon.toString()), 'Snap icon must be a valid SVG.');\n}\n\n/**\n * Extract the dimensions of an image from an SVG string if possible.\n *\n * @param svg - An SVG string.\n * @returns The height and width of the SVG or null.\n */\nexport function getSvgDimensions(svg: string): {\n height: number;\n width: number;\n} | null {\n try {\n const parsed = parseSvg(svg);\n\n const height = parsed['@_height'];\n const width = parsed['@_width'];\n\n if (height && width) {\n return { height, width };\n }\n\n const viewBox = parsed['@_viewBox'];\n if (viewBox) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [_minX, _minY, viewBoxWidth, viewBoxHeight] = viewBox.split(' ');\n\n if (viewBoxWidth && viewBoxHeight) {\n const parsedWidth = parseInt(viewBoxWidth, 10);\n const parsedHeight = parseInt(viewBoxHeight, 10);\n\n assert(Number.isInteger(parsedWidth) && parsedWidth > 0);\n assert(Number.isInteger(parsedHeight) && parsedHeight > 0);\n\n return {\n width: parsedWidth,\n height: parsedHeight,\n };\n }\n }\n } catch {\n throw new Error('Snap icon must be a valid SVG.');\n }\n\n return null;\n}\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/ui.ts"],"names":[],"mappings":";AACA,SAAS,gBAAgB;AACzB,SAAS,QAAQ,sBAAsB;AAEvC,IAAM,s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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';\n\nconst MARKDOWN_LINK_REGEX = /\\[(?<name>[^\\]]*)\\]\\((?<url>[^)]+)\\)/giu;\n\nconst ALLOWED_PROTOCOLS = ['https:', 'mailto:'];\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 matches = String.prototype.matchAll.call(text, MARKDOWN_LINK_REGEX);\n\n for (const { groups } of matches) {\n const link = groups?.url;\n\n /* This case should never happen with the regex but the TS type allows for undefined */\n /* istanbul ignore next */\n if (!link) {\n continue;\n }\n\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/icon.ts"],"sourcesContent":["import { isSvg, parseSvg } from '@metamask/snaps-sdk';\nimport { assert } from '@metamask/utils';\n\nimport type { VirtualFile } from './virtual-file';\n\nexport const SVG_MAX_BYTE_SIZE = 100_000;\nexport const SVG_MAX_BYTE_SIZE_TEXT = `${Math.floor(\n SVG_MAX_BYTE_SIZE / 1000,\n)}kb`;\n\n/**\n * Assert that a virtual file containing a Snap icon is valid.\n *\n * @param icon - A virtual file containing a Snap icon.\n */\nexport function assertIsSnapIcon(icon: VirtualFile) {\n assert(icon.path.endsWith('.svg'), 'Expected snap icon to end in \".svg\".');\n\n assert(\n Buffer.byteLength(icon.value, 'utf8') <= SVG_MAX_BYTE_SIZE,\n `The specified SVG icon exceeds the maximum size of ${SVG_MAX_BYTE_SIZE_TEXT}.`,\n );\n\n assert(isSvg(icon.toString()), 'Snap icon must be a valid SVG.');\n}\n\n/**\n * Extract the dimensions of an image from an SVG string if possible.\n *\n * @param svg - An SVG string.\n * @returns The height and width of the SVG or null.\n */\nexport function getSvgDimensions(svg: string): {\n height: number;\n width: number;\n} | null {\n try {\n const parsed = parseSvg(svg);\n\n const height = parsed['@_height'];\n const width = parsed['@_width'];\n\n if (height && width) {\n return { height, width };\n }\n\n const viewBox = parsed['@_viewBox'];\n if (viewBox) {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n const [_minX, _minY, viewBoxWidth, viewBoxHeight] = viewBox.split(' ');\n\n if (viewBoxWidth && viewBoxHeight) {\n const parsedWidth = parseInt(viewBoxWidth, 10);\n const parsedHeight = parseInt(viewBoxHeight, 10);\n\n assert(Number.isInteger(parsedWidth) && parsedWidth > 0);\n assert(Number.isInteger(parsedHeight) && parsedHeight > 0);\n\n return {\n width: parsedWidth,\n height: parsedHeight,\n };\n }\n }\n } catch {\n throw new Error('Snap icon must be a valid SVG.');\n }\n\n return null;\n}\n"],"mappings":";AAAA,SAAS,OAAO,gBAAgB;AAChC,SAAS,cAAc;AAIhB,IAAM,oBAAoB;AAC1B,IAAM,yBAAyB,GAAG,KAAK;AAAA,EAC5C,oBAAoB;AACtB,CAAC;AAOM,SAAS,iBAAiB,MAAmB;AAClD,SAAO,KAAK,KAAK,SAAS,MAAM,GAAG,sCAAsC;AAEzE;AAAA,IACE,OAAO,WAAW,KAAK,OAAO,MAAM,KAAK;AAAA,IACzC,sDAAsD,sBAAsB;AAAA,EAC9E;AAEA,SAAO,MAAM,KAAK,SAAS,CAAC,GAAG,gCAAgC;AACjE;AAQO,SAAS,iBAAiB,KAGxB;AACP,MAAI;AACF,UAAM,SAAS,SAAS,GAAG;AAE3B,UAAM,SAAS,OAAO,UAAU;AAChC,UAAM,QAAQ,OAAO,SAAS;AAE9B,QAAI,UAAU,OAAO;AACnB,aAAO,EAAE,QAAQ,MAAM;AAAA,IACzB;AAEA,UAAM,UAAU,OAAO,WAAW;AAClC,QAAI,SAAS;AAEX,YAAM,CAAC,OAAO,OAAO,cAAc,aAAa,IAAI,QAAQ,MAAM,GAAG;AAErE,UAAI,gBAAgB,eAAe;AACjC,cAAM,cAAc,SAAS,cAAc,EAAE;AAC7C,cAAM,eAAe,SAAS,eAAe,EAAE;AAE/C,eAAO,OAAO,UAAU,WAAW,KAAK,cAAc,CAAC;AACvD,eAAO,OAAO,UAAU,YAAY,KAAK,eAAe,CAAC;AAEzD,eAAO;AAAA,UACL,OAAO;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,MACF;AAAA,IACF;AAAA,EACF,QAAQ;AACN,UAAM,IAAI,MAAM,gCAAgC;AAAA,EAClD;AAEA,SAAO;AACT;","names":[]}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|