@metamask-previews/transaction-controller 72.2.1-preview-5669a8ae0 → 72.3.0-preview-bbbbbb9f2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [72.3.0]
|
|
11
|
+
|
|
10
12
|
### Added
|
|
11
13
|
|
|
12
14
|
- Add `mode` to the `estimateGasBatch` result, `eip7702` for a single gas limit of the outer EIP-7702 transaction or `separate` for one gas limit per transaction, and export the `EstimateGasBatchMode` and `EstimateGasBatchResult` types ([#10790](https://github.com/MetaMask/core/pull/10790))
|
|
@@ -33,6 +35,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
33
35
|
|
|
34
36
|
### Fixed
|
|
35
37
|
|
|
38
|
+
- Treat `MPC Money Keyring` accounts as EIP-7702 capable, so deposits no longer fail with "Account does not support EIP-7702" ([#11153](https://github.com/MetaMask/core/pull/11153))
|
|
36
39
|
- Exclude the unused gas refund from `nativeBalanceChange` when the simulation credits the sender without debiting the gas cost ([#10614](https://github.com/MetaMask/core/pull/10614))
|
|
37
40
|
- On Arc the simulated state diff credits the fee recipient and, when the gas limit exceeds the gas used, refunds the sender's unused gas, but never debits the upfront gas, so a value-0 call was reported as an incoming native balance and a native send under-reported its decrease.
|
|
38
41
|
|
|
@@ -2863,7 +2866,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
2863
2866
|
|
|
2864
2867
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
2865
2868
|
|
|
2866
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.
|
|
2869
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.3.0...HEAD
|
|
2870
|
+
[72.3.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.2.1...@metamask/transaction-controller@72.3.0
|
|
2867
2871
|
[72.2.1]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.2.0...@metamask/transaction-controller@72.2.1
|
|
2868
2872
|
[72.2.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.1.0...@metamask/transaction-controller@72.2.0
|
|
2869
2873
|
[72.1.0]: https://github.com/MetaMask/core/compare/@metamask/transaction-controller@72.0.1...@metamask/transaction-controller@72.1.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eip7702.d.ts","sourceRoot":"","sources":["../../src/utils/eip7702.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAK3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,eAAe,EAChB,MAAM,aAAa,CAAC;AAOrB,eAAO,MAAM,iBAAiB,aAAa,CAAC;AAC5C,eAAO,MAAM,mBAAmB,YAAY,CAAC;AAC7C,eAAO,MAAM,eAAe,8BAA8B,CAAC;AAC3D,eAAO,MAAM,uBAAuB,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"eip7702.d.ts","sourceRoot":"","sources":["../../src/utils/eip7702.ts"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AAEpE,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AAK3C,OAAO,KAAK,EAAE,8BAA8B,EAAE,MAAM,6BAA6B,CAAC;AAClF,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACvB,aAAa,EACb,iBAAiB,EACjB,e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CAAC;IAC7C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,GAAG,CAAC,2CAA2C,EAAE,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3E,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CACvC,aAA4B,EAC5B,eAAuB;IAEvB,IAAI,CAAC,qBAAqB,CAAC,aAAa,CAAC,EAAE,CAAC;QAC1C,OAAO,eAAsB,CAAC;IAChC,CAAC;IAED,OAAO,6BAA6B,CAAC,aAAa,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,aAA4B,EAC5B,eAAgC,EAChC,KAAa;IAEb,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,aAAa,CAAC;IACzE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,eAAe,CAAC;IAClE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,QAAQ,CAAC;IAE7C,MAAM,OAAO,GAAG,eAAe,IAAI,kBAAkB,CAAC;IACtD,IAAI,KAAK,GAAG,aAAa,CAAC;IAE1B,KAAK,KAAK,KAAK,CAAC,QAAQ,CAAC,gBAA0B,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAEtE,MAAM,MAAM,GAAG;QACb,GAAG,aAAa;QAChB,OAAO;QACP,KAAK;KACN,CAAC;IAEF,GAAG,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;IAEtC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { RLP } from '@ethereumjs/rlp';\nimport {\n bigIntToUnpaddedBytes,\n bytesToHex,\n ecrecover,\n hexToBytes,\n pubToAddress,\n} from '@ethereumjs/util';\nimport { defaultAbiCoder } from '@ethersproject/abi';\nimport { Contract } from '@ethersproject/contracts';\nimport { toHex } from '@metamask/controller-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { createModuleLogger, add0x } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport { keccak256 } from 'ethereum-cryptography/keccak';\n\nimport { ABI_IERC7821 } from '../constants.js';\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n BatchTransactionParams,\n NestedTransactionUpdate,\n Authorization,\n AuthorizationList,\n TransactionMeta,\n} from '../types.js';\nimport {\n getEIP7702ContractAddresses,\n getEIP7702SupportedChains,\n} from './feature-flags.js';\nimport { rpcRequest } from './provider.js';\n\nexport const DELEGATION_PREFIX = '0xef0100';\nexport const BATCH_FUNCTION_NAME = 'execute';\nexport const CALLS_SIGNATURE = '(address,uint256,bytes)[]';\nexport const ERROR_MESSGE_PUBLIC_KEY = 'EIP-7702 public key not specified';\n\n/** EIP-7702 authorization signature magic prefix. */\nconst EIP7702_AUTHORIZATION_MAGIC = 0x05;\n\n/**\n * ERC-7579 ModeCode encoding for the ERC-7821 `execute` function.\n *\n * Layout: | CallType (1 byte) | ExecType (1 byte) | Unused (4 bytes) | ModeSelector (4 bytes) | ModePayload (22 bytes) |\n *\n * - CallType 0x01 = batch\n * - ExecType 0x00 = default (revert on failure)\n * - ExecType 0x01 = try (skip on failure)\n */\nconst ERC7579_CALL_TYPE_BATCH = '01';\nconst ERC7579_EXEC_TYPE_DEFAULT = '00';\nconst ERC7579_EXEC_TYPE_TRY = '01';\n\nconst log = createModuleLogger(projectLogger, 'eip-7702');\n\nconst KEYRING_TYPES_SUPPORTING_7702 = [\n 'HD Key Tree',\n 'Simple Key Pair',\n 'Money Keyring',\n];\n\n/**\n * Check whether a given account's keyring supports EIP-7702 authorization\n * signing.\n *\n * Looks up the account's keyring via `KeyringController:getState` and returns\n * `true` only when the keyring type is in the supported list.\n * Returns `false` when the keyring cannot be resolved.\n *\n * @param messenger - Controller messenger.\n * @param account - The account address to check.\n * @returns Whether the account supports EIP-7702.\n */\nexport function doesAccountSupportEIP7702(\n messenger: TransactionControllerMessenger,\n account: string,\n): boolean {\n const { keyrings } = messenger.call('KeyringController:getState');\n\n return keyrings.some(\n (k: { type: string; accounts: string[] }) =>\n KEYRING_TYPES_SUPPORTING_7702.includes(k.type) &&\n k.accounts.some((a: string) => a.toLowerCase() === account.toLowerCase()),\n );\n}\n\n/**\n * Determine if a chain supports EIP-7702 using LaunchDarkly feature flag.\n *\n * @param chainId - Hexadecimal ID of the chain.\n * @param messenger - Messenger instance.\n * @returns True if the chain supports EIP-7702.\n */\nexport function doesChainSupportEIP7702(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): boolean {\n const supportedChains = getEIP7702SupportedChains(messenger);\n\n return supportedChains.some(\n (supportedChainId) =>\n supportedChainId.toLowerCase() === chainId.toLowerCase(),\n );\n}\n\n/**\n * Retrieve the delegation address for an account.\n *\n * @param address - The address to check.\n * @param messenger - The TransactionController messenger.\n * @param networkClientId - The network client ID to use.\n * @returns The delegation address if it exists.\n */\nexport async function getDelegationAddress(\n address: Hex,\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n): Promise<Hex | undefined> {\n const code = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_getCode',\n params: [address, 'latest'],\n })) as string;\n const normalizedCode = add0x(code?.toLowerCase?.() ?? '');\n\n const hasDelegation =\n code?.length === 48 && normalizedCode.startsWith(DELEGATION_PREFIX);\n\n return hasDelegation\n ? add0x(normalizedCode.slice(DELEGATION_PREFIX.length))\n : undefined;\n}\n\n/**\n * Determine if an account has been upgraded to a supported EIP-7702 contract.\n *\n * @param address - The EOA address to check.\n * @param chainId - The chain ID.\n * @param publicKey - Public key used to validate EIP-7702 contract signatures in feature flags.\n * @param messenger - The messenger instance.\n * @param networkClientId - The network client ID to use.\n * @returns An object with the results of the check.\n */\nexport async function isAccountUpgradedToEIP7702(\n address: Hex,\n chainId: Hex,\n publicKey: Hex,\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n): Promise<{\n delegationAddress: Hex | undefined;\n isSupported: boolean;\n}> {\n const contractAddresses = getEIP7702ContractAddresses(\n chainId,\n messenger,\n publicKey,\n );\n\n const delegationAddress = await getDelegationAddress(\n address,\n messenger,\n networkClientId,\n );\n\n const isSupported = Boolean(\n delegationAddress &&\n contractAddresses.some(\n (contract) => contract.toLowerCase() === delegationAddress.toLowerCase(),\n ),\n );\n\n return {\n delegationAddress,\n isSupported,\n };\n}\n\n/**\n * Update indexed transactions in an EIP-7702 batch and regenerate its calldata.\n *\n * @param options - Update options.\n * @param options.from - The sender address.\n * @param options.transactions - The existing nested transactions.\n * @param options.updates - Indexed calldata updates.\n * @returns Updated nested transactions and regenerated batch calldata.\n */\nexport function updateEIP7702BatchData({\n from,\n transactions,\n updates,\n}: {\n from: Hex;\n transactions: BatchTransactionParams[];\n updates: NestedTransactionUpdate[];\n}): {\n nestedTransactions: BatchTransactionParams[];\n transactionData: Hex;\n} {\n const updatesByIndex = new Map<number, Hex>();\n\n for (const { transactionIndex, transactionData } of updates) {\n if (updatesByIndex.has(transactionIndex)) {\n throw new Error(\n `Duplicate nested transaction index - ${transactionIndex}`,\n );\n }\n\n if (!transactions[transactionIndex]) {\n throw new Error(\n `Nested transaction not found with index - ${transactionIndex}`,\n );\n }\n\n updatesByIndex.set(transactionIndex, transactionData);\n }\n\n const nestedTransactions = transactions.map((transaction, index) => {\n const transactionData = updatesByIndex.get(index);\n\n return {\n ...transaction,\n ...(transactionData === undefined ? {} : { data: transactionData }),\n };\n });\n const batchTransaction = generateEIP7702BatchTransaction(\n from,\n nestedTransactions,\n );\n\n return {\n nestedTransactions,\n transactionData: batchTransaction.data as Hex,\n };\n}\n\n/**\n * Generate an EIP-7702 batch transaction.\n *\n * @param from - The sender address.\n * @param transactions - The transactions to batch.\n * @param options - Options bag.\n * @param options.atomic - Whether the batch should be atomic. Defaults to `true`.\n * When `true`, uses ERC-7579 ExecType `default` and all calls revert together.\n * When `false`, uses ERC-7579 ExecType `try` and individual calls can fail independently.\n * @returns The batch transaction.\n */\nexport function generateEIP7702BatchTransaction(\n from: Hex,\n transactions: BatchTransactionParams[],\n options?: { atomic?: boolean },\n): BatchTransactionParams {\n const atomic = options?.atomic ?? true;\n const erc7821Contract = Contract.getInterface(ABI_IERC7821);\n\n const calls = transactions.map((transaction) => {\n const { data, to, value } = transaction;\n\n return [\n to ?? '0x0000000000000000000000000000000000000000',\n value ?? '0x0',\n data ?? '0x',\n ];\n });\n\n const execType = atomic ? ERC7579_EXEC_TYPE_DEFAULT : ERC7579_EXEC_TYPE_TRY;\n const mode = `0x${ERC7579_CALL_TYPE_BATCH}${execType}`.padEnd(66, '0');\n\n const callData = defaultAbiCoder.encode([CALLS_SIGNATURE], [calls]);\n\n const data = erc7821Contract.encodeFunctionData(BATCH_FUNCTION_NAME, [\n mode,\n callData,\n ]) as Hex;\n\n log('Transaction data', data);\n\n return {\n data,\n to: from,\n };\n}\n\n/**\n * Sign an authorization list.\n *\n * @param options - Options bag.\n * @param options.authorizationList - The authorization list to sign.\n * @param options.messenger - The controller messenger.\n * @param options.transactionMeta - The transaction metadata.\n * @returns The signed authorization list.\n */\nexport async function signAuthorizationList({\n authorizationList,\n messenger,\n transactionMeta,\n}: {\n authorizationList?: AuthorizationList;\n messenger: TransactionControllerMessenger;\n transactionMeta: TransactionMeta;\n}): Promise<Required<AuthorizationList | undefined>> {\n if (!authorizationList) {\n return undefined;\n }\n\n const signedAuthorizationList: Required<AuthorizationList> = [];\n let index = 0;\n\n for (const authorization of authorizationList) {\n const signedAuthorization = await signAuthorization(\n authorization,\n transactionMeta,\n messenger,\n index,\n );\n\n signedAuthorizationList.push(signedAuthorization);\n index += 1;\n }\n\n return signedAuthorizationList;\n}\n\n/**\n * Decode a 65-byte EIP-7702 authorization signature into RLP-canonical\n * `r`, `s`, and `yParity` (no leading zero nibbles, `0x0` for zero).\n *\n * @param signature - The 65-byte signature.\n * @returns The decoded authorization fields.\n */\nexport function decodeAuthorizationSignature(signature: Hex): {\n r: Hex;\n s: Hex;\n yParity: Hex;\n} {\n // eslint-disable-next-line id-length\n const r = toCanonicalHex(signature.slice(0, 66));\n // eslint-disable-next-line id-length\n const s = toCanonicalHex(signature.slice(66, 130));\n // eslint-disable-next-line id-length\n const v = parseInt(signature.slice(130, 132), 16);\n const yParity = toCanonicalHex(toHex(v - 27 === 0 ? 0 : 1));\n\n return { r, s, yParity };\n}\n\n/**\n * Strip leading zero nibbles from a hex string to produce its RLP-canonical\n * form. Accepts input with or without a `0x` prefix; always returns\n * `0x`-prefixed. An all-zero input is preserved as `0x0`.\n *\n * @param value - Hex string with or without a `0x` prefix.\n * @returns The canonical `0x`-prefixed hex string.\n */\nfunction toCanonicalHex(value: string): Hex {\n const raw = value.startsWith('0x') ? value.slice(2) : value;\n const stripped = raw.replace(/^0+/u, '');\n return stripped.length === 0 ? '0x0' : `0x${stripped}`;\n}\n\n/**\n * Signs an authorization.\n *\n * @param authorization - The authorization to sign.\n * @param transactionMeta - The associated transaction metadata.\n * @param messenger - The messenger to use for signing.\n * @param index - The index of the authorization in the list.\n * @returns The signed authorization.\n */\nasync function signAuthorization(\n authorization: Authorization,\n transactionMeta: TransactionMeta,\n messenger: TransactionControllerMessenger,\n index: number,\n): Promise<Required<Authorization>> {\n // Retain pre-signed authorizations (e.g. Money Account upgrades signed by an\n // account other than `txParams.from`) instead of re-signing with `from`.\n if (isAuthorizationSigned(authorization)) {\n log('Retaining pre-signed authorization', authorization);\n return authorization;\n }\n\n const finalAuthorization = prepareAuthorization(\n authorization,\n transactionMeta,\n index,\n );\n\n const { txParams } = transactionMeta;\n const { from } = txParams;\n const { address, chainId, nonce } = finalAuthorization;\n const chainIdDecimal = parseInt(chainId, 16);\n const nonceDecimal = parseInt(nonce, 16);\n\n const signature = await messenger.call(\n 'KeyringController:signEip7702Authorization',\n {\n chainId: chainIdDecimal,\n contractAddress: address,\n from,\n nonce: nonceDecimal,\n },\n );\n\n const { r, s, yParity } = decodeAuthorizationSignature(signature as Hex);\n\n const result: Required<Authorization> = {\n address,\n chainId,\n nonce,\n r,\n s,\n yParity,\n };\n\n log('Signed authorization', result);\n\n return result;\n}\n\n/**\n * Whether an authorization already includes a complete EIP-7702 signature.\n *\n * @param authorization - Authorization to check.\n * @returns True when chainId, nonce, and signature components are all present.\n */\nexport function isAuthorizationSigned(\n authorization: Authorization,\n): authorization is Required<Authorization> {\n return Boolean(\n authorization.chainId &&\n authorization.nonce !== undefined &&\n authorization.r &&\n authorization.s &&\n authorization.yParity !== undefined,\n );\n}\n\n/**\n * Recover the authority (signer) of a fully signed EIP-7702 authorization.\n *\n * Per EIP-7702: `authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s)`.\n *\n * @param authorization - Fully signed authorization.\n * @returns The recovered authority address, or undefined if recovery fails.\n */\nexport function recoverAuthorizationAuthority(\n authorization: Required<Authorization>,\n): Hex | undefined {\n try {\n const chainIdBytes = bigIntToUnpaddedBytes(BigInt(authorization.chainId));\n const addressBytes = hexToBytes(authorization.address);\n const nonceBytes = bigIntToUnpaddedBytes(BigInt(authorization.nonce));\n const rlpEncoded = RLP.encode([chainIdBytes, addressBytes, nonceBytes]);\n const messageHash = keccak256(\n Uint8Array.from([EIP7702_AUTHORIZATION_MAGIC, ...rlpEncoded]),\n );\n const publicKey = ecrecover(\n messageHash,\n BigInt(authorization.yParity),\n bigIntToUnpaddedBytes(BigInt(authorization.r)),\n bigIntToUnpaddedBytes(BigInt(authorization.s)),\n );\n\n return bytesToHex(pubToAddress(publicKey));\n } catch (error) {\n log('Failed to recover authorization authority', { authorization, error });\n return undefined;\n }\n}\n\n/**\n * Resolve which account an authorization nonce belongs to for nonce tracking.\n *\n * Unsigned authorizations are signed by the outer transaction sender (`from`).\n * Signed authorizations recover their authority independently per EIP-7702.\n *\n * @param authorization - Authorization entry.\n * @param transactionFrom - Outer transaction sender.\n * @returns Authority address, or undefined when a signed auth cannot be recovered.\n */\nexport function getAuthorizationAuthority(\n authorization: Authorization,\n transactionFrom: string,\n): Hex | undefined {\n if (!isAuthorizationSigned(authorization)) {\n return transactionFrom as Hex;\n }\n\n return recoverAuthorizationAuthority(authorization);\n}\n\n/**\n * Prepares an authorization for signing by populating the chainId and nonce.\n *\n * @param authorization - The authorization to prepare.\n * @param transactionMeta - The associated transaction metadata.\n * @param index - The index of the authorization in the list.\n * @returns The prepared authorization.\n */\nfunction prepareAuthorization(\n authorization: Authorization,\n transactionMeta: TransactionMeta,\n index: number,\n): Authorization & { chainId: Hex; nonce: Hex } {\n const { chainId: existingChainId, nonce: existingNonce } = authorization;\n const { txParams, chainId: transactionChainId } = transactionMeta;\n const { nonce: transactionNonce } = txParams;\n\n const chainId = existingChainId ?? transactionChainId;\n let nonce = existingNonce;\n\n nonce ??= toHex(parseInt(transactionNonce as string, 16) + 1 + index);\n\n const result = {\n ...authorization,\n chainId,\n nonce,\n };\n\n log('Prepared authorization', result);\n\n return result;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"eip7702.js","sourceRoot":"","sources":["../../src/utils/eip7702.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC;AACtC,OAAO,EACL,qBAAqB,EACrB,UAAU,EACV,SAAS,EACT,UAAU,EACV,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,MAAM,4BAA4B,CAAC;AAEnD,OAAO,EAAE,kBAAkB,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAE5D,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAS7C,OAAO,EACL,2BAA2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AC;IAED,OAAO,6BAA6B,CAAC,aAAa,CAAC,CAAC;AACtD,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,oBAAoB,CAC3B,aAA4B,EAC5B,eAAgC,EAChC,KAAa;IAEb,MAAM,EAAE,OAAO,EAAE,eAAe,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,aAAa,CAAC;IACzE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,kBAAkB,EAAE,GAAG,eAAe,CAAC;IAClE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,GAAG,QAAQ,CAAC;IAE7C,MAAM,OAAO,GAAG,eAAe,IAAI,kBAAkB,CAAC;IACtD,IAAI,KAAK,GAAG,aAAa,CAAC;IAE1B,KAAK,KAAK,KAAK,CAAC,QAAQ,CAAC,gBAA0B,EAAE,EAAE,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IAEtE,MAAM,MAAM,GAAG;QACb,GAAG,aAAa;QAChB,OAAO;QACP,KAAK;KACN,CAAC;IAEF,GAAG,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;IAEtC,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { RLP } from '@ethereumjs/rlp';\nimport {\n bigIntToUnpaddedBytes,\n bytesToHex,\n ecrecover,\n hexToBytes,\n pubToAddress,\n} from '@ethereumjs/util';\nimport { defaultAbiCoder } from '@ethersproject/abi';\nimport { Contract } from '@ethersproject/contracts';\nimport { toHex } from '@metamask/controller-utils';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport { createModuleLogger, add0x } from '@metamask/utils';\nimport type { Hex } from '@metamask/utils';\nimport { keccak256 } from 'ethereum-cryptography/keccak';\n\nimport { ABI_IERC7821 } from '../constants.js';\nimport { projectLogger } from '../logger.js';\nimport type { TransactionControllerMessenger } from '../TransactionController.js';\nimport type {\n BatchTransactionParams,\n NestedTransactionUpdate,\n Authorization,\n AuthorizationList,\n TransactionMeta,\n} from '../types.js';\nimport {\n getEIP7702ContractAddresses,\n getEIP7702SupportedChains,\n} from './feature-flags.js';\nimport { rpcRequest } from './provider.js';\n\nexport const DELEGATION_PREFIX = '0xef0100';\nexport const BATCH_FUNCTION_NAME = 'execute';\nexport const CALLS_SIGNATURE = '(address,uint256,bytes)[]';\nexport const ERROR_MESSGE_PUBLIC_KEY = 'EIP-7702 public key not specified';\n\n/** EIP-7702 authorization signature magic prefix. */\nconst EIP7702_AUTHORIZATION_MAGIC = 0x05;\n\n/**\n * ERC-7579 ModeCode encoding for the ERC-7821 `execute` function.\n *\n * Layout: | CallType (1 byte) | ExecType (1 byte) | Unused (4 bytes) | ModeSelector (4 bytes) | ModePayload (22 bytes) |\n *\n * - CallType 0x01 = batch\n * - ExecType 0x00 = default (revert on failure)\n * - ExecType 0x01 = try (skip on failure)\n */\nconst ERC7579_CALL_TYPE_BATCH = '01';\nconst ERC7579_EXEC_TYPE_DEFAULT = '00';\nconst ERC7579_EXEC_TYPE_TRY = '01';\n\nconst log = createModuleLogger(projectLogger, 'eip-7702');\n\nconst KEYRING_TYPES_SUPPORTING_7702 = [\n 'HD Key Tree',\n 'Simple Key Pair',\n 'Money Keyring',\n 'MPC Money Keyring',\n];\n\n/**\n * Check whether a given account's keyring supports EIP-7702 authorization\n * signing.\n *\n * Looks up the account's keyring via `KeyringController:getState` and returns\n * `true` only when the keyring type is in the supported list.\n * Returns `false` when the keyring cannot be resolved.\n *\n * @param messenger - Controller messenger.\n * @param account - The account address to check.\n * @returns Whether the account supports EIP-7702.\n */\nexport function doesAccountSupportEIP7702(\n messenger: TransactionControllerMessenger,\n account: string,\n): boolean {\n const { keyrings } = messenger.call('KeyringController:getState');\n\n return keyrings.some(\n (k: { type: string; accounts: string[] }) =>\n KEYRING_TYPES_SUPPORTING_7702.includes(k.type) &&\n k.accounts.some((a: string) => a.toLowerCase() === account.toLowerCase()),\n );\n}\n\n/**\n * Determine if a chain supports EIP-7702 using LaunchDarkly feature flag.\n *\n * @param chainId - Hexadecimal ID of the chain.\n * @param messenger - Messenger instance.\n * @returns True if the chain supports EIP-7702.\n */\nexport function doesChainSupportEIP7702(\n chainId: Hex,\n messenger: TransactionControllerMessenger,\n): boolean {\n const supportedChains = getEIP7702SupportedChains(messenger);\n\n return supportedChains.some(\n (supportedChainId) =>\n supportedChainId.toLowerCase() === chainId.toLowerCase(),\n );\n}\n\n/**\n * Retrieve the delegation address for an account.\n *\n * @param address - The address to check.\n * @param messenger - The TransactionController messenger.\n * @param networkClientId - The network client ID to use.\n * @returns The delegation address if it exists.\n */\nexport async function getDelegationAddress(\n address: Hex,\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n): Promise<Hex | undefined> {\n const code = (await rpcRequest({\n messenger,\n networkClientId,\n method: 'eth_getCode',\n params: [address, 'latest'],\n })) as string;\n const normalizedCode = add0x(code?.toLowerCase?.() ?? '');\n\n const hasDelegation =\n code?.length === 48 && normalizedCode.startsWith(DELEGATION_PREFIX);\n\n return hasDelegation\n ? add0x(normalizedCode.slice(DELEGATION_PREFIX.length))\n : undefined;\n}\n\n/**\n * Determine if an account has been upgraded to a supported EIP-7702 contract.\n *\n * @param address - The EOA address to check.\n * @param chainId - The chain ID.\n * @param publicKey - Public key used to validate EIP-7702 contract signatures in feature flags.\n * @param messenger - The messenger instance.\n * @param networkClientId - The network client ID to use.\n * @returns An object with the results of the check.\n */\nexport async function isAccountUpgradedToEIP7702(\n address: Hex,\n chainId: Hex,\n publicKey: Hex,\n messenger: TransactionControllerMessenger,\n networkClientId: NetworkClientId,\n): Promise<{\n delegationAddress: Hex | undefined;\n isSupported: boolean;\n}> {\n const contractAddresses = getEIP7702ContractAddresses(\n chainId,\n messenger,\n publicKey,\n );\n\n const delegationAddress = await getDelegationAddress(\n address,\n messenger,\n networkClientId,\n );\n\n const isSupported = Boolean(\n delegationAddress &&\n contractAddresses.some(\n (contract) => contract.toLowerCase() === delegationAddress.toLowerCase(),\n ),\n );\n\n return {\n delegationAddress,\n isSupported,\n };\n}\n\n/**\n * Update indexed transactions in an EIP-7702 batch and regenerate its calldata.\n *\n * @param options - Update options.\n * @param options.from - The sender address.\n * @param options.transactions - The existing nested transactions.\n * @param options.updates - Indexed calldata updates.\n * @returns Updated nested transactions and regenerated batch calldata.\n */\nexport function updateEIP7702BatchData({\n from,\n transactions,\n updates,\n}: {\n from: Hex;\n transactions: BatchTransactionParams[];\n updates: NestedTransactionUpdate[];\n}): {\n nestedTransactions: BatchTransactionParams[];\n transactionData: Hex;\n} {\n const updatesByIndex = new Map<number, Hex>();\n\n for (const { transactionIndex, transactionData } of updates) {\n if (updatesByIndex.has(transactionIndex)) {\n throw new Error(\n `Duplicate nested transaction index - ${transactionIndex}`,\n );\n }\n\n if (!transactions[transactionIndex]) {\n throw new Error(\n `Nested transaction not found with index - ${transactionIndex}`,\n );\n }\n\n updatesByIndex.set(transactionIndex, transactionData);\n }\n\n const nestedTransactions = transactions.map((transaction, index) => {\n const transactionData = updatesByIndex.get(index);\n\n return {\n ...transaction,\n ...(transactionData === undefined ? {} : { data: transactionData }),\n };\n });\n const batchTransaction = generateEIP7702BatchTransaction(\n from,\n nestedTransactions,\n );\n\n return {\n nestedTransactions,\n transactionData: batchTransaction.data as Hex,\n };\n}\n\n/**\n * Generate an EIP-7702 batch transaction.\n *\n * @param from - The sender address.\n * @param transactions - The transactions to batch.\n * @param options - Options bag.\n * @param options.atomic - Whether the batch should be atomic. Defaults to `true`.\n * When `true`, uses ERC-7579 ExecType `default` and all calls revert together.\n * When `false`, uses ERC-7579 ExecType `try` and individual calls can fail independently.\n * @returns The batch transaction.\n */\nexport function generateEIP7702BatchTransaction(\n from: Hex,\n transactions: BatchTransactionParams[],\n options?: { atomic?: boolean },\n): BatchTransactionParams {\n const atomic = options?.atomic ?? true;\n const erc7821Contract = Contract.getInterface(ABI_IERC7821);\n\n const calls = transactions.map((transaction) => {\n const { data, to, value } = transaction;\n\n return [\n to ?? '0x0000000000000000000000000000000000000000',\n value ?? '0x0',\n data ?? '0x',\n ];\n });\n\n const execType = atomic ? ERC7579_EXEC_TYPE_DEFAULT : ERC7579_EXEC_TYPE_TRY;\n const mode = `0x${ERC7579_CALL_TYPE_BATCH}${execType}`.padEnd(66, '0');\n\n const callData = defaultAbiCoder.encode([CALLS_SIGNATURE], [calls]);\n\n const data = erc7821Contract.encodeFunctionData(BATCH_FUNCTION_NAME, [\n mode,\n callData,\n ]) as Hex;\n\n log('Transaction data', data);\n\n return {\n data,\n to: from,\n };\n}\n\n/**\n * Sign an authorization list.\n *\n * @param options - Options bag.\n * @param options.authorizationList - The authorization list to sign.\n * @param options.messenger - The controller messenger.\n * @param options.transactionMeta - The transaction metadata.\n * @returns The signed authorization list.\n */\nexport async function signAuthorizationList({\n authorizationList,\n messenger,\n transactionMeta,\n}: {\n authorizationList?: AuthorizationList;\n messenger: TransactionControllerMessenger;\n transactionMeta: TransactionMeta;\n}): Promise<Required<AuthorizationList | undefined>> {\n if (!authorizationList) {\n return undefined;\n }\n\n const signedAuthorizationList: Required<AuthorizationList> = [];\n let index = 0;\n\n for (const authorization of authorizationList) {\n const signedAuthorization = await signAuthorization(\n authorization,\n transactionMeta,\n messenger,\n index,\n );\n\n signedAuthorizationList.push(signedAuthorization);\n index += 1;\n }\n\n return signedAuthorizationList;\n}\n\n/**\n * Decode a 65-byte EIP-7702 authorization signature into RLP-canonical\n * `r`, `s`, and `yParity` (no leading zero nibbles, `0x0` for zero).\n *\n * @param signature - The 65-byte signature.\n * @returns The decoded authorization fields.\n */\nexport function decodeAuthorizationSignature(signature: Hex): {\n r: Hex;\n s: Hex;\n yParity: Hex;\n} {\n // eslint-disable-next-line id-length\n const r = toCanonicalHex(signature.slice(0, 66));\n // eslint-disable-next-line id-length\n const s = toCanonicalHex(signature.slice(66, 130));\n // eslint-disable-next-line id-length\n const v = parseInt(signature.slice(130, 132), 16);\n const yParity = toCanonicalHex(toHex(v - 27 === 0 ? 0 : 1));\n\n return { r, s, yParity };\n}\n\n/**\n * Strip leading zero nibbles from a hex string to produce its RLP-canonical\n * form. Accepts input with or without a `0x` prefix; always returns\n * `0x`-prefixed. An all-zero input is preserved as `0x0`.\n *\n * @param value - Hex string with or without a `0x` prefix.\n * @returns The canonical `0x`-prefixed hex string.\n */\nfunction toCanonicalHex(value: string): Hex {\n const raw = value.startsWith('0x') ? value.slice(2) : value;\n const stripped = raw.replace(/^0+/u, '');\n return stripped.length === 0 ? '0x0' : `0x${stripped}`;\n}\n\n/**\n * Signs an authorization.\n *\n * @param authorization - The authorization to sign.\n * @param transactionMeta - The associated transaction metadata.\n * @param messenger - The messenger to use for signing.\n * @param index - The index of the authorization in the list.\n * @returns The signed authorization.\n */\nasync function signAuthorization(\n authorization: Authorization,\n transactionMeta: TransactionMeta,\n messenger: TransactionControllerMessenger,\n index: number,\n): Promise<Required<Authorization>> {\n // Retain pre-signed authorizations (e.g. Money Account upgrades signed by an\n // account other than `txParams.from`) instead of re-signing with `from`.\n if (isAuthorizationSigned(authorization)) {\n log('Retaining pre-signed authorization', authorization);\n return authorization;\n }\n\n const finalAuthorization = prepareAuthorization(\n authorization,\n transactionMeta,\n index,\n );\n\n const { txParams } = transactionMeta;\n const { from } = txParams;\n const { address, chainId, nonce } = finalAuthorization;\n const chainIdDecimal = parseInt(chainId, 16);\n const nonceDecimal = parseInt(nonce, 16);\n\n const signature = await messenger.call(\n 'KeyringController:signEip7702Authorization',\n {\n chainId: chainIdDecimal,\n contractAddress: address,\n from,\n nonce: nonceDecimal,\n },\n );\n\n const { r, s, yParity } = decodeAuthorizationSignature(signature as Hex);\n\n const result: Required<Authorization> = {\n address,\n chainId,\n nonce,\n r,\n s,\n yParity,\n };\n\n log('Signed authorization', result);\n\n return result;\n}\n\n/**\n * Whether an authorization already includes a complete EIP-7702 signature.\n *\n * @param authorization - Authorization to check.\n * @returns True when chainId, nonce, and signature components are all present.\n */\nexport function isAuthorizationSigned(\n authorization: Authorization,\n): authorization is Required<Authorization> {\n return Boolean(\n authorization.chainId &&\n authorization.nonce !== undefined &&\n authorization.r &&\n authorization.s &&\n authorization.yParity !== undefined,\n );\n}\n\n/**\n * Recover the authority (signer) of a fully signed EIP-7702 authorization.\n *\n * Per EIP-7702: `authority = ecrecover(keccak(MAGIC || rlp([chain_id, address, nonce])), y_parity, r, s)`.\n *\n * @param authorization - Fully signed authorization.\n * @returns The recovered authority address, or undefined if recovery fails.\n */\nexport function recoverAuthorizationAuthority(\n authorization: Required<Authorization>,\n): Hex | undefined {\n try {\n const chainIdBytes = bigIntToUnpaddedBytes(BigInt(authorization.chainId));\n const addressBytes = hexToBytes(authorization.address);\n const nonceBytes = bigIntToUnpaddedBytes(BigInt(authorization.nonce));\n const rlpEncoded = RLP.encode([chainIdBytes, addressBytes, nonceBytes]);\n const messageHash = keccak256(\n Uint8Array.from([EIP7702_AUTHORIZATION_MAGIC, ...rlpEncoded]),\n );\n const publicKey = ecrecover(\n messageHash,\n BigInt(authorization.yParity),\n bigIntToUnpaddedBytes(BigInt(authorization.r)),\n bigIntToUnpaddedBytes(BigInt(authorization.s)),\n );\n\n return bytesToHex(pubToAddress(publicKey));\n } catch (error) {\n log('Failed to recover authorization authority', { authorization, error });\n return undefined;\n }\n}\n\n/**\n * Resolve which account an authorization nonce belongs to for nonce tracking.\n *\n * Unsigned authorizations are signed by the outer transaction sender (`from`).\n * Signed authorizations recover their authority independently per EIP-7702.\n *\n * @param authorization - Authorization entry.\n * @param transactionFrom - Outer transaction sender.\n * @returns Authority address, or undefined when a signed auth cannot be recovered.\n */\nexport function getAuthorizationAuthority(\n authorization: Authorization,\n transactionFrom: string,\n): Hex | undefined {\n if (!isAuthorizationSigned(authorization)) {\n return transactionFrom as Hex;\n }\n\n return recoverAuthorizationAuthority(authorization);\n}\n\n/**\n * Prepares an authorization for signing by populating the chainId and nonce.\n *\n * @param authorization - The authorization to prepare.\n * @param transactionMeta - The associated transaction metadata.\n * @param index - The index of the authorization in the list.\n * @returns The prepared authorization.\n */\nfunction prepareAuthorization(\n authorization: Authorization,\n transactionMeta: TransactionMeta,\n index: number,\n): Authorization & { chainId: Hex; nonce: Hex } {\n const { chainId: existingChainId, nonce: existingNonce } = authorization;\n const { txParams, chainId: transactionChainId } = transactionMeta;\n const { nonce: transactionNonce } = txParams;\n\n const chainId = existingChainId ?? transactionChainId;\n let nonce = existingNonce;\n\n nonce ??= toHex(parseInt(transactionNonce as string, 16) + 1 + index);\n\n const result = {\n ...authorization,\n chainId,\n nonce,\n };\n\n log('Prepared authorization', result);\n\n return result;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/transaction-controller",
|
|
3
|
-
"version": "72.
|
|
3
|
+
"version": "72.3.0-preview-bbbbbb9f2",
|
|
4
4
|
"description": "Stores transactions alongside their periodically updated statuses and manages interactions such as approval and cancellation",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Ethereum",
|