@metamask/gator-permissions-controller 0.6.0 → 0.8.0

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.
Files changed (52) hide show
  1. package/CHANGELOG.md +34 -1
  2. package/dist/GatorPermissionsController.cjs +111 -61
  3. package/dist/GatorPermissionsController.cjs.map +1 -1
  4. package/dist/GatorPermissionsController.d.cts +40 -7
  5. package/dist/GatorPermissionsController.d.cts.map +1 -1
  6. package/dist/GatorPermissionsController.d.mts +40 -7
  7. package/dist/GatorPermissionsController.d.mts.map +1 -1
  8. package/dist/GatorPermissionsController.mjs +109 -59
  9. package/dist/GatorPermissionsController.mjs.map +1 -1
  10. package/dist/constants.cjs +9 -0
  11. package/dist/constants.cjs.map +1 -0
  12. package/dist/constants.d.cts +6 -0
  13. package/dist/constants.d.cts.map +1 -0
  14. package/dist/constants.d.mts +6 -0
  15. package/dist/constants.d.mts.map +1 -0
  16. package/dist/constants.mjs +6 -0
  17. package/dist/constants.mjs.map +1 -0
  18. package/dist/decodePermission/decodePermission.cjs +56 -11
  19. package/dist/decodePermission/decodePermission.cjs.map +1 -1
  20. package/dist/decodePermission/decodePermission.d.cts +1 -1
  21. package/dist/decodePermission/decodePermission.d.cts.map +1 -1
  22. package/dist/decodePermission/decodePermission.d.mts +1 -1
  23. package/dist/decodePermission/decodePermission.d.mts.map +1 -1
  24. package/dist/decodePermission/decodePermission.mjs +57 -12
  25. package/dist/decodePermission/decodePermission.mjs.map +1 -1
  26. package/dist/decodePermission/utils.cjs +36 -24
  27. package/dist/decodePermission/utils.cjs.map +1 -1
  28. package/dist/decodePermission/utils.d.cts +5 -4
  29. package/dist/decodePermission/utils.d.cts.map +1 -1
  30. package/dist/decodePermission/utils.d.mts +5 -4
  31. package/dist/decodePermission/utils.d.mts.map +1 -1
  32. package/dist/decodePermission/utils.mjs +36 -24
  33. package/dist/decodePermission/utils.mjs.map +1 -1
  34. package/dist/index.cjs +3 -1
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +2 -1
  37. package/dist/index.d.cts.map +1 -1
  38. package/dist/index.d.mts +2 -1
  39. package/dist/index.d.mts.map +1 -1
  40. package/dist/index.mjs +1 -0
  41. package/dist/index.mjs.map +1 -1
  42. package/dist/test/mocks.cjs +5 -5
  43. package/dist/test/mocks.cjs.map +1 -1
  44. package/dist/test/mocks.mjs +5 -5
  45. package/dist/test/mocks.mjs.map +1 -1
  46. package/dist/types.cjs.map +1 -1
  47. package/dist/types.d.cts +6 -3
  48. package/dist/types.d.cts.map +1 -1
  49. package/dist/types.d.mts +6 -3
  50. package/dist/types.d.mts.map +1 -1
  51. package/dist/types.mjs.map +1 -1
  52. package/package.json +4 -8
