UNPKG

@metamask/snaps-rpc-methods

Version:
65 lines 2.77 kB
import type { PermittedHandlerExport } from "@metamask/permission-controller"; import type { SetStateParams, SetStateResult } from "@metamask/snaps-sdk"; import type { JsonObject } from "@metamask/snaps-sdk/jsx"; import { type InferMatching } from "@metamask/snaps-utils"; import type { Json } from "@metamask/utils"; /** * `snap_setState` sets the state of the Snap. */ export declare const setStateHandler: PermittedHandlerExport<SetStateHooks, SetStateParameters, SetStateResult>; export type SetStateHooks = { /** * Check if the requesting origin has a given permission. * * @param permissionName - The name of the permission to check. * @returns Whether the origin has the permission. */ hasPermission: (permissionName: string) => boolean; /** * Get the state of the requesting Snap. * * @param encrypted - Whether the state is encrypted. * @returns The current state of the Snap. */ getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>; /** * Wait for the extension to be unlocked. * * @returns A promise that resolves once the extension is unlocked. */ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>; /** * Update the state of the requesting Snap. * * @param newState - The new state of the Snap. * @param encrypted - Whether the state should be encrypted. */ updateSnapState: (newState: Record<string, Json>, encrypted: boolean) => Promise<void>; }; declare const SetStateParametersStruct: import("@metamask/superstruct").Struct<{ value: Json; encrypted?: boolean | undefined; key?: string | undefined; }, { key: import("@metamask/superstruct").Struct<string | undefined, null>; value: import("@metamask/superstruct").Struct<Json, unknown>; encrypted: import("@metamask/superstruct").Struct<boolean | undefined, null>; }>; export type SetStateParameters = InferMatching<typeof SetStateParametersStruct, SetStateParams>; /** * Set the value of a key in an object. The key may contain Lodash-style path * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does * not exist, it is created (and any missing intermediate keys are created as * well). * * This is a simplified version of Lodash's `set` function, but Lodash doesn't * seem to be maintained anymore, so we're using our own implementation. * * @param object - The object to get the key from. * @param key - The key to set. * @param value - The value to set the key to. * @returns The new object with the key set to the value. */ export declare function set(object: Record<string, Json> | null, key: string, value: Json): JsonObject; export {}; //# sourceMappingURL=setState.d.mts.map