fix: use static bs58check import, not dynamic await import
This commit is contained in:
parent
91c24b20f7
commit
2bd6adc090
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
// @ts-ignore — bitcore libs don't have perfect types
|
// @ts-ignore — bitcore libs don't have perfect types
|
||||||
import bitcore from "bitcore-lib";
|
import bitcore from "bitcore-lib";
|
||||||
|
import bs58check from "bs58check";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import bitcoreCash from "bitcore-lib-cash";
|
import bitcoreCash from "bitcore-lib-cash";
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
|
|
@ -86,11 +87,10 @@ export function deriveAddressSafe(coin: string, index: number): string {
|
||||||
let key = xpub;
|
let key = xpub;
|
||||||
if (xpub.startsWith("zpub") || xpub.startsWith("Zpub")) {
|
if (xpub.startsWith("zpub") || xpub.startsWith("Zpub")) {
|
||||||
// Decode base58check, swap version bytes to Ltub (0x019da462), re-encode
|
// Decode base58check, swap version bytes to Ltub (0x019da462), re-encode
|
||||||
const bs58check = await import("bs58check");
|
const decoded = bs58check.decode(xpub);
|
||||||
const decoded = bs58check.default.decode(xpub);
|
|
||||||
// Replace first 4 bytes with Ltub version: 0x019da462
|
// Replace first 4 bytes with Ltub version: 0x019da462
|
||||||
decoded[0] = 0x01; decoded[1] = 0x9d; decoded[2] = 0xa4; decoded[3] = 0x62;
|
decoded[0] = 0x01; decoded[1] = 0x9d; decoded[2] = 0xa4; decoded[3] = 0x62;
|
||||||
key = bs58check.default.encode(decoded);
|
key = bs58check.encode(decoded);
|
||||||
}
|
}
|
||||||
const hd = new bitcoreLtc.HDPublicKey(key);
|
const hd = new bitcoreLtc.HDPublicKey(key);
|
||||||
return hd.deriveChild(0).deriveChild(index).publicKey.toAddress().toString();
|
return hd.deriveChild(0).deriveChild(index).publicKey.toAddress().toString();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue