Address generation tests
This commit is contained in:
parent
66197aa0d2
commit
ec4f0704d6
2 changed files with 31 additions and 10 deletions
|
@ -65,8 +65,8 @@ public class Main {
|
||||||
|
|
||||||
// test.testRandomNumberGeneration();
|
// test.testRandomNumberGeneration();
|
||||||
|
|
||||||
test.testBrainKeyOperations();
|
test.testBrainKeyOperations(false);
|
||||||
|
|
||||||
test.testBip39Opertion();
|
// test.testBip39Opertion();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,8 @@ import com.luminiasoft.bitshares.ws.TransactionBroadcastSequence;
|
||||||
import com.neovisionaries.ws.client.*;
|
import com.neovisionaries.ws.client.*;
|
||||||
import org.bitcoinj.core.*;
|
import org.bitcoinj.core.*;
|
||||||
import org.spongycastle.crypto.Digest;
|
import org.spongycastle.crypto.Digest;
|
||||||
|
import org.spongycastle.crypto.digests.RIPEMD128Digest;
|
||||||
|
import org.spongycastle.crypto.digests.RIPEMD160Digest;
|
||||||
import org.spongycastle.crypto.digests.SHA512Digest;
|
import org.spongycastle.crypto.digests.SHA512Digest;
|
||||||
import org.spongycastle.crypto.prng.DigestRandomGenerator;
|
import org.spongycastle.crypto.prng.DigestRandomGenerator;
|
||||||
|
|
||||||
|
@ -506,8 +508,10 @@ public class Test {
|
||||||
* The final purpose of this test is to convert the plain brainkey at
|
* The final purpose of this test is to convert the plain brainkey at
|
||||||
* Main.BRAIN_KEY into the WIF at Main.WIF
|
* Main.BRAIN_KEY into the WIF at Main.WIF
|
||||||
*/
|
*/
|
||||||
public void testBrainKeyOperations(){
|
public void testBrainKeyOperations(boolean random){
|
||||||
try {
|
try {
|
||||||
|
BrainKey brainKey;
|
||||||
|
if(random){
|
||||||
String current = new java.io.File( "." ).getCanonicalPath();
|
String current = new java.io.File( "." ).getCanonicalPath();
|
||||||
File file = new File(current + "/src/main/java/com/luminiasoft/bitshares/brainkeydict.txt");
|
File file = new File(current + "/src/main/java/com/luminiasoft/bitshares/brainkeydict.txt");
|
||||||
|
|
||||||
|
@ -515,8 +519,13 @@ public class Test {
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
String words = bufferedReader.readLine();
|
String words = bufferedReader.readLine();
|
||||||
String suggestion = BrainKey.suggest(words);
|
String suggestion = BrainKey.suggest(words);
|
||||||
BrainKey brainKey = new BrainKey(Main.BRAIN_KEY, 0);
|
brainKey = new BrainKey(suggestion, 0);
|
||||||
|
}else{
|
||||||
|
brainKey = new BrainKey(Main.BRAIN_KEY, 0);
|
||||||
|
}
|
||||||
ECKey key = brainKey.getPrivateKey();
|
ECKey key = brainKey.getPrivateKey();
|
||||||
|
System.out.println("Private key");
|
||||||
|
System.out.println(Util.bytesToHex(key.getSecretBytes()));
|
||||||
String wif = key.getPrivateKeyAsWiF(NetworkParameters.fromID(NetworkParameters.ID_MAINNET));
|
String wif = key.getPrivateKeyAsWiF(NetworkParameters.fromID(NetworkParameters.ID_MAINNET));
|
||||||
System.out.println("wif compressed: "+wif);
|
System.out.println("wif compressed: "+wif);
|
||||||
String wif2 = key.decompress().getPrivateKeyAsWiF(NetworkParameters.fromID(NetworkParameters.ID_MAINNET));
|
String wif2 = key.decompress().getPrivateKeyAsWiF(NetworkParameters.fromID(NetworkParameters.ID_MAINNET));
|
||||||
|
@ -533,6 +542,18 @@ public class Test {
|
||||||
byte[] pubKey3 = key.getPubKeyPoint().getEncoded(true);
|
byte[] pubKey3 = key.getPubKeyPoint().getEncoded(true);
|
||||||
System.out.println("pub key compressed : "+Base58.encode(pubKey3));
|
System.out.println("pub key compressed : "+Base58.encode(pubKey3));
|
||||||
|
|
||||||
|
// Address generation test
|
||||||
|
RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest();
|
||||||
|
SHA512Digest sha512Digest = new SHA512Digest();
|
||||||
|
sha512Digest.update(pubKey1, 0, pubKey1.length);
|
||||||
|
byte[] intermediate = new byte[512 / 8];
|
||||||
|
sha512Digest.doFinal(intermediate, 0);
|
||||||
|
ripemd160Digest.update(intermediate, 0, intermediate.length);
|
||||||
|
byte[] output = new byte[160 / 8];
|
||||||
|
ripemd160Digest.doFinal(output, 0);
|
||||||
|
System.out.println("output after : "+Util.bytesToHex(output));
|
||||||
|
String encoded = Base58.encode(output);
|
||||||
|
System.out.println("base 58: "+encoded);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
System.out.println("FileNotFoundException. Msg: "+e.getMessage());
|
System.out.println("FileNotFoundException. Msg: "+e.getMessage());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
Loading…
Reference in a new issue