UNPKG

dohjs

Version:

DNS over HTTPS lookups from web apps

8 lines 131 kB
!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{("undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this).doh=e()}}((function(){return function e(t,r,n){function o(s,a){if(!r[s]){if(!t[s]){var u="function"==typeof require&&require;if(!a&&u)return u(s,!0);if(i)return i(s,!0);var c=new Error("Cannot find module '"+s+"'");throw c.code="MODULE_NOT_FOUND",c}var f=r[s]={exports:{}};t[s][0].call(f.exports,(function(e){return o(t[s][1][e]||e)}),f,f.exports,e,t,r,n)}return r[s].exports}for(var i="function"==typeof require&&require,s=0;s<n.length;s++)o(n[s]);return o}({1:[function(e,t,r){(function(r){(function(){const n=e("dns-packet"),o=e("https"),i=e("http"),s=e("base32-encode");var a=e("url").URL;"undefined"!=typeof window&&(a=window.URL);const u=["GET","POST"];class c extends Error{constructor(e="",...t){super(),this.name="MethodNotAllowedError",this.message=e}}function f(e){return-1!==u.indexOf(e)}function l(e,t="A"){return{type:"query",id:0,flags:n.RECURSION_DESIRED,questions:[{type:t,name:e}]}}function h(e,t,s,u,c){return new Promise((f,l)=>{const h=t.startsWith("https://")?o:i,d=n.encode(e);let p,g,y;if(u||(u={Accept:"application/dns-message","User-Agent":"dohjs/0.2.0"}),"POST"===s)Object.assign(u,{"Content-Type":"application/dns-message","Content-Length":d.length});else if("GET"===s){const e=d.toString("base64").toString("utf-8").replace(/=/g,"");t=`${t}?dns=${e}`}t=new a(t),p={method:s,hostname:t.hostname,port:t.port||443,path:t.pathname+t.search,headers:u};const b=h.request(p,e=>{e.on("data",e=>{g=g?r.concat([g,e]):e}),e.on("end",()=>{y&&clearTimeout(y);try{const e=n.decode(g);f(e)}catch(e){l(e)}})});b.on("error",e=>(b.destroy(),l(e))),c&&(y=setTimeout(()=>(b.destroy(),l(new Error(`Query timed out after ${c} milliseconds of inactivity`))),c)),"POST"===s&&b.write(d),b.end()})}const d={sendDohMsg:h,DohResolver:class{constructor(e){this.nameserver_url=e}query(e,t="A",r="POST",n=null,o=null){return new Promise((i,s)=>{if(!f(r))return s(new c(`Request method ${r} not allowed. Must be either 'GET' or 'POST'`));h(l(e,t),this.nameserver_url,r,n,o).then(i).catch(s)})}},makeQuery:l,MethodNotAllowedError:c,isMethodAllowed:f,prettify:function(e){for(const t of(e.answers||[]).concat(e.authorities||[]))if(t.hasOwnProperty("data"))switch(t.type){case"TXT":t.data=t.data.toString("utf8");break;case"DNSKEY":t.data.key=t.data.key.toString("base64").replace("=","");break;case"DS":t.data.digest=t.data.digest.toString("hex");break;case"NSEC3":t.data.salt=t.data.salt.toString("hex"),t.data.nextDomain=s(t.data.nextDomain,"RFC4648-HEX").replace("=","");break;case"RRSIG":t.data.signature=t.data.signature.toString("base64").replace("=","")}for(const t of e.additionals||[])if("OPT"===t.type)for(const e of t.options)switch(e.code){case 12:e.length=e.data.length,e.data=e.data.toString("hex").substring(0,80),80===e.data.length&&(e.data+="...")}return e},dnsPacket:n};t.exports=d}).call(this)}).call(this,e("buffer").Buffer)},{"base32-encode":2,buffer:5,"dns-packet":8,http:25,https:14,url:45}],2:[function(e,t,r){t.exports=function(e,t,r){var n,o;switch(r=r||{},t){case"RFC3548":case"RFC4648":n="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",o=!0;break;case"RFC4648-HEX":n="0123456789ABCDEFGHIJKLMNOPQRSTUV",o=!0;break;case"Crockford":n="0123456789ABCDEFGHJKMNPQRSTVWXYZ",o=!1;break;default:throw new Error("Unknown base32 variant: "+t)}for(var i=void 0!==r.padding?r.padding:o,s=e.byteLength,a=new Uint8Array(e),u=0,c=0,f="",l=0;l<s;l++)for(c=c<<8|a[l],u+=8;u>=5;)f+=n[c>>>u-5&31],u-=5;if(u>0&&(f+=n[c<<5-u&31]),i)for(;f.length%8!=0;)f+="=";return f}},{}],3:[function(e,t,r){"use strict";r.byteLength=function(e){var t=c(e),r=t[0],n=t[1];return 3*(r+n)/4-n},r.toByteArray=function(e){var t,r,n=c(e),s=n[0],a=n[1],u=new i(function(e,t,r){return 3*(t+r)/4-r}(0,s,a)),f=0,l=a>0?s-4:s;for(r=0;r<l;r+=4)t=o[e.charCodeAt(r)]<<18|o[e.charCodeAt(r+1)]<<12|o[e.charCodeAt(r+2)]<<6|o[e.charCodeAt(r+3)],u[f++]=t>>16&255,u[f++]=t>>8&255,u[f++]=255&t;2===a&&(t=o[e.charCodeAt(r)]<<2|o[e.charCodeAt(r+1)]>>4,u[f++]=255&t);1===a&&(t=o[e.charCodeAt(r)]<<10|o[e.charCodeAt(r+1)]<<4|o[e.charCodeAt(r+2)]>>2,u[f++]=t>>8&255,u[f++]=255&t);return u},r.fromByteArray=function(e){for(var t,r=e.length,o=r%3,i=[],s=0,a=r-o;s<a;s+=16383)i.push(f(e,s,s+16383>a?a:s+16383));1===o?(t=e[r-1],i.push(n[t>>2]+n[t<<4&63]+"==")):2===o&&(t=(e[r-2]<<8)+e[r-1],i.push(n[t>>10]+n[t>>4&63]+n[t<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,s="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a=0,u=s.length;a<u;++a)n[a]=s[a],o[s.charCodeAt(a)]=a;function c(e){var t=e.length;if(t%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=e.indexOf("=");return-1===r&&(r=t),[r,r===t?0:4-r%4]}function f(e,t,r){for(var o,i,s=[],a=t;a<r;a+=3)o=(e[a]<<16&16711680)+(e[a+1]<<8&65280)+(255&e[a+2]),s.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return s.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},{}],4:[function(e,t,r){},{}],5:[function(e,t,r){(function(t){(function(){ /*! * The buffer module from node.js, for the browser. * * @author Feross Aboukhadijeh <https://feross.org> * @license MIT */ "use strict";var t=e("base64-js"),n=e("ieee754");r.Buffer=i,r.SlowBuffer=function(e){+e!=e&&(e=0);return i.alloc(+e)},r.INSPECT_MAX_BYTES=50;function o(e){if(e>2147483647)throw new RangeError('The value "'+e+'" is invalid for option "size"');var t=new Uint8Array(e);return t.__proto__=i.prototype,t}function i(e,t,r){if("number"==typeof e){if("string"==typeof t)throw new TypeError('The "string" argument must be of type string. Received type number');return u(e)}return s(e,t,r)}function s(e,t,r){if("string"==typeof e)return function(e,t){"string"==typeof t&&""!==t||(t="utf8");if(!i.isEncoding(t))throw new TypeError("Unknown encoding: "+t);var r=0|l(e,t),n=o(r),s=n.write(e,t);s!==r&&(n=n.slice(0,s));return n}(e,t);if(ArrayBuffer.isView(e))return c(e);if(null==e)throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e);if(D(e,ArrayBuffer)||e&&D(e.buffer,ArrayBuffer))return function(e,t,r){if(t<0||e.byteLength<t)throw new RangeError('"offset" is outside of buffer bounds');if(e.byteLength<t+(r||0))throw new RangeError('"length" is outside of buffer bounds');var n;n=void 0===t&&void 0===r?new Uint8Array(e):void 0===r?new Uint8Array(e,t):new Uint8Array(e,t,r);return n.__proto__=i.prototype,n}(e,t,r);if("number"==typeof e)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=e.valueOf&&e.valueOf();if(null!=n&&n!==e)return i.from(n,t,r);var s=function(e){if(i.isBuffer(e)){var t=0|f(e.length),r=o(t);return 0===r.length||e.copy(r,0,0,t),r}if(void 0!==e.length)return"number"!=typeof e.length||j(e.length)?o(0):c(e);if("Buffer"===e.type&&Array.isArray(e.data))return c(e.data)}(e);if(s)return s;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof e[Symbol.toPrimitive])return i.from(e[Symbol.toPrimitive]("string"),t,r);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof e)}function a(e){if("number"!=typeof e)throw new TypeError('"size" argument must be of type number');if(e<0)throw new RangeError('The value "'+e+'" is invalid for option "size"')}function u(e){return a(e),o(e<0?0:0|f(e))}function c(e){for(var t=e.length<0?0:0|f(e.length),r=o(t),n=0;n<t;n+=1)r[n]=255&e[n];return r}function f(e){if(e>=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+2147483647..toString(16)+" bytes");return 0|e}function l(e,t){if(i.isBuffer(e))return e.length;if(ArrayBuffer.isView(e)||D(e,ArrayBuffer))return e.byteLength;if("string"!=typeof e)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof e);var r=e.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===r)return 0;for(var o=!1;;)switch(t){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":return P(e).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return k(e).length;default:if(o)return n?-1:P(e).length;t=(""+t).toLowerCase(),o=!0}}function h(e,t,r){var n=!1;if((void 0===t||t<0)&&(t=0),t>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(t>>>=0))return"";for(e||(e="utf8");;)switch(e){case"hex":return I(this,t,r);case"utf8":case"utf-8":return S(this,t,r);case"ascii":return R(this,t,r);case"latin1":case"binary":return T(this,t,r);case"base64":return _(this,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,r);default:if(n)throw new TypeError("Unknown encoding: "+e);e=(e+"").toLowerCase(),n=!0}}function d(e,t,r){var n=e[t];e[t]=e[r],e[r]=n}function p(e,t,r,n,o){if(0===e.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),j(r=+r)&&(r=o?0:e.length-1),r<0&&(r=e.length+r),r>=e.length){if(o)return-1;r=e.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof t&&(t=i.from(t,n)),i.isBuffer(t))return 0===t.length?-1:g(e,t,r,n,o);if("number"==typeof t)return t&=255,"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(e,t,r):Uint8Array.prototype.lastIndexOf.call(e,t,r):g(e,[t],r,n,o);throw new TypeError("val must be string, number or Buffer")}function g(e,t,r,n,o){var i,s=1,a=e.length,u=t.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(e.length<2||t.length<2)return-1;s=2,a/=2,u/=2,r/=2}function c(e,t){return 1===s?e[t]:e.readUInt16BE(t*s)}if(o){var f=-1;for(i=r;i<a;i++)if(c(e,i)===c(t,-1===f?0:i-f)){if(-1===f&&(f=i),i-f+1===u)return f*s}else-1!==f&&(i-=i-f),f=-1}else for(r+u>a&&(r=a-u),i=r;i>=0;i--){for(var l=!0,h=0;h<u;h++)if(c(e,i+h)!==c(t,h)){l=!1;break}if(l)return i}return-1}function y(e,t,r,n){r=Number(r)||0;var o=e.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=t.length;n>i/2&&(n=i/2);for(var s=0;s<n;++s){var a=parseInt(t.substr(2*s,2),16);if(j(a))return s;e[r+s]=a}return s}function b(e,t,r,n){return M(P(t,e.length-r),e,r,n)}function m(e,t,r,n){return M(function(e){for(var t=[],r=0;r<e.length;++r)t.push(255&e.charCodeAt(r));return t}(t),e,r,n)}function w(e,t,r,n){return m(e,t,r,n)}function v(e,t,r,n){return M(k(t),e,r,n)}function E(e,t,r,n){return M(function(e,t){for(var r,n,o,i=[],s=0;s<e.length&&!((t-=2)<0);++s)r=e.charCodeAt(s),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(t,e.length-r),e,r,n)}function _(e,r,n){return 0===r&&n===e.length?t.fromByteArray(e):t.fromByteArray(e.slice(r,n))}function S(e,t,r){r=Math.min(e.length,r);for(var n=[],o=t;o<r;){var i,s,a,u,c=e[o],f=null,l=c>239?4:c>223?3:c>191?2:1;if(o+l<=r)switch(l){case 1:c<128&&(f=c);break;case 2:128==(192&(i=e[o+1]))&&(u=(31&c)<<6|63&i)>127&&(f=u);break;case 3:i=e[o+1],s=e[o+2],128==(192&i)&&128==(192&s)&&(u=(15&c)<<12|(63&i)<<6|63&s)>2047&&(u<55296||u>57343)&&(f=u);break;case 4:i=e[o+1],s=e[o+2],a=e[o+3],128==(192&i)&&128==(192&s)&&128==(192&a)&&(u=(15&c)<<18|(63&i)<<12|(63&s)<<6|63&a)>65535&&u<1114112&&(f=u)}null===f?(f=65533,l=1):f>65535&&(f-=65536,n.push(f>>>10&1023|55296),f=56320|1023&f),n.push(f),o+=l}return function(e){var t=e.length;if(t<=4096)return String.fromCharCode.apply(String,e);var r="",n=0;for(;n<t;)r+=String.fromCharCode.apply(String,e.slice(n,n+=4096));return r}(n)}r.kMaxLength=2147483647,i.TYPED_ARRAY_SUPPORT=function(){try{var e=new Uint8Array(1);return e.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===e.foo()}catch(e){return!1}}(),i.TYPED_ARRAY_SUPPORT||"undefined"==typeof console||"function"!=typeof console.error||console.error("This browser lacks typed array (Uint8Array) support which is required by `buffer` v5.x. Use `buffer` v4.x if you require old browser support."),Object.defineProperty(i.prototype,"parent",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.buffer}}),Object.defineProperty(i.prototype,"offset",{enumerable:!0,get:function(){if(i.isBuffer(this))return this.byteOffset}}),"undefined"!=typeof Symbol&&null!=Symbol.species&&i[Symbol.species]===i&&Object.defineProperty(i,Symbol.species,{value:null,configurable:!0,enumerable:!1,writable:!1}),i.poolSize=8192,i.from=function(e,t,r){return s(e,t,r)},i.prototype.__proto__=Uint8Array.prototype,i.__proto__=Uint8Array,i.alloc=function(e,t,r){return function(e,t,r){return a(e),e<=0?o(e):void 0!==t?"string"==typeof r?o(e).fill(t,r):o(e).fill(t):o(e)}(e,t,r)},i.allocUnsafe=function(e){return u(e)},i.allocUnsafeSlow=function(e){return u(e)},i.isBuffer=function(e){return null!=e&&!0===e._isBuffer&&e!==i.prototype},i.compare=function(e,t){if(D(e,Uint8Array)&&(e=i.from(e,e.offset,e.byteLength)),D(t,Uint8Array)&&(t=i.from(t,t.offset,t.byteLength)),!i.isBuffer(e)||!i.isBuffer(t))throw new TypeError('The "buf1", "buf2" arguments must be one of type Buffer or Uint8Array');if(e===t)return 0;for(var r=e.length,n=t.length,o=0,s=Math.min(r,n);o<s;++o)if(e[o]!==t[o]){r=e[o],n=t[o];break}return r<n?-1:n<r?1:0},i.isEncoding=function(e){switch(String(e).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},i.concat=function(e,t){if(!Array.isArray(e))throw new TypeError('"list" argument must be an Array of Buffers');if(0===e.length)return i.alloc(0);var r;if(void 0===t)for(t=0,r=0;r<e.length;++r)t+=e[r].length;var n=i.allocUnsafe(t),o=0;for(r=0;r<e.length;++r){var s=e[r];if(D(s,Uint8Array)&&(s=i.from(s)),!i.isBuffer(s))throw new TypeError('"list" argument must be an Array of Buffers');s.copy(n,o),o+=s.length}return n},i.byteLength=l,i.prototype._isBuffer=!0,i.prototype.swap16=function(){var e=this.length;if(e%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var t=0;t<e;t+=2)d(this,t,t+1);return this},i.prototype.swap32=function(){var e=this.length;if(e%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var t=0;t<e;t+=4)d(this,t,t+3),d(this,t+1,t+2);return this},i.prototype.swap64=function(){var e=this.length;if(e%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var t=0;t<e;t+=8)d(this,t,t+7),d(this,t+1,t+6),d(this,t+2,t+5),d(this,t+3,t+4);return this},i.prototype.toString=function(){var e=this.length;return 0===e?"":0===arguments.length?S(this,0,e):h.apply(this,arguments)},i.prototype.toLocaleString=i.prototype.toString,i.prototype.equals=function(e){if(!i.isBuffer(e))throw new TypeError("Argument must be a Buffer");return this===e||0===i.compare(this,e)},i.prototype.inspect=function(){var e="",t=r.INSPECT_MAX_BYTES;return e=this.toString("hex",0,t).replace(/(.{2})/g,"$1 ").trim(),this.length>t&&(e+=" ... "),"<Buffer "+e+">"},i.prototype.compare=function(e,t,r,n,o){if(D(e,Uint8Array)&&(e=i.from(e,e.offset,e.byteLength)),!i.isBuffer(e))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof e);if(void 0===t&&(t=0),void 0===r&&(r=e?e.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),t<0||r>e.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&t>=r)return 0;if(n>=o)return-1;if(t>=r)return 1;if(this===e)return 0;for(var s=(o>>>=0)-(n>>>=0),a=(r>>>=0)-(t>>>=0),u=Math.min(s,a),c=this.slice(n,o),f=e.slice(t,r),l=0;l<u;++l)if(c[l]!==f[l]){s=c[l],a=f[l];break}return s<a?-1:a<s?1:0},i.prototype.includes=function(e,t,r){return-1!==this.indexOf(e,t,r)},i.prototype.indexOf=function(e,t,r){return p(this,e,t,r,!0)},i.prototype.lastIndexOf=function(e,t,r){return p(this,e,t,r,!1)},i.prototype.write=function(e,t,r,n){if(void 0===t)n="utf8",r=this.length,t=0;else if(void 0===r&&"string"==typeof t)n=t,r=this.length,t=0;else{if(!isFinite(t))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");t>>>=0,isFinite(r)?(r>>>=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-t;if((void 0===r||r>o)&&(r=o),e.length>0&&(r<0||t<0)||t>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return y(this,e,t,r);case"utf8":case"utf-8":return b(this,e,t,r);case"ascii":return m(this,e,t,r);case"latin1":case"binary":return w(this,e,t,r);case"base64":return v(this,e,t,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return E(this,e,t,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function R(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(127&e[o]);return n}function T(e,t,r){var n="";r=Math.min(e.length,r);for(var o=t;o<r;++o)n+=String.fromCharCode(e[o]);return n}function I(e,t,r){var n=e.length;(!t||t<0)&&(t=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=t;i<r;++i)o+=N(e[i]);return o}function U(e,t,r){for(var n=e.slice(t,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function L(e,t,r){if(e%1!=0||e<0)throw new RangeError("offset is not uint");if(e+t>r)throw new RangeError("Trying to access beyond buffer length")}function A(e,t,r,n,o,s){if(!i.isBuffer(e))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<s)throw new RangeError('"value" argument is out of bounds');if(r+n>e.length)throw new RangeError("Index out of range")}function O(e,t,r,n,o,i){if(r+n>e.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function C(e,t,r,o,i){return t=+t,r>>>=0,i||O(e,0,r,4),n.write(e,t,r,o,23,4),r+4}function B(e,t,r,o,i){return t=+t,r>>>=0,i||O(e,0,r,8),n.write(e,t,r,o,52,8),r+8}i.prototype.slice=function(e,t){var r=this.length;(e=~~e)<0?(e+=r)<0&&(e=0):e>r&&(e=r),(t=void 0===t?r:~~t)<0?(t+=r)<0&&(t=0):t>r&&(t=r),t<e&&(t=e);var n=this.subarray(e,t);return n.__proto__=i.prototype,n},i.prototype.readUIntLE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n},i.prototype.readUIntBE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);for(var n=this[e+--t],o=1;t>0&&(o*=256);)n+=this[e+--t]*o;return n},i.prototype.readUInt8=function(e,t){return e>>>=0,t||L(e,1,this.length),this[e]},i.prototype.readUInt16LE=function(e,t){return e>>>=0,t||L(e,2,this.length),this[e]|this[e+1]<<8},i.prototype.readUInt16BE=function(e,t){return e>>>=0,t||L(e,2,this.length),this[e]<<8|this[e+1]},i.prototype.readUInt32LE=function(e,t){return e>>>=0,t||L(e,4,this.length),(this[e]|this[e+1]<<8|this[e+2]<<16)+16777216*this[e+3]},i.prototype.readUInt32BE=function(e,t){return e>>>=0,t||L(e,4,this.length),16777216*this[e]+(this[e+1]<<16|this[e+2]<<8|this[e+3])},i.prototype.readIntLE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);for(var n=this[e],o=1,i=0;++i<t&&(o*=256);)n+=this[e+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*t)),n},i.prototype.readIntBE=function(e,t,r){e>>>=0,t>>>=0,r||L(e,t,this.length);for(var n=t,o=1,i=this[e+--n];n>0&&(o*=256);)i+=this[e+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*t)),i},i.prototype.readInt8=function(e,t){return e>>>=0,t||L(e,1,this.length),128&this[e]?-1*(255-this[e]+1):this[e]},i.prototype.readInt16LE=function(e,t){e>>>=0,t||L(e,2,this.length);var r=this[e]|this[e+1]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt16BE=function(e,t){e>>>=0,t||L(e,2,this.length);var r=this[e+1]|this[e]<<8;return 32768&r?4294901760|r:r},i.prototype.readInt32LE=function(e,t){return e>>>=0,t||L(e,4,this.length),this[e]|this[e+1]<<8|this[e+2]<<16|this[e+3]<<24},i.prototype.readInt32BE=function(e,t){return e>>>=0,t||L(e,4,this.length),this[e]<<24|this[e+1]<<16|this[e+2]<<8|this[e+3]},i.prototype.readFloatLE=function(e,t){return e>>>=0,t||L(e,4,this.length),n.read(this,e,!0,23,4)},i.prototype.readFloatBE=function(e,t){return e>>>=0,t||L(e,4,this.length),n.read(this,e,!1,23,4)},i.prototype.readDoubleLE=function(e,t){return e>>>=0,t||L(e,8,this.length),n.read(this,e,!0,52,8)},i.prototype.readDoubleBE=function(e,t){return e>>>=0,t||L(e,8,this.length),n.read(this,e,!1,52,8)},i.prototype.writeUIntLE=function(e,t,r,n){(e=+e,t>>>=0,r>>>=0,n)||A(this,e,t,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[t]=255&e;++i<r&&(o*=256);)this[t+i]=e/o&255;return t+r},i.prototype.writeUIntBE=function(e,t,r,n){(e=+e,t>>>=0,r>>>=0,n)||A(this,e,t,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[t+o]=255&e;--o>=0&&(i*=256);)this[t+o]=e/i&255;return t+r},i.prototype.writeUInt8=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,1,255,0),this[t]=255&e,t+1},i.prototype.writeUInt16LE=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,2,65535,0),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeUInt16BE=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,2,65535,0),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeUInt32LE=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,4,4294967295,0),this[t+3]=e>>>24,this[t+2]=e>>>16,this[t+1]=e>>>8,this[t]=255&e,t+4},i.prototype.writeUInt32BE=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,4,4294967295,0),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},i.prototype.writeIntLE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);A(this,e,t,r,o-1,-o)}var i=0,s=1,a=0;for(this[t]=255&e;++i<r&&(s*=256);)e<0&&0===a&&0!==this[t+i-1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},i.prototype.writeIntBE=function(e,t,r,n){if(e=+e,t>>>=0,!n){var o=Math.pow(2,8*r-1);A(this,e,t,r,o-1,-o)}var i=r-1,s=1,a=0;for(this[t+i]=255&e;--i>=0&&(s*=256);)e<0&&0===a&&0!==this[t+i+1]&&(a=1),this[t+i]=(e/s>>0)-a&255;return t+r},i.prototype.writeInt8=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,1,127,-128),e<0&&(e=255+e+1),this[t]=255&e,t+1},i.prototype.writeInt16LE=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,2,32767,-32768),this[t]=255&e,this[t+1]=e>>>8,t+2},i.prototype.writeInt16BE=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,2,32767,-32768),this[t]=e>>>8,this[t+1]=255&e,t+2},i.prototype.writeInt32LE=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,4,2147483647,-2147483648),this[t]=255&e,this[t+1]=e>>>8,this[t+2]=e>>>16,this[t+3]=e>>>24,t+4},i.prototype.writeInt32BE=function(e,t,r){return e=+e,t>>>=0,r||A(this,e,t,4,2147483647,-2147483648),e<0&&(e=4294967295+e+1),this[t]=e>>>24,this[t+1]=e>>>16,this[t+2]=e>>>8,this[t+3]=255&e,t+4},i.prototype.writeFloatLE=function(e,t,r){return C(this,e,t,!0,r)},i.prototype.writeFloatBE=function(e,t,r){return C(this,e,t,!1,r)},i.prototype.writeDoubleLE=function(e,t,r){return B(this,e,t,!0,r)},i.prototype.writeDoubleBE=function(e,t,r){return B(this,e,t,!1,r)},i.prototype.copy=function(e,t,r,n){if(!i.isBuffer(e))throw new TypeError("argument should be a Buffer");if(r||(r=0),n||0===n||(n=this.length),t>=e.length&&(t=e.length),t||(t=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===e.length||0===this.length)return 0;if(t<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),e.length-t<n-r&&(n=e.length-t+r);var o=n-r;if(this===e&&"function"==typeof Uint8Array.prototype.copyWithin)this.copyWithin(t,r,n);else if(this===e&&r<t&&t<n)for(var s=o-1;s>=0;--s)e[s+t]=this[s+r];else Uint8Array.prototype.set.call(e,this.subarray(r,n),t);return o},i.prototype.fill=function(e,t,r,n){if("string"==typeof e){if("string"==typeof t?(n=t,t=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!i.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===e.length){var o=e.charCodeAt(0);("utf8"===n&&o<128||"latin1"===n)&&(e=o)}}else"number"==typeof e&&(e&=255);if(t<0||this.length<t||this.length<r)throw new RangeError("Out of range index");if(r<=t)return this;var s;if(t>>>=0,r=void 0===r?this.length:r>>>0,e||(e=0),"number"==typeof e)for(s=t;s<r;++s)this[s]=e;else{var a=i.isBuffer(e)?e:i.from(e,n),u=a.length;if(0===u)throw new TypeError('The value "'+e+'" is invalid for argument "value"');for(s=0;s<r-t;++s)this[s+t]=a[s%u]}return this};var x=/[^+/0-9A-Za-z-_]/g;function N(e){return e<16?"0"+e.toString(16):e.toString(16)}function P(e,t){var r;t=t||1/0;for(var n=e.length,o=null,i=[],s=0;s<n;++s){if((r=e.charCodeAt(s))>55295&&r<57344){if(!o){if(r>56319){(t-=3)>-1&&i.push(239,191,189);continue}if(s+1===n){(t-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(t-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((t-=1)<0)break;i.push(r)}else if(r<2048){if((t-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((t-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((t-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function k(e){return t.toByteArray(function(e){if((e=(e=e.split("=")[0]).trim().replace(x,"")).length<2)return"";for(;e.length%4!=0;)e+="=";return e}(e))}function M(e,t,r,n){for(var o=0;o<n&&!(o+r>=t.length||o>=e.length);++o)t[o+r]=e[o];return o}function D(e,t){return e instanceof t||null!=e&&null!=e.constructor&&null!=e.constructor.name&&e.constructor.name===t.name}function j(e){return e!=e}}).call(this)}).call(this,e("buffer").Buffer)},{"base64-js":3,buffer:5,ieee754:15}],6:[function(e,t,r){t.exports={100:"Continue",101:"Switching Protocols",102:"Processing",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",418:"I'm a teapot",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Unordered Collection",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",509:"Bandwidth Limit Exceeded",510:"Not Extended",511:"Network Authentication Required"}},{}],7:[function(e,t,r){"use strict";r.toString=function(e){switch(e){case 1:return"IN";case 2:return"CS";case 3:return"CH";case 4:return"HS";case 255:return"ANY"}return"UNKNOWN_"+e},r.toClass=function(e){switch(e.toUpperCase()){case"IN":return 1;case"CS":return 2;case"CH":return 3;case"HS":return 4;case"ANY":return 255}return 0}},{}],8:[function(e,t,r){(function(t){(function(){"use strict";const n=e("./types"),o=e("./rcodes"),i=e("./opcodes"),s=e("./classes"),a=e("./optioncodes"),u=e("ip"),c=r.txt=r.name={};c.encode=function(e,r,n){r||(r=t.allocUnsafe(c.encodingLength(e))),n||(n=0);const o=n,i=e.replace(/^\.|\.$/gm,"");if(i.length){const e=i.split(".");for(let t=0;t<e.length;t++){const o=r.write(e[t],n+1);r[n]=o,n+=o+1}}return r[n++]=0,c.encode.bytes=n-o,r},c.encode.bytes=0,c.decode=function(e,t){t||(t=0);const r=[],n=t;let o=e[t++];if(0===o)return c.decode.bytes=1,".";if(o>=192){const r=c.decode(e,e.readUInt16BE(t-1)-49152);return c.decode.bytes=2,r}for(;o;){if(o>=192){r.push(c.decode(e,e.readUInt16BE(t-1)-49152)),t++;break}r.push(e.toString("utf-8",t,t+o)),t+=o,o=e[t++]}return c.decode.bytes=t-n,r.join(".")},c.decode.bytes=0,c.encodingLength=function(e){return"."===e?1:t.byteLength(e.replace(/^\.|\.$/gm,""))+2};const f={encode:function(e,r,n){r||(r=t.allocUnsafe(f.encodingLength(e))),n||(n=0);const o=r.write(e,n+1);return r[n]=o,f.encode.bytes=o+1,r}};f.encode.bytes=0,f.decode=function(e,t){t||(t=0);const r=e[t],n=e.toString("utf-8",t+1,t+1+r);return f.decode.bytes=r+1,n},f.decode.bytes=0,f.encodingLength=function(e){return t.byteLength(e)+1};const l={encode:function(e,t,r){t||(t=l.encodingLength(e)),r||(r=0);const n=32767&(e.flags||0),o="response"===e.type?32768:0;return t.writeUInt16BE(e.id||0,r),t.writeUInt16BE(n|o,r+2),t.writeUInt16BE(e.questions.length,r+4),t.writeUInt16BE(e.answers.length,r+6),t.writeUInt16BE(e.authorities.length,r+8),t.writeUInt16BE(e.additionals.length,r+10),t}};l.encode.bytes=12,l.decode=function(e,t){if(t||(t=0),e.length<12)throw new Error("Header must be 12 bytes");const r=e.readUInt16BE(t+2);return{id:e.readUInt16BE(t),type:32768&r?"response":"query",flags:32767&r,flag_qr:1==(r>>15&1),opcode:i.toString(r>>11&15),flag_aa:1==(r>>10&1),flag_tc:1==(r>>9&1),flag_rd:1==(r>>8&1),flag_ra:1==(r>>7&1),flag_z:1==(r>>6&1),flag_ad:1==(r>>5&1),flag_cd:1==(r>>4&1),rcode:o.toString(15&r),questions:new Array(e.readUInt16BE(t+4)),answers:new Array(e.readUInt16BE(t+6)),authorities:new Array(e.readUInt16BE(t+8)),additionals:new Array(e.readUInt16BE(t+10))}},l.decode.bytes=12,l.encodingLength=function(){return 12};const h=r.unknown={};h.encode=function(e,r,n){return r||(r=t.allocUnsafe(h.encodingLength(e))),n||(n=0),r.writeUInt16BE(e.length,n),e.copy(r,n+2),h.encode.bytes=e.length+2,r},h.encode.bytes=0,h.decode=function(e,t){t||(t=0);const r=e.readUInt16BE(t),n=e.slice(t+2,t+2+r);return h.decode.bytes=r+2,n},h.decode.bytes=0,h.encodingLength=function(e){return e.length+2};const d=r.ns={};d.encode=function(e,r,n){return r||(r=t.allocUnsafe(d.encodingLength(e))),n||(n=0),c.encode(e,r,n+2),r.writeUInt16BE(c.encode.bytes,n),d.encode.bytes=c.encode.bytes+2,r},d.encode.bytes=0,d.decode=function(e,t){t||(t=0);const r=e.readUInt16BE(t),n=c.decode(e,t+2);return d.decode.bytes=r+2,n},d.decode.bytes=0,d.encodingLength=function(e){return c.encodingLength(e)+2};const p=r.soa={};p.encode=function(e,r,n){r||(r=t.allocUnsafe(p.encodingLength(e))),n||(n=0);const o=n;return n+=2,c.encode(e.mname,r,n),n+=c.encode.bytes,c.encode(e.rname,r,n),n+=c.encode.bytes,r.writeUInt32BE(e.serial||0,n),n+=4,r.writeUInt32BE(e.refresh||0,n),n+=4,r.writeUInt32BE(e.retry||0,n),n+=4,r.writeUInt32BE(e.expire||0,n),n+=4,r.writeUInt32BE(e.minimum||0,n),n+=4,r.writeUInt16BE(n-o-2,o),p.encode.bytes=n-o,r},p.encode.bytes=0,p.decode=function(e,t){t||(t=0);const r=t,n={};return t+=2,n.mname=c.decode(e,t),t+=c.decode.bytes,n.rname=c.decode(e,t),t+=c.decode.bytes,n.serial=e.readUInt32BE(t),t+=4,n.refresh=e.readUInt32BE(t),t+=4,n.retry=e.readUInt32BE(t),t+=4,n.expire=e.readUInt32BE(t),t+=4,n.minimum=e.readUInt32BE(t),t+=4,p.decode.bytes=t-r,n},p.decode.bytes=0,p.encodingLength=function(e){return 22+c.encodingLength(e.mname)+c.encodingLength(e.rname)};const g=r.txt={};g.encode=function(e,r,n){Array.isArray(e)||(e=[e]);for(let r=0;r<e.length;r++)if("string"==typeof e[r]&&(e[r]=t.from(e[r])),!t.isBuffer(e[r]))throw new Error("Must be a Buffer");r||(r=t.allocUnsafe(g.encodingLength(e))),n||(n=0);const o=n;return n+=2,e.forEach((function(e){r[n++]=e.length,e.copy(r,n,0,e.length),n+=e.length})),r.writeUInt16BE(n-o-2,o),g.encode.bytes=n-o,r},g.encode.bytes=0,g.decode=function(e,t){t||(t=0);const r=t;let n=e.readUInt16BE(t);t+=2;let o=[];for(;n>0;){const r=e[t++];if(--n,n<r)throw new Error("Buffer overflow");o.push(e.slice(t,t+r)),t+=r,n-=r}return g.decode.bytes=t-r,o},g.decode.bytes=0,g.encodingLength=function(e){Array.isArray(e)||(e=[e]);let r=2;return e.forEach((function(e){r+="string"==typeof e?t.byteLength(e)+1:e.length+1})),r};const y=r.null={};y.encode=function(e,r,n){r||(r=t.allocUnsafe(y.encodingLength(e))),n||(n=0),"string"==typeof e&&(e=t.from(e)),e||(e=t.allocUnsafe(0));const o=n;n+=2;const i=e.length;return e.copy(r,n,0,i),n+=i,r.writeUInt16BE(n-o-2,o),y.encode.bytes=n-o,r},y.encode.bytes=0,y.decode=function(e,t){t||(t=0);const r=t,n=e.readUInt16BE(t);t+=2;const o=e.slice(t,t+n);return t+=n,y.decode.bytes=t-r,o},y.decode.bytes=0,y.encodingLength=function(e){return e?(t.isBuffer(e)?e.length:t.byteLength(e))+2:2};const b=r.hinfo={};b.encode=function(e,r,n){r||(r=t.allocUnsafe(b.encodingLength(e))),n||(n=0);const o=n;return n+=2,f.encode(e.cpu,r,n),n+=f.encode.bytes,f.encode(e.os,r,n),n+=f.encode.bytes,r.writeUInt16BE(n-o-2,o),b.encode.bytes=n-o,r},b.encode.bytes=0,b.decode=function(e,t){t||(t=0);const r=t,n={};return t+=2,n.cpu=f.decode(e,t),t+=f.decode.bytes,n.os=f.decode(e,t),t+=f.decode.bytes,b.decode.bytes=t-r,n},b.decode.bytes=0,b.encodingLength=function(e){return f.encodingLength(e.cpu)+f.encodingLength(e.os)+2};const m=r.ptr={},w=r.cname=m,v=r.dname=m;m.encode=function(e,r,n){return r||(r=t.allocUnsafe(m.encodingLength(e))),n||(n=0),c.encode(e,r,n+2),r.writeUInt16BE(c.encode.bytes,n),m.encode.bytes=c.encode.bytes+2,r},m.encode.bytes=0,m.decode=function(e,t){t||(t=0);const r=c.decode(e,t+2);return m.decode.bytes=c.decode.bytes+2,r},m.decode.bytes=0,m.encodingLength=function(e){return c.encodingLength(e)+2};const E=r.srv={};E.encode=function(e,r,n){r||(r=t.allocUnsafe(E.encodingLength(e))),n||(n=0),r.writeUInt16BE(e.priority||0,n+2),r.writeUInt16BE(e.weight||0,n+4),r.writeUInt16BE(e.port||0,n+6),c.encode(e.target,r,n+8);const o=c.encode.bytes+6;return r.writeUInt16BE(o,n),E.encode.bytes=o+2,r},E.encode.bytes=0,E.decode=function(e,t){t||(t=0);const r=e.readUInt16BE(t),n={};return n.priority=e.readUInt16BE(t+2),n.weight=e.readUInt16BE(t+4),n.port=e.readUInt16BE(t+6),n.target=c.decode(e,t+8),E.decode.bytes=r+2,n},E.decode.bytes=0,E.encodingLength=function(e){return 8+c.encodingLength(e.target)};const _=r.caa={};_.ISSUER_CRITICAL=128,_.encode=function(e,r,n){const o=_.encodingLength(e);return r||(r=t.allocUnsafe(_.encodingLength(e))),n||(n=0),e.issuerCritical&&(e.flags=_.ISSUER_CRITICAL),r.writeUInt16BE(o-2,n),n+=2,r.writeUInt8(e.flags||0,n),n+=1,f.encode(e.tag,r,n),n+=f.encode.bytes,r.write(e.value,n),n+=t.byteLength(e.value),_.encode.bytes=o,r},_.encode.bytes=0,_.decode=function(e,t){t||(t=0);const r=e.readUInt16BE(t),n=t+=2,o={};return o.flags=e.readUInt8(t),t+=1,o.tag=f.decode(e,t),t+=f.decode.bytes,o.value=e.toString("utf-8",t,n+r),o.issuerCritical=!!(o.flags&_.ISSUER_CRITICAL),_.decode.bytes=r+2,o},_.decode.bytes=0,_.encodingLength=function(e){return f.encodingLength(e.tag)+f.encodingLength(e.value)+2};const S=r.mx={};S.encode=function(e,r,n){r||(r=t.allocUnsafe(S.encodingLength(e))),n||(n=0);const o=n;return n+=2,r.writeUInt16BE(e.preference||0,n),n+=2,c.encode(e.exchange,r,n),n+=c.encode.bytes,r.writeUInt16BE(n-o-2,o),S.encode.bytes=n-o,r},S.encode.bytes=0,S.decode=function(e,t){t||(t=0);const r=t,n={};return t+=2,n.preference=e.readUInt16BE(t),t+=2,n.exchange=c.decode(e,t),t+=c.decode.bytes,S.decode.bytes=t-r,n},S.encodingLength=function(e){return 4+c.encodingLength(e.exchange)};const R=r.a={};R.encode=function(e,r,n){return r||(r=t.allocUnsafe(R.encodingLength(e))),n||(n=0),r.writeUInt16BE(4,n),n+=2,u.toBuffer(e,r,n),R.encode.bytes=6,r},R.encode.bytes=0,R.decode=function(e,t){t||(t=0),t+=2;const r=u.toString(e,t,4);return R.decode.bytes=6,r},R.decode.bytes=0,R.encodingLength=function(){return 6};const T=r.aaaa={};T.encode=function(e,r,n){return r||(r=t.allocUnsafe(T.encodingLength(e))),n||(n=0),r.writeUInt16BE(16,n),n+=2,u.toBuffer(e,r,n),T.encode.bytes=18,r},T.encode.bytes=0,T.decode=function(e,t){t||(t=0),t+=2;const r=u.toString(e,t,16);return T.decode.bytes=18,r},T.decode.bytes=0,T.encodingLength=function(){return 18};const I=r.option={};I.encode=function(e,r,n){r||(r=t.allocUnsafe(I.encodingLength(e))),n||(n=0);const o=n,i=a.toCode(e.code);if(r.writeUInt16BE(i,n),n+=2,e.data)r.writeUInt16BE(e.data.length,n),n+=2,e.data.copy(r,n),n+=e.data.length;else switch(i){case 8:const t=e.sourcePrefixLength||0,o=e.family||(u.isV4Format(e.ip)?1:2),i=u.toBuffer(e.ip),s=Math.ceil(t/8);r.writeUInt16BE(s+4,n),n+=2,r.writeUInt16BE(o,n),n+=2,r.writeUInt8(t,n++),r.writeUInt8(e.scopePrefixLength||0,n++),i.copy(r,n,0,s),n+=s;break;case 11:e.timeout?(r.writeUInt16BE(2,n),n+=2,r.writeUInt16BE(e.timeout,n),n+=2):(r.writeUInt16BE(0,n),n+=2);break;case 12:const a=e.length||0;r.writeUInt16BE(a,n),n+=2,r.fill(0,n,n+a),n+=a;break;case 14:const c=2*e.tags.length;r.writeUInt16BE(c,n),n+=2;for(const t of e.tags)r.writeUInt16BE(t,n),n+=2;break;default:throw new Error("Unknown roption code: "+e.code)}return I.encode.bytes=n-o,r},I.encode.bytes=0,I.decode=function(e,r){r||(r=0);const n={};n.code=e.readUInt16BE(r),n.type=a.toString(n.code),r+=2;const o=e.readUInt16BE(r);switch(r+=2,n.data=e.slice(r,r+o),n.code){case 8:n.family=e.readUInt16BE(r),r+=2,n.sourcePrefixLength=e.readUInt8(r++),n.scopePrefixLength=e.readUInt8(r++);const i=t.alloc(1===n.family?4:16);e.copy(i,0,r,r+o-4),n.ip=u.toString(i);break;case 11:o>0&&(n.timeout=e.readUInt16BE(r),r+=2);break;case 14:n.tags=[];for(let t=0;t<o;t+=2)n.tags.push(e.readUInt16BE(r)),r+=2}return I.decode.bytes=o+4,n},I.decode.bytes=0,I.encodingLength=function(e){if(e.data)return e.data.length+4;switch(a.toCode(e.code)){case 8:const t=e.sourcePrefixLength||0;return Math.ceil(t/8)+8;case 11:return"number"==typeof e.timeout?6:4;case 12:return e.length+4;case 14:return 4+2*e.tags.length}throw new Error("Unknown roption code: "+e.code)};const U=r.opt={};U.encode=function(e,r,n){r||(r=t.allocUnsafe(U.encodingLength(e))),n||(n=0);const o=n,i=D(e,I);return r.writeUInt16BE(i,n),n=j(e,I,r,n+2),U.encode.bytes=n-o,r},U.encode.bytes=0,U.decode=function(e,t){t||(t=0);const r=t,n=[];let o=e.readUInt16BE(t);t+=2;let i=0;for(;o>0;)n[i++]=I.decode(e,t),t+=I.decode.bytes,o-=I.decode.bytes;return U.decode.bytes=t-r,n},U.decode.bytes=0,U.encodingLength=function(e){return 2+D(e||[],I)};const L=r.dnskey={};L.PROTOCOL_DNSSEC=3,L.ZONE_KEY=128,L.SECURE_ENTRYPOINT=32768,L.encode=function(e,r,n){r||(r=t.allocUnsafe(L.encodingLength(e))),n||(n=0);const o=n,i=e.key;if(!t.isBuffer(i))throw new Error("Key must be a Buffer");return n+=2,r.writeUInt16BE(e.flags,n),n+=2,r.writeUInt8(L.PROTOCOL_DNSSEC,n),n+=1,r.writeUInt8(e.algorithm,n),n+=1,i.copy(r,n,0,i.length),n+=i.length,L.encode.bytes=n-o,r.writeUInt16BE(L.encode.bytes-2,o),r},L.encode.bytes=0,L.decode=function(e,t){t||(t=0);const r=t;var n={},o=e.readUInt16BE(t);if(t+=2,n.flags=e.readUInt16BE(t),t+=2,e.readUInt8(t)!==L.PROTOCOL_DNSSEC)throw new Error("Protocol must be 3");return t+=1,n.algorithm=e.readUInt8(t),t+=1,n.key=e.slice(t,r+o+2),t+=n.key.length,L.decode.bytes=t-r,n},L.decode.bytes=0,L.encodingLength=function(e){return 6+t.byteLength(e.key)};const A=r.rrsig={};A.encode=function(e,r,o){r||(r=t.allocUnsafe(A.encodingLength(e))),o||(o=0);const i=o,s=e.signature;if(!t.isBuffer(s))throw new Error("Signature must be a Buffer");return o+=2,r.writeUInt16BE(n.toType(e.typeCovered),o),o+=2,r.writeUInt8(e.algorithm,o),o+=1,r.writeUInt8(e.labels,o),o+=1,r.writeUInt32BE(e.originalTTL,o),o+=4,r.writeUInt32BE(e.expiration,o),o+=4,r.writeUInt32BE(e.inception,o),o+=4,r.writeUInt16BE(e.keyTag,o),o+=2,c.encode(e.signersName,r,o),o+=c.encode.bytes,s.copy(r,o,0,s.length),o+=s.length,A.encode.bytes=o-i,r.writeUInt16BE(A.encode.bytes-2,i),r},A.encode.bytes=0,A.decode=function(e,t){t||(t=0);const r=t;var o={},i=e.readUInt16BE(t);return t+=2,o.typeCovered=n.toString(e.readUInt16BE(t)),t+=2,o.algorithm=e.readUInt8(t),t+=1,o.labels=e.readUInt8(t),t+=1,o.originalTTL=e.readUInt32BE(t),t+=4,o.expiration=e.readUInt32BE(t),t+=4,o.inception=e.readUInt32BE(t),t+=4,o.keyTag=e.readUInt16BE(t),t+=2,o.signersName=c.decode(e,t),t+=c.decode.bytes,o.signature=e.slice(t,r+i+2),t+=o.signature.length,A.decode.bytes=t-r,o},A.decode.bytes=0,A.encodingLength=function(e){return 20+c.encodingLength(e.signersName)+t.byteLength(e.signature)};const O=r.rp={};O.encode=function(e,r,n){r||(r=t.allocUnsafe(O.encodingLength(e))),n||(n=0);const o=n;return n+=2,c.encode(e.mbox||".",r,n),n+=c.encode.bytes,c.encode(e.txt||".",r,n),n+=c.encode.bytes,O.encode.bytes=n-o,r.writeUInt16BE(O.encode.bytes-2,o),r},O.encode.bytes=0,O.decode=function(e,t){t||(t=0);const r=t,n={};return t+=2,n.mbox=c.decode(e,t)||".",t+=c.decode.bytes,n.txt=c.decode(e,t)||".",t+=c.decode.bytes,O.decode.bytes=t-r,n},O.decode.bytes=0,O.encodingLength=function(e){return 2+c.encodingLength(e.mbox||".")+c.encodingLength(e.txt||".")};const C={encode:function(e,r,o){r||(r=t.allocUnsafe(C.encodingLength(e))),o||(o=0);const i=o;for(var s=[],a=0;a<e.length;a++){var u=n.toType(e[a]);void 0===s[u>>8]&&(s[u>>8]=[]),s[u>>8][u>>3&31]|=1<<7-(7&u)}for(a=0;a<s.length;a++)if(void 0!==s[a]){var c=t.from(s[a]);r.writeUInt8(a,o),o+=1,r.writeUInt8(c.length,o),o+=1,c.copy(r,o),o+=c.length}return C.encode.bytes=o-i,r}};C.encode.bytes=0,C.decode=function(e,t,r){t||(t=0);const o=t;for(var i=[];t-o<r;){var s=e.readUInt8(t);t+=1;var a=e.readUInt8(t);t+=1;for(var u=0;u<a;u++)for(var c=e.readUInt8(t+u),f=0;f<8;f++)if(c&1<<7-f){var l=n.toString(s<<8|u<<3|f);i.push(l)}t+=a}return C.decode.bytes=t-o,i},C.decode.bytes=0,C.encodingLength=function(e){for(var t=[],r=0;r<e.length;r++){var o=n.toType(e[r]);t[o>>8]=Math.max(t[o>>8]||0,255&o)}var i=0;for(r=0;r<t.length;r++)void 0!==t[r]&&(i+=2+Math.ceil((t[r]+1)/8));return i};const B=r.nsec={};B.encode=function(e,r,n){r||(r=t.allocUnsafe(B.encodingLength(e))),n||(n=0);const o=n;return n+=2,c.encode(e.nextDomain,r,n),n+=c.encode.bytes,C.encode(e.rrtypes,r,n),n+=C.encode.bytes,B.encode.bytes=n-o,r.writeUInt16BE(B.encode.bytes-2,o),r},B.encode.bytes=0,B.decode=function(e,t){t||(t=0);const r=t;var n={},o=e.readUInt16BE(t);return t+=2,n.nextDomain=c.decode(e,t),t+=c.decode.bytes,n.rrtypes=C.decode(e,t,o-(t-r)),t+=C.decode.bytes,B.decode.bytes=t-r,n},B.decode.bytes=0,B.encodingLength=function(e){return 2+c.encodingLength(e.nextDomain)+C.encodingLength(e.rrtypes)};const x=r.nsec3={};x.encode=function(e,r,n){r||(r=t.allocUnsafe(x.encodingLength(e))),n||(n=0);const o=n,i=e.salt;if(!t.isBuffer(i))throw new Error("salt must be a Buffer");const s=e.nextDomain;if(!t.isBuffer(s))throw new Error("nextDomain must be a Buffer");return n+=2,r.writeUInt8(e.algorithm,n),n+=1,r.writeUInt8(e.flags,n),n+=1,r.writeUInt16BE(e.iterations,n),n+=2,r.writeUInt8(i.length,n),n+=1,i.copy(r,n,0,i.length),n+=i.length,r.writeUInt8(s.length,n),n+=1,s.copy(r,n,0,s.length),n+=s.length,C.encode(e.rrtypes,r,n),n+=C.encode.bytes,x.encode.bytes=n-o,r.writeUInt16BE(x.encode.bytes-2,o),r},x.encode.bytes=0,x.decode=function(e,t){t||(t=0);const r=t;var n={},o=e.readUInt16BE(t);t+=2,n.algorithm=e.readUInt8(t),t+=1,n.flags=e.readUInt8(t),t+=1,n.iterations=e.readUInt16BE(t),t+=2;const i=e.readUInt8(t);t+=1,n.salt=e.slice(t,t+i),t+=i;const s=e.readUInt8(t);return t+=1,n.nextDomain=e.slice(t,t+s),t+=s,n.rrtypes=C.decode(e,t,o-(t-r)),t+=C.decode.bytes,x.decode.bytes=t-r,n},x.decode.bytes=0,x.encodingLength=function(e){return 8+e.salt.length+e.nextDomain.length+C.encodingLength(e.rrtypes)};const N=r.ds={};N.encode=function(e,r,n){r||(r=t.allocUnsafe(N.encodingLength(e))),n||(n=0);const o=n,i=e.digest;if(!t.isBuffer(i))throw new Error("Digest must be a Buffer");return n+=2,r.writeUInt16BE(e.keyTag,n),n+=2,r.writeUInt8(e.algorithm,n),n+=1,r.writeUInt8(e.digestType,n),n+=1,i.copy(r,n,0,i.length),n+=i.length,N.encode.bytes=n-o,r.writeUInt16BE(N.encode.bytes-2,o),r},N.encode.bytes=0,N.decode=function(e,t){t||(t=0);const r=t;var n={},o=e.readUInt16BE(t);return t+=2,n.keyTag=e.readUInt16BE(t),t+=2,n.algorithm=e.readUInt8(t),t+=1,n.digestType=e.readUInt8(t),t+=1,n.digest=e.slice(t,r+o+2),t+=n.digest.length,N.decode.bytes=t-r,n},N.decode.bytes=0,N.encodingLength=function(e){return 6+t.byteLength(e.digest)};const P=r.record=function(e){switch(e.toUpperCase()){case"A":return R;case"PTR":return m;case"CNAME":return w;case"DNAME":return v;case"TXT":return g;case"NULL":return y;case"AAAA":return T;case"SRV":return E;case"HINFO":return b;case"CAA":return _;case"NS":return d;case"SOA":return p;case"MX":return S;case"OPT":return U;case"DNSKEY":return L;case"RRSIG":return A;case"RP":return O;case"NSEC":return B;case"NSEC3":return x;case"DS":return N}return h},k=r.answer={};k.encode=function(e,r,o){r||(r=t.allocUnsafe(k.encodingLength(e))),o||(o=0);const i=o;if(c.encode(e.name,r,o),o+=c.encode.bytes,r.writeUInt16BE(n.toType(e.type),o),"OPT"===e.type.toUpperCase()){if("."!==e.name)throw new Error("OPT name must be root.");r.writeUInt16BE(e.udpPayloadSize||4096,o+2),r.writeUInt8(e.extendedRcode||0,o+4),r.writeUInt8(e.ednsVersion||0,o+5),r.writeUInt16BE(e.flags||0,o+6),o+=8,U.encode(e.options||[],r,o),o+=U.encode.bytes}else{let t=s.toClass(void 0===e.class?"IN":e.class);e.flush&&(t|=32768),r.writeUInt16BE(t,o+2),r.writeUInt32BE(e.ttl||0,o+4),o+=8;const n=P(e.type);n.encode(e.data,r,o),o+=n.encode.bytes}return k.encode.bytes=o-i,r},k.encode.bytes=0,k.decode=function(e,t){t||(t=0);const r={},o=t;if(r.name=c.decode(e,t),t+=c.decode.bytes,r.type=n.toString(e.readUInt16BE(t)),"OPT"===r.type)r.udpPayloadSize=e.readUInt16BE(t+2),r.extendedRcode=e.readUInt8(t+4),r.ednsVersion=e.readUInt8(t+5),r.flags=e.readUInt16BE(t+6),r.flag_do=1==(r.flags>>15&1),r.options=U.decode(e,t+8),t+=8+U.decode.bytes;else{const n=e.readUInt16BE(t+2);r.ttl=e.readUInt32BE(t+4),r.class=s.toString(-32769&n),r.flush=!!(32768&n);const o=P(r.type);r.data=o.decode(e,t+8),t+=8+o.decode.bytes}return k.decode.bytes=t-o,r},k.decode.bytes=0,k.encodingLength=function(e){const t=null!==e.data&&void 0!==e.data?e.data:e.options;return c.encodingLength(e.name)+8+P(e.type).encodingLength(t)};const M=r.question={};function D(e,t){let r=0;for(let n=0;n<e.length;n++)r+=t.encodingLength(e[n]);return r}function j(e,t,r,n){for(let o=0;o<e.length;o++)t.encode(e[o],r,n),n+=t.encode.bytes;return n}function q(e,t,r,n){for(let o=0;o<e.length;o++)e[o]=t.decode(r,n),n+=t.decode.bytes;return n}M.encode=function(e,r,o){r||(r=t.allocUnsafe(M.encodingLength(e))),o||(o=0);const i=o;return c.encode(e.name,r,o),o+=c.encode.bytes,r.writeUInt16BE(n.toType(e.type),o),o+=2,r.writeUInt16BE(s.toClass(void 0===e.class?"IN":e.class),o),o+=2,M.encode.bytes=o-i,e},M.encode.bytes=0,M.decode=function(e,t){t||(t=0);const r=t,o={};o.name=c.decode(e,t),t+=c.decode.bytes,o.type=n.toString(e.readUInt16BE(t)),t+=2,o.class=s.toString(e.readUInt16BE(t)),t+=2;return!!(32768&o.class)&&(o.class&=-32769),M.decode.bytes=t-r,o},M.decode.bytes=0,M.encodingLength=function(e){return c.encodingLength(e.name)+4},r.AUTHORITATIVE_ANSWER=1024,r.TRUNCATED_RESPONSE=512,r.RECURSION_DESIRED=256,r.RECURSION_AVAILABLE=128,r.AUTHENTIC_DATA=32,r.CHECKING_DISABLED=16,r.DNSSEC_OK=32768,r.encode=function(e,n,o){n||(n=t.allocUnsafe(r.encodingLength(e))),o||(o=0);const i=o;return e.questions||(e.questions=[]),e.answers||(e.answers=[]),e.authorities||(e.authorities=[]),e.additionals||(e.additionals=[]),l.encode(e,n,o),o+=l.encode.bytes,o=j(e.questions,M,n,o),o=j(e.answers,k,n,o),o=j(e.authorities,k,n,o),o=j(e.additionals,k,n,o),r.encode.bytes=o-i,n},r.encode.bytes=0,r.decode=function(e,t){t||(t=0);const n=t,o=l.decode(e,t);return t+=l.decode.bytes,t=q(o.questions,M,e,t),t=q(o.answers,k,e,t),t=q(o.authorities,k,e,t),t=q(o.additionals,k,e,t),r.decode.bytes=t-n,o},r.decode.bytes=0,r.encodingLength=function(e){return l.encodingLength(e)+D(e.questions||[],M)+D(e.answers||[],k)+D(e.authorities||[],k)+D(e.additionals||[],k)},r.streamEncode=function(e){const n=r.encode(e),o=t.allocUnsafe(2);o.writeUInt16BE(n.byteLength);const i=t.concat([o,n]);return r.streamEncode.bytes=i.byteLength,i},r.streamEncode.bytes=0,r.streamDecode=function(e){const t=e.readUInt16BE(0);if(e.byteLength<t+2)return null;const n=r.decode(e.slice(2));return r.streamDecode.bytes=r.decode.bytes,n},r.streamDecode.bytes=0}).call(this)}).call(this,e("buffer").Buffer)},{"./classes":7,"./opcodes":9,"./optioncodes":10,"./rcodes":11,"./types":12,buffer:5,ip:17}],9:[function(e,t,r){"use strict";r.toString=function(e){switch(e){case 0:return"QUERY";case 1:return"IQUERY";case 2:return"STATUS";case 3:return"OPCODE_3";case 4:return"NOTIFY";case 5:return"UPDATE";case 6:return"OPCODE_6";case 7:return"OPCODE_7";case 8:return"OPCODE_8";case 9:return"OPCODE_9";case 10:return"OPCODE_10";case 11:return"OPCODE_11";case 12:return"OPCODE_12";case 13:return"OPCODE_13";case 14:return"OPCODE_14";case 15:return"OPCODE_15"}return"OPCODE_"+e},r.toOpcode=function(e){switch(e.toUpperCase()){case"QUERY":return 0;case"IQUERY":return 1;case"STATUS":return 2;case"OPCODE_3":return 3;case"NOTIFY":return 4;case"UPDATE":return 5;case"OPCODE_6":return 6;case"OPCODE_7":return 7;case"OPCODE_8":return 8;case"OPCODE_9":return 9;case"OPCODE_10":return 10;case"OPCODE_11":return 11;case"OPCODE_12":return 12;case"OPCODE_13":return 13;case"OPCODE_14":return 14;case"OPCODE_15":return 15}return 0}},{}],10:[function(e,t,r){"use strict";r.toString=function(e){switch(e){case 1:return"LLQ";case 2:return"UL";case 3:return"NSID";case 5:return"DAU";case 6:return"DHU";case 7:return"N3U";case 8:return"CLIENT_SUBNET";case 9:return"EXPIRE";case 10:return"COOKIE";case 11:return"TCP_KEEPALIVE";case 12:return"PADDING";case 13:return"CHAIN";case 14:return"KEY_TAG";case 26946:return"DEVICEID"}return e<0?null:"OPTION_"+e},r.toCode=function(e){if("number"==typeof e)return e;if(!e)return-1;switch(e.toUpperCase()){case"OPTION_0":return 0;case"LLQ":return 1;case"UL":return 2;case"NSID":return 3;case"OPTION_4":return 4;case"DAU":return 5;case"DHU":return 6;case"N3U":return 7;case"CLIENT_SUBNET":return 8;case"EXPIRE":return 9;case"COOKIE":return 10;case"TCP_KEEPALIVE":return 11;case"PADDING":return 12;case"CHAIN":return 13;case"KEY_TAG":return 14;case"DEVICEID":return 26946;case"OPTION_65535":return 65535}const t=e.match(/_(\d+)$/);return t?parseInt(t[1],10):-1}},{}],11:[function(e,