@metamask/gator-permissions-controller 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -1
- package/README.md +8 -0
- package/dist/GatorPermissionsController.cjs +228 -3
- package/dist/GatorPermissionsController.cjs.map +1 -1
- package/dist/GatorPermissionsController.d.cts +64 -4
- package/dist/GatorPermissionsController.d.cts.map +1 -1
- package/dist/GatorPermissionsController.d.mts +64 -4
- package/dist/GatorPermissionsController.d.mts.map +1 -1
- package/dist/GatorPermissionsController.mjs +228 -3
- package/dist/GatorPermissionsController.mjs.map +1 -1
- package/dist/decodePermission/decodePermission.cjs.map +1 -1
- package/dist/decodePermission/decodePermission.mjs.map +1 -1
- package/dist/decodePermission/utils.cjs.map +1 -1
- package/dist/decodePermission/utils.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/test/mocks.cjs.map +1 -1
- package/dist/test/mocks.mjs.map +1 -1
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +35 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +35 -1
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +4 -0
- package/dist/types.mjs.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +7 -4
|
@@ -3,8 +3,10 @@ import { BaseController } from "@metamask/base-controller";
|
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
4
|
import type { HandleSnapRequest, HasSnap } from "@metamask/snaps-controllers";
|
|
5
5
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
6
|
+
import type { TransactionControllerTransactionApprovedEvent, TransactionControllerTransactionConfirmedEvent, TransactionControllerTransactionDroppedEvent, TransactionControllerTransactionFailedEvent, TransactionControllerTransactionRejectedEvent } from "@metamask/transaction-controller";
|
|
7
|
+
import type { Hex, Json } from "@metamask/utils";
|
|
6
8
|
import type { DecodedPermission } from "./decodePermission/index.cjs";
|
|
7
|
-
import { type GatorPermissionsMap, type DelegationDetails } from "./types.cjs";
|
|
9
|
+
import { type GatorPermissionsMap, type DelegationDetails, type RevocationParams, type PendingRevocationParams } from "./types.cjs";
|
|
8
10
|
declare const controllerName = "GatorPermissionsController";
|
|
9
11
|
/**
|
|
10
12
|
* Delegation framework version used to select the correct deployed enforcer
|
|
@@ -33,6 +35,13 @@ export type GatorPermissionsControllerState = {
|
|
|
33
35
|
* Default value is `@metamask/gator-permissions-snap`
|
|
34
36
|
*/
|
|
35
37
|
gatorPermissionsProviderSnapId: SnapId;
|
|
38
|
+
/**
|
|
39
|
+
* List of gator permission pending a revocation transaction
|
|
40
|
+
*/
|
|
41
|
+
pendingRevocations: {
|
|
42
|
+
txId: string;
|
|
43
|
+
permissionContext: Hex;
|
|
44
|
+
}[];
|
|
36
45
|
};
|
|
37
46
|
/**
|
|
38
47
|
* Constructs the default {@link GatorPermissionsController} state. This allows
|
|
@@ -73,11 +82,25 @@ export type GatorPermissionsControllerDecodePermissionFromPermissionContextForOr
|
|
|
73
82
|
type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;
|
|
74
83
|
handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];
|
|
75
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* The action which can be used to submit a revocation.
|
|
87
|
+
*/
|
|
88
|
+
export type GatorPermissionsControllerSubmitRevocationAction = {
|
|
89
|
+
type: `${typeof controllerName}:submitRevocation`;
|
|
90
|
+
handler: GatorPermissionsController['submitRevocation'];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The action which can be used to add a pending revocation.
|
|
94
|
+
*/
|
|
95
|
+
export type GatorPermissionsControllerAddPendingRevocationAction = {
|
|
96
|
+
type: `${typeof controllerName}:addPendingRevocation`;
|
|
97
|
+
handler: GatorPermissionsController['addPendingRevocation'];
|
|
98
|
+
};
|
|
76
99
|
/**
|
|
77
100
|
* All actions that {@link GatorPermissionsController} registers, to be called
|
|
78
101
|
* externally.
|
|
79
102
|
*/
|
|
80
|
-
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerEnableGatorPermissionsAction | GatorPermissionsControllerDisableGatorPermissionsAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction;
|
|
103
|
+
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerEnableGatorPermissionsAction | GatorPermissionsControllerDisableGatorPermissionsAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | GatorPermissionsControllerSubmitRevocationAction | GatorPermissionsControllerAddPendingRevocationAction;
|
|
81
104
|
/**
|
|
82
105
|
* All actions that {@link GatorPermissionsController} calls internally.
|
|
83
106
|
*
|
|
@@ -97,7 +120,7 @@ export type GatorPermissionsControllerEvents = GatorPermissionsControllerStateCh
|
|
|
97
120
|
/**
|
|
98
121
|
* Events that {@link GatorPermissionsController} is allowed to subscribe to internally.
|
|
99
122
|
*/
|
|
100
|
-
type AllowedEvents = GatorPermissionsControllerStateChangeEvent;
|
|
123
|
+
type AllowedEvents = GatorPermissionsControllerStateChangeEvent | TransactionControllerTransactionApprovedEvent | TransactionControllerTransactionRejectedEvent | TransactionControllerTransactionConfirmedEvent | TransactionControllerTransactionFailedEvent | TransactionControllerTransactionDroppedEvent;
|
|
101
124
|
/**
|
|
102
125
|
* Messenger type for the GatorPermissionsController.
|
|
103
126
|
*/
|
|
@@ -138,13 +161,23 @@ export default class GatorPermissionsController extends BaseController<typeof co
|
|
|
138
161
|
* Clears the gator permissions map and disables the feature.
|
|
139
162
|
*/
|
|
140
163
|
disableGatorPermissions(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Gets the pending revocations list.
|
|
166
|
+
*
|
|
167
|
+
* @returns The pending revocations list.
|
|
168
|
+
*/
|
|
169
|
+
get pendingRevocations(): {
|
|
170
|
+
txId: string;
|
|
171
|
+
permissionContext: Hex;
|
|
172
|
+
}[];
|
|
141
173
|
/**
|
|
142
174
|
* Fetches the gator permissions from profile sync and updates the state.
|
|
143
175
|
*
|
|
176
|
+
* @param params - Optional parameters to pass to the snap's getGrantedPermissions method.
|
|
144
177
|
* @returns A promise that resolves to the gator permissions map.
|
|
145
178
|
* @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.
|
|
146
179
|
*/
|
|
147
|
-
fetchAndUpdateGatorPermissions(): Promise<GatorPermissionsMap>;
|
|
180
|
+
fetchAndUpdateGatorPermissions(params?: Json): Promise<GatorPermissionsMap>;
|
|
148
181
|
/**
|
|
149
182
|
* Decodes a permission context into a structured permission for a specific origin.
|
|
150
183
|
*
|
|
@@ -174,6 +207,33 @@ export default class GatorPermissionsController extends BaseController<typeof co
|
|
|
174
207
|
};
|
|
175
208
|
delegation: DelegationDetails;
|
|
176
209
|
}): DecodedPermission;
|
|
210
|
+
/**
|
|
211
|
+
* Submits a revocation to the gator permissions provider snap.
|
|
212
|
+
*
|
|
213
|
+
* @param revocationParams - The revocation parameters containing the permission context.
|
|
214
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
215
|
+
* @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.
|
|
216
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
217
|
+
*/
|
|
218
|
+
submitRevocation(revocationParams: RevocationParams): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Adds a pending revocation that will be submitted once the transaction is confirmed.
|
|
221
|
+
*
|
|
222
|
+
* This method sets up listeners for the user's approval/rejection decision and
|
|
223
|
+
* terminal transaction states (confirmed, failed, dropped). The flow is:
|
|
224
|
+
* 1. Wait for user to approve or reject the transaction
|
|
225
|
+
* 2. If approved, add to pending revocations state
|
|
226
|
+
* 3. If rejected, cleanup without adding to state
|
|
227
|
+
* 4. If confirmed, submit the revocation
|
|
228
|
+
* 5. If failed or dropped, cleanup
|
|
229
|
+
*
|
|
230
|
+
* Includes a timeout safety net to prevent memory leaks if the transaction never
|
|
231
|
+
* reaches a terminal state.
|
|
232
|
+
*
|
|
233
|
+
* @param params - The pending revocation parameters.
|
|
234
|
+
* @returns A promise that resolves when the listener is set up.
|
|
235
|
+
*/
|
|
236
|
+
addPendingRevocation(params: PendingRevocationParams): Promise<void>;
|
|
177
237
|
}
|
|
178
238
|
export {};
|
|
179
239
|
//# sourceMappingURL=GatorPermissionsController.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatorPermissionsController.d.cts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,oCAAoC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController.d.cts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,OAAO,EAAE,oCAAoC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,4BAA4B;AAElD,OAAO,KAAK,EACV,6CAA6C,EAC7C,8CAA8C,EAC9C,4CAA4C,EAC5C,2CAA2C,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C9B,OAAO,CAAC,IAAI,CAAC;CAwMjB"}
|
|
@@ -3,8 +3,10 @@ import { BaseController } from "@metamask/base-controller";
|
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
4
|
import type { HandleSnapRequest, HasSnap } from "@metamask/snaps-controllers";
|
|
5
5
|
import type { SnapId } from "@metamask/snaps-sdk";
|
|
6
|
+
import type { TransactionControllerTransactionApprovedEvent, TransactionControllerTransactionConfirmedEvent, TransactionControllerTransactionDroppedEvent, TransactionControllerTransactionFailedEvent, TransactionControllerTransactionRejectedEvent } from "@metamask/transaction-controller";
|
|
7
|
+
import type { Hex, Json } from "@metamask/utils";
|
|
6
8
|
import type { DecodedPermission } from "./decodePermission/index.mjs";
|
|
7
|
-
import { type GatorPermissionsMap, type DelegationDetails } from "./types.mjs";
|
|
9
|
+
import { type GatorPermissionsMap, type DelegationDetails, type RevocationParams, type PendingRevocationParams } from "./types.mjs";
|
|
8
10
|
declare const controllerName = "GatorPermissionsController";
|
|
9
11
|
/**
|
|
10
12
|
* Delegation framework version used to select the correct deployed enforcer
|
|
@@ -33,6 +35,13 @@ export type GatorPermissionsControllerState = {
|
|
|
33
35
|
* Default value is `@metamask/gator-permissions-snap`
|
|
34
36
|
*/
|
|
35
37
|
gatorPermissionsProviderSnapId: SnapId;
|
|
38
|
+
/**
|
|
39
|
+
* List of gator permission pending a revocation transaction
|
|
40
|
+
*/
|
|
41
|
+
pendingRevocations: {
|
|
42
|
+
txId: string;
|
|
43
|
+
permissionContext: Hex;
|
|
44
|
+
}[];
|
|
36
45
|
};
|
|
37
46
|
/**
|
|
38
47
|
* Constructs the default {@link GatorPermissionsController} state. This allows
|
|
@@ -73,11 +82,25 @@ export type GatorPermissionsControllerDecodePermissionFromPermissionContextForOr
|
|
|
73
82
|
type: `${typeof controllerName}:decodePermissionFromPermissionContextForOrigin`;
|
|
74
83
|
handler: GatorPermissionsController['decodePermissionFromPermissionContextForOrigin'];
|
|
75
84
|
};
|
|
85
|
+
/**
|
|
86
|
+
* The action which can be used to submit a revocation.
|
|
87
|
+
*/
|
|
88
|
+
export type GatorPermissionsControllerSubmitRevocationAction = {
|
|
89
|
+
type: `${typeof controllerName}:submitRevocation`;
|
|
90
|
+
handler: GatorPermissionsController['submitRevocation'];
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* The action which can be used to add a pending revocation.
|
|
94
|
+
*/
|
|
95
|
+
export type GatorPermissionsControllerAddPendingRevocationAction = {
|
|
96
|
+
type: `${typeof controllerName}:addPendingRevocation`;
|
|
97
|
+
handler: GatorPermissionsController['addPendingRevocation'];
|
|
98
|
+
};
|
|
76
99
|
/**
|
|
77
100
|
* All actions that {@link GatorPermissionsController} registers, to be called
|
|
78
101
|
* externally.
|
|
79
102
|
*/
|
|
80
|
-
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerEnableGatorPermissionsAction | GatorPermissionsControllerDisableGatorPermissionsAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction;
|
|
103
|
+
export type GatorPermissionsControllerActions = GatorPermissionsControllerGetStateAction | GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerEnableGatorPermissionsAction | GatorPermissionsControllerDisableGatorPermissionsAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | GatorPermissionsControllerSubmitRevocationAction | GatorPermissionsControllerAddPendingRevocationAction;
|
|
81
104
|
/**
|
|
82
105
|
* All actions that {@link GatorPermissionsController} calls internally.
|
|
83
106
|
*
|
|
@@ -97,7 +120,7 @@ export type GatorPermissionsControllerEvents = GatorPermissionsControllerStateCh
|
|
|
97
120
|
/**
|
|
98
121
|
* Events that {@link GatorPermissionsController} is allowed to subscribe to internally.
|
|
99
122
|
*/
|
|
100
|
-
type AllowedEvents = GatorPermissionsControllerStateChangeEvent;
|
|
123
|
+
type AllowedEvents = GatorPermissionsControllerStateChangeEvent | TransactionControllerTransactionApprovedEvent | TransactionControllerTransactionRejectedEvent | TransactionControllerTransactionConfirmedEvent | TransactionControllerTransactionFailedEvent | TransactionControllerTransactionDroppedEvent;
|
|
101
124
|
/**
|
|
102
125
|
* Messenger type for the GatorPermissionsController.
|
|
103
126
|
*/
|
|
@@ -138,13 +161,23 @@ export default class GatorPermissionsController extends BaseController<typeof co
|
|
|
138
161
|
* Clears the gator permissions map and disables the feature.
|
|
139
162
|
*/
|
|
140
163
|
disableGatorPermissions(): Promise<void>;
|
|
164
|
+
/**
|
|
165
|
+
* Gets the pending revocations list.
|
|
166
|
+
*
|
|
167
|
+
* @returns The pending revocations list.
|
|
168
|
+
*/
|
|
169
|
+
get pendingRevocations(): {
|
|
170
|
+
txId: string;
|
|
171
|
+
permissionContext: Hex;
|
|
172
|
+
}[];
|
|
141
173
|
/**
|
|
142
174
|
* Fetches the gator permissions from profile sync and updates the state.
|
|
143
175
|
*
|
|
176
|
+
* @param params - Optional parameters to pass to the snap's getGrantedPermissions method.
|
|
144
177
|
* @returns A promise that resolves to the gator permissions map.
|
|
145
178
|
* @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.
|
|
146
179
|
*/
|
|
147
|
-
fetchAndUpdateGatorPermissions(): Promise<GatorPermissionsMap>;
|
|
180
|
+
fetchAndUpdateGatorPermissions(params?: Json): Promise<GatorPermissionsMap>;
|
|
148
181
|
/**
|
|
149
182
|
* Decodes a permission context into a structured permission for a specific origin.
|
|
150
183
|
*
|
|
@@ -174,6 +207,33 @@ export default class GatorPermissionsController extends BaseController<typeof co
|
|
|
174
207
|
};
|
|
175
208
|
delegation: DelegationDetails;
|
|
176
209
|
}): DecodedPermission;
|
|
210
|
+
/**
|
|
211
|
+
* Submits a revocation to the gator permissions provider snap.
|
|
212
|
+
*
|
|
213
|
+
* @param revocationParams - The revocation parameters containing the permission context.
|
|
214
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
215
|
+
* @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.
|
|
216
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
217
|
+
*/
|
|
218
|
+
submitRevocation(revocationParams: RevocationParams): Promise<void>;
|
|
219
|
+
/**
|
|
220
|
+
* Adds a pending revocation that will be submitted once the transaction is confirmed.
|
|
221
|
+
*
|
|
222
|
+
* This method sets up listeners for the user's approval/rejection decision and
|
|
223
|
+
* terminal transaction states (confirmed, failed, dropped). The flow is:
|
|
224
|
+
* 1. Wait for user to approve or reject the transaction
|
|
225
|
+
* 2. If approved, add to pending revocations state
|
|
226
|
+
* 3. If rejected, cleanup without adding to state
|
|
227
|
+
* 4. If confirmed, submit the revocation
|
|
228
|
+
* 5. If failed or dropped, cleanup
|
|
229
|
+
*
|
|
230
|
+
* Includes a timeout safety net to prevent memory leaks if the transaction never
|
|
231
|
+
* reaches a terminal state.
|
|
232
|
+
*
|
|
233
|
+
* @param params - The pending revocation parameters.
|
|
234
|
+
* @returns A promise that resolves when the listener is set up.
|
|
235
|
+
*/
|
|
236
|
+
addPendingRevocation(params: PendingRevocationParams): Promise<void>;
|
|
177
237
|
}
|
|
178
238
|
export {};
|
|
179
239
|
//# sourceMappingURL=GatorPermissionsController.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GatorPermissionsController.d.mts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,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;
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController.d.mts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,wBAAw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AE;YACR,aAAa,EAAE,MAAM,CAAC;YACtB,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC;QACF,UAAU,EAAE,iBAAiB,CAAC;KAC/B,GAAG,iBAAiB;IA6CrB;;;;;;;OAOG;IACU,gBAAgB,CAC3B,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,IAAI,CAAC;IA+ChB;;;;;;;;;;;;;;;;OAgBG;IACU,oBAAoB,CAC/B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,IAAI,CAAC;CAwMjB"}
|
|
@@ -3,7 +3,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
3
3
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
4
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
5
|
};
|
|
6
|
-
var _GatorPermissionsController_instances, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_setIsGatorPermissionsEnabled, _GatorPermissionsController_registerMessageHandlers, _GatorPermissionsController_assertGatorPermissionsEnabled, _GatorPermissionsController_handleSnapRequestToGatorPermissionsProvider, _GatorPermissionsController_sanitizeStoredGatorPermission, _GatorPermissionsController_categorizePermissionsDataByTypeAndChainId;
|
|
6
|
+
var _GatorPermissionsController_instances, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_setIsGatorPermissionsEnabled, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext, _GatorPermissionsController_registerMessageHandlers, _GatorPermissionsController_assertGatorPermissionsEnabled, _GatorPermissionsController_handleSnapRequestToGatorPermissionsProvider, _GatorPermissionsController_sanitizeStoredGatorPermission, _GatorPermissionsController_categorizePermissionsDataByTypeAndChainId;
|
|
7
7
|
import { BaseController } from "@metamask/base-controller";
|
|
8
8
|
import { DELEGATOR_CONTRACTS } from "@metamask/delegation-deployments";
|
|
9
9
|
import { HandlerType } from "@metamask/snaps-utils";
|
|
@@ -29,6 +29,11 @@ const defaultGatorPermissionsMap = {
|
|
|
29
29
|
* contract addresses from `@metamask/delegation-deployments`.
|
|
30
30
|
*/
|
|
31
31
|
export const DELEGATION_FRAMEWORK_VERSION = '1.3.0';
|
|
32
|
+
/**
|
|
33
|
+
* Timeout duration for pending revocations (2 hours in milliseconds).
|
|
34
|
+
* After this time, event listeners will be cleaned up to prevent memory leaks.
|
|
35
|
+
*/
|
|
36
|
+
const PENDING_REVOCATION_TIMEOUT = 2 * 60 * 60 * 1000;
|
|
32
37
|
const contractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];
|
|
33
38
|
const gatorPermissionsControllerMetadata = {
|
|
34
39
|
isGatorPermissionsEnabled: {
|
|
@@ -55,6 +60,12 @@ const gatorPermissionsControllerMetadata = {
|
|
|
55
60
|
includeInDebugSnapshot: false,
|
|
56
61
|
usedInUi: false,
|
|
57
62
|
},
|
|
63
|
+
pendingRevocations: {
|
|
64
|
+
includeInStateLogs: true,
|
|
65
|
+
persist: false,
|
|
66
|
+
includeInDebugSnapshot: false,
|
|
67
|
+
usedInUi: true,
|
|
68
|
+
},
|
|
58
69
|
};
|
|
59
70
|
/**
|
|
60
71
|
* Constructs the default {@link GatorPermissionsController} state. This allows
|
|
@@ -70,6 +81,7 @@ export function getDefaultGatorPermissionsControllerState() {
|
|
|
70
81
|
gatorPermissionsMapSerialized: serializeGatorPermissionsMap(defaultGatorPermissionsMap),
|
|
71
82
|
isFetchingGatorPermissions: false,
|
|
72
83
|
gatorPermissionsProviderSnapId: defaultGatorPermissionsProviderSnapId,
|
|
84
|
+
pendingRevocations: [],
|
|
73
85
|
};
|
|
74
86
|
}
|
|
75
87
|
/**
|
|
@@ -128,18 +140,28 @@ class GatorPermissionsController extends BaseController {
|
|
|
128
140
|
state.gatorPermissionsMapSerialized = serializeGatorPermissionsMap(defaultGatorPermissionsMap);
|
|
129
141
|
});
|
|
130
142
|
}
|
|
143
|
+
/**
|
|
144
|
+
* Gets the pending revocations list.
|
|
145
|
+
*
|
|
146
|
+
* @returns The pending revocations list.
|
|
147
|
+
*/
|
|
148
|
+
get pendingRevocations() {
|
|
149
|
+
return this.state.pendingRevocations;
|
|
150
|
+
}
|
|
131
151
|
/**
|
|
132
152
|
* Fetches the gator permissions from profile sync and updates the state.
|
|
133
153
|
*
|
|
154
|
+
* @param params - Optional parameters to pass to the snap's getGrantedPermissions method.
|
|
134
155
|
* @returns A promise that resolves to the gator permissions map.
|
|
135
156
|
* @throws {GatorPermissionsFetchError} If the gator permissions fetch fails.
|
|
136
157
|
*/
|
|
137
|
-
async fetchAndUpdateGatorPermissions() {
|
|
158
|
+
async fetchAndUpdateGatorPermissions(params) {
|
|
138
159
|
try {
|
|
139
160
|
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_setIsFetchingGatorPermissions).call(this, true);
|
|
140
161
|
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_assertGatorPermissionsEnabled).call(this);
|
|
141
162
|
const permissionsData = await __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_handleSnapRequestToGatorPermissionsProvider).call(this, {
|
|
142
163
|
snapId: this.state.gatorPermissionsProviderSnapId,
|
|
164
|
+
params,
|
|
143
165
|
});
|
|
144
166
|
const gatorPermissionsMap = __classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_categorizePermissionsDataByTypeAndChainId).call(this, permissionsData);
|
|
145
167
|
this.update((state) => {
|
|
@@ -217,6 +239,189 @@ class GatorPermissionsController extends BaseController {
|
|
|
217
239
|
});
|
|
218
240
|
}
|
|
219
241
|
}
|
|
242
|
+
/**
|
|
243
|
+
* Submits a revocation to the gator permissions provider snap.
|
|
244
|
+
*
|
|
245
|
+
* @param revocationParams - The revocation parameters containing the permission context.
|
|
246
|
+
* @returns A promise that resolves when the revocation is submitted successfully.
|
|
247
|
+
* @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled.
|
|
248
|
+
* @throws {GatorPermissionsProviderError} If the snap request fails.
|
|
249
|
+
*/
|
|
250
|
+
async submitRevocation(revocationParams) {
|
|
251
|
+
controllerLog('submitRevocation method called', {
|
|
252
|
+
permissionContext: revocationParams.permissionContext,
|
|
253
|
+
});
|
|
254
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_assertGatorPermissionsEnabled).call(this);
|
|
255
|
+
try {
|
|
256
|
+
const snapRequest = {
|
|
257
|
+
snapId: this.state.gatorPermissionsProviderSnapId,
|
|
258
|
+
origin: 'metamask',
|
|
259
|
+
handler: HandlerType.OnRpcRequest,
|
|
260
|
+
request: {
|
|
261
|
+
jsonrpc: '2.0',
|
|
262
|
+
method: GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,
|
|
263
|
+
params: revocationParams,
|
|
264
|
+
},
|
|
265
|
+
};
|
|
266
|
+
const result = await this.messenger.call('SnapController:handleRequest', snapRequest);
|
|
267
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext).call(this, revocationParams.permissionContext);
|
|
268
|
+
controllerLog('Successfully submitted revocation', {
|
|
269
|
+
permissionContext: revocationParams.permissionContext,
|
|
270
|
+
result,
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
controllerLog('Failed to submit revocation', {
|
|
275
|
+
error,
|
|
276
|
+
permissionContext: revocationParams.permissionContext,
|
|
277
|
+
});
|
|
278
|
+
throw new GatorPermissionsProviderError({
|
|
279
|
+
method: GatorPermissionsSnapRpcMethod.PermissionProviderSubmitRevocation,
|
|
280
|
+
cause: error,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Adds a pending revocation that will be submitted once the transaction is confirmed.
|
|
286
|
+
*
|
|
287
|
+
* This method sets up listeners for the user's approval/rejection decision and
|
|
288
|
+
* terminal transaction states (confirmed, failed, dropped). The flow is:
|
|
289
|
+
* 1. Wait for user to approve or reject the transaction
|
|
290
|
+
* 2. If approved, add to pending revocations state
|
|
291
|
+
* 3. If rejected, cleanup without adding to state
|
|
292
|
+
* 4. If confirmed, submit the revocation
|
|
293
|
+
* 5. If failed or dropped, cleanup
|
|
294
|
+
*
|
|
295
|
+
* Includes a timeout safety net to prevent memory leaks if the transaction never
|
|
296
|
+
* reaches a terminal state.
|
|
297
|
+
*
|
|
298
|
+
* @param params - The pending revocation parameters.
|
|
299
|
+
* @returns A promise that resolves when the listener is set up.
|
|
300
|
+
*/
|
|
301
|
+
async addPendingRevocation(params) {
|
|
302
|
+
const { txId, permissionContext } = params;
|
|
303
|
+
controllerLog('addPendingRevocation method called', {
|
|
304
|
+
txId,
|
|
305
|
+
permissionContext,
|
|
306
|
+
});
|
|
307
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_assertGatorPermissionsEnabled).call(this);
|
|
308
|
+
// Track handlers and timeout for cleanup
|
|
309
|
+
const handlers = {
|
|
310
|
+
approved: undefined,
|
|
311
|
+
rejected: undefined,
|
|
312
|
+
confirmed: undefined,
|
|
313
|
+
failed: undefined,
|
|
314
|
+
dropped: undefined,
|
|
315
|
+
timeoutId: undefined,
|
|
316
|
+
};
|
|
317
|
+
// Helper to unsubscribe from approval/rejection events after decision is made
|
|
318
|
+
const cleanupApprovalHandlers = () => {
|
|
319
|
+
if (handlers.approved) {
|
|
320
|
+
this.messenger.unsubscribe('TransactionController:transactionApproved', handlers.approved);
|
|
321
|
+
handlers.approved = undefined;
|
|
322
|
+
}
|
|
323
|
+
if (handlers.rejected) {
|
|
324
|
+
this.messenger.unsubscribe('TransactionController:transactionRejected', handlers.rejected);
|
|
325
|
+
handlers.rejected = undefined;
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
// Cleanup function to unsubscribe from all events and clear timeout
|
|
329
|
+
const cleanup = (txIdToRemove, removeFromState = true) => {
|
|
330
|
+
cleanupApprovalHandlers();
|
|
331
|
+
if (handlers.confirmed) {
|
|
332
|
+
this.messenger.unsubscribe('TransactionController:transactionConfirmed', handlers.confirmed);
|
|
333
|
+
}
|
|
334
|
+
if (handlers.failed) {
|
|
335
|
+
this.messenger.unsubscribe('TransactionController:transactionFailed', handlers.failed);
|
|
336
|
+
}
|
|
337
|
+
if (handlers.dropped) {
|
|
338
|
+
this.messenger.unsubscribe('TransactionController:transactionDropped', handlers.dropped);
|
|
339
|
+
}
|
|
340
|
+
if (handlers.timeoutId !== undefined) {
|
|
341
|
+
clearTimeout(handlers.timeoutId);
|
|
342
|
+
}
|
|
343
|
+
// Remove the pending revocation from the state (only if it was added)
|
|
344
|
+
if (removeFromState) {
|
|
345
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_removePendingRevocationFromStateByTxId).call(this, txIdToRemove);
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
// Handle approved transaction - add to pending revocations state
|
|
349
|
+
handlers.approved = (payload) => {
|
|
350
|
+
if (payload.transactionMeta.id === txId) {
|
|
351
|
+
controllerLog('Transaction approved by user, adding to pending revocations', {
|
|
352
|
+
txId,
|
|
353
|
+
permissionContext,
|
|
354
|
+
});
|
|
355
|
+
__classPrivateFieldGet(this, _GatorPermissionsController_instances, "m", _GatorPermissionsController_addPendingRevocationToState).call(this, txId, permissionContext);
|
|
356
|
+
// Unsubscribe from approval/rejection events since decision is made
|
|
357
|
+
cleanupApprovalHandlers();
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
// Handle rejected transaction - cleanup without adding to state
|
|
361
|
+
handlers.rejected = (payload) => {
|
|
362
|
+
if (payload.transactionMeta.id === txId) {
|
|
363
|
+
controllerLog('Transaction rejected by user, cleaning up listeners', {
|
|
364
|
+
txId,
|
|
365
|
+
permissionContext,
|
|
366
|
+
});
|
|
367
|
+
// Don't remove from state since it was never added
|
|
368
|
+
cleanup(payload.transactionMeta.id, false);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
// Handle confirmed transaction - submit revocation
|
|
372
|
+
handlers.confirmed = (transactionMeta) => {
|
|
373
|
+
if (transactionMeta.id === txId) {
|
|
374
|
+
controllerLog('Transaction confirmed, submitting revocation', {
|
|
375
|
+
txId,
|
|
376
|
+
permissionContext,
|
|
377
|
+
});
|
|
378
|
+
this.submitRevocation({ permissionContext }).catch((error) => {
|
|
379
|
+
controllerLog('Failed to submit revocation after transaction confirmed', {
|
|
380
|
+
txId,
|
|
381
|
+
permissionContext,
|
|
382
|
+
error,
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
cleanup(transactionMeta.id);
|
|
386
|
+
}
|
|
387
|
+
};
|
|
388
|
+
// Handle failed transaction - cleanup without submitting revocation
|
|
389
|
+
handlers.failed = (payload) => {
|
|
390
|
+
if (payload.transactionMeta.id === txId) {
|
|
391
|
+
controllerLog('Transaction failed, cleaning up revocation listener', {
|
|
392
|
+
txId,
|
|
393
|
+
permissionContext,
|
|
394
|
+
error: payload.error,
|
|
395
|
+
});
|
|
396
|
+
cleanup(payload.transactionMeta.id);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
// Handle dropped transaction - cleanup without submitting revocation
|
|
400
|
+
handlers.dropped = (payload) => {
|
|
401
|
+
if (payload.transactionMeta.id === txId) {
|
|
402
|
+
controllerLog('Transaction dropped, cleaning up revocation listener', {
|
|
403
|
+
txId,
|
|
404
|
+
permissionContext,
|
|
405
|
+
});
|
|
406
|
+
cleanup(payload.transactionMeta.id);
|
|
407
|
+
}
|
|
408
|
+
};
|
|
409
|
+
// Subscribe to user approval/rejection events
|
|
410
|
+
this.messenger.subscribe('TransactionController:transactionApproved', handlers.approved);
|
|
411
|
+
this.messenger.subscribe('TransactionController:transactionRejected', handlers.rejected);
|
|
412
|
+
// Subscribe to terminal transaction events
|
|
413
|
+
this.messenger.subscribe('TransactionController:transactionConfirmed', handlers.confirmed);
|
|
414
|
+
this.messenger.subscribe('TransactionController:transactionFailed', handlers.failed);
|
|
415
|
+
this.messenger.subscribe('TransactionController:transactionDropped', handlers.dropped);
|
|
416
|
+
// Set timeout as safety net to prevent memory leaks
|
|
417
|
+
handlers.timeoutId = setTimeout(() => {
|
|
418
|
+
controllerLog('Pending revocation timed out, cleaning up listeners', {
|
|
419
|
+
txId,
|
|
420
|
+
permissionContext,
|
|
421
|
+
});
|
|
422
|
+
cleanup(txId);
|
|
423
|
+
}, PENDING_REVOCATION_TIMEOUT);
|
|
424
|
+
}
|
|
220
425
|
}
|
|
221
426
|
_GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsController_setIsFetchingGatorPermissions = function _GatorPermissionsController_setIsFetchingGatorPermissions(isFetchingGatorPermissions) {
|
|
222
427
|
this.update((state) => {
|
|
@@ -226,11 +431,29 @@ _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsControll
|
|
|
226
431
|
this.update((state) => {
|
|
227
432
|
state.isGatorPermissionsEnabled = isGatorPermissionsEnabled;
|
|
228
433
|
});
|
|
434
|
+
}, _GatorPermissionsController_addPendingRevocationToState = function _GatorPermissionsController_addPendingRevocationToState(txId, permissionContext) {
|
|
435
|
+
this.update((state) => {
|
|
436
|
+
state.pendingRevocations = [
|
|
437
|
+
...state.pendingRevocations,
|
|
438
|
+
{ txId, permissionContext },
|
|
439
|
+
];
|
|
440
|
+
});
|
|
441
|
+
}, _GatorPermissionsController_removePendingRevocationFromStateByTxId = function _GatorPermissionsController_removePendingRevocationFromStateByTxId(txId) {
|
|
442
|
+
this.update((state) => {
|
|
443
|
+
state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.txId !== txId);
|
|
444
|
+
});
|
|
445
|
+
}, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext = function _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext(permissionContext) {
|
|
446
|
+
this.update((state) => {
|
|
447
|
+
state.pendingRevocations = state.pendingRevocations.filter((pendingRevocations) => pendingRevocations.permissionContext !== permissionContext);
|
|
448
|
+
});
|
|
229
449
|
}, _GatorPermissionsController_registerMessageHandlers = function _GatorPermissionsController_registerMessageHandlers() {
|
|
230
450
|
this.messenger.registerActionHandler(`${controllerName}:fetchAndUpdateGatorPermissions`, this.fetchAndUpdateGatorPermissions.bind(this));
|
|
231
451
|
this.messenger.registerActionHandler(`${controllerName}:enableGatorPermissions`, this.enableGatorPermissions.bind(this));
|
|
232
452
|
this.messenger.registerActionHandler(`${controllerName}:disableGatorPermissions`, this.disableGatorPermissions.bind(this));
|
|
233
453
|
this.messenger.registerActionHandler(`${controllerName}:decodePermissionFromPermissionContextForOrigin`, this.decodePermissionFromPermissionContextForOrigin.bind(this));
|
|
454
|
+
const submitRevocationAction = `${controllerName}:submitRevocation`;
|
|
455
|
+
this.messenger.registerActionHandler(submitRevocationAction, this.submitRevocation.bind(this));
|
|
456
|
+
this.messenger.registerActionHandler(`${controllerName}:addPendingRevocation`, this.addPendingRevocation.bind(this));
|
|
234
457
|
}, _GatorPermissionsController_assertGatorPermissionsEnabled = function _GatorPermissionsController_assertGatorPermissionsEnabled() {
|
|
235
458
|
if (!this.state.isGatorPermissionsEnabled) {
|
|
236
459
|
throw new GatorPermissionsNotEnabledError();
|
|
@@ -241,9 +464,10 @@ _GatorPermissionsController_instances = new WeakSet(), _GatorPermissionsControll
|
|
|
241
464
|
*
|
|
242
465
|
* @param args - The request parameters.
|
|
243
466
|
* @param args.snapId - The ID of the Snap of the gator permissions provider snap.
|
|
467
|
+
* @param args.params - Optional parameters to pass to the snap method.
|
|
244
468
|
* @returns A promise that resolves with the gator permissions.
|
|
245
469
|
*/
|
|
246
|
-
async function _GatorPermissionsController_handleSnapRequestToGatorPermissionsProvider({ snapId, }) {
|
|
470
|
+
async function _GatorPermissionsController_handleSnapRequestToGatorPermissionsProvider({ snapId, params, }) {
|
|
247
471
|
try {
|
|
248
472
|
const response = (await this.messenger.call('SnapController:handleRequest', {
|
|
249
473
|
snapId,
|
|
@@ -252,6 +476,7 @@ async function _GatorPermissionsController_handleSnapRequestToGatorPermissionsPr
|
|
|
252
476
|
request: {
|
|
253
477
|
jsonrpc: '2.0',
|
|
254
478
|
method: GatorPermissionsSnapRpcMethod.PermissionProviderGetGrantedPermissions,
|
|
479
|
+
...(params !== undefined && { params }),
|
|
255
480
|
},
|
|
256
481
|
}));
|
|
257
482
|
return response;
|