tronwallet/scripts/genMultichainAddress.js
void-57 ef65ac5886 feat: Add multi-chain wallet generation and address recovery
- Implemented `genMultichainAddress.js` for generating addresses for FLO, BTC, and TRON from private keys.
- Created `recoverAddress.js` to recover addresses from a given private key, supporting multiple blockchains.
- Added `sendTRX.js` for sending TRX transactions, including WIF to hex conversion and transaction details display.
- Developed `transactionHistory.js` to fetch and display transaction history for TRON addresses with pagination and filtering options.
2025-08-29 08:38:21 +05:30

79 lines
2.1 KiB
JavaScript

function getRandomPrivateKey() {
const array = new Uint8Array(32);
window.crypto.getRandomValues(array);
return Array.from(array)
.map((b) => b.toString(16).padStart(2, "0"))
.join("");
}
function generateFLOFromPrivateKey(privateKey) {
try {
let flowif = privateKey;
if (/^[0-9a-fA-F]{64}$/.test(privateKey)) {
flowif = coinjs.privkey2wif(privateKey);
}
let floprivateKey = btcOperator.convert.wif(flowif, bitjs.priv);
let floAddress = floCrypto.getFloID(floprivateKey);
if (!floAddress) {
throw new Error("No working FLO address generation method found");
}
return {
address: floAddress,
privateKey: floprivateKey, // Returns the format that actually works
};
} catch (error) {
console.warn("FLO generation not available:", error.message);
return null;
}
}
function generateBTCFromPrivateKey(privateKey) {
try {
if (typeof btcOperator === "undefined") {
throw new Error("btcOperator library not available");
}
// Convert private key to WIF format if it's hex
let wifKey = privateKey;
if (/^[0-9a-fA-F]{64}$/.test(privateKey)) {
wifKey = coinjs.privkey2wif(privateKey);
}
let btcPrivateKey = btcOperator.convert.wif(wifKey);
let btcAddress;
btcAddress = btcOperator.bech32Address(wifKey);
return {
address: btcAddress,
privateKey: btcPrivateKey,
};
} catch (error) {
console.warn("BTC generation error:", error.message);
return null;
}
}
async function generateTronWallet() {
const fullNode = "https://api.shasta.trongrid.io";
const solidityNode = "https://api.shasta.trongrid.io";
const eventServer = "https://api.shasta.trongrid.io";
const tronWeb = new TronWeb(
fullNode,
solidityNode,
eventServer,
getRandomPrivateKey()
);
const wallet = await tronWeb.createAccount();
return {
address: wallet.address.base58,
privateKey: wallet.privateKey,
};
}
window.generateTronWallet = generateTronWallet;
window.generateBTCFromPrivateKey = generateBTCFromPrivateKey;
window.generateFLOFromPrivateKey = generateFLOFromPrivateKey;
window.getRandomPrivateKey = getRandomPrivateKey;