Beispiel #1
0
        public void TestIsValidAddress()
        {
            var address1 = "0x7567d83b7b8d80addcb281a71d54fc7b3364ffed";
            var address2 = "0x7567d83b7b8d80addcb2";
            var address3 = "hello world";

            Assert.True(SimpleWallet.IsValidAddress(address1));
            Assert.False(SimpleWallet.IsValidAddress(address2));
            Assert.False(SimpleWallet.IsValidAddress(address3));
        }
Beispiel #2
0
        public string CalculateIDWithUnsigned(string origin)
        {
            if (!SimpleWallet.IsValidAddress(origin))
            {
                throw new ArgumentException("origin expected address");
            }
            byte[]       signingHash = this.SigningHash();
            MemoryStream stream      = new MemoryStream();

            stream.Append(signingHash);
            stream.Append(origin.ToBytes());
            return(Blake2b.CalculateHash(stream.ToArray()).ToHexString());
        }
Beispiel #3
0
        public byte[] SigningHash(string delegateFor = "")
        {
            byte[] encode = RlpCode.Encode(Transaction.UnsignedRlpDefinition(), this.Body);
            byte[] hash   = Blake2b.CalculateHash(encode);

            if (delegateFor.Length != 0)
            {
                if (SimpleWallet.IsValidAddress(delegateFor))
                {
                    MemoryStream stream = new MemoryStream();
                    stream.Append(hash);
                    stream.Append(delegateFor.ToBytes());
                    return(Blake2b.CalculateHash(stream.ToArray()));
                }
                else
                {
                    throw new ArgumentException("delegateFor expected address");
                }
            }
            return(hash);
        }