Skip to content

Commit fce9aaa

Browse files
committed
Relax ENS normalize for double-hyphen to only throw on punycode conflicts (#42, #2376, #2754).
1 parent d9897e0 commit fce9aaa

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

packages/hash/src.ts/namehash.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,27 @@ Zeros.fill(0);
1414
function checkComponent(comp: Uint8Array): Uint8Array {
1515
if (comp.length === 0) { throw new Error("invalid ENS name; empty component"); }
1616
let nonUnder = false;
17-
let last = -1;
17+
let allAscii = true;
1818
for (let i = 0; i < comp.length; i++) {
1919
const c = comp[i];
2020

2121
// An underscore (i.e. "_"); only allows at the beginning
2222
if (c === 0x5f) {
2323
if (nonUnder) { throw new Error("invalid ENS name; non-prefix underscore"); }
2424
} else {
25-
// A hyphen (i.e. "-"); only allows a single in a row
26-
if (c === 0x2d && last === c) {
27-
throw new Error("invalid ENS name; double-hyphen");
28-
}
25+
// Non-ASCII byte
26+
if (c & 0x80) { allAscii = false; }
27+
28+
// Non-underscore found
2929
nonUnder = true;
3030
}
31-
last = c;
3231
}
32+
33+
// Prevent punycode-looking components
34+
if (allAscii && comp[2] === 0x2d && comp[3] === 0x2d) {
35+
throw new Error("invalid ENS name; punycode conflict");
36+
}
37+
3338
return comp;
3439
}
3540

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

99104
}))) + "00";
100105
}
101-

0 commit comments

Comments
 (0)