Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/gator-permissions-controller/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Bump `@metamask/utils` from `^11.4.2` to `^11.8.0` ([#6588](https://github.com/MetaMask/core/pull/6588))
- Bump `@metamask/base-controller` from `^8.3.0` to `^8.4.0` ([#6632](https://github.com/MetaMask/core/pull/6632))
- Function `decodePermissionFromPermissionContextForOrigin` is now synchronous ([#6656](https://github.com/MetaMask/core/pull/6656))

## [0.1.0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ describe('GatorPermissionsController', () => {
});
});

it('throws if contracts are not found', async () => {
await expect(
it('throws if contracts are not found', () => {
expect(() =>
controller.decodePermissionFromPermissionContextForOrigin({
origin: controller.permissionsProviderSnapId,
chainId: 999999,
Expand All @@ -501,10 +501,10 @@ describe('GatorPermissionsController', () => {
},
metadata: buildMetadata(''),
}),
).rejects.toThrow('Contracts not found for chainId: 999999');
).toThrow('Contracts not found for chainId: 999999');
});

it('decodes a native-token-stream permission successfully', async () => {
it('decodes a native-token-stream permission successfully', () => {
const {
TimestampEnforcer,
NativeTokenStreamingEnforcer,
Expand Down Expand Up @@ -552,13 +552,12 @@ describe('GatorPermissionsController', () => {
caveats,
};

const result =
await controller.decodePermissionFromPermissionContextForOrigin({
origin: controller.permissionsProviderSnapId,
chainId,
delegation,
metadata: buildMetadata('Test justification'),
});
const result = controller.decodePermissionFromPermissionContextForOrigin({
origin: controller.permissionsProviderSnapId,
chainId,
delegation,
metadata: buildMetadata('Test justification'),
});

expect(result.chainId).toBe(numberToHex(chainId));
expect(result.address).toBe(delegator);
Expand All @@ -581,8 +580,8 @@ describe('GatorPermissionsController', () => {
expect(result.permission.justification).toBe('Test justification');
});

it('throws when origin does not match permissions provider', async () => {
await expect(
it('throws when origin does not match permissions provider', () => {
expect(() =>
controller.decodePermissionFromPermissionContextForOrigin({
origin: 'not-the-provider',
chainId: 1,
Expand All @@ -594,10 +593,10 @@ describe('GatorPermissionsController', () => {
},
metadata: buildMetadata(''),
}),
).rejects.toThrow('Origin not-the-provider not allowed');
).toThrow('Origin not-the-provider not allowed');
});

it('throws when enforcers do not identify a supported permission', async () => {
it('throws when enforcers do not identify a supported permission', () => {
const { TimestampEnforcer, ValueLteEnforcer } = contracts;

const expiryTerms = createTimestampTerms(
Expand All @@ -615,7 +614,7 @@ describe('GatorPermissionsController', () => {
{ enforcer: ValueLteEnforcer, terms: '0x', args: '0x' } as const,
];

await expect(
expect(() =>
controller.decodePermissionFromPermissionContextForOrigin({
origin: controller.permissionsProviderSnapId,
chainId,
Expand All @@ -627,10 +626,10 @@ describe('GatorPermissionsController', () => {
},
metadata: buildMetadata(''),
}),
).rejects.toThrow('Failed to decode permission');
).toThrow('Failed to decode permission');
});

it('throws when authority is not ROOT_AUTHORITY', async () => {
it('throws when authority is not ROOT_AUTHORITY', () => {
const {
TimestampEnforcer,
NativeTokenStreamingEnforcer,
Expand Down Expand Up @@ -674,7 +673,7 @@ describe('GatorPermissionsController', () => {
const invalidAuthority =
'0x0000000000000000000000000000000000000000' as Hex;

await expect(
expect(() =>
controller.decodePermissionFromPermissionContextForOrigin({
origin: controller.permissionsProviderSnapId,
chainId,
Expand All @@ -686,7 +685,7 @@ describe('GatorPermissionsController', () => {
},
metadata: buildMetadata(''),
}),
).rejects.toThrow('Failed to decode permission');
).toThrow('Failed to decode permission');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ export default class GatorPermissionsController extends BaseController<
* @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,
* or the enforcers/terms do not match a supported permission type.
*/
public async decodePermissionFromPermissionContextForOrigin({
public decodePermissionFromPermissionContextForOrigin({
origin,
chainId,
delegation: { caveats, delegator, delegate, authority },
Expand All @@ -554,7 +554,7 @@ export default class GatorPermissionsController extends BaseController<
origin: string;
};
delegation: DelegationDetails;
}): Promise<DecodedPermission> {
}): DecodedPermission {
if (origin !== this.permissionsProviderSnapId) {
throw new OriginNotAllowedError({ origin });
}
Expand Down
1 change: 1 addition & 0 deletions packages/gator-permissions-controller/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export type {
SupportedGatorPermissionType,
GatorPermissionsMapByPermissionType,
GatorPermissionsListByPermissionTypeAndChainId,
DelegationDetails,
} from './types';

export type {
Expand Down
Loading