UNPKG

@metamask/snaps-rpc-methods

Version:
84 lines 3.76 kB
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine"; import type { Messenger } from "@metamask/messenger"; import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller"; import type { GetStateParams, GetStateResult } from "@metamask/snaps-sdk"; import { type InferMatching } from "@metamask/snaps-utils"; import type { PendingJsonRpcResponse, Json } from "@metamask/utils"; import type { JsonRpcRequestWithOrigin, SnapControllerGetSnapStateAction } from "../types.cjs"; import type { MethodHooksObject } from "../utils.cjs"; export type GetStateMethodHooks = { /** * Wait for the extension to be unlocked. * * @returns A promise that resolves once the extension is unlocked. */ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>; }; export type GetStateMethodActions = PermissionControllerHasPermissionAction | SnapControllerGetSnapStateAction; /** * Get the state of the Snap, or a specific value within the state. By default, * the data is automatically encrypted using a Snap-specific key and * automatically decrypted when retrieved. You can set `encrypted` to `false` to * use unencrypted storage (available when the client is locked). * * @example * ```json name="Manifest" * { * "initialPermissions": { * "snap_manageState": {} * } * } * ``` * ```ts name="Usage" * const state = await snap.request({ * method: 'snap_getState', * params: { * key: 'some.nested.value', // Optional, defaults to entire state * encrypted: true, // Optional, defaults to `true` * }, * }); * ``` */ export declare const getStateHandler: { implementation: typeof getStateImplementation; hookNames: MethodHooksObject<GetStateMethodHooks>; actionNames: ("SnapController:getSnapState" | "PermissionController:hasPermission")[]; }; declare const GetStateParametersStruct: import("@metamask/superstruct").Struct<{ encrypted?: boolean | undefined; key?: string | undefined; }, { key: import("@metamask/superstruct").Struct<string | undefined, null>; encrypted: import("@metamask/superstruct").Struct<boolean | undefined, null>; }>; export type GetStateParameters = InferMatching<typeof GetStateParametersStruct, GetStateParams>; /** * The `snap_getState` method implementation. * * @param request - The JSON-RPC request object. * @param response - 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.getUnlockPromise - Wait for the extension to be unlocked. * @param messenger - The messenger used to call controller actions. * @returns Nothing. */ declare function getStateImplementation(request: JsonRpcRequestWithOrigin<GetStateParameters>, response: PendingJsonRpcResponse<GetStateResult>, _next: unknown, end: JsonRpcEngineEndCallback, { getUnlockPromise }: GetStateMethodHooks, messenger: Messenger<string, GetStateMethodActions>): Promise<void>; /** * Get 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, `null` is returned. * * This is a simplified version of Lodash's `get` function, but Lodash doesn't * seem to be maintained anymore, so we're using our own implementation. * * @param value - The object to get the key from. * @param key - The key to get. * @returns The value of the key in the object, or `null` if the key does not * exist. */ export declare function get(value: Record<string, Json> | null, key?: string | undefined): Json; export {}; //# sourceMappingURL=getState.d.cts.map