Hi Guys
I need to extract the public key for multisig address generation
How to do it within this library? or do you know other libraries which can extract the public key from private key?
Were these examples as found in README helpful?
Basically, <keyPair>.getPublicKeyBuffer() should give the compressed public key buffer. Check this (rather useless otherwise) code for for a complete example https://gist.github.com/mixdev/0b3862ccd198a9598ebffe00befa3b1d @
@mixdev thanks!
I hope you don't mind, but I've copied the contents of your gist below:
/*
How to recreate a Bitcoin wallet address from a public key
Ref: https://github.com/bitcoinjs/bitcoinjs-lib/issues/590
*/
var bitcoin = require('bitcoinjs-lib')
var assert = require('assert')
var bigi = require('bigi')
var crypto = require('crypto')
/* New hash */
var hash = bitcoin.crypto.sha256('correct horse battery staple')
var d = bigi.fromBuffer(hash)
/* Create a new Eleptic Curve key pair from hash */
var keyPair = new bitcoin.ECPair(d)
/* Extract public key buffer(compressed) */
var publicKeyBuffer = keyPair.getPublicKeyBuffer()
/* Copy the (compressed) pub key from the ECPair we have created above */
var publicKey = bitcoin.ECPair.fromPublicKeyBuffer(publicKeyBuffer)
/* Create a new keypair from the copied public key */
var newKeyPair = new bitcoin.ECPair(null, publicKey.Q, { compressed: true })
/* The old address */
console.log(keyPair.getAddress())
/* should be same as the new address */
console.log(newKeyPair.getAddress())
This and the multi-sig example should be more than enough to do what @askucher asked.
Most helpful comment
@mixdev thanks!
I hope you don't mind, but I've copied the contents of your gist below:
This and the multi-sig example should be more than enough to do what @askucher asked.