@metamask/snaps-jest 8.2.0 → 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 (191) hide show
  1. package/CHANGELOG.md +11 -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-DVDAOXO7.js → chunk-3NP6BDGK.js} +48 -15
  9. package/dist/chunk-3NP6BDGK.js.map +1 -0
  10. package/dist/{chunk-43HRTFLS.mjs → chunk-6JPBXAHM.mjs} +103 -15
  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-MAT5SBM7.mjs → chunk-7PCHIR6O.mjs} +7 -37
  15. package/dist/chunk-7PCHIR6O.mjs.map +1 -0
  16. package/dist/{chunk-4MAA7WGJ.js → chunk-AMAL4SJH.js} +7 -7
  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-NSMTFK33.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-GVTDUKXK.js → chunk-DUVKGPX5.js} +106 -18
  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-WMLSD6B5.js → chunk-K7MK6LQU.js} +3 -3
  30. package/dist/{chunk-B73P64TE.mjs → chunk-KOPPL55J.mjs} +2 -2
  31. package/dist/chunk-KOPPL55J.mjs.map +1 -0
  32. package/dist/{chunk-XKJHFUHE.js → chunk-KPRLFCKD.js} +4 -2
  33. package/dist/chunk-KPRLFCKD.js.map +1 -0
  34. package/dist/{chunk-IVFVB4VR.js → chunk-LPMHPAZK.js} +54 -14
  35. package/dist/chunk-LPMHPAZK.js.map +1 -0
  36. package/dist/{chunk-GG2BCPQH.mjs → chunk-LSKT2AUS.mjs} +5 -3
  37. package/dist/chunk-LSKT2AUS.mjs.map +1 -0
  38. package/dist/{chunk-6KXCBUNZ.mjs → chunk-LVNNGMJ2.mjs} +3 -1
  39. package/dist/{chunk-6KXCBUNZ.mjs.map → chunk-LVNNGMJ2.mjs.map} +1 -1
  40. package/dist/{chunk-TMAWGVZP.mjs → chunk-OHRFO2BL.mjs} +7 -7
  41. package/dist/chunk-OHRFO2BL.mjs.map +1 -0
  42. package/dist/{chunk-WRKY2DLV.js → chunk-OO6IVUCV.js} +5 -5
  43. package/dist/{chunk-3M4GRUMH.mjs → chunk-ORR7AE5X.mjs} +2 -2
  44. package/dist/{chunk-5SGLRSWR.mjs → chunk-PDOVVC74.mjs} +4 -4
  45. package/dist/chunk-PDOVVC74.mjs.map +1 -0
  46. package/dist/{chunk-O24GTINW.mjs → chunk-Q3I6P2ZF.mjs} +42 -9
  47. package/dist/chunk-Q3I6P2ZF.mjs.map +1 -0
  48. package/dist/chunk-QRVFWATH.mjs +14 -0
  49. package/dist/chunk-QRVFWATH.mjs.map +1 -0
  50. package/dist/{chunk-MBQHVBLA.js → chunk-QYHQ2WWX.js} +5 -5
  51. package/dist/chunk-QYHQ2WWX.js.map +1 -0
  52. package/dist/{chunk-XWGECIXI.js → chunk-RJNNNCZJ.js} +3 -3
  53. package/dist/{chunk-CYPP66I7.mjs → chunk-ROCGQYSK.mjs} +46 -6
  54. package/dist/chunk-ROCGQYSK.mjs.map +1 -0
  55. package/dist/chunk-SNXRXX2O.js +30 -0
  56. package/dist/chunk-SNXRXX2O.js.map +1 -0
  57. package/dist/{chunk-44ARQBXS.js → chunk-WZ57PU2K.js} +6 -4
  58. package/dist/chunk-WZ57PU2K.js.map +1 -0
  59. package/dist/chunk-XP4YGQJA.js +14 -0
  60. package/dist/chunk-XP4YGQJA.js.map +1 -0
  61. package/dist/{chunk-7Y27L2EV.js → chunk-Y2U3ZPCK.js} +15 -45
  62. package/dist/chunk-Y2U3ZPCK.js.map +1 -0
  63. package/dist/{chunk-74TIKA2T.mjs → chunk-ZJQSGRNK.mjs} +1 -1
  64. package/dist/chunk-ZJQSGRNK.mjs.map +1 -0
  65. package/dist/environment.js +16 -16
  66. package/dist/environment.mjs +15 -15
  67. package/dist/helpers.js +29 -15
  68. package/dist/helpers.mjs +28 -14
  69. package/dist/index.js +31 -17
  70. package/dist/index.mjs +30 -16
  71. package/dist/internals/index.js +28 -20
  72. package/dist/internals/index.mjs +31 -23
  73. package/dist/internals/request.js +14 -14
  74. package/dist/internals/request.mjs +13 -13
  75. package/dist/internals/simulation/constants.js +4 -2
  76. package/dist/internals/simulation/constants.mjs +3 -1
  77. package/dist/internals/simulation/controllers.js +7 -7
  78. package/dist/internals/simulation/controllers.mjs +6 -6
  79. package/dist/internals/simulation/index.js +26 -18
  80. package/dist/internals/simulation/index.mjs +29 -21
  81. package/dist/internals/simulation/interface.js +10 -4
  82. package/dist/internals/simulation/interface.mjs +9 -3
  83. package/dist/internals/simulation/methods/hooks/get-preferences.js +8 -0
  84. package/dist/internals/simulation/methods/hooks/get-preferences.mjs +8 -0
  85. package/dist/internals/simulation/methods/hooks/index.js +5 -5
  86. package/dist/internals/simulation/methods/hooks/index.mjs +8 -8
  87. package/dist/internals/simulation/methods/hooks/notifications.js +2 -2
  88. package/dist/internals/simulation/methods/hooks/notifications.mjs +2 -2
  89. package/dist/internals/simulation/methods/hooks/request-user-approval.js +14 -0
  90. package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +14 -0
  91. package/dist/internals/simulation/methods/hooks/state.js +2 -2
  92. package/dist/internals/simulation/methods/hooks/state.mjs +2 -2
  93. package/dist/internals/simulation/methods/index.js +6 -6
  94. package/dist/internals/simulation/methods/index.mjs +5 -5
  95. package/dist/internals/simulation/methods/specifications.js +6 -6
  96. package/dist/internals/simulation/methods/specifications.mjs +5 -5
  97. package/dist/internals/simulation/middleware/engine.js +3 -3
  98. package/dist/internals/simulation/middleware/engine.mjs +2 -2
  99. package/dist/internals/simulation/middleware/index.js +3 -3
  100. package/dist/internals/simulation/middleware/index.mjs +2 -2
  101. package/dist/internals/simulation/options.js +3 -3
  102. package/dist/internals/simulation/options.mjs +2 -2
  103. package/dist/internals/simulation/simulation.js +12 -11
  104. package/dist/internals/simulation/simulation.mjs +11 -10
  105. package/dist/internals/simulation/store/index.js +3 -3
  106. package/dist/internals/simulation/store/index.mjs +2 -2
  107. package/dist/internals/simulation/store/store.js +3 -3
  108. package/dist/internals/simulation/store/store.mjs +2 -2
  109. package/dist/internals/simulation/store/ui.js +2 -2
  110. package/dist/internals/simulation/store/ui.mjs +1 -1
  111. package/dist/internals/structs.js +2 -2
  112. package/dist/internals/structs.mjs +1 -1
  113. package/dist/matchers.js +15 -17
  114. package/dist/matchers.mjs +14 -16
  115. package/dist/options.js +2 -2
  116. package/dist/options.mjs +1 -1
  117. package/dist/setup.js +14 -14
  118. package/dist/setup.mjs +14 -14
  119. package/dist/tsconfig.build.tsbuildinfo +1 -1
  120. package/dist/types/helpers.d.ts +43 -1
  121. package/dist/types/internals/request.d.ts +1 -1
  122. package/dist/types/internals/server.d.ts +1 -1
  123. package/dist/types/internals/simulation/constants.d.ts +4 -0
  124. package/dist/types/internals/simulation/controllers.d.ts +4 -4
  125. package/dist/types/internals/simulation/interface.d.ts +31 -4
  126. package/dist/types/internals/simulation/methods/hooks/get-preferences.d.ts +13 -0
  127. package/dist/types/internals/simulation/methods/hooks/index.d.ts +2 -2
  128. package/dist/types/internals/simulation/methods/hooks/request-user-approval.d.ts +15 -0
  129. package/dist/types/internals/simulation/methods/specifications.d.ts +2 -2
  130. package/dist/types/internals/simulation/middleware/engine.d.ts +1 -1
  131. package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +1 -1
  132. package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +1 -1
  133. package/dist/types/internals/simulation/options.d.ts +10 -8
  134. package/dist/types/internals/simulation/simulation.d.ts +8 -5
  135. package/dist/types/internals/simulation/store/mocks.d.ts +2 -2
  136. package/dist/types/internals/simulation/store/notifications.d.ts +2 -2
  137. package/dist/types/internals/simulation/store/state.d.ts +1 -1
  138. package/dist/types/internals/simulation/store/store.d.ts +4 -4
  139. package/dist/types/internals/simulation/store/ui.d.ts +4 -3
  140. package/dist/types/internals/structs.d.ts +41 -41
  141. package/dist/types/matchers.d.ts +0 -10
  142. package/dist/types/options.d.ts +7 -7
  143. package/dist/types/types.d.ts +60 -21
  144. package/package.json +16 -16
  145. package/dist/chunk-265BMFM5.js +0 -13
  146. package/dist/chunk-265BMFM5.js.map +0 -1
  147. package/dist/chunk-43HRTFLS.mjs.map +0 -1
  148. package/dist/chunk-44ARQBXS.js.map +0 -1
  149. package/dist/chunk-4MAA7WGJ.js.map +0 -1
  150. package/dist/chunk-5SGLRSWR.mjs.map +0 -1
  151. package/dist/chunk-74TIKA2T.mjs.map +0 -1
  152. package/dist/chunk-7Y27L2EV.js.map +0 -1
  153. package/dist/chunk-B73P64TE.mjs.map +0 -1
  154. package/dist/chunk-CYPP66I7.mjs.map +0 -1
  155. package/dist/chunk-DVDAOXO7.js.map +0 -1
  156. package/dist/chunk-GG2BCPQH.mjs.map +0 -1
  157. package/dist/chunk-GVTDUKXK.js.map +0 -1
  158. package/dist/chunk-HOI6FPLR.mjs.map +0 -1
  159. package/dist/chunk-IH7UNS5A.mjs.map +0 -1
  160. package/dist/chunk-IVFVB4VR.js.map +0 -1
  161. package/dist/chunk-KSIBNOB2.mjs +0 -13
  162. package/dist/chunk-KSIBNOB2.mjs.map +0 -1
  163. package/dist/chunk-MAT5SBM7.mjs.map +0 -1
  164. package/dist/chunk-MBQHVBLA.js.map +0 -1
  165. package/dist/chunk-O24GTINW.mjs.map +0 -1
  166. package/dist/chunk-ORO3T6BU.mjs +0 -24
  167. package/dist/chunk-ORO3T6BU.mjs.map +0 -1
  168. package/dist/chunk-PZDTZGSI.js.map +0 -1
  169. package/dist/chunk-RAMAN5RM.js +0 -24
  170. package/dist/chunk-RAMAN5RM.js.map +0 -1
  171. package/dist/chunk-T2PHS5FY.js.map +0 -1
  172. package/dist/chunk-TMAWGVZP.mjs.map +0 -1
  173. package/dist/chunk-VXPCUDBI.js.map +0 -1
  174. package/dist/chunk-XKJHFUHE.js.map +0 -1
  175. package/dist/chunk-YNUVT3HC.js.map +0 -1
  176. package/dist/internals/simulation/methods/hooks/get-locale.js +0 -8
  177. package/dist/internals/simulation/methods/hooks/get-locale.mjs +0 -8
  178. package/dist/internals/simulation/methods/hooks/show-dialog.js +0 -14
  179. package/dist/internals/simulation/methods/hooks/show-dialog.mjs +0 -14
  180. package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +0 -9
  181. package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +0 -9
  182. /package/dist/{chunk-KNJNL723.mjs.map → chunk-3J2IBWXV.mjs.map} +0 -0
  183. /package/dist/{chunk-NSMTFK33.mjs.map → chunk-CACRY3TX.mjs.map} +0 -0
  184. /package/dist/{chunk-WMLSD6B5.js.map → chunk-K7MK6LQU.js.map} +0 -0
  185. /package/dist/{chunk-WRKY2DLV.js.map → chunk-OO6IVUCV.js.map} +0 -0
  186. /package/dist/{chunk-3M4GRUMH.mjs.map → chunk-ORR7AE5X.mjs.map} +0 -0
  187. /package/dist/{chunk-XWGECIXI.js.map → chunk-RJNNNCZJ.js.map} +0 -0
  188. /package/dist/internals/simulation/methods/hooks/{get-locale.js.map → get-preferences.js.map} +0 -0
  189. /package/dist/internals/simulation/methods/hooks/{get-locale.mjs.map → get-preferences.mjs.map} +0 -0
  190. /package/dist/internals/simulation/methods/hooks/{show-dialog.js.map → request-user-approval.js.map} +0 -0
  191. /package/dist/internals/simulation/methods/hooks/{show-dialog.mjs.map → request-user-approval.mjs.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/interface.ts"],"names":["content"],"mappings":";;;;;;;;;;;AAQA,SAAS,YAAY,oBAAoB,cAAc;AAEvD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB,mBAAmB;AAG9C,SAAS,MAAM,KAAK,QAAQ,YAAY;AAexC,IAAM,gBAAgB;AAWf,SAAS,qBACd,SACA,MACA,SACA,kBACe;AACf,UAAQ,MAAM;AAAA,IACZ,KAAK,WAAW;AACd,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,QACA;AAAA,QACA,IAAI,YAAY,SAAS,IAAI;AAAA,MAC/B;AAAA,IAEF,KAAK,WAAW;AACd,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,QACA;AAAA,QAEA,IAAI,YAAY,SAAS,IAAI;AAAA,QAC7B,QAAQ,YAAY,SAAS,KAAK;AAAA,MACpC;AAAA,IAEF,KAAK,WAAW;AACd,aAAO;AAAA,QACL,GAAG;AAAA,QACH;AAAA,QACA;AAAA,QAEA,IAAI,iBAAiB,OAAO;AAAA,QAC5B,QAAQ,YAAY,SAAS,IAAI;AAAA,MACnC;AAAA,IAEF;AACE,YAAM,IAAI,MAAM,wCAAwC,OAAO,IAAI,CAAC,IAAI;AAAA,EAC5E;AACF;AAUA,SAAS,YAAY,SAA0B,OAAgB;AAM7D,YAAU,kBAAgC;AACxC,UA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OAAO,QAAQ,MAAM;AAAA,UAC3B,MAAM;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAaO,SAAS,oBACd,QACA,qBACA,EAAE,SAAS,GAAG,GACQ;AACtB,SAAO;AAAA,IACL,cAAc,OAAO,SAAiB;AACpC,YAAM,aAAa,qBAAqB,IAAI,SAAS,QAAQ,IAAI;AAAA,IACnE;AAAA,IAEA,aAAa,OAAO,MAAc,UAAkB;AAClD,YAAM,YAAY,qBAAqB,IAAI,SAAS,QAAQ,MAAM,KAAK;AAAA,IACzE;AAAA,IAEA,kBAAkB,OAAO,MAAc,UAAkB;AACvD,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,IAEA,YAAY,OACV,MACA,MACA,YACG;AACH,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAWO,UAAU,aACf,SACA,QACA,qBAC6B;AAC7B,QAAM,kBAAkB,MAAM;AAAA,IAC5B;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,mBAAmB;AAAA,IACvB;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO;AAAA,IACL;AAAA,IACA,gBAAgB;AAAA,IAChB,gBAAgB;AAAA,IAChB;AAAA,EACF;AACF","sourcesContent":["import type {\n FormState,\n InterfaceContext,\n InterfaceState,\n SnapId,\n UserInputEvent,\n File,\n} from '@metamask/snaps-sdk';\nimport { DialogType, UserInputEventType, assert } from '@metamask/snaps-sdk';\nimport type { FormElement, JSXElement } from '@metamask/snaps-sdk/jsx';\nimport {\n HandlerType,\n getJsxChildren,\n unwrapError,\n walkJsx,\n} from '@metamask/snaps-utils';\nimport { assertExhaustive, hasProperty } from '@metamask/utils';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { type SagaIterator } from 'redux-saga';\nimport { call, put, select, take } from 'redux-saga/effects';\n\nimport type {\n FileOptions,\n SnapInterface,\n SnapInterfaceActions,\n} from '../../types';\nimport type { RootControllerMessenger } from './controllers';\nimport { getFileSize, getFileToUpload } from './files';\nimport type { Interface, RunSagaFunction } from './store';\nimport { getCurrentInterface, resolveInterface, setInterface } from './store';\n\n/**\n * The maximum file size that can be uploaded.\n */\nconst MAX_FILE_SIZE = 10_000_000; // 10 MB\n\n/**\n * Get a user interface object from a type and content object.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param type - The type of the interface.\n * @param content - The content to show in the interface.\n * @param interfaceActions - The actions to interact with the interface.\n * @returns The user interface object.\n */\nexport function getInterfaceResponse(\n runSaga: RunSagaFunction,\n type: DialogType,\n content: JSXElement,\n interfaceActions: SnapInterfaceActions,\n): SnapInterface {\n switch (type) {\n case DialogType.Alert:\n return {\n ...interfaceActions,\n type,\n content,\n ok: resolveWith(runSaga, null),\n };\n\n case DialogType.Confirmation:\n return {\n ...interfaceActions,\n type,\n content,\n\n ok: resolveWith(runSaga, true),\n cancel: resolveWith(runSaga, false),\n };\n\n case DialogType.Prompt:\n return {\n ...interfaceActions,\n type,\n content,\n\n ok: resolveWithInput(runSaga),\n cancel: resolveWith(runSaga, null),\n };\n\n default:\n throw new Error(`Unknown or unsupported dialog type: \"${String(type)}\".`);\n }\n}\n\n/**\n * Resolve the current user interface with the given value. This returns a\n * function that can be used to resolve the user interface.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param value - The value to resolve the user interface with.\n * @returns A function that can be used to resolve the user interface.\n */\nfunction resolveWith(runSaga: RunSagaFunction, value: unknown) {\n /**\n * Resolve the current user interface with the given value.\n *\n * @yields Puts the resolve user interface action.\n */\n function* resolveWithSaga(): SagaIterator {\n yield put(resolveInterface(value));\n }\n\n return async () => {\n await runSaga(resolveWithSaga).toPromise();\n };\n}\n\n/**\n * Resolve the current user interface with the provided input. This returns a\n * function that can be used to resolve the user interface.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @returns A function that can be used to resolve the user interface.\n */\nfunction resolveWithInput(runSaga: RunSagaFunction) {\n /**\n * Resolve the current user interface with the given value.\n *\n * @param value - The value to resolve the user interface with.\n * @yields Puts the resolve user interface action.\n */\n function* resolveWithSaga(value: string): SagaIterator {\n yield put(resolveInterface(value));\n }\n\n return async (value = '') => {\n await runSaga(resolveWithSaga, value).toPromise();\n };\n}\n\n/**\n * Get the stored user interface from the store.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param snapId - The Snap ID.\n * @yields Takes the set interface action.\n * @returns The user interface object.\n */\nfunction* getStoredInterface(\n controllerMessenger: RootControllerMessenger,\n snapId: SnapId,\n): SagaIterator<Interface & { content: JSXElement }> {\n const currentInterface: Interface | null = yield select(getCurrentInterface);\n\n if (currentInterface) {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n currentInterface.id,\n );\n\n return { ...currentInterface, content };\n }\n\n const { payload }: PayloadAction<Interface> = yield take(setInterface.type);\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n payload.id,\n );\n\n return { ...payload, content };\n}\n\n/**\n * A JSX element with a name.\n */\nexport type NamedJSXElement = JSXElement & { props: { name: string } };\n\n/**\n * Check if a JSX element is a JSX element with a given name.\n *\n * @param element - The JSX element.\n * @param name - The element name.\n * @returns True if the element is a JSX element with the given name, otherwise\n * false.\n */\nfunction isJSXElementWithName<Element extends JSXElement, Name extends string>(\n element: Element,\n name: Name,\n): element is Element & { props: { name: Name } } {\n return hasProperty(element.props, 'name') && element.props.name === name;\n}\n\n/**\n * Find an element inside a form element in a JSX tree.\n *\n * @param form - The form element.\n * @param name - The element name.\n * @returns An object containing the element and the form name if it's contained\n * in a form, otherwise undefined.\n */\nfunction getFormElement(form: FormElement, name: string) {\n const element = walkJsx<NamedJSXElement>(form, (childElement) => {\n if (isJSXElementWithName(childElement, name)) {\n return childElement;\n }\n\n return undefined;\n });\n\n if (element === undefined) {\n return undefined;\n }\n\n return { element, form: form.props.name };\n}\n\n/**\n * Get an element from a JSX tree with the given name.\n *\n * @param content - The interface content.\n * @param name - The element name.\n * @returns An object containing the element and the form name if it's contained\n * in a form, otherwise undefined.\n */\nexport function getElement(\n content: JSXElement,\n name: string,\n):\n | {\n element: NamedJSXElement;\n form?: string;\n }\n | undefined {\n if (isJSXElementWithName(content, name)) {\n return { element: content };\n }\n\n return walkJsx(content, (element) => {\n if (element.type === 'Form') {\n return getFormElement(element, name);\n }\n\n if (isJSXElementWithName(element, name)) {\n return { element };\n }\n\n return undefined;\n });\n}\n/**\n * Handle submitting event requests to OnUserInput including unwrapping potential errors.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param snapId - The Snap ID.\n * @param id - The interface ID.\n * @param event - The event to submit.\n * @param context - The interface context.\n */\nasync function handleEvent(\n controllerMessenger: RootControllerMessenger,\n snapId: SnapId,\n id: string,\n event: UserInputEvent,\n context: InterfaceContext | null,\n) {\n try {\n await controllerMessenger.call(\n 'ExecutionService:handleRpcRequest',\n snapId,\n {\n origin: '',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event,\n id,\n context,\n },\n },\n },\n );\n } catch (error) {\n const [unwrapped] = unwrapError(error);\n throw unwrapped;\n }\n}\n\n/**\n * Click on an element of the Snap interface.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface content.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n */\nexport async function clickElement(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n): Promise<void> {\n const result = getElement(content, name);\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'Button' || result.element.type === 'Checkbox',\n `Expected an element of type \"Button\" or \"Checkbox\", but found \"${result.element.type}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const { type } = result.element;\n const elementName = result.element.props.name;\n\n const formState = (result.form ? state[result.form] : state) as FormState;\n const currentValue = formState[elementName];\n\n switch (type) {\n case 'Button': {\n // Button click events are always triggered.\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.ButtonClickEvent,\n name: elementName,\n },\n context,\n );\n\n if (result.form && result.element.props.type === 'submit') {\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.FormSubmitEvent,\n name: result.form,\n value: state[result.form] as FormState,\n },\n context,\n );\n }\n break;\n }\n\n case 'Checkbox': {\n const newValue = !currentValue;\n const newState = mergeValue(state, name, newValue, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.InputChangeEvent,\n name: elementName,\n value: newValue,\n },\n context,\n );\n break;\n }\n\n /* istanbul ignore next */\n default:\n assertExhaustive(type);\n }\n}\n\n/**\n * Merge a value in the interface state.\n *\n * @param state - The actual interface state.\n * @param name - The component name that changed value.\n * @param value - The new value.\n * @param form - The form name if the element is in one.\n * @returns The state with the merged value.\n */\nexport function mergeValue(\n state: InterfaceState,\n name: string,\n value: string | File | boolean | null,\n form?: string,\n): InterfaceState {\n if (form) {\n return {\n ...state,\n [form]: {\n ...(state[form] as FormState),\n [name]: value,\n },\n };\n }\n\n return { ...state, [name]: value };\n}\n\n/**\n * Type a value in an interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function typeInField(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'Input',\n `Expected an element of type \"Input\", but found \"${result.element.type}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, value, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: '',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Type a value in an interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param value - The value to type in the element.\n */\nexport async function selectInDropdown(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'Dropdown',\n `Expected an element of type \"Dropdown\", but found \"${result.element.type}\".`,\n );\n\n const options = getJsxChildren(result.element) as JSXElement[];\n const selectedOption = options.find(\n (option) =>\n hasProperty(option.props, 'value') && option.props.value === value,\n );\n\n assert(\n selectedOption !== undefined,\n `The dropdown with the name \"${name}\" does not contain \"${value}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const newState = mergeValue(state, name, value, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: '',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.InputChangeEvent,\n name: result.element.props.name,\n value,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Get a formatted file size.\n *\n * @param size - The file size in bytes.\n * @returns The formatted file size in MB, with two decimal places.\n * @example\n * getFormattedFileSize(1_000_000); // '1.00 MB'\n */\nfunction getFormattedFileSize(size: number) {\n return `${(size / 1_000_000).toFixed(2)} MB`;\n}\n\n/**\n * Upload a file to an interface element.\n *\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param id - The interface ID.\n * @param content - The interface Components.\n * @param snapId - The Snap ID.\n * @param name - The element name.\n * @param file - The file to upload. This can be a path to a file or a\n * `Uint8Array` containing the file contents. If this is a path, the file is\n * resolved relative to the current working directory.\n * @param options - The file options.\n * @param options.fileName - The name of the file. By default, this is\n * inferred from the file path if it's a path, and defaults to an empty string\n * if it's a `Uint8Array`.\n * @param options.contentType - The content type of the file. By default, this\n * is inferred from the file name if it's a path, and defaults to\n * `application/octet-stream` if it's a `Uint8Array` or the content type\n * cannot be inferred from the file name.\n */\nexport async function uploadFile(\n controllerMessenger: RootControllerMessenger,\n id: string,\n content: JSXElement,\n snapId: SnapId,\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined,\n `Could not find an element in the interface with the name \"${name}\".`,\n );\n\n assert(\n result.element.type === 'FileInput',\n `Expected an element of type \"FileInput\", but found \"${result.element.type}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n const fileSize = await getFileSize(file);\n if (fileSize > MAX_FILE_SIZE) {\n throw new Error(\n `The file size (${getFormattedFileSize(\n fileSize,\n )}) exceeds the maximum allowed size of ${getFormattedFileSize(\n MAX_FILE_SIZE,\n )}.`,\n );\n }\n\n const fileObject = await getFileToUpload(file, options);\n const newState = mergeValue(state, name, fileObject, result.form);\n\n controllerMessenger.call(\n 'SnapInterfaceController:updateInterfaceState',\n id,\n newState,\n );\n\n await controllerMessenger.call('ExecutionService:handleRpcRequest', snapId, {\n origin: '',\n handler: HandlerType.OnUserInput,\n request: {\n jsonrpc: '2.0',\n method: ' ',\n params: {\n event: {\n type: UserInputEventType.FileUploadEvent,\n name: result.element.props.name,\n file: fileObject,\n },\n id,\n context,\n },\n },\n });\n}\n\n/**\n * Get the user interface actions for a Snap interface. These actions can be\n * used to interact with the interface.\n *\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger used to call actions.\n * @param interface - The interface object.\n * @param interface.content - The interface content.\n * @param interface.id - The interface ID.\n * @returns The user interface actions.\n */\nexport function getInterfaceActions(\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n { content, id }: Omit<Interface, 'type'> & { content: JSXElement },\n): SnapInterfaceActions {\n return {\n clickElement: async (name: string) => {\n await clickElement(controllerMessenger, id, content, snapId, name);\n },\n\n typeInField: async (name: string, value: string) => {\n await typeInField(controllerMessenger, id, content, snapId, name, value);\n },\n\n selectInDropdown: async (name: string, value: string) => {\n await selectInDropdown(\n controllerMessenger,\n id,\n content,\n snapId,\n name,\n value,\n );\n },\n\n uploadFile: async (\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ) => {\n await uploadFile(\n controllerMessenger,\n id,\n content,\n snapId,\n name,\n file,\n options,\n );\n },\n };\n}\n\n/**\n * Get a user interface object from a Snap.\n *\n * @param runSaga - A function to run a saga outside the usual Redux flow.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger used to call actions.\n * @yields Takes the set interface action.\n * @returns The user interface object.\n */\nexport function* getInterface(\n runSaga: RunSagaFunction,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): SagaIterator<SnapInterface> {\n const storedInterface = yield call(\n getStoredInterface,\n controllerMessenger,\n snapId,\n );\n\n const interfaceActions = getInterfaceActions(\n snapId,\n controllerMessenger,\n storedInterface,\n );\n\n return getInterfaceResponse(\n runSaga,\n storedInterface.type,\n storedInterface.content,\n interfaceActions,\n );\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/structs.ts"],"sourcesContent":["import { NotificationType, enumValue } from '@metamask/snaps-sdk';\nimport { JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n union,\n record,\n any,\n func,\n type,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SignatureOptionsStruct = object({\n /**\n * The origin making the signature request.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address signing the signature request. Defaults to a randomly generated\n * address.\n */\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `string`, an object, or an array of objects. This covers the data types\n * for the supported signature methods. Defaults to `0x`.\n */\n data: defaulted(\n union([\n StrictHexStruct,\n literal('0x'),\n record(string(), any()),\n array(record(string(), any())),\n ]),\n '0x',\n ),\n\n /**\n * The signature method being used.\n */\n signatureMethod: defaulted(\n union([\n literal('eth_sign'),\n literal('personal_sign'),\n literal('eth_signTypedData'),\n literal('eth_signTypedData_v3'),\n literal('eth_signTypedData_v4'),\n ]),\n 'personal_sign',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const JsonRpcMockOptionsStruct = object({\n method: string(),\n result: JsonStruct,\n});\n\nexport const InterfaceStruct = type({\n content: optional(JSXElementStruct),\n});\n\nexport const SnapResponseWithoutInterfaceStruct = object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n});\n\nexport const SnapResponseWithInterfaceStruct = assign(\n SnapResponseWithoutInterfaceStruct,\n object({\n getInterface: func(),\n }),\n);\n\nexport const SnapResponseStruct = union([\n SnapResponseWithoutInterfaceStruct,\n SnapResponseWithInterfaceStruct,\n]);\n"],"mappings":";AAAA,SAAS,kBAAkB,iBAAiB;AAC5C,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,IAAM,kBAAkB,MAAM;AAAA,EAC5B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,SAAS,UAAU;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IAAM,oBAAoB,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA,EAKtC,SAAS,UAAU,SAAS,OAAO,CAAC,GAAG,GAAI;AAC7C,CAAC;AAEM,IAAM,2BAA2B,OAAO;AAAA,EAC7C,QAAQ,OAAO;AAAA,EACf,QAAQ;AACV,CAAC;AAEM,IAAM,kBAAkB,KAAK;AAAA,EAClC,SAAS,SAAS,gBAAgB;AACpC,CAAC;AAEM,IAAM,qCAAqC,OAAO;AAAA,EACvD,IAAI,OAAO;AAAA,EAEX,UAAU,MAAM;AAAA,IACd,OAAO;AAAA,MACL,QAAQ;AAAA,IACV,CAAC;AAAA,IACD,OAAO;AAAA,MACL,OAAO;AAAA,IACT,CAAC;AAAA,EACH,CAAC;AAAA,EAED,eAAe;AAAA,IACb,OAAO;AAAA,MACL,IAAI,OAAO;AAAA,MACX,SAAS,OAAO;AAAA,MAChB,MAAM,MAAM;AAAA,QACV,UAAU,iBAAiB,KAAK;AAAA,QAChC,UAAU,iBAAiB,MAAM;AAAA,MACnC,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF,CAAC;AAEM,IAAM,kCAAkC;AAAA,EAC7C;AAAA,EACA,OAAO;AAAA,IACL,cAAc,KAAK;AAAA,EACrB,CAAC;AACH;AAEO,IAAM,qBAAqB,MAAM;AAAA,EACtC;AAAA,EACA;AACF,CAAC;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/options.ts"],"sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n create,\n defaulted,\n nullable,\n object,\n optional,\n record,\n string,\n} from 'superstruct';\n\nimport { DEFAULT_LOCALE, DEFAULT_SRP } from './constants';\n\nconst SimulationOptionsStruct = object({\n secretRecoveryPhrase: defaulted(optional(string()), DEFAULT_SRP),\n locale: defaulted(optional(string()), DEFAULT_LOCALE),\n state: defaulted(optional(nullable(record(string(), JsonStruct))), null),\n unencryptedState: defaulted(\n optional(nullable(record(string(), JsonStruct))),\n null,\n ),\n});\n\n/**\n * Options for the simulation.\n *\n * @property secretRecoveryPhrase - The secret recovery phrase to use. This is\n * used to derive addresses and private keys. Defaults to a test recovery\n * phrase.\n * @property locale - The locale to use. Defaults to `en`.\n * @property state - The initial state of the Snap, if any. Defaults to `null`.\n */\nexport type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;\n\n/**\n * Options for the simulation, with defaults filled in.\n *\n * See {@link SimulationUserOptions} for documentation.\n */\nexport type SimulationOptions = Required<SimulationUserOptions>;\n\n/**\n * Get the options for the simulation.\n *\n * @param options - The user options. Any options not specified will be filled\n * in with default values.\n * @returns The simulation options.\n */\nexport function getOptions(options: SimulationUserOptions): SimulationOptions {\n return create(\n options,\n SimulationOptionsStruct,\n ) as Required<SimulationUserOptions>;\n}\n"],"mappings":";;;;;;AAAA,SAAS,kBAAkB;AAE3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAIP,IAAM,0BAA0B,OAAO;AAAA,EACrC,sBAAsB,UAAU,SAAS,OAAO,CAAC,GAAG,WAAW;AAAA,EAC/D,QAAQ,UAAU,SAAS,OAAO,CAAC,GAAG,cAAc;AAAA,EACpD,OAAO,UAAU,SAAS,SAAS,OAAO,OAAO,GAAG,UAAU,CAAC,CAAC,GAAG,IAAI;AAAA,EACvE,kBAAkB;AAAA,IAChB,SAAS,SAAS,OAAO,OAAO,GAAG,UAAU,CAAC,CAAC;AAAA,IAC/C;AAAA,EACF;AACF,CAAC;AA2BM,SAAS,WAAW,SAAmD;AAC5E,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/helpers.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa,eAAe;AACrC,SAAS,cAAc,0BAA0B;AACjD,SAAS,cAAc;AAyBvB,IAAM,MAAM,mBA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sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType, logInfo } from '@metamask/snaps-utils';\nimport { assertStruct, createModuleLogger } from '@metamask/utils';\nimport { create } from 'superstruct';\n\nimport {\n rootLogger,\n handleRequest,\n TransactionOptionsStruct,\n getEnvironment,\n JsonRpcMockOptionsStruct,\n SignatureOptionsStruct,\n SnapResponseWithInterfaceStruct,\n} from './internals';\nimport type { InstallSnapOptions } from './internals';\nimport {\n addJsonRpcMock,\n removeJsonRpcMock,\n} from './internals/simulation/store/mocks';\nimport type {\n SnapResponseWithInterface,\n CronjobOptions,\n JsonRpcMockOptions,\n Snap,\n SnapResponse,\n TransactionOptions,\n} from './types';\n\nconst log = createModuleLogger(rootLogger, 'helpers');\n\n/**\n * Get the options for {@link installSnap}.\n *\n * @param snapId - The ID of the Snap, or the options.\n * @param options - The options, if any.\n * @returns The options.\n */\nfunction getOptions<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId | Partial<InstallSnapOptions<Service>> | undefined,\n options: Partial<InstallSnapOptions<Service>>,\n): [SnapId | undefined, Partial<InstallSnapOptions<Service>>] {\n if (typeof snapId === 'object') {\n return [undefined, snapId];\n }\n\n return [snapId, options];\n}\n\n/**\n * Ensure that the actual response contains `getInterface`.\n *\n * @param response - The response of the handler.\n */\nfunction assertIsResponseWithInterface(\n response: SnapResponse,\n): asserts response is SnapResponseWithInterface {\n assertStruct(response, SnapResponseWithInterfaceStruct);\n}\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap(): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\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 * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(options: Partial<InstallSnapOptions<Service>>): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\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 * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId: SnapId,\n options?: Partial<InstallSnapOptions<Service>>,\n): Promise<Snap>;\n\n/**\n * Load a snap into the environment. This is the main entry point for testing\n * snaps: It returns a {@link Snap} object that can be used to interact with the\n * snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * describe('My Snap', () => {\n * it('should do something', async () => {\n * const { request } = await installSnap('local:my-snap');\n * const response = await request({\n * method: 'foo',\n * params: ['bar'],\n * });\n * expect(response).toRespondWith('bar');\n * });\n * });\n * @param snapId - The ID of the snap, including the prefix (`local:`). Defaults\n * to the URL of the built-in server, if it is running. This supports both\n * local snap IDs and NPM snap IDs.\n * @param options - The options to use.\n * @param options.executionService - The execution service to use. Defaults to\n * {@link NodeThreadExecutionService}. You do not need to provide this unless\n * you are testing a custom execution service.\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 * @returns The snap.\n * @throws If the built-in server is not running, and no snap ID is provided.\n */\nexport async function installSnap<\n Service extends new (...args: any[]) => InstanceType<\n typeof AbstractExecutionService\n >,\n>(\n snapId?: SnapId | Partial<InstallSnapOptions<Service>>,\n options: Partial<InstallSnapOptions<Service>> = {},\n): Promise<Snap> {\n const resolvedOptions = getOptions(snapId, options);\n const {\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n } = await getEnvironment().installSnap(...resolvedOptions);\n\n const onTransaction = async (\n request: TransactionOptions,\n ): Promise<SnapResponseWithInterface> => {\n log('Sending transaction %o.', request);\n\n const {\n origin: transactionOrigin,\n chainId,\n ...transaction\n } = create(request, TransactionOptionsStruct);\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n runSaga,\n controllerMessenger,\n handler: HandlerType.OnTransaction,\n request: {\n method: '',\n params: {\n chainId,\n transaction,\n transactionOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n };\n\n const onCronjob = (request: CronjobOptions) => {\n log('Running cronjob %o.', options);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnCronjob,\n request,\n });\n };\n\n return {\n request: (request) => {\n log('Sending request %o.', request);\n\n return handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnRpcRequest,\n request,\n });\n },\n\n onTransaction,\n sendTransaction: onTransaction,\n\n onSignature: async (\n request: unknown,\n ): Promise<SnapResponseWithInterface> => {\n log('Requesting signature %o.', request);\n\n const { origin: signatureOrigin, ...signature } = create(\n request,\n SignatureOptionsStruct,\n );\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnSignature,\n request: {\n method: '',\n params: {\n signature,\n signatureOrigin,\n },\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n onCronjob,\n runCronjob: onCronjob,\n\n onHomePage: async (): Promise<SnapResponseWithInterface> => {\n log('Rendering home page.');\n\n const response = await handleRequest({\n snapId: installedSnapId,\n store,\n executionService,\n controllerMessenger,\n runSaga,\n handler: HandlerType.OnHomePage,\n request: {\n method: '',\n },\n });\n\n assertIsResponseWithInterface(response);\n\n return response;\n },\n\n mockJsonRpc(mock: JsonRpcMockOptions) {\n log('Mocking JSON-RPC request %o.', mock);\n\n const { method, result } = create(mock, JsonRpcMockOptionsStruct);\n store.dispatch(addJsonRpcMock({ method, result }));\n\n return {\n unmock() {\n log('Unmocking JSON-RPC request %o.', mock);\n\n store.dispatch(removeJsonRpcMock(method));\n },\n };\n },\n\n close: async () => {\n log('Closing execution service.');\n logInfo(\n 'Calling `snap.close()` is deprecated, and will be removed in a future release. Snaps are now automatically closed when the test ends.',\n );\n\n await executionService.terminateAllSnaps();\n },\n };\n}\n"]}
@@ -1,13 +0,0 @@
1
- // src/internals/simulation/methods/hooks/get-locale.ts
2
- function getGetLocaleMethodImplementation({
3
- locale
4
- }) {
5
- return async () => {
6
- return locale;
7
- };
8
- }
9
-
10
- export {
11
- getGetLocaleMethodImplementation
12
- };
13
- //# sourceMappingURL=chunk-KSIBNOB2.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/methods/hooks/get-locale.ts"],"sourcesContent":["import type { SimulationOptions } from '../../options';\n\n/**\n * Get the implementation of the `getLocale` hook.\n *\n * @param options - The simulation options.\n * @param options.locale - The locale to use.\n * @returns The implementation of the `getLocale` hook.\n */\nexport function getGetLocaleMethodImplementation({\n locale,\n}: SimulationOptions) {\n return async () => {\n return locale;\n };\n}\n"],"mappings":";AASO,SAAS,iCAAiC;AAAA,EAC/C;AACF,GAAsB;AACpB,SAAO,YAAY;AACjB,WAAO;AAAA,EACT;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n ComponentOrElement,\n Component,\n} from '@metamask/snaps-sdk';\nimport type {\n GenericSnapElement,\n JSXElement,\n SnapNode,\n} from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport { getJsxElementFromComponent } from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n EXPECTED_COLOR,\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: JSXElement } {\n if (!is(actual, InterfaceStruct) || !actual.content) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR('received')} value must have a \\`content\\` property`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Check if a JSON-RPC response matches the expected value. This matcher is\n * intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected response.\n * @returns The status and message.\n */\nexport const toRespondWith: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWith');\n\n const { response } = actual;\n if (hasProperty(response, 'error')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected response: ${this.utils.printExpected(expected)}\\n` +\n `Received error: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.result, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWith')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass };\n};\n\nexport const toRespondWithError: MatcherFunction<[expected: Json]> = function (\n actual,\n expected,\n) {\n assertActualIsSnapResponse(actual, 'toRespondWithError');\n\n const { response } = actual;\n if (hasProperty(response, 'result')) {\n const message = () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected error: ${this.utils.printExpected(expected)}\\n` +\n `Received result: ${this.utils.printReceived(response.result)}`;\n\n return { message, pass: false };\n }\n\n const pass = this.equals(response.error, expected);\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`\n : () =>\n `${this.utils.matcherHint('.toRespondWithError')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(response.error)}`;\n\n return { message, pass };\n};\n\n/**\n * Check if the snap sent a notification with the expected message. This matcher\n * is intended to be used with the `expect` global.\n *\n * @param actual - The actual response.\n * @param expected - The expected notification message.\n * @param type - The expected notification type.\n * @returns The status and message.\n */\nexport const toSendNotification: MatcherFunction<\n [expected: string, type?: EnumToUnion<NotificationType> | undefined]\n> = function (actual, expected, type) {\n assertActualIsSnapResponse(actual, 'toSendNotification');\n\n const { notifications } = actual;\n const pass = notifications.some(\n (notification) =>\n this.equals(notification.message, expected) &&\n (type === undefined || notification.type === type),\n );\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`\n : () =>\n `${this.utils.matcherHint('.toSendNotification')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Expected type: ${this.utils.printExpected(type)}\\n` +\n `Received: ${this.utils.printReceived(notifications)}`;\n\n return { message, pass };\n};\n\n/**\n * Serialise a JSX prop to a string.\n *\n * @param prop - The JSX prop.\n * @returns The serialised JSX prop.\n */\nfunction serialiseProp(prop: unknown): string {\n if (typeof prop === 'string') {\n return `\"${prop}\"`;\n }\n\n return `{${JSON.stringify(prop)}}`;\n}\n\n/**\n * Serialise JSX props to a string.\n *\n * @param props - The JSX props.\n * @returns The serialised JSX props.\n */\nfunction serialiseProps(props: Record<string, unknown>): string {\n return Object.entries(props)\n .filter(([key]) => key !== 'children')\n .sort(([a], [b]) => a.localeCompare(b))\n .map(([key, value]) => ` ${key}=${serialiseProp(value)}`)\n .join('');\n}\n\n/**\n * Serialise a JSX node to a string.\n *\n * @param node - The JSX node.\n * @param indentation - The indentation level. Defaults to `0`. This should not\n * be set by the caller, as it is used for recursion.\n * @returns The serialised JSX node.\n */\nexport function serialiseJsx(node: SnapNode, indentation = 0): string {\n if (Array.isArray(node)) {\n return node.map((child) => serialiseJsx(child, indentation)).join('');\n }\n\n const indent = ' '.repeat(indentation);\n if (typeof node === 'string') {\n return `${indent}${node}\\n`;\n }\n\n if (!node) {\n return '';\n }\n\n const { type, props } = node as GenericSnapElement;\n const trailingNewline = indentation > 0 ? '\\n' : '';\n\n if (hasProperty(props, 'children')) {\n const children = serialiseJsx(props.children as SnapNode, indentation + 1);\n return `${indent}<${type}${serialiseProps(\n props,\n )}>\\n${children}${indent}</${type}>${trailingNewline}`;\n }\n\n return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;\n}\n\nconst toRenderLegacy: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\n\n const { content } = actual;\n const expectedElement = getJsxElementFromComponent(expected);\n const pass = this.equals(content, expectedElement);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expectedElement, content) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${this.utils.printExpected(expectedElement)}\\n\\n` +\n `Received:\\n${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n};\n\nexport const toRender: MatcherFunction<[expected: ComponentOrElement]> =\n function (actual, expected) {\n assertHasInterface(actual, 'toRender');\n\n if (!isJSXElementUnsafe(expected)) {\n return toRenderLegacy.call(this, actual, expected);\n }\n\n const { content } = actual;\n const pass = this.equals(content, expected);\n\n // This is typed as `string | null`, but in practice it's always a string.\n // The function only returns `null` if both the expected and actual values\n // are numbers, bigints, or booleans, which is never the case here.\n const difference = diff(\n serialiseJsx(expected),\n serialiseJsx(content),\n ) as string;\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected:\\n${EXPECTED_COLOR(serialiseJsx(expected))}\\n\\n` +\n `Received:\\n${RECEIVED_COLOR(serialiseJsx(content))}` +\n `\\n\\nDifference:\\n\\n${difference}`;\n\n return { message, pass };\n };\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"mappings":";;;;;;AAMA,SAAS,cAAc;AAYvB,SAAS,0BAA0B;AACnC,SAAS,kCAAkC;AAE3C,SAAS,mBAAmB;AAE5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU;AAYnB,SAAS,2BACP,QACA,aACA,SACgC;AAChC,MAAI,CAAC,GAAG,QAAQ,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AC;AAAA;AAAA;AAAA;AAAA,EAC7B,UAAU,KAClC,MACE,GAAG,KAAK,MAAM,YAAY,WAAW,CAAC;AAAA;AAAA;AAAA,EACxB,eAAe,aAAa,QAAQ,CAAC,CAAC;AAAA;AAAA;AAAA,EACtC,eAAe,aAAa,OAAO,CAAC,CAAC;AAAA;AAAA;AAAA;AAAA,EAC7B,UAAU;AAEtC,SAAO,EAAE,SAAS,KAAK;AACzB;AAEF,OAAO,OAAO;AAAA,EACZ;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;","names":["message"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/methods/specifications.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AA2C5B,SAAS,QAAQ,QAAiB;AACvC,SAAO,MAAM;AACf;AASO,SAAS,aAAa,QAAkB;AAC7C,SAAO,YAAY;AACrB;AAaO,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AACrC,SAAO;AAAA,IACL,GAAG,iCAAiC,wBAAwB;AAAA,IAC5D,GAAG,wCAAwC,2BAA2B;AAAA;AAAA,MAEpE,GAAG;AAAA;AAAA,MAGH,gBAAgB,sCAAsC,OAAO;AAAA,MAC7D,WAAW,iCAAiC,OAAO;AAAA,MACnD,cAAc,oCAAoC,OAAO;AAAA,MACzD,kBAAkB,aAAa,IAAI;AAAA;AAAA,MAGnC,kBAAkB,QAAQ,KAAK;AAAA,MAE/B,yBAAyB,aAAa;AAAA,MACtC,YAAY,4BAA4B,OAAO;AAAA,MAC/C,uBAAuB,uCAAuC,OAAO;AAAA,MACrE,wBAAwB,wCAAwC,OAAO;AAAA,MACvE,iBAAiB,uCAAuC,OAAO;AAAA,MAC/D,iBAAiB,iCAAiC,mBAAmB;AAAA,MACrE,cAAc,8BAA8B,mBAAmB;AAAA,IACjE,CAAC;AAAA,EACH;AACF;AASA,eAAsB,cACpB,sBACA,QACA;AACA,QAAM,gBAAgB,MAAM,OAAO,KAAK,2BAA2B,EAAE,OAEnE,OAAO,SAAS,mBAAmB;AACnC,UAAM,cAAc,MAAM;AAC1B,QAAI,qBAAqB,cAAc,QAAQ,cAAc,GAAG;AAC9D,YAAM,aAAa,MAAM,qBAAqB;AAAA,QAC5C;AAAA,QACA;AAAA,MACF;AAEA,UAAI,YAAY;AACd,eAAO,YAAY,OAAO,UAAsB;AAAA,MAClD;AAAA,IACF;AAEA,WAAO;AAAA,EACT,GAAG,QAAQ,QAAQ,CAAC,CAAC,CAAC;AAEtB,SAAO,CAAC,GAAG,oBAAI,IAAI,CAAC,GAAG,oBAAoB,GAAG,aAAa,CAAC,CAAC;AAC/D","sourcesContent":["import type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetLocaleMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowDialogImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n} from './hooks';\n\nexport type PermissionSpecificationsHooks = {\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\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve(result?: unknown) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.runSaga - The function to run a saga outside the usual Redux\n * flow.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n}: GetPermissionSpecificationsOptions) {\n return {\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {\n // Shared hooks.\n ...hooks,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getLocale: getGetLocaleMethodImplementation(options),\n getSnapState: getGetSnapStateMethodImplementation(runSaga),\n getUnlockPromise: asyncResolve(true),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n showDialog: getShowDialogImplementation(runSaga),\n showInAppNotification: getShowInAppNotificationImplementation(runSaga),\n showNativeNotification: getShowNativeNotificationImplementation(runSaga),\n updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),\n createInterface: getCreateInterfaceImplementation(controllerMessenger),\n getInterface: getGetInterfaceImplementation(controllerMessenger),\n }),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/simulation.ts"],"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 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 { Duplex } from 'readable-stream';\nimport { pipeline } from 'readable-stream';\n\nimport type { RootControllerMessenger } from './controllers';\nimport { getControllers, registerSnap } from './controllers';\nimport { getSnapFile } from './files';\nimport { getEndowments } from './methods';\nimport { createJsonRpcEngine } from './middleware';\nimport type { SimulationOptions, SimulationUserOptions } from './options';\nimport { getOptions } from './options';\nimport type { RunSagaFunction, Store } from './store';\nimport { createStore } 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};\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);\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 };\n}\n\n/**\n * Register mocked action handlers.\n *\n * @param controllerMessenger - The controller messenger.\n */\nexport function registerActions(controllerMessenger: RootControllerMessenger) {\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAIA,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,6BAA6B;AAEtC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAQP,SAAS,gBAAgB;AAEzB,SAAS,gBAAgB;AAyGzB,eAAsB,kBAKpB,QACA;AAAA,EACE;AAAA,EACA;AAAA,EACA,SAAS,aAAa,CAAC;AACzB,IAA0C,CAAC,GACnB;AACxB,QA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,YAAY,MAAM,cAAc,sBAAsB,MAAM;AAAA,EAC9D,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,kBAAkB;AAAA,IAClB;AAAA,IACA;AAAA,EACF;AACF;AAWO,SAAS,SACd,SACA,WACA,QACA,qBACiB;AACjB,SAAO;AAAA,IACL,aAAa,YACX,QAAQ,QAAQ,sBAAsB,QAAQ,oBAAoB,CAAC;AAAA,IACrE,aAAa,OAAO,MAAc,aAChC,MAAM,YAAY,UAAU,gBAAgB,MAAM,QAAQ;AAAA,IAC5D,aAAa,MAAM;AAAA,IACnB,iBAAiB,UAAU,SACzB,oBAAoB;AAAA,MAClB;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL;AAAA,IACF,iBAAiB,UAAU,SACzB,oBAAoB;AAAA,MAClB;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL;AAAA,IACF,mBAAmB,IAAI,SACrB,oBAAoB;AAAA,MAClB;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IACL,EAAE;AAAA,EACN;AACF;AAOO,SAAS,gBAAgB,qBAA8C;AAC5E,sBAAoB;AAAA,IAClB;AAAA,IACA,YAAY,QAAQ,QAAQ;AAAA,EAC9B;AAEA,sBAAoB;AAAA,IAClB;AAAA,IACA,OAAO,EAAE,QAAQ,OAAO,MAAM,MAAM;AAAA,EACtC;AACF;","names":[]}
@@ -1,24 +0,0 @@
1
- import {
2
- closeInterface,
3
- resolveInterface,
4
- setInterface
5
- } from "./chunk-74TIKA2T.mjs";
6
-
7
- // src/internals/simulation/methods/hooks/show-dialog.ts
8
- import { put, take } from "redux-saga/effects";
9
- function* showDialogImplementation(_snapId, type, id, _placeholder) {
10
- yield put(setInterface({ type, id }));
11
- const { payload } = yield take(resolveInterface.type);
12
- yield put(closeInterface());
13
- return payload;
14
- }
15
- function getShowDialogImplementation(runSaga) {
16
- return async (...args) => {
17
- return await runSaga(showDialogImplementation, ...args).toPromise();
18
- };
19
- }
20
-
21
- export {
22
- getShowDialogImplementation
23
- };
24
- //# sourceMappingURL=chunk-ORO3T6BU.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/methods/hooks/show-dialog.ts"],"sourcesContent":["import type { DialogType } from '@metamask/snaps-sdk';\nimport 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\n/**\n * Show a dialog to the user. This will wait for `resolveUserInterface` to be\n * dispatched before returning.\n *\n * @param _snapId - The ID of the Snap that created the dialog. This is ignored\n * because the simulator only supports one Snap.\n * @param type - The type of dialog to show.\n * @param id - The interface ID.\n * @param _placeholder - The placeholder text to show in the dialog. This is\n * not implemented yet.\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* showDialogImplementation(\n _snapId: string,\n type: DialogType,\n id: string,\n _placeholder?: string,\n): 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 `showDialog` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `showDialog` hook.\n */\nexport function getShowDialogImplementation(runSaga: RunSagaFunction) {\n return async (...args: Parameters<typeof showDialogImplementation>) => {\n return await runSaga(showDialogImplementation, ...args).toPromise();\n };\n}\n"],"mappings":";;;;;;;AAEA,SAAS,KAAK,YAAY;AAmB1B,UAAU,yBACR,SACA,MACA,IACA,cACuB;AACvB,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,4BAA4B,SAA0B;AACpE,SAAO,UAAU,SAAsD;AACrE,WAAO,MAAM,QAAQ,0BAA0B,GAAG,IAAI,EAAE,UAAU;AAAA,EACpE;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/store/ui.ts"],"names":[],"mappings":";AAEA,SAAS,cAAc,gBAAgB,mBAAmB;AAa1D,IAAM,gBAAyB;AAAA,EAC7B,SAAS;AACX;AAEO,IAAM,UAAU,YAAY;AAAA,EACjC,MAAM;AAAA,EACN,cAAc;AAAA,EACd,UAAU;AAAA,IACR,aAAa,OAAO,QAAkC;AACpD,YAAM,UAAU,OAAO;AAAA,IACzB;AAAA,IACA,eAAe,OAAO;AACpB,YAAM,UAAU;AAAA,IAClB;AAAA,EACF;AACF,CAAC;AAEM,IAAM,mBAAmB;AAAA,EAC9B,GAAG,QAAQ,IAAI;AACjB;AAEO,IAAM,EAAE,cAAc,eAAe,IAAI,QAAQ;AAEjD,IAAM,sBAAsB;AAAA,EACjC,CAAC,UAA4B,MAAM;AAAA,EACnC,CAAC,OAAO,GAAG;AACb","sourcesContent":["import type { DialogType } from '@metamask/snaps-sdk';\nimport type { PayloadAction } from '@reduxjs/toolkit';\nimport { createAction, createSelector, createSlice } from '@reduxjs/toolkit';\n\nimport type { ApplicationState } from './store';\n\nexport type Interface = {\n type: DialogType;\n id: string;\n};\n\nexport type UiState = {\n current?: Interface | null;\n};\n\nconst INITIAL_STATE: UiState = {\n current: null,\n};\n\nexport const uiSlice = createSlice({\n name: 'ui',\n initialState: INITIAL_STATE,\n reducers: {\n setInterface(state, action: PayloadAction<Interface>) {\n state.current = action.payload;\n },\n closeInterface(state) {\n state.current = null;\n },\n },\n});\n\nexport const resolveInterface = createAction<unknown>(\n `${uiSlice.name}/resolveInterface`,\n);\n\nexport const { setInterface, closeInterface } = uiSlice.actions;\n\nexport const getCurrentInterface = createSelector(\n (state: ApplicationState) => state.ui,\n (ui) => ui.current,\n);\n"]}
@@ -1,24 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
-
4
-
5
- var _chunkPZDTZGSIjs = require('./chunk-PZDTZGSI.js');
6
-
7
- // src/internals/simulation/methods/hooks/show-dialog.ts
8
- var _effects = require('redux-saga/effects');
9
- function* showDialogImplementation(_snapId, type, id, _placeholder) {
10
- yield _effects.put.call(void 0, _chunkPZDTZGSIjs.setInterface.call(void 0, { type, id }));
11
- const { payload } = yield _effects.take.call(void 0, _chunkPZDTZGSIjs.resolveInterface.type);
12
- yield _effects.put.call(void 0, _chunkPZDTZGSIjs.closeInterface.call(void 0, ));
13
- return payload;
14
- }
15
- function getShowDialogImplementation(runSaga) {
16
- return async (...args) => {
17
- return await runSaga(showDialogImplementation, ...args).toPromise();
18
- };
19
- }
20
-
21
-
22
-
23
- exports.getShowDialogImplementation = getShowDialogImplementation;
24
- //# sourceMappingURL=chunk-RAMAN5RM.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/methods/hooks/show-dialog.ts"],"names":[],"mappings":";;;;;;;AAEA,SAAS,KAAK,YAAY;AAmB1B,UAAU,yBACR,SACA,MACA,IACA,cACuB;AACvB,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,4BAA4B,SAA0B;AACpE,SAAO,UAAU,SAAsD;AACrE,WAAO,MAAM,QAAQ,0BAA0B,GAAG,IAAI,EAAE,UAAU;AAAA,EACpE;AACF","sourcesContent":["import type { DialogType } from '@metamask/snaps-sdk';\nimport 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\n/**\n * Show a dialog to the user. This will wait for `resolveUserInterface` to be\n * dispatched before returning.\n *\n * @param _snapId - The ID of the Snap that created the dialog. This is ignored\n * because the simulator only supports one Snap.\n * @param type - The type of dialog to show.\n * @param id - The interface ID.\n * @param _placeholder - The placeholder text to show in the dialog. This is\n * not implemented yet.\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* showDialogImplementation(\n _snapId: string,\n type: DialogType,\n id: string,\n _placeholder?: string,\n): 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 `showDialog` hook.\n *\n * @param runSaga - The function to run a saga outside the usual Redux flow.\n * @returns The implementation of the `showDialog` hook.\n */\nexport function getShowDialogImplementation(runSaga: RunSagaFunction) {\n return async (...args: Parameters<typeof showDialogImplementation>) => {\n return await runSaga(showDialogImplementation, ...args).toPromise();\n };\n}\n"]}
@@ -1 +0,0 @@
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 'superstruct';\nimport {\n boolean,\n create,\n defaulted,\n number,\n object,\n string,\n type,\n} from '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"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/methods/specifications.ts"],"sourcesContent":["import type { GenericPermissionController } from '@metamask/permission-controller';\nimport {\n endowmentPermissionBuilders,\n buildSnapEndowmentSpecifications,\n buildSnapRestrictedMethodSpecifications,\n} from '@metamask/snaps-rpc-methods';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { DEFAULT_ENDOWMENTS } from '@metamask/snaps-utils';\n\nimport type { RootControllerMessenger } from '../controllers';\nimport type { SimulationOptions } from '../options';\nimport type { RunSagaFunction } from '../store';\nimport {\n EXCLUDED_SNAP_ENDOWMENTS,\n EXCLUDED_SNAP_PERMISSIONS,\n} from './constants';\nimport {\n getGetLocaleMethodImplementation,\n getClearSnapStateMethodImplementation,\n getGetSnapStateMethodImplementation,\n getUpdateSnapStateMethodImplementation,\n getShowDialogImplementation,\n getShowInAppNotificationImplementation,\n getShowNativeNotificationImplementation,\n getCreateInterfaceImplementation,\n getGetInterfaceImplementation,\n} from './hooks';\n\nexport type PermissionSpecificationsHooks = {\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\nexport type GetPermissionSpecificationsOptions = {\n controllerMessenger: RootControllerMessenger;\n hooks: PermissionSpecificationsHooks;\n runSaga: RunSagaFunction;\n options: SimulationOptions;\n};\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return.\n * @returns The function implementation.\n */\nexport function resolve(result: unknown) {\n return () => result;\n}\n\n/**\n * Get a function which resolves with the specified result.\n *\n * @param result - The result to return. If not specified, the function will\n * resolve with `undefined`.\n * @returns The function implementation.\n */\nexport function asyncResolve(result?: unknown) {\n return async () => result;\n}\n\n/**\n * Get the permission specifications for the Snap.\n *\n * @param options - The options.\n * @param options.controllerMessenger - The controller messenger.\n * @param options.hooks - The hooks.\n * @param options.runSaga - The function to run a saga outside the usual Redux\n * flow.\n * @param options.options - The simulation options.\n * @returns The permission specifications for the Snap.\n */\nexport function getPermissionSpecifications({\n controllerMessenger,\n hooks,\n runSaga,\n options,\n}: GetPermissionSpecificationsOptions) {\n return {\n ...buildSnapEndowmentSpecifications(EXCLUDED_SNAP_ENDOWMENTS),\n ...buildSnapRestrictedMethodSpecifications(EXCLUDED_SNAP_PERMISSIONS, {\n // Shared hooks.\n ...hooks,\n\n // Snaps-specific hooks.\n clearSnapState: getClearSnapStateMethodImplementation(runSaga),\n getLocale: getGetLocaleMethodImplementation(options),\n getSnapState: getGetSnapStateMethodImplementation(runSaga),\n getUnlockPromise: asyncResolve(true),\n\n // TODO: Allow the user to specify the result of this function.\n isOnPhishingList: resolve(false),\n\n maybeUpdatePhishingList: asyncResolve(),\n showDialog: getShowDialogImplementation(runSaga),\n showInAppNotification: getShowInAppNotificationImplementation(runSaga),\n showNativeNotification: getShowNativeNotificationImplementation(runSaga),\n updateSnapState: getUpdateSnapStateMethodImplementation(runSaga),\n createInterface: getCreateInterfaceImplementation(controllerMessenger),\n getInterface: getGetInterfaceImplementation(controllerMessenger),\n }),\n };\n}\n\n/**\n * Get the endowments for the Snap.\n *\n * @param permissionController - The permission controller.\n * @param snapId - The ID of the Snap.\n * @returns The endowments for the Snap.\n */\nexport async function getEndowments(\n permissionController: GenericPermissionController,\n snapId: SnapId,\n) {\n const allEndowments = await Object.keys(endowmentPermissionBuilders).reduce<\n Promise<string[]>\n >(async (promise, permissionName) => {\n const accumulator = await promise;\n if (permissionController.hasPermission(snapId, permissionName)) {\n const endowments = await permissionController.getEndowments(\n snapId,\n permissionName,\n );\n\n if (endowments) {\n return accumulator.concat(endowments as string[]);\n }\n }\n\n return accumulator;\n }, Promise.resolve([]));\n\n return [...new Set([...DEFAULT_ENDOWMENTS, ...allEndowments])];\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,SAAS,0BAA0B;AA2C5B,SAAS,QAAQ,QAAiB;AACvC,SAAO,MAAM;AACf;AASO,SAAS,aAAa,QAAkB;AAC7C,SAAO,YAAY;AACrB;AAaO,SAAS,4BAA4B;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAuC;AACrC,SAAO;AAAA,IACL,GAAG,iCAAiC,wBAAwB;AAAA,IAC5D,GAAG,wCAAwC,2BAA2B;AAAA;AAAA,MAEpE,GAAG;AAAA;AAAA,MAGH,gBAAgB,sCAAsC,OAAO;AAAA,MAC7D,WAAW,iCAAiC,OAAO;AAAA,MACnD,cAAc,oCAAoC,OAAO;AAAA,MACzD,kBAAkB,aAAa,IAAI;AAAA;AAAA,MAGnC,kBAAkB,QAAQ,KAAK;AAAA,MAE/B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AAA,IAC/C;AAAA,EACF;AACF,CAAC;AA2BM,SAAS,WAAW,SAAmD;AAC5E,SAAO;AAAA,IACL;AAAA,IACA;AAAA,EACF;AACF","sourcesContent":["import { JsonStruct } from '@metamask/utils';\nimport type { Infer } from 'superstruct';\nimport {\n create,\n defaulted,\n nullable,\n object,\n optional,\n record,\n string,\n} from 'superstruct';\n\nimport { DEFAULT_LOCALE, DEFAULT_SRP } from './constants';\n\nconst SimulationOptionsStruct = object({\n secretRecoveryPhrase: defaulted(optional(string()), DEFAULT_SRP),\n locale: defaulted(optional(string()), DEFAULT_LOCALE),\n state: defaulted(optional(nullable(record(string(), JsonStruct))), null),\n unencryptedState: defaulted(\n optional(nullable(record(string(), JsonStruct))),\n null,\n ),\n});\n\n/**\n * Options for the simulation.\n *\n * @property secretRecoveryPhrase - The secret recovery phrase to use. This is\n * used to derive addresses and private keys. Defaults to a test recovery\n * phrase.\n * @property locale - The locale to use. Defaults to `en`.\n * @property state - The initial state of the Snap, if any. Defaults to `null`.\n */\nexport type SimulationUserOptions = Infer<typeof SimulationOptionsStruct>;\n\n/**\n * Options for the simulation, with defaults filled in.\n *\n * See {@link SimulationUserOptions} for documentation.\n */\nexport type SimulationOptions = Required<SimulationUserOptions>;\n\n/**\n * Get the options for the simulation.\n *\n * @param options - The user options. Any options not specified will be filled\n * in with default values.\n * @returns The simulation options.\n */\nexport function getOptions(options: SimulationUserOptions): SimulationOptions {\n return create(\n options,\n SimulationOptionsStruct,\n ) as Required<SimulationUserOptions>;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/constants.ts"],"names":[],"mappings":";AAIO,IAAM,cACX;AAKK,IAAM,iBAAiB;AAKvB,IAAM,4BAA4B","sourcesContent":["/**\n * A secret recovery phrase that is used for testing purposes. Do not use this\n * to store any real funds!\n */\nexport const DEFAULT_SRP =\n 'test test test test test test test test test test test ball';\n\n/**\n * The default locale.\n */\nexport const DEFAULT_LOCALE = 'en';\n\n/**\n * The default JSON-RPC endpoint for Ethereum requests.\n */\nexport const DEFAULT_JSON_RPC_ENDPOINT = 'https://cloudflare-eth.com/';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/structs.ts"],"names":[],"mappings":";AAAA,SAAS,kBAAkB,iBAAiB;AAC5C,SAAS,wBAAwB;AACjC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,IAAM,kBAAkB,MAAM;AAAA,EAC5B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AAAA,EACP,SAAS,UAAU;AACrB,CAAC;AAEM,IAAM,2BAA2B,OAAO;AAAA;AAAA;AAAA;AAAA,EAI7C,SAAS,UAAU,OAAO,GAAG,UAAU;AAAA;AAAA;AAAA;AAAA,EAKvC,QAAQ,UAAU,OAAO,GAAG,aAAa;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOzC,MAAM,OAAO,iBAAiB,SAAS,eAAe,GAAG,CAAC,UAAU;AAClE,QAAI,OAAO;AACT,aAAO,WAAW,aAAa,KAAK,CAAC;AAAA,IACvC;AAEA,WAAO,WAAW,YAAY,EAAE,CAAC;AAAA,EACnC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOD,IAAI,OAAO,iBAAiB,SAAS,eAAe,GAAG,CAAC,UAAU;AAChE,QAAI,OAAO;AACT,aAAO,WAAW,aAAa,KAAK,CAAC;AAAA,IACvC;AAEA,WAAO,WAAW,YAAY,EAAE,CAAC;AAAA,EACnC,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA,EAMD,OAAO;AAAA,IACL;AAAA,MAAO;AAAA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AAC;AAAA,EACH;AACF,CAAC;AAEM,IAAM,kCAAkC;AAAA,EAC7C;AAAA,EACA,OAAO;AAAA,IACL,cAAc,KAAK;AAAA,EACrB,CAAC;AACH;AAEO,IAAM,qBAAqB,MAAM;AAAA,EACtC;AAAA,EACA;AACF,CAAC","sourcesContent":["import { NotificationType, enumValue } from '@metamask/snaps-sdk';\nimport { JSXElementStruct } from '@metamask/snaps-sdk/jsx';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\nimport {\n array,\n assign,\n bigint,\n coerce,\n defaulted,\n instance,\n literal,\n number,\n object,\n optional,\n string,\n union,\n record,\n any,\n func,\n type,\n} from 'superstruct';\n\n// TODO: Export this from `@metamask/utils` instead.\nconst BytesLikeStruct = union([\n bigint(),\n number(),\n string(),\n instance(Uint8Array),\n]);\n\nexport const TransactionOptionsStruct = object({\n /**\n * The CAIP-2 chain ID to send the transaction on. Defaults to `eip155:1`.\n */\n chainId: defaulted(string(), 'eip155:1'),\n\n /**\n * The origin to send the transaction from. Defaults to `metamask.io`.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address to send the transaction from. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The address to send the transaction to. Defaults to a randomly generated\n * address.\n */\n // TODO: Move this coercer to `@metamask/utils`.\n to: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The value to send with the transaction. The value may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n value: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x0',\n ),\n\n /**\n * The gas limit to use for the transaction. The gas limit may be specified\n * as a `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `21_000`.\n */\n gasLimit: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(21_000),\n ),\n\n /**\n * The max fee per gas (in Wei) to use for the transaction. The max fee per\n * gas may be specified as a `number`, `bigint`, `string`, or `Uint8Array`.\n * Defaults to `1`.\n */\n maxFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The max priority fee per gas (in Wei) to use for the transaction. The max\n * priority fee per gas may be specified as a `number`, `bigint`, `string`,\n * or `Uint8Array`. Defaults to `1`.\n */\n maxPriorityFeePerGas: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(1),\n ),\n\n /**\n * The nonce to use for the transaction. The nonce may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0`.\n */\n nonce: defaulted(\n coerce(StrictHexStruct, BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n valueToBytes(0),\n ),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `number`, `bigint`, `string`, or `Uint8Array`. Defaults to `0x`.\n */\n data: defaulted(\n coerce(union([StrictHexStruct, literal('0x')]), BytesLikeStruct, (value) =>\n bytesToHex(valueToBytes(value)),\n ),\n '0x',\n ),\n});\n\nexport const SignatureOptionsStruct = object({\n /**\n * The origin making the signature request.\n */\n origin: defaulted(string(), 'metamask.io'),\n\n /**\n * The address signing the signature request. Defaults to a randomly generated\n * address.\n */\n from: coerce(StrictHexStruct, optional(BytesLikeStruct), (value) => {\n if (value) {\n return bytesToHex(valueToBytes(value));\n }\n\n return bytesToHex(randomBytes(20));\n }),\n\n /**\n * The data to send with the transaction. The data may be specified as a\n * `string`, an object, or an array of objects. This covers the data types\n * for the supported signature methods. Defaults to `0x`.\n */\n data: defaulted(\n union([\n StrictHexStruct,\n literal('0x'),\n record(string(), any()),\n array(record(string(), any())),\n ]),\n '0x',\n ),\n\n /**\n * The signature method being used.\n */\n signatureMethod: defaulted(\n union([\n literal('eth_sign'),\n literal('personal_sign'),\n literal('eth_signTypedData'),\n literal('eth_signTypedData_v3'),\n literal('eth_signTypedData_v4'),\n ]),\n 'personal_sign',\n ),\n});\n\nexport const SnapOptionsStruct = object({\n /**\n * The timeout in milliseconds to use for requests to the snap. Defaults to\n * `1000`.\n */\n timeout: defaulted(optional(number()), 1000),\n});\n\nexport const JsonRpcMockOptionsStruct = object({\n method: string(),\n result: JsonStruct,\n});\n\nexport const InterfaceStruct = type({\n content: optional(JSXElementStruct),\n});\n\nexport const SnapResponseWithoutInterfaceStruct = object({\n id: string(),\n\n response: union([\n object({\n result: JsonStruct,\n }),\n object({\n error: JsonStruct,\n }),\n ]),\n\n notifications: array(\n object({\n id: string(),\n message: string(),\n type: union([\n enumValue(NotificationType.InApp),\n enumValue(NotificationType.Native),\n ]),\n }),\n ),\n});\n\nexport const SnapResponseWithInterfaceStruct = assign(\n SnapResponseWithoutInterfaceStruct,\n object({\n getInterface: func(),\n }),\n);\n\nexport const SnapResponseStruct = union([\n SnapResponseWithoutInterfaceStruct,\n SnapResponseWithInterfaceStruct,\n]);\n"]}
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunk265BMFM5js = require('../../../../chunk-265BMFM5.js');
4
- require('../../../../chunk-PHUTP7NB.js');
5
-
6
-
7
- exports.getGetLocaleMethodImplementation = _chunk265BMFM5js.getGetLocaleMethodImplementation;
8
- //# sourceMappingURL=get-locale.js.map
@@ -1,8 +0,0 @@
1
- import {
2
- getGetLocaleMethodImplementation
3
- } from "../../../../chunk-KSIBNOB2.mjs";
4
- import "../../../../chunk-JMDSN227.mjs";
5
- export {
6
- getGetLocaleMethodImplementation
7
- };
8
- //# sourceMappingURL=get-locale.mjs.map
@@ -1,14 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkRAMAN5RMjs = require('../../../../chunk-RAMAN5RM.js');
4
- require('../../../../chunk-VHJZERIC.js');
5
- require('../../../../chunk-WMLSD6B5.js');
6
- require('../../../../chunk-PZDTZGSI.js');
7
- require('../../../../chunk-LACTK6EO.js');
8
- require('../../../../chunk-2YE2P5BZ.js');
9
- require('../../../../chunk-LBC2OGSN.js');
10
- require('../../../../chunk-PHUTP7NB.js');
11
-
12
-
13
- exports.getShowDialogImplementation = _chunkRAMAN5RMjs.getShowDialogImplementation;
14
- //# sourceMappingURL=show-dialog.js.map
@@ -1,14 +0,0 @@
1
- import {
2
- getShowDialogImplementation
3
- } from "../../../../chunk-ORO3T6BU.mjs";
4
- import "../../../../chunk-RQKT6BQ2.mjs";
5
- import "../../../../chunk-3M4GRUMH.mjs";
6
- import "../../../../chunk-74TIKA2T.mjs";
7
- import "../../../../chunk-H2464AXT.mjs";
8
- import "../../../../chunk-LB4R3BUA.mjs";
9
- import "../../../../chunk-MPZOXW6I.mjs";
10
- import "../../../../chunk-JMDSN227.mjs";
11
- export {
12
- getShowDialogImplementation
13
- };
14
- //# sourceMappingURL=show-dialog.mjs.map
@@ -1,9 +0,0 @@
1
- import type { SimulationOptions } from '../../options';
2
- /**
3
- * Get the implementation of the `getLocale` hook.
4
- *
5
- * @param options - The simulation options.
6
- * @param options.locale - The locale to use.
7
- * @returns The implementation of the `getLocale` hook.
8
- */
9
- export declare function getGetLocaleMethodImplementation({ locale, }: SimulationOptions): () => Promise<string>;
@@ -1,9 +0,0 @@
1
- import type { DialogType } from '@metamask/snaps-sdk';
2
- import type { RunSagaFunction } from '../../store';
3
- /**
4
- * Get the implementation of the `showDialog` hook.
5
- *
6
- * @param runSaga - The function to run a saga outside the usual Redux flow.
7
- * @returns The implementation of the `showDialog` hook.
8
- */
9
- export declare function getShowDialogImplementation(runSaga: RunSagaFunction): (_snapId: string, type: DialogType, id: string, _placeholder?: string | undefined) => Promise<any>;