From 2cfdb03e4346f7c9dd824caf5d9828d6ac41ff9d Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 9 Dec 2025 19:03:33 +0530 Subject: [PATCH 1/6] Adding requestId field to dapp confirmations --- .../src/hooks/processSendCalls.ts | 10 ++++++++++ .../src/TransactionController.ts | 2 ++ packages/transaction-controller/src/types.ts | 16 ++++++++++++++++ .../transaction-controller/src/utils/batch.ts | 5 +++++ 4 files changed, 33 insertions(+) diff --git a/packages/eip-5792-middleware/src/hooks/processSendCalls.ts b/packages/eip-5792-middleware/src/hooks/processSendCalls.ts index 6f87cb86720..2cae5e86d10 100644 --- a/packages/eip-5792-middleware/src/hooks/processSendCalls.ts +++ b/packages/eip-5792-middleware/src/hooks/processSendCalls.ts @@ -101,6 +101,8 @@ export async function processSendCalls( const securityAlertId = uuid(); const validateSecurity = validateSecurityHook.bind(null, securityAlertId); + const requestId = String(req.id); + let batchId: Hex; if (Object.keys(transactions).length === 1) { batchId = await processSingleTransaction({ @@ -110,6 +112,7 @@ export async function processSendCalls( messenger, networkClientId, origin, + requestId, securityAlertId, sendCalls: params, transactions, @@ -126,6 +129,7 @@ export async function processSendCalls( messenger, networkClientId, origin, + requestId, sendCalls: params, securityAlertId, transactions, @@ -161,6 +165,7 @@ async function processSingleTransaction({ messenger, networkClientId, origin, + requestId, securityAlertId, sendCalls, transactions, @@ -173,6 +178,7 @@ async function processSingleTransaction({ messenger: EIP5792Messenger; networkClientId: string; origin?: string; + requestId?: string; securityAlertId: string; sendCalls: SendCallsPayload; transactions: { params: BatchTransactionParams }[]; @@ -209,6 +215,7 @@ async function processSingleTransaction({ const batchId = generateBatchId(); await addTransaction(txParams, { + requestId, networkClientId, origin, securityAlertResponse: { securityAlertId } as SecurityAlertResponse, @@ -245,6 +252,7 @@ async function processMultipleTransaction({ networkClientId, messenger, origin, + requestId, sendCalls, securityAlertId, transactions, @@ -259,6 +267,7 @@ async function processMultipleTransaction({ messenger: EIP5792Messenger; networkClientId: string; origin?: string; + requestId?: string; sendCalls: SendCallsPayload; securityAlertId: string; transactions: { params: BatchTransactionParams }[]; @@ -295,6 +304,7 @@ async function processMultipleTransaction({ from, networkClientId, origin, + requestId, securityAlertId, transactions, validateSecurity, diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index 3196fabea81..caaa80da32b 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -1260,6 +1260,7 @@ export class TransactionController extends BaseController< networkClientId, origin, publishHook, + requestId, requireApproval, securityAlertResponse, sendFlowHistory, @@ -1357,6 +1358,7 @@ export class TransactionController extends BaseController< nestedTransactions, networkClientId, origin, + requestId, securityAlertResponse, selectedGasFeeToken: gasFeeToken, status: TransactionStatus.unapproved as const, diff --git a/packages/transaction-controller/src/types.ts b/packages/transaction-controller/src/types.ts index a339a13cdb2..fd8504847c5 100644 --- a/packages/transaction-controller/src/types.ts +++ b/packages/transaction-controller/src/types.ts @@ -384,6 +384,11 @@ export type TransactionMeta = { */ replacedById?: string; + /** + * ID of JSON-RPC request from DAPP. + */ + requestId?: string; + /** * IDs of any transactions that must be confirmed before this one is submitted. * Unlike a transaction batch, these transactions can be on alternate chains. @@ -592,6 +597,11 @@ export type TransactionBatchMeta = { */ origin?: string; + /** + * ID of the JSON-RPC request from DAPP. + */ + requestId?: string; + /** Current status of the transaction. */ status: TransactionStatus; @@ -1754,6 +1764,9 @@ export type TransactionBatchRequest = { /** Whether to overwrite existing EIP-7702 delegation with MetaMask contract. */ overwriteUpgrade?: boolean; + /** ID of the JSON-RPC request from DAPP. */ + requestId?: string; + /** Whether an approval request should be created to require confirmation from the user. */ requireApproval?: boolean; @@ -2107,6 +2120,9 @@ export type AddTransactionOptions = { /** Custom logic to publish the transaction. */ publishHook?: PublishHook; + /** ID of JSON-RPC request from DAPP. */ + requestId?: string; + /** Whether the transaction requires approval by the user, defaults to true unless explicitly disabled. */ requireApproval?: boolean | undefined; diff --git a/packages/transaction-controller/src/utils/batch.ts b/packages/transaction-controller/src/utils/batch.ts index fdf028c73ba..a39d2eda47b 100644 --- a/packages/transaction-controller/src/utils/batch.ts +++ b/packages/transaction-controller/src/utils/batch.ts @@ -96,6 +96,7 @@ type AddTransactionBatchRequest = { ) => Promise; publicKeyEIP7702?: Hex; request: TransactionBatchRequest; + requestId?: string; signTransaction: ( transactionMeta: TransactionMeta, ) => Promise; @@ -300,6 +301,7 @@ async function addTransactionBatchWith7702( networkClientId, origin, overwriteUpgrade, + requestId, requireApproval, securityAlertId, skipInitialGasEstimate, @@ -430,6 +432,7 @@ async function addTransactionBatchWith7702( nestedTransactions, networkClientId, origin, + requestId, requireApproval, securityAlertResponse, skipInitialGasEstimate, @@ -854,6 +857,7 @@ async function prepareApprovalData({ origin, networkClientId, transactions: nestedTransactions, + requestId, } = userRequest; const ethQuery = getEthQuery(networkClientId); @@ -881,6 +885,7 @@ async function prepareApprovalData({ networkClientId, origin, transactions: nestedTransactions, + requestId, }); const defaultGasFeeFlow = new DefaultGasFeeFlow(); From 665775dad8cb0a6615f250d7ebd951e84fe141e8 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 9 Dec 2025 19:11:57 +0530 Subject: [PATCH 2/6] update --- packages/eip-5792-middleware/src/hooks/processSendCalls.test.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/eip-5792-middleware/src/hooks/processSendCalls.test.ts b/packages/eip-5792-middleware/src/hooks/processSendCalls.test.ts index 009b81962d0..24f35b3eb41 100644 --- a/packages/eip-5792-middleware/src/hooks/processSendCalls.test.ts +++ b/packages/eip-5792-middleware/src/hooks/processSendCalls.test.ts @@ -210,6 +210,7 @@ describe('EIP-5792', () => { from: SEND_CALLS_MOCK.from, networkClientId: NETWORK_CLIENT_ID_MOCK, origin: ORIGIN_MOCK, + requestId: '1', securityAlertId: expect.any(String), transactions: [ { params: SEND_CALLS_MOCK.calls[0] }, @@ -237,6 +238,7 @@ describe('EIP-5792', () => { batchId: expect.any(String), networkClientId: 'test-client', origin: 'test.com', + requestId: '1', securityAlertResponse: { securityAlertId: expect.any(String), }, From c64583126d22f2f6b625866c44720f989cc6bb5c Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Tue, 9 Dec 2025 19:57:47 +0530 Subject: [PATCH 3/6] update --- packages/eip-5792-middleware/src/hooks/processSendCalls.ts | 2 ++ .../transaction-controller/src/TransactionController.test.ts | 1 + 2 files changed, 3 insertions(+) diff --git a/packages/eip-5792-middleware/src/hooks/processSendCalls.ts b/packages/eip-5792-middleware/src/hooks/processSendCalls.ts index 2cae5e86d10..cfeab8cb4cc 100644 --- a/packages/eip-5792-middleware/src/hooks/processSendCalls.ts +++ b/packages/eip-5792-middleware/src/hooks/processSendCalls.ts @@ -151,6 +151,7 @@ export async function processSendCalls( * @param params.messenger - Messenger instance for controller communication. * @param params.networkClientId - The network client ID. * @param params.origin - The origin of the request (optional). + * @param params.requestId - Unique requestId of the JSON-RPC request from DAPP. * @param params.securityAlertId - The security alert ID for this transaction. * @param params.sendCalls - The original sendCalls request. * @param params.transactions - Array containing the single transaction. @@ -236,6 +237,7 @@ async function processSingleTransaction({ * @param params.networkClientId - The network client ID. * @param params.messenger - Messenger instance for controller communication. * @param params.origin - The origin of the request (optional). + * @param params.requestId - Unique requestId of the JSON-RPC request from DAPP. * @param params.sendCalls - The original sendCalls request. * @param params.securityAlertId - The security alert ID for this batch. * @param params.transactions - Array of transactions to process. diff --git a/packages/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index d45aec18760..3993a0f564b 100644 --- a/packages/transaction-controller/src/TransactionController.test.ts +++ b/packages/transaction-controller/src/TransactionController.test.ts @@ -1784,6 +1784,7 @@ describe('TransactionController', () => { nestedTransactions: undefined, networkClientId: NETWORK_CLIENT_ID_MOCK, origin: undefined, + requestId: undefined, securityAlertResponse: undefined, selectedGasFeeToken: undefined, sendFlowHistory: expect.any(Array), From c75349a8104ed43bc53bb74408fb8fe368351c18 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Wed, 10 Dec 2025 17:02:37 +0530 Subject: [PATCH 4/6] update --- packages/eip-5792-middleware/src/hooks/processSendCalls.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eip-5792-middleware/src/hooks/processSendCalls.ts b/packages/eip-5792-middleware/src/hooks/processSendCalls.ts index cfeab8cb4cc..0ff8f926550 100644 --- a/packages/eip-5792-middleware/src/hooks/processSendCalls.ts +++ b/packages/eip-5792-middleware/src/hooks/processSendCalls.ts @@ -101,7 +101,7 @@ export async function processSendCalls( const securityAlertId = uuid(); const validateSecurity = validateSecurityHook.bind(null, securityAlertId); - const requestId = String(req.id); + const requestId = req.id ? String(req.id) : ''; let batchId: Hex; if (Object.keys(transactions).length === 1) { From ddd24c9e2798562cd3e67884530cf603cf2b5759 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Wed, 10 Dec 2025 17:08:26 +0530 Subject: [PATCH 5/6] update --- packages/eip-5792-middleware/CHANGELOG.md | 4 ++++ packages/transaction-controller/CHANGELOG.md | 1 + 2 files changed, 5 insertions(+) diff --git a/packages/eip-5792-middleware/CHANGELOG.md b/packages/eip-5792-middleware/CHANGELOG.md index 439e6eb6eb3..1545e367a2a 100644 --- a/packages/eip-5792-middleware/CHANGELOG.md +++ b/packages/eip-5792-middleware/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Id of JSON RPC request is passed to functions to create batched transaction, id is thus added to transaction meta ([#7415](https://github.com/MetaMask/core/pull/7415)) + ### Changed - Bump `@metamask/transaction-controller` from `^61.3.0` to `^62.5.0` ([#7007](https://github.com/MetaMask/core/pull/7007), [#7126](https://github.com/MetaMask/core/pull/7126), [#7153](https://github.com/MetaMask/core/pull/7153), [#7202](https://github.com/MetaMask/core/pull/7202), [#7215](https://github.com/MetaMask/core/pull/7202), [#7220](https://github.com/MetaMask/core/pull/7220), [#7236](https://github.com/MetaMask/core/pull/7236), [#7257](https://github.com/MetaMask/core/pull/7257), [#7289](https://github.com/MetaMask/core/pull/7289), [#7325](https://github.com/MetaMask/core/pull/7325)) diff --git a/packages/transaction-controller/CHANGELOG.md b/packages/transaction-controller/CHANGELOG.md index 4f9ecf16906..a17ca6075e3 100644 --- a/packages/transaction-controller/CHANGELOG.md +++ b/packages/transaction-controller/CHANGELOG.md @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add optional `isTimeoutEnabled` callback to disable for specific transactions. - Ignores transactions with future nonce. - Threshold determined by feature flag. +- Adding a new transaction meta property `requestId`. It is supported for both simple and batched transactions ([#7415](https://github.com/MetaMask/core/pull/7415)) ### Fixed From a209dc8204cb495ddcdaae2df6a2bba2877edbc1 Mon Sep 17 00:00:00 2001 From: Jyoti Puri Date: Wed, 10 Dec 2025 17:35:43 +0530 Subject: [PATCH 6/6] update --- packages/transaction-controller/src/utils/batch.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/transaction-controller/src/utils/batch.ts b/packages/transaction-controller/src/utils/batch.ts index a39d2eda47b..48e046b49b1 100644 --- a/packages/transaction-controller/src/utils/batch.ts +++ b/packages/transaction-controller/src/utils/batch.ts @@ -857,7 +857,6 @@ async function prepareApprovalData({ origin, networkClientId, transactions: nestedTransactions, - requestId, } = userRequest; const ethQuery = getEthQuery(networkClientId); @@ -885,7 +884,6 @@ async function prepareApprovalData({ networkClientId, origin, transactions: nestedTransactions, - requestId, }); const defaultGasFeeFlow = new DefaultGasFeeFlow();