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