最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to get bitcoin address from a public key with bitcoinjs - Stack Overflow

programmeradmin1浏览0评论

Found an article explaining how to generate bitcoin address from a public key:

But wondering if this procedure is already implemented in bitcoinjs or any other JS library. So I don't need to perform all the 8 steps from the guide manually

Found an article explaining how to generate bitcoin address from a public key: https://en.bitcoin.it/wiki/Technical_background_of_version_1_Bitcoin_addresses

But wondering if this procedure is already implemented in bitcoinjs or any other JS library. So I don't need to perform all the 8 steps from the guide manually

Share Improve this question asked Mar 13, 2019 at 17:00 Dmitry TaipovDmitry Taipov 471 silver badge8 bronze badges 4
  • Bitcoin address is just a SHA256 hash of the public key, any library that has a SHA256 function will get you an address from a public key. – Adam Jenkins Commented Mar 13, 2019 at 17:23
  • @Adam It's a bit more than that, it's a SHA256 hash, which is then RIPEMD160 hashed and then encoded in Base58 with a checksum (which es from a double SHA256 of the RIPEMD160 hash). – Paul Commented Mar 13, 2019 at 17:29
  • @Adam but this guide I mentioned states that there are whole 8 steps to get the address. That's why I'm asking. Will try to do just SHA256. Thank you! – Dmitry Taipov Commented Mar 13, 2019 at 17:31
  • @DmitryTaipov - listen to paulpro, my memory was wrong. – Adam Jenkins Commented Mar 13, 2019 at 17:47
Add a ment  | 

1 Answer 1

Reset to default 7

Yes, that library can do it.

const bitcoinjs = require( 'bitcoinjs-lib' );

const pubkey = Buffer.from( '0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352', 'hex' );
const { address } = bitcoinjs.payments.p2pkh({ pubkey });
console.log( address ); // 1PMycacnJaSqwwJqjawXBErnLsZ7RkXUAs
发布评论

评论列表(0)

  1. 暂无评论