package/CHANGELOG.md CHANGED
@@ -7,6 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.8.0]
11
+
12
+ ### Added
13
+
14
+ - Export `DELEGATION_FRAMEWORK_VERSION` constant to indicate the supported Delegation Framework version ([#7195](https://github.com/MetaMask/core/pull/7195))
15
+
16
+ ### Changed
17
+
18
+ - **BREAKING:** Permission decoding now rejects `TimestampEnforcer` caveats with zero `timestampBeforeThreshold` values ([#7195](https://github.com/MetaMask/core/pull/7195))
19
+ - `PermissionResponseSanitized` now includes `rules` property for stronger typing support ([#7195](https://github.com/MetaMask/core/pull/7195))
20
+ - Permission decoding now resolves `erc20-token-revocation` permission type ([#7299](https://github.com/MetaMask/core/pull/7299))
21
+ - Differentiate `erc20-token-revocation` permissions from `other` in controller state ([#7318](https://github.com/MetaMask/core/pull/7318))
22
+ - Bump `@metamask/transaction-controller` from `^62.3.1` to `^62.5.0` ([#7289](https://github.com/MetaMask/core/pull/7289), [#7325](https://github.com/MetaMask/core/pull/7325))
23
+
24
+ ## [0.7.0]
25
+
26
+ ### Added
27
+
28
+ - Refresh gator permissions map after revocation state change ([#7235](https://github.com/MetaMask/core/pull/7235))
29
+ - New `submitDirectRevocation` method for already-disabled delegations that don't require an on-chain transaction ([#7244](https://github.com/MetaMask/core/pull/7244))
30
+
31
+ ### Changed
32
+
33
+ - Move peer dependencies for controller and service packages to direct dependencies ([#7209](https://github.com/MetaMask/core/pull/7209), [#7220](https://github.com/MetaMask/core/pull/7220), [#7236](https://github.com/MetaMask/core/pull/7236), [#7257](https://github.com/MetaMask/core/pull/7257))
34
+ - The dependencies moved are:
35
+ - `@metamask/snaps-controllers` (^14.0.1)
36
+ - `@metamask/transaction-controller` (^62.3.1)
37
+ - In clients, it is now possible for multiple versions of these packages to exist in the dependency tree.
38
+ - For example, this scenario would be valid: a client relies on `@metamask/controller-a` 1.0.0 and `@metamask/controller-b` 1.0.0, and `@metamask/controller-b` depends on `@metamask/controller-a` 1.1.0.
39
+ - Note, however, that the versions specified in the client's `package.json` always "win", and you are expected to keep them up to date so as not to break controller and service intercommunication.
40
+
10
41
  ## [0.6.0]
11
42
 
12
43
  ### Changed
@@ -80,7 +111,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
80
111
 
81
112
  - Initial release ([#6033](https://github.com/MetaMask/core/pull/6033))
82
113
 
83
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.6.0...HEAD
114
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.8.0...HEAD
115
+ [0.8.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.7.0...@metamask/gator-permissions-controller@0.8.0
116
+ [0.7.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.6.0...@metamask/gator-permissions-controller@0.7.0
84
117
  [0.6.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.5.0...@metamask/gator-permissions-controller@0.6.0
85
118
  [0.5.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.4.0...@metamask/gator-permissions-controller@0.5.0
86
119
  [0.4.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.3.0...@metamask/gator-permissions-controller@0.4.0
@@ -6,10 +6,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
6
6
  };
7
7
  var _GatorPermissionsController_instances, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_setIsGatorPermissionsEnabled, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext, _GatorPermissionsController_registerMessageHandlers, _GatorPermissionsController_assertGatorPermissionsEnabled, _GatorPermissionsController_handleSnapRequestToGatorPermissionsProvider, _GatorPermissionsController_sanitizeStoredGatorPermission, _GatorPermissionsController_categorizePermissionsDataByTypeAndChainId;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.getDefaultGatorPermissionsControllerState = exports.DELEGATION_FRAMEWORK_VERSION = void 0;
9
+ exports.getDefaultGatorPermissionsControllerState = void 0;
10
10
  const base_controller_1 = require("@metamask/base-controller");
11
11
  const delegation_deployments_1 = require("@metamask/delegation-deployments");
12
12
  const snaps_utils_1 = require("@metamask/snaps-utils");
13
+ const constants_1 = require("./constants.cjs");
13
14
  const decodePermission_1 = require("./decodePermission/index.cjs");
14
15
  const errors_1 = require("./errors.cjs");
15
16
  const logger_1 = require("./logger.cjs");
@@ -20,24 +21,22 @@ const utils_1 = require("./utils.cjs");
20
21
  const controllerName = 'GatorPermissionsController';
21
22
  // Default value for the gator permissions provider snap id
22
23
  const defaultGatorPermissionsProviderSnapId = 'npm:@metamask/gator-permissions-snap';
23
- const defaultGatorPermissionsMap = {
24
- 'native-token-stream': {},
25
- 'native-token-periodic': {},
26
- 'erc20-token-stream': {},
27
- 'erc20-token-periodic': {},
28
- other: {},
24
+ const createEmptyGatorPermissionsMap = () => {
25
+ return {
26
+ 'erc20-token-revocation': {},
27
+ 'native-token-stream': {},
28
+ 'native-token-periodic': {},
29
+ 'erc20-token-stream': {},
30
+ 'erc20-token-periodic': {},
31
+ other: {},
32
+ };
29
33
  };
30
- /**
31
- * Delegation framework version used to select the correct deployed enforcer
32
- * contract addresses from `@metamask/delegation-deployments`.
33
- */
34
- exports.DELEGATION_FRAMEWORK_VERSION = '1.3.0';
35
34
  /**
36
35
  * Timeout duration for pending revocations (2 hours in milliseconds).
37
36
  * After this time, event listeners will be cleaned up to prevent memory leaks.
38
37
  */
39
38
  const PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;
40
- const contractsByChainId = delegation_deployments_1.DELEGATOR_CONTRACTS[exports.DELEGATION_FRAMEWORK_VERSION];
39
+ const contractsByChainId = delegation_deployments_1.DELEGATOR_CONTRACTS[constants_1.DELEGATION_FRAMEWORK_VERSION];
41
40
  const gatorPermissionsControllerMetadata = {
42
41
  isGatorPermissionsEnabled: {
43
42
  includeInStateLogs: true,
@@ -81,7 +80,7 @@ const gatorPermissionsControllerMetadata = {
81
80
  function getDefaultGatorPermissionsControllerState() {
82
81
  return {
83
82
  isGatorPermissionsEnabled: false,
84
- gatorPermissionsMapSerialized: (0, utils_1.serializeGatorPermissionsMap)(defaultGatorPermissionsMap),
83
+ gatorPermissionsMapSerialized: (0, utils_1.serializeGatorPermissionsMap)(createEmptyGatorPermissionsMap()),
85
84
  isFetchingGatorPermissions: false,
86
85
  gatorPermissionsProviderSnapId: defaultGatorPermissionsProviderSnapId,
87
86
  pendingRevocations: [],
@@ -141,7 +140,7 @@ class GatorPermissionsController extends base_controller_1.BaseController {
141
140
  async disableGatorPermissions() {
142
141
  this.update((state) => {
143
142
  state.isGatorPermissionsEnabled = false;
144
- state.gatorPermissionsMapSerialized = (0, utils_1.serializeGatorPermissionsMap)(defaultGatorPermissionsMap);
143
+ state.gatorPermissionsMapSerialized = (0, utils_1.serializeGatorPermissionsMap)(createEmptyGatorPermissionsMap());
145
144
  });
146
145
  }
147
146
  /**
@@ -256,25 +255,39 @@ class GatorPermissionsController extends base_controller_1.BaseController {
256
255
  permissionContext: revocationParams.permissionContext,
257
256
  });
258
257
  __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_assertGatorPermissionsEnabled).call(this);
258
+ const snapRequest = {
259
+ snapId: this.state.gatorPermissionsProviderSnapId,
260
+ origin: 'metamask',
261
+ handler: snaps_utils_1.HandlerType.OnRpcRequest,
262
+ request: {
263
+ jsonrpc: '2.0',
264
+ method: types_1.GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,
265
+ params: revocationParams,
266
+ },
267
+ };
259
268
  try {
260
- const snapRequest = {
261
- snapId: this.state.gatorPermissionsProviderSnapId,
262
- origin: 'metamask',
263
- handler: snaps_utils_1.HandlerType.OnRpcRequest,
264
- request: {
265
- jsonrpc: '2.0',
266
- method: types_1.GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,
267
- params: revocationParams,
268
- },
269
- };
270
269
  const result = await this.messenger.call('SnapController:handleRequest', snapRequest);
271
- __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext).call(this, revocationParams.permissionContext);
270
+ // Refresh list first (permission removed from list)
271
+ await this.fetchAndUpdateGatorPermissions({ isRevoked: false });
272
272
  (0, logger_1.controllerLog)('Successfully submitted revocation', {
273
273
  permissionContext: revocationParams.permissionContext,
274
274
  result,
275
275
  });
276
276
  }
277
277
  catch (error) {
278
+ // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed
279
+ if (error instanceof errors_1.GatorPermissionsFetchError) {
280
+ (0, logger_1.controllerLog)('Revocation submitted successfully but failed to refresh permissions list', {
281
+ error,
282
+ permissionContext: revocationParams.permissionContext,
283
+ });
284
+ // Wrap with a more specific message indicating revocation succeeded
285
+ throw new errors_1.GatorPermissionsFetchError({
286
+ message: 'Failed to refresh permissions list after successful revocation',
287
+ cause: error,
288
+ });
289
+ }
290
+ // Otherwise, revocation failed - wrap in provider error
278
291
  (0, logger_1.controllerLog)('Failed to submit revocation', {
279
292
  error,
280
293
  permissionContext: revocationParams.permissionContext,
@@ -284,6 +297,9 @@ class GatorPermissionsController extends base_controller_1.BaseController {
284
297
  cause: error,
285
298
  });
286
299
  }
300
+ finally {
301
+ __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext).call(this, revocationParams.permissionContext);
302
+ }
287
303
  }
288
304
  /**
289
305
  * Adds a pending revocation that will be submitted once the transaction is confirmed.
@@ -318,6 +334,16 @@ class GatorPermissionsController extends base_controller_1.BaseController {
318
334
  dropped: undefined,
319
335
  timeoutId: undefined,
320
336
  };
337
+ // Helper to refresh permissions after transaction state change
338
+ const refreshPermissions = (context) => {
339
+ this.fetchAndUpdateGatorPermissions({ isRevoked: false }).catch((error) => {
340
+ (0, logger_1.controllerLog)(`Failed to refresh permissions after ${context}`, {
341
+ txId,
342
+ permissionContext,
343
+ error,
344
+ });
345
+ });
346
+ };
321
347
  // Helper to unsubscribe from approval/rejection events after decision is made
322
348
  const cleanupApprovalHandlers = () => {
323
349
  if (handlers.approved) {
@@ -379,13 +405,15 @@ class GatorPermissionsController extends base_controller_1.BaseController {
379
405
  txId,
380
406
  permissionContext,
381
407
  });
382
- this.submitRevocation({ permissionContext }).catch((error) => {
408
+ this.submitRevocation({ permissionContext })
409
+ .catch((error) => {
383
410
  (0, logger_1.controllerLog)('Failed to submit revocation after transaction confirmed', {
384
411
  txId,
385
412
  permissionContext,
386
413
  error,
387
414
  });
388
- });
415
+ })
416
+ .finally(() => refreshPermissions('transaction confirmed'));
389
417
  cleanup(transactionMeta.id);
390
418
  }
391
419
  };
@@ -398,6 +426,7 @@ class GatorPermissionsController extends base_controller_1.BaseController {
398
426
  error: payload.error,
399
427
  });
400
428
  cleanup(payload.transactionMeta.id);
429
+ refreshPermissions('transaction failed');
401
430
  }
402
431
  };
403
432
  // Handle dropped transaction - cleanup without submitting revocation
@@ -408,6 +437,7 @@ class GatorPermissionsController extends base_controller_1.BaseController {
408
437
  permissionContext,
409
438
  });
410
439
  cleanup(payload.transactionMeta.id);
440
+ refreshPermissions('transaction dropped');
411
441
  }
412
442
  };
413
443
  // Subscribe to user approval/rejection events
@@ -426,6 +456,40 @@ class GatorPermissionsController extends base_controller_1.BaseController {
426
456
  cleanup(txId);
427
457
  }, PENDING_REVOCATION_TIMEOUT);
428
458
  }
459
+ /**
460
+ * Submits a revocation directly without requiring an on-chain transaction.
461
+ * Used for already-disabled delegations that don't require an on-chain transaction.
462
+ *
463
+ * This method:
464
+ * 1. Adds the permission context to pending revocations state (disables UI button)
465
+ * 2. Immediately calls submitRevocation to remove from snap storage
466
+ * 3. On success, removes from pending revocations state (re-enables UI button)
467
+ * 4. On failure, keeps in pending revocations so UI can show error/retry state
468
+ *
469
+ * @param params - The revocation parameters containing the permission context.
470
+ * @returns A promise that resolves when the revocation is submitted successfully.
471
+ * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.
472
+ * @throws {GatorPermissionsProviderError} If the snap request fails.
473
+ */
474
+ async submitDirectRevocation(params) {
475
+ __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_assertGatorPermissionsEnabled).call(this);
476
+ // Use a placeholder txId that doesn't conflict with real transaction IDs
477
+ const placeholderTxId = `no-tx-${params.permissionContext}`;
478
+ // Add to pending revocations state first (disables UI button immediately)
479
+ __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_addPendingRevocationToState).call(this, placeholderTxId, params.permissionContext);
480
+ // Immediately submit the revocation (will remove from pending on success)
481
+ await this.submitRevocation(params);
482
+ }
483
+ /**
484
+ * Checks if a permission context is in the pending revocations list.
485
+ *
486
+ * @param permissionContext - The permission context to check.
487
+ * @returns `true` if the permission context is pending revocation, `false` otherwise.
488
+ */
489
+ isPendingRevocation(permissionContext) {
490
+ return this.state.pendingRevocations.some((pendingRevocation) => pendingRevocation.permissionContext.toLowerCase() ===
491
+ permissionContext.toLowerCase());
492
+ }
429
493
  }
430
494
  _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsController_setIsFetchingGatorPermissions = function _GatorPermissionsController_setIsFetchingGatorPermissions(isFetchingGatorPermissions) {
431
495
  this.update((state) => {
@@ -448,7 +512,8 @@ _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsControll
448
512
  });
449
513
  }, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext = function _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext(permissionContext) {
450
514
  this.update((state) => {
451
- state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext !== permissionContext);
515
+ state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext.toLowerCase() !==
516
+ permissionContext.toLowerCase());
452
517
  });
453
518
  }, _GatorPermissionsController_registerMessageHandlers = function _GatorPermissionsController_registerMessageHandlers() {
454
519
  this.messenger.registerActionHandler(`${controllerName}:fetchAndUpdateGatorPermissions`, this.fetchAndUpdateGatorPermissions.bind(this));
@@ -458,6 +523,8 @@ _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsControll
458
523
  const submitRevocationAction = `${controllerName}:submitRevocation`;
459
524
  this.messenger.registerActionHandler(submitRevocationAction, this.submitRevocation.bind(this));
460
525
  this.messenger.registerActionHandler(`${controllerName}:addPendingRevocation`, this.addPendingRevocation.bind(this));
526
+ this.messenger.registerActionHandler(`${controllerName}:submitDirectRevocation`, this.submitDirectRevocation.bind(this));
527
+ this.messenger.registerActionHandler(`${controllerName}:isPendingRevocation`, this.isPendingRevocation.bind(this));
461
528
  }, _GatorPermissionsController_assertGatorPermissionsEnabled = function _GatorPermissionsController_assertGatorPermissionsEnabled() {
462
529
  if (!this.state.isGatorPermissionsEnabled) {
463
530
  throw new errors_1.GatorPermissionsNotEnabledError();
@@ -494,7 +561,7 @@ async function _GatorPermissionsController_handleSnapRequestToGatorPermissionsPr
494
561
  }
495
562
  }, _GatorPermissionsController_sanitizeStoredGatorPermission = function _GatorPermissionsController_sanitizeStoredGatorPermission(storedGatorPermission) {
496
563
  const { permissionResponse } = storedGatorPermission;
497
- const { rules, dependencyInfo, signer, ...rest } = permissionResponse;
564
+ const { dependencyInfo, signer, ...rest } = permissionResponse;
498
565
  return {
499
566
  ...storedGatorPermission,
500
567
  permissionResponse: {
@@ -502,39 +569,22 @@ async function _GatorPermissionsController_handleSnapRequestToGatorPermissionsPr
502
569
  },
503
570
  };
504
571
  }, _GatorPermissionsController_categorizePermissionsDataByTypeAndChainId = function _GatorPermissionsController_categorizePermissionsDataByTypeAndChainId(storedGatorPermissions) {
572
+ const gatorPermissionsMap = createEmptyGatorPermissionsMap();
505
573
  if (!storedGatorPermissions) {
506
- return defaultGatorPermissionsMap;
507
- }
508
- return storedGatorPermissions.reduce((gatorPermissionsMap, storedGatorPermission) => {
509
- const { permissionResponse } = storedGatorPermission;
510
- const permissionType = permissionResponse.permission.type;
511
- const { chainId } = permissionResponse;
512
- const sanitizedStoredGatorPermission = __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_sanitizeStoredGatorPermission).call(this, storedGatorPermission);
513
- switch (permissionType) {
514
- case 'native-token-stream':
515
- case 'native-token-periodic':
516
- case 'erc20-token-stream':
517
- case 'erc20-token-periodic':
518
- if (!gatorPermissionsMap[permissionType][chainId]) {
519
- gatorPermissionsMap[permissionType][chainId] = [];
520
- }
521
- gatorPermissionsMap[permissionType][chainId].push(sanitizedStoredGatorPermission);
522
- break;
523
- default:
524
- if (!gatorPermissionsMap.other[chainId]) {
525
- gatorPermissionsMap.other[chainId] = [];
526
- }
527
- gatorPermissionsMap.other[chainId].push(sanitizedStoredGatorPermission);
528
- break;
529
- }
530
574
  return gatorPermissionsMap;
531
- }, {
532
- 'native-token-stream': {},
533
- 'native-token-periodic': {},
534
- 'erc20-token-stream': {},
535
- 'erc20-token-periodic': {},
536
- other: {},
537
- });
575
+ }
576
+ for (const storedGatorPermission of storedGatorPermissions) {
577
+ const { permissionResponse: { permission: { type: permissionType }, chainId, }, } = storedGatorPermission;
578
+ const isPermissionTypeKnown = Object.prototype.hasOwnProperty.call(gatorPermissionsMap, permissionType);
579
+ const permissionTypeKey = isPermissionTypeKnown
580
+ ? permissionType
581
+ : 'other';
582
+ gatorPermissionsMap[permissionTypeKey][chainId] = [
583
+ ...(gatorPermissionsMap[permissionTypeKey][chainId] || []),
584
+ __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_sanitizeStoredGatorPermission).call(this, storedGatorPermission),
585
+ ];
586
+ }
587
+ return gatorPermissionsMap;
538
588
  };
539
589
  exports.default = GatorPermissionsController;
540
590
  //# sourceMappingURL=GatorPermissionsController.cjs.map
@@ -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;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;AACU,QAAA,4BAA4B,GAAG,OAAO,CAAC;AAEpD;;;GAGG;AACH,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtD,MAAM,kBAAkB,GAAG,4CAAmB,CAAC,oCAA4B,CAAC,CAAC;AAuC7E,MAAM,kCAAkC,GACtC;IACE,yBAAyB,EAAE;QACzB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb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AAmB,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;kBA7PkB,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 * 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\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 !== permissionContext,\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\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 try {\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 const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (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 }\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"]}
1
+ {"version":3,"file":"GatorPermissionsController.cjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;;;;AAMA,+DAA2D;AAC3D,6EAAuE;AAIvE,uDAAoD;AAUpD,+CAA2D;AAE3D,mEAI4B;AAC5B,yCAMkB;AAClB,yCAAyC;AACzC,uCAAwD;AAUxD,uCAGiB;AAEjB,kBAAkB;AAElB,iCAAiC;AACjC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,2DAA2D;AAC3D,MAAM,qCAAqC,GACzC,sCAAgD,CAAC;AAEnD,MAAM,8BAA8B,GAA8B,GAAG,EAAE;IACrE,OAAO;QACL,wBAAwB,EAAE,EAAE;QAC5B,qBAAqB,EAAE,EAAE;QACzB,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,sBAAsB,EAAE,EAAE;QAC1B,KAAK,EAAE,EAAE;KACV,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,0BAA0B,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAEtD,MAAM,kBAAkB,GAAG,4CAAmB,CAAC,wCAA4B,CAAC,CAAC;AAuC7E,MAAM,kCAAkC,GACtC;IACE,yBAAyB,EAAE;QACzB,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,KAAK;KAChB;IACD,6BAA6B,EAAE;QAC7B,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;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BAAmB,CAAC;AAC7B,CAAC;kBAjPkB,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 { DELEGATION_FRAMEWORK_VERSION } from './constants';\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 { GatorPermissionsSnapRpcMethod } from './types';\nimport type { StoredGatorPermissionSanitized } from './types';\nimport type {\n GatorPermissionsMap,\n PermissionTypesWithCustom,\n StoredGatorPermission,\n DelegationDetails,\n RevocationParams,\n 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 createEmptyGatorPermissionsMap: () => GatorPermissionsMap = () => {\n return {\n 'erc20-token-revocation': {},\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n };\n};\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 createEmptyGatorPermissionsMap(),\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 for client exposure.\n * Removes internal fields (dependencyInfo, signer)\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 { 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 const gatorPermissionsMap = createEmptyGatorPermissionsMap();\n\n if (!storedGatorPermissions) {\n return gatorPermissionsMap;\n }\n\n for (const storedGatorPermission of storedGatorPermissions) {\n const {\n permissionResponse: {\n permission: { type: permissionType },\n chainId,\n },\n } = storedGatorPermission;\n\n const isPermissionTypeKnown = Object.prototype.hasOwnProperty.call(\n gatorPermissionsMap,\n permissionType,\n );\n\n const permissionTypeKey = isPermissionTypeKnown\n ? (permissionType as keyof GatorPermissionsMap)\n : 'other';\n\n type PermissionsMapElementArray =\n GatorPermissionsMap[typeof permissionTypeKey][typeof chainId];\n\n gatorPermissionsMap[permissionTypeKey][chainId] = [\n ...(gatorPermissionsMap[permissionTypeKey][chainId] || []),\n this.#sanitizeStoredGatorPermission(storedGatorPermission),\n ] as PermissionsMapElementArray;\n }\n\n return gatorPermissionsMap;\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 createEmptyGatorPermissionsMap(),\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"]}