use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class MainActivity2 method launchFromDialer.
private void launchFromDialer(final String pin) {
if (progress != null && progress.isShowing()) {
progress.dismiss();
progress = null;
}
progress = new ProgressDialog(MainActivity2.this);
progress.setCancelable(false);
progress.setTitle(R.string.app_name);
progress.setMessage(getString(R.string.please_wait));
progress.show();
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
try {
PayloadUtil.getInstance(MainActivity2.this).restoreWalletfromJSON(new CharSequenceX(AccessFactory.getInstance(MainActivity2.this).getGUID() + pin));
if (progress != null && progress.isShowing()) {
progress.dismiss();
progress = null;
}
AccessFactory.getInstance(MainActivity2.this).setIsLoggedIn(true);
TimeOutUtil.getInstance().updatePin();
AppUtil.getInstance(MainActivity2.this).restartApp();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} catch (DecoderException de) {
de.printStackTrace();
} finally {
if (progress != null && progress.isShowing()) {
progress.dismiss();
progress = null;
}
}
Looper.loop();
}
}).start();
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class CreateWalletActivity method initThread.
/**
* Creates new wallet account
*
* @param create
* @param pin
* @param passphrase
* @param seed
*/
private void initThread(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(CreateWalletActivity.this).createGUID();
String hash = AccessFactory.getInstance(CreateWalletActivity.this).getHash(guid, new CharSequenceX(pin), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
if (create) {
try {
HD_WalletFactory.getInstance(CreateWalletActivity.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(CreateWalletActivity.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(CreateWalletActivity.this).setValue(PrefsUtil.SCRAMBLE_PIN, true);
try {
String msg = null;
if (HD_WalletFactory.getInstance(CreateWalletActivity.this).get() != null) {
if (create) {
msg = getString(R.string.wallet_created_ok);
} else {
msg = getString(R.string.wallet_restored_ok);
}
try {
AccessFactory.getInstance(CreateWalletActivity.this).setPIN(pin);
PayloadUtil.getInstance(CreateWalletActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(CreateWalletActivity.this).getGUID() + pin));
if (create) {
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "new");
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
} else {
PrefsUtil.getInstance(CreateWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "restored");
PrefsUtil.getInstance(CreateWalletActivity.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(CreateWalletActivity.this).get().getAccount(0).xpubstr());
AddressFactory.getInstance().xpub2account().put(HD_WalletFactory.getInstance(CreateWalletActivity.this).get().getAccount(0).xpubstr(), 0);
//
if (create) {
String seed = null;
try {
seed = HD_WalletFactory.getInstance(CreateWalletActivity.this).get().getMnemonic();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
}
Intent intent = new Intent(CreateWalletActivity.this, RecoveryWordsActivity.class);
intent.putExtra("BIP39_WORD_LIST", seed);
startActivity(intent);
finish();
} else {
AccessFactory.getInstance(CreateWalletActivity.this).setIsLoggedIn(true);
TimeOutUtil.getInstance().updatePin();
AppUtil.getInstance(CreateWalletActivity.this).restartApp();
}
} else {
if (create) {
msg = getString(R.string.wallet_created_ko);
} else {
msg = getString(R.string.wallet_restored_ko);
}
}
Toast.makeText(CreateWalletActivity.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 LandingActivity method RestoreWalletFromBackup.
public void RestoreWalletFromBackup() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Restore backup");
LayoutInflater inflater = getLayoutInflater();
View view = inflater.inflate(R.layout.landing_restore_dialog, null);
final EditText password = view.findViewById(R.id.restore_dialog_password_edittext);
builder.setView(view);
builder.setPositiveButton("RESTORE", (dialog, which) -> {
dialog.dismiss();
String backupData = readFromBackupFile();
final String decrypted = PayloadUtil.getInstance(LandingActivity.this).getDecryptedBackupPayload(backupData, new CharSequenceX(password.getText()));
if (decrypted == null || decrypted.length() < 1) {
Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} else {
RestoreWalletFromSamouraiBackup(decrypted);
}
});
builder.setNegativeButton("CANCEL", (dialog, which) -> dialog.cancel());
AlertDialog alert = builder.create();
alert.show();
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class PayNymDetailsActivity method savePayLoad.
private void savePayLoad() throws MnemonicException.MnemonicLengthException, DecryptionException, JSONException, IOException {
PayloadUtil.getInstance(PayNymDetailsActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(PayNymDetailsActivity.this).getGUID() + AccessFactory.getInstance(PayNymDetailsActivity.this).getPIN()));
Log.i(TAG, "savePayLoad: ");
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class BIP47Add method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == android.R.id.home) {
finish();
} else if (id == R.id.action_add) {
View view = BIP47Add.this.getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
String label = edLabel.getText().toString();
final String pcode = edPCode.getText().toString();
if (pcode == null || pcode.length() < 1 || !FormatsUtil.getInstance().isValidPaymentCode(pcode)) {
Toast.makeText(BIP47Add.this, R.string.invalid_payment_code, Toast.LENGTH_SHORT).show();
} else if (label == null || label.length() < 1) {
Toast.makeText(BIP47Add.this, R.string.bip47_no_label_error, Toast.LENGTH_SHORT).show();
} else {
BIP47Meta.getInstance().setLabel(pcode, label);
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
try {
PayloadUtil.getInstance(BIP47Add.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(BIP47Add.this).getGUID() + AccessFactory.getInstance().getPIN()));
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
Toast.makeText(BIP47Add.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (DecoderException de) {
de.printStackTrace();
Toast.makeText(BIP47Add.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (JSONException je) {
je.printStackTrace();
Toast.makeText(BIP47Add.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
ioe.printStackTrace();
Toast.makeText(BIP47Add.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (java.lang.NullPointerException npe) {
npe.printStackTrace();
Toast.makeText(BIP47Add.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} catch (DecryptionException de) {
de.printStackTrace();
Toast.makeText(BIP47Add.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
} finally {
;
}
Looper.loop();
}
}).start();
Intent resultIntent = new Intent();
resultIntent.putExtra("pcode", pcode);
setResult(Activity.RESULT_OK, resultIntent);
finish();
}
} else {
;
}
return super.onOptionsItemSelected(item);
}
Aggregations