Esempio n. 1
0
        public override string ToHex(Transaction transaction, Transaction.SigHash sigHash = Transaction.SigHash.Undefined)
        {
            var hash = base.ToHex(transaction, sigHash);

            if (sigHash == Transaction.SigHash.Undefined)
            {
                // add the hashBoinc to the end of the transaction
                hash += "00";
            }
            else
            {
                // append the hashBoinc before the 4 byte sig hash (8 characters)
                hash = hash.Insert(hash.Length - 8, "00");
            }

            return(hash);
        }
Esempio n. 2
0
        public virtual string ToHex(Transaction transaction, Transaction.SigHash sigHash = Transaction.SigHash.Undefined)
        {
            using (var stream = new MemoryStream())
            {
                using (var writer = new BinaryWriter(stream))
                {
                    this.WriteVersion(writer, transaction);
                    this.WriteTimeStamp(writer, transaction);
                    this.WriteInputs(writer, transaction);
                    this.WriteOutputs(writer, transaction);
                    this.WriteLocktime(writer, transaction);

                    // when signing a transaction
                    this.WriteSigHash(writer, transaction, sigHash);

                    return(CryptoUtil.ToHex(stream.ToArray()));
                }
            }
        }
Esempio n. 3
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. 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionSignature"/> class.
 /// </summary>
 public TransactionSignature(EcKey.EcdsaSignature signature, Transaction.SigHash mode)
     : base(signature.R, signature.S)
 {
     this.sighash = mode;
 }
Esempio n. 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="TransactionSignature"/> class.
 /// </summary>
 public TransactionSignature(BigInteger r, BigInteger s, Transaction.SigHash sighash)
     : base(r, s)
 {
     this.sighash = sighash;
 }
Esempio n. 6
0
 protected virtual void WriteSigHash(BinaryWriter writer, Transaction transactionm, Transaction.SigHash sigHash)
 {
     if (sigHash != Transaction.SigHash.Undefined)
     {
         writer.Write((uint)sigHash);
     }
 }
 protected override void WriteSigHash(BinaryWriter writer, Transaction transactionm, Transaction.SigHash sigHash)
 {
     if (sigHash != Transaction.SigHash.Undefined)
     {
         // this is a signing transaction so we need to remove the timestamp
         writer.Seek(-4, SeekOrigin.Current);
         base.WriteSigHash(writer, transactionm, sigHash);
     }
 }