Find vanity addresses with suffixes

This commit is contained in:
Boris Kubiak 2018-10-06 17:41:52 +02:00
parent e664d580fe
commit 19ab920b7b

View file

@ -30,20 +30,29 @@ const getRandomWallet = () => {
* @param address * @param address
* @param input * @param input
* @param isChecksum * @param isChecksum
* @param isSuffix
* @returns {boolean} * @returns {boolean}
*/ */
const isValidVanityAddress = (address, input, isChecksum) => { const isValidVanityAddress = (address, input, isChecksum, isSuffix) => {
const subStr = isSuffix ? address.substr(40 - input.length) : address.substr(0, input.length);
if (!isChecksum) { if (!isChecksum) {
return input === address.substr(0, input.length); return input === subStr;
} }
if (input.toLowerCase() !== address.substr(0, input.length)) { if (input.toLowerCase() !== subStr) {
return false; return false;
} }
return isValidChecksum(address, input, isSuffix);
};
const isValidChecksum = (address, input, isSuffix) => {
const hash = keccak('keccak256').update(address).digest().toString('hex'); const hash = keccak('keccak256').update(address).digest().toString('hex');
const shift = isSuffix ? 40 - input.length : 0;
for (let i = 0; i < input.length; i++) { for (let i = 0; i < input.length; i++) {
if (input[i] !== (parseInt(hash[i], 16) >= 8 ? address[i].toUpperCase() : address[i])) { const j = i + shift;
if (input[i] !== (parseInt(hash[j], 16) >= 8 ? address[j].toUpperCase() : address[j])) {
return false; return false;
} }
} }
@ -72,7 +81,7 @@ const getVanityWallet = (input, isChecksum, isSuffix, cb) => {
let wallet = getRandomWallet(); let wallet = getRandomWallet();
let attempts = 1; let attempts = 1;
while (!isValidVanityAddress(wallet.address, input, isChecksum)) { while (!isValidVanityAddress(wallet.address, input, isChecksum, isSuffix)) {
if (attempts >= step) { if (attempts >= step) {
cb({attempts}); cb({attempts});
attempts = 0; attempts = 0;
@ -88,7 +97,7 @@ onmessage = function (event) {
try { try {
getVanityWallet(input.hex, input.checksum, input.suffix, (message) => postMessage(message)); getVanityWallet(input.hex, input.checksum, input.suffix, (message) => postMessage(message));
} catch (err) { } catch (err) {
self.postMessage({error: err.toString()}); self.postMessage({error: err.toString()}, '*');
} }
}; };