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