public PayToMultiSigTemplateParameters ExtractScriptPubKeyParameters(Script scriptPubKey) { if (!CheckScriptPubKey(scriptPubKey)) { return(null); } var ops = scriptPubKey.ToOps().ToArray(); var sigCount = (byte)ops[0].PushData[0]; List <PubKey> keys = new List <PubKey>(); for (int i = 1; i < ops.Length; i++) { if (!PubKey.IsValidSize(ops[i].PushData.Length)) { break; } keys.Add(new PubKey(ops[i].PushData)); } return(new PayToMultiSigTemplateParameters() { SignatureCount = sigCount, PubKeys = keys.ToArray() }); }
public override bool CheckScriptSig(Script scriptSig, Script scriptPubKey) { var ops = scriptSig.ToOps().ToArray(); if (ops.Length != 2) { return(false); } return(ops[0].PushData != null && ops[1].PushData != null && PubKey.IsValidSize(ops[1].PushData.Length)); }
public override bool CheckScriptPubKey(Script scriptPubKey) { var ops = scriptPubKey.ToOps().ToList(); if (ops.Count != 2) { return(false); } return(ops[0].PushData != null && PubKey.IsValidSize(ops[0].PushData.Length) && ops[1].Code == OpcodeType.OP_CHECKSIG); }
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[1].PushData != null && PubKey.IsValidSize(ops[1].PushData.Length)); }
protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps) { var ops = scriptPubKeyOps; if (ops.Length != 2) { return(false); } return(ops[0].PushData != null && PubKey.IsValidSize(ops[0].PushData.Length) && ops[1].Code == OpcodeType.OP_CHECKSIG); }
public PayToMultiSigTemplateParameters ExtractScriptPubKeyParameters(Script scriptPubKey) { if (!FastCheckScriptPubKey(scriptPubKey)) { return(null); } var ops = scriptPubKey.ToOps().ToArray(); if (!CheckScriptPubKeyCore(scriptPubKey, ops)) { return(null); } var sigCount = (int)ops[0].GetValue(); var keyCount = (int)ops[ops.Length - 2].GetValue(); List <PubKey> keys = new List <PubKey>(); List <byte[]> invalidKeys = new List <byte[]>(); for (int i = 1; i < keyCount + 1; i++) { if (!PubKey.IsValidSize(ops[i].PushData.Length)) { invalidKeys.Add(ops[i].PushData); } else { try { keys.Add(new PubKey(ops[i].PushData)); } catch (FormatException) { invalidKeys.Add(ops[i].PushData); } } } return(new PayToMultiSigTemplateParameters() { SignatureCount = sigCount, PubKeys = keys.ToArray(), InvalidPubKeys = invalidKeys.ToArray() }); }
public override bool CheckScriptPubKey(Script scriptPubKey) { var ops = scriptPubKey.ToOps().ToArray(); if (ops.Length < 3) { return(false); } var sigCount = ops[0]; if (!sigCount.IsSmallUInt) { return(false); } var expectedKeyCount = 0; var keyCountIndex = 0; for (int i = 1; i < ops.Length; i++) { if (ops[i].PushData == null) { return(false); } if (!PubKey.IsValidSize(ops[i].PushData.Length)) { keyCountIndex = i; break; } expectedKeyCount++; } if (!ops[keyCountIndex].IsSmallUInt) { return(false); } if (ops[keyCountIndex].GetValue() != expectedKeyCount) { return(false); } return(ops[keyCountIndex + 1].Code == OpcodeType.OP_CHECKMULTISIG && keyCountIndex + 1 == ops.Length - 1); }
private bool CheckSig(byte[] vchSig, byte[] vchPubKey, Script scriptCode, Transaction txTo, int nIn) { //static CSignatureCache signatureCache; if (!PubKey.IsValidSize(vchPubKey.Length)) { return(false); } PubKey pubkey = null; try { pubkey = new PubKey(vchPubKey); } catch (Exception) { return(false); } // Hash type is one byte tacked on to the end of the signature if (vchSig.Length == 0) { return(false); } var scriptSig = new TransactionSignature(vchSig); if (!IsAllowedSignature(scriptSig.SigHash)) { return(false); } uint256 sighash = scriptCode.SignatureHash(txTo, nIn, scriptSig.SigHash); //if (signatureCache.Get(sighash, vchSig, pubkey)) // return true; if (!pubkey.Verify(sighash, scriptSig.Signature)) { if ((ScriptVerify & ScriptVerify.StrictEnc) != 0) { return(false); } //Replicate OpenSSL bug on 23b397edccd3740a74adb603c9756370fafcde9bcc4483eb271ecad09a94dd63 (http://r6.ca/blog/20111119T211504Z.html) var nLenR = vchSig[3]; var nLenS = vchSig[5 + nLenR]; var R = 4; var S = 6 + nLenR; var newS = new Org.BouncyCastle.Math.BigInteger(1, vchSig, S, nLenS); var newR = new Org.BouncyCastle.Math.BigInteger(1, vchSig, R, nLenR); var sig2 = new ECDSASignature(newR, newS); if (sig2.R != scriptSig.Signature.R || sig2.S != scriptSig.Signature.S) { if (!pubkey.Verify(sighash, sig2)) { return(false); } } } //if (!(flags & SCRIPT_VERIFY_NOCACHE)) // signatureCache.Set(sighash, vchSig, pubkey); return(true); }