Search in sources :

Example 36 with ECKey

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

the class EthereumKeyGenerator method main.

public static void main(String[] args) {
    ECKey ecKey = new ECKey();
    System.out.println("Private key:\n" + Hex.toHexString(ecKey.getPrivKeyBytes()));
    System.out.println("Address:\n0x" + Hex.toHexString(ecKey.getAddress()));
}
Also used : ECKey(org.ethereum.crypto.ECKey)

Example 37 with ECKey

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

the class ProofOfWorkRule method validFallbackBlockSignature.

public static boolean validFallbackBlockSignature(Constants constants, BlockHeader header, byte[] signatureBytesRLP) {
    if (header.getBitcoinMergedMiningCoinbaseTransaction() != null) {
        return false;
    }
    if (header.getBitcoinMergedMiningMerkleProof() != null) {
        return false;
    }
    byte[] fallbackMiningPubKeyBytes;
    boolean isEvenBlockNumber = header.getNumber() % 2 == 0;
    if (isEvenBlockNumber) {
        fallbackMiningPubKeyBytes = constants.getFallbackMiningPubKey0();
    } else {
        fallbackMiningPubKeyBytes = constants.getFallbackMiningPubKey1();
    }
    ECKey fallbackMiningPubKey = ECKey.fromPublicOnly(fallbackMiningPubKeyBytes);
    List<RLPElement> signatureRLP = (RLPList) RLP.decode2(signatureBytesRLP).get(0);
    if (signatureRLP.size() != 3) {
        return false;
    }
    byte[] v = signatureRLP.get(0).getRLPData();
    byte[] r = signatureRLP.get(1).getRLPData();
    byte[] s = signatureRLP.get(2).getRLPData();
    ECKey.ECDSASignature signature = ECKey.ECDSASignature.fromComponents(r, s, v[0]);
    return fallbackMiningPubKey.verify(header.getHashForMergedMining(), signature);
}
Also used : RLPElement(org.ethereum.util.RLPElement) ECKey(org.ethereum.crypto.ECKey) RLPList(org.ethereum.util.RLPList)

Example 38 with ECKey

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

the class DefaultConfig method peerExplorer.

@Bean
public PeerExplorer peerExplorer(RskSystemProperties rskConfig) {
    ECKey key = rskConfig.getMyKey();
    Node localNode = new Node(key.getNodeId(), rskConfig.getPublicIp(), rskConfig.getPeerPort());
    NodeDistanceTable distanceTable = new NodeDistanceTable(KademliaOptions.BINS, KademliaOptions.BUCKET_SIZE, localNode);
    long msgTimeOut = rskConfig.peerDiscoveryMessageTimeOut();
    long refreshPeriod = rskConfig.peerDiscoveryRefreshPeriod();
    List<String> initialBootNodes = rskConfig.peerDiscoveryIPList();
    List<Node> activePeers = rskConfig.peerActive();
    if (CollectionUtils.isNotEmpty(activePeers)) {
        for (Node n : activePeers) {
            InetSocketAddress address = n.getAddress();
            initialBootNodes.add(address.getHostName() + ":" + address.getPort());
        }
    }
    return new PeerExplorer(initialBootNodes, localNode, distanceTable, key, msgTimeOut, refreshPeriod);
}
Also used : NodeDistanceTable(co.rsk.net.discovery.table.NodeDistanceTable) PeerExplorer(co.rsk.net.discovery.PeerExplorer) InetSocketAddress(java.net.InetSocketAddress) Node(org.ethereum.net.rlpx.Node) ECKey(org.ethereum.crypto.ECKey) Bean(org.springframework.context.annotation.Bean)

Example 39 with ECKey

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

the class SystemProperties method getGeneratedNodePrivateKey.

private String getGeneratedNodePrivateKey() {
    try {
        File file = new File(databaseDir(), "nodeId.properties");
        Properties props = new Properties();
        if (file.canRead()) {
            props.load(new FileReader(file));
        } else {
            ECKey key = new ECKey();
            props.setProperty("nodeIdPrivateKey", Hex.toHexString(key.getPrivKeyBytes()));
            props.setProperty("nodeId", Hex.toHexString(key.getNodeId()));
            file.getParentFile().mkdirs();
            props.store(new FileWriter(file), "Generated NodeID. To use your own nodeId please refer to 'peer.privateKey' config option.");
            logger.info("New nodeID generated: " + props.getProperty("nodeId"));
            logger.info("Generated nodeID and its private key stored in " + file);
        }
        return props.getProperty("nodeIdPrivateKey");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ECKey(org.ethereum.crypto.ECKey)

Example 40 with ECKey

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

the class Transaction method sign.

public void sign(byte[] privKeyBytes) throws MissingPrivateKeyException {
    byte[] rawHash = this.getRawHash().getBytes();
    ECKey key = ECKey.fromPrivate(privKeyBytes).decompress();
    this.setSignature(key.sign(rawHash));
}
Also used : 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