今回使用するライブラリ
ライブラリのインストール
$ npm install ethereumjs-wallet --save $ npm install ethereumjs-util --save
公開鍵から秘密鍵を取得するコード
var Wallet = require('ethereumjs-wallet'); var EthUtil = require('ethereumjs-util'); // 秘密鍵を使用して、wallet インスタンスを取得 const privateKeyBuffer = EthUtil.toBuffer('0x61ce8b95ca5fd6f55cd97ac60817777bdf64f1670e903758ce53efc32c3dffeb'); const wallet = Wallet.fromPrivateKey(privateKeyBuffer); // ウォレットの公開鍵を取得 const publicKey = wallet.getPublicKeyString(); console.log(publicKey);
Note
- Ethereum 関連の情報は https://scrapbox.io/sushiether/ に集約することにしました。
- この記事の内容に変更・更新がある場合は、以下の URL を更新します。
- Ethereum の秘密鍵から公開鍵を取得 (JavaScript))