Search in sources :

Example 1 with PubKey

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());
    }
}
Also used : PubKey(io.libp2p.core.crypto.PubKey) FileWriter(java.io.FileWriter) FileNotFoundException(java.io.FileNotFoundException) PrivKey(io.libp2p.core.crypto.PrivKey) File(java.io.File) InvalidConfigurationException(tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException) PrintWriter(java.io.PrintWriter) PeerId(io.libp2p.core.PeerId)

Aggregations

PeerId (io.libp2p.core.PeerId)1 PrivKey (io.libp2p.core.crypto.PrivKey)1 PubKey (io.libp2p.core.crypto.PubKey)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1 PrintWriter (java.io.PrintWriter)1 InvalidConfigurationException (tech.pegasys.teku.infrastructure.exceptions.InvalidConfigurationException)1