UNPKG

@metamask/snaps-rpc-methods

Version:
58 lines 2.98 kB
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine"; import type { Messenger } from "@metamask/messenger"; import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller"; import type { SendWebSocketMessageParams, SendWebSocketMessageResult } from "@metamask/snaps-sdk"; import type { InferMatching } from "@metamask/snaps-utils"; import type { PendingJsonRpcResponse } from "@metamask/utils"; import type { JsonRpcRequestWithOrigin, WebSocketServiceSendMessageAction } from "../types.mjs"; export type SendWebSocketMessageMethodActions = PermissionControllerHasPermissionAction | WebSocketServiceSendMessageAction; declare const SendWebSocketMessageParametersStruct: import("@metamask/superstruct").Struct<{ id: string; message: string | number[]; }, { id: import("@metamask/superstruct").Struct<string, null>; message: import("@metamask/superstruct").Struct<string | number[], [head: import("@metamask/superstruct").Struct<string, null>, import("@metamask/superstruct").Struct<number[], import("@metamask/superstruct").Struct<number, null>>]>; }>; export type SendWebSocketMessageParameters = InferMatching<typeof SendWebSocketMessageParametersStruct, SendWebSocketMessageParams>; /** * Send a message to an open WebSocket connection. The message will be sent to * the WebSocket connection with the specified ID, which must have been * previously opened by the Snap using the [`snap_openWebSocket`](https://docs.metamask.io/snaps/reference/snaps-api/snap_openwebsocket/) * method. * * @example * ```json name="Manifest" * { * "initialPermissions": { * "endowment:network-access": {} * } * } * ``` * ```ts name="Usage" * await wallet.request({ * method: 'snap_sendWebSocketMessage', * params: { * id: 'websocket-connection-id', * message: 'Hello, WebSocket!', // or message: [1, 2, 3] for binary data * }, * }); * ``` */ export declare const sendWebSocketMessageHandler: { implementation: typeof sendWebSocketMessageImplementation; actionNames: ("WebSocketService:sendMessage" | "PermissionController:hasPermission")[]; }; /** * The `snap_sendWebSocketMessage` method implementation. * * @param req - The JSON-RPC request object. * @param res - The JSON-RPC response object. * @param _next - The `json-rpc-engine` "next" callback. Not used by this function. * @param end - The `json-rpc-engine` "end" callback. * @param _hooks - The RPC method hooks. Not used by this function. * @param messenger - The messenger used to call controller actions. * @returns Nothing. */ declare function sendWebSocketMessageImplementation(req: JsonRpcRequestWithOrigin<SendWebSocketMessageParameters>, res: PendingJsonRpcResponse<SendWebSocketMessageResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, SendWebSocketMessageMethodActions>): Promise<void>; export {}; //# sourceMappingURL=sendWebSocketMessage.d.mts.map