fix: convert zpub to xpub version bytes — bitcore-lib-ltc only understands standard xpub
This commit is contained in:
parent
2bd6adc090
commit
8b2dcf0d56
|
|
@ -85,11 +85,11 @@ export function deriveAddressSafe(coin: string, index: number): string {
|
|||
if (coin === "ltc") {
|
||||
// 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 decoded = bs58check.decode(xpub);
|
||||
// Replace first 4 bytes with Ltub version: 0x019da462
|
||||
decoded[0] = 0x01; decoded[1] = 0x9d; decoded[2] = 0xa4; decoded[3] = 0x62;
|
||||
if (xpub.startsWith("zpub") || xpub.startsWith("Zpub") || xpub.startsWith("Ltub") || xpub.startsWith("Mtub")) {
|
||||
// bitcore-lib-ltc only understands standard xpub version bytes (0x0488b21e).
|
||||
// Convert zpub/Ltub/Mtub → xpub by swapping the 4-byte version prefix.
|
||||
const decoded = Buffer.from(bs58check.decode(xpub));
|
||||
decoded[0] = 0x04; decoded[1] = 0x88; decoded[2] = 0xb2; decoded[3] = 0x1e;
|
||||
key = bs58check.encode(decoded);
|
||||
}
|
||||
const hd = new bitcoreLtc.HDPublicKey(key);
|
||||
|
|
|
|||
Loading…
Reference in New Issue