From 4c105de826023765c47e5d42b84eccb3ac62d25e Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Thu, 24 Nov 2016 12:49:19 -0500 Subject: [PATCH] Added the getWalletImportFormat to the BrainKey class --- .../java/com/luminiasoft/bitshares/BIP39.java | 1 - .../com/luminiasoft/bitshares/BrainKey.java | 23 +++++++++++++++++++ .../java/com/luminiasoft/bitshares/Main.java | 6 +++-- .../java/com/luminiasoft/bitshares/Test.java | 1 + 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/luminiasoft/bitshares/BIP39.java b/src/main/java/com/luminiasoft/bitshares/BIP39.java index aa3aabd..2b10c83 100644 --- a/src/main/java/com/luminiasoft/bitshares/BIP39.java +++ b/src/main/java/com/luminiasoft/bitshares/BIP39.java @@ -1,7 +1,6 @@ package com.luminiasoft.bitshares; import java.util.Arrays; -import java.util.Base64; import org.bitcoinj.core.Base58; import org.bitcoinj.core.ECKey; import org.bitcoinj.crypto.HDKeyDerivation; diff --git a/src/main/java/com/luminiasoft/bitshares/BrainKey.java b/src/main/java/com/luminiasoft/bitshares/BrainKey.java index 1aaa4e0..79a359e 100644 --- a/src/main/java/com/luminiasoft/bitshares/BrainKey.java +++ b/src/main/java/com/luminiasoft/bitshares/BrainKey.java @@ -2,12 +2,16 @@ package com.luminiasoft.bitshares; import com.luminiasoft.bitshares.crypto.AndroidRandomSource; import com.luminiasoft.bitshares.crypto.SecureRandomStrengthener; +import org.bitcoinj.core.Base58; +import org.bitcoinj.core.DumpedPrivateKey; import org.bitcoinj.core.ECKey; +import org.bitcoinj.core.NetworkParameters; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; +import java.security.spec.ECPoint; import java.util.ArrayList; /** @@ -72,11 +76,30 @@ public class BrainKey { System.out.println("UnsupportedEncodingException. Msg: " + e.getMessage()); } } + + /** + * Gets the array of bytes representing the public key. + * @return + */ public byte[] getPublicKey() { return mPrivateKey.getPubKey(); } + /** + * Returns the private key as an instance of the ECKey class. + * @return + */ public ECKey getPrivateKey() { return mPrivateKey; } + + /** + * Returns the private key in the Wallet Import Format for the uncompressed private key. + * @see WIF + * @return + */ + public String getWalletImportFormat(){ + DumpedPrivateKey wif = this.mPrivateKey.decompress().getPrivateKeyEncoded(NetworkParameters.fromID(NetworkParameters.ID_MAINNET)); + return wif.toString(); + } } diff --git a/src/main/java/com/luminiasoft/bitshares/Main.java b/src/main/java/com/luminiasoft/bitshares/Main.java index 2e57f7e..ead7ba6 100644 --- a/src/main/java/com/luminiasoft/bitshares/Main.java +++ b/src/main/java/com/luminiasoft/bitshares/Main.java @@ -6,8 +6,10 @@ import java.io.IOException; public class Main { // Brain key from Nelson's app referencing the bilthon-83 account - public static final String BRAIN_KEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH"; +// public static final String BRAIN_KEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH"; + //public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER"; + public static final String BRAIN_KEY = "SIVER TIKKER FOGO HOMINAL PRAYER LUTEIN SMALLY ACARID MEROPIA TRANCE BOGONG IDDAT HICKORY SOUTANE MOOD DOWSER"; public static final String BIP39_KEY = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"; @@ -66,7 +68,7 @@ public class Main { // test.testRandomNumberGeneration(); - test.testBrainKeyOperations(true); + test.testBrainKeyOperations(false); // test.testBip39Opertion(); } diff --git a/src/main/java/com/luminiasoft/bitshares/Test.java b/src/main/java/com/luminiasoft/bitshares/Test.java index 605d21a..2fca809 100644 --- a/src/main/java/com/luminiasoft/bitshares/Test.java +++ b/src/main/java/com/luminiasoft/bitshares/Test.java @@ -546,6 +546,7 @@ public class Test { Address address = new Address(key); System.out.println("Block explorer's address: "+address); + System.out.println("Wif: : "+brainKey.getWalletImportFormat()); } catch (FileNotFoundException e) { System.out.println("FileNotFoundException. Msg: " + e.getMessage()); } catch (IOException e) {