use of com.samourai.wallet.util.PrivKeyReader in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method doSweepViaScan.
private void doSweepViaScan() {
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);
} else if (FormatsUtil.getInstance().isPSBT(code.trim())) {
CahootsUtil.getInstance(BalanceActivity.this).doPSBT(code.trim());
} else if (DojoUtil.getInstance(BalanceActivity.this).isValidPairingPayload(code.trim())) {
Toast.makeText(BalanceActivity.this, "Samourai Dojo full node coming soon.", Toast.LENGTH_SHORT).show();
} else {
Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
intent.putExtra("uri", code.trim());
intent.putExtra("_account", account);
startActivity(intent);
}
} catch (Exception e) {
}
});
}
use of com.samourai.wallet.util.PrivKeyReader in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method doPrivKey.
private void doPrivKey(final String data) {
PrivKeyReader privKeyReader = null;
String format = null;
try {
privKeyReader = new PrivKeyReader(new CharSequenceX(data), null);
format = privKeyReader.getFormat();
} catch (Exception e) {
Toast.makeText(BalanceActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
if (format != null) {
if (format.equals(PrivKeyReader.BIP38)) {
final PrivKeyReader pvr = privKeyReader;
final EditText password38 = new EditText(BalanceActivity.this);
password38.setSingleLine(true);
password38.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
AlertDialog.Builder dlg = new AlertDialog.Builder(BalanceActivity.this).setTitle(R.string.app_name).setMessage(R.string.bip38_pw).setView(password38).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String password = password38.getText().toString();
ProgressDialog progress = new ProgressDialog(BalanceActivity.this);
progress.setCancelable(false);
progress.setTitle(R.string.app_name);
progress.setMessage(getString(R.string.decrypting_bip38));
progress.show();
boolean keyDecoded = false;
try {
BIP38PrivateKey bip38 = new BIP38PrivateKey(SamouraiWallet.getInstance().getCurrentNetworkParams(), data);
final ECKey ecKey = bip38.decrypt(password);
if (ecKey != null && ecKey.hasPrivKey()) {
if (progress != null && progress.isShowing()) {
progress.cancel();
}
pvr.setPassword(new CharSequenceX(password));
keyDecoded = true;
Toast.makeText(BalanceActivity.this, pvr.getFormat(), Toast.LENGTH_SHORT).show();
Toast.makeText(BalanceActivity.this, pvr.getKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(BalanceActivity.this, R.string.bip38_pw_error, Toast.LENGTH_SHORT).show();
}
if (progress != null && progress.isShowing()) {
progress.cancel();
}
if (keyDecoded) {
SweepUtil.getInstance(BalanceActivity.this).sweep(pvr, SweepUtil.TYPE_P2PKH);
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(BalanceActivity.this, R.string.bip38_pw_error, Toast.LENGTH_SHORT).show();
}
});
if (!isFinishing()) {
dlg.show();
}
} else if (privKeyReader != null) {
SweepUtil.getInstance(BalanceActivity.this).sweep(privKeyReader, SweepUtil.TYPE_P2PKH);
} else {
;
}
} else {
Toast.makeText(BalanceActivity.this, R.string.cannot_recognize_privkey, Toast.LENGTH_SHORT).show();
}
}
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))) {
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) {
;
}
}
}
}
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));
try {
if (privKeyReader.getFormat() != null) {
doPrivKey(strResult);
} else {
Intent intent = new Intent(BalanceActivity.this, SendActivity.class);
intent.putExtra("uri", strResult);
startActivity(intent);
}
} catch (Exception e) {
;
}
}
} else if (resultCode == Activity.RESULT_CANCELED && requestCode == SCAN_QR) {
;
} else {
;
}
}
use of com.samourai.wallet.util.PrivKeyReader in project samourai-wallet-android by Samourai-Wallet.
the class BalanceActivity method doPrivKey.
private void doPrivKey(final String data) {
PrivKeyReader privKeyReader = null;
String format = null;
try {
privKeyReader = new PrivKeyReader(new CharSequenceX(data), null);
format = privKeyReader.getFormat();
} catch (Exception e) {
Toast.makeText(BalanceActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
return;
}
if (format != null) {
if (format.equals(PrivKeyReader.BIP38)) {
final PrivKeyReader pvr = privKeyReader;
final EditText password38 = new EditText(BalanceActivity.this);
AlertDialog.Builder dlg = new AlertDialog.Builder(BalanceActivity.this).setTitle(R.string.app_name).setMessage(R.string.bip38_pw).setView(password38).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String password = password38.getText().toString();
ProgressDialog progress = new ProgressDialog(BalanceActivity.this);
progress.setCancelable(false);
progress.setTitle(R.string.app_name);
progress.setMessage(getString(R.string.decrypting_bip38));
progress.show();
boolean keyDecoded = false;
try {
BIP38PrivateKey bip38 = new BIP38PrivateKey(SamouraiWallet.getInstance().getCurrentNetworkParams(), data);
final ECKey ecKey = bip38.decrypt(password);
if (ecKey != null && ecKey.hasPrivKey()) {
if (progress != null && progress.isShowing()) {
progress.cancel();
}
pvr.setPassword(new CharSequenceX(password));
keyDecoded = true;
Toast.makeText(BalanceActivity.this, pvr.getFormat(), Toast.LENGTH_SHORT).show();
Toast.makeText(BalanceActivity.this, pvr.getKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString(), Toast.LENGTH_SHORT).show();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(BalanceActivity.this, R.string.bip38_pw_error, Toast.LENGTH_SHORT).show();
}
if (progress != null && progress.isShowing()) {
progress.cancel();
}
if (keyDecoded) {
SweepUtil.getInstance(BalanceActivity.this).sweep(pvr, false);
}
}
}).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
Toast.makeText(BalanceActivity.this, R.string.bip38_pw_error, Toast.LENGTH_SHORT).show();
}
});
if (!isFinishing()) {
dlg.show();
}
} else if (privKeyReader != null) {
SweepUtil.getInstance(BalanceActivity.this).sweep(privKeyReader, false);
} else {
;
}
} else {
Toast.makeText(BalanceActivity.this, R.string.cannot_recognize_privkey, Toast.LENGTH_SHORT).show();
}
}
Aggregations