@metamask/snaps-jest 7.0.1 → 8.0.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 (54) hide show
  1. package/CHANGELOG.md +20 -1
  2. package/dist/{chunk-FIZAYEHV.js → chunk-2SBUXBSN.js} +87 -10
  3. package/dist/chunk-2SBUXBSN.js.map +1 -0
  4. package/dist/{chunk-7L5S3PID.js → chunk-573UCCBF.js} +5 -5
  5. package/dist/{chunk-LMCG5RIX.js → chunk-A3EYYEAY.js} +12 -12
  6. package/dist/{chunk-QPC6UJH7.mjs → chunk-B23SV5TL.mjs} +43 -27
  7. package/dist/chunk-B23SV5TL.mjs.map +1 -0
  8. package/dist/{chunk-YEVKBYKO.mjs → chunk-HOI6FPLR.mjs} +4 -7
  9. package/dist/chunk-HOI6FPLR.mjs.map +1 -0
  10. package/dist/{chunk-KR7CYXCR.js → chunk-IS4GY5A2.js} +41 -25
  11. package/dist/chunk-IS4GY5A2.js.map +1 -0
  12. package/dist/{chunk-ZJVA3AOC.mjs → chunk-QC3BL5R2.mjs} +2 -2
  13. package/dist/{chunk-BVGI3E45.mjs → chunk-QSIY5NAK.mjs} +84 -7
  14. package/dist/chunk-QSIY5NAK.mjs.map +1 -0
  15. package/dist/{chunk-3OEADJAL.mjs → chunk-R7PQRB54.mjs} +3 -3
  16. package/dist/{chunk-IDGD7TZ7.js → chunk-YNUVT3HC.js} +3 -6
  17. package/dist/chunk-YNUVT3HC.js.map +1 -0
  18. package/dist/environment.js +3 -3
  19. package/dist/environment.mjs +3 -3
  20. package/dist/helpers.js +5 -5
  21. package/dist/helpers.mjs +4 -4
  22. package/dist/index.js +5 -5
  23. package/dist/index.mjs +4 -4
  24. package/dist/internals/index.js +4 -4
  25. package/dist/internals/index.mjs +3 -3
  26. package/dist/internals/request.js +3 -3
  27. package/dist/internals/request.mjs +2 -2
  28. package/dist/internals/simulation/index.js +2 -2
  29. package/dist/internals/simulation/index.mjs +1 -1
  30. package/dist/internals/simulation/interface.js +2 -2
  31. package/dist/internals/simulation/interface.mjs +1 -1
  32. package/dist/internals/structs.js +2 -2
  33. package/dist/internals/structs.mjs +1 -1
  34. package/dist/matchers.js +7 -5
  35. package/dist/matchers.mjs +6 -4
  36. package/dist/setup.js +4 -4
  37. package/dist/setup.mjs +4 -4
  38. package/dist/tsconfig.build.tsbuildinfo +1 -1
  39. package/dist/types/global.d.ts +2 -2
  40. package/dist/types/internals/simulation/interface.d.ts +18 -8
  41. package/dist/types/internals/structs.d.ts +16 -152
  42. package/dist/types/matchers.d.ts +12 -2
  43. package/dist/types/types.d.ts +6 -5
  44. package/package.json +7 -7
  45. package/dist/chunk-BVGI3E45.mjs.map +0 -1
  46. package/dist/chunk-FIZAYEHV.js.map +0 -1
  47. package/dist/chunk-IDGD7TZ7.js.map +0 -1
  48. package/dist/chunk-KR7CYXCR.js.map +0 -1
  49. package/dist/chunk-QPC6UJH7.mjs.map +0 -1
  50. package/dist/chunk-YEVKBYKO.mjs.map +0 -1
  51. /package/dist/{chunk-7L5S3PID.js.map → chunk-573UCCBF.js.map} +0 -0
  52. /package/dist/{chunk-LMCG5RIX.js.map → chunk-A3EYYEAY.js.map} +0 -0
  53. /package/dist/{chunk-ZJVA3AOC.mjs.map → chunk-QC3BL5R2.mjs.map} +0 -0
  54. /package/dist/{chunk-3OEADJAL.mjs.map → chunk-R7PQRB54.mjs.map} +0 -0
