import { BaseControllerV2, type RestrictedControllerMessenger } from '@metamask/base-controller'; import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine'; import type { Json, JsonRpcRequest, JsonRpcParams, PendingJsonRpcResponse } from '@metamask/utils'; import { LOG_METHOD_TYPES } from './enums'; export declare type JsonRpcRequestWithOrigin = JsonRpcRequest & { origin?: string; }; export declare type Caveat = { type: string; value: string[]; }; export declare type Permission = { parentCapability: string; caveats?: Caveat[]; }; export declare type PermissionActivityLog = { id: string | number | null; method: string; methodType: LOG_METHOD_TYPES; origin?: string; requestTime: number; responseTime: number | null; success: boolean | null; }; export declare type PermissionName = string; export declare type PermissionLog = { accounts?: Record; lastApproved: number; }; export declare type PermissionEntry = Record; export declare type PermissionOrigin = string; export declare type PermissionHistory = Record; /** * * Permission log controller state * @property permissionHistory - permission history * @property permissionActivityLog - permission activity logs */ export declare type PermissionLogControllerState = { permissionHistory: PermissionHistory; permissionActivityLog: PermissionActivityLog[]; }; export declare type PermissionLogControllerOptions = { restrictedMethods: Set; state?: Partial; messenger: PermissionLogControllerMessenger; }; export declare type PermissionLogControllerMessenger = RestrictedControllerMessenger; /** * The name of the {@link PermissionController}. */ declare const name = "PermissionLogController"; /** * Controller with middleware for logging requests and responses to restricted * and permissions-related methods. */ export declare class PermissionLogController extends BaseControllerV2 { restrictedMethods: Set; constructor({ messenger, restrictedMethods, state, }: PermissionLogControllerOptions); /** * Get the restricted method activity log. * * @returns The activity log. */ getActivityLog(): PermissionActivityLog[]; /** * Update the restricted method activity log. * * @param logs - The new activity log array. */ updateActivityLog(logs: PermissionActivityLog[]): void; /** * Get the permission history log. * * @returns The permissions history log. */ getHistory(): PermissionHistory; /** * Update the permission history log. * * @param history - The new permissions history log object. */ updateHistory(history: PermissionHistory): void; /** * Updates the exposed account history for the given origin. * Sets the 'last seen' time to Date.now() for the given accounts. * Does **not** update the 'lastApproved' time for the permission itself. * Returns if the accounts array is empty. * * @param origin - The origin that the accounts are exposed to. * @param accounts - The accounts. */ updateAccountsHistory(origin: string, accounts: string[]): void; /** * Create a permissions log middleware. Records permissions activity and history: * * Activity: requests and responses for restricted and most wallet_ methods. * * History: for each origin, the last time a permission was granted, including * which accounts were exposed, if any. * * @returns The permissions log middleware. */ createMiddleware(): JsonRpcMiddleware; /** * Creates and commits an activity log entry, without response data. * * @param request - The request object. * @param isInternal - Whether the request is internal. * @returns new added activity entry */ logRequest(request: JsonRpcRequestWithOrigin, isInternal: boolean): PermissionActivityLog; /** * Adds response data to an existing activity log entry. * Entry assumed already committed (i.e., in the log). * * @param entry - The entry to add a response to. * @param response - The response object. * @param time - Output from Date.now() */ logResponse(entry: PermissionActivityLog, response: PendingJsonRpcResponse, time: number): void; /** * Commit a new entry to the activity log. * Removes the oldest entry from the log if it exceeds the log limit. * * @param entry - The activity log entry. */ commitNewActivity(entry: PermissionActivityLog): void; /** * Create new permissions history log entries, if any, and commit them. * * @param requestedMethods - The method names corresponding to the requested permissions. * @param origin - The origin of the permissions request. * @param result - The permissions request response.result. * @param time - The time of the request, i.e. Date.now(). * @param isEthRequestAccounts - Whether the permissions request was 'eth_requestAccounts'. */ logPermissionsHistory(requestedMethods: string[], origin: string, result: Json, time: number, isEthRequestAccounts: boolean): void; /** * Commit new entries to the permissions history log. * Merges the history for the given origin, overwriting existing entries * with the same key (permission name). * * @param origin - The requesting origin. * @param newEntries - The new entries to commit. */ commitNewHistory(origin: string, newEntries: Record>): void; /** * Get all requested methods from a permissions request. * * @param request - The request object. * @returns The names of the requested permissions. */ getRequestedMethods(request: JsonRpcRequestWithOrigin): string[] | null; /** * Get the permitted accounts from an eth_accounts permissions object. * Returns an empty array if the permission is not eth_accounts. * * @param perm - The permissions object. * @param perm.parentCapability - The permissions parentCapability. * @param perm.caveats - The permissions caveats. * @returns The permitted accounts. */ getAccountsFromPermission(perm: Permission): string[]; } export {}; //# sourceMappingURL=PermissionLogController.d.ts.map