Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
validate / validate-idna-to-asciiOpenRuns on Liberas

Domain name to ASCII (IDNA)

Converts a domain name to its ASCII form by UTS #46 ToASCII: map, normalize, break into labels, validate, then convert each non-ASCII label to xn-- Punycode. UTS #46 (Unicode IDNA Compatibility Processing) for Unicode 18.0.0: its IdnaMappingTable and Unicode 18.0.0 normalization (NFC) and character properties. Non-transitional (Transitional_Processing false: ß, ς, ZWJ and ZWNJ are kept, not mapped). Flags: CheckHyphens true (no label starts or ends with -, or has -- as its 3rd and 4th characters), CheckBidi true (RFC 5893's rules when the domain has right-to-left characters), CheckJoiners true (ZWNJ and ZWJ only where RFC 5892 Appendix A.1 and A.2 allow them), UseSTD3ASCIIRules true (after mapping, the only ASCII allowed is a-z, 0-9, - and the label separator .), IgnoreInvalidPunycode false. Labels are separated by . and the full stops U+3002, U+FF0E, U+FF61 after mapping; an xn-- label must decode as Punycode (RFC 3492) to a valid label in NFC that does not round-trip differently. ICU's limits apply (ICU-13727): an xn-- label with over 2,000 characters after xn--, or a non-ASCII label over 1,000 code points, is an error. VerifyDnsLength true: the result must be 1 to 253 characters with every label 1 to 63, so empty labels, including the root label of a trailing dot, are errors. Any UTS #46 error gives none: which error is not part of the contract (UTS #46 does not fix error codes). Input over 65,536 bytes is none. Unicode's IdnaTestV2.txt 18.0.0 is the test of record; where an edge case differs from it, the reference (the Rust idna crate 1.1.0 with ICU4X data 2.4.0, which is Unicode 18.0.0) rules.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init validate-idna-to-ascii --lang rust
cd validate-idna-to-ascii && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)11 lines›
validate-idna-to-ascii.wit
package root:component;

