Skip to content

Commit

Permalink
Merge branch 'main' into caip25-permission-migration
Browse files Browse the repository at this point in the history
  • Loading branch information
jiexi committed Dec 20, 2024
2 parents 352f964 + 547b264 commit 9657527
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 18 deletions.
24 changes: 24 additions & 0 deletions app/scripts/lib/createMainFrameOriginMiddleware.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Request and responses are currently untyped.
/* eslint-disable @typescript-eslint/no-explicit-any */

/**
* Returns a middleware that appends the mainFrameOrigin to request
*
* @param {{ mainFrameOrigin: string }} opts - The middleware options
* @returns {Function}
*/

export default function createMainFrameOriginMiddleware({
mainFrameOrigin,
}: {
mainFrameOrigin: string;
}) {
return function mainFrameOriginMiddleware(
req: any,
_res: any,
next: () => void,
) {
req.mainFrameOrigin = mainFrameOrigin;
next();
};
}
22 changes: 21 additions & 1 deletion app/scripts/metamask-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ import {
createUnsupportedMethodMiddleware,
} from './lib/rpc-method-middleware';
import createOriginMiddleware from './lib/createOriginMiddleware';
import createMainFrameOriginMiddleware from './lib/createMainFrameOriginMiddleware';
import createTabIdMiddleware from './lib/createTabIdMiddleware';
import { NetworkOrderController } from './controllers/network-order';
import { AccountOrderController } from './controllers/account-order';
Expand Down Expand Up @@ -6071,11 +6072,18 @@ export default class MetamaskController extends EventEmitter {
tabId = sender.tab.id;
}

let mainFrameOrigin = origin;
if (sender.tab && sender.tab.url) {
// If sender origin is an iframe, then get the top-level frame's origin
mainFrameOrigin = new URL(sender.tab.url).origin;
}

const engine = this.setupProviderEngineEip1193({
origin,
sender,
subjectType,
tabId,
mainFrameOrigin,
});

