@deserialize/multi-vm-wallet 1.2.293 → 1.3.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 (106) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/SMART_WALLET_GUIDE.md +746 -0
  3. package/SMART_WALLET_IMPLEMENTATION.md +460 -0
  4. package/dist/IChainWallet.d.ts +4 -3
  5. package/dist/IChainWallet.js +5 -0
  6. package/dist/IChainWallet.js.map +1 -1
  7. package/dist/constant.js +17 -4
  8. package/dist/constant.js.map +1 -1
  9. package/dist/evm/SMART_WALLET_EXAMPLES.d.ts +20 -0
  10. package/dist/evm/SMART_WALLET_EXAMPLES.js +451 -0
  11. package/dist/evm/SMART_WALLET_EXAMPLES.js.map +1 -0
  12. package/dist/evm/aa-service/index.d.ts +16 -0
  13. package/dist/evm/aa-service/index.js +69 -0
  14. package/dist/evm/aa-service/index.js.map +1 -0
  15. package/dist/evm/aa-service/lib/account-adapter.d.ts +26 -0
  16. package/dist/evm/aa-service/lib/account-adapter.js +53 -0
  17. package/dist/evm/aa-service/lib/account-adapter.js.map +1 -0
  18. package/dist/evm/aa-service/lib/kernel-account.d.ts +91 -0
  19. package/dist/evm/aa-service/lib/kernel-account.js +251 -0
  20. package/dist/evm/aa-service/lib/kernel-account.js.map +1 -0
  21. package/dist/evm/aa-service/lib/kernel-modules.d.ts +240 -0
  22. package/dist/evm/aa-service/lib/kernel-modules.js +409 -0
  23. package/dist/evm/aa-service/lib/kernel-modules.js.map +1 -0
  24. package/dist/evm/aa-service/lib/session-keys.d.ts +170 -0
  25. package/dist/evm/aa-service/lib/session-keys.js +297 -0
  26. package/dist/evm/aa-service/lib/session-keys.js.map +1 -0
  27. package/dist/evm/aa-service/lib/type.d.ts +167 -0
  28. package/dist/evm/aa-service/lib/type.js +43 -0
  29. package/dist/evm/aa-service/lib/type.js.map +1 -0
  30. package/dist/evm/aa-service/services/account-abstraction.d.ts +614 -0
  31. package/dist/evm/aa-service/services/account-abstraction.js +754 -0
  32. package/dist/evm/aa-service/services/account-abstraction.js.map +1 -0
  33. package/dist/evm/aa-service/services/bundler.d.ts +29 -0
  34. package/dist/evm/aa-service/services/bundler.js +168 -0
  35. package/dist/evm/aa-service/services/bundler.js.map +1 -0
  36. package/dist/evm/evm.d.ts +68 -3
  37. package/dist/evm/evm.js +223 -8
  38. package/dist/evm/evm.js.map +1 -1
  39. package/dist/evm/index.d.ts +1 -0
  40. package/dist/evm/index.js +3 -0
  41. package/dist/evm/index.js.map +1 -1
  42. package/dist/evm/smartWallet.d.ts +265 -0
  43. package/dist/evm/smartWallet.js +675 -0
  44. package/dist/evm/smartWallet.js.map +1 -0
  45. package/dist/evm/smartWallet.types.d.ts +10 -0
  46. package/dist/evm/smartWallet.types.js +16 -0
  47. package/dist/evm/smartWallet.types.js.map +1 -0
  48. package/dist/evm/transaction.utils.d.ts +10 -10
  49. package/dist/evm/transaction.utils.js +12 -8
  50. package/dist/evm/transaction.utils.js.map +1 -1
  51. package/dist/evm/transactionParsing.js +123 -27
  52. package/dist/evm/transactionParsing.js.map +1 -1
  53. package/dist/evm/utils.d.ts +12 -1
  54. package/dist/evm/utils.js +138 -2
  55. package/dist/evm/utils.js.map +1 -1
  56. package/dist/helpers/index.d.ts +4 -1
  57. package/dist/helpers/index.js +25 -0
  58. package/dist/helpers/index.js.map +1 -1
  59. package/dist/helpers/routeScan.d.ts +191 -0
  60. package/dist/helpers/routeScan.js +114 -0
  61. package/dist/helpers/routeScan.js.map +1 -0
  62. package/dist/index.d.ts +0 -2
  63. package/dist/index.js +0 -2
  64. package/dist/index.js.map +1 -1
  65. package/dist/svm/svm.d.ts +6 -4
  66. package/dist/svm/svm.js +33 -19
  67. package/dist/svm/svm.js.map +1 -1
  68. package/dist/svm/transactionSender.js +2 -2
  69. package/dist/svm/transactionSender.js.map +1 -1
  70. package/dist/svm/utils.d.ts +20 -4
  71. package/dist/svm/utils.js +232 -12
  72. package/dist/svm/utils.js.map +1 -1
  73. package/dist/test.d.ts +1 -6
  74. package/dist/test.js +47 -16
  75. package/dist/test.js.map +1 -1
  76. package/dist/types.d.ts +169 -2
  77. package/dist/types.js.map +1 -1
  78. package/dist/vm.js +9 -7
  79. package/dist/vm.js.map +1 -1
  80. package/package.json +2 -2
  81. package/tsconfig.json +4 -3
  82. package/utils/IChainWallet.ts +4 -3
  83. package/utils/constant.ts +18 -4
  84. package/utils/evm/SMART_WALLET_EXAMPLES.ts.bak +591 -0
  85. package/utils/evm/aa-service/index.ts +85 -0
  86. package/utils/evm/aa-service/lib/account-adapter.ts +60 -0
  87. package/utils/evm/aa-service/lib/kernel-account.ts +367 -0
  88. package/utils/evm/aa-service/lib/kernel-modules.ts +598 -0
  89. package/utils/evm/aa-service/lib/session-keys.ts +389 -0
  90. package/utils/evm/aa-service/lib/type.ts +236 -0
  91. package/utils/evm/aa-service/services/account-abstraction.ts +1015 -0
  92. package/utils/evm/aa-service/services/bundler.ts +217 -0
  93. package/utils/evm/evm.ts +281 -13
  94. package/utils/evm/index.ts +5 -1
  95. package/utils/evm/smartWallet.ts +797 -0
  96. package/utils/evm/smartWallet.types.ts +33 -0
  97. package/utils/evm/transaction.utils.ts +12 -10
  98. package/utils/evm/transactionParsing.ts +153 -63
  99. package/utils/evm/utils.ts +161 -2
  100. package/utils/helpers/index.ts +13 -1
  101. package/utils/helpers/routeScan.ts +397 -0
  102. package/utils/index.ts +0 -2
  103. package/utils/svm/svm.ts +61 -14
  104. package/utils/svm/utils.ts +317 -14
  105. package/utils/test.ts +54 -18
  106. package/utils/types.ts +223 -2
