Search in sources :

Example 26 with CharSequenceX

use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.

the class BalanceActivity method doClipboardCheck.

private void doClipboardCheck() {
    final android.content.ClipboardManager clipboard = (android.content.ClipboardManager) BalanceActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
    if (clipboard.hasPrimaryClip()) {
        final ClipData clip = clipboard.getPrimaryClip();
        ClipData.Item item = clip.getItemAt(0);
        if (item.getText() != null) {
            String text = item.getText().toString();
            String[] s = text.split("\\s+");
            try {
                for (int i = 0; i < s.length; i++) {
                    PrivKeyReader privKeyReader = new PrivKeyReader(new CharSequenceX(s[i]));
                    if (privKeyReader.getFormat() != null && (privKeyReader.getFormat().equals(PrivKeyReader.WIF_COMPRESSED) || privKeyReader.getFormat().equals(PrivKeyReader.WIF_UNCOMPRESSED) || privKeyReader.getFormat().equals(PrivKeyReader.BIP38))) {
                        new AlertDialog.Builder(BalanceActivity.this).setTitle(R.string.app_name).setMessage(R.string.privkey_clipboard).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                clipboard.setPrimaryClip(ClipData.newPlainText("", ""));
                            }
                        }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                ;
                            }
                        }).show();
                    }
                }
            } catch (Exception e) {
                ;
            }
        }
    }
}
Also used : CharSequenceX(com.samourai.wallet.util.CharSequenceX) DialogInterface(android.content.DialogInterface) PrivKeyReader(com.samourai.wallet.util.PrivKeyReader) ScriptBuilder(org.bitcoinj.script.ScriptBuilder) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) JSONException(org.json.JSONException) AddressFormatException(org.bitcoinj.core.AddressFormatException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) DecoderException(org.bouncycastle.util.encoders.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) OnClickListener(android.view.View.OnClickListener) ClipData(android.content.ClipData)

Example 27 with CharSequenceX

use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.

the class BalanceActivity method onKeyDown.

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ask_you_sure_exit).setCancelable(false);
        AlertDialog alert = builder.create();
        alert.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.yes), new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
                try {
                    PayloadUtil.getInstance(BalanceActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(BalanceActivity.this).getGUID() + AccessFactory.getInstance(BalanceActivity.this).getPIN()));
                } catch (MnemonicException.MnemonicLengthException mle) {
                    ;
                } catch (JSONException je) {
                    ;
                } catch (IOException ioe) {
                    ;
                } catch (DecryptionException de) {
                    ;
                }
                Intent intent = new Intent(BalanceActivity.this, ExodusActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                BalanceActivity.this.startActivity(intent);
            }
        });
        alert.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.no), new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int id) {
                dialog.dismiss();
            }
        });
        if (!isFinishing()) {
            alert.show();
        }
        return true;
    } else {
        ;
    }
    return false;
}
Also used : AlertDialog(android.app.AlertDialog) CharSequenceX(com.samourai.wallet.util.CharSequenceX) DialogInterface(android.content.DialogInterface) ScriptBuilder(org.bitcoinj.script.ScriptBuilder) JSONException(org.json.JSONException) Intent(android.content.Intent) IOException(java.io.IOException) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Example 28 with CharSequenceX

use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.

the class BalanceActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == Activity.RESULT_OK && requestCode == SCAN_COLD_STORAGE) {
        if (data != null && data.getStringExtra(ZBarConstants.SCAN_RESULT) != null) {
            final String strResult = data.getStringExtra(ZBarConstants.SCAN_RESULT);
            doPrivKey(strResult);
        }
    } else if (resultCode == Activity.RESULT_CANCELED && requestCode == SCAN_COLD_STORAGE) {
        ;
    } else if (resultCode == Activity.RESULT_OK && requestCode == SCAN_QR) {
        if (data != null && data.getStringExtra(ZBarConstants.SCAN_RESULT) != null) {
            final String strResult = data.getStringExtra(ZBarConstants.SCAN_RESULT);
            PrivKeyReader privKeyReader = new PrivKeyReader(new CharSequenceX(strResult));
            try {
                if (privKeyReader.getFormat() != null) {
                    doPrivKey(strResult);
                } else {
                    Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
                    intent.putExtra("uri", strResult);
                    startActivity(intent);
                }
            } catch (Exception e) {
                ;
            }
        }
    } else if (resultCode == Activity.RESULT_CANCELED && requestCode == SCAN_QR) {
        ;
    } else {
        ;
    }
}
Also used : CharSequenceX(com.samourai.wallet.util.CharSequenceX) PrivKeyReader(com.samourai.wallet.util.PrivKeyReader) Intent(android.content.Intent) JSONException(org.json.JSONException) AddressFormatException(org.bitcoinj.core.AddressFormatException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) DecoderException(org.bouncycastle.util.encoders.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException)

