@zubari/sdk 0.1.3 → 0.1.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/index.js +65 -64
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +66 -65
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.js +65 -64
- package/dist/react/index.js.map +1 -1
- package/dist/react/index.mjs +66 -65
- package/dist/react/index.mjs.map +1 -1
- package/dist/services/index.d.mts +2 -1
- package/dist/services/index.d.ts +2 -1
- package/dist/services/index.js +10 -64
- package/dist/services/index.js.map +1 -1
- package/dist/services/index.mjs +11 -65
- package/dist/services/index.mjs.map +1 -1
- package/dist/wallet/index.js +65 -64
- package/dist/wallet/index.js.map +1 -1
- package/dist/wallet/index.mjs +66 -65
- package/dist/wallet/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { mainnet, sepolia } from 'viem/chains';
|
|
|
5
5
|
import { mnemonicToSeedSync } from '@scure/bip39';
|
|
6
6
|
import '@scure/bip39/wordlists/english';
|
|
7
7
|
import { HDKey } from '@scure/bip32';
|
|
8
|
-
import { bech32 } from '@scure/base';
|
|
8
|
+
import { bech32, base58check } from '@scure/base';
|
|
9
9
|
import { sha256 } from '@noble/hashes/sha256';
|
|
10
10
|
import { ripemd160 } from '@noble/hashes/ripemd160';
|
|
11
11
|
|
|
@@ -2407,59 +2407,6 @@ var require_bs58 = __commonJS({
|
|
|
2407
2407
|
}
|
|
2408
2408
|
});
|
|
2409
2409
|
|
|
2410
|
-
// ../../node_modules/bs58check/base.js
|
|
2411
|
-
var require_base = __commonJS({
|
|
2412
|
-
"../../node_modules/bs58check/base.js"(exports$1, module) {
|
|
2413
|
-
var base58 = require_bs58();
|
|
2414
|
-
module.exports = function(checksumFn) {
|
|
2415
|
-
function encode(payload) {
|
|
2416
|
-
var payloadU8 = Uint8Array.from(payload);
|
|
2417
|
-
var checksum = checksumFn(payloadU8);
|
|
2418
|
-
var length = payloadU8.length + 4;
|
|
2419
|
-
var both = new Uint8Array(length);
|
|
2420
|
-
both.set(payloadU8, 0);
|
|
2421
|
-
both.set(checksum.subarray(0, 4), payloadU8.length);
|
|
2422
|
-
return base58.encode(both, length);
|
|
2423
|
-
}
|
|
2424
|
-
function decodeRaw(buffer) {
|
|
2425
|
-
var payload = buffer.slice(0, -4);
|
|
2426
|
-
var checksum = buffer.slice(-4);
|
|
2427
|
-
var newChecksum = checksumFn(payload);
|
|
2428
|
-
if (checksum[0] ^ newChecksum[0] | checksum[1] ^ newChecksum[1] | checksum[2] ^ newChecksum[2] | checksum[3] ^ newChecksum[3]) return;
|
|
2429
|
-
return payload;
|
|
2430
|
-
}
|
|
2431
|
-
function decodeUnsafe(string) {
|
|
2432
|
-
var buffer = base58.decodeUnsafe(string);
|
|
2433
|
-
if (!buffer) return;
|
|
2434
|
-
return decodeRaw(buffer);
|
|
2435
|
-
}
|
|
2436
|
-
function decode(string) {
|
|
2437
|
-
var buffer = base58.decode(string);
|
|
2438
|
-
var payload = decodeRaw(buffer);
|
|
2439
|
-
if (!payload) throw new Error("Invalid checksum");
|
|
2440
|
-
return payload;
|
|
2441
|
-
}
|
|
2442
|
-
return {
|
|
2443
|
-
encode,
|
|
2444
|
-
decode,
|
|
2445
|
-
decodeUnsafe
|
|
2446
|
-
};
|
|
2447
|
-
};
|
|
2448
|
-
}
|
|
2449
|
-
});
|
|
2450
|
-
|
|
2451
|
-
// ../../node_modules/bs58check/index.js
|
|
2452
|
-
var require_bs58check = __commonJS({
|
|
2453
|
-
"../../node_modules/bs58check/index.js"(exports$1, module) {
|
|
2454
|
-
var { sha256: sha2562 } = __require("@noble/hashes/sha256");
|
|
2455
|
-
var bs58checkBase = require_base();
|
|
2456
|
-
function sha256x2(buffer) {
|
|
2457
|
-
return sha2562(sha2562(buffer));
|
|
2458
|
-
}
|
|
2459
|
-
module.exports = bs58checkBase(sha256x2);
|
|
2460
|
-
}
|
|
2461
|
-
});
|
|
2462
|
-
|
|
2463
2410
|
// src/config/networks.ts
|
|
2464
2411
|
var NETWORKS = {
|
|
2465
2412
|
bitcoin: {
|
|
@@ -3376,9 +3323,8 @@ function crc16(data) {
|
|
|
3376
3323
|
}
|
|
3377
3324
|
return crc;
|
|
3378
3325
|
}
|
|
3379
|
-
|
|
3326
|
+
function deriveTronAddress(seed) {
|
|
3380
3327
|
try {
|
|
3381
|
-
const bs58check = await Promise.resolve().then(() => __toESM(require_bs58check()));
|
|
3382
3328
|
const hdNode = HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS3.tron);
|
|
3383
3329
|
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
3384
3330
|
const addressBytes = new Uint8Array(21);
|
|
@@ -3386,7 +3332,8 @@ async function deriveTronAddress(seed) {
|
|
|
3386
3332
|
for (let i = 0; i < 20; i++) {
|
|
3387
3333
|
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
3388
3334
|
}
|
|
3389
|
-
|
|
3335
|
+
const tronBase58check = base58check(sha256);
|
|
3336
|
+
return tronBase58check.encode(addressBytes);
|
|
3390
3337
|
} catch (error) {
|
|
3391
3338
|
console.error("TRON address derivation failed:", error);
|
|
3392
3339
|
throw error;
|
|
@@ -3436,10 +3383,14 @@ async function deriveAllAddresses(seed, network = "testnet") {
|
|
|
3436
3383
|
} catch (e) {
|
|
3437
3384
|
console.error("Spark derivation failed:", e);
|
|
3438
3385
|
}
|
|
3439
|
-
|
|
3386
|
+
try {
|
|
3387
|
+
addresses.tron = deriveTronAddress(seed);
|
|
3388
|
+
} catch (e) {
|
|
3389
|
+
console.error("TRON derivation failed:", e);
|
|
3390
|
+
}
|
|
3391
|
+
const [solResult, tonResult] = await Promise.allSettled([
|
|
3440
3392
|
deriveSolanaAddress(seed),
|
|
3441
|
-
deriveTonAddress(seed)
|
|
3442
|
-
deriveTronAddress(seed)
|
|
3393
|
+
deriveTonAddress(seed)
|
|
3443
3394
|
]);
|
|
3444
3395
|
if (solResult.status === "fulfilled") {
|
|
3445
3396
|
addresses.solana = solResult.value;
|
|
@@ -3451,11 +3402,6 @@ async function deriveAllAddresses(seed, network = "testnet") {
|
|
|
3451
3402
|
} else {
|
|
3452
3403
|
console.error("TON derivation failed:", tonResult.reason);
|
|
3453
3404
|
}
|
|
3454
|
-
if (tronResult.status === "fulfilled") {
|
|
3455
|
-
addresses.tron = tronResult.value;
|
|
3456
|
-
} else {
|
|
3457
|
-
console.error("TRON derivation failed:", tronResult.reason);
|
|
3458
|
-
}
|
|
3459
3405
|
return addresses;
|
|
3460
3406
|
}
|
|
3461
3407
|
|
|
@@ -3967,6 +3913,61 @@ var WalletManager = class _WalletManager {
|
|
|
3967
3913
|
} catch (error) {
|
|
3968
3914
|
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
3969
3915
|
}
|
|
3916
|
+
} else if (chain === "bitcoin") {
|
|
3917
|
+
const baseUrl = this.config.network === "mainnet" ? "https://blockstream.info/api" : "https://blockstream.info/testnet/api";
|
|
3918
|
+
try {
|
|
3919
|
+
const response = await fetch(`${baseUrl}/address/${address}`, {
|
|
3920
|
+
headers: { "Accept": "application/json" }
|
|
3921
|
+
});
|
|
3922
|
+
if (response.ok) {
|
|
3923
|
+
const data = await response.json();
|
|
3924
|
+
const chainFunded = data.chain_stats?.funded_txo_sum || 0;
|
|
3925
|
+
const chainSpent = data.chain_stats?.spent_txo_sum || 0;
|
|
3926
|
+
const mempoolFunded = data.mempool_stats?.funded_txo_sum || 0;
|
|
3927
|
+
const mempoolSpent = data.mempool_stats?.spent_txo_sum || 0;
|
|
3928
|
+
const satoshis = chainFunded - chainSpent + (mempoolFunded - mempoolSpent);
|
|
3929
|
+
balance = (satoshis / 1e8).toFixed(8);
|
|
3930
|
+
}
|
|
3931
|
+
} catch (error) {
|
|
3932
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
3933
|
+
}
|
|
3934
|
+
} else if (chain === "solana") {
|
|
3935
|
+
const rpcUrl = this.config.network === "mainnet" ? "https://api.mainnet-beta.solana.com" : "https://api.devnet.solana.com";
|
|
3936
|
+
try {
|
|
3937
|
+
const response = await fetch(rpcUrl, {
|
|
3938
|
+
method: "POST",
|
|
3939
|
+
headers: { "Content-Type": "application/json" },
|
|
3940
|
+
body: JSON.stringify({
|
|
3941
|
+
jsonrpc: "2.0",
|
|
3942
|
+
id: 1,
|
|
3943
|
+
method: "getBalance",
|
|
3944
|
+
params: [address]
|
|
3945
|
+
})
|
|
3946
|
+
});
|
|
3947
|
+
if (response.ok) {
|
|
3948
|
+
const data = await response.json();
|
|
3949
|
+
if (data.result?.value !== void 0) {
|
|
3950
|
+
balance = (data.result.value / 1e9).toFixed(9);
|
|
3951
|
+
}
|
|
3952
|
+
}
|
|
3953
|
+
} catch (error) {
|
|
3954
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
3955
|
+
}
|
|
3956
|
+
} else if (chain === "tron") {
|
|
3957
|
+
const baseUrl = this.config.network === "mainnet" ? "https://api.trongrid.io" : "https://api.shasta.trongrid.io";
|
|
3958
|
+
try {
|
|
3959
|
+
const response = await fetch(`${baseUrl}/v1/accounts/${address}`, {
|
|
3960
|
+
headers: { "Accept": "application/json" }
|
|
3961
|
+
});
|
|
3962
|
+
if (response.ok) {
|
|
3963
|
+
const data = await response.json();
|
|
3964
|
+
if (data.data?.[0]?.balance !== void 0) {
|
|
3965
|
+
balance = (data.data[0].balance / 1e6).toFixed(6);
|
|
3966
|
+
}
|
|
3967
|
+
}
|
|
3968
|
+
} catch (error) {
|
|
3969
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
3970
|
+
}
|
|
3970
3971
|
}
|
|
3971
3972
|
return {
|
|
3972
3973
|
chain,
|