@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/wallet/index.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import { mainnet, sepolia } from 'viem/chains';
|
|
|
4
4
|
import { mnemonicToSeedSync } from '@scure/bip39';
|
|
5
5
|
import '@scure/bip39/wordlists/english';
|
|
6
6
|
import { HDKey } from '@scure/bip32';
|
|
7
|
-
import { bech32 } from '@scure/base';
|
|
7
|
+
import { bech32, base58check } from '@scure/base';
|
|
8
8
|
import { sha256 } from '@noble/hashes/sha256';
|
|
9
9
|
import { ripemd160 } from '@noble/hashes/ripemd160';
|
|
10
10
|
|
|
@@ -2406,59 +2406,6 @@ var require_bs58 = __commonJS({
|
|
|
2406
2406
|
}
|
|
2407
2407
|
});
|
|
2408
2408
|
|
|
2409
|
-
// ../../node_modules/bs58check/base.js
|
|
2410
|
-
var require_base = __commonJS({
|
|
2411
|
-
"../../node_modules/bs58check/base.js"(exports$1, module) {
|
|
2412
|
-
var base58 = require_bs58();
|
|
2413
|
-
module.exports = function(checksumFn) {
|
|
2414
|
-
function encode(payload) {
|
|
2415
|
-
var payloadU8 = Uint8Array.from(payload);
|
|
2416
|
-
var checksum = checksumFn(payloadU8);
|
|
2417
|
-
var length = payloadU8.length + 4;
|
|
2418
|
-
var both = new Uint8Array(length);
|
|
2419
|
-
both.set(payloadU8, 0);
|
|
2420
|
-
both.set(checksum.subarray(0, 4), payloadU8.length);
|
|
2421
|
-
return base58.encode(both, length);
|
|
2422
|
-
}
|
|
2423
|
-
function decodeRaw(buffer) {
|
|
2424
|
-
var payload = buffer.slice(0, -4);
|
|
2425
|
-
var checksum = buffer.slice(-4);
|
|
2426
|
-
var newChecksum = checksumFn(payload);
|
|
2427
|
-
if (checksum[0] ^ newChecksum[0] | checksum[1] ^ newChecksum[1] | checksum[2] ^ newChecksum[2] | checksum[3] ^ newChecksum[3]) return;
|
|
2428
|
-
return payload;
|
|
2429
|
-
}
|
|
2430
|
-
function decodeUnsafe(string) {
|
|
2431
|
-
var buffer = base58.decodeUnsafe(string);
|
|
2432
|
-
if (!buffer) return;
|
|
2433
|
-
return decodeRaw(buffer);
|
|
2434
|
-
}
|
|
2435
|
-
function decode(string) {
|
|
2436
|
-
var buffer = base58.decode(string);
|
|
2437
|
-
var payload = decodeRaw(buffer);
|
|
2438
|
-
if (!payload) throw new Error("Invalid checksum");
|
|
2439
|
-
return payload;
|
|
2440
|
-
}
|
|
2441
|
-
return {
|
|
2442
|
-
encode,
|
|
2443
|
-
decode,
|
|
2444
|
-
decodeUnsafe
|
|
2445
|
-
};
|
|
2446
|
-
};
|
|
2447
|
-
}
|
|
2448
|
-
});
|
|
2449
|
-
|
|
2450
|
-
// ../../node_modules/bs58check/index.js
|
|
2451
|
-
var require_bs58check = __commonJS({
|
|
2452
|
-
"../../node_modules/bs58check/index.js"(exports$1, module) {
|
|
2453
|
-
var { sha256: sha2562 } = __require("@noble/hashes/sha256");
|
|
2454
|
-
var bs58checkBase = require_base();
|
|
2455
|
-
function sha256x2(buffer) {
|
|
2456
|
-
return sha2562(sha2562(buffer));
|
|
2457
|
-
}
|
|
2458
|
-
module.exports = bs58checkBase(sha256x2);
|
|
2459
|
-
}
|
|
2460
|
-
});
|
|
2461
|
-
|
|
2462
2409
|
// src/config/networks.ts
|
|
2463
2410
|
var NETWORKS = {
|
|
2464
2411
|
bitcoin: {
|
|
@@ -3676,9 +3623,8 @@ function crc16(data) {
|
|
|
3676
3623
|
}
|
|
3677
3624
|
return crc;
|
|
3678
3625
|
}
|
|
3679
|
-
|
|
3626
|
+
function deriveTronAddress(seed) {
|
|
3680
3627
|
try {
|
|
3681
|
-
const bs58check = await Promise.resolve().then(() => __toESM(require_bs58check()));
|
|
3682
3628
|
const hdNode = HDNodeWallet.fromPhrase(seed, void 0, DERIVATION_PATHS3.tron);
|
|
3683
3629
|
const ethAddressHex = hdNode.address.slice(2).toLowerCase();
|
|
3684
3630
|
const addressBytes = new Uint8Array(21);
|
|
@@ -3686,7 +3632,8 @@ async function deriveTronAddress(seed) {
|
|
|
3686
3632
|
for (let i = 0; i < 20; i++) {
|
|
3687
3633
|
addressBytes[i + 1] = parseInt(ethAddressHex.slice(i * 2, i * 2 + 2), 16);
|
|
3688
3634
|
}
|
|
3689
|
-
|
|
3635
|
+
const tronBase58check = base58check(sha256);
|
|
3636
|
+
return tronBase58check.encode(addressBytes);
|
|
3690
3637
|
} catch (error) {
|
|
3691
3638
|
console.error("TRON address derivation failed:", error);
|
|
3692
3639
|
throw error;
|
|
@@ -3736,10 +3683,14 @@ async function deriveAllAddresses(seed, network = "testnet") {
|
|
|
3736
3683
|
} catch (e) {
|
|
3737
3684
|
console.error("Spark derivation failed:", e);
|
|
3738
3685
|
}
|
|
3739
|
-
|
|
3686
|
+
try {
|
|
3687
|
+
addresses.tron = deriveTronAddress(seed);
|
|
3688
|
+
} catch (e) {
|
|
3689
|
+
console.error("TRON derivation failed:", e);
|
|
3690
|
+
}
|
|
3691
|
+
const [solResult, tonResult] = await Promise.allSettled([
|
|
3740
3692
|
deriveSolanaAddress(seed),
|
|
3741
|
-
deriveTonAddress(seed)
|
|
3742
|
-
deriveTronAddress(seed)
|
|
3693
|
+
deriveTonAddress(seed)
|
|
3743
3694
|
]);
|
|
3744
3695
|
if (solResult.status === "fulfilled") {
|
|
3745
3696
|
addresses.solana = solResult.value;
|
|
@@ -3751,11 +3702,6 @@ async function deriveAllAddresses(seed, network = "testnet") {
|
|
|
3751
3702
|
} else {
|
|
3752
3703
|
console.error("TON derivation failed:", tonResult.reason);
|
|
3753
3704
|
}
|
|
3754
|
-
if (tronResult.status === "fulfilled") {
|
|
3755
|
-
addresses.tron = tronResult.value;
|
|
3756
|
-
} else {
|
|
3757
|
-
console.error("TRON derivation failed:", tronResult.reason);
|
|
3758
|
-
}
|
|
3759
3705
|
return addresses;
|
|
3760
3706
|
}
|
|
3761
3707
|
|
|
@@ -4267,6 +4213,61 @@ var WalletManager = class _WalletManager {
|
|
|
4267
4213
|
} catch (error) {
|
|
4268
4214
|
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
4269
4215
|
}
|
|
4216
|
+
} else if (chain === "bitcoin") {
|
|
4217
|
+
const baseUrl = this.config.network === "mainnet" ? "https://blockstream.info/api" : "https://blockstream.info/testnet/api";
|
|
4218
|
+
try {
|
|
4219
|
+
const response = await fetch(`${baseUrl}/address/${address}`, {
|
|
4220
|
+
headers: { "Accept": "application/json" }
|
|
4221
|
+
});
|
|
4222
|
+
if (response.ok) {
|
|
4223
|
+
const data = await response.json();
|
|
4224
|
+
const chainFunded = data.chain_stats?.funded_txo_sum || 0;
|
|
4225
|
+
const chainSpent = data.chain_stats?.spent_txo_sum || 0;
|
|
4226
|
+
const mempoolFunded = data.mempool_stats?.funded_txo_sum || 0;
|
|
4227
|
+
const mempoolSpent = data.mempool_stats?.spent_txo_sum || 0;
|
|
4228
|
+
const satoshis = chainFunded - chainSpent + (mempoolFunded - mempoolSpent);
|
|
4229
|
+
balance = (satoshis / 1e8).toFixed(8);
|
|
4230
|
+
}
|
|
4231
|
+
} catch (error) {
|
|
4232
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
4233
|
+
}
|
|
4234
|
+
} else if (chain === "solana") {
|
|
4235
|
+
const rpcUrl = this.config.network === "mainnet" ? "https://api.mainnet-beta.solana.com" : "https://api.devnet.solana.com";
|
|
4236
|
+
try {
|
|
4237
|
+
const response = await fetch(rpcUrl, {
|
|
4238
|
+
method: "POST",
|
|
4239
|
+
headers: { "Content-Type": "application/json" },
|
|
4240
|
+
body: JSON.stringify({
|
|
4241
|
+
jsonrpc: "2.0",
|
|
4242
|
+
id: 1,
|
|
4243
|
+
method: "getBalance",
|
|
4244
|
+
params: [address]
|
|
4245
|
+
})
|
|
4246
|
+
});
|
|
4247
|
+
if (response.ok) {
|
|
4248
|
+
const data = await response.json();
|
|
4249
|
+
if (data.result?.value !== void 0) {
|
|
4250
|
+
balance = (data.result.value / 1e9).toFixed(9);
|
|
4251
|
+
}
|
|
4252
|
+
}
|
|
4253
|
+
} catch (error) {
|
|
4254
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
4255
|
+
}
|
|
4256
|
+
} else if (chain === "tron") {
|
|
4257
|
+
const baseUrl = this.config.network === "mainnet" ? "https://api.trongrid.io" : "https://api.shasta.trongrid.io";
|
|
4258
|
+
try {
|
|
4259
|
+
const response = await fetch(`${baseUrl}/v1/accounts/${address}`, {
|
|
4260
|
+
headers: { "Accept": "application/json" }
|
|
4261
|
+
});
|
|
4262
|
+
if (response.ok) {
|
|
4263
|
+
const data = await response.json();
|
|
4264
|
+
if (data.data?.[0]?.balance !== void 0) {
|
|
4265
|
+
balance = (data.data[0].balance / 1e6).toFixed(6);
|
|
4266
|
+
}
|
|
4267
|
+
}
|
|
4268
|
+
} catch (error) {
|
|
4269
|
+
console.warn(`Failed to fetch ${chain} balance:`, error);
|
|
4270
|
+
}
|
|
4270
4271
|
}
|
|
4271
4272
|
return {
|
|
4272
4273
|
chain,
|