Esempio n. 1
0
        public TransactionSignature CalculateSignature(Transaction transaction, TransactionOutPoint outPoint, EcKey key, Script.Script redeemScript, Transaction.SigHash hashType)
        {
            // at the moment only signing all the outputs is supported
            Thrower.If(hashType != Transaction.SigHash.All).Throw <TransactionException>("Only SigHash type 'All' supported");

            //// clone the transaction and clear all the inputs
            //// only the inputs for the equivalent output needs to be present for signing
            var signTx = transaction.Clone();

            signTx.Inputs.ForEach(input => input.ScriptBytes = Enumerable.Empty <byte>().ToArray());

            // set the redeem script and clear it of 'OP_CODESEPARATOR'
            var connectedScript       = redeemScript.GetProgram();
            var redeemConnectedScript = Script.Script.RemoveAllInstancesOfOp(connectedScript, ScriptOpCodes.OP_CODESEPARATOR);

            signTx.FindInput(outPoint).ScriptBytes = redeemConnectedScript;

            // serialize then hash the transaction to HEX and sign it.
            var trxHex = this.Serializer.ToHex(signTx, hashType);
            var hash   = CryptoUtil.Sha256HashTwice(CryptoUtil.ConvertHex(trxHex));

            return(new TransactionSignature(key.Sign(hash), hashType));
        }
Esempio n. 2
0
 public RedeemScript Find(TransactionOutPoint outPoint)
 {
     return(this.Items.FirstOrDefault(t => t.Hash == outPoint.Hash && t.Index == outPoint.Index));
 }