fix: convert zpub to Ltub before LTC HD derivation
This commit is contained in:
+11
-1
@@ -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") {
|
||||
|
||||
Reference in New Issue
Block a user