@toruslabs/ethereum-controllers 8.15.0 → 8.17.0

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.
Files changed (56) hide show
  1. package/dist/ethereumControllers.umd.min.js +1 -1
  2. package/dist/lib.cjs/Eip5792/walletGetCallsStatus.js +75 -0
  3. package/dist/lib.cjs/Eip5792/walletGetCapabilities.js +64 -0
  4. package/dist/lib.cjs/Eip5792/walletSendCalls.js +163 -0
  5. package/dist/lib.cjs/Eip7702/eip7702Utils.js +82 -0
  6. package/dist/lib.cjs/Eip7702/walletGetUpgradeStatus.js +35 -0
  7. package/dist/lib.cjs/Eip7702/walletUpgradeAccount.js +58 -0
  8. package/dist/lib.cjs/Keyring/KeyringController.js +50 -14
  9. package/dist/lib.cjs/Network/createEthereumMiddleware.js +114 -1
  10. package/dist/lib.cjs/Transaction/TransactionController.js +117 -6
  11. package/dist/lib.cjs/Transaction/TransactionGasUtil.js +13 -0
  12. package/dist/lib.cjs/Transaction/TransactionStateManager.js +9 -0
  13. package/dist/lib.cjs/Transaction/TransactionUtils.js +103 -10
  14. package/dist/lib.cjs/index.js +36 -0
  15. package/dist/lib.cjs/types/Eip5792/index.d.ts +3 -0
  16. package/dist/lib.cjs/types/Eip5792/walletGetCallsStatus.d.ts +19 -0
  17. package/dist/lib.cjs/types/Eip5792/walletGetCapabilities.d.ts +17 -0
  18. package/dist/lib.cjs/types/Eip5792/walletSendCalls.d.ts +45 -0
  19. package/dist/lib.cjs/types/Eip7702/eip7702Utils.d.ts +27 -0
  20. package/dist/lib.cjs/types/Eip7702/walletGetUpgradeStatus.d.ts +11 -0
  21. package/dist/lib.cjs/types/Eip7702/walletUpgradeAccount.d.ts +13 -0
  22. package/dist/lib.cjs/types/Keyring/KeyringController.d.ts +2 -0
  23. package/dist/lib.cjs/types/Network/createEthereumMiddleware.d.ts +53 -1
  24. package/dist/lib.cjs/types/Transaction/TransactionController.d.ts +9 -1
  25. package/dist/lib.cjs/types/Transaction/TransactionStateManager.d.ts +1 -0
  26. package/dist/lib.cjs/types/Transaction/TransactionUtils.d.ts +38 -1
  27. package/dist/lib.cjs/types/index.d.ts +4 -0
  28. package/dist/lib.cjs/types/utils/abis.d.ts +15 -0
  29. package/dist/lib.cjs/types/utils/constants.d.ts +2 -0
  30. package/dist/lib.cjs/types/utils/eip5792Types.d.ts +155 -0
  31. package/dist/lib.cjs/types/utils/eip7702Types.d.ts +60 -0
  32. package/dist/lib.cjs/types/utils/interfaces.d.ts +22 -2
  33. package/dist/lib.cjs/utils/abis.js +30 -0
  34. package/dist/lib.cjs/utils/constants.js +4 -1
  35. package/dist/lib.cjs/utils/eip5792Types.js +41 -0
  36. package/dist/lib.cjs/utils/eip7702Types.js +14 -0
  37. package/dist/lib.cjs/utils/interfaces.js +8 -0
  38. package/dist/lib.esm/Eip5792/walletGetCallsStatus.js +76 -0
  39. package/dist/lib.esm/Eip5792/walletGetCapabilities.js +63 -0
  40. package/dist/lib.esm/Eip5792/walletSendCalls.js +168 -0
  41. package/dist/lib.esm/Eip7702/eip7702Utils.js +81 -0
  42. package/dist/lib.esm/Eip7702/walletGetUpgradeStatus.js +33 -0
  43. package/dist/lib.esm/Eip7702/walletUpgradeAccount.js +56 -0
  44. package/dist/lib.esm/Keyring/KeyringController.js +53 -15
  45. package/dist/lib.esm/Network/createEthereumMiddleware.js +117 -2
  46. package/dist/lib.esm/Transaction/TransactionController.js +124 -10
  47. package/dist/lib.esm/Transaction/TransactionGasUtil.js +13 -0
  48. package/dist/lib.esm/Transaction/TransactionStateManager.js +9 -0
  49. package/dist/lib.esm/Transaction/TransactionUtils.js +103 -11
  50. package/dist/lib.esm/index.js +11 -4
  51. package/dist/lib.esm/utils/abis.js +30 -1
  52. package/dist/lib.esm/utils/constants.js +4 -2
  53. package/dist/lib.esm/utils/eip5792Types.js +105 -0
  54. package/dist/lib.esm/utils/eip7702Types.js +15 -0
  55. package/dist/lib.esm/utils/interfaces.js +28 -0
  56. package/package.json +8 -5
