mirror of https://github.com/waku-org/js-waku.git
Merge pull request #841 from status-im/doh-resolver
This commit is contained in:
commit
3217b28063
|
@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
the latter does not bring Buffer/Long deps, is ESM compatible and remove the need for bufbuild and protoc.
|
||||
- Move package to `"type": "module"`.
|
||||
- Use ESM code in Mocha and Karma tests.
|
||||
- Upgrade `dns-query` dependency, breaking change on `DnsNodeDiscovery` API.
|
||||
|
||||
## [0.24.0] - 2022-05-27
|
||||
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
"@ethersproject/rlp": "^5.5.0",
|
||||
"@noble/secp256k1": "^1.3.4",
|
||||
"debug": "^4.3.1",
|
||||
"dns-query": "^0.8.0",
|
||||
"dns-query": "^0.11.1",
|
||||
"hi-base32": "^0.5.1",
|
||||
"it-concat": "^2.0.0",
|
||||
"it-length-prefixed": "^5.0.2",
|
||||
|
@ -1090,10 +1090,42 @@
|
|||
"node": ">=8"
|
||||
}
|
||||
},
|
||||
"node_modules/@leichtgewicht/base64-codec": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/base64-codec/-/base64-codec-1.0.0.tgz",
|
||||
"integrity": "sha512-0cgP4lRBzh3F4tlpTfs7F+PJyBN8j5yUC9KrQFWp/bREswgzZVHE8T1rNyRDWgvALwwpPtnJDQfqWUmxI33Epg=="
|
||||
},
|
||||
"node_modules/@leichtgewicht/dns-packet": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/dns-packet/-/dns-packet-6.0.3.tgz",
|
||||
"integrity": "sha512-qmVHhFBFiBvPsk/wJ/EdoWHb+tGkzY4haybmDPukhF6w0+8wpEbrHTIRE9LzeUu2P0bAbmrK8WOXt5V5QN6jQg==",
|
||||
"dependencies": {
|
||||
"@leichtgewicht/ip-codec": "^2.0.4",
|
||||
"bytes.js": "^0.0.2",
|
||||
"utf8-bytes": "^0.0.1",
|
||||
"utf8-codec": "^1.0.0",
|
||||
"utf8-length": "^0.0.1",
|
||||
"utf8-string-bytes": "^1.0.3"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/@leichtgewicht/dns-socket": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/dns-socket/-/dns-socket-5.0.0.tgz",
|
||||
"integrity": "sha512-Sbrn/OG0HTTPGSkwIDCHy8/tUI6UglIzFsMNjzZn/Na1/i5owSm6rVi9CfKNNjRcUlYEzICELYW6EoZdjwVY2A==",
|
||||
"dependencies": {
|
||||
"@leichtgewicht/dns-packet": "^6.0.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/@leichtgewicht/ip-codec": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.3.tgz",
|
||||
"integrity": "sha512-nkalE/f1RvRGChwBnEIoBfSEYOXnCRdleKuv6+lePbMDrMZXeDQnqak5XDOeBgrPPyPfAdcCu/B5z+v3VhplGg=="
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz",
|
||||
"integrity": "sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A=="
|
||||
},
|
||||
"node_modules/@noble/ed25519": {
|
||||
"version": "1.5.1",
|
||||
|
@ -1573,14 +1605,6 @@
|
|||
"@types/ms": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/dns-packet": {
|
||||
"version": "5.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/dns-packet/-/dns-packet-5.2.4.tgz",
|
||||
"integrity": "sha512-OAruArypdNxR/tzbmrtoyEuXeNTLaZCpO19BXaNC10T5ACIbvjmvhmV2RDEy2eLc3w8IjK7SY3cvUCcAW+sfoQ==",
|
||||
"dependencies": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/eslint": {
|
||||
"version": "8.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.1.tgz",
|
||||
|
@ -2929,6 +2953,11 @@
|
|||
"node": ">= 0.8"
|
||||
}
|
||||
},
|
||||
"node_modules/bytes.js": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bytes.js/-/bytes.js-0.0.2.tgz",
|
||||
"integrity": "sha512-KrLm4hv5Qs9w6b0U7h1bCdqxrsf+e9QMsfHeyQFzAz94x/5Aqa+FTEUSNBtt5d2VuV3Hfiea3c4ti74RZDDYkg=="
|
||||
},
|
||||
"node_modules/caching-transform": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-4.0.0.tgz",
|
||||
|
@ -4031,42 +4060,21 @@
|
|||
"receptacle": "^1.3.2"
|
||||
}
|
||||
},
|
||||
"node_modules/dns-packet": {
|
||||
"version": "5.3.1",
|
||||
"resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-5.3.1.tgz",
|
||||
"integrity": "sha512-spBwIj0TK0Ey3666GwIdWVfUpLyubpU53BTCu8iPn4r4oXd9O14Hjg3EHw3ts2oed77/SeckunUYCyRlSngqHw==",
|
||||
"dependencies": {
|
||||
"@leichtgewicht/ip-codec": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/dns-query": {
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/dns-query/-/dns-query-0.8.0.tgz",
|
||||
"integrity": "sha512-Gx3jYhdj9oLMZFieinpwpTFK0c2Q+teV53Se1+l4AbcWLPMUCBACu7qcj0IqTWwnpasWl8Gwgxeqw2RjoCwIoA==",
|
||||
"version": "0.11.1",
|
||||
"resolved": "https://registry.npmjs.org/dns-query/-/dns-query-0.11.1.tgz",
|
||||
"integrity": "sha512-ZdXl7HdLa23JqpAj8EdUg/oO9qwlDvWf2iY/cFCTHF6deJWv/xglgs3WrvTz9/Ig3NGv5lF4FIZjURl2FUvFog==",
|
||||
"dependencies": {
|
||||
"@leichtgewicht/ip-codec": "^2.0.2",
|
||||
"@types/dns-packet": "^5.2.0",
|
||||
"dns-packet": "^5.3.0",
|
||||
"dns-socket": "^4.2.2"
|
||||
"@leichtgewicht/base64-codec": "^1.0.0",
|
||||
"@leichtgewicht/dns-packet": "^6.0.2",
|
||||
"@leichtgewicht/dns-socket": "^5.0.0",
|
||||
"@leichtgewicht/ip-codec": "^2.0.4",
|
||||
"utf8-codec": "^1.0.0"
|
||||
},
|
||||
"bin": {
|
||||
"dns-query": "bin/dns-query"
|
||||
}
|
||||
},
|
||||
"node_modules/dns-socket": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/dns-socket/-/dns-socket-4.2.2.tgz",
|
||||
"integrity": "sha512-BDeBd8najI4/lS00HSKpdFia+OvUMytaVjfzR9n5Lq8MlZRSvtbI+uLtx1+XmQFls5wFU9dssccTmQQ6nfpjdg==",
|
||||
"dependencies": {
|
||||
"dns-packet": "^5.2.4"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
}
|
||||
},
|
||||
"node_modules/doctrine": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/doctrine/-/doctrine-3.0.0.tgz",
|
||||
|
@ -11843,6 +11851,26 @@
|
|||
"resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz",
|
||||
"integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E="
|
||||
},
|
||||
"node_modules/utf8-bytes": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/utf8-bytes/-/utf8-bytes-0.0.1.tgz",
|
||||
"integrity": "sha512-GifWmJAx2qAXT+lZLhbkWhBsy7pr6xWHiPWlVToDiELdWgZwt4Ogjf9tlgvKuALzTFR/d+EPQQI9ogJV3957Jg=="
|
||||
},
|
||||
"node_modules/utf8-codec": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/utf8-codec/-/utf8-codec-1.0.0.tgz",
|
||||
"integrity": "sha512-S/QSLezp3qvG4ld5PUfXiH7mCFxLKjSVZRFkB3DOjgwHuJPFDkInAXc/anf7BAbHt/D38ozDzL+QMZ6/7gsI6w=="
|
||||
},
|
||||
"node_modules/utf8-length": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/utf8-length/-/utf8-length-0.0.1.tgz",
|
||||
"integrity": "sha512-j/XH2ftofBiobnyApxlN/J6j/ixwT89WEjDcjT66d2i0+GIn9RZfzt8lpEXXE4jUe4NsjBSUq70kS2euQ4nnMw=="
|
||||
},
|
||||
"node_modules/utf8-string-bytes": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/utf8-string-bytes/-/utf8-string-bytes-1.0.3.tgz",
|
||||
"integrity": "sha512-i/I1Omf6lADjVBlwJpQifZOePV15snHny9w04+lc71+3t8PyWuLC/7clyoOSHOBNGXFe2PAGxmTiZ+Z4HWsPyw=="
|
||||
},
|
||||
"node_modules/util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
|
@ -13291,10 +13319,36 @@
|
|||
"integrity": "sha512-ZXRY4jNvVgSVQ8DL3LTcakaAtXwTVUxE81hslsyD2AtoXW/wVob10HkOJ1X/pAlcI7D+2YoZKg5do8G/w6RYgA==",
|
||||
"dev": true
|
||||
},
|
||||
"@leichtgewicht/base64-codec": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/base64-codec/-/base64-codec-1.0.0.tgz",
|
||||
"integrity": "sha512-0cgP4lRBzh3F4tlpTfs7F+PJyBN8j5yUC9KrQFWp/bREswgzZVHE8T1rNyRDWgvALwwpPtnJDQfqWUmxI33Epg=="
|
||||
},
|
||||
"@leichtgewicht/dns-packet": {
|
||||
"version": "6.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/dns-packet/-/dns-packet-6.0.3.tgz",
|
||||
"integrity": "sha512-qmVHhFBFiBvPsk/wJ/EdoWHb+tGkzY4haybmDPukhF6w0+8wpEbrHTIRE9LzeUu2P0bAbmrK8WOXt5V5QN6jQg==",
|
||||
"requires": {
|
||||
"@leichtgewicht/ip-codec": "^2.0.4",
|
||||
"bytes.js": "^0.0.2",
|
||||
"utf8-bytes": "^0.0.1",
|
||||
"utf8-codec": "^1.0.0",
|
||||
"utf8-length": "^0.0.1",
|
||||
"utf8-string-bytes": "^1.0.3"
|
||||
}
|
||||
},
|
||||
"@leichtgewicht/dns-socket": {
|
||||
"version": "5.0.0",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/dns-socket/-/dns-socket-5.0.0.tgz",
|
||||
"integrity": "sha512-Sbrn/OG0HTTPGSkwIDCHy8/tUI6UglIzFsMNjzZn/Na1/i5owSm6rVi9CfKNNjRcUlYEzICELYW6EoZdjwVY2A==",
|
||||
"requires": {
|
||||
"@leichtgewicht/dns-packet": "^6.0.0"
|
||||
}
|
||||
},
|
||||
"@leichtgewicht/ip-codec": {
|
||||
"version": "2.0.3",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.3.tgz",
|
||||
"integrity": "sha512-nkalE/f1RvRGChwBnEIoBfSEYOXnCRdleKuv6+lePbMDrMZXeDQnqak5XDOeBgrPPyPfAdcCu/B5z+v3VhplGg=="
|
||||
"version": "2.0.4",
|
||||
"resolved": "https://registry.npmjs.org/@leichtgewicht/ip-codec/-/ip-codec-2.0.4.tgz",
|
||||
"integrity": "sha512-Hcv+nVC0kZnQ3tD9GVu5xSMR4VVYOteQIr/hwFPVEvPdlXqgGEuRjiheChHgdM+JyqdgNcmzZOX/tnl0JOiI7A=="
|
||||
},
|
||||
"@noble/ed25519": {
|
||||
"version": "1.5.1",
|
||||
|
@ -13714,14 +13768,6 @@
|
|||
"@types/ms": "*"
|
||||
}
|
||||
},
|
||||
"@types/dns-packet": {
|
||||
"version": "5.2.4",
|
||||
"resolved": "https://registry.npmjs.org/@types/dns-packet/-/dns-packet-5.2.4.tgz",
|
||||
"integrity": "sha512-OAruArypdNxR/tzbmrtoyEuXeNTLaZCpO19BXaNC10T5ACIbvjmvhmV2RDEy2eLc3w8IjK7SY3cvUCcAW+sfoQ==",
|
||||
"requires": {
|
||||
"@types/node": "*"
|
||||
}
|
||||
},
|
||||
"@types/eslint": {
|
||||
"version": "8.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@types/eslint/-/eslint-8.4.1.tgz",
|
||||
|
@ -14733,6 +14779,11 @@
|
|||
"integrity": "sha512-fey6+4jDK7TFtFg/klGSvNKJctyU7n2aQdnM+CO0ruLPbqqMOM8Tio0Pc+deqUeVKX1tL5DQep1zQ7+37aTAsA==",
|
||||
"dev": true
|
||||
},
|
||||
"bytes.js": {
|
||||
"version": "0.0.2",
|
||||
"resolved": "https://registry.npmjs.org/bytes.js/-/bytes.js-0.0.2.tgz",
|
||||
"integrity": "sha512-KrLm4hv5Qs9w6b0U7h1bCdqxrsf+e9QMsfHeyQFzAz94x/5Aqa+FTEUSNBtt5d2VuV3Hfiea3c4ti74RZDDYkg=="
|
||||
},
|
||||
"caching-transform": {
|
||||
"version": "4.0.0",
|
||||
"resolved": "https://registry.npmjs.org/caching-transform/-/caching-transform-4.0.0.tgz",
|
||||
|
@ -15578,31 +15629,16 @@
|
|||
"receptacle": "^1.3.2"
|
||||
}
|
||||
},
|
||||
"dns-packet": {
|
||||
"version": "5.3.1",
|
||||
"resolved": "https://registry.npmjs.org/dns-packet/-/dns-packet-5.3.1.tgz",
|
||||
"integrity": "sha512-spBwIj0TK0Ey3666GwIdWVfUpLyubpU53BTCu8iPn4r4oXd9O14Hjg3EHw3ts2oed77/SeckunUYCyRlSngqHw==",
|
||||
"requires": {
|
||||
"@leichtgewicht/ip-codec": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"dns-query": {
|
||||
"version": "0.8.0",
|
||||
"resolved": "https://registry.npmjs.org/dns-query/-/dns-query-0.8.0.tgz",
|
||||
"integrity": "sha512-Gx3jYhdj9oLMZFieinpwpTFK0c2Q+teV53Se1+l4AbcWLPMUCBACu7qcj0IqTWwnpasWl8Gwgxeqw2RjoCwIoA==",
|
||||
"version": "0.11.1",
|
||||
"resolved": "https://registry.npmjs.org/dns-query/-/dns-query-0.11.1.tgz",
|
||||
"integrity": "sha512-ZdXl7HdLa23JqpAj8EdUg/oO9qwlDvWf2iY/cFCTHF6deJWv/xglgs3WrvTz9/Ig3NGv5lF4FIZjURl2FUvFog==",
|
||||
"requires": {
|
||||
"@leichtgewicht/ip-codec": "^2.0.2",
|
||||
"@types/dns-packet": "^5.2.0",
|
||||
"dns-packet": "^5.3.0",
|
||||
"dns-socket": "^4.2.2"
|
||||
}
|
||||
},
|
||||
"dns-socket": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/dns-socket/-/dns-socket-4.2.2.tgz",
|
||||
"integrity": "sha512-BDeBd8najI4/lS00HSKpdFia+OvUMytaVjfzR9n5Lq8MlZRSvtbI+uLtx1+XmQFls5wFU9dssccTmQQ6nfpjdg==",
|
||||
"requires": {
|
||||
"dns-packet": "^5.2.4"
|
||||
"@leichtgewicht/base64-codec": "^1.0.0",
|
||||
"@leichtgewicht/dns-packet": "^6.0.2",
|
||||
"@leichtgewicht/dns-socket": "^5.0.0",
|
||||
"@leichtgewicht/ip-codec": "^2.0.4",
|
||||
"utf8-codec": "^1.0.0"
|
||||
}
|
||||
},
|
||||
"doctrine": {
|
||||
|
@ -21475,6 +21511,26 @@
|
|||
"resolved": "https://registry.npmjs.org/utf8-byte-length/-/utf8-byte-length-1.0.4.tgz",
|
||||
"integrity": "sha1-9F8VDExm7uloGGUFq5P8u4rWv2E="
|
||||
},
|
||||
"utf8-bytes": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/utf8-bytes/-/utf8-bytes-0.0.1.tgz",
|
||||
"integrity": "sha512-GifWmJAx2qAXT+lZLhbkWhBsy7pr6xWHiPWlVToDiELdWgZwt4Ogjf9tlgvKuALzTFR/d+EPQQI9ogJV3957Jg=="
|
||||
},
|
||||
"utf8-codec": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/utf8-codec/-/utf8-codec-1.0.0.tgz",
|
||||
"integrity": "sha512-S/QSLezp3qvG4ld5PUfXiH7mCFxLKjSVZRFkB3DOjgwHuJPFDkInAXc/anf7BAbHt/D38ozDzL+QMZ6/7gsI6w=="
|
||||
},
|
||||
"utf8-length": {
|
||||
"version": "0.0.1",
|
||||
"resolved": "https://registry.npmjs.org/utf8-length/-/utf8-length-0.0.1.tgz",
|
||||
"integrity": "sha512-j/XH2ftofBiobnyApxlN/J6j/ixwT89WEjDcjT66d2i0+GIn9RZfzt8lpEXXE4jUe4NsjBSUq70kS2euQ4nnMw=="
|
||||
},
|
||||
"utf8-string-bytes": {
|
||||
"version": "1.0.3",
|
||||
"resolved": "https://registry.npmjs.org/utf8-string-bytes/-/utf8-string-bytes-1.0.3.tgz",
|
||||
"integrity": "sha512-i/I1Omf6lADjVBlwJpQifZOePV15snHny9w04+lc71+3t8PyWuLC/7clyoOSHOBNGXFe2PAGxmTiZ+Z4HWsPyw=="
|
||||
},
|
||||
"util-deprecate": {
|
||||
"version": "1.0.2",
|
||||
"resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
"@ethersproject/rlp": "^5.5.0",
|
||||
"@noble/secp256k1": "^1.3.4",
|
||||
"debug": "^4.3.1",
|
||||
"dns-query": "^0.8.0",
|
||||
"dns-query": "^0.11.1",
|
||||
"hi-base32": "^0.5.1",
|
||||
"it-concat": "^2.0.0",
|
||||
"it-length-prefixed": "^5.0.2",
|
||||
|
|
|
@ -2,7 +2,7 @@ import debug from "debug";
|
|||
|
||||
import { ENR } from "../enr";
|
||||
|
||||
import { DnsOverHttps, Endpoints } from "./dns_over_https";
|
||||
import { DnsOverHttps } from "./dns_over_https";
|
||||
import { ENRTree } from "./enrtree";
|
||||
import fetchNodesUntilCapabilitiesFulfilled from "./fetch_nodes";
|
||||
|
||||
|
@ -30,8 +30,10 @@ export class DnsNodeDiscovery {
|
|||
private readonly _DNSTreeCache: { [key: string]: string };
|
||||
private readonly _errorTolerance: number = 10;
|
||||
|
||||
public static dnsOverHttp(endpoints?: Endpoints): DnsNodeDiscovery {
|
||||
const dnsClient = new DnsOverHttps(endpoints);
|
||||
public static dnsOverHttp(dnsClient?: DnsClient): DnsNodeDiscovery {
|
||||
if (!dnsClient) {
|
||||
dnsClient = new DnsOverHttps();
|
||||
}
|
||||
return new DnsNodeDiscovery(dnsClient);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,34 +1,47 @@
|
|||
import { TxtAnswer } from "dns-packet";
|
||||
import {
|
||||
endpoints as defaultEndpoints,
|
||||
Endpoint,
|
||||
EndpointProps,
|
||||
query,
|
||||
} from "dns-query";
|
||||
import debug from "debug";
|
||||
import { Endpoint, query, toEndpoint } from "dns-query";
|
||||
|
||||
import { bytesToUtf8 } from "../utils";
|
||||
|
||||
import { DnsClient } from "./dns";
|
||||
|
||||
const { cloudflare, google, opendns } = defaultEndpoints;
|
||||
|
||||
export type Endpoints =
|
||||
| "doh"
|
||||
| "dns"
|
||||
| Iterable<Endpoint | EndpointProps | string>;
|
||||
const log = debug("waku:dns-over-https");
|
||||
|
||||
export class DnsOverHttps implements DnsClient {
|
||||
/**
|
||||
* Default endpoints to use for DNS queries.
|
||||
* Taken from https://github.com/martinheidegger/dns-query as static data
|
||||
* to avoid dynamic queries.
|
||||
*
|
||||
* To dynamically retrieve other endpoints, use https://github.com/martinheidegger/dns-query#well-known-endpoints
|
||||
*/
|
||||
static DefaultEndpoints: Endpoint[] = [
|
||||
toEndpoint({
|
||||
name: "cisco-doh",
|
||||
protocol: "https:",
|
||||
host: "doh.opendns.com",
|
||||
ipv4: "146.112.41.2",
|
||||
}),
|
||||
toEndpoint({
|
||||
name: "cloudflare",
|
||||
protocol: "https:",
|
||||
host: "dns.cloudflare.com",
|
||||
ipv4: "1.0.0.1",
|
||||
}),
|
||||
];
|
||||
|
||||
/**
|
||||
* Create new Dns-Over-Http DNS client.
|
||||
*
|
||||
* @param endpoints The endpoints for Dns-Over-Https queries.
|
||||
* See [dns-query](https://www.npmjs.com/package/dns-query) for details.
|
||||
* Defaults to cloudflare, google and opendns.
|
||||
* @param endpoints The endpoints for Dns-Over-Https queries;
|
||||
* Defaults to [[DnsOverHttps.DefaultEndpoints]].
|
||||
* @param retries Retries if a given endpoint fails.
|
||||
*
|
||||
* @throws {code: string} If DNS query fails.
|
||||
*/
|
||||
public constructor(
|
||||
public endpoints: Endpoints = [cloudflare, google, opendns]
|
||||
private endpoints: Endpoint[] = DnsOverHttps.DefaultEndpoints,
|
||||
private retries: number = 3
|
||||
) {}
|
||||
|
||||
/**
|
||||
|
@ -36,17 +49,31 @@ export class DnsOverHttps implements DnsClient {
|
|||
*
|
||||
* @param domain The domain name
|
||||
*
|
||||
* @throws if the result is provided in byte form which cannot be decoded
|
||||
* to UTF-8
|
||||
* @throws if the query fails
|
||||
*/
|
||||
async resolveTXT(domain: string): Promise<string[]> {
|
||||
const response = await query({
|
||||
questions: [{ type: "TXT", name: domain }],
|
||||
});
|
||||
let answers;
|
||||
try {
|
||||
const res = await query(
|
||||
{
|
||||
question: { type: "TXT", name: domain },
|
||||
},
|
||||
{
|
||||
endpoints: this.endpoints,
|
||||
retries: this.retries,
|
||||
}
|
||||
);
|
||||
answers = res.answers;
|
||||
} catch (error) {
|
||||
log("query failed: ", error);
|
||||
throw new Error("DNS query failed");
|
||||
}
|
||||
|
||||
const answers = response.answers as TxtAnswer[];
|
||||
if (!answers) throw new Error(`Could not resolve ${domain}`);
|
||||
|
||||
const data = answers.map((a) => a.data);
|
||||
const data = answers.map((a) => a.data) as
|
||||
| Array<string | Uint8Array>
|
||||
| Array<Array<string | Uint8Array>>;
|
||||
|
||||
const result: string[] = [];
|
||||
|
||||
|
|
|
@ -2,5 +2,5 @@ export { getPredefinedBootstrapNodes } from "./predefined";
|
|||
export * as predefined from "./predefined";
|
||||
export { Bootstrap, BootstrapOptions } from "./bootstrap";
|
||||
export * as dns from "./dns";
|
||||
export { Endpoints, DnsOverHttps } from "./dns_over_https";
|
||||
export { DnsOverHttps } from "./dns_over_https";
|
||||
export { ENRTree, ENRTreeValues, ENRRootValues } from "./enrtree";
|
||||
|
|
Loading…
Reference in New Issue