Exemple #1
0
        public void Test_Rlp()
        {
            var tx = new Transaction
            {
                To       = "0x5f193b130d7c856179aa3d738ee06fab65e73147".HexToBytes().ToUInt160(),
                Value    = Money.Parse("100").ToUInt256(),
                Nonce    = 0,
                GasPrice = 5000000000,
                GasLimit = 4500000
            };
            var rlp = tx.Rlp(false);
            // This is correct rlp with chain id 25. Check here: https://toolkit.abdk.consulting/ethereum#transaction
            var expectedRlp =
                "0xee8085012a05f2008344aa20945f193b130d7c856179aa3d738ee06fab65e7314789056bc75e2d6310000080198080"
                .HexToBytes();

            Assert.IsTrue(rlp.SequenceEqual(expectedRlp));

            rlp = tx.Rlp(true);
            // This is correct rlp with chain id 225. Check here: https://toolkit.abdk.consulting/ethereum#transaction
            expectedRlp =
                "0xef8085012a05f2008344aa20945f193b130d7c856179aa3d738ee06fab65e7314789056bc75e2d631000008081e18080"
                .HexToBytes();
            Assert.IsTrue(rlp.SequenceEqual(expectedRlp));
        }
Exemple #2
0
        public void Test_External_Signature2()
        {
            var crypto = CryptoProvider.GetCrypto();

            var rawTx =
                "0xf86d808504a817c800832dc6c0948e7b7262e0fa4616566591d51f998f16a79fb547880de0b6b3a76400008025a0115105d96a43f41a5ea562bb3e591cbfa431a8cdae9c3030457adca2cb854f78a012fb41922c53c73473563003667ed8e783359c91d95b42301e1955d530b1ca33";

            var ethTx = new TransactionChainId(rawTx.HexToBytes());

            Console.WriteLine("ETH RLP: " + ethTx.GetRLPEncodedRaw().ToHex());

            var nonce = ethTx.Nonce.ToHex();

            Console.WriteLine("Nonce " + nonce);
            Console.WriteLine("ChainId " + Convert.ToUInt64(ethTx.ChainId.ToHex(), 16));

            var tx = new Transaction
            {
                To       = ethTx.ReceiveAddress.ToUInt160(),
                Value    = ethTx.Value.ToUInt256(true),
                Nonce    = Convert.ToUInt64(ethTx.Nonce.ToHex(), 16),
                GasPrice = Convert.ToUInt64(ethTx.GasPrice.ToHex(), 16),
                GasLimit = Convert.ToUInt64(ethTx.GasLimit.ToHex(), 16)
            };

            Console.WriteLine("RLP: " + tx.Rlp(true).ToHex());

            var address = ethTx.Key.GetPublicAddress().HexToBytes();
            var from    = ethTx.Key.GetPublicAddress().HexToBytes().ToUInt160();

            Console.WriteLine(address.ToHex());

            var r         = "0x115105d96a43f41a5ea562bb3e591cbfa431a8cdae9c3030457adca2cb854f78".HexToBytes();
            var s         = "0x12fb41922c53c73473563003667ed8e783359c91d95b42301e1955d530b1ca33".HexToBytes();
            var v         = "0x25".HexToBytes();
            var signature = r.Concat(s).Concat(v).ToArray();

            Console.WriteLine(signature.ToHex());

            var message =
                "0xed808504a817c800832dc6c0948e7b7262e0fa4616566591d51f998f16a79fb547880de0b6b3a764000080018080"
                .HexToBytes().KeccakBytes();

            var recoveredPubkey = crypto.RecoverSignatureHashed(message, signature, false);

            Console.WriteLine(recoveredPubkey.ToHex());

            var addr = crypto.ComputeAddress(recoveredPubkey);
            var same = addr.SequenceEqual(from.ToBytes());

            Console.WriteLine(addr.ToHex());
            Console.WriteLine(same);
        }