Esempio n. 1
0
        public async Task <Transaction> SignTransaction(Wallet wallet, Transaction transaction, SigHashType sigHashType, bool ignoreKeyNotFound = false)
        {
            foreach (var input in transaction.Inputs)
            {
                var priorOutput = await fetcher.FetchPriorOutput(input);

                var scriptType = scriptClassifier.GetScriptType(priorOutput.ScriptPubKey);
                var signer     = signerMap[scriptType];
                if (signer != null)
                {
                    try
                    {
                        var sigScript = await signer.CreateSigScript(wallet, transaction, input, sigHashType);

                        transaction = transaction.CloneWithReplacedSigScript(input, sigScript);
                    }
                    catch (PrivateKeyNotFoundException)
                    {
                        if (!ignoreKeyNotFound)
                        {
                            throw;
                        }
                    }
                }
                else if (!ignoreKeyNotFound)
                {
                    throw new InvalidOperationException($"Unknown script type for prior output {input.PreviousTransaction}:{input.PreviousIndex}");
                }
            }

            return(transaction);
        }
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));
        }
Esempio n. 3
0
        public async Task <byte[]> ComputeSigHash(Transaction transaction, TransactionInput input, SigHashType sigHashType)
        {
            var priorOutput = await fetcher.FetchPriorOutput(input);

            return(ComputeSigHash(transaction, input, priorOutput, sigHashType));
        }