function isHex64(str) { return /^[0-9a-fA-F]{64}$/.test(str); } function isWif(str) { return /^[5KLc9RQ][1-9A-HJ-NP-Za-km-z]{50,}$/.test(str); // BTC/FLO WIF regex } async function recoverAllAddressesFromPrivKey(privKey) { const tronWeb = new TronWeb( "https://api.shasta.trongrid.io", "https://api.shasta.trongrid.io", "https://api.shasta.trongrid.io" ); try { let hexPrivateKey = privKey; let source = "Tron"; // Convert WIF to hex if needed if (isWif(privKey)) { const decoded = coinjs.wif2privkey(privKey); if (!decoded || !decoded["privkey"]) { return { error: "Invalid WIF private key" }; } hexPrivateKey = decoded["privkey"]; source = "BTC/FLO"; } else if (!isHex64(privKey)) { return { error: "Unsupported private key format. Please use Tron hex (64 characters) or BTC/FLO WIF format.", }; } // Generate TRON address const tronAddress = tronWeb.address.fromPrivateKey(hexPrivateKey); // Generate FLO address const floWallet = generateFLOFromPrivateKey(hexPrivateKey); // Generate BTC address const btcWallet = generateBTCFromPrivateKey(hexPrivateKey); return { source, hexPrivateKey, tronAddress, floWallet, btcWallet, }; } catch (err) { return { error: err.message }; } } async function runAddressRecovery() { const privKey = document.getElementById("recoveryPrivKey").value.trim(); const output = document.getElementById("recoveryOutput"); if (!privKey) { output.innerHTML = `
Your multi-blockchain addresses have been recovered. All addresses are derived from the same private key.
${recovered.tronAddress}
${recovered.hexPrivateKey}
${recovered.floWallet.address}
${recovered.floWallet.privateKey}
${recovered.btcWallet.address}
${recovered.btcWallet.privateKey}
Keep your private key safe and secure. Never share it with anyone. Consider backing it up in a secure location.