public string GetPublicAddress() { if (!string.IsNullOrWhiteSpace(_publicAddress)) { return(_publicAddress); } var initaddr = _ecKey.GetPubKeyNoPrefix().ToKeccakHash(); var address = new byte[initaddr.Length - 11]; Array.Copy(initaddr, 12, address, 1, 20); address[0] = GetPublicAddressPrefix(); var hash = Base58Encoder.TwiceHash(address); var bytes = new byte[4]; Array.Copy(hash, bytes, 4); var addressChecksum = new byte[25]; Array.Copy(address, 0, addressChecksum, 0, 21); Array.Copy(bytes, 0, addressChecksum, 21, 4); if (_network == TronNetwork.MainNet) { _publicAddress = Base58Encoder.Encode(addressChecksum); } else { _publicAddress = addressChecksum.ToHex(); } return(_publicAddress); }
public void Base58TestCases(bool ok, string hex, string base58) { var hexValue = Hex.Decode(hex); var result = Base58.TryDecode(base58, out var bytes); Assert.Equal(result, ok); Assert.Equal(hexValue, bytes); Assert.Equal(base58, Base58.Encode(bytes)); }
public async Task <string> Post([FromBody] UrlViewModel model) { long number = 0; await counterRepository.Update(Constants.DefaultPartitionKey, Constants.DefaultRowKey, (existing) => { existing.Count++; number = existing.Count; }); var encodedUrl = Base58Encoder.Encode(number); await urlRepository.Insert(new UrlEntity(encodedUrl, model.Url)); return(encodedUrl); }