Skip to content

Commit

Permalink
Relax ENS normalize for double-hyphen to only throw on punycode confl…
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent d621428 commit e98924c
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/hash/src.ts/namehash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,27 @@ Zeros.fill(0);
function checkComponent(comp: Uint8Array): Uint8Array {
if (comp.length === 0) { throw new Error("invalid ENS name; empty component"); }
let nonUnder = false;
let last = -1;
let allAscii = true;
for (let i = 0; i < comp.length; i++) {
const c = comp[i];

// An underscore (i.e. "_"); only allows at the beginning
if (c === 0x5f) {
if (nonUnder) { throw new Error("invalid ENS name; non-prefix underscore"); }
} else {
// A hyphen (i.e. "-"); only allows a single in a row
if (c === 0x2d && last === c) {
throw new Error("invalid ENS name; double-hyphen");
}
// Non-ASCII byte
if (c & 0x80) { allAscii = false; }

// Non-underscore found
nonUnder = true;
}
last = c;
}

// Prevent punycode-looking components
if (allAscii && comp[2] === 0x2d && comp[3] === 0x2d) {
throw new Error("invalid ENS name; punycode conflict");
}

return comp;
}

Expand Down Expand Up @@ -98,4 +103,3 @@ export function dnsEncode(name: string): string {

}))) + "00";
}

0 comments on commit e98924c

Please sign in to comment.