1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | export type RecordType =
|
7 | | "A"
|
8 | | "AAAA"
|
9 | | "AFSDB"
|
10 | | "APL"
|
11 | | "AXFR"
|
12 | | "CAA"
|
13 | | "CDNSKEY"
|
14 | | "CDS"
|
15 | | "CERT"
|
16 | | "CNAME"
|
17 | | "DNAME"
|
18 | | "DHCID"
|
19 | | "DLV"
|
20 | | "DNSKEY"
|
21 | | "DS"
|
22 | | "HINFO"
|
23 | | "HIP"
|
24 | | "IXFR"
|
25 | | "IPSECKEY"
|
26 | | "KEY"
|
27 | | "KX"
|
28 | | "LOC"
|
29 | | "MX"
|
30 | | "NAPTR"
|
31 | | "NS"
|
32 | | "NSEC"
|
33 | | "NSEC3"
|
34 | | "NSEC3PARAM"
|
35 | | "NULL"
|
36 | | "OPT"
|
37 | | "PTR"
|
38 | | "RRSIG"
|
39 | | "RP"
|
40 | | "SIG"
|
41 | | "SOA"
|
42 | | "SRV"
|
43 | | "SSHFP"
|
44 | | "TA"
|
45 | | "TKEY"
|
46 | | "TLSA"
|
47 | | "TSIG"
|
48 | | "TXT"
|
49 | | "URI";
|
50 |
|
51 | export type RecordClass = "IN" | "CS" | "CH" | "HS" | "ANY";
|
52 |
|
53 | export interface Question {
|
54 | type: RecordType;
|
55 | name: string;
|
56 | class?: RecordClass | undefined;
|
57 | }
|
58 |
|
59 | export interface CaaData {
|
60 | issuerCritical?: boolean | undefined;
|
61 | flags?: number | undefined;
|
62 | tag: "issue" | "issuewild" | "iodef";
|
63 | value: string;
|
64 | }
|
65 |
|
66 | export interface DnskeyData {
|
67 | flags: number;
|
68 | algorithm: number;
|
69 | key: Buffer;
|
70 | }
|
71 |
|
72 | export interface DsData {
|
73 | keyTag: number;
|
74 | algorithm: number;
|
75 | digestType: number;
|
76 | digest: Buffer;
|
77 | }
|
78 |
|
79 | export interface HInfoData {
|
80 | cpu: string;
|
81 | os: string;
|
82 | }
|
83 |
|
84 | export interface MxData {
|
85 | preference?: number | undefined;
|
86 | exchange: string;
|
87 | }
|
88 |
|
89 | export interface NaptrData {
|
90 | order: number;
|
91 | preference: number;
|
92 | flags: string;
|
93 | services: string;
|
94 | regexp: string;
|
95 | replacement: string;
|
96 | }
|
97 | export interface NsecData {
|
98 | nextDomain: string;
|
99 | rrtypes: string[];
|
100 | }
|
101 |
|
102 | export interface Nsec3Data {
|
103 | algorithm: number;
|
104 | flags: number;
|
105 | iterations: number;
|
106 | salt: Buffer;
|
107 | nextDomain: Buffer;
|
108 | rrtypes: string[];
|
109 | }
|
110 |
|
111 | export interface RpData {
|
112 | mbox: string;
|
113 | txt: string;
|
114 | }
|
115 |
|
116 | export interface RrsigData {
|
117 | typeCovered: string;
|
118 | algorithm: number;
|
119 | labels: number;
|
120 | originalTTL: number;
|
121 | expiration: number;
|
122 | inception: number;
|
123 | keyTag: number;
|
124 | signersName: string;
|
125 | signature: Buffer;
|
126 | }
|
127 |
|
128 | export interface SrvData {
|
129 | port: number;
|
130 | target: string;
|
131 | priority?: number | undefined;
|
132 | weight?: number | undefined;
|
133 | }
|
134 |
|
135 | export interface SoaData {
|
136 | mname: string;
|
137 | rname: string;
|
138 | serial?: number | undefined;
|
139 | refresh?: number | undefined;
|
140 | retry?: number | undefined;
|
141 | expire?: number | undefined;
|
142 | minimum?: number | undefined;
|
143 | }
|
144 |
|
145 | export interface SshfpData {
|
146 | algorithm: number;
|
147 | hash: number;
|
148 | fingerprint: string;
|
149 | }
|
150 |
|
151 | export interface TlsaData {
|
152 | usage: number;
|
153 | selector: number;
|
154 | matchingType: number;
|
155 | certificate: Buffer;
|
156 | }
|
157 |
|
158 | export type TxtData = string | Buffer | Array<string | Buffer>;
|
159 |
|
160 | export interface GenericAnswer<T> {
|
161 | type: T;
|
162 | name: string;
|
163 | }
|
164 |
|
165 | export interface BaseAnswer<T, D> extends GenericAnswer<T> {
|
166 | ttl?: number | undefined;
|
167 | class?: RecordClass | undefined;
|
168 | flush?: boolean | undefined;
|
169 | data: D;
|
170 | }
|
171 |
|
172 |
|
173 |
|
174 |
|
175 | export type StringRecordType = "A" | "AAAA" | "CNAME" | "DNAME" | "NS" | "PTR";
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 | export type OtherRecordType =
|
182 | | "AFSDB"
|
183 | | "APL"
|
184 | | "AXFR"
|
185 | | "CDNSKEY"
|
186 | | "CDS"
|
187 | | "CERT"
|
188 | | "DHCID"
|
189 | | "DLV"
|
190 | | "HIP"
|
191 | | "IPSECKEY"
|
192 | | "IXFR"
|
193 | | "KEY"
|
194 | | "KX"
|
195 | | "LOC"
|
196 | | "NSEC3PARAM"
|
197 | | "NULL"
|
198 | | "SIG"
|
199 | | "TA"
|
200 | | "TKEY"
|
201 | | "TSIG"
|
202 | | "URI";
|
203 |
|
204 | export type StringAnswer = BaseAnswer<StringRecordType, string>;
|
205 | export type BufferAnswer = BaseAnswer<OtherRecordType, Buffer>;
|
206 | export type CaaAnswer = BaseAnswer<"CAA", CaaData>;
|
207 | export type DnskeyAnswer = BaseAnswer<"DNSKEY", DnskeyData>;
|
208 | export type DSAnswer = BaseAnswer<"DS", DsData>;
|
209 | export type HInfoAnswer = BaseAnswer<"HINFO", HInfoData>;
|
210 | export type MxAnswer = BaseAnswer<"MX", MxData>;
|
211 | export type NaptrAnswer = BaseAnswer<"NAPTR", NaptrData>;
|
212 | export type Nsec3Answer = BaseAnswer<"NSEC3", Nsec3Data>;
|
213 | export type NsecAnswer = BaseAnswer<"NSEC", NsecData>;
|
214 | export type RpAnswer = BaseAnswer<"RP", RpData>;
|
215 | export type RrsigAnswer = BaseAnswer<"RRSIG", RrsigData>;
|
216 | export type SoaAnswer = BaseAnswer<"SOA", SoaData>;
|
217 | export type SrvAnswer = BaseAnswer<"SRV", SrvData>;
|
218 | export type SshfpAnswer = BaseAnswer<"SSHFP", SshfpData>;
|
219 | export type TlsaAnswer = BaseAnswer<"TLSA", TlsaData>;
|
220 | export type TxtAnswer = BaseAnswer<"TXT", TxtData>;
|
221 |
|
222 | interface OptCodes {
|
223 | OPTION_0: 0;
|
224 | LLQ: 1;
|
225 | UL: 2;
|
226 | NSID: 3;
|
227 | OPTION_4: 4;
|
228 | DAU: 5;
|
229 | DHU: 6;
|
230 | N3U: 7;
|
231 | CLIENT_SUBNET: 8;
|
232 | EXPIRE: 9;
|
233 | COOKIE: 10;
|
234 | TCP_KEEPALIVE: 11;
|
235 | PADDING: 12;
|
236 | CHAIN: 13;
|
237 | KEY_TAG: 14;
|
238 | DEVICEID: 26946;
|
239 | OPTION_65535: 65535;
|
240 | }
|
241 |
|
242 | type OptCodeType = keyof OptCodes;
|
243 | type OptCode<K extends OptCodeType> = OptCodes[K];
|
244 |
|
245 | interface GenericOpt<T extends OptCodeType> {
|
246 | code: OptCode<T>;
|
247 | type?: T | undefined;
|
248 | data?: Buffer | undefined;
|
249 | }
|
250 |
|
251 | interface ClientSubnetOpt extends GenericOpt<"CLIENT_SUBNET"> {
|
252 | family?: number | undefined;
|
253 | sourcePrefixLength?: number | undefined;
|
254 | scopePrefixLength?: number | undefined;
|
255 | ip: string | undefined;
|
256 | }
|
257 |
|
258 | interface KeepAliveOpt extends GenericOpt<"TCP_KEEPALIVE"> {
|
259 | timeout?: number | undefined;
|
260 | }
|
261 |
|
262 | interface PaddingOpt extends GenericOpt<"PADDING"> {
|
263 | length?: number | undefined;
|
264 | }
|
265 |
|
266 | interface TagOpt extends GenericOpt<"KEY_TAG"> {
|
267 | tags: number[];
|
268 | }
|
269 |
|
270 | export type PacketOpt = ClientSubnetOpt | KeepAliveOpt | PaddingOpt | TagOpt;
|
271 |
|
272 | export interface OptAnswer extends GenericAnswer<"OPT"> {
|
273 | udpPayloadSize: number;
|
274 | extendedRcode: number;
|
275 | ednsVersion: number;
|
276 | flags: number;
|
277 |
|
278 | |
279 |
|
280 |
|
281 | flag_do: boolean;
|
282 |
|
283 | options: PacketOpt[];
|
284 | }
|
285 |
|
286 | export type Answer =
|
287 | | StringAnswer
|
288 | | BufferAnswer
|
289 | | CaaAnswer
|
290 | | DnskeyAnswer
|
291 | | DSAnswer
|
292 | | HInfoAnswer
|
293 | | MxAnswer
|
294 | | NaptrAnswer
|
295 | | Nsec3Answer
|
296 | | NsecAnswer
|
297 | | OptAnswer
|
298 | | RpAnswer
|
299 | | RrsigAnswer
|
300 | | SoaAnswer
|
301 | | SrvAnswer
|
302 | | SshfpAnswer
|
303 | | TlsaAnswer
|
304 | | TxtAnswer;
|
305 |
|
306 | export interface Packet {
|
307 | |
308 |
|
309 |
|
310 |
|
311 |
|
312 | type?: "query" | "response" | undefined;
|
313 |
|
314 | id?: number | undefined;
|
315 |
|
316 | |
317 |
|
318 |
|
319 |
|
320 |
|
321 |
|
322 |
|
323 |
|
324 |
|
325 | flags?: number | undefined;
|
326 | questions?: Question[] | undefined;
|
327 | answers?: Answer[] | undefined;
|
328 | additionals?: Answer[] | undefined;
|
329 | authorities?: Answer[] | undefined;
|
330 | }
|
331 |
|
332 |
|
333 | export interface DecodedPacket extends Packet {
|
334 | flag_qr: boolean;
|
335 | flag_aa: boolean;
|
336 | flag_tc: boolean;
|
337 | flag_rd: boolean;
|
338 | flag_ra: boolean;
|
339 | flag_z: boolean;
|
340 | flag_ad: boolean;
|
341 | flag_cd: boolean;
|
342 | }
|
343 |
|
344 | export const AUTHORITATIVE_ANSWER: number;
|
345 | export const TRUNCATED_RESPONSE: number;
|
346 | export const RECURSION_DESIRED: number;
|
347 | export const RECURSION_AVAILABLE: number;
|
348 | export const AUTHENTIC_DATA: number;
|
349 | export const CHECKING_DISABLED: number;
|
350 | export const DNSSEC_OK: number;
|
351 |
|
352 | export function encode(package: Packet, buf?: Buffer, offset?: number): Buffer;
|
353 | export namespace encode {
|
354 | let bytes: number;
|
355 | }
|
356 | export function decode(buf: Buffer, offset?: number): DecodedPacket;
|
357 | export namespace decode {
|
358 | let bytes: number;
|
359 | }
|
360 | export function encodingLength(packet: Packet): number;
|
361 | export function streamEncode(package: Packet): Buffer;
|
362 | export namespace streamEncode {
|
363 | let bytes: number;
|
364 | }
|
365 | export function streamDecode(package: Buffer): Packet;
|
366 | export namespace streamDecode {
|
367 | let bytes: number;
|
368 | }
|
369 |
|
370 | export {};
|