Search in sources :

Example 11 with HD_Wallet

use of com.samourai.wallet.hd.HD_Wallet in project samourai-wallet-android by Samourai-Wallet.

the class AbstractWhirlpoolTest method computeBip84w.

protected HD_Wallet computeBip84w(String seedWords, String passphrase) throws Exception {
    byte[] seed = hdWalletFactoryGeneric.computeSeedFromWords(seedWords);
    HD_Wallet bip84w = hdWalletFactoryGeneric.getBIP84(seed, passphrase, networkParameters);
    return bip84w;
}
Also used : HD_Wallet(com.samourai.wallet.hd.HD_Wallet)

Example 12 with HD_Wallet

use of com.samourai.wallet.hd.HD_Wallet in project samourai-wallet-android by Samourai-Wallet.

the class BalanceActivity method onCreate.

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_balance);
    balanceViewModel = ViewModelProviders.of(this).get(BalanceViewModel.class);
    makePaynymAvatarcache();
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
    TxRecyclerView = findViewById(R.id.rv_txes);
    progressBar = findViewById(R.id.progressBar);
    toolbar = findViewById(R.id.toolbar);
    mCollapsingToolbar = findViewById(R.id.toolbar_layout);
    txSwipeLayout = findViewById(R.id.tx_swipe_container);
    setSupportActionBar(toolbar);
    TxRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    Drawable drawable = this.getResources().getDrawable(R.drawable.divider);
    TxRecyclerView.addItemDecoration(new ItemDividerDecorator(drawable));
    menuFab = findViewById(R.id.fab_menu);
    txs = new ArrayList<>();
    whirlpoolFab = findViewById(R.id.whirlpool_fab);
    sendFab = findViewById(R.id.send_fab);
    receiveFab = findViewById(R.id.receive_fab);
    paynymFab = findViewById(R.id.paynym_fab);
    findViewById(R.id.whirlpool_fab).setOnClickListener(view -> {
        Intent intent = new Intent(BalanceActivity.this, WhirlpoolMain.class);
        startActivity(intent);
        menuFab.toggle(true);
    });
    sendFab.setOnClickListener(view -> {
        Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
        intent.putExtra("via_menu", true);
        intent.putExtra("_account", account);
        startActivity(intent);
        menuFab.toggle(true);
    });
    JSONObject payload = PayloadUtil.getInstance(BalanceActivity.this).getPayload();
    if (account == 0 && payload != null && payload.has("prev_balance")) {
        try {
            setBalance(payload.getLong("prev_balance"), false);
        } catch (Exception e) {
            setBalance(0L, false);
        }
    } else {
        setBalance(0L, false);
    }
    receiveFab.setOnClickListener(view -> {
        menuFab.toggle(true);
        try {
            HD_Wallet hdw = HD_WalletFactory.getInstance(BalanceActivity.this).get();
            if (hdw != null) {
                Intent intent = new Intent(BalanceActivity.this, ReceiveActivity.class);
                startActivity(intent);
            }
        } catch (IOException | MnemonicException.MnemonicLengthException e) {
        }
    });
    paynymFab.setOnClickListener(view -> {
        menuFab.toggle(true);
        Intent intent = new Intent(BalanceActivity.this, PayNymHome.class);
        startActivity(intent);
    });
    txSwipeLayout.setOnRefreshListener(() -> {
        refreshTx(false, true, false);
        txSwipeLayout.setRefreshing(false);
        progressBar.setVisibility(View.VISIBLE);
    });
    IntentFilter filter = new IntentFilter(ACTION_INTENT);
    LocalBroadcastManager.getInstance(BalanceActivity.this).registerReceiver(receiver, filter);
    IntentFilter filterDisplay = new IntentFilter(DISPLAY_INTENT);
    LocalBroadcastManager.getInstance(BalanceActivity.this).registerReceiver(receiverDisplay, filterDisplay);
    if (!PermissionsUtil.getInstance(BalanceActivity.this).hasPermission(Manifest.permission.READ_EXTERNAL_STORAGE) || !PermissionsUtil.getInstance(BalanceActivity.this).hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE)) {
        PermissionsUtil.getInstance(BalanceActivity.this).showRequestPermissionsInfoAlertDialog(PermissionsUtil.READ_WRITE_EXTERNAL_PERMISSION_CODE);
    }
    if (!PermissionsUtil.getInstance(BalanceActivity.this).hasPermission(Manifest.permission.CAMERA)) {
        PermissionsUtil.getInstance(BalanceActivity.this).showRequestPermissionsInfoAlertDialog(PermissionsUtil.CAMERA_PERMISSION_CODE);
    }
    if (PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_CLAIMED, false) == true && PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_FEATURED_SEGWIT, false) == false) {
        doFeaturePayNymUpdate();
    } else if (PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_CLAIMED, false) == false && PrefsUtil.getInstance(BalanceActivity.this).getValue(PrefsUtil.PAYNYM_REFUSED, false) == false) {
        doClaimPayNym();
    } else {
    }
    if (RicochetMeta.getInstance(BalanceActivity.this).getQueue().size() > 0) {
        if (ricochetQueueTask == null || ricochetQueueTask.getStatus().equals(AsyncTask.Status.FINISHED)) {
            ricochetQueueTask = new RicochetQueueTask();
            ricochetQueueTask.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
        }
    }
    if (!AppUtil.getInstance(BalanceActivity.this).isClipboardSeen()) {
        doClipboardCheck();
    }
    if (!AppUtil.getInstance(BalanceActivity.this.getApplicationContext()).isServiceRunning(WebSocketService.class)) {
        startService(new Intent(BalanceActivity.this.getApplicationContext(), WebSocketService.class));
    }
    setUpTor();
    initViewModel();
    progressBar.setVisibility(View.VISIBLE);
    if (account == 0) {
        final Handler delayedHandler = new Handler();
        delayedHandler.postDelayed(() -> {
            boolean notifTx = false;
            Bundle extras = getIntent().getExtras();
            if (extras != null && extras.containsKey("notifTx")) {
                notifTx = extras.getBoolean("notifTx");
            }
            refreshTx(notifTx, false, true);
            updateDisplay(false);
        }, 100L);
        getSupportActionBar().setIcon(R.drawable.ic_samourai_logo_toolbar);
        balanceViewModel.loadOfflineData();
    } else {
        getSupportActionBar().setIcon(R.drawable.ic_whirlpool);
        receiveFab.setVisibility(View.GONE);
        whirlpoolFab.setVisibility(View.GONE);
        paynymFab.setVisibility(View.GONE);
        new Handler().postDelayed(() -> updateDisplay(true), 600L);
    }
    boolean hadContentDescription = android.text.TextUtils.isEmpty(toolbar.getLogoDescription());
    String contentDescription = String.valueOf(!hadContentDescription ? toolbar.getLogoDescription() : "logoContentDescription");
    toolbar.setLogoDescription(contentDescription);
    ArrayList<View> potentialViews = new ArrayList<View>();
    toolbar.findViewsWithText(potentialViews, contentDescription, View.FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
    View logoView = null;
    if (potentialViews.size() > 0) {
        logoView = potentialViews.get(0);
        if (account == 0) {
            logoView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent _intent = new Intent(BalanceActivity.this, BalanceActivity.class);
                    _intent.putExtra("_account", WhirlpoolMeta.getInstance(BalanceActivity.this).getWhirlpoolPostmix());
                    startActivity(_intent);
                }
            });
        } else {
            logoView.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    Intent _intent = new Intent(BalanceActivity.this, BalanceActivity.class);
                    _intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                    startActivity(_intent);
                }
            });
        }
    }
    updateDisplay(false);
    checkDeepLinks();
}
Also used : HD_Wallet(com.samourai.wallet.hd.HD_Wallet) ItemDividerDecorator(com.samourai.wallet.widgets.ItemDividerDecorator) ArrayList(java.util.ArrayList) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) WebSocketService(com.samourai.wallet.service.WebSocketService) IntentFilter(android.content.IntentFilter) Bundle(android.os.Bundle) Drawable(android.graphics.drawable.Drawable) Handler(android.os.Handler) Intent(android.content.Intent) IOException(java.io.IOException) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) TextView(android.widget.TextView) JSONException(org.json.JSONException) ConcurrentModificationException(java.util.ConcurrentModificationException) DecryptionException(com.samourai.wallet.crypto.DecryptionException) IOException(java.io.IOException) MnemonicException(org.bitcoinj.crypto.MnemonicException) JSONObject(org.json.JSONObject)

