Skip to content

Commit 26dbd80

Browse files
committed
Use PERMITTED_CHAINS_ENDOWMENT constant
1 parent 9473208 commit 26dbd80

File tree

4 files changed

+31
-13
lines changed

4 files changed

+31
-13
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"branches": 92.96,
2+
"branches": 92.97,
33
"functions": 96.56,
4-
"lines": 98.05,
5-
"statements": 97.77
4+
"lines": 98.06,
5+
"statements": 97.78
66
}

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

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,10 @@ import {
103103
waitForStateChange,
104104
} from '../test-utils';
105105
import { delay } from '../utils';
106-
import { LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS } from './constants';
106+
import {
107+
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS,
108+
PERMITTED_CHAINS_ENDOWMENT,
109+
} from './constants';
107110
import { SnapsRegistryStatus } from './registry';
108111
import type { SnapControllerState } from './SnapController';
109112
import {
@@ -4922,15 +4925,27 @@ describe('SnapController', () => {
49224925
});
49234926

49244927
const approvedPermissions = {
4925-
'endowment:ethereum-provider': {
4926-
caveats: [],
4928+
'endowment:page-home': {
4929+
caveats: null,
4930+
},
4931+
'endowment:ethereum-provider': {},
4932+
[PERMITTED_CHAINS_ENDOWMENT]: {
4933+
caveats: [
4934+
{
4935+
type: 'restrictNetworkSwitching',
4936+
value: ['0x1'],
4937+
},
4938+
],
49274939
},
4928-
permittedChains: {},
49294940
};
49304941

49314942
expect(messenger.call).toHaveBeenCalledWith(
49324943
'PermissionController:grantPermissions',
4933-
{ approvedPermissions, subject: { origin: MOCK_SNAP_ID } },
4944+
{
4945+
approvedPermissions,
4946+
subject: { origin: MOCK_SNAP_ID },
4947+
requestData: expect.any(Object),
4948+
},
49344949
);
49354950

49364951
snapController.destroy();

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ import type {
127127
TerminateAllSnapsAction,
128128
TerminateSnapAction,
129129
} from '../services';
130-
import type { EncryptionResult } from '../types';
131-
import {
132-
type ExportableKeyEncryptor,
133-
type KeyDerivationOptions,
130+
import type {
131+
EncryptionResult,
132+
ExportableKeyEncryptor,
133+
KeyDerivationOptions,
134134
} from '../types';
135135
import {
136136
fetchSnap,
@@ -142,6 +142,7 @@ import {
142142
import {
143143
ALLOWED_PERMISSIONS,
144144
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS,
145+
PERMITTED_CHAINS_ENDOWMENT,
145146
} from './constants';
146147
import type { SnapLocation } from './location';
147148
import { detectSnapLocation } from './location';
@@ -3948,7 +3949,7 @@ export class SnapController extends BaseController<
39483949
// This needs to be assigned to have proper type inference.
39493950
const modifiedPermissions: RequestedPermissions = {
39503951
...newPermissions,
3951-
permittedChains: {
3952+
[PERMITTED_CHAINS_ENDOWMENT]: {
39523953
caveats: [
39533954
{
39543955
type: 'restrictNetworkSwitching',

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)