@cfxdevkit/core 0.1.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/CHANGELOG.md +35 -0
- package/LICENSE +72 -0
- package/README.md +257 -0
- package/dist/clients/index.cjs +2053 -0
- package/dist/clients/index.cjs.map +1 -0
- package/dist/clients/index.d.cts +7 -0
- package/dist/clients/index.d.ts +7 -0
- package/dist/clients/index.js +2043 -0
- package/dist/clients/index.js.map +1 -0
- package/dist/config/index.cjs +423 -0
- package/dist/config/index.cjs.map +1 -0
- package/dist/config/index.d.cts +99 -0
- package/dist/config/index.d.ts +99 -0
- package/dist/config/index.js +380 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config-BMtaWM0X.d.cts +165 -0
- package/dist/config-BMtaWM0X.d.ts +165 -0
- package/dist/core-C5qe16RS.d.ts +352 -0
- package/dist/core-RZA4aKwj.d.cts +352 -0
- package/dist/index-BhCpy6Fz.d.cts +165 -0
- package/dist/index-Qz84U9Oq.d.ts +165 -0
- package/dist/index.cjs +3773 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +945 -0
- package/dist/index.d.ts +945 -0
- package/dist/index.js +3730 -0
- package/dist/index.js.map +1 -0
- package/dist/types/index.cjs +44 -0
- package/dist/types/index.cjs.map +1 -0
- package/dist/types/index.d.cts +5 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +17 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/index.cjs +83 -0
- package/dist/utils/index.cjs.map +1 -0
- package/dist/utils/index.d.cts +11 -0
- package/dist/utils/index.d.ts +11 -0
- package/dist/utils/index.js +56 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/wallet/index.cjs +852 -0
- package/dist/wallet/index.cjs.map +1 -0
- package/dist/wallet/index.d.cts +726 -0
- package/dist/wallet/index.d.ts +726 -0
- package/dist/wallet/index.js +815 -0
- package/dist/wallet/index.js.map +1 -0
- package/package.json +119 -0
|
@@ -0,0 +1,726 @@
|
|
|
1
|
+
import { C as ChainType } from '../config-BMtaWM0X.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Session Key Types
|
|
5
|
+
*/
|
|
6
|
+
interface SessionKeyPermissions {
|
|
7
|
+
/** Maximum value per transaction (in wei) */
|
|
8
|
+
maxValue?: bigint;
|
|
9
|
+
/** Whitelisted contract addresses */
|
|
10
|
+
contracts?: string[];
|
|
11
|
+
/** Allowed operations/function signatures */
|
|
12
|
+
operations?: string[];
|
|
13
|
+
/** Allowed chains */
|
|
14
|
+
chains?: ChainType[];
|
|
15
|
+
}
|
|
16
|
+
interface SessionKey {
|
|
17
|
+
/** Unique identifier for this session key */
|
|
18
|
+
id: string;
|
|
19
|
+
/** The session key's private key */
|
|
20
|
+
privateKey: string;
|
|
21
|
+
/** The session key's address */
|
|
22
|
+
address: string;
|
|
23
|
+
/** Parent wallet address */
|
|
24
|
+
parentAddress: string;
|
|
25
|
+
/** Time-to-live in seconds */
|
|
26
|
+
ttl: number;
|
|
27
|
+
/** Expiration timestamp */
|
|
28
|
+
expiresAt: Date;
|
|
29
|
+
/** Session key permissions */
|
|
30
|
+
permissions: SessionKeyPermissions;
|
|
31
|
+
/** Creation timestamp */
|
|
32
|
+
createdAt: Date;
|
|
33
|
+
/** Whether the session key is active */
|
|
34
|
+
isActive: boolean;
|
|
35
|
+
/** Chain type */
|
|
36
|
+
chain: ChainType;
|
|
37
|
+
}
|
|
38
|
+
interface SessionKeyOptions {
|
|
39
|
+
/** Time-to-live in seconds (default: 3600) */
|
|
40
|
+
ttl?: number;
|
|
41
|
+
/** Session key permissions */
|
|
42
|
+
permissions?: SessionKeyPermissions;
|
|
43
|
+
/** Chain type */
|
|
44
|
+
chain: ChainType;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Transaction Batching Types
|
|
48
|
+
*/
|
|
49
|
+
interface BatchTransaction {
|
|
50
|
+
/** Unique identifier */
|
|
51
|
+
id: string;
|
|
52
|
+
/** Target address */
|
|
53
|
+
to: string;
|
|
54
|
+
/** Value to send (in wei) */
|
|
55
|
+
value?: bigint;
|
|
56
|
+
/** Transaction data */
|
|
57
|
+
data?: string;
|
|
58
|
+
/** Gas limit */
|
|
59
|
+
gasLimit?: bigint;
|
|
60
|
+
/** Chain type */
|
|
61
|
+
chain: ChainType;
|
|
62
|
+
/** Added timestamp */
|
|
63
|
+
addedAt: Date;
|
|
64
|
+
}
|
|
65
|
+
interface BatchResult {
|
|
66
|
+
/** Batch identifier */
|
|
67
|
+
batchId: string;
|
|
68
|
+
/** Transaction hashes */
|
|
69
|
+
transactionHashes: string[];
|
|
70
|
+
/** Number of successful transactions */
|
|
71
|
+
successCount: number;
|
|
72
|
+
/** Number of failed transactions */
|
|
73
|
+
failureCount: number;
|
|
74
|
+
/** Execution timestamp */
|
|
75
|
+
executedAt: Date;
|
|
76
|
+
/** Total gas used */
|
|
77
|
+
totalGasUsed: bigint;
|
|
78
|
+
/** Chain type */
|
|
79
|
+
chain: ChainType;
|
|
80
|
+
}
|
|
81
|
+
interface BatcherOptions {
|
|
82
|
+
/** Maximum batch size */
|
|
83
|
+
maxBatchSize?: number;
|
|
84
|
+
/** Auto-execute batch after timeout (ms) */
|
|
85
|
+
autoExecuteTimeout?: number;
|
|
86
|
+
/** Minimum gas price (in wei) */
|
|
87
|
+
minGasPrice?: bigint;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Embedded Wallet Types
|
|
91
|
+
*/
|
|
92
|
+
interface EmbeddedWallet {
|
|
93
|
+
/** User identifier */
|
|
94
|
+
userId: string;
|
|
95
|
+
/** Wallet address (Core Space) */
|
|
96
|
+
coreAddress: string;
|
|
97
|
+
/** Wallet address (eSpace) */
|
|
98
|
+
evmAddress: string;
|
|
99
|
+
/** Encrypted private key */
|
|
100
|
+
encryptedPrivateKey: string;
|
|
101
|
+
/** Encryption metadata */
|
|
102
|
+
encryption: {
|
|
103
|
+
algorithm: string;
|
|
104
|
+
iv: string;
|
|
105
|
+
salt: string;
|
|
106
|
+
};
|
|
107
|
+
/** Creation timestamp */
|
|
108
|
+
createdAt: Date;
|
|
109
|
+
/** Last accessed timestamp */
|
|
110
|
+
lastAccessedAt: Date;
|
|
111
|
+
/** Whether the wallet is active */
|
|
112
|
+
isActive: boolean;
|
|
113
|
+
}
|
|
114
|
+
interface WalletExport {
|
|
115
|
+
/** User identifier */
|
|
116
|
+
userId: string;
|
|
117
|
+
/** Encrypted wallet data */
|
|
118
|
+
encryptedData: string;
|
|
119
|
+
/** Encryption metadata */
|
|
120
|
+
encryption: {
|
|
121
|
+
algorithm: string;
|
|
122
|
+
iv: string;
|
|
123
|
+
salt: string;
|
|
124
|
+
};
|
|
125
|
+
/** Export timestamp */
|
|
126
|
+
exportedAt: Date;
|
|
127
|
+
}
|
|
128
|
+
interface EmbeddedWalletOptions {
|
|
129
|
+
/** Encryption algorithm (default: 'aes-256-gcm') */
|
|
130
|
+
algorithm?: string;
|
|
131
|
+
/** Key derivation iterations (default: 100000) */
|
|
132
|
+
iterations?: number;
|
|
133
|
+
/** Whether to auto-create wallets for new users */
|
|
134
|
+
autoCreate?: boolean;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Transaction Signing Types
|
|
138
|
+
*/
|
|
139
|
+
interface SignTransactionRequest {
|
|
140
|
+
/** Transaction to sign */
|
|
141
|
+
to: string;
|
|
142
|
+
value?: bigint;
|
|
143
|
+
data?: string;
|
|
144
|
+
gasLimit?: bigint;
|
|
145
|
+
gasPrice?: bigint;
|
|
146
|
+
nonce?: number;
|
|
147
|
+
/** Chain type */
|
|
148
|
+
chain: ChainType;
|
|
149
|
+
}
|
|
150
|
+
interface SignedTransaction {
|
|
151
|
+
/** Raw signed transaction */
|
|
152
|
+
rawTransaction: string;
|
|
153
|
+
/** Transaction hash */
|
|
154
|
+
hash: string;
|
|
155
|
+
/** Signer address */
|
|
156
|
+
from: string;
|
|
157
|
+
/** Chain type */
|
|
158
|
+
chain: ChainType;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Wallet Manager Types
|
|
162
|
+
*/
|
|
163
|
+
interface WalletManagerOptions {
|
|
164
|
+
/** Session key options */
|
|
165
|
+
sessionKeys?: SessionKeyOptions;
|
|
166
|
+
/** Batcher options */
|
|
167
|
+
batcher?: BatcherOptions;
|
|
168
|
+
/** Embedded wallet options */
|
|
169
|
+
embedded?: EmbeddedWalletOptions;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Error Types
|
|
173
|
+
*/
|
|
174
|
+
declare class WalletError extends Error {
|
|
175
|
+
code: string;
|
|
176
|
+
context?: Record<string, unknown> | undefined;
|
|
177
|
+
constructor(message: string, code: string, context?: Record<string, unknown> | undefined);
|
|
178
|
+
}
|
|
179
|
+
declare class SessionKeyError extends WalletError {
|
|
180
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
181
|
+
}
|
|
182
|
+
declare class BatcherError extends WalletError {
|
|
183
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
184
|
+
}
|
|
185
|
+
declare class EmbeddedWalletError extends WalletError {
|
|
186
|
+
constructor(message: string, context?: Record<string, unknown>);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Transaction Batcher
|
|
191
|
+
*
|
|
192
|
+
* Batches multiple transactions for efficient execution.
|
|
193
|
+
* Reduces gas costs and network congestion by grouping related operations.
|
|
194
|
+
*
|
|
195
|
+
* Use Cases:
|
|
196
|
+
* - Batch NFT minting
|
|
197
|
+
* - Multi-send operations
|
|
198
|
+
* - Batch token approvals
|
|
199
|
+
* - Gas optimization for high-frequency operations
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* const batcher = new TransactionBatcher({
|
|
204
|
+
* maxBatchSize: 10,
|
|
205
|
+
* autoExecuteTimeout: 5000
|
|
206
|
+
* });
|
|
207
|
+
*
|
|
208
|
+
* // Add transactions to batch
|
|
209
|
+
* batcher.addTransaction({
|
|
210
|
+
* to: '0xRecipient1...',
|
|
211
|
+
* value: parseEther('1.0'),
|
|
212
|
+
* chain: 'evm'
|
|
213
|
+
* });
|
|
214
|
+
*
|
|
215
|
+
* batcher.addTransaction({
|
|
216
|
+
* to: '0xRecipient2...',
|
|
217
|
+
* value: parseEther('2.0'),
|
|
218
|
+
* chain: 'evm'
|
|
219
|
+
* });
|
|
220
|
+
*
|
|
221
|
+
* // Execute batch
|
|
222
|
+
* const result = await batcher.executeBatch('evm', signer);
|
|
223
|
+
* console.log(`Executed ${result.successCount} transactions`);
|
|
224
|
+
* ```
|
|
225
|
+
*/
|
|
226
|
+
declare class TransactionBatcher {
|
|
227
|
+
private coreBatch;
|
|
228
|
+
private evmBatch;
|
|
229
|
+
private autoExecuteTimer;
|
|
230
|
+
private options;
|
|
231
|
+
constructor(options?: BatcherOptions);
|
|
232
|
+
/**
|
|
233
|
+
* Add transaction to batch
|
|
234
|
+
*
|
|
235
|
+
* @param tx - Transaction to add
|
|
236
|
+
* @returns Transaction ID
|
|
237
|
+
*/
|
|
238
|
+
addTransaction(tx: Omit<BatchTransaction, 'id' | 'addedAt'>): string;
|
|
239
|
+
/**
|
|
240
|
+
* Remove transaction from batch
|
|
241
|
+
*
|
|
242
|
+
* @param transactionId - Transaction ID
|
|
243
|
+
* @param chain - Chain type
|
|
244
|
+
* @returns true if removed, false if not found
|
|
245
|
+
*/
|
|
246
|
+
removeTransaction(transactionId: string, chain: ChainType): boolean;
|
|
247
|
+
/**
|
|
248
|
+
* Get pending transactions for a chain
|
|
249
|
+
*
|
|
250
|
+
* @param chain - Chain type
|
|
251
|
+
* @returns Array of pending transactions
|
|
252
|
+
*/
|
|
253
|
+
getPendingTransactions(chain: ChainType): BatchTransaction[];
|
|
254
|
+
/**
|
|
255
|
+
* Get batch statistics
|
|
256
|
+
*
|
|
257
|
+
* @param chain - Chain type
|
|
258
|
+
* @returns Batch statistics
|
|
259
|
+
*/
|
|
260
|
+
getBatchStats(chain: ChainType): {
|
|
261
|
+
count: number;
|
|
262
|
+
totalValue: bigint;
|
|
263
|
+
avgGasLimit: bigint;
|
|
264
|
+
oldestTransaction: Date;
|
|
265
|
+
};
|
|
266
|
+
/**
|
|
267
|
+
* Execute batch of transactions
|
|
268
|
+
*
|
|
269
|
+
* Note: This is a simplified implementation. In production, you would:
|
|
270
|
+
* - Use multicall contracts for actual batching
|
|
271
|
+
* - Handle gas estimation
|
|
272
|
+
* - Implement retry logic
|
|
273
|
+
* - Support different batching strategies (sequential, parallel, etc.)
|
|
274
|
+
*
|
|
275
|
+
* @param chain - Chain to execute on
|
|
276
|
+
* @param signer - Function to sign and send transactions
|
|
277
|
+
* @returns Batch execution result
|
|
278
|
+
*/
|
|
279
|
+
executeBatch(chain: ChainType, signer?: (tx: BatchTransaction) => Promise<string>): Promise<BatchResult>;
|
|
280
|
+
/**
|
|
281
|
+
* Clear all pending transactions
|
|
282
|
+
*
|
|
283
|
+
* @param chain - Chain to clear, or undefined to clear both
|
|
284
|
+
*/
|
|
285
|
+
clearBatch(chain?: ChainType): void;
|
|
286
|
+
/**
|
|
287
|
+
* Start auto-execute timer
|
|
288
|
+
*/
|
|
289
|
+
private startAutoExecuteTimer;
|
|
290
|
+
/**
|
|
291
|
+
* Stop auto-execute timer
|
|
292
|
+
*/
|
|
293
|
+
private stopAutoExecuteTimer;
|
|
294
|
+
/**
|
|
295
|
+
* Get batcher configuration
|
|
296
|
+
*/
|
|
297
|
+
getOptions(): Required<BatcherOptions>;
|
|
298
|
+
/**
|
|
299
|
+
* Update batcher configuration
|
|
300
|
+
*/
|
|
301
|
+
updateOptions(options: Partial<BatcherOptions>): void;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Wallet Types for HD Derivation
|
|
306
|
+
*
|
|
307
|
+
* Provides unified types for BIP32/BIP39 HD wallet derivation
|
|
308
|
+
* supporting both Conflux Core Space and eSpace (EVM).
|
|
309
|
+
*/
|
|
310
|
+
/**
|
|
311
|
+
* Derived account with dual-chain support.
|
|
312
|
+
* Uses separate derivation paths for Core Space (coin type 503)
|
|
313
|
+
* and eSpace (coin type 60).
|
|
314
|
+
*/
|
|
315
|
+
interface DerivedAccount {
|
|
316
|
+
/** Account index in derivation sequence */
|
|
317
|
+
index: number;
|
|
318
|
+
/** Core Space address (cfx:...) */
|
|
319
|
+
coreAddress: string;
|
|
320
|
+
/** eSpace address (0x...) */
|
|
321
|
+
evmAddress: string;
|
|
322
|
+
/** Core Space private key from m/44'/503'/accountType'/0/index */
|
|
323
|
+
corePrivateKey: `0x${string}`;
|
|
324
|
+
/** eSpace private key from m/44'/60'/accountType'/0/index */
|
|
325
|
+
evmPrivateKey: `0x${string}`;
|
|
326
|
+
/** Derivation paths used */
|
|
327
|
+
paths: {
|
|
328
|
+
/** Core Space derivation path */
|
|
329
|
+
core: string;
|
|
330
|
+
/** eSpace derivation path */
|
|
331
|
+
evm: string;
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* Options for deriving accounts from a mnemonic
|
|
336
|
+
*/
|
|
337
|
+
interface DerivationOptions {
|
|
338
|
+
/** Number of accounts to derive */
|
|
339
|
+
count: number;
|
|
340
|
+
/** Starting index (default: 0) */
|
|
341
|
+
startIndex?: number;
|
|
342
|
+
/** Core Space network ID for address encoding (default: 2029 for local) */
|
|
343
|
+
coreNetworkId?: number;
|
|
344
|
+
/**
|
|
345
|
+
* Account type determines the derivation path:
|
|
346
|
+
* - 'standard' (default): m/44'/{coin}'/0'/0/{index} - Regular user accounts
|
|
347
|
+
* - 'mining': m/44'/{coin}'/1'/0/{index} - Mining/faucet accounts
|
|
348
|
+
*/
|
|
349
|
+
accountType?: 'standard' | 'mining';
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Result of mnemonic validation
|
|
353
|
+
*/
|
|
354
|
+
interface MnemonicValidation {
|
|
355
|
+
/** Whether the mnemonic is valid */
|
|
356
|
+
valid: boolean;
|
|
357
|
+
/** Number of words in the mnemonic */
|
|
358
|
+
wordCount: number;
|
|
359
|
+
/** Error message if invalid */
|
|
360
|
+
error?: string;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Coin type constants for BIP44 derivation paths
|
|
364
|
+
*/
|
|
365
|
+
declare const COIN_TYPES: {
|
|
366
|
+
/** Conflux Core Space - registered coin type 503 */
|
|
367
|
+
readonly CONFLUX: 503;
|
|
368
|
+
/** Ethereum/eSpace - standard coin type 60 */
|
|
369
|
+
readonly ETHEREUM: 60;
|
|
370
|
+
};
|
|
371
|
+
/**
|
|
372
|
+
* Network IDs for Conflux Core Space address encoding
|
|
373
|
+
*/
|
|
374
|
+
declare const CORE_NETWORK_IDS: {
|
|
375
|
+
/** Local development network */
|
|
376
|
+
readonly LOCAL: 2029;
|
|
377
|
+
/** Testnet */
|
|
378
|
+
readonly TESTNET: 1;
|
|
379
|
+
/** Mainnet */
|
|
380
|
+
readonly MAINNET: 1029;
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Generate a new BIP-39 mnemonic phrase
|
|
385
|
+
*
|
|
386
|
+
* @param strength - 128 for 12 words (default) or 256 for 24 words
|
|
387
|
+
* @returns A valid BIP-39 mnemonic phrase
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* const mnemonic = generateMnemonic(); // 12 words
|
|
392
|
+
* const mnemonic24 = generateMnemonic(256); // 24 words
|
|
393
|
+
* ```
|
|
394
|
+
*/
|
|
395
|
+
declare function generateMnemonic(strength?: 128 | 256): string;
|
|
396
|
+
/**
|
|
397
|
+
* Validate a mnemonic phrase
|
|
398
|
+
*
|
|
399
|
+
* Checks that the mnemonic has a valid word count (12 or 24)
|
|
400
|
+
* and passes BIP-39 checksum validation.
|
|
401
|
+
*
|
|
402
|
+
* @param mnemonic - The mnemonic phrase to validate
|
|
403
|
+
* @returns Validation result with details
|
|
404
|
+
*
|
|
405
|
+
* @example
|
|
406
|
+
* ```typescript
|
|
407
|
+
* const result = validateMnemonic('abandon abandon ...');
|
|
408
|
+
* if (result.valid) {
|
|
409
|
+
* console.log(`Valid ${result.wordCount}-word mnemonic`);
|
|
410
|
+
* } else {
|
|
411
|
+
* console.error(result.error);
|
|
412
|
+
* }
|
|
413
|
+
* ```
|
|
414
|
+
*/
|
|
415
|
+
declare function validateMnemonic(mnemonic: string): MnemonicValidation;
|
|
416
|
+
/**
|
|
417
|
+
* Derive multiple accounts from a mnemonic phrase
|
|
418
|
+
*
|
|
419
|
+
* Derives accounts for both Conflux Core Space and eSpace using
|
|
420
|
+
* BIP-44 standard derivation paths:
|
|
421
|
+
* - Core Space: m/44'/503'/{accountType}'/0/{index}
|
|
422
|
+
* - eSpace: m/44'/60'/{accountType}'/0/{index}
|
|
423
|
+
*
|
|
424
|
+
* @param mnemonic - BIP-39 mnemonic phrase
|
|
425
|
+
* @param options - Derivation options
|
|
426
|
+
* @returns Array of derived accounts
|
|
427
|
+
* @throws Error if mnemonic is invalid
|
|
428
|
+
*
|
|
429
|
+
* @example
|
|
430
|
+
* ```typescript
|
|
431
|
+
* const accounts = deriveAccounts(mnemonic, {
|
|
432
|
+
* count: 10,
|
|
433
|
+
* coreNetworkId: 2029, // Local network
|
|
434
|
+
* });
|
|
435
|
+
* console.log(accounts[0].coreAddress); // cfx:...
|
|
436
|
+
* console.log(accounts[0].evmAddress); // 0x...
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
declare function deriveAccounts(mnemonic: string, options: DerivationOptions): DerivedAccount[];
|
|
440
|
+
/**
|
|
441
|
+
* Derive a single account at a specific index
|
|
442
|
+
*
|
|
443
|
+
* Convenience function for deriving just one account.
|
|
444
|
+
*
|
|
445
|
+
* @param mnemonic - BIP-39 mnemonic phrase
|
|
446
|
+
* @param index - Account index to derive
|
|
447
|
+
* @param coreNetworkId - Core Space network ID (default: 2029 for local)
|
|
448
|
+
* @param accountType - 'standard' or 'mining' (default: 'standard')
|
|
449
|
+
* @returns The derived account
|
|
450
|
+
*
|
|
451
|
+
* @example
|
|
452
|
+
* ```typescript
|
|
453
|
+
* const account = deriveAccount(mnemonic, 5);
|
|
454
|
+
* console.log(account.index); // 5
|
|
455
|
+
* ```
|
|
456
|
+
*/
|
|
457
|
+
declare function deriveAccount(mnemonic: string, index: number, coreNetworkId?: number, accountType?: 'standard' | 'mining'): DerivedAccount;
|
|
458
|
+
/**
|
|
459
|
+
* Derive the faucet/mining account
|
|
460
|
+
*
|
|
461
|
+
* The faucet account uses a separate derivation path (mining type)
|
|
462
|
+
* at index 0. This is used for the mining rewards recipient and
|
|
463
|
+
* as the source for faucet operations.
|
|
464
|
+
*
|
|
465
|
+
* @param mnemonic - BIP-39 mnemonic phrase
|
|
466
|
+
* @param coreNetworkId - Core Space network ID (default: 2029 for local)
|
|
467
|
+
* @returns The faucet account
|
|
468
|
+
*
|
|
469
|
+
* @example
|
|
470
|
+
* ```typescript
|
|
471
|
+
* const faucet = deriveFaucetAccount(mnemonic);
|
|
472
|
+
* // Uses paths: m/44'/503'/1'/0/0 and m/44'/60'/1'/0/0
|
|
473
|
+
* ```
|
|
474
|
+
*/
|
|
475
|
+
declare function deriveFaucetAccount(mnemonic: string, coreNetworkId?: number): DerivedAccount;
|
|
476
|
+
/**
|
|
477
|
+
* Get the derivation path for an account
|
|
478
|
+
*
|
|
479
|
+
* Utility function to generate standard derivation paths.
|
|
480
|
+
*
|
|
481
|
+
* @param coinType - Coin type (503 for Conflux, 60 for Ethereum)
|
|
482
|
+
* @param index - Account index
|
|
483
|
+
* @param accountType - 'standard' (0') or 'mining' (1')
|
|
484
|
+
* @returns The BIP-44 derivation path
|
|
485
|
+
*/
|
|
486
|
+
declare function getDerivationPath(coinType: number, index: number, accountType?: 'standard' | 'mining'): string;
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Embedded Wallet Manager
|
|
490
|
+
*
|
|
491
|
+
* Manages server-side custody wallets for users.
|
|
492
|
+
* Provides secure wallet creation, storage, and transaction signing.
|
|
493
|
+
*
|
|
494
|
+
* SECURITY WARNING:
|
|
495
|
+
* This is a simplified implementation for development and testing.
|
|
496
|
+
* Production use requires:
|
|
497
|
+
* - Hardware Security Modules (HSM)
|
|
498
|
+
* - Proper key management infrastructure
|
|
499
|
+
* - Multi-signature schemes
|
|
500
|
+
* - Audit logging
|
|
501
|
+
* - Compliance with custody regulations
|
|
502
|
+
*
|
|
503
|
+
* Use Cases:
|
|
504
|
+
* - Social login wallets (Privy, Magic, Web3Auth)
|
|
505
|
+
* - Custodial game wallets
|
|
506
|
+
* - Enterprise treasury management
|
|
507
|
+
* - Automated service accounts
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```typescript
|
|
511
|
+
* const manager = new EmbeddedWalletManager();
|
|
512
|
+
*
|
|
513
|
+
* // Create wallet for user
|
|
514
|
+
* const wallet = await manager.createWallet('user123', 'secure-password');
|
|
515
|
+
*
|
|
516
|
+
* // Sign transaction
|
|
517
|
+
* const signed = await manager.signTransaction('user123', 'secure-password', {
|
|
518
|
+
* to: '0xRecipient...',
|
|
519
|
+
* value: parseEther('1.0'),
|
|
520
|
+
* chain: 'evm'
|
|
521
|
+
* });
|
|
522
|
+
*
|
|
523
|
+
* // Export wallet for user
|
|
524
|
+
* const exportData = await manager.exportWallet('user123', 'secure-password');
|
|
525
|
+
* ```
|
|
526
|
+
*/
|
|
527
|
+
declare class EmbeddedWalletManager {
|
|
528
|
+
private wallets;
|
|
529
|
+
private options;
|
|
530
|
+
constructor(options?: EmbeddedWalletOptions);
|
|
531
|
+
/**
|
|
532
|
+
* Create a new embedded wallet for a user
|
|
533
|
+
*
|
|
534
|
+
* @param userId - User identifier
|
|
535
|
+
* @param password - Encryption password
|
|
536
|
+
* @returns Created wallet (without private key)
|
|
537
|
+
*/
|
|
538
|
+
createWallet(userId: string, password: string): Promise<Omit<EmbeddedWallet, 'encryptedPrivateKey'>>;
|
|
539
|
+
/**
|
|
540
|
+
* Get wallet info (without private key)
|
|
541
|
+
*
|
|
542
|
+
* @param userId - User identifier
|
|
543
|
+
* @returns Wallet info or undefined
|
|
544
|
+
*/
|
|
545
|
+
getWallet(userId: string): Omit<EmbeddedWallet, 'encryptedPrivateKey'> | undefined;
|
|
546
|
+
/**
|
|
547
|
+
* Check if user has a wallet
|
|
548
|
+
*
|
|
549
|
+
* @param userId - User identifier
|
|
550
|
+
* @returns true if wallet exists
|
|
551
|
+
*/
|
|
552
|
+
hasWallet(userId: string): boolean;
|
|
553
|
+
/**
|
|
554
|
+
* Sign transaction with user's embedded wallet
|
|
555
|
+
*
|
|
556
|
+
* @param userId - User identifier
|
|
557
|
+
* @param password - Decryption password
|
|
558
|
+
* @param request - Transaction request
|
|
559
|
+
* @returns Signed transaction
|
|
560
|
+
*/
|
|
561
|
+
signTransaction(userId: string, password: string, request: SignTransactionRequest): Promise<SignedTransaction>;
|
|
562
|
+
/**
|
|
563
|
+
* Export wallet for user backup
|
|
564
|
+
*
|
|
565
|
+
* @param userId - User identifier
|
|
566
|
+
* @param password - Encryption password
|
|
567
|
+
* @returns Encrypted wallet export
|
|
568
|
+
*/
|
|
569
|
+
exportWallet(userId: string, password: string): Promise<WalletExport>;
|
|
570
|
+
/**
|
|
571
|
+
* Deactivate wallet
|
|
572
|
+
*
|
|
573
|
+
* @param userId - User identifier
|
|
574
|
+
*/
|
|
575
|
+
deactivateWallet(userId: string): void;
|
|
576
|
+
/**
|
|
577
|
+
* Delete wallet permanently
|
|
578
|
+
*
|
|
579
|
+
* WARNING: This operation cannot be undone
|
|
580
|
+
*
|
|
581
|
+
* @param userId - User identifier
|
|
582
|
+
* @returns true if deleted, false if not found
|
|
583
|
+
*/
|
|
584
|
+
deleteWallet(userId: string): boolean;
|
|
585
|
+
/**
|
|
586
|
+
* List all wallets (without private keys)
|
|
587
|
+
*
|
|
588
|
+
* @returns Array of wallet info
|
|
589
|
+
*/
|
|
590
|
+
listWallets(): Array<Omit<EmbeddedWallet, 'encryptedPrivateKey'>>;
|
|
591
|
+
/**
|
|
592
|
+
* Get wallet statistics
|
|
593
|
+
*
|
|
594
|
+
* @returns Wallet statistics
|
|
595
|
+
*/
|
|
596
|
+
getStats(): {
|
|
597
|
+
total: number;
|
|
598
|
+
active: number;
|
|
599
|
+
inactive: number;
|
|
600
|
+
};
|
|
601
|
+
/**
|
|
602
|
+
* Encrypt private key
|
|
603
|
+
*
|
|
604
|
+
* NOTE: Simplified implementation for demonstration
|
|
605
|
+
* Production should use proper encryption (node:crypto, @noble/ciphers, etc.)
|
|
606
|
+
*/
|
|
607
|
+
private encryptPrivateKey;
|
|
608
|
+
/**
|
|
609
|
+
* Decrypt private key
|
|
610
|
+
*
|
|
611
|
+
* NOTE: Simplified implementation for demonstration
|
|
612
|
+
*/
|
|
613
|
+
private decryptPrivateKey;
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
/**
|
|
617
|
+
* Session Key Manager
|
|
618
|
+
*
|
|
619
|
+
* Manages temporary session keys for delegated transaction signing.
|
|
620
|
+
* Session keys allow applications to sign transactions on behalf of users
|
|
621
|
+
* with time-limited and permission-scoped access.
|
|
622
|
+
*
|
|
623
|
+
* Use Cases:
|
|
624
|
+
* - Gaming: Allow game to make in-game purchases without repeated wallet prompts
|
|
625
|
+
* - Trading: Enable automated trading bots with spending limits
|
|
626
|
+
* - DeFi: Permit auto-compounding or rebalancing with constraints
|
|
627
|
+
*
|
|
628
|
+
* @example
|
|
629
|
+
* ```typescript
|
|
630
|
+
* const manager = new SessionKeyManager();
|
|
631
|
+
*
|
|
632
|
+
* // Create session key with 1 hour TTL and spending limit
|
|
633
|
+
* const sessionKey = manager.generateSessionKey(
|
|
634
|
+
* '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
|
|
635
|
+
* {
|
|
636
|
+
* ttl: 3600,
|
|
637
|
+
* permissions: {
|
|
638
|
+
* maxValue: parseEther('1.0'),
|
|
639
|
+
* contracts: ['0xGameContract...']
|
|
640
|
+
* },
|
|
641
|
+
* chain: 'evm'
|
|
642
|
+
* }
|
|
643
|
+
* );
|
|
644
|
+
*
|
|
645
|
+
* // Use session key to sign transactions
|
|
646
|
+
* const signedTx = await manager.signWithSessionKey(sessionKey.id, {
|
|
647
|
+
* to: '0xGameContract...',
|
|
648
|
+
* data: '0x...',
|
|
649
|
+
* chain: 'evm'
|
|
650
|
+
* });
|
|
651
|
+
* ```
|
|
652
|
+
*/
|
|
653
|
+
declare class SessionKeyManager {
|
|
654
|
+
private sessionKeys;
|
|
655
|
+
/**
|
|
656
|
+
* Generate a new session key
|
|
657
|
+
*
|
|
658
|
+
* @param parentAddress - Parent wallet address
|
|
659
|
+
* @param options - Session key configuration
|
|
660
|
+
* @returns Created session key
|
|
661
|
+
*/
|
|
662
|
+
generateSessionKey(parentAddress: string, options: SessionKeyOptions): SessionKey;
|
|
663
|
+
/**
|
|
664
|
+
* Get session key by ID
|
|
665
|
+
*
|
|
666
|
+
* @param sessionKeyId - Session key identifier
|
|
667
|
+
* @returns Session key or undefined
|
|
668
|
+
*/
|
|
669
|
+
getSessionKey(sessionKeyId: string): SessionKey | undefined;
|
|
670
|
+
/**
|
|
671
|
+
* Revoke a session key
|
|
672
|
+
*
|
|
673
|
+
* @param sessionKeyId - Session key identifier
|
|
674
|
+
*/
|
|
675
|
+
revokeSessionKey(sessionKeyId: string): void;
|
|
676
|
+
/**
|
|
677
|
+
* List all session keys for a parent address
|
|
678
|
+
*
|
|
679
|
+
* @param parentAddress - Parent wallet address
|
|
680
|
+
* @returns Array of session keys
|
|
681
|
+
*/
|
|
682
|
+
listSessionKeys(parentAddress: string): SessionKey[];
|
|
683
|
+
/**
|
|
684
|
+
* List active session keys for a parent address
|
|
685
|
+
*
|
|
686
|
+
* @param parentAddress - Parent wallet address
|
|
687
|
+
* @returns Array of active session keys
|
|
688
|
+
*/
|
|
689
|
+
listActiveSessionKeys(parentAddress: string): SessionKey[];
|
|
690
|
+
/**
|
|
691
|
+
* Validate transaction against session key permissions
|
|
692
|
+
*
|
|
693
|
+
* @param sessionKey - Session key
|
|
694
|
+
* @param request - Transaction request
|
|
695
|
+
* @throws SessionKeyError if validation fails
|
|
696
|
+
*/
|
|
697
|
+
private validateTransaction;
|
|
698
|
+
/**
|
|
699
|
+
* Sign transaction with session key
|
|
700
|
+
*
|
|
701
|
+
* @param sessionKeyId - Session key identifier
|
|
702
|
+
* @param request - Transaction request
|
|
703
|
+
* @returns Signed transaction
|
|
704
|
+
* @throws SessionKeyError if session key is invalid or transaction violates permissions
|
|
705
|
+
*/
|
|
706
|
+
signWithSessionKey(sessionKeyId: string, request: SignTransactionRequest): Promise<SignedTransaction>;
|
|
707
|
+
/**
|
|
708
|
+
* Clean up expired session keys
|
|
709
|
+
*
|
|
710
|
+
* @returns Number of removed session keys
|
|
711
|
+
*/
|
|
712
|
+
cleanupExpired(): number;
|
|
713
|
+
/**
|
|
714
|
+
* Get session key statistics
|
|
715
|
+
*
|
|
716
|
+
* @returns Statistics about session keys
|
|
717
|
+
*/
|
|
718
|
+
getStats(): {
|
|
719
|
+
total: number;
|
|
720
|
+
active: number;
|
|
721
|
+
expired: number;
|
|
722
|
+
inactive: number;
|
|
723
|
+
};
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
export { type BatchResult, type BatchTransaction, BatcherError, type BatcherOptions, COIN_TYPES, CORE_NETWORK_IDS, type DerivationOptions, type DerivedAccount, type EmbeddedWallet, EmbeddedWalletError, EmbeddedWalletManager, type EmbeddedWalletOptions, type MnemonicValidation, type SessionKey, SessionKeyError, SessionKeyManager, type SessionKeyOptions, type SessionKeyPermissions, type SignTransactionRequest, type SignedTransaction, TransactionBatcher, WalletError, type WalletExport, type WalletManagerOptions, deriveAccount, deriveAccounts, deriveFaucetAccount, generateMnemonic, getDerivationPath, validateMnemonic };
|