private static string GetHash(Guid guid, string coinAdapterAddress, string fromAddress, string toAddress, BigInteger currentBalance)
 {
     return(EthUtils.GuidToByteArray(guid).ToHex() +
            coinAdapterAddress.HexToByteArray().ToHex() +
            fromAddress.HexToByteArray().ToHex() +
            toAddress.HexToByteArray().ToHex() +
            EthUtils.BigIntToArrayWithPadding(currentBalance).ToHex());
 }
        public byte[] GetHash(Guid id, string coinAddress, string clientAddr, string toAddr, BigInteger amount)
        {
            var strForHash = EthUtils.GuidToByteArray(id).ToHex() +
                             coinAddress.HexToByteArray().ToHex() +
                             clientAddr.HexToByteArray().ToHex() +
                             toAddr.HexToByteArray().ToHex() +
                             EthUtils.BigIntToArrayWithPadding(amount).ToHex();

            var hash = new Sha3Keccack().CalculateHash(strForHash.HexToByteArray());

            return(hash);
        }
Beispiel #3
0
        public void Test22()
        {
            var guid = new Guid("0b67caf2-0b02-4691-ac25-04858b0fa475");

            var strForHash = EthUtils.GuidToByteArray(guid).ToHex() +
                             "0x8c32ad594a6dc17b2e8b40af3df2c3ce1f79cdd4".HexToByteArray().ToHex() +
                             "0x5c711f0bfad342c4691b6e23cedcdf39e3fe03c1".HexToByteArray().ToHex() +
                             "0x33f53d968aee3cfe1ad460457a29827bfff33d8c".HexToByteArray().ToHex() +
                             EthUtils.BigIntToArrayWithPadding(9500).ToHex();

            var hash = new Sha3Keccack().CalculateHash(strForHash.HexToByteArray());

            var sign = Sign(hash, "0x443dac9b6e682a887009cfd00690d0cac1905e494f84d03070174149c2d0cc76").ToHex();

            Assert.AreEqual("6ddfe17c1ff216df529277ff7fc94bff41b6984d3de36d2132f452986743de4c44831c1bd41d58043705a60aa853d6beeb8b2e0dcdb09805c5dd28b7e3e705ce1b", sign);
        }
Beispiel #4
0
        public void TestHash()
        {
            var guid       = Guid.NewGuid();
            var amount     = 100;
            var strForHash = EthUtils.GuidToByteArray(guid).ToHex() +
                             _tokenAdapterAddress.HexToByteArray().ToHex() +
                             _clientA.HexToByteArray().ToHex() +
                             _clientB.HexToByteArray().ToHex() +
                             EthUtils.BigIntToArrayWithPadding(new BigInteger(amount)).ToHex();

            byte[] expectedHash = new Sha3Keccack().CalculateHash(strForHash.HexToByteArray());
            byte[] actualHash   = _hashCalculator.GetHash(guid, _tokenAdapterAddress, _clientA, _clientB, amount);
            bool   isEqual      = Enumerable.SequenceEqual(expectedHash, actualHash);

            Assert.IsTrue(isEqual);
        }
        public async Task TestCheckSign_IsWrong()
        {
            var guid   = Guid.NewGuid();
            var amount = 50;

            EthUtils.GuidToBigInteger(guid);
            var strForHash = EthUtils.GuidToByteArray(guid).ToHex() +
                             _ethereumAdapterAddress.HexToByteArray().ToHex() +
                             _clientA.HexToByteArray().ToHex() +
                             _clientA.HexToByteArray().ToHex() +
                             EthUtils.BigIntToArrayWithPadding(new BigInteger(amount)).ToHex();

            var hash   = new Sha3Keccack().CalculateHash(strForHash.HexToByteArray());
            var sign   = Sign(hash, _privateKeyA).ToHex();
            var result = _exchangeService.CheckSign(guid, _ethereumAdapterAddress, _clientA, _clientA, new BigInteger(amount - 1), sign);

            Assert.IsFalse(result);
        }
        public async Task TestCheckSign_IsCorrect()
        {
            var guid   = Guid.NewGuid();
            var amount = 50;

            EthUtils.GuidToBigInteger(guid);
            var strForHash = EthUtils.GuidToByteArray(guid).ToHex() +
                             _tokenAdapterAddress.HexToByteArray().ToHex() +
                             _clientA.HexToByteArray().ToHex() +
                             _clientA.HexToByteArray().ToHex() +
                             EthUtils.BigIntToArrayWithPadding(new BigInteger(amount)).ToHex();

            var hash = new Sha3Keccack().CalculateHash(strForHash.HexToByteArray());
            var sign = Sign(hash, _privateKeyA).ToHex();
            //var externalSign = await _exchangeService.GetSign(guid, _tokenAdapterAddress, ClientA, ClientA, new BigInteger(amount));
            var result = _exchangeService.CheckSign(guid, _tokenAdapterAddress, _clientA, _clientA, new BigInteger(amount), sign);

            Assert.IsTrue(result);
        }