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()));
}
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);
}
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);
}
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);
}
}
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));
}
Aggregations