Using only Javascript and JS related Bitcoin Libraries. How do you extract the Bitcoin Address from a private key?

0

I'm building an js related application that only stores my user's bitcoin private keys, but not the public key or bitcoin address to save space.

Is there a javascript library that can output the bitcoin address by only providing the bitcoin private key as an input?

Patoshi パトシ

Posted 2019-02-08T20:52:10.167

Reputation: 8 911

You’re using javascript, but are concerned about storing tens of bytes?Anonymous 2019-02-08T21:23:51.147

I need it to be as compact as possible due to storage constraint. If i can derive the bitcoin address from the private key, great. I'm using very low bandwidth communications, every byte saved is time saved.Patoshi パトシ 2019-02-08T21:48:07.070

2be careful sending private keys over the air.JBaczuk 2019-02-08T21:53:30.883

Answers

0

Try bitcoinjs-lib

The following will generate a P2SH(P2WPKH) address

const bitcoin = require('bitcoinjs-lib')

let ecpair = bitcoin.ECPair.fromWIF('L34XqVbrw1VSHsiavdpm4QGTRrFyH7RKAp7SFYf36gYcyLX2ieWi')
let address = bitcoin.payments.p2sh({redeem: bitcoin.payments.p2wpkh({ pubkey: ecpair.publicKey })}).address

> '3F1JMjuxgNFuK4kBxv4JXMEdQ2yvjuz939'

JBaczuk

Posted 2019-02-08T20:52:10.167

Reputation: 6 172