@libp2p/kad-dht 14.1.0-eee97c7d4 → 14.1.1-05d559f54

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.min.js CHANGED
@@ -1,5 +1,5 @@
1
1
  (function (root, factory) {(typeof module === 'object' && module.exports) ? module.exports = factory() : root.Libp2PKadDht = factory()}(typeof self !== 'undefined' ? self : this, function () {
2
- "use strict";var Libp2PKadDht=(()=>{var B4=Object.create;var Gn=Object.defineProperty;var I4=Object.getOwnPropertyDescriptor;var k4=Object.getOwnPropertyNames;var T4=Object.getPrototypeOf,R4=Object.prototype.hasOwnProperty;var ws=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ke=(r,e)=>{for(var t in e)Gn(r,t,{get:e[t],enumerable:!0})},F2=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of k4(e))!R4.call(r,i)&&i!==t&&Gn(r,i,{get:()=>e[i],enumerable:!(n=I4(e,i))||n.enumerable});return r};var bs=(r,e,t)=>(t=r!=null?B4(T4(r)):{},F2(e||!r||!r.__esModule?Gn(t,"default",{value:r,enumerable:!0}):t,r)),P4=r=>F2(Gn({},"__esModule",{value:!0}),r);var Q2=ws((Fc,vs)=>{"use strict";var _4=Object.prototype.hasOwnProperty,Te="~";function on(){}Object.create&&(on.prototype=Object.create(null),new on().__proto__||(Te=!1));function C4(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function W2(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new C4(t,n||r,i),o=Te?Te+e:e;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],s]:r._events[o].push(s):(r._events[o]=s,r._eventsCount++),r}function Qn(r,e){--r._eventsCount===0?r._events=new on:delete r._events[e]}function ve(){this._events=new on,this._eventsCount=0}ve.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)_4.call(t,n)&&e.push(Te?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};ve.prototype.listeners=function(e){var t=Te?Te+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o};ve.prototype.listenerCount=function(e){var t=Te?Te+e:e,n=this._events[t];return n?n.fn?1:n.length:0};ve.prototype.emit=function(e,t,n,i,s,o){var a=Te?Te+e:e;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,u,f;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,s),!0;case 6:return c.fn.call(c.context,t,n,i,s,o),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var h=c.length,p;for(f=0;f<h;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,i);break;default:if(!u)for(p=1,u=new Array(l-1);p<l;p++)u[p-1]=arguments[p];c[f].fn.apply(c[f].context,u)}}return!0};ve.prototype.on=function(e,t,n){return W2(this,e,t,n,!1)};ve.prototype.once=function(e,t,n){return W2(this,e,t,n,!0)};ve.prototype.removeListener=function(e,t,n,i){var s=Te?Te+e:e;if(!this._events[s])return this;if(!t)return Qn(this,s),this;var o=this._events[s];if(o.fn)o.fn===t&&(!i||o.once)&&(!n||o.context===n)&&Qn(this,s);else{for(var a=0,c=[],l=o.length;a<l;a++)(o[a].fn!==t||i&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[s]=c.length===1?c[0]:c:Qn(this,s)}return this};ve.prototype.removeAllListeners=function(e){var t;return e?(t=Te?Te+e:e,this._events[t]&&Qn(this,t)):(this._events=new on,this._eventsCount=0),this};ve.prototype.off=ve.prototype.removeListener;ve.prototype.addListener=ve.prototype.on;ve.prefixed=Te;ve.EventEmitter=ve;typeof vs<"u"&&(vs.exports=ve)});var E3=ws(Kr=>{"use strict";var m8="[object ArrayBuffer]",Et=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===m8}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),i=r.toUint8Array(t);if(n.length!==i.byteLength)return!1;for(let s=0;s<n.length;s++)if(n[s]!==i[s])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let o of t)n+=o.byteLength;let i=new Uint8Array(n),s=0;for(let o of t){let a=this.toUint8Array(o);i.set(a,s),s+=a.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}},Wo="string",y8=/^[0-9a-f]+$/i,w8=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,b8=/^[a-zA-Z0-9-_]+$/,E1=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n.buffer}static toString(e){let t=Et.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return decodeURIComponent(escape(n))}},$e=class{static toString(e,t=!1){let n=Et.toArrayBuffer(e),i=new DataView(n),s="";for(let o=0;o<n.byteLength;o+=2){let a=i.getUint16(o,t);s+=String.fromCharCode(a)}return s}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),i=new DataView(n);for(let s=0;s<e.length;s++)i.setUint16(s*2,e.charCodeAt(s),t);return n}},A1=class r{static isHex(e){return typeof e===Wo&&y8.test(e)}static isBase64(e){return typeof e===Wo&&w8.test(e)}static isBase64Url(e){return typeof e===Wo&&b8.test(e)}static ToString(e,t="utf8"){let n=Et.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return $e.toString(n,!0);case"utf16":case"utf16be":return $e.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return $e.fromString(e,!0);case"utf16":case"utf16be":return $e.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Et.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return E1.fromString(e);case"utf16":case"utf16be":return $e.fromString(e);case"utf16le":case"usc2":return $e.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return E1.toString(e);case"utf16":case"utf16be":return $e.toString(e);case"utf16le":case"usc2":return $e.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);return n.buffer}static ToBinary(e){let t=Et.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return n}static ToHex(e){let t=Et.toUint8Array(e),n="",i=t.length;for(let s=0;s<i;s++){let o=t[s];o<16&&(n+="0"),n+=o.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let i=0;i<t.length;i=i+2){let s=t.slice(i,i+2);n[i/2]=parseInt(s,16)}return n.buffer}static ToUtf16String(e,t=!1){return $e.toString(e,t)}static FromUtf16String(e,t=!1){return $e.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};A1.DEFAULT_UTF8_ENCODING="utf8";function x8(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let i=arguments[n];for(let s in i)t[s]=i[s]}return t}function v8(...r){let e=r.map(i=>i.byteLength).reduce((i,s)=>i+s),t=new Uint8Array(e),n=0;return r.map(i=>new Uint8Array(i)).forEach(i=>{for(let s of i)t[n++]=s}),t.buffer}function E8(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<r.byteLength;i++)if(t[i]!==n[i])return!1;return!0}Kr.BufferSourceConverter=Et;Kr.Convert=A1;Kr.assign=x8;Kr.combine=v8;Kr.isEqual=E8});var Da=ws(Mn=>{(function(){var r,e,t,n,i,s,o,a;a=function(c){var l,u,f,h;return l=(c&255<<24)>>>24,u=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[l,u,f,h].join(".")},o=function(c){var l,u,f,h,p,y;for(l=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}y=e(c),p=y[0],u=y[1],c=c.substring(u),l.push(p)}if(c.length!==0)throw new Error("Invalid IP");switch(l.length){case 1:if(l[0]>4294967295)throw new Error("Invalid IP");return l[0]>>>0;case 2:if(l[0]>255||l[1]>16777215)throw new Error("Invalid IP");return(l[0]<<24|l[1])>>>0;case 3:if(l[0]>255||l[1]>255||l[2]>65535)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2])>>>0;case 4:if(l[0]>255||l[1]>255||l[2]>255||l[3]>255)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2]<<8|l[3])>>>0;default:throw new Error("Invalid IP")}},t=function(c){return c.charCodeAt(0)},n=t("0"),s=t("a"),i=t("A"),e=function(c){var l,u,f,h,p;for(h=0,l=10,u="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,l=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,l=8,u="7")),p=f;f<c.length;){if("0"<=c[f]&&c[f]<=u)h=h*l+(t(c[f])-n)>>>0;else if(l===16)if("a"<=c[f]&&c[f]<="f")h=h*l+(10+t(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*l+(10+t(c[f])-i)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===p)throw new Error("empty octet");return[h,f]},r=function(){function c(l,u){var f,h,p,y;if(typeof l!="string")throw new Error("Missing `net' parameter");if(u||(y=l.split("/",2),l=y[0],u=y[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=o(u)}catch(w){throw f=w,new Error("Invalid mask: "+u)}for(h=p=32;p>=0;h=--p)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(u||u===0)this.bitmask=parseInt(u,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(o(l)&this.maskLong)>>>0}catch(w){throw f=w,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new c(l)),l instanceof c?this.contains(l.base)&&this.contains(l.broadcast||l.last):(o(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(l){return l==null&&(l=1),new c(a(this.netLong+this.size*l),this.mask)},c.prototype.forEach=function(l){var u,f,h;for(h=o(this.first),f=o(this.last),u=0;h<=f;)l(a(h),h,u),u++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),Mn.ip2long=o,Mn.long2ip=a,Mn.Netmask=r}).call(Mn)});var ic={};ke(ic,{EventTypes:()=>Kn,MessageType:()=>O,Record:()=>ue,kadDHT:()=>nc,passthroughMapper:()=>Fa,removePrivateAddressesMapper:()=>Bi,removePublicAddressesMapper:()=>Va});var H2=Symbol.for("@libp2p/content-routing");var q2=Symbol.for("@libp2p/peer-discovery");var xs=Symbol.for("@libp2p/peer-id");var K2=Symbol.for("@libp2p/peer-routing");var $2="keep-alive";var ft=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ht=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var ze=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var jn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Ne=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Jt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var te=(r,...e)=>{try{[...e]}catch{}};var Le=class extends EventTarget{#e=new Map;constructor(){super(),te(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:s})=>s!==t),this.#e.set(e,i))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:i})=>!i),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};function z2(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function nn(...r){let e=[];for(let t of r)z2(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function Wn(...r){let e=[];for(let t of r)z2(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var G2=Symbol.for("@libp2p/service-capabilities"),j2=Symbol.for("@libp2p/service-dependencies");function N4(r){return r[Symbol.asyncIterator]!=null}function L4(r){if(N4(r))return(async()=>{for await(let e of r);})();for(let e of r);}var sn=L4;var Es=bs(Q2(),1);var an=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},As=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Z2=r=>globalThis.DOMException===void 0?new As(r):new DOMException(r),Y2=r=>{let e=r.reason===void 0?Z2("This operation was aborted."):r.reason;return e instanceof Error?e:Z2(e)};function er(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:s={setTimeout,clearTimeout}}=e,o,c=new Promise((l,u)=>{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:h}=e;h.aborted&&u(Y2(h));let p=()=>{u(Y2(h))};h.addEventListener("abort",p,{once:!0}),r.finally(()=>{h.removeEventListener("abort",p)})}if(t===Number.POSITIVE_INFINITY){r.then(l,u);return}let f=new an;o=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(h){u(h)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?l():i instanceof Error?u(i):(f.message=i??`Promise timed out after ${t} milliseconds`,u(f))},t),(async()=>{try{l(await r)}catch(h){u(h)}})()}).finally(()=>{c.clear()});return c.clear=()=>{s.clearTimeout.call(void 0,o),o=void 0},c}function Ss(r,e,t){let n=0,i=r.length;for(;i>0;){let s=Math.trunc(i/2),o=n+s;t(r[o],e)<=0?(n=++o,i-=s+1):i=s}return n}var cn=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 i=Ss(this.#e,n,(s,o)=>o.priority-s.priority);this.#e.splice(i,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 br=class extends Es.default{#e;#r;#s=0;#a;#c;#p=0;#n;#l;#t;#g;#i=0;#u;#o;#m;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:cn,...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.#r=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#a=e.intervalCap,this.#c=e.interval,this.#t=new e.queueClass,this.#g=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#m=e.throwOnTimeout===!0,this.#o=e.autoStart===!1}get#b(){return this.#r||this.#s<this.#a}get#x(){return this.#i<this.#u}#v(){this.#i--,this.#f(),this.emit("next")}#E(){this.#w(),this.#y(),this.#l=void 0}get#A(){let e=Date.now();if(this.#n===void 0){let t=this.#p-e;if(t<0)this.#s=this.#e?this.#i:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#E()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#n&&clearInterval(this.#n),this.#n=void 0,this.emit("empty"),this.#i===0&&this.emit("idle"),!1;if(!this.#o){let e=!this.#A;if(this.#b&&this.#x){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#r||this.#n!==void 0||(this.#n=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#s===0&&this.#i===0&&this.#n&&(clearInterval(this.#n),this.#n=void 0),this.#s=this.#e?this.#i:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#u}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.#u=e,this.#h()}async#S(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.#m,...t},new Promise((n,i)=>{this.#t.enqueue(async()=>{this.#i++,this.#s++;try{t.signal?.throwIfAborted();let s=e({signal:t.signal});t.timeout&&(s=er(Promise.resolve(s),{milliseconds:t.timeout})),t.signal&&(s=Promise.race([s,this.#S(t.signal)]));let o=await s;n(o),this.emit("completed",o)}catch(s){if(s instanceof an&&!t.throwOnTimeout){n();return}i(s),this.emit("error",s)}finally{this.#v()}},t),this.emit("add"),this.#f()})}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.#g}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.#i===0&&this.#t.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#i}get isPaused(){return this.#o}};var Lt={},xr=r=>{r.addEventListener("message",e=>{xr.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{xr.dispatchEvent("message",r,e)})};xr.addEventListener=(r,e)=>{Lt[r]==null&&(Lt[r]=[]),Lt[r].push(e)};xr.removeEventListener=(r,e)=>{Lt[r]!=null&&(Lt[r]=Lt[r].filter(t=>t===e))};xr.dispatchEvent=function(r,e,t){Lt[r]!=null&&Lt[r].forEach(n=>n(e,t))};var Bs=xr;var Is="lock:worker:request-read",ks="lock:worker:release-read",Ts="lock:master:grant-read",Rs="lock:worker:request-write",Ps="lock:worker:release-write",Ns="lock:master:grant-write";var X2=(r=21)=>Math.random().toString().substring(2);var J2=(r,e,t,n,i)=>(s,o)=>{if(o.data.type!==t)return;let a={type:o.data.type,name:o.data.name,identifier:o.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{s.postMessage({type:i,name:a.name,identifier:a.identifier}),await new Promise(c=>{let l=u=>{if(u?.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===n&&f.identifier===a.identifier&&(s.removeEventListener("message",l),c())};s.addEventListener("message",l)})}}}))},e0=(r,e,t,n)=>async()=>{let i=X2();return globalThis.postMessage({type:e,identifier:i,name:r}),new Promise(s=>{let o=a=>{if(a?.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===t&&c.identifier===i&&(globalThis.removeEventListener("message",o),s(()=>{globalThis.postMessage({type:n,identifier:i,name:r})}))};globalThis.addEventListener("message",o)})},U4={singleProcess:!1},t0=r=>{if(r=Object.assign({},U4,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Bs.addEventListener("message",J2(t,"requestReadLock",Is,ks,Ts)),Bs.addEventListener("message",J2(t,"requestWriteLock",Rs,Ps,Ns)),t}return{isWorker:!0,readLock:t=>e0(t,Is,Ts,ks),writeLock:t=>e0(t,Rs,Ns,Ps)}};var tr={},_t;async function Ls(r,e){let t,n=new Promise(i=>{t=i});return r.add(async()=>er((async()=>{await new Promise(i=>{t(()=>{i()})})})(),{milliseconds:e.timeout})),n}var D4=(r,e)=>{if(_t.isWorker===!0)return{readLock:_t.readLock(r,e),writeLock:_t.writeLock(r,e)};let t=new br({concurrency:1}),n;return{async readLock(){if(n!=null)return Ls(n,e);n=new br({concurrency:e.concurrency,autoStart:!1});let i=n,s=Ls(n,e);return t.add(async()=>{i.start(),await i.onIdle().then(()=>{n===i&&(n=null)})}),s},async writeLock(){return n=null,Ls(t,e)}}},O4={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function _s(r){let e=Object.assign({},O4,r);return _t==null&&(_t=t0(e),_t.isWorker!==!0&&(_t.addEventListener("requestReadLock",t=>{tr[t.data.name]!=null&&tr[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),_t.addEventListener("requestWriteLock",async t=>{tr[t.data.name]!=null&&tr[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),tr[e.name]==null&&(tr[e.name]=D4(e.name,e)),tr[e.name]}function se(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var vr=1e3,Cs=60*vr,Zn=60*Cs,r0=36*Zn,n0="/ipfs/kad/1.0.0",i0=24*Zn;var s0=2*Zn,o0=10,a0=16384,c0=Zn,ll=10*vr;var Yn=20,Er=3,l0=5*Cs,u0=vr,f0=5*vr,h0=5*Cs,d0=30*vr,p0=180*vr,Us=`${$2}-kad-dht`;function _e(r=0){return new Uint8Array(r)}function ge(r=0){return new Uint8Array(r)}var M4=Math.pow(2,7),V4=Math.pow(2,14),F4=Math.pow(2,21),Ds=Math.pow(2,28),Os=Math.pow(2,35),Ms=Math.pow(2,42),Vs=Math.pow(2,49),z=128,Ee=127;function oe(r){if(r<M4)return 1;if(r<V4)return 2;if(r<F4)return 3;if(r<Ds)return 4;if(r<Os)return 5;if(r<Ms)return 6;if(r<Vs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Fs(r,e,t=0){switch(oe(r)){case 8:e[t++]=r&255|z,r/=128;case 7:e[t++]=r&255|z,r/=128;case 6:e[t++]=r&255|z,r/=128;case 5:e[t++]=r&255|z,r/=128;case 4:e[t++]=r&255|z,r>>>=7;case 3:e[t++]=r&255|z,r>>>=7;case 2:e[t++]=r&255|z,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function H4(r,e,t=0){switch(oe(r)){case 8:e.set(t++,r&255|z),r/=128;case 7:e.set(t++,r&255|z),r/=128;case 6:e.set(t++,r&255|z),r/=128;case 5:e.set(t++,r&255|z),r/=128;case 4:e.set(t++,r&255|z),r>>>=7;case 3:e.set(t++,r&255|z),r>>>=7;case 2:e.set(t++,r&255|z),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Hs(r,e){let t=r[e],n=0;if(n+=t&Ee,t<z||(t=r[e+1],n+=(t&Ee)<<7,t<z)||(t=r[e+2],n+=(t&Ee)<<14,t<z)||(t=r[e+3],n+=(t&Ee)<<21,t<z)||(t=r[e+4],n+=(t&Ee)*Ds,t<z)||(t=r[e+5],n+=(t&Ee)*Os,t<z)||(t=r[e+6],n+=(t&Ee)*Ms,t<z)||(t=r[e+7],n+=(t&Ee)*Vs,t<z))return n;throw new RangeError("Could not decode varint")}function q4(r,e){let t=r.get(e),n=0;if(n+=t&Ee,t<z||(t=r.get(e+1),n+=(t&Ee)<<7,t<z)||(t=r.get(e+2),n+=(t&Ee)<<14,t<z)||(t=r.get(e+3),n+=(t&Ee)<<21,t<z)||(t=r.get(e+4),n+=(t&Ee)*Ds,t<z)||(t=r.get(e+5),n+=(t&Ee)*Os,t<z)||(t=r.get(e+6),n+=(t&Ee)*Ms,t<z)||(t=r.get(e+7),n+=(t&Ee)*Vs,t<z))return n;throw new RangeError("Could not decode varint")}function qe(r,e,t=0){return e==null&&(e=ge(oe(r))),e instanceof Uint8Array?Fs(r,e,t):H4(r,e,t)}function Me(r,e=0){return r instanceof Uint8Array?Hs(r,e):q4(r,e)}var qs=new Float32Array([-0]),Ct=new Uint8Array(qs.buffer);function g0(r,e,t){qs[0]=r,e[t]=Ct[0],e[t+1]=Ct[1],e[t+2]=Ct[2],e[t+3]=Ct[3]}function m0(r,e){return Ct[0]=r[e],Ct[1]=r[e+1],Ct[2]=r[e+2],Ct[3]=r[e+3],qs[0]}var Ks=new Float64Array([-0]),Ae=new Uint8Array(Ks.buffer);function y0(r,e,t){Ks[0]=r,e[t]=Ae[0],e[t+1]=Ae[1],e[t+2]=Ae[2],e[t+3]=Ae[3],e[t+4]=Ae[4],e[t+5]=Ae[5],e[t+6]=Ae[6],e[t+7]=Ae[7]}function w0(r,e){return Ae[0]=r[e],Ae[1]=r[e+1],Ae[2]=r[e+2],Ae[3]=r[e+3],Ae[4]=r[e+4],Ae[5]=r[e+5],Ae[6]=r[e+6],Ae[7]=r[e+7],Ks[0]}var K4=BigInt(Number.MAX_SAFE_INTEGER),$4=BigInt(Number.MIN_SAFE_INTEGER),Ve=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return nr;if(e<K4&&e>$4)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,i=e-(n<<32n);return t&&(n=~n|0n,i=~i|0n,++i>b0&&(i=0n,++n>b0&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(e){if(e===0)return nr;let t=e<0;t&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return t&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):nr}},nr=new Ve(0,0);nr.toBigInt=function(){return 0n};nr.zzEncode=nr.zzDecode=function(){return this};nr.length=function(){return 1};var b0=4294967296n;function x0(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function v0(r,e,t){if(t-e<1)return"";let i,s=[],o=0,a;for(;e<t;)a=r[e++],a<128?s[o++]=a:a>191&&a<224?s[o++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[o++]=55296+(a>>10),s[o++]=56320+(a&1023)):s[o++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,o>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i!=null?(o>0&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))}function $s(r,e,t){let n=t,i,s;for(let o=0;o<r.length;++o)i=r.charCodeAt(o),i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&((s=r.charCodeAt(o+1))&64512)===56320?(i=65536+((i&1023)<<10)+(s&1023),++o,e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128);return t-n}function Ge(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Xn(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var zs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ge(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ge(this,4);return Xn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ge(this,4);return Xn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ge(this,4);let e=m0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ge(this,4);let e=w0(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Ge(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return v0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ge(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ge(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ve(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Ge(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Ge(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ge(this,8);let e=Xn(this.buf,this.pos+=4),t=Xn(this.buf,this.pos+=4);return new Ve(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Hs(this.buf,this.pos);return this.pos+=oe(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Gs(r){return new zs(r instanceof Uint8Array?r:r.subarray())}function tt(r,e,t){let n=Gs(r);return e.decode(n,void 0,t)}var Ys={};ke(Ys,{base10:()=>Z4});var vl=new Uint8Array(0);function A0(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 dt(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 S0(r){return new TextEncoder().encode(r)}function B0(r){return new TextDecoder().decode(r)}function z4(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 i=0;i<r.length;i++){var s=r.charAt(i),o=s.charCodeAt(0);if(t[o]!==255)throw new TypeError(s+" is ambiguous");t[o]=i}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var w=0,d=0,x=0,E=y.length;x!==E&&y[x]===0;)x++,w++;for(var g=(E-x)*u+1>>>0,A=new Uint8Array(g);x!==E;){for(var R=y[x],T=0,I=g-1;(R!==0||T<d)&&I!==-1;I--,T++)R+=256*A[I]>>>0,A[I]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");d=T,x++}for(var k=g-d;k!==g&&A[k]===0;)k++;for(var L=c.repeat(w);k<g;++k)L+=r.charAt(A[k]);return L}function h(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var w=0;if(y[w]!==" "){for(var d=0,x=0;y[w]===c;)d++,w++;for(var E=(y.length-w)*l+1>>>0,g=new Uint8Array(E);y[w];){var A=t[y.charCodeAt(w)];if(A===255)return;for(var R=0,T=E-1;(A!==0||R<x)&&T!==-1;T--,R++)A+=a*g[T]>>>0,g[T]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");x=R,w++}if(y[w]!==" "){for(var I=E-x;I!==E&&g[I]===0;)I++;for(var k=new Uint8Array(d+(E-I)),L=d;I!==E;)k[L++]=g[I++];return k}}}function p(y){var w=h(y);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:p}}var G4=z4,j4=G4,k0=j4;var js=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")}},Ws=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let i=t.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 T0(this,e)}},Qs=class{decoders;constructor(e){this.decoders=e}or(e){return T0(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 T0(r,e){return new Qs({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Zs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new js(e,t,n),this.decoder=new Ws(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ar({name:r,prefix:e,encode:t,decode:n}){return new Zs(r,e,t,n)}function Ut({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=k0(t,r);return Ar({prefix:e,name:r,encode:n,decode:s=>dt(i(s))})}function W4(r,e,t,n){let i={};for(let u=0;u<e.length;++u)i[e[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),a=0,c=0,l=0;for(let u=0;u<s;++u){let f=i[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,o[l++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function Q4(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,s="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,s+=e[i&a>>o];if(o!==0&&(s+=e[i&a<<t-o]),n)for(;s.length*t&7;)s+="=";return s}function ne({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Ar({prefix:e,name:r,encode(i){return Q4(i,n,t)},decode(i){return W4(i,n,t,r)}})}var Z4=Ut({prefix:"9",name:"base10",alphabet:"0123456789"});var Xs={};ke(Xs,{base16:()=>Y4,base16upper:()=>X4});var Y4=ne({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),X4=ne({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Js={};ke(Js,{base2:()=>J4});var J4=ne({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var eo={};ke(eo,{base256emoji:()=>i5});var R0=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}"),e5=R0.reduce((r,e,t)=>(r[t]=e,r),[]),t5=R0.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function r5(r){return r.reduce((e,t)=>(e+=e5[t],e),"")}function n5(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=t5[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}var i5=Ar({prefix:"\u{1F680}",name:"base256emoji",encode:r5,decode:n5});var to={};ke(to,{base32:()=>pt,base32hex:()=>c5,base32hexpad:()=>u5,base32hexpadupper:()=>f5,base32hexupper:()=>l5,base32pad:()=>o5,base32padupper:()=>a5,base32upper:()=>s5,base32z:()=>h5});var pt=ne({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),s5=ne({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),o5=ne({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),a5=ne({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),c5=ne({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),l5=ne({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),u5=ne({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),f5=ne({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),h5=ne({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ro={};ke(ro,{base36:()=>ln,base36upper:()=>d5});var ln=Ut({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),d5=Ut({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var no={};ke(no,{base58btc:()=>Y,base58flickr:()=>p5});var Y=Ut({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),p5=Ut({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var io={};ke(io,{base64:()=>g5,base64pad:()=>m5,base64url:()=>y5,base64urlpad:()=>w5});var g5=ne({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),m5=ne({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),y5=ne({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),w5=ne({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var so={};ke(so,{base8:()=>b5});var b5=ne({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oo={};ke(oo,{identity:()=>x5});var x5=Ar({prefix:"\0",name:"identity",encode:r=>B0(r),decode:r=>S0(r)});var Ol=new TextEncoder,Ml=new TextDecoder;var P0=85;var co={};ke(co,{identity:()=>gt});var E5=C0,L0=128,A5=127,S5=~A5,B5=Math.pow(2,31);function C0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=B5;)e[t++]=r&255|L0,r/=128;for(;r&S5;)e[t++]=r&255|L0,r>>>=7;return e[t]=r|0,C0.bytes=t-n+1,e}var I5=ao,k5=128,_0=127;function ao(r,n){var t=0,n=n||0,i=0,s=n,o,a=r.length;do{if(s>=a)throw ao.bytes=0,new RangeError("Could not decode varint");o=r[s++],t+=i<28?(o&_0)<<i:(o&_0)*Math.pow(2,i),i+=7}while(o>=k5);return ao.bytes=s-n,t}var T5=Math.pow(2,7),R5=Math.pow(2,14),P5=Math.pow(2,21),N5=Math.pow(2,28),L5=Math.pow(2,35),_5=Math.pow(2,42),C5=Math.pow(2,49),U5=Math.pow(2,56),D5=Math.pow(2,63),O5=function(r){return r<T5?1:r<R5?2:r<P5?3:r<N5?4:r<L5?5:r<_5?6:r<C5?7:r<U5?8:r<D5?9:10},M5={encode:E5,decode:I5,encodingLength:O5},V5=M5,un=V5;function fn(r,e=0){return[un.decode(r,e),un.decode.bytes]}function Sr(r,e,t=0){return un.encode(r,e,t),e}function Br(r){return un.encodingLength(r)}function je(r,e){let t=e.byteLength,n=Br(r),i=n+Br(t),s=new Uint8Array(i+t);return Sr(r,s,0),Sr(t,s,n),s.set(e,i),new Ir(r,t,e,s)}function me(r){let e=dt(r),[t,n]=fn(e),[i,s]=fn(e.subarray(n)),o=e.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Ir(t,i,o,e)}function U0(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&A0(r.bytes,t.bytes)}}var Ir=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var D0=0,F5="identity",O0=dt;function H5(r){return je(D0,O0(r))}var gt={code:D0,name:F5,encode:O0,digest:H5};var fo={};ke(fo,{sha256:()=>mt,sha512:()=>q5});function uo({name:r,code:e,encode:t}){return new lo(r,e,t)}var lo=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?je(this.code,t):t.then(n=>je(this.code,n))}else throw Error("Unknown type, must be binary type")}};function V0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var mt=uo({name:"sha2-256",code:18,encode:V0("SHA-256")}),q5=uo({name:"sha2-512",code:19,encode:V0("SHA-512")});function F0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return $5(t,ho(r),e??Y.encoder);default:return z5(t,ho(r),e??pt.encoder)}}var H0=new WeakMap;function ho(r){let e=H0.get(r);if(e==null){let t=new Map;return H0.set(r,t),t}return e}var re=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}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!==hn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==G5)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=je(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&&U0(e.multihash,n.multihash)}toString(e){return F0(this,e)}toJSON(){return{"/":F0(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:i,multihash:s,bytes:o}=t;return new r(n,i,s,o??q0(n,i,s.bytes))}else if(t[j5]===!0){let{version:n,multihash:i,code:s}=t,o=me(i);return r.create(n,s,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!==hn)throw new Error(`Version 0 CID must use dag-pb (code: ${hn}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=q0(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,hn,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,i=dt(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=i.subarray(t.multihashSize-t.digestSize),o=new Ir(t.multihashCode,t.digestSize,s,i);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,h]=fn(e.subarray(t));return t+=h,f},i=n(),s=hn;if(i===18?(i=0,t=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=t,a=n(),c=n(),l=t+c,u=l-o;return{version:i,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,i]=K5(e,t),s=r.decode(i);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ho(s).set(n,e),s}};function K5(r,e){switch(r[0]){case"Q":{let t=e??Y;return[Y.prefix,t.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let t=e??Y;return[Y.prefix,t.decode(r)]}case pt.prefix:{let t=e??pt;return[pt.prefix,t.decode(r)]}case ln.prefix:{let t=e??ln;return[ln.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 $5(r,e,t){let{prefix:n}=t;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return i}function z5(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let s=t.encode(r);return e.set(n,s),s}else return i}var hn=112,G5=18;function q0(r,e,t){let n=Br(r),i=n+Br(e),s=new Uint8Array(i+t.byteLength);return Sr(r,s,0),Sr(e,s,n),s.set(t,i),s}var j5=Symbol.for("@ipld/js-cid/CID");var dn={...oo,...Js,...so,...Ys,...Xs,...to,...ro,...no,...io,...eo},o9={...fo,...co};function $0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var K0=$0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),po=$0("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=ge(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),W5={utf8:K0,"utf-8":K0,hex:dn.base16,latin1:po,ascii:po,binary:po,...dn},e1=W5;function Q(r,e="utf8"){let t=e1[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function go(r){let e=r??8192,t=e>>>1,n,i=e;return function(o){if(o<1||o>t)return ge(o);i+o>e&&(n=ge(e),i=0);let a=n.subarray(i,i+=o);return i&7&&(i=(i|7)+1),a}}var ir=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function mo(){}var wo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Q5=go();function Z5(r){return globalThis.Buffer!=null?ge(r):Q5(r)}var gn=class{len;head;tail;states;constructor(){this.len=0,this.head=new ir(mo,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new ir(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new bo((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(t1,10,Ve.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Ve.fromBigInt(e);return this._push(t1,t.length(),t)}uint64Number(e){return this._push(Fs,oe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Ve.fromBigInt(e).zzEncode();return this._push(t1,t.length(),t)}sint64Number(e){let t=Ve.fromNumber(e).zzEncode();return this._push(t1,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(yo,1,e?1:0)}fixed32(e){return this._push(pn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Ve.fromBigInt(e);return this._push(pn,4,t.lo)._push(pn,4,t.hi)}fixed64Number(e){let t=Ve.fromNumber(e);return this._push(pn,4,t.lo)._push(pn,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(g0,4,e)}double(e){return this._push(y0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(yo,1,0):this.uint32(t)._push(X5,t,e)}string(e){let t=x0(e);return t!==0?this.uint32(t)._push($s,t,e):this._push(yo,1,0)}fork(){return this.states=new wo(this),this.head=this.tail=new ir(mo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ir(mo,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Z5(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function yo(r,e,t){e[t]=r&255}function Y5(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var bo=class extends ir{next;constructor(e,t){super(Y5,e,t),this.next=void 0}};function t1(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function pn(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function X5(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(gn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(J5,e,r),this},gn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(e6,e,r),this});function J5(r,e,t){e.set(r,t)}function e6(r,e,t){r.length<40?$s(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Q(r),t)}function xo(){return new gn}function rt(r,e){let t=xo();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var kr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(kr||(kr={}));function r1(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Tr(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(s,o){let a=e(s);o.int32(a)},n=function(s){let o=s.int32();return e(o)};return r1("enum",kr.VARINT,t,n)}function nt(r,e){return r1("message",kr.LENGTH_DELIMITED,r,e)}var Rr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var mn;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.key!=null&&t.key.byteLength>0&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&t.value.byteLength>0&&(n.uint32(18),n.bytes(t.value)),t.timeReceived!=null&&t.timeReceived!==""&&(n.uint32(42),n.string(t.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={key:_e(0),value:_e(0),timeReceived:""},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.key=t.bytes();break}case 2:{s.value=t.bytes();break}case 5:{s.timeReceived=t.string();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(mn||(mn={}));function z0(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),i=String(r.getUTCHours()).padStart(2,"0"),s=String(r.getUTCMinutes()).padStart(2,"0"),o=String(r.getUTCSeconds()).padStart(2,"0"),a=r.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${t}-${n}T${i}:${s}:${o}.${c}Z`}function G0(r){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),t=String(r).trim().match(e);if(t==null)throw new Error("Invalid format");let n=parseInt(t[1],10),i=parseInt(t[2],10)-1,s=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),c=parseInt(t[6],10),l=parseInt(t[7].slice(0,-6),10);return new Date(Date.UTC(n,i,s,o,a,c,l))}var ue=class r{key;value;timeReceived;constructor(e,t,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(t instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=t,this.timeReceived=n}serialize(){return mn.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:z0(this.timeReceived)}}static deserialize(e){let t=mn.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=G0(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new r(e.key,e.value,t)}};function r6(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var j0=r6;function n6(r){return r[Symbol.asyncIterator]!=null}function i6(r,e){let t=0;if(n6(r))return async function*(){for await(let c of r)yield e(c,t++)}();let n=j0(r),{value:i,done:s}=n.next();if(s===!0)return function*(){}();let o=e(i,t++);if(typeof o.then=="function")return async function*(){yield await o;for await(let c of n)yield e(c,t++)}();let a=e;return function*(){yield o;for(let c of n)yield a(c,t++)}()}var Pr=i6;var n1=globalThis.CustomEvent??Event;async function*sr(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered==null?!1:e.ordered,i=new EventTarget,s=[],o=se(),a=se(),c=!1,l,u=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let y of r){if(s.length===t&&(o=se(),await o.promise),u)break;let w={done:!1};s.push(w),y().then(d=>{w.done=!0,w.ok=!0,w.value=d,i.dispatchEvent(new n1("task-complete"))},d=>{w.done=!0,w.err=d,i.dispatchEvent(new n1("task-complete"))})}c=!0,i.dispatchEvent(new n1("task-complete"))}catch(y){l=y,i.dispatchEvent(new n1("task-complete"))}});function f(){return n?s[0]?.done:!!s.find(y=>y.done)}function*h(){for(;s.length>0&&s[0].done;){let y=s[0];if(s.shift(),y.ok)yield y.value;else throw u=!0,o.resolve(),y.err;o.resolve()}}function*p(){for(;f();)for(let y=0;y<s.length;y++)if(s[y].done){let w=s[y];if(s.splice(y,1),y--,w.ok)yield w.value;else throw u=!0,o.resolve(),w.err;o.resolve()}}for(;;){if(f()||(a=se(),await a.promise),l!=null)throw l;if(n?yield*h():yield*p(),c&&s.length===0)break}}var i1=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Nr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new i1(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new i1(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var vo=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Lr(r={}){return s6(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function s6(r,e){e=e??{};let t=e.onEnd,n=new Nr,i,s,o,a=se(),c=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((d,x)=>{s=E=>{s=null,n.push(E);try{d(r(n))}catch(g){x(g)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=se()})}},l=d=>s!=null?s(d):(n.push(d),i),u=d=>(n=new Nr,s!=null?s({error:d}):(n.push({error:d}),i)),f=d=>{if(o)return i;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},h=d=>o?i:(o=!0,d!=null?u(d):l({done:!0})),p=()=>(n=new Nr,h(),{done:!0}),y=d=>(h(d),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:p,throw:y,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let x=d?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,g;x!=null&&(E=new Promise((A,R)=>{g=()=>{R(new vo)},x.addEventListener("abort",g)}));try{await Promise.race([a.promise,E])}finally{g!=null&&x!=null&&x?.removeEventListener("abort",g)}}},t==null)return i;let w=i;return i={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(d){return w.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(d){return w.end(d),t!=null&&(t(d),t=void 0),i},get readableLength(){return w.readableLength},onEmpty:d=>w.onEmpty(d)},i}function o6(r){return r[Symbol.asyncIterator]!=null}function a6(...r){let e=[];for(let t of r)o6(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Lr({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let i of n)t.push(i)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var s1=a6;function Dt(r,...e){if(r==null)throw new Error("Empty pipeline");if(Eo(r)){let n=r;r=()=>n.source}else if(Q0(r)||W0(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Eo(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Eo(t[n])&&(t[n]=l6(t[n]));return c6(...t)}var c6=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},W0=r=>r?.[Symbol.asyncIterator]!=null,Q0=r=>r?.[Symbol.iterator]!=null,Eo=r=>r==null?!1:r.sink!=null&&r.source!=null,l6=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Lr({objectMode:!0});t.then(()=>{n.end()},o=>{n.end(o)});let i,s=r.source;if(W0(s))i=async function*(){yield*s,n.end()};else if(Q0(s))i=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return s1(n,i())}return r.source};function X(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}var Ot=class extends Error{constructor(e="Query error"){super(e),this.name="QueryError"}},o1=class extends Error{constructor(e="Query aborted"){super(e),this.name="QueryAbortedError"}},a1=class extends Error{constructor(e="Invalid record"){super(e),this.name="InvalidRecordError"}},c1=class extends Error{constructor(e="No selector function configured for prefix"){super(e),this.name="MissingSelectorError"}};var Z0;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.key!=null&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&(n.uint32(18),n.bytes(t.value)),t.author!=null&&(n.uint32(26),n.bytes(t.author)),t.signature!=null&&(n.uint32(34),n.bytes(t.signature)),t.timeReceived!=null&&(n.uint32(42),n.string(t.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.key=t.bytes();break}case 2:{s.value=t.bytes();break}case 3:{s.author=t.bytes();break}case 4:{s.signature=t.bytes();break}case 5:{s.timeReceived=t.string();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(Z0||(Z0={}));var O;(function(r){r.PUT_VALUE="PUT_VALUE",r.GET_VALUE="GET_VALUE",r.ADD_PROVIDER="ADD_PROVIDER",r.GET_PROVIDERS="GET_PROVIDERS",r.FIND_NODE="FIND_NODE",r.PING="PING"})(O||(O={}));var l1;(function(r){r[r.PUT_VALUE=0]="PUT_VALUE",r[r.GET_VALUE=1]="GET_VALUE",r[r.ADD_PROVIDER=2]="ADD_PROVIDER",r[r.GET_PROVIDERS=3]="GET_PROVIDERS",r[r.FIND_NODE=4]="FIND_NODE",r[r.PING=5]="PING"})(l1||(l1={}));(function(r){r.codec=()=>Tr(l1)})(O||(O={}));var Cr;(function(r){r.NOT_CONNECTED="NOT_CONNECTED",r.CONNECTED="CONNECTED",r.CAN_CONNECT="CAN_CONNECT",r.CANNOT_CONNECT="CANNOT_CONNECT"})(Cr||(Cr={}));var Ao;(function(r){r[r.NOT_CONNECTED=0]="NOT_CONNECTED",r[r.CONNECTED=1]="CONNECTED",r[r.CAN_CONNECT=2]="CAN_CONNECT",r[r.CANNOT_CONNECT=3]="CANNOT_CONNECT"})(Ao||(Ao={}));(function(r){r.codec=()=>Tr(Ao)})(Cr||(Cr={}));var _r;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{if(i.lengthDelimited!==!1&&n.fork(),t.id!=null&&t.id.byteLength>0&&(n.uint32(10),n.bytes(t.id)),t.multiaddrs!=null)for(let s of t.multiaddrs)n.uint32(18),n.bytes(s);t.connection!=null&&(n.uint32(24),Cr.codec().encode(t.connection,n)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={id:_e(0),multiaddrs:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.id=t.bytes();break}case 2:{if(i.limits?.multiaddrs!=null&&s.multiaddrs.length===i.limits.multiaddrs)throw new Rr('Decode error - map field "multiaddrs" had too many elements');s.multiaddrs.push(t.bytes());break}case 3:{s.connection=Cr.codec().decode(t);break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(_r||(_r={}));var yt;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{if(i.lengthDelimited!==!1&&n.fork(),t.type!=null&&l1[t.type]!==0&&(n.uint32(8),O.codec().encode(t.type,n)),t.clusterLevel!=null&&(n.uint32(80),n.int32(t.clusterLevel)),t.key!=null&&(n.uint32(18),n.bytes(t.key)),t.record!=null&&(n.uint32(26),n.bytes(t.record)),t.closer!=null)for(let s of t.closer)n.uint32(66),_r.codec().encode(s,n);if(t.providers!=null)for(let s of t.providers)n.uint32(74),_r.codec().encode(s,n);i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={type:O.PUT_VALUE,closer:[],providers:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.type=O.codec().decode(t);break}case 10:{s.clusterLevel=t.int32();break}case 2:{s.key=t.bytes();break}case 3:{s.record=t.bytes();break}case 8:{if(i.limits?.closer!=null&&s.closer.length===i.limits.closer)throw new Rr('Decode error - map field "closer" had too many elements');s.closer.push(_r.codec().decode(t,t.uint32(),{limits:i.limits?.closer$}));break}case 9:{if(i.limits?.providers!=null&&s.providers.length===i.limits.providers)throw new Rr('Decode error - map field "providers" had too many elements');s.providers.push(_r.codec().decode(t,t.uint32(),{limits:i.limits?.providers$}));break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(yt||(yt={}));function So(r,e={}){let t={...r,name:"SEND_QUERY",type:0,messageName:r.type,messageType:r.type};return e.onProgress?.(new CustomEvent("kad-dht:query:send-query",{detail:t})),t}function yn(r,e={}){let t={...r,name:"PEER_RESPONSE",type:1,messageName:r.messageType,closer:r.closer??[],providers:r.providers??[]};return e.onProgress?.(new CustomEvent("kad-dht:query:peer-response",{detail:t})),t}function u1(r,e={}){let t={...r,name:"FINAL_PEER",type:2};return e.onProgress?.(new CustomEvent("kad-dht:query:final-peer",{detail:t})),t}function Fe(r,e={}){let t={...r,name:"QUERY_ERROR",type:3};return e.onProgress?.(new CustomEvent("kad-dht:query:query-error",{detail:t})),t}function Bo(r,e={}){let t={...r,name:"PROVIDER",type:4};return e.onProgress?.(new CustomEvent("kad-dht:query:provider",{detail:t})),t}function wn(r,e={}){let t={...r,name:"VALUE",type:5};return e.onProgress?.(new CustomEvent("kad-dht:query:value",{detail:t})),t}function Io(r,e={}){let t={...r,name:"DIAL_PEER",type:7};return e.onProgress?.(new CustomEvent("kad-dht:query:dial-peer",{detail:t})),t}function D(r,e="utf8"){let t=e1[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function Y0(r,e,t){if(t.length===0)throw new $("No records given");let i=D(e).split("/");if(i.length<3)throw new $("Record key does not have a selector function");let s=r[i[1].toString()];if(s==null)throw new c1(`No selector function configured for key type "${i[1]}"`);return t.length===1?0:s(e,t)}function u6(r,e){return 0}var X0={pk:u6};function J0(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function f6(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ur(r,...e){if(!f6(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function e3(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");J0(r.outputLen),J0(r.blockLen)}function Dr(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function t3(r,e){Ur(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var or=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var f1=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),We=(r,e)=>r<<32-e|r>>>e;var yu=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function r3(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function bn(r){return typeof r=="string"&&(r=r3(r)),Ur(r),r}function ko(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];Ur(i),e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let s=r[n];t.set(s,i),i+=s.length}return t}var Or=class{clone(){return this._cloneInto()}},wu={}.toString;function h1(r){let e=n=>r().update(bn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Mr(r=32){if(or&&typeof or.getRandomValues=="function")return or.getRandomValues(new Uint8Array(r));if(or&&typeof or.randomBytes=="function")return or.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function h6(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),s=BigInt(4294967295),o=Number(t>>i&s),a=Number(t&s),c=n?4:0,l=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+l,a,n)}var n3=(r,e,t)=>r&e^~r&t,i3=(r,e,t)=>r&e^r&t^e&t,Vr=class extends Or{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=f1(this.buffer)}update(e){Dr(this);let{view:t,buffer:n,blockLen:i}=this;e=bn(e);let s=e.length;for(let o=0;o<s;){let a=Math.min(i-this.pos,s-o);if(a===i){let c=f1(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Dr(this),t3(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let f=o;f<i;f++)t[f]=0;h6(n,i-8,BigInt(this.length*8),s),this.process(n,0);let a=f1(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return e.length=i,e.pos=a,e.finished=s,e.destroyed=o,i%t&&e.buffer.set(n),e}};var d1=BigInt(4294967295),To=BigInt(32);function s3(r,e=!1){return e?{h:Number(r&d1),l:Number(r>>To&d1)}:{h:Number(r>>To&d1)|0,l:Number(r&d1)|0}}function d6(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:s,l:o}=s3(r[i],e);[t[i],n[i]]=[s,o]}return[t,n]}var p6=(r,e)=>BigInt(r>>>0)<<To|BigInt(e>>>0),g6=(r,e,t)=>r>>>t,m6=(r,e,t)=>r<<32-t|e>>>t,y6=(r,e,t)=>r>>>t|e<<32-t,w6=(r,e,t)=>r<<32-t|e>>>t,b6=(r,e,t)=>r<<64-t|e>>>t-32,x6=(r,e,t)=>r>>>t-32|e<<64-t,v6=(r,e)=>e,E6=(r,e)=>r,A6=(r,e,t)=>r<<t|e>>>32-t,S6=(r,e,t)=>e<<t|r>>>32-t,B6=(r,e,t)=>e<<t-32|r>>>64-t,I6=(r,e,t)=>r<<t-32|e>>>64-t;function k6(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var T6=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),R6=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,P6=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),N6=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,L6=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),_6=(r,e,t,n,i,s)=>e+t+n+i+s+(r/2**32|0)|0;var C6={fromBig:s3,split:d6,toBig:p6,shrSH:g6,shrSL:m6,rotrSH:y6,rotrSL:w6,rotrBH:b6,rotrBL:x6,rotr32H:v6,rotr32L:E6,rotlSH:A6,rotlSL:S6,rotlBH:B6,rotlBL:I6,add:k6,add3L:T6,add3H:R6,add4L:P6,add4H:N6,add5H:_6,add5L:L6},U=C6;var[U6,D6]=U.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Mt=new Uint32Array(80),Vt=new Uint32Array(80),Ro=class extends Vr{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:h,Gh:p,Gl:y,Hh:w,Hl:d}=this;return[e,t,n,i,s,o,a,c,l,u,f,h,p,y,w,d]}set(e,t,n,i,s,o,a,c,l,u,f,h,p,y,w,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=y|0,this.Hh=w|0,this.Hl=d|0}process(e,t){for(let g=0;g<16;g++,t+=4)Mt[g]=e.getUint32(t),Vt[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){let A=Mt[g-15]|0,R=Vt[g-15]|0,T=U.rotrSH(A,R,1)^U.rotrSH(A,R,8)^U.shrSH(A,R,7),I=U.rotrSL(A,R,1)^U.rotrSL(A,R,8)^U.shrSL(A,R,7),k=Mt[g-2]|0,L=Vt[g-2]|0,ae=U.rotrSH(k,L,19)^U.rotrBH(k,L,61)^U.shrSH(k,L,6),K=U.rotrSL(k,L,19)^U.rotrBL(k,L,61)^U.shrSL(k,L,6),M=U.add4L(I,K,Vt[g-7],Vt[g-16]),ce=U.add4H(M,T,ae,Mt[g-7],Mt[g-16]);Mt[g]=ce|0,Vt[g]=M|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:p,Fl:y,Gh:w,Gl:d,Hh:x,Hl:E}=this;for(let g=0;g<80;g++){let A=U.rotrSH(f,h,14)^U.rotrSH(f,h,18)^U.rotrBH(f,h,41),R=U.rotrSL(f,h,14)^U.rotrSL(f,h,18)^U.rotrBL(f,h,41),T=f&p^~f&w,I=h&y^~h&d,k=U.add5L(E,R,I,D6[g],Vt[g]),L=U.add5H(k,x,A,T,U6[g],Mt[g]),ae=k|0,K=U.rotrSH(n,i,28)^U.rotrBH(n,i,34)^U.rotrBH(n,i,39),M=U.rotrSL(n,i,28)^U.rotrBL(n,i,34)^U.rotrBL(n,i,39),ce=n&s^n&a^s&a,S=i&o^i&c^o&c;x=w|0,E=d|0,w=p|0,d=y|0,p=f|0,y=h|0,{h:f,l:h}=U.add(l|0,u|0,L|0,ae|0),l=a|0,u=c|0,a=s|0,c=o|0,s=n|0,o=i|0;let P=U.add3L(ae,M,S);n=U.add3H(P,L,K,ce),i=P|0}({h:n,l:i}=U.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:s,l:o}=U.add(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=U.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=U.add(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:y}=U.add(this.Fh|0,this.Fl|0,p|0,y|0),{h:w,l:d}=U.add(this.Gh|0,this.Gl|0,w|0,d|0),{h:x,l:E}=U.add(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,i,s,o,a,c,l,u,f,h,p,y,w,d,x,E)}roundClean(){Mt.fill(0),Vt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var o3=h1(()=>new Ro);var g1={};ke(g1,{aInRange:()=>Ce,abool:()=>Qe,abytes:()=>Fr,bitGet:()=>q6,bitLen:()=>Co,bitMask:()=>vn,bitSet:()=>K6,bytesToHex:()=>bt,bytesToNumberBE:()=>xt,bytesToNumberLE:()=>Ht,concatBytes:()=>vt,createHmacDrbg:()=>Uo,ensureBytes:()=>ie,equalBytes:()=>F6,hexToBytes:()=>cr,hexToNumber:()=>_o,inRange:()=>xn,isBytes:()=>Ft,memoized:()=>ur,notImplemented:()=>z6,numberToBytesBE:()=>qt,numberToBytesLE:()=>lr,numberToHexUnpadded:()=>ar,numberToVarBytesBE:()=>V6,utf8ToBytes:()=>H6,validateObject:()=>it});var Lo=BigInt(0),p1=BigInt(1),O6=BigInt(2);function Ft(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Fr(r){if(!Ft(r))throw new Error("Uint8Array expected")}function Qe(r,e){if(typeof e!="boolean")throw new Error(`${r} must be valid boolean, got "${e}".`)}var M6=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function bt(r){Fr(r);let e="";for(let t=0;t<r.length;t++)e+=M6[r[t]];return e}function ar(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function _o(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var wt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function a3(r){if(r>=wt._0&&r<=wt._9)return r-wt._0;if(r>=wt._A&&r<=wt._F)return r-(wt._A-10);if(r>=wt._a&&r<=wt._f)return r-(wt._a-10)}function cr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,s=0;i<t;i++,s+=2){let o=a3(r.charCodeAt(s)),a=a3(r.charCodeAt(s+1));if(o===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function xt(r){return _o(bt(r))}function Ht(r){return Fr(r),_o(bt(Uint8Array.from(r).reverse()))}function qt(r,e){return cr(r.toString(16).padStart(e*2,"0"))}function lr(r,e){return qt(r,e).reverse()}function V6(r){return cr(ar(r))}function ie(r,e,t){let n;if(typeof e=="string")try{n=cr(e)}catch(s){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${s}`)}else if(Ft(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof t=="number"&&i!==t)throw new Error(`${r} expected ${t} bytes, got ${i}`);return n}function vt(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];Fr(i),e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let s=r[n];t.set(s,i),i+=s.length}return t}function F6(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function H6(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var Po=r=>typeof r=="bigint"&&Lo<=r;function xn(r,e,t){return Po(r)&&Po(e)&&Po(t)&&e<=r&&r<t}function Ce(r,e,t,n){if(!xn(e,t,n))throw new Error(`expected valid ${r}: ${t} <= n < ${n}, got ${typeof e} ${e}`)}function Co(r){let e;for(e=0;r>Lo;r>>=p1,e+=1);return e}function q6(r,e){return r>>BigInt(e)&p1}function K6(r,e,t){return r|(t?p1:Lo)<<BigInt(e)}var vn=r=>(O6<<BigInt(r-1))-p1,No=r=>new Uint8Array(r),c3=r=>Uint8Array.from(r);function Uo(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=No(r),i=No(r),s=0,o=()=>{n.fill(1),i.fill(0),s=0},a=(...f)=>t(i,n,...f),c=(f=No())=>{i=a(c3([0]),f),n=a(),f.length!==0&&(i=a(c3([1]),f),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<e;){n=a();let p=n.slice();h.push(p),f+=n.length}return vt(...h)};return(f,h)=>{o(),c(f);let p;for(;!(p=h(l()));)c();return o(),p}}var $6={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ft(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function it(r,e,t={}){let n=(i,s,o)=>{let a=$6[s];if(typeof a!="function")throw new Error(`Invalid validator "${s}", expected function`);let c=r[i];if(!(o&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${s}`)};for(let[i,s]of Object.entries(e))n(i,s,!1);for(let[i,s]of Object.entries(t))n(i,s,!0);return r}var z6=()=>{throw new Error("not implemented")};function ur(r){let e=new WeakMap;return(t,...n)=>{let i=e.get(t);if(i!==void 0)return i;let s=r(t,...n);return e.set(t,s),s}}var fe=BigInt(0),J=BigInt(1),fr=BigInt(2),G6=BigInt(3),Do=BigInt(4),l3=BigInt(5),u3=BigInt(8),j6=BigInt(9),W6=BigInt(16);function W(r,e){let t=r%e;return t>=fe?t:e+t}function Q6(r,e,t){if(t<=fe||e<fe)throw new Error("Expected power/modulo > 0");if(t===J)return fe;let n=J;for(;e>fe;)e&J&&(n=n*r%t),r=r*r%t,e>>=J;return n}function ee(r,e,t){let n=r;for(;e-- >fe;)n*=n,n%=t;return n}function m1(r,e){if(r===fe||e<=fe)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=W(r,e),n=e,i=fe,s=J,o=J,a=fe;for(;t!==fe;){let l=n/t,u=n%t,f=i-o*l,h=s-a*l;n=t,t=u,i=o,s=a,o=f,a=h}if(n!==J)throw new Error("invert: does not exist");return W(i,e)}function Z6(r){let e=(r-J)/fr,t,n,i;for(t=r-J,n=0;t%fr===fe;t/=fr,n++);for(i=fr;i<r&&Q6(i,e,r)!==r-J;i++);if(n===1){let o=(r+J)/Do;return function(c,l){let u=c.pow(l,o);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let s=(t+J)/fr;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,i),t),f=a.pow(c,s),h=a.pow(c,t);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let p=1;for(let w=a.sqr(h);p<l&&!a.eql(w,a.ONE);p++)w=a.sqr(w);let y=a.pow(u,J<<BigInt(l-p-1));u=a.sqr(y),f=a.mul(f,y),h=a.mul(h,u),l=p}return f}}function Y6(r){if(r%Do===G6){let e=(r+J)/Do;return function(n,i){let s=n.pow(i,e);if(!n.eql(n.sqr(s),i))throw new Error("Cannot find square root");return s}}if(r%u3===l3){let e=(r-l3)/u3;return function(n,i){let s=n.mul(i,fr),o=n.pow(s,e),a=n.mul(i,o),c=n.mul(n.mul(a,fr),o),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),i))throw new Error("Cannot find square root");return l}}return r%W6,Z6(r)}var f3=(r,e)=>(W(r,e)&J)===J,X6=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Oo(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=X6.reduce((n,i)=>(n[i]="function",n),e);return it(r,t)}function J6(r,e,t){if(t<fe)throw new Error("Expected power > 0");if(t===fe)return r.ONE;if(t===J)return e;let n=r.ONE,i=e;for(;t>fe;)t&J&&(n=r.mul(n,i)),i=r.sqr(i),t>>=J;return n}function e8(r,e){let t=new Array(e.length),n=e.reduce((s,o,a)=>r.is0(o)?s:(t[a]=s,r.mul(s,o)),r.ONE),i=r.inv(n);return e.reduceRight((s,o,a)=>r.is0(o)?s:(t[a]=r.mul(s,t[a]),r.mul(s,o)),i),t}function Mo(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Kt(r,e,t=!1,n={}){if(r<=fe)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:s}=Mo(r,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=Y6(r),a=Object.freeze({ORDER:r,BITS:i,BYTES:s,MASK:vn(i),ZERO:fe,ONE:J,create:c=>W(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return fe<=c&&c<r},is0:c=>c===fe,isOdd:c=>(c&J)===J,neg:c=>W(-c,r),eql:(c,l)=>c===l,sqr:c=>W(c*c,r),add:(c,l)=>W(c+l,r),sub:(c,l)=>W(c-l,r),mul:(c,l)=>W(c*l,r),pow:(c,l)=>J6(a,c,l),div:(c,l)=>W(c*m1(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>m1(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>e8(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>t?lr(c,s):qt(c,s),fromBytes:c=>{if(c.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);return t?Ht(c):xt(c)}});return Object.freeze(a)}function h3(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Vo(r){let e=h3(r);return e+Math.ceil(e/2)}function d3(r,e,t=!1){let n=r.length,i=h3(e),s=Vo(e);if(n<16||n<s||n>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${n}`);let o=t?xt(r):Ht(r),a=W(o,e-J)+J;return t?lr(a,i):qt(a,i)}var r8=BigInt(0),Fo=BigInt(1),Ho=new WeakMap,p3=new WeakMap;function y1(r,e){let t=(s,o)=>{let a=o.negate();return s?a:o},n=s=>{if(!Number.isSafeInteger(s)||s<=0||s>e)throw new Error(`Wrong window size=${s}, should be [1..${e}]`)},i=s=>{n(s);let o=Math.ceil(e/s)+1,a=2**(s-1);return{windows:o,windowSize:a}};return{constTimeNegate:t,unsafeLadder(s,o){let a=r.ZERO,c=s;for(;o>r8;)o&Fo&&(a=a.add(c)),c=c.double(),o>>=Fo;return a},precomputeWindow(s,o){let{windows:a,windowSize:c}=i(o),l=[],u=s,f=u;for(let h=0;h<a;h++){f=u,l.push(f);for(let p=1;p<c;p++)f=f.add(u),l.push(f);u=f.double()}return l},wNAF(s,o,a){let{windows:c,windowSize:l}=i(s),u=r.ZERO,f=r.BASE,h=BigInt(2**s-1),p=2**s,y=BigInt(s);for(let w=0;w<c;w++){let d=w*l,x=Number(a&h);a>>=y,x>l&&(x-=p,a+=Fo);let E=d,g=d+Math.abs(x)-1,A=w%2!==0,R=x<0;x===0?f=f.add(t(A,o[E])):u=u.add(t(R,o[g]))}return{p:u,f}},wNAFCached(s,o,a){let c=p3.get(s)||1,l=Ho.get(s);return l||(l=this.precomputeWindow(s,c),c!==1&&Ho.set(s,a(l))),this.wNAF(c,l,o)},setWindowSize(s,o){n(o),p3.set(s,o),Ho.delete(s)}}}function w1(r,e,t,n){if(!Array.isArray(t)||!Array.isArray(n)||n.length!==t.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((u,f)=>{if(!e.isValid(u))throw new Error(`wrong scalar at index ${f}`)}),t.forEach((u,f)=>{if(!(u instanceof r))throw new Error(`wrong point at index ${f}`)});let i=Co(BigInt(t.length)),s=i>12?i-3:i>4?i-2:i?2:1,o=(1<<s)-1,a=new Array(o+1).fill(r.ZERO),c=Math.floor((e.BITS-1)/s)*s,l=r.ZERO;for(let u=c;u>=0;u-=s){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let p=n[h],y=Number(p>>BigInt(u)&BigInt(o));a[y]=a[y].add(t[h])}let f=r.ZERO;for(let h=a.length-1,p=r.ZERO;h>0;h--)p=p.add(a[h]),f=f.add(p);if(l=l.add(f),u!==0)for(let h=0;h<s;h++)l=l.double()}return l}function En(r){return Oo(r.Fp),it(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Mo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ze=BigInt(0),Ue=BigInt(1),b1=BigInt(2),n8=BigInt(8),i8={zip215:!0};function s8(r){let e=En(r);return it(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function g3(r){let e=s8(r),{Fp:t,n,prehash:i,hash:s,randomBytes:o,nByteLength:a,h:c}=e,l=b1<<BigInt(a*8)-Ue,u=t.create,f=Kt(e.n,e.nBitLength),h=e.uvRatio||((b,m)=>{try{return{isValid:!0,value:t.sqrt(b*t.inv(m))}}catch{return{isValid:!1,value:Ze}}}),p=e.adjustScalarBytes||(b=>b),y=e.domain||((b,m,v)=>{if(Qe("phflag",v),m.length||v)throw new Error("Contexts/pre-hash are not supported");return b});function w(b,m){Ce("coordinate "+b,m,Ze,l)}function d(b){if(!(b instanceof g))throw new Error("ExtendedPoint expected")}let x=ur((b,m)=>{let{ex:v,ey:N,ez:_}=b,C=b.is0();m==null&&(m=C?n8:t.inv(_));let V=u(v*m),q=u(N*m),F=u(_*m);if(C)return{x:Ze,y:Ue};if(F!==Ue)throw new Error("invZ was invalid");return{x:V,y:q}}),E=ur(b=>{let{a:m,d:v}=e;if(b.is0())throw new Error("bad point: ZERO");let{ex:N,ey:_,ez:C,et:V}=b,q=u(N*N),F=u(_*_),j=u(C*C),Z=u(j*j),de=u(q*m),pe=u(j*u(de+F)),we=u(Z+u(v*u(q*F)));if(pe!==we)throw new Error("bad point: equation left != right (1)");let Ie=u(N*_),le=u(C*V);if(Ie!==le)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(m,v,N,_){this.ex=m,this.ey=v,this.ez=N,this.et=_,w("x",m),w("y",v),w("z",N),w("t",_),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof g)throw new Error("extended point not allowed");let{x:v,y:N}=m||{};return w("x",v),w("y",N),new g(v,N,Ue,u(v*N))}static normalizeZ(m){let v=t.invertBatch(m.map(N=>N.ez));return m.map((N,_)=>N.toAffine(v[_])).map(g.fromAffine)}static msm(m,v){return w1(g,f,m,v)}_setWindowSize(m){T.setWindowSize(this,m)}assertValidity(){E(this)}equals(m){d(m);let{ex:v,ey:N,ez:_}=this,{ex:C,ey:V,ez:q}=m,F=u(v*q),j=u(C*_),Z=u(N*q),de=u(V*_);return F===j&&Z===de}is0(){return this.equals(g.ZERO)}negate(){return new g(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:m}=e,{ex:v,ey:N,ez:_}=this,C=u(v*v),V=u(N*N),q=u(b1*u(_*_)),F=u(m*C),j=v+N,Z=u(u(j*j)-C-V),de=F+V,pe=de-q,we=F-V,Ie=u(Z*pe),le=u(de*we),Pe=u(Z*we),ut=u(pe*de);return new g(Ie,le,ut,Pe)}add(m){d(m);let{a:v,d:N}=e,{ex:_,ey:C,ez:V,et:q}=this,{ex:F,ey:j,ez:Z,et:de}=m;if(v===BigInt(-1)){let _2=u((C-_)*(j+F)),C2=u((C+_)*(j-F)),ys=u(C2-_2);if(ys===Ze)return this.double();let U2=u(V*b1*de),D2=u(q*b1*Z),O2=D2+U2,M2=C2+_2,V2=D2-U2,v4=u(O2*ys),E4=u(M2*V2),A4=u(O2*V2),S4=u(ys*M2);return new g(v4,E4,S4,A4)}let pe=u(_*F),we=u(C*j),Ie=u(q*N*de),le=u(V*Z),Pe=u((_+C)*(F+j)-pe-we),ut=le-Ie,tn=le+Ie,rn=u(we-v*pe),y4=u(Pe*ut),w4=u(tn*rn),b4=u(Pe*rn),x4=u(ut*tn);return new g(y4,w4,x4,b4)}subtract(m){return this.add(m.negate())}wNAF(m){return T.wNAFCached(this,m,g.normalizeZ)}multiply(m){let v=m;Ce("scalar",v,Ue,n);let{p:N,f:_}=this.wNAF(v);return g.normalizeZ([N,_])[0]}multiplyUnsafe(m){let v=m;return Ce("scalar",v,Ze,n),v===Ze?R:this.equals(R)||v===Ue?this:this.equals(A)?this.wNAF(v).p:T.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return T.unsafeLadder(this,n).is0()}toAffine(m){return x(this,m)}clearCofactor(){let{h:m}=e;return m===Ue?this:this.multiplyUnsafe(m)}static fromHex(m,v=!1){let{d:N,a:_}=e,C=t.BYTES;m=ie("pointHex",m,C),Qe("zip215",v);let V=m.slice(),q=m[C-1];V[C-1]=q&-129;let F=Ht(V),j=v?l:t.ORDER;Ce("pointHex.y",F,Ze,j);let Z=u(F*F),de=u(Z-Ue),pe=u(N*Z-_),{isValid:we,value:Ie}=h(de,pe);if(!we)throw new Error("Point.fromHex: invalid y coordinate");let le=(Ie&Ue)===Ue,Pe=(q&128)!==0;if(!v&&Ie===Ze&&Pe)throw new Error("Point.fromHex: x=0 and x_0=1");return Pe!==le&&(Ie=u(-Ie)),g.fromAffine({x:Ie,y:F})}static fromPrivateKey(m){return L(m).point}toRawBytes(){let{x:m,y:v}=this.toAffine(),N=lr(v,t.BYTES);return N[N.length-1]|=m&Ue?128:0,N}toHex(){return bt(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,Ue,u(e.Gx*e.Gy)),g.ZERO=new g(Ze,Ue,Ue,Ze);let{BASE:A,ZERO:R}=g,T=y1(g,a*8);function I(b){return W(b,n)}function k(b){return I(Ht(b))}function L(b){let m=a;b=ie("private key",b,m);let v=ie("hashed private key",s(b),2*m),N=p(v.slice(0,m)),_=v.slice(m,2*m),C=k(N),V=A.multiply(C),q=V.toRawBytes();return{head:N,prefix:_,scalar:C,point:V,pointBytes:q}}function ae(b){return L(b).pointBytes}function K(b=new Uint8Array,...m){let v=vt(...m);return k(s(y(v,ie("context",b),!!i)))}function M(b,m,v={}){b=ie("message",b),i&&(b=i(b));let{prefix:N,scalar:_,pointBytes:C}=L(m),V=K(v.context,N,b),q=A.multiply(V).toRawBytes(),F=K(v.context,q,C,b),j=I(V+F*_);Ce("signature.s",j,Ze,n);let Z=vt(q,lr(j,t.BYTES));return ie("result",Z,a*2)}let ce=i8;function S(b,m,v,N=ce){let{context:_,zip215:C}=N,V=t.BYTES;b=ie("signature",b,2*V),m=ie("message",m),C!==void 0&&Qe("zip215",C),i&&(m=i(m));let q=Ht(b.slice(V,2*V)),F,j,Z;try{F=g.fromHex(v,C),j=g.fromHex(b.slice(0,V),C),Z=A.multiplyUnsafe(q)}catch{return!1}if(!C&&F.isSmallOrder())return!1;let de=K(_,j.toRawBytes(),F.toRawBytes(),m);return j.add(F.multiplyUnsafe(de)).subtract(Z).clearCofactor().equals(g.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:ae,sign:M,verify:S,ExtendedPoint:g,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>o(t.BYTES),precompute(b=8,m=g.BASE){return m._setWindowSize(b),m.multiply(BigInt(3)),m}}}}var qo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),m3=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Hu=BigInt(0),o8=BigInt(1),y3=BigInt(2),qu=BigInt(3),a8=BigInt(5),c8=BigInt(8);function l8(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),i=BigInt(80),s=qo,a=r*r%s*r%s,c=ee(a,y3,s)*a%s,l=ee(c,o8,s)*r%s,u=ee(l,a8,s)*l%s,f=ee(u,e,s)*u%s,h=ee(f,t,s)*f%s,p=ee(h,n,s)*h%s,y=ee(p,i,s)*p%s,w=ee(y,i,s)*p%s,d=ee(w,e,s)*u%s;return{pow_p_5_8:ee(d,y3,s)*r%s,b2:a}}function u8(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function f8(r,e){let t=qo,n=W(e*e*e,t),i=W(n*n*e,t),s=l8(r*i).pow_p_5_8,o=W(r*n*s,t),a=W(e*o*o,t),c=o,l=W(o*m3,t),u=a===r,f=a===W(-r,t),h=a===W(-r*m3,t);return u&&(o=c),(f||h)&&(o=l),f3(o,t)&&(o=W(-o,t)),{isValid:u||f,value:o}}var h8=Kt(qo,void 0,!0),d8={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:h8,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:c8,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:o3,randomBytes:Mr,adjustScalarBytes:u8,uvRatio:f8},w3=g3(d8);var x1=32;function b3(r,e,t){return w3.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}var v1=class{type="Ed25519";raw;constructor(e){this.raw=Ko(e,x1)}toMultihash(){return gt.digest(Hr(this))}toCID(){return re.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:X(this.raw,e.raw)}verify(e,t){return b3(this.raw,t,e)}};function $o(r){return r=Ko(r,x1),new v1(r)}function Ko(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new $(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var he;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(he||(he={}));var zo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(zo||(zo={}));(function(r){r.codec=()=>Tr(zo)})(he||(he={}));var st;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.Type=he.codec().decode(t);break}case 2:{s.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(st||(st={}));var Go;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.Type=he.codec().decode(t);break}case 2:{s.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(Go||(Go={}));var Ln={};ke(Ln,{MAX_RSA_KEY_SIZE:()=>di,generateRSAKeyPair:()=>ya,jwkToJWKKeyPair:()=>wa,jwkToPkcs1:()=>P8,jwkToPkix:()=>t2,jwkToRSAPrivateKey:()=>ma,pkcs1ToJwk:()=>da,pkcs1ToRSAPrivateKey:()=>ga,pkixToJwk:()=>pa,pkixToRSAPublicKey:()=>r2});var g8=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),$t=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),zt=new Uint32Array(64),jo=class extends Vr{constructor(){super(64,32,8,!1),this.A=$t[0]|0,this.B=$t[1]|0,this.C=$t[2]|0,this.D=$t[3]|0,this.E=$t[4]|0,this.F=$t[5]|0,this.G=$t[6]|0,this.H=$t[7]|0}get(){let{A:e,B:t,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[e,t,n,i,s,o,a,c]}set(e,t,n,i,s,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)zt[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let h=zt[f-15],p=zt[f-2],y=We(h,7)^We(h,18)^h>>>3,w=We(p,17)^We(p,19)^p>>>10;zt[f]=w+zt[f-7]+y+zt[f-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=We(a,6)^We(a,11)^We(a,25),p=u+h+n3(a,c,l)+g8[f]+zt[f]|0,w=(We(n,2)^We(n,13)^We(n,22))+i3(n,i,s)|0;u=l,l=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+w|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,i,s,o,a,c,l,u)}roundClean(){zt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var qr=h1(()=>new jo);var H=bs(E3());function hr(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function Gt(r,e,t=-1){let n=t,i=r,s=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(r<o){let c;if(n<0)c=new ArrayBuffer(a),s=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),s=n}let l=new Uint8Array(c);for(let u=a-1;u>=0;u--){let f=Math.pow(2,u*e);l[s-u-1]=Math.floor(i/f),i-=l[s-u-1]*f}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function S1(...r){let e=0,t=0;for(let s of r)e+=s.length;let n=new ArrayBuffer(e),i=new Uint8Array(n);for(let s of r)i.set(s,t),t+=s.length;return i}function Qo(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=hr(t,8),i=new ArrayBuffer(this.valueHex.byteLength),s=new Uint8Array(i);for(let a=0;a<this.valueHex.byteLength;a++)s[a]=r[a];return s[0]&=127,hr(s,8)-n}function A3(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let o=t-e,a=Gt(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let i=Gt(e,8,n),s=new Uint8Array(i);if(s[0]&128){let o=i.slice(0),a=new Uint8Array(o);i=new ArrayBuffer(i.byteLength+1),s=new Uint8Array(i);for(let c=0;c<o.byteLength;c++)s[c+1]=a[c];s[0]=0}return i}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function S3(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0}function De(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,i=new Array(n);for(let o=0;o<n;o++)i[o]="0";return i.join("").concat(t)}var hf=Math.log(2);function B1(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Zo(r){let e=0,t=0;for(let i=0;i<r.length;i++){let s=r[i];e+=s.byteLength}let n=new Uint8Array(e);for(let i=0;i<r.length;i++){let s=r[i];n.set(new Uint8Array(s),t),t+=s.byteLength}return n.buffer}function It(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Sn=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Zo(this.items)}},An=[new Uint8Array([1])],B3="0123456789";var jr="",Ye=new ArrayBuffer(0),Yo=new Uint8Array(0),Bn="EndOfContent",k3="OCTET STRING",T3="BIT STRING";function kt(r){var e;return e=class extends r{constructor(...n){var i;super(...n);let s=n[0]||{};this.isHexOnly=(i=s.isHexOnly)!==null&&i!==void 0?i:!1,this.valueHexView=s.valueHex?H.BufferSourceConverter.toUint8Array(s.valueHex):Yo}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,i,s){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!It(this,o,i,s))return-1;let a=i+s;return this.valueHexView=o.subarray(i,a),this.valueHexView.length?(this.blockLength=s,a):(this.warnings.push("Zero buffer length"),i)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Ye)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:H.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var At=class{constructor({blockLength:e=0,error:t=jr,warnings:n=[],valueBeforeDecode:i=Yo}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=H.BufferSourceConverter.toUint8Array(i)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:H.Convert.ToHex(this.valueBeforeDecodeView)}}};At.NAME="baseBlock";var Se=class extends At{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Se.NAME="valueBlock";var I1=class extends kt(At){constructor({idBlock:e={}}={}){var t,n,i,s;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?H.BufferSourceConverter.toUint8Array(e.valueHex):Yo,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(i=e.tagNumber)!==null&&i!==void 0?i:-1,this.isConstructed=(s=e.isConstructed)!==null&&s!==void 0?s:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",Ye}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let i=new Uint8Array(1);if(!e){let s=this.tagNumber;s&=31,t|=s,i[0]=t}return i.buffer}if(!this.isHexOnly){let i=Gt(this.tagNumber,7),s=new Uint8Array(i),o=i.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=s[c]|128;a[o]=s[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let i=this.valueHexView;for(let s=0;s<i.length-1;s++)n[s+1]=i[s]|128;n[this.valueHexView.byteLength]=i[i.length-1]}return n.buffer}fromBER(e,t,n){let i=H.BufferSourceConverter.toUint8Array(e);if(!It(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;switch(s[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(s[0]&32)===32,this.isHexOnly=!1;let a=s[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),u=255;for(;s[c]&128;){if(l[c-1]=s[c]&127,c++,c>=s.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let h=new Uint8Array(u);for(let p=0;p<l.length;p++)h[p]=l[p];l=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,l[c-1]=s[c]&127;let f=new Uint8Array(c);for(let h=0;h<c;h++)f[h]=l[h];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=hr(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};I1.NAME="identificationBlock";var k1=class extends At{constructor({lenBlock:e={}}={}){var t,n,i;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(i=e.length)!==null&&i!==void 0?i:0}fromBER(e,t,n){let i=H.BufferSourceConverter.toUint8Array(e);if(!It(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;if(s[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=s[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(s[0]&128),this.longFormUsed===!1)return this.length=s[0],this.blockLength=1,t+this.blockLength;let o=s[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>s.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=i.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=hr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let i=Gt(this.length,8);if(i.byteLength>127)return this.error="Too big length",Ye;if(t=new ArrayBuffer(i.byteLength+1),e)return t;let s=new Uint8Array(i);n=new Uint8Array(t),n[0]=i.byteLength|128;for(let o=0;o<i.byteLength;o++)n[o+1]=s[o];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};k1.NAME="lengthBlock";var B={},be=class extends At{constructor({name:e=jr,optional:t=!1,primitiveSchema:n,...i}={},s){super(i),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new I1(i),this.lenBlock=new k1(i),this.valueBlock=s?new s(i):new Se(i)}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}toBER(e,t){let n=t||new Sn;t||R3(this);let i=this.idBlock.toBER(e);if(n.write(i),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let s=this.valueBlock.toBER(e);this.lenBlock.length=s.byteLength;let o=this.lenBlock.toBER(e);n.write(o),n.write(s)}return t?Ye:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():H.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${H.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return S3(t,n)}};be.NAME="BaseBlock";function R3(r){if(r instanceof B.Constructed)for(let e of r.valueBlock.value)R3(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var T1=class extends be{constructor({value:e=jr,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};T1.NAME="BaseStringBlock";var R1=class extends kt(Se){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};R1.NAME="PrimitiveValueBlock";var P3,P1=class extends be{constructor(e={}){super(e,R1),this.idBlock.isConstructed=!1}};P3=P1;B.Primitive=P3;P1.NAME="PRIMITIVE";function S8(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function ui(r,e=0,t=r.length){let n=e,i=new be({},Se),s=new At;if(!It(s,r,e,t))return i.error=s.error,{offset:-1,result:i};if(!r.subarray(e,e+t).length)return i.error="Zero buffer length",{offset:-1,result:i};let a=i.idBlock.fromBER(r,e,t);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),a===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=a,t-=i.idBlock.blockLength,a=i.lenBlock.fromBER(r,e,t),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),a===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};if(e=a,t-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let c=be;switch(i.idBlock.tagClass){case 1:if(i.idBlock.tagNumber>=37&&i.idBlock.isHexOnly===!1)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};c=B.EndOfContent;break;case 1:c=B.Boolean;break;case 2:c=B.Integer;break;case 3:c=B.BitString;break;case 4:c=B.OctetString;break;case 5:c=B.Null;break;case 6:c=B.ObjectIdentifier;break;case 10:c=B.Enumerated;break;case 12:c=B.Utf8String;break;case 13:c=B.RelativeObjectIdentifier;break;case 14:c=B.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:c=B.Sequence;break;case 17:c=B.Set;break;case 18:c=B.NumericString;break;case 19:c=B.PrintableString;break;case 20:c=B.TeletexString;break;case 21:c=B.VideotexString;break;case 22:c=B.IA5String;break;case 23:c=B.UTCTime;break;case 24:c=B.GeneralizedTime;break;case 25:c=B.GraphicString;break;case 26:c=B.VisibleString;break;case 27:c=B.GeneralString;break;case 28:c=B.UniversalString;break;case 29:c=B.CharacterString;break;case 30:c=B.BmpString;break;case 31:c=B.DATE;break;case 32:c=B.TimeOfDay;break;case 33:c=B.DateTime;break;case 34:c=B.Duration;break;default:{let l=i.idBlock.isConstructed?new B.Constructed:new B.Primitive;l.idBlock=i.idBlock,l.lenBlock=i.lenBlock,l.warnings=i.warnings,i=l}}break;case 2:case 3:case 4:default:c=i.idBlock.isConstructed?B.Constructed:B.Primitive}return i=S8(i,c),a=i.fromBER(r,e,i.lenBlock.isIndefiniteForm?t:i.lenBlock.length),i.valueBeforeDecodeView=r.subarray(n,n+i.blockLength),{offset:a,result:i}}function Xo(r){if(!r.byteLength){let e=new be({},Se);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ui(H.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function B8(r,e){return r?1:e}var ot=class extends Se{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let i=H.BufferSourceConverter.toUint8Array(e);if(!It(this,i,t,n))return-1;if(this.valueBeforeDecodeView=i.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let s=t;for(;B8(this.isIndefiniteForm,n)>0;){let o=ui(i,s,n);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(s=o.offset,this.blockLength+=o.result.blockLength,n-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===Bn)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Bn?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,t){let n=t||new Sn;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,n);return t?Ye:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};ot.NAME="ConstructedValueBlock";var N3,jt=class extends be{constructor(e={}){super(e,ot),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
2
+ "use strict";var Libp2PKadDht=(()=>{var B4=Object.create;var Gn=Object.defineProperty;var I4=Object.getOwnPropertyDescriptor;var k4=Object.getOwnPropertyNames;var T4=Object.getPrototypeOf,R4=Object.prototype.hasOwnProperty;var ws=(r,e)=>()=>(e||r((e={exports:{}}).exports,e),e.exports),ke=(r,e)=>{for(var t in e)Gn(r,t,{get:e[t],enumerable:!0})},F2=(r,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of k4(e))!R4.call(r,i)&&i!==t&&Gn(r,i,{get:()=>e[i],enumerable:!(n=I4(e,i))||n.enumerable});return r};var bs=(r,e,t)=>(t=r!=null?B4(T4(r)):{},F2(e||!r||!r.__esModule?Gn(t,"default",{value:r,enumerable:!0}):t,r)),P4=r=>F2(Gn({},"__esModule",{value:!0}),r);var Q2=ws((Fc,vs)=>{"use strict";var _4=Object.prototype.hasOwnProperty,Te="~";function on(){}Object.create&&(on.prototype=Object.create(null),new on().__proto__||(Te=!1));function C4(r,e,t){this.fn=r,this.context=e,this.once=t||!1}function W2(r,e,t,n,i){if(typeof t!="function")throw new TypeError("The listener must be a function");var s=new C4(t,n||r,i),o=Te?Te+e:e;return r._events[o]?r._events[o].fn?r._events[o]=[r._events[o],s]:r._events[o].push(s):(r._events[o]=s,r._eventsCount++),r}function Qn(r,e){--r._eventsCount===0?r._events=new on:delete r._events[e]}function ve(){this._events=new on,this._eventsCount=0}ve.prototype.eventNames=function(){var e=[],t,n;if(this._eventsCount===0)return e;for(n in t=this._events)_4.call(t,n)&&e.push(Te?n.slice(1):n);return Object.getOwnPropertySymbols?e.concat(Object.getOwnPropertySymbols(t)):e};ve.prototype.listeners=function(e){var t=Te?Te+e:e,n=this._events[t];if(!n)return[];if(n.fn)return[n.fn];for(var i=0,s=n.length,o=new Array(s);i<s;i++)o[i]=n[i].fn;return o};ve.prototype.listenerCount=function(e){var t=Te?Te+e:e,n=this._events[t];return n?n.fn?1:n.length:0};ve.prototype.emit=function(e,t,n,i,s,o){var a=Te?Te+e:e;if(!this._events[a])return!1;var c=this._events[a],l=arguments.length,u,f;if(c.fn){switch(c.once&&this.removeListener(e,c.fn,void 0,!0),l){case 1:return c.fn.call(c.context),!0;case 2:return c.fn.call(c.context,t),!0;case 3:return c.fn.call(c.context,t,n),!0;case 4:return c.fn.call(c.context,t,n,i),!0;case 5:return c.fn.call(c.context,t,n,i,s),!0;case 6:return c.fn.call(c.context,t,n,i,s,o),!0}for(f=1,u=new Array(l-1);f<l;f++)u[f-1]=arguments[f];c.fn.apply(c.context,u)}else{var h=c.length,p;for(f=0;f<h;f++)switch(c[f].once&&this.removeListener(e,c[f].fn,void 0,!0),l){case 1:c[f].fn.call(c[f].context);break;case 2:c[f].fn.call(c[f].context,t);break;case 3:c[f].fn.call(c[f].context,t,n);break;case 4:c[f].fn.call(c[f].context,t,n,i);break;default:if(!u)for(p=1,u=new Array(l-1);p<l;p++)u[p-1]=arguments[p];c[f].fn.apply(c[f].context,u)}}return!0};ve.prototype.on=function(e,t,n){return W2(this,e,t,n,!1)};ve.prototype.once=function(e,t,n){return W2(this,e,t,n,!0)};ve.prototype.removeListener=function(e,t,n,i){var s=Te?Te+e:e;if(!this._events[s])return this;if(!t)return Qn(this,s),this;var o=this._events[s];if(o.fn)o.fn===t&&(!i||o.once)&&(!n||o.context===n)&&Qn(this,s);else{for(var a=0,c=[],l=o.length;a<l;a++)(o[a].fn!==t||i&&!o[a].once||n&&o[a].context!==n)&&c.push(o[a]);c.length?this._events[s]=c.length===1?c[0]:c:Qn(this,s)}return this};ve.prototype.removeAllListeners=function(e){var t;return e?(t=Te?Te+e:e,this._events[t]&&Qn(this,t)):(this._events=new on,this._eventsCount=0),this};ve.prototype.off=ve.prototype.removeListener;ve.prototype.addListener=ve.prototype.on;ve.prefixed=Te;ve.EventEmitter=ve;typeof vs<"u"&&(vs.exports=ve)});var E3=ws(Kr=>{"use strict";var m8="[object ArrayBuffer]",Et=class r{static isArrayBuffer(e){return Object.prototype.toString.call(e)===m8}static toArrayBuffer(e){return this.isArrayBuffer(e)?e:e.byteLength===e.buffer.byteLength||e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:this.toUint8Array(e.buffer).slice(e.byteOffset,e.byteOffset+e.byteLength).buffer}static toUint8Array(e){return this.toView(e,Uint8Array)}static toView(e,t){if(e.constructor===t)return e;if(this.isArrayBuffer(e))return new t(e);if(this.isArrayBufferView(e))return new t(e.buffer,e.byteOffset,e.byteLength);throw new TypeError("The provided value is not of type '(ArrayBuffer or ArrayBufferView)'")}static isBufferSource(e){return this.isArrayBufferView(e)||this.isArrayBuffer(e)}static isArrayBufferView(e){return ArrayBuffer.isView(e)||e&&this.isArrayBuffer(e.buffer)}static isEqual(e,t){let n=r.toUint8Array(e),i=r.toUint8Array(t);if(n.length!==i.byteLength)return!1;for(let s=0;s<n.length;s++)if(n[s]!==i[s])return!1;return!0}static concat(...e){let t;Array.isArray(e[0])&&!(e[1]instanceof Function)||Array.isArray(e[0])&&e[1]instanceof Function?t=e[0]:e[e.length-1]instanceof Function?t=e.slice(0,e.length-1):t=e;let n=0;for(let o of t)n+=o.byteLength;let i=new Uint8Array(n),s=0;for(let o of t){let a=this.toUint8Array(o);i.set(a,s),s+=a.length}return e[e.length-1]instanceof Function?this.toView(i,e[e.length-1]):i.buffer}},Wo="string",y8=/^[0-9a-f]+$/i,w8=/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/,b8=/^[a-zA-Z0-9-_]+$/,E1=class{static fromString(e){let t=unescape(encodeURIComponent(e)),n=new Uint8Array(t.length);for(let i=0;i<t.length;i++)n[i]=t.charCodeAt(i);return n.buffer}static toString(e){let t=Et.toUint8Array(e),n="";for(let s=0;s<t.length;s++)n+=String.fromCharCode(t[s]);return decodeURIComponent(escape(n))}},$e=class{static toString(e,t=!1){let n=Et.toArrayBuffer(e),i=new DataView(n),s="";for(let o=0;o<n.byteLength;o+=2){let a=i.getUint16(o,t);s+=String.fromCharCode(a)}return s}static fromString(e,t=!1){let n=new ArrayBuffer(e.length*2),i=new DataView(n);for(let s=0;s<e.length;s++)i.setUint16(s*2,e.charCodeAt(s),t);return n}},A1=class r{static isHex(e){return typeof e===Wo&&y8.test(e)}static isBase64(e){return typeof e===Wo&&w8.test(e)}static isBase64Url(e){return typeof e===Wo&&b8.test(e)}static ToString(e,t="utf8"){let n=Et.toUint8Array(e);switch(t.toLowerCase()){case"utf8":return this.ToUtf8String(n);case"binary":return this.ToBinary(n);case"hex":return this.ToHex(n);case"base64":return this.ToBase64(n);case"base64url":return this.ToBase64Url(n);case"utf16le":return $e.toString(n,!0);case"utf16":case"utf16be":return $e.toString(n);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromString(e,t="utf8"){if(!e)return new ArrayBuffer(0);switch(t.toLowerCase()){case"utf8":return this.FromUtf8String(e);case"binary":return this.FromBinary(e);case"hex":return this.FromHex(e);case"base64":return this.FromBase64(e);case"base64url":return this.FromBase64Url(e);case"utf16le":return $e.fromString(e,!0);case"utf16":case"utf16be":return $e.fromString(e);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToBase64(e){let t=Et.toUint8Array(e);if(typeof btoa<"u"){let n=this.ToString(t,"binary");return btoa(n)}else return Buffer.from(t).toString("base64")}static FromBase64(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64(t))throw new TypeError("Argument 'base64Text' is not Base64 encoded");return typeof atob<"u"?this.FromBinary(atob(t)):new Uint8Array(Buffer.from(t,"base64")).buffer}static FromBase64Url(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isBase64Url(t))throw new TypeError("Argument 'base64url' is not Base64Url encoded");return this.FromBase64(this.Base64Padding(t.replace(/\-/g,"+").replace(/\_/g,"/")))}static ToBase64Url(e){return this.ToBase64(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/\=/g,"")}static FromUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.FromBinary(e);case"utf8":return E1.fromString(e);case"utf16":case"utf16be":return $e.fromString(e);case"utf16le":case"usc2":return $e.fromString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static ToUtf8String(e,t=r.DEFAULT_UTF8_ENCODING){switch(t){case"ascii":return this.ToBinary(e);case"utf8":return E1.toString(e);case"utf16":case"utf16be":return $e.toString(e);case"utf16le":case"usc2":return $e.toString(e,!0);default:throw new Error(`Unknown type of encoding '${t}'`)}}static FromBinary(e){let t=e.length,n=new Uint8Array(t);for(let i=0;i<t;i++)n[i]=e.charCodeAt(i);return n.buffer}static ToBinary(e){let t=Et.toUint8Array(e),n="";for(let i=0;i<t.length;i++)n+=String.fromCharCode(t[i]);return n}static ToHex(e){let t=Et.toUint8Array(e),n="",i=t.length;for(let s=0;s<i;s++){let o=t[s];o<16&&(n+="0"),n+=o.toString(16)}return n}static FromHex(e){let t=this.formatString(e);if(!t)return new ArrayBuffer(0);if(!r.isHex(t))throw new TypeError("Argument 'hexString' is not HEX encoded");t.length%2&&(t=`0${t}`);let n=new Uint8Array(t.length/2);for(let i=0;i<t.length;i=i+2){let s=t.slice(i,i+2);n[i/2]=parseInt(s,16)}return n.buffer}static ToUtf16String(e,t=!1){return $e.toString(e,t)}static FromUtf16String(e,t=!1){return $e.fromString(e,t)}static Base64Padding(e){let t=4-e.length%4;if(t<4)for(let n=0;n<t;n++)e+="=";return e}static formatString(e){return e?.replace(/[\n\r\t ]/g,"")||""}};A1.DEFAULT_UTF8_ENCODING="utf8";function x8(r,...e){let t=arguments[0];for(let n=1;n<arguments.length;n++){let i=arguments[n];for(let s in i)t[s]=i[s]}return t}function v8(...r){let e=r.map(i=>i.byteLength).reduce((i,s)=>i+s),t=new Uint8Array(e),n=0;return r.map(i=>new Uint8Array(i)).forEach(i=>{for(let s of i)t[n++]=s}),t.buffer}function E8(r,e){if(!(r&&e)||r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<r.byteLength;i++)if(t[i]!==n[i])return!1;return!0}Kr.BufferSourceConverter=Et;Kr.Convert=A1;Kr.assign=x8;Kr.combine=v8;Kr.isEqual=E8});var Da=ws(Mn=>{(function(){var r,e,t,n,i,s,o,a;a=function(c){var l,u,f,h;return l=(c&255<<24)>>>24,u=(c&255<<16)>>>16,f=(c&65280)>>>8,h=c&255,[l,u,f,h].join(".")},o=function(c){var l,u,f,h,p,y;for(l=[],f=h=0;h<=3&&c.length!==0;f=++h){if(f>0){if(c[0]!==".")throw new Error("Invalid IP");c=c.substring(1)}y=e(c),p=y[0],u=y[1],c=c.substring(u),l.push(p)}if(c.length!==0)throw new Error("Invalid IP");switch(l.length){case 1:if(l[0]>4294967295)throw new Error("Invalid IP");return l[0]>>>0;case 2:if(l[0]>255||l[1]>16777215)throw new Error("Invalid IP");return(l[0]<<24|l[1])>>>0;case 3:if(l[0]>255||l[1]>255||l[2]>65535)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2])>>>0;case 4:if(l[0]>255||l[1]>255||l[2]>255||l[3]>255)throw new Error("Invalid IP");return(l[0]<<24|l[1]<<16|l[2]<<8|l[3])>>>0;default:throw new Error("Invalid IP")}},t=function(c){return c.charCodeAt(0)},n=t("0"),s=t("a"),i=t("A"),e=function(c){var l,u,f,h,p;for(h=0,l=10,u="9",f=0,c.length>1&&c[f]==="0"&&(c[f+1]==="x"||c[f+1]==="X"?(f+=2,l=16):"0"<=c[f+1]&&c[f+1]<="9"&&(f++,l=8,u="7")),p=f;f<c.length;){if("0"<=c[f]&&c[f]<=u)h=h*l+(t(c[f])-n)>>>0;else if(l===16)if("a"<=c[f]&&c[f]<="f")h=h*l+(10+t(c[f])-s)>>>0;else if("A"<=c[f]&&c[f]<="F")h=h*l+(10+t(c[f])-i)>>>0;else break;else break;if(h>4294967295)throw new Error("too large");f++}if(f===p)throw new Error("empty octet");return[h,f]},r=function(){function c(l,u){var f,h,p,y;if(typeof l!="string")throw new Error("Missing `net' parameter");if(u||(y=l.split("/",2),l=y[0],u=y[1]),u||(u=32),typeof u=="string"&&u.indexOf(".")>-1){try{this.maskLong=o(u)}catch(w){throw f=w,new Error("Invalid mask: "+u)}for(h=p=32;p>=0;h=--p)if(this.maskLong===4294967295<<32-h>>>0){this.bitmask=h;break}}else if(u||u===0)this.bitmask=parseInt(u,10),this.maskLong=0,this.bitmask>0&&(this.maskLong=4294967295<<32-this.bitmask>>>0);else throw new Error("Invalid mask: empty");try{this.netLong=(o(l)&this.maskLong)>>>0}catch(w){throw f=w,new Error("Invalid net address: "+l)}if(!(this.bitmask<=32))throw new Error("Invalid mask for ip4: "+u);this.size=Math.pow(2,32-this.bitmask),this.base=a(this.netLong),this.mask=a(this.maskLong),this.hostmask=a(~this.maskLong),this.first=this.bitmask<=30?a(this.netLong+1):this.base,this.last=this.bitmask<=30?a(this.netLong+this.size-2):a(this.netLong+this.size-1),this.broadcast=this.bitmask<=30?a(this.netLong+this.size-1):void 0}return c.prototype.contains=function(l){return typeof l=="string"&&(l.indexOf("/")>0||l.split(".").length!==4)&&(l=new c(l)),l instanceof c?this.contains(l.base)&&this.contains(l.broadcast||l.last):(o(l)&this.maskLong)>>>0===(this.netLong&this.maskLong)>>>0},c.prototype.next=function(l){return l==null&&(l=1),new c(a(this.netLong+this.size*l),this.mask)},c.prototype.forEach=function(l){var u,f,h;for(h=o(this.first),f=o(this.last),u=0;h<=f;)l(a(h),h,u),u++,h++},c.prototype.toString=function(){return this.base+"/"+this.bitmask},c}(),Mn.ip2long=o,Mn.long2ip=a,Mn.Netmask=r}).call(Mn)});var ic={};ke(ic,{EventTypes:()=>Kn,MessageType:()=>O,Record:()=>ue,kadDHT:()=>nc,passthroughMapper:()=>Fa,removePrivateAddressesMapper:()=>Bi,removePublicAddressesMapper:()=>Va});var H2=Symbol.for("@libp2p/content-routing");var q2=Symbol.for("@libp2p/peer-discovery");var xs=Symbol.for("@libp2p/peer-id");var K2=Symbol.for("@libp2p/peer-routing");var $2="keep-alive";var ft=class extends Error{static name="AbortError";constructor(e="The operation was aborted"){super(e),this.name="AbortError"}};var $=class extends Error{static name="InvalidParametersError";constructor(e="Invalid parameters"){super(e),this.name="InvalidParametersError"}},ht=class extends Error{static name="InvalidPublicKeyError";constructor(e="Invalid public key"){super(e),this.name="InvalidPublicKeyError"}};var ze=class extends Error{static name="NotFoundError";constructor(e="Not found"){super(e),this.name="NotFoundError"}};var jn=class extends Error{static name="InvalidMultihashError";constructor(e="Invalid Multihash"){super(e),this.name="InvalidMultihashError"}};var Ne=class extends Error{static name="InvalidMessageError";constructor(e="Invalid message"){super(e),this.name="InvalidMessageError"}};var Jt=class extends Error{static name="UnsupportedKeyTypeError";constructor(e="Unsupported key type"){super(e),this.name="UnsupportedKeyTypeError"}};var te=(r,...e)=>{try{[...e]}catch{}};var Le=class extends EventTarget{#e=new Map;constructor(){super(),te(1/0,this)}listenerCount(e){let t=this.#e.get(e);return t==null?0:t.length}addEventListener(e,t,n){super.addEventListener(e,t,n);let i=this.#e.get(e);i==null&&(i=[],this.#e.set(e,i)),i.push({callback:t,once:(n!==!0&&n!==!1&&n?.once)??!1})}removeEventListener(e,t,n){super.removeEventListener(e.toString(),t??null,n);let i=this.#e.get(e);i!=null&&(i=i.filter(({callback:s})=>s!==t),this.#e.set(e,i))}dispatchEvent(e){let t=super.dispatchEvent(e),n=this.#e.get(e.type);return n==null||(n=n.filter(({once:i})=>!i),this.#e.set(e.type,n)),t}safeDispatchEvent(e,t={}){return this.dispatchEvent(new CustomEvent(e,t))}};function z2(r){return r!=null&&typeof r.start=="function"&&typeof r.stop=="function"}async function nn(...r){let e=[];for(let t of r)z2(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStart!=null&&await t.beforeStart()})),await Promise.all(e.map(async t=>{await t.start()})),await Promise.all(e.map(async t=>{t.afterStart!=null&&await t.afterStart()}))}async function Wn(...r){let e=[];for(let t of r)z2(t)&&e.push(t);await Promise.all(e.map(async t=>{t.beforeStop!=null&&await t.beforeStop()})),await Promise.all(e.map(async t=>{await t.stop()})),await Promise.all(e.map(async t=>{t.afterStop!=null&&await t.afterStop()}))}var G2=Symbol.for("@libp2p/service-capabilities"),j2=Symbol.for("@libp2p/service-dependencies");function N4(r){return r[Symbol.asyncIterator]!=null}function L4(r){if(N4(r))return(async()=>{for await(let e of r);})();for(let e of r);}var sn=L4;var Es=bs(Q2(),1);var an=class extends Error{constructor(e){super(e),this.name="TimeoutError"}},As=class extends Error{constructor(e){super(),this.name="AbortError",this.message=e}},Z2=r=>globalThis.DOMException===void 0?new As(r):new DOMException(r),Y2=r=>{let e=r.reason===void 0?Z2("This operation was aborted."):r.reason;return e instanceof Error?e:Z2(e)};function er(r,e){let{milliseconds:t,fallback:n,message:i,customTimers:s={setTimeout,clearTimeout}}=e,o,c=new Promise((l,u)=>{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:h}=e;h.aborted&&u(Y2(h));let p=()=>{u(Y2(h))};h.addEventListener("abort",p,{once:!0}),r.finally(()=>{h.removeEventListener("abort",p)})}if(t===Number.POSITIVE_INFINITY){r.then(l,u);return}let f=new an;o=s.setTimeout.call(void 0,()=>{if(n){try{l(n())}catch(h){u(h)}return}typeof r.cancel=="function"&&r.cancel(),i===!1?l():i instanceof Error?u(i):(f.message=i??`Promise timed out after ${t} milliseconds`,u(f))},t),(async()=>{try{l(await r)}catch(h){u(h)}})()}).finally(()=>{c.clear()});return c.clear=()=>{s.clearTimeout.call(void 0,o),o=void 0},c}function Ss(r,e,t){let n=0,i=r.length;for(;i>0;){let s=Math.trunc(i/2),o=n+s;t(r[o],e)<=0?(n=++o,i-=s+1):i=s}return n}var cn=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 i=Ss(this.#e,n,(s,o)=>o.priority-s.priority);this.#e.splice(i,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 br=class extends Es.default{#e;#r;#s=0;#a;#c;#p=0;#n;#l;#t;#g;#i=0;#u;#o;#m;timeout;constructor(e){if(super(),e={carryoverConcurrencyCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:cn,...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.#r=e.intervalCap===Number.POSITIVE_INFINITY||e.interval===0,this.#a=e.intervalCap,this.#c=e.interval,this.#t=new e.queueClass,this.#g=e.queueClass,this.concurrency=e.concurrency,this.timeout=e.timeout,this.#m=e.throwOnTimeout===!0,this.#o=e.autoStart===!1}get#b(){return this.#r||this.#s<this.#a}get#x(){return this.#i<this.#u}#v(){this.#i--,this.#f(),this.emit("next")}#E(){this.#w(),this.#y(),this.#l=void 0}get#A(){let e=Date.now();if(this.#n===void 0){let t=this.#p-e;if(t<0)this.#s=this.#e?this.#i:0;else return this.#l===void 0&&(this.#l=setTimeout(()=>{this.#E()},t)),!0}return!1}#f(){if(this.#t.size===0)return this.#n&&clearInterval(this.#n),this.#n=void 0,this.emit("empty"),this.#i===0&&this.emit("idle"),!1;if(!this.#o){let e=!this.#A;if(this.#b&&this.#x){let t=this.#t.dequeue();return t?(this.emit("active"),t(),e&&this.#y(),!0):!1}}return!1}#y(){this.#r||this.#n!==void 0||(this.#n=setInterval(()=>{this.#w()},this.#c),this.#p=Date.now()+this.#c)}#w(){this.#s===0&&this.#i===0&&this.#n&&(clearInterval(this.#n),this.#n=void 0),this.#s=this.#e?this.#i:0,this.#h()}#h(){for(;this.#f(););}get concurrency(){return this.#u}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.#u=e,this.#h()}async#S(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.#m,...t},new Promise((n,i)=>{this.#t.enqueue(async()=>{this.#i++,this.#s++;try{t.signal?.throwIfAborted();let s=e({signal:t.signal});t.timeout&&(s=er(Promise.resolve(s),{milliseconds:t.timeout})),t.signal&&(s=Promise.race([s,this.#S(t.signal)]));let o=await s;n(o),this.emit("completed",o)}catch(s){if(s instanceof an&&!t.throwOnTimeout){n();return}i(s),this.emit("error",s)}finally{this.#v()}},t),this.emit("add"),this.#f()})}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.#g}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.#i===0&&this.#t.size===0||await this.#d("idle")}async#d(e,t){return new Promise(n=>{let i=()=>{t&&!t()||(this.off(e,i),n())};this.on(e,i)})}get size(){return this.#t.size}sizeBy(e){return this.#t.filter(e).length}get pending(){return this.#i}get isPaused(){return this.#o}};var Lt={},xr=r=>{r.addEventListener("message",e=>{xr.dispatchEvent("message",r,e)}),r.port!=null&&r.port.addEventListener("message",e=>{xr.dispatchEvent("message",r,e)})};xr.addEventListener=(r,e)=>{Lt[r]==null&&(Lt[r]=[]),Lt[r].push(e)};xr.removeEventListener=(r,e)=>{Lt[r]!=null&&(Lt[r]=Lt[r].filter(t=>t===e))};xr.dispatchEvent=function(r,e,t){Lt[r]!=null&&Lt[r].forEach(n=>n(e,t))};var Bs=xr;var Is="lock:worker:request-read",ks="lock:worker:release-read",Ts="lock:master:grant-read",Rs="lock:worker:request-write",Ps="lock:worker:release-write",Ns="lock:master:grant-write";var X2=(r=21)=>Math.random().toString().substring(2);var J2=(r,e,t,n,i)=>(s,o)=>{if(o.data.type!==t)return;let a={type:o.data.type,name:o.data.name,identifier:o.data.identifier};r.dispatchEvent(new MessageEvent(e,{data:{name:a.name,handler:async()=>{s.postMessage({type:i,name:a.name,identifier:a.identifier}),await new Promise(c=>{let l=u=>{if(u?.data==null)return;let f={type:u.data.type,name:u.data.name,identifier:u.data.identifier};f.type===n&&f.identifier===a.identifier&&(s.removeEventListener("message",l),c())};s.addEventListener("message",l)})}}}))},e0=(r,e,t,n)=>async()=>{let i=X2();return globalThis.postMessage({type:e,identifier:i,name:r}),new Promise(s=>{let o=a=>{if(a?.data==null)return;let c={type:a.data.type,identifier:a.data.identifier};c.type===t&&c.identifier===i&&(globalThis.removeEventListener("message",o),s(()=>{globalThis.postMessage({type:n,identifier:i,name:r})}))};globalThis.addEventListener("message",o)})},U4={singleProcess:!1},t0=r=>{if(r=Object.assign({},U4,r),!!globalThis.document||r.singleProcess){let t=new EventTarget;return Bs.addEventListener("message",J2(t,"requestReadLock",Is,ks,Ts)),Bs.addEventListener("message",J2(t,"requestWriteLock",Rs,Ps,Ns)),t}return{isWorker:!0,readLock:t=>e0(t,Is,Ts,ks),writeLock:t=>e0(t,Rs,Ns,Ps)}};var tr={},_t;async function Ls(r,e){let t,n=new Promise(i=>{t=i});return r.add(async()=>er((async()=>{await new Promise(i=>{t(()=>{i()})})})(),{milliseconds:e.timeout})),n}var D4=(r,e)=>{if(_t.isWorker===!0)return{readLock:_t.readLock(r,e),writeLock:_t.writeLock(r,e)};let t=new br({concurrency:1}),n;return{async readLock(){if(n!=null)return Ls(n,e);n=new br({concurrency:e.concurrency,autoStart:!1});let i=n,s=Ls(n,e);return t.add(async()=>{i.start(),await i.onIdle().then(()=>{n===i&&(n=null)})}),s},async writeLock(){return n=null,Ls(t,e)}}},O4={name:"lock",concurrency:1/0,timeout:846e5,singleProcess:!1};function _s(r){let e=Object.assign({},O4,r);return _t==null&&(_t=t0(e),_t.isWorker!==!0&&(_t.addEventListener("requestReadLock",t=>{tr[t.data.name]!=null&&tr[t.data.name].readLock().then(async n=>t.data.handler().finally(()=>{n()}))}),_t.addEventListener("requestWriteLock",async t=>{tr[t.data.name]!=null&&tr[t.data.name].writeLock().then(async n=>t.data.handler().finally(()=>{n()}))}))),tr[e.name]==null&&(tr[e.name]=D4(e.name,e)),tr[e.name]}function se(){let r={};return r.promise=new Promise((e,t)=>{r.resolve=e,r.reject=t}),r}var vr=1e3,Cs=60*vr,Zn=60*Cs,r0=36*Zn,n0="/ipfs/kad/1.0.0",i0=48*Zn;var s0=24*Zn,o0=10,a0=16384,c0=Zn,ll=10*vr;var Yn=20,Er=3,l0=5*Cs,u0=vr,f0=5*vr,h0=5*Cs,d0=30*vr,p0=180*vr,Us=`${$2}-kad-dht`;function _e(r=0){return new Uint8Array(r)}function ge(r=0){return new Uint8Array(r)}var M4=Math.pow(2,7),V4=Math.pow(2,14),F4=Math.pow(2,21),Ds=Math.pow(2,28),Os=Math.pow(2,35),Ms=Math.pow(2,42),Vs=Math.pow(2,49),z=128,Ee=127;function oe(r){if(r<M4)return 1;if(r<V4)return 2;if(r<F4)return 3;if(r<Ds)return 4;if(r<Os)return 5;if(r<Ms)return 6;if(r<Vs)return 7;if(Number.MAX_SAFE_INTEGER!=null&&r>Number.MAX_SAFE_INTEGER)throw new RangeError("Could not encode varint");return 8}function Fs(r,e,t=0){switch(oe(r)){case 8:e[t++]=r&255|z,r/=128;case 7:e[t++]=r&255|z,r/=128;case 6:e[t++]=r&255|z,r/=128;case 5:e[t++]=r&255|z,r/=128;case 4:e[t++]=r&255|z,r>>>=7;case 3:e[t++]=r&255|z,r>>>=7;case 2:e[t++]=r&255|z,r>>>=7;case 1:{e[t++]=r&255,r>>>=7;break}default:throw new Error("unreachable")}return e}function H4(r,e,t=0){switch(oe(r)){case 8:e.set(t++,r&255|z),r/=128;case 7:e.set(t++,r&255|z),r/=128;case 6:e.set(t++,r&255|z),r/=128;case 5:e.set(t++,r&255|z),r/=128;case 4:e.set(t++,r&255|z),r>>>=7;case 3:e.set(t++,r&255|z),r>>>=7;case 2:e.set(t++,r&255|z),r>>>=7;case 1:{e.set(t++,r&255),r>>>=7;break}default:throw new Error("unreachable")}return e}function Hs(r,e){let t=r[e],n=0;if(n+=t&Ee,t<z||(t=r[e+1],n+=(t&Ee)<<7,t<z)||(t=r[e+2],n+=(t&Ee)<<14,t<z)||(t=r[e+3],n+=(t&Ee)<<21,t<z)||(t=r[e+4],n+=(t&Ee)*Ds,t<z)||(t=r[e+5],n+=(t&Ee)*Os,t<z)||(t=r[e+6],n+=(t&Ee)*Ms,t<z)||(t=r[e+7],n+=(t&Ee)*Vs,t<z))return n;throw new RangeError("Could not decode varint")}function q4(r,e){let t=r.get(e),n=0;if(n+=t&Ee,t<z||(t=r.get(e+1),n+=(t&Ee)<<7,t<z)||(t=r.get(e+2),n+=(t&Ee)<<14,t<z)||(t=r.get(e+3),n+=(t&Ee)<<21,t<z)||(t=r.get(e+4),n+=(t&Ee)*Ds,t<z)||(t=r.get(e+5),n+=(t&Ee)*Os,t<z)||(t=r.get(e+6),n+=(t&Ee)*Ms,t<z)||(t=r.get(e+7),n+=(t&Ee)*Vs,t<z))return n;throw new RangeError("Could not decode varint")}function qe(r,e,t=0){return e==null&&(e=ge(oe(r))),e instanceof Uint8Array?Fs(r,e,t):H4(r,e,t)}function Me(r,e=0){return r instanceof Uint8Array?Hs(r,e):q4(r,e)}var qs=new Float32Array([-0]),Ct=new Uint8Array(qs.buffer);function g0(r,e,t){qs[0]=r,e[t]=Ct[0],e[t+1]=Ct[1],e[t+2]=Ct[2],e[t+3]=Ct[3]}function m0(r,e){return Ct[0]=r[e],Ct[1]=r[e+1],Ct[2]=r[e+2],Ct[3]=r[e+3],qs[0]}var Ks=new Float64Array([-0]),Ae=new Uint8Array(Ks.buffer);function y0(r,e,t){Ks[0]=r,e[t]=Ae[0],e[t+1]=Ae[1],e[t+2]=Ae[2],e[t+3]=Ae[3],e[t+4]=Ae[4],e[t+5]=Ae[5],e[t+6]=Ae[6],e[t+7]=Ae[7]}function w0(r,e){return Ae[0]=r[e],Ae[1]=r[e+1],Ae[2]=r[e+2],Ae[3]=r[e+3],Ae[4]=r[e+4],Ae[5]=r[e+5],Ae[6]=r[e+6],Ae[7]=r[e+7],Ks[0]}var K4=BigInt(Number.MAX_SAFE_INTEGER),$4=BigInt(Number.MIN_SAFE_INTEGER),Ve=class r{lo;hi;constructor(e,t){this.lo=e|0,this.hi=t|0}toNumber(e=!1){if(!e&&this.hi>>>31>0){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(t+n*4294967296)}return this.lo+this.hi*4294967296}toBigInt(e=!1){if(e)return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n);if(this.hi>>>31){let t=~this.lo+1>>>0,n=~this.hi>>>0;return t===0&&(n=n+1>>>0),-(BigInt(t)+(BigInt(n)<<32n))}return BigInt(this.lo>>>0)+(BigInt(this.hi>>>0)<<32n)}toString(e=!1){return this.toBigInt(e).toString()}zzEncode(){let e=this.hi>>31;return this.hi=((this.hi<<1|this.lo>>>31)^e)>>>0,this.lo=(this.lo<<1^e)>>>0,this}zzDecode(){let e=-(this.lo&1);return this.lo=((this.lo>>>1|this.hi<<31)^e)>>>0,this.hi=(this.hi>>>1^e)>>>0,this}length(){let e=this.lo,t=(this.lo>>>28|this.hi<<4)>>>0,n=this.hi>>>24;return n===0?t===0?e<16384?e<128?1:2:e<2097152?3:4:t<16384?t<128?5:6:t<2097152?7:8:n<128?9:10}static fromBigInt(e){if(e===0n)return nr;if(e<K4&&e>$4)return this.fromNumber(Number(e));let t=e<0n;t&&(e=-e);let n=e>>32n,i=e-(n<<32n);return t&&(n=~n|0n,i=~i|0n,++i>b0&&(i=0n,++n>b0&&(n=0n))),new r(Number(i),Number(n))}static fromNumber(e){if(e===0)return nr;let t=e<0;t&&(e=-e);let n=e>>>0,i=(e-n)/4294967296>>>0;return t&&(i=~i>>>0,n=~n>>>0,++n>4294967295&&(n=0,++i>4294967295&&(i=0))),new r(n,i)}static from(e){return typeof e=="number"?r.fromNumber(e):typeof e=="bigint"?r.fromBigInt(e):typeof e=="string"?r.fromBigInt(BigInt(e)):e.low!=null||e.high!=null?new r(e.low>>>0,e.high>>>0):nr}},nr=new Ve(0,0);nr.toBigInt=function(){return 0n};nr.zzEncode=nr.zzDecode=function(){return this};nr.length=function(){return 1};var b0=4294967296n;function x0(r){let e=0,t=0;for(let n=0;n<r.length;++n)t=r.charCodeAt(n),t<128?e+=1:t<2048?e+=2:(t&64512)===55296&&(r.charCodeAt(n+1)&64512)===56320?(++n,e+=4):e+=3;return e}function v0(r,e,t){if(t-e<1)return"";let i,s=[],o=0,a;for(;e<t;)a=r[e++],a<128?s[o++]=a:a>191&&a<224?s[o++]=(a&31)<<6|r[e++]&63:a>239&&a<365?(a=((a&7)<<18|(r[e++]&63)<<12|(r[e++]&63)<<6|r[e++]&63)-65536,s[o++]=55296+(a>>10),s[o++]=56320+(a&1023)):s[o++]=(a&15)<<12|(r[e++]&63)<<6|r[e++]&63,o>8191&&((i??(i=[])).push(String.fromCharCode.apply(String,s)),o=0);return i!=null?(o>0&&i.push(String.fromCharCode.apply(String,s.slice(0,o))),i.join("")):String.fromCharCode.apply(String,s.slice(0,o))}function $s(r,e,t){let n=t,i,s;for(let o=0;o<r.length;++o)i=r.charCodeAt(o),i<128?e[t++]=i:i<2048?(e[t++]=i>>6|192,e[t++]=i&63|128):(i&64512)===55296&&((s=r.charCodeAt(o+1))&64512)===56320?(i=65536+((i&1023)<<10)+(s&1023),++o,e[t++]=i>>18|240,e[t++]=i>>12&63|128,e[t++]=i>>6&63|128,e[t++]=i&63|128):(e[t++]=i>>12|224,e[t++]=i>>6&63|128,e[t++]=i&63|128);return t-n}function Ge(r,e){return RangeError(`index out of range: ${r.pos} + ${e??1} > ${r.len}`)}function Xn(r,e){return(r[e-4]|r[e-3]<<8|r[e-2]<<16|r[e-1]<<24)>>>0}var zs=class{buf;pos;len;_slice=Uint8Array.prototype.subarray;constructor(e){this.buf=e,this.pos=0,this.len=e.length}uint32(){let e=4294967295;if(e=(this.buf[this.pos]&127)>>>0,this.buf[this.pos++]<128||(e=(e|(this.buf[this.pos]&127)<<7)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<14)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&127)<<21)>>>0,this.buf[this.pos++]<128)||(e=(e|(this.buf[this.pos]&15)<<28)>>>0,this.buf[this.pos++]<128))return e;if((this.pos+=5)>this.len)throw this.pos=this.len,Ge(this,10);return e}int32(){return this.uint32()|0}sint32(){let e=this.uint32();return e>>>1^-(e&1)|0}bool(){return this.uint32()!==0}fixed32(){if(this.pos+4>this.len)throw Ge(this,4);return Xn(this.buf,this.pos+=4)}sfixed32(){if(this.pos+4>this.len)throw Ge(this,4);return Xn(this.buf,this.pos+=4)|0}float(){if(this.pos+4>this.len)throw Ge(this,4);let e=m0(this.buf,this.pos);return this.pos+=4,e}double(){if(this.pos+8>this.len)throw Ge(this,4);let e=w0(this.buf,this.pos);return this.pos+=8,e}bytes(){let e=this.uint32(),t=this.pos,n=this.pos+e;if(n>this.len)throw Ge(this,e);return this.pos+=e,t===n?new Uint8Array(0):this.buf.subarray(t,n)}string(){let e=this.bytes();return v0(e,0,e.length)}skip(e){if(typeof e=="number"){if(this.pos+e>this.len)throw Ge(this,e);this.pos+=e}else do if(this.pos>=this.len)throw Ge(this);while(this.buf[this.pos++]&128);return this}skipType(e){switch(e){case 0:this.skip();break;case 1:this.skip(8);break;case 2:this.skip(this.uint32());break;case 3:for(;(e=this.uint32()&7)!==4;)this.skipType(e);break;case 5:this.skip(4);break;default:throw Error(`invalid wire type ${e} at offset ${this.pos}`)}return this}readLongVarint(){let e=new Ve(0,0),t=0;if(this.len-this.pos>4){for(;t<4;++t)if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e;if(e.lo=(e.lo|(this.buf[this.pos]&127)<<28)>>>0,e.hi=(e.hi|(this.buf[this.pos]&127)>>4)>>>0,this.buf[this.pos++]<128)return e;t=0}else{for(;t<3;++t){if(this.pos>=this.len)throw Ge(this);if(e.lo=(e.lo|(this.buf[this.pos]&127)<<t*7)>>>0,this.buf[this.pos++]<128)return e}return e.lo=(e.lo|(this.buf[this.pos++]&127)<<t*7)>>>0,e}if(this.len-this.pos>4){for(;t<5;++t)if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}else for(;t<5;++t){if(this.pos>=this.len)throw Ge(this);if(e.hi=(e.hi|(this.buf[this.pos]&127)<<t*7+3)>>>0,this.buf[this.pos++]<128)return e}throw Error("invalid varint encoding")}readFixed64(){if(this.pos+8>this.len)throw Ge(this,8);let e=Xn(this.buf,this.pos+=4),t=Xn(this.buf,this.pos+=4);return new Ve(e,t)}int64(){return this.readLongVarint().toBigInt()}int64Number(){return this.readLongVarint().toNumber()}int64String(){return this.readLongVarint().toString()}uint64(){return this.readLongVarint().toBigInt(!0)}uint64Number(){let e=Hs(this.buf,this.pos);return this.pos+=oe(e),e}uint64String(){return this.readLongVarint().toString(!0)}sint64(){return this.readLongVarint().zzDecode().toBigInt()}sint64Number(){return this.readLongVarint().zzDecode().toNumber()}sint64String(){return this.readLongVarint().zzDecode().toString()}fixed64(){return this.readFixed64().toBigInt()}fixed64Number(){return this.readFixed64().toNumber()}fixed64String(){return this.readFixed64().toString()}sfixed64(){return this.readFixed64().toBigInt()}sfixed64Number(){return this.readFixed64().toNumber()}sfixed64String(){return this.readFixed64().toString()}};function Gs(r){return new zs(r instanceof Uint8Array?r:r.subarray())}function tt(r,e,t){let n=Gs(r);return e.decode(n,void 0,t)}var Ys={};ke(Ys,{base10:()=>Z4});var vl=new Uint8Array(0);function A0(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 dt(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 S0(r){return new TextEncoder().encode(r)}function B0(r){return new TextDecoder().decode(r)}function z4(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 i=0;i<r.length;i++){var s=r.charAt(i),o=s.charCodeAt(0);if(t[o]!==255)throw new TypeError(s+" is ambiguous");t[o]=i}var a=r.length,c=r.charAt(0),l=Math.log(a)/Math.log(256),u=Math.log(256)/Math.log(a);function f(y){if(y instanceof Uint8Array||(ArrayBuffer.isView(y)?y=new Uint8Array(y.buffer,y.byteOffset,y.byteLength):Array.isArray(y)&&(y=Uint8Array.from(y))),!(y instanceof Uint8Array))throw new TypeError("Expected Uint8Array");if(y.length===0)return"";for(var w=0,d=0,x=0,E=y.length;x!==E&&y[x]===0;)x++,w++;for(var g=(E-x)*u+1>>>0,A=new Uint8Array(g);x!==E;){for(var R=y[x],T=0,I=g-1;(R!==0||T<d)&&I!==-1;I--,T++)R+=256*A[I]>>>0,A[I]=R%a>>>0,R=R/a>>>0;if(R!==0)throw new Error("Non-zero carry");d=T,x++}for(var k=g-d;k!==g&&A[k]===0;)k++;for(var L=c.repeat(w);k<g;++k)L+=r.charAt(A[k]);return L}function h(y){if(typeof y!="string")throw new TypeError("Expected String");if(y.length===0)return new Uint8Array;var w=0;if(y[w]!==" "){for(var d=0,x=0;y[w]===c;)d++,w++;for(var E=(y.length-w)*l+1>>>0,g=new Uint8Array(E);y[w];){var A=t[y.charCodeAt(w)];if(A===255)return;for(var R=0,T=E-1;(A!==0||R<x)&&T!==-1;T--,R++)A+=a*g[T]>>>0,g[T]=A%256>>>0,A=A/256>>>0;if(A!==0)throw new Error("Non-zero carry");x=R,w++}if(y[w]!==" "){for(var I=E-x;I!==E&&g[I]===0;)I++;for(var k=new Uint8Array(d+(E-I)),L=d;I!==E;)k[L++]=g[I++];return k}}}function p(y){var w=h(y);if(w)return w;throw new Error(`Non-${e} character`)}return{encode:f,decodeUnsafe:h,decode:p}}var G4=z4,j4=G4,k0=j4;var js=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")}},Ws=class{name;prefix;baseDecode;prefixCodePoint;constructor(e,t,n){this.name=e,this.prefix=t;let i=t.codePointAt(0);if(i===void 0)throw new Error("Invalid prefix character");this.prefixCodePoint=i,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 T0(this,e)}},Qs=class{decoders;constructor(e){this.decoders=e}or(e){return T0(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 T0(r,e){return new Qs({...r.decoders??{[r.prefix]:r},...e.decoders??{[e.prefix]:e}})}var Zs=class{name;prefix;baseEncode;baseDecode;encoder;decoder;constructor(e,t,n,i){this.name=e,this.prefix=t,this.baseEncode=n,this.baseDecode=i,this.encoder=new js(e,t,n),this.decoder=new Ws(e,t,i)}encode(e){return this.encoder.encode(e)}decode(e){return this.decoder.decode(e)}};function Ar({name:r,prefix:e,encode:t,decode:n}){return new Zs(r,e,t,n)}function Ut({name:r,prefix:e,alphabet:t}){let{encode:n,decode:i}=k0(t,r);return Ar({prefix:e,name:r,encode:n,decode:s=>dt(i(s))})}function W4(r,e,t,n){let i={};for(let u=0;u<e.length;++u)i[e[u]]=u;let s=r.length;for(;r[s-1]==="=";)--s;let o=new Uint8Array(s*t/8|0),a=0,c=0,l=0;for(let u=0;u<s;++u){let f=i[r[u]];if(f===void 0)throw new SyntaxError(`Non-${n} character`);c=c<<t|f,a+=t,a>=8&&(a-=8,o[l++]=255&c>>a)}if(a>=t||255&c<<8-a)throw new SyntaxError("Unexpected end of data");return o}function Q4(r,e,t){let n=e[e.length-1]==="=",i=(1<<t)-1,s="",o=0,a=0;for(let c=0;c<r.length;++c)for(a=a<<8|r[c],o+=8;o>t;)o-=t,s+=e[i&a>>o];if(o!==0&&(s+=e[i&a<<t-o]),n)for(;s.length*t&7;)s+="=";return s}function ne({name:r,prefix:e,bitsPerChar:t,alphabet:n}){return Ar({prefix:e,name:r,encode(i){return Q4(i,n,t)},decode(i){return W4(i,n,t,r)}})}var Z4=Ut({prefix:"9",name:"base10",alphabet:"0123456789"});var Xs={};ke(Xs,{base16:()=>Y4,base16upper:()=>X4});var Y4=ne({prefix:"f",name:"base16",alphabet:"0123456789abcdef",bitsPerChar:4}),X4=ne({prefix:"F",name:"base16upper",alphabet:"0123456789ABCDEF",bitsPerChar:4});var Js={};ke(Js,{base2:()=>J4});var J4=ne({prefix:"0",name:"base2",alphabet:"01",bitsPerChar:1});var eo={};ke(eo,{base256emoji:()=>i5});var R0=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}"),e5=R0.reduce((r,e,t)=>(r[t]=e,r),[]),t5=R0.reduce((r,e,t)=>{let n=e.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${e}`);return r[n]=t,r},[]);function r5(r){return r.reduce((e,t)=>(e+=e5[t],e),"")}function n5(r){let e=[];for(let t of r){let n=t.codePointAt(0);if(n==null)throw new Error(`Invalid character: ${t}`);let i=t5[n];if(i==null)throw new Error(`Non-base256emoji character: ${t}`);e.push(i)}return new Uint8Array(e)}var i5=Ar({prefix:"\u{1F680}",name:"base256emoji",encode:r5,decode:n5});var to={};ke(to,{base32:()=>pt,base32hex:()=>c5,base32hexpad:()=>u5,base32hexpadupper:()=>f5,base32hexupper:()=>l5,base32pad:()=>o5,base32padupper:()=>a5,base32upper:()=>s5,base32z:()=>h5});var pt=ne({prefix:"b",name:"base32",alphabet:"abcdefghijklmnopqrstuvwxyz234567",bitsPerChar:5}),s5=ne({prefix:"B",name:"base32upper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567",bitsPerChar:5}),o5=ne({prefix:"c",name:"base32pad",alphabet:"abcdefghijklmnopqrstuvwxyz234567=",bitsPerChar:5}),a5=ne({prefix:"C",name:"base32padupper",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZ234567=",bitsPerChar:5}),c5=ne({prefix:"v",name:"base32hex",alphabet:"0123456789abcdefghijklmnopqrstuv",bitsPerChar:5}),l5=ne({prefix:"V",name:"base32hexupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV",bitsPerChar:5}),u5=ne({prefix:"t",name:"base32hexpad",alphabet:"0123456789abcdefghijklmnopqrstuv=",bitsPerChar:5}),f5=ne({prefix:"T",name:"base32hexpadupper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUV=",bitsPerChar:5}),h5=ne({prefix:"h",name:"base32z",alphabet:"ybndrfg8ejkmcpqxot1uwisza345h769",bitsPerChar:5});var ro={};ke(ro,{base36:()=>ln,base36upper:()=>d5});var ln=Ut({prefix:"k",name:"base36",alphabet:"0123456789abcdefghijklmnopqrstuvwxyz"}),d5=Ut({prefix:"K",name:"base36upper",alphabet:"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"});var no={};ke(no,{base58btc:()=>Y,base58flickr:()=>p5});var Y=Ut({name:"base58btc",prefix:"z",alphabet:"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"}),p5=Ut({name:"base58flickr",prefix:"Z",alphabet:"123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ"});var io={};ke(io,{base64:()=>g5,base64pad:()=>m5,base64url:()=>y5,base64urlpad:()=>w5});var g5=ne({prefix:"m",name:"base64",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",bitsPerChar:6}),m5=ne({prefix:"M",name:"base64pad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",bitsPerChar:6}),y5=ne({prefix:"u",name:"base64url",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_",bitsPerChar:6}),w5=ne({prefix:"U",name:"base64urlpad",alphabet:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=",bitsPerChar:6});var so={};ke(so,{base8:()=>b5});var b5=ne({prefix:"7",name:"base8",alphabet:"01234567",bitsPerChar:3});var oo={};ke(oo,{identity:()=>x5});var x5=Ar({prefix:"\0",name:"identity",encode:r=>B0(r),decode:r=>S0(r)});var Ol=new TextEncoder,Ml=new TextDecoder;var P0=85;var co={};ke(co,{identity:()=>gt});var E5=C0,L0=128,A5=127,S5=~A5,B5=Math.pow(2,31);function C0(r,e,t){e=e||[],t=t||0;for(var n=t;r>=B5;)e[t++]=r&255|L0,r/=128;for(;r&S5;)e[t++]=r&255|L0,r>>>=7;return e[t]=r|0,C0.bytes=t-n+1,e}var I5=ao,k5=128,_0=127;function ao(r,n){var t=0,n=n||0,i=0,s=n,o,a=r.length;do{if(s>=a)throw ao.bytes=0,new RangeError("Could not decode varint");o=r[s++],t+=i<28?(o&_0)<<i:(o&_0)*Math.pow(2,i),i+=7}while(o>=k5);return ao.bytes=s-n,t}var T5=Math.pow(2,7),R5=Math.pow(2,14),P5=Math.pow(2,21),N5=Math.pow(2,28),L5=Math.pow(2,35),_5=Math.pow(2,42),C5=Math.pow(2,49),U5=Math.pow(2,56),D5=Math.pow(2,63),O5=function(r){return r<T5?1:r<R5?2:r<P5?3:r<N5?4:r<L5?5:r<_5?6:r<C5?7:r<U5?8:r<D5?9:10},M5={encode:E5,decode:I5,encodingLength:O5},V5=M5,un=V5;function fn(r,e=0){return[un.decode(r,e),un.decode.bytes]}function Sr(r,e,t=0){return un.encode(r,e,t),e}function Br(r){return un.encodingLength(r)}function je(r,e){let t=e.byteLength,n=Br(r),i=n+Br(t),s=new Uint8Array(i+t);return Sr(r,s,0),Sr(t,s,n),s.set(e,i),new Ir(r,t,e,s)}function me(r){let e=dt(r),[t,n]=fn(e),[i,s]=fn(e.subarray(n)),o=e.subarray(n+s);if(o.byteLength!==i)throw new Error("Incorrect length");return new Ir(t,i,o,e)}function U0(r,e){if(r===e)return!0;{let t=e;return r.code===t.code&&r.size===t.size&&t.bytes instanceof Uint8Array&&A0(r.bytes,t.bytes)}}var Ir=class{code;size;digest;bytes;constructor(e,t,n,i){this.code=e,this.size=t,this.digest=n,this.bytes=i}};var D0=0,F5="identity",O0=dt;function H5(r){return je(D0,O0(r))}var gt={code:D0,name:F5,encode:O0,digest:H5};var fo={};ke(fo,{sha256:()=>mt,sha512:()=>q5});function uo({name:r,code:e,encode:t}){return new lo(r,e,t)}var lo=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?je(this.code,t):t.then(n=>je(this.code,n))}else throw Error("Unknown type, must be binary type")}};function V0(r){return async e=>new Uint8Array(await crypto.subtle.digest(r,e))}var mt=uo({name:"sha2-256",code:18,encode:V0("SHA-256")}),q5=uo({name:"sha2-512",code:19,encode:V0("SHA-512")});function F0(r,e){let{bytes:t,version:n}=r;switch(n){case 0:return $5(t,ho(r),e??Y.encoder);default:return z5(t,ho(r),e??pt.encoder)}}var H0=new WeakMap;function ho(r){let e=H0.get(r);if(e==null){let t=new Map;return H0.set(r,t),t}return e}var re=class r{code;version;multihash;bytes;"/";constructor(e,t,n,i){this.code=t,this.version=e,this.multihash=n,this.bytes=i,this["/"]=i}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!==hn)throw new Error("Cannot convert a non dag-pb CID to CIDv0");if(t.code!==G5)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=je(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&&U0(e.multihash,n.multihash)}toString(e){return F0(this,e)}toJSON(){return{"/":F0(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:i,multihash:s,bytes:o}=t;return new r(n,i,s,o??q0(n,i,s.bytes))}else if(t[j5]===!0){let{version:n,multihash:i,code:s}=t,o=me(i);return r.create(n,s,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!==hn)throw new Error(`Version 0 CID must use dag-pb (code: ${hn}) block encoding`);return new r(e,t,n,n.bytes)}case 1:{let i=q0(e,t,n.bytes);return new r(e,t,n,i)}default:throw new Error("Invalid version")}}static createV0(e){return r.create(0,hn,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,i=dt(e.subarray(n,n+t.multihashSize));if(i.byteLength!==t.multihashSize)throw new Error("Incorrect length");let s=i.subarray(t.multihashSize-t.digestSize),o=new Ir(t.multihashCode,t.digestSize,s,i);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,h]=fn(e.subarray(t));return t+=h,f},i=n(),s=hn;if(i===18?(i=0,t=0):s=n(),i!==0&&i!==1)throw new RangeError(`Invalid CID version ${i}`);let o=t,a=n(),c=n(),l=t+c,u=l-o;return{version:i,codec:s,multihashCode:a,digestSize:c,multihashSize:u,size:l}}static parse(e,t){let[n,i]=K5(e,t),s=r.decode(i);if(s.version===0&&e[0]!=="Q")throw Error("Version 0 CID string must not include multibase prefix");return ho(s).set(n,e),s}};function K5(r,e){switch(r[0]){case"Q":{let t=e??Y;return[Y.prefix,t.decode(`${Y.prefix}${r}`)]}case Y.prefix:{let t=e??Y;return[Y.prefix,t.decode(r)]}case pt.prefix:{let t=e??pt;return[pt.prefix,t.decode(r)]}case ln.prefix:{let t=e??ln;return[ln.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 $5(r,e,t){let{prefix:n}=t;if(n!==Y.prefix)throw Error(`Cannot string encode V0 in ${t.name} encoding`);let i=e.get(n);if(i==null){let s=t.encode(r).slice(1);return e.set(n,s),s}else return i}function z5(r,e,t){let{prefix:n}=t,i=e.get(n);if(i==null){let s=t.encode(r);return e.set(n,s),s}else return i}var hn=112,G5=18;function q0(r,e,t){let n=Br(r),i=n+Br(e),s=new Uint8Array(i+t.byteLength);return Sr(r,s,0),Sr(e,s,n),s.set(t,i),s}var j5=Symbol.for("@ipld/js-cid/CID");var dn={...oo,...Js,...so,...Ys,...Xs,...to,...ro,...no,...io,...eo},o9={...fo,...co};function $0(r,e,t,n){return{name:r,prefix:e,encoder:{name:r,prefix:e,encode:t},decoder:{decode:n}}}var K0=$0("utf8","u",r=>"u"+new TextDecoder("utf8").decode(r),r=>new TextEncoder().encode(r.substring(1))),po=$0("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=ge(r.length);for(let t=0;t<r.length;t++)e[t]=r.charCodeAt(t);return e}),W5={utf8:K0,"utf-8":K0,hex:dn.base16,latin1:po,ascii:po,binary:po,...dn},e1=W5;function Q(r,e="utf8"){let t=e1[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.decoder.decode(`${t.prefix}${r}`)}function go(r){let e=r??8192,t=e>>>1,n,i=e;return function(o){if(o<1||o>t)return ge(o);i+o>e&&(n=ge(e),i=0);let a=n.subarray(i,i+=o);return i&7&&(i=(i|7)+1),a}}var ir=class{fn;len;next;val;constructor(e,t,n){this.fn=e,this.len=t,this.next=void 0,this.val=n}};function mo(){}var wo=class{head;tail;len;next;constructor(e){this.head=e.head,this.tail=e.tail,this.len=e.len,this.next=e.states}},Q5=go();function Z5(r){return globalThis.Buffer!=null?ge(r):Q5(r)}var gn=class{len;head;tail;states;constructor(){this.len=0,this.head=new ir(mo,0,0),this.tail=this.head,this.states=null}_push(e,t,n){return this.tail=this.tail.next=new ir(e,t,n),this.len+=t,this}uint32(e){return this.len+=(this.tail=this.tail.next=new bo((e=e>>>0)<128?1:e<16384?2:e<2097152?3:e<268435456?4:5,e)).len,this}int32(e){return e<0?this._push(t1,10,Ve.fromNumber(e)):this.uint32(e)}sint32(e){return this.uint32((e<<1^e>>31)>>>0)}uint64(e){let t=Ve.fromBigInt(e);return this._push(t1,t.length(),t)}uint64Number(e){return this._push(Fs,oe(e),e)}uint64String(e){return this.uint64(BigInt(e))}int64(e){return this.uint64(e)}int64Number(e){return this.uint64Number(e)}int64String(e){return this.uint64String(e)}sint64(e){let t=Ve.fromBigInt(e).zzEncode();return this._push(t1,t.length(),t)}sint64Number(e){let t=Ve.fromNumber(e).zzEncode();return this._push(t1,t.length(),t)}sint64String(e){return this.sint64(BigInt(e))}bool(e){return this._push(yo,1,e?1:0)}fixed32(e){return this._push(pn,4,e>>>0)}sfixed32(e){return this.fixed32(e)}fixed64(e){let t=Ve.fromBigInt(e);return this._push(pn,4,t.lo)._push(pn,4,t.hi)}fixed64Number(e){let t=Ve.fromNumber(e);return this._push(pn,4,t.lo)._push(pn,4,t.hi)}fixed64String(e){return this.fixed64(BigInt(e))}sfixed64(e){return this.fixed64(e)}sfixed64Number(e){return this.fixed64Number(e)}sfixed64String(e){return this.fixed64String(e)}float(e){return this._push(g0,4,e)}double(e){return this._push(y0,8,e)}bytes(e){let t=e.length>>>0;return t===0?this._push(yo,1,0):this.uint32(t)._push(X5,t,e)}string(e){let t=x0(e);return t!==0?this.uint32(t)._push($s,t,e):this._push(yo,1,0)}fork(){return this.states=new wo(this),this.head=this.tail=new ir(mo,0,0),this.len=0,this}reset(){return this.states!=null?(this.head=this.states.head,this.tail=this.states.tail,this.len=this.states.len,this.states=this.states.next):(this.head=this.tail=new ir(mo,0,0),this.len=0),this}ldelim(){let e=this.head,t=this.tail,n=this.len;return this.reset().uint32(n),n!==0&&(this.tail.next=e.next,this.tail=t,this.len+=n),this}finish(){let e=this.head.next,t=Z5(this.len),n=0;for(;e!=null;)e.fn(e.val,t,n),n+=e.len,e=e.next;return t}};function yo(r,e,t){e[t]=r&255}function Y5(r,e,t){for(;r>127;)e[t++]=r&127|128,r>>>=7;e[t]=r}var bo=class extends ir{next;constructor(e,t){super(Y5,e,t),this.next=void 0}};function t1(r,e,t){for(;r.hi!==0;)e[t++]=r.lo&127|128,r.lo=(r.lo>>>7|r.hi<<25)>>>0,r.hi>>>=7;for(;r.lo>127;)e[t++]=r.lo&127|128,r.lo=r.lo>>>7;e[t++]=r.lo}function pn(r,e,t){e[t]=r&255,e[t+1]=r>>>8&255,e[t+2]=r>>>16&255,e[t+3]=r>>>24}function X5(r,e,t){e.set(r,t)}globalThis.Buffer!=null&&(gn.prototype.bytes=function(r){let e=r.length>>>0;return this.uint32(e),e>0&&this._push(J5,e,r),this},gn.prototype.string=function(r){let e=globalThis.Buffer.byteLength(r);return this.uint32(e),e>0&&this._push(e6,e,r),this});function J5(r,e,t){e.set(r,t)}function e6(r,e,t){r.length<40?$s(r,e,t):e.utf8Write!=null?e.utf8Write(r,t):e.set(Q(r),t)}function xo(){return new gn}function rt(r,e){let t=xo();return e.encode(r,t,{lengthDelimited:!1}),t.finish()}var kr;(function(r){r[r.VARINT=0]="VARINT",r[r.BIT64=1]="BIT64",r[r.LENGTH_DELIMITED=2]="LENGTH_DELIMITED",r[r.START_GROUP=3]="START_GROUP",r[r.END_GROUP=4]="END_GROUP",r[r.BIT32=5]="BIT32"})(kr||(kr={}));function r1(r,e,t,n){return{name:r,type:e,encode:t,decode:n}}function Tr(r){function e(i){if(r[i.toString()]==null)throw new Error("Invalid enum value");return r[i]}let t=function(s,o){let a=e(s);o.int32(a)},n=function(s){let o=s.int32();return e(o)};return r1("enum",kr.VARINT,t,n)}function nt(r,e){return r1("message",kr.LENGTH_DELIMITED,r,e)}var Rr=class extends Error{code="ERR_MAX_LENGTH";name="MaxLengthError"};var mn;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.key!=null&&t.key.byteLength>0&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&t.value.byteLength>0&&(n.uint32(18),n.bytes(t.value)),t.timeReceived!=null&&t.timeReceived!==""&&(n.uint32(42),n.string(t.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={key:_e(0),value:_e(0),timeReceived:""},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.key=t.bytes();break}case 2:{s.value=t.bytes();break}case 5:{s.timeReceived=t.string();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(mn||(mn={}));function z0(r){let e=r.getUTCFullYear(),t=String(r.getUTCMonth()+1).padStart(2,"0"),n=String(r.getUTCDate()).padStart(2,"0"),i=String(r.getUTCHours()).padStart(2,"0"),s=String(r.getUTCMinutes()).padStart(2,"0"),o=String(r.getUTCSeconds()).padStart(2,"0"),a=r.getUTCMilliseconds(),c=String(a*1e3*1e3).padStart(9,"0");return`${e}-${t}-${n}T${i}:${s}:${o}.${c}Z`}function G0(r){let e=new RegExp("(\\d{4})-(\\d{2})-(\\d{2})T(\\d{2}):(\\d{2}):(\\d{2})\\.(\\d+)Z"),t=String(r).trim().match(e);if(t==null)throw new Error("Invalid format");let n=parseInt(t[1],10),i=parseInt(t[2],10)-1,s=parseInt(t[3],10),o=parseInt(t[4],10),a=parseInt(t[5],10),c=parseInt(t[6],10),l=parseInt(t[7].slice(0,-6),10);return new Date(Date.UTC(n,i,s,o,a,c,l))}var ue=class r{key;value;timeReceived;constructor(e,t,n){if(!(e instanceof Uint8Array))throw new Error("key must be a Uint8Array");if(!(t instanceof Uint8Array))throw new Error("value must be a Uint8Array");this.key=e,this.value=t,this.timeReceived=n}serialize(){return mn.encode(this.prepareSerialize())}prepareSerialize(){return{key:this.key,value:this.value,timeReceived:z0(this.timeReceived)}}static deserialize(e){let t=mn.decode(e);return new r(t.key,t.value,new Date(t.timeReceived))}static fromDeserialized(e){let t=G0(e.timeReceived);if(e.key==null)throw new Error("key missing from deserialized object");if(e.value==null)throw new Error("value missing from deserialized object");return new r(e.key,e.value,t)}};function r6(r){let[e,t]=r[Symbol.asyncIterator]!=null?[r[Symbol.asyncIterator](),Symbol.asyncIterator]:[r[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>e.next(),push:i=>{n.push(i)},next:()=>n.length>0?{done:!1,value:n.shift()}:e.next(),[t](){return this}}}var j0=r6;function n6(r){return r[Symbol.asyncIterator]!=null}function i6(r,e){let t=0;if(n6(r))return async function*(){for await(let c of r)yield e(c,t++)}();let n=j0(r),{value:i,done:s}=n.next();if(s===!0)return function*(){}();let o=e(i,t++);if(typeof o.then=="function")return async function*(){yield await o;for await(let c of n)yield e(c,t++)}();let a=e;return function*(){yield o;for(let c of n)yield a(c,t++)}()}var Pr=i6;var n1=globalThis.CustomEvent??Event;async function*sr(r,e={}){let t=e.concurrency??1/0;t<1&&(t=1/0);let n=e.ordered==null?!1:e.ordered,i=new EventTarget,s=[],o=se(),a=se(),c=!1,l,u=!1;i.addEventListener("task-complete",()=>{a.resolve()}),Promise.resolve().then(async()=>{try{for await(let y of r){if(s.length===t&&(o=se(),await o.promise),u)break;let w={done:!1};s.push(w),y().then(d=>{w.done=!0,w.ok=!0,w.value=d,i.dispatchEvent(new n1("task-complete"))},d=>{w.done=!0,w.err=d,i.dispatchEvent(new n1("task-complete"))})}c=!0,i.dispatchEvent(new n1("task-complete"))}catch(y){l=y,i.dispatchEvent(new n1("task-complete"))}});function f(){return n?s[0]?.done:!!s.find(y=>y.done)}function*h(){for(;s.length>0&&s[0].done;){let y=s[0];if(s.shift(),y.ok)yield y.value;else throw u=!0,o.resolve(),y.err;o.resolve()}}function*p(){for(;f();)for(let y=0;y<s.length;y++)if(s[y].done){let w=s[y];if(s.splice(y,1),y--,w.ok)yield w.value;else throw u=!0,o.resolve(),w.err;o.resolve()}}for(;;){if(f()||(a=se(),await a.promise),l!=null)throw l;if(n?yield*h():yield*p(),c&&s.length===0)break}}var i1=class{buffer;mask;top;btm;next;constructor(e){if(!(e>0)||e-1&e)throw new Error("Max size for a FixedFIFO should be a power of two");this.buffer=new Array(e),this.mask=e-1,this.top=0,this.btm=0,this.next=null}push(e){return this.buffer[this.top]!==void 0?!1:(this.buffer[this.top]=e,this.top=this.top+1&this.mask,!0)}shift(){let e=this.buffer[this.btm];if(e!==void 0)return this.buffer[this.btm]=void 0,this.btm=this.btm+1&this.mask,e}isEmpty(){return this.buffer[this.btm]===void 0}},Nr=class{size;hwm;head;tail;constructor(e={}){this.hwm=e.splitLimit??16,this.head=new i1(this.hwm),this.tail=this.head,this.size=0}calculateSize(e){return e?.byteLength!=null?e.byteLength:1}push(e){if(e?.value!=null&&(this.size+=this.calculateSize(e.value)),!this.head.push(e)){let t=this.head;this.head=t.next=new i1(2*this.head.buffer.length),this.head.push(e)}}shift(){let e=this.tail.shift();if(e===void 0&&this.tail.next!=null){let t=this.tail.next;this.tail.next=null,this.tail=t,e=this.tail.shift()}return e?.value!=null&&(this.size-=this.calculateSize(e.value)),e}isEmpty(){return this.head.isEmpty()}};var vo=class extends Error{type;code;constructor(e,t){super(e??"The operation was aborted"),this.type="aborted",this.code=t??"ABORT_ERR"}};function Lr(r={}){return s6(t=>{let n=t.shift();if(n==null)return{done:!0};if(n.error!=null)throw n.error;return{done:n.done===!0,value:n.value}},r)}function s6(r,e){e=e??{};let t=e.onEnd,n=new Nr,i,s,o,a=se(),c=async()=>{try{return n.isEmpty()?o?{done:!0}:await new Promise((d,x)=>{s=E=>{s=null,n.push(E);try{d(r(n))}catch(g){x(g)}return i}}):r(n)}finally{n.isEmpty()&&queueMicrotask(()=>{a.resolve(),a=se()})}},l=d=>s!=null?s(d):(n.push(d),i),u=d=>(n=new Nr,s!=null?s({error:d}):(n.push({error:d}),i)),f=d=>{if(o)return i;if(e?.objectMode!==!0&&d?.byteLength==null)throw new Error("objectMode was not true but tried to push non-Uint8Array value");return l({done:!1,value:d})},h=d=>o?i:(o=!0,d!=null?u(d):l({done:!0})),p=()=>(n=new Nr,h(),{done:!0}),y=d=>(h(d),{done:!0});if(i={[Symbol.asyncIterator](){return this},next:c,return:p,throw:y,push:f,end:h,get readableLength(){return n.size},onEmpty:async d=>{let x=d?.signal;if(x?.throwIfAborted(),n.isEmpty())return;let E,g;x!=null&&(E=new Promise((A,R)=>{g=()=>{R(new vo)},x.addEventListener("abort",g)}));try{await Promise.race([a.promise,E])}finally{g!=null&&x!=null&&x?.removeEventListener("abort",g)}}},t==null)return i;let w=i;return i={[Symbol.asyncIterator](){return this},next(){return w.next()},throw(d){return w.throw(d),t!=null&&(t(d),t=void 0),{done:!0}},return(){return w.return(),t!=null&&(t(),t=void 0),{done:!0}},push:f,end(d){return w.end(d),t!=null&&(t(d),t=void 0),i},get readableLength(){return w.readableLength},onEmpty:d=>w.onEmpty(d)},i}function o6(r){return r[Symbol.asyncIterator]!=null}function a6(...r){let e=[];for(let t of r)o6(t)||e.push(t);return e.length===r.length?function*(){for(let t of e)yield*t}():async function*(){let t=Lr({objectMode:!0});Promise.resolve().then(async()=>{try{await Promise.all(r.map(async n=>{for await(let i of n)t.push(i)})),t.end()}catch(n){t.end(n)}}),yield*t}()}var s1=a6;function Dt(r,...e){if(r==null)throw new Error("Empty pipeline");if(Eo(r)){let n=r;r=()=>n.source}else if(Q0(r)||W0(r)){let n=r;r=()=>n}let t=[r,...e];if(t.length>1&&Eo(t[t.length-1])&&(t[t.length-1]=t[t.length-1].sink),t.length>2)for(let n=1;n<t.length-1;n++)Eo(t[n])&&(t[n]=l6(t[n]));return c6(...t)}var c6=(...r)=>{let e;for(;r.length>0;)e=r.shift()(e);return e},W0=r=>r?.[Symbol.asyncIterator]!=null,Q0=r=>r?.[Symbol.iterator]!=null,Eo=r=>r==null?!1:r.sink!=null&&r.source!=null,l6=r=>e=>{let t=r.sink(e);if(t?.then!=null){let n=Lr({objectMode:!0});t.then(()=>{n.end()},o=>{n.end(o)});let i,s=r.source;if(W0(s))i=async function*(){yield*s,n.end()};else if(Q0(s))i=function*(){yield*s,n.end()};else throw new Error("Unknown duplex source type - must be Iterable or AsyncIterable");return s1(n,i())}return r.source};function X(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}var Ot=class extends Error{constructor(e="Query error"){super(e),this.name="QueryError"}},o1=class extends Error{constructor(e="Query aborted"){super(e),this.name="QueryAbortedError"}},a1=class extends Error{constructor(e="Invalid record"){super(e),this.name="InvalidRecordError"}},c1=class extends Error{constructor(e="No selector function configured for prefix"){super(e),this.name="MissingSelectorError"}};var Z0;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.key!=null&&(n.uint32(10),n.bytes(t.key)),t.value!=null&&(n.uint32(18),n.bytes(t.value)),t.author!=null&&(n.uint32(26),n.bytes(t.author)),t.signature!=null&&(n.uint32(34),n.bytes(t.signature)),t.timeReceived!=null&&(n.uint32(42),n.string(t.timeReceived)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.key=t.bytes();break}case 2:{s.value=t.bytes();break}case 3:{s.author=t.bytes();break}case 4:{s.signature=t.bytes();break}case 5:{s.timeReceived=t.string();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(Z0||(Z0={}));var O;(function(r){r.PUT_VALUE="PUT_VALUE",r.GET_VALUE="GET_VALUE",r.ADD_PROVIDER="ADD_PROVIDER",r.GET_PROVIDERS="GET_PROVIDERS",r.FIND_NODE="FIND_NODE",r.PING="PING"})(O||(O={}));var l1;(function(r){r[r.PUT_VALUE=0]="PUT_VALUE",r[r.GET_VALUE=1]="GET_VALUE",r[r.ADD_PROVIDER=2]="ADD_PROVIDER",r[r.GET_PROVIDERS=3]="GET_PROVIDERS",r[r.FIND_NODE=4]="FIND_NODE",r[r.PING=5]="PING"})(l1||(l1={}));(function(r){r.codec=()=>Tr(l1)})(O||(O={}));var Cr;(function(r){r.NOT_CONNECTED="NOT_CONNECTED",r.CONNECTED="CONNECTED",r.CAN_CONNECT="CAN_CONNECT",r.CANNOT_CONNECT="CANNOT_CONNECT"})(Cr||(Cr={}));var Ao;(function(r){r[r.NOT_CONNECTED=0]="NOT_CONNECTED",r[r.CONNECTED=1]="CONNECTED",r[r.CAN_CONNECT=2]="CAN_CONNECT",r[r.CANNOT_CONNECT=3]="CANNOT_CONNECT"})(Ao||(Ao={}));(function(r){r.codec=()=>Tr(Ao)})(Cr||(Cr={}));var _r;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{if(i.lengthDelimited!==!1&&n.fork(),t.id!=null&&t.id.byteLength>0&&(n.uint32(10),n.bytes(t.id)),t.multiaddrs!=null)for(let s of t.multiaddrs)n.uint32(18),n.bytes(s);t.connection!=null&&(n.uint32(24),Cr.codec().encode(t.connection,n)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={id:_e(0),multiaddrs:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.id=t.bytes();break}case 2:{if(i.limits?.multiaddrs!=null&&s.multiaddrs.length===i.limits.multiaddrs)throw new Rr('Decode error - map field "multiaddrs" had too many elements');s.multiaddrs.push(t.bytes());break}case 3:{s.connection=Cr.codec().decode(t);break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(_r||(_r={}));var yt;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{if(i.lengthDelimited!==!1&&n.fork(),t.type!=null&&l1[t.type]!==0&&(n.uint32(8),O.codec().encode(t.type,n)),t.clusterLevel!=null&&(n.uint32(80),n.int32(t.clusterLevel)),t.key!=null&&(n.uint32(18),n.bytes(t.key)),t.record!=null&&(n.uint32(26),n.bytes(t.record)),t.closer!=null)for(let s of t.closer)n.uint32(66),_r.codec().encode(s,n);if(t.providers!=null)for(let s of t.providers)n.uint32(74),_r.codec().encode(s,n);i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={type:O.PUT_VALUE,closer:[],providers:[]},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.type=O.codec().decode(t);break}case 10:{s.clusterLevel=t.int32();break}case 2:{s.key=t.bytes();break}case 3:{s.record=t.bytes();break}case 8:{if(i.limits?.closer!=null&&s.closer.length===i.limits.closer)throw new Rr('Decode error - map field "closer" had too many elements');s.closer.push(_r.codec().decode(t,t.uint32(),{limits:i.limits?.closer$}));break}case 9:{if(i.limits?.providers!=null&&s.providers.length===i.limits.providers)throw new Rr('Decode error - map field "providers" had too many elements');s.providers.push(_r.codec().decode(t,t.uint32(),{limits:i.limits?.providers$}));break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(yt||(yt={}));function So(r,e={}){let t={...r,name:"SEND_QUERY",type:0,messageName:r.type,messageType:r.type};return e.onProgress?.(new CustomEvent("kad-dht:query:send-query",{detail:t})),t}function yn(r,e={}){let t={...r,name:"PEER_RESPONSE",type:1,messageName:r.messageType,closer:r.closer??[],providers:r.providers??[]};return e.onProgress?.(new CustomEvent("kad-dht:query:peer-response",{detail:t})),t}function u1(r,e={}){let t={...r,name:"FINAL_PEER",type:2};return e.onProgress?.(new CustomEvent("kad-dht:query:final-peer",{detail:t})),t}function Fe(r,e={}){let t={...r,name:"QUERY_ERROR",type:3};return e.onProgress?.(new CustomEvent("kad-dht:query:query-error",{detail:t})),t}function Bo(r,e={}){let t={...r,name:"PROVIDER",type:4};return e.onProgress?.(new CustomEvent("kad-dht:query:provider",{detail:t})),t}function wn(r,e={}){let t={...r,name:"VALUE",type:5};return e.onProgress?.(new CustomEvent("kad-dht:query:value",{detail:t})),t}function Io(r,e={}){let t={...r,name:"DIAL_PEER",type:7};return e.onProgress?.(new CustomEvent("kad-dht:query:dial-peer",{detail:t})),t}function D(r,e="utf8"){let t=e1[e];if(t==null)throw new Error(`Unsupported encoding "${e}"`);return t.encoder.encode(r).substring(1)}function Y0(r,e,t){if(t.length===0)throw new $("No records given");let i=D(e).split("/");if(i.length<3)throw new $("Record key does not have a selector function");let s=r[i[1].toString()];if(s==null)throw new c1(`No selector function configured for key type "${i[1]}"`);return t.length===1?0:s(e,t)}function u6(r,e){return 0}var X0={pk:u6};function J0(r){if(!Number.isSafeInteger(r)||r<0)throw new Error(`positive integer expected, not ${r}`)}function f6(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Ur(r,...e){if(!f6(r))throw new Error("Uint8Array expected");if(e.length>0&&!e.includes(r.length))throw new Error(`Uint8Array expected of length ${e}, not of length=${r.length}`)}function e3(r){if(typeof r!="function"||typeof r.create!="function")throw new Error("Hash should be wrapped by utils.wrapConstructor");J0(r.outputLen),J0(r.blockLen)}function Dr(r,e=!0){if(r.destroyed)throw new Error("Hash instance has been destroyed");if(e&&r.finished)throw new Error("Hash#digest() has already been called")}function t3(r,e){Ur(r);let t=e.outputLen;if(r.length<t)throw new Error(`digestInto() expects output buffer of length at least ${t}`)}var or=typeof globalThis=="object"&&"crypto"in globalThis?globalThis.crypto:void 0;var f1=r=>new DataView(r.buffer,r.byteOffset,r.byteLength),We=(r,e)=>r<<32-e|r>>>e;var yu=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function r3(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}function bn(r){return typeof r=="string"&&(r=r3(r)),Ur(r),r}function ko(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];Ur(i),e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let s=r[n];t.set(s,i),i+=s.length}return t}var Or=class{clone(){return this._cloneInto()}},wu={}.toString;function h1(r){let e=n=>r().update(bn(n)).digest(),t=r();return e.outputLen=t.outputLen,e.blockLen=t.blockLen,e.create=()=>r(),e}function Mr(r=32){if(or&&typeof or.getRandomValues=="function")return or.getRandomValues(new Uint8Array(r));if(or&&typeof or.randomBytes=="function")return or.randomBytes(r);throw new Error("crypto.getRandomValues must be defined")}function h6(r,e,t,n){if(typeof r.setBigUint64=="function")return r.setBigUint64(e,t,n);let i=BigInt(32),s=BigInt(4294967295),o=Number(t>>i&s),a=Number(t&s),c=n?4:0,l=n?0:4;r.setUint32(e+c,o,n),r.setUint32(e+l,a,n)}var n3=(r,e,t)=>r&e^~r&t,i3=(r,e,t)=>r&e^r&t^e&t,Vr=class extends Or{constructor(e,t,n,i){super(),this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=i,this.finished=!1,this.length=0,this.pos=0,this.destroyed=!1,this.buffer=new Uint8Array(e),this.view=f1(this.buffer)}update(e){Dr(this);let{view:t,buffer:n,blockLen:i}=this;e=bn(e);let s=e.length;for(let o=0;o<s;){let a=Math.min(i-this.pos,s-o);if(a===i){let c=f1(e);for(;i<=s-o;o+=i)this.process(c,o);continue}n.set(e.subarray(o,o+a),this.pos),this.pos+=a,o+=a,this.pos===i&&(this.process(t,0),this.pos=0)}return this.length+=e.length,this.roundClean(),this}digestInto(e){Dr(this),t3(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:i,isLE:s}=this,{pos:o}=this;t[o++]=128,this.buffer.subarray(o).fill(0),this.padOffset>i-o&&(this.process(n,0),o=0);for(let f=o;f<i;f++)t[f]=0;h6(n,i-8,BigInt(this.length*8),s),this.process(n,0);let a=f1(e),c=this.outputLen;if(c%4)throw new Error("_sha2: outputLen should be aligned to 32bit");let l=c/4,u=this.get();if(l>u.length)throw new Error("_sha2: outputLen bigger than state");for(let f=0;f<l;f++)a.setUint32(4*f,u[f],s)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneInto(e){e||(e=new this.constructor),e.set(...this.get());let{blockLen:t,buffer:n,length:i,finished:s,destroyed:o,pos:a}=this;return e.length=i,e.pos=a,e.finished=s,e.destroyed=o,i%t&&e.buffer.set(n),e}};var d1=BigInt(4294967295),To=BigInt(32);function s3(r,e=!1){return e?{h:Number(r&d1),l:Number(r>>To&d1)}:{h:Number(r>>To&d1)|0,l:Number(r&d1)|0}}function d6(r,e=!1){let t=new Uint32Array(r.length),n=new Uint32Array(r.length);for(let i=0;i<r.length;i++){let{h:s,l:o}=s3(r[i],e);[t[i],n[i]]=[s,o]}return[t,n]}var p6=(r,e)=>BigInt(r>>>0)<<To|BigInt(e>>>0),g6=(r,e,t)=>r>>>t,m6=(r,e,t)=>r<<32-t|e>>>t,y6=(r,e,t)=>r>>>t|e<<32-t,w6=(r,e,t)=>r<<32-t|e>>>t,b6=(r,e,t)=>r<<64-t|e>>>t-32,x6=(r,e,t)=>r>>>t-32|e<<64-t,v6=(r,e)=>e,E6=(r,e)=>r,A6=(r,e,t)=>r<<t|e>>>32-t,S6=(r,e,t)=>e<<t|r>>>32-t,B6=(r,e,t)=>e<<t-32|r>>>64-t,I6=(r,e,t)=>r<<t-32|e>>>64-t;function k6(r,e,t,n){let i=(e>>>0)+(n>>>0);return{h:r+t+(i/2**32|0)|0,l:i|0}}var T6=(r,e,t)=>(r>>>0)+(e>>>0)+(t>>>0),R6=(r,e,t,n)=>e+t+n+(r/2**32|0)|0,P6=(r,e,t,n)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0),N6=(r,e,t,n,i)=>e+t+n+i+(r/2**32|0)|0,L6=(r,e,t,n,i)=>(r>>>0)+(e>>>0)+(t>>>0)+(n>>>0)+(i>>>0),_6=(r,e,t,n,i,s)=>e+t+n+i+s+(r/2**32|0)|0;var C6={fromBig:s3,split:d6,toBig:p6,shrSH:g6,shrSL:m6,rotrSH:y6,rotrSL:w6,rotrBH:b6,rotrBL:x6,rotr32H:v6,rotr32L:E6,rotlSH:A6,rotlSL:S6,rotlBH:B6,rotlBL:I6,add:k6,add3L:T6,add3H:R6,add4L:P6,add4H:N6,add5H:_6,add5L:L6},U=C6;var[U6,D6]=U.split(["0x428a2f98d728ae22","0x7137449123ef65cd","0xb5c0fbcfec4d3b2f","0xe9b5dba58189dbbc","0x3956c25bf348b538","0x59f111f1b605d019","0x923f82a4af194f9b","0xab1c5ed5da6d8118","0xd807aa98a3030242","0x12835b0145706fbe","0x243185be4ee4b28c","0x550c7dc3d5ffb4e2","0x72be5d74f27b896f","0x80deb1fe3b1696b1","0x9bdc06a725c71235","0xc19bf174cf692694","0xe49b69c19ef14ad2","0xefbe4786384f25e3","0x0fc19dc68b8cd5b5","0x240ca1cc77ac9c65","0x2de92c6f592b0275","0x4a7484aa6ea6e483","0x5cb0a9dcbd41fbd4","0x76f988da831153b5","0x983e5152ee66dfab","0xa831c66d2db43210","0xb00327c898fb213f","0xbf597fc7beef0ee4","0xc6e00bf33da88fc2","0xd5a79147930aa725","0x06ca6351e003826f","0x142929670a0e6e70","0x27b70a8546d22ffc","0x2e1b21385c26c926","0x4d2c6dfc5ac42aed","0x53380d139d95b3df","0x650a73548baf63de","0x766a0abb3c77b2a8","0x81c2c92e47edaee6","0x92722c851482353b","0xa2bfe8a14cf10364","0xa81a664bbc423001","0xc24b8b70d0f89791","0xc76c51a30654be30","0xd192e819d6ef5218","0xd69906245565a910","0xf40e35855771202a","0x106aa07032bbd1b8","0x19a4c116b8d2d0c8","0x1e376c085141ab53","0x2748774cdf8eeb99","0x34b0bcb5e19b48a8","0x391c0cb3c5c95a63","0x4ed8aa4ae3418acb","0x5b9cca4f7763e373","0x682e6ff3d6b2b8a3","0x748f82ee5defb2fc","0x78a5636f43172f60","0x84c87814a1f0ab72","0x8cc702081a6439ec","0x90befffa23631e28","0xa4506cebde82bde9","0xbef9a3f7b2c67915","0xc67178f2e372532b","0xca273eceea26619c","0xd186b8c721c0c207","0xeada7dd6cde0eb1e","0xf57d4f7fee6ed178","0x06f067aa72176fba","0x0a637dc5a2c898a6","0x113f9804bef90dae","0x1b710b35131c471b","0x28db77f523047d84","0x32caab7b40c72493","0x3c9ebe0a15c9bebc","0x431d67c49c100d4c","0x4cc5d4becb3e42b6","0x597f299cfc657e2a","0x5fcb6fab3ad6faec","0x6c44198c4a475817"].map(r=>BigInt(r))),Mt=new Uint32Array(80),Vt=new Uint32Array(80),Ro=class extends Vr{constructor(){super(128,64,16,!1),this.Ah=1779033703,this.Al=-205731576,this.Bh=-1150833019,this.Bl=-2067093701,this.Ch=1013904242,this.Cl=-23791573,this.Dh=-1521486534,this.Dl=1595750129,this.Eh=1359893119,this.El=-1377402159,this.Fh=-1694144372,this.Fl=725511199,this.Gh=528734635,this.Gl=-79577749,this.Hh=1541459225,this.Hl=327033209}get(){let{Ah:e,Al:t,Bh:n,Bl:i,Ch:s,Cl:o,Dh:a,Dl:c,Eh:l,El:u,Fh:f,Fl:h,Gh:p,Gl:y,Hh:w,Hl:d}=this;return[e,t,n,i,s,o,a,c,l,u,f,h,p,y,w,d]}set(e,t,n,i,s,o,a,c,l,u,f,h,p,y,w,d){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=i|0,this.Ch=s|0,this.Cl=o|0,this.Dh=a|0,this.Dl=c|0,this.Eh=l|0,this.El=u|0,this.Fh=f|0,this.Fl=h|0,this.Gh=p|0,this.Gl=y|0,this.Hh=w|0,this.Hl=d|0}process(e,t){for(let g=0;g<16;g++,t+=4)Mt[g]=e.getUint32(t),Vt[g]=e.getUint32(t+=4);for(let g=16;g<80;g++){let A=Mt[g-15]|0,R=Vt[g-15]|0,T=U.rotrSH(A,R,1)^U.rotrSH(A,R,8)^U.shrSH(A,R,7),I=U.rotrSL(A,R,1)^U.rotrSL(A,R,8)^U.shrSL(A,R,7),k=Mt[g-2]|0,L=Vt[g-2]|0,ae=U.rotrSH(k,L,19)^U.rotrBH(k,L,61)^U.shrSH(k,L,6),K=U.rotrSL(k,L,19)^U.rotrBL(k,L,61)^U.shrSL(k,L,6),M=U.add4L(I,K,Vt[g-7],Vt[g-16]),ce=U.add4H(M,T,ae,Mt[g-7],Mt[g-16]);Mt[g]=ce|0,Vt[g]=M|0}let{Ah:n,Al:i,Bh:s,Bl:o,Ch:a,Cl:c,Dh:l,Dl:u,Eh:f,El:h,Fh:p,Fl:y,Gh:w,Gl:d,Hh:x,Hl:E}=this;for(let g=0;g<80;g++){let A=U.rotrSH(f,h,14)^U.rotrSH(f,h,18)^U.rotrBH(f,h,41),R=U.rotrSL(f,h,14)^U.rotrSL(f,h,18)^U.rotrBL(f,h,41),T=f&p^~f&w,I=h&y^~h&d,k=U.add5L(E,R,I,D6[g],Vt[g]),L=U.add5H(k,x,A,T,U6[g],Mt[g]),ae=k|0,K=U.rotrSH(n,i,28)^U.rotrBH(n,i,34)^U.rotrBH(n,i,39),M=U.rotrSL(n,i,28)^U.rotrBL(n,i,34)^U.rotrBL(n,i,39),ce=n&s^n&a^s&a,S=i&o^i&c^o&c;x=w|0,E=d|0,w=p|0,d=y|0,p=f|0,y=h|0,{h:f,l:h}=U.add(l|0,u|0,L|0,ae|0),l=a|0,u=c|0,a=s|0,c=o|0,s=n|0,o=i|0;let P=U.add3L(ae,M,S);n=U.add3H(P,L,K,ce),i=P|0}({h:n,l:i}=U.add(this.Ah|0,this.Al|0,n|0,i|0)),{h:s,l:o}=U.add(this.Bh|0,this.Bl|0,s|0,o|0),{h:a,l:c}=U.add(this.Ch|0,this.Cl|0,a|0,c|0),{h:l,l:u}=U.add(this.Dh|0,this.Dl|0,l|0,u|0),{h:f,l:h}=U.add(this.Eh|0,this.El|0,f|0,h|0),{h:p,l:y}=U.add(this.Fh|0,this.Fl|0,p|0,y|0),{h:w,l:d}=U.add(this.Gh|0,this.Gl|0,w|0,d|0),{h:x,l:E}=U.add(this.Hh|0,this.Hl|0,x|0,E|0),this.set(n,i,s,o,a,c,l,u,f,h,p,y,w,d,x,E)}roundClean(){Mt.fill(0),Vt.fill(0)}destroy(){this.buffer.fill(0),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}};var o3=h1(()=>new Ro);var g1={};ke(g1,{aInRange:()=>Ce,abool:()=>Qe,abytes:()=>Fr,bitGet:()=>q6,bitLen:()=>Co,bitMask:()=>vn,bitSet:()=>K6,bytesToHex:()=>bt,bytesToNumberBE:()=>xt,bytesToNumberLE:()=>Ht,concatBytes:()=>vt,createHmacDrbg:()=>Uo,ensureBytes:()=>ie,equalBytes:()=>F6,hexToBytes:()=>cr,hexToNumber:()=>_o,inRange:()=>xn,isBytes:()=>Ft,memoized:()=>ur,notImplemented:()=>z6,numberToBytesBE:()=>qt,numberToBytesLE:()=>lr,numberToHexUnpadded:()=>ar,numberToVarBytesBE:()=>V6,utf8ToBytes:()=>H6,validateObject:()=>it});var Lo=BigInt(0),p1=BigInt(1),O6=BigInt(2);function Ft(r){return r instanceof Uint8Array||r!=null&&typeof r=="object"&&r.constructor.name==="Uint8Array"}function Fr(r){if(!Ft(r))throw new Error("Uint8Array expected")}function Qe(r,e){if(typeof e!="boolean")throw new Error(`${r} must be valid boolean, got "${e}".`)}var M6=Array.from({length:256},(r,e)=>e.toString(16).padStart(2,"0"));function bt(r){Fr(r);let e="";for(let t=0;t<r.length;t++)e+=M6[r[t]];return e}function ar(r){let e=r.toString(16);return e.length&1?`0${e}`:e}function _o(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);return BigInt(r===""?"0":`0x${r}`)}var wt={_0:48,_9:57,_A:65,_F:70,_a:97,_f:102};function a3(r){if(r>=wt._0&&r<=wt._9)return r-wt._0;if(r>=wt._A&&r<=wt._F)return r-(wt._A-10);if(r>=wt._a&&r<=wt._f)return r-(wt._a-10)}function cr(r){if(typeof r!="string")throw new Error("hex string expected, got "+typeof r);let e=r.length,t=e/2;if(e%2)throw new Error("padded hex string expected, got unpadded hex of length "+e);let n=new Uint8Array(t);for(let i=0,s=0;i<t;i++,s+=2){let o=a3(r.charCodeAt(s)),a=a3(r.charCodeAt(s+1));if(o===void 0||a===void 0){let c=r[s]+r[s+1];throw new Error('hex string expected, got non-hex character "'+c+'" at index '+s)}n[i]=o*16+a}return n}function xt(r){return _o(bt(r))}function Ht(r){return Fr(r),_o(bt(Uint8Array.from(r).reverse()))}function qt(r,e){return cr(r.toString(16).padStart(e*2,"0"))}function lr(r,e){return qt(r,e).reverse()}function V6(r){return cr(ar(r))}function ie(r,e,t){let n;if(typeof e=="string")try{n=cr(e)}catch(s){throw new Error(`${r} must be valid hex string, got "${e}". Cause: ${s}`)}else if(Ft(e))n=Uint8Array.from(e);else throw new Error(`${r} must be hex string or Uint8Array`);let i=n.length;if(typeof t=="number"&&i!==t)throw new Error(`${r} expected ${t} bytes, got ${i}`);return n}function vt(...r){let e=0;for(let n=0;n<r.length;n++){let i=r[n];Fr(i),e+=i.length}let t=new Uint8Array(e);for(let n=0,i=0;n<r.length;n++){let s=r[n];t.set(s,i),i+=s.length}return t}function F6(r,e){if(r.length!==e.length)return!1;let t=0;for(let n=0;n<r.length;n++)t|=r[n]^e[n];return t===0}function H6(r){if(typeof r!="string")throw new Error(`utf8ToBytes expected string, got ${typeof r}`);return new Uint8Array(new TextEncoder().encode(r))}var Po=r=>typeof r=="bigint"&&Lo<=r;function xn(r,e,t){return Po(r)&&Po(e)&&Po(t)&&e<=r&&r<t}function Ce(r,e,t,n){if(!xn(e,t,n))throw new Error(`expected valid ${r}: ${t} <= n < ${n}, got ${typeof e} ${e}`)}function Co(r){let e;for(e=0;r>Lo;r>>=p1,e+=1);return e}function q6(r,e){return r>>BigInt(e)&p1}function K6(r,e,t){return r|(t?p1:Lo)<<BigInt(e)}var vn=r=>(O6<<BigInt(r-1))-p1,No=r=>new Uint8Array(r),c3=r=>Uint8Array.from(r);function Uo(r,e,t){if(typeof r!="number"||r<2)throw new Error("hashLen must be a number");if(typeof e!="number"||e<2)throw new Error("qByteLen must be a number");if(typeof t!="function")throw new Error("hmacFn must be a function");let n=No(r),i=No(r),s=0,o=()=>{n.fill(1),i.fill(0),s=0},a=(...f)=>t(i,n,...f),c=(f=No())=>{i=a(c3([0]),f),n=a(),f.length!==0&&(i=a(c3([1]),f),n=a())},l=()=>{if(s++>=1e3)throw new Error("drbg: tried 1000 values");let f=0,h=[];for(;f<e;){n=a();let p=n.slice();h.push(p),f+=n.length}return vt(...h)};return(f,h)=>{o(),c(f);let p;for(;!(p=h(l()));)c();return o(),p}}var $6={bigint:r=>typeof r=="bigint",function:r=>typeof r=="function",boolean:r=>typeof r=="boolean",string:r=>typeof r=="string",stringOrUint8Array:r=>typeof r=="string"||Ft(r),isSafeInteger:r=>Number.isSafeInteger(r),array:r=>Array.isArray(r),field:(r,e)=>e.Fp.isValid(r),hash:r=>typeof r=="function"&&Number.isSafeInteger(r.outputLen)};function it(r,e,t={}){let n=(i,s,o)=>{let a=$6[s];if(typeof a!="function")throw new Error(`Invalid validator "${s}", expected function`);let c=r[i];if(!(o&&c===void 0)&&!a(c,r))throw new Error(`Invalid param ${String(i)}=${c} (${typeof c}), expected ${s}`)};for(let[i,s]of Object.entries(e))n(i,s,!1);for(let[i,s]of Object.entries(t))n(i,s,!0);return r}var z6=()=>{throw new Error("not implemented")};function ur(r){let e=new WeakMap;return(t,...n)=>{let i=e.get(t);if(i!==void 0)return i;let s=r(t,...n);return e.set(t,s),s}}var fe=BigInt(0),J=BigInt(1),fr=BigInt(2),G6=BigInt(3),Do=BigInt(4),l3=BigInt(5),u3=BigInt(8),j6=BigInt(9),W6=BigInt(16);function W(r,e){let t=r%e;return t>=fe?t:e+t}function Q6(r,e,t){if(t<=fe||e<fe)throw new Error("Expected power/modulo > 0");if(t===J)return fe;let n=J;for(;e>fe;)e&J&&(n=n*r%t),r=r*r%t,e>>=J;return n}function ee(r,e,t){let n=r;for(;e-- >fe;)n*=n,n%=t;return n}function m1(r,e){if(r===fe||e<=fe)throw new Error(`invert: expected positive integers, got n=${r} mod=${e}`);let t=W(r,e),n=e,i=fe,s=J,o=J,a=fe;for(;t!==fe;){let l=n/t,u=n%t,f=i-o*l,h=s-a*l;n=t,t=u,i=o,s=a,o=f,a=h}if(n!==J)throw new Error("invert: does not exist");return W(i,e)}function Z6(r){let e=(r-J)/fr,t,n,i;for(t=r-J,n=0;t%fr===fe;t/=fr,n++);for(i=fr;i<r&&Q6(i,e,r)!==r-J;i++);if(n===1){let o=(r+J)/Do;return function(c,l){let u=c.pow(l,o);if(!c.eql(c.sqr(u),l))throw new Error("Cannot find square root");return u}}let s=(t+J)/fr;return function(a,c){if(a.pow(c,e)===a.neg(a.ONE))throw new Error("Cannot find square root");let l=n,u=a.pow(a.mul(a.ONE,i),t),f=a.pow(c,s),h=a.pow(c,t);for(;!a.eql(h,a.ONE);){if(a.eql(h,a.ZERO))return a.ZERO;let p=1;for(let w=a.sqr(h);p<l&&!a.eql(w,a.ONE);p++)w=a.sqr(w);let y=a.pow(u,J<<BigInt(l-p-1));u=a.sqr(y),f=a.mul(f,y),h=a.mul(h,u),l=p}return f}}function Y6(r){if(r%Do===G6){let e=(r+J)/Do;return function(n,i){let s=n.pow(i,e);if(!n.eql(n.sqr(s),i))throw new Error("Cannot find square root");return s}}if(r%u3===l3){let e=(r-l3)/u3;return function(n,i){let s=n.mul(i,fr),o=n.pow(s,e),a=n.mul(i,o),c=n.mul(n.mul(a,fr),o),l=n.mul(a,n.sub(c,n.ONE));if(!n.eql(n.sqr(l),i))throw new Error("Cannot find square root");return l}}return r%W6,Z6(r)}var f3=(r,e)=>(W(r,e)&J)===J,X6=["create","isValid","is0","neg","inv","sqrt","sqr","eql","add","sub","mul","pow","div","addN","subN","mulN","sqrN"];function Oo(r){let e={ORDER:"bigint",MASK:"bigint",BYTES:"isSafeInteger",BITS:"isSafeInteger"},t=X6.reduce((n,i)=>(n[i]="function",n),e);return it(r,t)}function J6(r,e,t){if(t<fe)throw new Error("Expected power > 0");if(t===fe)return r.ONE;if(t===J)return e;let n=r.ONE,i=e;for(;t>fe;)t&J&&(n=r.mul(n,i)),i=r.sqr(i),t>>=J;return n}function e8(r,e){let t=new Array(e.length),n=e.reduce((s,o,a)=>r.is0(o)?s:(t[a]=s,r.mul(s,o)),r.ONE),i=r.inv(n);return e.reduceRight((s,o,a)=>r.is0(o)?s:(t[a]=r.mul(s,t[a]),r.mul(s,o)),i),t}function Mo(r,e){let t=e!==void 0?e:r.toString(2).length,n=Math.ceil(t/8);return{nBitLength:t,nByteLength:n}}function Kt(r,e,t=!1,n={}){if(r<=fe)throw new Error(`Expected Field ORDER > 0, got ${r}`);let{nBitLength:i,nByteLength:s}=Mo(r,e);if(s>2048)throw new Error("Field lengths over 2048 bytes are not supported");let o=Y6(r),a=Object.freeze({ORDER:r,BITS:i,BYTES:s,MASK:vn(i),ZERO:fe,ONE:J,create:c=>W(c,r),isValid:c=>{if(typeof c!="bigint")throw new Error(`Invalid field element: expected bigint, got ${typeof c}`);return fe<=c&&c<r},is0:c=>c===fe,isOdd:c=>(c&J)===J,neg:c=>W(-c,r),eql:(c,l)=>c===l,sqr:c=>W(c*c,r),add:(c,l)=>W(c+l,r),sub:(c,l)=>W(c-l,r),mul:(c,l)=>W(c*l,r),pow:(c,l)=>J6(a,c,l),div:(c,l)=>W(c*m1(l,r),r),sqrN:c=>c*c,addN:(c,l)=>c+l,subN:(c,l)=>c-l,mulN:(c,l)=>c*l,inv:c=>m1(c,r),sqrt:n.sqrt||(c=>o(a,c)),invertBatch:c=>e8(a,c),cmov:(c,l,u)=>u?l:c,toBytes:c=>t?lr(c,s):qt(c,s),fromBytes:c=>{if(c.length!==s)throw new Error(`Fp.fromBytes: expected ${s}, got ${c.length}`);return t?Ht(c):xt(c)}});return Object.freeze(a)}function h3(r){if(typeof r!="bigint")throw new Error("field order must be bigint");let e=r.toString(2).length;return Math.ceil(e/8)}function Vo(r){let e=h3(r);return e+Math.ceil(e/2)}function d3(r,e,t=!1){let n=r.length,i=h3(e),s=Vo(e);if(n<16||n<s||n>1024)throw new Error(`expected ${s}-1024 bytes of input, got ${n}`);let o=t?xt(r):Ht(r),a=W(o,e-J)+J;return t?lr(a,i):qt(a,i)}var r8=BigInt(0),Fo=BigInt(1),Ho=new WeakMap,p3=new WeakMap;function y1(r,e){let t=(s,o)=>{let a=o.negate();return s?a:o},n=s=>{if(!Number.isSafeInteger(s)||s<=0||s>e)throw new Error(`Wrong window size=${s}, should be [1..${e}]`)},i=s=>{n(s);let o=Math.ceil(e/s)+1,a=2**(s-1);return{windows:o,windowSize:a}};return{constTimeNegate:t,unsafeLadder(s,o){let a=r.ZERO,c=s;for(;o>r8;)o&Fo&&(a=a.add(c)),c=c.double(),o>>=Fo;return a},precomputeWindow(s,o){let{windows:a,windowSize:c}=i(o),l=[],u=s,f=u;for(let h=0;h<a;h++){f=u,l.push(f);for(let p=1;p<c;p++)f=f.add(u),l.push(f);u=f.double()}return l},wNAF(s,o,a){let{windows:c,windowSize:l}=i(s),u=r.ZERO,f=r.BASE,h=BigInt(2**s-1),p=2**s,y=BigInt(s);for(let w=0;w<c;w++){let d=w*l,x=Number(a&h);a>>=y,x>l&&(x-=p,a+=Fo);let E=d,g=d+Math.abs(x)-1,A=w%2!==0,R=x<0;x===0?f=f.add(t(A,o[E])):u=u.add(t(R,o[g]))}return{p:u,f}},wNAFCached(s,o,a){let c=p3.get(s)||1,l=Ho.get(s);return l||(l=this.precomputeWindow(s,c),c!==1&&Ho.set(s,a(l))),this.wNAF(c,l,o)},setWindowSize(s,o){n(o),p3.set(s,o),Ho.delete(s)}}}function w1(r,e,t,n){if(!Array.isArray(t)||!Array.isArray(n)||n.length!==t.length)throw new Error("arrays of points and scalars must have equal length");n.forEach((u,f)=>{if(!e.isValid(u))throw new Error(`wrong scalar at index ${f}`)}),t.forEach((u,f)=>{if(!(u instanceof r))throw new Error(`wrong point at index ${f}`)});let i=Co(BigInt(t.length)),s=i>12?i-3:i>4?i-2:i?2:1,o=(1<<s)-1,a=new Array(o+1).fill(r.ZERO),c=Math.floor((e.BITS-1)/s)*s,l=r.ZERO;for(let u=c;u>=0;u-=s){a.fill(r.ZERO);for(let h=0;h<n.length;h++){let p=n[h],y=Number(p>>BigInt(u)&BigInt(o));a[y]=a[y].add(t[h])}let f=r.ZERO;for(let h=a.length-1,p=r.ZERO;h>0;h--)p=p.add(a[h]),f=f.add(p);if(l=l.add(f),u!==0)for(let h=0;h<s;h++)l=l.double()}return l}function En(r){return Oo(r.Fp),it(r,{n:"bigint",h:"bigint",Gx:"field",Gy:"field"},{nBitLength:"isSafeInteger",nByteLength:"isSafeInteger"}),Object.freeze({...Mo(r.n,r.nBitLength),...r,p:r.Fp.ORDER})}var Ze=BigInt(0),Ue=BigInt(1),b1=BigInt(2),n8=BigInt(8),i8={zip215:!0};function s8(r){let e=En(r);return it(r,{hash:"function",a:"bigint",d:"bigint",randomBytes:"function"},{adjustScalarBytes:"function",domain:"function",uvRatio:"function",mapToCurve:"function"}),Object.freeze({...e})}function g3(r){let e=s8(r),{Fp:t,n,prehash:i,hash:s,randomBytes:o,nByteLength:a,h:c}=e,l=b1<<BigInt(a*8)-Ue,u=t.create,f=Kt(e.n,e.nBitLength),h=e.uvRatio||((b,m)=>{try{return{isValid:!0,value:t.sqrt(b*t.inv(m))}}catch{return{isValid:!1,value:Ze}}}),p=e.adjustScalarBytes||(b=>b),y=e.domain||((b,m,v)=>{if(Qe("phflag",v),m.length||v)throw new Error("Contexts/pre-hash are not supported");return b});function w(b,m){Ce("coordinate "+b,m,Ze,l)}function d(b){if(!(b instanceof g))throw new Error("ExtendedPoint expected")}let x=ur((b,m)=>{let{ex:v,ey:N,ez:_}=b,C=b.is0();m==null&&(m=C?n8:t.inv(_));let V=u(v*m),q=u(N*m),F=u(_*m);if(C)return{x:Ze,y:Ue};if(F!==Ue)throw new Error("invZ was invalid");return{x:V,y:q}}),E=ur(b=>{let{a:m,d:v}=e;if(b.is0())throw new Error("bad point: ZERO");let{ex:N,ey:_,ez:C,et:V}=b,q=u(N*N),F=u(_*_),j=u(C*C),Z=u(j*j),de=u(q*m),pe=u(j*u(de+F)),we=u(Z+u(v*u(q*F)));if(pe!==we)throw new Error("bad point: equation left != right (1)");let Ie=u(N*_),le=u(C*V);if(Ie!==le)throw new Error("bad point: equation left != right (2)");return!0});class g{constructor(m,v,N,_){this.ex=m,this.ey=v,this.ez=N,this.et=_,w("x",m),w("y",v),w("z",N),w("t",_),Object.freeze(this)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}static fromAffine(m){if(m instanceof g)throw new Error("extended point not allowed");let{x:v,y:N}=m||{};return w("x",v),w("y",N),new g(v,N,Ue,u(v*N))}static normalizeZ(m){let v=t.invertBatch(m.map(N=>N.ez));return m.map((N,_)=>N.toAffine(v[_])).map(g.fromAffine)}static msm(m,v){return w1(g,f,m,v)}_setWindowSize(m){T.setWindowSize(this,m)}assertValidity(){E(this)}equals(m){d(m);let{ex:v,ey:N,ez:_}=this,{ex:C,ey:V,ez:q}=m,F=u(v*q),j=u(C*_),Z=u(N*q),de=u(V*_);return F===j&&Z===de}is0(){return this.equals(g.ZERO)}negate(){return new g(u(-this.ex),this.ey,this.ez,u(-this.et))}double(){let{a:m}=e,{ex:v,ey:N,ez:_}=this,C=u(v*v),V=u(N*N),q=u(b1*u(_*_)),F=u(m*C),j=v+N,Z=u(u(j*j)-C-V),de=F+V,pe=de-q,we=F-V,Ie=u(Z*pe),le=u(de*we),Pe=u(Z*we),ut=u(pe*de);return new g(Ie,le,ut,Pe)}add(m){d(m);let{a:v,d:N}=e,{ex:_,ey:C,ez:V,et:q}=this,{ex:F,ey:j,ez:Z,et:de}=m;if(v===BigInt(-1)){let _2=u((C-_)*(j+F)),C2=u((C+_)*(j-F)),ys=u(C2-_2);if(ys===Ze)return this.double();let U2=u(V*b1*de),D2=u(q*b1*Z),O2=D2+U2,M2=C2+_2,V2=D2-U2,v4=u(O2*ys),E4=u(M2*V2),A4=u(O2*V2),S4=u(ys*M2);return new g(v4,E4,S4,A4)}let pe=u(_*F),we=u(C*j),Ie=u(q*N*de),le=u(V*Z),Pe=u((_+C)*(F+j)-pe-we),ut=le-Ie,tn=le+Ie,rn=u(we-v*pe),y4=u(Pe*ut),w4=u(tn*rn),b4=u(Pe*rn),x4=u(ut*tn);return new g(y4,w4,x4,b4)}subtract(m){return this.add(m.negate())}wNAF(m){return T.wNAFCached(this,m,g.normalizeZ)}multiply(m){let v=m;Ce("scalar",v,Ue,n);let{p:N,f:_}=this.wNAF(v);return g.normalizeZ([N,_])[0]}multiplyUnsafe(m){let v=m;return Ce("scalar",v,Ze,n),v===Ze?R:this.equals(R)||v===Ue?this:this.equals(A)?this.wNAF(v).p:T.unsafeLadder(this,v)}isSmallOrder(){return this.multiplyUnsafe(c).is0()}isTorsionFree(){return T.unsafeLadder(this,n).is0()}toAffine(m){return x(this,m)}clearCofactor(){let{h:m}=e;return m===Ue?this:this.multiplyUnsafe(m)}static fromHex(m,v=!1){let{d:N,a:_}=e,C=t.BYTES;m=ie("pointHex",m,C),Qe("zip215",v);let V=m.slice(),q=m[C-1];V[C-1]=q&-129;let F=Ht(V),j=v?l:t.ORDER;Ce("pointHex.y",F,Ze,j);let Z=u(F*F),de=u(Z-Ue),pe=u(N*Z-_),{isValid:we,value:Ie}=h(de,pe);if(!we)throw new Error("Point.fromHex: invalid y coordinate");let le=(Ie&Ue)===Ue,Pe=(q&128)!==0;if(!v&&Ie===Ze&&Pe)throw new Error("Point.fromHex: x=0 and x_0=1");return Pe!==le&&(Ie=u(-Ie)),g.fromAffine({x:Ie,y:F})}static fromPrivateKey(m){return L(m).point}toRawBytes(){let{x:m,y:v}=this.toAffine(),N=lr(v,t.BYTES);return N[N.length-1]|=m&Ue?128:0,N}toHex(){return bt(this.toRawBytes())}}g.BASE=new g(e.Gx,e.Gy,Ue,u(e.Gx*e.Gy)),g.ZERO=new g(Ze,Ue,Ue,Ze);let{BASE:A,ZERO:R}=g,T=y1(g,a*8);function I(b){return W(b,n)}function k(b){return I(Ht(b))}function L(b){let m=a;b=ie("private key",b,m);let v=ie("hashed private key",s(b),2*m),N=p(v.slice(0,m)),_=v.slice(m,2*m),C=k(N),V=A.multiply(C),q=V.toRawBytes();return{head:N,prefix:_,scalar:C,point:V,pointBytes:q}}function ae(b){return L(b).pointBytes}function K(b=new Uint8Array,...m){let v=vt(...m);return k(s(y(v,ie("context",b),!!i)))}function M(b,m,v={}){b=ie("message",b),i&&(b=i(b));let{prefix:N,scalar:_,pointBytes:C}=L(m),V=K(v.context,N,b),q=A.multiply(V).toRawBytes(),F=K(v.context,q,C,b),j=I(V+F*_);Ce("signature.s",j,Ze,n);let Z=vt(q,lr(j,t.BYTES));return ie("result",Z,a*2)}let ce=i8;function S(b,m,v,N=ce){let{context:_,zip215:C}=N,V=t.BYTES;b=ie("signature",b,2*V),m=ie("message",m),C!==void 0&&Qe("zip215",C),i&&(m=i(m));let q=Ht(b.slice(V,2*V)),F,j,Z;try{F=g.fromHex(v,C),j=g.fromHex(b.slice(0,V),C),Z=A.multiplyUnsafe(q)}catch{return!1}if(!C&&F.isSmallOrder())return!1;let de=K(_,j.toRawBytes(),F.toRawBytes(),m);return j.add(F.multiplyUnsafe(de)).subtract(Z).clearCofactor().equals(g.ZERO)}return A._setWindowSize(8),{CURVE:e,getPublicKey:ae,sign:M,verify:S,ExtendedPoint:g,utils:{getExtendedPublicKey:L,randomPrivateKey:()=>o(t.BYTES),precompute(b=8,m=g.BASE){return m._setWindowSize(b),m.multiply(BigInt(3)),m}}}}var qo=BigInt("57896044618658097711785492504343953926634992332820282019728792003956564819949"),m3=BigInt("19681161376707505956807079304988542015446066515923890162744021073123829784752"),Hu=BigInt(0),o8=BigInt(1),y3=BigInt(2),qu=BigInt(3),a8=BigInt(5),c8=BigInt(8);function l8(r){let e=BigInt(10),t=BigInt(20),n=BigInt(40),i=BigInt(80),s=qo,a=r*r%s*r%s,c=ee(a,y3,s)*a%s,l=ee(c,o8,s)*r%s,u=ee(l,a8,s)*l%s,f=ee(u,e,s)*u%s,h=ee(f,t,s)*f%s,p=ee(h,n,s)*h%s,y=ee(p,i,s)*p%s,w=ee(y,i,s)*p%s,d=ee(w,e,s)*u%s;return{pow_p_5_8:ee(d,y3,s)*r%s,b2:a}}function u8(r){return r[0]&=248,r[31]&=127,r[31]|=64,r}function f8(r,e){let t=qo,n=W(e*e*e,t),i=W(n*n*e,t),s=l8(r*i).pow_p_5_8,o=W(r*n*s,t),a=W(e*o*o,t),c=o,l=W(o*m3,t),u=a===r,f=a===W(-r,t),h=a===W(-r*m3,t);return u&&(o=c),(f||h)&&(o=l),f3(o,t)&&(o=W(-o,t)),{isValid:u||f,value:o}}var h8=Kt(qo,void 0,!0),d8={a:BigInt(-1),d:BigInt("37095705934669439343138083508754565189542113879843219016388785533085940283555"),Fp:h8,n:BigInt("7237005577332262213973186563042994240857116359379907606001950938285454250989"),h:c8,Gx:BigInt("15112221349535400772501151409588531511454012693041857206046113283949847762202"),Gy:BigInt("46316835694926478169428394003475163141307993866256225615783033603165251855960"),hash:o3,randomBytes:Mr,adjustScalarBytes:u8,uvRatio:f8},w3=g3(d8);var x1=32;function b3(r,e,t){return w3.verify(e,t instanceof Uint8Array?t:t.subarray(),r)}var v1=class{type="Ed25519";raw;constructor(e){this.raw=Ko(e,x1)}toMultihash(){return gt.digest(Hr(this))}toCID(){return re.createV1(114,this.toMultihash())}toString(){return Y.encode(this.toMultihash().bytes).substring(1)}equals(e){return e==null||!(e.raw instanceof Uint8Array)?!1:X(this.raw,e.raw)}verify(e,t){return b3(this.raw,t,e)}};function $o(r){return r=Ko(r,x1),new v1(r)}function Ko(r,e){if(r=Uint8Array.from(r??[]),r.length!==e)throw new $(`Key must be a Uint8Array of length ${e}, got ${r.length}`);return r}var he;(function(r){r.RSA="RSA",r.Ed25519="Ed25519",r.secp256k1="secp256k1"})(he||(he={}));var zo;(function(r){r[r.RSA=0]="RSA",r[r.Ed25519=1]="Ed25519",r[r.secp256k1=2]="secp256k1"})(zo||(zo={}));(function(r){r.codec=()=>Tr(zo)})(he||(he={}));var st;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.Type=he.codec().decode(t);break}case 2:{s.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(st||(st={}));var Go;(function(r){let e;r.codec=()=>(e==null&&(e=nt((t,n,i={})=>{i.lengthDelimited!==!1&&n.fork(),t.Type!=null&&(n.uint32(8),he.codec().encode(t.Type,n)),t.Data!=null&&(n.uint32(18),n.bytes(t.Data)),i.lengthDelimited!==!1&&n.ldelim()},(t,n,i={})=>{let s={},o=n==null?t.len:t.pos+n;for(;t.pos<o;){let a=t.uint32();switch(a>>>3){case 1:{s.Type=he.codec().decode(t);break}case 2:{s.Data=t.bytes();break}default:{t.skipType(a&7);break}}}return s})),e),r.encode=t=>rt(t,r.codec()),r.decode=(t,n)=>tt(t,r.codec(),n)})(Go||(Go={}));var Ln={};ke(Ln,{MAX_RSA_KEY_SIZE:()=>di,generateRSAKeyPair:()=>ya,jwkToJWKKeyPair:()=>wa,jwkToPkcs1:()=>P8,jwkToPkix:()=>t2,jwkToRSAPrivateKey:()=>ma,pkcs1ToJwk:()=>da,pkcs1ToRSAPrivateKey:()=>ga,pkixToJwk:()=>pa,pkixToRSAPublicKey:()=>r2});var g8=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),$t=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),zt=new Uint32Array(64),jo=class extends Vr{constructor(){super(64,32,8,!1),this.A=$t[0]|0,this.B=$t[1]|0,this.C=$t[2]|0,this.D=$t[3]|0,this.E=$t[4]|0,this.F=$t[5]|0,this.G=$t[6]|0,this.H=$t[7]|0}get(){let{A:e,B:t,C:n,D:i,E:s,F:o,G:a,H:c}=this;return[e,t,n,i,s,o,a,c]}set(e,t,n,i,s,o,a,c){this.A=e|0,this.B=t|0,this.C=n|0,this.D=i|0,this.E=s|0,this.F=o|0,this.G=a|0,this.H=c|0}process(e,t){for(let f=0;f<16;f++,t+=4)zt[f]=e.getUint32(t,!1);for(let f=16;f<64;f++){let h=zt[f-15],p=zt[f-2],y=We(h,7)^We(h,18)^h>>>3,w=We(p,17)^We(p,19)^p>>>10;zt[f]=w+zt[f-7]+y+zt[f-16]|0}let{A:n,B:i,C:s,D:o,E:a,F:c,G:l,H:u}=this;for(let f=0;f<64;f++){let h=We(a,6)^We(a,11)^We(a,25),p=u+h+n3(a,c,l)+g8[f]+zt[f]|0,w=(We(n,2)^We(n,13)^We(n,22))+i3(n,i,s)|0;u=l,l=c,c=a,a=o+p|0,o=s,s=i,i=n,n=p+w|0}n=n+this.A|0,i=i+this.B|0,s=s+this.C|0,o=o+this.D|0,a=a+this.E|0,c=c+this.F|0,l=l+this.G|0,u=u+this.H|0,this.set(n,i,s,o,a,c,l,u)}roundClean(){zt.fill(0)}destroy(){this.set(0,0,0,0,0,0,0,0),this.buffer.fill(0)}};var qr=h1(()=>new jo);var H=bs(E3());function hr(r,e){let t=0;if(r.length===1)return r[0];for(let n=r.length-1;n>=0;n--)t+=r[r.length-1-n]*Math.pow(2,e*n);return t}function Gt(r,e,t=-1){let n=t,i=r,s=0,o=Math.pow(2,e);for(let a=1;a<8;a++){if(r<o){let c;if(n<0)c=new ArrayBuffer(a),s=a;else{if(n<a)return new ArrayBuffer(0);c=new ArrayBuffer(n),s=n}let l=new Uint8Array(c);for(let u=a-1;u>=0;u--){let f=Math.pow(2,u*e);l[s-u-1]=Math.floor(i/f),i-=l[s-u-1]*f}return c}o*=Math.pow(2,e)}return new ArrayBuffer(0)}function S1(...r){let e=0,t=0;for(let s of r)e+=s.length;let n=new ArrayBuffer(e),i=new Uint8Array(n);for(let s of r)i.set(s,t),t+=s.length;return i}function Qo(){let r=new Uint8Array(this.valueHex);if(this.valueHex.byteLength>=2){let a=r[0]===255&&r[1]&128,c=r[0]===0&&(r[1]&128)===0;(a||c)&&this.warnings.push("Needlessly long format")}let e=new ArrayBuffer(this.valueHex.byteLength),t=new Uint8Array(e);for(let a=0;a<this.valueHex.byteLength;a++)t[a]=0;t[0]=r[0]&128;let n=hr(t,8),i=new ArrayBuffer(this.valueHex.byteLength),s=new Uint8Array(i);for(let a=0;a<this.valueHex.byteLength;a++)s[a]=r[a];return s[0]&=127,hr(s,8)-n}function A3(r){let e=r<0?r*-1:r,t=128;for(let n=1;n<8;n++){if(e<=t){if(r<0){let o=t-e,a=Gt(o,8,n),c=new Uint8Array(a);return c[0]|=128,a}let i=Gt(e,8,n),s=new Uint8Array(i);if(s[0]&128){let o=i.slice(0),a=new Uint8Array(o);i=new ArrayBuffer(i.byteLength+1),s=new Uint8Array(i);for(let c=0;c<o.byteLength;c++)s[c+1]=a[c];s[0]=0}return i}t*=Math.pow(2,8)}return new ArrayBuffer(0)}function S3(r,e){if(r.byteLength!==e.byteLength)return!1;let t=new Uint8Array(r),n=new Uint8Array(e);for(let i=0;i<t.length;i++)if(t[i]!==n[i])return!1;return!0}function De(r,e){let t=r.toString(10);if(e<t.length)return"";let n=e-t.length,i=new Array(n);for(let o=0;o<n;o++)i[o]="0";return i.join("").concat(t)}var hf=Math.log(2);function B1(){if(typeof BigInt>"u")throw new Error("BigInt is not defined. Your environment doesn't implement BigInt.")}function Zo(r){let e=0,t=0;for(let i=0;i<r.length;i++){let s=r[i];e+=s.byteLength}let n=new Uint8Array(e);for(let i=0;i<r.length;i++){let s=r[i];n.set(new Uint8Array(s),t),t+=s.byteLength}return n.buffer}function It(r,e,t,n){return e instanceof Uint8Array?e.byteLength?t<0?(r.error="Wrong parameter: inputOffset less than zero",!1):n<0?(r.error="Wrong parameter: inputLength less than zero",!1):e.byteLength-t-n<0?(r.error="End of input reached before message was fully decoded (inconsistent offset and length values)",!1):!0:(r.error="Wrong parameter: inputBuffer has zero length",!1):(r.error="Wrong parameter: inputBuffer must be 'Uint8Array'",!1)}var Sn=class{constructor(){this.items=[]}write(e){this.items.push(e)}final(){return Zo(this.items)}},An=[new Uint8Array([1])],B3="0123456789";var jr="",Ye=new ArrayBuffer(0),Yo=new Uint8Array(0),Bn="EndOfContent",k3="OCTET STRING",T3="BIT STRING";function kt(r){var e;return e=class extends r{constructor(...n){var i;super(...n);let s=n[0]||{};this.isHexOnly=(i=s.isHexOnly)!==null&&i!==void 0?i:!1,this.valueHexView=s.valueHex?H.BufferSourceConverter.toUint8Array(s.valueHex):Yo}get valueHex(){return this.valueHexView.slice().buffer}set valueHex(n){this.valueHexView=new Uint8Array(n)}fromBER(n,i,s){let o=n instanceof ArrayBuffer?new Uint8Array(n):n;if(!It(this,o,i,s))return-1;let a=i+s;return this.valueHexView=o.subarray(i,a),this.valueHexView.length?(this.blockLength=s,a):(this.warnings.push("Zero buffer length"),i)}toBER(n=!1){return this.isHexOnly?n?new ArrayBuffer(this.valueHexView.byteLength):this.valueHexView.byteLength===this.valueHexView.buffer.byteLength?this.valueHexView.buffer:this.valueHexView.slice().buffer:(this.error="Flag 'isHexOnly' is not set, abort",Ye)}toJSON(){return{...super.toJSON(),isHexOnly:this.isHexOnly,valueHex:H.Convert.ToHex(this.valueHexView)}}},e.NAME="hexBlock",e}var At=class{constructor({blockLength:e=0,error:t=jr,warnings:n=[],valueBeforeDecode:i=Yo}={}){this.blockLength=e,this.error=t,this.warnings=n,this.valueBeforeDecodeView=H.BufferSourceConverter.toUint8Array(i)}static blockName(){return this.NAME}get valueBeforeDecode(){return this.valueBeforeDecodeView.slice().buffer}set valueBeforeDecode(e){this.valueBeforeDecodeView=new Uint8Array(e)}toJSON(){return{blockName:this.constructor.NAME,blockLength:this.blockLength,error:this.error,warnings:this.warnings,valueBeforeDecode:H.Convert.ToHex(this.valueBeforeDecodeView)}}};At.NAME="baseBlock";var Se=class extends At{fromBER(e,t,n){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}toBER(e,t){throw TypeError("User need to make a specific function in a class which extends 'ValueBlock'")}};Se.NAME="valueBlock";var I1=class extends kt(At){constructor({idBlock:e={}}={}){var t,n,i,s;super(),e?(this.isHexOnly=(t=e.isHexOnly)!==null&&t!==void 0?t:!1,this.valueHexView=e.valueHex?H.BufferSourceConverter.toUint8Array(e.valueHex):Yo,this.tagClass=(n=e.tagClass)!==null&&n!==void 0?n:-1,this.tagNumber=(i=e.tagNumber)!==null&&i!==void 0?i:-1,this.isConstructed=(s=e.isConstructed)!==null&&s!==void 0?s:!1):(this.tagClass=-1,this.tagNumber=-1,this.isConstructed=!1)}toBER(e=!1){let t=0;switch(this.tagClass){case 1:t|=0;break;case 2:t|=64;break;case 3:t|=128;break;case 4:t|=192;break;default:return this.error="Unknown tag class",Ye}if(this.isConstructed&&(t|=32),this.tagNumber<31&&!this.isHexOnly){let i=new Uint8Array(1);if(!e){let s=this.tagNumber;s&=31,t|=s,i[0]=t}return i.buffer}if(!this.isHexOnly){let i=Gt(this.tagNumber,7),s=new Uint8Array(i),o=i.byteLength,a=new Uint8Array(o+1);if(a[0]=t|31,!e){for(let c=0;c<o-1;c++)a[c+1]=s[c]|128;a[o]=s[o-1]}return a.buffer}let n=new Uint8Array(this.valueHexView.byteLength+1);if(n[0]=t|31,!e){let i=this.valueHexView;for(let s=0;s<i.length-1;s++)n[s+1]=i[s]|128;n[this.valueHexView.byteLength]=i[i.length-1]}return n.buffer}fromBER(e,t,n){let i=H.BufferSourceConverter.toUint8Array(e);if(!It(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;switch(s[0]&192){case 0:this.tagClass=1;break;case 64:this.tagClass=2;break;case 128:this.tagClass=3;break;case 192:this.tagClass=4;break;default:return this.error="Unknown tag class",-1}this.isConstructed=(s[0]&32)===32,this.isHexOnly=!1;let a=s[0]&31;if(a!==31)this.tagNumber=a,this.blockLength=1;else{let c=1,l=this.valueHexView=new Uint8Array(255),u=255;for(;s[c]&128;){if(l[c-1]=s[c]&127,c++,c>=s.length)return this.error="End of input reached before message was fully decoded",-1;if(c===u){u+=255;let h=new Uint8Array(u);for(let p=0;p<l.length;p++)h[p]=l[p];l=this.valueHexView=new Uint8Array(u)}}this.blockLength=c+1,l[c-1]=s[c]&127;let f=new Uint8Array(c);for(let h=0;h<c;h++)f[h]=l[h];l=this.valueHexView=new Uint8Array(c),l.set(f),this.blockLength<=9?this.tagNumber=hr(l,7):(this.isHexOnly=!0,this.warnings.push("Tag too long, represented as hex-coded"))}if(this.tagClass===1&&this.isConstructed)switch(this.tagNumber){case 1:case 2:case 5:case 6:case 9:case 13:case 14:case 23:case 24:case 31:case 32:case 33:case 34:return this.error="Constructed encoding used for primitive type",-1}return t+this.blockLength}toJSON(){return{...super.toJSON(),tagClass:this.tagClass,tagNumber:this.tagNumber,isConstructed:this.isConstructed}}};I1.NAME="identificationBlock";var k1=class extends At{constructor({lenBlock:e={}}={}){var t,n,i;super(),this.isIndefiniteForm=(t=e.isIndefiniteForm)!==null&&t!==void 0?t:!1,this.longFormUsed=(n=e.longFormUsed)!==null&&n!==void 0?n:!1,this.length=(i=e.length)!==null&&i!==void 0?i:0}fromBER(e,t,n){let i=H.BufferSourceConverter.toUint8Array(e);if(!It(this,i,t,n))return-1;let s=i.subarray(t,t+n);if(s.length===0)return this.error="Zero buffer length",-1;if(s[0]===255)return this.error="Length block 0xFF is reserved by standard",-1;if(this.isIndefiniteForm=s[0]===128,this.isIndefiniteForm)return this.blockLength=1,t+this.blockLength;if(this.longFormUsed=!!(s[0]&128),this.longFormUsed===!1)return this.length=s[0],this.blockLength=1,t+this.blockLength;let o=s[0]&127;if(o>8)return this.error="Too big integer",-1;if(o+1>s.length)return this.error="End of input reached before message was fully decoded",-1;let a=t+1,c=i.subarray(a,a+o);return c[o-1]===0&&this.warnings.push("Needlessly long encoded length"),this.length=hr(c,8),this.longFormUsed&&this.length<=127&&this.warnings.push("Unnecessary usage of long length form"),this.blockLength=o+1,t+this.blockLength}toBER(e=!1){let t,n;if(this.length>127&&(this.longFormUsed=!0),this.isIndefiniteForm)return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=128),t;if(this.longFormUsed){let i=Gt(this.length,8);if(i.byteLength>127)return this.error="Too big length",Ye;if(t=new ArrayBuffer(i.byteLength+1),e)return t;let s=new Uint8Array(i);n=new Uint8Array(t),n[0]=i.byteLength|128;for(let o=0;o<i.byteLength;o++)n[o+1]=s[o];return t}return t=new ArrayBuffer(1),e===!1&&(n=new Uint8Array(t),n[0]=this.length),t}toJSON(){return{...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,longFormUsed:this.longFormUsed,length:this.length}}};k1.NAME="lengthBlock";var B={},be=class extends At{constructor({name:e=jr,optional:t=!1,primitiveSchema:n,...i}={},s){super(i),this.name=e,this.optional=t,n&&(this.primitiveSchema=n),this.idBlock=new I1(i),this.lenBlock=new k1(i),this.valueBlock=s?new s(i):new Se(i)}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}toBER(e,t){let n=t||new Sn;t||R3(this);let i=this.idBlock.toBER(e);if(n.write(i),this.lenBlock.isIndefiniteForm)n.write(new Uint8Array([128]).buffer),this.valueBlock.toBER(e,n),n.write(new ArrayBuffer(2));else{let s=this.valueBlock.toBER(e);this.lenBlock.length=s.byteLength;let o=this.lenBlock.toBER(e);n.write(o),n.write(s)}return t?Ye:n.final()}toJSON(){let e={...super.toJSON(),idBlock:this.idBlock.toJSON(),lenBlock:this.lenBlock.toJSON(),valueBlock:this.valueBlock.toJSON(),name:this.name,optional:this.optional};return this.primitiveSchema&&(e.primitiveSchema=this.primitiveSchema.toJSON()),e}toString(e="ascii"){return e==="ascii"?this.onAsciiEncoding():H.Convert.ToHex(this.toBER())}onAsciiEncoding(){return`${this.constructor.NAME} : ${H.Convert.ToHex(this.valueBlock.valueBeforeDecodeView)}`}isEqual(e){if(this===e)return!0;if(!(e instanceof this.constructor))return!1;let t=this.toBER(),n=e.toBER();return S3(t,n)}};be.NAME="BaseBlock";function R3(r){if(r instanceof B.Constructed)for(let e of r.valueBlock.value)R3(e)&&(r.lenBlock.isIndefiniteForm=!0);return!!r.lenBlock.isIndefiniteForm}var T1=class extends be{constructor({value:e=jr,...t}={},n){super(t,n),e&&this.fromString(e)}getValue(){return this.valueBlock.value}setValue(e){this.valueBlock.value=e}fromBER(e,t,n){let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.fromBuffer(this.valueBlock.valueHexView),this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){return`${this.constructor.NAME} : '${this.valueBlock.value}'`}};T1.NAME="BaseStringBlock";var R1=class extends kt(Se){constructor({isHexOnly:e=!0,...t}={}){super(t),this.isHexOnly=e}};R1.NAME="PrimitiveValueBlock";var P3,P1=class extends be{constructor(e={}){super(e,R1),this.idBlock.isConstructed=!1}};P3=P1;B.Primitive=P3;P1.NAME="PRIMITIVE";function S8(r,e){if(r instanceof e)return r;let t=new e;return t.idBlock=r.idBlock,t.lenBlock=r.lenBlock,t.warnings=r.warnings,t.valueBeforeDecodeView=r.valueBeforeDecodeView,t}function ui(r,e=0,t=r.length){let n=e,i=new be({},Se),s=new At;if(!It(s,r,e,t))return i.error=s.error,{offset:-1,result:i};if(!r.subarray(e,e+t).length)return i.error="Zero buffer length",{offset:-1,result:i};let a=i.idBlock.fromBER(r,e,t);if(i.idBlock.warnings.length&&i.warnings.concat(i.idBlock.warnings),a===-1)return i.error=i.idBlock.error,{offset:-1,result:i};if(e=a,t-=i.idBlock.blockLength,a=i.lenBlock.fromBER(r,e,t),i.lenBlock.warnings.length&&i.warnings.concat(i.lenBlock.warnings),a===-1)return i.error=i.lenBlock.error,{offset:-1,result:i};if(e=a,t-=i.lenBlock.blockLength,!i.idBlock.isConstructed&&i.lenBlock.isIndefiniteForm)return i.error="Indefinite length form used for primitive encoding form",{offset:-1,result:i};let c=be;switch(i.idBlock.tagClass){case 1:if(i.idBlock.tagNumber>=37&&i.idBlock.isHexOnly===!1)return i.error="UNIVERSAL 37 and upper tags are reserved by ASN.1 standard",{offset:-1,result:i};switch(i.idBlock.tagNumber){case 0:if(i.idBlock.isConstructed&&i.lenBlock.length>0)return i.error="Type [UNIVERSAL 0] is reserved",{offset:-1,result:i};c=B.EndOfContent;break;case 1:c=B.Boolean;break;case 2:c=B.Integer;break;case 3:c=B.BitString;break;case 4:c=B.OctetString;break;case 5:c=B.Null;break;case 6:c=B.ObjectIdentifier;break;case 10:c=B.Enumerated;break;case 12:c=B.Utf8String;break;case 13:c=B.RelativeObjectIdentifier;break;case 14:c=B.TIME;break;case 15:return i.error="[UNIVERSAL 15] is reserved by ASN.1 standard",{offset:-1,result:i};case 16:c=B.Sequence;break;case 17:c=B.Set;break;case 18:c=B.NumericString;break;case 19:c=B.PrintableString;break;case 20:c=B.TeletexString;break;case 21:c=B.VideotexString;break;case 22:c=B.IA5String;break;case 23:c=B.UTCTime;break;case 24:c=B.GeneralizedTime;break;case 25:c=B.GraphicString;break;case 26:c=B.VisibleString;break;case 27:c=B.GeneralString;break;case 28:c=B.UniversalString;break;case 29:c=B.CharacterString;break;case 30:c=B.BmpString;break;case 31:c=B.DATE;break;case 32:c=B.TimeOfDay;break;case 33:c=B.DateTime;break;case 34:c=B.Duration;break;default:{let l=i.idBlock.isConstructed?new B.Constructed:new B.Primitive;l.idBlock=i.idBlock,l.lenBlock=i.lenBlock,l.warnings=i.warnings,i=l}}break;case 2:case 3:case 4:default:c=i.idBlock.isConstructed?B.Constructed:B.Primitive}return i=S8(i,c),a=i.fromBER(r,e,i.lenBlock.isIndefiniteForm?t:i.lenBlock.length),i.valueBeforeDecodeView=r.subarray(n,n+i.blockLength),{offset:a,result:i}}function Xo(r){if(!r.byteLength){let e=new be({},Se);return e.error="Input buffer has zero length",{offset:-1,result:e}}return ui(H.BufferSourceConverter.toUint8Array(r).slice(),0,r.byteLength)}function B8(r,e){return r?1:e}var ot=class extends Se{constructor({value:e=[],isIndefiniteForm:t=!1,...n}={}){super(n),this.value=e,this.isIndefiniteForm=t}fromBER(e,t,n){let i=H.BufferSourceConverter.toUint8Array(e);if(!It(this,i,t,n))return-1;if(this.valueBeforeDecodeView=i.subarray(t,t+n),this.valueBeforeDecodeView.length===0)return this.warnings.push("Zero buffer length"),t;let s=t;for(;B8(this.isIndefiniteForm,n)>0;){let o=ui(i,s,n);if(o.offset===-1)return this.error=o.result.error,this.warnings.concat(o.result.warnings),-1;if(s=o.offset,this.blockLength+=o.result.blockLength,n-=o.result.blockLength,this.value.push(o.result),this.isIndefiniteForm&&o.result.constructor.NAME===Bn)break}return this.isIndefiniteForm&&(this.value[this.value.length-1].constructor.NAME===Bn?this.value.pop():this.warnings.push("No EndOfContent block encoded")),s}toBER(e,t){let n=t||new Sn;for(let i=0;i<this.value.length;i++)this.value[i].toBER(e,n);return t?Ye:n.final()}toJSON(){let e={...super.toJSON(),isIndefiniteForm:this.isIndefiniteForm,value:[]};for(let t of this.value)e.value.push(t.toJSON());return e}};ot.NAME="ConstructedValueBlock";var N3,jt=class extends be{constructor(e={}){super(e,ot),this.idBlock.isConstructed=!0}fromBER(e,t,n){this.valueBlock.isIndefiniteForm=this.lenBlock.isIndefiniteForm;let i=this.valueBlock.fromBER(e,t,this.lenBlock.isIndefiniteForm?n:this.lenBlock.length);return i===-1?(this.error=this.valueBlock.error,i):(this.idBlock.error.length||(this.blockLength+=this.idBlock.blockLength),this.lenBlock.error.length||(this.blockLength+=this.lenBlock.blockLength),this.valueBlock.error.length||(this.blockLength+=this.valueBlock.blockLength),i)}onAsciiEncoding(){let e=[];for(let n of this.valueBlock.value)e.push(n.toString("ascii").split(`
3
3
  `).map(i=>` ${i}`).join(`
4
4
  `));let t=this.idBlock.tagClass===3?`[${this.idBlock.tagNumber}]`:this.constructor.NAME;return e.length?`${t} :
5
5
  ${e.join(`
@@ -3,6 +3,9 @@ export declare const minute: number;
3
3
  export declare const hour: number;
4
4
  export declare const MAX_RECORD_AGE: number;
5
5
  export declare const PROTOCOL = "/ipfs/kad/1.0.0";
6
+ /**
7
+ * @see https://github.com/libp2p/specs/blob/master/kad-dht/README.md#content-provider-advertisement-and-discovery
8
+ */
6
9
  export declare const PROVIDERS_VALIDITY: number;
7
10
  export declare const PROVIDERS_CLEANUP_INTERVAL: number;
8
11
  export declare const REPROVIDE_THRESHOLD: number;
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,MAAM,OAAO,CAAA;AAC1B,eAAO,MAAM,MAAM,QAAc,CAAA;AACjC,eAAO,MAAM,IAAI,QAAc,CAAA;AAE/B,eAAO,MAAM,cAAc,QAAY,CAAA;AAEvC,eAAO,MAAM,QAAQ,oBAAoB,CAAA;AAEzC,eAAO,MAAM,kBAAkB,QAAY,CAAA;AAE3C,eAAO,MAAM,0BAA0B,QAAO,CAAA;AAG9C,eAAO,MAAM,mBAAmB,QAAW,CAAA;AAG3C,eAAO,MAAM,qBAAqB,KAAK,CAAA;AAGvC,eAAO,MAAM,wBAAwB,QAAS,CAAA;AAG9C,eAAO,MAAM,kBAAkB,QAAO,CAAA;AAEtC,eAAO,MAAM,oBAAoB,QAAc,CAAA;AAG/C,eAAO,MAAM,qBAAqB,KAAK,CAAA;AAGvC,eAAO,MAAM,CAAC,KAAK,CAAA;AAGnB,eAAO,MAAM,KAAK,IAAI,CAAA;AAGtB,eAAO,MAAM,mBAAmB,QAAa,CAAA;AAG7C,eAAO,MAAM,2BAA2B,OAAS,CAAA;AAGjD,eAAO,MAAM,kBAAkB,QAAa,CAAA;AAG5C,eAAO,MAAM,sBAAsB,QAAa,CAAA;AAGhD,eAAO,MAAM,2BAA2B,QAAc,CAAA;AAGtD,eAAO,MAAM,qBAAqB,QAAe,CAAA;AAGjD,eAAO,MAAM,cAAc,uBAA0B,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,MAAM,OAAO,CAAA;AAC1B,eAAO,MAAM,MAAM,QAAc,CAAA;AACjC,eAAO,MAAM,IAAI,QAAc,CAAA;AAE/B,eAAO,MAAM,cAAc,QAAY,CAAA;AAEvC,eAAO,MAAM,QAAQ,oBAAoB,CAAA;AAEzC;;GAEG;AACH,eAAO,MAAM,kBAAkB,QAAY,CAAA;AAE3C,eAAO,MAAM,0BAA0B,QAAO,CAAA;AAG9C,eAAO,MAAM,mBAAmB,QAAY,CAAA;AAG5C,eAAO,MAAM,qBAAqB,KAAK,CAAA;AAGvC,eAAO,MAAM,wBAAwB,QAAS,CAAA;AAG9C,eAAO,MAAM,kBAAkB,QAAO,CAAA;AAEtC,eAAO,MAAM,oBAAoB,QAAc,CAAA;AAG/C,eAAO,MAAM,qBAAqB,KAAK,CAAA;AAGvC,eAAO,MAAM,CAAC,KAAK,CAAA;AAGnB,eAAO,MAAM,KAAK,IAAI,CAAA;AAGtB,eAAO,MAAM,mBAAmB,QAAa,CAAA;AAG7C,eAAO,MAAM,2BAA2B,OAAS,CAAA;AAGjD,eAAO,MAAM,kBAAkB,QAAa,CAAA;AAG5C,eAAO,MAAM,sBAAsB,QAAa,CAAA;AAGhD,eAAO,MAAM,2BAA2B,QAAc,CAAA;AAGtD,eAAO,MAAM,qBAAqB,QAAe,CAAA;AAGjD,eAAO,MAAM,cAAc,uBAA0B,CAAA"}
@@ -1,19 +1,16 @@
1
- // MaxRecordAge specifies the maximum time that any node will hold onto a record
2
- // from the time its received. This does not apply to any other forms of validity that
3
- // the record may contain.
4
- // For example, a record may contain an ipns entry with an EOL saying its valid
5
- // until the year 2020 (a great time in the future). For that record to stick around
6
- // it must be rebroadcasted more frequently than once every 'MaxRecordAge'
7
1
  import { KEEP_ALIVE } from '@libp2p/interface';
8
2
  export const second = 1000;
9
3
  export const minute = 60 * second;
10
4
  export const hour = 60 * minute;
11
5
  export const MAX_RECORD_AGE = 36 * hour;
12
6
  export const PROTOCOL = '/ipfs/kad/1.0.0';
13
- export const PROVIDERS_VALIDITY = 24 * hour;
7
+ /**
8
+ * @see https://github.com/libp2p/specs/blob/master/kad-dht/README.md#content-provider-advertisement-and-discovery
9
+ */
10
+ export const PROVIDERS_VALIDITY = 48 * hour;
14
11
  export const PROVIDERS_CLEANUP_INTERVAL = hour;
15
12
  // Re-run the provide operation when the expiry of our provider records is within this amount
16
- export const REPROVIDE_THRESHOLD = 2 * hour;
13
+ export const REPROVIDE_THRESHOLD = 24 * hour;
17
14
  // How many reprovide operations to run at once
18
15
  export const REPROVIDE_CONCURRENCY = 10;
19
16
  // How long to let the reprovide queue grow before we wait for capacity
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,sFAAsF;AACtF,0BAA0B;AAC1B,+EAA+E;AAC/E,oFAAoF;AACpF,0EAA0E;AAE1E,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAA;AAC1B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAA;AACjC,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,CAAA;AAE/B,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,CAAA;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAiB,CAAA;AAEzC,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAA;AAE3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAA;AAE9C,6FAA6F;AAC7F,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,IAAI,CAAA;AAE3C,+CAA+C;AAC/C,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEvC,uEAAuE;AACvE,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAA;AAE9C,iDAAiD;AACjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAEtC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,MAAM,CAAA;AAE/C,sEAAsE;AACtE,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEvC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;AAEnB,qDAAqD;AACrD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAA;AAEtB,mDAAmD;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,MAAM,CAAA;AAE7C,oEAAoE;AACpE,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAA;AAEjD,sDAAsD;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,MAAM,CAAA;AAE5C,qCAAqC;AACrC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,MAAM,CAAA;AAEhD,yCAAyC;AACzC,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,MAAM,CAAA;AAEtD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,GAAG,MAAM,CAAA;AAEjD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,UAAU,UAAU,CAAA"}
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE9C,MAAM,CAAC,MAAM,MAAM,GAAG,IAAI,CAAA;AAC1B,MAAM,CAAC,MAAM,MAAM,GAAG,EAAE,GAAG,MAAM,CAAA;AACjC,MAAM,CAAC,MAAM,IAAI,GAAG,EAAE,GAAG,MAAM,CAAA;AAE/B,MAAM,CAAC,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,CAAA;AAEvC,MAAM,CAAC,MAAM,QAAQ,GAAG,iBAAiB,CAAA;AAEzC;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,GAAG,IAAI,CAAA;AAE3C,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,CAAA;AAE9C,6FAA6F;AAC7F,MAAM,CAAC,MAAM,mBAAmB,GAAG,EAAE,GAAG,IAAI,CAAA;AAE5C,+CAA+C;AAC/C,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEvC,uEAAuE;AACvE,MAAM,CAAC,MAAM,wBAAwB,GAAG,MAAM,CAAA;AAE9C,iDAAiD;AACjD,MAAM,CAAC,MAAM,kBAAkB,GAAG,IAAI,CAAA;AAEtC,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,GAAG,MAAM,CAAA;AAE/C,sEAAsE;AACtE,MAAM,CAAC,MAAM,qBAAqB,GAAG,EAAE,CAAA;AAEvC,0EAA0E;AAC1E,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAA;AAEnB,qDAAqD;AACrD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,CAAA;AAEtB,mDAAmD;AACnD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,GAAG,MAAM,CAAA;AAE7C,oEAAoE;AACpE,MAAM,CAAC,MAAM,2BAA2B,GAAG,MAAM,CAAA;AAEjD,sDAAsD;AACtD,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,MAAM,CAAA;AAE5C,qCAAqC;AACrC,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,MAAM,CAAA;AAEhD,yCAAyC;AACzC,MAAM,CAAC,MAAM,2BAA2B,GAAG,EAAE,GAAG,MAAM,CAAA;AAEtD,6DAA6D;AAC7D,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,GAAG,MAAM,CAAA;AAEjD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,UAAU,UAAU,CAAA"}
@@ -307,15 +307,15 @@ export interface ProvidersInit {
307
307
  */
308
308
  cacheSize?: number;
309
309
  /**
310
- * How often invalid records are cleaned. (in seconds)
310
+ * How often invalid records are cleaned in seconds
311
311
  *
312
- * @default 5400
312
+ * @default 5_400
313
313
  */
314
314
  cleanupInterval?: number;
315
315
  /**
316
- * How long is a provider valid for. (in seconds)
316
+ * How long is a provider valid for in seconds
317
317
  *
318
- * @default 86400
318
+ * @default 86_400
319
319
  */
320
320
  provideValidity?: number;
321
321
  }
@@ -329,25 +329,25 @@ export interface ReProvideInit {
329
329
  /**
330
330
  * How long to let the re-provide queue grow
331
331
  *
332
- * @default 16384
332
+ * @default 16_384
333
333
  */
334
334
  maxQueueSize?: number;
335
335
  /**
336
336
  * How long before the record expiry to re-provide in ms
337
337
  *
338
- * @default 7200000
338
+ * @default 86_400_000 (24 hours)
339
339
  */
340
340
  threshold?: number;
341
341
  /**
342
- * How often to check which records need reproviding in ms
342
+ * How often to check which records need re-providing in ms
343
343
  *
344
- * @default 3600000
344
+ * @default 3_600_000 (1 hour)
345
345
  */
346
346
  interval?: number;
347
347
  /**
348
348
  * How long provider records are valid for in ms
349
349
  *
350
- * @default 86400000
350
+ * @default 172_800_000 (48 hours)
351
351
  */
352
352
  validity?: number;
353
353
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@libp2p/kad-dht",
3
- "version": "14.1.0-eee97c7d4",
3
+ "version": "14.1.1-05d559f54",
4
4
  "description": "JavaScript implementation of the Kad-DHT for libp2p",
5
5
  "license": "Apache-2.0 OR MIT",
6
6
  "homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/kad-dht#readme",
@@ -57,13 +57,13 @@
57
57
  "doc-check": "aegir doc-check"
58
58
  },
59
59
  "dependencies": {
60
- "@libp2p/crypto": "5.0.6-eee97c7d4",
61
- "@libp2p/interface": "2.2.0-eee97c7d4",
62
- "@libp2p/interface-internal": "2.0.10-eee97c7d4",
63
- "@libp2p/peer-collections": "6.0.10-eee97c7d4",
64
- "@libp2p/peer-id": "5.0.7-eee97c7d4",
65
- "@libp2p/record": "4.0.4-eee97c7d4",
66
- "@libp2p/utils": "6.1.3-eee97c7d4",
60
+ "@libp2p/crypto": "5.0.6-05d559f54",
61
+ "@libp2p/interface": "2.2.0-05d559f54",
62
+ "@libp2p/interface-internal": "2.1.0-05d559f54",
63
+ "@libp2p/peer-collections": "6.0.11-05d559f54",
64
+ "@libp2p/peer-id": "5.0.7-05d559f54",
65
+ "@libp2p/record": "4.0.4-05d559f54",
66
+ "@libp2p/utils": "6.2.0-05d559f54",
67
67
  "@multiformats/multiaddr": "^12.2.3",
68
68
  "any-signal": "^4.1.1",
69
69
  "interface-datastore": "^8.3.0",
@@ -88,9 +88,9 @@
88
88
  "uint8arrays": "^5.1.0"
89
89
  },
90
90
  "devDependencies": {
91
- "@libp2p/interface-compliance-tests": "6.1.8-eee97c7d4",
92
- "@libp2p/logger": "5.1.3-eee97c7d4",
93
- "@libp2p/peer-store": "11.0.10-eee97c7d4",
91
+ "@libp2p/interface-compliance-tests": "6.1.9-05d559f54",
92
+ "@libp2p/logger": "5.1.3-05d559f54",
93
+ "@libp2p/peer-store": "11.0.11-05d559f54",
94
94
  "@types/lodash.random": "^3.2.9",
95
95
  "@types/lodash.range": "^3.2.9",
96
96
  "@types/sinon": "^17.0.3",
package/src/constants.ts CHANGED
@@ -1,10 +1,3 @@
1
- // MaxRecordAge specifies the maximum time that any node will hold onto a record
2
- // from the time its received. This does not apply to any other forms of validity that
3
- // the record may contain.
4
- // For example, a record may contain an ipns entry with an EOL saying its valid
5
- // until the year 2020 (a great time in the future). For that record to stick around
6
- // it must be rebroadcasted more frequently than once every 'MaxRecordAge'
7
-
8
1
  import { KEEP_ALIVE } from '@libp2p/interface'
9
2
 
10
3
  export const second = 1000
@@ -15,12 +8,15 @@ export const MAX_RECORD_AGE = 36 * hour
15
8
 
16
9
  export const PROTOCOL = '/ipfs/kad/1.0.0'
17
10
 
18
- export const PROVIDERS_VALIDITY = 24 * hour
11
+ /**
12
+ * @see https://github.com/libp2p/specs/blob/master/kad-dht/README.md#content-provider-advertisement-and-discovery
13
+ */
14
+ export const PROVIDERS_VALIDITY = 48 * hour
19
15
 
20
16
  export const PROVIDERS_CLEANUP_INTERVAL = hour
21
17
 
22
18
  // Re-run the provide operation when the expiry of our provider records is within this amount
23
- export const REPROVIDE_THRESHOLD = 2 * hour
19
+ export const REPROVIDE_THRESHOLD = 24 * hour
24
20
 
25
21
  // How many reprovide operations to run at once
26
22
  export const REPROVIDE_CONCURRENCY = 10
package/src/index.ts CHANGED
@@ -346,15 +346,15 @@ export interface ProvidersInit {
346
346
  */
347
347
  cacheSize?: number
348
348
  /**
349
- * How often invalid records are cleaned. (in seconds)
349
+ * How often invalid records are cleaned in seconds
350
350
  *
351
- * @default 5400
351
+ * @default 5_400
352
352
  */
353
353
  cleanupInterval?: number
354
354
  /**
355
- * How long is a provider valid for. (in seconds)
355
+ * How long is a provider valid for in seconds
356
356
  *
357
- * @default 86400
357
+ * @default 86_400
358
358
  */
359
359
  provideValidity?: number
360
360
  }
@@ -370,28 +370,28 @@ export interface ReProvideInit {
370
370
  /**
371
371
  * How long to let the re-provide queue grow
372
372
  *
373
- * @default 16384
373
+ * @default 16_384
374
374
  */
375
375
  maxQueueSize?: number
376
376
 
377
377
  /**
378
378
  * How long before the record expiry to re-provide in ms
379
379
  *
380
- * @default 7200000
380
+ * @default 86_400_000 (24 hours)
381
381
  */
382
382
  threshold?: number
383
383
 
384
384
  /**
385
- * How often to check which records need reproviding in ms
385
+ * How often to check which records need re-providing in ms
386
386
  *
387
- * @default 3600000
387
+ * @default 3_600_000 (1 hour)
388
388
  */
389
389
  interval?: number
390
390
 
391
391
  /**
392
392
  * How long provider records are valid for in ms
393
393
  *
394
- * @default 86400000
394
+ * @default 172_800_000 (48 hours)
395
395
  */
396
396
  validity?: number
397
397
  }