@@ -1,4 +1,4 @@
1
- import type { Component, EnumToUnion, NotificationType } from '@metamask/snaps-sdk';
1
+ import type { EnumToUnion, NotificationType, ComponentOrElement } from '@metamask/snaps-sdk';
2
2
  interface SnapsMatchers {
3
3
  /**
4
4
  * Assert that the response is a JSON-RPC response with the given result. This
@@ -52,7 +52,7 @@ interface SnapsMatchers {
52
52
  * const ui = await response.getInterface();
53
53
  * expect(ui).toRender(panel([heading('Hello, world!')]));
54
54
  */
55
- toRender(component: Component): void;
55
+ toRender(component: ComponentOrElement): void;
56
56
  }
57
57
  declare module 'expect' {
58
58
  interface AsymmetricMatchers extends SnapsMatchers {
@@ -1,5 +1,6 @@
1
- import type { Button, Component, Input, InterfaceState, SnapId } from '@metamask/snaps-sdk';
1
+ import type { InterfaceState, SnapId } from '@metamask/snaps-sdk';
2
2
  import { DialogType } from '@metamask/snaps-sdk';
3
+ import type { JSXElement } from '@metamask/snaps-sdk/jsx';
3
4
  import { type SagaIterator } from 'redux-saga';
4
5
  import type { SnapInterface, SnapInterfaceActions } from '../../types';
5
6
  import type { RootControllerMessenger } from './controllers';
@@ -13,16 +14,25 @@ import type { RunSagaFunction } from './store';
13
14
  * @param interfaceActions - The actions to interact with the interface.
14
15
  * @returns The user interface object.
15
16
  */
16
- export declare function getInterfaceResponse(runSaga: RunSagaFunction, type: DialogType, content: Component, interfaceActions: SnapInterfaceActions): SnapInterface;
17
+ export declare function getInterfaceResponse(runSaga: RunSagaFunction, type: DialogType, content: JSXElement, interfaceActions: SnapInterfaceActions): SnapInterface;
17
18
  /**
18
- * Get a Button or an Input from an interface.
19
+ * A JSX element with a name.
20
+ */
21
+ export declare type NamedJSXElement = JSXElement & {
22
+ props: {
23
+ name: string;
24
+ };
25
+ };
26
+ /**
27
+ * Get an element from a JSX tree with the given name.
19
28
  *
20
29
  * @param content - The interface content.
21
30
  * @param name - The element name.
22
- * @returns An object containing the element and the form name if it's contained in a form, otherwise undefined.
31
+ * @returns An object containing the element and the form name if it's contained
32
+ * in a form, otherwise undefined.
23
33
  */
24
- export declare function getElement(content: Component, name: string): {
25
- element: Button | Input;
34
+ export declare function getElement(content: JSXElement, name: string): {
35
+ element: NamedJSXElement;
26
36
  form?: string;
27
37
  } | undefined;
28
38
  /**
@@ -34,7 +44,7 @@ export declare function getElement(content: Component, name: string): {
34
44
  * @param snapId - The Snap ID.
35
45
  * @param name - The element name.
36
46
  */
37
- export declare function clickElement(controllerMessenger: RootControllerMessenger, id: string, content: Component, snapId: SnapId, name: string): Promise<void>;
47
+ export declare function clickElement(controllerMessenger: RootControllerMessenger, id: string, content: JSXElement, snapId: SnapId, name: string): Promise<void>;
38
48
  /**
39
49
  * Merge a value in the interface state.
40
50
  *
@@ -55,7 +65,7 @@ export declare function mergeValue(state: InterfaceState, name: string, value: s
55
65
  * @param name - The element name.
56
66
  * @param value - The value to type in the element.
57
67
  */
58
- export declare function typeInField(controllerMessenger: RootControllerMessenger, id: string, content: Component, snapId: SnapId, name: string, value: string): Promise<void>;
68
+ export declare function typeInField(controllerMessenger: RootControllerMessenger, id: string, content: JSXElement, snapId: SnapId, name: string, value: string): Promise<void>;
59
69
  /**
60
70
  * Get a user interface object from a Snap.
61
71
  *
@@ -1,8 +1,8 @@
1
1
  export declare const TransactionOptionsStruct: import("superstruct").Struct<{
2
+ value: `0x${string}`;
2
3
  data: `0x${string}`;
3
4
  from: `0x${string}`;
4
5
  origin: string;
5
- value: `0x${string}`;
6
6
  chainId: string;
7
7
  to: `0x${string}`;
8
8
  gasLimit: `0x${string}`;
@@ -104,156 +104,20 @@ export declare const JsonRpcMockOptionsStruct: import("superstruct").Struct<{
104
104
  result: import("superstruct").Struct<import("@metamask/snaps-sdk").Json, unknown>;
105
105
  }>;
106
106
  export declare const InterfaceStruct: import("superstruct").Struct<{
107
- content?: import("@metamask/snaps-sdk").Panel | {
108
- type: import("@metamask/snaps-sdk").NodeType.Input;
109
- name: string;
110
- value?: string | undefined;
111
- error?: string | undefined;
112
- inputType?: "number" | "text" | "password" | undefined;
113
- placeholder?: string | undefined;
114
- label?: string | undefined;
115
- } | {
116
- value: string;
117
- type: import("@metamask/snaps-sdk").NodeType.Button;
118
- name?: string | undefined;
119
- variant?: "primary" | "secondary" | undefined;
120
- buttonType?: "button" | "submit" | undefined;
121
- } | {
122
- type: import("@metamask/snaps-sdk").NodeType.Form;
123
- name: string;
124
- children: ({
125
- type: import("@metamask/snaps-sdk").NodeType.Input;
126
- name: string;
127
- value?: string | undefined;
128
- error?: string | undefined;
129
- inputType?: "number" | "text" | "password" | undefined;
130
- placeholder?: string | undefined;
131
- label?: string | undefined;
132
- } | {
133
- value: string;
134
- type: import("@metamask/snaps-sdk").NodeType.Button;
135
- name?: string | undefined;
136
- variant?: "primary" | "secondary" | undefined;
137
- buttonType?: "button" | "submit" | undefined;
138
- })[];
139
- } | {
140
- value: string;
141
- type: import("@metamask/snaps-sdk").NodeType.Copyable;
142
- sensitive?: boolean | undefined;
143
- } | {
144
- type: import("@metamask/snaps-sdk").NodeType.Divider;
145
- } | {
146
- value: string;
147
- type: import("@metamask/snaps-sdk").NodeType.Heading;
148
- } | {
149
- value: string;
150
- type: import("@metamask/snaps-sdk").NodeType.Image;
151
- } | {
152
- type: import("@metamask/snaps-sdk").NodeType.Spinner;
153
- } | {
154
- value: string;
155
- type: import("@metamask/snaps-sdk").NodeType.Text;
156
- markdown?: boolean | undefined;
157
- } | {
158
- value: `0x${string}`;
159
- type: import("@metamask/snaps-sdk").NodeType.Address;
160
- } | {
161
- value: {
162
- value: string;
163
- type: import("@metamask/snaps-sdk").NodeType.Image;
164
- } | {
165
- value: string;
166
- type: import("@metamask/snaps-sdk").NodeType.Text;
167
- markdown?: boolean | undefined;
168
- } | {
169
- value: `0x${string}`;
170
- type: import("@metamask/snaps-sdk").NodeType.Address;
171
- };
172
- type: import("@metamask/snaps-sdk").NodeType.Row;
173
- label: string;
174
- variant?: "default" | "warning" | "critical" | undefined;
175
- } | undefined;
107
+ content?: import("@metamask/snaps-sdk/jsx-runtime").JSXElement | undefined;
176
108
  }, {
177
- content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
178
- type: import("@metamask/snaps-sdk").NodeType.Input;
179
- name: string;
180
- value?: string | undefined;
181
- error?: string | undefined;
182
- inputType?: "number" | "text" | "password" | undefined;
183
- placeholder?: string | undefined;
184
- label?: string | undefined;
185
- } | {
186
- value: string;
187
- type: import("@metamask/snaps-sdk").NodeType.Button;
188
- name?: string | undefined;
189
- variant?: "primary" | "secondary" | undefined;
190
- buttonType?: "button" | "submit" | undefined;
191
- } | {
192
- type: import("@metamask/snaps-sdk").NodeType.Form;
193
- name: string;
194
- children: ({
195
- type: import("@metamask/snaps-sdk").NodeType.Input;
196
- name: string;
197
- value?: string | undefined;
198
- error?: string | undefined;
199
- inputType?: "number" | "text" | "password" | undefined;
200
- placeholder?: string | undefined;
201
- label?: string | undefined;
202
- } | {
203
- value: string;
204
- type: import("@metamask/snaps-sdk").NodeType.Button;
205
- name?: string | undefined;
206
- variant?: "primary" | "secondary" | undefined;
207
- buttonType?: "button" | "submit" | undefined;
208
- })[];
209
- } | {
210
- value: string;
211
- type: import("@metamask/snaps-sdk").NodeType.Copyable;
212
- sensitive?: boolean | undefined;
213
- } | {
214
- type: import("@metamask/snaps-sdk").NodeType.Divider;
215
- } | {
216
- value: string;
217
- type: import("@metamask/snaps-sdk").NodeType.Heading;
218
- } | {
219
- value: string;
220
- type: import("@metamask/snaps-sdk").NodeType.Image;
221
- } | {
222
- type: import("@metamask/snaps-sdk").NodeType.Spinner;
223
- } | {
224
- value: string;
225
- type: import("@metamask/snaps-sdk").NodeType.Text;
226
- markdown?: boolean | undefined;
227
- } | {
228
- value: `0x${string}`;
229
- type: import("@metamask/snaps-sdk").NodeType.Address;
230
- } | {
231
- value: {
232
- value: string;
233
- type: import("@metamask/snaps-sdk").NodeType.Image;
234
- } | {
235
- value: string;
236
- type: import("@metamask/snaps-sdk").NodeType.Text;
237
- markdown?: boolean | undefined;
238
- } | {
239
- value: `0x${string}`;
240
- type: import("@metamask/snaps-sdk").NodeType.Address;
241
- };
242
- type: import("@metamask/snaps-sdk").NodeType.Row;
243
- label: string;
244
- variant?: "default" | "warning" | "critical" | undefined;
245
- } | undefined, null>;
109
+ content: import("superstruct").Struct<import("@metamask/snaps-sdk/jsx-runtime").JSXElement | undefined, null>;
246
110
  }>;
247
111
  export declare const SnapResponseWithoutInterfaceStruct: import("superstruct").Struct<{
112
+ id: string;
248
113
  response: {
249
114
  result: import("@metamask/snaps-sdk").Json;
250
115
  } | {
251
116
  error: import("@metamask/snaps-sdk").Json;
252
117
  };
253
- id: string;
254
118
  notifications: {
255
- message: string;
256
119
  type: "native" | "inApp";
120
+ message: string;
257
121
  id: string;
258
122
  }[];
259
123
  }, {
@@ -264,12 +128,12 @@ export declare const SnapResponseWithoutInterfaceStruct: import("superstruct").S
264
128
  error: import("@metamask/snaps-sdk").Json;
265
129
  }, null>;
266
130
  notifications: import("superstruct").Struct<{
267
- message: string;
268
131
  type: "native" | "inApp";
132
+ message: string;
269
133
  id: string;
270
134
  }[], import("superstruct").Struct<{
271
- message: string;
272
135
  type: "native" | "inApp";
136
+ message: string;
273
137
  id: string;
274
138
  }, {
275
139
  id: import("superstruct").Struct<string, null>;
@@ -278,33 +142,33 @@ export declare const SnapResponseWithoutInterfaceStruct: import("superstruct").S
278
142
  }>>;
279
143
  }>;
280
144
  export declare const SnapResponseWithInterfaceStruct: import("superstruct").Struct<{
145
+ id: string;
281
146
  response: {
282
147
  result: import("@metamask/snaps-sdk").Json;
283
148
  } | {
284
149
  error: import("@metamask/snaps-sdk").Json;
285
150
  };
286
- id: string;
287
151
  getInterface: Function;
288
152
  notifications: {
289
- message: string;
290
153
  type: "native" | "inApp";
154
+ message: string;
291
155
  id: string;
292
156
  }[];
293
157
  }, {
294
158
  getInterface: import("superstruct").Struct<Function, null>;
159
+ id: import("superstruct").Struct<string, null>;
295
160
  response: import("superstruct").Struct<{
296
161
  result: import("@metamask/snaps-sdk").Json;
297
162
  } | {
298
163
  error: import("@metamask/snaps-sdk").Json;
299
164
  }, null>;
300
- id: import("superstruct").Struct<string, null>;
301
165
  notifications: import("superstruct").Struct<{
302
- message: string;
303
166
  type: "native" | "inApp";
167
+ message: string;
304
168
  id: string;
305
169
  }[], import("superstruct").Struct<{
306
- message: string;
307
170
  type: "native" | "inApp";
171
+ message: string;
308
172
  id: string;
309
173
  }, {
310
174
  id: import("superstruct").Struct<string, null>;
@@ -313,28 +177,28 @@ export declare const SnapResponseWithInterfaceStruct: import("superstruct").Stru
313
177
  }>>;
314
178
  }>;
315
179
  export declare const SnapResponseStruct: import("superstruct").Struct<{
180
+ id: string;
316
181
  response: {
317
182
  result: import("@metamask/snaps-sdk").Json;
318
183
  } | {
319
184
  error: import("@metamask/snaps-sdk").Json;
320
185
  };
321
- id: string;
322
186
  notifications: {
323
- message: string;
324
187
  type: "native" | "inApp";
188
+ message: string;
325
189
  id: string;
326
190
  }[];
327
191
  } | {
192
+ id: string;
328
193
  response: {
329
194
  result: import("@metamask/snaps-sdk").Json;
330
195
  } | {
331
196
  error: import("@metamask/snaps-sdk").Json;
332
197
  };
333
- id: string;
334
198
  getInterface: Function;
335
199
  notifications: {
336
- message: string;
337
200
  type: "native" | "inApp";
201
+ message: string;
338
202
  id: string;
339
203
  }[];
340
204
  }, null>;
@@ -1,5 +1,6 @@
1
1
  import type { MatcherFunction } from '@jest/expect';
2
- import type { NotificationType, EnumToUnion, Component } from '@metamask/snaps-sdk';
2
+ import type { NotificationType, EnumToUnion, ComponentOrElement } from '@metamask/snaps-sdk';
3
+ import type { SnapNode } from '@metamask/snaps-sdk/jsx';
3
4
  import type { Json } from '@metamask/utils';
4
5
  /**
5
6
  * Check if a JSON-RPC response matches the expected value. This matcher is
@@ -24,4 +25,13 @@ export declare const toSendNotification: MatcherFunction<[
24
25
  expected: string,
25
26
  type?: EnumToUnion<NotificationType> | undefined
26
27
  ]>;
27
- export declare const toRender: MatcherFunction<[expected: Component]>;
28
+ /**
29
+ * Serialise a JSX node to a string.
30
+ *
31
+ * @param node - The JSX node.
32
+ * @param indentation - The indentation level. Defaults to `0`. This should not
33
+ * be set by the caller, as it is used for recursion.
34
+ * @returns The serialised JSX node.
35
+ */
36
+ export declare function serialiseJsx(node: SnapNode, indentation?: number): string;
37
+ export declare const toRender: MatcherFunction<[expected: ComponentOrElement]>;
@@ -1,4 +1,5 @@
1
- import type { Component, NotificationType, EnumToUnion } from '@metamask/snaps-sdk';
1
+ import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';
2
+ import type { JSXElement } from '@metamask/snaps-sdk/jsx';
2
3
  import type { InferMatching } from '@metamask/snaps-utils';
3
4
  import type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils';
4
5
  import type { Infer } from 'superstruct';
@@ -91,7 +92,7 @@ export declare type SnapAlertInterface = {
91
92
  /**
92
93
  * The content to show in the alert.
93
94
  */
94
- content: Component;
95
+ content: JSXElement;
95
96
  /**
96
97
  * Close the alert.
97
98
  */
@@ -108,7 +109,7 @@ export declare type SnapConfirmationInterface = {
108
109
  /**
109
110
  * The content to show in the confirmation.
110
111
  */
111
- content: Component;
112
+ content: JSXElement;
112
113
  /**
113
114
  * Close the confirmation.
114
115
  */
@@ -129,7 +130,7 @@ export declare type SnapPromptInterface = {
129
130
  /**
130
131
  * The content to show in the prompt.
131
132
  */
132
- content: Component;
133
+ content: JSXElement;
133
134
  /**
134
135
  * Close the prompt.
135
136
  *
@@ -285,7 +286,7 @@ export declare type Snap = {
285
286
  close(): Promise<void>;
286
287
  };
287
288
  export declare type SnapHandlerInterface = {
288
- content: Component;
289
+ content: JSXElement;
289
290
  } & SnapInterfaceActions;
290
291
  export declare type SnapResponseWithInterface = {
291
292
  id: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-jest",
3
- "version": "7.0.1",
3
+ "version": "8.0.0",
4
4
  "description": "A Jest preset for end-to-end testing MetaMask Snaps, including a Jest environment, and a set of Jest matchers.",
5
5
  "sideEffects": false,
6
6
  "exports": {
@@ -40,17 +40,17 @@
40
40
  "@jest/environment": "^29.5.0",
41
41
  "@jest/expect": "^29.5.0",
42
42
  "@jest/globals": "^29.5.0",
43
- "@metamask/base-controller": "^5.0.1",
43
+ "@metamask/base-controller": "^5.0.2",
44
44
  "@metamask/eth-json-rpc-middleware": "^12.1.0",
45
45
  "@metamask/json-rpc-engine": "^8.0.1",
46
46
  "@metamask/json-rpc-middleware-stream": "^7.0.1",
47
47
  "@metamask/key-tree": "^9.0.0",
48
48
  "@metamask/permission-controller": "^9.0.2",
49
- "@metamask/snaps-controllers": "^7.0.1",
50
- "@metamask/snaps-execution-environments": "^6.0.0",
51
- "@metamask/snaps-rpc-methods": "^8.0.0",
52
- "@metamask/snaps-sdk": "^4.0.1",
53
- "@metamask/snaps-utils": "^7.1.0",
49
+ "@metamask/snaps-controllers": "^8.1.0",
50
+ "@metamask/snaps-execution-environments": "^6.1.0",
51
+ "@metamask/snaps-rpc-methods": "^8.1.0",
52
+ "@metamask/snaps-sdk": "^4.1.0",
53
+ "@metamask/snaps-utils": "^7.3.0",
54
54
  "@metamask/utils": "^8.3.0",
55
55
  "@reduxjs/toolkit": "^1.9.5",
56
56
  "express": "^4.18.2",
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/matchers.ts"],"sourcesContent":["/* eslint-disable no-invalid-this */\n\n// Note: Because this file imports from `@jest/globals`, it can only be used in\n// a Jest environment. This is why it's not exported from the index file.\n\nimport type { MatcherFunction } from '@jest/expect';\nimport { expect } from '@jest/globals';\nimport type {\n NotificationType,\n EnumToUnion,\n Component,\n} from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\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\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\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. The\n // function only returns `null` if both the expected and actual values are\n // numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference as string}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference as string}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"],"mappings":";;;;;;AAMA,SAAS,cAAc;AAOvB,SAAS,mBAAmB;AAE5B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,UAAU;AAYnB,SAAS,2BACP,QACA,aACA,SACgC;AAChC,MAAI,CAAC,GAAG,QAAQ,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,SAC0C;AAC1C,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,cAAc,Q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AAC","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 Component,\n} from '@metamask/snaps-sdk';\nimport type { Json } from '@metamask/utils';\nimport { hasProperty } from '@metamask/utils';\nimport type { MatcherHintOptions } from 'jest-matcher-utils';\nimport {\n diff,\n matcherErrorMessage,\n matcherHint,\n printReceived,\n printWithType,\n RECEIVED_COLOR,\n} from 'jest-matcher-utils';\nimport { is } from 'superstruct';\n\nimport { InterfaceStruct, SnapResponseStruct } from './internals';\nimport type { SnapResponse } from './types';\n\n/**\n * Ensure that the actual value is a response from the `request` function.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertActualIsSnapResponse(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is SnapResponse {\n if (!is(actual, SnapResponseStruct)) {\n throw new Error(\n matcherErrorMessage(\n matcherHint(matcherName, undefined, undefined, options),\n `${RECEIVED_COLOR(\n 'received',\n )} value must be a response from the \\`request\\` function`,\n printWithType('Received', actual, printReceived),\n ),\n );\n }\n}\n\n/**\n * Ensure that the actual value is a response from the `request` function, and\n * that it has a `ui` property.\n *\n * @param actual - The actual value.\n * @param matcherName - The name of the matcher.\n * @param options - The matcher options.\n */\nfunction assertHasInterface(\n actual: unknown,\n matcherName: string,\n options?: MatcherHintOptions,\n): asserts actual is { content: Component } {\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\nexport const toRender: MatcherFunction<[expected: Component]> = function (\n actual,\n expected,\n) {\n assertHasInterface(actual, 'toRender');\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. The\n // function only returns `null` if both the expected and actual values are\n // numbers, bigints, or booleans, which is never the case here.\n const difference = diff(expected, content);\n\n const message = pass\n ? () =>\n `${this.utils.matcherHint('.not.toRender')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference as string}`\n : () =>\n `${this.utils.matcherHint('.toRender')}\\n\\n` +\n `Expected: ${this.utils.printExpected(expected)}\\n` +\n `Received: ${this.utils.printReceived(content)}` +\n `\\n\\nDifference:\\n\\n${difference as string}`;\n\n return { message, pass };\n};\n\nexpect.extend({\n toRespondWith,\n toRespondWithError,\n toSendNotification,\n toRender,\n});\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/structs.ts"],"names":[],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,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Hex,\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(ComponentStruct),\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 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/interface.ts"],"names":["content"],"mappings":";;;;;;;AASA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,aAAa,mBAAmB;AAGtD,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,YAAY,SAAS,IAAI;AAAA,QAC7B,QAAQ,YAAY,SAAS,KAAK;AAAA,MACpC;AAAA,IAEF,KAAK,WAAW;AACd,aAAO;AAAA,QACL,GAAG;AAAA,QACH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,MAAM,SAAS,gBAAgB;AACtE","sourcesContent":["import type {\n Button,\n Component,\n FormState,\n Input,\n InterfaceState,\n SnapId,\n UserInputEvent,\n} from '@metamask/snaps-sdk';\nimport {\n ButtonType,\n DialogType,\n NodeType,\n UserInputEventType,\n assert,\n} from '@metamask/snaps-sdk';\nimport { HandlerType, hasChildren, unwrapError } from '@metamask/snaps-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: Component,\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: Component }> {\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\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n payload.id,\n );\n\n return { ...payload, content };\n}\n\n/**\n * Get a Button or an Input from an interface.\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 in a form, otherwise undefined.\n */\nexport function getElement(\n content: Component,\n name: string,\n):\n | {\n element: Button | Input;\n form?: string;\n }\n | undefined {\n const { type } = content;\n\n if (\n (type === NodeType.Button || type === NodeType.Input) &&\n content.name === name\n ) {\n return { element: content };\n }\n\n if (hasChildren(content)) {\n for (const element of content.children) {\n const result = getElement(element, name);\n const form = type === NodeType.Form ? content.name : result?.form;\n\n if (result) {\n return { element: result.element, form };\n }\n }\n }\n\n return undefined;\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 */\nasync function handleEvent(\n controllerMessenger: RootControllerMessenger,\n snapId: SnapId,\n id: string,\n event: UserInputEvent,\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 },\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: Component,\n snapId: SnapId,\n name: string,\n): Promise<void> {\n const result = getElement(content, name);\n assert(\n result !== undefined && result.element.type === NodeType.Button,\n 'No button found in the interface.',\n );\n\n // Button click events are always triggered.\n await handleEvent(controllerMessenger, snapId, id, {\n type: UserInputEventType.ButtonClickEvent,\n name: result.element.name,\n });\n\n if (result.form && result.element.buttonType === ButtonType.Submit) {\n const { state } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n await handleEvent(controllerMessenger, snapId, id, {\n type: UserInputEventType.FormSubmitEvent,\n name: result.form,\n value: state[result.form] as Record<string, string | null>,\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: Component,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined && result.element.type === NodeType.Input,\n 'No input found in the interface.',\n );\n\n const { state } = 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.name,\n value,\n },\n id,\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 };\n\n return getInterfaceResponse(runSaga, type, content, interfaceActions);\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/simulation/interface.ts"],"sourcesContent":["import type {\n Button,\n Component,\n FormState,\n Input,\n InterfaceState,\n SnapId,\n UserInputEvent,\n} from '@metamask/snaps-sdk';\nimport {\n ButtonType,\n DialogType,\n NodeType,\n UserInputEventType,\n assert,\n} from '@metamask/snaps-sdk';\nimport { HandlerType, hasChildren, unwrapError } from '@metamask/snaps-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: Component,\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: Component }> {\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\n const { content } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n payload.id,\n );\n\n return { ...payload, content };\n}\n\n/**\n * Get a Button or an Input from an interface.\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 in a form, otherwise undefined.\n */\nexport function getElement(\n content: Component,\n name: string,\n):\n | {\n element: Button | Input;\n form?: string;\n }\n | undefined {\n const { type } = content;\n\n if (\n (type === NodeType.Button || type === NodeType.Input) &&\n content.name === name\n ) {\n return { element: content };\n }\n\n if (hasChildren(content)) {\n for (const element of content.children) {\n const result = getElement(element, name);\n const form = type === NodeType.Form ? content.name : result?.form;\n\n if (result) {\n return { element: result.element, form };\n }\n }\n }\n\n return undefined;\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 */\nasync function handleEvent(\n controllerMessenger: RootControllerMessenger,\n snapId: SnapId,\n id: string,\n event: UserInputEvent,\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 },\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: Component,\n snapId: SnapId,\n name: string,\n): Promise<void> {\n const result = getElement(content, name);\n assert(\n result !== undefined && result.element.type === NodeType.Button,\n 'No button found in the interface.',\n );\n\n // Button click events are always triggered.\n await handleEvent(controllerMessenger, snapId, id, {\n type: UserInputEventType.ButtonClickEvent,\n name: result.element.name,\n });\n\n if (result.form && result.element.buttonType === ButtonType.Submit) {\n const { state } = controllerMessenger.call(\n 'SnapInterfaceController:getInterface',\n snapId,\n id,\n );\n\n await handleEvent(controllerMessenger, snapId, id, {\n type: UserInputEventType.FormSubmitEvent,\n name: result.form,\n value: state[result.form] as Record<string, string | null>,\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: Component,\n snapId: SnapId,\n name: string,\n value: string,\n) {\n const result = getElement(content, name);\n\n assert(\n result !== undefined && result.element.type === NodeType.Input,\n 'No input found in the interface.',\n );\n\n const { state } = 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.name,\n value,\n },\n id,\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 };\n\n return getInterfaceResponse(runSaga, type, content, interfaceActions);\n}\n"],"mappings":";;;;;;;AASA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,aAAa,aAAa,mB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QACF;AAAA,QACA;AAAA,MACF;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,EACF;AAEA,SAAO,qBAAqB,SAAS,MAAM,SAAS,gBAAgB;AACtE;","names":["content"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/internals/structs.ts"],"sourcesContent":["import {\n ComponentStruct,\n NotificationType,\n enumValue,\n} from '@metamask/snaps-sdk';\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(ComponentStruct),\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":";A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