@metamask-previews/eip-5792-middleware 2.0.0-preview-eb60826c → 2.0.0-preview-565dfca2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -4
- package/dist/hooks/processSendCalls.cjs +2 -9
- package/dist/hooks/processSendCalls.cjs.map +1 -1
- package/dist/hooks/processSendCalls.d.cts.map +1 -1
- package/dist/hooks/processSendCalls.d.mts.map +1 -1
- package/dist/hooks/processSendCalls.mjs +2 -9
- package/dist/hooks/processSendCalls.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,10 +7,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
-
### Added
|
|
11
|
-
|
|
12
|
-
- 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))
|
|
13
|
-
|
|
14
10
|
### Changed
|
|
15
11
|
|
|
16
12
|
- Bump `@metamask/transaction-controller` from `^61.3.0` to `^62.6.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), [#7430](https://github.com/MetaMask/core/pull/7430))
|
|
@@ -27,7 +27,6 @@ async function processSendCalls(hooks, messenger, params, req) {
|
|
|
27
27
|
messenger.call('AccountsController:getSelectedAccount').address;
|
|
28
28
|
const securityAlertId = (0, uuid_1.v4)();
|
|
29
29
|
const validateSecurity = validateSecurityHook.bind(null, securityAlertId);
|
|
30
|
-
const requestId = req.id ? String(req.id) : '';
|
|
31
30
|
let batchId;
|
|
32
31
|
if (Object.keys(transactions).length === 1) {
|
|
33
32
|
batchId = await processSingleTransaction({
|
|
@@ -37,7 +36,6 @@ async function processSendCalls(hooks, messenger, params, req) {
|
|
|
37
36
|
messenger,
|
|
38
37
|
networkClientId,
|
|
39
38
|
origin,
|
|
40
|
-
requestId,
|
|
41
39
|
securityAlertId,
|
|
42
40
|
sendCalls: params,
|
|
43
41
|
transactions,
|
|
@@ -55,7 +53,6 @@ async function processSendCalls(hooks, messenger, params, req) {
|
|
|
55
53
|
messenger,
|
|
56
54
|
networkClientId,
|
|
57
55
|
origin,
|
|
58
|
-
requestId,
|
|
59
56
|
sendCalls: params,
|
|
60
57
|
securityAlertId,
|
|
61
58
|
transactions,
|
|
@@ -76,7 +73,6 @@ exports.processSendCalls = processSendCalls;
|
|
|
76
73
|
* @param params.messenger - Messenger instance for controller communication.
|
|
77
74
|
* @param params.networkClientId - The network client ID.
|
|
78
75
|
* @param params.origin - The origin of the request (optional).
|
|
79
|
-
* @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.
|
|
80
76
|
* @param params.securityAlertId - The security alert ID for this transaction.
|
|
81
77
|
* @param params.sendCalls - The original sendCalls request.
|
|
82
78
|
* @param params.transactions - Array containing the single transaction.
|
|
@@ -84,7 +80,7 @@ exports.processSendCalls = processSendCalls;
|
|
|
84
80
|
* @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
85
81
|
* @returns Promise resolving to the generated batch ID for the transaction.
|
|
86
82
|
*/
|
|
87
|
-
async function processSingleTransaction({ addTransaction, chainId, from, messenger, networkClientId, origin,
|
|
83
|
+
async function processSingleTransaction({ addTransaction, chainId, from, messenger, networkClientId, origin, securityAlertId, sendCalls, transactions, validateSecurity, isAuxiliaryFundsSupported, }) {
|
|
88
84
|
const keyringType = (0, utils_2.getAccountKeyringType)(from, messenger);
|
|
89
85
|
validateSingleSendCall(sendCalls, chainId, keyringType, isAuxiliaryFundsSupported);
|
|
90
86
|
const txParams = {
|
|
@@ -101,7 +97,6 @@ async function processSingleTransaction({ addTransaction, chainId, from, messeng
|
|
|
101
97
|
dedupeAuxiliaryFundsRequiredAssets(sendCalls);
|
|
102
98
|
const batchId = generateBatchId();
|
|
103
99
|
await addTransaction(txParams, {
|
|
104
|
-
requestId,
|
|
105
100
|
networkClientId,
|
|
106
101
|
origin,
|
|
107
102
|
securityAlertResponse: { securityAlertId },
|
|
@@ -121,7 +116,6 @@ async function processSingleTransaction({ addTransaction, chainId, from, messeng
|
|
|
121
116
|
* @param params.networkClientId - The network client ID.
|
|
122
117
|
* @param params.messenger - Messenger instance for controller communication.
|
|
123
118
|
* @param params.origin - The origin of the request (optional).
|
|
124
|
-
* @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.
|
|
125
119
|
* @param params.sendCalls - The original sendCalls request.
|
|
126
120
|
* @param params.securityAlertId - The security alert ID for this batch.
|
|
127
121
|
* @param params.transactions - Array of transactions to process.
|
|
@@ -129,7 +123,7 @@ async function processSingleTransaction({ addTransaction, chainId, from, messeng
|
|
|
129
123
|
* @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
130
124
|
* @returns Promise resolving to the generated batch ID for the transaction batch.
|
|
131
125
|
*/
|
|
132
|
-
async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSupported, chainId, from, getDismissSmartAccountSuggestionEnabled, networkClientId, messenger, origin,
|
|
126
|
+
async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSupported, chainId, from, getDismissSmartAccountSuggestionEnabled, networkClientId, messenger, origin, sendCalls, securityAlertId, transactions, validateSecurity, isAuxiliaryFundsSupported, }) {
|
|
133
127
|
const batchSupport = await isAtomicBatchSupported({
|
|
134
128
|
address: from,
|
|
135
129
|
chainIds: [chainId],
|
|
@@ -143,7 +137,6 @@ async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSu
|
|
|
143
137
|
from,
|
|
144
138
|
networkClientId,
|
|
145
139
|
origin,
|
|
146
|
-
requestId,
|
|
147
140
|
securityAlertId,
|
|
148
141
|
transactions,
|
|
149
142
|
validateSecurity,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processSendCalls.cjs","sourceRoot":"","sources":["../../src/hooks/processSendCalls.ts"],"names":[],"mappings":";;;AACA,qDAA+D;AAQ/D,6EAA2E;AAE3E,2CAAoD;AACpD,mCAAiC;AACjC,+BAAyC;AAEzC,gDAOsB;AAOtB,wCAAiD;AAkCjD;;;;;;;;GAQG;AACI,KAAK,UAAU,gBAAgB,CACpC,KAA4B,EAC5B,SAA2B,EAC3B,MAAwB,EACxB,GAA4B;IAE5B,MAAM,EACJ,mBAAmB,EACnB,cAAc,EACd,uCAAuC,EACvC,sBAAsB,EACtB,gBAAgB,EAAE,oBAAoB,EACtC,yBAAyB,GAC1B,GAAG,KAAK,CAAC;IAEV,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC1C,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACxC,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;IAE7D,MAAM,EAAE,OAAO,EAAE,GAAG,SAAS,CAAC,IAAI,CAChC,wCAAwC,EACxC,eAAe,CAChB,CAAC,aAAa,CAAC;IAEhB,MAAM,IAAI,GACR,SAAS;QACR,SAAS,CAAC,IAAI,CAAC,uCAAuC,CAAC,CAAC,OAAe,CAAC;IAE3E,MAAM,eAAe,GAAG,IAAA,SAAI,GAAE,CAAC;IAC/B,MAAM,gBAAgB,GAAG,oBAAoB,CAAC,IAAI,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;IAE1E,MAAM,SAAS,GAAG,GAAG,CAAC,EAAE,CAAC,CAA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AAC;gBACvB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YAED,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;gBAC9C,OAAO,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACpC,CAAC,EAAE,EAAE,CAAC,CAAC;YAEP,OAAO;gBACL,GAAG,KAAK,CAAC,CAAC,CAAC;gBACX,MAAM,EAAE,IAAA,aAAK,EAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACxC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,YAAY,CAAC,cAAc,CAAC,cAAc,GAAG,kBAAkB,CAAC;IAC5E,CAAC;AACH,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n BatchTransactionParams,\n IsAtomicBatchSupportedResultEntry,\n SecurityAlertResponse,\n TransactionController,\n ValidateSecurityRequest,\n} from '@metamask/transaction-controller';\nimport { TransactionEnvelopeType } from '@metamask/transaction-controller';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\nimport { add0x, bytesToHex } from '@metamask/utils';\nimport { groupBy } from 'lodash';\nimport { parse, v4 as uuid } from 'uuid';\n\nimport {\n EIP5792ErrorCode,\n EIP7682ErrorCode,\n KEYRING_TYPES_SUPPORTING_7702,\n MessageType,\n SupportedCapabilities,\n VERSION,\n} from '../constants';\nimport type {\n EIP5792Messenger,\n SendCallsPayload,\n SendCallsRequiredAssetsParam,\n SendCallsResult,\n} from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link processSendCalls}\n */\nexport type ProcessSendCallsHooks = {\n /** Function to add a batch of transactions atomically */\n addTransactionBatch: TransactionController['addTransactionBatch'];\n /** Function to add a single transaction */\n addTransaction: TransactionController['addTransaction'];\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if atomic batching is supported for given parameters */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to validate security for transaction requests */\n validateSecurity: (\n securityAlertId: string,\n request: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * A valid JSON-RPC request object for `wallet_sendCalls`.\n */\nexport type ProcessSendCallsRequest = JsonRpcRequest & {\n /** The identifier for the network client that has been created for this RPC endpoint */\n networkClientId: string;\n /** The origin of the RPC request */\n origin?: string;\n};\n\n/**\n * Processes a sendCalls request for EIP-5792 transactions.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param params - The sendCalls parameters containing transaction calls and metadata.\n * @param req - The original JSON-RPC request.\n * @returns Promise resolving to a SendCallsResult containing the batch ID.\n */\nexport async function processSendCalls(\n hooks: ProcessSendCallsHooks,\n messenger: EIP5792Messenger,\n params: SendCallsPayload,\n req: ProcessSendCallsRequest,\n): Promise<SendCallsResult> {\n const {\n addTransactionBatch,\n addTransaction,\n getDismissSmartAccountSuggestionEnabled,\n isAtomicBatchSupported,\n validateSecurity: validateSecurityHook,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n const { calls, from: paramFrom } = params;\n const { networkClientId, origin } = req;\n const transactions = calls.map((call) => ({ params: call }));\n\n const { chainId } = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration;\n\n const from =\n paramFrom ??\n (messenger.call('AccountsController:getSelectedAccount').address as Hex);\n\n const securityAlertId = uuid();\n const validateSecurity = validateSecurityHook.bind(null, securityAlertId);\n\n const requestId = req.id ? String(req.id) : '';\n\n let batchId: Hex;\n if (Object.keys(transactions).length === 1) {\n batchId = await processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n requestId,\n securityAlertId,\n sendCalls: params,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n } else {\n batchId = await processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n messenger,\n networkClientId,\n origin,\n requestId,\n sendCalls: params,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n }\n\n return { id: batchId };\n}\n\n/**\n * Processes a single transaction from a sendCalls request.\n *\n * @param params - Object containing all parameters needed for single transaction processing.\n * @param params.addTransaction - Function to add a single transaction.\n * @param params.chainId - The chain ID for the transaction.\n * @param params.from - The sender address.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.networkClientId - The network client ID.\n * @param params.origin - The origin of the request (optional).\n * @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.\n * @param params.securityAlertId - The security alert ID for this transaction.\n * @param params.sendCalls - The original sendCalls request.\n * @param params.transactions - Array containing the single transaction.\n * @param params.validateSecurity - Function to validate security for the transaction.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction.\n */\nasync function processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n requestId,\n securityAlertId,\n sendCalls,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransaction: TransactionController['addTransaction'];\n chainId: Hex;\n from: Hex;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n requestId?: string;\n securityAlertId: string;\n sendCalls: SendCallsPayload;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => void;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const keyringType = getAccountKeyringType(from, messenger);\n\n validateSingleSendCall(\n sendCalls,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n const txParams = {\n from,\n ...transactions[0].params,\n type: TransactionEnvelopeType.feeMarket,\n };\n\n const securityRequest: ValidateSecurityRequest = {\n method: MessageType.SendTransaction,\n params: [txParams],\n origin,\n };\n validateSecurity(securityRequest, chainId);\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const batchId = generateBatchId();\n\n await addTransaction(txParams, {\n requestId,\n networkClientId,\n origin,\n securityAlertResponse: { securityAlertId } as SecurityAlertResponse,\n batchId,\n });\n return batchId;\n}\n\n/**\n * Processes multiple transactions from a sendCalls request as an atomic batch.\n *\n * @param params - Object containing all parameters needed for multiple transaction processing.\n * @param params.addTransactionBatch - Function to add a batch of transactions atomically.\n * @param params.isAtomicBatchSupported - Function to check if atomic batching is supported.\n * @param params.chainId - The chain ID for the transactions.\n * @param params.from - The sender address.\n * @param params.getDismissSmartAccountSuggestionEnabled - Function to check if smart account suggestions are disabled.\n * @param params.networkClientId - The network client ID.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.origin - The origin of the request (optional).\n * @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.\n * @param params.sendCalls - The original sendCalls request.\n * @param params.securityAlertId - The security alert ID for this batch.\n * @param params.transactions - Array of transactions to process.\n * @param params.validateSecurity - Function to validate security for the transactions.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction batch.\n */\nasync function processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n networkClientId,\n messenger,\n origin,\n requestId,\n sendCalls,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n chainId: Hex;\n from: Hex;\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n requestId?: string;\n sendCalls: SendCallsPayload;\n securityAlertId: string;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const batchSupport = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const chainBatchSupport = batchSupport?.[0];\n\n const keyringType = getAccountKeyringType(from, messenger);\n\n const dismissSmartAccountSuggestionEnabled =\n getDismissSmartAccountSuggestionEnabled();\n\n validateSendCalls(\n sendCalls,\n chainId,\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const result = await addTransactionBatch({\n from,\n networkClientId,\n origin,\n requestId,\n securityAlertId,\n transactions,\n validateSecurity,\n });\n return result.batchId;\n}\n\n/**\n * Generate a transaction batch ID.\n *\n * @returns A unique batch ID as a hexadecimal string.\n */\nfunction generateBatchId(): Hex {\n const idString = uuid();\n const idBytes = new Uint8Array(parse(idString));\n return bytesToHex(idBytes);\n}\n\n/**\n * Validates a single sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSingleSendCall(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateDappChainId(sendCalls, dappChainId);\n}\n\n/**\n * Validates a sendCalls request for multiple transactions.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSendCalls(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateUpgrade(\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n );\n}\n\n/**\n * Validates the version of a sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @throws JsonRpcError if the version is not supported.\n */\nfunction validateSendCallsVersion(sendCalls: SendCallsPayload) {\n const { version } = sendCalls;\n\n if (version !== VERSION) {\n throw rpcErrors.invalidInput(\n `Version not supported: Got ${version}, expected ${VERSION}`,\n );\n }\n}\n\n/**\n * Validates that the chain ID in the sendCalls request matches the dApp's selected network.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @throws JsonRpcError if the chain IDs don't match\n */\nfunction validateDappChainId(sendCalls: SendCallsPayload, dappChainId: Hex) {\n const { chainId: requestChainId } = sendCalls;\n\n if (\n requestChainId &&\n requestChainId.toLowerCase() !== dappChainId.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Chain ID must match the dApp selected network: Got ${requestChainId}, expected ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates the chain ID for sendCalls requests with additional EIP-7702 support checks.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param chainBatchSupport - Information about atomic batch support for the chain\n * @throws JsonRpcError if the chain ID doesn't match or EIP-7702 is not supported\n */\nfunction validateSendCallsChainId(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n) {\n validateDappChainId(sendCalls, dappChainId);\n if (!chainBatchSupport) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedChainId,\n `EIP-7702 not supported on chain: ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates that all required capabilities in the sendCalls request are supported.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n *\n * @throws JsonRpcError if unsupported non-optional capabilities are requested.\n */\nfunction validateCapabilities(\n sendCalls: SendCallsPayload,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n const { calls, capabilities, chainId } = sendCalls;\n\n const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter(\n (name) =>\n // Non optional capabilities other than `auxiliaryFunds` are not supported by the wallet\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n capabilities?.[name].optional !== true,\n );\n\n const requiredCallCapabilities = calls.flatMap((call) =>\n Object.keys(call.capabilities ?? {}).filter(\n (name) =>\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n call.capabilities?.[name].optional !== true,\n ),\n );\n\n const requiredCapabilities = [\n ...requiredTopLevelCapabilities,\n ...requiredCallCapabilities,\n ];\n\n if (requiredCapabilities?.length) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capabilities: ${requiredCapabilities.join(\n ', ',\n )}`,\n );\n }\n\n if (capabilities?.auxiliaryFunds) {\n validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds: capabilities.auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n });\n }\n}\n\n/**\n * Validates EIP-7682 optional `requiredAssets` to see if the account and chain are supported, and that param is well-formed.\n *\n * docs: {@link https://eips.ethereum.org/EIPS/eip-7682#extended-usage-requiredassets-parameter}\n *\n * @param param - The parameter object.\n * @param param.auxiliaryFunds - The auxiliaryFunds param to validate.\n * @param param.auxiliaryFunds.optional - Metadata to signal for wallets that support this optional capability, while maintaining compatibility with wallets that do not.\n * @param param.auxiliaryFunds.requiredAssets - Metadata that enables a wallets support for `auxiliaryFunds` capability.\n * @param param.chainId - The chain ID of the incoming request.\n * @param param.keyringType - The type of keyring associated with the account.\n * @param param.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @throws JsonRpcError if auxiliary funds capability is not supported.\n */\nfunction validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n}: {\n auxiliaryFunds: {\n optional?: boolean;\n requiredAssets?: SendCallsRequiredAssetsParam[];\n };\n chainId: Hex;\n keyringType: KeyringTypes;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n // If we can make use of that capability then we should, but otherwise we can process the request and ignore the capability\n // so if the capability is signaled as optional, no validation is required, so we don't block the transaction from happening.\n if (auxiliaryFunds.optional) {\n return;\n }\n const isSupportedAccount =\n KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n\n if (!isSupportedAccount) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capability: ${SupportedCapabilities.AuxiliaryFunds}`,\n );\n }\n\n if (!isAuxiliaryFundsSupported(chainId)) {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedChain,\n `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`,\n );\n }\n\n if (!auxiliaryFunds?.requiredAssets) {\n return;\n }\n\n for (const asset of auxiliaryFunds.requiredAssets) {\n if (asset.standard !== 'erc20') {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedAsset,\n `The requested asset ${asset.address} is not available through the wallet’s auxiliary fund system: unsupported token standard ${asset.standard}`,\n );\n }\n }\n}\n\n/**\n * Validates whether an EIP-7702 upgrade is allowed for the given parameters.\n *\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @throws JsonRpcError if the upgrade is rejected due to user settings or account type.\n */\nfunction validateUpgrade(\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n) {\n if (chainBatchSupport?.delegationAddress) {\n return;\n }\n\n if (dismissSmartAccountSuggestionEnabled) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade disabled by the user',\n );\n }\n\n if (!KEYRING_TYPES_SUPPORTING_7702.includes(keyringType)) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported on account',\n );\n }\n}\n\n/**\n * Function to possibly deduplicate `auxiliaryFunds` capability `requiredAssets`.\n * Does nothing if no `requiredAssets` exists in `auxiliaryFunds` capability.\n *\n * @param sendCalls - The original sendCalls request.\n */\nfunction dedupeAuxiliaryFundsRequiredAssets(sendCalls: SendCallsPayload): void {\n if (sendCalls.capabilities?.auxiliaryFunds?.requiredAssets) {\n const { requiredAssets } = sendCalls.capabilities.auxiliaryFunds;\n // Group assets by their address (lowercased) and standard\n const grouped = groupBy(\n requiredAssets,\n (asset) => `${asset.address.toLowerCase()}-${asset.standard}`,\n );\n\n // For each group, sum the amounts and return a single asset\n const deduplicatedAssets = Object.values(grouped).map((group) => {\n if (group.length === 1) {\n return group[0];\n }\n\n const totalAmount = group.reduce((sum, asset) => {\n return sum + BigInt(asset.amount);\n }, 0n);\n\n return {\n ...group[0],\n amount: add0x(totalAmount.toString(16)),\n };\n });\n\n sendCalls.capabilities.auxiliaryFunds.requiredAssets = deduplicatedAssets;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"processSendCalls.cjs","sourceRoot":"","sources":["../../src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AC,CAAC,CAAC;QAEH,SAAS,CAAC,YAAY,CAAC,cAAc,CAAC,cAAc,GAAG,kBAAkB,CAAC;IAC5E,CAAC;AACH,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n BatchTransactionParams,\n IsAtomicBatchSupportedResultEntry,\n SecurityAlertResponse,\n TransactionController,\n ValidateSecurityRequest,\n} from '@metamask/transaction-controller';\nimport { TransactionEnvelopeType } from '@metamask/transaction-controller';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\nimport { add0x, bytesToHex } from '@metamask/utils';\nimport { groupBy } from 'lodash';\nimport { parse, v4 as uuid } from 'uuid';\n\nimport {\n EIP5792ErrorCode,\n EIP7682ErrorCode,\n KEYRING_TYPES_SUPPORTING_7702,\n MessageType,\n SupportedCapabilities,\n VERSION,\n} from '../constants';\nimport type {\n EIP5792Messenger,\n SendCallsPayload,\n SendCallsRequiredAssetsParam,\n SendCallsResult,\n} from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link processSendCalls}\n */\nexport type ProcessSendCallsHooks = {\n /** Function to add a batch of transactions atomically */\n addTransactionBatch: TransactionController['addTransactionBatch'];\n /** Function to add a single transaction */\n addTransaction: TransactionController['addTransaction'];\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if atomic batching is supported for given parameters */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to validate security for transaction requests */\n validateSecurity: (\n securityAlertId: string,\n request: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * A valid JSON-RPC request object for `wallet_sendCalls`.\n */\nexport type ProcessSendCallsRequest = JsonRpcRequest & {\n /** The identifier for the network client that has been created for this RPC endpoint */\n networkClientId: string;\n /** The origin of the RPC request */\n origin?: string;\n};\n\n/**\n * Processes a sendCalls request for EIP-5792 transactions.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param params - The sendCalls parameters containing transaction calls and metadata.\n * @param req - The original JSON-RPC request.\n * @returns Promise resolving to a SendCallsResult containing the batch ID.\n */\nexport async function processSendCalls(\n hooks: ProcessSendCallsHooks,\n messenger: EIP5792Messenger,\n params: SendCallsPayload,\n req: ProcessSendCallsRequest,\n): Promise<SendCallsResult> {\n const {\n addTransactionBatch,\n addTransaction,\n getDismissSmartAccountSuggestionEnabled,\n isAtomicBatchSupported,\n validateSecurity: validateSecurityHook,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n const { calls, from: paramFrom } = params;\n const { networkClientId, origin } = req;\n const transactions = calls.map((call) => ({ params: call }));\n\n const { chainId } = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration;\n\n const from =\n paramFrom ??\n (messenger.call('AccountsController:getSelectedAccount').address as Hex);\n\n const securityAlertId = uuid();\n const validateSecurity = validateSecurityHook.bind(null, securityAlertId);\n\n let batchId: Hex;\n if (Object.keys(transactions).length === 1) {\n batchId = await processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls: params,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n } else {\n batchId = await processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n messenger,\n networkClientId,\n origin,\n sendCalls: params,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n }\n\n return { id: batchId };\n}\n\n/**\n * Processes a single transaction from a sendCalls request.\n *\n * @param params - Object containing all parameters needed for single transaction processing.\n * @param params.addTransaction - Function to add a single transaction.\n * @param params.chainId - The chain ID for the transaction.\n * @param params.from - The sender address.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.networkClientId - The network client ID.\n * @param params.origin - The origin of the request (optional).\n * @param params.securityAlertId - The security alert ID for this transaction.\n * @param params.sendCalls - The original sendCalls request.\n * @param params.transactions - Array containing the single transaction.\n * @param params.validateSecurity - Function to validate security for the transaction.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction.\n */\nasync function processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransaction: TransactionController['addTransaction'];\n chainId: Hex;\n from: Hex;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n securityAlertId: string;\n sendCalls: SendCallsPayload;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => void;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const keyringType = getAccountKeyringType(from, messenger);\n\n validateSingleSendCall(\n sendCalls,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n const txParams = {\n from,\n ...transactions[0].params,\n type: TransactionEnvelopeType.feeMarket,\n };\n\n const securityRequest: ValidateSecurityRequest = {\n method: MessageType.SendTransaction,\n params: [txParams],\n origin,\n };\n validateSecurity(securityRequest, chainId);\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const batchId = generateBatchId();\n\n await addTransaction(txParams, {\n networkClientId,\n origin,\n securityAlertResponse: { securityAlertId } as SecurityAlertResponse,\n batchId,\n });\n return batchId;\n}\n\n/**\n * Processes multiple transactions from a sendCalls request as an atomic batch.\n *\n * @param params - Object containing all parameters needed for multiple transaction processing.\n * @param params.addTransactionBatch - Function to add a batch of transactions atomically.\n * @param params.isAtomicBatchSupported - Function to check if atomic batching is supported.\n * @param params.chainId - The chain ID for the transactions.\n * @param params.from - The sender address.\n * @param params.getDismissSmartAccountSuggestionEnabled - Function to check if smart account suggestions are disabled.\n * @param params.networkClientId - The network client ID.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.origin - The origin of the request (optional).\n * @param params.sendCalls - The original sendCalls request.\n * @param params.securityAlertId - The security alert ID for this batch.\n * @param params.transactions - Array of transactions to process.\n * @param params.validateSecurity - Function to validate security for the transactions.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction batch.\n */\nasync function processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n networkClientId,\n messenger,\n origin,\n sendCalls,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n chainId: Hex;\n from: Hex;\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n sendCalls: SendCallsPayload;\n securityAlertId: string;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const batchSupport = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const chainBatchSupport = batchSupport?.[0];\n\n const keyringType = getAccountKeyringType(from, messenger);\n\n const dismissSmartAccountSuggestionEnabled =\n getDismissSmartAccountSuggestionEnabled();\n\n validateSendCalls(\n sendCalls,\n chainId,\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const result = await addTransactionBatch({\n from,\n networkClientId,\n origin,\n securityAlertId,\n transactions,\n validateSecurity,\n });\n return result.batchId;\n}\n\n/**\n * Generate a transaction batch ID.\n *\n * @returns A unique batch ID as a hexadecimal string.\n */\nfunction generateBatchId(): Hex {\n const idString = uuid();\n const idBytes = new Uint8Array(parse(idString));\n return bytesToHex(idBytes);\n}\n\n/**\n * Validates a single sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSingleSendCall(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateDappChainId(sendCalls, dappChainId);\n}\n\n/**\n * Validates a sendCalls request for multiple transactions.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSendCalls(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateUpgrade(\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n );\n}\n\n/**\n * Validates the version of a sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @throws JsonRpcError if the version is not supported.\n */\nfunction validateSendCallsVersion(sendCalls: SendCallsPayload) {\n const { version } = sendCalls;\n\n if (version !== VERSION) {\n throw rpcErrors.invalidInput(\n `Version not supported: Got ${version}, expected ${VERSION}`,\n );\n }\n}\n\n/**\n * Validates that the chain ID in the sendCalls request matches the dApp's selected network.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @throws JsonRpcError if the chain IDs don't match\n */\nfunction validateDappChainId(sendCalls: SendCallsPayload, dappChainId: Hex) {\n const { chainId: requestChainId } = sendCalls;\n\n if (\n requestChainId &&\n requestChainId.toLowerCase() !== dappChainId.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Chain ID must match the dApp selected network: Got ${requestChainId}, expected ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates the chain ID for sendCalls requests with additional EIP-7702 support checks.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param chainBatchSupport - Information about atomic batch support for the chain\n * @throws JsonRpcError if the chain ID doesn't match or EIP-7702 is not supported\n */\nfunction validateSendCallsChainId(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n) {\n validateDappChainId(sendCalls, dappChainId);\n if (!chainBatchSupport) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedChainId,\n `EIP-7702 not supported on chain: ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates that all required capabilities in the sendCalls request are supported.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n *\n * @throws JsonRpcError if unsupported non-optional capabilities are requested.\n */\nfunction validateCapabilities(\n sendCalls: SendCallsPayload,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n const { calls, capabilities, chainId } = sendCalls;\n\n const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter(\n (name) =>\n // Non optional capabilities other than `auxiliaryFunds` are not supported by the wallet\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n capabilities?.[name].optional !== true,\n );\n\n const requiredCallCapabilities = calls.flatMap((call) =>\n Object.keys(call.capabilities ?? {}).filter(\n (name) =>\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n call.capabilities?.[name].optional !== true,\n ),\n );\n\n const requiredCapabilities = [\n ...requiredTopLevelCapabilities,\n ...requiredCallCapabilities,\n ];\n\n if (requiredCapabilities?.length) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capabilities: ${requiredCapabilities.join(\n ', ',\n )}`,\n );\n }\n\n if (capabilities?.auxiliaryFunds) {\n validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds: capabilities.auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n });\n }\n}\n\n/**\n * Validates EIP-7682 optional `requiredAssets` to see if the account and chain are supported, and that param is well-formed.\n *\n * docs: {@link https://eips.ethereum.org/EIPS/eip-7682#extended-usage-requiredassets-parameter}\n *\n * @param param - The parameter object.\n * @param param.auxiliaryFunds - The auxiliaryFunds param to validate.\n * @param param.auxiliaryFunds.optional - Metadata to signal for wallets that support this optional capability, while maintaining compatibility with wallets that do not.\n * @param param.auxiliaryFunds.requiredAssets - Metadata that enables a wallets support for `auxiliaryFunds` capability.\n * @param param.chainId - The chain ID of the incoming request.\n * @param param.keyringType - The type of keyring associated with the account.\n * @param param.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @throws JsonRpcError if auxiliary funds capability is not supported.\n */\nfunction validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n}: {\n auxiliaryFunds: {\n optional?: boolean;\n requiredAssets?: SendCallsRequiredAssetsParam[];\n };\n chainId: Hex;\n keyringType: KeyringTypes;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n // If we can make use of that capability then we should, but otherwise we can process the request and ignore the capability\n // so if the capability is signaled as optional, no validation is required, so we don't block the transaction from happening.\n if (auxiliaryFunds.optional) {\n return;\n }\n const isSupportedAccount =\n KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n\n if (!isSupportedAccount) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capability: ${SupportedCapabilities.AuxiliaryFunds}`,\n );\n }\n\n if (!isAuxiliaryFundsSupported(chainId)) {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedChain,\n `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`,\n );\n }\n\n if (!auxiliaryFunds?.requiredAssets) {\n return;\n }\n\n for (const asset of auxiliaryFunds.requiredAssets) {\n if (asset.standard !== 'erc20') {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedAsset,\n `The requested asset ${asset.address} is not available through the wallet’s auxiliary fund system: unsupported token standard ${asset.standard}`,\n );\n }\n }\n}\n\n/**\n * Validates whether an EIP-7702 upgrade is allowed for the given parameters.\n *\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @throws JsonRpcError if the upgrade is rejected due to user settings or account type.\n */\nfunction validateUpgrade(\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n) {\n if (chainBatchSupport?.delegationAddress) {\n return;\n }\n\n if (dismissSmartAccountSuggestionEnabled) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade disabled by the user',\n );\n }\n\n if (!KEYRING_TYPES_SUPPORTING_7702.includes(keyringType)) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported on account',\n );\n }\n}\n\n/**\n * Function to possibly deduplicate `auxiliaryFunds` capability `requiredAssets`.\n * Does nothing if no `requiredAssets` exists in `auxiliaryFunds` capability.\n *\n * @param sendCalls - The original sendCalls request.\n */\nfunction dedupeAuxiliaryFundsRequiredAssets(sendCalls: SendCallsPayload): void {\n if (sendCalls.capabilities?.auxiliaryFunds?.requiredAssets) {\n const { requiredAssets } = sendCalls.capabilities.auxiliaryFunds;\n // Group assets by their address (lowercased) and standard\n const grouped = groupBy(\n requiredAssets,\n (asset) => `${asset.address.toLowerCase()}-${asset.standard}`,\n );\n\n // For each group, sum the amounts and return a single asset\n const deduplicatedAssets = Object.values(grouped).map((group) => {\n if (group.length === 1) {\n return group[0];\n }\n\n const totalAmount = group.reduce((sum, asset) => {\n return sum + BigInt(asset.amount);\n }, 0n);\n\n return {\n ...group[0],\n amount: add0x(totalAmount.toString(16)),\n };\n });\n\n sendCalls.capabilities.auxiliaryFunds.requiredAssets = deduplicatedAssets;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processSendCalls.d.cts","sourceRoot":"","sources":["../../src/hooks/processSendCalls.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAIV,qBAAqB,EACrB,uBAAuB,EACxB,yCAAyC;AAE1C,OAAO,KAAK,EAAE,GAAG,EAAE,cAAc,EAAE,wBAAwB;AAa3D,OAAO,KAAK,EACV,gBAAgB,EAChB,gBAAgB,EAEhB,eAAe,EAChB,qBAAiB;AAGlB;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,yDAAyD;IACzD,mBAAmB,EAAE,qBAAqB,CAAC,qBAAqB,CAAC,CAAC;IAClE,2CAA2C;IAC3C,cAAc,EAAE,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;IACxD,kEAAkE;IAClE,uCAAuC,EAAE,MAAM,OAAO,CAAC;IACvD,6EAA6E;IAC7E,sBAAsB,EAAE,qBAAqB,CAAC,wBAAwB,CAAC,CAAC;IACxE,6DAA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uE;IACvE,yBAAyB,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC;CACtD,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG,cAAc,GAAG;IACrD,wFAAwF;IACxF,eAAe,EAAE,MAAM,CAAC;IACxB,oCAAoC;IACpC,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF;;;;;;;;GAQG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,qBAAqB,EAC5B,SAAS,EAAE,gBAAgB,EAC3B,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,uBAAuB,GAC3B,OAAO,CAAC,eAAe,CAAC,CA4D1B"}
|
|
@@ -25,7 +25,6 @@ export async function processSendCalls(hooks, messenger, params, req) {
|
|
|
25
25
|
messenger.call('AccountsController:getSelectedAccount').address;
|
|
26
26
|
const securityAlertId = uuid();
|
|
27
27
|
const validateSecurity = validateSecurityHook.bind(null, securityAlertId);
|
|
28
|
-
const requestId = req.id ? String(req.id) : '';
|
|
29
28
|
let batchId;
|
|
30
29
|
if (Object.keys(transactions).length === 1) {
|
|
31
30
|
batchId = await processSingleTransaction({
|
|
@@ -35,7 +34,6 @@ export async function processSendCalls(hooks, messenger, params, req) {
|
|
|
35
34
|
messenger,
|
|
36
35
|
networkClientId,
|
|
37
36
|
origin,
|
|
38
|
-
requestId,
|
|
39
37
|
securityAlertId,
|
|
40
38
|
sendCalls: params,
|
|
41
39
|
transactions,
|
|
@@ -53,7 +51,6 @@ export async function processSendCalls(hooks, messenger, params, req) {
|
|
|
53
51
|
messenger,
|
|
54
52
|
networkClientId,
|
|
55
53
|
origin,
|
|
56
|
-
requestId,
|
|
57
54
|
sendCalls: params,
|
|
58
55
|
securityAlertId,
|
|
59
56
|
transactions,
|
|
@@ -73,7 +70,6 @@ export async function processSendCalls(hooks, messenger, params, req) {
|
|
|
73
70
|
* @param params.messenger - Messenger instance for controller communication.
|
|
74
71
|
* @param params.networkClientId - The network client ID.
|
|
75
72
|
* @param params.origin - The origin of the request (optional).
|
|
76
|
-
* @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.
|
|
77
73
|
* @param params.securityAlertId - The security alert ID for this transaction.
|
|
78
74
|
* @param params.sendCalls - The original sendCalls request.
|
|
79
75
|
* @param params.transactions - Array containing the single transaction.
|
|
@@ -81,7 +77,7 @@ export async function processSendCalls(hooks, messenger, params, req) {
|
|
|
81
77
|
* @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
82
78
|
* @returns Promise resolving to the generated batch ID for the transaction.
|
|
83
79
|
*/
|
|
84
|
-
async function processSingleTransaction({ addTransaction, chainId, from, messenger, networkClientId, origin,
|
|
80
|
+
async function processSingleTransaction({ addTransaction, chainId, from, messenger, networkClientId, origin, securityAlertId, sendCalls, transactions, validateSecurity, isAuxiliaryFundsSupported, }) {
|
|
85
81
|
const keyringType = getAccountKeyringType(from, messenger);
|
|
86
82
|
validateSingleSendCall(sendCalls, chainId, keyringType, isAuxiliaryFundsSupported);
|
|
87
83
|
const txParams = {
|
|
@@ -98,7 +94,6 @@ async function processSingleTransaction({ addTransaction, chainId, from, messeng
|
|
|
98
94
|
dedupeAuxiliaryFundsRequiredAssets(sendCalls);
|
|
99
95
|
const batchId = generateBatchId();
|
|
100
96
|
await addTransaction(txParams, {
|
|
101
|
-
requestId,
|
|
102
97
|
networkClientId,
|
|
103
98
|
origin,
|
|
104
99
|
securityAlertResponse: { securityAlertId },
|
|
@@ -118,7 +113,6 @@ async function processSingleTransaction({ addTransaction, chainId, from, messeng
|
|
|
118
113
|
* @param params.networkClientId - The network client ID.
|
|
119
114
|
* @param params.messenger - Messenger instance for controller communication.
|
|
120
115
|
* @param params.origin - The origin of the request (optional).
|
|
121
|
-
* @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.
|
|
122
116
|
* @param params.sendCalls - The original sendCalls request.
|
|
123
117
|
* @param params.securityAlertId - The security alert ID for this batch.
|
|
124
118
|
* @param params.transactions - Array of transactions to process.
|
|
@@ -126,7 +120,7 @@ async function processSingleTransaction({ addTransaction, chainId, from, messeng
|
|
|
126
120
|
* @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
127
121
|
* @returns Promise resolving to the generated batch ID for the transaction batch.
|
|
128
122
|
*/
|
|
129
|
-
async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSupported, chainId, from, getDismissSmartAccountSuggestionEnabled, networkClientId, messenger, origin,
|
|
123
|
+
async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSupported, chainId, from, getDismissSmartAccountSuggestionEnabled, networkClientId, messenger, origin, sendCalls, securityAlertId, transactions, validateSecurity, isAuxiliaryFundsSupported, }) {
|
|
130
124
|
const batchSupport = await isAtomicBatchSupported({
|
|
131
125
|
address: from,
|
|
132
126
|
chainIds: [chainId],
|
|
@@ -140,7 +134,6 @@ async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSu
|
|
|
140
134
|
from,
|
|
141
135
|
networkClientId,
|
|
142
136
|
origin,
|
|
143
|
-
requestId,
|
|
144
137
|
securityAlertId,
|
|
145
138
|
transactions,
|
|
146
139
|
validateSecurity,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processSendCalls.mjs","sourceRoot":"","sources":["../../src/hooks/processSendCalls.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B;AAQ/D,OAAO,EAAE,uBAAuB,EAAE,yCAAyC;AAE3E,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,wBAAwB;;;AAEpD,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAEzC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,6BAA6B,EAC7B,WAAW,EACX,qBAAqB,EACrB,OAAO,EACR,yBAAqB;AAOtB,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AAkCjD;;;;;;;;GAQG;AACH,MAAM,C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Ac,CAAC,cAAc,GAAG,kBAAkB,CAAC;IAC5E,CAAC;AACH,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n BatchTransactionParams,\n IsAtomicBatchSupportedResultEntry,\n SecurityAlertResponse,\n TransactionController,\n ValidateSecurityRequest,\n} from '@metamask/transaction-controller';\nimport { TransactionEnvelopeType } from '@metamask/transaction-controller';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\nimport { add0x, bytesToHex } from '@metamask/utils';\nimport { groupBy } from 'lodash';\nimport { parse, v4 as uuid } from 'uuid';\n\nimport {\n EIP5792ErrorCode,\n EIP7682ErrorCode,\n KEYRING_TYPES_SUPPORTING_7702,\n MessageType,\n SupportedCapabilities,\n VERSION,\n} from '../constants';\nimport type {\n EIP5792Messenger,\n SendCallsPayload,\n SendCallsRequiredAssetsParam,\n SendCallsResult,\n} from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link processSendCalls}\n */\nexport type ProcessSendCallsHooks = {\n /** Function to add a batch of transactions atomically */\n addTransactionBatch: TransactionController['addTransactionBatch'];\n /** Function to add a single transaction */\n addTransaction: TransactionController['addTransaction'];\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if atomic batching is supported for given parameters */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to validate security for transaction requests */\n validateSecurity: (\n securityAlertId: string,\n request: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * A valid JSON-RPC request object for `wallet_sendCalls`.\n */\nexport type ProcessSendCallsRequest = JsonRpcRequest & {\n /** The identifier for the network client that has been created for this RPC endpoint */\n networkClientId: string;\n /** The origin of the RPC request */\n origin?: string;\n};\n\n/**\n * Processes a sendCalls request for EIP-5792 transactions.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param params - The sendCalls parameters containing transaction calls and metadata.\n * @param req - The original JSON-RPC request.\n * @returns Promise resolving to a SendCallsResult containing the batch ID.\n */\nexport async function processSendCalls(\n hooks: ProcessSendCallsHooks,\n messenger: EIP5792Messenger,\n params: SendCallsPayload,\n req: ProcessSendCallsRequest,\n): Promise<SendCallsResult> {\n const {\n addTransactionBatch,\n addTransaction,\n getDismissSmartAccountSuggestionEnabled,\n isAtomicBatchSupported,\n validateSecurity: validateSecurityHook,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n const { calls, from: paramFrom } = params;\n const { networkClientId, origin } = req;\n const transactions = calls.map((call) => ({ params: call }));\n\n const { chainId } = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration;\n\n const from =\n paramFrom ??\n (messenger.call('AccountsController:getSelectedAccount').address as Hex);\n\n const securityAlertId = uuid();\n const validateSecurity = validateSecurityHook.bind(null, securityAlertId);\n\n const requestId = req.id ? String(req.id) : '';\n\n let batchId: Hex;\n if (Object.keys(transactions).length === 1) {\n batchId = await processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n requestId,\n securityAlertId,\n sendCalls: params,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n } else {\n batchId = await processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n messenger,\n networkClientId,\n origin,\n requestId,\n sendCalls: params,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n }\n\n return { id: batchId };\n}\n\n/**\n * Processes a single transaction from a sendCalls request.\n *\n * @param params - Object containing all parameters needed for single transaction processing.\n * @param params.addTransaction - Function to add a single transaction.\n * @param params.chainId - The chain ID for the transaction.\n * @param params.from - The sender address.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.networkClientId - The network client ID.\n * @param params.origin - The origin of the request (optional).\n * @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.\n * @param params.securityAlertId - The security alert ID for this transaction.\n * @param params.sendCalls - The original sendCalls request.\n * @param params.transactions - Array containing the single transaction.\n * @param params.validateSecurity - Function to validate security for the transaction.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction.\n */\nasync function processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n requestId,\n securityAlertId,\n sendCalls,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransaction: TransactionController['addTransaction'];\n chainId: Hex;\n from: Hex;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n requestId?: string;\n securityAlertId: string;\n sendCalls: SendCallsPayload;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => void;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const keyringType = getAccountKeyringType(from, messenger);\n\n validateSingleSendCall(\n sendCalls,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n const txParams = {\n from,\n ...transactions[0].params,\n type: TransactionEnvelopeType.feeMarket,\n };\n\n const securityRequest: ValidateSecurityRequest = {\n method: MessageType.SendTransaction,\n params: [txParams],\n origin,\n };\n validateSecurity(securityRequest, chainId);\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const batchId = generateBatchId();\n\n await addTransaction(txParams, {\n requestId,\n networkClientId,\n origin,\n securityAlertResponse: { securityAlertId } as SecurityAlertResponse,\n batchId,\n });\n return batchId;\n}\n\n/**\n * Processes multiple transactions from a sendCalls request as an atomic batch.\n *\n * @param params - Object containing all parameters needed for multiple transaction processing.\n * @param params.addTransactionBatch - Function to add a batch of transactions atomically.\n * @param params.isAtomicBatchSupported - Function to check if atomic batching is supported.\n * @param params.chainId - The chain ID for the transactions.\n * @param params.from - The sender address.\n * @param params.getDismissSmartAccountSuggestionEnabled - Function to check if smart account suggestions are disabled.\n * @param params.networkClientId - The network client ID.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.origin - The origin of the request (optional).\n * @param params.requestId - Unique requestId of the JSON-RPC request from DAPP.\n * @param params.sendCalls - The original sendCalls request.\n * @param params.securityAlertId - The security alert ID for this batch.\n * @param params.transactions - Array of transactions to process.\n * @param params.validateSecurity - Function to validate security for the transactions.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction batch.\n */\nasync function processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n networkClientId,\n messenger,\n origin,\n requestId,\n sendCalls,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n chainId: Hex;\n from: Hex;\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n requestId?: string;\n sendCalls: SendCallsPayload;\n securityAlertId: string;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const batchSupport = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const chainBatchSupport = batchSupport?.[0];\n\n const keyringType = getAccountKeyringType(from, messenger);\n\n const dismissSmartAccountSuggestionEnabled =\n getDismissSmartAccountSuggestionEnabled();\n\n validateSendCalls(\n sendCalls,\n chainId,\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const result = await addTransactionBatch({\n from,\n networkClientId,\n origin,\n requestId,\n securityAlertId,\n transactions,\n validateSecurity,\n });\n return result.batchId;\n}\n\n/**\n * Generate a transaction batch ID.\n *\n * @returns A unique batch ID as a hexadecimal string.\n */\nfunction generateBatchId(): Hex {\n const idString = uuid();\n const idBytes = new Uint8Array(parse(idString));\n return bytesToHex(idBytes);\n}\n\n/**\n * Validates a single sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSingleSendCall(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateDappChainId(sendCalls, dappChainId);\n}\n\n/**\n * Validates a sendCalls request for multiple transactions.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSendCalls(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateUpgrade(\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n );\n}\n\n/**\n * Validates the version of a sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @throws JsonRpcError if the version is not supported.\n */\nfunction validateSendCallsVersion(sendCalls: SendCallsPayload) {\n const { version } = sendCalls;\n\n if (version !== VERSION) {\n throw rpcErrors.invalidInput(\n `Version not supported: Got ${version}, expected ${VERSION}`,\n );\n }\n}\n\n/**\n * Validates that the chain ID in the sendCalls request matches the dApp's selected network.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @throws JsonRpcError if the chain IDs don't match\n */\nfunction validateDappChainId(sendCalls: SendCallsPayload, dappChainId: Hex) {\n const { chainId: requestChainId } = sendCalls;\n\n if (\n requestChainId &&\n requestChainId.toLowerCase() !== dappChainId.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Chain ID must match the dApp selected network: Got ${requestChainId}, expected ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates the chain ID for sendCalls requests with additional EIP-7702 support checks.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param chainBatchSupport - Information about atomic batch support for the chain\n * @throws JsonRpcError if the chain ID doesn't match or EIP-7702 is not supported\n */\nfunction validateSendCallsChainId(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n) {\n validateDappChainId(sendCalls, dappChainId);\n if (!chainBatchSupport) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedChainId,\n `EIP-7702 not supported on chain: ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates that all required capabilities in the sendCalls request are supported.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n *\n * @throws JsonRpcError if unsupported non-optional capabilities are requested.\n */\nfunction validateCapabilities(\n sendCalls: SendCallsPayload,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n const { calls, capabilities, chainId } = sendCalls;\n\n const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter(\n (name) =>\n // Non optional capabilities other than `auxiliaryFunds` are not supported by the wallet\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n capabilities?.[name].optional !== true,\n );\n\n const requiredCallCapabilities = calls.flatMap((call) =>\n Object.keys(call.capabilities ?? {}).filter(\n (name) =>\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n call.capabilities?.[name].optional !== true,\n ),\n );\n\n const requiredCapabilities = [\n ...requiredTopLevelCapabilities,\n ...requiredCallCapabilities,\n ];\n\n if (requiredCapabilities?.length) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capabilities: ${requiredCapabilities.join(\n ', ',\n )}`,\n );\n }\n\n if (capabilities?.auxiliaryFunds) {\n validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds: capabilities.auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n });\n }\n}\n\n/**\n * Validates EIP-7682 optional `requiredAssets` to see if the account and chain are supported, and that param is well-formed.\n *\n * docs: {@link https://eips.ethereum.org/EIPS/eip-7682#extended-usage-requiredassets-parameter}\n *\n * @param param - The parameter object.\n * @param param.auxiliaryFunds - The auxiliaryFunds param to validate.\n * @param param.auxiliaryFunds.optional - Metadata to signal for wallets that support this optional capability, while maintaining compatibility with wallets that do not.\n * @param param.auxiliaryFunds.requiredAssets - Metadata that enables a wallets support for `auxiliaryFunds` capability.\n * @param param.chainId - The chain ID of the incoming request.\n * @param param.keyringType - The type of keyring associated with the account.\n * @param param.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @throws JsonRpcError if auxiliary funds capability is not supported.\n */\nfunction validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n}: {\n auxiliaryFunds: {\n optional?: boolean;\n requiredAssets?: SendCallsRequiredAssetsParam[];\n };\n chainId: Hex;\n keyringType: KeyringTypes;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n // If we can make use of that capability then we should, but otherwise we can process the request and ignore the capability\n // so if the capability is signaled as optional, no validation is required, so we don't block the transaction from happening.\n if (auxiliaryFunds.optional) {\n return;\n }\n const isSupportedAccount =\n KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n\n if (!isSupportedAccount) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capability: ${SupportedCapabilities.AuxiliaryFunds}`,\n );\n }\n\n if (!isAuxiliaryFundsSupported(chainId)) {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedChain,\n `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`,\n );\n }\n\n if (!auxiliaryFunds?.requiredAssets) {\n return;\n }\n\n for (const asset of auxiliaryFunds.requiredAssets) {\n if (asset.standard !== 'erc20') {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedAsset,\n `The requested asset ${asset.address} is not available through the wallet’s auxiliary fund system: unsupported token standard ${asset.standard}`,\n );\n }\n }\n}\n\n/**\n * Validates whether an EIP-7702 upgrade is allowed for the given parameters.\n *\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @throws JsonRpcError if the upgrade is rejected due to user settings or account type.\n */\nfunction validateUpgrade(\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n) {\n if (chainBatchSupport?.delegationAddress) {\n return;\n }\n\n if (dismissSmartAccountSuggestionEnabled) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade disabled by the user',\n );\n }\n\n if (!KEYRING_TYPES_SUPPORTING_7702.includes(keyringType)) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported on account',\n );\n }\n}\n\n/**\n * Function to possibly deduplicate `auxiliaryFunds` capability `requiredAssets`.\n * Does nothing if no `requiredAssets` exists in `auxiliaryFunds` capability.\n *\n * @param sendCalls - The original sendCalls request.\n */\nfunction dedupeAuxiliaryFundsRequiredAssets(sendCalls: SendCallsPayload): void {\n if (sendCalls.capabilities?.auxiliaryFunds?.requiredAssets) {\n const { requiredAssets } = sendCalls.capabilities.auxiliaryFunds;\n // Group assets by their address (lowercased) and standard\n const grouped = groupBy(\n requiredAssets,\n (asset) => `${asset.address.toLowerCase()}-${asset.standard}`,\n );\n\n // For each group, sum the amounts and return a single asset\n const deduplicatedAssets = Object.values(grouped).map((group) => {\n if (group.length === 1) {\n return group[0];\n }\n\n const totalAmount = group.reduce((sum, asset) => {\n return sum + BigInt(asset.amount);\n }, 0n);\n\n return {\n ...group[0],\n amount: add0x(totalAmount.toString(16)),\n };\n });\n\n sendCalls.capabilities.auxiliaryFunds.requiredAssets = deduplicatedAssets;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"processSendCalls.mjs","sourceRoot":"","sources":["../../src/hooks/processSendCalls.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B;AAQ/D,OAAO,EAAE,uBAAuB,EAAE,yCAAyC;AAE3E,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,wBAAwB;;;AAEpD,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAEzC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,6BAA6B,EAC7B,WAAW,EACX,qBAAqB,EACrB,OAAO,EACR,yBAAqB;AAOtB,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AAkCjD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,gB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AA2C,CAC5C,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,kCAAkC,CAAC,SAA2B;IACrE,IAAI,SAAS,CAAC,YAAY,EAAE,cAAc,EAAE,cAAc,EAAE,CAAC;QAC3D,MAAM,EAAE,cAAc,EAAE,GAAG,SAAS,CAAC,YAAY,CAAC,cAAc,CAAC;QACjE,0DAA0D;QAC1D,MAAM,OAAO,GAAG,OAAO,CACrB,cAAc,EACd,CAAC,KAAK,EAAE,EAAE,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,WAAW,EAAE,IAAI,KAAK,CAAC,QAAQ,EAAE,CAC9D,CAAC;QAEF,4DAA4D;QAC5D,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC9D,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBACvB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;YAClB,CAAC;YAED,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;gBAC9C,OAAO,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;YACpC,CAAC,EAAE,EAAE,CAAC,CAAC;YAEP,OAAO;gBACL,GAAG,KAAK,CAAC,CAAC,CAAC;gBACX,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACxC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,YAAY,CAAC,cAAc,CAAC,cAAc,GAAG,kBAAkB,CAAC;IAC5E,CAAC;AACH,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n BatchTransactionParams,\n IsAtomicBatchSupportedResultEntry,\n SecurityAlertResponse,\n TransactionController,\n ValidateSecurityRequest,\n} from '@metamask/transaction-controller';\nimport { TransactionEnvelopeType } from '@metamask/transaction-controller';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\nimport { add0x, bytesToHex } from '@metamask/utils';\nimport { groupBy } from 'lodash';\nimport { parse, v4 as uuid } from 'uuid';\n\nimport {\n EIP5792ErrorCode,\n EIP7682ErrorCode,\n KEYRING_TYPES_SUPPORTING_7702,\n MessageType,\n SupportedCapabilities,\n VERSION,\n} from '../constants';\nimport type {\n EIP5792Messenger,\n SendCallsPayload,\n SendCallsRequiredAssetsParam,\n SendCallsResult,\n} from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link processSendCalls}\n */\nexport type ProcessSendCallsHooks = {\n /** Function to add a batch of transactions atomically */\n addTransactionBatch: TransactionController['addTransactionBatch'];\n /** Function to add a single transaction */\n addTransaction: TransactionController['addTransaction'];\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if atomic batching is supported for given parameters */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to validate security for transaction requests */\n validateSecurity: (\n securityAlertId: string,\n request: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * A valid JSON-RPC request object for `wallet_sendCalls`.\n */\nexport type ProcessSendCallsRequest = JsonRpcRequest & {\n /** The identifier for the network client that has been created for this RPC endpoint */\n networkClientId: string;\n /** The origin of the RPC request */\n origin?: string;\n};\n\n/**\n * Processes a sendCalls request for EIP-5792 transactions.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param params - The sendCalls parameters containing transaction calls and metadata.\n * @param req - The original JSON-RPC request.\n * @returns Promise resolving to a SendCallsResult containing the batch ID.\n */\nexport async function processSendCalls(\n hooks: ProcessSendCallsHooks,\n messenger: EIP5792Messenger,\n params: SendCallsPayload,\n req: ProcessSendCallsRequest,\n): Promise<SendCallsResult> {\n const {\n addTransactionBatch,\n addTransaction,\n getDismissSmartAccountSuggestionEnabled,\n isAtomicBatchSupported,\n validateSecurity: validateSecurityHook,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n const { calls, from: paramFrom } = params;\n const { networkClientId, origin } = req;\n const transactions = calls.map((call) => ({ params: call }));\n\n const { chainId } = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration;\n\n const from =\n paramFrom ??\n (messenger.call('AccountsController:getSelectedAccount').address as Hex);\n\n const securityAlertId = uuid();\n const validateSecurity = validateSecurityHook.bind(null, securityAlertId);\n\n let batchId: Hex;\n if (Object.keys(transactions).length === 1) {\n batchId = await processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls: params,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n } else {\n batchId = await processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n messenger,\n networkClientId,\n origin,\n sendCalls: params,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n }\n\n return { id: batchId };\n}\n\n/**\n * Processes a single transaction from a sendCalls request.\n *\n * @param params - Object containing all parameters needed for single transaction processing.\n * @param params.addTransaction - Function to add a single transaction.\n * @param params.chainId - The chain ID for the transaction.\n * @param params.from - The sender address.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.networkClientId - The network client ID.\n * @param params.origin - The origin of the request (optional).\n * @param params.securityAlertId - The security alert ID for this transaction.\n * @param params.sendCalls - The original sendCalls request.\n * @param params.transactions - Array containing the single transaction.\n * @param params.validateSecurity - Function to validate security for the transaction.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction.\n */\nasync function processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransaction: TransactionController['addTransaction'];\n chainId: Hex;\n from: Hex;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n securityAlertId: string;\n sendCalls: SendCallsPayload;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => void;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const keyringType = getAccountKeyringType(from, messenger);\n\n validateSingleSendCall(\n sendCalls,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n const txParams = {\n from,\n ...transactions[0].params,\n type: TransactionEnvelopeType.feeMarket,\n };\n\n const securityRequest: ValidateSecurityRequest = {\n method: MessageType.SendTransaction,\n params: [txParams],\n origin,\n };\n validateSecurity(securityRequest, chainId);\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const batchId = generateBatchId();\n\n await addTransaction(txParams, {\n networkClientId,\n origin,\n securityAlertResponse: { securityAlertId } as SecurityAlertResponse,\n batchId,\n });\n return batchId;\n}\n\n/**\n * Processes multiple transactions from a sendCalls request as an atomic batch.\n *\n * @param params - Object containing all parameters needed for multiple transaction processing.\n * @param params.addTransactionBatch - Function to add a batch of transactions atomically.\n * @param params.isAtomicBatchSupported - Function to check if atomic batching is supported.\n * @param params.chainId - The chain ID for the transactions.\n * @param params.from - The sender address.\n * @param params.getDismissSmartAccountSuggestionEnabled - Function to check if smart account suggestions are disabled.\n * @param params.networkClientId - The network client ID.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.origin - The origin of the request (optional).\n * @param params.sendCalls - The original sendCalls request.\n * @param params.securityAlertId - The security alert ID for this batch.\n * @param params.transactions - Array of transactions to process.\n * @param params.validateSecurity - Function to validate security for the transactions.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction batch.\n */\nasync function processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n networkClientId,\n messenger,\n origin,\n sendCalls,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n chainId: Hex;\n from: Hex;\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n sendCalls: SendCallsPayload;\n securityAlertId: string;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const batchSupport = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const chainBatchSupport = batchSupport?.[0];\n\n const keyringType = getAccountKeyringType(from, messenger);\n\n const dismissSmartAccountSuggestionEnabled =\n getDismissSmartAccountSuggestionEnabled();\n\n validateSendCalls(\n sendCalls,\n chainId,\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const result = await addTransactionBatch({\n from,\n networkClientId,\n origin,\n securityAlertId,\n transactions,\n validateSecurity,\n });\n return result.batchId;\n}\n\n/**\n * Generate a transaction batch ID.\n *\n * @returns A unique batch ID as a hexadecimal string.\n */\nfunction generateBatchId(): Hex {\n const idString = uuid();\n const idBytes = new Uint8Array(parse(idString));\n return bytesToHex(idBytes);\n}\n\n/**\n * Validates a single sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSingleSendCall(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateDappChainId(sendCalls, dappChainId);\n}\n\n/**\n * Validates a sendCalls request for multiple transactions.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSendCalls(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateUpgrade(\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n );\n}\n\n/**\n * Validates the version of a sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @throws JsonRpcError if the version is not supported.\n */\nfunction validateSendCallsVersion(sendCalls: SendCallsPayload) {\n const { version } = sendCalls;\n\n if (version !== VERSION) {\n throw rpcErrors.invalidInput(\n `Version not supported: Got ${version}, expected ${VERSION}`,\n );\n }\n}\n\n/**\n * Validates that the chain ID in the sendCalls request matches the dApp's selected network.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @throws JsonRpcError if the chain IDs don't match\n */\nfunction validateDappChainId(sendCalls: SendCallsPayload, dappChainId: Hex) {\n const { chainId: requestChainId } = sendCalls;\n\n if (\n requestChainId &&\n requestChainId.toLowerCase() !== dappChainId.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Chain ID must match the dApp selected network: Got ${requestChainId}, expected ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates the chain ID for sendCalls requests with additional EIP-7702 support checks.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param chainBatchSupport - Information about atomic batch support for the chain\n * @throws JsonRpcError if the chain ID doesn't match or EIP-7702 is not supported\n */\nfunction validateSendCallsChainId(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n) {\n validateDappChainId(sendCalls, dappChainId);\n if (!chainBatchSupport) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedChainId,\n `EIP-7702 not supported on chain: ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates that all required capabilities in the sendCalls request are supported.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n *\n * @throws JsonRpcError if unsupported non-optional capabilities are requested.\n */\nfunction validateCapabilities(\n sendCalls: SendCallsPayload,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n const { calls, capabilities, chainId } = sendCalls;\n\n const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter(\n (name) =>\n // Non optional capabilities other than `auxiliaryFunds` are not supported by the wallet\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n capabilities?.[name].optional !== true,\n );\n\n const requiredCallCapabilities = calls.flatMap((call) =>\n Object.keys(call.capabilities ?? {}).filter(\n (name) =>\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n call.capabilities?.[name].optional !== true,\n ),\n );\n\n const requiredCapabilities = [\n ...requiredTopLevelCapabilities,\n ...requiredCallCapabilities,\n ];\n\n if (requiredCapabilities?.length) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capabilities: ${requiredCapabilities.join(\n ', ',\n )}`,\n );\n }\n\n if (capabilities?.auxiliaryFunds) {\n validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds: capabilities.auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n });\n }\n}\n\n/**\n * Validates EIP-7682 optional `requiredAssets` to see if the account and chain are supported, and that param is well-formed.\n *\n * docs: {@link https://eips.ethereum.org/EIPS/eip-7682#extended-usage-requiredassets-parameter}\n *\n * @param param - The parameter object.\n * @param param.auxiliaryFunds - The auxiliaryFunds param to validate.\n * @param param.auxiliaryFunds.optional - Metadata to signal for wallets that support this optional capability, while maintaining compatibility with wallets that do not.\n * @param param.auxiliaryFunds.requiredAssets - Metadata that enables a wallets support for `auxiliaryFunds` capability.\n * @param param.chainId - The chain ID of the incoming request.\n * @param param.keyringType - The type of keyring associated with the account.\n * @param param.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @throws JsonRpcError if auxiliary funds capability is not supported.\n */\nfunction validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n}: {\n auxiliaryFunds: {\n optional?: boolean;\n requiredAssets?: SendCallsRequiredAssetsParam[];\n };\n chainId: Hex;\n keyringType: KeyringTypes;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n // If we can make use of that capability then we should, but otherwise we can process the request and ignore the capability\n // so if the capability is signaled as optional, no validation is required, so we don't block the transaction from happening.\n if (auxiliaryFunds.optional) {\n return;\n }\n const isSupportedAccount =\n KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n\n if (!isSupportedAccount) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capability: ${SupportedCapabilities.AuxiliaryFunds}`,\n );\n }\n\n if (!isAuxiliaryFundsSupported(chainId)) {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedChain,\n `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`,\n );\n }\n\n if (!auxiliaryFunds?.requiredAssets) {\n return;\n }\n\n for (const asset of auxiliaryFunds.requiredAssets) {\n if (asset.standard !== 'erc20') {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedAsset,\n `The requested asset ${asset.address} is not available through the wallet’s auxiliary fund system: unsupported token standard ${asset.standard}`,\n );\n }\n }\n}\n\n/**\n * Validates whether an EIP-7702 upgrade is allowed for the given parameters.\n *\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @throws JsonRpcError if the upgrade is rejected due to user settings or account type.\n */\nfunction validateUpgrade(\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n) {\n if (chainBatchSupport?.delegationAddress) {\n return;\n }\n\n if (dismissSmartAccountSuggestionEnabled) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade disabled by the user',\n );\n }\n\n if (!KEYRING_TYPES_SUPPORTING_7702.includes(keyringType)) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported on account',\n );\n }\n}\n\n/**\n * Function to possibly deduplicate `auxiliaryFunds` capability `requiredAssets`.\n * Does nothing if no `requiredAssets` exists in `auxiliaryFunds` capability.\n *\n * @param sendCalls - The original sendCalls request.\n */\nfunction dedupeAuxiliaryFundsRequiredAssets(sendCalls: SendCallsPayload): void {\n if (sendCalls.capabilities?.auxiliaryFunds?.requiredAssets) {\n const { requiredAssets } = sendCalls.capabilities.auxiliaryFunds;\n // Group assets by their address (lowercased) and standard\n const grouped = groupBy(\n requiredAssets,\n (asset) => `${asset.address.toLowerCase()}-${asset.standard}`,\n );\n\n // For each group, sum the amounts and return a single asset\n const deduplicatedAssets = Object.values(grouped).map((group) => {\n if (group.length === 1) {\n return group[0];\n }\n\n const totalAmount = group.reduce((sum, asset) => {\n return sum + BigInt(asset.amount);\n }, 0n);\n\n return {\n ...group[0],\n amount: add0x(totalAmount.toString(16)),\n };\n });\n\n sendCalls.capabilities.auxiliaryFunds.requiredAssets = deduplicatedAssets;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/eip-5792-middleware",
|
|
3
|
-
"version": "2.0.0-preview-
|
|
3
|
+
"version": "2.0.0-preview-565dfca2",
|
|
4
4
|
"description": "Implements the JSON-RPC methods for sending multiple calls from the user's wallet, and checking their status, as referenced in EIP-5792",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|