elonmusk commited on
Update index.js
Browse files
index.js
CHANGED
|
@@ -17,53 +17,71 @@ const bot = new TelegramBot(botToken);
|
|
| 17 |
app.use(express.json());
|
| 18 |
app.use(express.urlencoded({ extended: true }));
|
| 19 |
|
|
|
|
|
|
|
| 20 |
app.get('/', (req, res) => {
|
| 21 |
res.send(`
|
| 22 |
-
<
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
`);
|
| 28 |
});
|
| 29 |
|
| 30 |
-
app.post('/generate', (req, res) => {
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
return res.status(400).send('Invalid number of addresses');
|
| 34 |
}
|
| 35 |
|
|
|
|
|
|
|
| 36 |
// Send Telegram notification when generation starts
|
| 37 |
-
bot.sendMessage(chatId,
|
| 38 |
.catch(err => console.error('Failed to send start notification:', err.message));
|
| 39 |
|
|
|
|
|
|
|
| 40 |
const addressList = readAddressesFromFile();
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
}
|
| 63 |
}
|
| 64 |
-
|
| 65 |
-
// Send confirmation to webpage without address details
|
| 66 |
-
res.send(`Addresses generated. Check Telegram for any matches.<br><a href="/">Back</a>`);
|
| 67 |
});
|
| 68 |
|
| 69 |
function readAddressesFromFile() {
|
|
@@ -84,6 +102,19 @@ function sendAddressInfoToBot(info) {
|
|
| 84 |
.catch(err => console.error('Failed to send address notification:', err.message));
|
| 85 |
}
|
| 86 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
app.listen(port, () => {
|
| 88 |
console.log(`Server started on port ${port}`);
|
| 89 |
});
|
|
|
|
| 17 |
app.use(express.json());
|
| 18 |
app.use(express.urlencoded({ extended: true }));
|
| 19 |
|
| 20 |
+
let isGenerating = false;
|
| 21 |
+
|
| 22 |
app.get('/', (req, res) => {
|
| 23 |
res.send(`
|
| 24 |
+
<h1>Bitcoin Address Generator</h1>
|
| 25 |
+
<button onclick="startGeneration()" ${isGenerating ? 'disabled' : ''}>Generate</button>
|
| 26 |
+
<p>Status: ${isGenerating ? 'Generating addresses...' : 'Idle'}</p>
|
| 27 |
+
<script>
|
| 28 |
+
async function startGeneration() {
|
| 29 |
+
const response = await fetch('/generate', { method: 'POST' });
|
| 30 |
+
const result = await response.text();
|
| 31 |
+
alert(result);
|
| 32 |
+
location.reload();
|
| 33 |
+
}
|
| 34 |
+
</script>
|
| 35 |
`);
|
| 36 |
});
|
| 37 |
|
| 38 |
+
app.post('/generate', async (req, res) => {
|
| 39 |
+
if (isGenerating) {
|
| 40 |
+
return res.send('Generation already in progress');
|
|
|
|
| 41 |
}
|
| 42 |
|
| 43 |
+
isGenerating = true;
|
| 44 |
+
|
| 45 |
// Send Telegram notification when generation starts
|
| 46 |
+
bot.sendMessage(chatId, 'Address generation started.')
|
| 47 |
.catch(err => console.error('Failed to send start notification:', err.message));
|
| 48 |
|
| 49 |
+
res.send('Generation started. Check Telegram for any matches.');
|
| 50 |
+
|
| 51 |
const addressList = readAddressesFromFile();
|
| 52 |
|
| 53 |
+
// Run generation loop until stopped
|
| 54 |
+
while (isGenerating) {
|
| 55 |
+
try {
|
| 56 |
+
const mnemonic = bip39.generateMnemonic(128);
|
| 57 |
+
const seed = bip39.mnemonicToSeedSync(mnemonic);
|
| 58 |
+
const network = bitcoin.networks.bitcoin;
|
| 59 |
+
const root = bip32.fromSeed(seed, network);
|
| 60 |
+
const account = root.derivePath("m/84'/0'/0'/0");
|
| 61 |
+
const addressNode = account.derive(0);
|
| 62 |
+
const publicKey = addressNode.publicKey;
|
| 63 |
+
|
| 64 |
+
const { address: bech32Address } = bitcoin.payments.p2wpkh({ pubkey: publicKey, network });
|
| 65 |
+
const p2pkhAddress = bitcoin.payments.p2pkh({ pubkey: publicKey, network }).address;
|
| 66 |
+
|
| 67 |
+
const addressInfo = `
|
| 68 |
+
Mnemonic: ${mnemonic}
|
| 69 |
+
Bech32 SegWit Address: ${bech32Address}
|
| 70 |
+
P2PKH Address: ${p2pkhAddress}
|
| 71 |
+
`;
|
| 72 |
+
|
| 73 |
+
if (addressList.includes(bech32Address) || addressList.includes(p2pkhAddress)) {
|
| 74 |
+
sendAddressInfoToBot(addressInfo);
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
// Prevent CPU overload
|
| 78 |
+
await new Promise(resolve => setTimeout(resolve, 0));
|
| 79 |
+
} catch (error) {
|
| 80 |
+
console.error('Error during generation:', error.message);
|
| 81 |
+
bot.sendMessage(chatId, `Error during generation: ${error.message}`)
|
| 82 |
+
.catch(err => console.error('Failed to send error notification:', err.message));
|
| 83 |
}
|
| 84 |
}
|
|
|
|
|
|
|
|
|
|
| 85 |
});
|
| 86 |
|
| 87 |
function readAddressesFromFile() {
|
|
|
|
| 102 |
.catch(err => console.error('Failed to send address notification:', err.message));
|
| 103 |
}
|
| 104 |
|
| 105 |
+
// Handle server shutdown gracefully
|
| 106 |
+
process.on('SIGTERM', () => {
|
| 107 |
+
isGenerating = false;
|
| 108 |
+
console.log('Server shutting down');
|
| 109 |
+
process.exit(0);
|
| 110 |
+
});
|
| 111 |
+
|
| 112 |
+
process.on('SIGINT', () => {
|
| 113 |
+
isGenerating = false;
|
| 114 |
+
console.log('Server interrupted');
|
| 115 |
+
process.exit(0);
|
| 116 |
+
});
|
| 117 |
+
|
| 118 |
app.listen(port, () => {
|
| 119 |
console.log(`Server started on port ${port}`);
|
| 120 |
});
|