@metamask-previews/gator-permissions-controller 0.6.0-preview-2b2b3f4d → 0.7.0-preview-be27197a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,8 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.7.0]
11
+
10
12
  ### Added
11
13
 
14
+ - Refresh gator permissions map after revocation state change ([#7235](https://github.com/MetaMask/core/pull/7235))
12
15
  - Add `submitDirectRevocation` method for already-disabled delegations that don't require an on-chain transaction ([#7244](https://github.com/MetaMask/core/pull/7244))
13
16
 
14
17
  ### Changed
@@ -94,7 +97,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
94
97
 
95
98
  - Initial release ([#6033](https://github.com/MetaMask/core/pull/6033))
96
99
 
97
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.6.0...HEAD
100
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.7.0...HEAD
101
+ [0.7.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.6.0...@metamask/gator-permissions-controller@0.7.0
98
102
  [0.6.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.5.0...@metamask/gator-permissions-controller@0.6.0
99
103
  [0.5.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.4.0...@metamask/gator-permissions-controller@0.5.0
100
104
  [0.4.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.3.0...@metamask/gator-permissions-controller@0.4.0
@@ -335,6 +335,16 @@ class GatorPermissionsController extends base_controller_1.BaseController {
335
335
  dropped: undefined,
336
336
  timeoutId: undefined,
337
337
  };
338
+ // Helper to refresh permissions after transaction state change
339
+ const refreshPermissions = (context) => {
340
+ this.fetchAndUpdateGatorPermissions({ isRevoked: false }).catch((error) => {
341
+ (0, logger_1.controllerLog)(`Failed to refresh permissions after ${context}`, {
342
+ txId,
343
+ permissionContext,
344
+ error,
345
+ });
346
+ });
347
+ };
338
348
  // Helper to unsubscribe from approval/rejection events after decision is made
339
349
  const cleanupApprovalHandlers = () => {
340
350
  if (handlers.approved) {
@@ -396,13 +406,15 @@ class GatorPermissionsController extends base_controller_1.BaseController {
396
406
  txId,
397
407
  permissionContext,
398
408
  });
399
- this.submitRevocation({ permissionContext }).catch((error) => {
409
+ this.submitRevocation({ permissionContext })
410
+ .catch((error) => {
400
411
  (0, logger_1.controllerLog)('Failed to submit revocation after transaction confirmed', {
401
412
  txId,
402
413
  permissionContext,
403
414
  error,
404
415
  });
405
- });
416
+ })
417
+ .finally(() => refreshPermissions('transaction confirmed'));
406
418
  cleanup(transactionMeta.id);
407
419
  }
408
420
  };
@@ -415,6 +427,7 @@ class GatorPermissionsController extends base_controller_1.BaseController {
415
427
  error: payload.error,
416
428
  });
417
429
  cleanup(payload.transactionMeta.id);
430
+ refreshPermissions('transaction failed');
418
431
  }
419
432
  };
420
433
  // Handle dropped transaction - cleanup without submitting revocation
@@ -425,6 +438,7 @@ class GatorPermissionsController extends base_controller_1.BaseController {
425
438
  permissionContext,
426
439
  });
427
440
  cleanup(payload.transactionMeta.id);
441
+ refreshPermissions('transaction dropped');
428
442
  }
429
443
  };
430
444
  // Subscribe to user approval/rejection events
@@ -1 +1 @@
1
- {"version":3,"file":"GatorPermissionsController.cjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;;;;AAMA,+DAA2D;AAC3D,6EAAuE;AAIvE,uDAAoD;AAWpD,mEAI4B;AAC5B,yCAMkB;AAClB,yCAAyC;AAEzC,uCAQiB;AACjB,uCAGiB;AAEjB,kBAAkB;AAElB,iCAAiC;AACjC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,2DAA2D;AAC3D,MAAM,qCAAqC,GACzC,sCAAgD,CAAC;AAE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uBAAuB,CAAC;YAC7B,KAAK,oBAAoB,CAAC;YAC1B,KAAK,sBAAsB;gBACzB,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;oBAClD,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBACpD,CAAC;gBAGC,mBAAmB,CAAC,cAAc,CAAC,CACjC,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;YACR;gBACE,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBACxC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBAC1C,CAAC;gBAGC,mBAAmB,CAAC,KAAK,CACvB,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;QACV,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,sBAAsB,EAAE,EAAE;QAC1B,KAAK,EAAE,EAAE;KACa,CACzB,CAAC;AACJ,CAAC;kBAxQkB,0BAA0B","sourcesContent":["import type { Signer } from '@metamask/7715-permission-types';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\n\nimport type { DecodedPermission } from './decodePermission';\nimport {\n getPermissionDataAndExpiry,\n identifyPermissionByEnforcers,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsNotEnabledError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport { controllerLog } from './logger';\nimport type { StoredGatorPermissionSanitized } from './types';\nimport {\n GatorPermissionsSnapRpcMethod,\n type GatorPermissionsMap,\n type PermissionTypesWithCustom,\n type StoredGatorPermission,\n type DelegationDetails,\n type RevocationParams,\n type PendingRevocationParams,\n} from './types';\nimport {\n deserializeGatorPermissionsMap,\n serializeGatorPermissionsMap,\n} from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst defaultGatorPermissionsMap: GatorPermissionsMap = {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n};\n\n/**\n * Delegation framework version used to select the correct deployed enforcer\n * contract addresses from `@metamask/delegation-deployments`.\n */\nexport const DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === STATE ===\n\n/**\n * State shape for GatorPermissionsController\n */\nexport type GatorPermissionsControllerState = {\n /**\n * Flag that indicates if the gator permissions feature is enabled\n */\n isGatorPermissionsEnabled: boolean;\n\n /**\n * JSON serialized object containing gator permissions fetched from profile sync\n */\n gatorPermissionsMapSerialized: string;\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This is used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * The ID of the Snap of the gator permissions provider snap\n * Default value is `@metamask/gator-permissions-snap`\n */\n gatorPermissionsProviderSnapId: SnapId;\n\n /**\n * List of gator permission pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n isGatorPermissionsEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsMapSerialized: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsProviderSnapId: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Constructs the default {@link GatorPermissionsController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link GatorPermissionsController} state.\n */\nexport function getDefaultGatorPermissionsControllerState(): GatorPermissionsControllerState {\n return {\n isGatorPermissionsEnabled: false,\n gatorPermissionsMapSerialized: serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n ),\n isFetchingGatorPermissions: false,\n gatorPermissionsProviderSnapId: defaultGatorPermissionsProviderSnapId,\n pendingRevocations: [],\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * The action which can be used to fetch and update gator permissions.\n */\nexport type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {\n type: `${typeof controllerName}:fetchAndUpdateGatorPermissions`;\n handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];\n};\n\n/**\n * The action which can be used to enable gator permissions.\n */\nexport type GatorPermissionsControllerEnableGatorPermissionsAction = {\n type: `${typeof controllerName}:enableGatorPermissions`;\n handler: GatorPermissionsController['enableGatorPermissions'];\n};\n\n/**\n * The action which can be used to disable gator permissions.\n */\nexport type GatorPermissionsControllerDisableGatorPermissionsAction = {\n type: `${typeof controllerName}:disableGatorPermissions`;\n handler: GatorPermissionsController['disableGatorPermissions'];\n};\n\nexport type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction =\n {\n type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;\n handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];\n };\n\n/**\n * The action which can be used to submit a revocation.\n */\nexport type GatorPermissionsControllerSubmitRevocationAction = {\n type: `${typeof controllerName}:submitRevocation`;\n handler: GatorPermissionsController['submitRevocation'];\n};\n\n/**\n * The action which can be used to add a pending revocation.\n */\nexport type GatorPermissionsControllerAddPendingRevocationAction = {\n type: `${typeof controllerName}:addPendingRevocation`;\n handler: GatorPermissionsController['addPendingRevocation'];\n};\n\n/**\n * The action which can be used to submit a revocation directly without requiring\n * an on-chain transaction (for already-disabled delegations).\n */\nexport type GatorPermissionsControllerSubmitDirectRevocationAction = {\n type: `${typeof controllerName}:submitDirectRevocation`;\n handler: GatorPermissionsController['submitDirectRevocation'];\n};\n\n/**\n * The action which can be used to check if a permission context is pending revocation.\n */\nexport type GatorPermissionsControllerIsPendingRevocationAction = {\n type: `${typeof controllerName}:isPendingRevocation`;\n handler: GatorPermissionsController['isPendingRevocation'];\n};\n\n/**\n * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction\n | GatorPermissionsControllerEnableGatorPermissionsAction\n | GatorPermissionsControllerDisableGatorPermissionsAction\n | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapsController:handleRequest and SnapsController:has are allowed to be called\n * internally because they are used to fetch gator permissions from the Snap.\n */\ntype AllowedActions = HandleSnapRequest | HasSnap;\n\n/**\n * The event that {@link GatorPermissionsController} publishes when updating state.\n */\nexport type GatorPermissionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n GatorPermissionsControllerState\n >;\n\n/**\n * All events that {@link GatorPermissionsController} publishes, to be subscribed to\n * externally.\n */\nexport type GatorPermissionsControllerEvents =\n GatorPermissionsControllerStateChangeEvent;\n\n/**\n * Events that {@link GatorPermissionsController} is allowed to subscribe to internally.\n */\ntype AllowedEvents =\n | GatorPermissionsControllerStateChangeEvent\n | TransactionControllerTransactionApprovedEvent\n | TransactionControllerTransactionRejectedEvent\n | TransactionControllerTransactionConfirmedEvent\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionDroppedEvent;\n\n/**\n * Messenger type for the GatorPermissionsController.\n */\nexport type GatorPermissionsControllerMessenger = Messenger<\n typeof controllerName,\n GatorPermissionsControllerActions | AllowedActions,\n GatorPermissionsControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that manages gator permissions by reading from profile sync\n */\nexport default class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: {\n ...getDefaultGatorPermissionsControllerState(),\n ...state,\n isFetchingGatorPermissions: false,\n },\n });\n\n this.#registerMessageHandlers();\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean) {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #setIsGatorPermissionsEnabled(isGatorPermissionsEnabled: boolean) {\n this.update((state) => {\n state.isGatorPermissionsEnabled = isGatorPermissionsEnabled;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchAndUpdateGatorPermissions`,\n this.fetchAndUpdateGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:enableGatorPermissions`,\n this.enableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:disableGatorPermissions`,\n this.disableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:decodePermissionFromPermissionContextForOrigin`,\n this.decodePermissionFromPermissionContextForOrigin.bind(this),\n );\n\n const submitRevocationAction = `${controllerName}:submitRevocation`;\n\n this.messenger.registerActionHandler(\n submitRevocationAction,\n this.submitRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:addPendingRevocation`,\n this.addPendingRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitDirectRevocation`,\n this.submitDirectRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:isPendingRevocation`,\n this.isPendingRevocation.bind(this),\n );\n }\n\n /**\n * Asserts that the gator permissions are enabled.\n *\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n */\n #assertGatorPermissionsEnabled() {\n if (!this.state.isGatorPermissionsEnabled) {\n throw new GatorPermissionsNotEnabledError();\n }\n }\n\n /**\n * Forwards a Snap request to the SnapController.\n *\n * @param args - The request parameters.\n * @param args.snapId - The ID of the Snap of the gator permissions provider snap.\n * @param args.params - Optional parameters to pass to the snap method.\n * @returns A promise that resolves with the gator permissions.\n */\n async #handleSnapRequestToGatorPermissionsProvider({\n snapId,\n params,\n }: {\n snapId: SnapId;\n params?: Json;\n }): Promise<\n StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null\n > {\n try {\n const response = (await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n ...(params !== undefined && { params }),\n },\n },\n )) as StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null;\n\n return response;\n } catch (error) {\n controllerLog(\n 'Failed to handle snap request to gator permissions provider',\n error,\n );\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n cause: error as Error,\n });\n }\n }\n\n /**\n * Sanitizes a stored gator permission by removing the fields that are not expose to MetaMask client.\n *\n * @param storedGatorPermission - The stored gator permission to sanitize.\n * @returns The sanitized stored gator permission.\n */\n #sanitizeStoredGatorPermission(\n storedGatorPermission: StoredGatorPermission<\n Signer,\n PermissionTypesWithCustom\n >,\n ): StoredGatorPermissionSanitized<Signer, PermissionTypesWithCustom> {\n const { permissionResponse } = storedGatorPermission;\n const { rules, dependencyInfo, signer, ...rest } = permissionResponse;\n return {\n ...storedGatorPermission,\n permissionResponse: {\n ...rest,\n },\n };\n }\n\n /**\n * Categorizes stored gator permissions by type and chainId.\n *\n * @param storedGatorPermissions - An array of stored gator permissions.\n * @returns The gator permissions map.\n */\n #categorizePermissionsDataByTypeAndChainId(\n storedGatorPermissions:\n | StoredGatorPermission<Signer, PermissionTypesWithCustom>[]\n | null,\n ): GatorPermissionsMap {\n if (!storedGatorPermissions) {\n return defaultGatorPermissionsMap;\n }\n\n return storedGatorPermissions.reduce(\n (gatorPermissionsMap, storedGatorPermission) => {\n const { permissionResponse } = storedGatorPermission;\n const permissionType = permissionResponse.permission.type;\n const { chainId } = permissionResponse;\n\n const sanitizedStoredGatorPermission =\n this.#sanitizeStoredGatorPermission(storedGatorPermission);\n\n switch (permissionType) {\n case 'native-token-stream':\n case 'native-token-periodic':\n case 'erc20-token-stream':\n case 'erc20-token-periodic':\n if (!gatorPermissionsMap[permissionType][chainId]) {\n gatorPermissionsMap[permissionType][chainId] = [];\n }\n\n (\n gatorPermissionsMap[permissionType][\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n default:\n if (!gatorPermissionsMap.other[chainId]) {\n gatorPermissionsMap.other[chainId] = [];\n }\n\n (\n gatorPermissionsMap.other[\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n }\n\n return gatorPermissionsMap;\n },\n {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n } as GatorPermissionsMap,\n );\n }\n\n /**\n * Gets the gator permissions map from the state.\n *\n * @returns The gator permissions map.\n */\n get gatorPermissionsMap(): GatorPermissionsMap {\n return deserializeGatorPermissionsMap(\n this.state.gatorPermissionsMapSerialized,\n );\n }\n\n /**\n * Gets the gator permissions provider snap id that is used to fetch gator permissions.\n *\n * @returns The gator permissions provider snap id.\n */\n get permissionsProviderSnapId(): SnapId {\n return this.state.gatorPermissionsProviderSnapId;\n }\n\n /**\n * Enables gator permissions for the user.\n */\n public async enableGatorPermissions() {\n this.#setIsGatorPermissionsEnabled(true);\n }\n\n /**\n * Clears the gator permissions map and disables the feature.\n */\n public async disableGatorPermissions() {\n this.update((state) => {\n state.isGatorPermissionsEnabled = false;\n state.gatorPermissionsMapSerialized = serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n );\n });\n }\n\n /**\n * Gets the pending revocations list.\n *\n * @returns The pending revocations list.\n */\n get pendingRevocations(): { txId: string; permissionContext: Hex }[] {\n return this.state.pendingRevocations;\n }\n\n /**\n * Fetches the gator permissions from profile sync and updates the state.\n *\n * @param params - Optional parameters to pass to the snap's getGrantedPermissions method.\n * @returns A promise that resolves to the gator permissions map.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public async fetchAndUpdateGatorPermissions(\n params?: Json,\n ): Promise<GatorPermissionsMap> {\n try {\n this.#setIsFetchingGatorPermissions(true);\n this.#assertGatorPermissionsEnabled();\n\n const permissionsData =\n await this.#handleSnapRequestToGatorPermissionsProvider({\n snapId: this.state.gatorPermissionsProviderSnapId,\n params,\n });\n\n const gatorPermissionsMap =\n this.#categorizePermissionsDataByTypeAndChainId(permissionsData);\n\n this.update((state) => {\n state.gatorPermissionsMapSerialized =\n serializeGatorPermissionsMap(gatorPermissionsMap);\n });\n\n return gatorPermissionsMap;\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, signer, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.permissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n\n const permissionType = identifyPermissionByEnforcers({\n enforcers,\n contracts,\n });\n\n const { expiry, data } = getPermissionDataAndExpiry({\n contracts,\n caveats,\n permissionType,\n });\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n const snapRequest = {\n snapId: this.state.gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions({ isRevoked: false });\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = () => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true) => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta) => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n });\n\n this.submitRevocation({ permissionContext }).catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n });\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n this.#assertGatorPermissionsEnabled();\n\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n permissionContext.toLowerCase(),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"GatorPermissionsController.cjs","sourceRoot":"","sources":["../src/Gat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,EAAE,CAAC;gBAC1C,CAAC;gBAGC,mBAAmB,CAAC,KAAK,CACvB,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;QACV,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,sBAAsB,EAAE,EAAE;QAC1B,KAAK,EAAE,EAAE;KACa,CACzB,CAAC;AACJ,CAAC;kBAxQkB,0BAA0B","sourcesContent":["import type { Signer } from '@metamask/7715-permission-types';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\n\nimport type { DecodedPermission } from './decodePermission';\nimport {\n getPermissionDataAndExpiry,\n identifyPermissionByEnforcers,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsNotEnabledError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport { controllerLog } from './logger';\nimport type { StoredGatorPermissionSanitized } from './types';\nimport {\n GatorPermissionsSnapRpcMethod,\n type GatorPermissionsMap,\n type PermissionTypesWithCustom,\n type StoredGatorPermission,\n type DelegationDetails,\n type RevocationParams,\n type PendingRevocationParams,\n} from './types';\nimport {\n deserializeGatorPermissionsMap,\n serializeGatorPermissionsMap,\n} from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst defaultGatorPermissionsMap: GatorPermissionsMap = {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n};\n\n/**\n * Delegation framework version used to select the correct deployed enforcer\n * contract addresses from `@metamask/delegation-deployments`.\n */\nexport const DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === STATE ===\n\n/**\n * State shape for GatorPermissionsController\n */\nexport type GatorPermissionsControllerState = {\n /**\n * Flag that indicates if the gator permissions feature is enabled\n */\n isGatorPermissionsEnabled: boolean;\n\n /**\n * JSON serialized object containing gator permissions fetched from profile sync\n */\n gatorPermissionsMapSerialized: string;\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This is used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * The ID of the Snap of the gator permissions provider snap\n * Default value is `@metamask/gator-permissions-snap`\n */\n gatorPermissionsProviderSnapId: SnapId;\n\n /**\n * List of gator permission pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n isGatorPermissionsEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsMapSerialized: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsProviderSnapId: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Constructs the default {@link GatorPermissionsController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link GatorPermissionsController} state.\n */\nexport function getDefaultGatorPermissionsControllerState(): GatorPermissionsControllerState {\n return {\n isGatorPermissionsEnabled: false,\n gatorPermissionsMapSerialized: serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n ),\n isFetchingGatorPermissions: false,\n gatorPermissionsProviderSnapId: defaultGatorPermissionsProviderSnapId,\n pendingRevocations: [],\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * The action which can be used to fetch and update gator permissions.\n */\nexport type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {\n type: `${typeof controllerName}:fetchAndUpdateGatorPermissions`;\n handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];\n};\n\n/**\n * The action which can be used to enable gator permissions.\n */\nexport type GatorPermissionsControllerEnableGatorPermissionsAction = {\n type: `${typeof controllerName}:enableGatorPermissions`;\n handler: GatorPermissionsController['enableGatorPermissions'];\n};\n\n/**\n * The action which can be used to disable gator permissions.\n */\nexport type GatorPermissionsControllerDisableGatorPermissionsAction = {\n type: `${typeof controllerName}:disableGatorPermissions`;\n handler: GatorPermissionsController['disableGatorPermissions'];\n};\n\nexport type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction =\n {\n type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;\n handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];\n };\n\n/**\n * The action which can be used to submit a revocation.\n */\nexport type GatorPermissionsControllerSubmitRevocationAction = {\n type: `${typeof controllerName}:submitRevocation`;\n handler: GatorPermissionsController['submitRevocation'];\n};\n\n/**\n * The action which can be used to add a pending revocation.\n */\nexport type GatorPermissionsControllerAddPendingRevocationAction = {\n type: `${typeof controllerName}:addPendingRevocation`;\n handler: GatorPermissionsController['addPendingRevocation'];\n};\n\n/**\n * The action which can be used to submit a revocation directly without requiring\n * an on-chain transaction (for already-disabled delegations).\n */\nexport type GatorPermissionsControllerSubmitDirectRevocationAction = {\n type: `${typeof controllerName}:submitDirectRevocation`;\n handler: GatorPermissionsController['submitDirectRevocation'];\n};\n\n/**\n * The action which can be used to check if a permission context is pending revocation.\n */\nexport type GatorPermissionsControllerIsPendingRevocationAction = {\n type: `${typeof controllerName}:isPendingRevocation`;\n handler: GatorPermissionsController['isPendingRevocation'];\n};\n\n/**\n * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction\n | GatorPermissionsControllerEnableGatorPermissionsAction\n | GatorPermissionsControllerDisableGatorPermissionsAction\n | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapsController:handleRequest and SnapsController:has are allowed to be called\n * internally because they are used to fetch gator permissions from the Snap.\n */\ntype AllowedActions = HandleSnapRequest | HasSnap;\n\n/**\n * The event that {@link GatorPermissionsController} publishes when updating state.\n */\nexport type GatorPermissionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n GatorPermissionsControllerState\n >;\n\n/**\n * All events that {@link GatorPermissionsController} publishes, to be subscribed to\n * externally.\n */\nexport type GatorPermissionsControllerEvents =\n GatorPermissionsControllerStateChangeEvent;\n\n/**\n * Events that {@link GatorPermissionsController} is allowed to subscribe to internally.\n */\ntype AllowedEvents =\n | GatorPermissionsControllerStateChangeEvent\n | TransactionControllerTransactionApprovedEvent\n | TransactionControllerTransactionRejectedEvent\n | TransactionControllerTransactionConfirmedEvent\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionDroppedEvent;\n\n/**\n * Messenger type for the GatorPermissionsController.\n */\nexport type GatorPermissionsControllerMessenger = Messenger<\n typeof controllerName,\n GatorPermissionsControllerActions | AllowedActions,\n GatorPermissionsControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that manages gator permissions by reading from profile sync\n */\nexport default class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: {\n ...getDefaultGatorPermissionsControllerState(),\n ...state,\n isFetchingGatorPermissions: false,\n },\n });\n\n this.#registerMessageHandlers();\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean) {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #setIsGatorPermissionsEnabled(isGatorPermissionsEnabled: boolean) {\n this.update((state) => {\n state.isGatorPermissionsEnabled = isGatorPermissionsEnabled;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchAndUpdateGatorPermissions`,\n this.fetchAndUpdateGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:enableGatorPermissions`,\n this.enableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:disableGatorPermissions`,\n this.disableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:decodePermissionFromPermissionContextForOrigin`,\n this.decodePermissionFromPermissionContextForOrigin.bind(this),\n );\n\n const submitRevocationAction = `${controllerName}:submitRevocation`;\n\n this.messenger.registerActionHandler(\n submitRevocationAction,\n this.submitRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:addPendingRevocation`,\n this.addPendingRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitDirectRevocation`,\n this.submitDirectRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:isPendingRevocation`,\n this.isPendingRevocation.bind(this),\n );\n }\n\n /**\n * Asserts that the gator permissions are enabled.\n *\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n */\n #assertGatorPermissionsEnabled() {\n if (!this.state.isGatorPermissionsEnabled) {\n throw new GatorPermissionsNotEnabledError();\n }\n }\n\n /**\n * Forwards a Snap request to the SnapController.\n *\n * @param args - The request parameters.\n * @param args.snapId - The ID of the Snap of the gator permissions provider snap.\n * @param args.params - Optional parameters to pass to the snap method.\n * @returns A promise that resolves with the gator permissions.\n */\n async #handleSnapRequestToGatorPermissionsProvider({\n snapId,\n params,\n }: {\n snapId: SnapId;\n params?: Json;\n }): Promise<\n StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null\n > {\n try {\n const response = (await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n ...(params !== undefined && { params }),\n },\n },\n )) as StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null;\n\n return response;\n } catch (error) {\n controllerLog(\n 'Failed to handle snap request to gator permissions provider',\n error,\n );\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n cause: error as Error,\n });\n }\n }\n\n /**\n * Sanitizes a stored gator permission by removing the fields that are not expose to MetaMask client.\n *\n * @param storedGatorPermission - The stored gator permission to sanitize.\n * @returns The sanitized stored gator permission.\n */\n #sanitizeStoredGatorPermission(\n storedGatorPermission: StoredGatorPermission<\n Signer,\n PermissionTypesWithCustom\n >,\n ): StoredGatorPermissionSanitized<Signer, PermissionTypesWithCustom> {\n const { permissionResponse } = storedGatorPermission;\n const { rules, dependencyInfo, signer, ...rest } = permissionResponse;\n return {\n ...storedGatorPermission,\n permissionResponse: {\n ...rest,\n },\n };\n }\n\n /**\n * Categorizes stored gator permissions by type and chainId.\n *\n * @param storedGatorPermissions - An array of stored gator permissions.\n * @returns The gator permissions map.\n */\n #categorizePermissionsDataByTypeAndChainId(\n storedGatorPermissions:\n | StoredGatorPermission<Signer, PermissionTypesWithCustom>[]\n | null,\n ): GatorPermissionsMap {\n if (!storedGatorPermissions) {\n return defaultGatorPermissionsMap;\n }\n\n return storedGatorPermissions.reduce(\n (gatorPermissionsMap, storedGatorPermission) => {\n const { permissionResponse } = storedGatorPermission;\n const permissionType = permissionResponse.permission.type;\n const { chainId } = permissionResponse;\n\n const sanitizedStoredGatorPermission =\n this.#sanitizeStoredGatorPermission(storedGatorPermission);\n\n switch (permissionType) {\n case 'native-token-stream':\n case 'native-token-periodic':\n case 'erc20-token-stream':\n case 'erc20-token-periodic':\n if (!gatorPermissionsMap[permissionType][chainId]) {\n gatorPermissionsMap[permissionType][chainId] = [];\n }\n\n (\n gatorPermissionsMap[permissionType][\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n default:\n if (!gatorPermissionsMap.other[chainId]) {\n gatorPermissionsMap.other[chainId] = [];\n }\n\n (\n gatorPermissionsMap.other[\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n }\n\n return gatorPermissionsMap;\n },\n {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n } as GatorPermissionsMap,\n );\n }\n\n /**\n * Gets the gator permissions map from the state.\n *\n * @returns The gator permissions map.\n */\n get gatorPermissionsMap(): GatorPermissionsMap {\n return deserializeGatorPermissionsMap(\n this.state.gatorPermissionsMapSerialized,\n );\n }\n\n /**\n * Gets the gator permissions provider snap id that is used to fetch gator permissions.\n *\n * @returns The gator permissions provider snap id.\n */\n get permissionsProviderSnapId(): SnapId {\n return this.state.gatorPermissionsProviderSnapId;\n }\n\n /**\n * Enables gator permissions for the user.\n */\n public async enableGatorPermissions() {\n this.#setIsGatorPermissionsEnabled(true);\n }\n\n /**\n * Clears the gator permissions map and disables the feature.\n */\n public async disableGatorPermissions() {\n this.update((state) => {\n state.isGatorPermissionsEnabled = false;\n state.gatorPermissionsMapSerialized = serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n );\n });\n }\n\n /**\n * Gets the pending revocations list.\n *\n * @returns The pending revocations list.\n */\n get pendingRevocations(): { txId: string; permissionContext: Hex }[] {\n return this.state.pendingRevocations;\n }\n\n /**\n * Fetches the gator permissions from profile sync and updates the state.\n *\n * @param params - Optional parameters to pass to the snap's getGrantedPermissions method.\n * @returns A promise that resolves to the gator permissions map.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public async fetchAndUpdateGatorPermissions(\n params?: Json,\n ): Promise<GatorPermissionsMap> {\n try {\n this.#setIsFetchingGatorPermissions(true);\n this.#assertGatorPermissionsEnabled();\n\n const permissionsData =\n await this.#handleSnapRequestToGatorPermissionsProvider({\n snapId: this.state.gatorPermissionsProviderSnapId,\n params,\n });\n\n const gatorPermissionsMap =\n this.#categorizePermissionsDataByTypeAndChainId(permissionsData);\n\n this.update((state) => {\n state.gatorPermissionsMapSerialized =\n serializeGatorPermissionsMap(gatorPermissionsMap);\n });\n\n return gatorPermissionsMap;\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, signer, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.permissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n\n const permissionType = identifyPermissionByEnforcers({\n enforcers,\n contracts,\n });\n\n const { expiry, data } = getPermissionDataAndExpiry({\n contracts,\n caveats,\n permissionType,\n });\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n const snapRequest = {\n snapId: this.state.gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions({ isRevoked: false });\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to refresh permissions after transaction state change\n const refreshPermissions = (context: string) => {\n this.fetchAndUpdateGatorPermissions({ isRevoked: false }).catch(\n (error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n },\n );\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = () => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true) => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta) => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n });\n\n this.submitRevocation({ permissionContext })\n .catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n })\n .finally(() => refreshPermissions('transaction confirmed'));\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction failed');\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction dropped');\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n this.#assertGatorPermissionsEnabled();\n\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n permissionContext.toLowerCase(),\n );\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"GatorPermissionsController.d.cts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE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  dropped: undefined,
332
332
  timeoutId: undefined,
333
333
  };
334
+ // Helper to refresh permissions after transaction state change
335
+ const refreshPermissions = (context) => {
336
+ this.fetchAndUpdateGatorPermissions({ isRevoked: false }).catch((error) => {
337
+ controllerLog(`Failed to refresh permissions after ${context}`, {
338
+ txId,
339
+ permissionContext,
340
+ error,
341
+ });
342
+ });
343
+ };
334
344
  // Helper to unsubscribe from approval/rejection events after decision is made
335
345
  const cleanupApprovalHandlers = () => {
336
346
  if (handlers.approved) {
@@ -392,13 +402,15 @@ class GatorPermissionsController extends BaseController {
392
402
  txId,
393
403
  permissionContext,
394
404
  });
395
- this.submitRevocation({ permissionContext }).catch((error) => {
405
+ this.submitRevocation({ permissionContext })
406
+ .catch((error) => {
396
407
  controllerLog('Failed to submit revocation after transaction confirmed', {
397
408
  txId,
398
409
  permissionContext,
399
410
  error,
400
411
  });
401
- });
412
+ })
413
+ .finally(() => refreshPermissions('transaction confirmed'));
402
414
  cleanup(transactionMeta.id);
403
415
  }
404
416
  };
