/// <summary> /// Computes double SHA256 of data: SHA256(SHA256(data)) /// </summary> /// <param name="data">Input: bytes to be hashed.</param> /// <returns>SHA256 of SHA256 of data.</returns> public static UInt256 Hash256(this ReadOnlyByteSpan data) { var hash = new UInt256(); data.Hash256(hash.Span); return(hash); }
/// <summary> /// Appends first 4 bytes of double SHA256 hash to bytes before standard Base58 encoding. /// </summary> /// <param name="bytes"></param> /// <returns></returns> public override string Encode(ReadOnlyByteSpan bytes) { var checksum = bytes.Hash256(); var buf = new byte[bytes.Length + 4]; bytes.CopyTo(buf); checksum.Span.Slice(0, 4).CopyTo(buf.AsSpan().Slice(bytes.Length)); return(Encoders.Base58.Encode(buf)); }