Add mnemonic phrase support to VanityGen

This commit is contained in:
catbref 2019-05-15 11:00:53 +01:00
parent 7a318c9fc7
commit 6be9bf9c3c

View File

@ -8,8 +8,12 @@ import java.util.Random;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.bouncycastle.jsse.provider.BouncyCastleJsseProvider;
import org.qora.account.PrivateKeyAccount;
import org.qora.crypto.Crypto;
import org.qora.utils.BIP39;
import org.qora.utils.Base58;
import com.google.common.primitives.Bytes;
public class VanityGen {
public static void main(String argv[]) throws IOException {
@ -23,14 +27,25 @@ public class VanityGen {
Security.insertProviderAt(new BouncyCastleJsseProvider(), 1);
Random random = new SecureRandom();
byte[] seed = new byte[32];
byte[] entropy = new byte[16];
while (true) {
random.nextBytes(seed);
PrivateKeyAccount account = new PrivateKeyAccount(null, seed);
// Generate entropy internally
random.nextBytes(entropy);
// Use SHA256 to generate more bits
byte[] hash = Crypto.digest(entropy);
// Append first 4 bits from hash to end. (Actually 8 bits but we only use 4).
byte checksum = (byte) (hash[0] & 0xf0);
byte[] entropy132 = Bytes.concat(entropy, new byte[] { checksum });
String mnemonic = BIP39.encode(entropy132, "en");
PrivateKeyAccount account = new PrivateKeyAccount(null, hash);
if (account.getAddress().startsWith(argv[0]))
System.out.println(String.format("Address: %s, public key: %s, private key: %s", account.getAddress(), Base58.encode(account.getPublicKey()), Base58.encode(seed)));
System.out.println(String.format("Address: %s, public key: %s, private key: %s, mnemonic: %s", account.getAddress(), Base58.encode(account.getPublicKey()), Base58.encode(hash), mnemonic));
}
}