Skip to content

Commit 767ed38

Browse files
authored
refactor: improve GatorPermissionsController permission storage and syncronisation (#7847)
## Explanation Makes the following changes to the `GatorPermissionsController` to improve storage and syncronisation of permissions data with Profile Sync service: - constructor now accepts a configuration object, including `supportedPermissionTypes` and optional `gatorPermissionsProviderSnapId` and `maxSyncIntervalMs`. - adds `lastSyncedTimestamp` (default -1); set when a sync completes successfully so `initialize()` can decide when to sync again. - `initialize()` call after construction; triggers a sync if no sync has run yet or cached data is older than the configured interval. - `fetchAndUpdateGatorPermissions()` now returns `Promise<void>`; callers should read from controller state. Concurrent calls share the same in-flight sync and no longer trigger duplicate operations. - removes the `GatorPermissionsMap` JSON-serialized state (and related types and utils); permissions are now stored in state as a simple array. Sync is done by calling the gator permissions Snap via RPC. - removes `enableGatorPermissions()` / `disableGatorPermissions()` and related actions; the controller is used as the single source for gator permissions when instantiated. - removes support for the "custom" permission type from the public API and types. - renames "Sanitized" permissions to "PermissionInfo" for clarity (this is the information required to show the permission in the UI) ## Checklist - [x] I've updated the test suite for new or updated code as appropriate - [x] I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate - [x] I've communicated my changes to consumers by [updating changelogs for packages I've changed](https://github.com/MetaMask/core/tree/main/docs/processes/updating-changelogs.md) - [x] I've introduced [breaking changes](https://github.com/MetaMask/core/tree/main/docs/processes/breaking-changes.md) in this PR and have prepared draft pull requests for clients and consumer packages to resolve them <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Medium Risk** > Breaking API/state-shape changes and new sync caching logic can affect downstream consumers and initial data freshness if integration assumptions differ. > > **Overview** > Refactors `GatorPermissionsController` to be config-driven and to store permissions as a flat `state.grantedPermissions` array (sanitized for UI) instead of a serialized `GatorPermissionsMap`. > > Adds `initialize()` with `lastSyncedTimestamp` + configurable `maxSyncIntervalMs` to control when an initial/stale sync happens, and changes `fetchAndUpdateGatorPermissions()` to return `Promise<void>` while deduplicating concurrent sync calls. > > Removes `enableGatorPermissions`/`disableGatorPermissions`, related actions/types/utils, and drops public support for “custom” permission types; introduces `executeSnapRpc` and updates docs/tests accordingly (including new error unit tests). > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 993b214. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 739a485 commit 767ed38

File tree

12 files changed

+850
-1138
lines changed

12 files changed

+850
-1138
lines changed

packages/gator-permissions-controller/CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Changed
1111

12-
- Bump `@metamask/transaction-controller` from `^62.11.0` to `^62.17.0` ([#7775](https://github.com/MetaMask/core/pull/7775), [#7802](https://github.com/MetaMask/core/pull/7802), [#7832](https://github.com/MetaMask/core/pull/7832), [#7854](https://github.com/MetaMask/core/pull/7854), [#7872](https://github.com/MetaMask/core/pull/7872)), ([#7897](https://github.com/MetaMask/core/pull/7897))
12+
- **BREAKING:** Refactor `GatorPermissionsController`: simplified config, permission storage, and public API ([#7847](https://github.com/MetaMask/core/pull/7847))
13+
- Constructor now requires `config`, internal configuration is removed from controller state
14+
- New `initialize()` function performs a syncronisation process if required when the controller is first initialized
15+
- Replaces `gatorPermissionsMapSerialized` with `grantedPermissions` property in internal state, replaces related types, and utility functions
16+
- `fetchAndUpdateGatorPermissions()` no longer accepts parameters and resolves to `void`
17+
- `getPendingRevocations` / `pendingRevocations` getter replaced by `isPendingRevocation(permissionContext)`; list on `state.pendingRevocations`
18+
- Bump `@metamask/transaction-controller` from `^62.11.0` to `^62.17.0` ([#7775](https://github.com/MetaMask/core/pull/7775), [#7802](https://github.com/MetaMask/core/pull/7802), [#7832](https://github.com/MetaMask/core/pull/7832), [#7854](https://github.com/MetaMask/core/pull/7854), [#7872](https://github.com/MetaMask/core/pull/7872)), ([#7897](https://github.com/MetaMask/core/pull/7897))>>>>>>> Stashed changes
1319

1420
## [1.1.2]
1521

packages/gator-permissions-controller/README.md

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,21 @@ or
1717
```typescript
1818
import { GatorPermissionsController } from '@metamask/gator-permissions-controller';
1919

20-
// Create the controller
20+
// Create the controller with required config
2121
const gatorPermissionsController = new GatorPermissionsController({
2222
messenger: yourMessenger,
23+
config: {
24+
supportedPermissionTypes: [
25+
'native-token-stream',
26+
'native-token-periodic',
27+
'erc20-token-stream',
28+
'erc20-token-periodic',
29+
'erc20-token-revocation',
30+
],
31+
// Optional: override the default gator permissions provider Snap id
32+
// gatorPermissionsProviderSnapId: 'npm:@metamask/gator-permissions-snap',
33+
},
2334
});
24-
25-
// Enable the feature (requires authentication)
26-
gatorPermissionsController.enableGatorPermissions();
2735
```
2836

2937
### Fetch from Profile Sync
@@ -33,12 +41,9 @@ gatorPermissionsController.enableGatorPermissions();
3341
const permissions =
3442
await gatorPermissionsController.fetchAndUpdateGatorPermissions();
3543

36-
// Fetch permissions with optional filter params
37-
const filteredPermissions =
38-
await gatorPermissionsController.fetchAndUpdateGatorPermissions({
39-
origin: 'https://example.com',
40-
chainId: '0x1',
41-
});
44+
// Fetch permissions and update internal state
45+
const permissions =
46+
await gatorPermissionsController.fetchAndUpdateGatorPermissions();
4247
```
4348

4449
## Contributing

0 commit comments

Comments
 (0)