Search in sources :

Example 31 with ECKey

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

the class GenNodeKeyId method main.

public static void main(String[] args) {
    String generator = "";
    if (args.length > 0) {
        generator = args[0];
    }
    ECKey key;
    if (generator.equals("")) {
        key = new ECKey();
    } else {
        key = ECKey.fromPrivate(HashUtil.keccak256(generator.getBytes(StandardCharsets.UTF_8)));
    }
    String keybytes = Hex.toHexString(key.getPrivKeyBytes());
    String pubkeybytes = Hex.toHexString(key.getPubKey());
    String compressedpubkeybytes = Hex.toHexString(key.getPubKey(true));
    String address = Hex.toHexString(key.getAddress());
    String nodeid = Hex.toHexString(key.getNodeId());
    System.out.println('{');
    System.out.println("   \"privateKey\": \"" + keybytes + "\",");
    System.out.println("   \"publicKey\": \"" + pubkeybytes + "\",");
    System.out.println("   \"publicKeyCompressed\": \"" + compressedpubkeybytes + "\",");
    System.out.println("   \"address\": \"" + address + "\",");
    System.out.println("   \"nodeId\": \"" + nodeid + "\"");
    System.out.println('}');
}
Also used : ECKey(org.ethereum.crypto.ECKey)

Example 32 with ECKey

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

the class Wallet method addAccount.

public RskAddress addAccount() {
    Account account = new Account(new ECKey());
    saveAccount(account);
    return account.getAddress();
}
Also used : Account(org.ethereum.core.Account) ECKey(org.ethereum.crypto.ECKey)

Example 33 with ECKey

use of org.ethereum.crypto.ECKey in project account-identity by cryptofiat.

the class EthereumService method transferAccountApprovalRight.

public void transferAccountApprovalRight(String newAddress) throws IOException {
    newAddress = with0x(newAddress);
    ECKey approver = getAccountApproverKey();
    String txHash = sendTransaction(approver, appointAccountApproverFunction.encode(newAddress));
    log.info("Account approval right transferred to " + newAddress + ". You must change your account approver key file accordingly. TxHash=" + txHash);
}
Also used : ECKey(org.ethereum.crypto.ECKey)

Example 34 with ECKey

use of org.ethereum.crypto.ECKey in project account-identity by cryptofiat.

the class EthereumService method sendBalance.

public String sendBalance(String toAddress, String privKey, int nonceIncrement) throws IOException {
    ECKey signer = ECKey.fromPrivate(Hex.decode(without0x(privKey)));
    WalletServerAccountResponse addrDetails = wsService.getAccount(hex(signer.getAddress()));
    return sendBalance(toAddress, privKey, nonceIncrement, addrDetails.getBalance());
}
Also used : WalletServerAccountResponse(eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse) ECKey(org.ethereum.crypto.ECKey)

Example 35 with ECKey

use of org.ethereum.crypto.ECKey in project account-identity by cryptofiat.

the class EthereumService method sendBalance.

public String sendBalance(String toAddress, String privKey, int nonceIncrement, long amount) throws IOException {
    ECKey signer = ECKey.fromPrivate(Hex.decode(without0x(privKey)));
    ECKey sponsorKey = getAccountApproverKey();
    WalletServerAccountResponse addrDetails = wsService.getAccount(hex(signer.getAddress()));
    byte[] signatureArg = signDelegate(0, amount, addrDetails.getNonce() + 1 + nonceIncrement, without0x(toAddress), signer);
    byte[] callData = transferFunction.encode(addrDetails.getNonce() + 1 + nonceIncrement, toAddress, amount, 0, signatureArg, hex(sponsorKey.getAddress()));
    String txHash = sendTransaction(sponsorKey, callData, contractAddressForTransfers, nonceIncrement);
    log.info("Submitted transfer and got Tx= " + txHash);
    return txHash;
}
Also used : WalletServerAccountResponse(eu.cryptoeuro.accountmapper.response.WalletServerAccountResponse) ECKey(org.ethereum.crypto.ECKey)

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