Implemented WIF Account Seed

This commit is contained in:
hvarona 2018-11-18 11:44:30 -04:00
parent 83c95a35a8
commit 5aa7175016
2 changed files with 15 additions and 3 deletions

View file

@ -6,5 +6,6 @@ package cy.agorise.crystalwallet.enums;
public enum SeedType { public enum SeedType {
BIP39, BIP39,
BRAINKEY BRAINKEY,
WIF
} }

View file

@ -9,12 +9,14 @@ import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.v7.util.DiffUtil; import android.support.v7.util.DiffUtil;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.ECKey; import org.bitcoinj.core.ECKey;
import org.bitcoinj.crypto.HDKeyDerivation; import org.bitcoinj.crypto.HDKeyDerivation;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.Arrays;
import cy.agorise.crystalwallet.enums.SeedType; import cy.agorise.crystalwallet.enums.SeedType;
import cy.agorise.crystalwallet.models.seed.BIP39; import cy.agorise.crystalwallet.models.seed.BIP39;
@ -115,8 +117,6 @@ public class AccountSeed {
BufferedReader reader = null; BufferedReader reader = null;
switch (type) { switch (type) {
case BRAINKEY: case BRAINKEY:
try { try {
reader = new BufferedReader(new InputStreamReader(context.getAssets().open("brainkeydict.txt"), "UTF-8")); reader = new BufferedReader(new InputStreamReader(context.getAssets().open("brainkeydict.txt"), "UTF-8"));
@ -130,6 +130,7 @@ public class AccountSeed {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
break;
case BIP39: case BIP39:
try { try {
reader = new BufferedReader(new InputStreamReader(context.getAssets().open("bip39dict.txt"), "UTF-8")); reader = new BufferedReader(new InputStreamReader(context.getAssets().open("bip39dict.txt"), "UTF-8"));
@ -139,6 +140,7 @@ public class AccountSeed {
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
break;
} }
return null; return null;
} }
@ -149,6 +151,15 @@ public class AccountSeed {
return new BrainKey(this.mMasterSeed,0).getPrivateKey(); return new BrainKey(this.mMasterSeed,0).getPrivateKey();
case BIP39: case BIP39:
return HDKeyDerivation.createMasterPrivateKey(new BIP39(mId, mMasterSeed).getSeed()); return HDKeyDerivation.createMasterPrivateKey(new BIP39(mId, mMasterSeed).getSeed());
case WIF:
byte[] decoded = Base58.decode(this.mMasterSeed);
byte[] privKey = Arrays.copyOfRange(decoded, 1, decoded.length - 4);
byte[] checksum = Arrays.copyOfRange(decoded, decoded.length - 4, decoded.length);
//TODO calculate chekcsum
while(privKey.length>32){
privKey = Arrays.copyOfRange(privKey,0,privKey.length-1);
}
return ECKey.fromPrivate(privKey);
} }
return null; return null;
} }