class NameHash {

    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);
        } catch (StringIndexOutOfBoundsException e) {
            // http://bugs.java.com/bugdatabase/view_bug.do?bug_id=8022758
            throw new EnsResolutionException("Invalid ENS name provided: " + ensName);
        }
    }

}