Search in sources :

Example 31 with CharSequenceX

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);
}
Also used : CompositeDisposable(io.reactivex.disposables.CompositeDisposable) Disposable(io.reactivex.disposables.Disposable) CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONException(org.json.JSONException) IOException(java.io.IOException) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Example 32 with CharSequenceX

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();
}
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 33 with CharSequenceX

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

Example 34 with CharSequenceX

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();
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) HD_Wallet(com.samourai.wallet.hd.HD_Wallet) CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) IOException(java.io.IOException) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Example 35 with CharSequenceX

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);
    }
}
Also used : CharSequenceX(com.samourai.wallet.util.CharSequenceX) BalanceActivity(com.samourai.wallet.home.BalanceActivity) Intent(android.content.Intent)

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