import type { CryptographicFunctions } from "@metamask/key-tree"; import type { ActionConstraint, EventConstraint, NamespacedName } from "@metamask/messenger"; import { Messenger } from "@metamask/messenger"; import { type Caveat, type RequestedPermissions } from "@metamask/permission-controller"; import type { ExecutionService } from "@metamask/snaps-controllers"; import type { TrackEventParams, SnapId, TraceRequest, EndTraceRequest, TraceContext } from "@metamask/snaps-sdk"; import type { Snap, VirtualFile } from "@metamask/snaps-utils"; import type { Hex, Json } from "@metamask/utils"; import type { RootControllerMessenger } from "./controllers.cjs"; import type { SnapHelpers } from "./helpers.cjs"; import type { SimulationAccount, SimulationOptions, SimulationUserOptions } from "./options.cjs"; import type { ApplicationState, RunSagaFunction, Store } from "./store/index.cjs"; /** * Options for the execution service, without the options that are shared * between all execution services. * * @template Service - The type of the execution service, i.e., the class that * creates the execution service. */ export type ExecutionServiceOptions any> = Omit[0], keyof ConstructorParameters[0]>; /** * The options for running a Snap in a simulated environment. * * @property executionService - The execution service to use. * @property executionServiceOptions - The options to use when creating the * execution service, if any. This should only include options specific to the * provided execution service. * @property options - The simulation options. * @template Service - The type of the execution service. */ export type InstallSnapOptions InstanceType> = ExecutionServiceOptions extends Record ? { executionService: Service; executionServiceOptions?: ExecutionServiceOptions; options?: SimulationUserOptions; } : { executionService: Service; executionServiceOptions: ExecutionServiceOptions; options?: SimulationUserOptions; }; export type InstalledSnap = { snapId: SnapId; store: Store; executionService: InstanceType; controllerMessenger: Messenger; runSaga: RunSagaFunction; }; export type RestrictedMiddlewareHooks = { /** * A hook that returns the user's secret recovery phrase. * * @returns The user's secret recovery phrase. */ getMnemonic: () => Promise; /** * A hook that returns whether the client is locked or not. * * @returns A boolean flag signaling whether the client is locked. */ getIsLocked: () => boolean; /** * Get the cryptographic functions to use for the client. This may return an * empty object to fall back to the default cryptographic functions. * * @returns The cryptographic functions to use for the client. */ getClientCryptography: () => CryptographicFunctions; /** * A hook that returns metadata about a given Snap. * * @param snapId - The ID of a Snap. * @returns The metadata for the given Snap. */ getSnap: (snapId: string) => Snap; /** * A hook that sets the current chain ID. * * @param chainId - The chain ID. */ setCurrentChain: (chainId: Hex) => null; /** * A hook that gets the current simulation state. * * @returns The simulation state. */ getSimulationState: () => ApplicationState; }; export type PermittedMiddlewareHooks = { /** * A hook that returns a promise that resolves once the extension is unlocked. * * @param shouldShowUnlockRequest - Whether to show the unlock request. * @returns A promise that resolves once the extension is unlocked. */ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise; /** * A hook that returns whether the client is active or not. * * @returns A boolean flag signaling whether the client is opened. */ getIsActive: () => boolean; /** * A hook that returns the client version. * * @returns A string that corresponds to the client version. */ getVersion: () => string; /** * A hook that tracks an error. * * @param error - The error object containing error details and properties. */ trackError(error: Error): void; /** * A hook that tracks an event. * * @param event - The event object containing event details and properties. */ trackEvent(event: TrackEventParams['event']): void; /** * A hook that starts a performance trace. * * @param request - The trace request object containing trace details. */ startTrace(request: TraceRequest): TraceContext; /** * A hook that ends a performance trace. * * @param request - The trace request object containing trace details. * @returns The trace data. */ endTrace(request: EndTraceRequest): void; /** * A hook that returns the allowed keyring methods. * * @returns The keyring methods. */ getAllowedKeyringMethods(): string[]; /** * A hook that returns a specialized messenger for the Snap. * * @returns The messenger. */ getMessenger(args: { actions?: string[]; events?: string[]; }): Messenger; }; export type MultichainMiddlewareHooks = { /** * A hook that returns the simulated accounts. * * @returns The simulated accounts. */ getAccounts: () => SimulationAccount[]; /** * A hook that retrieves a caveat for a given permission. * * @param permission - The permission name. * @param caveatType - The caveat type. * @returns The caveat, if it exists. */ getCaveat: (permission: string, caveatType: string) => Caveat | undefined; /** * A hook that grants permissions to the origin. * * @param permissions - The permissions. */ grantPermissions: (permissions: RequestedPermissions) => void; /** * A hook that revokes a permission for the origin. * * @param permission - The permission name. */ revokePermission: (permission: string) => void; }; /** * Install a Snap in a simulated environment. This will fetch the Snap files, * create a Redux store, set up the controllers and JSON-RPC stack, register the * Snap, and run the Snap code in the execution service. * * @param snapId - The ID of the Snap to install. * @param options - The options to use when installing the Snap. * @param options.executionService - The execution service to use. * @param options.executionServiceOptions - The options to use when creating the * execution service, if any. This should only include options specific to the * provided execution service. * @param options.options - The simulation options. * @returns The installed Snap object. * @template Service - The type of the execution service. */ export declare function installSnap InstanceType>(snapId: SnapId, { executionService, executionServiceOptions, options: rawOptions, }?: Partial>): Promise; /** * Get the hooks for the simulation. * * @param options - The simulation options. * @param store - The Redux store. * @param runSaga - The run saga function. * @returns The hooks for the simulation. */ export declare function getRestrictedHooks(options: SimulationOptions, store: Store, runSaga: RunSagaFunction): RestrictedMiddlewareHooks; /** * Get the permitted hooks for the simulation. * * @param snapId - The Snap ID. * @param controllerMessenger - The controller messenger. * @param runSaga - The run saga function. * @returns The permitted hooks for the simulation. */ export declare function getPermittedHooks(snapId: string, controllerMessenger: RootControllerMessenger, runSaga: RunSagaFunction): PermittedMiddlewareHooks; /** * Get the hooks for the multichain middleware simulation. * * @param snapId - The Snap ID. * @param options - The simulation options. * @param controllerMessenger - The controller messenger. * @returns The hooks for the middleware. */ export declare function getMultichainHooks(snapId: SnapId, options: SimulationOptions, controllerMessenger: RootControllerMessenger): MultichainMiddlewareHooks; /** * Get the mock mnemonic for a given source ID. * * @param options - The simulation options. * @returns The mnemonic. */ /** * Register mocked action handlers. * * @param controllerMessenger - The controller messenger. * @param runSaga - The run saga function. * @param options - The simulation options. * @param snapId - The ID of the Snap. * @param auxiliaryFiles - Auxiliary files from the fetched Snap. */ export declare function registerActions(controllerMessenger: RootControllerMessenger, runSaga: RunSagaFunction, options: SimulationOptions, snapId: SnapId, auxiliaryFiles: VirtualFile[]): void; //# sourceMappingURL=simulation.d.cts.map