web3js里有直接从私钥获取公钥的接口吗 是这个web3.shh.getPublicKey吗,我调用直接报错没有这类方法

我调用直接调用web3.shh.xxx会报错没有这类方法 web3.shh.addPrivateKey('0x8bda3abeb454847b515fa9b404cede50b1cc63cfdeddd4999d074284b4c21e15').then(console.log); Error: the method shh_addPrivateKey does not exist/is not available at web3.js:3143:20 at web3.js:6347:15 at web3.js:5081:36 at <anonymous>:1:1

请先 登录 后评论

最佳答案 2021-04-28 23:02

可以用: https://github.com/ethereumjs/ethereumjs-util

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

或者 用 secp256k1:

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

或者使用 https://github.com/ethereumjs/ethereumjs-wallet

请先 登录 后评论

其它 0 个回答