current position:Home>Is there an interface in web3js to obtain the public key directly from the private key? It's Web3 shh. Getpublickey? I call direct error reporting. There is no such method

Is there an interface in web3js to obtain the public key directly from the private key? It's Web3 shh. Getpublickey? I call direct error reporting. There is no such method

2022-02-04 00:23:42 Q & A of Denglian community

I call directly web3.shh.xxx There is no such method web3.shh.addPrivateKey('0x8bda3abeb454847b515fa9b404cede50b1cc63cfdeddd4999d074284b4c21e15').then(console.log);Error: the method shh_addPrivateKey does not exist/is not availableat web3.js:3143:20at web3.js:6347:15at web3.js:5081:36at <anonymous>:1:1




Take the answer 1:

It can be used : https://github.com/ethereumjs/ethereumjs-util

> const util = require('ethereumjs-util')> util.privateToPublic(privateKey)

perhaps use secp256k1:

> const secp256k1 = require('secp256k1')> secp256k1.publicKeyCreate(privateKey, false).slice(1)

Or use https://github.com/ethereumjs/ethereumjs-wallet




copyright notice
author[Q & A of Denglian community],Please bring the original link to reprint, thank you.
https://en.netfreeman.com/2022/02/202202040023408193.html

Random recommended