universal-doh 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -233,7 +233,7 @@ function G(t, n, r) {
233
233
  t = d(t, y - w), i += 36;
234
234
  return i + d(36 * t, t + Q);
235
235
  }
236
- const X = "0.0.1";
236
+ const X = "0.0.2";
237
237
  function Y(t, n) {
238
238
  const r = P(t), i = S([
239
239
  {
@@ -1 +1 @@
1
- (function(d,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(d=typeof globalThis<"u"?globalThis:d||self,u(d["universal-doh"]={}))})(this,function(d){"use strict";function u(t){return t.map(n=>String.fromCharCode(...n)).join(".")}function v(t){const n=t.split(".").filter(i=>i.length>0),e=[];for(const i of n){if(i.length<1||i.length>63)throw new Error(`Label "${i}" must be between 1 and 63 characters long`);if(i.startsWith("-")||i.endsWith("-"))throw new Error(`Label "${i}" cannot start or end with a hyphen`);const r=[];for(const o of i){const c=o.charCodeAt(0);if(c>=48&&c<=57||c>=97&&c<=122||c===45)r.push(c);else throw new Error(`Invalid character '${o}' in label "${i}"`)}e.push(r)}return e}function z(){return{id:0,qr:0,opcode:0,aa:0,tc:0,rd:0,ra:0,z:0,rcode:0,qdcount:0,ancount:0,nscount:0,arcount:0,questions:[],answers:[],authorityRecords:[],additionalRecords:[]}}function D(t){const n=z();return n.rd=1,n.qdcount+=t.length,n.questions.push(...t),n.arcount+=1,n.additionalRecords.push({name:[],type:41,class:65535,ttl:0,rdlength:0,rdata:[]}),n}function M(t){const n=new ArrayBuffer(1024),e=new DataView(n);let i=0;i=x(e,i,t);for(const r of t.questions)i=j(e,i,r);if(t.answers.length>0||t.authorityRecords.length>0)throw new Error("Cannot serialize answers or authority records for query");for(const r of t.additionalRecords)i=L(e,i,r);return i=$(e,i),n.slice(0,i)}function N(t,n,e){for(const i of e){t.setUint8(n++,i.length);for(const r of i)t.setUint8(n++,r)}return t.setUint8(n++,0),n}function L(t,n,e){n=N(t,n,e.name),t.setUint16(n,e.type),n+=2,t.setUint16(n,e.class),n+=2,t.setUint32(n,e.ttl),n+=4,t.setUint16(n,e.rdlength),n+=2;for(const i of e.rdata)t.setUint8(n++,i);return n}function $(t,n){const e=n+4,i=Math.ceil(e/128)*128-e;t.setUint16(n,12),n+=2,t.setUint16(n,i),n+=2;for(let r=0;r<i;r++)t.setUint8(n++,Math.floor(Math.random()*255));return n}function j(t,n,e){return n=N(t,n,e.qname),t.setUint16(n,e.qtype),n+=2,t.setUint16(n,e.qclass),n+=2,n}function x(t,n,e){return t.setUint16(n,e.id),n+=2,t.setUint16(n,(e.qr&1)<<15|(e.opcode&15)<<11|(e.aa&1)<<10|(e.tc&1)<<9|(e.rd&1)<<8|(e.ra&1)<<7|(e.z&7)<<4|e.rcode&15),n+=2,t.setUint16(4,e.qdcount),n+=2,t.setUint16(6,e.ancount),n+=2,t.setUint16(8,e.nscount),n+=2,t.setUint16(10,e.arcount),n+=2,n}function P(t,n=0){const e=new DataView(t),i=z();return n=F(e,n,i),n=k(e,n,i.qdcount,i.questions),n=R(e,n,i.ancount,i.answers),n=R(e,n,i.nscount,i.authorityRecords),n=R(e,n,i.arcount,i.additionalRecords),n!==t.byteLength&&console.warn(`Unexpected end of message (offset: ${n}, length: ${t.byteLength})`),i}function k(t,n,e,i){for(let r=0;r<e;r++){const o=[];n=w(t,n,o,0);const c=t.getUint16(n);n+=2;const a=t.getUint16(n);n+=2,i.push({qname:o,qtype:c,qclass:a})}return n}function R(t,n,e,i){for(let r=0;r<e;r++){const o=[];n=w(t,n,o,0);const c=t.getUint16(n);n+=2;const a=t.getUint16(n);n+=2;const h=t.getUint32(n);n+=4;const g=t.getUint16(n);n+=2;const b=[];for(let s=0;s<g;s++)b.push(t.getUint8(n++));i.push({name:o,type:c,class:a,ttl:h,rdlength:g,rdata:b})}return n}function w(t,n,e,i=0){if(i>20)throw new Error("Too many nested labels");let r=t.getUint8(n++);for(;r!==0;){const o=r>>6;if(o===0){const c=[];for(let a=0;a<r;a++)c.push(t.getUint8(n++));e.push(c),r=t.getUint8(n++)}else if(o===3){const c=(r&63)<<8|t.getUint8(n++);w(t,c,e,i+1);break}else throw new Error(`Invalid label type: ${o.toString(2)}`)}return n}function F(t,n,e){e.id=t.getUint16(n),n+=2;const i=t.getUint16(n);return n+=2,e.qr=(i&32768)>>15,e.opcode=(i&30720)>>11,e.aa=(i&1024)>>10,e.tc=(i&512)>>9,e.rd=(i&256)>>8,e.ra=(i&128)>>7,e.z=(i&112)>>4,e.rcode=i&15,e.qdcount=t.getUint16(n),n+=2,e.ancount=t.getUint16(n),n+=2,e.nscount=t.getUint16(n),n+=2,e.arcount=t.getUint16(n),n+=2,n}function I(t){return O(t).split(".").map(r=>_(r)?r:"xn--"+W(r)).join(".").toLowerCase()}function O(t){return t.replace(/[.。。]/gu,".").replace(/ẞ/gu,"ß").normalize("NFKC").toLowerCase().replace(/[\uFE00-\uFE0F]/gu,"")}function _(t){return Array.from(t).every(S)}function S(t){return t.charCodeAt(0)<128}const y=36,C=1,E=26,Q=38,B=700,H=72,K=128;function W(t){let n=K,e=0,i=H;const r=[],o=Array.from(t),c=o.filter(S),a=c.length;let h=a;r.push(...c),a>0&&r.push("-");const g=o.map(s=>s.codePointAt(0)),b=g.length;for(;h<b;){let s=Number.MAX_SAFE_INTEGER;for(const U of g)U>=n&&U<s&&(s=U);e+=(s-n)*(h+1),n=s;for(const U of g)if(U<n)e++;else if(U===n){let m=e,q=y;for(;;){let l;if(q<=i?l=C:q>=i+E?l=E:l=q-i,m<l)break;const Z=l+(m-l)%(y-l);r.push(T(Z)),m=p(m-l,y-l),q+=y}r.push(T(m)),i=G(e,h+1,h===a),e=0,h++}e++,n++}return r.join("")}function T(t){return String.fromCharCode(t+22+75*+(t<26))}function p(t,n){return Math.floor(t/n)}function G(t,n,e){e?t=p(t,B):t=p(t,2),t+=p(t,n);let i=0;for(;t>p((y-C)*E,2);)t=p(t,y-C),i+=36;return i+p(36*t,t+Q)}const J="0.0.1";function X(t,n){const e=I(t),i=D([{qname:v(e),qtype:parseInt(n,10),qclass:1}]),r=M(i),o=new URL("https://1.1.1.1/dns-query");return fetch(o,{method:"POST",mode:"cors",headers:{Accept:"application/dns-message","Content-Type":"application/dns-message"},body:r}).then(c=>{if(!c.ok)throw new Error(`Failed to fetch: ${c.status} ${c.statusText}`);return c.arrayBuffer()}).then(c=>{const a=P(c);return Y(a)}).catch(c=>{throw console.error(c),c})}function Y(t){const n={id:t.id,authoritativeAnswer:t.aa===1,truncated:t.tc===1,recursionAvailable:t.ra===1,responseCode:t.rcode===0?"OK":"ERROR",questions:t.questions.map(e=>({name:u(e.qname),type:e.qtype})),answers:t.answers.map(e=>({name:u(e.name),type:e.type,ttl:e.ttl,value:A(e.type,e.rdata)})),authorityRecords:t.authorityRecords.map(e=>({name:u(e.name),type:e.type,ttl:e.ttl,value:A(e.type,e.rdata)})),additionalRecords:t.additionalRecords.map(e=>({name:u(e.name),type:e.type,ttl:e.ttl,value:A(e.type,e.rdata)}))};return JSON.stringify(n,null,2)}function A(t,n){switch(t){case 1:return n.join(".");case 28:return n.map(e=>e.toString(16)).join(":");default:return n}}d.resolve=X,d.version=J,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
1
+ (function(d,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(d=typeof globalThis<"u"?globalThis:d||self,u(d["universal-doh"]={}))})(this,function(d){"use strict";function u(t){return t.map(n=>String.fromCharCode(...n)).join(".")}function v(t){const n=t.split(".").filter(i=>i.length>0),e=[];for(const i of n){if(i.length<1||i.length>63)throw new Error(`Label "${i}" must be between 1 and 63 characters long`);if(i.startsWith("-")||i.endsWith("-"))throw new Error(`Label "${i}" cannot start or end with a hyphen`);const r=[];for(const o of i){const c=o.charCodeAt(0);if(c>=48&&c<=57||c>=97&&c<=122||c===45)r.push(c);else throw new Error(`Invalid character '${o}' in label "${i}"`)}e.push(r)}return e}function z(){return{id:0,qr:0,opcode:0,aa:0,tc:0,rd:0,ra:0,z:0,rcode:0,qdcount:0,ancount:0,nscount:0,arcount:0,questions:[],answers:[],authorityRecords:[],additionalRecords:[]}}function D(t){const n=z();return n.rd=1,n.qdcount+=t.length,n.questions.push(...t),n.arcount+=1,n.additionalRecords.push({name:[],type:41,class:65535,ttl:0,rdlength:0,rdata:[]}),n}function M(t){const n=new ArrayBuffer(1024),e=new DataView(n);let i=0;i=x(e,i,t);for(const r of t.questions)i=j(e,i,r);if(t.answers.length>0||t.authorityRecords.length>0)throw new Error("Cannot serialize answers or authority records for query");for(const r of t.additionalRecords)i=L(e,i,r);return i=$(e,i),n.slice(0,i)}function N(t,n,e){for(const i of e){t.setUint8(n++,i.length);for(const r of i)t.setUint8(n++,r)}return t.setUint8(n++,0),n}function L(t,n,e){n=N(t,n,e.name),t.setUint16(n,e.type),n+=2,t.setUint16(n,e.class),n+=2,t.setUint32(n,e.ttl),n+=4,t.setUint16(n,e.rdlength),n+=2;for(const i of e.rdata)t.setUint8(n++,i);return n}function $(t,n){const e=n+4,i=Math.ceil(e/128)*128-e;t.setUint16(n,12),n+=2,t.setUint16(n,i),n+=2;for(let r=0;r<i;r++)t.setUint8(n++,Math.floor(Math.random()*255));return n}function j(t,n,e){return n=N(t,n,e.qname),t.setUint16(n,e.qtype),n+=2,t.setUint16(n,e.qclass),n+=2,n}function x(t,n,e){return t.setUint16(n,e.id),n+=2,t.setUint16(n,(e.qr&1)<<15|(e.opcode&15)<<11|(e.aa&1)<<10|(e.tc&1)<<9|(e.rd&1)<<8|(e.ra&1)<<7|(e.z&7)<<4|e.rcode&15),n+=2,t.setUint16(4,e.qdcount),n+=2,t.setUint16(6,e.ancount),n+=2,t.setUint16(8,e.nscount),n+=2,t.setUint16(10,e.arcount),n+=2,n}function P(t,n=0){const e=new DataView(t),i=z();return n=F(e,n,i),n=k(e,n,i.qdcount,i.questions),n=R(e,n,i.ancount,i.answers),n=R(e,n,i.nscount,i.authorityRecords),n=R(e,n,i.arcount,i.additionalRecords),n!==t.byteLength&&console.warn(`Unexpected end of message (offset: ${n}, length: ${t.byteLength})`),i}function k(t,n,e,i){for(let r=0;r<e;r++){const o=[];n=w(t,n,o,0);const c=t.getUint16(n);n+=2;const a=t.getUint16(n);n+=2,i.push({qname:o,qtype:c,qclass:a})}return n}function R(t,n,e,i){for(let r=0;r<e;r++){const o=[];n=w(t,n,o,0);const c=t.getUint16(n);n+=2;const a=t.getUint16(n);n+=2;const h=t.getUint32(n);n+=4;const g=t.getUint16(n);n+=2;const b=[];for(let s=0;s<g;s++)b.push(t.getUint8(n++));i.push({name:o,type:c,class:a,ttl:h,rdlength:g,rdata:b})}return n}function w(t,n,e,i=0){if(i>20)throw new Error("Too many nested labels");let r=t.getUint8(n++);for(;r!==0;){const o=r>>6;if(o===0){const c=[];for(let a=0;a<r;a++)c.push(t.getUint8(n++));e.push(c),r=t.getUint8(n++)}else if(o===3){const c=(r&63)<<8|t.getUint8(n++);w(t,c,e,i+1);break}else throw new Error(`Invalid label type: ${o.toString(2)}`)}return n}function F(t,n,e){e.id=t.getUint16(n),n+=2;const i=t.getUint16(n);return n+=2,e.qr=(i&32768)>>15,e.opcode=(i&30720)>>11,e.aa=(i&1024)>>10,e.tc=(i&512)>>9,e.rd=(i&256)>>8,e.ra=(i&128)>>7,e.z=(i&112)>>4,e.rcode=i&15,e.qdcount=t.getUint16(n),n+=2,e.ancount=t.getUint16(n),n+=2,e.nscount=t.getUint16(n),n+=2,e.arcount=t.getUint16(n),n+=2,n}function I(t){return O(t).split(".").map(r=>_(r)?r:"xn--"+W(r)).join(".").toLowerCase()}function O(t){return t.replace(/[.。。]/gu,".").replace(/ẞ/gu,"ß").normalize("NFKC").toLowerCase().replace(/[\uFE00-\uFE0F]/gu,"")}function _(t){return Array.from(t).every(S)}function S(t){return t.charCodeAt(0)<128}const y=36,C=1,E=26,Q=38,B=700,H=72,K=128;function W(t){let n=K,e=0,i=H;const r=[],o=Array.from(t),c=o.filter(S),a=c.length;let h=a;r.push(...c),a>0&&r.push("-");const g=o.map(s=>s.codePointAt(0)),b=g.length;for(;h<b;){let s=Number.MAX_SAFE_INTEGER;for(const U of g)U>=n&&U<s&&(s=U);e+=(s-n)*(h+1),n=s;for(const U of g)if(U<n)e++;else if(U===n){let m=e,q=y;for(;;){let l;if(q<=i?l=C:q>=i+E?l=E:l=q-i,m<l)break;const Z=l+(m-l)%(y-l);r.push(T(Z)),m=p(m-l,y-l),q+=y}r.push(T(m)),i=G(e,h+1,h===a),e=0,h++}e++,n++}return r.join("")}function T(t){return String.fromCharCode(t+22+75*+(t<26))}function p(t,n){return Math.floor(t/n)}function G(t,n,e){e?t=p(t,B):t=p(t,2),t+=p(t,n);let i=0;for(;t>p((y-C)*E,2);)t=p(t,y-C),i+=36;return i+p(36*t,t+Q)}const J="0.0.2";function X(t,n){const e=I(t),i=D([{qname:v(e),qtype:parseInt(n,10),qclass:1}]),r=M(i),o=new URL("https://1.1.1.1/dns-query");return fetch(o,{method:"POST",mode:"cors",headers:{Accept:"application/dns-message","Content-Type":"application/dns-message"},body:r}).then(c=>{if(!c.ok)throw new Error(`Failed to fetch: ${c.status} ${c.statusText}`);return c.arrayBuffer()}).then(c=>{const a=P(c);return Y(a)}).catch(c=>{throw console.error(c),c})}function Y(t){const n={id:t.id,authoritativeAnswer:t.aa===1,truncated:t.tc===1,recursionAvailable:t.ra===1,responseCode:t.rcode===0?"OK":"ERROR",questions:t.questions.map(e=>({name:u(e.qname),type:e.qtype})),answers:t.answers.map(e=>({name:u(e.name),type:e.type,ttl:e.ttl,value:A(e.type,e.rdata)})),authorityRecords:t.authorityRecords.map(e=>({name:u(e.name),type:e.type,ttl:e.ttl,value:A(e.type,e.rdata)})),additionalRecords:t.additionalRecords.map(e=>({name:u(e.name),type:e.type,ttl:e.ttl,value:A(e.type,e.rdata)}))};return JSON.stringify(n,null,2)}function A(t,n){switch(t){case 1:return n.join(".");case 28:return n.map(e=>e.toString(16)).join(":");default:return n}}d.resolve=X,d.version=J,Object.defineProperty(d,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,20 +1,48 @@
1
1
  {
2
2
  "name": "universal-doh",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "DNS over HTTPS universal TypeScript library",
5
+ "keywords": [
6
+ "universal-doh",
7
+ "dns",
8
+ "dns-over-https",
9
+ "doh",
10
+ "dns-client",
11
+ "dns-resolver",
12
+ "typescript",
13
+ "nodejs",
14
+ "browser",
15
+ "web-workers",
16
+ "cloudflare-workers",
17
+ "bun",
18
+ "universal",
19
+ "idn",
20
+ "punycode",
21
+ "async-dns",
22
+ "dns-lookup",
23
+ "dns-query",
24
+ "cloudflare-dns",
25
+ "google-dns",
26
+ "quad9-dns"
27
+ ],
5
28
  "author": {
6
29
  "name": "Wojciech Malinowski"
7
30
  },
8
31
  "license": "MIT",
32
+ "homepage": "https://wmalinowski.github.io/universal-doh/",
9
33
  "repository": {
10
34
  "type": "git",
11
35
  "url": "git+https://github.com/wmalinowski/universal-doh.git"
12
36
  },
37
+ "bugs": {
38
+ "url": "https://github.com/wmalinowski/universal-doh/issues"
39
+ },
13
40
  "type": "module",
14
41
  "files": [
15
42
  "dist"
16
43
  ],
17
44
  "main": "dist/universal-doh.umd.cjs",
45
+ "browser": "dist/universal-doh.umd.cjs",
18
46
  "module": "dist/universal-doh.js",
19
47
  "types": "dist/universal-doh.d.ts",
20
48
  "exports": {