@metamask/snaps-utils 4.0.0 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/cjs/cronjob.js +6 -7
  3. package/dist/cjs/cronjob.js.map +1 -1
  4. package/dist/cjs/index.browser.js +0 -1
  5. package/dist/cjs/index.browser.js.map +1 -1
  6. package/dist/cjs/index.js +0 -1
  7. package/dist/cjs/index.js.map +1 -1
  8. package/dist/cjs/manifest/manifest.js +4 -3
  9. package/dist/cjs/manifest/manifest.js.map +1 -1
  10. package/dist/cjs/structs.js +0 -22
  11. package/dist/cjs/structs.js.map +1 -1
  12. package/dist/cjs/ui.js +16 -14
  13. package/dist/cjs/ui.js.map +1 -1
  14. package/dist/esm/cronjob.js +8 -9
  15. package/dist/esm/cronjob.js.map +1 -1
  16. package/dist/esm/index.browser.js +0 -1
  17. package/dist/esm/index.browser.js.map +1 -1
  18. package/dist/esm/index.js +0 -1
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/manifest/manifest.js +5 -3
  21. package/dist/esm/manifest/manifest.js.map +1 -1
  22. package/dist/esm/structs.js +1 -48
  23. package/dist/esm/structs.js.map +1 -1
  24. package/dist/esm/ui.js +18 -16
  25. package/dist/esm/ui.js.map +1 -1
  26. package/dist/types/cronjob.d.ts +15 -15
  27. package/dist/types/handlers.d.ts +72 -0
  28. package/dist/types/index.browser.d.ts +0 -1
  29. package/dist/types/index.d.ts +0 -1
  30. package/dist/types/localization.d.ts +1 -1
  31. package/dist/types/manifest/manifest.d.ts +3 -1
  32. package/dist/types/manifest/validation.d.ts +17 -17
  33. package/dist/types/structs.d.ts +2 -40
  34. package/dist/types/ui.d.ts +1 -1
  35. package/package.json +4 -4
  36. package/dist/cjs/enum.js +0 -16
  37. package/dist/cjs/enum.js.map +0 -1
  38. package/dist/esm/enum.js +0 -12
  39. package/dist/esm/enum.js.map +0 -1
  40. package/dist/types/enum.d.ts +0 -10
