Skip to content

Commit

Permalink
Integrating ppom update tool into mobile build (#7363)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Oct 24, 2023
1 parent 03bf584 commit c8e30cd
Show file tree
Hide file tree
Showing 32 changed files with 10,817 additions and 53 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ CHANGELOG.md
wdio
/app/util/test/testSetup.js
/app/lib/ppom/ppom.html.js
/ppom
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ module.exports = {
'import/no-amd': 2,
'import/no-commonjs': 2,
'import/no-duplicates': 2,
'import/no-extraneous-dependencies': 2,
'import/no-extraneous-dependencies': ['error', { packageDir: ['./'] }],
'import/no-mutable-exports': 2,
'import/no-namespace': 2,
'import/no-nodejs-modules': 2,
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,7 @@ browserstack.err

# Reports generated by tests
e2e/reports

# ppom
ppom/node_modules
ppom/dist
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const REASON_DESCRIPTION_I18N_KEY_MAP: { [Reason: string]: string } =
[Reason.transferFarming]: 'blockaid_banner.transfer_farming_description',
[Reason.transferFromFarming]:
'blockaid_banner.transfer_farming_description',
[Reason.notApplicable]: 'blockaid_banner.not_applicable',
});

export const REASON_TITLE_I18N_KEY_MAP: Record<string, string> = Object.freeze({
Expand Down
14 changes: 7 additions & 7 deletions app/components/UI/BlockaidBanner/BlockaidBanner.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('BlockaidBanner', () => {
const wrapper = render(
<BlockaidBanner
securityAlertResponse={{
resultType: ResultType.Warning,
result_type: ResultType.Warning,
reason: Reason.approvalFarming,
features: mockFeatures,
}}
Expand All @@ -43,7 +43,7 @@ describe('BlockaidBanner', () => {
const wrapper = render(
<BlockaidBanner
securityAlertResponse={{
resultType: ResultType.Malicious,
result_type: ResultType.Malicious,
reason: Reason.rawSignatureFarming,
features: mockFeatures,
}}
Expand All @@ -66,7 +66,7 @@ describe('BlockaidBanner', () => {
const wrapper = render(
<BlockaidBanner
securityAlertResponse={{
resultType: ResultType.Malicious,
result_type: ResultType.Malicious,
reason: Reason.rawSignatureFarming,
features: mockFeatures,
}}
Expand All @@ -80,7 +80,7 @@ describe('BlockaidBanner', () => {
const wrapper = render(
<BlockaidBanner
securityAlertResponse={{
resultType: ResultType.Malicious,
result_type: ResultType.Malicious,
reason: Reason.approvalFarming,
features: mockFeatures,
}}
Expand Down Expand Up @@ -119,7 +119,7 @@ describe('BlockaidBanner', () => {
const wrapper = render(
<BlockaidBanner
securityAlertResponse={{
resultType: ResultType.Malicious,
result_type: ResultType.Malicious,
reason: Reason.approvalFarming,
features: mockFeatures,
}}
Expand Down Expand Up @@ -153,7 +153,7 @@ describe('BlockaidBanner', () => {
const wrapper = render(
<BlockaidBanner
securityAlertResponse={{
resultType: ResultType.Benign,
result_type: ResultType.Benign,
reason: Reason.rawSignatureFarming,
features: mockFeatures,
}}
Expand All @@ -169,7 +169,7 @@ describe('BlockaidBanner', () => {
const wrapper = render(
<BlockaidBanner
securityAlertResponse={{
resultType: ResultType.Failed,
result_type: ResultType.Failed,
reason: Reason.rawSignatureFarming,
features: mockFeatures,
}}
Expand Down
8 changes: 4 additions & 4 deletions app/components/UI/BlockaidBanner/BlockaidBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ const BlockaidBanner = (bannerProps: BlockaidBannerProps) => {
return null;
}

const { resultType, reason, features } = securityAlertResponse;
const { result_type, reason, features } = securityAlertResponse;

if (resultType === ResultType.Benign) {
if (result_type === ResultType.Benign) {
return null;
}

const title = getTitle(reason);
const description = getDescription(reason);

if (resultType === ResultType.Failed) {
if (result_type === ResultType.Failed) {
return (
<BannerAlert
severity={BannerAlertSeverity.Warning}
Expand Down Expand Up @@ -122,7 +122,7 @@ const BlockaidBanner = (bannerProps: BlockaidBannerProps) => {
return (
<BannerAlert
severity={
resultType === ResultType.Malicious
result_type === ResultType.Malicious
? BannerAlertSeverity.Error
: BannerAlertSeverity.Warning
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/UI/BlockaidBanner/BlockaidBanner.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export enum ResultType {
export interface SecurityAlertResponse {
reason: Reason;
features: string[];
resultType: ResultType;
result_type: ResultType;
providerRequestsCount?: Record<string, number>;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ exports[`BlockaidBanner should render correctly 1`] = `
"Operator is untrusted according to previous activity",
],
"reason": "approval_farming",
"resultType": "Warning",
"result_type": "Warning",
}
}
style={
Expand Down Expand Up @@ -256,7 +256,7 @@ exports[`BlockaidBanner should render correctly with list attack details 1`] = `
"Operator is untrusted according to previous activity",
],
"reason": "approval_farming",
"resultType": "Malicious",
"result_type": "Malicious",
}
}
style={
Expand Down Expand Up @@ -496,7 +496,7 @@ exports[`BlockaidBanner should render correctly with reason "raw_signature_farmi
"Operator is untrusted according to previous activity",
],
"reason": "raw_signature_farming",
"resultType": "Malicious",
"result_type": "Malicious",
}
}
style={
Expand Down Expand Up @@ -812,7 +812,7 @@ exports[`BlockaidBanner should render something does not look right with contact
"Operator is untrusted according to previous activity",
],
"reason": "approval_farming",
"resultType": "Malicious",
"result_type": "Malicious",
}
}
style={
Expand Down
6 changes: 3 additions & 3 deletions app/components/UI/TransactionReview/index.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ describe('TransactionReview', () => {

it('should display blockaid banner', async () => {
const securityAlertResponse = {
resultType: 'Malicious',
result_type: 'Malicious',
reason: 'blur_farming',
providerRequestsCount: {},
};
Expand All @@ -141,8 +141,8 @@ describe('TransactionReview', () => {

const blockaidMetricsParamsSpy = jest
.spyOn(BlockaidUtils, 'getBlockaidMetricsParams')
.mockImplementation(({ resultType, reason, providerRequestsCount }) => ({
security_alert_response: resultType,
.mockImplementation(({ result_type, reason, providerRequestsCount }) => ({
security_alert_response: result_type,
security_alert_reason: reason,
security_alert_provider_requests_count: providerRequestsCount,
}));
Expand Down
3 changes: 1 addition & 2 deletions app/core/Engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,8 +681,7 @@ class Engine {
listener,
),
onPreferencesChange: () => undefined,
provider: () =>
networkController.getProviderAndBlockTracker().provider,
provider: networkController.getProviderAndBlockTracker().provider,
ppomProvider: {
PPOM,
ppomInit,
Expand Down
4 changes: 3 additions & 1 deletion app/lib/ppom/PPOMView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { WebView } from 'react-native-webview';

import Logger from '../../util/Logger.js';
import asyncInvoke from './invoke-lib';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import { html } from './ppom.html.js';

const styles = StyleSheet.create({
Expand All @@ -26,7 +28,7 @@ const convertFilesToBase64 = (files: any[][]) =>
});

class PPOMInner {
_new = invoke.bind('PPOM.new');
_new = invoke.bindAsync('PPOM.new');
_free = invoke.bind('PPOM.free');
_test = invoke.bindAsync('PPOM.test');
_validateJsonRpc = invoke.bindAsync('PPOM.validateJsonRpc');
Expand Down
2 changes: 1 addition & 1 deletion app/lib/ppom/invoke-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default (invoke: any) => {

invoke.define(`${name}_trigger`, ({ id, args }: any) => {
func(...args)
.then((...args1: any[]) => resolveCallback({ id, args1 }))
.then((...args2: any[]) => resolveCallback({ id, args: args2 }))
.catch((e: Error) => rejectCallback({ id, error: serializeError(e) }));
});
};
Expand Down
16 changes: 1 addition & 15 deletions app/lib/ppom/ppom.html.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions app/util/blockaid/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('getBlockaidMetricsParams', () => {

it('should return additionalParams object when securityAlertResponse defined', () => {
const securityAlertResponse: SecurityAlertResponse = {
resultType: ResultType.Malicious,
result_type: ResultType.Malicious,
reason: Reason.notApplicable,
providerRequestsCount: {
eth_call: 5,
Expand All @@ -34,7 +34,7 @@ describe('getBlockaidMetricsParams', () => {

it('should not return eth call counts if providerRequestsCount is empty', () => {
const securityAlertResponse: SecurityAlertResponse = {
resultType: ResultType.Malicious,
result_type: ResultType.Malicious,
reason: Reason.notApplicable,
features: [],
providerRequestsCount: {},
Expand All @@ -50,7 +50,7 @@ describe('getBlockaidMetricsParams', () => {

it('should not return eth call counts if providerRequestsCount is undefined', () => {
const securityAlertResponse: SecurityAlertResponse = {
resultType: ResultType.Malicious,
result_type: ResultType.Malicious,
reason: Reason.notApplicable,
features: [],
providerRequestsCount: undefined,
Expand Down
9 changes: 5 additions & 4 deletions app/util/blockaid/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ export const getBlockaidMetricsParams = (
const additionalParams: Record<string, any> = {};

if (securityAlertResponse && isBlockaidFeatureEnabled()) {
const { resultType, reason, providerRequestsCount } = securityAlertResponse;
const { result_type, reason, providerRequestsCount } =
securityAlertResponse;

if (resultType === ResultType.Malicious) {
if (result_type === ResultType.Malicious) {
additionalParams.ui_customizations = ['flagged_as_malicious'];
}

if (resultType !== ResultType.Benign) {
if (result_type !== ResultType.Benign) {
additionalParams.security_alert_reason = Reason.notApplicable;

if (reason) {
additionalParams.security_alert_response = resultType;
additionalParams.security_alert_response = result_type;
additionalParams.security_alert_reason = reason;
}
}
Expand Down
3 changes: 2 additions & 1 deletion app/util/test/initial-background-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"chainStatus": {
"0x1": {
"chainId": "0x1",
"dataFetched": false
"dataFetched": false,
"versionInfo": []
}
},
"storageMetadata": [],
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"lint:fix": "eslint '**/*.{js,ts,tsx}' --fix",
"lint:tsc": "tsc --project ./tsconfig.lint.json",
"format": "prettier '**/*.{js,ts,tsx,json,feature}' --write",
"setup": "yarn clean && yarn pod:install && yarn allow-scripts && ./scripts/postinstall.sh",
"setup": "yarn clean && yarn pod:install && yarn allow-scripts && ./scripts/build_ppom.sh && ./scripts/postinstall.sh",
"setup:node": "yarn clean:node && yarn allow-scripts && yarn patch-package",
"setup:e2e": "cd wdio && yarn install",
"start:ios": "./scripts/build.sh ios debug",
Expand Down Expand Up @@ -175,7 +175,7 @@
"@metamask/network-controller": "^8.0.0",
"@metamask/permission-controller": "^4.0.1",
"@metamask/phishing-controller": "^3.0.0",
"@metamask/ppom-validator": "^0.5.0",
"@metamask/ppom-validator": "^0.7.0",
"@metamask/preferences-controller": "^3.0.0",
"@metamask/scure-bip39": "^2.1.0",
"@metamask/sdk-communication-layer": "^0.7.0",
Expand Down
2 changes: 2 additions & 0 deletions ppom/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/webpack.config.html-js.js
/webpack.config.html.js
Loading

0 comments on commit c8e30cd

Please sign in to comment.