Created
December 13, 2024 11:28
-
-
Save alsma/c1fe290337c921f778de95e5b6a7c0fd to your computer and use it in GitHub Desktop.
Mass Ethereum keystore decoder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const { fork } = require('child_process'); | |
const os = require('os'); | |
console.log(os.cpus().length); | |
const NUM_WORKERS = os.cpus().length; | |
const KEYSTORE_DIR = './keystores'; // Replace with your directory path | |
const RESULT_DIR = './results'; // Directory for storing results | |
// Ensure results directory exists | |
if (!fs.existsSync(RESULT_DIR)) { | |
fs.mkdirSync(RESULT_DIR); | |
} | |
// Scan the directory for keystore files | |
const keystoreFiles = fs | |
.readdirSync(KEYSTORE_DIR) | |
.filter((file) => file.includes('UTC')) | |
.map((file) => path.join(KEYSTORE_DIR, file)); | |
let taskQueue = [...keystoreFiles]; | |
const workers = []; | |
// Create workers and distribute tasks | |
for (let i = 0; i < NUM_WORKERS; i++) { | |
const worker = fork(path.join(__dirname, 'worker.js')); | |
workers.push(worker); | |
worker.on('message', (msg) => { | |
if (!msg.done) { | |
console.log(`Worker ${i + 1} completed task: ${msg.file} error: ${msg.error}`); | |
} else { | |
// Write result to the worker's result file | |
const resultFile = path.join(RESULT_DIR, `worker_${i + 1}.csv`); | |
fs.appendFileSync(resultFile, `${msg.result}\n`); | |
} | |
if (taskQueue.length % 100 == 0) { | |
console.log(`[${Date()}] Tasks left: ${taskQueue.length}`); | |
} | |
// Assign the next task if available | |
if (taskQueue.length > 0) { | |
const nextFile = taskQueue.shift(); | |
worker.send({ file: nextFile }); | |
} else { | |
worker.send({ terminate: true }); | |
} | |
}); | |
// Start initial tasks | |
if (taskQueue.length > 0) { | |
const nextFile = taskQueue.shift(); | |
worker.send({ file: nextFile }); | |
} else { | |
worker.send({ terminate: true }); | |
} | |
} | |
// Handle worker exit events | |
workers.forEach((worker, index) => { | |
worker.on('exit', () => { | |
console.log(`Worker ${index + 1} exited.`); | |
if (workers.every((w) => w.killed)) { | |
console.log('All tasks completed.'); | |
} | |
}); | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fs = require('fs'); | |
const path = require('path'); | |
const web3 = require('web3'); | |
var Accounts = require('web3-eth-accounts'); | |
const pwd = 123123123; | |
process.on('message', (msg) => { | |
if (msg.terminate) { | |
process.exit(0); | |
} | |
if (msg.file) { | |
Accounts.decrypt(fs.readFileSync(msg.file, 'utf8'), pwd) | |
.then(({ address, privateKey }) => { | |
process.send({ done: true, file: msg.file, result: `${address},${privateKey}` }); | |
}) | |
.catch(e => { | |
process.send({ done: false, file: msg.file, error: e.message }); | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment