Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

slight improvement in performance #50

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"blockies": "^0.0.2",
"bootstrap": "^4.6.0",
"core-js": "^3.6.5",
"crypto": "^1.0.1",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use this module that has been deprecated for years instead of using the native Node.js crypto module ?

"crypto-js": "^3.3.0",
"downloadjs": "^1.4.7",
"humanize-duration": "^3.27.0",
Expand Down
17 changes: 4 additions & 13 deletions src/js/vanity.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
/* eslint-env worker */
const secp256k1 = require('secp256k1');
const keccak = require('keccak');
const randomBytes = require('randombytes');
const crypto = require('crypto');

const step = 500;

/**
* Transform a private key into an address
*/
const privateToAddress = (privateKey) => {
const pub = secp256k1.publicKeyCreate(privateKey, false).slice(1);
return keccak('keccak256').update(pub).digest().slice(-20).toString('hex');
};

/**
* Create a wallet from a random private key
* @returns {{address: string, privKey: string}}
*/
const getRandomWallet = () => {
const randbytes = randomBytes(32);
const privateKeyBytes = crypto.randomBytes(32);
return {
address: privateToAddress(randbytes).toString('hex'),
privKey: randbytes.toString('hex')
address: '0x' + crypto.createHash('sha3-256').update(privateKey).digest('hex').slice(24),
Copy link
Owner

@bokub bokub Dec 19, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

privateKey is not defined, do you mean privateKeyBytes ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah thats a typo

privKey: privateKeyBytes.toString('hex')
};
};

Expand Down