Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
263 lines (225 loc) Β· 9.43 KB
/
Copy pathindex.js
File metadata and controls
263 lines (225 loc) Β· 9.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
const { Keypair } = require('@solana/web3.js');
const bs58 = require('bs58');
const crypto = require('crypto');
const fs = require('fs');
const { Worker, isMainThread, parentPort, workerData } = require('worker_threads');
const os = require('os');
class FastVanityGenerator {
constructor(searchTerms, options = {}) {
// Support multiple search terms
this.searchTerms = Array.isArray(searchTerms)
? searchTerms.map(term => options.caseSensitive ? term : term.toLowerCase())
: [options.caseSensitive ? searchTerms : searchTerms.toLowerCase()];
this.caseSensitive = options.caseSensitive || false;
this.workers = options.workers || (options.maxSpeed ? os.cpus().length * 2 : os.cpus().length);
this.maxResults = options.maxResults || Infinity;
this.batchSize = options.batchSize || (options.maxSpeed ? 100000 : 50000);
this.outputFile = options.outputFile || `vanity-${Date.now()}.json`;
this.maxSpeed = options.maxSpeed || false;
this.results = [];
this.startTime = Date.now();
this.totalAttempts = 0;
this.rates = [];
this.initOutput();
}
initOutput() {
const data = {
searchTerms: this.searchTerms,
startTime: new Date().toISOString(),
results: [],
stats: { found: 0, attempts: 0, rate: 0 }
};
fs.writeFileSync(this.outputFile, JSON.stringify(data, null, 2));
console.log(`π Searching for: ${this.searchTerms.join(', ')}`);
console.log(`β‘ Workers: ${this.workers} | Batch: ${this.batchSize.toLocaleString()}`);
console.log(`π₯ Max speed mode: ${this.maxSpeed ? 'ON' : 'OFF'}`);
console.log('β'.repeat(60));
}
async start() {
return new Promise((resolve) => {
const workers = [];
let isRunning = true;
// Graceful shutdown
process.on('SIGINT', () => {
isRunning = false;
workers.forEach(w => w.terminate());
this.showFinalStats();
process.exit(0);
});
// Spawn workers
for (let i = 0; i < this.workers; i++) {
const worker = new Worker(__filename, {
workerData: {
searchTerms: this.searchTerms,
caseSensitive: this.caseSensitive,
batchSize: this.batchSize,
workerId: i,
maxSpeed: this.maxSpeed
}
});
worker.on('message', (msg) => {
if (!isRunning) return;
if (msg.found) {
this.handleResult(msg);
if (this.results.length >= this.maxResults) {
isRunning = false;
workers.forEach(w => w.terminate());
resolve(this.results);
}
} else {
this.totalAttempts += msg.attempts;
this.updateProgress();
}
});
workers.push(worker);
}
});
}
handleResult(result) {
const data = {
id: this.results.length + 1,
publicKey: result.publicKey,
privateKey: result.privateKey,
matchedTerm: result.matchedTerm,
quality: this.getQuality(result.publicKey),
timestamp: new Date().toISOString(),
attempts: this.totalAttempts
};
this.results.push(data);
this.updateFile(data);
console.log(`\nπ FOUND #${data.id}: ${result.publicKey}`);
console.log(`π Private: ${result.privateKey}`);
console.log(`π― Term: "${result.matchedTerm}" | Quality: ${data.quality}`);
}
getQuality(address) {
let score = 0;
const addr = this.caseSensitive ? address : address.toLowerCase();
for (const term of this.searchTerms) {
if (addr.includes(term)) {
score += 10;
if (addr.startsWith(term)) score += 20;
if (addr.endsWith(term)) score += 15;
const matches = (addr.match(new RegExp(term, 'g')) || []).length;
score += (matches - 1) * 5;
}
}
return score;
}
updateFile(newResult) {
try {
const data = JSON.parse(fs.readFileSync(this.outputFile, 'utf8'));
data.results.push(newResult);
data.stats = {
found: this.results.length,
attempts: this.totalAttempts,
rate: Math.round(this.totalAttempts / ((Date.now() - this.startTime) / 1000))
};
fs.writeFileSync(this.outputFile, JSON.stringify(data, null, 2));
} catch (e) {}
}
updateProgress() {
const elapsed = (Date.now() - this.startTime) / 1000;
const rate = Math.round(this.totalAttempts / elapsed);
this.rates.push(rate);
if (this.rates.length > 5) this.rates.shift();
const avgRate = Math.round(this.rates.reduce((a, b) => a + b) / this.rates.length);
const time = elapsed > 3600 ? `${Math.floor(elapsed/3600)}h${Math.floor((elapsed%3600)/60)}m`
: elapsed > 60 ? `${Math.floor(elapsed/60)}m${Math.floor(elapsed%60)}s`
: `${Math.floor(elapsed)}s`;
process.stdout.write(`\rβ‘ ${this.totalAttempts.toLocaleString()} attempts | ${avgRate.toLocaleString()}/s | Found: ${this.results.length} | ${time} `);
}
showFinalStats() {
const elapsed = (Date.now() - this.startTime) / 1000;
const avgRate = Math.round(this.totalAttempts / elapsed);
console.log('\nπ FINAL STATS');
console.log(`π Found: ${this.results.length} | Attempts: ${this.totalAttempts.toLocaleString()}`);
console.log(`β‘ Average rate: ${avgRate.toLocaleString()}/s | Time: ${Math.floor(elapsed)}s`);
console.log(`π Results: ${this.outputFile}`);
}
}
// Ultra-fast worker implementation
if (!isMainThread) {
const { searchTerms, caseSensitive, batchSize, workerId, maxSpeed } = workerData;
// Pre-allocate buffers for max speed
const seedBuffer = maxSpeed ? new Uint8Array(32) : null;
const fastGenerate = () => {
let seed;
if (maxSpeed && seedBuffer) {
crypto.getRandomValues(seedBuffer);
seed = seedBuffer;
} else {
seed = crypto.randomBytes(32);
}
const keypair = Keypair.fromSeed(seed);
const publicKey = keypair.publicKey.toBase58();
const checkAddr = caseSensitive ? publicKey : publicKey.toLowerCase();
// Check all search terms at once
for (const term of searchTerms) {
if (checkAddr.includes(term)) {
return {
found: true,
publicKey,
privateKey: bs58.encode(keypair.secretKey),
matchedTerm: term,
workerId
};
}
}
return null;
};
let attempts = 0;
const runBatch = () => {
for (let i = 0; i < batchSize; i++) {
attempts++;
const result = fastGenerate();
if (result) {
parentPort.postMessage(result);
attempts = 0;
}
}
parentPort.postMessage({ attempts, workerId });
attempts = 0;
setImmediate(runBatch);
};
runBatch();
}
// Main execution
if (isMainThread && require.main === module) {
const args = process.argv.slice(2);
if (!args.length) {
console.log('π― Fast Solana Vanity Generator');
console.log('Usage: node vanity.js <word1> [word2] [word3] [options]');
console.log('\nOptions:');
console.log(' --case Case sensitive');
console.log(' --max-speed Maximum performance mode');
console.log(' --workers=N Number of workers');
console.log(' --batch=N Batch size');
console.log(' --limit=N Stop after N results');
console.log(' --output=file Output filename');
console.log('\nExamples:');
console.log(' node vanity.js moon');
console.log(' node vanity.js moon doge pump --max-speed');
console.log(' node vanity.js Moon --case --limit=5');
process.exit(1);
}
const searchTerms = [];
const options = {};
for (const arg of args) {
if (arg.startsWith('--')) {
const [key, value] = arg.slice(2).split('=');
switch (key) {
case 'case': options.caseSensitive = true; break;
case 'max-speed': options.maxSpeed = true; break;
case 'workers': options.workers = parseInt(value); break;
case 'batch': options.batchSize = parseInt(value); break;
case 'limit': options.maxResults = parseInt(value); break;
case 'output': options.outputFile = value; break;
}
} else {
searchTerms.push(arg);
}
}
const generator = new FastVanityGenerator(searchTerms, options);
generator.start().catch(console.error);
}
module.exports = FastVanityGenerator;