@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/react/index.js
CHANGED
|
@@ -2,12 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
var react = require('react');
|
|
4
4
|
var ethers = require('ethers');
|
|
5
|
-
var bip39 = require('@scure/bip39');
|
|
6
|
-
var english = require('@scure/bip39/wordlists/english');
|
|
7
|
-
var bip32 = require('@scure/bip32');
|
|
8
|
-
var base = require('@scure/base');
|
|
9
|
-
var sha256 = require('@noble/hashes/sha256');
|
|
10
|
-
var ripemd160 = require('@noble/hashes/ripemd160');
|
|
11
5
|
var viem = require('viem');
|
|
12
6
|
var chains = require('viem/chains');
|
|
13
7
|
|
|
@@ -347,25 +341,50 @@ var DERIVATION_PATHS2 = {
|
|
|
347
341
|
solana: `${DERIVATION_PATHS.solana}/0'`,
|
|
348
342
|
spark: `${DERIVATION_PATHS.spark}/0`
|
|
349
343
|
};
|
|
344
|
+
var _crypto = null;
|
|
345
|
+
async function loadCrypto() {
|
|
346
|
+
if (_crypto) return _crypto;
|
|
347
|
+
const [bip39, bip39Words, bip32, scureBase, sha256Mod, ripemd160Mod] = await Promise.all([
|
|
348
|
+
import('@scure/bip39'),
|
|
349
|
+
import('@scure/bip39/wordlists/english'),
|
|
350
|
+
import('@scure/bip32'),
|
|
351
|
+
import('@scure/base'),
|
|
352
|
+
import('@noble/hashes/sha256'),
|
|
353
|
+
import('@noble/hashes/ripemd160')
|
|
354
|
+
]);
|
|
355
|
+
_crypto = {
|
|
356
|
+
mnemonicToSeedSync: bip39.mnemonicToSeedSync,
|
|
357
|
+
validateMnemonic: bip39.validateMnemonic,
|
|
358
|
+
generateMnemonic: bip39.generateMnemonic,
|
|
359
|
+
wordlist: bip39Words.wordlist,
|
|
360
|
+
HDKey: bip32.HDKey,
|
|
361
|
+
bech32: scureBase.bech32,
|
|
362
|
+
base58check: scureBase.base58check,
|
|
363
|
+
sha256: sha256Mod.sha256,
|
|
364
|
+
ripemd160: ripemd160Mod.ripemd160
|
|
365
|
+
};
|
|
366
|
+
return _crypto;
|
|
367
|
+
}
|
|
350
368
|
function deriveEthereumAddress(seed) {
|
|
351
369
|
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.ethereum);
|
|
352
370
|
return hdNode.address;
|
|
353
371
|
}
|
|
354
|
-
function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
372
|
+
async function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
355
373
|
try {
|
|
356
|
-
const
|
|
357
|
-
const
|
|
374
|
+
const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
|
|
375
|
+
const seedBytes = mnemonicToSeedSync(seed);
|
|
376
|
+
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
358
377
|
const path = network === "testnet" ? DERIVATION_PATHS2.bitcoin_testnet : DERIVATION_PATHS2.bitcoin_mainnet;
|
|
359
378
|
const child = hdKey.derive(path);
|
|
360
379
|
if (!child.publicKey) {
|
|
361
380
|
throw new Error("Failed to derive public key");
|
|
362
381
|
}
|
|
363
|
-
const pubKeyHash = ripemd160
|
|
382
|
+
const pubKeyHash = ripemd160(sha256(child.publicKey));
|
|
364
383
|
const witnessVersion = 0;
|
|
365
|
-
const words =
|
|
384
|
+
const words = bech32.toWords(pubKeyHash);
|
|
366
385
|
words.unshift(witnessVersion);
|
|
367
386
|
const hrp = network === "testnet" ? "tb" : "bc";
|
|
368
|
-
const address =
|
|
387
|
+
const address = bech32.encode(hrp, words);
|
|
369
388
|
return address;
|
|
370
389
|
} catch (error) {
|
|
371
390
|
console.error("Bitcoin address derivation failed:", error);
|
|
@@ -374,13 +393,14 @@ function deriveBitcoinAddress(seed, network = "mainnet") {
|
|
|
374
393
|
}
|
|
375
394
|
async function deriveSolanaAddress(seed) {
|
|
376
395
|
try {
|
|
377
|
-
const [ed25519, nacl, bs58Module] = await Promise.all([
|
|
396
|
+
const [crypto2, ed25519, nacl, bs58Module] = await Promise.all([
|
|
397
|
+
loadCrypto(),
|
|
378
398
|
import('ed25519-hd-key'),
|
|
379
399
|
import('tweetnacl'),
|
|
380
400
|
import('bs58')
|
|
381
401
|
]);
|
|
382
402
|
const bs58 = bs58Module.default || bs58Module;
|
|
383
|
-
const seedBytes =
|
|
403
|
+
const seedBytes = crypto2.mnemonicToSeedSync(seed);
|
|
384
404
|
const derived = ed25519.derivePath(DERIVATION_PATHS2.solana, Buffer.from(seedBytes).toString("hex"));
|
|
385
405
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
386
406
|
return bs58.encode(keypair.publicKey);
|
|
@@ -391,17 +411,18 @@ async function deriveSolanaAddress(seed) {
|
|
|
391
411
|
}
|
|
392
412
|
async function deriveTonAddress(seed) {
|
|
393
413
|
try {
|
|
394
|
-
const [ed25519, nacl] = await Promise.all([
|
|
414
|
+
const [crypto2, ed25519, nacl] = await Promise.all([
|
|
415
|
+
loadCrypto(),
|
|
395
416
|
import('ed25519-hd-key'),
|
|
396
417
|
import('tweetnacl')
|
|
397
418
|
]);
|
|
398
|
-
const seedBytes =
|
|
419
|
+
const seedBytes = crypto2.mnemonicToSeedSync(seed);
|
|
399
420
|
const derived = ed25519.derivePath(DERIVATION_PATHS2.ton, Buffer.from(seedBytes).toString("hex"));
|
|
400
421
|
const keypair = nacl.sign.keyPair.fromSeed(new Uint8Array(derived.key));
|
|
401
422
|
const publicKey = keypair.publicKey;
|
|
402
423
|
const workchain = 0;
|
|
403
424
|
const flags = 17;
|
|
404
|
-
const hash =
|
|
425
|
+
const hash = crypto2.sha256(publicKey);
|
|
405
426
|
const addressData = new Uint8Array(34);
|
|
406
427
|
addressData[0] = flags;
|
|
407
428
|
addressData[1] = workchain;
|
|
@@ -429,8 +450,9 @@ function crc16(data) {
|
|
|
429
450
|
}
|
|
430
451
|
return crc;
|
|
431
452
|
}
|
|
432
|
-
function deriveTronAddress(seed) {
|
|
453
|
+
async function deriveTronAddress(seed) {
|
|
433
454
|
try {
|
|
455
|
+
const { sha256, base58check } = await loadCrypto();
|
|
434
456
|
const hdNode = ethers.HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS2.tron);
|
|
435
457
|
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
436
458
|
const addressBytes = new Uint8Array(21);
|
|
@@ -438,27 +460,28 @@ function deriveTronAddress(seed) {
|
|
|
438
460
|
for (let i = 0; i < 20; i++) {
|
|
439
461
|
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
440
462
|
}
|
|
441
|
-
const tronBase58check =
|
|
463
|
+
const tronBase58check = base58check(sha256);
|
|
442
464
|
return tronBase58check.encode(addressBytes);
|
|
443
465
|
} catch (error) {
|
|
444
466
|
console.error("TRON address derivation failed:", error);
|
|
445
467
|
throw error;
|
|
446
468
|
}
|
|
447
469
|
}
|
|
448
|
-
function deriveSparkAddress(seed, network = "mainnet") {
|
|
470
|
+
async function deriveSparkAddress(seed, network = "mainnet") {
|
|
449
471
|
try {
|
|
450
|
-
const
|
|
451
|
-
const
|
|
472
|
+
const { mnemonicToSeedSync, HDKey, sha256, ripemd160, bech32 } = await loadCrypto();
|
|
473
|
+
const seedBytes = mnemonicToSeedSync(seed);
|
|
474
|
+
const hdKey = HDKey.fromMasterSeed(seedBytes);
|
|
452
475
|
const child = hdKey.derive(DERIVATION_PATHS2.spark);
|
|
453
476
|
if (!child.publicKey) {
|
|
454
477
|
throw new Error("Failed to derive public key");
|
|
455
478
|
}
|
|
456
|
-
const pubKeyHash = ripemd160
|
|
479
|
+
const pubKeyHash = ripemd160(sha256(child.publicKey));
|
|
457
480
|
const witnessVersion = 0;
|
|
458
|
-
const words =
|
|
481
|
+
const words = bech32.toWords(pubKeyHash);
|
|
459
482
|
words.unshift(witnessVersion);
|
|
460
483
|
const hrp = network === "testnet" ? "tsp" : "sp";
|
|
461
|
-
const address =
|
|
484
|
+
const address = bech32.encode(hrp, words);
|
|
462
485
|
return address;
|
|
463
486
|
} catch (error) {
|
|
464
487
|
console.error("Spark address derivation failed:", error);
|
|
@@ -474,47 +497,38 @@ async function deriveAllAddresses(seed, network = "mainnet") {
|
|
|
474
497
|
solana: null,
|
|
475
498
|
spark: null
|
|
476
499
|
};
|
|
500
|
+
await loadCrypto();
|
|
477
501
|
try {
|
|
478
502
|
addresses.ethereum = deriveEthereumAddress(seed);
|
|
479
503
|
} catch (e) {
|
|
480
504
|
console.error("ETH derivation failed:", e);
|
|
481
505
|
}
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
}
|
|
487
|
-
try {
|
|
488
|
-
addresses.spark = deriveSparkAddress(seed, network);
|
|
489
|
-
} catch (e) {
|
|
490
|
-
console.error("Spark derivation failed:", e);
|
|
491
|
-
}
|
|
492
|
-
try {
|
|
493
|
-
addresses.tron = deriveTronAddress(seed);
|
|
494
|
-
} catch (e) {
|
|
495
|
-
console.error("TRON derivation failed:", e);
|
|
496
|
-
}
|
|
497
|
-
const [solResult, tonResult] = await Promise.allSettled([
|
|
506
|
+
const [btcResult, sparkResult, tronResult, solResult, tonResult] = await Promise.allSettled([
|
|
507
|
+
deriveBitcoinAddress(seed, network),
|
|
508
|
+
deriveSparkAddress(seed, network),
|
|
509
|
+
deriveTronAddress(seed),
|
|
498
510
|
deriveSolanaAddress(seed),
|
|
499
511
|
deriveTonAddress(seed)
|
|
500
512
|
]);
|
|
501
|
-
if (
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
513
|
+
if (btcResult.status === "fulfilled") addresses.bitcoin = btcResult.value;
|
|
514
|
+
else console.error("BTC derivation failed:", btcResult.reason);
|
|
515
|
+
if (sparkResult.status === "fulfilled") addresses.spark = sparkResult.value;
|
|
516
|
+
else console.error("Spark derivation failed:", sparkResult.reason);
|
|
517
|
+
if (tronResult.status === "fulfilled") addresses.tron = tronResult.value;
|
|
518
|
+
else console.error("TRON derivation failed:", tronResult.reason);
|
|
519
|
+
if (solResult.status === "fulfilled") addresses.solana = solResult.value;
|
|
520
|
+
else console.error("SOL derivation failed:", solResult.reason);
|
|
521
|
+
if (tonResult.status === "fulfilled") addresses.ton = tonResult.value;
|
|
522
|
+
else console.error("TON derivation failed:", tonResult.reason);
|
|
511
523
|
return addresses;
|
|
512
524
|
}
|
|
513
|
-
function isValidSeed(seed) {
|
|
514
|
-
|
|
525
|
+
async function isValidSeed(seed) {
|
|
526
|
+
const { validateMnemonic, wordlist } = await loadCrypto();
|
|
527
|
+
return validateMnemonic(seed, wordlist);
|
|
515
528
|
}
|
|
516
|
-
function generateSeedPhrase() {
|
|
517
|
-
|
|
529
|
+
async function generateSeedPhrase() {
|
|
530
|
+
const { generateMnemonic, wordlist } = await loadCrypto();
|
|
531
|
+
return generateMnemonic(wordlist);
|
|
518
532
|
}
|
|
519
533
|
|
|
520
534
|
// src/services/ZubariWdkService.ts
|
|
@@ -757,7 +771,7 @@ var ZubariWdkService = class {
|
|
|
757
771
|
};
|
|
758
772
|
if (!addresses.spark) {
|
|
759
773
|
try {
|
|
760
|
-
addresses.spark = deriveSparkAddress(seed, this.config.network);
|
|
774
|
+
addresses.spark = await deriveSparkAddress(seed, this.config.network);
|
|
761
775
|
} catch (e) {
|
|
762
776
|
console.warn("Browser Spark derivation fallback failed:", e);
|
|
763
777
|
}
|
|
@@ -993,13 +1007,13 @@ var ZubariWdkService = class {
|
|
|
993
1007
|
address = deriveEthereumAddress(seed);
|
|
994
1008
|
break;
|
|
995
1009
|
case "bitcoin":
|
|
996
|
-
address = deriveBitcoinAddress(seed, this.config.network);
|
|
1010
|
+
address = await deriveBitcoinAddress(seed, this.config.network);
|
|
997
1011
|
break;
|
|
998
1012
|
case "tron":
|
|
999
|
-
address = deriveTronAddress(seed);
|
|
1013
|
+
address = await deriveTronAddress(seed);
|
|
1000
1014
|
break;
|
|
1001
1015
|
case "spark":
|
|
1002
|
-
address = deriveSparkAddress(seed, this.config.network);
|
|
1016
|
+
address = await deriveSparkAddress(seed, this.config.network);
|
|
1003
1017
|
break;
|
|
1004
1018
|
case "solana":
|
|
1005
1019
|
address = await deriveSolanaAddress(seed);
|