Search in sources :

Example 1 with NotSecp256k1Exception

use of com.samourai.wallet.bip47.rpc.NotSecp256k1Exception in project samourai-wallet-android by Samourai-Wallet.

the class BIP47Util method getPaymentAddress.

public PaymentAddress getPaymentAddress(PaymentCode pcode, int idx, HD_Address address) throws AddressFormatException, NotSecp256k1Exception {
    DumpedPrivateKey dpk = new DumpedPrivateKey(SamouraiWallet.getInstance().getCurrentNetworkParams(), address.getPrivateKeyString());
    ECKey eckey = dpk.getKey();
    PaymentAddress paymentAddress = new PaymentAddress(pcode, idx, eckey.getPrivKeyBytes());
    return paymentAddress;
}
Also used : ECKey(org.bitcoinj.core.ECKey) PaymentAddress(com.samourai.wallet.bip47.rpc.PaymentAddress) DumpedPrivateKey(org.bitcoinj.core.DumpedPrivateKey)

Example 2 with NotSecp256k1Exception

use of com.samourai.wallet.bip47.rpc.NotSecp256k1Exception 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 3 with NotSecp256k1Exception

use of com.samourai.wallet.bip47.rpc.NotSecp256k1Exception 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)

Example 4 with NotSecp256k1Exception

use of com.samourai.wallet.bip47.rpc.NotSecp256k1Exception in project samourai-wallet-android by Samourai-Wallet.

the class APIFactory method bip47Lookahead.

private synchronized void bip47Lookahead(String pcode, String addr) {
    debug("APIFactory", "bip47Lookahead():" + addr);
    debug("APIFactory", "bip47Lookahead():" + pcode);
    debug("APIFactory", "bip47Lookahead():" + BIP47Meta.getInstance().getPCode4Addr(addr));
    int idx = BIP47Meta.getInstance().getIdx4Addr(addr);
    debug("APIFactory", "bip47Lookahead():" + idx);
    try {
        idx++;
        for (int i = idx; i < (idx + BIP47Meta.INCOMING_LOOKAHEAD); i++) {
            info("APIFactory", "receive from " + i + ":" + BIP47Util.getInstance(context).getReceivePubKey(new PaymentCode(pcode), i));
            BIP47Meta.getInstance().getIdx4AddrLookup().put(BIP47Util.getInstance(context).getReceivePubKey(new PaymentCode(pcode), i), i);
            BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(context).getReceivePubKey(new PaymentCode(pcode), i), pcode.toString());
        // _addrs.add(BIP47Util.getInstance(RefreshService.this).getReceivePubKey(new PaymentCode(pcode), i));
        }
        idx--;
        if (idx >= 2) {
            for (int i = idx; i >= (idx - (BIP47Meta.INCOMING_LOOKAHEAD - 1)); i--) {
                info("APIFactory", "receive from " + i + ":" + BIP47Util.getInstance(context).getReceivePubKey(new PaymentCode(pcode), i));
                BIP47Meta.getInstance().getIdx4AddrLookup().put(BIP47Util.getInstance(context).getReceivePubKey(new PaymentCode(pcode), i), i);
                BIP47Meta.getInstance().getPCode4AddrLookup().put(BIP47Util.getInstance(context).getReceivePubKey(new PaymentCode(pcode), i), pcode.toString());
            // _addrs.add(BIP47Util.getInstance(context).getReceivePubKey(new PaymentCode(pcode), i));
            }
        }
    // addrs = _addrs.toArray(new String[_addrs.size()]);
    } catch (NullPointerException | NotSecp256k1Exception | InvalidKeyException | NoSuchAlgorithmException | NoSuchProviderException | InvalidKeySpecException e) {
        ;
    }
}
Also used : PaymentCode(com.samourai.wallet.bip47.rpc.PaymentCode) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) InvalidKeySpecException(java.security.spec.InvalidKeySpecException) InvalidKeyException(java.security.InvalidKeyException) NoSuchProviderException(java.security.NoSuchProviderException) NotSecp256k1Exception(com.samourai.wallet.bip47.rpc.NotSecp256k1Exception) MyTransactionOutPoint(com.samourai.wallet.send.MyTransactionOutPoint) TransactionOutPoint(org.bitcoinj.core.TransactionOutPoint)

Aggregations

NotSecp256k1Exception (com.samourai.wallet.bip47.rpc.NotSecp256k1Exception)3 PaymentAddress (com.samourai.wallet.bip47.rpc.PaymentAddress)3 PaymentCode (com.samourai.wallet.bip47.rpc.PaymentCode)3 InvalidKeyException (java.security.InvalidKeyException)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)3 NoSuchProviderException (java.security.NoSuchProviderException)3 InvalidKeySpecException (java.security.spec.InvalidKeySpecException)3 DecryptionException (com.samourai.wallet.crypto.DecryptionException)2 MyTransactionOutPoint (com.samourai.wallet.send.MyTransactionOutPoint)2 CharSequenceX (com.samourai.wallet.util.CharSequenceX)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 MnemonicException (org.bitcoinj.crypto.MnemonicException)2 JSONException (org.json.JSONException)2 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 Point (android.graphics.Point)1 SecretPoint (com.samourai.wallet.bip47.rpc.SecretPoint)1 UndeliverableException (io.reactivex.exceptions.UndeliverableException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1