web3js里有直接从私钥获取公钥的接口吗 是这个web3.shh.getPublicKey吗,我调用直接报...
source link: https://learnblockchain.cn/question/1981
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
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 :1:1
最佳答案 1天前
可以用: 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)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK