Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: Anonymous Kid on October 07, 2018, 01:00:57 PM



Title: How is a bitcoin transaction serialised so that it is ready for signing?
Post by: Anonymous Kid on October 07, 2018, 01:00:57 PM
What are the exact technical steps to serialize a transactions so that it is ready to be signed and the resulting signature is valid?


Title: Re: How is a bitcoin transaction serialised so that it is ready for signing?
Post by: AdolfinWolf on October 07, 2018, 01:29:41 PM
What are the exact technical steps to serialize a transactions so that it is ready to be signed and the resulting signature is valid?
You mean something like this? https://bitcoin.stackexchange.com/a/32695

This answer is also pretty constructive (And is what the above answer is based on). https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx?noredirect=1&lq=1

The above answer also links an article which is defnitely worth a read. See http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html

I'd be very much interested in seeing a segwit version of this aswell. especially one which uses bech adresses. (If anyone has any links!)


Title: Re: How is a bitcoin transaction serialised so that it is ready for signing?
Post by: Anonymous Kid on October 07, 2018, 04:15:15 PM
What are the exact technical steps to serialize a transactions so that it is ready to be signed and the resulting signature is valid?
You mean something like this? https://bitcoin.stackexchange.com/a/32695

This answer is also pretty constructive (And is what the above answer is based on). https://bitcoin.stackexchange.com/questions/3374/how-to-redeem-a-basic-tx?noredirect=1&lq=1

The above answer also links an article which is defnitely worth a read. See http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html

I'd be very much interested in seeing a segwit version of this aswell. especially one which uses bech adresses. (If anyone has any links!)

Why does the hex transaction need to be decoded?
Code:
HEX_TRANSACTION="010000000126c07ece0bce7cda0ccd14d99e205f118cde27e83dd75da7b141fe487b5528fb000000008b48304502202b7e37831273d74c8b5b1956c23e79acd660635a8d1063d413c50b218eb6bc8a022100a10a3a7b5aaa0f07827207daf81f718f51eeac96695cf1ef9f2020f21a0de02f01410452684bce6797a0a50d028e9632be0c2a7e5031b710972c2a3285520fb29fcd4ecfb5fc2bf86a1e7578e4f8a305eeb341d1c6fc0173e5837e2d3c7b178aade078ffffffff02b06c191e010000001976a9143564a74f9ddb4372301c49154605573d7d1a88fe88ac00e1f505000000001976a914010966776006953d5567439e5e39f86a0d273bee88ac00000000"

tx_data=HEX_TRANSACTION.decode('hex_codec')
tx_hash=double_sha256(tx_data)

wouldnt the whole process work just as fine as
Code:
tx_hash = double_sha256(HEX_TRANSACTION)
. Whats the reasoning for adding this extra step?


Title: Re: How is a bitcoin transaction serialised so that it is ready for signing?
Post by: BrewMaster on October 07, 2018, 04:44:44 PM
Why does the hex transaction need to be decoded?

wouldnt the whole process work just as fine as
Code:
tx_hash = double_sha256(HEX_TRANSACTION)
. Whats the reasoning for adding this extra step?

you have to go look at what "double_sha256" method is doing under the hood. that function only understands an array of bytes. it can not understand a "string" which happens to be a hexadecimal one in this case. so you first "translate" it by calling "decode"