@metamask/snaps-rpc-methods 15.1.0 → 16.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 +34 -4
- package/dist/endowments/keyring.cjs +2 -5
- package/dist/endowments/keyring.cjs.map +1 -1
- package/dist/endowments/keyring.d.cts +0 -2
- package/dist/endowments/keyring.d.cts.map +1 -1
- package/dist/endowments/keyring.d.mts +0 -2
- package/dist/endowments/keyring.d.mts.map +1 -1
- package/dist/endowments/keyring.mjs +3 -6
- package/dist/endowments/keyring.mjs.map +1 -1
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/permissions.cjs +18 -8
- package/dist/permissions.cjs.map +1 -1
- package/dist/permissions.d.cts +3 -2
- package/dist/permissions.d.cts.map +1 -1
- package/dist/permissions.d.mts +3 -2
- package/dist/permissions.d.mts.map +1 -1
- package/dist/permissions.mjs +17 -7
- package/dist/permissions.mjs.map +1 -1
- package/dist/permitted/cancelBackgroundEvent.cjs +10 -14
- package/dist/permitted/cancelBackgroundEvent.cjs.map +1 -1
- package/dist/permitted/cancelBackgroundEvent.d.cts +9 -12
- package/dist/permitted/cancelBackgroundEvent.d.cts.map +1 -1
- package/dist/permitted/cancelBackgroundEvent.d.mts +9 -12
- package/dist/permitted/cancelBackgroundEvent.d.mts.map +1 -1
- package/dist/permitted/cancelBackgroundEvent.mjs +10 -14
- package/dist/permitted/cancelBackgroundEvent.mjs.map +1 -1
- package/dist/permitted/clearState.cjs +10 -16
- package/dist/permitted/clearState.cjs.map +1 -1
- package/dist/permitted/clearState.d.cts +9 -23
- package/dist/permitted/clearState.d.cts.map +1 -1
- package/dist/permitted/clearState.d.mts +9 -23
- package/dist/permitted/clearState.d.mts.map +1 -1
- package/dist/permitted/clearState.mjs +10 -16
- package/dist/permitted/clearState.mjs.map +1 -1
- package/dist/permitted/closeWebSocket.cjs +7 -14
- package/dist/permitted/closeWebSocket.cjs.map +1 -1
- package/dist/permitted/closeWebSocket.d.cts +9 -12
- package/dist/permitted/closeWebSocket.d.cts.map +1 -1
- package/dist/permitted/closeWebSocket.d.mts +9 -12
- package/dist/permitted/closeWebSocket.d.mts.map +1 -1
- package/dist/permitted/closeWebSocket.mjs +7 -14
- package/dist/permitted/closeWebSocket.mjs.map +1 -1
- package/dist/permitted/createInterface.cjs +11 -15
- package/dist/permitted/createInterface.cjs.map +1 -1
- package/dist/permitted/createInterface.d.cts +23 -37
- package/dist/permitted/createInterface.d.cts.map +1 -1
- package/dist/permitted/createInterface.d.mts +23 -37
- package/dist/permitted/createInterface.d.mts.map +1 -1
- package/dist/permitted/createInterface.mjs +11 -15
- package/dist/permitted/createInterface.mjs.map +1 -1
- package/dist/permitted/endTrace.cjs +4 -6
- package/dist/permitted/endTrace.cjs.map +1 -1
- package/dist/permitted/endTrace.d.cts +8 -11
- package/dist/permitted/endTrace.d.cts.map +1 -1
- package/dist/permitted/endTrace.d.mts +8 -11
- package/dist/permitted/endTrace.d.mts.map +1 -1
- package/dist/permitted/endTrace.mjs +4 -6
- package/dist/permitted/endTrace.mjs.map +1 -1
- package/dist/permitted/getAllSnaps.cjs +5 -11
- package/dist/permitted/getAllSnaps.cjs.map +1 -1
- package/dist/permitted/getAllSnaps.d.cts +10 -14
- package/dist/permitted/getAllSnaps.d.cts.map +1 -1
- package/dist/permitted/getAllSnaps.d.mts +10 -14
- package/dist/permitted/getAllSnaps.d.mts.map +1 -1
- package/dist/permitted/getAllSnaps.mjs +5 -11
- package/dist/permitted/getAllSnaps.mjs.map +1 -1
- package/dist/permitted/getBackgroundEvents.cjs +8 -15
- package/dist/permitted/getBackgroundEvents.cjs.map +1 -1
- package/dist/permitted/getBackgroundEvents.d.cts +10 -13
- package/dist/permitted/getBackgroundEvents.d.cts.map +1 -1
- package/dist/permitted/getBackgroundEvents.d.mts +10 -13
- package/dist/permitted/getBackgroundEvents.d.mts.map +1 -1
- package/dist/permitted/getBackgroundEvents.mjs +8 -15
- package/dist/permitted/getBackgroundEvents.mjs.map +1 -1
- package/dist/permitted/getClientStatus.cjs +5 -6
- package/dist/permitted/getClientStatus.cjs.map +1 -1
- package/dist/permitted/getClientStatus.d.cts +17 -18
- package/dist/permitted/getClientStatus.d.cts.map +1 -1
- package/dist/permitted/getClientStatus.d.mts +17 -18
- package/dist/permitted/getClientStatus.d.mts.map +1 -1
- package/dist/permitted/getClientStatus.mjs +5 -6
- package/dist/permitted/getClientStatus.mjs.map +1 -1
- package/dist/permitted/getFile.cjs +7 -11
- package/dist/permitted/getFile.cjs.map +1 -1
- package/dist/permitted/getFile.d.cts +8 -10
- package/dist/permitted/getFile.d.cts.map +1 -1
- package/dist/permitted/getFile.d.mts +8 -10
- package/dist/permitted/getFile.d.mts.map +1 -1
- package/dist/permitted/getFile.mjs +7 -11
- package/dist/permitted/getFile.mjs.map +1 -1
- package/dist/permitted/getInterfaceContext.cjs +12 -15
- package/dist/permitted/getInterfaceContext.cjs.map +1 -1
- package/dist/permitted/getInterfaceContext.d.cts +9 -21
- package/dist/permitted/getInterfaceContext.d.cts.map +1 -1
- package/dist/permitted/getInterfaceContext.d.mts +9 -21
- package/dist/permitted/getInterfaceContext.d.mts.map +1 -1
- package/dist/permitted/getInterfaceContext.mjs +12 -15
- package/dist/permitted/getInterfaceContext.mjs.map +1 -1
- package/dist/permitted/getInterfaceState.cjs +11 -15
- package/dist/permitted/getInterfaceState.cjs.map +1 -1
- package/dist/permitted/getInterfaceState.d.cts +9 -21
- package/dist/permitted/getInterfaceState.d.cts.map +1 -1
- package/dist/permitted/getInterfaceState.d.mts +9 -21
- package/dist/permitted/getInterfaceState.d.mts.map +1 -1
- package/dist/permitted/getInterfaceState.mjs +11 -15
- package/dist/permitted/getInterfaceState.mjs.map +1 -1
- package/dist/permitted/getSnaps.cjs +6 -12
- package/dist/permitted/getSnaps.cjs.map +1 -1
- package/dist/permitted/getSnaps.d.cts +11 -14
- package/dist/permitted/getSnaps.d.cts.map +1 -1
- package/dist/permitted/getSnaps.d.mts +11 -14
- package/dist/permitted/getSnaps.d.mts.map +1 -1
- package/dist/permitted/getSnaps.mjs +6 -12
- package/dist/permitted/getSnaps.mjs.map +1 -1
- package/dist/permitted/getState.cjs +9 -11
- package/dist/permitted/getState.cjs.map +1 -1
- package/dist/permitted/getState.d.cts +17 -28
- package/dist/permitted/getState.d.cts.map +1 -1
- package/dist/permitted/getState.d.mts +17 -28
- package/dist/permitted/getState.d.mts.map +1 -1
- package/dist/permitted/getState.mjs +9 -11
- package/dist/permitted/getState.mjs.map +1 -1
- package/dist/permitted/getWebSockets.cjs +11 -14
- package/dist/permitted/getWebSockets.cjs.map +1 -1
- package/dist/permitted/getWebSockets.d.cts +10 -13
- package/dist/permitted/getWebSockets.d.cts.map +1 -1
- package/dist/permitted/getWebSockets.d.mts +10 -13
- package/dist/permitted/getWebSockets.d.mts.map +1 -1
- package/dist/permitted/getWebSockets.mjs +11 -14
- package/dist/permitted/getWebSockets.mjs.map +1 -1
- package/dist/permitted/index.cjs +0 -1
- package/dist/permitted/index.cjs.map +1 -1
- package/dist/permitted/index.d.cts +29 -25
- package/dist/permitted/index.d.cts.map +1 -1
- package/dist/permitted/index.d.mts +29 -25
- package/dist/permitted/index.d.mts.map +1 -1
- package/dist/permitted/index.mjs +0 -1
- package/dist/permitted/index.mjs.map +1 -1
- package/dist/permitted/invokeKeyring.cjs +12 -13
- package/dist/permitted/invokeKeyring.cjs.map +1 -1
- package/dist/permitted/invokeKeyring.d.cts +17 -16
- package/dist/permitted/invokeKeyring.d.cts.map +1 -1
- package/dist/permitted/invokeKeyring.d.mts +17 -16
- package/dist/permitted/invokeKeyring.d.mts.map +1 -1
- package/dist/permitted/invokeKeyring.mjs +12 -13
- package/dist/permitted/invokeKeyring.mjs.map +1 -1
- package/dist/permitted/invokeSnapSugar.cjs +6 -10
- package/dist/permitted/invokeSnapSugar.cjs.map +1 -1
- package/dist/permitted/invokeSnapSugar.d.cts +9 -12
- package/dist/permitted/invokeSnapSugar.d.cts.map +1 -1
- package/dist/permitted/invokeSnapSugar.d.mts +9 -12
- package/dist/permitted/invokeSnapSugar.d.mts.map +1 -1
- package/dist/permitted/invokeSnapSugar.mjs +6 -10
- package/dist/permitted/invokeSnapSugar.mjs.map +1 -1
- package/dist/permitted/listEntropySources.cjs +28 -12
- package/dist/permitted/listEntropySources.cjs.map +1 -1
- package/dist/permitted/listEntropySources.d.cts +12 -23
- package/dist/permitted/listEntropySources.d.cts.map +1 -1
- package/dist/permitted/listEntropySources.d.mts +12 -23
- package/dist/permitted/listEntropySources.d.mts.map +1 -1
- package/dist/permitted/listEntropySources.mjs +28 -12
- package/dist/permitted/listEntropySources.mjs.map +1 -1
- package/dist/permitted/middleware.cjs +70 -20
- package/dist/permitted/middleware.cjs.map +1 -1
- package/dist/permitted/middleware.d.cts +5 -2
- package/dist/permitted/middleware.d.cts.map +1 -1
- package/dist/permitted/middleware.d.mts +5 -2
- package/dist/permitted/middleware.d.mts.map +1 -1
- package/dist/permitted/middleware.mjs +70 -20
- package/dist/permitted/middleware.mjs.map +1 -1
- package/dist/permitted/openWebSocket.cjs +7 -14
- package/dist/permitted/openWebSocket.cjs.map +1 -1
- package/dist/permitted/openWebSocket.d.cts +9 -12
- package/dist/permitted/openWebSocket.d.cts.map +1 -1
- package/dist/permitted/openWebSocket.d.mts +9 -12
- package/dist/permitted/openWebSocket.d.mts.map +1 -1
- package/dist/permitted/openWebSocket.mjs +7 -14
- package/dist/permitted/openWebSocket.mjs.map +1 -1
- package/dist/permitted/requestSnaps.cjs +14 -19
- package/dist/permitted/requestSnaps.cjs.map +1 -1
- package/dist/permitted/requestSnaps.d.cts +9 -36
- package/dist/permitted/requestSnaps.d.cts.map +1 -1
- package/dist/permitted/requestSnaps.d.mts +9 -36
- package/dist/permitted/requestSnaps.d.mts.map +1 -1
- package/dist/permitted/requestSnaps.mjs +15 -20
- package/dist/permitted/requestSnaps.mjs.map +1 -1
- package/dist/permitted/resolveInterface.cjs +11 -15
- package/dist/permitted/resolveInterface.cjs.map +1 -1
- package/dist/permitted/resolveInterface.d.cts +12 -24
- package/dist/permitted/resolveInterface.d.cts.map +1 -1
- package/dist/permitted/resolveInterface.d.mts +12 -24
- package/dist/permitted/resolveInterface.d.mts.map +1 -1
- package/dist/permitted/resolveInterface.mjs +11 -15
- package/dist/permitted/resolveInterface.mjs.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.cjs +11 -14
- package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.cts +10 -17
- package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.mts +10 -17
- package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.mjs +11 -14
- package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -1
- package/dist/permitted/sendWebSocketMessage.cjs +10 -14
- package/dist/permitted/sendWebSocketMessage.cjs.map +1 -1
- package/dist/permitted/sendWebSocketMessage.d.cts +9 -12
- package/dist/permitted/sendWebSocketMessage.d.cts.map +1 -1
- package/dist/permitted/sendWebSocketMessage.d.mts +9 -12
- package/dist/permitted/sendWebSocketMessage.d.mts.map +1 -1
- package/dist/permitted/sendWebSocketMessage.mjs +10 -14
- package/dist/permitted/sendWebSocketMessage.mjs.map +1 -1
- package/dist/permitted/setState.cjs +18 -21
- package/dist/permitted/setState.cjs.map +1 -1
- package/dist/permitted/setState.d.cts +18 -45
- package/dist/permitted/setState.d.cts.map +1 -1
- package/dist/permitted/setState.d.mts +18 -45
- package/dist/permitted/setState.d.mts.map +1 -1
- package/dist/permitted/setState.mjs +18 -21
- package/dist/permitted/setState.mjs.map +1 -1
- package/dist/permitted/startTrace.cjs +4 -6
- package/dist/permitted/startTrace.cjs.map +1 -1
- package/dist/permitted/startTrace.d.cts +8 -11
- package/dist/permitted/startTrace.d.cts.map +1 -1
- package/dist/permitted/startTrace.d.mts +8 -11
- package/dist/permitted/startTrace.d.mts.map +1 -1
- package/dist/permitted/startTrace.mjs +4 -6
- package/dist/permitted/startTrace.mjs.map +1 -1
- package/dist/permitted/trackError.cjs +4 -6
- package/dist/permitted/trackError.cjs.map +1 -1
- package/dist/permitted/trackError.d.cts +8 -11
- package/dist/permitted/trackError.d.cts.map +1 -1
- package/dist/permitted/trackError.d.mts +8 -11
- package/dist/permitted/trackError.d.mts.map +1 -1
- package/dist/permitted/trackError.mjs +4 -6
- package/dist/permitted/trackError.mjs.map +1 -1
- package/dist/permitted/trackEvent.cjs +4 -6
- package/dist/permitted/trackEvent.cjs.map +1 -1
- package/dist/permitted/trackEvent.d.cts +8 -11
- package/dist/permitted/trackEvent.d.cts.map +1 -1
- package/dist/permitted/trackEvent.d.mts +8 -11
- package/dist/permitted/trackEvent.d.mts.map +1 -1
- package/dist/permitted/trackEvent.mjs +4 -6
- package/dist/permitted/trackEvent.mjs.map +1 -1
- package/dist/permitted/updateInterface.cjs +11 -15
- package/dist/permitted/updateInterface.cjs.map +1 -1
- package/dist/permitted/updateInterface.d.cts +9 -22
- package/dist/permitted/updateInterface.d.cts.map +1 -1
- package/dist/permitted/updateInterface.d.mts +9 -22
- package/dist/permitted/updateInterface.d.mts.map +1 -1
- package/dist/permitted/updateInterface.mjs +11 -15
- package/dist/permitted/updateInterface.mjs.map +1 -1
- package/dist/restricted/dialog.cjs +23 -30
- package/dist/restricted/dialog.cjs.map +1 -1
- package/dist/restricted/dialog.d.cts +10 -58
- package/dist/restricted/dialog.d.cts.map +1 -1
- package/dist/restricted/dialog.d.mts +10 -58
- package/dist/restricted/dialog.d.mts.map +1 -1
- package/dist/restricted/dialog.mjs +23 -30
- package/dist/restricted/dialog.mjs.map +1 -1
- package/dist/restricted/getBip32Entropy.cjs +15 -12
- package/dist/restricted/getBip32Entropy.cjs.map +1 -1
- package/dist/restricted/getBip32Entropy.d.cts +11 -24
- package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip32Entropy.d.mts +11 -24
- package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip32Entropy.mjs +16 -13
- package/dist/restricted/getBip32Entropy.mjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.cjs +15 -12
- package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.cts +11 -24
- package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.mts +11 -24
- package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
- package/dist/restricted/getBip32PublicKey.mjs +16 -13
- package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
- package/dist/restricted/getBip44Entropy.cjs +14 -10
- package/dist/restricted/getBip44Entropy.cjs.map +1 -1
- package/dist/restricted/getBip44Entropy.d.cts +11 -15
- package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip44Entropy.d.mts +11 -15
- package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip44Entropy.mjs +15 -11
- package/dist/restricted/getBip44Entropy.mjs.map +1 -1
- package/dist/restricted/getEntropy.cjs +10 -10
- package/dist/restricted/getEntropy.cjs.map +1 -1
- package/dist/restricted/getEntropy.d.cts +11 -15
- package/dist/restricted/getEntropy.d.cts.map +1 -1
- package/dist/restricted/getEntropy.d.mts +11 -15
- package/dist/restricted/getEntropy.d.mts.map +1 -1
- package/dist/restricted/getEntropy.mjs +11 -11
- package/dist/restricted/getEntropy.mjs.map +1 -1
- package/dist/restricted/index.cjs.map +1 -1
- package/dist/restricted/index.d.cts +20 -160
- package/dist/restricted/index.d.cts.map +1 -1
- package/dist/restricted/index.d.mts +20 -160
- package/dist/restricted/index.d.mts.map +1 -1
- package/dist/restricted/index.mjs.map +1 -1
- package/dist/restricted/invokeSnap.cjs +11 -12
- package/dist/restricted/invokeSnap.cjs.map +1 -1
- package/dist/restricted/invokeSnap.d.cts +9 -13
- package/dist/restricted/invokeSnap.d.cts.map +1 -1
- package/dist/restricted/invokeSnap.d.mts +9 -13
- package/dist/restricted/invokeSnap.d.mts.map +1 -1
- package/dist/restricted/invokeSnap.mjs +11 -12
- package/dist/restricted/invokeSnap.mjs.map +1 -1
- package/dist/restricted/manageState.cjs +21 -20
- package/dist/restricted/manageState.cjs.map +1 -1
- package/dist/restricted/manageState.d.cts +12 -34
- package/dist/restricted/manageState.d.cts.map +1 -1
- package/dist/restricted/manageState.d.mts +12 -34
- package/dist/restricted/manageState.d.mts.map +1 -1
- package/dist/restricted/manageState.mjs +21 -20
- package/dist/restricted/manageState.mjs.map +1 -1
- package/dist/restricted/notify.cjs +31 -24
- package/dist/restricted/notify.cjs.map +1 -1
- package/dist/restricted/notify.d.cts +16 -25
- package/dist/restricted/notify.d.cts.map +1 -1
- package/dist/restricted/notify.d.mts +16 -25
- package/dist/restricted/notify.d.mts.map +1 -1
- package/dist/restricted/notify.mjs +32 -25
- package/dist/restricted/notify.mjs.map +1 -1
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +155 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +155 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +78 -24
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +21 -13
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +21 -13
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +75 -22
- package/dist/utils.mjs.map +1 -1
- package/package.json +6 -6
- package/dist/permitted/handlers.cjs +0 -63
- package/dist/permitted/handlers.cjs.map +0 -1
- package/dist/permitted/handlers.d.cts +0 -299
- package/dist/permitted/handlers.d.cts.map +0 -1
- package/dist/permitted/handlers.d.mts +0 -299
- package/dist/permitted/handlers.d.mts.map +0 -1
- package/dist/permitted/handlers.mjs +0 -60
- package/dist/permitted/handlers.mjs.map +0 -1
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
2
3
|
import type { GetFileParams, GetFileResult } from "@metamask/snaps-sdk";
|
|
3
4
|
import type { InferMatching } from "@metamask/snaps-utils";
|
|
4
|
-
import type { PendingJsonRpcResponse
|
|
5
|
-
import type {
|
|
5
|
+
import type { PendingJsonRpcResponse } from "@metamask/utils";
|
|
6
|
+
import type { JsonRpcRequestWithOrigin, SnapControllerGetSnapFileAction } from "../types.mjs";
|
|
6
7
|
export declare const GetFileArgsStruct: import("@metamask/superstruct").Struct<{
|
|
7
8
|
path: string;
|
|
8
9
|
encoding?: "base64" | "hex" | "utf8" | undefined;
|
|
@@ -11,6 +12,7 @@ export declare const GetFileArgsStruct: import("@metamask/superstruct").Struct<{
|
|
|
11
12
|
encoding: import("@metamask/superstruct").Struct<"base64" | "hex" | "utf8" | undefined, null>;
|
|
12
13
|
}>;
|
|
13
14
|
export type InferredGetFileParams = InferMatching<typeof GetFileArgsStruct, GetFileParams>;
|
|
15
|
+
export type GetFileMethodActions = SnapControllerGetSnapFileAction;
|
|
14
16
|
/**
|
|
15
17
|
* Gets a static file's content in UTF-8, Base64, or hexadecimal.
|
|
16
18
|
*
|
|
@@ -38,12 +40,8 @@ export type InferredGetFileParams = InferMatching<typeof GetFileArgsStruct, GetF
|
|
|
38
40
|
* ```
|
|
39
41
|
*/
|
|
40
42
|
export declare const getFileHandler: {
|
|
41
|
-
methodNames: ["snap_getFile"];
|
|
42
43
|
implementation: typeof implementation;
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
export type GetFileHooks = {
|
|
46
|
-
getSnapFile: (path: InferredGetFileParams['path'], encoding: InferredGetFileParams['encoding']) => Promise<string>;
|
|
44
|
+
actionNames: "SnapController:getSnapFile"[];
|
|
47
45
|
};
|
|
48
46
|
/**
|
|
49
47
|
* The `snap_getFile` method implementation.
|
|
@@ -53,10 +51,10 @@ export type GetFileHooks = {
|
|
|
53
51
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
54
52
|
* function.
|
|
55
53
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
56
|
-
* @param
|
|
57
|
-
* @param
|
|
54
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
55
|
+
* @param messenger - The messenger used to call controller actions.
|
|
58
56
|
* @returns Nothing.
|
|
59
57
|
*/
|
|
60
|
-
declare function implementation(req:
|
|
58
|
+
declare function implementation(req: JsonRpcRequestWithOrigin<InferredGetFileParams>, res: PendingJsonRpcResponse<GetFileResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, GetFileMethodActions>): Promise<void>;
|
|
61
59
|
export {};
|
|
62
60
|
//# sourceMappingURL=getFile.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFile.d.mts","sourceRoot":"","sources":["../../src/permitted/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"getFile.d.mts","sourceRoot":"","sources":["../../src/permitted/getFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,4BAA4B;AAExE,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAG9D,OAAO,KAAK,EACV,wBAAwB,EACxB,+BAA+B,EAChC,qBAAiB;AAElB,eAAO,MAAM,iBAAiB;;;;;;EAS5B,CAAC;AAEH,MAAM,MAAM,qBAAqB,GAAG,aAAa,CAC/C,OAAO,iBAAiB,EACxB,aAAa,CACd,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAEnE;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,cAAc;;;CAS1B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,iBAAe,cAAc,CAC3B,GAAG,EAAE,wBAAwB,CAAC,qBAAqB,CAAC,EACpD,GAAG,EAAE,sBAAsB,CAAC,aAAa,CAAC,EAC1C,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,oBAAoB,CAAC,GACjD,OAAO,CAAC,IAAI,CAAC,CAuBf"}
|
|
@@ -10,10 +10,6 @@ export const GetFileArgsStruct = object({
|
|
|
10
10
|
enumValue(AuxiliaryFileEncoding.Utf8),
|
|
11
11
|
])),
|
|
12
12
|
});
|
|
13
|
-
const methodName = 'snap_getFile';
|
|
14
|
-
const hookNames = {
|
|
15
|
-
getSnapFile: true,
|
|
16
|
-
};
|
|
17
13
|
/**
|
|
18
14
|
* Gets a static file's content in UTF-8, Base64, or hexadecimal.
|
|
19
15
|
*
|
|
@@ -41,9 +37,8 @@ const hookNames = {
|
|
|
41
37
|
* ```
|
|
42
38
|
*/
|
|
43
39
|
export const getFileHandler = {
|
|
44
|
-
methodNames: [methodName],
|
|
45
40
|
implementation,
|
|
46
|
-
|
|
41
|
+
actionNames: ['SnapController:getSnapFile'],
|
|
47
42
|
};
|
|
48
43
|
/**
|
|
49
44
|
* The `snap_getFile` method implementation.
|
|
@@ -53,15 +48,16 @@ export const getFileHandler = {
|
|
|
53
48
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
54
49
|
* function.
|
|
55
50
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
56
|
-
* @param
|
|
57
|
-
* @param
|
|
51
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
52
|
+
* @param messenger - The messenger used to call controller actions.
|
|
58
53
|
* @returns Nothing.
|
|
59
54
|
*/
|
|
60
|
-
async function implementation(req, res, _next, end,
|
|
61
|
-
const { params } = req;
|
|
55
|
+
async function implementation(req, res, _next, end, _hooks, messenger) {
|
|
56
|
+
const { params, origin } = req;
|
|
62
57
|
assertStruct(params, GetFileArgsStruct, 'Invalid "snap_getFile" parameters', rpcErrors.invalidParams);
|
|
63
58
|
try {
|
|
64
|
-
res.result = await getSnapFile
|
|
59
|
+
res.result = await messenger.call('SnapController:getSnapFile', origin, params.path, params.encoding ??
|
|
60
|
+
AuxiliaryFileEncoding.Base64);
|
|
65
61
|
}
|
|
66
62
|
catch (error) {
|
|
67
63
|
return end(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getFile.mjs","sourceRoot":"","sources":["../../src/permitted/getFile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getFile.mjs","sourceRoot":"","sources":["../../src/permitted/getFile.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,qBAAqB,EAAE,SAAS,EAAE,4BAA4B;AAEvE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,8BAA8B;AAExE,OAAO,EAAE,YAAY,EAAE,wBAAwB;AAO/C,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC;IACtC,IAAI,EAAE,MAAM,EAAE;IACd,QAAQ,EAAE,QAAQ,CAChB,KAAK,CAAC;QACJ,SAAS,CAAC,qBAAqB,CAAC,MAAM,CAAC;QACvC,SAAS,CAAC,qBAAqB,CAAC,GAAG,CAAC;QACpC,SAAS,CAAC,qBAAqB,CAAC,IAAI,CAAC;KACtC,CAAC,CACH;CACF,CAAC,CAAC;AASH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,cAAc;IACd,WAAW,EAAE,CAAC,4BAA4B,CAAC;CAO5C,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,cAAc,CAC3B,GAAoD,EACpD,GAA0C,EAC1C,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAAkD;IAElD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,YAAY,CACV,MAAM,EACN,iBAAiB,EACjB,mCAAmC,EACnC,SAAS,CAAC,aAAa,CACxB,CAAC;IAEF,IAAI,CAAC;QACH,GAAG,CAAC,MAAM,GAAG,MAAM,SAAS,CAAC,IAAI,CAC/B,4BAA4B,EAC5B,MAAM,EACN,MAAM,CAAC,IAAI,EACV,MAAM,CAAC,QAAkC;YACxC,qBAAqB,CAAC,MAAM,CAC/B,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { GetFileParams, GetFileResult } from '@metamask/snaps-sdk';\nimport { AuxiliaryFileEncoding, enumValue } from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { object, optional, string, union } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { assertStruct } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapControllerGetSnapFileAction,\n} from '../types';\n\nexport const GetFileArgsStruct = object({\n path: string(),\n encoding: optional(\n union([\n enumValue(AuxiliaryFileEncoding.Base64),\n enumValue(AuxiliaryFileEncoding.Hex),\n enumValue(AuxiliaryFileEncoding.Utf8),\n ]),\n ),\n});\n\nexport type InferredGetFileParams = InferMatching<\n typeof GetFileArgsStruct,\n GetFileParams\n>;\n\nexport type GetFileMethodActions = SnapControllerGetSnapFileAction;\n\n/**\n * Gets a static file's content in UTF-8, Base64, or hexadecimal.\n *\n * The file must be specified in [the Snap's manifest file](https://docs.metamask.io/snaps/features/static-files/).\n *\n * @example\n * ```json name=\"Manifest\"\n * {\n * \"source\": {\n * \"files\": [\"./files/my-file.bin\"]\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * const contents = await snap.request({\n * method: 'snap_getFile',\n * params: {\n * path: './files/myfile.bin',\n * encoding: 'hex',\n * },\n * })\n *\n * // '0x...'\n * console.log(contents)\n * ```\n */\nexport const getFileHandler = {\n implementation,\n actionNames: ['SnapController:getSnapFile'],\n} satisfies MethodHandler<\n never,\n GetFileMethodActions,\n InferredGetFileParams,\n GetFileResult,\n { origin: string }\n>;\n\n/**\n * The `snap_getFile` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nasync function implementation(\n req: JsonRpcRequestWithOrigin<InferredGetFileParams>,\n res: PendingJsonRpcResponse<GetFileResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, GetFileMethodActions>,\n): Promise<void> {\n const { params, origin } = req;\n\n assertStruct(\n params,\n GetFileArgsStruct,\n 'Invalid \"snap_getFile\" parameters',\n rpcErrors.invalidParams,\n );\n\n try {\n res.result = await messenger.call(\n 'SnapController:getSnapFile',\n origin,\n params.path,\n (params.encoding as AuxiliaryFileEncoding) ??\n AuxiliaryFileEncoding.Base64,\n );\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n"]}
|
|
@@ -4,11 +4,6 @@ exports.getInterfaceContextHandler = void 0;
|
|
|
4
4
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
5
|
const superstruct_1 = require("@metamask/superstruct");
|
|
6
6
|
const utils_1 = require("../utils.cjs");
|
|
7
|
-
const methodName = 'snap_getInterfaceContext';
|
|
8
|
-
const hookNames = {
|
|
9
|
-
hasPermission: true,
|
|
10
|
-
getInterfaceContext: true,
|
|
11
|
-
};
|
|
12
7
|
/**
|
|
13
8
|
* Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
|
|
14
9
|
* created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
|
|
@@ -46,9 +41,11 @@ const hookNames = {
|
|
|
46
41
|
* ```
|
|
47
42
|
*/
|
|
48
43
|
exports.getInterfaceContextHandler = {
|
|
49
|
-
methodNames: [methodName],
|
|
50
44
|
implementation: getInterfaceContextImplementation,
|
|
51
|
-
|
|
45
|
+
actionNames: [
|
|
46
|
+
'PermissionController:hasPermission',
|
|
47
|
+
'SnapInterfaceController:getInterface',
|
|
48
|
+
],
|
|
52
49
|
};
|
|
53
50
|
const GetInterfaceContextParametersStruct = (0, superstruct_1.object)({
|
|
54
51
|
id: (0, superstruct_1.string)(),
|
|
@@ -61,23 +58,23 @@ const GetInterfaceContextParametersStruct = (0, superstruct_1.object)({
|
|
|
61
58
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
62
59
|
* function.
|
|
63
60
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
64
|
-
* @param
|
|
65
|
-
* @param
|
|
66
|
-
* permission.
|
|
67
|
-
* @param hooks.getInterfaceContext - The function to get the interface context.
|
|
61
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
62
|
+
* @param messenger - The messenger used to call controller actions.
|
|
68
63
|
* @returns Nothing.
|
|
69
64
|
*/
|
|
70
|
-
function getInterfaceContextImplementation(req, res, _next, end,
|
|
71
|
-
|
|
65
|
+
function getInterfaceContextImplementation(req, res, _next, end, _hooks, messenger) {
|
|
66
|
+
const { params, origin } = req;
|
|
67
|
+
const isPermitted = utils_1.UI_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
|
|
68
|
+
if (!isPermitted) {
|
|
72
69
|
return end(rpc_errors_1.providerErrors.unauthorized({
|
|
73
70
|
message: `This method can only be used if the Snap has one of the following permissions: ${utils_1.UI_PERMISSIONS.join(', ')}.`,
|
|
74
71
|
}));
|
|
75
72
|
}
|
|
76
|
-
const { params } = req;
|
|
77
73
|
try {
|
|
78
74
|
const validatedParams = getValidatedParams(params);
|
|
79
75
|
const { id } = validatedParams;
|
|
80
|
-
|
|
76
|
+
const { context } = messenger.call('SnapInterfaceController:getInterface', origin, id);
|
|
77
|
+
res.result = context;
|
|
81
78
|
}
|
|
82
79
|
catch (error) {
|
|
83
80
|
return end(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInterfaceContext.cjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getInterfaceContext.cjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":";;;AAMA,qDAAiE;AAMjE,uDAA4E;AAO5E,wCAA0C;AAM1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACU,QAAA,0BAA0B,GAAG;IACxC,cAAc,EAAE,iCAAiC;IACjD,WAAW,EAAE;QACX,oCAAoC;QACpC,sCAAsC;KACvC;CAOF,CAAC;AAEF,MAAM,mCAAmC,GAAG,IAAA,oBAAM,EAAC;IACjD,EAAE,EAAE,IAAA,oBAAM,GAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,iCAAiC,CACxC,GAA4D,EAC5D,GAAsD,EACtD,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAA8D;IAE9D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,MAAM,WAAW,GAAG,sBAAc,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACrD,SAAS,CAAC,IAAI,CAAC,oCAAoC,EAAE,MAAM,EAAE,UAAU,CAAC,CACzE,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CACR,2BAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,sBAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC,IAAI,CAChC,sCAAsC,EACtC,MAAM,EACN,EAAE,CACH,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,mCAAmC,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport type { PermissionControllerHasPermissionAction } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceContextParams,\n GetInterfaceContextResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapInterfaceControllerGetInterfaceAction,\n} from '../types';\nimport { UI_PERMISSIONS } from '../utils';\n\nexport type GetInterfaceContextMethodActions =\n | PermissionControllerHasPermissionAction\n | SnapInterfaceControllerGetInterfaceAction;\n\n/**\n * Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)\n * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n *\n * @example\n * ```ts\n * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';\n *\n * const interfaceId = await snap.request({\n * method: 'snap_createInterface',\n * params: {\n * ui: (\n * <Box>\n * <Heading>Hello, world!</Heading>\n * <Text>Welcome to my Snap homepage!</Text>\n * </Box>\n * ),\n * context: {\n * key: 'value'\n * }\n * },\n * })\n *\n * const context = await snap.request({\n * method: 'snap_getInterfaceContext',\n * params: {\n * id: interfaceId,\n * },\n * })\n *\n * console.log(context)\n * // {\n * // key: 'value'\n * // }\n * ```\n */\nexport const getInterfaceContextHandler = {\n implementation: getInterfaceContextImplementation,\n actionNames: [\n 'PermissionController:hasPermission',\n 'SnapInterfaceController:getInterface',\n ],\n} satisfies MethodHandler<\n never,\n GetInterfaceContextMethodActions,\n GetInterfaceContextParameters,\n GetInterfaceContextResult,\n { origin: string }\n>;\n\nconst GetInterfaceContextParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceContextParameters = InferMatching<\n typeof GetInterfaceContextParametersStruct,\n GetInterfaceContextParams\n>;\n\n/**\n * The `snap_getInterfaceContext` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getInterfaceContextImplementation(\n req: JsonRpcRequestWithOrigin<GetInterfaceContextParameters>,\n res: PendingJsonRpcResponse<GetInterfaceContextResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, GetInterfaceContextMethodActions>,\n): void {\n const { params, origin } = req;\n\n const isPermitted = UI_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n const { context } = messenger.call(\n 'SnapInterfaceController:getInterface',\n origin,\n id,\n );\n\n res.result = context;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceContext method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated getInterfaceContext method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceContextParameters {\n try {\n return create(params, GetInterfaceContextParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
3
|
+
import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
|
|
4
|
+
import type { GetInterfaceContextParams, GetInterfaceContextResult } from "@metamask/snaps-sdk";
|
|
3
5
|
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
6
|
import type { PendingJsonRpcResponse } from "@metamask/utils";
|
|
5
|
-
import type {
|
|
6
|
-
export type
|
|
7
|
-
/**
|
|
8
|
-
* @param permissionName - The name of the permission to check.
|
|
9
|
-
* @returns Whether the Snap has the permission.
|
|
10
|
-
*/
|
|
11
|
-
hasPermission: (permissionName: string) => boolean;
|
|
12
|
-
/**
|
|
13
|
-
* @param id - The interface ID.
|
|
14
|
-
* @returns The interface context.
|
|
15
|
-
*/
|
|
16
|
-
getInterfaceContext: (id: string) => InterfaceContext | null;
|
|
17
|
-
};
|
|
7
|
+
import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerGetInterfaceAction } from "../types.cjs";
|
|
8
|
+
export type GetInterfaceContextMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerGetInterfaceAction;
|
|
18
9
|
/**
|
|
19
10
|
* Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
|
|
20
11
|
* created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
|
|
@@ -52,9 +43,8 @@ export type GetInterfaceContextMethodHooks = {
|
|
|
52
43
|
* ```
|
|
53
44
|
*/
|
|
54
45
|
export declare const getInterfaceContextHandler: {
|
|
55
|
-
methodNames: ["snap_getInterfaceContext"];
|
|
56
46
|
implementation: typeof getInterfaceContextImplementation;
|
|
57
|
-
|
|
47
|
+
actionNames: ("SnapInterfaceController:getInterface" | "PermissionController:hasPermission")[];
|
|
58
48
|
};
|
|
59
49
|
declare const GetInterfaceContextParametersStruct: import("@metamask/superstruct").Struct<{
|
|
60
50
|
id: string;
|
|
@@ -70,12 +60,10 @@ export type GetInterfaceContextParameters = InferMatching<typeof GetInterfaceCon
|
|
|
70
60
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
71
61
|
* function.
|
|
72
62
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
73
|
-
* @param
|
|
74
|
-
* @param
|
|
75
|
-
* permission.
|
|
76
|
-
* @param hooks.getInterfaceContext - The function to get the interface context.
|
|
63
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
64
|
+
* @param messenger - The messenger used to call controller actions.
|
|
77
65
|
* @returns Nothing.
|
|
78
66
|
*/
|
|
79
|
-
declare function getInterfaceContextImplementation(req:
|
|
67
|
+
declare function getInterfaceContextImplementation(req: JsonRpcRequestWithOrigin<GetInterfaceContextParameters>, res: PendingJsonRpcResponse<GetInterfaceContextResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, GetInterfaceContextMethodActions>): void;
|
|
80
68
|
export {};
|
|
81
69
|
//# sourceMappingURL=getInterfaceContext.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInterfaceContext.d.cts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"getInterfaceContext.d.cts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,uCAAuC,EAAE,wCAAwC;AAE/F,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EAC1B,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EACV,wBAAwB,EACxB,yCAAyC,EAC1C,qBAAiB;AAGlB,MAAM,MAAM,gCAAgC,GACxC,uCAAuC,GACvC,yCAAyC,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,0BAA0B;;;CAYtC,CAAC;AAEF,QAAA,MAAM,mCAAmC;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,aAAa,CACvD,OAAO,mCAAmC,EAC1C,yBAAyB,CAC1B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,iBAAS,iCAAiC,CACxC,GAAG,EAAE,wBAAwB,CAAC,6BAA6B,CAAC,EAC5D,GAAG,EAAE,sBAAsB,CAAC,yBAAyB,CAAC,EACtD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,gCAAgC,CAAC,GAC7D,IAAI,CAgCN"}
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
3
|
+
import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
|
|
4
|
+
import type { GetInterfaceContextParams, GetInterfaceContextResult } from "@metamask/snaps-sdk";
|
|
3
5
|
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
6
|
import type { PendingJsonRpcResponse } from "@metamask/utils";
|
|
5
|
-
import type {
|
|
6
|
-
export type
|
|
7
|
-
/**
|
|
8
|
-
* @param permissionName - The name of the permission to check.
|
|
9
|
-
* @returns Whether the Snap has the permission.
|
|
10
|
-
*/
|
|
11
|
-
hasPermission: (permissionName: string) => boolean;
|
|
12
|
-
/**
|
|
13
|
-
* @param id - The interface ID.
|
|
14
|
-
* @returns The interface context.
|
|
15
|
-
*/
|
|
16
|
-
getInterfaceContext: (id: string) => InterfaceContext | null;
|
|
17
|
-
};
|
|
7
|
+
import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerGetInterfaceAction } from "../types.mjs";
|
|
8
|
+
export type GetInterfaceContextMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerGetInterfaceAction;
|
|
18
9
|
/**
|
|
19
10
|
* Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
|
|
20
11
|
* created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
|
|
@@ -52,9 +43,8 @@ export type GetInterfaceContextMethodHooks = {
|
|
|
52
43
|
* ```
|
|
53
44
|
*/
|
|
54
45
|
export declare const getInterfaceContextHandler: {
|
|
55
|
-
methodNames: ["snap_getInterfaceContext"];
|
|
56
46
|
implementation: typeof getInterfaceContextImplementation;
|
|
57
|
-
|
|
47
|
+
actionNames: ("SnapInterfaceController:getInterface" | "PermissionController:hasPermission")[];
|
|
58
48
|
};
|
|
59
49
|
declare const GetInterfaceContextParametersStruct: import("@metamask/superstruct").Struct<{
|
|
60
50
|
id: string;
|
|
@@ -70,12 +60,10 @@ export type GetInterfaceContextParameters = InferMatching<typeof GetInterfaceCon
|
|
|
70
60
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
71
61
|
* function.
|
|
72
62
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
73
|
-
* @param
|
|
74
|
-
* @param
|
|
75
|
-
* permission.
|
|
76
|
-
* @param hooks.getInterfaceContext - The function to get the interface context.
|
|
63
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
64
|
+
* @param messenger - The messenger used to call controller actions.
|
|
77
65
|
* @returns Nothing.
|
|
78
66
|
*/
|
|
79
|
-
declare function getInterfaceContextImplementation(req:
|
|
67
|
+
declare function getInterfaceContextImplementation(req: JsonRpcRequestWithOrigin<GetInterfaceContextParameters>, res: PendingJsonRpcResponse<GetInterfaceContextResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, GetInterfaceContextMethodActions>): void;
|
|
80
68
|
export {};
|
|
81
69
|
//# sourceMappingURL=getInterfaceContext.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInterfaceContext.d.mts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"getInterfaceContext.d.mts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,uCAAuC,EAAE,wCAAwC;AAE/F,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EAC1B,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EACV,wBAAwB,EACxB,yCAAyC,EAC1C,qBAAiB;AAGlB,MAAM,MAAM,gCAAgC,GACxC,uCAAuC,GACvC,yCAAyC,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,0BAA0B;;;CAYtC,CAAC;AAEF,QAAA,MAAM,mCAAmC;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,aAAa,CACvD,OAAO,mCAAmC,EAC1C,yBAAyB,CAC1B,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,iBAAS,iCAAiC,CACxC,GAAG,EAAE,wBAAwB,CAAC,6BAA6B,CAAC,EAC5D,GAAG,EAAE,sBAAsB,CAAC,yBAAyB,CAAC,EACtD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,gCAAgC,CAAC,GAC7D,IAAI,CAgCN"}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
|
|
2
2
|
import { StructError, create, object, string } from "@metamask/superstruct";
|
|
3
3
|
import { UI_PERMISSIONS } from "../utils.mjs";
|
|
4
|
-
const methodName = 'snap_getInterfaceContext';
|
|
5
|
-
const hookNames = {
|
|
6
|
-
hasPermission: true,
|
|
7
|
-
getInterfaceContext: true,
|
|
8
|
-
};
|
|
9
4
|
/**
|
|
10
5
|
* Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
|
|
11
6
|
* created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
|
|
@@ -43,9 +38,11 @@ const hookNames = {
|
|
|
43
38
|
* ```
|
|
44
39
|
*/
|
|
45
40
|
export const getInterfaceContextHandler = {
|
|
46
|
-
methodNames: [methodName],
|
|
47
41
|
implementation: getInterfaceContextImplementation,
|
|
48
|
-
|
|
42
|
+
actionNames: [
|
|
43
|
+
'PermissionController:hasPermission',
|
|
44
|
+
'SnapInterfaceController:getInterface',
|
|
45
|
+
],
|
|
49
46
|
};
|
|
50
47
|
const GetInterfaceContextParametersStruct = object({
|
|
51
48
|
id: string(),
|
|
@@ -58,23 +55,23 @@ const GetInterfaceContextParametersStruct = object({
|
|
|
58
55
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
59
56
|
* function.
|
|
60
57
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
61
|
-
* @param
|
|
62
|
-
* @param
|
|
63
|
-
* permission.
|
|
64
|
-
* @param hooks.getInterfaceContext - The function to get the interface context.
|
|
58
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
59
|
+
* @param messenger - The messenger used to call controller actions.
|
|
65
60
|
* @returns Nothing.
|
|
66
61
|
*/
|
|
67
|
-
function getInterfaceContextImplementation(req, res, _next, end,
|
|
68
|
-
|
|
62
|
+
function getInterfaceContextImplementation(req, res, _next, end, _hooks, messenger) {
|
|
63
|
+
const { params, origin } = req;
|
|
64
|
+
const isPermitted = UI_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
|
|
65
|
+
if (!isPermitted) {
|
|
69
66
|
return end(providerErrors.unauthorized({
|
|
70
67
|
message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,
|
|
71
68
|
}));
|
|
72
69
|
}
|
|
73
|
-
const { params } = req;
|
|
74
70
|
try {
|
|
75
71
|
const validatedParams = getValidatedParams(params);
|
|
76
72
|
const { id } = validatedParams;
|
|
77
|
-
|
|
73
|
+
const { context } = messenger.call('SnapInterfaceController:getInterface', origin, id);
|
|
74
|
+
res.result = context;
|
|
78
75
|
}
|
|
79
76
|
catch (error) {
|
|
80
77
|
return end(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInterfaceContext.mjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getInterfaceContext.mjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAMjE,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAO5E,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAM1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACxC,cAAc,EAAE,iCAAiC;IACjD,WAAW,EAAE;QACX,oCAAoC;QACpC,sCAAsC;KACvC;CAOF,CAAC;AAEF,MAAM,mCAAmC,GAAG,MAAM,CAAC;IACjD,EAAE,EAAE,MAAM,EAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,iCAAiC,CACxC,GAA4D,EAC5D,GAAsD,EACtD,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAA8D;IAE9D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACrD,SAAS,CAAC,IAAI,CAAC,oCAAoC,EAAE,MAAM,EAAE,UAAU,CAAC,CACzE,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CACR,cAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC,IAAI,CAChC,sCAAsC,EACtC,MAAM,EACN,EAAE,CACH,CAAC;QAEF,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC;IACvB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,mCAAmC,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport type { PermissionControllerHasPermissionAction } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceContextParams,\n GetInterfaceContextResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapInterfaceControllerGetInterfaceAction,\n} from '../types';\nimport { UI_PERMISSIONS } from '../utils';\n\nexport type GetInterfaceContextMethodActions =\n | PermissionControllerHasPermissionAction\n | SnapInterfaceControllerGetInterfaceAction;\n\n/**\n * Get the context of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)\n * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n *\n * @example\n * ```ts\n * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';\n *\n * const interfaceId = await snap.request({\n * method: 'snap_createInterface',\n * params: {\n * ui: (\n * <Box>\n * <Heading>Hello, world!</Heading>\n * <Text>Welcome to my Snap homepage!</Text>\n * </Box>\n * ),\n * context: {\n * key: 'value'\n * }\n * },\n * })\n *\n * const context = await snap.request({\n * method: 'snap_getInterfaceContext',\n * params: {\n * id: interfaceId,\n * },\n * })\n *\n * console.log(context)\n * // {\n * // key: 'value'\n * // }\n * ```\n */\nexport const getInterfaceContextHandler = {\n implementation: getInterfaceContextImplementation,\n actionNames: [\n 'PermissionController:hasPermission',\n 'SnapInterfaceController:getInterface',\n ],\n} satisfies MethodHandler<\n never,\n GetInterfaceContextMethodActions,\n GetInterfaceContextParameters,\n GetInterfaceContextResult,\n { origin: string }\n>;\n\nconst GetInterfaceContextParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceContextParameters = InferMatching<\n typeof GetInterfaceContextParametersStruct,\n GetInterfaceContextParams\n>;\n\n/**\n * The `snap_getInterfaceContext` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getInterfaceContextImplementation(\n req: JsonRpcRequestWithOrigin<GetInterfaceContextParameters>,\n res: PendingJsonRpcResponse<GetInterfaceContextResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, GetInterfaceContextMethodActions>,\n): void {\n const { params, origin } = req;\n\n const isPermitted = UI_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n const { context } = messenger.call(\n 'SnapInterfaceController:getInterface',\n origin,\n id,\n );\n\n res.result = context;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceContext method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated getInterfaceContext method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceContextParameters {\n try {\n return create(params, GetInterfaceContextParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -4,11 +4,6 @@ exports.getInterfaceStateHandler = void 0;
|
|
|
4
4
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
5
|
const superstruct_1 = require("@metamask/superstruct");
|
|
6
6
|
const utils_1 = require("../utils.cjs");
|
|
7
|
-
const methodName = 'snap_getInterfaceState';
|
|
8
|
-
const hookNames = {
|
|
9
|
-
hasPermission: true,
|
|
10
|
-
getInterfaceState: true,
|
|
11
|
-
};
|
|
12
7
|
/**
|
|
13
8
|
* Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
|
|
14
9
|
* created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
|
|
@@ -24,9 +19,11 @@ const hookNames = {
|
|
|
24
19
|
* ```
|
|
25
20
|
*/
|
|
26
21
|
exports.getInterfaceStateHandler = {
|
|
27
|
-
methodNames: [methodName],
|
|
28
22
|
implementation: getGetInterfaceStateImplementation,
|
|
29
|
-
|
|
23
|
+
actionNames: [
|
|
24
|
+
'PermissionController:hasPermission',
|
|
25
|
+
'SnapInterfaceController:getInterfaceState',
|
|
26
|
+
],
|
|
30
27
|
};
|
|
31
28
|
const GetInterfaceStateParametersStruct = (0, superstruct_1.object)({
|
|
32
29
|
id: (0, superstruct_1.string)(),
|
|
@@ -39,23 +36,22 @@ const GetInterfaceStateParametersStruct = (0, superstruct_1.object)({
|
|
|
39
36
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
40
37
|
* function.
|
|
41
38
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
42
|
-
* @param
|
|
43
|
-
* @param
|
|
44
|
-
* permission.
|
|
45
|
-
* @param hooks.getInterfaceState - The function to get the interface state.
|
|
39
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
40
|
+
* @param messenger - The messenger used to call controller actions.
|
|
46
41
|
* @returns Nothing.
|
|
47
42
|
*/
|
|
48
|
-
function getGetInterfaceStateImplementation(req, res, _next, end,
|
|
49
|
-
|
|
43
|
+
function getGetInterfaceStateImplementation(req, res, _next, end, _hooks, messenger) {
|
|
44
|
+
const { params, origin } = req;
|
|
45
|
+
const isPermitted = utils_1.UI_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
|
|
46
|
+
if (!isPermitted) {
|
|
50
47
|
return end(rpc_errors_1.providerErrors.unauthorized({
|
|
51
48
|
message: `This method can only be used if the Snap has one of the following permissions: ${utils_1.UI_PERMISSIONS.join(', ')}.`,
|
|
52
49
|
}));
|
|
53
50
|
}
|
|
54
|
-
const { params } = req;
|
|
55
51
|
try {
|
|
56
52
|
const validatedParams = getValidatedParams(params);
|
|
57
53
|
const { id } = validatedParams;
|
|
58
|
-
res.result = getInterfaceState
|
|
54
|
+
res.result = messenger.call('SnapInterfaceController:getInterfaceState', origin, id);
|
|
59
55
|
}
|
|
60
56
|
catch (error) {
|
|
61
57
|
return end(error);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInterfaceState.cjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"getInterfaceState.cjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":";;;AAMA,qDAAiE;AAMjE,uDAA4E;AAO5E,wCAA0C;AAM1C;;;;;;;;;;;;;GAaG;AACU,QAAA,wBAAwB,GAAG;IACtC,cAAc,EAAE,kCAAkC;IAClD,WAAW,EAAE;QACX,oCAAoC;QACpC,2CAA2C;KAC5C;CAOF,CAAC;AAEF,MAAM,iCAAiC,GAAG,IAAA,oBAAM,EAAC;IAC/C,EAAE,EAAE,IAAA,oBAAM,GAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,kCAAkC,CACzC,GAA0D,EAC1D,GAAoD,EACpD,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAA4D;IAE5D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,MAAM,WAAW,GAAG,sBAAc,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACrD,SAAS,CAAC,IAAI,CAAC,oCAAoC,EAAE,MAAM,EAAE,UAAU,CAAC,CACzE,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CACR,2BAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,sBAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,GAAG,CAAC,MAAM,GAAG,SAAS,CAAC,IAAI,CACzB,2CAA2C,EAC3C,MAAM,EACN,EAAE,CACH,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,iCAAiC,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport type { PermissionControllerHasPermissionAction } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceStateParams,\n GetInterfaceStateResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapInterfaceControllerGetInterfaceStateAction,\n} from '../types';\nimport { UI_PERMISSIONS } from '../utils';\n\nexport type GetInterfaceStateMethodActions =\n | PermissionControllerHasPermissionAction\n | SnapInterfaceControllerGetInterfaceStateAction;\n\n/**\n * Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)\n * created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).\n *\n * @example\n * ```ts\n * const state = await snap.request({\n * method: 'snap_getInterfaceState',\n * params: {\n * id: interfaceId,\n * },\n * });\n * ```\n */\nexport const getInterfaceStateHandler = {\n implementation: getGetInterfaceStateImplementation,\n actionNames: [\n 'PermissionController:hasPermission',\n 'SnapInterfaceController:getInterfaceState',\n ],\n} satisfies MethodHandler<\n never,\n GetInterfaceStateMethodActions,\n GetInterfaceStateParameters,\n GetInterfaceStateResult,\n { origin: string }\n>;\n\nconst GetInterfaceStateParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceStateParameters = InferMatching<\n typeof GetInterfaceStateParametersStruct,\n GetInterfaceStateParams\n>;\n\n/**\n * The `snap_getInterfaceState` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getGetInterfaceStateImplementation(\n req: JsonRpcRequestWithOrigin<GetInterfaceStateParameters>,\n res: PendingJsonRpcResponse<GetInterfaceStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, GetInterfaceStateMethodActions>,\n): void {\n const { params, origin } = req;\n\n const isPermitted = UI_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = messenger.call(\n 'SnapInterfaceController:getInterfaceState',\n origin,\n id,\n );\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceState method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated getInterfaceState method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceStateParameters {\n try {\n return create(params, GetInterfaceStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -1,20 +1,11 @@
|
|
|
1
1
|
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
3
|
+
import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
|
|
4
|
+
import type { GetInterfaceStateParams, GetInterfaceStateResult } from "@metamask/snaps-sdk";
|
|
3
5
|
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
6
|
import type { PendingJsonRpcResponse } from "@metamask/utils";
|
|
5
|
-
import type {
|
|
6
|
-
export type
|
|
7
|
-
/**
|
|
8
|
-
* @param permissionName - The name of the permission to check.
|
|
9
|
-
* @returns Whether the Snap has the permission.
|
|
10
|
-
*/
|
|
11
|
-
hasPermission: (permissionName: string) => boolean;
|
|
12
|
-
/**
|
|
13
|
-
* @param id - The interface ID.
|
|
14
|
-
* @returns The interface state.
|
|
15
|
-
*/
|
|
16
|
-
getInterfaceState: (id: string) => InterfaceState;
|
|
17
|
-
};
|
|
7
|
+
import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerGetInterfaceStateAction } from "../types.cjs";
|
|
8
|
+
export type GetInterfaceStateMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerGetInterfaceStateAction;
|
|
18
9
|
/**
|
|
19
10
|
* Get the form state of an [interface](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/)
|
|
20
11
|
* created by [`snap_createInterface`](https://docs.metamask.io/snaps/reference/snaps-api/snap_createinterface).
|
|
@@ -30,9 +21,8 @@ export type GetInterfaceStateMethodHooks = {
|
|
|
30
21
|
* ```
|
|
31
22
|
*/
|
|
32
23
|
export declare const getInterfaceStateHandler: {
|
|
33
|
-
methodNames: ["snap_getInterfaceState"];
|
|
34
24
|
implementation: typeof getGetInterfaceStateImplementation;
|
|
35
|
-
|
|
25
|
+
actionNames: ("SnapInterfaceController:getInterfaceState" | "PermissionController:hasPermission")[];
|
|
36
26
|
};
|
|
37
27
|
declare const GetInterfaceStateParametersStruct: import("@metamask/superstruct").Struct<{
|
|
38
28
|
id: string;
|
|
@@ -48,12 +38,10 @@ export type GetInterfaceStateParameters = InferMatching<typeof GetInterfaceState
|
|
|
48
38
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
49
39
|
* function.
|
|
50
40
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
51
|
-
* @param
|
|
52
|
-
* @param
|
|
53
|
-
* permission.
|
|
54
|
-
* @param hooks.getInterfaceState - The function to get the interface state.
|
|
41
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
42
|
+
* @param messenger - The messenger used to call controller actions.
|
|
55
43
|
* @returns Nothing.
|
|
56
44
|
*/
|
|
57
|
-
declare function getGetInterfaceStateImplementation(req:
|
|
45
|
+
declare function getGetInterfaceStateImplementation(req: JsonRpcRequestWithOrigin<GetInterfaceStateParameters>, res: PendingJsonRpcResponse<GetInterfaceStateResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, GetInterfaceStateMethodActions>): void;
|
|
58
46
|
export {};
|
|
59
47
|
//# sourceMappingURL=getInterfaceState.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getInterfaceState.d.cts","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"getInterfaceState.d.cts","sourceRoot":"","sources":["../../src/permitted/getInterfaceState.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,uCAAuC,EAAE,wCAAwC;AAE/F,OAAO,KAAK,EACV,uBAAuB,EACvB,uBAAuB,EACxB,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAE3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EACV,wBAAwB,EACxB,8CAA8C,EAC/C,qBAAiB;AAGlB,MAAM,MAAM,8BAA8B,GACtC,uCAAuC,GACvC,8CAA8C,CAAC;AAEnD;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,wBAAwB;;;CAYpC,CAAC;AAEF,QAAA,MAAM,iCAAiC;;;;EAErC,CAAC;AAEH,MAAM,MAAM,2BAA2B,GAAG,aAAa,CACrD,OAAO,iCAAiC,EACxC,uBAAuB,CACxB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,iBAAS,kCAAkC,CACzC,GAAG,EAAE,wBAAwB,CAAC,2BAA2B,CAAC,EAC1D,GAAG,EAAE,sBAAsB,CAAC,uBAAuB,CAAC,EACpD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,8BAA8B,CAAC,GAC3D,IAAI,CA8BN"}
|