Exemplo 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]) :
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo n.º 7
0
 public abstract Task <Script> CreateSigScript(Wallet wallet, Transaction transaction, TransactionInput input, SigHashType sigHashType);
Exemplo n.º 8
0
 public abstract Task <Script> CreateSigScript(PrivateKey privateKey, Transaction transaction, TransactionInput input, SigHashType sigHashType);
Exemplo 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));
        }
Exemplo 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));
        }
Exemplo n.º 11
0
 public async Task <TransactionOutput> FetchPriorOutput(TransactionInput input)
 {
     return(await FetchOutput(new OutputPoint(input.PreviousTransaction, input.PreviousIndex)));
 }