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.trongrid.io", "https://api.trongrid.io", "https://api.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 = `
Enter a private key
`; if (typeof notify === "function") notify("Enter a private key", "error"); return; } // Set loading state if (typeof setButtonLoading === "function") { setButtonLoading("recoverBtn", true); } // Show notification if (typeof notify === "function") { notify("Recovering address...", "success", 1500); } const recovered = await recoverAllAddressesFromPrivKey(privKey); if (recovered.error) { output.innerHTML = `
${recovered.error}
`; if (typeof notify === "function") notify(recovered.error, "error"); } else { output.innerHTML = `

Addresses Recovered Successfully!

Your multi-blockchain addresses have been recovered. All addresses are derived from the same private key.

TRON (TRX)

Primary
${recovered.tronAddress}
${recovered.hexPrivateKey}
${ recovered.floWallet ? `

FLO

Secondary
${recovered.floWallet.address}
${recovered.floWallet.privateKey}
` : "" } ${ recovered.btcWallet ? `

Bitcoin (BTC)

Secondary
${recovered.btcWallet.address}
${recovered.btcWallet.privateKey}
` : "" }

Security Reminder

Keep your private key safe and secure. Never share it with anyone. Consider backing it up in a secure location.

`; if (typeof notify === "function") notify("All addresses recovered", "success"); } // Clear loading state if (typeof setButtonLoading === "function") { setButtonLoading("recoverBtn", false); } }