UNPKG

@metamask/snaps-rpc-methods

Version:
59 lines 2.88 kB
import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine"; import type { Messenger } from "@metamask/messenger"; import type { PermissionControllerExecuteRestrictedMethodAction } from "@metamask/permission-controller"; import type { InvokeSnapParams, InvokeSnapResult } from "@metamask/snaps-sdk"; import type { PendingJsonRpcResponse } from "@metamask/utils"; import type { JsonRpcRequestWithOrigin } from "../types.cjs"; export type InvokeSnapSugarMethodActions = PermissionControllerExecuteRestrictedMethodAction; /** * Invoke a method of a Snap, designated by the `snapId` parameter, with a * JSON-RPC request specified in the `request` parameter. This is effectively a * wrapper around [`wallet_snap`](https://docs.metamask.io/snaps/reference/snaps-api/wallet_snap) * that allows for more convenient invocation of Snap methods without needing to * specify the full `wallet_snap` parameters. * * The Snap must be installed and the dapp must have permission to communicate * with the Snap, or the request is rejected. The dapp can install the Snap and * request permission to communicate with it using [`wallet_requestSnaps`](https://docs.metamask.io/snaps/reference/snaps-api/wallet_requestsnaps). * * @example * ```ts * const result = await snap.request({ * method: 'wallet_invokeSnap', * params: { * snapId: 'npm:@metamask/example-snap', * request: { * method: 'someMethod', * params: { some: 'params' }, * }, * }, * }); * ``` */ export declare const invokeSnapSugarHandler: { implementation: typeof invokeSnapSugar; actionNames: "PermissionController:executeRestrictedMethod"[]; }; /** * The `wallet_invokeSnap` method implementation. * Effectively calls `wallet_snap` under the hood. * * @param req - The JSON-RPC request object. * @param res - The JSON-RPC response object. * @param _next - The `json-rpc-engine` "next" callback. * @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. * @throws If the params are invalid. */ export declare function invokeSnapSugar(req: JsonRpcRequestWithOrigin<InvokeSnapParams>, res: PendingJsonRpcResponse<InvokeSnapResult>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, InvokeSnapSugarMethodActions>): Promise<void>; /** * Validates the wallet_invokeSnap method `params` and returns them cast to the correct * type. Throws if validation fails. * * @param params - The unvalidated params object from the method request. * @returns The validated method parameter object. */ export declare function getValidatedParams(params: unknown): InvokeSnapParams; //# sourceMappingURL=invokeSnapSugar.d.cts.map