Search in sources :

Example 36 with CharSequenceX

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

the class PinEntryActivity method validateThread.

private void validateThread(final String pin, final String uri) {
    progressBar.setVisibility(View.VISIBLE);
    new Thread(() -> {
        Looper.prepare();
        if (pin.length() < AccessFactory.MIN_PIN_LENGTH || pin.length() > AccessFactory.MAX_PIN_LENGTH) {
            runOnUiThread(() -> {
                progressBar.setVisibility(View.INVISIBLE);
            });
            Toast.makeText(PinEntryActivity.this, R.string.pin_error, Toast.LENGTH_SHORT).show();
            AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
            finish();
        }
        String randomKey = AccessFactory.getInstance(PinEntryActivity.this).getGUID();
        if (randomKey.length() < 1) {
            runOnUiThread(() -> {
                progressBar.setVisibility(View.INVISIBLE);
            });
            Toast.makeText(PinEntryActivity.this, R.string.random_key_error, Toast.LENGTH_SHORT).show();
            AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
            finish();
        }
        String hash = PrefsUtil.getInstance(PinEntryActivity.this).getValue(PrefsUtil.ACCESS_HASH, "");
        if (AccessFactory.getInstance(PinEntryActivity.this).validateHash(hash, randomKey, new CharSequenceX(pin), AESUtil.DefaultPBKDF2Iterations)) {
            AccessFactory.getInstance(PinEntryActivity.this).setPIN(pin);
            try {
                HD_Wallet hdw = PayloadUtil.getInstance(PinEntryActivity.this).restoreWalletfromJSON(new CharSequenceX(AccessFactory.getInstance(PinEntryActivity.this).getGUID() + pin));
                runOnUiThread(() -> {
                    progressBar.setVisibility(View.INVISIBLE);
                });
                if (hdw == null) {
                    runOnUiThread(() -> {
                        failures++;
                        Toast.makeText(PinEntryActivity.this, PinEntryActivity.this.getText(R.string.login_error) + ":" + failures + "/3", Toast.LENGTH_SHORT).show();
                        if (failures == 3) {
                            failures = 0;
                            doBackupRestore();
                        } else {
                            Intent intent = new Intent(PinEntryActivity.this, PinEntryActivity.class);
                            // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                            startActivity(intent);
                            finish();
                        }
                    });
                }
                AccessFactory.getInstance(PinEntryActivity.this).setIsLoggedIn(true);
                TimeOutUtil.getInstance().updatePin();
                if (isOpenDime) {
                    runOnUiThread(() -> {
                        Intent intent = new Intent(PinEntryActivity.this, OpenDimeActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                        startActivity(intent);
                    });
                } else {
                    AppUtil.getInstance(PinEntryActivity.this).restartApp(getIntent().getExtras());
                    finish();
                }
            } catch (MnemonicException.MnemonicLengthException mle) {
                mle.printStackTrace();
            } catch (DecoderException de) {
                de.printStackTrace();
            } finally {
                runOnUiThread(() -> {
                    progressBar.setVisibility(View.INVISIBLE);
                });
            }
        } else {
            runOnUiThread(() -> {
                progressBar.setVisibility(View.INVISIBLE);
                failures++;
                Toast.makeText(PinEntryActivity.this, PinEntryActivity.this.getText(R.string.login_error) + ":" + failures + "/3", Toast.LENGTH_SHORT).show();
                if (failures == 3) {
                    failures = 0;
                    doBackupRestore();
                } else {
                    Intent intent = new Intent(PinEntryActivity.this, PinEntryActivity.class);
                    // intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                    if (getIntent().getExtras() != null)
                        intent.putExtras(getIntent().getExtras());
                    startActivity(intent);
                    finish();
                }
            });
        }
        runOnUiThread(() -> {
            progressBar.setVisibility(View.INVISIBLE);
        });
    }).start();
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) HD_Wallet(com.samourai.wallet.hd.HD_Wallet) CharSequenceX(com.samourai.wallet.util.CharSequenceX) Intent(android.content.Intent)

Example 37 with CharSequenceX

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

the class SettingsActivity2 method getTrustedNode.

private void getTrustedNode() {
    final EditText edNode = new EditText(SettingsActivity2.this);
    edNode.setHint(R.string.trusted_node_ip_hint);
    edNode.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    edNode.setText(TrustedNodeUtil.getInstance().getNode() == null ? "" : TrustedNodeUtil.getInstance().getNode());
    final EditText edPort = new EditText(SettingsActivity2.this);
    edPort.setHint(R.string.trusted_node_port_hint);
    edPort.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_CLASS_NUMBER);
    edPort.setText(TrustedNodeUtil.getInstance().getPort() == 0 ? Integer.toString(TrustedNodeUtil.DEFAULT_PORT) : Integer.toString(TrustedNodeUtil.getInstance().getPort()));
    final EditText edUser = new EditText(SettingsActivity2.this);
    edUser.setHint(R.string.trusted_node_user_hint);
    edUser.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
    edUser.setText(TrustedNodeUtil.getInstance().getUser() == null ? "" : TrustedNodeUtil.getInstance().getUser());
    final EditText edPassword = new EditText(SettingsActivity2.this);
    edPassword.setHint(R.string.trusted_node_password_hint);
    edPassword.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    edPassword.setSingleLine(true);
    edPassword.setText(TrustedNodeUtil.getInstance().getPassword() == null ? "" : TrustedNodeUtil.getInstance().getPassword());
    LinearLayout restoreLayout = new LinearLayout(SettingsActivity2.this);
    restoreLayout.setOrientation(LinearLayout.VERTICAL);
    restoreLayout.addView(edNode);
    restoreLayout.addView(edPort);
    restoreLayout.addView(edUser);
    restoreLayout.addView(edPassword);
    AlertDialog.Builder dlg = new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.trusted_node).setView(restoreLayout).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            final String node = edNode.getText().toString();
            final String port = edPort.getText().toString().length() == 0 ? Integer.toString(TrustedNodeUtil.DEFAULT_PORT) : edPort.getText().toString();
            final String user = edUser.getText().toString();
            final String password = edPassword.getText().toString();
            if (node != null && node.length() > 0 && port != null && port.length() > 0 && user != null && user.length() > 0 && password != null && password.length() > 0) {
                TrustedNodeUtil.getInstance().setParams(user, new CharSequenceX(password), node, Integer.parseInt(port));
                final Handler handler = new Handler();
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        Looper.prepare();
                        final CheckBoxPreference cbPref8 = (CheckBoxPreference) SettingsActivity2.this.findPreference("useTrustedNode");
                        boolean isOK = false;
                        JSONRPC jsonrpc = new JSONRPC(user, new CharSequenceX(password), node, Integer.parseInt(port));
                        String result = jsonrpc.getNetworkInfoAsString();
                        Log.d("TrustedNodeUtil", "getnetworkinfo:" + result);
                        if (result != null) {
                            try {
                                JSONObject obj = new JSONObject(result);
                                if (obj != null && obj.has("version") && obj.has("subversion")) {
                                    if (obj.getString("subversion").contains("Bitcoin XT") || obj.getString("subversion").contains("Classic") || obj.getString("subversion").contains("BitcoinUnlimited") || obj.getString("subversion").contains("SegWit2x") || obj.getString("subversion").contains("Segwit2x") || obj.getString("subversion").contains("Bitcoin ABC") || obj.getString("subversion").contains("Satoshi:1.14")) {
                                        Toast.makeText(SettingsActivity2.this, R.string.trusted_node_breaks_consensus, Toast.LENGTH_SHORT).show();
                                    } else if (obj.getInt("version") < 130100 || !obj.getString("subversion").contains("Satoshi")) {
                                        isOK = true;
                                        Toast.makeText(SettingsActivity2.this, R.string.trusted_node_not_core_131, Toast.LENGTH_SHORT).show();
                                    } else {
                                        isOK = true;
                                        Toast.makeText(SettingsActivity2.this, "Trusted node running:\n" + obj.getString("subversion") + ", " + obj.getInt("version"), Toast.LENGTH_SHORT).show();
                                    }
                                } else {
                                    Toast.makeText(SettingsActivity2.this, R.string.trusted_node_ko, Toast.LENGTH_SHORT).show();
                                }
                            } catch (Exception e) {
                                Toast.makeText(SettingsActivity2.this, e.getMessage() + "\n" + R.string.trusted_node_error, Toast.LENGTH_SHORT).show();
                            }
                        } else {
                            Toast.makeText(SettingsActivity2.this, R.string.trusted_node_not_responding, Toast.LENGTH_SHORT).show();
                        }
                        final boolean _isOK = isOK;
                        handler.post(new Runnable() {

                            @Override
                            public void run() {
                                if (_isOK) {
                                    cbPref8.setEnabled(true);
                                    TrustedNodeUtil.getInstance().setValidated(true);
                                } else {
                                    cbPref8.setChecked(false);
                                    cbPref8.setEnabled(false);
                                    PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.USE_TRUSTED_NODE, false);
                                    PrefsUtil.getInstance(SettingsActivity2.this).setValue(PrefsUtil.FEE_PROVIDER_SEL, 0);
                                    TrustedNodeUtil.getInstance().setValidated(false);
                                }
                                SettingsActivity2.this.recreate();
                            }
                        });
                        Looper.loop();
                    }
                }).start();
                dialog.dismiss();
            } else if ((node == null || node.length() == 0) && (port == null || port.length() == 0) && (user == null || user.length() == 0) && (password == null || password.length() == 0)) {
                TrustedNodeUtil.getInstance().reset();
            } else {
                Toast.makeText(SettingsActivity2.this, R.string.trusted_node_not_valid, Toast.LENGTH_SHORT).show();
            }
        }
    }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int whichButton) {
            dialog.dismiss();
        }
    });
    if (!isFinishing()) {
        dlg.show();
    }
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) CharSequenceX(com.samourai.wallet.util.CharSequenceX) DialogInterface(android.content.DialogInterface) CheckBoxPreference(android.preference.CheckBoxPreference) Handler(android.os.Handler) WriterException(com.google.zxing.WriterException) JSONException(org.json.JSONException) FileNotFoundException(java.io.FileNotFoundException) MnemonicException(org.bitcoinj.crypto.MnemonicException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) JSONRPC(com.samourai.wallet.JSONRPC.JSONRPC) JSONObject(org.json.JSONObject) LinearLayout(android.widget.LinearLayout)

