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

View file

@ -26,6 +26,7 @@ import java.util.*;
* Created by nelson on 11/9/16.
*/
public class Test {
public static final String WITNESS_URL = "ws://api.devling.xyz:8088";
private Transaction transaction;
@ -33,7 +34,6 @@ public class Test {
return transaction;
}
private WitnessResponseListener mListener = new WitnessResponseListener() {
@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.");
}
}
int headerByte = recId + 27 + (sk.isCompressed() ? 4 : 0);
byte[] sigData = new byte[65]; // 1 header + 32 bytes for R + 32 bytes for S
sigData[0] = (byte) headerByte;
@ -207,7 +208,8 @@ public class Test {
}
if (baseResponse.id == 2) {
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);
networkBroadcastApiId = witnessResponse.result.intValue();
System.out.println(">>");
@ -328,7 +330,8 @@ public class Test {
public void testNetworkBroadcastDeserialization() {
String response = "{\"id\":2,\"result\":2}";
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);
}
@ -340,7 +343,8 @@ public class Test {
public void testRequiredFeesResponse() {
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.registerTypeAdapter(AssetAmount.class, new AssetAmount.AssetDeserializer());
WitnessResponse<List<AssetAmount>> witnessResponse = gsonBuilder.create().fromJson(response, AccountLookupResponse);
@ -395,7 +399,8 @@ public class Test {
public void testAccountLookupDeserialization() {
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();
WitnessResponse<List<List<String>>> witnessResponse = gson.fromJson(response, AccountLookupResponse);
for (int i = 0; i < witnessResponse.result.size(); i++) {
@ -469,11 +474,9 @@ public class Test {
generator.addSeedMaterial(seed);
for (int i = 0; i != 1000000; i++)
{
for (int i = 0; i != 1000000; i++) {
generator.nextBytes(output);
for (int j = 0; j != output.length; j++)
{
for (int j = 0; j != output.length; j++) {
averages[j] += output[j] & 0xff;
ands[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
* into the WIF at Main.WIF
* The final purpose of this test is to convert the plain brainkey at
* Main.BRAIN_KEY into the WIF at Main.WIF
*/
public void testBrainKeyOperations() {
BrainKey brainKey = new BrainKey(Main.BRAIN_KEY, 0);
}
public void testBip39Opertion() {
BIP39 bip39 = new BIP39(Main.BIP39_KEY, "");
}
}