@metamask/gator-permissions-controller 0.5.0 → 0.7.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.
- package/CHANGELOG.md +26 -1
- package/dist/GatorPermissionsController.cjs +82 -14
- package/dist/GatorPermissionsController.cjs.map +1 -1
- package/dist/GatorPermissionsController.d.cts +39 -1
- package/dist/GatorPermissionsController.d.cts.map +1 -1
- package/dist/GatorPermissionsController.d.mts +39 -1
- package/dist/GatorPermissionsController.d.mts.map +1 -1
- package/dist/GatorPermissionsController.mjs +82 -14
- package/dist/GatorPermissionsController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -7
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.7.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Refresh gator permissions map after revocation state change ([#7235](https://github.com/MetaMask/core/pull/7235))
|
|
15
|
+
- Add `submitDirectRevocation` method for already-disabled delegations that don't require an on-chain transaction ([#7244](https://github.com/MetaMask/core/pull/7244))
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- 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))
|
|
20
|
+
- The dependencies moved are:
|
|
21
|
+
- `@metamask/snaps-controllers` (^14.0.1)
|
|
22
|
+
- `@metamask/transaction-controller` (^62.3.1)
|
|
23
|
+
- In clients, it is now possible for multiple versions of these packages to exist in the dependency tree.
|
|
24
|
+
- 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.
|
|
25
|
+
- 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.
|
|
26
|
+
|
|
27
|
+
## [0.6.0]
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- **BREAKING:** Bump `@metamask/transaction-controller` from `^61.1.0` to `^62.0.0` ([#7202](https://github.com/MetaMask/core/pull/7202))
|
|
32
|
+
|
|
10
33
|
## [0.5.0]
|
|
11
34
|
|
|
12
35
|
### Fixed
|
|
@@ -74,7 +97,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
74
97
|
|
|
75
98
|
- Initial release ([#6033](https://github.com/MetaMask/core/pull/6033))
|
|
76
99
|
|
|
77
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.
|
|
100
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.7.0...HEAD
|
|
101
|
+
[0.7.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.6.0...@metamask/gator-permissions-controller@0.7.0
|
|
102
|
+
[0.6.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.5.0...@metamask/gator-permissions-controller@0.6.0
|
|
78
103
|
[0.5.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.4.0...@metamask/gator-permissions-controller@0.5.0
|
|
79
104
|
[0.4.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.3.0...@metamask/gator-permissions-controller@0.4.0
|
|
80
105
|
[0.3.0]: https://github.com/MetaMask/core/compare/@metamask/gator-permissions-controller@0.2.2...@metamask/gator-permissions-controller@0.3.0
|
|
@@ -256,25 +256,39 @@ class GatorPermissionsController extends base_controller_1.BaseController {
|
|
|
256
256
|
permissionContext: revocationParams.permissionContext,
|
|
257
257
|
});
|
|
258
258
|
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_assertGatorPermissionsEnabled).call(this);
|
|
259
|
+
const snapRequest = {
|
|
260
|
+
snapId: this.state.gatorPermissionsProviderSnapId,
|
|
261
|
+
origin: 'metamask',
|
|
262
|
+
handler: snaps_utils_1.HandlerType.OnRpcRequest,
|
|
263
|
+
request: {
|
|
264
|
+
jsonrpc: '2.0',
|
|
265
|
+
method: types_1.GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,
|
|
266
|
+
params: revocationParams,
|
|
267
|
+
},
|
|
268
|
+
};
|
|
259
269
|
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
270
|
const result = await this.messenger.call('SnapController:handleRequest', snapRequest);
|
|
271
|
-
|
|
271
|
+
// Refresh list first (permission removed from list)
|
|
272
|
+
await this.fetchAndUpdateGatorPermissions({ isRevoked: false });
|
|
272
273
|
(0, logger_1.controllerLog)('Successfully submitted revocation', {
|
|
273
274
|
permissionContext: revocationParams.permissionContext,
|
|
274
275
|
result,
|
|
275
276
|
});
|
|
276
277
|
}
|
|
277
278
|
catch (error) {
|
|
279
|
+
// If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed
|
|
280
|
+
if (error instanceof errors_1.GatorPermissionsFetchError) {
|
|
281
|
+
(0, logger_1.controllerLog)('Revocation submitted successfully but failed to refresh permissions list', {
|
|
282
|
+
error,
|
|
283
|
+
permissionContext: revocationParams.permissionContext,
|
|
284
|
+
});
|
|
285
|
+
// Wrap with a more specific message indicating revocation succeeded
|
|
286
|
+
throw new errors_1.GatorPermissionsFetchError({
|
|
287
|
+
message: 'Failed to refresh permissions list after successful revocation',
|
|
288
|
+
cause: error,
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
// Otherwise, revocation failed - wrap in provider error
|
|
278
292
|
(0, logger_1.controllerLog)('Failed to submit revocation', {
|
|
279
293
|
error,
|
|
280
294
|
permissionContext: revocationParams.permissionContext,
|
|
@@ -284,6 +298,9 @@ class GatorPermissionsController extends base_controller_1.BaseController {
|
|
|
284
298
|
cause: error,
|
|
285
299
|
});
|
|
286
300
|
}
|
|
301
|
+
finally {
|
|
302
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext).call(this, revocationParams.permissionContext);
|
|
303
|
+
}
|
|
287
304
|
}
|
|
288
305
|
/**
|
|
289
306
|
* Adds a pending revocation that will be submitted once the transaction is confirmed.
|
|
@@ -318,6 +335,16 @@ class GatorPermissionsController extends base_controller_1.BaseController {
|
|
|
318
335
|
dropped: undefined,
|
|
319
336
|
timeoutId: undefined,
|
|
320
337
|
};
|
|
338
|
+
// Helper to refresh permissions after transaction state change
|
|
339
|
+
const refreshPermissions = (context) => {
|
|
340
|
+
this.fetchAndUpdateGatorPermissions({ isRevoked: false }).catch((error) => {
|
|
341
|
+
(0, logger_1.controllerLog)(`Failed to refresh permissions after ${context}`, {
|
|
342
|
+
txId,
|
|
343
|
+
permissionContext,
|
|
344
|
+
error,
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
};
|
|
321
348
|
// Helper to unsubscribe from approval/rejection events after decision is made
|
|
322
349
|
const cleanupApprovalHandlers = () => {
|
|
323
350
|
if (handlers.approved) {
|
|
@@ -379,13 +406,15 @@ class GatorPermissionsController extends base_controller_1.BaseController {
|
|
|
379
406
|
txId,
|
|
380
407
|
permissionContext,
|
|
381
408
|
});
|
|
382
|
-
this.submitRevocation({ permissionContext })
|
|
409
|
+
this.submitRevocation({ permissionContext })
|
|
410
|
+
.catch((error) => {
|
|
383
411
|
(0, logger_1.controllerLog)('Failed to submit revocation after transaction confirmed', {
|
|
384
412
|
txId,
|
|
385
413
|
permissionContext,
|
|
386
414
|
error,
|
|
387
415
|
});
|
|
388
|
-
})
|
|
416
|
+
})
|
|
417
|
+
.finally(() => refreshPermissions('transaction confirmed'));
|
|
389
418
|
cleanup(transactionMeta.id);
|
|
390
419
|
}
|
|
391
420
|
};
|
|
@@ -398,6 +427,7 @@ class GatorPermissionsController extends base_controller_1.BaseController {
|
|
|
398
427
|
error: payload.error,
|
|
399
428
|
});
|
|
400
429
|
cleanup(payload.transactionMeta.id);
|
|
430
|
+
refreshPermissions('transaction failed');
|
|
401
431
|
}
|
|
402
432
|
};
|
|
403
433
|
// Handle dropped transaction - cleanup without submitting revocation
|
|
@@ -408,6 +438,7 @@ class GatorPermissionsController extends base_controller_1.BaseController {
|
|
|
408
438
|
permissionContext,
|
|
409
439
|
});
|
|
410
440
|
cleanup(payload.transactionMeta.id);
|
|
441
|
+
refreshPermissions('transaction dropped');
|
|
411
442
|
}
|
|
412
443
|
};
|
|
413
444
|
// Subscribe to user approval/rejection events
|
|
@@ -426,6 +457,40 @@ class GatorPermissionsController extends base_controller_1.BaseController {
|
|
|
426
457
|
cleanup(txId);
|
|
427
458
|
}, PENDING_REVOCATION_TIMEOUT);
|
|
428
459
|
}
|
|
460
|
+
/**
|
|
461
|
+
* Submits a revocation directly without requiring an on-chain transaction.
|
|
462
|
+
* Used for already-disabled delegations that don't require an on-chain transaction.
|
|
463
|
+
*
|
|
464
|
+
* This method:
|
|
465
|
+
* 1. Adds the permission context to pending revocations state (disables UI button)
|
|
466
|
+
* 2. Immediately calls submitRevocation to remove from snap storage
|
|
467
|
+
* 3. On success, removes from pending revocations state (re-enables UI button)
|
|
468
|
+
* 4. On failure, keeps in pending revocations so UI can show error/retry state
|
|
469
|
+
*
|
|
470
|
+
* @param params - The revocation parameters containing the permission context.
|
|
471
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
472
|
+
* @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.
|
|
473
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
474
|
+
*/
|
|
475
|
+
async submitDirectRevocation(params) {
|
|
476
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_assertGatorPermissionsEnabled).call(this);
|
|
477
|
+
// Use a placeholder txId that doesn't conflict with real transaction IDs
|
|
478
|
+
const placeholderTxId = `no-tx-${params.permissionContext}`;
|
|
479
|
+
// Add to pending revocations state first (disables UI button immediately)
|
|
480
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_addPendingRevocationToState).call(this, placeholderTxId, params.permissionContext);
|
|
481
|
+
// Immediately submit the revocation (will remove from pending on success)
|
|
482
|
+
await this.submitRevocation(params);
|
|
483
|
+
}
|
|
484
|
+
/**
|
|
485
|
+
* Checks if a permission context is in the pending revocations list.
|
|
486
|
+
*
|
|
487
|
+
* @param permissionContext - The permission context to check.
|
|
488
|
+
* @returns `true` if the permission context is pending revocation, `false` otherwise.
|
|
489
|
+
*/
|
|
490
|
+
isPendingRevocation(permissionContext) {
|
|
491
|
+
return this.state.pendingRevocations.some((pendingRevocation) => pendingRevocation.permissionContext.toLowerCase() ===
|
|
492
|
+
permissionContext.toLowerCase());
|
|
493
|
+
}
|
|
429
494
|
}
|
|
430
495
|
_GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsController_setIsFetchingGatorPermissions = function _GatorPermissionsController_setIsFetchingGatorPermissions(isFetchingGatorPermissions) {
|
|
431
496
|
this.update((state) => {
|
|
@@ -448,7 +513,8 @@ _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsControll
|
|
|
448
513
|
});
|
|
449
514
|
}, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext = function _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext(permissionContext) {
|
|
450
515
|
this.update((state) => {
|
|
451
|
-
state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext !==
|
|
516
|
+
state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext.toLowerCase() !==
|
|
517
|
+
permissionContext.toLowerCase());
|
|
452
518
|
});
|
|
453
519
|
}, _GatorPermissionsController_registerMessageHandlers = function _GatorPermissionsController_registerMessageHandlers() {
|
|
454
520
|
this.messenger.registerActionHandler(`${controllerName}:fetchAndUpdateGatorPermissions`, this.fetchAndUpdateGatorPermissions.bind(this));
|
|
@@ -458,6 +524,8 @@ _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsControll
|
|
|
458
524
|
const submitRevocationAction = `${controllerName}:submitRevocation`;
|
|
459
525
|
this.messenger.registerActionHandler(submitRevocationAction, this.submitRevocation.bind(this));
|
|
460
526
|
this.messenger.registerActionHandler(`${controllerName}:addPendingRevocation`, this.addPendingRevocation.bind(this));
|
|
527
|
+
this.messenger.registerActionHandler(`${controllerName}:submitDirectRevocation`, this.submitDirectRevocation.bind(this));
|
|
528
|
+
this.messenger.registerActionHandler(`${controllerName}:isPendingRevocation`, this.isPendingRevocation.bind(this));
|
|
461
529
|
}, _GatorPermissionsController_assertGatorPermissionsEnabled = function _GatorPermissionsController_assertGatorPermissionsEnabled() {
|
|
462
530
|
if (!this.state.isGatorPermissionsEnabled) {
|
|
463
531
|
throw new errors_1.GatorPermissionsNotEnabledError();
|
|
@@ -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;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AC;YAC7B,KAAK,oBAAoB,CAAC;YAC1B,KAAK,sBAAsB;gBACzB,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;oBAClD,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBACpD,CAAC;gBAGC,mBAAmB,CAAC,cAAc,CAAC,CACjC,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;YACR;gBACE,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBACxC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBAC1C,CAAC;gBAGC,mBAAmB,CAAC,KAAK,CACvB,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;QACV,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,sBAAsB,EAAE,EAAE;QAC1B,KAAK,EAAE,EAAE;KACa,CACzB,CAAC;AACJ,CAAC;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;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,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B,EAAE,GAAG,qBAAqB,CAAC;QACrD,MAAM,cAAc,GAAG,kBAAkB,CAAC,UAAU,CAAC,IAAI,CAAC;QAC1D,MAAM,EAAE,OAAO,EAAE,GAAG,kBAAkB,CAAC;QAEvC,MAAM,8BAA8B,GAClC,uBAAA,IAAI,wGAA+B,MAAnC,IAAI,EAAgC,qBAAqB,CAAC,CAAC;QAE7D,QAAQ,cAAc,EAAE,CAAC;YACvB,KAAK,qBAAqB,CAAC;YAC3B,KAAK,uBAAuB,CAAC;YAC7B,KAAK,oBAAoB,CAAC;YAC1B,KAAK,sBAAsB;gBACzB,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;oBAClD,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBACpD,CAAC;gBAGC,mBAAmB,CAAC,cAAc,CAAC,CACjC,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;YACR;gBACE,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBACxC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBAC1C,CAAC;gBAGC,mBAAmB,CAAC,KAAK,CACvB,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;QACV,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,sBAAsB,EAAE,EAAE;QAC1B,KAAK,EAAE,EAAE;KACa,CACzB,CAAC;AACJ,CAAC;kBAxQkB,0BAA0B","sourcesContent":["import type { Signer } from '@metamask/7715-permission-types';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\n\nimport type { DecodedPermission } from './decodePermission';\nimport {\n getPermissionDataAndExpiry,\n identifyPermissionByEnforcers,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsNotEnabledError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport { controllerLog } from './logger';\nimport type { StoredGatorPermissionSanitized } from './types';\nimport {\n GatorPermissionsSnapRpcMethod,\n type GatorPermissionsMap,\n type PermissionTypesWithCustom,\n type StoredGatorPermission,\n type DelegationDetails,\n type RevocationParams,\n type PendingRevocationParams,\n} from './types';\nimport {\n deserializeGatorPermissionsMap,\n serializeGatorPermissionsMap,\n} from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst defaultGatorPermissionsMap: GatorPermissionsMap = {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n};\n\n/**\n * Delegation framework version used to select the correct deployed enforcer\n * contract addresses from `@metamask/delegation-deployments`.\n */\nexport const DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === STATE ===\n\n/**\n * State shape for GatorPermissionsController\n */\nexport type GatorPermissionsControllerState = {\n /**\n * Flag that indicates if the gator permissions feature is enabled\n */\n isGatorPermissionsEnabled: boolean;\n\n /**\n * JSON serialized object containing gator permissions fetched from profile sync\n */\n gatorPermissionsMapSerialized: string;\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This is used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * The ID of the Snap of the gator permissions provider snap\n * Default value is `@metamask/gator-permissions-snap`\n */\n gatorPermissionsProviderSnapId: SnapId;\n\n /**\n * List of gator permission pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n isGatorPermissionsEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsMapSerialized: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsProviderSnapId: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Constructs the default {@link GatorPermissionsController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link GatorPermissionsController} state.\n */\nexport function getDefaultGatorPermissionsControllerState(): GatorPermissionsControllerState {\n return {\n isGatorPermissionsEnabled: false,\n gatorPermissionsMapSerialized: serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n ),\n isFetchingGatorPermissions: false,\n gatorPermissionsProviderSnapId: defaultGatorPermissionsProviderSnapId,\n pendingRevocations: [],\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * The action which can be used to fetch and update gator permissions.\n */\nexport type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {\n type: `${typeof controllerName}:fetchAndUpdateGatorPermissions`;\n handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];\n};\n\n/**\n * The action which can be used to enable gator permissions.\n */\nexport type GatorPermissionsControllerEnableGatorPermissionsAction = {\n type: `${typeof controllerName}:enableGatorPermissions`;\n handler: GatorPermissionsController['enableGatorPermissions'];\n};\n\n/**\n * The action which can be used to disable gator permissions.\n */\nexport type GatorPermissionsControllerDisableGatorPermissionsAction = {\n type: `${typeof controllerName}:disableGatorPermissions`;\n handler: GatorPermissionsController['disableGatorPermissions'];\n};\n\nexport type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction =\n {\n type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;\n handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];\n };\n\n/**\n * The action which can be used to submit a revocation.\n */\nexport type GatorPermissionsControllerSubmitRevocationAction = {\n type: `${typeof controllerName}:submitRevocation`;\n handler: GatorPermissionsController['submitRevocation'];\n};\n\n/**\n * The action which can be used to add a pending revocation.\n */\nexport type GatorPermissionsControllerAddPendingRevocationAction = {\n type: `${typeof controllerName}:addPendingRevocation`;\n handler: GatorPermissionsController['addPendingRevocation'];\n};\n\n/**\n * The action which can be used to submit a revocation directly without requiring\n * an on-chain transaction (for already-disabled delegations).\n */\nexport type GatorPermissionsControllerSubmitDirectRevocationAction = {\n type: `${typeof controllerName}:submitDirectRevocation`;\n handler: GatorPermissionsController['submitDirectRevocation'];\n};\n\n/**\n * The action which can be used to check if a permission context is pending revocation.\n */\nexport type GatorPermissionsControllerIsPendingRevocationAction = {\n type: `${typeof controllerName}:isPendingRevocation`;\n handler: GatorPermissionsController['isPendingRevocation'];\n};\n\n/**\n * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction\n | GatorPermissionsControllerEnableGatorPermissionsAction\n | GatorPermissionsControllerDisableGatorPermissionsAction\n | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapsController:handleRequest and SnapsController:has are allowed to be called\n * internally because they are used to fetch gator permissions from the Snap.\n */\ntype AllowedActions = HandleSnapRequest | HasSnap;\n\n/**\n * The event that {@link GatorPermissionsController} publishes when updating state.\n */\nexport type GatorPermissionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n GatorPermissionsControllerState\n >;\n\n/**\n * All events that {@link GatorPermissionsController} publishes, to be subscribed to\n * externally.\n */\nexport type GatorPermissionsControllerEvents =\n GatorPermissionsControllerStateChangeEvent;\n\n/**\n * Events that {@link GatorPermissionsController} is allowed to subscribe to internally.\n */\ntype AllowedEvents =\n | GatorPermissionsControllerStateChangeEvent\n | TransactionControllerTransactionApprovedEvent\n | TransactionControllerTransactionRejectedEvent\n | TransactionControllerTransactionConfirmedEvent\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionDroppedEvent;\n\n/**\n * Messenger type for the GatorPermissionsController.\n */\nexport type GatorPermissionsControllerMessenger = Messenger<\n typeof controllerName,\n GatorPermissionsControllerActions | AllowedActions,\n GatorPermissionsControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that manages gator permissions by reading from profile sync\n */\nexport default class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: {\n ...getDefaultGatorPermissionsControllerState(),\n ...state,\n isFetchingGatorPermissions: false,\n },\n });\n\n this.#registerMessageHandlers();\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean) {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #setIsGatorPermissionsEnabled(isGatorPermissionsEnabled: boolean) {\n this.update((state) => {\n state.isGatorPermissionsEnabled = isGatorPermissionsEnabled;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchAndUpdateGatorPermissions`,\n this.fetchAndUpdateGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:enableGatorPermissions`,\n this.enableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:disableGatorPermissions`,\n this.disableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:decodePermissionFromPermissionContextForOrigin`,\n this.decodePermissionFromPermissionContextForOrigin.bind(this),\n );\n\n const submitRevocationAction = `${controllerName}:submitRevocation`;\n\n this.messenger.registerActionHandler(\n submitRevocationAction,\n this.submitRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:addPendingRevocation`,\n this.addPendingRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitDirectRevocation`,\n this.submitDirectRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:isPendingRevocation`,\n this.isPendingRevocation.bind(this),\n );\n }\n\n /**\n * Asserts that the gator permissions are enabled.\n *\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n */\n #assertGatorPermissionsEnabled() {\n if (!this.state.isGatorPermissionsEnabled) {\n throw new GatorPermissionsNotEnabledError();\n }\n }\n\n /**\n * Forwards a Snap request to the SnapController.\n *\n * @param args - The request parameters.\n * @param args.snapId - The ID of the Snap of the gator permissions provider snap.\n * @param args.params - Optional parameters to pass to the snap method.\n * @returns A promise that resolves with the gator permissions.\n */\n async #handleSnapRequestToGatorPermissionsProvider({\n snapId,\n params,\n }: {\n snapId: SnapId;\n params?: Json;\n }): Promise<\n StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null\n > {\n try {\n const response = (await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n ...(params !== undefined && { params }),\n },\n },\n )) as StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null;\n\n return response;\n } catch (error) {\n controllerLog(\n 'Failed to handle snap request to gator permissions provider',\n error,\n );\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n cause: error as Error,\n });\n }\n }\n\n /**\n * Sanitizes a stored gator permission by removing the fields that are not expose to MetaMask client.\n *\n * @param storedGatorPermission - The stored gator permission to sanitize.\n * @returns The sanitized stored gator permission.\n */\n #sanitizeStoredGatorPermission(\n storedGatorPermission: StoredGatorPermission<\n Signer,\n PermissionTypesWithCustom\n >,\n ): StoredGatorPermissionSanitized<Signer, PermissionTypesWithCustom> {\n const { permissionResponse } = storedGatorPermission;\n const { rules, dependencyInfo, signer, ...rest } = permissionResponse;\n return {\n ...storedGatorPermission,\n permissionResponse: {\n ...rest,\n },\n };\n }\n\n /**\n * Categorizes stored gator permissions by type and chainId.\n *\n * @param storedGatorPermissions - An array of stored gator permissions.\n * @returns The gator permissions map.\n */\n #categorizePermissionsDataByTypeAndChainId(\n storedGatorPermissions:\n | StoredGatorPermission<Signer, PermissionTypesWithCustom>[]\n | null,\n ): GatorPermissionsMap {\n if (!storedGatorPermissions) {\n return defaultGatorPermissionsMap;\n }\n\n return storedGatorPermissions.reduce(\n (gatorPermissionsMap, storedGatorPermission) => {\n const { permissionResponse } = storedGatorPermission;\n const permissionType = permissionResponse.permission.type;\n const { chainId } = permissionResponse;\n\n const sanitizedStoredGatorPermission =\n this.#sanitizeStoredGatorPermission(storedGatorPermission);\n\n switch (permissionType) {\n case 'native-token-stream':\n case 'native-token-periodic':\n case 'erc20-token-stream':\n case 'erc20-token-periodic':\n if (!gatorPermissionsMap[permissionType][chainId]) {\n gatorPermissionsMap[permissionType][chainId] = [];\n }\n\n (\n gatorPermissionsMap[permissionType][\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n default:\n if (!gatorPermissionsMap.other[chainId]) {\n gatorPermissionsMap.other[chainId] = [];\n }\n\n (\n gatorPermissionsMap.other[\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n }\n\n return gatorPermissionsMap;\n },\n {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n } as GatorPermissionsMap,\n );\n }\n\n /**\n * Gets the gator permissions map from the state.\n *\n * @returns The gator permissions map.\n */\n get gatorPermissionsMap(): GatorPermissionsMap {\n return deserializeGatorPermissionsMap(\n this.state.gatorPermissionsMapSerialized,\n );\n }\n\n /**\n * Gets the gator permissions provider snap id that is used to fetch gator permissions.\n *\n * @returns The gator permissions provider snap id.\n */\n get permissionsProviderSnapId(): SnapId {\n return this.state.gatorPermissionsProviderSnapId;\n }\n\n /**\n * Enables gator permissions for the user.\n */\n public async enableGatorPermissions() {\n this.#setIsGatorPermissionsEnabled(true);\n }\n\n /**\n * Clears the gator permissions map and disables the feature.\n */\n public async disableGatorPermissions() {\n this.update((state) => {\n state.isGatorPermissionsEnabled = false;\n state.gatorPermissionsMapSerialized = serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n );\n });\n }\n\n /**\n * Gets the pending revocations list.\n *\n * @returns The pending revocations list.\n */\n get pendingRevocations(): { txId: string; permissionContext: Hex }[] {\n return this.state.pendingRevocations;\n }\n\n /**\n * Fetches the gator permissions from profile sync and updates the state.\n *\n * @param params - Optional parameters to pass to the snap's getGrantedPermissions method.\n * @returns A promise that resolves to the gator permissions map.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public async fetchAndUpdateGatorPermissions(\n params?: Json,\n ): Promise<GatorPermissionsMap> {\n try {\n this.#setIsFetchingGatorPermissions(true);\n this.#assertGatorPermissionsEnabled();\n\n const permissionsData =\n await this.#handleSnapRequestToGatorPermissionsProvider({\n snapId: this.state.gatorPermissionsProviderSnapId,\n params,\n });\n\n const gatorPermissionsMap =\n this.#categorizePermissionsDataByTypeAndChainId(permissionsData);\n\n this.update((state) => {\n state.gatorPermissionsMapSerialized =\n serializeGatorPermissionsMap(gatorPermissionsMap);\n });\n\n return gatorPermissionsMap;\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, signer, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.permissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n\n const permissionType = identifyPermissionByEnforcers({\n enforcers,\n contracts,\n });\n\n const { expiry, data } = getPermissionDataAndExpiry({\n contracts,\n caveats,\n permissionType,\n });\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n const snapRequest = {\n snapId: this.state.gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions({ isRevoked: false });\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to refresh permissions after transaction state change\n const refreshPermissions = (context: string) => {\n this.fetchAndUpdateGatorPermissions({ isRevoked: false }).catch(\n (error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n },\n );\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = () => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true) => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta) => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n });\n\n this.submitRevocation({ permissionContext })\n .catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n })\n .finally(() => refreshPermissions('transaction confirmed'));\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction failed');\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction dropped');\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n this.#assertGatorPermissionsEnabled();\n\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n permissionContext.toLowerCase(),\n );\n }\n}\n"]}
|
|
@@ -96,11 +96,26 @@ export type GatorPermissionsControllerAddPendingRevocationAction = {
|
|
|
96
96
|
type: `${typeof controllerName}:addPendingRevocation`;
|
|
97
97
|
handler: GatorPermissionsController['addPendingRevocation'];
|
|
98
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* The action which can be used to submit a revocation directly without requiring
|
|
101
|
+
* an on-chain transaction (for already-disabled delegations).
|
|
102
|
+
*/
|
|
103
|
+
export type GatorPermissionsControllerSubmitDirectRevocationAction = {
|
|
104
|
+
type: `${typeof controllerName}:submitDirectRevocation`;
|
|
105
|
+
handler: GatorPermissionsController['submitDirectRevocation'];
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* The action which can be used to check if a permission context is pending revocation.
|
|
109
|
+
*/
|
|
110
|
+
export type GatorPermissionsControllerIsPendingRevocationAction = {
|
|
111
|
+
type: `${typeof controllerName}:isPendingRevocation`;
|
|
112
|
+
handler: GatorPermissionsController['isPendingRevocation'];
|
|
113
|
+
};
|
|
99
114
|
/**
|
|
100
115
|
* All actions that {@link GatorPermissionsController} registers, to be called
|
|
101
116
|
* externally.
|
|
102
117
|
*/
|
|
103
|
-
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerEnableGatorPermissionsAction | GatorPermissionsControllerDisableGatorPermissionsAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | GatorPermissionsControllerSubmitRevocationAction | GatorPermissionsControllerAddPendingRevocationAction;
|
|
118
|
+
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerEnableGatorPermissionsAction | GatorPermissionsControllerDisableGatorPermissionsAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | GatorPermissionsControllerSubmitRevocationAction | GatorPermissionsControllerAddPendingRevocationAction | GatorPermissionsControllerSubmitDirectRevocationAction | GatorPermissionsControllerIsPendingRevocationAction;
|
|
104
119
|
/**
|
|
105
120
|
* All actions that {@link GatorPermissionsController} calls internally.
|
|
106
121
|
*
|
|
@@ -234,6 +249,29 @@ export default class GatorPermissionsController extends BaseController<typeof co
|
|
|
234
249
|
* @returns A promise that resolves when the listener is set up.
|
|
235
250
|
*/
|
|
236
251
|
addPendingRevocation(params: PendingRevocationParams): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Submits a revocation directly without requiring an on-chain transaction.
|
|
254
|
+
* Used for already-disabled delegations that don't require an on-chain transaction.
|
|
255
|
+
*
|
|
256
|
+
* This method:
|
|
257
|
+
* 1. Adds the permission context to pending revocations state (disables UI button)
|
|
258
|
+
* 2. Immediately calls submitRevocation to remove from snap storage
|
|
259
|
+
* 3. On success, removes from pending revocations state (re-enables UI button)
|
|
260
|
+
* 4. On failure, keeps in pending revocations so UI can show error/retry state
|
|
261
|
+
*
|
|
262
|
+
* @param params - The revocation parameters containing the permission context.
|
|
263
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
264
|
+
* @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.
|
|
265
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
266
|
+
*/
|
|
267
|
+
submitDirectRevocation(params: RevocationParams): Promise<void>;
|
|
268
|
+
/**
|
|
269
|
+
* Checks if a permission context is in the pending revocations list.
|
|
270
|
+
*
|
|
271
|
+
* @param permissionContext - The permission context to check.
|
|
272
|
+
* @returns `true` if the permission context is pending revocation, `false` otherwise.
|
|
273
|
+
*/
|
|
274
|
+
isPendingRevocation(permissionContext: Hex): boolean;
|
|
237
275
|
}
|
|
238
276
|
export {};
|
|
239
277
|
//# sourceMappingURL=GatorPermissionsController.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatorPermissionsController.d.cts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,oCAAoC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,KAAK,EACV,6CAA6C,EAC7C,8CAA8C,EAC9C,4CAA4C,EAC5C,2CAA2C,EAC3C,6CAA6C,EAC9C,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,wBAAwB;AAEjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAA2B;AAe5D,OAAO,EAEL,KAAK,mBAAmB,EAGxB,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC7B,oBAAgB;AASjB,QAAA,MAAM,cAAc,+BAA+B,CAAC;AAcpD;;;GAGG;AACH,eAAO,MAAM,4BAA4B,UAAU,CAAC;AAYpD;;GAEG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C;;OAEG;IACH,yBAAyB,EAAE,OAAO,CAAC;IAEnC;;OAEG;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E,GAAG,GAAG,OAAO;CAO5D"}
|
|
@@ -96,11 +96,26 @@ export type GatorPermissionsControllerAddPendingRevocationAction = {
|
|
|
96
96
|
type: `${typeof controllerName}:addPendingRevocation`;
|
|
97
97
|
handler: GatorPermissionsController['addPendingRevocation'];
|
|
98
98
|
};
|
|
99
|
+
/**
|
|
100
|
+
* The action which can be used to submit a revocation directly without requiring
|
|
101
|
+
* an on-chain transaction (for already-disabled delegations).
|
|
102
|
+
*/
|
|
103
|
+
export type GatorPermissionsControllerSubmitDirectRevocationAction = {
|
|
104
|
+
type: `${typeof controllerName}:submitDirectRevocation`;
|
|
105
|
+
handler: GatorPermissionsController['submitDirectRevocation'];
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* The action which can be used to check if a permission context is pending revocation.
|
|
109
|
+
*/
|
|
110
|
+
export type GatorPermissionsControllerIsPendingRevocationAction = {
|
|
111
|
+
type: `${typeof controllerName}:isPendingRevocation`;
|
|
112
|
+
handler: GatorPermissionsController['isPendingRevocation'];
|
|
113
|
+
};
|
|
99
114
|
/**
|
|
100
115
|
* All actions that {@link GatorPermissionsController} registers, to be called
|
|
101
116
|
* externally.
|
|
102
117
|
*/
|
|
103
|
-
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerEnableGatorPermissionsAction | GatorPermissionsControllerDisableGatorPermissionsAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | GatorPermissionsControllerSubmitRevocationAction | GatorPermissionsControllerAddPendingRevocationAction;
|
|
118
|
+
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerEnableGatorPermissionsAction | GatorPermissionsControllerDisableGatorPermissionsAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | GatorPermissionsControllerSubmitRevocationAction | GatorPermissionsControllerAddPendingRevocationAction | GatorPermissionsControllerSubmitDirectRevocationAction | GatorPermissionsControllerIsPendingRevocationAction;
|
|
104
119
|
/**
|
|
105
120
|
* All actions that {@link GatorPermissionsController} calls internally.
|
|
106
121
|
*
|
|
@@ -234,6 +249,29 @@ export default class GatorPermissionsController extends BaseController<typeof co
|
|
|
234
249
|
* @returns A promise that resolves when the listener is set up.
|
|
235
250
|
*/
|
|
236
251
|
addPendingRevocation(params: PendingRevocationParams): Promise<void>;
|
|
252
|
+
/**
|
|
253
|
+
* Submits a revocation directly without requiring an on-chain transaction.
|
|
254
|
+
* Used for already-disabled delegations that don't require an on-chain transaction.
|
|
255
|
+
*
|
|
256
|
+
* This method:
|
|
257
|
+
* 1. Adds the permission context to pending revocations state (disables UI button)
|
|
258
|
+
* 2. Immediately calls submitRevocation to remove from snap storage
|
|
259
|
+
* 3. On success, removes from pending revocations state (re-enables UI button)
|
|
260
|
+
* 4. On failure, keeps in pending revocations so UI can show error/retry state
|
|
261
|
+
*
|
|
262
|
+
* @param params - The revocation parameters containing the permission context.
|
|
263
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
264
|
+
* @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.
|
|
265
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
266
|
+
*/
|
|
267
|
+
submitDirectRevocation(params: RevocationParams): Promise<void>;
|
|
268
|
+
/**
|
|
269
|
+
* Checks if a permission context is in the pending revocations list.
|
|
270
|
+
*
|
|
271
|
+
* @param permissionContext - The permission context to check.
|
|
272
|
+
* @returns `true` if the permission context is pending revocation, `false` otherwise.
|
|
273
|
+
*/
|
|
274
|
+
isPendingRevocation(permissionContext: Hex): boolean;
|
|
237
275
|
}
|
|
238
276
|
export {};
|
|
239
277
|
//# sourceMappingURL=GatorPermissionsController.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatorPermissionsController.d.mts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AAC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E,IAAI,EAAE,GAAG,OAAO,cAAc,iCAAiC,CAAC;IAChE,OAAO,EAAE,0BAA0B,CAAC,gCAAgC,CAAC,CAAC;CACvE,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,sDAAsD,GAAG;IACnE,IAAI,EAAE,GAAG,OAAO,cAAc,yBAAyB,CAAC;IACxD,OAAO,EAAE,0BAA0B,CAAC,wBAAwB,CAAC,CAAC;CAC/D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uDAAuD,GAAG;IACpE,IAAI,EAAE,GAAG,OAAO,cAAc,0BAA0B,CAAC;IACzD,OAAO,EAAE,0BAA0B,CAAC,yBAAyB,CAAC,CAAC;CAChE,CAAC;AAEF,MAAM,MAAM,8EAA8E,GACxF;IACE,IAAI,EAAE,GAAG,OAAO,cAAc,iDAAiD,CAAC;IAChF,OAAO,EAAE,0BAA0B,CAAC,gDAAgD,CAAC,CAAC;CACvF,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,GAAG,OAAO,cAAc,mBAAmB,CAAC;IAClD,OAAO,EAAE,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACzD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,GAAG,OAAO,cAAc,uBAAuB,CAAC;IACtD,OAAO,EAAE,0BAA0B,CAAC,sBAAsB,CAAC,CAAC;CAC7D,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,iCAAiC,GACzC,wCAAwC,GACxC,8DAA8D,GAC9D,sDAAsD,GACtD,uDAAuD,GACvD,8EAA8E,GAC9E,gDAAgD,GAChD,oDAAoD,CAAC;
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController.d.mts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EA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B;;;;;;;;;;;;;;;;;;;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;IA6CrB;;;;;;;OAOG;IACU,gBAAgB,CAC3B,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,IAAI,CAAC;IAoEhB;;;;;;;;;;;;;;;;OAgBG;IACU,oBAAoB,CAC/B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,IAAI,CAAC;IA4NhB;;;;;;;;;;;;;;OAcG;IACU,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAgB5E;;;;;OAKG;IACI,mBAAmB,CAAC,iBAAiB,EAAE,GAAG,GAAG,OAAO;CAO5D"}
|
|
@@ -252,25 +252,39 @@ class GatorPermissionsController extends BaseController {
|
|
|
252
252
|
permissionContext: revocationParams.permissionContext,
|
|
253
253
|
});
|
|
254
254
|
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_assertGatorPermissionsEnabled).call(this);
|
|
255
|
+
const snapRequest = {
|
|
256
|
+
snapId: this.state.gatorPermissionsProviderSnapId,
|
|
257
|
+
origin: 'metamask',
|
|
258
|
+
handler: HandlerType.OnRpcRequest,
|
|
259
|
+
request: {
|
|
260
|
+
jsonrpc: '2.0',
|
|
261
|
+
method: GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,
|
|
262
|
+
params: revocationParams,
|
|
263
|
+
},
|
|
264
|
+
};
|
|
255
265
|
try {
|
|
256
|
-
const snapRequest = {
|
|
257
|
-
snapId: this.state.gatorPermissionsProviderSnapId,
|
|
258
|
-
origin: 'metamask',
|
|
259
|
-
handler: HandlerType.OnRpcRequest,
|
|
260
|
-
request: {
|
|
261
|
-
jsonrpc: '2.0',
|
|
262
|
-
method: GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,
|
|
263
|
-
params: revocationParams,
|
|
264
|
-
},
|
|
265
|
-
};
|
|
266
266
|
const result = await this.messenger.call('SnapController:handleRequest', snapRequest);
|
|
267
|
-
|
|
267
|
+
// Refresh list first (permission removed from list)
|
|
268
|
+
await this.fetchAndUpdateGatorPermissions({ isRevoked: false });
|
|
268
269
|
controllerLog('Successfully submitted revocation', {
|
|
269
270
|
permissionContext: revocationParams.permissionContext,
|
|
270
271
|
result,
|
|
271
272
|
});
|
|
272
273
|
}
|
|
273
274
|
catch (error) {
|
|
275
|
+
// If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed
|
|
276
|
+
if (error instanceof GatorPermissionsFetchError) {
|
|
277
|
+
controllerLog('Revocation submitted successfully but failed to refresh permissions list', {
|
|
278
|
+
error,
|
|
279
|
+
permissionContext: revocationParams.permissionContext,
|
|
280
|
+
});
|
|
281
|
+
// Wrap with a more specific message indicating revocation succeeded
|
|
282
|
+
throw new GatorPermissionsFetchError({
|
|
283
|
+
message: 'Failed to refresh permissions list after successful revocation',
|
|
284
|
+
cause: error,
|
|
285
|
+
});
|
|
286
|
+
}
|
|
287
|
+
// Otherwise, revocation failed - wrap in provider error
|
|
274
288
|
controllerLog('Failed to submit revocation', {
|
|
275
289
|
error,
|
|
276
290
|
permissionContext: revocationParams.permissionContext,
|
|
@@ -280,6 +294,9 @@ class GatorPermissionsController extends BaseController {
|
|
|
280
294
|
cause: error,
|
|
281
295
|
});
|
|
282
296
|
}
|
|
297
|
+
finally {
|
|
298
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext).call(this, revocationParams.permissionContext);
|
|
299
|
+
}
|
|
283
300
|
}
|
|
284
301
|
/**
|
|
285
302
|
* Adds a pending revocation that will be submitted once the transaction is confirmed.
|
|
@@ -314,6 +331,16 @@ class GatorPermissionsController extends BaseController {
|
|
|
314
331
|
dropped: undefined,
|
|
315
332
|
timeoutId: undefined,
|
|
316
333
|
};
|
|
334
|
+
// Helper to refresh permissions after transaction state change
|
|
335
|
+
const refreshPermissions = (context) => {
|
|
336
|
+
this.fetchAndUpdateGatorPermissions({ isRevoked: false }).catch((error) => {
|
|
337
|
+
controllerLog(`Failed to refresh permissions after ${context}`, {
|
|
338
|
+
txId,
|
|
339
|
+
permissionContext,
|
|
340
|
+
error,
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
};
|
|
317
344
|
// Helper to unsubscribe from approval/rejection events after decision is made
|
|
318
345
|
const cleanupApprovalHandlers = () => {
|
|
319
346
|
if (handlers.approved) {
|
|
@@ -375,13 +402,15 @@ class GatorPermissionsController extends BaseController {
|
|
|
375
402
|
txId,
|
|
376
403
|
permissionContext,
|
|
377
404
|
});
|
|
378
|
-
this.submitRevocation({ permissionContext })
|
|
405
|
+
this.submitRevocation({ permissionContext })
|
|
406
|
+
.catch((error) => {
|
|
379
407
|
controllerLog('Failed to submit revocation after transaction confirmed', {
|
|
380
408
|
txId,
|
|
381
409
|
permissionContext,
|
|
382
410
|
error,
|
|
383
411
|
});
|
|
384
|
-
})
|
|
412
|
+
})
|
|
413
|
+
.finally(() => refreshPermissions('transaction confirmed'));
|
|
385
414
|
cleanup(transactionMeta.id);
|
|
386
415
|
}
|
|
387
416
|
};
|
|
@@ -394,6 +423,7 @@ class GatorPermissionsController extends BaseController {
|
|
|
394
423
|
error: payload.error,
|
|
395
424
|
});
|
|
396
425
|
cleanup(payload.transactionMeta.id);
|
|
426
|
+
refreshPermissions('transaction failed');
|
|
397
427
|
}
|
|
398
428
|
};
|
|
399
429
|
// Handle dropped transaction - cleanup without submitting revocation
|
|
@@ -404,6 +434,7 @@ class GatorPermissionsController extends BaseController {
|
|
|
404
434
|
permissionContext,
|
|
405
435
|
});
|
|
406
436
|
cleanup(payload.transactionMeta.id);
|
|
437
|
+
refreshPermissions('transaction dropped');
|
|
407
438
|
}
|
|
408
439
|
};
|
|
409
440
|
// Subscribe to user approval/rejection events
|
|
@@ -422,6 +453,40 @@ class GatorPermissionsController extends BaseController {
|
|
|
422
453
|
cleanup(txId);
|
|
423
454
|
}, PENDING_REVOCATION_TIMEOUT);
|
|
424
455
|
}
|
|
456
|
+
/**
|
|
457
|
+
* Submits a revocation directly without requiring an on-chain transaction.
|
|
458
|
+
* Used for already-disabled delegations that don't require an on-chain transaction.
|
|
459
|
+
*
|
|
460
|
+
* This method:
|
|
461
|
+
* 1. Adds the permission context to pending revocations state (disables UI button)
|
|
462
|
+
* 2. Immediately calls submitRevocation to remove from snap storage
|
|
463
|
+
* 3. On success, removes from pending revocations state (re-enables UI button)
|
|
464
|
+
* 4. On failure, keeps in pending revocations so UI can show error/retry state
|
|
465
|
+
*
|
|
466
|
+
* @param params - The revocation parameters containing the permission context.
|
|
467
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
468
|
+
* @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.
|
|
469
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
470
|
+
*/
|
|
471
|
+
async submitDirectRevocation(params) {
|
|
472
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_assertGatorPermissionsEnabled).call(this);
|
|
473
|
+
// Use a placeholder txId that doesn't conflict with real transaction IDs
|
|
474
|
+
const placeholderTxId = `no-tx-${params.permissionContext}`;
|
|
475
|
+
// Add to pending revocations state first (disables UI button immediately)
|
|
476
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_addPendingRevocationToState).call(this, placeholderTxId, params.permissionContext);
|
|
477
|
+
// Immediately submit the revocation (will remove from pending on success)
|
|
478
|
+
await this.submitRevocation(params);
|
|
479
|
+
}
|
|
480
|
+
/**
|
|
481
|
+
* Checks if a permission context is in the pending revocations list.
|
|
482
|
+
*
|
|
483
|
+
* @param permissionContext - The permission context to check.
|
|
484
|
+
* @returns `true` if the permission context is pending revocation, `false` otherwise.
|
|
485
|
+
*/
|
|
486
|
+
isPendingRevocation(permissionContext) {
|
|
487
|
+
return this.state.pendingRevocations.some((pendingRevocation) => pendingRevocation.permissionContext.toLowerCase() ===
|
|
488
|
+
permissionContext.toLowerCase());
|
|
489
|
+
}
|
|
425
490
|
}
|
|
426
491
|
_GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsController_setIsFetchingGatorPermissions = function _GatorPermissionsController_setIsFetchingGatorPermissions(isFetchingGatorPermissions) {
|
|
427
492
|
this.update((state) => {
|
|
@@ -444,7 +509,8 @@ _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsControll
|
|
|
444
509
|
});
|
|
445
510
|
}, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext = function _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext(permissionContext) {
|
|
446
511
|
this.update((state) => {
|
|
447
|
-
state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext !==
|
|
512
|
+
state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext.toLowerCase() !==
|
|
513
|
+
permissionContext.toLowerCase());
|
|
448
514
|
});
|
|
449
515
|
}, _GatorPermissionsController_registerMessageHandlers = function _GatorPermissionsController_registerMessageHandlers() {
|
|
450
516
|
this.messenger.registerActionHandler(`${controllerName}:fetchAndUpdateGatorPermissions`, this.fetchAndUpdateGatorPermissions.bind(this));
|
|
@@ -454,6 +520,8 @@ _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsControll
|
|
|
454
520
|
const submitRevocationAction = `${controllerName}:submitRevocation`;
|
|
455
521
|
this.messenger.registerActionHandler(submitRevocationAction, this.submitRevocation.bind(this));
|
|
456
522
|
this.messenger.registerActionHandler(`${controllerName}:addPendingRevocation`, this.addPendingRevocation.bind(this));
|
|
523
|
+
this.messenger.registerActionHandler(`${controllerName}:submitDirectRevocation`, this.submitDirectRevocation.bind(this));
|
|
524
|
+
this.messenger.registerActionHandler(`${controllerName}:isPendingRevocation`, this.isPendingRevocation.bind(this));
|
|
457
525
|
}, _GatorPermissionsController_assertGatorPermissionsEnabled = function _GatorPermissionsController_assertGatorPermissionsEnabled() {
|
|
458
526
|
if (!this.state.isGatorPermissionsEnabled) {
|
|
459
527
|
throw new GatorPermissionsNotEnabledError();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatorPermissionsController.mjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAIvE,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAWpD,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC7B,qCAA2B;AAC5B,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,6BAA6B,EAC7B,qBAAqB,EACrB,uBAAuB,EACxB,qBAAiB;AAClB,OAAO,EAAE,aAAa,EAAE,qBAAiB;AAEzC,OAAO,EACL,6BAA6B,EAO9B,oBAAgB;AACjB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC7B,oBAAgB;AAEjB,kBAAkB;AAElB,iCAAiC;AACjC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,2DAA2D;AAC3D,MAAM,qCAAqC,GACzC,sCAAgD,CAAC;AAEnD,MAAM,0BAA0B,GAAwB;IACtD,qBAAqB,EAAE,EAAE;IACzB,uBAAuB,EAAE,EAAE;IAC3B,oBAAoB,EAAE,EAAE;IACxB,sBAAsB,EAAE,EAAE;IAC1B,K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ACxC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBAC1C,CAAC;gBAGC,mBAAmB,CAAC,KAAK,CACvB,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;QACV,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,sBAAsB,EAAE,EAAE;QAC1B,KAAK,EAAE,EAAE;KACa,CACzB,CAAC;AACJ,CAAC;eA7PkB,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.mjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;AAMA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAIvE,OAAO,EAAE,WAAW,EAAE,8BAA8B;AAWpD,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,4BAA4B,EAC7B,qCAA2B;AAC5B,OAAO,EACL,0BAA0B,EAC1B,+BAA+B,EAC/B,6BAA6B,EAC7B,qBAAqB,EACrB,uBAAuB,EACxB,qBAAiB;AAClB,OAAO,EAAE,aAAa,EAAE,qBAAiB;AAEzC,OAAO,EACL,6BAA6B,EAO9B,oBAAgB;AACjB,OAAO,EACL,8BAA8B,EAC9B,4BAA4B,EAC7B,oBAAgB;AAEjB,kBAAkB;AAElB,iCAAiC;AACjC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,2DAA2D;AAC3D,MAAM,qCAAqC,GACzC,sCAAgD,CAAC;AAEnD,MAAM,0BAA0B,GAAwB;IACtD,qBAAqB,EAAE,EAAE;IACzB,uBAAuB,EAAE,EAAE;IAC3B,oBAAoB,EAAE,EAAE;IACxB,sBAAsB,EAAE,EAAE;IAC1B,KAAK,EAAE,EAAE;CACV,CAAC;AAEF;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAEpD;;;GAGG;AACH,MAAM,0BAA0B,GAAG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AE7D,QAAQ,cAAc,EAAE,CAAC;YACvB,KAAK,qBAAqB,CAAC;YAC3B,KAAK,uBAAuB,CAAC;YAC7B,KAAK,oBAAoB,CAAC;YAC1B,KAAK,sBAAsB;gBACzB,IAAI,CAAC,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;oBAClD,mBAAmB,CAAC,cAAc,CAAC,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBACpD,CAAC;gBAGC,mBAAmB,CAAC,cAAc,CAAC,CACjC,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;YACR;gBACE,IAAI,CAAC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;oBACxC,mBAAmB,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC;gBAC1C,CAAC;gBAGC,mBAAmB,CAAC,KAAK,CACvB,OAAO,CAKV,CAAC,IAAI,CAAC,8BAA8B,CAAC,CAAC;gBACvC,MAAM;QACV,CAAC;QAED,OAAO,mBAAmB,CAAC;IAC7B,CAAC,EACD;QACE,qBAAqB,EAAE,EAAE;QACzB,uBAAuB,EAAE,EAAE;QAC3B,oBAAoB,EAAE,EAAE;QACxB,sBAAsB,EAAE,EAAE;QAC1B,KAAK,EAAE,EAAE;KACa,CACzB,CAAC;AACJ,CAAC;eAxQkB,0BAA0B","sourcesContent":["import type { Signer } from '@metamask/7715-permission-types';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex, Json } from '@metamask/utils';\n\nimport type { DecodedPermission } from './decodePermission';\nimport {\n getPermissionDataAndExpiry,\n identifyPermissionByEnforcers,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsNotEnabledError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport { controllerLog } from './logger';\nimport type { StoredGatorPermissionSanitized } from './types';\nimport {\n GatorPermissionsSnapRpcMethod,\n type GatorPermissionsMap,\n type PermissionTypesWithCustom,\n type StoredGatorPermission,\n type DelegationDetails,\n type RevocationParams,\n type PendingRevocationParams,\n} from './types';\nimport {\n deserializeGatorPermissionsMap,\n serializeGatorPermissionsMap,\n} from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst defaultGatorPermissionsMap: GatorPermissionsMap = {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n};\n\n/**\n * Delegation framework version used to select the correct deployed enforcer\n * contract addresses from `@metamask/delegation-deployments`.\n */\nexport const DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === STATE ===\n\n/**\n * State shape for GatorPermissionsController\n */\nexport type GatorPermissionsControllerState = {\n /**\n * Flag that indicates if the gator permissions feature is enabled\n */\n isGatorPermissionsEnabled: boolean;\n\n /**\n * JSON serialized object containing gator permissions fetched from profile sync\n */\n gatorPermissionsMapSerialized: string;\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This is used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * The ID of the Snap of the gator permissions provider snap\n * Default value is `@metamask/gator-permissions-snap`\n */\n gatorPermissionsProviderSnapId: SnapId;\n\n /**\n * List of gator permission pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n isGatorPermissionsEnabled: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsMapSerialized: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n gatorPermissionsProviderSnapId: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Constructs the default {@link GatorPermissionsController} state. This allows\n * consumers to provide a partial state object when initializing the controller\n * and also helps in constructing complete state objects for this controller in\n * tests.\n *\n * @returns The default {@link GatorPermissionsController} state.\n */\nexport function getDefaultGatorPermissionsControllerState(): GatorPermissionsControllerState {\n return {\n isGatorPermissionsEnabled: false,\n gatorPermissionsMapSerialized: serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n ),\n isFetchingGatorPermissions: false,\n gatorPermissionsProviderSnapId: defaultGatorPermissionsProviderSnapId,\n pendingRevocations: [],\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * The action which can be used to fetch and update gator permissions.\n */\nexport type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {\n type: `${typeof controllerName}:fetchAndUpdateGatorPermissions`;\n handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];\n};\n\n/**\n * The action which can be used to enable gator permissions.\n */\nexport type GatorPermissionsControllerEnableGatorPermissionsAction = {\n type: `${typeof controllerName}:enableGatorPermissions`;\n handler: GatorPermissionsController['enableGatorPermissions'];\n};\n\n/**\n * The action which can be used to disable gator permissions.\n */\nexport type GatorPermissionsControllerDisableGatorPermissionsAction = {\n type: `${typeof controllerName}:disableGatorPermissions`;\n handler: GatorPermissionsController['disableGatorPermissions'];\n};\n\nexport type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction =\n {\n type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;\n handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];\n };\n\n/**\n * The action which can be used to submit a revocation.\n */\nexport type GatorPermissionsControllerSubmitRevocationAction = {\n type: `${typeof controllerName}:submitRevocation`;\n handler: GatorPermissionsController['submitRevocation'];\n};\n\n/**\n * The action which can be used to add a pending revocation.\n */\nexport type GatorPermissionsControllerAddPendingRevocationAction = {\n type: `${typeof controllerName}:addPendingRevocation`;\n handler: GatorPermissionsController['addPendingRevocation'];\n};\n\n/**\n * The action which can be used to submit a revocation directly without requiring\n * an on-chain transaction (for already-disabled delegations).\n */\nexport type GatorPermissionsControllerSubmitDirectRevocationAction = {\n type: `${typeof controllerName}:submitDirectRevocation`;\n handler: GatorPermissionsController['submitDirectRevocation'];\n};\n\n/**\n * The action which can be used to check if a permission context is pending revocation.\n */\nexport type GatorPermissionsControllerIsPendingRevocationAction = {\n type: `${typeof controllerName}:isPendingRevocation`;\n handler: GatorPermissionsController['isPendingRevocation'];\n};\n\n/**\n * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction\n | GatorPermissionsControllerEnableGatorPermissionsAction\n | GatorPermissionsControllerDisableGatorPermissionsAction\n | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapsController:handleRequest and SnapsController:has are allowed to be called\n * internally because they are used to fetch gator permissions from the Snap.\n */\ntype AllowedActions = HandleSnapRequest | HasSnap;\n\n/**\n * The event that {@link GatorPermissionsController} publishes when updating state.\n */\nexport type GatorPermissionsControllerStateChangeEvent =\n ControllerStateChangeEvent<\n typeof controllerName,\n GatorPermissionsControllerState\n >;\n\n/**\n * All events that {@link GatorPermissionsController} publishes, to be subscribed to\n * externally.\n */\nexport type GatorPermissionsControllerEvents =\n GatorPermissionsControllerStateChangeEvent;\n\n/**\n * Events that {@link GatorPermissionsController} is allowed to subscribe to internally.\n */\ntype AllowedEvents =\n | GatorPermissionsControllerStateChangeEvent\n | TransactionControllerTransactionApprovedEvent\n | TransactionControllerTransactionRejectedEvent\n | TransactionControllerTransactionConfirmedEvent\n | TransactionControllerTransactionFailedEvent\n | TransactionControllerTransactionDroppedEvent;\n\n/**\n * Messenger type for the GatorPermissionsController.\n */\nexport type GatorPermissionsControllerMessenger = Messenger<\n typeof controllerName,\n GatorPermissionsControllerActions | AllowedActions,\n GatorPermissionsControllerEvents | AllowedEvents\n>;\n\n/**\n * Controller that manages gator permissions by reading from profile sync\n */\nexport default class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with BaseV2 controller.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: {\n ...getDefaultGatorPermissionsControllerState(),\n ...state,\n isFetchingGatorPermissions: false,\n },\n });\n\n this.#registerMessageHandlers();\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean) {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #setIsGatorPermissionsEnabled(isGatorPermissionsEnabled: boolean) {\n this.update((state) => {\n state.isGatorPermissionsEnabled = isGatorPermissionsEnabled;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(permissionContext: Hex) {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchAndUpdateGatorPermissions`,\n this.fetchAndUpdateGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:enableGatorPermissions`,\n this.enableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:disableGatorPermissions`,\n this.disableGatorPermissions.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:decodePermissionFromPermissionContextForOrigin`,\n this.decodePermissionFromPermissionContextForOrigin.bind(this),\n );\n\n const submitRevocationAction = `${controllerName}:submitRevocation`;\n\n this.messenger.registerActionHandler(\n submitRevocationAction,\n this.submitRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:addPendingRevocation`,\n this.addPendingRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:submitDirectRevocation`,\n this.submitDirectRevocation.bind(this),\n );\n\n this.messenger.registerActionHandler(\n `${controllerName}:isPendingRevocation`,\n this.isPendingRevocation.bind(this),\n );\n }\n\n /**\n * Asserts that the gator permissions are enabled.\n *\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n */\n #assertGatorPermissionsEnabled() {\n if (!this.state.isGatorPermissionsEnabled) {\n throw new GatorPermissionsNotEnabledError();\n }\n }\n\n /**\n * Forwards a Snap request to the SnapController.\n *\n * @param args - The request parameters.\n * @param args.snapId - The ID of the Snap of the gator permissions provider snap.\n * @param args.params - Optional parameters to pass to the snap method.\n * @returns A promise that resolves with the gator permissions.\n */\n async #handleSnapRequestToGatorPermissionsProvider({\n snapId,\n params,\n }: {\n snapId: SnapId;\n params?: Json;\n }): Promise<\n StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null\n > {\n try {\n const response = (await this.messenger.call(\n 'SnapController:handleRequest',\n {\n snapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n ...(params !== undefined && { params }),\n },\n },\n )) as StoredGatorPermission<Signer, PermissionTypesWithCustom>[] | null;\n\n return response;\n } catch (error) {\n controllerLog(\n 'Failed to handle snap request to gator permissions provider',\n error,\n );\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n cause: error as Error,\n });\n }\n }\n\n /**\n * Sanitizes a stored gator permission by removing the fields that are not expose to MetaMask client.\n *\n * @param storedGatorPermission - The stored gator permission to sanitize.\n * @returns The sanitized stored gator permission.\n */\n #sanitizeStoredGatorPermission(\n storedGatorPermission: StoredGatorPermission<\n Signer,\n PermissionTypesWithCustom\n >,\n ): StoredGatorPermissionSanitized<Signer, PermissionTypesWithCustom> {\n const { permissionResponse } = storedGatorPermission;\n const { rules, dependencyInfo, signer, ...rest } = permissionResponse;\n return {\n ...storedGatorPermission,\n permissionResponse: {\n ...rest,\n },\n };\n }\n\n /**\n * Categorizes stored gator permissions by type and chainId.\n *\n * @param storedGatorPermissions - An array of stored gator permissions.\n * @returns The gator permissions map.\n */\n #categorizePermissionsDataByTypeAndChainId(\n storedGatorPermissions:\n | StoredGatorPermission<Signer, PermissionTypesWithCustom>[]\n | null,\n ): GatorPermissionsMap {\n if (!storedGatorPermissions) {\n return defaultGatorPermissionsMap;\n }\n\n return storedGatorPermissions.reduce(\n (gatorPermissionsMap, storedGatorPermission) => {\n const { permissionResponse } = storedGatorPermission;\n const permissionType = permissionResponse.permission.type;\n const { chainId } = permissionResponse;\n\n const sanitizedStoredGatorPermission =\n this.#sanitizeStoredGatorPermission(storedGatorPermission);\n\n switch (permissionType) {\n case 'native-token-stream':\n case 'native-token-periodic':\n case 'erc20-token-stream':\n case 'erc20-token-periodic':\n if (!gatorPermissionsMap[permissionType][chainId]) {\n gatorPermissionsMap[permissionType][chainId] = [];\n }\n\n (\n gatorPermissionsMap[permissionType][\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n default:\n if (!gatorPermissionsMap.other[chainId]) {\n gatorPermissionsMap.other[chainId] = [];\n }\n\n (\n gatorPermissionsMap.other[\n chainId\n ] as StoredGatorPermissionSanitized<\n Signer,\n PermissionTypesWithCustom\n >[]\n ).push(sanitizedStoredGatorPermission);\n break;\n }\n\n return gatorPermissionsMap;\n },\n {\n 'native-token-stream': {},\n 'native-token-periodic': {},\n 'erc20-token-stream': {},\n 'erc20-token-periodic': {},\n other: {},\n } as GatorPermissionsMap,\n );\n }\n\n /**\n * Gets the gator permissions map from the state.\n *\n * @returns The gator permissions map.\n */\n get gatorPermissionsMap(): GatorPermissionsMap {\n return deserializeGatorPermissionsMap(\n this.state.gatorPermissionsMapSerialized,\n );\n }\n\n /**\n * Gets the gator permissions provider snap id that is used to fetch gator permissions.\n *\n * @returns The gator permissions provider snap id.\n */\n get permissionsProviderSnapId(): SnapId {\n return this.state.gatorPermissionsProviderSnapId;\n }\n\n /**\n * Enables gator permissions for the user.\n */\n public async enableGatorPermissions() {\n this.#setIsGatorPermissionsEnabled(true);\n }\n\n /**\n * Clears the gator permissions map and disables the feature.\n */\n public async disableGatorPermissions() {\n this.update((state) => {\n state.isGatorPermissionsEnabled = false;\n state.gatorPermissionsMapSerialized = serializeGatorPermissionsMap(\n defaultGatorPermissionsMap,\n );\n });\n }\n\n /**\n * Gets the pending revocations list.\n *\n * @returns The pending revocations list.\n */\n get pendingRevocations(): { txId: string; permissionContext: Hex }[] {\n return this.state.pendingRevocations;\n }\n\n /**\n * Fetches the gator permissions from profile sync and updates the state.\n *\n * @param params - Optional parameters to pass to the snap's getGrantedPermissions method.\n * @returns A promise that resolves to the gator permissions map.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public async fetchAndUpdateGatorPermissions(\n params?: Json,\n ): Promise<GatorPermissionsMap> {\n try {\n this.#setIsFetchingGatorPermissions(true);\n this.#assertGatorPermissionsEnabled();\n\n const permissionsData =\n await this.#handleSnapRequestToGatorPermissionsProvider({\n snapId: this.state.gatorPermissionsProviderSnapId,\n params,\n });\n\n const gatorPermissionsMap =\n this.#categorizePermissionsDataByTypeAndChainId(permissionsData);\n\n this.update((state) => {\n state.gatorPermissionsMapSerialized =\n serializeGatorPermissionsMap(gatorPermissionsMap);\n });\n\n return gatorPermissionsMap;\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, signer, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.permissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n\n const permissionType = identifyPermissionByEnforcers({\n enforcers,\n contracts,\n });\n\n const { expiry, data } = getPermissionDataAndExpiry({\n contracts,\n caveats,\n permissionType,\n });\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n const snapRequest = {\n snapId: this.state.gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions({ isRevoked: false });\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n this.#assertGatorPermissionsEnabled();\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to refresh permissions after transaction state change\n const refreshPermissions = (context: string) => {\n this.fetchAndUpdateGatorPermissions({ isRevoked: false }).catch(\n (error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n },\n );\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = () => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true) => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta) => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n });\n\n this.submitRevocation({ permissionContext })\n .catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n })\n .finally(() => refreshPermissions('transaction confirmed'));\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction failed');\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload) => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction dropped');\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n this.#assertGatorPermissionsEnabled();\n\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n permissionContext.toLowerCase(),\n );\n }\n}\n"]}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,+EAAqF;AAA5E,yJAAA,OAAO,OAA8B;AAC9C,qCAGiB;AAFf,qHAAA,4BAA4B,OAAA;AAC5B,uHAAA,8BAA8B,OAAA","sourcesContent":["export { default as GatorPermissionsController } from './GatorPermissionsController';\nexport {\n serializeGatorPermissionsMap,\n deserializeGatorPermissionsMap,\n} from './utils';\nexport type {\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger,\n GatorPermissionsControllerGetStateAction,\n GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction,\n GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction,\n GatorPermissionsControllerEnableGatorPermissionsAction,\n GatorPermissionsControllerDisableGatorPermissionsAction,\n GatorPermissionsControllerSubmitRevocationAction,\n GatorPermissionsControllerAddPendingRevocationAction,\n GatorPermissionsControllerActions,\n GatorPermissionsControllerEvents,\n GatorPermissionsControllerStateChangeEvent,\n} from './GatorPermissionsController';\nexport type { DecodedPermission } from './decodePermission';\nexport type {\n GatorPermissionsControllerErrorCode,\n GatorPermissionsSnapRpcMethod,\n CustomPermission,\n PermissionTypesWithCustom,\n PermissionRequest,\n PermissionResponse,\n PermissionResponseSanitized,\n StoredGatorPermission,\n StoredGatorPermissionSanitized,\n GatorPermissionsMap,\n SupportedGatorPermissionType,\n GatorPermissionsMapByPermissionType,\n GatorPermissionsListByPermissionTypeAndChainId,\n DelegationDetails,\n RevocationParams,\n} from './types';\n\nexport type {\n NativeTokenStreamPermission,\n NativeTokenPeriodicPermission,\n Erc20TokenStreamPermission,\n Erc20TokenPeriodicPermission,\n AccountSigner,\n WalletSigner,\n Signer,\n MetaMaskBasePermissionData,\n} from '@metamask/7715-permission-types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,+EAAqF;AAA5E,yJAAA,OAAO,OAA8B;AAC9C,qCAGiB;AAFf,qHAAA,4BAA4B,OAAA;AAC5B,uHAAA,8BAA8B,OAAA","sourcesContent":["export { default as GatorPermissionsController } from './GatorPermissionsController';\nexport {\n serializeGatorPermissionsMap,\n deserializeGatorPermissionsMap,\n} from './utils';\nexport type {\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger,\n GatorPermissionsControllerGetStateAction,\n GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction,\n GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction,\n GatorPermissionsControllerEnableGatorPermissionsAction,\n GatorPermissionsControllerDisableGatorPermissionsAction,\n GatorPermissionsControllerSubmitRevocationAction,\n GatorPermissionsControllerAddPendingRevocationAction,\n GatorPermissionsControllerSubmitDirectRevocationAction,\n GatorPermissionsControllerIsPendingRevocationAction,\n GatorPermissionsControllerActions,\n GatorPermissionsControllerEvents,\n GatorPermissionsControllerStateChangeEvent,\n} from './GatorPermissionsController';\nexport type { DecodedPermission } from './decodePermission';\nexport type {\n GatorPermissionsControllerErrorCode,\n GatorPermissionsSnapRpcMethod,\n CustomPermission,\n PermissionTypesWithCustom,\n PermissionRequest,\n PermissionResponse,\n PermissionResponseSanitized,\n StoredGatorPermission,\n StoredGatorPermissionSanitized,\n GatorPermissionsMap,\n SupportedGatorPermissionType,\n GatorPermissionsMapByPermissionType,\n GatorPermissionsListByPermissionTypeAndChainId,\n DelegationDetails,\n RevocationParams,\n} from './types';\n\nexport type {\n NativeTokenStreamPermission,\n NativeTokenPeriodicPermission,\n Erc20TokenStreamPermission,\n Erc20TokenPeriodicPermission,\n AccountSigner,\n WalletSigner,\n Signer,\n MetaMaskBasePermissionData,\n} from '@metamask/7715-permission-types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as GatorPermissionsController } from "./GatorPermissionsController.cjs";
|
|
2
2
|
export { serializeGatorPermissionsMap, deserializeGatorPermissionsMap, } from "./utils.cjs";
|
|
3
|
-
export type { GatorPermissionsControllerState, GatorPermissionsControllerMessenger, GatorPermissionsControllerGetStateAction, GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction, GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction, GatorPermissionsControllerEnableGatorPermissionsAction, GatorPermissionsControllerDisableGatorPermissionsAction, GatorPermissionsControllerSubmitRevocationAction, GatorPermissionsControllerAddPendingRevocationAction, GatorPermissionsControllerActions, GatorPermissionsControllerEvents, GatorPermissionsControllerStateChangeEvent, } from "./GatorPermissionsController.cjs";
|
|
3
|
+
export type { GatorPermissionsControllerState, GatorPermissionsControllerMessenger, GatorPermissionsControllerGetStateAction, GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction, GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction, GatorPermissionsControllerEnableGatorPermissionsAction, GatorPermissionsControllerDisableGatorPermissionsAction, GatorPermissionsControllerSubmitRevocationAction, GatorPermissionsControllerAddPendingRevocationAction, GatorPermissionsControllerSubmitDirectRevocationAction, GatorPermissionsControllerIsPendingRevocationAction, GatorPermissionsControllerActions, GatorPermissionsControllerEvents, GatorPermissionsControllerStateChangeEvent, } from "./GatorPermissionsController.cjs";
|
|
4
4
|
export type { DecodedPermission } from "./decodePermission/index.cjs";
|
|
5
5
|
export type { GatorPermissionsControllerErrorCode, GatorPermissionsSnapRpcMethod, CustomPermission, PermissionTypesWithCustom, PermissionRequest, PermissionResponse, PermissionResponseSanitized, StoredGatorPermission, StoredGatorPermissionSanitized, GatorPermissionsMap, SupportedGatorPermissionType, GatorPermissionsMapByPermissionType, GatorPermissionsListByPermissionTypeAndChainId, DelegationDetails, RevocationParams, } from "./types.cjs";
|
|
6
6
|
export type { NativeTokenStreamPermission, NativeTokenPeriodicPermission, Erc20TokenStreamPermission, Erc20TokenPeriodicPermission, AccountSigner, WalletSigner, Signer, MetaMaskBasePermissionData, } from "@metamask/7715-permission-types";
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,yCAAqC;AACrF,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,oBAAgB;AACjB,YAAY,EACV,+BAA+B,EAC/B,mCAAmC,EACnC,wCAAwC,EACxC,8EAA8E,EAC9E,8DAA8D,EAC9D,sDAAsD,EACtD,uDAAuD,EACvD,gDAAgD,EAChD,oDAAoD,EACpD,iCAAiC,EACjC,gCAAgC,EAChC,0CAA0C,GAC3C,yCAAqC;AACtC,YAAY,EAAE,iBAAiB,EAAE,qCAA2B;AAC5D,YAAY,EACV,mCAAmC,EACnC,6BAA6B,EAC7B,gBAAgB,EAChB,yBAAyB,EACzB,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,EAC3B,qBAAqB,EACrB,8BAA8B,EAC9B,mBAAmB,EACnB,4BAA4B,EAC5B,mCAAmC,EACnC,8CAA8C,EAC9C,iBAAiB,EACjB,gBAAgB,GACjB,oBAAgB;AAEjB,YAAY,EACV,2BAA2B,EAC3B,6BAA6B,EAC7B,0BAA0B,EAC1B,4BAA4B,EAC5B,aAAa,EACb,YAAY,EACZ,MAAM,EACN,0BAA0B,GAC3B,wCAAwC"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,yCAAqC;AACrF,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,oBAAgB;AACjB,YAAY,EACV,+BAA+B,EAC/B,mCAAmC,EACnC,wCAAwC,EACxC,8EAA8E,EAC9E,8DAA8D,EAC9D,sDAAsD,EACtD,uDAAuD,EACvD,gDAAgD,EAChD,oDAAoD,EACpD,sDAAsD,EACtD,mDAAmD,EACnD,iCAAiC,EACjC,gCAAgC,EAChC,0CAA0C,GAC3C,yCAAqC;AACtC,YAAY,EAAE,iBAAiB,EAAE,qCAA2B;AAC5D,YAAY,EACV,mCAAmC,EACnC,6BAA6B,EAC7B,gBAAgB,EAChB,yBAAyB,EACzB,iBAAiB,EACjB,kBAAkB,EAClB,2BAA2B,EAC3B,qBAAqB,EACrB,8BAA8B,EAC9B,mBAAmB,EACnB,4BAA4B,EAC5B,mCAAmC,EACnC,8CAA8C,EAC9C,iBAAiB,EACjB,gBAAgB,GACjB,oBAAgB;AAEjB,YAAY,EACV,2BAA2B,EAC3B,6BAA6B,EAC7B,0BAA0B,EAC1B,4BAA4B,EAC5B,aAAa,EACb,YAAY,EACZ,MAAM,EACN,0BAA0B,GAC3B,wCAAwC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as GatorPermissionsController } from "./GatorPermissionsController.mjs";
|
|
2
2
|
export { serializeGatorPermissionsMap, deserializeGatorPermissionsMap, } from "./utils.mjs";
|
|
3
|
-
export type { GatorPermissionsControllerState, GatorPermissionsControllerMessenger, GatorPermissionsControllerGetStateAction, GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction, GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction, GatorPermissionsControllerEnableGatorPermissionsAction, GatorPermissionsControllerDisableGatorPermissionsAction, GatorPermissionsControllerSubmitRevocationAction, GatorPermissionsControllerAddPendingRevocationAction, GatorPermissionsControllerActions, GatorPermissionsControllerEvents, GatorPermissionsControllerStateChangeEvent, } from "./GatorPermissionsController.mjs";
|
|
3
|
+
export type { GatorPermissionsControllerState, GatorPermissionsControllerMessenger, GatorPermissionsControllerGetStateAction, GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction, GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction, GatorPermissionsControllerEnableGatorPermissionsAction, GatorPermissionsControllerDisableGatorPermissionsAction, GatorPermissionsControllerSubmitRevocationAction, GatorPermissionsControllerAddPendingRevocationAction, GatorPermissionsControllerSubmitDirectRevocationAction, GatorPermissionsControllerIsPendingRevocationAction, GatorPermissionsControllerActions, GatorPermissionsControllerEvents, GatorPermissionsControllerStateChangeEvent, } from "./GatorPermissionsController.mjs";
|
|
4
4
|
export type { DecodedPermission } from "./decodePermission/index.mjs";
|
|
5
5
|
export type { GatorPermissionsControllerErrorCode, GatorPermissionsSnapRpcMethod, CustomPermission, PermissionTypesWithCustom, PermissionRequest, PermissionResponse, PermissionResponseSanitized, StoredGatorPermission, StoredGatorPermissionSanitized, GatorPermissionsMap, SupportedGatorPermissionType, GatorPermissionsMapByPermissionType, GatorPermissionsListByPermissionTypeAndChainId, DelegationDetails, RevocationParams, } from "./types.mjs";
|
|
6
6
|
export type { NativeTokenStreamPermission, NativeTokenPeriodicPermission, Erc20TokenStreamPermission, Erc20TokenPeriodicPermission, AccountSigner, WalletSigner, Signer, MetaMaskBasePermissionData, } from "@metamask/7715-permission-types";
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,yCAAqC;AACrF,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,GAC/B,oBAAgB;AACjB,YAAY,EACV,+BAA+B,EAC/B,mCAAmC,EACnC,wCAAwC,EACxC,8EAA8E,EAC9E,8DAA8D,EAC9D,sDAAsD,EACtD,uDAAuD,EACvD,gDAAgD,EAChD,oDAAoD,EACpD,iCA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,0BAA0B,EAC1B,4BAA4B,EAC5B,aAAa,EACb,YAAY,EACZ,MAAM,EACN,0BAA0B,GAC3B,wCAAwC"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,yCAAqC;AACrF,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,EAC/B,oBAAgB","sourcesContent":["export { default as GatorPermissionsController } from './GatorPermissionsController';\nexport {\n serializeGatorPermissionsMap,\n deserializeGatorPermissionsMap,\n} from './utils';\nexport type {\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger,\n GatorPermissionsControllerGetStateAction,\n GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction,\n GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction,\n GatorPermissionsControllerEnableGatorPermissionsAction,\n GatorPermissionsControllerDisableGatorPermissionsAction,\n GatorPermissionsControllerSubmitRevocationAction,\n GatorPermissionsControllerAddPendingRevocationAction,\n GatorPermissionsControllerActions,\n GatorPermissionsControllerEvents,\n GatorPermissionsControllerStateChangeEvent,\n} from './GatorPermissionsController';\nexport type { DecodedPermission } from './decodePermission';\nexport type {\n GatorPermissionsControllerErrorCode,\n GatorPermissionsSnapRpcMethod,\n CustomPermission,\n PermissionTypesWithCustom,\n PermissionRequest,\n PermissionResponse,\n PermissionResponseSanitized,\n StoredGatorPermission,\n StoredGatorPermissionSanitized,\n GatorPermissionsMap,\n SupportedGatorPermissionType,\n GatorPermissionsMapByPermissionType,\n GatorPermissionsListByPermissionTypeAndChainId,\n DelegationDetails,\n RevocationParams,\n} from './types';\n\nexport type {\n NativeTokenStreamPermission,\n NativeTokenPeriodicPermission,\n Erc20TokenStreamPermission,\n Erc20TokenPeriodicPermission,\n AccountSigner,\n WalletSigner,\n Signer,\n MetaMaskBasePermissionData,\n} from '@metamask/7715-permission-types';\n"]}
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,yCAAqC;AACrF,OAAO,EACL,4BAA4B,EAC5B,8BAA8B,EAC/B,oBAAgB","sourcesContent":["export { default as GatorPermissionsController } from './GatorPermissionsController';\nexport {\n serializeGatorPermissionsMap,\n deserializeGatorPermissionsMap,\n} from './utils';\nexport type {\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger,\n GatorPermissionsControllerGetStateAction,\n GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction,\n GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction,\n GatorPermissionsControllerEnableGatorPermissionsAction,\n GatorPermissionsControllerDisableGatorPermissionsAction,\n GatorPermissionsControllerSubmitRevocationAction,\n GatorPermissionsControllerAddPendingRevocationAction,\n GatorPermissionsControllerSubmitDirectRevocationAction,\n GatorPermissionsControllerIsPendingRevocationAction,\n GatorPermissionsControllerActions,\n GatorPermissionsControllerEvents,\n GatorPermissionsControllerStateChangeEvent,\n} from './GatorPermissionsController';\nexport type { DecodedPermission } from './decodePermission';\nexport type {\n GatorPermissionsControllerErrorCode,\n GatorPermissionsSnapRpcMethod,\n CustomPermission,\n PermissionTypesWithCustom,\n PermissionRequest,\n PermissionResponse,\n PermissionResponseSanitized,\n StoredGatorPermission,\n StoredGatorPermissionSanitized,\n GatorPermissionsMap,\n SupportedGatorPermissionType,\n GatorPermissionsMapByPermissionType,\n GatorPermissionsListByPermissionTypeAndChainId,\n DelegationDetails,\n RevocationParams,\n} from './types';\n\nexport type {\n NativeTokenStreamPermission,\n NativeTokenPeriodicPermission,\n Erc20TokenStreamPermission,\n Erc20TokenPeriodicPermission,\n AccountSigner,\n WalletSigner,\n Signer,\n MetaMaskBasePermissionData,\n} from '@metamask/7715-permission-types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/gator-permissions-controller",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "Controller for managing gator permissions with profile sync integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -53,16 +53,16 @@
|
|
|
53
53
|
"@metamask/delegation-core": "^0.2.0",
|
|
54
54
|
"@metamask/delegation-deployments": "^0.12.0",
|
|
55
55
|
"@metamask/messenger": "^0.3.0",
|
|
56
|
+
"@metamask/snaps-controllers": "^14.0.1",
|
|
56
57
|
"@metamask/snaps-sdk": "^9.0.0",
|
|
57
58
|
"@metamask/snaps-utils": "^11.0.0",
|
|
59
|
+
"@metamask/transaction-controller": "^62.3.1",
|
|
58
60
|
"@metamask/utils": "^11.8.1"
|
|
59
61
|
},
|
|
60
62
|
"devDependencies": {
|
|
61
63
|
"@lavamoat/allow-scripts": "^3.0.4",
|
|
62
64
|
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
63
65
|
"@metamask/auto-changelog": "^3.4.4",
|
|
64
|
-
"@metamask/snaps-controllers": "^14.0.1",
|
|
65
|
-
"@metamask/transaction-controller": "^61.3.0",
|
|
66
66
|
"@ts-bridge/cli": "^0.6.4",
|
|
67
67
|
"@types/jest": "^27.4.1",
|
|
68
68
|
"deepmerge": "^4.2.2",
|
|
@@ -72,10 +72,6 @@
|
|
|
72
72
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
73
73
|
"typescript": "~5.3.3"
|
|
74
74
|
},
|
|
75
|
-
"peerDependencies": {
|
|
76
|
-
"@metamask/snaps-controllers": "^14.0.1",
|
|
77
|
-
"@metamask/transaction-controller": "^61.1.0"
|
|
78
|
-
},
|
|
79
75
|
"engines": {
|
|
80
76
|
"node": "^18.18 || >=20"
|
|
81
77
|
},
|