Esempio n. 1
0
        public byte[] ComputeSigHash(Transaction transaction, TransactionInput input, TransactionOutput priorOutput, SigHashType sigHashType)
        {
            if (sigHashType != SigHashType.All)
            {
                throw new NotImplementedException("Only supports SigHashType.All");
            }

            var hashingScript = IsPayToScriptHash(input.SigScript, priorOutput.ScriptPubKey) ?
                                DecodeRedeemScript((byte[])input.SigScript.Commands[^ 1]) :
Esempio n. 2
0
        async Task <bool> InternalVerify(Transaction transaction, TransactionInput input)
        {
            var priorOutput = await fetcher.FetchPriorOutput(input);

            var script  = new Script(input.SigScript, priorOutput.ScriptPubKey);
            var sigHash = hasher.ComputeSigHash(transaction, input, priorOutput, SigHashType.All);

            return(evaluator.Evaluate(script.Commands, sigHash));
        }
        public override async Task <Script> CreateSigScript(Wallet wallet, Transaction transaction, TransactionInput input, SigHashType sigHashType)
        {
            var priorOutput = await Fetcher.FetchPriorOutput(input);

            if (priorOutput.ScriptPubKey.Commands.Count < 3 ||
                !(priorOutput.ScriptPubKey.Commands[2] is byte[] hash))
            {
                throw new FormatException("Unexpected opcode in output script");
            }
            var privateKey = wallet.FindByHash(hash);

            if (privateKey == null)
            {
                throw new PrivateKeyNotFoundException("Key not found in wallet");
            }
            return(await CreateSigScript(privateKey, transaction, input, sigHashType));
        }
        public override async Task <Script> CreateSigScript(PrivateKey privateKey, Transaction transaction, TransactionInput input, SigHashType sigHashType)
        {
            var signature = await ComputeSignatureBytes(privateKey, transaction, input, sigHashType);

            var sec = privateKey.PublicKey.ToSec();

            return(new Script(signature, sec));
        }
Esempio n. 5
0
        protected async Task <byte[]> ComputeSignatureBytes(PrivateKey privateKey, Transaction transaction, TransactionInput input, SigHashType sigHashType)
        {
            var hash = await hasher.ComputeSigHash(transaction, input, sigHashType);

            return(privateKey.Sign(hash).ToDer().Concat((byte)sigHashType));
        }
Esempio n. 6
0
        public async Task <byte[]> ComputeSigHash(Transaction transaction, TransactionInput input, SigHashType sigHashType)
        {
            var priorOutput = await fetcher.FetchPriorOutput(input);

            return(ComputeSigHash(transaction, input, priorOutput, sigHashType));
        }
Esempio n. 7
0
 public abstract Task <Script> CreateSigScript(Wallet wallet, Transaction transaction, TransactionInput input, SigHashType sigHashType);
Esempio n. 8
0
 public abstract Task <Script> CreateSigScript(PrivateKey privateKey, Transaction transaction, TransactionInput input, SigHashType sigHashType);
Esempio n. 9
0
        public Transaction CloneWithReplacedSigScript(TransactionInput input, Script script)
        {
            var newInputs = Inputs.Select(i => i == input ? i.CloneWithSigScript(script) : i.CloneWithoutSigScript());

            return(new(Version, Segwit, newInputs, Outputs, LockTime, Testnet));
        }
Esempio n. 10
0
        public Transaction CloneWithReplacedInput(TransactionInput oldInput, TransactionInput newInput)
        {
            var newInputs = Inputs.Select(i => i == oldInput ? newInput : i);

            return(new(Version, Segwit, newInputs, Outputs, LockTime, Testnet));
        }
Esempio n. 11
0
 public async Task <TransactionOutput> FetchPriorOutput(TransactionInput input)
 {
     return(await FetchOutput(new OutputPoint(input.PreviousTransaction, input.PreviousIndex)));
 }