Пример #1
0
        public static bool VerifyLockScriptByUnlockScript(string transactionHash, int outputIndex, string lockScript, string unlockScript)
        {
            var data = new List <byte>();

            data.AddRange(Base16.Decode(transactionHash));

            var indexBytes = BitConverter.GetBytes(outputIndex);

            if (BitConverter.IsLittleEndian)
            {
                Array.Reverse(indexBytes);
            }

            data.AddRange(indexBytes);

            var parameters      = unlockScript.Split("[ALL] ");
            var dsa             = ECDsa.ImportPublicKey(Base16.Decode(parameters[1]));
            var signatureResult = dsa.VerifyData(data.ToArray(), Base16.Decode(parameters[0]));

            if (signatureResult)
            {
                var publicKeyHash = GetPublicKeyHashFromLockScript(lockScript);
                return(Base16.Encode(HashHelper.Hash160(Base16.Decode(parameters[1]))) == publicKeyHash);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        public static bool VerifyMiningPoolSignature(string data, string signature)
        {
            var dsa            = ECDsa.ImportPublicKey(Base16.Decode(SUPER_NODE_PUBLIC_KEY));
            var current        = Base16.Decode(data);
            var signatureBytes = Base16.Decode(signature);
            var result         = dsa.VerifyData(current, signatureBytes);

            return(result);
        }
Пример #3
0
        public static bool VerifyBlockSignature(string data, string signature, string publicKey)
        {
            var dsa            = ECDsa.ImportPublicKey(Base16.Decode(publicKey));
            var current        = Base16.Decode(data);
            var signatureBytes = Base16.Decode(signature);
            var result         = dsa.VerifyData(current, signatureBytes);

            return(result);
        }
Пример #4
0
 public IRpcMethodResult VerifyMessage(string publicKey, string signature, string message)
 {
     try
     {
         ECDsa dsa    = ECDsa.ImportPublicKey(Base16.Decode(publicKey));
         var   result = dsa.VerifyData(Encoding.UTF8.GetBytes(message), Base16.Decode(signature));
         return(Ok(result));
     }
     catch (CommonException ce)
     {
         return(Error(ce.ErrorCode, ce.Message, ce));
     }
     catch (Exception ex)
     {
         return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
     }
 }