@zubari/sdk 0.5.4 → 0.5.5

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.
@@ -207,6 +207,10 @@ declare function getWdkApiClient(baseUrl?: string, authToken?: string): WdkApiCl
207
207
  * - TON: ed25519 derivation with TON address format
208
208
  * - TRON: secp256k1 + base58check
209
209
  * - Spark: Bitcoin-based with custom derivation
210
+ *
211
+ * NOTE: All @scure/* and @noble/* packages are loaded via dynamic import()
212
+ * to prevent CJS require() of ESM-only modules. This ensures compatibility
213
+ * with Next.js and other bundlers that may load the CJS build.
210
214
  */
211
215
 
212
216
  interface ChainAddress$1 {
@@ -230,7 +234,7 @@ declare function deriveEthereumAddress(seed: string): string;
230
234
  * Derive Bitcoin address from seed phrase (BIP-84 native SegWit)
231
235
  * Uses @scure libraries for browser compatibility
232
236
  */
233
- declare function deriveBitcoinAddress(seed: string, network?: 'mainnet' | 'testnet'): string;
237
+ declare function deriveBitcoinAddress(seed: string, network?: 'mainnet' | 'testnet'): Promise<string>;
234
238
  /**
235
239
  * Derive Solana address from seed phrase using SLIP-0010 (ed25519)
236
240
  */
@@ -245,13 +249,13 @@ declare function deriveTonAddress(seed: string): Promise<string>;
245
249
  * TRON uses secp256k1 like Ethereum but with base58check encoding
246
250
  * Uses @scure/base for browser compatibility
247
251
  */
248
- declare function deriveTronAddress(seed: string): string;
252
+ declare function deriveTronAddress(seed: string): Promise<string>;
249
253
  /**
250
254
  * Derive Spark address from seed phrase
251
255
  * Spark uses its own derivation path and bech32 format
252
256
  * Uses @scure libraries for browser compatibility
253
257
  */
254
- declare function deriveSparkAddress(seed: string, network?: 'mainnet' | 'testnet'): string;
258
+ declare function deriveSparkAddress(seed: string, network?: 'mainnet' | 'testnet'): Promise<string>;
255
259
  /**
256
260
  * Derive addresses for all supported chains
257
261
  */
@@ -259,11 +263,11 @@ declare function deriveAllAddresses(seed: string, network?: 'mainnet' | 'testnet
259
263
  /**
260
264
  * Validate a BIP-39 seed phrase using @scure/bip39
261
265
  */
262
- declare function isValidSeed(seed: string): boolean;
266
+ declare function isValidSeed(seed: string): Promise<boolean>;
263
267
  /**
264
268
  * Generate a random BIP-39 seed phrase using @scure/bip39
265
269
  */
266
- declare function generateSeedPhrase(): string;
270
+ declare function generateSeedPhrase(): Promise<string>;
267
271
 
268
272
  type BrowserAddressDerivation_BrowserMultiChainAddresses = BrowserMultiChainAddresses;
269
273
  declare const BrowserAddressDerivation_deriveAllAddresses: typeof deriveAllAddresses;
@@ -207,6 +207,10 @@ declare function getWdkApiClient(baseUrl?: string, authToken?: string): WdkApiCl
207
207
  * - TON: ed25519 derivation with TON address format
208
208
  * - TRON: secp256k1 + base58check
209
209
  * - Spark: Bitcoin-based with custom derivation
210
+ *
211
+ * NOTE: All @scure/* and @noble/* packages are loaded via dynamic import()
212
+ * to prevent CJS require() of ESM-only modules. This ensures compatibility
213
+ * with Next.js and other bundlers that may load the CJS build.
210
214
  */
211
215
 
212
216
  interface ChainAddress$1 {
@@ -230,7 +234,7 @@ declare function deriveEthereumAddress(seed: string): string;
230
234
  * Derive Bitcoin address from seed phrase (BIP-84 native SegWit)
231
235
  * Uses @scure libraries for browser compatibility
232
236
  */
233
- declare function deriveBitcoinAddress(seed: string, network?: 'mainnet' | 'testnet'): string;
237
+ declare function deriveBitcoinAddress(seed: string, network?: 'mainnet' | 'testnet'): Promise<string>;
234
238
  /**
235
239
  * Derive Solana address from seed phrase using SLIP-0010 (ed25519)
236
240
  */
@@ -245,13 +249,13 @@ declare function deriveTonAddress(seed: string): Promise<string>;
245
249
  * TRON uses secp256k1 like Ethereum but with base58check encoding
246
250
  * Uses @scure/base for browser compatibility
247
251
  */
248
- declare function deriveTronAddress(seed: string): string;
252
+ declare function deriveTronAddress(seed: string): Promise<string>;
249
253
  /**
250
254
  * Derive Spark address from seed phrase
251
255
  * Spark uses its own derivation path and bech32 format
252
256
  * Uses @scure libraries for browser compatibility
253
257
  */
254
- declare function deriveSparkAddress(seed: string, network?: 'mainnet' | 'testnet'): string;
258
+ declare function deriveSparkAddress(seed: string, network?: 'mainnet' | 'testnet'): Promise<string>;
255
259
  /**
256
260
  * Derive addresses for all supported chains
257
261
  */
@@ -259,11 +263,11 @@ declare function deriveAllAddresses(seed: string, network?: 'mainnet' | 'testnet
259
263
  /**
260
264
  * Validate a BIP-39 seed phrase using @scure/bip39
261
265
  */
262
- declare function isValidSeed(seed: string): boolean;
266
+ declare function isValidSeed(seed: string): Promise<boolean>;
263
267
  /**
264
268
  * Generate a random BIP-39 seed phrase using @scure/bip39
265
269
  */
266
- declare function generateSeedPhrase(): string;
270
+ declare function generateSeedPhrase(): Promise<string>;
267
271
 
268
272
  type BrowserAddressDerivation_BrowserMultiChainAddresses = BrowserMultiChainAddresses;
269
273
  declare const BrowserAddressDerivation_deriveAllAddresses: typeof deriveAllAddresses;
package/dist/index.d.mts CHANGED
@@ -3,7 +3,7 @@ export { D as DERIVATION_PATHS, N as NETWORKS, T as TESTNET_NETWORKS, b as Walle
3
3
  export { M as MemoryStorageAdapter, S as SecureStorageAdapter, W as WebEncryptedStorageAdapter, c as createSecureStorage } from './SecureStorage-jO783AhC.mjs';
4
4
  export { a as ZubariMarketProtocol, Z as ZubariNFTProtocol, d as ZubariPayoutsProtocol, c as ZubariSubscriptionProtocol, b as ZubariTipsProtocol } from './PayoutsProtocol-DKEQhwYH.mjs';
5
5
  export { A as Account, B as BuyParams, h as CreateVoucherParams, E as EarningsBreakdown, L as LazyMintVoucher, k as Listing, j as ListingParams, i as NFT, f as NFTAttribute, N as NFTCurrency, g as NFTMetadata, c as NetworkBalance, b as NetworkType, R as RevenueSplit, e as SendParams, a as Subscription, S as SubscriptionPlan, q as SwapParams, p as SwapQuote, o as Tip, l as TipData, m as TipResult, n as TipStats, d as TokenBalance, T as TxResult, W as WatermarkingData, s as ZubariError, r as ZubariErrorCode, Z as ZubariWalletConfig } from './index-c90msmwW.mjs';
6
- export { B as BrowserAddressDerivation, l as ChainAddress, m as ChainBalance, w as FeeEstimate, F as FeeRates, M as MultiChainAddresses, k as SupportedChain, S as SwapService, v as TransactionHistoryItem, t as TransactionParams, u as TransactionResult, q as TransactionService, x as TransactionServiceConfig, W as WdkApiClient, Z as ZubariWdkService, p as ZubariWdkServiceConfig, s as createTransactionService, i as createZubariWdkService, r as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from './TransactionService-CF_C3Kqm.mjs';
6
+ export { B as BrowserAddressDerivation, l as ChainAddress, m as ChainBalance, w as FeeEstimate, F as FeeRates, M as MultiChainAddresses, k as SupportedChain, S as SwapService, v as TransactionHistoryItem, t as TransactionParams, u as TransactionResult, q as TransactionService, x as TransactionServiceConfig, W as WdkApiClient, Z as ZubariWdkService, p as ZubariWdkServiceConfig, s as createTransactionService, i as createZubariWdkService, r as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from './TransactionService-Cmw33HXX.mjs';
7
7
  import 'abitype';
8
8
  import 'viem';
9
9
  import 'ethers';
package/dist/index.d.ts CHANGED
@@ -3,7 +3,7 @@ export { D as DERIVATION_PATHS, N as NETWORKS, T as TESTNET_NETWORKS, b as Walle
3
3
  export { M as MemoryStorageAdapter, S as SecureStorageAdapter, W as WebEncryptedStorageAdapter, c as createSecureStorage } from './SecureStorage-jO783AhC.js';
4
4
  export { a as ZubariMarketProtocol, Z as ZubariNFTProtocol, d as ZubariPayoutsProtocol, c as ZubariSubscriptionProtocol, b as ZubariTipsProtocol } from './PayoutsProtocol-DAa-9A5C.js';
5
5
  export { A as Account, B as BuyParams, h as CreateVoucherParams, E as EarningsBreakdown, L as LazyMintVoucher, k as Listing, j as ListingParams, i as NFT, f as NFTAttribute, N as NFTCurrency, g as NFTMetadata, c as NetworkBalance, b as NetworkType, R as RevenueSplit, e as SendParams, a as Subscription, S as SubscriptionPlan, q as SwapParams, p as SwapQuote, o as Tip, l as TipData, m as TipResult, n as TipStats, d as TokenBalance, T as TxResult, W as WatermarkingData, s as ZubariError, r as ZubariErrorCode, Z as ZubariWalletConfig } from './index-c90msmwW.js';
6
- export { B as BrowserAddressDerivation, l as ChainAddress, m as ChainBalance, w as FeeEstimate, F as FeeRates, M as MultiChainAddresses, k as SupportedChain, S as SwapService, v as TransactionHistoryItem, t as TransactionParams, u as TransactionResult, q as TransactionService, x as TransactionServiceConfig, W as WdkApiClient, Z as ZubariWdkService, p as ZubariWdkServiceConfig, s as createTransactionService, i as createZubariWdkService, r as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from './TransactionService-BEkgF1T6.js';
6
+ export { B as BrowserAddressDerivation, l as ChainAddress, m as ChainBalance, w as FeeEstimate, F as FeeRates, M as MultiChainAddresses, k as SupportedChain, S as SwapService, v as TransactionHistoryItem, t as TransactionParams, u as TransactionResult, q as TransactionService, x as TransactionServiceConfig, W as WdkApiClient, Z as ZubariWdkService, p as ZubariWdkServiceConfig, s as createTransactionService, i as createZubariWdkService, r as getTransactionService, g as getWdkApiClient, h as getZubariWdkService, j as isBrowser } from './TransactionService-DbNDRzXh.js';
7
7
  import 'abitype';
8
8
  import 'viem';
9
9
  import 'ethers';
package/dist/index.js CHANGED
@@ -1,12 +1,6 @@
1
1
  'use strict';
2
2
 
3
3
  var ethers = require('ethers');
4
- var bip39 = require('@scure/bip39');
5
- var english = require('@scure/bip39/wordlists/english');
6
- var bip32 = require('@scure/bip32');
7
- var base = require('@scure/base');
8
- var sha256 = require('@noble/hashes/sha256');
9
- var ripemd160 = require('@noble/hashes/ripemd160');
10
4
  var viem = require('viem');
11
5
  var chains = require('viem/chains');
12
6
 
@@ -612,25 +606,50 @@ var DERIVATION_PATHS2 = {
612
606
  solana: `${DERIVATION_PATHS.solana}/0'`,
613
607
  spark: `${DERIVATION_PATHS.spark}/0`
614
608
  };
609
+ var _crypto = null;
610
+ async function loadCrypto() {
611
+ if (_crypto) return _crypto;
612
+ const [bip39, bip39Words, bip32, scureBase, sha256Mod, ripemd160Mod] = await Promise.all([
613
+ import('@scure/bip39'),
614
+ import('@scure/bip39/wordlists/english.js'),
615
+ import('@scure/bip32'),
616
+ import('@scure/base'),
617
+ import('@noble/hashes/sha256'),
618
+ import('@noble/hashes/ripemd160')
619
+ ]);
620
+ _crypto = {
621
+ mnemonicToSeedSync: bip39.mnemonicToSeedSync,
622
+ validateMnemonic: bip39.validateMnemonic,
623
+ generateMnemonic: bip39.generateMnemonic,
624
+ wordlist: bip39Words.wordlist,
625
+ HDKey: bip32.HDKey,
626
+ bech32: scureBase.bech32,
627
+ base58check: scureBase.base58check,
628
+ sha256: sha256Mod.sha256,
629
+ ripemd160: ripemd160Mod.ripemd160
630
+ };
631
+ return _crypto;
632
+ }
615
633
  function deriveEthereumAddress(seed) {
616
634
  const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
617
635
  return hdNode.address;
618
636
  }
619
- function deriveBitcoinAddress(seed, network = "mainnet") {
637
+ async function deriveBitcoinAddress(seed, network = "mainnet") {
620
638
  try {
621
- const seedBytes = bip39.mnemonicToSeedSync(seed);
622
- const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
639
+ const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
640
+ const seedBytes = mnemonicToSeedSync(seed);
641
+ const hdKey = HDKey.fromMasterSeed(seedBytes);
623
642
  const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
624
643
  const child = hdKey.derive(path);
625
644
  if (!child.publicKey) {
626
645
  throw new Error("Failed to derive public key");
627
646
  }
628
- const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
647
+ const pubKeyHash = ripemd160(sha256(child.publicKey));
629
648
  const witnessVersion = 0;
630
- const words = base.bech32.toWords(pubKeyHash);
649
+ const words = bech32.toWords(pubKeyHash);
631
650
  words.unshift(witnessVersion);
632
651
  const hrp = network === "testnet" ? "tb" : "bc";
633
- const address = base.bech32.encode(hrp, words);
652
+ const address = bech32.encode(hrp, words);
634
653
  return address;
635
654
  } catch (error) {
636
655
  console.error("Bitcoin address derivation failed:", error);
@@ -639,13 +658,14 @@ function deriveBitcoinAddress(seed, network = "mainnet") {
639
658
  }
640
659
  async function deriveSolanaAddress(seed) {
641
660
  try {
642
- const [ed25519, nacl, bs58Module] = await Promise.all([
661
+ const [crypto2, ed25519, nacl, bs58Module] = await Promise.all([
662
+ loadCrypto(),
643
663
  import('ed25519-hd-key'),
644
664
  import('tweetnacl'),
645
665
  import('bs58')
646
666
  ]);
647
667
  const bs58 = bs58Module.default || bs58Module;
648
- const seedBytes = bip39.mnemonicToSeedSync(seed);
668
+ const seedBytes = crypto2.mnemonicToSeedSync(seed);
649
669
  const derived = ed25519.derivePath(DERIVATION_PATHS2.solana, Buffer.from(seedBytes).toString("hex"));
650
670
  const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
651
671
  return bs58.encode(keypair.publicKey);
@@ -656,17 +676,18 @@ async function deriveSolanaAddress(seed) {
656
676
  }
657
677
  async function deriveTonAddress(seed) {
658
678
  try {
659
- const [ed25519, nacl] = await Promise.all([
679
+ const [crypto2, ed25519, nacl] = await Promise.all([
680
+ loadCrypto(),
660
681
  import('ed25519-hd-key'),
661
682
  import('tweetnacl')
662
683
  ]);
663
- const seedBytes = bip39.mnemonicToSeedSync(seed);
684
+ const seedBytes = crypto2.mnemonicToSeedSync(seed);
664
685
  const derived = ed25519.derivePath(DERIVATION_PATHS2.ton, Buffer.from(seedBytes).toString("hex"));
665
686
  const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
666
687
  const publicKey = keypair.publicKey;
667
688
  const workchain = 0;
668
689
  const flags = 17;
669
- const hash = sha256.sha256(publicKey);
690
+ const hash = crypto2.sha256(publicKey);
670
691
  const addressData = new Uint8Array(34);
671
692
  addressData[0] = flags;
672
693
  addressData[1] = workchain;
@@ -694,8 +715,9 @@ function crc16(data) {
694
715
  }
695
716
  return crc;
696
717
  }
697
- function deriveTronAddress(seed) {
718
+ async function deriveTronAddress(seed) {
698
719
  try {
720
+ const { sha256, base58check } = await loadCrypto();
699
721
  const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.tron);
700
722
  const ethAddressHex = hdNode.address.slice(2).toLowerCase();
701
723
  const addressBytes = new Uint8Array(21);
@@ -703,27 +725,28 @@ function deriveTronAddress(seed) {
703
725
  for (let i = 0; i < 20; i++) {
704
726
  addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
705
727
  }
706
- const tronBase58check = base.base58check(sha256.sha256);
728
+ const tronBase58check = base58check(sha256);
707
729
  return tronBase58check.encode(addressBytes);
708
730
  } catch (error) {
709
731
  console.error("TRON address derivation failed:", error);
710
732
  throw error;
711
733
  }
712
734
  }
713
- function deriveSparkAddress(seed, network = "mainnet") {
735
+ async function deriveSparkAddress(seed, network = "mainnet") {
714
736
  try {
715
- const seedBytes = bip39.mnemonicToSeedSync(seed);
716
- const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
737
+ const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
738
+ const seedBytes = mnemonicToSeedSync(seed);
739
+ const hdKey = HDKey.fromMasterSeed(seedBytes);
717
740
  const child = hdKey.derive(DERIVATION_PATHS2.spark);
718
741
  if (!child.publicKey) {
719
742
  throw new Error("Failed to derive public key");
720
743
  }
721
- const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
744
+ const pubKeyHash = ripemd160(sha256(child.publicKey));
722
745
  const witnessVersion = 0;
723
- const words = base.bech32.toWords(pubKeyHash);
746
+ const words = bech32.toWords(pubKeyHash);
724
747
  words.unshift(witnessVersion);
725
748
  const hrp = network === "testnet" ? "tsp" : "sp";
726
- const address = base.bech32.encode(hrp, words);
749
+ const address = bech32.encode(hrp, words);
727
750
  return address;
728
751
  } catch (error) {
729
752
  console.error("Spark address derivation failed:", error);
@@ -739,47 +762,38 @@ async function deriveAllAddresses(seed, network = "mainnet") {
739
762
  solana: null,
740
763
  spark: null
741
764
  };
765
+ await loadCrypto();
742
766
  try {
743
767
  addresses.ethereum = deriveEthereumAddress(seed);
744
768
  } catch (e) {
745
769
  console.error("ETH derivation failed:", e);
746
770
  }
747
- try {
748
- addresses.bitcoin = deriveBitcoinAddress(seed, network);
749
- } catch (e) {
750
- console.error("BTC derivation failed:", e);
751
- }
752
- try {
753
- addresses.spark = deriveSparkAddress(seed, network);
754
- } catch (e) {
755
- console.error("Spark derivation failed:", e);
756
- }
757
- try {
758
- addresses.tron = deriveTronAddress(seed);
759
- } catch (e) {
760
- console.error("TRON derivation failed:", e);
761
- }
762
- const [solResult, tonResult] = await Promise.allSettled([
771
+ const [btcResult, sparkResult, tronResult, solResult, tonResult] = await Promise.allSettled([
772
+ deriveBitcoinAddress(seed, network),
773
+ deriveSparkAddress(seed, network),
774
+ deriveTronAddress(seed),
763
775
  deriveSolanaAddress(seed),
764
776
  deriveTonAddress(seed)
765
777
  ]);
766
- if (solResult.status === "fulfilled") {
767
- addresses.solana = solResult.value;
768
- } else {
769
- console.error("SOL derivation failed:", solResult.reason);
770
- }
771
- if (tonResult.status === "fulfilled") {
772
- addresses.ton = tonResult.value;
773
- } else {
774
- console.error("TON derivation failed:", tonResult.reason);
775
- }
778
+ if (btcResult.status === "fulfilled") addresses.bitcoin = btcResult.value;
779
+ else console.error("BTC derivation failed:", btcResult.reason);
780
+ if (sparkResult.status === "fulfilled") addresses.spark = sparkResult.value;
781
+ else console.error("Spark derivation failed:", sparkResult.reason);
782
+ if (tronResult.status === "fulfilled") addresses.tron = tronResult.value;
783
+ else console.error("TRON derivation failed:", tronResult.reason);
784
+ if (solResult.status === "fulfilled") addresses.solana = solResult.value;
785
+ else console.error("SOL derivation failed:", solResult.reason);
786
+ if (tonResult.status === "fulfilled") addresses.ton = tonResult.value;
787
+ else console.error("TON derivation failed:", tonResult.reason);
776
788
  return addresses;
777
789
  }
778
- function isValidSeed(seed) {
779
- return bip39.validateMnemonic(seed, english.wordlist);
790
+ async function isValidSeed(seed) {
791
+ const { validateMnemonic, wordlist } = await loadCrypto();
792
+ return validateMnemonic(seed, wordlist);
780
793
  }
781
- function generateSeedPhrase() {
782
- return bip39.generateMnemonic(english.wordlist);
794
+ async function generateSeedPhrase() {
795
+ const { generateMnemonic, wordlist } = await loadCrypto();
796
+ return generateMnemonic(wordlist);
783
797
  }
784
798
 
785
799
  // src/services/ZubariWdkService.ts
@@ -1022,7 +1036,7 @@ var ZubariWdkService = class {
1022
1036
  };
1023
1037
  if (!addresses.spark) {
1024
1038
  try {
1025
- addresses.spark = deriveSparkAddress(seed, this.config.network);
1039
+ addresses.spark = await deriveSparkAddress(seed, this.config.network);
1026
1040
  } catch (e) {
1027
1041
  console.warn("Browser Spark derivation fallback failed:", e);
1028
1042
  }
@@ -1258,13 +1272,13 @@ var ZubariWdkService = class {
1258
1272
  address = deriveEthereumAddress(seed);
1259
1273
  break;
1260
1274
  case "bitcoin":
1261
- address = deriveBitcoinAddress(seed, this.config.network);
1275
+ address = await deriveBitcoinAddress(seed, this.config.network);
1262
1276
  break;
1263
1277
  case "tron":
1264
- address = deriveTronAddress(seed);
1278
+ address = await deriveTronAddress(seed);
1265
1279
  break;
1266
1280
  case "spark":
1267
- address = deriveSparkAddress(seed, this.config.network);
1281
+ address = await deriveSparkAddress(seed, this.config.network);
1268
1282
  break;
1269
1283
  case "solana":
1270
1284
  address = await deriveSolanaAddress(seed);