@metamask/snaps-utils 0.34.0-flask.1 → 0.35.0-flask.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (249) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/dist/cjs/array.js +23 -0
  3. package/dist/cjs/array.js.map +1 -0
  4. package/dist/cjs/caveats.js +33 -0
  5. package/dist/cjs/caveats.js.map +1 -0
  6. package/dist/cjs/checksum.js +38 -0
  7. package/dist/cjs/checksum.js.map +1 -0
  8. package/dist/cjs/cronjob.js +84 -0
  9. package/dist/cjs/cronjob.js.map +1 -0
  10. package/dist/cjs/deep-clone.js +22 -0
  11. package/dist/cjs/deep-clone.js.map +1 -0
  12. package/dist/cjs/default-endowments.js +49 -0
  13. package/dist/cjs/default-endowments.js.map +1 -0
  14. package/dist/cjs/entropy.js +23 -0
  15. package/dist/cjs/entropy.js.map +1 -0
  16. package/dist/cjs/enum.js +16 -0
  17. package/dist/cjs/enum.js.map +1 -0
  18. package/dist/{eval-worker.js → cjs/eval-worker.js} +22 -21
  19. package/dist/cjs/eval-worker.js.map +1 -0
  20. package/dist/cjs/eval.js +29 -0
  21. package/dist/cjs/eval.js.map +1 -0
  22. package/dist/cjs/fs.js +126 -0
  23. package/dist/cjs/fs.js.map +1 -0
  24. package/dist/cjs/handlers.js +6 -0
  25. package/dist/cjs/handlers.js.map +1 -0
  26. package/dist/cjs/icon.js +37 -0
  27. package/dist/cjs/icon.js.map +1 -0
  28. package/dist/{iframe.js → cjs/iframe.js} +14 -9
  29. package/dist/cjs/iframe.js.map +1 -0
  30. package/dist/cjs/index.browser.js +40 -0
  31. package/dist/cjs/index.browser.js.map +1 -0
  32. package/dist/cjs/index.executionenv.js +24 -0
  33. package/dist/cjs/index.executionenv.js.map +1 -0
  34. package/dist/cjs/index.js +45 -0
  35. package/dist/cjs/index.js.map +1 -0
  36. package/dist/cjs/json-rpc.js +46 -0
  37. package/dist/cjs/json-rpc.js.map +1 -0
  38. package/dist/cjs/json.js +16 -0
  39. package/dist/cjs/json.js.map +1 -0
  40. package/dist/cjs/logging.js +40 -0
  41. package/dist/cjs/logging.js.map +1 -0
  42. package/dist/cjs/manifest/index.browser.js +20 -0
  43. package/dist/cjs/manifest/index.browser.js.map +1 -0
  44. package/dist/cjs/manifest/index.js +21 -0
  45. package/dist/cjs/manifest/index.js.map +1 -0
  46. package/dist/cjs/manifest/manifest.js +239 -0
  47. package/dist/cjs/manifest/manifest.js.map +1 -0
  48. package/dist/cjs/manifest/validation.js +183 -0
  49. package/dist/cjs/manifest/validation.js.map +1 -0
  50. package/dist/cjs/mock.js +128 -0
  51. package/dist/cjs/mock.js.map +1 -0
  52. package/dist/cjs/namespace.js +124 -0
  53. package/dist/cjs/namespace.js.map +1 -0
  54. package/dist/cjs/npm.js +81 -0
  55. package/dist/cjs/npm.js.map +1 -0
  56. package/dist/cjs/path.js +21 -0
  57. package/dist/cjs/path.js.map +1 -0
  58. package/dist/cjs/post-process.js +328 -0
  59. package/dist/cjs/post-process.js.map +1 -0
  60. package/dist/cjs/snaps.js +230 -0
  61. package/dist/cjs/snaps.js.map +1 -0
  62. package/dist/cjs/types.js +117 -0
  63. package/dist/cjs/types.js.map +1 -0
  64. package/dist/cjs/validation.js +22 -0
  65. package/dist/cjs/validation.js.map +1 -0
  66. package/dist/cjs/versions.js +47 -0
  67. package/dist/cjs/versions.js.map +1 -0
  68. package/dist/cjs/virtual-file/VirtualFile.js +85 -0
  69. package/dist/cjs/virtual-file/VirtualFile.js.map +1 -0
  70. package/dist/cjs/virtual-file/index.browser.js +20 -0
  71. package/dist/cjs/virtual-file/index.browser.js.map +1 -0
  72. package/dist/cjs/virtual-file/index.js +21 -0
  73. package/dist/cjs/virtual-file/index.js.map +1 -0
  74. package/dist/cjs/virtual-file/toVirtualFile.js +33 -0
  75. package/dist/cjs/virtual-file/toVirtualFile.js.map +1 -0
  76. package/dist/esm/array.js +13 -0
  77. package/dist/esm/array.js.map +1 -0
  78. package/dist/esm/caveats.js +23 -0
  79. package/dist/esm/caveats.js.map +1 -0
  80. package/dist/esm/checksum.js +36 -0
  81. package/dist/esm/checksum.js.map +1 -0
  82. package/dist/esm/cronjob.js +66 -0
  83. package/dist/esm/cronjob.js.map +1 -0
  84. package/dist/esm/deep-clone.js +7 -0
  85. package/dist/esm/deep-clone.js.map +1 -0
  86. package/dist/{default-endowments.js → esm/default-endowments.js} +3 -6
  87. package/dist/esm/default-endowments.js.map +1 -0
  88. package/dist/esm/entropy.js +6 -0
  89. package/dist/esm/entropy.js.map +1 -0
  90. package/dist/esm/enum.js +12 -0
  91. package/dist/esm/enum.js.map +1 -0
  92. package/dist/esm/eval-worker.js +47 -0
  93. package/dist/esm/eval-worker.js.map +1 -0
  94. package/dist/esm/eval.js +25 -0
  95. package/dist/esm/eval.js.map +1 -0
  96. package/dist/{fs.js → esm/fs.js} +33 -55
  97. package/dist/esm/fs.js.map +1 -0
  98. package/dist/esm/handlers.js +3 -0
  99. package/dist/esm/handlers.js.map +1 -0
  100. package/dist/esm/icon.js +11 -0
  101. package/dist/esm/icon.js.map +1 -0
  102. package/dist/esm/iframe.js +49 -0
  103. package/dist/esm/iframe.js.map +1 -0
  104. package/dist/esm/index.browser.js +23 -0
  105. package/dist/esm/index.browser.js.map +1 -0
  106. package/dist/esm/index.executionenv.js +7 -0
  107. package/dist/esm/index.executionenv.js.map +1 -0
  108. package/dist/esm/index.js +28 -0
  109. package/dist/esm/index.js.map +1 -0
  110. package/dist/esm/json-rpc.js +39 -0
  111. package/dist/esm/json-rpc.js.map +1 -0
  112. package/dist/esm/json.js +17 -0
  113. package/dist/esm/json.js.map +1 -0
  114. package/dist/{logging.js → esm/logging.js} +6 -14
  115. package/dist/esm/logging.js.map +1 -0
  116. package/dist/esm/manifest/index.browser.js +3 -0
  117. package/dist/esm/manifest/index.browser.js.map +1 -0
  118. package/dist/esm/manifest/index.js +4 -0
  119. package/dist/esm/manifest/index.js.map +1 -0
  120. package/dist/{manifest → esm/manifest}/manifest.js +91 -107
  121. package/dist/esm/manifest/manifest.js.map +1 -0
  122. package/dist/esm/manifest/validation.js +152 -0
  123. package/dist/esm/manifest/validation.js.map +1 -0
  124. package/dist/{mock.js → esm/mock.js} +40 -42
  125. package/dist/esm/mock.js.map +1 -0
  126. package/dist/esm/namespace.js +110 -0
  127. package/dist/esm/namespace.js.map +1 -0
  128. package/dist/{npm.js → esm/npm.js} +23 -30
  129. package/dist/esm/npm.js.map +1 -0
  130. package/dist/esm/path.js +17 -0
  131. package/dist/esm/path.js.map +1 -0
  132. package/dist/{post-process.js → esm/post-process.js} +110 -99
  133. package/dist/esm/post-process.js.map +1 -0
  134. package/dist/esm/snaps.js +215 -0
  135. package/dist/esm/snaps.js.map +1 -0
  136. package/dist/esm/types.js +85 -0
  137. package/dist/esm/types.js.map +1 -0
  138. package/dist/esm/validation.js +17 -0
  139. package/dist/esm/validation.js.map +1 -0
  140. package/dist/{versions.js → esm/versions.js} +15 -18
  141. package/dist/esm/versions.js.map +1 -0
  142. package/dist/{virtual-file → esm/virtual-file}/VirtualFile.js +47 -33
  143. package/dist/esm/virtual-file/VirtualFile.js.map +1 -0
  144. package/dist/esm/virtual-file/index.browser.js +3 -0
  145. package/dist/esm/virtual-file/index.browser.js.map +1 -0
  146. package/dist/esm/virtual-file/index.js +4 -0
  147. package/dist/esm/virtual-file/index.js.map +1 -0
  148. package/dist/esm/virtual-file/toVirtualFile.js +26 -0
  149. package/dist/esm/virtual-file/toVirtualFile.js.map +1 -0
  150. package/dist/types/array.d.ts +10 -0
  151. package/dist/{caveats.d.ts → types/caveats.d.ts} +0 -4
  152. package/dist/types/enum.d.ts +30 -0
  153. package/dist/{handlers.d.ts → types/handlers.d.ts} +1 -38
  154. package/dist/{index.browser.d.ts → types/index.browser.d.ts} +3 -1
  155. package/dist/{index.d.ts → types/index.d.ts} +3 -1
  156. package/dist/types/index.executionenv.d.ts +4 -0
  157. package/dist/types/json.d.ts +13 -0
  158. package/dist/{manifest → types/manifest}/validation.d.ts +6 -69
  159. package/dist/types/namespace.d.ts +124 -0
  160. package/dist/{types.d.ts → types/types.d.ts} +2 -5
  161. package/package.json +52 -25
  162. package/dist/caveats.js +0 -35
  163. package/dist/caveats.js.map +0 -1
  164. package/dist/checksum.js +0 -42
  165. package/dist/checksum.js.map +0 -1
  166. package/dist/cronjob.js +0 -71
  167. package/dist/cronjob.js.map +0 -1
  168. package/dist/deep-clone.js +0 -9
  169. package/dist/deep-clone.js.map +0 -1
  170. package/dist/default-endowments.js.map +0 -1
  171. package/dist/entropy.js +0 -8
  172. package/dist/entropy.js.map +0 -1
  173. package/dist/eval-worker.js.map +0 -1
  174. package/dist/eval.js +0 -27
  175. package/dist/eval.js.map +0 -1
  176. package/dist/fs.js.map +0 -1
  177. package/dist/handlers.js +0 -3
  178. package/dist/handlers.js.map +0 -1
  179. package/dist/icon.js +0 -17
  180. package/dist/icon.js.map +0 -1
  181. package/dist/iframe.js.map +0 -1
  182. package/dist/iframe.test.browser.js +0 -15
  183. package/dist/iframe.test.browser.js.map +0 -1
  184. package/dist/index.browser.js +0 -36
  185. package/dist/index.browser.js.map +0 -1
  186. package/dist/index.js +0 -41
  187. package/dist/index.js.map +0 -1
  188. package/dist/json-rpc.js +0 -46
  189. package/dist/json-rpc.js.map +0 -1
  190. package/dist/logging.js.map +0 -1
  191. package/dist/manifest/index.browser.js +0 -18
  192. package/dist/manifest/index.browser.js.map +0 -1
  193. package/dist/manifest/index.js +0 -19
  194. package/dist/manifest/index.js.map +0 -1
  195. package/dist/manifest/manifest.js.map +0 -1
  196. package/dist/manifest/validation.js +0 -146
  197. package/dist/manifest/validation.js.map +0 -1
  198. package/dist/mock.js.map +0 -1
  199. package/dist/namespace.d.ts +0 -275
  200. package/dist/namespace.js +0 -225
  201. package/dist/namespace.js.map +0 -1
  202. package/dist/notification.d.ts +0 -66
  203. package/dist/notification.js +0 -58
  204. package/dist/notification.js.map +0 -1
  205. package/dist/npm.js.map +0 -1
  206. package/dist/path.js +0 -21
  207. package/dist/path.js.map +0 -1
  208. package/dist/post-process.js.map +0 -1
  209. package/dist/snaps.js +0 -212
  210. package/dist/snaps.js.map +0 -1
  211. package/dist/types.js +0 -103
  212. package/dist/types.js.map +0 -1
  213. package/dist/validation.js +0 -21
  214. package/dist/validation.js.map +0 -1
  215. package/dist/versions.js.map +0 -1
  216. package/dist/virtual-file/VirtualFile.js.map +0 -1
  217. package/dist/virtual-file/index.browser.js +0 -18
  218. package/dist/virtual-file/index.browser.js.map +0 -1
  219. package/dist/virtual-file/index.js +0 -19
  220. package/dist/virtual-file/index.js.map +0 -1
  221. package/dist/virtual-file/toVirtualFile.js +0 -30
  222. package/dist/virtual-file/toVirtualFile.js.map +0 -1
  223. /package/dist/{checksum.d.ts → types/checksum.d.ts} +0 -0
  224. /package/dist/{cronjob.d.ts → types/cronjob.d.ts} +0 -0
  225. /package/dist/{deep-clone.d.ts → types/deep-clone.d.ts} +0 -0
  226. /package/dist/{default-endowments.d.ts → types/default-endowments.d.ts} +0 -0
  227. /package/dist/{entropy.d.ts → types/entropy.d.ts} +0 -0
  228. /package/dist/{eval-worker.d.ts → types/eval-worker.d.ts} +0 -0
  229. /package/dist/{eval.d.ts → types/eval.d.ts} +0 -0
  230. /package/dist/{fs.d.ts → types/fs.d.ts} +0 -0
  231. /package/dist/{icon.d.ts → types/icon.d.ts} +0 -0
  232. /package/dist/{iframe.d.ts → types/iframe.d.ts} +0 -0
  233. /package/dist/{iframe.test.browser.d.ts → types/iframe.test.browser.d.ts} +0 -0
  234. /package/dist/{json-rpc.d.ts → types/json-rpc.d.ts} +0 -0
  235. /package/dist/{logging.d.ts → types/logging.d.ts} +0 -0
  236. /package/dist/{manifest → types/manifest}/index.browser.d.ts +0 -0
  237. /package/dist/{manifest → types/manifest}/index.d.ts +0 -0
  238. /package/dist/{manifest → types/manifest}/manifest.d.ts +0 -0
  239. /package/dist/{mock.d.ts → types/mock.d.ts} +0 -0
  240. /package/dist/{npm.d.ts → types/npm.d.ts} +0 -0
  241. /package/dist/{path.d.ts → types/path.d.ts} +0 -0
  242. /package/dist/{post-process.d.ts → types/post-process.d.ts} +0 -0
  243. /package/dist/{snaps.d.ts → types/snaps.d.ts} +0 -0
  244. /package/dist/{validation.d.ts → types/validation.d.ts} +0 -0
  245. /package/dist/{versions.d.ts → types/versions.d.ts} +0 -0
  246. /package/dist/{virtual-file → types/virtual-file}/VirtualFile.d.ts +0 -0
  247. /package/dist/{virtual-file → types/virtual-file}/index.browser.d.ts +0 -0
  248. /package/dist/{virtual-file → types/virtual-file}/index.d.ts +0 -0
  249. /package/dist/{virtual-file → types/virtual-file}/toVirtualFile.d.ts +0 -0