Example 38 with CharSequenceX

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

the class SettingsActivity2 method doTroubleshoot.

private void doTroubleshoot() {
    try {
        final String strExpected = HD_WalletFactory.getInstance(SettingsActivity2.this).get().getPassphrase();
        final EditText passphrase = new EditText(SettingsActivity2.this);
        passphrase.setSingleLine(true);
        passphrase.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        AlertDialog.Builder dlg = new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.wallet_passphrase).setView(passphrase).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                final String _passphrase39 = passphrase.getText().toString();
                if (_passphrase39.equals(strExpected)) {
                    Toast.makeText(SettingsActivity2.this, R.string.bip39_match, Toast.LENGTH_SHORT).show();
                    final File file = PayloadUtil.getInstance(SettingsActivity2.this).getBackupFile();
                    if (file != null && file.exists()) {
                        new AlertDialog.Builder(SettingsActivity2.this).setTitle(R.string.app_name).setMessage(R.string.bip39_decrypt_test).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                new Thread(new Runnable() {

                                    @Override
                                    public void run() {
                                        Looper.prepare();
                                        StringBuilder sb = new StringBuilder();
                                        try {
                                            BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF8"));
                                            String str = null;
                                            while ((str = in.readLine()) != null) {
                                                sb.append(str);
                                            }
                                            in.close();
                                            String data = sb.toString();
                                            String decrypted = PayloadUtil.getInstance(SettingsActivity2.this).getDecryptedBackupPayload(data, new CharSequenceX(_passphrase39));
                                            if (decrypted == null || decrypted.length() < 1) {
                                                Toast.makeText(SettingsActivity2.this, R.string.backup_read_error, Toast.LENGTH_SHORT).show();
                                            } else {
                                                Toast.makeText(SettingsActivity2.this, R.string.backup_read_ok, Toast.LENGTH_SHORT).show();
                                            }
                                        } catch (FileNotFoundException fnfe) {
                                            Toast.makeText(SettingsActivity2.this, R.string.backup_read_error, Toast.LENGTH_SHORT).show();
                                        } catch (IOException ioe) {
                                            Toast.makeText(SettingsActivity2.this, R.string.backup_read_error, Toast.LENGTH_SHORT).show();
                                        }
                                        Looper.loop();
                                    }
                                }).start();
                            }
                        }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int whichButton) {
                                ;
                            }
                        }).show();
                    }
                } else {
                    Toast.makeText(SettingsActivity2.this, R.string.invalid_passphrase, Toast.LENGTH_SHORT).show();
                }
            }
        }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int whichButton) {
                ;
            }
        });
        if (!isFinishing()) {
            dlg.show();
        }
    } catch (IOException ioe) {
        ioe.printStackTrace();
        Toast.makeText(SettingsActivity2.this, "HD wallet error", Toast.LENGTH_SHORT).show();
    } catch (MnemonicException.MnemonicLengthException mle) {
        mle.printStackTrace();
        Toast.makeText(SettingsActivity2.this, "HD wallet error", Toast.LENGTH_SHORT).show();
    }
}
Also used : EditText(android.widget.EditText) AlertDialog(android.app.AlertDialog) CharSequenceX(com.samourai.wallet.util.CharSequenceX) InputStreamReader(java.io.InputStreamReader) DialogInterface(android.content.DialogInterface) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) MnemonicException(org.bitcoinj.crypto.MnemonicException) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 39 with CharSequenceX

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