Example 13 with HD_Wallet

use of com.samourai.wallet.hd.HD_Wallet in project samourai-wallet-android by Samourai-Wallet.

the class AddressFactory method getBIP84.

public SegwitAddress getBIP84(int chain) {
    int idx = 0;
    HD_Address addr = null;
    SegwitAddress p2wpkh = null;
    // try	{
    HD_Wallet hdw = BIP84Util.getInstance(context).getWallet();
    if (hdw != null) {
        idx = BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).getAddrIdx();
        addr = BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).getAddressAt(idx);
        p2wpkh = new SegwitAddress(addr.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
        if (chain == RECEIVE_CHAIN && canIncBIP84ReceiveAddress(idx)) {
            BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).incAddrIdx();
        // PayloadUtil.getInstance(context).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance(context).getPIN()));
        }
    }
    return p2wpkh;
}
Also used : HD_Wallet(com.samourai.wallet.hd.HD_Wallet) HD_Address(com.samourai.wallet.hd.HD_Address) SegwitAddress(com.samourai.wallet.segwit.SegwitAddress)

Example 14 with HD_Wallet

use of com.samourai.wallet.hd.HD_Wallet in project samourai-wallet-android by Samourai-Wallet.

the class RestoreSeedWalletActivity method RestoreWalletFromSamouraiBackup.

