@zubari/sdk 0.4.5 → 0.5.1
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/dist/{TransactionService-Djonkbp4.d.ts → TransactionService-BtWUjKt_.d.ts} +14 -2
- package/dist/{TransactionService-1Jt8ZRqO.d.mts → TransactionService-Lr_WS6iR.d.mts} +14 -2
- package/dist/{WalletManager-DfvFJ-mk.d.ts → WalletManager-DQQwVkoa.d.ts} +4 -0
- package/dist/{WalletManager-j0tgNIKi.d.mts → WalletManager-Sbpx4E1-.d.mts} +4 -0
- package/dist/{contracts-BahTuxZj.d.mts → contracts-B842YprC.d.mts} +2 -2
- package/dist/{contracts-D7rVmNJy.d.ts → contracts-s_CDIruh.d.ts} +2 -2
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +305 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +306 -24
- package/dist/index.mjs.map +1 -1
- package/dist/protocols/index.js +2 -2
- package/dist/protocols/index.js.map +1 -1
- package/dist/protocols/index.mjs +2 -2
- package/dist/protocols/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +303 -21
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +304 -22
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +1 -1
- package/dist/services/index.d.ts +1 -1
- package/dist/services/index.js +132 -8
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +132 -8
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +2 -2
- package/dist/wallet/index.d.ts +2 -2
- package/dist/wallet/index.js +303 -21
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +304 -22
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -319,7 +319,9 @@ interface TransactionResult$1 {
|
|
|
319
319
|
chain?: string;
|
|
320
320
|
network?: string;
|
|
321
321
|
error?: string;
|
|
322
|
+
errorCode?: TransactionErrorCode;
|
|
322
323
|
}
|
|
324
|
+
type TransactionErrorCode = 'INSUFFICIENT_FUNDS' | 'INVALID_ADDRESS' | 'NETWORK_ERROR' | 'TIMEOUT' | 'REJECTED' | 'GAS_TOO_LOW' | 'NONCE_TOO_LOW' | 'MEMPOOL_FULL' | 'DUST_AMOUNT' | 'UNKNOWN';
|
|
323
325
|
interface ZubariWdkServiceConfig {
|
|
324
326
|
/** Network to use (mainnet or testnet) */
|
|
325
327
|
network: 'mainnet' | 'testnet';
|
|
@@ -399,9 +401,19 @@ declare class ZubariWdkService {
|
|
|
399
401
|
symbol: string;
|
|
400
402
|
}>;
|
|
401
403
|
/**
|
|
402
|
-
* Send a transaction
|
|
404
|
+
* Send a transaction on any supported chain
|
|
405
|
+
*
|
|
406
|
+
* @param seed - BIP-39 seed phrase
|
|
407
|
+
* @param chain - Target blockchain (ethereum, bitcoin, solana, ton, tron, spark)
|
|
408
|
+
* @param to - Recipient address
|
|
409
|
+
* @param amount - Amount to send (in native units: ETH, BTC, SOL, etc.)
|
|
410
|
+
* @returns Transaction result with hash on success, or error details on failure
|
|
403
411
|
*/
|
|
404
412
|
sendTransaction(seed: string, chain: SupportedChain, to: string, amount: string): Promise<TransactionResult$1>;
|
|
413
|
+
/**
|
|
414
|
+
* Validate transaction hash format for a specific chain
|
|
415
|
+
*/
|
|
416
|
+
private validateTxHash;
|
|
405
417
|
/**
|
|
406
418
|
* Get the network configuration
|
|
407
419
|
*/
|
|
@@ -600,4 +612,4 @@ declare function getTransactionService(config?: Partial<TransactionServiceConfig
|
|
|
600
612
|
*/
|
|
601
613
|
declare function createTransactionService(config?: Partial<TransactionServiceConfig>): TransactionService;
|
|
602
614
|
|
|
603
|
-
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
|
|
615
|
+
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 TransactionErrorCode as o, type ZubariWdkServiceConfig as p, TransactionService as q, getTransactionService as r, createTransactionService as s, type TransactionParams as t, type TransactionResult as u, type TransactionHistoryItem as v, type FeeEstimate as w, type TransactionServiceConfig as x };
|
|
@@ -319,7 +319,9 @@ interface TransactionResult$1 {
|
|
|
319
319
|
chain?: string;
|
|
320
320
|
network?: string;
|
|
321
321
|
error?: string;
|
|
322
|
+
errorCode?: TransactionErrorCode;
|
|
322
323
|
}
|
|
324
|
+
type TransactionErrorCode = 'INSUFFICIENT_FUNDS' | 'INVALID_ADDRESS' | 'NETWORK_ERROR' | 'TIMEOUT' | 'REJECTED' | 'GAS_TOO_LOW' | 'NONCE_TOO_LOW' | 'MEMPOOL_FULL' | 'DUST_AMOUNT' | 'UNKNOWN';
|
|
323
325
|
interface ZubariWdkServiceConfig {
|
|
324
326
|
/** Network to use (mainnet or testnet) */
|
|
325
327
|
network: 'mainnet' | 'testnet';
|
|
@@ -399,9 +401,19 @@ declare class ZubariWdkService {
|
|
|
399
401
|
symbol: string;
|
|
400
402
|
}>;
|
|
401
403
|
/**
|
|
402
|
-
* Send a transaction
|
|
404
|
+
* Send a transaction on any supported chain
|
|
405
|
+
*
|
|
406
|
+
* @param seed - BIP-39 seed phrase
|
|
407
|
+
* @param chain - Target blockchain (ethereum, bitcoin, solana, ton, tron, spark)
|
|
408
|
+
* @param to - Recipient address
|
|
409
|
+
* @param amount - Amount to send (in native units: ETH, BTC, SOL, etc.)
|
|
410
|
+
* @returns Transaction result with hash on success, or error details on failure
|
|
403
411
|
*/
|
|
404
412
|
sendTransaction(seed: string, chain: SupportedChain, to: string, amount: string): Promise<TransactionResult$1>;
|
|
413
|
+
/**
|
|
414
|
+
* Validate transaction hash format for a specific chain
|
|
415
|
+
*/
|
|
416
|
+
private validateTxHash;
|
|
405
417
|
/**
|
|
406
418
|
* Get the network configuration
|
|
407
419
|
*/
|
|
@@ -600,4 +612,4 @@ declare function getTransactionService(config?: Partial<TransactionServiceConfig
|
|
|
600
612
|
*/
|
|
601
613
|
declare function createTransactionService(config?: Partial<TransactionServiceConfig>): TransactionService;
|
|
602
614
|
|
|
603
|
-
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
|
|
615
|
+
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 TransactionErrorCode as o, type ZubariWdkServiceConfig as p, TransactionService as q, getTransactionService as r, createTransactionService as s, type TransactionParams as t, type TransactionResult as u, type TransactionHistoryItem as v, type FeeEstimate as w, type TransactionServiceConfig as x };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Z as ZubariWalletConfig, b as NetworkType, A as Account, c as NetworkBalance, e as SendParams, T as TxResult } from './index-CTyZlHKg.mjs';
|
|
2
|
-
import './WalletManager-
|
|
2
|
+
import './WalletManager-Sbpx4E1-.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ZubariWallet - Multi-chain self-custodial wallet
|
|
@@ -193,7 +193,7 @@ declare const NFT_VOUCHER_TYPES: {
|
|
|
193
193
|
declare const CURRENCY_ADDRESSES: {
|
|
194
194
|
readonly testnet: {
|
|
195
195
|
readonly ETH: "0x0000000000000000000000000000000000000000";
|
|
196
|
-
readonly USDT: "
|
|
196
|
+
readonly USDT: "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06";
|
|
197
197
|
};
|
|
198
198
|
readonly mainnet: {
|
|
199
199
|
readonly ETH: "0x0000000000000000000000000000000000000000";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Z as ZubariWalletConfig, b as NetworkType, A as Account, c as NetworkBalance, e as SendParams, T as TxResult } from './index-CTyZlHKg.js';
|
|
2
|
-
import './WalletManager-
|
|
2
|
+
import './WalletManager-DQQwVkoa.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* ZubariWallet - Multi-chain self-custodial wallet
|
|
@@ -193,7 +193,7 @@ declare const NFT_VOUCHER_TYPES: {
|
|
|
193
193
|
declare const CURRENCY_ADDRESSES: {
|
|
194
194
|
readonly testnet: {
|
|
195
195
|
readonly ETH: "0x0000000000000000000000000000000000000000";
|
|
196
|
-
readonly USDT: "
|
|
196
|
+
readonly USDT: "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06";
|
|
197
197
|
};
|
|
198
198
|
readonly mainnet: {
|
|
199
199
|
readonly ETH: "0x0000000000000000000000000000000000000000";
|
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { C as CURRENCY_ADDRESSES, l as ContractAddresses, D as DEFAULT_CONTRACTS, F as FeeWalletConfig, M as MAINNET_FEE_WALLETS, N as NFT_VOUCHER_DOMAIN, c as NFT_VOUCHER_TYPES, P as PLATFORM_CONFIG, S as SupportedFeeChain, T as TESTNET_FEE_WALLETS, b as ZERO_ADDRESS, a as ZUBARI_CONTRACTS, Z as ZubariWallet, k as getAllFeeWallets, g as getContractAddresses, d as getCurrentContractAddresses, i as getCurrentCurrencyAddresses, h as getCurrentFeeWallet, f as getCurrentFeeWallets, e as getDefaultSubscriptionAddress, j as getFeeWallet } from './contracts-
|
|
2
|
-
export { D as DERIVATION_PATHS, N as NETWORKS, T as TESTNET_NETWORKS, b as WalletManager, W as WalletManagerConfig, a as WalletState, g as getNetworkConfig } from './WalletManager-
|
|
1
|
+
export { C as CURRENCY_ADDRESSES, l as ContractAddresses, D as DEFAULT_CONTRACTS, F as FeeWalletConfig, M as MAINNET_FEE_WALLETS, N as NFT_VOUCHER_DOMAIN, c as NFT_VOUCHER_TYPES, P as PLATFORM_CONFIG, S as SupportedFeeChain, T as TESTNET_FEE_WALLETS, b as ZERO_ADDRESS, a as ZUBARI_CONTRACTS, Z as ZubariWallet, k as getAllFeeWallets, g as getContractAddresses, d as getCurrentContractAddresses, i as getCurrentCurrencyAddresses, h as getCurrentFeeWallet, f as getCurrentFeeWallets, e as getDefaultSubscriptionAddress, j as getFeeWallet } from './contracts-B842YprC.mjs';
|
|
2
|
+
export { D as DERIVATION_PATHS, N as NETWORKS, T as TESTNET_NETWORKS, b as WalletManager, W as WalletManagerConfig, a as WalletState, g as getNetworkConfig } from './WalletManager-Sbpx4E1-.mjs';
|
|
3
3
|
export { M as MemoryStorageAdapter, S as SecureStorageAdapter, W as WebEncryptedStorageAdapter, c as createSecureStorage } from './SecureStorage-jO783AhC.mjs';
|
|
4
4
|
export { a as ZubariMarketProtocol, Z as ZubariNFTProtocol, d as ZubariPayoutsProtocol, c as ZubariSubscriptionProtocol, b as ZubariTipsProtocol } from './PayoutsProtocol-CLiMFe54.mjs';
|
|
5
5
|
export { A as Account, B as BuyParams, h as CreateVoucherParams, E as EarningsBreakdown, L as LazyMintVoucher, k as Listing, j as ListingParams, i as NFT, f as NFTAttribute, N as NFTCurrency, g as NFTMetadata, c as NetworkBalance, b as NetworkType, R as RevenueSplit, e as SendParams, a as Subscription, S as SubscriptionPlan, q as SwapParams, p as SwapQuote, o as Tip, l as TipData, m as TipResult, n as TipStats, d as TokenBalance, T as TxResult, W as WatermarkingData, s as ZubariError, r as ZubariErrorCode, Z as ZubariWalletConfig } from './index-CTyZlHKg.mjs';
|
|
6
|
-
export { B as BrowserAddressDerivation, l as ChainAddress, m as ChainBalance,
|
|
6
|
+
export { B as BrowserAddressDerivation, l as ChainAddress, m as ChainBalance, w as FeeEstimate, F as FeeRates, M as MultiChainAddresses, k as SupportedChain, S as SwapService, v as TransactionHistoryItem, t as TransactionParams, u as TransactionResult, q as TransactionService, x as TransactionServiceConfig, W as WdkApiClient, Z as ZubariWdkService, p as ZubariWdkServiceConfig, s as createTransactionService, i as createZubariWdkService, r as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from './TransactionService-Lr_WS6iR.mjs';
|
|
7
7
|
import 'abitype';
|
|
8
8
|
import 'viem';
|
|
9
9
|
import 'ethers';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { C as CURRENCY_ADDRESSES, l as ContractAddresses, D as DEFAULT_CONTRACTS, F as FeeWalletConfig, M as MAINNET_FEE_WALLETS, N as NFT_VOUCHER_DOMAIN, c as NFT_VOUCHER_TYPES, P as PLATFORM_CONFIG, S as SupportedFeeChain, T as TESTNET_FEE_WALLETS, b as ZERO_ADDRESS, a as ZUBARI_CONTRACTS, Z as ZubariWallet, k as getAllFeeWallets, g as getContractAddresses, d as getCurrentContractAddresses, i as getCurrentCurrencyAddresses, h as getCurrentFeeWallet, f as getCurrentFeeWallets, e as getDefaultSubscriptionAddress, j as getFeeWallet } from './contracts-
|
|
2
|
-
export { D as DERIVATION_PATHS, N as NETWORKS, T as TESTNET_NETWORKS, b as WalletManager, W as WalletManagerConfig, a as WalletState, g as getNetworkConfig } from './WalletManager-
|
|
1
|
+
export { C as CURRENCY_ADDRESSES, l as ContractAddresses, D as DEFAULT_CONTRACTS, F as FeeWalletConfig, M as MAINNET_FEE_WALLETS, N as NFT_VOUCHER_DOMAIN, c as NFT_VOUCHER_TYPES, P as PLATFORM_CONFIG, S as SupportedFeeChain, T as TESTNET_FEE_WALLETS, b as ZERO_ADDRESS, a as ZUBARI_CONTRACTS, Z as ZubariWallet, k as getAllFeeWallets, g as getContractAddresses, d as getCurrentContractAddresses, i as getCurrentCurrencyAddresses, h as getCurrentFeeWallet, f as getCurrentFeeWallets, e as getDefaultSubscriptionAddress, j as getFeeWallet } from './contracts-s_CDIruh.js';
|
|
2
|
+
export { D as DERIVATION_PATHS, N as NETWORKS, T as TESTNET_NETWORKS, b as WalletManager, W as WalletManagerConfig, a as WalletState, g as getNetworkConfig } from './WalletManager-DQQwVkoa.js';
|
|
3
3
|
export { M as MemoryStorageAdapter, S as SecureStorageAdapter, W as WebEncryptedStorageAdapter, c as createSecureStorage } from './SecureStorage-jO783AhC.js';
|
|
4
4
|
export { a as ZubariMarketProtocol, Z as ZubariNFTProtocol, d as ZubariPayoutsProtocol, c as ZubariSubscriptionProtocol, b as ZubariTipsProtocol } from './PayoutsProtocol-B5z8SEA-.js';
|
|
5
5
|
export { A as Account, B as BuyParams, h as CreateVoucherParams, E as EarningsBreakdown, L as LazyMintVoucher, k as Listing, j as ListingParams, i as NFT, f as NFTAttribute, N as NFTCurrency, g as NFTMetadata, c as NetworkBalance, b as NetworkType, R as RevenueSplit, e as SendParams, a as Subscription, S as SubscriptionPlan, q as SwapParams, p as SwapQuote, o as Tip, l as TipData, m as TipResult, n as TipStats, d as TokenBalance, T as TxResult, W as WatermarkingData, s as ZubariError, r as ZubariErrorCode, Z as ZubariWalletConfig } from './index-CTyZlHKg.js';
|
|
6
|
-
export { B as BrowserAddressDerivation, l as ChainAddress, m as ChainBalance,
|
|
6
|
+
export { B as BrowserAddressDerivation, l as ChainAddress, m as ChainBalance, w as FeeEstimate, F as FeeRates, M as MultiChainAddresses, k as SupportedChain, S as SwapService, v as TransactionHistoryItem, t as TransactionParams, u as TransactionResult, q as TransactionService, x as TransactionServiceConfig, W as WdkApiClient, Z as ZubariWdkService, p as ZubariWdkServiceConfig, s as createTransactionService, i as createZubariWdkService, r as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from './TransactionService-BtWUjKt_.js';
|
|
7
7
|
import 'abitype';
|
|
8
8
|
import 'viem';
|
|
9
9
|
import 'ethers';
|
package/dist/index.js
CHANGED
|
@@ -121,6 +121,38 @@ var TESTNET_NETWORKS = {
|
|
|
121
121
|
name: "Solana Devnet",
|
|
122
122
|
rpcUrl: "https://api.devnet.solana.com",
|
|
123
123
|
explorerUrl: "https://solscan.io?cluster=devnet"
|
|
124
|
+
},
|
|
125
|
+
tron: {
|
|
126
|
+
name: "TRON Nile Testnet",
|
|
127
|
+
chainId: 3448148188,
|
|
128
|
+
rpcUrl: "https://nile.trongrid.io",
|
|
129
|
+
explorerUrl: "https://nile.tronscan.org"
|
|
130
|
+
},
|
|
131
|
+
ton: {
|
|
132
|
+
name: "TON Testnet",
|
|
133
|
+
rpcUrl: "https://testnet.toncenter.com/api/v2",
|
|
134
|
+
explorerUrl: "https://testnet.tonscan.org"
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
var USDT_ADDRESSES = {
|
|
138
|
+
ethereum: {
|
|
139
|
+
mainnet: "0xdAC17F958D2ee523a2206206994597C13D831ec7",
|
|
140
|
+
testnet: "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06"
|
|
141
|
+
// Sepolia (Test Tether USD)
|
|
142
|
+
},
|
|
143
|
+
tron: {
|
|
144
|
+
mainnet: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
145
|
+
testnet: "TXYZopYRdj2D9XRtbG411XZZ3kM5VkAeBf"
|
|
146
|
+
// Nile testnet
|
|
147
|
+
},
|
|
148
|
+
solana: {
|
|
149
|
+
mainnet: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB",
|
|
150
|
+
testnet: ""
|
|
151
|
+
// No official USDT on devnet
|
|
152
|
+
},
|
|
153
|
+
ton: {
|
|
154
|
+
mainnet: "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs",
|
|
155
|
+
testnet: "kQD0GKBM8ZbryVk2aESmzfU6b9b_8era_IkvBSELujFZPsyy"
|
|
124
156
|
}
|
|
125
157
|
};
|
|
126
158
|
var DERIVATION_PATHS = {
|
|
@@ -284,8 +316,8 @@ var NFT_VOUCHER_TYPES = {
|
|
|
284
316
|
var CURRENCY_ADDRESSES = {
|
|
285
317
|
testnet: {
|
|
286
318
|
ETH: ZERO_ADDRESS,
|
|
287
|
-
USDT: "
|
|
288
|
-
// USDT on Sepolia
|
|
319
|
+
USDT: "0x7169D38820dfd117C3FA1f22a697dBA58d90BA06"
|
|
320
|
+
// USDT on Sepolia (Test Tether USD)
|
|
289
321
|
},
|
|
290
322
|
mainnet: {
|
|
291
323
|
ETH: ZERO_ADDRESS,
|
|
@@ -744,6 +776,60 @@ function generateSeedPhrase() {
|
|
|
744
776
|
|
|
745
777
|
// src/services/ZubariWdkService.ts
|
|
746
778
|
var DEFAULT_API_URL2 = "https://ckgwifsxka.us-east-2.awsapprunner.com";
|
|
779
|
+
var CHAIN_ERROR_MESSAGES = {
|
|
780
|
+
ethereum: {
|
|
781
|
+
"insufficient funds": "INSUFFICIENT_FUNDS",
|
|
782
|
+
"nonce too low": "NONCE_TOO_LOW",
|
|
783
|
+
"gas too low": "GAS_TOO_LOW",
|
|
784
|
+
"replacement transaction underpriced": "GAS_TOO_LOW",
|
|
785
|
+
"transaction underpriced": "GAS_TOO_LOW",
|
|
786
|
+
"invalid address": "INVALID_ADDRESS"
|
|
787
|
+
},
|
|
788
|
+
bitcoin: {
|
|
789
|
+
"insufficient funds": "INSUFFICIENT_FUNDS",
|
|
790
|
+
"dust": "DUST_AMOUNT",
|
|
791
|
+
"mempool": "MEMPOOL_FULL",
|
|
792
|
+
"invalid address": "INVALID_ADDRESS"
|
|
793
|
+
},
|
|
794
|
+
solana: {
|
|
795
|
+
"insufficient funds": "INSUFFICIENT_FUNDS",
|
|
796
|
+
"invalid account": "INVALID_ADDRESS",
|
|
797
|
+
"blockhash not found": "NETWORK_ERROR"
|
|
798
|
+
},
|
|
799
|
+
ton: {
|
|
800
|
+
"insufficient funds": "INSUFFICIENT_FUNDS",
|
|
801
|
+
"invalid address": "INVALID_ADDRESS"
|
|
802
|
+
},
|
|
803
|
+
tron: {
|
|
804
|
+
"insufficient funds": "INSUFFICIENT_FUNDS",
|
|
805
|
+
"invalid address": "INVALID_ADDRESS",
|
|
806
|
+
"bandwidth": "GAS_TOO_LOW"
|
|
807
|
+
},
|
|
808
|
+
spark: {
|
|
809
|
+
"insufficient funds": "INSUFFICIENT_FUNDS",
|
|
810
|
+
"invoice expired": "TIMEOUT",
|
|
811
|
+
"no route": "NETWORK_ERROR"
|
|
812
|
+
}
|
|
813
|
+
};
|
|
814
|
+
function parseChainError(chain, errorMessage) {
|
|
815
|
+
const errorLower = errorMessage.toLowerCase();
|
|
816
|
+
const chainErrors = CHAIN_ERROR_MESSAGES[chain];
|
|
817
|
+
for (const [pattern, code] of Object.entries(chainErrors)) {
|
|
818
|
+
if (errorLower.includes(pattern)) {
|
|
819
|
+
return code;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
if (errorLower.includes("timeout") || errorLower.includes("timed out")) {
|
|
823
|
+
return "TIMEOUT";
|
|
824
|
+
}
|
|
825
|
+
if (errorLower.includes("network") || errorLower.includes("connection")) {
|
|
826
|
+
return "NETWORK_ERROR";
|
|
827
|
+
}
|
|
828
|
+
if (errorLower.includes("rejected") || errorLower.includes("denied")) {
|
|
829
|
+
return "REJECTED";
|
|
830
|
+
}
|
|
831
|
+
return "UNKNOWN";
|
|
832
|
+
}
|
|
747
833
|
function isBrowser() {
|
|
748
834
|
return typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
749
835
|
}
|
|
@@ -1018,47 +1104,117 @@ var ZubariWdkService = class {
|
|
|
1018
1104
|
return { fee: "0", symbol: this.getChainSymbol(chain) };
|
|
1019
1105
|
}
|
|
1020
1106
|
/**
|
|
1021
|
-
* Send a transaction
|
|
1107
|
+
* Send a transaction on any supported chain
|
|
1108
|
+
*
|
|
1109
|
+
* @param seed - BIP-39 seed phrase
|
|
1110
|
+
* @param chain - Target blockchain (ethereum, bitcoin, solana, ton, tron, spark)
|
|
1111
|
+
* @param to - Recipient address
|
|
1112
|
+
* @param amount - Amount to send (in native units: ETH, BTC, SOL, etc.)
|
|
1113
|
+
* @returns Transaction result with hash on success, or error details on failure
|
|
1022
1114
|
*/
|
|
1023
1115
|
async sendTransaction(seed, chain, to, amount) {
|
|
1024
1116
|
await this.initialize();
|
|
1117
|
+
const startTime = Date.now();
|
|
1118
|
+
console.log(`[ZubariWdkService] Sending ${chain} transaction`, {
|
|
1119
|
+
to: `${to.slice(0, 10)}...${to.slice(-6)}`,
|
|
1120
|
+
amount,
|
|
1121
|
+
network: this.config.network
|
|
1122
|
+
});
|
|
1025
1123
|
try {
|
|
1026
1124
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/send`, {
|
|
1027
1125
|
method: "POST",
|
|
1028
1126
|
headers: { "Content-Type": "application/json" },
|
|
1029
1127
|
body: JSON.stringify({ seed, chain, to, amount, network: this.config.network })
|
|
1030
1128
|
});
|
|
1129
|
+
const elapsed = Date.now() - startTime;
|
|
1031
1130
|
if (response.ok) {
|
|
1032
1131
|
const data = await response.json();
|
|
1033
1132
|
let txHash = data.txHash || data.transactionHash || data.hash;
|
|
1034
1133
|
if (txHash && typeof txHash === "object" && "hash" in txHash) {
|
|
1035
1134
|
txHash = txHash.hash;
|
|
1036
1135
|
}
|
|
1037
|
-
if (
|
|
1038
|
-
|
|
1136
|
+
if (txHash) {
|
|
1137
|
+
const isValid = this.validateTxHash(chain, txHash);
|
|
1138
|
+
if (!isValid) {
|
|
1139
|
+
console.warn(`[ZubariWdkService] Invalid ${chain} tx hash format:`, txHash);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
console.log(`[ZubariWdkService] ${chain} transaction ${data.success ? "SUCCESS" : "FAILED"}`, {
|
|
1143
|
+
txHash: txHash ? `${txHash.slice(0, 16)}...` : "N/A",
|
|
1144
|
+
elapsed: `${elapsed}ms`
|
|
1145
|
+
});
|
|
1146
|
+
if (!data.success) {
|
|
1147
|
+
const errorCode2 = parseChainError(chain, data.error || "");
|
|
1148
|
+
return {
|
|
1149
|
+
success: false,
|
|
1150
|
+
error: data.error,
|
|
1151
|
+
errorCode: errorCode2,
|
|
1152
|
+
chain
|
|
1153
|
+
};
|
|
1039
1154
|
}
|
|
1040
1155
|
return {
|
|
1041
|
-
success:
|
|
1156
|
+
success: true,
|
|
1042
1157
|
txHash,
|
|
1043
1158
|
from: data.from,
|
|
1044
1159
|
to: data.to,
|
|
1045
1160
|
amount: data.amount,
|
|
1046
|
-
chain: data.chain,
|
|
1047
|
-
network: data.network
|
|
1161
|
+
chain: data.chain || chain,
|
|
1162
|
+
network: data.network || this.config.network
|
|
1048
1163
|
};
|
|
1049
1164
|
}
|
|
1050
1165
|
const errorData = await response.json().catch(() => ({}));
|
|
1166
|
+
const errorMessage = errorData.error || `HTTP ${response.status}`;
|
|
1167
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
1168
|
+
console.error(`[ZubariWdkService] ${chain} transaction FAILED`, {
|
|
1169
|
+
status: response.status,
|
|
1170
|
+
error: errorMessage,
|
|
1171
|
+
errorCode,
|
|
1172
|
+
elapsed: `${elapsed}ms`
|
|
1173
|
+
});
|
|
1051
1174
|
return {
|
|
1052
1175
|
success: false,
|
|
1053
|
-
error:
|
|
1176
|
+
error: errorMessage,
|
|
1177
|
+
errorCode,
|
|
1178
|
+
chain
|
|
1054
1179
|
};
|
|
1055
1180
|
} catch (error) {
|
|
1181
|
+
const elapsed = Date.now() - startTime;
|
|
1182
|
+
const errorMessage = error instanceof Error ? error.message : "Transaction failed";
|
|
1183
|
+
const errorCode = parseChainError(chain, errorMessage);
|
|
1184
|
+
console.error(`[ZubariWdkService] ${chain} transaction ERROR`, {
|
|
1185
|
+
error: errorMessage,
|
|
1186
|
+
errorCode,
|
|
1187
|
+
elapsed: `${elapsed}ms`
|
|
1188
|
+
});
|
|
1056
1189
|
return {
|
|
1057
1190
|
success: false,
|
|
1058
|
-
error:
|
|
1191
|
+
error: errorMessage,
|
|
1192
|
+
errorCode,
|
|
1193
|
+
chain
|
|
1059
1194
|
};
|
|
1060
1195
|
}
|
|
1061
1196
|
}
|
|
1197
|
+
/**
|
|
1198
|
+
* Validate transaction hash format for a specific chain
|
|
1199
|
+
*/
|
|
1200
|
+
validateTxHash(chain, txHash) {
|
|
1201
|
+
switch (chain) {
|
|
1202
|
+
case "ethereum":
|
|
1203
|
+
return /^0x[a-fA-F0-9]{64}$/.test(txHash);
|
|
1204
|
+
case "bitcoin":
|
|
1205
|
+
return /^[a-fA-F0-9]{64}$/.test(txHash);
|
|
1206
|
+
case "solana":
|
|
1207
|
+
return /^[1-9A-HJ-NP-Za-km-z]{80,90}$/.test(txHash);
|
|
1208
|
+
case "ton":
|
|
1209
|
+
return txHash.length >= 40;
|
|
1210
|
+
case "tron":
|
|
1211
|
+
return /^[a-fA-F0-9]{64}$/.test(txHash);
|
|
1212
|
+
case "spark":
|
|
1213
|
+
return txHash.length >= 32;
|
|
1214
|
+
default:
|
|
1215
|
+
return true;
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1062
1218
|
/**
|
|
1063
1219
|
* Get the network configuration
|
|
1064
1220
|
*/
|
|
@@ -2048,6 +2204,19 @@ async function getPriceForChain(chain) {
|
|
|
2048
2204
|
const prices = await fetchPrices();
|
|
2049
2205
|
return prices[chain] || 0;
|
|
2050
2206
|
}
|
|
2207
|
+
function tonFriendlyToRaw(addr) {
|
|
2208
|
+
if (addr.includes(":")) return addr;
|
|
2209
|
+
try {
|
|
2210
|
+
const b64 = addr.replace(/-/g, "+").replace(/_/g, "/");
|
|
2211
|
+
const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
|
|
2212
|
+
if (bytes.length !== 36) return addr;
|
|
2213
|
+
const workchain = bytes[1] === 255 ? -1 : bytes[1];
|
|
2214
|
+
const hash = Array.from(bytes.slice(2, 34)).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
2215
|
+
return `${workchain}:${hash}`;
|
|
2216
|
+
} catch {
|
|
2217
|
+
return addr;
|
|
2218
|
+
}
|
|
2219
|
+
}
|
|
2051
2220
|
var STORAGE_KEYS = {
|
|
2052
2221
|
ENCRYPTED_SEED: "encrypted_seed",
|
|
2053
2222
|
ACTIVE_WALLET: "active_wallet",
|
|
@@ -2552,26 +2721,53 @@ var WalletManager = class _WalletManager {
|
|
|
2552
2721
|
}
|
|
2553
2722
|
const networkConfig = this.getChainConfig(chain);
|
|
2554
2723
|
let balance = "0";
|
|
2724
|
+
const tokenBalances = {};
|
|
2555
2725
|
if (chain === "ethereum") {
|
|
2556
2726
|
const viemChain = this.config.network === "mainnet" ? chains.mainnet : chains.sepolia;
|
|
2557
|
-
|
|
2727
|
+
const isTestnet2 = this.config.network !== "mainnet";
|
|
2558
2728
|
const client = viem.createPublicClient({
|
|
2559
2729
|
chain: viemChain,
|
|
2560
2730
|
transport: viem.http(this.config.rpcUrl, {
|
|
2561
2731
|
timeout: 15e3,
|
|
2562
|
-
// 15 second timeout
|
|
2563
2732
|
retryCount: 2,
|
|
2564
2733
|
retryDelay: 1e3
|
|
2565
2734
|
})
|
|
2566
2735
|
});
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2736
|
+
const usdtAddr = USDT_ADDRESSES.ethereum?.[isTestnet2 ? "testnet" : "mainnet"];
|
|
2737
|
+
const erc20BalanceOfAbi = [{
|
|
2738
|
+
type: "function",
|
|
2739
|
+
name: "balanceOf",
|
|
2740
|
+
stateMutability: "view",
|
|
2741
|
+
inputs: [{ name: "account", type: "address" }],
|
|
2742
|
+
outputs: [{ name: "", type: "uint256" }]
|
|
2743
|
+
}];
|
|
2744
|
+
const checksumAddr = viem.getAddress(address);
|
|
2745
|
+
const [ethResult, usdtResult] = await Promise.allSettled([
|
|
2746
|
+
client.getBalance({ address: checksumAddr }),
|
|
2747
|
+
usdtAddr ? client.readContract({
|
|
2748
|
+
address: viem.getAddress(usdtAddr),
|
|
2749
|
+
abi: erc20BalanceOfAbi,
|
|
2750
|
+
functionName: "balanceOf",
|
|
2751
|
+
args: [checksumAddr]
|
|
2752
|
+
}) : Promise.resolve(null)
|
|
2753
|
+
]);
|
|
2754
|
+
if (ethResult.status === "fulfilled") {
|
|
2755
|
+
balance = viem.formatEther(ethResult.value);
|
|
2756
|
+
} else {
|
|
2757
|
+
console.error(`[WalletManager] Failed to fetch ETH balance:`, ethResult.reason);
|
|
2758
|
+
}
|
|
2759
|
+
if (usdtResult.status === "fulfilled" && usdtResult.value != null) {
|
|
2760
|
+
try {
|
|
2761
|
+
const rawUsdt = BigInt(usdtResult.value);
|
|
2762
|
+
const usdtAmount = Number(rawUsdt) / 1e6;
|
|
2763
|
+
if (usdtAmount > 0) {
|
|
2764
|
+
tokenBalances.USDT = { balance: usdtAmount.toFixed(6), balanceUsd: usdtAmount };
|
|
2765
|
+
}
|
|
2766
|
+
} catch (err) {
|
|
2767
|
+
console.warn("[WalletManager] Failed to parse ETH USDT balance:", err);
|
|
2768
|
+
}
|
|
2769
|
+
} else if (usdtResult.status === "rejected") {
|
|
2770
|
+
console.warn("[WalletManager] Failed to fetch ETH USDT balance:", usdtResult.reason);
|
|
2575
2771
|
}
|
|
2576
2772
|
} else if (chain === "bitcoin") {
|
|
2577
2773
|
const isMainnet2 = this.config.network === "mainnet" || address.startsWith("bc1") || address.startsWith("1") || address.startsWith("3");
|
|
@@ -2627,8 +2823,41 @@ var WalletManager = class _WalletManager {
|
|
|
2627
2823
|
} catch (error) {
|
|
2628
2824
|
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
2629
2825
|
}
|
|
2826
|
+
const isTestnet2 = this.config.network !== "mainnet";
|
|
2827
|
+
const usdtMint = USDT_ADDRESSES.solana?.[isTestnet2 ? "testnet" : "mainnet"];
|
|
2828
|
+
if (usdtMint) {
|
|
2829
|
+
try {
|
|
2830
|
+
const tokenResponse = await fetch(rpcUrl, {
|
|
2831
|
+
method: "POST",
|
|
2832
|
+
headers: { "Content-Type": "application/json" },
|
|
2833
|
+
body: JSON.stringify({
|
|
2834
|
+
jsonrpc: "2.0",
|
|
2835
|
+
id: 2,
|
|
2836
|
+
method: "getTokenAccountsByOwner",
|
|
2837
|
+
params: [
|
|
2838
|
+
address,
|
|
2839
|
+
{ mint: usdtMint },
|
|
2840
|
+
{ encoding: "jsonParsed" }
|
|
2841
|
+
]
|
|
2842
|
+
})
|
|
2843
|
+
});
|
|
2844
|
+
if (tokenResponse.ok) {
|
|
2845
|
+
const tokenData = await tokenResponse.json();
|
|
2846
|
+
const accounts = tokenData.result?.value;
|
|
2847
|
+
if (accounts && accounts.length > 0) {
|
|
2848
|
+
const uiAmount = accounts[0].account?.data?.parsed?.info?.tokenAmount?.uiAmount;
|
|
2849
|
+
if (uiAmount && uiAmount > 0) {
|
|
2850
|
+
tokenBalances.USDT = { balance: uiAmount.toFixed(6), balanceUsd: uiAmount };
|
|
2851
|
+
}
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
} catch (error) {
|
|
2855
|
+
console.warn("Failed to fetch Solana USDT balance:", error);
|
|
2856
|
+
}
|
|
2857
|
+
}
|
|
2630
2858
|
} else if (chain === "tron") {
|
|
2631
|
-
const
|
|
2859
|
+
const tronConfig = getNetworkConfig("tron", this.config.network !== "mainnet");
|
|
2860
|
+
const baseUrl = tronConfig.rpcUrl;
|
|
2632
2861
|
try {
|
|
2633
2862
|
const response = await fetch(`${baseUrl}/v1/accounts/${address}`, {
|
|
2634
2863
|
headers: { "Accept": "application/json" }
|
|
@@ -2638,12 +2867,28 @@ var WalletManager = class _WalletManager {
|
|
|
2638
2867
|
if (data.data?.[0]?.balance !== void 0) {
|
|
2639
2868
|
balance = (data.data[0].balance / 1e6).toFixed(6);
|
|
2640
2869
|
}
|
|
2870
|
+
const isTestnet2 = this.config.network !== "mainnet";
|
|
2871
|
+
const usdtAddr = USDT_ADDRESSES.tron?.[isTestnet2 ? "testnet" : "mainnet"];
|
|
2872
|
+
if (usdtAddr && data.data?.[0]?.trc20) {
|
|
2873
|
+
const trc20List = data.data[0].trc20;
|
|
2874
|
+
for (const tokenObj of trc20List) {
|
|
2875
|
+
if (tokenObj[usdtAddr]) {
|
|
2876
|
+
const rawUsdtBalance = BigInt(tokenObj[usdtAddr]);
|
|
2877
|
+
const usdtAmount = Number(rawUsdtBalance) / 1e6;
|
|
2878
|
+
if (usdtAmount > 0) {
|
|
2879
|
+
tokenBalances.USDT = { balance: usdtAmount.toFixed(6), balanceUsd: usdtAmount };
|
|
2880
|
+
}
|
|
2881
|
+
break;
|
|
2882
|
+
}
|
|
2883
|
+
}
|
|
2884
|
+
}
|
|
2641
2885
|
}
|
|
2642
2886
|
} catch (error) {
|
|
2643
2887
|
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
2644
2888
|
}
|
|
2645
2889
|
} else if (chain === "ton") {
|
|
2646
|
-
const
|
|
2890
|
+
const isTestnet2 = this.config.network !== "mainnet";
|
|
2891
|
+
const baseUrl = isTestnet2 ? "https://testnet.toncenter.com/api/v2" : "https://toncenter.com/api/v2";
|
|
2647
2892
|
try {
|
|
2648
2893
|
const response = await fetch(`${baseUrl}/getAddressBalance?address=${address}`, {
|
|
2649
2894
|
headers: { "Accept": "application/json" }
|
|
@@ -2659,6 +2904,42 @@ var WalletManager = class _WalletManager {
|
|
|
2659
2904
|
} catch (error) {
|
|
2660
2905
|
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
2661
2906
|
}
|
|
2907
|
+
const usdtJetton = USDT_ADDRESSES.ton?.[isTestnet2 ? "testnet" : "mainnet"];
|
|
2908
|
+
if (usdtJetton) {
|
|
2909
|
+
const tonapiBaseUrl = isTestnet2 ? "https://testnet.tonapi.io/v2" : "https://tonapi.io/v2";
|
|
2910
|
+
try {
|
|
2911
|
+
const rawAddr = tonFriendlyToRaw(address);
|
|
2912
|
+
const jettonResponse = await fetch(
|
|
2913
|
+
`${tonapiBaseUrl}/accounts/${encodeURIComponent(rawAddr)}/jettons?currencies=usd`,
|
|
2914
|
+
{ headers: { "Accept": "application/json" } }
|
|
2915
|
+
);
|
|
2916
|
+
if (jettonResponse.ok) {
|
|
2917
|
+
const jettonData = await jettonResponse.json();
|
|
2918
|
+
const balances = jettonData.balances;
|
|
2919
|
+
if (balances && balances.length > 0) {
|
|
2920
|
+
for (const jb of balances) {
|
|
2921
|
+
const jettonAddr = jb.jetton?.address;
|
|
2922
|
+
if (jettonAddr) {
|
|
2923
|
+
const usdtRaw = tonFriendlyToRaw(usdtJetton);
|
|
2924
|
+
if (jettonAddr.toLowerCase() === usdtRaw.toLowerCase()) {
|
|
2925
|
+
const rawBalance = jb.balance;
|
|
2926
|
+
if (rawBalance) {
|
|
2927
|
+
const decimals = jb.jetton?.decimals || 6;
|
|
2928
|
+
const usdtAmount = Number(BigInt(rawBalance)) / Math.pow(10, decimals);
|
|
2929
|
+
if (usdtAmount > 0) {
|
|
2930
|
+
tokenBalances.USDT = { balance: usdtAmount.toFixed(6), balanceUsd: usdtAmount };
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
break;
|
|
2934
|
+
}
|
|
2935
|
+
}
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
}
|
|
2939
|
+
} catch (error) {
|
|
2940
|
+
console.warn("Failed to fetch TON USDT jetton balance:", error);
|
|
2941
|
+
}
|
|
2942
|
+
}
|
|
2662
2943
|
} else if (chain === "spark") {
|
|
2663
2944
|
try {
|
|
2664
2945
|
const response = await fetch(`${this.config.apiUrl}/api/wallets/wdk/balance`, {
|
|
@@ -2690,7 +2971,8 @@ var WalletManager = class _WalletManager {
|
|
|
2690
2971
|
balance,
|
|
2691
2972
|
balanceUsd,
|
|
2692
2973
|
address,
|
|
2693
|
-
decimals: networkConfig.nativeCurrency.decimals
|
|
2974
|
+
decimals: networkConfig.nativeCurrency.decimals,
|
|
2975
|
+
...Object.keys(tokenBalances).length > 0 ? { tokenBalances } : {}
|
|
2694
2976
|
};
|
|
2695
2977
|
}
|
|
2696
2978
|
/**
|