17

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

 3 years ago
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.
neoserver,ios ssh client

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)

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

Tiny熊 - 布道者
擅长:智能合约,以太坊 | 采纳率 40% | 回答于 1天前

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK