Exemplo n.º 1
0
        /// <summary>
        /// Verifies if signature of provided header was created using
        /// private key that corresponds to given public key.
        /// </summary>
        public bool VerifySignature(PubKey pubKey, PoABlockHeader header)
        {
            if ((header.BlockSignature == null) || header.BlockSignature.IsEmpty())
            {
                this.logger.LogTrace("(-)[NO_SIGNATURE]");
                return(false);
            }

            if (!ECDSASignature.IsValidDER(header.BlockSignature.Signature))
            {
                this.logger.LogTrace("(-)[INVALID_DER]");
                return(false);
            }

            ECDSASignature signature = ECDSASignature.FromDER(header.BlockSignature.Signature);

            if (!signature.IsLowS)
            {
                this.logger.LogTrace("(-)[NOT_CANONICAL]");
                return(false);
            }

            uint256 headerHash       = header.GetHash();
            bool    isValidSignature = pubKey.Verify(headerHash, signature);

            return(isValidSignature);
        }
        public void Sign(Key key, PoABlockHeader header)
        {
            ECDSASignature signature = key.Sign(header.GetHash());

            header.BlockSignature = new BlockSignature {
                Signature = signature.ToDER()
            };
        }