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/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), }, diff --git a/packages/eip-5792-middleware/src/hooks/processSendCalls.ts b/packages/eip-5792-middleware/src/hooks/processSendCalls.ts index 6f87cb86720..0ff8f926550 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 = req.id ? 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, @@ -147,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. @@ -161,6 +166,7 @@ async function processSingleTransaction({ messenger, networkClientId, origin, + requestId, securityAlertId, sendCalls, transactions, @@ -173,6 +179,7 @@ async function processSingleTransaction({ messenger: EIP5792Messenger; networkClientId: string; origin?: string; + requestId?: string; securityAlertId: string; sendCalls: SendCallsPayload; transactions: { params: BatchTransactionParams }[]; @@ -209,6 +216,7 @@ async function processSingleTransaction({ const batchId = generateBatchId(); await addTransaction(txParams, { + requestId, networkClientId, origin, securityAlertResponse: { securityAlertId } as SecurityAlertResponse, @@ -229,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. @@ -245,6 +254,7 @@ async function processMultipleTransaction({ networkClientId, messenger, origin, + requestId, sendCalls, securityAlertId, transactions, @@ -259,6 +269,7 @@ async function processMultipleTransaction({ messenger: EIP5792Messenger; networkClientId: string; origin?: string; + requestId?: string; sendCalls: SendCallsPayload; securityAlertId: string; transactions: { params: BatchTransactionParams }[]; @@ -295,6 +306,7 @@ async function processMultipleTransaction({ from, networkClientId, origin, + requestId, securityAlertId, transactions, validateSecurity, diff --git a/packages/transaction-controller/CHANGELOG.md b/packages/transaction-controller/CHANGELOG.md index 75f7eb34515..d3158451201 100644 --- a/packages/transaction-controller/CHANGELOG.md +++ b/packages/transaction-controller/CHANGELOG.md @@ -15,6 +15,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)) ### Changed diff --git a/packages/transaction-controller/src/TransactionController.test.ts b/packages/transaction-controller/src/TransactionController.test.ts index 1685eb58cae..a9cd9aaf1ca 100644 --- a/packages/transaction-controller/src/TransactionController.test.ts +++ b/packages/transaction-controller/src/TransactionController.test.ts @@ -1790,6 +1790,7 @@ describe('TransactionController', () => { nestedTransactions: undefined, networkClientId: NETWORK_CLIENT_ID_MOCK, origin: undefined, + requestId: undefined, securityAlertResponse: undefined, selectedGasFeeToken: undefined, sendFlowHistory: expect.any(Array), diff --git a/packages/transaction-controller/src/TransactionController.ts b/packages/transaction-controller/src/TransactionController.ts index fdaa1f1a668..a8e976b1574 100644 --- a/packages/transaction-controller/src/TransactionController.ts +++ b/packages/transaction-controller/src/TransactionController.ts @@ -1280,6 +1280,7 @@ export class TransactionController extends BaseController< networkClientId, origin, publishHook, + requestId, requireApproval, securityAlertResponse, sendFlowHistory, @@ -1377,6 +1378,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 a6e3cce50a8..17b41e5e485 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; @@ -1762,6 +1772,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; @@ -2115,6 +2128,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 952c989a08c..6b4ec92f272 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; @@ -301,6 +302,7 @@ async function addTransactionBatchWith7702( networkClientId, origin, overwriteUpgrade, + requestId, requireApproval, securityAlertId, skipInitialGasEstimate, @@ -432,6 +434,7 @@ async function addTransactionBatchWith7702( nestedTransactions, networkClientId, origin, + requestId, requireApproval, securityAlertResponse, skipInitialGasEstimate,