use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class RefreshService method onHandleIntent.
@Override
protected void onHandleIntent(Intent intent) {
//
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, FOREGROUND_SERVICE_CHANNEL_ID).setPriority(NotificationCompat.PRIORITY_LOW).setContentTitle("Updating Wallet...").setSmallIcon(R.drawable.ic_samourai_logo_trans2x).setOngoing(true).setCategory(Notification.CATEGORY_SERVICE).setAutoCancel(true);
Notification notification = builder.build();
startForeground(1001, notification);
}
dragged = intent.getBooleanExtra("dragged", false);
launch = intent.getBooleanExtra("launch", false);
notifTx = intent.getBooleanExtra("notifTx", false);
APIFactory.getInstance(RefreshService.this).stayingAlive();
APIFactory.getInstance(RefreshService.this).initWallet();
try {
int acc = 0;
if (AddressFactory.getInstance().getHighestTxReceiveIdx(acc) > HD_WalletFactory.getInstance(RefreshService.this).get().getAccount(acc).getReceive().getAddrIdx()) {
HD_WalletFactory.getInstance(RefreshService.this).get().getAccount(acc).getReceive().setAddrIdx(AddressFactory.getInstance().getHighestTxReceiveIdx(acc));
}
if (AddressFactory.getInstance().getHighestTxChangeIdx(acc) > HD_WalletFactory.getInstance(RefreshService.this).get().getAccount(acc).getChange().getAddrIdx()) {
HD_WalletFactory.getInstance(RefreshService.this).get().getAccount(acc).getChange().setAddrIdx(AddressFactory.getInstance().getHighestTxChangeIdx(acc));
}
if (AddressFactory.getInstance().getHighestBIP49ReceiveIdx() > BIP49Util.getInstance(RefreshService.this).getWallet().getAccount(0).getReceive().getAddrIdx()) {
BIP49Util.getInstance(RefreshService.this).getWallet().getAccount(0).getReceive().setAddrIdx(AddressFactory.getInstance().getHighestBIP49ReceiveIdx());
}
if (AddressFactory.getInstance().getHighestBIP49ChangeIdx() > BIP49Util.getInstance(RefreshService.this).getWallet().getAccount(0).getChange().getAddrIdx()) {
BIP49Util.getInstance(RefreshService.this).getWallet().getAccount(0).getChange().setAddrIdx(AddressFactory.getInstance().getHighestBIP49ChangeIdx());
}
if (AddressFactory.getInstance().getHighestBIP84ReceiveIdx() > BIP84Util.getInstance(RefreshService.this).getWallet().getAccount(0).getReceive().getAddrIdx()) {
BIP84Util.getInstance(RefreshService.this).getWallet().getAccount(0).getReceive().setAddrIdx(AddressFactory.getInstance().getHighestBIP84ReceiveIdx());
}
if (AddressFactory.getInstance().getHighestBIP84ChangeIdx() > BIP84Util.getInstance(RefreshService.this).getWallet().getAccount(0).getChange().getAddrIdx()) {
BIP84Util.getInstance(RefreshService.this).getWallet().getAccount(0).getChange().setAddrIdx(AddressFactory.getInstance().getHighestBIP84ChangeIdx());
}
} catch (IOException ioe) {
ioe.printStackTrace();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
} catch (NullPointerException npe) {
npe.printStackTrace();
} finally {
Intent _intent = new Intent("com.samourai.wallet.BalanceFragment.DISPLAY");
LocalBroadcastManager.getInstance(RefreshService.this).sendBroadcast(_intent);
}
PrefsUtil.getInstance(RefreshService.this).setValue(PrefsUtil.FIRST_RUN, false);
if (notifTx && !AppUtil.getInstance(RefreshService.this).isOfflineMode()) {
//
try {
PaymentCode pcode = BIP47Util.getInstance(RefreshService.this).getPaymentCode();
// Log.i("BalanceFragment", "payment code:" + pcode.toString());
// Log.i("BalanceFragment", "notification address:" + pcode.notificationAddress().getAddressString());
APIFactory.getInstance(RefreshService.this).getNotifAddress(pcode.notificationAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).getAddressString());
} catch (AddressFormatException afe) {
afe.printStackTrace();
Toast.makeText(RefreshService.this, "HD wallet error", Toast.LENGTH_SHORT).show();
}
//
// 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(RefreshService.this).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(RefreshService.this).sendBroadcast(_intent);
}
if (launch) {
if (PrefsUtil.getInstance(RefreshService.this).getValue(PrefsUtil.GUID_V, 0) < 4) {
Log.i("RefreshService", "guid_v < 4");
try {
String _guid = AccessFactory.getInstance(RefreshService.this).createGUID();
String _hash = AccessFactory.getInstance(RefreshService.this).getHash(_guid, new CharSequenceX(AccessFactory.getInstance(RefreshService.this).getPIN()), AESUtil.DefaultPBKDF2Iterations);
PayloadUtil.getInstance(RefreshService.this).saveWalletToJSON(new CharSequenceX(_guid + AccessFactory.getInstance().getPIN()));
PrefsUtil.getInstance(RefreshService.this).setValue(PrefsUtil.ACCESS_HASH, _hash);
PrefsUtil.getInstance(RefreshService.this).setValue(PrefsUtil.ACCESS_HASH2, _hash);
Log.i("RefreshService", "guid_v == 4");
} catch (MnemonicException.MnemonicLengthException | IOException | JSONException | DecryptionException e) {
;
}
}
if (PrefsUtil.getInstance(RefreshService.this).getValue(PrefsUtil.XPUB44LOCK, false) == false) {
try {
String[] s = HD_WalletFactory.getInstance(RefreshService.this).get().getXPUBs();
APIFactory.getInstance(RefreshService.this).lockXPUB(s[0], 44, null);
} catch (IOException | MnemonicException.MnemonicLengthException e) {
;
}
}
if (PrefsUtil.getInstance(RefreshService.this).getValue(PrefsUtil.XPUB49LOCK, false) == false) {
String ypub = BIP49Util.getInstance(RefreshService.this).getWallet().getAccount(0).ypubstr();
APIFactory.getInstance(RefreshService.this).lockXPUB(ypub, 49, null);
}
if (PrefsUtil.getInstance(RefreshService.this).getValue(PrefsUtil.XPUB84LOCK, false) == false) {
String zpub = BIP84Util.getInstance(RefreshService.this).getWallet().getAccount(0).zpubstr();
APIFactory.getInstance(RefreshService.this).lockXPUB(zpub, 84, null);
}
if (PrefsUtil.getInstance(RefreshService.this).getValue(PrefsUtil.XPUBPRELOCK, false) == false) {
String zpub = BIP84Util.getInstance(RefreshService.this).getWallet().getAccountAt(WhirlpoolMeta.getInstance(RefreshService.this).getWhirlpoolPremixAccount()).zpubstr();
APIFactory.getInstance(RefreshService.this).lockXPUB(zpub, 84, PrefsUtil.XPUBPRELOCK);
}
if (PrefsUtil.getInstance(RefreshService.this).getValue(PrefsUtil.XPUBPOSTLOCK, false) == false) {
String zpub = BIP84Util.getInstance(RefreshService.this).getWallet().getAccountAt(WhirlpoolMeta.getInstance(RefreshService.this).getWhirlpoolPostmix()).zpubstr();
APIFactory.getInstance(RefreshService.this).lockXPUB(zpub, 84, PrefsUtil.XPUBPRELOCK);
}
if (PrefsUtil.getInstance(RefreshService.this).getValue(PrefsUtil.XPUBBADBANKLOCK, false) == false) {
String zpub = BIP84Util.getInstance(RefreshService.this).getWallet().getAccountAt(WhirlpoolMeta.getInstance(RefreshService.this).getWhirlpoolBadBank()).zpubstr();
APIFactory.getInstance(RefreshService.this).lockXPUB(zpub, 84, PrefsUtil.XPUBBADBANKLOCK);
}
} else {
try {
PayloadUtil.getInstance(RefreshService.this).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(RefreshService.this).getGUID() + AccessFactory.getInstance(RefreshService.this).getPIN()));
} catch (Exception e) {
;
}
}
Intent _intent = new Intent("com.samourai.wallet.BalanceFragment.DISPLAY");
LocalBroadcastManager.getInstance(RefreshService.this).sendBroadcast(_intent);
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class PayloadUtil method serializeUTXOPre.
public void serializeUTXOPre(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()), strUTXOPreFilename);
}
}
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class PayloadUtil method serializeUTXO.
public void serializeUTXO(List<JSONObject> objs) throws IOException, JSONException, DecryptionException, UnsupportedEncodingException {
if (!AppUtil.getInstance(context).isOfflineMode()) {
JSONArray utxos = new JSONArray();
for (JSONObject obj : objs) {
if (obj != null && obj.has("unspent_outputs")) {
JSONArray array = obj.getJSONArray("unspent_outputs");
for (int i = 0; i < array.length(); i++) {
JSONObject _obj = array.getJSONObject(i);
utxos.put(_obj);
}
}
}
JSONObject utxoObj = new JSONObject();
utxoObj.put("unspent_outputs", utxos);
serializeAux(utxoObj, new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance().getPIN()), strUTXOFilename);
}
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class InterceptOutgoingReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
String strTelNo = null;
if (intent.getAction().equals(ACTION) && PrefsUtil.getInstance(context).getValue(PrefsUtil.ICON_HIDDEN, false) == true) {
// Log.i("InterceptOutgoing", "ACTION recognized, ICON_HIDDEN == true");
Bundle extras = intent.getExtras();
if (extras != null) {
strTelNo = extras.getString("android.intent.extra.PHONE_NUMBER");
if (strTelNo.startsWith("**") && strTelNo.endsWith("#")) {
String pin = strTelNo.substring(2, strTelNo.length() - 1);
// Log.i("InterceptOutgoing", "pin:" + pin);
if (pin.length() >= AccessFactory.MIN_PIN_LENGTH && pin.length() <= AccessFactory.MAX_PIN_LENGTH) {
// Log.i("InterceptOutgoing", "pin ok");
String accessHash = PrefsUtil.getInstance(context).getValue(PrefsUtil.ACCESS_HASH, "");
String accessHash2 = PrefsUtil.getInstance(context).getValue(PrefsUtil.ACCESS_HASH2, "");
if (AccessFactory.getInstance(context).validateHash(accessHash2, AccessFactory.getInstance(context).getGUID(), new CharSequenceX(pin), AESUtil.DefaultPBKDF2Iterations)) {
// Log.i("InterceptOutgoing", "access ok");
if (accessHash.equals(accessHash2)) {
AccessFactory.getInstance(context).setPIN(pin);
} else {
TimeOutUtil.getInstance().reset();
AccessFactory.getInstance(context).setIsLoggedIn(false);
}
Intent i = new Intent(context, MainActivity2.class);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
if (accessHash.equals(accessHash2)) {
i.putExtra("dialed", true);
}
context.startActivity(i);
setResultData(null);
abortBroadcast();
return;
}
}
}
// Log.i("InterceptOutgoing", "intercept ignored");
setResultData(strTelNo);
}
}
}
use of com.samourai.wallet.util.CharSequenceX in project samourai-wallet-android by Samourai-Wallet.
the class SMSReceiver method onReceive.
// @Override
public void onReceive(Context context, Intent intent) {
String incoming = null;
if (msgs == null) {
msgs = new Hashtable<String, String>();
}
if (seen == null) {
seen = new HashMap<String, Long>();
}
if ((intent.getAction().equals(ACTION) || intent.getAction().contains("SMS_RECEIVED")) && PrefsUtil.getInstance(context).getValue(PrefsUtil.ACCEPT_REMOTE, false) == true) {
StringBuilder sb = new StringBuilder();
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdusObj = (Object[]) bundle.get("pdus");
SmsMessage[] messages = new SmsMessage[pdusObj.length];
for (int i = 0; i < pdusObj.length; i++) {
messages[i] = SmsMessage.createFromPdu((byte[]) pdusObj[i]);
}
for (SmsMessage currentMessage : messages) {
String msg = currentMessage.getDisplayMessageBody().trim().toLowerCase();
String[] s = msg.split("\\s+");
String incomingTelNo = currentMessage.getDisplayOriginatingAddress();
if (seen.get(incomingTelNo + msg) != null && seen.get(incomingTelNo + msg) != 0L && (System.currentTimeMillis() - seen.get(incomingTelNo + msg) < 3000)) {
continue;
} else {
seen.put(incomingTelNo + msg, System.currentTimeMillis());
}
if (s.length == 3) {
if (AccessFactory.getInstance(context).validateHash(PrefsUtil.getInstance(context).getValue(PrefsUtil.ACCESS_HASH2, ""), AccessFactory.getInstance(context).getGUID(), new CharSequenceX(s[2]), AESUtil.DefaultPBKDF2Iterations)) {
if (PrefsUtil.getInstance(context).getValue(PrefsUtil.TRUSTED_LOCK, false) == true) {
String strTrustedNo = PrefsUtil.getInstance(context).getValue(PrefsUtil.ALERT_MOBILE_NO, "");
// Log.i("SMSReceiver", "incoming no.:" + incomingTelNo);
if (!incomingTelNo.equals(strTrustedNo.replaceAll("[^\\+0-9]", ""))) {
continue;
}
}
doRemote(context, msg, incomingTelNo, s[2]);
}
}
}
}
}
}
Aggregations