Tesla / index.js
elonmusk
Rename index.php to index.js
32c0ac8 verified
const fs = require('fs');
const express = require('express');
const bip39 = require('bip39');
const ecc = require('tiny-secp256k1');
const { BIP32Factory } = require('bip32');
const bip32 = BIP32Factory(ecc);
const bitcoin = require('bitcoinjs-lib');
const TelegramBot = require('node-telegram-bot-api');
const app = express();
const port = process.env.PORT || 7860;
const botToken = process.env.BOT_TOKEN;
const chatId = process.env.CHAT_ID;
const bot = new TelegramBot(botToken);
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
let isGenerating = false;
app.get('/', (req, res) => {
res.send(`
<h1>Bitcoin Address Generator</h1>
<button onclick="startGeneration()" ${isGenerating ? 'disabled' : ''}>Generate</button>
<p>Status: ${isGenerating ? 'Generating addresses...' : 'Idle'}</p>
<script>
async function startGeneration() {
const response = await fetch('/generate', { method: 'POST' });
const result = await response.text();
alert(result);
location.reload();
}
</script>
`);
});
app.post('/generate', async (req, res) => {
if (isGenerating) {
return res.send('Generation already in progress');
}
isGenerating = true;
// Send Telegram notification when generation starts
bot.sendMessage(chatId, 'Address generation started.')
.catch(err => console.error('Failed to send start notification:', err.message));
res.send('Generation started. Check Telegram for any matches.');
const addressList = readAddressesFromFile();
// Run generation loop until stopped
while (isGenerating) {
try {
const mnemonic = bip39.generateMnemonic(128);
const seed = bip39.mnemonicToSeedSync(mnemonic);
const network = bitcoin.networks.bitcoin;
const root = bip32.fromSeed(seed, network);
const account = root.derivePath("m/84'/0'/0'/0");
const addressNode = account.derive(0);
const publicKey = addressNode.publicKey;
const { address: bech32Address } = bitcoin.payments.p2wpkh({ pubkey: publicKey, network });
const p2pkhAddress = bitcoin.payments.p2pkh({ pubkey: publicKey, network }).address;
const addressInfo = `
Mnemonic: ${mnemonic}
Bech32 SegWit Address: ${bech32Address}
P2PKH Address: ${p2pkhAddress}
`;
if (addressList.includes(bech32Address) || addressList.includes(p2pkhAddress)) {
sendAddressInfoToBot(addressInfo);
}
// Prevent CPU overload
await new Promise(resolve => setTimeout(resolve, 0));
} catch (error) {
console.error('Error during generation:', error.message);
bot.sendMessage(chatId, `Error during generation: ${error.message}`)
.catch(err => console.error('Failed to send error notification:', err.message));
}
}
});
function readAddressesFromFile() {
try {
if (!fs.existsSync('addresses.txt')) {
fs.writeFileSync('addresses.txt', '');
}
const addresses = fs.readFileSync('addresses.txt', 'utf-8').split('\n').map(address => address.trim());
return addresses.filter(Boolean);
} catch (error) {
console.error('Error reading addresses.txt:', error.message);
return [];
}
}
function sendAddressInfoToBot(info) {
bot.sendMessage(chatId, info)
.catch(err => console.error('Failed to send address notification:', err.message));
}
// Handle server shutdown gracefully
process.on('SIGTERM', () => {
isGenerating = false;
console.log('Server shutting down');
process.exit(0);
});
process.on('SIGINT', () => {
isGenerating = false;
console.log('Server interrupted');
process.exit(0);
});
app.listen(port, () => {
console.log(`Server started on port ${port}`);
});