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?

  • You’re using javascript, but are concerned about storing tens of bytes? – Anonymous Feb 8 '19 at 21:23
  • 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 パトシ Feb 8 '19 at 21:48
  • 2
    be careful sending private keys over the air. – JBaczuk Feb 8 '19 at 21:53

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'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.