@metamask/snaps-jest 8.1.3 → 8.3.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 (203) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/README.md +2 -2
  3. package/dist/chunk-24CGIQLL.mjs +30 -0
  4. package/dist/chunk-24CGIQLL.mjs.map +1 -0
  5. package/dist/{chunk-T2PHS5FY.js → chunk-2RJYSYUB.js} +2 -2
  6. package/dist/chunk-2RJYSYUB.js.map +1 -0
  7. package/dist/{chunk-KNJNL723.mjs → chunk-3J2IBWXV.mjs} +2 -2
  8. package/dist/{chunk-EDFQDZNY.js → chunk-3NP6BDGK.js} +50 -17
  9. package/dist/chunk-3NP6BDGK.js.map +1 -0
  10. package/dist/{chunk-AFA4KKWW.mjs → chunk-6JPBXAHM.mjs} +250 -47
  11. package/dist/chunk-6JPBXAHM.mjs.map +1 -0
  12. package/dist/{chunk-VXPCUDBI.js → chunk-6V6MFT67.js} +8 -6
  13. package/dist/chunk-6V6MFT67.js.map +1 -0
  14. package/dist/{chunk-6V5GEUDO.mjs → chunk-7PCHIR6O.mjs} +7 -37
  15. package/dist/chunk-7PCHIR6O.mjs.map +1 -0
  16. package/dist/{chunk-2OHD2VKS.js → chunk-AMAL4SJH.js} +11 -37
  17. package/dist/chunk-AMAL4SJH.js.map +1 -0
  18. package/dist/{chunk-HOI6FPLR.mjs → chunk-C26TYXXD.mjs} +9 -9
  19. package/dist/chunk-C26TYXXD.mjs.map +1 -0
  20. package/dist/{chunk-K55LIE3W.mjs → chunk-CACRY3TX.mjs} +3 -3
  21. package/dist/{chunk-PZDTZGSI.js → chunk-D653LBAY.js} +1 -1
  22. package/dist/chunk-D653LBAY.js.map +1 -0
  23. package/dist/chunk-DUVKGPX5.js +509 -0
  24. package/dist/chunk-DUVKGPX5.js.map +1 -0
  25. package/dist/{chunk-IH7UNS5A.mjs → chunk-G333FBBL.mjs} +6 -4
  26. package/dist/chunk-G333FBBL.mjs.map +1 -0
  27. package/dist/{chunk-YNUVT3HC.js → chunk-GLPGOEVE.js} +4 -4
  28. package/dist/chunk-GLPGOEVE.js.map +1 -0
  29. package/dist/chunk-IWJ4HKDR.mjs +50 -0
  30. package/dist/chunk-IWJ4HKDR.mjs.map +1 -0
  31. package/dist/{chunk-WMLSD6B5.js → chunk-K7MK6LQU.js} +3 -3
  32. package/dist/{chunk-B73P64TE.mjs → chunk-KOPPL55J.mjs} +2 -2
  33. package/dist/chunk-KOPPL55J.mjs.map +1 -0
  34. package/dist/{chunk-XKJHFUHE.js → chunk-KPRLFCKD.js} +4 -2
  35. package/dist/chunk-KPRLFCKD.js.map +1 -0
  36. package/dist/{chunk-3FDEYMQU.js → chunk-LPMHPAZK.js} +54 -14
  37. package/dist/chunk-LPMHPAZK.js.map +1 -0
  38. package/dist/{chunk-GG2BCPQH.mjs → chunk-LSKT2AUS.mjs} +5 -3
  39. package/dist/chunk-LSKT2AUS.mjs.map +1 -0
  40. package/dist/{chunk-6KXCBUNZ.mjs → chunk-LVNNGMJ2.mjs} +3 -1
  41. package/dist/{chunk-6KXCBUNZ.mjs.map → chunk-LVNNGMJ2.mjs.map} +1 -1
  42. package/dist/{chunk-TMAWGVZP.mjs → chunk-OHRFO2BL.mjs} +7 -7
  43. package/dist/chunk-OHRFO2BL.mjs.map +1 -0
  44. package/dist/{chunk-JXAJWUVZ.js → chunk-OO6IVUCV.js} +5 -5
  45. package/dist/{chunk-3M4GRUMH.mjs → chunk-ORR7AE5X.mjs} +2 -2
  46. package/dist/{chunk-UPR3PTSA.mjs → chunk-PDOVVC74.mjs} +10 -36
  47. package/dist/chunk-PDOVVC74.mjs.map +1 -0
  48. package/dist/{chunk-E2BYTLOT.mjs → chunk-Q3I6P2ZF.mjs} +43 -10
  49. package/dist/chunk-Q3I6P2ZF.mjs.map +1 -0
  50. package/dist/chunk-QRVFWATH.mjs +14 -0
  51. package/dist/chunk-QRVFWATH.mjs.map +1 -0
  52. package/dist/{chunk-MBQHVBLA.js → chunk-QYHQ2WWX.js} +5 -5
  53. package/dist/chunk-QYHQ2WWX.js.map +1 -0
  54. package/dist/{chunk-XWGECIXI.js → chunk-RJNNNCZJ.js} +3 -3
  55. package/dist/{chunk-U3DVRTS2.mjs → chunk-ROCGQYSK.mjs} +46 -6
  56. package/dist/chunk-ROCGQYSK.mjs.map +1 -0
  57. package/dist/chunk-SNXRXX2O.js +30 -0
  58. package/dist/chunk-SNXRXX2O.js.map +1 -0
  59. package/dist/chunk-SW65QYFV.js +50 -0
  60. package/dist/chunk-SW65QYFV.js.map +1 -0
  61. package/dist/{chunk-44ARQBXS.js → chunk-WZ57PU2K.js} +6 -4
  62. package/dist/chunk-WZ57PU2K.js.map +1 -0
  63. package/dist/chunk-XP4YGQJA.js +14 -0
  64. package/dist/chunk-XP4YGQJA.js.map +1 -0
  65. package/dist/{chunk-KQBJQLZG.js → chunk-Y2U3ZPCK.js} +15 -45
  66. package/dist/chunk-Y2U3ZPCK.js.map +1 -0
  67. package/dist/{chunk-74TIKA2T.mjs → chunk-ZJQSGRNK.mjs} +1 -1
  68. package/dist/chunk-ZJQSGRNK.mjs.map +1 -0
  69. package/dist/environment.js +17 -17
  70. package/dist/environment.mjs +16 -16
  71. package/dist/helpers.js +30 -16
  72. package/dist/helpers.mjs +29 -15
  73. package/dist/index.js +32 -18
  74. package/dist/index.mjs +31 -17
  75. package/dist/internals/index.js +33 -21
  76. package/dist/internals/index.mjs +35 -23
  77. package/dist/internals/request.js +15 -15
  78. package/dist/internals/request.mjs +14 -14
  79. package/dist/internals/simulation/constants.js +4 -2
  80. package/dist/internals/simulation/constants.mjs +3 -1
  81. package/dist/internals/simulation/controllers.js +7 -7
  82. package/dist/internals/simulation/controllers.mjs +6 -6
  83. package/dist/internals/simulation/files.js +8 -2
  84. package/dist/internals/simulation/files.mjs +7 -1
  85. package/dist/internals/simulation/index.js +31 -19
  86. package/dist/internals/simulation/index.mjs +33 -21
  87. package/dist/internals/simulation/interface.js +15 -4
  88. package/dist/internals/simulation/interface.mjs +16 -5
  89. package/dist/internals/simulation/methods/hooks/get-preferences.js +8 -0
  90. package/dist/internals/simulation/methods/hooks/get-preferences.mjs +8 -0
  91. package/dist/internals/simulation/methods/hooks/index.js +5 -5
  92. package/dist/internals/simulation/methods/hooks/index.mjs +8 -8
  93. package/dist/internals/simulation/methods/hooks/notifications.js +2 -2
  94. package/dist/internals/simulation/methods/hooks/notifications.mjs +2 -2
  95. package/dist/internals/simulation/methods/hooks/request-user-approval.js +14 -0
  96. package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +14 -0
  97. package/dist/internals/simulation/methods/hooks/state.js +2 -2
  98. package/dist/internals/simulation/methods/hooks/state.mjs +2 -2
  99. package/dist/internals/simulation/methods/index.js +6 -6
  100. package/dist/internals/simulation/methods/index.mjs +5 -5
  101. package/dist/internals/simulation/methods/specifications.js +6 -6
  102. package/dist/internals/simulation/methods/specifications.mjs +5 -5
  103. package/dist/internals/simulation/middleware/engine.js +3 -3
  104. package/dist/internals/simulation/middleware/engine.mjs +2 -2
  105. package/dist/internals/simulation/middleware/index.js +3 -3
  106. package/dist/internals/simulation/middleware/index.mjs +2 -2
  107. package/dist/internals/simulation/options.js +3 -3
  108. package/dist/internals/simulation/options.mjs +2 -2
  109. package/dist/internals/simulation/simulation.js +13 -12
  110. package/dist/internals/simulation/simulation.mjs +12 -11
  111. package/dist/internals/simulation/store/index.js +3 -3
  112. package/dist/internals/simulation/store/index.mjs +2 -2
  113. package/dist/internals/simulation/store/store.js +3 -3
  114. package/dist/internals/simulation/store/store.mjs +2 -2
  115. package/dist/internals/simulation/store/ui.js +2 -2
  116. package/dist/internals/simulation/store/ui.mjs +1 -1
  117. package/dist/internals/structs.js +2 -2
  118. package/dist/internals/structs.mjs +1 -1
  119. package/dist/matchers.js +16 -18
  120. package/dist/matchers.mjs +15 -17
  121. package/dist/options.js +2 -2
  122. package/dist/options.mjs +1 -1
  123. package/dist/setup.js +15 -15
  124. package/dist/setup.mjs +15 -15
  125. package/dist/tsconfig.build.tsbuildinfo +1 -1
  126. package/dist/types/helpers.d.ts +43 -1
  127. package/dist/types/internals/request.d.ts +3 -2
  128. package/dist/types/internals/server.d.ts +1 -1
  129. package/dist/types/internals/simulation/constants.d.ts +4 -0
  130. package/dist/types/internals/simulation/controllers.d.ts +4 -4
  131. package/dist/types/internals/simulation/files.d.ts +36 -0
  132. package/dist/types/internals/simulation/interface.d.ts +70 -8
  133. package/dist/types/internals/simulation/methods/hooks/get-preferences.d.ts +13 -0
  134. package/dist/types/internals/simulation/methods/hooks/index.d.ts +2 -2
  135. package/dist/types/internals/simulation/methods/hooks/request-user-approval.d.ts +15 -0
  136. package/dist/types/internals/simulation/methods/specifications.d.ts +2 -2
  137. package/dist/types/internals/simulation/middleware/engine.d.ts +1 -1
  138. package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +1 -1
  139. package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +1 -1
  140. package/dist/types/internals/simulation/options.d.ts +10 -8
  141. package/dist/types/internals/simulation/simulation.d.ts +8 -5
  142. package/dist/types/internals/simulation/store/mocks.d.ts +2 -2
  143. package/dist/types/internals/simulation/store/notifications.d.ts +2 -2
  144. package/dist/types/internals/simulation/store/state.d.ts +1 -1
  145. package/dist/types/internals/simulation/store/store.d.ts +4 -4
  146. package/dist/types/internals/simulation/store/ui.d.ts +4 -3
  147. package/dist/types/internals/structs.d.ts +41 -41
  148. package/dist/types/matchers.d.ts +0 -10
  149. package/dist/types/options.d.ts +7 -7
  150. package/dist/types/types.d.ts +91 -20
  151. package/package.json +18 -16
  152. package/dist/chunk-265BMFM5.js +0 -13
  153. package/dist/chunk-265BMFM5.js.map +0 -1
  154. package/dist/chunk-2OHD2VKS.js.map +0 -1
  155. package/dist/chunk-3FDEYMQU.js.map +0 -1
  156. package/dist/chunk-44ARQBXS.js.map +0 -1
  157. package/dist/chunk-6V5GEUDO.mjs.map +0 -1
  158. package/dist/chunk-74TIKA2T.mjs.map +0 -1
  159. package/dist/chunk-AFA4KKWW.mjs.map +0 -1
  160. package/dist/chunk-B73P64TE.mjs.map +0 -1
  161. package/dist/chunk-E2BYTLOT.mjs.map +0 -1
  162. package/dist/chunk-EDFQDZNY.js.map +0 -1
  163. package/dist/chunk-GG2BCPQH.mjs.map +0 -1
  164. package/dist/chunk-HOI6FPLR.mjs.map +0 -1
  165. package/dist/chunk-IH7UNS5A.mjs.map +0 -1
  166. package/dist/chunk-KQBJQLZG.js.map +0 -1
  167. package/dist/chunk-KSIBNOB2.mjs +0 -13
  168. package/dist/chunk-KSIBNOB2.mjs.map +0 -1
  169. package/dist/chunk-MBQHVBLA.js.map +0 -1
  170. package/dist/chunk-ORO3T6BU.mjs +0 -24
  171. package/dist/chunk-ORO3T6BU.mjs.map +0 -1
  172. package/dist/chunk-PZDTZGSI.js.map +0 -1
  173. package/dist/chunk-R55KAAM4.js +0 -306
  174. package/dist/chunk-R55KAAM4.js.map +0 -1
  175. package/dist/chunk-RAMAN5RM.js +0 -24
  176. package/dist/chunk-RAMAN5RM.js.map +0 -1
  177. package/dist/chunk-T2PHS5FY.js.map +0 -1
  178. package/dist/chunk-TBDYQSRT.mjs +0 -16
  179. package/dist/chunk-TBDYQSRT.mjs.map +0 -1
  180. package/dist/chunk-TMAWGVZP.mjs.map +0 -1
  181. package/dist/chunk-TVD4SWH7.js +0 -16
  182. package/dist/chunk-TVD4SWH7.js.map +0 -1
  183. package/dist/chunk-U3DVRTS2.mjs.map +0 -1
  184. package/dist/chunk-UPR3PTSA.mjs.map +0 -1
  185. package/dist/chunk-VXPCUDBI.js.map +0 -1
  186. package/dist/chunk-XKJHFUHE.js.map +0 -1
  187. package/dist/chunk-YNUVT3HC.js.map +0 -1
  188. package/dist/internals/simulation/methods/hooks/get-locale.js +0 -8
  189. package/dist/internals/simulation/methods/hooks/get-locale.mjs +0 -8
  190. package/dist/internals/simulation/methods/hooks/show-dialog.js +0 -14
  191. package/dist/internals/simulation/methods/hooks/show-dialog.mjs +0 -14
  192. package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +0 -9
  193. package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +0 -9
  194. /package/dist/{chunk-KNJNL723.mjs.map → chunk-3J2IBWXV.mjs.map} +0 -0
  195. /package/dist/{chunk-K55LIE3W.mjs.map → chunk-CACRY3TX.mjs.map} +0 -0
  196. /package/dist/{chunk-WMLSD6B5.js.map → chunk-K7MK6LQU.js.map} +0 -0
  197. /package/dist/{chunk-JXAJWUVZ.js.map → chunk-OO6IVUCV.js.map} +0 -0
  198. /package/dist/{chunk-3M4GRUMH.mjs.map → chunk-ORR7AE5X.mjs.map} +0 -0
  199. /package/dist/{chunk-XWGECIXI.js.map → chunk-RJNNNCZJ.js.map} +0 -0
  200. /package/dist/internals/simulation/methods/hooks/{get-locale.js.map → get-preferences.js.map} +0 -0
  201. /package/dist/internals/simulation/methods/hooks/{get-locale.mjs.map → get-preferences.mjs.map} +0 -0
  202. /package/dist/internals/simulation/methods/hooks/{show-dialog.js.map → request-user-approval.js.map} +0 -0
  203. /package/dist/internals/simulation/methods/hooks/{show-dialog.mjs.map → request-user-approval.mjs.map} +0 -0