@@ -7,10 +7,6 @@ export declare enum SnapCaveatType {
7
7
  * Permitted coin types, used by `snap_getBip44Entropy`.
8
8
  */
9
9
  PermittedCoinTypes = "permittedCoinTypes",
10
- /**
11
- * Permission to use the Snap keyring API.
12
- */
13
- SnapKeyring = "snapKeyring",
14
10
  /**
15
11
  * Caveat specifying a snap cronjob.
16
12
  */
@@ -0,0 +1,30 @@
1
+ import { Struct } from 'superstruct';
2
+ /**
3
+ * Get the enum values as union type. This allows using both the enum string
4
+ * values and the enum itself as values.
5
+ *
6
+ * Note: This only works for string enums.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * enum Foo {
11
+ * Bar = 'bar',
12
+ * Baz = 'baz',
13
+ * }
14
+ *
15
+ * type FooValue = EnumToUnion<Foo>;
16
+ * // FooValue is 'bar' | 'baz'
17
+ *
18
+ * const foo: FooValue = Foo.Bar; // Works
19
+ * const foo: FooValue = 'bar'; // Also works
20
+ * ```
21
+ */
22
+ export declare type EnumToUnion<Type extends string> = `${Type}`;
23
+ /**
24
+ * Superstruct struct for validating an enum value. This allows using both the
25
+ * enum string values and the enum itself as values.
26
+ *
27
+ * @param constant - The enum to validate against.
28
+ * @returns The superstruct struct.
29
+ */
30
+ export declare function enumValue<Type extends string>(constant: Type): Struct<EnumToUnion<Type>, EnumToUnion<Type>>;
@@ -1,6 +1,5 @@
1
1
  import { Component } from '@metamask/snaps-ui';
2
2
  import { Json, JsonRpcRequest } from '@metamask/utils';
3
- import { AccountId, ChainId, RequestArguments } from './namespace';
4
3
  /**
5
4
  * The `onRpcRequest` handler. This is called whenever a JSON-RPC request is
6
5
  * made to the snap.
@@ -55,40 +54,6 @@ export declare type OnTransactionHandler = (args: {
55
54
  export declare type OnCronjobHandler<Params extends Json[] | Record<string, Json> | undefined = Json[] | Record<string, Json> | undefined> = (args: {
56
55
  request: JsonRpcRequest<Params>;
57
56
  }) => Promise<unknown>;
58
- /**
59
- * A request sent to the `handleRequest` handler of a snap keyring.
60
- *
61
- * @property chainId - The CAIP-2 chain ID of the network the request is being
62
- * made to.
63
- * @property origin - The origin of the request. This can be the ID of another
64
- * snap, or the URL of a dapp.
65
- */
66
- export declare type KeyringRequest = {
67
- chainId: ChainId;
68
- origin: string;
69
- };
70
- /**
71
- * A keyring event, which consists of a {@link KeyringRequest}, combined with
72
- * the name of the event.
73
- */
74
- export declare type KeyringEvent = KeyringRequest & {
75
- eventName: string;
76
- };
77
- /**
78
- * A snap keyring object, which can be exported as `keyring` in a snap.
79
- */
80
- export interface SnapKeyring {
81
- getAccounts(): Promise<AccountId[]>;
82
- handleRequest(data: KeyringRequest & {
83
- request: RequestArguments;
84
- }): Promise<Json>;
85
- on(data: KeyringEvent, listener: (...args: Json[]) => void): void;
86
- off(data: KeyringEvent): void;
87
- addAccount?(chainId: ChainId): Promise<AccountId>;
88
- removeAccount?(accountId: AccountId): Promise<void>;
89
- importAccount?(chainId: ChainId, data: Json): Promise<AccountId>;
90
- exportAccount?(accountId: AccountId): Promise<Json>;
91
- }
92
57
  /**
93
58
  * All the function-based handlers that a snap can implement.
94
59
  */
@@ -100,6 +65,4 @@ export declare type SnapFunctionExports = {
100
65
  /**
101
66
  * All handlers that a snap can implement.
102
67
  */
103
- export declare type SnapExports = SnapFunctionExports & {
104
- keyring?: SnapKeyring;
105
- };
68
+ export declare type SnapExports = SnapFunctionExports;
@@ -1,16 +1,18 @@
1
+ export * from './array';
1
2
  export * from './caveats';
2
3
  export * from './checksum';
3
4
  export * from './cronjob';
4
5
  export * from './deep-clone';
5
6
  export * from './default-endowments';
6
7
  export * from './entropy';
8
+ export * from './enum';
7
9
  export * from './handlers';
8
10
  export * from './iframe';
11
+ export * from './json';
9
12
  export * from './json-rpc';
10
13
  export * from './logging';
11
14
  export * from './manifest/index.browser';
12
15
  export * from './namespace';
13
- export * from './notification';
14
16
  export * from './path';
15
17
  export * from './snaps';
16
18
  export * from './types';
@@ -1,19 +1,21 @@
1
+ export * from './array';
1
2
  export * from './caveats';
2
3
  export * from './cronjob';
3
4
  export * from './checksum';
4
5
  export * from './deep-clone';
5
6
  export * from './default-endowments';
6
7
  export * from './entropy';
8
+ export * from './enum';
7
9
  export * from './eval';
8
10
  export * from './fs';
9
11
  export * from './handlers';
10
12
  export * from './iframe';
13
+ export * from './json';
11
14
  export * from './json-rpc';
12
15
  export * from './logging';
13
16
  export * from './manifest';
14
17
  export * from './mock';
15
18
  export * from './namespace';
16
- export * from './notification';
17
19
  export * from './npm';
18
20
  export * from './path';
19
21
  export * from './post-process';
@@ -0,0 +1,4 @@
1
+ export * from './handlers';
2
+ export * from './logging';
3
+ export * from './namespace';
4
+ export * from './types';
@@ -0,0 +1,13 @@
1
+ import { Json } from '@metamask/utils';
2
+ /**
3
+ * Parse JSON safely.
4
+ *
5
+ * Does multiple kinds of validation and strips unwanted properties like
6
+ * `__proto__` and `constructor`.
7
+ *
8
+ * @param json - A JSON string to be parsed.
9
+ * @returns The parsed JSON object.
10
+ * @template Type - The type of the JSON object. The type is not actually
11
+ * checked, but it is used to infer the return type.
12
+ */
13
+ export declare function parseJson<Type extends Json = Json>(json: string): Type;
@@ -1,4 +1,5 @@
1
1
  import { Infer, Struct } from 'superstruct';
2
+ export declare const FORBIDDEN_COIN_TYPES: number[];
2
3
  export declare const Bip32PathStruct: Struct<string[], Struct<string, null>>;
3
4
  export declare const bip32entropy: <T extends {
4
5
  path: string[];
@@ -58,6 +59,7 @@ export declare const PermissionsStruct: Struct<{
58
59
  snap_dialog?: {} | undefined;
59
60
  snap_confirm?: {} | undefined;
60
61
  snap_manageState?: {} | undefined;
62
+ snap_manageAccounts?: {} | undefined;
61
63
  snap_notify?: {} | undefined;
62
64
  snap_getBip32Entropy?: {
63
65
  path: string[];
@@ -71,16 +73,6 @@ export declare const PermissionsStruct: Struct<{
71
73
  coinType: number;
72
74
  }[] | undefined;
73
75
  snap_getEntropy?: {} | undefined;
74
- 'endowment:keyring'?: {
75
- namespaces: Record<string, {
76
- chains: {
77
- name: string;
78
- id: string;
79
- }[];
80
- methods?: string[] | undefined;
81
- events?: string[] | undefined;
82
- }>;
83
- } | undefined;
84
76
  wallet_snap?: Record<string, {
85
77
  version?: string | undefined;
86
78
  }> | undefined;
@@ -145,6 +137,7 @@ export declare const PermissionsStruct: Struct<{
145
137
  snap_dialog: Struct<{} | undefined, {}>;
146
138
  snap_confirm: Struct<{} | undefined, {}>;
147
139
  snap_manageState: Struct<{} | undefined, {}>;
140
+ snap_manageAccounts: Struct<{} | undefined, {}>;
148
141
  snap_notify: Struct<{} | undefined, {}>;
149
142
  snap_getBip32Entropy: Struct<{
150
143
  path: string[];
@@ -180,25 +173,6 @@ export declare const PermissionsStruct: Struct<{
180
173
  coinType: Struct<number, null>;
181
174
  }>>;
182
175
  snap_getEntropy: Struct<{} | undefined, {}>;
183
- 'endowment:keyring': Struct<{
184
- namespaces: Record<string, {
185
- chains: {
186
- name: string;
187
- id: string;
188
- }[];
189
- methods?: string[] | undefined;
190
- events?: string[] | undefined;
191
- }>;
192
- } | undefined, {
193
- namespaces: Struct<Record<string, {
194
- chains: {
195
- name: string;
196
- id: string;
197
- }[];
198
- methods?: string[] | undefined;
199
- events?: string[] | undefined;
200
- }>, null>;
201
- }>;
202
176
  wallet_snap: Struct<Record<string, {
203
177
  version?: string | undefined;
204
178
  }> | undefined, null>;
@@ -244,6 +218,7 @@ export declare const SnapManifestStruct: Struct<{
244
218
  snap_dialog?: {} | undefined;
245
219
  snap_confirm?: {} | undefined;
246
220
  snap_manageState?: {} | undefined;
221
+ snap_manageAccounts?: {} | undefined;
247
222
  snap_notify?: {} | undefined;
248
223
  snap_getBip32Entropy?: {
249
224
  path: string[];
@@ -257,16 +232,6 @@ export declare const SnapManifestStruct: Struct<{
257
232
  coinType: number;
258
233
  }[] | undefined;
259
234
  snap_getEntropy?: {} | undefined;
260
- 'endowment:keyring'?: {
261
- namespaces: Record<string, {
262
- chains: {
263
- name: string;
264
- id: string;
265
- }[];
266
- methods?: string[] | undefined;
267
- events?: string[] | undefined;
268
- }>;
269
- } | undefined;
270
235
  wallet_snap?: Record<string, {
271
236
  version?: string | undefined;
272
237
  }> | undefined;
@@ -346,6 +311,7 @@ export declare const SnapManifestStruct: Struct<{
346
311
  snap_dialog?: {} | undefined;
347
312
  snap_confirm?: {} | undefined;
348
313
  snap_manageState?: {} | undefined;
314
+ snap_manageAccounts?: {} | undefined;
349
315
  snap_notify?: {} | undefined;
350
316
  snap_getBip32Entropy?: {
351
317
  path: string[];
@@ -359,16 +325,6 @@ export declare const SnapManifestStruct: Struct<{
359
325
  coinType: number;
360
326
  }[] | undefined;
361
327
  snap_getEntropy?: {} | undefined;
362
- 'endowment:keyring'?: {
363
- namespaces: Record<string, {
364
- chains: {
365
- name: string;
366
- id: string;
367
- }[];
368
- methods?: string[] | undefined;
369
- events?: string[] | undefined;
370
- }>;
371
- } | undefined;
372
328
  wallet_snap?: Record<string, {
373
329
  version?: string | undefined;
374
330
  }> | undefined;
@@ -433,6 +389,7 @@ export declare const SnapManifestStruct: Struct<{
433
389
  snap_dialog: Struct<{} | undefined, {}>;
434
390
  snap_confirm: Struct<{} | undefined, {}>;
435
391
  snap_manageState: Struct<{} | undefined, {}>;
392
+ snap_manageAccounts: Struct<{} | undefined, {}>;
436
393
  snap_notify: Struct<{} | undefined, {}>;
437
394
  snap_getBip32Entropy: Struct<{
438
395
  path: string[];
@@ -468,25 +425,6 @@ export declare const SnapManifestStruct: Struct<{
468
425
  coinType: Struct<number, null>;
469
426
  }>>;
470
427
  snap_getEntropy: Struct<{} | undefined, {}>;
471
- 'endowment:keyring': Struct<{
472
- namespaces: Record<string, {
473
- chains: {
474
- name: string;
475
- id: string;
476
- }[];
477
- methods?: string[] | undefined;
478
- events?: string[] | undefined;
479
- }>;
480
- } | undefined, {
481
- namespaces: Struct<Record<string, {
482
- chains: {
483
- name: string;
484
- id: string;
485
- }[];
486
- methods?: string[] | undefined;
487
- events?: string[] | undefined;
488
- }>, null>;
489
- }>;
490
428
  wallet_snap: Struct<Record<string, {
491
429
  version?: string | undefined;
492
430
  }> | undefined, null>;
@@ -512,7 +450,6 @@ export declare function assertIsSnapManifest(value: unknown): asserts value is S
512
450
  /**
513
451
  * Creates a {@link SnapManifest} object from JSON.
514
452
  *
515
- *
516
453
  * @param value - The value to check.
517
454
  * @throws If the value cannot be coerced to a {@link SnapManifest} object.
518
455
  * @returns The created {@link SnapManifest} object.
@@ -0,0 +1,124 @@
1
+ import { Infer } from 'superstruct';
2
+ export declare const CHAIN_ID_REGEX: RegExp;
3
+ export declare const ACCOUNT_ID_REGEX: RegExp;
4
+ /**
5
+ * Parse a chain ID string to an object containing the namespace and reference.
6
+ * This validates the chain ID before parsing it.
7
+ *
8
+ * @param chainId - The chain ID to validate and parse.
9
+ * @returns The parsed chain ID.
10
+ */
11
+ export declare function parseChainId(chainId: ChainId): {
12
+ namespace: NamespaceId;
13
+ reference: string;
14
+ };
15
+ /**
16
+ * Parse an account ID to an object containing the chain, chain ID and address.
17
+ * This validates the account ID before parsing it.
18
+ *
19
+ * @param accountId - The account ID to validate and parse.
20
+ * @returns The parsed account ID.
21
+ */
22
+ export declare function parseAccountId(accountId: AccountId): {
23
+ chain: {
24
+ namespace: NamespaceId;
25
+ reference: string;
26
+ };
27
+ chainId: ChainId;
28
+ address: string;
29
+ };
30
+ /**
31
+ * A helper struct for a string with a minimum length of 1 and a maximum length
32
+ * of 40.
33
+ */
34
+ export declare const LimitedString: import("superstruct").Struct<string, null>;
35
+ /**
36
+ * A CAIP-2 chain ID, i.e., a human-readable namespace and reference.
37
+ */
38
+ export declare const ChainIdStruct: import("superstruct").Struct<string, null>;
39
+ export declare type ChainId = `${string}:${string}`;
40
+ export declare const AccountIdStruct: import("superstruct").Struct<string, null>;
41
+ export declare type AccountId = `${ChainId}:${string}`;
42
+ export declare const AccountIdArrayStruct: import("superstruct").Struct<string[], import("superstruct").Struct<string, null>>;
43
+ /**
44
+ * A chain descriptor.
45
+ */
46
+ export declare const ChainStruct: import("superstruct").Struct<{
47
+ name: string;
48
+ id: string;
49
+ }, {
50
+ id: import("superstruct").Struct<string, null>;
51
+ name: import("superstruct").Struct<string, null>;
52
+ }>;
53
+ export declare type Chain = Infer<typeof ChainStruct>;
54
+ export declare const NamespaceStruct: import("superstruct").Struct<{
55
+ chains: {
56
+ name: string;
57
+ id: string;
58
+ }[];
59
+ methods?: string[] | undefined;
60
+ events?: string[] | undefined;
61
+ }, {
62
+ /**
63
+ * A list of supported chains in the namespace.
64
+ */
65
+ chains: import("superstruct").Struct<{
66
+ name: string;
67
+ id: string;
68
+ }[], import("superstruct").Struct<{
69
+ name: string;
70
+ id: string;
71
+ }, {
72
+ id: import("superstruct").Struct<string, null>;
73
+ name: import("superstruct").Struct<string, null>;
74
+ }>>;
75
+ /**
76
+ * A list of supported RPC methods on the namespace, that a DApp can call.
77
+ */
78
+ methods: import("superstruct").Struct<string[] | undefined, import("superstruct").Struct<string, null>>;
79
+ /**
80
+ * A list of supported RPC events on the namespace, that a DApp can listen to.
81
+ */
82
+ events: import("superstruct").Struct<string[] | undefined, import("superstruct").Struct<string, null>>;
83
+ }>;
84
+ export declare type Namespace = Infer<typeof NamespaceStruct>;
85
+ /**
86
+ * A CAIP-2 namespace, i.e., the first part of a chain ID.
87
+ */
88
+ export declare const NamespaceIdStruct: import("superstruct").Struct<string, null>;
89
+ export declare type NamespaceId = Infer<typeof NamespaceIdStruct>;
90
+ /**
91
+ * Check if the given value is a CAIP-2 namespace ID.
92
+ *
93
+ * @param value - The value to check.
94
+ * @returns Whether the value is a CAIP-2 namespace ID.
95
+ */
96
+ export declare function isNamespaceId(value: unknown): value is NamespaceId;
97
+ /**
98
+ * Check if the given value is a CAIP-2 chain ID.
99
+ *
100
+ * @param value - The value to check.
101
+ * @returns Whether the value is a CAIP-2 chain ID.
102
+ */
103
+ export declare function isChainId(value: unknown): value is ChainId;
104
+ /**
105
+ * Check if the given value is a CAIP-10 account ID.
106
+ *
107
+ * @param value - The value to check.
108
+ * @returns Whether the value is a CAIP-10 account ID.
109
+ */
110
+ export declare function isAccountId(value: unknown): value is AccountId;
111
+ /**
112
+ * Check if the given value is an array of CAIP-10 account IDs.
113
+ *
114
+ * @param value - The value to check.
115
+ * @returns Whether the value is an array of CAIP-10 account IDs.
116
+ */
117
+ export declare function isAccountIdArray(value: unknown): value is AccountId[];
118
+ /**
119
+ * Check if a value is a {@link Namespace}.
120
+ *
121
+ * @param value - The value to validate.
122
+ * @returns True if the value is a valid {@link Namespace}.
123
+ */
124
+ export declare function isNamespace(value: unknown): value is Namespace;
@@ -1,7 +1,7 @@
1
1
  import { Json } from '@metamask/utils';
2
2
  import { Infer, Struct } from 'superstruct';
3
3
  import { SnapCaveatType } from './caveats';
4
- import { SnapFunctionExports, SnapKeyring as Keyring } from './handlers';
4
+ import { SnapFunctionExports } from './handlers';
5
5
  import { SnapManifest } from './manifest';
6
6
  import { VirtualFile } from './virtual-file';
7
7
  export declare enum NpmSnapFileNames {
@@ -88,7 +88,6 @@ export declare enum SNAP_STREAM_NAMES {
88
88
  export declare enum HandlerType {
89
89
  OnRpcRequest = "onRpcRequest",
90
90
  OnTransaction = "onTransaction",
91
- SnapKeyring = "keyring",
92
91
  OnCronjob = "onCronjob"
93
92
  }
94
93
  export declare const SNAP_EXPORT_NAMES: HandlerType[];
@@ -99,9 +98,7 @@ export declare type SnapRpcHookArgs = {
99
98
  };
100
99
  export declare type SnapRpcHook = (options: SnapRpcHookArgs) => Promise<unknown>;
101
100
  declare type ObjectParameters<Type extends Record<string, (...args: any[]) => unknown>> = Parameters<Type[keyof Type]>;
102
- declare type KeyringParameter<Fn> = Fn extends (...args: any[]) => unknown ? Parameters<Fn> : never;
103
- declare type KeyringParameters = KeyringParameter<Keyring[keyof Keyring]>;
104
- export declare type SnapExportsParameters = ObjectParameters<SnapFunctionExports> | KeyringParameters;
101
+ export declare type SnapExportsParameters = ObjectParameters<SnapFunctionExports>;
105
102
  declare type UriOptions<T extends string> = {
106
103
  protocol?: Struct<T>;
107
104
  hash?: Struct<T>;
package/package.json CHANGED
@@ -1,66 +1,92 @@
1
1
  {
2
2
  "name": "@metamask/snaps-utils",
3
- "version": "0.34.0-flask.1",
3
+ "version": "0.35.0-flask.1",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/MetaMask/snaps.git"
7
7
  },
8
+ "sideEffects": false,
8
9
  "exports": {
9
10
  ".": {
10
11
  "browser": {
11
- "default": "./dist/index.browser.js"
12
+ "import": "./dist/esm/index.browser.js",
13
+ "require": "./dist/cjs/index.browser.js"
12
14
  },
13
- "import": "./dist/index.js",
14
- "require": "./dist/index.js"
15
+ "import": "./dist/esm/index.js",
16
+ "require": "./dist/cjs/index.js",
17
+ "types": "./dist/types/index.d.ts"
15
18
  },
16
19
  "./test-utils": {
17
- "import": "./dist/test-utils/index.js",
18
- "require": "./dist/test-utils/index.js"
20
+ "import": "./dist/esm/test-utils/index.js",
21
+ "require": "./dist/cjs/test-utils/index.js",
22
+ "types": "./dist/types/test-utils/index.d.ts"
23
+ },
24
+ "./dist/cjs/*": {
25
+ "require": "./dist/cjs/*.js",
26
+ "types": "./dist/types/*.d.ts"
27
+ },
28
+ "./dist/esm/*": {
29
+ "import": "./dist/esm/*.js",
30
+ "types": "./dist/types/*.d.ts"
19
31
  }
20
32
  },
21
- "main": "dist/index.js",
33
+ "main": "./dist/cjs/index.js",
34
+ "module": "./dist/esm/index.js",
22
35
  "browser": {
23
- "./dist/index.js": "./dist/index.browser.js"
36
+ "./dist/cjs/index.js": "./dist/cjs/index.browser.js",
37
+ "./dist/esm/index.js": "./dist/esm/index.browser.js"
24
38
  },
39
+ "types": "./dist/types/index.d.ts",
25
40
  "typesVersions": {
26
41
  "*": {
27
42
  "*": [
28
- "dist/index.d.ts"
43
+ "./dist/types/*"
44
+ ],
45
+ "./dist/cjs/*": [
46
+ "./dist/types/*"
29
47
  ],
30
- "test-utils": [
31
- "dist/test-utils/index.d.ts"
48
+ "./dist/esm/*": [
49
+ "./dist/types/*"
32
50
  ]
33
51
  }
34
52
  },
35
53
  "files": [
36
- "dist/"
54
+ "dist/cjs/**",
55
+ "dist/esm/**",
56
+ "dist/types/**"
37
57
  ],
38
58
  "scripts": {
39
59
  "test": "rimraf coverage && jest && yarn test:browser && yarn posttest",
40
60
  "posttest": "ts-node scripts/coverage.ts && rimraf coverage/jest coverage/wdio",
41
61
  "test:browser": "wdio run wdio.config.ts",
42
62
  "test:ci": "yarn test",
43
- "lint:eslint": "eslint . --cache --ext js,ts",
44
- "lint:misc": "prettier '**/*.json' '**/*.md' '!CHANGELOG.md' --ignore-path ../../.gitignore",
45
- "lint": "yarn lint:eslint && yarn lint:misc --check",
63
+ "lint:eslint": "eslint . --cache --ext js,ts,jsx,tsx",
64
+ "lint:misc": "prettier --no-error-on-unmatched-pattern --loglevel warn \"**/*.json\" \"**/*.md\" \"**/*.html\" \"!CHANGELOG.md\" --ignore-path ../../.gitignore",
65
+ "lint": "yarn lint:eslint && yarn lint:misc --check && yarn lint:changelog",
46
66
  "lint:fix": "yarn lint:eslint --fix && yarn lint:misc --write",
47
67
  "lint:changelog": "yarn auto-changelog validate",
48
- "build": "tsc --project tsconfig.build.json",
68
+ "build": "yarn build:source && yarn build:types",
69
+ "build:source": "yarn build:esm && yarn build:cjs",
70
+ "build:types": "tsc --project tsconfig.build.json",
71
+ "build:esm": "swc src --out-dir dist/esm --config-file ../../.swcrc.build.json --config module.type=es6",
72
+ "build:cjs": "swc src --out-dir dist/cjs --config-file ../../.swcrc.build.json --config module.type=commonjs",
49
73
  "build:clean": "yarn clean && yarn build",
50
74
  "clean": "rimraf '*.tsbuildinfo' 'dist/*'",
51
75
  "prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
52
- "publish:preview": "yarn npm publish --tag preview"
76
+ "publish:preview": "yarn npm publish --tag preview",
77
+ "lint:ci": "yarn lint"
53
78
  },
54
79
  "dependencies": {
55
80
  "@babel/core": "^7.20.12",
56
81
  "@babel/types": "^7.18.7",
57
82
  "@metamask/base-controller": "^3.0.0",
83
+ "@metamask/key-tree": "^7.1.1",
58
84
  "@metamask/permission-controller": "^4.0.0",
59
- "@metamask/providers": "^10.2.1",
85
+ "@metamask/providers": "^11.0.0",
60
86
  "@metamask/snaps-registry": "^1.2.1",
61
- "@metamask/snaps-ui": "^0.34.0-flask.1",
62
- "@metamask/utils": "^6.0.0",
63
- "@noble/hashes": "^1.1.3",
87
+ "@metamask/snaps-ui": "^0.35.0-flask.1",
88
+ "@metamask/utils": "^6.0.1",
89
+ "@noble/hashes": "^1.3.1",
64
90
  "@scure/base": "^1.1.1",
65
91
  "cron-parser": "^4.5.0",
66
92
  "eth-rpc-errors": "^4.0.3",
@@ -82,11 +108,13 @@
82
108
  "@metamask/eslint-config-jest": "^11.0.0",
83
109
  "@metamask/eslint-config-nodejs": "^11.0.1",
84
110
  "@metamask/eslint-config-typescript": "^11.0.0",
85
- "@metamask/key-tree": "^7.0.0",
86
111
  "@metamask/post-message-stream": "^6.1.2",
112
+ "@swc/cli": "^0.1.62",
113
+ "@swc/core": "^1.3.66",
114
+ "@swc/jest": "^0.2.26",
87
115
  "@types/jest": "^27.5.1",
88
116
  "@types/mocha": "^10.0.1",
89
- "@types/node": "^17.0.36",
117
+ "@types/node": "^20.3.1",
90
118
  "@types/semver": "^7.3.10",
91
119
  "@types/validate-npm-package-name": "^4.0.0",
92
120
  "@typescript-eslint/eslint-plugin": "^5.42.1",
@@ -116,10 +144,9 @@
116
144
  "prettier-plugin-packagejson": "^2.2.11",
117
145
  "rimraf": "^4.1.2",
118
146
  "serve-handler": "^6.1.5",
119
- "ts-jest": "^29.0.2",
120
147
  "ts-node": "^10.9.1",
121
148
  "typescript": "~4.8.4",
122
- "vite": "^4.1.4",
149
+ "vite": "^4.3.9",
123
150
  "vite-tsconfig-paths": "^4.0.5",
124
151
  "wdio-chromedriver-service": "^8.1.1",
125
152
  "wdio-geckodriver-service": "^4.1.0",
package/dist/caveats.js DELETED
@@ -1,35 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SnapCaveatType = void 0;
4
- var SnapCaveatType;
5
- (function (SnapCaveatType) {
6
- /**
7
- * Permitted derivation paths, used by `snap_getBip32Entropy`.
8
- */
9
- SnapCaveatType["PermittedDerivationPaths"] = "permittedDerivationPaths";
10
- /**
11
- * Permitted coin types, used by `snap_getBip44Entropy`.
12
- */
13
- SnapCaveatType["PermittedCoinTypes"] = "permittedCoinTypes";
14
- /**
15
- * Permission to use the Snap keyring API.
16
- */
17
- SnapCaveatType["SnapKeyring"] = "snapKeyring";
18
- /**
19
- * Caveat specifying a snap cronjob.
20
- */
21
- SnapCaveatType["SnapCronjob"] = "snapCronjob";
22
- /**
23
- * Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.
24
- */
25
- SnapCaveatType["TransactionOrigin"] = "transactionOrigin";
26
- /**
27
- * The origins that a Snap can receive JSON-RPC messages from.
28
- */
29
- SnapCaveatType["RpcOrigin"] = "rpcOrigin";
30
- /**
31
- * Caveat specifying the snap IDs that can be interacted with.
32
- */
33
- SnapCaveatType["SnapIds"] = "snapIds";
34
- })(SnapCaveatType = exports.SnapCaveatType || (exports.SnapCaveatType = {}));
35
- //# sourceMappingURL=caveats.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"caveats.js","sourceRoot":"","sources":["../src/caveats.ts"],"names":[],"mappings":";;;AAAA,IAAY,cAmCX;AAnCD,WAAY,cAAc;IACxB;;OAEG;IACH,uEAAqD,CAAA;IAErD;;OAEG;IACH,2DAAyC,CAAA;IAEzC;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,6CAA2B,CAAA;IAE3B;;OAEG;IACH,yDAAuC,CAAA;IAEvC;;OAEG;IACH,yCAAuB,CAAA;IAEvB;;OAEG;IACH,qCAAmB,CAAA;AACrB,CAAC,EAnCW,cAAc,GAAd,sBAAc,KAAd,sBAAc,QAmCzB","sourcesContent":["export enum SnapCaveatType {\n /**\n * Permitted derivation paths, used by `snap_getBip32Entropy`.\n */\n PermittedDerivationPaths = 'permittedDerivationPaths',\n\n /**\n * Permitted coin types, used by `snap_getBip44Entropy`.\n */\n PermittedCoinTypes = 'permittedCoinTypes',\n\n /**\n * Permission to use the Snap keyring API.\n */\n SnapKeyring = 'snapKeyring',\n\n /**\n * Caveat specifying a snap cronjob.\n */\n SnapCronjob = 'snapCronjob',\n\n /**\n * Caveat specifying access to the transaction origin, used by `endowment:transaction-insight`.\n */\n TransactionOrigin = 'transactionOrigin',\n\n /**\n * The origins that a Snap can receive JSON-RPC messages from.\n */\n RpcOrigin = 'rpcOrigin',\n\n /**\n * Caveat specifying the snap IDs that can be interacted with.\n */\n SnapIds = 'snapIds',\n}\n"]}