use of com.samourai.wallet.hd.HD_Wallet in project samourai-wallet-android by Samourai-Wallet.
the class PinEntryActivity method validateThread.
private void validateThread(final String pin, final String uri) {
progressBar.setVisibility(View.VISIBLE);
new Thread(() -> {
Looper.prepare();
if (pin.length() < AccessFactory.MIN_PIN_LENGTH || pin.length() > AccessFactory.MAX_PIN_LENGTH) {
runOnUiThread(() -> {
progressBar.setVisibility(View.INVISIBLE);
});
Toast.makeText(PinEntryActivity.this, R.string.pin_error, Toast.LENGTH_SHORT).show();
AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
finish();
}
String randomKey = AccessFactory.getInstance(PinEntryActivity.this).getGUID();
if (randomKey.length() < 1) {
runOnUiThread(() -> {
progressBar.setVisibility(View.INVISIBLE);
});
Toast.makeText(PinEntryActivity.this, R.string.random_key_error, Toast.LENGTH_SHORT).show();
AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
finish();
}
String hash = PrefsUtil.getInstance(PinEntryActivity.this).getValue(PrefsUtil.ACCESS_HASH, "");
if (AccessFactory.getInstance(PinEntryActivity.this).validateHash(hash, randomKey, new CharSequenceX(pin), AESUtil.DefaultPBKDF2Iterations)) {
AccessFactory.getInstance(PinEntryActivity.this).setPIN(pin);
try {
HD_Wallet hdw = PayloadUtil.getInstance(PinEntryActivity.this).restoreWalletfromJSON(new CharSequenceX(AccessFactory.getInstance(PinEntryActivity.this).getGUID() + pin));
runOnUiThread(() -> {
progressBar.setVisibility(View.INVISIBLE);
});
if (hdw == null) {
runOnUiThread(() -> {
failures++;
Toast.makeText(PinEntryActivity.this, PinEntryActivity.this.getText(R.string.login_error) + ":" + failures + "/3", Toast.LENGTH_SHORT).show();
if (failures == 3) {
failures = 0;
doBackupRestore();
} else {
Intent intent = new Intent(PinEntryActivity.this, PinEntryActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
}
});
}
AccessFactory.getInstance(PinEntryActivity.this).setIsLoggedIn(true);
TimeOutUtil.getInstance().updatePin();
if (isOpenDime) {
runOnUiThread(() -> {
Intent intent = new Intent(PinEntryActivity.this, OpenDimeActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
});
} else {
AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
finish();
}
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} catch (DecoderException de) {
de.printStackTrace();
} finally {
runOnUiThread(() -> {
progressBar.setVisibility(View.INVISIBLE);
});
}
} else {
runOnUiThread(() -> {
progressBar.setVisibility(View.INVISIBLE);
failures++;
Toast.makeText(PinEntryActivity.this, PinEntryActivity.this.getText(R.string.login_error) + ":" + failures + "/3", Toast.LENGTH_SHORT).show();
if (failures == 3) {
failures = 0;
doBackupRestore();
} else {
Intent intent = new Intent(PinEntryActivity.this, PinEntryActivity.class);
// intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
if (getIntent().getExtras() != null)
intent.putExtras(getIntent().getExtras());
startActivity(intent);
finish();
}
});
}
runOnUiThread(() -> {
progressBar.setVisibility(View.INVISIBLE);
});
}).start();
}
Aggregations