@zubari/sdk 0.5.6 → 0.5.7

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
- export { Z as ZubariWallet } from '../contracts-pugJnFzl.mjs';
2
- export { C as ChainBalance, M as MultiChainAddresses, S as SUPPORTED_CHAINS, b as WalletManager, W as WalletManagerConfig, a as WalletState } from '../WalletManager-DIx8nENh.mjs';
1
+ export { Z as ZubariWallet } from '../contracts-i0GG-cBt.mjs';
2
+ export { C as ChainBalance, M as MultiChainAddresses, S as SUPPORTED_CHAINS, b as WalletManager, W as WalletManagerConfig, a as WalletState } from '../WalletManager-BTewpMGA.mjs';
3
3
  import '../index-c90msmwW.mjs';
4
- import 'abitype';
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
- export { Z as ZubariWallet } from '../contracts-JfZDzaV7.js';
2
- export { C as ChainBalance, M as MultiChainAddresses, S as SUPPORTED_CHAINS, b as WalletManager, W as WalletManagerConfig, a as WalletState } from '../WalletManager-CeLlZo2y.js';
1
+ export { Z as ZubariWallet } from '../contracts-CyIOTDtT.js';
2
+ export { C as ChainBalance, M as MultiChainAddresses, S as SUPPORTED_CHAINS, b as WalletManager, W as WalletManagerConfig, a as WalletState } from '../WalletManager-BV1QA08D.js';
3
3
  import '../index-c90msmwW.js';
4
- import 'abitype';
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';
@@ -1,6 +1,12 @@
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');
4
10
  var viem = require('viem');
5
11
  var chains = require('viem/chains');
6
12
 
@@ -396,50 +402,25 @@ var DERIVATION_PATHS2 = {
396
402
  solana: `${DERIVATION_PATHS.solana}/0'`,
397
403
  spark: `${DERIVATION_PATHS.spark}/0`
398
404
  };
399
- var _crypto = null;
400
- async function loadCrypto() {
401
- if (_crypto) return _crypto;
402
- const [bip39, bip39Words, bip32, scureBase, sha256Mod, ripemd160Mod] = await Promise.all([
403
- import('@scure/bip39'),
404
- import('@scure/bip39/wordlists/english'),
405
- import('@scure/bip32'),
406
- import('@scure/base'),
407
- import('@noble/hashes/sha256'),
408
- import('@noble/hashes/ripemd160')
409
- ]);
410
- _crypto = {
411
- mnemonicToSeedSync: bip39.mnemonicToSeedSync,
412
- validateMnemonic: bip39.validateMnemonic,
413
- generateMnemonic: bip39.generateMnemonic,
414
- wordlist: bip39Words.wordlist,
415
- HDKey: bip32.HDKey,
416
- bech32: scureBase.bech32,
417
- base58check: scureBase.base58check,
418
- sha256: sha256Mod.sha256,
419
- ripemd160: ripemd160Mod.ripemd160
420
- };
421
- return _crypto;
422
- }
423
405
  function deriveEthereumAddress(seed) {
424
406
  const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
425
407
  return hdNode.address;
426
408
  }
