@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.
@@ -2,11 +2,11 @@ import { Wallet, HDNodeWallet } from 'ethers';
2
2
  import { createPublicClient, http, formatEther } from 'viem';
3
3
  import { mainnet, sepolia } from 'viem/chains';
4
4
  import { generateMnemonic, validateMnemonic, mnemonicToSeedSync } from '@scure/bip39';
5
- import { wordlist } from '@scure/bip39/wordlists/english.js';
5
+ import { wordlist } from '@scure/bip39/wordlists/english';
6
6
  import { HDKey } from '@scure/bip32';
7
7
  import { bech32, base58check } from '@scure/base';
8
- import { sha256 } from '@noble/hashes/sha2.js';
9
- import { ripemd160 } from '@noble/hashes/legacy.js';
8
+ import { sha256 } from '@noble/hashes/sha256';
9
+ import { ripemd160 } from '@noble/hashes/ripemd160';
10
10
 
11
11
  // src/config/networks.ts
12
12
  var NETWORKS = {
@@ -96,6 +96,11 @@ var NETWORKS = {
96
96
  }
97
97
  };
98
98
  var TESTNET_NETWORKS = {
99
+ bitcoin: {
100
+ name: "Bitcoin Testnet",
101
+ rpcUrl: "https://blockstream.info/testnet/api",
102
+ explorerUrl: "https://mempool.space/testnet"
103
+ },
99
104
  ethereum: {
100
105
  name: "Sepolia",
101
106
  chainId: 11155111,
@@ -1841,6 +1846,33 @@ var WalletManager = class _WalletManager {
1841
1846
  console.warn("Failed to save addresses to storage:", error);
1842
1847
  }
1843
1848
  }
1849
+ /**
1850
+ * Normalize an address value - extract string from object format if needed
1851
+ * Handles both string addresses and object format {chain, address, path}
1852
+ */
1853
+ normalizeAddress(value) {
1854
+ if (typeof value === "string") {
1855
+ return value;
1856
+ }
1857
+ if (value && typeof value === "object" && "address" in value) {
1858
+ const addr = value.address;
1859
+ return typeof addr === "string" ? addr : null;
1860
+ }
1861
+ return null;
1862
+ }
1863
+ /**
1864
+ * Normalize all addresses in an object - extract strings from object format
1865
+ */
1866
+ normalizeAddresses(addresses) {
1867
+ const normalized = {};
1868
+ for (const [chain, value] of Object.entries(addresses)) {
1869
+ const addr = this.normalizeAddress(value);
1870
+ if (addr) {
1871
+ normalized[chain] = addr;
1872
+ }
1873
+ }
1874
+ return normalized;
1875
+ }
1844
1876
  /**
1845
1877
  * Load derived addresses from storage
1846
1878
  */
@@ -1848,8 +1880,11 @@ var WalletManager = class _WalletManager {
1848
1880
  try {
1849
1881
  const stored = await this.storage.getItem(STORAGE_KEYS.DERIVED_ADDRESSES);
1850
1882
  if (stored) {
1851
- const addresses = JSON.parse(stored);
1852
- console.log("Loaded derived addresses from storage:", Object.keys(addresses));
1883
+ const rawAddresses = JSON.parse(stored);
1884
+ console.log("[WalletManager] Raw addresses from storage:", rawAddresses);
1885
+ const addresses = this.normalizeAddresses(rawAddresses);
1886
+ console.log("[WalletManager] Normalized addresses:", addresses);
1887
+ await this.saveAddressesToStorage(addresses);
1853
1888
  return addresses;
1854
1889
  }
1855
1890
  } catch (error) {
@@ -1887,8 +1922,15 @@ var WalletManager = class _WalletManager {
1887
1922
  * Returns cached address or null - use deriveAllAddressesAsync to derive addresses
1888
1923
  */
1889
1924
  getAddressForChain(chain) {
1890
- if (this.derivedAddresses[chain]) {
1891
- return this.derivedAddresses[chain];
1925
+ const cachedValue = this.derivedAddresses[chain];
1926
+ if (cachedValue) {
1927
+ console.log(`[WalletManager] getAddressForChain(${chain}) cached value:`, cachedValue, "type:", typeof cachedValue);
1928
+ const addr = this.normalizeAddress(cachedValue);
1929
+ console.log(`[WalletManager] getAddressForChain(${chain}) normalized:`, addr);
1930
+ if (addr) {
1931
+ this.derivedAddresses[chain] = addr;
1932
+ return addr;
1933
+ }
1892
1934
  }
1893
1935
  if (chain === "ethereum" && this.currentSeed) {
1894
1936
  this.derivedAddresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
@@ -1900,7 +1942,7 @@ var WalletManager = class _WalletManager {
1900
1942
  * Get all derived addresses
1901
1943
  */
1902
1944
  getAllAddresses() {
1903
- return { ...this.derivedAddresses };
1945
+ return this.normalizeAddresses(this.derivedAddresses);
1904
1946
  }
1905
1947
  /**
1906
1948
  * Set the selected chain
@@ -1942,6 +1984,7 @@ var WalletManager = class _WalletManager {
1942
1984
  let balance = "0";
1943
1985
  if (chain === "ethereum") {
1944
1986
  const viemChain = this.config.network === "mainnet" ? mainnet : sepolia;
1987
+ console.log(`[WalletManager] Fetching ${chain} balance for ${address} using RPC: ${this.config.rpcUrl}`);
1945
1988
  const client = createPublicClient({
1946
1989
  chain: viemChain,
1947
1990
  transport: http(this.config.rpcUrl, {
@@ -1956,8 +1999,9 @@ var WalletManager = class _WalletManager {
1956
1999
  address
1957
2000
  });
1958
2001
  balance = formatEther(rawBalance);
2002
+ console.log(`[WalletManager] ${chain} balance fetched: ${balance} (raw: ${rawBalance})`);
1959
2003
  } catch (error) {
1960
- console.warn(`Failed to fetch ${chain} balance:`, error);
2004
+ console.error(`[WalletManager] Failed to fetch ${chain} balance from ${this.config.rpcUrl}:`, error);
1961
2005
  }
1962
2006
  } else if (chain === "bitcoin") {
1963
2007
  const isMainnet = this.config.network === "mainnet" || address.startsWith("bc1") || address.startsWith("1") || address.startsWith("3");