@metamask/snaps-jest 6.0.1 → 7.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.
- package/CHANGELOG.md +18 -1
- package/README.md +100 -7
- package/dist/{chunk-JUNUGLG4.js → chunk-2JAGD4N6.js} +3 -3
- package/dist/{chunk-7YD4IW43.mjs → chunk-3M4GRUMH.mjs} +3 -6
- package/dist/chunk-3M4GRUMH.mjs.map +1 -0
- package/dist/{chunk-7BFTEFLS.mjs → chunk-5U5WB3SM.mjs} +5 -3
- package/dist/chunk-5U5WB3SM.mjs.map +1 -0
- package/dist/chunk-6POKT4OO.js +127 -0
- package/dist/chunk-6POKT4OO.js.map +1 -0
- package/dist/{chunk-7VILST6M.mjs → chunk-BVGI3E45.mjs} +2 -2
- package/dist/chunk-CKRORVDW.js +1 -0
- package/dist/{chunk-WFBQPYSV.js → chunk-DTDYOBCI.js} +10 -6
- package/dist/chunk-DTDYOBCI.js.map +1 -0
- package/dist/{chunk-WIFOID2P.mjs → chunk-EDEJD326.mjs} +20 -10
- package/dist/chunk-EDEJD326.mjs.map +1 -0
- package/dist/{chunk-B4QZXXQY.js → chunk-FIZAYEHV.js} +4 -4
- package/dist/chunk-I5P52IMF.mjs +223 -0
- package/dist/chunk-I5P52IMF.mjs.map +1 -0
- package/dist/{chunk-T2BE4O5H.js → chunk-IDGD7TZ7.js} +33 -23
- package/dist/chunk-IDGD7TZ7.js.map +1 -0
- package/dist/{chunk-CCYBLBVL.mjs → chunk-LG3VKXGH.mjs} +9 -5
- package/dist/chunk-LG3VKXGH.mjs.map +1 -0
- package/dist/{chunk-SQJOQ7AF.js → chunk-MCYTJUDG.js} +13 -16
- package/dist/chunk-MCYTJUDG.js.map +1 -0
- package/dist/chunk-PVMIH6OB.mjs +127 -0
- package/dist/chunk-PVMIH6OB.mjs.map +1 -0
- package/dist/chunk-S2HLITUN.js +1 -0
- package/dist/{chunk-ISWZ7XZ5.js → chunk-SB5EPHE3.js} +5 -3
- package/dist/chunk-SB5EPHE3.js.map +1 -0
- package/dist/{chunk-HBLJOACO.mjs → chunk-TAIJXTLU.mjs} +2 -10
- package/dist/chunk-TAIJXTLU.mjs.map +1 -0
- package/dist/chunk-TGZ7WOTJ.mjs +1 -0
- package/dist/chunk-UDOXICJK.mjs +1 -0
- package/dist/{chunk-LHU3EHLI.mjs → chunk-VSUNWJMQ.mjs} +11 -14
- package/dist/chunk-VSUNWJMQ.mjs.map +1 -0
- package/dist/{chunk-TO46ICOZ.js → chunk-WMLSD6B5.js} +3 -6
- package/dist/chunk-WMLSD6B5.js.map +1 -0
- package/dist/{chunk-4SC3HVI5.mjs → chunk-X5IPMTHO.mjs} +2 -2
- package/dist/chunk-Y4DKEF7Y.js +223 -0
- package/dist/chunk-Y4DKEF7Y.js.map +1 -0
- package/dist/{chunk-7J34R6YW.mjs → chunk-YEVKBYKO.mjs} +35 -25
- package/dist/chunk-YEVKBYKO.mjs.map +1 -0
- package/dist/{chunk-5PLDD7ZC.js → chunk-Z35PCKFD.js} +24 -14
- package/dist/chunk-Z35PCKFD.js.map +1 -0
- package/dist/{chunk-LXSNRZV4.js → chunk-ZWN4SO2V.js} +5 -13
- package/dist/chunk-ZWN4SO2V.js.map +1 -0
- package/dist/environment.js +13 -14
- package/dist/environment.mjs +12 -13
- package/dist/global.js +2 -0
- package/dist/global.js.map +1 -0
- package/dist/global.mjs +2 -0
- package/dist/global.mjs.map +1 -0
- package/dist/helpers.js +13 -14
- package/dist/helpers.mjs +12 -13
- package/dist/index.js +16 -16
- package/dist/index.mjs +15 -15
- package/dist/internals/index.js +27 -14
- package/dist/internals/index.mjs +30 -17
- package/dist/internals/request.js +12 -11
- package/dist/internals/request.mjs +13 -12
- package/dist/internals/simulation/controllers.js +6 -7
- package/dist/internals/simulation/controllers.mjs +5 -6
- package/dist/internals/simulation/index.js +17 -10
- package/dist/internals/simulation/index.mjs +17 -10
- package/dist/internals/simulation/interface.js +11 -3
- package/dist/internals/simulation/interface.mjs +12 -4
- package/dist/internals/simulation/methods/hooks/index.js +4 -10
- package/dist/internals/simulation/methods/hooks/index.mjs +3 -9
- package/dist/internals/simulation/methods/hooks/notifications.js +1 -1
- package/dist/internals/simulation/methods/hooks/notifications.mjs +1 -1
- package/dist/internals/simulation/methods/hooks/show-dialog.js +1 -1
- package/dist/internals/simulation/methods/hooks/show-dialog.mjs +1 -1
- package/dist/internals/simulation/methods/hooks/state.js +3 -3
- package/dist/internals/simulation/methods/hooks/state.mjs +2 -2
- package/dist/internals/simulation/methods/index.js +5 -6
- package/dist/internals/simulation/methods/index.mjs +4 -5
- package/dist/internals/simulation/methods/specifications.js +5 -6
- package/dist/internals/simulation/methods/specifications.mjs +4 -5
- package/dist/internals/simulation/simulation.js +8 -9
- package/dist/internals/simulation/simulation.mjs +7 -8
- package/dist/internals/simulation/store/index.js +2 -2
- package/dist/internals/simulation/store/index.mjs +1 -1
- package/dist/internals/simulation/store/store.js +2 -2
- package/dist/internals/simulation/store/store.mjs +1 -1
- package/dist/internals/structs.js +6 -2
- package/dist/internals/structs.mjs +5 -1
- package/dist/matchers.js +13 -14
- package/dist/matchers.mjs +12 -13
- package/dist/setup.js +12 -13
- package/dist/setup.mjs +12 -13
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/global.d.ts +69 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/internals/request.d.ts +13 -4
- package/dist/types/internals/simulation/interface.d.ts +47 -4
- package/dist/types/internals/simulation/methods/hooks/index.d.ts +0 -1
- package/dist/types/internals/simulation/methods/hooks/state.d.ts +2 -1
- package/dist/types/internals/simulation/store/store.d.ts +1 -2
- package/dist/types/internals/structs.d.ts +87 -156
- package/dist/types/types.d.ts +42 -21
- package/package.json +11 -11
- package/dist/chunk-2X23DUDP.mjs +0 -22
- package/dist/chunk-2X23DUDP.mjs.map +0 -1
- package/dist/chunk-5PLDD7ZC.js.map +0 -1
- package/dist/chunk-6MVV44M5.mjs +0 -76
- package/dist/chunk-6MVV44M5.mjs.map +0 -1
- package/dist/chunk-7BFTEFLS.mjs.map +0 -1
- package/dist/chunk-7J34R6YW.mjs.map +0 -1
- package/dist/chunk-7YD4IW43.mjs.map +0 -1
- package/dist/chunk-CCYBLBVL.mjs.map +0 -1
- package/dist/chunk-HBLJOACO.mjs.map +0 -1
- package/dist/chunk-HNH5UAKZ.js +0 -80
- package/dist/chunk-HNH5UAKZ.js.map +0 -1
- package/dist/chunk-ISWZ7XZ5.js.map +0 -1
- package/dist/chunk-LHU3EHLI.mjs.map +0 -1
- package/dist/chunk-LXSNRZV4.js.map +0 -1
- package/dist/chunk-LYK6EGZU.mjs +0 -80
- package/dist/chunk-LYK6EGZU.mjs.map +0 -1
- package/dist/chunk-RD7GQCPL.js +0 -22
- package/dist/chunk-RD7GQCPL.js.map +0 -1
- package/dist/chunk-SQJOQ7AF.js.map +0 -1
- package/dist/chunk-T2BE4O5H.js.map +0 -1
- package/dist/chunk-TO46ICOZ.js.map +0 -1
- package/dist/chunk-U5BLLHIU.js +0 -1
- package/dist/chunk-V6LFAN3U.mjs +0 -1
- package/dist/chunk-WFBQPYSV.js.map +0 -1
- package/dist/chunk-WIFOID2P.mjs.map +0 -1
- package/dist/chunk-ZAQZRYPW.js +0 -76
- package/dist/chunk-ZAQZRYPW.js.map +0 -1
- package/dist/internals/simulation/methods/hooks/encryption.js +0 -10
- package/dist/internals/simulation/methods/hooks/encryption.mjs +0 -10
- package/dist/types/internals/simulation/methods/hooks/encryption.d.ts +0 -29
- /package/dist/{chunk-JUNUGLG4.js.map → chunk-2JAGD4N6.js.map} +0 -0
- /package/dist/{chunk-7VILST6M.mjs.map → chunk-BVGI3E45.mjs.map} +0 -0
- /package/dist/{chunk-U5BLLHIU.js.map → chunk-CKRORVDW.js.map} +0 -0
- /package/dist/{chunk-B4QZXXQY.js.map → chunk-FIZAYEHV.js.map} +0 -0
- /package/dist/{internals/simulation/methods/hooks/encryption.js.map → chunk-S2HLITUN.js.map} +0 -0
- /package/dist/{chunk-V6LFAN3U.mjs.map → chunk-TGZ7WOTJ.mjs.map} +0 -0
- /package/dist/{internals/simulation/methods/hooks/encryption.mjs.map → chunk-UDOXICJK.mjs.map} +0 -0
- /package/dist/{chunk-4SC3HVI5.mjs.map → chunk-X5IPMTHO.mjs.map} +0 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Component, EnumToUnion, NotificationType } from '@metamask/snaps-sdk';
|
|
2
|
+
interface SnapsMatchers {
|
|
3
|
+
/**
|
|
4
|
+
* Assert that the response is a JSON-RPC response with the given result. This
|
|
5
|
+
* is equivalent to calling `expect(response.result).toStrictEqual(result)`.
|
|
6
|
+
*
|
|
7
|
+
* @param response - The expected response result.
|
|
8
|
+
* @throws If the response is not a JSON-RPC response with the given result.
|
|
9
|
+
* @example
|
|
10
|
+
* const response = await request({ method: 'foo' });
|
|
11
|
+
* expect(response).toRespondWith('bar');
|
|
12
|
+
*/
|
|
13
|
+
toRespondWith(response: unknown): void;
|
|
14
|
+
/**
|
|
15
|
+
* Assert that the response is a JSON-RPC response with the given error. This
|
|
16
|
+
* is equivalent to calling `expect(response.error).toStrictEqual(error)`.
|
|
17
|
+
*
|
|
18
|
+
* @param error - The expected response error.
|
|
19
|
+
* @throws If the response is not a JSON-RPC response with the given error.
|
|
20
|
+
* @example
|
|
21
|
+
* const response = await request({ method: 'foo' });
|
|
22
|
+
* expect(response).toRespondWithError({
|
|
23
|
+
* code: -32601,
|
|
24
|
+
* message: 'The method does not exist / is not available.',
|
|
25
|
+
* stack: expect.any(String),
|
|
26
|
+
* data: { method: 'foo', cause: null },
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
toRespondWithError(error: unknown): void;
|
|
30
|
+
/**
|
|
31
|
+
* Assert that the Snap sent a notification with the expected message, and
|
|
32
|
+
* optionally the expected notification type. This is equivalent to calling
|
|
33
|
+
* `expect(response.notifications).toContainEqual({ message, type })`.
|
|
34
|
+
*
|
|
35
|
+
* @param message - The expected notification message.
|
|
36
|
+
* @param type - The expected notification type, i.e., 'inApp' or 'native'. If
|
|
37
|
+
* not provided, the type will be ignored.
|
|
38
|
+
* @throws If the snap did not send a notification with the expected message.
|
|
39
|
+
* @example
|
|
40
|
+
* const response = await request({ method: 'foo' });
|
|
41
|
+
* expect(response).toSendNotification('bar', NotificationType.InApp);
|
|
42
|
+
*/
|
|
43
|
+
toSendNotification(message: string, type?: EnumToUnion<NotificationType>): void;
|
|
44
|
+
/**
|
|
45
|
+
* Assert that the Snap rendered the expected component. This is equivalent to
|
|
46
|
+
* calling `expect(interface.content).toStrictEqual(component)`.
|
|
47
|
+
*
|
|
48
|
+
* @param component - The expected rendered component.
|
|
49
|
+
* @throws If the snap did not render the expected component.
|
|
50
|
+
* @example
|
|
51
|
+
* const response = request({ method: 'foo' });
|
|
52
|
+
* const ui = await response.getInterface();
|
|
53
|
+
* expect(ui).toRender(panel([heading('Hello, world!')]));
|
|
54
|
+
*/
|
|
55
|
+
toRender(component: Component): void;
|
|
56
|
+
}
|
|
57
|
+
declare module 'expect' {
|
|
58
|
+
interface AsymmetricMatchers extends SnapsMatchers {
|
|
59
|
+
}
|
|
60
|
+
interface Matchers<R> extends SnapsMatchers {
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
declare global {
|
|
64
|
+
namespace jest {
|
|
65
|
+
interface Matchers<R> extends SnapsMatchers {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
export {};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AbstractExecutionService } from '@metamask/snaps-controllers';
|
|
2
|
-
import type { SnapId
|
|
2
|
+
import type { SnapId } from '@metamask/snaps-sdk';
|
|
3
3
|
import type { HandlerType } from '@metamask/snaps-utils';
|
|
4
|
-
import type { RequestOptions, SnapRequest } from '../types';
|
|
4
|
+
import type { RequestOptions, SnapHandlerInterface, SnapRequest } from '../types';
|
|
5
5
|
import type { RunSagaFunction, Store } from './simulation';
|
|
6
6
|
import type { RootControllerMessenger } from './simulation/controllers';
|
|
7
7
|
export declare type HandleRequestOptions = {
|
|
@@ -35,11 +35,20 @@ export declare type HandleRequestOptions = {
|
|
|
35
35
|
*/
|
|
36
36
|
export declare function handleRequest({ snapId, store, executionService, handler, controllerMessenger, runSaga, request: { id, origin, ...options }, }: HandleRequestOptions): SnapRequest;
|
|
37
37
|
/**
|
|
38
|
-
* Get the
|
|
38
|
+
* Get the interface ID from the result if it's available or create a new interface if the result contains static components.
|
|
39
|
+
*
|
|
40
|
+
* @param result - The handler result object.
|
|
41
|
+
* @param snapId - The Snap ID.
|
|
42
|
+
* @param controllerMessenger - The controller messenger.
|
|
43
|
+
* @returns The interface ID or undefined if the result doesn't include content.
|
|
44
|
+
*/
|
|
45
|
+
export declare function getInterfaceFromResult(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<string | undefined>;
|
|
46
|
+
/**
|
|
47
|
+
* Get the response content from the SnapInterfaceController and include the interaction methods.
|
|
39
48
|
*
|
|
40
49
|
* @param result - The handler result object.
|
|
41
50
|
* @param snapId - The Snap ID.
|
|
42
51
|
* @param controllerMessenger - The controller messenger.
|
|
43
52
|
* @returns The content components if any.
|
|
44
53
|
*/
|
|
45
|
-
export declare function
|
|
54
|
+
export declare function getInterfaceApi(result: unknown, snapId: SnapId, controllerMessenger: RootControllerMessenger): Promise<(() => SnapHandlerInterface) | undefined>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Component, SnapId } from '@metamask/snaps-sdk';
|
|
1
|
+
import type { Button, Component, Input, InterfaceState, SnapId } from '@metamask/snaps-sdk';
|
|
2
2
|
import { DialogType } from '@metamask/snaps-sdk';
|
|
3
|
-
import type
|
|
4
|
-
import type { SnapInterface } from '../../types';
|
|
3
|
+
import { type SagaIterator } from 'redux-saga';
|
|
4
|
+
import type { SnapInterface, SnapInterfaceActions } from '../../types';
|
|
5
5
|
import type { RootControllerMessenger } from './controllers';
|
|
6
6
|
import type { RunSagaFunction } from './store';
|
|
7
7
|
/**
|
|
@@ -10,9 +10,52 @@ import type { RunSagaFunction } from './store';
|
|
|
10
10
|
* @param runSaga - A function to run a saga outside the usual Redux flow.
|
|
11
11
|
* @param type - The type of the interface.
|
|
12
12
|
* @param content - The content to show in the interface.
|
|
13
|
+
* @param interfaceActions - The actions to interact with the interface.
|
|
13
14
|
* @returns The user interface object.
|
|
14
15
|
*/
|
|
15
|
-
export declare function getInterfaceResponse(runSaga: RunSagaFunction, type: DialogType, content: Component): SnapInterface;
|
|
16
|
+
export declare function getInterfaceResponse(runSaga: RunSagaFunction, type: DialogType, content: Component, interfaceActions: SnapInterfaceActions): SnapInterface;
|
|
17
|
+
/**
|
|
18
|
+
* Get a Button or an Input from an interface.
|
|
19
|
+
*
|
|
20
|
+
* @param content - The interface content.
|
|
21
|
+
* @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.
|
|
23
|
+
*/
|
|
24
|
+
export declare function getElement(content: Component, name: string): {
|
|
25
|
+
element: Button | Input;
|
|
26
|
+
form?: string;
|
|
27
|
+
} | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* Click on an element of the Snap interface.
|
|
30
|
+
*
|
|
31
|
+
* @param controllerMessenger - The controller messenger used to call actions.
|
|
32
|
+
* @param id - The interface ID.
|
|
33
|
+
* @param content - The interface content.
|
|
34
|
+
* @param snapId - The Snap ID.
|
|
35
|
+
* @param name - The element name.
|
|
36
|
+
*/
|
|
37
|
+
export declare function clickElement(controllerMessenger: RootControllerMessenger, id: string, content: Component, snapId: SnapId, name: string): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Merge a value in the interface state.
|
|
40
|
+
*
|
|
41
|
+
* @param state - The actual interface state.
|
|
42
|
+
* @param name - The component name that changed value.
|
|
43
|
+
* @param value - The new value.
|
|
44
|
+
* @param form - The form name if the element is in one.
|
|
45
|
+
* @returns The state with the merged value.
|
|
46
|
+
*/
|
|
47
|
+
export declare function mergeValue(state: InterfaceState, name: string, value: string | null, form?: string): InterfaceState;
|
|
48
|
+
/**
|
|
49
|
+
* Type a value in an interface element.
|
|
50
|
+
*
|
|
51
|
+
* @param controllerMessenger - The controller messenger used to call actions.
|
|
52
|
+
* @param id - The interface ID.
|
|
53
|
+
* @param content - The interface Components.
|
|
54
|
+
* @param snapId - The Snap ID.
|
|
55
|
+
* @param name - The element name.
|
|
56
|
+
* @param value - The value to type in the element.
|
|
57
|
+
*/
|
|
58
|
+
export declare function typeInField(controllerMessenger: RootControllerMessenger, id: string, content: Component, snapId: SnapId, name: string, value: string): Promise<void>;
|
|
16
59
|
/**
|
|
17
60
|
* Get a user interface object from a Snap.
|
|
18
61
|
*
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Json } from '@metamask/utils';
|
|
1
2
|
import type { RunSagaFunction } from '../../store';
|
|
2
3
|
/**
|
|
3
4
|
* Get the implementation of the `getSnapState` hook.
|
|
@@ -12,7 +13,7 @@ export declare function getGetSnapStateMethodImplementation(runSaga: RunSagaFunc
|
|
|
12
13
|
* @param runSaga - The function to run a saga outside the usual Redux flow.
|
|
13
14
|
* @returns The implementation of the `updateSnapState` hook.
|
|
14
15
|
*/
|
|
15
|
-
export declare function getUpdateSnapStateMethodImplementation(runSaga: RunSagaFunction): (_snapId: string, newState: string, encrypted?: boolean | undefined) => void;
|
|
16
|
+
export declare function getUpdateSnapStateMethodImplementation(runSaga: RunSagaFunction): (_snapId: string, newState: Record<string, Json>, encrypted?: boolean | undefined) => void;
|
|
16
17
|
/**
|
|
17
18
|
* Get the implementation of the `clearSnapState` hook.
|
|
18
19
|
*
|
|
@@ -2,13 +2,12 @@ import type { SimulationOptions } from '../options';
|
|
|
2
2
|
/**
|
|
3
3
|
* Create a Redux store.
|
|
4
4
|
*
|
|
5
|
-
* @param password - The password to use for state encryption.
|
|
6
5
|
* @param options - The simulation options.
|
|
7
6
|
* @param options.state - The initial state for the Snap.
|
|
8
7
|
* @param options.unencryptedState - The initial unencrypted state for the Snap.
|
|
9
8
|
* @returns A Redux store with the default state.
|
|
10
9
|
*/
|
|
11
|
-
export declare function createStore(
|
|
10
|
+
export declare function createStore({ state, unencryptedState }: SimulationOptions): {
|
|
12
11
|
store: import("@reduxjs/toolkit/dist/configureStore").ToolkitStore<{
|
|
13
12
|
mocks: import("./mocks").MocksState;
|
|
14
13
|
notifications: import("./notifications").NotificationsState;
|
|
@@ -105,48 +105,13 @@ export declare const JsonRpcMockOptionsStruct: import("superstruct").Struct<{
|
|
|
105
105
|
}>;
|
|
106
106
|
export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
107
107
|
content?: import("@metamask/snaps-sdk").Panel | {
|
|
108
|
-
value: string;
|
|
109
|
-
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
110
|
-
sensitive?: boolean | undefined;
|
|
111
|
-
} | {
|
|
112
|
-
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
113
|
-
} | {
|
|
114
|
-
value: string;
|
|
115
|
-
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
116
|
-
} | {
|
|
117
|
-
value: string;
|
|
118
|
-
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
119
|
-
} | {
|
|
120
|
-
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
121
|
-
} | {
|
|
122
|
-
value: string;
|
|
123
|
-
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
124
|
-
markdown?: boolean | undefined;
|
|
125
|
-
} | {
|
|
126
|
-
value: string;
|
|
127
|
-
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
128
|
-
} | {
|
|
129
|
-
value: {
|
|
130
|
-
value: string;
|
|
131
|
-
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
132
|
-
} | {
|
|
133
|
-
value: string;
|
|
134
|
-
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
135
|
-
markdown?: boolean | undefined;
|
|
136
|
-
} | {
|
|
137
|
-
value: string;
|
|
138
|
-
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
139
|
-
};
|
|
140
|
-
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
141
|
-
label: string;
|
|
142
|
-
variant?: "default" | "warning" | "critical" | undefined;
|
|
143
|
-
} | {
|
|
144
108
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
145
109
|
name: string;
|
|
146
110
|
value?: string | undefined;
|
|
147
|
-
|
|
111
|
+
error?: string | undefined;
|
|
148
112
|
inputType?: "number" | "text" | "password" | undefined;
|
|
149
113
|
placeholder?: string | undefined;
|
|
114
|
+
label?: string | undefined;
|
|
150
115
|
} | {
|
|
151
116
|
value: string;
|
|
152
117
|
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
@@ -160,9 +125,10 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
|
160
125
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
161
126
|
name: string;
|
|
162
127
|
value?: string | undefined;
|
|
163
|
-
|
|
128
|
+
error?: string | undefined;
|
|
164
129
|
inputType?: "number" | "text" | "password" | undefined;
|
|
165
130
|
placeholder?: string | undefined;
|
|
131
|
+
label?: string | undefined;
|
|
166
132
|
} | {
|
|
167
133
|
value: string;
|
|
168
134
|
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
@@ -170,9 +136,7 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
|
170
136
|
variant?: "primary" | "secondary" | undefined;
|
|
171
137
|
buttonType?: "button" | "submit" | undefined;
|
|
172
138
|
})[];
|
|
173
|
-
} |
|
|
174
|
-
}, {
|
|
175
|
-
content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
|
|
139
|
+
} | {
|
|
176
140
|
value: string;
|
|
177
141
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
178
142
|
sensitive?: boolean | undefined;
|
|
@@ -191,7 +155,7 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
|
191
155
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
192
156
|
markdown?: boolean | undefined;
|
|
193
157
|
} | {
|
|
194
|
-
value: string
|
|
158
|
+
value: `0x${string}`;
|
|
195
159
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
196
160
|
} | {
|
|
197
161
|
value: {
|
|
@@ -202,19 +166,22 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
|
202
166
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
203
167
|
markdown?: boolean | undefined;
|
|
204
168
|
} | {
|
|
205
|
-
value: string
|
|
169
|
+
value: `0x${string}`;
|
|
206
170
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
207
171
|
};
|
|
208
172
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
209
173
|
label: string;
|
|
210
174
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
211
|
-
} |
|
|
175
|
+
} | undefined;
|
|
176
|
+
}, {
|
|
177
|
+
content: import("superstruct").Struct<import("@metamask/snaps-sdk").Panel | {
|
|
212
178
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
213
179
|
name: string;
|
|
214
180
|
value?: string | undefined;
|
|
215
|
-
|
|
181
|
+
error?: string | undefined;
|
|
216
182
|
inputType?: "number" | "text" | "password" | undefined;
|
|
217
183
|
placeholder?: string | undefined;
|
|
184
|
+
label?: string | undefined;
|
|
218
185
|
} | {
|
|
219
186
|
value: string;
|
|
220
187
|
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
@@ -228,9 +195,10 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
|
228
195
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
229
196
|
name: string;
|
|
230
197
|
value?: string | undefined;
|
|
231
|
-
|
|
198
|
+
error?: string | undefined;
|
|
232
199
|
inputType?: "number" | "text" | "password" | undefined;
|
|
233
200
|
placeholder?: string | undefined;
|
|
201
|
+
label?: string | undefined;
|
|
234
202
|
} | {
|
|
235
203
|
value: string;
|
|
236
204
|
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
@@ -238,21 +206,7 @@ export declare const InterfaceStruct: import("superstruct").Struct<{
|
|
|
238
206
|
variant?: "primary" | "secondary" | undefined;
|
|
239
207
|
buttonType?: "button" | "submit" | undefined;
|
|
240
208
|
})[];
|
|
241
|
-
} | undefined, null>;
|
|
242
|
-
}>;
|
|
243
|
-
export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
244
|
-
response: {
|
|
245
|
-
result: import("@metamask/snaps-sdk").Json;
|
|
246
209
|
} | {
|
|
247
|
-
error: import("@metamask/snaps-sdk").Json;
|
|
248
|
-
};
|
|
249
|
-
id: string;
|
|
250
|
-
notifications: {
|
|
251
|
-
message: string;
|
|
252
|
-
type: "native" | "inApp";
|
|
253
|
-
id: string;
|
|
254
|
-
}[];
|
|
255
|
-
content?: import("@metamask/snaps-sdk").Panel | {
|
|
256
210
|
value: string;
|
|
257
211
|
type: import("@metamask/snaps-sdk").NodeType.Copyable;
|
|
258
212
|
sensitive?: boolean | undefined;
|
|
@@ -271,7 +225,7 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
|
271
225
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
272
226
|
markdown?: boolean | undefined;
|
|
273
227
|
} | {
|
|
274
|
-
value: string
|
|
228
|
+
value: `0x${string}`;
|
|
275
229
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
276
230
|
} | {
|
|
277
231
|
value: {
|
|
@@ -282,43 +236,26 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
|
282
236
|
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
283
237
|
markdown?: boolean | undefined;
|
|
284
238
|
} | {
|
|
285
|
-
value: string
|
|
239
|
+
value: `0x${string}`;
|
|
286
240
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
287
241
|
};
|
|
288
242
|
type: import("@metamask/snaps-sdk").NodeType.Row;
|
|
289
243
|
label: string;
|
|
290
244
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
245
|
+
} | undefined, null>;
|
|
246
|
+
}>;
|
|
247
|
+
export declare const SnapResponseWithoutInterfaceStruct: import("superstruct").Struct<{
|
|
248
|
+
response: {
|
|
249
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
291
250
|
} | {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
301
|
-
name?: string | undefined;
|
|
302
|
-
variant?: "primary" | "secondary" | undefined;
|
|
303
|
-
buttonType?: "button" | "submit" | undefined;
|
|
304
|
-
} | {
|
|
305
|
-
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
306
|
-
name: string;
|
|
307
|
-
children: ({
|
|
308
|
-
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
309
|
-
name: string;
|
|
310
|
-
value?: string | undefined;
|
|
311
|
-
label?: string | undefined;
|
|
312
|
-
inputType?: "number" | "text" | "password" | undefined;
|
|
313
|
-
placeholder?: string | undefined;
|
|
314
|
-
} | {
|
|
315
|
-
value: string;
|
|
316
|
-
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
317
|
-
name?: string | undefined;
|
|
318
|
-
variant?: "primary" | "secondary" | undefined;
|
|
319
|
-
buttonType?: "button" | "submit" | undefined;
|
|
320
|
-
})[];
|
|
321
|
-
} | undefined;
|
|
251
|
+
error: import("@metamask/snaps-sdk").Json;
|
|
252
|
+
};
|
|
253
|
+
id: string;
|
|
254
|
+
notifications: {
|
|
255
|
+
message: string;
|
|
256
|
+
type: "native" | "inApp";
|
|
257
|
+
id: string;
|
|
258
|
+
}[];
|
|
322
259
|
}, {
|
|
323
260
|
id: import("superstruct").Struct<string, null>;
|
|
324
261
|
response: import("superstruct").Struct<{
|
|
@@ -339,71 +276,65 @@ export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
|
339
276
|
message: import("superstruct").Struct<string, null>;
|
|
340
277
|
type: import("superstruct").Struct<"native" | "inApp", null>;
|
|
341
278
|
}>>;
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
} | {
|
|
347
|
-
type: import("@metamask/snaps-sdk").NodeType.Divider;
|
|
348
|
-
} | {
|
|
349
|
-
value: string;
|
|
350
|
-
type: import("@metamask/snaps-sdk").NodeType.Heading;
|
|
351
|
-
} | {
|
|
352
|
-
value: string;
|
|
353
|
-
type: import("@metamask/snaps-sdk").NodeType.Image;
|
|
354
|
-
} | {
|
|
355
|
-
type: import("@metamask/snaps-sdk").NodeType.Spinner;
|
|
356
|
-
} | {
|
|
357
|
-
value: string;
|
|
358
|
-
type: import("@metamask/snaps-sdk").NodeType.Text;
|
|
359
|
-
markdown?: boolean | undefined;
|
|
360
|
-
} | {
|
|
361
|
-
value: string;
|
|
362
|
-
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
279
|
+
}>;
|
|
280
|
+
export declare const SnapResponseWithInterfaceStruct: import("superstruct").Struct<{
|
|
281
|
+
response: {
|
|
282
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
363
283
|
} | {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
variant?: "default" | "warning" | "critical" | undefined;
|
|
284
|
+
error: import("@metamask/snaps-sdk").Json;
|
|
285
|
+
};
|
|
286
|
+
id: string;
|
|
287
|
+
getInterface: Function;
|
|
288
|
+
notifications: {
|
|
289
|
+
message: string;
|
|
290
|
+
type: "native" | "inApp";
|
|
291
|
+
id: string;
|
|
292
|
+
}[];
|
|
293
|
+
}, {
|
|
294
|
+
getInterface: import("superstruct").Struct<Function, null>;
|
|
295
|
+
response: import("superstruct").Struct<{
|
|
296
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
378
297
|
} | {
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
298
|
+
error: import("@metamask/snaps-sdk").Json;
|
|
299
|
+
}, null>;
|
|
300
|
+
id: import("superstruct").Struct<string, null>;
|
|
301
|
+
notifications: import("superstruct").Struct<{
|
|
302
|
+
message: string;
|
|
303
|
+
type: "native" | "inApp";
|
|
304
|
+
id: string;
|
|
305
|
+
}[], import("superstruct").Struct<{
|
|
306
|
+
message: string;
|
|
307
|
+
type: "native" | "inApp";
|
|
308
|
+
id: string;
|
|
309
|
+
}, {
|
|
310
|
+
id: import("superstruct").Struct<string, null>;
|
|
311
|
+
message: import("superstruct").Struct<string, null>;
|
|
312
|
+
type: import("superstruct").Struct<"native" | "inApp", null>;
|
|
313
|
+
}>>;
|
|
314
|
+
}>;
|
|
315
|
+
export declare const SnapResponseStruct: import("superstruct").Struct<{
|
|
316
|
+
response: {
|
|
317
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
385
318
|
} | {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
319
|
+
error: import("@metamask/snaps-sdk").Json;
|
|
320
|
+
};
|
|
321
|
+
id: string;
|
|
322
|
+
notifications: {
|
|
323
|
+
message: string;
|
|
324
|
+
type: "native" | "inApp";
|
|
325
|
+
id: string;
|
|
326
|
+
}[];
|
|
327
|
+
} | {
|
|
328
|
+
response: {
|
|
329
|
+
result: import("@metamask/snaps-sdk").Json;
|
|
391
330
|
} | {
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
value: string;
|
|
403
|
-
type: import("@metamask/snaps-sdk").NodeType.Button;
|
|
404
|
-
name?: string | undefined;
|
|
405
|
-
variant?: "primary" | "secondary" | undefined;
|
|
406
|
-
buttonType?: "button" | "submit" | undefined;
|
|
407
|
-
})[];
|
|
408
|
-
} | undefined, null>;
|
|
409
|
-
}>;
|
|
331
|
+
error: import("@metamask/snaps-sdk").Json;
|
|
332
|
+
};
|
|
333
|
+
id: string;
|
|
334
|
+
getInterface: Function;
|
|
335
|
+
notifications: {
|
|
336
|
+
message: string;
|
|
337
|
+
type: "native" | "inApp";
|
|
338
|
+
id: string;
|
|
339
|
+
}[];
|
|
340
|
+
}, null>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,21 +1,8 @@
|
|
|
1
|
-
import type { NotificationType, EnumToUnion
|
|
1
|
+
import type { Component, NotificationType, EnumToUnion } from '@metamask/snaps-sdk';
|
|
2
|
+
import type { InferMatching } from '@metamask/snaps-utils';
|
|
2
3
|
import type { Json, JsonRpcId, JsonRpcParams } from '@metamask/utils';
|
|
3
4
|
import type { Infer } from 'superstruct';
|
|
4
5
|
import type { SignatureOptionsStruct, SnapOptionsStruct, SnapResponseStruct, TransactionOptionsStruct } from './internals';
|
|
5
|
-
declare module 'expect' {
|
|
6
|
-
interface AsymmetricMatchers {
|
|
7
|
-
toRespondWith(response: unknown): void;
|
|
8
|
-
toRespondWithError(error: unknown): void;
|
|
9
|
-
toSendNotification(message: string, type?: EnumToUnion<NotificationType>): void;
|
|
10
|
-
toRender(component: Component): void;
|
|
11
|
-
}
|
|
12
|
-
interface Matchers<R> {
|
|
13
|
-
toRespondWith(response: unknown): R;
|
|
14
|
-
toRespondWithError(error: unknown): R;
|
|
15
|
-
toSendNotification(message: string, type?: EnumToUnion<NotificationType>): R;
|
|
16
|
-
toRender(component: Component): R;
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
6
|
export declare type RequestOptions = {
|
|
20
7
|
/**
|
|
21
8
|
* The JSON-RPC request ID.
|
|
@@ -78,6 +65,21 @@ export declare type SignatureOptions = Infer<typeof SignatureOptionsStruct>;
|
|
|
78
65
|
* @property timeout - The timeout in milliseconds to use. Defaults to `1000`.
|
|
79
66
|
*/
|
|
80
67
|
export declare type SnapOptions = Infer<typeof SnapOptionsStruct>;
|
|
68
|
+
export declare type SnapInterfaceActions = {
|
|
69
|
+
/**
|
|
70
|
+
* Click on an interface element.
|
|
71
|
+
*
|
|
72
|
+
* @param name - The element name to click.
|
|
73
|
+
*/
|
|
74
|
+
clickElement(name: string): Promise<void>;
|
|
75
|
+
/**
|
|
76
|
+
* Type a value in a interface field.
|
|
77
|
+
*
|
|
78
|
+
* @param name - The element name to type in.
|
|
79
|
+
* @param value - The value to type.
|
|
80
|
+
*/
|
|
81
|
+
typeInField(name: string, value: string): Promise<void>;
|
|
82
|
+
};
|
|
81
83
|
/**
|
|
82
84
|
* A `snap_dialog` alert interface.
|
|
83
85
|
*/
|
|
@@ -139,7 +141,7 @@ export declare type SnapPromptInterface = {
|
|
|
139
141
|
*/
|
|
140
142
|
cancel(): Promise<void>;
|
|
141
143
|
};
|
|
142
|
-
export declare type SnapInterface = SnapAlertInterface | SnapConfirmationInterface | SnapPromptInterface;
|
|
144
|
+
export declare type SnapInterface = (SnapAlertInterface | SnapConfirmationInterface | SnapPromptInterface) & SnapInterfaceActions;
|
|
143
145
|
export declare type SnapRequestObject = {
|
|
144
146
|
/**
|
|
145
147
|
* Get a user interface object from a snap. This will throw an error if the
|
|
@@ -200,7 +202,7 @@ export declare type Snap = {
|
|
|
200
202
|
* will be filled in with default values.
|
|
201
203
|
* @returns The response.
|
|
202
204
|
*/
|
|
203
|
-
onTransaction(transaction?: Partial<TransactionOptions>): Promise<
|
|
205
|
+
onTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponseWithInterface>;
|
|
204
206
|
/**
|
|
205
207
|
* Send a transaction to the snap.
|
|
206
208
|
*
|
|
@@ -210,7 +212,7 @@ export declare type Snap = {
|
|
|
210
212
|
* @returns The response.
|
|
211
213
|
* @deprecated Use {@link onTransaction} instead.
|
|
212
214
|
*/
|
|
213
|
-
sendTransaction(transaction?: Partial<TransactionOptions>): Promise<
|
|
215
|
+
sendTransaction(transaction?: Partial<TransactionOptions>): Promise<SnapResponseWithInterface>;
|
|
214
216
|
/**
|
|
215
217
|
* Send a signature request to the snap.
|
|
216
218
|
*
|
|
@@ -219,7 +221,7 @@ export declare type Snap = {
|
|
|
219
221
|
* Any missing fields will be filled in with default values.
|
|
220
222
|
* @returns The response.
|
|
221
223
|
*/
|
|
222
|
-
onSignature(signature?: Partial<SignatureOptions>): Promise<
|
|
224
|
+
onSignature(signature?: Partial<SignatureOptions>): Promise<SnapResponseWithInterface>;
|
|
223
225
|
/**
|
|
224
226
|
* Run a cronjob in the snap. This is similar to {@link request}, but the
|
|
225
227
|
* request will be sent to the `onCronjob` method of the snap.
|
|
@@ -246,7 +248,7 @@ export declare type Snap = {
|
|
|
246
248
|
*
|
|
247
249
|
* @returns The response.
|
|
248
250
|
*/
|
|
249
|
-
onHomePage(): Promise<
|
|
251
|
+
onHomePage(): Promise<SnapResponseWithInterface>;
|
|
250
252
|
/**
|
|
251
253
|
* Mock a JSON-RPC request. This will cause the snap to respond with the
|
|
252
254
|
* specified response when a request with the specified method is sent.
|
|
@@ -282,4 +284,23 @@ export declare type Snap = {
|
|
|
282
284
|
*/
|
|
283
285
|
close(): Promise<void>;
|
|
284
286
|
};
|
|
285
|
-
export declare type
|
|
287
|
+
export declare type SnapHandlerInterface = {
|
|
288
|
+
content: Component;
|
|
289
|
+
} & SnapInterfaceActions;
|
|
290
|
+
export declare type SnapResponseWithInterface = {
|
|
291
|
+
id: string;
|
|
292
|
+
response: {
|
|
293
|
+
result: Json;
|
|
294
|
+
} | {
|
|
295
|
+
error: Json;
|
|
296
|
+
};
|
|
297
|
+
notifications: {
|
|
298
|
+
id: string;
|
|
299
|
+
message: string;
|
|
300
|
+
type: EnumToUnion<NotificationType>;
|
|
301
|
+
}[];
|
|
302
|
+
getInterface(): SnapHandlerInterface;
|
|
303
|
+
};
|
|
304
|
+
export declare type SnapResponseWithoutInterface = Omit<SnapResponseWithInterface, 'getInterface'>;
|
|
305
|
+
export declare type SnapResponseType = SnapResponseWithoutInterface | SnapResponseWithInterface;
|
|
306
|
+
export declare type SnapResponse = InferMatching<typeof SnapResponseStruct, SnapResponseType>;
|