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
…icts (#42, #2376, #2754).
  • Loading branch information
ricmoo committed Aug 16, 2022
1 parent d9897e0 commit fce9aaa
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/hash/src.ts/namehash.ts
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 fce9aaa

Please sign in to comment.