@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
package/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [8.3.0]
10
+ ### Added
11
+ - Add support for `snap_getPreferences` ([#2607](https://github.com/MetaMask/snaps/pull/2607))
12
+ - Add `RadioButton` component ([#2592](https://github.com/MetaMask/snaps/pull/2592))
13
+ - Add support for custom dialogs in `snaps-jest` ([#2526](https://github.com/MetaMask/snaps/pull/2526), [#2509](https://github.com/MetaMask/snaps/pull/2509))
14
+
15
+ ### Changed
16
+ - Replace `superstruct` with ESM-compatible fork `@metamask/superstruct` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
17
+
18
+ ## [8.2.0]
19
+ ### Added
20
+ - Add support for `Checkbox` to `snaps-jest` ([#2515](https://github.com/MetaMask/snaps/pull/2515))
21
+ - Checkboxes can be interacted with using `clickElement`.
22
+ - Add support for `FileInput` to `snaps-jest` ([#2494](https://github.com/MetaMask/snaps/pull/2494))
23
+ - Files can be uploaded to file inputs using `uploadFile`.
24
+
9
25
  ## [8.1.3]
10
26
  ### Changed
11
27
  - Bump MetaMask dependencies ([#2460](https://github.com/MetaMask/snaps/pull/2460), [#2477](https://github.com/MetaMask/snaps/pull/2477))
@@ -165,7 +181,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
165
181
  - The version of the package no longer needs to match the version of all other
166
182
  MetaMask Snaps packages.
167
183
 
168
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.1.3...HEAD
184
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.3.0...HEAD
185
+ [8.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.2.0...@metamask/snaps-jest@8.3.0
186
+ [8.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.1.3...@metamask/snaps-jest@8.2.0
169
187
  [8.1.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.1.2...@metamask/snaps-jest@8.1.3
170
188
  [8.1.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.1.1...@metamask/snaps-jest@8.1.2
171
189
  [8.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-jest@8.1.0...@metamask/snaps-jest@8.1.1
package/README.md CHANGED
@@ -362,7 +362,7 @@ functions that can be used to interact with the user interface.
362
362
  ##### Example
363
363
 
364
364
  ```js
365
- import { installSnap } from '@metamask/snaps-jest';
365
+ import { installSnap, assertIsAlertDialog } from '@metamask/snaps-jest';
366
366
  import { text } from '@metamask/snaps-sdk';
367
367
  import { assert } from '@metamask/utils';
368
368
 
@@ -379,7 +379,7 @@ describe('MySnap', () => {
379
379
 
380
380
  // This is useful if you're using TypeScript, since it will infer the type
381
381
  // of the user interface.
382
- assert(ui.type === 'alert');
382
+ assertIsAlertDialog(ui);
383
383
  expect(ui).toRender(text('Hello, world!'));
384
384
 
385
385
  // "Click" the OK button.
@@ -0,0 +1,30 @@
1
+ import {
2
+ closeInterface,
3
+ resolveInterface,
4
+ setInterface
5
+ } from "./chunk-ZJQSGRNK.mjs";
6
+
7
+ // src/internals/simulation/methods/hooks/request-user-approval.ts
8
+ import { put, take } from "redux-saga/effects";
9
+ function* requestUserApprovalImplementation({
10
+ type,
11
+ requestData: { id }
12
+ }) {
13
+ yield put(setInterface({ type, id }));
14
+ const { payload } = yield take(resolveInterface.type);
15
+ yield put(closeInterface());
16
+ return payload;
17
+ }
18
+ function getRequestUserApprovalImplementation(runSaga) {
19
+ return async (...args) => {
20
+ return await runSaga(
21
+ requestUserApprovalImplementation,
22
+ ...args
23
+ ).toPromise();
24
+ };
25
+ }
26
+
27
+ export {
28
+ getRequestUserApprovalImplementation
29
+ };
30
+ //# sourceMappingURL=chunk-24CGIQLL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internals/simulation/methods/hooks/request-user-approval.ts"],"sourcesContent":["import type { SagaIterator } from 'redux-saga';\nimport { put, take } from 'redux-saga/effects';\n\nimport type { RunSagaFunction } from '../../store';\nimport { resolveInterface, setInterface, closeInterface } from '../../store';\n\ntype RequestUserApprovalParams = {\n type: string;\n requestData: {\n id: string;\n };\n};\n\n/**\n * Show a dialog to the user. This will wait for `resolveUserInterface` to be\n * dispatched before returning.\n *\n * @param opts - The options for the request.\n * @param opts.type - The type of dialog to show.\n * @param opts.requestData - The data to display in the dialog.\n * @param opts.requestData.id - The ID of the interface.\n * @yields Sets the dialog in the store, waits for the user to resolve the\n * dialog, and closes the dialog.\n * @returns The result of the dialog.\n */\nfunction* requestUserApprovalImplementation({\n type,\n requestData: { id },\n}: RequestUserApprovalParams): SagaIterator<unknown> {\n yield put(setInterface({ type, id }));\n\n // We use `take` to wait for `resolveUserInterface` to be dispatched, which\n // indicates that the user has resolved the dialog.\n const { payload } = yield take(resolveInterface.type);\n yield put(closeInterface());\n\n return payload;\n}\n\n/**\n * Get the implementation of the `requestUserApproval` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `requestUserApproval` hook.\n */\nexport function getRequestUserApprovalImplementation(runSaga: RunSagaFunction) {\n return async (\n ...args: Parameters<typeof requestUserApprovalImplementation>\n ) => {\n return await runSaga(\n requestUserApprovalImplementation,\n ...args,\n ).toPromise();\n };\n}\n"],"mappings":";;;;;;;AACA,SAAS,KAAK,YAAY;AAwB1B,UAAU,kCAAkC;AAAA,EAC1C;AAAA,EACA,aAAa,EAAE,GAAG;AACpB,GAAqD;AACnD,QAAM,IAAI,aAAa,EAAE,MAAM,GAAG,CAAC,CAAC;AAIpC,QAAM,EAAE,QAAQ,IAAI,MAAM,KAAK,iBAAiB,IAAI;AACpD,QAAM,IAAI,eAAe,CAAC;AAE1B,SAAO;AACT;AAQO,SAAS,qCAAqC,SAA0B;AAC7E,SAAO,UACF,SACA;AACH,WAAO,MAAM;AAAA,MACX;AAAA,MACA,GAAG;AAAA,IACL,EAAE,UAAU;AAAA,EACd;AACF;","names":[]}
@@ -7,7 +7,7 @@
7
7
 
8
8
 
9
9
 
10
- var _superstruct = require('superstruct');
10
+ var _superstruct = require('@metamask/superstruct');
11
11
  var SnapsEnvironmentOptionsStruct = _superstruct.type.call(void 0, {
12
12
  server: _superstruct.defaulted.call(void 0,
13
13
  _superstruct.object.call(void 0, {
@@ -25,4 +25,4 @@ function getOptions(testEnvironmentOptions) {
25
25
 
26
26
 
27
27
  exports.getOptions = getOptions;
28
- //# sourceMappingURL=chunk-T2PHS5FY.js.map
28
+ //# sourceMappingURL=chunk-2RJYSYUB.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/options.ts"],"names":[],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,IAAM,gCAAgC,KAAK;AAAA,EACzC,QAAQ;AAAA,IACN,OAAO;AAAA,MACL,SAAS,UAAU,QAAQ,GAAG,IAAI;AAAA,MAClC,MAAM,UAAU,OAAO,GAAG,CAAC;AAAA,MAC3B,MAAM,UAAU,OAAO,GAAG,QAAQ,IAAI,CAAC;AAAA,IACzC,CAAC;AAAA,IACD,CAAC;AAAA,EACH;AACF,CAAC;AAuCM,SAAS,WAAW,wBAAiD;AAC1E,SAAO,OAAO,wBAAwB,6BAA6B;AACrE","sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from '@metamask/superstruct';\n\nconst SnapsEnvironmentOptionsStruct = type({\n server: defaulted(\n object({\n enabled: defaulted(boolean(), true),\n port: defaulted(number(), 0),\n root: defaulted(string(), process.cwd()),\n }),\n {},\n ),\n});\n\n/**\n * The options for the environment. These can be specified in the Jest\n * configuration under `testEnvironmentOptions`.\n *\n * @example\n * {\n * \"testEnvironment\": \"@metamask/snaps-jest\",\n * \"testEnvironmentOptions\": {\n * \"executionEnvironmentUrl\": \"http://localhost:8080\",\n * \"server\": {\n * \"port\": 8080,\n * /* ... *\\/\n * }\n * }\n * }\n * @property server - The options for the built-in HTTP server.\n * @property server.enabled - Whether to run the built-in HTTP server. Defaults\n * to `true`.\n * @property server.port - The port to use for the built-in HTTP server. If this\n * is not provided, a random available port will be used.\n * @property server.root - The root directory to serve from the built-in HTTP\n * server. Defaults to the current working directory. This is assumed to be the\n * directory containing the snap manifest and `dist` files. If this is a\n * relative path, it will be resolved relative to the current working directory.\n */\nexport type SnapsEnvironmentOptions = Infer<\n typeof SnapsEnvironmentOptionsStruct\n>;\n\n/**\n * Get the environment options. This validates the options, and returns the\n * default options if none are provided.\n *\n * @param testEnvironmentOptions - The test environment options as defined in\n * the Jest configuration.\n * @returns The environment options.\n */\nexport function getOptions(testEnvironmentOptions: Record<string, unknown>) {\n return create(testEnvironmentOptions, SnapsEnvironmentOptionsStruct);\n}\n"]}
@@ -6,7 +6,7 @@ import {
6
6
  } from "./chunk-FP4H3ADT.mjs";
7
7
  import {
8
8
  DEFAULT_JSON_RPC_ENDPOINT
9
- } from "./chunk-6KXCBUNZ.mjs";
9
+ } from "./chunk-LVNNGMJ2.mjs";
10
10
 
11
11
  // src/internals/simulation/middleware/engine.ts
12
12
  import { createFetchMiddleware } from "@metamask/eth-json-rpc-middleware";
@@ -36,4 +36,4 @@ function createJsonRpcEngine({
36
36
  export {
37
37
  createJsonRpcEngine
38
38
  };
39
- //# sourceMappingURL=chunk-KNJNL723.mjs.map
39
+ //# sourceMappingURL=chunk-3J2IBWXV.mjs.map
@@ -1,22 +1,28 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
- var _chunkXWGECIXIjs = require('./chunk-XWGECIXI.js');
3
+ var _chunkRJNNNCZJjs = require('./chunk-RJNNNCZJ.js');
4
4
 
5
5
 
6
- var _chunkTVD4SWH7js = require('./chunk-TVD4SWH7.js');
6
+ var _chunkDUVKGPX5js = require('./chunk-DUVKGPX5.js');
7
7
 
8
8
 
9
- var _chunkVXPCUDBIjs = require('./chunk-VXPCUDBI.js');
9
+ var _chunkSW65QYFVjs = require('./chunk-SW65QYFV.js');
10
10
 
11
11
 
12
+ var _chunk6V6MFT67js = require('./chunk-6V6MFT67.js');
12
13
 
13
- var _chunk44ARQBXSjs = require('./chunk-44ARQBXS.js');
14
14
 
15
15
 
16
- var _chunkMBQHVBLAjs = require('./chunk-MBQHVBLA.js');
16
+ var _chunkWZ57PU2Kjs = require('./chunk-WZ57PU2K.js');
17
17
 
18
18
 
19
- var _chunkWMLSD6B5js = require('./chunk-WMLSD6B5.js');
19
+ var _chunkQYHQ2WWXjs = require('./chunk-QYHQ2WWX.js');
20
+
21
+
22
+ var _chunkK7MK6LQUjs = require('./chunk-K7MK6LQU.js');
23
+
24
+
25
+ var _chunkD653LBAYjs = require('./chunk-D653LBAY.js');
20
26
 
21
27
  // src/internals/simulation/simulation.ts
22
28
  var _basecontroller = require('@metamask/base-controller');
@@ -28,29 +34,31 @@ var _keytree = require('@metamask/key-tree');
28
34
 
29
35
 
30
36
  var _node = require('@metamask/snaps-controllers/node');
37
+ var _snapsrpcmethods = require('@metamask/snaps-rpc-methods');
31
38
  var _snapsutils = require('@metamask/snaps-utils');
32
39
  var _readablestream = require('readable-stream');
40
+ var _effects = require('redux-saga/effects');
33
41
  async function handleInstallSnap(snapId, {
34
42
  executionService,
35
43
  executionServiceOptions,
36
44
  options: rawOptions = {}
37
45
  } = {}) {
38
- const options = _chunkVXPCUDBIjs.getOptions.call(void 0, rawOptions);
46
+ const options = _chunk6V6MFT67js.getOptions.call(void 0, rawOptions);
39
47
  const location = _node.detectSnapLocation.call(void 0, snapId, {
40
48
  allowLocal: true
41
49
  });
42
50
  const snapFiles = await _node.fetchSnap.call(void 0, snapId, location);
43
- const { store, runSaga } = _chunkWMLSD6B5js.createStore.call(void 0, options);
51
+ const { store, runSaga } = _chunkK7MK6LQUjs.createStore.call(void 0, options);
44
52
  const controllerMessenger = new (0, _basecontroller.ControllerMessenger)();
45
- registerActions(controllerMessenger);
53
+ registerActions(controllerMessenger, runSaga);
46
54
  const hooks = getHooks(options, snapFiles, snapId, controllerMessenger);
47
- const { subjectMetadataController, permissionController } = _chunk44ARQBXSjs.getControllers.call(void 0, {
55
+ const { subjectMetadataController, permissionController } = _chunkWZ57PU2Kjs.getControllers.call(void 0, {
48
56
  controllerMessenger,
49
57
  hooks,
50
58
  runSaga,
51
59
  options
52
60
  });
53
- const engine = _chunkXWGECIXIjs.createJsonRpcEngine.call(void 0, {
61
+ const engine = _chunkRJNNNCZJjs.createJsonRpcEngine.call(void 0, {
54
62
  store,
55
63
  hooks,
56
64
  permissionMiddleware: permissionController.createPermissionMiddleware({
@@ -76,14 +84,14 @@ async function handleInstallSnap(snapId, {
76
84
  });
77
85
  }
78
86
  });
79
- await _chunk44ARQBXSjs.registerSnap.call(void 0, snapId, snapFiles.manifest.result, {
87
+ await _chunkWZ57PU2Kjs.registerSnap.call(void 0, snapId, snapFiles.manifest.result, {
80
88
  permissionController,
81
89
  subjectMetadataController
82
90
  });
83
91
  await service.executeSnap({
84
92
  snapId,
85
93
  sourceCode: snapFiles.sourceCode.toString("utf8"),
86
- endowments: await _chunkMBQHVBLAjs.getEndowments.call(void 0, permissionController, snapId)
94
+ endowments: await _chunkQYHQ2WWXjs.getEndowments.call(void 0, permissionController, snapId)
87
95
  });
88
96
  return {
89
97
  snapId,
@@ -96,7 +104,7 @@ async function handleInstallSnap(snapId, {
96
104
  function getHooks(options, snapFiles, snapId, controllerMessenger) {
97
105
  return {
98
106
  getMnemonic: async () => Promise.resolve(_keytree.mnemonicPhraseToBytes.call(void 0, options.secretRecoveryPhrase)),
99
- getSnapFile: async (path, encoding) => await _chunkTVD4SWH7js.getSnapFile.call(void 0, snapFiles.auxiliaryFiles, path, encoding),
107
+ getSnapFile: async (path, encoding) => await _chunkSW65QYFVjs.getSnapFile.call(void 0, snapFiles.auxiliaryFiles, path, encoding),
100
108
  getIsLocked: () => false,
101
109
  createInterface: async (...args) => controllerMessenger.call(
102
110
  "SnapInterfaceController:createInterface",
@@ -112,10 +120,15 @@ function getHooks(options, snapFiles, snapId, controllerMessenger) {
112
120
  "SnapInterfaceController:getInterface",
113
121
  snapId,
114
122
  ...args
115
- ).state
123
+ ).state,
124
+ resolveInterface: async (...args) => controllerMessenger.call(
125
+ "SnapInterfaceController:resolveInterface",
126
+ snapId,
127
+ ...args
128
+ )
116
129
  };
117
130
  }
118
- function registerActions(controllerMessenger) {
131
+ function registerActions(controllerMessenger, runSaga) {
119
132
  controllerMessenger.registerActionHandler(
120
133
  "PhishingController:maybeUpdateState",
121
134
  async () => Promise.resolve()
@@ -124,6 +137,26 @@ function registerActions(controllerMessenger) {
124
137
  "PhishingController:testOrigin",
125
138
  () => ({ result: false, type: "all" })
126
139
  );
140
+ controllerMessenger.registerActionHandler(
141
+ "ApprovalController:hasRequest",
142
+ (opts) => {
143
+ function* getCurrentInterfaceSaga() {
144
+ const currentInterface2 = yield _effects.select.call(void 0, _chunkD653LBAYjs.getCurrentInterface);
145
+ return currentInterface2;
146
+ }
147
+ const currentInterface = runSaga(
148
+ getCurrentInterfaceSaga
149
+ ).result();
150
+ return currentInterface?.type === _snapsrpcmethods.DIALOG_APPROVAL_TYPES.default && currentInterface?.id === opts?.id;
151
+ }
152
+ );
153
+ controllerMessenger.registerActionHandler(
154
+ "ApprovalController:acceptRequest",
155
+ async (_id, value) => {
156
+ await runSaga(_chunkDUVKGPX5js.resolveWithSaga, value).toPromise();
157
+ return { value };
158
+ }
159
+ );
127
160
  }
128
161
 
129
162
 
@@ -131,4 +164,4 @@ function registerActions(controllerMessenger) {
131
164
 
132
165
 
133
166
  exports.handleInstallSnap = handleInstallSnap; exports.getHooks = getHooks; exports.registerActions = registerActions;
134
- //# sourceMappingURL=chunk-EDFQDZNY.js.map
167
+ //# sourceMappingURL=chunk-3NP6BDGK.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internals/simulation/simulation.ts"],"names":["currentInterface"],"mappings":"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","sourcesContent":["import type {\n ActionConstraint,\n EventConstraint,\n} from '@metamask/base-controller';\nimport { ControllerMessenger } from '@metamask/base-controller';\nimport { createEngineStream } from '@metamask/json-rpc-middleware-stream';\nimport { mnemonicPhraseToBytes } from '@metamask/key-tree';\nimport type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n fetchSnap,\n detectSnapLocation,\n NodeThreadExecutionService,\n setupMultiplex,\n} from '@metamask/snaps-controllers/node';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport type {\n SnapId,\n AuxiliaryFileEncoding,\n Component,\n InterfaceState,\n} from '@metamask/snaps-sdk';\nimport type { FetchedSnapFiles } from '@metamask/snaps-utils';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport type { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\nimport type { SagaIterator } from 'redux-saga';\nimport { select } from 'redux-saga/effects';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport { resolveWithSaga } from './interface';\nimport { getEndowments } from './methods';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { Interface, RunSagaFunction, Store } from './store';\nimport { createStore, getCurrentInterface } from './store';\n\n/**\n * Options for the execution service, without the options that are shared\n * between all execution services.\n *\n * @template Service - The type of the execution service, i.e., the class that\n * creates the execution service.\n */\nexport type ExecutionServiceOptions<\n Service extends new (...args: any[]) => any,\n> = Omit<\n ConstructorParameters<Service>[0],\n keyof ConstructorParameters<typeof AbstractExecutionService<unknown>>[0]\n>;\n\n/**\n * The options for running a Snap in a simulated environment.\n *\n * @property executionService - The execution service to use.\n * @property executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @property options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport type InstallSnapOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService<unknown>\n >,\n> = ExecutionServiceOptions<Service> extends Record<string, never>\n ? {\n executionService: Service;\n executionServiceOptions?: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n }\n : {\n executionService: Service;\n executionServiceOptions: ExecutionServiceOptions<Service>;\n options?: SimulationUserOptions;\n };\n\nexport type InstalledSnap = {\n snapId: SnapId;\n store: Store;\n executionService: InstanceType<typeof AbstractExecutionService>;\n controllerMessenger: ControllerMessenger<ActionConstraint, EventConstraint>;\n runSaga: RunSagaFunction;\n};\n\nexport type MiddlewareHooks = {\n /**\n * A hook that returns the user's secret recovery phrase.\n *\n * @returns The user's secret recovery phrase.\n */\n getMnemonic: () => Promise<Uint8Array>;\n\n /**\n * A hook that returns the Snap's auxiliary file for the given path.\n *\n * @param path - The path of the auxiliary file to get.\n * @param encoding - The encoding to use when returning the file.\n * @returns The Snap's auxiliary file for the given path.\n */\n getSnapFile: (\n path: string,\n encoding: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n\n /**\n * A hook that returns whether the client is locked or not.\n *\n * @returns A boolean flag signaling whether the client is locked.\n */\n getIsLocked: () => boolean;\n createInterface: (content: Component) => Promise<string>;\n updateInterface: (id: string, content: Component) => Promise<void>;\n getInterfaceState: (id: string) => InterfaceState;\n resolveInterface: (id: string, value: Json) => Promise<void>;\n};\n\n/**\n * Install a Snap in a simulated environment. This will fetch the Snap files,\n * create a Redux store, set up the controllers and JSON-RPC stack, register the\n * Snap, and run the Snap code in the execution service.\n *\n * @param snapId - The ID of the Snap to install.\n * @param options - The options to use when installing the Snap.\n * @param options.executionService - The execution service to use.\n * @param options.executionServiceOptions - The options to use when creating the\n * execution service, if any. This should only include options specific to the\n * provided execution service.\n * @param options.options - The simulation options.\n * @template Service - The type of the execution service.\n */\nexport async function handleInstallSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n {\n executionService,\n executionServiceOptions,\n options: rawOptions = {},\n }: Partial<InstallSnapOptions<Service>> = {},\n): Promise<InstalledSnap> {\n const options = getOptions(rawOptions);\n\n // Fetch Snap files.\n const location = detectSnapLocation(snapId, {\n allowLocal: true,\n });\n\n const snapFiles = await fetchSnap(snapId, location);\n\n // Create Redux store.\n const { store, runSaga } = createStore(options);\n\n const controllerMessenger = new ControllerMessenger<any, any>();\n\n registerActions(controllerMessenger, runSaga);\n\n // Set up controllers and JSON-RPC stack.\n const hooks = getHooks(options, snapFiles, snapId, controllerMessenger);\n\n const { subjectMetadataController, permissionController } = getControllers({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n });\n\n const engine = createJsonRpcEngine({\n store,\n hooks,\n permissionMiddleware: permissionController.createPermissionMiddleware({\n origin: snapId,\n }),\n });\n\n // Create execution service.\n const ExecutionService = executionService ?? NodeThreadExecutionService;\n const service = new ExecutionService({\n ...executionServiceOptions,\n messenger: controllerMessenger.getRestricted({\n name: 'ExecutionService',\n allowedActions: [],\n allowedEvents: [],\n }),\n setupSnapProvider: (_snapId: string, rpcStream: Duplex) => {\n const mux = setupMultiplex(rpcStream, 'snapStream');\n const stream = mux.createStream('metamask-provider');\n const providerStream = createEngineStream({ engine });\n\n // Error function is difficult to test, so we ignore it.\n /* istanbul ignore next 2 */\n pipeline(stream, providerStream, stream, (error: unknown) => {\n if (error) {\n logError(`Provider stream failure.`, error);\n }\n });\n },\n });\n\n // Register the Snap. This sets up the Snap's permissions and subject\n // metadata.\n await registerSnap(snapId, snapFiles.manifest.result, {\n permissionController,\n subjectMetadataController,\n });\n\n // Run the Snap code in the execution service.\n await service.executeSnap({\n snapId,\n sourceCode: snapFiles.sourceCode.toString('utf8'),\n endowments: await getEndowments(permissionController, snapId),\n });\n\n return {\n snapId,\n store,\n executionService: service,\n controllerMessenger,\n runSaga,\n };\n}\n\n/**\n * Get the hooks for the simulation.\n *\n * @param options - The simulation options.\n * @param snapFiles - The Snap files.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The hooks for the simulation.\n */\nexport function getHooks(\n options: SimulationOptions,\n snapFiles: FetchedSnapFiles,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): MiddlewareHooks {\n return {\n getMnemonic: async () =>\n Promise.resolve(mnemonicPhraseToBytes(options.secretRecoveryPhrase)),\n getSnapFile: async (path: string, encoding: AuxiliaryFileEncoding) =>\n await getSnapFile(snapFiles.auxiliaryFiles, path, encoding),\n getIsLocked: () => false,\n createInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n ...args,\n ),\n updateInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterface',\n snapId,\n ...args,\n ),\n getInterfaceState: (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n ...args,\n ).state,\n resolveInterface: async (...args) =>\n controllerMessenger.call(\n 'SnapInterfaceController:resolveInterface',\n snapId,\n ...args,\n ),\n };\n}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n * @param runSaga - The run saga function.\n */\nexport function registerActions(\n controllerMessenger: RootControllerMessenger,\n runSaga: RunSagaFunction,\n) {\n controllerMessenger.registerActionHandler(\n 'PhishingController:maybeUpdateState',\n async () => Promise.resolve(),\n );\n\n controllerMessenger.registerActionHandler(\n 'PhishingController:testOrigin',\n () => ({ result: false, type: 'all' }),\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:hasRequest',\n (opts) => {\n /**\n * Get the current interface from the store.\n *\n * @yields Selects the current interface from the store.\n * @returns The current interface.\n */\n function* getCurrentInterfaceSaga(): SagaIterator {\n const currentInterface: Interface = yield select(getCurrentInterface);\n return currentInterface;\n }\n\n const currentInterface: Interface | undefined = runSaga(\n getCurrentInterfaceSaga,\n ).result();\n return (\n currentInterface?.type === DIALOG_APPROVAL_TYPES.default &&\n currentInterface?.id === opts?.id\n );\n },\n );\n\n controllerMessenger.registerActionHandler(\n 'ApprovalController:acceptRequest',\n async (_id: string, value: unknown) => {\n await runSaga(resolveWithSaga, value).toPromise();\n\n return { value };\n },\n );\n}\n"]}