Exemplo n.º 1
0
        public static int VerifyAddress(String address)
        {
            if (!address.StartsWith("1") && !address.StartsWith("WX") && !address.StartsWith("WR"))
            {
                return(-1);
            }
            byte[] r5;
            if (address.StartsWith("1"))
            {
                r5 = Base58Check.Decode(address);
            }
            else
            {
                r5 = Base58Check.Decode(address.Substring(2));
            }
            Sha3Keccack sha3Keccack = Sha3Keccack.Current;

            byte[] r3  = sha3Keccack.CalculateHash(sha3Keccack.CalculateHash(AddressToPubkeyHashByteArray(address)));
            byte[] b4  = Utils.CopyByteArray(r3, 0, 4);
            byte[] _b4 = Utils.CopyByteArray(r5, r5.Length - 4, 4);
            if (Array.Equals(b4, _b4))
            {
                return(0);
            }
            else
            {
                return(-2);
            }
        }
Exemplo n.º 2
0
        public static string PubkeyHashToAddress(byte[] publicHash)
        {
            Sha3Keccack sha3Keccack = Sha3Keccack.Current;

            byte[] r1 = publicHash;
            byte[] r2 = Utils.prepend(r1, (byte)0x00);
            byte[] r3 = sha3Keccack.CalculateHash(sha3Keccack.CalculateHash(r1));
            byte[] b4 = Utils.CopyByteArray(r3, 0, 4);
            byte[] b5 = Utils.Combine(r2, b4);
            string s6 = "WX" + Base58Check.Encode(b5);

            return(s6);
        }
Exemplo n.º 3
0
 private static byte[] AddressToPubkeyHashByteArray(string address)
 {
     byte[] r5;
     if (address.StartsWith("1"))
     {
         r5 = Base58Check.Decode(address);
     }
     else
     {
         r5 = Base58Check.Decode(address.Substring(2));
     }
     byte[] r2 = Utils.CopyByteArray(r5, 0, 21);
     byte[] r1 = Utils.CopyByteArray(r2, 1, 20);
     return(r1);
 }
Exemplo n.º 4
0
 public void TestBase58WithEverything()
 {
     Assert.Equal("5T", Base58Check.Encode(new byte[] { 0x01, 0x02 }));
     Assert.Equal(new byte[] { 0x01, 0x02 }, Base58Check.Decode("5T"));
 }