Search in sources :

Example 41 with CharSequenceX

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

the class PayloadUtil method serializeUTXOBadBank.

public void serializeUTXOBadBank(JSONObject obj) throws IOException, JSONException, DecryptionException, UnsupportedEncodingException {
    if (!AppUtil.getInstance(context).isOfflineMode()) {
        if (obj != null) {
            JSONObject utxoObj = new JSONObject();
            utxoObj.put("unspent_outputs", obj);
            serializeAux(utxoObj, new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance().getPIN()), strUTXOBadBankFilename);
        }
    }
}
Also used : CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONObject(org.json.JSONObject)

Example 42 with CharSequenceX

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

the class PayloadUtil method serializeUTXOPost.

public void serializeUTXOPost(JSONObject obj) throws IOException, JSONException, DecryptionException, UnsupportedEncodingException {
    if (!AppUtil.getInstance(context).isOfflineMode()) {
        if (obj != null) {
            JSONObject utxoObj = new JSONObject();
            utxoObj.put("unspent_outputs", obj);
            serializeAux(utxoObj, new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance().getPIN()), strUTXOPostFilename);
        }
    }
}
Also used : CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONObject(org.json.JSONObject)

Example 43 with CharSequenceX

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

the class PayloadUtil method wipe.

public synchronized void wipe() throws IOException {
    BIP47Util.getInstance(context).reset();
    BIP47Meta.getInstance().clear();
    BIP49Util.getInstance(context).reset();
    BIP84Util.getInstance(context).reset();
    DojoUtil.getInstance(context).clear();
    APIFactory.getInstance(context).reset();
    PrefsUtil.getInstance(context).setValue(PrefsUtil.ENABLE_TOR, false);
    PrefsUtil.getInstance(context).setValue(PrefsUtil.IS_RESTORE, false);
    PrefsUtil.getInstance(context).setValue(PrefsUtil.USE_TRUSTED_NODE, false);
    PrefsUtil.getInstance(context).clear();
    try {
        int nbAccounts = HD_WalletFactory.getInstance(context).get().getAccounts().size();
        for (int i = 0; i < nbAccounts; i++) {
            HD_WalletFactory.getInstance(context).get().getAccount(i).getReceive().setAddrIdx(0);
            HD_WalletFactory.getInstance(context).get().getAccount(i).getChange().setAddrIdx(0);
            AddressFactory.getInstance().setHighestTxReceiveIdx(i, 0);
            AddressFactory.getInstance().setHighestTxChangeIdx(i, 0);
        }
        AddressFactory.getInstance().setHighestBIP49ReceiveIdx(0);
        AddressFactory.getInstance().setHighestBIP49ChangeIdx(0);
        AddressFactory.getInstance().setHighestBIP84ReceiveIdx(0);
        AddressFactory.getInstance().setHighestBIP84ChangeIdx(0);
        BIP49Util.getInstance(context).getWallet().getAccount(0).getReceive().setAddrIdx(0);
        BIP49Util.getInstance(context).getWallet().getAccount(0).getChange().setAddrIdx(0);
        BIP84Util.getInstance(context).getWallet().getAccount(0).getReceive().setAddrIdx(0);
        BIP84Util.getInstance(context).getWallet().getAccount(0).getChange().setAddrIdx(0);
        AddressFactory.getInstance().setHighestPreReceiveIdx(0);
        AddressFactory.getInstance().setHighestPreChangeIdx(0);
        AddressFactory.getInstance().setHighestPostReceiveIdx(0);
        AddressFactory.getInstance().setHighestPostChangeIdx(0);
        AddressFactory.getInstance().setHighestBadBankReceiveIdx(0);
        AddressFactory.getInstance().setHighestBadBankChangeIdx(0);
        HD_WalletFactory.getInstance(context).set(null);
    } catch (MnemonicException.MnemonicLengthException mle) {
        mle.printStackTrace();
    }
    HD_WalletFactory.getInstance(context).clear();
    File dir = context.getDir(dataDir, Context.MODE_PRIVATE);
    File datfile = new File(dir, strFilename);
    File tmpfile = new File(dir, strTmpFilename);
    if (tmpfile.exists()) {
        secureDelete(tmpfile);
    }
    if (datfile.exists()) {
        secureDelete(datfile);
        try {
            serialize(new JSONObject("{}"), new CharSequenceX(""));
        } catch (JSONException je) {
            je.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
Also used : MnemonicException(org.bitcoinj.crypto.MnemonicException) CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) JSONException(org.json.JSONException) AddressFormatException(org.bitcoinj.core.AddressFormatException) DecoderException(org.apache.commons.codec.DecoderException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MnemonicException(org.bitcoinj.crypto.MnemonicException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException)

Example 44 with CharSequenceX

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

the class BalanceActivity method doScan.

private void doScan() {
    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);
            // CahootsUtil.getInstance(BalanceActivity.this).processCahoots(code.trim(), 0);
            } else if (FormatsUtil.getInstance().isPSBT(code.trim())) {
                CahootsUtil.getInstance(BalanceActivity.this).doPSBT(code.trim());
            } else if (DojoUtil.getInstance(BalanceActivity.this).isValidPairingPayload(code.trim())) {
                Intent intent = new Intent(BalanceActivity.this, NetworkDashboard.class);
                intent.putExtra("params", code.trim());
                startActivity(intent);
            } 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) NetworkDashboard(com.samourai.wallet.network.NetworkDashboard) 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 45 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) || FormatsUtil.getInstance().isValidXprv(s[i]))) {
                        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 : ClipboardManager(android.content.ClipboardManager) CharSequenceX(com.samourai.wallet.util.CharSequenceX) DialogInterface(android.content.DialogInterface) PrivKeyReader(com.samourai.wallet.util.PrivKeyReader) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) JSONException(org.json.JSONException) ConcurrentModificationException(java.util.ConcurrentModificationException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) MnemonicException(org.bitcoinj.crypto.MnemonicException) ClipboardManager(android.content.ClipboardManager) ClipData(android.content.ClipData)

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