fix: convert zpub to Ltub before LTC HD derivation

This commit is contained in:
M1
2026-03-18 23:18:49 +04:00
parent bc0f7715da
commit 91c24b20f7
2 changed files with 16 additions and 5 deletions
+11 -1
View File
@@ -82,7 +82,17 @@ export function deriveAddressSafe(coin: string, index: number): string {
return addr.replace(/^bitcoincash:/, "ecash:");
}
if (coin === "ltc") {
const hd = new bitcoreLtc.HDPublicKey(xpub);
// zpub uses BIP84 version bytes — convert to Ltub so bitcore-lib-ltc can parse it
let key = xpub;
if (xpub.startsWith("zpub") || xpub.startsWith("Zpub")) {
// Decode base58check, swap version bytes to Ltub (0x019da462), re-encode
const bs58check = await import("bs58check");
const decoded = bs58check.default.decode(xpub);
// Replace first 4 bytes with Ltub version: 0x019da462
decoded[0] = 0x01; decoded[1] = 0x9d; decoded[2] = 0xa4; decoded[3] = 0x62;
key = bs58check.default.encode(decoded);
}
const hd = new bitcoreLtc.HDPublicKey(key);
return hd.deriveChild(0).deriveChild(index).publicKey.toAddress().toString();
}
if (coin === "doge") {