1
1
Given a bitcoin transaction where it is able to redeem it's UTXO's, how can I verify in Java if the signature is actually a valid signature or not. I was trying to use the Bouncy Castle library where I was trying to recreate the message that the private key signs over.
From what I know I need the following things -
1.The version number(4 bytes)
2.The number of Inputs(1 byte)
3.Transaction hash of the input being redeemed
4.Index of the output being redeemed (4 bytes)
5.ScriptPubKey of the output being redeemed prepended with the length of the script
6.Sequence Number(4 bytes)
7.No of outputs we are signing over(1 byte)
8.Total value of the output(8 bytes)
9.ScriptSig for the output prepended with the length
10.locktime field(4 bytes)
11.hashcode type(4 bytes)
I have tried to capture this information from the transaction data but when I try to verify the signature, it fails. Am I missing something?I want to be able to verify if a signature is correct. Thanks.
From what I have read, Step number 5 is a temporary step and the ScriptPubkey is replaced by some other value but I am unable to understand what that value should be.
So in the case where I have one single input spending to two outputs how would this work? Say I hold 500 BTC in one private key and I am sending 200 to Address A, 200 to Address B and 100 to Address C(for sake of simplicity we omit the transaction fee). Then which ScriptPubkey should be put in the scriptSig for input of 500 BTC. @AndrewChow – shubham saxena – 2019-09-10T06:37:22.827
Awesome! I found the bug. I realised that except for the Scripts everything else is stored in little endian format! It works now. – shubham saxena – 2019-09-10T10:12:57.870