Skip to content

Commit e53f4e2

Browse files
committed
method 'decodePermissionFromPermissionContextForOrigin' is now synchronous
1 parent 567e202 commit e53f4e2

File tree

4 files changed

+23
-22
lines changed

4 files changed

+23
-22
lines changed

packages/gator-permissions-controller/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616

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

2021
## [0.1.0]
2122

packages/gator-permissions-controller/src/GatorPermissionsController.test.ts

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,8 @@ describe('GatorPermissionsController', () => {
488488
});
489489
});
490490

491-
it('throws if contracts are not found', async () => {
492-
await expect(
491+
it('throws if contracts are not found', () => {
492+
expect(() =>
493493
controller.decodePermissionFromPermissionContextForOrigin({
494494
origin: controller.permissionsProviderSnapId,
495495
chainId: 999999,
@@ -501,10 +501,10 @@ describe('GatorPermissionsController', () => {
501501
},
502502
metadata: buildMetadata(''),
503503
}),
504-
).rejects.toThrow('Contracts not found for chainId: 999999');
504+
).toThrow('Contracts not found for chainId: 999999');
505505
});
506506

507-
it('decodes a native-token-stream permission successfully', async () => {
507+
it('decodes a native-token-stream permission successfully', () => {
508508
const {
509509
TimestampEnforcer,
510510
NativeTokenStreamingEnforcer,
@@ -552,13 +552,12 @@ describe('GatorPermissionsController', () => {
552552
caveats,
553553
};
554554

555-
const result =
556-
await controller.decodePermissionFromPermissionContextForOrigin({
557-
origin: controller.permissionsProviderSnapId,
558-
chainId,
559-
delegation,
560-
metadata: buildMetadata('Test justification'),
561-
});
555+
const result = controller.decodePermissionFromPermissionContextForOrigin({
556+
origin: controller.permissionsProviderSnapId,
557+
chainId,
558+
delegation,
559+
metadata: buildMetadata('Test justification'),
560+
});
562561

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

584-
it('throws when origin does not match permissions provider', async () => {
585-
await expect(
583+
it('throws when origin does not match permissions provider', () => {
584+
expect(() =>
586585
controller.decodePermissionFromPermissionContextForOrigin({
587586
origin: 'not-the-provider',
588587
chainId: 1,
@@ -594,10 +593,10 @@ describe('GatorPermissionsController', () => {
594593
},
595594
metadata: buildMetadata(''),
596595
}),
597-
).rejects.toThrow('Origin not-the-provider not allowed');
596+
).toThrow('Origin not-the-provider not allowed');
598597
});
599598

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

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

618-
await expect(
617+
expect(() =>
619618
controller.decodePermissionFromPermissionContextForOrigin({
620619
origin: controller.permissionsProviderSnapId,
621620
chainId,
@@ -627,10 +626,10 @@ describe('GatorPermissionsController', () => {
627626
},
628627
metadata: buildMetadata(''),
629628
}),
630-
).rejects.toThrow('Failed to decode permission');
629+
).toThrow('Failed to decode permission');
631630
});
632631

633-
it('throws when authority is not ROOT_AUTHORITY', async () => {
632+
it('throws when authority is not ROOT_AUTHORITY', () => {
634633
const {
635634
TimestampEnforcer,
636635
NativeTokenStreamingEnforcer,
@@ -674,7 +673,7 @@ describe('GatorPermissionsController', () => {
674673
const invalidAuthority =
675674
'0x0000000000000000000000000000000000000000' as Hex;
676675

677-
await expect(
676+
expect(() =>
678677
controller.decodePermissionFromPermissionContextForOrigin({
679678
origin: controller.permissionsProviderSnapId,
680679
chainId,
@@ -686,7 +685,7 @@ describe('GatorPermissionsController', () => {
686685
},
687686
metadata: buildMetadata(''),
688687
}),
689-
).rejects.toThrow('Failed to decode permission');
688+
).toThrow('Failed to decode permission');
690689
});
691690
});
692691
});

packages/gator-permissions-controller/src/GatorPermissionsController.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ export default class GatorPermissionsController extends BaseController<
541541
* @throws If the origin is not allowed, the context cannot be decoded into exactly one delegation,
542542
* or the enforcers/terms do not match a supported permission type.
543543
*/
544-
public async decodePermissionFromPermissionContextForOrigin({
544+
public decodePermissionFromPermissionContextForOrigin({
545545
origin,
546546
chainId,
547547
delegation: { caveats, delegator, delegate, authority },
@@ -554,7 +554,7 @@ export default class GatorPermissionsController extends BaseController<
554554
origin: string;
555555
};
556556
delegation: DelegationDetails;
557-
}): Promise<DecodedPermission> {
557+
}): DecodedPermission {
558558
if (origin !== this.permissionsProviderSnapId) {
559559
throw new OriginNotAllowedError({ origin });
560560
}

packages/gator-permissions-controller/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export type {
3030
SupportedGatorPermissionType,
3131
GatorPermissionsMapByPermissionType,
3232
GatorPermissionsListByPermissionTypeAndChainId,
33+
DelegationDetails,
3334
} from './types';
3435

3536
export type {

0 commit comments

Comments
 (0)