@deserialize/multi-vm-wallet 1.2.441 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/.claude/settings.local.json +14 -0
  2. package/SMART_WALLET_GUIDE.md +746 -0
  3. package/SMART_WALLET_IMPLEMENTATION.md +460 -0
  4. package/dist/IChainWallet.d.ts +3 -3
  5. package/dist/IChainWallet.js +5 -0
  6. package/dist/IChainWallet.js.map +1 -1
  7. package/dist/evm/SMART_WALLET_EXAMPLES.d.ts +20 -0
  8. package/dist/evm/SMART_WALLET_EXAMPLES.js +451 -0
  9. package/dist/evm/SMART_WALLET_EXAMPLES.js.map +1 -0
  10. package/dist/evm/aa-service/index.d.ts +16 -0
  11. package/dist/evm/aa-service/index.js +69 -0
  12. package/dist/evm/aa-service/index.js.map +1 -0
  13. package/dist/evm/aa-service/lib/account-adapter.d.ts +26 -0
  14. package/dist/evm/aa-service/lib/account-adapter.js +53 -0
  15. package/dist/evm/aa-service/lib/account-adapter.js.map +1 -0
  16. package/dist/evm/aa-service/lib/kernel-account.d.ts +91 -0
  17. package/dist/evm/aa-service/lib/kernel-account.js +251 -0
  18. package/dist/evm/aa-service/lib/kernel-account.js.map +1 -0
  19. package/dist/evm/aa-service/lib/kernel-modules.d.ts +240 -0
  20. package/dist/evm/aa-service/lib/kernel-modules.js +409 -0
  21. package/dist/evm/aa-service/lib/kernel-modules.js.map +1 -0
  22. package/dist/evm/aa-service/lib/session-keys.d.ts +170 -0
  23. package/dist/evm/aa-service/lib/session-keys.js +297 -0
  24. package/dist/evm/aa-service/lib/session-keys.js.map +1 -0
  25. package/dist/evm/aa-service/lib/type.d.ts +167 -0
  26. package/dist/evm/aa-service/lib/type.js +43 -0
  27. package/dist/evm/aa-service/lib/type.js.map +1 -0
  28. package/dist/evm/aa-service/services/account-abstraction.d.ts +614 -0
  29. package/dist/evm/aa-service/services/account-abstraction.js +754 -0
  30. package/dist/evm/aa-service/services/account-abstraction.js.map +1 -0
  31. package/dist/evm/aa-service/services/bundler.d.ts +29 -0
  32. package/dist/evm/aa-service/services/bundler.js +168 -0
  33. package/dist/evm/aa-service/services/bundler.js.map +1 -0
  34. package/dist/evm/evm.d.ts +67 -3
  35. package/dist/evm/evm.js +212 -7
  36. package/dist/evm/evm.js.map +1 -1
  37. package/dist/evm/index.d.ts +1 -0
  38. package/dist/evm/index.js +3 -0
  39. package/dist/evm/index.js.map +1 -1
  40. package/dist/evm/smartWallet.d.ts +265 -0
  41. package/dist/evm/smartWallet.js +676 -0
  42. package/dist/evm/smartWallet.js.map +1 -0
  43. package/dist/evm/smartWallet.types.d.ts +10 -0
  44. package/dist/evm/smartWallet.types.js +16 -0
  45. package/dist/evm/smartWallet.types.js.map +1 -0
  46. package/dist/evm/transaction.utils.d.ts +10 -10
  47. package/dist/evm/transaction.utils.js +12 -8
  48. package/dist/evm/transaction.utils.js.map +1 -1
  49. package/dist/evm/transactionParsing.js +77 -1
  50. package/dist/evm/transactionParsing.js.map +1 -1
  51. package/dist/helpers/index.d.ts +1 -0
  52. package/dist/helpers/index.js +15 -0
  53. package/dist/helpers/index.js.map +1 -1
  54. package/dist/helpers/routeScan.d.ts +191 -0
  55. package/dist/helpers/routeScan.js +114 -0
  56. package/dist/helpers/routeScan.js.map +1 -0
  57. package/dist/index.d.ts +0 -2
  58. package/dist/index.js +0 -2
  59. package/dist/index.js.map +1 -1
  60. package/dist/svm/svm.d.ts +4 -3
  61. package/dist/svm/svm.js +29 -18
  62. package/dist/svm/svm.js.map +1 -1
  63. package/dist/svm/transactionSender.js +2 -2
  64. package/dist/svm/transactionSender.js.map +1 -1
  65. package/dist/svm/utils.d.ts +4 -3
  66. package/dist/svm/utils.js +19 -6
  67. package/dist/svm/utils.js.map +1 -1
  68. package/dist/test.d.ts +4 -0
  69. package/dist/test.js +50 -19
  70. package/dist/test.js.map +1 -1
  71. package/dist/types.d.ts +19 -2
  72. package/dist/types.js.map +1 -1
  73. package/dist/vm.js +9 -7
  74. package/dist/vm.js.map +1 -1
  75. package/package.json +4 -2
  76. package/tsconfig.json +4 -3
  77. package/utils/IChainWallet.ts +3 -3
  78. package/utils/evm/aa-service/index.ts +85 -0
  79. package/utils/evm/aa-service/lib/account-adapter.ts +60 -0
  80. package/utils/evm/aa-service/lib/kernel-account.ts +367 -0
  81. package/utils/evm/aa-service/lib/kernel-modules.ts +598 -0
  82. package/utils/evm/aa-service/lib/session-keys.ts +389 -0
  83. package/utils/evm/aa-service/lib/type.ts +236 -0
  84. package/utils/evm/aa-service/services/account-abstraction.ts +1015 -0
  85. package/utils/evm/aa-service/services/bundler.ts +217 -0
  86. package/utils/evm/evm.ts +268 -11
  87. package/utils/evm/index.ts +5 -1
  88. package/utils/evm/smartWallet.ts +799 -0
  89. package/utils/evm/smartWallet.types.ts +33 -0
  90. package/utils/evm/transaction.utils.ts +12 -10
  91. package/utils/evm/transactionParsing.ts +100 -14
  92. package/utils/helpers/index.ts +1 -0
  93. package/utils/helpers/routeScan.ts +397 -0
  94. package/utils/index.ts +0 -2
  95. package/utils/svm/svm.ts +50 -9
  96. package/utils/svm/utils.ts +52 -7
  97. package/utils/test.ts +66 -19
  98. package/utils/types.ts +24 -2