@@ -411,6 +423,7 @@ class GatorPermissionsController extends BaseController {
411
423
  error: payload.error,
412
424
  });
413
425
  cleanup(payload.transactionMeta.id);
426
+ refreshPermissions('transaction failed');
414
427
  }
415
428
  };
416
429
  // Handle dropped transaction - cleanup without submitting revocation
@@ -421,6 +434,7 @@ class GatorPermissionsController extends BaseController {
421
434
  permissionContext,
422
435
  });
423
436
  cleanup(payload.transactionMeta.id);
437
+ refreshPermissions('transaction dropped');
424
438
  }
425
439
  };
426
440
  // Subscribe to user approval/rejection events
@@ -1 +1 @@
1
- {"version":3,"file":"GatorPermissionsController.mjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAIvE,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAWpD,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,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AC,UAAU,CAAC,IAAI,CAAC;QAC1D,MAAM,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC;QAEvC,MAAM,8BAA8B,GAClC,uBAAA,IAAI,wGAA+B,MAAnC,IAAI,EAAgC,qBAAqB,CAAC,CAAC;QAE7D,QAAQ,cAAc,EAAE,CAAC;YACvB,KAAK,qBAAqB,CAAC;YAC3B,KAAK,uBAAuB,CAAC;YAC7B,KAAK,oBAAoB,CAAC;YAC1B,KAAK,sBAAsB;gBACzB,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;oBAClD,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBACpD,CAAC;gBAGC,mBAAmB,CAAC,cAAc,CAAC,CACjC,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;YACR;gBACE,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBACxC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBAC1C,CAAC;gBAGC,mBAAmB,CAAC,KAAK,CACvB,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;QACV,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,sBAAsB,EAAE,EAAE;QAC1B,KAAK,EAAE,EAAE;KACa,CACzB,CAAC;AACJ,CAAC;eAxQkB,0BAA0B","sourcesContent":["import type { Signer } from '@metamask/7715-permission-types';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\n\nimport type { DecodedPermission } from './decodePermission';\nimport {\n getPermissionDataAndExpiry,\n identifyPermissionByEnforcers,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsNotEnabledError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport { controllerLog } from './logger';\nimport type { StoredGatorPermissionSanitized } from './types';\nimport {\n GatorPermissionsSnapRpcMethod,\n type GatorPermissionsMap,\n type PermissionTypesWithCustom,\n type StoredGatorPermission,\n type DelegationDetails,\n type RevocationParams,\n type PendingRevocationParams,\n} from './types';\nimport {\n deserializeGatorPermissionsMap,\n serializeGatorPermissionsMap,\n} from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst defaultGatorPermissionsMap: GatorPermissionsMap = {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n};\n\n/**\n * Delegation framework version used to select the correct deployed enforcer\n * contract addresses from `@metamask/delegation-deployments`.\n */\nexport const DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === STATE ===\n\n/**\n * State shape for GatorPermissionsController\n */\nexport type GatorPermissionsControllerState = {\n /**\n * Flag that indicates if the gator permissions feature is enabled\n */\n isGatorPermissionsEnabled: boolean;\n\n /**\n * JSON serialized object containing gator permissions fetched from profile sync\n */\n gatorPermissionsMapSerialized: string;\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This is used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * The ID of the Snap of the gator permissions provider snap\n * Default value is `@metamask/gator-permissions-snap`\n */\n gatorPermissionsProviderSnapId: SnapId;\n\n /**\n * List of gator permission pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n isGatorPermissionsEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsMapSerialized: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsProviderSnapId: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Constructs the default {@link GatorPermissionsController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link GatorPermissionsController} state.\n */\nexport function getDefaultGatorPermissionsControllerState(): GatorPermissionsControllerState {\n return {\n isGatorPermissionsEnabled: false,\n gatorPermissionsMapSerialized: serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n ),\n isFetchingGatorPermissions: false,\n gatorPermissionsProviderSnapId: defaultGatorPermissionsProviderSnapId,\n pendingRevocations: [],\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * The action which can be used to fetch and update gator permissions.\n */\nexport type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {\n type: `${typeof controllerName}:fetchAndUpdateGatorPermissions`;\n handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];\n};\n\n/**\n * The action which can be used to enable gator permissions.\n */\nexport type GatorPermissionsControllerEnableGatorPermissionsAction = {\n type: `${typeof controllerName}:enableGatorPermissions`;\n handler: GatorPermissionsController['enableGatorPermissions'];\n};\n\n/**\n * The action which can be used to disable gator permissions.\n */\nexport type GatorPermissionsControllerDisableGatorPermissionsAction = {\n type: `${typeof controllerName}:disableGatorPermissions`;\n handler: GatorPermissionsController['disableGatorPermissions'];\n};\n\nexport type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction =\n {\n type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;\n handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];\n };\n\n/**\n * The action which can be used to submit a revocation.\n */\nexport type GatorPermissionsControllerSubmitRevocationAction = {\n type: `${typeof controllerName}:submitRevocation`;\n handler: GatorPermissionsController['submitRevocation'];\n};\n\n/**\n * The action which can be used to add a pending revocation.\n */\nexport type GatorPermissionsControllerAddPendingRevocationAction = {\n type: `${typeof controllerName}:addPendingRevocation`;\n handler: GatorPermissionsController['addPendingRevocation'];\n};\n\n/**\n * The action which can be used to submit a revocation directly without requiring\n * an on-chain transaction (for already-disabled delegations).\n */\nexport type GatorPermissionsControllerSubmitDirectRevocationAction = {\n type: `${typeof controllerName}:submitDirectRevocation`;\n handler: GatorPermissionsController['submitDirectRevocation'];\n};\n\n/**\n * The action which can be used to check if a permission context is pending revocation.\n */\nexport type GatorPermissionsControllerIsPendingRevocationAction = {\n type: `${typeof controllerName}:isPendingRevocation`;\n handler: GatorPermissionsController['isPendingRevocation'];\n};\n\n/**\n * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction\n | GatorPermissionsControllerEnableGatorPermissionsAction\n | GatorPermissionsControllerDisableGatorPermissionsAction\n | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapsController:handleRequest and SnapsController:has are allowed to be called\n * internally because they are used to fetch gator permissions from the Snap.\n */\ntype AllowedActions = HandleSnapRequest | HasSnap;\n\n/**\n * The event that {@link GatorPermissionsController} publishes when updating state.\n */\nexport type GatorPermissionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n GatorPermissionsControllerState\n >;\n\n/**\n * All events that {@link GatorPermissionsController} publishes, to be subscribed to\n * externally.\n */\nexport type GatorPermissionsControllerEvents =\n GatorPermissionsControllerStateChangeEvent;\n\n/**\n * Events that {@link GatorPermissionsController} is allowed to subscribe to internally.\n */\ntype AllowedEvents =\n | GatorPermissionsControllerStateChangeEvent\n | TransactionControllerTransactionApprovedEvent\n | TransactionControllerTransactionRejectedEvent\n | TransactionControllerTransactionConfirmedEvent\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionDroppedEvent;\n\n/**\n * Messenger type for the GatorPermissionsController.\n */\nexport type GatorPermissionsControllerMessenger = Messenger<\n typeof controllerName,\n GatorPermissionsControllerActions | AllowedActions,\n GatorPermissionsControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that manages gator permissions by reading from profile sync\n */\nexport default class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: {\n ...getDefaultGatorPermissionsControllerState(),\n ...state,\n isFetchingGatorPermissions: false,\n },\n });\n\n this.#registerMessageHandlers();\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean) {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #setIsGatorPermissionsEnabled(isGatorPermissionsEnabled: boolean) {\n this.update((state) => {\n state.isGatorPermissionsEnabled = isGatorPermissionsEnabled;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchAndUpdateGatorPermissions`,\n this.fetchAndUpdateGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:enableGatorPermissions`,\n this.enableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:disableGatorPermissions`,\n this.disableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:decodePermissionFromPermissionContextForOrigin`,\n this.decodePermissionFromPermissionContextForOrigin.bind(this),\n );\n\n const submitRevocationAction = `${controllerName}:submitRevocation`;\n\n this.messenger.registerActionHandler(\n submitRevocationAction,\n this.submitRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:addPendingRevocation`,\n this.addPendingRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitDirectRevocation`,\n this.submitDirectRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:isPendingRevocation`,\n this.isPendingRevocation.bind(this),\n );\n }\n\n /**\n * Asserts that the gator permissions are enabled.\n *\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n */\n #assertGatorPermissionsEnabled() {\n if (!this.state.isGatorPermissionsEnabled) {\n throw new GatorPermissionsNotEnabledError();\n }\n }\n\n /**\n * Forwards a Snap request to the SnapController.\n *\n * @param args - The request parameters.\n * @param args.snapId - The ID of the Snap of the gator permissions provider snap.\n * @param args.params - Optional parameters to pass to the snap method.\n * @returns A promise that resolves with the gator permissions.\n */\n async #handleSnapRequestToGatorPermissionsProvider({\n snapId,\n params,\n }: {\n snapId: SnapId;\n params?: Json;\n }): Promise<\n StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null\n > {\n try {\n const response = (await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n ...(params !== undefined && { params }),\n },\n },\n )) as StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null;\n\n return response;\n } catch (error) {\n controllerLog(\n 'Failed to handle snap request to gator permissions provider',\n error,\n );\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n cause: error as Error,\n });\n }\n }\n\n /**\n * Sanitizes a stored gator permission by removing the fields that are not expose to MetaMask client.\n *\n * @param storedGatorPermission - The stored gator permission to sanitize.\n * @returns The sanitized stored gator permission.\n */\n #sanitizeStoredGatorPermission(\n storedGatorPermission: StoredGatorPermission<\n Signer,\n PermissionTypesWithCustom\n >,\n ): StoredGatorPermissionSanitized<Signer, PermissionTypesWithCustom> {\n const { permissionResponse } = storedGatorPermission;\n const { rules, dependencyInfo, signer, ...rest } = permissionResponse;\n return {\n ...storedGatorPermission,\n permissionResponse: {\n ...rest,\n },\n };\n }\n\n /**\n * Categorizes stored gator permissions by type and chainId.\n *\n * @param storedGatorPermissions - An array of stored gator permissions.\n * @returns The gator permissions map.\n */\n #categorizePermissionsDataByTypeAndChainId(\n storedGatorPermissions:\n | StoredGatorPermission<Signer, PermissionTypesWithCustom>[]\n | null,\n ): GatorPermissionsMap {\n if (!storedGatorPermissions) {\n return defaultGatorPermissionsMap;\n }\n\n return storedGatorPermissions.reduce(\n (gatorPermissionsMap, storedGatorPermission) => {\n const { permissionResponse } = storedGatorPermission;\n const permissionType = permissionResponse.permission.type;\n const { chainId } = permissionResponse;\n\n const sanitizedStoredGatorPermission =\n this.#sanitizeStoredGatorPermission(storedGatorPermission);\n\n switch (permissionType) {\n case 'native-token-stream':\n case 'native-token-periodic':\n case 'erc20-token-stream':\n case 'erc20-token-periodic':\n if (!gatorPermissionsMap[permissionType][chainId]) {\n gatorPermissionsMap[permissionType][chainId] = [];\n }\n\n (\n gatorPermissionsMap[permissionType][\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n default:\n if (!gatorPermissionsMap.other[chainId]) {\n gatorPermissionsMap.other[chainId] = [];\n }\n\n (\n gatorPermissionsMap.other[\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n }\n\n return gatorPermissionsMap;\n },\n {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n } as GatorPermissionsMap,\n );\n }\n\n /**\n * Gets the gator permissions map from the state.\n *\n * @returns The gator permissions map.\n */\n get gatorPermissionsMap(): GatorPermissionsMap {\n return deserializeGatorPermissionsMap(\n this.state.gatorPermissionsMapSerialized,\n );\n }\n\n /**\n * Gets the gator permissions provider snap id that is used to fetch gator permissions.\n *\n * @returns The gator permissions provider snap id.\n */\n get permissionsProviderSnapId(): SnapId {\n return this.state.gatorPermissionsProviderSnapId;\n }\n\n /**\n * Enables gator permissions for the user.\n */\n public async enableGatorPermissions() {\n this.#setIsGatorPermissionsEnabled(true);\n }\n\n /**\n * Clears the gator permissions map and disables the feature.\n */\n public async disableGatorPermissions() {\n this.update((state) => {\n state.isGatorPermissionsEnabled = false;\n state.gatorPermissionsMapSerialized = serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n );\n });\n }\n\n /**\n * Gets the pending revocations list.\n *\n * @returns The pending revocations list.\n */\n get pendingRevocations(): { txId: string; permissionContext: Hex }[] {\n return this.state.pendingRevocations;\n }\n\n /**\n * Fetches the gator permissions from profile sync and updates the state.\n *\n * @param params - Optional parameters to pass to the snap's getGrantedPermissions method.\n * @returns A promise that resolves to the gator permissions map.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public async fetchAndUpdateGatorPermissions(\n params?: Json,\n ): Promise<GatorPermissionsMap> {\n try {\n this.#setIsFetchingGatorPermissions(true);\n this.#assertGatorPermissionsEnabled();\n\n const permissionsData =\n await this.#handleSnapRequestToGatorPermissionsProvider({\n snapId: this.state.gatorPermissionsProviderSnapId,\n params,\n });\n\n const gatorPermissionsMap =\n this.#categorizePermissionsDataByTypeAndChainId(permissionsData);\n\n this.update((state) => {\n state.gatorPermissionsMapSerialized =\n serializeGatorPermissionsMap(gatorPermissionsMap);\n });\n\n return gatorPermissionsMap;\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, signer, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.permissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n\n const permissionType = identifyPermissionByEnforcers({\n enforcers,\n contracts,\n });\n\n const { expiry, data } = getPermissionDataAndExpiry({\n contracts,\n caveats,\n permissionType,\n });\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n const snapRequest = {\n snapId: this.state.gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions({ isRevoked: false });\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = () => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true) => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta) => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n });\n\n this.submitRevocation({ permissionContext }).catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n });\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n this.#assertGatorPermissionsEnabled();\n\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n permissionContext.toLowerCase(),\n );\n }\n}\n"]}
1
+ {"version":3,"file":"GatorPermissionsController.mjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAIvE,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAWpD,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC7B,qCAA2B;AAC5B,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,6BAA6B,EAC7B,qBAAqB,EACrB,uBAAuB,EACxB,qBAAiB;AAClB,OAAO,EAAE,aAAa,EAAE,qBAAiB;AAEzC,OAAO,EACL,6BAA6B,EAO9B,oBAAgB;AACjB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC7B,oBAAgB;AAEjB,kBAAkB;AAElB,iCAAiC;AACjC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,2DAA2D;AAC3D,MAAM,qCAAqC,GACzC,sCAAgD,CAAC;AAEnD,MAAM,0BAA0B,GAAwB;IACtD,qBAAqB,EAAE,EAAE;IACzB,uBAAuB,EAAE,EAAE;IAC3B,oBAAoB,EAAE,EAAE;IACxB,sBAAsB,EAAE,EAAE;IAC1B,KAAK,EAAE,EAAE;CACV,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAEpD;;;GAGG;AACH,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtD,MAAM,kBAAkB,GAAG,mBAAmB,CAAC,4BAA4B,CAAC,CAAC;AAuC7E,MA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AK,sBAAsB;gBACzB,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;oBAClD,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBACpD,CAAC;gBAGC,mBAAmB,CAAC,cAAc,CAAC,CACjC,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;YACR;gBACE,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBACxC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBAC1C,CAAC;gBAGC,mBAAmB,CAAC,KAAK,CACvB,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;QACV,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,sBAAsB,EAAE,EAAE;QAC1B,KAAK,EAAE,EAAE;KACa,CACzB,CAAC;AACJ,CAAC;eAxQkB,0BAA0B","sourcesContent":["import type { Signer } from '@metamask/7715-permission-types';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\n\nimport type { DecodedPermission } from './decodePermission';\nimport {\n getPermissionDataAndExpiry,\n identifyPermissionByEnforcers,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsNotEnabledError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport { controllerLog } from './logger';\nimport type { StoredGatorPermissionSanitized } from './types';\nimport {\n GatorPermissionsSnapRpcMethod,\n type GatorPermissionsMap,\n type PermissionTypesWithCustom,\n type StoredGatorPermission,\n type DelegationDetails,\n type RevocationParams,\n type PendingRevocationParams,\n} from './types';\nimport {\n deserializeGatorPermissionsMap,\n serializeGatorPermissionsMap,\n} from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst defaultGatorPermissionsMap: GatorPermissionsMap = {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n};\n\n/**\n * Delegation framework version used to select the correct deployed enforcer\n * contract addresses from `@metamask/delegation-deployments`.\n */\nexport const DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === STATE ===\n\n/**\n * State shape for GatorPermissionsController\n */\nexport type GatorPermissionsControllerState = {\n /**\n * Flag that indicates if the gator permissions feature is enabled\n */\n isGatorPermissionsEnabled: boolean;\n\n /**\n * JSON serialized object containing gator permissions fetched from profile sync\n */\n gatorPermissionsMapSerialized: string;\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This is used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * The ID of the Snap of the gator permissions provider snap\n * Default value is `@metamask/gator-permissions-snap`\n */\n gatorPermissionsProviderSnapId: SnapId;\n\n /**\n * List of gator permission pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n isGatorPermissionsEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsMapSerialized: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsProviderSnapId: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Constructs the default {@link GatorPermissionsController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link GatorPermissionsController} state.\n */\nexport function getDefaultGatorPermissionsControllerState(): GatorPermissionsControllerState {\n return {\n isGatorPermissionsEnabled: false,\n gatorPermissionsMapSerialized: serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n ),\n isFetchingGatorPermissions: false,\n gatorPermissionsProviderSnapId: defaultGatorPermissionsProviderSnapId,\n pendingRevocations: [],\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * The action which can be used to fetch and update gator permissions.\n */\nexport type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {\n type: `${typeof controllerName}:fetchAndUpdateGatorPermissions`;\n handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];\n};\n\n/**\n * The action which can be used to enable gator permissions.\n */\nexport type GatorPermissionsControllerEnableGatorPermissionsAction = {\n type: `${typeof controllerName}:enableGatorPermissions`;\n handler: GatorPermissionsController['enableGatorPermissions'];\n};\n\n/**\n * The action which can be used to disable gator permissions.\n */\nexport type GatorPermissionsControllerDisableGatorPermissionsAction = {\n type: `${typeof controllerName}:disableGatorPermissions`;\n handler: GatorPermissionsController['disableGatorPermissions'];\n};\n\nexport type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction =\n {\n type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;\n handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];\n };\n\n/**\n * The action which can be used to submit a revocation.\n */\nexport type GatorPermissionsControllerSubmitRevocationAction = {\n type: `${typeof controllerName}:submitRevocation`;\n handler: GatorPermissionsController['submitRevocation'];\n};\n\n/**\n * The action which can be used to add a pending revocation.\n */\nexport type GatorPermissionsControllerAddPendingRevocationAction = {\n type: `${typeof controllerName}:addPendingRevocation`;\n handler: GatorPermissionsController['addPendingRevocation'];\n};\n\n/**\n * The action which can be used to submit a revocation directly without requiring\n * an on-chain transaction (for already-disabled delegations).\n */\nexport type GatorPermissionsControllerSubmitDirectRevocationAction = {\n type: `${typeof controllerName}:submitDirectRevocation`;\n handler: GatorPermissionsController['submitDirectRevocation'];\n};\n\n/**\n * The action which can be used to check if a permission context is pending revocation.\n */\nexport type GatorPermissionsControllerIsPendingRevocationAction = {\n type: `${typeof controllerName}:isPendingRevocation`;\n handler: GatorPermissionsController['isPendingRevocation'];\n};\n\n/**\n * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction\n | GatorPermissionsControllerEnableGatorPermissionsAction\n | GatorPermissionsControllerDisableGatorPermissionsAction\n | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapsController:handleRequest and SnapsController:has are allowed to be called\n * internally because they are used to fetch gator permissions from the Snap.\n */\ntype AllowedActions = HandleSnapRequest | HasSnap;\n\n/**\n * The event that {@link GatorPermissionsController} publishes when updating state.\n */\nexport type GatorPermissionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n GatorPermissionsControllerState\n >;\n\n/**\n * All events that {@link GatorPermissionsController} publishes, to be subscribed to\n * externally.\n */\nexport type GatorPermissionsControllerEvents =\n GatorPermissionsControllerStateChangeEvent;\n\n/**\n * Events that {@link GatorPermissionsController} is allowed to subscribe to internally.\n */\ntype AllowedEvents =\n | GatorPermissionsControllerStateChangeEvent\n | TransactionControllerTransactionApprovedEvent\n | TransactionControllerTransactionRejectedEvent\n | TransactionControllerTransactionConfirmedEvent\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionDroppedEvent;\n\n/**\n * Messenger type for the GatorPermissionsController.\n */\nexport type GatorPermissionsControllerMessenger = Messenger<\n typeof controllerName,\n GatorPermissionsControllerActions | AllowedActions,\n GatorPermissionsControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that manages gator permissions by reading from profile sync\n */\nexport default class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: {\n ...getDefaultGatorPermissionsControllerState(),\n ...state,\n isFetchingGatorPermissions: false,\n },\n });\n\n this.#registerMessageHandlers();\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean) {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #setIsGatorPermissionsEnabled(isGatorPermissionsEnabled: boolean) {\n this.update((state) => {\n state.isGatorPermissionsEnabled = isGatorPermissionsEnabled;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchAndUpdateGatorPermissions`,\n this.fetchAndUpdateGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:enableGatorPermissions`,\n this.enableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:disableGatorPermissions`,\n this.disableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:decodePermissionFromPermissionContextForOrigin`,\n this.decodePermissionFromPermissionContextForOrigin.bind(this),\n );\n\n const submitRevocationAction = `${controllerName}:submitRevocation`;\n\n this.messenger.registerActionHandler(\n submitRevocationAction,\n this.submitRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:addPendingRevocation`,\n this.addPendingRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitDirectRevocation`,\n this.submitDirectRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:isPendingRevocation`,\n this.isPendingRevocation.bind(this),\n );\n }\n\n /**\n * Asserts that the gator permissions are enabled.\n *\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n */\n #assertGatorPermissionsEnabled() {\n if (!this.state.isGatorPermissionsEnabled) {\n throw new GatorPermissionsNotEnabledError();\n }\n }\n\n /**\n * Forwards a Snap request to the SnapController.\n *\n * @param args - The request parameters.\n * @param args.snapId - The ID of the Snap of the gator permissions provider snap.\n * @param args.params - Optional parameters to pass to the snap method.\n * @returns A promise that resolves with the gator permissions.\n */\n async #handleSnapRequestToGatorPermissionsProvider({\n snapId,\n params,\n }: {\n snapId: SnapId;\n params?: Json;\n }): Promise<\n StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null\n > {\n try {\n const response = (await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n ...(params !== undefined && { params }),\n },\n },\n )) as StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null;\n\n return response;\n } catch (error) {\n controllerLog(\n 'Failed to handle snap request to gator permissions provider',\n error,\n );\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n cause: error as Error,\n });\n }\n }\n\n /**\n * Sanitizes a stored gator permission by removing the fields that are not expose to MetaMask client.\n *\n * @param storedGatorPermission - The stored gator permission to sanitize.\n * @returns The sanitized stored gator permission.\n */\n #sanitizeStoredGatorPermission(\n storedGatorPermission: StoredGatorPermission<\n Signer,\n PermissionTypesWithCustom\n >,\n ): StoredGatorPermissionSanitized<Signer, PermissionTypesWithCustom> {\n const { permissionResponse } = storedGatorPermission;\n const { rules, dependencyInfo, signer, ...rest } = permissionResponse;\n return {\n ...storedGatorPermission,\n permissionResponse: {\n ...rest,\n },\n };\n }\n\n /**\n * Categorizes stored gator permissions by type and chainId.\n *\n * @param storedGatorPermissions - An array of stored gator permissions.\n * @returns The gator permissions map.\n */\n #categorizePermissionsDataByTypeAndChainId(\n storedGatorPermissions:\n | StoredGatorPermission<Signer, PermissionTypesWithCustom>[]\n | null,\n ): GatorPermissionsMap {\n if (!storedGatorPermissions) {\n return defaultGatorPermissionsMap;\n }\n\n return storedGatorPermissions.reduce(\n (gatorPermissionsMap, storedGatorPermission) => {\n const { permissionResponse } = storedGatorPermission;\n const permissionType = permissionResponse.permission.type;\n const { chainId } = permissionResponse;\n\n const sanitizedStoredGatorPermission =\n this.#sanitizeStoredGatorPermission(storedGatorPermission);\n\n switch (permissionType) {\n case 'native-token-stream':\n case 'native-token-periodic':\n case 'erc20-token-stream':\n case 'erc20-token-periodic':\n if (!gatorPermissionsMap[permissionType][chainId]) {\n gatorPermissionsMap[permissionType][chainId] = [];\n }\n\n (\n gatorPermissionsMap[permissionType][\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n default:\n if (!gatorPermissionsMap.other[chainId]) {\n gatorPermissionsMap.other[chainId] = [];\n }\n\n (\n gatorPermissionsMap.other[\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n }\n\n return gatorPermissionsMap;\n },\n {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n } as GatorPermissionsMap,\n );\n }\n\n /**\n * Gets the gator permissions map from the state.\n *\n * @returns The gator permissions map.\n */\n get gatorPermissionsMap(): GatorPermissionsMap {\n return deserializeGatorPermissionsMap(\n this.state.gatorPermissionsMapSerialized,\n );\n }\n\n /**\n * Gets the gator permissions provider snap id that is used to fetch gator permissions.\n *\n * @returns The gator permissions provider snap id.\n */\n get permissionsProviderSnapId(): SnapId {\n return this.state.gatorPermissionsProviderSnapId;\n }\n\n /**\n * Enables gator permissions for the user.\n */\n public async enableGatorPermissions() {\n this.#setIsGatorPermissionsEnabled(true);\n }\n\n /**\n * Clears the gator permissions map and disables the feature.\n */\n public async disableGatorPermissions() {\n this.update((state) => {\n state.isGatorPermissionsEnabled = false;\n state.gatorPermissionsMapSerialized = serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n );\n });\n }\n\n /**\n * Gets the pending revocations list.\n *\n * @returns The pending revocations list.\n */\n get pendingRevocations(): { txId: string; permissionContext: Hex }[] {\n return this.state.pendingRevocations;\n }\n\n /**\n * Fetches the gator permissions from profile sync and updates the state.\n *\n * @param params - Optional parameters to pass to the snap's getGrantedPermissions method.\n * @returns A promise that resolves to the gator permissions map.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public async fetchAndUpdateGatorPermissions(\n params?: Json,\n ): Promise<GatorPermissionsMap> {\n try {\n this.#setIsFetchingGatorPermissions(true);\n this.#assertGatorPermissionsEnabled();\n\n const permissionsData =\n await this.#handleSnapRequestToGatorPermissionsProvider({\n snapId: this.state.gatorPermissionsProviderSnapId,\n params,\n });\n\n const gatorPermissionsMap =\n this.#categorizePermissionsDataByTypeAndChainId(permissionsData);\n\n this.update((state) => {\n state.gatorPermissionsMapSerialized =\n serializeGatorPermissionsMap(gatorPermissionsMap);\n });\n\n return gatorPermissionsMap;\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, signer, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.permissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n\n const permissionType = identifyPermissionByEnforcers({\n enforcers,\n contracts,\n });\n\n const { expiry, data } = getPermissionDataAndExpiry({\n contracts,\n caveats,\n permissionType,\n });\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n const snapRequest = {\n snapId: this.state.gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions({ isRevoked: false });\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to refresh permissions after transaction state change\n const refreshPermissions = (context: string) => {\n this.fetchAndUpdateGatorPermissions({ isRevoked: false }).catch(\n (error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n },\n );\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = () => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true) => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta) => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n });\n\n this.submitRevocation({ permissionContext })\n .catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n })\n .finally(() => refreshPermissions('transaction confirmed'));\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction failed');\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction dropped');\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n this.#assertGatorPermissionsEnabled();\n\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n permissionContext.toLowerCase(),\n );\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/gator-permissions-controller",
3
- "version": "0.6.0-preview-2b2b3f4d",
3
+ "version": "0.7.0-preview-be27197a",
4
4
  "description": "Controller for managing gator permissions with profile sync integration",
5
5
  "keywords": [
6
6
  "MetaMask",