Search in sources :

Example 6 with PrivKeyReader

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

the class OpenDimeActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_opendime);
    setTitle(R.string.samourai_opendime);
    if (!AccessFactory.getInstance(OpenDimeActivity.this).isLoggedIn()) {
        Intent _intent = new Intent(OpenDimeActivity.this, PinEntryActivity.class);
        _intent.putExtra("opendime", true);
        _intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(_intent);
    }
    display = (OpenDimeActivity.this).getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    imgWidth = Math.max(size.x - 300, 150);
    tvAddress = (TextView) findViewById(R.id.address);
    tvBalance = (TextView) findViewById(R.id.balanceAmount);
    tvKey = (TextView) findViewById(R.id.keyStatus);
    ivQR = (ImageView) findViewById(R.id.qr);
    btTopUp = (Button) findViewById(R.id.topup);
    btView = (Button) findViewById(R.id.view);
    btSweep = (Button) findViewById(R.id.sweep);
    btTopUp.setVisibility(View.GONE);
    /*
        btTopUp = (Button)findViewById(R.id.topup);
        btTopUp.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {


            }
        });
*/
    btView = (Button) findViewById(R.id.view);
    btView.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (strAddress != null) {
                String blockExplorer = "https://m.oxt.me/transaction/";
                if (SamouraiWallet.getInstance().isTestNet()) {
                    blockExplorer = "https://blockstream.info/testnet/";
                }
                Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(blockExplorer + strAddress));
                startActivity(browserIntent);
            }
        }
    });
    btSweep = (Button) findViewById(R.id.sweep);
    btSweep.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            if (strPrivKey != null) {
                SweepUtil.getInstance(OpenDimeActivity.this).sweep(new PrivKeyReader(strPrivKey), SweepUtil.TYPE_P2PKH);
            }
        }
    });
    ivQR.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (strAddress != null) {
                new AlertDialog.Builder(OpenDimeActivity.this).setTitle(R.string.app_name).setMessage(R.string.receive_address_to_clipboard).setCancelable(false).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        android.content.ClipboardManager clipboard = (android.content.ClipboardManager) OpenDimeActivity.this.getSystemService(android.content.Context.CLIPBOARD_SERVICE);
                        android.content.ClipData clip = null;
                        clip = android.content.ClipData.newPlainText("Receive address", strAddress);
                        clipboard.setPrimaryClip(clip);
                        Toast.makeText(OpenDimeActivity.this, R.string.copied_to_clipboard, Toast.LENGTH_SHORT).show();
                    }
                }).setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                    public void onClick(DialogInterface dialog, int whichButton) {
                        ;
                    }
                }).show();
            }
            return false;
        }
    });
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
    filter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
    registerReceiver(usbReceiver, filter);
    readOpenDimeUSB();
}
Also used : AlertDialog(android.app.AlertDialog) IntentFilter(android.content.IntentFilter) DialogInterface(android.content.DialogInterface) PrivKeyReader(com.samourai.wallet.util.PrivKeyReader) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) Point(android.graphics.Point) SpannableString(android.text.SpannableString) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) Point(android.graphics.Point) MotionEvent(android.view.MotionEvent)

Example 7 with PrivKeyReader

use of com.samourai.wallet.util.PrivKeyReader 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 8 with PrivKeyReader

use of com.samourai.wallet.util.PrivKeyReader 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)

Example 9 with PrivKeyReader

use of com.samourai.wallet.util.PrivKeyReader 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.trim()));
            try {
                if (privKeyReader.getFormat() != null) {
                    doPrivKey(strResult.trim());
                } else if (Cahoots.isCahoots(strResult.trim())) {
                    Intent cahootIntent = new Intent(this, ManualCahootsActivity.class);
                    cahootIntent.putExtra("_account", account);
                    cahootIntent.putExtra("payload", strResult.trim());
                    startActivity(cahootIntent);
                } else if (FormatsUtil.getInstance().isPSBT(strResult.trim())) {
                    CahootsUtil.getInstance(BalanceActivity.this).doPSBT(strResult.trim());
                } else if (DojoUtil.getInstance(BalanceActivity.this).isValidPairingPayload(strResult.trim())) {
                    Intent intent = new Intent(BalanceActivity.this, NetworkDashboard.class);
                    intent.putExtra("params", strResult.trim());
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
                    intent.putExtra("uri", strResult.trim());
                    intent.putExtra("_account", account);
                    startActivity(intent);
                }
            } catch (Exception e) {
            }
        }
    }
    if (resultCode == Activity.RESULT_OK && requestCode == UTXO_REQUESTCODE) {
        refreshTx(false, false, false);
        progressBar.setVisibility(View.VISIBLE);
    } else {
        ;
    }
}
Also used : 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)

Aggregations

PrivKeyReader (com.samourai.wallet.util.PrivKeyReader)9 DecryptionException (com.samourai.wallet.crypto.DecryptionException)8 CharSequenceX (com.samourai.wallet.util.CharSequenceX)8 IOException (java.io.IOException)8 MnemonicException (org.bitcoinj.crypto.MnemonicException)8 JSONException (org.json.JSONException)8 DialogInterface (android.content.DialogInterface)5 Intent (android.content.Intent)5 ConcurrentModificationException (java.util.ConcurrentModificationException)5 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)4 AlertDialog (android.app.AlertDialog)3 SendActivity (com.samourai.wallet.send.SendActivity)3 ManualCahootsActivity (com.samourai.wallet.send.cahoots.ManualCahootsActivity)3 AddressFormatException (org.bitcoinj.core.AddressFormatException)3 DecoderException (org.bouncycastle.util.encoders.DecoderException)3 ProgressDialog (android.app.ProgressDialog)2 ClipData (android.content.ClipData)2 OnClickListener (android.view.View.OnClickListener)2 EditText (android.widget.EditText)2 CameraFragmentBottomSheet (com.samourai.wallet.fragments.CameraFragmentBottomSheet)2