@zubari/sdk 0.1.11 → 0.1.12

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,6 +1,6 @@
1
1
  import { N as NetworkType } from '../index-DhluuR9H.mjs';
2
- import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager--UOBwXJp.mjs';
3
- export { S as SUPPORTED_CHAINS } from '../WalletManager--UOBwXJp.mjs';
2
+ import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-DWLhos10.mjs';
3
+ export { S as SUPPORTED_CHAINS } from '../WalletManager-DWLhos10.mjs';
4
4
  import 'abitype';
5
5
  import 'viem';
6
6
  import 'ethers';
@@ -1,6 +1,6 @@
1
1
  import { N as NetworkType } from '../index-DhluuR9H.js';
2
- import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-DVq_PUZK.js';
3
- export { S as SUPPORTED_CHAINS } from '../WalletManager-DVq_PUZK.js';
2
+ import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-DLN81Bpl.js';
3
+ export { S as SUPPORTED_CHAINS } from '../WalletManager-DLN81Bpl.js';
4
4
  import 'abitype';
5
5
  import 'viem';
6
6
  import 'ethers';
@@ -822,7 +822,10 @@ var ZubariWdkService = class {
822
822
  return isValidSeed(seed);
823
823
  }
824
824
  /**
825
- * Derive address for a specific chain
825
+ * Derive address for a specific chain using WDK API
826
+ *
827
+ * For Ethereum, falls back to local derivation if API fails.
828
+ * For other chains, WDK API is required - no placeholder fallback.
826
829
  */
827
830
  async deriveAddress(seed, chain) {
828
831
  await this.initialize();
@@ -838,6 +841,9 @@ var ZubariWdkService = class {
838
841
  }
839
842
  } catch (error) {
840
843
  console.warn(`API address derivation failed for ${chain}:`, error);
844
+ if (chain === "ethereum") {
845
+ return this.deriveBrowserAddress(seed, chain);
846
+ }
841
847
  }
842
848
  if (this.useNativeWdk && this.nativeWdkService) {
843
849
  try {
@@ -848,10 +854,18 @@ var ZubariWdkService = class {
848
854
  console.warn(`Native WDK address derivation failed for ${chain}:`, error);
849
855
  }
850
856
  }
851
- return this.deriveBrowserAddress(seed, chain);
857
+ if (chain === "ethereum") {
858
+ return this.deriveBrowserAddress(seed, chain);
859
+ }
860
+ throw new Error(
861
+ `WDK API required for ${chain} address derivation. Ensure the backend is running.`
862
+ );
852
863
  }
853
864
  /**
854
- * Derive addresses for all supported chains
865
+ * Derive addresses for all supported chains using WDK API
866
+ *
867
+ * Uses the backend WDK API for real cryptographically valid addresses.
868
+ * No placeholder fallback - WDK API is required for multi-chain addresses.
855
869
  */
856
870
  async deriveAllAddresses(seed) {
857
871
  await this.initialize();
@@ -879,7 +893,9 @@ var ZubariWdkService = class {
879
893
  console.warn("Native WDK multi-chain derivation failed:", error);
880
894
  }
881
895
  }
882
- return this.deriveAllBrowserAddresses(seed);
896
+ throw new Error(
897
+ "WDK API required for multi-chain address derivation. Ensure the backend is running."
898
+ );
883
899
  }
