Search in sources :

Example 66 with ECKey

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

the class EncryptionHandshakeTest method setUp.

@Before
public void setUp() {
    remoteKey = new ECKey();
    myKey = new ECKey();
    initiator = new EncryptionHandshake(remoteKey.getPubKeyPoint());
}
Also used : ECKey(org.ethereum.crypto.ECKey) Before(org.junit.Before)

Example 67 with ECKey

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

the class RlpxConnectionTest method setUp.

@Before
public void setUp() throws Exception {
    ECKey remoteKey = new ECKey();
    ECKey myKey = new ECKey();
    initiator = new EncryptionHandshake(remoteKey.getPubKeyPoint());
    responder = new EncryptionHandshake();
    AuthInitiateMessage initiate = initiator.createAuthInitiate(null, myKey);
    byte[] initiatePacket = initiator.encryptAuthMessage(initiate);
    byte[] responsePacket = responder.handleAuthInitiate(initiatePacket, remoteKey);
    initiator.handleAuthResponse(myKey, initiatePacket, responsePacket);
    to = new PipedInputStream(1024 * 1024);
    toOut = new PipedOutputStream(to);
    from = new PipedInputStream(1024 * 1024);
    fromOut = new PipedOutputStream(from);
    iCodec = new FrameCodec(initiator.getSecrets());
    rCodec = new FrameCodec(responder.getSecrets());
    byte[] nodeId = { 1, 2, 3, 4 };
    iMessage = new HandshakeMessage(123, "abcd", Lists.newArrayList(new Capability("zz", (byte) 1), new Capability("yy", (byte) 3)), 3333, nodeId);
}
Also used : Capability(org.ethereum.net.client.Capability) ECKey(org.ethereum.crypto.ECKey) Before(org.junit.Before)

Example 68 with ECKey

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

the class ReleaseBtcTest method releaseBtc.

@Test
public void releaseBtc() throws IOException {
    int minCentsBtc = 5;
    int maxCentsBtc = 100;
    final NetworkParameters parameters = NetworkParameters.fromID(NetworkParameters.ID_REGTEST);
    BridgeStorageProviderInitializer storageInitializer = (BridgeStorageProvider provider, Repository repository, int executionIndex) -> {
        ReleaseRequestQueue queue;
        try {
            queue = provider.getReleaseRequestQueue();
        } catch (Exception e) {
            throw new RuntimeException("Unable to gather release request queue");
        }
        for (int i = 0; i < Helper.randomInRange(10, 100); i++) {
            Coin value = Coin.CENT.multiply(Helper.randomInRange(minCentsBtc, maxCentsBtc));
            queue.add(new BtcECKey().toAddress(parameters), value);
        }
    };
    final byte[] releaseBtcEncoded = Bridge.RELEASE_BTC.encode();
    ABIEncoder abiEncoder = (int executionIndex) -> releaseBtcEncoded;
    TxBuilder txBuilder = (int executionIndex) -> {
        long satoshis = Coin.CENT.multiply(Helper.randomInRange(minCentsBtc, maxCentsBtc)).getValue();
        BigInteger weis = Denomination.satoshisToWeis(BigInteger.valueOf(satoshis));
        ECKey sender = new ECKey();
        return Helper.buildSendValueTx(sender, weis);
    };
    ExecutionStats stats = new ExecutionStats("releaseBtc");
    executeAndAverage("releaseBtc", 1000, abiEncoder, storageInitializer, txBuilder, Helper.getRandomHeightProvider(10), stats);
    BridgePerformanceTest.addStats(stats);
}
Also used : NetworkParameters(co.rsk.bitcoinj.core.NetworkParameters) BridgeStorageProvider(co.rsk.peg.BridgeStorageProvider) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) ECKey(org.ethereum.crypto.ECKey) ReleaseRequestQueue(co.rsk.peg.ReleaseRequestQueue) BtcECKey(co.rsk.bitcoinj.core.BtcECKey) IOException(java.io.IOException) Coin(co.rsk.bitcoinj.core.Coin) Repository(org.ethereum.core.Repository) BigInteger(java.math.BigInteger) Test(org.junit.Test)

Example 69 with ECKey

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

the class Web3ImplTest method importAccountUsingRawKey.

@Test
public void importAccountUsingRawKey() {
    Web3Impl web3 = createWeb3();
    ECKey eckey = new ECKey();
    String address = web3.personal_importRawKey(Hex.toHexString(eckey.getPrivKeyBytes()), "passphrase1");
    org.junit.Assert.assertNotNull(address);
    Account account0 = wallet.getAccount(new RskAddress(address));
    org.junit.Assert.assertNull(account0);
    Account account = wallet.getAccount(new RskAddress(address), "passphrase1");
    org.junit.Assert.assertNotNull(account);
    org.junit.Assert.assertEquals(address, "0x" + Hex.toHexString(account.getAddress().getBytes()));
    org.junit.Assert.assertArrayEquals(eckey.getPrivKeyBytes(), account.getEcKey().getPrivKeyBytes());
}
Also used : ECKey(org.ethereum.crypto.ECKey) Test(org.junit.Test)

Example 70 with ECKey

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

the class WorldTest method saveAndGetAccount.

@Test
public void saveAndGetAccount() {
    World world = new World();
    Account account = new Account(new ECKey(Utils.getRandom()));
    world.saveAccount("acc1", account);
    Assert.assertSame(account, world.getAccountByName("acc1"));
}
Also used : Account(org.ethereum.core.Account) 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