/// <summary> /// Encodes a hash from a given type into a Bitcoin Cash address with the given prefix /// </summary> /// <param name="prefix">Network prefix. E.g.: 'bitcoincash'</param> /// <param name="type">Type of address to generate.</param> /// <param name="hash">Hash to encode represented as an array of 8-bit integers</param> /// <returns></returns> public static string Encode(string prefix, BchAddr.CashType type, byte[] hash) { var prefixData = Concat(PrefixToByte5Array(prefix), new byte[1]); var versionByte = GetTypeBits(type) + GetHashSizeBits(hash); var payloadData = ToByte5Array(Concat(new byte[1] { (byte)versionByte }, hash)); var checksumData = Concat(Concat(prefixData, payloadData), new byte[8]); var payload = Concat(payloadData, ChecksumToByte5Array(Polymod(checksumData))); return(prefix + ':' + Base32.Encode(payload)); }
/// <summary> /// Encodes a hash from a given type into a Bitcoin Cash address with the given prefix /// </summary> /// <param name="prefix">prefix Network prefix. E.g.: 'bitcoincash'</param> /// <param name="type">type Type of address to generate. Either 'P2PKH' or 'P2SH'</param> /// <param name="hash">hash Hash to encode represented as an array of 8-bit integers</param> /// <returns></returns> public static string Encode(string prefix, string type, byte[] hash) { Validation.Validate(IsValidPrefix(prefix), $"Invalid prefix: {prefix}"); var prefixData = Concat(PrefixToByte5Array(prefix), new byte[1]); var versionByte = GetTypeBits(type) + GetHashSizeBits(hash); var payloadData = ToByte5Array(Concat(new byte[1] { (byte)versionByte }, hash)); var checksumData = Concat(Concat(prefixData, payloadData), new byte[8]); var payload = Concat(payloadData, ChecksumToByte5Array(Polymod(checksumData))); return(prefix + ':' + Base32.Encode(payload)); }