Compare commits
4 Commits
v0.0.2-dev
...
v0.0.2-dev
Author | SHA1 | Date |
---|---|---|
semantic-release-bot | eaefadd473 | |
Derrick Hammer | dd629edd8c | |
Derrick Hammer | b6d0c362c6 | |
Derrick Hammer | 0ba86078d4 |
|
@ -1,3 +1,5 @@
|
||||||
|
## [0.0.2-develop.5](https://git.lumeweb.com/LumeWeb/resolver-module-handshake/compare/v0.0.2-develop.4...v0.0.2-develop.5) (2023-08-02)
|
||||||
|
|
||||||
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/resolver-module-handshake/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-29)
|
## [0.0.2-develop.4](https://git.lumeweb.com/LumeWeb/resolver-module-handshake/compare/v0.0.2-develop.3...v0.0.2-develop.4) (2023-07-29)
|
||||||
|
|
||||||
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/resolver-module-handshake/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-29)
|
## [0.0.2-develop.3](https://git.lumeweb.com/LumeWeb/resolver-module-handshake/compare/v0.0.2-develop.2...v0.0.2-develop.3) (2023-07-29)
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/resolver-module-handshake",
|
"name": "@lumeweb/resolver-module-handshake",
|
||||||
"version": "0.0.2-develop.4",
|
"version": "0.0.2-develop.5",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "@lumeweb/resolver-module-handshake",
|
"name": "@lumeweb/resolver-module-handshake",
|
||||||
"version": "0.0.2-develop.4",
|
"version": "0.0.2-develop.5",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/kernel-handshake-client": "0.0.2-develop.17",
|
"@lumeweb/kernel-handshake-client": "0.1.0-develop.2",
|
||||||
"@lumeweb/kernel-libresolver": "^0.1.0-develop.6",
|
"@lumeweb/kernel-libresolver": "^0.1.0-develop.6",
|
||||||
"@lumeweb/tld-enum": "^0.1.0-develop.1"
|
"@lumeweb/tld-enum": "^0.1.0-develop.1"
|
||||||
},
|
},
|
||||||
|
@ -1687,9 +1687,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@lumeweb/kernel-handshake-client": {
|
"node_modules/@lumeweb/kernel-handshake-client": {
|
||||||
"version": "0.0.2-develop.17",
|
"version": "0.1.0-develop.2",
|
||||||
"resolved": "https://registry.npmjs.org/@lumeweb/kernel-handshake-client/-/kernel-handshake-client-0.0.2-develop.17.tgz",
|
"resolved": "https://registry.npmjs.org/@lumeweb/kernel-handshake-client/-/kernel-handshake-client-0.1.0-develop.2.tgz",
|
||||||
"integrity": "sha512-6+LIfFKfl6kuInOmpNwsr7EoJJvZ0C6lPY3ANVqQkys1yc73LYyimPW6LPaNxQT9RQ8oVZZs/ku6cEgLVrsHwQ==",
|
"integrity": "sha512-N0i9CESdw3g6K7GRlPhX1HpkcBOFX/2hqVXXuT+ZCm36rNGgbfa2W7T0+saqLAcwxmrvwZhbaPrvFFpt3mIo0w==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/libkernel": "^0.1.0-develop.27"
|
"@lumeweb/libkernel": "^0.1.0-develop.27"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "@lumeweb/resolver-module-handshake",
|
"name": "@lumeweb/resolver-module-handshake",
|
||||||
"version": "0.0.2-develop.4",
|
"version": "0.0.2-develop.5",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"readme": "ERROR: No README data found!",
|
"readme": "ERROR: No README data found!",
|
||||||
|
@ -14,7 +14,7 @@
|
||||||
"semantic-release": "semantic-release"
|
"semantic-release": "semantic-release"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lumeweb/kernel-handshake-client": "0.0.2-develop.17",
|
"@lumeweb/kernel-handshake-client": "0.1.0-develop.2",
|
||||||
"@lumeweb/kernel-libresolver": "^0.1.0-develop.6",
|
"@lumeweb/kernel-libresolver": "^0.1.0-develop.6",
|
||||||
"@lumeweb/tld-enum": "^0.1.0-develop.1"
|
"@lumeweb/tld-enum": "^0.1.0-develop.1"
|
||||||
},
|
},
|
||||||
|
|
277
src/resolver.ts
277
src/resolver.ts
|
@ -69,10 +69,6 @@ export default class Handshake extends AbstractResolverModule {
|
||||||
return resolverEmptyResponse();
|
return resolverEmptyResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options?.options && "subquery" in options.options) {
|
|
||||||
return resolverEmptyResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
const chainRecords = await this.query(tld);
|
const chainRecords = await this.query(tld);
|
||||||
if (chainRecords.error) {
|
if (chainRecords.error) {
|
||||||
return resolverError(chainRecords.error);
|
return resolverError(chainRecords.error);
|
||||||
|
@ -84,51 +80,48 @@ export default class Handshake extends AbstractResolverModule {
|
||||||
|
|
||||||
let records: DNSRecord[] = [];
|
let records: DNSRecord[] = [];
|
||||||
|
|
||||||
for (const record of chainRecords.result?.records) {
|
const hnsRecords = chainRecords.result?.records;
|
||||||
switch (record.type) {
|
const nsServer = this.findNameserver(hnsRecords, options);
|
||||||
case "NS": {
|
|
||||||
await this.processNs(
|
if (!nsServer) {
|
||||||
|
const ns = this.findRecordsByType(hnsRecords, "NS");
|
||||||
|
|
||||||
|
if (ns && this.isNSHip5(ns[0], options)) {
|
||||||
|
let result = await this.resolver.resolve(
|
||||||
|
ns[0].ns,
|
||||||
|
{
|
||||||
|
...options,
|
||||||
|
options: {
|
||||||
domain,
|
domain,
|
||||||
record,
|
},
|
||||||
records,
|
},
|
||||||
chainRecords.result?.records,
|
|
||||||
options,
|
|
||||||
bypassCache,
|
bypassCache,
|
||||||
);
|
);
|
||||||
break;
|
|
||||||
|
if (result.records.length) {
|
||||||
|
records.push.apply(records, result.records);
|
||||||
}
|
}
|
||||||
case "GLUE4": {
|
} else {
|
||||||
await this.processGlue(domain, record, records, options, bypassCache);
|
const content = this.findRecordsByType(hnsRecords, "TXT");
|
||||||
break;
|
if (content && [DNS_RECORD_TYPE.CONTENT].includes(options.type)) {
|
||||||
}
|
content.forEach((record) =>
|
||||||
case "TXT": {
|
|
||||||
await this.processTxt(record, records, options);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "SYNTH6": {
|
|
||||||
if (
|
|
||||||
options.type === DNS_RECORD_TYPE.A &&
|
|
||||||
"ipv6" in options.options &&
|
|
||||||
options.options.ipv6
|
|
||||||
) {
|
|
||||||
records.push({
|
records.push({
|
||||||
type: options.type,
|
type: DNS_RECORD_TYPE.CONTENT,
|
||||||
value: record.address,
|
value: record.txt.slice().pop() as string,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (const type of [DNS_RECORD_TYPE.A, DNS_RECORD_TYPE.CNAME]) {
|
||||||
|
if (type === options.type) {
|
||||||
|
const ret = await this.dnsQuery(domain, type);
|
||||||
|
if (ret.length) {
|
||||||
|
records.push({
|
||||||
|
type,
|
||||||
|
value: ret.slice().shift().data.address,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
|
||||||
case "SYNTH4": {
|
|
||||||
if (options.type === DNS_RECORD_TYPE.A) {
|
|
||||||
records.push({
|
|
||||||
type: options.type,
|
|
||||||
value: record.address,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -142,155 +135,71 @@ export default class Handshake extends AbstractResolverModule {
|
||||||
return resolverEmptyResponse();
|
return resolverEmptyResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
// @ts-ignore
|
|
||||||
private async processNs(
|
|
||||||
domain: string,
|
|
||||||
record: HnsRecord,
|
|
||||||
records: DNSRecord[],
|
|
||||||
hnsRecords: HnsRecord[],
|
|
||||||
options: ResolverOptions,
|
|
||||||
bypassCache: boolean,
|
|
||||||
) {
|
|
||||||
if (
|
|
||||||
![DNS_RECORD_TYPE.A, DNS_RECORD_TYPE.CNAME, DNS_RECORD_TYPE.NS].includes(
|
|
||||||
options.type,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// @ts-ignore
|
|
||||||
const glue = hnsRecords.slice().find(
|
|
||||||
(item: object) =>
|
|
||||||
// @ts-ignore
|
|
||||||
["GLUE4", "GLUE6"].includes(item.type) && item.ns === record.ns,
|
|
||||||
);
|
|
||||||
|
|
||||||
if (glue && options.type !== DNS_RECORD_TYPE.NS) {
|
|
||||||
return this.processGlue(domain, glue, records, options, bypassCache);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (options.type === DNS_RECORD_TYPE.NS) {
|
|
||||||
records.push({ type: options.type, value: record.ns });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const foundDomain = normalizeDomain(record.ns);
|
|
||||||
|
|
||||||
let isIcann = false;
|
|
||||||
let isHip5 = false;
|
|
||||||
|
|
||||||
let hip5Parts = foundDomain.split(".");
|
|
||||||
|
|
||||||
if (
|
|
||||||
hip5Parts.length >= 2 &&
|
|
||||||
[...(options.options?.hip5 ?? []), ...HIP5_EXTENSIONS].includes(
|
|
||||||
hip5Parts[hip5Parts.length - 1],
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
isHip5 = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
(isDomain(foundDomain) || /[a-zA-Z0-9\-]+/.test(foundDomain)) &&
|
|
||||||
!isHip5
|
|
||||||
) {
|
|
||||||
if (foundDomain.includes(".")) {
|
|
||||||
const tld = foundDomain.split(".")[foundDomain.split(".").length - 1];
|
|
||||||
|
|
||||||
isIcann = tldEnum.list.includes(tld);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isIcann) {
|
|
||||||
const hnsNs = await this.resolver.resolve(foundDomain, options);
|
|
||||||
|
|
||||||
if (hnsNs.records.length) {
|
|
||||||
let icannRecords = await this.resolver.resolve(domain, {
|
|
||||||
...options,
|
|
||||||
options: {
|
|
||||||
subquery: true,
|
|
||||||
nameserver: hnsNs.records.pop()?.value,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
if (icannRecords.records.length) {
|
|
||||||
records.push.apply(records, icannRecords.records);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolverEmptyResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
let icannRecords = await this.resolver.resolve(domain, {
|
|
||||||
...options,
|
|
||||||
options: { subquery: true, nameserver: foundDomain },
|
|
||||||
});
|
|
||||||
if (icannRecords.records.length) {
|
|
||||||
records.push.apply(records, icannRecords.records);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return resolverEmptyResponse();
|
|
||||||
}
|
|
||||||
|
|
||||||
let result = await this.resolver.resolve(record.ns, options, bypassCache);
|
|
||||||
|
|
||||||
if (!result.records.length) {
|
|
||||||
result.records.push({ type: DNS_RECORD_TYPE.NS, value: record.ns });
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
records.push.apply(records, result.records);
|
|
||||||
}
|
|
||||||
|
|
||||||
private async processGlue(
|
|
||||||
domain: string,
|
|
||||||
record: HnsRecord,
|
|
||||||
records: DNSRecord[],
|
|
||||||
options: ResolverOptions,
|
|
||||||
bypassCache: boolean,
|
|
||||||
) {
|
|
||||||
if (![DNS_RECORD_TYPE.A, DNS_RECORD_TYPE.CNAME].includes(options.type)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (isDomain(record.ns) && isIp(record.address)) {
|
|
||||||
let results = await this.resolver.resolve(
|
|
||||||
domain,
|
|
||||||
{
|
|
||||||
...options,
|
|
||||||
options: {
|
|
||||||
subquery: true,
|
|
||||||
nameserver: record.address,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
bypassCache,
|
|
||||||
);
|
|
||||||
if (results.records.length) {
|
|
||||||
records.push.apply(records, results.records);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private async query(tld: string): Promise<HandshakeResponse> {
|
private async query(tld: string): Promise<HandshakeResponse> {
|
||||||
return client.query("getnameresource", [tld, true]);
|
return client.query("getnameresource", [tld, true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private async processTxt(
|
private async dnsQuery(domain: string, type: string): Promise<any> {
|
||||||
record: HnsRecord,
|
return client.dnsQuery(domain, type);
|
||||||
records: DNSRecord[],
|
|
||||||
options: ResolverOptions,
|
|
||||||
) {
|
|
||||||
const content = record.txt.slice().pop() as string;
|
|
||||||
|
|
||||||
if (
|
|
||||||
[DNS_RECORD_TYPE.TEXT, DNS_RECORD_TYPE.CONTENT].includes(options.type)
|
|
||||||
) {
|
|
||||||
records.push({
|
|
||||||
type: DNS_RECORD_TYPE.TEXT,
|
|
||||||
value: content,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async ready() {
|
async ready() {
|
||||||
return ((await client.status()) as any)?.ready;
|
return ((await client.status()) as any)?.ready;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private findNameserver(
|
||||||
|
records: HnsRecord[],
|
||||||
|
options: ResolverOptions,
|
||||||
|
): HnsRecord | false {
|
||||||
|
const synth4 = this.findRecordsByType(records, "SYNTH4");
|
||||||
|
const synth6 = this.findRecordsByType(records, "SYNTH6");
|
||||||
|
const synth = synth4 || synth6;
|
||||||
|
const glue4 = this.findRecordsByType(records, "GLUE4");
|
||||||
|
const glue6 = this.findRecordsByType(records, "GLUE6");
|
||||||
|
const glue = glue4 || glue6;
|
||||||
|
|
||||||
|
const ns = this.findRecordsByType(records, "NS");
|
||||||
|
|
||||||
|
if (synth) {
|
||||||
|
return synth[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (glue) {
|
||||||
|
return glue[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ns) {
|
||||||
|
if (!this.isNSHip5(ns[0], options)) {
|
||||||
|
return ns[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private findRecordsByType(
|
||||||
|
records: HnsRecord[],
|
||||||
|
type: "NS" | "SYNTH4" | "SYNTH6" | "GLUE4" | "GLUE6" | "TXT",
|
||||||
|
) {
|
||||||
|
const ret = records.filter((item) => item.type === type);
|
||||||
|
|
||||||
|
if (!ret.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
private isNSHip5(record: HnsRecord, options: ResolverOptions) {
|
||||||
|
const foundDomain = normalizeDomain(record.ns);
|
||||||
|
|
||||||
|
let hip5Parts = foundDomain.split(".");
|
||||||
|
|
||||||
|
return (
|
||||||
|
hip5Parts.length >= 2 &&
|
||||||
|
[...(options.options?.hip5 ?? []), ...HIP5_EXTENSIONS].includes(
|
||||||
|
hip5Parts[hip5Parts.length - 1],
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue