Modify HDAccountCold QrCode Support For Importing Chinese
MODIFY
bither-android/src/net/bither/activity/cold/ColdActivity.java
bither-android/src/net/bither/activity/cold/ColdActivity.java
@@ -51,6 +51,7 @@ import net.bither.fragment.Selectable;
import net.bither.fragment.Unselectable;
import net.bither.fragment.cold.CheckFragment;
import net.bither.fragment.cold.ColdAddressFragment;
+import net.bither.mnemonic.MnemonicCodeAndroid;
import net.bither.ui.base.BaseFragmentActivity;
import net.bither.ui.base.DropdownMessage;
import net.bither.ui.base.TabButton;
@@ -71,6 +72,7 @@ import net.bither.util.UIUtil;
import net.bither.util.WalletUtils;
import java.io.File;
+import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -419,11 +421,15 @@ public class ColdActivity extends BaseFragmentActivity {
}
continue;
}
- if (keyString.indexOf(MnemonicCode.instance().getMnemonicWordList().getHdQrCodeFlag()) == 0) {
+
+ MnemonicWordList mnemonicWordList = MnemonicWordList.getMnemonicWordListForHdSeed(keyString);
+ if (mnemonicWordList != null) {
+ try {
+ MnemonicCode mnemonicCode = new MnemonicCodeAndroid();
+ mnemonicCode.setMnemonicWordList(mnemonicWordList);
String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keyString);
String encreyptString = Utils.joinString(new String[]{passwordSeeds[1], passwordSeeds[2], passwordSeeds[3]}, QRCodeUtil.QR_CODE_SPLIT);
- try {
- new HDAccountCold(new EncryptedData(encreyptString), password);
+ new HDAccountCold(mnemonicCode, new EncryptedData(encreyptString), password);
} catch (Exception e) {
e.printStackTrace();
}
@@ -437,7 +443,6 @@ public class ColdActivity extends BaseFragmentActivity {
PrivateKeyUtil.getEncryptedString(key), false, key.isFromXRandom());
addressList.add(address);
key.clearPrivateKey();
-
}
}

