UNPKG

8.05 kBTypeScriptView Raw
1/// <reference types="node" />
2
3/**
4 * The currently defined set of DNS record types.
5 */
6export 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
51export type RecordClass = "IN" | "CS" | "CH" | "HS" | "ANY";
52
53export interface Question {
54 type: RecordType;
55 name: string;
56 class?: RecordClass | undefined;
57}
58
59export interface CaaData {
60 issuerCritical?: boolean | undefined;
61 flags?: number | undefined;
62 tag: "issue" | "issuewild" | "iodef";
63 value: string;
64}
65
66export interface DnskeyData {
67 flags: number;
68 algorithm: number;
69 key: Buffer;
70}
71
72export interface DsData {
73 keyTag: number;
74 algorithm: number;
75 digestType: number;
76 digest: Buffer;
77}
78
79export interface HInfoData {
80 cpu: string;
81 os: string;
82}
83
84export interface MxData {
85 preference?: number | undefined;
86 exchange: string;
87}
88
89export interface NaptrData {
90 order: number;
91 preference: number;
92 flags: string;
93 services: string;
94 regexp: string;
95 replacement: string;
96}
97export interface NsecData {
98 nextDomain: string;
99 rrtypes: string[];
100}
101
102export interface Nsec3Data {
103 algorithm: number;
104 flags: number;
105 iterations: number;
106 salt: Buffer;
107 nextDomain: Buffer;
108 rrtypes: string[];
109}
110
111export interface RpData {
112 mbox: string;
113 txt: string;
114}
115
116export 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
128export interface SrvData {
129 port: number;
130 target: string;
131 priority?: number | undefined;
132 weight?: number | undefined;
133}
134
135export 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
145export interface SshfpData {
146 algorithm: number;
147 hash: number;
148 fingerprint: string;
149}
150
151export interface TlsaData {
152 usage: number;
153 selector: number;
154 matchingType: number;
155 certificate: Buffer;
156}
157
158export type TxtData = string | Buffer | Array<string | Buffer>;
159
160export interface GenericAnswer<T> {
161 type: T;
162 name: string;
163}
164
165export 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 * Record types for which the library will provide a string in the data field.
174 */
175export type StringRecordType = "A" | "AAAA" | "CNAME" | "DNAME" | "NS" | "PTR";
176
177/**
178 * Record types for which the library does not attempt to process the data
179 * field.
180 */
181export 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
204export type StringAnswer = BaseAnswer<StringRecordType, string>;
205export type BufferAnswer = BaseAnswer<OtherRecordType, Buffer>;
206export type CaaAnswer = BaseAnswer<"CAA", CaaData>;
207export type DnskeyAnswer = BaseAnswer<"DNSKEY", DnskeyData>;
208export type DSAnswer = BaseAnswer<"DS", DsData>;
209export type HInfoAnswer = BaseAnswer<"HINFO", HInfoData>;
210export type MxAnswer = BaseAnswer<"MX", MxData>;
211export type NaptrAnswer = BaseAnswer<"NAPTR", NaptrData>;
212export type Nsec3Answer = BaseAnswer<"NSEC3", Nsec3Data>;
213export type NsecAnswer = BaseAnswer<"NSEC", NsecData>;
214export type RpAnswer = BaseAnswer<"RP", RpData>;
215export type RrsigAnswer = BaseAnswer<"RRSIG", RrsigData>;
216export type SoaAnswer = BaseAnswer<"SOA", SoaData>;
217export type SrvAnswer = BaseAnswer<"SRV", SrvData>;
218export type SshfpAnswer = BaseAnswer<"SSHFP", SshfpData>;
219export type TlsaAnswer = BaseAnswer<"TLSA", TlsaData>;
220export type TxtAnswer = BaseAnswer<"TXT", TxtData>;
221
222interface 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
242type OptCodeType = keyof OptCodes;
243type OptCode<K extends OptCodeType> = OptCodes[K];
244
245interface GenericOpt<T extends OptCodeType> {
246 code: OptCode<T>;
247 type?: T | undefined;
248 data?: Buffer | undefined;
249}
250
251interface ClientSubnetOpt extends GenericOpt<"CLIENT_SUBNET"> {
252 family?: number | undefined;
253 sourcePrefixLength?: number | undefined;
254 scopePrefixLength?: number | undefined;
255 ip: string | undefined;
256}
257
258interface KeepAliveOpt extends GenericOpt<"TCP_KEEPALIVE"> {
259 timeout?: number | undefined;
260}
261
262interface PaddingOpt extends GenericOpt<"PADDING"> {
263 length?: number | undefined;
264}
265
266interface TagOpt extends GenericOpt<"KEY_TAG"> {
267 tags: number[];
268}
269
270export type PacketOpt = ClientSubnetOpt | KeepAliveOpt | PaddingOpt | TagOpt;
271
272export interface OptAnswer extends GenericAnswer<"OPT"> {
273 udpPayloadSize: number;
274 extendedRcode: number;
275 ednsVersion: number;
276 flags: number;
277
278 /**
279 * Whether or not the DNS DO bit is set
280 */
281 flag_do: boolean;
282
283 options: PacketOpt[];
284}
285
286export 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
306export interface Packet {
307 /**
308 * Whether the packet is a query or a response. This field may be
309 * omitted if it is clear from the context of usage what type of packet
310 * it is.
311 */
312 type?: "query" | "response" | undefined;
313
314 id?: number | undefined;
315
316 /**
317 * A bit-mask combination of zero or more of:
318 * {@link AUTHORITATIVE_ANSWER},
319 * {@link TRUNCATED_RESPONSE},
320 * {@link RECURSION_DESIRED},
321 * {@link RECURSION_AVAILABLE},
322 * {@link AUTHENTIC_DATA},
323 * {@link CHECKING_DISABLED}.
324 */
325 flags?: number | undefined;
326 questions?: Question[] | undefined;
327 answers?: Answer[] | undefined;
328 additionals?: Answer[] | undefined;
329 authorities?: Answer[] | undefined;
330}
331
332// https://github.com/mafintosh/dns-packet/blob/7b6662025c49c0e31d2f0c5cbd726e4423805639/index.js#L181-L197
333export 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
344export const AUTHORITATIVE_ANSWER: number;
345export const TRUNCATED_RESPONSE: number;
346export const RECURSION_DESIRED: number;
347export const RECURSION_AVAILABLE: number;
348export const AUTHENTIC_DATA: number;
349export const CHECKING_DISABLED: number;
350export const DNSSEC_OK: number;
351
352export function encode(package: Packet, buf?: Buffer, offset?: number): Buffer;
353export namespace encode {
354 let bytes: number;
355}
356export function decode(buf: Buffer, offset?: number): DecodedPacket;
357export namespace decode {
358 let bytes: number;
359}
360export function encodingLength(packet: Packet): number;
361export function streamEncode(package: Packet): Buffer;
362export namespace streamEncode {
363 let bytes: number;
364}
365export function streamDecode(package: Buffer): Packet;
366export namespace streamDecode {
367 let bytes: number;
368}
369
370export {};