public byte[] InputHash(SigHash hashType, Script subScript, int inputIndex) { if (hashType.HasFlag(SigHash.None)) { throw new NotImplementedException(); } if (hashType.HasFlag(SigHash.Single)) { throw new NotImplementedException(); } if (hashType.HasFlag(SigHash.AnyoneCanPay)) { throw new NotImplementedException(); } Transaction copy = Transaction.FromByteArray(ToByteArray()); foreach (Input input in copy.Inputs) { input.ScriptSig = new Script(); } copy.Inputs[inputIndex].ScriptSig = subScript; var verify = new List <byte>(); verify.AddRange(copy.ToByteArray()); verify.AddRange(BitConverter.GetBytes((UInt32)hashType)); return(Digest.Hash <SHA256, SHA256>(verify.ToArray())); }
public byte[] GenerateInputSignature(ECKey privateKey, SigHash hashType, Script subScript, int inputIndex) { if (hashType.HasFlag(SigHash.None)) { throw new NotImplementedException(); } if (hashType.HasFlag(SigHash.Single)) { throw new NotImplementedException(); } if (hashType.HasFlag(SigHash.AnyoneCanPay)) { throw new NotImplementedException(); } return(ArrayHelpers.ConcatArrays(privateKey.Sign(InputHash(hashType, subScript, inputIndex)), new byte[] { (byte)hashType })); }