@metamask-previews/gator-permissions-controller 2.1.1-preview-434bd0c → 2.1.1-preview-e9620906a
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 +7 -0
- package/dist/GatorPermissionsController-method-action-types.cjs +7 -0
- package/dist/GatorPermissionsController-method-action-types.cjs.map +1 -0
- package/dist/GatorPermissionsController-method-action-types.d.cts +116 -0
- package/dist/GatorPermissionsController-method-action-types.d.cts.map +1 -0
- package/dist/GatorPermissionsController-method-action-types.d.mts +116 -0
- package/dist/GatorPermissionsController-method-action-types.d.mts.map +1 -0
- package/dist/GatorPermissionsController-method-action-types.mjs +6 -0
- package/dist/GatorPermissionsController-method-action-types.mjs.map +1 -0
- package/dist/GatorPermissionsController.cjs +13 -10
- package/dist/GatorPermissionsController.cjs.map +1 -1
- package/dist/GatorPermissionsController.d.cts +4 -43
- package/dist/GatorPermissionsController.d.cts.map +1 -1
- package/dist/GatorPermissionsController.d.mts +4 -43
- package/dist/GatorPermissionsController.d.mts.map +1 -1
- package/dist/GatorPermissionsController.mjs +12 -11
- package/dist/GatorPermissionsController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Expose missing public `GatorPermissionsController` methods through its messenger ([#8205](https://github.com/MetaMask/core/pull/8205))
|
|
13
|
+
- The following actions are now available:
|
|
14
|
+
- `GatorPermissionsController:initialize`
|
|
15
|
+
- Corresponding action types (e.g. `GatorPermissionsControllerInitializeAction`) are available as well.
|
|
16
|
+
|
|
10
17
|
## [2.1.1]
|
|
11
18
|
|
|
12
19
|
### Changed
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
4
|
+
* Do not edit manually.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
//# sourceMappingURL=GatorPermissionsController-method-action-types.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController-method-action-types.cjs","sourceRoot":"","sources":["../src/GatorPermissionsController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { GatorPermissionsController } from './GatorPermissionsController';\n\n/**\n * Fetches granted permissions from the gator permissions provider Snap and updates state.\n * If a sync is already in progress, returns the same promise. After the sync completes,\n * the next call will perform a new sync.\n *\n * @returns A promise that resolves when the sync completes. All data is available via the controller's state.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\nexport type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {\n type: `GatorPermissionsController:fetchAndUpdateGatorPermissions`;\n handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];\n};\n\n/**\n * Initializes the controller. Call once after construction to ensure the\n * controller is ready for use.\n *\n * @returns A promise that resolves when initialization is complete.\n */\nexport type GatorPermissionsControllerInitializeAction = {\n type: `GatorPermissionsController:initialize`;\n handler: GatorPermissionsController['initialize'];\n};\n\n/**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, to, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\nexport type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction =\n {\n type: `GatorPermissionsController:decodePermissionFromPermissionContextForOrigin`;\n handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];\n };\n\n/**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\nexport type GatorPermissionsControllerSubmitRevocationAction = {\n type: `GatorPermissionsController:submitRevocation`;\n handler: GatorPermissionsController['submitRevocation'];\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 */\nexport type GatorPermissionsControllerAddPendingRevocationAction = {\n type: `GatorPermissionsController:addPendingRevocation`;\n handler: GatorPermissionsController['addPendingRevocation'];\n};\n\n/**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\nexport type GatorPermissionsControllerSubmitDirectRevocationAction = {\n type: `GatorPermissionsController:submitDirectRevocation`;\n handler: GatorPermissionsController['submitDirectRevocation'];\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 */\nexport type GatorPermissionsControllerIsPendingRevocationAction = {\n type: `GatorPermissionsController:isPendingRevocation`;\n handler: GatorPermissionsController['isPendingRevocation'];\n};\n\n/**\n * Union of all GatorPermissionsController action types.\n */\nexport type GatorPermissionsControllerMethodActions =\n | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction\n | GatorPermissionsControllerInitializeAction\n | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n"]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { GatorPermissionsController } from "./GatorPermissionsController.cjs";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches granted permissions from the gator permissions provider Snap and updates state.
|
|
8
|
+
* If a sync is already in progress, returns the same promise. After the sync completes,
|
|
9
|
+
* the next call will perform a new sync.
|
|
10
|
+
*
|
|
11
|
+
* @returns A promise that resolves when the sync completes. All data is available via the controller's state.
|
|
12
|
+
* @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.
|
|
13
|
+
*/
|
|
14
|
+
export type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {
|
|
15
|
+
type: `GatorPermissionsController:fetchAndUpdateGatorPermissions`;
|
|
16
|
+
handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the controller. Call once after construction to ensure the
|
|
20
|
+
* controller is ready for use.
|
|
21
|
+
*
|
|
22
|
+
* @returns A promise that resolves when initialization is complete.
|
|
23
|
+
*/
|
|
24
|
+
export type GatorPermissionsControllerInitializeAction = {
|
|
25
|
+
type: `GatorPermissionsController:initialize`;
|
|
26
|
+
handler: GatorPermissionsController['initialize'];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Decodes a permission context into a structured permission for a specific origin.
|
|
30
|
+
*
|
|
31
|
+
* This method validates the caller origin, decodes the provided `permissionContext`
|
|
32
|
+
* into delegations, identifies the permission type from the caveat enforcers,
|
|
33
|
+
* extracts the permission-specific data and expiry, and reconstructs a
|
|
34
|
+
* {@link DecodedPermission} containing chainId, account addresses, to, type and data.
|
|
35
|
+
*
|
|
36
|
+
* @param args - The arguments to this function.
|
|
37
|
+
* @param args.origin - The caller's origin; must match the configured permissions provider Snap id.
|
|
38
|
+
* @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.
|
|
39
|
+
* @param args.delegation - delegation representing the permission.
|
|
40
|
+
* @param args.metadata - metadata included in the request.
|
|
41
|
+
* @param args.metadata.justification - the justification as specified in the request metadata.
|
|
42
|
+
* @param args.metadata.origin - the origin as specified in the request metadata.
|
|
43
|
+
*
|
|
44
|
+
* @returns A decoded permission object suitable for UI consumption and follow-up actions.
|
|
45
|
+
* @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,
|
|
46
|
+
* or the enforcers/terms do not match a supported permission type.
|
|
47
|
+
*/
|
|
48
|
+
export type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction = {
|
|
49
|
+
type: `GatorPermissionsController:decodePermissionFromPermissionContextForOrigin`;
|
|
50
|
+
handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Submits a revocation to the gator permissions provider snap.
|
|
54
|
+
*
|
|
55
|
+
* @param revocationParams - The revocation parameters containing the permission context.
|
|
56
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
57
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
58
|
+
*/
|
|
59
|
+
export type GatorPermissionsControllerSubmitRevocationAction = {
|
|
60
|
+
type: `GatorPermissionsController:submitRevocation`;
|
|
61
|
+
handler: GatorPermissionsController['submitRevocation'];
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Adds a pending revocation that will be submitted once the transaction is confirmed.
|
|
65
|
+
*
|
|
66
|
+
* This method sets up listeners for the user's approval/rejection decision and
|
|
67
|
+
* terminal transaction states (confirmed, failed, dropped). The flow is:
|
|
68
|
+
* 1. Wait for user to approve or reject the transaction
|
|
69
|
+
* 2. If approved, add to pending revocations state
|
|
70
|
+
* 3. If rejected, cleanup without adding to state
|
|
71
|
+
* 4. If confirmed, submit the revocation
|
|
72
|
+
* 5. If failed or dropped, cleanup
|
|
73
|
+
*
|
|
74
|
+
* Includes a timeout safety net to prevent memory leaks if the transaction never
|
|
75
|
+
* reaches a terminal state.
|
|
76
|
+
*
|
|
77
|
+
* @param params - The pending revocation parameters.
|
|
78
|
+
* @returns A promise that resolves when the listener is set up.
|
|
79
|
+
*/
|
|
80
|
+
export type GatorPermissionsControllerAddPendingRevocationAction = {
|
|
81
|
+
type: `GatorPermissionsController:addPendingRevocation`;
|
|
82
|
+
handler: GatorPermissionsController['addPendingRevocation'];
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Submits a revocation directly without requiring an on-chain transaction.
|
|
86
|
+
* Used for already-disabled delegations that don't require an on-chain transaction.
|
|
87
|
+
*
|
|
88
|
+
* This method:
|
|
89
|
+
* 1. Adds the permission context to pending revocations state (disables UI button)
|
|
90
|
+
* 2. Immediately calls submitRevocation to remove from snap storage
|
|
91
|
+
* 3. On success, removes from pending revocations state (re-enables UI button)
|
|
92
|
+
* 4. On failure, keeps in pending revocations so UI can show error/retry state
|
|
93
|
+
*
|
|
94
|
+
* @param params - The revocation parameters containing the permission context.
|
|
95
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
96
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
97
|
+
*/
|
|
98
|
+
export type GatorPermissionsControllerSubmitDirectRevocationAction = {
|
|
99
|
+
type: `GatorPermissionsController:submitDirectRevocation`;
|
|
100
|
+
handler: GatorPermissionsController['submitDirectRevocation'];
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Checks if a permission context is in the pending revocations list.
|
|
104
|
+
*
|
|
105
|
+
* @param permissionContext - The permission context to check.
|
|
106
|
+
* @returns `true` if the permission context is pending revocation, `false` otherwise.
|
|
107
|
+
*/
|
|
108
|
+
export type GatorPermissionsControllerIsPendingRevocationAction = {
|
|
109
|
+
type: `GatorPermissionsController:isPendingRevocation`;
|
|
110
|
+
handler: GatorPermissionsController['isPendingRevocation'];
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Union of all GatorPermissionsController action types.
|
|
114
|
+
*/
|
|
115
|
+
export type GatorPermissionsControllerMethodActions = GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerInitializeAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | GatorPermissionsControllerSubmitRevocationAction | GatorPermissionsControllerAddPendingRevocationAction | GatorPermissionsControllerSubmitDirectRevocationAction | GatorPermissionsControllerIsPendingRevocationAction;
|
|
116
|
+
//# sourceMappingURL=GatorPermissionsController-method-action-types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController-method-action-types.d.cts","sourceRoot":"","sources":["../src/GatorPermissionsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;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D,GACpD,sDAAsD,GACtD,mDAAmD,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { GatorPermissionsController } from "./GatorPermissionsController.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Fetches granted permissions from the gator permissions provider Snap and updates state.
|
|
8
|
+
* If a sync is already in progress, returns the same promise. After the sync completes,
|
|
9
|
+
* the next call will perform a new sync.
|
|
10
|
+
*
|
|
11
|
+
* @returns A promise that resolves when the sync completes. All data is available via the controller's state.
|
|
12
|
+
* @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.
|
|
13
|
+
*/
|
|
14
|
+
export type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {
|
|
15
|
+
type: `GatorPermissionsController:fetchAndUpdateGatorPermissions`;
|
|
16
|
+
handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Initializes the controller. Call once after construction to ensure the
|
|
20
|
+
* controller is ready for use.
|
|
21
|
+
*
|
|
22
|
+
* @returns A promise that resolves when initialization is complete.
|
|
23
|
+
*/
|
|
24
|
+
export type GatorPermissionsControllerInitializeAction = {
|
|
25
|
+
type: `GatorPermissionsController:initialize`;
|
|
26
|
+
handler: GatorPermissionsController['initialize'];
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Decodes a permission context into a structured permission for a specific origin.
|
|
30
|
+
*
|
|
31
|
+
* This method validates the caller origin, decodes the provided `permissionContext`
|
|
32
|
+
* into delegations, identifies the permission type from the caveat enforcers,
|
|
33
|
+
* extracts the permission-specific data and expiry, and reconstructs a
|
|
34
|
+
* {@link DecodedPermission} containing chainId, account addresses, to, type and data.
|
|
35
|
+
*
|
|
36
|
+
* @param args - The arguments to this function.
|
|
37
|
+
* @param args.origin - The caller's origin; must match the configured permissions provider Snap id.
|
|
38
|
+
* @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.
|
|
39
|
+
* @param args.delegation - delegation representing the permission.
|
|
40
|
+
* @param args.metadata - metadata included in the request.
|
|
41
|
+
* @param args.metadata.justification - the justification as specified in the request metadata.
|
|
42
|
+
* @param args.metadata.origin - the origin as specified in the request metadata.
|
|
43
|
+
*
|
|
44
|
+
* @returns A decoded permission object suitable for UI consumption and follow-up actions.
|
|
45
|
+
* @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,
|
|
46
|
+
* or the enforcers/terms do not match a supported permission type.
|
|
47
|
+
*/
|
|
48
|
+
export type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction = {
|
|
49
|
+
type: `GatorPermissionsController:decodePermissionFromPermissionContextForOrigin`;
|
|
50
|
+
handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* Submits a revocation to the gator permissions provider snap.
|
|
54
|
+
*
|
|
55
|
+
* @param revocationParams - The revocation parameters containing the permission context.
|
|
56
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
57
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
58
|
+
*/
|
|
59
|
+
export type GatorPermissionsControllerSubmitRevocationAction = {
|
|
60
|
+
type: `GatorPermissionsController:submitRevocation`;
|
|
61
|
+
handler: GatorPermissionsController['submitRevocation'];
|
|
62
|
+
};
|
|
63
|
+
/**
|
|
64
|
+
* Adds a pending revocation that will be submitted once the transaction is confirmed.
|
|
65
|
+
*
|
|
66
|
+
* This method sets up listeners for the user's approval/rejection decision and
|
|
67
|
+
* terminal transaction states (confirmed, failed, dropped). The flow is:
|
|
68
|
+
* 1. Wait for user to approve or reject the transaction
|
|
69
|
+
* 2. If approved, add to pending revocations state
|
|
70
|
+
* 3. If rejected, cleanup without adding to state
|
|
71
|
+
* 4. If confirmed, submit the revocation
|
|
72
|
+
* 5. If failed or dropped, cleanup
|
|
73
|
+
*
|
|
74
|
+
* Includes a timeout safety net to prevent memory leaks if the transaction never
|
|
75
|
+
* reaches a terminal state.
|
|
76
|
+
*
|
|
77
|
+
* @param params - The pending revocation parameters.
|
|
78
|
+
* @returns A promise that resolves when the listener is set up.
|
|
79
|
+
*/
|
|
80
|
+
export type GatorPermissionsControllerAddPendingRevocationAction = {
|
|
81
|
+
type: `GatorPermissionsController:addPendingRevocation`;
|
|
82
|
+
handler: GatorPermissionsController['addPendingRevocation'];
|
|
83
|
+
};
|
|
84
|
+
/**
|
|
85
|
+
* Submits a revocation directly without requiring an on-chain transaction.
|
|
86
|
+
* Used for already-disabled delegations that don't require an on-chain transaction.
|
|
87
|
+
*
|
|
88
|
+
* This method:
|
|
89
|
+
* 1. Adds the permission context to pending revocations state (disables UI button)
|
|
90
|
+
* 2. Immediately calls submitRevocation to remove from snap storage
|
|
91
|
+
* 3. On success, removes from pending revocations state (re-enables UI button)
|
|
92
|
+
* 4. On failure, keeps in pending revocations so UI can show error/retry state
|
|
93
|
+
*
|
|
94
|
+
* @param params - The revocation parameters containing the permission context.
|
|
95
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
96
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
97
|
+
*/
|
|
98
|
+
export type GatorPermissionsControllerSubmitDirectRevocationAction = {
|
|
99
|
+
type: `GatorPermissionsController:submitDirectRevocation`;
|
|
100
|
+
handler: GatorPermissionsController['submitDirectRevocation'];
|
|
101
|
+
};
|
|
102
|
+
/**
|
|
103
|
+
* Checks if a permission context is in the pending revocations list.
|
|
104
|
+
*
|
|
105
|
+
* @param permissionContext - The permission context to check.
|
|
106
|
+
* @returns `true` if the permission context is pending revocation, `false` otherwise.
|
|
107
|
+
*/
|
|
108
|
+
export type GatorPermissionsControllerIsPendingRevocationAction = {
|
|
109
|
+
type: `GatorPermissionsController:isPendingRevocation`;
|
|
110
|
+
handler: GatorPermissionsController['isPendingRevocation'];
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Union of all GatorPermissionsController action types.
|
|
114
|
+
*/
|
|
115
|
+
export type GatorPermissionsControllerMethodActions = GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerInitializeAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | GatorPermissionsControllerSubmitRevocationAction | GatorPermissionsControllerAddPendingRevocationAction | GatorPermissionsControllerSubmitDirectRevocationAction | GatorPermissionsControllerIsPendingRevocationAction;
|
|
116
|
+
//# sourceMappingURL=GatorPermissionsController-method-action-types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController-method-action-types.d.mts","sourceRoot":"","sources":["../src/GatorPermissionsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,yCAAqC;AAE/E;;;;;;;GAOG;AACH,MAAM,MAAM,8DAA8D,GAAG;IAC3E,IAAI,EAAE,2DAA2D,CAAC;IAClE,OAAO,EAAE,0BAA0B,CAAC,gCAAgC,CAAC,CAAC;CACvE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,0CAA0C,GAAG;IACvD,IAAI,EAAE,uCAAuC,CAAC;IAC9C,OAAO,EAAE,0BAA0B,CAAC,YAAY,CAAC,CAAC;CACnD,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,MAAM,8EAA8E,GACxF;IACE,IAAI,EAAE,2EAA2E,CAAC;IAClF,OAAO,EAAE,0BAA0B,CAAC,gDAAgD,CAAC,CAAC;CACvF,CAAC;AAEJ;;;;;;GAMG;AACH,MAAM,MAAM,gDAAgD,GAAG;IAC7D,IAAI,EAAE,6CAA6C,CAAC;IACpD,OAAO,EAAE,0BAA0B,CAAC,kBAAkB,CAAC,CAAC;CACzD,CAAC;AAEF;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,MAAM,oDAAoD,GAAG;IACjE,IAAI,EAAE,iDAAiD,CAAC;IACxD,OAAO,EAAE,0BAA0B,CAAC,sBAAsB,CAAC,CAAC;CAC7D,CAAC;AAEF;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,sDAAsD,GAAG;IACnE,IAAI,EAAE,mDAAmD,CAAC;IAC1D,OAAO,EAAE,0BAA0B,CAAC,wBAAwB,CAAC,CAAC;CAC/D,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,mDAAmD,GAAG;IAChE,IAAI,EAAE,gDAAgD,CAAC;IACvD,OAAO,EAAE,0BAA0B,CAAC,qBAAqB,CAAC,CAAC;CAC5D,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uCAAuC,GAC/C,8DAA8D,GAC9D,0CAA0C,GAC1C,8EAA8E,GAC9E,gDAAgD,GAChD,oDAAoD,GACpD,sDAAsD,GACtD,mDAAmD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController-method-action-types.mjs","sourceRoot":"","sources":["../src/GatorPermissionsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { GatorPermissionsController } from './GatorPermissionsController';\n\n/**\n * Fetches granted permissions from the gator permissions provider Snap and updates state.\n * If a sync is already in progress, returns the same promise. After the sync completes,\n * the next call will perform a new sync.\n *\n * @returns A promise that resolves when the sync completes. All data is available via the controller's state.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\nexport type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {\n type: `GatorPermissionsController:fetchAndUpdateGatorPermissions`;\n handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];\n};\n\n/**\n * Initializes the controller. Call once after construction to ensure the\n * controller is ready for use.\n *\n * @returns A promise that resolves when initialization is complete.\n */\nexport type GatorPermissionsControllerInitializeAction = {\n type: `GatorPermissionsController:initialize`;\n handler: GatorPermissionsController['initialize'];\n};\n\n/**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, to, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\nexport type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction =\n {\n type: `GatorPermissionsController:decodePermissionFromPermissionContextForOrigin`;\n handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];\n };\n\n/**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\nexport type GatorPermissionsControllerSubmitRevocationAction = {\n type: `GatorPermissionsController:submitRevocation`;\n handler: GatorPermissionsController['submitRevocation'];\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 */\nexport type GatorPermissionsControllerAddPendingRevocationAction = {\n type: `GatorPermissionsController:addPendingRevocation`;\n handler: GatorPermissionsController['addPendingRevocation'];\n};\n\n/**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\nexport type GatorPermissionsControllerSubmitDirectRevocationAction = {\n type: `GatorPermissionsController:submitDirectRevocation`;\n handler: GatorPermissionsController['submitDirectRevocation'];\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 */\nexport type GatorPermissionsControllerIsPendingRevocationAction = {\n type: `GatorPermissionsController:isPendingRevocation`;\n handler: GatorPermissionsController['isPendingRevocation'];\n};\n\n/**\n * Union of all GatorPermissionsController action types.\n */\nexport type GatorPermissionsControllerMethodActions =\n | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction\n | GatorPermissionsControllerInitializeAction\n | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n"]}
|
|
@@ -10,8 +10,9 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
11
11
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
12
|
};
|
|
13
|
-
var _GatorPermissionsController_instances, _GatorPermissionsController_supportedPermissionTypes, _GatorPermissionsController_gatorPermissionsProviderSnapId, _GatorPermissionsController_maxSyncIntervalMs, _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext,
|
|
13
|
+
var _GatorPermissionsController_instances, _GatorPermissionsController_supportedPermissionTypes, _GatorPermissionsController_gatorPermissionsProviderSnapId, _GatorPermissionsController_maxSyncIntervalMs, _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext, _GatorPermissionsController_storedPermissionToPermissionInfo, _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.GatorPermissionsController = void 0;
|
|
15
16
|
const base_controller_1 = require("@metamask/base-controller");
|
|
16
17
|
const delegation_deployments_1 = require("@metamask/delegation-deployments");
|
|
17
18
|
const snaps_utils_1 = require("@metamask/snaps-utils");
|
|
@@ -25,6 +26,15 @@ const utils_1 = require("./utils.cjs");
|
|
|
25
26
|
// === GENERAL ===
|
|
26
27
|
// Unique name for the controller
|
|
27
28
|
const controllerName = 'GatorPermissionsController';
|
|
29
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
30
|
+
'fetchAndUpdateGatorPermissions',
|
|
31
|
+
'initialize',
|
|
32
|
+
'decodePermissionFromPermissionContextForOrigin',
|
|
33
|
+
'submitRevocation',
|
|
34
|
+
'addPendingRevocation',
|
|
35
|
+
'submitDirectRevocation',
|
|
36
|
+
'isPendingRevocation',
|
|
37
|
+
];
|
|
28
38
|
// Default value for the gator permissions provider snap id
|
|
29
39
|
const defaultGatorPermissionsProviderSnapId = 'npm:@metamask/gator-permissions-snap';
|
|
30
40
|
const DEFAULT_MAX_SYNC_INTERVAL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds
|
|
@@ -118,7 +128,7 @@ class GatorPermissionsController extends base_controller_1.BaseController {
|
|
|
118
128
|
__classPrivateFieldSet(this, _GatorPermissionsController_gatorPermissionsProviderSnapId, config.gatorPermissionsProviderSnapId ??
|
|
119
129
|
defaultGatorPermissionsProviderSnapId, "f");
|
|
120
130
|
__classPrivateFieldSet(this, _GatorPermissionsController_maxSyncIntervalMs, config.maxSyncIntervalMs ?? DEFAULT_MAX_SYNC_INTERVAL_MS, "f");
|
|
121
|
-
|
|
131
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
122
132
|
}
|
|
123
133
|
/**
|
|
124
134
|
* Supported permission types this controller was configured with.
|
|
@@ -519,6 +529,7 @@ class GatorPermissionsController extends base_controller_1.BaseController {
|
|
|
519
529
|
requestedPermissionContextLowercase);
|
|
520
530
|
}
|
|
521
531
|
}
|
|
532
|
+
exports.GatorPermissionsController = GatorPermissionsController;
|
|
522
533
|
_GatorPermissionsController_supportedPermissionTypes = new WeakMap(), _GatorPermissionsController_gatorPermissionsProviderSnapId = new WeakMap(), _GatorPermissionsController_maxSyncIntervalMs = new WeakMap(), _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise = new WeakMap(), _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsController_setIsFetchingGatorPermissions = function _GatorPermissionsController_setIsFetchingGatorPermissions(isFetchingGatorPermissions) {
|
|
523
534
|
this.update((state) => {
|
|
524
535
|
state.isFetchingGatorPermissions = isFetchingGatorPermissions;
|
|
@@ -539,14 +550,6 @@ _GatorPermissionsController_supportedPermissionTypes = new WeakMap(), _GatorPerm
|
|
|
539
550
|
state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext.toLowerCase() !==
|
|
540
551
|
permissionContext.toLowerCase());
|
|
541
552
|
});
|
|
542
|
-
}, _GatorPermissionsController_registerMessageHandlers = function _GatorPermissionsController_registerMessageHandlers() {
|
|
543
|
-
this.messenger.registerActionHandler(`${controllerName}:fetchAndUpdateGatorPermissions`, this.fetchAndUpdateGatorPermissions.bind(this));
|
|
544
|
-
this.messenger.registerActionHandler(`${controllerName}:decodePermissionFromPermissionContextForOrigin`, this.decodePermissionFromPermissionContextForOrigin.bind(this));
|
|
545
|
-
const submitRevocationAction = `${controllerName}:submitRevocation`;
|
|
546
|
-
this.messenger.registerActionHandler(submitRevocationAction, this.submitRevocation.bind(this));
|
|
547
|
-
this.messenger.registerActionHandler(`${controllerName}:addPendingRevocation`, this.addPendingRevocation.bind(this));
|
|
548
|
-
this.messenger.registerActionHandler(`${controllerName}:submitDirectRevocation`, this.submitDirectRevocation.bind(this));
|
|
549
|
-
this.messenger.registerActionHandler(`${controllerName}:isPendingRevocation`, this.isPendingRevocation.bind(this));
|
|
550
553
|
}, _GatorPermissionsController_storedPermissionToPermissionInfo = function _GatorPermissionsController_storedPermissionToPermissionInfo(storedGatorPermission) {
|
|
551
554
|
const { permissionResponse: fullPermissionResponse } = storedGatorPermission;
|
|
552
555
|
const { dependencies: _dependencies, to: _to, ...permissionResponse } = fullPermissionResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatorPermissionsController.cjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAKA,+DAA2D;AAC3D,6EAAuE;AAIvE,uDAAoD;AACpD,6EAAqE;AAUrE,+CAA2D;AAE3D,mEAI4B;AAC5B,yCAKkB;AAClB,yCAAyC;AACzC,uCAAwD;AASxD,uCAAyC;AAEzC,kBAAkB;AAElB,iCAAiC;AACjC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,2DAA2D;AAC3D,MAAM,qCAAqC,GACzC,sC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AAI,EAAmC,gBAAgB,CAAC,CACzD,CAAC;AACJ,CAAC;kBAnLkB,0BAA0B","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { DELEGATION_FRAMEWORK_VERSION } from './constants';\nimport type { DecodedPermission } from './decodePermission';\nimport {\n createPermissionRulesForContracts,\n findRuleWithMatchingCaveatAddresses,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport { controllerLog } from './logger';\nimport { GatorPermissionsSnapRpcMethod } from './types';\nimport type {\n StoredGatorPermission,\n PermissionInfoWithMetadata,\n SupportedPermissionType,\n DelegationDetails,\n RevocationParams,\n PendingRevocationParams,\n} from './types';\nimport { executeSnapRpc } from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst DEFAULT_MAX_SYNC_INTERVAL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === CONFIG ===\n\n/**\n * Configuration for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerConfig = {\n /**\n * Permission types the controller supports (e.g. 'native-token-stream', 'erc20-token-periodic').\n */\n supportedPermissionTypes: SupportedPermissionType[];\n /**\n * Optional ID of the gator permissions provider Snap. Defaults to npm:@metamask/gator-permissions-snap.\n */\n gatorPermissionsProviderSnapId?: SnapId;\n /**\n * Optional maximum age of cached permissions (ms) before {@link GatorPermissionsController.initialize}\n * triggers a sync. Defaults to 30 days.\n */\n maxSyncIntervalMs?: number;\n};\n\n// === STATE ===\n\n/**\n * State shape for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerState = {\n /**\n * List of granted permissions with metadata (siteOrigin, revocationMetadata).\n */\n grantedPermissions: PermissionInfoWithMetadata[];\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This can be used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * List of gator permissions pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n\n /**\n * Timestamp (ms) of the last successful sync of gator permissions from profile sync.\n * -1 indicates that a sync has never completed successfully.\n */\n lastSyncedTimestamp: number;\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n grantedPermissions: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSyncedTimestamp: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Creates initial controller state, merging defaults with optional partial state.\n * Internal use only (e.g. constructor, tests).\n *\n * @param state - Optional partial state to merge with defaults.\n * @returns Complete {@link GatorPermissionsController} state.\n */\nfunction createGatorPermissionsControllerState(\n state?: Partial<GatorPermissionsControllerState>,\n): GatorPermissionsControllerState {\n return {\n grantedPermissions: [],\n pendingRevocations: [],\n lastSyncedTimestamp: -1,\n ...state,\n // isFetchingGatorPermissions is _always_ false when the controller is created\n isFetchingGatorPermissions: false,\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * 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\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 | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapController:handleRequest and SnapController: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 the gator permissions provider Snap.\n */\nexport default class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n readonly #supportedPermissionTypes: readonly SupportedPermissionType[];\n\n /**\n * The Snap ID of the gator permissions provider.\n *\n * @returns The Snap ID of the gator permissions provider.\n */\n get gatorPermissionsProviderSnapId(): SnapId {\n return this.#gatorPermissionsProviderSnapId;\n }\n\n readonly #gatorPermissionsProviderSnapId: SnapId;\n\n readonly #maxSyncIntervalMs: number;\n\n /**\n * When a sync is in progress, holds the promise for that sync so concurrent\n * callers receive the same promise. Cleared when the sync completes.\n */\n #fetchAndUpdateGatorPermissionsPromise: Promise<void> | null = null;\n\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with other controllers.\n * @param args.config - Configuration (supported permission types and optional Snap id).\n * @param args.state - Optional partial state to merge with defaults.\n */\n constructor({\n messenger,\n config,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n config: GatorPermissionsControllerConfig;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n const initialState = createGatorPermissionsControllerState(state);\n\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: initialState,\n });\n\n this.#supportedPermissionTypes = config.supportedPermissionTypes;\n this.#gatorPermissionsProviderSnapId =\n config.gatorPermissionsProviderSnapId ??\n defaultGatorPermissionsProviderSnapId;\n this.#maxSyncIntervalMs =\n config.maxSyncIntervalMs ?? DEFAULT_MAX_SYNC_INTERVAL_MS;\n this.#registerMessageHandlers();\n }\n\n /**\n * Supported permission types this controller was configured with.\n *\n * @returns The supported permission types.\n */\n get supportedPermissionTypes(): readonly SupportedPermissionType[] {\n return this.#supportedPermissionTypes;\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean): void {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex): void {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(\n permissionContext: Hex,\n ): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchAndUpdateGatorPermissions`,\n this.fetchAndUpdateGatorPermissions.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 * Converts a stored gator permission to permission info with metadata.\n * Strips internal fields (dependencies, to) from the permission response.\n *\n * @param storedGatorPermission - The stored gator permission from the Snap.\n * @returns Permission info with metadata for state/UI.\n */\n #storedPermissionToPermissionInfo(\n storedGatorPermission: StoredGatorPermission,\n ): PermissionInfoWithMetadata {\n const { permissionResponse: fullPermissionResponse } =\n storedGatorPermission;\n const {\n dependencies: _dependencies,\n to: _to,\n ...permissionResponse\n } = fullPermissionResponse;\n\n return {\n ...storedGatorPermission,\n permissionResponse,\n };\n }\n\n /**\n * Converts stored gator permissions from the Snap into permission info with metadata.\n *\n * @param storedGatorPermissions - Stored gator permissions returned by the Snap, or null.\n * @returns Array of permission info with metadata for state.\n */\n #storedPermissionsToPermissionInfoWithMetadata(\n storedGatorPermissions: StoredGatorPermission[] | null,\n ): PermissionInfoWithMetadata[] {\n if (!storedGatorPermissions) {\n return [];\n }\n\n return storedGatorPermissions.map((storedPermission) =>\n this.#storedPermissionToPermissionInfo(storedPermission),\n );\n }\n\n /**\n * Fetches granted permissions from the gator permissions provider Snap and updates state.\n * If a sync is already in progress, returns the same promise. After the sync completes,\n * the next call will perform a new sync.\n *\n * @returns A promise that resolves when the sync completes. All data is available via the controller's state.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public fetchAndUpdateGatorPermissions(): Promise<void> {\n if (this.#fetchAndUpdateGatorPermissionsPromise !== null) {\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n const performFetchAndUpdate = async (): Promise<void> => {\n try {\n this.#setIsFetchingGatorPermissions(true);\n\n // Only ever fetch non-revoked permissions. Revoked permissions may be\n // left in storage by the gator permissions snap, but we don't need to\n // fetch them.\n const params = { isRevoked: false };\n\n const permissionsData = await executeSnapRpc<\n StoredGatorPermission[] | null\n >({\n messenger: this.messenger,\n snapId: this.#gatorPermissionsProviderSnapId,\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n params,\n });\n\n const grantedPermissions =\n this.#storedPermissionsToPermissionInfoWithMetadata(permissionsData);\n\n this.update((state) => {\n state.grantedPermissions = grantedPermissions;\n state.lastSyncedTimestamp = Date.now();\n });\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n this.#fetchAndUpdateGatorPermissionsPromise = null;\n }\n };\n\n this.#fetchAndUpdateGatorPermissionsPromise = performFetchAndUpdate();\n\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n /**\n * Initializes the controller. Call once after construction to ensure the\n * controller is ready for use.\n *\n * @returns A promise that resolves when initialization is complete.\n */\n public async initialize(): Promise<void> {\n const currentTime = Date.now();\n const millisecondsSinceLastSync =\n currentTime - this.state.lastSyncedTimestamp;\n\n // Sync only when we have no data or data is stale, to avoid excessive startup\n // queries while still avoiding showing stale data while a refresh runs.\n if (\n this.state.lastSyncedTimestamp === -1 ||\n millisecondsSinceLastSync > this.#maxSyncIntervalMs\n ) {\n await this.fetchAndUpdateGatorPermissions();\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, to, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.#gatorPermissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n const permissionRules = createPermissionRulesForContracts(contracts);\n\n // find the single rule where the specified enforcers contain all the required enforcers\n // and no forbidden enforcers\n const matchingRule = findRuleWithMatchingCaveatAddresses({\n enforcers,\n permissionRules,\n });\n\n // validate the terms of each caveat against the matching rule, returning the decoded result\n // this happens in a single function, as decoding is an inherent part of validation.\n const decodeResult = matchingRule.validateAndDecodePermission(caveats);\n\n if (!decodeResult.isValid) {\n throw new PermissionDecodingError({\n cause: decodeResult.error,\n });\n }\n\n const { expiry, data } = decodeResult;\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType: matchingRule.permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n const snapRequest = {\n snapId: this.#gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions();\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to refresh permissions after transaction state change\n const refreshPermissions = (context: string): void => {\n this.fetchAndUpdateGatorPermissions().catch((error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n });\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = (): void => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true): void => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta): void => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n txHash: transactionMeta.hash,\n });\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n controllerLog('Transaction not confirmed, skipping revocation', {\n txId,\n permissionContext,\n status: transactionMeta.status,\n });\n cleanup(transactionMeta.id);\n refreshPermissions('transaction not confirmed');\n return;\n }\n\n const txHash = transactionMeta.hash as Hex | undefined;\n\n if (txHash === undefined) {\n controllerLog(\n 'Failed to resolve transaction hash after revocation transaction confirmed',\n {\n txId,\n permissionContext,\n error: new Error(\n 'Confirmed transaction is missing transaction hash',\n ),\n },\n );\n }\n\n this.submitRevocation({ permissionContext, txHash })\n .catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n })\n .finally(() => refreshPermissions('transaction confirmed'));\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction failed');\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction dropped');\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n const requestedPermissionContextLowercase = permissionContext.toLowerCase();\n\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n requestedPermissionContextLowercase,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController.cjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAKA,+DAA2D;AAC3D,6EAAuE;AAIvE,uDAAoD;AACpD,6EAAqE;AAUrE,+CAA2D;AAE3D,mEAI4B;AAC5B,yCAKkB;AAElB,yCAAyC;AACzC,uCAAwD;AASxD,uCAAyC;AAEzC,kBAAkB;AAElB,iCAAiC;AACjC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B,CAAC,MAAM,CACxD,CAAC,kBAAkB,EAAE,EAAE,CACrB,kBAAkB,CAAC,iBAAiB,CAAC,WAAW,EAAE;YAClD,iBAAiB,CAAC,WAAW,EAAE,CAClC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,uIAUC,qBAA4C;IAE5C,MAAM,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,GAClD,qBAAqB,CAAC;IACxB,MAAM,EACJ,YAAY,EAAE,aAAa,EAC3B,EAAE,EAAE,GAAG,EACP,GAAG,kBAAkB,EACtB,GAAG,sBAAsB,CAAC;IAE3B,OAAO;QACL,GAAG,qBAAqB;QACxB,kBAAkB;KACnB,CAAC;AACJ,CAAC,iKASC,sBAAsD;IAEtD,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,sBAAsB,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,CACrD,uBAAA,IAAI,2GAAkC,MAAtC,IAAI,EAAmC,gBAAgB,CAAC,CACzD,CAAC;AACJ,CAAC;AAoiBH,kBAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { DELEGATION_FRAMEWORK_VERSION } from './constants';\nimport type { DecodedPermission } from './decodePermission';\nimport {\n createPermissionRulesForContracts,\n findRuleWithMatchingCaveatAddresses,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport type { GatorPermissionsControllerMethodActions } from './GatorPermissionsController-method-action-types';\nimport { controllerLog } from './logger';\nimport { GatorPermissionsSnapRpcMethod } from './types';\nimport type {\n StoredGatorPermission,\n PermissionInfoWithMetadata,\n SupportedPermissionType,\n DelegationDetails,\n RevocationParams,\n PendingRevocationParams,\n} from './types';\nimport { executeSnapRpc } from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchAndUpdateGatorPermissions',\n 'initialize',\n 'decodePermissionFromPermissionContextForOrigin',\n 'submitRevocation',\n 'addPendingRevocation',\n 'submitDirectRevocation',\n 'isPendingRevocation',\n] as const;\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst DEFAULT_MAX_SYNC_INTERVAL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === CONFIG ===\n\n/**\n * Configuration for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerConfig = {\n /**\n * Permission types the controller supports (e.g. 'native-token-stream', 'erc20-token-periodic').\n */\n supportedPermissionTypes: SupportedPermissionType[];\n /**\n * Optional ID of the gator permissions provider Snap. Defaults to npm:@metamask/gator-permissions-snap.\n */\n gatorPermissionsProviderSnapId?: SnapId;\n /**\n * Optional maximum age of cached permissions (ms) before {@link GatorPermissionsController.initialize}\n * triggers a sync. Defaults to 30 days.\n */\n maxSyncIntervalMs?: number;\n};\n\n// === STATE ===\n\n/**\n * State shape for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerState = {\n /**\n * List of granted permissions with metadata (siteOrigin, revocationMetadata).\n */\n grantedPermissions: PermissionInfoWithMetadata[];\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This can be used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * List of gator permissions pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n\n /**\n * Timestamp (ms) of the last successful sync of gator permissions from profile sync.\n * -1 indicates that a sync has never completed successfully.\n */\n lastSyncedTimestamp: number;\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n grantedPermissions: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSyncedTimestamp: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Creates initial controller state, merging defaults with optional partial state.\n * Internal use only (e.g. constructor, tests).\n *\n * @param state - Optional partial state to merge with defaults.\n * @returns Complete {@link GatorPermissionsController} state.\n */\nfunction createGatorPermissionsControllerState(\n state?: Partial<GatorPermissionsControllerState>,\n): GatorPermissionsControllerState {\n return {\n grantedPermissions: [],\n pendingRevocations: [],\n lastSyncedTimestamp: -1,\n ...state,\n // isFetchingGatorPermissions is _always_ false when the controller is created\n isFetchingGatorPermissions: false,\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerMethodActions;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapController:handleRequest and SnapController: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 the gator permissions provider Snap.\n */\nexport class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n readonly #supportedPermissionTypes: readonly SupportedPermissionType[];\n\n /**\n * The Snap ID of the gator permissions provider.\n *\n * @returns The Snap ID of the gator permissions provider.\n */\n get gatorPermissionsProviderSnapId(): SnapId {\n return this.#gatorPermissionsProviderSnapId;\n }\n\n readonly #gatorPermissionsProviderSnapId: SnapId;\n\n readonly #maxSyncIntervalMs: number;\n\n /**\n * When a sync is in progress, holds the promise for that sync so concurrent\n * callers receive the same promise. Cleared when the sync completes.\n */\n #fetchAndUpdateGatorPermissionsPromise: Promise<void> | null = null;\n\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with other controllers.\n * @param args.config - Configuration (supported permission types and optional Snap id).\n * @param args.state - Optional partial state to merge with defaults.\n */\n constructor({\n messenger,\n config,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n config: GatorPermissionsControllerConfig;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n const initialState = createGatorPermissionsControllerState(state);\n\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: initialState,\n });\n\n this.#supportedPermissionTypes = config.supportedPermissionTypes;\n this.#gatorPermissionsProviderSnapId =\n config.gatorPermissionsProviderSnapId ??\n defaultGatorPermissionsProviderSnapId;\n this.#maxSyncIntervalMs =\n config.maxSyncIntervalMs ?? DEFAULT_MAX_SYNC_INTERVAL_MS;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Supported permission types this controller was configured with.\n *\n * @returns The supported permission types.\n */\n get supportedPermissionTypes(): readonly SupportedPermissionType[] {\n return this.#supportedPermissionTypes;\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean): void {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex): void {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(\n permissionContext: Hex,\n ): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n /**\n * Converts a stored gator permission to permission info with metadata.\n * Strips internal fields (dependencies, to) from the permission response.\n *\n * @param storedGatorPermission - The stored gator permission from the Snap.\n * @returns Permission info with metadata for state/UI.\n */\n #storedPermissionToPermissionInfo(\n storedGatorPermission: StoredGatorPermission,\n ): PermissionInfoWithMetadata {\n const { permissionResponse: fullPermissionResponse } =\n storedGatorPermission;\n const {\n dependencies: _dependencies,\n to: _to,\n ...permissionResponse\n } = fullPermissionResponse;\n\n return {\n ...storedGatorPermission,\n permissionResponse,\n };\n }\n\n /**\n * Converts stored gator permissions from the Snap into permission info with metadata.\n *\n * @param storedGatorPermissions - Stored gator permissions returned by the Snap, or null.\n * @returns Array of permission info with metadata for state.\n */\n #storedPermissionsToPermissionInfoWithMetadata(\n storedGatorPermissions: StoredGatorPermission[] | null,\n ): PermissionInfoWithMetadata[] {\n if (!storedGatorPermissions) {\n return [];\n }\n\n return storedGatorPermissions.map((storedPermission) =>\n this.#storedPermissionToPermissionInfo(storedPermission),\n );\n }\n\n /**\n * Fetches granted permissions from the gator permissions provider Snap and updates state.\n * If a sync is already in progress, returns the same promise. After the sync completes,\n * the next call will perform a new sync.\n *\n * @returns A promise that resolves when the sync completes. All data is available via the controller's state.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public fetchAndUpdateGatorPermissions(): Promise<void> {\n if (this.#fetchAndUpdateGatorPermissionsPromise !== null) {\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n const performFetchAndUpdate = async (): Promise<void> => {\n try {\n this.#setIsFetchingGatorPermissions(true);\n\n // Only ever fetch non-revoked permissions. Revoked permissions may be\n // left in storage by the gator permissions snap, but we don't need to\n // fetch them.\n const params = { isRevoked: false };\n\n const permissionsData = await executeSnapRpc<\n StoredGatorPermission[] | null\n >({\n messenger: this.messenger,\n snapId: this.#gatorPermissionsProviderSnapId,\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n params,\n });\n\n const grantedPermissions =\n this.#storedPermissionsToPermissionInfoWithMetadata(permissionsData);\n\n this.update((state) => {\n state.grantedPermissions = grantedPermissions;\n state.lastSyncedTimestamp = Date.now();\n });\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n this.#fetchAndUpdateGatorPermissionsPromise = null;\n }\n };\n\n this.#fetchAndUpdateGatorPermissionsPromise = performFetchAndUpdate();\n\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n /**\n * Initializes the controller. Call once after construction to ensure the\n * controller is ready for use.\n *\n * @returns A promise that resolves when initialization is complete.\n */\n public async initialize(): Promise<void> {\n const currentTime = Date.now();\n const millisecondsSinceLastSync =\n currentTime - this.state.lastSyncedTimestamp;\n\n // Sync only when we have no data or data is stale, to avoid excessive startup\n // queries while still avoiding showing stale data while a refresh runs.\n if (\n this.state.lastSyncedTimestamp === -1 ||\n millisecondsSinceLastSync > this.#maxSyncIntervalMs\n ) {\n await this.fetchAndUpdateGatorPermissions();\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, to, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.#gatorPermissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n const permissionRules = createPermissionRulesForContracts(contracts);\n\n // find the single rule where the specified enforcers contain all the required enforcers\n // and no forbidden enforcers\n const matchingRule = findRuleWithMatchingCaveatAddresses({\n enforcers,\n permissionRules,\n });\n\n // validate the terms of each caveat against the matching rule, returning the decoded result\n // this happens in a single function, as decoding is an inherent part of validation.\n const decodeResult = matchingRule.validateAndDecodePermission(caveats);\n\n if (!decodeResult.isValid) {\n throw new PermissionDecodingError({\n cause: decodeResult.error,\n });\n }\n\n const { expiry, data } = decodeResult;\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType: matchingRule.permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n const snapRequest = {\n snapId: this.#gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions();\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to refresh permissions after transaction state change\n const refreshPermissions = (context: string): void => {\n this.fetchAndUpdateGatorPermissions().catch((error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n });\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = (): void => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true): void => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta): void => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n txHash: transactionMeta.hash,\n });\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n controllerLog('Transaction not confirmed, skipping revocation', {\n txId,\n permissionContext,\n status: transactionMeta.status,\n });\n cleanup(transactionMeta.id);\n refreshPermissions('transaction not confirmed');\n return;\n }\n\n const txHash = transactionMeta.hash as Hex | undefined;\n\n if (txHash === undefined) {\n controllerLog(\n 'Failed to resolve transaction hash after revocation transaction confirmed',\n {\n txId,\n permissionContext,\n error: new Error(\n 'Confirmed transaction is missing transaction hash',\n ),\n },\n );\n }\n\n this.submitRevocation({ permissionContext, txHash })\n .catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n })\n .finally(() => refreshPermissions('transaction confirmed'));\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction failed');\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction dropped');\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n const requestedPermissionContextLowercase = permissionContext.toLowerCase();\n\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n requestedPermissionContextLowercase,\n );\n }\n}\n\nexport default GatorPermissionsController;\n"]}
|
|
@@ -6,6 +6,7 @@ import type { SnapId } from "@metamask/snaps-sdk";
|
|
|
6
6
|
import type { TransactionControllerTransactionApprovedEvent, TransactionControllerTransactionConfirmedEvent, TransactionControllerTransactionDroppedEvent, TransactionControllerTransactionFailedEvent, TransactionControllerTransactionRejectedEvent } from "@metamask/transaction-controller";
|
|
7
7
|
import type { Hex } from "@metamask/utils";
|
|
8
8
|
import type { DecodedPermission } from "./decodePermission/index.cjs";
|
|
9
|
+
import type { GatorPermissionsControllerMethodActions } from "./GatorPermissionsController-method-action-types.cjs";
|
|
9
10
|
import type { PermissionInfoWithMetadata, SupportedPermissionType, DelegationDetails, RevocationParams, PendingRevocationParams } from "./types.cjs";
|
|
10
11
|
declare const controllerName = "GatorPermissionsController";
|
|
11
12
|
/**
|
|
@@ -57,51 +58,11 @@ export type GatorPermissionsControllerState = {
|
|
|
57
58
|
* {@link GatorPermissionsController}.
|
|
58
59
|
*/
|
|
59
60
|
export type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<typeof controllerName, GatorPermissionsControllerState>;
|
|
60
|
-
/**
|
|
61
|
-
* The action which can be used to fetch and update gator permissions.
|
|
62
|
-
*/
|
|
63
|
-
export type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {
|
|
64
|
-
type: `${typeof controllerName}:fetchAndUpdateGatorPermissions`;
|
|
65
|
-
handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];
|
|
66
|
-
};
|
|
67
|
-
export type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction = {
|
|
68
|
-
type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;
|
|
69
|
-
handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* The action which can be used to submit a revocation.
|
|
73
|
-
*/
|
|
74
|
-
export type GatorPermissionsControllerSubmitRevocationAction = {
|
|
75
|
-
type: `${typeof controllerName}:submitRevocation`;
|
|
76
|
-
handler: GatorPermissionsController['submitRevocation'];
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* The action which can be used to add a pending revocation.
|
|
80
|
-
*/
|
|
81
|
-
export type GatorPermissionsControllerAddPendingRevocationAction = {
|
|
82
|
-
type: `${typeof controllerName}:addPendingRevocation`;
|
|
83
|
-
handler: GatorPermissionsController['addPendingRevocation'];
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* The action which can be used to submit a revocation directly without requiring
|
|
87
|
-
* an on-chain transaction (for already-disabled delegations).
|
|
88
|
-
*/
|
|
89
|
-
export type GatorPermissionsControllerSubmitDirectRevocationAction = {
|
|
90
|
-
type: `${typeof controllerName}:submitDirectRevocation`;
|
|
91
|
-
handler: GatorPermissionsController['submitDirectRevocation'];
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* The action which can be used to check if a permission context is pending revocation.
|
|
95
|
-
*/
|
|
96
|
-
export type GatorPermissionsControllerIsPendingRevocationAction = {
|
|
97
|
-
type: `${typeof controllerName}:isPendingRevocation`;
|
|
98
|
-
handler: GatorPermissionsController['isPendingRevocation'];
|
|
99
|
-
};
|
|
100
61
|
/**
|
|
101
62
|
* All actions that {@link GatorPermissionsController} registers, to be called
|
|
102
63
|
* externally.
|
|
103
64
|
*/
|
|
104
|
-
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction |
|
|
65
|
+
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerMethodActions;
|
|
105
66
|
/**
|
|
106
67
|
* All actions that {@link GatorPermissionsController} calls internally.
|
|
107
68
|
*
|
|
@@ -129,7 +90,7 @@ export type GatorPermissionsControllerMessenger = Messenger<typeof controllerNam
|
|
|
129
90
|
/**
|
|
130
91
|
* Controller that manages gator permissions by reading from the gator permissions provider Snap.
|
|
131
92
|
*/
|
|
132
|
-
export
|
|
93
|
+
export declare class GatorPermissionsController extends BaseController<typeof controllerName, GatorPermissionsControllerState, GatorPermissionsControllerMessenger> {
|
|
133
94
|
#private;
|
|
134
95
|
/**
|
|
135
96
|
* The Snap ID of the gator permissions provider.
|
|
@@ -250,5 +211,5 @@ export default class GatorPermissionsController extends BaseController<typeof co
|
|
|
250
211
|
*/
|
|
251
212
|
isPendingRevocation(permissionContext: Hex): boolean;
|
|
252
213
|
}
|
|
253
|
-
export
|
|
214
|
+
export default GatorPermissionsController;
|
|
254
215
|
//# sourceMappingURL=GatorPermissionsController.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatorPermissionsController.d.cts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,oCAAoC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAGlD,OAAO,KAAK,EACV,6CAA6C,EAC7C,8CAA8C,EAC9C,4CAA4C,EAC5C,2CAA2C,EAC3C,6CAA6C,EAC9C,yCAAyC;AAC1C,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAG3C,OAAO,KAAK,EAAE,iBAAiB,EAAE,qCAA2B;
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController.d.cts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"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,EACN,OAAO,EACP,UAAU,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,EACvD,QAAQ,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,eAAe,EAAE,GACrD,EAAE;QACD,MAAM,EAAE,MAAM,CAAC;QACf,OAAO,EAAE,MAAM,CAAC;QAChB,QAAQ,EAAE;YACR,aAAa,EAAE,MAAM,CAAC;YACtB,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC;QACF,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,iBAAiB;IAsDrB;;;;;;OAMG;IACU,gBAAgB,CAC3B,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,IAAI,CAAC;IAkEhB;;;;;;;;;;;;;;;;OAgBG;IACU,oBAAoB,CAC/B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,IAAI,CAAC;IAmPhB;;;;;;;;;;;;;OAaG;IACU,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC;IAc5E;;;;;OAKG;IACI,mBAAmB,CAAC,iBAAiB,EAAE,GAAG,GAAG,OAAO;CAS5D;AAED,eAAe,0BAA0B,CAAC"}
|
|
@@ -6,6 +6,7 @@ import type { SnapId } from "@metamask/snaps-sdk";
|
|
|
6
6
|
import type { TransactionControllerTransactionApprovedEvent, TransactionControllerTransactionConfirmedEvent, TransactionControllerTransactionDroppedEvent, TransactionControllerTransactionFailedEvent, TransactionControllerTransactionRejectedEvent } from "@metamask/transaction-controller";
|
|
7
7
|
import type { Hex } from "@metamask/utils";
|
|
8
8
|
import type { DecodedPermission } from "./decodePermission/index.mjs";
|
|
9
|
+
import type { GatorPermissionsControllerMethodActions } from "./GatorPermissionsController-method-action-types.mjs";
|
|
9
10
|
import type { PermissionInfoWithMetadata, SupportedPermissionType, DelegationDetails, RevocationParams, PendingRevocationParams } from "./types.mjs";
|
|
10
11
|
declare const controllerName = "GatorPermissionsController";
|
|
11
12
|
/**
|
|
@@ -57,51 +58,11 @@ export type GatorPermissionsControllerState = {
|
|
|
57
58
|
* {@link GatorPermissionsController}.
|
|
58
59
|
*/
|
|
59
60
|
export type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<typeof controllerName, GatorPermissionsControllerState>;
|
|
60
|
-
/**
|
|
61
|
-
* The action which can be used to fetch and update gator permissions.
|
|
62
|
-
*/
|
|
63
|
-
export type GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction = {
|
|
64
|
-
type: `${typeof controllerName}:fetchAndUpdateGatorPermissions`;
|
|
65
|
-
handler: GatorPermissionsController['fetchAndUpdateGatorPermissions'];
|
|
66
|
-
};
|
|
67
|
-
export type GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction = {
|
|
68
|
-
type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;
|
|
69
|
-
handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* The action which can be used to submit a revocation.
|
|
73
|
-
*/
|
|
74
|
-
export type GatorPermissionsControllerSubmitRevocationAction = {
|
|
75
|
-
type: `${typeof controllerName}:submitRevocation`;
|
|
76
|
-
handler: GatorPermissionsController['submitRevocation'];
|
|
77
|
-
};
|
|
78
|
-
/**
|
|
79
|
-
* The action which can be used to add a pending revocation.
|
|
80
|
-
*/
|
|
81
|
-
export type GatorPermissionsControllerAddPendingRevocationAction = {
|
|
82
|
-
type: `${typeof controllerName}:addPendingRevocation`;
|
|
83
|
-
handler: GatorPermissionsController['addPendingRevocation'];
|
|
84
|
-
};
|
|
85
|
-
/**
|
|
86
|
-
* The action which can be used to submit a revocation directly without requiring
|
|
87
|
-
* an on-chain transaction (for already-disabled delegations).
|
|
88
|
-
*/
|
|
89
|
-
export type GatorPermissionsControllerSubmitDirectRevocationAction = {
|
|
90
|
-
type: `${typeof controllerName}:submitDirectRevocation`;
|
|
91
|
-
handler: GatorPermissionsController['submitDirectRevocation'];
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* The action which can be used to check if a permission context is pending revocation.
|
|
95
|
-
*/
|
|
96
|
-
export type GatorPermissionsControllerIsPendingRevocationAction = {
|
|
97
|
-
type: `${typeof controllerName}:isPendingRevocation`;
|
|
98
|
-
handler: GatorPermissionsController['isPendingRevocation'];
|
|
99
|
-
};
|
|
100
61
|
/**
|
|
101
62
|
* All actions that {@link GatorPermissionsController} registers, to be called
|
|
102
63
|
* externally.
|
|
103
64
|
*/
|
|
104
|
-
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction |
|
|
65
|
+
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerMethodActions;
|
|
105
66
|
/**
|
|
106
67
|
* All actions that {@link GatorPermissionsController} calls internally.
|
|
107
68
|
*
|
|
@@ -129,7 +90,7 @@ export type GatorPermissionsControllerMessenger = Messenger<typeof controllerNam
|
|
|
129
90
|
/**
|
|
130
91
|
* Controller that manages gator permissions by reading from the gator permissions provider Snap.
|
|
131
92
|
*/
|
|
132
|
-
export
|
|
93
|
+
export declare class GatorPermissionsController extends BaseController<typeof controllerName, GatorPermissionsControllerState, GatorPermissionsControllerMessenger> {
|
|
133
94
|
#private;
|
|
134
95
|
/**
|
|
135
96
|
* The Snap ID of the gator permissions provider.
|
|
@@ -250,5 +211,5 @@ export default class GatorPermissionsController extends BaseController<typeof co
|
|
|
250
211
|
*/
|
|
251
212
|
isPendingRevocation(permissionContext: Hex): boolean;
|
|
252
213
|
}
|
|
253
|
-
export
|
|
214
|
+
export default GatorPermissionsController;
|
|
254
215
|
//# sourceMappingURL=GatorPermissionsController.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatorPermissionsController.d.mts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,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"}
|
|
@@ -9,7 +9,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _GatorPermissionsController_instances, _GatorPermissionsController_supportedPermissionTypes, _GatorPermissionsController_gatorPermissionsProviderSnapId, _GatorPermissionsController_maxSyncIntervalMs, _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext,
|
|
12
|
+
var _GatorPermissionsController_instances, _GatorPermissionsController_supportedPermissionTypes, _GatorPermissionsController_gatorPermissionsProviderSnapId, _GatorPermissionsController_maxSyncIntervalMs, _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext, _GatorPermissionsController_storedPermissionToPermissionInfo, _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
14
|
import { DELEGATOR_CONTRACTS } from "@metamask/delegation-deployments";
|
|
15
15
|
import { HandlerType } from "@metamask/snaps-utils";
|
|
@@ -23,6 +23,15 @@ import { executeSnapRpc } from "./utils.mjs";
|
|
|
23
23
|
// === GENERAL ===
|
|
24
24
|
// Unique name for the controller
|
|
25
25
|
const controllerName = 'GatorPermissionsController';
|
|
26
|
+
const MESSENGER_EXPOSED_METHODS = [
|
|
27
|
+
'fetchAndUpdateGatorPermissions',
|
|
28
|
+
'initialize',
|
|
29
|
+
'decodePermissionFromPermissionContextForOrigin',
|
|
30
|
+
'submitRevocation',
|
|
31
|
+
'addPendingRevocation',
|
|
32
|
+
'submitDirectRevocation',
|
|
33
|
+
'isPendingRevocation',
|
|
34
|
+
];
|
|
26
35
|
// Default value for the gator permissions provider snap id
|
|
27
36
|
const defaultGatorPermissionsProviderSnapId = 'npm:@metamask/gator-permissions-snap';
|
|
28
37
|
const DEFAULT_MAX_SYNC_INTERVAL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds
|
|
@@ -78,7 +87,7 @@ function createGatorPermissionsControllerState(state) {
|
|
|
78
87
|
/**
|
|
79
88
|
* Controller that manages gator permissions by reading from the gator permissions provider Snap.
|
|
80
89
|
*/
|
|
81
|
-
class GatorPermissionsController extends BaseController {
|
|
90
|
+
export class GatorPermissionsController extends BaseController {
|
|
82
91
|
/**
|
|
83
92
|
* The Snap ID of the gator permissions provider.
|
|
84
93
|
*
|
|
@@ -116,7 +125,7 @@ class GatorPermissionsController extends BaseController {
|
|
|
116
125
|
__classPrivateFieldSet(this, _GatorPermissionsController_gatorPermissionsProviderSnapId, config.gatorPermissionsProviderSnapId ??
|
|
117
126
|
defaultGatorPermissionsProviderSnapId, "f");
|
|
118
127
|
__classPrivateFieldSet(this, _GatorPermissionsController_maxSyncIntervalMs, config.maxSyncIntervalMs ?? DEFAULT_MAX_SYNC_INTERVAL_MS, "f");
|
|
119
|
-
|
|
128
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
120
129
|
}
|
|
121
130
|
/**
|
|
122
131
|
* Supported permission types this controller was configured with.
|
|
@@ -537,14 +546,6 @@ _GatorPermissionsController_supportedPermissionTypes = new WeakMap(), _GatorPerm
|
|
|
537
546
|
state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext.toLowerCase() !==
|
|
538
547
|
permissionContext.toLowerCase());
|
|
539
548
|
});
|
|
540
|
-
}, _GatorPermissionsController_registerMessageHandlers = function _GatorPermissionsController_registerMessageHandlers() {
|
|
541
|
-
this.messenger.registerActionHandler(`${controllerName}:fetchAndUpdateGatorPermissions`, this.fetchAndUpdateGatorPermissions.bind(this));
|
|
542
|
-
this.messenger.registerActionHandler(`${controllerName}:decodePermissionFromPermissionContextForOrigin`, this.decodePermissionFromPermissionContextForOrigin.bind(this));
|
|
543
|
-
const submitRevocationAction = `${controllerName}:submitRevocation`;
|
|
544
|
-
this.messenger.registerActionHandler(submitRevocationAction, this.submitRevocation.bind(this));
|
|
545
|
-
this.messenger.registerActionHandler(`${controllerName}:addPendingRevocation`, this.addPendingRevocation.bind(this));
|
|
546
|
-
this.messenger.registerActionHandler(`${controllerName}:submitDirectRevocation`, this.submitDirectRevocation.bind(this));
|
|
547
|
-
this.messenger.registerActionHandler(`${controllerName}:isPendingRevocation`, this.isPendingRevocation.bind(this));
|
|
548
549
|
}, _GatorPermissionsController_storedPermissionToPermissionInfo = function _GatorPermissionsController_storedPermissionToPermissionInfo(storedGatorPermission) {
|
|
549
550
|
const { permissionResponse: fullPermissionResponse } = storedGatorPermission;
|
|
550
551
|
const { dependencies: _dependencies, to: _to, ...permissionResponse } = fullPermissionResponse;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatorPermissionsController.mjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAIvE,OAAO,EAAE,WAAW,EAAE,8BAA8B;AACpD,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;AAUrE,OAAO,EAAE,4BAA4B,EAAE,wBAAoB;AAE3D,OAAO,EACL,iCAAiC,EACjC,mCAAmC,EACnC,4BAA4B,EAC7B,qCAA2B;AAC5B,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,qBAAqB,EACrB,uBAAuB,EACxB,qBAAiB;A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BAAsB,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,CACrD,uBAAA,IAAI,2GAAkC,MAAtC,IAAI,EAAmC,gBAAgB,CAAC,CACzD,CAAC;AACJ,CAAC;eAnLkB,0BAA0B","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { DELEGATION_FRAMEWORK_VERSION } from './constants';\nimport type { DecodedPermission } from './decodePermission';\nimport {\n createPermissionRulesForContracts,\n findRuleWithMatchingCaveatAddresses,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport { controllerLog } from './logger';\nimport { GatorPermissionsSnapRpcMethod } from './types';\nimport type {\n StoredGatorPermission,\n PermissionInfoWithMetadata,\n SupportedPermissionType,\n DelegationDetails,\n RevocationParams,\n PendingRevocationParams,\n} from './types';\nimport { executeSnapRpc } from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst DEFAULT_MAX_SYNC_INTERVAL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === CONFIG ===\n\n/**\n * Configuration for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerConfig = {\n /**\n * Permission types the controller supports (e.g. 'native-token-stream', 'erc20-token-periodic').\n */\n supportedPermissionTypes: SupportedPermissionType[];\n /**\n * Optional ID of the gator permissions provider Snap. Defaults to npm:@metamask/gator-permissions-snap.\n */\n gatorPermissionsProviderSnapId?: SnapId;\n /**\n * Optional maximum age of cached permissions (ms) before {@link GatorPermissionsController.initialize}\n * triggers a sync. Defaults to 30 days.\n */\n maxSyncIntervalMs?: number;\n};\n\n// === STATE ===\n\n/**\n * State shape for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerState = {\n /**\n * List of granted permissions with metadata (siteOrigin, revocationMetadata).\n */\n grantedPermissions: PermissionInfoWithMetadata[];\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This can be used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * List of gator permissions pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n\n /**\n * Timestamp (ms) of the last successful sync of gator permissions from profile sync.\n * -1 indicates that a sync has never completed successfully.\n */\n lastSyncedTimestamp: number;\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n grantedPermissions: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSyncedTimestamp: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Creates initial controller state, merging defaults with optional partial state.\n * Internal use only (e.g. constructor, tests).\n *\n * @param state - Optional partial state to merge with defaults.\n * @returns Complete {@link GatorPermissionsController} state.\n */\nfunction createGatorPermissionsControllerState(\n state?: Partial<GatorPermissionsControllerState>,\n): GatorPermissionsControllerState {\n return {\n grantedPermissions: [],\n pendingRevocations: [],\n lastSyncedTimestamp: -1,\n ...state,\n // isFetchingGatorPermissions is _always_ false when the controller is created\n isFetchingGatorPermissions: false,\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * 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\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 | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction\n | GatorPermissionsControllerSubmitRevocationAction\n | GatorPermissionsControllerAddPendingRevocationAction\n | GatorPermissionsControllerSubmitDirectRevocationAction\n | GatorPermissionsControllerIsPendingRevocationAction;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapController:handleRequest and SnapController: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 the gator permissions provider Snap.\n */\nexport default class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n readonly #supportedPermissionTypes: readonly SupportedPermissionType[];\n\n /**\n * The Snap ID of the gator permissions provider.\n *\n * @returns The Snap ID of the gator permissions provider.\n */\n get gatorPermissionsProviderSnapId(): SnapId {\n return this.#gatorPermissionsProviderSnapId;\n }\n\n readonly #gatorPermissionsProviderSnapId: SnapId;\n\n readonly #maxSyncIntervalMs: number;\n\n /**\n * When a sync is in progress, holds the promise for that sync so concurrent\n * callers receive the same promise. Cleared when the sync completes.\n */\n #fetchAndUpdateGatorPermissionsPromise: Promise<void> | null = null;\n\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with other controllers.\n * @param args.config - Configuration (supported permission types and optional Snap id).\n * @param args.state - Optional partial state to merge with defaults.\n */\n constructor({\n messenger,\n config,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n config: GatorPermissionsControllerConfig;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n const initialState = createGatorPermissionsControllerState(state);\n\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: initialState,\n });\n\n this.#supportedPermissionTypes = config.supportedPermissionTypes;\n this.#gatorPermissionsProviderSnapId =\n config.gatorPermissionsProviderSnapId ??\n defaultGatorPermissionsProviderSnapId;\n this.#maxSyncIntervalMs =\n config.maxSyncIntervalMs ?? DEFAULT_MAX_SYNC_INTERVAL_MS;\n this.#registerMessageHandlers();\n }\n\n /**\n * Supported permission types this controller was configured with.\n *\n * @returns The supported permission types.\n */\n get supportedPermissionTypes(): readonly SupportedPermissionType[] {\n return this.#supportedPermissionTypes;\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean): void {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex): void {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(\n permissionContext: Hex,\n ): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n #registerMessageHandlers(): void {\n this.messenger.registerActionHandler(\n `${controllerName}:fetchAndUpdateGatorPermissions`,\n this.fetchAndUpdateGatorPermissions.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 * Converts a stored gator permission to permission info with metadata.\n * Strips internal fields (dependencies, to) from the permission response.\n *\n * @param storedGatorPermission - The stored gator permission from the Snap.\n * @returns Permission info with metadata for state/UI.\n */\n #storedPermissionToPermissionInfo(\n storedGatorPermission: StoredGatorPermission,\n ): PermissionInfoWithMetadata {\n const { permissionResponse: fullPermissionResponse } =\n storedGatorPermission;\n const {\n dependencies: _dependencies,\n to: _to,\n ...permissionResponse\n } = fullPermissionResponse;\n\n return {\n ...storedGatorPermission,\n permissionResponse,\n };\n }\n\n /**\n * Converts stored gator permissions from the Snap into permission info with metadata.\n *\n * @param storedGatorPermissions - Stored gator permissions returned by the Snap, or null.\n * @returns Array of permission info with metadata for state.\n */\n #storedPermissionsToPermissionInfoWithMetadata(\n storedGatorPermissions: StoredGatorPermission[] | null,\n ): PermissionInfoWithMetadata[] {\n if (!storedGatorPermissions) {\n return [];\n }\n\n return storedGatorPermissions.map((storedPermission) =>\n this.#storedPermissionToPermissionInfo(storedPermission),\n );\n }\n\n /**\n * Fetches granted permissions from the gator permissions provider Snap and updates state.\n * If a sync is already in progress, returns the same promise. After the sync completes,\n * the next call will perform a new sync.\n *\n * @returns A promise that resolves when the sync completes. All data is available via the controller's state.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public fetchAndUpdateGatorPermissions(): Promise<void> {\n if (this.#fetchAndUpdateGatorPermissionsPromise !== null) {\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n const performFetchAndUpdate = async (): Promise<void> => {\n try {\n this.#setIsFetchingGatorPermissions(true);\n\n // Only ever fetch non-revoked permissions. Revoked permissions may be\n // left in storage by the gator permissions snap, but we don't need to\n // fetch them.\n const params = { isRevoked: false };\n\n const permissionsData = await executeSnapRpc<\n StoredGatorPermission[] | null\n >({\n messenger: this.messenger,\n snapId: this.#gatorPermissionsProviderSnapId,\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n params,\n });\n\n const grantedPermissions =\n this.#storedPermissionsToPermissionInfoWithMetadata(permissionsData);\n\n this.update((state) => {\n state.grantedPermissions = grantedPermissions;\n state.lastSyncedTimestamp = Date.now();\n });\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n this.#fetchAndUpdateGatorPermissionsPromise = null;\n }\n };\n\n this.#fetchAndUpdateGatorPermissionsPromise = performFetchAndUpdate();\n\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n /**\n * Initializes the controller. Call once after construction to ensure the\n * controller is ready for use.\n *\n * @returns A promise that resolves when initialization is complete.\n */\n public async initialize(): Promise<void> {\n const currentTime = Date.now();\n const millisecondsSinceLastSync =\n currentTime - this.state.lastSyncedTimestamp;\n\n // Sync only when we have no data or data is stale, to avoid excessive startup\n // queries while still avoiding showing stale data while a refresh runs.\n if (\n this.state.lastSyncedTimestamp === -1 ||\n millisecondsSinceLastSync > this.#maxSyncIntervalMs\n ) {\n await this.fetchAndUpdateGatorPermissions();\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, to, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.#gatorPermissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n const permissionRules = createPermissionRulesForContracts(contracts);\n\n // find the single rule where the specified enforcers contain all the required enforcers\n // and no forbidden enforcers\n const matchingRule = findRuleWithMatchingCaveatAddresses({\n enforcers,\n permissionRules,\n });\n\n // validate the terms of each caveat against the matching rule, returning the decoded result\n // this happens in a single function, as decoding is an inherent part of validation.\n const decodeResult = matchingRule.validateAndDecodePermission(caveats);\n\n if (!decodeResult.isValid) {\n throw new PermissionDecodingError({\n cause: decodeResult.error,\n });\n }\n\n const { expiry, data } = decodeResult;\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType: matchingRule.permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n const snapRequest = {\n snapId: this.#gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions();\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to refresh permissions after transaction state change\n const refreshPermissions = (context: string): void => {\n this.fetchAndUpdateGatorPermissions().catch((error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n });\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = (): void => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true): void => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta): void => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n txHash: transactionMeta.hash,\n });\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n controllerLog('Transaction not confirmed, skipping revocation', {\n txId,\n permissionContext,\n status: transactionMeta.status,\n });\n cleanup(transactionMeta.id);\n refreshPermissions('transaction not confirmed');\n return;\n }\n\n const txHash = transactionMeta.hash as Hex | undefined;\n\n if (txHash === undefined) {\n controllerLog(\n 'Failed to resolve transaction hash after revocation transaction confirmed',\n {\n txId,\n permissionContext,\n error: new Error(\n 'Confirmed transaction is missing transaction hash',\n ),\n },\n );\n }\n\n this.submitRevocation({ permissionContext, txHash })\n .catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n })\n .finally(() => refreshPermissions('transaction confirmed'));\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction failed');\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction dropped');\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n const requestedPermissionContextLowercase = permissionContext.toLowerCase();\n\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n requestedPermissionContextLowercase,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController.mjs","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,yCAAyC;AAIvE,OAAO,EAAE,WA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AAkB,CAAC,MAAM,CACxD,CAAC,kBAAkB,EAAE,EAAE,CAAC,kBAAkB,CAAC,IAAI,KAAK,IAAI,CACzD,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,6KAGC,iBAAsB;IAEtB,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,KAAK,CAAC,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,CAAC,MAAM,CACxD,CAAC,kBAAkB,EAAE,EAAE,CACrB,kBAAkB,CAAC,iBAAiB,CAAC,WAAW,EAAE;YAClD,iBAAiB,CAAC,WAAW,EAAE,CAClC,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,uIAUC,qBAA4C;IAE5C,MAAM,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,GAClD,qBAAqB,CAAC;IACxB,MAAM,EACJ,YAAY,EAAE,aAAa,EAC3B,EAAE,EAAE,GAAG,EACP,GAAG,kBAAkB,EACtB,GAAG,sBAAsB,CAAC;IAE3B,OAAO;QACL,GAAG,qBAAqB;QACxB,kBAAkB;KACnB,CAAC;AACJ,CAAC,iKASC,sBAAsD;IAEtD,IAAI,CAAC,sBAAsB,EAAE,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,OAAO,sBAAsB,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,CACrD,uBAAA,IAAI,2GAAkC,MAAtC,IAAI,EAAmC,gBAAgB,CAAC,CACzD,CAAC;AACJ,CAAC;AAoiBH,eAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport type { Messenger } from '@metamask/messenger';\nimport type { HandleSnapRequest, HasSnap } from '@metamask/snaps-controllers';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { HandlerType } from '@metamask/snaps-utils';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport type {\n TransactionControllerTransactionApprovedEvent,\n TransactionControllerTransactionConfirmedEvent,\n TransactionControllerTransactionDroppedEvent,\n TransactionControllerTransactionFailedEvent,\n TransactionControllerTransactionRejectedEvent,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { DELEGATION_FRAMEWORK_VERSION } from './constants';\nimport type { DecodedPermission } from './decodePermission';\nimport {\n createPermissionRulesForContracts,\n findRuleWithMatchingCaveatAddresses,\n reconstructDecodedPermission,\n} from './decodePermission';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors';\nimport type { GatorPermissionsControllerMethodActions } from './GatorPermissionsController-method-action-types';\nimport { controllerLog } from './logger';\nimport { GatorPermissionsSnapRpcMethod } from './types';\nimport type {\n StoredGatorPermission,\n PermissionInfoWithMetadata,\n SupportedPermissionType,\n DelegationDetails,\n RevocationParams,\n PendingRevocationParams,\n} from './types';\nimport { executeSnapRpc } from './utils';\n\n// === GENERAL ===\n\n// Unique name for the controller\nconst controllerName = 'GatorPermissionsController';\n\nconst MESSENGER_EXPOSED_METHODS = [\n 'fetchAndUpdateGatorPermissions',\n 'initialize',\n 'decodePermissionFromPermissionContextForOrigin',\n 'submitRevocation',\n 'addPendingRevocation',\n 'submitDirectRevocation',\n 'isPendingRevocation',\n] as const;\n\n// Default value for the gator permissions provider snap id\nconst defaultGatorPermissionsProviderSnapId =\n 'npm:@metamask/gator-permissions-snap' as SnapId;\n\nconst DEFAULT_MAX_SYNC_INTERVAL_MS = 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds\n\n/**\n * Timeout duration for pending revocations (2 hours in milliseconds).\n * After this time, event listeners will be cleaned up to prevent memory leaks.\n */\nconst PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;\n\nconst contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];\n\n// === CONFIG ===\n\n/**\n * Configuration for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerConfig = {\n /**\n * Permission types the controller supports (e.g. 'native-token-stream', 'erc20-token-periodic').\n */\n supportedPermissionTypes: SupportedPermissionType[];\n /**\n * Optional ID of the gator permissions provider Snap. Defaults to npm:@metamask/gator-permissions-snap.\n */\n gatorPermissionsProviderSnapId?: SnapId;\n /**\n * Optional maximum age of cached permissions (ms) before {@link GatorPermissionsController.initialize}\n * triggers a sync. Defaults to 30 days.\n */\n maxSyncIntervalMs?: number;\n};\n\n// === STATE ===\n\n/**\n * State shape for {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerState = {\n /**\n * List of granted permissions with metadata (siteOrigin, revocationMetadata).\n */\n grantedPermissions: PermissionInfoWithMetadata[];\n\n /**\n * Flag that indicates that fetching permissions is in progress\n * This can be used to show a loading spinner in the UI\n */\n isFetchingGatorPermissions: boolean;\n\n /**\n * List of gator permissions pending a revocation transaction\n */\n pendingRevocations: {\n txId: string;\n permissionContext: Hex;\n }[];\n\n /**\n * Timestamp (ms) of the last successful sync of gator permissions from profile sync.\n * -1 indicates that a sync has never completed successfully.\n */\n lastSyncedTimestamp: number;\n};\n\nconst gatorPermissionsControllerMetadata: StateMetadata<GatorPermissionsControllerState> =\n {\n grantedPermissions: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n isFetchingGatorPermissions: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n pendingRevocations: {\n includeInStateLogs: true,\n persist: false,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n lastSyncedTimestamp: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: false,\n },\n } satisfies StateMetadata<GatorPermissionsControllerState>;\n\n/**\n * Creates initial controller state, merging defaults with optional partial state.\n * Internal use only (e.g. constructor, tests).\n *\n * @param state - Optional partial state to merge with defaults.\n * @returns Complete {@link GatorPermissionsController} state.\n */\nfunction createGatorPermissionsControllerState(\n state?: Partial<GatorPermissionsControllerState>,\n): GatorPermissionsControllerState {\n return {\n grantedPermissions: [],\n pendingRevocations: [],\n lastSyncedTimestamp: -1,\n ...state,\n // isFetchingGatorPermissions is _always_ false when the controller is created\n isFetchingGatorPermissions: false,\n };\n}\n\n// === MESSENGER ===\n\n/**\n * The action which can be used to retrieve the state of the\n * {@link GatorPermissionsController}.\n */\nexport type GatorPermissionsControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n GatorPermissionsControllerState\n>;\n\n/**\n * All actions that {@link GatorPermissionsController} registers, to be called\n * externally.\n */\nexport type GatorPermissionsControllerActions =\n | GatorPermissionsControllerGetStateAction\n | GatorPermissionsControllerMethodActions;\n\n/**\n * All actions that {@link GatorPermissionsController} calls internally.\n *\n * SnapController:handleRequest and SnapController: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 the gator permissions provider Snap.\n */\nexport class GatorPermissionsController extends BaseController<\n typeof controllerName,\n GatorPermissionsControllerState,\n GatorPermissionsControllerMessenger\n> {\n readonly #supportedPermissionTypes: readonly SupportedPermissionType[];\n\n /**\n * The Snap ID of the gator permissions provider.\n *\n * @returns The Snap ID of the gator permissions provider.\n */\n get gatorPermissionsProviderSnapId(): SnapId {\n return this.#gatorPermissionsProviderSnapId;\n }\n\n readonly #gatorPermissionsProviderSnapId: SnapId;\n\n readonly #maxSyncIntervalMs: number;\n\n /**\n * When a sync is in progress, holds the promise for that sync so concurrent\n * callers receive the same promise. Cleared when the sync completes.\n */\n #fetchAndUpdateGatorPermissionsPromise: Promise<void> | null = null;\n\n /**\n * Creates a GatorPermissionsController instance.\n *\n * @param args - The arguments to this function.\n * @param args.messenger - Messenger used to communicate with other controllers.\n * @param args.config - Configuration (supported permission types and optional Snap id).\n * @param args.state - Optional partial state to merge with defaults.\n */\n constructor({\n messenger,\n config,\n state,\n }: {\n messenger: GatorPermissionsControllerMessenger;\n config: GatorPermissionsControllerConfig;\n state?: Partial<GatorPermissionsControllerState>;\n }) {\n const initialState = createGatorPermissionsControllerState(state);\n\n super({\n name: controllerName,\n metadata: gatorPermissionsControllerMetadata,\n messenger,\n state: initialState,\n });\n\n this.#supportedPermissionTypes = config.supportedPermissionTypes;\n this.#gatorPermissionsProviderSnapId =\n config.gatorPermissionsProviderSnapId ??\n defaultGatorPermissionsProviderSnapId;\n this.#maxSyncIntervalMs =\n config.maxSyncIntervalMs ?? DEFAULT_MAX_SYNC_INTERVAL_MS;\n\n this.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\n }\n\n /**\n * Supported permission types this controller was configured with.\n *\n * @returns The supported permission types.\n */\n get supportedPermissionTypes(): readonly SupportedPermissionType[] {\n return this.#supportedPermissionTypes;\n }\n\n #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean): void {\n this.update((state) => {\n state.isFetchingGatorPermissions = isFetchingGatorPermissions;\n });\n }\n\n #addPendingRevocationToState(txId: string, permissionContext: Hex): void {\n this.update((state) => {\n state.pendingRevocations = [\n ...state.pendingRevocations,\n { txId, permissionContext },\n ];\n });\n }\n\n #removePendingRevocationFromStateByTxId(txId: string): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) => pendingRevocations.txId !== txId,\n );\n });\n }\n\n #removePendingRevocationFromStateByPermissionContext(\n permissionContext: Hex,\n ): void {\n this.update((state) => {\n state.pendingRevocations = state.pendingRevocations.filter(\n (pendingRevocations) =>\n pendingRevocations.permissionContext.toLowerCase() !==\n permissionContext.toLowerCase(),\n );\n });\n }\n\n /**\n * Converts a stored gator permission to permission info with metadata.\n * Strips internal fields (dependencies, to) from the permission response.\n *\n * @param storedGatorPermission - The stored gator permission from the Snap.\n * @returns Permission info with metadata for state/UI.\n */\n #storedPermissionToPermissionInfo(\n storedGatorPermission: StoredGatorPermission,\n ): PermissionInfoWithMetadata {\n const { permissionResponse: fullPermissionResponse } =\n storedGatorPermission;\n const {\n dependencies: _dependencies,\n to: _to,\n ...permissionResponse\n } = fullPermissionResponse;\n\n return {\n ...storedGatorPermission,\n permissionResponse,\n };\n }\n\n /**\n * Converts stored gator permissions from the Snap into permission info with metadata.\n *\n * @param storedGatorPermissions - Stored gator permissions returned by the Snap, or null.\n * @returns Array of permission info with metadata for state.\n */\n #storedPermissionsToPermissionInfoWithMetadata(\n storedGatorPermissions: StoredGatorPermission[] | null,\n ): PermissionInfoWithMetadata[] {\n if (!storedGatorPermissions) {\n return [];\n }\n\n return storedGatorPermissions.map((storedPermission) =>\n this.#storedPermissionToPermissionInfo(storedPermission),\n );\n }\n\n /**\n * Fetches granted permissions from the gator permissions provider Snap and updates state.\n * If a sync is already in progress, returns the same promise. After the sync completes,\n * the next call will perform a new sync.\n *\n * @returns A promise that resolves when the sync completes. All data is available via the controller's state.\n * @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.\n */\n public fetchAndUpdateGatorPermissions(): Promise<void> {\n if (this.#fetchAndUpdateGatorPermissionsPromise !== null) {\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n const performFetchAndUpdate = async (): Promise<void> => {\n try {\n this.#setIsFetchingGatorPermissions(true);\n\n // Only ever fetch non-revoked permissions. Revoked permissions may be\n // left in storage by the gator permissions snap, but we don't need to\n // fetch them.\n const params = { isRevoked: false };\n\n const permissionsData = await executeSnapRpc<\n StoredGatorPermission[] | null\n >({\n messenger: this.messenger,\n snapId: this.#gatorPermissionsProviderSnapId,\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,\n params,\n });\n\n const grantedPermissions =\n this.#storedPermissionsToPermissionInfoWithMetadata(permissionsData);\n\n this.update((state) => {\n state.grantedPermissions = grantedPermissions;\n state.lastSyncedTimestamp = Date.now();\n });\n } catch (error) {\n controllerLog('Failed to fetch gator permissions', error);\n throw new GatorPermissionsFetchError({\n message: 'Failed to fetch gator permissions',\n cause: error as Error,\n });\n } finally {\n this.#setIsFetchingGatorPermissions(false);\n this.#fetchAndUpdateGatorPermissionsPromise = null;\n }\n };\n\n this.#fetchAndUpdateGatorPermissionsPromise = performFetchAndUpdate();\n\n return this.#fetchAndUpdateGatorPermissionsPromise;\n }\n\n /**\n * Initializes the controller. Call once after construction to ensure the\n * controller is ready for use.\n *\n * @returns A promise that resolves when initialization is complete.\n */\n public async initialize(): Promise<void> {\n const currentTime = Date.now();\n const millisecondsSinceLastSync =\n currentTime - this.state.lastSyncedTimestamp;\n\n // Sync only when we have no data or data is stale, to avoid excessive startup\n // queries while still avoiding showing stale data while a refresh runs.\n if (\n this.state.lastSyncedTimestamp === -1 ||\n millisecondsSinceLastSync > this.#maxSyncIntervalMs\n ) {\n await this.fetchAndUpdateGatorPermissions();\n }\n }\n\n /**\n * Decodes a permission context into a structured permission for a specific origin.\n *\n * This method validates the caller origin, decodes the provided `permissionContext`\n * into delegations, identifies the permission type from the caveat enforcers,\n * extracts the permission-specific data and expiry, and reconstructs a\n * {@link DecodedPermission} containing chainId, account addresses, to, type and data.\n *\n * @param args - The arguments to this function.\n * @param args.origin - The caller's origin; must match the configured permissions provider Snap id.\n * @param args.chainId - Numeric EIP-155 chain id used for resolving enforcer contracts and encoding.\n * @param args.delegation - delegation representing the permission.\n * @param args.metadata - metadata included in the request.\n * @param args.metadata.justification - the justification as specified in the request metadata.\n * @param args.metadata.origin - the origin as specified in the request metadata.\n *\n * @returns A decoded permission object suitable for UI consumption and follow-up actions.\n * @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,\n * or the enforcers/terms do not match a supported permission type.\n */\n public decodePermissionFromPermissionContextForOrigin({\n origin,\n chainId,\n delegation: { caveats, delegator, delegate, authority },\n metadata: { justification, origin: specifiedOrigin },\n }: {\n origin: string;\n chainId: number;\n metadata: {\n justification: string;\n origin: string;\n };\n delegation: DelegationDetails;\n }): DecodedPermission {\n if (origin !== this.#gatorPermissionsProviderSnapId) {\n throw new OriginNotAllowedError({ origin });\n }\n\n const contracts = contractsByChainId[chainId];\n\n if (!contracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n try {\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n const permissionRules = createPermissionRulesForContracts(contracts);\n\n // find the single rule where the specified enforcers contain all the required enforcers\n // and no forbidden enforcers\n const matchingRule = findRuleWithMatchingCaveatAddresses({\n enforcers,\n permissionRules,\n });\n\n // validate the terms of each caveat against the matching rule, returning the decoded result\n // this happens in a single function, as decoding is an inherent part of validation.\n const decodeResult = matchingRule.validateAndDecodePermission(caveats);\n\n if (!decodeResult.isValid) {\n throw new PermissionDecodingError({\n cause: decodeResult.error,\n });\n }\n\n const { expiry, data } = decodeResult;\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType: matchingRule.permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n });\n\n return permission;\n } catch (error) {\n throw new PermissionDecodingError({\n cause: error as Error,\n });\n }\n }\n\n /**\n * Submits a revocation to the gator permissions provider snap.\n *\n * @param revocationParams - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitRevocation(\n revocationParams: RevocationParams,\n ): Promise<void> {\n controllerLog('submitRevocation method called', {\n permissionContext: revocationParams.permissionContext,\n });\n\n const snapRequest = {\n snapId: this.#gatorPermissionsProviderSnapId,\n origin: 'metamask',\n handler: HandlerType.OnRpcRequest,\n request: {\n jsonrpc: '2.0',\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n params: revocationParams,\n },\n };\n\n try {\n const result = await this.messenger.call(\n 'SnapController:handleRequest',\n snapRequest,\n );\n\n // Refresh list first (permission removed from list)\n await this.fetchAndUpdateGatorPermissions();\n\n controllerLog('Successfully submitted revocation', {\n permissionContext: revocationParams.permissionContext,\n result,\n });\n } catch (error) {\n // If it's a GatorPermissionsFetchError, revocation succeeded but refresh failed\n if (error instanceof GatorPermissionsFetchError) {\n controllerLog(\n 'Revocation submitted successfully but failed to refresh permissions list',\n {\n error,\n permissionContext: revocationParams.permissionContext,\n },\n );\n // Wrap with a more specific message indicating revocation succeeded\n throw new GatorPermissionsFetchError({\n message:\n 'Failed to refresh permissions list after successful revocation',\n cause: error as Error,\n });\n }\n\n // Otherwise, revocation failed - wrap in provider error\n controllerLog('Failed to submit revocation', {\n error,\n permissionContext: revocationParams.permissionContext,\n });\n\n throw new GatorPermissionsProviderError({\n method:\n GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,\n cause: error as Error,\n });\n } finally {\n this.#removePendingRevocationFromStateByPermissionContext(\n revocationParams.permissionContext,\n );\n }\n }\n\n /**\n * Adds a pending revocation that will be submitted once the transaction is confirmed.\n *\n * This method sets up listeners for the user's approval/rejection decision and\n * terminal transaction states (confirmed, failed, dropped). The flow is:\n * 1. Wait for user to approve or reject the transaction\n * 2. If approved, add to pending revocations state\n * 3. If rejected, cleanup without adding to state\n * 4. If confirmed, submit the revocation\n * 5. If failed or dropped, cleanup\n *\n * Includes a timeout safety net to prevent memory leaks if the transaction never\n * reaches a terminal state.\n *\n * @param params - The pending revocation parameters.\n * @returns A promise that resolves when the listener is set up.\n */\n public async addPendingRevocation(\n params: PendingRevocationParams,\n ): Promise<void> {\n const { txId, permissionContext } = params;\n\n controllerLog('addPendingRevocation method called', {\n txId,\n permissionContext,\n });\n\n type PendingRevocationHandlers = {\n approved?: (\n ...args: TransactionControllerTransactionApprovedEvent['payload']\n ) => void;\n rejected?: (\n ...args: TransactionControllerTransactionRejectedEvent['payload']\n ) => void;\n confirmed?: (\n ...args: TransactionControllerTransactionConfirmedEvent['payload']\n ) => void;\n failed?: (\n ...args: TransactionControllerTransactionFailedEvent['payload']\n ) => void;\n dropped?: (\n ...args: TransactionControllerTransactionDroppedEvent['payload']\n ) => void;\n timeoutId?: ReturnType<typeof setTimeout>;\n };\n\n // Track handlers and timeout for cleanup\n const handlers: PendingRevocationHandlers = {\n approved: undefined,\n rejected: undefined,\n confirmed: undefined,\n failed: undefined,\n dropped: undefined,\n timeoutId: undefined,\n };\n\n // Helper to refresh permissions after transaction state change\n const refreshPermissions = (context: string): void => {\n this.fetchAndUpdateGatorPermissions().catch((error) => {\n controllerLog(`Failed to refresh permissions after ${context}`, {\n txId,\n permissionContext,\n error,\n });\n });\n };\n\n // Helper to unsubscribe from approval/rejection events after decision is made\n const cleanupApprovalHandlers = (): void => {\n if (handlers.approved) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n handlers.approved = undefined;\n }\n if (handlers.rejected) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n handlers.rejected = undefined;\n }\n };\n\n // Cleanup function to unsubscribe from all events and clear timeout\n const cleanup = (txIdToRemove: string, removeFromState = true): void => {\n cleanupApprovalHandlers();\n if (handlers.confirmed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n }\n if (handlers.failed) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n }\n if (handlers.dropped) {\n this.messenger.unsubscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n }\n if (handlers.timeoutId !== undefined) {\n clearTimeout(handlers.timeoutId);\n }\n\n // Remove the pending revocation from the state (only if it was added)\n if (removeFromState) {\n this.#removePendingRevocationFromStateByTxId(txIdToRemove);\n }\n };\n\n // Handle approved transaction - add to pending revocations state\n handlers.approved = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog(\n 'Transaction approved by user, adding to pending revocations',\n {\n txId,\n permissionContext,\n },\n );\n\n this.#addPendingRevocationToState(txId, permissionContext);\n\n // Unsubscribe from approval/rejection events since decision is made\n cleanupApprovalHandlers();\n }\n };\n\n // Handle rejected transaction - cleanup without adding to state\n handlers.rejected = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction rejected by user, cleaning up listeners', {\n txId,\n permissionContext,\n });\n\n // Don't remove from state since it was never added\n cleanup(payload.transactionMeta.id, false);\n }\n };\n\n // Handle confirmed transaction - submit revocation\n handlers.confirmed = (transactionMeta): void => {\n if (transactionMeta.id === txId) {\n controllerLog('Transaction confirmed, submitting revocation', {\n txId,\n permissionContext,\n txHash: transactionMeta.hash,\n });\n\n if (transactionMeta.status !== TransactionStatus.confirmed) {\n controllerLog('Transaction not confirmed, skipping revocation', {\n txId,\n permissionContext,\n status: transactionMeta.status,\n });\n cleanup(transactionMeta.id);\n refreshPermissions('transaction not confirmed');\n return;\n }\n\n const txHash = transactionMeta.hash as Hex | undefined;\n\n if (txHash === undefined) {\n controllerLog(\n 'Failed to resolve transaction hash after revocation transaction confirmed',\n {\n txId,\n permissionContext,\n error: new Error(\n 'Confirmed transaction is missing transaction hash',\n ),\n },\n );\n }\n\n this.submitRevocation({ permissionContext, txHash })\n .catch((error) => {\n controllerLog(\n 'Failed to submit revocation after transaction confirmed',\n {\n txId,\n permissionContext,\n error,\n },\n );\n })\n .finally(() => refreshPermissions('transaction confirmed'));\n\n cleanup(transactionMeta.id);\n }\n };\n\n // Handle failed transaction - cleanup without submitting revocation\n handlers.failed = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction failed, cleaning up revocation listener', {\n txId,\n permissionContext,\n error: payload.error,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction failed');\n }\n };\n\n // Handle dropped transaction - cleanup without submitting revocation\n handlers.dropped = (payload): void => {\n if (payload.transactionMeta.id === txId) {\n controllerLog('Transaction dropped, cleaning up revocation listener', {\n txId,\n permissionContext,\n });\n\n cleanup(payload.transactionMeta.id);\n\n refreshPermissions('transaction dropped');\n }\n };\n\n // Subscribe to user approval/rejection events\n this.messenger.subscribe(\n 'TransactionController:transactionApproved',\n handlers.approved,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionRejected',\n handlers.rejected,\n );\n\n // Subscribe to terminal transaction events\n this.messenger.subscribe(\n 'TransactionController:transactionConfirmed',\n handlers.confirmed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionFailed',\n handlers.failed,\n );\n this.messenger.subscribe(\n 'TransactionController:transactionDropped',\n handlers.dropped,\n );\n\n // Set timeout as safety net to prevent memory leaks\n handlers.timeoutId = setTimeout(() => {\n controllerLog('Pending revocation timed out, cleaning up listeners', {\n txId,\n permissionContext,\n });\n cleanup(txId);\n }, PENDING_REVOCATION_TIMEOUT);\n }\n\n /**\n * Submits a revocation directly without requiring an on-chain transaction.\n * Used for already-disabled delegations that don't require an on-chain transaction.\n *\n * This method:\n * 1. Adds the permission context to pending revocations state (disables UI button)\n * 2. Immediately calls submitRevocation to remove from snap storage\n * 3. On success, removes from pending revocations state (re-enables UI button)\n * 4. On failure, keeps in pending revocations so UI can show error/retry state\n *\n * @param params - The revocation parameters containing the permission context.\n * @returns A promise that resolves when the revocation is submitted successfully.\n * @throws {GatorPermissionsProviderError} If the snap request fails.\n */\n public async submitDirectRevocation(params: RevocationParams): Promise<void> {\n // Use a placeholder txId that doesn't conflict with real transaction IDs\n const placeholderTxId = `no-tx-${params.permissionContext}`;\n\n // Add to pending revocations state first (disables UI button immediately)\n this.#addPendingRevocationToState(\n placeholderTxId,\n params.permissionContext,\n );\n\n // Immediately submit the revocation (will remove from pending on success)\n await this.submitRevocation(params);\n }\n\n /**\n * Checks if a permission context is in the pending revocations list.\n *\n * @param permissionContext - The permission context to check.\n * @returns `true` if the permission context is pending revocation, `false` otherwise.\n */\n public isPendingRevocation(permissionContext: Hex): boolean {\n const requestedPermissionContextLowercase = permissionContext.toLowerCase();\n\n return this.state.pendingRevocations.some(\n (pendingRevocation) =>\n pendingRevocation.permissionContext.toLowerCase() ===\n requestedPermissionContextLowercase,\n );\n }\n}\n\nexport default GatorPermissionsController;\n"]}
|
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;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAAA,+EAAqF;AAA5E,yJAAA,OAAO,OAA8B;AAoB9C,6CAA2D;AAAlD,yHAAA,4BAA4B,OAAA","sourcesContent":["export { default as GatorPermissionsController } from './GatorPermissionsController';\nexport type {\n GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction,\n GatorPermissionsControllerAddPendingRevocationAction,\n GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction,\n GatorPermissionsControllerInitializeAction,\n GatorPermissionsControllerIsPendingRevocationAction,\n GatorPermissionsControllerSubmitDirectRevocationAction,\n GatorPermissionsControllerSubmitRevocationAction,\n} from './GatorPermissionsController-method-action-types';\nexport type {\n GatorPermissionsControllerState,\n GatorPermissionsControllerConfig,\n GatorPermissionsControllerMessenger,\n GatorPermissionsControllerGetStateAction,\n GatorPermissionsControllerActions,\n GatorPermissionsControllerEvents,\n GatorPermissionsControllerStateChangeEvent,\n} from './GatorPermissionsController';\nexport type { DecodedPermission } from './decodePermission';\nexport { DELEGATION_FRAMEWORK_VERSION } from './constants';\nexport type {\n GatorPermissionsControllerErrorCode,\n GatorPermissionsSnapRpcMethod,\n PermissionRequest,\n PermissionResponse,\n PermissionInfo,\n StoredGatorPermission,\n PermissionInfoWithMetadata,\n DelegationDetails,\n RevocationParams,\n RevocationMetadata,\n SupportedPermissionType,\n} from './types';\n\nexport type {\n NativeTokenStreamPermission,\n NativeTokenPeriodicPermission,\n Erc20TokenStreamPermission,\n Erc20TokenPeriodicPermission,\n MetaMaskBasePermissionData,\n} from '@metamask/7715-permission-types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as GatorPermissionsController } from "./GatorPermissionsController.cjs";
|
|
2
|
-
export type {
|
|
2
|
+
export type { GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction, GatorPermissionsControllerAddPendingRevocationAction, GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction, GatorPermissionsControllerInitializeAction, GatorPermissionsControllerIsPendingRevocationAction, GatorPermissionsControllerSubmitDirectRevocationAction, GatorPermissionsControllerSubmitRevocationAction, } from "./GatorPermissionsController-method-action-types.cjs";
|
|
3
|
+
export type { GatorPermissionsControllerState, GatorPermissionsControllerConfig, GatorPermissionsControllerMessenger, GatorPermissionsControllerGetStateAction, GatorPermissionsControllerActions, GatorPermissionsControllerEvents, GatorPermissionsControllerStateChangeEvent, } from "./GatorPermissionsController.cjs";
|
|
3
4
|
export type { DecodedPermission } from "./decodePermission/index.cjs";
|
|
4
5
|
export { DELEGATION_FRAMEWORK_VERSION } from "./constants.cjs";
|
|
5
6
|
export type { GatorPermissionsControllerErrorCode, GatorPermissionsSnapRpcMethod, PermissionRequest, PermissionResponse, PermissionInfo, StoredGatorPermission, PermissionInfoWithMetadata, DelegationDetails, RevocationParams, RevocationMetadata, SupportedPermissionType, } from "./types.cjs";
|
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,YAAY,EACV,+BAA+B,EAC/B,gCAAgC,EAChC,mCAAmC,EACnC,wCAAwC,EACxC,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,yCAAqC;AACrF,YAAY,EACV,8DAA8D,EAC9D,oDAAoD,EACpD,8EAA8E,EAC9E,0CAA0C,EAC1C,mDAAmD,EACnD,sDAAsD,EACtD,gDAAgD,GACjD,6DAAyD;AAC1D,YAAY,EACV,+BAA+B,EAC/B,gCAAgC,EAChC,mCAAmC,EACnC,wCAAwC,EACxC,iCAAiC,EACjC,gCAAgC,EAChC,0CAA0C,GAC3C,yCAAqC;AACtC,YAAY,EAAE,iBAAiB,EAAE,qCAA2B;AAC5D,OAAO,EAAE,4BAA4B,EAAE,wBAAoB;AAC3D,YAAY,EACV,mCAAmC,EACnC,6BAA6B,EAC7B,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,GACxB,oBAAgB;AAEjB,YAAY,EACV,2BAA2B,EAC3B,6BAA6B,EAC7B,0BAA0B,EAC1B,4BAA4B,EAC5B,0BAA0B,GAC3B,wCAAwC"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export { default as GatorPermissionsController } from "./GatorPermissionsController.mjs";
|
|
2
|
-
export type {
|
|
2
|
+
export type { GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction, GatorPermissionsControllerAddPendingRevocationAction, GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction, GatorPermissionsControllerInitializeAction, GatorPermissionsControllerIsPendingRevocationAction, GatorPermissionsControllerSubmitDirectRevocationAction, GatorPermissionsControllerSubmitRevocationAction, } from "./GatorPermissionsController-method-action-types.mjs";
|
|
3
|
+
export type { GatorPermissionsControllerState, GatorPermissionsControllerConfig, GatorPermissionsControllerMessenger, GatorPermissionsControllerGetStateAction, GatorPermissionsControllerActions, GatorPermissionsControllerEvents, GatorPermissionsControllerStateChangeEvent, } from "./GatorPermissionsController.mjs";
|
|
3
4
|
export type { DecodedPermission } from "./decodePermission/index.mjs";
|
|
4
5
|
export { DELEGATION_FRAMEWORK_VERSION } from "./constants.mjs";
|
|
5
6
|
export type { GatorPermissionsControllerErrorCode, GatorPermissionsSnapRpcMethod, PermissionRequest, PermissionResponse, PermissionInfo, StoredGatorPermission, PermissionInfoWithMetadata, DelegationDetails, RevocationParams, RevocationMetadata, SupportedPermissionType, } from "./types.mjs";
|
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,YAAY,EACV,+BAA+B,EAC/B,gCAAgC,EAChC,mCAAmC,EACnC,wCAAwC,EACxC,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,yCAAqC;AACrF,YAAY,EACV,8DAA8D,EAC9D,oDAAoD,EACpD,8EAA8E,EAC9E,0CAA0C,EAC1C,mDAAmD,EACnD,sDAAsD,EACtD,gDAAgD,GACjD,6DAAyD;AAC1D,YAAY,EACV,+BAA+B,EAC/B,gCAAgC,EAChC,mCAAmC,EACnC,wCAAwC,EACxC,iCAAiC,EACjC,gCAAgC,EAChC,0CAA0C,GAC3C,yCAAqC;AACtC,YAAY,EAAE,iBAAiB,EAAE,qCAA2B;AAC5D,OAAO,EAAE,4BAA4B,EAAE,wBAAoB;AAC3D,YAAY,EACV,mCAAmC,EACnC,6BAA6B,EAC7B,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,qBAAqB,EACrB,0BAA0B,EAC1B,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,uBAAuB,GACxB,oBAAgB;AAEjB,YAAY,EACV,2BAA2B,EAC3B,6BAA6B,EAC7B,0BAA0B,EAC1B,4BAA4B,EAC5B,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;
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,yCAAqC;AAoBrF,OAAO,EAAE,4BAA4B,EAAE,wBAAoB","sourcesContent":["export { default as GatorPermissionsController } from './GatorPermissionsController';\nexport type {\n GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction,\n GatorPermissionsControllerAddPendingRevocationAction,\n GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction,\n GatorPermissionsControllerInitializeAction,\n GatorPermissionsControllerIsPendingRevocationAction,\n GatorPermissionsControllerSubmitDirectRevocationAction,\n GatorPermissionsControllerSubmitRevocationAction,\n} from './GatorPermissionsController-method-action-types';\nexport type {\n GatorPermissionsControllerState,\n GatorPermissionsControllerConfig,\n GatorPermissionsControllerMessenger,\n GatorPermissionsControllerGetStateAction,\n GatorPermissionsControllerActions,\n GatorPermissionsControllerEvents,\n GatorPermissionsControllerStateChangeEvent,\n} from './GatorPermissionsController';\nexport type { DecodedPermission } from './decodePermission';\nexport { DELEGATION_FRAMEWORK_VERSION } from './constants';\nexport type {\n GatorPermissionsControllerErrorCode,\n GatorPermissionsSnapRpcMethod,\n PermissionRequest,\n PermissionResponse,\n PermissionInfo,\n StoredGatorPermission,\n PermissionInfoWithMetadata,\n DelegationDetails,\n RevocationParams,\n RevocationMetadata,\n SupportedPermissionType,\n} from './types';\n\nexport type {\n NativeTokenStreamPermission,\n NativeTokenPeriodicPermission,\n Erc20TokenStreamPermission,\n Erc20TokenPeriodicPermission,\n MetaMaskBasePermissionData,\n} from '@metamask/7715-permission-types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/gator-permissions-controller",
|
|
3
|
-
"version": "2.1.1-preview-
|
|
3
|
+
"version": "2.1.1-preview-e9620906a",
|
|
4
4
|
"description": "Controller for managing gator permissions with profile sync integration",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"build:docs": "typedoc",
|
|
41
41
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/gator-permissions-controller",
|
|
42
42
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/gator-permissions-controller",
|
|
43
|
+
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
|
|
43
44
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
44
45
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
45
46
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -67,6 +68,7 @@
|
|
|
67
68
|
"deepmerge": "^4.2.2",
|
|
68
69
|
"jest": "^29.7.0",
|
|
69
70
|
"ts-jest": "^29.2.5",
|
|
71
|
+
"tsx": "^4.20.5",
|
|
70
72
|
"typedoc": "^0.25.13",
|
|
71
73
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
72
74
|
"typescript": "~5.3.3"
|