@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.
package/dist/index.mjs CHANGED
@@ -2,11 +2,11 @@ import { HDNodeWallet, Wallet } from 'ethers';
2
2
  import { createPublicClient, http, formatEther } from 'viem';
3
3
  import { mainnet, sepolia } from 'viem/chains';
4
4
  import { mnemonicToSeedSync, validateMnemonic, generateMnemonic } 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
  import { useMemo, useState, useCallback, useEffect } from 'react';
11
11
 
12
12
  var __defProp = Object.defineProperty;
@@ -103,6 +103,11 @@ var NETWORKS = {
103
103
  }
104
104
  };
105
105
  var TESTNET_NETWORKS = {
106
+ bitcoin: {
107
+ name: "Bitcoin Testnet",
108
+ rpcUrl: "https://blockstream.info/testnet/api",
109
+ explorerUrl: "https://mempool.space/testnet"
110
+ },
106
111
  ethereum: {
107
112
  name: "Sepolia",
108
113
  chainId: 11155111,
@@ -1890,6 +1895,33 @@ var WalletManager = class _WalletManager {
1890
1895
  console.warn("Failed to save addresses to storage:", error);
1891
1896
  }
1892
1897
  }
1898
+ /**
1899
+ * Normalize an address value - extract string from object format if needed
1900
+ * Handles both string addresses and object format {chain, address, path}
1901
+ */
1902
+ normalizeAddress(value) {
1903
+ if (typeof value === "string") {
1904
+ return value;
1905
+ }
1906
+ if (value && typeof value === "object" && "address" in value) {
1907
+ const addr = value.address;
1908
+ return typeof addr === "string" ? addr : null;
1909
+ }
1910
+ return null;
1911
+ }
1912
+ /**
1913
+ * Normalize all addresses in an object - extract strings from object format
1914
+ */
1915
+ normalizeAddresses(addresses) {
1916
+ const normalized = {};
1917
+ for (const [chain, value] of Object.entries(addresses)) {
1918
+ const addr = this.normalizeAddress(value);
1919
+ if (addr) {
1920
+ normalized[chain] = addr;
1921
+ }
1922
+ }
1923
+ return normalized;
1924
+ }
1893
1925
  /**
1894
1926
  * Load derived addresses from storage
1895
1927
  */
@@ -1897,8 +1929,11 @@ var WalletManager = class _WalletManager {
1897
1929
  try {
1898
1930
  const stored = await this.storage.getItem(STORAGE_KEYS.DERIVED_ADDRESSES);
1899
1931
  if (stored) {
1900
- const addresses = JSON.parse(stored);
1901
- console.log("Loaded derived addresses from storage:", Object.keys(addresses));
1932
+ const rawAddresses = JSON.parse(stored);
1933
+ console.log("[WalletManager] Raw addresses from storage:", rawAddresses);
1934
+ const addresses = this.normalizeAddresses(rawAddresses);
1935
+ console.log("[WalletManager] Normalized addresses:", addresses);
1936
+ await this.saveAddressesToStorage(addresses);
1902
1937
  return addresses;
1903
1938
  }
1904
1939
  } catch (error) {
@@ -1936,8 +1971,15 @@ var WalletManager = class _WalletManager {
1936
1971
  * Returns cached address or null - use deriveAllAddressesAsync to derive addresses
1937
1972
  */
1938
1973
  getAddressForChain(chain) {
1939
- if (this.derivedAddresses[chain]) {
1940
- return this.derivedAddresses[chain];
1974
+ const cachedValue = this.derivedAddresses[chain];
1975
+ if (cachedValue) {
1976
+ console.log(`[WalletManager] getAddressForChain(${chain}) cached value:`, cachedValue, "type:", typeof cachedValue);
1977
+ const addr = this.normalizeAddress(cachedValue);
1978
+ console.log(`[WalletManager] getAddressForChain(${chain}) normalized:`, addr);
1979
+ if (addr) {
1980
+ this.derivedAddresses[chain] = addr;
1981
+ return addr;
1982
+ }
1941
1983
  }
1942
1984
  if (chain === "ethereum" && this.currentSeed) {
1943
1985
  this.derivedAddresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
@@ -1949,7 +1991,7 @@ var WalletManager = class _WalletManager {
1949
1991
  * Get all derived addresses
1950
1992
  */
1951
1993
  getAllAddresses() {
1952
- return { ...this.derivedAddresses };
1994
+ return this.normalizeAddresses(this.derivedAddresses);
1953
1995
  }
1954
1996
  /**
1955
1997
  * Set the selected chain
@@ -1991,6 +2033,7 @@ var WalletManager = class _WalletManager {
1991
2033
  let balance = "0";
1992
2034
  if (chain === "ethereum") {
1993
2035
  const viemChain = this.config.network === "mainnet" ? mainnet : sepolia;
2036
+ console.log(`[WalletManager] Fetching ${chain} balance for ${address} using RPC: ${this.config.rpcUrl}`);
1994
2037
  const client = createPublicClient({
1995
2038
  chain: viemChain,
1996
2039
  transport: http(this.config.rpcUrl, {
@@ -2005,8 +2048,9 @@ var WalletManager = class _WalletManager {
2005
2048
  address
2006
2049
  });
2007
2050
  balance = formatEther(rawBalance);
2051
+ console.log(`[WalletManager] ${chain} balance fetched: ${balance} (raw: ${rawBalance})`);
2008
2052
  } catch (error) {
2009
- console.warn(`Failed to fetch ${chain} balance:`, error);
2053
+ console.error(`[WalletManager] Failed to fetch ${chain} balance from ${this.config.rpcUrl}:`, error);
2010
2054
  }
2011
2055
  } else if (chain === "bitcoin") {
2012
2056
  const isMainnet = this.config.network === "mainnet" || address.startsWith("bc1") || address.startsWith("1") || address.startsWith("3");