mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-11-22 01:47:00 +01:00
Adding metrics events for blockaid (#20091)
This commit is contained in:
parent
2b5c112a02
commit
4e52fe2494
@ -56,6 +56,12 @@ import {
|
|||||||
isEIP1559Transaction,
|
isEIP1559Transaction,
|
||||||
} from '../../../../shared/modules/transaction.utils';
|
} from '../../../../shared/modules/transaction.utils';
|
||||||
import { ORIGIN_METAMASK } from '../../../../shared/constants/app';
|
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 {
|
import {
|
||||||
calcGasTotal,
|
calcGasTotal,
|
||||||
getSwapsTokensReceivedFromTxMeta,
|
getSwapsTokensReceivedFromTxMeta,
|
||||||
@ -327,6 +333,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
this.txStateManager.wipeTransactions(address);
|
this.txStateManager.wipeTransactions(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* eslint-disable jsdoc/require-param, jsdoc/check-param-names */
|
||||||
/**
|
/**
|
||||||
* Add a new unapproved transaction
|
* Add a new unapproved transaction
|
||||||
*
|
*
|
||||||
@ -342,7 +349,7 @@ export default class TransactionController extends EventEmitter {
|
|||||||
* @param {boolean} opts.swaps.meta - Additional metadata to store for the 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.type - Type of transaction to add, such as 'cancel' or 'swap'
|
||||||
* @returns {Promise<{transactionMeta: TransactionMeta, result: Promise<string>}>} An object containing the transaction metadata, and a promise that resolves to the transaction hash after being submitted to the network
|
* @returns {Promise<{transactionMeta: TransactionMeta, result: Promise<string>}>} An object containing the transaction metadata, and a promise that resolves to the transaction hash after being submitted to the network
|
||||||
*/
|
*/ /* eslint-enable jsdoc/require-param, jsdoc/check-param-names */
|
||||||
async addTransaction(
|
async addTransaction(
|
||||||
txParams,
|
txParams,
|
||||||
{
|
{
|
||||||
@ -353,6 +360,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
sendFlowHistory,
|
sendFlowHistory,
|
||||||
swaps: { hasApproveTx, meta } = {},
|
swaps: { hasApproveTx, meta } = {},
|
||||||
type,
|
type,
|
||||||
|
///: BEGIN:ONLY_INCLUDE_IN(blockaid)
|
||||||
|
securityAlertResponse,
|
||||||
|
///: END:ONLY_INCLUDE_IN
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
log.debug(`MetaMaskController addTransaction ${JSON.stringify(txParams)}`);
|
log.debug(`MetaMaskController addTransaction ${JSON.stringify(txParams)}`);
|
||||||
@ -364,6 +374,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
sendFlowHistory,
|
sendFlowHistory,
|
||||||
swaps: { hasApproveTx, meta },
|
swaps: { hasApproveTx, meta },
|
||||||
type,
|
type,
|
||||||
|
///: BEGIN:ONLY_INCLUDE_IN(blockaid)
|
||||||
|
securityAlertResponse,
|
||||||
|
///: END:ONLY_INCLUDE_IN
|
||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@ -1469,7 +1482,17 @@ export default class TransactionController extends EventEmitter {
|
|||||||
|
|
||||||
async _createTransaction(
|
async _createTransaction(
|
||||||
txParams,
|
txParams,
|
||||||
{ actionId, method, origin, sendFlowHistory = [], swaps, type },
|
{
|
||||||
|
actionId,
|
||||||
|
method,
|
||||||
|
origin,
|
||||||
|
sendFlowHistory = [],
|
||||||
|
swaps,
|
||||||
|
type,
|
||||||
|
///: BEGIN:ONLY_INCLUDE_IN(blockaid)
|
||||||
|
securityAlertResponse,
|
||||||
|
///: END:ONLY_INCLUDE_IN
|
||||||
|
},
|
||||||
) {
|
) {
|
||||||
if (
|
if (
|
||||||
type !== undefined &&
|
type !== undefined &&
|
||||||
@ -1504,6 +1527,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
txParams: normalizedTxParams,
|
txParams: normalizedTxParams,
|
||||||
origin,
|
origin,
|
||||||
sendFlowHistory,
|
sendFlowHistory,
|
||||||
|
///: BEGIN:ONLY_INCLUDE_IN(blockaid)
|
||||||
|
securityAlertResponse,
|
||||||
|
///: END:ONLY_INCLUDE_IN
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add actionId to txMeta to check if same actionId is seen again
|
// Add actionId to txMeta to check if same actionId is seen again
|
||||||
@ -2233,6 +2259,9 @@ export default class TransactionController extends EventEmitter {
|
|||||||
finalApprovalAmount,
|
finalApprovalAmount,
|
||||||
contractMethodName,
|
contractMethodName,
|
||||||
securityProviderResponse,
|
securityProviderResponse,
|
||||||
|
///: BEGIN:ONLY_INCLUDE_IN(blockaid)
|
||||||
|
securityAlertResponse,
|
||||||
|
///: END:ONLY_INCLUDE_IN
|
||||||
} = txMeta;
|
} = txMeta;
|
||||||
|
|
||||||
const source = referrer === ORIGIN_METAMASK ? 'user' : 'dapp';
|
const source = referrer === ORIGIN_METAMASK ? 'user' : 'dapp';
|
||||||
@ -2411,6 +2440,12 @@ export default class TransactionController extends EventEmitter {
|
|||||||
transaction_type: transactionType,
|
transaction_type: transactionType,
|
||||||
transaction_speed_up: type === TransactionType.retry,
|
transaction_speed_up: type === TransactionType.retry,
|
||||||
ui_customizations: uiCustomizations,
|
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) {
|
if (transactionContractMethod === contractMethodNames.APPROVE) {
|
||||||
|
@ -8,6 +8,10 @@ import { ApprovalType } from '@metamask/controller-utils';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
|
|
||||||
import { errorCodes, ethErrors } from 'eth-rpc-errors';
|
import { errorCodes, ethErrors } from 'eth-rpc-errors';
|
||||||
|
import {
|
||||||
|
BlockaidReason,
|
||||||
|
BlockaidResultType,
|
||||||
|
} from '../../../../shared/constants/security-provider';
|
||||||
import {
|
import {
|
||||||
createTestProviderTools,
|
createTestProviderTools,
|
||||||
getTestAccounts,
|
getTestAccounts,
|
||||||
@ -2163,6 +2167,8 @@ describe('Transaction Controller', function () {
|
|||||||
device_model: 'N/A',
|
device_model: 'N/A',
|
||||||
transaction_speed_up: false,
|
transaction_speed_up: false,
|
||||||
ui_customizations: null,
|
ui_customizations: null,
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
},
|
},
|
||||||
sensitiveProperties: {
|
sensitiveProperties: {
|
||||||
@ -2250,6 +2256,8 @@ describe('Transaction Controller', function () {
|
|||||||
device_model: 'N/A',
|
device_model: 'N/A',
|
||||||
transaction_speed_up: false,
|
transaction_speed_up: false,
|
||||||
ui_customizations: null,
|
ui_customizations: null,
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
},
|
},
|
||||||
sensitiveProperties: {
|
sensitiveProperties: {
|
||||||
@ -2349,6 +2357,8 @@ describe('Transaction Controller', function () {
|
|||||||
device_model: 'N/A',
|
device_model: 'N/A',
|
||||||
transaction_speed_up: false,
|
transaction_speed_up: false,
|
||||||
ui_customizations: null,
|
ui_customizations: null,
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
},
|
},
|
||||||
sensitiveProperties: {
|
sensitiveProperties: {
|
||||||
@ -2438,6 +2448,8 @@ describe('Transaction Controller', function () {
|
|||||||
device_model: 'N/A',
|
device_model: 'N/A',
|
||||||
transaction_speed_up: false,
|
transaction_speed_up: false,
|
||||||
ui_customizations: null,
|
ui_customizations: null,
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
},
|
},
|
||||||
sensitiveProperties: {
|
sensitiveProperties: {
|
||||||
@ -2505,6 +2517,10 @@ describe('Transaction Controller', function () {
|
|||||||
securityProviderResponse: {
|
securityProviderResponse: {
|
||||||
flagAsDangerous: 0,
|
flagAsDangerous: 0,
|
||||||
},
|
},
|
||||||
|
securityAlertResponse: {
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedPayload = {
|
const expectedPayload = {
|
||||||
@ -2529,6 +2545,8 @@ describe('Transaction Controller', function () {
|
|||||||
device_model: 'N/A',
|
device_model: 'N/A',
|
||||||
transaction_speed_up: false,
|
transaction_speed_up: false,
|
||||||
ui_customizations: null,
|
ui_customizations: null,
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
},
|
},
|
||||||
sensitiveProperties: {
|
sensitiveProperties: {
|
||||||
@ -2601,6 +2619,8 @@ describe('Transaction Controller', function () {
|
|||||||
device_model: 'N/A',
|
device_model: 'N/A',
|
||||||
transaction_speed_up: false,
|
transaction_speed_up: false,
|
||||||
ui_customizations: null,
|
ui_customizations: null,
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
},
|
},
|
||||||
sensitiveProperties: {
|
sensitiveProperties: {
|
||||||
@ -2675,6 +2695,8 @@ describe('Transaction Controller', function () {
|
|||||||
device_model: 'N/A',
|
device_model: 'N/A',
|
||||||
transaction_speed_up: false,
|
transaction_speed_up: false,
|
||||||
ui_customizations: ['flagged_as_malicious'],
|
ui_customizations: ['flagged_as_malicious'],
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
},
|
},
|
||||||
sensitiveProperties: {
|
sensitiveProperties: {
|
||||||
@ -2749,6 +2771,8 @@ describe('Transaction Controller', function () {
|
|||||||
device_model: 'N/A',
|
device_model: 'N/A',
|
||||||
transaction_speed_up: false,
|
transaction_speed_up: false,
|
||||||
ui_customizations: ['flagged_as_safety_unknown'],
|
ui_customizations: ['flagged_as_safety_unknown'],
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
},
|
},
|
||||||
sensitiveProperties: {
|
sensitiveProperties: {
|
||||||
@ -2831,6 +2855,8 @@ describe('Transaction Controller', function () {
|
|||||||
device_model: 'N/A',
|
device_model: 'N/A',
|
||||||
transaction_speed_up: false,
|
transaction_speed_up: false,
|
||||||
ui_customizations: null,
|
ui_customizations: null,
|
||||||
|
security_alert_reason: BlockaidReason.notApplicable,
|
||||||
|
security_alert_response: BlockaidResultType.NotApplicable,
|
||||||
status: 'unapproved',
|
status: 'unapproved',
|
||||||
},
|
},
|
||||||
sensitiveProperties: {
|
sensitiveProperties: {
|
||||||
|
@ -3595,6 +3595,9 @@ export default class MetamaskController extends EventEmitter {
|
|||||||
origin: req.origin,
|
origin: req.origin,
|
||||||
// This is the default behaviour but specified here for clarity
|
// This is the default behaviour but specified here for clarity
|
||||||
requireApproval: true,
|
requireApproval: true,
|
||||||
|
///: BEGIN:ONLY_INCLUDE_IN(blockaid)
|
||||||
|
securityAlertResponse: req.securityAlertResponse,
|
||||||
|
///: END:ONLY_INCLUDE_IN
|
||||||
});
|
});
|
||||||
|
|
||||||
return await result;
|
return await result;
|
||||||
|
@ -47,12 +47,17 @@ export enum BlockaidReason {
|
|||||||
unfairTrade = 'unfair_trade',
|
unfairTrade = 'unfair_trade',
|
||||||
|
|
||||||
other = 'other',
|
other = 'other',
|
||||||
|
|
||||||
|
// Locally defined
|
||||||
|
notApplicable = 'NotApplicable',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum BlockaidResultType {
|
export enum BlockaidResultType {
|
||||||
Malicious = 'Malicious',
|
Malicious = 'Malicious',
|
||||||
Warning = 'Warning',
|
Warning = 'Warning',
|
||||||
Benign = 'Benign',
|
Benign = 'Benign',
|
||||||
|
// Locally defined
|
||||||
|
NotApplicable = 'NotApplicable',
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user