use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class Web3ImplTest method dumpRawKey.
@Test
public void dumpRawKey() throws Exception {
Web3Impl web3 = createWeb3();
ECKey eckey = new ECKey();
String address = web3.personal_importRawKey(Hex.toHexString(eckey.getPrivKeyBytes()), "passphrase1");
org.junit.Assert.assertTrue(web3.personal_unlockAccount(address, "passphrase1", ""));
String rawKey = web3.personal_dumpRawKey(address).substring(2);
org.junit.Assert.assertArrayEquals(eckey.getPrivKeyBytes(), Hex.decode(rawKey));
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class RLPDump method dumpTest.
@Test
public void dumpTest() {
System.out.println(Hex.toHexString(new ECKey().getPubKey()));
String hexRlp = "f872f870845609a1ba64c0b8660480136e573eb81ac4a664f8f76e4887ba927f791a053ec5ff580b1037a8633320ca70f8ec0cdea59167acaa1debc07bc0a0b3a5b41bdf0cb4346c18ddbbd2cf222f54fed795dde94417d2e57f85a580d87238efc75394ca4a92cfe6eb9debcc3583c26fee8580";
System.out.println(dump(RLP.decode2(Hex.decode(hexRlp)), 0));
hexRlp = "f8d1f8cf845605846c3cc58479a94c49b8c0800b0b2d39d7c59778edb5166bfd0415c5e02417955ef4ef7f7d8c1dfc7f59a0141d97dd798bde6b972090390758b67457e93c2acb11ed4941d4443f87cedbc09c1b0476ca17f4f04da3d69cfb6470969f73d401ee7692293a00a2ff2d7f3fac87d43d85aed19c9e6ecbfe7e5f8268209477ffda58c7a481eec5c50abd313d10b6554e6e04a04fd93b9bf781d600f4ceb3060002ce1eddbbd51a9a902a970d9b41a9627141c0c52742b1179d83e17f1a273adf0a4a1d0346c68686a51428dd9a01";
System.out.println(dump(RLP.decode2(Hex.decode(hexRlp)), 0));
hexRlp = "dedd84560586f03cc58479a94c498e0c48656c6c6f205768697370657281bc";
System.out.println(dump(RLP.decode2(Hex.decode(hexRlp)), 0));
hexRlp = "dedd84560586f03cc58479a94c498e0c48656c6c6f205768697370657281bc";
System.out.println(dump(RLP.decode2(Hex.decode(hexRlp)), 0));
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class AccountBuilder method build.
public Account build() {
byte[] privateKeyBytes = HashUtil.keccak256(name.getBytes());
ECKey key = ECKey.fromPrivate(privateKeyBytes);
Account account = new Account(key);
if (blockChain != null) {
Block best = blockChain.getStatus().getBestBlock();
BlockDifficulty td = blockChain.getStatus().getTotalDifficulty();
Repository repository = blockChain.getRepository();
Repository track = repository.startTracking();
track.createAccount(account.getAddress());
if (this.balance != null)
track.addBalance(account.getAddress(), this.balance);
if (this.code != null)
track.saveCode(account.getAddress(), this.code);
track.commit();
best.setStateRoot(repository.getRoot());
best.flushRLP();
blockChain.getBlockStore().saveBlock(best, td, true);
}
return account;
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class EncryptionHandshake method makeAuthInitiateV4.
AuthResponseMessageV4 makeAuthInitiateV4(AuthInitiateMessageV4 initiate, ECKey key) {
initiatorNonce = initiate.nonce;
remotePublicKey = initiate.publicKey;
BigInteger secretScalar = remotePublicKey.multiply(key.getPrivKey()).normalize().getXCoord().toBigInteger();
byte[] token = ByteUtil.bigIntegerToBytes(secretScalar, NONCE_SIZE);
byte[] signed = xor(token, initiatorNonce);
ECKey ephemeral = ECKey.recoverFromSignature(recIdFromSignatureV(initiate.signature.v), initiate.signature, signed, false);
if (ephemeral == null) {
throw new RuntimeException("failed to recover signatue from message");
}
remoteEphemeralKey = ephemeral.getPubKeyPoint();
AuthResponseMessageV4 response = new AuthResponseMessageV4();
response.ephemeralPublicKey = ephemeralKey.getPubKeyPoint();
response.nonce = responderNonce;
return response;
}
use of org.ethereum.crypto.ECKey in project rskj by rsksmart.
the class BlockEncodingTest method testBadBlockEncoding1.
@Test(expected = ArithmeticException.class)
public void testBadBlockEncoding1() {
List<Transaction> txs = new ArrayList<>();
Transaction tx = new Transaction(BigInteger.ZERO.toByteArray(), BigInteger.ONE.toByteArray(), BigInteger.valueOf(21000).toByteArray(), new ECKey().getAddress(), BigInteger.valueOf(1000).toByteArray(), null);
txs.add(tx);
byte[] bigBadByteArray = new byte[10000];
Arrays.fill(bigBadByteArray, (byte) -1);
FreeBlock fblock = new FreeBlock(// parent hash
PegTestUtils.createHash3().getBytes(), // uncle hash
EMPTY_LIST_HASH, // coinbase
TestUtils.randomAddress().getBytes(), // logs bloom
new Bloom().getData(), // difficulty
BigInteger.ONE.toByteArray(), bigBadByteArray, // gasLimit
bigBadByteArray, // gasUsed
bigBadByteArray, // timestamp
bigBadByteArray, // extraData
new byte[0], // mixHash
new byte[0], // provisory nonce
new byte[] { 0 }, // receipts root
HashUtil.EMPTY_TRIE_HASH, // transaction root
BlockChainImpl.calcTxTrie(txs), // EMPTY_TRIE_HASH, // state root
HashUtil.EMPTY_TRIE_HASH, // transaction list
txs, // uncle list
null, BigInteger.TEN.toByteArray(), new byte[0]);
// Now decode, and re-encode
Block parsedBlock = new Block(fblock.getEncoded());
// must throw java.lang.ArithmeticException
// forced parse
parsedBlock.getGasLimit();
}
Aggregations