Thursday, November 21, 2024

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

It appears the primary query may be completed with one thing like:

//after creating newtx and specifying enter and outputs  
newtx.Inputs[0].ScriptSig = privatekey.ScriptPubKey;  
newtx.Signal(privatekey, false);  //places signature and pubkey in ScriptSig  
//use these plus further parameters in script  
newtx.Inputs[0].ScriptSig = new Script(  
   newtx.Inputs[0].ScriptSig + " " +  
   //depart signature and pubkey as first parameters pushed onto stack  
   //then add further parameter (kind PubKey)  
   Op.GetPushOp(additionalParameter.ToBytes()) + " " +  
   //then add script whose hash was in unique P2SH trans  
   Op.GetPushOp(scriptIn.ToBytes()));  

The scriptIn is identical as the standard P2KH script preceded by a test for the hash of one other 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"  
        );  

However when the transaction is shipped it will get the next error:
16: mandatory-script-verify-flag-failed (Signature have to be zero for failed CHECK(MULTI)SIG operation)

Unsure why it is failing.

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles