@deserialize/multi-vm-wallet 1.2.441 → 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.
- package/.claude/settings.local.json +12 -0
- package/SMART_WALLET_GUIDE.md +746 -0
- package/SMART_WALLET_IMPLEMENTATION.md +460 -0
- package/dist/IChainWallet.d.ts +3 -3
- package/dist/IChainWallet.js +5 -0
- package/dist/IChainWallet.js.map +1 -1
- package/dist/evm/SMART_WALLET_EXAMPLES.d.ts +20 -0
- package/dist/evm/SMART_WALLET_EXAMPLES.js +451 -0
- package/dist/evm/SMART_WALLET_EXAMPLES.js.map +1 -0
- package/dist/evm/aa-service/index.d.ts +16 -0
- package/dist/evm/aa-service/index.js +69 -0
- package/dist/evm/aa-service/index.js.map +1 -0
- package/dist/evm/aa-service/lib/account-adapter.d.ts +26 -0
- package/dist/evm/aa-service/lib/account-adapter.js +53 -0
- package/dist/evm/aa-service/lib/account-adapter.js.map +1 -0
- package/dist/evm/aa-service/lib/kernel-account.d.ts +91 -0
- package/dist/evm/aa-service/lib/kernel-account.js +251 -0
- package/dist/evm/aa-service/lib/kernel-account.js.map +1 -0
- package/dist/evm/aa-service/lib/kernel-modules.d.ts +240 -0
- package/dist/evm/aa-service/lib/kernel-modules.js +409 -0
- package/dist/evm/aa-service/lib/kernel-modules.js.map +1 -0
- package/dist/evm/aa-service/lib/session-keys.d.ts +170 -0
- package/dist/evm/aa-service/lib/session-keys.js +297 -0
- package/dist/evm/aa-service/lib/session-keys.js.map +1 -0
- package/dist/evm/aa-service/lib/type.d.ts +167 -0
- package/dist/evm/aa-service/lib/type.js +43 -0
- package/dist/evm/aa-service/lib/type.js.map +1 -0
- package/dist/evm/aa-service/services/account-abstraction.d.ts +614 -0
- package/dist/evm/aa-service/services/account-abstraction.js +754 -0
- package/dist/evm/aa-service/services/account-abstraction.js.map +1 -0
- package/dist/evm/aa-service/services/bundler.d.ts +29 -0
- package/dist/evm/aa-service/services/bundler.js +168 -0
- package/dist/evm/aa-service/services/bundler.js.map +1 -0
- package/dist/evm/evm.d.ts +67 -3
- package/dist/evm/evm.js +212 -7
- package/dist/evm/evm.js.map +1 -1
- package/dist/evm/index.d.ts +1 -0
- package/dist/evm/index.js +3 -0
- package/dist/evm/index.js.map +1 -1
- package/dist/evm/smartWallet.d.ts +265 -0
- package/dist/evm/smartWallet.js +675 -0
- package/dist/evm/smartWallet.js.map +1 -0
- package/dist/evm/smartWallet.types.d.ts +10 -0
- package/dist/evm/smartWallet.types.js +16 -0
- package/dist/evm/smartWallet.types.js.map +1 -0
- package/dist/evm/transaction.utils.d.ts +10 -10
- package/dist/evm/transaction.utils.js +12 -8
- package/dist/evm/transaction.utils.js.map +1 -1
- package/dist/evm/transactionParsing.js +77 -1
- package/dist/evm/transactionParsing.js.map +1 -1
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.js +15 -0
- package/dist/helpers/index.js.map +1 -1
- package/dist/helpers/routeScan.d.ts +191 -0
- package/dist/helpers/routeScan.js +114 -0
- package/dist/helpers/routeScan.js.map +1 -0
- package/dist/index.d.ts +0 -2
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/svm/svm.d.ts +4 -3
- package/dist/svm/svm.js +29 -18
- package/dist/svm/svm.js.map +1 -1
- package/dist/svm/transactionSender.js +2 -2
- package/dist/svm/transactionSender.js.map +1 -1
- package/dist/svm/utils.d.ts +4 -3
- package/dist/svm/utils.js +19 -6
- package/dist/svm/utils.js.map +1 -1
- package/dist/test.js +7 -0
- package/dist/test.js.map +1 -1
- package/dist/types.d.ts +19 -2
- package/dist/types.js.map +1 -1
- package/dist/vm.js +9 -7
- package/dist/vm.js.map +1 -1
- package/package.json +2 -2
- package/tsconfig.json +4 -3
- package/utils/IChainWallet.ts +3 -3
- package/utils/evm/SMART_WALLET_EXAMPLES.ts.bak +591 -0
- package/utils/evm/aa-service/index.ts +85 -0
- package/utils/evm/aa-service/lib/account-adapter.ts +60 -0
- package/utils/evm/aa-service/lib/kernel-account.ts +367 -0
- package/utils/evm/aa-service/lib/kernel-modules.ts +598 -0
- package/utils/evm/aa-service/lib/session-keys.ts +389 -0
- package/utils/evm/aa-service/lib/type.ts +236 -0
- package/utils/evm/aa-service/services/account-abstraction.ts +1015 -0
- package/utils/evm/aa-service/services/bundler.ts +217 -0
- package/utils/evm/evm.ts +268 -11
- package/utils/evm/index.ts +5 -1
- package/utils/evm/smartWallet.ts +797 -0
- package/utils/evm/smartWallet.types.ts +33 -0
- package/utils/evm/transaction.utils.ts +12 -10
- package/utils/evm/transactionParsing.ts +100 -14
- package/utils/helpers/index.ts +1 -0
- package/utils/helpers/routeScan.ts +397 -0
- package/utils/index.ts +0 -2
- package/utils/svm/svm.ts +50 -9
- package/utils/svm/utils.ts +52 -7
- package/utils/test.ts +7 -0
- package/utils/types.ts +24 -2
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Account Abstraction Service (Singleton)
|
|
3
|
+
*
|
|
4
|
+
* Centralized service for managing Kernel accounts, bundlers, and transactions.
|
|
5
|
+
* Use this singleton across your application for consistent AA operations.
|
|
6
|
+
*
|
|
7
|
+
* Usage:
|
|
8
|
+
* const aaService = AccountAbstractionService.getInstance({
|
|
9
|
+
* bundlerProvider: 'pimlico',
|
|
10
|
+
* apiKey: env.pimlicoApiKey
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* const account = await aaService.createAccount(sepolia, owner);
|
|
14
|
+
* const txHash = await aaService.sendTransaction({ account, to, value });
|
|
15
|
+
*/
|
|
16
|
+
import { Chain, Hex } from 'viem';
|
|
17
|
+
import { PrivateKeyAccount } from 'viem/accounts';
|
|
18
|
+
import { SignAuthorizationReturnType } from 'viem';
|
|
19
|
+
import { BundlerManager } from './bundler';
|
|
20
|
+
import { KernelAccountInstance, EntryPointVersion, Call } from '../lib/kernel-account';
|
|
21
|
+
import { ModuleType, SessionKeyPermission } from '../lib/kernel-modules';
|
|
22
|
+
import { SessionKeyInfo, SessionKeyPermissionRule } from '../lib/session-keys';
|
|
23
|
+
import { ModularSigner } from '@zerodev/permissions';
|
|
24
|
+
export interface AAServiceConfig {
|
|
25
|
+
bundlerProvider: 'pimlico' | 'etherspot' | 'custom';
|
|
26
|
+
apiKey?: string;
|
|
27
|
+
customBundlerUrl?: string;
|
|
28
|
+
}
|
|
29
|
+
export interface CreateAccountOptions {
|
|
30
|
+
chain: Chain;
|
|
31
|
+
owner: PrivateKeyAccount;
|
|
32
|
+
entryPointVersion?: EntryPointVersion;
|
|
33
|
+
}
|
|
34
|
+
export interface SendTransactionOptions {
|
|
35
|
+
account: KernelAccountInstance;
|
|
36
|
+
to: Hex;
|
|
37
|
+
value?: bigint;
|
|
38
|
+
data?: Hex;
|
|
39
|
+
authorization?: SignAuthorizationReturnType;
|
|
40
|
+
}
|
|
41
|
+
export interface SendBatchTransactionOptions {
|
|
42
|
+
account: KernelAccountInstance;
|
|
43
|
+
calls: Call[];
|
|
44
|
+
authorization?: SignAuthorizationReturnType;
|
|
45
|
+
}
|
|
46
|
+
export interface WaitForReceiptOptions {
|
|
47
|
+
userOpHash: Hex;
|
|
48
|
+
chain: Chain;
|
|
49
|
+
}
|
|
50
|
+
export declare class AccountAbstractionService {
|
|
51
|
+
private static instance;
|
|
52
|
+
private bundlerManager;
|
|
53
|
+
private accountCache;
|
|
54
|
+
private authorizationCache;
|
|
55
|
+
private publicClientCache;
|
|
56
|
+
/**
|
|
57
|
+
* Private constructor (singleton pattern)
|
|
58
|
+
*/
|
|
59
|
+
private constructor();
|
|
60
|
+
/**
|
|
61
|
+
* Get singleton instance
|
|
62
|
+
*/
|
|
63
|
+
static getInstance(config?: AAServiceConfig): AccountAbstractionService;
|
|
64
|
+
/**
|
|
65
|
+
* Reset singleton instance (useful for testing or reconfiguration)
|
|
66
|
+
*/
|
|
67
|
+
static reset(): void;
|
|
68
|
+
/**
|
|
69
|
+
* Update bundler configuration (creates new bundler manager)
|
|
70
|
+
*/
|
|
71
|
+
updateBundlerConfig(config: AAServiceConfig): void;
|
|
72
|
+
/**
|
|
73
|
+
* Create a Kernel 7702 account
|
|
74
|
+
*/
|
|
75
|
+
createAccount(options: CreateAccountOptions): Promise<KernelAccountInstance>;
|
|
76
|
+
/**
|
|
77
|
+
* Get cached account (if exists)
|
|
78
|
+
*/
|
|
79
|
+
getCachedAccount(chain: Chain, owner: PrivateKeyAccount, entryPointVersion?: EntryPointVersion): KernelAccountInstance | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Check if account is already delegated to Kernel
|
|
82
|
+
*/
|
|
83
|
+
isAccountDelegated(owner: PrivateKeyAccount, chain: Chain): Promise<boolean>;
|
|
84
|
+
/**
|
|
85
|
+
* Create EIP-7702 authorization (if needed)
|
|
86
|
+
*/
|
|
87
|
+
createAuthorization(options: {
|
|
88
|
+
owner: PrivateKeyAccount;
|
|
89
|
+
chain: Chain;
|
|
90
|
+
}): Promise<SignAuthorizationReturnType | undefined>;
|
|
91
|
+
/**
|
|
92
|
+
* Prepare a call (for batching)
|
|
93
|
+
*
|
|
94
|
+
* Returns a Call object that can be included in a batch transaction.
|
|
95
|
+
* Use this to prepare any transfer or contract interaction for batching.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* // Prepare multiple calls
|
|
99
|
+
* const calls = [
|
|
100
|
+
* aaService.prepareCall({ to: recipient1, value: parseEther('0.1') }),
|
|
101
|
+
* aaService.prepareCall({ to: recipient2, value: parseEther('0.2') }),
|
|
102
|
+
* aaService.prepareCall({ to: contractAddress, data: encodedData })
|
|
103
|
+
* ];
|
|
104
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
105
|
+
*/
|
|
106
|
+
prepareCall(options: {
|
|
107
|
+
to: Hex;
|
|
108
|
+
value?: bigint;
|
|
109
|
+
data?: Hex;
|
|
110
|
+
}): Call;
|
|
111
|
+
/**
|
|
112
|
+
* Prepare a contract call (for batching)
|
|
113
|
+
*
|
|
114
|
+
* Helper for preparing contract interactions with type-safe encoding.
|
|
115
|
+
*
|
|
116
|
+
* @example
|
|
117
|
+
* import { parseAbi, encodeFunctionData } from 'viem';
|
|
118
|
+
*
|
|
119
|
+
* const call = aaService.prepareContractCall({
|
|
120
|
+
* to: USDC_ADDRESS,
|
|
121
|
+
* data: encodeFunctionData({
|
|
122
|
+
* abi: parseAbi(['function transfer(address to, uint256 amount)']),
|
|
123
|
+
* functionName: 'transfer',
|
|
124
|
+
* args: [recipient, parseUnits('100', 6)]
|
|
125
|
+
* })
|
|
126
|
+
* });
|
|
127
|
+
*/
|
|
128
|
+
prepareContractCall(options: {
|
|
129
|
+
to: Hex;
|
|
130
|
+
data: Hex;
|
|
131
|
+
value?: bigint;
|
|
132
|
+
}): Call;
|
|
133
|
+
/**
|
|
134
|
+
* Send a transaction using Kernel account (execute immediately)
|
|
135
|
+
*
|
|
136
|
+
* For batching multiple operations, use prepareCall() + sendBatchTransaction() instead.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* // Single transaction
|
|
140
|
+
* await aaService.sendTransaction({
|
|
141
|
+
* account,
|
|
142
|
+
* to: recipient,
|
|
143
|
+
* value: parseEther('0.1')
|
|
144
|
+
* });
|
|
145
|
+
*
|
|
146
|
+
* // For batching, use prepareCall instead:
|
|
147
|
+
* const calls = [
|
|
148
|
+
* aaService.prepareCall({ to: recipient1, value: parseEther('0.1') }),
|
|
149
|
+
* aaService.prepareCall({ to: recipient2, value: parseEther('0.2') })
|
|
150
|
+
* ];
|
|
151
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
152
|
+
*/
|
|
153
|
+
sendTransaction(options: SendTransactionOptions): Promise<Hex>;
|
|
154
|
+
/**
|
|
155
|
+
* Wait for transaction receipt
|
|
156
|
+
*/
|
|
157
|
+
waitForReceipt(options: WaitForReceiptOptions): Promise<any>;
|
|
158
|
+
/**
|
|
159
|
+
* Send transaction and wait for receipt (convenience method)
|
|
160
|
+
*/
|
|
161
|
+
sendTransactionAndWait(options: SendTransactionOptions): Promise<{
|
|
162
|
+
userOpHash: Hex;
|
|
163
|
+
receipt: any;
|
|
164
|
+
}>;
|
|
165
|
+
/**
|
|
166
|
+
* Send batch transaction (RECOMMENDED for smart accounts)
|
|
167
|
+
*
|
|
168
|
+
* Sends multiple calls in a single UserOperation, paying gas ONLY ONCE.
|
|
169
|
+
* This is one of the main advantages of smart accounts over EOAs.
|
|
170
|
+
*
|
|
171
|
+
* Use prepare*() methods to create Call objects for batching:
|
|
172
|
+
* - prepareCall() - for transfers and contract interactions
|
|
173
|
+
* - prepareInstallModule() - for module installations
|
|
174
|
+
* - prepareInstallSessionKey() - for session keys
|
|
175
|
+
* - prepareInstallMultiSigValidator() - for multi-sig
|
|
176
|
+
* - etc.
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* // Send ETH to 3 recipients in one transaction
|
|
180
|
+
* const calls = [
|
|
181
|
+
* aaService.prepareCall({ to: '0xRecipient1', value: parseEther('0.01') }),
|
|
182
|
+
* aaService.prepareCall({ to: '0xRecipient2', value: parseEther('0.02') }),
|
|
183
|
+
* aaService.prepareCall({ to: '0xRecipient3', value: parseEther('0.03') })
|
|
184
|
+
* ];
|
|
185
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
186
|
+
*
|
|
187
|
+
* @example
|
|
188
|
+
* // Mix transfers, contract calls, and module installations
|
|
189
|
+
* const calls = [
|
|
190
|
+
* aaService.prepareCall({ to: recipient, value: parseEther('0.1') }),
|
|
191
|
+
* aaService.prepareContractCall({ to: USDC, data: transferData }),
|
|
192
|
+
* aaService.prepareInstallSessionKey({ account, sessionKeyAddress, permissions })
|
|
193
|
+
* ];
|
|
194
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
195
|
+
*
|
|
196
|
+
* @example
|
|
197
|
+
* // Install multiple modules at once
|
|
198
|
+
* const calls = [
|
|
199
|
+
* aaService.prepareInstallSessionKey({ account, ... }),
|
|
200
|
+
* aaService.prepareInstallMultiSigValidator({ account, ... }),
|
|
201
|
+
* aaService.prepareInstallModule({ account, moduleType: 'hook', ... })
|
|
202
|
+
* ];
|
|
203
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
204
|
+
*/
|
|
205
|
+
sendBatchTransaction(options: SendBatchTransactionOptions): Promise<Hex>;
|
|
206
|
+
/**
|
|
207
|
+
* Send batch transaction and wait for receipt (convenience method)
|
|
208
|
+
*
|
|
209
|
+
* Same as sendBatchTransaction but waits for confirmation.
|
|
210
|
+
*/
|
|
211
|
+
sendBatchTransactionAndWait(options: SendBatchTransactionOptions): Promise<{
|
|
212
|
+
userOpHash: Hex;
|
|
213
|
+
receipt: any;
|
|
214
|
+
}>;
|
|
215
|
+
/**
|
|
216
|
+
* Get account balance
|
|
217
|
+
*/
|
|
218
|
+
getBalance(account: KernelAccountInstance): Promise<bigint>;
|
|
219
|
+
/**
|
|
220
|
+
* Get or create public client for standard RPC calls
|
|
221
|
+
* (bundler clients don't support standard eth_* methods)
|
|
222
|
+
*/
|
|
223
|
+
private getPublicClient;
|
|
224
|
+
/**
|
|
225
|
+
* Get bundler information
|
|
226
|
+
*/
|
|
227
|
+
getBundlerInfo(chain: Chain): {
|
|
228
|
+
provider: string;
|
|
229
|
+
url: string;
|
|
230
|
+
};
|
|
231
|
+
/**
|
|
232
|
+
* Get bundler client directly (advanced usage)
|
|
233
|
+
*/
|
|
234
|
+
getBundlerClient(chain: Chain): any;
|
|
235
|
+
/**
|
|
236
|
+
* Get bundler manager (advanced usage)
|
|
237
|
+
*/
|
|
238
|
+
getBundlerManager(chain: Chain): BundlerManager;
|
|
239
|
+
/**
|
|
240
|
+
* Clear all caches
|
|
241
|
+
*/
|
|
242
|
+
clearCache(): void;
|
|
243
|
+
/**
|
|
244
|
+
* Prepare module installation call (for batching)
|
|
245
|
+
*
|
|
246
|
+
* Returns a Call object that can be included in a batch transaction.
|
|
247
|
+
* This allows you to install multiple modules in a single UserOperation.
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* // Batch install multiple modules
|
|
251
|
+
* const calls = [
|
|
252
|
+
* aaService.prepareInstallModule({
|
|
253
|
+
* account,
|
|
254
|
+
* moduleType: 'validator',
|
|
255
|
+
* moduleAddress: SESSION_KEY_VALIDATOR
|
|
256
|
+
* }),
|
|
257
|
+
* aaService.prepareInstallModule({
|
|
258
|
+
* account,
|
|
259
|
+
* moduleType: 'hook',
|
|
260
|
+
* moduleAddress: SPENDING_LIMIT_HOOK
|
|
261
|
+
* })
|
|
262
|
+
* ];
|
|
263
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
264
|
+
*/
|
|
265
|
+
prepareInstallModule(options: {
|
|
266
|
+
account: KernelAccountInstance;
|
|
267
|
+
moduleType: ModuleType;
|
|
268
|
+
moduleAddress: Hex;
|
|
269
|
+
initData?: Hex;
|
|
270
|
+
}): Call;
|
|
271
|
+
/**
|
|
272
|
+
* Install a module on an account (execute immediately)
|
|
273
|
+
*
|
|
274
|
+
* For batching multiple modules, use prepareInstallModule instead.
|
|
275
|
+
*
|
|
276
|
+
* @example
|
|
277
|
+
* // Install a single module
|
|
278
|
+
* await aaService.installModule({
|
|
279
|
+
* account,
|
|
280
|
+
* moduleType: 'validator',
|
|
281
|
+
* moduleAddress: SESSION_KEY_VALIDATOR_ADDRESS,
|
|
282
|
+
* initData: encodedPermissions
|
|
283
|
+
* });
|
|
284
|
+
*/
|
|
285
|
+
installModule(options: {
|
|
286
|
+
account: KernelAccountInstance;
|
|
287
|
+
moduleType: ModuleType;
|
|
288
|
+
moduleAddress: Hex;
|
|
289
|
+
initData?: Hex;
|
|
290
|
+
}): Promise<Hex>;
|
|
291
|
+
/**
|
|
292
|
+
* Prepare module uninstallation call (for batching)
|
|
293
|
+
*
|
|
294
|
+
* Returns a Call object that can be included in a batch transaction.
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* // Batch uninstall multiple modules
|
|
298
|
+
* const calls = [
|
|
299
|
+
* aaService.prepareUninstallModule({ account, moduleType: 'validator', moduleAddress: '0x...' }),
|
|
300
|
+
* aaService.prepareUninstallModule({ account, moduleType: 'hook', moduleAddress: '0x...' })
|
|
301
|
+
* ];
|
|
302
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
303
|
+
*/
|
|
304
|
+
prepareUninstallModule(options: {
|
|
305
|
+
account: KernelAccountInstance;
|
|
306
|
+
moduleType: ModuleType;
|
|
307
|
+
moduleAddress: Hex;
|
|
308
|
+
deInitData?: Hex;
|
|
309
|
+
}): Call;
|
|
310
|
+
/**
|
|
311
|
+
* Uninstall a module from an account (execute immediately)
|
|
312
|
+
*
|
|
313
|
+
* For batching, use prepareUninstallModule instead.
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* await aaService.uninstallModule({
|
|
317
|
+
* account,
|
|
318
|
+
* moduleType: 'validator',
|
|
319
|
+
* moduleAddress: SESSION_KEY_VALIDATOR_ADDRESS
|
|
320
|
+
* });
|
|
321
|
+
*/
|
|
322
|
+
uninstallModule(options: {
|
|
323
|
+
account: KernelAccountInstance;
|
|
324
|
+
moduleType: ModuleType;
|
|
325
|
+
moduleAddress: Hex;
|
|
326
|
+
deInitData?: Hex;
|
|
327
|
+
}): Promise<Hex>;
|
|
328
|
+
/**
|
|
329
|
+
* Check if a module is installed
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* const isInstalled = await aaService.isModuleInstalled({
|
|
333
|
+
* account,
|
|
334
|
+
* moduleType: 'validator',
|
|
335
|
+
* moduleAddress: SESSION_KEY_VALIDATOR_ADDRESS
|
|
336
|
+
* });
|
|
337
|
+
*/
|
|
338
|
+
isModuleInstalled(options: {
|
|
339
|
+
account: KernelAccountInstance;
|
|
340
|
+
moduleType: ModuleType;
|
|
341
|
+
moduleAddress: Hex;
|
|
342
|
+
}): Promise<boolean>;
|
|
343
|
+
/**
|
|
344
|
+
* Prepare session key installation call (for batching)
|
|
345
|
+
*
|
|
346
|
+
* Returns a Call object that can be batched with other operations.
|
|
347
|
+
*
|
|
348
|
+
* @example
|
|
349
|
+
* // Batch install session key with multi-sig
|
|
350
|
+
* const calls = [
|
|
351
|
+
* aaService.prepareInstallSessionKey({ account, sessionKeyAddress, permissions }),
|
|
352
|
+
* aaService.prepareInstallMultiSigValidator({ account, owners, threshold: 2 })
|
|
353
|
+
* ];
|
|
354
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
355
|
+
*/
|
|
356
|
+
prepareInstallSessionKey(options: {
|
|
357
|
+
account: KernelAccountInstance;
|
|
358
|
+
sessionKeyAddress: Hex;
|
|
359
|
+
permissions: SessionKeyPermission[];
|
|
360
|
+
}): Call;
|
|
361
|
+
/**
|
|
362
|
+
* Create and install a session key for automated operations (execute immediately)
|
|
363
|
+
*
|
|
364
|
+
* Perfect for use cases like:
|
|
365
|
+
* - Recurring payments
|
|
366
|
+
* - Automated savings
|
|
367
|
+
* - Subscription management
|
|
368
|
+
* - DCA (Dollar Cost Averaging)
|
|
369
|
+
*
|
|
370
|
+
* For batching with other operations, use prepareInstallSessionKey instead.
|
|
371
|
+
*
|
|
372
|
+
* @example
|
|
373
|
+
* // Create session key for monthly savings
|
|
374
|
+
* const sessionKey = privateKeyToAccount('0x...');
|
|
375
|
+
*
|
|
376
|
+
* await aaService.createSessionKey({
|
|
377
|
+
* account,
|
|
378
|
+
* sessionKeyAddress: sessionKey.address,
|
|
379
|
+
* permissions: [{
|
|
380
|
+
* target: USDC_ADDRESS,
|
|
381
|
+
* functionSelector: '0xa9059cbb', // transfer(address,uint256)
|
|
382
|
+
* maxValuePerUse: parseUnits('100', 6), // Max 100 USDC
|
|
383
|
+
* validUntil: Date.now() + 30 * 24 * 60 * 60 * 1000, // 30 days
|
|
384
|
+
* maxUses: 1 // Once per month
|
|
385
|
+
* }]
|
|
386
|
+
* });
|
|
387
|
+
*/
|
|
388
|
+
createSessionKey(options: {
|
|
389
|
+
account: KernelAccountInstance;
|
|
390
|
+
sessionKeyAddress: Hex;
|
|
391
|
+
permissions: SessionKeyPermission[];
|
|
392
|
+
}): Promise<Hex>;
|
|
393
|
+
/**
|
|
394
|
+
* Prepare session key revocation call (for batching)
|
|
395
|
+
*
|
|
396
|
+
* Returns a Call object that can be batched with other operations.
|
|
397
|
+
*
|
|
398
|
+
* @example
|
|
399
|
+
* // Batch revoke multiple session keys
|
|
400
|
+
* const calls = [
|
|
401
|
+
* aaService.prepareRevokeSessionKey({ account, sessionKeyAddress: key1 }),
|
|
402
|
+
* aaService.prepareRevokeSessionKey({ account, sessionKeyAddress: key2 })
|
|
403
|
+
* ];
|
|
404
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
405
|
+
*/
|
|
406
|
+
prepareRevokeSessionKey(options: {
|
|
407
|
+
account: KernelAccountInstance;
|
|
408
|
+
sessionKeyAddress: Hex;
|
|
409
|
+
}): Call;
|
|
410
|
+
/**
|
|
411
|
+
* Revoke a session key (execute immediately)
|
|
412
|
+
*
|
|
413
|
+
* For batching, use prepareRevokeSessionKey instead.
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* await aaService.revokeSessionKey({
|
|
417
|
+
* account,
|
|
418
|
+
* sessionKeyAddress: sessionKey.address
|
|
419
|
+
* });
|
|
420
|
+
*/
|
|
421
|
+
revokeSessionKey(options: {
|
|
422
|
+
account: KernelAccountInstance;
|
|
423
|
+
sessionKeyAddress: Hex;
|
|
424
|
+
}): Promise<Hex>;
|
|
425
|
+
/**
|
|
426
|
+
* Prepare multi-sig validator installation call (for batching)
|
|
427
|
+
*
|
|
428
|
+
* Returns a Call object that can be batched with other operations.
|
|
429
|
+
*
|
|
430
|
+
* @example
|
|
431
|
+
* // Batch install multi-sig with session key
|
|
432
|
+
* const calls = [
|
|
433
|
+
* aaService.prepareInstallMultiSigValidator({ account, owners, threshold: 2 }),
|
|
434
|
+
* aaService.prepareInstallSessionKey({ account, sessionKeyAddress, permissions })
|
|
435
|
+
* ];
|
|
436
|
+
* await aaService.sendBatchTransaction({ account, calls });
|
|
437
|
+
*/
|
|
438
|
+
prepareInstallMultiSigValidator(options: {
|
|
439
|
+
account: KernelAccountInstance;
|
|
440
|
+
owners: Hex[];
|
|
441
|
+
threshold: number;
|
|
442
|
+
}): Call;
|
|
443
|
+
/**
|
|
444
|
+
* Install a multi-signature validator (execute immediately)
|
|
445
|
+
*
|
|
446
|
+
* For batching, use prepareInstallMultiSigValidator instead.
|
|
447
|
+
*
|
|
448
|
+
* @example
|
|
449
|
+
* await aaService.installMultiSigValidator({
|
|
450
|
+
* account,
|
|
451
|
+
* owners: [owner1, owner2, owner3],
|
|
452
|
+
* threshold: 2 // 2 of 3 required
|
|
453
|
+
* });
|
|
454
|
+
*/
|
|
455
|
+
installMultiSigValidator(options: {
|
|
456
|
+
account: KernelAccountInstance;
|
|
457
|
+
owners: Hex[];
|
|
458
|
+
threshold: number;
|
|
459
|
+
}): Promise<Hex>;
|
|
460
|
+
/**
|
|
461
|
+
* Generate a new session key
|
|
462
|
+
*
|
|
463
|
+
* Creates a new keypair for use as a session key with EIP-7702 accounts.
|
|
464
|
+
* The private key should be stored securely and shared with the agent.
|
|
465
|
+
* The address should be shared with the owner for approval.
|
|
466
|
+
*
|
|
467
|
+
* This uses the NEW EIP-7702 pattern, not the legacy module-based pattern.
|
|
468
|
+
*
|
|
469
|
+
* @returns Session key info including private key, address, and signer
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* // Agent generates session key
|
|
473
|
+
* const sessionKey = await aaService.generateSessionKey();
|
|
474
|
+
* console.log("Share this address with owner:", sessionKey.address);
|
|
475
|
+
* console.log("Keep this private key secure:", sessionKey.privateKey);
|
|
476
|
+
* // Store sessionKey.privateKey securely for later use
|
|
477
|
+
*/
|
|
478
|
+
generateSessionKey(): Promise<SessionKeyInfo>;
|
|
479
|
+
/**
|
|
480
|
+
* Recreate session key from private key
|
|
481
|
+
*
|
|
482
|
+
* Recreates a session key signer from a stored private key.
|
|
483
|
+
*
|
|
484
|
+
* @param privateKey - The session key private key
|
|
485
|
+
* @returns Session key info
|
|
486
|
+
*
|
|
487
|
+
* @example
|
|
488
|
+
* // Agent recreates session key from storage
|
|
489
|
+
* const sessionKey = await aaService.recreateSessionKey(storedPrivateKey);
|
|
490
|
+
*/
|
|
491
|
+
recreateSessionKey(privateKey: Hex): Promise<SessionKeyInfo>;
|
|
492
|
+
/**
|
|
493
|
+
* Create session key approval (Owner side)
|
|
494
|
+
*
|
|
495
|
+
* The owner calls this to create an approval for a session key address.
|
|
496
|
+
* This uses the NEW EIP-7702 pattern with addressToEmptyAccount.
|
|
497
|
+
*
|
|
498
|
+
* @param options - Configuration options
|
|
499
|
+
* @returns Serialized approval string to share with the agent
|
|
500
|
+
*
|
|
501
|
+
* @example
|
|
502
|
+
* // Owner approves session key with USDC transfer restrictions
|
|
503
|
+
* const approval = await aaService.createSessionKeyApproval({
|
|
504
|
+
* sessionKeyAddress: '0x...', // Agent's session key address
|
|
505
|
+
* owner: ownerAccount,
|
|
506
|
+
* chain: sepolia,
|
|
507
|
+
* permissions: [
|
|
508
|
+
* aaService.createUSDCTransferPermission(USDC_ADDRESS, '10') // Max 10 USDC
|
|
509
|
+
* ]
|
|
510
|
+
* });
|
|
511
|
+
* // Share approval with agent
|
|
512
|
+
*
|
|
513
|
+
* @example
|
|
514
|
+
* // Owner approves session key with sudo (unrestricted) access
|
|
515
|
+
* const approval = await aaService.createSessionKeyApproval({
|
|
516
|
+
* sessionKeyAddress: agentSessionKey.address,
|
|
517
|
+
* owner: ownerAccount,
|
|
518
|
+
* chain: sepolia,
|
|
519
|
+
* useSudoPolicy: true
|
|
520
|
+
* });
|
|
521
|
+
*/
|
|
522
|
+
createSessionKeyApproval(options: {
|
|
523
|
+
sessionKeyAddress: Hex;
|
|
524
|
+
owner: PrivateKeyAccount;
|
|
525
|
+
chain: Chain;
|
|
526
|
+
entryPointVersion?: '0.6' | '0.7';
|
|
527
|
+
useSudoPolicy?: boolean;
|
|
528
|
+
permissions?: SessionKeyPermissionRule[];
|
|
529
|
+
}): Promise<string>;
|
|
530
|
+
/**
|
|
531
|
+
* Deserialize session key account (Agent side)
|
|
532
|
+
*
|
|
533
|
+
* The agent calls this to reconstruct the session key account from the approval.
|
|
534
|
+
* This requires BOTH the approval AND the session key signer.
|
|
535
|
+
*
|
|
536
|
+
* @param options - Deserialization options
|
|
537
|
+
* @returns Deserialized session key account
|
|
538
|
+
*
|
|
539
|
+
* @example
|
|
540
|
+
* // Agent deserializes with private key
|
|
541
|
+
* const sessionKey = await aaService.recreateSessionKey(storedPrivateKey);
|
|
542
|
+
* const account = await aaService.deserializeSessionKey({
|
|
543
|
+
* approval,
|
|
544
|
+
* sessionKeySigner: sessionKey.signer,
|
|
545
|
+
* chain: sepolia
|
|
546
|
+
* });
|
|
547
|
+
*/
|
|
548
|
+
deserializeSessionKey(options: {
|
|
549
|
+
approval: string;
|
|
550
|
+
sessionKeySigner: ModularSigner;
|
|
551
|
+
chain: Chain;
|
|
552
|
+
entryPointVersion?: '0.6' | '0.7';
|
|
553
|
+
}): Promise<any>;
|
|
554
|
+
/**
|
|
555
|
+
* Create kernel client for session key
|
|
556
|
+
*
|
|
557
|
+
* Creates a client for sending transactions with the session key.
|
|
558
|
+
*
|
|
559
|
+
* @param options - Client options
|
|
560
|
+
* @returns Kernel account client
|
|
561
|
+
*
|
|
562
|
+
* @example
|
|
563
|
+
* // Agent creates client for session key
|
|
564
|
+
* const sessionKey = await aaService.recreateSessionKey(storedPrivateKey);
|
|
565
|
+
* const account = await aaService.deserializeSessionKey({
|
|
566
|
+
* approval,
|
|
567
|
+
* sessionKeySigner: sessionKey.signer,
|
|
568
|
+
* chain: sepolia
|
|
569
|
+
* });
|
|
570
|
+
* const client = aaService.createSessionKeyClient({
|
|
571
|
+
* account,
|
|
572
|
+
* chain: sepolia,
|
|
573
|
+
* bundlerUrl: 'https://api.pimlico.io/...'
|
|
574
|
+
* });
|
|
575
|
+
*/
|
|
576
|
+
createSessionKeyClient(options: {
|
|
577
|
+
account: any;
|
|
578
|
+
chain: Chain;
|
|
579
|
+
bundlerUrl: string;
|
|
580
|
+
paymasterUrl?: string;
|
|
581
|
+
}): any;
|
|
582
|
+
/**
|
|
583
|
+
* Create USDC transfer permission rule
|
|
584
|
+
*
|
|
585
|
+
* Helper to create a permission rule for USDC transfers with a maximum amount.
|
|
586
|
+
*
|
|
587
|
+
* @param usdcAddress - USDC contract address
|
|
588
|
+
* @param maxAmount - Maximum USDC amount (in USDC units, e.g., "10" for 10 USDC)
|
|
589
|
+
* @returns Permission rule
|
|
590
|
+
*
|
|
591
|
+
* @example
|
|
592
|
+
* const rule = aaService.createUSDCTransferPermission(
|
|
593
|
+
* '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', // Sepolia USDC
|
|
594
|
+
* '10' // Max 10 USDC
|
|
595
|
+
* );
|
|
596
|
+
*/
|
|
597
|
+
createUSDCTransferPermission(usdcAddress: Hex, maxAmount: string): SessionKeyPermissionRule;
|
|
598
|
+
/**
|
|
599
|
+
* Create ETH transfer permission rule
|
|
600
|
+
*
|
|
601
|
+
* Helper to create a permission rule for ETH transfers with a maximum value.
|
|
602
|
+
*
|
|
603
|
+
* @param maxValue - Maximum ETH value (in ether units, e.g., "0.1" for 0.1 ETH)
|
|
604
|
+
* @returns Permission rule
|
|
605
|
+
*
|
|
606
|
+
* @example
|
|
607
|
+
* const rule = aaService.createETHTransferPermission('0.1'); // Max 0.1 ETH
|
|
608
|
+
*/
|
|
609
|
+
createETHTransferPermission(maxValue: string): SessionKeyPermissionRule;
|
|
610
|
+
private getAccountCacheKey;
|
|
611
|
+
private getAuthorizationCacheKey;
|
|
612
|
+
}
|
|
613
|
+
export default AccountAbstractionService;
|
|
614
|
+
export type { SessionKeyInfo, SessionKeyPermissionRule } from '../lib/session-keys';
|