UNPKG

ethereum-private-key-to-public-key

Version:
17 lines (12 loc) 482 B
const { publicKeyCreate } = require('secp256k1') function privateKeyToPublicKey (privateKey) { if (!Buffer.isBuffer(privateKey)) { if (typeof privateKey !== 'string') { throw new Error('Expected Buffer or string as argument') } privateKey = privateKey.slice(0, 2) === '0x' ? privateKey.slice(2) : privateKey privateKey = Buffer.from(privateKey, 'hex') } return Buffer.from(publicKeyCreate(privateKey, false)) } module.exports = privateKeyToPublicKey