Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compressed public key #155

Closed
AshleyDDD opened this issue Apr 24, 2014 · 3 comments
Closed

Compressed public key #155

AshleyDDD opened this issue Apr 24, 2014 · 3 comments

Comments

@AshleyDDD
Copy link

right now, the output of this file only gives out uncompressed 65 bytes (correct me if I am wrong). How would I output the uncompressed key to compressed key?

@dcousens
Copy link
Contributor

What file are you referring to?

If you have an ECPubKey that is uncompressed, call it pub, and you want the compressed form, just take a copy of it and add the compressed flag: new ECPubKey(pub.Q, true).
Then you would just use toBuffer() like you normally would.

Full example:

// Generate a random private key (with an uncompressed public key when serialized)
var priv = ECKey.makeRandom(false)

var cpub = new ECPubKey(priv.pub.Q, true)
console.log(cpub.toHex())

@AshleyDDD
Copy link
Author

Ah sorry for that. I am talking to bitcoinjs-min file but I will give what you wrote a try.

@dcousens
Copy link
Contributor

I think it is important to distinguish that ECKey and ECPubKey are Bitcoin level abstractions, not ecdsa.
Therefore if you want to work with the raw public key like this then you should probably do it directly (this API will change in the future, but still):

var priv = ECKey.makeRandom()
var Q = priv.pub

// Print an encoded public key (compressed, uncompressed respectively)
console.log(Q.getEncoded(true))
console.log(Q.getEncoded(false))

edit: Q.getEncoded returns a byte array for now, it'll be a buffer soon enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants