diff --git a/app/components/Views/confirmations/SendFlow/Confirm/index.test.tsx b/app/components/Views/confirmations/SendFlow/Confirm/index.test.tsx index 34fbde618c2..254fb1d4e6e 100644 --- a/app/components/Views/confirmations/SendFlow/Confirm/index.test.tsx +++ b/app/components/Views/confirmations/SendFlow/Confirm/index.test.tsx @@ -126,7 +126,6 @@ jest.mock('../../../../../util/ENSUtils', () => ({ jest.mock('../../../../../lib/ppom/ppom-util', () => ({ ...jest.requireActual('../../../../../lib/ppom/ppom-util'), validateRequest: jest.fn(), - isChainSupported: jest.fn(), })); jest.mock('../../../../../core/Engine', () => { diff --git a/app/core/NotificationsManager.test.ts b/app/core/NotificationsManager.test.ts index c052e782ed6..c6034875496 100644 --- a/app/core/NotificationsManager.test.ts +++ b/app/core/NotificationsManager.test.ts @@ -126,7 +126,7 @@ describe('NotificationManager', () => { expect(message).toBe(strings('notifications.default_message_description')); }); }); - + describe('smartTransactionListener', () => { const mockTransactionController = { getTransactions: jest.fn(), @@ -172,7 +172,7 @@ describe('NotificationManager', () => { beforeEach(() => { // Clear all mock interactions before each test jest.clearAllMocks(); - + // Reset the notification manager before each test notificationManager = NotificationManager.init({ navigation: mockNavigation, @@ -197,14 +197,14 @@ describe('NotificationManager', () => { transactionId: '0x123', }; - notificationManager.watchSubmittedTransaction({ + notificationManager.watchSubmittedTransaction({ id: '0x123', txParams: { nonce: '0x1' }, silent: false }); - + // Get the subscriber callback const subscriberCallback = mockControllerMessenger.subscribe.mock.calls[0][1]; await subscriberCallback(transaction); @@ -217,7 +217,7 @@ describe('NotificationManager', () => { }); it('shows a cancelled notification for cancelled smart transactions', async () => { - const mockTransaction = { + const mockTransaction = { id: '0x123', txParams: { nonce: '0x1' @@ -230,14 +230,14 @@ describe('NotificationManager', () => { transactionId: '0x123', }; - notificationManager.watchSubmittedTransaction({ + notificationManager.watchSubmittedTransaction({ id: '0x123', txParams: { nonce: '0x1' }, silent: false }); - + // Get the subscriber callback const subscriberCallback = mockControllerMessenger.subscribe.mock.calls[0][1]; await subscriberCallback(smartTransaction); @@ -256,14 +256,14 @@ describe('NotificationManager', () => { transactionId: '0x123', }; - notificationManager.watchSubmittedTransaction({ + notificationManager.watchSubmittedTransaction({ id: '0x123', txParams: { nonce: '0x1' }, silent: false }); - + // Get the subscriber callback const subscriberCallback = mockControllerMessenger.subscribe.mock.calls[0][1]; await subscriberCallback(transaction); @@ -275,7 +275,7 @@ describe('NotificationManager', () => { }); it('sets up transaction event listeners correctly', () => { - const transaction = { + const transaction = { id: '0x123', txParams: { nonce: '0x1' diff --git a/app/core/SDKConnect/utils/isUUID.ts b/app/core/SDKConnect/utils/isUUID.ts index 5b975d9cff8..9885bd90796 100644 --- a/app/core/SDKConnect/utils/isUUID.ts +++ b/app/core/SDKConnect/utils/isUUID.ts @@ -2,4 +2,4 @@ export const isUUID = (str: string) => { const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i; return uuidRegex.test(str); -}; \ No newline at end of file +}; diff --git a/app/lib/ppom/ppom-util.ts b/app/lib/ppom/ppom-util.ts index b76d4bf8f4b..76c18c1f8af 100644 --- a/app/lib/ppom/ppom-util.ts +++ b/app/lib/ppom/ppom-util.ts @@ -18,13 +18,10 @@ import { import { WALLET_CONNECT_ORIGIN } from '../../util/walletconnect'; import AppConstants from '../../core/AppConstants'; import { - getSecurityAlertsAPISupportedChainIds, isSecurityAlertsAPIEnabled, validateWithSecurityAlertsAPI, } from './security-alerts-api'; import { PPOMController } from '@metamask/ppom-validator'; -import { Hex } from '@metamask/utils'; -import { SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST } from '../../util/networks'; export interface PPOMRequest { method: string; @@ -72,13 +69,11 @@ async function validateRequest(req: PPOMRequest, transactionId?: string) { NetworkController.state?.selectedNetworkClientId, ); const isConfirmationMethod = CONFIRMATION_METHODS.includes(req.method); - const isSupportedChain = await isChainSupported(chainId); const isBlockaidFeatEnabled = await isBlockaidFeatureEnabled(); if ( !ppomController || !isBlockaidFeatEnabled || - !isConfirmationMethod || - !isSupportedChain + !isConfirmationMethod ) { return; } @@ -138,21 +133,6 @@ async function validateRequest(req: PPOMRequest, transactionId?: string) { } } -async function isChainSupported(chainId: Hex): Promise { - let supportedChainIds = SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST; - try { - if (isSecurityAlertsAPIEnabled()) { - supportedChainIds = await getSecurityAlertsAPISupportedChainIds(); - } - } catch (e) { - Logger.log( - `Error fetching supported chains from security alerts API: ${e}`, - ); - } - - return supportedChainIds.includes(chainId); -} - async function validateWithController( ppomController: PPOMController, request: PPOMRequest, @@ -251,4 +231,4 @@ function normalizeRequest(request: PPOMRequest): PPOMRequest { }; } -export default { validateRequest, isChainSupported }; +export default { validateRequest }; diff --git a/app/lib/ppom/security-alerts-api.test.ts b/app/lib/ppom/security-alerts-api.test.ts index 2ca15d22052..231972e0b86 100644 --- a/app/lib/ppom/security-alerts-api.test.ts +++ b/app/lib/ppom/security-alerts-api.test.ts @@ -3,7 +3,6 @@ import { ResultType, } from '../../components/Views/confirmations/components/BlockaidBanner/BlockaidBanner.types'; import { - getSecurityAlertsAPISupportedChainIds, validateWithSecurityAlertsAPI, } from './security-alerts-api'; @@ -69,31 +68,4 @@ describe('Security Alerts API', () => { ); }); }); - - describe('getSecurityAlertsAPISupportedChainIds', () => { - it('sends GET request', async () => { - const SUPPORTED_CHAIN_IDS_MOCK = ['0x1', '0x2']; - fetchMock.mockResolvedValue({ - ok: true, - json: async () => SUPPORTED_CHAIN_IDS_MOCK, - }); - const response = await getSecurityAlertsAPISupportedChainIds(); - - expect(response).toEqual(SUPPORTED_CHAIN_IDS_MOCK); - - expect(fetchMock).toHaveBeenCalledTimes(1); - expect(fetchMock).toHaveBeenCalledWith( - `https://example.com/supportedChains`, - undefined, - ); - }); - - it('throws an error if response is not ok', async () => { - fetchMock.mockResolvedValue({ ok: false, status: 404 }); - - await expect(getSecurityAlertsAPISupportedChainIds()).rejects.toThrow( - 'Security alerts API request failed with status: 404', - ); - }); - }); }); diff --git a/app/lib/ppom/security-alerts-api.ts b/app/lib/ppom/security-alerts-api.ts index f710b63f710..49eff9fe5b7 100644 --- a/app/lib/ppom/security-alerts-api.ts +++ b/app/lib/ppom/security-alerts-api.ts @@ -1,9 +1,7 @@ -import { Hex } from '@metamask/utils'; import { SecurityAlertResponse } from '../../components/Views/confirmations/components/BlockaidBanner/BlockaidBanner.types'; import AppConstants from '../../core/AppConstants'; const ENDPOINT_VALIDATE = 'validate'; -const ENDPOINT_SUPPORTED_CHAINS = 'supportedChains'; export interface SecurityAlertsAPIRequest { method: string; @@ -28,10 +26,6 @@ export async function validateWithSecurityAlertsAPI( }); } -export async function getSecurityAlertsAPISupportedChainIds(): Promise { - return request(ENDPOINT_SUPPORTED_CHAINS); -} - async function request(endpoint: string, options?: RequestInit) { const url = getUrl(endpoint); diff --git a/app/util/blockaid/index.test.ts b/app/util/blockaid/index.test.ts index 612982fd4bb..1f87c57c37b 100644 --- a/app/util/blockaid/index.test.ts +++ b/app/util/blockaid/index.test.ts @@ -8,11 +8,9 @@ import { import * as NetworkControllerMock from '../../selectors/networkController'; import { NETWORKS_CHAIN_ID } from '../../constants/network'; import Engine from '../../core/Engine'; -import ppomUtil from '../../lib/ppom/ppom-util'; import { getBlockaidMetricsParams, - isBlockaidSupportedOnCurrentChain, getBlockaidTransactionMetricsParams, isBlockaidFeatureEnabled, TransactionType, @@ -30,18 +28,12 @@ jest.mock('../../core/Engine', () => ({ }, })); -const mockIsChainSupported = jest.fn().mockResolvedValue(true); - describe('Blockaid util', () => { describe('getBlockaidTransactionMetricsParams', () => { beforeEach(() => { jest .spyOn(NetworkControllerMock, 'selectChainId') .mockReturnValue(NETWORKS_CHAIN_ID.MAINNET); - - jest - .spyOn(ppomUtil, 'isChainSupported') - .mockImplementation(mockIsChainSupported); }); afterEach(() => { @@ -194,28 +186,6 @@ describe('Blockaid util', () => { }); }); - describe('isBlockaidSupportedOnCurrentChain', () => { - afterEach(() => { - jest.clearAllMocks(); - }); - - it('return true if blockaid is supported on current network', async () => { - jest - .spyOn(NetworkControllerMock, 'selectChainId') - .mockReturnValue(NETWORKS_CHAIN_ID.MAINNET); - const result = await isBlockaidSupportedOnCurrentChain(); - expect(result).toEqual(true); - }); - - it('return false if blockaid is not on current network', async () => { - jest - .spyOn(NetworkControllerMock, 'selectChainId') - .mockReturnValue(NETWORKS_CHAIN_ID.GOERLI); - const result = await isBlockaidSupportedOnCurrentChain(); - expect(result).toEqual(false); - }); - }); - describe('isBlockaidFeatureEnabled', () => { afterEach(() => { jest.clearAllMocks(); diff --git a/app/util/blockaid/index.ts b/app/util/blockaid/index.ts index 7379e669ce6..ece50b83f04 100644 --- a/app/util/blockaid/index.ts +++ b/app/util/blockaid/index.ts @@ -3,10 +3,7 @@ import { ResultType, SecurityAlertResponse, } from '../../components/Views/confirmations/components/BlockaidBanner/BlockaidBanner.types'; -import { store } from '../../store'; -import { selectChainId } from '../../selectors/networkController'; import type { TransactionMeta } from '@metamask/transaction-controller'; -import PPOMUtils from '../../lib/ppom/ppom-util'; interface TransactionSecurityAlertResponseType { securityAlertResponses: Record; @@ -15,18 +12,13 @@ interface TransactionSecurityAlertResponseType { export type TransactionType = TransactionMeta & TransactionSecurityAlertResponseType; -export const isBlockaidSupportedOnCurrentChain = async (): Promise => { - const chainId = selectChainId(store.getState()); - return await PPOMUtils.isChainSupported(chainId); -}; - export const isBlockaidPreferenceEnabled = (): boolean => { const { PreferencesController } = Engine.context; return PreferencesController.state.securityAlertsEnabled; }; export const isBlockaidFeatureEnabled = async (): Promise => - (await isBlockaidSupportedOnCurrentChain()) && isBlockaidPreferenceEnabled(); + isBlockaidPreferenceEnabled(); export const getBlockaidMetricsParams = ( securityAlertResponse?: SecurityAlertResponse, diff --git a/app/util/networks/index.js b/app/util/networks/index.js index 51cfed908a0..72d21928c15 100644 --- a/app/util/networks/index.js +++ b/app/util/networks/index.js @@ -115,23 +115,6 @@ export const NetworkList = { const NetworkListKeys = Object.keys(NetworkList); -export const SECURITY_PROVIDER_SUPPORTED_CHAIN_IDS_FALLBACK_LIST = [ - NETWORKS_CHAIN_ID.MAINNET, - NETWORKS_CHAIN_ID.BSC, - NETWORKS_CHAIN_ID.BASE, - NETWORKS_CHAIN_ID.POLYGON, - NETWORKS_CHAIN_ID.ARBITRUM, - NETWORKS_CHAIN_ID.OPTIMISM, - NETWORKS_CHAIN_ID.AVAXCCHAIN, - NETWORKS_CHAIN_ID.LINEA_MAINNET, - NETWORKS_CHAIN_ID.SEPOLIA, - NETWORKS_CHAIN_ID.OPBNB, - NETWORKS_CHAIN_ID.ZKSYNC_ERA, - NETWORKS_CHAIN_ID.SCROLL, - NETWORKS_CHAIN_ID.BERACHAIN, - NETWORKS_CHAIN_ID.METACHAIN_ONE, -]; - export const BLOCKAID_SUPPORTED_NETWORK_NAMES = { [NETWORKS_CHAIN_ID.MAINNET]: 'Ethereum Mainnet', [NETWORKS_CHAIN_ID.BSC]: 'Binance Smart Chain', diff --git a/e2e/api-mocking/mock-config/mock-events.js b/e2e/api-mocking/mock-config/mock-events.js index 755fe4d39da..6cab3512592 100644 --- a/e2e/api-mocking/mock-config/mock-events.js +++ b/e2e/api-mocking/mock-config/mock-events.js @@ -35,27 +35,6 @@ export const mockEvents = { responseCode: 200, }, - securityAlertApiSupportedChains: { - urlEndpoint: 'https://security-alerts.api.cx.metamask.io/supportedChains', - response: [ - '0xa4b1', - '0xa86a', - '0x2105', - '0x138d5', - '0x38', - '0xe708', - '0x1', - '0x1b6e6', - '0xcc', - '0xa', - '0x89', - '0x82750', - '0xaa36a7', - '0x144', - ], - responseCode: 200, - }, - remoteFeatureFlags: { urlEndpoint: 'https://client-config.api.cx.metamask.io/v1/flags?client=mobile&distribution=main&environment=dev', diff --git a/e2e/specs/quarantine/security-alert-send-eth.mock.failing.js b/e2e/specs/confirmations/security-alert-send-eth.mock.js similarity index 95% rename from e2e/specs/quarantine/security-alert-send-eth.mock.failing.js rename to e2e/specs/confirmations/security-alert-send-eth.mock.js index b3e346fc460..d44538c6ca2 100644 --- a/e2e/specs/quarantine/security-alert-send-eth.mock.failing.js +++ b/e2e/specs/confirmations/security-alert-send-eth.mock.js @@ -49,7 +49,9 @@ describe(SmokeConfirmations('Security Alert API - Send flow'), () => { it('should not show security alerts for benign requests', async () => { const testSpecificMock = { - GET: [mockEvents.GET.securityAlertApiSupportedChains], + GET: [ + mockEvents.GET.remoteFeatureFlags, + ], POST: [mockEvents.POST.securityAlertApiValidate], }; @@ -67,7 +69,9 @@ describe(SmokeConfirmations('Security Alert API - Send flow'), () => { it('should show security alerts for malicious request', async () => { const testSpecificMock = { - GET: [mockEvents.GET.securityAlertApiSupportedChains], + GET: [ + mockEvents.GET.remoteFeatureFlags, + ], POST: [ { ...mockEvents.POST.securityAlertApiValidate, @@ -92,7 +96,7 @@ describe(SmokeConfirmations('Security Alert API - Send flow'), () => { it('should show security alerts for error when validating request fails', async () => { const testSpecificMock = { GET: [ - mockEvents.GET.securityAlertApiSupportedChains, + mockEvents.GET.remoteFeatureFlags, { urlEndpoint: 'https://static.cx.metamask.io/api/v1/confirmations/ppom/ppom_version.json', diff --git a/e2e/specs/confirmations/send-failing-contract.spec.js b/e2e/specs/confirmations/send-failing-contract.spec.js index dac0b112d01..79b8741d862 100644 --- a/e2e/specs/confirmations/send-failing-contract.spec.js +++ b/e2e/specs/confirmations/send-failing-contract.spec.js @@ -54,7 +54,7 @@ describe(SmokeConfirmations('Failing contracts'), () => { await TestDApp.navigateToTestDappWithContract({ contractAddress: failingAddress, }); - + // Send a failing transaction await TestDApp.tapSendFailingTransactionButton(); await TestHelpers.delay(3000); diff --git a/e2e/specs/confirmations/signatures/security-alert-signatures.mock.spec.js b/e2e/specs/confirmations/signatures/security-alert-signatures.mock.spec.js index 77f0f3b3721..483068d2a67 100644 --- a/e2e/specs/confirmations/signatures/security-alert-signatures.mock.spec.js +++ b/e2e/specs/confirmations/signatures/security-alert-signatures.mock.spec.js @@ -61,7 +61,6 @@ describe(SmokeConfirmations('Security Alert API - Signature'), () => { it('should sign typed message', async () => { const testSpecificMock = { GET: [ - mockEvents.GET.securityAlertApiSupportedChains, mockEvents.GET.remoteFeatureFlags, ], POST: [ @@ -87,7 +86,6 @@ describe(SmokeConfirmations('Security Alert API - Signature'), () => { it('should show security alert for malicious request', async () => { const testSpecificMock = { GET: [ - mockEvents.GET.securityAlertApiSupportedChains, mockEvents.GET.remoteFeatureFlags, ], POST: [ @@ -113,7 +111,6 @@ describe(SmokeConfirmations('Security Alert API - Signature'), () => { it('should show security alert for error when validating request fails', async () => { const testSpecificMock = { GET: [ - mockEvents.GET.securityAlertApiSupportedChains, mockEvents.GET.remoteFeatureFlags, { urlEndpoint: