diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 9fafda276e0..081f53c2cea 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -1106,24 +1106,13 @@ } }, "packages/gator-permissions-controller/src/GatorPermissionsController.test.ts": { - "@typescript-eslint/explicit-function-return-type": { - "count": 2 - }, "id-denylist": { "count": 2 - }, - "no-new": { - "count": 1 } }, "packages/gator-permissions-controller/src/GatorPermissionsController.ts": { "@typescript-eslint/explicit-function-return-type": { - "count": 16 - } - }, - "packages/gator-permissions-controller/src/decodePermission/decodePermission.ts": { - "@typescript-eslint/explicit-function-return-type": { - "count": 1 + "count": 8 } }, "packages/gator-permissions-controller/src/decodePermission/utils.test.ts": { @@ -1142,11 +1131,6 @@ "count": 1 } }, - "packages/gator-permissions-controller/src/test/mocks.ts": { - "@typescript-eslint/explicit-function-return-type": { - "count": 1 - } - }, "packages/logging-controller/src/LoggingController.test.ts": { "@typescript-eslint/explicit-function-return-type": { "count": 1 diff --git a/packages/gator-permissions-controller/CHANGELOG.md b/packages/gator-permissions-controller/CHANGELOG.md index f570dcfec5c..49b3ebfab79 100644 --- a/packages/gator-permissions-controller/CHANGELOG.md +++ b/packages/gator-permissions-controller/CHANGELOG.md @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Bump `@metamask/snaps-utils` from `^11.0.0` to `^11.7.0` ([#7550](https://github.com/MetaMask/core/pull/7550)) - Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511)) - Bump `@metamask/transaction-controller` from `^62.5.0` to `^62.9.1` ([#7430](https://github.com/MetaMask/core/pull/7430), [#7494](https://github.com/MetaMask/core/pull/7494), [#7596](https://github.com/MetaMask/core/pull/7596), [#7602](https://github.com/MetaMask/core/pull/7602), [#7604](https://github.com/MetaMask/core/pull/7604)) +- **BREAKING:** Gator Permissions Controller and Gator Permission Decoder core types have been updated to comply with 7715 spec revisions ([#7613](https://github.com/MetaMask/core/pull/7613)) + - Bump `@metamask/7715-permission-type` from `^0.4.0` to `^0.5.0` ## [0.8.0] diff --git a/packages/gator-permissions-controller/package.json b/packages/gator-permissions-controller/package.json index 573e4a1fdb5..ebedd28b76e 100644 --- a/packages/gator-permissions-controller/package.json +++ b/packages/gator-permissions-controller/package.json @@ -48,7 +48,7 @@ "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch" }, "dependencies": { - "@metamask/7715-permission-types": "^0.4.0", + "@metamask/7715-permission-types": "^0.5.0", "@metamask/base-controller": "^9.0.0", "@metamask/delegation-core": "^0.2.0", "@metamask/delegation-deployments": "^0.12.0", diff --git a/packages/gator-permissions-controller/src/GatorPermissionsController.test.ts b/packages/gator-permissions-controller/src/GatorPermissionsController.test.ts index a46ca7879c7..8af70571b6a 100644 --- a/packages/gator-permissions-controller/src/GatorPermissionsController.test.ts +++ b/packages/gator-permissions-controller/src/GatorPermissionsController.test.ts @@ -1,4 +1,3 @@ -import type { AccountSigner } from '@metamask/7715-permission-types'; import { deriveStateFromMetadata } from '@metamask/base-controller'; import { createTimestampTerms, @@ -45,45 +44,43 @@ const MOCK_CHAIN_ID_1: Hex = '0xaa36a7'; const MOCK_CHAIN_ID_2: Hex = '0x1'; const MOCK_GATOR_PERMISSIONS_PROVIDER_SNAP_ID = 'local:http://localhost:8082' as SnapId; -const MOCK_GATOR_PERMISSIONS_STORAGE_ENTRIES: StoredGatorPermission< - AccountSigner, - PermissionTypesWithCustom ->[] = mockGatorPermissionsStorageEntriesFactory({ - [MOCK_CHAIN_ID_1]: { - nativeTokenStream: 5, - nativeTokenPeriodic: 5, - erc20TokenStream: 5, - erc20TokenPeriodic: 5, - custom: { - count: 2, - data: [ - { - customData: 'customData-0', - }, - { - customData: 'customData-1', - }, - ], +const MOCK_GATOR_PERMISSIONS_STORAGE_ENTRIES: StoredGatorPermission[] = + mockGatorPermissionsStorageEntriesFactory({ + [MOCK_CHAIN_ID_1]: { + nativeTokenStream: 5, + nativeTokenPeriodic: 5, + erc20TokenStream: 5, + erc20TokenPeriodic: 5, + custom: { + count: 2, + data: [ + { + customData: 'customData-0', + }, + { + customData: 'customData-1', + }, + ], + }, }, - }, - [MOCK_CHAIN_ID_2]: { - nativeTokenStream: 5, - nativeTokenPeriodic: 5, - erc20TokenStream: 5, - erc20TokenPeriodic: 5, - custom: { - count: 2, - data: [ - { - customData: 'customData-0', - }, - { - customData: 'customData-1', - }, - ], + [MOCK_CHAIN_ID_2]: { + nativeTokenStream: 5, + nativeTokenPeriodic: 5, + erc20TokenStream: 5, + erc20TokenPeriodic: 5, + custom: { + count: 2, + data: [ + { + customData: 'customData-0', + }, + { + customData: 'customData-1', + }, + ], + }, }, - }, -}); + }); describe('GatorPermissionsController', () => { describe('constructor', () => { @@ -246,13 +243,15 @@ describe('GatorPermissionsController', () => { expect(controller.state.isFetchingGatorPermissions).toBe(false); // check that the gator permissions map is sanitized - const sanitizedCheck = (permissionType: keyof GatorPermissionsMap) => { + const sanitizedCheck = ( + permissionType: keyof GatorPermissionsMap, + ): void => { const flattenedStoredGatorPermissions = Object.values( result[permissionType], ).flat(); flattenedStoredGatorPermissions.forEach((permission) => { - expect(permission.permissionResponse.signer).toBeUndefined(); - expect(permission.permissionResponse.dependencyInfo).toBeUndefined(); + expect(permission.permissionResponse.to).toBeUndefined(); + expect(permission.permissionResponse.dependencies).toBeUndefined(); }); }; @@ -288,11 +287,8 @@ describe('GatorPermissionsController', () => { const revocationEntry = { permissionResponse: { chainId, - address: '0x0000000000000000000000000000000000000001', - signer: { - type: 'account', - data: { address: '0x0000000000000000000000000000000000000002' }, - }, + from: '0x0000000000000000000000000000000000000001', + to: '0x0000000000000000000000000000000000000002', permission: { type: 'erc20-token-revocation', isAdjustmentAllowed: false, @@ -301,10 +297,8 @@ describe('GatorPermissionsController', () => { data: {} as any, }, context: '0xdeadbeef', - dependencyInfo: [], - signerMeta: { - delegationManager: '0x0000000000000000000000000000000000000003', - }, + dependencies: [], + delegationManager: '0x0000000000000000000000000000000000000003', }, siteOrigin: 'https://example.org', } as unknown; @@ -490,10 +484,11 @@ describe('GatorPermissionsController', () => { 'registerActionHandler', ); - new GatorPermissionsController({ + const controller = new GatorPermissionsController({ messenger, }); + expect(controller.state.isGatorPermissionsEnabled).toBe(false); expect(mockRegisterActionHandler).toHaveBeenCalledWith( 'GatorPermissionsController:fetchAndUpdateGatorPermissions', expect.any(Function), @@ -607,7 +602,9 @@ describe('GatorPermissionsController', () => { const delegateAddressB = '0x2222222222222222222222222222222222222222' as Hex; const metamaskOrigin = 'https://metamask.io'; - const buildMetadata = (justification: string) => ({ + const buildMetadata = ( + justification: string, + ): { justification: string; origin: string } => ({ justification, origin: metamaskOrigin, }); @@ -692,11 +689,8 @@ describe('GatorPermissionsController', () => { }); expect(result.chainId).toBe(numberToHex(chainId)); - expect(result.address).toBe(delegator); - expect(result.signer).toStrictEqual({ - type: 'account', - data: { address: delegate }, - }); + expect(result.from).toBe(delegator); + expect(result.to).toStrictEqual(delegate); expect(result.permission.type).toBe('native-token-stream'); expect(result.expiry).toBe(timestampBeforeThreshold); // amounts are hex-encoded in decoded data; startTime is numeric diff --git a/packages/gator-permissions-controller/src/GatorPermissionsController.ts b/packages/gator-permissions-controller/src/GatorPermissionsController.ts index de0756c849d..815fd6e6e88 100644 --- a/packages/gator-permissions-controller/src/GatorPermissionsController.ts +++ b/packages/gator-permissions-controller/src/GatorPermissionsController.ts @@ -1,4 +1,3 @@ -import type { Signer } from '@metamask/7715-permission-types'; import type { ControllerGetStateAction, ControllerStateChangeEvent, @@ -337,19 +336,19 @@ export default class GatorPermissionsController extends BaseController< this.#registerMessageHandlers(); } - #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean) { + #setIsFetchingGatorPermissions(isFetchingGatorPermissions: boolean): void { this.update((state) => { state.isFetchingGatorPermissions = isFetchingGatorPermissions; }); } - #setIsGatorPermissionsEnabled(isGatorPermissionsEnabled: boolean) { + #setIsGatorPermissionsEnabled(isGatorPermissionsEnabled: boolean): void { this.update((state) => { state.isGatorPermissionsEnabled = isGatorPermissionsEnabled; }); } - #addPendingRevocationToState(txId: string, permissionContext: Hex) { + #addPendingRevocationToState(txId: string, permissionContext: Hex): void { this.update((state) => { state.pendingRevocations = [ ...state.pendingRevocations, @@ -358,7 +357,7 @@ export default class GatorPermissionsController extends BaseController< }); } - #removePendingRevocationFromStateByTxId(txId: string) { + #removePendingRevocationFromStateByTxId(txId: string): void { this.update((state) => { state.pendingRevocations = state.pendingRevocations.filter( (pendingRevocations) => pendingRevocations.txId !== txId, @@ -366,7 +365,9 @@ export default class GatorPermissionsController extends BaseController< }); } - #removePendingRevocationFromStateByPermissionContext(permissionContext: Hex) { + #removePendingRevocationFromStateByPermissionContext( + permissionContext: Hex, + ): void { this.update((state) => { state.pendingRevocations = state.pendingRevocations.filter( (pendingRevocations) => @@ -425,7 +426,7 @@ export default class GatorPermissionsController extends BaseController< * * @throws {GatorPermissionsNotEnabledError} If the gator permissions are not enabled. */ - #assertGatorPermissionsEnabled() { + #assertGatorPermissionsEnabled(): void { if (!this.state.isGatorPermissionsEnabled) { throw new GatorPermissionsNotEnabledError(); } @@ -445,9 +446,7 @@ export default class GatorPermissionsController extends BaseController< }: { snapId: SnapId; params?: Json; - }): Promise< - StoredGatorPermission[] | null - > { + }): Promise[] | null> { try { const response = (await this.messenger.call( 'SnapController:handleRequest', @@ -462,7 +461,7 @@ export default class GatorPermissionsController extends BaseController< ...(params !== undefined && { params }), }, }, - )) as StoredGatorPermission[] | null; + )) as StoredGatorPermission[] | null; return response; } catch (error) { @@ -480,19 +479,16 @@ export default class GatorPermissionsController extends BaseController< /** * Sanitizes a stored gator permission for client exposure. - * Removes internal fields (dependencyInfo, signer) + * Removes internal fields (dependencies, to) * * @param storedGatorPermission - The stored gator permission to sanitize. * @returns The sanitized stored gator permission. */ #sanitizeStoredGatorPermission( - storedGatorPermission: StoredGatorPermission< - Signer, - PermissionTypesWithCustom - >, - ): StoredGatorPermissionSanitized { + storedGatorPermission: StoredGatorPermission, + ): StoredGatorPermissionSanitized { const { permissionResponse } = storedGatorPermission; - const { dependencyInfo, signer, ...rest } = permissionResponse; + const { dependencies, to, ...rest } = permissionResponse; return { ...storedGatorPermission, permissionResponse: { @@ -509,7 +505,7 @@ export default class GatorPermissionsController extends BaseController< */ #categorizePermissionsDataByTypeAndChainId( storedGatorPermissions: - | StoredGatorPermission[] + | StoredGatorPermission[] | null, ): GatorPermissionsMap { const gatorPermissionsMap = createEmptyGatorPermissionsMap(); @@ -570,14 +566,14 @@ export default class GatorPermissionsController extends BaseController< /** * Enables gator permissions for the user. */ - public async enableGatorPermissions() { + public async enableGatorPermissions(): Promise { this.#setIsGatorPermissionsEnabled(true); } /** * Clears the gator permissions map and disables the feature. */ - public async disableGatorPermissions() { + public async disableGatorPermissions(): Promise { this.update((state) => { state.isGatorPermissionsEnabled = false; state.gatorPermissionsMapSerialized = serializeGatorPermissionsMap( @@ -641,7 +637,7 @@ export default class GatorPermissionsController extends BaseController< * This method validates the caller origin, decodes the provided `permissionContext` * into delegations, identifies the permission type from the caveat enforcers, * extracts the permission-specific data and expiry, and reconstructs a - * {@link DecodedPermission} containing chainId, account addresses, signer, type and data. + * {@link DecodedPermission} containing chainId, account addresses, to, type and data. * * @param args - The arguments to this function. * @param args.origin - The caller's origin; must match the configured permissions provider Snap id. diff --git a/packages/gator-permissions-controller/src/decodePermission/decodePermission.test.ts b/packages/gator-permissions-controller/src/decodePermission/decodePermission.test.ts index 414c50389cb..a6c49ba4e2d 100644 --- a/packages/gator-permissions-controller/src/decodePermission/decodePermission.test.ts +++ b/packages/gator-permissions-controller/src/decodePermission/decodePermission.test.ts @@ -1204,11 +1204,8 @@ describe('decodePermission', () => { }); expect(result.chainId).toBe(numberToHex(chainId)); - expect(result.address).toBe(delegator); - expect(result.signer).toStrictEqual({ - type: 'account', - data: { address: delegate }, - }); + expect(result.from).toBe(delegator); + expect(result.to).toStrictEqual(delegate); expect(result.permission).toStrictEqual({ type: permissionType, data, diff --git a/packages/gator-permissions-controller/src/decodePermission/decodePermission.ts b/packages/gator-permissions-controller/src/decodePermission/decodePermission.ts index 2b1711b3c08..55ce1e48c05 100644 --- a/packages/gator-permissions-controller/src/decodePermission/decodePermission.ts +++ b/packages/gator-permissions-controller/src/decodePermission/decodePermission.ts @@ -321,15 +321,15 @@ export const reconstructDecodedPermission = ({ data: DecodedPermission['permission']['data']; justification: string; specifiedOrigin: string; -}) => { +}): DecodedPermission => { if (authority !== ROOT_AUTHORITY) { throw new Error('Invalid authority'); } const permission: DecodedPermission = { chainId: numberToHex(chainId), - address: delegator, - signer: { type: 'account', data: { address: delegate } }, + from: delegator, + to: delegate, permission: { type: permissionType, data, diff --git a/packages/gator-permissions-controller/src/decodePermission/types.ts b/packages/gator-permissions-controller/src/decodePermission/types.ts index 9a05a6d624a..85a28233375 100644 --- a/packages/gator-permissions-controller/src/decodePermission/types.ts +++ b/packages/gator-permissions-controller/src/decodePermission/types.ts @@ -1,7 +1,6 @@ import type { PermissionRequest, PermissionTypes, - Signer, } from '@metamask/7715-permission-types'; import type { DELEGATOR_CONTRACTS } from '@metamask/delegation-deployments'; @@ -18,11 +17,11 @@ export type DeployedContractsByName = * `TimestampEnforcer` terms, as well as the `origin` property. */ export type DecodedPermission = Pick< - PermissionRequest, - 'chainId' | 'address' | 'signer' + PermissionRequest, + 'chainId' | 'from' | 'to' > & { permission: Omit< - PermissionRequest['permission'], + PermissionRequest['permission'], 'isAdjustmentAllowed' > & { // PermissionRequest type does not work well without the specific permission type, so we amend it here diff --git a/packages/gator-permissions-controller/src/index.ts b/packages/gator-permissions-controller/src/index.ts index 9b13e2500c1..dcfefe7d566 100644 --- a/packages/gator-permissions-controller/src/index.ts +++ b/packages/gator-permissions-controller/src/index.ts @@ -44,8 +44,5 @@ export type { NativeTokenPeriodicPermission, Erc20TokenStreamPermission, Erc20TokenPeriodicPermission, - AccountSigner, - WalletSigner, - Signer, MetaMaskBasePermissionData, } from '@metamask/7715-permission-types'; diff --git a/packages/gator-permissions-controller/src/test/mocks.ts b/packages/gator-permissions-controller/src/test/mocks.ts index 322ffa6f230..afe9e8dca9a 100644 --- a/packages/gator-permissions-controller/src/test/mocks.ts +++ b/packages/gator-permissions-controller/src/test/mocks.ts @@ -1,5 +1,4 @@ import type { - AccountSigner, Erc20TokenPeriodicPermission, Erc20TokenStreamPermission, NativeTokenPeriodicPermission, @@ -15,14 +14,11 @@ import type { export const mockNativeTokenStreamStorageEntry = ( chainId: Hex, -): StoredGatorPermission => ({ +): StoredGatorPermission => ({ permissionResponse: { chainId, - address: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', - signer: { - type: 'account', - data: { address: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63' }, - }, + from: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', + to: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63', permission: { type: 'native-token-stream', isAdjustmentAllowed: true, @@ -36,29 +32,24 @@ export const mockNativeTokenStreamStorageEntry = ( }, }, context: '0x00000000', - dependencyInfo: [ + dependencies: [ { factory: '0x69Aa2f9fe1572F1B640E1bbc512f5c3a734fc77c', factoryData: '0x0000000', }, ], - signerMeta: { - delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', - }, + delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', }, siteOrigin: 'http://localhost:8000', }); export const mockNativeTokenPeriodicStorageEntry = ( chainId: Hex, -): StoredGatorPermission => ({ +): StoredGatorPermission => ({ permissionResponse: { chainId, - address: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', - signer: { - type: 'account', - data: { address: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63' }, - }, + from: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', + to: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63', permission: { type: 'native-token-periodic', isAdjustmentAllowed: true, @@ -71,29 +62,24 @@ export const mockNativeTokenPeriodicStorageEntry = ( }, }, context: '0x00000000', - dependencyInfo: [ + dependencies: [ { factory: '0x69Aa2f9fe1572F1B640E1bbc512f5c3a734fc77c', factoryData: '0x0000000', }, ], - signerMeta: { - delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', - }, + delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', }, siteOrigin: 'http://localhost:8000', }); export const mockErc20TokenStreamStorageEntry = ( chainId: Hex, -): StoredGatorPermission => ({ +): StoredGatorPermission => ({ permissionResponse: { chainId, - address: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', - signer: { - type: 'account', - data: { address: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63' }, - }, + from: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', + to: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63', permission: { type: 'erc20-token-stream', isAdjustmentAllowed: true, @@ -108,29 +94,24 @@ export const mockErc20TokenStreamStorageEntry = ( }, }, context: '0x00000000', - dependencyInfo: [ + dependencies: [ { factory: '0x69Aa2f9fe1572F1B640E1bbc512f5c3a734fc77c', factoryData: '0x0000000', }, ], - signerMeta: { - delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', - }, + delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', }, siteOrigin: 'http://localhost:8000', }); export const mockErc20TokenPeriodicStorageEntry = ( chainId: Hex, -): StoredGatorPermission => ({ +): StoredGatorPermission => ({ permissionResponse: { chainId, - address: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', - signer: { - type: 'account', - data: { address: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63' }, - }, + from: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', + to: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63', permission: { type: 'erc20-token-periodic', isAdjustmentAllowed: true, @@ -144,15 +125,13 @@ export const mockErc20TokenPeriodicStorageEntry = ( }, }, context: '0x00000000', - dependencyInfo: [ + dependencies: [ { factory: '0x69Aa2f9fe1572F1B640E1bbc512f5c3a734fc77c', factoryData: '0x0000000', }, ], - signerMeta: { - delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', - }, + delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', }, siteOrigin: 'http://localhost:8000', }); @@ -160,14 +139,11 @@ export const mockErc20TokenPeriodicStorageEntry = ( export const mockCustomPermissionStorageEntry = ( chainId: Hex, data: Record, -): StoredGatorPermission => ({ +): StoredGatorPermission => ({ permissionResponse: { chainId, - address: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', - signer: { - type: 'account', - data: { address: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63' }, - }, + from: '0xB68c70159E9892DdF5659ec42ff9BD2bbC23e778', + to: '0x4f71DA06987BfeDE90aF0b33E1e3e4ffDCEE7a63', permission: { type: 'custom', isAdjustmentAllowed: true, @@ -178,15 +154,13 @@ export const mockCustomPermissionStorageEntry = ( }, }, context: '0x00000000', - dependencyInfo: [ + dependencies: [ { factory: '0x69Aa2f9fe1572F1B640E1bbc512f5c3a734fc77c', factoryData: '0x0000000', }, ], - signerMeta: { - delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', - }, + delegationManager: '0xdb9B1e94B5b69Df7e401DDbedE43491141047dB3', }, siteOrigin: 'http://localhost:8000', }); @@ -218,11 +192,8 @@ export type MockGatorPermissionsStorageEntriesConfig = { */ export function mockGatorPermissionsStorageEntriesFactory( config: MockGatorPermissionsStorageEntriesConfig, -): StoredGatorPermission[] { - const result: StoredGatorPermission< - AccountSigner, - PermissionTypesWithCustom - >[] = []; +): StoredGatorPermission[] { + const result: StoredGatorPermission[] = []; Object.entries(config).forEach(([chainId, counts]) => { if (counts.custom.count !== counts.custom.data.length) { @@ -237,11 +208,8 @@ export function mockGatorPermissionsStorageEntriesFactory( */ const createEntries = ( count: number, - createEntry: () => StoredGatorPermission< - AccountSigner, - PermissionTypesWithCustom - >, - ) => { + createEntry: () => StoredGatorPermission, + ): void => { for (let i = 0; i < count; i++) { const entry = createEntry(); result.push(entry); diff --git a/packages/gator-permissions-controller/src/types.ts b/packages/gator-permissions-controller/src/types.ts index b1f57419e26..7fd028abd0b 100644 --- a/packages/gator-permissions-controller/src/types.ts +++ b/packages/gator-permissions-controller/src/types.ts @@ -1,6 +1,5 @@ import type { PermissionTypes, - Signer, BasePermission, NativeTokenStreamPermission, NativeTokenPeriodicPermission, @@ -55,13 +54,10 @@ export type PermissionTypesWithCustom = PermissionTypes | CustomPermission; /** * Represents a ERC-7715 permission request. * - * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner. + * @template to - The type of the signer provided, either an AccountSigner or WalletSigner. * @template Permission - The type of the permission provided. */ -export type PermissionRequest< - TSigner extends Signer, - TPermission extends PermissionTypesWithCustom, -> = { +export type PermissionRequest = { /** * hex-encoding of uint256 defined the chain with EIP-155 */ @@ -72,15 +68,15 @@ export type PermissionRequest< * The account being targeted for this permission request. * It is optional to let the user choose which account to grant permission from. */ - address?: Hex; + from?: Hex; /** - * An account that is associated with the recipient of the granted 7715 permission or alternatively the wallet will manage the session. + * A field that identifies the DApp session account associated with the permission */ - signer: TSigner; + to: Hex; /** - * Defines the allowed behavior the signer can do on behalf of the account. + * Defines the allowed behavior the `to` account can do on behalf of the `from` account. */ permission: TPermission; @@ -90,62 +86,53 @@ export type PermissionRequest< /** * Represents a ERC-7715 permission response. * - * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner. * @template Permission - The type of the permission provided. */ -export type PermissionResponse< - TSigner extends Signer, - TPermission extends PermissionTypesWithCustom, -> = PermissionRequest & { - /** - * Is a catch-all to identify a permission for revoking permissions or submitting - * Defined in ERC-7710. - */ - context: Hex; - - /** - * The dependencyInfo field is required and contains information needed to deploy accounts. - * Each entry specifies a factory contract and its associated deployment data. - * If no account deployment is needed when redeeming the permission, this array must be empty. - * When non-empty, DApps MUST deploy the accounts by calling the factory contract with factoryData as the calldata. - * Defined in ERC-4337. - */ - dependencyInfo: { - factory: Hex; - factoryData: Hex; - }[]; - - /** - * If the signer type is account then delegationManager is required as defined in ERC-7710. - */ - signerMeta: { +export type PermissionResponse = + PermissionRequest & { + /** + * Is a catch-all to identify a permission for revoking permissions or submitting + * Defined in ERC-7710. + */ + context: Hex; + + /** + * The dependencyInfo field is required and contains information needed to deploy accounts. + * Each entry specifies a factory contract and its associated deployment data. + * If no account deployment is needed when redeeming the permission, this array must be empty. + * When non-empty, DApps MUST deploy the accounts by calling the factory contract with factoryData as the calldata. + * Defined in ERC-4337. + */ + dependencies: { + factory: Hex; + factoryData: Hex; + }[]; + + /** + * Is required as defined in ERC-7710. + */ delegationManager: Hex; }; -}; /** * Represents a sanitized version of the PermissionResponse type. - * Internal fields (dependencyInfo, signer) are removed + * Internal fields (dependencies, to) are removed * - * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner. * @template Permission - The type of the permission provided. */ export type PermissionResponseSanitized< - TSigner extends Signer, TPermission extends PermissionTypesWithCustom, -> = Omit, 'dependencyInfo' | 'signer'>; +> = Omit, 'dependencies' | 'to'>; /** * Represents a gator ERC-7715 granted(ie. signed by an user account) permission entry that is stored in profile sync. * - * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner. * @template Permission - The type of the permission provided */ export type StoredGatorPermission< - TSigner extends Signer, TPermission extends PermissionTypesWithCustom, > = { - permissionResponse: PermissionResponse; + permissionResponse: PermissionResponse; siteOrigin: string; /** * Flag indicating whether this permission has been revoked. @@ -156,14 +143,12 @@ export type StoredGatorPermission< /** * Represents a sanitized version of the StoredGatorPermission type. Some fields have been removed but the fields are still present in profile sync. * - * @template Signer - The type of the signer provided, either an AccountSigner or WalletSigner. * @template Permission - The type of the permission provided. */ export type StoredGatorPermissionSanitized< - TSigner extends Signer, TPermission extends PermissionTypesWithCustom, > = { - permissionResponse: PermissionResponseSanitized; + permissionResponse: PermissionResponseSanitized; siteOrigin: string; /** * Flag indicating whether this permission has been revoked. @@ -176,37 +161,32 @@ export type StoredGatorPermissionSanitized< */ export type GatorPermissionsMap = { 'erc20-token-revocation': { - [chainId: Hex]: StoredGatorPermissionSanitized< - Signer, - Erc20TokenRevocationPermission - >[]; + [ + chainId: Hex + ]: StoredGatorPermissionSanitized[]; }; 'native-token-stream': { - [chainId: Hex]: StoredGatorPermissionSanitized< - Signer, - NativeTokenStreamPermission - >[]; + [ + chainId: Hex + ]: StoredGatorPermissionSanitized[]; }; 'native-token-periodic': { - [chainId: Hex]: StoredGatorPermissionSanitized< - Signer, - NativeTokenPeriodicPermission - >[]; + [ + chainId: Hex + ]: StoredGatorPermissionSanitized[]; }; 'erc20-token-stream': { - [chainId: Hex]: StoredGatorPermissionSanitized< - Signer, - Erc20TokenStreamPermission - >[]; + [ + chainId: Hex + ]: StoredGatorPermissionSanitized[]; }; 'erc20-token-periodic': { - [chainId: Hex]: StoredGatorPermissionSanitized< - Signer, - Erc20TokenPeriodicPermission - >[]; + [ + chainId: Hex + ]: StoredGatorPermissionSanitized[]; }; other: { - [chainId: Hex]: StoredGatorPermissionSanitized[]; + [chainId: Hex]: StoredGatorPermissionSanitized[]; }; }; diff --git a/yarn.lock b/yarn.lock index 5da153fd94f..36a620a1576 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2385,10 +2385,10 @@ __metadata: languageName: node linkType: hard -"@metamask/7715-permission-types@npm:^0.4.0": - version: 0.4.0 - resolution: "@metamask/7715-permission-types@npm:0.4.0" - checksum: 10/70748053e7b9fcd89d044a7602b48168137cc0761f8606ad17fdaafc13ac69271a75230c727a64df49dfedc59a0b3f60bd6fa46c60e06df40691985b9823881d +"@metamask/7715-permission-types@npm:^0.5.0": + version: 0.5.0 + resolution: "@metamask/7715-permission-types@npm:0.5.0" + checksum: 10/f01dcf7ffc3e39536f7cc4d54c088ea659c392de5bdfcaafb9f4d67bbe6b56010358ed2a2ba3adba4e454af51412a2fd5be377cac5c7ab101b032d30711e0b37 languageName: node linkType: hard @@ -3751,7 +3751,7 @@ __metadata: dependencies: "@lavamoat/allow-scripts": "npm:^3.0.4" "@lavamoat/preinstall-always-fail": "npm:^2.1.0" - "@metamask/7715-permission-types": "npm:^0.4.0" + "@metamask/7715-permission-types": "npm:^0.5.0" "@metamask/auto-changelog": "npm:^3.4.4" "@metamask/base-controller": "npm:^9.0.0" "@metamask/delegation-core": "npm:^0.2.0"