Example 29 with CharSequenceX

use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.

the class BalanceActivity method doPrivKey.

private void doPrivKey(final String data) {
    PrivKeyReader privKeyReader = null;
    String format = null;
    try {
        privKeyReader = new PrivKeyReader(new CharSequenceX(data), null);
        format = privKeyReader.getFormat();
    } catch (Exception e) {
        Toast.makeText(BalanceActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
        return;
    }
    if (format != null) {
        if (format.equals(PrivKeyReader.BIP38)) {
            final PrivKeyReader pvr = privKeyReader;
            final EditText password38 = new EditText(BalanceActivity.this);
            AlertDialog.Builder dlg = new AlertDialog.Builder(BalanceActivity.this).setTitle(R.string.app_name).setMessage(R.string.bip38_pw).setView(password38).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    String password = password38.getText().toString();
                    ProgressDialog progress = new ProgressDialog(BalanceActivity.this);
                    progress.setCancelable(false);
                    progress.setTitle(R.string.app_name);
                    progress.setMessage(getString(R.string.decrypting_bip38));
                    progress.show();
                    boolean keyDecoded = false;
                    try {
                        BIP38PrivateKey bip38 = new BIP38PrivateKey(SamouraiWallet.getInstance().getCurrentNetworkParams(), data);
                        final ECKey ecKey = bip38.decrypt(password);
                        if (ecKey != null && ecKey.hasPrivKey()) {
                            if (progress != null && progress.isShowing()) {
                                progress.cancel();
                            }
                            pvr.setPassword(new CharSequenceX(password));
                            keyDecoded = true;
                            Toast.makeText(BalanceActivity.this, pvr.getFormat(), Toast.LENGTH_SHORT).show();
                            Toast.makeText(BalanceActivity.this, pvr.getKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString(), Toast.LENGTH_SHORT).show();
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        Toast.makeText(BalanceActivity.this, R.string.bip38_pw_error, Toast.LENGTH_SHORT).show();
                    }
                    if (progress != null && progress.isShowing()) {
                        progress.cancel();
                    }
                    if (keyDecoded) {
                        SweepUtil.getInstance(BalanceActivity.this).sweep(pvr, false);
                    }
                }
            }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    Toast.makeText(BalanceActivity.this, R.string.bip38_pw_error, Toast.LENGTH_SHORT).show();
                }
            });
            if (!isFinishing()) {
                dlg.show();
            }
        } else if (privKeyReader != null) {
            SweepUtil.getInstance(BalanceActivity.this).sweep(privKeyReader, false);
        } else {
            ;
        }
    } else {
        Toast.makeText(BalanceActivity.this, R.string.cannot_recognize_privkey, Toast.LENGTH_SHORT).show();
    }
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) CharSequenceX(com.samourai.wallet.util.CharSequenceX) DialogInterface(android.content.DialogInterface) BIP38PrivateKey(org.bitcoinj.crypto.BIP38PrivateKey) PrivKeyReader(com.samourai.wallet.util.PrivKeyReader) ScriptBuilder(org.bitcoinj.script.ScriptBuilder) ECKey(org.bitcoinj.core.ECKey) ProgressDialog(android.app.ProgressDialog) JSONException(org.json.JSONException) AddressFormatException(org.bitcoinj.core.AddressFormatException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) DecoderException(org.bouncycastle.util.encoders.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) OnClickListener(android.view.View.OnClickListener)

Example 30 with CharSequenceX

use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.

the class UTXODetailsActivity 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)

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