@qevm/hash 5.7.2 → 5.7.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -5
- package/lib/_version.d.ts +1 -1
- package/lib/_version.js +1 -1
- package/lib/id.js +1 -1
- package/lib/id.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js.map +1 -1
- package/lib/message.d.ts +1 -1
- package/lib/message.d.ts.map +1 -1
- package/lib/message.js +4 -4
- package/lib/message.js.map +1 -1
- package/lib/namehash.d.ts.map +1 -1
- package/lib/namehash.js +9 -7
- package/lib/namehash.js.map +1 -1
- package/lib/typed-data.d.ts.map +1 -1
- package/lib/typed-data.js +49 -33
- package/lib/typed-data.js.map +1 -1
- package/package.json +34 -30
- package/src.ts/_version.ts +1 -1
- package/src.ts/id.ts +1 -1
- package/src.ts/index.ts +1 -5
- package/src.ts/message.ts +12 -9
- package/src.ts/namehash.ts +42 -23
- package/src.ts/typed-data.ts +271 -112
package/src.ts/namehash.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { concat, hexlify } from "@qevm/bytes";
|
|
2
2
|
import { toUtf8Bytes, toUtf8String } from "@qevm/strings";
|
|
3
|
-
import { keccak256 } from "@
|
|
3
|
+
import { keccak256 } from "@qevm/keccak256";
|
|
4
4
|
|
|
5
|
-
import { Logger } from "@
|
|
5
|
+
import { Logger } from "@qevm/logger";
|
|
6
6
|
import { version } from "./_version";
|
|
7
7
|
const logger = new Logger(version);
|
|
8
8
|
|
|
@@ -12,15 +12,19 @@ const Zeros = new Uint8Array(32);
|
|
|
12
12
|
Zeros.fill(0);
|
|
13
13
|
|
|
14
14
|
function checkComponent(comp: Uint8Array): Uint8Array {
|
|
15
|
-
if (comp.length === 0) {
|
|
15
|
+
if (comp.length === 0) {
|
|
16
|
+
throw new Error("invalid ENS name; empty component");
|
|
17
|
+
}
|
|
16
18
|
return comp;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
function ensNameSplit(name: string): Array<Uint8Array> {
|
|
20
22
|
const bytes = toUtf8Bytes(ens_normalize(name));
|
|
21
|
-
const comps: Array<Uint8Array> = [
|
|
23
|
+
const comps: Array<Uint8Array> = [];
|
|
22
24
|
|
|
23
|
-
if (name.length === 0) {
|
|
25
|
+
if (name.length === 0) {
|
|
26
|
+
return comps;
|
|
27
|
+
}
|
|
24
28
|
|
|
25
29
|
let last = 0;
|
|
26
30
|
for (let i = 0; i < bytes.length; i++) {
|
|
@@ -34,27 +38,35 @@ function ensNameSplit(name: string): Array<Uint8Array> {
|
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
// There was a stray separator at the end of the name
|
|
37
|
-
if (last >= bytes.length) {
|
|
41
|
+
if (last >= bytes.length) {
|
|
42
|
+
throw new Error("invalid ENS name; empty component");
|
|
43
|
+
}
|
|
38
44
|
|
|
39
45
|
comps.push(checkComponent(bytes.slice(last)));
|
|
40
46
|
return comps;
|
|
41
47
|
}
|
|
42
48
|
|
|
43
49
|
export function ensNormalize(name: string): string {
|
|
44
|
-
return ensNameSplit(name)
|
|
50
|
+
return ensNameSplit(name)
|
|
51
|
+
.map((comp) => toUtf8String(comp))
|
|
52
|
+
.join(".");
|
|
45
53
|
}
|
|
46
54
|
|
|
47
55
|
export function isValidName(name: string): boolean {
|
|
48
56
|
try {
|
|
49
|
-
return
|
|
50
|
-
} catch (error) {
|
|
57
|
+
return ensNameSplit(name).length !== 0;
|
|
58
|
+
} catch (error) {}
|
|
51
59
|
return false;
|
|
52
60
|
}
|
|
53
61
|
|
|
54
62
|
export function namehash(name: string): string {
|
|
55
63
|
/* istanbul ignore if */
|
|
56
|
-
if (typeof
|
|
57
|
-
logger.throwArgumentError(
|
|
64
|
+
if (typeof name !== "string") {
|
|
65
|
+
logger.throwArgumentError(
|
|
66
|
+
"invalid ENS name; not a string",
|
|
67
|
+
"name",
|
|
68
|
+
name,
|
|
69
|
+
);
|
|
58
70
|
}
|
|
59
71
|
|
|
60
72
|
let result: string | Uint8Array = Zeros;
|
|
@@ -68,16 +80,23 @@ export function namehash(name: string): string {
|
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
export function dnsEncode(name: string): string {
|
|
71
|
-
return
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
+
return (
|
|
84
|
+
hexlify(
|
|
85
|
+
concat(
|
|
86
|
+
ensNameSplit(name).map((comp) => {
|
|
87
|
+
// DNS does not allow components over 63 bytes in length
|
|
88
|
+
if (comp.length > 63) {
|
|
89
|
+
throw new Error(
|
|
90
|
+
"invalid DNS encoded entry; length exceeds 63 bytes",
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const bytes = new Uint8Array(comp.length + 1);
|
|
95
|
+
bytes.set(comp, 1);
|
|
96
|
+
bytes[0] = bytes.length - 1;
|
|
97
|
+
return bytes;
|
|
98
|
+
}),
|
|
99
|
+
),
|
|
100
|
+
) + "00"
|
|
101
|
+
);
|
|
83
102
|
}
|