Search in sources :

Example 21 with CharSequenceX

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

the class BalanceActivity method doSweepViaScan.

private void doSweepViaScan() {
    CameraFragmentBottomSheet cameraFragmentBottomSheet = new CameraFragmentBottomSheet();
    cameraFragmentBottomSheet.show(getSupportFragmentManager(), cameraFragmentBottomSheet.getTag());
    cameraFragmentBottomSheet.setQrCodeScanLisenter(code -> {
        cameraFragmentBottomSheet.dismissAllowingStateLoss();
        PrivKeyReader privKeyReader = new PrivKeyReader(new CharSequenceX(code.trim()));
        try {
            if (privKeyReader.getFormat() != null) {
                doPrivKey(code.trim());
            } else if (Cahoots.isCahoots(code.trim())) {
                Intent cahootIntent = new Intent(this, ManualCahootsActivity.class);
                cahootIntent.putExtra("payload", code.trim());
                cahootIntent.putExtra("_account", account);
                startActivity(cahootIntent);
            } else if (FormatsUtil.getInstance().isPSBT(code.trim())) {
                CahootsUtil.getInstance(BalanceActivity.this).doPSBT(code.trim());
            } else if (DojoUtil.getInstance(BalanceActivity.this).isValidPairingPayload(code.trim())) {
                Toast.makeText(BalanceActivity.this, "Samourai Dojo full node coming soon.", Toast.LENGTH_SHORT).show();
            } else {
                Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
                intent.putExtra("uri", code.trim());
                intent.putExtra("_account", account);
                startActivity(intent);
            }
        } catch (Exception e) {
        }
    });
}
Also used : CameraFragmentBottomSheet(com.samourai.wallet.fragments.CameraFragmentBottomSheet) CharSequenceX(com.samourai.wallet.util.CharSequenceX) SendActivity(com.samourai.wallet.send.SendActivity) PrivKeyReader(com.samourai.wallet.util.PrivKeyReader) Intent(android.content.Intent) ManualCahootsActivity(com.samourai.wallet.send.cahoots.ManualCahootsActivity) JSONException(org.json.JSONException) ConcurrentModificationException(java.util.ConcurrentModificationException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) MnemonicException(org.bitcoinj.crypto.MnemonicException)

Example 22 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);
            password38.setSingleLine(true);
            password38.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
            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, SweepUtil.TYPE_P2PKH);
                    }
                }
            }).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, SweepUtil.TYPE_P2PKH);
        } 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) ECKey(org.bitcoinj.core.ECKey) ProgressDialog(android.app.ProgressDialog) JSONException(org.json.JSONException) ConcurrentModificationException(java.util.ConcurrentModificationException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) MnemonicException(org.bitcoinj.crypto.MnemonicException) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint)

Example 23 with CharSequenceX

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

the class BIP47Activity method doSync.

