Added BIP39 ECKey creation

This commit is contained in:
Henry Varona 2016-11-22 15:12:44 -04:30
parent a611f9b388
commit 51bed577aa
3 changed files with 605 additions and 573 deletions

View file

@ -0,0 +1,23 @@
package com.luminiasoft.bitshares;
import java.util.Arrays;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.crypto.HDKeyDerivation;
import org.bitcoinj.crypto.MnemonicCode;
/**
*
* @author hvarona
*/
public class BIP39 {
private ECKey mPrivateKey;
public BIP39(String words, String passphrase) {
byte[] seed = MnemonicCode.toSeed(Arrays.asList(words.split(" ")), passphrase);
mPrivateKey = HDKeyDerivation.createMasterPrivateKey(seed);
}
}

View file

@ -7,6 +7,7 @@ import java.io.IOException;
public class Main { public class Main {
// Brain key from Nelson's app referencing the bilthon-83 account // 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 BIP39_KEY = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
// WIF from Nelson's app referencing the bilthon-83 account // WIF from Nelson's app referencing the bilthon-83 account
public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM"; public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM";
@ -60,5 +61,6 @@ public class Main {
// test.testRandomNumberGeneration(); // test.testRandomNumberGeneration();
test.testBrainKeyOperations(); test.testBrainKeyOperations();
test.testBip39Opertion();
} }
} }

View file

@ -26,6 +26,7 @@ import java.util.*;
* Created by nelson on 11/9/16. * Created by nelson on 11/9/16.
*/ */
public class Test { public class Test {
public static final String WITNESS_URL = "ws://api.devling.xyz:8088"; public static final String WITNESS_URL = "ws://api.devling.xyz:8088";
private Transaction transaction; private Transaction transaction;
@ -33,7 +34,6 @@ public class Test {
return transaction; return transaction;
} }
private WitnessResponseListener mListener = new WitnessResponseListener() { private WitnessResponseListener mListener = new WitnessResponseListener() {
@Override @Override
@ -115,9 +115,10 @@ public class Test {
} }
} }
} }
if (recId == -1) if (recId == -1) {
throw new RuntimeException("Could not construct a recoverable key. This should never happen."); throw new RuntimeException("Could not construct a recoverable key. This should never happen.");
} }
}
int headerByte = recId + 27 + (sk.isCompressed() ? 4 : 0); int headerByte = recId + 27 + (sk.isCompressed() ? 4 : 0);
byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S
sigData[0] = (byte) headerByte; sigData[0] = (byte) headerByte;
@ -207,7 +208,8 @@ public class Test {
} }
if (baseResponse.id == 2) { if (baseResponse.id == 2) {
String payload = String.format(getDynamicParameters, 3); String payload = String.format(getDynamicParameters, 3);
Type ApiIdResponse = new TypeToken<WitnessResponse<Integer>>() {}.getType(); Type ApiIdResponse = new TypeToken<WitnessResponse<Integer>>() {
}.getType();
WitnessResponse<Integer> witnessResponse = gson.fromJson(response, ApiIdResponse); WitnessResponse<Integer> witnessResponse = gson.fromJson(response, ApiIdResponse);
networkBroadcastApiId = witnessResponse.result.intValue(); networkBroadcastApiId = witnessResponse.result.intValue();
System.out.println(">>"); System.out.println(">>");
@ -328,7 +330,8 @@ public class Test {
public void testNetworkBroadcastDeserialization() { public void testNetworkBroadcastDeserialization() {
String response = "{\"id\":2,\"result\":2}"; String response = "{\"id\":2,\"result\":2}";
Gson gson = new Gson(); Gson gson = new Gson();
Type ApiIdResponse = new TypeToken<WitnessResponse<Integer>>() {}.getType(); Type ApiIdResponse = new TypeToken<WitnessResponse<Integer>>() {
}.getType();
WitnessResponse<Integer> witnessResponse = gson.fromJson(response, ApiIdResponse); WitnessResponse<Integer> witnessResponse = gson.fromJson(response, ApiIdResponse);
} }
@ -340,7 +343,8 @@ public class Test {
public void testRequiredFeesResponse() { public void testRequiredFeesResponse() {
String response = "{\"id\":1,\"result\":[{\"amount\":264174,\"asset_id\":\"1.3.0\"}]}"; String response = "{\"id\":1,\"result\":[{\"amount\":264174,\"asset_id\":\"1.3.0\"}]}";
Type AccountLookupResponse = new TypeToken<WitnessResponse<List<AssetAmount>>>() {}.getType(); Type AccountLookupResponse = new TypeToken<WitnessResponse<List<AssetAmount>>>() {
}.getType();
GsonBuilder gsonBuilder = new GsonBuilder(); GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetDeserializer()); gsonBuilder.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetDeserializer());
WitnessResponse<List<AssetAmount>> witnessResponse = gsonBuilder.create().fromJson(response, AccountLookupResponse); WitnessResponse<List<AssetAmount>> witnessResponse = gsonBuilder.create().fromJson(response, AccountLookupResponse);
@ -395,7 +399,8 @@ public class Test {
public void testAccountLookupDeserialization() { public void testAccountLookupDeserialization() {
String response = "{\"id\":1,\"result\":[[\"ken\",\"1.2.3111\"],[\"ken-1\",\"1.2.101491\"],[\"ken-k\",\"1.2.108646\"]]}"; String response = "{\"id\":1,\"result\":[[\"ken\",\"1.2.3111\"],[\"ken-1\",\"1.2.101491\"],[\"ken-k\",\"1.2.108646\"]]}";
Type AccountLookupResponse = new TypeToken<WitnessResponse<List<List<String>>>>() {}.getType(); Type AccountLookupResponse = new TypeToken<WitnessResponse<List<List<String>>>>() {
}.getType();
Gson gson = new Gson(); Gson gson = new Gson();
WitnessResponse<List<List<String>>> witnessResponse = gson.fromJson(response, AccountLookupResponse); WitnessResponse<List<List<String>>> witnessResponse = gson.fromJson(response, AccountLookupResponse);
for (int i = 0; i < witnessResponse.result.size(); i++) { for (int i = 0; i < witnessResponse.result.size(); i++) {
@ -469,11 +474,9 @@ public class Test {
generator.addSeedMaterial(seed); generator.addSeedMaterial(seed);
for (int i = 0; i != 1000000; i++) for (int i = 0; i != 1000000; i++) {
{
generator.nextBytes(output); generator.nextBytes(output);
for (int j = 0; j != output.length; j++) for (int j = 0; j != output.length; j++) {
{
averages[j] += output[j] & 0xff; averages[j] += output[j] & 0xff;
ands[j] &= output[j]; ands[j] &= output[j];
xors[j] ^= output[j]; xors[j] ^= output[j];
@ -499,11 +502,15 @@ public class Test {
} }
/** /**
* The final purpose of this test is to convert the plain brainkey at Main.BRAIN_KEY * The final purpose of this test is to convert the plain brainkey at
* into the WIF at Main.WIF * Main.BRAIN_KEY into the WIF at Main.WIF
*/ */
public void testBrainKeyOperations() { public void testBrainKeyOperations() {
BrainKey brainKey = new BrainKey(Main.BRAIN_KEY, 0); BrainKey brainKey = new BrainKey(Main.BRAIN_KEY, 0);
} }
public void testBip39Opertion() {
BIP39 bip39 = new BIP39(Main.BIP39_KEY, "");
}
} }