What goes in to the message of a transaction signature?
来源:互联网 发布:网络潮州歌曲大全100首 编辑:程序博客网 时间:2024/06/05 19:58
I'm trying to create my own transaction from scratch, just to see how it works.
I'm currently working backwards, and I'm stuck on the signature of a transaction...
Here's my unsigned transaction:
0100000001ff8ddda903d6e76b6c6211e1b8f3b4eaaa8d080aaa008d4b05ca01ea39116cbf0000000000ffffffff0170c9fa02000000001976a9147865b0b301119fc3eadc7f3406ff1339908e46d488ac00000000
I like to think I understand each segment of this serialized transaction. However, I don't know how to recreate the signature. I know I need to create a message and send it through an ECDSA signing function, but I do not know how to construct the message.So basically, what goes in to the message to create a signature for this transaction?
The message whose numerically interpreted hash, z, is used to construct the ECDSA signature (r,s) is constructed as follows:
- Start with your unsigned transaction.
- Remove all scriptSigs (for example, if you have multiple txins, some of which may already be signed, remove those signatures). For your example this step has no effect since there's only one txin.
- For the txin you're about to sign, find the corresponding UTXO's scriptPubKey, and set the current txin's scriptSig to be the value of the UTXO's scriptPubKey.
- Serialize the transaction.
- Append the SIGHASH type, serialized as a 32-bit little-endian integer (the default SIGHASH_ALL has a value of 1).
The resulting byte stream is double SHA-256 hashed and interpreted as a big-endian integer (and used for ECDSA's z parameter).
For your example, the scriptPubKey to insert comes from the UTXO at txid bf6c1139ea01ca054b8d00aa0a088daaeab4f3b8e111626c6be7d603a9dd8dff index 0, specifically it is OP_DUP OP_HASH160 d951eb562f1ff26b6cbe89f04eda365ea6bd95ce OP_EQUALVERIFY OP_CHECKSIG
. Serialized, this is 76a914d951eb562f1ff26b6cbe89f04eda365ea6bd95ce88ac
. The transaction constructed after completing step 3 is:
"txid" : "a80d616ca30a003448157b92df511ad5294e225fd77fc3f2d5dc367a4d27f375","version" : 1,"locktime" : 0,"vin" : [ { "txid" : "bf6c1139ea01ca054b8d00aa0a088daaeab4f3b8e111626c6be7d603a9dd8dff", "vout" : 0, "scriptSig" : { "asm" : "OP_DUP OP_HASH160 d951eb562f1ff26b6cbe89f04eda365ea6bd95ce OP_EQUALVERIFY OP_CHECKSIG", "hex" : "76a914d951eb562f1ff26b6cbe89f04eda365ea6bd95ce88ac" }, "sequence" : 4294967295 }],"vout" : [ { "value" : 0.49990000, "n" : 0, "scriptPubKey" : { "asm" : "OP_DUP OP_HASH160 7865b0b301119fc3eadc7f3406ff1339908e46d4 OP_EQUALVERIFY OP_CHECKSIG", "hex" : "76a9147865b0b301119fc3eadc7f3406ff1339908e46d488ac", "reqSigs" : 1, "type" : "pubkeyhash", "addresses" : [ "1Bybuago2EGrB7Z6jJG2GAFDojp6Njr8fa" ] } }]
It may look strange to have a scriptPubKey-style script in the scriptSig field, but that's the way it is. Once serialized, this becomes:1: 0100000001ff8ddda903d6e76b6c6211e1b8f3b4eaaa8d080aaa008d4b05ca01ea39116cbf00000000192: 76a914d951eb562f1ff26b6cbe89f04eda365ea6bd95ce88ac3: ffffffff0170c9fa02000000001976a9147865b0b301119fc3eadc7f3406ff1339908e46d488ac000000004: 01000000
Above, line 2 is the serialized scriptPubKey, and line 4 is the appended SIGHASH_ALL. This full message is then hashed and interpreted as an int, resulting in z=78289050778760245857840977078575435990304898491073736369300700378208907476567
, which along with the private key is used to finally create the ECDSA signature.Note that step 2 above assumes a SIGHASH_ALL signature. Other signature types remove additional parts of the transaction before signing, please see the SIGHASH types link for more details.
- What goes in to the message of a transaction signature?
- Animate to display a dialog message box in the right-bottom of the window screen
- Use of the RSASSA-PSS Signature Algorithm in Cryptographic Message Syntax (CMS)
- What are the meaning of the items in the “alignment trap” error message?
- For different transaction types,What's the meaning of fields in MTL_MATERIAL_TRANSACTIONS
- Verifying the Signature of a PE File
- Verifying the Signature of a PE File
- Windows 2000 Loader What Goes On Inside Windows 2000: Solving the Mysteries of the Loader
- Windows 2000 Loader What Goes On Inside Windows 2000: Solving the Mysteries of the Loader
- What Goes On Inside Windows 2000: Solving the Mysteries of the Loader2
- NTDLL.dll1 : What Goes On Inside Windows 2000: Solving the Mysteries of the Loader
- A Message to the Future
- A Message to the Future
- 62.You are in the middle of a transaction updating a very important table. The machine on which a da
- Describe the process of opening a file in Linux system, what actions the operating system w
- What is the role of the activation function in a neural network?
- What is a Digital Signature?
- What is a Digital Signature?
- 博客关闭公告
- LeetCode No.264 Ugly Number II
- 【数据结构】利用堆建立哈夫曼树
- [转载]使用EasyRTMP调用海康、大华等SDK进行RTMP推送
- 【HDU 5945】 Fxx and game 【单调队列优化dp】
- What goes in to the message of a transaction signature?
- 使用Record Espresso Test功能自动生成测试代码
- 详解HashMap的存储结构与hash冲突
- 1861: [Zjoi2006]Book 书架
- Jfinal适用于条件查询的动态SQL语句生成工具
- 自定义异常类、运行时异常与编译时异常
- scau 1079 三角形(暴力)
- HTML前端学习1029(HTML结构)
- C语言实现打字通游戏