diff --git a/app/scripts/controllers/transactions/index.js b/app/scripts/controllers/transactions/index.js index 0d06fbc991c6..1ca5f78c02e0 100644 --- a/app/scripts/controllers/transactions/index.js +++ b/app/scripts/controllers/transactions/index.js @@ -53,6 +53,12 @@ import { isEIP1559Transaction, } from '../../../../shared/modules/transaction.utils'; import { ORIGIN_METAMASK } from '../../../../shared/constants/app'; +///: BEGIN:ONLY_INCLUDE_IN(blockaid) +import { + BlockaidReason, + BlockaidResultType, +} from '../../../../shared/constants/security-provider'; +///: END:ONLY_INCLUDE_IN import { calcGasTotal, getSwapsTokensReceivedFromTxMeta, @@ -338,6 +344,7 @@ export default class TransactionController extends EventEmitter { * @param {boolean} opts.swaps.hasApproveTx - Whether this transaction required an approval transaction * @param {boolean} opts.swaps.meta - Additional metadata to store for the transaction * @param {TransactionType} opts.type - Type of transaction to add, such as 'cancel' or 'swap' + * @param {TransactionType} opts.securityAlertResponse - Response from security provider * @returns {Promise<{transactionMeta: TransactionMeta, result: Promise}>} An object containing the transaction metadata, and a promise that resolves to the transaction hash after being submitted to the network */ async addTransaction( @@ -350,6 +357,7 @@ export default class TransactionController extends EventEmitter { sendFlowHistory, swaps: { hasApproveTx, meta } = {}, type, + securityAlertResponse, } = {}, ) { log.debug(`MetaMaskController addTransaction ${JSON.stringify(txParams)}`); @@ -361,6 +369,7 @@ export default class TransactionController extends EventEmitter { sendFlowHistory, swaps: { hasApproveTx, meta }, type, + securityAlertResponse, }); return { @@ -1549,6 +1558,9 @@ export default class TransactionController extends EventEmitter { txParams: normalizedTxParams, origin, sendFlowHistory, + ///: BEGIN:ONLY_INCLUDE_IN(blockaid) + securityAlertResponse: options?.securityAlertResponse, + ///: END:ONLY_INCLUDE_IN }); // Add actionId to txMeta to check if same actionId is seen again @@ -2272,6 +2284,9 @@ export default class TransactionController extends EventEmitter { finalApprovalAmount, contractMethodName, securityProviderResponse, + ///: BEGIN:ONLY_INCLUDE_IN(blockaid) + securityAlertResponse, + ///: END:ONLY_INCLUDE_IN } = txMeta; const source = referrer === ORIGIN_METAMASK ? 'user' : 'dapp'; @@ -2448,6 +2463,12 @@ export default class TransactionController extends EventEmitter { transaction_type: transactionType, transaction_speed_up: type === TransactionType.retry, ui_customizations: uiCustomizations, + ///: BEGIN:ONLY_INCLUDE_IN(blockaid) + security_alert_response: + securityAlertResponse?.result_type ?? BlockaidResultType.NotApplicable, + security_alert_reason: + securityAlertResponse?.reason ?? BlockaidReason.notApplicable, + ///: END:ONLY_INCLUDE_IN }; if (transactionContractMethod === contractMethodNames.APPROVE) { diff --git a/app/scripts/controllers/transactions/index.test.js b/app/scripts/controllers/transactions/index.test.js index 9c1f7a131817..7437311191ac 100644 --- a/app/scripts/controllers/transactions/index.test.js +++ b/app/scripts/controllers/transactions/index.test.js @@ -2163,6 +2163,8 @@ describe('Transaction Controller', function () { device_model: 'N/A', transaction_speed_up: false, ui_customizations: null, + security_alert_reason: 'not_applicable', + security_alert_response: 'not_applicable', }, sensitiveProperties: { default_gas: '0.000031501', @@ -2250,6 +2252,8 @@ describe('Transaction Controller', function () { device_model: 'N/A', transaction_speed_up: false, ui_customizations: null, + security_alert_reason: 'not_applicable', + security_alert_response: 'not_applicable', }, sensitiveProperties: { default_gas: '0.000031501', @@ -2349,6 +2353,8 @@ describe('Transaction Controller', function () { device_model: 'N/A', transaction_speed_up: false, ui_customizations: null, + security_alert_reason: 'not_applicable', + security_alert_response: 'not_applicable', }, sensitiveProperties: { default_gas: '0.000031501', @@ -2438,6 +2444,8 @@ describe('Transaction Controller', function () { device_model: 'N/A', transaction_speed_up: false, ui_customizations: null, + security_alert_reason: 'not_applicable', + security_alert_response: 'not_applicable', }, sensitiveProperties: { default_gas: '0.000031501', @@ -2505,6 +2513,10 @@ describe('Transaction Controller', function () { securityProviderResponse: { flagAsDangerous: 0, }, + securityAlertResponse: { + result_type: 'Benign', + reason: 'none', + }, }; const expectedPayload = { @@ -2529,6 +2541,8 @@ describe('Transaction Controller', function () { device_model: 'N/A', transaction_speed_up: false, ui_customizations: null, + security_alert_response: 'Benign', + security_alert_reason: 'none', }, sensitiveProperties: { gas_price: '2', @@ -2601,6 +2615,8 @@ describe('Transaction Controller', function () { device_model: 'N/A', transaction_speed_up: false, ui_customizations: null, + security_alert_reason: 'not_applicable', + security_alert_response: 'not_applicable', }, sensitiveProperties: { baz: 3.0, @@ -2675,6 +2691,8 @@ describe('Transaction Controller', function () { device_model: 'N/A', transaction_speed_up: false, ui_customizations: ['flagged_as_malicious'], + security_alert_reason: 'not_applicable', + security_alert_response: 'not_applicable', }, sensitiveProperties: { baz: 3.0, @@ -2749,6 +2767,8 @@ describe('Transaction Controller', function () { device_model: 'N/A', transaction_speed_up: false, ui_customizations: ['flagged_as_safety_unknown'], + security_alert_reason: 'not_applicable', + security_alert_response: 'not_applicable', }, sensitiveProperties: { baz: 3.0, @@ -2831,6 +2851,8 @@ describe('Transaction Controller', function () { device_model: 'N/A', transaction_speed_up: false, ui_customizations: null, + security_alert_reason: 'not_applicable', + security_alert_response: 'not_applicable', }, sensitiveProperties: { baz: 3.0, diff --git a/shared/constants/security-provider.ts b/shared/constants/security-provider.ts index b956a8e7529b..94bbd9f06356 100644 --- a/shared/constants/security-provider.ts +++ b/shared/constants/security-provider.ts @@ -46,6 +46,8 @@ export enum BlockaidReason { /** Malicious trade that results in the victim being rained */ unfairTrade = 'unfair_trade', + notApplicable = 'not_applicable', + other = 'other', } @@ -53,6 +55,7 @@ export enum BlockaidResultType { Malicious = 'Malicious', Warning = 'Warning', Benign = 'Benign', + NotApplicable = 'not_applicable', } /**