Compare commits

..

40 Commits

Author SHA1 Message Date
semantic-release-bot 8b8e08a07f chore(release): 0.0.2-develop.1 [skip ci]
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/resolver-module-handshake/compare/v0.0.1...v0.0.2-develop.1) (2023-07-15)
2023-07-15 13:05:33 +00:00
Derrick Hammer c953bd7986
dep: update presetter-kernel-module-preset 2023-07-15 09:00:03 -04:00
Derrick Hammer e1f527d7da
style: add @ts-ignore 2023-07-15 08:57:31 -04:00
Derrick Hammer 80e6b4aa7b
ci: setup 2023-07-15 08:56:30 -04:00
Derrick Hammer 23714fba07
refactor: move to new sdks, and build system 2023-07-15 08:56:29 -04:00
Derrick Hammer addc693fb3
*update deps 2023-04-04 06:42:39 -04:00
Derrick Hammer 575b3198fb
*Update for new system design and use light client 2023-02-20 11:21:52 -05:00
Derrick Hammer 4a224bd8d6
*Update dist 2022-09-09 04:51:45 -04:00
Derrick Hammer 5a3e5ef399
*Pass correct child property 2022-09-09 04:51:28 -04:00
Derrick Hammer 122124c550
*Update dist 2022-08-30 22:26:18 -04:00
Derrick Hammer 33f5d36aca
*Properly handle RPC errors 2022-08-30 22:25:44 -04:00
Derrick Hammer 599a1a1e0b
*Update dist 2022-08-30 03:08:33 -04:00
Derrick Hammer 5e9092f351
*Update module name 2022-08-30 03:07:26 -04:00
Derrick Hammer a3465ab9f0
*Update dist 2022-08-29 01:05:35 -04:00
Derrick Hammer eb7d84cd40
*Add @lumeweb/relay-types 2022-08-29 01:05:27 -04:00
Derrick Hammer 5b82f0a8d8
*Use new rpc protocol 2022-08-29 01:04:08 -04:00
Derrick Hammer 6d60a68674
*Switch to libresolver
*Use ensureUniqueRecords
2022-08-29 01:03:00 -04:00
Derrick Hammer cef692b7ec
*Update dist 2022-08-23 14:35:08 -04:00
Derrick Hammer faad982f0f
*Properly handle recursive queries to the icann resolver 2022-08-23 14:34:44 -04:00
Derrick Hammer f86a05f2be
*Update dist 2022-08-23 14:24:59 -04:00
Derrick Hammer d8e5b94efe
*Pass the value not the record 2022-08-23 14:24:43 -04:00
Derrick Hammer bc190774c0
*Update dist 2022-08-20 12:09:45 -04:00
Derrick Hammer cab30a8c13
*Property handle follow ns/glue records for A lookup
*Handle NS record lookup
*Dedupe array elements using serialization and set
*Ensure options.options is an object for simplicity
2022-08-20 12:09:09 -04:00
Derrick Hammer f3379652a6
*Fix source file 2022-08-20 06:18:36 -04:00
Derrick Hammer 083df81534
*Merge in kernel module 2022-08-20 03:46:43 -04:00
Derrick Hammer 8df42b7202
*Update dist 2022-08-19 12:49:26 -04:00
Derrick Hammer 7e5b9e4b22
*add missing resolveSuccess 2022-08-19 12:49:09 -04:00
Derrick Hammer 5070b94728
*Update dist 2022-08-19 12:44:29 -04:00
Derrick Hammer 179b7831b2
*Abort processGlue is we are not looking for an A, CNAME, or NS record 2022-08-19 12:43:43 -04:00
Derrick Hammer c6ca4f81ca
*Update dist 2022-08-19 12:15:41 -04:00
Derrick Hammer 672916880d
*Ensure options.options exists 2022-08-19 12:15:31 -04:00
Derrick Hammer f1585ed6b3
*Update dist 2022-08-19 12:12:40 -04:00
Derrick Hammer 94f30df69a
*option.options may be not set 2022-08-19 12:12:26 -04:00
Derrick Hammer 43944cb5b5
*Update dist 2022-08-19 09:49:15 -04:00
Derrick Hammer 74f60ea59a
*Resolvers getter may be a promise 2022-08-19 09:49:02 -04:00
Derrick Hammer cc2a8668ab
*Update package.json 2022-08-19 08:46:29 -04:00
Derrick Hammer b19dcb14b0
*Add dist 2022-08-19 08:42:59 -04:00
Derrick Hammer 7584d974b5
*Update types and add HnsRecord interface 2022-08-19 08:38:53 -04:00
Derrick Hammer 12dfdb750c
*Re-implement blacklist 2022-08-18 20:11:22 -04:00
Derrick Hammer 8b57218172
*Initial version 2022-08-18 15:21:41 -04:00
7 changed files with 19950 additions and 0 deletions

13
.github/workflows/ci.yml vendored Normal file
View File

@ -0,0 +1,13 @@
name: Build/Publish
on:
push:
branches:
- master
- develop
- develop-*
jobs:
main:
uses: lumeweb/github-node-deploy-workflow/.github/workflows/main.yml@master
secrets: inherit

8
.presetterrc.json Normal file
View File

@ -0,0 +1,8 @@
{
"preset": [
"@lumeweb/presetter-kernel-module-preset"
],
"config": {
"official": true
}
}

1
CHANGELOG.md Normal file
View File

@ -0,0 +1 @@
## [0.0.2-develop.1](https://git.lumeweb.com/LumeWeb/resolver-module-handshake/compare/v0.0.1...v0.0.2-develop.1) (2023-07-15)

19603
npm-shrinkwrap.json generated Normal file

File diff suppressed because it is too large Load Diff

24
package.json Normal file
View File

@ -0,0 +1,24 @@
{
"name": "@lumeweb/resolver-module-handshake",
"version": "0.0.2-develop.1",
"main": "lib/index.js",
"type": "module",
"readme": "ERROR: No README data found!",
"repository": {
"type": "git",
"url": "gitea@git.lumeweb.com:LumeWeb/resolver-module-handshake.git"
},
"scripts": {
"prepare": "presetter bootstrap",
"build": "run build",
"semantic-release": "semantic-release"
},
"dependencies": {
"@lumeweb/kernel-handshake-client": "^0.0.2-develop.4",
"@lumeweb/kernel-libresolver": "^0.1.0-develop.3",
"@lumeweb/tld-enum": "^0.1.0-develop.1"
},
"devDependencies": {
"@lumeweb/presetter-kernel-module-preset": "^0.1.0-develop.43"
}
}

5
src/index.ts Normal file
View File

@ -0,0 +1,5 @@
import { setup } from "@lumeweb/kernel-libresolver";
import Handshake from "./resolver.js";
// @ts-ignore
setup(new Handshake());

296
src/resolver.ts Normal file
View File

@ -0,0 +1,296 @@
import tldEnum from "@lumeweb/tld-enum";
import {
AbstractResolverModule,
DNS_RECORD_TYPE,
DNSResult,
isDomain,
isIp,
isPromise,
normalizeDomain,
resolverEmptyResponse,
ResolverOptions,
resolveSuccess,
ensureUniqueRecords,
DNSRecord,
getTld,
resolverError,
} from "@lumeweb/libresolver";
import {
createClient,
Response as HandshakeResponse,
} from "@lumeweb/kernel-handshake-client";
import { ResolverModule } from "@lumeweb/kernel-dns-client";
const client = createClient();
const HIP5_EXTENSIONS = ["eth", "_eth"];
interface HnsRecord {
type: string;
address: string;
txt: string[];
ns: string;
}
export default class Handshake extends AbstractResolverModule {
private async buildBlacklist(): Promise<Set<string>> {
const blacklist = new Set<string>();
let resolvers = this.resolver.resolvers as unknown as Set<ResolverModule>;
if (isPromise(resolvers as any)) {
resolvers = await resolvers;
}
for (const resolver of resolvers) {
let tlds: string[] | Promise<string[]> = resolver.getSupportedTlds();
if (isPromise(tlds as any)) {
tlds = await tlds;
}
(tlds as string[]).map((item: string) => blacklist.add(item));
}
return blacklist;
}
async resolve(
domain: string,
options: ResolverOptions,
bypassCache: boolean,
): Promise<DNSResult> {
options.options = options.options || {};
const tld = getTld(domain);
const blacklist = await this.buildBlacklist();
if (blacklist.has(tld)) {
return resolverEmptyResponse();
}
if (isIp(domain)) {
return resolverEmptyResponse();
}
if (options?.options && "subquery" in options.options) {
return resolverEmptyResponse();
}
const chainRecords = await this.query(tld);
if (chainRecords.error) {
return resolverError(chainRecords.error);
}
if (!chainRecords.result?.records.length) {
return resolverEmptyResponse();
}
let records: DNSRecord[] = [];
for (const record of chainRecords.result?.records) {
switch (record.type) {
case "NS": {
await this.processNs(
domain,
record,
records,
chainRecords.result?.records,
options,
bypassCache,
);
break;
}
case "GLUE4": {
await this.processGlue(domain, record, records, options, bypassCache);
break;
}
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({
type: options.type,
value: record.address,
});
}
break;
}
case "SYNTH4": {
if (options.type === DNS_RECORD_TYPE.A) {
records.push({
type: options.type,
value: record.address,
});
}
break;
}
default: {
break;
}
}
}
records = ensureUniqueRecords(records);
if (0 < records.length) {
return resolveSuccess(records);
}
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> {
return client.query("getnameresource", [tld, true]);
}
private async processTxt(
record: HnsRecord,
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() {
await client.ready();
}
}