@zubari/sdk 0.2.4 → 0.2.5

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.
@@ -0,0 +1,579 @@
1
+ import { o as SwapQuote, c as TxResult, a as NetworkType } from './index-Cx389p_j.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
+ }
34
+
35
+ /**
36
+ * WDK API Client
37
+ *
38
+ * Client for calling the backend WDK endpoints to derive addresses
39
+ * using Tether WDK (which runs server-side in Node.js).
40
+ */
41
+
42
+ interface WdkApiConfig {
43
+ baseUrl: string;
44
+ timeout?: number;
45
+ }
46
+ interface DeriveAddressResponse {
47
+ success: boolean;
48
+ address?: string;
49
+ chain?: string;
50
+ path?: string;
51
+ network?: string;
52
+ error?: string;
53
+ }
54
+ interface DeriveAllAddressesResponse {
55
+ success: boolean;
56
+ addresses?: {
57
+ ethereum: string | null;
58
+ bitcoin: string | null;
59
+ ton: string | null;
60
+ tron: string | null;
61
+ solana: string | null;
62
+ spark: string | null;
63
+ };
64
+ network?: string;
65
+ error?: string;
66
+ }
67
+ interface ValidateSeedResponse {
68
+ success: boolean;
69
+ isValid?: boolean;
70
+ wordCount?: number;
71
+ error?: string;
72
+ }
73
+ interface GenerateSeedResponse {
74
+ success: boolean;
75
+ seed?: string;
76
+ wordCount?: number;
77
+ error?: string;
78
+ }
79
+ interface TransactionHistoryItem$1 {
80
+ hash: string;
81
+ from: string;
82
+ to: string;
83
+ value: string;
84
+ timestamp: number;
85
+ status: 'confirmed' | 'pending' | 'failed';
86
+ blockNumber?: number;
87
+ }
88
+ interface TransactionHistoryResponse {
89
+ success: boolean;
90
+ address?: string;
91
+ transactions?: TransactionHistoryItem$1[];
92
+ chain?: string;
93
+ network?: string;
94
+ error?: string;
95
+ }
96
+ interface SendTransactionResponse {
97
+ success: boolean;
98
+ txHash?: string;
99
+ from?: string;
100
+ to?: string;
101
+ amount?: string;
102
+ chain?: string;
103
+ network?: string;
104
+ error?: string;
105
+ }
106
+ interface TransactionStatusResponse {
107
+ success: boolean;
108
+ hash?: string;
109
+ status?: 'confirmed' | 'pending' | 'failed';
110
+ blockNumber?: number;
111
+ confirmations?: number;
112
+ timestamp?: number;
113
+ from?: string;
114
+ to?: string;
115
+ value?: string;
116
+ fee?: string;
117
+ chain?: string;
118
+ network?: string;
119
+ error?: string;
120
+ }
121
+ /**
122
+ * WDK API Client for server-side Tether WDK integration
123
+ */
124
+ declare class WdkApiClient {
125
+ private config;
126
+ constructor(config: WdkApiConfig);
127
+ /**
128
+ * Generate a new BIP-39 seed phrase using Tether WDK
129
+ */
130
+ generateSeed(): Promise<GenerateSeedResponse>;
131
+ /**
132
+ * Validate a BIP-39 seed phrase
133
+ */
134
+ validateSeed(seed: string): Promise<ValidateSeedResponse>;
135
+ /**
136
+ * Derive address for a specific chain using Tether WDK
137
+ */
138
+ deriveAddress(seed: string, chain: NetworkType, network?: 'mainnet' | 'testnet'): Promise<DeriveAddressResponse>;
139
+ /**
140
+ * Derive addresses for all chains using Tether WDK
141
+ */
142
+ deriveAllAddresses(seed: string, network?: 'mainnet' | 'testnet'): Promise<DeriveAllAddressesResponse>;
143
+ /**
144
+ * Send a transaction on a specific chain using Tether WDK
145
+ */
146
+ sendTransaction(seed: string, chain: NetworkType, to: string, amount: string, network?: 'mainnet' | 'testnet'): Promise<SendTransactionResponse>;
147
+ /**
148
+ * Get transaction history for an address on a specific chain
149
+ * Fetches from blockchain explorers (Etherscan, mempool.space, etc.)
150
+ */
151
+ getTransactionHistory(seed: string, chain: NetworkType, network?: 'mainnet' | 'testnet', limit?: number): Promise<TransactionHistoryResponse>;
152
+ /**
153
+ * Get transaction status by hash
154
+ * Fetches from blockchain explorers to check confirmation status
155
+ */
156
+ getTransactionStatus(txHash: string, chain: NetworkType, network?: 'mainnet' | 'testnet'): Promise<TransactionStatusResponse>;
157
+ }
158
+ /**
159
+ * Get or create the WDK API client instance
160
+ */
161
+ declare function getWdkApiClient(baseUrl?: string): WdkApiClient;
162
+
163
+ /**
164
+ * Browser-Compatible Address Derivation
165
+ *
166
+ * This module provides multi-chain address derivation that works in browser environments.
167
+ * It uses the @scure libraries which are pure JS and don't require Node.js polyfills.
168
+ *
169
+ * Supported chains:
170
+ * - Ethereum: ethers.js (BIP-44)
171
+ * - Bitcoin: @scure/bip32 + @scure/base (BIP-84 native SegWit)
172
+ * - Solana: ed25519-hd-key + tweetnacl (SLIP-0010)
173
+ * - TON: ed25519 derivation with TON address format
174
+ * - TRON: secp256k1 + base58check
175
+ * - Spark: Bitcoin-based with custom derivation
176
+ */
177
+
178
+ interface ChainAddress$1 {
179
+ chain: NetworkType;
180
+ address: string;
181
+ path: string;
182
+ }
183
+ interface BrowserMultiChainAddresses {
184
+ ethereum: string | null;
185
+ bitcoin: string | null;
186
+ ton: string | null;
187
+ tron: string | null;
188
+ solana: string | null;
189
+ spark: string | null;
190
+ }
191
+ /**
192
+ * Derive Ethereum address from seed phrase
193
+ */
194
+ declare function deriveEthereumAddress(seed: string): string;
195
+ /**
196
+ * Derive Bitcoin address from seed phrase (BIP-84 native SegWit)
197
+ * Uses @scure libraries for browser compatibility
198
+ */
199
+ declare function deriveBitcoinAddress(seed: string, network?: 'mainnet' | 'testnet'): string;
200
+ /**
201
+ * Derive Solana address from seed phrase using SLIP-0010 (ed25519)
202
+ */
203
+ declare function deriveSolanaAddress(seed: string): Promise<string>;
204
+ /**
205
+ * Derive TON address from seed phrase
206
+ * Uses proper BIP-44 derivation path m/44'/607'/0'/0'/0'
207
+ */
208
+ declare function deriveTonAddress(seed: string): Promise<string>;
209
+ /**
210
+ * Derive TRON address from seed phrase
211
+ * TRON uses secp256k1 like Ethereum but with base58check encoding
212
+ * Uses @scure/base for browser compatibility
213
+ */
214
+ declare function deriveTronAddress(seed: string): string;
215
+ /**
216
+ * Derive Spark address from seed phrase
217
+ * Spark uses its own derivation path and bech32 format
218
+ * Uses @scure libraries for browser compatibility
219
+ */
220
+ declare function deriveSparkAddress(seed: string, network?: 'mainnet' | 'testnet'): string;
221
+ /**
222
+ * Derive addresses for all supported chains
223
+ */
224
+ declare function deriveAllAddresses(seed: string, network?: 'mainnet' | 'testnet'): Promise<BrowserMultiChainAddresses>;
225
+ /**
226
+ * Validate a BIP-39 seed phrase using @scure/bip39
227
+ */
228
+ declare function isValidSeed(seed: string): boolean;
229
+ /**
230
+ * Generate a random BIP-39 seed phrase using @scure/bip39
231
+ */
232
+ declare function generateSeedPhrase(): string;
233
+
234
+ type BrowserAddressDerivation_BrowserMultiChainAddresses = BrowserMultiChainAddresses;
235
+ declare const BrowserAddressDerivation_deriveAllAddresses: typeof deriveAllAddresses;
236
+ declare const BrowserAddressDerivation_deriveBitcoinAddress: typeof deriveBitcoinAddress;
237
+ declare const BrowserAddressDerivation_deriveEthereumAddress: typeof deriveEthereumAddress;
238
+ declare const BrowserAddressDerivation_deriveSolanaAddress: typeof deriveSolanaAddress;
239
+ declare const BrowserAddressDerivation_deriveSparkAddress: typeof deriveSparkAddress;
240
+ declare const BrowserAddressDerivation_deriveTonAddress: typeof deriveTonAddress;
241
+ declare const BrowserAddressDerivation_deriveTronAddress: typeof deriveTronAddress;
242
+ declare const BrowserAddressDerivation_generateSeedPhrase: typeof generateSeedPhrase;
243
+ declare const BrowserAddressDerivation_isValidSeed: typeof isValidSeed;
244
+ declare namespace BrowserAddressDerivation {
245
+ export { type BrowserAddressDerivation_BrowserMultiChainAddresses as BrowserMultiChainAddresses, type ChainAddress$1 as ChainAddress, BrowserAddressDerivation_deriveAllAddresses as deriveAllAddresses, BrowserAddressDerivation_deriveBitcoinAddress as deriveBitcoinAddress, BrowserAddressDerivation_deriveEthereumAddress as deriveEthereumAddress, BrowserAddressDerivation_deriveSolanaAddress as deriveSolanaAddress, BrowserAddressDerivation_deriveSparkAddress as deriveSparkAddress, BrowserAddressDerivation_deriveTonAddress as deriveTonAddress, BrowserAddressDerivation_deriveTronAddress as deriveTronAddress, BrowserAddressDerivation_generateSeedPhrase as generateSeedPhrase, BrowserAddressDerivation_isValidSeed as isValidSeed };
246
+ }
247
+
248
+ /**
249
+ * Zubari WDK Service - Unified Multi-Chain Wallet Service
250
+ *
251
+ * This service provides a unified interface for multi-chain wallet operations
252
+ * that works in both browser and Node.js environments.
253
+ *
254
+ * Strategy:
255
+ * - Browser: Uses WdkApiClient to call the backend API (which has Tether WDK)
256
+ * - Node.js: Uses WdkService natively (with Tether WDK modules)
257
+ *
258
+ * The Tether WDK (@tetherto/wdk-*) only works in Node.js environments due to
259
+ * native dependencies (Electrum client, gRPC, etc.). For browser environments,
260
+ * we route all operations through the backend API.
261
+ *
262
+ * @see https://docs.wallet.tether.io/
263
+ */
264
+ type SupportedChain = 'ethereum' | 'bitcoin' | 'ton' | 'tron' | 'solana' | 'spark';
265
+ interface ChainAddress {
266
+ chain: SupportedChain;
267
+ address: string;
268
+ path: string;
269
+ }
270
+ interface MultiChainAddresses {
271
+ ethereum: string | null;
272
+ bitcoin: string | null;
273
+ ton: string | null;
274
+ tron: string | null;
275
+ solana: string | null;
276
+ spark: string | null;
277
+ }
278
+ interface ChainBalance {
279
+ chain: SupportedChain;
280
+ address: string;
281
+ balance: string;
282
+ symbol: string;
283
+ }
284
+ interface FeeRates {
285
+ slow: string;
286
+ normal: string;
287
+ fast: string;
288
+ }
289
+ interface TransactionResult$1 {
290
+ success: boolean;
291
+ txHash?: string;
292
+ from?: string;
293
+ to?: string;
294
+ amount?: string;
295
+ chain?: string;
296
+ network?: string;
297
+ error?: string;
298
+ }
299
+ interface ZubariWdkServiceConfig {
300
+ /** Network to use (mainnet or testnet) */
301
+ network: 'mainnet' | 'testnet';
302
+ /** API URL for the Zubari backend (required for browser environments) */
303
+ apiUrl?: string;
304
+ /** Force using API even in Node.js (useful for testing) */
305
+ forceApi?: boolean;
306
+ /** Request timeout in milliseconds */
307
+ timeout?: number;
308
+ }
309
+ /**
310
+ * Check if we're running in a browser environment
311
+ */
312
+ declare function isBrowser(): boolean;
313
+ /**
314
+ * ZubariWdkService - Unified wallet service for browser and Node.js
315
+ *
316
+ * This service automatically routes operations to:
317
+ * - API backend (browser) - using WdkApiClient
318
+ * - Native WDK (Node.js) - using WdkService
319
+ * - Browser derivation (fallback) - using BrowserAddressDerivation
320
+ */
321
+ declare class ZubariWdkService {
322
+ private config;
323
+ private apiClient;
324
+ private nativeWdkService;
325
+ private initialized;
326
+ private useNativeWdk;
327
+ constructor(config?: Partial<ZubariWdkServiceConfig>);
328
+ /**
329
+ * Initialize the service and determine the best strategy
330
+ */
331
+ initialize(): Promise<void>;
332
+ /**
333
+ * Get the current execution mode
334
+ */
335
+ getMode(): 'api' | 'native' | 'browser-fallback';
336
+ /**
337
+ * Check if running in browser
338
+ */
339
+ isBrowserEnvironment(): boolean;
340
+ /**
341
+ * Generate a new BIP-39 seed phrase (12 words)
342
+ */
343
+ generateSeed(): Promise<string>;
344
+ /**
345
+ * Validate a BIP-39 seed phrase
346
+ */
347
+ validateSeed(seed: string): Promise<boolean>;
348
+ /**
349
+ * Derive address for a specific chain using WDK API
350
+ *
351
+ * For Ethereum, falls back to local derivation if API fails.
352
+ * For other chains, WDK API is required - no placeholder fallback.
353
+ */
354
+ deriveAddress(seed: string, chain: SupportedChain): Promise<ChainAddress>;
355
+ /**
356
+ * Derive addresses for all supported chains using WDK API
357
+ *
358
+ * Uses the backend WDK API for real cryptographically valid addresses.
359
+ * No placeholder fallback - WDK API is required for multi-chain addresses.
360
+ */
361
+ deriveAllAddresses(seed: string): Promise<MultiChainAddresses>;
362
+ /**
363
+ * Get balances for all chains
364
+ */
365
+ getAllBalances(seed: string): Promise<Record<string, ChainBalance | null>>;
366
+ /**
367
+ * Get fee rates for a chain
368
+ */
369
+ getFeeRates(seed: string, chain: SupportedChain): Promise<FeeRates>;
370
+ /**
371
+ * Estimate transaction fee
372
+ */
373
+ estimateFee(seed: string, chain: SupportedChain, to: string, amount: string): Promise<{
374
+ fee: string;
375
+ symbol: string;
376
+ }>;
377
+ /**
378
+ * Send a transaction
379
+ */
380
+ sendTransaction(seed: string, chain: SupportedChain, to: string, amount: string): Promise<TransactionResult$1>;
381
+ /**
382
+ * Get the network configuration
383
+ */
384
+ getNetwork(): 'mainnet' | 'testnet';
385
+ /**
386
+ * Get API URL
387
+ */
388
+ getApiUrl(): string;
389
+ private getDerivationPath;
390
+ private getChainSymbol;
391
+ /**
392
+ * Derive address using browser-compatible libraries
393
+ */
394
+ private deriveBrowserAddress;
395
+ /**
396
+ * Derive all addresses using browser-compatible libraries
397
+ */
398
+ private deriveAllBrowserAddresses;
399
+ }
400
+ /**
401
+ * Get or create the default ZubariWdkService instance
402
+ */
403
+ declare function getZubariWdkService(config?: Partial<ZubariWdkServiceConfig>): ZubariWdkService;
404
+ /**
405
+ * Create a new ZubariWdkService instance
406
+ */
407
+ declare function createZubariWdkService(config?: Partial<ZubariWdkServiceConfig>): ZubariWdkService;
408
+
409
+ /**
410
+ * Transaction Service for Zubari SDK
411
+ *
412
+ * Provides multi-chain transaction capabilities using Tether WDK.
413
+ * Supports Ethereum, Bitcoin, Solana, TON, TRON, and Spark (Lightning).
414
+ *
415
+ * @see https://docs.wallet.tether.io/
416
+ */
417
+
418
+ /**
419
+ * Transaction parameters for sending
420
+ */
421
+ interface TransactionParams {
422
+ /** Recipient address */
423
+ to: string;
424
+ /** Amount to send (in human-readable format, e.g., "0.1") */
425
+ amount: string;
426
+ /** Token address (optional, for ERC-20/SPL tokens) */
427
+ token?: string;
428
+ /** Transaction memo/message (for chains that support it) */
429
+ memo?: string;
430
+ /** Fee priority: 'slow' | 'medium' | 'fast' */
431
+ feePriority?: 'slow' | 'medium' | 'fast';
432
+ /** Custom gas limit (EVM chains) */
433
+ gasLimit?: string;
434
+ /** Custom gas price (EVM chains) */
435
+ gasPrice?: string;
436
+ }
437
+ /**
438
+ * Transaction result with detailed information
439
+ */
440
+ interface TransactionResult {
441
+ /** Transaction hash */
442
+ hash: string;
443
+ /** Network/chain */
444
+ network: NetworkType;
445
+ /** Transaction status */
446
+ status: 'pending' | 'confirmed' | 'failed';
447
+ /** Block number (when confirmed) */
448
+ blockNumber?: number;
449
+ /** Gas used (EVM chains) */
450
+ gasUsed?: string;
451
+ /** Fee paid */
452
+ fee?: string;
453
+ /** Explorer URL */
454
+ explorerUrl?: string;
455
+ /** Error message if failed */
456
+ error?: string;
457
+ /** Timestamp */
458
+ timestamp: number;
459
+ }
460
+ /**
461
+ * Transaction history item
462
+ */
463
+ interface TransactionHistoryItem {
464
+ hash: string;
465
+ network: NetworkType;
466
+ type: 'send' | 'receive' | 'swap' | 'contract';
467
+ from: string;
468
+ to: string;
469
+ amount: string;
470
+ token?: string;
471
+ fee?: string;
472
+ status: 'pending' | 'confirmed' | 'failed';
473
+ timestamp: number;
474
+ blockNumber?: number;
475
+ }
476
+ /**
477
+ * Fee estimate for a transaction
478
+ */
479
+ interface FeeEstimate {
480
+ slow: {
481
+ fee: string;
482
+ estimatedTime: string;
483
+ };
484
+ medium: {
485
+ fee: string;
486
+ estimatedTime: string;
487
+ };
488
+ fast: {
489
+ fee: string;
490
+ estimatedTime: string;
491
+ };
492
+ }
493
+ /**
494
+ * Transaction Service configuration
495
+ */
496
+ interface TransactionServiceConfig {
497
+ network: 'mainnet' | 'testnet';
498
+ rpcUrls?: Partial<Record<NetworkType, string>>;
499
+ }
500
+ /**
501
+ * Transaction Service
502
+ *
503
+ * Provides multi-chain transaction capabilities:
504
+ * - Send native tokens (ETH, BTC, SOL, TON, TRX)
505
+ * - Send ERC-20/SPL tokens
506
+ * - Fee estimation
507
+ * - Transaction history
508
+ */
509
+ declare class TransactionService {
510
+ private seed;
511
+ private config;
512
+ private wallets;
513
+ constructor(config?: Partial<TransactionServiceConfig>);
514
+ /**
515
+ * Ensure WDK modules are loaded
516
+ */
517
+ private ensureLoaded;
518
+ /**
519
+ * Get RPC URL for a chain
520
+ */
521
+ private getRpcUrl;
522
+ /**
523
+ * Get explorer URL for a transaction
524
+ */
525
+ getExplorerUrl(chain: NetworkType, txHash: string): string;
526
+ /**
527
+ * Initialize the service with a seed phrase
528
+ */
529
+ initialize(seed: string): Promise<void>;
530
+ /**
531
+ * Check if service is initialized
532
+ */
533
+ isInitialized(): boolean;
534
+ /**
535
+ * Get or create wallet instance for a specific chain
536
+ */
537
+ private getWallet;
538
+ /**
539
+ * Estimate transaction fee
540
+ */
541
+ estimateFee(chain: NetworkType, params: TransactionParams): Promise<FeeEstimate>;
542
+ /**
543
+ * Send a transaction
544
+ */
545
+ send(chain: NetworkType, params: TransactionParams): Promise<TransactionResult>;
546
+ /**
547
+ * Get transaction status
548
+ */
549
+ getTransactionStatus(chain: NetworkType, txHash: string): Promise<TransactionResult>;
550
+ /**
551
+ * Get transaction history for an address
552
+ */
553
+ getTransactionHistory(chain: NetworkType, limit?: number): Promise<TransactionHistoryItem[]>;
554
+ /**
555
+ * Get balance for a specific chain
556
+ */
557
+ getBalance(chain: NetworkType): Promise<{
558
+ balance: string;
559
+ balanceUsd: number;
560
+ }>;
561
+ /**
562
+ * Get the current network configuration
563
+ */
564
+ getNetwork(): 'mainnet' | 'testnet';
565
+ /**
566
+ * Clean up and dispose of wallet instances
567
+ */
568
+ dispose(): void;
569
+ }
570
+ /**
571
+ * Get or create the Transaction service singleton
572
+ */
573
+ declare function getTransactionService(config?: Partial<TransactionServiceConfig>): TransactionService;
574
+ /**
575
+ * Create a new Transaction service instance (non-singleton)
576
+ */
577
+ declare function createTransactionService(config?: Partial<TransactionServiceConfig>): TransactionService;
578
+
579
+ export { BrowserAddressDerivation as B, type ChainAddress$1 as C, type DeriveAddressResponse as D, type FeeRates as F, type GenerateSeedResponse as G, type MultiChainAddresses as M, SwapService as S, type TransactionHistoryItem$1 as T, type ValidateSeedResponse as V, WdkApiClient as W, ZubariWdkService as Z, type BrowserMultiChainAddresses as a, type WdkApiConfig as b, type DeriveAllAddressesResponse as c, type TransactionHistoryResponse as d, type SendTransactionResponse as e, type TransactionStatusResponse as f, getWdkApiClient as g, getZubariWdkService as h, createZubariWdkService as i, isBrowser as j, type SupportedChain as k, type ChainAddress as l, type ChainBalance as m, type TransactionResult$1 as n, type ZubariWdkServiceConfig as o, TransactionService as p, getTransactionService as q, createTransactionService as r, type TransactionParams as s, type TransactionResult as t, type TransactionHistoryItem as u, type FeeEstimate as v, type TransactionServiceConfig as w };