Esempio n. 1
0
 internal static VerificationResult VerifySignature(this ISignable signable)
 {
     UInt160[] hashes;
     try
     {
         hashes = signable.GetScriptHashesForVerifying();
     }
     catch (InvalidOperationException)
     {
         return VerificationResult.LackOfInformation;
     }
     byte[][] scripts = signable.Scripts;
     if (hashes.Length != scripts.Length)
         return VerificationResult.InvalidSignature;
     for (int i = 0; i < hashes.Length; i++)
     {
         using (ScriptBuilder sb = new ScriptBuilder())
         {
             byte[] script = sb.Add(scripts[i]).Add(ScriptOp.OP_DUP).Add(ScriptOp.OP_HASH160).Push(hashes[i]).Add(ScriptOp.OP_EQUALVERIFY).Add(ScriptOp.OP_EVAL).ToArray();
             if (!ScriptEngine.Execute(script, signable.GetHashForSigning()))
                 return VerificationResult.InvalidSignature;
         }
     }
     return VerificationResult.OK;
 }
Esempio n. 2
0
 public static byte[] CreateSignatureRedeemScript(ECPoint publicKey)
 {
     using (ScriptBuilder sb = new ScriptBuilder())
     {
         sb.Push(publicKey.EncodePoint(true));
         sb.Add(ScriptOp.OP_CHECKSIG);
         return sb.ToArray();
     }
 }
Esempio n. 3
0
 public static byte[] CreateMultiSigRedeemScript(int m, params ECPoint[] publicKeys)
 {
     if (!(1 <= m && m <= publicKeys.Length && publicKeys.Length <= 1024))
         throw new ArgumentException();
     using (ScriptBuilder sb = new ScriptBuilder())
     {
         sb.Push(m);
         for (int i = 0; i < publicKeys.Length; i++)
         {
             sb.Push(publicKeys[i].EncodePoint(true));
         }
         sb.Push(publicKeys.Length);
         sb.Add(ScriptOp.OP_CHECKMULTISIG);
         return sb.ToArray();
     }
 }