@zubari/sdk 0.1.26 → 0.1.27

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.
@@ -3,11 +3,11 @@ import { Wallet, HDNodeWallet } from 'ethers';
3
3
  import { createPublicClient, http, formatEther } from 'viem';
4
4
  import { mainnet, sepolia } from 'viem/chains';
5
5
  import { generateMnemonic, validateMnemonic, mnemonicToSeedSync } from '@scure/bip39';
6
- import { wordlist } from '@scure/bip39/wordlists/english.js';
6
+ import { wordlist } from '@scure/bip39/wordlists/english';
7
7
  import { HDKey } from '@scure/bip32';
8
8
  import { bech32, base58check } from '@scure/base';
9
- import { sha256 } from '@noble/hashes/sha2.js';
10
- import { ripemd160 } from '@noble/hashes/legacy.js';
9
+ import { sha256 } from '@noble/hashes/sha256';
10
+ import { ripemd160 } from '@noble/hashes/ripemd160';
11
11
 
12
12
  // src/react/useWalletManager.ts
13
13
 
@@ -99,6 +99,11 @@ var NETWORKS = {
99
99
  }
100
100
  };
101
101
  var TESTNET_NETWORKS = {
102
+ bitcoin: {
103
+ name: "Bitcoin Testnet",
104
+ rpcUrl: "https://blockstream.info/testnet/api",
105
+ explorerUrl: "https://mempool.space/testnet"
106
+ },
102
107
  ethereum: {
103
108
  name: "Sepolia",
104
109
  chainId: 11155111,
@@ -1539,6 +1544,33 @@ var WalletManager = class _WalletManager {
1539
1544
  console.warn("Failed to save addresses to storage:", error);
1540
1545
  }
1541
1546
  }
1547
+ /**
1548
+ * Normalize an address value - extract string from object format if needed
1549
+ * Handles both string addresses and object format {chain, address, path}
1550
+ */
1551
+ normalizeAddress(value) {
1552
+ if (typeof value === "string") {
1553
+ return value;
1554
+ }
1555
+ if (value && typeof value === "object" && "address" in value) {
1556
+ const addr = value.address;
1557
+ return typeof addr === "string" ? addr : null;
1558
+ }
1559
+ return null;
1560
+ }
1561
+ /**
1562
+ * Normalize all addresses in an object - extract strings from object format
1563
+ */
1564
+ normalizeAddresses(addresses) {
1565
+ const normalized = {};
1566
+ for (const [chain, value] of Object.entries(addresses)) {
1567
+ const addr = this.normalizeAddress(value);
1568
+ if (addr) {
1569
+ normalized[chain] = addr;
1570
+ }
1571
+ }
1572
+ return normalized;
1573
+ }
1542
1574
  /**
1543
1575
  * Load derived addresses from storage
1544
1576
  */
@@ -1546,8 +1578,11 @@ var WalletManager = class _WalletManager {
1546
1578
  try {
1547
1579
  const stored = await this.storage.getItem(STORAGE_KEYS.DERIVED_ADDRESSES);
1548
1580
  if (stored) {
1549
- const addresses = JSON.parse(stored);
1550
- console.log("Loaded derived addresses from storage:", Object.keys(addresses));
1581
+ const rawAddresses = JSON.parse(stored);
1582
+ console.log("[WalletManager] Raw addresses from storage:", rawAddresses);
1583
+ const addresses = this.normalizeAddresses(rawAddresses);
1584
+ console.log("[WalletManager] Normalized addresses:", addresses);
1585
+ await this.saveAddressesToStorage(addresses);
1551
1586
  return addresses;
1552
1587
  }
1553
1588
  } catch (error) {
@@ -1585,8 +1620,15 @@ var WalletManager = class _WalletManager {
1585
1620
  * Returns cached address or null - use deriveAllAddressesAsync to derive addresses
1586
1621
  */
1587
1622
  getAddressForChain(chain) {
1588
- if (this.derivedAddresses[chain]) {
1589
- return this.derivedAddresses[chain];
1623
+ const cachedValue = this.derivedAddresses[chain];
1624
+ if (cachedValue) {
1625
+ console.log(`[WalletManager] getAddressForChain(${chain}) cached value:`, cachedValue, "type:", typeof cachedValue);
1626
+ const addr = this.normalizeAddress(cachedValue);
1627
+ console.log(`[WalletManager] getAddressForChain(${chain}) normalized:`, addr);
1628
+ if (addr) {
1629
+ this.derivedAddresses[chain] = addr;
1630
+ return addr;
1631
+ }
1590
1632
  }
1591
1633
  if (chain === "ethereum" && this.currentSeed) {
1592
1634
  this.derivedAddresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
@@ -1598,7 +1640,7 @@ var WalletManager = class _WalletManager {
1598
1640
  * Get all derived addresses
1599
1641
  */
1600
1642
  getAllAddresses() {
1601
- return { ...this.derivedAddresses };
1643
+ return this.normalizeAddresses(this.derivedAddresses);
1602
1644
  }
1603
1645
  /**
1604
1646
  * Set the selected chain
@@ -1640,6 +1682,7 @@ var WalletManager = class _WalletManager {
1640
1682
  let balance = "0";
1641
1683
  if (chain === "ethereum") {
1642
1684
  const viemChain = this.config.network === "mainnet" ? mainnet : sepolia;
1685
+ console.log(`[WalletManager] Fetching ${chain} balance for ${address} using RPC: ${this.config.rpcUrl}`);
1643
1686
  const client = createPublicClient({
1644
1687
  chain: viemChain,
1645
1688
  transport: http(this.config.rpcUrl, {
@@ -1654,8 +1697,9 @@ var WalletManager = class _WalletManager {
1654
1697
  address
1655
1698
  });
1656
1699
  balance = formatEther(rawBalance);
1700
+ console.log(`[WalletManager] ${chain} balance fetched: ${balance} (raw: ${rawBalance})`);
1657
1701
  } catch (error) {
1658
- console.warn(`Failed to fetch ${chain} balance:`, error);
1702
+ console.error(`[WalletManager] Failed to fetch ${chain} balance from ${this.config.rpcUrl}:`, error);
1659
1703
  }
1660
1704
  } else if (chain === "bitcoin") {
1661
1705
  const isMainnet = this.config.network === "mainnet" || address.startsWith("bc1") || address.startsWith("1") || address.startsWith("3");