use of io.libp2p.core.crypto.PubKey in project teku by ConsenSys.
the class PeerCommand method validateParamsAndGenerate.
void validateParamsAndGenerate(String outputFile, int number) throws IOException {
try {
File f = new File(outputFile);
if (f.exists()) {
throw new InvalidConfigurationException(String.format("Not overwriting existing file %s \nDelete file or use --output-file to point to a file that does not currently exist.", outputFile));
}
FileWriter fileWriter = new FileWriter(outputFile, Charset.defaultCharset());
PrintWriter printWriter = new PrintWriter(fileWriter);
printWriter.println("Private Key(Hex)\tPublic Key(Hex)\tPeerId(Base58)");
for (int i = 0; i < number; i++) {
PrivKey privKey = KeyKt.generateKeyPair(KEY_TYPE.SECP256K1).component1();
PubKey pubKey = privKey.publicKey();
PeerId peerId = PeerId.fromPubKey(pubKey);
printWriter.println(Bytes.wrap(privKey.bytes()).toHexString() + "\t" + Bytes.wrap(pubKey.bytes()).toHexString() + "\t" + peerId.toBase58());
}
printWriter.close();
} catch (final FileNotFoundException ex) {
throw new InvalidConfigurationException("use --output-file to point to a file in an existing directory " + ex.getMessage());
}
}
Aggregations