Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ENS and UD resolver #779

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ dependencies {
implementation 'dnsjava:dnsjava:2.1.9'
implementation 'org.jitsi:dnssecjava:1.2.0'
implementation 'org.slf4j:slf4j-nop:1.7.30'
implementation 'com.unstoppabledomains:resolution:3.0.0'
implementation 'com.github.brnunes:swipeablerecyclerview:1.0.2'

implementation 'com.github.aelstad:keccakj:1.1.0'
Expand Down
50 changes: 50 additions & 0 deletions app/src/main/java/com/m2049r/xmrwallet/data/BarcodeData.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
package com.m2049r.xmrwallet.data;

import android.net.Uri;
import android.util.Patterns;

import com.m2049r.xmrwallet.util.OpenAliasHelper;
import com.unstoppabledomains.exceptions.ns.NamingServiceException;
import com.unstoppabledomains.resolution.DomainResolution;
import com.unstoppabledomains.resolution.Resolution;
import com.unstoppabledomains.resolution.naming.service.NamingServiceType;

import java.net.URI;
import java.net.URISyntaxException;
Expand Down Expand Up @@ -175,13 +180,58 @@ static public BarcodeData fromString(String qrCode) {
// maybe it's naked?
bcData = parseNaked(qrCode);
}
if (bcData == null) {
// Check for UD domain
bcData = parseUD(qrCode);
}
if (bcData == null) {
// check for OpenAlias
bcData = parseOpenAlias(qrCode, false);
}
return bcData;
}

static public BarcodeData parseUD(String udString) {
Timber.d("parseUD=%s", udString);
if (udString == null || !Patterns.DOMAIN_NAME.matcher(udString).matches()) return null;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default DOMAIN_NAME pattern probably won't match some crypto TLDs.
I can't double-check now, but looking at https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/util/Patterns.java#309 it looks like it won't match 888 and x domains.

Since you are already handling any errors that may be returned from the library. What do you think about removing this check altogether?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point, I'll remove the domain check


DomainResolution resolution = Resolution.builder()
.providerUrl(NamingServiceType.ENS, "https://cloudflare-eth.com")
.build();

final String[] address = {null};
final Crypto[] crypto = {null};
Thread udThread = new Thread(new Runnable() {
@Override
public void run() {
for (Crypto currentCrypto: Crypto.values()) {
try {
address[0] = resolution.getAddress(udString, currentCrypto.getSymbol().toLowerCase());
crypto[0] = currentCrypto;
break;
} catch (NamingServiceException e) {
Timber.d(e.getLocalizedMessage());
}
}
}
});
udThread.start();
try {
udThread.join();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why start a thread and then block the UI thread waiting for it to finish anyway?

} catch (InterruptedException e) {
return null;
}
if (crypto[0] == null) {
Timber.d("Unsupported UD address %s", udString);
return null;
}
if (!crypto[0].validate(address[0])) {
Timber.d("%s address invalid", crypto[0]);
return null;
}
return new BarcodeData(crypto[0], address[0], udString, null, null, Security.NORMAL);
}

