@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
71 lines • 3.29 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 ScheduleBackgroundEventParams, type ScheduleBackgroundEventResult } from "@metamask/snaps-sdk";
import type { InferMatching } from "@metamask/snaps-utils";
import { type PendingJsonRpcResponse } from "@metamask/utils";
import type { CronjobControllerScheduleAction, JsonRpcRequestWithOrigin } from "../types.cjs";
export type ScheduleBackgroundEventMethodActions = PermissionControllerHasPermissionAction | CronjobControllerScheduleAction;
/**
* Schedule a background event for a Snap. The background event will trigger a
* JSON-RPC request to the Snap at the scheduled time, handled by the
* `onCronjob` entry point in the Snap.
*
* The schedule can be defined using either an ISO 8601 date or duration string.
* For example:
*
* - Using a date: `2026-12-31T23:59:59Z`
* - Using a duration: `P1DT2H` (which represents a duration of 1 day and 2
* hours)
*
* @example
* ```ts
* const id = await wallet.request({
* method: 'snap_scheduleBackgroundEvent',
* params: {
* date: '2026-12-31T23:59:59Z',
* request: {
* method: 'mySnapMethod',
* params: { foo: 'bar' },
* },
* },
* });
* ```
*/
export declare const scheduleBackgroundEventHandler: {
implementation: typeof getScheduleBackgroundEventImplementation;
actionNames: ("CronjobController:schedule" | "PermissionController:hasPermission")[];
};
declare const ScheduleBackgroundEventParametersStruct: import("@metamask/superstruct").Struct<{
date: string;
request: {
method: string;
jsonrpc?: "2.0" | undefined;
id?: string | number | null | undefined;
params?: import("@metamask/snaps-sdk").Json[] | Record<string, import("@metamask/snaps-sdk").Json> | undefined;
};
} | {
request: {
method: string;
jsonrpc?: "2.0" | undefined;
id?: string | number | null | undefined;
params?: import("@metamask/snaps-sdk").Json[] | Record<string, import("@metamask/snaps-sdk").Json> | undefined;
};
duration: string;
}, null>;
export type ScheduleBackgroundEventParameters = InferMatching<typeof ScheduleBackgroundEventParametersStruct, ScheduleBackgroundEventParams>;
/**
* The `snap_scheduleBackgroundEvent` 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 An id representing the background event.
*/
declare function getScheduleBackgroundEventImplementation(req: JsonRpcRequestWithOrigin<ScheduleBackgroundEventParameters>, res: PendingJsonRpcResponse<ScheduleBackgroundEventResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, ScheduleBackgroundEventMethodActions>): Promise<void>;
export {};
//# sourceMappingURL=scheduleBackgroundEvent.d.cts.map