Skip to content

Commit 49948b2

Browse files
authored
fix: Remove logic for granting CAIP-25 permissions (#3723)
This logic may not be needed. Pending verification. <!-- CURSOR_SUMMARY --> --- > [!NOTE] > Removes automatic granting of `endowment:caip25` and related network lookups, updates default dynamic permission to `endowment:caip25`, and adjusts tests accordingly. > > - **Core (`SnapController.ts`)**: > - Remove logic that auto-added `endowment:caip25` based on `endowment:ethereum-provider` (and associated network client lookups); permissions are now granted as requested without modification. > - Drop `NetworkController:getNetworkClientById` and `SelectedNetworkController:getNetworkClientIdForDomain` from allowed actions; remove `hex`/`hexToNumber` usage. > - Change default `dynamicPermissions` from `eth_accounts` to `endowment:caip25`. > - **Tests (`SnapController.test.tsx`)**: > - Delete tests asserting auto-grant of `endowment:caip25` on install/update; keep install/update flows without CAIP-25 injection. > - Update dynamic permissions revocation test to use `endowment:caip25` instead of `eth_accounts`. > > <sup>Written by [Cursor Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit 9800313. This will update automatically on new commits. Configure [here](https://cursor.com/dashboard?tab=bugbot).</sup> <!-- /CURSOR_SUMMARY -->
1 parent 213c19a commit 49948b2

File tree

2 files changed

+5
-349
lines changed

2 files changed

+5
-349
lines changed

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

Lines changed: 2 additions & 271 deletions
Original file line numberDiff line numberDiff line change
@@ -6011,275 +6011,6 @@ describe('SnapController', () => {
60116011
snapController.destroy();
60126012
});
60136013

6014-
it('grants the `endowment:caip25` permission to a Snap with `endowment:ethereum-provider`', async () => {
6015-
const rootMessenger = getControllerMessenger();
6016-
const messenger = getSnapControllerMessenger(rootMessenger);
6017-
6018-
rootMessenger.registerActionHandler(
6019-
'PermissionController:getPermissions',
6020-
() => ({}),
6021-
);
6022-
6023-
rootMessenger.registerActionHandler(
6024-
'SelectedNetworkController:getNetworkClientIdForDomain',
6025-
() => 'mainnet',
6026-
);
6027-
6028-
rootMessenger.registerActionHandler(
6029-
'NetworkController:getNetworkClientById',
6030-
() => ({
6031-
configuration: {
6032-
chainId: '0x1',
6033-
},
6034-
}),
6035-
);
6036-
6037-
const { manifest } = await getMockSnapFilesWithUpdatedChecksum({
6038-
manifest: getSnapManifest({
6039-
initialPermissions: {
6040-
'endowment:page-home': {},
6041-
'endowment:ethereum-provider': {},
6042-
},
6043-
}),
6044-
});
6045-
6046-
const snapController = getSnapController(
6047-
getSnapControllerOptions({
6048-
messenger,
6049-
detectSnapLocation: loopbackDetect({ manifest }),
6050-
}),
6051-
);
6052-
6053-
await snapController.installSnaps(MOCK_ORIGIN, {
6054-
[MOCK_SNAP_ID]: {},
6055-
});
6056-
6057-
const approvedPermissions = {
6058-
'endowment:page-home': {
6059-
caveats: null,
6060-
},
6061-
'endowment:ethereum-provider': {},
6062-
'endowment:caip25': {
6063-
caveats: [
6064-
{
6065-
type: 'authorizedScopes',
6066-
value: {
6067-
requiredScopes: {},
6068-
optionalScopes: {
6069-
'eip155:1': {
6070-
accounts: [],
6071-
},
6072-
},
6073-
sessionProperties: {},
6074-
isMultichainOrigin: false,
6075-
},
6076-
},
6077-
],
6078-
},
6079-
};
6080-
6081-
expect(messenger.call).toHaveBeenCalledWith(
6082-
'PermissionController:grantPermissions',
6083-
{
6084-
approvedPermissions,
6085-
subject: { origin: MOCK_SNAP_ID },
6086-
requestData: expect.any(Object),
6087-
},
6088-
);
6089-
6090-
snapController.destroy();
6091-
});
6092-
6093-
it('grants the `endowment:caip25` permission when updating a Snap with `endowment:ethereum-provider`', async () => {
6094-
const newVersion = '1.0.2';
6095-
const newVersionRange = '>=1.0.1';
6096-
6097-
const rootMessenger = getControllerMessenger();
6098-
const messenger = getSnapControllerMessenger(rootMessenger);
6099-
6100-
rootMessenger.registerActionHandler(
6101-
'SelectedNetworkController:getNetworkClientIdForDomain',
6102-
() => 'mainnet',
6103-
);
6104-
6105-
rootMessenger.registerActionHandler(
6106-
'NetworkController:getNetworkClientById',
6107-
() => ({
6108-
configuration: {
6109-
chainId: '0x1',
6110-
},
6111-
}),
6112-
);
6113-
6114-
const { manifest: originalManifest } =
6115-
await getMockSnapFilesWithUpdatedChecksum({
6116-
manifest: getSnapManifest({
6117-
initialPermissions: {
6118-
'endowment:page-home': {},
6119-
},
6120-
}),
6121-
});
6122-
6123-
const { manifest: updatedManifest } =
6124-
await getMockSnapFilesWithUpdatedChecksum({
6125-
manifest: getSnapManifest({
6126-
version: newVersion,
6127-
initialPermissions: {
6128-
'endowment:page-home': {},
6129-
'endowment:ethereum-provider': {},
6130-
},
6131-
}),
6132-
});
6133-
6134-
const detectLocationMock = jest
6135-
.fn()
6136-
.mockImplementationOnce(
6137-
() =>
6138-
new LoopbackLocation({
6139-
manifest: originalManifest,
6140-
}),
6141-
)
6142-
.mockImplementationOnce(
6143-
() =>
6144-
new LoopbackLocation({
6145-
manifest: updatedManifest,
6146-
}),
6147-
);
6148-
6149-
const controller = getSnapController(
6150-
getSnapControllerOptions({
6151-
messenger,
6152-
detectSnapLocation: detectLocationMock,
6153-
}),
6154-
);
6155-
6156-
await controller.installSnaps(MOCK_ORIGIN, { [MOCK_SNAP_ID]: {} });
6157-
await controller.stopSnap(MOCK_SNAP_ID);
6158-
6159-
const approvedPermissions = {
6160-
'endowment:page-home': {
6161-
caveats: null,
6162-
},
6163-
};
6164-
6165-
expect(messenger.call).toHaveBeenCalledWith(
6166-
'PermissionController:grantPermissions',
6167-
{
6168-
approvedPermissions,
6169-
subject: { origin: MOCK_SNAP_ID },
6170-
requestData: expect.any(Object),
6171-
},
6172-
);
6173-
6174-
jest.mocked(messenger.call).mockClear();
6175-
6176-
const result = await controller.installSnaps(MOCK_ORIGIN, {
6177-
[MOCK_SNAP_ID]: { version: newVersionRange },
6178-
});
6179-
6180-
const updatedApprovedPermissions = {
6181-
'endowment:page-home': {
6182-
caveats: null,
6183-
},
6184-
'endowment:ethereum-provider': {},
6185-
'endowment:caip25': {
6186-
caveats: [
6187-
{
6188-
type: 'authorizedScopes',
6189-
value: {
6190-
requiredScopes: {},
6191-
optionalScopes: {
6192-
'eip155:1': {
6193-
accounts: [],
6194-
},
6195-
},
6196-
sessionProperties: {},
6197-
isMultichainOrigin: false,
6198-
},
6199-
},
6200-
],
6201-
},
6202-
};
6203-
6204-
expect(messenger.call).toHaveBeenCalledWith(
6205-
'PermissionController:grantPermissions',
6206-
{
6207-
approvedPermissions: updatedApprovedPermissions,
6208-
subject: { origin: MOCK_SNAP_ID },
6209-
requestData: expect.any(Object),
6210-
},
6211-
);
6212-
6213-
expect(result).toStrictEqual({
6214-
[MOCK_SNAP_ID]: getTruncatedSnap({
6215-
version: newVersion,
6216-
initialPermissions: updatedManifest.result.initialPermissions,
6217-
}),
6218-
});
6219-
6220-
controller.destroy();
6221-
});
6222-
6223-
it('does not grant the `endowment:caip25` permission if the Snap does not have the `endowment:ethereum-provider` permission', async () => {
6224-
const rootMessenger = getControllerMessenger();
6225-
const messenger = getSnapControllerMessenger(rootMessenger);
6226-
6227-
rootMessenger.registerActionHandler(
6228-
'PermissionController:getPermissions',
6229-
() => ({}),
6230-
);
6231-
6232-
rootMessenger.registerActionHandler(
6233-
'SelectedNetworkController:getNetworkClientIdForDomain',
6234-
() => {
6235-
throw new Error('This should not be called.');
6236-
},
6237-
);
6238-
6239-
rootMessenger.registerActionHandler(
6240-
'NetworkController:getNetworkClientById',
6241-
() => {
6242-
throw new Error('This should not be called.');
6243-
},
6244-
);
6245-
6246-
const { manifest } = await getMockSnapFilesWithUpdatedChecksum({
6247-
manifest: getSnapManifest({
6248-
initialPermissions: {
6249-
'endowment:page-home': {},
6250-
},
6251-
}),
6252-
});
6253-
6254-
const snapController = getSnapController(
6255-
getSnapControllerOptions({
6256-
messenger,
6257-
detectSnapLocation: loopbackDetect({ manifest }),
6258-
}),
6259-
);
6260-
6261-
await snapController.installSnaps(MOCK_ORIGIN, {
6262-
[MOCK_SNAP_ID]: {},
6263-
});
6264-
6265-
const approvedPermissions = {
6266-
'endowment:page-home': {
6267-
caveats: null,
6268-
},
6269-
};
6270-
6271-
expect(messenger.call).toHaveBeenCalledWith(
6272-
'PermissionController:grantPermissions',
6273-
{
6274-
approvedPermissions,
6275-
subject: { origin: MOCK_SNAP_ID },
6276-
requestData: expect.any(Object),
6277-
},
6278-
);
6279-
6280-
snapController.destroy();
6281-
});
6282-
62836014
it('supports preinstalled snaps', async () => {
62846015
const rootMessenger = getControllerMessenger();
62856016
jest.spyOn(rootMessenger, 'call');
@@ -11804,12 +11535,12 @@ describe('SnapController', () => {
1180411535
const callActionSpy = jest.spyOn(messenger, 'call');
1180511536

1180611537
messenger.call('SnapController:revokeDynamicPermissions', MOCK_SNAP_ID, [
11807-
'eth_accounts',
11538+
'endowment:caip25',
1180811539
]);
1180911540

1181011541
expect(callActionSpy).toHaveBeenCalledWith(
1181111542
'PermissionController:revokePermissions',
11812-
{ [MOCK_SNAP_ID]: ['eth_accounts'] },
11543+
{ [MOCK_SNAP_ID]: ['endowment:caip25'] },
1181311544
);
1181411545

1181511546
snapController.destroy();

0 commit comments

Comments
 (0)