@@ -0,0 +1,754 @@
1
+ "use strict";
2
+ /**
3
+ * Account Abstraction Service (Singleton)
4
+ *
5
+ * Centralized service for managing Kernel accounts, bundlers, and transactions.
6
+ * Use this singleton across your application for consistent AA operations.
7
+ *
8
+ * Usage:
9
+ * const aaService = AccountAbstractionService.getInstance({
10
+ * bundlerProvider: 'pimlico',
11
+ * apiKey: env.pimlicoApiKey
12
+ * });
13
+ *
14
+ * const account = await aaService.createAccount(sepolia, owner);
15
+ * const txHash = await aaService.sendTransaction({ account, to, value });
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.AccountAbstractionService = void 0;
19
+ const viem_1 = require("viem");
20
+ const bundler_1 = require("./bundler");
21
+ const kernel_account_1 = require("../lib/kernel-account");
22
+ const kernel_modules_1 = require("../lib/kernel-modules");
23
+ const session_keys_1 = require("../lib/session-keys");
24
+ // ============================================
25
+ // Singleton Service
26
+ // ============================================
27
+ class AccountAbstractionService {
28
+ static instance = null;
29
+ bundlerManager;
30
+ accountCache = new Map();
31
+ authorizationCache = new Map();
32
+ publicClientCache = new Map();
33
+ /**
34
+ * Private constructor (singleton pattern)
35
+ */
36
+ constructor(config) {
37
+ const bundlerConfig = {
38
+ provider: config.bundlerProvider,
39
+ apiKey: config.apiKey,
40
+ customUrl: config.customBundlerUrl
41
+ };
42
+ this.bundlerManager = (0, bundler_1.createBundlerManager)(bundlerConfig);
43
+ }
44
+ /**
45
+ * Get singleton instance
46
+ */
47
+ static getInstance(config) {
48
+ if (!AccountAbstractionService.instance) {
49
+ if (!config) {
50
+ throw new Error('AccountAbstractionService must be initialized with config on first call');
51
+ }
52
+ AccountAbstractionService.instance = new AccountAbstractionService(config);
53
+ }
54
+ return AccountAbstractionService.instance;
55
+ }
56
+ /**
57
+ * Reset singleton instance (useful for testing or reconfiguration)
58
+ */
59
+ static reset() {
60
+ AccountAbstractionService.instance = null;
61
+ }
62
+ /**
63
+ * Update bundler configuration (creates new bundler manager)
64
+ */
65
+ updateBundlerConfig(config) {
66
+ const bundlerConfig = {
67
+ provider: config.bundlerProvider,
68
+ apiKey: config.apiKey,
69
+ customUrl: config.customBundlerUrl
70
+ };
71
+ this.bundlerManager = (0, bundler_1.createBundlerManager)(bundlerConfig);
72
+ this.clearCache();
73
+ }
74
+ // ============================================
75
+ // Account Management
76
+ // ============================================
77
+ /**
78
+ * Create a Kernel 7702 account
79
+ */
80
+ async createAccount(options) {
81
+ const { chain, owner, entryPointVersion = '0.7' } = options;
82
+ const cacheKey = this.getAccountCacheKey(chain, owner, entryPointVersion);
83
+ // Return cached account if exists
84
+ if (this.accountCache.has(cacheKey)) {
85
+ return this.accountCache.get(cacheKey);
86
+ }
87
+ // Create new account
88
+ const account = await (0, kernel_account_1.createKernel7702Account)({
89
+ chain,
90
+ owner,
91
+ bundlerManager: this.bundlerManager,
92
+ entryPointVersion
93
+ });
94
+ // Cache and return
95
+ this.accountCache.set(cacheKey, account);
96
+ return account;
97
+ }
98
+ /**
99
+ * Get cached account (if exists)
100
+ */
101
+ getCachedAccount(chain, owner, entryPointVersion = '0.7') {
102
+ const cacheKey = this.getAccountCacheKey(chain, owner, entryPointVersion);
103
+ return this.accountCache.get(cacheKey);
104
+ }
105
+ /**
106
+ * Check if account is already delegated to Kernel
107
+ */
108
+ async isAccountDelegated(owner, chain) {
109
+ const authorization = await this.createAuthorization({ owner, chain });
110
+ return authorization === undefined;
111
+ }
112
+ // ============================================
113
+ // Authorization Management
114
+ // ============================================
115
+ /**
116
+ * Create EIP-7702 authorization (if needed)
117
+ */
118
+ async createAuthorization(options) {
119
+ const { owner, chain } = options;
120
+ const cacheKey = this.getAuthorizationCacheKey(chain, owner);
121
+ // Return cached authorization if exists
122
+ if (this.authorizationCache.has(cacheKey)) {
123
+ return this.authorizationCache.get(cacheKey);
124
+ }
125
+ // Create authorization
126
+ const authorization = await (0, kernel_account_1.createKernelAuthorization)({
127
+ owner,
128
+ chain,
129
+ bundlerManager: this.bundlerManager
130
+ });
131
+ // Cache if created (undefined means already delegated)
132
+ if (authorization) {
133
+ this.authorizationCache.set(cacheKey, authorization);
134
+ }
135
+ return authorization;
136
+ }
137
+ // ============================================
138
+ // Transaction Management
139
+ // ============================================
140
+ /**
141
+ * Prepare a call (for batching)
142
+ *
143
+ * Returns a Call object that can be included in a batch transaction.
144
+ * Use this to prepare any transfer or contract interaction for batching.
145
+ *
146
+ * @example
147
+ * // Prepare multiple calls
148
+ * const calls = [
149
+ * aaService.prepareCall({ to: recipient1, value: parseEther('0.1') }),
150
+ * aaService.prepareCall({ to: recipient2, value: parseEther('0.2') }),
151
+ * aaService.prepareCall({ to: contractAddress, data: encodedData })
152
+ * ];
153
+ * await aaService.sendBatchTransaction({ account, calls });
154
+ */
155
+ prepareCall(options) {
156
+ return {
157
+ to: options.to,
158
+ value: options.value ?? 0n,
159
+ data: options.data ?? '0x'
160
+ };
161
+ }
162
+ /**
163
+ * Prepare a contract call (for batching)
164
+ *
165
+ * Helper for preparing contract interactions with type-safe encoding.
166
+ *
167
+ * @example
168
+ * import { parseAbi, encodeFunctionData } from 'viem';
169
+ *
170
+ * const call = aaService.prepareContractCall({
171
+ * to: USDC_ADDRESS,
172
+ * data: encodeFunctionData({
173
+ * abi: parseAbi(['function transfer(address to, uint256 amount)']),
174
+ * functionName: 'transfer',
175
+ * args: [recipient, parseUnits('100', 6)]
176
+ * })
177
+ * });
178
+ */
179
+ prepareContractCall(options) {
180
+ return {
181
+ to: options.to,
182
+ data: options.data,
183
+ value: options.value ?? 0n
184
+ };
185
+ }
186
+ /**
187
+ * Send a transaction using Kernel account (execute immediately)
188
+ *
189
+ * For batching multiple operations, use prepareCall() + sendBatchTransaction() instead.
190
+ *
191
+ * @example
192
+ * // Single transaction
193
+ * await aaService.sendTransaction({
194
+ * account,
195
+ * to: recipient,
196
+ * value: parseEther('0.1')
197
+ * });
198
+ *
199
+ * // For batching, use prepareCall instead:
200
+ * const calls = [
201
+ * aaService.prepareCall({ to: recipient1, value: parseEther('0.1') }),
202
+ * aaService.prepareCall({ to: recipient2, value: parseEther('0.2') })
203
+ * ];
204
+ * await aaService.sendBatchTransaction({ account, calls });
205
+ */
206
+ async sendTransaction(options) {
207
+ const { account, to, value = 0n, data = '0x', authorization } = options;
208
+ // If no authorization provided, try to create one
209
+ let auth = authorization;
210
+ if (!auth) {
211
+ auth = await this.createAuthorization({
212
+ owner: account.owner,
213
+ chain: account.chain
214
+ });
215
+ }
216
+ // Send transaction
217
+ const userOpHash = await (0, kernel_account_1.sendKernelTransaction)({
218
+ kernelAccount: account,
219
+ bundlerManager: this.bundlerManager,
220
+ authorization: auth,
221
+ to,
222
+ value,
223
+ data
224
+ });
225
+ return userOpHash;
226
+ }
227
+ /**
228
+ * Wait for transaction receipt
229
+ */
230
+ async waitForReceipt(options) {
231
+ const { userOpHash, chain } = options;
232
+ return await (0, kernel_account_1.waitForKernelReceipt)({
233
+ userOpHash,
234
+ chain,
235
+ bundlerManager: this.bundlerManager
236
+ });
237
+ }
238
+ /**
239
+ * Send transaction and wait for receipt (convenience method)
240
+ */
241
+ async sendTransactionAndWait(options) {
242
+ const userOpHash = await this.sendTransaction(options);
243
+ const receipt = await this.waitForReceipt({
244
+ userOpHash,
245
+ chain: options.account.chain
246
+ });
247
+ return { userOpHash, receipt };
248
+ }
249
+ /**
250
+ * Send batch transaction (RECOMMENDED for smart accounts)
251
+ *
252
+ * Sends multiple calls in a single UserOperation, paying gas ONLY ONCE.
253
+ * This is one of the main advantages of smart accounts over EOAs.
254
+ *
255
+ * Use prepare*() methods to create Call objects for batching:
256
+ * - prepareCall() - for transfers and contract interactions
257
+ * - prepareInstallModule() - for module installations
258
+ * - prepareInstallSessionKey() - for session keys
259
+ * - prepareInstallMultiSigValidator() - for multi-sig
260
+ * - etc.
261
+ *
262
+ * @example
263
+ * // Send ETH to 3 recipients in one transaction
264
+ * const calls = [
265
+ * aaService.prepareCall({ to: '0xRecipient1', value: parseEther('0.01') }),
266
+ * aaService.prepareCall({ to: '0xRecipient2', value: parseEther('0.02') }),
267
+ * aaService.prepareCall({ to: '0xRecipient3', value: parseEther('0.03') })
268
+ * ];
269
+ * await aaService.sendBatchTransaction({ account, calls });
270
+ *
271
+ * @example
272
+ * // Mix transfers, contract calls, and module installations
273
+ * const calls = [
274
+ * aaService.prepareCall({ to: recipient, value: parseEther('0.1') }),
275
+ * aaService.prepareContractCall({ to: USDC, data: transferData }),
276
+ * aaService.prepareInstallSessionKey({ account, sessionKeyAddress, permissions })
277
+ * ];
278
+ * await aaService.sendBatchTransaction({ account, calls });
279
+ *
280
+ * @example
281
+ * // Install multiple modules at once
282
+ * const calls = [
283
+ * aaService.prepareInstallSessionKey({ account, ... }),
284
+ * aaService.prepareInstallMultiSigValidator({ account, ... }),
285
+ * aaService.prepareInstallModule({ account, moduleType: 'hook', ... })
286
+ * ];
287
+ * await aaService.sendBatchTransaction({ account, calls });
288
+ */
289
+ async sendBatchTransaction(options) {
290
+ const { account, calls, authorization } = options;
291
+ if (calls.length === 0) {
292
+ throw new Error('Batch transaction must have at least one call');
293
+ }
294
+ // If no authorization provided, try to create one
295
+ let auth = authorization;
296
+ if (!auth) {
297
+ auth = await this.createAuthorization({
298
+ owner: account.owner,
299
+ chain: account.chain
300
+ });
301
+ }
302
+ // Send batch transaction
303
+ const userOpHash = await (0, kernel_account_1.sendBatchTransaction)({
304
+ kernelAccount: account,
305
+ bundlerManager: this.bundlerManager,
306
+ authorization: auth,
307
+ calls
308
+ });
309
+ return userOpHash;
310
+ }
311
+ /**
312
+ * Send batch transaction and wait for receipt (convenience method)
313
+ *
314
+ * Same as sendBatchTransaction but waits for confirmation.
315
+ */
316
+ async sendBatchTransactionAndWait(options) {
317
+ const userOpHash = await this.sendBatchTransaction(options);
318
+ const receipt = await this.waitForReceipt({
319
+ userOpHash,
320
+ chain: options.account.chain
321
+ });
322
+ return { userOpHash, receipt };
323
+ }
324
+ // ============================================
325
+ // Utility Methods
326
+ // ============================================
327
+ /**
328
+ * Get account balance
329
+ */
330
+ async getBalance(account) {
331
+ const publicClient = this.getPublicClient(account.chain);
332
+ return await publicClient.getBalance({ address: account.address });
333
+ }
334
+ /**
335
+ * Get or create public client for standard RPC calls
336
+ * (bundler clients don't support standard eth_* methods)
337
+ */
338
+ getPublicClient(chain) {
339
+ if (!this.publicClientCache.has(chain.id)) {
340
+ const client = (0, viem_1.createPublicClient)({
341
+ chain,
342
+ transport: (0, viem_1.http)()
343
+ });
344
+ this.publicClientCache.set(chain.id, client);
345
+ }
346
+ return this.publicClientCache.get(chain.id);
347
+ }
348
+ /**
349
+ * Get bundler information
350
+ */
351
+ getBundlerInfo(chain) {
352
+ return {
353
+ provider: this.bundlerManager.getProvider(),
354
+ url: this.bundlerManager.getBundlerUrl(chain)
355
+ };
356
+ }
357
+ /**
358
+ * Get bundler client directly (advanced usage)
359
+ */
360
+ getBundlerClient(chain) {
361
+ return this.bundlerManager.getClient(chain);
362
+ }
363
+ /**
364
+ * Get bundler manager (advanced usage)
365
+ */
366
+ getBundlerManager(chain) {
367
+ return this.bundlerManager;
368
+ }
369
+ /**
370
+ * Clear all caches
371
+ */
372
+ clearCache() {
373
+ this.accountCache.clear();
374
+ this.authorizationCache.clear();
375
+ this.publicClientCache.clear();
376
+ this.bundlerManager.clearCache();
377
+ }
378
+ // ============================================
379
+ // Module Management (ERC-7579)
380
+ // ============================================
381
+ /**
382
+ * Prepare module installation call (for batching)
383
+ *
384
+ * Returns a Call object that can be included in a batch transaction.
385
+ * This allows you to install multiple modules in a single UserOperation.
386
+ *
387
+ * @example
388
+ * // Batch install multiple modules
389
+ * const calls = [
390
+ * aaService.prepareInstallModule({
391
+ * account,
392
+ * moduleType: 'validator',
393
+ * moduleAddress: SESSION_KEY_VALIDATOR
394
+ * }),
395
+ * aaService.prepareInstallModule({
396
+ * account,
397
+ * moduleType: 'hook',
398
+ * moduleAddress: SPENDING_LIMIT_HOOK
399
+ * })
400
+ * ];
401
+ * await aaService.sendBatchTransaction({ account, calls });
402
+ */
403
+ prepareInstallModule(options) {
404
+ return (0, kernel_modules_1.prepareInstallModule)(options);
405
+ }
406
+ /**
407
+ * Install a module on an account (execute immediately)
408
+ *
409
+ * For batching multiple modules, use prepareInstallModule instead.
410
+ *
411
+ * @example
412
+ * // Install a single module
413
+ * await aaService.installModule({
414
+ * account,
415
+ * moduleType: 'validator',
416
+ * moduleAddress: SESSION_KEY_VALIDATOR_ADDRESS,
417
+ * initData: encodedPermissions
418
+ * });
419
+ */
420
+ async installModule(options) {
421
+ return (0, kernel_modules_1.installModule)({
422
+ ...options,
423
+ bundlerManager: this.bundlerManager
424
+ });
425
+ }
426
+ /**
427
+ * Prepare module uninstallation call (for batching)
428
+ *
429
+ * Returns a Call object that can be included in a batch transaction.
430
+ *
431
+ * @example
432
+ * // Batch uninstall multiple modules
433
+ * const calls = [
434
+ * aaService.prepareUninstallModule({ account, moduleType: 'validator', moduleAddress: '0x...' }),
435
+ * aaService.prepareUninstallModule({ account, moduleType: 'hook', moduleAddress: '0x...' })
436
+ * ];
437
+ * await aaService.sendBatchTransaction({ account, calls });
438
+ */
439
+ prepareUninstallModule(options) {
440
+ return (0, kernel_modules_1.prepareUninstallModule)(options);
441
+ }
442
+ /**
443
+ * Uninstall a module from an account (execute immediately)
444
+ *
445
+ * For batching, use prepareUninstallModule instead.
446
+ *
447
+ * @example
448
+ * await aaService.uninstallModule({
449
+ * account,
450
+ * moduleType: 'validator',
451
+ * moduleAddress: SESSION_KEY_VALIDATOR_ADDRESS
452
+ * });
453
+ */
454
+ async uninstallModule(options) {
455
+ return (0, kernel_modules_1.uninstallModule)({
456
+ ...options,
457
+ bundlerManager: this.bundlerManager
458
+ });
459
+ }
460
+ /**
461
+ * Check if a module is installed
462
+ *
463
+ * @example
464
+ * const isInstalled = await aaService.isModuleInstalled({
465
+ * account,
466
+ * moduleType: 'validator',
467
+ * moduleAddress: SESSION_KEY_VALIDATOR_ADDRESS
468
+ * });
469
+ */
470
+ async isModuleInstalled(options) {
471
+ return (0, kernel_modules_1.isModuleInstalled)({
472
+ ...options,
473
+ bundlerManager: this.bundlerManager
474
+ });
475
+ }
476
+ /**
477
+ * Prepare session key installation call (for batching)
478
+ *
479
+ * Returns a Call object that can be batched with other operations.
480
+ *
481
+ * @example
482
+ * // Batch install session key with multi-sig
483
+ * const calls = [
484
+ * aaService.prepareInstallSessionKey({ account, sessionKeyAddress, permissions }),
485
+ * aaService.prepareInstallMultiSigValidator({ account, owners, threshold: 2 })
486
+ * ];
487
+ * await aaService.sendBatchTransaction({ account, calls });
488
+ */
489
+ prepareInstallSessionKey(options) {
490
+ return (0, kernel_modules_1.prepareInstallSessionKey)(options);
491
+ }
492
+ /**
493
+ * Create and install a session key for automated operations (execute immediately)
494
+ *
495
+ * Perfect for use cases like:
496
+ * - Recurring payments
497
+ * - Automated savings
498
+ * - Subscription management
499
+ * - DCA (Dollar Cost Averaging)
500
+ *
501
+ * For batching with other operations, use prepareInstallSessionKey instead.
502
+ *
503
+ * @example
504
+ * // Create session key for monthly savings
505
+ * const sessionKey = privateKeyToAccount('0x...');
506
+ *
507
+ * await aaService.createSessionKey({
508
+ * account,
509
+ * sessionKeyAddress: sessionKey.address,
510
+ * permissions: [{
511
+ * target: USDC_ADDRESS,
512
+ * functionSelector: '0xa9059cbb', // transfer(address,uint256)
513
+ * maxValuePerUse: parseUnits('100', 6), // Max 100 USDC
514
+ * validUntil: Date.now() + 30 * 24 * 60 * 60 * 1000, // 30 days
515
+ * maxUses: 1 // Once per month
516
+ * }]
517
+ * });
518
+ */
519
+ async createSessionKey(options) {
520
+ return (0, kernel_modules_1.createSessionKey)({
521
+ ...options,
522
+ bundlerManager: this.bundlerManager
523
+ });
524
+ }
525
+ /**
526
+ * Prepare session key revocation call (for batching)
527
+ *
528
+ * Returns a Call object that can be batched with other operations.
529
+ *
530
+ * @example
531
+ * // Batch revoke multiple session keys
532
+ * const calls = [
533
+ * aaService.prepareRevokeSessionKey({ account, sessionKeyAddress: key1 }),
534
+ * aaService.prepareRevokeSessionKey({ account, sessionKeyAddress: key2 })
535
+ * ];
536
+ * await aaService.sendBatchTransaction({ account, calls });
537
+ */
538
+ prepareRevokeSessionKey(options) {
539
+ return (0, kernel_modules_1.prepareRevokeSessionKey)(options);
540
+ }
541
+ /**
542
+ * Revoke a session key (execute immediately)
543
+ *
544
+ * For batching, use prepareRevokeSessionKey instead.
545
+ *
546
+ * @example
547
+ * await aaService.revokeSessionKey({
548
+ * account,
549
+ * sessionKeyAddress: sessionKey.address
550
+ * });
551
+ */
552
+ async revokeSessionKey(options) {
553
+ return (0, kernel_modules_1.revokeSessionKey)(options.account, this.bundlerManager, options.sessionKeyAddress);
554
+ }
555
+ /**
556
+ * Prepare multi-sig validator installation call (for batching)
557
+ *
558
+ * Returns a Call object that can be batched with other operations.
559
+ *
560
+ * @example
561
+ * // Batch install multi-sig with session key
562
+ * const calls = [
563
+ * aaService.prepareInstallMultiSigValidator({ account, owners, threshold: 2 }),
564
+ * aaService.prepareInstallSessionKey({ account, sessionKeyAddress, permissions })
565
+ * ];
566
+ * await aaService.sendBatchTransaction({ account, calls });
567
+ */
568
+ prepareInstallMultiSigValidator(options) {
569
+ return (0, kernel_modules_1.prepareInstallMultiSigValidator)(options);
570
+ }
571
+ /**
572
+ * Install a multi-signature validator (execute immediately)
573
+ *
574
+ * For batching, use prepareInstallMultiSigValidator instead.
575
+ *
576
+ * @example
577
+ * await aaService.installMultiSigValidator({
578
+ * account,
579
+ * owners: [owner1, owner2, owner3],
580
+ * threshold: 2 // 2 of 3 required
581
+ * });
582
+ */
583
+ async installMultiSigValidator(options) {
584
+ return (0, kernel_modules_1.installMultiSigValidator)({
585
+ ...options,
586
+ bundlerManager: this.bundlerManager
587
+ });
588
+ }
589
+ // ============================================
590
+ // EIP-7702 Session Keys (NEW Pattern)
591
+ // ============================================
592
+ /**
593
+ * Generate a new session key
594
+ *
595
+ * Creates a new keypair for use as a session key with EIP-7702 accounts.
596
+ * The private key should be stored securely and shared with the agent.
597
+ * The address should be shared with the owner for approval.
598
+ *
599
+ * This uses the NEW EIP-7702 pattern, not the legacy module-based pattern.
600
+ *
601
+ * @returns Session key info including private key, address, and signer
602
+ *
603
+ * @example
604
+ * // Agent generates session key
605
+ * const sessionKey = await aaService.generateSessionKey();
606
+ * console.log("Share this address with owner:", sessionKey.address);
607
+ * console.log("Keep this private key secure:", sessionKey.privateKey);
608
+ * // Store sessionKey.privateKey securely for later use
609
+ */
610
+ async generateSessionKey() {
611
+ return await (0, session_keys_1.generateSessionKey)();
612
+ }
613
+ /**
614
+ * Recreate session key from private key
615
+ *
616
+ * Recreates a session key signer from a stored private key.
617
+ *
618
+ * @param privateKey - The session key private key
619
+ * @returns Session key info
620
+ *
621
+ * @example
622
+ * // Agent recreates session key from storage
623
+ * const sessionKey = await aaService.recreateSessionKey(storedPrivateKey);
624
+ */
625
+ async recreateSessionKey(privateKey) {
626
+ return await (0, session_keys_1.recreateSessionKey)(privateKey);
627
+ }
628
+ /**
629
+ * Create session key approval (Owner side)
630
+ *
631
+ * The owner calls this to create an approval for a session key address.
632
+ * This uses the NEW EIP-7702 pattern with addressToEmptyAccount.
633
+ *
634
+ * @param options - Configuration options
635
+ * @returns Serialized approval string to share with the agent
636
+ *
637
+ * @example
638
+ * // Owner approves session key with USDC transfer restrictions
639
+ * const approval = await aaService.createSessionKeyApproval({
640
+ * sessionKeyAddress: '0x...', // Agent's session key address
641
+ * owner: ownerAccount,
642
+ * chain: sepolia,
643
+ * permissions: [
644
+ * aaService.createUSDCTransferPermission(USDC_ADDRESS, '10') // Max 10 USDC
645
+ * ]
646
+ * });
647
+ * // Share approval with agent
648
+ *
649
+ * @example
650
+ * // Owner approves session key with sudo (unrestricted) access
651
+ * const approval = await aaService.createSessionKeyApproval({
652
+ * sessionKeyAddress: agentSessionKey.address,
653
+ * owner: ownerAccount,
654
+ * chain: sepolia,
655
+ * useSudoPolicy: true
656
+ * });
657
+ */
658
+ async createSessionKeyApproval(options) {
659
+ return await (0, session_keys_1.createSessionKeyApproval)(options);
660
+ }
661
+ /**
662
+ * Deserialize session key account (Agent side)
663
+ *
664
+ * The agent calls this to reconstruct the session key account from the approval.
665
+ * This requires BOTH the approval AND the session key signer.
666
+ *
667
+ * @param options - Deserialization options
668
+ * @returns Deserialized session key account
669
+ *
670
+ * @example
671
+ * // Agent deserializes with private key
672
+ * const sessionKey = await aaService.recreateSessionKey(storedPrivateKey);
673
+ * const account = await aaService.deserializeSessionKey({
674
+ * approval,
675
+ * sessionKeySigner: sessionKey.signer,
676
+ * chain: sepolia
677
+ * });
678
+ */
679
+ async deserializeSessionKey(options) {
680
+ return await (0, session_keys_1.deserializeSessionKey)(options);
681
+ }
682
+ /**
683
+ * Create kernel client for session key
684
+ *
685
+ * Creates a client for sending transactions with the session key.
686
+ *
687
+ * @param options - Client options
688
+ * @returns Kernel account client
689
+ *
690
+ * @example
691
+ * // Agent creates client for session key
692
+ * const sessionKey = await aaService.recreateSessionKey(storedPrivateKey);
693
+ * const account = await aaService.deserializeSessionKey({
694
+ * approval,
695
+ * sessionKeySigner: sessionKey.signer,
696
+ * chain: sepolia
697
+ * });
698
+ * const client = aaService.createSessionKeyClient({
699
+ * account,
700
+ * chain: sepolia,
701
+ * bundlerUrl: 'https://api.pimlico.io/...'
702
+ * });
703
+ */
704
+ createSessionKeyClient(options) {
705
+ return (0, session_keys_1.createSessionKeyClient)(options);
706
+ }
707
+ /**
708
+ * Create USDC transfer permission rule
709
+ *
710
+ * Helper to create a permission rule for USDC transfers with a maximum amount.
711
+ *
712
+ * @param usdcAddress - USDC contract address
713
+ * @param maxAmount - Maximum USDC amount (in USDC units, e.g., "10" for 10 USDC)
714
+ * @returns Permission rule
715
+ *
716
+ * @example
717
+ * const rule = aaService.createUSDCTransferPermission(
718
+ * '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', // Sepolia USDC
719
+ * '10' // Max 10 USDC
720
+ * );
721
+ */
722
+ createUSDCTransferPermission(usdcAddress, maxAmount) {
723
+ return (0, session_keys_1.createUSDCTransferPermission)(usdcAddress, maxAmount);
724
+ }
725
+ /**
726
+ * Create ETH transfer permission rule
727
+ *
728
+ * Helper to create a permission rule for ETH transfers with a maximum value.
729
+ *
730
+ * @param maxValue - Maximum ETH value (in ether units, e.g., "0.1" for 0.1 ETH)
731
+ * @returns Permission rule
732
+ *
733
+ * @example
734
+ * const rule = aaService.createETHTransferPermission('0.1'); // Max 0.1 ETH
735
+ */
736
+ createETHTransferPermission(maxValue) {
737
+ return (0, session_keys_1.createETHTransferPermission)(maxValue);
738
+ }
739
+ // ============================================
740
+ // Private Helpers
741
+ // ============================================
742
+ getAccountCacheKey(chain, owner, entryPointVersion) {
743
+ return `${chain.id}-${owner.address}-${entryPointVersion}`;
744
+ }
745
+ getAuthorizationCacheKey(chain, owner) {
746
+ return `${chain.id}-${owner.address}`;
747
+ }
748
+ }
749
+ exports.AccountAbstractionService = AccountAbstractionService;
750
+ // ============================================
751
+ // Convenience Exports
752
+ // ============================================
753
+ exports.default = AccountAbstractionService;
754
+ //# sourceMappingURL=account-abstraction.js.map