Skip to content

Commit f5d4553

Browse files
committed
Add feature flag for CAIP-25 permission
1 parent b198fe3 commit f5d4553

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

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

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5330,7 +5330,7 @@ describe('SnapController', () => {
53305330
snapController.destroy();
53315331
});
53325332

5333-
it('grants the `endowment:caip25` permission to a Snap with `endowment:ethereum-provider`', async () => {
5333+
it('grants the `endowment:caip25` permission to a Snap with `endowment:ethereum-provider` if the `useCaip25Permission` feature flag is enabled', async () => {
53345334
const rootMessenger = getControllerMessenger();
53355335
const messenger = getSnapControllerMessenger(rootMessenger);
53365336

@@ -5366,6 +5366,9 @@ describe('SnapController', () => {
53665366
getSnapControllerOptions({
53675367
messenger,
53685368
detectSnapLocation: loopbackDetect({ manifest }),
5369+
featureFlags: {
5370+
useCaip25Permission: true,
5371+
},
53695372
}),
53705373
);
53715374

@@ -5409,6 +5412,71 @@ describe('SnapController', () => {
54095412
snapController.destroy();
54105413
});
54115414

5415+
it('does not grant the `endowment:caip25` permission to a Snap with `endowment:ethereum-provider` if the `useCaip25Permission` feature flag is disabled', async () => {
5416+
const rootMessenger = getControllerMessenger();
5417+
const messenger = getSnapControllerMessenger(rootMessenger);
5418+
5419+
rootMessenger.registerActionHandler(
5420+
'PermissionController:getPermissions',
5421+
() => ({}),
5422+
);
5423+
5424+
rootMessenger.registerActionHandler(
5425+
'SelectedNetworkController:getNetworkClientIdForDomain',
5426+
() => 'mainnet',
5427+
);
5428+
5429+
rootMessenger.registerActionHandler(
5430+
'NetworkController:getNetworkClientById',
5431+
() => ({
5432+
configuration: {
5433+
chainId: '0x1',
5434+
},
5435+
}),
5436+
);
5437+
5438+
const { manifest } = await getMockSnapFilesWithUpdatedChecksum({
5439+
manifest: getSnapManifest({
5440+
initialPermissions: {
5441+
'endowment:page-home': {},
5442+
'endowment:ethereum-provider': {},
5443+
},
5444+
}),
5445+
});
5446+
5447+
const snapController = getSnapController(
5448+
getSnapControllerOptions({
5449+
messenger,
5450+
detectSnapLocation: loopbackDetect({ manifest }),
5451+
featureFlags: {
5452+
useCaip25Permission: false,
5453+
},
5454+
}),
5455+
);
5456+
5457+
await snapController.installSnaps(MOCK_ORIGIN, {
5458+
[MOCK_SNAP_ID]: {},
5459+
});
5460+
5461+
const approvedPermissions = {
5462+
'endowment:page-home': {
5463+
caveats: null,
5464+
},
5465+
'endowment:ethereum-provider': {},
5466+
};
5467+
5468+
expect(messenger.call).toHaveBeenCalledWith(
5469+
'PermissionController:grantPermissions',
5470+
{
5471+
approvedPermissions,
5472+
subject: { origin: MOCK_SNAP_ID },
5473+
requestData: expect.any(Object),
5474+
},
5475+
);
5476+
5477+
snapController.destroy();
5478+
});
5479+
54125480
it('does not grant the `endowment:caip25` permission if the Snap does not have the `endowment:ethereum-provider` permission', async () => {
54135481
const rootMessenger = getControllerMessenger();
54145482
const messenger = getSnapControllerMessenger(rootMessenger);
@@ -5444,6 +5512,9 @@ describe('SnapController', () => {
54445512
getSnapControllerOptions({
54455513
messenger,
54465514
detectSnapLocation: loopbackDetect({ manifest }),
5515+
featureFlags: {
5516+
useCaip25Permission: true,
5517+
},
54475518
}),
54485519
);
54495520

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,7 @@ type FeatureFlags = {
675675
allowLocalSnaps?: boolean;
676676
disableSnapInstallation?: boolean;
677677
rejectInvalidPlatformVersion?: boolean;
678+
useCaip25Permission?: boolean;
678679
};
679680

680681
type DynamicFeatureFlags = {
@@ -4086,7 +4087,10 @@ export class SnapController extends BaseController<
40864087
* @returns The permissions to grant to the Snap.
40874088
*/
40884089
#getPermissionsToGrant(snapId: SnapId, newPermissions: RequestedPermissions) {
4089-
if (Object.keys(newPermissions).includes(SnapEndowments.EthereumProvider)) {
4090+
if (
4091+
this.#featureFlags.useCaip25Permission &&
4092+
Object.keys(newPermissions).includes(SnapEndowments.EthereumProvider)
4093+
) {
40904094
// This will return the globally selected network if the Snap doesn't have
40914095
// one set.
40924096
const networkClientId = this.messagingSystem.call(

0 commit comments

Comments
 (0)