@metamask-previews/eip-5792-middleware 2.0.0-preview-ee982ebe → 2.0.0-preview-91b0ac79
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/dist/hooks/getCallsStatus.cjs +1 -1
- package/dist/hooks/getCallsStatus.cjs.map +1 -1
- package/dist/hooks/getCallsStatus.mjs +1 -1
- package/dist/hooks/getCallsStatus.mjs.map +1 -1
- package/dist/hooks/getCapabilities.cjs.map +1 -1
- package/dist/hooks/getCapabilities.mjs.map +1 -1
- package/dist/hooks/processSendCalls.cjs.map +1 -1
- package/dist/hooks/processSendCalls.mjs.map +1 -1
- package/dist/methods/wallet_getCallsStatus.cjs.map +1 -1
- package/dist/methods/wallet_getCallsStatus.mjs.map +1 -1
- package/dist/methods/wallet_getCapabilities.cjs.map +1 -1
- package/dist/methods/wallet_getCapabilities.mjs.map +1 -1
- package/dist/methods/wallet_sendCalls.cjs.map +1 -1
- package/dist/methods/wallet_sendCalls.mjs.map +1 -1
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.mjs.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCallsStatus.cjs","sourceRoot":"","sources":["../../src/hooks/getCallsStatus.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAMpD,6EAAqE;AAGrE,gDAA6E;AAG7E;;;;;;;GAOG;AACH,SAAgB,cAAc,CAC5B,SAA2B,EAC3B,EAAO;IAEP,MAAM,YAAY,GAAG,SAAS;SAC3B,IAAI,CAAC,gCAAgC,CAAC;SACtC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC;IAElD,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE;
|
|
1
|
+
{"version":3,"file":"getCallsStatus.cjs","sourceRoot":"","sources":["../../src/hooks/getCallsStatus.ts"],"names":[],"mappings":";;;AAA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,EAAE,IAAI,EAAE,8DAA8D;QAC5E,MAAM;QACN,QAAQ;KACT,CAAC;AACJ,CAAC;AA5CD,wCA4CC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,eAAgC;IACrD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,eAAe,CAAC;IAEzC,IAAI,MAAM,KAAK,0CAAiB,CAAC,SAAS,EAAE,CAAC;QAC3C,OAAO,8BAAkB,CAAC,SAAS,CAAC;IACtC,CAAC;IAED,IAAI,MAAM,KAAK,0CAAiB,CAAC,MAAM,EAAE,CAAC;QACxC,OAAO,IAAI;YACT,CAAC,CAAC,8BAAkB,CAAC,QAAQ;YAC7B,CAAC,CAAC,8BAAkB,CAAC,eAAe,CAAC;IACzC,CAAC;IAED,IAAI,MAAM,KAAK,0CAAiB,CAAC,OAAO,EAAE,CAAC;QACzC,OAAO,8BAAkB,CAAC,QAAQ,CAAC;IACrC,CAAC;IAED,OAAO,8BAAkB,CAAC,OAAO,CAAC;AACpC,CAAC","sourcesContent":["import { JsonRpcError } from '@metamask/rpc-errors';\nimport type {\n Log,\n TransactionMeta,\n TransactionReceipt,\n} from '@metamask/transaction-controller';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { EIP5792ErrorCode, GetCallsStatusCode, VERSION } from '../constants';\nimport type { EIP5792Messenger, GetCallsStatusResult } from '../types';\n\n/**\n * Retrieves the status of a transaction batch by its ID.\n *\n * @param messenger - Messenger instance for controller communication.\n * @param id - The batch ID to look up (hexadecimal string).\n * @returns GetCallsStatusResult containing the batch status, receipts, and metadata.\n * @throws JsonRpcError with EIP5792ErrorCode.UnknownBundleId if no matching bundle is found.\n */\nexport function getCallsStatus(\n messenger: EIP5792Messenger,\n id: Hex,\n): GetCallsStatusResult {\n const transactions = messenger\n .call('TransactionController:getState')\n .transactions.filter((tx) => tx.batchId === id);\n\n if (!transactions?.length) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnknownBundleId,\n `No matching bundle found`,\n );\n }\n\n const transaction = transactions[0];\n const { chainId, txReceipt: rawTxReceipt } = transaction;\n const status = getStatusCode(transaction);\n const txReceipt = rawTxReceipt as Required<TransactionReceipt> | undefined;\n const logs = (txReceipt?.logs ?? []) as Required<Log>[];\n\n const receipts: GetCallsStatusResult['receipts'] = txReceipt && [\n {\n blockHash: txReceipt.blockHash as Hex,\n blockNumber: txReceipt.blockNumber as Hex,\n gasUsed: txReceipt.gasUsed as Hex,\n logs: logs.map((log: Required<Log> & { data: Hex }) => ({\n address: log.address as Hex,\n data: log.data,\n topics: log.topics as unknown as Hex[],\n })),\n status: txReceipt.status as '0x0' | '0x1',\n transactionHash: txReceipt.transactionHash,\n },\n ];\n\n return {\n version: VERSION,\n id,\n chainId,\n atomic: true, // Always atomic as we currently only support EIP-7702 batches\n status,\n receipts,\n };\n}\n\n/**\n * Maps transaction status to EIP-5792 call status codes.\n *\n * @param transactionMeta - The transaction metadata containing status and hash information.\n * @returns GetCallsStatusCode representing the current status of the transaction.\n */\nfunction getStatusCode(transactionMeta: TransactionMeta) {\n const { hash, status } = transactionMeta;\n\n if (status === TransactionStatus.confirmed) {\n return GetCallsStatusCode.CONFIRMED;\n }\n\n if (status === TransactionStatus.failed) {\n return hash\n ? GetCallsStatusCode.REVERTED\n : GetCallsStatusCode.FAILED_OFFCHAIN;\n }\n\n if (status === TransactionStatus.dropped) {\n return GetCallsStatusCode.REVERTED;\n }\n\n return GetCallsStatusCode.PENDING;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCallsStatus.mjs","sourceRoot":"","sources":["../../src/hooks/getCallsStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,6BAA6B;AAMpD,OAAO,EAAE,iBAAiB,EAAE,yCAAyC;AAGrE,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,OAAO,EAAE,yBAAqB;AAG7E;;;;;;;GAOG;AACH,MAAM,U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SAAgB;YACrC,WAAW,EAAE,SAAS,CAAC,WAAkB;YACzC,OAAO,EAAE,SAAS,CAAC,OAAc;YACjC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,GAAkC,EAAE,EAAE,CAAC,CAAC;gBACtD,OAAO,EAAE,GAAG,CAAC,OAAc;gBAC3B,IAAI,EAAE,GAAG,CAAC,IAAI;gBACd,MAAM,EAAE,GAAG,CAAC,MAA0B;aACvC,CAAC,CAAC;YACH,MAAM,EAAE,SAAS,CAAC,MAAuB;YACzC,eAAe,EAAE,SAAS,CAAC,eAAe;SAC3C;KACF,CAAC;IAEF,OAAO;QACL,OAAO,EAAE,OAAO;QAChB,EAAE;QACF,OAAO;QACP,MAAM,EAAE,IAAI,EAAE,8DAA8D;QAC5E,MAAM;QACN,QAAQ;KACT,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,eAAgC;IACrD,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,eAAe,CAAC;IAEzC,IAAI,MAAM,KAAK,iBAAiB,CAAC,SAAS,EAAE,CAAC;QAC3C,OAAO,kBAAkB,CAAC,SAAS,CAAC;IACtC,CAAC;IAED,IAAI,MAAM,KAAK,iBAAiB,CAAC,MAAM,EAAE,CAAC;QACxC,OAAO,IAAI;YACT,CAAC,CAAC,kBAAkB,CAAC,QAAQ;YAC7B,CAAC,CAAC,kBAAkB,CAAC,eAAe,CAAC;IACzC,CAAC;IAED,IAAI,MAAM,KAAK,iBAAiB,CAAC,OAAO,EAAE,CAAC;QACzC,OAAO,kBAAkB,CAAC,QAAQ,CAAC;IACrC,CAAC;IAED,OAAO,kBAAkB,CAAC,OAAO,CAAC;AACpC,CAAC","sourcesContent":["import { JsonRpcError } from '@metamask/rpc-errors';\nimport type {\n Log,\n TransactionMeta,\n TransactionReceipt,\n} from '@metamask/transaction-controller';\nimport { TransactionStatus } from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { EIP5792ErrorCode, GetCallsStatusCode, VERSION } from '../constants';\nimport type { EIP5792Messenger, GetCallsStatusResult } from '../types';\n\n/**\n * Retrieves the status of a transaction batch by its ID.\n *\n * @param messenger - Messenger instance for controller communication.\n * @param id - The batch ID to look up (hexadecimal string).\n * @returns GetCallsStatusResult containing the batch status, receipts, and metadata.\n * @throws JsonRpcError with EIP5792ErrorCode.UnknownBundleId if no matching bundle is found.\n */\nexport function getCallsStatus(\n messenger: EIP5792Messenger,\n id: Hex,\n): GetCallsStatusResult {\n const transactions = messenger\n .call('TransactionController:getState')\n .transactions.filter((tx) => tx.batchId === id);\n\n if (!transactions?.length) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnknownBundleId,\n `No matching bundle found`,\n );\n }\n\n const transaction = transactions[0];\n const { chainId, txReceipt: rawTxReceipt } = transaction;\n const status = getStatusCode(transaction);\n const txReceipt = rawTxReceipt as Required<TransactionReceipt> | undefined;\n const logs = (txReceipt?.logs ?? []) as Required<Log>[];\n\n const receipts: GetCallsStatusResult['receipts'] = txReceipt && [\n {\n blockHash: txReceipt.blockHash as Hex,\n blockNumber: txReceipt.blockNumber as Hex,\n gasUsed: txReceipt.gasUsed as Hex,\n logs: logs.map((log: Required<Log> & { data: Hex }) => ({\n address: log.address as Hex,\n data: log.data,\n topics: log.topics as unknown as Hex[],\n })),\n status: txReceipt.status as '0x0' | '0x1',\n transactionHash: txReceipt.transactionHash,\n },\n ];\n\n return {\n version: VERSION,\n id,\n chainId,\n atomic: true, // Always atomic as we currently only support EIP-7702 batches\n status,\n receipts,\n };\n}\n\n/**\n * Maps transaction status to EIP-5792 call status codes.\n *\n * @param transactionMeta - The transaction metadata containing status and hash information.\n * @returns GetCallsStatusCode representing the current status of the transaction.\n */\nfunction getStatusCode(transactionMeta: TransactionMeta) {\n const { hash, status } = transactionMeta;\n\n if (status === TransactionStatus.confirmed) {\n return GetCallsStatusCode.CONFIRMED;\n }\n\n if (status === TransactionStatus.failed) {\n return hash\n ? GetCallsStatusCode.REVERTED\n : GetCallsStatusCode.FAILED_OFFCHAIN;\n }\n\n if (status === TransactionStatus.dropped) {\n return GetCallsStatusCode.REVERTED;\n }\n\n return GetCallsStatusCode.PENDING;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCapabilities.cjs","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":";;;AAOA,gDAA6D;AAE7D,wCAAiD;AAsBjD;;;;;;;;GAQG;AACI,KAAK,UAAU,eAAe,CACnC,KAA2B,EAC3B,SAA2B,EAC3B,OAAY,EACZ,QAA2B;IAE3B,MAAM,EACJ,uCAAuC,EACvC,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,yBAAyB,GAC1B,GAAG,KAAK,CAAC;IAEV,IAAI,kBAAkB,GAAG,QAAQ,EAAE,GAAG,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,EAAS,CAC1C,CAAC;IAEF,IAAI,CAAC,kBAAkB,EAAE,MAAM,EAAE;QAC/B,MAAM,qBAAqB,GAAG,SAAS,CAAC,IAAI,CAC1C,4BAA4B,CAC7B,CAAC,8BAA8B,CAAC;QACjC,kBAAkB,GAAG,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAU,CAAC;KAClE;IAED,MAAM,YAAY,GAAG,MAAM,sBAAsB,CAAC;QAChD,OAAO;QACP,QAAQ,EAAE,kBAAkB;KAC7B,CAAC,CAAC;IAEH,MAAM,mBAAmB,GAAG,MAAM,6BAA6B,CAC7D,kBAAkB,EAClB,YAAY,EACZ,qBAAqB,EACrB,gBAAgB,EAChB,4BAA4B,EAC5B,SAAS,CACV,CAAC;IAEF,OAAO,kBAAkB,CAAC,MAAM,CAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QACvE,MAAM,iBAAiB,GAAG,CAAC,YAAY,CAAC,IAAI,CAC1C,CAAC,EAAE,OAAO,EAAE,YAAY,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G,CAAC,OAAc,CAAC,GAAG;gBACpB,gBAAgB,EAAE;oBAChB,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC;SACH;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import type {\n IsAtomicBatchSupportedResult,\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { KEYRING_TYPES_SUPPORTING_7702 } from '../constants';\nimport type { EIP5792Messenger, GetCapabilitiesResult } from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link getCapabilities}\n */\nexport type GetCapabilitiesHooks = {\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if a chain supports smart transactions */\n getIsSmartTransaction: (chainId: Hex) => boolean;\n /** Function to check if atomic batching is supported */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to check if relay is supported on a chain */\n isRelaySupported: (chainId: Hex) => Promise<boolean>;\n /** Function to get chains that support send bundle */\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * Retrieves the capabilities for atomic transactions on specified chains.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param address - The account address to check capabilities for.\n * @param chainIds - Array of chain IDs to check capabilities for (if undefined, checks all configured networks).\n * @returns Promise resolving to GetCapabilitiesResult mapping chain IDs to their capabilities.\n */\nexport async function getCapabilities(\n hooks: GetCapabilitiesHooks,\n messenger: EIP5792Messenger,\n address: Hex,\n chainIds: Hex[] | undefined,\n) {\n const {\n getDismissSmartAccountSuggestionEnabled,\n getIsSmartTransaction,\n isAtomicBatchSupported,\n isRelaySupported,\n getSendBundleSupportedChains,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n let chainIdsNormalized = chainIds?.map(\n (chainId) => chainId.toLowerCase() as Hex,\n );\n\n if (!chainIdsNormalized?.length) {\n const networkConfigurations = messenger.call(\n 'NetworkController:getState',\n ).networkConfigurationsByChainId;\n chainIdsNormalized = Object.keys(networkConfigurations) as Hex[];\n }\n\n const batchSupport = await isAtomicBatchSupported({\n address,\n chainIds: chainIdsNormalized,\n });\n\n const alternateGasFeesAcc = await getAlternateGasFeesCapability(\n chainIdsNormalized,\n batchSupport,\n getIsSmartTransaction,\n isRelaySupported,\n getSendBundleSupportedChains,\n messenger,\n );\n\n return chainIdsNormalized.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (batchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n isRelaySupported: boolean;\n };\n\n const { delegationAddress, isSupported, upgradeContractAddress } =\n chainBatchSupport;\n\n const isUpgradeDisabled = getDismissSmartAccountSuggestionEnabled();\n let isSupportedAccount = false;\n\n try {\n const keyringType = getAccountKeyringType(address, messenger);\n isSupportedAccount = KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n } catch {\n // Intentionally empty\n }\n\n const canUpgrade =\n !isUpgradeDisabled &&\n upgradeContractAddress &&\n !delegationAddress &&\n isSupportedAccount;\n\n if (!isSupported && !canUpgrade) {\n return acc;\n }\n\n const status = isSupported ? 'supported' : 'ready';\n const hexChainId = chainId as Hex;\n\n if (acc[hexChainId] === undefined) {\n acc[hexChainId] = {};\n }\n\n acc[hexChainId].atomic = {\n status,\n };\n\n if (isSupportedAccount && isAuxiliaryFundsSupported(chainId)) {\n acc[hexChainId].auxiliaryFunds = {\n supported: true,\n };\n }\n\n return acc;\n }, alternateGasFeesAcc);\n}\n\n/**\n * Determines alternate gas fees capability for the specified chains.\n *\n * @param chainIds - Array of chain IDs to check for alternate gas fees support.\n * @param batchSupport - Information about atomic batch support for each chain.\n * @param getIsSmartTransaction - Function to check if a chain supports smart transactions.\n * @param isRelaySupported - Function to check if relay is supported on a chain.\n * @param getSendBundleSupportedChains - Function to get chains that support send bundle.\n * @param messenger - Messenger instance for controller communication.\n * @returns Promise resolving to GetCapabilitiesResult with alternate gas fees information.\n */\nasync function getAlternateGasFeesCapability(\n chainIds: Hex[],\n batchSupport: IsAtomicBatchSupportedResult,\n getIsSmartTransaction: (chainId: Hex) => boolean,\n isRelaySupported: (chainId: Hex) => Promise<boolean>,\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>,\n messenger: EIP5792Messenger,\n) {\n const simulationEnabled = messenger.call(\n 'PreferencesController:getState',\n ).useTransactionSimulations;\n\n const relaySupportedChains = await Promise.all(\n batchSupport\n .map(({ chainId }) => chainId)\n .map((chainId) => isRelaySupported(chainId)),\n );\n\n const sendBundleSupportedChains =\n await getSendBundleSupportedChains(chainIds);\n\n const updatedBatchSupport = batchSupport.map((support, index) => ({\n ...support,\n relaySupportedForChain: relaySupportedChains[index],\n }));\n\n return chainIds.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (updatedBatchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n relaySupportedForChain: boolean;\n };\n\n const { isSupported = false, relaySupportedForChain } = chainBatchSupport;\n\n const isSmartTransaction = getIsSmartTransaction(chainId);\n const isSendBundleSupported = sendBundleSupportedChains[chainId] ?? false;\n\n const alternateGasFees =\n simulationEnabled &&\n ((isSmartTransaction && isSendBundleSupported) ||\n (isSupported && relaySupportedForChain));\n\n if (alternateGasFees) {\n acc[chainId as Hex] = {\n alternateGasFees: {\n supported: true,\n },\n };\n }\n\n return acc;\n }, {});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getCapabilities.cjs","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":";;;AAOA,gDAA6D;AAE7D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atchSupportedResult,\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { KEYRING_TYPES_SUPPORTING_7702 } from '../constants';\nimport type { EIP5792Messenger, GetCapabilitiesResult } from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link getCapabilities}\n */\nexport type GetCapabilitiesHooks = {\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if a chain supports smart transactions */\n getIsSmartTransaction: (chainId: Hex) => boolean;\n /** Function to check if atomic batching is supported */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to check if relay is supported on a chain */\n isRelaySupported: (chainId: Hex) => Promise<boolean>;\n /** Function to get chains that support send bundle */\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * Retrieves the capabilities for atomic transactions on specified chains.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param address - The account address to check capabilities for.\n * @param chainIds - Array of chain IDs to check capabilities for (if undefined, checks all configured networks).\n * @returns Promise resolving to GetCapabilitiesResult mapping chain IDs to their capabilities.\n */\nexport async function getCapabilities(\n hooks: GetCapabilitiesHooks,\n messenger: EIP5792Messenger,\n address: Hex,\n chainIds: Hex[] | undefined,\n) {\n const {\n getDismissSmartAccountSuggestionEnabled,\n getIsSmartTransaction,\n isAtomicBatchSupported,\n isRelaySupported,\n getSendBundleSupportedChains,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n let chainIdsNormalized = chainIds?.map(\n (chainId) => chainId.toLowerCase() as Hex,\n );\n\n if (!chainIdsNormalized?.length) {\n const networkConfigurations = messenger.call(\n 'NetworkController:getState',\n ).networkConfigurationsByChainId;\n chainIdsNormalized = Object.keys(networkConfigurations) as Hex[];\n }\n\n const batchSupport = await isAtomicBatchSupported({\n address,\n chainIds: chainIdsNormalized,\n });\n\n const alternateGasFeesAcc = await getAlternateGasFeesCapability(\n chainIdsNormalized,\n batchSupport,\n getIsSmartTransaction,\n isRelaySupported,\n getSendBundleSupportedChains,\n messenger,\n );\n\n return chainIdsNormalized.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (batchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n isRelaySupported: boolean;\n };\n\n const { delegationAddress, isSupported, upgradeContractAddress } =\n chainBatchSupport;\n\n const isUpgradeDisabled = getDismissSmartAccountSuggestionEnabled();\n let isSupportedAccount = false;\n\n try {\n const keyringType = getAccountKeyringType(address, messenger);\n isSupportedAccount = KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n } catch {\n // Intentionally empty\n }\n\n const canUpgrade =\n !isUpgradeDisabled &&\n upgradeContractAddress &&\n !delegationAddress &&\n isSupportedAccount;\n\n if (!isSupported && !canUpgrade) {\n return acc;\n }\n\n const status = isSupported ? 'supported' : 'ready';\n const hexChainId = chainId as Hex;\n\n if (acc[hexChainId] === undefined) {\n acc[hexChainId] = {};\n }\n\n acc[hexChainId].atomic = {\n status,\n };\n\n if (isSupportedAccount && isAuxiliaryFundsSupported(chainId)) {\n acc[hexChainId].auxiliaryFunds = {\n supported: true,\n };\n }\n\n return acc;\n }, alternateGasFeesAcc);\n}\n\n/**\n * Determines alternate gas fees capability for the specified chains.\n *\n * @param chainIds - Array of chain IDs to check for alternate gas fees support.\n * @param batchSupport - Information about atomic batch support for each chain.\n * @param getIsSmartTransaction - Function to check if a chain supports smart transactions.\n * @param isRelaySupported - Function to check if relay is supported on a chain.\n * @param getSendBundleSupportedChains - Function to get chains that support send bundle.\n * @param messenger - Messenger instance for controller communication.\n * @returns Promise resolving to GetCapabilitiesResult with alternate gas fees information.\n */\nasync function getAlternateGasFeesCapability(\n chainIds: Hex[],\n batchSupport: IsAtomicBatchSupportedResult,\n getIsSmartTransaction: (chainId: Hex) => boolean,\n isRelaySupported: (chainId: Hex) => Promise<boolean>,\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>,\n messenger: EIP5792Messenger,\n) {\n const simulationEnabled = messenger.call(\n 'PreferencesController:getState',\n ).useTransactionSimulations;\n\n const relaySupportedChains = await Promise.all(\n batchSupport\n .map(({ chainId }) => chainId)\n .map((chainId) => isRelaySupported(chainId)),\n );\n\n const sendBundleSupportedChains =\n await getSendBundleSupportedChains(chainIds);\n\n const updatedBatchSupport = batchSupport.map((support, index) => ({\n ...support,\n relaySupportedForChain: relaySupportedChains[index],\n }));\n\n return chainIds.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (updatedBatchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n relaySupportedForChain: boolean;\n };\n\n const { isSupported = false, relaySupportedForChain } = chainBatchSupport;\n\n const isSmartTransaction = getIsSmartTransaction(chainId);\n const isSendBundleSupported = sendBundleSupportedChains[chainId] ?? false;\n\n const alternateGasFees =\n simulationEnabled &&\n ((isSmartTransaction && isSendBundleSupported) ||\n (isSupported && relaySupportedForChain));\n\n if (alternateGasFees) {\n acc[chainId as Hex] = {\n alternateGasFees: {\n supported: true,\n },\n };\n }\n\n return acc;\n }, {});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getCapabilities.mjs","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,6BAA6B,EAAE,yBAAqB;AAE7D,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AAsBjD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,KAA2B,EAC3B,SAA2B,EAC3B,OAAY,EACZ,QA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CAAC,QAAQ,CAAC,CAAC;IAE/C,MAAM,mBAAmB,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAChE,GAAG,OAAO;QACV,sBAAsB,EAAE,oBAAoB,CAAC,KAAK,CAAC;KACpD,CAAC,CAAC,CAAC;IAEJ,OAAO,QAAQ,CAAC,MAAM,CAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,iBAAiB,GAAG,CAAC,mBAAmB,CAAC,IAAI,CACjD,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAY,KAAK,OAAO,CACxD,IAAI,EAAE,CAEN,CAAC;QAEF,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE,sBAAsB,EAAE,GAAG,iBAAiB,CAAC;QAE1E,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,qBAAqB,GAAG,yBAAyB,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;QAE1E,MAAM,gBAAgB,GACpB,iBAAiB;YACjB,CAAC,CAAC,kBAAkB,IAAI,qBAAqB,CAAC;gBAC5C,CAAC,WAAW,IAAI,sBAAsB,CAAC,CAAC,CAAC;QAE7C,IAAI,gBAAgB,EAAE;YACpB,GAAG,CAAC,OAAc,CAAC,GAAG;gBACpB,gBAAgB,EAAE;oBAChB,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC;SACH;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import type {\n IsAtomicBatchSupportedResult,\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { KEYRING_TYPES_SUPPORTING_7702 } from '../constants';\nimport type { EIP5792Messenger, GetCapabilitiesResult } from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link getCapabilities}\n */\nexport type GetCapabilitiesHooks = {\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if a chain supports smart transactions */\n getIsSmartTransaction: (chainId: Hex) => boolean;\n /** Function to check if atomic batching is supported */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to check if relay is supported on a chain */\n isRelaySupported: (chainId: Hex) => Promise<boolean>;\n /** Function to get chains that support send bundle */\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * Retrieves the capabilities for atomic transactions on specified chains.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param address - The account address to check capabilities for.\n * @param chainIds - Array of chain IDs to check capabilities for (if undefined, checks all configured networks).\n * @returns Promise resolving to GetCapabilitiesResult mapping chain IDs to their capabilities.\n */\nexport async function getCapabilities(\n hooks: GetCapabilitiesHooks,\n messenger: EIP5792Messenger,\n address: Hex,\n chainIds: Hex[] | undefined,\n) {\n const {\n getDismissSmartAccountSuggestionEnabled,\n getIsSmartTransaction,\n isAtomicBatchSupported,\n isRelaySupported,\n getSendBundleSupportedChains,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n let chainIdsNormalized = chainIds?.map(\n (chainId) => chainId.toLowerCase() as Hex,\n );\n\n if (!chainIdsNormalized?.length) {\n const networkConfigurations = messenger.call(\n 'NetworkController:getState',\n ).networkConfigurationsByChainId;\n chainIdsNormalized = Object.keys(networkConfigurations) as Hex[];\n }\n\n const batchSupport = await isAtomicBatchSupported({\n address,\n chainIds: chainIdsNormalized,\n });\n\n const alternateGasFeesAcc = await getAlternateGasFeesCapability(\n chainIdsNormalized,\n batchSupport,\n getIsSmartTransaction,\n isRelaySupported,\n getSendBundleSupportedChains,\n messenger,\n );\n\n return chainIdsNormalized.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (batchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n isRelaySupported: boolean;\n };\n\n const { delegationAddress, isSupported, upgradeContractAddress } =\n chainBatchSupport;\n\n const isUpgradeDisabled = getDismissSmartAccountSuggestionEnabled();\n let isSupportedAccount = false;\n\n try {\n const keyringType = getAccountKeyringType(address, messenger);\n isSupportedAccount = KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n } catch {\n // Intentionally empty\n }\n\n const canUpgrade =\n !isUpgradeDisabled &&\n upgradeContractAddress &&\n !delegationAddress &&\n isSupportedAccount;\n\n if (!isSupported && !canUpgrade) {\n return acc;\n }\n\n const status = isSupported ? 'supported' : 'ready';\n const hexChainId = chainId as Hex;\n\n if (acc[hexChainId] === undefined) {\n acc[hexChainId] = {};\n }\n\n acc[hexChainId].atomic = {\n status,\n };\n\n if (isSupportedAccount && isAuxiliaryFundsSupported(chainId)) {\n acc[hexChainId].auxiliaryFunds = {\n supported: true,\n };\n }\n\n return acc;\n }, alternateGasFeesAcc);\n}\n\n/**\n * Determines alternate gas fees capability for the specified chains.\n *\n * @param chainIds - Array of chain IDs to check for alternate gas fees support.\n * @param batchSupport - Information about atomic batch support for each chain.\n * @param getIsSmartTransaction - Function to check if a chain supports smart transactions.\n * @param isRelaySupported - Function to check if relay is supported on a chain.\n * @param getSendBundleSupportedChains - Function to get chains that support send bundle.\n * @param messenger - Messenger instance for controller communication.\n * @returns Promise resolving to GetCapabilitiesResult with alternate gas fees information.\n */\nasync function getAlternateGasFeesCapability(\n chainIds: Hex[],\n batchSupport: IsAtomicBatchSupportedResult,\n getIsSmartTransaction: (chainId: Hex) => boolean,\n isRelaySupported: (chainId: Hex) => Promise<boolean>,\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>,\n messenger: EIP5792Messenger,\n) {\n const simulationEnabled = messenger.call(\n 'PreferencesController:getState',\n ).useTransactionSimulations;\n\n const relaySupportedChains = await Promise.all(\n batchSupport\n .map(({ chainId }) => chainId)\n .map((chainId) => isRelaySupported(chainId)),\n );\n\n const sendBundleSupportedChains =\n await getSendBundleSupportedChains(chainIds);\n\n const updatedBatchSupport = batchSupport.map((support, index) => ({\n ...support,\n relaySupportedForChain: relaySupportedChains[index],\n }));\n\n return chainIds.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (updatedBatchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n relaySupportedForChain: boolean;\n };\n\n const { isSupported = false, relaySupportedForChain } = chainBatchSupport;\n\n const isSmartTransaction = getIsSmartTransaction(chainId);\n const isSendBundleSupported = sendBundleSupportedChains[chainId] ?? false;\n\n const alternateGasFees =\n simulationEnabled &&\n ((isSmartTransaction && isSendBundleSupported) ||\n (isSupported && relaySupportedForChain));\n\n if (alternateGasFees) {\n acc[chainId as Hex] = {\n alternateGasFees: {\n supported: true,\n },\n };\n }\n\n return acc;\n }, {});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getCapabilities.mjs","sourceRoot":"","sources":["../../src/hooks/getCapabilities.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,6BAA6B,EAAE,yBAAqB;AAE7D,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AAsBjD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,KAA2B,EAC3B,SAA2B,EAC3B,OAAY,EACZ,QAA2B;IAE3B,MAAM,EACJ,uCAAuC,EACvC,qBAAqB,EACrB,sBAAsB,EACtB,gBAAgB,EAChB,4BAA4B,EAC5B,yBAAyB,GAC1B,GAAG,KAAK,CAAC;IAEV,IAAI,kBAAkB,GAAG,QAAQ,EAAE,GAAG,CACpC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,WAAW,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,oBAAoB,CAAC,KAAK,CAAC;KACpD,CAAC,CAAC,CAAC;IAEJ,OAAO,QAAQ,CAAC,MAAM,CAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,EAAE;QAC7D,MAAM,iBAAiB,GAAG,CAAC,mBAAmB,CAAC,IAAI,CACjD,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,YAAY,KAAK,OAAO,CACxD,IAAI,EAAE,CAEN,CAAC;QAEF,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE,sBAAsB,EAAE,GAAG,iBAAiB,CAAC;QAE1E,MAAM,kBAAkB,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAC1D,MAAM,qBAAqB,GAAG,yBAAyB,CAAC,OAAO,CAAC,IAAI,KAAK,CAAC;QAE1E,MAAM,gBAAgB,GACpB,iBAAiB;YACjB,CAAC,CAAC,kBAAkB,IAAI,qBAAqB,CAAC;gBAC5C,CAAC,WAAW,IAAI,sBAAsB,CAAC,CAAC,CAAC;QAE7C,IAAI,gBAAgB,EAAE,CAAC;YACrB,GAAG,CAAC,OAAc,CAAC,GAAG;gBACpB,gBAAgB,EAAE;oBAChB,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC;QACJ,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC,EAAE,EAAE,CAAC,CAAC;AACT,CAAC","sourcesContent":["import type {\n IsAtomicBatchSupportedResult,\n IsAtomicBatchSupportedResultEntry,\n TransactionController,\n} from '@metamask/transaction-controller';\nimport type { Hex } from '@metamask/utils';\n\nimport { KEYRING_TYPES_SUPPORTING_7702 } from '../constants';\nimport type { EIP5792Messenger, GetCapabilitiesResult } from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link getCapabilities}\n */\nexport type GetCapabilitiesHooks = {\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if a chain supports smart transactions */\n getIsSmartTransaction: (chainId: Hex) => boolean;\n /** Function to check if atomic batching is supported */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to check if relay is supported on a chain */\n isRelaySupported: (chainId: Hex) => Promise<boolean>;\n /** Function to get chains that support send bundle */\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * Retrieves the capabilities for atomic transactions on specified chains.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param address - The account address to check capabilities for.\n * @param chainIds - Array of chain IDs to check capabilities for (if undefined, checks all configured networks).\n * @returns Promise resolving to GetCapabilitiesResult mapping chain IDs to their capabilities.\n */\nexport async function getCapabilities(\n hooks: GetCapabilitiesHooks,\n messenger: EIP5792Messenger,\n address: Hex,\n chainIds: Hex[] | undefined,\n) {\n const {\n getDismissSmartAccountSuggestionEnabled,\n getIsSmartTransaction,\n isAtomicBatchSupported,\n isRelaySupported,\n getSendBundleSupportedChains,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n let chainIdsNormalized = chainIds?.map(\n (chainId) => chainId.toLowerCase() as Hex,\n );\n\n if (!chainIdsNormalized?.length) {\n const networkConfigurations = messenger.call(\n 'NetworkController:getState',\n ).networkConfigurationsByChainId;\n chainIdsNormalized = Object.keys(networkConfigurations) as Hex[];\n }\n\n const batchSupport = await isAtomicBatchSupported({\n address,\n chainIds: chainIdsNormalized,\n });\n\n const alternateGasFeesAcc = await getAlternateGasFeesCapability(\n chainIdsNormalized,\n batchSupport,\n getIsSmartTransaction,\n isRelaySupported,\n getSendBundleSupportedChains,\n messenger,\n );\n\n return chainIdsNormalized.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (batchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n isRelaySupported: boolean;\n };\n\n const { delegationAddress, isSupported, upgradeContractAddress } =\n chainBatchSupport;\n\n const isUpgradeDisabled = getDismissSmartAccountSuggestionEnabled();\n let isSupportedAccount = false;\n\n try {\n const keyringType = getAccountKeyringType(address, messenger);\n isSupportedAccount = KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n } catch {\n // Intentionally empty\n }\n\n const canUpgrade =\n !isUpgradeDisabled &&\n upgradeContractAddress &&\n !delegationAddress &&\n isSupportedAccount;\n\n if (!isSupported && !canUpgrade) {\n return acc;\n }\n\n const status = isSupported ? 'supported' : 'ready';\n const hexChainId = chainId as Hex;\n\n if (acc[hexChainId] === undefined) {\n acc[hexChainId] = {};\n }\n\n acc[hexChainId].atomic = {\n status,\n };\n\n if (isSupportedAccount && isAuxiliaryFundsSupported(chainId)) {\n acc[hexChainId].auxiliaryFunds = {\n supported: true,\n };\n }\n\n return acc;\n }, alternateGasFeesAcc);\n}\n\n/**\n * Determines alternate gas fees capability for the specified chains.\n *\n * @param chainIds - Array of chain IDs to check for alternate gas fees support.\n * @param batchSupport - Information about atomic batch support for each chain.\n * @param getIsSmartTransaction - Function to check if a chain supports smart transactions.\n * @param isRelaySupported - Function to check if relay is supported on a chain.\n * @param getSendBundleSupportedChains - Function to get chains that support send bundle.\n * @param messenger - Messenger instance for controller communication.\n * @returns Promise resolving to GetCapabilitiesResult with alternate gas fees information.\n */\nasync function getAlternateGasFeesCapability(\n chainIds: Hex[],\n batchSupport: IsAtomicBatchSupportedResult,\n getIsSmartTransaction: (chainId: Hex) => boolean,\n isRelaySupported: (chainId: Hex) => Promise<boolean>,\n getSendBundleSupportedChains: (\n chainIds: Hex[],\n ) => Promise<Record<string, boolean>>,\n messenger: EIP5792Messenger,\n) {\n const simulationEnabled = messenger.call(\n 'PreferencesController:getState',\n ).useTransactionSimulations;\n\n const relaySupportedChains = await Promise.all(\n batchSupport\n .map(({ chainId }) => chainId)\n .map((chainId) => isRelaySupported(chainId)),\n );\n\n const sendBundleSupportedChains =\n await getSendBundleSupportedChains(chainIds);\n\n const updatedBatchSupport = batchSupport.map((support, index) => ({\n ...support,\n relaySupportedForChain: relaySupportedChains[index],\n }));\n\n return chainIds.reduce<GetCapabilitiesResult>((acc, chainId) => {\n const chainBatchSupport = (updatedBatchSupport.find(\n ({ chainId: batchChainId }) => batchChainId === chainId,\n ) ?? {}) as IsAtomicBatchSupportedResultEntry & {\n relaySupportedForChain: boolean;\n };\n\n const { isSupported = false, relaySupportedForChain } = chainBatchSupport;\n\n const isSmartTransaction = getIsSmartTransaction(chainId);\n const isSendBundleSupported = sendBundleSupportedChains[chainId] ?? false;\n\n const alternateGasFees =\n simulationEnabled &&\n ((isSmartTransaction && isSendBundleSupported) ||\n (isSupported && relaySupportedForChain));\n\n if (alternateGasFees) {\n acc[chainId as Hex] = {\n alternateGasFees: {\n supported: true,\n },\n };\n }\n\n return acc;\n }, {});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processSendCalls.cjs","sourceRoot":"","sources":["../../src/hooks/processSendCalls.ts"],"names":[],"mappings":";;;AACA,qDAA+D;AAQ/D,6EAA2E;AAE3E,2CAAoD;AACpD,mCAAiC;AACjC,+BAAyC;AAEzC,gDAOsB;AAOtB,wCAAiD;AAkCjD;;;;;;;;GAQG;AACI,KAAK,UAAU,gBAAgB,CACpC,KAA4B,EAC5B,SAA2B,EAC3B,MAAwB,EACxB,GAA4B;IAE5B,MAAM,EACJ,mBAAmB,EACnB,cAAc,EACd,uCAAuC,EACvC,sBAAsB,EACtB,gBAAgB,EAAE,oBAAoB,EACtC,yBAAyB,GAC1B,GAAG,KAAK,CAAC;IAEV,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC1C,MAAM,EAAE,eAAe,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IACxC,MAAM,YAAY,GAAG,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,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YAC9D,IAAI,KAAK,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"]}
|
|
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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keyring-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n BatchTransactionParams,\n IsAtomicBatchSupportedResultEntry,\n SecurityAlertResponse,\n TransactionController,\n ValidateSecurityRequest,\n} from '@metamask/transaction-controller';\nimport { TransactionEnvelopeType } from '@metamask/transaction-controller';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\nimport { add0x, bytesToHex } from '@metamask/utils';\nimport { groupBy } from 'lodash';\nimport { parse, v4 as uuid } from 'uuid';\n\nimport {\n EIP5792ErrorCode,\n EIP7682ErrorCode,\n KEYRING_TYPES_SUPPORTING_7702,\n MessageType,\n SupportedCapabilities,\n VERSION,\n} from '../constants';\nimport type {\n EIP5792Messenger,\n SendCallsPayload,\n SendCallsRequiredAssetsParam,\n SendCallsResult,\n} from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link processSendCalls}\n */\nexport type ProcessSendCallsHooks = {\n /** Function to add a batch of transactions atomically */\n addTransactionBatch: TransactionController['addTransactionBatch'];\n /** Function to add a single transaction */\n addTransaction: TransactionController['addTransaction'];\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if atomic batching is supported for given parameters */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to validate security for transaction requests */\n validateSecurity: (\n securityAlertId: string,\n request: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * A valid JSON-RPC request object for `wallet_sendCalls`.\n */\nexport type ProcessSendCallsRequest = JsonRpcRequest & {\n /** The identifier for the network client that has been created for this RPC endpoint */\n networkClientId: string;\n /** The origin of the RPC request */\n origin?: string;\n};\n\n/**\n * Processes a sendCalls request for EIP-5792 transactions.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param params - The sendCalls parameters containing transaction calls and metadata.\n * @param req - The original JSON-RPC request.\n * @returns Promise resolving to a SendCallsResult containing the batch ID.\n */\nexport async function processSendCalls(\n hooks: ProcessSendCallsHooks,\n messenger: EIP5792Messenger,\n params: SendCallsPayload,\n req: ProcessSendCallsRequest,\n): Promise<SendCallsResult> {\n const {\n addTransactionBatch,\n addTransaction,\n getDismissSmartAccountSuggestionEnabled,\n isAtomicBatchSupported,\n validateSecurity: validateSecurityHook,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n const { calls, from: paramFrom } = params;\n const { networkClientId, origin } = req;\n const transactions = calls.map((call) => ({ params: call }));\n\n const { chainId } = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration;\n\n const from =\n paramFrom ??\n (messenger.call('AccountsController:getSelectedAccount').address as Hex);\n\n const securityAlertId = uuid();\n const validateSecurity = validateSecurityHook.bind(null, securityAlertId);\n\n let batchId: Hex;\n if (Object.keys(transactions).length === 1) {\n batchId = await processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls: params,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n } else {\n batchId = await processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n messenger,\n networkClientId,\n origin,\n sendCalls: params,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n }\n\n return { id: batchId };\n}\n\n/**\n * Processes a single transaction from a sendCalls request.\n *\n * @param params - Object containing all parameters needed for single transaction processing.\n * @param params.addTransaction - Function to add a single transaction.\n * @param params.chainId - The chain ID for the transaction.\n * @param params.from - The sender address.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.networkClientId - The network client ID.\n * @param params.origin - The origin of the request (optional).\n * @param params.securityAlertId - The security alert ID for this transaction.\n * @param params.sendCalls - The original sendCalls request.\n * @param params.transactions - Array containing the single transaction.\n * @param params.validateSecurity - Function to validate security for the transaction.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction.\n */\nasync function processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransaction: TransactionController['addTransaction'];\n chainId: Hex;\n from: Hex;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n securityAlertId: string;\n sendCalls: SendCallsPayload;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => void;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const keyringType = getAccountKeyringType(from, messenger);\n\n validateSingleSendCall(\n sendCalls,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n const txParams = {\n from,\n ...transactions[0].params,\n type: TransactionEnvelopeType.feeMarket,\n };\n\n const securityRequest: ValidateSecurityRequest = {\n method: MessageType.SendTransaction,\n params: [txParams],\n origin,\n };\n validateSecurity(securityRequest, chainId);\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const batchId = generateBatchId();\n\n await addTransaction(txParams, {\n networkClientId,\n origin,\n securityAlertResponse: { securityAlertId } as SecurityAlertResponse,\n batchId,\n });\n return batchId;\n}\n\n/**\n * Processes multiple transactions from a sendCalls request as an atomic batch.\n *\n * @param params - Object containing all parameters needed for multiple transaction processing.\n * @param params.addTransactionBatch - Function to add a batch of transactions atomically.\n * @param params.isAtomicBatchSupported - Function to check if atomic batching is supported.\n * @param params.chainId - The chain ID for the transactions.\n * @param params.from - The sender address.\n * @param params.getDismissSmartAccountSuggestionEnabled - Function to check if smart account suggestions are disabled.\n * @param params.networkClientId - The network client ID.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.origin - The origin of the request (optional).\n * @param params.sendCalls - The original sendCalls request.\n * @param params.securityAlertId - The security alert ID for this batch.\n * @param params.transactions - Array of transactions to process.\n * @param params.validateSecurity - Function to validate security for the transactions.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction batch.\n */\nasync function processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n networkClientId,\n messenger,\n origin,\n sendCalls,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n chainId: Hex;\n from: Hex;\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n sendCalls: SendCallsPayload;\n securityAlertId: string;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const batchSupport = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const chainBatchSupport = batchSupport?.[0];\n\n const keyringType = getAccountKeyringType(from, messenger);\n\n const dismissSmartAccountSuggestionEnabled =\n getDismissSmartAccountSuggestionEnabled();\n\n validateSendCalls(\n sendCalls,\n chainId,\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const result = await addTransactionBatch({\n from,\n networkClientId,\n origin,\n securityAlertId,\n transactions,\n validateSecurity,\n });\n return result.batchId;\n}\n\n/**\n * Generate a transaction batch ID.\n *\n * @returns A unique batch ID as a hexadecimal string.\n */\nfunction generateBatchId(): Hex {\n const idString = uuid();\n const idBytes = new Uint8Array(parse(idString));\n return bytesToHex(idBytes);\n}\n\n/**\n * Validates a single sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSingleSendCall(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateDappChainId(sendCalls, dappChainId);\n}\n\n/**\n * Validates a sendCalls request for multiple transactions.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSendCalls(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateUpgrade(\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n );\n}\n\n/**\n * Validates the version of a sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @throws JsonRpcError if the version is not supported.\n */\nfunction validateSendCallsVersion(sendCalls: SendCallsPayload) {\n const { version } = sendCalls;\n\n if (version !== VERSION) {\n throw rpcErrors.invalidInput(\n `Version not supported: Got ${version}, expected ${VERSION}`,\n );\n }\n}\n\n/**\n * Validates that the chain ID in the sendCalls request matches the dApp's selected network.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @throws JsonRpcError if the chain IDs don't match\n */\nfunction validateDappChainId(sendCalls: SendCallsPayload, dappChainId: Hex) {\n const { chainId: requestChainId } = sendCalls;\n\n if (\n requestChainId &&\n requestChainId.toLowerCase() !== dappChainId.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Chain ID must match the dApp selected network: Got ${requestChainId}, expected ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates the chain ID for sendCalls requests with additional EIP-7702 support checks.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param chainBatchSupport - Information about atomic batch support for the chain\n * @throws JsonRpcError if the chain ID doesn't match or EIP-7702 is not supported\n */\nfunction validateSendCallsChainId(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n) {\n validateDappChainId(sendCalls, dappChainId);\n if (!chainBatchSupport) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedChainId,\n `EIP-7702 not supported on chain: ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates that all required capabilities in the sendCalls request are supported.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n *\n * @throws JsonRpcError if unsupported non-optional capabilities are requested.\n */\nfunction validateCapabilities(\n sendCalls: SendCallsPayload,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n const { calls, capabilities, chainId } = sendCalls;\n\n const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter(\n (name) =>\n // Non optional capabilities other than `auxiliaryFunds` are not supported by the wallet\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n capabilities?.[name].optional !== true,\n );\n\n const requiredCallCapabilities = calls.flatMap((call) =>\n Object.keys(call.capabilities ?? {}).filter(\n (name) =>\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n call.capabilities?.[name].optional !== true,\n ),\n );\n\n const requiredCapabilities = [\n ...requiredTopLevelCapabilities,\n ...requiredCallCapabilities,\n ];\n\n if (requiredCapabilities?.length) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capabilities: ${requiredCapabilities.join(\n ', ',\n )}`,\n );\n }\n\n if (capabilities?.auxiliaryFunds) {\n validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds: capabilities.auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n });\n }\n}\n\n/**\n * Validates EIP-7682 optional `requiredAssets` to see if the account and chain are supported, and that param is well-formed.\n *\n * docs: {@link https://eips.ethereum.org/EIPS/eip-7682#extended-usage-requiredassets-parameter}\n *\n * @param param - The parameter object.\n * @param param.auxiliaryFunds - The auxiliaryFunds param to validate.\n * @param param.auxiliaryFunds.optional - Metadata to signal for wallets that support this optional capability, while maintaining compatibility with wallets that do not.\n * @param param.auxiliaryFunds.requiredAssets - Metadata that enables a wallets support for `auxiliaryFunds` capability.\n * @param param.chainId - The chain ID of the incoming request.\n * @param param.keyringType - The type of keyring associated with the account.\n * @param param.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @throws JsonRpcError if auxiliary funds capability is not supported.\n */\nfunction validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n}: {\n auxiliaryFunds: {\n optional?: boolean;\n requiredAssets?: SendCallsRequiredAssetsParam[];\n };\n chainId: Hex;\n keyringType: KeyringTypes;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n // If we can make use of that capability then we should, but otherwise we can process the request and ignore the capability\n // so if the capability is signaled as optional, no validation is required, so we don't block the transaction from happening.\n if (auxiliaryFunds.optional) {\n return;\n }\n const isSupportedAccount =\n KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n\n if (!isSupportedAccount) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capability: ${SupportedCapabilities.AuxiliaryFunds}`,\n );\n }\n\n if (!isAuxiliaryFundsSupported(chainId)) {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedChain,\n `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`,\n );\n }\n\n if (!auxiliaryFunds?.requiredAssets) {\n return;\n }\n\n for (const asset of auxiliaryFunds.requiredAssets) {\n if (asset.standard !== 'erc20') {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedAsset,\n `The requested asset ${asset.address} is not available through the wallet’s auxiliary fund system: unsupported token standard ${asset.standard}`,\n );\n }\n }\n}\n\n/**\n * Validates whether an EIP-7702 upgrade is allowed for the given parameters.\n *\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @throws JsonRpcError if the upgrade is rejected due to user settings or account type.\n */\nfunction validateUpgrade(\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n) {\n if (chainBatchSupport?.delegationAddress) {\n return;\n }\n\n if (dismissSmartAccountSuggestionEnabled) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade disabled by the user',\n );\n }\n\n if (!KEYRING_TYPES_SUPPORTING_7702.includes(keyringType)) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported on account',\n );\n }\n}\n\n/**\n * Function to possibly deduplicate `auxiliaryFunds` capability `requiredAssets`.\n * Does nothing if no `requiredAssets` exists in `auxiliaryFunds` capability.\n *\n * @param sendCalls - The original sendCalls request.\n */\nfunction dedupeAuxiliaryFundsRequiredAssets(sendCalls: SendCallsPayload): void {\n if (sendCalls.capabilities?.auxiliaryFunds?.requiredAssets) {\n const { requiredAssets } = sendCalls.capabilities.auxiliaryFunds;\n // Group assets by their address (lowercased) and standard\n const grouped = groupBy(\n requiredAssets,\n (asset) => `${asset.address.toLowerCase()}-${asset.standard}`,\n );\n\n // For each group, sum the amounts and return a single asset\n const deduplicatedAssets = Object.values(grouped).map((group) => {\n if (group.length === 1) {\n return group[0];\n }\n\n const totalAmount = group.reduce((sum, asset) => {\n return sum + BigInt(asset.amount);\n }, 0n);\n\n return {\n ...group[0],\n amount: add0x(totalAmount.toString(16)),\n };\n });\n\n sendCalls.capabilities.auxiliaryFunds.requiredAssets = deduplicatedAssets;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"processSendCalls.mjs","sourceRoot":"","sources":["../../src/hooks/processSendCalls.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,6BAA6B;AAQ/D,OAAO,EAAE,uBAAuB,EAAE,yCAAyC;AAE3E,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,wBAAwB;;;AAEpD,OAAO,EAAE,KAAK,EAAE,EAAE,IAAI,IAAI,EAAE,aAAa;AAEzC,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,6BAA6B,EAC7B,WAAW,EACX,qBAAqB,EACrB,OAAO,EACR,yBAAqB;AAOtB,OAAO,EAAE,qBAAqB,EAAE,qBAAiB;AAkCjD;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,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,SA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AG,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC9D,IAAI,KAAK,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,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACxC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,YAAY,CAAC,cAAc,CAAC,cAAc,GAAG,kBAAkB,CAAC;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"]}
|
|
1
|
+
{"version":3,"file":"processSendCalls.mjs","sourceRoot":"","sources":["../../src/hooks/processSendCalls.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,SA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KAAK,CAAC,CAAC,CAAC;gBACX,MAAM,EAAE,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC;aACxC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,SAAS,CAAC,YAAY,CAAC,cAAc,CAAC,cAAc,GAAG,kBAAkB,CAAC;IAC5E,CAAC;AACH,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { JsonRpcError, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n BatchTransactionParams,\n IsAtomicBatchSupportedResultEntry,\n SecurityAlertResponse,\n TransactionController,\n ValidateSecurityRequest,\n} from '@metamask/transaction-controller';\nimport { TransactionEnvelopeType } from '@metamask/transaction-controller';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\nimport { add0x, bytesToHex } from '@metamask/utils';\nimport { groupBy } from 'lodash';\nimport { parse, v4 as uuid } from 'uuid';\n\nimport {\n EIP5792ErrorCode,\n EIP7682ErrorCode,\n KEYRING_TYPES_SUPPORTING_7702,\n MessageType,\n SupportedCapabilities,\n VERSION,\n} from '../constants';\nimport type {\n EIP5792Messenger,\n SendCallsPayload,\n SendCallsRequiredAssetsParam,\n SendCallsResult,\n} from '../types';\nimport { getAccountKeyringType } from '../utils';\n\n/**\n * Type definition for required controller hooks and utilities of {@link processSendCalls}\n */\nexport type ProcessSendCallsHooks = {\n /** Function to add a batch of transactions atomically */\n addTransactionBatch: TransactionController['addTransactionBatch'];\n /** Function to add a single transaction */\n addTransaction: TransactionController['addTransaction'];\n /** Function to check if smart account suggestions are disabled */\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n /** Function to check if atomic batching is supported for given parameters */\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n /** Function to validate security for transaction requests */\n validateSecurity: (\n securityAlertId: string,\n request: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n /** Function to validate if auxiliary funds capability is supported. */\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n};\n\n/**\n * A valid JSON-RPC request object for `wallet_sendCalls`.\n */\nexport type ProcessSendCallsRequest = JsonRpcRequest & {\n /** The identifier for the network client that has been created for this RPC endpoint */\n networkClientId: string;\n /** The origin of the RPC request */\n origin?: string;\n};\n\n/**\n * Processes a sendCalls request for EIP-5792 transactions.\n *\n * @param hooks - Object containing required controller hooks and utilities.\n * @param messenger - Messenger instance for controller communication.\n * @param params - The sendCalls parameters containing transaction calls and metadata.\n * @param req - The original JSON-RPC request.\n * @returns Promise resolving to a SendCallsResult containing the batch ID.\n */\nexport async function processSendCalls(\n hooks: ProcessSendCallsHooks,\n messenger: EIP5792Messenger,\n params: SendCallsPayload,\n req: ProcessSendCallsRequest,\n): Promise<SendCallsResult> {\n const {\n addTransactionBatch,\n addTransaction,\n getDismissSmartAccountSuggestionEnabled,\n isAtomicBatchSupported,\n validateSecurity: validateSecurityHook,\n isAuxiliaryFundsSupported,\n } = hooks;\n\n const { calls, from: paramFrom } = params;\n const { networkClientId, origin } = req;\n const transactions = calls.map((call) => ({ params: call }));\n\n const { chainId } = messenger.call(\n 'NetworkController:getNetworkClientById',\n networkClientId,\n ).configuration;\n\n const from =\n paramFrom ??\n (messenger.call('AccountsController:getSelectedAccount').address as Hex);\n\n const securityAlertId = uuid();\n const validateSecurity = validateSecurityHook.bind(null, securityAlertId);\n\n let batchId: Hex;\n if (Object.keys(transactions).length === 1) {\n batchId = await processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls: params,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n } else {\n batchId = await processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n messenger,\n networkClientId,\n origin,\n sendCalls: params,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n });\n }\n\n return { id: batchId };\n}\n\n/**\n * Processes a single transaction from a sendCalls request.\n *\n * @param params - Object containing all parameters needed for single transaction processing.\n * @param params.addTransaction - Function to add a single transaction.\n * @param params.chainId - The chain ID for the transaction.\n * @param params.from - The sender address.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.networkClientId - The network client ID.\n * @param params.origin - The origin of the request (optional).\n * @param params.securityAlertId - The security alert ID for this transaction.\n * @param params.sendCalls - The original sendCalls request.\n * @param params.transactions - Array containing the single transaction.\n * @param params.validateSecurity - Function to validate security for the transaction.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction.\n */\nasync function processSingleTransaction({\n addTransaction,\n chainId,\n from,\n messenger,\n networkClientId,\n origin,\n securityAlertId,\n sendCalls,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransaction: TransactionController['addTransaction'];\n chainId: Hex;\n from: Hex;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n securityAlertId: string;\n sendCalls: SendCallsPayload;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => void;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const keyringType = getAccountKeyringType(from, messenger);\n\n validateSingleSendCall(\n sendCalls,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n const txParams = {\n from,\n ...transactions[0].params,\n type: TransactionEnvelopeType.feeMarket,\n };\n\n const securityRequest: ValidateSecurityRequest = {\n method: MessageType.SendTransaction,\n params: [txParams],\n origin,\n };\n validateSecurity(securityRequest, chainId);\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const batchId = generateBatchId();\n\n await addTransaction(txParams, {\n networkClientId,\n origin,\n securityAlertResponse: { securityAlertId } as SecurityAlertResponse,\n batchId,\n });\n return batchId;\n}\n\n/**\n * Processes multiple transactions from a sendCalls request as an atomic batch.\n *\n * @param params - Object containing all parameters needed for multiple transaction processing.\n * @param params.addTransactionBatch - Function to add a batch of transactions atomically.\n * @param params.isAtomicBatchSupported - Function to check if atomic batching is supported.\n * @param params.chainId - The chain ID for the transactions.\n * @param params.from - The sender address.\n * @param params.getDismissSmartAccountSuggestionEnabled - Function to check if smart account suggestions are disabled.\n * @param params.networkClientId - The network client ID.\n * @param params.messenger - Messenger instance for controller communication.\n * @param params.origin - The origin of the request (optional).\n * @param params.sendCalls - The original sendCalls request.\n * @param params.securityAlertId - The security alert ID for this batch.\n * @param params.transactions - Array of transactions to process.\n * @param params.validateSecurity - Function to validate security for the transactions.\n * @param params.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @returns Promise resolving to the generated batch ID for the transaction batch.\n */\nasync function processMultipleTransaction({\n addTransactionBatch,\n isAtomicBatchSupported,\n chainId,\n from,\n getDismissSmartAccountSuggestionEnabled,\n networkClientId,\n messenger,\n origin,\n sendCalls,\n securityAlertId,\n transactions,\n validateSecurity,\n isAuxiliaryFundsSupported,\n}: {\n addTransactionBatch: TransactionController['addTransactionBatch'];\n isAtomicBatchSupported: TransactionController['isAtomicBatchSupported'];\n chainId: Hex;\n from: Hex;\n getDismissSmartAccountSuggestionEnabled: () => boolean;\n messenger: EIP5792Messenger;\n networkClientId: string;\n origin?: string;\n sendCalls: SendCallsPayload;\n securityAlertId: string;\n transactions: { params: BatchTransactionParams }[];\n validateSecurity: (\n securityRequest: ValidateSecurityRequest,\n chainId: Hex,\n ) => Promise<void>;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n const batchSupport = await isAtomicBatchSupported({\n address: from,\n chainIds: [chainId],\n });\n\n const chainBatchSupport = batchSupport?.[0];\n\n const keyringType = getAccountKeyringType(from, messenger);\n\n const dismissSmartAccountSuggestionEnabled =\n getDismissSmartAccountSuggestionEnabled();\n\n validateSendCalls(\n sendCalls,\n chainId,\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n isAuxiliaryFundsSupported,\n );\n\n dedupeAuxiliaryFundsRequiredAssets(sendCalls);\n\n const result = await addTransactionBatch({\n from,\n networkClientId,\n origin,\n securityAlertId,\n transactions,\n validateSecurity,\n });\n return result.batchId;\n}\n\n/**\n * Generate a transaction batch ID.\n *\n * @returns A unique batch ID as a hexadecimal string.\n */\nfunction generateBatchId(): Hex {\n const idString = uuid();\n const idBytes = new Uint8Array(parse(idString));\n return bytesToHex(idBytes);\n}\n\n/**\n * Validates a single sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSingleSendCall(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateDappChainId(sendCalls, dappChainId);\n}\n\n/**\n * Validates a sendCalls request for multiple transactions.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n */\nfunction validateSendCalls(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n validateSendCallsVersion(sendCalls);\n validateSendCallsChainId(sendCalls, dappChainId, chainBatchSupport);\n validateCapabilities(sendCalls, keyringType, isAuxiliaryFundsSupported);\n validateUpgrade(\n dismissSmartAccountSuggestionEnabled,\n chainBatchSupport,\n keyringType,\n );\n}\n\n/**\n * Validates the version of a sendCalls request.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @throws JsonRpcError if the version is not supported.\n */\nfunction validateSendCallsVersion(sendCalls: SendCallsPayload) {\n const { version } = sendCalls;\n\n if (version !== VERSION) {\n throw rpcErrors.invalidInput(\n `Version not supported: Got ${version}, expected ${VERSION}`,\n );\n }\n}\n\n/**\n * Validates that the chain ID in the sendCalls request matches the dApp's selected network.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @throws JsonRpcError if the chain IDs don't match\n */\nfunction validateDappChainId(sendCalls: SendCallsPayload, dappChainId: Hex) {\n const { chainId: requestChainId } = sendCalls;\n\n if (\n requestChainId &&\n requestChainId.toLowerCase() !== dappChainId.toLowerCase()\n ) {\n throw rpcErrors.invalidParams(\n `Chain ID must match the dApp selected network: Got ${requestChainId}, expected ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates the chain ID for sendCalls requests with additional EIP-7702 support checks.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param dappChainId - The chain ID that the dApp is connected to\n * @param chainBatchSupport - Information about atomic batch support for the chain\n * @throws JsonRpcError if the chain ID doesn't match or EIP-7702 is not supported\n */\nfunction validateSendCallsChainId(\n sendCalls: SendCallsPayload,\n dappChainId: Hex,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n) {\n validateDappChainId(sendCalls, dappChainId);\n if (!chainBatchSupport) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedChainId,\n `EIP-7702 not supported on chain: ${dappChainId}`,\n );\n }\n}\n\n/**\n * Validates that all required capabilities in the sendCalls request are supported.\n *\n * @param sendCalls - The sendCalls request to validate.\n * @param keyringType - The type of keyring associated with the account.\n * @param isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n *\n * @throws JsonRpcError if unsupported non-optional capabilities are requested.\n */\nfunction validateCapabilities(\n sendCalls: SendCallsPayload,\n keyringType: KeyringTypes,\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean,\n) {\n const { calls, capabilities, chainId } = sendCalls;\n\n const requiredTopLevelCapabilities = Object.keys(capabilities ?? {}).filter(\n (name) =>\n // Non optional capabilities other than `auxiliaryFunds` are not supported by the wallet\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n capabilities?.[name].optional !== true,\n );\n\n const requiredCallCapabilities = calls.flatMap((call) =>\n Object.keys(call.capabilities ?? {}).filter(\n (name) =>\n name !== SupportedCapabilities.AuxiliaryFunds.toString() &&\n call.capabilities?.[name].optional !== true,\n ),\n );\n\n const requiredCapabilities = [\n ...requiredTopLevelCapabilities,\n ...requiredCallCapabilities,\n ];\n\n if (requiredCapabilities?.length) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capabilities: ${requiredCapabilities.join(\n ', ',\n )}`,\n );\n }\n\n if (capabilities?.auxiliaryFunds) {\n validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds: capabilities.auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n });\n }\n}\n\n/**\n * Validates EIP-7682 optional `requiredAssets` to see if the account and chain are supported, and that param is well-formed.\n *\n * docs: {@link https://eips.ethereum.org/EIPS/eip-7682#extended-usage-requiredassets-parameter}\n *\n * @param param - The parameter object.\n * @param param.auxiliaryFunds - The auxiliaryFunds param to validate.\n * @param param.auxiliaryFunds.optional - Metadata to signal for wallets that support this optional capability, while maintaining compatibility with wallets that do not.\n * @param param.auxiliaryFunds.requiredAssets - Metadata that enables a wallets support for `auxiliaryFunds` capability.\n * @param param.chainId - The chain ID of the incoming request.\n * @param param.keyringType - The type of keyring associated with the account.\n * @param param.isAuxiliaryFundsSupported - Function to validate if auxiliary funds capability is supported.\n * @throws JsonRpcError if auxiliary funds capability is not supported.\n */\nfunction validateAuxFundsSupportAndRequiredAssets({\n auxiliaryFunds,\n chainId,\n keyringType,\n isAuxiliaryFundsSupported,\n}: {\n auxiliaryFunds: {\n optional?: boolean;\n requiredAssets?: SendCallsRequiredAssetsParam[];\n };\n chainId: Hex;\n keyringType: KeyringTypes;\n isAuxiliaryFundsSupported: (chainId: Hex) => boolean;\n}) {\n // If we can make use of that capability then we should, but otherwise we can process the request and ignore the capability\n // so if the capability is signaled as optional, no validation is required, so we don't block the transaction from happening.\n if (auxiliaryFunds.optional) {\n return;\n }\n const isSupportedAccount =\n KEYRING_TYPES_SUPPORTING_7702.includes(keyringType);\n\n if (!isSupportedAccount) {\n throw new JsonRpcError(\n EIP5792ErrorCode.UnsupportedNonOptionalCapability,\n `Unsupported non-optional capability: ${SupportedCapabilities.AuxiliaryFunds}`,\n );\n }\n\n if (!isAuxiliaryFundsSupported(chainId)) {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedChain,\n `The wallet no longer supports auxiliary funds on the requested chain: ${chainId}`,\n );\n }\n\n if (!auxiliaryFunds?.requiredAssets) {\n return;\n }\n\n for (const asset of auxiliaryFunds.requiredAssets) {\n if (asset.standard !== 'erc20') {\n throw new JsonRpcError(\n EIP7682ErrorCode.UnsupportedAsset,\n `The requested asset ${asset.address} is not available through the wallet’s auxiliary fund system: unsupported token standard ${asset.standard}`,\n );\n }\n }\n}\n\n/**\n * Validates whether an EIP-7702 upgrade is allowed for the given parameters.\n *\n * @param dismissSmartAccountSuggestionEnabled - Whether smart account suggestions are disabled.\n * @param chainBatchSupport - Information about atomic batch support for the chain.\n * @param keyringType - The type of keyring associated with the account.\n * @throws JsonRpcError if the upgrade is rejected due to user settings or account type.\n */\nfunction validateUpgrade(\n dismissSmartAccountSuggestionEnabled: boolean,\n chainBatchSupport: IsAtomicBatchSupportedResultEntry | undefined,\n keyringType: KeyringTypes,\n) {\n if (chainBatchSupport?.delegationAddress) {\n return;\n }\n\n if (dismissSmartAccountSuggestionEnabled) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade disabled by the user',\n );\n }\n\n if (!KEYRING_TYPES_SUPPORTING_7702.includes(keyringType)) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported on account',\n );\n }\n}\n\n/**\n * Function to possibly deduplicate `auxiliaryFunds` capability `requiredAssets`.\n * Does nothing if no `requiredAssets` exists in `auxiliaryFunds` capability.\n *\n * @param sendCalls - The original sendCalls request.\n */\nfunction dedupeAuxiliaryFundsRequiredAssets(sendCalls: SendCallsPayload): void {\n if (sendCalls.capabilities?.auxiliaryFunds?.requiredAssets) {\n const { requiredAssets } = sendCalls.capabilities.auxiliaryFunds;\n // Group assets by their address (lowercased) and standard\n const grouped = groupBy(\n requiredAssets,\n (asset) => `${asset.address.toLowerCase()}-${asset.standard}`,\n );\n\n // For each group, sum the amounts and return a single asset\n const deduplicatedAssets = Object.values(grouped).map((group) => {\n if (group.length === 1) {\n return group[0];\n }\n\n const totalAmount = group.reduce((sum, asset) => {\n return sum + BigInt(asset.amount);\n }, 0n);\n\n return {\n ...group[0],\n amount: add0x(totalAmount.toString(16)),\n };\n });\n\n sendCalls.capabilities.auxiliaryFunds.requiredAssets = deduplicatedAssets;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet_getCallsStatus.cjs","sourceRoot":"","sources":["../../src/methods/wallet_getCallsStatus.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAGjD,wCAAyE;AACzE,wCAA0C;AAE1C;;;;;;;GAOG;AACI,KAAK,UAAU,oBAAoB,CACxC,GAAmB,EACnB,GAA2B,EAC3B,EACE,cAAc,GAGf;IAED,IAAI,CAAC,cAAc,EAAE;
|
|
1
|
+
{"version":3,"file":"wallet_getCallsStatus.cjs","sourceRoot":"","sources":["../../src/methods/wallet_getCallsStatus.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAGjD,wCAAyE;AACzE,wCAA0C;AAE1C;;;;;;;GAOG;AACI,KAAK,UAAU,oBAAoB,CACxC,GAAmB,EACnB,GAA2B,EAC3B,EACE,cAAc,GAGf;IAED,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,sBAAS,CAAC,kBAAkB,EAAE,CAAC;IACvC,CAAC;IAED,IAAA,sBAAc,EAAC,GAAG,CAAC,MAAM,EAAE,4BAAoB,CAAC,CAAC;IAEjD,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAEzB,GAAG,CAAC,MAAM,GAAG,MAAM,cAAc,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC;AAlBD,oDAkBC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { type GetCallsStatusHook, GetCallsStatusStruct } from '../types';\nimport { validateParams } from '../utils';\n\n/**\n * The RPC method handler middleware for `wallet_getCallStatus`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks object.\n * @param hooks.getCallsStatus - Function that retrieves the status of a transaction batch by its ID.\n */\nexport async function walletGetCallsStatus(\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n {\n getCallsStatus,\n }: {\n getCallsStatus?: GetCallsStatusHook;\n },\n): Promise<void> {\n if (!getCallsStatus) {\n throw rpcErrors.methodNotSupported();\n }\n\n validateParams(req.params, GetCallsStatusStruct);\n\n const id = req.params[0];\n\n res.result = await getCallsStatus(id, req);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet_getCallsStatus.mjs","sourceRoot":"","sources":["../../src/methods/wallet_getCallsStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAGjD,OAAO,EAA2B,oBAAoB,EAAE,qBAAiB;AACzE,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAE1C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAmB,EACnB,GAA2B,EAC3B,EACE,cAAc,GAGf;IAED,IAAI,CAAC,cAAc,EAAE;
|
|
1
|
+
{"version":3,"file":"wallet_getCallsStatus.mjs","sourceRoot":"","sources":["../../src/methods/wallet_getCallsStatus.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAGjD,OAAO,EAA2B,oBAAoB,EAAE,qBAAiB;AACzE,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAE1C;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CACxC,GAAmB,EACnB,GAA2B,EAC3B,EACE,cAAc,GAGf;IAED,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,SAAS,CAAC,kBAAkB,EAAE,CAAC;IACvC,CAAC;IAED,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,oBAAoB,CAAC,CAAC;IAEjD,MAAM,EAAE,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAEzB,GAAG,CAAC,MAAM,GAAG,MAAM,cAAc,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC;AAC7C,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { type GetCallsStatusHook, GetCallsStatusStruct } from '../types';\nimport { validateParams } from '../utils';\n\n/**\n * The RPC method handler middleware for `wallet_getCallStatus`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks object.\n * @param hooks.getCallsStatus - Function that retrieves the status of a transaction batch by its ID.\n */\nexport async function walletGetCallsStatus(\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n {\n getCallsStatus,\n }: {\n getCallsStatus?: GetCallsStatusHook;\n },\n): Promise<void> {\n if (!getCallsStatus) {\n throw rpcErrors.methodNotSupported();\n }\n\n validateParams(req.params, GetCallsStatusStruct);\n\n const id = req.params[0];\n\n res.result = await getCallsStatus(id, req);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet_getCapabilities.cjs","sourceRoot":"","sources":["../../src/methods/wallet_getCapabilities.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAGjD,wCAA2E;AAC3E,wCAAyE;AAEzE;;;;;;;;GAQG;AACI,KAAK,UAAU,qBAAqB,CACzC,GAAmB,EACnB,GAA2B,EAC3B,EACE,WAAW,EACX,eAAe,GAIhB;IAED,IAAI,CAAC,eAAe,EAAE;
|
|
1
|
+
{"version":3,"file":"wallet_getCapabilities.cjs","sourceRoot":"","sources":["../../src/methods/wallet_getCapabilities.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAGjD,wCAA2E;AAC3E,wCAAyE;AAEzE;;;;;;;;GAQG;AACI,KAAK,UAAU,qBAAqB,CACzC,GAAmB,EACnB,GAA2B,EAC3B,EACE,WAAW,EACX,eAAe,GAIhB;IAED,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,sBAAS,CAAC,kBAAkB,EAAE,CAAC;IACvC,CAAC;IAED,IAAA,sBAAc,EAAC,GAAG,CAAC,MAAM,EAAE,6BAAqB,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAE/B,MAAM,IAAA,qCAA6B,EAAC,OAAO,EAAE,GAAG,EAAE;QAChD,WAAW;KACZ,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IAEnE,GAAG,CAAC,MAAM,GAAG,YAAY,CAAC;AAC5B,CAAC;AA3BD,sDA2BC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { type GetCapabilitiesHook, GetCapabilitiesStruct } from '../types';\nimport { validateAndNormalizeKeyholder, validateParams } from '../utils';\n\n/**\n * The RPC method handler middleware for `wallet_getCapabilities`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks object.\n * @param hooks.getAccounts - Function that retrieves available accounts.\n * @param hooks.getCapabilities - Function that retrieves the capabilities for atomic transactions on specified chains.\n */\nexport async function walletGetCapabilities(\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n {\n getAccounts,\n getCapabilities,\n }: {\n getAccounts: (req: JsonRpcRequest) => Promise<string[]>;\n getCapabilities?: GetCapabilitiesHook;\n },\n): Promise<void> {\n if (!getCapabilities) {\n throw rpcErrors.methodNotSupported();\n }\n\n validateParams(req.params, GetCapabilitiesStruct);\n\n const address = req.params[0];\n const chainIds = req.params[1];\n\n await validateAndNormalizeKeyholder(address, req, {\n getAccounts,\n });\n\n const capabilities = await getCapabilities(address, chainIds, req);\n\n res.result = capabilities;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet_getCapabilities.mjs","sourceRoot":"","sources":["../../src/methods/wallet_getCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAGjD,OAAO,EAA4B,qBAAqB,EAAE,qBAAiB;AAC3E,OAAO,EAAE,6BAA6B,EAAE,cAAc,EAAE,qBAAiB;AAEzE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,GAAmB,EACnB,GAA2B,EAC3B,EACE,WAAW,EACX,eAAe,GAIhB;IAED,IAAI,CAAC,eAAe,EAAE;
|
|
1
|
+
{"version":3,"file":"wallet_getCapabilities.mjs","sourceRoot":"","sources":["../../src/methods/wallet_getCapabilities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAGjD,OAAO,EAA4B,qBAAqB,EAAE,qBAAiB;AAC3E,OAAO,EAAE,6BAA6B,EAAE,cAAc,EAAE,qBAAiB;AAEzE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,qBAAqB,CACzC,GAAmB,EACnB,GAA2B,EAC3B,EACE,WAAW,EACX,eAAe,GAIhB;IAED,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,SAAS,CAAC,kBAAkB,EAAE,CAAC;IACvC,CAAC;IAED,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,qBAAqB,CAAC,CAAC;IAElD,MAAM,OAAO,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAC9B,MAAM,QAAQ,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAE/B,MAAM,6BAA6B,CAAC,OAAO,EAAE,GAAG,EAAE;QAChD,WAAW;KACZ,CAAC,CAAC;IAEH,MAAM,YAAY,GAAG,MAAM,eAAe,CAAC,OAAO,EAAE,QAAQ,EAAE,GAAG,CAAC,CAAC;IAEnE,GAAG,CAAC,MAAM,GAAG,YAAY,CAAC;AAC5B,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { type GetCapabilitiesHook, GetCapabilitiesStruct } from '../types';\nimport { validateAndNormalizeKeyholder, validateParams } from '../utils';\n\n/**\n * The RPC method handler middleware for `wallet_getCapabilities`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks object.\n * @param hooks.getAccounts - Function that retrieves available accounts.\n * @param hooks.getCapabilities - Function that retrieves the capabilities for atomic transactions on specified chains.\n */\nexport async function walletGetCapabilities(\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n {\n getAccounts,\n getCapabilities,\n }: {\n getAccounts: (req: JsonRpcRequest) => Promise<string[]>;\n getCapabilities?: GetCapabilitiesHook;\n },\n): Promise<void> {\n if (!getCapabilities) {\n throw rpcErrors.methodNotSupported();\n }\n\n validateParams(req.params, GetCapabilitiesStruct);\n\n const address = req.params[0];\n const chainIds = req.params[1];\n\n await validateAndNormalizeKeyholder(address, req, {\n getAccounts,\n });\n\n const capabilities = await getCapabilities(address, chainIds, req);\n\n res.result = capabilities;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet_sendCalls.cjs","sourceRoot":"","sources":["../../src/methods/wallet_sendCalls.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAGjD,wCAIkB;AAClB,wCAAyE;AAEzE;;;;;;;;GAQG;AACI,KAAK,UAAU,eAAe,CACnC,GAAmB,EACnB,GAA2B,EAC3B,EACE,WAAW,EACX,gBAAgB,GAIjB;IAED,IAAI,CAAC,gBAAgB,EAAE;
|
|
1
|
+
{"version":3,"file":"wallet_sendCalls.cjs","sourceRoot":"","sources":["../../src/methods/wallet_sendCalls.ts"],"names":[],"mappings":";;;AAAA,qDAAiD;AAGjD,wCAIkB;AAClB,wCAAyE;AAEzE;;;;;;;;GAQG;AACI,KAAK,UAAU,eAAe,CACnC,GAAmB,EACnB,GAA2B,EAC3B,EACE,WAAW,EACX,gBAAgB,GAIjB;IAED,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,sBAAS,CAAC,kBAAkB,EAAE,CAAC;IACvC,CAAC;IAED,IAAA,sBAAc,EAAC,GAAG,CAAC,MAAM,EAAE,uBAAe,CAAC,CAAC;IAE5C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAE7B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI;QACtB,CAAC,CAAC,MAAM,IAAA,qCAA6B,EAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACpD,WAAW;SACZ,CAAC;QACJ,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,SAAS,GAAqB;QAClC,GAAG,MAAM;QACT,IAAI;KACL,CAAC;IAEF,GAAG,CAAC,MAAM,GAAG,MAAM,gBAAgB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC;AA/BD,0CA+BC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport {\n type ProcessSendCallsHook,\n type SendCallsPayload,\n SendCallsStruct,\n} from '../types';\nimport { validateAndNormalizeKeyholder, validateParams } from '../utils';\n\n/**\n * The RPC method handler middleware for `wallet_sendCalls`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks object.\n * @param hooks.getAccounts - Function that retrieves available accounts.\n * @param hooks.processSendCalls - Function that processes a sendCalls request for EIP-5792 transactions.\n */\nexport async function walletSendCalls(\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n {\n getAccounts,\n processSendCalls,\n }: {\n getAccounts: (req: JsonRpcRequest) => Promise<string[]>;\n processSendCalls?: ProcessSendCallsHook;\n },\n): Promise<void> {\n if (!processSendCalls) {\n throw rpcErrors.methodNotSupported();\n }\n\n validateParams(req.params, SendCallsStruct);\n\n const params = req.params[0];\n\n const from = params.from\n ? await validateAndNormalizeKeyholder(params.from, req, {\n getAccounts,\n })\n : undefined;\n\n const sendCalls: SendCallsPayload = {\n ...params,\n from,\n };\n\n res.result = await processSendCalls(sendCalls, req);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet_sendCalls.mjs","sourceRoot":"","sources":["../../src/methods/wallet_sendCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAGjD,OAAO,EAGL,eAAe,EAChB,qBAAiB;AAClB,OAAO,EAAE,6BAA6B,EAAE,cAAc,EAAE,qBAAiB;AAEzE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,GAAmB,EACnB,GAA2B,EAC3B,EACE,WAAW,EACX,gBAAgB,GAIjB;IAED,IAAI,CAAC,gBAAgB,EAAE;
|
|
1
|
+
{"version":3,"file":"wallet_sendCalls.mjs","sourceRoot":"","sources":["../../src/methods/wallet_sendCalls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAGjD,OAAO,EAGL,eAAe,EAChB,qBAAiB;AAClB,OAAO,EAAE,6BAA6B,EAAE,cAAc,EAAE,qBAAiB;AAEzE;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,GAAmB,EACnB,GAA2B,EAC3B,EACE,WAAW,EACX,gBAAgB,GAIjB;IAED,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACtB,MAAM,SAAS,CAAC,kBAAkB,EAAE,CAAC;IACvC,CAAC;IAED,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAC;IAE5C,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAE7B,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI;QACtB,CAAC,CAAC,MAAM,6BAA6B,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,EAAE;YACpD,WAAW;SACZ,CAAC;QACJ,CAAC,CAAC,SAAS,CAAC;IAEd,MAAM,SAAS,GAAqB;QAClC,GAAG,MAAM;QACT,IAAI;KACL,CAAC;IAEF,GAAG,CAAC,MAAM,GAAG,MAAM,gBAAgB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AACtD,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\nimport type { JsonRpcRequest, PendingJsonRpcResponse } from '@metamask/utils';\n\nimport {\n type ProcessSendCallsHook,\n type SendCallsPayload,\n SendCallsStruct,\n} from '../types';\nimport { validateAndNormalizeKeyholder, validateParams } from '../utils';\n\n/**\n * The RPC method handler middleware for `wallet_sendCalls`\n *\n * @param req - The JSON RPC request's end callback.\n * @param res - The JSON RPC request's pending response object.\n * @param hooks - The hooks object.\n * @param hooks.getAccounts - Function that retrieves available accounts.\n * @param hooks.processSendCalls - Function that processes a sendCalls request for EIP-5792 transactions.\n */\nexport async function walletSendCalls(\n req: JsonRpcRequest,\n res: PendingJsonRpcResponse,\n {\n getAccounts,\n processSendCalls,\n }: {\n getAccounts: (req: JsonRpcRequest) => Promise<string[]>;\n processSendCalls?: ProcessSendCallsHook;\n },\n): Promise<void> {\n if (!processSendCalls) {\n throw rpcErrors.methodNotSupported();\n }\n\n validateParams(req.params, SendCallsStruct);\n\n const params = req.params[0];\n\n const from = params.from\n ? await validateAndNormalizeKeyholder(params.from, req, {\n getAccounts,\n })\n : undefined;\n\n const sendCalls: SendCallsPayload = {\n ...params,\n from,\n };\n\n res.result = await processSendCalls(sendCalls, req);\n}\n"]}
|
package/dist/utils.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,qDAA+E;AAE/E,uDAAiD;AAGjD,+CAA+C;AAG/C;;;;;;;GAOG;AACH,SAAgB,qBAAqB,CACnC,cAAmB,EACnB,SAA2B;IAE3B,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,IAAI,CACjC,6BAA6B,CAC9B,CAAC,gBAAgB,CAAC;IAEnB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAC1C,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,cAAc,CAAC,WAAW,EAAE,CACpE,CAAC;IAEF,MAAM,WAAW,GAAG,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC;IAErD,IAAI,CAAC,WAAW,EAAE;
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;AACA,qDAA+E;AAE/E,uDAAiD;AAGjD,+CAA+C;AAG/C;;;;;;;G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,CAAC;IAED,MAAM,sBAAS,CAAC,aAAa,CAAC;QAC5B,OAAO,EAAE,uDAAuD;KACjE,CAAC,CAAC;AACL,CAAC;AA9BD,sEA8BC;AAED;;;;;;GAMG;AACH,SAAgB,cAAc,CAC5B,KAA2B,EAC3B,MAA0B;IAE1B,MAAM,CAAC,KAAK,CAAC,GAAG,IAAA,sBAAQ,EAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAExC,IAAI,KAAK,EAAE,CAAC;QACV,MAAM,sBAAS,CAAC,aAAa,CAC3B,qBAAqB,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAC/C,CAAC;IACJ,CAAC;AACH,CAAC;AAXD,wCAWC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,GAAW;IAC1C,0BAA0B;IAC1B,OAAO,GAAG,CAAC,MAAM,KAAK,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AACnC,CAAC;AAHD,4CAGC;AAED;;;;;;GAMG;AACH,SAAS,qBAAqB,CAAC,KAAkB,EAAE,OAAe;IAChE,OAAO,GAAG,OAAO,OAAO,KAAK;SAC1B,QAAQ,EAAE;SACV,GAAG,CACF,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CACxE;SACA,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { JsonRpcError, providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\n\nimport { EIP5792ErrorCode } from './constants';\nimport type { EIP5792Messenger } from './types';\n\n/**\n * Retrieves the keyring type for a given account address.\n *\n * @param accountAddress - The account address to look up.\n * @param messenger - Messenger instance for controller communication.\n * @returns The keyring type associated with the account.\n * @throws JsonRpcError if the account type is unknown or not found.\n */\nexport function getAccountKeyringType(\n accountAddress: Hex,\n messenger: EIP5792Messenger,\n): KeyringTypes {\n const { accounts } = messenger.call(\n 'AccountsController:getState',\n ).internalAccounts;\n\n const account = Object.values(accounts).find(\n (acc) => acc.address.toLowerCase() === accountAddress.toLowerCase(),\n );\n\n const keyringType = account?.metadata?.keyring?.type;\n\n if (!keyringType) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported as account type is unknown',\n );\n }\n\n return keyringType as KeyringTypes;\n}\n\n/**\n * Validates and normalizes a keyholder address for EIP-5792 operations.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param req - The JSON-RPC request object for permission checking.\n * @param options - Configuration object containing the getAccounts function.\n * @param options.getAccounts - Function to retrieve accounts for the requester.\n * @returns A normalized (lowercase) hex address if valid and authorized.\n * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.\n * @throws JsonRpcError with invalid params if the address format is invalid.\n */\nexport async function validateAndNormalizeKeyholder(\n address: Hex,\n req: JsonRpcRequest,\n { getAccounts }: { getAccounts: (req: JsonRpcRequest) => Promise<string[]> },\n): Promise<Hex> {\n if (\n typeof address === 'string' &&\n address.length > 0 &&\n resemblesAddress(address)\n ) {\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getAccounts(req);\n\n const normalizedAccounts: string[] = accounts.map((_address) =>\n _address.toLowerCase(),\n );\n\n const normalizedAddress = address.toLowerCase() as Hex;\n\n if (normalizedAccounts.includes(normalizedAddress)) {\n return normalizedAddress;\n }\n\n throw providerErrors.unauthorized();\n }\n\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an Ethereum address.`,\n });\n}\n\n/**\n * Validates parameters against a Superstruct schema and throws an error if validation fails.\n *\n * @param value - The value to validate against the struct schema.\n * @param struct - The Superstruct schema to validate against.\n * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.\n */\nexport function validateParams<ParamsType>(\n value: unknown | ParamsType,\n struct: Struct<ParamsType>,\n): asserts value is ParamsType {\n const [error] = validate(value, struct);\n\n if (error) {\n throw rpcErrors.invalidParams(\n formatValidationError(error, `Invalid params`),\n );\n }\n}\n\n/**\n * Checks if a string resembles an Ethereum address format.\n *\n * @param str - The string to check for address-like format.\n * @returns True if the string has the correct length for an Ethereum address.\n */\nexport function resemblesAddress(str: string): boolean {\n // hex prefix 2 + 20 bytes\n return str.length === 2 + 20 * 2;\n}\n\n/**\n * Formats a Superstruct validation error into a human-readable string.\n *\n * @param error - The Superstruct validation error to format.\n * @param message - The base error message to prepend to the formatted details.\n * @returns A formatted error message string with validation failure details.\n */\nfunction formatValidationError(error: StructError, message: string): string {\n return `${message}\\n\\n${error\n .failures()\n .map(\n (f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`,\n )\n .join('\\n')}`;\n}\n"]}
|
package/dist/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAE/E,OAAO,EAAE,QAAQ,EAAE,8BAA8B;AAGjD,OAAO,EAAE,gBAAgB,EAAE,wBAAoB;AAG/C;;;;;;;GAOG;AACH,MAAM,UAAU,qBAAqB,CACnC,cAAmB,EACnB,SAA2B;IAE3B,MAAM,EAAE,QAAQ,EAAE,GAAG,SAAS,CAAC,IAAI,CACjC,6BAA6B,CAC9B,CAAC,gBAAgB,CAAC;IAEnB,MAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,IAAI,CAC1C,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC,WA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AE,GAAG,CAAC,CAAC,OAAO,EAAE,CACxE;SACA,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import type { KeyringTypes } from '@metamask/keyring-controller';\nimport { JsonRpcError, providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { Struct, StructError } from '@metamask/superstruct';\nimport { validate } from '@metamask/superstruct';\nimport type { Hex, JsonRpcRequest } from '@metamask/utils';\n\nimport { EIP5792ErrorCode } from './constants';\nimport type { EIP5792Messenger } from './types';\n\n/**\n * Retrieves the keyring type for a given account address.\n *\n * @param accountAddress - The account address to look up.\n * @param messenger - Messenger instance for controller communication.\n * @returns The keyring type associated with the account.\n * @throws JsonRpcError if the account type is unknown or not found.\n */\nexport function getAccountKeyringType(\n accountAddress: Hex,\n messenger: EIP5792Messenger,\n): KeyringTypes {\n const { accounts } = messenger.call(\n 'AccountsController:getState',\n ).internalAccounts;\n\n const account = Object.values(accounts).find(\n (acc) => acc.address.toLowerCase() === accountAddress.toLowerCase(),\n );\n\n const keyringType = account?.metadata?.keyring?.type;\n\n if (!keyringType) {\n throw new JsonRpcError(\n EIP5792ErrorCode.RejectedUpgrade,\n 'EIP-7702 upgrade not supported as account type is unknown',\n );\n }\n\n return keyringType as KeyringTypes;\n}\n\n/**\n * Validates and normalizes a keyholder address for EIP-5792 operations.\n *\n * @param address - The Ethereum address to validate and normalize.\n * @param req - The JSON-RPC request object for permission checking.\n * @param options - Configuration object containing the getAccounts function.\n * @param options.getAccounts - Function to retrieve accounts for the requester.\n * @returns A normalized (lowercase) hex address if valid and authorized.\n * @throws JsonRpcError with unauthorized error if the requester doesn't have permission to access the address.\n * @throws JsonRpcError with invalid params if the address format is invalid.\n */\nexport async function validateAndNormalizeKeyholder(\n address: Hex,\n req: JsonRpcRequest,\n { getAccounts }: { getAccounts: (req: JsonRpcRequest) => Promise<string[]> },\n): Promise<Hex> {\n if (\n typeof address === 'string' &&\n address.length > 0 &&\n resemblesAddress(address)\n ) {\n // Ensure that an \"unauthorized\" error is thrown if the requester\n // does not have the `eth_accounts` permission.\n const accounts = await getAccounts(req);\n\n const normalizedAccounts: string[] = accounts.map((_address) =>\n _address.toLowerCase(),\n );\n\n const normalizedAddress = address.toLowerCase() as Hex;\n\n if (normalizedAccounts.includes(normalizedAddress)) {\n return normalizedAddress;\n }\n\n throw providerErrors.unauthorized();\n }\n\n throw rpcErrors.invalidParams({\n message: `Invalid parameters: must provide an Ethereum address.`,\n });\n}\n\n/**\n * Validates parameters against a Superstruct schema and throws an error if validation fails.\n *\n * @param value - The value to validate against the struct schema.\n * @param struct - The Superstruct schema to validate against.\n * @throws JsonRpcError with invalid params if the value doesn't match the struct schema.\n */\nexport function validateParams<ParamsType>(\n value: unknown | ParamsType,\n struct: Struct<ParamsType>,\n): asserts value is ParamsType {\n const [error] = validate(value, struct);\n\n if (error) {\n throw rpcErrors.invalidParams(\n formatValidationError(error, `Invalid params`),\n );\n }\n}\n\n/**\n * Checks if a string resembles an Ethereum address format.\n *\n * @param str - The string to check for address-like format.\n * @returns True if the string has the correct length for an Ethereum address.\n */\nexport function resemblesAddress(str: string): boolean {\n // hex prefix 2 + 20 bytes\n return str.length === 2 + 20 * 2;\n}\n\n/**\n * Formats a Superstruct validation error into a human-readable string.\n *\n * @param error - The Superstruct validation error to format.\n * @param message - The base error message to prepend to the formatted details.\n * @returns A formatted error message string with validation failure details.\n */\nfunction formatValidationError(error: StructError, message: string): string {\n return `${message}\\n\\n${error\n .failures()\n .map(\n (f) => `${f.path.join(' > ')}${f.path.length ? ' - ' : ''}${f.message}`,\n )\n .join('\\n')}`;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/eip-5792-middleware",
|
|
3
|
-
"version": "2.0.0-preview-
|
|
3
|
+
"version": "2.0.0-preview-91b0ac79",
|
|
4
4
|
"description": "Implements the JSON-RPC methods for sending multiple calls from the user's wallet, and checking their status, as referenced in EIP-5792",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"ts-jest": "^27.1.4",
|
|
68
68
|
"typedoc": "^0.24.8",
|
|
69
69
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
70
|
-
"typescript": "~5.
|
|
70
|
+
"typescript": "~5.3.3"
|
|
71
71
|
},
|
|
72
72
|
"engines": {
|
|
73
73
|
"node": "^18.18 || >=20"
|