@metamask/snaps-jest 8.4.0 → 8.6.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.
- package/CHANGELOG.md +78 -1
- package/LICENSE +15 -0
- package/README.md +33 -0
- package/dist/environment.cjs.map +1 -1
- package/dist/environment.d.cts +2 -2
- package/dist/environment.d.cts.map +1 -1
- package/dist/environment.d.mts +2 -2
- package/dist/environment.d.mts.map +1 -1
- package/dist/environment.mjs.map +1 -1
- package/dist/helpers.cjs +9 -108
- package/dist/helpers.cjs.map +1 -1
- package/dist/helpers.d.cts +1 -2
- package/dist/helpers.d.cts.map +1 -1
- package/dist/helpers.d.mts +1 -2
- package/dist/helpers.d.mts.map +1 -1
- package/dist/helpers.mjs +11 -110
- package/dist/helpers.mjs.map +1 -1
- package/dist/index.cjs +0 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +0 -1
- package/dist/index.mjs.map +1 -1
- package/dist/matchers.cjs.map +1 -1
- package/dist/matchers.d.cts.map +1 -1
- package/dist/matchers.d.mts.map +1 -1
- package/dist/matchers.mjs.map +1 -1
- package/package.json +37 -19
- package/dist/types/index.cjs +0 -18
- package/dist/types/index.cjs.map +0 -1
- package/dist/types/index.d.cts +0 -2
- package/dist/types/index.d.cts.map +0 -1
- package/dist/types/index.d.mts +0 -2
- package/dist/types/index.d.mts.map +0 -1
- package/dist/types/index.mjs +0 -2
- package/dist/types/index.mjs.map +0 -1
- package/dist/types/types.cjs +0 -3
- package/dist/types/types.cjs.map +0 -1
- package/dist/types/types.d.cts +0 -393
- package/dist/types/types.d.cts.map +0 -1
- package/dist/types/types.d.mts +0 -393
- package/dist/types/types.d.mts.map +0 -1
- package/dist/types/types.mjs +0 -2
- package/dist/types/types.mjs.map +0 -1
package/dist/types/types.d.mts
DELETED
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
import type { NotificationType, EnumToUnion } from "@metamask/snaps-sdk";
|
|
2
|
-
import type { JSXElement } from "@metamask/snaps-sdk/jsx";
|
|
3
|
-
import type { SignatureOptionsStruct, SnapOptionsStruct, SnapResponseStruct, TransactionOptionsStruct } from "@metamask/snaps-simulation";
|
|
4
|
-
import type { InferMatching } from "@metamask/snaps-utils";
|
|
5
|
-
import type { Infer } from "@metamask/superstruct";
|
|
6
|
-
import type { Json, JsonRpcId, JsonRpcParams } from "@metamask/utils";
|
|
7
|
-
export type RequestOptions = {
|
|
8
|
-
/**
|
|
9
|
-
* The JSON-RPC request ID.
|
|
10
|
-
*/
|
|
11
|
-
id?: JsonRpcId;
|
|
12
|
-
/**
|
|
13
|
-
* The JSON-RPC method.
|
|
14
|
-
*/
|
|
15
|
-
method: string;
|
|
16
|
-
/**
|
|
17
|
-
* The JSON-RPC params.
|
|
18
|
-
*/
|
|
19
|
-
params?: JsonRpcParams;
|
|
20
|
-
/**
|
|
21
|
-
* The origin to send the request from.
|
|
22
|
-
*/
|
|
23
|
-
origin?: string;
|
|
24
|
-
};
|
|
25
|
-
/**
|
|
26
|
-
* The `runCronjob` options. This is the same as {@link RequestOptions}, except
|
|
27
|
-
* that it does not have an `origin` property.
|
|
28
|
-
*/
|
|
29
|
-
export type CronjobOptions = Omit<RequestOptions, 'origin'>;
|
|
30
|
-
/**
|
|
31
|
-
* The options to use for transaction requests.
|
|
32
|
-
*
|
|
33
|
-
* @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults
|
|
34
|
-
* to `eip155:1`.
|
|
35
|
-
* @property origin - The origin to send the transaction from. Defaults to
|
|
36
|
-
* `metamask.io`.
|
|
37
|
-
* @property from - The address to send the transaction from. Defaults to a
|
|
38
|
-
* randomly generated address.
|
|
39
|
-
* @property to - The address to send the transaction to. Defaults to a randomly
|
|
40
|
-
* generated address.
|
|
41
|
-
* @property value - The value to send with the transaction. Defaults to `0`.
|
|
42
|
-
* @property data - The data to send with the transaction. Defaults to `0x`.
|
|
43
|
-
* @property gasLimit - The gas limit to use for the transaction. Defaults to
|
|
44
|
-
* `21_000`.
|
|
45
|
-
* @property maxFeePerGas - The maximum fee per gas to use for the transaction.
|
|
46
|
-
* Defaults to `1`.
|
|
47
|
-
* @property maxPriorityFeePerGas - The maximum priority fee per gas to use for
|
|
48
|
-
* the transaction. Defaults to `1`.
|
|
49
|
-
* @property nonce - The nonce to use for the transaction. Defaults to `0`.
|
|
50
|
-
*/
|
|
51
|
-
export type TransactionOptions = Infer<typeof TransactionOptionsStruct>;
|
|
52
|
-
/**
|
|
53
|
-
* The options to use for signature requests.
|
|
54
|
-
*
|
|
55
|
-
* @property origin - The origin to send the signature request from. Defaults to
|
|
56
|
-
* `metamask.io`.
|
|
57
|
-
* @property from - The address to send the signature from. Defaults to a
|
|
58
|
-
* randomly generated address.
|
|
59
|
-
* @property data - The data to sign. Defaults to `0x`.
|
|
60
|
-
* @property signatureMethod - The signature method.
|
|
61
|
-
*/
|
|
62
|
-
export type SignatureOptions = Infer<typeof SignatureOptionsStruct>;
|
|
63
|
-
/**
|
|
64
|
-
* The options to use for requests to the snap.
|
|
65
|
-
*
|
|
66
|
-
* @property timeout - The timeout in milliseconds to use. Defaults to `1000`.
|
|
67
|
-
*/
|
|
68
|
-
export type SnapOptions = Infer<typeof SnapOptionsStruct>;
|
|
69
|
-
/**
|
|
70
|
-
* Options for uploading a file.
|
|
71
|
-
*
|
|
72
|
-
* @property fileName - The name of the file. By default, this is inferred from
|
|
73
|
-
* the file path if it's a path, and defaults to an empty string if it's a
|
|
74
|
-
* `Uint8Array`.
|
|
75
|
-
* @property contentType - The content type of the file. By default, this is
|
|
76
|
-
* inferred from the file name if it's a path, and defaults to
|
|
77
|
-
* `application/octet-stream` if it's a `Uint8Array` or the content type cannot
|
|
78
|
-
* be inferred from the file name.
|
|
79
|
-
*/
|
|
80
|
-
export type FileOptions = {
|
|
81
|
-
fileName?: string;
|
|
82
|
-
contentType?: string;
|
|
83
|
-
};
|
|
84
|
-
export type SnapInterfaceActions = {
|
|
85
|
-
/**
|
|
86
|
-
* Click on an interface element.
|
|
87
|
-
*
|
|
88
|
-
* @param name - The element name to click.
|
|
89
|
-
*/
|
|
90
|
-
clickElement(name: string): Promise<void>;
|
|
91
|
-
/**
|
|
92
|
-
* Type a value in a interface field.
|
|
93
|
-
*
|
|
94
|
-
* @param name - The element name to type in.
|
|
95
|
-
* @param value - The value to type.
|
|
96
|
-
*/
|
|
97
|
-
typeInField(name: string, value: string): Promise<void>;
|
|
98
|
-
/**
|
|
99
|
-
* Select an option with a value in a dropdown.
|
|
100
|
-
*
|
|
101
|
-
* @param name - The element name to type in.
|
|
102
|
-
* @param value - The value to type.
|
|
103
|
-
*/
|
|
104
|
-
selectInDropdown(name: string, value: string): Promise<void>;
|
|
105
|
-
/**
|
|
106
|
-
* Choose an option with a value from radio group.
|
|
107
|
-
*
|
|
108
|
-
* @param name - The element name to type in.
|
|
109
|
-
* @param value - The value to type.
|
|
110
|
-
*/
|
|
111
|
-
selectFromRadioGroup(name: string, value: string): Promise<void>;
|
|
112
|
-
/**
|
|
113
|
-
* Choose an option with a value from Selector component.
|
|
114
|
-
*
|
|
115
|
-
* @param name - The element name to type in.
|
|
116
|
-
* @param value - The value to type.
|
|
117
|
-
*/
|
|
118
|
-
selectFromSelector(name: string, value: string): Promise<void>;
|
|
119
|
-
/**
|
|
120
|
-
* Upload a file.
|
|
121
|
-
*
|
|
122
|
-
* @param name - The element name to upload the file to.
|
|
123
|
-
* @param file - The file to upload. This can be a path to a file or a
|
|
124
|
-
* `Uint8Array` containing the file contents. If this is a path, the file is
|
|
125
|
-
* resolved relative to the current working directory.
|
|
126
|
-
* @param options - The file options.
|
|
127
|
-
* @param options.fileName - The name of the file. By default, this is
|
|
128
|
-
* inferred from the file path if it's a path, and defaults to an empty string
|
|
129
|
-
* if it's a `Uint8Array`.
|
|
130
|
-
* @param options.contentType - The content type of the file. By default, this
|
|
131
|
-
* is inferred from the file name if it's a path, and defaults to
|
|
132
|
-
* `application/octet-stream` if it's a `Uint8Array` or the content type
|
|
133
|
-
* cannot be inferred from the file name.
|
|
134
|
-
*/
|
|
135
|
-
uploadFile(name: string, file: string | Uint8Array, options?: FileOptions): Promise<void>;
|
|
136
|
-
};
|
|
137
|
-
/**
|
|
138
|
-
* A `snap_dialog` alert interface.
|
|
139
|
-
*/
|
|
140
|
-
export type SnapAlertInterface = {
|
|
141
|
-
/**
|
|
142
|
-
* The type of the interface. This is always `alert`.
|
|
143
|
-
*/
|
|
144
|
-
type: 'alert';
|
|
145
|
-
/**
|
|
146
|
-
* The content to show in the alert.
|
|
147
|
-
*/
|
|
148
|
-
content: JSXElement;
|
|
149
|
-
/**
|
|
150
|
-
* Close the alert.
|
|
151
|
-
*/
|
|
152
|
-
ok(): Promise<void>;
|
|
153
|
-
};
|
|
154
|
-
/**
|
|
155
|
-
* A `snap_dialog` confirmation interface.
|
|
156
|
-
*/
|
|
157
|
-
export type SnapConfirmationInterface = {
|
|
158
|
-
/**
|
|
159
|
-
* The type of the interface. This is always `confirmation`.
|
|
160
|
-
*/
|
|
161
|
-
type: 'confirmation';
|
|
162
|
-
/**
|
|
163
|
-
* The content to show in the confirmation.
|
|
164
|
-
*/
|
|
165
|
-
content: JSXElement;
|
|
166
|
-
/**
|
|
167
|
-
* Close the confirmation.
|
|
168
|
-
*/
|
|
169
|
-
ok(): Promise<void>;
|
|
170
|
-
/**
|
|
171
|
-
* Cancel the confirmation.
|
|
172
|
-
*/
|
|
173
|
-
cancel(): Promise<void>;
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* A `snap_dialog` prompt interface.
|
|
177
|
-
*/
|
|
178
|
-
export type SnapPromptInterface = {
|
|
179
|
-
/**
|
|
180
|
-
* The type of the interface. This is always `prompt`.
|
|
181
|
-
*/
|
|
182
|
-
type: 'prompt';
|
|
183
|
-
/**
|
|
184
|
-
* The content to show in the prompt.
|
|
185
|
-
*/
|
|
186
|
-
content: JSXElement;
|
|
187
|
-
/**
|
|
188
|
-
* Close the prompt.
|
|
189
|
-
*
|
|
190
|
-
* @param value - The value to close the prompt with.
|
|
191
|
-
*/
|
|
192
|
-
ok(value?: string): Promise<void>;
|
|
193
|
-
/**
|
|
194
|
-
* Cancel the prompt.
|
|
195
|
-
*/
|
|
196
|
-
cancel(): Promise<void>;
|
|
197
|
-
};
|
|
198
|
-
/**
|
|
199
|
-
* A `snap_dialog` default interface that has a Footer with two buttons defined.
|
|
200
|
-
* The approval of this confirmation is handled by the snap.
|
|
201
|
-
*/
|
|
202
|
-
export type DefaultSnapInterfaceWithFooter = {
|
|
203
|
-
/**
|
|
204
|
-
* The content to show in the interface.
|
|
205
|
-
*/
|
|
206
|
-
content: JSXElement;
|
|
207
|
-
};
|
|
208
|
-
/**
|
|
209
|
-
* A `snap_dialog` default interface that has a Footer with one button defined.
|
|
210
|
-
* A cancel button is automatically applied to the interface in this case.
|
|
211
|
-
*/
|
|
212
|
-
export type DefaultSnapInterfaceWithPartialFooter = DefaultSnapInterfaceWithFooter & {
|
|
213
|
-
/**
|
|
214
|
-
* Cancel the dialog.
|
|
215
|
-
*/
|
|
216
|
-
cancel(): Promise<void>;
|
|
217
|
-
};
|
|
218
|
-
/**
|
|
219
|
-
* A `snap_dialog` default interface that has no Footer defined.
|
|
220
|
-
* A cancel and ok button is automatically applied to the interface in this case.
|
|
221
|
-
*/
|
|
222
|
-
export type DefaultSnapInterfaceWithoutFooter = DefaultSnapInterfaceWithPartialFooter & {
|
|
223
|
-
/**
|
|
224
|
-
* Close the dialog.
|
|
225
|
-
*
|
|
226
|
-
*/
|
|
227
|
-
ok(): Promise<void>;
|
|
228
|
-
};
|
|
229
|
-
export type DefaultSnapInterface = DefaultSnapInterfaceWithFooter | DefaultSnapInterfaceWithPartialFooter | DefaultSnapInterfaceWithoutFooter;
|
|
230
|
-
export type SnapInterface = (SnapAlertInterface | SnapConfirmationInterface | SnapPromptInterface | DefaultSnapInterface) & SnapInterfaceActions;
|
|
231
|
-
export type SnapRequestObject = {
|
|
232
|
-
/**
|
|
233
|
-
* Get a user interface object from a snap. This will throw an error if the
|
|
234
|
-
* snap does not show a user interface within the timeout.
|
|
235
|
-
*
|
|
236
|
-
* @param options - The options to use.
|
|
237
|
-
* @param options.timeout - The timeout in milliseconds to use. Defaults to
|
|
238
|
-
* `1000`.
|
|
239
|
-
* @returns The user interface object.
|
|
240
|
-
*/
|
|
241
|
-
getInterface(options?: SnapOptions): Promise<SnapInterface>;
|
|
242
|
-
};
|
|
243
|
-
/**
|
|
244
|
-
* A pending request object. This is a promise with extra
|
|
245
|
-
* {@link SnapRequestObject} fields.
|
|
246
|
-
*/
|
|
247
|
-
export type SnapRequest = Promise<SnapResponse> & SnapRequestObject;
|
|
248
|
-
/**
|
|
249
|
-
* The options to use for mocking a JSON-RPC request.
|
|
250
|
-
*/
|
|
251
|
-
export type JsonRpcMockOptions = {
|
|
252
|
-
/**
|
|
253
|
-
* The JSON-RPC request method.
|
|
254
|
-
*/
|
|
255
|
-
method: string;
|
|
256
|
-
/**
|
|
257
|
-
* The JSON-RPC response, which will be returned when a request with the
|
|
258
|
-
* specified method is sent.
|
|
259
|
-
*/
|
|
260
|
-
result: Json;
|
|
261
|
-
};
|
|
262
|
-
/**
|
|
263
|
-
* This is the main entry point to interact with the snap. It is returned by
|
|
264
|
-
* {@link installSnap}, and has methods to send requests to the snap.
|
|
265
|
-
*
|
|
266
|
-
* @example
|
|
267
|
-
* import { installSnap } from '@metamask/snaps-jest';
|
|
268
|
-
*
|
|
269
|
-
* const snap = await installSnap();
|
|
270
|
-
* const response = await snap.request({ method: 'hello' });
|
|
271
|
-
*
|
|
272
|
-
* expect(response).toRespondWith('Hello, world!');
|
|
273
|
-
*/
|
|
274
|
-
export type Snap = {
|
|
275
|
-
/**
|
|
276
|
-
* Send a JSON-RPC request to the snap.
|
|
277
|
-
*
|
|
278
|
-
* @param request - The request. This is similar to a JSON-RPC request, but
|
|
279
|
-
* has an extra `origin` field.
|
|
280
|
-
* @returns The response promise, with extra {@link SnapRequestObject} fields.
|
|
281
|
-
*/
|
|
282
|
-
request(request: RequestOptions): SnapRequest;
|
|
283
|
-
/**
|
|
284
|
-
* Send a transaction to the snap.
|
|
285
|
-
*
|
|
286
|
-
* @param transaction - The transaction. This is similar to an Ethereum
|
|
287
|
-
* transaction object, but has an extra `origin` field. Any missing fields
|
|
288
|
-
* will be filled in with default values.
|
|
289
|
-
* @returns The response.
|
|
290
|
-
*/
|
|
291
|
-
onTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponseWithInterface>;
|
|
292
|
-
/**
|
|
293
|
-
* Send a transaction to the snap.
|
|
294
|
-
*
|
|
295
|
-
* @param transaction - The transaction. This is similar to an Ethereum
|
|
296
|
-
* transaction object, but has an extra `origin` field. Any missing fields
|
|
297
|
-
* will be filled in with default values.
|
|
298
|
-
* @returns The response.
|
|
299
|
-
* @deprecated Use {@link onTransaction} instead.
|
|
300
|
-
*/
|
|
301
|
-
sendTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponseWithInterface>;
|
|
302
|
-
/**
|
|
303
|
-
* Send a signature request to the snap.
|
|
304
|
-
*
|
|
305
|
-
* @param signature - The signature request object. Contains the params from
|
|
306
|
-
* the various signature methods, but has an extra `origin` and `signatureMethod` field.
|
|
307
|
-
* Any missing fields will be filled in with default values.
|
|
308
|
-
* @returns The response.
|
|
309
|
-
*/
|
|
310
|
-
onSignature(signature?: Partial<SignatureOptions>): Promise<SnapResponseWithInterface>;
|
|
311
|
-
/**
|
|
312
|
-
* Run a cronjob in the snap. This is similar to {@link request}, but the
|
|
313
|
-
* request will be sent to the `onCronjob` method of the snap.
|
|
314
|
-
*
|
|
315
|
-
* @param cronjob - The cronjob request. This is similar to a JSON-RPC
|
|
316
|
-
* request, and is normally specified in the snap manifest, under the
|
|
317
|
-
* `endowment:cronjob` permission.
|
|
318
|
-
* @returns The response promise, with extra {@link SnapRequestObject} fields.
|
|
319
|
-
*/
|
|
320
|
-
onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;
|
|
321
|
-
/**
|
|
322
|
-
* Run a cronjob in the snap. This is similar to {@link request}, but the
|
|
323
|
-
* request will be sent to the `onCronjob` method of the snap.
|
|
324
|
-
*
|
|
325
|
-
* @param cronjob - The cronjob request. This is similar to a JSON-RPC
|
|
326
|
-
* request, and is normally specified in the snap manifest, under the
|
|
327
|
-
* `endowment:cronjob` permission.
|
|
328
|
-
* @returns The response promise, with extra {@link SnapRequestObject} fields.
|
|
329
|
-
* @deprecated Use {@link onCronjob} instead.
|
|
330
|
-
*/
|
|
331
|
-
runCronjob(cronjob: CronjobOptions): SnapRequest;
|
|
332
|
-
/**
|
|
333
|
-
* Get the response from the snap's `onHomePage` method.
|
|
334
|
-
*
|
|
335
|
-
* @returns The response.
|
|
336
|
-
*/
|
|
337
|
-
onHomePage(): Promise<SnapResponseWithInterface>;
|
|
338
|
-
/**
|
|
339
|
-
* Mock a JSON-RPC request. This will cause the snap to respond with the
|
|
340
|
-
* specified response when a request with the specified method is sent.
|
|
341
|
-
*
|
|
342
|
-
* @param mock - The mock options.
|
|
343
|
-
* @param mock.method - The JSON-RPC request method.
|
|
344
|
-
* @param mock.result - The JSON-RPC response, which will be returned when a
|
|
345
|
-
* request with the specified method is sent.
|
|
346
|
-
* @example
|
|
347
|
-
* import { installSnap } from '@metamask/snaps-jest';
|
|
348
|
-
*
|
|
349
|
-
* // In the test
|
|
350
|
-
* const snap = await installSnap();
|
|
351
|
-
* snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });
|
|
352
|
-
*
|
|
353
|
-
* // In the Snap
|
|
354
|
-
* const response =
|
|
355
|
-
* await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']
|
|
356
|
-
*/
|
|
357
|
-
mockJsonRpc(mock: JsonRpcMockOptions): {
|
|
358
|
-
/**
|
|
359
|
-
* Remove the mock.
|
|
360
|
-
*/
|
|
361
|
-
unmock(): void;
|
|
362
|
-
};
|
|
363
|
-
/**
|
|
364
|
-
* Close the page running the snap. This is mainly useful for cleaning up
|
|
365
|
-
* the test environment, and calling it is not strictly necessary.
|
|
366
|
-
*
|
|
367
|
-
* @returns A promise that resolves when the page is closed.
|
|
368
|
-
* @deprecated Snaps are now automatically closed when the test ends. This
|
|
369
|
-
* method will be removed in a future release.
|
|
370
|
-
*/
|
|
371
|
-
close(): Promise<void>;
|
|
372
|
-
};
|
|
373
|
-
export type SnapHandlerInterface = {
|
|
374
|
-
content: JSXElement;
|
|
375
|
-
} & SnapInterfaceActions;
|
|
376
|
-
export type SnapResponseWithInterface = {
|
|
377
|
-
id: string;
|
|
378
|
-
response: {
|
|
379
|
-
result: Json;
|
|
380
|
-
} | {
|
|
381
|
-
error: Json;
|
|
382
|
-
};
|
|
383
|
-
notifications: {
|
|
384
|
-
id: string;
|
|
385
|
-
message: string;
|
|
386
|
-
type: EnumToUnion<NotificationType>;
|
|
387
|
-
}[];
|
|
388
|
-
getInterface(): SnapHandlerInterface;
|
|
389
|
-
};
|
|
390
|
-
export type SnapResponseWithoutInterface = Omit<SnapResponseWithInterface, 'getInterface'>;
|
|
391
|
-
export type SnapResponseType = SnapResponseWithoutInterface | SnapResponseWithInterface;
|
|
392
|
-
export type SnapResponse = InferMatching<typeof SnapResponseStruct, SnapResponseType>;
|
|
393
|
-
//# sourceMappingURL=types.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,4BAA4B;AACzE,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAC1D,OAAO,KAAK,EACV,sBAAsB,EACtB,iBAAiB,EACjB,kBAAkB,EAClB,wBAAwB,EACzB,mCAAmC;AACpC,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;A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+0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.mjs","sourceRoot":"","sources":["../../src/types/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { NotificationType, EnumToUnion } from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport type {\n SignatureOptionsStruct,\n SnapOptionsStruct,\n SnapResponseStruct,\n TransactionOptionsStruct,\n} from '@metamask/snaps-simulation';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils';\n\nexport type RequestOptions = {\n /**\n * The JSON-RPC request ID.\n */\n id?: JsonRpcId;\n\n /**\n * The JSON-RPC method.\n */\n method: string;\n\n /**\n * The JSON-RPC params.\n */\n params?: JsonRpcParams;\n\n /**\n * The origin to send the request from.\n */\n origin?: string;\n};\n\n/**\n * The `runCronjob` options. This is the same as {@link RequestOptions}, except\n * that it does not have an `origin` property.\n */\nexport type CronjobOptions = Omit<RequestOptions, 'origin'>;\n\n/**\n * The options to use for transaction requests.\n *\n * @property chainId - The CAIP-2 chain ID to send the transaction on. Defaults\n * to `eip155:1`.\n * @property origin - The origin to send the transaction from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the transaction from. Defaults to a\n * randomly generated address.\n * @property to - The address to send the transaction to. Defaults to a randomly\n * generated address.\n * @property value - The value to send with the transaction. Defaults to `0`.\n * @property data - The data to send with the transaction. Defaults to `0x`.\n * @property gasLimit - The gas limit to use for the transaction. Defaults to\n * `21_000`.\n * @property maxFeePerGas - The maximum fee per gas to use for the transaction.\n * Defaults to `1`.\n * @property maxPriorityFeePerGas - The maximum priority fee per gas to use for\n * the transaction. Defaults to `1`.\n * @property nonce - The nonce to use for the transaction. Defaults to `0`.\n */\nexport type TransactionOptions = Infer<typeof TransactionOptionsStruct>;\n\n/**\n * The options to use for signature requests.\n *\n * @property origin - The origin to send the signature request from. Defaults to\n * `metamask.io`.\n * @property from - The address to send the signature from. Defaults to a\n * randomly generated address.\n * @property data - The data to sign. Defaults to `0x`.\n * @property signatureMethod - The signature method.\n */\nexport type SignatureOptions = Infer<typeof SignatureOptionsStruct>;\n\n/**\n * The options to use for requests to the snap.\n *\n * @property timeout - The timeout in milliseconds to use. Defaults to `1000`.\n */\nexport type SnapOptions = Infer<typeof SnapOptionsStruct>;\n\n/**\n * Options for uploading a file.\n *\n * @property fileName - The name of the file. By default, this is inferred from\n * the file path if it's a path, and defaults to an empty string if it's a\n * `Uint8Array`.\n * @property contentType - The content type of the file. By default, this is\n * 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 cannot\n * be inferred from the file name.\n */\nexport type FileOptions = {\n fileName?: string;\n contentType?: string;\n};\n\nexport type SnapInterfaceActions = {\n /**\n * Click on an interface element.\n *\n * @param name - The element name to click.\n */\n clickElement(name: string): Promise<void>;\n\n /**\n * Type a value in a interface field.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n typeInField(name: string, value: string): Promise<void>;\n\n /**\n * Select an option with a value in a dropdown.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectInDropdown(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from radio group.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromRadioGroup(name: string, value: string): Promise<void>;\n\n /**\n * Choose an option with a value from Selector component.\n *\n * @param name - The element name to type in.\n * @param value - The value to type.\n */\n selectFromSelector(name: string, value: string): Promise<void>;\n\n /**\n * Upload a file.\n *\n * @param name - The element name to upload the file to.\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 */\n uploadFile(\n name: string,\n file: string | Uint8Array,\n options?: FileOptions,\n ): Promise<void>;\n};\n\n/**\n * A `snap_dialog` alert interface.\n */\nexport type SnapAlertInterface = {\n /**\n * The type of the interface. This is always `alert`.\n */\n type: 'alert';\n\n /**\n * The content to show in the alert.\n */\n content: JSXElement;\n\n /**\n * Close the alert.\n */\n ok(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` confirmation interface.\n */\nexport type SnapConfirmationInterface = {\n /**\n * The type of the interface. This is always `confirmation`.\n */\n type: 'confirmation';\n\n /**\n * The content to show in the confirmation.\n */\n content: JSXElement;\n\n /**\n * Close the confirmation.\n */\n ok(): Promise<void>;\n\n /**\n * Cancel the confirmation.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` prompt interface.\n */\nexport type SnapPromptInterface = {\n /**\n * The type of the interface. This is always `prompt`.\n */\n type: 'prompt';\n\n /**\n * The content to show in the prompt.\n */\n content: JSXElement;\n\n /**\n * Close the prompt.\n *\n * @param value - The value to close the prompt with.\n */\n ok(value?: string): Promise<void>;\n\n /**\n * Cancel the prompt.\n */\n cancel(): Promise<void>;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with two buttons defined.\n * The approval of this confirmation is handled by the snap.\n */\nexport type DefaultSnapInterfaceWithFooter = {\n /**\n * The content to show in the interface.\n */\n content: JSXElement;\n};\n\n/**\n * A `snap_dialog` default interface that has a Footer with one button defined.\n * A cancel button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithPartialFooter =\n DefaultSnapInterfaceWithFooter & {\n /**\n * Cancel the dialog.\n */\n cancel(): Promise<void>;\n };\n\n/**\n * A `snap_dialog` default interface that has no Footer defined.\n * A cancel and ok button is automatically applied to the interface in this case.\n */\nexport type DefaultSnapInterfaceWithoutFooter =\n DefaultSnapInterfaceWithPartialFooter & {\n /**\n * Close the dialog.\n *\n */\n ok(): Promise<void>;\n };\n\nexport type DefaultSnapInterface =\n | DefaultSnapInterfaceWithFooter\n | DefaultSnapInterfaceWithPartialFooter\n | DefaultSnapInterfaceWithoutFooter;\n\nexport type SnapInterface = (\n | SnapAlertInterface\n | SnapConfirmationInterface\n | SnapPromptInterface\n | DefaultSnapInterface\n) &\n SnapInterfaceActions;\n\nexport type SnapRequestObject = {\n /**\n * Get a user interface object from a snap. This will throw an error if the\n * snap does not show a user interface within the timeout.\n *\n * @param options - The options to use.\n * @param options.timeout - The timeout in milliseconds to use. Defaults to\n * `1000`.\n * @returns The user interface object.\n */\n getInterface(options?: SnapOptions): Promise<SnapInterface>;\n};\n\n/**\n * A pending request object. This is a promise with extra\n * {@link SnapRequestObject} fields.\n */\nexport type SnapRequest = Promise<SnapResponse> & SnapRequestObject;\n\n/**\n * The options to use for mocking a JSON-RPC request.\n */\nexport type JsonRpcMockOptions = {\n /**\n * The JSON-RPC request method.\n */\n method: string;\n\n /**\n * The JSON-RPC response, which will be returned when a request with the\n * specified method is sent.\n */\n result: Json;\n};\n\n/**\n * This is the main entry point to interact with the snap. It is returned by\n * {@link installSnap}, and has methods to send requests to the snap.\n *\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * const snap = await installSnap();\n * const response = await snap.request({ method: 'hello' });\n *\n * expect(response).toRespondWith('Hello, world!');\n */\nexport type Snap = {\n /**\n * Send a JSON-RPC request to the snap.\n *\n * @param request - The request. This is similar to a JSON-RPC request, but\n * has an extra `origin` field.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n request(request: RequestOptions): SnapRequest;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n */\n onTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a transaction to the snap.\n *\n * @param transaction - The transaction. This is similar to an Ethereum\n * transaction object, but has an extra `origin` field. Any missing fields\n * will be filled in with default values.\n * @returns The response.\n * @deprecated Use {@link onTransaction} instead.\n */\n sendTransaction(\n transaction?: Partial<TransactionOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Send a signature request to the snap.\n *\n * @param signature - The signature request object. Contains the params from\n * the various signature methods, but has an extra `origin` and `signatureMethod` field.\n * Any missing fields will be filled in with default values.\n * @returns The response.\n */\n onSignature(\n signature?: Partial<SignatureOptions>,\n ): Promise<SnapResponseWithInterface>;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n */\n onCronjob(cronjob?: Partial<CronjobOptions>): SnapRequest;\n\n /**\n * Run a cronjob in the snap. This is similar to {@link request}, but the\n * request will be sent to the `onCronjob` method of the snap.\n *\n * @param cronjob - The cronjob request. This is similar to a JSON-RPC\n * request, and is normally specified in the snap manifest, under the\n * `endowment:cronjob` permission.\n * @returns The response promise, with extra {@link SnapRequestObject} fields.\n * @deprecated Use {@link onCronjob} instead.\n */\n runCronjob(cronjob: CronjobOptions): SnapRequest;\n\n /**\n * Get the response from the snap's `onHomePage` method.\n *\n * @returns The response.\n */\n onHomePage(): Promise<SnapResponseWithInterface>;\n\n /**\n * Mock a JSON-RPC request. This will cause the snap to respond with the\n * specified response when a request with the specified method is sent.\n *\n * @param mock - The mock options.\n * @param mock.method - The JSON-RPC request method.\n * @param mock.result - The JSON-RPC response, which will be returned when a\n * request with the specified method is sent.\n * @example\n * import { installSnap } from '@metamask/snaps-jest';\n *\n * // In the test\n * const snap = await installSnap();\n * snap.mockJsonRpc({ method: 'eth_accounts', result: ['0x1234'] });\n *\n * // In the Snap\n * const response =\n * await ethereum.request({ method: 'eth_accounts' }); // ['0x1234']\n */\n mockJsonRpc(mock: JsonRpcMockOptions): {\n /**\n * Remove the mock.\n */\n unmock(): void;\n };\n\n /**\n * Close the page running the snap. This is mainly useful for cleaning up\n * the test environment, and calling it is not strictly necessary.\n *\n * @returns A promise that resolves when the page is closed.\n * @deprecated Snaps are now automatically closed when the test ends. This\n * method will be removed in a future release.\n */\n close(): Promise<void>;\n};\n\nexport type SnapHandlerInterface = {\n content: JSXElement;\n} & SnapInterfaceActions;\n\nexport type SnapResponseWithInterface = {\n id: string;\n response: { result: Json } | { error: Json };\n notifications: {\n id: string;\n message: string;\n type: EnumToUnion<NotificationType>;\n }[];\n getInterface(): SnapHandlerInterface;\n};\n\nexport type SnapResponseWithoutInterface = Omit<\n SnapResponseWithInterface,\n 'getInterface'\n>;\n\nexport type SnapResponseType =\n | SnapResponseWithoutInterface\n | SnapResponseWithInterface;\n\nexport type SnapResponse = InferMatching<\n typeof SnapResponseStruct,\n SnapResponseType\n>;\n"]}
|