Пример #1
0
        bool Verify()
        {
            var s = _Static;

            var message         = $"{s.prevMinerId}{s.minerId}{s.vctx.txid}";
            var verifyHash      = KzHashes.SHA256(message.UTF8ToBytes());
            var verifySignature = s.prevMinerIdSig.HexToBytes();

            PrevPubKeyBytes = s.prevMinerId.HexToBytes();
            PrevPubKey      = new KzPubKey(PrevPubKeyBytes);

            var verified = PrevPubKey.IsValid && PrevPubKey.Verify(verifyHash, verifySignature);

            if (verified)
            {
                PubKeyBytes = s.minerId.HexToBytes();
                PubKey      = new KzPubKey(PubKeyBytes);
                verified    = PubKey.IsValid;
            }

            return(verified);
        }
Пример #2
0
        /// <summary>
        /// The checksum is a substring of the binary representation of the SHA256 hash of entropy.
        /// For every four bytes of entropy, one additional bit of the hash is used.
        /// </summary>
        /// <param name="entropy"></param>
        /// <returns></returns>
        public static string GetChecksum(ReadOnlySequence <byte> entropy)
        {
            var hash = KzHashes.SHA256(entropy);
            var bits = (int)entropy.Length * 8;
            var cs   = bits / 32;

            var sb = new StringBuilder();

            foreach (var b in hash.Span)
            {
                sb.Append(Convert.ToString(b, 2).PadLeft(8, '0'));
                cs -= 8;
                if (cs <= 0)
                {
                    break;
                }
            }
            if (cs < 0)
            {
                sb.Length += cs;
            }

            return(sb.ToString());
        }
Пример #3
0
        static KzUInt256 GetMessageHash(ReadOnlySpan <byte> message)
        {
            var messagehash = KzHashes.SHA256(message).ToHex();

            return(new KzWriterHash().Add(_messageMagic).Add(messagehash).GetHashFinal());
        }