private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, Money value, ScriptVerify scriptVerify, out ScriptError error) { #if !NOCONSENSUSLIB if (!UseConsensusLib) #endif { if (input.Transaction is IHasForkId) { scriptVerify |= Scripting.ScriptVerify.ForkId; } return(input.VerifyScript(scriptPubKey, value, scriptVerify, out error)); } #if !NOCONSENSUSLIB if (input.Transaction is IHasForkId) { scriptVerify |= (ScriptVerify)(1U << 16); } var ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify); if (!ok) { if (input.VerifyScript(scriptPubKey, scriptVerify, out error)) { error = ScriptError.UnknownError; } return(false); } error = ScriptError.OK; return(true); #endif }
private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, ScriptVerify scriptVerify, out ScriptError error) { #if !NOCONSENSUSLIB if (!UseConsensusLib) #endif return(input.VerifyScript(scriptPubKey, scriptVerify, out error)); #if !NOCONSENSUSLIB else { var ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify); if (!ok) { if (input.VerifyScript(scriptPubKey, scriptVerify, out error)) { error = ScriptError.UnknownError; } return(false); } else { error = ScriptError.OK; } return(true); } #endif }
private bool VerifyScript(IndexedTxIn input, TxOut spentOutput, ScriptVerify scriptVerify, out ScriptError error) { #if !NOCONSENSUSLIB if (!UseConsensusLib) #endif { if (input.Transaction is IHasForkId) { scriptVerify |= NBitcoin.ScriptVerify.ForkId; } return(input.VerifyScript(spentOutput, scriptVerify, out error)); } #if !NOCONSENSUSLIB else { if (input.Transaction is IHasForkId) { scriptVerify |= (NBitcoin.ScriptVerify)(1U << 16); } var ok = Script.VerifyScriptConsensus(spentOutput.ScriptPubKey, input.Transaction, input.Index, scriptVerify); if (!ok) { if (input.VerifyScript(spentOutput, scriptVerify, out error)) { error = ScriptError.UnknownError; } return(false); } else { error = ScriptError.OK; } return(true); } #endif }
private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, Money value, ScriptVerify scriptVerify, out ScriptError error) { if (!this.UseConsensusLib) { return(input.VerifyScript(this.network, scriptPubKey, value, scriptVerify, out error)); } else { bool ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify); if (!ok) { if (input.VerifyScript(this.network, scriptPubKey, scriptVerify, out error)) { error = ScriptError.UnknownError; } return(false); } else { error = ScriptError.OK; } return(true); } }
public async Task <IActionResult> PostSignaturesAsync([FromQuery, Required] string uniqueId, [FromQuery, Required] long roundId, [FromBody, Required] IDictionary <int, string> signatures) { if (roundId < 0 || !signatures.Any() || signatures.Any(x => x.Key < 0 || string.IsNullOrWhiteSpace(x.Value)) || !ModelState.IsValid) { return(BadRequest()); } (CoordinatorRound round, Alice alice) = GetRunningRoundAndAliceOrFailureResponse(roundId, uniqueId, RoundPhase.Signing, out IActionResult returnFailureResponse); if (returnFailureResponse != null) { return(returnFailureResponse); } // Check if Alice provided signature to all her inputs. if (signatures.Count != alice.Inputs.Count()) { return(BadRequest("Alice did not provide enough witnesses.")); } RoundPhase phase = round.Phase; switch (phase) { case RoundPhase.Signing: { using (await SigningLock.LockAsync()) { foreach (var signaturePair in signatures) { int index = signaturePair.Key; WitScript witness = null; try { witness = new WitScript(signaturePair.Value); } catch (Exception ex) { return(BadRequest($"Malformed witness is provided. Details: {ex.Message}")); } int maxIndex = round.UnsignedCoinJoin.Inputs.Count - 1; if (maxIndex < index) { return(BadRequest($"Index out of range. Maximum value: {maxIndex}. Provided value: {index}")); } // Check duplicates. if (round.SignedCoinJoin.Inputs[index].HasWitScript()) { return(BadRequest("Input is already signed.")); } // Verify witness. // 1. Copy UnsignedCoinJoin. Transaction cjCopy = Transaction.Parse(round.UnsignedCoinJoin.ToHex(), Network); // 2. Sign the copy. cjCopy.Inputs[index].WitScript = witness; // 3. Convert the current input to IndexedTxIn. IndexedTxIn currentIndexedInput = cjCopy.Inputs.AsIndexedInputs().Skip(index).First(); // 4. Find the corresponding registered input. Coin registeredCoin = alice.Inputs.Single(x => x.Outpoint == cjCopy.Inputs[index].PrevOut); // 5. Verify if currentIndexedInput is correctly signed, if not, return the specific error. if (!currentIndexedInput.VerifyScript(registeredCoin, out ScriptError error)) { return(BadRequest($"Invalid witness is provided. {nameof(ScriptError)}: {error}.")); } // Finally add it to our CJ. round.SignedCoinJoin.Inputs[index].WitScript = witness; } alice.State = AliceState.SignedCoinJoin; await round.BroadcastCoinJoinIfFullySignedAsync(); } return(NoContent()); } default: { TryLogLateRequest(roundId, RoundPhase.Signing); return(Conflict($"CoinJoin can only be requested from Signing phase. Current phase: {phase}.")); } } }
private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, ScriptVerify scriptVerify, out ScriptError error) { if(!UseConsensusLib) return input.VerifyScript(scriptPubKey, scriptVerify, out error); else { var ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify); if(!ok) { if(input.VerifyScript(scriptPubKey, scriptVerify, out error)) error = ScriptError.UnknownError; return false; } else { error = ScriptError.OK; } return true; } }
private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, Money value, ScriptVerify scriptVerify, out ScriptError error) { return(input.VerifyScript(scriptPubKey, value, scriptVerify, out error)); }
static void Main(string[] args) { // parameters var walletPath = "/home/lontivero/.walletwasabi/client/Wallets/REAL.json"; var txHex = File.ReadAllText("tx.hex"); var index = 56; var tx = Transaction.Parse(txHex); tx.Inputs[index].WitScript = null; IndexedTxIn currentIndexedInput = tx.Inputs.AsIndexedInputs().Skip(index).First(); // 4. Find the corresponding registered input. Coin registeredCoin; TxOut output = null; OutPoint prevOut = tx.Inputs[index].PrevOut; using (var client = new HttpClient{BaseAddress = new Uri("https://api.smartbit.com.au/v1/")}) { using (HttpResponseMessage response = client.GetAsync($"blockchain/tx/{prevOut.Hash}/hex").GetAwaiter().GetResult()) { string cont = response.Content.ReadAsStringAsync().GetAwaiter().GetResult(); var json = JObject.Parse(cont); string hex = json["hex"][0]["hex"].ToString(); Transaction ttx = Transaction.Parse(hex, Network.Main); output = ttx.Outputs[prevOut.N]; registeredCoin = new Coin(prevOut, output); } } var km = KeyManager.FromFile(walletPath); var keys = km.GetSecrets("", registeredCoin.ScriptPubKey); var pass = false; while(!pass) { var builder = Network.Main.CreateTransactionBuilder(); var signedCoinJoin = builder .ContinueToBuild(tx) .AddKeys( keys.ToArray()) .AddCoins( registeredCoin ) .BuildTransaction(true); var w = signedCoinJoin.Inputs.Where(x=> x.WitScript != WitScript.Empty).FirstOrDefault(); tx.Inputs[index].WitScript = signedCoinJoin.Inputs[index].WitScript; // 5. Verify if currentIndexedInput is correctly signed, if not, return the specific error. #if CONSENSUS if (!Script.VerifyScriptConsensus(output.ScriptPubKey, tx, (uint)index, output.Value, ScriptVerify.Standard)) { Console.WriteLine($"Error"); } #else if (!currentIndexedInput.VerifyScript(registeredCoin, out ScriptError error)) { Console.WriteLine($"Error: {error}"); } } pass = true; #endif }
private bool VerifyScript(IndexedTxIn input, Script scriptPubKey, Money value, ScriptVerify scriptVerify, out ScriptError error) { #if !NOCONSENSUSLIB if(!UseConsensusLib) #endif return input.VerifyScript(scriptPubKey, value, scriptVerify, out error); #if !NOCONSENSUSLIB else { var ok = Script.VerifyScriptConsensus(scriptPubKey, input.Transaction, input.Index, scriptVerify); if(!ok) { if(input.VerifyScript(scriptPubKey, scriptVerify, out error)) error = ScriptError.UnknownError; return false; } else { error = ScriptError.OK; } return true; } #endif }