use of com.samourai.wallet.hd.HD_Address in project samourai-wallet-android by Samourai-Wallet.
the class AddressFactory method get.
public HD_Address get(int chain) {
int idx = 0;
HD_Address addr = null;
try {
HD_Wallet hdw = HD_WalletFactory.getInstance(context).get();
if (hdw != null) {
idx = HD_WalletFactory.getInstance(context).get().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).getAddrIdx();
addr = HD_WalletFactory.getInstance(context).get().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).getAddressAt(idx);
if (chain == RECEIVE_CHAIN && canIncReceiveAddress(SamouraiWallet.SAMOURAI_ACCOUNT)) {
HD_WalletFactory.getInstance(context).get().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).incAddrIdx();
// PayloadUtil.getInstance(context).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance(context).getPIN()));
}
}
} catch (IOException ioe) {
ioe.printStackTrace();
Toast.makeText(context, "HD wallet error", Toast.LENGTH_SHORT).show();
} catch (MnemonicException.MnemonicLengthException mle) {
mle.printStackTrace();
Toast.makeText(context, "HD wallet error", Toast.LENGTH_SHORT).show();
}
return addr;
}
use of com.samourai.wallet.hd.HD_Address in project samourai-wallet-android by Samourai-Wallet.
the class APIFactory method deleteXPUB.
public synchronized JSONObject deleteXPUB(String xpub, boolean bip49) {
String _url = SamouraiWallet.getInstance().isTestNet() ? WebUtil.SAMOURAI_API2_TESTNET : WebUtil.SAMOURAI_API2;
JSONObject jsonObject = null;
try {
String response = null;
ECKey ecKey = null;
if (AddressFactory.getInstance(context).xpub2account().get(xpub) != null || xpub.equals(BIP49Util.getInstance(context).getWallet().getAccount(0).ypubstr())) {
HD_Address addr = null;
if (bip49) {
addr = BIP49Util.getInstance(context).getWallet().getAccountAt(0).getChange().getAddressAt(0);
} else {
addr = HD_WalletFactory.getInstance(context).get().getAccount(0).getChain(AddressFactory.CHANGE_CHAIN).getAddressAt(0);
}
ecKey = addr.getECKey();
if (ecKey != null && ecKey.hasPrivKey()) {
String sig = ecKey.signMessage(xpub);
String address = null;
if (bip49) {
SegwitAddress segwitAddress = new SegwitAddress(ecKey.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
address = segwitAddress.getAddressAsString();
} else {
address = ecKey.toAddress(SamouraiWallet.getInstance().getCurrentNetworkParams()).toString();
}
if (!TorUtil.getInstance(context).statusFromBroadcast()) {
StringBuilder args = new StringBuilder();
args.append("message=");
args.append(xpub);
args.append("address=");
args.append(address);
args.append("&signature=");
args.append(Uri.encode(sig));
Log.i("APIFactory", "delete XPUB:" + args.toString());
response = WebUtil.getInstance(context).deleteURL(_url + "delete/" + xpub, args.toString());
Log.i("APIFactory", "delete XPUB response:" + response);
} else {
HashMap<String, String> args = new HashMap<String, String>();
args.put("message", xpub);
args.put("address", address);
args.put("signature", Uri.encode(sig));
Log.i("APIFactory", "delete XPUB:" + args.toString());
response = WebUtil.getInstance(context).tor_deleteURL(_url + "delete", args);
Log.i("APIFactory", "delete XPUB response:" + response);
}
try {
jsonObject = new JSONObject(response);
if (jsonObject.has("status") && jsonObject.getString("status").equals("ok")) {
;
}
} catch (JSONException je) {
je.printStackTrace();
jsonObject = null;
}
}
}
} catch (Exception e) {
jsonObject = null;
e.printStackTrace();
}
return jsonObject;
}
use of com.samourai.wallet.hd.HD_Address in project samourai-wallet-android by Samourai-Wallet.
the class BIP47Util method getIncomingMask.
public byte[] getIncomingMask(byte[] pubkey, byte[] outPoint) throws AddressFormatException, Exception {
HD_Address notifAddress = getNotificationAddress();
DumpedPrivateKey dpk = new DumpedPrivateKey(SamouraiWallet.getInstance().getCurrentNetworkParams(), notifAddress.getPrivateKeyString());
ECKey inputKey = dpk.getKey();
byte[] privkey = inputKey.getPrivKeyBytes();
byte[] mask = PaymentCode.getMask(new SecretPoint(privkey, pubkey).ECDHSecretAsBytes(), outPoint);
return mask;
}
use of com.samourai.wallet.hd.HD_Address in project samourai-wallet-android by Samourai-Wallet.
the class AddressFactory method getBIP84.
public SegwitAddress getBIP84(int chain) {
int idx = 0;
HD_Address addr = null;
SegwitAddress p2wpkh = null;
// try {
HD_Wallet hdw = BIP84Util.getInstance(context).getWallet();
if (hdw != null) {
idx = BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).getAddrIdx();
addr = BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).getAddressAt(idx);
p2wpkh = new SegwitAddress(addr.getPubKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
if (chain == RECEIVE_CHAIN && canIncBIP84ReceiveAddress(idx)) {
BIP84Util.getInstance(context).getWallet().getAccount(SamouraiWallet.SAMOURAI_ACCOUNT).getChain(chain).incAddrIdx();
// PayloadUtil.getInstance(context).saveWalletToJSON(new CharSequenceX(AccessFactory.getInstance(context).getGUID() + AccessFactory.getInstance(context).getPIN()));
}
}
return p2wpkh;
}
use of com.samourai.wallet.hd.HD_Address in project samourai-wallet-android by Samourai-Wallet.
the class AddressCalcActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_address_calc);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
edIndex = (EditText) findViewById(R.id.index);
spType = (Spinner) findViewById(R.id.address_type_spinner);
spType.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
if (position == 3) {
tvChain.setVisibility(View.INVISIBLE);
rChain.setVisibility(View.INVISIBLE);
} else {
tvChain.setVisibility(View.VISIBLE);
rChain.setVisibility(View.VISIBLE);
}
}
@Override
public void onNothingSelected(AdapterView<?> parentView) {
;
}
});
populateSpinner();
tvChain = (TextView) findViewById(R.id.chain_label);
rChain = (RadioGroup) findViewById(R.id.chain);
btOK = (Button) findViewById(R.id.ok);
btOK.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try {
HD_Address hd_addr = null;
final SegwitAddress segwitAddress;
String strIndex = edIndex.getText().toString();
if (strIndex == null || strIndex.length() < 1) {
Toast.makeText(AddressCalcActivity.this, R.string.invalid_index, Toast.LENGTH_SHORT).show();
return;
}
int index = Integer.parseInt(strIndex);
int chain = 0;
int selectedId = rChain.getCheckedRadioButtonId();
if (spType.getSelectedItemPosition() == 3) {
chain = 0;
} else if (selectedId == R.id.change) {
chain = 1;
} else {
chain = 0;
}
if (spType.getSelectedItemPosition() == 1) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(0).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else if (spType.getSelectedItemPosition() == 2) {
segwitAddress = null;
hd_addr = HD_WalletFactory.getInstance(AddressCalcActivity.this).get().getAccount(0).getChain(chain).getAddressAt(index);
} else if (spType.getSelectedItemPosition() == 3) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(RicochetMeta.getInstance(AddressCalcActivity.this).getRicochetAccount()).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else if (spType.getSelectedItemPosition() == 4) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(WhirlpoolMeta.getInstance(AddressCalcActivity.this).getWhirlpoolPremixAccount()).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else if (spType.getSelectedItemPosition() == 5) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(WhirlpoolMeta.getInstance(AddressCalcActivity.this).getWhirlpoolPostmix()).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else if (spType.getSelectedItemPosition() == 6) {
hd_addr = BIP84Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(WhirlpoolMeta.getInstance(AddressCalcActivity.this).getWhirlpoolBadBank()).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
} else {
hd_addr = BIP49Util.getInstance(AddressCalcActivity.this).getWallet().getAccountAt(0).getChain(chain).getAddressAt(index);
segwitAddress = new SegwitAddress(hd_addr.getECKey(), SamouraiWallet.getInstance().getCurrentNetworkParams());
}
final ECKey ecKey;
final String strAddress;
if (spType.getSelectedItemPosition() == 2) {
ecKey = hd_addr.getECKey();
strAddress = hd_addr.getAddressString();
} else {
ecKey = segwitAddress.getECKey();
if (spType.getSelectedItemPosition() == 0) {
strAddress = segwitAddress.getAddressAsString();
} else {
strAddress = segwitAddress.getBech32AsString();
}
}
String message = spType.getSelectedItem().toString();
message += "\n";
message += (chain == 1) ? AddressCalcActivity.this.getText(R.string.change_chain) : AddressCalcActivity.this.getText(R.string.receive_chain);
message += "\n";
message += index + ":";
message += "\n";
message += strAddress;
final TextView tvText = new TextView(getApplicationContext());
tvText.setText(message);
tvText.setTextIsSelectable(true);
tvText.setPadding(40, 10, 40, 10);
tvText.setTextColor(0xffffffff);
AlertDialog.Builder dlg = new AlertDialog.Builder(AddressCalcActivity.this).setTitle(R.string.app_name).setView(tvText).setCancelable(true).setNeutralButton(R.string.utxo_sign, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
dialog.dismiss();
String addr = strAddress;
String msg = null;
if (FormatsUtil.getInstance().isValidBech32(addr) || Address.fromBase58(SamouraiWallet.getInstance().getCurrentNetworkParams(), addr).isP2SHAddress()) {
msg = AddressCalcActivity.this.getString(R.string.utxo_sign_text3);
try {
JSONObject obj = new JSONObject();
obj.put("pubkey", ecKey.getPublicKeyAsHex());
obj.put("address", addr);
msg += " " + obj.toString();
} catch (JSONException je) {
msg += ":";
msg += addr;
msg += ", ";
msg += "pubkey:";
msg += ecKey.getPublicKeyAsHex();
}
} else {
msg = AddressCalcActivity.this.getString(R.string.utxo_sign_text2);
}
if (ecKey != null) {
MessageSignUtil.getInstance(AddressCalcActivity.this).doSign(AddressCalcActivity.this.getString(R.string.utxo_sign), AddressCalcActivity.this.getString(R.string.utxo_sign_text1), msg, ecKey);
}
}
}).setNegativeButton(R.string.options_display_privkey, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String strPrivKey = ecKey.getPrivateKeyAsWiF(SamouraiWallet.getInstance().getCurrentNetworkParams());
ImageView showQR = new ImageView(AddressCalcActivity.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(AddressCalcActivity.this);
showText.setText(strPrivKey);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
LinearLayout privkeyLayout = new LinearLayout(AddressCalcActivity.this);
privkeyLayout.setOrientation(LinearLayout.VERTICAL);
privkeyLayout.addView(showQR);
privkeyLayout.addView(showText);
new AlertDialog.Builder(AddressCalcActivity.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 (spType.getSelectedItemPosition() != 2) {
dlg.setPositiveButton(R.string.options_display_redeem_script, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
String redeemScript = org.spongycastle.util.encoders.Hex.toHexString(segwitAddress.segWitRedeemScript().getProgram());
TextView showText = new TextView(AddressCalcActivity.this);
showText.setText(redeemScript);
showText.setTextIsSelectable(true);
showText.setPadding(40, 10, 40, 10);
showText.setTextSize(18.0f);
new AlertDialog.Builder(AddressCalcActivity.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();
}
});
}
if (!isFinishing()) {
dlg.show();
}
} catch (Exception e) {
Toast.makeText(AddressCalcActivity.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