bool CheckWitScriptCore(Network network, WitScript witScript)
 {
     return(witScript.PushCount == 2 &&
            (witScript[0].Length == 1 && witScript[0][0] == 0 ||
             TransactionSignature.IsValid(network, witScript[0], ScriptVerify.None)) &&
            PubKey.Check(witScript[1], false));
 }
 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);
 }
Пример #3
0
		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.Check(ops[1].PushData, false);
		}
Пример #4
0
		protected override bool CheckScriptPubKeyCore(Script scriptPubKey, Op[] scriptPubKeyOps)
		{
			var ops = scriptPubKeyOps;
			if(ops.Length != 2)
				return false;
			return ops[0].PushData != null && PubKey.Check(ops[0].PushData, false) &&
				   ops[1].Code == OpcodeType.OP_CHECKSIG;
		}
        /// <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(Network network, Script scriptSig, Op[] scriptSigOps, Script scriptPubKey, Op[] scriptPubKeyOps)
 {
     Op[] ops = scriptSigOps;
     if (ops.Length != 2)
     {
         return(false);
     }
     return(ops[0].PushData != null &&
            ((ops[0].Code == OpcodeType.OP_0) || TransactionSignature.IsValid(network, 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;
            var keys        = new List <PubKey>();
            var invalidKeys = new List <byte[]>();

            for (var 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()
            });
        }
Пример #8
0
		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.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()
			};
		}
Пример #9
0
 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));
 }
Пример #10
0
 public PubKey[] GetAllPubKeys() =>
 ToOps().Where(op => op.PushData != null && PubKey.Check(op.PushData, true)).Select(op => new PubKey(op.PushData)).ToArray();