I’ve been making an attempt to signal my transactions with a digital signature for the previous few days however appears that libraries in bitcoin, so far as to my data don’t present a easy technique to signal the transactions with digital signatures. I’ve been making an attempt to make use of bitcoinjs-lib to attain my end result.

Bitcoinjs-lib got here out with a brand new approach of signing transactions with the category Psbt (partially signed bitcoin transaction) and I’ve been making an attempt to serialize the unsigned transaction after which create a signature with the unsigned transaction after which lastly signal the transaction with the signature.

These are the steps that I’ve adopted, can somebody please information me as to the place I could be going mistaken and what to do subsequent?

I’ve created a brand new handle say: bc1qjkg99q654997uz5lxanjugzz2hfwum7ph9fcvw, with the compressed public key as 039b219ff489f9f5d3c674602e2280cc803f068f07db7295c7d2a2f9d51844cc45 (in hexadecimal illustration).

Script used is P2WPKH.

Say I wish to switch funds to 3HmEiQfaghizrNNn3tt5ydzvejLeYMzbD1, with some quantity of BTC.
Now I wish to create an unsigned transaction in order that I can generate a digital signature after which signal the transaction.

That is how I proceeded:

First I created a fee object like so:

perform createPayment(kind, keys) {
        const community = bitcoin.networks.bitcoin;
        const fee = (bitcoin.funds)[type]({
                pubkey: keys[0].publicKey,
                community,
        });
        return {
                fee,
                keys,
        };
}
.
.
.
keys = [{ publicKey: Buffer.from('039b219ff489f9f5d3c674602e2280cc803f068f07db7295c7d2a2f9d51844cc45', 'hex') }];
const p2wpkh = createPayment('p2wpkh', keys);

Now I perhaps going mistaken right here…

I then proceeded to create an enter information object like so (perhaps I’m lacking scriptPubKey, if that’s the case derive it in a state of affairs the place you aren’t related to the web?)?!

        const psbt = new bitcoin.Psbt({ community: bitcoin.networks.bitcoin })
                .addInput(inputData)
                .addOutput({
                        handle: '3HmEiQfaghizrNNn3tt5ydzvejLeYMzbD1',
                        worth: 2e4,
                })

Can somebody information me on proceed or the place to vary the logic?

Additionally if I perceive appropriately all unspent inputs (if I’ve a number of) would have to be signed individually, so do digital signatures have to be created individually after which signal the inputs one after the other?
Learn how to create a hash of the an unsigned transaction from PSBT? Additionally if there may be another approach to do that utilizing bitcoin-core or another library please let me know. I’d be a lot grateful.

Additionally please inform me if this doesn’t make sense in any respect. I feel I could be a bit confused on how I ought to use digital signatures right here.

Source link

LEAVE A REPLY

Please enter your comment!
Please enter your name here