@zubari/sdk 0.1.4 → 0.1.6

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.
@@ -1,5 +1,36 @@
1
- export { F as FeeEstimate, S as SwapService, d as TransactionHistoryItem, a as TransactionParams, b as TransactionResult, T as TransactionService, e as TransactionServiceConfig, c as createTransactionService, g as getTransactionService } from '../TransactionService-DdL6H6M-.js';
2
- import { N as NetworkType } from '../index-DhluuR9H.js';
1
+ import { k as SwapQuote, b as TxResult, N as NetworkType } from '../index-DhluuR9H.js';
2
+
3
+ /**
4
+ * SwapService - DEX integration via Velora
5
+ *
6
+ * Handles token swaps with slippage protection,
7
+ * quote fetching, and earnings conversion.
8
+ */
9
+ declare class SwapService {
10
+ private readonly _chainId;
11
+ private readonly isTestnet;
12
+ constructor(chainId: number, isTestnet?: boolean);
13
+ /**
14
+ * Get a swap quote
15
+ */
16
+ getQuote(tokenIn: string, tokenOut: string, amountIn: bigint): Promise<SwapQuote>;
17
+ /**
18
+ * Execute a swap with slippage protection
19
+ */
20
+ executeSwap(quote: SwapQuote, slippageToleranceBps?: number): Promise<TxResult>;
21
+ /**
22
+ * Convert earnings to USDT, keeping some ETH for gas
23
+ */
24
+ convertEarningsToStable(ethBalance: bigint, reserveForGas?: bigint): Promise<TxResult>;
25
+ /**
26
+ * Check if a swap route exists
27
+ */
28
+ hasRoute(tokenIn: string, tokenOut: string): Promise<boolean>;
29
+ /**
30
+ * Get supported tokens for swapping
31
+ */
32
+ getSupportedTokens(): Promise<string[]>;
33
+ }
3
34
 
4
35
  /**
5
36
  * WDK API Client
@@ -122,8 +153,9 @@ declare function deriveTonAddress(seed: string): Promise<string>;
122
153
  /**
123
154
  * Derive TRON address from seed phrase
124
155
  * TRON uses secp256k1 like Ethereum but with base58check encoding
156
+ * Uses @scure/base for browser compatibility
125
157
  */
126
- declare function deriveTronAddress(seed: string): Promise<string>;
158
+ declare function deriveTronAddress(seed: string): string;
127
159
  /**
128
160
  * Derive Spark address from seed phrase
129
161
  * Spark uses its own derivation path and bech32 format
@@ -158,13 +190,18 @@ declare namespace BrowserAddressDerivation {
158
190
  }
159
191
 
160
192
  /**
161
- * WDK Service for SDK
193
+ * Zubari WDK Service - Unified Multi-Chain Wallet Service
162
194
  *
163
- * Native integration with Tether WDK for multi-chain address derivation.
164
- * Uses individual wallet modules for each chain to derive cryptographically
165
- * valid addresses from a BIP-39 seed phrase.
195
+ * This service provides a unified interface for multi-chain wallet operations
196
+ * that works in both browser and Node.js environments.
166
197
  *
167
- * Supported chains: Ethereum, Bitcoin, TON, TRON, Solana, Spark (Lightning)
198
+ * Strategy:
199
+ * - Browser: Uses WdkApiClient to call the backend API (which has Tether WDK)
200
+ * - Node.js: Uses WdkService natively (with Tether WDK modules)
201
+ *
202
+ * The Tether WDK (@tetherto/wdk-*) only works in Node.js environments due to
203
+ * native dependencies (Electrum client, gRPC, etc.). For browser environments,
204
+ * we route all operations through the backend API.
168
205
  *
169
206
  * @see https://docs.wallet.tether.io/
170
207
  */
@@ -182,101 +219,299 @@ interface MultiChainAddresses {
182
219
  solana: string | null;
183
220
  spark: string | null;
184
221
  }
