Пример #1
0
        public virtual void ShouldEncodeSha3UsingTypes()
        {
            //0x407D73d8a49eeb85D32Cf465507dd71d507100c1
            var abiEncode = new ABIEncode();

            Assert.Equal("4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b",
                         abiEncode.GetSha3ABIEncodedPacked(new ABIValue("address", "0x407D73d8a49eeb85D32Cf465507dd71d507100c1"))
                         .ToHex());

            Assert.Equal("4e8ebbefa452077428f93c9520d3edd60594ff452a29ac7d2ccc11d47f3ab95b",
                         abiEncode.GetSha3ABIEncodedPacked(new ABIValue("bytes",
                                                                        "0x407D73d8a49eeb85D32Cf465507dd71d507100c1".HexToByteArray())).ToHex());

            //bytes32 it is a 32 bytes array so it will be padded with 00 values
            Assert.Equal("3c69a194aaf415ba5d6afca734660d0a3d45acdc05d54cd1ca89a8988e7625b4",
                         abiEncode.GetSha3ABIEncodedPacked(new ABIValue("bytes32",
                                                                        "0x407D73d8a49eeb85D32Cf465507dd71d507100c1".HexToByteArray())).ToHex());

            //web3.utils.soliditySha3({t: 'string', v: 'Hello!%'}, {t: 'int8', v:-23}, {t: 'address', v: '0x85F43D8a49eeB85d32Cf465507DD71d507100C1d'});
            var result =
                abiEncode.GetSha3ABIEncodedPacked(
                    new ABIValue("string", "Hello!%"), new ABIValue("int8", -23),
                    new ABIValue("address", "0x85F43D8a49eeB85d32Cf465507DD71d507100C1d"));

            Assert.Equal("0xa13b31627c1ed7aaded5aecec71baf02fe123797fffd45e662eac8e06fbe4955", result.ToHex(true));
        }
Пример #2
0
        public virtual void ShouldEncodeSha3UsingDefaultValuesIntAsBigInt()
        {
            var abiEncode = new ABIEncode();
            var result    = abiEncode.GetSha3ABIEncodedPacked(new BigInteger(234564535),
                                                              "0xfff23243".HexToByteArray(), true, new BigInteger(-10));

            Assert.Equal("3e27a893dc40ef8a7f0841d96639de2f58a132be5ae466d40087a2cfa83b7179", result.ToHex());

            var result2 = abiEncode.GetSha3ABIEncodedPacked("Hello!%");

            Assert.Equal("661136a4267dba9ccdf6bfddb7c00e714de936674c4bdb065a531cf1cb15c7fc", result2.ToHex());

            var result3 = abiEncode.GetSha3ABIEncodedPacked(new BigInteger(234));

            Assert.Equal("61c831beab28d67d1bb40b5ae1a11e2757fa842f031a2d0bc94a7867bc5d26c2", result3.ToHex());
        }
Пример #3
0
        private string getGluwacoinReserveTxnSignature(
            ECurrency currency,
            string address,
            string amount,
            string fee,
            string target,
            string executor,
            BigInteger nonce,
            BigInteger expiryBlockNumber,
            string privateKey)
        {
            BigInteger convertAmount = BigInteger.Zero;
            BigInteger convertFee    = BigInteger.Zero;

            if (currency.IsGluwacoinSideChainCurrency())
            {
                convertAmount = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(amount, currency);
                convertFee    = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(fee, currency);
            }
            else
            {
                convertAmount = GluwacoinConverter.ConvertToGluwacoinBigInteger(amount);
                convertFee    = GluwacoinConverter.ConvertToGluwacoinBigInteger(fee);
            }

            ABIEncode abiEncode = new ABIEncode();

            byte[] messageHash = abiEncode.GetSha3ABIEncodedPacked(
                new ABIValue("address", GluwaService.getGluwacoinContractAddress(currency, mEnv)),
                new ABIValue("address", address),
                new ABIValue("address", target),
                new ABIValue("address", executor),
                new ABIValue("uint256", convertAmount),
                new ABIValue("uint256", convertFee),
                new ABIValue("uint256", nonce),
                new ABIValue("uint256", expiryBlockNumber)
                );

            EthereumMessageSigner signer = new EthereumMessageSigner();
            string signature             = signer.Sign(messageHash, privateKey);

            return(signature);
        }
Пример #4
0
        private string getGluwacoinTransactionSignature(ECurrency currency, string amount, string fee, string nonce, string address, string target, string privateKey)
        {
            BigInteger convertAmount = BigInteger.Zero;
            BigInteger convertFee    = BigInteger.Zero;

            if (currency.IsGluwacoinSideChainCurrency())
            {
                if (currency == ECurrency.sNGNG)
                {
                    convertAmount = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(amount, currency);
                    convertFee    = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(fee.ToString(), currency);
                }
                else if (currency == ECurrency.sUSDCG)
                {
                    convertAmount = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(amount, currency);
                    convertFee    = GluwacoinConverter.ConvertToGluwacoinSideChainBigInteger(fee.ToString(), currency);
                }
            }
            else
            {
                convertAmount = GluwacoinConverter.ConvertToGluwacoinBigInteger(amount);
                convertFee    = GluwacoinConverter.ConvertToGluwacoinBigInteger(fee.ToString());
            }

            ABIEncode abiEncode = new ABIEncode();

            byte[] messageHash = abiEncode.GetSha3ABIEncodedPacked(
                new ABIValue("address", GluwaService.getGluwacoinContractAddress(currency, mEnv)),
                new ABIValue("address", address),
                new ABIValue("address", target),
                new ABIValue("uint256", convertAmount),
                new ABIValue("uint256", convertFee),
                new ABIValue("uint256", BigInteger.Parse(nonce))
                );

            EthereumMessageSigner signer = new EthereumMessageSigner();
            string signature             = signer.Sign(messageHash, privateKey);

            return(signature);
        }
Пример #5
0
        private byte[] GetApprovalData(
            TransactionInput transaction,
            BigInteger txFee,
            BigInteger gasPrice,
            BigInteger gasLimit,
            BigInteger nonce,
            string relayHubAddress,
            string relayAddress)
        {
            var abiEncode = new ABIEncode();

            return(abiEncode.GetSha3ABIEncodedPacked(
                       new ABIValue("address", relayAddress),
                       new ABIValue("address", transaction.From),
                       new ABIValue("bytes", transaction.Data.HexToByteArray()),
                       new ABIValue("uint256", txFee),
                       new ABIValue("uint256", gasPrice),
                       new ABIValue("uint256", gasLimit),
                       new ABIValue("uint256", nonce),
                       new ABIValue("address", relayHubAddress),
                       new ABIValue("address", transaction.To)));
        }