//加密库 var Crypto = require('crypto') //椭圆曲线库 var secp256k1 = require('secp256k1') //哈希库 var createKeccakHash = require('keccak')
//一个32字节的随机数(1~2^256--1),直接把它当成私钥 var privateKey = Crypto.randomBytes(32)
//由secp256kl椭圆曲线算法先计算出公钥 var pubKey = secp256k1.publicKeyCreate(privateKey,false).slice(1);
//进行keccak256hash运算再取后40位得到 var address = createKeccakHash('keccak256').update(pubKey).digest().slice(-20);
console.log(privateKey.toString('hex')); console.log("0x" + address.toString('hex'));