@@ -1,7 +1,49 @@
1
1
  import type { AbstractExecutionService } from '@metamask/snaps-controllers';
2
2
  import type { SnapId } from '@metamask/snaps-sdk';
3
3
  import type { InstallSnapOptions } from './internals';
4
- import type { Snap } from './types';
4
+ import type { Snap, SnapInterface, SnapAlertInterface, SnapInterfaceActions, SnapConfirmationInterface, SnapPromptInterface, DefaultSnapInterface, DefaultSnapInterfaceWithFooter, DefaultSnapInterfaceWithPartialFooter, DefaultSnapInterfaceWithoutFooter } from './types';
5
+ /**
6
+ * Ensure that the actual interface is an alert dialog.
7
+ *
8
+ * @param ui - The interface to verify.
9
+ */
10
+ export declare function assertIsAlertDialog(ui: SnapInterface): asserts ui is SnapAlertInterface & SnapInterfaceActions;
11
+ /**
12
+ * Ensure that the actual interface is a confirmation dialog.
13
+ *
14
+ * @param ui - The interface to verify.
15
+ */
16
+ export declare function assertIsConfirmationDialog(ui: SnapInterface): asserts ui is SnapConfirmationInterface & SnapInterfaceActions;
17
+ /**
18
+ * Ensure that the actual interface is a Prompt dialog.
19
+ *
20
+ * @param ui - The interface to verify.
21
+ */
22
+ export declare function assertIsPromptDialog(ui: SnapInterface): asserts ui is SnapPromptInterface & SnapInterfaceActions;
23
+ /**
24
+ * Ensure that the actual interface is a custom dialog.
25
+ *
26
+ * @param ui - The interface to verify.
27
+ */
28
+ export declare function assertIsCustomDialog(ui: SnapInterface): asserts ui is DefaultSnapInterface & SnapInterfaceActions;
29
+ /**
30
+ * Ensure that the actual interface is a custom dialog with a complete footer.
31
+ *
32
+ * @param ui - The interface to verify.
33
+ */
34
+ export declare function assertCustomDialogHasFooter(ui: DefaultSnapInterface & SnapInterfaceActions): asserts ui is DefaultSnapInterfaceWithFooter & SnapInterfaceActions;
35
+ /**
36
+ * Ensure that the actual interface is a custom dialog with a partial footer.
37
+ *
38
+ * @param ui - The interface to verify.
39
+ */
40
+ export declare function assertCustomDialogHasPartialFooter(ui: DefaultSnapInterface & SnapInterfaceActions): asserts ui is DefaultSnapInterfaceWithPartialFooter & SnapInterfaceActions;
41
+ /**
42
+ * Ensure that the actual interface is a custom dialog without a footer.
43
+ *
44
+ * @param ui - The interface to verify.
45
+ */
46
+ export declare function assertCustomDialogHasNoFooter(ui: DefaultSnapInterface & SnapInterfaceActions): asserts ui is DefaultSnapInterfaceWithoutFooter & SnapInterfaceActions;
5
47
  /**
6
48
  * Load a snap into the environment. This is the main entry point for testing
7
49
  * snaps: It returns a {@link Snap} object that can be used to interact with the
@@ -4,7 +4,7 @@ import type { HandlerType } from '@metamask/snaps-utils';
4
4
  import type { RequestOptions, SnapHandlerInterface, SnapRequest } from '../types';
5
5
  import type { RunSagaFunction, Store } from './simulation';
6
6
  import type { RootControllerMessenger } from './simulation/controllers';
7
- export declare type HandleRequestOptions = {
7
+ export type HandleRequestOptions = {
8
8
  snapId: SnapId;
9
9
  store: Store;
10
10
  executionService: AbstractExecutionService<unknown>;
@@ -44,7 +44,8 @@ export declare function handleRequest({ snapId, store, executionService, handler
44
44
  */
45
45
  export declare function getInterfaceFromResult(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<string | undefined>;
46
46
  /**
47
- * Get the response content from the SnapInterfaceController and include the interaction methods.
47
+ * Get the response content from the `SnapInterfaceController` and include the
48
+ * interaction methods.
48
49
  *
49
50
  * @param result - The handler result object.
50
51
  * @param snapId - The Snap ID.
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
2
  import type { Server } from 'http';
3
3
  import type { SnapsEnvironmentOptions } from '../options';
4
- export declare type ServerOptions = Required<Required<SnapsEnvironmentOptions>['server']>;
4
+ export type ServerOptions = Required<Required<SnapsEnvironmentOptions>['server']>;
5
5
  /**
6
6
  * Start an HTTP server on `localhost` with a random port. This is used to serve
7
7
  * the static files for the environment.
@@ -7,6 +7,10 @@ export declare const DEFAULT_SRP = "test test test test test test test test test
7
7
  * The default locale.
8
8
  */
9
9
  export declare const DEFAULT_LOCALE = "en";
10
+ /**
11
+ * The default currency.
12
+ */
13
+ export declare const DEFAULT_CURRENCY = "usd";
10
14
  /**
11
15
  * The default JSON-RPC endpoint for Ethereum requests.
12
16
  */
@@ -8,15 +8,15 @@ import type { SnapManifest } from '@metamask/snaps-utils';
8
8
  import type { SimulationOptions } from './options';
9
9
  import type { MiddlewareHooks } from './simulation';
10
10
  import type { RunSagaFunction } from './store';
11
- export declare type RootControllerAllowedActions = SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions | PermissionControllerActions | ExecutionServiceActions | SubjectMetadataControllerActions;
12
- export declare type RootControllerMessenger = ControllerMessenger<RootControllerAllowedActions, any>;
13
- export declare type GetControllersOptions = {
11
+ export type RootControllerAllowedActions = SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions | PermissionControllerActions | ExecutionServiceActions | SubjectMetadataControllerActions;
12
+ export type RootControllerMessenger = ControllerMessenger<RootControllerAllowedActions, any>;
13
+ export type GetControllersOptions = {
14
14
  controllerMessenger: ControllerMessenger<any, any>;
15
15
  hooks: MiddlewareHooks;
16
16
  runSaga: RunSagaFunction;
17
17
  options: SimulationOptions;
18
18
  };
19
- export declare type Controllers = {
19
+ export type Controllers = {
20
20
  permissionController: PermissionController<PermissionSpecificationConstraint, CaveatSpecificationConstraint>;
21
21
  subjectMetadataController: SubjectMetadataController;
22
22
  interfaceController: SnapInterfaceController;
@@ -1,5 +1,7 @@
1
+ import type { File } from '@metamask/snaps-sdk';
1
2
  import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';
2
3
  import type { VirtualFile } from '@metamask/snaps-utils';
4
+ import type { FileOptions } from '../../types';
3
5
  /**
4
6
  * Get a statically defined Snap file from an array of files.
5
7
  *
@@ -9,3 +11,37 @@ import type { VirtualFile } from '@metamask/snaps-utils';
9
11
  * @returns The file in the requested encoding if found, otherwise null.
10
12
  */
11
13
  export declare function getSnapFile(files: VirtualFile[], path: string, encoding?: AuxiliaryFileEncoding): Promise<string | null>;
14
+ /**
15
+ * Get the content type of a file based on its extension.
16
+ *
17
+ * @param extension - The file extension.
18
+ * @returns The content type of the file. If the content type cannot be inferred
19
+ * from the extension, `application/octet-stream` is returned.
20
+ */
21
+ export declare function getContentType(extension: string): string;
22
+ /**
23
+ * Get the size of a file, from a file path or a `Uint8Array`.
24
+ *
25
+ * @param file - The file to get the size of. This can be a path to a file or a
26
+ * `Uint8Array` containing the file contents. If this is a path, the file is
27
+ * resolved relative to the current working directory.
28
+ * @returns The size of the file in bytes.
29
+ */
30
+ export declare function getFileSize(file: string | Uint8Array): Promise<number>;
31
+ /**
32
+ * Get a file object to upload, from a file path or a `Uint8Array`, with an
33
+ * optional file name and content type.
34
+ *
35
+ * @param file - The file to upload. This can be a path to a file or a
36
+ * `Uint8Array` containing the file contents. If this is a path, the file is
37
+ * resolved relative to the current working directory.
38
+ * @param options - The file options.
39
+ * @param options.fileName - The name of the file. By default, this is
40
+ * inferred from the file path if it's a path, and defaults to an empty string
41
+ * if it's a `Uint8Array`.
42
+ * @param options.contentType - The content type of the file. By default, this
43
+ * is inferred from the file name if it's a path, and defaults to
44
+ * `application/octet-stream` if it's a `Uint8Array` or the content type
45
+ * cannot be inferred from the file name.
46
+ */
47
+ export declare function getFileToUpload(file: string | Uint8Array, { fileName, contentType }?: FileOptions): Promise<File>;
@@ -1,10 +1,11 @@
1
- import type { InterfaceState, SnapId } from '@metamask/snaps-sdk';
1
+ import type { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';
2
+ import type { InterfaceState, SnapId, File } from '@metamask/snaps-sdk';
2
3
  import { DialogType } from '@metamask/snaps-sdk';
3
- import type { JSXElement } from '@metamask/snaps-sdk/jsx';
4
+ import { type JSXElement } from '@metamask/snaps-sdk/jsx';
4
5
  import { type SagaIterator } from 'redux-saga';
5
- import type { SnapInterface, SnapInterfaceActions } from '../../types';
6
+ import type { FileOptions, SnapInterface, SnapInterfaceActions } from '../../types';
6
7
  import type { RootControllerMessenger } from './controllers';
7
- import type { RunSagaFunction } from './store';
8
+ import type { Interface, RunSagaFunction } from './store';
8
9
  /**
9
10
  * Get a user interface object from a type and content object.
10
11
  *
@@ -14,11 +15,18 @@ import type { RunSagaFunction } from './store';
14
15
  * @param interfaceActions - The actions to interact with the interface.
15
16
  * @returns The user interface object.
16
17
  */
17
- export declare function getInterfaceResponse(runSaga: RunSagaFunction, type: DialogType, content: JSXElement, interfaceActions: SnapInterfaceActions): SnapInterface;
18
+ export declare function getInterfaceResponse(runSaga: RunSagaFunction, type: DialogApprovalTypes[DialogType | 'default'], content: JSXElement, interfaceActions: SnapInterfaceActions): SnapInterface;
19
+ /**
20
+ * Resolve the current user interface with the given value.
21
+ *
22
+ * @param value - The value to resolve the user interface with.
23
+ * @yields Puts the resolve user interface action.
24
+ */
25
+ export declare function resolveWithSaga(value: unknown): SagaIterator;
18
26
  /**
19
27
  * A JSX element with a name.
20
28
  */
21
- export declare type NamedJSXElement = JSXElement & {
29
+ export type NamedJSXElement = JSXElement & {
22
30
  props: {
23
31
  name: string;
24
32
  };
@@ -35,6 +43,14 @@ export declare function getElement(content: JSXElement, name: string): {
35
43
  element: NamedJSXElement;
36
44
  form?: string;
37
45
  } | undefined;
46
+ /**
47
+ * Get an element from a JSX tree with the given type.
48
+ *
49
+ * @param content - The interface content.
50
+ * @param type - The element type.
51
+ * @returns The element with the given type.
52
+ */
53
+ export declare function getElementByType<Element extends JSXElement>(content: JSXElement, type: string): Element | undefined;
38
54
  /**
39
55
  * Click on an element of the Snap interface.
40
56
  *
@@ -54,7 +70,7 @@ export declare function clickElement(controllerMessenger: RootControllerMessenge
54
70
  * @param form - The form name if the element is in one.
55
71
  * @returns The state with the merged value.
56
72
  */
57
- export declare function mergeValue(state: InterfaceState, name: string, value: string | null, form?: string): InterfaceState;
73
+ export declare function mergeValue(state: InterfaceState, name: string, value: string | File | boolean | null, form?: string): InterfaceState;
58
74
  /**
59
75
  * Type a value in an interface element.
60
76
  *
@@ -77,6 +93,52 @@ export declare function typeInField(controllerMessenger: RootControllerMessenger
77
93
  * @param value - The value to type in the element.
78
94
  */
79
95
  export declare function selectInDropdown(controllerMessenger: RootControllerMessenger, id: string, content: JSXElement, snapId: SnapId, name: string, value: string): Promise<void>;
96
+ /**
97
+ * Choose an option with value from radio group interface element.
98
+ *
99
+ * @param controllerMessenger - The controller messenger used to call actions.
100
+ * @param id - The interface ID.
101
+ * @param content - The interface Components.
102
+ * @param snapId - The Snap ID.
103
+ * @param name - The element name.
104
+ * @param value - The value to type in the element.
105
+ */
106
+ export declare function selectFromRadioGroup(controllerMessenger: RootControllerMessenger, id: string, content: JSXElement, snapId: SnapId, name: string, value: string): Promise<void>;
107
+ /**
108
+ * Upload a file to an interface element.
109
+ *
110
+ * @param controllerMessenger - The controller messenger used to call actions.
111
+ * @param id - The interface ID.
112
+ * @param content - The interface Components.
113
+ * @param snapId - The Snap ID.
114
+ * @param name - The element name.
115
+ * @param file - The file to upload. This can be a path to a file or a
116
+ * `Uint8Array` containing the file contents. If this is a path, the file is
117
+ * resolved relative to the current working directory.
118
+ * @param options - The file options.
119
+ * @param options.fileName - The name of the file. By default, this is
120
+ * inferred from the file path if it's a path, and defaults to an empty string
121
+ * if it's a `Uint8Array`.
122
+ * @param options.contentType - The content type of the file. By default, this
123
+ * is inferred from the file name if it's a path, and defaults to
124
+ * `application/octet-stream` if it's a `Uint8Array` or the content type
125
+ * cannot be inferred from the file name.
126
+ */
127
+ export declare function uploadFile(controllerMessenger: RootControllerMessenger, id: string, content: JSXElement, snapId: SnapId, name: string, file: string | Uint8Array, options?: FileOptions): Promise<void>;
128
+ /**
129
+ * Get the user interface actions for a Snap interface. These actions can be
130
+ * used to interact with the interface.
131
+ *
132
+ * @param snapId - The Snap ID.
133
+ * @param controllerMessenger - The controller messenger used to call actions.
134
+ * @param interface - The interface object.
135
+ * @param interface.content - The interface content.
136
+ * @param interface.id - The interface ID.
137
+ * @returns The user interface actions.
138
+ */
139
+ export declare function getInterfaceActions(snapId: SnapId, controllerMessenger: RootControllerMessenger, { content, id }: Omit<Interface, 'type'> & {
140
+ content: JSXElement;
141
+ }): SnapInterfaceActions;
80
142
  /**
81
143
  * Get a user interface object from a Snap.
82
144
  *
@@ -86,4 +148,4 @@ export declare function selectInDropdown(controllerMessenger: RootControllerMess
86
148
  * @yields Takes the set interface action.
87
149
  * @returns The user interface object.
88
150
  */
89
- export declare function getInterface(runSaga: RunSagaFunction, snapId: SnapId, controllerMessenger: RootControllerMessenger): SagaIterator<SnapInterface>;
151
+ export declare function getInterface(runSaga: RunSagaFunction, snapId: SnapId, controllerMessenger: RootControllerMessenger): SagaIterator;
@@ -0,0 +1,13 @@
1
+ import type { SimulationOptions } from '../../options';
2
+ /**
3
+ * Get the implementation of the `getPreferences` hook.
4
+ *
5
+ * @param options - The simulation options.
6
+ * @param options.currency - The currency to use.
7
+ * @param options.locale - The locale to use.
8
+ * @returns The implementation of the `getPreferences` hook.
9
+ */
10
+ export declare function getGetPreferencesMethodImplementation({ currency, locale, }: SimulationOptions): () => {
11
+ currency: string;
12
+ locale: string;
13
+ };
@@ -1,5 +1,5 @@
1
- export * from './get-locale';
1
+ export * from './get-preferences';
2
2
  export * from './notifications';
3
- export * from './show-dialog';
3
+ export * from './request-user-approval';
4
4
  export * from './state';
5
5
  export * from './interface';
@@ -0,0 +1,15 @@
1
+ import type { RunSagaFunction } from '../../store';
2
+ type RequestUserApprovalParams = {
3
+ type: string;
4
+ requestData: {
5
+ id: string;
6
+ };
7
+ };
8
+ /**
9
+ * Get the implementation of the `requestUserApproval` hook.
10
+ *
11
+ * @param runSaga - The function to run a saga outside the usual Redux flow.
12
+ * @returns The implementation of the `requestUserApproval` hook.
13
+ */
14
+ export declare function getRequestUserApprovalImplementation(runSaga: RunSagaFunction): (args_0: RequestUserApprovalParams) => Promise<any>;
15
+ export {};
@@ -3,7 +3,7 @@ import type { SnapId } from '@metamask/snaps-sdk';
3
3
  import type { RootControllerMessenger } from '../controllers';
4
4
  import type { SimulationOptions } from '../options';
5
5
  import type { RunSagaFunction } from '../store';
6
- export declare type PermissionSpecificationsHooks = {
6
+ export type PermissionSpecificationsHooks = {
7
7
  /**
8
8
  * A hook that returns the user's secret recovery phrase.
9
9
  *
@@ -11,7 +11,7 @@ export declare type PermissionSpecificationsHooks = {
11
11
  */
12
12
  getMnemonic: () => Promise<Uint8Array>;
13
13
  };
14
- export declare type GetPermissionSpecificationsOptions = {
14
+ export type GetPermissionSpecificationsOptions = {
15
15
  controllerMessenger: RootControllerMessenger;
16
16
  hooks: PermissionSpecificationsHooks;
17
17
  runSaga: RunSagaFunction;
@@ -4,7 +4,7 @@ import type { RestrictedMethodParameters } from '@metamask/permission-controller
4
4
  import type { Json } from '@metamask/utils';
5
5
  import type { MiddlewareHooks } from '../simulation';
6
6
  import type { Store } from '../store';
7
- export declare type CreateJsonRpcEngineOptions = {
7
+ export type CreateJsonRpcEngineOptions = {
8
8
  store: Store;
9
9
  hooks: MiddlewareHooks;
10
10
  permissionMiddleware: JsonRpcMiddleware<RestrictedMethodParameters, Json>;
@@ -1,6 +1,6 @@
1
1
  import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from '@metamask/json-rpc-engine';
2
2
  import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';
3
- export declare type GetAccountsHandlerHooks = {
3
+ export type GetAccountsHandlerHooks = {
4
4
  getMnemonic: () => Promise<Uint8Array>;
5
5
  };
6
6
  /**
@@ -1,6 +1,6 @@
1
1
  import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';
2
2
  import type { Json, JsonRpcParams } from '@metamask/utils';
3
- export declare type InternalMethodsMiddlewareHooks = {
3
+ export type InternalMethodsMiddlewareHooks = {
4
4
  /**
5
5
  * A hook that returns the user's secret recovery phrase.
6
6
  *
@@ -1,14 +1,16 @@
1
- import type { Infer } from 'superstruct';
2
- declare const SimulationOptionsStruct: import("superstruct").Struct<{
1
+ import type { Infer } from '@metamask/superstruct';
2
+ declare const SimulationOptionsStruct: import("@metamask/superstruct").Struct<{
3
3
  state?: Record<string, import("@metamask/utils").Json> | null | undefined;
4
4
  locale?: string | undefined;
5
5
  secretRecoveryPhrase?: string | undefined;
6
+ currency?: string | undefined;
6
7
  unencryptedState?: Record<string, import("@metamask/utils").Json> | null | undefined;
7
8
  }, {
8
- secretRecoveryPhrase: import("superstruct").Struct<string | undefined, null>;
9
- locale: import("superstruct").Struct<string | undefined, null>;
10
- state: import("superstruct").Struct<Record<string, import("@metamask/utils").Json> | null | undefined, null>;
11
- unencryptedState: import("superstruct").Struct<Record<string, import("@metamask/utils").Json> | null | undefined, null>;
9
+ currency: import("@metamask/superstruct").Struct<string | undefined, null>;
10
+ secretRecoveryPhrase: import("@metamask/superstruct").Struct<string | undefined, null>;
11
+ locale: import("@metamask/superstruct").Struct<string | undefined, null>;
12
+ state: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | null | undefined, null>;
13
+ unencryptedState: import("@metamask/superstruct").Struct<Record<string, import("@metamask/utils").Json> | null | undefined, null>;
12
14
  }>;
13
15
  /**
14
16
  * Options for the simulation.
@@ -19,13 +21,13 @@ declare const SimulationOptionsStruct: import("superstruct").Struct<{
19
21
  * @property locale - The locale to use. Defaults to `en`.
20
22
  * @property state - The initial state of the Snap, if any. Defaults to `null`.
21
23
  */
22
- export declare type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;
24
+ export type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;
23
25
  /**
24
26
  * Options for the simulation, with defaults filled in.
25
27
  *
26
28
  * See {@link SimulationUserOptions} for documentation.
27
29
  */
28
- export declare type SimulationOptions = Required<SimulationUserOptions>;
30
+ export type SimulationOptions = Required<SimulationUserOptions>;
29
31
  /**
30
32
  * Get the options for the simulation.
31
33
  *
@@ -3,6 +3,7 @@ import { ControllerMessenger } from '@metamask/base-controller';
3
3
  import type { AbstractExecutionService } from '@metamask/snaps-controllers';
4
4
  import type { SnapId, AuxiliaryFileEncoding, Component, InterfaceState } from '@metamask/snaps-sdk';
5
5
  import type { FetchedSnapFiles } from '@metamask/snaps-utils';
6
+ import type { Json } from '@metamask/utils';
6
7
  import type { RootControllerMessenger } from './controllers';
7
8
  import type { SimulationOptions, SimulationUserOptions } from './options';
8
9
  import type { RunSagaFunction, Store } from './store';
@@ -13,7 +14,7 @@ import type { RunSagaFunction, Store } from './store';
13
14
  * @template Service - The type of the execution service, i.e., the class that
14
15
  * creates the execution service.
15
16
  */
16
- export declare type ExecutionServiceOptions<Service extends new (...args: any[]) => any> = Omit<ConstructorParameters<Service>[0], keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]>;
17
+ export type ExecutionServiceOptions<Service extends new (...args: any[]) => any> = Omit<ConstructorParameters<Service>[0], keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]>;
17
18
  /**
18
19
  * The options for running a Snap in a simulated environment.
19
20
  *
@@ -24,7 +25,7 @@ export declare type ExecutionServiceOptions<Service extends new (...args: any[])
24
25
  * @property options - The simulation options.
25
26
  * @template Service - The type of the execution service.
26
27
  */
27
- export declare type InstallSnapOptions<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService<unknown>>> = ExecutionServiceOptions<Service> extends Record<string, never> ? {
28
+ export type InstallSnapOptions<Service extends new (...args: any[]) => InstanceType<typeof AbstractExecutionService<unknown>>> = ExecutionServiceOptions<Service> extends Record<string, never> ? {
28
29
  executionService: Service;
29
30
  executionServiceOptions?: ExecutionServiceOptions<Service>;
30
31
  options?: SimulationUserOptions;
@@ -33,14 +34,14 @@ export declare type InstallSnapOptions<Service extends new (...args: any[]) => I
33
34
  executionServiceOptions: ExecutionServiceOptions<Service>;
34
35
  options?: SimulationUserOptions;
35
36
  };
36
- export declare type InstalledSnap = {
37
+ export type InstalledSnap = {
37
38
  snapId: SnapId;
38
39
  store: Store;
39
40
  executionService: InstanceType<typeof AbstractExecutionService>;
40
41
  controllerMessenger: ControllerMessenger<ActionConstraint, EventConstraint>;
41
42
  runSaga: RunSagaFunction;
42
43
  };
43
- export declare type MiddlewareHooks = {
44
+ export type MiddlewareHooks = {
44
45
  /**
45
46
  * A hook that returns the user's secret recovery phrase.
46
47
  *
@@ -64,6 +65,7 @@ export declare type MiddlewareHooks = {
64
65
  createInterface: (content: Component) => Promise<string>;
65
66
  updateInterface: (id: string, content: Component) => Promise<void>;
66
67
  getInterfaceState: (id: string) => InterfaceState;
68
+ resolveInterface: (id: string, value: Json) => Promise<void>;
67
69
  };
68
70
  /**
69
71
  * Install a Snap in a simulated environment. This will fetch the Snap files,
@@ -94,5 +96,6 @@ export declare function getHooks(options: SimulationOptions, snapFiles: FetchedS
94
96
  * Register mocked action handlers.
95
97
  *
96
98
  * @param controllerMessenger - The controller messenger.
99
+ * @param runSaga - The run saga function.
97
100
  */
98
- export declare function registerActions(controllerMessenger: RootControllerMessenger): void;
101
+ export declare function registerActions(controllerMessenger: RootControllerMessenger, runSaga: RunSagaFunction): void;
@@ -1,11 +1,11 @@
1
1
  import type { Json } from '@metamask/utils';
2
2
  import type { PayloadAction } from '@reduxjs/toolkit';
3
3
  import type { ApplicationState } from './store';
4
- export declare type JsonRpcMock = {
4
+ export type JsonRpcMock = {
5
5
  method: string;
6
6
  result: Json;
7
7
  };
8
- export declare type MocksState = {
8
+ export type MocksState = {
9
9
  jsonRpc: Record<string, Json>;
10
10
  };
11
11
  export declare const mocksSlice: import("@reduxjs/toolkit").Slice<MocksState, {
@@ -7,7 +7,7 @@ import type { PayloadAction } from '@reduxjs/toolkit';
7
7
  * @property message - The notification message.
8
8
  * @property type - The notification type.
9
9
  */
10
- export declare type Notification = {
10
+ export type Notification = {
11
11
  id: string;
12
12
  message: string;
13
13
  type: NotificationType;
@@ -17,7 +17,7 @@ export declare type Notification = {
17
17
  *
18
18
  * @property notifications - An array of notifications.
19
19
  */
20
- export declare type NotificationsState = {
20
+ export type NotificationsState = {
21
21
  notifications: Notification[];
22
22
  };
23
23
  export declare const notificationsSlice: import("@reduxjs/toolkit").Slice<NotificationsState, {
@@ -7,7 +7,7 @@ import type { PayloadAction } from '@reduxjs/toolkit';
7
7
  * @property unencrypted - The unencrypted state. Can be null if the Snap does
8
8
  * not have an unencrypted state.
9
9
  */
10
- export declare type State = {
10
+ export type State = {
11
11
  encrypted: string | null;
12
12
  unencrypted: string | null;
13
13
  };
@@ -14,8 +14,8 @@ export declare function createStore({ state, unencryptedState }: SimulationOptio
14
14
  state: import("./state").State;
15
15
  ui: import("./ui").UiState;
16
16
  }, import("redux").AnyAction, import("@reduxjs/toolkit").MiddlewareArray<[import("redux-saga").SagaMiddleware<object>]>>;
17
- runSaga: <S extends import("redux-saga").Saga<any[]>>(saga: S, ...args: Parameters<S>) => import("redux-saga").Task<any>;
17
+ runSaga: <S extends import("redux-saga").Saga>(saga: S, ...args: Parameters<S>) => import("redux-saga").Task<any>;
18
18
  };
19
- export declare type Store = ReturnType<typeof createStore>['store'];
20
- export declare type ApplicationState = ReturnType<Store['getState']>;
21
- export declare type RunSagaFunction = ReturnType<typeof createStore>['runSaga'];
19
+ export type Store = ReturnType<typeof createStore>['store'];
20
+ export type ApplicationState = ReturnType<Store['getState']>;
21
+ export type RunSagaFunction = ReturnType<typeof createStore>['runSaga'];
@@ -1,10 +1,11 @@
1
+ import type { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';
1
2
  import type { DialogType } from '@metamask/snaps-sdk';
2
3
  import type { PayloadAction } from '@reduxjs/toolkit';
3
- export declare type Interface = {
4
- type: DialogType;
4
+ export type Interface = {
5
+ type: DialogApprovalTypes[DialogType | 'default'];
5
6
  id: string;
6
7
  };
7
- export declare type UiState = {
8
+ export type UiState = {
8
9
  current?: Interface | null;
9
10
  };
10
11
  export declare const uiSlice: import("@reduxjs/toolkit").Slice<UiState, {