@@ -66,9 +66,9 @@ export declare const PermissionsStruct: Struct<{
66
66
  jobs: {
67
67
  request: {
68
68
  method: string;
69
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
70
69
  id?: string | number | null | undefined;
71
70
  jsonrpc?: "2.0" | undefined;
71
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
72
72
  };
73
73
  expression: string;
74
74
  }[];
@@ -95,9 +95,9 @@ export declare const PermissionsStruct: Struct<{
95
95
  jobs: {
96
96
  request: {
97
97
  method: string;
98
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
99
98
  id?: string | number | null | undefined;
100
99
  jsonrpc?: "2.0" | undefined;
100
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
101
101
  };
102
102
  expression: string;
103
103
  }[];
@@ -105,31 +105,31 @@ export declare const PermissionsStruct: Struct<{
105
105
  jobs: Struct<{
106
106
  request: {
107
107
  method: string;
108
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
109
108
  id?: string | number | null | undefined;
110
109
  jsonrpc?: "2.0" | undefined;
110
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
111
111
  };
112
112
  expression: string;
113
113
  }[], Struct<{
114
114
  request: {
115
115
  method: string;
116
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
117
116
  id?: string | number | null | undefined;
118
117
  jsonrpc?: "2.0" | undefined;
118
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
119
119
  };
120
120
  expression: string;
121
121
  }, {
122
122
  expression: Struct<string, null>;
123
123
  request: Struct<{
124
124
  method: string;
125
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
126
125
  id?: string | number | null | undefined;
127
126
  jsonrpc?: "2.0" | undefined;
127
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
128
128
  }, {
129
- params: Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
129
+ jsonrpc: Struct<"2.0" | undefined, "2.0">;
130
+ id: Struct<string | number | null | undefined, null>;
130
131
  method: Struct<string, null>;
131
- id: Struct<string | number | null | undefined, unknown>;
132
- jsonrpc: Struct<"2.0" | undefined, unknown>;
132
+ params: Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
133
133
  }>;
134
134
  }>>;
135
135
  }>;
@@ -239,9 +239,9 @@ export declare const SnapManifestStruct: Struct<{
239
239
  jobs: {
240
240
  request: {
241
241
  method: string;
242
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
243
242
  id?: string | number | null | undefined;
244
243
  jsonrpc?: "2.0" | undefined;
244
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
245
245
  };
246
246
  expression: string;
247
247
  }[];
@@ -340,9 +340,9 @@ export declare const SnapManifestStruct: Struct<{
340
340
  jobs: {
341
341
  request: {
342
342
  method: string;
343
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
344
343
  id?: string | number | null | undefined;
345
344
  jsonrpc?: "2.0" | undefined;
345
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
346
346
  };
347
347
  expression: string;
348
348
  }[];
@@ -369,9 +369,9 @@ export declare const SnapManifestStruct: Struct<{
369
369
  jobs: {
370
370
  request: {
371
371
  method: string;
372
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
373
372
  id?: string | number | null | undefined;
374
373
  jsonrpc?: "2.0" | undefined;
374
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
375
375
  };
376
376
  expression: string;
377
377
  }[];
@@ -379,31 +379,31 @@ export declare const SnapManifestStruct: Struct<{
379
379
  jobs: Struct<{
380
380
  request: {
381
381
  method: string;
382
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
383
382
  id?: string | number | null | undefined;
384
383
  jsonrpc?: "2.0" | undefined;
384
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
385
385
  };
386
386
  expression: string;
387
387
  }[], Struct<{
388
388
  request: {
389
389
  method: string;
390
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
391
390
  id?: string | number | null | undefined;
392
391
  jsonrpc?: "2.0" | undefined;
392
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
393
393
  };
394
394
  expression: string;
395
395
  }, {
396
396
  expression: Struct<string, null>;
397
397
  request: Struct<{
398
398
  method: string;
399
- params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
400
399
  id?: string | number | null | undefined;
401
400
  jsonrpc?: "2.0" | undefined;
401
+ params?: Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined;
402
402
  }, {
403
- params: Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
403
+ jsonrpc: Struct<"2.0" | undefined, "2.0">;
404
+ id: Struct<string | number | null | undefined, null>;
404
405
  method: Struct<string, null>;
405
- id: Struct<string | number | null | undefined, unknown>;
406
- jsonrpc: Struct<"2.0" | undefined, unknown>;
406
+ params: Struct<Record<string, import("@metamask/snaps-sdk").Json> | import("@metamask/snaps-sdk").Json[] | undefined, null>;
407
407
  }>;
408
408
  }>>;
409
409
  }>;
@@ -1,6 +1,6 @@
1
- import type { Failure, Infer } from 'superstruct';
1
+ import type { Failure } from 'superstruct';
2
2
  import { Struct, StructError } from 'superstruct';
3
- import type { AnyStruct, InferStructTuple } from 'superstruct/dist/utils';
3
+ import type { AnyStruct } from 'superstruct/dist/utils';
4
4
  /**
5
5
  * Infer a struct type, only if it matches the specified type. This is useful
6
6
  * for defining types and structs that are related to each other in separate
@@ -24,44 +24,6 @@ import type { AnyStruct, InferStructTuple } from 'superstruct/dist/utils';
24
24
  * ```
25
25
  */
26
26
  export declare type InferMatching<StructType extends Struct<any, any>, Type> = StructType['TYPE'] extends Type ? Type : never;
27
- /**
28
- * A wrapper of `superstruct`'s `literal` struct that also defines the name of
29
- * the struct as the literal value.
30
- *
31
- * This is useful for improving the error messages returned by `superstruct`.
32
- * For example, instead of returning an error like:
33
- *
34
- * ```
35
- * Expected the value to satisfy a union of `literal | literal`, but received: \"baz\"
36
- * ```
37
- *
38
- * This struct will return an error like:
39
- *
40
- * ```
41
- * Expected the value to satisfy a union of `"foo" | "bar"`, but received: \"baz\"
42
- * ```
43
- *
44
- * @param value - The literal value.
45
- * @returns The `superstruct` struct, which validates that the value is equal
46
- * to the literal value.
47
- */
48
- export declare function literal<Type extends string | number | boolean>(value: Type): Struct<Type, null>;
49
- /**
50
- * A wrapper of `superstruct`'s `union` struct that also defines the schema as
51
- * the union of the schemas of the structs.
52
- *
53
- * This is useful for improving the error messages returned by `superstruct`.
54
- *
55
- * @param structs - The structs to union.
56
- * @param structs."0" - The first struct.
57
- * @param structs."1" - The remaining structs.
58
- * @returns The `superstruct` struct, which validates that the value satisfies
59
- * one of the structs.
60
- */
61
- export declare function union<Head extends AnyStruct, Tail extends AnyStruct[]>([head, ...tail]: [head: Head, ...tail: Tail]): Struct<Infer<Head> | InferStructTuple<Tail>[number], [
62
- head: Head,
63
- ...tail: Tail
64
- ]>;
65
27
  /**
66
28
  * A wrapper of `superstruct`'s `string` struct that coerces a value to a string
67
29
  * and resolves it relative to the current working directory. This is useful
@@ -1,6 +1,6 @@
1
1
  import type { Component } from '@metamask/snaps-sdk';
2
2
  /**
3
- * Search for links in a sting and check them against the phishing list.
3
+ * Searches for markdown links in a string and checks them against the phishing list.
4
4
  *
5
5
  * @param text - The text to verify.
6
6
  * @param isOnPhishingList - The function that checks the link against the
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-utils",
3
- "version": "4.0.0",
3
+ "version": "5.0.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/MetaMask/snaps.git"
@@ -69,11 +69,11 @@
69
69
  "@babel/types": "^7.23.0",
70
70
  "@metamask/base-controller": "^3.2.0",
71
71
  "@metamask/key-tree": "^9.0.0",
72
- "@metamask/permission-controller": "^5.0.0",
72
+ "@metamask/permission-controller": "^5.0.1",
73
73
  "@metamask/rpc-errors": "^6.1.0",
74
74
  "@metamask/snaps-registry": "^2.1.0",
75
- "@metamask/snaps-sdk": "^1.0.0",
76
- "@metamask/utils": "^8.1.0",
75
+ "@metamask/snaps-sdk": "^1.2.0",
76
+ "@metamask/utils": "^8.2.1",
77
77
  "@noble/hashes": "^1.3.1",
78
78
  "@scure/base": "^1.1.1",
79
79
  "chalk": "^4.1.2",
package/dist/cjs/enum.js DELETED
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- Object.defineProperty(exports, "enumValue", {
6
- enumerable: true,
7
- get: function() {
8
- return enumValue;
9
- }
10
- });
11
- const _structs = require("./structs");
12
- function enumValue(constant) {
13
- return (0, _structs.literal)(constant);
14
- }
15
-
16
- //# sourceMappingURL=enum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/enum.ts"],"sourcesContent":["import type { EnumToUnion } from '@metamask/snaps-sdk';\nimport type { Struct } from 'superstruct';\n\nimport { literal } from './structs';\n\n/**\n * Superstruct struct for validating an enum value. This allows using both the\n * enum string values and the enum itself as values.\n *\n * @param constant - The enum to validate against.\n * @returns The superstruct struct.\n */\nexport function enumValue<Type extends string>(\n constant: Type,\n): Struct<EnumToUnion<Type>, null> {\n return literal(constant as EnumToUnion<Type>);\n}\n"],"names":["enumValue","constant","literal"],"mappings":";;;;+BAYgBA;;;eAAAA;;;yBATQ;AASjB,SAASA,UACdC,QAAc;IAEd,OAAOC,IAAAA,gBAAO,EAACD;AACjB"}
package/dist/esm/enum.js DELETED
@@ -1,12 +0,0 @@
1
- import { literal } from './structs';
2
- /**
3
- * Superstruct struct for validating an enum value. This allows using both the
4
- * enum string values and the enum itself as values.
5
- *
6
- * @param constant - The enum to validate against.
7
- * @returns The superstruct struct.
8
- */ export function enumValue(constant) {
9
- return literal(constant);
10
- }
11
-
12
- //# sourceMappingURL=enum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/enum.ts"],"sourcesContent":["import type { EnumToUnion } from '@metamask/snaps-sdk';\nimport type { Struct } from 'superstruct';\n\nimport { literal } from './structs';\n\n/**\n * Superstruct struct for validating an enum value. This allows using both the\n * enum string values and the enum itself as values.\n *\n * @param constant - The enum to validate against.\n * @returns The superstruct struct.\n */\nexport function enumValue<Type extends string>(\n constant: Type,\n): Struct<EnumToUnion<Type>, null> {\n return literal(constant as EnumToUnion<Type>);\n}\n"],"names":["literal","enumValue","constant"],"mappings":"AAGA,SAASA,OAAO,QAAQ,YAAY;AAEpC;;;;;;CAMC,GACD,OAAO,SAASC,UACdC,QAAc;IAEd,OAAOF,QAAQE;AACjB"}
@@ -1,10 +0,0 @@
1
- import type { EnumToUnion } from '@metamask/snaps-sdk';
2
- import type { Struct } from 'superstruct';
3
- /**
4
- * Superstruct struct for validating an enum value. This allows using both the
5
- * enum string values and the enum itself as values.
6
- *
7
- * @param constant - The enum to validate against.
8
- * @returns The superstruct struct.
9
- */
10
- export declare function enumValue<Type extends string>(constant: Type): Struct<EnumToUnion<Type>, null>;