MODIFY
bither-android/src/net/bither/activity/cold/ColdAdvanceActivity.java
bither-android/src/net/bither/activity/cold/ColdAdvanceActivity.java
@@ -43,6 +43,7 @@ import net.bither.bitherj.crypto.EncryptedData;
import net.bither.bitherj.crypto.SecureCharSequence;
import net.bither.bitherj.crypto.bip38.Bip38;
import net.bither.bitherj.crypto.mnemonic.MnemonicCode;
+import net.bither.bitherj.crypto.mnemonic.MnemonicWordList;
import net.bither.bitherj.factory.ImportHDSeed;
import net.bither.bitherj.factory.ImportPrivateKey;
import net.bither.bitherj.qrcode.QRCodeUtil;
@@ -51,6 +52,7 @@ import net.bither.bitherj.utils.Utils;
import net.bither.factory.ImportHDSeedAndroid;
import net.bither.factory.ImportPrivateKeyAndroid;
import net.bither.fragment.Refreshable;
+import net.bither.mnemonic.MnemonicCodeAndroid;
import net.bither.pin.PinCodeChangeActivity;
import net.bither.pin.PinCodeDisableActivity;
import net.bither.pin.PinCodeEnableActivity;
@@ -79,6 +81,7 @@ import net.bither.util.LogUtil;
import net.bither.util.ThreadUtil;
import java.io.File;
+import java.io.IOException;
public class ColdAdvanceActivity extends SwipeRightFragmentActivity {
@@ -743,14 +746,18 @@ public class ColdAdvanceActivity extends SwipeRightFragmentActivity {
break;
case BitherSetting.INTENT_REF.IMPORT_HD_ACCOUNT_SEED_REQUEST_CODE:
final String hdAccountSeed = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
- if (hdAccountSeed.indexOf(MnemonicCode.instance().getMnemonicWordList().getHdQrCodeFlag()) == 0) {
+ final MnemonicWordList mnemonicWordList = MnemonicWordList.getMnemonicWordListForHdSeed(hdAccountSeed);
+ if (mnemonicWordList != null) {
+ try {
+ MnemonicCode mnemonicCode = new MnemonicCodeAndroid();
+ mnemonicCode.setMnemonicWordList(mnemonicWordList);
dialogPassword = new DialogPassword(this,
- new ImportHDAccountPasswordListener(hdAccountSeed));
+ new ImportHDAccountPasswordListener(hdAccountSeed, mnemonicCode));
dialogPassword.setCheckPre(false);
dialogPassword.setCheckPasswordListener(new ICheckPasswordListener() {
@Override
public boolean checkPassword(SecureCharSequence password) {
- String keyString = hdAccountSeed.substring(1);
+ String keyString = hdAccountSeed.substring(mnemonicWordList.getHdQrCodeFlag().length());
String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keyString);
String encreyptString = Utils.joinString(new String[]{passwordSeeds[0], passwordSeeds[1], passwordSeeds[2]}, QRCodeUtil.QR_CODE_SPLIT);
EncryptedData encryptedData = new EncryptedData(encreyptString);
@@ -765,9 +772,12 @@ public class ColdAdvanceActivity extends SwipeRightFragmentActivity {
});
dialogPassword.setTitle(R.string.import_private_key_qr_code_password);
dialogPassword.show();
+ } catch (IOException e) {
+ e.printStackTrace();
+ DropdownMessage.showDropdownMessage(ColdAdvanceActivity.this, R.string.import_hd_account_seed_format_error);
+ }
} else {
- DropdownMessage.showDropdownMessage(ColdAdvanceActivity.this
- , R.string.import_hd_account_seed_format_error);
+ DropdownMessage.showDropdownMessage(ColdAdvanceActivity.this, R.string.import_hd_account_seed_format_error);
}
break;
}
@@ -775,9 +785,11 @@ public class ColdAdvanceActivity extends SwipeRightFragmentActivity {
private class ImportHDAccountPasswordListener implements IDialogPasswordListener {
private String content;
+ private MnemonicCode mnemonicCode;
- public ImportHDAccountPasswordListener(String content) {
+ public ImportHDAccountPasswordListener(String content, MnemonicCode mnemonicCode) {
this.content = content;
+ this.mnemonicCode = mnemonicCode;
}
@Override
@@ -786,7 +798,7 @@ public class ColdAdvanceActivity extends SwipeRightFragmentActivity {
dp.setMessage(R.string.import_private_key_qr_code_importing);
LogUtil.d("importhdseed", "onPasswordEntered");
ImportHDSeedAndroid importHDSeedAndroid = new ImportHDSeedAndroid
- (ColdAdvanceActivity.this, ImportHDSeed.ImportHDSeedType.HDSeedQRCode, dp, content, null, password, null);
+ (ColdAdvanceActivity.this, ImportHDSeed.ImportHDSeedType.HDSeedQRCode, dp, content, null, password, mnemonicCode);
importHDSeedAndroid.importHDSeed();
}
}

MODIFY
bither-android/src/net/bither/activity/hot/HotAdvanceActivity.java
bither-android/src/net/bither/activity/hot/HotAdvanceActivity.java
@@ -1270,7 +1270,7 @@ public class HotAdvanceActivity extends SwipeRightFragmentActivity {
break;
case BitherSetting.INTENT_REF.IMPORT_HD_ACCOUNT_SEED_REQUEST_CODE:
final String hdAccountSeed = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
- final MnemonicWordList mnemonicWordList = MnemonicWordList.getMnemonicWordList(hdAccountSeed);
+ final MnemonicWordList mnemonicWordList = MnemonicWordList.getMnemonicWordListForHdSeed(hdAccountSeed);
if (mnemonicWordList != null) {
try {
MnemonicCode mnemonicCode = new MnemonicCodeAndroid();

MODIFY
bither-android/src/net/bither/fragment/cold/AddAddressColdHDAccountFragment.java
bither-android/src/net/bither/fragment/cold/AddAddressColdHDAccountFragment.java
@@ -33,6 +33,7 @@ import net.bither.activity.hot.AddHotAddressActivity;
import net.bither.bitherj.core.HDAccount;
import net.bither.bitherj.core.HDAccountCold;
import net.bither.bitherj.crypto.SecureCharSequence;
+import net.bither.bitherj.crypto.mnemonic.MnemonicCode;
import net.bither.bitherj.crypto.mnemonic.MnemonicException;
import net.bither.preference.AppSharedPreference;
import net.bither.runnable.ThreadNeedService;
@@ -122,7 +123,7 @@ public class AddAddressColdHDAccountFragment extends Fragment implements AddHotA
final ArrayList<String> words = new ArrayList<String>();
try {
- hdAccount = new HDAccountCold(new SecureRandom(), password);
+ hdAccount = new HDAccountCold(MnemonicCode.instance(), new SecureRandom(), password);
words.addAll(hdAccount.getSeedWords(password));
} catch (MnemonicException.MnemonicLengthException e) {
throw new RuntimeException(e);

MODIFY
bither-android/src/net/bither/fragment/cold/OptionColdFragment.java
bither-android/src/net/bither/fragment/cold/OptionColdFragment.java
@@ -51,11 +51,14 @@ import net.bither.bitherj.core.EnterpriseHDMSeed;
import net.bither.bitherj.core.HDAccountCold;
import net.bither.bitherj.core.HDMKeychain;
import net.bither.bitherj.crypto.SecureCharSequence;
+import net.bither.bitherj.crypto.mnemonic.MnemonicCode;
+import net.bither.bitherj.crypto.mnemonic.MnemonicWordList;
import net.bither.bitherj.qrcode.QRCodeEnodeUtil;
import net.bither.bitherj.utils.PrivateKeyUtil;
import net.bither.bitherj.utils.Utils;
import net.bither.fragment.Refreshable;
import net.bither.fragment.Selectable;
+import net.bither.mnemonic.MnemonicCodeAndroid;
import net.bither.preference.AppSharedPreference;
import net.bither.qrcode.BitherQRCodeActivity;
import net.bither.qrcode.ScanActivity;
@@ -76,6 +79,7 @@ import net.bither.util.UnitUtilWrapper;
import org.w3c.dom.Text;
+import java.io.IOException;
import java.util.Date;
import java.util.List;
@@ -491,7 +495,18 @@ public class OptionColdFragment extends Fragment implements Selectable {
public void run() {
List<Address> addressList = PrivateKeyUtil.getECKeysFromBackupString(content, password);
HDMKeychain hdmKeychain = PrivateKeyUtil.getHDMKeychain(content, password);
- HDAccountCold hdAccountCold = PrivateKeyUtil.getHDAccountCold(content, password);
+ HDAccountCold hdAccountCold = null;
+ MnemonicWordList mnemonicWordList = MnemonicWordList.getMnemonicWordListForHdSeed(content);
+ MnemonicCode mnemonicCode = null;
+ if (mnemonicWordList != null) {
+ try {
+ mnemonicCode = new MnemonicCodeAndroid();
+ mnemonicCode.setMnemonicWordList(mnemonicWordList);
+ hdAccountCold = PrivateKeyUtil.getHDAccountCold(mnemonicCode, content, password);
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
if ((addressList == null || addressList.size() == 0) && (hdmKeychain == null) &&
hdAccountCold == null) {
@@ -514,6 +529,10 @@ public class OptionColdFragment extends Fragment implements Selectable {
KeyUtil.setHDKeyChain(hdmKeychain);
}
password.wipe();
+ if (mnemonicCode != null && mnemonicWordList != null) {
+ AppSharedPreference.getInstance().setMnemonicWordList(mnemonicWordList);
+ MnemonicCode.setInstance(mnemonicCode);
+ }
getActivity().runOnUiThread(new Runnable() {
@Override

MODIFY
bither-android/src/net/bither/xrandom/HDAccountColdUEntropyActivity.java
bither-android/src/net/bither/xrandom/HDAccountColdUEntropyActivity.java
@@ -26,6 +26,7 @@ import net.bither.bitherj.core.AddressManager;
import net.bither.bitherj.core.HDAccount;
import net.bither.bitherj.core.HDAccountCold;
import net.bither.bitherj.crypto.SecureCharSequence;
+import net.bither.bitherj.crypto.mnemonic.MnemonicCode;
import net.bither.runnable.ThreadNeedService;
import net.bither.service.BlockchainService;
import net.bither.ui.base.DialogFragmentHDMSingularColdSeed;
@@ -134,7 +135,7 @@ public class HDAccountColdUEntropyActivity extends UEntropyActivity {
return;
}
- HDAccountCold hdAccount = new HDAccountCold(xRandom, password);
+ HDAccountCold hdAccount = new HDAccountCold(MnemonicCode.instance(), xRandom, password);
if (cancelRunnable != null) {
finishGenerate(service);
runOnUiThread(cancelRunnable);

MODIFY
bitherj
bitherj
-Subproject commit cb5a50e55b8b0ae41a957b6ea3e4d2b42a0bbeaa
+Subproject commit 83082ac2f264e4f0df167d16127490146a972f08

Modify HDAccountCold QrCode Support For Importing Chinese