@metamask-previews/gator-permissions-controller 5.0.2-preview-b13d916 → 5.0.2-preview-4f4c98e
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 +4 -0
- package/dist/{GatorPermissionsController-method-action-types.d.mts → GatorPermissionsController-method-action-types.d.ts} +2 -2
- package/dist/GatorPermissionsController-method-action-types.d.ts.map +1 -0
- package/dist/{GatorPermissionsController-method-action-types.mjs → GatorPermissionsController-method-action-types.js} +1 -1
- package/dist/GatorPermissionsController-method-action-types.js.map +1 -0
- package/dist/{GatorPermissionsController.d.cts → GatorPermissionsController.d.ts} +12 -12
- package/dist/GatorPermissionsController.d.ts.map +1 -0
- package/dist/{GatorPermissionsController.mjs → GatorPermissionsController.js} +12 -12
- package/dist/GatorPermissionsController.js.map +1 -0
- package/dist/{constants.d.cts → constants.d.ts} +4 -4
- package/dist/constants.d.ts.map +1 -0
- package/dist/{constants.mjs → constants.js} +1 -1
- package/dist/constants.js.map +1 -0
- package/dist/decodePermission/{decodePermission.d.mts → decodePermission.d.ts} +3 -3
- package/dist/decodePermission/decodePermission.d.ts.map +1 -0
- package/dist/decodePermission/{decodePermission.mjs → decodePermission.js} +3 -3
- package/dist/decodePermission/decodePermission.js.map +1 -0
- package/dist/decodePermission/decoders/{index.d.cts → index.d.ts} +3 -3
- package/dist/decodePermission/decoders/index.d.ts.map +1 -0
- package/dist/decodePermission/decoders/{index.mjs → index.js} +3 -3
- package/dist/decodePermission/decoders/index.js.map +1 -0
- package/dist/decodePermission/decoders/{makePermissionDecoder.d.cts → makePermissionDecoder.d.ts} +3 -3
- package/dist/decodePermission/decoders/makePermissionDecoder.d.ts.map +1 -0
- package/dist/decodePermission/decoders/{makePermissionDecoder.mjs → makePermissionDecoder.js} +4 -4
- package/dist/decodePermission/decoders/makePermissionDecoder.js.map +1 -0
- package/dist/decodePermission/{enforcerAddresses.d.cts → enforcerAddresses.d.ts} +3 -3
- package/dist/decodePermission/enforcerAddresses.d.ts.map +1 -0
- package/dist/decodePermission/{enforcerAddresses.mjs → enforcerAddresses.js} +4 -4
- package/dist/decodePermission/enforcerAddresses.js.map +1 -0
- package/dist/decodePermission/{index.d.cts → index.d.ts} +4 -4
- package/dist/decodePermission/index.d.ts.map +1 -0
- package/dist/decodePermission/index.js +3 -0
- package/dist/decodePermission/index.js.map +1 -0
- package/dist/decodePermission/{types.d.mts → types.d.ts} +4 -4
- package/dist/decodePermission/types.d.ts.map +1 -0
- package/dist/decodePermission/types.js +2 -0
- package/dist/decodePermission/types.js.map +1 -0
- package/dist/decodePermission/{utils.d.cts → utils.d.ts} +3 -3
- package/dist/decodePermission/utils.d.ts.map +1 -0
- package/dist/decodePermission/{utils.mjs → utils.js} +2 -2
- package/dist/decodePermission/utils.js.map +1 -0
- package/dist/{errors.d.cts → errors.d.ts} +3 -3
- package/dist/errors.d.ts.map +1 -0
- package/dist/{errors.mjs → errors.js} +2 -2
- package/dist/errors.js.map +1 -0
- package/dist/{index.d.cts → index.d.ts} +10 -10
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/{logger.d.cts → logger.d.ts} +2 -3
- package/dist/logger.d.ts.map +1 -0
- package/dist/{logger.mjs → logger.js} +2 -2
- package/dist/logger.js.map +1 -0
- package/dist/{payeeRule.d.cts → payeeRule.d.ts} +2 -2
- package/dist/payeeRule.d.ts.map +1 -0
- package/dist/payeeRule.js +2 -0
- package/dist/payeeRule.js.map +1 -0
- package/dist/{permissionOnChainStatus.d.mts → permissionOnChainStatus.d.ts} +5 -5
- package/dist/permissionOnChainStatus.d.ts.map +1 -0
- package/dist/{permissionOnChainStatus.mjs → permissionOnChainStatus.js} +7 -7
- package/dist/permissionOnChainStatus.js.map +1 -0
- package/dist/{redeemerRule.d.mts → redeemerRule.d.ts} +2 -2
- package/dist/redeemerRule.d.ts.map +1 -0
- package/dist/redeemerRule.js +2 -0
- package/dist/redeemerRule.js.map +1 -0
- package/dist/{types.d.cts → types.d.ts} +4 -4
- package/dist/types.d.ts.map +1 -0
- package/dist/{types.mjs → types.js} +1 -1
- package/dist/types.js.map +1 -0
- package/dist/{utils.d.cts → utils.d.ts} +5 -5
- package/dist/utils.d.ts.map +1 -0
- package/dist/{utils.mjs → utils.js} +4 -4
- package/dist/utils.js.map +1 -0
- package/package.json +12 -16
- package/dist/GatorPermissionsController-method-action-types.cjs +0 -7
- package/dist/GatorPermissionsController-method-action-types.cjs.map +0 -1
- package/dist/GatorPermissionsController-method-action-types.d.cts +0 -118
- package/dist/GatorPermissionsController-method-action-types.d.cts.map +0 -1
- package/dist/GatorPermissionsController-method-action-types.d.mts.map +0 -1
- package/dist/GatorPermissionsController-method-action-types.mjs.map +0 -1
- package/dist/GatorPermissionsController.cjs +0 -589
- package/dist/GatorPermissionsController.cjs.map +0 -1
- package/dist/GatorPermissionsController.d.cts.map +0 -1
- package/dist/GatorPermissionsController.d.mts +0 -219
- package/dist/GatorPermissionsController.d.mts.map +0 -1
- package/dist/GatorPermissionsController.mjs.map +0 -1
- package/dist/constants.cjs +0 -29
- package/dist/constants.cjs.map +0 -1
- package/dist/constants.d.cts.map +0 -1
- package/dist/constants.d.mts +0 -26
- package/dist/constants.d.mts.map +0 -1
- package/dist/constants.mjs.map +0 -1
- package/dist/decodePermission/decodePermission.cjs +0 -110
- package/dist/decodePermission/decodePermission.cjs.map +0 -1
- package/dist/decodePermission/decodePermission.d.cts +0 -72
- package/dist/decodePermission/decodePermission.d.cts.map +0 -1
- package/dist/decodePermission/decodePermission.d.mts.map +0 -1
- package/dist/decodePermission/decodePermission.mjs.map +0 -1
- package/dist/decodePermission/decoders/index.cjs +0 -26
- package/dist/decodePermission/decoders/index.cjs.map +0 -1
- package/dist/decodePermission/decoders/index.d.cts.map +0 -1
- package/dist/decodePermission/decoders/index.d.mts +0 -20
- package/dist/decodePermission/decoders/index.d.mts.map +0 -1
- package/dist/decodePermission/decoders/index.mjs.map +0 -1
- package/dist/decodePermission/decoders/makePermissionDecoder.cjs +0 -108
- package/dist/decodePermission/decoders/makePermissionDecoder.cjs.map +0 -1
- package/dist/decodePermission/decoders/makePermissionDecoder.d.cts.map +0 -1
- package/dist/decodePermission/decoders/makePermissionDecoder.d.mts +0 -46
- package/dist/decodePermission/decoders/makePermissionDecoder.d.mts.map +0 -1
- package/dist/decodePermission/decoders/makePermissionDecoder.mjs.map +0 -1
- package/dist/decodePermission/enforcerAddresses.cjs +0 -39
- package/dist/decodePermission/enforcerAddresses.cjs.map +0 -1
- package/dist/decodePermission/enforcerAddresses.d.cts.map +0 -1
- package/dist/decodePermission/enforcerAddresses.d.mts +0 -13
- package/dist/decodePermission/enforcerAddresses.d.mts.map +0 -1
- package/dist/decodePermission/enforcerAddresses.mjs.map +0 -1
- package/dist/decodePermission/index.cjs +0 -10
- package/dist/decodePermission/index.cjs.map +0 -1
- package/dist/decodePermission/index.d.cts.map +0 -1
- package/dist/decodePermission/index.d.mts +0 -4
- package/dist/decodePermission/index.d.mts.map +0 -1
- package/dist/decodePermission/index.mjs +0 -3
- package/dist/decodePermission/index.mjs.map +0 -1
- package/dist/decodePermission/types.cjs +0 -3
- package/dist/decodePermission/types.cjs.map +0 -1
- package/dist/decodePermission/types.d.cts +0 -64
- package/dist/decodePermission/types.d.cts.map +0 -1
- package/dist/decodePermission/types.d.mts.map +0 -1
- package/dist/decodePermission/types.mjs +0 -2
- package/dist/decodePermission/types.mjs.map +0 -1
- package/dist/decodePermission/utils.cjs +0 -125
- package/dist/decodePermission/utils.cjs.map +0 -1
- package/dist/decodePermission/utils.d.cts.map +0 -1
- package/dist/decodePermission/utils.d.mts +0 -68
- package/dist/decodePermission/utils.d.mts.map +0 -1
- package/dist/decodePermission/utils.mjs.map +0 -1
- package/dist/errors.cjs +0 -54
- package/dist/errors.cjs.map +0 -1
- package/dist/errors.d.cts.map +0 -1
- package/dist/errors.d.mts +0 -39
- package/dist/errors.d.mts.map +0 -1
- package/dist/errors.mjs.map +0 -1
- package/dist/index.cjs +0 -14
- package/dist/index.cjs.map +0 -1
- package/dist/index.d.cts.map +0 -1
- package/dist/index.d.mts +0 -10
- package/dist/index.d.mts.map +0 -1
- package/dist/index.mjs +0 -3
- package/dist/index.mjs.map +0 -1
- package/dist/logger.cjs +0 -10
- package/dist/logger.cjs.map +0 -1
- package/dist/logger.d.cts.map +0 -1
- package/dist/logger.d.mts +0 -7
- package/dist/logger.d.mts.map +0 -1
- package/dist/logger.mjs.map +0 -1
- package/dist/payeeRule.cjs +0 -3
- package/dist/payeeRule.cjs.map +0 -1
- package/dist/payeeRule.d.cts.map +0 -1
- package/dist/payeeRule.d.mts +0 -12
- package/dist/payeeRule.d.mts.map +0 -1
- package/dist/payeeRule.mjs +0 -2
- package/dist/payeeRule.mjs.map +0 -1
- package/dist/permissionOnChainStatus.cjs +0 -140
- package/dist/permissionOnChainStatus.cjs.map +0 -1
- package/dist/permissionOnChainStatus.d.cts +0 -73
- package/dist/permissionOnChainStatus.d.cts.map +0 -1
- package/dist/permissionOnChainStatus.d.mts.map +0 -1
- package/dist/permissionOnChainStatus.mjs.map +0 -1
- package/dist/redeemerRule.cjs +0 -3
- package/dist/redeemerRule.cjs.map +0 -1
- package/dist/redeemerRule.d.cts +0 -12
- package/dist/redeemerRule.d.cts.map +0 -1
- package/dist/redeemerRule.d.mts.map +0 -1
- package/dist/redeemerRule.mjs +0 -2
- package/dist/redeemerRule.mjs.map +0 -1
- package/dist/types.cjs +0 -28
- package/dist/types.cjs.map +0 -1
- package/dist/types.d.cts.map +0 -1
- package/dist/types.d.mts +0 -161
- package/dist/types.d.mts.map +0 -1
- package/dist/types.mjs.map +0 -1
- package/dist/utils.cjs +0 -41
- package/dist/utils.cjs.map +0 -1
- package/dist/utils.d.cts.map +0 -1
- package/dist/utils.d.mts +0 -22
- package/dist/utils.d.mts.map +0 -1
- package/dist/utils.mjs.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Changed
|
|
11
|
+
|
|
12
|
+
- **BREAKING:** Bump minimum Node.js version to 22 ([#9168](https://github.com/MetaMask/core/pull/9168))
|
|
13
|
+
|
|
10
14
|
## [5.0.2]
|
|
11
15
|
|
|
12
16
|
### Changed
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* This file is auto generated.
|
|
3
3
|
* Do not edit manually.
|
|
4
4
|
*/
|
|
5
|
-
import type { GatorPermissionsController } from
|
|
5
|
+
import type { GatorPermissionsController } from './GatorPermissionsController.js';
|
|
6
6
|
/**
|
|
7
7
|
* Fetches granted permissions from the gator permissions provider Snap and updates state.
|
|
8
8
|
* If a sync is already in progress, returns the same promise. After the sync completes,
|
|
@@ -115,4 +115,4 @@ export type GatorPermissionsControllerIsPendingRevocationAction = {
|
|
|
115
115
|
* Union of all GatorPermissionsController action types.
|
|
116
116
|
*/
|
|
117
117
|
export type GatorPermissionsControllerMethodActions = GatorPermissionsControllerFetchAndUpdateGatorPermissionsAction | GatorPermissionsControllerInitializeAction | GatorPermissionsControllerDecodePermissionFromPermissionContextForOriginAction | GatorPermissionsControllerSubmitRevocationAction | GatorPermissionsControllerAddPendingRevocationAction | GatorPermissionsControllerSubmitDirectRevocationAction | GatorPermissionsControllerIsPendingRevocationAction;
|
|
118
|
-
//# sourceMappingURL=GatorPermissionsController-method-action-types.d.
|
|
118
|
+
//# sourceMappingURL=GatorPermissionsController-method-action-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController-method-action-types.d.ts","sourceRoot":"","sources":["../src/GatorPermissionsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAElF;;;;;;;GAOG;AACH,MAAM,MAAM,8DAA8D,GAAG;IAC3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-action-types.js","sourceRoot":"","sources":["../src/GatorPermissionsController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { GatorPermissionsController } from './GatorPermissionsController.js';\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 * the enforcers do not match any supported permission type, no candidate type validates\n * the caveat terms, or more than one permission type successfully validates\n * (ambiguous delegation).\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"]}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { ControllerGetStateAction, ControllerStateChangeEvent } from
|
|
2
|
-
import { BaseController } from
|
|
3
|
-
import type { Messenger } from
|
|
4
|
-
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from
|
|
5
|
-
import type { SnapControllerHandleRequestAction, SnapControllerHasSnapAction } from
|
|
6
|
-
import type { SnapId } from
|
|
7
|
-
import type { TransactionControllerTransactionApprovedEvent, TransactionControllerTransactionConfirmedEvent, TransactionControllerTransactionDroppedEvent, TransactionControllerTransactionFailedEvent, TransactionControllerTransactionRejectedEvent } from
|
|
8
|
-
import type { Hex } from
|
|
9
|
-
import type { DecodedPermission } from
|
|
10
|
-
import type { GatorPermissionsControllerMethodActions } from
|
|
11
|
-
import type { PermissionInfoWithMetadata, SupportedPermissionType, DelegationDetails, RevocationParams, PendingRevocationParams } from
|
|
1
|
+
import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
|
|
2
|
+
import { BaseController } from '@metamask/base-controller';
|
|
3
|
+
import type { Messenger } from '@metamask/messenger';
|
|
4
|
+
import type { NetworkControllerFindNetworkClientIdByChainIdAction, NetworkControllerGetNetworkClientByIdAction } from '@metamask/network-controller';
|
|
5
|
+
import type { SnapControllerHandleRequestAction, SnapControllerHasSnapAction } from '@metamask/snaps-controllers';
|
|
6
|
+
import type { SnapId } from '@metamask/snaps-sdk';
|
|
7
|
+
import type { TransactionControllerTransactionApprovedEvent, TransactionControllerTransactionConfirmedEvent, TransactionControllerTransactionDroppedEvent, TransactionControllerTransactionFailedEvent, TransactionControllerTransactionRejectedEvent } from '@metamask/transaction-controller';
|
|
8
|
+
import type { Hex } from '@metamask/utils';
|
|
9
|
+
import type { DecodedPermission } from './decodePermission/index.js';
|
|
10
|
+
import type { GatorPermissionsControllerMethodActions } from './GatorPermissionsController-method-action-types.js';
|
|
11
|
+
import type { PermissionInfoWithMetadata, SupportedPermissionType, DelegationDetails, RevocationParams, PendingRevocationParams } from './types.js';
|
|
12
12
|
declare const controllerName = "GatorPermissionsController";
|
|
13
13
|
/**
|
|
14
14
|
* Configuration for {@link GatorPermissionsController}.
|
|
@@ -216,4 +216,4 @@ export declare class GatorPermissionsController extends BaseController<typeof co
|
|
|
216
216
|
isPendingRevocation(permissionContext: Hex): boolean;
|
|
217
217
|
}
|
|
218
218
|
export default GatorPermissionsController;
|
|
219
|
-
//# sourceMappingURL=GatorPermissionsController.d.
|
|
219
|
+
//# sourceMappingURL=GatorPermissionsController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController.d.ts","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,mDAAmD,EACnD,2CAA2C,EAE5C,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,iCAAiC,EACjC,2BAA2B,EAC5B,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EAAE,MAAM,EAAE,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AE,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,CAsDpB;IAED;;;;;;OAMG;IACU,gBAAgB,CAC3B,gBAAgB,EAAE,gBAAgB,GACjC,OAAO,CAAC,IAAI,CAAC,CAgEf;IAED;;;;;;;;;;;;;;;;OAgBG;IACU,oBAAoB,CAC/B,MAAM,EAAE,uBAAuB,GAC9B,OAAO,CAAC,IAAI,CAAC,CAiPf;IAED;;;;;;;;;;;;;OAaG;IACU,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAY3E;IAED;;;;;OAKG;IACI,mBAAmB,CAAC,iBAAiB,EAAE,GAAG,GAAG,OAAO,CAQ1D;CACF;eAEc,0BAA0B"}
|
|
@@ -10,17 +10,17 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
12
|
var _GatorPermissionsController_instances, _GatorPermissionsController_supportedPermissionTypes, _GatorPermissionsController_gatorPermissionsProviderSnapId, _GatorPermissionsController_maxSyncIntervalMs, _GatorPermissionsController_fetchAndUpdateGatorPermissionsPromise, _GatorPermissionsController_setIsFetchingGatorPermissions, _GatorPermissionsController_addPendingRevocationToState, _GatorPermissionsController_removePendingRevocationFromStateByTxId, _GatorPermissionsController_removePendingRevocationFromStateByPermissionContext, _GatorPermissionsController_buildPreviousStatusByContext, _GatorPermissionsController_getProviderForChainId, _GatorPermissionsController_updateGrantedPermissionsStatus, _GatorPermissionsController_storedPermissionToPermissionInfo, _GatorPermissionsController_storedPermissionsToPermissionInfoWithMetadata;
|
|
13
|
-
import { BaseController } from
|
|
14
|
-
import { HandlerType } from
|
|
15
|
-
import { TransactionStatus } from
|
|
16
|
-
import { createPermissionDecodersForContracts } from
|
|
17
|
-
import { delegationContractsByChainId, toEnforcerAddressesByName } from
|
|
18
|
-
import { findDecodersWithMatchingCaveatAddresses, reconstructDecodedPermission, selectUniqueDecoderAndDecodedPermission } from
|
|
19
|
-
import { GatorPermissionsFetchError, GatorPermissionsProviderError, OriginNotAllowedError, PermissionDecodingError } from
|
|
20
|
-
import { controllerLog } from
|
|
21
|
-
import { updateGrantedPermissionsStatus } from
|
|
22
|
-
import { GatorPermissionsSnapRpcMethod } from
|
|
23
|
-
import { executeSnapRpc } from
|
|
13
|
+
import { BaseController } from '@metamask/base-controller';
|
|
14
|
+
import { HandlerType } from '@metamask/snaps-utils';
|
|
15
|
+
import { TransactionStatus } from '@metamask/transaction-controller';
|
|
16
|
+
import { createPermissionDecodersForContracts } from './decodePermission/decoders/index.js';
|
|
17
|
+
import { delegationContractsByChainId, toEnforcerAddressesByName, } from './decodePermission/enforcerAddresses.js';
|
|
18
|
+
import { findDecodersWithMatchingCaveatAddresses, reconstructDecodedPermission, selectUniqueDecoderAndDecodedPermission, } from './decodePermission/index.js';
|
|
19
|
+
import { GatorPermissionsFetchError, GatorPermissionsProviderError, OriginNotAllowedError, PermissionDecodingError, } from './errors.js';
|
|
20
|
+
import { controllerLog } from './logger.js';
|
|
21
|
+
import { updateGrantedPermissionsStatus } from './permissionOnChainStatus.js';
|
|
22
|
+
import { GatorPermissionsSnapRpcMethod } from './types.js';
|
|
23
|
+
import { executeSnapRpc } from './utils.js';
|
|
24
24
|
// === GENERAL ===
|
|
25
25
|
// Unique name for the controller
|
|
26
26
|
const controllerName = 'GatorPermissionsController';
|
|
@@ -582,4 +582,4 @@ _GatorPermissionsController_supportedPermissionTypes = new WeakMap(), _GatorPerm
|
|
|
582
582
|
});
|
|
583
583
|
};
|
|
584
584
|
export default GatorPermissionsController;
|
|
585
|
-
//# sourceMappingURL=GatorPermissionsController.
|
|
585
|
+
//# sourceMappingURL=GatorPermissionsController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GatorPermissionsController.js","sourceRoot":"","sources":["../src/GatorPermissionsController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAY3D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAUrE,OAAO,EAAE,oCAAoC,EAAE,MAAM,sCAAsC,CAAC;AAC5F,OAAO,EACL,4BAA4B,EAC5B,yBAAyB,GAC1B,MAAM,yCAAyC,CAAC;AAEjD,OAAO,EACL,uCAAuC,EACvC,4BAA4B,EAC5B,uCAAuC,GACxC,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,0BAA0B,EAC1B,6BAA6B,EAC7B,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,8BAA8B,CAAC;AAE9E,OAAO,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAU3D,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAE5C,kBAAkB;AAElB,iCAAiC;AACjC,MAAM,cAAc,GAAG,4BAA4B,CAAC;AAEpD,MAAM,yBAAyB,GAAG;IAChC,gCAAgC;IAChC,YAAY;IACZ,gDAAgD;IAChD,kBAAkB;IAClB,sBAAsB;IACtB,wBAAwB;IACxB,qBAAqB;CACb,CAAC;AAEX,2DAA2D;AAC3D,MAAM,qCAAqC,GACzC,sCAAgD,CAAC;AAEnD,MAAM,4BAA4B,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC,0BAA0B;AAE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AAc,IAAI,QAAQ,CAC3B,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC;AA+iBH,eAAe,0BAA0B,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { Messenger } from '@metamask/messenger';\nimport type {\n NetworkControllerFindNetworkClientIdByChainIdAction,\n NetworkControllerGetNetworkClientByIdAction,\n NetworkClientId,\n} from '@metamask/network-controller';\nimport type {\n SnapControllerHandleRequestAction,\n SnapControllerHasSnapAction,\n} 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 { createPermissionDecodersForContracts } from './decodePermission/decoders/index.js';\nimport {\n delegationContractsByChainId,\n toEnforcerAddressesByName,\n} from './decodePermission/enforcerAddresses.js';\nimport type { DecodedPermission } from './decodePermission/index.js';\nimport {\n findDecodersWithMatchingCaveatAddresses,\n reconstructDecodedPermission,\n selectUniqueDecoderAndDecodedPermission,\n} from './decodePermission/index.js';\nimport {\n GatorPermissionsFetchError,\n GatorPermissionsProviderError,\n OriginNotAllowedError,\n PermissionDecodingError,\n} from './errors.js';\nimport type { GatorPermissionsControllerMethodActions } from './GatorPermissionsController-method-action-types.js';\nimport { controllerLog } from './logger.js';\nimport { updateGrantedPermissionsStatus } from './permissionOnChainStatus.js';\nimport type { PermissionStatusEip1193Provider } from './permissionOnChainStatus.js';\nimport { GatorPermissionsSnapRpcMethod } from './types.js';\nimport type {\n StoredGatorPermission,\n PermissionInfoWithMetadata,\n GatorPermissionStatus,\n SupportedPermissionType,\n DelegationDetails,\n RevocationParams,\n PendingRevocationParams,\n} from './types.js';\nimport { executeSnapRpc } from './utils.js';\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\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, status, 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:hasSnap are allowed to be\n * called internally because they are used to fetch gator permissions from the\n * Snap.\n */\ntype AllowedActions =\n | SnapControllerHandleRequestAction\n | SnapControllerHasSnapAction\n | NetworkControllerFindNetworkClientIdByChainIdAction\n | NetworkControllerGetNetworkClientByIdAction;\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 * Maps permission `context` (lowercase hex) to the last known {@link PermissionStatus}\n * from the current controller state (used when merging after a snap sync).\n *\n * @returns Map from lowercase `permissionResponse.context` to the prior {@link PermissionStatus}.\n */\n #buildPreviousStatusByContext(): Map<string, GatorPermissionStatus> {\n const map = new Map<string, GatorPermissionStatus>();\n for (const prev of this.state.grantedPermissions) {\n map.set(\n prev.permissionResponse.context.toLowerCase(),\n prev.status ?? 'Active',\n );\n }\n return map;\n }\n\n async #getProviderForChainId(\n chainId: Hex,\n ): Promise<PermissionStatusEip1193Provider> {\n const networkClientId: NetworkClientId = this.messenger.call(\n 'NetworkController:findNetworkClientIdByChainId',\n chainId,\n );\n const { provider } = this.messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n );\n return provider as PermissionStatusEip1193Provider;\n }\n\n async #updateGrantedPermissionsStatus(\n grantedPermissions: PermissionInfoWithMetadata[],\n ): Promise<PermissionInfoWithMetadata[]> {\n return updateGrantedPermissionsStatus(grantedPermissions, {\n getProviderForChainId: (chainId) => this.#getProviderForChainId(chainId),\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 * @param status - The status for this permission.\n * @returns Permission info with metadata for state/UI.\n */\n #storedPermissionToPermissionInfo(\n storedGatorPermission: StoredGatorPermission,\n status: GatorPermissionStatus,\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 status,\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 const previousStatusByContext = this.#buildPreviousStatusByContext();\n\n return storedGatorPermissions.map((storedPermission) => {\n const previousStatus = previousStatusByContext.get(\n storedPermission.permissionResponse.context.toLowerCase(),\n );\n return this.#storedPermissionToPermissionInfo(\n storedPermission,\n previousStatus ?? 'Active',\n );\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\n const grantedPermissionsWithStatus =\n await this.#updateGrantedPermissionsStatus(grantedPermissions);\n\n this.update((state) => {\n state.grantedPermissions = grantedPermissionsWithStatus;\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 * the enforcers do not match any supported permission type, no candidate type validates\n * the caveat terms, or more than one permission type successfully validates\n * (ambiguous delegation).\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 deploymentContracts = delegationContractsByChainId[chainId];\n\n try {\n if (!deploymentContracts) {\n throw new Error(`Contracts not found for chainId: ${chainId}`);\n }\n\n const contracts = toEnforcerAddressesByName(deploymentContracts);\n\n const enforcers = caveats.map((caveat) => caveat.enforcer);\n const permissionDecoders =\n createPermissionDecodersForContracts(contracts);\n\n // Every decoder where enforcer addresses match; multiple types may share the\n // same caveat pattern and are disambiguated by validateAndDecodePermission.\n const matchingDecoders = findDecodersWithMatchingCaveatAddresses({\n enforcers,\n permissionDecoders,\n });\n\n const {\n decoder: { permissionType },\n expiry,\n data,\n rules,\n } = selectUniqueDecoderAndDecodedPermission({\n candidateDecoders: matchingDecoders,\n caveats,\n });\n\n const permission = reconstructDecodedPermission({\n chainId,\n permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n rules,\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"]}
|
|
@@ -8,19 +8,19 @@ export declare const DELEGATION_FRAMEWORK_VERSION = "1.3.0";
|
|
|
8
8
|
* redeemer allowlists (RedeemerEnforcer). Hosts should advertise this for every
|
|
9
9
|
* supported execution permission type.
|
|
10
10
|
*/
|
|
11
|
-
export declare const EXECUTION_PERMISSION_REDEEMER_RULE_TYPE:
|
|
11
|
+
export declare const EXECUTION_PERMISSION_REDEEMER_RULE_TYPE: 'redeemer';
|
|
12
12
|
/**
|
|
13
13
|
* `Rule.type` / `wallet_getSupportedExecutionPermissions` `ruleTypes` entry for
|
|
14
14
|
* payee allowlists (AllowedCalldataEnforcer / AllowedTargetsEnforcer). Hosts
|
|
15
15
|
* should advertise this for every supported execution permission type that supports
|
|
16
16
|
* payee restrictions.
|
|
17
17
|
*/
|
|
18
|
-
export declare const EXECUTION_PERMISSION_PAYEE_RULE_TYPE:
|
|
18
|
+
export declare const EXECUTION_PERMISSION_PAYEE_RULE_TYPE: 'payee';
|
|
19
19
|
/**
|
|
20
20
|
* `Rule.type` / `wallet_getSupportedExecutionPermissions` `ruleTypes` entry for
|
|
21
21
|
* permission expiry derived from a TimestampEnforcer caveat. The decoded
|
|
22
22
|
* permission additionally hoists the expiry value onto its top-level `expiry`
|
|
23
23
|
* field for convenience.
|
|
24
24
|
*/
|
|
25
|
-
export declare const EXECUTION_PERMISSION_EXPIRY_RULE_TYPE:
|
|
26
|
-
//# sourceMappingURL=constants.d.
|
|
25
|
+
export declare const EXECUTION_PERMISSION_EXPIRY_RULE_TYPE: 'expiry';
|
|
26
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,eAAO,MAAM,4BAA4B,UAAU,CAAC;AAEpD;;;;GAIG;AACH,eAAO,MAAM,uCAAuC,EAAG,UAAmB,CAAC;AAE3E;;;;;GAKG;AACH,eAAO,MAAM,oCAAoC,EAAG,OAAgB,CAAC;AAErE;;;;;GAKG;AACH,eAAO,MAAM,qCAAqC,EAAG,QAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,OAAO,CAAC;AAEpD;;;;GAIG;AACH,MAAM,CAAC,MAAM,uCAAuC,GAAG,UAAmB,CAAC;AAE3E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,OAAgB,CAAC;AAErE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,qCAAqC,GAAG,QAAiB,CAAC","sourcesContent":["/**\n * Delegation framework version used to select the correct deployed enforcer\n * contract addresses from `@metamask/delegation-deployments`.\n */\nexport const DELEGATION_FRAMEWORK_VERSION = '1.3.0';\n\n/**\n * `Rule.type` / `wallet_getSupportedExecutionPermissions` `ruleTypes` entry for\n * redeemer allowlists (RedeemerEnforcer). Hosts should advertise this for every\n * supported execution permission type.\n */\nexport const EXECUTION_PERMISSION_REDEEMER_RULE_TYPE = 'redeemer' as const;\n\n/**\n * `Rule.type` / `wallet_getSupportedExecutionPermissions` `ruleTypes` entry for\n * payee allowlists (AllowedCalldataEnforcer / AllowedTargetsEnforcer). Hosts\n * should advertise this for every supported execution permission type that supports\n * payee restrictions.\n */\nexport const EXECUTION_PERMISSION_PAYEE_RULE_TYPE = 'payee' as const;\n\n/**\n * `Rule.type` / `wallet_getSupportedExecutionPermissions` `ruleTypes` entry for\n * permission expiry derived from a TimestampEnforcer caveat. The decoded\n * permission additionally hoists the expiry value onto its top-level `expiry`\n * field for convenience.\n */\nexport const EXECUTION_PERMISSION_EXPIRY_RULE_TYPE = 'expiry' as const;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Caveat, Hex } from
|
|
2
|
-
import type { DecodedPermission, PermissionType, PermissionDecoder, ValidateAndDecodeResult } from
|
|
1
|
+
import type { Caveat, Hex } from '@metamask/delegation-core';
|
|
2
|
+
import type { DecodedPermission, PermissionType, PermissionDecoder, ValidateAndDecodeResult } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Returns every permission decoder whose caveat-address pattern matches the
|
|
5
5
|
* given enforcer list for the chain. Used when more than one permission type
|
|
@@ -69,4 +69,4 @@ export declare const reconstructDecodedPermission: ({ chainId, permissionType, d
|
|
|
69
69
|
rules?: DecodedPermission['rules'];
|
|
70
70
|
}) => DecodedPermission;
|
|
71
71
|
export {};
|
|
72
|
-
//# sourceMappingURL=decodePermission.d.
|
|
72
|
+
//# sourceMappingURL=decodePermission.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodePermission.d.ts","sourceRoot":"","sources":["../../src/decodePermission/decodePermission.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAI7D,OAAO,KAAK,EACV,iBAAiB,EACjB,cAAc,EACd,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;GAUG;AACH,eAAO,MAAM,uCAAuC,uCAGjD;IACD,SAAS,EAAE,GAAG,EAAE,CAAC;IACjB,kBAAkB,EAAE,iBAAiB,EAAE,CAAC;CACzC,KAAG,iBAAiB,EAIpB,CAAC;AAEF,KAAK,iCAAiC,GAAG,OAAO,CAC9C,uBAAuB,EACvB;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,CAClB,CAAC;AAEF,KAAK,2BAA2B,GAAG;IACjC,OAAO,EAAE,iBAAiB,CAAC;IAC3B,KAAK,EAAE,iCAAiC,CAAC,OAAO,CAAC,CAAC;IAClD,IAAI,EAAE,iCAAiC,CAAC,MAAM,CAAC,CAAC;IAChD,MAAM,EAAE,iCAAiC,CAAC,QAAQ,CAAC,CAAC;CACrD,CAAC;AAEF;;;;;;;;;GASG;AACH,eAAO,MAAM,uCAAuC,oCAGjD;IACD,iBAAiB,EAAE,iBAAiB,EAAE,CAAC;IACvC,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;CACxB,KAAG,2BAqDH,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,4BAA4B,sHAWtC;IACD,OAAO,EAAE,MAAM,CAAC;IAChB,cAAc,EAAE,cAAc,CAAC;IAC/B,SAAS,EAAE,GAAG,CAAC;IACf,QAAQ,EAAE,GAAG,CAAC;IACd,SAAS,EAAE,GAAG,CAAC;IACf,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,IAAI,EAAE,iBAAiB,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,CAAC;IAC9C,aAAa,EAAE,MAAM,CAAC;IACtB,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,CAAC,EAAE,iBAAiB,CAAC,OAAO,CAAC,CAAC;CACpC,KAAG,iBAoBH,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ROOT_AUTHORITY } from
|
|
2
|
-
import { numberToHex } from
|
|
1
|
+
import { ROOT_AUTHORITY } from '@metamask/delegation-core';
|
|
2
|
+
import { numberToHex } from '@metamask/utils';
|
|
3
3
|
/**
|
|
4
4
|
* Returns every permission decoder whose caveat-address pattern matches the
|
|
5
5
|
* given enforcer list for the chain. Used when more than one permission type
|
|
@@ -101,4 +101,4 @@ export const reconstructDecodedPermission = ({ chainId, permissionType, delegato
|
|
|
101
101
|
};
|
|
102
102
|
return permission;
|
|
103
103
|
};
|
|
104
|
-
//# sourceMappingURL=decodePermission.
|
|
104
|
+
//# sourceMappingURL=decodePermission.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decodePermission.js","sourceRoot":"","sources":["../../src/decodePermission/decodePermission.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAS9C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC,EACtD,SAAS,EACT,kBAAkB,GAInB,EAAuB,EAAE;IACxB,OAAO,kBAAkB,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAC3C,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,CACxC,CAAC;A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AI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,MAAM,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IAChC,CAAC;IAED,MAAM,OAAO,GAAG,cAAc;SAC3B,GAAG,CACF,CAAC,OAAO,EAAE,EAAE,CACV,GAAG,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,KAAK,OAAO,CAAC,KAAK,CAAC,OAAO,EAAE,CAChE;SACA,IAAI,CAAC,IAAI,CAAC,CAAC;IAEd,MAAM,IAAI,KAAK,CACb,uEAAuE,OAAO,EAAE,CACjF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,EAC3C,OAAO,EACP,cAAc,EACd,SAAS,EACT,QAAQ,EACR,SAAS,EACT,MAAM,EACN,IAAI,EACJ,aAAa,EACb,eAAe,EACf,KAAK,GAYN,EAAqB,EAAE;IACtB,IAAI,SAAS,KAAK,cAAc,EAAE,CAAC;QACjC,MAAM,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAAC;IACvC,CAAC;IAED,MAAM,UAAU,GAAsB;QACpC,OAAO,EAAE,WAAW,CAAC,OAAO,CAAC;QAC7B,IAAI,EAAE,SAAS;QACf,EAAE,EAAE,QAAQ;QACZ,UAAU,EAAE;YACV,IAAI,EAAE,cAAc;YACpB,IAAI;YACJ,aAAa;SACd;QACD,MAAM;QACN,MAAM,EAAE,eAAe;QACvB,GAAG,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC;KAC1C,CAAC;IAEF,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC","sourcesContent":["import type { Caveat, Hex } from '@metamask/delegation-core';\nimport { ROOT_AUTHORITY } from '@metamask/delegation-core';\nimport { numberToHex } from '@metamask/utils';\n\nimport type {\n DecodedPermission,\n PermissionType,\n PermissionDecoder,\n ValidateAndDecodeResult,\n} from './types.js';\n\n/**\n * Returns every permission decoder whose caveat-address pattern matches the\n * given enforcer list for the chain. Used when more than one permission type\n * can share the same enforcer set; the caller must disambiguate by validating\n * caveat terms (see {@link selectUniqueDecoderAndDecodedPermission}).\n *\n * @param args - The arguments to this function.\n * @param args.enforcers - List of enforcer contract addresses (hex strings).\n * @param args.permissionDecoders - The permission decoders for the chain.\n * @returns All decoders that match, possibly empty.\n */\nexport const findDecodersWithMatchingCaveatAddresses = ({\n enforcers,\n permissionDecoders,\n}: {\n enforcers: Hex[];\n permissionDecoders: PermissionDecoder[];\n}): PermissionDecoder[] => {\n return permissionDecoders.filter((decoder) =>\n decoder.caveatAddressesMatch(enforcers),\n );\n};\n\ntype SuccessfulValidateAndDecodeResult = Extract<\n ValidateAndDecodeResult,\n { isValid: true }\n>;\n\ntype DecoderAndDecodedPermission = {\n decoder: PermissionDecoder;\n rules: SuccessfulValidateAndDecodeResult['rules'];\n data: SuccessfulValidateAndDecodeResult['data'];\n expiry: SuccessfulValidateAndDecodeResult['expiry'];\n};\n\n/**\n * Runs {@link PermissionDecoder.validateAndDecodePermission} on each candidate\n * decoder. Use when several decoders share the same caveat addresses.\n *\n * @param args - The arguments to this function.\n * @param args.candidateDecoders - Decoders whose addresses already match the caveats.\n * @param args.caveats - Caveats from the delegation.\n * @returns The unique decoder and decoded expiry/data when exactly one decoder validates.\n * @throws If `candidateDecoders` is empty, if no decoder validates, or if more than one decoder validates.\n */\nexport const selectUniqueDecoderAndDecodedPermission = ({\n candidateDecoders,\n caveats,\n}: {\n candidateDecoders: PermissionDecoder[];\n caveats: Caveat<Hex>[];\n}): DecoderAndDecodedPermission => {\n if (candidateDecoders.length === 0) {\n throw new Error('Unable to identify permission type');\n }\n\n const successfulDecodingResult: DecoderAndDecodedPermission[] = [];\n\n const failedAttempts: { permissionType: PermissionType; error: Error }[] = [];\n\n for (const decoder of candidateDecoders) {\n const decodeResult = decoder.validateAndDecodePermission(caveats);\n if (decodeResult.isValid) {\n successfulDecodingResult.push({\n decoder,\n rules: decodeResult.rules,\n data: decodeResult.data,\n expiry: decodeResult.expiry,\n });\n } else {\n failedAttempts.push({\n permissionType: decoder.permissionType,\n error: decodeResult.error,\n });\n }\n }\n\n if (successfulDecodingResult.length === 1) {\n return successfulDecodingResult[0];\n }\n\n if (successfulDecodingResult.length > 1) {\n const types = successfulDecodingResult\n .map((result) => result.decoder.permissionType)\n .join(', ');\n throw new Error(\n `Multiple permission types validate the same delegation caveats: ${types}`,\n );\n }\n\n if (failedAttempts.length === 1) {\n throw failedAttempts[0].error;\n }\n\n const details = failedAttempts\n .map(\n (attempt) =>\n `${String(attempt.permissionType)}: ${attempt.error.message}`,\n )\n .join('; ');\n\n throw new Error(\n `No permission type could validate the delegation caveats. Attempts: ${details}`,\n );\n};\n\n/**\n * Reconstructs a {@link DecodedPermission} object from primitive values\n * obtained while decoding a permission context.\n *\n * @param args - The arguments to this function.\n * @param args.chainId - Chain ID.\n * @param args.permissionType - Identified permission type.\n * @param args.delegator - Address of the account delegating permission.\n * @param args.delegate - Address that will act under the granted permission.\n * @param args.authority - Authority identifier; must be ROOT_AUTHORITY.\n * @param args.expiry - Expiry timestamp (unix seconds) or null if unbounded.\n * @param args.data - Permission-specific decoded data payload.\n * @param args.justification - Human-readable justification for the permission.\n * @param args.specifiedOrigin - The origin reported in the request metadata.\n * @param args.rules - Rules recovered from caveats (e.g. redeemer allowlist).\n *\n * @returns The reconstructed {@link DecodedPermission}.\n */\nexport const reconstructDecodedPermission = ({\n chainId,\n permissionType,\n delegator,\n delegate,\n authority,\n expiry,\n data,\n justification,\n specifiedOrigin,\n rules,\n}: {\n chainId: number;\n permissionType: PermissionType;\n delegator: Hex;\n delegate: Hex;\n authority: Hex;\n expiry: number | null;\n data: DecodedPermission['permission']['data'];\n justification: string;\n specifiedOrigin: string;\n rules?: DecodedPermission['rules'];\n}): DecodedPermission => {\n if (authority !== ROOT_AUTHORITY) {\n throw new Error('Invalid authority');\n }\n\n const permission: DecodedPermission = {\n chainId: numberToHex(chainId),\n from: delegator,\n to: delegate,\n permission: {\n type: permissionType,\n data,\n justification,\n },\n expiry,\n origin: specifiedOrigin,\n ...(rules === undefined ? {} : { rules }),\n };\n\n return permission;\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EnforcerAddressesByName } from
|
|
2
|
-
import type { PermissionDecoder } from
|
|
1
|
+
import type { EnforcerAddressesByName } from '@metamask/7715-permission-types';
|
|
2
|
+
import type { PermissionDecoder } from '../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Builds the canonical set of permission decoders for a chain.
|
|
5
5
|
*
|
|
@@ -17,4 +17,4 @@ import type { PermissionDecoder } from "../types.cjs";
|
|
|
17
17
|
* @throws Propagates any errors from resolving enforcer addresses.
|
|
18
18
|
*/
|
|
19
19
|
export declare const createPermissionDecodersForContracts: (contracts: EnforcerAddressesByName) => PermissionDecoder[];
|
|
20
|
-
//# sourceMappingURL=index.d.
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/decodePermission/decoders/index.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE/E,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGrD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,oCAAoC,cACpC,uBAAuB,KACjC,iBAAiB,EAEnB,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { makePermissionDecoderConfigs } from
|
|
2
|
-
import { makePermissionDecoder } from
|
|
1
|
+
import { makePermissionDecoderConfigs } from '@metamask/7715-permission-types';
|
|
2
|
+
import { makePermissionDecoder } from './makePermissionDecoder.js';
|
|
3
3
|
/**
|
|
4
4
|
* Builds the canonical set of permission decoders for a chain.
|
|
5
5
|
*
|
|
@@ -19,4 +19,4 @@ import { makePermissionDecoder } from "./makePermissionDecoder.mjs";
|
|
|
19
19
|
export const createPermissionDecodersForContracts = (contracts) => {
|
|
20
20
|
return makePermissionDecoderConfigs(contracts).map(makePermissionDecoder);
|
|
21
21
|
};
|
|
22
|
-
//# sourceMappingURL=index.
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/decodePermission/decoders/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,MAAM,iCAAiC,CAAC;AAI/E,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAEnE;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAAG,CAClD,SAAkC,EACb,EAAE;IACvB,OAAO,4BAA4B,CAAC,SAAS,CAAC,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAC5E,CAAC,CAAC","sourcesContent":["import { makePermissionDecoderConfigs } from '@metamask/7715-permission-types';\nimport type { EnforcerAddressesByName } from '@metamask/7715-permission-types';\n\nimport type { PermissionDecoder } from '../types.js';\nimport { makePermissionDecoder } from './makePermissionDecoder.js';\n\n/**\n * Builds the canonical set of permission decoders for a chain.\n *\n * Each decoder specifies the `permissionType`, required/optional enforcers,\n * and provides `caveatAddressesMatch` and `validateAndDecodePermission` so the\n * entire decode flow can be driven by the decoders.\n *\n * `contracts` should already be checksummed (see {@link toEnforcerAddressesByName}).\n * `makePermissionDecoderConfigs` checksums them again, and {@link makePermissionDecoder}\n * normalizes enforcer sets once more — see the module comment in\n * `makePermissionDecoder.ts` for why checksumming is layered this way.\n *\n * @param contracts - The deployed enforcer addresses for the chain.\n * @returns A list of permission decoders used to identify and decode permission types.\n * @throws Propagates any errors from resolving enforcer addresses.\n */\nexport const createPermissionDecodersForContracts = (\n contracts: EnforcerAddressesByName,\n): PermissionDecoder[] => {\n return makePermissionDecoderConfigs(contracts).map(makePermissionDecoder);\n};\n"]}
|
package/dist/decodePermission/decoders/{makePermissionDecoder.d.cts → makePermissionDecoder.d.ts}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PermissionDecoderConfig } from
|
|
2
|
-
import type { PermissionDecoder } from
|
|
1
|
+
import type { PermissionDecoderConfig } from '@metamask/7715-permission-types';
|
|
2
|
+
import type { PermissionDecoder } from '../types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Address checksumming in the permission decode flow.
|
|
5
5
|
*
|
|
@@ -43,4 +43,4 @@ import type { PermissionDecoder } from "../types.cjs";
|
|
|
43
43
|
* `validateAndDecodePermission`.
|
|
44
44
|
*/
|
|
45
45
|
export declare function makePermissionDecoder({ permissionType, contractAddresses, optionalEnforcers, requiredEnforcers, rules, validateAndDecodeData, }: PermissionDecoderConfig): PermissionDecoder;
|
|
46
|
-
//# sourceMappingURL=makePermissionDecoder.d.
|
|
46
|
+
//# sourceMappingURL=makePermissionDecoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makePermissionDecoder.d.ts","sourceRoot":"","sources":["../../../src/decodePermission/decoders/makePermissionDecoder.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,uBAAuB,EAExB,MAAM,iCAAiC,CAAC;AAMzC,OAAO,KAAK,EAAE,iBAAiB,EAA2B,MAAM,aAAa,CAAC;AAG9E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,EACL,qBAAqB,GACtB,EAAE,uBAAuB,GAAG,iBAAiB,CAgF7C"}
|
package/dist/decodePermission/decoders/{makePermissionDecoder.mjs → makePermissionDecoder.js}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { getChecksumAddress, isStrictHexString } from
|
|
2
|
-
import { EXECUTION_PERMISSION_EXPIRY_RULE_TYPE } from
|
|
3
|
-
import { buildEnforcerCountsAndSet, enforcersMatchRule } from
|
|
1
|
+
import { getChecksumAddress, isStrictHexString } from '@metamask/utils';
|
|
2
|
+
import { EXECUTION_PERMISSION_EXPIRY_RULE_TYPE } from '../../constants.js';
|
|
3
|
+
import { buildEnforcerCountsAndSet, enforcersMatchRule } from '../utils.js';
|
|
4
4
|
/**
|
|
5
5
|
* Address checksumming in the permission decode flow.
|
|
6
6
|
*
|
|
@@ -101,4 +101,4 @@ export function makePermissionDecoder({ permissionType, contractAddresses, optio
|
|
|
101
101
|
requiredEnforcers: requiredEnforcersMap,
|
|
102
102
|
};
|
|
103
103
|
}
|
|
104
|
-
//# sourceMappingURL=makePermissionDecoder.
|
|
104
|
+
//# sourceMappingURL=makePermissionDecoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makePermissionDecoder.js","sourceRoot":"","sources":["../../../src/decodePermission/decoders/makePermissionDecoder.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAGxE,OAAO,EAAE,qCAAqC,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAE5E;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,qBAAqB,CAAC,EACpC,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,iBAAiB,EACjB,KAAK,EACL,qBAAqB,GACG;IACxB,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAClC,iBAAiB,CAAC,GAAG,CAAC,kBAAkB,CAAC,CAC1C,CAAC;IACF,MAAM,oBAAoB,GAAG,IAAI,GAAG,CAClC,MAAM,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAA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gBAED,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;gBAExB,IAAI,IAAI,CAAC,IAAI,KAAK,qCAAqC,EAAE,CAAC;oBACxD,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,SAAmB,CAAC;gBACzC,CAAC;YACH,CAAC;YAED,MAAM,IAAI,GAAG,qBAAqB,CAAC,eAAe,EAAE,iBAAiB,CAAC,CAAC;YAEvE,OAAO;gBACL,OAAO,EAAE,IAAI;gBACb,MAAM;gBACN,IAAI;gBACJ,KAAK,EAAE,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS;aAC1D,CAAC;QACJ,CAAC;QAAC,OAAO,WAAW,EAAE,CAAC;YACrB,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,WAAoB,EAAE,CAAC;QACzD,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,cAAc;QACd,oBAAoB;QACpB,2BAA2B;QAC3B,iBAAiB,EAAE,oBAAoB;QACvC,iBAAiB,EAAE,oBAAoB;KACxC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n PermissionDecoderConfig,\n Rule,\n} from '@metamask/7715-permission-types';\nimport type { Caveat } from '@metamask/delegation-core';\nimport { getChecksumAddress, isStrictHexString } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { EXECUTION_PERMISSION_EXPIRY_RULE_TYPE } from '../../constants.js';\nimport type { PermissionDecoder, ValidateAndDecodeResult } from '../types.js';\nimport { buildEnforcerCountsAndSet, enforcersMatchRule } from '../utils.js';\n\n/**\n * Address checksumming in the permission decode flow.\n *\n * Enforcer addresses come from three sources, each of which may use a\n * different hex encoding (EIP-55 checksummed vs lowercase). Comparisons rely\n * on strict equality, so we normalize at function boundaries instead of\n * requiring callers to pass a specific encoding. `getChecksumAddress` is\n * idempotent, so repeated normalization is intentional and cheap.\n *\n * 1. **Canonical contract addresses** (`EnforcerAddressesByName`): normalized\n * in {@link toEnforcerAddressesByName}, again in\n * `makePermissionDecoderConfigs` (`checksumEnforcerAddresses` in\n * `@metamask/7715-permission-types`), and once more below when building\n * each decoder's required/optional enforcer sets.\n *\n * 2. **Delegation caveat enforcers**: read from the encoded permission\n * context with unpredictable casing. Normalized in\n * {@link buildEnforcerCountsAndSet} during address matching and again in\n * `validateAndDecodePermission` before term decoding (rule decoders and\n * `getTermsByEnforcer` compare enforcer addresses with `===`).\n *\n * 3. **Decoder required/optional enforcers**: populated from contract\n * addresses by `makePermissionDecoderConfigs`; normalized at decoder\n * construction so `caveatAddressesMatch` compares like-for-like with\n * caveat addresses from source (2).\n */\n\n/**\n * Creates a single {@link PermissionDecoder} with the given type, enforcer\n * sets, rule decoders, and decode/validate callback.\n *\n * @param config - The configuration describing the permission type's\n * enforcers, rule decoders, and data decoder. See\n * {@link PermissionDecoderConfig} for field documentation.\n * @param config.permissionType - The type of permission to decode.\n * @param config.contractAddresses - Checksummed enforcer addresses for the chain.\n * @param config.optionalEnforcers - Optional enforcers for the permission.\n * @param config.requiredEnforcers - Required enforcers for the permission.\n * @param config.rules - Rule decoders for the permission.\n * @param config.validateAndDecodeData - Data decoder for the permission.\n * @returns A {@link PermissionDecoder} with `caveatAddressesMatch` and\n * `validateAndDecodePermission`.\n */\nexport function makePermissionDecoder({\n permissionType,\n contractAddresses,\n optionalEnforcers,\n requiredEnforcers,\n rules,\n validateAndDecodeData,\n}: PermissionDecoderConfig): PermissionDecoder {\n const optionalEnforcersSet = new Set(\n optionalEnforcers.map(getChecksumAddress),\n );\n const requiredEnforcersMap = new Map(\n Object.entries(requiredEnforcers).map(([enforcer, count]) => [\n getChecksumAddress(enforcer as Hex),\n count,\n ]),\n );\n\n const caveatAddressesMatch = (caveatAddresses: Hex[]): boolean => {\n const { counts, enforcersSet } = buildEnforcerCountsAndSet(caveatAddresses);\n\n return enforcersMatchRule(\n counts,\n enforcersSet,\n requiredEnforcersMap,\n optionalEnforcersSet,\n );\n };\n\n const validateAndDecodePermission = (\n caveats: Caveat<Hex>[],\n ): ValidateAndDecodeResult => {\n const checksumCaveats: Caveat<Hex>[] = caveats.map((caveat) => ({\n ...caveat,\n enforcer: getChecksumAddress(caveat.enforcer),\n }));\n try {\n const invalidTerms = checksumCaveats.filter(\n // isStrictHexString rejects '0x' which is a valid terms value\n ({ terms }) => terms !== '0x' && !isStrictHexString(terms),\n );\n\n if (invalidTerms.length > 0) {\n throw new Error('Invalid terms: must be a hex string');\n }\n\n let expiry: number | null = null;\n const decodedRules: Rule[] = [];\n\n for (const decode of rules) {\n const rule = decode({\n contractAddresses,\n caveats: checksumCaveats,\n requiredEnforcers: requiredEnforcersMap,\n });\n\n if (rule === null) {\n continue;\n }\n\n decodedRules.push(rule);\n\n if (rule.type === EXECUTION_PERMISSION_EXPIRY_RULE_TYPE) {\n expiry = rule.data.timestamp as number;\n }\n }\n\n const data = validateAndDecodeData(checksumCaveats, contractAddresses);\n\n return {\n isValid: true,\n expiry,\n data,\n rules: decodedRules.length > 0 ? decodedRules : undefined,\n };\n } catch (caughtError) {\n return { isValid: false, error: caughtError as Error };\n }\n };\n\n return {\n permissionType,\n caveatAddressesMatch,\n validateAndDecodePermission,\n optionalEnforcers: optionalEnforcersSet,\n requiredEnforcers: requiredEnforcersMap,\n };\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EnforcerAddressesByName } from
|
|
2
|
-
import type { DelegationDeploymentsEnforcerAddressesByName } from
|
|
1
|
+
import type { EnforcerAddressesByName } from '@metamask/7715-permission-types';
|
|
2
|
+
import type { DelegationDeploymentsEnforcerAddressesByName } from '../types.js';
|
|
3
3
|
export declare const delegationContractsByChainId: Record<number, DelegationDeploymentsEnforcerAddressesByName>;
|
|
4
4
|
/**
|
|
5
5
|
* Converts delegation-deployments enforcer addresses to the canonical shape
|
|
@@ -10,4 +10,4 @@ export declare const delegationContractsByChainId: Record<number, DelegationDepl
|
|
|
10
10
|
* @throws If an expected enforcer contract is not found.
|
|
11
11
|
*/
|
|
12
12
|
export declare const toEnforcerAddressesByName: (contracts: DelegationDeploymentsEnforcerAddressesByName) => EnforcerAddressesByName;
|
|
13
|
-
//# sourceMappingURL=enforcerAddresses.d.
|
|
13
|
+
//# sourceMappingURL=enforcerAddresses.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforcerAddresses.d.ts","sourceRoot":"","sources":["../../src/decodePermission/enforcerAddresses.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAM/E,OAAO,KAAK,EAAE,4CAA4C,EAAE,MAAM,aAAa,CAAC;AAGhF,eAAO,MAAM,4BAA4B,EAEpC,MAAM,CAAC,MAAM,EAAE,4CAA4C,CAAC,CAAC;AAelE;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,cACzB,4CAA4C,KACtD,uBAqCD,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DELEGATOR_CONTRACTS } from
|
|
2
|
-
import { getChecksumAddress } from
|
|
3
|
-
import { DELEGATION_FRAMEWORK_VERSION } from
|
|
1
|
+
import { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';
|
|
2
|
+
import { getChecksumAddress } from '@metamask/utils';
|
|
3
|
+
import { DELEGATION_FRAMEWORK_VERSION } from '../constants.js';
|
|
4
4
|
// @metamask/delegation-deployments exports a very loosely typed object. We assert a more narrow typing here.
|
|
5
5
|
export const delegationContractsByChainId = DELEGATOR_CONTRACTS[DELEGATION_FRAMEWORK_VERSION];
|
|
6
6
|
const getChecksumContractAddress = (contracts, contractName) => {
|
|
@@ -32,4 +32,4 @@ export const toEnforcerAddressesByName = (contracts) => ({
|
|
|
32
32
|
timestampEnforcer: getChecksumContractAddress(contracts, 'TimestampEnforcer'),
|
|
33
33
|
nonceEnforcer: getChecksumContractAddress(contracts, 'NonceEnforcer'),
|
|
34
34
|
});
|
|
35
|
-
//# sourceMappingURL=enforcerAddresses.
|
|
35
|
+
//# sourceMappingURL=enforcerAddresses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enforcerAddresses.js","sourceRoot":"","sources":["../../src/decodePermission/enforcerAddresses.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AACvE,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD,OAAO,EAAE,4BAA4B,EAAE,MAAM,iBAAiB,CAAC;AAG/D,6GAA6G;AAC7G,MAAM,CAAC,MAAM,4BAA4B,GAAG,mBAAmB,CAC7D,4BAA4B,CACmC,CAAC;AAElE,MAAM,0BAA0B,GAAG,CACjC,SAAuD,EACvD,YAAgE,EAC3D,EAAE;IACP,MAAM,OAAO,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC;IAExC,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CAAC,uBAAuB,YAAY,EAAE,CAAC,CAAC;IACzD,CAAC;IAED,OAAO,kBAAkB,CAAC,OAAO,CAAC,CAAC;AACrC,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,SAAuD,EAC9B,EAAE,CAAC,CAAC;IAC7B,uBAAuB,EAAE,0BAA0B,CACjD,SAAS,EACT,yBAAyB,CAC1B;IACD,sBAAsB,EAAE,0BAA0B,CAChD,SAAS,EACT,wBAAwB,CACzB;IACD,gBAAgB,EAAE,0BAA0B,CAAC,SAAS,EAAE,kBAAkB,CAAC;IAC3E,sBAAsB,EAAE,0BAA0B,CAChD,SAAS,EACT,wBAAwB,CACzB;IACD,2BAA2B,EAAE,0BAA0B,CACrD,SAAS,EACT,6BAA6B,CAC9B;IACD,4BAA4B,EAAE,0BAA0B,CACtD,SAAS,EACT,8BAA8B,CAC/B;IACD,iCAAiC,EAAE,0BAA0B,CAC3D,SAAS,EACT,mCAAmC,CACpC;IACD,0BAA0B,EAAE,0BAA0B,CACpD,SAAS,EACT,4BAA4B,CAC7B;IACD,qBAAqB,EAAE,0BAA0B,CAC/C,SAAS,EACT,uBAAuB,CACxB;IACD,gBAAgB,EAAE,0BAA0B,CAAC,SAAS,EAAE,kBAAkB,CAAC;IAC3E,iBAAiB,EAAE,0BAA0B,CAAC,SAAS,EAAE,mBAAmB,CAAC;IAC7E,aAAa,EAAE,0BAA0B,CAAC,SAAS,EAAE,eAAe,CAAC;CACtE,CAAC,CAAC","sourcesContent":["import type { EnforcerAddressesByName } from '@metamask/7715-permission-types';\nimport { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments';\nimport { getChecksumAddress } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\n\nimport { DELEGATION_FRAMEWORK_VERSION } from '../constants.js';\nimport type { DelegationDeploymentsEnforcerAddressesByName } from '../types.js';\n\n// @metamask/delegation-deployments exports a very loosely typed object. We assert a more narrow typing here.\nexport const delegationContractsByChainId = DELEGATOR_CONTRACTS[\n DELEGATION_FRAMEWORK_VERSION\n] as Record<number, DelegationDeploymentsEnforcerAddressesByName>;\n\nconst getChecksumContractAddress = (\n contracts: DelegationDeploymentsEnforcerAddressesByName,\n contractName: keyof DelegationDeploymentsEnforcerAddressesByName,\n): Hex => {\n const address = contracts[contractName];\n\n if (!address) {\n throw new Error(`Contract not found: ${contractName}`);\n }\n\n return getChecksumAddress(address);\n};\n\n/**\n * Converts delegation-deployments enforcer addresses to the canonical shape\n * expected by `@metamask/7715-permission-types`, checksumming each address.\n *\n * @param contracts - Enforcer addresses keyed by delegation-deployments names.\n * @returns Checksummed enforcer addresses keyed by permission-types names.\n * @throws If an expected enforcer contract is not found.\n */\nexport const toEnforcerAddressesByName = (\n contracts: DelegationDeploymentsEnforcerAddressesByName,\n): EnforcerAddressesByName => ({\n allowedCalldataEnforcer: getChecksumContractAddress(\n contracts,\n 'AllowedCalldataEnforcer',\n ),\n allowedTargetsEnforcer: getChecksumContractAddress(\n contracts,\n 'AllowedTargetsEnforcer',\n ),\n redeemerEnforcer: getChecksumContractAddress(contracts, 'RedeemerEnforcer'),\n erc20StreamingEnforcer: getChecksumContractAddress(\n contracts,\n 'ERC20StreamingEnforcer',\n ),\n erc20PeriodTransferEnforcer: getChecksumContractAddress(\n contracts,\n 'ERC20PeriodTransferEnforcer',\n ),\n nativeTokenStreamingEnforcer: getChecksumContractAddress(\n contracts,\n 'NativeTokenStreamingEnforcer',\n ),\n nativeTokenPeriodTransferEnforcer: getChecksumContractAddress(\n contracts,\n 'NativeTokenPeriodTransferEnforcer',\n ),\n approvalRevocationEnforcer: getChecksumContractAddress(\n contracts,\n 'ApprovalRevocationEnforcer',\n ),\n exactCalldataEnforcer: getChecksumContractAddress(\n contracts,\n 'ExactCalldataEnforcer',\n ),\n valueLteEnforcer: getChecksumContractAddress(contracts, 'ValueLteEnforcer'),\n timestampEnforcer: getChecksumContractAddress(contracts, 'TimestampEnforcer'),\n nonceEnforcer: getChecksumContractAddress(contracts, 'NonceEnforcer'),\n});\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { findDecodersWithMatchingCaveatAddresses, reconstructDecodedPermission, selectUniqueDecoderAndDecodedPermission, } from
|
|
2
|
-
export { createPermissionDecodersForContracts } from
|
|
3
|
-
export type { DecodedPermission, PermissionDecoder, ValidateAndDecodeResult, } from
|
|
4
|
-
//# sourceMappingURL=index.d.
|
|
1
|
+
export { findDecodersWithMatchingCaveatAddresses, reconstructDecodedPermission, selectUniqueDecoderAndDecodedPermission, } from './decodePermission.js';
|
|
2
|
+
export { createPermissionDecodersForContracts } from './decoders/index.js';
|
|
3
|
+
export type { DecodedPermission, PermissionDecoder, ValidateAndDecodeResult, } from './types.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/decodePermission/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uCAAuC,EACvC,4BAA4B,EAC5B,uCAAuC,GACxC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oCAAoC,EAAE,MAAM,qBAAqB,CAAC;AAE3E,YAAY,EACV,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/decodePermission/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,uCAAuC,EACvC,4BAA4B,EAC5B,uCAAuC,GACxC,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,oCAAoC,EAAE,MAAM,qBAAqB,CAAC","sourcesContent":["export {\n findDecodersWithMatchingCaveatAddresses,\n reconstructDecodedPermission,\n selectUniqueDecoderAndDecodedPermission,\n} from './decodePermission.js';\nexport { createPermissionDecodersForContracts } from './decoders/index.js';\n\nexport type {\n DecodedPermission,\n PermissionDecoder,\n ValidateAndDecodeResult,\n} from './types.js';\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { PermissionRequest, PermissionTypes, Rule } from
|
|
2
|
-
import type { Caveat } from
|
|
3
|
-
import type { Hex } from
|
|
1
|
+
import type { PermissionRequest, PermissionTypes, Rule } from '@metamask/7715-permission-types';
|
|
2
|
+
import type { Caveat } from '@metamask/delegation-core';
|
|
3
|
+
import type { Hex } from '@metamask/utils';
|
|
4
4
|
/**
|
|
5
5
|
* A partially reconstructed permission object decoded from a permission context.
|
|
6
6
|
*
|
|
@@ -61,4 +61,4 @@ export type PermissionDecoder = {
|
|
|
61
61
|
*/
|
|
62
62
|
validateAndDecodePermission: (caveats: Caveat<Hex>[]) => ValidateAndDecodeResult;
|
|
63
63
|
};
|
|
64
|
-
//# sourceMappingURL=types.d.
|
|
64
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","s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,GAAG;IAC9B,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,EAAE,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;IACpC,iBAAiB,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;IAC5B;;;;OAIG;IACH,oBAAoB,EAAE,CAAC,eAAe,EAAE,GAAG,EAAE,KAAK,OAAO,CAAC;IAC1D;;;OAGG;IACH,2BAA2B,EAAE,CAC3B,OAAO,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,KACnB,uBAAuB,CAAC;CAC9B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/decodePermission/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n PermissionRequest,\n PermissionTypes,\n Rule,\n} from '@metamask/7715-permission-types';\nimport type { Caveat } from '@metamask/delegation-core';\nimport type { Hex } from '@metamask/utils';\n\n// This is a somewhat convoluted type - it includes all of the fields that are decoded from the permission context.\n/**\n * A partially reconstructed permission object decoded from a permission context.\n *\n * This mirrors the shape of {@link PermissionRequest} for fields that can be\n * deterministically recovered from the encoded permission context, and it\n * augments the result with an explicit `expiry` property derived from the\n * `TimestampEnforcer` terms, as well as the `origin` property.\n */\nexport type DecodedPermission = Pick<\n PermissionRequest<PermissionTypes>,\n 'chainId' | 'from' | 'to'\n> & {\n permission: Omit<\n PermissionRequest<PermissionTypes>['permission'],\n 'isAdjustmentAllowed' | 'type' | 'data'\n > & {\n type: PermissionTypes['type'];\n data: PermissionTypes['data'];\n // PermissionRequest type does not work well without the specific permission type, so we amend it here\n justification?: string;\n };\n /**\n * @deprecated Use `rules` instead.\n */\n expiry: number | null;\n origin: string;\n /** Rules recovered from caveats (e.g. redeemer allowlist). */\n rules?: Rule[];\n};\n\n/**\n * Supported permission type identifiers that can be decoded from a permission context.\n */\nexport type PermissionType = DecodedPermission['permission']['type'];\n\n/**\n * Result of validating and decoding permission terms from caveats.\n * When valid, includes expiry and decoded data; when invalid, includes the error.\n */\nexport type ValidateAndDecodeResult =\n | {\n isValid: true;\n expiry: number | null;\n data: DecodedPermission['permission']['data'];\n rules?: Rule[];\n }\n | { isValid: false; error: Error };\n\n/**\n * A decoder that defines the required and optional enforcers for a permission\n * type, and provides methods to test whether caveat addresses match the\n * permission and to validate and decode permission terms from caveats.\n */\nexport type PermissionDecoder = {\n permissionType: PermissionType;\n requiredEnforcers: Map<Hex, number>;\n optionalEnforcers: Set<Hex>;\n /**\n * Returns true if the given caveat addresses (enforcer addresses) match this\n * decoder (required enforcers present with correct multiplicity, no\n * forbidden enforcers).\n */\n caveatAddressesMatch: (caveatAddresses: Hex[]) => boolean;\n /**\n * Validates and decodes permission terms from the caveats. Returns a result\n * object with isValid; when valid, includes expiry and data.\n */\n validateAndDecodePermission: (\n caveats: Caveat<Hex>[],\n ) => ValidateAndDecodeResult;\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Caveat } from
|
|
2
|
-
import type { Hex } from
|
|
1
|
+
import type { Caveat } from '@metamask/delegation-core';
|
|
2
|
+
import type { Hex } from '@metamask/utils';
|
|
3
3
|
/**
|
|
4
4
|
* Extracts the expiry timestamp from TimestampEnforcer caveat terms.
|
|
5
5
|
* Terms are 32 bytes: first 16 bytes timestampAfterThreshold (must be 0),
|
|
@@ -65,4 +65,4 @@ export declare function getTermsByEnforcer<TThrowIfNotFound extends boolean = tr
|
|
|
65
65
|
* @returns An array of hex substrings (each with `0x` prefix), one for each part.
|
|
66
66
|
*/
|
|
67
67
|
export declare function splitHex(value: Hex, lengths: number[]): Hex[];
|
|
68
|
-
//# sourceMappingURL=utils.d.
|
|
68
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/decodePermission/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,2BAA2B,CAAC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