Replicated former ENS normalize behaviour for empty strings and update namehash testcases.

This commit is contained in:
Richard Moore 2023-10-10 22:22:55 -04:00
parent bc115a2733
commit 125ff1189b
2 changed files with 3 additions and 0 deletions

View File

@ -44,6 +44,7 @@ function ensNameSplit(name: string): Array<Uint8Array> {
*/
export function ensNormalize(name: string): string {
try {
if (name.length === 0) { throw new Error("empty label"); }
return ens_normalize(name);
} catch (error: any) {
assertArgument(false, `invalid ENS name (${ error.message })`, "name", name);
@ -66,6 +67,8 @@ export function isValidName(name: string): name is string {
export function namehash(name: string): string {
assertArgument(typeof(name) === "string", "invalid ENS name; not a string", "name", name);
assertArgument(name.length, `invalid ENS name (empty label)`, "name", name);
let result: string | Uint8Array = Zeros;
const comps = ensNameSplit(name);

Binary file not shown.