How do you sign data with a private key? [javascript]

by timothyylim   Last Updated January 11, 2019 09:27 AM - source

Using BlockCypher’s signing tool (link), I can sign the following data:


with the private key:


to get the result:


However, I'm am not able to replicate this using javascript using the bitcoinjs-lib module. My attempt is shown below:

var bitcoin = require('bitcoinjs-lib')
var wif = require('wif')

var dataToSign = '05de69f5d37f41340eed3230f03d2394dde5e497738a76f027b7d962a0cbdf39'

var wifObj = wif.decode('KxpiD4T1QHFahGVyg9onfLXjbwBSf5Dyh3BPYY899uXQHn6gfnbz')
var keys = bitcoin.ECPair.fromPrivateKey(wifObj.privateKey)

var signed = keys.sign(Buffer.from(dataToSign, 'hex'))
var signedHex = signed.toString('hex')

Related Questions

How do you sign transactions from a HD wallet?

Updated January 08, 2019 10:27 AM