@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.
@@ -1,7 +1,8 @@
1
1
  import { N as NetworkType } from '../index-D9vwxETQ.mjs';
2
- import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-CGIuecnp.mjs';
3
- export { S as SUPPORTED_CHAINS } from '../WalletManager-CGIuecnp.mjs';
4
- import 'abitype';
2
+ import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-Cdk81G55.mjs';
3
+ export { S as SUPPORTED_CHAINS } from '../WalletManager-Cdk81G55.mjs';
4
+ import 'node_modules/viem/_types/actions/siwe/verifySiweMessage';
5
+ import 'node_modules/viem/_types/utils/ccip';
5
6
  import 'viem';
6
7
  import 'ethers';
7
8
  import '../SecureStorage-jO783AhC.mjs';
@@ -1,7 +1,8 @@
1
1
  import { N as NetworkType } from '../index-D9vwxETQ.js';
2
- import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-D1ohlVea.js';
3
- export { S as SUPPORTED_CHAINS } from '../WalletManager-D1ohlVea.js';
4
- import 'abitype';
2
+ import { b as WalletManagerConfig, a as WalletState, C as ChainBalance, M as MultiChainAddresses, W as WalletManager } from '../WalletManager-CR1B7vN_.js';
3
+ export { S as SUPPORTED_CHAINS } from '../WalletManager-CR1B7vN_.js';
4
+ import 'node_modules/viem/_types/actions/siwe/verifySiweMessage';
5
+ import 'node_modules/viem/_types/utils/ccip';
5
6
  import 'viem';
6
7
  import 'ethers';
7
8
  import '../SecureStorage-jO783AhC.js';
@@ -5,11 +5,11 @@ var ethers = require('ethers');
5
5
  var viem = require('viem');
6
6
  var chains = require('viem/chains');
7
7
  var bip39 = require('@scure/bip39');
8
- var english_js = require('@scure/bip39/wordlists/english.js');
8
+ var english = require('@scure/bip39/wordlists/english');
9
9
  var bip32 = require('@scure/bip32');
10
10
  var base = require('@scure/base');
11
- var sha2_js = require('@noble/hashes/sha2.js');
12
- var legacy_js = require('@noble/hashes/legacy.js');
11
+ var sha256 = require('@noble/hashes/sha256');
12
+ var ripemd160 = require('@noble/hashes/ripemd160');
13
13
 
14
14
  // src/react/useWalletManager.ts
15
15
 
@@ -101,6 +101,11 @@ var NETWORKS = {
101
101
  }
102
102
  };
103
103
  var TESTNET_NETWORKS = {
104
+ bitcoin: {
105
+ name: "Bitcoin Testnet",
106
+ rpcUrl: "https://blockstream.info/testnet/api",
107
+ explorerUrl: "https://mempool.space/testnet"
108
+ },
104
109
  ethereum: {
105
110
  name: "Sepolia",
106
111
  chainId: 11155111,
@@ -609,7 +614,7 @@ function deriveBitcoinAddress(seed, network = "testnet") {
609
614
  if (!child.publicKey) {
610
615
  throw new Error("Failed to derive public key");
611
616
  }
612
- const pubKeyHash = legacy_js.ripemd160(sha2_js.sha256(child.publicKey));
617
+ const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
613
618
  const witnessVersion = 0;
614
619
  const words = base.bech32.toWords(pubKeyHash);
615
620
  words.unshift(witnessVersion);
@@ -650,7 +655,7 @@ async function deriveTonAddress(seed) {
650
655
  const publicKey = keypair.publicKey;
651
656
  const workchain = 0;
652
657
  const flags = 17;
653
- const hash = sha2_js.sha256(publicKey);
658
+ const hash = sha256.sha256(publicKey);
654
659
  const addressData = new Uint8Array(34);
655
660
  addressData[0] = flags;
656
661
  addressData[1] = workchain;
@@ -687,7 +692,7 @@ function deriveTronAddress(seed) {
687
692
  for (let i = 0; i < 20; i++) {
688
693
  addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
689
694
  }
690
- const tronBase58check = base.base58check(sha2_js.sha256);
695
+ const tronBase58check = base.base58check(sha256.sha256);
691
696
  return tronBase58check.encode(addressBytes);
692
697
  } catch (error) {
693
698
  console.error("TRON address derivation failed:", error);
@@ -702,7 +707,7 @@ function deriveSparkAddress(seed, network = "testnet") {
702
707
  if (!child.publicKey) {
703
708
  throw new Error("Failed to derive public key");
704
709
  }
705
- const pubKeyHash = legacy_js.ripemd160(sha2_js.sha256(child.publicKey));
710
+ const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
706
711
  const witnessVersion = 0;
707
712
  const words = base.bech32.toWords(pubKeyHash);
708
713
  words.unshift(witnessVersion);
@@ -760,10 +765,10 @@ async function deriveAllAddresses(seed, network = "testnet") {
760
765
  return addresses;
761
766
  }
762
767
  function isValidSeed(seed) {
763
- return bip39.validateMnemonic(seed, english_js.wordlist);
768
+ return bip39.validateMnemonic(seed, english.wordlist);
764
769
  }
765
770
  function generateSeedPhrase() {
766
- return bip39.generateMnemonic(english_js.wordlist);
771
+ return bip39.generateMnemonic(english.wordlist);
767
772
  }
768
773
 
769
774
  // src/services/ZubariWdkService.ts
@@ -1541,6 +1546,33 @@ var WalletManager = class _WalletManager {
1541
1546
  console.warn("Failed to save addresses to storage:", error);
1542
1547
  }
1543
1548
  }
1549
+ /**
1550
+ * Normalize an address value - extract string from object format if needed
1551
+ * Handles both string addresses and object format {chain, address, path}
1552
+ */
1553
+ normalizeAddress(value) {
1554
+ if (typeof value === "string") {
1555
+ return value;
1556
+ }
1557
+ if (value && typeof value === "object" && "address" in value) {
1558
+ const addr = value.address;
1559
+ return typeof addr === "string" ? addr : null;
1560
+ }
1561
+ return null;
1562
+ }
1563
+ /**
1564
+ * Normalize all addresses in an object - extract strings from object format
1565
+ */
1566
+ normalizeAddresses(addresses) {
1567
+ const normalized = {};
1568
+ for (const [chain, value] of Object.entries(addresses)) {
1569
+ const addr = this.normalizeAddress(value);
1570
+ if (addr) {
1571
+ normalized[chain] = addr;
1572
+ }
1573
+ }
1574
+ return normalized;
1575
+ }
1544
1576
  /**
1545
1577
  * Load derived addresses from storage
1546
1578
  */
@@ -1548,8 +1580,11 @@ var WalletManager = class _WalletManager {
1548
1580
  try {
1549
1581
  const stored = await this.storage.getItem(STORAGE_KEYS.DERIVED_ADDRESSES);
1550
1582
  if (stored) {
1551
- const addresses = JSON.parse(stored);
1552
- console.log("Loaded derived addresses from storage:", Object.keys(addresses));
1583
+ const rawAddresses = JSON.parse(stored);
1584
+ console.log("[WalletManager] Raw addresses from storage:", rawAddresses);
1585
+ const addresses = this.normalizeAddresses(rawAddresses);
1586
+ console.log("[WalletManager] Normalized addresses:", addresses);
1587
+ await this.saveAddressesToStorage(addresses);
1553
1588
  return addresses;
1554
1589
  }
1555
1590
  } catch (error) {
@@ -1587,8 +1622,15 @@ var WalletManager = class _WalletManager {
1587
1622
  * Returns cached address or null - use deriveAllAddressesAsync to derive addresses
1588
1623
  */
1589
1624
  getAddressForChain(chain) {
1590
- if (this.derivedAddresses[chain]) {
1591
- return this.derivedAddresses[chain];
1625
+ const cachedValue = this.derivedAddresses[chain];
1626
+ if (cachedValue) {
1627
+ console.log(`[WalletManager] getAddressForChain(${chain}) cached value:`, cachedValue, "type:", typeof cachedValue);
1628
+ const addr = this.normalizeAddress(cachedValue);
1629
+ console.log(`[WalletManager] getAddressForChain(${chain}) normalized:`, addr);
1630
+ if (addr) {
1631
+ this.derivedAddresses[chain] = addr;
1632
+ return addr;
1633
+ }
1592
1634
  }
1593
1635
  if (chain === "ethereum" && this.currentSeed) {
1594
1636
  this.derivedAddresses[chain] = _WalletManager.deriveAddressForChain(this.currentSeed, chain);
@@ -1600,7 +1642,7 @@ var WalletManager = class _WalletManager {
1600
1642
  * Get all derived addresses
1601
1643
  */
1602
1644
  getAllAddresses() {
1603
- return { ...this.derivedAddresses };
1645
+ return this.normalizeAddresses(this.derivedAddresses);
1604
1646
  }
1605
1647
  /**
1606
1648
  * Set the selected chain
@@ -1642,6 +1684,7 @@ var WalletManager = class _WalletManager {
1642
1684
  let balance = "0";
1643
1685
  if (chain === "ethereum") {
1644
1686
  const viemChain = this.config.network === "mainnet" ? chains.mainnet : chains.sepolia;
1687
+ console.log(`[WalletManager] Fetching ${chain} balance for ${address} using RPC: ${this.config.rpcUrl}`);
1645
1688
  const client = viem.createPublicClient({
1646
1689
  chain: viemChain,
1647
1690
  transport: viem.http(this.config.rpcUrl, {
@@ -1656,8 +1699,9 @@ var WalletManager = class _WalletManager {
1656
1699
  address
1657
1700
  });
1658
1701
  balance = viem.formatEther(rawBalance);
1702
+ console.log(`[WalletManager] ${chain} balance fetched: ${balance} (raw: ${rawBalance})`);
1659
1703
  } catch (error) {
1660
- console.warn(`Failed to fetch ${chain} balance:`, error);
1704
+ console.error(`[WalletManager] Failed to fetch ${chain} balance from ${this.config.rpcUrl}:`, error);
1661
1705
  }
1662
1706
  } else if (chain === "bitcoin") {
1663
1707
  const isMainnet = this.config.network === "mainnet" || address.startsWith("bc1") || address.startsWith("1") || address.startsWith("3");