private void doSync(final String pcode) {
    progress = new ProgressDialog(BIP47Activity.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() {
            try {
                PaymentCode payment_code = new PaymentCode(pcode);
                int idx = 0;
                boolean loop = true;
                ArrayList<String> addrs = new ArrayList<String>();
                while (loop) {
                    addrs.clear();
                    for (int i = idx; i < (idx + 20); i++) {
                        PaymentAddress receiveAddress = BIP47Util.getInstance(BIP47Activity.this).getReceiveAddress(payment_code, i);
                        // Log.i("BIP47Activity", "sync receive from " + i + ":" + receiveAddress.getReceiveECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
                        BIP47Meta.getInstance().setIncomingIdx(payment_code.toString(), i, receiveAddress.getReceiveECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
                        BIP47Meta.getInstance().getIdx4AddrLookup().put(receiveAddress.getReceiveECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString(), i);
                        BIP47Meta.getInstance().getPCode4AddrLookup().put(receiveAddress.getReceiveECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString(), payment_code.toString());
                        addrs.add(receiveAddress.getReceiveECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
                    }
                    String[] s = addrs.toArray(new String[addrs.size()]);
                    int nb = APIFactory.getInstance(BIP47Activity.this).syncBIP47Incoming(s);
                    // Log.i("BIP47Activity", "sync receive idx:" + idx + ", nb == " + nb);
                    if (nb == 0) {
                        loop = false;
                    }
                    idx += 20;
                }
                idx = 0;
                loop = true;
                BIP47Meta.getInstance().setOutgoingIdx(pcode, 0);
                while (loop) {
                    addrs.clear();
                    for (int i = idx; i < (idx + 20); i++) {
                        PaymentAddress sendAddress = BIP47Util.getInstance(BIP47Activity.this).getSendAddress(payment_code, i);
                        // Log.i("BIP47Activity", "sync send to " + i + ":" + sendAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
                        // BIP47Meta.getInstance().setOutgoingIdx(payment_code.toString(), i);
                        BIP47Meta.getInstance().getIdx4AddrLookup().put(sendAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString(), i);
                        BIP47Meta.getInstance().getPCode4AddrLookup().put(sendAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString(), payment_code.toString());
                        addrs.add(sendAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
                    }
                    String[] s = addrs.toArray(new String[addrs.size()]);
                    int nb = APIFactory.getInstance(BIP47Activity.this).syncBIP47Outgoing(s);
                    // Log.i("BIP47Activity", "sync send idx:" + idx + ", nb == " + nb);
                    if (nb == 0) {
                        loop = false;
                    }
                    idx += 20;
                }
                BIP47Meta.getInstance().pruneIncoming();
                PayloadUtil.getInstance(BIP47Activity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(BIP47Activity.this).getGUID() + AccessFactory.getInstance(BIP47Activity.this).getPIN()));
                Intent intent = new Intent("com.samourai.wallet.BalanceFragment.REFRESH");
                LocalBroadcastManager.getInstance(BIP47Activity.this).sendBroadcast(intent);
            } catch (IOException ioe) {
                ;
            } catch (JSONException je) {
                ;
            } catch (DecryptionException de) {
                ;
            } catch (NotSecp256k1Exception nse) {
                ;
            } catch (InvalidKeySpecException ikse) {
                ;
            } catch (InvalidKeyException ike) {
                ;
            } catch (NoSuchAlgorithmException nsae) {
                ;
            } catch (NoSuchProviderException nspe) {
                ;
            } catch (MnemonicException.MnemonicLengthException mle) {
                ;
            }
            if (progress != null && progress.isShowing()) {
                progress.dismiss();
                progress = null;
            }
            runOnUiThread(new Runnable() {

                @Override
                public void run() {
                    new Thread(new Runnable() {

                        @Override
                        public void run() {
                            if (refreshDisplay()) {
                                handler.post(new Runnable() {

                                    @Override
                                    public void run() {
                                        refreshList();
                                        adapter.notifyDataSetChanged();
                                    }
                                });
                            }
                        }
                    }).start();
                }
            });
        }
    }).start();
}
Also used : PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) CharSequenceX(com.samourai.wallet.util.CharSequenceX) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) Intent(android.content.Intent) PaymentAddress(com.samourai.wallet.bip47.rpc.PaymentAddress) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ProgressDialog(android.app.ProgressDialog) InvalidKeyException(java.security.InvalidKeyException) NotSecp256k1Exception(com.samourai.wallet.bip47.rpc.NotSecp256k1Exception) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) SecretPoint(com.samourai.wallet.bip47.rpc.SecretPoint) Point(android.graphics.Point) MnemonicException(org.bitcoinj.crypto.MnemonicException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchProviderException(java.security.NoSuchProviderException) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Example 24 with CharSequenceX

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

the class BIP47Activity method onDestroy.

@Override
protected void onDestroy() {
    killTimer();
    try {
        PayloadUtil.getInstance(BIP47Activity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(BIP47Activity.this).getGUID() + AccessFactory.getInstance(BIP47Activity.this).getPIN()));
    } catch (Exception e) {
        ;
    }
    super.onDestroy();
}
Also used : CharSequenceX(com.samourai.wallet.util.CharSequenceX) NotSecp256k1Exception(com.samourai.wallet.bip47.rpc.NotSecp256k1Exception) JSONException(org.json.JSONException) AddressFormatException(org.bitcoinj.core.AddressFormatException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) DecoderException(org.bouncycastle.util.encoders.DecoderException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MnemonicException(org.bitcoinj.crypto.MnemonicException) NoSuchProviderException(java.security.NoSuchProviderException)

Example 25 with CharSequenceX

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

the class MainActivity2 method doAppInit.

private void doAppInit(boolean isDial, final String strUri, final String strPCode) {
    if ((strUri != null || strPCode != null) && AccessFactory.getInstance(MainActivity2.this).isLoggedIn()) {
        progress = new ProgressDialog(MainActivity2.this);
        progress.setCancelable(false);
        progress.setTitle(R.string.app_name);
        progress.setMessage(getText(R.string.please_wait));
        progress.show();
        new Thread(new Runnable() {

            @Override
            public void run() {
                Looper.prepare();
                APIFactory.getInstance(MainActivity2.this).initWallet();
                if (progress != null && progress.isShowing()) {
                    progress.dismiss();
                    progress = null;
                }
                Intent intent = new Intent(MainActivity2.this, SendActivity.class);
                intent.putExtra("uri", strUri);
                intent.putExtra("pcode", strPCode);
                startActivity(intent);
                Looper.loop();
            }
        }).start();
    } else 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()) {
            doSelectNet();
        } else {
            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 == null ? null : strUri);
    } else if (AccessFactory.getInstance(MainActivity2.this).isLoggedIn() && !TimeOutUtil.getInstance().isTimedOut()) {
        TimeOutUtil.getInstance().updatePin();
        loadedBalanceFragment = true;
        Intent intent = new Intent(MainActivity2.this, BalanceActivity.class);
        intent.putExtra("notifTx", true);
        intent.putExtra("fetch", true);
        startActivity(intent);
    } else {
        AccessFactory.getInstance(MainActivity2.this).setIsLoggedIn(false);
        validatePIN(strUri == null ? null : strUri);
    }
}
Also used : CharSequenceX(com.samourai.wallet.util.CharSequenceX) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog)

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