185
- interface WdkServiceConfig {
222
+ interface ChainBalance {
223
+ chain: SupportedChain;
224
+ address: string;
225
+ balance: string;
226
+ symbol: string;
227
+ }
228
+ interface FeeRates {
229
+ slow: string;
230
+ normal: string;
231
+ fast: string;
232
+ }
233
+ interface TransactionResult$1 {
234
+ success: boolean;
235
+ txHash?: string;
236
+ from?: string;
237
+ to?: string;
238
+ amount?: string;
239
+ chain?: string;
240
+ network?: string;
241
+ error?: string;
242
+ }
243
+ interface ZubariWdkServiceConfig {
244
+ /** Network to use (mainnet or testnet) */
186
245
  network: 'mainnet' | 'testnet';
187
- rpcUrls?: {
188
- ethereum?: string;
189
- bitcoin?: string;
190
- solana?: string;
191
- ton?: string;
192
- tron?: string;
193
- };
246
+ /** API URL for the Zubari backend (required for browser environments) */
247
+ apiUrl?: string;
248
+ /** Force using API even in Node.js (useful for testing) */
249
+ forceApi?: boolean;
250
+ /** Request timeout in milliseconds */
251
+ timeout?: number;
194
252
  }
195
253
  /**
196
- * WDK Service for native multi-chain address derivation
197
- * Uses Tether WDK wallet modules directly without needing a backend API
254
+ * Check if we're running in a browser environment
198
255
  */
199
- declare class WdkService {
200
- private seed;
256
+ declare function isBrowser(): boolean;
257
+ /**
258
+ * ZubariWdkService - Unified wallet service for browser and Node.js
259
+ *
260
+ * This service automatically routes operations to:
261
+ * - API backend (browser) - using WdkApiClient
262
+ * - Native WDK (Node.js) - using WdkService
263
+ * - Browser derivation (fallback) - using BrowserAddressDerivation
264
+ */
265
+ declare class ZubariWdkService {
201
266
  private config;
202
- private wallets;
203
- constructor(config?: Partial<WdkServiceConfig>);
267
+ private apiClient;
268
+ private nativeWdkService;
269
+ private initialized;
270
+ private useNativeWdk;
271
+ constructor(config?: Partial<ZubariWdkServiceConfig>);
204
272
  /**
205
- * Check if WDK modules are loaded
273
+ * Initialize the service and determine the best strategy
206
274
  */
207
- static isLoaded(): boolean;
275
+ initialize(): Promise<void>;
208
276
  /**
209
- * Ensure WDK modules are loaded
277
+ * Get the current execution mode
210
278
  */
211
- private ensureLoaded;
279
+ getMode(): 'api' | 'native' | 'browser-fallback';
212
280
  /**
213
- * Load WDK modules (call this before using sync methods)
281
+ * Check if running in browser
214
282
  */
215
- loadModules(): Promise<void>;
283
+ isBrowserEnvironment(): boolean;
216
284
  /**
217
- * Generate a random BIP-39 seed phrase (12 words)
285
+ * Generate a new BIP-39 seed phrase (12 words)
218
286
  */
219
- generateSeedPhrase(): Promise<string>;
287
+ generateSeed(): Promise<string>;
220
288
  /**
221
289
  * Validate a BIP-39 seed phrase
222
290
  */
223
- isValidSeed(seed: string): Promise<boolean>;
291
+ validateSeed(seed: string): Promise<boolean>;
224
292
  /**
225
- * Validate seed phrase (sync version - basic check)
293
+ * Derive address for a specific chain
226
294
  */
227
- isValidSeedSync(seed: string): boolean;
295
+ deriveAddress(seed: string, chain: SupportedChain): Promise<ChainAddress>;
228
296
  /**
229
- * Initialize the service with a seed phrase
297
+ * Derive addresses for all supported chains
230
298
  */
231
- initialize(seed: string): Promise<void>;
299
+ deriveAllAddresses(seed: string): Promise<MultiChainAddresses>;
300
+ /**
301
+ * Get balances for all chains
302
+ */
303
+ getAllBalances(seed: string): Promise<Record<string, ChainBalance | null>>;
304
+ /**
305
+ * Get fee rates for a chain
306
+ */
307
+ getFeeRates(seed: string, chain: SupportedChain): Promise<FeeRates>;
308
+ /**
309
+ * Estimate transaction fee
310
+ */
311
+ estimateFee(seed: string, chain: SupportedChain, to: string, amount: string): Promise<{
312
+ fee: string;
313
+ symbol: string;
314
+ }>;
315
+ /**
316
+ * Send a transaction
317
+ */
318
+ sendTransaction(seed: string, chain: SupportedChain, to: string, amount: string): Promise<TransactionResult$1>;
319
+ /**
320
+ * Get the network configuration
321
+ */
322
+ getNetwork(): 'mainnet' | 'testnet';
323
+ /**
324
+ * Get API URL
325
+ */
326
+ getApiUrl(): string;
327
+ private getDerivationPath;
328
+ private getChainSymbol;
329
+ /**
330
+ * Derive address using browser-compatible libraries
331
+ */
332
+ private deriveBrowserAddress;
333
+ /**
334
+ * Derive all addresses using browser-compatible libraries
335
+ */
336
+ private deriveAllBrowserAddresses;
337
+ }
338
+ /**
339
+ * Get or create the default ZubariWdkService instance
340
+ */
341
+ declare function getZubariWdkService(config?: Partial<ZubariWdkServiceConfig>): ZubariWdkService;
342
+ /**
343
+ * Create a new ZubariWdkService instance
344
+ */
345
+ declare function createZubariWdkService(config?: Partial<ZubariWdkServiceConfig>): ZubariWdkService;
346
+
347
+ /**
348
+ * Transaction Service for Zubari SDK
349
+ *
350
+ * Provides multi-chain transaction capabilities using Tether WDK.
351
+ * Supports Ethereum, Bitcoin, Solana, TON, TRON, and Spark (Lightning).
352
+ *
353
+ * @see https://docs.wallet.tether.io/
354
+ */
355
+
356
+ /**
357
+ * Transaction parameters for sending
358
+ */
359
+ interface TransactionParams {
360
+ /** Recipient address */
361
+ to: string;
362
+ /** Amount to send (in human-readable format, e.g., "0.1") */
363
+ amount: string;
364
+ /** Token address (optional, for ERC-20/SPL tokens) */
365
+ token?: string;
366
+ /** Transaction memo/message (for chains that support it) */
367
+ memo?: string;
368
+ /** Fee priority: 'slow' | 'medium' | 'fast' */
369
+ feePriority?: 'slow' | 'medium' | 'fast';
370
+ /** Custom gas limit (EVM chains) */
371
+ gasLimit?: string;
372
+ /** Custom gas price (EVM chains) */
373
+ gasPrice?: string;
374
+ }
375
+ /**
376
+ * Transaction result with detailed information
377
+ */
378
+ interface TransactionResult {
379
+ /** Transaction hash */
380
+ hash: string;
381
+ /** Network/chain */
382
+ network: NetworkType;
383
+ /** Transaction status */
384
+ status: 'pending' | 'confirmed' | 'failed';
385
+ /** Block number (when confirmed) */
386
+ blockNumber?: number;
387
+ /** Gas used (EVM chains) */
388
+ gasUsed?: string;
389
+ /** Fee paid */
390
+ fee?: string;
391
+ /** Explorer URL */
392
+ explorerUrl?: string;
393
+ /** Error message if failed */
394
+ error?: string;
395
+ /** Timestamp */
396
+ timestamp: number;
397
+ }
398
+ /**
399
+ * Transaction history item
400
+ */
401
+ interface TransactionHistoryItem {
402
+ hash: string;
403
+ network: NetworkType;
404
+ type: 'send' | 'receive' | 'swap' | 'contract';
405
+ from: string;
406
+ to: string;
407
+ amount: string;
408
+ token?: string;
409
+ fee?: string;
410
+ status: 'pending' | 'confirmed' | 'failed';
411
+ timestamp: number;
412
+ blockNumber?: number;
413
+ }
414
+ /**
415
+ * Fee estimate for a transaction
416
+ */
417
+ interface FeeEstimate {
418
+ slow: {
419
+ fee: string;
420
+ estimatedTime: string;
421
+ };
422
+ medium: {
423
+ fee: string;
424
+ estimatedTime: string;
425
+ };
426
+ fast: {
427
+ fee: string;
428
+ estimatedTime: string;
429
+ };
430
+ }
431
+ /**
432
+ * Transaction Service configuration
433
+ */
434
+ interface TransactionServiceConfig {
435
+ network: 'mainnet' | 'testnet';
436
+ rpcUrls?: Partial<Record<NetworkType, string>>;
437
+ }
438
+ /**
439
+ * Transaction Service
440
+ *
441
+ * Provides multi-chain transaction capabilities:
442
+ * - Send native tokens (ETH, BTC, SOL, TON, TRX)
443
+ * - Send ERC-20/SPL tokens
444
+ * - Fee estimation
445
+ * - Transaction history
446
+ */
447
+ declare class TransactionService {
448
+ private seed;
449
+ private config;
450
+ private wallets;
451
+ constructor(config?: Partial<TransactionServiceConfig>);
452
+ /**
453
+ * Ensure WDK modules are loaded
454
+ */
455
+ private ensureLoaded;
232
456
  /**
233
457
  * Get RPC URL for a chain
234
458
  */
235
459
  private getRpcUrl;
460
+ /**
461
+ * Get explorer URL for a transaction
462
+ */
463
+ getExplorerUrl(chain: NetworkType, txHash: string): string;
464
+ /**
465
+ * Initialize the service with a seed phrase
466
+ */
467
+ initialize(seed: string): Promise<void>;
468
+ /**
469
+ * Check if service is initialized
470
+ */
471
+ isInitialized(): boolean;
236
472
  /**
237
473
  * Get or create wallet instance for a specific chain
238
474
  */
239
475
  private getWallet;
240
476
  /**
241
- * Derive address for a specific chain
477
+ * Estimate transaction fee
242
478
  */
243
- deriveAddress(chain: SupportedChain): Promise<ChainAddress>;
479
+ estimateFee(chain: NetworkType, params: TransactionParams): Promise<FeeEstimate>;
244
480
  /**
245
- * Derive addresses for all supported chains
481
+ * Send a transaction
482
+ */
483
+ send(chain: NetworkType, params: TransactionParams): Promise<TransactionResult>;
484
+ /**
485
+ * Get transaction status
246
486
  */
247
- deriveAllAddresses(): Promise<MultiChainAddresses>;
487
+ getTransactionStatus(chain: NetworkType, txHash: string): Promise<TransactionResult>;
248
488
  /**
249
- * Derive addresses for specific chains only
489
+ * Get transaction history for an address
250
490
  */
251
- deriveAddressesForChains(chains: SupportedChain[]): Promise<Partial<MultiChainAddresses>>;
491
+ getTransactionHistory(chain: NetworkType, limit?: number): Promise<TransactionHistoryItem[]>;
252
492
  /**
253
- * Get fee rates for a specific chain
493
+ * Get balance for a specific chain
254
494
  */
255
- getFeeRates(chain: SupportedChain): Promise<{
256
- slow: string;
257
- medium: string;
258
- fast: string;
495
+ getBalance(chain: NetworkType): Promise<{
496
+ balance: string;
497
+ balanceUsd: number;
259
498
  }>;
260
499
  /**
261
500
  * Get the current network configuration
262
501
  */
263
502
  getNetwork(): 'mainnet' | 'testnet';
264
- /**
265
- * Check if service is initialized
266
- */
267
- isInitialized(): boolean;
268
503
  /**
269
504
  * Clean up and dispose of wallet instances
270
505
  */
271
506
  dispose(): void;
272
507
  }
273
508
  /**
274
- * Get or create the WDK service singleton
509
+ * Get or create the Transaction service singleton
275
510
  */
276
- declare function getWdkService(config?: Partial<WdkServiceConfig>): WdkService;
511
+ declare function getTransactionService(config?: Partial<TransactionServiceConfig>): TransactionService;
277
512
  /**
278
- * Create a new WDK service instance (non-singleton)
513
+ * Create a new Transaction service instance (non-singleton)
279
514
  */
280
- declare function createWdkService(config?: Partial<WdkServiceConfig>): WdkService;
515
+ declare function createTransactionService(config?: Partial<TransactionServiceConfig>): TransactionService;
281
516
 
282
- export { BrowserAddressDerivation, type ChainAddress$1 as BrowserChainAddress, type BrowserMultiChainAddresses, type ChainAddress, type DeriveAddressResponse, type DeriveAllAddressesResponse, type GenerateSeedResponse, type MultiChainAddresses, type SupportedChain, type ValidateSeedResponse, WdkApiClient, type WdkApiConfig, WdkService, type WdkServiceConfig, createWdkService, getWdkApiClient, getWdkService };
517
+ export { BrowserAddressDerivation, type ChainAddress$1 as BrowserChainAddress, type BrowserMultiChainAddresses, type ChainAddress, type ChainBalance, type DeriveAddressResponse, type DeriveAllAddressesResponse, type FeeEstimate, type FeeRates, type GenerateSeedResponse, type MultiChainAddresses, type SupportedChain, SwapService, type TransactionHistoryItem, type TransactionParams, type TransactionResult, TransactionService, type TransactionServiceConfig, type ValidateSeedResponse, WdkApiClient, type WdkApiConfig, type TransactionResult$1 as WdkTransactionResult, ZubariWdkService, type ZubariWdkServiceConfig, createTransactionService, createZubariWdkService, getTransactionService, getWdkApiClient, getZubariWdkService, isBrowser };