use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class UTXOSActivity method saveWalletState.
private void saveWalletState() {
Disposable disposable = Completable.fromCallable(() -> {
try {
PayloadUtil.getInstance(getApplicationContext()).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(getApplicationContext()).getGUID() + AccessFactory.getInstance().getPIN()));
} catch (MnemonicException.MnemonicLengthException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (DecryptionException e) {
e.printStackTrace();
}
return true;
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe();
compositeDisposable.add(disposable);
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class RestoreSeedWalletActivity method RestoreFromMnemonic.
private void RestoreFromMnemonic(final boolean create, final String pin, final String passphrase, final String seed) {
toggleLoading();
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
String guid = AccessFactory.getInstance(RestoreSeedWalletActivity.this).createGUID();
String hash = AccessFactory.getInstance(RestoreSeedWalletActivity.this).getHash(guid, new CharSequenceX(pin), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
if (create) {
try {
HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).newWallet(12, passphrase, SamouraiWallet.NB_ACCOUNTS);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} finally {
;
}
} else if (seed == null) {
;
} else {
try {
HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).restoreWallet(seed, passphrase, SamouraiWallet.NB_ACCOUNTS);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (DecoderException de) {
de.printStackTrace();
} catch (AddressFormatException afe) {
afe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} catch (MnemonicException.MnemonicChecksumException mce) {
mce.printStackTrace();
} catch (MnemonicException.MnemonicWordException mwe) {
mwe.printStackTrace();
} finally {
;
}
}
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.SCRAMBLE_PIN, true);
try {
String msg = null;
if (HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).get() != null) {
if (create) {
msg = getString(R.string.wallet_created_ok);
} else {
msg = getString(R.string.wallet_restored_ok);
}
try {
AccessFactory.getInstance(RestoreSeedWalletActivity.this).setPIN(pin);
PayloadUtil.getInstance(RestoreSeedWalletActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(RestoreSeedWalletActivity.this).getGUID() + pin));
if (create) {
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "new");
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
} else {
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "restored");
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
}
} catch (JSONException je) {
je.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (DecryptionException de) {
de.printStackTrace();
} finally {
;
}
AddressFactory.getInstance().account2xpub().put(0, HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).get().getAccount(0).xpubstr());
AddressFactory.getInstance().xpub2account().put(HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).get().getAccount(0).xpubstr(), 0);
//
if (create) {
String seed = null;
try {
seed = HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).get().getMnemonic();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
}
Intent intent = new Intent(RestoreSeedWalletActivity.this, RecoveryWordsActivity.class);
intent.putExtra("BIP39_WORD_LIST", seed);
startActivity(intent);
finish();
} else {
AccessFactory.getInstance(RestoreSeedWalletActivity.this).setIsLoggedIn(true);
TimeOutUtil.getInstance().updatePin();
AppUtil.getInstance(RestoreSeedWalletActivity.this).restartApp();
}
} else {
if (create) {
msg = getString(R.string.wallet_created_ko);
} else {
msg = getString(R.string.wallet_restored_ko);
}
}
Toast.makeText(RestoreSeedWalletActivity.this, msg, Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} finally {
;
}
toggleLoading();
Looper.loop();
}
}).start();
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class RestoreSeedWalletActivity method RestoreWalletFromSamouraiBackup.
private void RestoreWalletFromSamouraiBackup(final String decrypted) {
toggleLoading();
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
try {
JSONObject json = new JSONObject(decrypted);
HD_Wallet hdw = PayloadUtil.getInstance(RestoreSeedWalletActivity.this).restoreWalletfromJSON(json);
HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).set(hdw);
String guid = AccessFactory.getInstance(RestoreSeedWalletActivity.this).createGUID();
String hash = AccessFactory.getInstance(RestoreSeedWalletActivity.this).getHash(guid, new CharSequenceX(AccessFactory.getInstance(RestoreSeedWalletActivity.this).getPIN()), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
PayloadUtil.getInstance(RestoreSeedWalletActivity.this).saveWalletToJSON(new CharSequenceX(guid + AccessFactory.getInstance().getPIN()));
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (DecoderException de) {
de.printStackTrace();
Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (JSONException je) {
je.printStackTrace();
Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
ioe.printStackTrace();
Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (java.lang.NullPointerException npe) {
npe.printStackTrace();
Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (DecryptionException de) {
de.printStackTrace();
Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} finally {
AppUtil.getInstance(RestoreSeedWalletActivity.this).restartApp();
}
Looper.loop();
toggleLoading();
}
}).start();
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class LandingActivity method RestoreWalletFromSamouraiBackup.
private void RestoreWalletFromSamouraiBackup(final String decrypted) {
toggleLoading();
new Thread(() -> {
Looper.prepare();
try {
JSONObject json = new JSONObject(decrypted);
HD_Wallet hdw = PayloadUtil.getInstance(LandingActivity.this).restoreWalletfromJSON(json);
HD_WalletFactory.getInstance(LandingActivity.this).set(hdw);
String guid = AccessFactory.getInstance(LandingActivity.this).createGUID();
String hash = AccessFactory.getInstance(LandingActivity.this).getHash(guid, new CharSequenceX(AccessFactory.getInstance(LandingActivity.this).getPIN()), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(LandingActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
PrefsUtil.getInstance(LandingActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
PayloadUtil.getInstance(LandingActivity.this).saveWalletToJSON(new CharSequenceX(guid + AccessFactory.getInstance().getPIN()));
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (DecoderException de) {
de.printStackTrace();
Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (JSONException je) {
je.printStackTrace();
Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
ioe.printStackTrace();
Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (NullPointerException npe) {
npe.printStackTrace();
Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (DecryptionException de) {
de.printStackTrace();
Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} finally {
AppUtil.getInstance(LandingActivity.this).restartApp();
}
Looper.loop();
toggleLoading();
}).start();
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class MainActivity2 method doAppInit1.
private void doAppInit1(boolean isDial, final String strUri, final String strPCode) {
if (AccessFactory.getInstance(MainActivity2.this).getGUID().length() < 1 || !PayloadUtil.getInstance(MainActivity2.this).walletFileExists()) {
AccessFactory.getInstance(MainActivity2.this).setIsLoggedIn(false);
if (AppUtil.getInstance(MainActivity2.this).isSideLoaded()) {
runOnUiThread(this::doSelectNet);
} else {
runOnUiThread(this::initDialog);
}
} else if (isDial && AccessFactory.getInstance(MainActivity2.this).validateHash(PrefsUtil.getInstance(MainActivity2.this).getValue(PrefsUtil.ACCESS_HASH, ""), AccessFactory.getInstance(MainActivity2.this).getGUID(), new CharSequenceX(AccessFactory.getInstance(MainActivity2.this).getPIN()), AESUtil.DefaultPBKDF2Iterations)) {
TimeOutUtil.getInstance().updatePin();
launchFromDialer(AccessFactory.getInstance(MainActivity2.this).getPIN());
} else if (TimeOutUtil.getInstance().isTimedOut()) {
AccessFactory.getInstance(MainActivity2.this).setIsLoggedIn(false);
validatePIN(strUri);
} else if (AccessFactory.getInstance(MainActivity2.this).isLoggedIn() && !TimeOutUtil.getInstance().isTimedOut()) {
TimeOutUtil.getInstance().updatePin();
Intent intent = new Intent(MainActivity2.this, BalanceActivity.class);
intent.putExtra("notifTx", true);
intent.putExtra("fetch", true);
if (getBundleExtras() != null) {
intent.putExtras(getBundleExtras());
}
startActivity(intent);
} else {
AccessFactory.getInstance(MainActivity2.this).setIsLoggedIn(false);
validatePIN(strUri == null ? null : strUri);
}
}
Aggregations