the class JobRefreshService method onHandleWork.

@Override
protected void onHandleWork(@NonNull Intent intent) {
    boolean dragged = intent.getBooleanExtra("dragged", false);
    boolean launch = intent.getBooleanExtra("launch", false);
    boolean notifTx = intent.getBooleanExtra("notifTx", false);
    Log.d("JobRefreshService", "doInBackground()");
    APIFactory.getInstance(this.getApplicationContext()).stayingAlive();
    APIFactory.getInstance(this.getApplicationContext()).initWallet();
    try {
        int acc = 0;
        if (AddressFactory.getInstance().getHighestTxReceiveIdx(acc) > HD_WalletFactory.getInstance(this.getApplicationContext()).get().getAccount(acc).getReceive().getAddrIdx()) {
            HD_WalletFactory.getInstance(this.getApplicationContext()).get().getAccount(acc).getReceive().setAddrIdx(AddressFactory.getInstance().getHighestTxReceiveIdx(acc));
        }
        if (AddressFactory.getInstance().getHighestTxChangeIdx(acc) > HD_WalletFactory.getInstance(this.getApplicationContext()).get().getAccount(acc).getChange().getAddrIdx()) {
            HD_WalletFactory.getInstance(this.getApplicationContext()).get().getAccount(acc).getChange().setAddrIdx(AddressFactory.getInstance().getHighestTxChangeIdx(acc));
        }
        if (AddressFactory.getInstance().getHighestBIP49ReceiveIdx() > BIP49Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).getReceive().getAddrIdx()) {
            BIP49Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).getReceive().setAddrIdx(AddressFactory.getInstance().getHighestBIP49ReceiveIdx());
        }
        if (AddressFactory.getInstance().getHighestBIP49ChangeIdx() > BIP49Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).getChange().getAddrIdx()) {
            BIP49Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).getChange().setAddrIdx(AddressFactory.getInstance().getHighestBIP49ChangeIdx());
        }
        if (AddressFactory.getInstance().getHighestBIP84ReceiveIdx() > BIP84Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).getReceive().getAddrIdx()) {
            BIP84Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).getReceive().setAddrIdx(AddressFactory.getInstance().getHighestBIP84ReceiveIdx());
        }
        if (AddressFactory.getInstance().getHighestBIP84ChangeIdx() > BIP84Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).getChange().getAddrIdx()) {
            BIP84Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).getChange().setAddrIdx(AddressFactory.getInstance().getHighestBIP84ChangeIdx());
        }
    } catch (IOException | MnemonicException.MnemonicLengthException | NullPointerException ioe) {
        ioe.printStackTrace();
    } finally {
        Intent _intent = new Intent("com.samourai.wallet.BalanceFragment.DISPLAY");
        LocalBroadcastManager.getInstance(this.getApplicationContext()).sendBroadcast(_intent);
    }
    PrefsUtil.getInstance(this.getApplicationContext()).setValue(PrefsUtil.FIRST_RUN, false);
    if (notifTx && !AppUtil.getInstance(this.getApplicationContext()).isOfflineMode()) {
        // 
        try {
            PaymentCode pcode = BIP47Util.getInstance(this.getApplicationContext()).getPaymentCode();
            // Log.i("BalanceFragment", "payment code:" + pcode.toString());
            // Log.i("BalanceFragment", "notification address:" + pcode.notificationAddress().getAddressString());
            APIFactory.getInstance(this.getApplicationContext()).getNotifAddress(pcode.notificationAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).getAddressString());
        } catch (AddressFormatException afe) {
            afe.printStackTrace();
            Toast.makeText(this.getApplicationContext(), "HD wallet error", Toast.LENGTH_SHORT).show();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        // 
        // check on outgoing payment code notification tx
        // 
        List<Pair<String, String>> outgoingUnconfirmed = BIP47Meta.getInstance().getOutgoingUnconfirmed();
        // Log.i("BalanceFragment", "outgoingUnconfirmed:" + outgoingUnconfirmed.size());
        for (Pair<String, String> pair : outgoingUnconfirmed) {
            // Log.i("BalanceFragment", "outgoing payment code:" + pair.getLeft());
            // Log.i("BalanceFragment", "outgoing payment code tx:" + pair.getRight());
            int confirmations = APIFactory.getInstance(this.getApplicationContext()).getNotifTxConfirmations(pair.getRight());
            if (confirmations > 0) {
                BIP47Meta.getInstance().setOutgoingStatus(pair.getLeft(), BIP47Meta.STATUS_SENT_CFM);
            }
            if (confirmations == -1) {
                BIP47Meta.getInstance().setOutgoingStatus(pair.getLeft(), BIP47Meta.STATUS_NOT_SENT);
            }
        }
        Intent _intent = new Intent("com.samourai.wallet.MainActivity2.RESTART_SERVICE");
        LocalBroadcastManager.getInstance(this.getApplicationContext()).sendBroadcast(_intent);
    }
    if (launch) {
        if (PrefsUtil.getInstance(this.getApplicationContext()).getValue(PrefsUtil.GUID_V, 0) < 4) {
            Log.i("JobIntentService", "guid_v < 4");
            try {
                String _guid = AccessFactory.getInstance(this.getApplicationContext()).createGUID();
                String _hash = AccessFactory.getInstance(this.getApplicationContext()).getHash(_guid, new CharSequenceX(AccessFactory.getInstance(this.getApplicationContext()).getPIN()), AESUtil.DefaultPBKDF2Iterations);
                PayloadUtil.getInstance(this.getApplicationContext()).saveWalletToJSON(new CharSequenceX(_guid + AccessFactory.getInstance().getPIN()));
                PrefsUtil.getInstance(this.getApplicationContext()).setValue(PrefsUtil.ACCESS_HASH, _hash);
                PrefsUtil.getInstance(this.getApplicationContext()).setValue(PrefsUtil.ACCESS_HASH2, _hash);
                Log.i("JobIntentService", "guid_v == 4");
            } catch (MnemonicException.MnemonicLengthException | IOException | JSONException | DecryptionException e) {
                ;
            }
        }
        if (!PrefsUtil.getInstance(this.getApplicationContext().getApplicationContext()).getValue(PrefsUtil.XPUB44LOCK, false)) {
            try {
                String[] s = HD_WalletFactory.getInstance(this.getApplicationContext()).get().getXPUBs();
                APIFactory.getInstance(this.getApplicationContext()).lockXPUB(s[0], 44, null);
            } catch (IOException | MnemonicException.MnemonicLengthException e) {
                ;
            }
        }
        if (!PrefsUtil.getInstance(this.getApplicationContext()).getValue(PrefsUtil.XPUB49LOCK, false)) {
            String ypub = BIP49Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).ypubstr();
            APIFactory.getInstance(this.getApplicationContext()).lockXPUB(ypub, 49, null);
        }
        if (!PrefsUtil.getInstance(this.getApplicationContext()).getValue(PrefsUtil.XPUB84LOCK, false)) {
            String zpub = BIP84Util.getInstance(this.getApplicationContext()).getWallet().getAccount(0).zpubstr();
            APIFactory.getInstance(this.getApplicationContext()).lockXPUB(zpub, 84, null);
        }
        if (!PrefsUtil.getInstance(this.getApplicationContext()).getValue(PrefsUtil.XPUBPRELOCK, false)) {
            String zpub = BIP84Util.getInstance(this.getApplicationContext()).getWallet().getAccountAt(WhirlpoolMeta.getInstance(this.getApplicationContext()).getWhirlpoolPremixAccount()).zpubstr();
            APIFactory.getInstance(this.getApplicationContext()).lockXPUB(zpub, 84, PrefsUtil.XPUBPRELOCK);
        }
        if (!PrefsUtil.getInstance(this.getApplicationContext()).getValue(PrefsUtil.XPUBPOSTLOCK, false)) {
            String zpub = BIP84Util.getInstance(this.getApplicationContext()).getWallet().getAccountAt(WhirlpoolMeta.getInstance(this.getApplicationContext()).getWhirlpoolPostmix()).zpubstr();
            APIFactory.getInstance(this.getApplicationContext()).lockXPUB(zpub, 84, PrefsUtil.XPUBPRELOCK);
        }
        if (!PrefsUtil.getInstance(this.getApplicationContext()).getValue(PrefsUtil.XPUBBADBANKLOCK, false)) {
            String zpub = BIP84Util.getInstance(this.getApplicationContext()).getWallet().getAccountAt(WhirlpoolMeta.getInstance(this.getApplicationContext()).getWhirlpoolBadBank()).zpubstr();
            APIFactory.getInstance(this.getApplicationContext()).lockXPUB(zpub, 84, PrefsUtil.XPUBBADBANKLOCK);
        }
    } else {
        try {
            PayloadUtil.getInstance(this.getApplicationContext()).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(this.getApplicationContext()).getGUID() + AccessFactory.getInstance(this.getApplicationContext()).getPIN()));
        } catch (Exception ignored) {
            ;
        }
    }
    Intent _intent = new Intent("com.samourai.wallet.BalanceFragment.DISPLAY");
    LocalBroadcastManager.getInstance(this.getApplicationContext()).sendBroadcast(_intent);
}
Also used : AddressFormatException(org.bitcoinj.core.AddressFormatException) PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONException(org.json.JSONException) Intent(android.content.Intent) IOException(java.io.IOException) MnemonicException(org.bitcoinj.crypto.MnemonicException) JSONException(org.json.JSONException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) AddressFormatException(org.bitcoinj.core.AddressFormatException) IOException(java.io.IOException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) Pair(org.apache.commons.lang3.tuple.Pair)

