@helia/routers 5.0.3-2d30414a → 5.0.3-5ee3283f
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.min.js +2 -2
- package/dist/index.min.js.map +2 -2
- package/dist/src/delegated-http-routing.d.ts.map +1 -1
- package/dist/src/delegated-http-routing.js +2 -1
- package/dist/src/delegated-http-routing.js.map +1 -1
- package/dist/src/http-gateway-routing.d.ts.map +1 -1
- package/dist/src/http-gateway-routing.js +1 -0
- package/dist/src/http-gateway-routing.js.map +1 -1
- package/dist/src/index.d.ts +5 -5
- package/dist/src/index.js +4 -4
- package/dist/src/libp2p-routing.d.ts.map +1 -1
- package/dist/src/libp2p-routing.js +1 -0
- package/dist/src/libp2p-routing.js.map +1 -1
- package/package.json +2 -2
- package/src/delegated-http-routing.ts +2 -1
- package/src/http-gateway-routing.ts +1 -0
- package/src/index.ts +5 -5
- package/src/libp2p-routing.ts +1 -0
package/dist/index.min.js
CHANGED
|
@@ -10,7 +10,7 @@ ${t}`)}`:n!=null?`${n.split(`
|
|
|
10
10
|
${t}`)}`:r!=null?`${r}`:`${e.toString()}`}function Rp(e){return e instanceof AggregateError||e?.name==="AggregateError"&&Array.isArray(e.errors)}function du(e,t=""){if(Rp(e)){let r=fu(e,t);return e.errors.length>0?(t=`${t} `,r+=`
|
|
11
11
|
${t}${e.errors.map(n=>`${du(n,`${t}`)}`).join(`
|
|
12
12
|
${t}`)}`):r+=`
|
|
13
|
-
${t}[Error list was empty]`,r.trim()}return fu(e,t)}Ct.formatters.e=e=>e==null?"undefined":du(e);function Pp(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function qe(e,t){let r=Pp(`${e}:trace`);return Ct.enabled(`${e}:trace`)&&Ct.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Ct(`${e}:trace`,t)),Object.assign(Ct(e,t),{error:Ct(`${e}:error`,t),trace:r,newScope:n=>qe(`${e}:${n}`,t)})}function lu(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var d0=Co(ws(),1);var Ht=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},Wn=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},wr=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Xn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},Jn=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Qn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Jr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var zt;(function(e){let t;(function(o){o.EOL="EOL"})(t=e.ValidityType||(e.ValidityType={}));let r;(function(o){o[o.EOL=0]="EOL"})(r||(r={})),(function(o){o.codec=()=>zr(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=pr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),e.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let c={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let l=o.uint32();switch(l>>>3){case 1:{c.value=o.bytes();break}case 2:{c.signatureV1=o.bytes();break}case 3:{c.validityType=e.ValidityType.codec().decode(o);break}case 4:{c.validity=o.bytes();break}case 5:{c.sequence=o.uint64();break}case 6:{c.ttl=o.uint64();break}case 7:{c.pubKey=o.bytes();break}case 8:{c.signatureV2=o.bytes();break}case 9:{c.data=o.bytes();break}default:{o.skipType(l&7);break}}}return c})),n),e.encode=o=>dr(o,e.codec()),e.decode=(o,i)=>lr(o,e.codec(),i)})(zt||(zt={}));var Np=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function hu(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=Lp(e);return r||"Object"}function Lp(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Np.includes(t))return t}var h=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};h.uint=new h(0,"uint",!0);h.negint=new h(1,"negint",!0);h.bytes=new h(2,"bytes",!0);h.string=new h(3,"string",!0);h.array=new h(4,"array",!1);h.map=new h(5,"map",!1);h.tag=new h(6,"tag",!1);h.float=new h(7,"float",!0);h.false=new h(7,"false",!0);h.true=new h(7,"true",!0);h.null=new h(7,"null",!0);h.undefined=new h(7,"undefined",!0);h.break=new h(7,"break",!0);var P=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Qr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Up=new TextEncoder;function to(e){return Qr&&globalThis.Buffer.isBuffer(e)}function tn(e){return e instanceof Uint8Array?to(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Op=24,kp=200,Es=Qr?e=>e.length>=Op?globalThis.Buffer.from(e):pu(e):e=>e.length>=kp?Up.encode(e):pu(e),re=e=>Uint8Array.from(e),mu=Qr?(e,t,r)=>to(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),yu=Qr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),tn(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},gu=Qr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function eo(e,t){if(to(e)&&to(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function pu(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var Kp=256,en=class{constructor(t=Kp){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=gu(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=mu(n,0,this.cursor)}else r=yu(this.chunks,this.cursor);return t&&this.reset(),r}},ro=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var F="CBOR decode error:",Ss="CBOR encode error:",rn=[];rn[23]=1;rn[24]=2;rn[25]=3;rn[26]=5;rn[27]=9;function ye(e,t,r){if(e.length-t<r)throw new Error(`${F} not enough data for type`)}var lt=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Rt(e,t,r){ye(e,t,1);let n=e[t];if(r.strict===!0&&n<lt[0])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Pt(e,t,r){ye(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<lt[1])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Nt(e,t,r){ye(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<lt[2])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Lt(e,t,r){ye(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<lt[3])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${F} integers outside of the safe integer range are not supported`)}function bu(e,t,r,n){return new P(h.uint,Rt(e,t+1,n),2)}function xu(e,t,r,n){return new P(h.uint,Pt(e,t+1,n),3)}function wu(e,t,r,n){return new P(h.uint,Nt(e,t+1,n),5)}function Eu(e,t,r,n){return new P(h.uint,Lt(e,t+1,n),9)}function kt(e,t){return dt(e,0,t.value)}function dt(e,t,r){if(r<lt[0]){let n=Number(r);e.push([t|n])}else if(r<lt[1]){let n=Number(r);e.push([t|24,n])}else if(r<lt[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<lt[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<lt[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${F} encountered BigInt larger than allowable range`)}}kt.encodedSize=function(t){return dt.encodedSize(t.value)};dt.encodedSize=function(t){return t<lt[0]?1:t<lt[1]?2:t<lt[2]?3:t<lt[3]?5:9};kt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Su(e,t,r,n){return new P(h.negint,-1-Rt(e,t+1,n),2)}function vu(e,t,r,n){return new P(h.negint,-1-Pt(e,t+1,n),3)}function Au(e,t,r,n){return new P(h.negint,-1-Nt(e,t+1,n),5)}var vs=BigInt(-1),Iu=BigInt(1);function Tu(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new P(h.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${F} integers outside of the safe integer range are not supported`);return new P(h.negint,vs-BigInt(o),9)}function no(e,t){let r=t.value,n=typeof r=="bigint"?r*vs-Iu:r*-1-1;dt(e,t.type.majorEncoded,n)}no.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*vs-Iu:r*-1-1;return n<lt[0]?1:n<lt[1]?2:n<lt[2]?3:n<lt[3]?5:9};no.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function nn(e,t,r,n){ye(e,t,r+n);let o=e.slice(t+r,t+r+n);return new P(h.bytes,o,r+n)}function Cu(e,t,r,n){return nn(e,t,1,r)}function Bu(e,t,r,n){return nn(e,t,2,Rt(e,t+1,n))}function _u(e,t,r,n){return nn(e,t,3,Pt(e,t+1,n))}function Du(e,t,r,n){return nn(e,t,5,Nt(e,t+1,n))}function Ru(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer bytes lengths not supported`);return nn(e,t,9,o)}function oo(e){return e.encodedBytes===void 0&&(e.encodedBytes=h.equals(e.type,h.string)?Es(e.value):e.value),e.encodedBytes}function Er(e,t){let r=oo(t);dt(e,t.type.majorEncoded,r.length),e.push(r)}Er.encodedSize=function(t){let r=oo(t);return dt.encodedSize(r.length)+r.length};Er.compareTokens=function(t,r){return Vp(oo(t),oo(r))};function Vp(e,t){return e.length<t.length?-1:e.length>t.length?1:eo(e,t)}var Pu=new TextDecoder,$p=32;function qp(e,t,r){if(r-t<$p){let o="";for(let i=t;i<r;i++){let s=e[i];if(s&128)return Pu.decode(e.subarray(t,r));o+=String.fromCharCode(s)}return o}return Pu.decode(e.subarray(t,r))}function on(e,t,r,n,o){let i=r+n;ye(e,t,i);let s=new P(h.string,qp(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=e.slice(t+r,t+i)),s}function Nu(e,t,r,n){return on(e,t,1,r,n)}function Lu(e,t,r,n){return on(e,t,2,Rt(e,t+1,n),n)}function Uu(e,t,r,n){return on(e,t,3,Pt(e,t+1,n),n)}function Ou(e,t,r,n){return on(e,t,5,Nt(e,t+1,n),n)}function ku(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer string lengths not supported`);return on(e,t,9,o,n)}var Ku=Er;function Sr(e,t,r,n){return new P(h.array,n,r)}function Mu(e,t,r,n){return Sr(e,t,1,r)}function Vu(e,t,r,n){return Sr(e,t,2,Rt(e,t+1,n))}function Fu(e,t,r,n){return Sr(e,t,3,Pt(e,t+1,n))}function $u(e,t,r,n){return Sr(e,t,5,Nt(e,t+1,n))}function qu(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer array lengths not supported`);return Sr(e,t,9,o)}function Hu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return Sr(e,t,1,1/0)}function io(e,t){dt(e,h.array.majorEncoded,t.value)}io.compareTokens=kt.compareTokens;io.encodedSize=function(t){return dt.encodedSize(t.value)};function vr(e,t,r,n){return new P(h.map,n,r)}function zu(e,t,r,n){return vr(e,t,1,r)}function ju(e,t,r,n){return vr(e,t,2,Rt(e,t+1,n))}function Gu(e,t,r,n){return vr(e,t,3,Pt(e,t+1,n))}function Zu(e,t,r,n){return vr(e,t,5,Nt(e,t+1,n))}function Yu(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer map lengths not supported`);return vr(e,t,9,o)}function Wu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return vr(e,t,1,1/0)}function so(e,t){dt(e,h.map.majorEncoded,t.value)}so.compareTokens=kt.compareTokens;so.encodedSize=function(t){return dt.encodedSize(t.value)};function Xu(e,t,r,n){return new P(h.tag,r,1)}function Ju(e,t,r,n){return new P(h.tag,Rt(e,t+1,n),2)}function Qu(e,t,r,n){return new P(h.tag,Pt(e,t+1,n),3)}function tf(e,t,r,n){return new P(h.tag,Nt(e,t+1,n),5)}function ef(e,t,r,n){return new P(h.tag,Lt(e,t+1,n),9)}function ao(e,t){dt(e,h.tag.majorEncoded,t.value)}ao.compareTokens=kt.compareTokens;ao.encodedSize=function(t){return dt.encodedSize(t.value)};var As=20,Is=21,Ts=22,Cs=23;function rf(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${F} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new P(h.null,null,1):new P(h.undefined,void 0,1)}function nf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return new P(h.break,void 0,1)}function Bs(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${F} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${F} Infinity values are not supported`)}return new P(h.float,e,t)}function of(e,t,r,n){return Bs(_s(e,t+1),3,n)}function sf(e,t,r,n){return Bs(Ds(e,t+1),5,n)}function af(e,t,r,n){return Bs(lf(e,t+1),9,n)}function co(e,t,r){let n=t.value;if(n===!1)e.push([h.float.majorEncoded|As]);else if(n===!0)e.push([h.float.majorEncoded|Is]);else if(n===null)e.push([h.float.majorEncoded|Ts]);else if(n===void 0)e.push([h.float.majorEncoded|Cs]);else{let o,i=!1;(!r||r.float64!==!0)&&(uf(n),o=_s(jt,1),n===o||Number.isNaN(n)?(jt[0]=249,e.push(jt.slice(0,3)),i=!0):(ff(n),o=Ds(jt,1),n===o&&(jt[0]=250,e.push(jt.slice(0,5)),i=!0))),i||(Zp(n),o=lf(jt,1),jt[0]=251,e.push(jt.slice(0,9)))}}co.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){uf(n);let o=_s(jt,1);if(n===o||Number.isNaN(n))return 3;if(ff(n),o=Ds(jt,1),n===o)return 5}return 9};var cf=new ArrayBuffer(9),Kt=new DataView(cf,1),jt=new Uint8Array(cf,0);function uf(e){if(e===1/0)Kt.setUint16(0,31744,!1);else if(e===-1/0)Kt.setUint16(0,64512,!1);else if(Number.isNaN(e))Kt.setUint16(0,32256,!1);else{Kt.setFloat32(0,e);let t=Kt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Kt.setUint16(0,31744,!1);else if(r===0)Kt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Kt.setUint16(0,0):o<-14?Kt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Kt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function _s(e,t){if(e.length-t<2)throw new Error(`${F} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function ff(e){Kt.setFloat32(0,e,!1)}function Ds(e,t){if(e.length-t<4)throw new Error(`${F} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Zp(e){Kt.setFloat64(0,e,!1)}function lf(e,t){if(e.length-t<8)throw new Error(`${F} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}co.compareTokens=kt.compareTokens;function Z(e,t,r){throw new Error(`${F} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function uo(e){return()=>{throw new Error(`${F} ${e}`)}}var B=[];for(let e=0;e<=23;e++)B[e]=Z;B[24]=bu;B[25]=xu;B[26]=wu;B[27]=Eu;B[28]=Z;B[29]=Z;B[30]=Z;B[31]=Z;for(let e=32;e<=55;e++)B[e]=Z;B[56]=Su;B[57]=vu;B[58]=Au;B[59]=Tu;B[60]=Z;B[61]=Z;B[62]=Z;B[63]=Z;for(let e=64;e<=87;e++)B[e]=Cu;B[88]=Bu;B[89]=_u;B[90]=Du;B[91]=Ru;B[92]=Z;B[93]=Z;B[94]=Z;B[95]=uo("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)B[e]=Nu;B[120]=Lu;B[121]=Uu;B[122]=Ou;B[123]=ku;B[124]=Z;B[125]=Z;B[126]=Z;B[127]=uo("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)B[e]=Mu;B[152]=Vu;B[153]=Fu;B[154]=$u;B[155]=qu;B[156]=Z;B[157]=Z;B[158]=Z;B[159]=Hu;for(let e=160;e<=183;e++)B[e]=zu;B[184]=ju;B[185]=Gu;B[186]=Zu;B[187]=Yu;B[188]=Z;B[189]=Z;B[190]=Z;B[191]=Wu;for(let e=192;e<=215;e++)B[e]=Xu;B[216]=Ju;B[217]=Qu;B[218]=tf;B[219]=ef;B[220]=Z;B[221]=Z;B[222]=Z;B[223]=Z;for(let e=224;e<=243;e++)B[e]=uo("simple values are not supported");B[244]=Z;B[245]=Z;B[246]=Z;B[247]=rf;B[248]=uo("simple values are not supported");B[249]=of;B[250]=sf;B[251]=af;B[252]=Z;B[253]=Z;B[254]=Z;B[255]=nf;var Gt=[];for(let e=0;e<24;e++)Gt[e]=new P(h.uint,e,1);for(let e=-1;e>=-24;e--)Gt[31-e]=new P(h.negint,e,1);Gt[64]=new P(h.bytes,new Uint8Array(0),1);Gt[96]=new P(h.string,"",1);Gt[128]=new P(h.array,0,1);Gt[160]=new P(h.map,0,1);Gt[244]=new P(h.false,!1,1);Gt[245]=new P(h.true,!0,1);Gt[246]=new P(h.null,null,1);function df(e){switch(e.type){case h.false:return re([244]);case h.true:return re([245]);case h.null:return re([246]);case h.bytes:return e.value.length?void 0:re([64]);case h.string:return e.value===""?re([96]):void 0;case h.array:return e.value===0?re([128]):void 0;case h.map:return e.value===0?re([160]):void 0;case h.uint:return e.value<24?re([Number(e.value)]):void 0;case h.negint:if(e.value>=-24)return re([31-Number(e.value)])}}var pf=Object.freeze({float64:!0,mapSorter:t0,quickEncodeToken:df});function Wp(){let e=[];return e[h.uint.major]=kt,e[h.negint.major]=no,e[h.bytes.major]=Er,e[h.string.major]=Ku,e[h.array.major]=io,e[h.map.major]=so,e[h.tag.major]=ao,e[h.float.major]=co,e}var Xp=Wp(),Jp=new en,lo=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${Ss} object contains circular references`);return new e(r,t)}},Be={null:new P(h.null,null),undefined:new P(h.undefined,void 0),true:new P(h.true,!0),false:new P(h.false,!1),emptyArray:new P(h.array,0),emptyMap:new P(h.map,0)},_e={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new P(h.float,e):e>=0?new P(h.uint,e):new P(h.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new P(h.uint,e):new P(h.negint,e)},Uint8Array(e,t,r,n){return new P(h.bytes,e)},string(e,t,r,n){return new P(h.string,e)},boolean(e,t,r,n){return e?Be.true:Be.false},null(e,t,r,n){return Be.null},undefined(e,t,r,n){return Be.undefined},ArrayBuffer(e,t,r,n){return new P(h.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new P(h.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Be.emptyArray,new P(h.break)]:Be.emptyArray;n=lo.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=fo(s,r,n);return r.addBreakTokens?[new P(h.array,e.length),o,new P(h.break)]:[new P(h.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length,c;if(s){c=new Array(s),n=lo.createCheck(n,e);let a=!o&&r.ignoreUndefinedProperties,l=0;for(let u of i){let f=o?e.get(u):e[u];a&&f===void 0||(c[l++]=[fo(u,r,n),fo(f,r,n)])}l<s&&(c.length=l)}return c?.length?(Qp(c,r),r.addBreakTokens?[new P(h.map,c.length),c,new P(h.break)]:[new P(h.map,c.length),c]):r.addBreakTokens===!0?[Be.emptyMap,new P(h.break)]:Be.emptyMap}};_e.Map=_e.Object;_e.Buffer=_e.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))_e[`${e}Array`]=_e.DataView;function fo(e,t={},r){let n=hu(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||_e[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=_e[n];if(!i)throw new Error(`${Ss} unsupported type: ${n}`);return i(e,n,t,r)}function Qp(e,t){t.mapSorter&&e.sort(t.mapSorter)}function t0(e,t){if(e[0]instanceof P&&t[0]instanceof P){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=hf(r.value)),n._keyBytes||(n._keyBytes=hf(n.value)),eo(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function hf(e){return e0(e,Xp,pf)}function mf(e,t,r,n){if(Array.isArray(t))for(let o of t)mf(e,o,r,n);else r[t.type.major](e,t,n)}var S1=h.uint.majorEncoded,v1=h.negint.majorEncoded,A1=h.bytes.majorEncoded,I1=h.string.majorEncoded,T1=h.array.majorEncoded,C1=h.float.majorEncoded|As,B1=h.float.majorEncoded|Is,_1=h.float.majorEncoded|Ts,D1=h.float.majorEncoded|Cs,R1=BigInt(-1),P1=BigInt(1);function e0(e,t,r,n){let o=n instanceof Uint8Array,i=o?new ro(n):Jp,s=fo(e,r);if(!Array.isArray(s)&&r.quickEncodeToken){let c=r.quickEncodeToken(s);if(c)return o?(i.push(c),i.toBytes()):c;let a=t[s.type.major];if(a.encodedSize){let l=a.encodedSize(s,r);if(o||(i=new en(l)),a(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():tn(i.chunks[0])}}return i.reset(),mf(i,s,t,r),i.toBytes(!0)}var r0={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ho=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=Gt[t];if(r===void 0){let n=B[t];if(!n)throw new Error(`${F} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},sn=Symbol.for("DONE"),po=Symbol.for("BREAK");function n0(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Ar(t,r);if(i===po){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed array`)}if(i===sn)throw new Error(`${F} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function o0(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let c=0;c<e.value;c++){let a=Ar(t,r);if(a===po){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed map`)}if(a===sn)throw new Error(`${F} found map but not enough entries (got ${c} [no key], expected ${e.value})`);if(!n&&typeof a!="string")throw new Error(`${F} non-string keys not supported (got ${typeof a})`);if(o&&(n&&s.has(a)||!n&&Object.hasOwn(i,a)))throw new Error(`${F} found repeat map key "${a}"`);let l=Ar(t,r);if(l===sn)throw new Error(`${F} found map but not enough entries (got ${c} [no value], expected ${e.value})`);n?s.set(a,l):i[a]=l}return n?s:i}function Ar(e,t){if(e.done())return sn;let r=e.next();if(h.equals(r.type,h.break))return po;if(r.type.terminal)return r.value;if(h.equals(r.type,h.array))return n0(r,e,t);if(h.equals(r.type,h.map))return o0(r,e,t);if(h.equals(r.type,h.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Ar(e,t);return t.tags[r.value](n)}throw new Error(`${F} tag not supported (${r.value})`)}throw new Error("unsupported")}function yf(e,t){if(!(e instanceof Uint8Array))throw new Error(`${F} data to decode must be a Uint8Array`);t=Object.assign({},r0,t);let r=tn(e),n=t.tokenizer||new ho(r,t),o=Ar(n,t);if(o===sn)throw new Error(`${F} did not find any content to decode`);if(o===po)throw new Error(`${F} got unexpected break`);return[o,e.subarray(n.pos())]}function Rs(e,t){let[r,n]=yf(e,t);if(n.length>0)throw new Error(`${F} too many terminals, data makes no sense`);return r}var a0=qe("ipns:utils"),gf=H("/ipns/");var c0=0,u0=18;function bf(e){let t;if(e.pubKey!=null)try{t=qc(e.pubKey)}catch(r){throw a0.error(r),r}if(t!=null)return t}function xf(e){let t=H("ipns-signature:");return Ut([t,e])}function ze(e){return"signatureV1"in e?zt.encode({value:H(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:H(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):zt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function ne(e){let t=zt.decode(e);if(t.sequence!=null&&(t.sequence=BigInt(t.sequence)),t.ttl!=null&&(t.ttl=BigInt(t.ttl)),t.signatureV2==null||t.data==null)throw new Ht("Missing data or signatureV2");let r=wf(t.data),n=f0(r.Value),o=z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return l0(t),{value:n,validityType:zt.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV1:t.signatureV1,signatureV2:t.signatureV2,data:t.data};if(t.signatureV2!=null)return{value:n,validityType:zt.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function an(e){return Ut([gf,e.bytes])}function ge(e){let t=xe(e.slice(gf.length));if(!mo(t,c0)&&!mo(t,u0))throw new Ze("Multihash in IPNS key was not identity or sha2-256");return t}function wf(e){let t=Rs(e);if(t.ValidityType===0)t.ValidityType=zt.ValidityType.EOL;else throw new wr("The validity type is unsupported");return Number.isInteger(t.Sequence)&&(t.Sequence=BigInt(t.Sequence)),Number.isInteger(t.TTL)&&(t.TTL=BigInt(t.TTL)),t}function f0(e){let t=z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${j.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${j.parse(t).toV1().toString()}`}catch{}throw new Jn("Value must be a valid content path starting with /")}function l0(e){if(e.data==null)throw new Qn("Record data is missing");let t=wf(e.data);if(!Y(t.Value,e.value??new Uint8Array(0)))throw new Ht('Field "value" did not match between protobuf and CBOR');if(!Y(t.Validity,e.validity??new Uint8Array(0)))throw new Ht('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Ht('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Ht('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Ht('Field "ttl" did not match between protobuf and CBOR')}function mo(e,t){return e.code===t}var n2=qe("ipns"),o2=300*1e9,h0="/ipns/",i2=h0.length;var Ef=Co(ws(),1);var yo=qe("ipns:validator"),p0=1024*10;async function m0(e,t){let r=ne(t),n;try{let o=xf(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw yo.error("record signature verification failed"),new Ht("Record signature verification failed");if(r.validityType===zt.ValidityType.EOL){if(Ef.default.fromString(r.validity).toDate().getTime()<Date.now())throw yo.error("record has expired"),new Wn("record has expired")}else if(r.validityType!=null)throw yo.error("the validity type is unsupported"),new wr("The validity type is unsupported");yo("ipns record for %s is valid",r.value)}async function Sf(e,t){if(t.byteLength>p0)throw new Xn("The record is too large");let r=ge(e),n;mo(r,0)&&(n=On(r));let o=ne(t),i=bf(o)??n;if(i==null)throw new Jr("Could not extract public key from IPNS record or routing key");let s=an(i.toMultihash());if(!Y(s,e))throw new Jr("Embedded public key did not match routing key");await m0(i,t)}var go=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*Ir(e,t={}){let r=/\r?\n/,n=new TextDecoder("utf8"),o="";for await(let i of e){if(typeof i=="string"&&(i=new TextEncoder().encode(i)),tr(i)&&(i=i.subarray()),o+=n.decode(i,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new go("Incoming message too long");let s=o.split(r);o=s.pop()??"";for(let c=0;c<s.length;c++)yield JSON.parse(s[c])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}function Mt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Ns=Co(Af(),1);var Ls=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},If=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Us(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,c,a,u=new Promise((f,g)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){g(If(s));return}if(s&&(a=()=>{g(If(s))},s.addEventListener("abort",a,{once:!0})),e.then(f,g),r===Number.POSITIVE_INFINITY)return;let E=new Ls;c=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(x){g(x)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?f():o instanceof Error?g(o):(E.message=o??`Promise timed out after ${r} milliseconds`,g(E))},r)}).finally(()=>{u.clear(),a&&s&&s.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,c),c=void 0},u}function Os(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(e[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var un=class{#t=[];enqueue(t,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=Os(this.#t,i,(c,a)=>a.priority-c.priority);this.#t.splice(s,0,i)}setPriority(t,r){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var fn=class extends Ns.default{#t;#n;#e=0;#h;#m=!1;#b=!1;#c;#T=0;#x=0;#u;#f;#a;#s=[];#i=0;#r;#C;#o=0;#y;#l;#P=1n;#g=new Map;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:un,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#n=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#c=t.interval,this.#a=t.strict,this.#r=new t.queueClass,this.#C=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#V()}#w(t){for(;this.#i<this.#s.length;){let n=this.#s[this.#i];if(n!==void 0&&t-n>=this.#c)this.#i++;else break}(this.#i>100&&this.#i>this.#s.length/2||this.#i===this.#s.length)&&(this.#s=this.#s.slice(this.#i),this.#i=0)}#N(t){this.#a?this.#s.push(t):this.#e++}#L(){this.#a?this.#s.length>this.#i&&this.#s.pop():this.#e>0&&this.#e--}#E(){return this.#s.length-this.#i}get#U(){return this.#n?!0:this.#a?this.#E()<this.#h:this.#e<this.#h}get#O(){return this.#o<this.#y}#k(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#A(),this.emit("next")}#K(){this.#f=void 0,this.#D(),this.#_()}#M(t){if(this.#a){if(this.#w(t),this.#E()>=this.#h){let n=this.#s[this.#i],o=this.#c-(t-n);return this.#S(o),!0}return!1}if(this.#u===void 0){let r=this.#T-t;if(r<0){if(this.#x>0){let n=t-this.#x;if(n<this.#c)return this.#S(this.#c-n),!0}this.#e=this.#t?this.#o:0}else return this.#S(r),!0}return!1}#S(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#K()},t))}#v(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#B(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#A(){if(this.#r.size===0){if(this.#v(),this.emit("empty"),this.#o===0){if(this.#B(),this.#a&&this.#i>0){let r=Date.now();this.#w(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#M(r);if(this.#U&&this.#O){let o=this.#r.dequeue();this.#n||(this.#N(r),this.#p()),this.emit("active"),o(),n&&this.#_(),t=!0}}return t}#_(){this.#n||this.#u!==void 0||this.#a||(this.#u=setInterval(()=>{this.#D()},this.#c),this.#T=Date.now()+this.#c)}#D(){this.#a||(this.#e===0&&this.#o===0&&this.#u&&this.#v(),this.#e=this.#t?this.#o:0),this.#I(),this.#p()}#I(){for(;this.#A(););}get concurrency(){return this.#y}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#y=t,this.#I()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(t,r)}async add(t,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#P++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`);this.#r.enqueue(async()=>{this.#o++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let s;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#F(),this.#g.delete(i),l}this.#x=Date.now();let c=t({signal:r.signal});if(r.timeout&&(c=Us(Promise.resolve(c),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#o} running, ${this.#r.size} waiting)`})),r.signal){let{signal:l}=r;c=Promise.race([c,new Promise((u,f)=>{s=()=>{f(l.reason)},l.addEventListener("abort",s,{once:!0})})])}let a=await c;n(a),this.emit("completed",a)}catch(c){o(c),this.emit("error",c)}finally{s&&r.signal?.removeEventListener("abort",s),this.#g.delete(i),queueMicrotask(()=>{this.#k()})}},r),this.emit("add"),this.#A()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){this.#r=new this.#C,this.#v(),this.#R(),this.emit("empty"),this.#o===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(t){this.#r.size<t||await this.#d("next",()=>this.#r.size<t)}async onIdle(){this.#o===0&&this.#r.size===0||await this.#d("idle")}async onPendingZero(){this.#o!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((t,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#l}#V(){this.#n||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#n||this.#b||(this.#b=!0,queueMicrotask(()=>{this.#b=!1,this.#R()}))}#F(){this.#n||(this.#L(),this.#p())}#R(){let t=this.#m;if(this.#n||this.#r.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let o=Date.now();this.#w(o),r=this.#E()}else r=this.#e;let n=r>=this.#h;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#o===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(t=>({...t}))}};var je=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},Vt=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};function b0(e){return e[Symbol.asyncIterator]!=null}function x0(e){if(b0(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var xo=x0;function w0(e){let[t,r]=e[Symbol.asyncIterator]!=null?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[r](){return this}}}var Tf=w0;function E0(e){return e[Symbol.asyncIterator]!=null}function S0(e,t){let r=0;if(E0(e))return(async function*(){for await(let a of e)yield t(a,r++)})();let n=Tf(e),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=t(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let a of n)yield t(a,r++)})();let c=t;return(function*(){yield s;for(let a of n)yield c(a,r++)})()}var wo=S0;var Cf=H("/ipns/");function Bf(e){return Y(e.subarray(0,Cf.byteLength),Cf)}var Eo=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){try{yield*wo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[],routing:"delegated-http-routing-v1"}))}catch(n){if(n instanceof At)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!Bf(t))return;let o=ge(t),i=j.createV1(114,o),s=ne(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!Bf(t))throw new At("Not found");let n=ge(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return ze(i)}catch(i){throw i.name==="BadResponseError"?new At("Not found"):i}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},So=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await xo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new At("Not found")}async*getClosestPeers(t,r={}){let n;try{n=j.decode(t)}catch{try{n=Vn(Xt.decode(t))}catch{n=j.createV1(ga,Et.digest(t))}}for await(let o of this.client.getClosestPeers(n,r))yield{id:o.ID,multiaddrs:o.Addrs??[]}}toString(){return`DelegatedRoutingV1HttpApiClientPeerRouting(${this.client.url})`}};var vo={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},Ao=class{url;started;httpQueue;shutDownController;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,r){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new fn({concurrency:r.concurrentRequests??vo.concurrentRequests}),this.inFlightRequests=new Map,this.url=r.url instanceof URL?r.url:new URL(r.url),this.timeout=r.timeout??vo.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new Eo(this),this.peerRouting=new So(this),this.cacheName=r.cacheName??vo.cacheName,this.cacheTTL=r.cacheTTL??vo.cacheTTL}get[Xs](){return this.contentRouting}get[Qs](){return this.peerRouting}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(t,r={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=xr([this.shutDownController.signal,n,r.signal]);let i=Mt(),s=Mt(),c=0;this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.url}routing/v1/providers/${t}`);this.#n(a,r.filterAddrs,r.filterProtocols);let l={headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o},u=await this.#e(a.toString(),l);if(!u.ok){if(u.status===404)return;throw u.status===422?new je("Request does not conform to schema or semantic constraints"):new Vt(`Unexpected status code: ${u.status}`)}let f=u.headers.get("Content-Type");if(f==null)throw new Vt("No Content-Type header received");if(u.body==null){if(f!=="application/x-ndjson")throw new Vt("Routing response had no body");return}if(f.startsWith("application/json")){let E=(await u.json()).Providers??[];for(let x of E){let T=this.#t(x);T!=null&&(c++,yield T)}}else if(f.includes("application/x-ndjson"))for await(let g of Ir(Xr(u.body))){let E=this.#t(g);E!=null&&(c++,yield E)}else throw new Vt(`Unsupported Content-Type: ${f}`)}finally{o.clear(),s.resolve(),this.log("getProviders finished found %d providers for %c",c,t)}}async*getPeers(t,r={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=xr([this.shutDownController.signal,n,r.signal]);let i=Mt(),s=Mt();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/peers/${t.toCID().toString()}`);this.#n(c,r.filterAddrs,r.filterProtocols);let a={headers:{Accept:"application/x-ndjson"},signal:o},l=await this.#e(c.toString(),a);if(l.status===404)return;if(l.status===422)throw new je("Request does not conform to schema or semantic constraints");if(l.body==null)throw new Vt("Routing response had no body");if(l.headers.get("Content-Type")?.startsWith("application/json")){let g=(await l.json()).Peers??[];for(let E of g){let x=this.#t(E);x!=null&&(yield x)}}else for await(let f of Ir(Xr(l.body))){let g=this.#t(f);g!=null&&(yield g)}}catch(c){this.log.error("getPeers errored - %e",c)}finally{o.clear(),s.resolve(),this.log("getPeers finished: %c",t)}}async*getClosestPeers(t,r={}){let n;if(Js(t))n=t.toCID().toString();else if(j.asCID(t)===t||t instanceof j)n=t.toV1().toString();else throw new nt("Key must be CID or PeerId");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),i=xr([this.shutDownController.signal,o,r.signal]);let s=Mt(),c=Mt();this.httpQueue.add(async()=>(s.resolve(),c.promise));try{await s.promise;let a=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#n(a,r.filterAddrs,r.filterProtocols);let l={headers:{Accept:"application/x-ndjson"},signal:i},u=await this.#e(a.toString(),l);if(u.status===404)return;if(u.status===422)throw new je("Request does not conform to schema or semantic constraints");if(u.body==null)throw new Vt("Routing response had no body");if(u.headers.get("Content-Type")?.startsWith("application/json")){let E=(await u.json()).Peers??[];for(let x of E){let T=this.#t(x);T!=null&&(yield T)}}else for await(let g of Ir(Xr(u.body))){let E=this.#t(g);E!=null&&(yield E)}}catch(a){this.log.error("getClosestPeers errored - %e",a)}finally{i.clear(),c.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(t,r={}){this.log("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=xr([this.shutDownController.signal,n,r.signal]);let i=Mt(),s=Mt();this.httpQueue.add(async()=>(i.resolve(),s.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let a={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},l=await this.#e(c,a);if(this.log("getIPNS GET %s %d",c,l.status),l.status===404)throw new At("No matching records found");if(l.status===422)throw new je("Request does not conform to schema or semantic constraints");if(!l.ok)throw new Vt(`Unexpected status code: ${l.status}`);let u=l.headers.get("Content-Type");if(u==null||!u.includes("application/vnd.ipfs.ipns-record"))throw new At("No matching records found");if(l.body==null)throw new Vt("GET ipns response had no body");let f=await l.arrayBuffer(),g=new Uint8Array(f,0,f.byteLength);return r.validate!==!1&&await Sf(an(t.multihash),g),ne(g)}catch(a){throw this.log.error("getIPNS GET %s error - %e",c,a),a}finally{o.clear(),s.resolve(),this.log("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=xr([this.shutDownController.signal,o,n.signal]);let s=Mt(),c=Mt();this.httpQueue.add(async()=>(s.resolve(),c.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let l=ze(r),u={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:l,signal:i},f=await this.#e(a,u);if(this.log("putIPNS PUT %s %d",a,f.status),f.status!==200)throw new Vt("PUT ipns response had status other than 200")}catch(l){throw this.log.error("putIPNS PUT %s error - %e",a,l.stack),l}finally{i.clear(),c.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map(Gn)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:jc(t.ID),Addrs:n,Protocols:r}}catch(r){this.log.error("could not conform record to peer schema - %e",r)}}#n(t,r,n){if(r!=null||this.filterAddrs!=null){let o=r?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&t.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&t.searchParams.set("filter-protocols",o)}}async#e(t,r){let n=r.method??"GET",o=`${n}-${t}`;if(n==="GET"){let a=await this.cache?.match(t);if(a!=null){if(parseInt(a.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(a),a;this.log("evicting cached response for %s",o),await this.cache?.delete(t)}else this.cache!=null&&this.log("cache miss for %s",o)}let i=this.inFlightRequests.get(o);if(i!=null){let a=await i;return this.log("deduplicating outgoing request for %s",o),a.clone()}this.log("outgoing request:"),this.logRequest(t,r);let s=fetch(t,r).then(async a=>{if(this.log("incoming response:"),this.logResponse(a),this.cache!=null&&a.ok&&n==="GET"){let l=Date.now()+this.cacheTTL,u=new Headers(a.headers);u.set("x-cache-expires",l.toString());let f=new Response(a.clone().body,{status:a.status,statusText:a.statusText,headers:u});await this.cache.put(t,f)}return a}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,r){let n=new Headers(r.headers);this.log("%s %s HTTP/1.1",r.method??"GET",t);for(let[o,i]of n.entries())this.log("%s: %s",o,i)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[r,n]of t.headers.entries())this.log("%s: %s",r,n)}};function _f(e){return t=>new Ao(t,e)}function Io(e){return{url:"https://delegated-ipfs.dev",filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss","tls"]}}var Df=H("/ipns/");function Rf(e){return Y(e.subarray(0,Df.byteLength),Df)}var ks=class{client;constructor(t,r){this.client=_f(r)(t)}async provide(t,r){}async cancelReprovide(t,r){}async*findProviders(t,r){yield*wo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols,routing:"delegated-http-routing"}))}async put(t,r,n){if(!Rf(t))return;let o=ge(t),i=j.createV1(114,o),s=ne(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!Rf(t))throw new At("Not found");let n=ge(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return ze(i)}catch(i){throw i.name==="BadResponseError"?new At("Not found"):i}}async findPeer(t,r){let n=await xo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new At("Not found")}async*getClosestPeers(t,r){}toString(){return`DelegatedHTTPRouter(${this.client.url})`}};function Pf(e){return t=>new ks(t,Io(e))}var Nf="[a-fA-F\\d:]",De=e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${Nf})|(?<=${Nf})(?=\\s|$))`:"",Zt="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",at="[a-fA-F\\d]{1,4}",To=`
|
|
13
|
+
${t}[Error list was empty]`,r.trim()}return fu(e,t)}Ct.formatters.e=e=>e==null?"undefined":du(e);function Pp(e){let t=()=>{};return t.enabled=!1,t.color="",t.diff=0,t.log=()=>{},t.namespace=e,t.destroy=()=>!0,t.extend=()=>t,t}function qe(e,t){let r=Pp(`${e}:trace`);return Ct.enabled(`${e}:trace`)&&Ct.names.map(n=>n.toString()).find(n=>n.includes(":trace"))!=null&&(r=Ct(`${e}:trace`,t)),Object.assign(Ct(e,t),{error:Ct(`${e}:error`,t),trace:r,newScope:n=>qe(`${e}:${n}`,t)})}function lu(e){if(e!=null&&(e=e.trim(),e.length!==0))return e}var d0=Co(ws(),1);var Ht=class extends Error{static name="SignatureVerificationError";constructor(t="Record signature verification failed"){super(t),this.name="SignatureVerificationError"}},Wn=class extends Error{static name="RecordExpiredError";constructor(t="Record has expired"){super(t),this.name="RecordExpiredError"}},wr=class extends Error{static name="UnsupportedValidityError";constructor(t="The validity type is unsupported"){super(t),this.name="UnsupportedValidityError"}},Xn=class extends Error{static name="RecordTooLargeError";constructor(t="The record is too large"){super(t),this.name="RecordTooLargeError"}},Jn=class extends Error{static name="InvalidValueError";constructor(t="Value must be a valid content path starting with /"){super(t),this.name="InvalidValueError"}},Qn=class extends Error{static name="InvalidRecordDataError";constructor(t="Invalid record data"){super(t),this.name="InvalidRecordDataError"}},Jr=class extends Error{static name="InvalidEmbeddedPublicKeyError";constructor(t="Invalid embedded public key"){super(t),this.name="InvalidEmbeddedPublicKeyError"}};var zt;(function(e){let t;(function(o){o.EOL="EOL"})(t=e.ValidityType||(e.ValidityType={}));let r;(function(o){o[o.EOL=0]="EOL"})(r||(r={})),(function(o){o.codec=()=>zr(r)})(t=e.ValidityType||(e.ValidityType={}));let n;e.codec=()=>(n==null&&(n=pr((o,i,s={})=>{s.lengthDelimited!==!1&&i.fork(),o.value!=null&&(i.uint32(10),i.bytes(o.value)),o.signatureV1!=null&&(i.uint32(18),i.bytes(o.signatureV1)),o.validityType!=null&&(i.uint32(24),e.ValidityType.codec().encode(o.validityType,i)),o.validity!=null&&(i.uint32(34),i.bytes(o.validity)),o.sequence!=null&&(i.uint32(40),i.uint64(o.sequence)),o.ttl!=null&&(i.uint32(48),i.uint64(o.ttl)),o.pubKey!=null&&(i.uint32(58),i.bytes(o.pubKey)),o.signatureV2!=null&&(i.uint32(66),i.bytes(o.signatureV2)),o.data!=null&&(i.uint32(74),i.bytes(o.data)),s.lengthDelimited!==!1&&i.ldelim()},(o,i,s={})=>{let c={},a=i==null?o.len:o.pos+i;for(;o.pos<a;){let l=o.uint32();switch(l>>>3){case 1:{c.value=o.bytes();break}case 2:{c.signatureV1=o.bytes();break}case 3:{c.validityType=e.ValidityType.codec().decode(o);break}case 4:{c.validity=o.bytes();break}case 5:{c.sequence=o.uint64();break}case 6:{c.ttl=o.uint64();break}case 7:{c.pubKey=o.bytes();break}case 8:{c.signatureV2=o.bytes();break}case 9:{c.data=o.bytes();break}default:{o.skipType(l&7);break}}}return c})),n),e.encode=o=>dr(o,e.codec()),e.decode=(o,i)=>lr(o,e.codec(),i)})(zt||(zt={}));var Np=["Object","RegExp","Date","Error","Map","Set","WeakMap","WeakSet","ArrayBuffer","SharedArrayBuffer","DataView","Promise","URL","HTMLElement","Int8Array","Uint8ClampedArray","Int16Array","Uint16Array","Int32Array","Uint32Array","Float32Array","Float64Array","BigInt64Array","BigUint64Array"];function hu(e){if(e===null)return"null";if(e===void 0)return"undefined";if(e===!0||e===!1)return"boolean";let t=typeof e;if(t==="string"||t==="number"||t==="bigint"||t==="symbol")return t;if(t==="function")return"Function";if(Array.isArray(e))return"Array";if(e instanceof Uint8Array)return"Uint8Array";if(e.constructor===Object)return"Object";let r=Lp(e);return r||"Object"}function Lp(e){let t=Object.prototype.toString.call(e).slice(8,-1);if(Np.includes(t))return t}var h=class{constructor(t,r,n){this.major=t,this.majorEncoded=t<<5,this.name=r,this.terminal=n}toString(){return`Type[${this.major}].${this.name}`}compare(t){return this.major<t.major?-1:this.major>t.major?1:0}static equals(t,r){return t===r||t.major===r.major&&t.name===r.name}};h.uint=new h(0,"uint",!0);h.negint=new h(1,"negint",!0);h.bytes=new h(2,"bytes",!0);h.string=new h(3,"string",!0);h.array=new h(4,"array",!1);h.map=new h(5,"map",!1);h.tag=new h(6,"tag",!1);h.float=new h(7,"float",!0);h.false=new h(7,"false",!0);h.true=new h(7,"true",!0);h.null=new h(7,"null",!0);h.undefined=new h(7,"undefined",!0);h.break=new h(7,"break",!0);var P=class{constructor(t,r,n){this.type=t,this.value=r,this.encodedLength=n,this.encodedBytes=void 0,this.byteValue=void 0}toString(){return`Token[${this.type}].${this.value}`}};var Qr=globalThis.process&&!globalThis.process.browser&&globalThis.Buffer&&typeof globalThis.Buffer.isBuffer=="function",Up=new TextEncoder;function to(e){return Qr&&globalThis.Buffer.isBuffer(e)}function tn(e){return e instanceof Uint8Array?to(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength):e:Uint8Array.from(e)}var Op=24,kp=200,Es=Qr?e=>e.length>=Op?globalThis.Buffer.from(e):pu(e):e=>e.length>=kp?Up.encode(e):pu(e),re=e=>Uint8Array.from(e),mu=Qr?(e,t,r)=>to(e)?new Uint8Array(e.subarray(t,r)):e.slice(t,r):(e,t,r)=>e.slice(t,r),yu=Qr?(e,t)=>(e=e.map(r=>r instanceof Uint8Array?r:globalThis.Buffer.from(r)),tn(globalThis.Buffer.concat(e,t))):(e,t)=>{let r=new Uint8Array(t),n=0;for(let o of e)n+o.length>r.length&&(o=o.subarray(0,r.length-n)),r.set(o,n),n+=o.length;return r},gu=Qr?e=>globalThis.Buffer.allocUnsafe(e):e=>new Uint8Array(e);function eo(e,t){if(to(e)&&to(t))return e.compare(t);for(let r=0;r<e.length;r++)if(e[r]!==t[r])return e[r]<t[r]?-1:1;return 0}function pu(e){let t=[],r=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);o<128?t[r++]=o:o<2048?(t[r++]=o>>6|192,t[r++]=o&63|128):(o&64512)===55296&&n+1<e.length&&(e.charCodeAt(n+1)&64512)===56320?(o=65536+((o&1023)<<10)+(e.charCodeAt(++n)&1023),t[r++]=o>>18|240,t[r++]=o>>12&63|128,t[r++]=o>>6&63|128,t[r++]=o&63|128):(o>=55296&&o<=57343&&(o=65533),t[r++]=o>>12|224,t[r++]=o>>6&63|128,t[r++]=o&63|128)}return t}var Kp=256,en=class{constructor(t=Kp){this.chunkSize=t,this.cursor=0,this.maxCursor=-1,this.chunks=[],this._initReuseChunk=null}reset(){this.cursor=0,this.maxCursor=-1,this.chunks.length&&(this.chunks=[]),this._initReuseChunk!==null&&(this.chunks.push(this._initReuseChunk),this.maxCursor=this._initReuseChunk.length-1)}push(t){let r=this.chunks[this.chunks.length-1];if(this.cursor+t.length<=this.maxCursor+1){let o=r.length-(this.maxCursor-this.cursor)-1;r.set(t,o)}else{if(r){let o=r.length-(this.maxCursor-this.cursor)-1;o<r.length&&(this.chunks[this.chunks.length-1]=r.subarray(0,o),this.maxCursor=this.cursor-1)}t.length<64&&t.length<this.chunkSize?(r=gu(this.chunkSize),this.chunks.push(r),this.maxCursor+=r.length,this._initReuseChunk===null&&(this._initReuseChunk=r),r.set(t,0)):(this.chunks.push(t),this.maxCursor+=t.length)}this.cursor+=t.length}toBytes(t=!1){let r;if(this.chunks.length===1){let n=this.chunks[0];t&&this.cursor>n.length/2?(r=this.cursor===n.length?n:n.subarray(0,this.cursor),this._initReuseChunk=null,this.chunks=[]):r=mu(n,0,this.cursor)}else r=yu(this.chunks,this.cursor);return t&&this.reset(),r}},ro=class{constructor(t){this.dest=t,this.cursor=0,this.chunks=[t]}reset(){this.cursor=0}push(t){if(this.cursor+t.length>this.dest.length)throw new Error("write out of bounds, destination buffer is too small");this.dest.set(t,this.cursor),this.cursor+=t.length}toBytes(t=!1){let r=this.dest.subarray(0,this.cursor);return t&&this.reset(),r}};var F="CBOR decode error:",Ss="CBOR encode error:",rn=[];rn[23]=1;rn[24]=2;rn[25]=3;rn[26]=5;rn[27]=9;function ye(e,t,r){if(e.length-t<r)throw new Error(`${F} not enough data for type`)}var lt=[24,256,65536,4294967296,BigInt("18446744073709551616")];function Rt(e,t,r){ye(e,t,1);let n=e[t];if(r.strict===!0&&n<lt[0])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Pt(e,t,r){ye(e,t,2);let n=e[t]<<8|e[t+1];if(r.strict===!0&&n<lt[1])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Nt(e,t,r){ye(e,t,4);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3];if(r.strict===!0&&n<lt[2])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);return n}function Lt(e,t,r){ye(e,t,8);let n=e[t]*16777216+(e[t+1]<<16)+(e[t+2]<<8)+e[t+3],o=e[t+4]*16777216+(e[t+5]<<16)+(e[t+6]<<8)+e[t+7],i=(BigInt(n)<<BigInt(32))+BigInt(o);if(r.strict===!0&&i<lt[3])throw new Error(`${F} integer encoded in more bytes than necessary (strict decode)`);if(i<=Number.MAX_SAFE_INTEGER)return Number(i);if(r.allowBigInt===!0)return i;throw new Error(`${F} integers outside of the safe integer range are not supported`)}function bu(e,t,r,n){return new P(h.uint,Rt(e,t+1,n),2)}function xu(e,t,r,n){return new P(h.uint,Pt(e,t+1,n),3)}function wu(e,t,r,n){return new P(h.uint,Nt(e,t+1,n),5)}function Eu(e,t,r,n){return new P(h.uint,Lt(e,t+1,n),9)}function kt(e,t){return dt(e,0,t.value)}function dt(e,t,r){if(r<lt[0]){let n=Number(r);e.push([t|n])}else if(r<lt[1]){let n=Number(r);e.push([t|24,n])}else if(r<lt[2]){let n=Number(r);e.push([t|25,n>>>8,n&255])}else if(r<lt[3]){let n=Number(r);e.push([t|26,n>>>24&255,n>>>16&255,n>>>8&255,n&255])}else{let n=BigInt(r);if(n<lt[4]){let o=[t|27,0,0,0,0,0,0,0],i=Number(n&BigInt(4294967295)),s=Number(n>>BigInt(32)&BigInt(4294967295));o[8]=i&255,i=i>>8,o[7]=i&255,i=i>>8,o[6]=i&255,i=i>>8,o[5]=i&255,o[4]=s&255,s=s>>8,o[3]=s&255,s=s>>8,o[2]=s&255,s=s>>8,o[1]=s&255,e.push(o)}else throw new Error(`${F} encountered BigInt larger than allowable range`)}}kt.encodedSize=function(t){return dt.encodedSize(t.value)};dt.encodedSize=function(t){return t<lt[0]?1:t<lt[1]?2:t<lt[2]?3:t<lt[3]?5:9};kt.compareTokens=function(t,r){return t.value<r.value?-1:t.value>r.value?1:0};function Su(e,t,r,n){return new P(h.negint,-1-Rt(e,t+1,n),2)}function vu(e,t,r,n){return new P(h.negint,-1-Pt(e,t+1,n),3)}function Au(e,t,r,n){return new P(h.negint,-1-Nt(e,t+1,n),5)}var vs=BigInt(-1),Iu=BigInt(1);function Tu(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o!="bigint"){let i=-1-o;if(i>=Number.MIN_SAFE_INTEGER)return new P(h.negint,i,9)}if(n.allowBigInt!==!0)throw new Error(`${F} integers outside of the safe integer range are not supported`);return new P(h.negint,vs-BigInt(o),9)}function no(e,t){let r=t.value,n=typeof r=="bigint"?r*vs-Iu:r*-1-1;dt(e,t.type.majorEncoded,n)}no.encodedSize=function(t){let r=t.value,n=typeof r=="bigint"?r*vs-Iu:r*-1-1;return n<lt[0]?1:n<lt[1]?2:n<lt[2]?3:n<lt[3]?5:9};no.compareTokens=function(t,r){return t.value<r.value?1:t.value>r.value?-1:0};function nn(e,t,r,n){ye(e,t,r+n);let o=e.slice(t+r,t+r+n);return new P(h.bytes,o,r+n)}function Cu(e,t,r,n){return nn(e,t,1,r)}function Bu(e,t,r,n){return nn(e,t,2,Rt(e,t+1,n))}function _u(e,t,r,n){return nn(e,t,3,Pt(e,t+1,n))}function Du(e,t,r,n){return nn(e,t,5,Nt(e,t+1,n))}function Ru(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer bytes lengths not supported`);return nn(e,t,9,o)}function oo(e){return e.encodedBytes===void 0&&(e.encodedBytes=h.equals(e.type,h.string)?Es(e.value):e.value),e.encodedBytes}function Er(e,t){let r=oo(t);dt(e,t.type.majorEncoded,r.length),e.push(r)}Er.encodedSize=function(t){let r=oo(t);return dt.encodedSize(r.length)+r.length};Er.compareTokens=function(t,r){return Vp(oo(t),oo(r))};function Vp(e,t){return e.length<t.length?-1:e.length>t.length?1:eo(e,t)}var Pu=new TextDecoder,$p=32;function qp(e,t,r){if(r-t<$p){let o="";for(let i=t;i<r;i++){let s=e[i];if(s&128)return Pu.decode(e.subarray(t,r));o+=String.fromCharCode(s)}return o}return Pu.decode(e.subarray(t,r))}function on(e,t,r,n,o){let i=r+n;ye(e,t,i);let s=new P(h.string,qp(e,t+r,t+i),i);return o.retainStringBytes===!0&&(s.byteValue=e.slice(t+r,t+i)),s}function Nu(e,t,r,n){return on(e,t,1,r,n)}function Lu(e,t,r,n){return on(e,t,2,Rt(e,t+1,n),n)}function Uu(e,t,r,n){return on(e,t,3,Pt(e,t+1,n),n)}function Ou(e,t,r,n){return on(e,t,5,Nt(e,t+1,n),n)}function ku(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer string lengths not supported`);return on(e,t,9,o,n)}var Ku=Er;function Sr(e,t,r,n){return new P(h.array,n,r)}function Mu(e,t,r,n){return Sr(e,t,1,r)}function Vu(e,t,r,n){return Sr(e,t,2,Rt(e,t+1,n))}function Fu(e,t,r,n){return Sr(e,t,3,Pt(e,t+1,n))}function $u(e,t,r,n){return Sr(e,t,5,Nt(e,t+1,n))}function qu(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer array lengths not supported`);return Sr(e,t,9,o)}function Hu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return Sr(e,t,1,1/0)}function io(e,t){dt(e,h.array.majorEncoded,t.value)}io.compareTokens=kt.compareTokens;io.encodedSize=function(t){return dt.encodedSize(t.value)};function vr(e,t,r,n){return new P(h.map,n,r)}function zu(e,t,r,n){return vr(e,t,1,r)}function ju(e,t,r,n){return vr(e,t,2,Rt(e,t+1,n))}function Gu(e,t,r,n){return vr(e,t,3,Pt(e,t+1,n))}function Zu(e,t,r,n){return vr(e,t,5,Nt(e,t+1,n))}function Yu(e,t,r,n){let o=Lt(e,t+1,n);if(typeof o=="bigint")throw new Error(`${F} 64-bit integer map lengths not supported`);return vr(e,t,9,o)}function Wu(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return vr(e,t,1,1/0)}function so(e,t){dt(e,h.map.majorEncoded,t.value)}so.compareTokens=kt.compareTokens;so.encodedSize=function(t){return dt.encodedSize(t.value)};function Xu(e,t,r,n){return new P(h.tag,r,1)}function Ju(e,t,r,n){return new P(h.tag,Rt(e,t+1,n),2)}function Qu(e,t,r,n){return new P(h.tag,Pt(e,t+1,n),3)}function tf(e,t,r,n){return new P(h.tag,Nt(e,t+1,n),5)}function ef(e,t,r,n){return new P(h.tag,Lt(e,t+1,n),9)}function ao(e,t){dt(e,h.tag.majorEncoded,t.value)}ao.compareTokens=kt.compareTokens;ao.encodedSize=function(t){return dt.encodedSize(t.value)};var As=20,Is=21,Ts=22,Cs=23;function rf(e,t,r,n){if(n.allowUndefined===!1)throw new Error(`${F} undefined values are not supported`);return n.coerceUndefinedToNull===!0?new P(h.null,null,1):new P(h.undefined,void 0,1)}function nf(e,t,r,n){if(n.allowIndefinite===!1)throw new Error(`${F} indefinite length items not allowed`);return new P(h.break,void 0,1)}function Bs(e,t,r){if(r){if(r.allowNaN===!1&&Number.isNaN(e))throw new Error(`${F} NaN values are not supported`);if(r.allowInfinity===!1&&(e===1/0||e===-1/0))throw new Error(`${F} Infinity values are not supported`)}return new P(h.float,e,t)}function of(e,t,r,n){return Bs(_s(e,t+1),3,n)}function sf(e,t,r,n){return Bs(Ds(e,t+1),5,n)}function af(e,t,r,n){return Bs(lf(e,t+1),9,n)}function co(e,t,r){let n=t.value;if(n===!1)e.push([h.float.majorEncoded|As]);else if(n===!0)e.push([h.float.majorEncoded|Is]);else if(n===null)e.push([h.float.majorEncoded|Ts]);else if(n===void 0)e.push([h.float.majorEncoded|Cs]);else{let o,i=!1;(!r||r.float64!==!0)&&(uf(n),o=_s(jt,1),n===o||Number.isNaN(n)?(jt[0]=249,e.push(jt.slice(0,3)),i=!0):(ff(n),o=Ds(jt,1),n===o&&(jt[0]=250,e.push(jt.slice(0,5)),i=!0))),i||(Zp(n),o=lf(jt,1),jt[0]=251,e.push(jt.slice(0,9)))}}co.encodedSize=function(t,r){let n=t.value;if(n===!1||n===!0||n===null||n===void 0)return 1;if(!r||r.float64!==!0){uf(n);let o=_s(jt,1);if(n===o||Number.isNaN(n))return 3;if(ff(n),o=Ds(jt,1),n===o)return 5}return 9};var cf=new ArrayBuffer(9),Kt=new DataView(cf,1),jt=new Uint8Array(cf,0);function uf(e){if(e===1/0)Kt.setUint16(0,31744,!1);else if(e===-1/0)Kt.setUint16(0,64512,!1);else if(Number.isNaN(e))Kt.setUint16(0,32256,!1);else{Kt.setFloat32(0,e);let t=Kt.getUint32(0),r=(t&2139095040)>>23,n=t&8388607;if(r===255)Kt.setUint16(0,31744,!1);else if(r===0)Kt.setUint16(0,(e&2147483648)>>16|n>>13,!1);else{let o=r-127;o<-24?Kt.setUint16(0,0):o<-14?Kt.setUint16(0,(t&2147483648)>>16|1<<24+o,!1):Kt.setUint16(0,(t&2147483648)>>16|o+15<<10|n>>13,!1)}}}function _s(e,t){if(e.length-t<2)throw new Error(`${F} not enough data for float16`);let r=(e[t]<<8)+e[t+1];if(r===31744)return 1/0;if(r===64512)return-1/0;if(r===32256)return NaN;let n=r>>10&31,o=r&1023,i;return n===0?i=o*2**-24:n!==31?i=(o+1024)*2**(n-25):i=o===0?1/0:NaN,r&32768?-i:i}function ff(e){Kt.setFloat32(0,e,!1)}function Ds(e,t){if(e.length-t<4)throw new Error(`${F} not enough data for float32`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,4).getFloat32(0,!1)}function Zp(e){Kt.setFloat64(0,e,!1)}function lf(e,t){if(e.length-t<8)throw new Error(`${F} not enough data for float64`);let r=(e.byteOffset||0)+t;return new DataView(e.buffer,r,8).getFloat64(0,!1)}co.compareTokens=kt.compareTokens;function Z(e,t,r){throw new Error(`${F} encountered invalid minor (${r}) for major ${e[t]>>>5}`)}function uo(e){return()=>{throw new Error(`${F} ${e}`)}}var B=[];for(let e=0;e<=23;e++)B[e]=Z;B[24]=bu;B[25]=xu;B[26]=wu;B[27]=Eu;B[28]=Z;B[29]=Z;B[30]=Z;B[31]=Z;for(let e=32;e<=55;e++)B[e]=Z;B[56]=Su;B[57]=vu;B[58]=Au;B[59]=Tu;B[60]=Z;B[61]=Z;B[62]=Z;B[63]=Z;for(let e=64;e<=87;e++)B[e]=Cu;B[88]=Bu;B[89]=_u;B[90]=Du;B[91]=Ru;B[92]=Z;B[93]=Z;B[94]=Z;B[95]=uo("indefinite length bytes/strings are not supported");for(let e=96;e<=119;e++)B[e]=Nu;B[120]=Lu;B[121]=Uu;B[122]=Ou;B[123]=ku;B[124]=Z;B[125]=Z;B[126]=Z;B[127]=uo("indefinite length bytes/strings are not supported");for(let e=128;e<=151;e++)B[e]=Mu;B[152]=Vu;B[153]=Fu;B[154]=$u;B[155]=qu;B[156]=Z;B[157]=Z;B[158]=Z;B[159]=Hu;for(let e=160;e<=183;e++)B[e]=zu;B[184]=ju;B[185]=Gu;B[186]=Zu;B[187]=Yu;B[188]=Z;B[189]=Z;B[190]=Z;B[191]=Wu;for(let e=192;e<=215;e++)B[e]=Xu;B[216]=Ju;B[217]=Qu;B[218]=tf;B[219]=ef;B[220]=Z;B[221]=Z;B[222]=Z;B[223]=Z;for(let e=224;e<=243;e++)B[e]=uo("simple values are not supported");B[244]=Z;B[245]=Z;B[246]=Z;B[247]=rf;B[248]=uo("simple values are not supported");B[249]=of;B[250]=sf;B[251]=af;B[252]=Z;B[253]=Z;B[254]=Z;B[255]=nf;var Gt=[];for(let e=0;e<24;e++)Gt[e]=new P(h.uint,e,1);for(let e=-1;e>=-24;e--)Gt[31-e]=new P(h.negint,e,1);Gt[64]=new P(h.bytes,new Uint8Array(0),1);Gt[96]=new P(h.string,"",1);Gt[128]=new P(h.array,0,1);Gt[160]=new P(h.map,0,1);Gt[244]=new P(h.false,!1,1);Gt[245]=new P(h.true,!0,1);Gt[246]=new P(h.null,null,1);function df(e){switch(e.type){case h.false:return re([244]);case h.true:return re([245]);case h.null:return re([246]);case h.bytes:return e.value.length?void 0:re([64]);case h.string:return e.value===""?re([96]):void 0;case h.array:return e.value===0?re([128]):void 0;case h.map:return e.value===0?re([160]):void 0;case h.uint:return e.value<24?re([Number(e.value)]):void 0;case h.negint:if(e.value>=-24)return re([31-Number(e.value)])}}var pf=Object.freeze({float64:!0,mapSorter:t0,quickEncodeToken:df});function Wp(){let e=[];return e[h.uint.major]=kt,e[h.negint.major]=no,e[h.bytes.major]=Er,e[h.string.major]=Ku,e[h.array.major]=io,e[h.map.major]=so,e[h.tag.major]=ao,e[h.float.major]=co,e}var Xp=Wp(),Jp=new en,lo=class e{constructor(t,r){this.obj=t,this.parent=r}includes(t){let r=this;do if(r.obj===t)return!0;while(r=r.parent);return!1}static createCheck(t,r){if(t&&t.includes(r))throw new Error(`${Ss} object contains circular references`);return new e(r,t)}},Be={null:new P(h.null,null),undefined:new P(h.undefined,void 0),true:new P(h.true,!0),false:new P(h.false,!1),emptyArray:new P(h.array,0),emptyMap:new P(h.map,0)},_e={number(e,t,r,n){return!Number.isInteger(e)||!Number.isSafeInteger(e)?new P(h.float,e):e>=0?new P(h.uint,e):new P(h.negint,e)},bigint(e,t,r,n){return e>=BigInt(0)?new P(h.uint,e):new P(h.negint,e)},Uint8Array(e,t,r,n){return new P(h.bytes,e)},string(e,t,r,n){return new P(h.string,e)},boolean(e,t,r,n){return e?Be.true:Be.false},null(e,t,r,n){return Be.null},undefined(e,t,r,n){return Be.undefined},ArrayBuffer(e,t,r,n){return new P(h.bytes,new Uint8Array(e))},DataView(e,t,r,n){return new P(h.bytes,new Uint8Array(e.buffer,e.byteOffset,e.byteLength))},Array(e,t,r,n){if(!e.length)return r.addBreakTokens===!0?[Be.emptyArray,new P(h.break)]:Be.emptyArray;n=lo.createCheck(n,e);let o=[],i=0;for(let s of e)o[i++]=fo(s,r,n);return r.addBreakTokens?[new P(h.array,e.length),o,new P(h.break)]:[new P(h.array,e.length),o]},Object(e,t,r,n){let o=t!=="Object",i=o?e.keys():Object.keys(e),s=o?e.size:i.length,c;if(s){c=new Array(s),n=lo.createCheck(n,e);let a=!o&&r.ignoreUndefinedProperties,l=0;for(let u of i){let f=o?e.get(u):e[u];a&&f===void 0||(c[l++]=[fo(u,r,n),fo(f,r,n)])}l<s&&(c.length=l)}return c?.length?(Qp(c,r),r.addBreakTokens?[new P(h.map,c.length),c,new P(h.break)]:[new P(h.map,c.length),c]):r.addBreakTokens===!0?[Be.emptyMap,new P(h.break)]:Be.emptyMap}};_e.Map=_e.Object;_e.Buffer=_e.Uint8Array;for(let e of"Uint8Clamped Uint16 Uint32 Int8 Int16 Int32 BigUint64 BigInt64 Float32 Float64".split(" "))_e[`${e}Array`]=_e.DataView;function fo(e,t={},r){let n=hu(e),o=t&&t.typeEncoders&&t.typeEncoders[n]||_e[n];if(typeof o=="function"){let s=o(e,n,t,r);if(s!=null)return s}let i=_e[n];if(!i)throw new Error(`${Ss} unsupported type: ${n}`);return i(e,n,t,r)}function Qp(e,t){t.mapSorter&&e.sort(t.mapSorter)}function t0(e,t){if(e[0]instanceof P&&t[0]instanceof P){let r=e[0],n=t[0];return r._keyBytes||(r._keyBytes=hf(r.value)),n._keyBytes||(n._keyBytes=hf(n.value)),eo(r._keyBytes,n._keyBytes)}throw new Error("rfc8949MapSorter: complex key types are not supported yet")}function hf(e){return e0(e,Xp,pf)}function mf(e,t,r,n){if(Array.isArray(t))for(let o of t)mf(e,o,r,n);else r[t.type.major](e,t,n)}var S1=h.uint.majorEncoded,v1=h.negint.majorEncoded,A1=h.bytes.majorEncoded,I1=h.string.majorEncoded,T1=h.array.majorEncoded,C1=h.float.majorEncoded|As,B1=h.float.majorEncoded|Is,_1=h.float.majorEncoded|Ts,D1=h.float.majorEncoded|Cs,R1=BigInt(-1),P1=BigInt(1);function e0(e,t,r,n){let o=n instanceof Uint8Array,i=o?new ro(n):Jp,s=fo(e,r);if(!Array.isArray(s)&&r.quickEncodeToken){let c=r.quickEncodeToken(s);if(c)return o?(i.push(c),i.toBytes()):c;let a=t[s.type.major];if(a.encodedSize){let l=a.encodedSize(s,r);if(o||(i=new en(l)),a(i,s,r),i.chunks.length!==1)throw new Error(`Unexpected error: pre-calculated length for ${s} was wrong`);return o?i.toBytes():tn(i.chunks[0])}}return i.reset(),mf(i,s,t,r),i.toBytes(!0)}var r0={strict:!1,allowIndefinite:!0,allowUndefined:!0,allowBigInt:!0},ho=class{constructor(t,r={}){this._pos=0,this.data=t,this.options=r}pos(){return this._pos}done(){return this._pos>=this.data.length}next(){let t=this.data[this._pos],r=Gt[t];if(r===void 0){let n=B[t];if(!n)throw new Error(`${F} no decoder for major type ${t>>>5} (byte 0x${t.toString(16).padStart(2,"0")})`);let o=t&31;r=n(this.data,this._pos,o,this.options)}return this._pos+=r.encodedLength,r}},sn=Symbol.for("DONE"),po=Symbol.for("BREAK");function n0(e,t,r){let n=[];for(let o=0;o<e.value;o++){let i=Ar(t,r);if(i===po){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed array`)}if(i===sn)throw new Error(`${F} found array but not enough entries (got ${o}, expected ${e.value})`);n[o]=i}return n}function o0(e,t,r){let n=r.useMaps===!0,o=r.rejectDuplicateMapKeys===!0,i=n?void 0:{},s=n?new Map:void 0;for(let c=0;c<e.value;c++){let a=Ar(t,r);if(a===po){if(e.value===1/0)break;throw new Error(`${F} got unexpected break to lengthed map`)}if(a===sn)throw new Error(`${F} found map but not enough entries (got ${c} [no key], expected ${e.value})`);if(!n&&typeof a!="string")throw new Error(`${F} non-string keys not supported (got ${typeof a})`);if(o&&(n&&s.has(a)||!n&&Object.hasOwn(i,a)))throw new Error(`${F} found repeat map key "${a}"`);let l=Ar(t,r);if(l===sn)throw new Error(`${F} found map but not enough entries (got ${c} [no value], expected ${e.value})`);n?s.set(a,l):i[a]=l}return n?s:i}function Ar(e,t){if(e.done())return sn;let r=e.next();if(h.equals(r.type,h.break))return po;if(r.type.terminal)return r.value;if(h.equals(r.type,h.array))return n0(r,e,t);if(h.equals(r.type,h.map))return o0(r,e,t);if(h.equals(r.type,h.tag)){if(t.tags&&typeof t.tags[r.value]=="function"){let n=Ar(e,t);return t.tags[r.value](n)}throw new Error(`${F} tag not supported (${r.value})`)}throw new Error("unsupported")}function yf(e,t){if(!(e instanceof Uint8Array))throw new Error(`${F} data to decode must be a Uint8Array`);t=Object.assign({},r0,t);let r=tn(e),n=t.tokenizer||new ho(r,t),o=Ar(n,t);if(o===sn)throw new Error(`${F} did not find any content to decode`);if(o===po)throw new Error(`${F} got unexpected break`);return[o,e.subarray(n.pos())]}function Rs(e,t){let[r,n]=yf(e,t);if(n.length>0)throw new Error(`${F} too many terminals, data makes no sense`);return r}var a0=qe("ipns:utils"),gf=H("/ipns/");var c0=0,u0=18;function bf(e){let t;if(e.pubKey!=null)try{t=qc(e.pubKey)}catch(r){throw a0.error(r),r}if(t!=null)return t}function xf(e){let t=H("ipns-signature:");return Ut([t,e])}function ze(e){return"signatureV1"in e?zt.encode({value:H(e.value),signatureV1:e.signatureV1,validityType:e.validityType,validity:H(e.validity),sequence:e.sequence,ttl:e.ttl,pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data}):zt.encode({pubKey:e.pubKey,signatureV2:e.signatureV2,data:e.data})}function ne(e){let t=zt.decode(e);if(t.sequence!=null&&(t.sequence=BigInt(t.sequence)),t.ttl!=null&&(t.ttl=BigInt(t.ttl)),t.signatureV2==null||t.data==null)throw new Ht("Missing data or signatureV2");let r=wf(t.data),n=f0(r.Value),o=z(r.Validity);if(t.value!=null&&t.signatureV1!=null)return l0(t),{value:n,validityType:zt.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV1:t.signatureV1,signatureV2:t.signatureV2,data:t.data};if(t.signatureV2!=null)return{value:n,validityType:zt.ValidityType.EOL,validity:o,sequence:r.Sequence,ttl:r.TTL,pubKey:t.pubKey,signatureV2:t.signatureV2,data:t.data};throw new Error("invalid record: does not include signatureV1 or signatureV2")}function an(e){return Ut([gf,e.bytes])}function ge(e){let t=xe(e.slice(gf.length));if(!mo(t,c0)&&!mo(t,u0))throw new Ze("Multihash in IPNS key was not identity or sha2-256");return t}function wf(e){let t=Rs(e);if(t.ValidityType===0)t.ValidityType=zt.ValidityType.EOL;else throw new wr("The validity type is unsupported");return Number.isInteger(t.Sequence)&&(t.Sequence=BigInt(t.Sequence)),Number.isInteger(t.TTL)&&(t.TTL=BigInt(t.TTL)),t}function f0(e){let t=z(e).trim();if(t.startsWith("/"))return t;try{return`/ipfs/${j.decode(e).toV1().toString()}`}catch{}try{return`/ipfs/${j.parse(t).toV1().toString()}`}catch{}throw new Jn("Value must be a valid content path starting with /")}function l0(e){if(e.data==null)throw new Qn("Record data is missing");let t=wf(e.data);if(!Y(t.Value,e.value??new Uint8Array(0)))throw new Ht('Field "value" did not match between protobuf and CBOR');if(!Y(t.Validity,e.validity??new Uint8Array(0)))throw new Ht('Field "validity" did not match between protobuf and CBOR');if(t.ValidityType!==e.validityType)throw new Ht('Field "validityType" did not match between protobuf and CBOR');if(t.Sequence!==e.sequence)throw new Ht('Field "sequence" did not match between protobuf and CBOR');if(t.TTL!==e.ttl)throw new Ht('Field "ttl" did not match between protobuf and CBOR')}function mo(e,t){return e.code===t}var n2=qe("ipns"),o2=300*1e9,h0="/ipns/",i2=h0.length;var Ef=Co(ws(),1);var yo=qe("ipns:validator"),p0=1024*10;async function m0(e,t){let r=ne(t),n;try{let o=xf(r.data);n=await e.verify(o,r.signatureV2)}catch{n=!1}if(!n)throw yo.error("record signature verification failed"),new Ht("Record signature verification failed");if(r.validityType===zt.ValidityType.EOL){if(Ef.default.fromString(r.validity).toDate().getTime()<Date.now())throw yo.error("record has expired"),new Wn("record has expired")}else if(r.validityType!=null)throw yo.error("the validity type is unsupported"),new wr("The validity type is unsupported");yo("ipns record for %s is valid",r.value)}async function Sf(e,t){if(t.byteLength>p0)throw new Xn("The record is too large");let r=ge(e),n;mo(r,0)&&(n=On(r));let o=ne(t),i=bf(o)??n;if(i==null)throw new Jr("Could not extract public key from IPNS record or routing key");let s=an(i.toMultihash());if(!Y(s,e))throw new Jr("Embedded public key did not match routing key");await m0(i,t)}var go=class extends Error{name="InvalidMessageLengthError";code="ERR_INVALID_MESSAGE_LENGTH"};async function*Ir(e,t={}){let r=/\r?\n/,n=new TextDecoder("utf8"),o="";for await(let i of e){if(typeof i=="string"&&(i=new TextEncoder().encode(i)),tr(i)&&(i=i.subarray()),o+=n.decode(i,{stream:!0}),o.length>(t?.maxMessageLength??o.length))throw new go("Incoming message too long");let s=o.split(r);o=s.pop()??"";for(let c=0;c<s.length;c++)yield JSON.parse(s[c])}o+=n.decode(),o!==""&&(yield JSON.parse(o))}function Mt(){let e={};return e.promise=new Promise((t,r)=>{e.resolve=t,e.reject=r}),e}var Ns=Co(Af(),1);var Ls=class e extends Error{name="TimeoutError";constructor(t,r){super(t,r),Error.captureStackTrace?.(this,e)}},If=e=>e.reason??new DOMException("This operation was aborted.","AbortError");function Us(e,t){let{milliseconds:r,fallback:n,message:o,customTimers:i={setTimeout,clearTimeout},signal:s}=t,c,a,u=new Promise((f,g)=>{if(typeof r!="number"||Math.sign(r)!==1)throw new TypeError(`Expected \`milliseconds\` to be a positive number, got \`${r}\``);if(s?.aborted){g(If(s));return}if(s&&(a=()=>{g(If(s))},s.addEventListener("abort",a,{once:!0})),e.then(f,g),r===Number.POSITIVE_INFINITY)return;let E=new Ls;c=i.setTimeout.call(void 0,()=>{if(n){try{f(n())}catch(x){g(x)}return}typeof e.cancel=="function"&&e.cancel(),o===!1?f():o instanceof Error?g(o):(E.message=o??`Promise timed out after ${r} milliseconds`,g(E))},r)}).finally(()=>{u.clear(),a&&s&&s.removeEventListener("abort",a)});return u.clear=()=>{i.clearTimeout.call(void 0,c),c=void 0},u}function Os(e,t,r){let n=0,o=e.length;for(;o>0;){let i=Math.trunc(o/2),s=n+i;r(e[s],t)<=0?(n=++s,o-=i+1):o=i}return n}var un=class{#t=[];enqueue(t,r){let{priority:n=0,id:o}=r??{},i={priority:n,id:o,run:t};if(this.size===0||this.#t[this.size-1].priority>=n){this.#t.push(i);return}let s=Os(this.#t,i,(c,a)=>a.priority-c.priority);this.#t.splice(s,0,i)}setPriority(t,r){let n=this.#t.findIndex(i=>i.id===t);if(n===-1)throw new ReferenceError(`No promise function with the id "${t}" exists in the queue.`);let[o]=this.#t.splice(n,1);this.enqueue(o.run,{priority:r,id:t})}dequeue(){return this.#t.shift()?.run}filter(t){return this.#t.filter(r=>r.priority===t.priority).map(r=>r.run)}get size(){return this.#t.length}};var fn=class extends Ns.default{#t;#n;#e=0;#h;#m=!1;#b=!1;#c;#T=0;#x=0;#u;#f;#a;#s=[];#i=0;#r;#C;#o=0;#y;#l;#P=1n;#g=new Map;timeout;constructor(t){if(super(),t={carryoverIntervalCount:!1,intervalCap:Number.POSITIVE_INFINITY,interval:0,concurrency:Number.POSITIVE_INFINITY,autoStart:!0,queueClass:un,strict:!1,...t},!(typeof t.intervalCap=="number"&&t.intervalCap>=1))throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${t.intervalCap?.toString()??""}\` (${typeof t.intervalCap})`);if(t.interval===void 0||!(Number.isFinite(t.interval)&&t.interval>=0))throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${t.interval?.toString()??""}\` (${typeof t.interval})`);if(t.strict&&t.interval===0)throw new TypeError("The `strict` option requires a non-zero `interval`");if(t.strict&&t.intervalCap===Number.POSITIVE_INFINITY)throw new TypeError("The `strict` option requires a finite `intervalCap`");if(this.#t=t.carryoverIntervalCount??t.carryoverConcurrencyCount??!1,this.#n=t.intervalCap===Number.POSITIVE_INFINITY||t.interval===0,this.#h=t.intervalCap,this.#c=t.interval,this.#a=t.strict,this.#r=new t.queueClass,this.#C=t.queueClass,this.concurrency=t.concurrency,t.timeout!==void 0&&!(Number.isFinite(t.timeout)&&t.timeout>0))throw new TypeError(`Expected \`timeout\` to be a positive finite number, got \`${t.timeout}\` (${typeof t.timeout})`);this.timeout=t.timeout,this.#l=t.autoStart===!1,this.#V()}#w(t){for(;this.#i<this.#s.length;){let n=this.#s[this.#i];if(n!==void 0&&t-n>=this.#c)this.#i++;else break}(this.#i>100&&this.#i>this.#s.length/2||this.#i===this.#s.length)&&(this.#s=this.#s.slice(this.#i),this.#i=0)}#N(t){this.#a?this.#s.push(t):this.#e++}#L(){this.#a?this.#s.length>this.#i&&this.#s.pop():this.#e>0&&this.#e--}#E(){return this.#s.length-this.#i}get#U(){return this.#n?!0:this.#a?this.#E()<this.#h:this.#e<this.#h}get#O(){return this.#o<this.#y}#k(){this.#o--,this.#o===0&&this.emit("pendingZero"),this.#A(),this.emit("next")}#K(){this.#f=void 0,this.#D(),this.#_()}#M(t){if(this.#a){if(this.#w(t),this.#E()>=this.#h){let n=this.#s[this.#i],o=this.#c-(t-n);return this.#S(o),!0}return!1}if(this.#u===void 0){let r=this.#T-t;if(r<0){if(this.#x>0){let n=t-this.#x;if(n<this.#c)return this.#S(this.#c-n),!0}this.#e=this.#t?this.#o:0}else return this.#S(r),!0}return!1}#S(t){this.#f===void 0&&(this.#f=setTimeout(()=>{this.#K()},t))}#v(){this.#u&&(clearInterval(this.#u),this.#u=void 0)}#B(){this.#f&&(clearTimeout(this.#f),this.#f=void 0)}#A(){if(this.#r.size===0){if(this.#v(),this.emit("empty"),this.#o===0){if(this.#B(),this.#a&&this.#i>0){let r=Date.now();this.#w(r)}this.emit("idle")}return!1}let t=!1;if(!this.#l){let r=Date.now(),n=!this.#M(r);if(this.#U&&this.#O){let o=this.#r.dequeue();this.#n||(this.#N(r),this.#p()),this.emit("active"),o(),n&&this.#_(),t=!0}}return t}#_(){this.#n||this.#u!==void 0||this.#a||(this.#u=setInterval(()=>{this.#D()},this.#c),this.#T=Date.now()+this.#c)}#D(){this.#a||(this.#e===0&&this.#o===0&&this.#u&&this.#v(),this.#e=this.#t?this.#o:0),this.#I(),this.#p()}#I(){for(;this.#A(););}get concurrency(){return this.#y}set concurrency(t){if(!(typeof t=="number"&&t>=1))throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${t}\` (${typeof t})`);this.#y=t,this.#I()}setPriority(t,r){if(typeof r!="number"||!Number.isFinite(r))throw new TypeError(`Expected \`priority\` to be a finite number, got \`${r}\` (${typeof r})`);this.#r.setPriority(t,r)}async add(t,r={}){return r={timeout:this.timeout,...r,id:r.id??(this.#P++).toString()},new Promise((n,o)=>{let i=Symbol(`task-${r.id}`);this.#r.enqueue(async()=>{this.#o++,this.#g.set(i,{id:r.id,priority:r.priority??0,startTime:Date.now(),timeout:r.timeout});let s;try{try{r.signal?.throwIfAborted()}catch(l){throw this.#F(),this.#g.delete(i),l}this.#x=Date.now();let c=t({signal:r.signal});if(r.timeout&&(c=Us(Promise.resolve(c),{milliseconds:r.timeout,message:`Task timed out after ${r.timeout}ms (queue has ${this.#o} running, ${this.#r.size} waiting)`})),r.signal){let{signal:l}=r;c=Promise.race([c,new Promise((u,f)=>{s=()=>{f(l.reason)},l.addEventListener("abort",s,{once:!0})})])}let a=await c;n(a),this.emit("completed",a)}catch(c){o(c),this.emit("error",c)}finally{s&&r.signal?.removeEventListener("abort",s),this.#g.delete(i),queueMicrotask(()=>{this.#k()})}},r),this.emit("add"),this.#A()})}async addAll(t,r){return Promise.all(t.map(async n=>this.add(n,r)))}start(){return this.#l?(this.#l=!1,this.#I(),this):this}pause(){this.#l=!0}clear(){this.#r=new this.#C,this.#v(),this.#R(),this.emit("empty"),this.#o===0&&(this.#B(),this.emit("idle")),this.emit("next")}async onEmpty(){this.#r.size!==0&&await this.#d("empty")}async onSizeLessThan(t){this.#r.size<t||await this.#d("next",()=>this.#r.size<t)}async onIdle(){this.#o===0&&this.#r.size===0||await this.#d("idle")}async onPendingZero(){this.#o!==0&&await this.#d("pendingZero")}async onRateLimit(){this.isRateLimited||await this.#d("rateLimit")}async onRateLimitCleared(){this.isRateLimited&&await this.#d("rateLimitCleared")}onError(){return new Promise((t,r)=>{let n=o=>{this.off("error",n),r(o)};this.on("error",n)})}async#d(t,r){return new Promise(n=>{let o=()=>{r&&!r()||(this.off(t,o),n())};this.on(t,o)})}get size(){return this.#r.size}sizeBy(t){return this.#r.filter(t).length}get pending(){return this.#o}get isPaused(){return this.#l}#V(){this.#n||(this.on("add",()=>{this.#r.size>0&&this.#p()}),this.on("next",()=>{this.#p()}))}#p(){this.#n||this.#b||(this.#b=!0,queueMicrotask(()=>{this.#b=!1,this.#R()}))}#F(){this.#n||(this.#L(),this.#p())}#R(){let t=this.#m;if(this.#n||this.#r.size===0){t&&(this.#m=!1,this.emit("rateLimitCleared"));return}let r;if(this.#a){let o=Date.now();this.#w(o),r=this.#E()}else r=this.#e;let n=r>=this.#h;n!==t&&(this.#m=n,this.emit(n?"rateLimit":"rateLimitCleared"))}get isRateLimited(){return this.#m}get isSaturated(){return this.#o===this.#y&&this.#r.size>0||this.isRateLimited&&this.#r.size>0}get runningTasks(){return[...this.#g.values()].map(t=>({...t}))}};var je=class extends Error{static name="InvalidRequestError";constructor(t="Invalid request"){super(t),this.name="InvalidRequestError"}},Vt=class extends Error{static name="BadResponseError";constructor(t="Bad response"){super(t),this.name="BadResponseError"}};function b0(e){return e[Symbol.asyncIterator]!=null}function x0(e){if(b0(e))return(async()=>{for await(let t of e)return t})();for(let t of e)return t}var xo=x0;function w0(e){let[t,r]=e[Symbol.asyncIterator]!=null?[e[Symbol.asyncIterator](),Symbol.asyncIterator]:[e[Symbol.iterator](),Symbol.iterator],n=[];return{peek:()=>t.next(),push:o=>{n.push(o)},next:()=>n.length>0?{done:!1,value:n.shift()}:t.next(),[r](){return this}}}var Tf=w0;function E0(e){return e[Symbol.asyncIterator]!=null}function S0(e,t){let r=0;if(E0(e))return(async function*(){for await(let a of e)yield t(a,r++)})();let n=Tf(e),{value:o,done:i}=n.next();if(i===!0)return(function*(){})();let s=t(o,r++);if(typeof s.then=="function")return(async function*(){yield await s;for(let a of n)yield t(a,r++)})();let c=t;return(function*(){yield s;for(let a of n)yield c(a,r++)})()}var wo=S0;var Cf=H("/ipns/");function Bf(e){return Y(e.subarray(0,Cf.byteLength),Cf)}var Eo=class{client;constructor(t){this.client=t}async*findProviders(t,r={}){try{yield*wo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs??[],routing:"delegated-http-routing-v1"}))}catch(n){if(n instanceof At)return;throw n}}async provide(){}async cancelReprovide(){}async put(t,r,n){if(!Bf(t))return;let o=ge(t),i=j.createV1(114,o),s=ne(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!Bf(t))throw new At("Not found");let n=ge(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return ze(i)}catch(i){throw i.name==="BadResponseError"?new At("Not found"):i}}toString(){return`DelegatedRoutingV1HttpApiClientContentRouting(${this.client.url})`}},So=class{client;constructor(t){this.client=t}async findPeer(t,r={}){let n=await xo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new At("Not found")}async*getClosestPeers(t,r={}){let n;try{n=j.decode(t)}catch{try{n=Vn(Xt.decode(t))}catch{n=j.createV1(ga,Et.digest(t))}}for await(let o of this.client.getClosestPeers(n,r))yield{id:o.ID,multiaddrs:o.Addrs??[]}}toString(){return`DelegatedRoutingV1HttpApiClientPeerRouting(${this.client.url})`}};var vo={concurrentRequests:4,timeout:3e4,cacheTTL:300*1e3,cacheName:"delegated-routing-v1-cache"},Ao=class{url;started;httpQueue;shutDownController;timeout;contentRouting;peerRouting;filterAddrs;filterProtocols;inFlightRequests;cacheName;cache;cacheTTL;log;constructor(t,r){this.log=t.logger.forComponent("delegated-routing-v1-http-api-client"),this.started=!1,this.shutDownController=new AbortController,this.shutDownController.signal,this.httpQueue=new fn({concurrency:r.concurrentRequests??vo.concurrentRequests}),this.inFlightRequests=new Map,this.url=r.url instanceof URL?r.url:new URL(r.url),this.timeout=r.timeout??vo.timeout,this.filterAddrs=r.filterAddrs,this.filterProtocols=r.filterProtocols,this.contentRouting=new Eo(this),this.peerRouting=new So(this),this.cacheName=r.cacheName??vo.cacheName,this.cacheTTL=r.cacheTTL??vo.cacheTTL}get[Xs](){return this.contentRouting}get[Qs](){return this.peerRouting}isStarted(){return this.started}async start(){this.started||(this.started=!0,this.cacheTTL>0&&(this.cache=await globalThis.caches?.open(this.cacheName),this.cache!=null&&this.log("cache enabled with ttl %d",this.cacheTTL)))}async stop(){this.httpQueue.clear(),this.shutDownController.abort(),await globalThis.caches?.delete(this.cacheName),this.started=!1}async*getProviders(t,r={}){this.log("getProviders starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=xr([this.shutDownController.signal,n,r.signal]);let i=Mt(),s=Mt(),c=0;this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let a=new URL(`${this.url}routing/v1/providers/${t}`);this.#n(a,r.filterAddrs,r.filterProtocols);let l={headers:{accept:"application/x-ndjson, application/json;q=0.8"},signal:o},u=await this.#e(a.toString(),l);if(!u.ok){if(u.status===404)return;throw u.status===422?new je("Request does not conform to schema or semantic constraints"):new Vt(`Unexpected status code: ${u.status}`)}let f=u.headers.get("Content-Type");if(f==null)throw new Vt("No Content-Type header received");if(u.body==null){if(f!=="application/x-ndjson")throw new Vt("Routing response had no body");return}if(f.startsWith("application/json")){let E=(await u.json()).Providers??[];for(let x of E){let T=this.#t(x);T!=null&&(c++,yield T)}}else if(f.includes("application/x-ndjson"))for await(let g of Ir(Xr(u.body))){let E=this.#t(g);E!=null&&(c++,yield E)}else throw new Vt(`Unsupported Content-Type: ${f}`)}finally{o.clear(),s.resolve(),this.log("getProviders finished found %d providers for %c",c,t)}}async*getPeers(t,r={}){this.log("getPeers starts: %c",t);let n=AbortSignal.timeout(this.timeout),o=xr([this.shutDownController.signal,n,r.signal]);let i=Mt(),s=Mt();this.httpQueue.add(async()=>(i.resolve(),s.promise));try{await i.promise;let c=new URL(`${this.url}routing/v1/peers/${t.toCID().toString()}`);this.#n(c,r.filterAddrs,r.filterProtocols);let a={headers:{Accept:"application/x-ndjson"},signal:o},l=await this.#e(c.toString(),a);if(l.status===404)return;if(l.status===422)throw new je("Request does not conform to schema or semantic constraints");if(l.body==null)throw new Vt("Routing response had no body");if(l.headers.get("Content-Type")?.startsWith("application/json")){let g=(await l.json()).Peers??[];for(let E of g){let x=this.#t(E);x!=null&&(yield x)}}else for await(let f of Ir(Xr(l.body))){let g=this.#t(f);g!=null&&(yield g)}}catch(c){this.log.error("getPeers errored - %e",c)}finally{o.clear(),s.resolve(),this.log("getPeers finished: %c",t)}}async*getClosestPeers(t,r={}){let n;if(Js(t))n=t.toCID().toString();else if(j.asCID(t)===t||t instanceof j)n=t.toV1().toString();else throw new nt("Key must be CID or PeerId");this.log("getClosestPeers starts: %s",n);let o=AbortSignal.timeout(this.timeout),i=xr([this.shutDownController.signal,o,r.signal]);let s=Mt(),c=Mt();this.httpQueue.add(async()=>(s.resolve(),c.promise));try{await s.promise;let a=new URL(`${this.url}routing/v1/dht/closest/peers/${n}`);this.#n(a,r.filterAddrs,r.filterProtocols);let l={headers:{Accept:"application/x-ndjson"},signal:i},u=await this.#e(a.toString(),l);if(u.status===404)return;if(u.status===422)throw new je("Request does not conform to schema or semantic constraints");if(u.body==null)throw new Vt("Routing response had no body");if(u.headers.get("Content-Type")?.startsWith("application/json")){let E=(await u.json()).Peers??[];for(let x of E){let T=this.#t(x);T!=null&&(yield T)}}else for await(let g of Ir(Xr(u.body))){let E=this.#t(g);E!=null&&(yield E)}}catch(a){this.log.error("getClosestPeers errored - %e",a)}finally{i.clear(),c.resolve(),this.log("getClosestPeers finished: %s",n)}}async getIPNS(t,r={}){this.log("getIPNS starts: %s",t);let n=AbortSignal.timeout(this.timeout),o=xr([this.shutDownController.signal,n,r.signal]);let i=Mt(),s=Mt();this.httpQueue.add(async()=>(i.resolve(),s.promise));let c=`${this.url}routing/v1/ipns/${t}`;try{await i.promise;let a={headers:{Accept:"application/vnd.ipfs.ipns-record"},signal:o},l=await this.#e(c,a);if(this.log("getIPNS GET %s %d",c,l.status),l.status===404)throw new At("No matching records found");if(l.status===422)throw new je("Request does not conform to schema or semantic constraints");if(!l.ok)throw new Vt(`Unexpected status code: ${l.status}`);let u=l.headers.get("Content-Type");if(u==null||!u.includes("application/vnd.ipfs.ipns-record"))throw new At("No matching records found");if(l.body==null)throw new Vt("GET ipns response had no body");let f=await l.arrayBuffer(),g=new Uint8Array(f,0,f.byteLength);return r.validate!==!1&&await Sf(an(t.multihash),g),ne(g)}catch(a){throw this.log.error("getIPNS GET %s error - %e",c,a),a}finally{o.clear(),s.resolve(),this.log("getIPNS finished: %s",t)}}async putIPNS(t,r,n={}){this.log("putIPNS starts: %c",t);let o=AbortSignal.timeout(this.timeout),i=xr([this.shutDownController.signal,o,n.signal]);let s=Mt(),c=Mt();this.httpQueue.add(async()=>(s.resolve(),c.promise));let a=`${this.url}routing/v1/ipns/${t}`;try{await s.promise;let l=ze(r),u={method:"PUT",headers:{"Content-Type":"application/vnd.ipfs.ipns-record"},body:l,signal:i},f=await this.#e(a,u);if(this.log("putIPNS PUT %s %d",a,f.status),f.status!==200)throw new Vt("PUT ipns response had status other than 200")}catch(l){throw this.log.error("putIPNS PUT %s error - %e",a,l.stack),l}finally{i.clear(),c.resolve(),this.log("putIPNS finished: %c",t)}}#t(t){try{let r=[],n=t.Addrs?.map(Gn)??[];return t.Protocols!=null&&r.push(...t.Protocols),t.Protocol!=null&&(r.push(t.Protocol),delete t.Protocol),{...t,Schema:"peer",ID:jc(t.ID),Addrs:n,Protocols:r}}catch(r){this.log.error("could not conform record to peer schema - %e",r)}}#n(t,r,n){if(r!=null||this.filterAddrs!=null){let o=r?.join(",")??this.filterAddrs?.join(",")??"";o!==""&&t.searchParams.set("filter-addrs",o)}if(n!=null||this.filterProtocols!=null){let o=n?.join(",")??this.filterProtocols?.join(",")??"";o!==""&&t.searchParams.set("filter-protocols",o)}}async#e(t,r){let n=r.method??"GET",o=`${n}-${t}`;if(n==="GET"){let a=await this.cache?.match(t);if(a!=null){if(parseInt(a.headers.get("x-cache-expires")??"0",10)>Date.now())return this.log("returning cached response for %s",o),this.logResponse(a),a;this.log("evicting cached response for %s",o),await this.cache?.delete(t)}else this.cache!=null&&this.log("cache miss for %s",o)}let i=this.inFlightRequests.get(o);if(i!=null){let a=await i;return this.log("deduplicating outgoing request for %s",o),a.clone()}this.log("outgoing request:"),this.logRequest(t,r);let s=fetch(t,r).then(async a=>{if(this.log("incoming response:"),this.logResponse(a),this.cache!=null&&a.ok&&n==="GET"){let l=Date.now()+this.cacheTTL,u=new Headers(a.headers);u.set("x-cache-expires",l.toString());let f=new Response(a.clone().body,{status:a.status,statusText:a.statusText,headers:u});await this.cache.put(t,f)}return a}).finally(()=>{this.inFlightRequests.delete(o)});return this.inFlightRequests.set(o,s),await s}toString(){return`DefaultDelegatedRoutingV1HttpApiClient(${this.url})`}logRequest(t,r){let n=new Headers(r.headers);this.log("%s %s HTTP/1.1",r.method??"GET",t);for(let[o,i]of n.entries())this.log("%s: %s",o,i)}logResponse(t){this.log("HTTP/1.1 %d %s",t.status,t.statusText);for(let[r,n]of t.headers.entries())this.log("%s: %s",r,n)}};function _f(e){return t=>new Ao(t,e)}function Io(e){return{url:"https://delegated-ipfs.dev",filterProtocols:["unknown","transport-bitswap","transport-ipfs-gateway-http"],filterAddrs:["https","webtransport","webrtc","webrtc-direct","wss","tls"]}}var Df=H("/ipns/");function Rf(e){return Y(e.subarray(0,Df.byteLength),Df)}var ks=class{name="delegated-http-router";client;constructor(t,r){this.client=_f(r)(t)}async provide(t,r){}async cancelReprovide(t,r){}async*findProviders(t,r){yield*wo(this.client.getProviders(t,r),n=>({id:n.ID,multiaddrs:n.Addrs,protocols:n.Protocols,routing:"delegated-http-routing"}))}async put(t,r,n){if(!Rf(t))return;let o=ge(t),i=j.createV1(114,o),s=ne(r);await this.client.putIPNS(i,s,n)}async get(t,r){if(!Rf(t))throw new At("Not found");let n=ge(t),o=j.createV1(114,n);try{let i=await this.client.getIPNS(o,r);return ze(i)}catch(i){throw i.name==="BadResponseError"?new At("Not found"):i}}async findPeer(t,r){let n=await xo(this.client.getPeers(t,r));if(n!=null)return{id:n.ID,multiaddrs:n.Addrs??[]};throw new At("Not found")}async*getClosestPeers(t,r){}toString(){return`DelegatedHTTPRouter(${this.client.url})`}};function Pf(e){return t=>new ks(t,Io(e))}var Nf="[a-fA-F\\d:]",De=e=>e&&e.includeBoundaries?`(?:(?<=\\s|^)(?=${Nf})|(?<=${Nf})(?=\\s|$))`:"",Zt="(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}",at="[a-fA-F\\d]{1,4}",To=`
|
|
14
14
|
(?:
|
|
15
15
|
(?:${at}:){7}(?:${at}|:)| // 1:2:3:4:5:6:7:: 1:2:3:4:5:6:7:8
|
|
16
16
|
(?:${at}:){6}(?:${Zt}|:${at}|:)| // 1:2:3:4:5:6:: 1:2:3:4:5:6::8 1:2:3:4:5:6::8 1:2:3:4:5:6::1.2.3.4
|
|
@@ -21,7 +21,7 @@ ${t}[Error list was empty]`,r.trim()}return fu(e,t)}Ct.formatters.e=e=>e==null?"
|
|
|
21
21
|
(?:${at}:){1}(?:(?::${at}){0,4}:${Zt}|(?::${at}){1,6}|:)| // 1:: 1::3:4:5:6:7:8 1::8 1::3:4:5:6:7:1.2.3.4
|
|
22
22
|
(?::(?:(?::${at}){0,5}:${Zt}|(?::${at}){1,7}|:)) // ::2:3:4:5:6:7:8 ::2:3:4:5:6:7:8 ::8 ::1.2.3.4
|
|
23
23
|
)(?:%[0-9a-zA-Z]{1,})? // %eth0 %1
|
|
24
|
-
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),v0=new RegExp(`(?:^${Zt}$)|(?:^${To}$)`),A0=new RegExp(`^${Zt}$`),I0=new RegExp(`^${To}$`),Ks=e=>e&&e.exact?v0:new RegExp(`(?:${De(e)}${Zt}${De(e)})|(?:${De(e)}${To}${De(e)})`,"g");Ks.v4=e=>e&&e.exact?A0:new RegExp(`${De(e)}${Zt}${De(e)}`,"g");Ks.v6=e=>e&&e.exact?I0:new RegExp(`${De(e)}${To}${De(e)}`,"g");var Ms=Ks;function Vs(e){let t=(...r)=>e(...r);return Object.defineProperty(t,"name",{value:`functionTimeout(${e.name||"<anonymous>"})`,configurable:!0}),t}function Lf(){return!1}var{toString:T0}=Object.prototype;function Fs(e){return T0.call(e)==="[object RegExp]"}var Uf={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function $s(e,t={}){if(!Fs(e))throw new TypeError("Expected a RegExp instance");let r=Object.keys(Uf).map(o=>(typeof t[o]=="boolean"?t[o]:e[o])?Uf[o]:"").join(""),n=new RegExp(t.source||e.source,r);return n.lastIndex=typeof t.lastIndex=="number"?t.lastIndex:e.lastIndex,n}function qs(e,t,{timeout:r}={}){try{return Vs(()=>$s(e).test(t),{timeout:r})()}catch(n){if(Lf(n))return!1;throw n}}var C0=15,B0=45,Of={timeout:400};function Hs(e){return e.length>B0?!1:qs(Ms.v6({exact:!0}),e,Of)}function kf(e){return e.length>C0?!1:qs(Ms.v4({exact:!0}),e,Of)}var Kf={http:"80",https:"443",ws:"80",wss:"443"},_0=["http","https","ws","wss"];function Mf(e,t){t=t??{};let r=t.defaultDnsType??"dns",{scheme:n,hostname:o,port:i,path:s}=D0(e),c=[R0(o,r),P0(i,n),N0(n)];s!=null&&c.push(L0(s));let a="/"+c.filter(l=>!!l).reduce((l,u)=>l.concat(u),[]).join("/");return Gn(a)}function D0(e){let[t]=e.split(":");_0.includes(t)||(e="http"+e.substring(t.length));let{protocol:r,hostname:n,port:o,pathname:i,search:s}=new URL(e);if(o==null||o===""){let a=U0(t);a!=null&&(o=a),a==null&&r==="http:"&&(o="80")}let c;return i!=null&&i!==""&&i!=="/"&&(i.startsWith("/")&&(i=i.substring(1)),c=i),s!=null&&s!==""&&(c=c??"",c+=s),{scheme:t,hostname:n,port:o,path:c}}function R0(e,t){if(!(e==null||e==="")){if(kf(e))return["ip4",e];if(Hs(e))return["ip6",e];if(e[0]==="["){let r=e.substring(1,e.length-1);if(Hs(r))return["ip6",r]}return[t,e]}}function P0(e,t){if(!(e==null||e===""))return t==="udp"?["udp",e]:["tcp",e]}function N0(e){if(e.match(/^tcp$|^udp$/)==null)return e==="https"?["/tls/http"]:e==="wss"?["/tls/ws"]:[e]}function L0(e){if(!(e==null||e===""))return["http-path",encodeURIComponent(e)]}function U0(e){if(!(e==null||e===""||Kf[e]==null))return Kf[e]}var O0=["https://trustless-gateway.link","https://4everland.io"],k0=2336;function K0(e){return e=e.toString(),{id:fs(j.createV1(k0,Et.digest(H(e)))),multiaddrs:[Mf(e)]}}function M0(e){return new URL(z(e.id.toMultihash().digest))}var zs=class{gateways;shuffle;constructor(t={}){this.gateways=(t.gateways??O0).map(r=>K0(r)),this.shuffle=t.shuffle??!0}async*findProviders(t,r){yield*(this.shuffle?this.gateways.toSorted(()=>Math.random()>.5?1:-1):this.gateways).map(n=>({...n,protocols:["transport-ipfs-gateway-http"],routing:"http-gateway-routing"}))}toString(){return`HTTPGatewayRouter([${this.gateways.map(t=>M0(t)).join(", ")}])`}};function Vf(e={}){return new zs(e)}var js=class{libp2p;constructor(t){this.libp2p=t}async provide(t,r){await this.libp2p.contentRouting.provide(t,r)}async cancelReprovide(t,r){await this.libp2p.contentRouting.cancelReprovide(t,r)}async*findProviders(t,r){yield*this.libp2p.contentRouting.findProviders(t,r)}async put(t,r,n){await this.libp2p.contentRouting.put(t,r,n)}async get(t,r){return this.libp2p.contentRouting.get(t,r)}async findPeer(t,r){return this.libp2p.peerRouting.findPeer(t,r)}async*getClosestPeers(t,r){yield*this.libp2p.peerRouting.getClosestPeers(t,r)}toString(){return"Libp2pRouter()"}};function Ff(e){return new js(e)}return Gf(V0);})();
|
|
24
|
+
`.replace(/\s*\/\/.*$/gm,"").replace(/\n/g,"").trim(),v0=new RegExp(`(?:^${Zt}$)|(?:^${To}$)`),A0=new RegExp(`^${Zt}$`),I0=new RegExp(`^${To}$`),Ks=e=>e&&e.exact?v0:new RegExp(`(?:${De(e)}${Zt}${De(e)})|(?:${De(e)}${To}${De(e)})`,"g");Ks.v4=e=>e&&e.exact?A0:new RegExp(`${De(e)}${Zt}${De(e)}`,"g");Ks.v6=e=>e&&e.exact?I0:new RegExp(`${De(e)}${To}${De(e)}`,"g");var Ms=Ks;function Vs(e){let t=(...r)=>e(...r);return Object.defineProperty(t,"name",{value:`functionTimeout(${e.name||"<anonymous>"})`,configurable:!0}),t}function Lf(){return!1}var{toString:T0}=Object.prototype;function Fs(e){return T0.call(e)==="[object RegExp]"}var Uf={global:"g",ignoreCase:"i",multiline:"m",dotAll:"s",sticky:"y",unicode:"u"};function $s(e,t={}){if(!Fs(e))throw new TypeError("Expected a RegExp instance");let r=Object.keys(Uf).map(o=>(typeof t[o]=="boolean"?t[o]:e[o])?Uf[o]:"").join(""),n=new RegExp(t.source||e.source,r);return n.lastIndex=typeof t.lastIndex=="number"?t.lastIndex:e.lastIndex,n}function qs(e,t,{timeout:r}={}){try{return Vs(()=>$s(e).test(t),{timeout:r})()}catch(n){if(Lf(n))return!1;throw n}}var C0=15,B0=45,Of={timeout:400};function Hs(e){return e.length>B0?!1:qs(Ms.v6({exact:!0}),e,Of)}function kf(e){return e.length>C0?!1:qs(Ms.v4({exact:!0}),e,Of)}var Kf={http:"80",https:"443",ws:"80",wss:"443"},_0=["http","https","ws","wss"];function Mf(e,t){t=t??{};let r=t.defaultDnsType??"dns",{scheme:n,hostname:o,port:i,path:s}=D0(e),c=[R0(o,r),P0(i,n),N0(n)];s!=null&&c.push(L0(s));let a="/"+c.filter(l=>!!l).reduce((l,u)=>l.concat(u),[]).join("/");return Gn(a)}function D0(e){let[t]=e.split(":");_0.includes(t)||(e="http"+e.substring(t.length));let{protocol:r,hostname:n,port:o,pathname:i,search:s}=new URL(e);if(o==null||o===""){let a=U0(t);a!=null&&(o=a),a==null&&r==="http:"&&(o="80")}let c;return i!=null&&i!==""&&i!=="/"&&(i.startsWith("/")&&(i=i.substring(1)),c=i),s!=null&&s!==""&&(c=c??"",c+=s),{scheme:t,hostname:n,port:o,path:c}}function R0(e,t){if(!(e==null||e==="")){if(kf(e))return["ip4",e];if(Hs(e))return["ip6",e];if(e[0]==="["){let r=e.substring(1,e.length-1);if(Hs(r))return["ip6",r]}return[t,e]}}function P0(e,t){if(!(e==null||e===""))return t==="udp"?["udp",e]:["tcp",e]}function N0(e){if(e.match(/^tcp$|^udp$/)==null)return e==="https"?["/tls/http"]:e==="wss"?["/tls/ws"]:[e]}function L0(e){if(!(e==null||e===""))return["http-path",encodeURIComponent(e)]}function U0(e){if(!(e==null||e===""||Kf[e]==null))return Kf[e]}var O0=["https://trustless-gateway.link","https://4everland.io"],k0=2336;function K0(e){return e=e.toString(),{id:fs(j.createV1(k0,Et.digest(H(e)))),multiaddrs:[Mf(e)]}}function M0(e){return new URL(z(e.id.toMultihash().digest))}var zs=class{name="http-gateway-router";gateways;shuffle;constructor(t={}){this.gateways=(t.gateways??O0).map(r=>K0(r)),this.shuffle=t.shuffle??!0}async*findProviders(t,r){yield*(this.shuffle?this.gateways.toSorted(()=>Math.random()>.5?1:-1):this.gateways).map(n=>({...n,protocols:["transport-ipfs-gateway-http"],routing:"http-gateway-routing"}))}toString(){return`HTTPGatewayRouter([${this.gateways.map(t=>M0(t)).join(", ")}])`}};function Vf(e={}){return new zs(e)}var js=class{name="libp2p-router";libp2p;constructor(t){this.libp2p=t}async provide(t,r){await this.libp2p.contentRouting.provide(t,r)}async cancelReprovide(t,r){await this.libp2p.contentRouting.cancelReprovide(t,r)}async*findProviders(t,r){yield*this.libp2p.contentRouting.findProviders(t,r)}async put(t,r,n){await this.libp2p.contentRouting.put(t,r,n)}async get(t,r){return this.libp2p.contentRouting.get(t,r)}async findPeer(t,r){return this.libp2p.peerRouting.findPeer(t,r)}async*getClosestPeers(t,r){yield*this.libp2p.peerRouting.getClosestPeers(t,r)}toString(){return"Libp2pRouter()"}};function Ff(e){return new js(e)}return Gf(V0);})();
|
|
25
25
|
/*! Bundled license information:
|
|
26
26
|
|
|
27
27
|
@noble/hashes/utils.js:
|