@metamask-previews/gator-permissions-controller 3.0.1-preview-debd7ebcd → 4.0.0-preview-9c8c0a0

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
@@ -9,8 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
9
9
 
10
10
  ### Changed
11
11
 
12
+ - Bump `@metamask/transaction-controller` from `^64.2.0` to `^64.3.0` ([#8482](https://github.com/MetaMask/core/pull/8482))
13
+
14
+ ## [4.0.0]
15
+
16
+ ### Changed
17
+
18
+ - **BREAKING:** Add `status` to `PermissionInfoWithMetadata` type, resolved from onchain data ([#8445](https://github.com/MetaMask/core/pull/8445))
12
19
  - Bump `@metamask/messenger` from `^1.0.0` to `^1.1.1` ([#8364](https://github.com/MetaMask/core/pull/8364), [#8373](https://github.com/MetaMask/core/pull/8373))
13
20
  - Bump `@metamask/transaction-controller` from `^64.0.0` to `^64.2.0` ([#8432](https://github.com/MetaMask/core/pull/8432), [#8447](https://github.com/MetaMask/core/pull/8447))
21
+ - Bump `@metamask/base-controller` from `^9.0.1` to `^9.1.0` ([#8457](https://github.com/MetaMask/core/pull/8457))
14
22
 
15
23
  ## [3.0.1]
16
24
 
@@ -68,7 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
68
76
  - Replaces `gatorPermissionsMapSerialized` with `grantedPermissions` property in internal state, replaces related types, and utility functions
69
77
  - `fetchAndUpdateGatorPermissions()` no longer accepts parameters and resolves to `void`
70
78
  - `getPendingRevocations` / `pendingRevocations` getter replaced by `isPendingRevocation(permissionContext)`; list on `state.pendingRevocations`
71
- - Bump `@metamask/transaction-controller` from `^62.11.0` to `^62.17.0` ([#7775](https://github.com/MetaMask/core/pull/7775), [#7802](https://github.com/MetaMask/core/pull/7802), [#7832](https://github.com/MetaMask/core/pull/7832), [#7854](https://github.com/MetaMask/core/pull/7854), [#7872](https://github.com/MetaMask/core/pull/7872)), ([#7897](https://github.com/MetaMask/core/pull/7897))
79
+ - Bump `@metamask/transaction-controller` from `^62.11.0` to `^62.17.0`, ([#7775](https://github.com/MetaMask/core/pull/7775), [#7802](https://github.com/MetaMask/core/pull/7802), [#7832](https://github.com/MetaMask/core/pull/7832), [#7854](https://github.com/MetaMask/core/pull/7854), [#7872](https://github.com/MetaMask/core/pull/7872), [#7897](https://github.com/MetaMask/core/pull/7897))
72
80
 
73
81
  ## [1.1.2]
74
82
 
@@ -213,7 +221,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
213
221
 
214
222
  - Initial release ([#6033](https://github.com/MetaMask/core/pull/6033))
215
223
 
216
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@3.0.1...HEAD
224
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@4.0.0...HEAD
225
+ [4.0.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@3.0.1...@metamask/gator-permissions-controller@4.0.0
217
226
  [3.0.1]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@3.0.0...@metamask/gator-permissions-controller@3.0.1
218
227
  [3.0.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@2.2.0...@metamask/gator-permissions-controller@3.0.0
219
228
  [2.2.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@2.1.1...@metamask/gator-permissions-controller@2.2.0
@@ -10,7 +10,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
10
10
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
11
11
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
12
12
  };
13
- var _GatorPermissionsController_instances, _GatorPermissionsController_supportedPermissionTypes, _GatorPermissionsController_gatorPermissionsProviderSnapId, _GatorPermissionsController_maxSyncIntervalMs, _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext, _GatorPermissionsController_storedPermissionToPermissionInfo, _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata;
13
+ var _GatorPermissionsController_instances, _GatorPermissionsController_supportedPermissionTypes, _GatorPermissionsController_gatorPermissionsProviderSnapId, _GatorPermissionsController_maxSyncIntervalMs, _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext, _GatorPermissionsController_buildPreviousStatusByContext, _GatorPermissionsController_getProviderForChainId, _GatorPermissionsController_updateGrantedPermissionsStatus, _GatorPermissionsController_storedPermissionToPermissionInfo, _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.GatorPermissionsController = void 0;
16
16
  const base_controller_1 = require("@metamask/base-controller");
@@ -21,6 +21,7 @@ const constants_1 = require("./constants.cjs");
21
21
  const decodePermission_1 = require("./decodePermission/index.cjs");
22
22
  const errors_1 = require("./errors.cjs");
23
23
  const logger_1 = require("./logger.cjs");
24
+ const permissionOnChainStatus_1 = require("./permissionOnChainStatus.cjs");
24
25
  const types_1 = require("./types.cjs");
25
26
  const utils_1 = require("./utils.cjs");
26
27
  // === GENERAL ===
@@ -168,6 +169,10 @@ class GatorPermissionsController extends base_controller_1.BaseController {
168
169
  state.grantedPermissions = grantedPermissions;
169
170
  state.lastSyncedTimestamp = Date.now();
170
171
  });
172
+ const grantedPermissionsWithStatus = await __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_updateGrantedPermissionsStatus).call(this, grantedPermissions);
173
+ this.update((state) => {
174
+ state.grantedPermissions = grantedPermissionsWithStatus;
175
+ });
171
176
  }
172
177
  catch (error) {
173
178
  (0, logger_1.controllerLog)('Failed to fetch gator permissions', error);
@@ -550,18 +555,38 @@ _GatorPermissionsController_supportedPermissionTypes = new WeakMap(), _GatorPerm
550
555
  state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext.toLowerCase() !==
551
556
  permissionContext.toLowerCase());
552
557
  });
553
- }, _GatorPermissionsController_storedPermissionToPermissionInfo = function _GatorPermissionsController_storedPermissionToPermissionInfo(storedGatorPermission) {
558
+ }, _GatorPermissionsController_buildPreviousStatusByContext = function _GatorPermissionsController_buildPreviousStatusByContext() {
559
+ const map = new Map();
560
+ for (const prev of this.state.grantedPermissions) {
561
+ map.set(prev.permissionResponse.context.toLowerCase(), prev.status ?? 'Active');
562
+ }
563
+ return map;
564
+ }, _GatorPermissionsController_getProviderForChainId = async function _GatorPermissionsController_getProviderForChainId(chainId) {
565
+ const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', chainId);
566
+ const { provider } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
567
+ return provider;
568
+ }, _GatorPermissionsController_updateGrantedPermissionsStatus = async function _GatorPermissionsController_updateGrantedPermissionsStatus(grantedPermissions) {
569
+ return (0, permissionOnChainStatus_1.updateGrantedPermissionsStatus)(grantedPermissions, {
570
+ getProviderForChainId: (chainId) => __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_getProviderForChainId).call(this, chainId),
571
+ contractsByChainId,
572
+ });
573
+ }, _GatorPermissionsController_storedPermissionToPermissionInfo = function _GatorPermissionsController_storedPermissionToPermissionInfo(storedGatorPermission, status) {
554
574
  const { permissionResponse: fullPermissionResponse } = storedGatorPermission;
555
575
  const { dependencies: _dependencies, to: _to, ...permissionResponse } = fullPermissionResponse;
556
576
  return {
557
577
  ...storedGatorPermission,
558
578
  permissionResponse,
579
+ status,
559
580
  };
560
581
  }, _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata = function _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata(storedGatorPermissions) {
561
582
  if (!storedGatorPermissions) {
562
583
  return [];
563
584
  }
564
- return storedGatorPermissions.map((storedPermission) => __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_storedPermissionToPermissionInfo).call(this, storedPermission));
585
+ const previousStatusByContext = __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_buildPreviousStatusByContext).call(this);
586
+ return storedGatorPermissions.map((storedPermission) => {
587
+ const previousStatus = previousStatusByContext.get(storedPermission.permissionResponse.context.toLowerCase());
588
+ return __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_storedPermissionToPermissionInfo).call(this, storedPermission, previousStatus ?? 'Active');
589
+ });
565
590
  };
566
591
  exports.default = GatorPermissionsController;
567
592
  //# sourceMappingURL=GatorPermissionsController.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"GatorPermissionsController.cjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAC3D,6EAAuE;AAOvE,uDAAoD;AACpD,6EAAqE;AAUrE,+CAA2D;AAE3D,mEAI4B;AAC5B,yCAKkB;AAElB,yCAAyC;AACzC,uCAAwD;AASxD,uCAAyC;AAEzC,kBAAkB;AAElB,iCAAiC;AACjC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,MAAM,yBAAyB,GAAG;IAChC,gCAAgC;IAChC,YAAY;IACZ,gDAAgD;IAChD,kBAAkB;IAClB,sBAAsB;IACtB,wBAAwB;IACxB,qBAAqB;CACb,CAAC;AAEX,2DAA2D;AAC3D,MAAM,qCAAqC,GACzC,sCAAgD,CAAC;AAEnD,MAAM,4BAA4B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,0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,GAAG,kBAAkB,EACtB,GAAG,sBAAsB,CAAC;IAE3B,OAAO;QACL,GAAG,qBAAqB;QACxB,kBAAkB;KACnB,CAAC;AACJ,CAAC,iKASC,sBAAsD;IAEtD,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,sBAAsB,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,CACrD,uBAAA,IAAI,2GAAkC,MAAtC,IAAI,EAAmC,gBAAgB,CAAC,CACzD,CAAC;AACJ,CAAC;AAoiBH,kBAAe,0BAA0B,CAAC","sourcesContent":["import 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 {\n SnapControllerHandleRequestAction,\n SnapControllerHasSnapAction,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { DELEGATION_FRAMEWORK_VERSION } from './constants';\nimport type { DecodedPermission } from './decodePermission';\nimport {\n createPermissionRulesForContracts,\n findRuleWithMatchingCaveatAddresses,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport type { GatorPermissionsControllerMethodActions } from './GatorPermissionsController-method-action-types';\nimport { controllerLog } from './logger';\nimport { GatorPermissionsSnapRpcMethod } from './types';\nimport type {\n StoredGatorPermission,\n PermissionInfoWithMetadata,\n SupportedPermissionType,\n DelegationDetails,\n RevocationParams,\n PendingRevocationParams,\n} from './types';\nimport { executeSnapRpc } from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchAndUpdateGatorPermissions',\n 'initialize',\n 'decodePermissionFromPermissionContextForOrigin',\n 'submitRevocation',\n 'addPendingRevocation',\n 'submitDirectRevocation',\n 'isPendingRevocation',\n] as const;\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst DEFAULT_MAX_SYNC_INTERVAL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\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// === CONFIG ===\n\n/**\n * Configuration for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerConfig = {\n /**\n * Permission types the controller supports (e.g. 'native-token-stream', 'erc20-token-periodic').\n */\n supportedPermissionTypes: SupportedPermissionType[];\n /**\n * Optional ID of the gator permissions provider Snap. Defaults to npm:@metamask/gator-permissions-snap.\n */\n gatorPermissionsProviderSnapId?: SnapId;\n /**\n * Optional maximum age of cached permissions (ms) before {@link GatorPermissionsController.initialize}\n * triggers a sync. Defaults to 30 days.\n */\n maxSyncIntervalMs?: number;\n};\n\n// === STATE ===\n\n/**\n * State shape for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerState = {\n /**\n * List of granted permissions with metadata (siteOrigin, revocationMetadata).\n */\n grantedPermissions: PermissionInfoWithMetadata[];\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This can be used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * List of gator permissions pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n\n /**\n * Timestamp (ms) of the last successful sync of gator permissions from profile sync.\n * -1 indicates that a sync has never completed successfully.\n */\n lastSyncedTimestamp: number;\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n grantedPermissions: {\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: true,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSyncedTimestamp: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Creates initial controller state, merging defaults with optional partial state.\n * Internal use only (e.g. constructor, tests).\n *\n * @param state - Optional partial state to merge with defaults.\n * @returns Complete {@link GatorPermissionsController} state.\n */\nfunction createGatorPermissionsControllerState(\n state?: Partial<GatorPermissionsControllerState>,\n): GatorPermissionsControllerState {\n return {\n grantedPermissions: [],\n pendingRevocations: [],\n lastSyncedTimestamp: -1,\n ...state,\n // isFetchingGatorPermissions is _always_ false when the controller is created\n isFetchingGatorPermissions: false,\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 * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerMethodActions;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapController:handleRequest and SnapController:hasSnap are allowed to be\n * called internally because they are used to fetch gator permissions from the\n * Snap.\n */\ntype AllowedActions =\n | SnapControllerHandleRequestAction\n | SnapControllerHasSnapAction;\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 the gator permissions provider Snap.\n */\nexport class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n readonly #supportedPermissionTypes: readonly SupportedPermissionType[];\n\n /**\n * The Snap ID of the gator permissions provider.\n *\n * @returns The Snap ID of the gator permissions provider.\n */\n get gatorPermissionsProviderSnapId(): SnapId {\n return this.#gatorPermissionsProviderSnapId;\n }\n\n readonly #gatorPermissionsProviderSnapId: SnapId;\n\n readonly #maxSyncIntervalMs: number;\n\n /**\n * When a sync is in progress, holds the promise for that sync so concurrent\n * callers receive the same promise. Cleared when the sync completes.\n */\n #fetchAndUpdateGatorPermissionsPromise: Promise<void> | null = null;\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 other controllers.\n * @param args.config - Configuration (supported permission types and optional Snap id).\n * @param args.state - Optional partial state to merge with defaults.\n */\n constructor({\n messenger,\n config,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n config: GatorPermissionsControllerConfig;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n const initialState = createGatorPermissionsControllerState(state);\n\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: initialState,\n });\n\n this.#supportedPermissionTypes = config.supportedPermissionTypes;\n this.#gatorPermissionsProviderSnapId =\n config.gatorPermissionsProviderSnapId ??\n defaultGatorPermissionsProviderSnapId;\n this.#maxSyncIntervalMs =\n config.maxSyncIntervalMs ?? DEFAULT_MAX_SYNC_INTERVAL_MS;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Supported permission types this controller was configured with.\n *\n * @returns The supported permission types.\n */\n get supportedPermissionTypes(): readonly SupportedPermissionType[] {\n return this.#supportedPermissionTypes;\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean): void {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex): void {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(\n permissionContext: Hex,\n ): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n /**\n * Converts a stored gator permission to permission info with metadata.\n * Strips internal fields (dependencies, to) from the permission response.\n *\n * @param storedGatorPermission - The stored gator permission from the Snap.\n * @returns Permission info with metadata for state/UI.\n */\n #storedPermissionToPermissionInfo(\n storedGatorPermission: StoredGatorPermission,\n ): PermissionInfoWithMetadata {\n const { permissionResponse: fullPermissionResponse } =\n storedGatorPermission;\n const {\n dependencies: _dependencies,\n to: _to,\n ...permissionResponse\n } = fullPermissionResponse;\n\n return {\n ...storedGatorPermission,\n permissionResponse,\n };\n }\n\n /**\n * Converts stored gator permissions from the Snap into permission info with metadata.\n *\n * @param storedGatorPermissions - Stored gator permissions returned by the Snap, or null.\n * @returns Array of permission info with metadata for state.\n */\n #storedPermissionsToPermissionInfoWithMetadata(\n storedGatorPermissions: StoredGatorPermission[] | null,\n ): PermissionInfoWithMetadata[] {\n if (!storedGatorPermissions) {\n return [];\n }\n\n return storedGatorPermissions.map((storedPermission) =>\n this.#storedPermissionToPermissionInfo(storedPermission),\n );\n }\n\n /**\n * Fetches granted permissions from the gator permissions provider Snap and updates state.\n * If a sync is already in progress, returns the same promise. After the sync completes,\n * the next call will perform a new sync.\n *\n * @returns A promise that resolves when the sync completes. All data is available via the controller's state.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public fetchAndUpdateGatorPermissions(): Promise<void> {\n if (this.#fetchAndUpdateGatorPermissionsPromise !== null) {\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n const performFetchAndUpdate = async (): Promise<void> => {\n try {\n this.#setIsFetchingGatorPermissions(true);\n\n // Only ever fetch non-revoked permissions. Revoked permissions may be\n // left in storage by the gator permissions snap, but we don't need to\n // fetch them.\n const params = { isRevoked: false };\n\n const permissionsData = await executeSnapRpc<\n StoredGatorPermission[] | null\n >({\n messenger: this.messenger,\n snapId: this.#gatorPermissionsProviderSnapId,\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n params,\n });\n\n const grantedPermissions =\n this.#storedPermissionsToPermissionInfoWithMetadata(permissionsData);\n\n this.update((state) => {\n state.grantedPermissions = grantedPermissions;\n state.lastSyncedTimestamp = Date.now();\n });\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 this.#fetchAndUpdateGatorPermissionsPromise = null;\n }\n };\n\n this.#fetchAndUpdateGatorPermissionsPromise = performFetchAndUpdate();\n\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n /**\n * Initializes the controller. Call once after construction to ensure the\n * controller is ready for use.\n *\n * @returns A promise that resolves when initialization is complete.\n */\n public async initialize(): Promise<void> {\n const currentTime = Date.now();\n const millisecondsSinceLastSync =\n currentTime - this.state.lastSyncedTimestamp;\n\n // Sync only when we have no data or data is stale, to avoid excessive startup\n // queries while still avoiding showing stale data while a refresh runs.\n if (\n this.state.lastSyncedTimestamp === -1 ||\n millisecondsSinceLastSync > this.#maxSyncIntervalMs\n ) {\n await this.fetchAndUpdateGatorPermissions();\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, to, 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.#gatorPermissionsProviderSnapId) {\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 const permissionRules = createPermissionRulesForContracts(contracts);\n\n // find the single rule where the specified enforcers contain all the required enforcers\n // and no forbidden enforcers\n const matchingRule = findRuleWithMatchingCaveatAddresses({\n enforcers,\n permissionRules,\n });\n\n // validate the terms of each caveat against the matching rule, returning the decoded result\n // this happens in a single function, as decoding is an inherent part of validation.\n const decodeResult = matchingRule.validateAndDecodePermission(caveats);\n\n if (!decodeResult.isValid) {\n throw new PermissionDecodingError({\n cause: decodeResult.error,\n });\n }\n\n const { expiry, data } = decodeResult;\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType: matchingRule.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 {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 const snapRequest = {\n snapId: this.#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();\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 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): void => {\n this.fetchAndUpdateGatorPermissions().catch((error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n });\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = (): void => {\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): void => {\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): void => {\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): void => {\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): void => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n txHash: transactionMeta.hash,\n });\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n controllerLog('Transaction not confirmed, skipping revocation', {\n txId,\n permissionContext,\n status: transactionMeta.status,\n });\n cleanup(transactionMeta.id);\n refreshPermissions('transaction not confirmed');\n return;\n }\n\n const txHash = transactionMeta.hash as Hex | undefined;\n\n if (txHash === undefined) {\n controllerLog(\n 'Failed to resolve transaction hash after revocation transaction confirmed',\n {\n txId,\n permissionContext,\n error: new Error(\n 'Confirmed transaction is missing transaction hash',\n ),\n },\n );\n }\n\n this.submitRevocation({ permissionContext, txHash })\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): void => {\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): void => {\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 {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\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 const requestedPermissionContextLowercase = permissionContext.toLowerCase();\n\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n requestedPermissionContextLowercase,\n );\n }\n}\n\nexport default GatorPermissionsController;\n"]}
1
+ {"version":3,"file":"GatorPermissionsController.cjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAC3D,6EAAuE;AAYvE,uDAAoD;AACpD,6EAAqE;AAUrE,+CAA2D;AAE3D,mEAI4B;AAC5B,yCAKkB;AAElB,yCAAyC;AACzC,2EAA2E;AAE3E,uCAAwD;AAUxD,uCAAyC;AAEzC,kBAAkB;AAElB,iCAAiC;AACjC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,MAAM,yBAAyB,GAAG;IAChC,gCAAgC;IAChC,YAAY;IACZ,gDAAgD;IAChD,kBAAkB;IAClB,sBAAsB;IACtB,wBAAwB;IACxB,qBAAqB;CACb,CAAC;AAEX,2DAA2D;AAC3D,MAAM,qCAAqC,GACzC,sCAAgD,CAAC;AAEnD,MAAM,4BAA4B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,0BAA0B;AAEzF;;;GAGG;AACH,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtD,MAAM,kBAAkB,GAAG,4CAAmB,CAAC,wCAA4B,CAAC,CAAC;AAuD7E,MAAM,kCAAkC,GACtC;IACE,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,0BAA0B,EAAE;QAC1B,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,kBAAkB,EAAE;QAClB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,KAAK;QACd,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;IACD,mBAAmB,EAAE;Q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ChB,CAAC;IACF,OAAO,QAA2C,CAAC;AACrD,CAAC,+DAED,KAAK,qEACH,kBAAgD;IAEhD,OAAO,IAAA,wDAA8B,EAAC,kBAAkB,EAAE;QACxD,qBAAqB,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,uBAAA,IAAI,gGAAuB,MAA3B,IAAI,EAAwB,OAAO,CAAC;QACxE,kBAAkB;KACnB,CAAC,CAAC;AACL,CAAC,uIAWC,qBAA4C,EAC5C,MAA6B;IAE7B,MAAM,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,GAClD,qBAAqB,CAAC;IACxB,MAAM,EACJ,YAAY,EAAE,aAAa,EAC3B,EAAE,EAAE,GAAG,EACP,GAAG,kBAAkB,EACtB,GAAG,sBAAsB,CAAC;IAE3B,OAAO;QACL,GAAG,qBAAqB;QACxB,kBAAkB;QAClB,MAAM;KACP,CAAC;AACJ,CAAC,iKASC,sBAAsD;IAEtD,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,uBAAuB,GAAG,uBAAA,IAAI,uGAA8B,MAAlC,IAAI,CAAgC,CAAC;IAErE,OAAO,sBAAsB,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE;QACrD,MAAM,cAAc,GAAG,uBAAuB,CAAC,GAAG,CAChD,gBAAgB,CAAC,kBAAkB,CAAC,OAAO,CAAC,WAAW,EAAE,CAC1D,CAAC;QACF,OAAO,uBAAA,IAAI,2GAAkC,MAAtC,IAAI,EACT,gBAAgB,EAChB,cAAc,IAAI,QAAQ,CAC3B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AA2iBH,kBAAe,0BAA0B,CAAC","sourcesContent":["import 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 {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport type {\n SnapControllerHandleRequestAction,\n SnapControllerHasSnapAction,\n} from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { DELEGATION_FRAMEWORK_VERSION } from './constants';\nimport type { DecodedPermission } from './decodePermission';\nimport {\n createPermissionRulesForContracts,\n findRuleWithMatchingCaveatAddresses,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport type { GatorPermissionsControllerMethodActions } from './GatorPermissionsController-method-action-types';\nimport { controllerLog } from './logger';\nimport { updateGrantedPermissionsStatus } from './permissionOnChainStatus';\nimport type { PermissionStatusEip1193Provider } from './permissionOnChainStatus';\nimport { GatorPermissionsSnapRpcMethod } from './types';\nimport type {\n StoredGatorPermission,\n PermissionInfoWithMetadata,\n GatorPermissionStatus,\n SupportedPermissionType,\n DelegationDetails,\n RevocationParams,\n PendingRevocationParams,\n} from './types';\nimport { executeSnapRpc } from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchAndUpdateGatorPermissions',\n 'initialize',\n 'decodePermissionFromPermissionContextForOrigin',\n 'submitRevocation',\n 'addPendingRevocation',\n 'submitDirectRevocation',\n 'isPendingRevocation',\n] as const;\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst DEFAULT_MAX_SYNC_INTERVAL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\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// === CONFIG ===\n\n/**\n * Configuration for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerConfig = {\n /**\n * Permission types the controller supports (e.g. 'native-token-stream', 'erc20-token-periodic').\n */\n supportedPermissionTypes: SupportedPermissionType[];\n /**\n * Optional ID of the gator permissions provider Snap. Defaults to npm:@metamask/gator-permissions-snap.\n */\n gatorPermissionsProviderSnapId?: SnapId;\n /**\n * Optional maximum age of cached permissions (ms) before {@link GatorPermissionsController.initialize}\n * triggers a sync. Defaults to 30 days.\n */\n maxSyncIntervalMs?: number;\n};\n\n// === STATE ===\n\n/**\n * State shape for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerState = {\n /**\n * List of granted permissions with metadata (siteOrigin, status, revocationMetadata).\n */\n grantedPermissions: PermissionInfoWithMetadata[];\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This can be used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * List of gator permissions pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n\n /**\n * Timestamp (ms) of the last successful sync of gator permissions from profile sync.\n * -1 indicates that a sync has never completed successfully.\n */\n lastSyncedTimestamp: number;\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n grantedPermissions: {\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: true,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSyncedTimestamp: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Creates initial controller state, merging defaults with optional partial state.\n * Internal use only (e.g. constructor, tests).\n *\n * @param state - Optional partial state to merge with defaults.\n * @returns Complete {@link GatorPermissionsController} state.\n */\nfunction createGatorPermissionsControllerState(\n state?: Partial<GatorPermissionsControllerState>,\n): GatorPermissionsControllerState {\n return {\n grantedPermissions: [],\n pendingRevocations: [],\n lastSyncedTimestamp: -1,\n ...state,\n // isFetchingGatorPermissions is _always_ false when the controller is created\n isFetchingGatorPermissions: false,\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 * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerMethodActions;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapController:handleRequest and SnapController:hasSnap are allowed to be\n * called internally because they are used to fetch gator permissions from the\n * Snap.\n */\ntype AllowedActions =\n | SnapControllerHandleRequestAction\n | SnapControllerHasSnapAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction;\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 the gator permissions provider Snap.\n */\nexport class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n readonly #supportedPermissionTypes: readonly SupportedPermissionType[];\n\n /**\n * The Snap ID of the gator permissions provider.\n *\n * @returns The Snap ID of the gator permissions provider.\n */\n get gatorPermissionsProviderSnapId(): SnapId {\n return this.#gatorPermissionsProviderSnapId;\n }\n\n readonly #gatorPermissionsProviderSnapId: SnapId;\n\n readonly #maxSyncIntervalMs: number;\n\n /**\n * When a sync is in progress, holds the promise for that sync so concurrent\n * callers receive the same promise. Cleared when the sync completes.\n */\n #fetchAndUpdateGatorPermissionsPromise: Promise<void> | null = null;\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 other controllers.\n * @param args.config - Configuration (supported permission types and optional Snap id).\n * @param args.state - Optional partial state to merge with defaults.\n */\n constructor({\n messenger,\n config,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n config: GatorPermissionsControllerConfig;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n const initialState = createGatorPermissionsControllerState(state);\n\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: initialState,\n });\n\n this.#supportedPermissionTypes = config.supportedPermissionTypes;\n this.#gatorPermissionsProviderSnapId =\n config.gatorPermissionsProviderSnapId ??\n defaultGatorPermissionsProviderSnapId;\n this.#maxSyncIntervalMs =\n config.maxSyncIntervalMs ?? DEFAULT_MAX_SYNC_INTERVAL_MS;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Supported permission types this controller was configured with.\n *\n * @returns The supported permission types.\n */\n get supportedPermissionTypes(): readonly SupportedPermissionType[] {\n return this.#supportedPermissionTypes;\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean): void {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex): void {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(\n permissionContext: Hex,\n ): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n /**\n * Maps permission `context` (lowercase hex) to the last known {@link PermissionStatus}\n * from the current controller state (used when merging after a snap sync).\n *\n * @returns Map from lowercase `permissionResponse.context` to the prior {@link PermissionStatus}.\n */\n #buildPreviousStatusByContext(): Map<string, GatorPermissionStatus> {\n const map = new Map<string, GatorPermissionStatus>();\n for (const prev of this.state.grantedPermissions) {\n map.set(\n prev.permissionResponse.context.toLowerCase(),\n prev.status ?? 'Active',\n );\n }\n return map;\n }\n\n async #getProviderForChainId(\n chainId: Hex,\n ): Promise<PermissionStatusEip1193Provider> {\n const networkClientId: NetworkClientId = this.messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n const { provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return provider as PermissionStatusEip1193Provider;\n }\n\n async #updateGrantedPermissionsStatus(\n grantedPermissions: PermissionInfoWithMetadata[],\n ): Promise<PermissionInfoWithMetadata[]> {\n return updateGrantedPermissionsStatus(grantedPermissions, {\n getProviderForChainId: (chainId) => this.#getProviderForChainId(chainId),\n contractsByChainId,\n });\n }\n\n /**\n * Converts a stored gator permission to permission info with metadata.\n * Strips internal fields (dependencies, to) from the permission response.\n *\n * @param storedGatorPermission - The stored gator permission from the Snap.\n * @param status - The status for this permission.\n * @returns Permission info with metadata for state/UI.\n */\n #storedPermissionToPermissionInfo(\n storedGatorPermission: StoredGatorPermission,\n status: GatorPermissionStatus,\n ): PermissionInfoWithMetadata {\n const { permissionResponse: fullPermissionResponse } =\n storedGatorPermission;\n const {\n dependencies: _dependencies,\n to: _to,\n ...permissionResponse\n } = fullPermissionResponse;\n\n return {\n ...storedGatorPermission,\n permissionResponse,\n status,\n };\n }\n\n /**\n * Converts stored gator permissions from the Snap into permission info with metadata.\n *\n * @param storedGatorPermissions - Stored gator permissions returned by the Snap, or null.\n * @returns Array of permission info with metadata for state.\n */\n #storedPermissionsToPermissionInfoWithMetadata(\n storedGatorPermissions: StoredGatorPermission[] | null,\n ): PermissionInfoWithMetadata[] {\n if (!storedGatorPermissions) {\n return [];\n }\n\n const previousStatusByContext = this.#buildPreviousStatusByContext();\n\n return storedGatorPermissions.map((storedPermission) => {\n const previousStatus = previousStatusByContext.get(\n storedPermission.permissionResponse.context.toLowerCase(),\n );\n return this.#storedPermissionToPermissionInfo(\n storedPermission,\n previousStatus ?? 'Active',\n );\n });\n }\n\n /**\n * Fetches granted permissions from the gator permissions provider Snap and updates state.\n * If a sync is already in progress, returns the same promise. After the sync completes,\n * the next call will perform a new sync.\n *\n * @returns A promise that resolves when the sync completes. All data is available via the controller's state.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public fetchAndUpdateGatorPermissions(): Promise<void> {\n if (this.#fetchAndUpdateGatorPermissionsPromise !== null) {\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n const performFetchAndUpdate = async (): Promise<void> => {\n try {\n this.#setIsFetchingGatorPermissions(true);\n\n // Only ever fetch non-revoked permissions. Revoked permissions may be\n // left in storage by the gator permissions snap, but we don't need to\n // fetch them.\n const params = { isRevoked: false };\n\n const permissionsData = await executeSnapRpc<\n StoredGatorPermission[] | null\n >({\n messenger: this.messenger,\n snapId: this.#gatorPermissionsProviderSnapId,\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n params,\n });\n\n const grantedPermissions =\n this.#storedPermissionsToPermissionInfoWithMetadata(permissionsData);\n\n this.update((state) => {\n state.grantedPermissions = grantedPermissions;\n state.lastSyncedTimestamp = Date.now();\n });\n\n const grantedPermissionsWithStatus =\n await this.#updateGrantedPermissionsStatus(grantedPermissions);\n\n this.update((state) => {\n state.grantedPermissions = grantedPermissionsWithStatus;\n });\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 this.#fetchAndUpdateGatorPermissionsPromise = null;\n }\n };\n\n this.#fetchAndUpdateGatorPermissionsPromise = performFetchAndUpdate();\n\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n /**\n * Initializes the controller. Call once after construction to ensure the\n * controller is ready for use.\n *\n * @returns A promise that resolves when initialization is complete.\n */\n public async initialize(): Promise<void> {\n const currentTime = Date.now();\n const millisecondsSinceLastSync =\n currentTime - this.state.lastSyncedTimestamp;\n\n // Sync only when we have no data or data is stale, to avoid excessive startup\n // queries while still avoiding showing stale data while a refresh runs.\n if (\n this.state.lastSyncedTimestamp === -1 ||\n millisecondsSinceLastSync > this.#maxSyncIntervalMs\n ) {\n await this.fetchAndUpdateGatorPermissions();\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, to, 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.#gatorPermissionsProviderSnapId) {\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 const permissionRules = createPermissionRulesForContracts(contracts);\n\n // find the single rule where the specified enforcers contain all the required enforcers\n // and no forbidden enforcers\n const matchingRule = findRuleWithMatchingCaveatAddresses({\n enforcers,\n permissionRules,\n });\n\n // validate the terms of each caveat against the matching rule, returning the decoded result\n // this happens in a single function, as decoding is an inherent part of validation.\n const decodeResult = matchingRule.validateAndDecodePermission(caveats);\n\n if (!decodeResult.isValid) {\n throw new PermissionDecodingError({\n cause: decodeResult.error,\n });\n }\n\n const { expiry, data } = decodeResult;\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType: matchingRule.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 {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 const snapRequest = {\n snapId: this.#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();\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 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): void => {\n this.fetchAndUpdateGatorPermissions().catch((error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n });\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = (): void => {\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): void => {\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): void => {\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): void => {\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): void => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n txHash: transactionMeta.hash,\n });\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n controllerLog('Transaction not confirmed, skipping revocation', {\n txId,\n permissionContext,\n status: transactionMeta.status,\n });\n cleanup(transactionMeta.id);\n refreshPermissions('transaction not confirmed');\n return;\n }\n\n const txHash = transactionMeta.hash as Hex | undefined;\n\n if (txHash === undefined) {\n controllerLog(\n 'Failed to resolve transaction hash after revocation transaction confirmed',\n {\n txId,\n permissionContext,\n error: new Error(\n 'Confirmed transaction is missing transaction hash',\n ),\n },\n );\n }\n\n this.submitRevocation({ permissionContext, txHash })\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): void => {\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): void => {\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 {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\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 const requestedPermissionContextLowercase = permissionContext.toLowerCase();\n\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n requestedPermissionContextLowercase,\n );\n }\n}\n\nexport default GatorPermissionsController;\n"]}
@@ -1,6 +1,7 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
+ import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
4
5
  import type { SnapControllerHandleRequestAction, SnapControllerHasSnapAction } from "@metamask/snaps-controllers";
5
6
  import type { SnapId } from "@metamask/snaps-sdk";
6
7
  import type { TransactionControllerTransactionApprovedEvent, TransactionControllerTransactionConfirmedEvent, TransactionControllerTransactionDroppedEvent, TransactionControllerTransactionFailedEvent, TransactionControllerTransactionRejectedEvent } from "@metamask/transaction-controller";
@@ -32,7 +33,7 @@ export type GatorPermissionsControllerConfig = {
32
33
  */
33
34
  export type GatorPermissionsControllerState = {
34
35
  /**
35
- * List of granted permissions with metadata (siteOrigin, revocationMetadata).
36
+ * List of granted permissions with metadata (siteOrigin, status, revocationMetadata).
36
37
  */
37
38
  grantedPermissions: PermissionInfoWithMetadata[];
38
39
  /**
@@ -70,7 +71,7 @@ export type GatorPermissionsControllerActions = GatorPermissionsControllerGetSta
70
71
  * called internally because they are used to fetch gator permissions from the
71
72
  * Snap.
72
73
  */
73
- type AllowedActions = SnapControllerHandleRequestAction | SnapControllerHasSnapAction;
74
+ type AllowedActions = SnapControllerHandleRequestAction | SnapControllerHasSnapAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction;
74
75
  /**
75
76
  * The event that {@link GatorPermissionsController} publishes when updating state.
76
77
  */
@@ -1 +1 @@
1
- {"version":3,"file":"GatorPermissionsController.d.cts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,iCAAiC,EACjC,2BAA2B,EAC5B,oCAAoC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAGlD,OAAO,KAAK,EACV,6CAA6C,EAC7C,8CAA8C,EAC9C,4CAA4C,EAC5C,2CAA2C,EAC3C,6CAA6C,EAC9C,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAA2B;AAY5D,OAAO,KAAK,EAAE,uCAAuC,EAAE,6DAAyD;AAGhH,OAAO,KAAK,EAEV,0BAA0B,EAC1B,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACxB,oBAAgB;AAMjB,QAAA,MAAM,cAAc,+BAA+B,CAAC;AA4BpD;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C;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B,EAAE,GAAG,GAAG,OAAO;CAS5D;AAED,eAAe,0BAA0B,CAAC"}
1
+ {"version":3,"file":"GatorPermissionsController.d.cts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,mDAAmD,EACnD,2CAA2C,EAE5C,qCAAqC;AACtC,OAAO,KAAK,EACV,iCAAiC,EACjC,2BAA2B,EAC5B,oCAAoC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAGlD,OAAO,KAAK,EACV,6CAA6C,EAC7C,8CAA8C,EAC9C,4CAA4C,EAC5C,2CAA2C,EAC3C,6CAA6C,EAC9C,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAA2B;AAY5D,OAAO,KAAK,EAAE,uCAAuC,EAAE,6DAAyD;AAKhH,OAAO,KAAK,EAEV,0BAA0B,EAE1B,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACxB,oBAAgB;AAMjB,QAAA,MAAM,cAAc,+BAA+B,CAAC;AA4BpD;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C;;OAEG;IACH,wBAAwB,EAAE,uBAAuB,EAAE,CAAC;IACpD;;OAEG;IACH,8BAA8B,CAAC,EAAE,MAAM,CAAC;IACxC;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AAIF;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C;;OAEG;IACH,kBAAkB,EAAE,0BAA0B,EAAE,CAAC;IAEjD;;;OAGG;IACH,0BAA0B,EAAE,OAAO,CAAC;IAEpC;;OAE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IACH,IAAI,wBAAwB,IAAI,SAAS,uBAAuB,EAAE,CAEjE;IAkID;;;;;;;OAOG;IACI,8BAA8B,IAAI,OAAO,CAAC,IAAI,CAAC;IAuDtD;;;;;OAKG;IACU,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAexC;;;;;;;;;;;;;;;;;;;OAmBG;IACI,8CAA8C,CAAC,EACpD,MAAM,EACN,OAAO,EACP,UAAU,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,EACvD,QAAQ,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,GACrD,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE;YACR,aAAa,EAAE,MAAM,CAAC;YACtB,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC;QACF,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,iBAAiB;IAsDrB;;;;;;OAMG;IACU,gBAAgB,CAC3B,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,IAAI,CAAC;IAkEhB;;;;;;;;;;;;;;;;OAgBG;IACU,oBAAoB,CAC/B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,IAAI,CAAC;IAmPhB;;;;;;;;;;;;;OAaG;IACU,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAc5E;;;;;OAKG;IACI,mBAAmB,CAAC,iBAAiB,EAAE,GAAG,GAAG,OAAO;CAS5D;AAED,eAAe,0BAA0B,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
2
  import { BaseController } from "@metamask/base-controller";
3
3
  import type { Messenger } from "@metamask/messenger";
4
+ import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from "@metamask/network-controller";
4
5
  import type { SnapControllerHandleRequestAction, SnapControllerHasSnapAction } from "@metamask/snaps-controllers";
5
6
  import type { SnapId } from "@metamask/snaps-sdk";
6
7
  import type { TransactionControllerTransactionApprovedEvent, TransactionControllerTransactionConfirmedEvent, TransactionControllerTransactionDroppedEvent, TransactionControllerTransactionFailedEvent, TransactionControllerTransactionRejectedEvent } from "@metamask/transaction-controller";
@@ -32,7 +33,7 @@ export type GatorPermissionsControllerConfig = {
32
33
  */
33
34
  export type GatorPermissionsControllerState = {
34
35
  /**
35
- * List of granted permissions with metadata (siteOrigin, revocationMetadata).
36
+ * List of granted permissions with metadata (siteOrigin, status, revocationMetadata).
36
37
  */
37
38
  grantedPermissions: PermissionInfoWithMetadata[];
38
39
  /**
@@ -70,7 +71,7 @@ export type GatorPermissionsControllerActions = GatorPermissionsControllerGetSta
70
71
  * called internally because they are used to fetch gator permissions from the
71
72
  * Snap.
72
73
  */
73
- type AllowedActions = SnapControllerHandleRequestAction | SnapControllerHasSnapAction;
74
+ type AllowedActions = SnapControllerHandleRequestAction | SnapControllerHasSnapAction | NetworkControllerFindNetworkClientIdByChainIdAction | NetworkControllerGetNetworkClientByIdAction;
74
75
  /**
75
76
  * The event that {@link GatorPermissionsController} publishes when updating state.
76
77
  */
@@ -1 +1 @@
1
- {"version":3,"file":"GatorPermissionsController.d.mts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EACV,iCAAiC,EACjC,2BAA2B,EAC5B,oCAAoC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAGlD,OAAO,KAAK,EACV,6CAA6C,EAC7C,8CAA8C,EAC9C,4CAA4C,EAC5C,2CAA2C,EAC3C,6CAA6C,EAC9C,yCAAyC;AAC1C,O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IAc5E;;;;;OAKG;IACI,mBAAmB,CAAC,iBAAiB,EAAE,GAAG,GAAG,OAAO;CAS5D;AAED,eAAe,0BAA0B,CAAC"}
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
10
  return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
11
  };
12
- var _GatorPermissionsController_instances, _GatorPermissionsController_supportedPermissionTypes, _GatorPermissionsController_gatorPermissionsProviderSnapId, _GatorPermissionsController_maxSyncIntervalMs, _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext, _GatorPermissionsController_storedPermissionToPermissionInfo, _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata;
12
+ var _GatorPermissionsController_instances, _GatorPermissionsController_supportedPermissionTypes, _GatorPermissionsController_gatorPermissionsProviderSnapId, _GatorPermissionsController_maxSyncIntervalMs, _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext, _GatorPermissionsController_buildPreviousStatusByContext, _GatorPermissionsController_getProviderForChainId, _GatorPermissionsController_updateGrantedPermissionsStatus, _GatorPermissionsController_storedPermissionToPermissionInfo, _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata;
13
13
  import { BaseController } from "@metamask/base-controller";
14
14
  import { DELEGATOR_CONTRACTS } from "@metamask/delegation-deployments";
15
15
  import { HandlerType } from "@metamask/snaps-utils";
@@ -18,6 +18,7 @@ import { DELEGATION_FRAMEWORK_VERSION } from "./constants.mjs";
18
18
  import { createPermissionRulesForContracts, findRuleWithMatchingCaveatAddresses, reconstructDecodedPermission } from "./decodePermission/index.mjs";
19
19
  import { GatorPermissionsFetchError, GatorPermissionsProviderError, OriginNotAllowedError, PermissionDecodingError } from "./errors.mjs";
20
20
  import { controllerLog } from "./logger.mjs";
21
+ import { updateGrantedPermissionsStatus } from "./permissionOnChainStatus.mjs";
21
22
  import { GatorPermissionsSnapRpcMethod } from "./types.mjs";
22
23
  import { executeSnapRpc } from "./utils.mjs";
23
24
  // === GENERAL ===
@@ -165,6 +166,10 @@ export class GatorPermissionsController extends BaseController {
165
166
  state.grantedPermissions = grantedPermissions;
166
167
  state.lastSyncedTimestamp = Date.now();
167
168
  });
169
+ const grantedPermissionsWithStatus = await __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_updateGrantedPermissionsStatus).call(this, grantedPermissions);
170
+ this.update((state) => {
171
+ state.grantedPermissions = grantedPermissionsWithStatus;
172
+ });
168
173
  }
169
174
  catch (error) {
170
175
  controllerLog('Failed to fetch gator permissions', error);
@@ -546,18 +551,38 @@ _GatorPermissionsController_supportedPermissionTypes = new WeakMap(), _GatorPerm
546
551
  state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext.toLowerCase() !==
547
552
  permissionContext.toLowerCase());
548
553
  });
549
- }, _GatorPermissionsController_storedPermissionToPermissionInfo = function _GatorPermissionsController_storedPermissionToPermissionInfo(storedGatorPermission) {
554
+ }, _GatorPermissionsController_buildPreviousStatusByContext = function _GatorPermissionsController_buildPreviousStatusByContext() {
555
+ const map = new Map();
556
+ for (const prev of this.state.grantedPermissions) {
557
+ map.set(prev.permissionResponse.context.toLowerCase(), prev.status ?? 'Active');
558
+ }
559
+ return map;
560
+ }, _GatorPermissionsController_getProviderForChainId = async function _GatorPermissionsController_getProviderForChainId(chainId) {
561
+ const networkClientId = this.messenger.call('NetworkController:findNetworkClientIdByChainId', chainId);
562
+ const { provider } = this.messenger.call('NetworkController:getNetworkClientById', networkClientId);
563
+ return provider;
564
+ }, _GatorPermissionsController_updateGrantedPermissionsStatus = async function _GatorPermissionsController_updateGrantedPermissionsStatus(grantedPermissions) {
565
+ return updateGrantedPermissionsStatus(grantedPermissions, {
566
+ getProviderForChainId: (chainId) => __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_getProviderForChainId).call(this, chainId),
567
+ contractsByChainId,
568
+ });
569
+ }, _GatorPermissionsController_storedPermissionToPermissionInfo = function _GatorPermissionsController_storedPermissionToPermissionInfo(storedGatorPermission, status) {
550
570
  const { permissionResponse: fullPermissionResponse } = storedGatorPermission;
551
571
  const { dependencies: _dependencies, to: _to, ...permissionResponse } = fullPermissionResponse;
552
572
  return {
553
573
  ...storedGatorPermission,
554
574
  permissionResponse,
575
+ status,
555
576
  };
556
577
  }, _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata = function _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata(storedGatorPermissions) {
557
578
  if (!storedGatorPermissions) {
558
579
  return [];
559
580
  }
560
- return storedGatorPermissions.map((storedPermission) => __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_storedPermissionToPermissionInfo).call(this, storedPermission));
581
+ const previousStatusByContext = __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_buildPreviousStatusByContext).call(this);
582
+ return storedGatorPermissions.map((storedPermission) => {
583
+ const previousStatus = previousStatusByContext.get(storedPermission.permissionResponse.context.toLowerCase());
584
+ return __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_storedPermissionToPermissionInfo).call(this, storedPermission, previousStatus ?? 'Active');
585
+ });
561
586
  };
562
587
  export default GatorPermissionsController;
563
588
  //# sourceMappingURL=GatorPermissionsController.mjs.map