NBitcoin get signature, use spending P2SH transaction with non-standard script

NBitcoin get signature, use spending P2SH transaction with non-standard script

Manage alerts

Loading saved threads...

BPFL · External communityPost link
External question — Bitcoin Stack Exchange Author: BPFL Original post: https://bitcoin.stackexchange.com/questions/81707 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. After creating a new NBitcoin transaction (with a single pay-to-script hash input and multiple outputs), is there any way to calculate the transaction signature and manually put it in the inputs[0].ScriptSig, along with other parameters used by the script? A related issue is whether (and how) non-standard scripts can be used in P2SH transactions.
Quote
Report
BPFL · External communityPost link
External answer — Bitcoin Stack Exchange Author: BPFL Original post: https://bitcoin.stackexchange.com/a/81910 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. It seems the first question can be accomplished with something like: //after creating newtx and specifying input and outputs newtx.Inputs[0].ScriptSig = privatekey.ScriptPubKey; newtx.Sign(privatekey, false); //puts signature and pubkey in ScriptSig //use those plus additional parameters in script newtx.Inputs[0].ScriptSig = new Script( newtx.Inputs[0].ScriptSig + " " + //leave signature and pubkey as first parameters pushed onto stack //then add additional parameter (type PubKey) Op.GetPushOp(additionalParameter.ToBytes()) + " " + //then add script whose hash was in original P2SH trans Op.GetPushOp(scriptIn.ToBytes())); The scriptIn is the same as the usual P2KH script preceded by a check for the hash of another parameter scriptIn = new Script( "OP_HASH160 " + Op.GetPushOp(additionalParameter.Hash.ToBytes()) + " OP_EQUALVERIFY" + " OP_DUP" + " OP_HASH160 " + Op.GetPushOp(pubkeyhash.ToBytes()) + " OP_EQUALVERIFY" + " OP_CHECKSIG" ); But when the transaction is sent it gets the following error: 16: mandatory-script-verify-flag-failed (Signature must be zero for failed CHECK(MULTI)SIG operation) Not sure why it's failing.
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Bitcoin Stack Exchange Author: BPFL Source score (net votes, not local likes): 2 Original post: https://bitcoin.stackexchange.com/questions/81707 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. After creating a new NBitcoin transaction (with a single pay-to-script hash input and multiple outputs), is there any way to calculate the transaction signature and manually put it in the inputs[0].ScriptSig, along with other parameters used by the script? A related issue is whether (and how) non-standard scripts can be used in P2SH transactions.

Cancel quote

Checking account access…