@waku/discovery 0.0.7-ebd7523.0 → 0.0.7
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/CHANGELOG.md +25 -0
- package/bundle/index.js +2294 -8232
- package/dist/.tsbuildinfo +1 -1
- package/dist/dns/dns_over_https.d.ts +2 -8
- package/dist/dns/dns_over_https.js +8 -22
- package/dist/dns/dns_over_https.js.map +1 -1
- package/package.json +93 -1
- package/src/dns/dns_over_https.ts +6 -31
@@ -1,7 +1,7 @@
|
|
1
1
|
import type { DnsClient } from "@waku/interfaces";
|
2
2
|
import { Logger } from "@waku/utils";
|
3
3
|
import { bytesToUtf8 } from "@waku/utils/bytes";
|
4
|
-
import
|
4
|
+
import DnsOverHttpResolver from "dns-over-http-resolver";
|
5
5
|
|
6
6
|
const log = new Logger("dns-over-https");
|
7
7
|
|
@@ -9,25 +9,13 @@ export class DnsOverHttps implements DnsClient {
|
|
9
9
|
/**
|
10
10
|
* Create new Dns-Over-Http DNS client.
|
11
11
|
*
|
12
|
-
* @param endpoints The endpoints for Dns-Over-Https queries;
|
13
|
-
* Defaults to using dns-query's API..
|
14
|
-
* @param retries Retries if a given endpoint fails.
|
15
|
-
*
|
16
12
|
* @throws {code: string} If DNS query fails.
|
17
13
|
*/
|
18
|
-
public static async create(
|
19
|
-
|
20
|
-
retries?: number
|
21
|
-
): Promise<DnsOverHttps> {
|
22
|
-
const _endpoints = endpoints ?? (await wellknown.endpoints("doh"));
|
23
|
-
|
24
|
-
return new DnsOverHttps(_endpoints, retries);
|
14
|
+
public static async create(): Promise<DnsOverHttps> {
|
15
|
+
return new DnsOverHttps();
|
25
16
|
}
|
26
17
|
|
27
|
-
private constructor(
|
28
|
-
private endpoints: Endpoint[],
|
29
|
-
private retries: number = 3
|
30
|
-
) {}
|
18
|
+
private constructor(private resolver = new DnsOverHttpResolver()) {}
|
31
19
|
|
32
20
|
/**
|
33
21
|
* Resolves a TXT record
|
@@ -39,16 +27,7 @@ export class DnsOverHttps implements DnsClient {
|
|
39
27
|
public async resolveTXT(domain: string): Promise<string[]> {
|
40
28
|
let answers;
|
41
29
|
try {
|
42
|
-
|
43
|
-
{
|
44
|
-
question: { type: "TXT", name: domain }
|
45
|
-
},
|
46
|
-
{
|
47
|
-
endpoints: this.endpoints,
|
48
|
-
retries: this.retries
|
49
|
-
}
|
50
|
-
);
|
51
|
-
answers = res.answers;
|
30
|
+
answers = await this.resolver.resolveTxt(domain);
|
52
31
|
} catch (error) {
|
53
32
|
log.error("query failed: ", error);
|
54
33
|
throw new Error("DNS query failed");
|
@@ -56,13 +35,9 @@ export class DnsOverHttps implements DnsClient {
|
|
56
35
|
|
57
36
|
if (!answers) throw new Error(`Could not resolve ${domain}`);
|
58
37
|
|
59
|
-
const data = answers.map((a) => a.data) as
|
60
|
-
| Array<string | Uint8Array>
|
61
|
-
| Array<Array<string | Uint8Array>>;
|
62
|
-
|
63
38
|
const result: string[] = [];
|
64
39
|
|
65
|
-
|
40
|
+
answers.forEach((d) => {
|
66
41
|
if (typeof d === "string") {
|
67
42
|
result.push(d);
|
68
43
|
} else if (Array.isArray(d)) {
|