Exemplo n.º 1
0
        public void Test_eip155_for_the_first_ropsten_transaction()
        {
            Transaction tx = Rlp.Decode <Transaction>(new Rlp(Bytes.FromHexString("0xf85f808082520894353535353535353535353535353535353535353580801ca08d24b906be2d91a0bf2168862726991cc408cddf94cb087b392ce992573be891a077964b4e55a5c8ec7b85087d619c641c06def33ab052331337ca9efcd6b82aef")));

            Assert.AreEqual(new Keccak("0x5fd225549ed5c587c843e04578bdd4240fc0d7ab61f8e9faa37e84ec8dc8766d"), tx.Hash, "hash");
            EthereumSigner signer = new EthereumSigner(RopstenSpecProvider.Instance, NullLogManager.Instance);
            Address        from   = signer.RecoverAddress(tx, 11);

            Assert.AreEqual(new Address("0x874b54a8bd152966d63f706bae1ffeb0411921e5"), from, "from");
        }
Exemplo n.º 2
0
        public void Sign_and_recover()
        {
            EthereumSigner ethereumSigner = new EthereumSigner(OlympicSpecProvider.Instance, NullLogManager.Instance);

            Keccak     message    = Keccak.Compute("Test message");
            PrivateKey privateKey = new PrivateKey(_cryptoRandom.GenerateRandomBytes(32));
            Signature  signature  = ethereumSigner.Sign(privateKey, message);

            Assert.AreEqual(privateKey.Address, ethereumSigner.RecoverAddress(signature, message));
        }
Exemplo n.º 3
0
        public void Sign_and_recover()
        {
            EthereumSigner ethereumSigner = new EthereumSigner(OlympicSpecProvider.Instance, NullLogManager.Instance);

            Keccak     message    = Keccak.Compute("Test message");
            PrivateKey privateKey = Build.A.PrivateKey.TestObject;
            Signature  signature  = ethereumSigner.Sign(privateKey, message);

            Assert.AreEqual(privateKey.Address, ethereumSigner.RecoverAddress(signature, message));
        }
Exemplo n.º 4
0
        public void Signature_test_olympic(int blockNumber)
        {
            EthereumSigner signer = new EthereumSigner(OlympicSpecProvider.Instance, NullLogManager.Instance);
            PrivateKey     key    = Build.A.PrivateKey.TestObject;
            Transaction    tx     = Build.A.Transaction.TestObject;

            signer.Sign(key, tx, blockNumber);
            Address address = signer.RecoverAddress(tx, blockNumber);

            Assert.AreEqual(key.Address, address);
        }
Exemplo n.º 5
0
        public void Sign_goerli()
        {
            EthereumSigner signer = new EthereumSigner(GoerliSpecProvider.Instance, LimboLogs.Instance);
            PrivateKey     key    = Build.A.PrivateKey.TestObject;
            Transaction    tx     = Build.A.Transaction.TestObject;

            signer.Sign(key, tx, 1);
            Address address = signer.RecoverAddress(tx, 1);

            Assert.AreEqual(key.Address, address);
        }
Exemplo n.º 6
0
        public void Signature_test_ropsten(uint blockNumber)
        {
            EthereumSigner signer = new EthereumSigner(RopstenSpecProvider.Instance, LimboLogs.Instance);
            PrivateKey     key    = Build.A.PrivateKey.TestObject;
            Transaction    tx     = Build.A.Transaction.TestObject;

            signer.Sign(key, tx, blockNumber);
            Address address = signer.RecoverAddress(tx, blockNumber);

            Assert.AreEqual(key.Address, address);
        }
Exemplo n.º 7
0
        public void Can_sign()
        {
            EthereumSigner signer = new EthereumSigner(new SingleReleaseSpecProvider(LatestRelease.Instance, 99), NullLogManager.Instance);
            DevWallet      wallet = new DevWallet(NullLogManager.Instance);

            for (int i = 1; i <= 10; i++)
            {
                Address   signerAddress = wallet.GetAccounts()[0];
                Signature sig           = wallet.Sign(signerAddress, TestObject.KeccakA);
                Address   recovered     = signer.RecoverAddress(sig, TestObject.KeccakA);
                Assert.AreEqual(signerAddress, recovered, $"{i}");
            }
        }
Exemplo n.º 8
0
        public void Can_sign_on_networks_with_chain_id(DevWalletType walletType)
        {
            const int      networkId = 40000;
            EthereumSigner signer    = new EthereumSigner(new SingleReleaseSpecProvider(LatestRelease.Instance, networkId), NullLogManager.Instance);
            IWallet        wallet    = SetupWallet(walletType);

            for (int i = 1; i <= (walletType == DevWalletType.Memory ? 10 : 3); i++)
            {
                Address     signerAddress = wallet.GetAccounts()[0];
                Transaction tx            = new Transaction();
                tx.SenderAddress = signerAddress;

                wallet.Sign(tx, networkId);
                Address recovered = signer.RecoverAddress(tx, networkId);
                Assert.AreEqual(signerAddress, recovered, $"{i}");
                Assert.AreEqual(networkId, tx.Signature.GetChainId, "chainId");
            }
        }
        public (byte[], bool) Run(byte[] inputData)
        {
            inputData = (inputData ?? Bytes.Empty).PadRight(128);

            Keccak hash = new Keccak(inputData.Slice(0, 32));

            byte[] vBytes = inputData.Slice(32, 32);
            byte[] r      = inputData.Slice(64, 32);
            byte[] s      = inputData.Slice(96, 32);

            // TEST: CALLCODEEcrecoverV_prefixedf0_d0g0v0
            // TEST: CALLCODEEcrecoverV_prefixedf0_d1g0v0
            for (int i = 0; i < 31; i++)
            {
                if (vBytes[i] != 0)
                {
                    return(Bytes.Empty, true);
                }
            }

            byte v = vBytes[31];

            if (v != 27 && v != 28)
            {
                return(Bytes.Empty, true);
            }

            Signature signature = new Signature(r, s, v);
            Address   recovered = _signer.RecoverAddress(signature, hash);

            if (recovered == null)
            {
                return(Bytes.Empty, true);
            }

            return(((byte[])recovered.Hex).PadLeft(32), true);  // TODO: change recovery code to return bytes?
        }