@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
47 lines • 2.63 kB
text/typescript
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
import type { Messenger } from "@metamask/messenger";
import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
import type { InvokeKeyringParams, InvokeKeyringResult } from "@metamask/snaps-sdk";
import type { PendingJsonRpcResponse } from "@metamask/utils";
import type { JsonRpcRequestWithOrigin, SnapControllerGetSnapAction, SnapControllerHandleRequestAction } from "../types.cjs";
import type { MethodHooksObject } from "../utils.cjs";
export type InvokeKeyringMethodHooks = {
/**
* Get the list of allowed Keyring methods for a given origin.
*
* @returns The list of allowed Keyring methods.
*/
getAllowedKeyringMethods: () => string[];
};
export type InvokeKeyringMethodActions = PermissionControllerHasPermissionAction | SnapControllerHandleRequestAction | SnapControllerGetSnapAction;
/**
* Invoke a keyring method of a Snap. This calls the `onKeyringRequest` handler
* of the Snap.
*
* 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).
*/
export declare const invokeKeyringHandler: {
implementation: typeof invokeKeyringImplementation;
hookNames: MethodHooksObject<InvokeKeyringMethodHooks>;
actionNames: ("SnapController:handleRequest" | "SnapController:getSnap" | "PermissionController:hasPermission")[];
};
/**
* The `wallet_invokeKeyring` method implementation.
* Invokes onKeyringRequest if the snap requested is installed and connected to the dapp.
*
* @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.
* @param hooks.getAllowedKeyringMethods - Get the list of allowed Keyring
* methods for a given origin.
* @param messenger - The messenger used to call controller actions.
* @returns Nothing.
*/
declare function invokeKeyringImplementation(req: JsonRpcRequestWithOrigin<InvokeKeyringParams>, res: PendingJsonRpcResponse<InvokeKeyringResult>, _next: unknown, end: JsonRpcEngineEndCallback, { getAllowedKeyringMethods }: InvokeKeyringMethodHooks, messenger: Messenger<string, InvokeKeyringMethodActions>): Promise<void>;
export {};
//# sourceMappingURL=invokeKeyring.d.cts.map