LoginSignup
4
3

More than 5 years have passed since last update.

Ethereum の秘密鍵から公開鍵を取得 (JavaScript)

Last updated at Posted at 2018-05-02

JavaScript で Ethereum の秘密鍵から公開鍵を取得する方法のメモです。
さまざまな方法がありますが、今回は比較的簡単なライブラリを使用した方法を共有します。

今回使用するライブラリ

ライブラリのインストール

$ 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 を更新します。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3