Skip to content

Commit

Permalink
feat: multichain support in PPOMController (#26966)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpuri authored Sep 6, 2024
1 parent 6deac15 commit 2f1f4d5
Show file tree
Hide file tree
Showing 8 changed files with 31 additions and 76 deletions.
14 changes: 10 additions & 4 deletions app/scripts/lib/ppom/ppom-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export async function validateRequestWithPPOM({

const ppomResponse = isSecurityAlertsAPIEnabled()
? await validateWithAPI(ppomController, chainId, normalizedRequest)
: await validateWithController(ppomController, normalizedRequest);
: await validateWithController(
ppomController,
normalizedRequest,
chainId,
);

return {
...ppomResponse,
Expand Down Expand Up @@ -207,9 +211,11 @@ async function findConfirmationBySecurityAlertId(
async function validateWithController(
ppomController: PPOMController,
request: SecurityAlertsAPIRequest | JsonRpcRequest,
chainId: string,
): Promise<SecurityAlertResponse> {
const response = (await ppomController.usePPOM((ppom: PPOM) =>
ppom.validateJsonRpc(request),
const response = (await ppomController.usePPOM(
(ppom: PPOM) => ppom.validateJsonRpc(request),
chainId,
)) as SecurityAlertResponse;

return {
Expand All @@ -232,6 +238,6 @@ async function validateWithAPI(
};
} catch (error: unknown) {
handlePPOMError(error, `Error validating request with security alerts API`);
return await validateWithController(ppomController, request);
return await validateWithController(ppomController, request, chainId);
}
}
5 changes: 4 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,10 @@ export default class MetamaskController extends EventEmitter {
this.ppomController = new PPOMController({
messenger: this.controllerMessenger.getRestricted({
name: 'PPOMController',
allowedEvents: ['NetworkController:stateChange'],
allowedEvents: [
'NetworkController:stateChange',
'NetworkController:networkDidChange',
],
allowedActions: ['NetworkController:getNetworkClientById'],
}),
storageBackend: new IndexedDBPPOMStorage('PPOMDB', 1),
Expand Down
11 changes: 2 additions & 9 deletions lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2098,23 +2098,16 @@
"crypto": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/eth-query>json-rpc-random-id": true,
"@metamask/ppom-validator>@metamask/base-controller": true,
"@metamask/ppom-validator>@metamask/controller-utils": true,
"@metamask/ppom-validator>crypto-js": true,
"@metamask/ppom-validator>elliptic": true,
"@metamask/rpc-errors": true,
"await-semaphore": true,
"browserify>buffer": true
}
},
"@metamask/ppom-validator>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/ppom-validator>@metamask/controller-utils": {
"globals": {
"URL": true,
Expand Down
11 changes: 2 additions & 9 deletions lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2098,23 +2098,16 @@
"crypto": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/eth-query>json-rpc-random-id": true,
"@metamask/ppom-validator>@metamask/base-controller": true,
"@metamask/ppom-validator>@metamask/controller-utils": true,
"@metamask/ppom-validator>crypto-js": true,
"@metamask/ppom-validator>elliptic": true,
"@metamask/rpc-errors": true,
"await-semaphore": true,
"browserify>buffer": true
}
},
"@metamask/ppom-validator>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/ppom-validator>@metamask/controller-utils": {
"globals": {
"URL": true,
Expand Down
11 changes: 2 additions & 9 deletions lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2098,23 +2098,16 @@
"crypto": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/eth-query>json-rpc-random-id": true,
"@metamask/ppom-validator>@metamask/base-controller": true,
"@metamask/ppom-validator>@metamask/controller-utils": true,
"@metamask/ppom-validator>crypto-js": true,
"@metamask/ppom-validator>elliptic": true,
"@metamask/rpc-errors": true,
"await-semaphore": true,
"browserify>buffer": true
}
},
"@metamask/ppom-validator>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/ppom-validator>@metamask/controller-utils": {
"globals": {
"URL": true,
Expand Down
11 changes: 2 additions & 9 deletions lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -2190,23 +2190,16 @@
"crypto": true
},
"packages": {
"@metamask/base-controller": true,
"@metamask/eth-query>json-rpc-random-id": true,
"@metamask/ppom-validator>@metamask/base-controller": true,
"@metamask/ppom-validator>@metamask/controller-utils": true,
"@metamask/ppom-validator>crypto-js": true,
"@metamask/ppom-validator>elliptic": true,
"@metamask/rpc-errors": true,
"await-semaphore": true,
"browserify>buffer": true
}
},
"@metamask/ppom-validator>@metamask/base-controller": {
"globals": {
"setTimeout": true
},
"packages": {
"immer": true
}
},
"@metamask/ppom-validator>@metamask/controller-utils": {
"globals": {
"URL": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@
"@metamask/permission-log-controller": "^2.0.1",
"@metamask/phishing-controller": "^12.0.1",
"@metamask/post-message-stream": "^8.0.0",
"@metamask/ppom-validator": "patch:@metamask/ppom-validator@npm%3A0.32.0#~/.yarn/patches/@metamask-ppom-validator-npm-0.32.0-f677deea54.patch",
"@metamask/ppom-validator": "0.34.0",
"@metamask/profile-sync-controller": "^0.2.1",
"@metamask/providers": "^14.0.2",
"@metamask/queued-request-controller": "^2.0.0",
Expand Down
42 changes: 8 additions & 34 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4871,16 +4871,6 @@ __metadata:
languageName: node
linkType: hard

"@metamask/base-controller@npm:^3.0.0":
version: 3.2.3
resolution: "@metamask/base-controller@npm:3.2.3"
dependencies:
"@metamask/utils": "npm:^8.1.0"
immer: "npm:^9.0.6"
checksum: 10/1a3005f4143f0a3e37094ce389ae9c2010194672d67c1b115a401379c1b712fb3d7ce8f1cbc8a4d21cffba61aafba6dc1aaae12172e57b9f14021a2505fadafe
languageName: node
linkType: hard

"@metamask/base-controller@npm:^5.0.1":
version: 5.0.2
resolution: "@metamask/base-controller@npm:5.0.2"
Expand Down Expand Up @@ -5996,37 +5986,21 @@ __metadata:
languageName: node
linkType: hard

"@metamask/ppom-validator@npm:0.32.0":
version: 0.32.0
resolution: "@metamask/ppom-validator@npm:0.32.0"
"@metamask/ppom-validator@npm:0.34.0":
version: 0.34.0
resolution: "@metamask/ppom-validator@npm:0.34.0"
dependencies:
"@metamask/base-controller": "npm:^3.0.0"
"@metamask/controller-utils": "npm:^8.0.1"
"@metamask/network-controller": "npm:^17.0.0"
"@metamask/utils": "npm:^8.3.0"
await-semaphore: "npm:^0.1.3"
crypto-js: "npm:^4.2.0"
elliptic: "npm:^6.5.4"
eslint-plugin-n: "npm:^16.6.2"
json-rpc-random-id: "npm:^1.0.1"
checksum: 10/6b88fc9b5dc4ddcff88c15aed96994f93a95c350ae522115415d44aa38da981bdbdee56c7889cb44992a08eff4bcaf6198516961d3a69ec3d7a83c8014748496
languageName: node
linkType: hard

"@metamask/ppom-validator@patch:@metamask/ppom-validator@npm%3A0.32.0#~/.yarn/patches/@metamask-ppom-validator-npm-0.32.0-f677deea54.patch":
version: 0.32.0
resolution: "@metamask/ppom-validator@patch:@metamask/ppom-validator@npm%3A0.32.0#~/.yarn/patches/@metamask-ppom-validator-npm-0.32.0-f677deea54.patch::version=0.32.0&hash=e59920"
dependencies:
"@metamask/base-controller": "npm:^3.0.0"
"@metamask/base-controller": "npm:^6.0.2"
"@metamask/controller-utils": "npm:^8.0.1"
"@metamask/network-controller": "npm:^17.0.0"
"@metamask/network-controller": "npm:^20.0.0"
"@metamask/rpc-errors": "npm:^6.3.1"
"@metamask/utils": "npm:^8.3.0"
await-semaphore: "npm:^0.1.3"
crypto-js: "npm:^4.2.0"
elliptic: "npm:^6.5.4"
eslint-plugin-n: "npm:^16.6.2"
json-rpc-random-id: "npm:^1.0.1"
checksum: 10/87d74699a7d05bca3fb9e09a60f60738511b045aa231d82eeadf838f531b5a147bd8819caad46d24b588eed940e342c67b87e3ce7840553753ef2e281d45cc8f
checksum: 10/140b2070ddf4a9d7d13518ab1a10aa71961715434053096d0caa6f4ce104bbcaea5f5152edfa9b6c42f9bc929116afbb6a0542c1147e3101d04ef29bcf7a6c9f
languageName: node
linkType: hard

Expand Down Expand Up @@ -26174,7 +26148,7 @@ __metadata:
"@metamask/phishing-controller": "npm:^12.0.1"
"@metamask/phishing-warning": "npm:^4.0.0"
"@metamask/post-message-stream": "npm:^8.0.0"
"@metamask/ppom-validator": "patch:@metamask/ppom-validator@npm%3A0.32.0#~/.yarn/patches/@metamask-ppom-validator-npm-0.32.0-f677deea54.patch"
"@metamask/ppom-validator": "npm:0.34.0"
"@metamask/profile-sync-controller": "npm:^0.2.1"
"@metamask/providers": "npm:^14.0.2"
"@metamask/queued-request-controller": "npm:^2.0.0"
Expand Down

0 comments on commit 2f1f4d5

Please sign in to comment.