Skip to content

Commit

Permalink
Revert "semi-fix types for dns-packet"
Browse files Browse the repository at this point in the history
This reverts commit 02a7f2a.
  • Loading branch information
LeonmanRolls committed Jul 8, 2022
1 parent bea0d2f commit c623ca4
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"publish:local:ensjs": "yalc publish packages/ensjs --push --up"
},
"devDependencies": {
"@types/dns-packet": "^5.2.4",
"@typescript-eslint/eslint-plugin": "^5.15.0",
"@typescript-eslint/parser": "^5.15.0",
"eslint": "^8.11.0",
Expand Down
1 change: 1 addition & 0 deletions packages/ensjs/src/@types/dns-packet.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
declare module 'dns-packet'
114 changes: 114 additions & 0 deletions packages/ensjs/src/@types/dns-packet/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
declare module 'dns-packet' {
const AUTHORITATIVE_ANSWER: number
const TRUNCATED_RESPONSE: number
const RECURSION_DESIRED: number
const RECURSION_AVAILABLE: number
const AUTHENTIC_DATA: number
const CHECKING_DISABLED: number
const DNSSEC_OK: number

interface decoder<T> {
(buf: Buffer, offset?: number): T
bytes: number;
}

const decode: decoder<Packet>;

interface encoder<T> {
(packet: T, buf?: Buffer, offset?: number): Buffer
bytes: number;
}

const encode: encoder<Packet>;

interface Packet {
id?: number
type: 'query' | 'response'
flags?: number
rcode?: string
questions: Question[]
answers?: Answer[]
authorities?: Answer[]
additionals?: Answer[]
}

interface Question {
type: string
class: string
name: string
}

interface AnswerBase {
type: string
class: string
name: string
ttl?: number
}

interface A extends AnswerBase {
type: 'A'
data: string
}

interface Dnskey extends AnswerBase {
type: 'DNSKEY'
data: {
flags: number
algorithm: number
key: Buffer
}
}

interface Ds extends AnswerBase {
type: 'DS'
data: {
keyTag: number
algorithm: number
digestType: number
digest: Buffer
}
}

interface Opt extends AnswerBase {
type: 'OPT'
udpPayloadSize?: number
extendedRcode?: number
ednsVersion?: number
flags?: number
data?: any
}

interface Rrsig extends AnswerBase {
type: 'RRSIG'
data: {
typeCovered: string
algorithm: number
labels: number
originalTTL: number
expiration: number
inception: number
keyTag: number
signersName: string
signature: Buffer
}
}

interface Rtxt extends AnswerBase {
type: 'TXT'
data: Buffer[]
}

type Answer = A|Dnskey|Ds|Opt|Rrsig|Rtxt

interface Encodable<T> {
decode: decoder<T>
encode: encoder<T>
}

const record: (type: string) => Encodable<Answer>
const answer: Encodable<Answer>
const dnskey: Encodable<Dnskey['data']>
const name: Encodable<string>
const rrsig: Encodable<Rrsig['data']>
}

1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4656,6 +4656,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "ensjs-monorepo@workspace:."
dependencies:
"@types/dns-packet": ^5.2.4
"@typescript-eslint/eslint-plugin": ^5.15.0
"@typescript-eslint/parser": ^5.15.0
eslint: ^8.11.0
Expand Down

0 comments on commit c623ca4

Please sign in to comment.