Skip to content

Commit f6effc6

Browse files
committed
Use PERMITTED_CHAINS_ENDOWMENT constant
1 parent 065c003 commit f6effc6

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

packages/snaps-controllers/src/snaps/SnapController.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ import {
9696
sleep,
9797
} from '../test-utils';
9898
import { delay } from '../utils';
99-
import { LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS } from './constants';
99+
import {
100+
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS,
101+
PERMITTED_CHAINS_ENDOWMENT,
102+
} from './constants';
100103
import { SnapsRegistryStatus } from './registry';
101104
import type { SnapControllerState } from './SnapController';
102105
import {
@@ -4676,7 +4679,7 @@ describe('SnapController', () => {
46764679
'endowment:ethereum-provider': {
46774680
caveats: [],
46784681
},
4679-
permittedChains: {},
4682+
[PERMITTED_CHAINS_ENDOWMENT]: {},
46804683
};
46814684

46824685
expect(messenger.call).toHaveBeenCalledWith(

packages/snaps-controllers/src/snaps/SnapController.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ import type {
118118
TerminateAllSnapsAction,
119119
TerminateSnapAction,
120120
} from '../services';
121-
import type { EncryptionResult } from '../types';
122-
import {
121+
import type {
122+
EncryptionResult,
123123
type ExportableKeyEncryptor,
124124
type KeyDerivationOptions,
125125
} from '../types';
@@ -133,6 +133,7 @@ import {
133133
import {
134134
ALLOWED_PERMISSIONS,
135135
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS,
136+
PERMITTED_CHAINS_ENDOWMENT,
136137
} from './constants';
137138
import type { SnapLocation } from './location';
138139
import { detectSnapLocation } from './location';
@@ -3652,17 +3653,15 @@ export class SnapController extends BaseController<
36523653
// This needs to be assigned to have proper type inference.
36533654
const modifiedPermissions: RequestedPermissions = {
36543655
...newPermissions,
3655-
permittedChains: {
3656+
[PERMITTED_CHAINS_ENDOWMENT]: {
36563657
caveats: [
36573658
{
36583659
type: 'restrictNetworkSwitching',
36593660
value: [configuration.chainId],
36603661
},
36613662
],
3662-
date: Date.now(),
3663-
id: nanoid(),
36643663
invoker: snapId,
3665-
parentCapability: 'permittedChains',
3664+
parentCapability: PERMITTED_CHAINS_ENDOWMENT,
36663665
},
36673666
};
36683667

packages/snaps-controllers/src/snaps/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,5 @@ export const LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS = {
2020
iterations: 10_000,
2121
},
2222
};
23+
24+
export const PERMITTED_CHAINS_ENDOWMENT = 'endowment:permitted-chains';

0 commit comments

Comments
 (0)