@@ -10,6 +10,10 @@ var SafeSmartAccount = require('./AccountAbstraction/smartAccounts/SafeSmartAcco
10
10
  var TrustSmartAccount = require('./AccountAbstraction/smartAccounts/TrustSmartAccount.js');
11
11
  var PollingBlockTracker = require('./Block/PollingBlockTracker.js');
12
12
  var CurrencyController = require('./Currency/CurrencyController.js');
13
+ var walletGetCallsStatus = require('./Eip5792/walletGetCallsStatus.js');
14
+ var walletGetCapabilities = require('./Eip5792/walletGetCapabilities.js');
15
+ var walletSendCalls = require('./Eip5792/walletSendCalls.js');
16
+ var eip7702Utils = require('./Eip7702/eip7702Utils.js');
13
17
  var GasFeeController = require('./Gas/GasFeeController.js');
14
18
  var KeyringController = require('./Keyring/KeyringController.js');
15
19
  var AddChainController = require('./Message/AddChainController.js');
@@ -37,7 +41,10 @@ var TransactionUtils = require('./Transaction/TransactionUtils.js');
37
41
  var abis = require('./utils/abis.js');
38
42
  var constants = require('./utils/constants.js');
39
43
  var conversionUtils = require('./utils/conversionUtils.js');
44
+ var eip5792Types = require('./utils/eip5792Types.js');
45
+ var eip7702Types = require('./utils/eip7702Types.js');
40
46
  var helpers = require('./utils/helpers.js');
47
+ var interfaces = require('./utils/interfaces.js');
41
48
 
42
49
 
43
50
 
@@ -53,6 +60,18 @@ exports.SafeSmartAccount = SafeSmartAccount.SafeSmartAccount;
53
60
  exports.TrustSmartAccount = TrustSmartAccount.TrustSmartAccount;
54
61
  exports.PollingBlockTracker = PollingBlockTracker.PollingBlockTracker;
55
62
  exports.CurrencyController = CurrencyController.CurrencyController;
63
+ exports.mapTransactionStatusToEip5792Status = walletGetCallsStatus.mapTransactionStatusToEip5792Status;
64
+ exports.walletGetCallsStatus = walletGetCallsStatus.walletGetCallsStatus;
65
+ exports.walletGetCapabilities = walletGetCapabilities.walletGetCapabilities;
66
+ exports.generateBatchId = walletSendCalls.generateBatchId;
67
+ exports.processMultipleTransactions = walletSendCalls.processMultipleTransactions;
68
+ exports.processSingleTransaction = walletSendCalls.processSingleTransaction;
69
+ exports.validateSendCallsParams = walletSendCalls.validateSendCallsParams;
70
+ exports.walletSendCalls = walletSendCalls.walletSendCalls;
71
+ exports.MetaMask_EIP7702_Stateless_Delegator = eip7702Utils.MetaMask_EIP7702_Stateless_Delegator;
72
+ exports.generateEIP7702BatchTransaction = eip7702Utils.generateEIP7702BatchTransaction;
73
+ exports.getDelegationAddress = eip7702Utils.getDelegationAddress;
74
+ exports.getIsEip7702UpgradeSupported = eip7702Utils.getIsEip7702UpgradeSupported;
56
75
  exports.GasFeeController = GasFeeController.GasFeeController;
57
76
  exports.KeyringController = KeyringController.KeyringController;
58
77
  exports.AddChainController = AddChainController.AddChainController;
@@ -67,6 +86,8 @@ exports.validateSignMessageData = utils.validateSignMessageData;
67
86
  exports.validateSwitchChainData = utils.validateSwitchChainData;
68
87
  exports.validateTypedSignMessageDataV4 = utils.validateTypedSignMessageDataV4;
69
88
  exports.createAAMiddleware = createEthereumMiddleware.createAAMiddleware;
89
+ exports.createEip5792Middleware = createEthereumMiddleware.createEip5792Middleware;
90
+ exports.createEip7702Middleware = createEthereumMiddleware.createEip7702Middleware;
70
91
  exports.createEthereumMiddleware = createEthereumMiddleware.createEthereumMiddleware;
71
92
  exports.createGetAccountsMiddleware = createEthereumMiddleware.createGetAccountsMiddleware;
72
93
  exports.createPendingNonceMiddleware = createEthereumMiddleware.createPendingNonceMiddleware;
@@ -101,11 +122,14 @@ exports.generateHistoryEntry = TransactionStateHistoryHelper.generateHistoryEntr
101
122
  exports.replayHistory = TransactionStateHistoryHelper.replayHistory;
102
123
  exports.snapshotFromTxMeta = TransactionStateHistoryHelper.snapshotFromTxMeta;
103
124
  exports.TransactionStateManager = TransactionStateManager.TransactionStateManager;
125
+ exports.createNestedTransactionMeta = TransactionUtils.createNestedTransactionMeta;
104
126
  exports.determineTransactionType = TransactionUtils.determineTransactionType;
105
127
  exports.ensureFieldIsString = TransactionUtils.ensureFieldIsString;
106
128
  exports.ensureMutuallyExclusiveFieldsNotProvided = TransactionUtils.ensureMutuallyExclusiveFieldsNotProvided;
107
129
  exports.getFinalStates = TransactionUtils.getFinalStates;
108
130
  exports.isEIP1559Transaction = TransactionUtils.isEIP1559Transaction;
131
+ exports.isEip7702SetCodeTx = TransactionUtils.isEip7702SetCodeTx;
132
+ exports.isEip7702UpgradeWithDataToSelfTransaction = TransactionUtils.isEip7702UpgradeWithDataToSelfTransaction;
109
133
  exports.isLegacyTransaction = TransactionUtils.isLegacyTransaction;
110
134
  exports.normalizeAndValidateTxParams = TransactionUtils.normalizeAndValidateTxParams;
111
135
  exports.normalizeTxParameters = TransactionUtils.normalizeTxParameters;
@@ -118,6 +142,7 @@ exports.validateTxParameters = TransactionUtils.validateTxParameters;
118
142
  exports.erc1155Abi = abis.erc1155Abi;
119
143
  exports.erc20Abi = abis.erc20Abi;
120
144
  exports.erc721Abi = abis.erc721Abi;
145
+ exports.erc7821Abi = abis.erc7821Abi;
121
146
  exports.singleBalanceCheckerAbi = abis.singleBalanceCheckerAbi;
122
147
  exports.ARBITRUM_MAINNET_CHAIN_ID = constants.ARBITRUM_MAINNET_CHAIN_ID;
123
148
  exports.ARBITRUM_TESTNET_CHAIN_ID = constants.ARBITRUM_TESTNET_CHAIN_ID;
@@ -135,6 +160,7 @@ exports.COINGECKO_SUPPORTED_CURRENCIES = constants.COINGECKO_SUPPORTED_CURRENCIE
135
160
  exports.CONTRACT_TYPE_ERC1155 = constants.CONTRACT_TYPE_ERC1155;
136
161
  exports.CONTRACT_TYPE_ERC20 = constants.CONTRACT_TYPE_ERC20;
137
162
  exports.CONTRACT_TYPE_ERC721 = constants.CONTRACT_TYPE_ERC721;
163
+ exports.CONTRACT_TYPE_ERC7821 = constants.CONTRACT_TYPE_ERC7821;
138
164
  exports.CONTRACT_TYPE_ETH = constants.CONTRACT_TYPE_ETH;
139
165
  exports.ERC1155_INTERFACE_ID = constants.ERC1155_INTERFACE_ID;
140
166
  exports.ERC721_ENUMERABLE_INTERFACE_ID = constants.ERC721_ENUMERABLE_INTERFACE_ID;
@@ -173,6 +199,15 @@ exports.hexWEIToDecGWEI = conversionUtils.hexWEIToDecGWEI;
173
199
  exports.multiplyCurrencies = conversionUtils.multiplyCurrencies;
174
200
  exports.subtractCurrencies = conversionUtils.subtractCurrencies;
175
201
  exports.toNegative = conversionUtils.toNegative;
202
+ exports.EIP5792ErrorCode = eip5792Types.EIP5792ErrorCode;
203
+ exports.EIP_5792_METHODS = eip5792Types.EIP_5792_METHODS;
204
+ exports.Eip5792AtomicStatus = eip5792Types.Eip5792AtomicStatus;
205
+ exports.GetCallsStatusCode = eip5792Types.GetCallsStatusCode;
206
+ exports.SUPPORTED_EIP_5792_VERSIONS = eip5792Types.SUPPORTED_EIP_5792_VERSIONS;
207
+ exports.DUMMY_AUTHORIZATION_SIGNATURE = eip7702Types.DUMMY_AUTHORIZATION_SIGNATURE;
208
+ exports.EIP_7702_METHODS = eip7702Types.EIP_7702_METHODS;
209
+ exports.EIP_7702_PREFIX = eip7702Types.EIP_7702_PREFIX;
210
+ exports.EIP_7702_REVOKE_ADDRESS = eip7702Types.EIP_7702_REVOKE_ADDRESS;
176
211
  exports.BNToHex = helpers.BNToHex;
177
212
  exports.GAS_LIMITS = helpers.GAS_LIMITS;
178
213
  exports.addEtherscanTransactions = helpers.addEtherscanTransactions;
@@ -188,3 +223,4 @@ exports.hexToBn = helpers.hexToBn;
188
223
  exports.isAddressByChainId = helpers.isAddressByChainId;
189
224
  exports.sanitizeNftMetdataUrl = helpers.sanitizeNftMetdataUrl;
190
225
  exports.toChecksumAddressByChainId = helpers.toChecksumAddressByChainId;
226
+ exports.TRANSACTION_CATEGORY_EIP7702 = interfaces.TRANSACTION_CATEGORY_EIP7702;
@@ -0,0 +1,3 @@
1
+ export * from "./walletGetCallsStatus";
2
+ export * from "./walletGetCapabilities";
3
+ export * from "./walletSendCalls";
@@ -0,0 +1,19 @@
1
+ import { TransactionStatus } from "@toruslabs/base-controllers";
2
+ import { JRPCRequest } from "@web3auth/auth";
3
+ import { TransactionStateManager } from "../Transaction/TransactionStateManager";
4
+ import { Eip5792GetCallsStatusParams, Eip5792GetCallsStatusResponse, GetCallsStatusCode } from "../utils/eip5792Types";
5
+ /**
6
+ * Maps a TransactionStatus to an EIP-5792 GetCallsStatusCode.
7
+ * @param status - The transaction status.
8
+ * @returns The corresponding EIP-5792 status code.
9
+ */
10
+ export declare function mapTransactionStatusToEip5792Status(status: TransactionStatus): (typeof GetCallsStatusCode)[keyof typeof GetCallsStatusCode];
11
+ /**
12
+ * Handler for wallet_getCallsStatus (EIP-5792).
13
+ * Returns the status of a batch of calls.
14
+ *
15
+ * @param request - The JRPC request with batch ID parameter.
16
+ * @param context - Context containing required functions.
17
+ * @returns The batch status and receipts.
18
+ */
19
+ export declare function walletGetCallsStatus(request: JRPCRequest<[Eip5792GetCallsStatusParams]>, getTransactionByBatchId: TransactionStateManager["getTransactionByBatchId"]): Eip5792GetCallsStatusResponse;
@@ -0,0 +1,17 @@
1
+ import { JRPCRequest } from "@web3auth/auth";
2
+ import { Eip5792GetCapabilitiesParams, Eip5792GetCapabilitiesResponse, GetCachedDelegationsFn, GetSupportedChainsFn } from "../utils/eip5792Types";
3
+ import { GetEthCodeFn } from "../utils/interfaces";
4
+ export interface WalletGetCapabilitiesContext {
5
+ getSupportedChains: GetSupportedChainsFn;
6
+ getCachedDelegations?: GetCachedDelegationsFn;
7
+ updateDelegationCache?: (walletAddress: `0x${string}`, chainId: `0x${string}`, delegation: `0x${string}` | null) => void;
8
+ }
9
+ /**
10
+ * Handler for wallet_getCapabilities (EIP-5792).
11
+ * Returns capabilities per chain, indicating atomicBatch support for upgraded accounts.
12
+ *
13
+ * @param request - The JRPC request with wallet address parameter.
14
+ * @param context - Context containing required functions.
15
+ * @returns Capabilities per chain.
16
+ */
17
+ export declare function walletGetCapabilities(request: JRPCRequest<Eip5792GetCapabilitiesParams>, getEthCode: GetEthCodeFn, context: WalletGetCapabilitiesContext): Promise<Eip5792GetCapabilitiesResponse | undefined>;
@@ -0,0 +1,45 @@
1
+ import { JRPCRequest } from "@web3auth/auth";
2
+ import { IProviderHandlers } from "../Network/createEthereumMiddleware";
3
+ import { BatchTransactionParams, Eip5792SendCallsParams } from "../utils/eip5792Types";
4
+ import { GetEthCodeFn } from "../utils/interfaces";
5
+ export interface WalletSendCallsContext {
6
+ processTransaction: IProviderHandlers["processTransaction"];
7
+ processTransactionBatch: IProviderHandlers["processTransactionBatch"];
8
+ }
9
+ /**
10
+ * Generates a unique batch ID for EIP-5792 calls.
11
+ * @returns A unique hex string batch ID.
12
+ */
13
+ export declare function generateBatchId(): `0x${string}`;
14
+ /**
15
+ * Validates the parameters for wallet_sendCalls (EIP-5792).
16
+ * @param sendCallsParams - The parameters to validate.
17
+ */
18
+ export declare function validateSendCallsParams(sendCallsParams: Eip5792SendCallsParams): void;
19
+ export declare function processMultipleTransactions({ from, transactions, request, chainId, getEthCode, processTransactionBatch, }: {
20
+ from: `0x${string}`;
21
+ transactions: {
22
+ params: BatchTransactionParams;
23
+ }[];
24
+ request: JRPCRequest<Eip5792SendCallsParams>;
25
+ chainId: `0x${string}`;
26
+ getEthCode: GetEthCodeFn;
27
+ processTransactionBatch: IProviderHandlers["processTransactionBatch"];
28
+ }): Promise<string>;
29
+ export declare function processSingleTransaction({ transactions, request, processTransactionBatch, }: {
30
+ transactions: {
31
+ params: BatchTransactionParams;
32
+ }[];
33
+ request: JRPCRequest<Eip5792SendCallsParams>;
34
+ processTransactionBatch: IProviderHandlers["processTransactionBatch"];
35
+ }): Promise<string>;
36
+ /**
37
+ * Handler for wallet_sendCalls (EIP-5792).
38
+ * Sends a batch of calls for an EIP-7702 upgraded account.
39
+ *
40
+ * @param request - The JRPC request with send calls parameters.
41
+ * @param getEthCode - Function to get the code at an address.
42
+ * @param context - Context containing required functions.
43
+ * @returns The batch ID.
44
+ */
45
+ export declare function walletSendCalls(request: JRPCRequest<Eip5792SendCallsParams>, getEthCode: GetEthCodeFn, context: WalletSendCallsContext): Promise<string | undefined>;
@@ -0,0 +1,27 @@
1
+ import { Hex } from "viem";
2
+ import { BatchTransactionParams } from "../utils/eip5792Types";
3
+ import { GetEthCodeFn } from "../utils/interfaces";
4
+ /**
5
+ * The MetaMask EIP-7702 Stateless Delegator contract address.
6
+ * Used as the delegation target for all supported networks.
7
+ */
8
+ export declare const MetaMask_EIP7702_Stateless_Delegator: Hex;
9
+ export declare function getDelegationAddress(walletAddress: `0x${string}`, chainId: `0x${string}`, getEthCode: GetEthCodeFn): Promise<`0x${string}` | null>;
10
+ /**
11
+ * Check if the wallet is supported for EIP-7702 on provided chain.
12
+ */
13
+ export declare function getIsEip7702UpgradeSupported(address: `0x${string}`, chainId: `0x${string}`, getEthCode: GetEthCodeFn): Promise<{
14
+ isSupported: boolean;
15
+ upgradeContractAddress?: `0x${string}`;
16
+ delegationAddress: `0x${string}` | null;
17
+ }>;
18
+ /**
19
+ * Generate an EIP-7702 batch transaction.
20
+ *
21
+ * Reference: {@link https://github.com/MetaMask/core/blob/main/packages/transaction-controller/src/utils/eip7702.ts#L119}
22
+ *
23
+ * @param from - The sender address.
24
+ * @param transactions - The transactions to batch.
25
+ * @returns The batch transaction.
26
+ */
27
+ export declare function generateEIP7702BatchTransaction(from: `0x${string}`, transactions: BatchTransactionParams[]): BatchTransactionParams;
@@ -0,0 +1,11 @@
1
+ import { JRPCRequest } from "@web3auth/auth";
2
+ import { Eip7702Params, Eip7702WalletGetUpgradeStatusResponse } from "../utils/eip7702Types";
3
+ import { GetEthCodeFn } from "../utils/interfaces";
4
+ /**
5
+ * Get the EIP7702 upgrade status of an EOA.
6
+ *
7
+ * @param request - The request object.
8
+ * @param getEthCode - The function to get the code of an account.
9
+ * @returns The upgrade status.
10
+ */
11
+ export declare function walletGetUpgradeStatus(request: JRPCRequest<Eip7702Params>, getEthCode: GetEthCodeFn): Promise<Eip7702WalletGetUpgradeStatusResponse>;
@@ -0,0 +1,13 @@
1
+ import { JRPCRequest } from "@web3auth/auth";
2
+ import { IProviderHandlers } from "../Network/createEthereumMiddleware";
3
+ import { Eip7702Params } from "../utils/eip7702Types";
4
+ import { GetEthCodeFn } from "../utils/interfaces";
5
+ /**
6
+ * Handle and prepare the transaction to upgrade an EOA to the EIP-7702 smart account.
7
+ *
8
+ * @param req - The request object.
9
+ * @param getEthCode - The function to get the code of an account.
10
+ * @param processTransaction - The function to process a transaction.
11
+ * @returns The transaction hash.
12
+ */
13
+ export declare function walletUpgradeAccount(req: JRPCRequest<Eip7702Params>, getEthCode: GetEthCodeFn, processTransaction: IProviderHandlers["processTransaction"]): Promise<string>;
@@ -1,4 +1,5 @@
1
1
  import { BaseConfig, BaseKeyringController, IKeyringController, KeyringControllerState } from "@toruslabs/base-controllers";
2
+ import { Authorization, UnsignedAuthorization } from "../utils/eip7702Types";
2
3
  import { SignTypedDataMessageV4 } from "../utils/interfaces";
3
4
  export declare class KeyringController extends BaseKeyringController<Partial<BaseConfig>, KeyringControllerState> implements IKeyringController {
4
5
  constructor({ config, state }: {
@@ -6,6 +7,7 @@ export declare class KeyringController extends BaseKeyringController<Partial<Bas
6
7
  state: Partial<KeyringControllerState>;
7
8
  });
8
9
  signTransaction<T, U>(tx: T, address: string): Promise<U>;
10
+ signEip7702Authorization(authorization: UnsignedAuthorization, address: string): Promise<Required<Authorization>>;
9
11
  getAccounts(): string[];
10
12
  importAccount(accountPrivateKey: string): string;
11
13
  removeAccount(address: string): void;
@@ -1,6 +1,8 @@
1
1
  import { type Analytics, InPageWalletProviderState, MessageParams, type ProviderConfig, SwitchChainMessageParams, UserRequestApprovalParams } from "@toruslabs/base-controllers";
2
2
  import { JRPCEngineEndCallback, JRPCEngineNextCallback, JRPCMiddleware, JRPCRequest, JRPCResponse } from "@web3auth/auth";
3
- import { AddChainMessageParams, BlockParams, EthereumTransactionMeta, TransactionParams, TransactionRPCMeta, TypedMessageParams, UserOperationGas } from "../utils/interfaces";
3
+ import { TransactionStateManager } from "../Transaction/TransactionStateManager";
4
+ import { Eip5792SendCallsParams, TransactionBatchRequest } from "../utils/eip5792Types";
5
+ import { AddChainMessageParams, BlockParams, EthereumTransactionMeta, GetEthCodeFn, TransactionParams, TransactionRPCMeta, TypedMessageParams, UserOperationGas } from "../utils/interfaces";
4
6
  export interface IProviderHandlers {
5
7
  version: string;
6
8
  aaConfig?: {
@@ -12,6 +14,7 @@ export interface IProviderHandlers {
12
14
  getPrivateKey?: (req: JRPCRequest<unknown>) => Promise<string>;
13
15
  getPublicKey?: (req: JRPCRequest<unknown>) => Promise<string>;
14
16
  processTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
17
+ processTransactionBatch?: (batchRequest: TransactionBatchRequest, req: JRPCRequest<Eip5792SendCallsParams>) => Promise<string>;
15
18
  processSignTransaction?: (txParams: TransactionParams, req: JRPCRequest<TransactionParams> & UserRequestApprovalParams) => Promise<string>;
16
19
  processEthSignMessage?: (msgParams: MessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
17
20
  processTypedMessageV4?: (msgParams: TypedMessageParams, req: JRPCRequest<unknown> & UserRequestApprovalParams) => Promise<string>;
@@ -28,7 +31,30 @@ export interface IProviderHandlers {
28
31
  blockReference: string;
29
32
  }>) => Promise<string>;
30
33
  getPendingTransactionByHash?: (hash: string, req: JRPCRequest<string>) => Promise<EthereumTransactionMeta>;
34
+ getTransactionByBatchId: TransactionStateManager["getTransactionByBatchId"];
31
35
  getProviderState: (req: JRPCRequest<[]>, res: JRPCResponse<InPageWalletProviderState>, next: JRPCEngineNextCallback, end: JRPCEngineEndCallback) => void;
36
+ /**
37
+ * Query the deployment bytecode of an address. (eth_getCode)
38
+ */
39
+ getEthCode?: GetEthCodeFn;
40
+ /**
41
+ * EIP-5792 configuration for wallet capabilities and batch calls.
42
+ */
43
+ eip5792Config?: {
44
+ /**
45
+ * Get the list of supported chain IDs for EIP-5792/EIP-7702.
46
+ */
47
+ getSupportedChains: () => `0x${string}`[];
48
+ /**
49
+ * Get cached delegation addresses.
50
+ * Key format: `${walletAddress}-${chainId}`
51
+ */
52
+ getCachedDelegations?: () => Record<string, `0x${string}` | null>;
53
+ /**
54
+ * Update the delegation cache.
55
+ */
56
+ updateDelegationCache?: (walletAddress: `0x${string}`, chainId: `0x${string}`, delegation: `0x${string}` | null) => void;
57
+ };
32
58
  }
33
59
  export declare function createGetAccountsMiddleware({ getAccounts }: {
34
60
  getAccounts: IProviderHandlers["getAccounts"];
@@ -82,4 +108,30 @@ export declare function createAAMiddleware({ bundlerUrl, paymasterUrl, providerC
82
108
  providerConfig: ProviderConfig;
83
109
  analytics?: Analytics;
84
110
  }): JRPCMiddleware<unknown, unknown>;
111
+ /**
112
+ * Middleware to handle EIP-7702 methods.
113
+ *
114
+ * @param getEthCode - Function to get the deployment bytecode of an address. (eth_getCode)
115
+ * @param processTransaction - Function to process a transaction.
116
+ * @returns JRPCMiddleware to handle EIP-7702 methods
117
+ */
118
+ export declare function createEip7702Middleware({ getEthCode, processTransaction, }: {
119
+ getEthCode: GetEthCodeFn;
120
+ processTransaction: IProviderHandlers["processTransaction"];
121
+ }): JRPCMiddleware<unknown, unknown>;
122
+ /**
123
+ * Middleware to handle EIP-5792 methods.
124
+ * Supports wallet capabilities and batch call operations for EIP-7702 upgraded accounts.
125
+ *
126
+ * @param eip5792Config - Configuration for EIP-5792 handlers.
127
+ * @param processTransaction - Function to process a transaction.
128
+ * @returns JRPCMiddleware to handle EIP-5792 methods
129
+ */
130
+ export declare function createEip5792Middleware({ eip5792Config, processTransaction, processTransactionBatch, getTransactionByBatchId, getEthCode, }: {
131
+ eip5792Config: IProviderHandlers["eip5792Config"];
132
+ processTransaction: IProviderHandlers["processTransaction"];
133
+ processTransactionBatch: IProviderHandlers["processTransactionBatch"];
134
+ getTransactionByBatchId: TransactionStateManager["getTransactionByBatchId"];
135
+ getEthCode: GetEthCodeFn;
136
+ }): JRPCMiddleware<unknown, unknown>;
85
137
  export declare function createEthereumMiddleware(providerHandlers: IProviderHandlers, providerConfig?: ProviderConfig, analytics?: Analytics): JRPCMiddleware<unknown, unknown>;
@@ -5,6 +5,7 @@ import { GasFeeController } from "../Gas/GasFeeController";
5
5
  import { KeyringController } from "../Keyring/KeyringController";
6
6
  import { NetworkController } from "../Network/NetworkController";
7
7
  import { PreferencesController } from "../Preferences/PreferencesController";
8
+ import { Eip5792SendCallsParams, TransactionBatchRequest } from "../utils/eip5792Types";
8
9
  import { EthereumTransactionMeta, TransactionParams } from "../utils/interfaces";
9
10
  import { NonceTracker } from "./NonceTracker";
10
11
  import { PendingTransactionTracker } from "./PendingTransactionTracker";
@@ -19,15 +20,17 @@ export declare class TransactionController extends TransactionStateManager imple
19
20
  private _getCurrentNetworkEIP1559Compatibility;
20
21
  private _getCurrentAccountEIP1559Compatibility;
21
22
  private signEthTx;
23
+ private signEip7702Authorization;
22
24
  private provider;
23
25
  private blockTracker;
24
26
  private inProcessOfSigning;
25
- constructor({ config, state, provider, blockTracker, signEthTx, getCurrentChainId, getCurrentNetworkEIP1559Compatibility, getCurrentAccountEIP1559Compatibility, getSelectedAddress, getEIP1559GasFeeEstimates, }: {
27
+ constructor({ config, state, provider, blockTracker, signEthTx, signEip7702Authorization, getCurrentChainId, getCurrentNetworkEIP1559Compatibility, getCurrentAccountEIP1559Compatibility, getSelectedAddress, getEIP1559GasFeeEstimates, }: {
26
28
  config?: Partial<TransactionConfig>;
27
29
  state?: Partial<TransactionState<TransactionParams, EthereumTransactionMeta>>;
28
30
  provider: SafeEventEmitterProvider;
29
31
  blockTracker: PollingBlockTracker;
30
32
  signEthTx: KeyringController["signTransaction"];
33
+ signEip7702Authorization: KeyringController["signEip7702Authorization"];
31
34
  getCurrentChainId: NetworkController["getNetworkIdentifier"];
32
35
  getCurrentNetworkEIP1559Compatibility: NetworkController["getEIP1559Compatibility"];
33
36
  getCurrentAccountEIP1559Compatibility: (address?: string) => Promise<boolean>;
@@ -39,6 +42,10 @@ export declare class TransactionController extends TransactionStateManager imple
39
42
  origin: string;
40
43
  isUserOperation?: boolean;
41
44
  }): Promise<string>;
45
+ addNewUnapprovedTransactionsBatch(batchRequest: TransactionBatchRequest, req: JRPCRequest<Eip5792SendCallsParams> & UserRequestApprovalParams & {
46
+ origin: string;
47
+ isUserOperation?: boolean;
48
+ }): Promise<string>;
42
49
  processApproval(txMeta: EthereumTransactionMeta): Promise<string>;
43
50
  approveTransaction(transactionID: string): Promise<void>;
44
51
  signTransaction(txId: string, isSignOnly?: boolean): Promise<string>;
@@ -62,4 +69,5 @@ export declare class TransactionController extends TransactionStateManager imple
62
69
  private setupBlockTrackerListener;
63
70
  private onLatestBlock;
64
71
  private markNonceDuplicatesDropped;
72
+ private getTransactionType;
65
73
  }
@@ -20,6 +20,7 @@ export declare class TransactionStateManager extends BaseTransactionStateManager
20
20
  filterToCurrentNetwork?: boolean;
21
21
  limit?: number;
22
22
  }): EthereumTransactionMeta[];
23
+ getTransactionByBatchId(batchId: string): EthereumTransactionMeta;
23
24
  getApprovedTransactions(address?: string): EthereumTransactionMeta[];
24
25
  getSubmittedTransactions(address?: string): EthereumTransactionMeta[];
25
26
  getPendingTransactions(address?: string): EthereumTransactionMeta[];
@@ -1,5 +1,6 @@
1
1
  import { TransactionStatus } from "@toruslabs/base-controllers";
2
2
  import { SafeEventEmitterProvider } from "@web3auth/auth";
3
+ import { NestedTransactionMetadata, TransactionBatchSingleRequest } from "../utils/eip5792Types";
3
4
  import { EthereumTransactionMeta, TransactionParams } from "../utils/interfaces";
4
5
  type NormalizableTransactionParams = keyof Omit<TransactionParams, "accessList">;
5
6
  /**
@@ -61,10 +62,46 @@ export declare const readAddressAsContract: (provider: SafeEventEmitterProvider,
61
62
  contractCode: string;
62
63
  isContractAddress: boolean;
63
64
  }>;
64
- export declare function determineTransactionType(txParams: TransactionParams, provider: SafeEventEmitterProvider): Promise<{
65
+ export declare function determineTransactionType(txParams: TransactionParams, provider: SafeEventEmitterProvider, overrideTxMeta?: Partial<EthereumTransactionMeta>): Promise<{
65
66
  type: string;
66
67
  category: string;
67
68
  methodParams: any[];
68
69
  getCodeResponse: string;
69
70
  }>;
71
+ /**
72
+ * Create the nested transaction metadata for a batch transaction.
73
+ *
74
+ * Reference: {@link https://github.com/MetaMask/core/blob/main/packages/transaction-controller/src/utils/batch.ts#L253}
75
+ *
76
+ * @param from - The sender address.
77
+ * @param batchTxParam - The batch transaction parameter.
78
+ * @param provider - The provider.
79
+ * @returns The nested transaction metadata.
80
+ */
81
+ export declare function createNestedTransactionMeta(from: `0x${string}`, batchTxParam: TransactionBatchSingleRequest, provider: SafeEventEmitterProvider): Promise<NestedTransactionMetadata>;
82
+ export declare function isEip7702SetCodeTx(txMeta: EthereumTransactionMeta): boolean;
83
+ /**
84
+ * Check if a transaction is a EIP-7702 upgrade with data to self transaction.
85
+ * Example: batch transactions with EIP5792 `wallet_sendCalls` method with EIP-7702 upgrade.
86
+ *
87
+ * @example
88
+ * ```json
89
+ * {
90
+ * "from": "0x1234567890123456789012345678901234567890",
91
+ * "to": "0x1234567890123456789012345678901234567890",
92
+ * "data": "0xdeadbeef", // ERC7821 execute batch function data
93
+ * "type": "0x04",
94
+ * "authorizationList": [
95
+ * {
96
+ * "address": "0x1234567890123456789012345678901234567890",
97
+ * "chainId": "0x1",
98
+ * "nonce": "0x1"
99
+ * }
100
+ * ]
101
+ * }
102
+ * ```
103
+ * @param txMeta - The transaction metadata
104
+ * @returns true if it's a EIP-7702 upgrade with data to self transaction
105
+ */
106
+ export declare function isEip7702UpgradeWithDataToSelfTransaction(txMeta: EthereumTransactionMeta): boolean;
70
107
  export {};
@@ -3,6 +3,8 @@ export * from "./AccountAbstraction/AccountAbstractionController";
3
3
  export * from "./AccountAbstraction/smartAccounts";
4
4
  export { PollingBlockTracker } from "./Block/PollingBlockTracker";
5
5
  export { CurrencyController } from "./Currency/CurrencyController";
6
+ export * from "./Eip5792";
7
+ export * from "./Eip7702/eip7702Utils";
6
8
  export { GasFeeController } from "./Gas/GasFeeController";
7
9
  export * from "./Gas/IGasFeeController";
8
10
  export { KeyringController } from "./Keyring/KeyringController";
@@ -35,6 +37,8 @@ export * from "./Transaction/TransactionUtils";
35
37
  export * from "./utils/abis";
36
38
  export * from "./utils/constants";
37
39
  export * from "./utils/conversionUtils";
40
+ export * from "./utils/eip5792Types";
41
+ export * from "./utils/eip7702Types";
38
42
  export * from "./utils/helpers";
39
43
  export * from "./utils/interfaces";
40
44
  /**
@@ -82,3 +82,18 @@ export declare const singleBalanceCheckerAbi: ({
82
82
  stateMutability: string;
83
83
  type: string;
84
84
  })[];
85
+ export declare const erc7821Abi: {
86
+ type: string;
87
+ name: string;
88
+ inputs: {
89
+ name: string;
90
+ type: string;
91
+ internalType: string;
92
+ }[];
93
+ outputs: {
94
+ name: string;
95
+ type: string;
96
+ internalType: string;
97
+ }[];
98
+ stateMutability: string;
99
+ }[];
@@ -4,6 +4,7 @@ export declare const CONTRACT_TYPE_ETH = "eth";
4
4
  export declare const CONTRACT_TYPE_ERC20 = "erc20";
5
5
  export declare const CONTRACT_TYPE_ERC721 = "erc721";
6
6
  export declare const CONTRACT_TYPE_ERC1155 = "erc1155";
7
+ export declare const CONTRACT_TYPE_ERC7821 = "erc7821";
7
8
  export declare const ERC1155_INTERFACE_ID = "0xd9b67a26";
8
9
  export declare const ERC721_INTERFACE_ID = "0x80ac58cd";
9
10
  export declare const ERC721_METADATA_INTERFACE_ID = "0x5b5e139f";
@@ -72,6 +73,7 @@ export declare const TRANSACTION_ENVELOPE_TYPES: {
72
73
  readonly LEGACY: "0x0";
73
74
  readonly ACCESS_LIST: "0x1";
74
75
  readonly FEE_MARKET: "0x2";
76
+ readonly SET_CODE: "0x4";
75
77
  };
76
78
  export declare const GAS_ESTIMATE_TYPES: {
77
79
  readonly FEE_MARKET: "fee-market";
@@ -0,0 +1,155 @@
1
+ import { BaseRequestParams, TransactionReceipt } from "./interfaces";
2
+ export declare const EIP_5792_METHODS: {
3
+ readonly WALLET_GET_CAPABILITIES: "wallet_getCapabilities";
4
+ readonly WALLET_SEND_CALLS: "wallet_sendCalls";
5
+ readonly WALLET_GET_CALLS_STATUS: "wallet_getCallsStatus";
6
+ readonly WALLET_SHOW_CALLS_STATUS: "wallet_showCallsStatus";
7
+ };
8
+ export declare const SUPPORTED_EIP_5792_VERSIONS: readonly ["1.0", "2.0"];
9
+ /**
10
+ * A single call in a batch (EIP-5792)
11
+ */
12
+ export interface Eip5792Call {
13
+ to: `0x${string}`;
14
+ value?: `0x${string}`;
15
+ data?: `0x${string}`;
16
+ capabilities?: Record<string, unknown>;
17
+ }
18
+ /**
19
+ * Parameters for wallet_sendCalls (EIP-5792)
20
+ */
21
+ export interface Eip5792SendCallsParams extends BaseRequestParams {
22
+ version: string;
23
+ chainId: `0x${string}`;
24
+ calls: Eip5792Call[];
25
+ capabilities?: Record<string, unknown>;
26
+ }
27
+ /**
28
+ * Parameters for wallet_getCallsStatus (EIP-5792)
29
+ */
30
+ export type Eip5792GetCallsStatusParams = `0x${string}`;
31
+ /**
32
+ * Parameters for wallet_showCallsStatus (EIP-5792)
33
+ */
34
+ export type Eip5792ShowCallsStatusParams = string;
35
+ /**
36
+ * Parameters for wallet_getCapabilities (EIP-5792)
37
+ */
38
+ export type Eip5792GetCapabilitiesParams = [`0x${string}`, `0x${string}`[]];
39
+ export declare const EIP5792ErrorCode: {
40
+ UnsupportedNonOptionalCapability: number;
41
+ UnsupportedChainId: number;
42
+ UnknownBundleId: number;
43
+ RejectedUpgrade: number;
44
+ };
45
+ export declare const GetCallsStatusCode: {
46
+ PENDING: number;
47
+ CONFIRMED: number;
48
+ FAILED_OFFCHAIN: number;
49
+ REVERTED: number;
50
+ REVERTED_PARTIAL: number;
51
+ };
52
+ /**
53
+ * Response for wallet_getCallsStatus (EIP-5792)
54
+ */
55
+ export interface Eip5792GetCallsStatusResponse {
56
+ id: string;
57
+ chainId: `0x${string}`;
58
+ atomic: boolean;
59
+ status: (typeof GetCallsStatusCode)[keyof typeof GetCallsStatusCode];
60
+ receipts?: TransactionReceipt[];
61
+ }
62
+ /**
63
+ * EIP-5792 atomic status (EIP-5792)
64
+ *
65
+ * Reference: https://eips.ethereum.org/EIPS/eip-5792#wallet_getcapabilities
66
+ */
67
+ export declare const Eip5792AtomicStatus: {
68
+ readonly SUPPORTED: "supported";
69
+ readonly READY: "ready";
70
+ readonly UNSUPPORTED: "unsupported";
71
+ };
72
+ /**
73
+ * Capabilities for a chain (EIP-5792)
74
+ */
75
+ export interface Eip5792ChainCapabilities {
76
+ atomic?: {
77
+ status: "supported" | "ready" | "unsupported";
78
+ };
79
+ paymasterService?: {
80
+ supported: boolean;
81
+ url?: string;
82
+ };
83
+ sessionKeys?: {
84
+ supported: boolean;
85
+ };
86
+ }
87
+ /**
88
+ * Response for wallet_getCapabilities (EIP-5792)
89
+ */
90
+ export type Eip5792GetCapabilitiesResponse = Record<`0x${string}`, Eip5792ChainCapabilities>;
91
+ /**
92
+ * Internal representation of a batch of calls
93
+ */
94
+ export interface Eip5792CallBatch {
95
+ id: string;
96
+ chainId: `0x${string}`;
97
+ from: `0x${string}`;
98
+ calls: Eip5792Call[];
99
+ }
100
+ /**
101
+ * Function type for getting supported chains
102
+ */
103
+ export type GetSupportedChainsFn = () => `0x${string}`[];
104
+ /**
105
+ * Function type for getting cached delegations
106
+ */
107
+ export type GetCachedDelegationsFn = () => Record<string, `0x${string}` | null>;
108
+ /**
109
+ * The parameters of a transaction within an atomic batch.
110
+ */
111
+ export type BatchTransactionParams = {
112
+ /** Data used to invoke a function on the target smart contract or EOA. */
113
+ data?: `0x${string}`;
114
+ /**
115
+ * Maximum number of units of gas to use for the transaction.
116
+ * Not supported in EIP-7702 batches.
117
+ */
118
+ gas?: `0x${string}`;
119
+ /**
120
+ * Maximum amount per gas to pay for the transaction, including the priority fee.
121
+ * Not supported in EIP-7702 batches.
122
+ */
123
+ maxFeePerGas?: `0x${string}`;
124
+ /**
125
+ * Maximum amount per gas to give to validator as incentive.
126
+ * Not supported in EIP-7702 batches.
127
+ */
128
+ maxPriorityFeePerGas?: `0x${string}`;
129
+ /** Address of the target contract or EOA. */
130
+ to?: `0x${string}`;
131
+ /** Native balance to transfer with the transaction. */
132
+ value?: `0x${string}`;
133
+ };
134
+ /** Metadata for a nested transaction within a standard transaction. */
135
+ export type NestedTransactionMetadata = BatchTransactionParams & {
136
+ /** Type of the nested transaction. */
137
+ type?: string;
138
+ };
139
+ export type TransactionBatchSingleRequest = {
140
+ params: BatchTransactionParams;
141
+ type?: string;
142
+ };
143
+ /**
144
+ * Request to submit a batch of transactions.
145
+ * Currently only atomic batches are supported via EIP-7702.
146
+ */
147
+ export type TransactionBatchRequest = {
148
+ batchId?: `0x${string}`;
149
+ /** Transactions to be submitted as part of the batch. */
150
+ transactions: TransactionBatchSingleRequest[];
151
+ /** Whether EIP-7702 upgrade is required for the batch. */
152
+ requiredEip7702Upgrade?: boolean;
153
+ /** Delegation address for EIP-7702 upgrade. */
154
+ eip7702UpgradeContractAddress?: `0x${string}`;
155
+ };