private void RestoreWalletFromSamouraiBackup(final String decrypted) {
    toggleLoading();
    new Thread(new Runnable() {

        @Override
        public void run() {
            Looper.prepare();
            try {
                JSONObject json = new JSONObject(decrypted);
                HD_Wallet hdw = PayloadUtil.getInstance(RestoreSeedWalletActivity.this).restoreWalletfromJSON(json);
                HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).set(hdw);
                String guid = AccessFactory.getInstance(RestoreSeedWalletActivity.this).createGUID();
                String hash = AccessFactory.getInstance(RestoreSeedWalletActivity.this).getHash(guid, new CharSequenceX(AccessFactory.getInstance(RestoreSeedWalletActivity.this).getPIN()), AESUtil.DefaultPBKDF2Iterations);
                PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
                PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
                PayloadUtil.getInstance(RestoreSeedWalletActivity.this).saveWalletToJSON(new CharSequenceX(guid + AccessFactory.getInstance().getPIN()));
            } catch (MnemonicException.MnemonicLengthException mle) {
                mle.printStackTrace();
                Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
            } catch (DecoderException de) {
                de.printStackTrace();
                Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
            } catch (JSONException je) {
                je.printStackTrace();
                Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
            } catch (IOException ioe) {
                ioe.printStackTrace();
                Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
            } catch (java.lang.NullPointerException npe) {
                npe.printStackTrace();
                Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
            } catch (DecryptionException de) {
                de.printStackTrace();
                Toast.makeText(RestoreSeedWalletActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
            } finally {
                AppUtil.getInstance(RestoreSeedWalletActivity.this).restartApp();
            }
            Looper.loop();
            toggleLoading();
        }
    }).start();
}
Also used : HD_Wallet(com.samourai.wallet.hd.HD_Wallet) CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONException(org.json.JSONException) IOException(java.io.IOException) DecoderException(org.apache.commons.codec.DecoderException) MnemonicException(org.bitcoinj.crypto.MnemonicException) JSONObject(org.json.JSONObject) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Example 15 with HD_Wallet

use of com.samourai.wallet.hd.HD_Wallet in project samourai-wallet-android by Samourai-Wallet.

the class LandingActivity method RestoreWalletFromSamouraiBackup.

private void RestoreWalletFromSamouraiBackup(final String decrypted) {
    toggleLoading();
    new Thread(() -> {
        Looper.prepare();
        try {
            JSONObject json = new JSONObject(decrypted);
            HD_Wallet hdw = PayloadUtil.getInstance(LandingActivity.this).restoreWalletfromJSON(json);
            HD_WalletFactory.getInstance(LandingActivity.this).set(hdw);
            String guid = AccessFactory.getInstance(LandingActivity.this).createGUID();
            String hash = AccessFactory.getInstance(LandingActivity.this).getHash(guid, new CharSequenceX(AccessFactory.getInstance(LandingActivity.this).getPIN()), AESUtil.DefaultPBKDF2Iterations);
            PrefsUtil.getInstance(LandingActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
            PrefsUtil.getInstance(LandingActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
            PayloadUtil.getInstance(LandingActivity.this).saveWalletToJSON(new CharSequenceX(guid + AccessFactory.getInstance().getPIN()));
        } catch (MnemonicException.MnemonicLengthException mle) {
            mle.printStackTrace();
            Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
        } catch (DecoderException de) {
            de.printStackTrace();
            Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
        } catch (JSONException je) {
            je.printStackTrace();
            Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
        } catch (IOException ioe) {
            ioe.printStackTrace();
            Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
        } catch (NullPointerException npe) {
            npe.printStackTrace();
            Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
        } catch (DecryptionException de) {
            de.printStackTrace();
            Toast.makeText(LandingActivity.this, R.string.decryption_error, Toast.LENGTH_SHORT).show();
        } finally {
            AppUtil.getInstance(LandingActivity.this).restartApp();
        }
        Looper.loop();
        toggleLoading();
    }).start();
}
Also used : DecoderException(org.apache.commons.codec.DecoderException) HD_Wallet(com.samourai.wallet.hd.HD_Wallet) CharSequenceX(com.samourai.wallet.util.CharSequenceX) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) IOException(java.io.IOException) DecryptionException(com.samourai.wallet.crypto.DecryptionException)

Aggregations

HD_Wallet (com.samourai.wallet.hd.HD_Wallet)16 IOException (java.io.IOException)7 MnemonicException (org.bitcoinj.crypto.MnemonicException)6 JSONException (org.json.JSONException)6 JSONObject (org.json.JSONObject)6 DecryptionException (com.samourai.wallet.crypto.DecryptionException)5 Intent (android.content.Intent)4 CharSequenceX (com.samourai.wallet.util.CharSequenceX)4 HD_Address (com.samourai.wallet.hd.HD_Address)3 DecoderException (org.apache.commons.codec.DecoderException)3 AlertDialog (android.app.AlertDialog)2 DialogInterface (android.content.DialogInterface)2 IntentFilter (android.content.IntentFilter)2 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 SegwitAddress (com.samourai.wallet.segwit.SegwitAddress)2 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)2