4 lines
34 KiB
JavaScript
4 lines
34 KiB
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 wt=Object.create;var W=Object.defineProperty;var xt=Object.getOwnPropertyDescriptor;var Et=Object.getOwnPropertyNames;var At=Object.getPrototypeOf,Ct=Object.prototype.hasOwnProperty;var ke=(r,e)=>()=>{try{return e||r((e={exports:{}}).exports,e),e.exports}catch(t){throw e=0,t}},v=(r,e)=>{for(var t in e)W(r,t,{get:e[t],enumerable:!0})},Me=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of Et(e))!Ct.call(r,s)&&s!==t&&W(r,s,{get:()=>e[s],enumerable:!(n=xt(e,s))||n.enumerable});return r};var qe=(r,e,t)=>(t=r!=null?wt(At(r)):{},Me(e||!r||!r.__esModule?W(t,"default",{value:r,enumerable:!0}):t,r)),Tt=r=>Me(W({},"__esModule",{value:!0}),r);var Be=ke((Yr,oe)=>{"use strict";var It=Object.prototype.hasOwnProperty,g="~";function V(){}Object.create&&(V.prototype=Object.create(null),new V().__proto__||(g=!1));function St(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function Re(r,e,t,n,s){if(typeof t!="function")throw new TypeError("The listener must be a function");var i=new St(t,n||r,s),o=g?g+e:e;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],i]:r._events[o].push(i):(r._events[o]=i,r._eventsCount++),r}function ee(r,e){--r._eventsCount===0?r._events=new V:delete r._events[e]}function m(){this._events=new V,this._eventsCount=0}m.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)It.call(t,n)&&e.push(g?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};m.prototype.listeners=function(e){var t=g?g+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var s=0,i=n.length,o=new Array(i);s<i;s++)o[s]=n[s].fn;return o};m.prototype.listenerCount=function(e){var t=g?g+e:e,n=this._events[t];return n?n.fn?1:n.length:0};m.prototype.emit=function(e,t,n,s,i,o){var c=g?g+e:e;if(!this._events[c])return!1;var a=this._events[c],h=arguments.length,u,f;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,s),!0;case 5:return a.fn.call(a.context,t,n,s,i),!0;case 6:return a.fn.call(a.context,t,n,s,i,o),!0}for(f=1,u=new Array(h-1);f<h;f++)u[f-1]=arguments[f];a.fn.apply(a.context,u)}else{var p=a.length,x;for(f=0;f<p;f++)switch(a[f].once&&this.removeListener(e,a[f].fn,void 0,!0),h){case 1:a[f].fn.call(a[f].context);break;case 2:a[f].fn.call(a[f].context,t);break;case 3:a[f].fn.call(a[f].context,t,n);break;case 4:a[f].fn.call(a[f].context,t,n,s);break;default:if(!u)for(x=1,u=new Array(h-1);x<h;x++)u[x-1]=arguments[x];a[f].fn.apply(a[f].context,u)}}return!0};m.prototype.on=function(e,t,n){return Re(this,e,t,n,!1)};m.prototype.once=function(e,t,n){return Re(this,e,t,n,!0)};m.prototype.removeListener=function(e,t,n,s){var i=g?g+e:e;if(!this._events[i])return this;if(!t)return ee(this,i),this;var o=this._events[i];if(o.fn)o.fn===t&&(!s||o.once)&&(!n||o.context===n)&&ee(this,i);else{for(var c=0,a=[],h=o.length;c<h;c++)(o[c].fn!==t||s&&!o[c].once||n&&o[c].context!==n)&&a.push(o[c]);a.length?this._events[i]=a.length===1?a[0]:a:ee(this,i)}return this};m.prototype.removeAllListeners=function(e){var t;return e?(t=g?g+e:e,this._events[t]&&ee(this,t)):(this._events=new V,this._eventsCount=0),this};m.prototype.off=m.prototype.removeListener;m.prototype.addListener=m.prototype.on;m.prefixed=g;m.EventEmitter=m;typeof oe<"u"&&(oe.exports=m)});var gt=ke((fs,mt)=>{mt.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 s(i,o){t[i]=o,e++,e>=r&&(e=0,n=t,t=Object.create(null))}return{has:function(i){return t[i]!==void 0||n[i]!==void 0},remove:function(i){t[i]!==void 0&&(t[i]=void 0),n[i]!==void 0&&(n[i]=void 0)},get:function(i){var o=t[i];if(o!==void 0)return o;if((o=n[i])!==void 0)return s(i,o),o},set:function(i,o){t[i]!==void 0?t[i]=o:s(i,o)},clear:function(){t=Object.create(null),n=Object.create(null)}}}});var Qr={};v(Qr,{MAX_RECURSIVE_DEPTH:()=>Fr,RecordType:()=>w,dns:()=>Vr});var U=class extends Event{type;detail;constructor(e,t){super(e),this.type=e,this.detail=t}};var K=class extends AggregateError{static name="DNSQueryFailedError";name="DNSQueryFailedError"},j=class extends AggregateError{static name="EmptyDNSAnswerError";name="EmptyDNSAnswerError"};var ae=qe(Be(),1);var ce=class r extends Error{name="TimeoutError";constructor(e,t){super(e,t),Error.captureStackTrace?.(this,r)}},Fe=r=>r.reason??new DOMException("This operation was aborted.","AbortError");function he(r,e){let{milliseconds:t,fallback:n,message:s,customTimers:i={setTimeout,clearTimeout},signal:o}=e,c,a,u=new Promise((f,p)=>{if(typeof t!="number"||Math.sign(t)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${t}\``);if(o?.aborted){p(Fe(o));return}if(o&&(a=()=>{p(Fe(o))},o.addEventListener("abort",a,{once:!0})),r.then(f,p),t===Number.POSITIVE_INFINITY)return;let x=new ce;c=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(F){p(F)}return}typeof r.cancel=="function"&&r.cancel(),s===!1?f():s instanceof Error?p(s):(x.message=s??`Promise timed out after ${t} milliseconds`,p(x))},t)}).finally(()=>{u.clear(),a&&o&&o.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,c),c=void 0},u}function ue(r,e,t){let n=0,s=r.length;for(;s>0;){let i=Math.trunc(s/2),o=n+i;t(r[o],e)<=0?(n=++o,s-=i+1):s=i}return n}var Lt=100,O=class{#t=[];#e=0;enqueue(e,t){let{priority:n=0,id:s}=t??{},{size:i}=this,o={priority:n,id:s,run:e};if(i===0){this.#t.length=0,this.#e=0,this.#t.push(o);return}if(this.#t.at(-1).priority>=n){this.#t.push(o);return}this.#i();let c=ue(this.#t,o,(a,h)=>h.priority-a.priority);this.#t.splice(c,0,o)}setPriority(e,t){let n=this.#t.findIndex((i,o)=>o>=this.#e&&i.id===e);if(n===-1)throw new ReferenceError(`No promise function with the id "${e}" exists in the queue.`);let[s]=this.#t.splice(n,1);this.enqueue(s.run,{priority:t,id:e})}remove(e){let t=this.#t.findIndex((n,s)=>s<this.#e?!1:typeof e=="string"?n.id===e:n.run===e);t!==-1&&this.#t.splice(t,1)}dequeue(){if(this.#e===this.#t.length)return;let e=this.#t[this.#e];return this.#e++,this.#e===this.#t.length?(this.#t.length=0,this.#e=0):this.#e>Lt&&this.#e>this.#t.length/2&&this.#i(),e?.run}filter(e){let t=[];for(let n=this.#e;n<this.#t.length;n++){let s=this.#t[n];s.priority===e.priority&&t.push(s.run)}return t}get size(){return this.#t.length-this.#e}#i(){this.#e!==0&&(this.#t.splice(0,this.#e),this.#e=0)}};var Q=class extends ae.default{#t;#e;#i=0;#d;#m=!1;#y=!1;#c;#S=0;#w=0;#h;#u;#a;#o=[];#s=0;#r;#L;#n=0;#g;#f;#z=1n;#b=new Map;#x=new Set;timeout;constructor(e){if(super(),e={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:O,strict:!1,...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})`);if(e.strict&&e.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(e.strict&&e.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=e.carryoverIntervalCount??e.carryoverConcurrencyCount??!1,this.#e=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#d=e.intervalCap,this.#c=e.interval,this.#a=e.strict,this.#r=new e.queueClass,this.#L=e.queueClass,this.concurrency=e.concurrency,e.timeout!==void 0&&!(Number.isFinite(e.timeout)&&e.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${e.timeout}\` (${typeof e.timeout})`);this.timeout=e.timeout,this.#f=e.autoStart===!1,this.#B()}#E(e){for(;this.#s<this.#o.length;){let n=this.#o[this.#s];if(n!==void 0&&e-n>=this.#c)this.#s++;else break}(this.#s>100&&this.#s>this.#o.length/2||this.#s===this.#o.length)&&(this.#o=this.#o.slice(this.#s),this.#s=0)}#$(e){this.#a?this.#o.push(e):this.#i++}#O(){this.#a?this.#o.length>this.#s&&this.#o.pop():this.#i>0&&this.#i--}#A(){return this.#o.length-this.#s}get#_(){return this.#e?!0:this.#a?this.#A()<this.#d:this.#i<this.#d}get#k(){return this.#n<this.#g}#M(){this.#n--,this.#n===0&&this.emit("pendingZero"),this.#v(),this.emit("next")}#q(){this.#u=void 0,this.#U(),this.#N()}#R(e){if(this.#a){if(this.#E(e),this.#A()>=this.#d){let n=this.#o[this.#s],s=this.#c-(e-n);return this.#C(s),!0}return!1}if(this.#h===void 0){let t=this.#S-e;if(t<0){if(this.#w>0){let n=e-this.#w;if(n<this.#c)return this.#C(this.#c-n),!0}this.#i=this.#t?this.#n:0}else return this.#C(t),!0}return!1}#C(e){this.#u===void 0&&(this.#u=setTimeout(()=>{this.#q()},e))}#T(){this.#h&&(clearInterval(this.#h),this.#h=void 0)}#D(){this.#u&&(clearTimeout(this.#u),this.#u=void 0)}#v(){if(this.#r.size===0){if(this.#T(),this.emit("empty"),this.#n===0){if(this.#D(),this.#a&&this.#s>0){let t=Date.now();this.#E(t)}this.emit("idle")}return!1}let e=!1;if(!this.#f){let t=Date.now(),n=!this.#R(t);if(this.#_&&this.#k){let s=this.#r.dequeue();this.#e||(this.#$(t),this.#p()),this.emit("active"),s(),n&&this.#N(),e=!0}}return e}#N(){this.#e||this.#h!==void 0||this.#a||(this.#h=setInterval(()=>{this.#U()},this.#c),this.#S=Date.now()+this.#c)}#U(){this.#a||(this.#i===0&&this.#n===0&&this.#h&&this.#T(),this.#i=this.#t?this.#n:0),this.#I(),this.#p()}#I(){for(;this.#v(););}get concurrency(){return this.#g}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.#g=e,this.#I()}setPriority(e,t){if(typeof t!="number"||!Number.isFinite(t))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${t}\` (${typeof t})`);this.#r.setPriority(e,t)}async add(e,t={}){return t={timeout:this.timeout,...t,id:t.id??(this.#z++).toString()},new Promise((n,s)=>{let i=Symbol(`task-${t.id}`),o=()=>{},c=async()=>{o(),this.#n++,this.#b.set(i,{id:t.id,priority:t.priority??0,startTime:Date.now(),timeout:t.timeout});let h;try{try{t.signal?.throwIfAborted()}catch(p){throw this.#F(),this.#b.delete(i),p}this.#w=Date.now();let u=e({signal:t.signal});if(t.timeout&&(u=he(Promise.resolve(u),{milliseconds:t.timeout,message:`Task timed out after ${t.timeout}ms (queue has ${this.#n} running, ${this.#r.size} waiting)`})),t.signal){let{signal:p}=t;u=Promise.race([u,new Promise((x,F)=>{h=()=>{F(p.reason)},p.addEventListener("abort",h,{once:!0})})])}let f=await u;n(f),this.emit("completed",f)}catch(u){s(u),this.emit("error",u)}finally{h&&t.signal?.removeEventListener("abort",h),this.#b.delete(i),queueMicrotask(()=>{this.#M()})}};this.#r.enqueue(c,t);let a=()=>{if(this.#r instanceof O){this.#r.remove(c);return}this.#r.remove?.(t.id)};if(t.signal){let{signal:h}=t,u=()=>{o(),a(),s(h.reason),this.#v(),this.emit("next")};if(o=()=>{h.removeEventListener("abort",u),this.#x.delete(o)},h.aborted){u();return}h.addEventListener("abort",u,{once:!0}),this.#x.add(o)}this.emit("add"),this.#v()})}async addAll(e,t){return Promise.all(e.map(async n=>this.add(n,t)))}start(){return this.#f?(this.#f=!1,this.#I(),this):this}pause(){this.#f=!0}clear(){for(let e of this.#x)e();this.#r=new this.#L,this.#T(),this.#P(),this.emit("empty"),this.#n===0&&(this.#D(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#l("empty")}async onSizeLessThan(e){this.#r.size<e||await this.#l("next",()=>this.#r.size<e)}async onIdle(){this.#n===0&&this.#r.size===0||await this.#l("idle")}async onPendingZero(){this.#n!==0&&await this.#l("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#l("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#l("rateLimitCleared")}onError(){return new Promise((e,t)=>{let n=s=>{this.off("error",n),t(s)};this.on("error",n)})}async#l(e,t){return new Promise(n=>{let s=()=>{t&&!t()||(this.off(e,s),n())};this.on(e,s)})}get size(){return this.#r.size}sizeBy(e){return this.#r.filter(e).length}get pending(){return this.#n}get isPaused(){return this.#f}#B(){this.#e||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#e||this.#y||(this.#y=!0,queueMicrotask(()=>{this.#y=!1,this.#P()}))}#F(){this.#e||(this.#O(),this.#p())}#P(){let e=this.#m;if(this.#e||this.#r.size===0){e&&(this.#m=!1,this.emit("rateLimitCleared"));return}let t;if(this.#a){let s=Date.now();this.#E(s),t=this.#A()}else t=this.#i;let n=t>=this.#d;n!==e&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#n===this.#g&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#b.values()].map(e=>({...e,timeoutRemaining:e.timeout?Math.max(0,e.startTime+e.timeout-Date.now()):void 0}))}};function te(r){let e=[w.A];return r==null?e:Array.isArray(r)?r.length===0?e:r:[r]}var me={};v(me,{base10:()=>_t});var an=new Uint8Array(0);function Ve(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 D(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 Qe(r){return new TextEncoder().encode(r)}function He(r){return new TextDecoder().decode(r)}function Dt(r){return r?.buffer instanceof ArrayBuffer}function $(r){return Dt(r)?r:r.slice()}function Nt(r,e,t){if(r.length>=255)throw new TypeError("Alphabet too long");for(var n=new Uint8Array(256),s=0;s<n.length;s++)n[s]=255;for(var i=0;i<r.length;i++){var o=r.charAt(i),c=o.charCodeAt(0);if(n[c]!==255)throw new TypeError(o+" is ambiguous");if(n[c]=i,t){var a=o.toLowerCase().charCodeAt(0),h=o.toUpperCase().charCodeAt(0);a!==c&&(n[a]=i),h!==c&&(n[h]=i)}}var u=r.length,f=r.charAt(0),p=Math.log(u)/Math.log(256),x=Math.log(256)/Math.log(u);function F(l){if(l instanceof Uint8Array||(ArrayBuffer.isView(l)?l=new Uint8Array(l.buffer,l.byteOffset,l.byteLength):Array.isArray(l)&&(l=Uint8Array.from(l))),!(l instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(l.length===0)return"";for(var b=0,z=0,E=0,C=l.length;E!==C&&l[E]===0;)E++,b++;for(var T=(C-E)*x+1>>>0,y=new Uint8Array(T);E!==C;){for(var I=l[E],N=0,A=T-1;(I!==0||N<z)&&A!==-1;A--,N++)I+=256*y[A]>>>0,y[A]=I%u>>>0,I=I/u>>>0;if(I!==0)throw new Error("Non-zero carry");z=N,E++}for(var L=T-z;L!==T&&y[L]===0;)L++;for(var Z=f.repeat(b);L<T;++L)Z+=r.charAt(y[L]);return Z}function _e(l){if(typeof l!="string")throw new TypeError("Expected String");if(l.length===0)return new Uint8Array;var b=0;if(l[b]!==" "){for(var z=0,E=0;l[b]===f;)z++,b++;for(var C=(l.length-b)*p+1>>>0,T=new Uint8Array(C);l[b];){var y=n[l.charCodeAt(b)];if(y===255)return;for(var I=0,N=C-1;(y!==0||I<E)&&N!==-1;N--,I++)y+=u*T[N]>>>0,T[N]=y%256>>>0,y=y/256>>>0;if(y!==0)throw new Error("Non-zero carry");E=I,b++}if(l[b]!==" "){for(var A=C-E;A!==C&&T[A]===0;)A++;for(var L=new Uint8Array(z+(C-A)),Z=z;A!==C;)L[Z++]=T[A++];return L}}}function yt(l){var b=_e(l);if(b)return b;throw new Error(`Non-${e} character`)}return{encode:F,decodeUnsafe:_e,decode:yt}}var Ut=Nt,Pt=Ut,Xe=Pt;var fe=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")}},le=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let s=t.codePointAt(0);if(s===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=s,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 Ye(this,e)}},de=class{decoders;constructor(e){this.decoders=e}or(e){return Ye(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 Ye(r,e){return new de({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var pe=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,s){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=s,this.encoder=new fe(e,t,n),this.decoder=new le(e,t,s)}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 pe(r,e,t,n)}function P({name:r,prefix:e,alphabet:t,caseInsensitive:n=!1}){let{encode:s,decode:i}=Xe(t,r,n);return _({prefix:e,name:r,encode:s,decode:o=>D(i(o))})}function zt(r,e,t,n){let s=r.length;for(;r[s-1]==="=";)--s;let i=new Uint8Array(s*t/8|0),o=0,c=0,a=0;for(let h=0;h<s;++h){let u=e[r[h]];if(u===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|u,o+=t,o>=8&&(o-=8,i[a++]=255&c>>o)}if(o>=t||(255&c<<8-o)!==0)throw new SyntaxError("Unexpected end of data");return i}function $t(r,e,t){let n=e[e.length-1]==="=",s=(1<<t)-1,i="",o=0,c=0;for(let a=0;a<r.length;++a)for(c=c<<8|r[a],o+=8;o>t;)o-=t,i+=e[s&c>>o];if(o!==0&&(i+=e[s&c<<t-o]),n)for(;(i.length*t&7)!==0;)i+="=";return i}function Ot(r,e){let t={};for(let n=0;n<r.length;++n)if(t[r[n]]=n,e){let s=r[n].toLowerCase(),i=r[n].toUpperCase();s!==r[n]&&(t[s]=n),i!==r[n]&&(t[i]=n)}return t}function d({name:r,prefix:e,bitsPerChar:t,alphabet:n,caseInsensitive:s=!1}){let i=Ot(n,s);return _({prefix:e,name:r,encode(o){return $t(o,n,t)},decode(o){return zt(o,i,t,r)}})}var _t=P({prefix:"9",name:"base10",alphabet:"0123456789"});var ge={};v(ge,{base16:()=>kt,base16upper:()=>Mt});var kt=d({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4,caseInsensitive:!0}),Mt=d({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4,caseInsensitive:!0});var be={};v(be,{base2:()=>qt});var qt=d({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var ve={};v(ve,{base256emoji:()=>Qt});var Ge=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}"),Rt=Ge.reduce((r,e,t)=>(r[t]=e,r),[]),Bt=Ge.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function Ft(r){return r.reduce((e,t)=>(e+=Rt[t],e),"")}function Vt(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let s=Bt[n];if(s==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(s)}return new Uint8Array(e)}var Qt=_({prefix:"\u{1F680}",name:"base256emoji",encode:Ft,decode:Vt});var ye={};v(ye,{base32:()=>k,base32hex:()=>Yt,base32hexpad:()=>Zt,base32hexpadupper:()=>Wt,base32hexupper:()=>Gt,base32pad:()=>Jt,base32padupper:()=>Xt,base32upper:()=>Ht,base32z:()=>Kt});var k=d({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5,caseInsensitive:!0}),Ht=d({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5,caseInsensitive:!0}),Jt=d({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5,caseInsensitive:!0}),Xt=d({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5,caseInsensitive:!0}),Yt=d({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5,caseInsensitive:!0}),Gt=d({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5,caseInsensitive:!0}),Zt=d({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5,caseInsensitive:!0}),Wt=d({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5,caseInsensitive:!0}),Kt=d({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var we={};v(we,{base36:()=>H,base36upper:()=>jt});var H=P({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz",caseInsensitive:!0}),jt=P({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ",caseInsensitive:!0});var xe={};v(xe,{base58btc:()=>S,base58flickr:()=>er});var S=P({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),er=P({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var Ee={};v(Ee,{base64:()=>tr,base64pad:()=>rr,base64url:()=>nr,base64urlpad:()=>sr});var tr=d({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),rr=d({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),nr=d({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),sr=d({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var Ae={};v(Ae,{base8:()=>ir});var ir=d({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var Ce={};v(Ce,{identity:()=>or});var or=_({prefix:"\0",name:"identity",encode:r=>He(r),decode:r=>Qe(r)});var An=new TextEncoder,Cn=new TextDecoder;var Ie={};v(Ie,{identity:()=>Dr});var hr=Ke,Ze=128,ur=127,fr=~ur,lr=Math.pow(2,31);function Ke(r,e,t){e=e||[],t=t||0;for(var n=t;r>=lr;)e[t++]=r&255|Ze,r/=128;for(;r&fr;)e[t++]=r&255|Ze,r>>>=7;return e[t]=r|0,Ke.bytes=t-n+1,e}var dr=Te,pr=128,We=127;function Te(r,n){var t=0,n=n||0,s=0,i=n,o,c=r.length;do{if(i>=c)throw Te.bytes=0,new RangeError("Could not decode varint");o=r[i++],t+=s<28?(o&We)<<s:(o&We)*Math.pow(2,s),s+=7}while(o>=pr);return Te.bytes=i-n,t}var mr=Math.pow(2,7),gr=Math.pow(2,14),br=Math.pow(2,21),vr=Math.pow(2,28),yr=Math.pow(2,35),wr=Math.pow(2,42),xr=Math.pow(2,49),Er=Math.pow(2,56),Ar=Math.pow(2,63),Cr=function(r){return r<mr?1:r<gr?2:r<br?3:r<vr?4:r<yr?5:r<wr?6:r<xr?7:r<Er?8:r<Ar?9:10},Tr={encode:hr,decode:dr,encodingLength:Cr},Ir=Tr,J=Ir;function X(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 q(r){return J.encodingLength(r)}function B(r,e){let t=e.byteLength,n=q(r),s=n+q(t),i=new Uint8Array(s+t);return M(r,i,0),M(t,i,n),i.set(e,s),new R(r,t,e,i)}function je(r){let e=D(r),[t,n]=X(e),[s,i]=X(e.subarray(n)),o=e.subarray(n+i);if(o.byteLength!==s)throw new Error("Incorrect length");return new R(t,s,o,e)}function et(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&Ve(r.bytes,t.bytes)}}var R=class{code;size;digest;bytes;constructor(e,t,n,s){this.code=e,this.size=t,this.digest=$(n),this.bytes=$(s)}};var tt=0,Sr="identity",rt=D;function Lr(r,e){if(e?.truncate!=null&&e.truncate!==r.byteLength){if(e.truncate<0||e.truncate>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,e.truncate)}return B(tt,rt(r))}var Dr={code:tt,name:Sr,encode:rt,digest:Lr};var De={};v(De,{sha256:()=>Ur,sha512:()=>Pr});var Nr=20;function Le({name:r,code:e,encode:t,minDigestLength:n,maxDigestLength:s}){return new Se(r,e,t,n,s)}var Se=class{name;code;encode;minDigestLength;maxDigestLength;constructor(e,t,n,s,i){this.name=e,this.code=t,this.encode=n,this.minDigestLength=s??Nr,this.maxDigestLength=i}digest(e,t){if(t?.truncate!=null){if(t.truncate<this.minDigestLength)throw new Error(`Invalid truncate option, must be greater than or equal to ${this.minDigestLength}`);if(this.maxDigestLength!=null&&t.truncate>this.maxDigestLength)throw new Error(`Invalid truncate option, must be less than or equal to ${this.maxDigestLength}`)}if(e instanceof Uint8Array){let n=this.encode(e);return n instanceof Uint8Array?nt(n,this.code,t?.truncate):n.then(s=>nt(s,this.code,t?.truncate))}else throw Error("Unknown type, must be binary type")}};function nt(r,e,t){if(t!=null&&t!==r.byteLength){if(t>r.byteLength)throw new Error(`Invalid truncate option, must be less than or equal to ${r.byteLength}`);r=r.subarray(0,t)}return B(e,r)}function it(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var Ur=Le({name:"sha2-256",code:18,encode:it("SHA-256")}),Pr=Le({name:"sha2-512",code:19,encode:it("SHA-512")});function ot(r,e){let{bytes:t,version:n}=r;return n===0?$r(t,Ne(r),e??S.encoder):Or(t,Ne(r),e??k.encoder)}var at=new WeakMap;function Ne(r){let e=at.get(r);if(e==null){let t=new Map;return at.set(r,t),t}return e}var ne=class r{code;version;multihash;bytes;"/";constructor(e,t,n,s){this.code=t,this.version=e,this.multihash=n,this.bytes=$(s),this["/"]=this.bytes}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!==G)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==_r)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=B(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&&et(e.multihash,n.multihash)}toString(e){return ot(this,e)}toJSON(){return{"/":ot(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:s,multihash:i,bytes:o}=t;return new r(n,s,i,o??ct(n,s,i.bytes))}else if(t[kr]===!0){let{version:n,multihash:s,code:i}=t,o=je(s);return r.create(n,i,o)}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!==G)throw new Error(`Version 0 CID must use dag-pb (code: ${G}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let s=ct(e,t,n.bytes);return new r(e,t,n,s)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,G,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,s=D(e.subarray(n,n+t.multihashSize));if(s.byteLength!==t.multihashSize)throw new Error("Incorrect length");let i=s.subarray(t.multihashSize-t.digestSize),o=new R(t.multihashCode,t.digestSize,i,s);return[t.version===0?r.createV0(o):r.createV1(t.codec,o),e.subarray(t.size)]}static inspectBytes(e){let t=0,n=()=>{let[f,p]=X(e.subarray(t));return t+=p,f},s=n(),i=G;if(s===18?(s=0,t=0):i=n(),s!==0&&s!==1)throw new RangeError(`Invalid CID version ${s}`);let o=t,c=n(),a=n(),h=t+a,u=h-o;return{version:s,codec:i,multihashCode:c,digestSize:a,multihashSize:u,size:h}}static parse(e,t){let[n,s]=zr(e,t),i=r.decode(s);if(i.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return Ne(i).set(n,e),i}};function zr(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 k.prefix:{let t=e??k;return[k.prefix,t.decode(r)]}case H.prefix:{let t=e??H;return[H.prefix,t.decode(r)]}default:{if(e==null)throw Error("To parse non base32, base36 or base58btc encoded CID multibase decoder must be provided");return[r[0],e.decode(r)]}}}function $r(r,e,t){let{prefix:n}=t;if(n!==S.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let s=e.get(n);if(s==null){let i=t.encode(r).slice(1);return e.set(n,i),i}else return s}function Or(r,e,t){let{prefix:n}=t,s=e.get(n);if(s==null){let i=t.encode(r);return e.set(n,i),i}else return s}var G=112,_r=18;function ct(r,e,t){let n=q(r),s=n+q(e),i=new Uint8Array(s+t.byteLength);return M(r,i,0),M(e,i,n),i.set(t,s),i}var kr=Symbol.for("@ipld/js-cid/CID");var Ue={...Ce,...be,...Ae,...me,...ge,...ye,...we,...xe,...Ee,...ve},Jn={...De,...Ie};function ht(r=0){return new Uint8Array(r)}function ft(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var ut=ft("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),Pe=ft("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=ht(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),Mr={utf8:ut,"utf-8":ut,hex:Ue.base16,latin1:Pe,ascii:Pe,binary:Pe,...Ue},lt=Mr;function dt(r,e="utf8"){let t=lt[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}var ze=60;function se(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:w[e.type]})),Answer:(r.Answer??r.answers??[]).map(e=>({name:e.name,type:w[e.type],TTL:e.TTL??e.ttl??ze,data:e.data instanceof Uint8Array?dt(e.data):e.data}))}}var qr=4;function $e(r,e={}){let t=new Q({concurrency:e.queryConcurrency??qr});return async(n,s={})=>{let i=s?.logger?.forComponent("dns:dns-json-over-https"),o=new URLSearchParams;o.set("name",n),te(s.types).forEach(a=>{o.append("type",w[a])}),s.onProgress?.(new U("dns:query",n)),i?.("GET %s",`${r}?${o}`);let c=await t.add(async()=>{let a=await fetch(`${r}?${o}`,{headers:{accept:"application/dns-json"},signal:s?.signal});if(i?.("GET %s %d",a.url,a.status),a.status!==200)throw new Error(`Unexpected HTTP status: ${a.status} - ${a.statusText}`);let h=se(await a.json());return s.onProgress?.(new U("dns:response",h)),h},{signal:s.signal});if(c==null)throw new Error("No DNS response received");return c}}function pt(){return[$e("https://cloudflare-dns.com/dns-query"),$e("https://dns.google/resolve")]}var bt=qe(gt(),1);var Oe=class{lru;constructor(e){this.lru=(0,bt.default)(e)}get(e,t){let n=!0,s=[];for(let i of t){let o=this.getAnswers(e,i);if(o.length===0){n=!1;break}s.push(...o)}if(n)return se({answers:s})}getAnswers(e,t){let n=`${e.toLowerCase()}-${t}`,s=this.lru.get(n);if(s!=null){let i=s.filter(o=>o.expires>Date.now()).map(({expires:o,value:c})=>({...c,TTL:Math.round((o-Date.now())/1e3),type:w[c.type]}));return i.length===0&&this.lru.remove(n),i}return[]}add(e,t){let n=`${e.toLowerCase()}-${t.type}`,s=this.lru.get(n)??[];s.push({expires:Date.now()+(t.TTL??ze)*1e3,value:t}),this.lru.set(n,s)}remove(e,t){let n=`${e.toLowerCase()}-${t}`;this.lru.remove(n)}clear(){this.lru.clear()}};function vt(r){return new Oe(r)}var Rr=1e3,Br=()=>Math.random()>.5?-1:1,ie=class{resolvers;cache;logger;sorter;constructor(e){this.resolvers={},this.cache=vt(e.cacheSize??Rr),this.logger=e.logger,this.sorter=e.sorter??Br,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["."]=pt())}async query(e,t={}){let n=te(t.types),s=t.cached!==!1?this.cache.get(e,n):void 0;if(s!=null)return t.onProgress?.(new U("dns:cache",s)),s;let i=`${e.split(".").pop()}.`,o=(this.resolvers[i]??this.resolvers["."]).sort(this.sorter),c=[];for(let a of o){if(t.signal?.aborted===!0)break;try{let h=await a(e,{...t,logger:this.logger,types:n});if(h.Answer.length===0)throw new j("Query result had no answers");for(let u of h.Answer)this.cache.add(e,u);return h}catch(h){c.push(h),t.onProgress?.(new U("dns:error",h))}}throw new K(c,`DNS lookup of ${e} ${n} failed`)}};var w;(function(r){r[r.A=1]="A",r[r.CNAME=5]="CNAME",r[r.TXT=16]="TXT",r[r.AAAA=28]="AAAA"})(w||(w={}));var Fr=32;function Vr(r={}){return new ie(r)}return Tt(Qr);})();
|
|
return MultiformatsDns}));
|
|
//# sourceMappingURL=index.min.js.map
|