use of com.samourai.wallet.bip47.rpc.PaymentAddress 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;
}
use of com.samourai.wallet.bip47.rpc.PaymentAddress in project samourai-wallet-android by Samourai-Wallet.
the class SendFactory method getPrivKey.
public static ECKey getPrivKey(String address) {
ECKey ecKey = null;
try {
String path = APIFactory.getInstance(context).getUnspentPaths().get(address);
// Log.d("APIFactory", "address:" + path);
if (path != null) {
String[] s = path.split("/");
if (Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), address).isP2SHAddress()) {
// Log.d("APIFactory", "address type:" + "bip49");
HD_Address addr = BIP49Util.getInstance(context).getWallet().getAccount(0).getChain(Integer.parseInt(s[1])).getAddressAt(Integer.parseInt(s[2]));
ecKey = addr.getECKey();
} else {
// Log.d("APIFactory", "address type:" + "bip44");
int account_no = APIFactory.getInstance(context).getUnspentAccounts().get(address);
HD_Address hd_address = AddressFactory.getInstance(context).get(account_no, Integer.parseInt(s[1]), Integer.parseInt(s[2]));
String strPrivKey = hd_address.getPrivateKeyString();
DumpedPrivateKey pk = new DumpedPrivateKey(SamouraiWallet.getInstance().getCurrentNetworkParams(), strPrivKey);
ecKey = pk.getKey();
}
} else {
// Log.d("APIFactory", "address type:" + "bip47");
String pcode = BIP47Meta.getInstance().getPCode4Addr(address);
int idx = BIP47Meta.getInstance().getIdx4Addr(address);
PaymentAddress addr = BIP47Util.getInstance(context).getReceiveAddress(new PaymentCode(pcode), idx);
ecKey = addr.getReceiveECKey();
}
} catch (Exception e) {
e.printStackTrace();
return null;
}
return ecKey;
}
use of com.samourai.wallet.bip47.rpc.PaymentAddress in project samourai-wallet-android by Samourai-Wallet.
the class SendActivity method processPCode.
private void processPCode(String pcode, String meta) {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
setBalance();
}
}, 2000);
if (FormatsUtil.getInstance().isValidPaymentCode(pcode)) {
if (BIP47Meta.getInstance().getOutgoingStatus(pcode) == BIP47Meta.STATUS_SENT_CFM) {
try {
PaymentCode _pcode = new PaymentCode(pcode);
PaymentAddress paymentAddress = BIP47Util.getInstance(this).getSendAddress(_pcode, BIP47Meta.getInstance().getOutgoingIdx(pcode));
if (BIP47Meta.getInstance().getSegwit(pcode)) {
SegwitAddress segwitAddress = new SegwitAddress(paymentAddress.getSendECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
strDestinationBTCAddress = segwitAddress.getBech32AsString();
} else {
strDestinationBTCAddress = paymentAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
}
strPCode = _pcode.toString();
setToAddress(BIP47Meta.getInstance().getDisplayLabel(strPCode));
toAddressEditText.setEnabled(false);
validateSpend();
} catch (Exception e) {
Toast.makeText(this, R.string.error_payment_code, Toast.LENGTH_SHORT).show();
}
} else {
// Toast.makeText(SendActivity.this, "Payment must be added and notification tx sent", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(this, PayNymDetailsActivity.class);
intent.putExtra("pcode", pcode);
intent.putExtra("label", "");
if (meta != null && meta.startsWith("?") && meta.length() > 1) {
meta = meta.substring(1);
if (meta.length() > 0) {
String _meta = null;
Map<String, String> map = new HashMap<String, String>();
meta.length();
try {
_meta = URLDecoder.decode(meta, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
map = Splitter.on('&').trimResults().withKeyValueSeparator("=").split(_meta);
intent.putExtra("label", map.containsKey("title") ? map.get("title").trim() : "");
}
}
if (!openedPaynym) {
startActivity(intent);
openedPaynym = true;
}
}
} else {
Toast.makeText(this, R.string.invalid_payment_code, Toast.LENGTH_SHORT).show();
}
}
use of com.samourai.wallet.bip47.rpc.PaymentAddress in project samourai-wallet-android by Samourai-Wallet.
the class BatchSendActivity method processPCode.
private void processPCode(String pcode, String meta) {
if (FormatsUtil.getInstance().isValidPaymentCode(pcode)) {
if (BIP47Meta.getInstance().getOutgoingStatus(pcode) == BIP47Meta.STATUS_SENT_CFM) {
try {
PaymentCode _pcode = new PaymentCode(pcode);
PaymentAddress paymentAddress = BIP47Util.getInstance(BatchSendActivity.this).getSendAddress(_pcode, BIP47Meta.getInstance().getOutgoingIdx(pcode));
if (BIP47Meta.getInstance().getSegwit(pcode)) {
SegwitAddress segwitAddress = new SegwitAddress(paymentAddress.getSendECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
strDestinationBTCAddress = segwitAddress.getBech32AsString();
} else {
strDestinationBTCAddress = paymentAddress.getSendECKey().toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
}
strPCode = _pcode.toString();
edAddress.setText(BIP47Meta.getInstance().getDisplayLabel(strPCode));
edAddress.setEnabled(false);
} catch (Exception e) {
Toast.makeText(BatchSendActivity.this, R.string.error_payment_code, Toast.LENGTH_SHORT).show();
}
} else {
if (meta != null && meta.startsWith("?") && meta.length() > 1) {
meta = meta.substring(1);
}
Intent intent = new Intent(BatchSendActivity.this, PayNymDetailsActivity.class);
intent.putExtra("pcode", pcode);
if (meta != null && meta.length() > 0) {
if (meta.startsWith("?") && meta.length() > 1) {
meta = meta.substring(1);
if (meta.length() > 0) {
String _meta = null;
Map<String, String> map = new HashMap<String, String>();
meta.length();
try {
_meta = URLDecoder.decode(meta, "UTF-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
map = Splitter.on('&').trimResults().withKeyValueSeparator("=").split(_meta);
intent.putExtra("label", map.containsKey("title") ? map.get("title").trim() : "");
}
}
}
startActivity(intent);
}
} else {
Toast.makeText(BatchSendActivity.this, R.string.invalid_payment_code, Toast.LENGTH_SHORT).show();
}
}
use of com.samourai.wallet.bip47.rpc.PaymentAddress in project samourai-wallet-android by Samourai-Wallet.
the class PayNymCalcActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_paynym_calc);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
edPayNym = (EditText) findViewById(R.id.paynym);
edIndex = (EditText) findViewById(R.id.index);
edPayNym.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
// final int DRAWABLE_LEFT = 0;
// final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
if (event.getAction() == MotionEvent.ACTION_UP && event.getRawX() >= (edPayNym.getRight() - edPayNym.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
final List<String> entries = new ArrayList<String>();
entries.addAll(BIP47Meta.getInstance().getSortedByLabels(true));
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(PayNymCalcActivity.this, android.R.layout.select_dialog_singlechoice);
for (int i = 0; i < entries.size(); i++) {
arrayAdapter.add(BIP47Meta.getInstance().getDisplayLabel(entries.get(i)));
}
AlertDialog.Builder dlg = new AlertDialog.Builder(PayNymCalcActivity.this);
dlg.setIcon(R.drawable.ic_launcher);
dlg.setTitle(R.string.app_name);
dlg.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
edPayNym.setText(entries.get(which));
}
});
dlg.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
dlg.show();
return true;
}
return false;
}
});
btOK = (Button) findViewById(R.id.ok);
btOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String strPayNym = edPayNym.getText().toString();
String strIndex = edIndex.getText().toString();
PaymentCode pcode = new PaymentCode(strPayNym);
if (pcode == null) {
Toast.makeText(PayNymCalcActivity.this, R.string.invalid_payment_code, Toast.LENGTH_SHORT).show();
return;
}
if (strIndex == null || strIndex.length() < 1) {
Toast.makeText(PayNymCalcActivity.this, R.string.invalid_index, Toast.LENGTH_SHORT).show();
return;
}
try {
int index = Integer.parseInt(strIndex);
String message = strPayNym;
final ECKey receiveECKey;
final SegwitAddress receiveSegwit;
PaymentAddress receiveAddress = BIP47Util.getInstance(PayNymCalcActivity.this).getReceiveAddress(new PaymentCode(strPayNym), index);
PaymentAddress sendAddress = BIP47Util.getInstance(PayNymCalcActivity.this).getSendAddress(new PaymentCode(strPayNym), index);
receiveECKey = receiveAddress.getReceiveECKey();
ECKey sendECKey = sendAddress.getSendECKey();
receiveSegwit = new SegwitAddress(receiveECKey, SamouraiWallet.getInstance().getCurrentNetworkParams());
SegwitAddress sendSegwit = new SegwitAddress(sendECKey, SamouraiWallet.getInstance().getCurrentNetworkParams());
message += "\n";
message += index + ":";
message += "\n";
message += "\n";
message += PayNymCalcActivity.this.getText(R.string.receive_addresses).toString() + ":";
message += "\n";
message += receiveECKey.toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
message += "\n";
message += receiveSegwit.getAddressAsString();
message += "\n";
message += receiveSegwit.getBech32AsString();
message += "\n";
message += PayNymCalcActivity.this.getText(R.string.send_addresses).toString() + ":";
message += "\n";
message += sendECKey.toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
message += "\n";
message += sendSegwit.getAddressAsString();
message += "\n";
message += sendSegwit.getBech32AsString();
message += "\n";
final TextView tvText = new TextView(getApplicationContext());
tvText.setTextSize(12);
tvText.setText(message);
tvText.setTextIsSelectable(true);
tvText.setPadding(40, 10, 40, 10);
tvText.setTextColor(0xffffffff);
AlertDialog.Builder dlg = new AlertDialog.Builder(PayNymCalcActivity.this).setTitle(R.string.app_name).setView(tvText).setCancelable(true).setPositiveButton(R.string.display_receive_redeem, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String redeemScript = org.spongycastle.util.encoders.Hex.toHexString(receiveSegwit.segWitRedeemScript().getProgram());
TextView showText = new TextView(PayNymCalcActivity.this);
showText.setText(redeemScript);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
new AlertDialog.Builder(PayNymCalcActivity.this).setTitle(R.string.app_name).setView(showText).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
}).show();
}
}).setNeutralButton(R.string.close, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
}
}).setNegativeButton(R.string.display_receive_privkey, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String strPrivKey = receiveECKey.getPrivateKeyAsWiF(SamouraiWallet.getInstance().getCurrentNetworkParams());
ImageView showQR = new ImageView(PayNymCalcActivity.this);
Bitmap bitmap = null;
QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(strPrivKey, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), 500);
try {
bitmap = qrCodeEncoder.encodeAsBitmap();
} catch (WriterException e) {
e.printStackTrace();
}
showQR.setImageBitmap(bitmap);
TextView showText = new TextView(PayNymCalcActivity.this);
showText.setText(strPrivKey);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
LinearLayout privkeyLayout = new LinearLayout(PayNymCalcActivity.this);
privkeyLayout.setOrientation(LinearLayout.VERTICAL);
privkeyLayout.addView(showQR);
privkeyLayout.addView(showText);
new AlertDialog.Builder(PayNymCalcActivity.this).setTitle(R.string.app_name).setView(privkeyLayout).setCancelable(false).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
;
}
}).show();
}
});
if (!isFinishing()) {
dlg.show();
}
} catch (Exception e) {
Toast.makeText(PayNymCalcActivity.this, e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
});
btCancel = (Button) findViewById(R.id.cancel);
btCancel.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
finish();
}
});
}
Aggregations