~
I think that signing process is very standard:
1. For all inputs
2. Read scriptPubKey
3. Hash scriptPubKey
4. Sign hashed result
I don't see any problem with if next step will be
5. Save signature in array
This should be work for any scriptPubKey. The user will decide for himself what to do with the array from step 5.
it is not that simple. you are missing a lot of branches after step 2 and your step 3 is wrong, you don't hash the script, you hash the "modified" transaction. look at
https://en.bitcoin.it/wiki/OP_CHECKSIG and
https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki for all the details but the summary of it is something like this:
1. for "each" input
2. read related outpoint's scriptpub
2.1. figure out the type of it
2.2. prepare the message digest or digests
based on the type3. hash it/them and get a final digest
4. sign it.
the steps 2.1 and 2.2 can be entirely different depending on what step 2. returned. and it has to be a pre-defined type. for example if it returned P2PKH type then it empties all the other txin scriptsigs and replaces the corresponding input's script with that P2PKH script and then signs the whole modified transaction.
if it was P2WPKH then the entire hashing mechanism changes. you have to concatenate different parts together hash them then concatenate the hashes together and hash them again (BIP143).
if it were non-standard or not pre-defined, like say your scriptpub was this:
OP_HASH160 <4266fc6f2c2861d7fe229b279a79803afca7ba34> OP_EQUAL
and redeem script was:
OP_2DUP OP_EQUAL OP_NOT OP_VERIFY OP_SHA1 OP_SWAP OP_SHA1 OP_EQUAL
there is no way any code could predict how to produce a valid signature for this. you HAVE TO do it manually since it is "non-standard". by the way there is no signing or hashing (the transaction) involved in this script
link