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

Ethereal Ethereal 提出于 2021-04-28 20:32 5932 浏览

我调用直接调用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

Tiny熊

擅长:智能合约,以太坊 · 采纳率 33% · 回答于 2021-04-28 20:48

其它 0 个回答

写回答

你需要登录后才可以回答问题,登录