@metamask/snaps-rpc-methods
Version:
MetaMask Snaps JSON-RPC method implementations
73 lines • 2.98 kB
text/typescript
import type { PermissionSpecificationBuilder, ValidPermissionSpecification, RestrictedMethodOptions, RestrictedMethodParameters } from "@metamask/permission-controller";
import { PermissionType } from "@metamask/permission-controller";
import type { GetPreferencesResult } from "@metamask/snaps-sdk";
import type { NonEmptyArray } from "@metamask/utils";
import type { MethodHooksObject } from "../utils.mjs";
declare const methodName = "snap_getPreferences";
export type GetPreferencesMethodHooks = {
getPreferences: () => GetPreferencesResult;
};
type SpecificationBuilderOptions = {
allowedCaveats?: Readonly<NonEmptyArray<string>> | null;
methodHooks: GetPreferencesMethodHooks;
};
type Specification = ValidPermissionSpecification<{
permissionType: PermissionType.RestrictedMethod;
targetName: typeof methodName;
methodImplementation: ReturnType<typeof getImplementation>;
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
}>;
/**
* The specification builder for the `snap_getPreferences` permission.
* `snap_getPreferences` allows snaps to access user preferences.
*
* @param options - The specification builder options.
* @param options.allowedCaveats - The optional allowed caveats for the permission.
* @param options.methodHooks - The RPC method hooks needed by the method implementation.
* @returns The specification for the `snap_getPreferences` permission.
*/
export declare const specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, SpecificationBuilderOptions, Specification>;
/**
* Gets the user's preferences.
*
* @example
* ```json name="Manifest"
* {
* "initialPermissions": {
* "snap_getPreferences": {}
* }
* }
* ```
* ```ts name="Usage"
* const preferences = await snap.request({
* method: 'snap_getPreferences',
* });
*
* console.log(preferences);
* // {
* // locale: 'en',
* // currency: 'usd',
* // ...
* // }
* ```
*/
export declare const getPreferencesBuilder: Readonly<{
readonly targetName: "snap_getPreferences";
readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, SpecificationBuilderOptions, {
permissionType: PermissionType.RestrictedMethod;
targetName: typeof methodName;
methodImplementation: ReturnType<typeof getImplementation>;
allowedCaveats: Readonly<NonEmptyArray<string>> | null;
}>;
readonly methodHooks: MethodHooksObject<GetPreferencesMethodHooks>;
}>;
/**
* Builds the method implementation for `snap_getPreferences`.
*
* @param hooks - The RPC method hooks.
* @param hooks.getPreferences - A function that returns the user selected preferences.
* @returns The user preferences.
*/
export declare function getImplementation({ getPreferences, }: GetPreferencesMethodHooks): (_args: RestrictedMethodOptions<RestrictedMethodParameters>) => Promise<GetPreferencesResult>;
export {};
//# sourceMappingURL=getPreferences.d.mts.map