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