-
Notifications
You must be signed in to change notification settings - Fork 441
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
encoding name(ens) for sending register contract #15
Comments
Oh, you mean a Namehash. Do, not yet implemented, although will come together with precompiled bindings to erc20 and erc721
…________________________________
From: Mahdi Mahjoobe <notifications@github.com>
Sent: Saturday, September 1, 2018 3:16:06 PM
To: matterinc/web3swift
Cc: Alexander; Mention
Subject: [matterinc/web3swift] encoding name(ens) for sending register contract (#15)
Hi, @shamatar<https://github.com/shamatar>
there is a function in android web3 that encode name for ens like blew
public class NameHash {
private static final byte[] EMPTY = new byte[32];
public static byte[] nameHashAsBytes(String ensName) {
return Numeric.hexStringToByteArray(nameHash(ensName));
}
public static String nameHash(String ensName) {
String normalisedEnsName = normalise(ensName);
return Numeric.toHexString(nameHash(normalisedEnsName.split("\\.")));
}
private static byte[] nameHash(String[] labels) {
if (labels.length == 0 || labels[0].equals("")) {
return EMPTY;
} else {
String[] tail;
if (labels.length == 1) {
tail = new String[] { };
} else {
tail = Arrays.copyOfRange(labels, 1, labels.length);
}
byte[] remainderHash = nameHash(tail);
byte[] result = Arrays.copyOf(remainderHash, 64);
byte[] labelHash = Hash.sha3(labels[0].getBytes(StandardCharsets.UTF_8));
System.arraycopy(labelHash, 0, result, 32, labelHash.length);
return Hash.sha3(result);
}
}
/**
* Normalise ENS name as per the
* <a href="http://docs.ens.domains/en/latest/implementers.html#normalising-and-validating-names">specification</a>.
*
* @param ensName our user input ENS name
* @return normalised ens name
* @throws EnsResolutionException if the name cannot be normalised
*/
static String normalise(String ensName) {
try {
return IDN.toASCII(ensName, IDN.USE_STD3_ASCII_RULES)
.toLowerCase();
} catch (IllegalArgumentException e) {
throw new EnsResolutionException("Invalid ENS name provided: " + ensName);
}
}
}
this class NameHash is used for hashing name (ens)
do we have any func like this in you're library?
thanks
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#15>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AGKv9xsB03Thn9w6A2fhTmgGTs8DdSEWks5uWoiWgaJpZM4WWN38>.
|
Namehash is implemented in 2.0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi, @shamatar
there is a function in android web3 that encode name for ens like blew
this class NameHash is used for hashing name (ens)
do we have any func like this in you're library?
thanks
The text was updated successfully, but these errors were encountered: