Bitcoinjs-lib: How to get uncompressed address from public key?

Created on 31 May 2020  路  3Comments  路  Source: bitcoinjs/bitcoinjs-lib

Hello,

I'm using the below method. May i know how to get an uncompressed address?

const { address } = bitcoin.payments.p2pkh({ pubkey: new Buffer(pubKey, 'hex') });
console.log(address);

Thanks.

Most helpful comment

const uncompressedHex = bitcoin.ECPair.fromPublicKey(
  Buffer.from(pubKey, 'hex'),
  { compressed: false },
).publicKey.toString('hex')

in this case pubKey can be compressed or uncompressed. the ECPair will force it to uncompressed when you pass compressed: false as an option.

All 3 comments

use an uncompressed "pubKey" (130 length instead of 66 length.)

Edit: i figured it :)

@junderw thank you very much. how to convert compressed public key to uncompressed one?

const uncompressedHex = bitcoin.ECPair.fromPublicKey(
  Buffer.from(pubKey, 'hex'),
  { compressed: false },
).publicKey.toString('hex')

in this case pubKey can be compressed or uncompressed. the ECPair will force it to uncompressed when you pass compressed: false as an option.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

stefanhuber picture stefanhuber  路  4Comments

dcousens picture dcousens  路  3Comments

Beardcoding picture Beardcoding  路  3Comments

coingeek picture coingeek  路  4Comments

LeonYanghaha picture LeonYanghaha  路  3Comments