world root {
  export liberas:validate/to-ascii@0.1.0;
}
package liberas:validate@0.1.0 {
  interface to-ascii {
    convert: func(input: string) -> option<string>;
  }
}
Test vectors73›
validate-idna-to-ascii.cases.json
[
  {
    "args": {
      "input": "example.com"
    }
  },
  {
    "args": {
      "input": "EXAMPLE.COM"
    }
  },
  {
    "args": {
      "input": "münchen.de"
    }
  },
  {
    "args": {
      "input": "xn--mnchen-3ya.de"
    }
  },
  {
    "args": {
      "input": "例え.テスト"
    }
  },
  {
    "args": {
      "input": "한국어.kr"
    }
  },
  {
    "args": {
      "input": "a_b.example"
    }
  },
  {
    "args": {
      "input": "ab--c.example"
    }
  },
  {
    "args": {
      "input": "-a.example"
    }
  },
  {
    "args": {
      "input": "a-.example"
    }
  },
  {
    "args": {
      "input": "a..b"
    }
  },
  {
    "args": {
      "input": "a.com."
    }
  },
  {
    "args": {
      "input": ""
    }
  },
  {
    "args": {
      "input": "xn--"
    }
  },
  {
    "args": {
      "input": "xn--a"
    }
  },
  {
    "args": {
      "input": "XN--MNCHEN-3YA.DE"
    }
  },
  {
    "args": {
      "input": "a b.example"
    }
  },
  {
    "args": {
      "input": "a@b.example"
    }
  },
  {
    "args": {
      "input": "١٢٣.com"
    }
  },
  {
    "args": {
      "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com"
    }
  },
  {
    "args": {
      "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.com"
    }
  },
  {
    "args": {
      "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.a"
    }
  },
  {
    "args": {
      "input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.ab"
    }
  },
  {
    "args": {
      "input": "fass.de"
    }
  },
  {
    "args": {
      "input": "faß.de"
    }
  },
  {
    "args": {
      "input": "Faß.de"
    }
  },
  {
    "args": {
      "input": "xn--fa-hia.de"
    }
  },
  {
    "args": {
      "input": "à.א̈"
    }
  },
  {
    "args": {
      "input": "᧚"
    }
  },
  {
    "args": {
      "input": "FAẞ.DE"
    }
  },
  {
    "args": {
      "input": "www.ශ්‍රී.com"
    }
  },
  {
    "args": {
      "input": "Ü.xn--tda"
    }
  },
  {
    "args": {
      "input": "日本語。Jp"
    }
  },
  {
    "args": {
      "input": "123456789012345678901234567890123456789012345678901234567890123.1234567890123456789012345678901234567890123456789012345678901234.123456789012345678901234567890123456789012345678901234567890123.12345678901234567890123456789012345678901234567890123456789a"
    }
  },
  {
    "args": {
      "input": "123456789012345678901234567890123456789012345678901234567890123.1234567890Ä123456789012345678901234567890123456789012345.123456789012345678901234567890123456789012345678901234567890123.123456789012345678901234567890123456789012345678901234567890b"
    }
  },
  {
    "args": {
      "input": "א٧ת"
    }
  },
  {
    "args": {
      "input": "xn--ghb65a953d"
    }
  },
  {
    "args": {
      "input": "繱𑖿‍.I."
    }
  },
  {
    "args": {
      "input": "ݖ.Σ"
    }
  },
  {
    "args": {
      "input": "ᚭ.𝌠Ss𖫱"
    }
  },
  {
    "args": {
      "input": "ßুᷭ。ؠ8₅"
    }
  },
  {
    "args": {
      "input": "Ⅎ្.≠"
    }
  },
  {
    "args": {
      "input": "xn--skb.xn--g9e"
    }
  },
  {
    "args": {
      "input": "舌.ꡈ5≯ß"
    }
  },
  {
    "args": {
      "input": "ⴚ.σ"
    }
  },
  {
    "args": {
      "input": "σⴥ。ݚ"
    }
  },
  {
    "args": {
      "input": "ⴕ。۰≮ss݅"
    }
  },
  {
    "args": {
      "input": "齙--𝟰.ss"
    }
  },
  {
    "args": {
      "input": "1𝨙⸖."
    }
  },
  {
    "args": {
      "input": "羚.≯"
    }
  },
  {
    "args": {
      "input": "xn--gky8837e."
    }
  },
  {
    "args": {
      "input": "xn--ss-bh7o"
    }
  },
  {
    "args": {
      "input": "ჁႱ6̘.SSᬃ"
    }
  },
  {
    "args": {
      "input": "àא"
    }
  },
  {
    "args": {
      "input": "xn--1-bs31m..xn--tv36e"
    }
  },
  {
    "args": {
      "input": "𐹸󠋳。‍Σ7"
    }
  },
  {
    "args": {
      "input": "ⴋ≮𱲆。‍ާ𐋣"
    }
  },
  {
    "args": {
      "input": "4𐋷ڹ.𞤭򿍡"
    }
  },
  {
    "args": {
      "input": "ڇ6Ⴔ辘.ﴢڇ‌"
    }
  },
  {
    "args": {
      "input": "ᠢ𐮂𐫘寐。‌≯✳"
    }
  },
  {
    "args": {
      "input": "ڶ۟.7꠆"
    }
  },
  {
    "args": {
      "input": "‌ⴆ3。-⃒-ߑ"
    }
  },
  {
    "args": {
      "input": "ࣟⴋ𶿸귤.򠅼0휪ૣ"
    }
  },
  {
    "args": {
      "input": "≠ႷᠤႫ。?͌س觴"
    }
  },
  {
    "args": {
      "input": "xn--hhb94ag41b739u.xn--dzb5582f"
    }
  },
  {
    "args": {
      "input": "xn--r5g.xn--ybc995g0835a"
    }
  },
  {
    "args": {
      "input": "xn--0ug754gxl4ldlt0k.xn--jgb476m"
    }
  },
  {
    "args": {
      "input": "xn--ofh.xn--rjb13118f"
    }
  },
  {
    "args": {
      "input": "Ⴘۂ𑲭。-"
    }
  },
  {
    "args": {
      "input": "xn--bk9c.xn--gdhx6802k"
    }
  },
  {
    "args": {
      "input": "ఀ9‍بح.‍ݐ1."
    }
  },
  {
    "args": {
      "input": "򋡐。≯𑋪"
    }
  },
  {
    "args": {
      "input": "xn--?-c1g3623d.xn--1ug73gl146a"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 73 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 160,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.