Skip to content

Commit 5430caa

Browse files
committed
[ETCM-411] Add optional param to generate more keys at once
1 parent b5cb34b commit 5430caa

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/main/scala/io/iohk/ethereum/crypto/EcKeyGen.scala

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,24 @@ package io.iohk.ethereum.crypto
33
import io.iohk.ethereum.nodebuilder.SecureRandomBuilder
44

55
/**
6-
* A simple tool to generate and ECDSA key pair. The key pair will be printed in the format:
6+
* A simple tool to generate ECDSA key pairs. Takes an optional positional argument [n] - number of key pairs
7+
* to generate (default is 1).
8+
* The key pairs will be printed in the format:
79
* priv-key-hex (32 bytes)
810
* pub-key-hex (64 bytes)
911
*
1012
* Run:
11-
* ./eckeygen > mantis-datadir/node.key
13+
* ./eckeygen [n] > mantis-datadir/node.key
1214
*
1315
* to generate the private key for the node. Note that only the private key will be read upon Mantis boot,
1416
* and the second line is equivalent to node ID.
1517
* The tool can also be used to generate keys for an Ethereum account.
1618
*/
1719
object EcKeyGen extends App with SecureRandomBuilder {
18-
val (prv, pub) = newRandomKeyPairAsStrings(secureRandom)
20+
val numOfKeys = args.headOption.map(_.toInt).getOrElse(1)
21+
22+
val keyPairs = for (_ <- 1 to numOfKeys) yield newRandomKeyPairAsStrings(secureRandom)
23+
1924
//scalastyle:off
20-
println(prv + "\n" + pub)
25+
println(keyPairs.map { case (prv, pub) => s"$prv\n$pub\n" }.mkString("\n"))
2126
}

0 commit comments

Comments
 (0)