UNPKG

@metamask/snaps-rpc-methods

Version:
83 lines 3.86 kB
import type { RestrictedMethodOptions, ValidPermissionSpecification, PermissionSpecificationBuilder } from "@metamask/permission-controller"; import { PermissionType } from "@metamask/permission-controller"; import type { ManageAccountsParams, ManageAccountsResult } from "@metamask/snaps-sdk"; import type { InferMatching } from "@metamask/snaps-utils"; import type { Json, NonEmptyArray } from "@metamask/utils"; declare const SnapMessageStruct: import("@metamask/superstruct").Struct<{ method: string; } | { method: string; params: Json[] | Record<string, Json>; }, null>; type Message = InferMatching<typeof SnapMessageStruct, ManageAccountsParams>; export declare const methodName = "snap_manageAccounts"; export type ManageAccountsMethodHooks = { /** * Gets the snap keyring implementation. */ getSnapKeyring: (snapOrigin: string) => Promise<{ handleKeyringSnapMessage: (snapId: string, message: Message) => Promise<Json>; }>; /** * Wait for the client to be unlocked. * * @returns A promise that resolves once the client is unlocked. */ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>; }; type ManageAccountsSpecificationBuilderOptions = { allowedCaveats?: Readonly<NonEmptyArray<string>> | null; methodHooks: ManageAccountsMethodHooks; }; type ManageAccountsSpecification = ValidPermissionSpecification<{ permissionType: PermissionType.RestrictedMethod; targetName: typeof methodName; methodImplementation: ReturnType<typeof manageAccountsImplementation>; allowedCaveats: Readonly<NonEmptyArray<string>> | null; }>; /** * The specification builder for the `snap_manageAccounts` permission. * `snap_manageAccounts` lets the Snap manage a set of accounts via a custom keyring. * * @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_manageAccounts` permission. */ export declare const specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, ManageAccountsSpecificationBuilderOptions, ManageAccountsSpecification>; /** * Builds the method implementation for `snap_manageAccounts`. * * @param hooks - The RPC method hooks. * @param hooks.getSnapKeyring - A function to get the snap keyring. * @param hooks.getUnlockPromise - The function to get the unlock promise. * @returns The method implementation which either returns `null` for a * successful state update/deletion or returns the decrypted state. * @throws If the params are invalid. */ export declare function manageAccountsImplementation({ getSnapKeyring, getUnlockPromise, }: ManageAccountsMethodHooks): (options: RestrictedMethodOptions<ManageAccountsParams>) => Promise<ManageAccountsResult>; /** * Manage account management Snap accounts. This method is organized into * multiple sub-methods which each take their own parameters: * * - `createAccount` * - `updateAccount` * - `deleteAccount` * - `listAccounts` * - `submitResponse` */ export declare const manageAccountsBuilder: Readonly<{ readonly targetName: "snap_manageAccounts"; readonly specificationBuilder: PermissionSpecificationBuilder<PermissionType.RestrictedMethod, ManageAccountsSpecificationBuilderOptions, { permissionType: PermissionType.RestrictedMethod; targetName: typeof methodName; methodImplementation: ReturnType<typeof manageAccountsImplementation>; allowedCaveats: Readonly<NonEmptyArray<string>> | null; }>; readonly methodHooks: { readonly getSnapKeyring: true; readonly getUnlockPromise: true; }; }>; export {}; //# sourceMappingURL=manageAccounts.d.mts.map