884
900
  /**
885
901
  * Get balances for all chains
@@ -1361,106 +1377,51 @@ var WalletManager = class _WalletManager {
1361
1377
  * Uses the unified WDK service which:
1362
1378
  * - In browser: Calls the backend API (which has Tether WDK)
1363
1379
  * - In Node.js: Uses native WDK
1364
- * - Falls back to browser-compatible derivation if needed
1365
- */
1366
- static async deriveAddressForChainAsync(seed, chain, network = "testnet", apiUrl) {
1367
- try {
1368
- const wdkService = getZubariWdkService({ network, apiUrl });
1369
- const result = await wdkService.deriveAddress(seed, chain);
1370
- return result.address;
1371
- } catch (error) {
1372
- console.warn(`WDK service failed for ${chain}, using local derivation:`, error);
1373
- }
1374
- return _WalletManager.deriveAddressForChain(seed, chain);
1375
- }
1376
- /**
1377
- * Format address for non-WDK chains (fallback)
1378
1380
  *
1379
- * Note: This fallback produces PLACEHOLDER addresses derived from the seed.
1380
- * For real blockchain interaction, use the WDK API via deriveAddressForChainAsync().
1381
- * These addresses should NOT be used for receiving funds without verification.
1381
+ * No fallback to placeholder addresses - WDK API is required for real addresses.
1382
1382
  */
1383
- static formatAddressForChain(address, chain) {
1383
+ static async deriveAddressForChainAsync(seed, chain, network = "testnet", apiUrl) {
1384
1384
  if (chain === "ethereum") {
1385
- return address;
1386
- }
1387
- const addressBytes = address.toLowerCase().replace("0x", "");
1388
- switch (chain) {
1389
- case "bitcoin": {
1390
- const btcChars = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
1391
- let btcAddr = "tb1q";
1392
- for (let i = 0; i < 38; i++) {
1393
- const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) % btcChars.length;
1394
- btcAddr += btcChars[idx];
1395
- }
1396
- return btcAddr;
1397
- }
1398
- case "ton": {
1399
- const base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
1400
- let tonAddr = "EQ";
1401
- for (let i = 0; i < 46; i++) {
1402
- const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) * 4 % base64Chars.length;
1403
- tonAddr += base64Chars[idx];
1404
- }
1405
- return tonAddr;
1406
- }
1407
- case "tron": {
1408
- const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
1409
- let tronAddr = "T";
1410
- for (let i = 0; i < 33; i++) {
1411
- const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) * 3 % base58Chars.length;
1412
- tronAddr += base58Chars[idx];
1413
- }
1414
- return tronAddr;
1415
- }
1416
- case "solana": {
1417
- const base58Chars = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
1418
- let solAddr = "";
1419
- for (let i = 0; i < 44; i++) {
1420
- const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) * 3 % base58Chars.length;
1421
- solAddr += base58Chars[idx];
1422
- }
1423
- return solAddr;
1424
- }
1425
- case "spark": {
1426
- const bech32Chars = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";
1427
- let sparkAddr = "sp1q";
1428
- for (let i = 0; i < 58; i++) {
1429
- const idx = parseInt(addressBytes.charAt(i % 40) || "0", 16) % bech32Chars.length;
1430
- sparkAddr += bech32Chars[idx];
1431
- }
1432
- return sparkAddr;
1385
+ try {
1386
+ const wdkService2 = getZubariWdkService({ network, apiUrl });
1387
+ const result2 = await wdkService2.deriveAddress(seed, chain);
1388
+ return result2.address;
1389
+ } catch (error) {
1390
+ console.warn("WDK service failed for Ethereum, using local derivation:", error);
1391
+ return _WalletManager.deriveAddressForChain(seed, "ethereum");
1433
1392
  }
1434
- default:
1435
- return address;
1436
1393
  }
1394
+ const wdkService = getZubariWdkService({ network, apiUrl });
1395
+ const result = await wdkService.deriveAddress(seed, chain);
1396
+ return result.address;
1437
1397
  }
1438
1398
  /**
1439
- * Derive address for a specific chain (sync version for backwards compatibility)
1440
- * Uses ethers for basic derivation, use deriveAddressForChainAsync for WDK
1399
+ * Derive address for a specific chain (sync version)
1400
+ * Only supports Ethereum - for other chains use deriveAddressForChainAsync with WDK API
1441
1401
  *
1442
- * Note: For non-Ethereum chains, this produces placeholder addresses that are
1443
- * deterministic but not cryptographically valid. Use WDK API for real addresses.
1402
+ * @throws Error for non-Ethereum chains - use WDK API instead
1444
1403
  */