const dupeReqFilterStream = createDupeReqFilterStream();
Expand Down Expand Up @@ -6196,13 +6204,25 @@ export default class MetamaskController extends EventEmitter {
* @param {MessageSender | SnapSender} options.sender - The sender object.
* @param {string} options.subjectType - The type of the sender subject.
* @param {tabId} [options.tabId] - The tab ID of the sender - if the sender is within a tab
* @param {mainFrameOrigin} [options.mainFrameOrigin] - The origin of the main frame if the sender is an iframe
*/
setupProviderEngineEip1193({ origin, subjectType, sender, tabId }) {
setupProviderEngineEip1193({
origin,
subjectType,
sender,
tabId,
mainFrameOrigin,
}) {
const engine = new JsonRpcEngine();

// Append origin to each request
engine.push(createOriginMiddleware({ origin }));

// Append mainFrameOrigin to each request if present
if (mainFrameOrigin) {
engine.push(createMainFrameOriginMiddleware({ mainFrameOrigin }));
}

// Append selectedNetworkClientId to each request
engine.push(createSelectedNetworkMiddleware(this.controllerMessenger));

Expand Down
17 changes: 16 additions & 1 deletion lavamoat/browserify/beta/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@
"@metamask/network-controller": true,
"@metamask/transaction-controller>@metamask/nonce-tracker": true,
"@metamask/rpc-errors": true,
"@metamask/utils": true,
"@metamask/transaction-controller>@metamask/utils": true,
"@metamask/name-controller>async-mutex": true,
"bn.js": true,
"browserify>buffer": true,
Expand Down Expand Up @@ -2266,6 +2266,21 @@
"semver": true
}
},
"@metamask/transaction-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@noble/hashes": true,
"@metamask/utils>@scure/base": true,
"browserify>buffer": true,
"nock>debug": true,
"@metamask/utils>pony-cause": true,
"semver": true
}
},
"@ngraveio/bc-ur": {
"packages": {
"@ngraveio/bc-ur>@keystonehq/alias-sampling": true,
Expand Down
17 changes: 16 additions & 1 deletion lavamoat/browserify/flask/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@
"@metamask/network-controller": true,
"@metamask/transaction-controller>@metamask/nonce-tracker": true,
"@metamask/rpc-errors": true,
"@metamask/utils": true,
"@metamask/transaction-controller>@metamask/utils": true,
"@metamask/name-controller>async-mutex": true,
"bn.js": true,
"browserify>buffer": true,
Expand Down Expand Up @@ -2266,6 +2266,21 @@
"semver": true
}
},
"@metamask/transaction-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@noble/hashes": true,
"@metamask/utils>@scure/base": true,
"browserify>buffer": true,
"nock>debug": true,
"@metamask/utils>pony-cause": true,
"semver": true
}
},
"@ngraveio/bc-ur": {
"packages": {
"@ngraveio/bc-ur>@keystonehq/alias-sampling": true,
Expand Down
17 changes: 16 additions & 1 deletion lavamoat/browserify/main/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1845,7 +1845,7 @@
"@metamask/network-controller": true,
"@metamask/transaction-controller>@metamask/nonce-tracker": true,
"@metamask/rpc-errors": true,
"@metamask/utils": true,
"@metamask/transaction-controller>@metamask/utils": true,
"@metamask/name-controller>async-mutex": true,
"bn.js": true,
"browserify>buffer": true,
Expand Down Expand Up @@ -2266,6 +2266,21 @@
"semver": true
}
},
"@metamask/transaction-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@noble/hashes": true,
"@metamask/utils>@scure/base": true,
"browserify>buffer": true,
"nock>debug": true,
"@metamask/utils>pony-cause": true,
"semver": true
}
},
"@ngraveio/bc-ur": {
"packages": {
"@ngraveio/bc-ur>@keystonehq/alias-sampling": true,
Expand Down
17 changes: 16 additions & 1 deletion lavamoat/browserify/mmi/policy.json
Original file line number Diff line number Diff line change
Expand Up @@ -1937,7 +1937,7 @@
"@metamask/network-controller": true,
"@metamask/transaction-controller>@metamask/nonce-tracker": true,
"@metamask/rpc-errors": true,
"@metamask/utils": true,
"@metamask/transaction-controller>@metamask/utils": true,
"@metamask/name-controller>async-mutex": true,
"bn.js": true,
"browserify>buffer": true,
Expand Down Expand Up @@ -2358,6 +2358,21 @@
"semver": true
}
},
"@metamask/transaction-controller>@metamask/utils": {
"globals": {
"TextDecoder": true,
"TextEncoder": true
},
"packages": {
"@metamask/utils>@metamask/superstruct": true,
"@noble/hashes": true,
"@metamask/utils>@scure/base": true,
"browserify>buffer": true,
"nock>debug": true,
"@metamask/utils>pony-cause": true,
"semver": true
}
},
"@ngraveio/bc-ur": {
"packages": {
"@ngraveio/bc-ur>@keystonehq/alias-sampling": true,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@
"@metamask/snaps-sdk": "^6.14.0",
"@metamask/snaps-utils": "^8.7.0",
"@metamask/solana-wallet-snap": "^1.0.4",
"@metamask/transaction-controller": "^42.0.0",
"@metamask/transaction-controller": "^42.1.0",
"@metamask/user-operation-controller": "^21.0.0",
"@metamask/utils": "^10.0.1",
"@ngraveio/bc-ur": "^1.1.12",
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5109,13 +5109,13 @@ __metadata:
languageName: node
linkType: hard

"@metamask/base-controller@npm:^7.0.0, @metamask/base-controller@npm:^7.0.1, @metamask/base-controller@npm:^7.0.2":
version: 7.0.2
resolution: "@metamask/base-controller@npm:7.0.2"
"@metamask/base-controller@npm:^7.0.0, @metamask/base-controller@npm:^7.0.1, @metamask/base-controller@npm:^7.0.2, @metamask/base-controller@npm:^7.1.0":
version: 7.1.0
resolution: "@metamask/base-controller@npm:7.1.0"
dependencies:
"@metamask/utils": "npm:^10.0.0"
immer: "npm:^9.0.6"
checksum: 10/6f78ec5af840c9947aa8eac6e402df6469600260d613a92196daefd5b072097a176fe5da1c386f2d36853513254b74140d667d817a12880c46f088e18ff3606a
checksum: 10/5a0b50c1e096cbf6483e308eddb3ca2e5e1865b803b5dba778bf635ec59657290895e21ada71c7508d8e34ff9695a192a414fd75e287d290346359ef8e23960a
languageName: node
linkType: hard

Expand Down Expand Up @@ -6477,23 +6477,23 @@ __metadata:
languageName: node
linkType: hard

"@metamask/transaction-controller@npm:^42.0.0":
version: 42.0.0
resolution: "@metamask/transaction-controller@npm:42.0.0"
"@metamask/transaction-controller@npm:^42.1.0":
version: 42.1.0
resolution: "@metamask/transaction-controller@npm:42.1.0"
dependencies:
"@ethereumjs/common": "npm:^3.2.0"
"@ethereumjs/tx": "npm:^4.2.0"
"@ethereumjs/util": "npm:^8.1.0"
"@ethersproject/abi": "npm:^5.7.0"
"@ethersproject/contracts": "npm:^5.7.0"
"@ethersproject/providers": "npm:^5.7.0"
"@metamask/base-controller": "npm:^7.0.2"
"@metamask/base-controller": "npm:^7.1.0"
"@metamask/controller-utils": "npm:^11.4.4"
"@metamask/eth-query": "npm:^4.0.0"
"@metamask/metamask-eth-abis": "npm:^3.1.1"
"@metamask/nonce-tracker": "npm:^6.0.0"
"@metamask/rpc-errors": "npm:^7.0.1"
"@metamask/utils": "npm:^10.0.0"
"@metamask/rpc-errors": "npm:^7.0.2"
"@metamask/utils": "npm:^11.0.1"
async-mutex: "npm:^0.5.0"
bn.js: "npm:^5.2.1"
eth-method-registry: "npm:^4.0.0"
Expand All @@ -6507,7 +6507,7 @@ __metadata:
"@metamask/eth-block-tracker": ">=9"
"@metamask/gas-fee-controller": ^22.0.0
"@metamask/network-controller": ^22.0.0
checksum: 10/73c510803a720b4c1da0b82f1279a404a9b11c4ab76f8e5e4378c65d5d08bbb32c52062abfe319476cc3f5e2623a8987775c4524e55aa94002af73d73721b869
checksum: 10/9f842e2b68e84cbffdda301a0e15faab08226fd8e22eb954690ed41df60fe92c24acffdd9186b4c9f1da911a368cbe22cdb9ee046fc02d079c53f76100c66755
languageName: node
linkType: hard

Expand Down Expand Up @@ -26715,7 +26715,7 @@ __metadata:
"@metamask/solana-wallet-snap": "npm:^1.0.4"
"@metamask/test-bundler": "npm:^1.0.0"
"@metamask/test-dapp": "npm:8.13.0"
"@metamask/transaction-controller": "npm:^42.0.0"
"@metamask/transaction-controller": "npm:^42.1.0"
"@metamask/user-operation-controller": "npm:^21.0.0"
"@metamask/utils": "npm:^10.0.1"
"@ngraveio/bc-ur": "npm:^1.1.12"
Expand Down

0 comments on commit 9657527

Please sign in to comment.