@@ -0,0 +1,675 @@
1
+ "use strict";
2
+ /**
3
+ * EVM Smart Wallet Implementation
4
+ *
5
+ * Provides Account Abstraction (EIP-4337) and EIP-7702 capabilities to EVMChainWallet.
6
+ * This class wraps the AA service and provides a clean API for smart wallet features.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.EVMSmartWallet = void 0;
10
+ const accounts_1 = require("viem/accounts");
11
+ const smartWallet_types_1 = require("./smartWallet.types");
12
+ // Import AA service from local aa-service
13
+ const account_abstraction_1 = require("./aa-service/services/account-abstraction");
14
+ const kernel_account_1 = require("./aa-service/lib/kernel-account");
15
+ /**
16
+ * EVMSmartWallet - Smart wallet capabilities for EVM chains
17
+ *
18
+ * Provides:
19
+ * - EIP-7702 account delegation
20
+ * - Batch transactions (pay gas once for multiple operations)
21
+ * - Session keys with granular permissions
22
+ * - Module management (validators, hooks, executors)
23
+ * - Gas sponsorship (paymasters)
24
+ * - Multi-signature support
25
+ * - Account recovery
26
+ */
27
+ class EVMSmartWallet {
28
+ aaService = null;
29
+ kernelAccount = null;
30
+ ownerAccount;
31
+ chain;
32
+ options;
33
+ sessionAccount = null;
34
+ paymasterConfig = null;
35
+ bundlerUrl;
36
+ constructor(privateKey, chain, bundlerUrl, options = {}) {
37
+ this.ownerAccount = (0, accounts_1.privateKeyToAccount)(privateKey);
38
+ this.chain = chain;
39
+ this.bundlerUrl = bundlerUrl;
40
+ this.options = {
41
+ entryPointVersion: '0.7',
42
+ autoInitialize: true,
43
+ ...options
44
+ };
45
+ // Set paymaster if provided
46
+ if (options.paymasterUrl) {
47
+ this.paymasterConfig = {
48
+ paymasterUrl: options.paymasterUrl
49
+ };
50
+ }
51
+ }
52
+ // ============================================
53
+ // Core Methods
54
+ // ============================================
55
+ /**
56
+ * Initialize the smart wallet
57
+ * Creates the Kernel account and sets up delegation if needed
58
+ */
59
+ async initialize() {
60
+ try {
61
+ // Initialize AA service singleton with custom bundler URL
62
+ this.aaService = account_abstraction_1.AccountAbstractionService.getInstance({
63
+ bundlerProvider: 'custom',
64
+ customBundlerUrl: this.bundlerUrl
65
+ });
66
+ // Create Kernel account
67
+ this.kernelAccount = await this.aaService.createAccount({
68
+ chain: this.chain,
69
+ owner: this.ownerAccount,
70
+ entryPointVersion: this.options.entryPointVersion
71
+ });
72
+ console.log(`Smart wallet initialized: ${this.kernelAccount.address}`);
73
+ }
74
+ catch (error) {
75
+ throw new smartWallet_types_1.SmartWalletError(`Failed to initialize smart wallet: ${error instanceof Error ? error.message : 'Unknown error'}`, 'INIT_ERROR');
76
+ }
77
+ }
78
+ /**
79
+ * Get the smart account address
80
+ */
81
+ getAddress() {
82
+ if (!this.kernelAccount) {
83
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
84
+ }
85
+ return this.kernelAccount.address;
86
+ }
87
+ /**
88
+ * Get smart account information
89
+ */
90
+ async getAccountInfo() {
91
+ if (!this.kernelAccount || !this.aaService) {
92
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
93
+ }
94
+ const balance = await this.getBalance();
95
+ const isDelegated = await this.aaService.isAccountDelegated(this.ownerAccount, this.chain);
96
+ return {
97
+ address: this.kernelAccount.address,
98
+ ownerAddress: this.ownerAccount.address,
99
+ chain: this.chain,
100
+ entryPointVersion: this.options.entryPointVersion,
101
+ isDelegated,
102
+ balance: BigInt(balance.balance.toString())
103
+ };
104
+ }
105
+ /**
106
+ * Get smart account balance
107
+ */
108
+ async getBalance() {
109
+ if (!this.kernelAccount || !this.aaService) {
110
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
111
+ }
112
+ const balance = await this.aaService.getBalance(this.kernelAccount);
113
+ return {
114
+ balance: balance,
115
+ decimal: 18,
116
+ formatted: Number(balance) / 1e18
117
+ };
118
+ }
119
+ /**
120
+ * Check if account is delegated
121
+ */
122
+ async isAccountDelegated() {
123
+ if (!this.aaService) {
124
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
125
+ }
126
+ return await this.aaService.isAccountDelegated(this.ownerAccount, this.chain);
127
+ }
128
+ // ============================================
129
+ // Transaction Methods
130
+ // ============================================
131
+ /**
132
+ * Send a single transaction via UserOperation
133
+ *
134
+ * @param to - Recipient address
135
+ * @param value - ETH value in wei
136
+ * @param data - Optional calldata
137
+ * @returns Transaction result with UserOp hash
138
+ *
139
+ * @example
140
+ * await smartWallet.sendTransaction(
141
+ * '0xRecipient',
142
+ * parseEther('0.1'),
143
+ * '0x'
144
+ * );
145
+ */
146
+ async sendTransaction(to, value = 0n, data = '0x') {
147
+ if (!this.kernelAccount || !this.aaService) {
148
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
149
+ }
150
+ try {
151
+ // Use session account if available, otherwise use kernel account
152
+ const account = this.sessionAccount || this.kernelAccount;
153
+ const userOpHash = await this.aaService.sendTransaction({
154
+ account,
155
+ to,
156
+ value,
157
+ data
158
+ });
159
+ // Wait for receipt
160
+ const receipt = await this.aaService.waitForReceipt({
161
+ userOpHash,
162
+ chain: this.chain
163
+ });
164
+ return {
165
+ success: true,
166
+ userOpHash,
167
+ transactionHash: receipt.transactionHash
168
+ };
169
+ }
170
+ catch (error) {
171
+ const errorMsg = error instanceof Error ? error.message : 'Unknown error';
172
+ return {
173
+ success: false,
174
+ userOpHash: '0x',
175
+ error: errorMsg
176
+ };
177
+ }
178
+ }
179
+ /**
180
+ * Send multiple transactions in a single UserOperation
181
+ * This is one of the main advantages of smart accounts - pay gas ONLY ONCE!
182
+ *
183
+ * @param calls - Array of calls to execute
184
+ * @returns Transaction result
185
+ *
186
+ * @example
187
+ * await smartWallet.sendBatchTransaction([
188
+ * { to: recipient1, value: parseEther('0.1'), data: '0x' },
189
+ * { to: recipient2, value: parseEther('0.2'), data: '0x' },
190
+ * { to: usdcAddress, value: 0n, data: transferCalldata }
191
+ * ]);
192
+ */
193
+ async sendBatchTransaction(calls) {
194
+ if (!this.kernelAccount || !this.aaService) {
195
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
196
+ }
197
+ if (calls.length === 0) {
198
+ throw new smartWallet_types_1.TransactionError('Batch transaction must have at least one call');
199
+ }
200
+ try {
201
+ // Convert to AA service Call format
202
+ const aaCalls = calls.map(call => ({
203
+ to: call.to,
204
+ value: call.value,
205
+ data: call.data
206
+ }));
207
+ // Use session account if available, otherwise use kernel account
208
+ const account = this.sessionAccount || this.kernelAccount;
209
+ const userOpHash = await this.aaService.sendBatchTransaction({
210
+ account,
211
+ calls: aaCalls
212
+ });
213
+ // Wait for receipt
214
+ const receipt = await this.aaService.waitForReceipt({
215
+ userOpHash,
216
+ chain: this.chain
217
+ });
218
+ return {
219
+ success: true,
220
+ userOpHash,
221
+ transactionHash: receipt.transactionHash
222
+ };
223
+ }
224
+ catch (error) {
225
+ const errorMsg = error instanceof Error ? error.message : 'Unknown error';
226
+ return {
227
+ success: false,
228
+ userOpHash: '0x',
229
+ error: errorMsg
230
+ };
231
+ }
232
+ }
233
+ /**
234
+ * Prepare a call for batching
235
+ * Helper method to create Call objects
236
+ */
237
+ prepareCall(to, value = 0n, data = '0x') {
238
+ return { to, value, data };
239
+ }
240
+ // ============================================
241
+ // Session Key Methods
242
+ // ============================================
243
+ /**
244
+ * Generate a new session key
245
+ * The private key should be stored securely by the agent
246
+ *
247
+ * @returns Session key info with private key, address, and signer
248
+ *
249
+ * @example
250
+ * const sessionKey = await smartWallet.generateSessionKey();
251
+ * console.log('Address:', sessionKey.address);
252
+ * // Store sessionKey.privateKey securely
253
+ */
254
+ async generateSessionKey() {
255
+ if (!this.aaService) {
256
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
257
+ }
258
+ try {
259
+ return await this.aaService.generateSessionKey();
260
+ }
261
+ catch (error) {
262
+ throw new smartWallet_types_1.SessionKeyError(`Failed to generate session key: ${error instanceof Error ? error.message : 'Unknown error'}`);
263
+ }
264
+ }
265
+ /**
266
+ * Recreate session key from stored private key
267
+ *
268
+ * @param privateKey - Session key private key
269
+ * @returns Session key info
270
+ *
271
+ * @example
272
+ * const sessionKey = await smartWallet.recreateSessionKey(storedPrivateKey);
273
+ */
274
+ async recreateSessionKey(privateKey) {
275
+ if (!this.aaService) {
276
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
277
+ }
278
+ try {
279
+ return await this.aaService.recreateSessionKey(privateKey);
280
+ }
281
+ catch (error) {
282
+ throw new smartWallet_types_1.SessionKeyError(`Failed to recreate session key: ${error instanceof Error ? error.message : 'Unknown error'}`);
283
+ }
284
+ }
285
+ /**
286
+ * Create session key approval (Owner side)
287
+ * Owner approves a session key with specific permissions
288
+ *
289
+ * @param options - Approval options with session key address and permissions
290
+ * @returns Serialized approval string to share with agent
291
+ *
292
+ * @example
293
+ * const approval = await smartWallet.approveSessionKey({
294
+ * sessionKeyAddress: '0x...',
295
+ * permissions: [
296
+ * smartWallet.createUSDCPermission(USDC_ADDRESS, '100')
297
+ * ]
298
+ * });
299
+ */
300
+ async approveSessionKey(options) {
301
+ if (!this.aaService) {
302
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
303
+ }
304
+ try {
305
+ return await this.aaService.createSessionKeyApproval({
306
+ sessionKeyAddress: options.sessionKeyAddress,
307
+ owner: this.ownerAccount,
308
+ chain: this.chain,
309
+ entryPointVersion: this.options.entryPointVersion,
310
+ useSudoPolicy: options.useSudoPolicy,
311
+ permissions: options.permissions
312
+ });
313
+ }
314
+ catch (error) {
315
+ throw new smartWallet_types_1.SessionKeyError(`Failed to approve session key: ${error instanceof Error ? error.message : 'Unknown error'}`);
316
+ }
317
+ }
318
+ /**
319
+ * Use session key for transactions (Agent side)
320
+ * Agent deserializes the approval and can send transactions with session key
321
+ *
322
+ * @param options - Session key usage options with approval and signer
323
+ *
324
+ * @example
325
+ * const sessionKey = await smartWallet.recreateSessionKey(privateKey);
326
+ * await smartWallet.useSessionKey({
327
+ * approval,
328
+ * sessionKeySigner: sessionKey.signer
329
+ * });
330
+ * // Now can send transactions with session key permissions
331
+ */
332
+ async useSessionKey(options) {
333
+ if (!this.aaService) {
334
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
335
+ }
336
+ try {
337
+ this.sessionAccount = await this.aaService.deserializeSessionKey({
338
+ approval: options.approval,
339
+ sessionKeySigner: options.sessionKeySigner,
340
+ chain: this.chain,
341
+ entryPointVersion: this.options.entryPointVersion
342
+ });
343
+ }
344
+ catch (error) {
345
+ throw new smartWallet_types_1.SessionKeyError(`Failed to use session key: ${error instanceof Error ? error.message : 'Unknown error'}`);
346
+ }
347
+ }
348
+ /**
349
+ * Clear session key (revert to owner account)
350
+ */
351
+ clearSessionKey() {
352
+ this.sessionAccount = null;
353
+ }
354
+ /**
355
+ * Check if using session key
356
+ */
357
+ isUsingSessionKey() {
358
+ return this.sessionAccount !== null;
359
+ }
360
+ /**
361
+ * Create USDC transfer permission
362
+ *
363
+ * @param usdcAddress - USDC contract address
364
+ * @param maxAmount - Maximum USDC amount (in USDC units, e.g., "10" for 10 USDC)
365
+ * @returns Permission rule
366
+ */
367
+ createUSDCPermission(usdcAddress, maxAmount) {
368
+ if (!this.aaService) {
369
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
370
+ }
371
+ return this.aaService.createUSDCTransferPermission(usdcAddress, maxAmount);
372
+ }
373
+ /**
374
+ * Create ETH transfer permission
375
+ *
376
+ * @param maxValue - Maximum ETH value (in ether units, e.g., "0.1" for 0.1 ETH)
377
+ * @returns Permission rule
378
+ */
379
+ createETHPermission(maxValue) {
380
+ if (!this.aaService) {
381
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
382
+ }
383
+ return this.aaService.createETHTransferPermission(maxValue);
384
+ }
385
+ // ============================================
386
+ // Module Management Methods
387
+ // ============================================
388
+ /**
389
+ * Install a module on the smart account
390
+ *
391
+ * @param options - Module installation options
392
+ * @returns Transaction result
393
+ *
394
+ * @example
395
+ * await smartWallet.installModule({
396
+ * moduleType: 'validator',
397
+ * moduleAddress: '0x...',
398
+ * initData: '0x...'
399
+ * });
400
+ */
401
+ async installModule(options) {
402
+ if (!this.kernelAccount || !this.aaService) {
403
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
404
+ }
405
+ try {
406
+ const userOpHash = await this.aaService.installModule({
407
+ account: this.kernelAccount,
408
+ moduleType: options.moduleType,
409
+ moduleAddress: options.moduleAddress,
410
+ initData: options.initData
411
+ });
412
+ const receipt = await this.aaService.waitForReceipt({
413
+ userOpHash,
414
+ chain: this.chain
415
+ });
416
+ return {
417
+ success: true,
418
+ userOpHash,
419
+ transactionHash: receipt.transactionHash
420
+ };
421
+ }
422
+ catch (error) {
423
+ const errorMsg = error instanceof Error ? error.message : 'Unknown error';
424
+ throw new smartWallet_types_1.ModuleError(`Failed to install module: ${errorMsg}`);
425
+ }
426
+ }
427
+ /**
428
+ * Uninstall a module from the smart account
429
+ *
430
+ * @param options - Module uninstallation options
431
+ * @returns Transaction result
432
+ */
433
+ async uninstallModule(options) {
434
+ if (!this.kernelAccount || !this.aaService) {
435
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
436
+ }
437
+ try {
438
+ const userOpHash = await this.aaService.uninstallModule({
439
+ account: this.kernelAccount,
440
+ moduleType: options.moduleType,
441
+ moduleAddress: options.moduleAddress,
442
+ deInitData: options.deInitData
443
+ });
444
+ const receipt = await this.aaService.waitForReceipt({
445
+ userOpHash,
446
+ chain: this.chain
447
+ });
448
+ return {
449
+ success: true,
450
+ userOpHash,
451
+ transactionHash: receipt.transactionHash
452
+ };
453
+ }
454
+ catch (error) {
455
+ const errorMsg = error instanceof Error ? error.message : 'Unknown error';
456
+ throw new smartWallet_types_1.ModuleError(`Failed to uninstall module: ${errorMsg}`);
457
+ }
458
+ }
459
+ /**
460
+ * Check if a module is installed
461
+ *
462
+ * @param moduleType - Type of module
463
+ * @param moduleAddress - Module contract address
464
+ * @returns Whether the module is installed
465
+ */
466
+ async isModuleInstalled(moduleType, moduleAddress) {
467
+ if (!this.kernelAccount || !this.aaService) {
468
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
469
+ }
470
+ try {
471
+ return await this.aaService.isModuleInstalled({
472
+ account: this.kernelAccount,
473
+ moduleType,
474
+ moduleAddress
475
+ });
476
+ }
477
+ catch (error) {
478
+ return false;
479
+ }
480
+ }
481
+ /**
482
+ * Prepare module installation call (for batching)
483
+ *
484
+ * @param options - Module installation options
485
+ * @returns Call object for batch transaction
486
+ */
487
+ prepareInstallModule(options) {
488
+ if (!this.kernelAccount || !this.aaService) {
489
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
490
+ }
491
+ const aaCall = this.aaService.prepareInstallModule({
492
+ account: this.kernelAccount,
493
+ moduleType: options.moduleType,
494
+ moduleAddress: options.moduleAddress,
495
+ initData: options.initData
496
+ });
497
+ return {
498
+ to: aaCall.to,
499
+ value: aaCall.value,
500
+ data: aaCall.data
501
+ };
502
+ }
503
+ /**
504
+ * Prepare module uninstallation call (for batching)
505
+ *
506
+ * @param options - Module uninstallation options
507
+ * @returns Call object for batch transaction
508
+ */
509
+ prepareUninstallModule(options) {
510
+ if (!this.kernelAccount || !this.aaService) {
511
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
512
+ }
513
+ const aaCall = this.aaService.prepareUninstallModule({
514
+ account: this.kernelAccount,
515
+ moduleType: options.moduleType,
516
+ moduleAddress: options.moduleAddress,
517
+ deInitData: options.deInitData
518
+ });
519
+ return {
520
+ to: aaCall.to,
521
+ value: aaCall.value,
522
+ data: aaCall.data
523
+ };
524
+ }
525
+ // ============================================
526
+ // Advanced Features
527
+ // ============================================
528
+ /**
529
+ * Enable multi-signature validation
530
+ *
531
+ * @param config - Multi-sig configuration with owners and threshold
532
+ * @returns Transaction result
533
+ *
534
+ * @example
535
+ * await smartWallet.enableMultiSig({
536
+ * owners: [owner1, owner2, owner3],
537
+ * threshold: 2 // 2 of 3 required
538
+ * });
539
+ */
540
+ async enableMultiSig(config) {
541
+ if (!this.kernelAccount || !this.aaService) {
542
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized', 'NOT_INITIALIZED');
543
+ }
544
+ try {
545
+ const userOpHash = await this.aaService.installMultiSigValidator({
546
+ account: this.kernelAccount,
547
+ owners: config.owners,
548
+ threshold: config.threshold
549
+ });
550
+ const receipt = await this.aaService.waitForReceipt({
551
+ userOpHash,
552
+ chain: this.chain
553
+ });
554
+ return {
555
+ success: true,
556
+ userOpHash,
557
+ transactionHash: receipt.transactionHash
558
+ };
559
+ }
560
+ catch (error) {
561
+ const errorMsg = error instanceof Error ? error.message : 'Unknown error';
562
+ throw new smartWallet_types_1.SmartWalletError(`Failed to enable multi-sig: ${errorMsg}`, 'MULTISIG_ERROR');
563
+ }
564
+ }
565
+ /**
566
+ * Set paymaster for gas sponsorship
567
+ *
568
+ * @param paymasterUrl - Paymaster service URL
569
+ *
570
+ * @example
571
+ * smartWallet.setPaymaster('https://api.pimlico.io/v2/sepolia/paymaster');
572
+ */
573
+ setPaymaster(paymasterUrl, context) {
574
+ this.paymasterConfig = {
575
+ paymasterUrl,
576
+ context
577
+ };
578
+ }
579
+ /**
580
+ * Clear paymaster (user pays gas)
581
+ */
582
+ clearPaymaster() {
583
+ this.paymasterConfig = null;
584
+ }
585
+ /**
586
+ * Check if paymaster is configured
587
+ */
588
+ hasPaymaster() {
589
+ return this.paymasterConfig !== null;
590
+ }
591
+ /**
592
+ * Get bundler information
593
+ */
594
+ getBundlerInfo() {
595
+ if (!this.aaService) {
596
+ return {
597
+ provider: 'custom',
598
+ url: this.bundlerUrl
599
+ };
600
+ }
601
+ return this.aaService.getBundlerInfo(this.chain);
602
+ }
603
+ // ============================================
604
+ // Sponsored Transactions (EIP-7702)
605
+ // ============================================
606
+ /**
607
+ * Send sponsored batch transaction where another wallet pays gas fees
608
+ * Requires smart wallet to be initialized
609
+ *
610
+ * @param calls - Array of calls to execute
611
+ * @param feePayerPrivateKey - Private key of the wallet paying gas fees
612
+ * @returns Transaction result with userOpHash and transactionHash
613
+ *
614
+ * @example
615
+ * // Send ETH transfer with sponsor paying gas
616
+ * const result = await smartWallet.sendSponsoredBatchTransaction(
617
+ * [{ to: recipient, value: parseEther('0.1') }],
618
+ * sponsorPrivateKey
619
+ * );
620
+ */
621
+ async sendSponsoredBatchTransaction(calls, feePayerPrivateKey) {
622
+ if (!this.aaService) {
623
+ throw new smartWallet_types_1.SmartWalletError('Smart wallet not initialized. Call initialize() first.', 'NOT_INITIALIZED');
624
+ }
625
+ if (!this.kernelAccount) {
626
+ throw new smartWallet_types_1.SmartWalletError('Kernel account not found. Smart wallet may not be properly initialized.', 'ACCOUNT_NOT_FOUND');
627
+ }
628
+ try {
629
+ // Create authorization for owner wallet
630
+ const authorization = await (0, kernel_account_1.createKernelAuthorization)({
631
+ owner: this.ownerAccount,
632
+ chain: this.chain,
633
+ bundlerManager: this.aaService.getBundlerManager(this.chain)
634
+ });
635
+ if (!authorization) {
636
+ throw new smartWallet_types_1.SmartWalletError('Failed to create authorization for sponsored transaction', 'AUTHORIZATION_FAILED');
637
+ }
638
+ // Send sponsored transaction with feePayer
639
+ const result = await (0, kernel_account_1.sendSponsoredBatchTransaction)({
640
+ ownerAuthorization: authorization,
641
+ calls,
642
+ feePayerPrivateKey,
643
+ bundlerUrl: this.bundlerUrl,
644
+ paymasterUrl: this.paymasterConfig?.paymasterUrl,
645
+ chain: this.chain,
646
+ entryPointVersion: this.options.entryPointVersion
647
+ });
648
+ return {
649
+ success: true,
650
+ userOpHash: result.userOpHash,
651
+ transactionHash: result.transactionHash
652
+ };
653
+ }
654
+ catch (error) {
655
+ console.error('Sponsored batch transaction failed:', error);
656
+ return {
657
+ success: false,
658
+ userOpHash: '0x',
659
+ error: error instanceof Error ? error.message : 'Unknown error occurred'
660
+ };
661
+ }
662
+ }
663
+ /**
664
+ * Clear all caches
665
+ */
666
+ clearCache() {
667
+ if (this.aaService) {
668
+ this.aaService.clearCache();
669
+ }
670
+ this.kernelAccount = null;
671
+ this.sessionAccount = null;
672
+ }
673
+ }
674
+ exports.EVMSmartWallet = EVMSmartWallet;
675
+ //# sourceMappingURL=smartWallet.js.map