@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.
@@ -1,8 +1,8 @@
1
1
  import { concat, hexlify } from "@qevm/bytes";
2
2
  import { toUtf8Bytes, toUtf8String } from "@qevm/strings";
3
- import { keccak256 } from "@ethersproject/keccak256";
3
+ import { keccak256 } from "@qevm/keccak256";
4
4
 
5
- import { Logger } from "@ethersproject/logger";
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) { throw new Error("invalid ENS name; empty component"); }
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) { return comps; }
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) { throw new Error("invalid ENS name; empty component"); }
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).map((comp) => toUtf8String(comp)).join(".");
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 (ensNameSplit(name).length !== 0);
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(name) !== "string") {
57
- logger.throwArgumentError("invalid ENS name; not a string", "name", name);
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 hexlify(concat(ensNameSplit(name).map((comp) => {
72
- // DNS does not allow components over 63 bytes in length
73
- if (comp.length > 63) {
74
- throw new Error("invalid DNS encoded entry; length exceeds 63 bytes");
75
- }
76
-
77
- const bytes = new Uint8Array(comp.length + 1);
78
- bytes.set(comp, 1);
79
- bytes[0] = bytes.length - 1;
80
- return bytes;
81
-
82
- }))) + "00";
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
  }