@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,12 +1,16 @@
1
1
  import {
2
2
  InterfaceStruct,
3
3
  SnapResponseStruct
4
- } from "./chunk-HOI6FPLR.mjs";
4
+ } from "./chunk-C26TYXXD.mjs";
5
5
 
6
6
  // src/matchers.ts
7
7
  import { expect } from "@jest/globals";
8
8
  import { isJSXElementUnsafe } from "@metamask/snaps-sdk/jsx";
9
- import { getJsxElementFromComponent } from "@metamask/snaps-utils";
9
+ import {
10
+ getJsxElementFromComponent,
11
+ serialiseJsx
12
+ } from "@metamask/snaps-utils";
13
+ import { is } from "@metamask/superstruct";
10
14
  import { hasProperty } from "@metamask/utils";
11
15
  import {
12
16
  EXPECTED_COLOR,
@@ -17,7 +21,6 @@ import {
17
21
  printWithType,
18
22
  RECEIVED_COLOR
19
23
  } from "jest-matcher-utils";
20
- import { is } from "superstruct";
21
24
  function assertActualIsSnapResponse(actual, matcherName, options) {
22
25
  if (!is(actual, SnapResponseStruct)) {
23
26
  throw new Error(
@@ -99,38 +102,6 @@ Expected type: ${this.utils.printExpected(type)}
99
102
  Received: ${this.utils.printReceived(notifications)}`;
100
103
  return { message, pass };
101
104
  };
102
- function serialiseProp(prop) {
103
- if (typeof prop === "string") {
104
- return `"${prop}"`;
105
- }
106
- return `{${JSON.stringify(prop)}}`;
107
- }
108
- function serialiseProps(props) {
109
- return Object.entries(props).filter(([key]) => key !== "children").sort(([a], [b]) => a.localeCompare(b)).map(([key, value]) => ` ${key}=${serialiseProp(value)}`).join("");
110
- }
111
- function serialiseJsx(node, indentation = 0) {
112
- if (Array.isArray(node)) {
113
- return node.map((child) => serialiseJsx(child, indentation)).join("");
114
- }
115
- const indent = " ".repeat(indentation);
116
- if (typeof node === "string") {
117
- return `${indent}${node}
118
- `;
119
- }
120
- if (!node) {
121
- return "";
122
- }
123
- const { type, props } = node;
124
- const trailingNewline = indentation > 0 ? "\n" : "";
125
- if (hasProperty(props, "children")) {
126
- const children = serialiseJsx(props.children, indentation + 1);
127
- return `${indent}<${type}${serialiseProps(
128
- props
129
- )}>
130
- ${children}${indent}</${type}>${trailingNewline}`;
131
- }
132
- return `${indent}<${type}${serialiseProps(props)} />${trailingNewline}`;
133
- }
134
105
  var toRenderLegacy = function(actual, expected) {
135
106
  assertHasInterface(actual, "toRender");
136
107
  const { content } = actual;
@@ -205,7 +176,6 @@ export {
205
176
  toRespondWith,
206
177
  toRespondWithError,
207
178
  toSendNotification,
208
- serialiseJsx,
209
179
  toRender
210
180
  };
211
- //# sourceMappingURL=chunk-MAT5SBM7.mjs.map
181
+ //# sourceMappingURL=chunk-7PCHIR6O.mjs.map
@@ -0,0 +1 @@
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 { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsxElementFromComponent,\n serialiseJsx,\n} from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\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';\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\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;AAQvB,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU;AAEnB,SAAS,mBAAmB;AAE5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAYP,SAAS,2BACP,QACA,aACA,SACgC;AAChC,MAAI,CAAC,GAAG,QAAQ,kBAAkB,GAAG;AACnC,UAAM,IAAI;AAAA,MACR;AAAA,QACE,YAAY,aAAa,QAAW,QAAW,OAAO;AAAA,QACtD,GAAG;AAAA,UACD;AAAA,QACF,CAAC;AAAA,QACD,cAAc,YAAY,QAAQ,aAAa;AAAA,MACjD;AAAA,IACF;AAAA,EACF;AACF;AAUA,SAAS,mBACP,QACA,aACA,SAC2C;AAC3C,MAAI,CAAC,GAAG,QAAQ,eAAe,KAAK,CAAC,OAAO,SAAS;AACnD,UAAM,IAAI;AAAA,MACR;AAAA,QACE,YAAY,aAAa,QAAW,QAAW,OAAO;AAAA,QACtD,GAAG,eAAe,UAAU,CAAC;AAAA,QAC7B,cAAc,YAAY,QAAQ,aAAa;AAAA,MACjD;AAAA,IACF;AAAA,EACF;AACF;AAUO,IAAM,gBAAmD,SAC9D,QACA,UACA;AACA,6BAA2B,QAAQ,eAAe;AAElD,QAAM,EAAE,SAAS,IAAI;AACrB,MAAI,YAAY,UAAU,OAAO,GAAG;AAClC,UAAMA,WAAU,MACd,GAAG,KAAK,MAAM,YAAY,gBAAgB,CAAC;AAAA;AAAA,qBACrB,KAAK,MAAM,cA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AA;AAAA,EACzC,KAAK,MAAM,cAAc,OAAO,CAAC;AAAA;AAAA;AAAA;AAAA,EACzB,UAAU;AAEtC,SAAO,EAAE,SAAS,KAAK;AACzB;AAEO,IAAM,WACX,SAAU,QAAQ,UAAU;AAC1B,qBAAmB,QAAQ,UAAU;AAErC,MAAI,CAAC,mBAAmB,QAAQ,GAAG;AACjC,WAAO,eAAe,KAAK,MAAM,QAAQ,QAAQ;AAAA,EACnD;AAEA,QAAM,EAAE,QAAQ,IAAI;AACpB,QAAM,OAAO,KAAK,OAAO,SAAS,QAAQ;AAK1C,QAAM,aAAa;AAAA,IACjB,aAAa,QAAQ;AAAA,IACrB,aAAa,OAAO;AAAA,EACtB;AAEA,QAAM,UAAU,OACZ,MACE,GAAG,KAAK,MAAM,YAAY,eAAe,CAAC;AAAA;AAAA;AAAA,EAC5B,eAAe,aAAa,QAAQ,CAAC,CAAC;AAAA;AAAA;AAAA,EACtC,eAAe,aAAa,OAAO,CAAC,CAAC;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,10 +1,10 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
2
 
3
3
 
4
- var _chunkGVTDUKXKjs = require('./chunk-GVTDUKXK.js');
4
+ var _chunkDUVKGPX5js = require('./chunk-DUVKGPX5.js');
5
5
 
6
6
 
7
- var _chunkYNUVT3HCjs = require('./chunk-YNUVT3HC.js');
7
+ var _chunkGLPGOEVEjs = require('./chunk-GLPGOEVE.js');
8
8
 
9
9
 
10
10
 
@@ -15,6 +15,7 @@ var _chunk2YE2P5BZjs = require('./chunk-2YE2P5BZ.js');
15
15
 
16
16
  var _snapssdk = require('@metamask/snaps-sdk');
17
17
  var _snapsutils = require('@metamask/snaps-utils');
18
+ var _superstruct = require('@metamask/superstruct');
18
19
 
19
20
 
20
21
 
@@ -22,7 +23,6 @@ var _snapsutils = require('@metamask/snaps-utils');
22
23
 
23
24
  var _utils = require('@metamask/utils');
24
25
  var _toolkit = require('@reduxjs/toolkit');
25
- var _superstruct = require('superstruct');
26
26
  function handleRequest({
27
27
  snapId,
28
28
  store,
@@ -86,13 +86,13 @@ function handleRequest({
86
86
  });
87
87
  promise.getInterface = async () => {
88
88
  const sagaPromise = runSaga(
89
- _chunkGVTDUKXKjs.getInterface,
89
+ _chunkDUVKGPX5js.getInterface,
90
90
  runSaga,
91
91
  snapId,
92
92
  controllerMessenger
93
93
  ).toPromise();
94
94
  const result = await Promise.race([promise, sagaPromise]);
95
- if (_superstruct.is.call(void 0, result, _chunkYNUVT3HCjs.SnapResponseStruct) && _utils.hasProperty.call(void 0, result.response, "error")) {
95
+ if (_superstruct.is.call(void 0, result, _chunkGLPGOEVEjs.SnapResponseStruct) && _utils.hasProperty.call(void 0, result.response, "error")) {
96
96
  throw new Error(
97
97
  `Unable to get the interface from the Snap: The returned interface may be invalid. The error message received was: ${result.response.error.message}`
98
98
  );
@@ -132,7 +132,7 @@ async function getInterfaceApi(result, snapId, controllerMessenger) {
132
132
  snapId,
133
133
  interfaceId
134
134
  );
135
- const actions = _chunkGVTDUKXKjs.getInterfaceActions.call(void 0, snapId, controllerMessenger, {
135
+ const actions = _chunkDUVKGPX5js.getInterfaceActions.call(void 0, snapId, controllerMessenger, {
136
136
  id: interfaceId,
137
137
  content
138
138
  });
@@ -150,4 +150,4 @@ async function getInterfaceApi(result, snapId, controllerMessenger) {
150
150
 
151
151
 
152
152
  exports.handleRequest = handleRequest; exports.getInterfaceFromResult = getInterfaceFromResult; exports.getInterfaceApi = getInterfaceApi;
153
- //# sourceMappingURL=chunk-4MAA7WGJ.js.map
153
+ //# sourceMappingURL=chunk-AMAL4SJH.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internals/request.ts"],"names":[],"mappings":";;;;;;;;;;;;;AACA;AAAA,EAEE;AAAA,OAGK;AAEP,SAAS,mBAAmB;AAC5B,SAAS,UAAU;AACnB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,cAAc;AA+ChB,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,KAAK;AAC1C,aAAO;AAAA,QACL,IAAI,OAAO,EAAE;AAAA,QACb,UAAU;AAAA,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YAAM,EAAE,QAAQ,IAAI,oBAAoB;AAAA,QACtC;AAAA,QACA;AAAA,QACA;AAAA,MACF;AAEA,YAAM,UAAU,oBAAoB,QAAQ,qBAAqB;AAAA,QAC/D,IAAI;AAAA,QACJ;AAAA,MACF,CAAC;AAED,aAAO;AAAA,QACL;AAAA,QACA,GAAG;AAAA,MACL;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT","sourcesContent":["import type { AbstractExecutionService } from '@metamask/snaps-controllers';\nimport {\n type ComponentOrElement,\n ComponentOrElementStruct,\n type JsonRpcError,\n type SnapId,\n} from '@metamask/snaps-sdk';\nimport type { HandlerType } from '@metamask/snaps-utils';\nimport { unwrapError } from '@metamask/snaps-utils';\nimport { is } from '@metamask/superstruct';\nimport {\n assert,\n getSafeJson,\n hasProperty,\n isPlainObject,\n} from '@metamask/utils';\nimport { nanoid } from '@reduxjs/toolkit';\n\nimport type {\n RequestOptions,\n SnapHandlerInterface,\n SnapRequest,\n} from '../types';\nimport type { RunSagaFunction, Store } from './simulation';\nimport {\n clearNotifications,\n getInterface,\n getInterfaceActions,\n getNotifications,\n} 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\n * 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 const actions = getInterfaceActions(snapId, controllerMessenger, {\n id: interfaceId,\n content,\n });\n\n return {\n content,\n ...actions,\n };\n };\n }\n\n return undefined;\n}\n"]}
@@ -1,13 +1,6 @@
1
1
  // src/internals/structs.ts
2
2
  import { NotificationType, enumValue } from "@metamask/snaps-sdk";
3
3
  import { JSXElementStruct } from "@metamask/snaps-sdk/jsx";
4
- import {
5
- bytesToHex,
6
- JsonStruct,
7
- StrictHexStruct,
8
- valueToBytes
9
- } from "@metamask/utils";
10
- import { randomBytes } from "crypto";
11
4
  import {
12
5
  array,
13
6
  assign,
@@ -25,7 +18,14 @@ import {
25
18
  any,
26
19
  func,
27
20
  type
28
- } from "superstruct";
21
+ } from "@metamask/superstruct";
22
+ import {
23
+ bytesToHex,
24
+ JsonStruct,
25
+ StrictHexStruct,
26
+ valueToBytes
27
+ } from "@metamask/utils";
28
+ import { randomBytes } from "crypto";
29
29
  var BytesLikeStruct = union([
30
30
  bigint(),
31
31
  number(),
@@ -237,4 +237,4 @@ export {
237
237
  SnapResponseWithInterfaceStruct,
238
238
  SnapResponseStruct
239
239
  };
240
- //# sourceMappingURL=chunk-HOI6FPLR.mjs.map
240
+ //# sourceMappingURL=chunk-C26TYXXD.mjs.map
@@ -0,0 +1 @@
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 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 '@metamask/superstruct';\nimport {\n bytesToHex,\n JsonStruct,\n StrictHexStruct,\n valueToBytes,\n} from '@metamask/utils';\nimport { randomBytes } from 'crypto';\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,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAC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A,IACf,MAAM;AAAA,MACJ,QAAQ,UAAU;AAAA,MAClB,QAAQ,eAAe;AAAA,MACvB,QAAQ,mBAAmB;AAAA,MAC3B,QAAQ,sBAAsB;AAAA,MAC9B,QAAQ,sBAAsB;AAAA,IAChC,CAAC;AAAA,IACD;AAAA,EACF;AACF,CAAC;AAEM,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,9 +1,9 @@
1
1
  import {
2
2
  getOptions
3
- } from "./chunk-B73P64TE.mjs";
3
+ } from "./chunk-KOPPL55J.mjs";
4
4
  import {
5
5
  handleInstallSnap
6
- } from "./chunk-O24GTINW.mjs";
6
+ } from "./chunk-Q3I6P2ZF.mjs";
7
7
  import {
8
8
  startServer
9
9
  } from "./chunk-SLU4FNKX.mjs";
@@ -101,4 +101,4 @@ export {
101
101
  SnapsEnvironment,
102
102
  environment_default
103
103
  };
104
- //# sourceMappingURL=chunk-NSMTFK33.mjs.map
104
+ //# sourceMappingURL=chunk-CACRY3TX.mjs.map
@@ -31,4 +31,4 @@ var getCurrentInterface = _toolkit.createSelector.call(void 0,
31
31
 
32
32
 
33
33
  exports.uiSlice = uiSlice; exports.resolveInterface = resolveInterface; exports.setInterface = setInterface; exports.closeInterface = closeInterface; exports.getCurrentInterface = getCurrentInterface;
34
- //# sourceMappingURL=chunk-PZDTZGSI.js.map
34
+ //# sourceMappingURL=chunk-D653LBAY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internals/simulation/store/ui.ts"],"names":[],"mappings":";AAGA,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 { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';\nimport 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: DialogApprovalTypes[DialogType | 'default'];\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"]}
@@ -6,9 +6,10 @@ var _chunkSW65QYFVjs = require('./chunk-SW65QYFV.js');
6
6
 
7
7
 
8
8
 
9
- var _chunkPZDTZGSIjs = require('./chunk-PZDTZGSI.js');
9
+ var _chunkD653LBAYjs = require('./chunk-D653LBAY.js');
10
10
 
11
11
  // src/internals/simulation/interface.ts
12
+ var _snapsrpcmethods = require('@metamask/snaps-rpc-methods');
12
13
  var _snapssdk = require('@metamask/snaps-sdk');
13
14
 
14
15
 
@@ -21,51 +22,70 @@ var _effects = require('redux-saga/effects');
21
22
  var MAX_FILE_SIZE = 1e7;
22
23
  function getInterfaceResponse(runSaga, type, content, interfaceActions) {
23
24
  switch (type) {
24
- case _snapssdk.DialogType.Alert:
25
+ case _snapsrpcmethods.DIALOG_APPROVAL_TYPES[_snapssdk.DialogType.Alert]:
25
26
  return {
26
27
  ...interfaceActions,
27
- type,
28
+ type: _snapssdk.DialogType.Alert,
28
29
  content,
29
30
  ok: resolveWith(runSaga, null)
30
31
  };
31
- case _snapssdk.DialogType.Confirmation:
32
+ case _snapsrpcmethods.DIALOG_APPROVAL_TYPES[_snapssdk.DialogType.Confirmation]:
32
33
  return {
33
34
  ...interfaceActions,
34
- type,
35
+ type: _snapssdk.DialogType.Confirmation,
35
36
  content,
36
37
  ok: resolveWith(runSaga, true),
37
38
  cancel: resolveWith(runSaga, false)
38
39
  };
39
- case _snapssdk.DialogType.Prompt:
40
+ case _snapsrpcmethods.DIALOG_APPROVAL_TYPES[_snapssdk.DialogType.Prompt]:
40
41
  return {
41
42
  ...interfaceActions,
42
- type,
43
+ type: _snapssdk.DialogType.Prompt,
43
44
  content,
44
45
  ok: resolveWithInput(runSaga),
45
46
  cancel: resolveWith(runSaga, null)
46
47
  };
48
+ case _snapsrpcmethods.DIALOG_APPROVAL_TYPES.default: {
49
+ const footer = getElementByType(content, "Footer");
50
+ if (!footer) {
51
+ return {
52
+ ...interfaceActions,
53
+ content,
54
+ ok: resolveWith(runSaga, null),
55
+ cancel: resolveWith(runSaga, null)
56
+ };
57
+ }
58
+ if (_snapsutils.getJsxChildren.call(void 0, footer).length === 1) {
59
+ return {
60
+ ...interfaceActions,
61
+ content,
62
+ cancel: resolveWith(runSaga, null)
63
+ };
64
+ }
65
+ return {
66
+ ...interfaceActions,
67
+ content
68
+ };
69
+ }
47
70
  default:
48
71
  throw new Error(`Unknown or unsupported dialog type: "${String(type)}".`);
49
72
  }
50
73
  }
74
+ function* resolveWithSaga(value) {
75
+ yield _effects.put.call(void 0, _chunkD653LBAYjs.resolveInterface.call(void 0, value));
76
+ }
51
77
  function resolveWith(runSaga, value) {
52
- function* resolveWithSaga() {
53
- yield _effects.put.call(void 0, _chunkPZDTZGSIjs.resolveInterface.call(void 0, value));
54
- }
55
78
  return async () => {
56
- await runSaga(resolveWithSaga).toPromise();
79
+ await runSaga(resolveWithSaga, value).toPromise();
57
80
  };
58
81
  }
59
82
  function resolveWithInput(runSaga) {
60
- function* resolveWithSaga(value) {
61
- yield _effects.put.call(void 0, _chunkPZDTZGSIjs.resolveInterface.call(void 0, value));
62
- }
63
83
  return async (value = "") => {
64
84
  await runSaga(resolveWithSaga, value).toPromise();
65
85
  };
66
86
  }
67
87
  function* getStoredInterface(controllerMessenger, snapId) {
68
- const currentInterface = yield _effects.select.call(void 0, _chunkPZDTZGSIjs.getCurrentInterface);
88
+ const currentInterface = yield _effects.select.call(void 0, _chunkD653LBAYjs.getCurrentInterface);
69
89
  if (currentInterface) {
70
90
  const { content: content2 } = controllerMessenger.call(
71
91
  "SnapInterfaceController:getInterface",
@@ -74,7 +94,7 @@ function* getStoredInterface(controllerMessenger, snapId) {
74
94
  );
75
95
  return { ...currentInterface, content: content2 };
76
96
  }
77
- const { payload } = yield _effects.take.call(void 0, _chunkPZDTZGSIjs.setInterface.type);
97
+ const { payload } = yield _effects.take.call(void 0, _chunkD653LBAYjs.setInterface.type);
78
98
  const { content } = controllerMessenger.call(
79
99
  "SnapInterfaceController:getInterface",
80
100
  snapId,
@@ -111,6 +131,14 @@ function getElement(content, name) {
111
131
  return void 0;
112
132
  });
113
133
  }
134
+ function getElementByType(content, type) {
135
+ return _snapsutils.walkJsx.call(void 0, content, (element) => {
136
+ if (element.type === type) {
137
+ return element;
138
+ }
139
+ return void 0;
140
+ });
141
+ }
114
142
  async function handleEvent(controllerMessenger, snapId, id, event, context) {
115
143
  try {
116
144
  await controllerMessenger.call(
@@ -304,6 +332,53 @@ async function selectInDropdown(controllerMessenger, id, content, snapId, name,
304
332
  }
305
333
  });
306
334
  }
335
+ async function selectFromRadioGroup(controllerMessenger, id, content, snapId, name, value) {
336
+ const result = getElement(content, name);
337
+ _snapssdk.assert.call(void 0,
338
+ result !== void 0,
339
+ `Could not find an element in the interface with the name "${name}".`
340
+ );
341
+ _snapssdk.assert.call(void 0,
342
+ result.element.type === "RadioGroup",
343
+ `Expected an element of type "RadioGroup", but found "${result.element.type}".`
344
+ );
345
+ const options = _snapsutils.getJsxChildren.call(void 0, result.element);
346
+ const selectedOption = options.find(
347
+ (option) => _utils.hasProperty.call(void 0, option.props, "value") && option.props.value === value
348
+ );
349
+ _snapssdk.assert.call(void 0,
350
+ selectedOption !== void 0,
351
+ `The RadioGroup with the name "${name}" does not contain "${value}".`
352
+ );
353
+ const { state, context } = controllerMessenger.call(
354
+ "SnapInterfaceController:getInterface",
355
+ snapId,
356
+ id
357
+ );
358
+ const newState = mergeValue(state, name, value, result.form);
359
+ controllerMessenger.call(
360
+ "SnapInterfaceController:updateInterfaceState",
361
+ id,
362
+ newState
363
+ );
364
+ await controllerMessenger.call("ExecutionService:handleRpcRequest", snapId, {
365
+ origin: "",
366
+ handler: _snapsutils.HandlerType.OnUserInput,
367
+ request: {
368
+ jsonrpc: "2.0",
369
+ method: " ",
370
+ params: {
371
+ event: {
372
+ type: _snapssdk.UserInputEventType.InputChangeEvent,
373
+ name: result.element.props.name,
374
+ value
375
+ },
376
+ id,
377
+ context
378
+ }
379
+ }
380
+ });
381
+ }
307
382
  function getFormattedFileSize(size) {
308
383
  return `${(size / 1e6).toFixed(2)} MB`;
309
384
  }
@@ -375,6 +450,16 @@ function getInterfaceActions(snapId, controllerMessenger, { content, id }) {
375
450
  value
376
451
  );
377
452
  },
453
+ selectFromRadioGroup: async (name, value) => {
454
+ await selectFromRadioGroup(
455
+ controllerMessenger,
456
+ id,
457
+ content,
458
+ snapId,
459
+ name,
460
+ value
461
+ );
462
+ },
378
463
  uploadFile: async (name, file, options) => {
379
464
  await uploadFile(
380
465
  controllerMessenger,
@@ -417,5 +502,8 @@ function* getInterface(runSaga, snapId, controllerMessenger) {
417
502
 
418
503
 
419
504
 
420
- exports.getInterfaceResponse = getInterfaceResponse; exports.getElement = getElement; exports.clickElement = clickElement; exports.mergeValue = mergeValue; exports.typeInField = typeInField; exports.selectInDropdown = selectInDropdown; exports.uploadFile = uploadFile; exports.getInterfaceActions = getInterfaceActions; exports.getInterface = getInterface;
421
- //# sourceMappingURL=chunk-GVTDUKXK.js.map
505
+
506
+
507
+
508
+ exports.getInterfaceResponse = getInterfaceResponse; exports.resolveWithSaga = resolveWithSaga; exports.getElement = getElement; exports.getElementByType = getElementByType; exports.clickElement = clickElement; exports.mergeValue = mergeValue; exports.typeInField = typeInField; exports.selectInDropdown = selectInDropdown; exports.selectFromRadioGroup = selectFromRadioGroup; exports.uploadFile = uploadFile; exports.getInterfaceActions = getInterfaceActions; exports.getInterface = getInterface;
509
+ //# sourceMappingURL=chunk-DUVKGPX5.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internals/simulation/interface.ts"],"names":["content"],"mappings":";;;;;;;;;;;AACA,SAAS,6BAA6B;AAStC,SAAS,YAAY,oBAAoB,cAAc;AAGvD;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,sBAAsB,WAAW,KAAK;AACzC,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM,WAAW;AAAA,QACjB;AAAA,QACA,IAAI,YAAY,SAAS,IAAI;AAAA,MAC/B;AAAA,IAEF,KAAK,sBAAsB,WAAW,YAAY;AAChD,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM,WAAW;AAAA,QACjB;AAAA,QAEA,IAAI,YAAY,SAAS,IAAI;AAAA,QAC7B,QAAQ,YAAY,SAAS,KAAK;AAAA,MACpC;AAAA,IAEF,KAAK,sBAAsB,WAAW,MAAM;AAC1C,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM,WAAW;AAAA,QACjB;AAAA,QAEA,IAAI,iBAAiB,OAAO;AAAA,QAC5B,QAAQ,YAAY,SAAS,IAAI;AAAA,MACnC;AAAA,IAEF,KAAK,sBAAsB,SAAS;AAClC,YAAM,SAAS,iBAAgC,SAAS,QAAQ;AAGhE,UAAI,CAAC,QAAQ;AACX,eAAO;AAAA,UACL,GAAG;AAAA,UACH;AAAA,UAEA,IAAI,YAAY,SAAS,IAAI;AAAA,UAC7B,QAAQ,YAAY,SAAS,IAAI;AAAA,QACnC;AAAA,MACF;AAGA,UAAI,eAAe,MAAM,EAAE,WAAW,GAAG;AACvC,eAAO;AAAA,UACL,GAAG;AAAA,UACH;AAAA,UAEA,QAAQ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AA,MACT,QAAQ;AAAA,MACR,QAAQ;AAAA,QACN,OAAO;AAAA,UACL,MAAM,mBAAmB;AAAA,UACzB,MAAM,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,sBAAsB,OAAO,MAAc,UAAkB;AAC3D,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,qBACc;AACd,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 { DialogApprovalTypes } from '@metamask/snaps-rpc-methods';\nimport { DIALOG_APPROVAL_TYPES } from '@metamask/snaps-rpc-methods';\nimport 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 { FooterElement } from '@metamask/snaps-sdk/jsx';\nimport { type FormElement, type 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: DialogApprovalTypes[DialogType | 'default'],\n content: JSXElement,\n interfaceActions: SnapInterfaceActions,\n): SnapInterface {\n switch (type) {\n case DIALOG_APPROVAL_TYPES[DialogType.Alert]:\n return {\n ...interfaceActions,\n type: DialogType.Alert,\n content,\n ok: resolveWith(runSaga, null),\n };\n\n case DIALOG_APPROVAL_TYPES[DialogType.Confirmation]:\n return {\n ...interfaceActions,\n type: DialogType.Confirmation,\n content,\n\n ok: resolveWith(runSaga, true),\n cancel: resolveWith(runSaga, false),\n };\n\n case DIALOG_APPROVAL_TYPES[DialogType.Prompt]:\n return {\n ...interfaceActions,\n type: DialogType.Prompt,\n content,\n\n ok: resolveWithInput(runSaga),\n cancel: resolveWith(runSaga, null),\n };\n\n case DIALOG_APPROVAL_TYPES.default: {\n const footer = getElementByType<FooterElement>(content, 'Footer');\n\n // No Footer defined so we apply a default footer.\n if (!footer) {\n return {\n ...interfaceActions,\n content,\n\n ok: resolveWith(runSaga, null),\n cancel: resolveWith(runSaga, null),\n };\n }\n\n // Only one button in footer so we apply a default cancel button.\n if (getJsxChildren(footer).length === 1) {\n return {\n ...interfaceActions,\n content,\n\n cancel: resolveWith(runSaga, null),\n };\n }\n\n // We have two buttons in the footer so we assume the snap handles the approval of the interface.\n return {\n ...interfaceActions,\n content,\n };\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.\n *\n * @param value - The value to resolve the user interface with.\n * @yields Puts the resolve user interface action.\n */\nexport function* resolveWithSaga(value: unknown): SagaIterator {\n yield put(resolveInterface(value));\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 return async () => {\n await runSaga(resolveWithSaga, value).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 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/**\n * Get an element from a JSX tree with the given type.\n *\n * @param content - The interface content.\n * @param type - The element type.\n * @returns The element with the given type.\n */\nexport function getElementByType<Element extends JSXElement>(\n content: JSXElement,\n type: string,\n) {\n return walkJsx(content, (element) => {\n if (element.type === type) {\n return element as Element;\n }\n\n return undefined;\n });\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 * Choose an option with value from radio group 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 selectFromRadioGroup(\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 === 'RadioGroup',\n `Expected an element of type \"RadioGroup\", 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 RadioGroup 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 selectFromRadioGroup: async (name: string, value: string) => {\n await selectFromRadioGroup(\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 {\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,10 +1,10 @@
1
1
  import {
2
+ DEFAULT_CURRENCY,
2
3
  DEFAULT_LOCALE,
3
4
  DEFAULT_SRP
4
- } from "./chunk-6KXCBUNZ.mjs";
5
+ } from "./chunk-LVNNGMJ2.mjs";
5
6
 
6
7
  // src/internals/simulation/options.ts
7
- import { JsonStruct } from "@metamask/utils";
8
8
  import {
9
9
  create,
10
10
  defaulted,
@@ -13,8 +13,10 @@ import {
13
13
  optional,
14
14
  record,
15
15
  string
16
- } from "superstruct";
16
+ } from "@metamask/superstruct";
17
+ import { JsonStruct } from "@metamask/utils";
17
18
  var SimulationOptionsStruct = object({
19
+ currency: defaulted(optional(string()), DEFAULT_CURRENCY),
18
20
  secretRecoveryPhrase: defaulted(optional(string()), DEFAULT_SRP),
19
21
  locale: defaulted(optional(string()), DEFAULT_LOCALE),
20
22
  state: defaulted(optional(nullable(record(string(), JsonStruct))), null),
@@ -33,4 +35,4 @@ function getOptions(options) {
33
35
  export {
34
36
  getOptions
35
37
  };
36
- //# sourceMappingURL=chunk-IH7UNS5A.mjs.map
38
+ //# sourceMappingURL=chunk-G333FBBL.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/internals/simulation/options.ts"],"sourcesContent":["import type { Infer } from '@metamask/superstruct';\nimport {\n create,\n defaulted,\n nullable,\n object,\n optional,\n record,\n string,\n} from '@metamask/superstruct';\nimport { JsonStruct } from '@metamask/utils';\n\nimport { DEFAULT_CURRENCY, DEFAULT_LOCALE, DEFAULT_SRP } from './constants';\n\nconst SimulationOptionsStruct = object({\n currency: defaulted(optional(string()), DEFAULT_CURRENCY),\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":";;;;;;;AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB;AAI3B,IAAM,0BAA0B,OAAO;AAAA,EACrC,UAAU,UAAU,SAAS,OAAO,CAAC,GAAG,gBAAgB;AAAA,EACxD,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":[]}
@@ -6,8 +6,6 @@ var _jsx = require('@metamask/snaps-sdk/jsx');
6
6
 
7
7
 
8
8
 
9
- var _utils = require('@metamask/utils');
10
- var _crypto = require('crypto');
11
9
 
12
10
 
13
11
 
@@ -20,12 +18,14 @@ var _crypto = require('crypto');
20
18
 
21
19
 
22
20
 
21
+ var _superstruct = require('@metamask/superstruct');
23
22
 
24
23
 
25
24
 
26
25
 
27
26
 
28
- var _superstruct = require('superstruct');
27
+ var _utils = require('@metamask/utils');
28
+ var _crypto = require('crypto');
29
29
  var BytesLikeStruct = _superstruct.union.call(void 0, [
30
30
  _superstruct.bigint.call(void 0, ),
31
31
  _superstruct.number.call(void 0, ),
@@ -237,4 +237,4 @@ var SnapResponseStruct = _superstruct.union.call(void 0, [
237
237
 
238
238
 
239
239
  exports.TransactionOptionsStruct = TransactionOptionsStruct; exports.SignatureOptionsStruct = SignatureOptionsStruct; exports.SnapOptionsStruct = SnapOptionsStruct; exports.JsonRpcMockOptionsStruct = JsonRpcMockOptionsStruct; exports.InterfaceStruct = InterfaceStruct; exports.SnapResponseWithoutInterfaceStruct = SnapResponseWithoutInterfaceStruct; exports.SnapResponseWithInterfaceStruct = SnapResponseWithInterfaceStruct; exports.SnapResponseStruct = SnapResponseStruct;
240
- //# sourceMappingURL=chunk-YNUVT3HC.js.map
240
+ //# sourceMappingURL=chunk-GLPGOEVE.js.map