Search in sources :

Example 16 with CharSequenceX

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();
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) CharSequenceX(com.samourai.wallet.util.CharSequenceX) ProgressDialog(android.app.ProgressDialog)

Example 17 with CharSequenceX

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();
}
Also used : AddressFormatException(org.bitcoinj.core.AddressFormatException) CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONException(org.json.JSONException) Intent(android.content.Intent) IOException(java.io.IOException) DecoderException(org.apache.commons.codec.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Example 18 with CharSequenceX

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();
}
Also used : AlertDialog(android.app.AlertDialog) EditText(android.widget.EditText) CharSequenceX(com.samourai.wallet.util.CharSequenceX) LayoutInflater(android.view.LayoutInflater) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 19 with CharSequenceX

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: ");
}
Also used : CharSequenceX(com.samourai.wallet.util.CharSequenceX)

Example 20 with CharSequenceX

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);
}
Also used : CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONException(org.json.JSONException) InputMethodManager(android.view.inputmethod.InputMethodManager) Intent(android.content.Intent) IOException(java.io.IOException) View(android.view.View) DecoderException(org.bouncycastle.util.encoders.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Aggregations

CharSequenceX (com.samourai.wallet.util.CharSequenceX)51 IOException (java.io.IOException)38 JSONException (org.json.JSONException)37 DecryptionException (com.samourai.wallet.crypto.DecryptionException)35 MnemonicException (org.bitcoinj.crypto.MnemonicException)35 Intent (android.content.Intent)22 AlertDialog (android.app.AlertDialog)14 DialogInterface (android.content.DialogInterface)14 JSONObject (org.json.JSONObject)14 AddressFormatException (org.bitcoinj.core.AddressFormatException)13 DecoderException (org.bouncycastle.util.encoders.DecoderException)10 DecoderException (org.apache.commons.codec.DecoderException)9 EditText (android.widget.EditText)8 PrivKeyReader (com.samourai.wallet.util.PrivKeyReader)8 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)7 ProgressDialog (android.app.ProgressDialog)6 PaymentCode (com.samourai.wallet.bip47.rpc.PaymentCode)6 FileNotFoundException (java.io.FileNotFoundException)6 ConcurrentModificationException (java.util.ConcurrentModificationException)6 ClipData (android.content.ClipData)4