Example 40 with CharSequenceX

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

the class PayNymHome method getPcodeSyncObservable.

private Observable<String> getPcodeSyncObservable(String pcode) {
    return Observable.fromCallable(() -> {
        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++) {
                    // Log.i("BIP47Activity", "sync receive from " + i + ":" + BIP47Util.getInstance(BIP47Activity.this).getReceivePubKey(payment_code, i));
                    BIP47Meta.getInstance().getIdx4AddrLookup().put(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i), i);
                    BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i), payment_code.toString());
                    addrs.add(BIP47Util.getInstance(this).getReceivePubKey(payment_code, i));
                // Log.i("BIP47Activity", "p2pkh " + i + ":" + BIP47Util.getInstance(BIP47Activity.this).getReceiveAddress(payment_code, i).getReceiveECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString());
                }
                String[] s = addrs.toArray(new String[addrs.size()]);
                int nb = APIFactory.getInstance(getApplicationContext()).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(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(BIP47Util.getInstance(this).getSendPubKey(payment_code, i), i);
                    BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(this).getSendPubKey(payment_code, i), payment_code.toString());
                    addrs.add(BIP47Util.getInstance(this).getSendPubKey(payment_code, i));
                }
                String[] s = addrs.toArray(new String[addrs.size()]);
                int nb = APIFactory.getInstance(getApplicationContext()).syncBIP47Outgoing(s);
                // Log.i("BIP47Activity", "sync send idx:" + idx + ", nb == " + nb);
                if (nb == 0) {
                    loop = false;
                }
                idx += 20;
            }
            BIP47Meta.getInstance().pruneIncoming();
            PayloadUtil.getInstance(this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(this).getGUID() + AccessFactory.getInstance(this).getPIN()));
        } 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) {
            ;
        } catch (Exception ex) {
        }
        return pcode;
    });
}
Also used : PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) CharSequenceX(com.samourai.wallet.util.CharSequenceX) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) PaymentAddress(com.samourai.wallet.bip47.rpc.PaymentAddress) IOException(java.io.IOException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) NotSecp256k1Exception(com.samourai.wallet.bip47.rpc.NotSecp256k1Exception) UndeliverableException(io.reactivex.exceptions.UndeliverableException) NotSecp256k1Exception(com.samourai.wallet.bip47.rpc.NotSecp256k1Exception) JSONException(org.json.JSONException) AddressFormatException(org.bitcoinj.core.AddressFormatException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeyException(java.security.InvalidKeyException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) MnemonicException(org.bitcoinj.crypto.MnemonicException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) NoSuchProviderException(java.security.NoSuchProviderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) NoSuchProviderException(java.security.NoSuchProviderException) 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