Exemplo n.º 1
0
 public SignatureContext(ISignable signable)
 {
     this.Signable      = signable;
     this.ScriptHashes  = signable.GetScriptHashesForVerifying();
     this.redeemScripts = new byte[ScriptHashes.Length][];
     this.signatures    = new Dictionary <ECPoint, byte[]> [ScriptHashes.Length];
 }
Exemplo n.º 2
0
 internal static bool VerifySignature(this ISignable signable)
 {
     UInt160[] hashes;
     try
     {
         hashes = signable.GetScriptHashesForVerifying();
     }
     catch (InvalidOperationException)
     {
         return(false);
     }
     if (hashes.Length != signable.Scripts.Length)
     {
         return(false);
     }
     for (int i = 0; i < hashes.Length; i++)
     {
         if (hashes[i] != signable.Scripts[i].RedeemScript.ToScriptHash())
         {
             return(false);
         }
         ScriptEngine engine = new ScriptEngine(signable.Scripts[i], signable, InterfaceEngine.Default);
         if (!engine.Execute())
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 3
0
 public SignatureContext(ISignable signable)
 {
     this.Signable = signable;
     this.ScriptHashes = signable.GetScriptHashesForVerifying();
     this.redeemScripts = new byte[ScriptHashes.Length][];
     this.signatures = new Dictionary<ECPoint, byte[]>[ScriptHashes.Length];
 }
Exemplo n.º 4
0
 /// <summary>
 /// 对指定的数据构造签名上下文
 /// </summary>
 /// <param name="signable">要签名的数据</param>
 public SignatureContext(ISignable signable)
 {
     this.Signable      = signable;
     this.ScriptHashes  = signable.GetScriptHashesForVerifying();
     this.redeemScripts = new byte[ScriptHashes.Length][];
     this.parameters    = new byte[ScriptHashes.Length][][];
     this.temp          = new JObject[ScriptHashes.Length];
 }
Exemplo n.º 5
0
 internal static bool VerifySignature(this ISignable signable)
 {
     UInt160[] hashes;
     try
     {
         hashes = signable.GetScriptHashesForVerifying();
     }
     catch (InvalidOperationException)
     {
         return(false);
     }
     if (hashes.Length != signable.Scripts.Length)
     {
         return(false);
     }
     for (int i = 0; i < hashes.Length; i++)
     {
         byte[] redeem_script = signable.Scripts[i].RedeemScript;
         if (redeem_script.Length == 0)
         {
             using (ScriptBuilder sb = new ScriptBuilder())
             {
                 sb.EmitAppCall(hashes[i].ToArray());
                 redeem_script = sb.ToArray();
             }
         }
         else
         {
             if (hashes[i] != redeem_script.ToScriptHash())
             {
                 return(false);
             }
         }
         ExecutionEngine engine = new ExecutionEngine(signable, ECDsaCrypto.Default, 1200, Blockchain.Default, InterfaceEngine.Default);
         engine.LoadScript(redeem_script, false);
         engine.LoadScript(signable.Scripts[i].StackScript, true);
         engine.Execute();
         if (engine.State != VMState.HALT)
         {
             return(false);
         }
         if (engine.EvaluationStack.Count != 1 || !engine.EvaluationStack.Pop().GetBoolean())
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 6
0
 internal static bool VerifySignature(this ISignable signable)
 {
     UInt160[] hashes;
     try
     {
         hashes = signable.GetScriptHashesForVerifying();
     }
     catch (InvalidOperationException)
     {
         return(false);
     }
     if (hashes.Length != signable.Scripts.Length)
     {
         return(false);
     }
     for (int i = 0; i < hashes.Length; i++)
     {
         if (hashes[i] != signable.Scripts[i].RedeemScript.ToScriptHash())
         {
             return(false);
         }
         ScriptEngine engine = new ScriptEngine(signable, ECDsaCrypto.Default, Blockchain.Default, InterfaceEngine.Default);
         if (!engine.ExecuteScript(signable.Scripts[i].StackScript, true))
         {
             return(false);
         }
         if (!engine.ExecuteScript(signable.Scripts[i].RedeemScript, false))
         {
             return(false);
         }
         if (engine.Stack.Count != 1 || !engine.Stack.Pop())
         {
             return(false);
         }
     }
     return(true);
 }
Exemplo n.º 7
0
 public SignatureContext(ISignable signable)
 {
     this.Signable = signable;
     this.ScriptHashes = signable.GetScriptHashesForVerifying();
     this.signatures = new MultiSigContext[ScriptHashes.Length];
 }