static public BarcodeData parseOpenAlias(String oaString, boolean dnssec) {
Timber.d("parseOpenAlias=%s", oaString);
if (oaString == null) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@
import com.m2049r.xmrwallet.util.validator.BitcoinAddressType;
import com.m2049r.xmrwallet.util.validator.BitcoinAddressValidator;
import com.m2049r.xmrwallet.util.validator.EthAddressValidator;
import com.unstoppabledomains.exceptions.ns.NamingServiceException;
import com.unstoppabledomains.resolution.DomainResolution;
import com.unstoppabledomains.resolution.Resolution;
import com.unstoppabledomains.resolution.naming.service.NamingServiceType;

import java.util.HashMap;
import java.util.HashSet;
Expand Down Expand Up @@ -156,11 +160,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
etAddress.getEditText().setOnFocusChangeListener((v, hasFocus) -> {
if (!hasFocus) {
String enteredAddress = etAddress.getEditText().getText().toString().trim();
String dnsOA = dnsFromOpenAlias(enteredAddress);
Timber.d("OpenAlias is %s", dnsOA);
if (dnsOA != null) {
processOpenAlias(dnsOA);
}
processUD(enteredAddress);
}
});
etAddress.getEditText().addTextChangedListener(new TextWatcher() {
Expand Down Expand Up @@ -206,6 +206,8 @@ public void afterTextChanged(Editable editable) {
}
if (possibleCryptos.isEmpty()) {
Timber.d("other");
// Makes the height of tvXmrTo consistent when invisible
tvXmrTo.setText(Html.fromHtml(getString(R.string.info_xmrto_help_xmr)));
tvXmrTo.setVisibility(View.INVISIBLE);
sendListener.setMode(SendFragment.Mode.XMR);
}
Expand Down Expand Up @@ -241,7 +243,6 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
etNotes = view.findViewById(R.id.etNotes);
etNotes.getEditText().setRawInputType(InputType.TYPE_CLASS_TEXT);
etNotes.getEditText().

setOnEditorActionListener((v, actionId, event) -> {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) && (event.getAction() == KeyEvent.ACTION_DOWN))
|| (actionId == EditorInfo.IME_ACTION_DONE)) {
Expand Down Expand Up @@ -305,13 +306,78 @@ private void updateCryptoButtons(boolean noAddress) {
tvXmrTo.setText(Html.fromHtml(getString(R.string.info_xmrto_ambiguous)));
tvXmrTo.setVisibility(View.VISIBLE);
} else {
// Makes the height of tvXmrTo consistent when invisible
tvXmrTo.setText(Html.fromHtml(getString(R.string.info_xmrto_help_xmr)));
tvXmrTo.setVisibility(View.INVISIBLE);
}
if (noAddress) {
selectedCrypto(Crypto.XMR);
}
}

private void processUD(String udString) {
if (udString == null || udString.length() == 0 || checkAddressNoError()) {
requireActivity().runOnUiThread(() -> etAddress.setErrorEnabled(false));
return;
}
sendListener.popBarcodeData();

DomainResolution resolution = Resolution.builder()
.providerUrl(NamingServiceType.ENS, "https://cloudflare-eth.com")
.build();
final boolean[] domainIsUD = {false};
final String[] address = {null};
final Crypto[] crypto = {null};
etAddress.setError(getString(R.string.send_address_resolve_ud));
new Thread(() -> {
for (Crypto currentCrypto: Crypto.values()) {
try {
address[0] = resolution.getAddress(udString, currentCrypto.getSymbol().toLowerCase());
crypto[0] = currentCrypto;
domainIsUD[0] = true;
break;
} catch (NamingServiceException e) {
Timber.d(e.getLocalizedMessage());
switch (e.getCode()) {
case UnknownCurrency:
case RecordNotFound:
domainIsUD[0] = true;
break;
default:
domainIsUD[0] = false;
break;
}
}
}

requireActivity().runOnUiThread(() -> {
if (domainIsUD[0]) {
if (crypto[0] == null) {
Timber.d("Unsupported UD address %s", udString);
etAddress.setError(getString(R.string.send_address_no_ud_records));
} else {
BarcodeData barcodeData = new BarcodeData(crypto[0], address[0], udString,
null, null, BarcodeData.Security.NORMAL);
processScannedData(barcodeData);
}
} else {
Timber.d("Non ENS / UD address %s", udString);
goToOpenAlias(udString);
}
});
}).start();
}

private void goToOpenAlias(String enteredAddress) {
String dnsOA = dnsFromOpenAlias(enteredAddress);
Timber.d("OpenAlias is %s", dnsOA);
if (dnsOA != null) {
processOpenAlias(dnsOA);
} else {
etAddress.setError(getString(R.string.send_address_not_openalias));
}
}

private void processOpenAlias(String dnsOA) {
if (resolvingOA) return; // already resolving - just wait
sendListener.popBarcodeData();
Expand Down Expand Up @@ -395,11 +461,7 @@ public boolean onValidateFields() {
if (!checkAddressNoError()) {
shakeAddress();
String enteredAddress = etAddress.getEditText().getText().toString().trim();
String dnsOA = dnsFromOpenAlias(enteredAddress);
Timber.d("OpenAlias is %s", dnsOA);
if (dnsOA != null) {
processOpenAlias(dnsOA);
}
processUD(enteredAddress);
return false;
}

Expand Down
15 changes: 12 additions & 3 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:locale="en">
<resources>
<string name="wallet_activity_name">محفظة</string>

<string name="menu_about">عن</string>
Expand All @@ -9,6 +9,7 @@
<string name="menu_help">ساعدني</string>
<string name="menu_receive">استلم</string>
<string name="menu_rename">أعد التسمية &#8230;</string>
<string name="menu_delete">Delete</string>
<string name="menu_backup">انشئ نسخة احتياطية</string>
<string name="menu_changepw">غير كلمة المرور</string>

Expand All @@ -35,7 +36,7 @@

<string name="info_xmrto"><![CDATA[
<b>أدخلت عنوان بيتكوين.</b><br/>
<i>سترسل XMR و سيستلم المستلم BTC باستخدام خدمة <b>Sideshift.ai</b></i>
<i>سترسل XMR و سيستلم المستلم %1$s باستخدام خدمة <b>Sideshift.ai</b></i>
]]></string>

<string name="info_send_xmrto_success_order_label">Sideshift.ai طلب</string>
Expand Down Expand Up @@ -93,6 +94,7 @@

<string name="backup_success">نجح النسخ الاحتياطي</string>
<string name="backup_failed">فشل النسخ الاحتياطي!</string>
<string name="delete_failed">Delete failed!</string>
<string name="rename_failed">فشلت إعادة التسمية!</string>
<string name="changepw_failed">فشل تغيير كلمة السر!</string>
<string name="changepw_success">تم تغيير كلمة السر</string>
Expand Down Expand Up @@ -415,4 +417,11 @@

<string name="menu_deletecache">أعد ضبط المحفظة!</string>
<string name="deletecache_alert_message">ستتم إعادة ضبط هذه المحفظة ، وفقدان جميع البيانات خارج السلسلة (مثل الملاحظات ، وأسماء الحسابات والعناوين الفرعية ، ومفاتيح المعاملات الخاصة ، ...)! استخدم هذا فقط إذا كانت هذه المحفظة تالفة و لا تحمل!</string>
</resources>

<string name="delete_alert_message">This wallet will be deleted. Your funds will be gone forever unless you have your seed or a working backup to recover it.</string>
<string name="delete_alert_yes">Yes, do that!</string>
<string name="delete_alert_no">No thanks!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-cat/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -427,4 +427,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-el/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-eo/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-et/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-hu/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -431,4 +431,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-nb/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-nl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-pt-rBR/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -420,4 +420,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-pt/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-ro/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -428,4 +428,7 @@

<string name="menu_deletecache">Reset wallet!</string>
<string name="deletecache_alert_message">This wallet will be reset, losing all off-chain data (like notes, account &amp; subaddress names, private transaction keys, ...)! Use this ONLY if this wallet is corrupt and does not load!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,7 @@

<string name="menu_deletecache">Сбросить кошелек</string>
<string name="deletecache_alert_message">Этот кошелек будет сброшен, вы потеряете все данные, которые не находятся в блокчейне (например примечания, имена подадресов, приватные ключи транзакций, ...)! Используйте это ТОЛЬКО если ваш кошелек поврежден и не загружается!</string>

<string name="send_address_resolve_ud">Resolving ENS / UD&#8230;</string>
<string name="send_address_no_ud_records">No address found for ENS / UD domain</string>
</resources>
Loading