UNPKG

eth-crypto

Version:

Cryptographic functions for ethereum and how to use them with web3 and solidity

20 lines (18 loc) 472 B
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); const publicKeyBuffer = privateToPublic(toBuffer(privateKey)); return publicKeyBuffer.toString('hex'); }