@multiformats/dns
Version:
Resolve DNS queries with browser fallback
4 lines (3 loc) • 28.9 kB
JavaScript
(function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.MultiformatsDns = factory()}(typeof self !== 'undefined' ? self : this, function () {
"use strict";var MultiformatsDns=(()=>{var pt=Object.create;var G=Object.defineProperty;var mt=Object.getOwnPropertyDescriptor;var bt=Object.getOwnPropertyNames;var xt=Object.getPrototypeOf,yt=Object.prototype.hasOwnProperty;var ze=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),y=(r,e)=>{for(var t in e)G(r,t,{get:e[t],enumerable:!0})},Pe=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of bt(e))!yt.call(r,o)&&o!==t&&G(r,o,{get:()=>e[o],enumerable:!(n=mt(e,o))||n.enumerable});return r};var Le=(r,e,t)=>(t=r!=null?pt(xt(r)):{},Pe(e||!r||!r.__esModule?G(t,"default",{value:r,enumerable:!0}):t,r)),wt=r=>Pe(G({},"__esModule",{value:!0}),r);var $e=ze((Mr,re)=>{"use strict";var gt=Object.prototype.hasOwnProperty,b="~";function B(){}Object.create&&(B.prototype=Object.create(null),new B().__proto__||(b=!1));function vt(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function _e(r,e,t,n,o){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new vt(t,n||r,o),i=b?b+e:e;return r._events[i]?r._events[i].fn?r._events[i]=[r._events[i],s]:r._events[i].push(s):(r._events[i]=s,r._eventsCount++),r}function K(r,e){--r._eventsCount===0?r._events=new B:delete r._events[e]}function p(){this._events=new B,this._eventsCount=0}p.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)gt.call(t,n)&&e.push(b?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};p.prototype.listeners=function(e){var t=b?b+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var o=0,s=n.length,i=new Array(s);o<s;o++)i[o]=n[o].fn;return i};p.prototype.listenerCount=function(e){var t=b?b+e:e,n=this._events[t];return n?n.fn?1:n.length:0};p.prototype.emit=function(e,t,n,o,s,i){var c=b?b+e:e;if(!this._events[c])return!1;var a=this._events[c],h=arguments.length,f,u;if(a.fn){switch(a.once&&this.removeListener(e,a.fn,void 0,!0),h){case 1:return a.fn.call(a.context),!0;case 2:return a.fn.call(a.context,t),!0;case 3:return a.fn.call(a.context,t,n),!0;case 4:return a.fn.call(a.context,t,n,o),!0;case 5:return a.fn.call(a.context,t,n,o,s),!0;case 6:return a.fn.call(a.context,t,n,o,s,i),!0}for(u=1,f=new Array(h-1);u<h;u++)f[u-1]=arguments[u];a.fn.apply(a.context,f)}else{var m=a.length,z;for(u=0;u<m;u++)switch(a[u].once&&this.removeListener(e,a[u].fn,void 0,!0),h){case 1:a[u].fn.call(a[u].context);break;case 2:a[u].fn.call(a[u].context,t);break;case 3:a[u].fn.call(a[u].context,t,n);break;case 4:a[u].fn.call(a[u].context,t,n,o);break;default:if(!f)for(z=1,f=new Array(h-1);z<h;z++)f[z-1]=arguments[z];a[u].fn.apply(a[u].context,f)}}return!0};p.prototype.on=function(e,t,n){return _e(this,e,t,n,!1)};p.prototype.once=function(e,t,n){return _e(this,e,t,n,!0)};p.prototype.removeListener=function(e,t,n,o){var s=b?b+e:e;if(!this._events[s])return this;if(!t)return K(this,s),this;var i=this._events[s];if(i.fn)i.fn===t&&(!o||i.once)&&(!n||i.context===n)&&K(this,s);else{for(var c=0,a=[],h=i.length;c<h;c++)(i[c].fn!==t||o&&!i[c].once||n&&i[c].context!==n)&&a.push(i[c]);a.length?this._events[s]=a.length===1?a[0]:a:K(this,s)}return this};p.prototype.removeAllListeners=function(e){var t;return e?(t=b?b+e:e,this._events[t]&&K(this,t)):(this._events=new B,this._eventsCount=0),this};p.prototype.off=p.prototype.removeListener;p.prototype.addListener=p.prototype.on;p.prefixed=b;p.EventEmitter=p;typeof re<"u"&&(re.exports=p)});var ht=ze((jn,ut)=>{ut.exports=function(r){if(!r)throw Error("hashlru must have a max value, of type number, greater than 0");var e=0,t=Object.create(null),n=Object.create(null);function o(s,i){t[s]=i,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(s){return t[s]!==void 0||n[s]!==void 0},remove:function(s){t[s]!==void 0&&(t[s]=void 0),n[s]!==void 0&&(n[s]=void 0)},get:function(s){var i=t[s];if(i!==void 0)return i;if((i=n[s])!==void 0)return o(s,i),i},set:function(s,i){t[s]!==void 0?t[s]=i:o(s,i)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Lr={};y(Lr,{MAX_RECURSIVE_DEPTH:()=>zr,RecordType:()=>g,dns:()=>Pr});var N=class extends Event{constructor(e,t){super(e),this.detail=t}};var ne=Le($e(),1);var F=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},oe=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Me=r=>globalThis.DOMException===void 0?new oe(r):new DOMException(r),Re=r=>{let e=r.reason===void 0?Me("This operation was aborted."):r.reason;return e instanceof Error?e:Me(e)};function se(r,e){let{milliseconds:t,fallback:n,message:o,customTimers:s={setTimeout,clearTimeout}}=e,i,a=new Promise((h,f)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(e.signal){let{signal:m}=e;m.aborted&&f(Re(m)),m.addEventListener("abort",()=>{f(Re(m))})}if(t===Number.POSITIVE_INFINITY){r.then(h,f);return}let u=new F;i=s.setTimeout.call(void 0,()=>{if(n){try{h(n())}catch(m){f(m)}return}typeof r.cancel=="function"&&r.cancel(),o===!1?h():o instanceof Error?f(o):(u.message=o??`Promise timed out after ${t} milliseconds`,f(u))},t),(async()=>{try{h(await r)}catch(m){f(m)}})()}).finally(()=>{a.clear()});return a.clear=()=>{s.clearTimeout.call(void 0,i),i=void 0},a}function ie(r,e,t){let n=0,o=r.length;for(;o>0;){let s=Math.trunc(o/2),i=n+s;t(r[i],e)<=0?(n=++i,o-=s+1):o=s}return n}var V=class{#e=[];enqueue(e,t){t={priority:0,...t};let n={priority:t.priority,run:e};if(this.size&&this.#e[this.size-1].priority>=t.priority){this.#e.push(n);return}let o=ie(this.#e,n,(s,i)=>i.priority-s.priority);this.#e.splice(o,0,n)}dequeue(){return this.#e.shift()?.run}filter(e){return this.#e.filter(t=>t.priority===e.priority).map(t=>t.run)}get size(){return this.#e.length}};var k=class extends ne.default{#e;#i;#s=0;#l;#a;#p=0;#r;#c;#t;#m;#n=0;#f;#o;#b;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:V,...e},!(typeof e.intervalCap=="number"&&e.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${e.intervalCap?.toString()??""}\` (${typeof e.intervalCap})`);if(e.interval===void 0||!(Number.isFinite(e.interval)&&e.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${e.interval?.toString()??""}\` (${typeof e.interval})`);this.#e=e.carryoverConcurrencyCount,this.#i=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#l=e.intervalCap,this.#a=e.interval,this.#t=new e.queueClass,this.#m=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#b=e.throwOnTimeout===!0,this.#o=e.autoStart===!1}get#w(){return this.#i||this.#s<this.#l}get#g(){return this.#n<this.#f}#v(){this.#n--,this.#u(),this.emit("next")}#E(){this.#y(),this.#x(),this.#c=void 0}get#A(){let e=Date.now();if(this.#r===void 0){let t=this.#p-e;if(t<0)this.#s=this.#e?this.#n:0;else return this.#c===void 0&&(this.#c=setTimeout(()=>{this.#E()},t)),!0}return!1}#u(){if(this.#t.size===0)return this.#r&&clearInterval(this.#r),this.#r=void 0,this.emit("empty"),this.#n===0&&this.emit("idle"),!1;if(!this.#o){let e=!this.#A;if(this.#w&&this.#g){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#x(),!0):!1}}return!1}#x(){this.#i||this.#r!==void 0||(this.#r=setInterval(()=>{this.#y()},this.#a),this.#p=Date.now()+this.#a)}#y(){this.#s===0&&this.#n===0&&this.#r&&(clearInterval(this.#r),this.#r=void 0),this.#s=this.#e?this.#n:0,this.#h()}#h(){for(;this.#u(););}get concurrency(){return this.#f}set concurrency(e){if(!(typeof e=="number"&&e>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${e}\` (${typeof e})`);this.#f=e,this.#h()}async#C(e){return new Promise((t,n)=>{e.addEventListener("abort",()=>{n(e.reason)},{once:!0})})}async add(e,t={}){return t={timeout:this.timeout,throwOnTimeout:this.#b,...t},new Promise((n,o)=>{this.#t.enqueue(async()=>{this.#n++,this.#s++;try{t.signal?.throwIfAborted();let s=e({signal:t.signal});t.timeout&&(s=se(Promise.resolve(s),{milliseconds:t.timeout})),t.signal&&(s=Promise.race([s,this.#C(t.signal)]));let i=await s;n(i),this.emit("completed",i)}catch(s){if(s instanceof F&&!t.throwOnTimeout){n();return}o(s),this.emit("error",s)}finally{this.#v()}},t),this.emit("add"),this.#u()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#o?(this.#o=!1,this.#h(),this):this}pause(){this.#o=!0}clear(){this.#t=new this.#m}async onEmpty(){this.#t.size!==0&&await this.#d("empty")}async onSizeLessThan(e){this.#t.size<e||await this.#d("next",()=>this.#t.size<e)}async onIdle(){this.#n===0&&this.#t.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let o=()=>{t&&!t()||(this.off(e,o),n())};this.on(e,o)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#o}};function W(r){let e=[g.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var he={};y(he,{base10:()=>Dt});var Gr=new Uint8Array(0);function qe(r,e){if(r===e)return!0;if(r.byteLength!==e.byteLength)return!1;for(let t=0;t<r.byteLength;t++)if(r[t]!==e[t])return!1;return!0}function I(r){if(r instanceof Uint8Array&&r.constructor.name==="Uint8Array")return r;if(r instanceof ArrayBuffer)return new Uint8Array(r);if(ArrayBuffer.isView(r))return new Uint8Array(r.buffer,r.byteOffset,r.byteLength);throw new Error("Unknown type, must be binary type")}function Be(r){return new TextEncoder().encode(r)}function Fe(r){return new TextDecoder().decode(r)}function Et(r,e){if(r.length>=255)throw new TypeError("Alphabet too long");for(var t=new Uint8Array(256),n=0;n<t.length;n++)t[n]=255;for(var o=0;o<r.length;o++){var s=r.charAt(o),i=s.charCodeAt(0);if(t[i]!==255)throw new TypeError(s+" is ambiguous");t[i]=o}var c=r.length,a=r.charAt(0),h=Math.log(c)/Math.log(256),f=Math.log(256)/Math.log(c);function u(d){if(d instanceof Uint8Array||(ArrayBuffer.isView(d)?d=new Uint8Array(d.buffer,d.byteOffset,d.byteLength):Array.isArray(d)&&(d=Uint8Array.from(d))),!(d instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(d.length===0)return"";for(var x=0,P=0,v=0,A=d.length;v!==A&&d[v]===0;)v++,x++;for(var C=(A-v)*f+1>>>0,w=new Uint8Array(C);v!==A;){for(var T=d[v],U=0,E=C-1;(T!==0||U<P)&&E!==-1;E--,U++)T+=256*w[E]>>>0,w[E]=T%c>>>0,T=T/c>>>0;if(T!==0)throw new Error("Non-zero carry");P=U,v++}for(var D=C-P;D!==C&&w[D]===0;)D++;for(var H=a.repeat(x);D<C;++D)H+=r.charAt(w[D]);return H}function m(d){if(typeof d!="string")throw new TypeError("Expected String");if(d.length===0)return new Uint8Array;var x=0;if(d[x]!==" "){for(var P=0,v=0;d[x]===a;)P++,x++;for(var A=(d.length-x)*h+1>>>0,C=new Uint8Array(A);d[x];){var w=t[d.charCodeAt(x)];if(w===255)return;for(var T=0,U=A-1;(w!==0||T<v)&&U!==-1;U--,T++)w+=c*C[U]>>>0,C[U]=w%256>>>0,w=w/256>>>0;if(w!==0)throw new Error("Non-zero carry");v=T,x++}if(d[x]!==" "){for(var E=A-v;E!==A&&C[E]===0;)E++;for(var D=new Uint8Array(P+(A-E)),H=P;E!==A;)D[H++]=C[E++];return D}}}function z(d){var x=m(d);if(x)return x;throw new Error(`Non-${e} character`)}return{encode:u,decodeUnsafe:m,decode:z}}var At=Et,Ct=At,ke=Ct;var ae=class{name;prefix;baseEncode;constructor(e,t,n){this.name=e,this.prefix=t,this.baseEncode=n}encode(e){if(e instanceof Uint8Array)return`${this.prefix}${this.baseEncode(e)}`;throw Error("Unknown type, must be binary type")}},ce=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){if(this.name=e,this.prefix=t,t.codePointAt(0)===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=t.codePointAt(0),this.baseDecode=n}decode(e){if(typeof e=="string"){if(e.codePointAt(0)!==this.prefixCodePoint)throw Error(`Unable to decode multibase string ${JSON.stringify(e)}, ${this.name} decoder only supports inputs prefixed with ${this.prefix}`);return this.baseDecode(e.slice(this.prefix.length))}else throw Error("Can only multibase decode strings")}or(e){return Je(this,e)}},fe=class{decoders;constructor(e){this.decoders=e}or(e){return Je(this,e)}decode(e){let t=e[0],n=this.decoders[t];if(n!=null)return n.decode(e);throw RangeError(`Unable to decode multibase string ${JSON.stringify(e)}, only inputs prefixed with ${Object.keys(this.decoders)} are supported`)}};function Je(r,e){return new fe({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var ue=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,o){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=o,this.encoder=new ae(e,t,n),this.decoder=new ce(e,t,o)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function _({name:r,prefix:e,encode:t,decode:n}){return new ue(r,e,t,n)}function O({name:r,prefix:e,alphabet:t}){let{encode:n,decode:o}=ke(t,r);return _({prefix:e,name:r,encode:n,decode:s=>I(o(s))})}function Tt(r,e,t,n){let o={};for(let f=0;f<e.length;++f)o[e[f]]=f;let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),c=0,a=0,h=0;for(let f=0;f<s;++f){let u=o[r[f]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);a=a<<t|u,c+=t,c>=8&&(c-=8,i[h++]=255&a>>c)}if(c>=t||255&a<<8-c)throw new SyntaxError("Unexpected end of data");return i}function St(r,e,t){let n=e[e.length-1]==="=",o=(1<<t)-1,s="",i=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],i+=8;i>t;)i-=t,s+=e[o&c>>i];if(i!==0&&(s+=e[o&c<<t-i]),n)for(;s.length*t&7;)s+="=";return s}function l({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return _({prefix:e,name:r,encode(o){return St(o,n,t)},decode(o){return Tt(o,n,t,r)}})}var Dt=O({prefix:"9",name:"base10",alphabet:"0123456789"});var de={};y(de,{base16:()=>It,base16upper:()=>Ut});var It=l({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),Ut=l({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var le={};y(le,{base2:()=>Nt});var Nt=l({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var pe={};y(pe,{base256emoji:()=>_t});var Qe=Array.from("\u{1F680}\u{1FA90}\u2604\u{1F6F0}\u{1F30C}\u{1F311}\u{1F312}\u{1F313}\u{1F314}\u{1F315}\u{1F316}\u{1F317}\u{1F318}\u{1F30D}\u{1F30F}\u{1F30E}\u{1F409}\u2600\u{1F4BB}\u{1F5A5}\u{1F4BE}\u{1F4BF}\u{1F602}\u2764\u{1F60D}\u{1F923}\u{1F60A}\u{1F64F}\u{1F495}\u{1F62D}\u{1F618}\u{1F44D}\u{1F605}\u{1F44F}\u{1F601}\u{1F525}\u{1F970}\u{1F494}\u{1F496}\u{1F499}\u{1F622}\u{1F914}\u{1F606}\u{1F644}\u{1F4AA}\u{1F609}\u263A\u{1F44C}\u{1F917}\u{1F49C}\u{1F614}\u{1F60E}\u{1F607}\u{1F339}\u{1F926}\u{1F389}\u{1F49E}\u270C\u2728\u{1F937}\u{1F631}\u{1F60C}\u{1F338}\u{1F64C}\u{1F60B}\u{1F497}\u{1F49A}\u{1F60F}\u{1F49B}\u{1F642}\u{1F493}\u{1F929}\u{1F604}\u{1F600}\u{1F5A4}\u{1F603}\u{1F4AF}\u{1F648}\u{1F447}\u{1F3B6}\u{1F612}\u{1F92D}\u2763\u{1F61C}\u{1F48B}\u{1F440}\u{1F62A}\u{1F611}\u{1F4A5}\u{1F64B}\u{1F61E}\u{1F629}\u{1F621}\u{1F92A}\u{1F44A}\u{1F973}\u{1F625}\u{1F924}\u{1F449}\u{1F483}\u{1F633}\u270B\u{1F61A}\u{1F61D}\u{1F634}\u{1F31F}\u{1F62C}\u{1F643}\u{1F340}\u{1F337}\u{1F63B}\u{1F613}\u2B50\u2705\u{1F97A}\u{1F308}\u{1F608}\u{1F918}\u{1F4A6}\u2714\u{1F623}\u{1F3C3}\u{1F490}\u2639\u{1F38A}\u{1F498}\u{1F620}\u261D\u{1F615}\u{1F33A}\u{1F382}\u{1F33B}\u{1F610}\u{1F595}\u{1F49D}\u{1F64A}\u{1F639}\u{1F5E3}\u{1F4AB}\u{1F480}\u{1F451}\u{1F3B5}\u{1F91E}\u{1F61B}\u{1F534}\u{1F624}\u{1F33C}\u{1F62B}\u26BD\u{1F919}\u2615\u{1F3C6}\u{1F92B}\u{1F448}\u{1F62E}\u{1F646}\u{1F37B}\u{1F343}\u{1F436}\u{1F481}\u{1F632}\u{1F33F}\u{1F9E1}\u{1F381}\u26A1\u{1F31E}\u{1F388}\u274C\u270A\u{1F44B}\u{1F630}\u{1F928}\u{1F636}\u{1F91D}\u{1F6B6}\u{1F4B0}\u{1F353}\u{1F4A2}\u{1F91F}\u{1F641}\u{1F6A8}\u{1F4A8}\u{1F92C}\u2708\u{1F380}\u{1F37A}\u{1F913}\u{1F619}\u{1F49F}\u{1F331}\u{1F616}\u{1F476}\u{1F974}\u25B6\u27A1\u2753\u{1F48E}\u{1F4B8}\u2B07\u{1F628}\u{1F31A}\u{1F98B}\u{1F637}\u{1F57A}\u26A0\u{1F645}\u{1F61F}\u{1F635}\u{1F44E}\u{1F932}\u{1F920}\u{1F927}\u{1F4CC}\u{1F535}\u{1F485}\u{1F9D0}\u{1F43E}\u{1F352}\u{1F617}\u{1F911}\u{1F30A}\u{1F92F}\u{1F437}\u260E\u{1F4A7}\u{1F62F}\u{1F486}\u{1F446}\u{1F3A4}\u{1F647}\u{1F351}\u2744\u{1F334}\u{1F4A3}\u{1F438}\u{1F48C}\u{1F4CD}\u{1F940}\u{1F922}\u{1F445}\u{1F4A1}\u{1F4A9}\u{1F450}\u{1F4F8}\u{1F47B}\u{1F910}\u{1F92E}\u{1F3BC}\u{1F975}\u{1F6A9}\u{1F34E}\u{1F34A}\u{1F47C}\u{1F48D}\u{1F4E3}\u{1F942}"),Ot=Qe.reduce((r,e,t)=>(r[t]=e,r),[]),zt=Qe.reduce((r,e,t)=>(r[e.codePointAt(0)]=t,r),[]);function Pt(r){return r.reduce((e,t)=>(e+=Ot[t],e),"")}function Lt(r){let e=[];for(let t of r){let n=zt[t.codePointAt(0)];if(n===void 0)throw new Error(`Non-base256emoji character: ${t}`);e.push(n)}return new Uint8Array(e)}var _t=_({prefix:"\u{1F680}",name:"base256emoji",encode:Pt,decode:Lt});var me={};y(me,{base32:()=>$,base32hex:()=>qt,base32hexpad:()=>Ft,base32hexpadupper:()=>Vt,base32hexupper:()=>Bt,base32pad:()=>Mt,base32padupper:()=>Rt,base32upper:()=>$t,base32z:()=>kt});var $=l({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),$t=l({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),Mt=l({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),Rt=l({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),qt=l({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),Bt=l({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),Ft=l({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),Vt=l({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),kt=l({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var be={};y(be,{base36:()=>Jt,base36upper:()=>Qt});var Jt=O({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),Qt=O({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var xe={};y(xe,{base58btc:()=>S,base58flickr:()=>Xt});var S=O({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),Xt=O({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var ye={};y(ye,{base64:()=>Yt,base64pad:()=>Ht,base64url:()=>Gt,base64urlpad:()=>Kt});var Yt=l({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),Ht=l({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),Gt=l({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),Kt=l({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var we={};y(we,{base8:()=>Wt});var Wt=l({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var ge={};y(ge,{identity:()=>Zt});var Zt=_({prefix:"\0",name:"identity",encode:r=>Fe(r),decode:r=>Be(r)});var dn=new TextEncoder,ln=new TextDecoder;var Ee={};y(Ee,{identity:()=>vr});var tr=He,Xe=128,rr=127,nr=~rr,or=Math.pow(2,31);function He(r,e,t){e=e||[],t=t||0;for(var n=t;r>=or;)e[t++]=r&255|Xe,r/=128;for(;r&nr;)e[t++]=r&255|Xe,r>>>=7;return e[t]=r|0,He.bytes=t-n+1,e}var sr=ve,ir=128,Ye=127;function ve(r,n){var t=0,n=n||0,o=0,s=n,i,c=r.length;do{if(s>=c)throw ve.bytes=0,new RangeError("Could not decode varint");i=r[s++],t+=o<28?(i&Ye)<<o:(i&Ye)*Math.pow(2,o),o+=7}while(i>=ir);return ve.bytes=s-n,t}var ar=Math.pow(2,7),cr=Math.pow(2,14),fr=Math.pow(2,21),ur=Math.pow(2,28),hr=Math.pow(2,35),dr=Math.pow(2,42),lr=Math.pow(2,49),pr=Math.pow(2,56),mr=Math.pow(2,63),br=function(r){return r<ar?1:r<cr?2:r<fr?3:r<ur?4:r<hr?5:r<dr?6:r<lr?7:r<pr?8:r<mr?9:10},xr={encode:tr,decode:sr,encodingLength:br},yr=xr,J=yr;function Q(r,e=0){return[J.decode(r,e),J.decode.bytes]}function M(r,e,t=0){return J.encode(r,e,t),e}function R(r){return J.encodingLength(r)}function L(r,e){let t=e.byteLength,n=R(r),o=n+R(t),s=new Uint8Array(o+t);return M(r,s,0),M(t,s,n),s.set(e,o),new q(r,t,e,s)}function Ge(r){let e=I(r),[t,n]=Q(e),[o,s]=Q(e.subarray(n)),i=e.subarray(n+s);if(i.byteLength!==o)throw new Error("Incorrect length");return new q(t,o,i,e)}function Ke(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&qe(r.bytes,t.bytes)}}var q=class{code;size;digest;bytes;constructor(e,t,n,o){this.code=e,this.size=t,this.digest=n,this.bytes=o}};var We=0,wr="identity",Ze=I;function gr(r){return L(We,Ze(r))}var vr={code:We,name:wr,encode:Ze,digest:gr};var Te={};y(Te,{sha256:()=>Er,sha512:()=>Ar});function Ce({name:r,code:e,encode:t}){return new Ae(r,e,t)}var Ae=class{name;code;encode;constructor(e,t,n){this.name=e,this.code=t,this.encode=n}digest(e){if(e instanceof Uint8Array){let t=this.encode(e);return t instanceof Uint8Array?L(this.code,t):t.then(n=>L(this.code,n))}else throw Error("Unknown type, must be binary type")}};function et(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Er=Ce({name:"sha2-256",code:18,encode:et("SHA-256")}),Ar=Ce({name:"sha2-512",code:19,encode:et("SHA-512")});function tt(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return Tr(t,Se(r),e??S.encoder);default:return Sr(t,Se(r),e??$.encoder)}}var rt=new WeakMap;function Se(r){let e=rt.get(r);if(e==null){let t=new Map;return rt.set(r,t),t}return e}var j=class r{code;version;multihash;bytes;"/";constructor(e,t,n,o){this.code=t,this.version=e,this.multihash=n,this.bytes=o,this["/"]=o}get asCID(){return this}get byteOffset(){return this.bytes.byteOffset}get byteLength(){return this.bytes.byteLength}toV0(){switch(this.version){case 0:return this;case 1:{let{code:e,multihash:t}=this;if(e!==Y)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==Dr)throw new Error("Cannot convert non sha2-256 multihash CID to CIDv0");return r.createV0(t)}default:throw Error(`Can not convert CID version ${this.version} to version 0. This is a bug please report`)}}toV1(){switch(this.version){case 0:{let{code:e,digest:t}=this.multihash,n=L(e,t);return r.createV1(this.code,n)}case 1:return this;default:throw Error(`Can not convert CID version ${this.version} to version 1. This is a bug please report`)}}equals(e){return r.equals(this,e)}static equals(e,t){let n=t;return n!=null&&e.code===n.code&&e.version===n.version&&Ke(e.multihash,n.multihash)}toString(e){return tt(this,e)}toJSON(){return{"/":tt(this)}}link(){return this}[Symbol.toStringTag]="CID";[Symbol.for("nodejs.util.inspect.custom")](){return`CID(${this.toString()})`}static asCID(e){if(e==null)return null;let t=e;if(t instanceof r)return t;if(t["/"]!=null&&t["/"]===t.bytes||t.asCID===t){let{version:n,code:o,multihash:s,bytes:i}=t;return new r(n,o,s,i??nt(n,o,s.bytes))}else if(t[Ir]===!0){let{version:n,multihash:o,code:s}=t,i=Ge(o);return r.create(n,s,i)}else return null}static create(e,t,n){if(typeof t!="number")throw new Error("String codecs are no longer supported");if(!(n.bytes instanceof Uint8Array))throw new Error("Invalid digest");switch(e){case 0:{if(t!==Y)throw new Error(`Version 0 CID must use dag-pb (code: ${Y}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let o=nt(e,t,n.bytes);return new r(e,t,n,o)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,Y,e)}static createV1(e,t){return r.create(1,e,t)}static decode(e){let[t,n]=r.decodeFirst(e);if(n.length!==0)throw new Error("Incorrect length");return t}static decodeFirst(e){let t=r.inspectBytes(e),n=t.size-t.multihashSize,o=I(e.subarray(n,n+t.multihashSize));if(o.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=o.subarray(t.multihashSize-t.digestSize),i=new q(t.multihashCode,t.digestSize,s,o);return[t.version===0?r.createV0(i):r.createV1(t.codec,i),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[u,m]=Q(e.subarray(t));return t+=m,u},o=n(),s=Y;if(o===18?(o=0,t=0):s=n(),o!==0&&o!==1)throw new RangeError(`Invalid CID version ${o}`);let i=t,c=n(),a=n(),h=t+a,f=h-i;return{version:o,codec:s,multihashCode:c,digestSize:a,multihashSize:f,size:h}}static parse(e,t){let[n,o]=Cr(e,t),s=r.decode(o);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Se(s).set(n,e),s}};function Cr(r,e){switch(r[0]){case"Q":{let t=e??S;return[S.prefix,t.decode(`${S.prefix}${r}`)]}case S.prefix:{let t=e??S;return[S.prefix,t.decode(r)]}case $.prefix:{let t=e??$;return[$.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function Tr(r,e,t){let{prefix:n}=t;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let o=e.get(n);if(o==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return o}function Sr(r,e,t){let{prefix:n}=t,o=e.get(n);if(o==null){let s=t.encode(r);return e.set(n,s),s}else return o}var Y=112,Dr=18;function nt(r,e,t){let n=R(r),o=n+R(e),s=new Uint8Array(o+t.byteLength);return M(r,s,0),M(e,s,n),s.set(t,o),s}var Ir=Symbol.for("@ipld/js-cid/CID");var De={...ge,...le,...we,...he,...de,...me,...be,...xe,...ye,...pe},Ln={...Te,...Ee};function ot(r=0){return new Uint8Array(r)}function it(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var st=it("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Ie=it("ascii","a",r=>{let e="a";for(let t=0;t<r.length;t++)e+=String.fromCharCode(r[t]);return e},r=>{r=r.substring(1);let e=ot(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Ur={utf8:st,"utf-8":st,hex:De.base16,latin1:Ie,ascii:Ie,binary:Ie,...De},at=Ur;function ct(r,e="utf8"){let t=at[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var Ue=60;function ee(r){return{Status:r.Status??0,TC:r.TC??r.flag_tc??!1,RD:r.RD??r.flag_rd??!1,RA:r.RA??r.flag_ra??!1,AD:r.AD??r.flag_ad??!1,CD:r.CD??r.flag_cd??!1,Question:(r.Question??r.questions??[]).map(e=>({name:e.name,type:g[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:g[e.type],TTL:e.TTL??e.ttl??Ue,data:e.data instanceof Uint8Array?ct(e.data):e.data}))}}var Nr=4;function Ne(r,e={}){let t=new k({concurrency:e.queryConcurrency??Nr});return async(n,o={})=>{let s=new URLSearchParams;s.set("name",n),W(o.types).forEach(c=>{s.append("type",g[c])}),o.onProgress?.(new N("dns:query",{detail:n}));let i=await t.add(async()=>{let c=await fetch(`${r}?${s}`,{headers:{accept:"application/dns-json"},signal:o?.signal});if(c.status!==200)throw new Error(`Unexpected HTTP status: ${c.status} - ${c.statusText}`);let a=ee(await c.json());return o.onProgress?.(new N("dns:response",{detail:a})),a},{signal:o.signal});if(i==null)throw new Error("No DNS response received");return i}}function ft(){return[Ne("https://cloudflare-dns.com/dns-query"),Ne("https://dns.google/resolve")]}var dt=Le(ht(),1);var Oe=class{lru;constructor(e){this.lru=(0,dt.default)(e)}get(e,t){let n=!0,o=[];for(let s of t){let i=this.getAnswers(e,s);if(i.length===0){n=!1;break}o.push(...i)}if(n)return ee({answers:o})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,o=this.lru.get(n);if(o!=null){let s=o.filter(i=>i.expires>Date.now()).map(({expires:i,value:c})=>({...c,TTL:Math.round((i-Date.now())/1e3),type:g[c.type]}));return s.length===0&&this.lru.remove(n),s}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,o=this.lru.get(n)??[];o.push({expires:Date.now()+(t.TTL??Ue)*1e3,value:t}),this.lru.set(n,o)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function lt(r){return new Oe(r)}var Or=1e3,te=class{resolvers;cache;constructor(e){this.resolvers={},this.cache=lt(e.cacheSize??Or),Object.entries(e.resolvers??{}).forEach(([t,n])=>{Array.isArray(n)||(n=[n]),t.endsWith(".")||(t=`${t}.`),this.resolvers[t]=n}),this.resolvers["."]==null&&(this.resolvers["."]=ft())}async query(e,t={}){let n=W(t.types),o=t.cached!==!1?this.cache.get(e,n):void 0;if(o!=null)return t.onProgress?.(new N("dns:cache",{detail:o})),o;let s=`${e.split(".").pop()}.`,i=(this.resolvers[s]??this.resolvers["."]).sort(()=>Math.random()>.5?-1:1),c=[];for(let a of i){if(t.signal?.aborted===!0)break;try{let h=await a(e,{...t,types:n});for(let f of h.Answer)this.cache.add(e,f);return h}catch(h){c.push(h),t.onProgress?.(new N("dns:error",{detail:h}))}}throw c.length===1?c[0]:new AggregateError(c,`DNS lookup of ${e} ${n} failed`)}};var g;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(g||(g={}));var zr=32;function Pr(r={}){return new te(r)}return wt(Lr);})();
return MultiformatsDns}));