protected override bool CheckScriptSigCore(Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps) { if (!scriptSig.IsPushOnly) { return(false); } if (scriptSigOps[0].Code != OpcodeType.OP_0) { return(false); } if (scriptSigOps.Length == 1) { return(false); } if (!scriptSigOps.Skip(1).All(s => TransactionSignature.ValidLength(s.PushData.Length) || s.Code == OpcodeType.OP_0)) { return(false); } if (scriptPubKeyOps != null) { if (!CheckScriptPubKeyCore(scriptPubKey, scriptPubKeyOps)) { return(false); } var sigCountExpected = scriptPubKeyOps[0].GetValue(); return(sigCountExpected == scriptSigOps.Length + 1); } return(true); }
protected override bool CheckScriptSigCore(Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps) { var ops = scriptSigOps; if (ops.Length != 1) { return(false); } return(ops[0].PushData != null && TransactionSignature.IsValid(ops[0].PushData)); }
public override bool Equals(object obj) { TransactionSignature item = obj as TransactionSignature; if (item == null) { return(false); } return(Id.Equals(item.Id)); }
public WitScript GenerateWitScript(TransactionSignature signature, PubKey publicKey) { if (publicKey == null) { throw new ArgumentNullException("publicKey"); } return(new WitScript( signature == null ? OpcodeType.OP_0 : Op.GetPushOp(signature.ToBytes()), Op.GetPushOp(publicKey.ToBytes()) )); }
protected override bool CheckScriptSigCore(Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps) { var ops = scriptSigOps; if (ops.Length != 2) { return(false); } return(ops[0].PushData != null && ((ops[0].Code == OpcodeType.OP_0) || TransactionSignature.IsValid(ops[0].PushData, ScriptVerify.None)) && ops[1].PushData != null && PubKey.Check(ops[1].PushData, false)); }
public TransactionSignature ExtractScriptSigParameters(Script scriptSig) { var ops = scriptSig.ToOps().ToArray(); if (!CheckScriptSigCore(scriptSig, ops, null, null)) { return(null); } var data = ops[0].PushData; if (!TransactionSignature.ValidLength(data.Length)) { return(null); } try { return(new TransactionSignature(data)); } catch (FormatException) { return(null); } }
private bool CheckWitScriptCore(WitScript witScript) { return(witScript.PushCount == 2 && ((witScript[0].Length == 1 && witScript[0][0] == 0) || (TransactionSignature.IsValid(witScript[0], ScriptVerify.None))) && PubKey.Check(witScript[1], false)); }
public Script GenerateScriptSig(TransactionSignature signature) { return(new Script( Op.GetPushOp(signature.ToBytes()) )); }
private static Script CombineMultisig(Script scriptPubKey, TransactionChecker checker, byte[][] sigs1, byte[][] sigs2, HashVersion hashVersion) { // Combine all the signatures we've got: List <TransactionSignature> allsigs = new List <TransactionSignature>(); foreach (var v in sigs1) { if (TransactionSignature.IsValid(v)) { allsigs.Add(new TransactionSignature(v)); } } foreach (var v in sigs2) { if (TransactionSignature.IsValid(v)) { allsigs.Add(new TransactionSignature(v)); } } var multiSigParams = PayToMultiSigTemplate.Instance.ExtractScriptPubKeyParameters(scriptPubKey); if (multiSigParams == null) { throw new InvalidOperationException("The scriptPubKey is not a valid multi sig"); } Dictionary <PubKey, TransactionSignature> sigs = new Dictionary <PubKey, TransactionSignature>(); foreach (var sig in allsigs) { foreach (var pubkey in multiSigParams.PubKeys) { if (sigs.ContainsKey(pubkey)) { continue; // Already got a sig for this pubkey } ScriptEvaluationContext eval = new ScriptEvaluationContext(); if (eval.CheckSig(sig, pubkey, scriptPubKey, checker, hashVersion)) { sigs.AddOrReplace(pubkey, sig); } } } // Now build a merged CScript: int nSigsHave = 0; Script result = new Script(OpcodeType.OP_0); // pop-one-too-many workaround foreach (var pubkey in multiSigParams.PubKeys) { if (sigs.ContainsKey(pubkey)) { result += Op.GetPushOp(sigs[pubkey].ToBytes()); nSigsHave++; } if (nSigsHave >= multiSigParams.SignatureCount) { break; } } // Fill any missing with OP_0: for (int i = nSigsHave; i < multiSigParams.SignatureCount; i++) { result += OpcodeType.OP_0; } return(result); }