diff --git a/packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.browser.ts b/packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.browser.ts index ce6f22853c..51d58cd98d 100644 --- a/packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.browser.ts +++ b/packages/snaps-execution-environments/src/common/BaseSnapExecutor.test.browser.ts @@ -191,6 +191,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'ethereum.request' }, }); const blockNumRequest = await executor.readRpc(); @@ -217,6 +218,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundResponse', + params: { source: 'ethereum.request' }, }); expect(await executor.readCommand()).toStrictEqual({ @@ -255,6 +257,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'snap.request' }, }); const walletRequest = await executor.readRpc(); @@ -281,6 +284,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundResponse', + params: { source: 'snap.request' }, }); expect(await executor.readCommand()).toStrictEqual({ @@ -416,6 +420,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'ethereum.request' }, }); const blockNumRequest = await executor.readRpc(); @@ -442,6 +447,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundResponse', + params: { source: 'ethereum.request' }, }); expect(await executor.readCommand()).toStrictEqual({ @@ -482,6 +488,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'snap.request' }, }); const getSnapsRequest = await executor.readRpc(); @@ -516,6 +523,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundResponse', + params: { source: 'snap.request' }, }); expect(await executor.readCommand()).toStrictEqual({ @@ -898,6 +906,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'snap.request' }, }); const request = await executor.readRpc(); @@ -930,6 +939,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundResponse', + params: { source: 'snap.request' }, }); expect(await executor.readCommand()).toStrictEqual({ @@ -973,6 +983,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'ethereum.request' }, }); const request = await executor.readRpc(); @@ -1007,6 +1018,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundResponse', + params: { source: 'ethereum.request' }, }); expect(await executor.readCommand()).toStrictEqual({ @@ -1051,21 +1063,25 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'fetch' }, }); expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundResponse', + params: { source: 'fetch' }, }); expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'fetch' }, }); expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundResponse', + params: { source: 'fetch' }, }); expect(await executor.readCommand()).toStrictEqual({ @@ -1624,6 +1640,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'ethereum.request' }, }); const blockNumRequest = await executor.readRpc(); @@ -1726,6 +1743,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'ethereum.request' }, }); const blockNumRequest = await executor.readRpc(); @@ -1813,6 +1831,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundRequest', + params: { source: 'ethereum.request' }, }); const blockNumRequest = await executor.readRpc(); @@ -1842,6 +1861,7 @@ describe('BaseSnapExecutor', () => { expect(await executor.readCommand()).toStrictEqual({ jsonrpc: '2.0', method: 'OutboundResponse', + params: { source: 'ethereum.request' }, }); expect(await executor.readCommand()).toStrictEqual({ diff --git a/packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts b/packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts index cbce8848d5..9d81c03f7c 100644 --- a/packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts +++ b/packages/snaps-execution-environments/src/common/BaseSnapExecutor.ts @@ -438,11 +438,17 @@ export class BaseSnapExecutor { const request = async (args: RequestArguments) => { const sanitizedArgs = sanitizeRequestArguments(args); assertSnapOutboundRequest(sanitizedArgs); - this.notify({ method: 'OutboundRequest' }); + this.notify({ + method: 'OutboundRequest', + params: { source: 'snap.request' }, + }); try { return await withTeardown(originalRequest(sanitizedArgs), this as any); } finally { - this.notify({ method: 'OutboundResponse' }); + this.notify({ + method: 'OutboundResponse', + params: { source: 'snap.request' }, + }); } }; @@ -479,11 +485,17 @@ export class BaseSnapExecutor { const request = async (args: RequestArguments) => { const sanitizedArgs = sanitizeRequestArguments(args); assertEthereumOutboundRequest(sanitizedArgs); - this.notify({ method: 'OutboundRequest' }); + this.notify({ + method: 'OutboundRequest', + params: { source: 'ethereum.request' }, + }); try { return await withTeardown(originalRequest(sanitizedArgs), this as any); } finally { - this.notify({ method: 'OutboundResponse' }); + this.notify({ + method: 'OutboundResponse', + params: { source: 'ethereum.request' }, + }); } }; diff --git a/packages/snaps-execution-environments/src/common/endowments/network.test.ts b/packages/snaps-execution-environments/src/common/endowments/network.test.ts index 1b19aa67a3..c9859dbcc1 100644 --- a/packages/snaps-execution-environments/src/common/endowments/network.test.ts +++ b/packages/snaps-execution-environments/src/common/endowments/network.test.ts @@ -33,11 +33,21 @@ describe('Network endowments', () => { const { fetch } = network.factory({ notify }); const result = await (await fetch('foo.com')).text(); expect(result).toStrictEqual(RESULT); - expect(notify).toHaveBeenCalledWith({ + expect(notify).toHaveBeenNthCalledWith(1, { method: 'OutboundRequest', + params: { source: 'fetch' }, }); - expect(notify).toHaveBeenCalledWith({ + expect(notify).toHaveBeenNthCalledWith(2, { method: 'OutboundResponse', + params: { source: 'fetch' }, + }); + expect(notify).toHaveBeenNthCalledWith(3, { + method: 'OutboundRequest', + params: { source: 'fetch' }, + }); + expect(notify).toHaveBeenNthCalledWith(4, { + method: 'OutboundResponse', + params: { source: 'fetch' }, }); expect(notify).toHaveBeenCalledTimes(4); }); diff --git a/packages/snaps-execution-environments/src/common/endowments/network.ts b/packages/snaps-execution-environments/src/common/endowments/network.ts index 5f8bd952b7..614fba68a6 100644 --- a/packages/snaps-execution-environments/src/common/endowments/network.ts +++ b/packages/snaps-execution-environments/src/common/endowments/network.ts @@ -175,7 +175,7 @@ const createNetwork = ({ notify }: EndowmentFactoryOptions = {}) => { const onStart = () => { if (!started) { started = true; - notify({ method: 'OutboundRequest' }); + notify({ method: 'OutboundRequest', params: { source: 'fetch' } }); } }; @@ -183,14 +183,14 @@ const createNetwork = ({ notify }: EndowmentFactoryOptions = {}) => { const onFinish = () => { if (!finished) { finished = true; - notify({ method: 'OutboundResponse' }); + notify({ method: 'OutboundResponse', params: { source: 'fetch' } }); } }; let res: Response; let openFetchConnection: { cancel: () => Promise } | undefined; try { - notify({ method: 'OutboundRequest' }); + notify({ method: 'OutboundRequest', params: { source: 'fetch' } }); const fetchPromise = fetch(input, { ...init, signal: abortController.signal, @@ -218,7 +218,7 @@ const createNetwork = ({ notify }: EndowmentFactoryOptions = {}) => { if (openFetchConnection !== undefined) { openConnections.delete(openFetchConnection); } - notify({ method: 'OutboundResponse' }); + notify({ method: 'OutboundResponse', params: { source: 'fetch' } }); } if (res.body !== null) {