1

I studied many links about bitcoin trxs and about generating scriptSig. Finally I couldn't understand how to make this part.

for example I read this links:

What is relation between scriptSig and scriptPubKey?

https://bitcoin.org/en/developer-guide#transactions

How do you create a scriptsig for a new raw tx?

How to redeem a basic Tx?

How to create the <sig> <PubK> part in "scriptSig"?

http://www.righto.com/2014/02/bitcoins-hard-way-using-raw-bitcoin.html

https://en.bitcoin.it/wiki/Protocol_documentation#tx

https://en.bitcoin.it/wiki/Transaction

I found that I must sign a thing but whats that thing ?

exactly and step by step What should I put together and then sign it?

specially if I had more than 1 input how make sigscript ?

I have a library that does the sign operation for me. however, I don't know what structure I need to use for the message that is going to be signed especially when there are multiple outputs.

1 Answer 1

1

The data to be signed is called Hash Preimage. Then you sign the double SHA256 of hash preimage, which is 256-bits long. Before hashing, the data must be formed as shown in this answer. If you're signing a SegWit transaction, the contents of the preimage changes, as defined in BIP 143.

Then you can use the formulae here, Eq. 2:

(x1, y1) = k × G(x, y) mod p
r = x1 mod n

k is a random number, G is the generator, p is the prime modulo, etc.

Then,

s = (k^-1 (h(m) + d * r)) mod n

d is the private key, h(m) is the double SHA256 result. Now, you can use r, s to create the DER-encoded signature.

5
  • I read this but this solution was for only a transaction with one output. if my outputs becomes 2 or 3 now how must make scriptsig? Aug 19, 2018 at 10:38
  • Here's an example with multiple outputs. Here's the specification for outputs in BIP143, scroll down to hashOutputs.
    – MCCCS
    Aug 19, 2018 at 13:42
  • I read this link But it's not explained at all about how the script signature section was created !! Aug 19, 2018 at 16:22
  • After you formed the data in the examples, you double sha256 it and use the equations above. Do you want to learn how to do that using libsecp256k1?
    – MCCCS
    Aug 19, 2018 at 19:18
  • 1
    no. I have a library that do the sign operation for me. I only want to know exactly which parts of the transaction do I need to put together, and what order should I use before sign operation with more than one input and one output ? Aug 21, 2018 at 7:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.