*Update types and add HnsRecord interface

This commit is contained in:
Derrick Hammer 2022-08-19 08:38:53 -04:00
parent 12dfdb750c
commit 7584d974b5
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 16 additions and 9 deletions

View File

@ -16,10 +16,17 @@ import { DNSRecord } from "@lumeweb/resolver-common";
const HIP5_EXTENSIONS = ["eth", "_eth"]; const HIP5_EXTENSIONS = ["eth", "_eth"];
interface HnsRecord {
type: string;
address: string;
txt: string[];
ns: string;
}
export default class Handshake extends AbstractResolverModule { export default class Handshake extends AbstractResolverModule {
private async buildBlacklist(): Promise<Set<string>> { private async buildBlacklist(): Promise<Set<string>> {
const blacklist = new Set<string>(); const blacklist = new Set<string>();
for (const resolver: ResolverModule of this.resolver.resolvers) { for (const resolver of this.resolver.resolvers) {
let tlds = resolver.getSupportedTlds(); let tlds = resolver.getSupportedTlds();
if (isPromise(tlds as any)) { if (isPromise(tlds as any)) {
tlds = await tlds; tlds = await tlds;
@ -58,7 +65,7 @@ export default class Handshake extends AbstractResolverModule {
let records: DNSRecord[] = []; let records: DNSRecord[] = [];
for (const record of chainRecords) { for (const record of chainRecords as HnsRecord[]) {
switch (record.type) { switch (record.type) {
case "NS": { case "NS": {
await this.processNs(domain, record, records, options, bypassCache); await this.processNs(domain, record, records, options, bypassCache);
@ -106,8 +113,8 @@ export default class Handshake extends AbstractResolverModule {
// @ts-ignore // @ts-ignore
private async processNs( private async processNs(
domain: string, domain: string,
record, record: HnsRecord,
records, records: DNSRecord[],
options: ResolverOptions, options: ResolverOptions,
bypassCache: boolean bypassCache: boolean
) { ) {
@ -187,7 +194,7 @@ export default class Handshake extends AbstractResolverModule {
private async processGlue( private async processGlue(
domain: string, domain: string,
record: any, record: HnsRecord,
records: DNSRecord[], records: DNSRecord[],
options: ResolverOptions, options: ResolverOptions,
bypassCache: boolean bypassCache: boolean
@ -210,7 +217,7 @@ export default class Handshake extends AbstractResolverModule {
} }
} }
private async query(tld: string, force: boolean): Promise<object | boolean> { private async query(tld: string, force: boolean): Promise<[] | boolean> {
const query = this.resolver.rpcNetwork.query( const query = this.resolver.rpcNetwork.query(
"getnameresource", "getnameresource",
"hns", "hns",
@ -224,11 +231,11 @@ export default class Handshake extends AbstractResolverModule {
} }
private async processTxt( private async processTxt(
record: any, record: HnsRecord,
records: DNSRecord[], records: DNSRecord[],
options: ResolverOptions options: ResolverOptions
): Promise<string | boolean> { ) {
const content = record.txt.slice().pop(); const content = record.txt.slice().pop() as string;
if ( if (
[DNS_RECORD_TYPE.TEXT, DNS_RECORD_TYPE.CONTENT].includes(options.type) [DNS_RECORD_TYPE.TEXT, DNS_RECORD_TYPE.CONTENT].includes(options.type)