@zubari/sdk 0.1.5 → 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-CxwB1kpN.mjs';
2
- import { N as NetworkType } from '../index-DhluuR9H.mjs';
1
+ import { k as SwapQuote, b as TxResult, N as NetworkType } from '../index-DhluuR9H.mjs';
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
@@ -159,13 +190,18 @@ declare namespace BrowserAddressDerivation {
159
190
  }
160
191
 
161
192
  /**
162
- * WDK Service for SDK
193
+ * Zubari WDK Service - Unified Multi-Chain Wallet Service
163
194
  *
164
- * Native integration with Tether WDK for multi-chain address derivation.
165
- * Uses individual wallet modules for each chain to derive cryptographically
166
- * 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.
167
197
  *
168
- * 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.
169
205
  *
170
206
  * @see https://docs.wallet.tether.io/
171
207
  */
@@ -183,101 +219,299 @@ interface MultiChainAddresses {
183
219
  solana: string | null;
184
220
  spark: string | null;
185
221
  }
186
- 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) */
187
245
  network: 'mainnet' | 'testnet';
188
- rpcUrls?: {
189
- ethereum?: string;
190
- bitcoin?: string;
191
- solana?: string;
192
- ton?: string;
193
- tron?: string;
194
- };
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;
195
252
  }
196
253
  /**
197
- * WDK Service for native multi-chain address derivation
198
- * Uses Tether WDK wallet modules directly without needing a backend API
254
+ * Check if we're running in a browser environment
199
255
  */
200
- declare class WdkService {
201
- 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 {
202
266
  private config;
203
- private wallets;
204
- constructor(config?: Partial<WdkServiceConfig>);
267
+ private apiClient;
268
+ private nativeWdkService;
269
+ private initialized;
270
+ private useNativeWdk;
271
+ constructor(config?: Partial<ZubariWdkServiceConfig>);
205
272
  /**
206
- * Check if WDK modules are loaded
273
+ * Initialize the service and determine the best strategy
207
274
  */
208
- static isLoaded(): boolean;
275
+ initialize(): Promise<void>;
209
276
  /**
210
- * Ensure WDK modules are loaded
277
+ * Get the current execution mode
211
278
  */
212
- private ensureLoaded;
279
+ getMode(): 'api' | 'native' | 'browser-fallback';
213
280
  /**
214
- * Load WDK modules (call this before using sync methods)
281
+ * Check if running in browser
215
282
  */
216
- loadModules(): Promise<void>;
283
+ isBrowserEnvironment(): boolean;
217
284
  /**
218
- * Generate a random BIP-39 seed phrase (12 words)
285
+ * Generate a new BIP-39 seed phrase (12 words)
219
286
  */
220
- generateSeedPhrase(): Promise<string>;
287
+ generateSeed(): Promise<string>;
221
288
  /**
222
289
  * Validate a BIP-39 seed phrase
223
290
  */
224
- isValidSeed(seed: string): Promise<boolean>;
291
+ validateSeed(seed: string): Promise<boolean>;
225
292
  /**
226
- * Validate seed phrase (sync version - basic check)
293
+ * Derive address for a specific chain
227
294
  */
228
- isValidSeedSync(seed: string): boolean;
295
+ deriveAddress(seed: string, chain: SupportedChain): Promise<ChainAddress>;
229
296
  /**
230
- * Initialize the service with a seed phrase
297
+ * Derive addresses for all supported chains
231
298
  */
232
- 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;
233
456
  /**
234
457
  * Get RPC URL for a chain
235
458
  */
236
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;
237
472
  /**
238
473
  * Get or create wallet instance for a specific chain
239
474
  */
240
475
  private getWallet;
241
476
  /**
242
- * Derive address for a specific chain
477
+ * Estimate transaction fee
243
478
  */
244
- deriveAddress(chain: SupportedChain): Promise<ChainAddress>;
479
+ estimateFee(chain: NetworkType, params: TransactionParams): Promise<FeeEstimate>;
245
480
  /**
246
- * Derive addresses for all supported chains
481
+ * Send a transaction
482
+ */
483
+ send(chain: NetworkType, params: TransactionParams): Promise<TransactionResult>;
484
+ /**
485
+ * Get transaction status
247
486
  */
248
- deriveAllAddresses(): Promise<MultiChainAddresses>;
487
+ getTransactionStatus(chain: NetworkType, txHash: string): Promise<TransactionResult>;
249
488
  /**
250
- * Derive addresses for specific chains only
489
+ * Get transaction history for an address
251
490
  */
252
- deriveAddressesForChains(chains: SupportedChain[]): Promise<Partial<MultiChainAddresses>>;
491
+ getTransactionHistory(chain: NetworkType, limit?: number): Promise<TransactionHistoryItem[]>;
253
492
  /**
254
- * Get fee rates for a specific chain
493
+ * Get balance for a specific chain
255
494
  */
256
- getFeeRates(chain: SupportedChain): Promise<{
257
- slow: string;
258
- medium: string;
259
- fast: string;
495
+ getBalance(chain: NetworkType): Promise<{
496
+ balance: string;
497
+ balanceUsd: number;
260
498
  }>;
261
499
  /**
262
500
  * Get the current network configuration
263
501
  */
264
502
  getNetwork(): 'mainnet' | 'testnet';
265
- /**
266
- * Check if service is initialized
267
- */
268
- isInitialized(): boolean;
269
503
  /**
270
504
  * Clean up and dispose of wallet instances
271
505
  */
272
506
  dispose(): void;
273
507
  }
274
508
  /**
275
- * Get or create the WDK service singleton
509
+ * Get or create the Transaction service singleton
276
510
  */
277
- declare function getWdkService(config?: Partial<WdkServiceConfig>): WdkService;
511
+ declare function getTransactionService(config?: Partial<TransactionServiceConfig>): TransactionService;
278
512
  /**
279
- * Create a new WDK service instance (non-singleton)
513
+ * Create a new Transaction service instance (non-singleton)
280
514
  */
281
- declare function createWdkService(config?: Partial<WdkServiceConfig>): WdkService;
515
+ declare function createTransactionService(config?: Partial<TransactionServiceConfig>): TransactionService;
282
516
 
283
- 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 };