diff --git a/packages/examples/packages/bip32/snap.manifest.json b/packages/examples/packages/bip32/snap.manifest.json index 96d01b54d3..923f18212a 100644 --- a/packages/examples/packages/bip32/snap.manifest.json +++ b/packages/examples/packages/bip32/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "FzEv7I4+3tYNzM6dcEEaoq3J3aH6l8WCo0bFp56hI3k=", + "shasum": "HAHCQmLzkvjg9lLzhgPOAXVe3GOchNyVG+3cjvU/FMY=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/bip44/snap.manifest.json b/packages/examples/packages/bip44/snap.manifest.json index fe7118dcd3..9b7b0be63a 100644 --- a/packages/examples/packages/bip44/snap.manifest.json +++ b/packages/examples/packages/bip44/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "jX8PaE9Oi1FWnJsW2Dm71crLo2uBEksCNeYPphmoy0Y=", + "shasum": "VBQyAPYvdb49ZFCT/gDmU0z8lzdCJjze/KJh3/ld6II=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/dialogs/snap.manifest.json b/packages/examples/packages/dialogs/snap.manifest.json index 5292da7c94..87c295d212 100644 --- a/packages/examples/packages/dialogs/snap.manifest.json +++ b/packages/examples/packages/dialogs/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "7ryoRHayMjd7Ws8C+806kGR3OMNQFryMvIXPp6cDRw8=", + "shasum": "2RI07sl8l49Ki8s4i3XNx7wXsKhvTZfpALKXtQVFieA=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/get-entropy/snap.manifest.json b/packages/examples/packages/get-entropy/snap.manifest.json index be590d56e7..57b5536121 100644 --- a/packages/examples/packages/get-entropy/snap.manifest.json +++ b/packages/examples/packages/get-entropy/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "txKgxLDTD0dBYL6WQgZxUqwHTcQcUUNNPU9/oWVK4Kg=", + "shasum": "L7jHmu5vrvLi2WW0x4rYeJlSQnqJ2Dc/3dTGdDhO2i4=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/get-locale/snap.manifest.json b/packages/examples/packages/get-locale/snap.manifest.json index cf1f5a75a2..03a568b8b2 100644 --- a/packages/examples/packages/get-locale/snap.manifest.json +++ b/packages/examples/packages/get-locale/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "0T4dTLDl+8OxbagVuXQ+hgE81KlmdxpZYWSShfw6+Hc=", + "shasum": "hGaWjH5AubB4sONlhAtfiSMKZSborqZ8laT3rFuA/zg=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/invoke-snap/packages/core-signer/snap.manifest.json b/packages/examples/packages/invoke-snap/packages/core-signer/snap.manifest.json index b618cde5fe..7b72e5a5c7 100644 --- a/packages/examples/packages/invoke-snap/packages/core-signer/snap.manifest.json +++ b/packages/examples/packages/invoke-snap/packages/core-signer/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "AVvItsFeFROPIhuZLuxiNc6egWLhbhJQR9//daxg8qQ=", + "shasum": "JvQh3zMf6/uJdeYucljWuRS4SsUgXfdKmIxySdlKWAI=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/manage-state/snap.manifest.json b/packages/examples/packages/manage-state/snap.manifest.json index 0d1acce4e7..b51f85c108 100644 --- a/packages/examples/packages/manage-state/snap.manifest.json +++ b/packages/examples/packages/manage-state/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "Gw+1DNkjLVuQfJbrVA2sG+lIgek5oEuk0jRdsd44Ky8=", + "shasum": "US68Oxl3a45bRvmfmnasLSom/jigytwIcfacFh89H58=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/examples/packages/notifications/snap.manifest.json b/packages/examples/packages/notifications/snap.manifest.json index 234e158a14..727b0ccbca 100644 --- a/packages/examples/packages/notifications/snap.manifest.json +++ b/packages/examples/packages/notifications/snap.manifest.json @@ -7,7 +7,7 @@ "url": "https://github.com/MetaMask/snaps.git" }, "source": { - "shasum": "cZdsqMkePYvSOaFyIkpn3WchgN4Dk/tDvVEHRyjdHeQ=", + "shasum": "P75BXdlAjBJTJVzhpFivnuVYw7X4IWSNb55zIbIWbM0=", "location": { "npm": { "filePath": "dist/bundle.js", diff --git a/packages/snaps-controllers/coverage.json b/packages/snaps-controllers/coverage.json index 3f12c69068..da3df43732 100644 --- a/packages/snaps-controllers/coverage.json +++ b/packages/snaps-controllers/coverage.json @@ -1,6 +1,6 @@ { - "branches": 89, - "functions": 95.13, - "lines": 96.77, - "statements": 96.44 + "branches": 88.97, + "functions": 95.8, + "lines": 96.88, + "statements": 96.54 } diff --git a/packages/snaps-controllers/src/snaps/SnapController.test.ts b/packages/snaps-controllers/src/snaps/SnapController.test.ts index 971a81f106..4e67292343 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.test.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.test.ts @@ -211,7 +211,7 @@ describe('SnapController', () => { await snapController.startSnap(snap.id); - expect(messenger.call).toHaveBeenCalledTimes(4); + expect(messenger.call).toHaveBeenCalledTimes(3); expect(messenger.call).toHaveBeenNthCalledWith( 1, 'PermissionController:hasPermission', @@ -235,13 +235,6 @@ describe('SnapController', () => { endowments: [...DEFAULT_ENDOWMENTS, 'fooEndowment'], }, ); - - expect(messenger.call).toHaveBeenNthCalledWith( - 4, - 'PermissionController:hasPermission', - MOCK_SNAP_ID, - SnapEndowments.LongRunning, - ); snapController.destroy(); }); @@ -261,7 +254,7 @@ describe('SnapController', () => { `Snap "${MOCK_SNAP_ID}" is already started.`, ); - expect(messenger.call).toHaveBeenCalledTimes(2); + expect(messenger.call).toHaveBeenCalledTimes(1); expect(messenger.call).toHaveBeenNthCalledWith( 1, 'ExecutionService:executeSnap', @@ -272,13 +265,6 @@ describe('SnapController', () => { }, ); - expect(messenger.call).toHaveBeenNthCalledWith( - 2, - 'PermissionController:hasPermission', - MOCK_SNAP_ID, - SnapEndowments.LongRunning, - ); - snapController.destroy(); }); @@ -590,7 +576,7 @@ describe('SnapController', () => { [MOCK_SNAP_ID]: expectedSnapObject, }); - expect(messenger.call).toHaveBeenCalledTimes(12); + expect(messenger.call).toHaveBeenCalledTimes(10); expect(messenger.call).toHaveBeenNthCalledWith( 1, @@ -660,13 +646,6 @@ describe('SnapController', () => { expect(messenger.call).toHaveBeenNthCalledWith( 7, - 'PermissionController:hasPermission', - MOCK_SNAP_ID, - SnapEndowments.LongRunning, - ); - - expect(messenger.call).toHaveBeenNthCalledWith( - 8, 'ApprovalController:updateRequestState', { id: expect.any(String), @@ -1220,64 +1199,6 @@ describe('SnapController', () => { await service.terminateAllSnaps(); }); - it('does not time out snaps that are permitted to be long-running', async () => { - const rootMessenger = getControllerMessenger(); - const options = getSnapControllerWithEESOptions({ - rootMessenger, - idleTimeCheckInterval: 30000, - maxIdleTime: 160000, - // Note that we are using the default maxRequestTime - state: { - snaps: getPersistedSnapsState(), - }, - }); - - rootMessenger.registerActionHandler( - 'ExecutionService:handleRpcRequest', - async () => await sleep(100), - ); - - rootMessenger.registerActionHandler( - 'PermissionController:hasPermission', - () => true, - ); - - const [snapController, service] = getSnapControllerWithEES(options); - - const snap = snapController.getExpect(MOCK_SNAP_ID); - - await snapController.startSnap(snap.id); - expect(snapController.state.snaps[snap.id].status).toBe('running'); - - // We set the maxRequestTime to a low enough value for it to time out if it - // weren't a long-running snap. - // @ts-expect-error - `maxRequestTime` is a private property. - snapController.maxRequestTime = 50; - - const handlerPromise = snapController.handleRequest({ - snapId: snap.id, - origin: 'foo.com', - handler: HandlerType.OnRpcRequest, - request: { - jsonrpc: '2.0', - method: 'test', - params: {}, - id: 1, - }, - }); - - const timeoutPromise = sleep(200); - - expect( - // Race the promises to check that handlerPromise does not time out - await Promise.race([handlerPromise, timeoutPromise]), - ).toBe('test1'); - expect(snapController.state.snaps[snap.id].status).toBe('running'); - - snapController.destroy(); - await service.terminateAllSnaps(); - }); - it('times out on stuck starting snap', async () => { const rootMessenger = getControllerMessenger(); const messenger = getSnapControllerMessenger(rootMessenger); @@ -1622,7 +1543,7 @@ describe('SnapController', () => { }, }); - expect(rootMessenger.call).toHaveBeenCalledTimes(7); + expect(rootMessenger.call).toHaveBeenCalledTimes(5); expect(rootMessenger.call).toHaveBeenCalledWith( 'ExecutionService:handleRpcRequest', MOCK_SNAP_ID, @@ -1869,7 +1790,7 @@ describe('SnapController', () => { expect(result).toStrictEqual({ [MOCK_LOCAL_SNAP_ID]: truncatedSnap }); - expect(messenger.call).toHaveBeenCalledTimes(14); + expect(messenger.call).toHaveBeenCalledTimes(12); expect(messenger.call).toHaveBeenNthCalledWith( 1, @@ -1948,13 +1869,6 @@ describe('SnapController', () => { expect(messenger.call).toHaveBeenNthCalledWith( 9, - 'PermissionController:hasPermission', - MOCK_LOCAL_SNAP_ID, - SnapEndowments.LongRunning, - ); - - expect(messenger.call).toHaveBeenNthCalledWith( - 10, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -2024,7 +1938,7 @@ describe('SnapController', () => { [MOCK_LOCAL_SNAP_ID]: truncatedSnap, }); - expect(messenger.call).toHaveBeenCalledTimes(27); + expect(messenger.call).toHaveBeenCalledTimes(23); expect(messenger.call).toHaveBeenNthCalledWith( 1, @@ -2104,13 +2018,6 @@ describe('SnapController', () => { expect(messenger.call).toHaveBeenNthCalledWith( 7, - 'PermissionController:hasPermission', - MOCK_LOCAL_SNAP_ID, - SnapEndowments.LongRunning, - ); - - expect(messenger.call).toHaveBeenNthCalledWith( - 8, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -2122,7 +2029,7 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 13, + 11, 'ApprovalController:addRequest', expect.objectContaining({ type: SNAP_APPROVAL_INSTALL, @@ -2142,13 +2049,13 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 14, + 12, 'ExecutionService:terminateSnap', MOCK_LOCAL_SNAP_ID, ); expect(messenger.call).toHaveBeenNthCalledWith( - 18, + 16, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -2160,7 +2067,7 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 19, + 17, 'PermissionController:grantPermissions', { approvedPermissions: permissions, @@ -2177,7 +2084,7 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 20, + 18, 'ApprovalController:addRequest', expect.objectContaining({ id: expect.any(String), @@ -2198,20 +2105,13 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 21, + 19, 'ExecutionService:executeSnap', expect.objectContaining({ snapId: MOCK_LOCAL_SNAP_ID }), ); expect(messenger.call).toHaveBeenNthCalledWith( - 22, - 'PermissionController:hasPermission', - MOCK_LOCAL_SNAP_ID, - SnapEndowments.LongRunning, - ); - - expect(messenger.call).toHaveBeenNthCalledWith( - 23, + 20, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -2371,7 +2271,7 @@ describe('SnapController', () => { expect(result).toStrictEqual({ [MOCK_SNAP_ID]: truncatedSnap, }); - expect(messenger.call).toHaveBeenCalledTimes(12); + expect(messenger.call).toHaveBeenCalledTimes(10); expect(messenger.call).toHaveBeenNthCalledWith( 1, @@ -2448,13 +2348,6 @@ describe('SnapController', () => { expect(messenger.call).toHaveBeenNthCalledWith( 7, - 'PermissionController:hasPermission', - MOCK_SNAP_ID, - SnapEndowments.LongRunning, - ); - - expect(messenger.call).toHaveBeenNthCalledWith( - 8, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -2472,7 +2365,7 @@ describe('SnapController', () => { const initialPermissions = { [handlerEndowments.onRpcRequest]: { snaps: false, dapps: true }, // eslint-disable-next-line @typescript-eslint/naming-convention - 'endowment:long-running': {}, + 'endowment:webassembly': {}, }; const { manifest } = getSnapFiles({ @@ -2489,7 +2382,7 @@ describe('SnapController', () => { manifest: manifest.result, }), // eslint-disable-next-line @typescript-eslint/naming-convention - excludedPermissions: { 'endowment:long-running': 'foobar' }, + excludedPermissions: { 'endowment:webassembly': 'foobar' }, }), ); @@ -2535,42 +2428,6 @@ describe('SnapController', () => { controller.destroy(); }); - it('displays a warning if endowment:long-running is used', async () => { - const consoleWarnSpy = jest.spyOn(console, 'warn').mockImplementation(); - - const rootMessenger = getControllerMessenger(); - const messenger = getSnapControllerMessenger(rootMessenger); - const snapController = getSnapController( - getSnapControllerOptions({ - messenger, - maxRequestTime: 50, - state: { - snaps: getPersistedSnapsState(), - }, - }), - ); - - rootMessenger.registerActionHandler( - 'PermissionController:hasPermission', - () => true, - ); - - rootMessenger.registerActionHandler( - 'ExecutionService:executeSnap', - async () => await sleep(300), - ); - - const snap = snapController.getExpect(MOCK_SNAP_ID); - - await snapController.startSnap(snap.id); - - snapController.destroy(); - - expect(consoleWarnSpy).toHaveBeenCalledWith( - 'endowment:long-running will soon be deprecated. For more information please see https://github.com/MetaMask/snaps-monorepo/issues/945.', - ); - }); - it('maps permission caveats to the proper format', async () => { const initialPermissions = { // eslint-disable-next-line @typescript-eslint/naming-convention @@ -2926,10 +2783,10 @@ describe('SnapController', () => { [MOCK_SNAP_ID]: { version: newVersionRange }, }); - expect(messenger.call).toHaveBeenCalledTimes(25); + expect(messenger.call).toHaveBeenCalledTimes(21); expect(messenger.call).toHaveBeenNthCalledWith( - 14, + 12, 'ApprovalController:addRequest', { origin: MOCK_ORIGIN, @@ -2951,13 +2808,13 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 16, + 14, 'PermissionController:getPermissions', MOCK_SNAP_ID, ); expect(messenger.call).toHaveBeenNthCalledWith( - 17, + 15, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -2973,7 +2830,7 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 18, + 16, 'ApprovalController:addRequest', expect.objectContaining({ id: expect.any(String), @@ -2994,20 +2851,13 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 19, + 17, 'ExecutionService:executeSnap', expect.objectContaining({}), ); expect(messenger.call).toHaveBeenNthCalledWith( 20, - 'PermissionController:hasPermission', - MOCK_SNAP_ID, - SnapEndowments.LongRunning, - ); - - expect(messenger.call).toHaveBeenNthCalledWith( - 23, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -3521,10 +3371,10 @@ describe('SnapController', () => { date: expect.any(Number), }, ]); - expect(callActionSpy).toHaveBeenCalledTimes(25); + expect(callActionSpy).toHaveBeenCalledTimes(21); expect(callActionSpy).toHaveBeenNthCalledWith( - 14, + 12, 'ApprovalController:addRequest', { origin: MOCK_ORIGIN, @@ -3546,13 +3396,13 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 16, + 14, 'PermissionController:getPermissions', MOCK_SNAP_ID, ); expect(messenger.call).toHaveBeenNthCalledWith( - 17, + 15, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -3568,7 +3418,7 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 18, + 16, 'ApprovalController:addRequest', expect.objectContaining({ id: expect.any(String), @@ -3589,20 +3439,13 @@ describe('SnapController', () => { ); expect(callActionSpy).toHaveBeenNthCalledWith( - 19, + 17, 'ExecutionService:executeSnap', expect.objectContaining({}), ); - expect(callActionSpy).toHaveBeenNthCalledWith( - 20, - 'PermissionController:hasPermission', - MOCK_SNAP_ID, - SnapEndowments.LongRunning, - ); - expect(messenger.call).toHaveBeenNthCalledWith( - 23, + 20, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -3703,7 +3546,7 @@ describe('SnapController', () => { const isRunning = controller.isRunning(MOCK_SNAP_ID); - expect(callActionSpy).toHaveBeenCalledTimes(15); + expect(callActionSpy).toHaveBeenCalledTimes(12); expect(callActionSpy).toHaveBeenNthCalledWith( 1, @@ -3713,13 +3556,6 @@ describe('SnapController', () => { expect(callActionSpy).toHaveBeenNthCalledWith( 2, - 'PermissionController:hasPermission', - MOCK_SNAP_ID, - SnapEndowments.LongRunning, - ); - - expect(callActionSpy).toHaveBeenNthCalledWith( - 3, 'ApprovalController:addRequest', { origin: MOCK_ORIGIN, @@ -3741,13 +3577,13 @@ describe('SnapController', () => { ); expect(callActionSpy).toHaveBeenNthCalledWith( - 5, + 4, 'PermissionController:getPermissions', MOCK_SNAP_ID, ); expect(callActionSpy).toHaveBeenNthCalledWith( - 6, + 5, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -3763,7 +3599,7 @@ describe('SnapController', () => { ); expect(callActionSpy).toHaveBeenNthCalledWith( - 7, + 6, 'ApprovalController:addRequest', expect.objectContaining({ id: expect.any(String), @@ -3784,20 +3620,13 @@ describe('SnapController', () => { ); expect(callActionSpy).toHaveBeenNthCalledWith( - 8, + 7, 'ExecutionService:terminateSnap', MOCK_SNAP_ID, ); expect(callActionSpy).toHaveBeenNthCalledWith( - 10, - 'PermissionController:hasPermission', - MOCK_SNAP_ID, - SnapEndowments.LongRunning, - ); - - expect(callActionSpy).toHaveBeenNthCalledWith( - 13, + 11, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -4054,10 +3883,10 @@ describe('SnapController', () => { await controller.updateSnap(MOCK_ORIGIN, MOCK_SNAP_ID, detect()); - expect(callActionSpy).toHaveBeenCalledTimes(27); + expect(callActionSpy).toHaveBeenCalledTimes(23); expect(callActionSpy).toHaveBeenNthCalledWith( - 14, + 12, 'ApprovalController:addRequest', { origin: MOCK_ORIGIN, @@ -4079,7 +3908,7 @@ describe('SnapController', () => { ); expect(callActionSpy).toHaveBeenNthCalledWith( - 17, + 15, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -4101,7 +3930,7 @@ describe('SnapController', () => { ); expect(callActionSpy).toHaveBeenNthCalledWith( - 18, + 16, 'ApprovalController:addRequest', { origin: MOCK_ORIGIN, @@ -4123,13 +3952,13 @@ describe('SnapController', () => { ); expect(callActionSpy).toHaveBeenNthCalledWith( - 19, + 17, 'PermissionController:revokePermissions', { [MOCK_SNAP_ID]: ['snap_manageState'] }, ); expect(callActionSpy).toHaveBeenNthCalledWith( - 20, + 18, 'PermissionController:grantPermissions', { approvedPermissions: { 'endowment:network-access': {} }, @@ -4146,20 +3975,13 @@ describe('SnapController', () => { ); expect(callActionSpy).toHaveBeenNthCalledWith( - 21, + 19, 'ExecutionService:executeSnap', expect.anything(), ); expect(callActionSpy).toHaveBeenNthCalledWith( 22, - 'PermissionController:hasPermission', - MOCK_SNAP_ID, - SnapEndowments.LongRunning, - ); - - expect(callActionSpy).toHaveBeenNthCalledWith( - 25, 'ApprovalController:updateRequestState', expect.objectContaining({ id: expect.any(String), @@ -5512,7 +5334,7 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 5, + 4, 'ExecutionService:handleRpcRequest', MOCK_SNAP_ID, { @@ -5635,7 +5457,7 @@ describe('SnapController', () => { ); expect(messenger.call).toHaveBeenNthCalledWith( - 5, + 4, 'ExecutionService:handleRpcRequest', MOCK_SNAP_ID, { diff --git a/packages/snaps-controllers/src/snaps/SnapController.ts b/packages/snaps-controllers/src/snaps/SnapController.ts index c1c9454f0c..9bf81ae29e 100644 --- a/packages/snaps-controllers/src/snaps/SnapController.ts +++ b/packages/snaps-controllers/src/snaps/SnapController.ts @@ -52,7 +52,6 @@ import { getErrorMessage, HandlerType, logError, - logWarning, normalizeRelative, resolveVersionRange, SnapCaveatType, @@ -2084,7 +2083,6 @@ export class SnapController extends BaseController< try { const result = await this.#executeWithTimeout( - snapId, this.messagingSystem.call('ExecutionService:executeSnap', { ...snapData, endowments: await this.#getEndowments(snapId), @@ -2535,7 +2533,6 @@ export class SnapController extends BaseController< // This will either get the result or reject due to the timeout. try { const result = await this.#executeWithTimeout( - snapId, handleRpcRequestPromise, timer, ); @@ -2555,31 +2552,15 @@ export class SnapController extends BaseController< * Awaits the specified promise and rejects if the promise doesn't resolve * before the timeout. * - * @param snapId - The snap id. * @param promise - The promise to await. * @param timer - An optional timer object to control the timeout. * @returns The result of the promise or rejects if the promise times out. * @template PromiseValue - The value of the Promise. */ async #executeWithTimeout( - snapId: ValidatedSnapId, promise: Promise, timer?: Timer, ): Promise { - const isLongRunning = this.messagingSystem.call( - 'PermissionController:hasPermission', - snapId, - SnapEndowments.LongRunning, - ); - - // Long running snaps have timeouts disabled - if (isLongRunning) { - logWarning( - `${SnapEndowments.LongRunning} will soon be deprecated. For more information please see https://github.com/MetaMask/snaps-monorepo/issues/945.`, - ); - return promise; - } - const result = await withTimeout(promise, timer ?? this.maxRequestTime); if (result === hasTimedOut) { throw new Error('The request timed out.'); diff --git a/packages/snaps-controllers/src/snaps/endowments/enum.ts b/packages/snaps-controllers/src/snaps/endowments/enum.ts index 14809b0dbf..f7e9ba05c6 100644 --- a/packages/snaps-controllers/src/snaps/endowments/enum.ts +++ b/packages/snaps-controllers/src/snaps/endowments/enum.ts @@ -1,6 +1,5 @@ export enum SnapEndowments { NetworkAccess = 'endowment:network-access', - LongRunning = 'endowment:long-running', TransactionInsight = 'endowment:transaction-insight', Cronjob = 'endowment:cronjob', EthereumProvider = 'endowment:ethereum-provider', diff --git a/packages/snaps-controllers/src/snaps/endowments/index.ts b/packages/snaps-controllers/src/snaps/endowments/index.ts index 29cf6faa0b..ecccb127da 100644 --- a/packages/snaps-controllers/src/snaps/endowments/index.ts +++ b/packages/snaps-controllers/src/snaps/endowments/index.ts @@ -9,7 +9,6 @@ import { } from './cronjob'; import { ethereumProviderEndowmentBuilder } from './ethereum-provider'; import { lifecycleHooksEndowmentBuilder } from './lifecycle-hooks'; -import { longRunningEndowmentBuilder } from './long-running'; import { getNameLookupCaveatMapper, nameLookupCaveatSpecifications, @@ -30,7 +29,6 @@ import { webAssemblyEndowmentBuilder } from './web-assembly'; export const endowmentPermissionBuilders = { [networkAccessEndowmentBuilder.targetName]: networkAccessEndowmentBuilder, - [longRunningEndowmentBuilder.targetName]: longRunningEndowmentBuilder, [transactionInsightEndowmentBuilder.targetName]: transactionInsightEndowmentBuilder, [cronjobEndowmentBuilder.targetName]: cronjobEndowmentBuilder, diff --git a/packages/snaps-controllers/src/snaps/endowments/long-running.test.ts b/packages/snaps-controllers/src/snaps/endowments/long-running.test.ts deleted file mode 100644 index 60f5b4a53c..0000000000 --- a/packages/snaps-controllers/src/snaps/endowments/long-running.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { PermissionType, SubjectType } from '@metamask/permission-controller'; - -import { SnapEndowments } from '.'; -import { longRunningEndowmentBuilder } from './long-running'; - -describe('endowment:long-running', () => { - it('builds the expected permission specification', () => { - const specification = longRunningEndowmentBuilder.specificationBuilder({}); - expect(specification).toStrictEqual({ - permissionType: PermissionType.Endowment, - targetName: SnapEndowments.LongRunning, - endowmentGetter: expect.any(Function), - allowedCaveats: null, - subjectTypes: [SubjectType.Snap], - }); - - expect(specification.endowmentGetter()).toBeUndefined(); - }); -}); diff --git a/packages/snaps-controllers/src/snaps/endowments/long-running.ts b/packages/snaps-controllers/src/snaps/endowments/long-running.ts deleted file mode 100644 index 19c554704b..0000000000 --- a/packages/snaps-controllers/src/snaps/endowments/long-running.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { - PermissionSpecificationBuilder, - EndowmentGetterParams, - ValidPermissionSpecification, -} from '@metamask/permission-controller'; -import { PermissionType, SubjectType } from '@metamask/permission-controller'; - -import { SnapEndowments } from './enum'; - -const permissionName = SnapEndowments.LongRunning; - -type LongRunningEndowmentSpecification = ValidPermissionSpecification<{ - permissionType: PermissionType.Endowment; - targetName: typeof permissionName; - endowmentGetter: (_options?: any) => undefined; - allowedCaveats: null; -}>; - -/** - * `endowment:long-running` returns nothing; it is intended to be used as a flag - * by the `SnapController` to make it ignore the request processing timeout - * during snap lifecycle management. Essentially, it allows a snap to take an - * infinite amount of time to process a request. - * - * @param _builderOptions - Optional specification builder options. - * @returns The specification for the long-running endowment. - */ -const specificationBuilder: PermissionSpecificationBuilder< - PermissionType.Endowment, - any, - LongRunningEndowmentSpecification -> = (_builderOptions?: any) => { - return { - permissionType: PermissionType.Endowment, - targetName: permissionName, - allowedCaveats: null, - endowmentGetter: (_getterOptions?: EndowmentGetterParams) => undefined, - subjectTypes: [SubjectType.Snap], - }; -}; - -export const longRunningEndowmentBuilder = Object.freeze({ - targetName: permissionName, - specificationBuilder, -} as const); diff --git a/packages/snaps-controllers/src/snaps/permission.test.ts b/packages/snaps-controllers/src/snaps/permission.test.ts index bc0a49aa28..8cacabf896 100644 --- a/packages/snaps-controllers/src/snaps/permission.test.ts +++ b/packages/snaps-controllers/src/snaps/permission.test.ts @@ -37,15 +37,6 @@ describe('buildSnapEndowmentSpecifications', () => { ], "targetName": "endowment:lifecycle-hooks", }, - "endowment:long-running": { - "allowedCaveats": null, - "endowmentGetter": [Function], - "permissionType": "Endowment", - "subjectTypes": [ - "snap", - ], - "targetName": "endowment:long-running", - }, "endowment:name-lookup": { "allowedCaveats": [ "chainIds", diff --git a/packages/snaps-controllers/src/test-utils/controller.ts b/packages/snaps-controllers/src/test-utils/controller.ts index 90e825f879..eaa0d3d78f 100644 --- a/packages/snaps-controllers/src/test-utils/controller.ts +++ b/packages/snaps-controllers/src/test-utils/controller.ts @@ -177,12 +177,9 @@ export const getControllerMessenger = (registry = new MockSnapsRegistry()) => { SnapControllerEvents | AllowedEvents >(); - messenger.registerActionHandler( - 'PermissionController:hasPermission', - (permission) => { - return permission !== SnapEndowments.LongRunning; - }, - ); + messenger.registerActionHandler('PermissionController:hasPermission', () => { + return true; + }); messenger.registerActionHandler('PermissionController:hasPermissions', () => { return true; @@ -480,8 +477,8 @@ export const getRestrictedCronjobControllerMessenger = ( if (mocked) { messenger.registerActionHandler( 'PermissionController:hasPermission', - (permission) => { - return permission !== SnapEndowments.LongRunning; + () => { + return true; }, ); diff --git a/packages/snaps-utils/src/manifest/validation.ts b/packages/snaps-utils/src/manifest/validation.ts index 1aa9cb2033..e4f2ba5eb4 100644 --- a/packages/snaps-utils/src/manifest/validation.ts +++ b/packages/snaps-utils/src/manifest/validation.ts @@ -140,7 +140,6 @@ export type SnapIds = Infer; /* eslint-disable @typescript-eslint/naming-convention */ export const PermissionsStruct = type({ - 'endowment:long-running': optional(object({})), 'endowment:network-access': optional(object({})), 'endowment:webassembly': optional(object({})), 'endowment:transaction-insight': optional(