1445
1404
  static deriveAddressForChain(seed, chain) {
1446
- const ethPath = DERIVATION_PATHS["ethereum"];
1447
- const ethNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, `${ethPath}/0`);
1448
1405
  if (chain === "ethereum") {
1406
+ const ethPath = DERIVATION_PATHS["ethereum"];
1407
+ const ethNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, `${ethPath}/0`);
1449
1408
  return ethNode.address;
1450
1409
  }
1451
- return _WalletManager.formatAddressForChain(ethNode.address, chain);
1410
+ throw new Error(
1411
+ `Sync derivation not supported for ${chain}. Use deriveAddressForChainAsync() with WDK API.`
1412
+ );
1452
1413
  }
1453
1414
  /**
1454
1415
  * Derive addresses for all enabled chains (sync version)
1416
+ * Only derives Ethereum address synchronously - use deriveAllAddressesAsync for all chains
1455
1417
  */
1456
1418
  deriveAllAddresses() {
1457
1419
  if (!this.currentSeed) {
1458
1420
  throw new Error("Wallet is locked");
1459
1421
  }
1460
- const addresses = {};
1461
- for (const chain of this.config.enabledChains) {
1462
- addresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
1463
- }
1422
+ const addresses = {
1423
+ ethereum: _WalletManager.deriveAddressForChain(this.currentSeed, "ethereum")
1424
+ };
1464
1425
  this.derivedAddresses = addresses;
1465
1426
  return addresses;
1466
1427
  }
@@ -1521,11 +1482,11 @@ var WalletManager = class _WalletManager {
1521
1482
  }
1522
1483
  /**
1523
1484
  * Derive addresses for all enabled chains using Tether WDK
1524
- * The unified WDK service handles all fallback strategies automatically:
1525
- * - Browser: API backend -> Browser derivation
1526
- * - Node.js: Native WDK -> API backend -> Browser derivation
1527
1485
  *
1528
- * First tries to load from storage to avoid losing real WDK-derived addresses.
1486
+ * Uses the WDK API backend for real cryptographically valid addresses.
1487
+ * First tries to load from storage to avoid losing previously derived addresses.
1488
+ *
1489
+ * @throws Error if WDK API is unavailable and no cached addresses exist
1529
1490
  */
1530
1491
  async deriveAllAddressesAsync() {
1531
1492
  if (!this.currentSeed) {
@@ -1542,26 +1503,21 @@ var WalletManager = class _WalletManager {
1542
1503
  console.log("Stored addresses do not match current seed, re-deriving...");
1543
1504
  }
1544
1505
  }
1545
- try {
1546
- return await this.deriveAllAddressesWithWdk();
1547
- } catch (error) {
1548
- console.error("All derivation strategies failed:", error);
1549
- const ethAddress = _WalletManager.deriveAddress(this.currentSeed);
1550
- this.derivedAddresses = { ethereum: ethAddress };
1551
- return this.derivedAddresses;
1552
- }
1506
+ return await this.deriveAllAddressesWithWdk();
1553
1507
  }
1554
1508
  /**
1555
1509
  * Get address for a specific chain
1510
+ * Returns cached address or null - use deriveAllAddressesAsync to derive addresses
1556
1511
  */
1557
1512
  getAddressForChain(chain) {
1558
- if (!this.currentSeed) {
1559
- return this.derivedAddresses[chain] || null;
1513
+ if (this.derivedAddresses[chain]) {
1514
+ return this.derivedAddresses[chain];
1560
1515
  }
1561
- if (!this.derivedAddresses[chain]) {
1516
+ if (chain === "ethereum" && this.currentSeed) {
1562
1517
  this.derivedAddresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
1518
+ return this.derivedAddresses[chain];
1563
1519
  }
1564
- return this.derivedAddresses[chain] || null;
1520
+ return null;
1565
1521
  }
1566
1522
  /**
1567
1523
  * Get all derived addresses