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