@metamask/snaps-jest 8.1.3 → 8.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (203) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/README.md +2 -2
  3. package/dist/chunk-24CGIQLL.mjs +30 -0
  4. package/dist/chunk-24CGIQLL.mjs.map +1 -0
  5. package/dist/{chunk-T2PHS5FY.js → chunk-2RJYSYUB.js} +2 -2
  6. package/dist/chunk-2RJYSYUB.js.map +1 -0
  7. package/dist/{chunk-KNJNL723.mjs → chunk-3J2IBWXV.mjs} +2 -2
  8. package/dist/{chunk-EDFQDZNY.js → chunk-3NP6BDGK.js} +50 -17
  9. package/dist/chunk-3NP6BDGK.js.map +1 -0
  10. package/dist/{chunk-AFA4KKWW.mjs → chunk-6JPBXAHM.mjs} +250 -47
  11. package/dist/chunk-6JPBXAHM.mjs.map +1 -0
  12. package/dist/{chunk-VXPCUDBI.js → chunk-6V6MFT67.js} +8 -6
  13. package/dist/chunk-6V6MFT67.js.map +1 -0
  14. package/dist/{chunk-6V5GEUDO.mjs → chunk-7PCHIR6O.mjs} +7 -37
  15. package/dist/chunk-7PCHIR6O.mjs.map +1 -0
  16. package/dist/{chunk-2OHD2VKS.js → chunk-AMAL4SJH.js} +11 -37
  17. package/dist/chunk-AMAL4SJH.js.map +1 -0
  18. package/dist/{chunk-HOI6FPLR.mjs → chunk-C26TYXXD.mjs} +9 -9
  19. package/dist/chunk-C26TYXXD.mjs.map +1 -0
  20. package/dist/{chunk-K55LIE3W.mjs → chunk-CACRY3TX.mjs} +3 -3
  21. package/dist/{chunk-PZDTZGSI.js → chunk-D653LBAY.js} +1 -1
  22. package/dist/chunk-D653LBAY.js.map +1 -0
  23. package/dist/chunk-DUVKGPX5.js +509 -0
  24. package/dist/chunk-DUVKGPX5.js.map +1 -0
  25. package/dist/{chunk-IH7UNS5A.mjs → chunk-G333FBBL.mjs} +6 -4
  26. package/dist/chunk-G333FBBL.mjs.map +1 -0
  27. package/dist/{chunk-YNUVT3HC.js → chunk-GLPGOEVE.js} +4 -4
  28. package/dist/chunk-GLPGOEVE.js.map +1 -0
  29. package/dist/chunk-IWJ4HKDR.mjs +50 -0
  30. package/dist/chunk-IWJ4HKDR.mjs.map +1 -0
  31. package/dist/{chunk-WMLSD6B5.js → chunk-K7MK6LQU.js} +3 -3
  32. package/dist/{chunk-B73P64TE.mjs → chunk-KOPPL55J.mjs} +2 -2
  33. package/dist/chunk-KOPPL55J.mjs.map +1 -0
  34. package/dist/{chunk-XKJHFUHE.js → chunk-KPRLFCKD.js} +4 -2
  35. package/dist/chunk-KPRLFCKD.js.map +1 -0
  36. package/dist/{chunk-3FDEYMQU.js → chunk-LPMHPAZK.js} +54 -14
  37. package/dist/chunk-LPMHPAZK.js.map +1 -0
  38. package/dist/{chunk-GG2BCPQH.mjs → chunk-LSKT2AUS.mjs} +5 -3
  39. package/dist/chunk-LSKT2AUS.mjs.map +1 -0
  40. package/dist/{chunk-6KXCBUNZ.mjs → chunk-LVNNGMJ2.mjs} +3 -1
  41. package/dist/{chunk-6KXCBUNZ.mjs.map → chunk-LVNNGMJ2.mjs.map} +1 -1
  42. package/dist/{chunk-TMAWGVZP.mjs → chunk-OHRFO2BL.mjs} +7 -7
  43. package/dist/chunk-OHRFO2BL.mjs.map +1 -0
  44. package/dist/{chunk-JXAJWUVZ.js → chunk-OO6IVUCV.js} +5 -5
  45. package/dist/{chunk-3M4GRUMH.mjs → chunk-ORR7AE5X.mjs} +2 -2
  46. package/dist/{chunk-UPR3PTSA.mjs → chunk-PDOVVC74.mjs} +10 -36
  47. package/dist/chunk-PDOVVC74.mjs.map +1 -0
  48. package/dist/{chunk-E2BYTLOT.mjs → chunk-Q3I6P2ZF.mjs} +43 -10
  49. package/dist/chunk-Q3I6P2ZF.mjs.map +1 -0
  50. package/dist/chunk-QRVFWATH.mjs +14 -0
  51. package/dist/chunk-QRVFWATH.mjs.map +1 -0
  52. package/dist/{chunk-MBQHVBLA.js → chunk-QYHQ2WWX.js} +5 -5
  53. package/dist/chunk-QYHQ2WWX.js.map +1 -0
  54. package/dist/{chunk-XWGECIXI.js → chunk-RJNNNCZJ.js} +3 -3
  55. package/dist/{chunk-U3DVRTS2.mjs → chunk-ROCGQYSK.mjs} +46 -6
  56. package/dist/chunk-ROCGQYSK.mjs.map +1 -0
  57. package/dist/chunk-SNXRXX2O.js +30 -0
  58. package/dist/chunk-SNXRXX2O.js.map +1 -0
  59. package/dist/chunk-SW65QYFV.js +50 -0
  60. package/dist/chunk-SW65QYFV.js.map +1 -0
  61. package/dist/{chunk-44ARQBXS.js → chunk-WZ57PU2K.js} +6 -4
  62. package/dist/chunk-WZ57PU2K.js.map +1 -0
  63. package/dist/chunk-XP4YGQJA.js +14 -0
  64. package/dist/chunk-XP4YGQJA.js.map +1 -0
  65. package/dist/{chunk-KQBJQLZG.js → chunk-Y2U3ZPCK.js} +15 -45
  66. package/dist/chunk-Y2U3ZPCK.js.map +1 -0
  67. package/dist/{chunk-74TIKA2T.mjs → chunk-ZJQSGRNK.mjs} +1 -1
  68. package/dist/chunk-ZJQSGRNK.mjs.map +1 -0
  69. package/dist/environment.js +17 -17
  70. package/dist/environment.mjs +16 -16
  71. package/dist/helpers.js +30 -16
  72. package/dist/helpers.mjs +29 -15
  73. package/dist/index.js +32 -18
  74. package/dist/index.mjs +31 -17
  75. package/dist/internals/index.js +33 -21
  76. package/dist/internals/index.mjs +35 -23
  77. package/dist/internals/request.js +15 -15
  78. package/dist/internals/request.mjs +14 -14
  79. package/dist/internals/simulation/constants.js +4 -2
  80. package/dist/internals/simulation/constants.mjs +3 -1
  81. package/dist/internals/simulation/controllers.js +7 -7
  82. package/dist/internals/simulation/controllers.mjs +6 -6
  83. package/dist/internals/simulation/files.js +8 -2
  84. package/dist/internals/simulation/files.mjs +7 -1
  85. package/dist/internals/simulation/index.js +31 -19
  86. package/dist/internals/simulation/index.mjs +33 -21
  87. package/dist/internals/simulation/interface.js +15 -4
  88. package/dist/internals/simulation/interface.mjs +16 -5
  89. package/dist/internals/simulation/methods/hooks/get-preferences.js +8 -0
  90. package/dist/internals/simulation/methods/hooks/get-preferences.mjs +8 -0
  91. package/dist/internals/simulation/methods/hooks/index.js +5 -5
  92. package/dist/internals/simulation/methods/hooks/index.mjs +8 -8
  93. package/dist/internals/simulation/methods/hooks/notifications.js +2 -2
  94. package/dist/internals/simulation/methods/hooks/notifications.mjs +2 -2
  95. package/dist/internals/simulation/methods/hooks/request-user-approval.js +14 -0
  96. package/dist/internals/simulation/methods/hooks/request-user-approval.mjs +14 -0
  97. package/dist/internals/simulation/methods/hooks/state.js +2 -2
  98. package/dist/internals/simulation/methods/hooks/state.mjs +2 -2
  99. package/dist/internals/simulation/methods/index.js +6 -6
  100. package/dist/internals/simulation/methods/index.mjs +5 -5
  101. package/dist/internals/simulation/methods/specifications.js +6 -6
  102. package/dist/internals/simulation/methods/specifications.mjs +5 -5
  103. package/dist/internals/simulation/middleware/engine.js +3 -3
  104. package/dist/internals/simulation/middleware/engine.mjs +2 -2
  105. package/dist/internals/simulation/middleware/index.js +3 -3
  106. package/dist/internals/simulation/middleware/index.mjs +2 -2
  107. package/dist/internals/simulation/options.js +3 -3
  108. package/dist/internals/simulation/options.mjs +2 -2
  109. package/dist/internals/simulation/simulation.js +13 -12
  110. package/dist/internals/simulation/simulation.mjs +12 -11
  111. package/dist/internals/simulation/store/index.js +3 -3
  112. package/dist/internals/simulation/store/index.mjs +2 -2
  113. package/dist/internals/simulation/store/store.js +3 -3
  114. package/dist/internals/simulation/store/store.mjs +2 -2
  115. package/dist/internals/simulation/store/ui.js +2 -2
  116. package/dist/internals/simulation/store/ui.mjs +1 -1
  117. package/dist/internals/structs.js +2 -2
  118. package/dist/internals/structs.mjs +1 -1
  119. package/dist/matchers.js +16 -18
  120. package/dist/matchers.mjs +15 -17
  121. package/dist/options.js +2 -2
  122. package/dist/options.mjs +1 -1
  123. package/dist/setup.js +15 -15
  124. package/dist/setup.mjs +15 -15
  125. package/dist/tsconfig.build.tsbuildinfo +1 -1
  126. package/dist/types/helpers.d.ts +43 -1
  127. package/dist/types/internals/request.d.ts +3 -2
  128. package/dist/types/internals/server.d.ts +1 -1
  129. package/dist/types/internals/simulation/constants.d.ts +4 -0
  130. package/dist/types/internals/simulation/controllers.d.ts +4 -4
  131. package/dist/types/internals/simulation/files.d.ts +36 -0
  132. package/dist/types/internals/simulation/interface.d.ts +70 -8
  133. package/dist/types/internals/simulation/methods/hooks/get-preferences.d.ts +13 -0
  134. package/dist/types/internals/simulation/methods/hooks/index.d.ts +2 -2
  135. package/dist/types/internals/simulation/methods/hooks/request-user-approval.d.ts +15 -0
  136. package/dist/types/internals/simulation/methods/specifications.d.ts +2 -2
  137. package/dist/types/internals/simulation/middleware/engine.d.ts +1 -1
  138. package/dist/types/internals/simulation/middleware/internal-methods/accounts.d.ts +1 -1
  139. package/dist/types/internals/simulation/middleware/internal-methods/middleware.d.ts +1 -1
  140. package/dist/types/internals/simulation/options.d.ts +10 -8
  141. package/dist/types/internals/simulation/simulation.d.ts +8 -5
  142. package/dist/types/internals/simulation/store/mocks.d.ts +2 -2
  143. package/dist/types/internals/simulation/store/notifications.d.ts +2 -2
  144. package/dist/types/internals/simulation/store/state.d.ts +1 -1
  145. package/dist/types/internals/simulation/store/store.d.ts +4 -4
  146. package/dist/types/internals/simulation/store/ui.d.ts +4 -3
  147. package/dist/types/internals/structs.d.ts +41 -41
  148. package/dist/types/matchers.d.ts +0 -10
  149. package/dist/types/options.d.ts +7 -7
  150. package/dist/types/types.d.ts +91 -20
  151. package/package.json +18 -16
  152. package/dist/chunk-265BMFM5.js +0 -13
  153. package/dist/chunk-265BMFM5.js.map +0 -1
  154. package/dist/chunk-2OHD2VKS.js.map +0 -1
  155. package/dist/chunk-3FDEYMQU.js.map +0 -1
  156. package/dist/chunk-44ARQBXS.js.map +0 -1
  157. package/dist/chunk-6V5GEUDO.mjs.map +0 -1
  158. package/dist/chunk-74TIKA2T.mjs.map +0 -1
  159. package/dist/chunk-AFA4KKWW.mjs.map +0 -1
  160. package/dist/chunk-B73P64TE.mjs.map +0 -1
  161. package/dist/chunk-E2BYTLOT.mjs.map +0 -1
  162. package/dist/chunk-EDFQDZNY.js.map +0 -1
  163. package/dist/chunk-GG2BCPQH.mjs.map +0 -1
  164. package/dist/chunk-HOI6FPLR.mjs.map +0 -1
  165. package/dist/chunk-IH7UNS5A.mjs.map +0 -1
  166. package/dist/chunk-KQBJQLZG.js.map +0 -1
  167. package/dist/chunk-KSIBNOB2.mjs +0 -13
  168. package/dist/chunk-KSIBNOB2.mjs.map +0 -1
  169. package/dist/chunk-MBQHVBLA.js.map +0 -1
  170. package/dist/chunk-ORO3T6BU.mjs +0 -24
  171. package/dist/chunk-ORO3T6BU.mjs.map +0 -1
  172. package/dist/chunk-PZDTZGSI.js.map +0 -1
  173. package/dist/chunk-R55KAAM4.js +0 -306
  174. package/dist/chunk-R55KAAM4.js.map +0 -1
  175. package/dist/chunk-RAMAN5RM.js +0 -24
  176. package/dist/chunk-RAMAN5RM.js.map +0 -1
  177. package/dist/chunk-T2PHS5FY.js.map +0 -1
  178. package/dist/chunk-TBDYQSRT.mjs +0 -16
  179. package/dist/chunk-TBDYQSRT.mjs.map +0 -1
  180. package/dist/chunk-TMAWGVZP.mjs.map +0 -1
  181. package/dist/chunk-TVD4SWH7.js +0 -16
  182. package/dist/chunk-TVD4SWH7.js.map +0 -1
  183. package/dist/chunk-U3DVRTS2.mjs.map +0 -1
  184. package/dist/chunk-UPR3PTSA.mjs.map +0 -1
  185. package/dist/chunk-VXPCUDBI.js.map +0 -1
  186. package/dist/chunk-XKJHFUHE.js.map +0 -1
  187. package/dist/chunk-YNUVT3HC.js.map +0 -1
  188. package/dist/internals/simulation/methods/hooks/get-locale.js +0 -8
  189. package/dist/internals/simulation/methods/hooks/get-locale.mjs +0 -8
  190. package/dist/internals/simulation/methods/hooks/show-dialog.js +0 -14
  191. package/dist/internals/simulation/methods/hooks/show-dialog.mjs +0 -14
  192. package/dist/types/internals/simulation/methods/hooks/get-locale.d.ts +0 -9
  193. package/dist/types/internals/simulation/methods/hooks/show-dialog.d.ts +0 -9
  194. /package/dist/{chunk-KNJNL723.mjs.map → chunk-3J2IBWXV.mjs.map} +0 -0
  195. /package/dist/{chunk-K55LIE3W.mjs.map → chunk-CACRY3TX.mjs.map} +0 -0
  196. /package/dist/{chunk-WMLSD6B5.js.map → chunk-K7MK6LQU.js.map} +0 -0
  197. /package/dist/{chunk-JXAJWUVZ.js.map → chunk-OO6IVUCV.js.map} +0 -0
  198. /package/dist/{chunk-3M4GRUMH.mjs.map → chunk-ORR7AE5X.mjs.map} +0 -0
  199. /package/dist/{chunk-XWGECIXI.js.map → chunk-RJNNNCZJ.js.map} +0 -0
  200. /package/dist/internals/simulation/methods/hooks/{get-locale.js.map → get-preferences.js.map} +0 -0
  201. /package/dist/internals/simulation/methods/hooks/{get-locale.mjs.map → get-preferences.mjs.map} +0 -0
  202. /package/dist/internals/simulation/methods/hooks/{show-dialog.js.map → request-user-approval.js.map} +0 -0
  203. /package/dist/internals/simulation/methods/hooks/{show-dialog.mjs.map → request-user-approval.mjs.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/interface.ts"],"names":["content"],"mappings":";;;;;;;AAOA,SAAS,YAAY,oBAAoB,cAAc;AAEvD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB;AAG5B,SAAS,MAAM,KAAK,QAAQ,YAAY;AAgBjC,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,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F;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAWO,UAAU,aACf,SACA,QACA,qBAC6B;AAC7B,QAAM,EAAE,MAAM,IAAI,QAAQ,IAAI,MAAM;AAAA,IAClC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,QAAM,mBAAmB;AAAA,IACvB,cAAc,OAAO,SAAiB;AACpC,YAAM,aAAa,qBAAqB,IAAI,SAAS,QAAQ,IAAI;AAAA,IACnE;AAAA,IACA,aAAa,OAAO,MAAc,UAAkB;AAClD,YAAM,YAAY,qBAAqB,IAAI,SAAS,QAAQ,MAAM,KAAK;AAAA,IACzE;AAAA,IACA,kBAAkB,OAAO,MAAc,UAAkB;AACvD,YAAM;AAAA,QACJ;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO,qBAAqB,SAAS,MAAM,SAAS,gBAAgB;AACtE","sourcesContent":["import type {\n FormState,\n InterfaceContext,\n InterfaceState,\n SnapId,\n UserInputEvent,\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 { 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 { SnapInterface, SnapInterfaceActions } from '../../types';\nimport type { RootControllerMessenger } from './controllers';\nimport type { Interface, RunSagaFunction } from './store';\nimport { getCurrentInterface, resolveInterface, setInterface } from './store';\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',\n `Expected an element of type \"Button\", but found \"${result.element.type}\".`,\n );\n\n const { state, context } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n // Button click events are always triggered.\n await handleEvent(\n controllerMessenger,\n snapId,\n id,\n {\n type: UserInputEventType.ButtonClickEvent,\n name: result.element.props.name,\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 Record<string, string | null>,\n },\n context,\n );\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 | 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 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 { type, id, content } = yield call(\n getStoredInterface,\n controllerMessenger,\n snapId,\n );\n\n const interfaceActions = {\n clickElement: async (name: string) => {\n await clickElement(controllerMessenger, id, content, snapId, name);\n },\n typeInField: async (name: string, value: string) => {\n await typeInField(controllerMessenger, id, content, snapId, name, value);\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\n return getInterfaceResponse(runSaga, type, content, interfaceActions);\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,16 +0,0 @@
1
- // src/internals/simulation/files.ts
2
- import { AuxiliaryFileEncoding } from "@metamask/snaps-sdk";
3
- import { encodeAuxiliaryFile, normalizeRelative } from "@metamask/snaps-utils";
4
- async function getSnapFile(files, path, encoding = AuxiliaryFileEncoding.Base64) {
5
- const normalizedPath = normalizeRelative(path);
6
- const base64 = files.find((file) => file.path === normalizedPath)?.toString("base64");
7
- if (!base64) {
8
- return null;
9
- }
10
- return await encodeAuxiliaryFile(base64, encoding);
11
- }
12
-
13
- export {
14
- getSnapFile
15
- };
16
- //# sourceMappingURL=chunk-TBDYQSRT.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/files.ts"],"sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport type { VirtualFile } from '@metamask/snaps-utils';\nimport { encodeAuxiliaryFile, normalizeRelative } from '@metamask/snaps-utils';\n\n/**\n * Get a statically defined Snap file from an array of files.\n *\n * @param files - The Snap files.\n * @param path - The file path.\n * @param encoding - The requested file encoding.\n * @returns The file in the requested encoding if found, otherwise null.\n */\nexport async function getSnapFile(\n files: VirtualFile[],\n path: string,\n encoding: AuxiliaryFileEncoding = AuxiliaryFileEncoding.Base64,\n) {\n const normalizedPath = normalizeRelative(path);\n const base64 = files\n .find((file) => file.path === normalizedPath)\n ?.toString('base64');\n\n if (!base64) {\n return null;\n }\n\n return await encodeAuxiliaryFile(base64, encoding);\n}\n"],"mappings":";AAAA,SAAS,6BAA6B;AAEtC,SAAS,qBAAqB,yBAAyB;AAUvD,eAAsB,YACpB,OACA,MACA,WAAkC,sBAAsB,QACxD;AACA,QAAM,iBAAiB,kBAAkB,IAAI;AAC7C,QAAM,SAAS,MACZ,KAAK,CAAC,SAAS,KAAK,SAAS,cAAc,GAC1C,SAAS,QAAQ;AAErB,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,oBAAoB,QAAQ,QAAQ;AACnD;","names":[]}
@@ -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,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;","names":[]}
@@ -1,16 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/internals/simulation/files.ts
2
- var _snapssdk = require('@metamask/snaps-sdk');
3
- var _snapsutils = require('@metamask/snaps-utils');
4
- async function getSnapFile(files, path, encoding = _snapssdk.AuxiliaryFileEncoding.Base64) {
5
- const normalizedPath = _snapsutils.normalizeRelative.call(void 0, path);
6
- const base64 = files.find((file) => file.path === normalizedPath)?.toString("base64");
7
- if (!base64) {
8
- return null;
9
- }
10
- return await _snapsutils.encodeAuxiliaryFile.call(void 0, base64, encoding);
11
- }
12
-
13
-
14
-
15
- exports.getSnapFile = getSnapFile;
16
- //# sourceMappingURL=chunk-TVD4SWH7.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/files.ts"],"names":[],"mappings":";AAAA,SAAS,6BAA6B;AAEtC,SAAS,qBAAqB,yBAAyB;AAUvD,eAAsB,YACpB,OACA,MACA,WAAkC,sBAAsB,QACxD;AACA,QAAM,iBAAiB,kBAAkB,IAAI;AAC7C,QAAM,SAAS,MACZ,KAAK,CAAC,SAAS,KAAK,SAAS,cAAc,GAC1C,SAAS,QAAQ;AAErB,MAAI,CAAC,QAAQ;AACX,WAAO;AAAA,EACT;AAEA,SAAO,MAAM,oBAAoB,QAAQ,QAAQ;AACnD","sourcesContent":["import { AuxiliaryFileEncoding } from '@metamask/snaps-sdk';\nimport type { VirtualFile } from '@metamask/snaps-utils';\nimport { encodeAuxiliaryFile, normalizeRelative } from '@metamask/snaps-utils';\n\n/**\n * Get a statically defined Snap file from an array of files.\n *\n * @param files - The Snap files.\n * @param path - The file path.\n * @param encoding - The requested file encoding.\n * @returns The file in the requested encoding if found, otherwise null.\n */\nexport async function getSnapFile(\n files: VirtualFile[],\n path: string,\n encoding: AuxiliaryFileEncoding = AuxiliaryFileEncoding.Base64,\n) {\n const normalizedPath = normalizeRelative(path);\n const base64 = files\n .find((file) => file.path === normalizedPath)\n ?.toString('base64');\n\n if (!base64) {\n return null;\n }\n\n return await encodeAuxiliaryFile(base64, encoding);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/helpers.ts"],"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"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAEA,SAAS,aAAa,eAAe;AACrC,SAAS,cAAc,0BAA0B;AACjD,SAAS,cAAc;AAyBvB,IAAM,MAAM,mBAAmB,YAAY,SAAS;AASpD,SAAS,WAKP,QACA,SAC4D;AAC5D,MAAI,OAAO,WAAW,UAAU;AAC9B,WAAO,CAAC,QAAW,MAAM;AAAA,EAC3B;AAEA,SAAO,CAAC,QAAQ,OAAO;AACzB;AAOA,SAAS,8BACP,UAC+C;AAC/C,eAAa,UAAU,+BAA+B;AACxD;AAqIA,eAAsB,YAKpB,QACA,UAAgD,CAAC,GAClC;AACf,QAAM,kBAAkB,WAAW,QAAQ,OAAO;AAClD,QAAM;AAAA,IACJ,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF,IAAI,MAAM,eAAe,EAAE,YAAY,GAAG,eAAe;AAEzD,QAAM,gBAAgB,OACpB,YACuC;AACvC,QAAI,2BAA2B,OAAO;AAEtC,UAAM;AAAA,MACJ,QAAQ;AAAA,MACR;AAAA,MACA,GAAG;AAAA,IACL,IAA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,UAAI,sBAAsB;AAE1B,YAAM,WAAW,MAAM,cAAc;AAAA,QACnC,QAAQ;AAAA,QACR;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,SAAS,YAAY;AAAA,QACrB,SAAS;AAAA,UACP,QAAQ;AAAA,QACV;AAAA,MACF,CAAC;AAED,oCAA8B,QAAQ;AAEtC,aAAO;AAAA,IACT;AAAA,IAEA,YAAY,MAA0B;AACpC,UAAI,gCAAgC,IAAI;AAExC,YAAM,EAAE,QAAQ,OAAO,IAAI,OAAO,MAAM,wBAAwB;AAChE,YAAM,SAAS,eAAe,EAAE,QAAQ,OAAO,CAAC,CAAC;AAEjD,aAAO;AAAA,QACL,SAAS;AACP,cAAI,kCAAkC,IAAI;AAE1C,gBAAM,SAAS,kBAAkB,MAAM,CAAC;AAAA,QAC1C;AAAA,MACF;AAAA,IACF;AAAA,IAEA,OAAO,YAAY;AACjB,UAAI,4BAA4B;AAChC;AAAA,QACE;AAAA,MACF;AAEA,YAAM,iBAAiB,kBAAkB;AAAA,IAC3C;AAAA,EACF;AACF;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/request.ts"],"sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n type SnapId,\n type JsonRpcError,\n type ComponentOrElement,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\nimport { is } from 'superstruct';\n\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from '../types';\nimport {\n clearNotifications,\n clickElement,\n getInterface,\n getNotifications,\n typeInField,\n selectInDropdown,\n} from './simulation';\nimport type { RunSagaFunction, Store } from './simulation';\nimport type { RootControllerMessenger } from './simulation/controllers';\nimport { SnapResponseStruct } from './structs';\n\nexport type HandleRequestOptions = {\n snapId: SnapId;\n store: Store;\n executionService: AbstractExecutionService<unknown>;\n handler: HandlerType;\n controllerMessenger: RootControllerMessenger;\n runSaga: RunSagaFunction;\n request: RequestOptions;\n};\n\n/**\n * Send a JSON-RPC request to the Snap, and wrap the response in a\n * {@link SnapResponse} object.\n *\n * @param options - The request options.\n * @param options.snapId - The ID of the Snap to send the request to.\n * @param options.store - The Redux store.\n * @param options.executionService - The execution service to use to send the\n * request.\n * @param options.handler - The handler to use to send the request.\n * @param options.controllerMessenger - The controller messenger used to call actions.\n * @param options.runSaga - A function to run a saga outside the usual Redux\n * flow.\n * @param options.request - The request to send.\n * @param options.request.id - The ID of the request. If not provided, a random\n * ID will be generated.\n * @param options.request.origin - The origin of the request. Defaults to\n * `https://metamask.io`.\n * @returns The response, wrapped in a {@link SnapResponse} object.\n */\nexport function handleRequest({\n snapId,\n store,\n executionService,\n handler,\n controllerMessenger,\n runSaga,\n request: { id = nanoid(), origin = 'https://metamask.io', ...options },\n}: HandleRequestOptions): SnapRequest {\n const getInterfaceError = () => {\n throw new Error(\n 'Unable to get the interface from the Snap: The request to the Snap failed.',\n );\n };\n\n const promise = executionService\n .handleRpcRequest(snapId, {\n origin,\n handler,\n request: {\n jsonrpc: '2.0',\n id: 1,\n ...options,\n },\n })\n .then(async (result) => {\n const notifications = getNotifications(store.getState());\n store.dispatch(clearNotifications());\n\n try {\n const getInterfaceFn = await getInterfaceApi(\n result,\n snapId,\n controllerMessenger,\n );\n\n return {\n id: String(id),\n response: {\n result: getSafeJson(result),\n },\n notifications,\n ...(getInterfaceFn ? { getInterface: getInterfaceFn } : {}),\n };\n } catch (error) {\n const [unwrappedError] = unwrapError(error);\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }\n })\n .catch((error) => {\n const [unwrappedError] = unwrapError(error);\n\n return {\n id: String(id),\n response: {\n error: unwrappedError.serialize(),\n },\n notifications: [],\n getInterface: getInterfaceError,\n };\n }) as unknown as SnapRequest;\n\n promise.getInterface = async () => {\n const sagaPromise = runSaga(\n getInterface,\n runSaga,\n snapId,\n controllerMessenger,\n ).toPromise();\n const result = await Promise.race([promise, sagaPromise]);\n\n // If the request promise has resolved to an error, we should throw\n // instead of waiting for an interface that likely will never be displayed\n if (\n is(result, SnapResponseStruct) &&\n hasProperty(result.response, 'error')\n ) {\n throw new Error(\n `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${\n (result.response.error as JsonRpcError).message\n }`,\n );\n }\n\n return await sagaPromise;\n };\n\n return promise;\n}\n\n/**\n * Get the interface ID from the result if it's available or create a new interface if the result contains static components.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The interface ID or undefined if the result doesn't include content.\n */\nexport async function getInterfaceFromResult(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n) {\n if (isPlainObject(result) && hasProperty(result, 'id')) {\n return result.id as string;\n }\n\n if (isPlainObject(result) && hasProperty(result, 'content')) {\n assert(\n is(result.content, ComponentOrElementStruct),\n 'The Snap returned an invalid interface.',\n );\n const id = await controllerMessenger.call(\n 'SnapInterfaceController:createInterface',\n snapId,\n result.content as ComponentOrElement,\n );\n\n return id;\n }\n\n return undefined;\n}\n\n/**\n * Get the response content from the SnapInterfaceController and include the interaction methods.\n *\n * @param result - The handler result object.\n * @param snapId - The Snap ID.\n * @param controllerMessenger - The controller messenger.\n * @returns The content components if any.\n */\nexport async function getInterfaceApi(\n result: unknown,\n snapId: SnapId,\n controllerMessenger: RootControllerMessenger,\n): Promise<(() => SnapHandlerInterface) | undefined> {\n const interfaceId = await getInterfaceFromResult(\n result,\n snapId,\n controllerMessenger,\n );\n\n if (interfaceId) {\n return () => {\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n interfaceId,\n );\n\n return {\n content,\n clickElement: async (name) => {\n await clickElement(\n controllerMessenger,\n interfaceId,\n content,\n snapId,\n name,\n );\n },\n typeInField: async (name, value) => {\n await typeInField(\n controllerMessenger,\n interfaceId,\n content,\n snapId,\n name,\n value,\n );\n },\n selectInDropdown: async (name, value) => {\n await selectInDropdown(\n controllerMessenger,\n interfaceId,\n content,\n snapId,\n name,\n value,\n );\n },\n };\n };\n }\n\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;AACA;AAAA,EAIE;AAAA,OACK;AAEP,SAAS,mBAAmB;AAC5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AACvB,SAAS,UAAU;AAiDZ,SAAS,cAAc;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,SAAS,EAAE,KAAK,OAAO,GAAG,SAAS,uBAAuB,GAAG,QAAQ;AACvE,GAAsC;AACpC,QAAM,oBAAoB,MAAM;AAC9B,UAAM,IAAI;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,QAAM,UAAU,iBACb,iBAAiB,QAAQ;AAAA,IACxB;AAAA,IACA;AAAA,IACA,SAAS;AAAA,MACP,SAAS;AAAA,MACT,IAAI;AAAA,MACJ,GAAG;AAAA,IACL;AAAA,EACF,CAAC,EACA,KAAK,OAAO,WAAW;AACtB,UAAM,gBAAgB,iBAAiB,MAAM,SAAS,CAAC;AACvD,UAAM,SAAS,mBAAmB,CAAC;AAEnC,QAAI;AACF,YAAM,iBAAiB,MAAM;AAAA,QAC3B;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,aAAO;AAAA,QACL,IAAI,OAAO,EAAE;AAAA,QACb,UAAU;AAAA,UACR,QAAQ,YAAY,MAAM;AAAA,QAC5B;AAAA,QACA;AAAA,QACA,GAAI,iBAAiB,EAAE,cAAc,eAAe,IAAI,CAAC;AAAA,MAC3D;AAAA,IACF,SAAS,OAAO;AACd,YAAM,CAAC,cAAc,IAAI,YAAY,KAA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,IACA;AAAA,IACA;AAAA,EACF;AAEA,MAAI,aAAa;AACf,WAAO,MAAM;AACX,YAAM,EAAE,QAAQ,IAAI,oBAAoB;AAAA,QACtC;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,aAAO;AAAA,QACL;AAAA,QACA,cAAc,OAAO,SAAS;AAC5B,gBAAM;AAAA,YACJ;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,aAAa,OAAO,MAAM,UAAU;AAClC,gBAAM;AAAA,YACJ;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,QACA,kBAAkB,OAAO,MAAM,UAAU;AACvC,gBAAM;AAAA,YACJ;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;","names":[]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/options.ts"],"names":[],"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","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,"s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ACH;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>;