-
Notifications
You must be signed in to change notification settings - Fork 0
/
vanity-eth-address.js
84 lines (68 loc) · 1.5 KB
/
vanity-eth-address.js
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
// referenced to https://github.com/bokub/vanity-eth
const secp256k1 = require('secp256k1');
const keccak = require('keccak');
const randomBytes = require('randombytes');
const privateToAddress = (privateKey) => {
const pub = secp256k1.publicKeyCreate(privateKey, false).slice(1);
return keccak('keccak256').update(pub).digest().slice(-20).toString('hex');
};
const getRandomAddress = () => {
const randbytes = randomBytes(32);
const private = privateToAddress(randbytes).toString('hex');
const public = randbytes.toString('hex');
return { private, public };
};
const getVanityAddress = (prefixs, suffixs) => {
let x = 0;
const p = new Set(prefixs);
const s = new Set(suffixs);
const TargetIteration = 5600000;
while (true) {
x++;
if (x % 200000 === 0) {
console.log(`${x / 1000}k address checked [${parseInt(x * 100 / TargetIteration)}%]`);
}
const {
public: address,
private: key,
} = getRandomAddress();
const prefix = address.slice(0, 4);
const suffix = address.slice(address.length - 4);
if (p.has(prefix) && s.has(suffix)) {
console.log({ address, key });
}
}
};
const prefixs = [
'0000',
'1111',
'2222',
'3333',
'5555',
'6666',
'7777',
'8888',
'9999',
'aaaa',
'bbbb',
'cccc',
'dddd',
'eeee',
'ffff',
'1234',
'2345',
'3456',
'4567',
'5678',
'6789',
'9876',
'8765',
'7654',
'6543',
'5432',
'4321',
'shun',
'haha',
];
const suffixs = prefixs;
getVanityAddress(prefixs, suffixs);