Search in sources :

Example 6 with ECKey

use of org.ethereum.crypto.ECKey in project rskj by rsksmart.

the class RskForksBridgeTest method buildUpdateCollectionsTx.

private Transaction buildUpdateCollectionsTx() {
    long nonce = 0;
    long value = 0;
    BigInteger gasPrice = BigInteger.valueOf(0);
    BigInteger gasLimit = BigInteger.valueOf(100000);
    Transaction rskTx = CallTransaction.createCallTransaction(config, nonce, gasPrice.longValue(), gasLimit.longValue(), PrecompiledContracts.BRIDGE_ADDR, value, Bridge.UPDATE_COLLECTIONS);
    rskTx.sign(new ECKey().getPrivKeyBytes());
    return rskTx;
}
Also used : BigInteger(java.math.BigInteger) ECKey(org.ethereum.crypto.ECKey)

Example 7 with ECKey

use of org.ethereum.crypto.ECKey in project rskj by rsksmart.

the class RskForksBridgeTest method before.

@Before
public void before() throws IOException, ClassNotFoundException {
    World world = new World();
    blockChain = world.getBlockChain();
    repository = blockChain.getRepository();
    whitelistManipulationKey = ECKey.fromPrivate(Hex.decode("3890187a3071327cee08467ba1b44ed4c13adb2da0d5ffcc0563c371fa88259c"));
    genesis = (Genesis) blockChain.getBestBlock();
    keyHoldingRSKs = new ECKey();
    co.rsk.core.Coin balance = new co.rsk.core.Coin(new BigInteger("10000000000000000000"));
    repository.addBalance(new RskAddress(keyHoldingRSKs.getAddress()), balance);
    genesis.setStateRoot(repository.getRoot());
    genesis.flushRLP();
    blockChain.getBlockStore().saveBlock(genesis, genesis.getCumulativeDifficulty(), true);
    Transaction whitelistAddressTx = buildWhitelistTx();
    Transaction receiveHeadersTx = buildReceiveHeadersTx();
    Transaction registerBtctransactionTx = buildRegisterBtcTransactionTx();
    blockBase = buildBlock(genesis, whitelistAddressTx, receiveHeadersTx, registerBtctransactionTx);
    Assert.assertEquals(ImportResult.IMPORTED_BEST, blockChain.tryToConnect(blockBase));
}
Also used : org.ethereum.core(org.ethereum.core) Coin(co.rsk.bitcoinj.core.Coin) RskAddress(co.rsk.core.RskAddress) BigInteger(java.math.BigInteger) ECKey(org.ethereum.crypto.ECKey) World(co.rsk.test.World) Before(org.junit.Before)

Example 8 with ECKey

use of org.ethereum.crypto.ECKey in project rskj by rsksmart.

the class CryptoTestCase method execute.

public void execute() {
    byte[] key = Hex.decode(this.key);
    byte[] cipher = Hex.decode(this.cipher);
    ECKey ecKey = ECKey.fromPrivate(key);
    byte[] resultPayload = new byte[0];
    if (decryption_type.equals("aes_ctr"))
        resultPayload = ecKey.decryptAES(cipher);
    if (decryption_type.equals("ecies_sec1_altered"))
        try {
            resultPayload = ECIESCoder.decrypt(new BigInteger(Hex.toHexString(key), 16), cipher);
        } catch (Throwable e) {
            e.printStackTrace();
        }
    if (!Hex.toHexString(resultPayload).equals(payload)) {
        String error = String.format("payload should be: %s, but got that result: %s  ", payload, Hex.toHexString(resultPayload));
        logger.info(error);
        System.exit(-1);
    }
}
Also used : BigInteger(java.math.BigInteger) ECKey(org.ethereum.crypto.ECKey)

Example 9 with ECKey

use of org.ethereum.crypto.ECKey in project rskj by rsksmart.

the class TransactionsMessageTest method test_3.

@Test
public /* Transactions msg encode */
void test_3() throws Exception {
    String expected = "f872f870808609184e72a0008242559479b08ad8787060333663d19704909ee7b1903e588b00d3c21bcecceda1000000801ca07c3f47d609d453737ddcf7c403190f67432c41e1f26051296b24e4e10a837083a0375fdb6d3b82dae7e1e78aa7d7413d0bfefeb05341058361d2b5a53d9c8783d6";
    BigInteger value = new BigInteger("1000000000000000000000000");
    byte[] privKey = HashUtil.keccak256("cat".getBytes());
    ECKey ecKey = ECKey.fromPrivate(privKey);
    byte[] gasPrice = Hex.decode("09184e72a000");
    byte[] gasLimit = Hex.decode("4255");
    Transaction tx = new Transaction(null, gasPrice, gasLimit, ecKey.getAddress(), value.toByteArray(), null);
    tx.sign(privKey);
    tx.getEncoded();
    TransactionsMessage transactionsMessage = new TransactionsMessage(config, Collections.singletonList(tx));
    assertEquals(expected, Hex.toHexString(transactionsMessage.getEncoded()));
}
Also used : Transaction(org.ethereum.core.Transaction) TransactionsMessage(org.ethereum.net.eth.message.TransactionsMessage) BigInteger(java.math.BigInteger) ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 10 with ECKey

use of org.ethereum.crypto.ECKey in project rskj by rsksmart.

the class TransactionTest method test1.

@Test
public /* sign transaction  https://tools.ietf.org/html/rfc6979 */
void test1() throws NoSuchProviderException, NoSuchAlgorithmException, InvalidKeyException, IOException {
    // python taken exact data
    String txRLPRawData = "a9e880872386f26fc1000085e8d4a510008203e89413978aee95f38490e9769c39b2773ed763d9cd5f80";
    // String txRLPRawData = "f82804881bc16d674ec8000094cd2a3d9f938e13cd947ec05abc7fe734df8dd8268609184e72a0006480";
    byte[] cowPrivKey = Hex.decode("c85ef7d79691fe79573b1a7064c19c1a9819ebdbd1faaab1a8ec92344438aaf4");
    ECKey key = ECKey.fromPrivate(cowPrivKey);
    byte[] data = Hex.decode(txRLPRawData);
    // step 1: serialize + RLP encode
    // step 2: hash = sha3(step1)
    byte[] txHash = HashUtil.keccak256(data);
    String signature = key.doSign(txHash).toBase64();
    System.out.println(signature);
}
Also used : ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Aggregations

ECKey (org.ethereum.crypto.ECKey)76 Test (org.junit.Test)43 BigInteger (java.math.BigInteger)17 NodeDistanceTable (co.rsk.net.discovery.table.NodeDistanceTable)10 ArrayList (java.util.ArrayList)10 Node (org.ethereum.net.rlpx.Node)10 InetSocketAddress (java.net.InetSocketAddress)9 Transaction (org.ethereum.core.Transaction)8 BlockGenerator (co.rsk.blockchain.utils.BlockGenerator)7 RepositoryImpl (co.rsk.db.RepositoryImpl)7 SimpleRskTransaction (co.rsk.peg.simples.SimpleRskTransaction)7 Channel (io.netty.channel.Channel)7 org.ethereum.core (org.ethereum.core)7 co.rsk.bitcoinj.core (co.rsk.bitcoinj.core)6 BridgeEventLogger (co.rsk.peg.utils.BridgeEventLogger)6 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)6 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 BlockChainBuilder (co.rsk.test.builders.BlockChainBuilder)4 Account (org.ethereum.core.Account)4 RskAddress (co.rsk.core.RskAddress)3