@@ -7,11 +7,13 @@ import io.iohk.ethereum.crypto._
7
7
import io .iohk .ethereum .domain .Address
8
8
import io .iohk .ethereum .utils .ByteStringUtils
9
9
import java .security .SecureRandom
10
+ import io .iohk .ethereum .nodebuilder .SecureRandomBuilder
10
11
import org .bouncycastle .util .encoders .Hex
11
12
12
- object CliCommands {
13
+ object CliCommands extends SecureRandomBuilder {
13
14
14
15
val generatePrivateKeyCommand = " generate-private-key"
16
+ val generateKeyPairsCommand = " generate-key-pairs"
15
17
val deriveAddressCommand = " derive-address"
16
18
val generateAllocsCommand = " generate-allocs"
17
19
val balanceOption = " balance"
@@ -27,6 +29,22 @@ object CliCommands {
27
29
}
28
30
}
29
31
32
+ private val GenerateKeyPairs : Command [String ] =
33
+ Command (name = generateKeyPairsCommand, header = " Generate key pairs private/public" ) {
34
+ val keyNumberOpts = Opts .argument[Int ](" number of keys to generate" ).withDefault(1 )
35
+
36
+ keyNumberOpts.map { numOfKeys =>
37
+ val keyPairs = for (_ <- 1 to numOfKeys) yield newRandomKeyPairAsStrings(secureRandom)
38
+
39
+ /**
40
+ * The key pairs will be printed in the format:
41
+ * priv-key-hex (32 bytes)
42
+ * pub-key-hex (64 bytes)
43
+ */
44
+ keyPairs.map { case (prv, pub) => s " $prv\n $pub\n " }.mkString(" \n " )
45
+ }
46
+ }
47
+
30
48
private val DeriveAddressFromPrivateKey : Command [String ] =
31
49
Command (name = deriveAddressCommand, header = " Derive address from private key" ) {
32
50
@@ -69,6 +87,6 @@ object CliCommands {
69
87
}
70
88
71
89
val api : Command [String ] = Command .apply(name = " cli" , header = " Mantis CLI" ) {
72
- Opts .subcommands(GeneratePrivateKeyCommand , DeriveAddressFromPrivateKey , GenerateAllocs )
90
+ Opts .subcommands(GeneratePrivateKeyCommand , DeriveAddressFromPrivateKey , GenerateAllocs , GenerateKeyPairs )
73
91
}
74
92
}
0 commit comments