Created
April 10, 2018 20:34
-
-
Save tgoldenberg/47e954b94e768e58c25718c018b5cc2b to your computer and use it in GitHub Desktop.
ECC Addresses
This file contains 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 secureRandom = require('secure-random'); | |
const ec = require('elliptic').ec; | |
const ecdsa = new ec('secp256k1'); | |
function generateAddress() { | |
const max = Buffer.from("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364140", 'hex'); | |
let isInvalid = true; | |
let privateKey; | |
while (isInvalid) { | |
privateKey = secureRandom.randomBuffer(32); | |
if (Buffer.compare(max, privateKey) === 1) { | |
isInvalid = false; | |
} | |
} | |
console.log('> Private key: ', privateKey.toString('hex')); | |
const keys = ecdsa.keyFromPrivate(privateKey); | |
const publicKey = keys.getPublic('hex'); | |
console.log('> Public key: ', publicKey); | |
return { | |
privateKey: privateKey.toString('hex'), | |
publicKey, | |
}; | |
} | |
generateAddress(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment