@metamask/eip-5792-middleware 1.1.0 → 1.2.1
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 +19 -1
- package/dist/constants.cjs +12 -1
- package/dist/constants.cjs.map +1 -1
- package/dist/constants.d.cts +8 -0
- package/dist/constants.d.cts.map +1 -1
- package/dist/constants.d.mts +8 -0
- package/dist/constants.d.mts.map +1 -1
- package/dist/constants.mjs +11 -0
- package/dist/constants.mjs.map +1 -1
- package/dist/hooks/getCapabilities.cjs +10 -4
- package/dist/hooks/getCapabilities.cjs.map +1 -1
- package/dist/hooks/getCapabilities.d.cts +2 -0
- package/dist/hooks/getCapabilities.d.cts.map +1 -1
- package/dist/hooks/getCapabilities.d.mts +2 -0
- package/dist/hooks/getCapabilities.d.mts.map +1 -1
- package/dist/hooks/getCapabilities.mjs +10 -4
- package/dist/hooks/getCapabilities.mjs.map +1 -1
- package/dist/hooks/processSendCalls.cjs +104 -13
- package/dist/hooks/processSendCalls.cjs.map +1 -1
- package/dist/hooks/processSendCalls.d.cts +2 -0
- package/dist/hooks/processSendCalls.d.cts.map +1 -1
- package/dist/hooks/processSendCalls.d.mts +2 -0
- package/dist/hooks/processSendCalls.d.mts.map +1 -1
- package/dist/hooks/processSendCalls.mjs +107 -15
- package/dist/hooks/processSendCalls.mjs.map +1 -1
- package/dist/types.cjs +6 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.cts +25 -0
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.mts +25 -0
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +6 -0
- package/dist/types.mjs.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processSendCalls.cjs","sourceRoot":"","sources":["../../src/hooks/processSendCalls.ts"],"names":[],"mappings":";;;AACA,qDAA+D;AAQ/D,6EAA2E;AAE3E,2CAA6C;AAC7C,+BAAyC;AAEzC,gDA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I,CAAC,IAAI,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,MAAM,CACzC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,YAAY,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,KAAK,IAAI,CACtD,CACF,CAAC;IAEF,MAAM,oBAAoB,GAAG;QAC3B,GAAG,4BAA4B;QAC/B,GAAG,wBAAwB;KAC5B,CAAC;IAEF,IAAI,oBAAoB,EAAE,MAAM,EAAE;QAChC,MAAM,IAAI,yBAAY,CACpB,4BAAgB,CAAC,gCAAgC,EACjD,0CAA0C,oBAAoB,CAAC,IAAI,CACjE,IAAI,CACL,EAAE,CACJ,CAAC;KACH;AACH,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,eAAe,CACtB,oCAA6C,EAC7C,iBAAgE,EAChE,WAAyB;IAEzB,IAAI,iBAAiB,EAAE,iBAAiB,EAAE;QACxC,OAAO;KACR;IAED,IAAI,oCAAoC,EAAE;QACxC,MAAM,IAAI,yBAAY,CACpB,4BAAgB,CAAC,eAAe,EAChC,uCAAuC,CACxC,CAAC;KACH;IAED,IAAI,CAAC,yCAA6B,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QACxD,MAAM,IAAI,yBAAY,CACpB,4BAAgB,CAAC,eAAe,EAChC,2CAA2C,CAC5C,CAAC;KACH;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 { bytesToHex } from '@metamask/utils';\nimport { parse, v4 as uuid } from 'uuid';\n\nimport {\n EIP5792ErrorCode,\n KEYRING_TYPES_SUPPORTING_7702,\n MessageType,\n VERSION,\n} from '../constants';\nimport type {\n EIP5792Messenger,\n SendCallsPayload,\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};\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 } = 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 networkClientId,\n origin,\n securityAlertId,\n sendCalls: params,\n transactions,\n validateSecurity,\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 });\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.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 * @returns Promise resolving to the generated batch ID for the transaction.\n */\nasync function processSingleTransaction({\n addTransaction,\n chainId,\n from,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls,\n transactions,\n validateSecurity,\n}: {\n addTransaction: TransactionController['addTransaction'];\n chainId: Hex;\n from: Hex;\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}) {\n validateSingleSendCall(sendCalls, chainId);\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 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 * @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}: {\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}) {\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 );\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 */\nfunction validateSingleSendCall(sendCalls: SendCallsPayload, dappChainId: Hex) {\n validateSendCallsVersion(sendCalls);\n validateCapabilities(sendCalls);\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 */\nfunction validateSendCalls(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n) {\n validateSendCallsVersion(sendCalls);\n validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);\n validateCapabilities(sendCalls);\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 * @throws JsonRpcError if unsupported non-optional capabilities are requested.\n */\nfunction validateCapabilities(sendCalls: SendCallsPayload) {\n const { calls, capabilities } = sendCalls;\n\n const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter(\n (name) => capabilities?.[name].optional !== true,\n );\n\n const requiredCallCapabilities = calls.flatMap((call) =>\n Object.keys(call.capabilities ?? {}).filter(\n (name) => 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\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"]}
|
|
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,CA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AAK,CAAC,MAAM,KAAK,CAAC,EAAE;gBACtB,OAAO,KAAK,CAAC,CAAC,CAAC,CAAC;aACjB;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;KAC3E;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"]}
|
|
@@ -15,6 +15,8 @@ export type ProcessSendCallsHooks = {
|
|
|
15
15
|
isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];
|
|
16
16
|
/** Function to validate security for transaction requests */
|
|
17
17
|
validateSecurity: (securityAlertId: string, request: ValidateSecurityRequest, chainId: Hex) => Promise<void>;
|
|
18
|
+
/** Function to validate if auxiliary funds capability is supported. */
|
|
19
|
+
isAuxiliaryFundsSupported: (chainId: Hex) => boolean;
|
|
18
20
|
};
|
|
19
21
|
/**
|
|
20
22
|
* A valid JSON-RPC request object for `wallet_sendCalls`.
|
|
@@ -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;
|
|
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,6DAA6D;IAC7D,gBAAgB,EAAE,CAChB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,GAAG,KACT,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,uEAAuE;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"}
|
|
@@ -15,6 +15,8 @@ export type ProcessSendCallsHooks = {
|
|
|
15
15
|
isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];
|
|
16
16
|
/** Function to validate security for transaction requests */
|
|
17
17
|
validateSecurity: (securityAlertId: string, request: ValidateSecurityRequest, chainId: Hex) => Promise<void>;
|
|
18
|
+
/** Function to validate if auxiliary funds capability is supported. */
|
|
19
|
+
isAuxiliaryFundsSupported: (chainId: Hex) => boolean;
|
|
18
20
|
};
|
|
19
21
|
/**
|
|
20
22
|
* A valid JSON-RPC request object for `wallet_sendCalls`.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processSendCalls.d.mts","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;
|
|
1
|
+
{"version":3,"file":"processSendCalls.d.mts","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,6DAA6D;IAC7D,gBAAgB,EAAE,CAChB,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,uBAAuB,EAChC,OAAO,EAAE,GAAG,KACT,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,uEAAuE;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"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { JsonRpcError, rpcErrors } from "@metamask/rpc-errors";
|
|
2
2
|
import { TransactionEnvelopeType } from "@metamask/transaction-controller";
|
|
3
|
-
import { bytesToHex } from "@metamask/utils";
|
|
3
|
+
import { add0x, bytesToHex } from "@metamask/utils";
|
|
4
|
+
import $lodash from "lodash";
|
|
5
|
+
const { groupBy } = $lodash;
|
|
4
6
|
import { parse, v4 as uuid } from "uuid";
|
|
5
|
-
import { EIP5792ErrorCode, KEYRING_TYPES_SUPPORTING_7702, MessageType, VERSION } from "../constants.mjs";
|
|
7
|
+
import { EIP5792ErrorCode, EIP7682ErrorCode, KEYRING_TYPES_SUPPORTING_7702, MessageType, SupportedCapabilities, VERSION } from "../constants.mjs";
|
|
6
8
|
import { getAccountKeyringType } from "../utils.mjs";
|
|
7
9
|
/**
|
|
8
10
|
* Processes a sendCalls request for EIP-5792 transactions.
|
|
@@ -14,7 +16,7 @@ import { getAccountKeyringType } from "../utils.mjs";
|
|
|
14
16
|
* @returns Promise resolving to a SendCallsResult containing the batch ID.
|
|
15
17
|
*/
|
|
16
18
|
export async function processSendCalls(hooks, messenger, params, req) {
|
|
17
|
-
const { addTransactionBatch, addTransaction, getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported, validateSecurity: validateSecurityHook, } = hooks;
|
|
19
|
+
const { addTransactionBatch, addTransaction, getDismissSmartAccountSuggestionEnabled, isAtomicBatchSupported, validateSecurity: validateSecurityHook, isAuxiliaryFundsSupported, } = hooks;
|
|
18
20
|
const { calls, from: paramFrom } = params;
|
|
19
21
|
const { networkClientId, origin } = req;
|
|
20
22
|
const transactions = calls.map((call) => ({ params: call }));
|
|
@@ -29,12 +31,14 @@ export async function processSendCalls(hooks, messenger, params, req) {
|
|
|
29
31
|
addTransaction,
|
|
30
32
|
chainId,
|
|
31
33
|
from,
|
|
34
|
+
messenger,
|
|
32
35
|
networkClientId,
|
|
33
36
|
origin,
|
|
34
37
|
securityAlertId,
|
|
35
38
|
sendCalls: params,
|
|
36
39
|
transactions,
|
|
37
40
|
validateSecurity,
|
|
41
|
+
isAuxiliaryFundsSupported,
|
|
38
42
|
});
|
|
39
43
|
}
|
|
40
44
|
else {
|
|
@@ -51,6 +55,7 @@ export async function processSendCalls(hooks, messenger, params, req) {
|
|
|
51
55
|
securityAlertId,
|
|
52
56
|
transactions,
|
|
53
57
|
validateSecurity,
|
|
58
|
+
isAuxiliaryFundsSupported,
|
|
54
59
|
});
|
|
55
60
|
}
|
|
56
61
|
return { id: batchId };
|
|
@@ -62,16 +67,19 @@ export async function processSendCalls(hooks, messenger, params, req) {
|
|
|
62
67
|
* @param params.addTransaction - Function to add a single transaction.
|
|
63
68
|
* @param params.chainId - The chain ID for the transaction.
|
|
64
69
|
* @param params.from - The sender address.
|
|
70
|
+
* @param params.messenger - Messenger instance for controller communication.
|
|
65
71
|
* @param params.networkClientId - The network client ID.
|
|
66
72
|
* @param params.origin - The origin of the request (optional).
|
|
67
73
|
* @param params.securityAlertId - The security alert ID for this transaction.
|
|
68
74
|
* @param params.sendCalls - The original sendCalls request.
|
|
69
75
|
* @param params.transactions - Array containing the single transaction.
|
|
70
76
|
* @param params.validateSecurity - Function to validate security for the transaction.
|
|
77
|
+
* @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
71
78
|
* @returns Promise resolving to the generated batch ID for the transaction.
|
|
72
79
|
*/
|
|
73
|
-
async function processSingleTransaction({ addTransaction, chainId, from, networkClientId, origin, securityAlertId, sendCalls, transactions, validateSecurity, }) {
|
|
74
|
-
|
|
80
|
+
async function processSingleTransaction({ addTransaction, chainId, from, messenger, networkClientId, origin, securityAlertId, sendCalls, transactions, validateSecurity, isAuxiliaryFundsSupported, }) {
|
|
81
|
+
const keyringType = getAccountKeyringType(from, messenger);
|
|
82
|
+
validateSingleSendCall(sendCalls, chainId, keyringType, isAuxiliaryFundsSupported);
|
|
75
83
|
const txParams = {
|
|
76
84
|
from,
|
|
77
85
|
...transactions[0].params,
|
|
@@ -83,6 +91,7 @@ async function processSingleTransaction({ addTransaction, chainId, from, network
|
|
|
83
91
|
origin,
|
|
84
92
|
};
|
|
85
93
|
validateSecurity(securityRequest, chainId);
|
|
94
|
+
dedupeAuxiliaryFundsRequiredAssets(sendCalls);
|
|
86
95
|
const batchId = generateBatchId();
|
|
87
96
|
await addTransaction(txParams, {
|
|
88
97
|
networkClientId,
|
|
@@ -108,9 +117,10 @@ async function processSingleTransaction({ addTransaction, chainId, from, network
|
|
|
108
117
|
* @param params.securityAlertId - The security alert ID for this batch.
|
|
109
118
|
* @param params.transactions - Array of transactions to process.
|
|
110
119
|
* @param params.validateSecurity - Function to validate security for the transactions.
|
|
120
|
+
* @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
111
121
|
* @returns Promise resolving to the generated batch ID for the transaction batch.
|
|
112
122
|
*/
|
|
113
|
-
async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSupported, chainId, from, getDismissSmartAccountSuggestionEnabled, networkClientId, messenger, origin, sendCalls, securityAlertId, transactions, validateSecurity, }) {
|
|
123
|
+
async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSupported, chainId, from, getDismissSmartAccountSuggestionEnabled, networkClientId, messenger, origin, sendCalls, securityAlertId, transactions, validateSecurity, isAuxiliaryFundsSupported, }) {
|
|
114
124
|
const batchSupport = await isAtomicBatchSupported({
|
|
115
125
|
address: from,
|
|
116
126
|
chainIds: [chainId],
|
|
@@ -118,7 +128,8 @@ async function processMultipleTransaction({ addTransactionBatch, isAtomicBatchSu
|
|
|
118
128
|
const chainBatchSupport = batchSupport?.[0];
|
|
119
129
|
const keyringType = getAccountKeyringType(from, messenger);
|
|
120
130
|
const dismissSmartAccountSuggestionEnabled = getDismissSmartAccountSuggestionEnabled();
|
|
121
|
-
validateSendCalls(sendCalls, chainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType);
|
|
131
|
+
validateSendCalls(sendCalls, chainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType, isAuxiliaryFundsSupported);
|
|
132
|
+
dedupeAuxiliaryFundsRequiredAssets(sendCalls);
|
|
122
133
|
const result = await addTransactionBatch({
|
|
123
134
|
from,
|
|
124
135
|
networkClientId,
|
|
@@ -144,10 +155,12 @@ function generateBatchId() {
|
|
|
144
155
|
*
|
|
145
156
|
* @param sendCalls - The sendCalls request to validate.
|
|
146
157
|
* @param dappChainId - The chain ID that the dApp is connected to.
|
|
158
|
+
* @param keyringType - The type of keyring associated with the account.
|
|
159
|
+
* @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
147
160
|
*/
|
|
148
|
-
function validateSingleSendCall(sendCalls, dappChainId) {
|
|
161
|
+
function validateSingleSendCall(sendCalls, dappChainId, keyringType, isAuxiliaryFundsSupported) {
|
|
149
162
|
validateSendCallsVersion(sendCalls);
|
|
150
|
-
validateCapabilities(sendCalls);
|
|
163
|
+
validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);
|
|
151
164
|
validateDappChainId(sendCalls, dappChainId);
|
|
152
165
|
}
|
|
153
166
|
/**
|
|
@@ -158,11 +171,12 @@ function validateSingleSendCall(sendCalls, dappChainId) {
|
|
|
158
171
|
* @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.
|
|
159
172
|
* @param chainBatchSupport - Information about atomic batch support for the chain.
|
|
160
173
|
* @param keyringType - The type of keyring associated with the account.
|
|
174
|
+
* @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
161
175
|
*/
|
|
162
|
-
function validateSendCalls(sendCalls, dappChainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType) {
|
|
176
|
+
function validateSendCalls(sendCalls, dappChainId, dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType, isAuxiliaryFundsSupported) {
|
|
163
177
|
validateSendCallsVersion(sendCalls);
|
|
164
178
|
validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);
|
|
165
|
-
validateCapabilities(sendCalls);
|
|
179
|
+
validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);
|
|
166
180
|
validateUpgrade(dismissSmartAccountSuggestionEnabled, chainBatchSupport, keyringType);
|
|
167
181
|
}
|
|
168
182
|
/**
|
|
@@ -209,12 +223,19 @@ function validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport) {
|
|
|
209
223
|
* Validates that all required capabilities in the sendCalls request are supported.
|
|
210
224
|
*
|
|
211
225
|
* @param sendCalls - The sendCalls request to validate.
|
|
226
|
+
* @param keyringType - The type of keyring associated with the account.
|
|
227
|
+
* @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
228
|
+
*
|
|
212
229
|
* @throws JsonRpcError if unsupported non-optional capabilities are requested.
|
|
213
230
|
*/
|
|
214
|
-
function validateCapabilities(sendCalls) {
|
|
215
|
-
const { calls, capabilities } = sendCalls;
|
|
216
|
-
const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter((name) =>
|
|
217
|
-
|
|
231
|
+
function validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported) {
|
|
232
|
+
const { calls, capabilities, chainId } = sendCalls;
|
|
233
|
+
const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter((name) =>
|
|
234
|
+
// Non optional capabilities other than `auxiliaryFunds` are not supported by the wallet
|
|
235
|
+
name !== SupportedCapabilities.AuxiliaryFunds.toString() &&
|
|
236
|
+
capabilities?.[name].optional !== true);
|
|
237
|
+
const requiredCallCapabilities = calls.flatMap((call) => Object.keys(call.capabilities ?? {}).filter((name) => name !== SupportedCapabilities.AuxiliaryFunds.toString() &&
|
|
238
|
+
call.capabilities?.[name].optional !== true));
|
|
218
239
|
const requiredCapabilities = [
|
|
219
240
|
...requiredTopLevelCapabilities,
|
|
220
241
|
...requiredCallCapabilities,
|
|
@@ -222,6 +243,50 @@ function validateCapabilities(sendCalls) {
|
|
|
222
243
|
if (requiredCapabilities?.length) {
|
|
223
244
|
throw new JsonRpcError(EIP5792ErrorCode.UnsupportedNonOptionalCapability, `Unsupported non-optional capabilities: ${requiredCapabilities.join(', ')}`);
|
|
224
245
|
}
|
|
246
|
+
if (capabilities?.auxiliaryFunds) {
|
|
247
|
+
validateAuxFundsSupportAndRequiredAssets({
|
|
248
|
+
auxiliaryFunds: capabilities.auxiliaryFunds,
|
|
249
|
+
chainId,
|
|
250
|
+
keyringType,
|
|
251
|
+
isAuxiliaryFundsSupported,
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Validates EIP-7682 optional `requiredAssets` to see if the account and chain are supported, and that param is well-formed.
|
|
257
|
+
*
|
|
258
|
+
* docs: {@link https://eips.ethereum.org/EIPS/eip-7682#extended-usage-requiredassets-parameter}
|
|
259
|
+
*
|
|
260
|
+
* @param param - The parameter object.
|
|
261
|
+
* @param param.auxiliaryFunds - The auxiliaryFunds param to validate.
|
|
262
|
+
* @param param.auxiliaryFunds.optional - Metadata to signal for wallets that support this optional capability, while maintaining compatibility with wallets that do not.
|
|
263
|
+
* @param param.auxiliaryFunds.requiredAssets - Metadata that enables a wallets support for `auxiliaryFunds` capability.
|
|
264
|
+
* @param param.chainId - The chain ID of the incoming request.
|
|
265
|
+
* @param param.keyringType - The type of keyring associated with the account.
|
|
266
|
+
* @param param.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.
|
|
267
|
+
* @throws JsonRpcError if auxiliary funds capability is not supported.
|
|
268
|
+
*/
|
|
269
|
+
function validateAuxFundsSupportAndRequiredAssets({ auxiliaryFunds, chainId, keyringType, isAuxiliaryFundsSupported, }) {
|
|
270
|
+
// If we can make use of that capability then we should, but otherwise we can process the request and ignore the capability
|
|
271
|
+
// so if the capability is signaled as optional, no validation is required, so we don't block the transaction from happening.
|
|
272
|
+
if (auxiliaryFunds.optional) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
const isSupportedAccount = KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);
|
|
276
|
+
if (!isSupportedAccount) {
|
|
277
|
+
throw new JsonRpcError(EIP5792ErrorCode.UnsupportedNonOptionalCapability, `Unsupported non-optional capability: ${SupportedCapabilities.AuxiliaryFunds}`);
|
|
278
|
+
}
|
|
279
|
+
if (!isAuxiliaryFundsSupported(chainId)) {
|
|
280
|
+
throw new JsonRpcError(EIP7682ErrorCode.UnsupportedChain, `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`);
|
|
281
|
+
}
|
|
282
|
+
if (!auxiliaryFunds?.requiredAssets) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
for (const asset of auxiliaryFunds.requiredAssets) {
|
|
286
|
+
if (asset.standard !== 'erc20') {
|
|
287
|
+
throw new JsonRpcError(EIP7682ErrorCode.UnsupportedAsset, `The requested asset ${asset.address} is not available through the wallet’s auxiliary fund system: unsupported token standard ${asset.standard}`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
225
290
|
}
|
|
226
291
|
/**
|
|
227
292
|
* Validates whether an EIP-7702 upgrade is allowed for the given parameters.
|
|
@@ -242,4 +307,31 @@ function validateUpgrade(dismissSmartAccountSuggestionEnabled, chainBatchSupport
|
|
|
242
307
|
throw new JsonRpcError(EIP5792ErrorCode.RejectedUpgrade, 'EIP-7702 upgrade not supported on account');
|
|
243
308
|
}
|
|
244
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Function to possibly deduplicate `auxiliaryFunds` capability `requiredAssets`.
|
|
312
|
+
* Does nothing if no `requiredAssets` exists in `auxiliaryFunds` capability.
|
|
313
|
+
*
|
|
314
|
+
* @param sendCalls - The original sendCalls request.
|
|
315
|
+
*/
|
|
316
|
+
function dedupeAuxiliaryFundsRequiredAssets(sendCalls) {
|
|
317
|
+
if (sendCalls.capabilities?.auxiliaryFunds?.requiredAssets) {
|
|
318
|
+
const { requiredAssets } = sendCalls.capabilities.auxiliaryFunds;
|
|
319
|
+
// Group assets by their address (lowercased) and standard
|
|
320
|
+
const grouped = groupBy(requiredAssets, (asset) => `${asset.address.toLowerCase()}-${asset.standard}`);
|
|
321
|
+
// For each group, sum the amounts and return a single asset
|
|
322
|
+
const deduplicatedAssets = Object.values(grouped).map((group) => {
|
|
323
|
+
if (group.length === 1) {
|
|
324
|
+
return group[0];
|
|
325
|
+
}
|
|
326
|
+
const totalAmount = group.reduce((sum, asset) => {
|
|
327
|
+
return sum + BigInt(asset.amount);
|
|
328
|
+
}, 0n);
|
|
329
|
+
return {
|
|
330
|
+
...group[0],
|
|
331
|
+
amount: add0x(totalAmount.toString(16)),
|
|
332
|
+
};
|
|
333
|
+
});
|
|
334
|
+
sendCalls.capabilities.auxiliaryFunds.requiredAssets = deduplicatedAssets;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
245
337
|
//# sourceMappingURL=processSendCalls.mjs.map
|
|
@@ -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,UAAU,EAAE,wBAAwB;AAC7C,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAEzC,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,WAAW,EACX,OAAO,EACR,yBAAqB;AAMtB,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AAgCjD;;;;;;;;GAQG;AACH,MAAM,CAAC,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,GACvC,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,MA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;IAED,IAAI,CAAC,6BAA6B,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE;QACxD,MAAM,IAAI,YAAY,CACpB,gBAAgB,CAAC,eAAe,EAChC,2CAA2C,CAC5C,CAAC;KACH;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 { bytesToHex } from '@metamask/utils';\nimport { parse, v4 as uuid } from 'uuid';\n\nimport {\n EIP5792ErrorCode,\n KEYRING_TYPES_SUPPORTING_7702,\n MessageType,\n VERSION,\n} from '../constants';\nimport type {\n EIP5792Messenger,\n SendCallsPayload,\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};\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 } = 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 networkClientId,\n origin,\n securityAlertId,\n sendCalls: params,\n transactions,\n validateSecurity,\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 });\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.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 * @returns Promise resolving to the generated batch ID for the transaction.\n */\nasync function processSingleTransaction({\n addTransaction,\n chainId,\n from,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls,\n transactions,\n validateSecurity,\n}: {\n addTransaction: TransactionController['addTransaction'];\n chainId: Hex;\n from: Hex;\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}) {\n validateSingleSendCall(sendCalls, chainId);\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 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 * @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}: {\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}) {\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 );\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 */\nfunction validateSingleSendCall(sendCalls: SendCallsPayload, dappChainId: Hex) {\n validateSendCallsVersion(sendCalls);\n validateCapabilities(sendCalls);\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 */\nfunction validateSendCalls(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n) {\n validateSendCallsVersion(sendCalls);\n validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);\n validateCapabilities(sendCalls);\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 * @throws JsonRpcError if unsupported non-optional capabilities are requested.\n */\nfunction validateCapabilities(sendCalls: SendCallsPayload) {\n const { calls, capabilities } = sendCalls;\n\n const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter(\n (name) => capabilities?.[name].optional !== true,\n );\n\n const requiredCallCapabilities = calls.flatMap((call) =>\n Object.keys(call.capabilities ?? {}).filter(\n (name) => 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\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"]}
|
|
1
|
+
{"version":3,"file":"processSendCalls.mjs","sourceRoot":"","sources":["../../src/hooks/processSendCalls.ts"],"names":[],"mappings":"AACA,OAAO,EA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C;KAC3E;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/dist/types.cjs
CHANGED
|
@@ -11,8 +11,14 @@ exports.GetCapabilitiesStruct = (0, superstruct_1.tuple)([
|
|
|
11
11
|
utils_1.HexChecksumAddressStruct,
|
|
12
12
|
(0, superstruct_1.optional)((0, superstruct_1.array)(utils_1.StrictHexStruct)),
|
|
13
13
|
]);
|
|
14
|
+
const RequiredAssetStruct = (0, superstruct_1.type)({
|
|
15
|
+
address: (0, superstruct_1.nonempty)(utils_1.HexChecksumAddressStruct),
|
|
16
|
+
amount: (0, superstruct_1.nonempty)(utils_1.StrictHexStruct),
|
|
17
|
+
standard: (0, superstruct_1.nonempty)((0, superstruct_1.string)()),
|
|
18
|
+
});
|
|
14
19
|
exports.CapabilitiesStruct = (0, superstruct_1.record)((0, superstruct_1.string)(), (0, superstruct_1.type)({
|
|
15
20
|
optional: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
|
|
21
|
+
requiredAssets: (0, superstruct_1.optional)((0, superstruct_1.array)(RequiredAssetStruct)),
|
|
16
22
|
}));
|
|
17
23
|
exports.SendCallsStruct = (0, superstruct_1.tuple)([
|
|
18
24
|
(0, superstruct_1.object)({
|
package/dist/types.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAWA,uDAU+B;AAG/B,2CAA4E;
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AAWA,uDAU+B;AAG/B,2CAA4E;AAmE5E,kBAAkB;AAClB,0FAA0F;AAC1F,+CAA+C;AAClC,QAAA,oBAAoB,GAAG,IAAA,mBAAK,EAAC,CAAC,uBAAe,CAAC,CAAC,CAAC;AAEhD,QAAA,qBAAqB,GAAG,IAAA,mBAAK,EAAC;IACzC,gCAAwB;IACxB,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,uBAAe,CAAC,CAAC;CACjC,CAAC,CAAC;AAEH,MAAM,mBAAmB,GAAG,IAAA,kBAAI,EAAC;IAC/B,OAAO,EAAE,IAAA,sBAAQ,EAAC,gCAAwB,CAAC;IAC3C,MAAM,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;IACjC,QAAQ,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;CAC7B,CAAC,CAAC;AAEU,QAAA,kBAAkB,GAAG,IAAA,oBAAM,EACtC,IAAA,oBAAM,GAAE,EACR,IAAA,kBAAI,EAAC;IACH,QAAQ,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;IAC7B,cAAc,EAAE,IAAA,sBAAQ,EAAC,IAAA,mBAAK,EAAC,mBAAmB,CAAC,CAAC;CACrD,CAAC,CACH,CAAC;AAEW,QAAA,eAAe,GAAG,IAAA,mBAAK,EAAC;IACnC,IAAA,oBAAM,EAAC;QACL,OAAO,EAAE,IAAA,sBAAQ,EAAC,IAAA,oBAAM,GAAE,CAAC;QAC3B,EAAE,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;QAC7B,IAAI,EAAE,IAAA,sBAAQ,EAAC,gCAAwB,CAAC;QACxC,OAAO,EAAE,uBAAe;QACxB,cAAc,EAAE,IAAA,qBAAO,GAAE;QACzB,KAAK,EAAE,IAAA,mBAAK,EACV,IAAA,oBAAM,EAAC;YACL,EAAE,EAAE,IAAA,sBAAQ,EAAC,gCAAwB,CAAC;YACtC,IAAI,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;YAC/B,KAAK,EAAE,IAAA,sBAAQ,EAAC,uBAAe,CAAC;YAChC,YAAY,EAAE,IAAA,sBAAQ,EAAC,0BAAkB,CAAC;SAC3C,CAAC,CACH;QACD,YAAY,EAAE,IAAA,sBAAQ,EAAC,0BAAkB,CAAC;KAC3C,CAAC;CACH,CAAC,CAAC","sourcesContent":["import type {\n AccountsControllerGetSelectedAccountAction,\n AccountsControllerGetStateAction,\n} from '@metamask/accounts-controller';\nimport type { Messenger } from '@metamask/base-controller';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n} from '@metamask/network-controller';\nimport type { PreferencesControllerGetStateAction } from '@metamask/preferences-controller';\nimport type { Infer } from '@metamask/superstruct';\nimport {\n array,\n boolean,\n nonempty,\n object,\n optional,\n record,\n string,\n tuple,\n type,\n} from '@metamask/superstruct';\nimport type { TransactionControllerGetStateAction } from '@metamask/transaction-controller';\nimport type { Hex, Json, JsonRpcRequest } from '@metamask/utils';\nimport { HexChecksumAddressStruct, StrictHexStruct } from '@metamask/utils';\n\ntype Actions =\n | AccountsControllerGetStateAction\n | AccountsControllerGetSelectedAccountAction\n | NetworkControllerGetNetworkClientByIdAction\n | TransactionControllerGetStateAction\n | PreferencesControllerGetStateAction\n | NetworkControllerGetStateAction;\n\nexport type EIP5792Messenger = Messenger<Actions, never>;\n\n// wallet_getCallStatus\nexport type GetCallsStatusParams = Infer<typeof GetCallsStatusStruct>;\n\nexport type GetCallsStatusResult = {\n version: string;\n id: Hex;\n chainId: Hex;\n status: number;\n atomic: boolean;\n receipts?: {\n logs: {\n address: Hex;\n data: Hex;\n topics: Hex[];\n }[];\n status: '0x0' | '0x1';\n blockHash: Hex;\n blockNumber: Hex;\n gasUsed: Hex;\n transactionHash: Hex;\n }[];\n capabilities?: Record<string, Json>;\n};\n\nexport type GetCallsStatusHook = (\n id: GetCallsStatusParams[0],\n req: JsonRpcRequest,\n) => Promise<GetCallsStatusResult>;\n\n// wallet_getCapabilities\nexport type GetCapabilitiesParams = Infer<typeof GetCapabilitiesStruct>;\nexport type GetCapabilitiesResult = Record<Hex, Record<string, Json>>;\n\nexport type GetCapabilitiesHook = (\n address: GetCapabilitiesParams[0],\n chainIds: GetCapabilitiesParams[1],\n req: JsonRpcRequest,\n) => Promise<GetCapabilitiesResult>;\n\n// wallet_sendCalls\nexport type SendCallsParams = Infer<typeof SendCallsStruct>;\nexport type SendCallsPayload = SendCallsParams[0];\n\nexport type SendCallsRequiredAssetsParam = Infer<typeof RequiredAssetStruct>;\n\nexport type SendCallsResult = {\n id: Hex;\n capabilities?: Record<string, Json>;\n};\n\nexport type ProcessSendCallsHook = (\n sendCalls: SendCallsPayload,\n req: JsonRpcRequest,\n) => Promise<SendCallsResult>;\n\n// /** Structs **/\n// Even though these aren't actually typescript types, these structs essentially represent\n// runtime types, so we keep them in this file.\nexport const GetCallsStatusStruct = tuple([StrictHexStruct]);\n\nexport const GetCapabilitiesStruct = tuple([\n HexChecksumAddressStruct,\n optional(array(StrictHexStruct)),\n]);\n\nconst RequiredAssetStruct = type({\n address: nonempty(HexChecksumAddressStruct),\n amount: nonempty(StrictHexStruct),\n standard: nonempty(string()),\n});\n\nexport const CapabilitiesStruct = record(\n string(),\n type({\n optional: optional(boolean()),\n requiredAssets: optional(array(RequiredAssetStruct)),\n }),\n);\n\nexport const SendCallsStruct = tuple([\n object({\n version: nonempty(string()),\n id: optional(StrictHexStruct),\n from: optional(HexChecksumAddressStruct),\n chainId: StrictHexStruct,\n atomicRequired: boolean(),\n calls: array(\n object({\n to: optional(HexChecksumAddressStruct),\n data: optional(StrictHexStruct),\n value: optional(StrictHexStruct),\n capabilities: optional(CapabilitiesStruct),\n }),\n ),\n capabilities: optional(CapabilitiesStruct),\n }),\n]);\n"]}
|
package/dist/types.d.cts
CHANGED
|
@@ -34,6 +34,7 @@ export type GetCapabilitiesResult = Record<Hex, Record<string, Json>>;
|
|
|
34
34
|
export type GetCapabilitiesHook = (address: GetCapabilitiesParams[0], chainIds: GetCapabilitiesParams[1], req: JsonRpcRequest) => Promise<GetCapabilitiesResult>;
|
|
35
35
|
export type SendCallsParams = Infer<typeof SendCallsStruct>;
|
|
36
36
|
export type SendCallsPayload = SendCallsParams[0];
|
|
37
|
+
export type SendCallsRequiredAssetsParam = Infer<typeof RequiredAssetStruct>;
|
|
37
38
|
export type SendCallsResult = {
|
|
38
39
|
id: Hex;
|
|
39
40
|
capabilities?: Record<string, Json>;
|
|
@@ -41,8 +42,22 @@ export type SendCallsResult = {
|
|
|
41
42
|
export type ProcessSendCallsHook = (sendCalls: SendCallsPayload, req: JsonRpcRequest) => Promise<SendCallsResult>;
|
|
42
43
|
export declare const GetCallsStatusStruct: import("@metamask/superstruct").Struct<[`0x${string}`], null>;
|
|
43
44
|
export declare const GetCapabilitiesStruct: import("@metamask/superstruct").Struct<[`0x${string}`, `0x${string}`[] | undefined], null>;
|
|
45
|
+
declare const RequiredAssetStruct: import("@metamask/superstruct").Struct<{
|
|
46
|
+
address: `0x${string}`;
|
|
47
|
+
standard: string;
|
|
48
|
+
amount: `0x${string}`;
|
|
49
|
+
}, {
|
|
50
|
+
address: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
51
|
+
amount: import("@metamask/superstruct").Struct<`0x${string}`, null>;
|
|
52
|
+
standard: import("@metamask/superstruct").Struct<string, null>;
|
|
53
|
+
}>;
|
|
44
54
|
export declare const CapabilitiesStruct: import("@metamask/superstruct").Struct<Record<string, {
|
|
45
55
|
optional?: boolean | undefined;
|
|
56
|
+
requiredAssets?: {
|
|
57
|
+
address: `0x${string}`;
|
|
58
|
+
standard: string;
|
|
59
|
+
amount: `0x${string}`;
|
|
60
|
+
}[] | undefined;
|
|
46
61
|
}>, null>;
|
|
47
62
|
export declare const SendCallsStruct: import("@metamask/superstruct").Struct<[{
|
|
48
63
|
version: string;
|
|
@@ -54,12 +69,22 @@ export declare const SendCallsStruct: import("@metamask/superstruct").Struct<[{
|
|
|
54
69
|
to?: `0x${string}` | undefined;
|
|
55
70
|
capabilities?: Record<string, {
|
|
56
71
|
optional?: boolean | undefined;
|
|
72
|
+
requiredAssets?: {
|
|
73
|
+
address: `0x${string}`;
|
|
74
|
+
standard: string;
|
|
75
|
+
amount: `0x${string}`;
|
|
76
|
+
}[] | undefined;
|
|
57
77
|
}> | undefined;
|
|
58
78
|
}[];
|
|
59
79
|
id?: `0x${string}` | undefined;
|
|
60
80
|
from?: `0x${string}` | undefined;
|
|
61
81
|
capabilities?: Record<string, {
|
|
62
82
|
optional?: boolean | undefined;
|
|
83
|
+
requiredAssets?: {
|
|
84
|
+
address: `0x${string}`;
|
|
85
|
+
standard: string;
|
|
86
|
+
amount: `0x${string}`;
|
|
87
|
+
}[] | undefined;
|
|
63
88
|
}> | undefined;
|
|
64
89
|
}], null>;
|
|
65
90
|
export {};
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,0CAA0C,EAC1C,gCAAgC,EACjC,sCAAsC;AACvC,OAAO,KAAK,EAAE,SAAS,EAAE,kCAAkC;AAC3D,OAAO,KAAK,EACV,2CAA2C,EAC3C,+BAA+B,EAChC,qCAAqC;AACtC,OAAO,KAAK,EAAE,mCAAmC,EAAE,yCAAyC;AAC5F,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAYnD,OAAO,KAAK,EAAE,mCAAmC,EAAE,yCAAyC;AAC5F,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,cAAc,EAAE,wBAAw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