Closed cancerts closed 5 years ago
please read the examples.
That usage is old and outdated.
please read the examples.
That usage is old and outdated.
how used ?
The above link is outdated and I assume the new one is [https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/ecpair.spec.ts]()
Example:
import { ECPair } from 'bitcoinjs-lib';
const keys = ECPair.fromPrivateKey(Buffer.from(my_hex_private_key, 'hex'));
If you want to sign a transaction, for instance, you can then:
tmpTx.pubkeys = [];
tmpTx.signatures = tmpTx.tosign.map(function (tosign, _n) {
tmpTx.pubkeys.push(keys.publicKey.toString('hex'));
return keys.sign(Buffer.from(tosign, 'hex')).toString('hex');
});
However, this results in a signature with the wrong length... any solutions?
The above link is outdated and I assume the new one is https://github.com/bitcoinjs/bitcoinjs-lib/blob/master/test/ecpair.spec.ts
Example:
import { ECPair } from 'bitcoinjs-lib'; const keys = ECPair.fromPrivateKey(Buffer.from(my_hex_private_key, 'hex'));
If you want to sign a transaction, for instance, you can then:
tmpTx.pubkeys = []; tmpTx.signatures = tmpTx.tosign.map(function (tosign, _n) { tmpTx.pubkeys.push(keys.publicKey.toString('hex')); return keys.sign(Buffer.from(tosign, 'hex')).toString('hex'); });
However, this results in a signature with the wrong length... any solutions?
Try this it worked for me, actually your methods create signature of length 128 chars while this is 140 chars-:
tmptx.pubkeys = [];
tmptx.signatures = tmptx.tosign.map(function (tosign, _n)
{
tmptx.pubkeys.push(keys.publicKey.toString('hex'));
let signature = keys.sign(Buffer.from(tosign, "hex"));
let encodedSignature = bitcoin.script.signature.encode(signature,bitcoin.Transaction.SIGHASH_ALL);
let hexStr = encodedSignature.toString("hex").slice(0, -2);
return hexStr;
});
var keys = new bitcoin.ECPair(bigi.fromHex(my_hex_private_key));