use of com.samourai.wallet.crypto.DecryptionException in project samourai-wallet-android by Samourai-Wallet.
the class UTXOSActivity method saveWalletState.
private void saveWalletState() {
Disposable disposable = Completable.fromCallable(() -> {
try {
PayloadUtil.getInstance(getApplicationContext()).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(getApplicationContext()).getGUID() + AccessFactory.getInstance().getPIN()));
} catch (MnemonicException.MnemonicLengthException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
} catch (DecryptionException e) {
e.printStackTrace();
}
return true;
}).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe();
compositeDisposable.add(disposable);
}
use of com.samourai.wallet.crypto.DecryptionException in project samourai-wallet-android by Samourai-Wallet.
the class RestoreSeedWalletActivity method RestoreFromMnemonic.
private void RestoreFromMnemonic(final boolean create, final String pin, final String passphrase, final String seed) {
toggleLoading();
new Thread(new Runnable() {
@Override
public void run() {
Looper.prepare();
String guid = AccessFactory.getInstance(RestoreSeedWalletActivity.this).createGUID();
String hash = AccessFactory.getInstance(RestoreSeedWalletActivity.this).getHash(guid, new CharSequenceX(pin), AESUtil.DefaultPBKDF2Iterations);
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH, hash);
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.ACCESS_HASH2, hash);
if (create) {
try {
HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).newWallet(12, passphrase, SamouraiWallet.NB_ACCOUNTS);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} finally {
;
}
} else if (seed == null) {
;
} else {
try {
HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).restoreWallet(seed, passphrase, SamouraiWallet.NB_ACCOUNTS);
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (DecoderException de) {
de.printStackTrace();
} catch (AddressFormatException afe) {
afe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} catch (MnemonicException.MnemonicChecksumException mce) {
mce.printStackTrace();
} catch (MnemonicException.MnemonicWordException mwe) {
mwe.printStackTrace();
} finally {
;
}
}
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.SCRAMBLE_PIN, true);
try {
String msg = null;
if (HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).get() != null) {
if (create) {
msg = getString(R.string.wallet_created_ok);
} else {
msg = getString(R.string.wallet_restored_ok);
}
try {
AccessFactory.getInstance(RestoreSeedWalletActivity.this).setPIN(pin);
PayloadUtil.getInstance(RestoreSeedWalletActivity.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(RestoreSeedWalletActivity.this).getGUID() + pin));
if (create) {
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "new");
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
} else {
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.WALLET_ORIGIN, "restored");
PrefsUtil.getInstance(RestoreSeedWalletActivity.this).setValue(PrefsUtil.FIRST_RUN, true);
}
} catch (JSONException je) {
je.printStackTrace();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (DecryptionException de) {
de.printStackTrace();
} finally {
;
}
AddressFactory.getInstance().account2xpub().put(0, HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).get().getAccount(0).xpubstr());
AddressFactory.getInstance().xpub2account().put(HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).get().getAccount(0).xpubstr(), 0);
//
if (create) {
String seed = null;
try {
seed = HD_WalletFactory.getInstance(RestoreSeedWalletActivity.this).get().getMnemonic();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
}
Intent intent = new Intent(RestoreSeedWalletActivity.this, RecoveryWordsActivity.class);
intent.putExtra("BIP39_WORD_LIST", seed);
startActivity(intent);
finish();
} else {
AccessFactory.getInstance(RestoreSeedWalletActivity.this).setIsLoggedIn(true);
TimeOutUtil.getInstance().updatePin();
AppUtil.getInstance(RestoreSeedWalletActivity.this).restartApp();
}
} else {
if (create) {
msg = getString(R.string.wallet_created_ko);
} else {
msg = getString(R.string.wallet_restored_ko);
}
}
Toast.makeText(RestoreSeedWalletActivity.this, msg, Toast.LENGTH_SHORT).show();
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} finally {
;
}
toggleLoading();
Looper.loop();
}
}).start();
}
use of com.samourai.wallet.crypto.DecryptionException 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();
}
use of com.samourai.wallet.crypto.DecryptionException 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();
}
use of com.samourai.wallet.crypto.DecryptionException 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);
}
Aggregations