Skip to content

Commit

Permalink
Use PERMITTED_CHAINS_ENDOWMENT constant
Browse files Browse the repository at this point in the history
  • Loading branch information
Mrtenz committed Aug 21, 2024
1 parent 031019a commit 832eb69
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
7 changes: 5 additions & 2 deletions packages/snaps-controllers/src/snaps/SnapController.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ import {
sleep,
} from '../test-utils';
import { delay } from '../utils';
import { LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS } from './constants';
import {
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS,
PERMITTED_CHAINS_ENDOWMENT,
} from './constants';
import { SnapsRegistryStatus } from './registry';
import type { SnapControllerState } from './SnapController';
import {
Expand Down Expand Up @@ -4676,7 +4679,7 @@ describe('SnapController', () => {
'endowment:ethereum-provider': {
caveats: [],
},
permittedChains: {},
[PERMITTED_CHAINS_ENDOWMENT]: {},
};

expect(messenger.call).toHaveBeenCalledWith(
Expand Down
11 changes: 5 additions & 6 deletions packages/snaps-controllers/src/snaps/SnapController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ import type {
TerminateAllSnapsAction,
TerminateSnapAction,
} from '../services';
import type { EncryptionResult } from '../types';
import {
import type {
EncryptionResult,
type ExportableKeyEncryptor,
type KeyDerivationOptions,
} from '../types';
Expand All @@ -133,6 +133,7 @@ import {
import {
ALLOWED_PERMISSIONS,
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS,
PERMITTED_CHAINS_ENDOWMENT,
} from './constants';
import type { SnapLocation } from './location';
import { detectSnapLocation } from './location';
Expand Down Expand Up @@ -3652,17 +3653,15 @@ export class SnapController extends BaseController<
// This needs to be assigned to have proper type inference.
const modifiedPermissions: RequestedPermissions = {
...newPermissions,
permittedChains: {
[PERMITTED_CHAINS_ENDOWMENT]: {
caveats: [
{
type: 'restrictNetworkSwitching',
value: [configuration.chainId],
},
],
date: Date.now(),
id: nanoid(),
invoker: snapId,
parentCapability: 'permittedChains',
parentCapability: PERMITTED_CHAINS_ENDOWMENT,
},
};

Expand Down
2 changes: 2 additions & 0 deletions packages/snaps-controllers/src/snaps/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ export const LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS = {
iterations: 10_000,
},
};

export const PERMITTED_CHAINS_ENDOWMENT = 'endowment:permitted-chains';

0 comments on commit 832eb69

Please sign in to comment.