eth-crypto
Version:
Cryptographic functions for ethereum and how to use them with web3 and solidity
14 lines (13 loc) • 451 B
JavaScript
import { privateToPublic, toBuffer } from 'ethereumjs-util';
import { addLeading0x } from './util';
/**
* Generate publicKey from the privateKey.
* This creates the uncompressed publicKey,
* where 04 has stripped from left
* @returns {string}
*/
export function publicKeyByPrivateKey(privateKey) {
privateKey = addLeading0x(privateKey);
var publicKeyBuffer = privateToPublic(toBuffer(privateKey));
return publicKeyBuffer.toString('hex');
}