427
- async function deriveBitcoinAddress(seed, network = "mainnet") {
409
+ function deriveBitcoinAddress(seed, network = "mainnet") {
428
410
  try {
429
- const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
430
- const seedBytes = mnemonicToSeedSync(seed);
431
- const hdKey = HDKey.fromMasterSeed(seedBytes);
411
+ const seedBytes = bip39.mnemonicToSeedSync(seed);
412
+ const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
432
413
  const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
433
414
  const child = hdKey.derive(path);
434
415
  if (!child.publicKey) {
435
416
  throw new Error("Failed to derive public key");
436
417
  }
437
- const pubKeyHash = ripemd160(sha256(child.publicKey));
418
+ const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
438
419
  const witnessVersion = 0;
439
- const words = bech32.toWords(pubKeyHash);
420
+ const words = base.bech32.toWords(pubKeyHash);
440
421
  words.unshift(witnessVersion);
441
422
  const hrp = network === "testnet" ? "tb" : "bc";
442
- const address = bech32.encode(hrp, words);
423
+ const address = base.bech32.encode(hrp, words);
443
424
  return address;
444
425
  } catch (error) {
445
426
  console.error("Bitcoin address derivation failed:", error);
@@ -448,14 +429,13 @@ async function deriveBitcoinAddress(seed, network = "mainnet") {
448
429
  }
449
430
  async function deriveSolanaAddress(seed) {
450
431
  try {
451
- const [crypto2, ed25519, nacl, bs58Module] = await Promise.all([
452
- loadCrypto(),
432
+ const [ed25519, nacl, bs58Module] = await Promise.all([
453
433
  import('ed25519-hd-key'),
454
434
  import('tweetnacl'),
455
435
  import('bs58')
456
436
  ]);
457
437
  const bs58 = bs58Module.default || bs58Module;
458
- const seedBytes = crypto2.mnemonicToSeedSync(seed);
438
+ const seedBytes = bip39.mnemonicToSeedSync(seed);
459
439
  const derived = ed25519.derivePath(DERIVATION_PATHS2.solana, Buffer.from(seedBytes).toString("hex"));
460
440
  const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
461
441
  return bs58.encode(keypair.publicKey);
@@ -466,18 +446,17 @@ async function deriveSolanaAddress(seed) {
466
446
  }
467
447
  async function deriveTonAddress(seed) {
468
448
  try {
469
- const [crypto2, ed25519, nacl] = await Promise.all([
470
- loadCrypto(),
449
+ const [ed25519, nacl] = await Promise.all([
471
450
  import('ed25519-hd-key'),
472
451
  import('tweetnacl')
473
452
  ]);
474
- const seedBytes = crypto2.mnemonicToSeedSync(seed);
453
+ const seedBytes = bip39.mnemonicToSeedSync(seed);
475
454
  const derived = ed25519.derivePath(DERIVATION_PATHS2.ton, Buffer.from(seedBytes).toString("hex"));
476
455
  const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
477
456
  const publicKey = keypair.publicKey;
478
457
  const workchain = 0;
479
458
  const flags = 17;
480
- const hash = crypto2.sha256(publicKey);
459
+ const hash = sha256.sha256(publicKey);
481
460
  const addressData = new Uint8Array(34);
482
461
  addressData[0] = flags;
483
462
  addressData[1] = workchain;
@@ -505,9 +484,8 @@ function crc16(data) {
505
484
  }
506
485
  return crc;
507
486
  }
508
- async function deriveTronAddress(seed) {
487
+ function deriveTronAddress(seed) {
509
488
  try {
510
- const { sha256, base58check } = await loadCrypto();
511
489
  const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.tron);
512
490
  const ethAddressHex = hdNode.address.slice(2).toLowerCase();
513
491
  const addressBytes = new Uint8Array(21);
@@ -515,28 +493,27 @@ async function deriveTronAddress(seed) {
515
493
  for (let i = 0; i < 20; i++) {
516
494
  addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
517
495
  }
518
- const tronBase58check = base58check(sha256);
496
+ const tronBase58check = base.base58check(sha256.sha256);
519
497
  return tronBase58check.encode(addressBytes);
520
498
  } catch (error) {
521
499
  console.error("TRON address derivation failed:", error);
522
500
  throw error;
523
501
  }
524
502
  }
525
- async function deriveSparkAddress(seed, network = "mainnet") {
503
+ function deriveSparkAddress(seed, network = "mainnet") {
526
504
  try {
527
- const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
528
- const seedBytes = mnemonicToSeedSync(seed);
529
- const hdKey = HDKey.fromMasterSeed(seedBytes);
505
+ const seedBytes = bip39.mnemonicToSeedSync(seed);
506
+ const hdKey = bip32.HDKey.fromMasterSeed(seedBytes);
530
507
  const child = hdKey.derive(DERIVATION_PATHS2.spark);
531
508
  if (!child.publicKey) {
532
509
  throw new Error("Failed to derive public key");
533
510
  }
534
- const pubKeyHash = ripemd160(sha256(child.publicKey));
511
+ const pubKeyHash = ripemd160.ripemd160(sha256.sha256(child.publicKey));
535
512
  const witnessVersion = 0;
536
- const words = bech32.toWords(pubKeyHash);
513
+ const words = base.bech32.toWords(pubKeyHash);
537
514
  words.unshift(witnessVersion);
538
515
  const hrp = network === "testnet" ? "tsp" : "sp";
539
- const address = bech32.encode(hrp, words);
516
+ const address = base.bech32.encode(hrp, words);
540
517
  return address;
541
518
  } catch (error) {
542
519
  console.error("Spark address derivation failed:", error);
@@ -552,38 +529,47 @@ async function deriveAllAddresses(seed, network = "mainnet") {
552
529
  solana: null,
553
530
  spark: null
554
531
  };
555
- await loadCrypto();
556
532
  try {
557
533
  addresses.ethereum = deriveEthereumAddress(seed);
558
534
  } catch (e) {
559
535
  console.error("ETH derivation failed:", e);
560
536
  }
561
- const [btcResult, sparkResult, tronResult, solResult, tonResult] = await Promise.allSettled([
562
- deriveBitcoinAddress(seed, network),
563
- deriveSparkAddress(seed, network),
564
- deriveTronAddress(seed),
537
+ try {
538
+ addresses.bitcoin = deriveBitcoinAddress(seed, network);
539
+ } catch (e) {
540
+ console.error("BTC derivation failed:", e);
541
+ }
542
+ try {
543
+ addresses.spark = deriveSparkAddress(seed, network);
544
+ } catch (e) {
545
+ console.error("Spark derivation failed:", e);
546
+ }
547
+ try {
548
+ addresses.tron = deriveTronAddress(seed);
549
+ } catch (e) {
550
+ console.error("TRON derivation failed:", e);
551
+ }
552
+ const [solResult, tonResult] = await Promise.allSettled([
565
553
  deriveSolanaAddress(seed),
566
554
  deriveTonAddress(seed)
567
555
  ]);
568
- if (btcResult.status === "fulfilled") addresses.bitcoin = btcResult.value;
569
- else console.error("BTC derivation failed:", btcResult.reason);
570
- if (sparkResult.status === "fulfilled") addresses.spark = sparkResult.value;
571
- else console.error("Spark derivation failed:", sparkResult.reason);
572
- if (tronResult.status === "fulfilled") addresses.tron = tronResult.value;
573
- else console.error("TRON derivation failed:", tronResult.reason);
574
- if (solResult.status === "fulfilled") addresses.solana = solResult.value;
575
- else console.error("SOL derivation failed:", solResult.reason);
576
- if (tonResult.status === "fulfilled") addresses.ton = tonResult.value;
577
- else console.error("TON derivation failed:", tonResult.reason);
556
+ if (solResult.status === "fulfilled") {
557
+ addresses.solana = solResult.value;
558
+ } else {
559
+ console.error("SOL derivation failed:", solResult.reason);
560
+ }
561
+ if (tonResult.status === "fulfilled") {
562
+ addresses.ton = tonResult.value;
563
+ } else {
564
+ console.error("TON derivation failed:", tonResult.reason);
565
+ }
578
566
  return addresses;
579
567
  }
580
- async function isValidSeed(seed) {
581
- const { validateMnemonic, wordlist } = await loadCrypto();
582
- return validateMnemonic(seed, wordlist);
568
+ function isValidSeed(seed) {
569
+ return bip39.validateMnemonic(seed, english.wordlist);
583
570
  }
584
- async function generateSeedPhrase() {
585
- const { generateMnemonic, wordlist } = await loadCrypto();
586
- return generateMnemonic(wordlist);
571
+ function generateSeedPhrase() {
572
+ return bip39.generateMnemonic(english.wordlist);
587
573
  }
588
574
 
589
575
  // src/services/ZubariWdkService.ts
@@ -826,7 +812,7 @@ var ZubariWdkService = class {
826
812
  };
827
813
  if (!addresses.spark) {
828
814
  try {
829
- addresses.spark = await deriveSparkAddress(seed, this.config.network);
815
+ addresses.spark = deriveSparkAddress(seed, this.config.network);
830
816
  } catch (e) {
831
817
  console.warn("Browser Spark derivation fallback failed:", e);
832
818
  }
@@ -1062,13 +1048,13 @@ var ZubariWdkService = class {
1062
1048
  address = deriveEthereumAddress(seed);
1063
1049
  break;
1064
1050
  case "bitcoin":
1065
- address = await deriveBitcoinAddress(seed, this.config.network);
1051
+ address = deriveBitcoinAddress(seed, this.config.network);
1066
1052
  break;
1067
1053
  case "tron":
1068
- address = await deriveTronAddress(seed);
1054
+ address = deriveTronAddress(seed);
1069
1055
  break;
1070
1056
  case "spark":
1071
- address = await deriveSparkAddress(seed, this.config.network);
1057
+ address = deriveSparkAddress(seed, this.config.network);
1072
1058
  break;
1073
1059
  case "solana":
1074
1060
  address = await deriveSolanaAddress(seed);