protected override bool FastCheckScriptPubKey(Script scriptPubKey, out bool needMoreCheck) { needMoreCheck = false; return (scriptPubKey.Length > 3 && PubKey.Check(scriptPubKey.ToBytes(true), 1, scriptPubKey.Length - 2, false) && scriptPubKey.ToBytes(true)[scriptPubKey.Length - 1] == 0xac); }
/// <summary> /// Extract the public key or null from the script /// </summary> /// <param name="scriptPubKey"></param> /// <param name="deepCheck">Whether deep checks are done on public key</param> /// <returns>The public key</returns> public PubKey ExtractScriptPubKeyParameters(Script scriptPubKey, bool deepCheck) { var result = ExtractScriptPubKeyParameters(scriptPubKey); if (result == null || !deepCheck) { return(result); } return(PubKey.Check(result.ToBytes(true), true) ? result : null); }
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 PayToMultiSigTemplateParameters ExtractScriptPubKeyParameters(Script scriptPubKey) { bool needMoreCheck; if (!FastCheckScriptPubKey(scriptPubKey, out needMoreCheck)) { return(null); } var ops = scriptPubKey.ToOps().ToArray(); if (!CheckScriptPubKeyCore(scriptPubKey, ops)) { return(null); } //already checked in CheckScriptPubKeyCore var sigCount = ops[0].GetInt().Value; var keyCount = ops[ops.Length - 2].GetInt().Value; List <PubKey> keys = new List <PubKey>(); List <byte[]> invalidKeys = new List <byte[]>(); for (int i = 1; i < keyCount + 1; i++) { if (!PubKey.Check(ops[i].PushData, false)) { 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() }); }
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)); }