@zubari/sdk 0.5.5 → 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.
- package/dist/{TransactionService-DbNDRzXh.d.ts → TransactionService-BEkgF1T6.d.ts} +5 -9
- package/dist/{TransactionService-Cmw33HXX.d.mts → TransactionService-CF_C3Kqm.d.mts} +5 -9
- package/dist/{WalletManager-DIx8nENh.d.mts → WalletManager-BTewpMGA.d.mts} +131 -48
- package/dist/{WalletManager-CeLlZo2y.d.ts → WalletManager-BV1QA08D.d.ts} +131 -48
- package/dist/{contracts-JfZDzaV7.d.ts → contracts-CyIOTDtT.d.ts} +1 -1
- package/dist/{contracts-pugJnFzl.d.mts → contracts-i0GG-cBt.d.mts} +1 -1
- package/dist/index.d.mts +5 -4
- package/dist/index.d.ts +5 -4
- package/dist/index.js +59 -73
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +46 -60
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +4 -3
- package/dist/react/index.d.ts +4 -3
- package/dist/react/index.js +59 -73
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +46 -60
- 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 +59 -73
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +46 -60
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.d.mts +4 -3
- package/dist/wallet/index.d.ts +4 -3
- package/dist/wallet/index.js +59 -73
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +46 -60
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +5 -4
package/dist/wallet/index.mjs
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import { Wallet, HDNodeWallet } from 'ethers';
|
|
2
|
+
import { generateMnemonic, validateMnemonic, mnemonicToSeedSync } from '@scure/bip39';
|
|
3
|
+
import { wordlist } from '@scure/bip39/wordlists/english';
|
|
4
|
+
import { HDKey } from '@scure/bip32';
|
|
5
|
+
import { bech32, base58check } from '@scure/base';
|
|
6
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
7
|
+
import { ripemd160 } from '@noble/hashes/ripemd160';
|
|
2
8
|
import { createPublicClient, http, formatEther, getAddress } from 'viem';
|
|
3
9
|
import { mainnet, sepolia } from 'viem/chains';
|
|
4
10
|
|
|
@@ -394,37 +400,12 @@ var DERIVATION_PATHS2 = {
|
|
|
394
400
|
solana: `${DERIVATION_PATHS.solana}/0'`,
|
|
395
401
|
spark: `${DERIVATION_PATHS.spark}/0`
|
|
396
402
|
};
|
|
397
|
-
var _crypto = null;
|
|
398
|
-
async function loadCrypto() {
|
|
399
|
-
if (_crypto) return _crypto;
|
|
400
|
-
const [bip39, bip39Words, bip32, scureBase, sha256Mod, ripemd160Mod] = await Promise.all([
|
|
401
|
-
import('@scure/bip39'),
|
|
402
|
-
import('@scure/bip39/wordlists/english.js'),
|
|
403
|
-
import('@scure/bip32'),
|
|
404
|
-
import('@scure/base'),
|
|
405
|
-
import('@noble/hashes/sha256'),
|
|
406
|
-
import('@noble/hashes/ripemd160')
|
|
407
|
-
]);
|
|
408
|
-
_crypto = {
|
|
409
|
-
mnemonicToSeedSync: bip39.mnemonicToSeedSync,
|
|
410
|
-
validateMnemonic: bip39.validateMnemonic,
|
|
411
|
-
generateMnemonic: bip39.generateMnemonic,
|
|
412
|
-
wordlist: bip39Words.wordlist,
|
|
413
|
-
HDKey: bip32.HDKey,
|
|
414
|
-
bech32: scureBase.bech32,
|
|
415
|
-
base58check: scureBase.base58check,
|
|
416
|
-
sha256: sha256Mod.sha256,
|
|
417
|
-
ripemd160: ripemd160Mod.ripemd160
|
|
418
|
-
};
|
|
419
|
-
return _crypto;
|
|
420
|
-
}
|
|
421
403
|
function deriveEthereumAddress(seed) {
|
|
422
404
|
const hdNode = HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
|
|
423
405
|
return hdNode.address;
|
|
424
406
|
}
|
|
425
|
-
|
|
407
|
+
function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
426
408
|
try {
|
|
427
|
-
const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
|
|
428
409
|
const seedBytes = mnemonicToSeedSync(seed);
|
|
429
410
|
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
430
411
|
const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
|
|
@@ -446,14 +427,13 @@ async function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
|
446
427
|
}
|
|
447
428
|
async function deriveSolanaAddress(seed) {
|
|
448
429
|
try {
|
|
449
|
-
const [
|
|
450
|
-
loadCrypto(),
|
|
430
|
+
const [ed25519, nacl, bs58Module] = await Promise.all([
|
|
451
431
|
import('ed25519-hd-key'),
|
|
452
432
|
import('tweetnacl'),
|
|
453
433
|
import('bs58')
|
|
454
434
|
]);
|
|
455
435
|
const bs58 = bs58Module.default || bs58Module;
|
|
456
|
-
const seedBytes =
|
|
436
|
+
const seedBytes = mnemonicToSeedSync(seed);
|
|
457
437
|
const derived = ed25519.derivePath(DERIVATION_PATHS2.solana, Buffer.from(seedBytes).toString("hex"));
|
|
458
438
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
459
439
|
return bs58.encode(keypair.publicKey);
|
|
@@ -464,18 +444,17 @@ async function deriveSolanaAddress(seed) {
|
|
|
464
444
|
}
|
|
465
445
|
async function deriveTonAddress(seed) {
|
|
466
446
|
try {
|
|
467
|
-
const [
|
|
468
|
-
loadCrypto(),
|
|
447
|
+
const [ed25519, nacl] = await Promise.all([
|
|
469
448
|
import('ed25519-hd-key'),
|
|
470
449
|
import('tweetnacl')
|
|
471
450
|
]);
|
|
472
|
-
const seedBytes =
|
|
451
|
+
const seedBytes = mnemonicToSeedSync(seed);
|
|
473
452
|
const derived = ed25519.derivePath(DERIVATION_PATHS2.ton, Buffer.from(seedBytes).toString("hex"));
|
|
474
453
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
475
454
|
const publicKey = keypair.publicKey;
|
|
476
455
|
const workchain = 0;
|
|
477
456
|
const flags = 17;
|
|
478
|
-
const hash =
|
|
457
|
+
const hash = sha256(publicKey);
|
|
479
458
|
const addressData = new Uint8Array(34);
|
|
480
459
|
addressData[0] = flags;
|
|
481
460
|
addressData[1] = workchain;
|
|
@@ -503,9 +482,8 @@ function crc16(data) {
|
|
|
503
482
|
}
|
|
504
483
|
return crc;
|
|
505
484
|
}
|
|
506
|
-
|
|
485
|
+
function deriveTronAddress(seed) {
|
|
507
486
|
try {
|
|
508
|
-
const { sha256, base58check } = await loadCrypto();
|
|
509
487
|
const hdNode = HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.tron);
|
|
510
488
|
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
511
489
|
const addressBytes = new Uint8Array(21);
|
|
@@ -520,9 +498,8 @@ async function deriveTronAddress(seed) {
|
|
|
520
498
|
throw error;
|
|
521
499
|
}
|
|
522
500
|
}
|
|
523
|
-
|
|
501
|
+
function deriveSparkAddress(seed, network = "mainnet") {
|
|
524
502
|
try {
|
|
525
|
-
const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
|
|
526
503
|
const seedBytes = mnemonicToSeedSync(seed);
|
|
527
504
|
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
528
505
|
const child = hdKey.derive(DERIVATION_PATHS2.spark);
|
|
@@ -550,37 +527,46 @@ async function deriveAllAddresses(seed, network = "mainnet") {
|
|
|
550
527
|
solana: null,
|
|
551
528
|
spark: null
|
|
552
529
|
};
|
|
553
|
-
await loadCrypto();
|
|
554
530
|
try {
|
|
555
531
|
addresses.ethereum = deriveEthereumAddress(seed);
|
|
556
532
|
} catch (e) {
|
|
557
533
|
console.error("ETH derivation failed:", e);
|
|
558
534
|
}
|
|
559
|
-
|
|
560
|
-
deriveBitcoinAddress(seed, network)
|
|
561
|
-
|
|
562
|
-
|
|
535
|
+
try {
|
|
536
|
+
addresses.bitcoin = deriveBitcoinAddress(seed, network);
|
|
537
|
+
} catch (e) {
|
|
538
|
+
console.error("BTC derivation failed:", e);
|
|
539
|
+
}
|
|
540
|
+
try {
|
|
541
|
+
addresses.spark = deriveSparkAddress(seed, network);
|
|
542
|
+
} catch (e) {
|
|
543
|
+
console.error("Spark derivation failed:", e);
|
|
544
|
+
}
|
|
545
|
+
try {
|
|
546
|
+
addresses.tron = deriveTronAddress(seed);
|
|
547
|
+
} catch (e) {
|
|
548
|
+
console.error("TRON derivation failed:", e);
|
|
549
|
+
}
|
|
550
|
+
const [solResult, tonResult] = await Promise.allSettled([
|
|
563
551
|
deriveSolanaAddress(seed),
|
|
564
552
|
deriveTonAddress(seed)
|
|
565
553
|
]);
|
|
566
|
-
if (
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
else
|
|
574
|
-
|
|
575
|
-
|
|
554
|
+
if (solResult.status === "fulfilled") {
|
|
555
|
+
addresses.solana = solResult.value;
|
|
556
|
+
} else {
|
|
557
|
+
console.error("SOL derivation failed:", solResult.reason);
|
|
558
|
+
}
|
|
559
|
+
if (tonResult.status === "fulfilled") {
|
|
560
|
+
addresses.ton = tonResult.value;
|
|
561
|
+
} else {
|
|
562
|
+
console.error("TON derivation failed:", tonResult.reason);
|
|
563
|
+
}
|
|
576
564
|
return addresses;
|
|
577
565
|
}
|
|
578
|
-
|
|
579
|
-
const { validateMnemonic, wordlist } = await loadCrypto();
|
|
566
|
+
function isValidSeed(seed) {
|
|
580
567
|
return validateMnemonic(seed, wordlist);
|
|
581
568
|
}
|
|
582
|
-
|
|
583
|
-
const { generateMnemonic, wordlist } = await loadCrypto();
|
|
569
|
+
function generateSeedPhrase() {
|
|
584
570
|
return generateMnemonic(wordlist);
|
|
585
571
|
}
|
|
586
572
|
|
|
@@ -824,7 +810,7 @@ var ZubariWdkService = class {
|
|
|
824
810
|
};
|
|
825
811
|
if (!addresses.spark) {
|
|
826
812
|
try {
|
|
827
|
-
addresses.spark =
|
|
813
|
+
addresses.spark = deriveSparkAddress(seed, this.config.network);
|
|
828
814
|
} catch (e) {
|
|
829
815
|
console.warn("Browser Spark derivation fallback failed:", e);
|
|
830
816
|
}
|
|
@@ -1060,13 +1046,13 @@ var ZubariWdkService = class {
|
|
|
1060
1046
|
address = deriveEthereumAddress(seed);
|
|
1061
1047
|
break;
|
|
1062
1048
|
case "bitcoin":
|
|
1063
|
-
address =
|
|
1049
|
+
address = deriveBitcoinAddress(seed, this.config.network);
|
|
1064
1050
|
break;
|
|
1065
1051
|
case "tron":
|
|
1066
|
-
address =
|
|
1052
|
+
address = deriveTronAddress(seed);
|
|
1067
1053
|
break;
|
|
1068
1054
|
case "spark":
|
|
1069
|
-
address =
|
|
1055
|
+
address = deriveSparkAddress(seed, this.config.network);
|
|
1070
1056
|
break;
|
|
1071
1057
|
case "solana":
|
|
1072
1058
|
address = await deriveSolanaAddress(seed);
|